Skip to content

Commit

Permalink
Merge pull request #79 from tslocum/wavfixes
Browse files Browse the repository at this point in the history
wav: Resolve conversion issues
  • Loading branch information
dusk125 committed Aug 31, 2021
2 parents b1fa209 + 9f69bc6 commit 00d0eee
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions wav/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,25 +230,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)
Expand Down

0 comments on commit 00d0eee

Please sign in to comment.