AudioKit microphone input + MIDI output

Can AudioKit be used to collect microphone input and at the same time use MIKMIDI to play notes from a MIDI file through stereo speakers?

I have found that I can successfully do each one by myself; I can collect mic frequencies from AudioKit and play recordings 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? DOS), not a stereo speaker, but notes are very low in amplitude.

Using AudioKit

This is literally the only piece of code I am using to get microphone frequencies. There is other code for which I am using frequency data, but it doesn't matter. The point is, if I comment on this piece of code, the MIKMIDI part works as expected and plays 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];
}

      

Using MIKMIDI

- (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]];
    }
}

      

+3


source to share





All Articles