Fix stereo compressed (FLAC/OGG) samples truncated to half length#150
Merged
git-moss merged 2 commits intoJun 22, 2026
Merged
Conversation
AudioFileUtils.decompressToWav computed the frame count as audioDataBytes.length / (frameSize * channels). AudioFormat.getFrameSize() already accounts for all channels (bytes-per-sample * channels), so the extra "* channels" halved the frame count for stereo samples and truncated them to their first half. For mono samples the result was correct, which is why this went unnoticed. This corrupted any conversion from a format that stores stereo compressed audio (e.g. a Renoise XRNI, which stores FLAC) to a destination written as uncompressed WAV: the second half of every sample was dropped and, because loop positions can be stored as a fraction of the sample length, the loop point landed in the wrong position and produced an audible click at the loop seam.
Contributor
Author
|
A couple of notes for merging: 1. Standalone fix, but especially relevant to #149 (Renoise XRNI support). This is a pre-existing bug independent of Renoise, but reading an XRNI's stereo FLAC samples into an uncompressed destination was being halved by it — so this PR and #149 complement each other. 2. Small overlap with #149 in |
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.
Problem
AudioFileUtils.decompressToWavcomputes the number of frames as:AudioFormat.getFrameSize()already accounts for all channels (bytes-per-sample × channels), so multiplying bychannelsagain divides by the channel count twice. For stereo samples this yields half the real frame count, so theAudioInputStreamis told it is half as long andAudioSystem.writeemits only the first half of the audio. Mono samples (channels = 1) are unaffected, which is why this went unnoticed.Impact
Any conversion from a format that stores stereo compressed audio (FLAC/OGG) to a destination written as uncompressed WAV loses the second half of every sample. Because some creators store loop positions as a fraction of the sample length (e.g. Waldorf Quantum/Iridium), the loop end then lands at the wrong position in the now-shorter sample, which is audible as a click at the loop point.
Concrete example: converting a Renoise instrument (XRNI, which stores stereo FLAC) to Waldorf Quantum/Iridium produced 8.03 s patches from 16.05 s sources, and a sustained-note loop clicked on the hardware.
Fix
Drop the redundant
* channels:Verification
For a stereo 48 kHz source resampled to 44.1 kHz / 16-bit: