想知道是否有检查我是否在一定时间内达到峰值功率然后做某事的功能。
伪代码
最大阈值 -110db 如果用户停留在此阈值超过 5 秒显示警报 别的 什么都不做。
编辑:回答
-(void)thresholdCheck:(NSString *)peakValue
{
int sec = hit/60; //1/60sec
NSString *tempSec = [NSString stringWithFormat:@"%i",sec];
[timeTrash setText:tempSec];
if (110<[peakValue intValue])//110db
{
hit++;
NSLog(@"hit threshold %i",hit);
}
else
{
hit =0;
//NSLog(@"hit threshold %i",hit);
}
if (hit >=330)//more then 5 sec {
NSLog(@"hit thresholded %i",hit);
[recorder stop];
[levelTimer invalidate];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Threshold Hit" message:@"Sorry You Hit the threshold" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
最佳答案
我怀疑您会找到一个现成的函数来完成您在这里的要求。一个简单的 finite state machine (FSM) 似乎很适合解决方案。看看这个 tutorial如果您还不熟悉 FSM,请了解它们。
您可以使用枚举和 switch 语句实现简单的 FSM,如图所示 here ,或我上面发布的教程链接中的 list 1。
这是您的 FSM 在您的特定情况下可能看起来的示例:
关于iphone - 如何检查峰值功率持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9249410/