Skip to content

Commit

Permalink
darwin: Add error handlings
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Sep 16, 2019
1 parent e6d5ffc commit 811d7bf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,21 @@ func newDriver(sampleRate, channelNum, bitDepthInBytes, bufferSizeInBytes int) (
setDriver(d)

for i := 0; i < len(d.buffers); i++ {
C.AudioQueueAllocateBuffer(audioQueue, C.UInt32(queueBufferSize), &d.buffers[i])
if osstatus := C.AudioQueueAllocateBuffer(audioQueue, C.UInt32(queueBufferSize), &d.buffers[i]); osstatus != C.noErr {
return nil, fmt.Errorf("oto: AudioQueueAllocateBuffer failed: %d", osstatus)
}
d.buffers[i].mAudioDataByteSize = C.UInt32(queueBufferSize)
for j := 0; j < queueBufferSize; j++ {
*(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(d.buffers[i].mAudioData)) + uintptr(j))) = 0
}
C.AudioQueueEnqueueBuffer(audioQueue, d.buffers[i], 0, nil)
if osstatus := C.AudioQueueEnqueueBuffer(audioQueue, d.buffers[i], 0, nil); osstatus != C.noErr {
return nil, fmt.Errorf("oto: AudioQueueEnqueueBuffer failed: %d", osstatus)
}
}

C.AudioQueueStart(audioQueue, nil)
if osstatus := C.AudioQueueStart(audioQueue, nil); osstatus != C.noErr {
return nil, fmt.Errorf("oto: AudioQueueStart failed: %d", osstatus)
}

return d, nil
}
Expand Down Expand Up @@ -165,6 +171,7 @@ loop:
}
// Do not update mAudioDataByteSize, or the buffer is not used correctly any more.

// TODO: Check errors?
C.AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, nil)
}

Expand Down

0 comments on commit 811d7bf

Please sign in to comment.