C++ - Analyzing Microphone Input

Started by
17 comments, last by PulsarSL 17 years, 10 months ago
Hi I want to take pictures of lightning with my digital camera. I've been experimenting though and noticed that it's very difficult because by the time I can react and hit the shutter, the lightning is mostly faded. Rather disappointing. When lightning strikes, it emits not just visible light, but also radio waves. You can observe this effect by tuning an AM radio to a station with nothing but soft static. Along with the bolt (not the thunder), there will be a very noticable increase in the volume of the static. Anyway, I had an idea. My camera (Rebel XT) can be controlled via USB. If I buy a cheap cable from an electronics store that allows me to go from the headphone output of my radio to the microphone input of my laptop, I can use a custom program to monitor the static. when it crosses a certain threshold, I could tell the camera to fire. This would reduce the time between the bolt and exposure to only a few milliseconds (hopefully). Since the burst of static and the light from the bolt arrive at the same time, the only delay is the processing time. Now... This is where you guys come in. How can I monitor an audio input (is this easy?). What library should I use? I'm hoping to do this in C++. Thanks! Pulsar
Advertisement
My physics class are long forgotten, but since light travels faster than sound, are you sure this would work?

What I'd do is have the computer query pictures every n millisecs, analyse them (convert to grayscale, and test for color differences, when a lightning strikes, colors should be composed of higher R, G, Bs... so the overall image will be way brighter... no need to actually find the lightning in the picture)... when ever you find that a lightning is striking, then you can take snapshots as often as you can for say, 1 second... and then allow the user (you) to keep the best pictures?

Anyway, that's just an idea heh

Good luck!

Eric
He's going to monitor input from a radio, so his application will "hear" the lightning with a very small delay as this spike will be there in the speed of light...

You can use MCI to record data like this, and just have a threshold, if amplitude increases above your limit, you take a photo.

Maybe this will do it.
Quote:Original post by xEricx
My physics class are long forgotten, but since light travels faster than sound, are you sure this would work?
"Radio waves" and "sound" are two different things, so yes, it seems eminently doable although its probably easier said than done in that you need to know which frequencies to detect and then go about detecting them.

I reckon it would be way easier to rig a photoresistor to the camera/computer and have the flash itself trigger the taking of a picture.

But the question is: do you really want to be out with your laptop and camera in the lightning storm!? :)

Edit: corrected crap spelling

[Edited by - Christer Ericson on July 2, 2006 11:59:52 PM]
Quote:Original post by xEricx
My physics class are long forgotten, but since light travels faster than sound, are you sure this would work?


Light does travel faster than sound -- MUCH faster. Light (and basically all electromagnetic radiation) travels at approx. 186,000 miles per SECOND. Sound travels at about 760mph.

When the lightning strikes, it emits visible light (the bolt), sound (the thunder) and some other EM radiation (including radio waves). The radio waves travel at the same speed as visible light, so the spike in the static and the light the camera captures arrive at my location at just about the same time.

Frequency doesn't matter too much. I think lightning emits radio waves around the 300mhz frequency, but the spike appears no matter where the radio is tuned to (I'm not sure why...)

I can't monitor the sky from the camera and compare the values as Eric suggested because my camera is an SLR. Because of the design of SLR cameras, there is no live preview. Each picture is pretty large because it's an 8mp camera, so I'd be lucky if I could snap and download 1 picture every second. Not even close to fast enough.

I also considered the idea of rigging up a photoresistor up, but there was no pratical way of doing it with my hardware. I would have to hook it up to something like a basic stamp board, download the value via serial and then run the comparison based on value. Seemed easier to watch for a change in amplitude.

I do like the idea of taking a burst of pictures and allowing the user to select the best.

Where can I find more info on how to do this? Everything I see with mci is about playing files. I don't even know what to search for to find out how to do this.


Pulsar
Click Me

Before you get started though, use the built-in sound recorder in Windows for testing, that way if it doesn't work out, you don't waste any time playing with code...
Sorry, but I don't think your solution will work. The lag between your static detection and the camera firing will be too great.

What's wrong with the traditional solution (bulb photography)?
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
Quote:Original post by ChaosEngine
Sorry, but I don't think your solution will work. The lag between your static detection and the camera firing will be too great.

What's wrong with the traditional solution (bulb photography)?


It's still an option, but I thought this would be a fun way to brush up on my c++ skills.

Even if it doesn't work, it's still a good learning experience. I'm working now on getting all the includes and declarations related to MCI working. I'm a bit tripped up on

C:\programming\visual studio\MSDev98\MyProjects\mci\myMci.cpp(20) : error C2061: syntax error : identifier 'DWORD_PTR'

I've included windows.h, so I'm not sure what's going on here. I'm searching the msdn forums now.

Pulsar
This may work, but it is a bad idea to route the headphone output of the radio straight to the microphone input. They usually are not compatible. If your laptop does not have a line-in jack (preferred for this application) then you will need a matching transformer. Or if you want to be really cheap, you might be able to get away with a variable resistor since you aren't really interested in the quality of the noise but only its volume.

I read on one of NASA's webpages that most lightning flashes are composed of multiple strokes of lightning, an average of 4. Each stroke lasting an average of 30 microseconds. So while it would be difficult to catch the first stroke of lightning, you should easily be able to capture the strokes that follow it, by detecting the first stroke. Though of course, most of the flashes will still likely go uncaptured unless you have a wide-field of view and good vantage point of the storm.
.
Anyway, I just threw a typedef DWORD * DWORD_PTR; into my app and that problem is taken care of.

Ugh. Who knew mci could be so nasty. I'm wading waist deep through msdn documentation (that, incidentally, doesn't help one bit). How do I find the device ID I need to send the MCI_OPEN command? I don't see it explained anywhere in the documentation.

Pulsar

[Edited by - PulsarSL on July 3, 2006 12:08:47 AM]

This topic is closed to new replies.

Advertisement