Skip to content

Commit

Permalink
make the envelope gain a mapped db gain
Browse files Browse the repository at this point in the history
better matches what I'd expect if my plugin is gonna fade the delay
in or out in x seconds
  • Loading branch information
magnetophon committed Nov 17, 2024
1 parent 3ee7772 commit 6d58d47
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
CLEAR_TAPS, LEARNING, LOCK_TAPS, MUTE_IN, MUTE_OUT, NO_LEARNED_NOTE, NUM_TAPS,
};

const GUI_SMOOTHING_DECAY_MS: f64 = 240.0;
const GUI_SMOOTHING_DECAY_MS: f64 = 280.0;

/// The minimum decibel value that the meters display
const MIN_TICK: f32 = -60.0;
Expand Down
37 changes: 31 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,12 @@ impl Plugin for Del2 {
for (value_idx, sample_idx) in (block_start..block_end).enumerate() {
let pre_filter_gain = self.global_drive[value_idx]
* gain[value_idx]
* self.delay_tap_amp_envelope[value_idx];
* Self::db_to_gain_with_remap(
self.delay_tap_amp_envelope[value_idx],
-99.0,
-47.0,
);
// * util::db_to_gain(self.delay_tap_amp_envelope[value_idx], -99.0, -47.0);

self.delayed_audio_l[tap_index][sample_idx] *= pre_filter_gain;
self.delayed_audio_r[tap_index][sample_idx] *= pre_filter_gain;
Expand Down Expand Up @@ -1278,7 +1283,7 @@ impl Del2 {
// Conditionally reset and configure the amplitude envelope
if self.params.global.mute_is_toggle.value() {
amp_envelope.reset(0.0);
amp_envelope.set_target(sample_rate, 1.0);
amp_envelope.set_target(sample_rate, 0.0);
}

// Start delay tap and configure its properties
Expand Down Expand Up @@ -1608,7 +1613,9 @@ impl Del2 {
delay_tap.releasing = true;
delay_tap.amp_envelope.style =
SmoothingStyle::Linear(self.params.global.release_ms.value());
delay_tap.amp_envelope.set_target(sample_rate, 0.0);
delay_tap
.amp_envelope
.set_target(sample_rate, util::MINUS_INFINITY_DB);
}
}

Expand All @@ -1633,11 +1640,13 @@ impl Del2 {
if new_mute {
delay_tap.amp_envelope.style =
SmoothingStyle::Linear(self.params.global.release_ms.value());
delay_tap.amp_envelope.set_target(sample_rate, 0.0);
delay_tap
.amp_envelope
.set_target(sample_rate, util::MINUS_INFINITY_DB);
} else {
delay_tap.amp_envelope.style =
SmoothingStyle::Linear(self.params.global.attack_ms.value());
delay_tap.amp_envelope.set_target(sample_rate, 1.0);
delay_tap.amp_envelope.set_target(sample_rate, 0.0);
}
delay_tap.is_muted = new_mute;
}
Expand Down Expand Up @@ -1682,6 +1691,23 @@ impl Del2 {
}
}
}

fn db_to_gain_with_remap(dbs: f32, remap_input_db: f32, remap_target_db: f32) -> f32 {
if dbs >= 0.0 {
1.0 // At 0.0 input, maximum gain
} else if dbs > remap_input_db {
// fade towards remap_target_db when the input is above remap_input_db
// Normalize the db range for use with db_to_gain_fast
let normalized_db = remap_target_db * (dbs / remap_input_db);
util::db_to_gain_fast(normalized_db)
} else if dbs > util::MINUS_INFINITY_DB {
// Below remap_input_db, fade toward 0 using db_to_gain_fast
let normalized_db_lower = remap_target_db * (dbs / util::MINUS_INFINITY_DB);
util::db_to_gain_fast(normalized_db_lower)
} else {
0.0 // Anything below MINUS_INFINITY_DB results in 0 gain
}
}
}

/// Compute a delay tap ID in case the host doesn't provide them. Polyphonic modulation will not work in
Expand Down Expand Up @@ -1757,7 +1783,6 @@ impl MyLadderMode {

Self::from_index(interpolated_index).0
}

const fn lp6() -> Self {
Self(LadderMode::LP6)
}
Expand Down

0 comments on commit 6d58d47

Please sign in to comment.