如何使用Superpowered库播放多种声音

时间:2018-05-22 16:09:23

标签: ios audio superpowered

我的目标是能够使用Superpowered API播放多种声音(为了制作Drum套件),因为我需要非常低的延迟。

我无法在.mm文件中找到整体架构。

现在,我的.mm文件中有:

  • 1 SuperpoweredIOSAudioIO *输出
  • 10 SuperpoweredAdvancedAudioPlayer *(玩家[10]),因为我有10个鼓

但是我找不到如何实现.mm文件的其余部分,特别是audioProcessing循环。

我目前有这个:

static bool audioProcessing(Superpowered *clientdata, float **buffers, unsigned int inputChannels, unsigned int outputChannels, unsigned int numberOfSamples, unsigned int samplerate, uint64_t hostTime) {
    Superpowered *self = clientdata;

    bool overallSilence = true;
    for(int i = 0; i < 10; i++) {
        SuperpoweredAdvancedAudioPlayer *player = self->players[i];
        bool silence = !player->process(self->stereoBuffer, false, numberOfSamples);
        if (silence == false) {
            overallSilence = false;
        }
    }

    if (!overallSilence) SuperpoweredDeInterleave(self->stereoBuffer, buffers[0], buffers[1], numberOfSamples); // The stereoBuffer is ready now, let's put the finished audio into the requested buffers.

    return !overallSilence;
}

当我想播放声音时:

- (void)playWithPlayerAtIndex:(int) index {
    SuperpoweredAdvancedAudioPlayer* player = players[index];
    player->seek(0);

    player->play(false);
}

但有了这个,我一次只能听到一个声音。

有人知道Superpowered API吗?

1 个答案:

答案 0 :(得分:0)

你所有的玩家都在&#34;玩&#34;进入&#34;自我&gt; stereoBuffer&#34;。检查播放器处理方法的bufferAdd参数。你需要&#34;添加&#34;输出到缓冲区的内容,如果至少有一个玩家输入了它。