ResamplerFft

Struct ResamplerFft 

Source
pub struct ResamplerFft<const CHANNEL: usize> { /* private fields */ }
Expand description

High-quality and high-performance FFT-based audio resampler supporting multi-channel audio.

ResamplerFft uses the overlap-add FFT method with Kaiser windowing to convert audio between different sample rates. The const generic parameter CHANNEL specifies the number of audio channels (e.g., 1 for mono, 2 for stereo).

Implementations§

Source§

impl<const CHANNEL: usize> ResamplerFft<CHANNEL>

Source

pub fn new( sample_rate_input: SampleRate, sample_rate_output: SampleRate, ) -> Self

Create a new ResamplerFft.

Parameters are:

  • sample_rate_input: Input sample rate.
  • sample_rate_output: Output sample rate.
Source

pub fn chunk_size_input(&self) -> usize

Returns the required input buffer size in total f32 values (including all channels).

For example, with a stereo resampler (CHANNEL=2), this returns the total number of f32 values needed in the interleaved input buffer [L0, R0, L1, R1, …].

Source

pub fn chunk_size_output(&self) -> usize

Returns the required output buffer size in total f32 values (including all channels).

For example, with a stereo resampler (CHANNEL=2), this returns the total number of f32 values needed in the interleaved output buffer [L0, R0, L1, R1, …].

Source

pub fn delay(&self) -> usize

Returns the algorithmic delay (latency) of the resampler in input samples.

This delay is inherent to the FFT-based overlap-add process and equals half the FFT input size due to the windowing operation.

Source

pub fn resample( &mut self, input: &[f32], output: &mut [f32], ) -> Result<(), ResampleError>

Processes one chunk of audio, resampling from input to output sample rate.

Input and output must be interleaved f32 slices with all channels interleaved. For stereo audio, the format is [L0, R0, L1, R1, ...]. For mono, it’s [S0, S1, S2, ...].

§Parameters
§Example
use resampler::{ResamplerFft, SampleRate};

let mut resampler = ResamplerFft::<1>::new(SampleRate::Hz48000, SampleRate::Hz44100);

let input = vec![0.0f32; resampler.chunk_size_input()];
let mut output = vec![0.0f32; resampler.chunk_size_output()];

match resampler.resample(&input, &mut output) {
    Ok(()) => {
        println!("Resample successfully");
    }
    Err(error) => eprintln!("Resampling error: {error:?}"),
}

Auto Trait Implementations§

§

impl<const CHANNEL: usize> Freeze for ResamplerFft<CHANNEL>

§

impl<const CHANNEL: usize> RefUnwindSafe for ResamplerFft<CHANNEL>

§

impl<const CHANNEL: usize> Send for ResamplerFft<CHANNEL>

§

impl<const CHANNEL: usize> Sync for ResamplerFft<CHANNEL>

§

impl<const CHANNEL: usize> Unpin for ResamplerFft<CHANNEL>

§

impl<const CHANNEL: usize> UnwindSafe for ResamplerFft<CHANNEL>

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.