package tiny_libs
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
From-scratch libraries for teaching: graphics, audio, compression, crypto, networking and more
Install
dune-project
Dependency
Authors
Maintainers
Sources
0.3.6.tar.gz
md5=7c636383d146d30ac6f2fa234a6253c8
sha512=c79f3823c5f8f57e5038eb640d487c61168b84aa07c61999d6622ef9fd0c890e2b03b4c6a7cdbbe9352a49e25dda00ac7bb14693cee8e3d7beeed251351a2af0
doc/src/tiny_libs.audio_signal/Signal.ml.html
Source file Signal.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42(* Claude Code * * Copyright (C) 2026 Yoann Padioleau * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * (LGPL) as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. *) (* See Signal.mli *) type t = float array type stereo = { left : t; right : t } (* the same array twice: nothing here writes into a sound once made *) let both (s : t) : stereo = { left = s; right = s } let mono (s : stereo) : t = Array.map2 (fun l r -> (l +. r) /. 2.) s.left s.right let rate = 44100 let nyquist = float_of_int rate /. 2. let samples (seconds : float) : int = int_of_float (seconds *. float_of_int rate) let period_in_samples (frequency : float) : float = float_of_int rate /. frequency let alias (frequency : float) : float = (* the spectrum repeats every [rate], and mirrors around each * multiple of it *) let f = Float.rem (Float.abs frequency) (float_of_int rate) in if f <= nyquist then f else float_of_int rate -. f let of_function (seconds : float) (f : float -> float) : t = Array.init (samples seconds) (fun i -> f (float_of_int i /. float_of_int rate)) (* claude: compared as ints; it was * * max (-32768) (min 32767 (int_of_float (Float.round (x *. 32767.)))) * * Stdlib's min and max are polymorphic, the runtime's generic compare * twice per sample written (notes_opti_ocaml.md) *) let to_int16 (x : float) : int = let v = int_of_float (Float.round (x *. 32767.)) in if v < -32768 then -32768 else if v > 32767 then 32767 else v
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>