audio/vorbis: Bug fix: Noise on browsers

This commit is contained in:
Hajime Hoshi 2016-11-27 20:26:13 +09:00
parent 78609fd705
commit b6a8b5f5c9

View File

@ -41,8 +41,22 @@ func (s *Stream) Read(b []byte) (int, error) {
} }
l = l / 4 * 4 l = l / 4 * 4
for i := 0; i < l/4; i++ { for i := 0; i < l/4; i++ {
il := int16(s.leftData[s.posInBytes/4+i] * (1 << 15)) l := s.leftData[s.posInBytes/4+i]
ir := int16(s.rightData[s.posInBytes/4+i] * (1 << 15)) r := s.rightData[s.posInBytes/4+i]
if 1 < l {
l = 1
}
if l < -1 {
l = -1
}
if 1 < r {
r = 1
}
if r < -1 {
r = -1
}
il := int16(l * ((1 << 15) - 1))
ir := int16(r * ((1 << 15) - 1))
b[4*i] = uint8(il) b[4*i] = uint8(il)
b[4*i+1] = uint8(il >> 8) b[4*i+1] = uint8(il >> 8)
b[4*i+2] = uint8(ir) b[4*i+2] = uint8(ir)