audio: Fix buffer size calculation

This commit is contained in:
Hajime Hoshi 2015-06-14 03:50:29 +09:00
parent 564248641b
commit cba1066b0f

View File

@ -96,11 +96,7 @@ func Queue(channel int, data []byte) {
func Tick() { func Tick() {
for _, ch := range channels { for _, ch := range channels {
if 0 < len(ch.buffer) { ch.nextInsertionPosition += SampleRate * 4 / 60
ch.nextInsertionPosition += SampleRate * 4 / 60
} else {
ch.nextInsertionPosition = 0
}
} }
} }
@ -140,11 +136,13 @@ func loadChannelBuffer(channel int, bufferSize int) []byte {
ch := channels[channel] ch := channels[channel]
length := min(len(ch.buffer), bufferSize) length := min(len(ch.buffer), bufferSize)
input := ch.buffer[:length] input := ch.buffer[:length]
ch.nextInsertionPosition -= length ch.buffer = ch.buffer[length:]
ch.nextInsertionPosition -= bufferSize
if ch.nextInsertionPosition < 0 { if ch.nextInsertionPosition < 0 {
ch.nextInsertionPosition = 0 ch.nextInsertionPosition = 0
} }
ch.buffer = ch.buffer[length:]
r = input r = input
}) })
return r return r