Skip to main content

ResamplingProd

Struct ResamplingProd 

Source
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 rubato and ringbuf crates.

Implementations§

Source§

impl<T: Sample + 'static> ResamplingProd<T>

Source

pub fn push( &mut self, input: &dyn Adapter<'_, T>, input_range: Option<Range<usize>>, active_channels_mask: Option<&[bool]>, ) -> PushStatus

Push the given input data.

  • input - The input data. You can use one of the types in the audioadapter_buffers::direct module to wrap your input data into a type that implements Adapter.
  • input_range - The range in each input channel to read from. If this is None, then the entire input buffer will be read.
  • active_channels_mask - An optional mask that selects which channels in input to use. Channels marked with false will be skipped and that output channel filled with zeros. If None, then all of the channels will be active.

This method is realtime-safe.

§Panics

Panics if:

  • The input_range is out of bounds for any of the input channels.
  • This producer was created with push_interleave_only set to true.
Source

pub fn push_interleaved(&mut self, input: &[T]) -> PushStatus

Push the given input data in interleaved format.

The input buffer must have the same number of channels as this producer.

This method is realtime-safe.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn num_channels(&self) -> usize

The number of channels configured for this stream.

This method is realtime-safe.

Source

pub fn in_sample_rate(&self) -> f64

The sample rate of the input stream.

This method is realtime-safe.

Source

pub fn out_sample_rate(&self) -> f64

The sample rate of the output stream.

This method is realtime-safe.

Source

pub fn latency_seconds(&self) -> f64

The latency of the channel in units of seconds.

This method is realtime-safe.

Source

pub fn is_resampling(&self) -> bool

Returns true if this channel is currently resampling.

This method is realtime-safe.

Source

pub fn reset(&mut self)

Tell the consumer to clear all queued frames in the buffer.

This method is realtime-safe.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<T> !Freeze for ResamplingProd<T>

§

impl<T> !RefUnwindSafe for ResamplingProd<T>

§

impl<T> Send for ResamplingProd<T>

§

impl<T> !Sync for ResamplingProd<T>

§

impl<T> Unpin for ResamplingProd<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ResamplingProd<T>

§

impl<T> !UnwindSafe for ResamplingProd<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.