这个 Vst 合成器示例的解释
Explanation of a this Vst Synth example
我在理解斯坦伯格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- 也被调整。
然后在循环中产生声音。
希望对您有所帮助。马克
- 请解释"函数1(p1,p2,p3);"的输出
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 被解释为低级别const的const对象的地址
- 计算每个节点的树高,帮助我解释这个代码解决方案
- MSVC将仅移动结构参数解释为指针
- 内联程序集printf将整数解释为地址
- 有人能解释一下为什么下界是这样工作的吗C++的
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 我是c ++的新手,你能解释一下在这种情况下的指针吗
- 有人能为我解释一下C++代码吗
- 你能解释一下什么运行时错误是如何解决它的吗?
- 请解释字谜的代码,我看不懂计数器数组,每个值已经是0
- 有人可以向我解释为什么控制台输出 0 吗?
- 有人可以解释一下这段代码如何能够反转字符串
- 在 C++ 中解释多维向量的语句时感到困惑
- 解释一下 for (char c : str) 的作用?
- 确切地说,如何解释 std::getline(stream, string) 函数在C++中填充的字符串
- 隐式重新解释引用时强制转换,没有警告/错误
- 有人可以在 c++ 中解释数组的这种输入
- 这个 Vst 合成器示例的解释