1
0
Fork 0

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:
Robbert van der Helm 2022-09-04 19:09:22 +02:00
parent 3a9d56e956
commit cd02ebb839
3 changed files with 24 additions and 6 deletions

View file

@ -3,6 +3,9 @@ use nih_plug::prelude::*;
use nih_plug_egui::{create_egui_editor, egui, widgets, EguiState}; use nih_plug_egui::{create_egui_editor, egui, widgets, EguiState};
use std::sync::Arc; use std::sync::Arc;
/// 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. /// This is mostly identical to the gain example, minus some fluff, and with a GUI.
struct Gain { struct Gain {
params: Arc<GainParams>, params: Arc<GainParams>,
@ -154,8 +157,11 @@ impl Plugin for Gain {
buffer_config: &BufferConfig, buffer_config: &BufferConfig,
_context: &mut impl InitContext, _context: &mut impl InitContext,
) -> bool { ) -> bool {
// TODO: How do you tie this exponential decay to an actual time span? // After `PEAK_METER_DECAY_MS` milliseconds of pure silence, the peak meter's value should
self.peak_meter_decay_weight = 0.9992f32.powf(44_100.0 / buffer_config.sample_rate); // 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 true
} }

View file

@ -5,6 +5,9 @@ use std::sync::Arc;
mod editor; 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. /// This is mostly identical to the gain example, minus some fluff, and with a GUI.
struct Gain { struct Gain {
params: Arc<GainParams>, params: Arc<GainParams>,
@ -100,8 +103,11 @@ impl Plugin for Gain {
buffer_config: &BufferConfig, buffer_config: &BufferConfig,
_context: &mut impl InitContext, _context: &mut impl InitContext,
) -> bool { ) -> bool {
// TODO: How do you tie this exponential decay to an actual time span? // After `PEAK_METER_DECAY_MS` milliseconds of pure silence, the peak meter's value should
self.peak_meter_decay_weight = 0.9992f32.powf(44_100.0 / buffer_config.sample_rate); // 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 true
} }

View file

@ -5,6 +5,9 @@ use std::sync::Arc;
mod editor; 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. /// This is mostly identical to the gain example, minus some fluff, and with a GUI.
pub struct Gain { pub struct Gain {
params: Arc<GainParams>, params: Arc<GainParams>,
@ -99,8 +102,11 @@ impl Plugin for Gain {
buffer_config: &BufferConfig, buffer_config: &BufferConfig,
_context: &mut impl InitContext, _context: &mut impl InitContext,
) -> bool { ) -> bool {
// TODO: How do you tie this exponential decay to an actual time span? // After `PEAK_METER_DECAY_MS` milliseconds of pure silence, the peak meter's value should
self.peak_meter_decay_weight = 0.9992f32.powf(44_100.0 / buffer_config.sample_rate); // 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 true
} }