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 return false, nil
} }
bs := make([]byte, p.context.oneBufferSize()) oneBufferSize := p.context.oneBufferSize()
n := copy(bs, p.buf) n := oneBufferSize
var signal bool if len(p.buf) < n {
if len(p.buf[n:]) < p.context.maxBufferSize() { n = len(p.buf)
signal = true
} }
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 *(*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 { if osstatus := C.AudioQueueEnqueueBuffer(p.audioQueue, inBuffer, 0, nil); osstatus != C.noErr {
// This can happen just after resetting. // This can happen just after resetting.