fixed_resample

Struct NonRtResampler

Source
pub struct NonRtResampler<T: Sample> { /* private fields */ }
Expand description

An easy to use resampler for use in non-realtime applications.

Implementations§

Source§

impl<T: Sample> NonRtResampler<T>

Source

pub fn new( in_sample_rate: u32, out_sample_rate: u32, num_channels: usize, quality: ResampleQuality, ) -> Self

Create a new non-realtime resampler.

  • in_sample_rate - The sample rate of the input stream.
  • out_sample_rate - The sample rate of the output stream.
  • num_channels - The number of channels.
  • interleaved - If you are planning to use NonRtResampler::process_interleaved, set this to true. Otherwise you can set this to false to save a bit of memory.
  • quality - The quality of the resampling algorithm.
§Panics

Panics if:

  • in_sample_rate == 0
  • out_sample_rate == 0
  • num_channels == 0,
Source

pub fn from_custom(resampler: impl Into<ResamplerType<T>>) -> Self

Create a new non-realtime resampler using the given rubato resampler.

§Panics

Panics if max_out_frames == 0.

Source

pub fn num_channels(&self) -> NonZeroUsize

Get the number of channels this resampler is configured for.

Source

pub fn reset(&mut self)

Reset the resampler state and clear all internal buffers.

Source

pub fn output_delay(&self) -> usize

Get the delay of the internal resampler, reported as a number of output frames.

Note, this resampler automatically truncates the starting padded zero frames for you.

Source

pub fn process<Vin: AsRef<[T]>>( &mut self, input: &[Vin], on_processed: impl FnMut(&[Vec<T>], usize), is_last_packet: bool, )

Resample the given input data.

  • input - The input data.
  • on_processed - Called whenever there is new resampled data. The first argument is the buffers containing the new data, and the second argument is the length of the new data in frames (NOTE, the second argument may be less than the length of the Vecs in the first argument).
  • is_last_packet - Whether or not this is the last (or only) packet of data that will be resampled. This ensures that any leftover samples in the internal resampler are flushed to the output.

If you want to flush the remaining samples out of the internal resampler when there is no more input data left, set the input to an empty slice with no channels (&[]), and set is_last_packet to true.

Note, when flushing the remaining data with is_last_packet, the resulting output may have a few extra padded zero samples on the end.

The delay of the internal resampler is automatically accounted for (the starting padded zero frames are automatically truncated). Call NonRtResampler::reset() before reusing this resampler for a new sample.

Note, this method is NOT realtime-safe.

Source

pub fn process_interleaved( &mut self, input: &[T], on_processed: impl FnMut(&[T]), is_last_packet: bool, )

Resample the given input data in interleaved format.

  • input - The input data in interleaved format.
  • on_processed - Called whenever there is new resampled data. This data is in interleaved format.
  • is_last_packet - Whether or not this is the last (or only) packet of data that will be resampled. This ensures that any leftover samples in the internal resampler are flushed to the output.

If you want to flush the remaining samples out of the internal resampler when there is no more input data left, set the input to an empty slice (&[]), and set is_last_packet to true.

Note, when flushing the remaining data with is_last_packet, the resulting output may have a few extra padded zero samples on the end.

The delay of the internal resampler is automatically accounted for (the starting padded zero frames are automatically truncated). Call NonRtResampler::reset() before reusing this resampler for a new sample.

Note, this method is NOT realtime-safe.

Source

pub fn resampler_type(&self) -> &ResamplerType<T>

Source

pub fn resampler_type_mut(&mut self) -> &mut ResamplerType<T>

Trait Implementations§

Source§

impl<T: Sample> Into<ResamplerType<T>> for NonRtResampler<T>

Source§

fn into(self) -> ResamplerType<T>

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl<T> Freeze for NonRtResampler<T>

§

impl<T> !RefUnwindSafe for NonRtResampler<T>

§

impl<T> Send for NonRtResampler<T>

§

impl<T> Sync for NonRtResampler<T>

§

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

§

impl<T> !UnwindSafe for NonRtResampler<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.