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

ref: https://github.com/mewkiz/flac/issues/51#issuecomment-1046183409

Updates #mewkiz/flac#51.
This commit is contained in:
Robin 2022-02-20 17:01:16 +01:00 committed by GitHub
parent 59ff7d9caa
commit 42d25f4866
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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{