Go Down

Topic: Arduino Realtime Audio Processing (Read 17222 times) previous topic - next topic


On compiling the program given in 'arduino_audio_loopback' i am getting an error as " TCCR2A not declared" . plz hlp...

No idea what program this is nor what you are trying to compile it on.
Please provide a link or post the code as an attachment or in code tags.
TCCR2A is a timer register in the ATmega 328 and others but it doesn't appear on things like the Duo.


Mike is probably right, as usual...
my guess would also go on...Maybe the wrong board/chip?!
As far as i remember that specific example will work on atmega 328, 168 and previous compatibles( 8, etc).
Even to use with the mega 2560 there might be the need for slight alterations in order to port the code( dont quote me on this, for this particular  example you mentioned though... Havent looked at the code for a while) , but am sure it does compile and work on the Uno/328,etc.
10 LET Loop=Infinite
20 GO TO 10


i am missing how did you record your audio sample? and how did you save it without a shield?
if you please can support me with a code. i really need it

Thanks in advance


Nice try whippoorwill but if you read the thread it is about processing audio not saving it.


I realize this is an old thread, if I should have started a new thread I'm sorry in advance.  I was just going through the reverb example and something jumped out at me:

Code: [Select]
  // set adc prescaler  to 64 for 19kHz sampling frequency
  cbi(ADCSRA, ADPS2);
  sbi(ADCSRA, ADPS1);
  sbi(ADCSRA, ADPS0);

Doesn't this set the prescaler to 8, not 64? So its sampling at 153kHz rather.  Was this intentional and the comment is just wrong? I attemped setting bits 2 and 1 and clearing pin 0 to set it to 64, but the output just isn't the same (much quieter for whatever reason).  Still going through the rest of the code to see what's going on with that just thought someone might have some insight.


Hi Edargelies,

yes, there is the preset error in the code. Marnaw has mentioned it in the previous forum for this topics, but it has not been reflected in the downloadable version.

here is the correct prescaler for the adc again
// set adc prescaler to 32 for 38 kHz sampling frequency
This sets preset divider to 32, thus to sampling rate of 38.5kHz, but if you use interrupt ISR(ADC_vect) when switching between the potentiometer (ADC0) and audio input (ADC1) channel, you get sampling rate 19.2kHz for each ADC channel. For this reason, one ADC channel seems to have a prescaler of 64, while the clock is divided by prescaler 32. The algorithm although does not use ADC interrupt for reading audio samples, whereas it sets the sampling rate with timer2 over interrupt ISR(TIMER2_OVF_vect). This is set to 31.25kHz, therefore getting 15,625kHz for single channel. It is important to have ADC interrupt set for higher frequency than frequency of timer2 interrupt (fadc > ftimer2), so that the ADC sample is always ready when the timer2 interrupt is called. It is mentioned in the previous forum as well:

the sampling rate is determined by the timer2 interrupt and set to 31,25KHz. Since we measure two inputs, the  audio signal and the pot position alternately, the effective sampling rate is 15,625 KHz.
With a prescaler of 64 and a 16000KHz Clock and 13 Cycles for one sample we get a sample rate of 16000 / 64 / 13 = 19,2 KHz
So the ADC is just ready before the sample is processed.
When you change the ADC preset divider to 32 as you did, getting 19.2kHz, fadc < ftimer2 and it brings distortion to the audio signal, because it often does not read new and ready samples. I can not notice much of the level difference and do not thing it should occur. Beside the distortion, it affects what frequencies you can read due to Nyquist Theorem, the usable ADC bit resolution, and ADC background noise.

Go Up