此Vst Synth示例的说明

达布隆

我在Steinberg VST Synth示例中无法理解代码的特定区域

在此功能中:


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音符,我们需要将wave表复制到输出数组中,以传递回VstHost。我不特别了解的是

if (currentDelta > 0)
有条件的块正在做。似乎它只是将零写入输出数组...

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

奥比万雅各比

即将到来的MIDI NoteOn事件可以相对于您收到的缓冲区的开始有一个偏移量(称为deltaFrames)。currentDelta跟踪音符何时应该相对于接收到的缓冲区的开始播放。

因此,如果currentDelta> sampleFrames,则意味着该音符不应在此循环中播放(将来)-提前退出。

如果currentDelta在此周期的范围内,则清除内存,直到音符应产生输出(内存集)为止,并操纵指针以使其看起来像缓冲区在声音应播放的位置开始-长度-sampleFrames-也进行了调整。

然后在循环中产生声音。

希望能帮助到你。马克

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章