SynthLab SDK
DCA

The SynthLab::DCA object processes audio samples from its AudioBuffer input array to its AudioBuffer output array. It also reads its modulation input array during the update( ) phase to allow parameter modulation. It is the simplest of the objects in SynthLab and has no cores.

You will need to add the following files for the SynthFilter

Follow the same pattern and start with the class documentation. The DCA:

  • uses a DCAParameters structure for control, both GUI and programatically
  • reads values from its own AudioBuffer input
  • renders values into its own AudioBuffer output
  • has no cores - it is too simple an object to warrant it

From the docs on DCA:

  • reads from the input buffer
  • renders into the output buffer
  • renders one block of audio per render cycle

Note that the SynthFilter documentation also shows you how to create the object in standalone mode, we can use this code verbatim because we will setup a blocksize of 64 for this DCA.

// --- standalone construction, block size = 64
DCA(nullptr, nullptr, 64);
//

So, we will do the following:

  1. create the DCA and pass nullptr for the MIDI input and parameters arguments
  2. reset it with the sample rate
  3. create a MIDI event and call the note-on handler
  4. use getParameters: set the output gain to +3dB and the pan value to +0.25 (1/4 to the right)
  5. transfer audio from the filter to the DCA
  6. call the render function to process the data (send that to your plugin framework output buffer)
  7. call the note-off handler when note event is done
#include "dca.h"
// --- create a LFO via shared pointer; here is the definition
std::unique_ptr<SynthLab::DCA> dca = nullptr;
// --- here is the creation
dca.reset(new SynthLab::DCA(nullptr, /* MIDI input data */
nullptr, /* dca parameters */
64)); /* block size */
// --- initialize
dca->reset(44100.0); //<- get fs from your framework
// --- get the parameter struct pointer;
// it was synthesized when we passed a nullptr into the constructor
std::shared_ptr<SynthLab::DCAParameters> dcaParameters = dca->getParameters();
if (dcaParameters) // should never fail
{
// --- set the variables
dcaParameters->gainValue_dB = +3.0;
dcaParameters->panValue = 0.25; // 1/4 to the right, 3/4 to the left
// --- call the update function (only needs to be done once per render cycle)
dca->update();
}
// ---

Now, in response to a MIDI note-on message, we setup a MIDIEvent structure (NOTE: we added the call to the pitch calculaton prior to the note-on function call):

// --- prepare a MIDI event for note-on
midiEvent.midiNoteNumber = 60;
midiEvent.midiPitch = SynthLab::midiNoteNumberToOscFrequency(midiEvent.midiNoteNumber); //< PITCH Calculation
midiEvent.midiNoteVelocity = 127;
// --- send note event
wtOsc->doNoteOn(midiEvent);
// --- filter note on handler
filter->doNoteOn(midiEvent);
// --- dca note on handler
dca->doNoteOn(midiEvent);
// ---

Now you render values from the oscillator and send them to the filter. Once rendered, you may send the block of data to your plugin framework's output buffers;

// --- render OSC output
wtOsc->render(64);
// --- transfer information from OSC output to filter input
SynthLab::copyOutputToInput(wtOsc->getAudioBuffers(), /* FROM osc output */
filter->getAudioBuffers(), /* TO filter input */
SynthLab::STEREO_TO_STEREO, /* stereo copy */
64); /* block size in frames */
// --- render the filter
filter->render(64);
// --- transfer information from filter output to DCA input
SynthLab::copyOutputToInput(filter->getAudioBuffers(), /* FROM filter output */
dca->getAudioBuffers(), /* TO dca input */
SynthLab::STEREO_TO_STEREO, /* stereo copy */
64); /* block size in frames */
// --- render the DCA
dca->render(64);
// --- get pointers to output buffers
float* leftOutBuffer = dca->getAudioBuffer()->getOutputBuffer(SynthLab::LEFT_CHANNEL);
float* rightOutBuffer = dca->getAudioBuffer()->getOutputBuffer(SynthLab::RIGHT_CHANNEL);
// --- loop over buffers to access samples; loop maximum (64) set manually here
for (uint32_t i = 0; i < 64; i++)
{
float leftSample = leftOutBuffer[i];
float rightSample = rightOutBuffer[i];
// --- SEND THESE OUTPUTS TO YOUR FRAMEWORK or play with them
}
// ---

From here you can keep rendering until the note-off message arrives.

// --- prepare a MIDI event for note-off
midiEvent.midiNoteNumber = 60; // <- get from your framework
midiEvent.midiPitch = SynthLab::midiNoteNumberToOscFrequency(midiEvent.midiNoteNumber); //< PITCH Calculation
midiEvent.midiNoteVelocity = 0; // <- get from your framework
// --- send note event
dca->doNoteOff(midiEvent);
// ---

Now, experiment with changing the DCA parameters (see the DCAParameter documentation to see what you can change). Also, try experimenting with the mod knobs (see SynthLFO tutorial above)


synthlab_4.png