我将如何以编程方式与 VST(i) 插件交互来合成音频?
以 Tweakbench 的 VSTi Triforce 为例。当加载到市场上的任何 VST 主机中时,它允许主机向 VSTi 发送(大概是 MIDI)信号。然后,VSTi 将处理该信号并输出由 VSTi 内的软件乐器创建的合成音频。
例如,将 A4(我相信是 MIDI 音符)发送到 VSTi 将导致它合成中音 C 上方的 A。它将音频数据发送回 VST 主机,然后 VST 主机可以在我的扬声器上播放它或保存它到 .wav 或其他一些音频文件格式。
假设我有 Triforce,并且正在尝试用我选择的语言编写一个程序,该程序可以通过发送要合成的 A4 笔记来与 VSTi 交互,并自动将其保存到计算机上的文件中。系统?
最终,我希望能够解析整个单轨 MIDI 文件(使用已建立的、稳定的库已可用于此目的)并将其发送到 VSTi 以“渲染”/将其合成为音频文件。
我将如何解决这个问题,以及我应该使用什么语言来构建核心框架?
最终,它将在基于 Ruby 的项目中使用,因此任何指向特定 Ruby 资源的指针也很好。
不过,我只是想基本上了解VSTi 的 API 是如何工作的。 (我意识到这个问题与首先构建 VST 主机的问题非常相关,尽管它只能将 VST 输出保存到文件而不播放它们,而且范围要小得多)
Take, for example, the VSTi Triforce, by Tweakbench. When loaded up in any VST host on the market, it allows the host to send a (presumably MIDI) signal to the VSTi. The VSTi will then process that signal and output synthesized audio as created by a software instrument within the VSTi.
For example, sending an A4 (MIDI note, I believe) to the VSTi will cause it to synthesize the A above Middle C. It sends the audio data back to the VST Host, which then could either play it on my speakers or save it to .wav or some other audio file format.
Let's say I have Triforce, and am trying to write a program in my language of choice that could interact with the VSTi by sending in an A4 note to be synthesized, and automatically saving it to a file on the system?
Eventually, I'd like to be able to parse an entire one-track MIDI file (using established, stable libraries already available for this purpose) and send it to the VSTi to "render"/synthesize it into an audio file.
How would I go about this, and in what language should I look to build the core framework?
Ultimately, it will be used in a Ruby-based project, so any pointers to specific Ruby resources would be nice as well.
However, I'm just trying to understand basically how the API of a VSTi works. (I've realized that this question is very much related to the question of building a VST host in the first place, albeit one that can only save VST outputs to file and not play them back, and with considerably smaller scope)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,既然你问了,像这样的项目的理想语言就是 C++。尽管有针对高级语言(例如 Java 和 Java)的包装器。 .NET for the VST SDK,我找不到一个用于 Ruby 的(尽管我确实找到了这个相当酷的项目,它可以让你 在 Ruby 中编写 VST 插件)。因此,您将不得不自己进行某种程度的 C/C++ 集成。
也就是说,这里基本上有两个选择:
我写了一个VST主机编程教程< /a> 不久前在我的博客上,您可能会发现这在任何情况下都很有用。它详细介绍了如何在 Mac OSX 和 Windows 上打开 VST 插件并与之通信。一旦你让你的主机加载插件,你需要能够将MIDI事件直接发送到插件,或者通过从文件中读取它们,或者在你的Ruby代码和VST主机之间进行某种类型的通信(即,命名管道、套接字、文件等)。如果您不熟悉 MIDI 协议,请查看以下链接:
您可能已经知道,VST 本质上是一种基于块的协议。您从插件请求小块音频数据,并在插件处理相应块之前将任何 MIDI 事件发送到插件。确保不要忽略 MIDI 增量字段;这将确保插件开始直接在所需样本上处理 MIDI 事件。否则,插件听起来会有点跑调,尤其是在乐器的情况下。
VST SDK 也基于浮点块,因此您返回的任何数据都将包含范围 { -1.0 .. 1.0 } 内的各个样本。根据您所需的输出格式,您可能需要将它们转换为其他格式。幸运的是,似乎有一个 音频文件库的 Ruby 绑定,所以你也许能够将您的输出发送到其中,以便生成正确的 AIFF/WAV 文件。
总而言之,要实现您想要的最终目标需要进行大量的工作,但这并非不可能。祝你好运!
Well, since you asked, the ideal language for a project like this is going to be C++. Although there are wrappers for higher-level languages such as Java & .NET for the VST SDK, I couldn't find one for Ruby (though I did find this rather cool project which lets you program VST plugins in Ruby). So you will be stuck doing some degree of C/C++ integration on your own.
That said, you have basically two options here:
I wrote up a VST host programming tutorial on my blog awhile back which you may find useful in either case. It details how you open and communicate with VST plugins on both Mac OSX and Windows. Once you have gotten your host to load up the plugins, you need to be able to either send MIDI events directly to the plugin, either by reading them from file or some type of communication between your Ruby code and the VST host (ie, a named pipe, socket, file, etc.). If you are unfamiliar with the MIDI protocol, check out these links:
As you might have already figured out, VST is fundamentally a block-based protocol. You request small blocks of audio data from the plugin, and you send along any MIDI events to the plugin right before it processes that respective block. Be sure not to ignore the MIDI delta field; this will ensure that the plugin starts processing the MIDI event directly on the desired sample. Otherwise, the plugin will sound a bit off-tempo, especially in the case of instruments.
The VST SDK is also based around floating-point blocks, so any data you get back will contain individual samples in the range { -1.0 .. 1.0 }. Depending on your desired output format, you may need to convert these to some other format. Fortunately, there seems to be a Ruby binding for the audiofile library, so you may be able to send your output into that in order to generate a proper AIFF/WAV file.
In all, it'll be a fair amount of work to get to your desired end goal, but it's not impossible by any means. Good luck!