Removed MAX_PEAK_LEVEL now uses target_level as intended and styled documentation

This commit is contained in:
UnknownSuperficialNight 2024-09-29 13:36:55 +13:00
parent ce3d7e0bd2
commit 28b3c4b80c
2 changed files with 13 additions and 16 deletions

View file

@ -28,9 +28,6 @@ const RMS_WINDOW_SIZE: usize = 1024;
/// Balances between responsiveness and stability.
const MIN_ATTACK_COEFF: f32 = 0.05;
/// Maximum allowed peak level to prevent clipping
const MAX_PEAK_LEVEL: f32 = 0.99;
/// Automatic Gain Control filter for maintaining consistent output levels.
///
/// This struct implements an AGC algorithm that dynamically adjusts audio levels
@ -186,7 +183,7 @@ where
#[inline]
fn calculate_peak_gain(&self) -> f32 {
if self.peak_level > 0.0 {
(MAX_PEAK_LEVEL / self.peak_level).min(self.absolute_max_gain)
(self.target_level / self.peak_level).min(self.absolute_max_gain)
} else {
self.absolute_max_gain
}

View file

@ -241,17 +241,17 @@ where
///
/// # Parameters
///
/// * `target_level`:
/// TL;DR: Desired output level. 1.0 = original level, > 1.0 amplifies, < 1.0 reduces.
///* `target_level`:
/// **TL;DR**: Desired output level. 1.0 = original level, > 1.0 amplifies, < 1.0 reduces.
///
/// The desired output level, where 1.0 represents the original sound level.
/// Values above 1.0 will amplify the sound, while values below 1.0 will lower it.
/// For example, a target_level of 1.4 means that at normal sound levels, the AGC
/// will aim to increase the gain by a factor of 1.4, resulting in a minimum 40% amplification.
/// A recommended level is 1.0, which maintains the original sound level.
/// A recommended level is `1.0`, which maintains the original sound level.
///
/// * `attack_time`:
/// TL;DR: Response time for volume increases. Shorter = faster but may cause abrupt changes. Recommended: 2.0 seconds.
///* `attack_time`:
/// **TL;DR**: Response time for volume increases. Shorter = faster but may cause abrupt changes. **Recommended: `4.0` seconds**.
///
/// The time (in seconds) for the AGC to respond to input level increases.
/// Shorter times mean faster response but may cause abrupt changes. Longer times result
@ -260,10 +260,10 @@ where
/// AGC miss important volume changes or react too slowly to sudden loud passages. Very
/// high values might result in excessively loud output or sluggish response, as the AGC's
/// adjustment speed is limited by the attack time. Balance is key for optimal performance.
/// A recommended attack_time of 2.0 seconds provides a sweet spot for most applications.
/// A recommended attack_time of `4.0` seconds provides a sweet spot for most applications.
///
/// * `release_time`:
/// TL;DR: Response time for volume decreases. Shorter = faster gain reduction. Recommended: 0.01 seconds.
///* `release_time`:
/// **TL;DR**: Response time for volume decreases. Shorter = faster gain reduction. **Recommended: `0.005` seconds**.
///
/// The time (in seconds) for the AGC to respond to input level decreases.
/// This parameter controls how quickly the gain is reduced when the signal level drops.
@ -273,18 +273,18 @@ where
/// However, if the release_time is too high, the AGC may not be able to lower the gain
/// quickly enough, potentially leading to clipping and distorted sound before it can adjust.
/// Finding the right balance is crucial for maintaining natural-sounding dynamics and
/// preventing distortion. A recommended release_time of 0.01 seconds often works well for
/// preventing distortion. A recommended release_time of `0.005` seconds often works well for
/// general use, providing a good balance between responsiveness and smooth transitions.
///
/// * `absolute_max_gain`:
/// TL;DR: Maximum allowed gain. Prevents over-amplification. Recommended: 4.0.
///* `absolute_max_gain`:
/// **TL;DR**: Maximum allowed gain. Prevents over-amplification. **Recommended: `5.0`**.
///
/// The maximum gain that can be applied to the signal.
/// This parameter acts as a safeguard against excessive amplification of quiet signals
/// or background noise. It establishes an upper boundary for the AGC's signal boost,
/// effectively preventing distortion or overamplification of low-level sounds.
/// This is crucial for maintaining audio quality and preventing unexpected volume spikes.
/// A recommended value for `absolute_max_gain` is 4, which provides a good balance between
/// A recommended value for `absolute_max_gain` is `5`, which provides a good balance between
/// amplification capability and protection against distortion in most scenarios.
#[inline]
fn automatic_gain_control(