WavWriter: fix SaveFile final flushing + add comprehensive unit test coverage#696
Conversation
|
This looks great! While minimal, the FatFS mock is pretty clean, and allows for a good foundation for confirming the logic of the classes using it. I'll be reviewing/merging a few other PRs this week, and should be able to merge this at the same time. If I notice anything while going through typical pre-merge testing, I'll let you know. Otherwise, this looks good to me! Thanks for the contribution! |
|
Alright, test coverage seems good, and I did a bit of testing on hardware to check for any regressions/behavioral issues. Seems good to me! I also wrote a more real-time oriented example program since the current example in the repo only does an offline render, which isn't typically what users would be trying to do. I'll add that to the examples after merge. |
|
Thanks again for the contribution, @chattob !! |
|
I'm really glad I could contribute! Thanks for your work on daisy |
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.