我想知道这个应用程序RoboStrobe如何检测节拍。我正在使用“AVAudioRecorder”来收听麦克风并获取声级计,但我不知道计算电平和节拍并触发我的方法的正确方法。
这是我现在要做的:
调用更新方法:
levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.05 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
还有我的更新方法
-(void)update
{
[recorder updateMeters];
const double ALPHA = 0.05;
double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
double scale = lowPassResults * 5;
NSLog(@"Result = %f",scale);
if (scale>4.5) {
[[UIScreen mainScreen] setBrightness:1.0];
NSLog(@"HEAVY Scale = %f",scale);
[self turnTorchOn:YES];
[self performSelector:@selector(off) withObject:Nil afterDelay:0.4];
}
else
{
[self turnTorchOn:NO];
[[UIScreen mainScreen] setBrightness:0.1];
}
}