简体   繁体   English

如何在OSX上的C ++应用程序中播放合成声音?

[英]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. 声音的持续时间很灵活,因此MIDI似乎是最好的解决方案。

I am using Open Framework for now. 我现在正在使用Open Framework。 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. 我已经在Mac上找到了AUi工具,但是我不知道如何从代码中访问它们。 I didn't find any way to play General Midi (built in MIDI instrument). 我没有找到玩通用Midi(内置MIDI乐器)的任何方法。 No out port found with RTMidi. RTMidi未找到输出端口。

Does anyone have a solution? 有没有人有办法解决吗? Thank you! 谢谢!

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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