SynthLab SDK
|
You can find the SynthEngine template code in the SynthLab_SDK/source folder in two files, synthengine.h and synthengine.cpp. This is the minimum implementation but with a bunch of helper code already added for you that mostly deals with deocding MIDI messages, and managing the array of voice objects that do the rendering.
The SynthEngine Operational Phases are discussed in detail in the synth book and so that theory will not be repeated here. However, we do want to to step through the operational phase methods, declared as virtual as these are the main interface functions that the SynthEngine will be calling.
For the SynthEngine, there is no such thing as "standalone" operation as it is alredy in standalone mode, acting as the sole object your frameowork needs to interact with. The engine is the fountainhead of all synth shared databases, parameters, and MIDI data and most of that is created within at construction.
Constructor
The constructor's main role is in constructing the SynthVoice members, passing them the shared resources that are instantiated during construction. Your plugin framework will instantiate the object and the constructor requires a committment by passing the maximum block size during instantiation. The framework may always render blocks smaller than this size. The constructor has only one argument, which is that block size.
Destructor
The SynthEngine is one of a few objects with a dedicated destructor as nearly all dynamic resources are maintained with smart pointers. The destructor is used to elimiate all dynamically declared PCM sample arrays that were extracted from WAV files at load time, and then later shared via the PCM sample database.
The SynthEngine simply forwards these calls to its member voice objects and these are direct consequences of your plugin framework calling reset() and initialize() at load time.
Your plugin framework will access the engine's parameter structure pointers and use them to alter variables based on the user's GUI control settings. After that, the framework should call the SynthEngine::setParameters() method to perform the updates. The engine template code is very light, simply calling the update() method on the voices. When you add unison mode, or any other mode of operation that affect voices in a different way, you need to add that code here. For example in unison mode, the SynthLab example synths will set the voice detuning, and oscillator starting phases during this function. We will add this code in the next section.
The render phase is detailed in the synth book and questions about the block processing or other details are answered there so it will not be repeated here. The render phase is very simple and has three parts:
The template engine object includes a couple of helper functions for accumulating the voice audio output buffers and applying global volume adjustments.
The engine processes incoming MIDI events that it finds in the MIDI event queue in the SynthProcInfo structure that the frameworks passes it during the render operation. The template version is empty, but we will add meaningful MIDI event coding in the next section.
This completes the tour of the template object. In the next section, we will modify the engine template to add the new SynthVoice from the previous section.