audio: Refactoring

This commit is contained in:
Hajime Hoshi 2015-02-14 19:55:43 +09:00
parent beecf31937
commit dc54867401
2 changed files with 11 additions and 14 deletions

View File

@ -147,17 +147,13 @@ func loadChannelBuffer(channel int, bufferSize int) (l, r []int16) {
}
ch := channels[channel]
inputL := make([]int16, bufferSize)
inputR := make([]int16, bufferSize)
length := min(len(ch.l), bufferSize)
for i := 0; i < length; i++ {
inputL[i] = ch.l[i]
inputR[i] = ch.r[i]
}
usedLen := min(bufferSize, len(ch.l))
ch.l = ch.l[usedLen:]
ch.r = ch.r[usedLen:]
inputL := make([]int16, length)
inputR := make([]int16, length)
copy(inputL, ch.l[:length])
copy(inputR, ch.r[:length])
ch.l = ch.l[length:]
ch.r = ch.r[length:]
ch.nextInsertionPosition -= min(bufferSize, ch.nextInsertionPosition)
return inputL, inputR
}

View File

@ -33,12 +33,13 @@ func audioProcess(channel int) func(e js.Object) {
currentPosition += bufferSize
}()
l := e.Get("outputBuffer").Call("getChannelData", 0)
r := e.Get("outputBuffer").Call("getChannelData", 1)
b := e.Get("outputBuffer")
l := b.Call("getChannelData", 0)
r := b.Call("getChannelData", 1)
inputL, inputR := loadChannelBuffer(channel, bufferSize)
const max = 1 << 15
for i := 0; i < bufferSize; i++ {
// TODO: Use copyFromChannel?
for i := 0; i < len(inputL); i++ {
// TODO: Use copyToChannel?
if len(inputL) <= i {
l.SetIndex(i, 0)
r.SetIndex(i, 0)