audio: Bug fix: alGenBuffer accepts only positive number

This commit is contained in:
Hajime Hoshi 2016-02-12 21:43:00 +09:00
parent b2724e8694
commit 68b84a90b6

View File

@ -132,13 +132,15 @@ func (p *player) play() error {
// TODO: What if play is already called? // TODO: What if play is already called?
emptyBytes := make([]byte, bufferSize) emptyBytes := make([]byte, bufferSize)
m.Lock() m.Lock()
queued := p.alSource.BuffersQueued() n := 8 - int(p.alSource.BuffersQueued())
bufs := al.GenBuffers(8 - int(queued)) if 0 < n {
bufs := al.GenBuffers(n)
for _, buf := range bufs { for _, buf := range bufs {
// 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)) buf.BufferData(al.FormatStereo16, emptyBytes, int32(p.sampleRate))
p.alSource.QueueBuffers(buf) p.alSource.QueueBuffers(buf)
} }
}
al.PlaySources(p.alSource) al.PlaySources(p.alSource)
m.Unlock() m.Unlock()
go func() { go func() {