From 9f69bc6b3d3c98f7a4b9d765b755d297a8ec5742 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 27 Jan 2020 17:02:20 -0800 Subject: [PATCH] wav: Resolve conversion issues Resolves #69 --- wav/decode.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wav/decode.go b/wav/decode.go index 7bf04b5..0db9da2 100644 --- a/wav/decode.go +++ b/wav/decode.go @@ -227,25 +227,25 @@ func (d *decoder) Stream(samples [][2]float64) (n int, ok bool) { } case d.h.BitsPerSample == 16 && d.h.NumChans == 1: for i, j := 0, 0; i <= n-bytesPerFrame; i, j = i+bytesPerFrame, j+1 { - val := float64(int16(p[i+0])+int16(p[i+1])*(1<<8)) / (1<<15 - 1) + val := float64(int16(p[i+0])+int16(p[i+1])*(1<<8)) / (1<<16 - 1) samples[j][0] = val samples[j][1] = val } case d.h.BitsPerSample == 16 && d.h.NumChans >= 2: for i, j := 0, 0; i <= n-bytesPerFrame; i, j = i+bytesPerFrame, j+1 { - samples[j][0] = float64(int16(p[i+0])+int16(p[i+1])*(1<<8)) / (1<<15 - 1) - samples[j][1] = float64(int16(p[i+2])+int16(p[i+3])*(1<<8)) / (1<<15 - 1) + samples[j][0] = float64(int16(p[i+0])+int16(p[i+1])*(1<<8)) / (1<<16 - 1) + samples[j][1] = float64(int16(p[i+2])+int16(p[i+3])*(1<<8)) / (1<<16 - 1) } - case d.h.BitsPerSample == 24 && d.h.NumChans >= 1: + case d.h.BitsPerSample == 24 && d.h.NumChans == 1: for i, j := 0, 0; i <= n-bytesPerFrame; i, j = i+bytesPerFrame, j+1 { - val := float64((int32(p[i+0])<<8)+(int32(p[i+1])<<16)+(int32(p[i+2])<<24)) / (1 << 8) / (1<<23 - 1) + val := float64((int32(p[i+0])<<8)+(int32(p[i+1])<<16)+(int32(p[i+2])<<24)) / (1 << 8) / (1<<24 - 1) samples[j][0] = val samples[j][1] = val } case d.h.BitsPerSample == 24 && d.h.NumChans >= 2: for i, j := 0, 0; i <= n-bytesPerFrame; i, j = i+bytesPerFrame, j+1 { - samples[j][0] = float64((int32(p[i+0])<<8)+(int32(p[i+1])<<16)+(int32(p[i+2])<<24)) / (1 << 8) / (1<<23 - 1) - samples[j][1] = float64((int32(p[i+3])<<8)+(int32(p[i+4])<<16)+(int32(p[i+5])<<24)) / (1 << 8) / (1<<23 - 1) + samples[j][0] = float64((int32(p[i+0])<<8)+(int32(p[i+1])<<16)+(int32(p[i+2])<<24)) / (1 << 8) / (1<<24 - 1) + samples[j][1] = float64((int32(p[i+3])<<8)+(int32(p[i+4])<<16)+(int32(p[i+5])<<24)) / (1 << 8) / (1<<24 - 1) } } d.pos += int32(n)