Search code examples
c++macosmidiaudiounitvst

How can I play a synth sound in a C++ app on OSX?


I want to play instrumental sounds in my app. The duration of the sounds is flexible so MIDI seems the best solution.

I am using Open Framework for now. Using Audio Units, I managed to process an input sound, not to play through an instrument. I have found AUi instruments on my Mac but I don't know how to access them from my code. I didn't find any way to play General Midi (built in MIDI instrument). No out port found with RTMidi.

Does anyone have a solution? Thank you!


Solution

  • I found the solution in this project.

    You need to use Audio Units. Add a node with this component description:

    description.componentType           = kAudioUnitType_MusicDevice;
    description.componentSubType        = kAudioUnitSubType_DLSSynth;
    description.componentManufacturer   = kAudioUnitManufacturer_Apple;
    description.componentFlags          = 0;
    description.componentFlagsMask      = 0;
    AUGraphAddNode (graph, &description, &synthNode);
    

    Open and initialize your audio units and play the notes like that:

    MusicDeviceMIDIEvent (synthUnit, channel, note, velocity, 0);