Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/flac2wav: fix encoding of 8-bps WAV; should use uint8, was using signed int #52

Merged
merged 1 commit into from
Feb 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/flac2wav/flac2wav.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,18 @@ func flac2wav(path string, force bool) error {
data = data[:0]
for i := 0; i < frame.Subframes[0].NSamples; i++ {
for _, subframe := range frame.Subframes {
data = append(data, int(subframe.Samples[i]))
sample := int(subframe.Samples[i])
if frame.BitsPerSample == 8 {
// WAV files with 8 bit-per-sample are stored with unsigned
// values, WAV files with more than 8 bit-per-sample are stored
// as signed values (ref page 59-60 of [1]).
//
// [1]: http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf
// ref: https://github.com/mewkiz/flac/issues/51#issuecomment-1046183409
const midpointValue = 0x80
sample += midpointValue
}
data = append(data, sample)
}
}
buf := &audio.IntBuffer{
Expand Down