SynthLab SDK
SynthLab::AnalogEGCore Class Reference

Analog EG emulator. More...

#include <analogegcore.h>

Inheritance diagram for SynthLab::AnalogEGCore:
SynthLab::ModuleCore

Public Member Functions

 AnalogEGCore ()
 Construction: Cores follow the same construction pattern. More...
 
virtual ~AnalogEGCore ()
 
virtual bool reset (CoreProcData &processInfo) override
 Resets object to initialized state. More...
 
virtual bool update (CoreProcData &processInfo) override
 Updates the object for the next block of audio processing. More...
 
virtual bool render (CoreProcData &processInfo) override
 Renders the output of the module. More...
 
virtual bool doNoteOn (CoreProcData &processInfo) override
 Note-on handler for the ModuleCore. More...
 
virtual bool doNoteOff (CoreProcData &processInfo) override
 Note-off handler for the ModuleCore. More...
 
virtual int32_t getState () override
 
virtual bool shutdown () override
 Shutdown handler for EG. More...
 
virtual void setSustainOverride (bool b) override
 Sustain pedal handler for EG. More...
 
- Public Member Functions inherited from SynthLab::ModuleCore
 ModuleCore ()
 Constructs a ModuleCore. More...
 
virtual void setStandAloneMode (bool b)
 
bool startGlideModulation (GlideInfo &glideInfo)
 
uint32_t getModuleType ()
 
const char * getModuleName ()
 
void * getModuleHandle ()
 
void setModuleHandle (void *handle)
 
uint32_t getModuleIndex ()
 
void setModuleIndex (uint32_t index)
 
int32_t getPreferredModuleIndex ()
 
void setPreferredModuleIndex (uint32_t index)
 
ModuleCoreDatagetModuleData ()
 provides access to the core data: More...
 

Protected Member Functions

void calcAttackCoeff (double attackTime, double attackTimeScalar=1.0)
 
void calcDecayCoeff (double decayTime, double decayTimeScalar=1.0)
 
void calcReleaseCoeff (double releaseTime, double releaseTimeScalar=1.0)
 

Protected Attributes

bool noteOff = false
 for retriggering EG
 
bool retriggered = false
 for retriggering EG
 
double lastTriggerMod = 0.0
 for retriggering EG trigger detection
 
double sustainLevel = 1.0
 level, not time
 
double attackTime_mSec = 1.0
 att: is a time duration
 
double decayTime_mSec = 1.0
 dcy: is a time to decay from max output to 0.0
 
double releaseTime_mSec = 1.0
 rel: is a time to decay from max output to 0.0
 
double sampleRate = 0.0
 sample rate
 
double envelopeOutput = 0.0
 the current envelope output sample
 
double attackCoeff = 0.0
 exponential feedback coefficient
 
double attackOffset = 0.0
 TCO offset to allow proper attack/decay on [1, 0].
 
double attackTCO = 0.0
 TCO value for calculating offset.
 
double decayCoeff = 0.0
 exponential feedback coefficient
 
double decayOffset = 0.0
 TCO offset to allow proper attack/decay on [1, 0].
 
double decayTCO = 0.0
 TCO value for calculating offset.
 
double releaseCoeff = 0.0
 exponential feedback coefficient
 
double releaseOffset = 0.0
 TCO offset to allow proper attack/decay on [1, 0].
 
double releaseTCO = 0.0
 TCO value for calculating offset.
 
bool sustainOverride = false
 if true, places the EG into sustain mode
 
bool releasePending = false
 a flag set when a note off event occurs while the sustain pedal is held, telling the EG to go to the release state once the pedal is released
 
double incShutdown = 0.0
 shutdown linear incrementer
 
EGState state = EGState::kOff
 EG state variable.
 
- Protected Attributes inherited from SynthLab::ModuleCore
uint32_t moduleType = UNDEFINED_MODULE
 type of module, LFO_MODULE, EG_MODULE, etc...
 
const char * moduleName = nullptr
 module name must be set in derived constructor
 
void * moduleHandle = nullptr
 used for dynamically loading cores from DLLs
 
uint32_t moduleIndex = 0
 index of this core
 
int32_t preferredIndex = -1
 preferred index of this DYNAMIC core
 
ModuleCoreData coreData
 core strings (16) and mod knob labels (4)
 
bool standAloneMode = false
 flag for stand-alone mode of operation outside of SynthLab
 
std::unique_ptr< GlideModulatorglideModulator
 built-in glide modulator for oscillators
 

Detailed Description

Analog EG emulator.

Base Class: ModuleCore

  • Overrides the five (5) common functions plus a special getParameters() method to return a shared pointer to the parameters structure.
  • NOTE: These functions have identical names as the SynthModules that own them, however the arguments are different. ModuleCores use the CoreProcData structure for passing arguments into the cores because they are thunk-barrier compliant.
  • This means that the owning SynthModule must prepare this structure and populate it prior to function calls. The large majority of this preparation is done in the SynthModule constructor and is one-time in nature.

GUI Parameters: EGParameters

  • GUI parameters are delivered into the core via the thunk-barrier compliant CoreProcData argument that is passed into each function identically
  • processInfo.moduleParameters contains a void* version of the GUI parameter structure pointer
  • the Core function casts the GUI parameter pointer prior to usage

Access to Modulators is done via the thunk-barrier compliant CoreProcData argument

  • processInfo.modulationInputs
  • processInfo.modulationOutputs

Access to audio buffers (I/O/FM) is done via the thunk-barrier compliant CoreProcData argument

  • processInfo.inputBuffers
  • processInfo.outputBuffers
  • processInfo.fmBuffers

Construction: Cores follow the same construction pattern

  • set the Module type and name parameters
  • expose the 16 module strings
  • expose the 4 mod knob label strings
  • intialize any internal variables

Standalone Mode:

  • These objects are designed to be internal members of the outer SynthModule that owns them. They may be used in standalone mode without modification, and you will use the CoreProcData structure to pass information into the functions.

Module Strings, zero-indexed for your GUI Control:

  • ADSR, AR

ModKnob Strings, for fixed GUI controls by index constant

  • MOD_KNOB_A = "Start Lvl"
  • MOD_KNOB_B = "B"
  • MOD_KNOB_C = "C"
  • MOD_KNOB_D = "D"

Render:

  • renders into the modulation output array that is passed into the function via the CoreProcData structure and populates the arrays with index values of:
  • kEGNormalOutput normal EG output value
  • kEGBiasedOutput biased EG (sustain level subtracted out)
  • designed to operate in a block-fasion, knowing that only the first output sample will be used
Author
Will Pirkle http://www.willpirkle.com
Remarks
This object is included and described in further detail in Designing Software Synthesizer Plugins in C++ 2nd Ed. by Will Pirkle
Version
Revision : 1.0
Date
Date : 2021 / 04 / 26

Constructor & Destructor Documentation

◆ AnalogEGCore()

SynthLab::AnalogEGCore::AnalogEGCore ( )

Construction: Cores follow the same construction pattern.

simple default constructor

  • set the Module type and name parameters
  • expose the 16 module strings
  • expose the 4 mod knob label strings
  • intialize any internal variables

Core Specific:

  • implements two EG contours, ADSR and AR
  • you can add more here
  • sets up attack and release time constants based on analog capacitor charge/discharge rates

◆ ~AnalogEGCore()

virtual SynthLab::AnalogEGCore::~AnalogEGCore ( )
inlinevirtual

Destructor is empty: all resources are smart pointers

Member Function Documentation

◆ calcAttackCoeff()

void SynthLab::AnalogEGCore::calcAttackCoeff ( double  attackTime,
double  attackTimeScalar = 1.0 
)
inlineprotected

Calculate Time Coefficients

◆ calcDecayCoeff()

void SynthLab::AnalogEGCore::calcDecayCoeff ( double  decayTime,
double  decayTimeScalar = 1.0 
)
inlineprotected

Calculate Time Coefficients

◆ calcReleaseCoeff()

void SynthLab::AnalogEGCore::calcReleaseCoeff ( double  releaseTime,
double  releaseTimeScalar = 1.0 
)
inlineprotected

Calculate Time Coefficients

◆ doNoteOff()

bool SynthLab::AnalogEGCore::doNoteOff ( CoreProcData processInfo)
overridevirtual

Note-off handler for the ModuleCore.

  • parameters are accessed via the processInfo.moduleParameters pointer
  • MIDI note information is accessed via processInfo.noteEvent

Core Specific:

  • checks the sustain override flag and releases the note if needed
  • goes to release or off mode
Parameters
processInfois the thunk-barrier compliant data structure for passing all needed parameters
Returns
true if successful, false otherwise

Implements SynthLab::ModuleCore.

◆ doNoteOn()

bool SynthLab::AnalogEGCore::doNoteOn ( CoreProcData processInfo)
overridevirtual

Note-on handler for the ModuleCore.

  • parameters are accessed via the processInfo.moduleParameters pointer
  • MIDI note information is accessed via processInfo.noteEvent

Core Specific:

  • sets the finite state machine for another run
  • checks attack and decay scaling (only caclulated once per note-event)
Parameters
processInfois the thunk-barrier compliant data structure for passing all needed parameters
Returns
true if successful, false otherwise

Implements SynthLab::ModuleCore.

◆ getState()

virtual int32_t SynthLab::AnalogEGCore::getState ( )
inlineoverridevirtual

ModuleCore Overrides for EG Cores only

Reimplemented from SynthLab::ModuleCore.

◆ render()

bool SynthLab::AnalogEGCore::render ( CoreProcData processInfo)
overridevirtual

Renders the output of the module.

  • write modulator output with: processInfo.modulationOutputs->setModValue( ) Core Specific:
  • runs the finite state machine for the EG
  • runs the FSM on each sample interval, but only use the output of the first loop (see book)
Parameters
processInfothe thunk-barrier compliant data structure for passing all needed parameters
Returns
true if successful, false otherwise

Implements SynthLab::ModuleCore.

◆ reset()

bool SynthLab::AnalogEGCore::reset ( CoreProcData processInfo)
overridevirtual

Resets object to initialized state.

ModuleCore Overrides

  • parameters are accessed via the processInfo.moduleParameters pointer
  • initializes sample rate dependent stuff via processInfo.sampleRate
  • calculates intitial coefficients
  • sets initial state variables
Parameters
processInfothe thunk-barrier compliant data structure for passing all needed parameters
Returns
true if successful, false otherwise

Implements SynthLab::ModuleCore.

◆ setSustainOverride()

void SynthLab::AnalogEGCore::setSustainOverride ( bool  b)
overridevirtual

Sustain pedal handler for EG.

  • all EGs should implement this base class function
  • if turned off (pedal released), clears the pending release if exists
  • if turned on, sets the sustain pedal override to keep the EG stuck in the sustain state until the pedal is released

Reimplemented from SynthLab::ModuleCore.

◆ shutdown()

bool SynthLab::AnalogEGCore::shutdown ( )
overridevirtual

Shutdown handler for EG.

  • all EGs should implement this base class function
  • calculates shutdown amp increment based on current output value
Returns
true if successful, false otherwise

Reimplemented from SynthLab::ModuleCore.

◆ update()

bool SynthLab::AnalogEGCore::update ( CoreProcData processInfo)
overridevirtual

Updates the object for the next block of audio processing.

  • parameters are accessed via the processInfo.moduleParameters pointer
  • modulator inputs are accessied via processInfo.modulationInputs
  • mod knob values are accessed via parameters->modKnobValue[] Core Specific:
  • recalculates attack/decay/release coefficients if needed
  • checks the re-trigger modulation input to alter state machine
Parameters
processInfothe thunk-barrier compliant data structure for passing all needed parameters
Returns
true if successful, false otherwise

Implements SynthLab::ModuleCore.


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