Skip to content

Commit

Permalink
More.
Browse files Browse the repository at this point in the history
  • Loading branch information
smimram authored and toots committed Oct 9, 2019
1 parent 0270548 commit 6d55d62
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/flac.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ exception Internal
let () =
Callback.register_exception "flac_exn_internal" Internal

type audio_buffer = (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t

module Decoder =
struct
type 'a dec

type 'a t = 'a dec

type write = (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t array -> unit
type write = audio_buffer array -> unit

type read = bytes -> int -> int -> int

Expand Down Expand Up @@ -238,7 +240,7 @@ struct
let enc = create comments p c in
enc,p

external process : 'a priv -> 'a callbacks -> float array array -> int -> unit = "ocaml_flac_encoder_process"
external process : 'a priv -> 'a callbacks -> audio_buffer array -> int -> unit = "ocaml_flac_encoder_process"

let process (enc,p) c data =
if (Array.length data <> p.channels) then
Expand Down
8 changes: 5 additions & 3 deletions src/flac.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

(* Author; Romain Beauxis <[email protected]> *)

(** {1 Native FLAC decoder/encoder modules for OCaml} *)
(** {1 Native FLAC decoder/encoder modules for OCaml} *)

type audio_buffer = (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t

(** Decode native FLAC data *)
module Decoder :
Expand Down Expand Up @@ -80,7 +82,7 @@ sig
type 'a t

(** Type of a write callback. *)
type write = (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t array -> unit
type write = audio_buffer array -> unit

(** Type of a read callback. *)
type read = bytes -> int -> int -> int
Expand Down Expand Up @@ -335,7 +337,7 @@ sig
val create : ?comments:comments -> params -> 'a callbacks -> 'a t

(** Encode some data *)
val process : 'a t -> 'a callbacks -> float array array -> unit
val process : 'a t -> 'a callbacks -> audio_buffer array -> unit

(** Terminate an encoder. Causes the encoder to
* flush remaining encoded data. The encoder should
Expand Down
8 changes: 6 additions & 2 deletions src/flac_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
*/


#include <assert.h>
#include <memory.h>
#include <stdint.h>

#include <caml/bigarray.h>
#include <caml/callback.h>
#include <caml/fail.h>
#include <caml/alloc.h>
Expand Down Expand Up @@ -840,7 +842,8 @@ CAMLprim value ocaml_flac_encoder_process(value _enc, value cb, value data, valu
ocaml_flac_encoder *enc = Encoder_val(_enc);

int chans = Wosize_val(data);
int samples = Wosize_val(Field(data, 0)) / Double_wosize;
assert (chans > 0);
int samples = Caml_ba_array_val(Field(data, 0))->dim[0];
int i;
int c;

Expand All @@ -860,8 +863,9 @@ CAMLprim value ocaml_flac_encoder_process(value _enc, value cb, value data, valu
{
if (c > 0)
enc->buf[c] = enc->buf[c-1] + samples;
float *b = Caml_ba_data_val(Field(data,c));
for (i = 0; i < samples; i++)
enc->buf[c][i] = sample_from_double(Double_field(Field(data,c),i),Int_val(bps));
enc->buf[c][i] = sample_from_double(b[i],Int_val(bps));
}

Fill_enc_values(enc,cb);
Expand Down

0 comments on commit 6d55d62

Please sign in to comment.