WavWriter: fix SaveFile final flushing + add comprehensive unit test coverage#696
Open
chattob wants to merge 7 commits intoelectro-smith:masterfrom
Open
WavWriter: fix SaveFile final flushing + add comprehensive unit test coverage#696chattob wants to merge 7 commits intoelectro-smith:masterfrom
chattob wants to merge 7 commits intoelectro-smith:masterfrom
Conversation
added 7 commits
March 12, 2026 12:39
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
This PR fixes
WavWriterfinalization bugs and adds comprehensive unit tests.What Was Fixed
SaveFile()final flush logic at buffer boundariesOn
master,SaveFile()does not flush any pending full half-buffer before finalizing. Instead, it writeswptr_ * bytes_per_samplebytes starting at the beginning of the transfer buffer.That is only correct while recording is still in the first half of the buffer. Once recording has advanced into the second half the final WAV tail repeats earlier samples from the first half.
The fix changes finalization to:
Uninitialized writer state
Init()andOpenFile()now reset the writer’s internal state and clear the transfer buffer before a new recording starts.This is more a preventive measure.
Missing WAV type dependency in header
src/util/WavWriter.hnow includesutil/wav_format.h, soWAV_FormatTypeDefand the WAV constants are always available.Test Coverage Added
Save-path state transitions
FLUSH0FLUSH0+ second-half tailFLUSH1FLUSH1+ new first-half tailRepresentative format cases
Validation
util_WavWritertests via CMake/CTest. The new tests expose the old finalization regressions and pass with the fix.