From cdb02e2b460833db327103e43886e94e1c116c88 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Aug 2015 13:11:34 -0700 Subject: [PATCH] CoreAudio: underflow test passes --- README.md | 1 - src/coreaudio.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8cd16f9..9060eff 100644 --- a/README.md +++ b/README.md @@ -251,7 +251,6 @@ view `coverage/index.html` in a browser. 0. implement CoreAudio (OSX) backend, get examples working - microphone example - - underflow example 0. ALSA backend for microphone example is broken 0. Add some builtin channel layouts from https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/Audio_Channel_Layout_Tags diff --git a/src/coreaudio.cpp b/src/coreaudio.cpp index fa14cc5..824ab9d 100644 --- a/src/coreaudio.cpp +++ b/src/coreaudio.cpp @@ -839,8 +839,29 @@ static void device_thread_run(void *arg) { } } +static OSStatus on_device_overload(AudioObjectID in_object_id, UInt32 in_number_addresses, + const AudioObjectPropertyAddress in_addresses[], void *in_client_data) +{ + SoundIoOutStreamPrivate *os = (SoundIoOutStreamPrivate *)in_client_data; + SoundIoOutStream *outstream = &os->pub; + outstream->underflow_callback(outstream); + return noErr; +} + static void outstream_destroy_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { SoundIoOutStreamCoreAudio *osca = &os->backend_data.coreaudio; + SoundIoOutStream *outstream = &os->pub; + SoundIoDevice *device = outstream->device; + SoundIoDevicePrivate *dev = (SoundIoDevicePrivate *)device; + SoundIoDeviceCoreAudio *dca = &dev->backend_data.coreaudio; + + AudioObjectPropertyAddress prop_address = { + kAudioDeviceProcessorOverload, + kAudioObjectPropertyScopeGlobal, + kAudioObjectPropertyElementMaster + }; + AudioObjectRemovePropertyListener(dca->device_id, &prop_address, on_device_overload, os); + if (osca->output_instance) { AudioOutputUnitStop(osca->output_instance); AudioComponentInstanceDispose(osca->output_instance); @@ -928,6 +949,19 @@ static int outstream_open_ca(struct SoundIoPrivate *si, struct SoundIoOutStreamP return SoundIoErrorOpeningDevice; } + + AudioObjectPropertyAddress prop_address = { + kAudioDeviceProcessorOverload, + kAudioObjectPropertyScopeGlobal, + kAudioObjectPropertyElementMaster + }; + if ((os_err = AudioObjectAddPropertyListener(dca->device_id, &prop_address, + on_device_overload, os))) + { + outstream_destroy_ca(si, os); + return SoundIoErrorOpeningDevice; + } + return 0; }