iphone - 如何检查峰值功率持续时间

标签 iphone ios xcode core-audio

想知道是否有检查我是否在一定时间内达到峰值功率然后做某事的功能。

伪代码

最大阈值 -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 在您的特定情况下可能看起来的示例:

State Chart

关于iphone - 如何检查峰值功率持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9249410/

相关文章:

IOS 以编程方式拒绝来电?

ios - Swift 项目因线程 1 : EXC_BAD_ACCESS (code = 1, 地址 = 0x0 而崩溃)

ios - 当应用程序位于前台时,如何在点击推送通知时执行操作而不是自行执行操作?

iphone - 应用程序仅在iPhone设备上崩溃而不在模拟器中崩溃

php - 推送通知 iphone(我的设备没有收到通知)

ios - 删除图像缓存

iphone - 即使应用程序未运行,如何调用方法? iOS

ios - 无法在 swift iOS 中的 UITableViewController 或 UITableViewController 中为 Switch 创建 socket

ios - Flutter:尝试将 Flutter 应用安装到真实 iOS 设备时出现无法安装 "Runner"错误

iphone - 在我的Xcode项目中有一个本地JSON文件