Replace deprecated Carbon API calls with modern AudioComponent APIs in the CoreAudio backend.

This prevents a deprecation notice from being output to stdout when alcOpenDevice is called in Mac OS X 10.11.

The new API calls require Mac OS X 10.6 or newer.
This commit is contained in:
Alex Szpakowski 2015-11-13 20:11:12 -04:00
parent f903a7aa64
commit 21c84bcd96

View File

@ -137,8 +137,8 @@ static OSStatus ca_capture_callback(void *inRefCon, AudioUnitRenderActionFlags *
static ALCenum ca_open_playback(ALCdevice *device, const ALCchar *deviceName)
{
ComponentDescription desc;
Component comp;
AudioComponentDescription desc;
AudioComponent comp;
ca_data *data;
OSStatus err;
@ -154,19 +154,19 @@ static ALCenum ca_open_playback(ALCdevice *device, const ALCchar *deviceName)
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
comp = FindNextComponent(NULL, &desc);
comp = AudioComponentFindNext(NULL, &desc);
if(comp == NULL)
{
ERR("FindNextComponent failed\n");
ERR("AudioComponentFindNext failed\n");
return ALC_INVALID_VALUE;
}
data = calloc(1, sizeof(*data));
err = OpenAComponent(comp, &data->audioUnit);
err = AudioComponentInstanceNew(comp, &data->audioUnit);
if(err != noErr)
{
ERR("OpenAComponent failed\n");
ERR("AudioComponentInstanceNew failed\n");
free(data);
return ALC_INVALID_VALUE;
}
@ -176,7 +176,7 @@ static ALCenum ca_open_playback(ALCdevice *device, const ALCchar *deviceName)
if(err != noErr)
{
ERR("AudioUnitInitialize failed\n");
CloseComponent(data->audioUnit);
AudioComponentInstanceDispose(data->audioUnit);
free(data);
return ALC_INVALID_VALUE;
}
@ -191,7 +191,7 @@ static void ca_close_playback(ALCdevice *device)
ca_data *data = (ca_data*)device->ExtraData;
AudioUnitUninitialize(data->audioUnit);
CloseComponent(data->audioUnit);
AudioComponentInstanceDispose(data->audioUnit);
free(data);
device->ExtraData = NULL;
@ -374,12 +374,13 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
AudioStreamBasicDescription hardwareFormat; // The hardware format
AudioStreamBasicDescription outputFormat; // The AudioUnit output format
AURenderCallbackStruct input;
ComponentDescription desc;
AudioComponentDescription desc;
AudioDeviceID inputDevice;
UInt32 outputFrameCount;
UInt32 propertySize;
AudioObjectPropertyAddress propertyAddress;
UInt32 enableIO;
Component comp;
AudioComponent comp;
ca_data *data;
OSStatus err;
@ -395,10 +396,10 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
desc.componentFlagsMask = 0;
// Search for component with given description
comp = FindNextComponent(NULL, &desc);
comp = AudioComponentFindNext(NULL, &desc);
if(comp == NULL)
{
ERR("FindNextComponent failed\n");
ERR("AudioComponentFindNext failed\n");
return ALC_INVALID_VALUE;
}
@ -406,10 +407,10 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
device->ExtraData = data;
// Open the component
err = OpenAComponent(comp, &data->audioUnit);
err = AudioComponentInstanceNew(comp, &data->audioUnit);
if(err != noErr)
{
ERR("OpenAComponent failed\n");
ERR("AudioComponentInstanceNew failed\n");
goto error;
}
@ -432,11 +433,16 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
}
// Get the default input device
propertySize = sizeof(AudioDeviceID);
err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &propertySize, &inputDevice);
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = kAudioObjectPropertyElementMaster;
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &propertySize, &inputDevice);
if(err != noErr)
{
ERR("AudioHardwareGetProperty failed\n");
ERR("AudioObjectGetPropertyData failed\n");
goto error;
}
@ -596,7 +602,7 @@ error:
if(data->audioConverter)
AudioConverterDispose(data->audioConverter);
if(data->audioUnit)
CloseComponent(data->audioUnit);
AudioComponentInstanceDispose(data->audioUnit);
free(data);
device->ExtraData = NULL;
@ -613,7 +619,7 @@ static void ca_close_capture(ALCdevice *device)
destroy_buffer_list(data->bufferList);
AudioConverterDispose(data->audioConverter);
CloseComponent(data->audioUnit);
AudioComponentInstanceDispose(data->audioUnit);
free(data);
device->ExtraData = NULL;