Skip to main content

Module resample

Module resample 

Source
Expand description

Sample-rate conversion using rubato’s SincFixedIn (high-quality windowed-sinc with band-limited interpolation).

Common case: 44.1 kHz MP3 source → 48 kHz Opus encoder. Less common: 22.05 / 32 / 96 kHz inputs. rubato handles arbitrary float ratios so we just compute out_rate / in_rate and feed it to SincFixedIn.

Squad-23 doesn’t call this directly — it goes through the Opus encoder, which holds an Option<Resampler> that’s Some whenever the input rate differs from 48 kHz.

§Layout conversion

Rubato wants non-interleaved (Vec<Vec<f32>>, one inner Vec per channel) — the codec module’s AudioFrame uses interleaved planar to match the rest of the codebase. We deinterleave at input, re-interleave at output. The cost is one extra pair of allocations per frame; for 20 ms of stereo at 48 kHz this is 1920 samples — a few µs at most, well below the per-frame budget of ~20 ms.

§PTS through resampling

Output PTS = input PTS. The lookahead delay rubato adds to satisfy its sinc filter is collapsed into the encoder’s pre_skip when Opus is the consumer; downstream callers should not see PTS drift.

Structs§

AudioResampler