Fix sonicFlushStream understating duration at low speed - #11
Open
austek wants to merge 1 commit into
Open
Conversation
sonicFlushStream appends 2*maxRequired samples of silence directly to stream->numInputSamples (giving the pitch-period algorithms enough lookahead to drain whatever's still buffered) but never advances stream->inputPlayTime to match. processStreamInput computes its actual working speed for insertPitchPeriod as numInputSamples * samplePeriod / inputPlayTime -- so once the padding inflates numInputSamples without inputPlayTime keeping pace, that computed speed comes out well above the caller's requested speed for the rest of the flush, compressing the tail of real audio (and the silence padding after it) into a far shorter span than it should, and whatever's left over reads back as silence. Fix: advance inputPlayTime by the same formula updateNumInputSamples already uses for real writes (numSamples * samplePeriod / speed) when appending the flush padding. Adds tests/slowdown_flush_test.c, verified failing before this fix and passing after. Ported from waywardgeek/sonic#74, which fixes the same bug (also present here, byte-identical sonicFlushStream/processStreamInput) upstream.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Same bug, same fix as waywardgeek/sonic#74 (which also fixes a second, related upstream report at a less extreme speed) — this repo's
sonicFlushStream/processStreamInputare byte-identical to what those had upstream, so the fix ports directly.sonicFlushStreamappends2*maxRequiredsamples of silence directly tostream->numInputSamples(giving the pitch-period algorithms enough lookahead to drain whatever's still buffered) but never advancesstream->inputPlayTimeto match.processStreamInputcomputes its actual working speed forinsertPitchPeriodasnumInputSamples * samplePeriod / inputPlayTime— so once the padding inflatesnumInputSampleswithoutinputPlayTimekeeping pace, that computed speed comes out well above the caller's requested speed for the rest of the flush, compressing the tail of real audio (and the silence padding after it) into a far shorter span than it should, and whatever's left over reads back as silence.Fix
Advance
inputPlayTimeby the same formulaupdateNumInputSamplesalready uses for real writes (numSamples * samplePeriod / speed) when appending the flush padding. A one-line addition.Tests
Adds
tests/slowdown_flush_test.c, verified failing before this fix and passing after.Test plan
cd tests && make runtests && ./runtests— passes, new test included-fsanitize=address,undefined— no finding from this path; only the separate, already-knownfindSincCoefficientfinding remains