mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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]
|
ch := channels[channel]
|
||||||
inputL := make([]int16, bufferSize)
|
|
||||||
inputR := make([]int16, bufferSize)
|
|
||||||
length := min(len(ch.l), bufferSize)
|
length := min(len(ch.l), bufferSize)
|
||||||
for i := 0; i < length; i++ {
|
inputL := make([]int16, length)
|
||||||
inputL[i] = ch.l[i]
|
inputR := make([]int16, length)
|
||||||
inputR[i] = ch.r[i]
|
copy(inputL, ch.l[:length])
|
||||||
}
|
copy(inputR, ch.r[:length])
|
||||||
usedLen := min(bufferSize, len(ch.l))
|
ch.l = ch.l[length:]
|
||||||
ch.l = ch.l[usedLen:]
|
ch.r = ch.r[length:]
|
||||||
ch.r = ch.r[usedLen:]
|
|
||||||
|
|
||||||
ch.nextInsertionPosition -= min(bufferSize, ch.nextInsertionPosition)
|
ch.nextInsertionPosition -= min(bufferSize, ch.nextInsertionPosition)
|
||||||
return inputL, inputR
|
return inputL, inputR
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,13 @@ func audioProcess(channel int) func(e js.Object) {
|
|||||||
currentPosition += bufferSize
|
currentPosition += bufferSize
|
||||||
}()
|
}()
|
||||||
|
|
||||||
l := e.Get("outputBuffer").Call("getChannelData", 0)
|
b := e.Get("outputBuffer")
|
||||||
r := e.Get("outputBuffer").Call("getChannelData", 1)
|
l := b.Call("getChannelData", 0)
|
||||||
|
r := b.Call("getChannelData", 1)
|
||||||
inputL, inputR := loadChannelBuffer(channel, bufferSize)
|
inputL, inputR := loadChannelBuffer(channel, bufferSize)
|
||||||
const max = 1 << 15
|
const max = 1 << 15
|
||||||
for i := 0; i < bufferSize; i++ {
|
for i := 0; i < len(inputL); i++ {
|
||||||
// TODO: Use copyFromChannel?
|
// TODO: Use copyToChannel?
|
||||||
if len(inputL) <= i {
|
if len(inputL) <= i {
|
||||||
l.SetIndex(i, 0)
|
l.SetIndex(i, 0)
|
||||||
r.SetIndex(i, 0)
|
r.SetIndex(i, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user