here's an explanation of digital oscillator implementation so you know why sawtooths aren't straight - from the beginning
you probably want several different waveforms on your synth. calculating the waveforms in realtime isn't cpu efficient. one way to lower cpu is to use lookup tables.
for example, using tables (arrays) of 2048 values, you "draw" the waveform in the array.
the oscillator's position in the wavecycle is tracked by an "index." every sample, the new oscillator phase position is calculated, and the array is referenced.
say your osc is at 90 degrees phase.. 90 is 1/4 of 360, so (1/4 of 2048 = 512) the 512th table value is used.
of course, the phase won't be on a whole number, so some form of interpolation is used to produce the exact value (say if the correct phase position translated to 511.57, you would interpolate the 511th and 512th array values).
here's where it gets tricky:
as you know, frequencies above nyquist alias, and as you know, complex timbres (eg. not sine waves) are composed of higher frequencies than the fundamental.
if you just "draw" a straight line for your saw, most notes above the fourth octave will have LOUD aliasing.
one solution to this is to use band limiting.
instead of "drawing" the waveform to the array, you build the waveform in the array using additive synthesis! you compose the sawtooth out of sines, up until the highest sine frequency below nyquist.
then, instead of using one array, many arrays are used, distributed across the pitch range.
when your synth is playing C#3, it is using a different lookup table than when playing C3.
if you play a very high note just below nyquist, it's array may only be composed of perhaps one or two harmonics.. oc at that frequency, most people aren't going to notice too abruptly.
the 'ripples' around the peaks are called the gibbs phenomenon. as you know, common contours like saw and triangle are created using simple mathematic methods that sum harmonics. mathematics is theoretic/ideal, and when you alter this ideal for band limiting, the ripples appear...
..eg. you're not composing a sawtooth by adding higher harmonics to infinity, it's only composed of ..say up to the 87th harmonic.. so those ripples are distortion created by subtracting the 88th and higher harmonics.
i know a lot of people have covered this all in the other thread, i wanted to put it together like this :p








