March Docs

Arcade.Synth

Types

typeSynthWaveSynthWave = WaveSine | WaveSquare | WaveTri | WaveNoise#
typeSynthVoiceSynthVoice = {#

Every Float field holds a value a Swift Float can hold. glide_floor is Swift's max(glide, 0.0001) and life its decay * 6, both computed once.

typeSynthTuningSynthTuning = {#

The numbers a synth is built from, as written (not yet rounded to Float). rate is samples per second; max_voices the cap past which add drops the oldest voices; seed the noise generator's start. The rumble bed is low-passed noise: its loudness follows set_rumble by rumble_follow a sample, the noise is low-passed by lowpass_follow, and the product is scaled by rumble_gain. The drum bed is one noise hit of drum_amp and drum_decay every drum_step seconds. min_glide floors every glide time, attack_time is every voice's linear attack, square_level the square wave's height, and default_glide the glide time of the short voice forms.

typeSynthConstsSynthConsts = {#

The Float constants of the synth, rounded to Float once. drum_amp and drum_decay stay as written: voice rounds them, as it rounds every argument.

typeSynthSynth = {#
typeMixMix = { level : Float, mix_seed : Int, kept : List(SynthVoice) }#

Functions

fnaddadd(s : Synth, vs : List(SynthVoice)) : Synth needs ()#

fn upto(n : Int, f : Int -> SynthVoice) : List(SynthVoice) needs () do upto_from(0, n, f, []) end

pfn upto_from(i : Int, n : Int, f : Int -> SynthVoice, acc : List(SynthVoice)) : List(SynthVoice) needs () do if i < n do upto_from(i + 1, n, f, Cons(f(i), acc)) else List.reverse(acc) end end

fnafterafter(c : SynthConsts, start : Float, i : Int, step : Float) : Float needs ()#

fn times(c : SynthConsts, i : Int, x : Float) : Float needs () do f32(c, int_to_float(i) *. f32(c, x)) end

fnbellbell(c : SynthConsts, pitch : Float, loudness : Float, delay : Float) : List(SynthVoice) needs ()#

fn arpeggio(c : SynthConsts, notes : List(Float), step : Float, amp : Float, decay : Float, w : SynthWave) : List(SynthVoice) needs () do arpeggio_from(c, notes, 0, step, amp, decay, w, []) end

fnconsts_ofconsts_of(t : SynthTuning) : SynthConsts needs ()#

fn max_voices() : Int needs () do let t = tuning() t.max_voices end

fnexpfexpf(c : SynthConsts, x : Float) : Float needs ()#

fn sinf(c : SynthConsts, x : Float) : Float needs () do Arcade.Float32.sinf(c.round, x) end

fnf32f32(c : SynthConsts, x : Float) : Float needs ()#

fn consts() : SynthConsts needs () do consts_of(tuning()) end

fnglideglide(c : SynthConsts, w : SynthWave, f : Float, to : Float, time : Float, amp : Float, decay : Float) : SynthVoice needs ()#

fn bend(c : SynthConsts, w : SynthWave, f : Float, to : Float, amp : Float, decay : Float) : SynthVoice needs () do voice(c, w, f, to, c.default_glide, amp, decay, 0.0) end

fnnew_tunednew_tuned(t : SynthTuning) : Synth needs ()#

fn powf(c : SynthConsts, base : Float, e : Float) : Float needs () do Arcade.Float32.powf(c.round, base, e) end

fnraterate() : Float needs ()#

fn tuning() : SynthTuning needs () do { rate: 44100.0, max_voices: 48, seed: 22222, rumble_follow: 0.0008, lowpass_follow: 0.035, rumble_gain: 0.9, drum_step: 0.055, drum_amp: 0.13, drum_decay: 0.03, min_glide: 0.0001, attack_time: 0.003, square_level: 0.6, default_glide: 0.1 } end

fnset_rumbleset_rumble(s : Synth, target : Float) : Synth needs ()#

fn new() : Synth needs () do new_tuned(tuning()) end

fntone_attone_at(c : SynthConsts, w : SynthWave, f : Float, amp : Float, decay : Float, delay : Float) : SynthVoice needs ()#

fn tone(c : SynthConsts, w : SynthWave, f : Float, amp : Float, decay : Float) : SynthVoice needs () do voice(c, w, f, f, c.default_glide, amp, decay, 0.0) end

fnvoicevoice(c : SynthConsts, w : SynthWave, f : Float, to : Float, glide : Float, amp : Float, decay : Float, delay : Float) : SynthVoice needs ()#

fn set_drum(s : Synth, drum_on : Bool) : Synth needs () do { s with drum: drum_on } end

fn voice_count(s : Synth) : Int needs () do List.length(s.voices) end

-- ---- Voices ----