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