mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +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 {
|
if !audioEnabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
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.buffer = ch.buffer[length:]
|
ch.buffer = ch.buffer[length:]
|
||||||
|
|
||||||
r = input
|
r = input
|
||||||
})
|
})
|
||||||
return r
|
return r
|
||||||
|
@ -44,16 +44,21 @@ func toLR(data []byte) ([]int16, []int16) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *audioProcessor) Process(e *js.Object) {
|
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")
|
b := e.Get("outputBuffer")
|
||||||
l := b.Call("getChannelData", 0)
|
l := b.Call("getChannelData", 0)
|
||||||
r := b.Call("getChannelData", 1)
|
r := b.Call("getChannelData", 1)
|
||||||
inputL, inputR := toLR(loadChannelBuffer(a.channel, bufferSize*4))
|
inputL, inputR := toLR(loadChannelBuffer(a.channel, bufferSize*4))
|
||||||
const max = 1 << 15
|
const max = 1 << 15
|
||||||
for i := 0; i < len(inputL); i++ {
|
for i := 0; i < bufferSize; i++ {
|
||||||
// TODO: Use copyToChannel?
|
// TODO: Use copyToChannel?
|
||||||
l.SetIndex(i, float64(inputL[i])/max)
|
if i < len(inputL) {
|
||||||
r.SetIndex(i, float64(inputR[i])/max)
|
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