[audio] Remove 'clac' noise when playing wave (javasound) #2670
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.
A 'clac' can be heard at the beginning of a wav file when playing on the javasound sink.
This is because the code playing the sound targets PCM. But a WAV file has an additional header (fmt). When the code tries to play this header as if it was actual sound, it outputs a "pop" noise.
This bug was first encoutered when playing WAV from the Google TTS, and also in my tests with the Pico TTS, and with the play action from a wav file in the sound directory.
With the fix in this PR, the code consumes (at most) 400 + 2 bytes (if it is a wav file) by trying to get to a "magic" packet that marks the beginning of the real PCM data.
I put the removal code in an utility class because every audio sink playing PCM could potentially need to remove the fmt header.
Close #2669