audio/internal/readerdriver: Refactoring

This commit is contained in:
Hajime Hoshi 2021-05-17 03:51:24 +09:00
parent d1138bc615
commit 089883aba0

View File

@ -593,16 +593,20 @@ func (p *playerImpl) appendBufferImpl(inBuffer C.AudioQueueBufferRef) (bool, err
return false, nil
}
bs := make([]byte, p.context.oneBufferSize())
n := copy(bs, p.buf)
var signal bool
if len(p.buf[n:]) < p.context.maxBufferSize() {
signal = true
oneBufferSize := p.context.oneBufferSize()
n := oneBufferSize
if len(p.buf) < n {
n = len(p.buf)
}
buf := p.buf[:n]
signal := len(p.buf[n:]) < p.context.maxBufferSize()
for i, b := range bs {
for i, b := range buf {
*(*byte)(unsafe.Pointer(uintptr(inBuffer.mAudioData) + uintptr(i))) = b
}
for i := len(buf); i < oneBufferSize; i++ {
*(*byte)(unsafe.Pointer(uintptr(inBuffer.mAudioData) + uintptr(i))) = 0
}
if osstatus := C.AudioQueueEnqueueBuffer(p.audioQueue, inBuffer, 0, nil); osstatus != C.noErr {
// This can happen just after resetting.