• Advertisement
Sign in to follow this  

C++ - Analyzing Microphone Input

This topic is 4215 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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)?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Hi, interesting idea, could worth a try. You may want to try FMOD, a free open source sound library that lets you record sounds from the microphone. I think that it already provides FFT (or other tools) for sound analisys. If not, and in case you need it, you can get FFTW.

Share this post


Link to post
Share on other sites
Quote:
Original post by cignox1
Hi, interesting idea, could worth a try. You may want to try FMOD, a free open source sound library that lets you record sounds from the microphone. I think that it already provides FFT (or other tools) for sound analisys. If not, and in case you need it, you can get FFTW.


Thanks for the link, FMOD looks GREAT. I'm going to keep trying to get this to work using MCI though. If I can't get that working, I'll give fmod a shot.

Pulsar

Share this post


Link to post
Share on other sites
You'll wanna check your laptop's documentation to find out whether the microphone input is really a mic-in or if it's a line-in. Headphone jacks output line level, which is significantly higher than mic level; if the microphone input takes a mic level signal, you'll need to have the radio at a low volume or risk damaging the audio hardware.

Share this post


Link to post
Share on other sites
FYI, the way lightning pictures are usually take is with long exposures rather than with trying to catch a specific single lightning bolt. It'd be a far, far simpler solution.
As for monitoring audio input, that depends on which sound API you're going to use. If you're using windows' built-in API, you're looking for WaveInOpen and related functions.

Share this post


Link to post
Share on other sites
I cut my audio cable (as per these directions: http://www.tkk.fi/Misc/Electronics/circuits/line_to_mic.html). There are three wires in it: a black, a red, and, surprisingly, a bare wire. I'm assuming red is signal and black is ground. What is this third wire for? I'm guessing it's some kind of shield or drain wire. I'll post pics of my hacked cable as soon as I finish soldering.

Thanks

Pulsar

[Edited by - PulsarSL on July 3, 2006 10:03:13 PM]

Share this post


Link to post
Share on other sites
If it is a stereo audio cable, then the bare one is ground, and the other two are left and right.

Share this post


Link to post
Share on other sites
I switched it from the black wire to the ground... Everything appears to be wired according to the diagram now, so I went ahead and hooked it up to an old PC (that I don't care too much about :)). Right now, only one channel is connected, though I hear the radio out of both speakers. If I hold one speaker to each ear, everything sounds 'centered'. Does the sound card simply copy the existing channel to the other to make it sound better?

[Edited by - PulsarSL on July 5, 2006 9:06:37 PM]

Share this post


Link to post
Share on other sites
Also, just to make sure everything is wired OK, when I measure the output end with a multimeter, I should expect DC voltage in the millivolt range, correct? I appear to have lost my little digital voltmeter that reads millivolts, but my analog does not move at all when I read either the output or in the cable before it goes through the resistors. Is it possible the radio outputs at mic level already?

Thanks,

Pulsar

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement