pub trait Signal<const N: usize> {
type Frame: Frame<N>;
Show 15 methods
// Required method
fn next(&mut self) -> Option<Self::Frame>;
// Provided methods
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> ⓘ
where Self: Sized { ... }
}
Expand description
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn sig_next(&mut self) -> Self::Frame
fn sig_next(&mut self) -> Self::Frame
Similar to [next
], but will always yield a Frame
. Yields
Frame::EQUILIBRIUM
if there are no more actual Frame
s to yield.
Sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
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));
}
Sourcefn zip_map<O, F, M, const NO: usize, const NF: usize>(
self,
other: O,
func: M,
) -> ZipMap<Self, O, F, M, N, NO, NF>
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>
Sourcefn add_signal<B>(self, other: B) -> AddSignal<Self, B, N>
fn add_signal<B>(self, other: B) -> AddSignal<Self, B, N>
Sourcefn mul_signal<B>(self, other: B) -> MulSignal<Self, B, N>
fn mul_signal<B>(self, other: B) -> MulSignal<Self, B, N>
Sourcefn delay(self, n_frames: usize) -> Delay<Self, N>where
Self: Sized,
fn delay(self, n_frames: usize) -> Delay<Self, N>where
Self: Sized,
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
.
Sourcefn inspect<F>(self, func: F) -> Inspect<Self, F, N>
fn inspect<F>(self, func: F) -> Inspect<Self, F, N>
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));
}
Sourcefn take(self, n: usize) -> Take<Self, N>where
Self: Sized,
fn take(self, n: usize) -> Take<Self, N>where
Self: Sized,
Returns a new Signal
that yields only the first N Frame
s 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);
}