pub struct ResamplingProd<T: Sample, const MAX_CHANNELS: usize> { /* 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 rubato
and ringbuf
crates.
Implementations§
Source§impl<T: Sample, const MAX_CHANNELS: usize> ResamplingProd<T, MAX_CHANNELS>
impl<T: Sample, const MAX_CHANNELS: usize> ResamplingProd<T, MAX_CHANNELS>
Sourcepub fn push<Vin: AsRef<[T]>>(
&mut self,
input: &[Vin],
input_range: Range<usize>,
) -> PushStatus
pub fn push<Vin: AsRef<[T]>>( &mut self, input: &[Vin], input_range: Range<usize>, ) -> PushStatus
Push the given data in de-interleaved format.
input
- The input data in de-interleaved format.input_range
- The range in each channel ininput
to read from.
This method is realtime-safe.
§Panics
Panics if:
input.len() < self.num_channels()
.- The
input_range
is out of bounds for any of the input channels.
Sourcepub fn push_interleaved(&mut self, input: &[T]) -> PushStatus
pub fn push_interleaved(&mut self, input: &[T]) -> PushStatus
Push the given data in interleaved format.
This method is realtime-safe.
Sourcepub fn available_frames(&mut self) -> usize
pub fn available_frames(&mut self) -> usize
Returns the number of input frames (samples in a single channel of audio) that are currently available to be pushed to the channel.
If the output stream is not ready yet, then this will return 0
.
This method is realtime-safe.
Sourcepub fn available_seconds(&mut self) -> f64
pub fn available_seconds(&mut self) -> f64
The amount of data in seconds that is available to be pushed to the channel.
If the output stream is not ready yet, then this will return 0.0
.
This method is realtime-safe.
Sourcepub fn occupied_output_frames(&self) -> usize
pub fn occupied_output_frames(&self) -> usize
The amount of data that is currently occupied in the channel, in units of output frames (samples in a single channel of audio).
Note, this is the number of frames in the output audio stream, not the input audio stream.
This method is realtime-safe.
Sourcepub fn occupied_seconds(&self) -> f64
pub fn occupied_seconds(&self) -> f64
The amount of data that is currently occupied in the channel, in units of seconds.
This method is realtime-safe.
Sourcepub fn num_channels(&self) -> NonZeroUsize
pub fn num_channels(&self) -> NonZeroUsize
The number of channels configured for this stream.
This method is realtime-safe.
Sourcepub fn in_sample_rate(&self) -> u32
pub fn in_sample_rate(&self) -> u32
The sample rate of the input stream.
This method is realtime-safe.
Sourcepub fn out_sample_rate(&self) -> u32
pub fn out_sample_rate(&self) -> u32
The sample rate of the output stream.
This method is realtime-safe.
Sourcepub fn latency_seconds(&self) -> f64
pub fn latency_seconds(&self) -> f64
The latency of the channel in units of seconds.
This method is realtime-safe.
Sourcepub fn is_resampling(&self) -> bool
pub fn is_resampling(&self) -> bool
Returns true
if this channel is currently resampling.
This method is realtime-safe.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Tell the consumer to clear all queued frames in the buffer.
This method is realtime-safe.
Sourcepub fn set_input_stream_ready(&mut self, ready: bool)
pub fn set_input_stream_ready(&mut self, ready: bool)
Manually notify the output stream that the input stream is ready/not ready to push samples to the channel.
If this producer end is being used in a non-realtime context, then it is
a good idea to set this to true
so that the consumer end can start
reading samples from the channel immediately.
Note, calling ResamplingProd::push
and
ResamplingProd::push_interleaved
automatically sets the input stream as
ready.
This method is realtime-safe.
Sourcepub fn output_stream_ready(&self) -> bool
pub fn output_stream_ready(&self) -> bool
Whether or not the output stream is ready to read samples from the channel.
This method is realtime-safe.
Sourcepub fn autocorrect_underflows(&mut self) -> Option<usize>
pub fn autocorrect_underflows(&mut self) -> Option<usize>
Correct for any underflows.
This returns the number of extra zero frames (samples in a single channel of audio)
that were added due to an underflow occurring. If no underflow occured, then None
is returned.
Note, this method is already automatically called in ResamplingProd::push
and
ResamplingProd::push_interleaved
.
This will have no effect if ResamplingChannelConfig::underflow_autocorrect_percent_threshold
was set to None
.
This method is realtime-safe.