Skip to content

Commit

Permalink
add wet/dry control
Browse files Browse the repository at this point in the history
  • Loading branch information
p42ul committed Feb 21, 2024
1 parent 9529d5f commit bc0fb29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct ResotoolParams {
pub sustain: FloatParam,
#[id = "release"]
pub release: FloatParam,
#[id = "wetdry" ]
pub wetdry: FloatParam,
}

impl Default for Resotool {
Expand Down Expand Up @@ -63,6 +65,7 @@ impl Default for ResotoolParams {
decay: adsr_param("Decay (seconds)"),
sustain: FloatParam::new("Sustain", 1.0, FloatRange::Linear { min: 0.0, max: 1.0 }),
release: adsr_param("Release (seconds)"),
wetdry: FloatParam::new("Wet/Dry", 1.0, FloatRange::Linear { min: 0.0, max: 1.0 }),
}
}
}
Expand Down Expand Up @@ -135,6 +138,7 @@ impl Plugin for Resotool {
context: &mut impl ProcessContext<Self>,
) -> ProcessStatus {
let voicer_params = VoicerParams {
wetdry: self.params.wetdry.value(),
bandwidth: self.params.bandwidth.value(),
attack: self.params.attack.value(),
decay: self.params.decay.value(),
Expand Down
9 changes: 8 additions & 1 deletion src/voicer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ type VoiceSize = U8;
pub struct Voicer {
last_played: u32,
voices: Box<[Voice; NUM_VOICES]>,
wetdry: Shared<f32>,
voices_sounding: Shared<f32>,
pub audio: Box<dyn AudioUnit32>,
}

pub struct VoicerParams {
pub wetdry: f32,
pub bandwidth: f32,
pub attack: f32,
pub decay: f32,
Expand All @@ -29,6 +31,7 @@ impl Voicer {
}

pub fn update(&self, params: VoicerParams) {
self.wetdry.set(params.wetdry);
for voice in self.voices.iter() {
voice.bandwidth.set(params.bandwidth);
voice.adsr.attack.set(params.attack);
Expand Down Expand Up @@ -70,6 +73,7 @@ impl Voicer {
pub fn new() -> Self {
let voices: [Voice; NUM_VOICES] = std::array::from_fn(|_| Voice::default());
let voices_sounding: Shared<f32> = Shared::new(0.0);
let wetdry = Shared::new(1.0);
let filterbank = stack::<VoiceSize, _, _>(|i| {
let voice = &voices[i as usize];
(
Expand All @@ -85,8 +89,11 @@ impl Voicer {
)
>> resonator() * var_fn(&voices_sounding, |vs| NUM_VOICES as f32 / vs)
});
let audio = Box::new(split() >> filterbank >> join());
let wet = (split() >> filterbank >> join()) * var(&wetdry);
let dry = pass() * var_fn(&wetdry, |wd| 1.0 - wd);
let audio = Box::new(wet & dry);
Self {
wetdry: wetdry,
last_played: 0,
voices: Box::new(voices),
voices_sounding: voices_sounding,
Expand Down

0 comments on commit bc0fb29

Please sign in to comment.