Skip to content

[codex] Clear stale output samples on underrun#152

Open
failuresmith wants to merge 1 commit intoteamclouday:mainfrom
failuresmith:codex/clear-stale-output-samples-on-underrun
Open

[codex] Clear stale output samples on underrun#152
failuresmith wants to merge 1 commit intoteamclouday:mainfrom
failuresmith:codex/clear-stale-output-samples-on-underrun

Conversation

@failuresmith
Copy link
Copy Markdown

What changed

  • zero-fill the CPAL output buffer before copying samples from the ring buffer
  • add regression tests for empty-buffer and partial-buffer underrun cases
  • drop the unrelated RNNoise, Speex, resampler, and shared-buffer tuning from this fix

Why

This issue was caused by process_audio leaving part or all of the output slice untouched when the ring buffer did not have enough bytes for a full callback. In those underrun paths, CPAL reused whatever values were already present in data, which replayed stale samples and sounded like duplicated audio.

The fix is to treat underruns as silence by default and then overwrite only the samples we actually received.

Impact

  • full underruns now output silence instead of stale audio
  • partial underruns preserve the valid samples and zero-fill the remainder of the callback buffer
  • the change is limited to the output callback path and is easy to revert if needed

Validation

  • cargo fmt --check
  • cargo clippy --lib --tests --all-features -- -D warnings
  • cargo test --lib --all-features
  • cargo check --lib --tests --all-features
  • cargo build --lib --tests --all-features

Notes

Repository-wide cargo clippy --all-targets --all-features -- -D warnings still reports an existing benches/audio.rs warning unrelated to this patch.

@failuresmith failuresmith marked this pull request as ready for review May 4, 2026 09:43
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