dasp_rms

Struct Rms

Source
pub struct Rms<F, S>
where F: Frame, S: Slice<Element = F::Float>,
{ /* private fields */ }
Expand description

Iteratively extracts the RMS (root mean square) envelope from a window over a signal of sample Frames.

Implementations§

Source§

impl<F, S> Rms<F, S>
where F: Frame, S: Slice<Element = F::Float>,

Source

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]);
}
Source

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]);
}
Source

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);
}
Source

pub fn next(&mut self, new_frame: F) -> F::Float
where 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]);
}
Source

pub fn next_squared(&mut self, new_frame: F) -> F::Float
where S: SliceMut,

The same as Rms::next, but does not calculate the final square root required to determine the RMS.

Source

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.

Source

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]);
}

Trait Implementations§

Source§

impl<F, S> Clone for Rms<F, S>
where F: Frame + Clone, S: Slice<Element = F::Float> + Clone, F::Float: Clone,

Source§

fn clone(&self) -> Rms<F, S>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F, S> Debug for Rms<F, S>
where F: Frame, F::Float: Debug, S: Debug + Slice<Element = F::Float>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<F, S> Freeze for Rms<F, S>
where <F as Frame>::Float: Freeze, S: Freeze,

§

impl<F, S> RefUnwindSafe for Rms<F, S>

§

impl<F, S> Send for Rms<F, S>
where <F as Frame>::Float: Send, F: Send, S: Send,

§

impl<F, S> Sync for Rms<F, S>
where <F as Frame>::Float: Sync, F: Sync, S: Sync,

§

impl<F, S> Unpin for Rms<F, S>
where <F as Frame>::Float: Unpin, F: Unpin, S: Unpin,

§

impl<F, S> UnwindSafe for Rms<F, S>
where <F as Frame>::Float: UnwindSafe, F: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,