AUMIDISynth - Anybody know how to load instruments into it?

In iOS 8 a new audio unit, called AUMIDISynth, has appeared in the core audo headers. The following comments in AudioUnitProperties suggest it's a multi-timbral GM synth for iOS, which would be a rather nice thing to have, particularly if it supports tuning messages:


Line 3072:

@abstract Audio unit property IDs used by AUMIDISynth (iOS) and DLSMusicDevice (OSX)


Line 3081:

For a multi-timbral music instrument, this property can return the number of independent patches that

are available to be chosen as an active patch for the instrument. For instance, for Apple's DLS Music Device

and AUMIDISynth, this value returns the number of patches that are found in a given DLS or SoundFont file when loaded.


Line 3109:

@discussion The AUMIDISynth audio unit lets a client create fully GM-compatible Midi Synth.

However, there appears to be no documentation, and the only mention of this unit I've found on the web is from other people who've noticed it in the headers. In particular, I can't see any way to load instruments into it.


The comments suggest it might be similar to the OS X DLSMusicDevice, which gets its instruments from a particular filesystem location (/Library/Audio/Sounds/Banks). Perhaps, there is similarly a location in the bundle where you can put sound banks for use by AUMIDISynth?


To use the MIDISynth AU, you need to include a SoundFont 2 (.sf2) or Downloadable Sounds (.dls) bank file with your app.

When you first set up your AU, pass it the URL for the bank file using the kMusicDeviceProperty_SoundBankURL property. This is different that what the Sampler AU does with samples -- here, you are passing it the specific path using [NSBundle bundleForClass: pathForResource:].


The MIDISynth loads instrument presets out of the bank you specify in response to program change messages in your MIDI file. If you use the MIDISynth in conjunction with the MusicPlayer/Sequence API, it will take care of the extra step you will need to pre-load all the instruments during the preroll stage, before you start playing.


If you goal is straightforward MIDI file playback, I *strongly* recommend the new AVMIDIPlayer which is part of the AVFoundation audio API. This lets you get away from the older C-based APIs completely.


The other possibility, if you need more flexibility, is the new iOS 9 AVAudioSequencer plus the AVAudioEngine. You can create an Instrument Node for the Engine which contains an AUMIDISynth instance. Check out the 2015 WWDC talk which touches on this.


-DS

Here's a basic example of the mentioned kMusicDeviceProperty_SoundBankURL property in use from the "PlaySequence" sample:


CFURLRef soundBankURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)soundBankPath, strlen(soundBankPath), false);
               
printf ("Setting Sound Bank:%s\n", soundBankPath);
   
OSStatus result = AudioUnitSetProperty(theMIDISynth,
                                       kMusicDeviceProperty_SoundBankURL,
                                       kAudioUnitScope_Global, 0,
                                       &soundBankURL, sizeof(soundBankURL));

if (soundBankURL) CFRelease(soundBankURL);
if (result) printf("AudioUnitSetProperty failed %d\n", result);

Bump! Has anyone got this working? I can load the piano patch from my SF2, but any program change messages mute playback entirely. I've tried everything!

Yes. Try this article which also has a working Github project.

AUMIDISynth - Anybody know how to load instruments into it?
 
 
Q