Skip to content

fix(audio): reset resampler state between recordings to prevent audio crosstalk#1344

Open
andrewleech wants to merge 1 commit into
cjpais:mainfrom
andrewleech:fix/resampler-state-leak
Open

fix(audio): reset resampler state between recordings to prevent audio crosstalk#1344
andrewleech wants to merge 1 commit into
cjpais:mainfrom
andrewleech:fix/resampler-state-leak

Conversation

@andrewleech
Copy link
Copy Markdown

@andrewleech andrewleech commented Apr 29, 2026

Before Submitting This PR

Please confirm you have done the following:

Human Written Description

The FrameResampler is created once per audio session and reused across multiple recordings without clearing its internal buffers. The rubato FftFixedIn overlap buffers retained audio from the previous recording, so the first ~30ms of each new recording contained stale samples from the prior one. This manifested as lost or corrupted words at the start of transcriptions and occasional stale text fragments (e.g. `ology.`) leaking into new sessions.

Adding a reset() that clears in_buf, pending, and calls rubato's own reset() to zero the FFT overlap buffers — invoked on Cmd::Start alongside the existing processed_samples and VAD resets — fixes it cleanly without touching the steady-state hot path.

Related Issues/Discussions

Fixes #

Community Feedback

Not yet gathered. The bug surfaced from my own use rather than a reported issue, but it's a real correctness problem affecting any user who records back-to-back without restarting the app.

Testing

  • New unit tests in `resampler.rs`:
    • `reset_clears_in_buf_and_pending` — verifies internal buffers are cleared.
    • `reset_zeroes_rubato_overlap` — pushes a sine wave, resets, then pushes silence and confirms the output is silent (no overlap leak).
  • Manual verification: recorded several short utterances back-to-back; previously the first word of each was clipped or contained text from the prior recording, after the fix transcriptions are clean from the first frame.

Screenshots/Videos (if applicable)

N/A — audio-pipeline correctness fix.

AI Assistance

  • No AI was used in this PR
  • AI was used (please describe below)

If AI was used:

  • Tools used: Claude Code
  • How extensively: original diagnosis, code, tests, reviews were all handled in collaboration with claude code / opus 4.6.

@cjpais
Copy link
Copy Markdown
Owner

cjpais commented Apr 29, 2026

Probably a good change, I will test it when I can and pull it in

The FrameResampler was created once per audio session and reused across
multiple recordings without clearing its internal buffers. The rubato
FftFixedIn overlap buffers retained audio from the previous recording,
causing the first ~30ms of each new recording to contain stale samples.

This manifested as lost/corrupted words at the start of transcriptions
and occasional stale text fragments (e.g. "ology.") from previous
sessions leaking into new ones.

Fix: add FrameResampler::reset() that clears in_buf, pending, and
calls rubato's reset() to zero the FFT overlap buffers. Called on
Cmd::Start alongside the existing processed_samples and VAD resets.
@andrewleech andrewleech force-pushed the fix/resampler-state-leak branch from 2bc524c to d560930 Compare May 8, 2026 14:10
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.

3 participants