Skip to main content

PacketResampler

Struct PacketResampler 

Source
pub struct PacketResampler<T: Sample, B: PacketResamplerBuffer<T>> { /* private fields */ }
Expand description

A wrapper around rubato’s Resampler that accepts inputs of any size and sends resampled output packets to a given closure.

When using the Sequential PacketResamplerBuffer, the output packets will be in de-interleaved format (using &SequentialOwned). When using the Interleaved PacketResamplerBuffer, the output packets be be in interleaved format (using &[T]).

This only supports synchronous resampling.

Implementations§

Source§

impl<T: Sample, B: PacketResamplerBuffer<T>> PacketResampler<T, B>

Source

pub fn new( num_channels: usize, in_sample_rate: u32, out_sample_rate: u32, config: ResamplerConfig, ) -> Self

Create a new PacketResampler.

  • num_channels - The number of audio channels.
  • in_sample_rate - The sample rate of the input data.
  • out_sample_rate - The sample rate of the output data.
  • config - Extra configuration for the resampler.
§Panics

Panics if:

  • num_channels == 0
  • in_sample_rate == 0
  • out_sample_rate == 0
  • config.chunk_size == 0
  • config.sub_chunks == 0
Source

pub fn from_custom(resampler: Box<dyn Resampler<T>>) -> Self

Create a new PacketResampler using a custom Resampler.

This can be used, for example, to create a PacketResampler with non-integer input and/or output sample rates.

Source

pub fn nbr_channels(&self) -> usize

The number of channels configured for this resampler.

Source

pub fn ratio(&self) -> f64

The resampling ratio output / input.

Source

pub fn max_input_block_frames(&self) -> usize

The number of frames (samples in a single channel of audio) that appear in a single packet of input data in the internal resampler.

Source

pub fn max_output_block_frames(&self) -> usize

The maximum number of frames (samples in a single channel of audio) that can appear in a single call to the on_output_packet closure in PacketResampler::process.

Source

pub fn output_delay(&self) -> usize

The delay introduced by the internal resampler in number of output frames ( samples in a single channel of audio).

Source

pub fn out_alloc_frames(&self, input_frames: u64) -> u64

The number of frames (samples in a single channel of audio) that are needed for an output buffer given the number of input frames.

Source

pub fn process( &mut self, buffer_in: &dyn Adapter<'_, T>, input_range: Option<Range<usize>>, active_channels_mask: Option<&[bool]>, on_output_packet: impl FnMut(&B::Output, usize), last_packet: Option<LastPacketInfo>, trim_delay: bool, )

Process the given input data and return packets of resampled output data.

  • buffer_in - The input data. You can use one of the types in the 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 buffer_in to use. Channels marked with false will be skipped and the output channel filled with zeros. If None, then all of the channels will be active.
  • on_output_packet - Gets called whenever there is a new packet of resampled output data. (buffer, output_frames)
    • When using Sequential output buffers, the output will be of type &SequentialOwned. Note, the length of this buffer may be less than output_frames. Only read up to output_frames data from the buffer.
    • When using Interleaved output buffers, the output will be of type &[T]. The number of frames in this slice will always be equal to output_frames.
  • last_packet - If this is Some, then any leftover input samples in the buffer will be flushed out and the resampler reset. Use this if this is the last/only packet of input data.
  • trim_delay - If true, then the initial padded zeros introduced by the internal resampler will be trimmed off.

This method is realtime-safe.

§Panics

Panics if:

  • The input_range is out of bounds for any of the input channels.
Source

pub fn output_delay_frames_left(&self) -> usize

Source

pub fn reset(&mut self)

Source

pub fn into_inner(self) -> Box<dyn Resampler<T>>

Auto Trait Implementations§

§

impl<T, B> Freeze for PacketResampler<T, B>
where B: Freeze,

§

impl<T, B> !RefUnwindSafe for PacketResampler<T, B>

§

impl<T, B> Send for PacketResampler<T, B>
where B: Send,

§

impl<T, B> !Sync for PacketResampler<T, B>

§

impl<T, B> Unpin for PacketResampler<T, B>
where B: Unpin,

§

impl<T, B> UnsafeUnpin for PacketResampler<T, B>
where B: UnsafeUnpin,

§

impl<T, B> !UnwindSafe for PacketResampler<T, B>

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.