我还是个初学者,所以这对我来说将是一个相当高级的项目,但我想现在就开始它并将其作为一个持续的事情(我不打算在 2 周内完成一个成品,甚至也不是构建我将使用的东西,只是一种学习经验)。
我想构建一个合成器用作 ableton live 9 的 vst3 插件。我认为第一步是制作输出任意波形并响应 midi 输入的东西(频率变化注意)和一个基本的 GUI 模板。然后我会尝试引入不同的波形,然后是更多的振荡器和失谐,然后是声音,然后是滤波器,然后是多个声音等等。
我将如何开始做这件事?我知道基本的 c++,但我不知道如何创建波形并将其输出为声音。 C++ 是否适合用于此类应用程序?
虽然您的问题很广泛,但我可以提供一些关于从哪里开始的见解。
首先,您需要一份 VST3 SDK来自斯坦伯格
根据我的经验,开始使用 VST SDK 的学习曲线相当大。所以我建议找一个在其之上提供包装器的库。例如JUCE
使用包装器将帮助您绕过使 VST 工作所需完成的大量样板编程。
至于波形生成、滤波和其他 DSP 相关概念……主题太多,我什至无法开始描述。
看看musicdsp和 The STK了解一些基本概念。
买一本关于这个主题的书。经典是 The Audio Programming Book
此外,您需要确保自己对音频理论有深入的了解。看看Introduction to Computer Music: Volume One .
当然,Google 是您的 friend 。
编辑:
更完整地回答您的问题。是的,C++(或 C)将是此类应用程序的首选语言(尽管不是唯一可能的选择)
在深入研究 VST 开发之前,我会考虑使用音频 API,这将使您能够在没有 VST 开发的麻烦的情况下提高您的技能。
至于音频库,以下是两个受欢迎的选项:
假设您已经安装了 PortAudio 和 libzaudio,以下将生成 sin 440hz 波形一秒钟:
#include <iostream>
#include <cmath>
#include <libzaudio/zaudio.hpp>
int main(int argc, char** argv)
{
try
{
//bring the needed zaudio components into scope
using zaudio::no_error;
using zaudio::sample;
using zaudio::sample_format;
using zaudio::stream_params;
using zaudio::time_point;
using zaudio::make_stream_context;
using zaudio::make_stream_params;
using zaudio::make_audio_stream;
using zaudio::start_stream;
using zaudio::stop_stream;
using zaudio::thread_sleep;
//create an alias for a 32 bit float sample
using sample_type = sample<sample_format::f32>;
//create a stream context with the default api (portaudio currently)
auto&& context = make_stream_context<sample_type>();
//create a stream params object
auto&& params = make_stream_params<sample_type>(44100,512,0,2);
//setup to generate a sine wave
constexpr sample_type _2pi = M_PI * 2.0;
float hz = 440.0;
sample_type phs = 0;
sample_type stp = hz / params.sample_rate() * _2pi;
//create a zaudio::stream_callback compliant lambda that generates a sine wave
auto&& callback = [&](const sample_type* input,
sample_type* output,
time_point stream_time,
stream_params<sample_type>& params) noexcept
{
for(std::size_t i = 0; i < params.frame_count(); ++i)
{
for(std::size_t j = 0; j < params.output_frame_width(); ++j)
{
*(output++) = std::sin(phs);
}
phs += stp;
if(phs > _2pi)
{
phs -= _2pi;
}
}
return no_error;
};
//create an audio stream using the params, context, and callback created above. Uses the default error callback
auto&& stream = make_audio_stream<sample_type>(params,context,callback);
//start the stream
start_stream(stream);
//run for 1 second
thread_sleep(std::chrono::seconds(1));
//stop the stream
stop_stream(stream);
}
catch (std::exception& e)
{
std::cout<<e.what()<<std::endl;
}
return 0;
}
(Pulled from one of my example files)
如果您想在其他地方与我联系,我很乐意为您提供更详细的解释。 (Stack Overflow 不允许就该主题进行长时间讨论)