Sample-rate conversion for audio in Zig: any rate to any other, as a stream

Sample-rate conversion for audio

Bandlimited interpolation, as Smith and Gossett describe it: each output the input's value between its samples, weighted by a Kaiser-windowed sinc kept as a table of 512 values a zero crossing and read between them; cut off at the lower rate's Nyquist frequency, so that going down in rate filters out what the new rate cannot carry. Any ratio, any channel count, interleaved f32, streaming; time kept exactly as a count, so nothing drifts; flushed, exactly ceil(frames * out / in) frames, aligned with the input. Tested against tones: 44.1 to 48 kHz within 60, 80 and 100 dB for the three qualities, aliasing 80 dB down going to 8 kHz, a passband tone kept within 0.01 dB, channels apart through 44 100 to 44 101, a step where it was. Fuzzed for any rates, channels and pieces: exact length, finite and bounded output, pieces bit-identical to whole, nothing leaked. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zMkSofB1qCR4M4bBFQ2ro


Author jcollie.dev
Co-author Claude Opus 5.5 (1M context) Date Commit