SynthLab SDK
SynthLab::WSOscillator Class Reference

This is an aggregate of 4 wavetable oscillators being controlled with the single object that appears as an oscillator to the voice objecgt. More...

#include <wsoscillator.h>

Inheritance diagram for SynthLab::WSOscillator:
SynthLab::SynthModule

Public Member Functions

 WSOscillator (std::shared_ptr< MidiInputData > _midiInputData, std::shared_ptr< WSOscParameters > _parameters, std::shared_ptr< WavetableDatabase > _waveTableDatabase, uint32_t blockSize=64)
 Constructs Wave Sequencing Oscillator module. More...
 
virtual ~WSOscillator ()
 
virtual bool reset (double _sampleRate) override
 Resets object to initialized state. More...
 
virtual bool update () override
 Updates the the two active oscillators. More...
 
virtual bool render (uint32_t samplesToProcess=1) override
 Renders audio from the selected core. More...
 
virtual bool doNoteOn (MIDINoteEvent &noteEvent) override
 Calls the note-on handler for all cores on all four internal oscillators so that they will be running during the round-robin render phase. More...
 
virtual bool doNoteOff (MIDINoteEvent &noteEvent) override
 Calls the note-off handler on four internal oscillators. More...
 
virtual bool startGlideModulation (GlideInfo &glideInfo) override
 Calls the startGlideModulation handler for the first two oscillators; these will always be the first two in the sequence. More...
 
void makeWaveStringMap ()
 Creates a mapping that links the waveform names to their underlying cores and oscillators. More...
 
void mixOscBuffers (std::shared_ptr< AudioBuffer > oscBuffers, uint32_t samplesInBlock, double scaling)
 Helper function to mix oscillator buffers together during render() phase into the audio buffers on this SynthModule. More...
 
bool oscIsFree (uint32_t oscIndex, uint32_t waveAIndex, uint32_t waveBIndex)
 Finds out if oscillator has the same core and waveform index as the selection. More...
 
bool oscHasWaveIndex (uint32_t oscIndex, uint32_t waveIndex)
 Finds out if oscillator has the same waveform index as the selection. More...
 
void setNewOscWaveA (uint32_t oscIndex, uint32_t waveAIndex, double oscAMixCoeff)
 Change oscillator's waveform to Wave A. More...
 
void setNewOscWaveB (uint32_t oscIndex, uint32_t waveBIndex, double oscBMixCoeff)
 Change oscillator's waveform to Wave B. More...
 
std::shared_ptr< ModulatorsgetWSOscModulationInput (uint32_t oscIndex)
 Gets the modulation input array pointer from one of the internal oscillators. More...
 
std::shared_ptr< WTOscillatorgetWTOscillator (uint32_t index)
 Provides direct access to internal oscillator objects. More...
 
void updateActiveOscillators ()
 Updates the two active oscillators during the update() phase. More...
 
- Public Member Functions inherited from SynthLab::SynthModule
 SynthModule (std::shared_ptr< MidiInputData > _midiInputData)
 Constructs a SynthModule. More...
 
virtual ~SynthModule ()
 Removes cores, if any.
 
virtual bool initialize (const char *_dllDirectory)
 
virtual int32_t getState ()
 
virtual bool shutdown ()
 
std::shared_ptr< ModulatorsgetModulationInput ()
 
std::shared_ptr< ModulatorsgetModulationOutput ()
 
std::shared_ptr< AudioBuffergetAudioBuffers ()
 
void setUnisonMode (double _unisonDetuneCents, double _unisonStarPhase)
 
void setFMBuffer (std::shared_ptr< AudioBuffer > pmBuffer)
 
void clearFMBuffer ()
 
virtual bool getModuleStrings (std::vector< std::string > &moduleStrings, std::string ignoreStr="")
 Gets a std::vector of Module Strings. More...
 
virtual bool getModuleStrings (uint32_t coreIndex, std::vector< std::string > &moduleStrings, std::string ignoreStr)
 Gets a std::vector of Module Strings from a particular core. More...
 
virtual bool getAllModuleStrings (std::vector< std::string > &moduleStrings, std::string ignoreStr)
 Gets a std::vector of all Module Strings concatenated from all cores in succession. More...
 
virtual bool getModKnobStrings (std::vector< std::string > &modKnobStrings)
 Gets a std::vector of Mod Knob label strings for the selected core. More...
 
virtual bool getModKnobStrings (uint32_t coreIndex, std::vector< std::string > &modKnobStrings)
 Gets a std::vector of Mod Knob label strings for a given core; if the core cannot be found returs the mod knob labels of the module itself. More...
 
virtual bool getModuleCoreStrings (std::vector< std::string > &moduleCoreStrings)
 Gets a std::vector of the names of the four cores in this module. More...
 
virtual bool addModuleCore (std::shared_ptr< ModuleCore > core)
 adds a module core to the module's set of four More...
 
virtual uint32_t getSelectedCoreIndex ()
 get the index of the selected core More...
 
virtual bool selectModuleCore (uint32_t index)
 Select a core. More...
 
virtual bool selectDefaultModuleCore ()
 Select the default core, which is always the first in the list. More...
 
virtual void packCores ()
 packs the cores into non-null ordering
 
virtual bool clearModuleCores ()
 Clears out the module core pointer list. More...
 
virtual void setStandAloneMode (bool b)
 Sets the stand-alone mode flag on all cores. More...
 

Protected Attributes

std::shared_ptr< WSOscParametersparameters = nullptr
 
std::shared_ptr< WTOscillatorwaveSeqOsc [NUM_WS_OSCILLATORS] = { nullptr, nullptr, nullptr, nullptr }
 
std::shared_ptr< WTOscParameterswaveSeqParams [NUM_WS_OSCILLATORS] = { nullptr, nullptr, nullptr, nullptr }
 
uint32_t activeOsc [2] = { 0, 1 }
 active pair
 
int32_t currSoloWave = -1
 
double oscMixCoeff [NUM_WS_OSCILLATORS] = { 0.0, 0.0, 0.0, 0.0 }
 
bool initRoundRobin = true
 
std::vector< WaveStringDatawaveStringFinder
 
- Protected Attributes inherited from SynthLab::SynthModule
std::shared_ptr< ModulatorsmodulationInput = std::make_shared<Modulators>()
 
std::shared_ptr< ModulatorsmodulationOutput = std::make_shared<Modulators>()
 
std::shared_ptr< MidiInputDatamidiInputData = nullptr
 
std::shared_ptr< AudioBufferaudioBuffers = nullptr
 
std::unique_ptr< GlideModulatorglideModulator
 
std::shared_ptr< AudioBufferfmBuffer = nullptr
 
std::shared_ptr< ModuleCoremoduleCores [NUM_MODULE_CORES]
 
std::shared_ptr< ModuleCoreselectedCore = nullptr
 
ModuleCoreData moduleData
 modulestrings (16) and mod knob labels (4) More...
 
double unisonDetuneCents = 0.0
 
double unisonStartPhase = 0.0
 
bool standAloneMode = false
 
CoreProcData coreProcessData
 
std::string dllDirectory
 

Detailed Description

This is an aggregate of 4 wavetable oscillators being controlled with the single object that appears as an oscillator to the voice objecgt.

  • demonstrates grouping objects together while still safely sharing data
  • demonstrates modifying and calling functions on these objects
  • does NOT implement the ModuleCores - this is a single object that is self-contained

Base Class: SynthModule

  • Overrides the five (5) common functions plus a special getParameters() method to return a shared pointer to the parameters structure.

Databases: WavetableDatabase

  • Accesses and holds shared pointer to WavetableDatabase
  • passes this database to internal oscillators which then registers theirwavetables with the database

GUI Parameters: WTOscParameters

  • getParameters() function allows direct access to std::shared_ptr<WTOscParameters>

std::shared_ptr<WTOscParameters> getParameters()

  • call the getParameters() function
  • set the parameters in the WTOscParameters structure with new values, typically from a GUI To apply these new parameters either:
  • (a) call the module's update() function OR
  • (b) call the render() function which in turn calls the update() method.

Ordinarily, this operation happens just prior to calling the render() function so that is the preferred method of operation to avoid multiple calls to the update() function, which is usually the most CPU intensive function of the SynthModule.

Access to Modulators

  • std::shared_ptr<Modulators> getModulationInput()
  • std::shared_ptr<Modulators> getModulationOutput()

Access to audio buffers (I/O)

Reads:

  • Modulation Input Values (modulators)

Writes:

Construction:

(1) For use within a synth project, the constructor is specialized to use shared recources for:

The owning object (SynthVoice for the SynthLab projects) must pass these valid pointers to the object at construction time. Typically the engine or voice will be the primary synthesizers of these resources. See the 2nd Edition Synth Book for more information.

(2) Standalone:

To use in standalone mode, call the constructor with the shared resoure pointers as null:

WTOscillator(nullptr, nullptr, nullptr, 64);

In standalone mode, the object creates and maintains these resources:

  • MidiInputData: this has no read access so you cannot access its data. Ordinarily, you pass this shared pointer into the object so that it has access to the current MIDI input data. The object does not write data into this resource, so it is functionally non-opeational.
  • WavetableDatabase: this has no read access so you cannot access its data. Ordinarily, you pass this shared pointer into the object so that it can share these resources with other like-objects. However, in standalone operation the object will create the database and then register its wavetables with the object and use this local database for rendering operations. The code is the same for all operations so the object does not know if it is using a local database or a shared one.
  • WTOscParameters: in standalone mode only, these are synthesized locally on the object, and then the owning object may obtain a shared pointer to them to read/write the parameters directly.

Render:

  • renders into its own AudioBuffers object; see SynthModule::getAudioBuffers()
  • renders stereo by default. For wavetables this really means dual-mono where the left buffer is copied to the right.
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

◆ WSOscillator()

SynthLab::WSOscillator::WSOscillator ( std::shared_ptr< MidiInputData _midiInputData,
std::shared_ptr< WSOscParameters _parameters,
std::shared_ptr< WavetableDatabase _waveTableDatabase,
uint32_t  blockSize = 64 
)

Constructs Wave Sequencing Oscillator module.

One and only specialized constructor; pointers may be null for stanalone

  • See class declaration for information on standalone operation
Parameters
_midiInputDatashared MIDI input resource; may be nullptr
_parametersshared GUI and operational parameters; may be nullptr
_waveTableDatabaseshared wavetable resource; may be nullptr
blockSizethe synth block process size in frames (stereo)
Returns
the newly constructed object

◆ ~WSOscillator()

virtual SynthLab::WSOscillator::~WSOscillator ( )
inlinevirtual

Destructor is empty: all resources are smart pointers

Member Function Documentation

◆ doNoteOff()

bool SynthLab::WSOscillator::doNoteOff ( MIDINoteEvent noteEvent)
overridevirtual

Calls the note-off handler on four internal oscillators.

Returns
true if successful, false otherwise

Implements SynthLab::SynthModule.

◆ doNoteOn()

bool SynthLab::WSOscillator::doNoteOn ( MIDINoteEvent noteEvent)
overridevirtual

Calls the note-on handler for all cores on all four internal oscillators so that they will be running during the round-robin render phase.

Returns
true if successful, false otherwise

Implements SynthLab::SynthModule.

◆ getWSOscModulationInput()

std::shared_ptr< Modulators > SynthLab::WSOscillator::getWSOscModulationInput ( uint32_t  oscIndex)

Gets the modulation input array pointer from one of the internal oscillators.

functions for accessing oscillators and modulation inputs

Parameters
oscIndexindex in oscillator array

◆ getWTOscillator()

std::shared_ptr< WTOscillator > SynthLab::WSOscillator::getWTOscillator ( uint32_t  oscIndex)

Provides direct access to internal oscillator objects.

Parameters
oscIndexindex in oscillator array

◆ makeWaveStringMap()

void SynthLab::WSOscillator::makeWaveStringMap ( )

Creates a mapping that links the waveform names to their underlying cores and oscillators.

functions for dealing with multiple oscillators

  • when the user selects a waveform, this decodes the oscillator and core that will be needed for rendering
Returns
true if successful, false otherwise

◆ mixOscBuffers()

void SynthLab::WSOscillator::mixOscBuffers ( std::shared_ptr< AudioBuffer oscBuffers,
uint32_t  samplesInBlock,
double  scaling 
)

Helper function to mix oscillator buffers together during render() phase into the audio buffers on this SynthModule.

Parameters
oscBuffersaudio buffers to add to the audio output buffers
samplesInBlocksamples to add
scalinga multiplier/divider used for scaling during mixing

◆ oscHasWaveIndex()

bool SynthLab::WSOscillator::oscHasWaveIndex ( uint32_t  oscIndex,
uint32_t  waveIndex 
)

Finds out if oscillator has the same waveform index as the selection.

Parameters
oscIndexindex in oscillator array
waveIndexindex of waveform for the wave-string-finder
Returns
true if oscillator matches the criteria, false otherwise

◆ oscIsFree()

bool SynthLab::WSOscillator::oscIsFree ( uint32_t  oscIndex,
uint32_t  waveAIndex,
uint32_t  waveBIndex 
)

Finds out if oscillator has the same core and waveform index as the selection.

functions for setting or swapping oscillators

Parameters
oscIndexindex in oscillator array
waveAIndexindex of waveform A for the wave-string-finder
waveBIndexindex of waveform B for the wave-string-finder
Returns
true if oscillator matches the criteria, false otherwise

◆ render()

bool SynthLab::WSOscillator::render ( uint32_t  samplesToProcess = 1)
overridevirtual

Renders audio from the selected core.

  • Calls the update function first - NOTE: owning object does not need to call update()
  • samples to process should normally be the block size, but may be a partial block in some cases due to OS/CPU activity.
Parameters
samplesToProcessthe number of samples in this audio block
Returns
true if successful, false otherwise

Implements SynthLab::SynthModule.

◆ reset()

bool SynthLab::WSOscillator::reset ( double  _sampleRate)
overridevirtual

Resets object to initialized state.

SynthModule Overrides

  • call once during initialization
  • call any time sample rate changes (after init)
  • create string map for waveform names
Parameters
_sampleRatethe current sample rate in Hz
Returns
true if successful, false otherwise

Implements SynthLab::SynthModule.

◆ setNewOscWaveA()

void SynthLab::WSOscillator::setNewOscWaveA ( uint32_t  oscIndex,
uint32_t  waveAIndex,
double  oscAMixCoeff 
)

Change oscillator's waveform to Wave A.

Parameters
oscIndexindex in oscillator array
waveAIndexindex of waveform A for the wave-string-finder
oscAMixCoeffmixing coefficient for the waveform to try to keep levels consistent across oscillators and waveforms

◆ setNewOscWaveB()

void SynthLab::WSOscillator::setNewOscWaveB ( uint32_t  oscIndex,
uint32_t  waveBIndex,
double  oscBMixCoeff 
)

Change oscillator's waveform to Wave B.

Parameters
oscIndexindex in oscillator array
waveBIndexindex of waveform B for the wave-string-finder
oscAMixCoeffmixing coefficient for the waveform to try to keep levels consistent across oscillators and waveforms

◆ startGlideModulation()

bool SynthLab::WSOscillator::startGlideModulation ( GlideInfo glideInfo)
overridevirtual

Calls the startGlideModulation handler for the first two oscillators; these will always be the first two in the sequence.

Returns
true if successful, false otherwise

Reimplemented from SynthLab::SynthModule.

◆ update()

bool SynthLab::WSOscillator::update ( )
overridevirtual

Updates the the two active oscillators.

  • watches the output of the wave sequencer to know when to switch to the next pair of oscillators
  • forwards some information to the oscillators as part of its own update phase
Returns
true if successful, false otherwise

Implements SynthLab::SynthModule.

◆ updateActiveOscillators()

void SynthLab::WSOscillator::updateActiveOscillators ( )

Updates the two active oscillators during the update() phase.

part of update() phase; this is only for the two oscillators that may be playing

Returns
true if successful, false otherwise

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