Skip to content

Commit

Permalink
bugs removed!
Browse files Browse the repository at this point in the history
  • Loading branch information
ardura committed Oct 4, 2024
1 parent 54e99ae commit e6a7abd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 48 deletions.
54 changes: 30 additions & 24 deletions src/audio_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ struct VoiceVec {
// into any threading issues trying to modify different vecs in the same function rather than 1 struct
// Underscores are to get rid of the compiler warning thinking it's not used but it's stored for debugging or passed between structs
// and still functional.

// Allow dead code is for rust-analyzer getting false issues on things that are actually used
#[allow(dead_code)]
#[derive(Clone)]
pub struct SingleVoice {
/// The note's key/note, in `0..128`. Only used for the voice terminated event.
Expand Down Expand Up @@ -193,6 +196,8 @@ pub struct SingleVoice {
internal_unison_voices: Vec<SingleUnisonVoice>,
}

// Allow dead code is for rust-analyzer getting false issues on things that are actually used
#[allow(dead_code)]
#[derive(Clone)]
pub struct SingleUnisonVoice {
/// The note's key/note, in `0..128`. Only used for the voice terminated event.
Expand Down Expand Up @@ -3123,8 +3128,8 @@ UniRandom: Every voice uses its own unique random phase every note".to_string())
A4I_r_1: A4iFilter::new(self.filter_cutoff, self.filter_cutoff, self.filter_resonance),
A4I_r_2: A4iFilter::new(self.filter_cutoff_2, self.filter_cutoff_2, self.filter_resonance_2),

cutoff_modulation: 0.0,
cutoff_modulation_2: 0.0,
cutoff_modulation: cutoff_mod,
cutoff_modulation_2: cutoff_mod_2,
resonance_modulation: 0.0,
resonance_modulation_2: 0.0,

Expand Down Expand Up @@ -3311,8 +3316,8 @@ UniRandom: Every voice uses its own unique random phase every note".to_string())
vector.push(0.0);
vector
},
cutoff_modulation: 0.0,
cutoff_modulation_2: 0.0,
cutoff_modulation: cutoff_mod,
cutoff_modulation_2: cutoff_mod_2,
resonance_modulation: 0.0,
resonance_modulation_2: 0.0,
};
Expand Down Expand Up @@ -3455,8 +3460,8 @@ UniRandom: Every voice uses its own unique random phase every note".to_string())
A4I_l_2: A4iFilter::new(44100.0, 20000.0, 0.0),
A4I_r_1: A4iFilter::new(44100.0, 20000.0, 0.0),
A4I_r_2: A4iFilter::new(44100.0, 20000.0, 0.0),
cutoff_modulation: 0.0,
cutoff_modulation_2: 0.0,
cutoff_modulation: cutoff_mod,
cutoff_modulation_2: cutoff_mod_2,
resonance_modulation: 0.0,
resonance_modulation_2: 0.0,

Expand Down Expand Up @@ -3725,8 +3730,8 @@ UniRandom: Every voice uses its own unique random phase every note".to_string())
A4I_l_2: A4iFilter::new(44100.0, 20000.0, 0.0),
A4I_r_1: A4iFilter::new(44100.0, 20000.0, 0.0),
A4I_r_2: A4iFilter::new(44100.0, 20000.0, 0.0),
cutoff_modulation: 0.0,
cutoff_modulation_2: 0.0,
cutoff_modulation: cutoff_mod,
cutoff_modulation_2: cutoff_mod_2,
resonance_modulation: 0.0,
resonance_modulation_2: 0.0,

Expand Down Expand Up @@ -4274,8 +4279,8 @@ UniRandom: Every voice uses its own unique random phase every note".to_string())
A4I_l_2: A4iFilter::new(self.sample_rate, self.filter_cutoff_2, 0.0),
A4I_r_1: A4iFilter::new(self.sample_rate, self.filter_cutoff, 0.0),
A4I_r_2: A4iFilter::new(self.sample_rate, self.filter_cutoff_2, 0.0),
cutoff_modulation: 0.0,
cutoff_modulation_2: 0.0,
cutoff_modulation: cutoff_mod,
cutoff_modulation_2: cutoff_mod_2,
resonance_modulation: 0.0,
resonance_modulation_2: 0.0,

Expand Down Expand Up @@ -4882,25 +4887,26 @@ UniRandom: Every voice uses its own unique random phase every note".to_string())
voice.filter_state_1 = OscState::Sustaining;
}
// use proper variable now that there are four filters and multiple states
// This double addition of voice.cutoff_modulation + cutoff_mod will stack the mod at the time of the voice movement with the current
next_filter_step = match voice.filter_state_1 {
OscState::Attacking => {
(voice.filter_atk_smoother_1.next() + voice.cutoff_modulation).clamp(20.0, 20000.0)
(voice.filter_atk_smoother_1.next() + voice.cutoff_modulation + cutoff_mod).clamp(20.0, 20000.0)
}
OscState::Decaying => {
(voice.filter_dec_smoother_1.next() + voice.cutoff_modulation).clamp(20.0, 20000.0)
(voice.filter_dec_smoother_1.next() + voice.cutoff_modulation + cutoff_mod).clamp(20.0, 20000.0)
}
OscState::Sustaining => {
(voice.filter_dec_smoother_1.next() + voice.cutoff_modulation).clamp(20.0, 20000.0)
(voice.filter_dec_smoother_1.next() + voice.cutoff_modulation + cutoff_mod).clamp(20.0, 20000.0)
}
OscState::Releasing => {
if self.filter_env_release <= 0.0001 {
(voice.filter_dec_smoother_1.next() + voice.cutoff_modulation).clamp(20.0, 20000.0)
(voice.filter_dec_smoother_1.next() + voice.cutoff_modulation + cutoff_mod).clamp(20.0, 20000.0)
} else {
(voice.filter_rel_smoother_1.next() + voice.cutoff_modulation).clamp(20.0, 20000.0)
(voice.filter_rel_smoother_1.next() + voice.cutoff_modulation + cutoff_mod).clamp(20.0, 20000.0)
}
}
// I don't expect this to be used
_ => (self.filter_cutoff + voice.cutoff_modulation).clamp(20.0, 20000.0),
_ => (self.filter_cutoff + voice.cutoff_modulation + cutoff_mod).clamp(20.0, 20000.0),
};
}

Expand Down Expand Up @@ -4962,23 +4968,23 @@ UniRandom: Every voice uses its own unique random phase every note".to_string())
// use proper variable now that there are four filters and multiple states
next_filter_step_2 = match voice.filter_state_2 {
OscState::Attacking => {
(voice.filter_atk_smoother_2.next() + voice.cutoff_modulation_2).clamp(20.0, 20000.0)
(voice.filter_atk_smoother_2.next() + voice.cutoff_modulation_2 + cutoff_mod_2).clamp(20.0, 20000.0)
}
OscState::Decaying => {
(voice.filter_dec_smoother_2.next() + voice.cutoff_modulation_2).clamp(20.0, 20000.0)
(voice.filter_dec_smoother_2.next() + voice.cutoff_modulation_2 + cutoff_mod_2).clamp(20.0, 20000.0)
}
OscState::Sustaining => {
(voice.filter_dec_smoother_2.next() + voice.cutoff_modulation_2).clamp(20.0, 20000.0)
(voice.filter_dec_smoother_2.next() + voice.cutoff_modulation_2 + cutoff_mod_2).clamp(20.0, 20000.0)
}
OscState::Releasing => {
if self.filter_env_release_2 <= 0.0001 {
(voice.filter_dec_smoother_2.next() + voice.cutoff_modulation_2).clamp(20.0, 20000.0)
(voice.filter_dec_smoother_2.next() + voice.cutoff_modulation_2 + cutoff_mod_2).clamp(20.0, 20000.0)
} else {
(voice.filter_rel_smoother_2.next() + voice.cutoff_modulation_2).clamp(20.0, 20000.0)
(voice.filter_rel_smoother_2.next() + voice.cutoff_modulation_2 + cutoff_mod_2).clamp(20.0, 20000.0)
}
}
// I don't expect this to be used
_ => (self.filter_cutoff_2 + voice.cutoff_modulation_2).clamp(20.0, 20000.0),
_ => (self.filter_cutoff_2 + voice.cutoff_modulation_2 + cutoff_mod_2).clamp(20.0, 20000.0),
};
}

Expand Down Expand Up @@ -5426,8 +5432,9 @@ UniRandom: Every voice uses its own unique random phase every note".to_string())
}
}

let mut temp_unison_voice_l = 0.0;
let mut temp_unison_voice_r = 0.0;
// Stereo applies to unison voices
/*
for unison_voice in self.unison_voices.voices.iter_mut() {
// Get our current gain amount for use in match below
let temp_osc_gain_multiplier: f32 = match unison_voice.state {
Expand Down Expand Up @@ -5500,7 +5507,6 @@ UniRandom: Every voice uses its own unique random phase every note".to_string())
stereo_voices_l += left_amp;
stereo_voices_r += right_amp;
}
*/

// Sum our voices for output
summed_voices_l += center_voices_l;
Expand Down
34 changes: 10 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ impl Default for Actuate {
Self {
params: Arc::new(ActuateParams::new(
update_something.clone(),
clear_voices.clone(),
file_dialog.clone(),
update_current_preset.clone(),
)),
Expand Down Expand Up @@ -1073,7 +1072,6 @@ pub struct ActuateParams {
impl ActuateParams {
fn new(
update_something: Arc<AtomicBool>,
clear_voices: Arc<AtomicBool>,
file_dialog: Arc<AtomicBool>,
update_current_preset: Arc<AtomicBool>,
) -> Self {
Expand All @@ -1091,32 +1089,20 @@ impl ActuateParams {
voice_limit: IntParam::new("Max Voices", 64, IntRange::Linear { min: 1, max: 512 }),

audio_module_1_type: EnumParam::new("Type", AudioModuleType::Sine)
//.with_callback({
// let clear_voices = clear_voices.clone();
// Arc::new(move |_| clear_voices.store(true, Ordering::SeqCst))
//})
.with_callback({
.with_callback({
let update_something = update_something.clone();
Arc::new(move |_| update_something.store(true, Ordering::SeqCst))
}),
}),
audio_module_2_type: EnumParam::new("Type", AudioModuleType::Sine)
//.with_callback({
// let clear_voices = clear_voices.clone();
// Arc::new(move |_| clear_voices.store(true, Ordering::SeqCst))
//})
.with_callback({
let update_something = update_something.clone();
Arc::new(move |_| update_something.store(true, Ordering::SeqCst))
}),
.with_callback({
let update_something = update_something.clone();
Arc::new(move |_| update_something.store(true, Ordering::SeqCst))
}),
audio_module_3_type: EnumParam::new("Type", AudioModuleType::Sine)
//.with_callback({
// let clear_voices = clear_voices.clone();
// Arc::new(move |_| clear_voices.store(true, Ordering::SeqCst))
//})
.with_callback({
let update_something = update_something.clone();
Arc::new(move |_| update_something.store(true, Ordering::SeqCst))
}),
.with_callback({
let update_something = update_something.clone();
Arc::new(move |_| update_something.store(true, Ordering::SeqCst))
}),

audio_module_1_level: FloatParam::new(
"Level",
Expand Down

0 comments on commit e6a7abd

Please sign in to comment.