We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Help a scientist - processing based flying bat
Page Index Toggle Pages: 1
Help a scientist - processing based flying bat (Read 1004 times)
Help a scientist - processing based flying bat
Oct 15th, 2009, 9:53pm
 
Hi everyone,

I'm just expanding my processing experience to the audio world so I'm new to minim library but I have processing programming experience. Here is what I want to do and could veterans on this board help me by commenting on whether I will be able to accomplish what I want? Thank you!

Objective: play a sound periodically and record the playback at the same time. Bats use this way to fly in the dark without hitting obstacles.

Details: I have a sample I want to play. It has less than a millisecond of a high frequency sound (sine wave at 20KHz) followed by silence. The length of the sample is possibly at most 0.1 second long if not shorter. While I play the sample I want to record it on the mike. Theoretically, the mike will record the initial high frequency sound and then another sound, a reflection of the original sound wave from objects near the speaker, a wall, a cup etc. Think about talking in an empty room and you can hear your echo. I want to play a sound and record its echo. The time lag between the two short sounds can be used to find the distance of the objects to the speaker. I think this is how bats navigate in dark caves.

Question 0: Can I get some comment on my objective?

Question 1: I did some search online about recording and playback. It seems that recording has a variable and inevitable latency, which is between you request for recording and recording occurs. I'd like to know how much latency minim has if ever.

Question 2: I also read through several pages at this sound forum and found some people having lags on playback. How bad can that be if all I want is to repeat a sample?

Question 3: Is there a way to play repeatedly on a hardware level so that once I set the sample to play the sound card will play the sample until the sound card is told to stop?

Thank you for your time!!! Grin Grin Grin
Re: Help a scientist - processing based flying bat
Reply #1 - Oct 16th, 2009, 8:59am
 
I found answer to question 3, how to play a short sample repeatedly, at least on the software level with sample in memory. I can use AudioSample.trigger(). I also read through some help files and found that sound runs on separate threads, which is good so I don't have to wait for a sound to finish playing to execute the next line.

I tried to play sound and record with the example getLineIn() and it worked nicely. If nobody has the answer to the latency of AudioSample play and record, I will just have to run a program to find out, with a stereo plug to channel output to input and time my recording.

If this works out, I can provide my code so someone may construct a sonic ranger with just a speaker and a microphone. The ranger tells you distance to an object. With a little calculation one can find the speed of the object and its acceleration, nice for robotics.
Re: Help a scientist - processing based flying bat
Reply #2 - Oct 20th, 2009, 2:58am
 
I'm by no means a board veteran so feel free to disregard if this seems like a stupid idea...

Couldn't you build in some calibration to take account of the effects on distance readings caused by lag?  i.e. have a variable you can adjust to compensate for lag after having tested against known distances...  Assuming the lag is unavoidable but consistent on a specific setup this might be an acceptable workaround.  In fact given that the lag may differ depending on the hardware the application runs on this might actually be an essential step in order to make it portable to other hardware.

Presumably a bat goes through a similar learning process when it first uses echo-location?
Re: Help a scientist - processing based flying bat
Reply #3 - Oct 20th, 2009, 1:56pm
 
Thanks Blindfish. I have done some test with an opensource recording program Audacity. It seems the lag is about 1 seconds but varies with +-0.5 seconds. My required accuracy is a millisecond, since sound travels 340m/s. I would not be able to do this sonic ranger if I tried to play a sound and then record.

But, if I start recording first and play a sound pulse while recording, I can record the original sound and its reflection. This proved to be quite consistence and accurate. I will need to build a program to see if I start recording with minim, how soon it will start recording. This determines how many sound pulses I can send out and receive in a second, or how often I can update object distance.

I'm trying to bring science labs into people's homes, or at least out of science labs. This will be great if it works out.
Page Index Toggle Pages: 1