Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
1b9c188
refactor: Modernise AGC state management and improve gain control sta…
UnknownSuperficialNight May 1, 2026
5e1a869
fix: Use `current_gain` as fallback during silence in AGC `rms_gain` …
UnknownSuperficialNight May 1, 2026
233ba47
fix: clamp peak_level to 1.0 to prevent decoder artifacts
UnknownSuperficialNight May 1, 2026
c502095
fix: clamp `rms` to `1.0` to prevent decoder artifacts
UnknownSuperficialNight May 2, 2026
5b256a1
chore: Increase `RMS_WINDOW_SIZE` to `1024` samples
UnknownSuperficialNight May 6, 2026
c98b781
refactor: Move `fast_exp` from `AGC` to shared `math` module
UnknownSuperficialNight May 15, 2026
a54f9b6
chore: Use `from_micros` for `500µs` release time
UnknownSuperficialNight May 15, 2026
110030f
Revert "fix: clamp `rms` to `1.0` to prevent decoder artifacts"
UnknownSuperficialNight Jun 6, 2026
1898760
Revert "fix: clamp peak_level to 1.0 to prevent decoder artifacts"
UnknownSuperficialNight Jun 6, 2026
d3c5d1b
refactor: Set AGC `Floor` To `1.0` apon initialisation
UnknownSuperficialNight Jun 6, 2026
66a7652
feat: Make AGC floor configurable at initialization
UnknownSuperficialNight Jun 20, 2026
3363516
refactor: Dynamically adjust RMS window size based on `sample_rate` a…
UnknownSuperficialNight Jun 27, 2026
898abe8
perf: Optimize `CircularBufferRMS` RMS calculation to avoid division
UnknownSuperficialNight Jun 27, 2026
181314a
chore: Remove irrelevant parameters for AGC
UnknownSuperficialNight Jun 27, 2026
9c8c10e
feat: Add `music` and `speech` presets for `AGC`
UnknownSuperficialNight Jun 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ pub(crate) fn duration_from_secs(secs: Float) -> Duration {
}
}

/// Fast approximation of `exp(x)` using Horner's Method for Polynomial Evaluation.
/// This function approximates the exponential function by evaluating the
/// third-order Taylor polynomial using Horner's scheme, which reduces the
/// number of multiplications and improves numerical stability.
///
/// This approximation is valid for small values of `x` (near zero) and is
/// used in the AGC algorithm to efficiently compute the release coefficient.
/// It provides a good balance between speed and accuracy, resulting in
/// faster benchmark times compared to the standard `exp` function.
#[inline]
pub(crate) fn fast_exp(x: Float) -> Float {
// Horner's method: 1 + x*(1 + x*(0.5 + x/6))
1.0 + x * (1.0 + x * (0.5 + x / 6.0))
}

/// Utility macro for getting a `NonZero` from a literal. Especially
/// useful for passing in `ChannelCount` and `Samplerate`.
/// Equivalent to: `const { core::num::NonZero::new($n).unwrap() }`
Expand Down
Loading
Loading