Home / IOS Development / ios – Core Audio: How do I play MIDI MusicSequence by MusicPlayer while AUGraph is phased out?

ios – Core Audio: How do I play MIDI MusicSequence by MusicPlayer while AUGraph is phased out?



I have a MIDI Synth Unit

 AudioComponentDescription midiSynthDesc;
  midiSynthDesc.componentType = kAudioUnitType_MusicDevice;
  midiSynthDesc.componentSubType = kAudioUnitSubType_MIDISynth;
  midiSynthDesc.componentManufacturer = kAudioUnitManufacturer_Apple;
  midiSynthDesc.componentFlags = 0;
  midiSynthDesc.componentFlagsMask = 0;

which used to be in an AUGraph. But since AUGraph is phased out, I used AudioComponentInstanceNew to create it without using AUNode and AUGraph

AudioComponent foundMIDISynthReference = AudioComponentFindNext ( NULL, &midiSynthDesc);
  AudioComponentInstanceNew(foundMIDISynthReference, &midiSynthUnit);

I used it to play Sequence by linking Sequence to AUGraph

NSString *presetURLPath = [[NSBundle mainBundle] pathForResource:@"GortsMiniPianoJ1" ofType:@"SF2"];
NSURL * presetURL = [NSURL fileURLWithPath:presetURLPath]; 
[self loadFromDLSOrSoundFont: (NSURL *)presetURL withPatch: (int)3];

NSString *midiFilePath = [[NSBundle mainBundle] pathForResource:name ofType:@"mid"];
NSURL * midiFileURL = [NSURL fileURLWithPath:midiFilePath];

NewMusicPlayer(&musicPlayer);
MusicPlayerSetSequence(musicPlayer, musicSequence);
MusicSequenceSetAUGraph(musicSequence, _processingGraph);
MusicPlayerPreroll(musicPlayer);
MusicPlayerStart(musicPlayer);

But now that AUGraph has been phased out, just using AudioUnit, how can I use Play MIDI Files in Core Audio?


Source link