mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
audio: Refactoring
This commit is contained in:
parent
3cedae882f
commit
1ded7dc6b8
@ -29,9 +29,6 @@ const (
|
||||
maxBufferNum = 8
|
||||
)
|
||||
|
||||
// TODO: This should be in player
|
||||
var totalBufferNum = 0
|
||||
|
||||
type player struct {
|
||||
alSource al.Source
|
||||
alBuffers []al.Buffer
|
||||
@ -56,22 +53,12 @@ func newPlayer(src io.Reader, sampleRate int) (*player, error) {
|
||||
}
|
||||
runtime.SetFinalizer(p, (*player).close)
|
||||
|
||||
n := maxBufferNum - int(p.alSource.BuffersQueued()) - len(p.alBuffers)
|
||||
if 0 < n {
|
||||
p.alBuffers = append(p.alBuffers, al.GenBuffers(n)...)
|
||||
totalBufferNum += n
|
||||
if maxBufferNum < totalBufferNum {
|
||||
panic("audio: not reach: too many buffers are created")
|
||||
}
|
||||
}
|
||||
if 0 < len(p.alBuffers) {
|
||||
bs := al.GenBuffers(maxBufferNum)
|
||||
emptyBytes := make([]byte, bufferSize)
|
||||
for _, buf := range p.alBuffers {
|
||||
for _, b := range bs {
|
||||
// Note that the third argument of only the first buffer is used.
|
||||
buf.BufferData(al.FormatStereo16, emptyBytes, int32(p.sampleRate))
|
||||
p.alSource.QueueBuffers(buf)
|
||||
}
|
||||
p.alBuffers = []al.Buffer{}
|
||||
b.BufferData(al.FormatStereo16, emptyBytes, int32(p.sampleRate))
|
||||
p.alSource.QueueBuffers(b)
|
||||
}
|
||||
al.PlaySources(p.alSource)
|
||||
return p, nil
|
||||
|
Loading…
Reference in New Issue
Block a user