我找到了这个教程,它很好,但对我不起作用!
这是代码:
- (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)
所以它似乎工作!但不会改变任何东西,如果我再次输入背景更改代码,我的代码更改背景但没有任何保龄球!有什么问题 ?