aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorMatthew Hoops2013-02-01 14:13:24 -0500
committerMatthew Hoops2013-02-01 14:15:10 -0500
commit412ac740aa04428251a94073357f5458ed217f3f (patch)
treecfc6d1286366e3578cca57b4d1e4cbeb4d16eb78 /backends
parentcef07f30d8fda37b5f03e7488f09aa0795dc57e1 (diff)
downloadscummvm-rg350-412ac740aa04428251a94073357f5458ed217f3f.tar.gz
scummvm-rg350-412ac740aa04428251a94073357f5458ed217f3f.tar.bz2
scummvm-rg350-412ac740aa04428251a94073357f5458ed217f3f.zip
MACOSX: Load soundfonts using FSRef instead of FSSpec on 10.5
Fixes bug #3602452
Diffstat (limited to 'backends')
-rw-r--r--backends/midi/coreaudio.cpp111
1 files changed, 65 insertions, 46 deletions
diff --git a/backends/midi/coreaudio.cpp b/backends/midi/coreaudio.cpp
index 94262d0d92..317268ae87 100644
--- a/backends/midi/coreaudio.cpp
+++ b/backends/midi/coreaudio.cpp
@@ -102,6 +102,7 @@ public:
void sysEx(const byte *msg, uint16 length);
private:
+ void loadSoundFont(const char *soundfont);
AUGraph _auGraph;
AudioUnit _synth;
};
@@ -171,52 +172,8 @@ int MidiDriver_CORE::open() {
#endif
// Load custom soundfont, if specified
- if (ConfMan.hasKey("soundfont")) {
- const char *soundfont = ConfMan.get("soundfont").c_str();
-
- // TODO: We should really check whether the file contains an
- // actual soundfont...
-
-#if USE_DEPRECATED_COREAUDIO_API
- // Before 10.5, we need to use kMusicDeviceProperty_SoundBankFSSpec
- FSRef fsref;
- FSSpec fsSpec;
- err = FSPathMakeRef ((const byte *)soundfont, &fsref, NULL);
-
- if (err == noErr) {
- err = FSGetCatalogInfo (&fsref, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL);
- }
-
- if (err == noErr) {
- err = AudioUnitSetProperty (
- _synth,
- kMusicDeviceProperty_SoundBankFSSpec, kAudioUnitScope_Global,
- 0,
- &fsSpec, sizeof(fsSpec)
- );
- }
-#else
- // kMusicDeviceProperty_SoundBankFSSpec is present on 10.6+, but broken
- // kMusicDeviceProperty_SoundBankURL was added in 10.5 as a replacement
- CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)soundfont, strlen(soundfont), false);
-
- if (url) {
- err = AudioUnitSetProperty (
- _synth,
- kMusicDeviceProperty_SoundBankURL, kAudioUnitScope_Global,
- 0,
- &url, sizeof(url)
- );
-
- CFRelease(url);
- } else {
- warning("Failed to allocate CFURLRef from '%s'", soundfont);
- }
-#endif
-
- if (err != noErr)
- error("Failed loading custom sound font '%s' (error %ld)", soundfont, (long)err);
- }
+ if (ConfMan.hasKey("soundfont"))
+ loadSoundFont(ConfMan.get("soundfont").c_str());
#ifdef COREAUDIO_DISABLE_REVERB
// Disable reverb mode, as that sucks up a lot of CPU power, which can
@@ -242,6 +199,68 @@ bail:
return MERR_CANNOT_CONNECT;
}
+void MidiDriver_CORE::loadSoundFont(const char *soundfont) {
+ // TODO: We should really check whether the file contains an
+ // actual soundfont...
+
+ OSStatus err = 0;
+
+#if USE_DEPRECATED_COREAUDIO_API
+ FSRef fsref;
+ err = FSPathMakeRef((const byte *)soundfont, &fsref, NULL);
+
+#ifdef MAC_OS_X_VERSION_10_5
+ // Use kMusicDeviceProperty_SoundBankFSRef if we know it's available
+ // (This became available in 10.3, but the 10.2 SDK has 10.3/10.4 defines)
+
+ if (err == noErr) {
+ err = AudioUnitSetProperty(
+ _synth,
+ kMusicDeviceProperty_SoundBankFSRef, kAudioUnitScope_Global,
+ 0,
+ &fsref, sizeof(fsref)
+ );
+ }
+#else
+ // Otherwise, we know kMusicDeviceProperty_SoundBankFSSpec is available
+ FSSpec fsSpec;
+
+ if (err == noErr)
+ err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL);
+
+ if (err == noErr) {
+ err = AudioUnitSetProperty(
+ _synth,
+ kMusicDeviceProperty_SoundBankFSSpec, kAudioUnitScope_Global,
+ 0,
+ &fsSpec, sizeof(fsSpec)
+ );
+ }
+#endif // MAC_OS_X_VERSION_10_5
+
+#else
+ // kMusicDeviceProperty_SoundBankURL was added in 10.5 as a replacement
+ // In addition, the File Manager API became deprecated starting in 10.8
+ CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)soundfont, strlen(soundfont), false);
+
+ if (url) {
+ err = AudioUnitSetProperty(
+ _synth,
+ kMusicDeviceProperty_SoundBankURL, kAudioUnitScope_Global,
+ 0,
+ &url, sizeof(url)
+ );
+
+ CFRelease(url);
+ } else {
+ warning("Failed to allocate CFURLRef from '%s'", soundfont);
+ }
+#endif // USE_DEPRECATED_COREAUDIO_API
+
+ if (err != noErr)
+ error("Failed loading custom sound font '%s' (error %ld)", soundfont, (long)err);
+}
+
void MidiDriver_CORE::close() {
MidiDriver_MPU401::close();
if (_auGraph) {