pub struct Buffered<S, D> { /* private fields */ }
Expand description
Buffers the signal using the given ring buffer.
When next
is called, Buffered
will first check if the ring buffer is empty. If so, it will
completely fill the ring buffer with signal
before yielding the next frame.
If next
is called and the ring buffer still contains un-yielded values, the next frame will
be popped from the front of the ring buffer and immediately returned.
Implementations§
Source§impl<S, D> Buffered<S, D>
impl<S, D> Buffered<S, D>
Sourcepub fn next_frames(&mut self) -> BufferedFrames<'_, D> ⓘ
pub fn next_frames(&mut self) -> BufferedFrames<'_, D> ⓘ
Produces an iterator yielding the next batch of buffered frames.
The returned iterator returns None
once the inner ring buffer becomes exhausted.
If the inner ring buffer is empty when this method is called, the ring buffer will first be
filled using Buffered
’s inner signal
before BufferedFrames
is returned.
use dasp_ring_buffer as ring_buffer;
use dasp_signal::{self as signal, Signal};
fn main() {
let frames = [0.1, 0.2, 0.3, 0.4];
let signal = signal::from_iter(frames.iter().cloned());
let ring_buffer = ring_buffer::Bounded::from([0f32; 2]);
let mut buffered_signal = signal.buffered(ring_buffer);
assert_eq!(buffered_signal.next_frames().collect::<Vec<_>>(), vec![0.1, 0.2]);
assert_eq!(buffered_signal.next_frames().collect::<Vec<_>>(), vec![0.3, 0.4]);
assert_eq!(buffered_signal.next_frames().collect::<Vec<_>>(), vec![0.0, 0.0]);
}
Sourcepub fn into_parts(self) -> (S, Bounded<D>)
pub fn into_parts(self) -> (S, Bounded<D>)
Consumes the Buffered
signal and returns its inner signal S
and bounded ring buffer.
Trait Implementations§
Source§impl<S, D> Signal for Buffered<S, D>
impl<S, D> Signal for Buffered<S, D>
Source§fn is_exhausted(&self) -> bool
fn is_exhausted(&self) -> bool
Source§fn map<M, F>(self, map: M) -> Map<Self, M, F>
fn map<M, F>(self, map: M) -> Map<Self, M, F>
Source§fn zip_map<O, M, F>(self, other: O, map: M) -> ZipMap<Self, O, M, F>
fn zip_map<O, M, F>(self, other: O, map: M) -> ZipMap<Self, O, M, F>
Source§fn add_amp<S>(self, other: S) -> AddAmp<Self, S>
fn add_amp<S>(self, other: S) -> AddAmp<Self, S>
other
and self
in lock-step. Read moreSource§fn mul_amp<S>(self, other: S) -> MulAmp<Self, S>
fn mul_amp<S>(self, other: S) -> MulAmp<Self, S>
other
and
self
in lock-step. Read moreSource§fn offset_amp(
self,
offset: <<Self::Frame as Frame>::Sample as Sample>::Signed,
) -> OffsetAmp<Self>where
Self: Sized,
fn offset_amp(
self,
offset: <<Self::Frame as Frame>::Sample as Sample>::Signed,
) -> OffsetAmp<Self>where
Self: Sized,
Source§fn scale_amp(
self,
amp: <<Self::Frame as Frame>::Sample as Sample>::Float,
) -> ScaleAmp<Self>where
Self: Sized,
fn scale_amp(
self,
amp: <<Self::Frame as Frame>::Sample as Sample>::Float,
) -> ScaleAmp<Self>where
Self: Sized,
Iterator
that scales the amplitude of the sample of each channel in every
Frame
yielded by self
by the given amplitude. Read moreSource§fn offset_amp_per_channel<F>(self, amp_frame: F) -> OffsetAmpPerChannel<Self, F>
fn offset_amp_per_channel<F>(self, amp_frame: F) -> OffsetAmpPerChannel<Self, F>
Signal
that offsets the amplitude of every Frame
in self
by the
respective amplitudes in each channel of the given amp_frame
. Read moreSource§fn scale_amp_per_channel<F>(self, amp_frame: F) -> ScaleAmpPerChannel<Self, F>
fn scale_amp_per_channel<F>(self, amp_frame: F) -> ScaleAmpPerChannel<Self, F>
Signal
that scales the amplitude of every Frame
in self
by the
respective amplitudes in each channel of the given amp_frame
. Read moreSource§fn from_hz_to_hz<I>(
self,
interpolator: I,
source_hz: f64,
target_hz: f64,
) -> Converter<Self, I>where
Self: Sized,
I: Interpolator,
fn from_hz_to_hz<I>(
self,
interpolator: I,
source_hz: f64,
target_hz: f64,
) -> Converter<Self, I>where
Self: Sized,
I: Interpolator,
Signal
are yielded using interpolation. Read moreSource§fn scale_hz<I>(self, interpolator: I, multi: f64) -> Converter<Self, I>where
Self: Sized,
I: Interpolator,
fn scale_hz<I>(self, interpolator: I, multi: f64) -> Converter<Self, I>where
Self: Sized,
I: Interpolator,
Signal
are yielded by the given value. Read moreSource§fn delay(self, n_frames: usize) -> Delay<Self>where
Self: Sized,
fn delay(self, n_frames: usize) -> Delay<Self>where
Self: Sized,
Signal
by the given number of frames. Read moreSource§fn into_interleaved_samples(self) -> IntoInterleavedSamples<Self>where
Self: Sized,
fn into_interleaved_samples(self) -> IntoInterleavedSamples<Self>where
Self: Sized,
Source§fn clip_amp(
self,
thresh: <<Self::Frame as Frame>::Sample as Sample>::Signed,
) -> ClipAmp<Self>where
Self: Sized,
fn clip_amp(
self,
thresh: <<Self::Frame as Frame>::Sample as Sample>::Signed,
) -> ClipAmp<Self>where
Self: Sized,
Frame
yielded by self
to the given
threshold amplitude. Read moreSource§fn inspect<F>(self, inspect: F) -> Inspect<Self, F>
fn inspect<F>(self, inspect: F) -> Inspect<Self, F>
Signal
that calls the enclosing function on each iteration. Read moreSource§fn fork<S>(self, ring_buffer: Bounded<S>) -> Fork<Self, S>
fn fork<S>(self, ring_buffer: Bounded<S>) -> Fork<Self, S>
Self
into two signals that produce the same frames. Read moreSource§fn take(self, n: usize) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, n: usize) -> Take<Self> ⓘwhere
Self: Sized,
Signal
into an Iterator
that will yield the given number for Frame
s
before returning None
. Read moreSource§fn until_exhausted(self) -> UntilExhausted<Self> ⓘwhere
Self: Sized,
fn until_exhausted(self) -> UntilExhausted<Self> ⓘwhere
Self: Sized,
Signal
into an Iterator
yielding frames until the signal.is_exhausted()
returns true
. Read more