Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting noise via mic while playing a song on iPhone

I am making an app that should play a simple audio track and let me know if there is any noise in the vicinity while the track is playing. This is done by doing a live recording from the microphone while the song plays on the iPhone's loudspeaker. Any sound that is not part of the music playing is defined as noise.

What would be the simplest way to implement this functionality?

I've researched it quite extensively online but I have not been able to find anything that points me to a solution for this specific problem. Although it may be a combination of different techniques I read about that eventually will be the solution.

Things I've already implemented
Playing the song and recording audio simultaneously.

Things I've tried
NOTE: Since we're encouraged to add what we've already tried I add the following part. But I'm by no means saying that this is the right way to solve the problem, it's just something I tried.

I hacked the aurioTouch2 sample application: what I did was playback the song once and record the fast fourier transform values (at a pretty low sample rate to keep the amount of recorded data low). Then when the track was played again I would basically calculate (per timestep) the correlation coefficient between the output graphs that are constructed using the live playback fft data and the recorded fft data (so the 'squiggly' lines that you see when you put the app in fft mode).
This 'sort of' works. The correlation coefficient is clearly lower when excess sound/noise is in the room but it isn't very sensitive and also depends on the volume level that was used when recording the fft data. In the end I'm thinking that this may not be the best approach.

Does anyone think this is possible? If so, what would be the best approach?
Please ask if you need more clarification!

like image 691
Marco Tolman Avatar asked Aug 16 '12 19:08

Marco Tolman


2 Answers

You just want to know, how much noise is in the environment and you have two signals, the original one and the recorded one? Then your solution is perfectly fine. You need to synchronize the signals and find some number, which gives you similarity. You can even avoid fft and use the original signal (in a proper presentation).

Autocorellation is a nice way to synchronice your signals. Autocorellation-index is a number which gives you the similarity.

Of course, if the volume is lower, the noise is (relative to the music) louder and has higher influence. Since you should be able to detect the volume, you should be able to add some correction-factors. But since this is a "natural" problem, I guess every algorithm will have this problem.

Another solution would be to subtract the original signal from the recorded signal and then you should get the noise as the difference of both signals. Then you also have the power of the noise...

like image 89
zen Avatar answered Nov 15 '22 12:11

zen


In the end we decided not to do this in the app. I got a demo working where I would first do a calibration for the song, collecting a set of the most dominant frequencies, do the same for the ambient room noise and use those frequencies in the decision process while the song is playing. It worked alright, although I felt it still needed a lot of tweaking. It was the best I could do with my limited knowledge of audio related programming :)

like image 24
Marco Tolman Avatar answered Nov 15 '22 12:11

Marco Tolman