Hi I would like to have my arduino be able to differentiate between pitches, and have it enter different "if" states for different pitches. Is this possible. Note I really only want to use a simple transducer to pick up the audio, meaning it is only going to have two leads coming off of it.
Kinda like a small mobile phone button mic or simular.
umm yes, I dont expect the arduino to sense minute differences. If I could get it to work with like a + or - 5 to 10 hertz buffer the project I have in mind will still work. all of the pitches would be within normal human thresholds. Do you think it would be better to build a separate board that interfaces with the arduino??? I was thinking about hacking like a music tuner or something???
I have written a tone detection program for the ATmega8 chip, which of course was the chip used in early versions of the Arduino. I wrote it in AVR assembler, thinking that I'd need the assembler code for speed. It uses a convolution technique to compare an input (sampled) signal with a stored reference sine wave. Convolution is all about doing lots of multiplication and addition instructions on a buffer in RAM. It turns out that the 16MHz ATmega8 can do this in 550us, whereas it takes 32ms to acquire the audio data in the first place! So, I have time to run eight tone-detection routines, which is sufficient to decode DTMF dialling tones, and still have time to spare.
I think this could be done, in C, on the Arduino with no problem.
(I'll be taking the tone detector to Dorkbot Bristol this evening)
Anachrocomputer - that is brilliant. I wish I could get down to Dorkbot to see it.
With DTMF, aren't the tones carefully chosen to make it "easy"? I'm not saying that isn't amazing (I doff my cap to you), just that it isn't as bad as sampling music.
neckrokid, I think it is practically impossible to separate tones only 5-10Hz apart with the analogue input system of the Arduino, unless that is a variation of abut 10%, i.e. on a 100Hz tone, unless you feel confident that you could do what Anachrocomputer has done.
Nyquists theorem says (summary) that you can't recognise the frequency of a signal with less than 2 samples/cycle. An Arduino is roughly capable of 10,000 samples/second, and so top frequency theoretically possible is 5KHz. For a pure tone.
Most folks I've ever listened to reckon on 10 samples being reliable, to account for noise, and Anachrocomputer has pulled it off for 1633Hz, which IMHO is exceptionally impressive.
I think your best bet is to simulate the old 70's gizmo's, and build some analogue electronics to separate the audio frequencies, and measure those. With some filters, and frequency to voltage converters, you could probably do a pretty good job.
An alternative might be to use an XMega (or ARM, or DSP) which have fast analogue to digital (ADC) and a bit more power.
Ok, I had an idea, what if I was to get rid of the mic all together and just wire up the arduino to one of the audio channels and use pitches that fall into the 0 to 1023 that a potentiometer puts out???? then I would put a separate track in the song that would control the arduino. do you think that would work???
your rite. I just looked up how pots work and realized I was thinking about them all wrong, I thought that pots were like a capacitor rather than a resistor. in the sense that I would be able to have the audio frequency act as a pot. but that isn't going to work
If you are confident you can do it, then, from an audio processing perspective, it would be a good idea to get rid of the mic, and take the signal directly. It may be a good way to get started with experiments too.
I like the idea of a seperate control track that isn't played through the speakers, but how would you make that? By hand?
If you could do that, maybe ask if Anachrocomputer can help with the DTMF decoder. You'd record touch tone phone dialling tones alongside the music to trigger actions. With a pre-built control track, it would be possible to do the creation of it off line, using whatever tools you like.
I must admit, this sounds like hard work, but no worse than building music in the first place, and hey, I'm no musician or DJ.
If you're going to use DTMF just run the signal through a DTMF decoder and interface it directly to the Arduino digital lines. Minimal hardware and you'll get 16 possible combinations....
Something to keep in mind. Line level Audio signals will not be 0-5 volts (much less) and SPEAKER signals will be much more than 0-5 Volts. You need to build some sort of buffer between the source and the Arduino of you remove the mic.
I believe it means that some line level source with an op-amp would be used.
I believe it means that some line level source with an op-amp would be used.
Radio Shack used to sell these attenuator plugs that would convert a signal from speaker level to line level; likely they were just resistors or something inside the plug (voltage divider, probably), but I used them as a kid (still have them) and they worked well for their purpose (I never had a way to measure actual levels, though).
yea, I was planning on just using a line out anyway, like a headphone jack although it will probably end up being a RCA jack. because well
i have a bunch (like 3) open on my audio card and it would be really easy to program one of them as a different (surround) track, but that still doesn't help very much with the decoding of frequency.
Pleas note that yes, it is going to be interfaced with my computer for the time being, so yes I could just control the arduino using USB, but I plan on getting rid of the computer aspect later.
That's a lovely project. IMHO Jesper is talented.
It relies on there being one dominant 'note', then amplifying it so much that it 'maxes out' and drives a digital pin. You can probably imagine how nicely that works with a single, pure, constant tone. Once it is made that simple, it is straightforward to time the duration between peaks, they will be pretty consistent.
I don't know for certain, but I would be surprised if the music you are interested in can be treated so directly, but it seems worth the experiment.
If you are confident that you can get into the detail, then there is some of the electronics you need 'hidden' inside the ATmega chip already. Jesper detects signal peaks, and times them. The ATmega has a piece of electronics inside which can detect peaks, and other pieces which can time the peak. It has a comparator which compares two voltages, and signals the result with a HIGH or LOW. One input would be the audio signal, and the other from a potentiometer so that you can adjust it to get the peaks. It may need a few resistors to get the audio to the right level, but I think line-out should be a reasonable start. You might give it a try.
Using the comparater is described in an Atmel document
in "22. Analog Comparator"
Then timer1 would be used to time the changes detected by the comparator. The time is exactly an inverse measure of frequency.
Having said all that, I'd be tempted to use the power of your PC to analyse music, and extract something for the Arduino to use to for the light show. A PC has, about, 200x more computer power than an Arduino, and if you are willing to do stuff ahead of time, it has even more power to analyse music.
Please note that "detecting tones" like DTMF telephone dialing (or a guitar tuner where only one string is plucked) is one thing.
Agreed.
But picking out individual pitches from typical music ...
Isn't that what a spectrum analyser does? I think, for example, recognising instruments within a piece of music is harder.
I do think you make a valuable point about the potential complexity of sophisticated analysis.
necrokid said
I plan on making a light show to some techno music
I admit, that I have been assuming that will be less complex processing than a Mac uses (e.g. in iTunes) to produce its on-screen light show when playing music. But I haven't been explicit about that assumption.
The idea of having an extra track, which would not be played through the audio system, but instead be fed to the Arduino gives a lot of flexibility. Nothing need to be analysed in realtime, and iTunes-quality analysis is feasible in realtime on a PC.
Maybe necrokid could explain in a bit more detail what kind of light show is needed?
I dont really see why you need to know exactly what kind of light show I plan on making. All I wanna do (rite now) is have different digital pins change from HIGH to LOW when a certain pitch is played. I haven't worked out exactly what kinda lights I wanna control with it yet, I haven't even looked at that aspect yet.
So, just for my sake I'm gonna jot down where were at:
I plan on using a separate audio track along side a song that I will have interfacing with the arduino. We are looking into a way of having the arduino differentiate between different audio pitches. When the arduino detects said pitches it will reverse the state of a predetermined digital pin.
ok so I was thinking that would it not be easier to have my separate audio track consist of square waves (like a PWM signal) rather than transverse waves? Is there a code that already exists that reads PWM as an input??????
Note: If you cant tell, I have a low level of knowledge about electronics and programing in general(thank goodness for google). LOL, and you guys of course. When I first thought of what I wanted to do, I was like I will post a question in the forum an someone (having already worked through the problem) would of replied to my post telling me to "plug this into that pin and supply 5v here, up load this code and there you go" obviously that is not the case an I thank all who have supplied me with their thoughts. So what I am really trying to say is I wanna get the gob done as easily as possible.