NxAudio.Transforms.Resample (nx_audio v0.3.1)

View Source

Provides 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:

  1. Upsampling by factor L (insertion of L-1 zeros between samples)
  2. Lowpass filtering with a windowed-sinc kernel
  3. 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

do_transform(audio_tensor, opts \\ [])

transform(audio_tensor, opts \\ [])

Receives an audio tensor in the format {channels, samples} and resamples it to a new frequency.

For options, check NxAudio.Transforms.ResampleConfig.