I am working on a project to make a speaker with reactive lighting. I need to be able to sample stereo audio at a decent rate for songs. The audioRead ()
function can do about 8 kHz
and I have heard you can push it up till 35 kHz
but than you can only use it for mono and you cannot use the arduino for anything else.
Someone recommended that I use an ADC. What can it do for me?
Is the arduino's operating speed a limitation?
If not the arduino which other micro-controller is suitable for this purpose.
2 Answers 2
If you are only interested in getting a reading of the sound intensity,
then 8 kHz may be enough. You can also convert the signal to mono
using a pair of resistors. If you want the Arduino to do other stuff
while taking the analog readings, then you should forego analogRead()
and access the ADC directly. This is more involved that typical Arduino
programming, as it involves configuring the ADC at low-level, in "free
running mode". In this mode the ADC operates in an autonomous way, and
send you an interrupt every time a sample is ready.
I have written a program that does something similar: it samples an analog input at 9.6 kHz (104 μs per sample) an periodically sends the reading through the serial port: sound-meter.ino. You can probably adapt it for driving LEDs instead of the serial port.
-
Thank you. I will do it using this method this time but is there any way I could do stereo and/or 50KHz +? Just curious.A.Shetye– A.Shetye2019年08月09日 15:02:03 +00:00Commented Aug 9, 2019 at 15:02
-
@A.Shetye: For stereo, you could add something like
ADMUX ^= _BV(MUX0);
to the ISR in order to alternate between the A0 and A1 inputs, but then the per-channel sampling rate would be half as fast. For faster sampling, you could set the prescaler to 16 and get 76.9 kHz mono or half that in stereo, but I do not guarantee the Arduino will keep up with the processing load. A prescaler lower than 16 will likely give very noisy readings.Edgar Bonet– Edgar Bonet2019年08月09日 17:30:34 +00:00Commented Aug 9, 2019 at 17:30
The first part of the speed limitation on the Arduino is that the ADC is painfully slow. If you had a faster ADC chip then you could take analog readings faster so you can take more per second. Once you're over that threshold then the next limitation you run into is the speed with which Arduino can communicate with that ADC. So make sure you get something fast (like SPI).