summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2018-04-10 23:09:57 +0200
committerMichael Lutz <michi@icosahedron.de>2018-04-10 23:30:01 +0200
commit27bfb1df8ffc9f40f1ce43ed1a6de4fc27a3d29e (patch)
treec5a9c5ddb89e352589b114de942b412003b4fa3c
parent4bfd2770179989d5ade3d018004dc15fa5b102bf (diff)
downloadopenttd-27bfb1df8ffc9f40f1ce43ed1a6de4fc27a3d29e.tar.xz
Codechange: [OSX] Use 10.6+ APIs to initialise audio when available.
-rw-r--r--src/sound/cocoa_s.cpp79
1 files changed, 59 insertions, 20 deletions
diff --git a/src/sound/cocoa_s.cpp b/src/sound/cocoa_s.cpp
index 8cf4a632b..8133bf62f 100644
--- a/src/sound/cocoa_s.cpp
+++ b/src/sound/cocoa_s.cpp
@@ -18,6 +18,7 @@
#ifdef WITH_COCOA
#include "../stdafx.h"
+#include "../os/macosx/macos.h"
#include "../debug.h"
#include "../driver.h"
#include "../mixer.h"
@@ -47,8 +48,6 @@ static OSStatus audioCallback(void *inRefCon, AudioUnitRenderActionFlags *inActi
const char *SoundDriver_Cocoa::Start(const char * const *parm)
{
- Component comp;
- ComponentDescription desc;
struct AURenderCallbackStruct callback;
AudioStreamBasicDescription requestedDesc;
@@ -71,21 +70,49 @@ const char *SoundDriver_Cocoa::Start(const char * const *parm)
MxInitialize((uint)requestedDesc.mSampleRate);
- /* Locate the default output audio unit */
- desc.componentType = kAudioUnitType_Output;
- desc.componentSubType = kAudioUnitSubType_HALOutput;
- desc.componentManufacturer = kAudioUnitManufacturer_Apple;
- desc.componentFlags = 0;
- desc.componentFlagsMask = 0;
-
- comp = FindNextComponent (NULL, &desc);
- if (comp == NULL) {
- return "cocoa_s: Failed to start CoreAudio: FindNextComponent returned NULL";
- }
-
- /* Open & initialize the default output audio unit */
- if (OpenAComponent(comp, &_outputAudioUnit) != noErr) {
- return "cocoa_s: Failed to start CoreAudio: OpenAComponent";
+#if defined(__AUDIOCOMPONENT_H__) || defined(HAVE_OSX_107_SDK)
+ if (MacOSVersionIsAtLeast(10, 6, 0)) {
+ /* Locate the default output audio unit */
+ AudioComponentDescription desc;
+ desc.componentType = kAudioUnitType_Output;
+ desc.componentSubType = kAudioUnitSubType_HALOutput;
+ desc.componentManufacturer = kAudioUnitManufacturer_Apple;
+ desc.componentFlags = 0;
+ desc.componentFlagsMask = 0;
+
+ AudioComponent comp = AudioComponentFindNext (NULL, &desc);
+ if (comp == NULL) {
+ return "cocoa_s: Failed to start CoreAudio: AudioComponentFindNext returned NULL";
+ }
+
+ /* Open & initialize the default output audio unit */
+ if (AudioComponentInstanceNew(comp, &_outputAudioUnit) != noErr) {
+ return "cocoa_s: Failed to start CoreAudio: AudioComponentInstanceNew";
+ }
+ } else
+#endif
+ {
+#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
+ /* Locate the default output audio unit */
+ ComponentDescription desc;
+ desc.componentType = kAudioUnitType_Output;
+ desc.componentSubType = kAudioUnitSubType_HALOutput;
+ desc.componentManufacturer = kAudioUnitManufacturer_Apple;
+ desc.componentFlags = 0;
+ desc.componentFlagsMask = 0;
+
+ Component comp = FindNextComponent (NULL, &desc);
+ if (comp == NULL) {
+ return "cocoa_s: Failed to start CoreAudio: FindNextComponent returned NULL";
+ }
+
+ /* Open & initialize the default output audio unit */
+ if (OpenAComponent(comp, &_outputAudioUnit) != noErr) {
+ return "cocoa_s: Failed to start CoreAudio: OpenAComponent";
+ }
+#else
+ return "cocoa_s: Not supported on this OS X version";
+#endif
}
if (AudioUnitInitialize(_outputAudioUnit) != noErr) {
@@ -132,9 +159,21 @@ void SoundDriver_Cocoa::Stop()
return;
}
- if (CloseComponent(_outputAudioUnit) != noErr) {
- DEBUG(driver, 0, "cocoa_s: Core_CloseAudio: CloseComponent failed");
- return;
+#if defined(__AUDIOCOMPONENT_H__) || defined(HAVE_OSX_107_SDK)
+ if (MacOSVersionIsAtLeast(10, 6, 0)) {
+ if (AudioComponentInstanceDispose(_outputAudioUnit) != noErr) {
+ DEBUG(driver, 0, "cocoa_s: Core_CloseAudio: AudioComponentInstanceDispose failed");
+ return;
+ }
+ } else
+#endif
+ {
+#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
+ if (CloseComponent(_outputAudioUnit) != noErr) {
+ DEBUG(driver, 0, "cocoa_s: Core_CloseAudio: CloseComponent failed");
+ return;
+ }
+#endif
}
}