diff --git a/buffer.go b/buffer.go index c20b993..a8536b0 100644 --- a/buffer.go +++ b/buffer.go @@ -128,26 +128,26 @@ func decodeFloat(signed bool, precision int, p []byte) (x float64, n int) { func floatToSigned(precision int, x float64) uint64 { if x < 0 { - compl := uint64(-x * (math.Exp2(float64(precision)*8-1) - 1)) + compl := uint64(-x * math.Exp2(float64(precision)*8-1)) return uint64(1<= 1<= 2: for i, j := 0, 0; i <= n-bytesPerFrame; i, j = i+bytesPerFrame, j+1 { - samples[j][0] = float64(p[i+0])/(1<<8-1)*2 - 1 - samples[j][1] = float64(p[i+1])/(1<<8-1)*2 - 1 + samples[j][0] = float64(p[i+0])/(1<<8)*2 - 1 + samples[j][1] = float64(p[i+1])/(1<<8)*2 - 1 } 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<<16 - 1) + val := float64(int16(p[i+0])+int16(p[i+1])*(1<<8)) / (1 << 15) 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<<16 - 1) - samples[j][1] = float64(int16(p[i+2])+int16(p[i+3])*(1<<8)) / (1<<16 - 1) + samples[j][0] = float64(int16(p[i+0])+int16(p[i+1])*(1<<8)) / (1 << 15) + samples[j][1] = float64(int16(p[i+2])+int16(p[i+3])*(1<<8)) / (1 << 15) } 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<<24 - 1) + val := float64((int32(p[i+0])<<8)+(int32(p[i+1])<<16)+(int32(p[i+2])<<24)) / (1 << 8) / (1 << 23) 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<<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) + samples[j][0] = float64((int32(p[i+0])<<8)+(int32(p[i+1])<<16)+(int32(p[i+2])<<24)) / (1 << 8) / (1 << 23) + samples[j][1] = float64((int32(p[i+3])<<8)+(int32(p[i+4])<<16)+(int32(p[i+5])<<24)) / (1 << 8) / (1 << 23) } } d.pos += int32(n)