14

I have searched for this online, but am still a bit confused (as I'm sure others will be if they think of something like this). I'd like to preface by saying that this is not for homework and/or profit.

I wanted to create an app that could listen to your microwave as you prepare popcorn. It would work by sounding an alarm when there's a certain time interval between pops (say 5-6 seconds). Again, this is simply a project to keep me occupied - not for a class.

Either way, I'm having trouble trying to figure out how to analyze the audio intake in real-time. That is, I need a way to log the time when a "pop" occurs. So that you guys don't think I didn't do any research into the matter, I've checked out this SO question and have extensively searched the AudioRecord function list.

I'm thinking that I will probably have to do something with one of the versions of read() and then compare the recorded audio every 2 seconds or so to the recorded audio of a "pop" (i.e. if 70% or more of the byte[] audioData array is the same as that of a popping sound, then log the time). Can anyone with Android audio input experience let me know if I'm at least on the right track? This is not a question of me wanting you to code anything for me, but a question as to whether I'm on the correct track, and, if not, which direction I should head instead.

Community
  • 1
  • 1
Vinay
  • 6,204
  • 6
  • 38
  • 55
  • 1
    old topic http://stackoverflow.com/questions/2257075/real-time-audio-processing-in-android – PedroAGSantos Sep 13 '11 at 15:59
  • 2
    ^ I've already referenced that question in my question. My question is more of whether I'm heading in the right direction given my specific needs for real-time audio analysis. – Vinay Sep 13 '11 at 16:09

3 Answers3

9

I think I have an easier way.

You could use the MediaRecorder 's getMaxAmplitude method.

Anytime your recorder detects a big jump in amplitude, you have detected a corn pop!

gregm
  • 12,019
  • 7
  • 56
  • 78
  • Thanks a ton man! My friend actually suggested the same thing, and I think I'll use it (still haven't finished the app because I've been terribly busy with other school-related stuff). +1 for this answer from me. – Vinay Oct 05 '11 at 16:11
  • Can you mark my answer as the correct answer? I cant wait to get the app! – gregm Oct 13 '11 at 14:03
  • gregm, although I will use your method, Andrew has given me a good direction to go (and I will still be using much of his method for live analysis of the audio), and he has answered first. Don't take it personally, I simply don't feel right unchecking his answer as the answer when he answered first. Again, thank you and I'm glad you can't wait for the app (although it really is just for fun/a mini-project), but please don't take it personally. – Vinay Oct 13 '11 at 16:40
6

Check out this code (ignore the playback part): Playing back sound coming from microphone in real-time

Basically the idea is that you will have to take the value of each 16-bit sample (which corresponds to the value of the wave at that time). Using the sampling rate, you can calculate the time between peaks in volume. I think that might accomplish what you want.

Community
  • 1
  • 1
5

this may be a bit overkill, but there is a framework from MIT media labs called funf: http://code.google.com/p/funf-open-sensing-framework/
They already created classes for audio input and some analysis (FFT and the like), also saving to files or uploading is implemented as far as I've seen, and they handle most of the sensors available on the phone. You can also get inspired from the code they wrote, which I think is pretty good.

Andrei
  • 2,282
  • 26
  • 35