mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
audio: Refactoring again (OpenAL's buffer requires fixed-size data)
This commit is contained in:
parent
e13e153cb4
commit
d5a2bdd7ac
@ -148,8 +148,8 @@ func loadChannelBuffer(channel int, bufferSize int) (l, r []int16) {
|
||||
|
||||
ch := channels[channel]
|
||||
length := min(len(ch.l), bufferSize)
|
||||
inputL := make([]int16, bufferSize)
|
||||
inputR := make([]int16, bufferSize)
|
||||
inputL := make([]int16, length)
|
||||
inputR := make([]int16, length)
|
||||
copy(inputL, ch.l[:length])
|
||||
copy(inputR, ch.r[:length])
|
||||
ch.l = ch.l[length:]
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func toBytes(l, r []int16) []byte {
|
||||
func toBytesWithPadding(l, r []int16, size int) []byte {
|
||||
if len(l) != len(r) {
|
||||
panic("len(l) must equal to len(r)")
|
||||
}
|
||||
@ -36,6 +36,11 @@ func toBytes(l, r []int16) []byte {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
if 0 < size-len(l) {
|
||||
if err := binary.Write(b, binary.LittleEndian, make([]int16, (size-len(l))*2)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
@ -91,7 +96,7 @@ func initialize() {
|
||||
source.UnqueueBuffers(buffers)
|
||||
for _, buffer := range buffers {
|
||||
l, r := loadChannelBuffer(channel, bufferSize)
|
||||
b := toBytes(l, r)
|
||||
b := toBytesWithPadding(l, r, bufferSize)
|
||||
buffer.SetData(openal.FormatStereo16, b, SampleRate)
|
||||
source.QueueBuffer(buffer)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user