I have an AUGraph with AudioUnits. My MIDI Synth AudioUnit was created by this:
AudioComponentDescription midiSynthDesc;
midiSynthDesc.componentType = kAudioUnitType_MusicDevice;
midiSynthDesc.componentSubType = kAudioUnitSubType_MIDISynth;
Then I load the SF2 File into the MIDI AudioUnit:
NSURL *bankURL = [[NSBundle mainBundle] URLForResource:@"Combined" withExtension:@"sf2"];
AudioUnitSetProperty(midiSynthUnit,
kMusicDeviceProperty_SoundBankURL,
kAudioUnitScope_Global,
0,
&bankURL,
sizeof(bankURL));
I have this SF2 loaded MIDI-Synth AudioUnit connected to Remote-IO AudioUnit, then I added MusicPlayer to this AUGraph to play:
MusicPlayerSetSequence(musicPlayer, musicSequence);
NewMusicSequence(&musicSequence);
MusicSequenceFileLoad(musicSequence, (__bridge CFURLRef)midiFileURL, 0, 0)
MusicSequenceSetAUGraph(musicSequence, processingGraph);
MusicPlayerPreroll(musicPlayer);
MusicPlayerStart(musicPlayer);
And it works with the Remote-IO, I can hear the MIDI file playing.
However, if I pull the MIDI Synth Audio Unit programmatically, trying to render the MIDI File into Raw Audio Data and then write into m4a file:
OSStatus err = noErr;
err = AudioUnitRender(midiSynthUnit, &flags, &inTimeStamp, busNumber, numberFrames, bufferList);
No audio data can be read ( bufferList's mData == 0 Always). No matter how many times I call AudioUnitRender, MusicPlayerGetTime always tells me that the current beat of the Music Player is 0:
Float64 currentBeat;
MusicPlayerGetTime(musicPlayer, ¤tBeat);
Can anybody tell me why? Any suggestion how to read the MIDI File with SF2 soundfont file and convert into raw audio data / render MIDI into m4a file?
Thanks