From b6a8b5f5c95b27cb530cd86d2a10e9033e7ec041 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 27 Nov 2016 20:26:13 +0900 Subject: [PATCH] audio/vorbis: Bug fix: Noise on browsers --- audio/vorbis/decode_js.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/audio/vorbis/decode_js.go b/audio/vorbis/decode_js.go index 591fae65c..a21d36f7c 100644 --- a/audio/vorbis/decode_js.go +++ b/audio/vorbis/decode_js.go @@ -41,8 +41,22 @@ func (s *Stream) Read(b []byte) (int, error) { } l = l / 4 * 4 for i := 0; i < l/4; i++ { - il := int16(s.leftData[s.posInBytes/4+i] * (1 << 15)) - ir := int16(s.rightData[s.posInBytes/4+i] * (1 << 15)) + l := s.leftData[s.posInBytes/4+i] + 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+1] = uint8(il >> 8) b[4*i+2] = uint8(ir)