OGeek|极客世界-中国程序员成长平台

标题: c++ - 使用 MoMu STK 进行音频合成 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 18:07
标题: c++ - 使用 MoMu STK 进行音频合成

有人在 iOS 上使用 MoMu STK 成功实现了 Instrument 吗?我对 Instrument 的流的初始化有点困惑。 我正在使用教程代码,看起来缺少一些东西

RtAudio DAC;

       //计算 StkFloat 中有多少字节并设置 RtAudio 流。
        RtAudio::StreamParameters 参数;
        参数.deviceId = dac.getDefaultOutputDevice();
        参数.nChannels = 1;
        RtAudioFormat 格式 = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64:RTAUDIO_FLOAT32;
        无符号整数 bufferFrames = RT_BUFFER_SIZE;

        dac.openStream( & 参数, NULL, 格式, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&data );

错误描述说输出设备的输出参数无效,但是当我跳过分配设备ID时,它就不能正常工作。 任何想法都会很棒。



Best Answer-推荐答案


RtAudio 仅适用于桌面应用,在 iOS 上实现时无需打开流。

示例:

头文件:

#import "Simple.h"

// make struct to hold 

struct TickData {

    Simple *synth;    

};

// Make instance of the struct in @interface= 
TickData data;

实现文件:

// init the synth:
data.synth = new Simple();
data.synth->keyOff();

// to trigger note on/off:
data.synth->noteOn(frequency, velocity);
data.synth->noteOff(velocity);

// audio callback method:
for (int i=0; i < FRAMESIZE; i++) {
    buffer[i] = data.synth -> tick();
}

关于c++ - 使用 MoMu STK 进行音频合成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8076694/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4