Skip to content

Commit 6592876

Browse files
committed
expose new modulators
1 parent 3c3ddd5 commit 6592876

2 files changed

Lines changed: 67 additions & 11 deletions

File tree

src/host/audio.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,60 @@ pub(crate) fn mod_hold(mut caller: C, node_id: u32, param: u32, low: f32, high:
245245
modulate(state, node_id, param, Box::new(lfo), low, high);
246246
}
247247

248+
pub(crate) fn mod_adsr(
249+
mut caller: C,
250+
node_id: u32,
251+
param: u32,
252+
low: f32,
253+
high: f32,
254+
attack: u32,
255+
decay: u32,
256+
sustain: u32,
257+
sustain_level: f32,
258+
release: u32,
259+
) {
260+
let state = caller.data_mut();
261+
state.called = "audio.mod_adsr";
262+
let lfo = modulators::Adsr::new(attack, decay, sustain, sustain_level, release);
263+
modulate(state, node_id, param, Box::new(lfo), low, high);
264+
}
265+
266+
// TODO(@orsinium): Put `low` and `high` before modulator params for consistency.
248267
pub(crate) fn mod_sine(mut caller: C, node_id: u32, param: u32, freq: f32, low: f32, high: f32) {
249268
let state = caller.data_mut();
250269
state.called = "audio.mod_sine";
251270
let lfo = modulators::Sine::new(freq);
252271
modulate(state, node_id, param, Box::new(lfo), low, high);
253272
}
254273

274+
pub(crate) fn mod_square(
275+
mut caller: C,
276+
node_id: u32,
277+
param: u32,
278+
low: f32,
279+
high: f32,
280+
period: u32,
281+
) {
282+
let state = caller.data_mut();
283+
state.called = "audio.mod_square";
284+
let lfo = modulators::Pulse::new_square(period);
285+
modulate(state, node_id, param, Box::new(lfo), low, high);
286+
}
287+
288+
pub(crate) fn mod_sawtooth(
289+
mut caller: C,
290+
node_id: u32,
291+
param: u32,
292+
low: f32,
293+
high: f32,
294+
period: u32,
295+
) {
296+
let state = caller.data_mut();
297+
state.called = "audio.mod_sawtooth";
298+
let lfo = modulators::Triangle::new_sawtooth(period);
299+
modulate(state, node_id, param, Box::new(lfo), low, high);
300+
}
301+
255302
fn modulate(
256303
state: &mut State,
257304
node_id: u32,

src/linking.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,40 @@ fn select_audio_external<'a>(
117117
"reset" => Func::wrap(ctx, audio::reset),
118118
"reset_all" => Func::wrap(ctx, audio::reset_all),
119119
"clear" => Func::wrap(ctx, audio::clear),
120-
"add_empty" => Func::wrap(ctx, audio::add_empty),
121-
"add_file" => Func::wrap(ctx, audio::add_file),
122-
"add_mix" => Func::wrap(ctx, audio::add_mix),
120+
121+
// Processors.
123122
"add_all_for_one" => Func::wrap(ctx, audio::add_all_for_one),
123+
"add_clip" => Func::wrap(ctx, audio::add_clip),
124+
"add_concat" => Func::wrap(ctx, audio::add_concat),
125+
"add_file" => Func::wrap(ctx, audio::add_file),
124126
"add_gain" => Func::wrap(ctx, audio::add_gain),
127+
"add_high_pass" => Func::wrap(ctx, audio::add_high_pass),
125128
"add_loop" => Func::wrap(ctx, audio::add_loop),
126-
"add_concat" => Func::wrap(ctx, audio::add_concat),
127-
"add_pan" => Func::wrap(ctx, audio::add_pan),
129+
"add_low_pass" => Func::wrap(ctx, audio::add_low_pass),
130+
"add_mix" => Func::wrap(ctx, audio::add_mix),
128131
"add_mute" => Func::wrap(ctx, audio::add_mute),
132+
"add_pan" => Func::wrap(ctx, audio::add_pan),
129133
"add_pause" => Func::wrap(ctx, audio::add_pause),
130-
"add_track_position" => Func::wrap(ctx, audio::add_track_position),
131-
"add_low_pass" => Func::wrap(ctx, audio::add_low_pass),
132-
"add_high_pass" => Func::wrap(ctx, audio::add_high_pass),
134+
"add_swap" => Func::wrap(ctx, audio::add_swap),
133135
"add_take_left" => Func::wrap(ctx, audio::add_take_left),
134136
"add_take_right" => Func::wrap(ctx, audio::add_take_right),
135-
"add_swap" => Func::wrap(ctx, audio::add_swap),
136-
"add_clip" => Func::wrap(ctx, audio::add_clip),
137+
"add_track_position" => Func::wrap(ctx, audio::add_track_position),
138+
139+
// Generators.
140+
"add_empty" => Func::wrap(ctx, audio::add_empty),
137141
"add_noise" => Func::wrap(ctx, audio::add_noise),
142+
"add_sawtooth" => Func::wrap(ctx, audio::add_sawtooth),
138143
"add_sine" => Func::wrap(ctx, audio::add_sine),
139144
"add_square" => Func::wrap(ctx, audio::add_square),
140-
"add_sawtooth" => Func::wrap(ctx, audio::add_sawtooth),
141145
"add_triangle" => Func::wrap(ctx, audio::add_triangle),
142146
"add_zero" => Func::wrap(ctx, audio::add_zero),
147+
148+
// Modulators.
143149
"mod_linear" => Func::wrap(ctx, audio::mod_linear),
144150
"mod_hold" => Func::wrap(ctx, audio::mod_hold),
151+
"mod_adsr" => Func::wrap(ctx, audio::mod_adsr),
152+
"mod_square" => Func::wrap(ctx, audio::mod_square),
153+
"mod_sawtooth" => Func::wrap(ctx, audio::mod_sawtooth),
145154
"mod_sine" => Func::wrap(ctx, audio::mod_sine),
146155
_ => return None,
147156
};

0 commit comments

Comments
 (0)