2

我在 OS X 上使用带有 Audio Graph 的 Superpowered Reverb 效果。我通过调用reverb->process输出音频单元的渲染回调来做到这一点(在kAudioUnitSubType_SystemOutput和上测试kAudioUnitSubType_DefaultOutput)。

混响效果有效,但产生的音频非常嘈杂。我尝试了不同的方法(调整采样率、使用额外和归零的缓冲区等),但似乎没有帮助。有没有办法解决这个问题?谢谢。

简化代码:

SuperpoweredReverb* reverb;

OSStatus callback(void * inComponentStorage,
                  AudioUnitRenderActionFlags * __nullable flags,
                  const AudioTimeStamp * inTimeStamp,
                  UInt32 busNumber,
                  UInt32 framesCount,
                  AudioBufferList * ioData)
{
    for (int i = 0; i < ioData->mNumberBuffers; ++i)
    {
        if (ioData->mBuffers[i].mData)
            reverb->process(static_cast<float*>(ioData->mBuffers[i].mData),
                            static_cast<float*>(ioData->mBuffers[i].mData),
                            framesCount);
    }

    return noErr;
}

void setupReverb(unsigned int sampleRate, AudioUnit unit)
{
    reverb = new SuperpoweredReverb(sampleRate);
    reverb->enable(true);
    reverb->setMix(0.5);
    AudioUnitAddRenderNotify(unit, callback, nullptr);
}
4

1 回答 1

1

事实证明,在音频图中,即使在同一个频道上,回调也会多次调用,我做了以下更改(使用整数来跟踪当前频道),现在它工作得非常好。(下面再次简化代码)

SuperpoweredReverb* reverbUnit;
int spliter = 0;

OSStatus callback(void * inComponentStorage,
                  AudioUnitRenderActionFlags * __nullable flags,
                  const AudioTimeStamp * inTimeStamp,
                  UInt32 busNumber,
                  UInt32 framesCount,
                  AudioBufferList * ioData)
{
    spliter++;
    for (int i = 0; i < ioData->mNumberBuffers; ++i)
    {
        if (ioData->mBuffers[i].mData) {
            if (!(spliter % ioData->mBuffers[i].mNumberChannels))
                reverbUnit->process(static_cast<float*>(ioData->mBuffers[i].mData),
                                    static_cast<float*>(ioData->mBuffers[i].mData),
                                    framesCount);
        }
    }

    return noErr;
}

void setupReverb(unsigned int sampleRate, AudioUnit unit)
{
    reverbUnit = new SuperpoweredReverb(sampleRate);
    reverbUnit->enable(true);
    reverbUnit->setWet(0.7);
    AudioUnitAddRenderNotify(unit, callback, nullptr);
}
于 2017-07-20T05:18:07.373 回答