Trait sampara::signal::Signal[][src]

pub trait Signal<const N: usize> {
    type Frame: Frame<N>;
    fn next(&mut self) -> Option<Self::Frame>;

    fn sig_next(&mut self) -> Self::Frame { ... }
fn by_ref(&mut self) -> &mut Self
    where
        Self: Sized
, { ... }
fn map<F, M, const NF: usize>(self, func: M) -> Map<Self, F, M, N, NF>
    where
        Self: Sized,
        F: Frame<NF>,
        M: FnMut(Self::Frame) -> F
, { ... }
fn zip_map<O, F, M, const NO: usize, const NF: usize>(
        self,
        other: O,
        func: M
    ) -> ZipMap<Self, O, F, M, N, NO, NF>
    where
        Self: Sized,
        O: Signal<NO>,
        F: Frame<NF>,
        M: FnMut(Self::Frame, O::Frame) -> F
, { ... }
fn add_signal<B>(self, other: B) -> AddSignal<Self, B, N>
    where
        Self: Sized,
        B: Signal<N>,
        Self::Frame: Frame<N, Signed = <B::Frame as Frame<N>>::Signed>
, { ... }
fn mul_signal<B>(self, other: B) -> MulSignal<Self, B, N>
    where
        Self: Sized,
        B: Signal<N>,
        Self::Frame: Frame<N, Float = <B::Frame as Frame<N>>::Float>
, { ... }
fn add_frame<F>(self, frame: F) -> AddFrame<Self, F, N>
    where
        Self: Sized,
        Self::Frame: Frame<N, Signed = F>,
        F: Frame<N>
, { ... }
fn mul_frame<F>(self, frame: F) -> MulFrame<Self, F, N>
    where
        Self: Sized,
        Self::Frame: Frame<N, Float = F>,
        F: Frame<N>
, { ... }
fn add_amp<X>(self, amp: X) -> AddAmp<Self, X, N>
    where
        Self: Sized,
        Self::Frame: Frame<N>,
        <Self::Frame as Frame<N>>::Sample: Sample<Signed = X>,
        X: Sample
, { ... }
fn mul_amp<X>(self, amp: X) -> MulAmp<Self, X, N>
    where
        Self: Sized,
        Self::Frame: Frame<N>,
        <Self::Frame as Frame<N>>::Sample: Sample<Float = X>,
        X: Sample
, { ... }
fn delay(self, n_frames: usize) -> Delay<Self, N>
    where
        Self: Sized
, { ... }
fn inspect<F>(self, func: F) -> Inspect<Self, F, N>
    where
        Self: Sized,
        F: FnMut(&Self::Frame)
, { ... }
fn take(self, n: usize) -> Take<Self, N>
    where
        Self: Sized
, { ... }
fn into_iter(self) -> IntoIter<Self, N>

Notable traits for IntoIter<S, N>

impl<S, const N: usize> Iterator for IntoIter<S, N> where
    S: Signal<N>, 
type Item = S::Frame;

    where
        Self: Sized
, { ... } }

Types that yield a sequence of Frames, representing an audio signal.

This trait is inspired by the Iterator trait and has similar methods and adaptors, but with a DSP-related focus.

Associated Types

type Frame: Frame<N>[src]

The Frame type returned by this Signal.

Loading content...

Required methods

fn next(&mut self) -> Option<Self::Frame>[src]

Advances Self and returns the next Frame, or None if there are no more to yield.

Loading content...

Provided methods

fn sig_next(&mut self) -> Self::Frame[src]

Similar to [next], but will always yield a Frame. Yields Frame::EQUILIBRIUM if there are no more actual Frames to yield.

fn by_ref(&mut self) -> &mut Self where
    Self: Sized
[src]

Borrows this Signal rather than consuming it.

This is useful for applying adaptors while still retaining ownership of the original Signal.

use sampara::{signal, Signal};

fn main() {
    let mut signal = signal::from_frames(vec![0, 1, 2, 3]);
    assert_eq!(signal.next(), Some(0));
    assert_eq!(signal.by_ref().add_amp(10).next(), Some(11));
    assert_eq!(signal.by_ref().mul_amp(2.5_f32).next(), Some(5));
    assert_eq!(signal.next(), Some(3));
}

fn map<F, M, const NF: usize>(self, func: M) -> Map<Self, F, M, N, NF> where
    Self: Sized,
    F: Frame<NF>,
    M: FnMut(Self::Frame) -> F, 
[src]

Creates a new Signal that applies a function to each Frame of Self.

fn zip_map<O, F, M, const NO: usize, const NF: usize>(
    self,
    other: O,
    func: M
) -> ZipMap<Self, O, F, M, N, NO, NF> where
    Self: Sized,
    O: Signal<NO>,
    F: Frame<NF>,
    M: FnMut(Self::Frame, O::Frame) -> F, 
[src]

Creates a new Signal that applies a function to each pair of Frames in Self and another Signal.

fn add_signal<B>(self, other: B) -> AddSignal<Self, B, N> where
    Self: Sized,
    B: Signal<N>,
    Self::Frame: Frame<N, Signed = <B::Frame as Frame<N>>::Signed>, 
[src]

Creates a new Signal that yields the sum of pairs of Frames yielded by Self and another Signal in lockstep.

fn mul_signal<B>(self, other: B) -> MulSignal<Self, B, N> where
    Self: Sized,
    B: Signal<N>,
    Self::Frame: Frame<N, Float = <B::Frame as Frame<N>>::Float>, 
[src]

Creates a new Signal that yields the product of pairs of Frames yielded by Self and another Signal in lockstep.

fn add_frame<F>(self, frame: F) -> AddFrame<Self, F, N> where
    Self: Sized,
    Self::Frame: Frame<N, Signed = F>,
    F: Frame<N>, 
[src]

Creates a new Signal that yields each Frame of a Signal summed with a constant Frame.

fn mul_frame<F>(self, frame: F) -> MulFrame<Self, F, N> where
    Self: Sized,
    Self::Frame: Frame<N, Float = F>,
    F: Frame<N>, 
[src]

Creates a new Signal that yields each Frame of a Signal multiplied with a constant Frame.

fn add_amp<X>(self, amp: X) -> AddAmp<Self, X, N> where
    Self: Sized,
    Self::Frame: Frame<N>,
    <Self::Frame as Frame<N>>::Sample: Sample<Signed = X>,
    X: Sample
[src]

Creates a new Signal that yields each Frame of a Signal with each channel summed with a constant Sample.

fn mul_amp<X>(self, amp: X) -> MulAmp<Self, X, N> where
    Self: Sized,
    Self::Frame: Frame<N>,
    <Self::Frame as Frame<N>>::Sample: Sample<Float = X>,
    X: Sample
[src]

Creates a new Signal that yields each Frame of a Signal with each channel multiplied with a constant Sample.

fn delay(self, n_frames: usize) -> Delay<Self, N> where
    Self: Sized
[src]

Delays Self by a given number of frames. The delay is performed by yielding Frame::EQUILIBRIUM that number of times before continuing to yield frames from Self.

fn inspect<F>(self, func: F) -> Inspect<Self, F, N> where
    Self: Sized,
    F: FnMut(&Self::Frame), 
[src]

Calls an inspection function on each Frame yielded by this Signal, and then passes the Frame through.

use sampara::{signal, Signal};

fn main() {
    let mut max: Option<i32> = None;
    let mut signal = signal::from_frames(vec![2i32, 3, 1])
        .inspect(|&f| {
            if let Some(m) = max {
                max.replace(m.max(f));
            } else {
                max = Some(f);
            }
        });

    assert_eq!(signal.next(), Some(2));
    assert_eq!(signal.next(), Some(3));
    assert_eq!(signal.next(), Some(1));
    assert_eq!(signal.next(), None);
    assert_eq!(max, Some(3));
}

fn take(self, n: usize) -> Take<Self, N> where
    Self: Sized
[src]

Returns a new Signal that yields only the first N Frames of Self.

use sampara::{signal, Signal};

fn main() {
    let mut signal = signal::from_frames(0u8..=99)
        .take(3);

    assert_eq!(signal.next(), Some(0));
    assert_eq!(signal.next(), Some(1));
    assert_eq!(signal.next(), Some(2));
    assert_eq!(signal.next(), None);
}

fn into_iter(self) -> IntoIter<Self, N>

Notable traits for IntoIter<S, N>

impl<S, const N: usize> Iterator for IntoIter<S, N> where
    S: Signal<N>, 
type Item = S::Frame;
where
    Self: Sized
[src]

Converts this Signal into an Iterator yielding Frames.

use sampara::{signal, Signal};

fn main() {
    let signal = signal::from_frames(vec![2i32, 3, 1]).add_amp(5);
    let iter = signal.into_iter();

    assert_eq!(iter.collect::<Vec<_>>(), vec![7, 8, 6]);
}
Loading content...

Implementations on Foreign Types

impl<S, const N: usize> Signal<N> for &mut S where
    S: Signal<N>, 
[src]

type Frame = S::Frame

Loading content...

Implementors

impl<A, B, const N: usize> Signal<N> for AddSignal<A, B, N> where
    A: Signal<N>,
    B: Signal<N>,
    A::Frame: Frame<N, Signed = <B::Frame as Frame<N>>::Signed>, 
[src]

type Frame = A::Frame

impl<A, B, const N: usize> Signal<N> for MulSignal<A, B, N> where
    A: Signal<N>,
    B: Signal<N>,
    A::Frame: Frame<N, Float = <B::Frame as Frame<N>>::Float>, 
[src]

type Frame = A::Frame

impl<D, const N: usize> Signal<N> for Phase<D, N> where
    D: Delta<N>, 
[src]

type Frame = D::Delta

impl<D, const N: usize> Signal<N> for Saw<D, N> where
    D: Delta<N>, 
[src]

type Frame = D::Delta

impl<D, const N: usize> Signal<N> for Sine<D, N> where
    D: Delta<N>, 
[src]

type Frame = D::Delta

impl<D, const N: usize> Signal<N> for Square<D, N> where
    D: Delta<N>, 
[src]

type Frame = D::Delta

impl<F, G, const N: usize> Signal<N> for FromFn<F, G, N> where
    F: Frame<N>,
    G: FnMut() -> Option<F>, 
[src]

type Frame = F

impl<F, I, const N: usize> Signal<N> for FromSamples<F, I, N> where
    F: Frame<N, Sample = I::Item>,
    I: Iterator,
    I::Item: Sample
[src]

type Frame = F

impl<F, const N: usize> Signal<N> for Constant<F, N> where
    F: Frame<N>, 
[src]

type Frame = F

impl<F, const N: usize> Signal<N> for Empty<F, N> where
    F: Frame<N>, 
[src]

type Frame = F

impl<F, const N: usize> Signal<N> for Equilibrium<F, N> where
    F: Frame<N>, 
[src]

type Frame = F

impl<I, const N: usize> Signal<N> for FromFrames<I, N> where
    I: Iterator,
    I::Item: Frame<N>, 
[src]

type Frame = I::Item

impl<S, F, M, const N: usize, const NF: usize> Signal<NF> for Map<S, F, M, N, NF> where
    S: Signal<N>,
    F: Frame<NF>,
    M: FnMut(S::Frame) -> F, 
[src]

type Frame = F

impl<S, F, const N: usize> Signal<N> for AddFrame<S, F, N> where
    S: Signal<N>,
    S::Frame: Frame<N, Signed = F>,
    F: Frame<N>, 
[src]

type Frame = S::Frame

impl<S, F, const N: usize> Signal<N> for Inspect<S, F, N> where
    S: Signal<N>,
    F: FnMut(&S::Frame), 
[src]

type Frame = S::Frame

impl<S, F, const N: usize> Signal<N> for MulFrame<S, F, N> where
    S: Signal<N>,
    S::Frame: Frame<N, Float = F>,
    F: Frame<N>, 
[src]

type Frame = S::Frame

impl<S, O, M, F, const N: usize, const NO: usize, const NF: usize> Signal<NF> for ZipMap<S, O, F, M, N, NO, NF> where
    S: Signal<N>,
    O: Signal<NO>,
    M: FnMut(S::Frame, O::Frame) -> F,
    F: Frame<NF>, 
[src]

type Frame = F

impl<S, X, const N: usize> Signal<N> for AddAmp<S, X, N> where
    S: Signal<N>,
    S::Frame: Frame<N>,
    <S::Frame as Frame<N>>::Sample: Sample<Signed = X>,
    X: Sample
[src]

type Frame = S::Frame

impl<S, X, const N: usize> Signal<N> for MulAmp<S, X, N> where
    S: Signal<N>,
    S::Frame: Frame<N>,
    <S::Frame as Frame<N>>::Sample: Sample<Float = X>,
    X: Sample
[src]

type Frame = S::Frame

impl<S, const N: usize> Signal<N> for Delay<S, N> where
    S: Signal<N>, 
[src]

type Frame = S::Frame

impl<S, const N: usize> Signal<N> for Take<S, N> where
    S: Signal<N>, 
[src]

type Frame = S::Frame

Loading content...