简体   繁体   中英

Play multiple midi notes simultaneously in iOS using Audio units

I need to play multiple tracks simultaneously in my app. The tracks may be normal audio files or a set of midi notes. So, I have configured an audio graph and connected various audio units (file player AUs and sampler AUs) to a multi channel mixer whose output is connected to remote io unit for playing audio files and midi notes. The sampler units are loaded with sf2 files of various instruments. All of this works fine but once I have more than two midi sampler Audio units and try to play midi notes simultaneously through those units using MusicDeviceMIDIEvent function, the output sound gets distorted/broken after a few loops. I need to simultaneously play about 10 instrument tracks and the problem starts right after I add a third midi unit. Can someone point me if there is a problem in this approach and if so, can you let me know how I can achieve this task of playing midi notes of various instruments simultaneously.

Playing multiple Midi notes on different tracks should not be a problem. I got it working fine. Make sure you stop the midi note being played before you play a new one. You can use the same function for stopping midi notes like below

UInt32 noteCommand =     kMIDIMessage_NoteOff << 4 | 0;
UInt32 velocity = 0;

MusicDeviceMIDIEvent (samplerUnit,                //audiounit
                                 noteCommand,    
                                 note,            //note being played
                                 velocity,
                                 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM