Enum ResamplerType

Source
pub enum ResamplerType<T: Sample> {
    Fast(FastFixedIn<T>),
    Fft(FftFixedIn<T>),
    ArbitraryRatioSinc(SincFixedIn<T>),
}
Expand description

The resampling algorithm used in fixed_resample.

Variants§

§

Fast(FastFixedIn<T>)

Ok quality, fast performance

§

Fft(FftFixedIn<T>)

Great quality, medium performance

§

ArbitraryRatioSinc(SincFixedIn<T>)

Similar quality to ResamplerType::Fft, low performance.

Use this if you need a non-integer ratio (i.e. repitching a sample).

Implementations§

Source§

impl<T: Sample> ResamplerType<T>

Source

pub fn from_quality( in_sample_rate: u32, out_sample_rate: u32, num_channels: NonZeroUsize, quality: ResampleQuality, ) -> Self

Source

pub fn arbitrary_ratio_sinc(ratio: f64, num_channels: NonZeroUsize) -> Self

Create a new resampler that uses the SincFixedIn resampler from rubato.

This has similar quality to the rubato::FftFixedIn resampler used for ResampleQuality::High, but with much lower performance. Use this if you need a non-integer ratio (i.e. repitching a sample).

  • ratio - The resampling ratio (output / input)
  • num_channels - The number of channels

More specifically, this creates a resampler with the following parameters:

SincInterpolationParameters {
    sinc_len: 128,
    f_cutoff: rubato::calculate_cutoff(128, WindowFunction::Blackman2),
    interpolation: SincInterpolationType::Cubic,
    oversampling_factor: 512,
    window: WindowFunction::Blackman2,
}
§Panics

Panics if:

  • ratio <= 0.0
  • num_channels > MAX_CHANNELS
Source

pub fn num_channels(&self) -> usize

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

Get the number of frames per channel needed for the next call to [ResamplerRefMut::process_into_buffer].

Source

pub fn input_frames_max(&mut self) -> usize

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

Source

pub fn output_delay(&mut self) -> usize

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

Source

pub fn output_frames_max(&mut self) -> usize

Get the max number of output frames per channel.

Source

pub 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.

The input and output buffers are used in a non-interleaved format. The input is a slice, where each element of the slice is itself referenceable as a slice (AsRef<[T]>) which contains the samples for a single channel. Because [Vec<T>] implements AsRef<\[T\]>, the input may be Vec<Vec<T>>.

The output data is a slice, where each element of the slice is a [T] which contains the samples for a single channel. If the output channel slices do not have sufficient capacity for all output samples, the function will return an error with the expected size. You could allocate the required output buffer with output_buffer_allocate before calling this function and reuse the same buffer for each call.

The active_channels_mask is optional. Any channel marked as inactive by a false value will be skipped during processing and the corresponding output will be left unchanged. If None is given, all channels will be considered active.

Before processing, it checks that the input and outputs are valid. If either has the wrong number of channels, or if the buffer for any channel is too short, a [ResampleError] is returned. Both input and output are allowed to be longer than required. The number of input samples consumed and the number output samples written per channel is returned in a tuple, (input_frames, output_frames).

Trait Implementations§

Source§

impl<T: Sample> From<FastFixedIn<T>> for ResamplerType<T>

Source§

fn from(r: FastFixedIn<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Sample> From<FftFixedIn<T>> for ResamplerType<T>

Source§

fn from(r: FftFixedIn<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Sample> From<SincFixedIn<T>> for ResamplerType<T>

Source§

fn from(r: SincFixedIn<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Sample, const MAX_CHANNELS: usize> Into<ResamplerType<T>> for FixedResampler<T, MAX_CHANNELS>

Source§

fn into(self) -> ResamplerType<T>

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

Auto Trait Implementations§

§

impl<T> Freeze for ResamplerType<T>

§

impl<T> !RefUnwindSafe for ResamplerType<T>

§

impl<T> Send for ResamplerType<T>

§

impl<T> !Sync for ResamplerType<T>

§

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

§

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