pub struct AtomicLoudnessState {
pub target_gain_db: AtomicF64,
pub current_gain_db: AtomicF64,
pub smoothing_coeff: AtomicF64,
pub album_gain_db: AtomicF64,
pub preamp_gain_db: AtomicF64,
pub enabled: AtomicBool,
pub mode: AtomicU8,
}Expand description
Atomic loudness state for lock-free audio thread access. Uses AtomicF64 with Relaxed ordering (gains don’t need strict synchronization).
Fields§
§target_gain_db: AtomicF64Target gain in dB (set by main thread, read by audio thread)
current_gain_db: AtomicF64Current smoothed gain in dB (updated by audio thread)
smoothing_coeff: AtomicF64Smoothing coefficient per sample (< 1.0, for multiplication)
album_gain_db: AtomicF64Album gain for Album mode (same for all tracks in album)
preamp_gain_db: AtomicF64Preamp gain for headroom adjustment (default -3 dB)
enabled: AtomicBoolEnable/disable normalization
mode: AtomicU8Normalization mode: 0=Track, 1=Album, 2=Streaming
Implementations§
Source§impl AtomicLoudnessState
impl AtomicLoudnessState
pub fn new(smoothing_time_ms: f64, sample_rate: u32) -> Self
Sourcepub fn set_target_gain(&self, gain_db: f64)
pub fn set_target_gain(&self, gain_db: f64)
Set target gain.
H-2 fix: Guards against NaN/Infinity values that could propagate through the
audio path and produce corrupted output by coercing them to 0 dB (no gain).
This is reachable from the audio thread in streaming mode
(LoudnessNormalizer::process), so the non-finite branch must stay
allocation- and log-free; non-realtime callers that want to report invalid
loudness (e.g. analyze_track) log it on their own path.
Sourcepub fn set_album_gain(&self, gain_db: f64)
pub fn set_album_gain(&self, gain_db: f64)
Set album gain (call from main thread)
Sourcepub fn set_preamp_gain(&self, gain_db: f64)
pub fn set_preamp_gain(&self, gain_db: f64)
Set preamp gain in dB (call from main thread)
Sourcepub fn set_enabled(&self, enabled: bool)
pub fn set_enabled(&self, enabled: bool)
Set enabled state
Sourcepub fn set_mode(&self, mode: u8)
pub fn set_mode(&self, mode: u8)
Set mode: 0=Track, 1=Album, 2=Streaming, 3=ReplayGainTrack, 4=ReplayGainAlbum
Sourcepub fn get_mode(&self) -> NormalizationMode
pub fn get_mode(&self) -> NormalizationMode
Get normalization mode as enum
Sourcepub fn set_smoothing(&self, smoothing_time_ms: f64, sample_rate: u32)
pub fn set_smoothing(&self, smoothing_time_ms: f64, sample_rate: u32)
Update smoothing coefficient
Sourcepub fn process_gain(&self, frames: usize) -> f64
pub fn process_gain(&self, frames: usize) -> f64
Process gain for a chunk (call from audio thread - lock-free) Returns the linear gain to apply (includes preamp)
All fields are read with Relaxed ordering. They are independent atomics, so
this is deliberately not a consistent snapshot: a concurrent main-thread
update can leave the mode and the gains momentarily mismatched for one block.
That is acceptable because the resulting gain is exponentially smoothed (see
remaining_factor below), so a single slightly-wrong target is inaudible and
self-corrects on the next call.
Sourcepub fn get_info(&self) -> LoudnessInfo
pub fn get_info(&self) -> LoudnessInfo
Get current loudness info (for API responses)
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for AtomicLoudnessState
impl !RefUnwindSafe for AtomicLoudnessState
impl Send for AtomicLoudnessState
impl Sync for AtomicLoudnessState
impl Unpin for AtomicLoudnessState
impl UnsafeUnpin for AtomicLoudnessState
impl UnwindSafe for AtomicLoudnessState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more