February 2nd, 2013, 11:53 PM
Analyse Sound Input
I am new to C programming (I'm coming from php/python) and I want to do something pretty complicated :D
I want to have a led on a arduino (uno) board blinking to the beat of the music.
I need to know how to analyze the frequencies of an virtual audio input (loop-back from the output)
I don't want to have the a complete solution, but I would be happy about some keywords/links/libraries I could use to reach my goal!
February 16th, 2013, 04:13 AM
Arduinos have analog input lines. Maybe the out on a RCA plug could be fed into it . Adjusting the input volume so the most intense sould just reach 5 volts then you could directly read it and analysis it on the Arduino.
It do not think you need a complex analysis of the sound to detect the beat. Just turn on the led when it the input voltage overly 4.5 and off otherwise.
A hack that may or may not work is to hook up the microphone to a digital line and flash the led when the digital input reads as 1.
This might work because intensity of the sound of the drums may push
Input to max.
I am unsure of the output voltage level of a RCA plug or a head phone
Jack but check out this
Last edited by admiraln; February 16th, 2013 at 04:23 AM.
February 16th, 2013, 03:11 PM
Admiraln's suggestion I suggest is somewhat simplistic. The "beat" need not be the loudest audio component, simply flashing the LED at some arbitrary amplitude might not give a satisfactory response. Apart from that if that is all you wanted to do it would not be a particularly interesting project.
Ideally I would suggest that you have more than one led, and that those LEDs were attached to PWM capable outputs so that you can easily control brightness - that would create a far more interesting effect.
Anyhow, digital signal processing (DSP) is what you should be looking at. I might suggest that an Arduino if you are using the old Atmel AVR based version might be a little underpowered for this, but you can probably do something moderately interesting. If you are using the new ARM version, that is probably more than capable, although being a Cortex-M3 it does not have the more complete DSP capability of an M4. Nonetheless ARM do provide an optimised DSP library for Cortex-M as part of the CMSIS.
The most common algorithms used in DSP audio processing are Finite Impulse Response (FIR) filters, Infinite Impulse Response Filters (IIR), and Fast Fourier Transform (FFT).
You will also need to understand the concepts of the Shannon-Nyquist sampling theorem and issues of quantisation and aliasing (and anti-alising as a method of avoiding aliasing - that requires real electronic analogue filters rather than software).
In a simple implementation you might use a low-pass filter to extract the part of the signal likely to have the base drum beat in it (of course different kinds of music may have the "beat" component elsewhere in the spectrum), then use an envelope detector to extract the amplitude then either change the brightness of the LED proportionally or simply switch it at some threshold. Using multiple LEDs you could use low pass, band pass, and high pass filters for example to visualise the bass, middle and treble components.
I came across this site: http://musicdsp.org, which has a wealth of information and code. In particular here it specifically has a "Beat Detector", which I was please to discover does more or less exactly what I suggested above - LP Filter, Envelope Detector, and Schmitt trigger (a threshold detector with hysteresis). The code is in C++, so may be easily adapted to Arduino, but the use of floating point may make it far too slow since it does not have an FPU. It would be better to adapt it to a fixed point implementation.
A good fixed point C++ library can be found here, mostly you can just replace the float or double keyword with the fixed class defined by the library.
Another DSP library can be found here, though I am not sure how suited it might be to use on a low end embedded target, but it might be useful for modelling your ideas on a PC.
Other tools for developing signal processing algorithms are MATLAB and its free clones and near clones Octave, SciLab, and FreeMAT. These tools are useful for example for calculating the necessary filter coefficients to achieve a specific frequency response.
Another place to get information might be http://dspguru.com/ and http://www.dsprelated.com/.