Skip to content

Transparent audio conversion: sinc resampling, drift correction, dither - #6

Merged
rhaist merged 1 commit into
mainfrom
audio-quality
Nov 9, 2026
Merged

rhaist merged 1 commit into
mainfrom
audio-quality

Conversation

@rhaist

@rhaist rhaist commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Makes podbeam's own audio chain transparent, for the 0.2.0 release (not tagged yet).

1. Sinc resampling instead of linear interpolation. Resampling now happens per packet, with a 256-tap sinc filter from rubato (FFT resamplers turned off). Measured with a 48 kHz → 44.1 kHz tone:

old (linear) new (sinc + dither)
1 kHz: signal vs. everything else 64 dB 87.2 dB
10 kHz 22 dB, −1.3 dB level 87.3 dB, ±0.000 dB
15 kHz 13 dB, −2.9 dB level 87.3 dB, ±0.000 dB

87 dB is the theoretical limit of 16-bit audio with TPDF dither.

2. Clock-drift correction instead of skips. The resampler ratio is nudged by at most ±1000 ppm (under 2 cents) to hold the capture backlog at its target. That replaces the ~20 ms skip every few minutes. Trimming stays only as a safety net after a stall, such as the PC waking from sleep. In the test with a sound card running 300 ppm fast, the backlog stays within 1 ms of target.

3. TPDF dither instead of truncation when converting to 16 bit. Quiet passages keep detail below one bit, and digital silence stays exactly silent with no dither hiss.

Testing:

  • New tests: tone purity and level at 1/10/15 kHz, drift tracking, and dither.
  • Existing live tests: both PulseAudio tests pass on the new f32 capture path.
  • Builds: clippy passes with -D warnings on Linux and Windows. rubato is built with opt-level = 3 even in debug builds, so the tests stay fast (about 2 s).
  • Dependencies: 7 small new crates; cargo audit is clean.

Not covered: streaming to a real HomePod from this branch. The audio path into the packet changed, but the packets themselves did not.


Generated by Claude Code

- Resampling to 44.1 kHz now uses a 256-tap sinc filter (rubato) per
  packet instead of linear interpolation in the capture callback. The old
  path measured 64 dB at 1 kHz, 22 dB at 10 kHz and lost 2.9 dB of level
  at 15 kHz; the new one measures 87 dB from 1 to 15 kHz with a flat
  response, the limit of dithered 16-bit audio.
- Clock drift between sound card and network is absorbed by nudging the
  resampler ratio (at most ±1000 ppm) to hold the capture backlog at its
  target, replacing the periodic ~20 ms skips. Trimming stays only as a
  safety net after stalls.
- 16-bit conversion uses TPDF dither and rounding instead of truncation;
  digital silence stays exactly silent.

Tests cover tone purity and level at 1/10/15 kHz, drift tracking at
+300 ppm and dither below one LSB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0153Jh6SvWis1QdJPf8i76cv
@rhaist
rhaist merged commit 39777b8 into main Nov 9, 2026
5 checks passed
@rhaist
rhaist deleted the audio-quality branch November 9, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant