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.
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.
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.
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???
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.
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 ).
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.
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.
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.
The main reason they sound different, instruments I mean.
The main reasons they sound different is :-
Harmonic content of the wave
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.
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?
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?
That was I say, instrument does.
What does that mean?
I will refer to initial post: 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.
note is just a frequency, doesn't have a harmonics ( instrument does ).
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?
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: 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?
@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.
To KE7GKP:
No, I didn't say I'm not allow polyphony, btw, what is it?
Probably I used wrong word for it:
Piano key frequencies - Wikipedia
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: Chord (music) - Wikipedia
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.
Grumpy_Mike:
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.
And this is perfectly fine. As long as it's "close enough". I do need to distinguish the differences between a lower and higher octave C being hit. And I think I can get that on a regular spectrum as one will generate more bass than the other. However, don't quote me on that, I don't have anything to test with right now. But this is also why I'm asking questions here before I try to actually make something.
KE7GKP:
If you look closely, you will find that most keyboard players have 10 fingers, typically 5 on each hand. If you don't allow for polyphony, then you are not making something that practical to use in the Real World.
However, on this particular instrument, the most notes that can be played at any given time would be 4 ... there's only so many mallets these kids know how to play with.
Ok, so if I read that right, you have pins 2-5, 6-9, and 10-13 assigned to red, green, and blue. Those pins go to two darlingtons which then drive the LEDs. Am I correct in assuming you're driving the Arduino with 12V then? I see a mic plugged into analog 0 - I'm assuming that board the mic is on is an amp then?
Based on the above, you're using 12 pins, that's 12 channels. Still (quite a bit) short of my goal of 67 frequency bands. I must be missing something ... the Arduino, in this particular setup, won't have enough pins to drive all the frequencies.
It's in description, just on right side of schematic:
12 V;
mic + IC NE5532;
only 3 "hardware" channels (RGB). There are 64 define in software: #define FFT_SIZE 64.
For color-music project 64 more than enough, 31 in use only.
Your project will require more bins/channels/bands, to calculate exact value I need to know:
1). lowest and highest notes on keyboard;
2). what kind of arduino board are you gonna use;
If you didn't decide on type on board, go for "Arduino Mega 2560".
There is a chance, that with UNO would not be possible to cover all range of keyboard.
For output, as you notice, not enough pins, shift register IC would be necessary. But it last thing to
worry about. I'd suggest, debugging all software first with just a serial monitor.
Yeah, about 30 minutes after I posted my questions, I realized ... I don't need that many pins because I'll be driving an addressable strip, so 4 pins ought to be enough. Or I can also drive a bunch of 5940NTs for individual LEDs, in which case 5 pins is enough.
As for the lowest and highest notes, I presume you want that in frequency? That's not something I can provide because I don't have any way of measuring that. I just had one of the kids e-mail me and say that they won't be using their largest one (5.5 octaves), but instead opted for the smaller ones of which they have several - that way it will all be the same (whatever that means.) Anyway, the smaller ones are 4 octaves. They have a xylophone and several vibes that are in the 3.5 range as well and if all goes as planned, they would want those wired up as well. I'm going to work with one thing at a time here, starting with the largest one. If it works out, then I'll figure out the rest.