NxAudio.Transforms.Resample (nx_audio v0.3.1)
View SourceProvides high-quality audio resampling using sinc interpolation.
This module implements a polyphase resampling algorithm that changes the sampling rate of an audio signal while maintaining high fidelity. The process involves three main steps:
- Upsampling by factor L (insertion of L-1 zeros between samples)
- Lowpass filtering with a windowed-sinc kernel
- Downsampling by factor M (keeping every Mth sample)
The mathematical foundation is based on the following equations:
Sinc Filter
The ideal lowpass filter kernel is the sinc function:
$h[n] = \text{sinc}(n) = \frac{\sin(\pi n)}{\pi n}$
Window Functions
The infinite sinc is truncated using either, hann or kaiser window functions
Resampling Process
The complete resampling operation can be expressed as:
$y[n] = \sum_{k} x[k] h[nM/L - k]$
where:
- x[n] is the input signal
- y[n] is the resampled output
- L is the upsampling factor
- M is the downsampling factor
- h[n] is the windowed-sinc filter
The implementation uses efficient polyphase decomposition and the GCD of the target and source sampling rates to minimize computational complexity.
Summary
Functions
Receives an audio tensor in the format {channels, samples} and resamples it to a new frequency.
Functions
@spec transform(NxAudio.IO.audio_tensor(), NxAudio.Transforms.ResampleConfig.t()) :: NxAudio.IO.audio_tensor()
Receives an audio tensor in the format {channels, samples} and resamples it to a new frequency.
For options, check NxAudio.Transforms.ResampleConfig
.