pub struct RmsWindow { /* private fields */ }Expand description
A moving-window RMS estimator over the most recent N samples.
Unlike AudioLevels’s per-block RMS (which resets every buffer), this gives a smooth
level over a fixed time window regardless of block size — feed it samples or whole blocks
and read rms. The window length in samples is window_secs · sample_rate.
use vst3_host::audio::RmsWindow;
let mut rms = RmsWindow::new(4);
for _ in 0..4 { rms.push_sample(0.5); }
assert!((rms.rms() - 0.5).abs() < 1e-6); // constant 0.5 → RMS 0.5Implementations§
Source§impl RmsWindow
impl RmsWindow
Sourcepub fn new(window_samples: usize) -> Self
pub fn new(window_samples: usize) -> Self
Create a window holding the most recent window_samples samples (minimum 1).
Sourcepub fn from_duration(window_secs: f32, sample_rate: f64) -> Self
pub fn from_duration(window_secs: f32, sample_rate: f64) -> Self
Create a window sized for window_secs of audio at sample_rate Hz.
The sample count is clamped: a non-finite or absurd duration/rate would otherwise saturate
to usize::MAX and panic in VecDeque::with_capacity.
Sourcepub fn push_sample(&mut self, sample: f32)
pub fn push_sample(&mut self, sample: f32)
Add one sample, evicting the oldest if the window is full.
Sourcepub fn push_block(&mut self, block: &[f32])
pub fn push_block(&mut self, block: &[f32])
Add a whole block of samples.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RmsWindow
impl RefUnwindSafe for RmsWindow
impl Send for RmsWindow
impl Sync for RmsWindow
impl Unpin for RmsWindow
impl UnsafeUnpin for RmsWindow
impl UnwindSafe for RmsWindow
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
Mutably borrows from an owned value. Read more