I'm trying to work on a reactive lighting project and I'm confused about a couple topics when it comes to sampling audio.

I want to be able to have RGB reactive lighting controlled by a microcontroller sampling audio from a standard audio jack (such as from a phone). I'm planning to just use a mono sound audio jack to simplify everything.

My main concern is how to actually sample the audio. My understanding is that from a phone audio jack the signal is already in analog form, and needs to be sampled again at the microcontroller, and I figure I would need a sampling rate of around 20kHz to capture most of the frequencies in the audio.

In the past I've used Arduinos for projects that sample at ~8kHz with the standard audioread() function. I was able to use a library I previously had and interrupts in C to achieve a sampling rate of around ~10kHz which isn't much better. Would I just need to purchase faster hardware or is there a way to increase the sampling rate on cheaper microcontrollers?

I'm also worried that even if I can sample the signal fast enough, that the processing for my reactive lighting may take too long and slow the sampling down. I plan on using FFT and calculate a dominant frequency from the last X samples (to be determined based on sampling rate) and quantize it into different colors. What sort of timing limitations are there here? If I know the sampling rate I can calculate the time between samples, but is there a way to calculate the time it takes to execute a loop of the reactive lighting algorithm? If I could do that I would be able to see if my algorithim is fast enough to keep up.

I'm trying to sort all this out before I go and purchase any parts for this project, so any help is appreciated.

  • 1
    \$\begingroup\$ Some suggestions: you could purchase a dedicated ADC which can sample faster than 10 kHz; running and FFT on an Uno might be possible but not recommended (faster µCs can do it fine though), a faster algorithm would be to filter into different bands like a graphic equalizer. \$\endgroup\$ – loudnoises May 10 '18 at 22:30
  • 1
    \$\begingroup\$ Don't try to get all functions out of one IC. Get a fast ADC with 16 bit resolution, an MPU fast enough to do basic DSP functions like FFT and quantization. You need an interface from the MPU to drive your lights. You need to power all of this stuff. Add test code and a few buttons to do predictable sequences to validate your code and hardware. \$\endgroup\$ – Sparky256 May 10 '18 at 22:48
  • \$\begingroup\$ The traditional 'sound-to-light' units used three band-pass filters - bass, middle and high - and they didn't have to be very precise. The outputs of these were fed to peak envelope detectors and these used to trigger the lights. You could feed the peak detectors into the micro and do some magic on it there. It seems a lot less trouble than coding everything. \$\endgroup\$ – Transistor May 10 '18 at 22:49
  • \$\begingroup\$ I think you'll need to carefully develop some quantitative data here. How often do you expect to update the colors of the lights? What's that rate? What frequencies of interest do you have, in particular? Smallest? Largest? (I used a Cygnal [bought by SiLabs a while ago] C8051F06x device. These include a 1 MHz 16-bit ADC with DMA. Fast and good ADC. Horrible CPU to process data coming in that fast, though. In my case, I sampled at full rate but in bursts at my measurement sample rate of outputting at 20 Hz.) \$\endgroup\$ – jonk May 11 '18 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.