mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
audio: Refactoring
This commit is contained in:
parent
beecf31937
commit
dc54867401
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user