pub struct ResamplingCons<T: Sample> { /* private fields */ }
Expand description
The consumer 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> ResamplingCons<T>
impl<T: Sample> ResamplingCons<T>
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 latency_frames(&self) -> usize
pub fn latency_frames(&self) -> usize
The latency of the channel in units of output frames.
This method is realtime-safe.
Sourcepub fn available_frames(&self) -> usize
pub fn available_frames(&self) -> usize
The number of frames (samples in a single channel of audio) that are currently available to be read from the channel.
If the input stream is not ready yet, then this will return 0
.
This method is realtime-safe.
Sourcepub fn available_seconds(&self) -> f64
pub fn available_seconds(&self) -> f64
The amount of data in seconds that is currently available to be read from the channel.
If the input stream is not ready yet, then this will return 0.0
.
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 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 resampler_output_delay(&self) -> usize
pub fn resampler_output_delay(&self) -> usize
The delay of the internal resampler in number of output frames (samples in a single channel of audio).
If there is no resampler being used for this channel, then this will return
0
.
This method is realtime-safe.
Sourcepub fn discard_frames(&mut self, frames: usize) -> usize
pub fn discard_frames(&mut self, frames: usize) -> usize
Discard a certian number of output frames from the buffer. This can be used to correct for jitter and avoid excessive overflows and reduce the percieved audible glitchiness.
This will discard frames.min(self.available_frames())
frames.
Returns the number of output frames that were discarded.
This method is realtime-safe.
Sourcepub fn read<Vout: AsMut<[T]>>(
&mut self,
output: &mut [Vout],
output_range: Range<usize>,
) -> ReadStatus
pub fn read<Vout: AsMut<[T]>>( &mut self, output: &mut [Vout], output_range: Range<usize>, ) -> ReadStatus
Read from the channel and store the results in the de-interleaved output buffer.
This method is realtime-safe.
Sourcepub fn read_interleaved(&mut self, output: &mut [T]) -> ReadStatus
pub fn read_interleaved(&mut self, output: &mut [T]) -> ReadStatus
Read from the channel and store the results into the output buffer in interleaved format.
This method is realtime-safe.
Sourcepub fn poll_reset(&mut self) -> bool
pub fn poll_reset(&mut self) -> bool
Poll the channel to see if it got a command to reset.
Returns true
if the channel was reset.
Sourcepub fn set_output_stream_ready(&mut self, ready: bool)
pub fn set_output_stream_ready(&mut self, ready: bool)
Manually notify the input stream that the output stream is ready/not ready to read samples from the channel.
If this consumer end is being used in a non-realtime context, then it is
a good idea to set this to true
so that the producer end can start
pushing samples to the channel immediately.
Note, calling ResamplingCons::read
and
ResamplingCons::read_interleaved
automatically sets the output stream as
ready.
This method is realtime-safe.
Sourcepub fn input_stream_ready(&self) -> bool
pub fn input_stream_ready(&self) -> bool
Whether or not the input stream is ready to push samples to the channel.
This method is realtime-safe.
Sourcepub fn autocorrect_overflows(&mut self) -> Option<usize>
pub fn autocorrect_overflows(&mut self) -> Option<usize>
Correct for any overflows.
This returns the number of frames (samples in a single channel of audio) that were
discarded due to an overflow occurring. If no overflow occured, then None
is returned.
Note, this method is already automatically called in ResamplingCons::read
and
ResamplingCons::read_interleaved
.
This will have no effect if ResamplingChannelConfig::overflow_autocorrect_percent_threshold
was set to None
.
This method is realtime-safe.