我发现了这个tutorial,这很好,但对我不起作用!
这是代码:
- (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 !
}
控制台中的告诉我这样的nslog研究(没有任何保龄球!):
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
我改变了这个值:
if (lowPassResults < 0.95)
到
if (lowPassResults > 0.95)
所以看起来很有效!但是,如果我把背景改变代码,我的代码改变背景,但没有任何保龄球! 有什么问题?
答案 0 :(得分:3)
我也在使用它,它对我有用。您只需要使用该值将其与lowPassResults
进行比较。这是我的代码:
- (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"); }