这个 Vst 合成器示例的解释

Explanation of a this Vst Synth example

本文关键字:解释 Vst 合成器 这个      更新时间:2023-10-16

我在理解斯坦伯格VST合成器示例中的特定代码区域时遇到困难

在此函数中:


void VstXSynth::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames)
{
    float* out1 = outputs[0];
    float* out2 = outputs[1];

if (noteIsOn) { float baseFreq = freqtab[currentNote & 0x7f] * fScaler; float freq1 = baseFreq + fFreq1; // not really linear... float freq2 = baseFreq + fFreq2; float* wave1 = (fWaveform1 < .5) ? sawtooth : pulse; float* wave2 = (fWaveform2 < .5) ? sawtooth : pulse; float wsf = (float)kWaveSize; float vol = (float)(fVolume * (double)currentVelocity * midiScaler); VstInt32 mask = kWaveSize - 1;

    if (currentDelta > 0)
    {
        if (currentDelta >= sampleFrames)   // future
        {
            currentDelta -= sampleFrames;
            return;
        }
        memset (out1, 0, currentDelta * sizeof (float));
        memset (out2, 0, currentDelta * sizeof (float));
        out1 += currentDelta;
        out2 += currentDelta;
        sampleFrames -= currentDelta;
        currentDelta = 0;
    }
    // loop
    while (--sampleFrames >= 0)
    {
        // this is all very raw, there is no means of interpolation,
        // and we will certainly get aliasing due to non-bandlimited
        // waveforms. don't use this for serious projects...
        (*out1++) = wave1[(VstInt32)fPhase1 & mask] * fVolume1 * vol;
        (*out2++) = wave2[(VstInt32)fPhase2 & mask] * fVolume2 * vol;
        fPhase1 += freq1;
        fPhase2 += freq2;
    }
}                       
else
{
    memset (out1, 0, sampleFrames * sizeof (float));
    memset (out2, 0, sampleFrames * sizeof (float));
}

}

我理解该功能的方式是,如果当前打开了 midi 音符,我们需要将波表复制到输出数组中以传递回 VstHost。我具体不明白的是

if (currentDelta > 0)
条件块中的区域在做什么。似乎它只是将零写入输出数组...

该文件的完整版本可在 http://pastebin.com/SdAXkRyW

传入

的 MIDI NoteOn 事件可以相对于您接收的缓冲区的开始(称为增量帧)具有偏移量。当前增量跟踪音符相对于收到的缓冲区的开始时间应播放的时间。

因此,如果当前 Delta> sampleFrames,这意味着音符不应该在这个周期(未来)中播放 - 提前退出。

如果当前 Delta 在此周期的范围内,则内存将被清除到音符应产生输出 (memset) 的那一刻,并且指针纵以使其看起来像缓冲区从声音应该播放的位置开始 - 长度 - sampleFrames- 也被调整。

然后在循环中产生声音。

希望对您有所帮助。马克