From 17c8497e8af5851505a1e3333e33a1b9b154babd Mon Sep 17 00:00:00 2001 From: Stephen Sherratt Date: Fri, 28 Jul 2023 15:58:43 +1000 Subject: [PATCH] Replace `float array` with `floatarray` --- src/core/dsl.mli | 2 +- src/core/modules.ml | 10 ++++++---- src/core/modules.mli | 2 +- src/interactive/window.ml | 14 +++++++------- src/low-level/llama_low_level.ml | 4 ++-- src/low-level/llama_low_level.mli | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/core/dsl.mli b/src/core/dsl.mli index 35d5918..0b6b3d6 100644 --- a/src/core/dsl.mli +++ b/src/core/dsl.mli @@ -79,7 +79,7 @@ val chebyshev_high_pass_filter : float t val sample_and_hold : float t -> bool t -> float t -val sample_player_mono : float array -> bool t -> float t +val sample_player_mono : floatarray -> bool t -> float t val bitwise_trigger_sequencer : int -> int t list -> bool t -> bool t list val delay : 'a t -> time_s:float t -> fill:'a -> 'a t val clock_delay : float -> bool t -> bool t diff --git a/src/core/modules.ml b/src/core/modules.ml index d48c4ec..393fd76 100644 --- a/src/core/modules.ml +++ b/src/core/modules.ml @@ -334,17 +334,19 @@ module Sample_and_hold = struct end module Sample_player_mono = struct - type t = { data : float array; trigger : bool Signal.t } + type t = { data : floatarray; trigger : bool Signal.t } let signal t = - Raw.with_state' ~init:(Array.length t.data) ~f:(fun index ctx -> + Raw.with_state' ~init:(Float.Array.length t.data) ~f:(fun index ctx -> if Signal.sample t.trigger ctx then (0, 0.0) else (* deliberately allow index to be 1 out of bounds to indicate that the sample is finished *) let sample = - if index < Array.length t.data then Array.get t.data index else 0.0 + if index < Float.Array.length t.data then + Float.Array.get t.data index + else 0.0 in - let index = Int.min (index + 1) (Array.length t.data) in + let index = Int.min (index + 1) (Float.Array.length t.data) in (index, sample)) |> Signal.of_raw end diff --git a/src/core/modules.mli b/src/core/modules.mli index a1253c3..e86a62e 100644 --- a/src/core/modules.mli +++ b/src/core/modules.mli @@ -105,7 +105,7 @@ module Sample_and_hold : sig end module Sample_player_mono : sig - type t = { data : float array; trigger : bool Signal.t } + type t = { data : floatarray; trigger : bool Signal.t } val signal : t -> float Signal.t end diff --git a/src/interactive/window.ml b/src/interactive/window.ml index 821bfc2..a4a901e 100644 --- a/src/interactive/window.ml +++ b/src/interactive/window.ml @@ -33,18 +33,18 @@ module Visualization_style = struct end module Sample_buffer = struct - type t = { samples : float array; mutable next_i : int } + type t = { samples : floatarray; mutable next_i : int } let create size = - let samples = Array.init size ~f:(Fun.const 0.0) in + let samples = Float.Array.init size (Fun.const 0.0) in { samples; next_i = 0 } let length t = t.next_i - let is_full t = t.next_i == Array.length t.samples + let is_full t = t.next_i == Float.Array.length t.samples let append_unless_full t sample = if not (is_full t) then ( - Array.set t.samples t.next_i sample; + Float.Array.set t.samples t.next_i sample; t.next_i <- t.next_i + 1) let clear t = t.next_i <- 0 @@ -53,8 +53,8 @@ module Sample_buffer = struct let rec loop i = if i >= t.next_i then None else - let prev = Array.get t.samples (i - 1) in - let current = Array.get t.samples i in + let prev = Float.Array.get t.samples (i - 1) in + let current = Float.Array.get t.samples i in if prev <= 0.0 && current >= 0.0 then Some i else loop (i + 1) in loop 1 @@ -63,7 +63,7 @@ module Sample_buffer = struct let rec loop i count = if i >= t.next_i || count >= max_iterations then () else ( - f count (Array.get t.samples i); + f count (Float.Array.get t.samples i); loop (i + stride) (count + 1)) in loop offset 0 diff --git a/src/low-level/llama_low_level.ml b/src/low-level/llama_low_level.ml index 4565fa9..d524c2a 100644 --- a/src/low-level/llama_low_level.ml +++ b/src/low-level/llama_low_level.ml @@ -16,9 +16,9 @@ module Wav = struct let read_wav_file_mono_exn path = (* TODO: This array can't be indexed with [Array.get] but values can be obtained with (say) [Array.iter]. This is possibly a bug in the ocaml - rust bindings for the [float array] special case. *) + rust bindings for the [floatarray] special case. *) let broken_array = read_wav_file_mono_exn_raw path in - Array.of_list (Array.to_list broken_array) + Float.Array.of_seq (Array.to_seq broken_array) end module Output_stream = struct diff --git a/src/low-level/llama_low_level.mli b/src/low-level/llama_low_level.mli index ff40010..b0e3a04 100644 --- a/src/low-level/llama_low_level.mli +++ b/src/low-level/llama_low_level.mli @@ -3,7 +3,7 @@ module System : sig end module Wav : sig - val read_wav_file_mono_exn : string -> float array + val read_wav_file_mono_exn : string -> floatarray end module Output_stream : sig