Is it possible to use AudioKit to gather microphone input and simultaneously use MIKMIDI for playing notes from a MIDI file through the stereo speakers?
I have found that I can successfully do each on their own; I can gather microphone frequencies from AudioKit and play notes from a MIDI file with MIKMIDI, but if I use them together, then the MIDI notes are played on an 'internal hardware speaker' (not quite sure of the actual name? kind of like a DOS game), not the stereo speaker, and the notes are extremely low in amplitude.
AudioKit Usage
This is literally the only piece of code I use to obtain the microphone frequencies. There is other code that I use that frequency data for, but it is irrelevant. Point being, if I comment out this piece of code, the MIKMIDI portion works as expected and plays through the stereo speakers.
- (void)setupAudio
{
AKSettings.audioInputEnabled = true;
self.microphone = [[AKMicrophone alloc] init];
self.tracker = [[AKFrequencyTracker alloc] init:self.microphone hopSize:0 peakCount:0];
self.silence = [[AKBooster alloc] init:self.tracker gain:0];
[AudioKit setOutput:self.silence];
[AudioKit start];
}
MIKMIDI Usage
- (void)playMidi:(NSUInteger)note withDuration:(float)duration
{
if ( [DEFAULTS boolForKey:kPreferenceMIDIPlaybackEnabled] )
{
NSDate * startDate = [NSDate date];
NSDate * endDate = [startDate dateByAddingTimeInterval:duration];
MIKMIDINoteOnCommand * noteOn = [MIKMIDINoteOnCommand noteOnCommandWithNote:note velocity:127 channel:0 timestamp:startDate];
MIKMIDINoteOffCommand * noteOff = [MIKMIDINoteOffCommand noteOffCommandWithNote:note velocity:0 channel:0 timestamp:endDate];
[self.synthesizer handleMIDIMessages:@[noteOn, noteOff]];
}
}