Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Re: ATtiny2313 audio- w/source

2009-12-29 by BobGardner@aol.com

Hi Donald. I also have written avr c programs to play sine waves and other 'arbitrary' waveforms from a table and usually there is plenty of cpu left to even generate samples at 2 or 3 frequencies (3 part harmony?) and arithmetically add the samples together and stuff it into the OCR register to play thru the pwm out and an RC filter. The trick to playing that one cycle of arbitrary waveform back at different freqencies is: dont change the clock frequency or the sample frequency to speed it up and slow it down... (this is the obvious method of course), but you advance a pointer through the waveform table by a non integer step size. How to do that wasnt obvious either. Its easy to see that if you play every other sample, you get to the end of the table twice as fast, so the waveform is looping one octave higher. Playing the next sample, then skip a sample is like playing every 1.5 samples, which is about a 5th higher. The trick is have a 'frequency increment' that has an integer part and a fractional part. This increment is added to the waveform pointer and the sample that the integer part is pointing to is played. As the freq gets higher, the waveform looks blocky-er, and it should sound terrible, but the output lowpass filter just lets the basic waveform thru. This is described in Hal Chamberlin's book 'Musical Applications of Microprocessors'. Some folks call it the 'phase accumulator' waveform generation technique. The Fairlight synthesizer used this (back in the 80s?!?) and used 6800s, so an avr running running way faster ought to be able to do it too.







[Non-text portions of this message have been removed]

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.