audio: Bug fix: always fill zero values (#147)

This commit is contained in:
Hajime Hoshi 2016-02-08 04:27:21 +09:00
parent 4b4802419b
commit 45329ab32f
2 changed files with 9 additions and 6 deletions

View File

@ -119,12 +119,10 @@ func loadChannelBuffer(channel int, bufferSize int) []byte {
if !audioEnabled {
return
}
ch := channels[channel]
length := min(len(ch.buffer), bufferSize)
input := ch.buffer[:length]
ch.buffer = ch.buffer[length:]
r = input
})
return r

View File

@ -44,16 +44,21 @@ func toLR(data []byte) ([]int16, []int16) {
}
func (a *audioProcessor) Process(e *js.Object) {
// Can't use 'go' here. Probably it may cause race conditions.
// Can't use goroutines here. Probably it may cause race conditions.
b := e.Get("outputBuffer")
l := b.Call("getChannelData", 0)
r := b.Call("getChannelData", 1)
inputL, inputR := toLR(loadChannelBuffer(a.channel, bufferSize*4))
const max = 1 << 15
for i := 0; i < len(inputL); i++ {
for i := 0; i < bufferSize; i++ {
// TODO: Use copyToChannel?
l.SetIndex(i, float64(inputL[i])/max)
r.SetIndex(i, float64(inputR[i])/max)
if i < len(inputL) {
l.SetIndex(i, float64(inputL[i])/max)
r.SetIndex(i, float64(inputR[i])/max)
} else {
l.SetIndex(i, 0)
r.SetIndex(i, 0)
}
}
}