mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: Bug fix: always fill zero values (#147)
This commit is contained in:
parent
4b4802419b
commit
45329ab32f
@ -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
|
||||
|
@ -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?
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user