Struct RtResampler

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

An easy to use resampler that can be used in realtime applications.

Implementations§

Source§

impl<T: Sample> RtResampler<T>

Source

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

Create a new 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 RtResampler::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>>, interleaved: bool, ) -> Self

Create a new realtime resampler using the given rubato resampler.

  • resampler - The rubato resampler.
  • interleaved - If you are planning to use RtResampler::process_interleaved, set this to true. Otherwise you can set this to false to save a bit of memory.
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 request_frames(&self) -> usize

The number of frames in each call to on_frames_requested in RtResampler::process.

Source

pub fn output_delay(&self) -> usize

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

Source

pub fn temp_frames(&self) -> usize

The number of frames that are currently stored in the temporary buffer.

Source

pub fn process<Vout: AsMut<[T]>>( &mut self, on_frames_requested: impl FnMut(&mut [Vec<T>]), output: &mut [Vout], range: Range<usize>, )

Resample the input stream and process into a block of data for the output stream.

This method is realtime-safe.

  • on_frames_requested - This gets called whenever the resampler needs more data from the input stream. The given buffer must be fully filled with new samples. If there is not enough data to fill the buffer (i.e. an underflow occured), then fill the rest of the frames with zeros. Do NOT resize the Vecs.
  • output - The channels of audio data to write data to.
  • range - The range in each slice in output to write data to. Data inside this range will be fully filled, and any data outside this range will be untouched.
Source

pub fn process_interleaved( &mut self, on_frames_requested: impl FnMut(&mut [T]), output: &mut [T], )

Resample the input stream and process into an interleaved block of data for the output stream.

  • on_frames_requested - This gets called whenever the resampler needs more data from the input stream. The given buffer is in interleaved format, and it must be completely filled with new data. If there is not enough data to fill the buffer (i.e. an underflow occured), then fill the rest of the frames with zeros.
  • output - The interleaved output buffer to write the resampled data to.
§Panics
  • Panics if the number of output channels does not equal the number of channels in this resampler.
  • Also panics if the interleaved argument was false when this struct was created and self.num_channels() > 1.
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 RtResampler<T>

Source§

fn into(self) -> ResamplerType<T>

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

Auto Trait Implementations§

§

impl<T> Freeze for RtResampler<T>

§

impl<T> !RefUnwindSafe for RtResampler<T>

§

impl<T> Send for RtResampler<T>

§

impl<T> Sync for RtResampler<T>

§

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

§

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