SynthLab SDK
SynthLab::SynthEngine Class Reference

Encapsulates an entire synth engine, producing one type of synthesizer set of voices (e.g. Virtual Analog, Sample Based, FM, etc...) More...

#include <synthengine.h>

Public Member Functions

 SynthEngine (uint32_t blockSize=64)
 Construction: More...
 
virtual ~SynthEngine ()
 Destruction: More...
 
virtual bool reset (double _sampleRate)
 Resets all voices and the audio delay object. More...
 
virtual bool render (SynthProcessInfo &synthProcessInfo)
 Render a buffer of output audio samples. More...
 
virtual bool processMIDIEvent (midiEvent &event)
 The MIDI event handler function; for note on/off messages it finds the voices to turn on/off. MIDI CC information is placed in the shared CC array. More...
 
virtual bool initialize (const char *dllPath=nullptr)
 Initializes all voices with the DLL path. More...
 
void accumulateVoice (SynthProcessInfo &synthProcessInfo, double scaling=0.707)
 Accumulates voice buffers into a single mix buffer for each channel. More...
 
void applyGlobalVolume (SynthProcessInfo &synthProcessInfo)
 Apply a single global volume control to output mix buffers. More...
 
void getParameters (std::shared_ptr< SynthEngineParameters > &_parameters)
 
void setParameters (std::shared_ptr< SynthEngineParameters > &_parameters)
 Function to update the engine and voice parameters. More...
 
int getFreeVoiceIndex ()
 Helper function to find a free voice to use. More...
 
int getVoiceIndexToSteal ()
 Helper function to find a free voice to steal based on some kind of heuristic. More...
 
int getActiveVoiceIndexInNoteOn (unsigned int midiNoteNumber)
 Helper function to find the voice that is playing a certain MIDI note. More...
 
int getStealingVoiceIndexInNoteOn (unsigned int midiNoteNumber)
 Helper function to find the voice that is playing a certain MIDI note and that will be stolen. More...
 
 SynthEngine (uint32_t blockSize=64, DMConfig *config=nullptr)
 Construction: More...
 
virtual bool reset (double _sampleRate)
 
virtual bool render (SynthProcessInfo &synthProcessInfo)
 
virtual bool processMIDIEvent (midiEvent &event)
 
virtual bool initialize (const char *dllPath=nullptr)
 
void accumulateVoice (SynthProcessInfo &synthProcessInfo, double scaling=0.707)
 
void applyGlobalVolume (SynthProcessInfo &synthProcessInfo)
 
void getParameters (std::shared_ptr< SynthEngineParameters > &_parameters)
 
void setParameters (std::shared_ptr< SynthEngineParameters > &_parameters)
 
int getFreeVoiceIndex ()
 
int getVoiceIndexToSteal ()
 
int getActiveVoiceIndexInNoteOn (uint32_t midiNoteNumber)
 Helper function to find the voice that is playing a certain MIDI note. More...
 
int getStealingVoiceIndexInNoteOn (uint32_t midiNoteNumber)
 Helper function to find the voice that is playing a certain MIDI note and that will be stolen. More...
 
std::vector< std::string > getModuleStrings (uint32_t mask)
 Gets module-specific core STRINGS (e.g. waveform names for oscillators, filter types for filters, etc... More...
 
std::vector< std::string > getModKnobStrings (uint32_t mask)
 Gets module-specific Mod Knob label STRINGS. More...
 
void setAllCustomUpdateCodes ()
 Forwards custom code settings to first voice (since all voices share the same architecture) More...
 
uint32_t getVoiceCount ()
 
void setDynamicModules (std::vector< std::shared_ptr< SynthLab::ModuleCore >> modules, uint32_t voiceIndex)
 Adds dynamic module cores to the voice's member obejcts. More...
 
std::vector< std::string > getModuleCoreNames (uint32_t moduleType)
 Gets module core names, four per object. More...
 
 SynthEngine (uint32_t blockSize=64)
 
virtual bool reset (double _sampleRate)
 
virtual bool render (SynthProcessInfo &synthProcessInfo)
 
virtual bool processMIDIEvent (midiEvent &event)
 
virtual bool initialize (const char *dllPath=nullptr)
 
void accumulateVoice (SynthProcessInfo &synthProcessInfo, double scaling=0.707)
 
void applyGlobalVolume (SynthProcessInfo &synthProcessInfo)
 
void getParameters (std::shared_ptr< SynthEngineParameters > &_parameters)
 
void setParameters (std::shared_ptr< SynthEngineParameters > &_parameters)
 
int getFreeVoiceIndex ()
 
int getVoiceIndexToSteal ()
 
int getActiveVoiceIndexInNoteOn (unsigned int midiNoteNumber)
 
int getStealingVoiceIndexInNoteOn (unsigned int midiNoteNumber)
 

Protected Attributes

SynthProcessInfo voiceProcessInfo
 
std::shared_ptr< SynthEngineParametersparameters = std::make_shared<SynthEngineParameters>()
 
std::shared_ptr< MidiInputDatamidiInputData = std::make_shared<MidiInputData>()
 
std::shared_ptr< MidiOutputDatamidiOutputData = std::make_shared<MidiOutputData>()
 
std::unique_ptr< SynthVoicesynthVoices [MAX_VOICES] = { 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0 }
 array of voice objects for the engine
 
std::shared_ptr< WavetableDatabasewavetableDatabase = nullptr
 
std::shared_ptr< PCMSampleDatabasesampleDatabase = nullptr
 
std::unique_ptr< AudioDelaypingPongDelay = nullptr
 

Detailed Description

Encapsulates an entire synth engine, producing one type of synthesizer set of voices (e.g. Virtual Analog, Sample Based, FM, etc...)

  • contains an array of SynthVoice objects to render audio and also processes MIDI events
  • contains an audio delay used as a master-buss effect
  • contains functions to interface with framework to deliver dynamic string lists (advanced GUI)
  • creates the global MIDI data object and passes shared pointers to all voices
  • creates the wavetable database object and passes shared pointers to all voices
  • creates the PCM sample database object and passes shared pointers to all voices
Author
Will Pirkle
Version
Revision : 1.0
Date
Date : 2017 / 09 / 24

Constructor & Destructor Documentation

◆ SynthEngine() [1/2]

SynthLab::SynthEngine::SynthEngine ( uint32_t  blockSize = 64)

Construction:

  • initializes global MIDI data structure with values to prevent accidental silence on first note-on
  • constructs the shared wavetable databse
  • constructs the shared PCM sample database
  • constructs the array of MAX_VOICES synth voice objects
  • constructs the (un-shared) audio delay object
Parameters
blockSizethe block size to be used for the lifetime of operation; OK if arriving blocks are smaller than this value, NOT OK if larger
Returns
the newly constructed object

◆ ~SynthEngine()

SynthLab::SynthEngine::~SynthEngine ( )
virtual

Destruction:

  • the PCM sample database is dynamic and is populated with arrays extracted from WAV files at startup time; the benefit is instant access to the samples
  • this deletes these arrays that are shared safely across voices vie the IPCMSampleDatabase objects

◆ SynthEngine() [2/2]

SynthLab::SynthEngine::SynthEngine ( uint32_t  blockSize = 64,
DMConfig config = nullptr 
)

Construction:

  • initializes global MIDI data structure with values to prevent accidental silence on first note-on
  • constructs the shared wavetable databse
  • constructs the shared PCM sample database
  • constructs the array of MAX_VOICES synth voice objects
  • constructs the (un-shared) audio delay object
Parameters
blockSizethe block size to be used for the lifetime of operation; OK if arriving blocks are smaller than this value, NOT OK if larger
configOPTIONAL argument for DM synth configuration; can be safely ignored for non DM products
Returns
the newly constructed object

Member Function Documentation

◆ accumulateVoice() [1/3]

void SynthLab::SynthEngine::accumulateVoice ( SynthProcessInfo synthProcessInfo,
double  scaling = 0.707 
)

Functions to help with rendering the final synth output audio stream

◆ accumulateVoice() [2/3]

void SynthLab::SynthEngine::accumulateVoice ( SynthProcessInfo synthProcessInfo,
double  scaling = 0.707 
)

Accumulates voice buffers into a single mix buffer for each channel.

Functions to help with rendering the final synth output audio stream

Parameters
synthProcessInfostructure containing all information needed about the current block to process including:
  • MIDI messages for the block
  • pointers to the output audio buffers
  • optional pointers to input audio buffers (not used in SynthLab)
scalinga scalar value to apply while accumulating
Returns
true if sucessful

◆ accumulateVoice() [3/3]

void SynthLab::SynthEngine::accumulateVoice ( SynthProcessInfo synthProcessInfo,
double  scaling = 0.707 
)

Functions to help with rendering the final synth output audio stream

◆ applyGlobalVolume()

void SynthLab::SynthEngine::applyGlobalVolume ( SynthProcessInfo synthProcessInfo)

Apply a single global volume control to output mix buffers.

Parameters
synthProcessInfostructure containing all information needed about the current block to process including:
  • MIDI messages for the block
  • pointers to the output audio buffers
  • optional pointers to input audio buffers (not used in SynthLab)
Returns
true if sucessful

◆ getActiveVoiceIndexInNoteOn() [1/2]

int SynthLab::SynthEngine::getActiveVoiceIndexInNoteOn ( unsigned int  midiNoteNumber)

Helper function to find the voice that is playing a certain MIDI note.

Parameters
midiNoteNumbernote number that a voice may or may not be plaing
Returns
index of the voice playing the note or -1 if no voice is playing this note

◆ getActiveVoiceIndexInNoteOn() [2/2]

int SynthLab::SynthEngine::getActiveVoiceIndexInNoteOn ( uint32_t  midiNoteNumber)

Helper function to find the voice that is playing a certain MIDI note.

Parameters
midiNoteNumbernote number that a voice may or may not be plaing
Returns
index of the voice playing the note or -1 if no voice is playing this note

◆ getFreeVoiceIndex() [1/3]

int SynthLab::SynthEngine::getFreeVoiceIndex ( )

Voice stealing helper functions

◆ getFreeVoiceIndex() [2/3]

int SynthLab::SynthEngine::getFreeVoiceIndex ( )

Helper function to find a free voice to use.

Voice stealing helper functions

Returns
index of free voice, or -1 if voice not found

◆ getFreeVoiceIndex() [3/3]

int SynthLab::SynthEngine::getFreeVoiceIndex ( )

Voice stealing helper functions

◆ getModKnobStrings()

std::vector< std::string > SynthLab::SynthEngine::getModKnobStrings ( uint32_t  mask)

Gets module-specific Mod Knob label STRINGS.

  • Forwards call to first voice since all share the same architecture
Returns
a vector full of module core mod knob lable strings (standard implementation is 4 strings)

◆ getModuleCoreNames()

std::vector< std::string > SynthLab::SynthEngine::getModuleCoreNames ( uint32_t  moduleType)

Gets module core names, four per object.

  • Forwards call to first voice since all share the same architecture
Returns
a vector full of module core NAME strings (standard implementation is 4 strings)

◆ getModuleStrings()

std::vector< std::string > SynthLab::SynthEngine::getModuleStrings ( uint32_t  mask)

Gets module-specific core STRINGS (e.g. waveform names for oscillators, filter types for filters, etc...

OPTIONAL methods for getting string values for dynamic GUIs – see your framework's GUI documentaiton

  • Forwards call to first voice since all share the same architecture
Returns
a vector full of module-specific strings (standard implementation is 16 strings)

◆ getStealingVoiceIndexInNoteOn() [1/2]

int SynthLab::SynthEngine::getStealingVoiceIndexInNoteOn ( unsigned int  midiNoteNumber)

Helper function to find the voice that is playing a certain MIDI note and that will be stolen.

Parameters
midiNoteNumbernote number that a voice may or may not be plaing
Returns
index of the voice playing the note or -1 if no voice is playing this note

◆ getStealingVoiceIndexInNoteOn() [2/2]

int SynthLab::SynthEngine::getStealingVoiceIndexInNoteOn ( uint32_t  midiNoteNumber)

Helper function to find the voice that is playing a certain MIDI note and that will be stolen.

Parameters
midiNoteNumbernote number that a voice may or may not be plaing
Returns
index of the voice playing the note or -1 if no voice is playing this note

◆ getVoiceIndexToSteal()

int SynthLab::SynthEngine::getVoiceIndexToSteal ( )

Helper function to find a free voice to steal based on some kind of heuristic.

Returns
index of the voice to be stolen, or -1 if voice not found (should never happen)

◆ initialize()

bool SynthLab::SynthEngine::initialize ( const char *  dllPath = nullptr)
virtual

Initializes all voices with the DLL path.

  • used for PCM sample oscillator cores that need to find WAV files with samples
Parameters
dllPathpath to the folder that contains the plugin DLL
Returns
true if sucessful

◆ processMIDIEvent()

bool SynthLab::SynthEngine::processMIDIEvent ( midiEvent event)
virtual

The MIDI event handler function; for note on/off messages it finds the voices to turn on/off. MIDI CC information is placed in the shared CC array.

Parameters
eventa single MIDI Event to decode and process
Returns
true if handled, false otherwise

◆ render()

bool SynthLab::SynthEngine::render ( SynthProcessInfo synthProcessInfo)
virtual

Render a buffer of output audio samples.

  • process all MIDI events at top of block
  • then renders the active voices one at a time
  • accumulates voices and applies delay FX
  • applies global gain control to final audio output stream
Parameters
synthProcessInfostructure containing all information needed about the current block to process including:
  • MIDI messages for the block
  • pointers to the output audio buffers
  • optional pointers to input audio buffers (not used in SynthLab)
Returns
true if sucessful

◆ reset() [1/3]

virtual bool SynthLab::SynthEngine::reset ( double  _sampleRate)
virtual

main functions, declared as virtual so you can use as as base class if needed

◆ reset() [2/3]

bool SynthLab::SynthEngine::reset ( double  _sampleRate)
virtual

Resets all voices and the audio delay object.

main functions, declared as virtual so you can use as as base class if needed

Parameters
_sampleRatethe initial or newly changed sample rate
Returns
true if sucessful

◆ reset() [3/3]

virtual bool SynthLab::SynthEngine::reset ( double  _sampleRate)
virtual

main functions, declared as virtual so you can use as as base class if needed

◆ setAllCustomUpdateCodes()

void SynthLab::SynthEngine::setAllCustomUpdateCodes ( )

Forwards custom code settings to first voice (since all voices share the same architecture)

OPTIONAL function - this uses the 32-bit enumeration codes to create a wire-or'ed register for keeping track of GUI updates for dynamic string and core loading ADVANCED: see your framework's GUI documentaiton to use; this is NOT tied to any framwork and is only here an an example

  • 100% optional and only for those who know how to use dynamic strings with their frameworks

◆ setDynamicModules()

void SynthLab::SynthEngine::setDynamicModules ( std::vector< std::shared_ptr< SynthLab::ModuleCore >>  modules,
uint32_t  voiceIndex 
)

Adds dynamic module cores to the voice's member obejcts.

  • only used in SynthLab-DM products

◆ setParameters()

void SynthLab::SynthEngine::setParameters ( std::shared_ptr< SynthEngineParameters > &  _parameters)

Function to update the engine and voice parameters.

  • note that most pararameter update information is in shared pointers to structures
  • most updating is done at the ModuleCore level
  • converts incoming global tune and volume information into MIDI data for cores to use
  • sets up voice detuning and panning in unison mode
Parameters
_parameterscustom parameter structure, delivered from plugin framework prior to calling the render function
Returns
true if handled, false otherwise

The documentation for this class was generated from the following files: