Doing my own OSC code.

Before I re-invent the wheel, just checking if maybe someone already came up with a simple way to create an OSC that is fast to calculate using PWM output.

I'm not looking into any fancy stuff, but something that is simply fast. ;-) Otherwise I will try to come up with my own. I already got 6 voices of fixed-pitch no-envelope drum-sounds from a single ATmega328 Arduino chip, now I want to check how I could add some SAW sounds. (not pulse) Also without envelope, as I'm using 8-bit and the envelope sounds pretty bad with 8-bits. ;-)

Best Regards, WilliamK


Using DDS, it should be easy .. (saw or other waveform using wavetable) see there : or

Or maybe i didn't catch exactly what you want to do :)



Thanks bud, I already know how to output the audio, just need to figure out a nice way to create a sawtooth which is guided by midi without using too many cycles. ;-) I will brainstorm more in a few days, but thanks for now, I will check the links tomorrow.

Best Regards, WilliamK


But doing audio with DDS or a single sawthooth is done the same way .. ? no See here a AVR mini DDS function generator controlled by serial port but is done in ASM and the output is a R2R, you could try to recover some part of the code which seems to be quite optimized. Just take a look if it can help you to get some very fast code . (normally doing some ASM could be quite faster)

Best Regards, xray303

Oh, thanks bud, that's great, will take a closer look at it during the week. :drooling_face:


Generally you have two choices, look up table or calculation. With a saw tooth wave calculation is a simple addition operation and is quick and easy. But I am sure you know this so maybe I am missing the point.

You could put one cycle of the waveform in a wavetable and use phase accumulators. You can get by with less than one cycle if you exploit symmetry.

My preference is to use one cycle. This makes it easier to change waveforms.

My numerically controlled oscillator code is at

(* jcl*)