Struct ResamplingCons

Source
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>

Source

pub fn num_channels(&self) -> NonZeroUsize

The number of channels configured for this stream.

This method is realtime-safe.

Source

pub fn in_sample_rate(&self) -> u32

The sample rate of the input stream.

This method is realtime-safe.

Source

pub fn out_sample_rate(&self) -> u32

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 latency_frames(&self) -> usize

The latency of the channel in units of output frames.

This method is realtime-safe.

Source

pub fn available_frames(&self) -> usize

The number of frames that are currently available to be read from the channel.

This method is realtime-safe.

Source

pub fn occupied_seconds(&self) -> f64

The amount of data that is currently present in 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 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.

Source

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.

Source

pub fn discard_jitter(&mut self, threshold_seconds: f64) -> usize

If the value of ResamplingCons::occupied_seconds is greater than the given threshold in seconds, then discard the number of frames needed to bring the occupied value back to ResamplingCons::latency_seconds to avoid excessive overflows in the future and reduce the percieved audible glitchiness.

If threshold_seconds is less than ResamplingCons::latency_seconds, then this will do nothing and return 0.

Returns the number of output frames that were discarded.

This method is realtime-safe.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<T> !Freeze for ResamplingCons<T>

§

impl<T> !RefUnwindSafe for ResamplingCons<T>

§

impl<T> Send for ResamplingCons<T>

§

impl<T> !Sync for ResamplingCons<T>

§

impl<T> Unpin for ResamplingCons<T>

§

impl<T> UnwindSafe for ResamplingCons<T>
where T: RefUnwindSafe,

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.