Efficiency - A few notes about optimizing CPU usage in your synth design

PC's are never fast enough, the better they get, the more we ask of them.  10 years ago software synthesizers were confined to University Computers.  Today we expect to run 10 soft-synths at once on our home PC.  The more efficient you can make your synth, the better.

CPU use is very dependant on a synth's structure, sometimes there are 2 ways to do something, with vastly different results.

Example case... The volume control section of a synth, It has a VCA to apply a volume envelope (pretty standard stuff)

efficiency1.gif (3883 bytes)

You want your synth to have a volume control, the 'obvious' way, just add a second VCA, and hook up a slider...

efficiency2.gif (4935 bytes)

This is not the most efficient method, both VCA's operate at audio-rate (usually 44.khz), so your synth now does an extra 44,100 calculations per second!.

Better way...

efficiency3.gif (5067 bytes)

What's the difference?. Instead of controlling the audio volume directly, we are controlling the ADSR level (which in turn controls the volume).
  Now, there no obvious improvement here, just a different way of doing the same thing right?.

What is not obvious is the effect on SynthEdit's automatic 'power saving' mode....

CPU 'Power Saving'

If you observe the slider's output on the Oscilloscope, you will see it is outputting a 'flat-line' signal..

efficiency4.gif (3221 bytes)

In other words, when you aren't moving the slider, it's not doing any real work, SynthEdit puts it to 'sleep', whereby it is ignored by the CPU, and uses absolutely no CPU resource.
  The same rule applies to the ADSR, while you hold a note (the sustain segment), the ADSR goes into 'sleep-mode' too.  It's also outputting a 'flat-line' signal.   Looking at the 'Level Adjust' module, you see that for much of the time, both it's inputs will be 'flat-line', inactive, signals.  Therefore it  also enters 'power-save' mode.
  That just leaves the Oscillator, one VCA, and the 'Sound Out' doing any real work.   You've effectively eliminated one entire module for 'free'.

Additional improvement. The ADSR has a built in level adjuster, it's 'Overall Level' plug. Using that instead of the external 'Level Adjust' eliminates annother module...

efficiency5.gif (4648 bytes)

Each 'wire' on you SynthEdit screen represents an audio buffer of around 100 samples (that's 400 bytes of memory). So this final version not only saves 44,100 math calculations every second, it also saves a further 88,200 sample copies per second through using less wires.

Well, I hope that made sense. Note that this example also applies when adding velocity sensitivity, or panning to your synth.

Another way of looking at it

Your synth handles two types of signal:

1 - 'Audio Signals' (the Oscillator, VCA, and Sound Out)

2 - 'Control Signals' (ADSR, Level Slider)

Adding modules to the 'audio path' is 'expensive' in terms of CPU usage.  Adding modules to the 'control path' is often 'cheap' or even free.  Signals originating from sliders, and signals that don't change often, like the 'MIDI to CVs' Pitch and Velocity outputs, can be considered 'Control' signals'.
An ADSR is somewhere in-between, during its Attack and Decay segments, it's generating 'Audio Rate' data, during the Sustain section, it's generating a 'flat-line', Control-Rate signal.