SynthLab SDK
SynthClock

This is a simple modulo counter whose mcounter member stores the value of the modulo counter as a unipolar ramp waveform and documented in the synth book. It is already setup for standalone operation because it does not require any members that are shared resources. You can easily create a primitive sawtooth waveform with it using the following code example:

// --- declare object
// --- set the oscillator frequency
// desired fo = 1kHz
// fs = 44.1kHz
clock.setFrequency(1000.0, 44100.0);
// --- reset the oscillator with the starging phase
// the starting phase varies from 0.0 to 1.0
// representing 0.0 to 2pi
clock.reset(0.0);
// --- SAMPLE PROCESSING LOOP
//
// --- generate an output sample
double ramp = clock.mcounter;
// --- use the synthfunction bipolar( ) to convert it to [-1, +1]
double bipolarRamp = SynthLab::bipolar(ramp);
// --- use the value somehow, for example write to an audio output
<your ouput sample> = bipolarRamp;
// --- advance the clock for the next sample period,
// modulo wrap the counter if needed
// ---

Notice the final line of code that advances and wraps the modulo counter. When you are working with one-shot oscillators that only play once through the oscillator waveform, PCM sample, or wavetable, you may use the wrapping flag to know when the counter has wrapped across the 1.0 boundary to stop the output. In this case you use two separate functions and generally you will use them in this order, checking the wrap at the top of the render() function, and advancing it at the end.

// check to see if the modulo counter has wrapped across 1.0
bool wrapped = oscClock.wrapClock();
// --- if wrapped, do something
if(wrapped)
; // stop the oscillator or other activity
// --- continue rendering ...
// --- end of loop, advance but don't wrap the clock
oscClock.advanceClock();
//


synthlab_4.png