1

Example: If I want to play a sound in my soon to be homemade VST instrument, and this note in the sequencer is 15000 samples long and the note is set to ON by the processEvents, the processReplace function starts to play the sound from 0 to sampleFrames (that is 10000 in my example here). Then there will be 5000 samples left to play of the note the next time it enters the loop in processReplace, but still the loop will play from 0 to 10000 which is 5000 more than samples to play from the note. There will be 5000 samples of silence that are going to be played and that means that this note will not be turned off until 5000 samples later!?

If a new sound in the sequencer is placed directly after the first one the processReplace function will not see the short period of OFF set by the processEvents and see the next sample as a continous sound of the first one because it will only see the new notes ON when the loop is entered again.

How can I prevent this from happening? How can I stop the processReplace loop if the note ends in the middle of the loop?

4

1 回答 1

4

我不确定我得到你的问题,但这里是一个刺。

当您确定要从传入的 Midi 音符事件在 processEvents 中生成什么声音时,下一次调用 processReplace 必须实现这一点。因此,您需要内部状态来记住在 processEvents 中检测到的注释并且需要在 processReplace 期间输出。

当样本的持续时间(在您的情况下)超过缓冲区可以容纳的时间(sampleFrames)时,您需要记住您在做什么以及您在哪里。在您的示例中,已经播放了 2/3 的样本,下一个 processReplace 需要播放样本的最后 1/3。

如果(Midi)音符尚未关闭(您没有收到 Midi note-off 事件),您必须决定作为 VSTi 插件如何处理它。因此,您可能希望重复相同的样本并在第二个 processEvents 调用中播放它的前 1/3 - 请记住您必须稍后播放该样本的其余部分。

如果您在这种情况下的任何地方收到 Midi note-off 消息 - 您将必须存储内部状态(数据),告诉您的插件的 processReplace 逻辑在播放该样本的正确时刻停止。许多插件采用捷径并将这些信息以样本块的形式处理,该样本块等于 processReplace 缓冲区的 sampleFrames。但是,如果您想要精确,您必须检查传入 Midi 音符事件的 deltaFrames,并在 processReplace 处理中考虑该偏移量。

主机 (DAW) 确定何时调用您的 processEvents 和 processReplace 方法。它通常会在插件(实例)的整个生命周期内继续这样做。因此,保持插件正在执行的内部状态是关键。如果它什么都不做 - 您无论如何都不会更改输出缓冲区(归零)。

希望能帮助到你。马克

于 2013-09-25T14:11:16.023 回答