1
0
Fork 0

Move knee scaling factor to a function

This commit is contained in:
Robbert van der Helm 2022-07-25 15:56:30 +02:00
parent 49d5ba147a
commit dd49bd9e7f

View file

@ -601,11 +601,11 @@ impl CompressorBank {
// bandwidths, the middle values needs to be pushed more towards the post-knee threshold // bandwidths, the middle values needs to be pushed more towards the post-knee threshold
// than with lower knee values. These scaling factors are used as exponents. // than with lower knee values. These scaling factors are used as exponents.
let downwards_knee_scaling_factor = let downwards_knee_scaling_factor =
((params.compressors.downwards.knee_width_db.value * 2.0) + 2.0).log2() - 1.0; compute_knee_scaling_factor(params.compressors.downwards.knee_width_db.value);
// Note the square root here, since the curve needs to go the other way for the upwards // Note the square root here, since the curve needs to go the other way for the upwards
// version. // version
let upwards_knee_scaling_factor = let upwards_knee_scaling_factor =
(((params.compressors.upwards.knee_width_db.value * 2.0) + 2.0).log2() - 1.0).sqrt(); compute_knee_scaling_factor(params.compressors.upwards.knee_width_db.value).sqrt();
// Is this what they mean by zip and and ship it? // Is this what they mean by zip and and ship it?
let downwards_knees = self let downwards_knees = self
@ -804,6 +804,13 @@ impl CompressorBank {
} }
} }
/// Get the knee scaling factor for converting a linear `[0, 1]` knee range into the correct curve
/// for the soft knee. This is used to blend between compression at the knee start to compression at
/// the actual threshold. For upwards compression this needs an additional square root.
fn compute_knee_scaling_factor(downwards_knee_width_db: f32) -> f32 {
((downwards_knee_width_db * 2.0) + 2.0).log2() - 1.0
}
/// Get the compression scaling factor for downwards compression with the supplied parameters. The /// Get the compression scaling factor for downwards compression with the supplied parameters. The
/// input signal can be multiplied by this factor to get the compressed output signal. All /// input signal can be multiplied by this factor to get the compressed output signal. All
/// parameters are linear gain values. /// parameters are linear gain values.