pub struct ResamplingProd<T: Sample> { /* private fields */ }
Expand description
The producer end of a realtime-safe spsc channel for sending samples across streams.
If the input and output samples rates differ, then this will automatically resample the input stream to match the output stream. If the sample rates match, then no resampling will occur.
Internally this uses the ringbuf
crate.
Implementations§
Source§impl<T: Sample + Copy> ResamplingProd<T>
impl<T: Sample + Copy> ResamplingProd<T>
Sourcepub fn push_interleaved(&mut self, data: &[T]) -> usize
pub fn push_interleaved(&mut self, data: &[T]) -> usize
Push the given data in interleaved format.
Returns the number of frames (samples in a single channel) that were successfully
pushed. If this number is less than the number of frames in data
, then it means
an overflow has occured.
Sourcepub fn push<Vin: AsRef<[T]>>(
&mut self,
data: &[Vin],
range: Range<usize>,
) -> usize
pub fn push<Vin: AsRef<[T]>>( &mut self, data: &[Vin], range: Range<usize>, ) -> usize
Push the given data in de-interleaved format.
Returns the number of frames (samples in a single channel) that were successfully
pushed. If this number is less than the number of frames in data
, then it means
an overflow has occured.
range
- The range in each channel ininput
to read data from.
Sourcepub fn available_frames(&self) -> usize
pub fn available_frames(&self) -> usize
Returns the number of frames (samples in a single channel) that are currently available to be pushed to the channel.
Sourcepub fn available_seconds(&self) -> f64
pub fn available_seconds(&self) -> f64
The amount of data in seconds that is currently available to be pushed to the channel
Sourcepub fn occupied_frames(&self) -> usize
pub fn occupied_frames(&self) -> usize
Returns the number of frames (samples in a single channel) that are currently occupied in the channel.
Sourcepub fn occupied_seconds(&self) -> f64
pub fn occupied_seconds(&self) -> f64
The amount of data in seconds that is currently occupied in the channel.
This value will be in the range [0.0, ResamplingProd::capacity_seconds()]
.
This value can be used to detect when new packets of data should be pushed
to the channel in a non-realtime thread. Generally, if this value falls below
ResamplingProd::latency_seconds()
, then a new packet of data should be
pushed.
Sourcepub fn latency_seconds(&self) -> f64
pub fn latency_seconds(&self) -> f64
The value of ResamplingChannelConfig::latency_seconds
that was passed when
this channel was created.
Sourcepub fn capacity_seconds(&self) -> f64
pub fn capacity_seconds(&self) -> f64
The capacity of the channel in seconds.
Sourcepub fn capacity_frames(&self) -> usize
pub fn capacity_frames(&self) -> usize
The capacity of the channel in frames (samples in a single channel).
Sourcepub fn num_channels(&self) -> NonZeroUsize
pub fn num_channels(&self) -> NonZeroUsize
The number of channels configured for this stream.
Sourcepub fn in_sample_rate(&self) -> NonZeroU32
pub fn in_sample_rate(&self) -> NonZeroU32
The sample rate of the input (producer) stream.
Sourcepub fn out_sample_rate(&self) -> NonZeroU32
pub fn out_sample_rate(&self) -> NonZeroU32
The sample rate of the output (consumer) stream.