Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect blow in Mic and do something

i found this tutorial , and it's good , but doesn't work for me !

here is the code :

- (void)listenForBlow:(NSTimer *)timer {
    [recorder updateMeters];

    const double ALPHA = 0.05;
    double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
    lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;

    if (lowPassResults > 0.95)
        NSLog(@"Mic blow detected");
 //change the background color e.g !
}

in the console show me the nslog reseult like this (without any bowling !):

2010-04-11 23:32:27.935 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:27.965 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:27.995 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.026 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.055 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.086 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.115 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.145 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.175 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.205 MicBlow[2358:207] Mic blow detected
2010-04-11 23:32:28.236 MicBlow[2358:207] Mic blow detected

i change this value :

 if (lowPassResults < 0.95)

to

if (lowPassResults > 0.95)

so it seems work ! but doesn't chage anything , again if i put the background changing code the , my code change background but without any bowling !! what's the problem ?

like image 668
Mc.Lover Avatar asked Apr 11 '10 19:04

Mc.Lover


1 Answers

I'm using it too and it works for me. You just have to play with the value to compare it with lowPassResults. Here's my code:

- (void)levelTimerCallback:(NSTimer *)timer {
    [recorder updateMeters];

    const double ALPHA = 0.05;
    double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
    lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;  
    //NSLog(@"%f", lowPassResults);
    if (lowPassResults > 0.55)
        NSLog(@"Mic blow detected");
}
like image 192
Youssef Avatar answered Oct 03 '22 14:10

Youssef