Struct rubato::SincFixedIn

source ·
pub struct SincFixedIn<T> { /* private fields */ }
Expand description

An asynchronous resampler that accepts a fixed number of audio frames for input and returns a variable number of frames.

The resampling is done by creating a number of intermediate points (defined by oversampling_factor) by sinc interpolation. The new samples are then calculated by interpolating between these points.

The resampling ratio can be freely adjusted within the range specified to the constructor. Adjusting the ratio does not recalculate the sinc functions used by the anti-aliasing filter. This causes no issue when increasing the ratio (which slows down the output). However, when decreasing more than a few percent (or speeding up the output), the filters can no longer suppress all aliasing and this may lead to some artefacts. Higher maximum ratios require more memory to be allocated by Resampler::output_buffer_allocate.

Implementations§

source§

impl<T> SincFixedIn<T>
where T: Sample,

source

pub fn new( resample_ratio: f64, max_resample_ratio_relative: f64, parameters: SincInterpolationParameters, chunk_size: usize, nbr_channels: usize ) -> Result<Self, ResamplerConstructionError>

Create a new SincFixedIn.

Parameters are:

  • resample_ratio: Starting ratio between output and input sample rates, must be > 0.
  • max_resample_ratio_relative: Maximum ratio that can be set with Resampler::set_resample_ratio relative to resample_ratio, must be >= 1.0. The minimum relative ratio is the reciprocal of the maximum. For example, with max_resample_ratio_relative of 10.0, the ratio can be set between resample_ratio * 10.0 and resample_ratio / 10.0.
  • parameters: Parameters for interpolation, see SincInterpolationParameters.
  • chunk_size: Size of input data in frames.
  • nbr_channels: Number of channels in input/output.
source

pub fn new_with_interpolator( resample_ratio: f64, max_resample_ratio_relative: f64, interpolation_type: SincInterpolationType, interpolator: Box<dyn SincInterpolator<T>>, chunk_size: usize, nbr_channels: usize ) -> Result<Self, ResamplerConstructionError>

Create a new SincFixedIn using an existing Interpolator.

Parameters are:

  • resample_ratio: Starting ratio between output and input sample rates, must be > 0.
  • max_resample_ratio_relative: Maximum ratio that can be set with Resampler::set_resample_ratio relative to resample_ratio, must be >= 1.0. The minimum relative ratio is the reciprocal of the maximum. For example, with max_resample_ratio_relative of 10.0, the ratio can be set between resample_ratio * 10.0 and resample_ratio / 10.0.
  • interpolation_type: Parameters for interpolation, see SincInterpolationParameters.
  • interpolator: The interpolator to use.
  • chunk_size: Size of output data in frames.
  • nbr_channels: Number of channels in input/output.

Trait Implementations§

source§

impl<T> Resampler<T> for SincFixedIn<T>
where T: Sample,

source§

fn process_into_buffer<Vin: AsRef<[T]>, Vout: AsMut<[T]>>( &mut self, wave_in: &[Vin], wave_out: &mut [Vout], active_channels_mask: Option<&[bool]> ) -> ResampleResult<(usize, usize)>

Resample a buffer of audio to a pre-allocated output buffer. Use this in real-time applications where the unpredictable time required to allocate memory from the heap can cause glitches. If this is not a problem, you may use the process method instead. Read more
source§

fn output_frames_max(&self) -> usize

Get the max number of output frames per channel.
source§

fn output_frames_next(&self) -> usize

Get the number of frames per channel that will be output from the next call to process_into_buffer or process.
source§

fn output_delay(&self) -> usize

Get the delay for the resampler, reported as a number of output frames.
source§

fn nbr_channels(&self) -> usize

Get the maximum number of channels this Resampler is configured for.
source§

fn input_frames_max(&self) -> usize

Get the maximum number of input frames per channel the resampler could require.
source§

fn input_frames_next(&self) -> usize

Get the number of frames per channel needed for the next call to process_into_buffer or process.
source§

fn set_resample_ratio( &mut self, new_ratio: f64, ramp: bool ) -> ResampleResult<()>

Update the resample ratio. Read more
source§

fn set_resample_ratio_relative( &mut self, rel_ratio: f64, ramp: bool ) -> ResampleResult<()>

Update the resample ratio as a factor relative to the original one. Read more
source§

fn reset(&mut self)

Reset the resampler state and clear all internal buffers.
source§

fn process<V: AsRef<[T]>>( &mut self, wave_in: &[V], active_channels_mask: Option<&[bool]> ) -> ResampleResult<Vec<Vec<T>>>

This is a convenience wrapper for process_into_buffer that allocates the output buffer with each call. For realtime applications, use process_into_buffer with a buffer allocated by output_buffer_allocate instead of this function.
source§

fn process_partial_into_buffer<Vin: AsRef<[T]>, Vout: AsMut<[T]>>( &mut self, wave_in: Option<&[Vin]>, wave_out: &mut [Vout], active_channels_mask: Option<&[bool]> ) -> ResampleResult<(usize, usize)>

This is a convenience method for processing the last frames at the end of a stream. Use this when there are fewer frames remaining than what the resampler requires as input. Calling this function is equivalent to padding the input buffer with zeros to make it the right input length, and then calling process_into_buffer. This method can also be called without any input frames, by providing None as input buffer. This can be utilized to push any remaining delayed frames out from the internal buffers. Note that this method allocates space for a temporary input buffer. Real-time applications should instead call process_into_buffer with a zero-padded pre-allocated input buffer.
source§

fn process_partial<V: AsRef<[T]>>( &mut self, wave_in: Option<&[V]>, active_channels_mask: Option<&[bool]> ) -> ResampleResult<Vec<Vec<T>>>

This is a convenience method for processing the last frames at the end of a stream. It is similar to process_partial_into_buffer but allocates the output buffer with each call. Note that this method allocates space for both input and output.
source§

fn input_buffer_allocate(&self, filled: bool) -> Vec<Vec<T>>

Convenience method for allocating an input buffer suitable for use with process_into_buffer. The buffer’s capacity is big enough to prevent allocating additional heap memory before any call to process_into_buffer regardless of the current resampling ratio. Read more
source§

fn output_buffer_allocate(&self, filled: bool) -> Vec<Vec<T>>

Convenience method for allocating an output buffer suitable for use with process_into_buffer. The buffer’s capacity is big enough to prevent allocating additional heap memory during any call to process_into_buffer regardless of the current resampling ratio. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for SincFixedIn<T>

§

impl<T> Send for SincFixedIn<T>
where T: Send,

§

impl<T> !Sync for SincFixedIn<T>

§

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

§

impl<T> !UnwindSafe for SincFixedIn<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>,

§

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

§

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.
source§

impl<T, U> VecResampler<T> for U
where U: Resampler<T>, T: Sample,

source§

fn process( &mut self, wave_in: &[Vec<T>], active_channels_mask: Option<&[bool]> ) -> Result<Vec<Vec<T>>, ResampleError>

source§

fn process_into_buffer( &mut self, wave_in: &[Vec<T>], wave_out: &mut [Vec<T>], active_channels_mask: Option<&[bool]> ) -> Result<(usize, usize), ResampleError>

source§

fn process_partial_into_buffer( &mut self, wave_in: Option<&[Vec<T>]>, wave_out: &mut [Vec<T>], active_channels_mask: Option<&[bool]> ) -> Result<(usize, usize), ResampleError>

source§

fn process_partial( &mut self, wave_in: Option<&[Vec<T>]>, active_channels_mask: Option<&[bool]> ) -> Result<Vec<Vec<T>>, ResampleError>

source§

fn output_buffer_allocate(&self, filled: bool) -> Vec<Vec<T>>

source§

fn output_frames_next(&self) -> usize

source§

fn output_frames_max(&self) -> usize

source§

fn input_frames_next(&self) -> usize

source§

fn output_delay(&self) -> usize

source§

fn nbr_channels(&self) -> usize

source§

fn input_frames_max(&self) -> usize

source§

fn input_buffer_allocate(&self, filled: bool) -> Vec<Vec<T>>

source§

fn set_resample_ratio( &mut self, new_ratio: f64, ramp: bool ) -> Result<(), ResampleError>

source§

fn set_resample_ratio_relative( &mut self, rel_ratio: f64, ramp: bool ) -> Result<(), ResampleError>