@@ -47,6 +47,9 @@ typedef struct coreaudioVoiceOut {
pthread_mutex_t mutex;
int isAtexit;
AudioDeviceID outputDeviceID;
+#if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED>=MAC_OS_X_VERSION_10_5)
+ AudioDeviceIOProcID ioProcID;
+#endif
UInt32 audioDevicePropertyBufferFrameSize;
AudioStreamBasicDescription outputStreamBasicDescription;
int live;
@@ -56,7 +59,7 @@ typedef struct coreaudioVoiceOut {
static void coreaudio_logstatus (OSStatus status)
{
- char *str = "BUG";
+ const char *str = "BUG";
switch(status) {
case kAudioHardwareNoError:
@@ -104,7 +107,7 @@ static void coreaudio_logstatus (OSStatus status)
break;
default:
- AUD_log (AUDIO_CAP, "Reason: status code %ld\n", status);
+ AUD_log (AUDIO_CAP, "Reason: status code %d\n", status);
return;
}
@@ -148,10 +151,21 @@ static inline UInt32 isPlaying (AudioDeviceID outputDeviceID)
{
OSStatus status;
UInt32 result = 0;
+#if MAC_OS_X_VERSION_MIN_REQUIRED>MAC_OS_X_VERSION_10_5
+ AudioObjectPropertyAddress propertyAddress = {
+ .mSelector = kAudioDevicePropertyDeviceIsRunning,
+ .mScope = kAudioObjectPropertyScopeGlobal,
+ .mElement = kAudioObjectPropertyElementMaster,
+ };
+ UInt32 resultSize = sizeof(result);
+ status = AudioObjectGetPropertyData(outputDeviceID, &propertyAddress,
+ 0, NULL, &resultSize, &result);
+#else
UInt32 propertySize = sizeof(outputDeviceID);
status = AudioDeviceGetProperty(
outputDeviceID, 0, 0,
kAudioDevicePropertyDeviceIsRunning, &propertySize, &result);
+#endif
if (status != kAudioHardwareNoError) {
coreaudio_logerr(status,
"Could not determine whether Device is playing\n");
@@ -307,10 +321,21 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
/* open default output device */
propertySize = sizeof(core->outputDeviceID);
+#if MAC_OS_X_VERSION_MIN_REQUIRED>MAC_OS_X_VERSION_10_5
+ AudioObjectPropertyAddress propertyAddress = {
+ .mSelector = kAudioHardwarePropertyDefaultOutputDevice,
+ .mScope = kAudioObjectPropertyScopeGlobal,
+ .mElement = kAudioObjectPropertyElementMaster,
+ };
+ status = AudioObjectGetPropertyData(kAudioObjectSystemObject,
+ &propertyAddress, 0, NULL,
+ &propertySize, &core->outputDeviceID);
+#else
status = AudioHardwareGetProperty(
kAudioHardwarePropertyDefaultOutputDevice,
&propertySize,
&core->outputDeviceID);
+#endif
if (status != kAudioHardwareNoError) {
coreaudio_logerr2 (status, typ,
"Could not get default output Device\n");
@@ -323,6 +348,11 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
/* get minimum and maximum buffer frame sizes */
propertySize = sizeof(frameRange);
+#if MAC_OS_X_VERSION_MIN_REQUIRED>MAC_OS_X_VERSION_10_5
+ propertyAddress.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
+ status = AudioObjectGetPropertyData(core->outputDeviceID, &propertyAddress,
+ 0, NULL, &propertySize, &frameRange);
+#else
status = AudioDeviceGetProperty(
core->outputDeviceID,
0,
@@ -330,6 +360,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
kAudioDevicePropertyBufferFrameSizeRange,
&propertySize,
&frameRange);
+#endif
if (status != kAudioHardwareNoError) {
coreaudio_logerr2 (status, typ,
"Could not get device buffer frame range\n");
@@ -350,6 +381,12 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
/* set Buffer Frame Size */
propertySize = sizeof(core->audioDevicePropertyBufferFrameSize);
+#if MAC_OS_X_VERSION_MIN_REQUIRED>MAC_OS_X_VERSION_10_5
+ propertyAddress.mSelector = kAudioDevicePropertyBufferFrameSize;
+ status = AudioObjectSetPropertyData(core->outputDeviceID, &propertyAddress,
+ 0, NULL, propertySize,
+ &core->audioDevicePropertyBufferFrameSize);
+#else
status = AudioDeviceSetProperty(
core->outputDeviceID,
NULL,
@@ -358,15 +395,22 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
kAudioDevicePropertyBufferFrameSize,
propertySize,
&core->audioDevicePropertyBufferFrameSize);
+#endif
if (status != kAudioHardwareNoError) {
coreaudio_logerr2 (status, typ,
- "Could not set device buffer frame size %ld\n",
+ "Could not set device buffer frame size %d\n",
core->audioDevicePropertyBufferFrameSize);
return -1;
}
/* get Buffer Frame Size */
propertySize = sizeof(core->audioDevicePropertyBufferFrameSize);
+#if MAC_OS_X_VERSION_MIN_REQUIRED>MAC_OS_X_VERSION_10_5
+ propertyAddress.mSelector = kAudioDevicePropertyBufferFrameSize;
+ status = AudioObjectGetPropertyData(core->outputDeviceID, &propertyAddress,
+ 0, NULL, &propertySize,
+ &core->audioDevicePropertyBufferFrameSize);
+#else
status = AudioDeviceGetProperty(
core->outputDeviceID,
0,
@@ -374,6 +418,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
kAudioDevicePropertyBufferFrameSize,
&propertySize,
&core->audioDevicePropertyBufferFrameSize);
+#endif
if (status != kAudioHardwareNoError) {
coreaudio_logerr2 (status, typ,
"Could not get device buffer frame size\n");
@@ -383,6 +428,12 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
/* get StreamFormat */
propertySize = sizeof(core->outputStreamBasicDescription);
+#if MAC_OS_X_VERSION_MIN_REQUIRED>MAC_OS_X_VERSION_10_5
+ propertyAddress.mSelector = kAudioDevicePropertyStreamFormat;
+ status = AudioObjectGetPropertyData(core->outputDeviceID, &propertyAddress,
+ 0, NULL, &propertySize,
+ &core->outputStreamBasicDescription);
+#else
status = AudioDeviceGetProperty(
core->outputDeviceID,
0,
@@ -390,6 +441,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
kAudioDevicePropertyStreamFormat,
&propertySize,
&core->outputStreamBasicDescription);
+#endif
if (status != kAudioHardwareNoError) {
coreaudio_logerr2 (status, typ,
"Could not get Device Stream properties\n");
@@ -400,6 +452,12 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
/* set Samplerate */
core->outputStreamBasicDescription.mSampleRate = (Float64) as->freq;
propertySize = sizeof(core->outputStreamBasicDescription);
+#if MAC_OS_X_VERSION_MIN_REQUIRED>MAC_OS_X_VERSION_10_5
+ propertyAddress.mSelector = kAudioDevicePropertyStreamFormat;
+ status = AudioObjectSetPropertyData(core->outputDeviceID, &propertyAddress,
+ 0, NULL, propertySize,
+ &core->outputStreamBasicDescription);
+#else
status = AudioDeviceSetProperty(
core->outputDeviceID,
0,
@@ -408,6 +466,7 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
kAudioDevicePropertyStreamFormat,
propertySize,
&core->outputStreamBasicDescription);
+#endif
if (status != kAudioHardwareNoError) {
coreaudio_logerr2 (status, typ, "Could not set samplerate %d\n",
as->freq);
@@ -416,7 +475,14 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
}
/* set Callback */
+#if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED>=MAC_OS_X_VERSION_10_5)
+ status = AudioDeviceCreateIOProcID(core->outputDeviceID,
+ audioDeviceIOProc,
+ hw,
+ &core->ioProcID);
+#else
status = AudioDeviceAddIOProc(core->outputDeviceID, audioDeviceIOProc, hw);
+#endif
if (status != kAudioHardwareNoError) {
coreaudio_logerr2 (status, typ, "Could not set IOProc\n");
core->outputDeviceID = kAudioDeviceUnknown;
@@ -428,7 +494,11 @@ static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc);
if (status != kAudioHardwareNoError) {
coreaudio_logerr2 (status, typ, "Could not start playback\n");
+#if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED>=MAC_OS_X_VERSION_10_5)
+ AudioDeviceDestroyIOProcID(core->outputDeviceID, core->ioProcID);
+#else
AudioDeviceRemoveIOProc(core->outputDeviceID, audioDeviceIOProc);
+#endif
core->outputDeviceID = kAudioDeviceUnknown;
return -1;
}
@@ -453,8 +523,13 @@ static void coreaudio_fini_out (HWVoiceOut *hw)
}
/* remove callback */
+#if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED>=MAC_OS_X_VERSION_10_5)
+ status = AudioDeviceDestroyIOProcID(core->outputDeviceID,
+ core->ioProcID);
+#else
status = AudioDeviceRemoveIOProc(core->outputDeviceID,
audioDeviceIOProc);
+#endif
if (status != kAudioHardwareNoError) {
coreaudio_logerr (status, "Could not remove IOProc\n");
}