mirror of
https://github.com/robbert-vdh/nih-plug.git
synced 2026-07-01 02:36:54 +00:00
Use less arbitrary decay weights for the gain GUIs
This solves the same problem as #27 but in a cleaner way. The previous commits refactored the smoothing to make it possible to use the calculations in plugin code to do the same thing as #27, but then I realized that that doesn't make much sense since the time to decay into complete silence isn't very meaningful for this kind of computation.
This commit is contained in:
@@ -5,6 +5,9 @@ use std::sync::Arc;
|
||||
|
||||
mod editor;
|
||||
|
||||
/// The time it takes for the peak meter to decay by 12 dB after switching to complete silence.
|
||||
const PEAK_METER_DECAY_MS: f64 = 150.0;
|
||||
|
||||
/// This is mostly identical to the gain example, minus some fluff, and with a GUI.
|
||||
pub struct Gain {
|
||||
params: Arc<GainParams>,
|
||||
@@ -99,8 +102,11 @@ impl Plugin for Gain {
|
||||
buffer_config: &BufferConfig,
|
||||
_context: &mut impl InitContext,
|
||||
) -> bool {
|
||||
// TODO: How do you tie this exponential decay to an actual time span?
|
||||
self.peak_meter_decay_weight = 0.9992f32.powf(44_100.0 / buffer_config.sample_rate);
|
||||
// After `PEAK_METER_DECAY_MS` milliseconds of pure silence, the peak meter's value should
|
||||
// have dropped by 12 dB
|
||||
self.peak_meter_decay_weight = 0.25f64
|
||||
.powf((buffer_config.sample_rate as f64 * PEAK_METER_DECAY_MS / 1000.0).recip())
|
||||
as f32;
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user