hot to build oscillators - about ripples

VST, AU, AAX, CLAP, etc. Plugin Virtual Instruments Discussion
Post Reply New Topic
RELATED
PRODUCTS

Post

sorry for starting a new thread.. for clarity :p

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 :)
you come and go, you come and go. amitabha neither a follower nor a leader be tagore "where roads are made i lose my way" where there is certainty, consideration is absent.

Post

Can i nitpick ? :D
EDIT: Nevermind. I read it again and realized i read a few things wrong. I only had one major objection but after thinking for a while i realized i was wrong about that too. :hihi:
Last edited by jupiter8 on Wed Oct 29, 2008 6:26 pm, edited 1 time in total.

Post

thread resurrection :o
not 'ere nowadays :(

interviews with cool people

Post

And all this time I though the Gibbs phenomenon was referring to "Saturday Night Fever"-era Bee Gees! :wink:

Due to the fact that I'm slowly working through Curtis Roads' "Computer Music Tutorial" I actually kinda sorta know what you're talking about.

Post

and here are some auditory and visual proofs why these ripples are our friends:

a naively synthesized sawtooth wave:

www.rs-met.com/democlips/NaiveSaw880Hz.wav

that's how it looks on an oscilloscope:

Image
Image

that's how it looks on a spectrum analyzer:

Image
Image



...and now an anti-aliased sawtooth:

www.rs-met.com/democlips/AntiAliasedSaw880Hz.wav

that's how it looks on an oscilloscope:

Image
Image

that's how it looks on a spectrum analyzer:

Image
Image


whoever wants to argue that (anti)aliasing is just a marketing buzzword or some theoretical BS - just listen. it's a very real and audible thing. ...since theory and practice are actually the same (thereotically :wink: )

xoxos explanation on table lookup synthesis is spot on. maybe it should be mentioned that there are other methods to implement oscillators which don't need tables - additive and minBlep come to mind
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

That makes sense. Thanks xoxos.

Post

i'll chime in on that one too :)

there's no "one correct way to do things," (imo!) and the array of techniques really is like a garden, each with pluses and minuses.. eg. i use a partial gibbs phen. reduction to keep a bit of edge in the timbre, and there's hundreds of ways to do that.

i learned this last month :) too bad i wasn't on speaking terms with any screen recorders to document these things (aliasing of non-bandlimited oscs, w/ and w/o gibbs) maybe the next developer who goes through this for the first time will have that facility :)
you come and go, you come and go. amitabha neither a follower nor a leader be tagore "where roads are made i lose my way" where there is certainty, consideration is absent.

Post

xoxos wrote:if you just "draw" a straight line for your saw, most notes above the fourth octave will have LOUD aliasing.
That's why early keyboards with ROM-waveforms like Korg DW-8000 or Ensoniq ESQ-1 had more than one version of a wave in their ROM - one for each octave. The higher the octave, the more "smoothed" the wave was, that's why they sounded so good even with low sample rates / bitdepths.

But the main problem is not the "straight line" you are writing, but to fast value changes on drawn waveforms: an exact square or saw waveform with jumps from max to min from one sample to the next will cause heavy aliasing, because the DACs can't do that (no analog circuit can do this too).

Post

WOK wrote: the main problem is not the "straight line" you are writing, but to fast value changes on drawn waveforms: an exact square or saw waveform with jumps from max to min from one sample to the next will cause heavy aliasing, because the DACs can't do that (no analog circuit can do this too).
yes on 1: the main problem is the jump in the signal
but no on 2: the problem is not that the DAC cannot jump from one voltage to another on time - it is merely the issue that the jump in the underlying continuous time signal occurs at non-integer sample times. that will introduce some kind of pitch period jitter - some periods are longer/shorter than others.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

bookmarked.
member of the guild of professional dilettantes.

Post

Robin from www.rs-met.com wrote:it is merely the issue that the jump in the underlying continuous time signal occurs at non-integer sample times. that will introduce some kind of pitch period jitter - some periods are longer/shorter than others.
I was about to joke about rounding the wave cycle to the nearest int and just do 1:1 playback, but now I wonder at what sample rate that would actually be doable.
At 44100, A6 (1760Hz) gets you a wave cycle of 25.056818 samples. Rounding to 25 is an error of 0.2268%.

At 192000 the cycle is 109.090909 samples, rounding to 109 is an error by 0.0833%

Post

Rock Hardbuns wrote:
Robin from www.rs-met.com wrote:it is merely the issue that the jump in the underlying continuous time signal occurs at non-integer sample times. that will introduce some kind of pitch period jitter - some periods are longer/shorter than others.
I was about to joke about rounding the wave cycle to the nearest int and just do 1:1 playback, but now I wonder at what sample rate that would actually be doable.
At 44100, A6 (1760Hz) gets you a wave cycle of 25.056818 samples. Rounding to 25 is an error of 0.2268%.

At 192000 the cycle is 109.090909 samples, rounding to 109 is an error by 0.0833%
my above statement was a bit imprecise: it's of course not the period of the signal that jitters but the distance (in samples) between those jumps. rounding the period to the next integer number of samples? and then living with wrong pitches? no - not acceptable for me.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Is there an advantage to skipping the work around and just render the waveforms in real time if you have a lot of cpu resources? Such as dedicated DSP chips?
Aiynzahev-sounds
Sound Designer - Soundsets for Pigments, Repro, Diva, Virus TI, Nord Lead 4, Serum, DUNE2, Spire, and others

Post

not sure what you mean with workaround. the mip-mapping approach? actuallly, i consider this not as workaround but as a bona fide solution (if coupled with 2x oversampling). doing additive synthesis in realtime is by orders of magnitude more expensive. a 100 Hz sawtooth with full spectrum up to 20 kHz requires 200 sines to be calculated and summed. 400 sines are needed for a 50 Hz sawtooth.

edit: even if you have a lot of CPU resources - that's not a reason to waste them. and if you have a fixed amount of resources which you can schedule, you can certainly find other aspects of the synth where you can spend them to actually improve quality by using more processing power.

edit2: i was assuming that we are talking strictly about creation of periodic waveforms here. the additive approach, however, opens much more opportunities. you could directly compose inharmonic spectra
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post Reply

Return to “Instruments”