Pages: [1] 2   Go Down
Author Topic: Driving LEDs with audio  (Read 3722 times)
0 Members and 1 Guest are viewing this topic.
Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a continuation of a previous post I started two months ago.  The basics and requirements of the project are still the same: light up LEDs based on notes played on a 67 key instrument.

The original idea, which also will not work for various reasons, was to wire each key with a sensor.  The next idea was to use an MSGEQ7 and process the audio signal, however that only gives me 7 frequency bands.  I need way more than that.

So I'm back at square one here.  Basically I need to sample the audio coming off of this instrument (electret microphone and amplifier) and light up LEDs that correspond to that note that was just played (or something close enough) - I'll be driving an addressable LED strip.  A suggestion was made to do something with FFT and pull out the frequencies that way.  Here's my problem: I have to keep it either within the Arduino's capabilities, or some other cost equivalent solution.  I recently saw a real life demo of someone using a PIC with an electret mic to do this - no Arduino used.  I just don't know what or how to do this.  Sample the audio, process then spit out data for an addressable strip ... oy vey.

Imagine a musical keyboard if you will, then place a strip of LEDS behind it so that it would face the audience.  As the player plays, the strip reacts and lights up that note, or notes that were played.  In our case, it's not a keyboard, but a wooden instrument.  And I completely realize that by hitting one note, it will always resonate those nearby and may very well cause nearby ones to also trigger.  That's fine, it can add to the light effect as well.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34547
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And I completely realize that by hitting one note, it will always resonate those nearby and may very well cause nearby ones to also trigger.
No what you will get is octave missrecognition, with say all the Cs lighting up. And that is if you are lucky.
There are many sorts of PIC many are much more powerful and have more memory than an arduino. 
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you try to google "arduino FFT"?
It should bring you to my post  smiley-mr-green
http://fftarduino.blogspot.com/2011/02/color-organ-spectrum-analyzer-on.html

Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did search for 'arduino fft' or some variant of it, but I did not come across your site.  Thank you for linking it.  Without video to see what it really does, I can't tell if it's what I'm looking for.  Any chance you can post that schematic with a white background instead of black?  It makes reading labels and lines hard.
Logged

Boston Suburbs
Offline Offline
God Member
*****
Karma: 16
Posts: 955
I am above your silly so-called "Laws", Mister Ohm.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://blurtime.blogspot.com/2010/11/arduino-realtime-audio-spectrum.html



That's 64 bands, Realtime, all done with Arduino.. including generating the realtime VIDEO.  LED's will take a lot less resources!

Not only can the Arduino do a Realtime FFT, it can also generate NTSC video while doing it.  I used a simple single transistor amp with an electret microphone.  There's PLENTY of overhead for what you want to do, at least if what you want is an FFT.  It'll make a neat light show and be close enough, most likely.. you aren't using this to convert the tone to MIDI or something, you want a color/light show, right?  It's actually pretty painless, your output is a 64-value scaled array.  You could map that onto LED's any way you want- monochrome, or maybe a mix of color vs. intensity per band.. but that's up to you.  The FFT code does the hard stuff for you.

All of this is being done with just an Arduino, no external hardware except for the microphone/amp circuit to give the A/D converter something to analyze and two resistors to set the voltages properly for NTSC video levels.  Links to the code are on the page, I've since encapsulated the FFT library and put it on Google Code (though I only wrappered it, not authored it!  That Integer FFT code is itself written very inefficiently, and could be done a lot faster in lower-level code... but obviously it's fast enough to do what's needed!  I can't praise "deif" enough for posting that code to the original Arduino forum.. if he ever returns).  When I set out to do it, I was sure that the little Arduino would not be enough... and it once again amazed me with just how much bang you can get out of an Arduino.  I can't even begin to praise the TVout Lib enough... that's a bit of coding so cute as to bring a warm tear to any tinkerer's eye.

To be clear:  this is an ATMEGA328, standard Arduino processor.. not a Mega.  it's just an Adafruit Boarduino, a variant that I like lot since it plugs directly into a standard breadboard.  No shields.  It's just so much more convenient sometimes... someone go fabricate a 99 cent Uno-To-Breadboard header, PLEASE???

http://code.google.com/p/arduino-integer-fft/
« Last Edit: June 07, 2011, 11:27:50 am by focalist » Logged

When the testing is complete there will be... cake.

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I did come across that.  It's one of the sites I have bookmarked to spend more time on and testing code, see what I can come up with.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Not only can the Arduino do a Realtime FFT, it can also generate NTSC video while doing it.
RS170 != NTSC
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34547
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Using an FFT is not going to do what the OP asked for. Yes it will give you a nice display but it will not pick out a single note and allow you to light an LED. It will light LEDs according to the spectrum of the waveform. That is you will get a different display from the same note, depending on the not's harmonic content.
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To OP:  unfortunately don't have a video.
Click on schematic, it will pop up in bigger size. It's pretty simple, three bar-graphs,
you will find a code and comments in "Example" section 7 (barGraph)  of the IDE.
To Grumpy_Mike: don't agree, note is just a frequency, doesn't have a harmonics ( instrument does ).
http://en.wikipedia.org/wiki/Piano_key_frequencies
Probably, with one note at a time, pulsein will do the job to identify the tone, but with 5/7 of them played simultaneously in accord,  FFT is only option.

Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34547
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
To Grumpy_Mike: don't agree, note is just a frequency, doesn't have a harmonics ( instrument does ).
You are soooo wrong.

The only sound that does not have harmonics is a sin wave from a sin wave generator. Even that is not perfect and will contain some levels of harmonics. You pay thousands for a low harmonic distortion generator, think how much you will pay for a no distortion generator.

What that link is saying is the root frequency of a piano, not the sound you get out of it. Have you ever looked at a piano's sound on a spectrum analyser, well if you had then you will know what nonsense you speak.
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That was I say, instrument does. The main reason they sound different, instruments I mean.
The same air , that allows sound to travel, create a second harmonic distortion too...
But even for worst case scenario, sine wave generator that generates square wave, there is 6 dB
margin between tone and overtone, very easy to sort them out.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34547
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That was I say, instrument does.
What does that mean?

Quote
The main reason they sound different, instruments I mean.
The main reasons they sound different is :-
1) Harmonic content of the wave
2) The envelope of each harmonic within the wave. This makes a big difference to the sound you perceive. With 1) only you have more like an organ sound that can vary but not so drastically.

Quote
The same air , that allows sound to travel, create a second harmonic distortion too
Care to explain how that happens? And it is only second harmonic not others?

Quote
sine wave generator that generates square wave, there is 6 dB margin between tone and overtone, very easy to sort them out.
So you have done this have you? Well a fortune awaits you in making sound to MIDI conversions. Odd that no one has done it very successfully yet. Yes you can buy them but they don't work well.

Also all this is talking about only having one note at a time, if you have a polyphonic system how do you tease out the fundamentals from that?

Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That was I say, instrument does.
What does that mean?
I will refer to initial post:
Code:
light up LEDs based on notes played on a 67 key instrument.

It's clear, that we are talking "musical instrument", and it does have harmonics.
Quote
note is just a frequency, doesn't have a harmonics ( instrument does ).

Quote
Quote
The same air , that allows sound to travel, create a second harmonic distortion too
Care to explain how that happens? And it is only second harmonic not others?

I point on a second as biggest troublemaker, there is a link, that provide more info from experts in the area:
http://www.qscaudio.com/support/education/designing_line_arrays/index.php?b=part2

Quote
Also all this is talking about only having one note at a time, if you have a polyphonic system how do you tease out the fundamentals from that?

I will refer to initial post, again:
Code:
light up LEDs based on notes played on a 67 key instrument.

It's only one instrument, not grand opera orchestra. I understand, that in situation two and more
instruments complexity of the task arise significantly.

And I assume it's not antimissile defense system some kind, so we are not gonna to lose human life or entire city, if couple notes didn't light up?  smiley-wink



Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34547
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@Magician, your English is becoming increasingly difficult to follow, litle of that post made any sense. You are clearly out of your depth. I read the link you posted and you are taking things way out of context. It dose not assert that you get second harmonic distortion, it is all about the transfer function of a pressur wave through a gas. Something that is only significant when the pressure wave is large compared to the gas pressure. That is in very loud systems.
The upshot of this is that you think what the OP wants to do is easy and we are telling you it is not. I look forward to you posting in the exhibition section a fully working system. However I feel I will have been long dead by the time you do.
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 30
Posts: 2602
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To KE7GKP:
No, I didn't say I'm not allow polyphony, btw, what is it?  smiley-roll-sweat
Probably I used wrong word for it:
Quote
http://en.wikipedia.org/wiki/Piano_key_frequencies
Probably, with one note at a time, pulsein will do the job to identify the tone, but with 5/7 of them played simultaneously in accord,  FFT is only option.
I name it "accord",  that was they taught me, excuse me, english not my native language.
Right name is chord: http://en.wikipedia.org/wiki/Musical_chord
Now, let's play C major:
  c4    e4    g4
261 329  392 Hz
I can't see any problem to identify each note, resolution 50 Hz would be enough for that.
Resolution 10 Hz is o'key to separate c4 and c#4.
And it the same with any other chord. This is why they invent musical note "scale", so even not musician can enjoy it. Check on a link Piano_key.
Note's frequencies distributed in such a way, that only "octave" ( or what right word ? ), could be unheard in the shadow of dominat's second harmonic.
For example, c4 and c5 played in four-note chord.
But it's a musical instrument, not square wave generator, the margin is much higher than 6 dB,
amplitude of c4 and c5 would be close enough to say it's two notes, not the one extremely distorted.
So, polyphony is not a problem at all.
What I say before, poly-instruments  would be. Due limited dynamic range (SNR) of the
 "arduino FFT ", pp "piano" or low level note of one instrument would be buried  in the ff "forte"
of another one.
Logged

Pages: [1] 2   Go Up
Jump to: