我正在尝试检测用户何时向 iPhone 的麦克风吹气。现在我正在使用 Stephen Celis 中的 SCListener 类打电话
if ([[SCListener sharedListener] peakPower] > 0.99)
在 NSTimer 中。然而,有时当我不吹气时,这又会出现。有人有任何示例代码来检查用户是否对着麦克风吹气吗?
最佳答案
我会推荐low-pass filtering首先是电源信号。总会有一定量的 transient 噪声会干扰瞬时读数;低通滤波有助于缓解这种情况。一个漂亮且简单的低通滤波器将是这样的:
// Make this a global variable, or a member of your class:
double micPower = 0.0;
// Tweak this value to your liking (must be between 0 and 1)
const double ALPHA = 0.05;
// Do this every 'tick' of your application (e.g. every 1/30 of a second)
double instantaneousPower = [[SCListener sharedListener] peakPower];
// This is the key line in computing the low-pass filtered value
micPower = ALPHA * instantaneousPower + (1.0 - ALPHA) * micPower;
if(micPower > THRESHOLD) // 0.99, in your example
// User is blowing on the microphone
关于iphone - 检测到对 iPhone 麦克风的吹气吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/795968/