Skip to content
Igor Zinken edited this page Dec 27, 2018 · 1 revision

See <generators/synthesizer.h>

The Synthesizer is a built-in renderer for the SynthInstrument. Its function is to represent the contents of BaseAudioEvents as audio. It hooks into the SynthInstruments modules (ADSR, Oscillators, Arpeggiator) for its audio sculpting properties.

While the Synthesizer is a complete tool that can be used for instant live audio synthesis, you can also use it draw inspiration from to quickly get your custom synthesis aspirations underway.

Constructor / destructor

Synthesizer( SynthInstrument* instrument, int oscillatorNum )
~Synthesizer()

Create/dispose a Synthesizer instance. The given instrument will be used to fetch (both sequenced and live) AudioEvents from for rendering (these events should be of the BaseSynthEvent subclass). Given oscillatorNum determines the oscillator index of the Synthesizer instance (each of the instruments oscillators is represented by a unique Synthesizer instance, in other words: there is one Synthesizer per voice). These "child Synthesizers" are maintained inside the parent Synthesizer (see updateProperties()/createOscillator()) and as such each instrument only manages a single Synthesizer instance (the parent is defined by oscillator index 0 as there will always be at least one oscillator).

Upon destruction, all allocated Synthesizer instances for the extra oscillators are disposed.

Public methods

void render( AudioBuffer* outputBuffer, BaseSynthEvent* event )

Invoked by given _event_s mixBuffer()-method (which in turn is invoked by the Sequencer when the event is fit for playback in the current sequence / live playback). The output will be mixed into given outputBuffer.

void updateProperties()

Invoked by the SynthInstrument whenever the oscillator amount changes. This updates the amount of allocated Synthesizers accordingly.

void initializeEventProperties( BaseSynthEvent* event, bool initializeBuffers )

Invoked by given event whenever the Synthesizers waveform properties change. This can be used to cache properties for certain waveforms (for instance: the Karplus-Strong routine which requires a RingBuffer). initializeBuffers can be used to allocate said RingBuffer.

Protected methods

void createOscillator( int index )
void destroyOscillator( int index )

Create / destroy an internal child-Synthesizer instance to represent the referenced SynthInstruments oscillator at given index.

void tuneOscillator( int index, float baseFrequency )

Tunes the oscillator at given index around given baseFrequency. This takes into account the optional detuning specified by the OscillatorProperties for given oscillator.

RingBuffer* getRingBuffer( BaseSynthEvent* event, float frequency )
void initKarplusStrong( RingBuffer* ringBuffer )

Unique to synthesizing a Karplus-Strong-waveform. getRingBuffer() retrieves a RingBuffer for given event at given frequency. This leverages the BufferPool for performance optimizations. initKarplusStrong() flushes given ringBuffer and fills it up with noise.

Clone this wiki locally