pub struct Rms<F, S>{ /* private fields */ }
Expand description
Iteratively extracts the RMS (root mean square) envelope from a window over a signal of sample
Frame
s.
Implementations§
Source§impl<F, S> Rms<F, S>
impl<F, S> Rms<F, S>
Sourcepub fn new(ring_buffer: Fixed<S>) -> Self
pub fn new(ring_buffer: Fixed<S>) -> Self
Construct a new Rms that uses the given ring buffer as its window.
The window size of the Rms is equal to the length of the given ring buffer.
use dasp_ring_buffer as ring_buffer;
use dasp_rms::Rms;
fn main() {
let window = ring_buffer::Fixed::from([[0.0]; 4]);
let mut rms = Rms::new(window);
rms.next([0.5]);
}
Sourcepub fn reset(&mut self)where
S: SliceMut,
pub fn reset(&mut self)where
S: SliceMut,
Zeroes the square_sum and the buffer of the window
.
use dasp_ring_buffer as ring_buffer;
use dasp_rms::Rms;
fn main() {
let window = ring_buffer::Fixed::from([[0.0]; 4]);
let mut rms = Rms::new(window);
rms.next([0.6]);
rms.next([0.9]);
rms.reset();
assert_eq!(rms.current(), [0.0]);
}
Sourcepub fn window_frames(&self) -> usize
pub fn window_frames(&self) -> usize
The length of the window as a number of frames.
use dasp_ring_buffer as ring_buffer;
use dasp_rms::Rms;
fn main() {
let window = ring_buffer::Fixed::from([[0.0]; 4]);
let mut rms = Rms::new(window);
assert_eq!(rms.window_frames(), 4);
rms.next([0.5]);
assert_eq!(rms.window_frames(), 4);
}
Sourcepub fn next(&mut self, new_frame: F) -> F::Floatwhere
S: SliceMut,
pub fn next(&mut self, new_frame: F) -> F::Floatwhere
S: SliceMut,
The next RMS given the new frame in the sequence.
The Rms pops its front frame and adds the new frame to the back.
The yielded RMS is the RMS of all frame squares in the window
after the new frame is
added.
This method uses Rms::next_squared
internally and then calculates the square root.
use dasp_ring_buffer as ring_buffer;
use dasp_rms::Rms;
fn main() {
let window = ring_buffer::Fixed::from([[0.0]; 4]);
let mut rms = Rms::new(window);
assert_eq!(rms.next([1.0]), [0.5]);
assert_eq!(rms.next([-1.0]), [0.7071067811865476]);
assert_eq!(rms.next([1.0]), [0.8660254037844386]);
assert_eq!(rms.next([-1.0]), [1.0]);
}
Sourcepub fn next_squared(&mut self, new_frame: F) -> F::Floatwhere
S: SliceMut,
pub fn next_squared(&mut self, new_frame: F) -> F::Floatwhere
S: SliceMut,
The same as Rms::next, but does not calculate the final square root required to determine the RMS.
Sourcepub fn into_parts(self) -> (Fixed<S>, S::Element)
pub fn into_parts(self) -> (Fixed<S>, S::Element)
Consumes the Rms and returns its inner ring buffer of squared frames along with a frame representing the sum of all frame squares contained within the ring buffer.
Sourcepub fn current(&self) -> F::Float
pub fn current(&self) -> F::Float
Calculates the RMS of all frames currently stored within the inner window.
use dasp_ring_buffer as ring_buffer;
use dasp_rms::Rms;
fn main() {
let window = ring_buffer::Fixed::from([[0.0]; 4]);
let mut rms = Rms::new(window);
assert_eq!(rms.current(), [0.0]);
rms.next([1.0]);
rms.next([1.0]);
rms.next([1.0]);
rms.next([1.0]);
assert_eq!(rms.current(), [1.0]);
}