我怎样才能让我的iPhone听声音频率超过一定阈值? [英] How can I get my iPhone to listen for sound frequencies above a certain threshold?

查看:756
本文介绍了我怎样才能让我的iPhone听声音频率超过一定阈值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很感兴趣,让我的iOS应用程序打开麦克风只听以上17000赫兹的频率。如果听到的东西在这个范围内,我想应用程序调用的方法。

I'm interested in getting my iOS app to turn on the microphone and only listen for frequencies above 17000 hz. If it hears something in that range, I'd like the app to call a method.

我能够找到检测频率资源库: https://github.com/krafter/DetectingAudioFrequency

I was able to find a repository that detects frequency: https://github.com/krafter/DetectingAudioFrequency

这里是一个岗位打破FFT:结果
<一href=\"http://stackoverflow.com/questions/11686625/get-hz-frequency-from-audio-stream-on-iphone/19966776#19966776\">Get从音频流赫兹的频率上iPhone

And here is a post breaking down FFT:
Get Hz frequency from audio stream on iPhone

使用这些例子中,我已经能够拿到手机向它听到最强的频率反应,但我更感兴趣的只是反应上述17000赫兹的频率。

Using these examples, I've been able to get the phone to react to the strongest frequency it hears, but I'm more interested in just reacting to the above 17000 hz frequencies.

推荐答案

这是我写的code可以帮助我回答这个问题,但答案也许只适用于在code。事实上

The fact that I wrote that code helps me answering this question but the answer probably only applies to this code.

您可以轻松地只是微调的输出数组仅包含你所需要的范围一块限制你听的频率。

You can easily limit the frequencies you listen to just by trimming that output array to a piece that contains only the range you need.

具体为::要简单 - 数组[0..255]包含频域音频。例如,你的采样率是44100,当你做FFT。
然后,最高频率可以连接code是22050.(奈奎斯特定理)。

In details: To be simple - array[0..255] contains your audio in frequency domain. For example you sample rate was 44100 when you did FFT. Then maximum frequency you can encode is 22050. (Nyquist theorem).

这是数组[0]包含二百五十六分之二万二千零五十零= 86.13 Hz的值。阵列[1]包含86.13 * 2 = 172.26 Hz的价值,阵列[2]包含86.13×3 = 258.39赫兹值。等等。您全方位的跨越那些256个值分布。 (是的,precision遭受)

That is array[0] contains value for 22050/256=86.13 Hz. Array[1] contains value for 86.13*2 = 172.26 Hz, array[2] contains value for 86.13*3 = 258.39 Hz. And so on. Your full range is distributed across those 256 values. (and yes, precision suffers)

所以,如果你只需要听一些范围,比方说上面17000Hz,你只要拿一张该数组的而忽略其他。在这种情况下,你需要17000 / 86.13 = 197〜255子阵和你有它。只有17000-22050范围。

So if you only need to listen to some range, let's say above 17000Hz, you just take a piece of that array and ignore the rest. In this case you take 17000/86.13=197 to 255 subarray and you have it. Only 17000-22050 range.

在我的回购协议修改 strongestFrequencyHZ 这样的功能:

In my repo you modify strongestFrequencyHZ function like that:

static Float32 strongestFrequencyHZ(Float32 *buffer, FFTHelperRef *fftHelper, UInt32 frameSize, Float32 *freqValue) {
Float32 *fftData = computeFFT(fftHelper, buffer, frameSize);
fftData[0] = 0.0;
unsigned long length = frameSize/2.0;
Float32 max = 0;
unsigned long maxIndex = 0;

Float32 freqLimit = 17000; //HZ

Float32 freqsPerIndex = NyquistMaxFreq/length;
unsigned long lowestLimitIndex = (unsigned long) freqLimit/freqsPerIndex;

unsigned long newLen = length-lowestLimitIndex;
Float32 *newData = fftData+lowestLimitIndex; //address arithmetic
max = vectorMaxValueACC32_index(newData, newLen, 1, &maxIndex);
if (freqValue!=NULL) { *freqValue = max; }
Float32 HZ = frequencyHerzValue(lowestLimitIndex+maxIndex, length, NyquistMaxFreq);
return HZ;

}

我做了一些地址运算在那里,所以它看起来有种复杂。你可以采取的 fftData 阵列,并做定期的东西。

I did some address arithmetic in there so it looks kind of complicated. You can just take that fftData array and do the regular stuff.

其他的事情要记住:

查找最强的频率。简单。你刚才发现,数组中的最大值。而已。但在你的情况下,你需要监视的范围内,发现当它从正规弱噪声去了一些强有力的信号。在东西时的峰值,而这也不是那么微不足道,但可能等字样。您可能只需要设置一些限制高于该信号变为检测,虽然这不是最好的选择。

Finding strongest freq. is easy. You just find maximum in that array. That's it. But in you case you need to monitor the range and find when it went from regular weak noise to some strong signal. In other words when stuff peaks, and this is not so trivial, but possible. You can probably just set some limit above which the signal becomes detected, although this not the best option.

我宁愿这个原因在现实生活中你看不到太多的噪音在18000Hz你身边乐观。一个能记住的唯一的事情是产生高音调的声音时,他们是在一些旧电视。

I would rather be optimistic about this cause in real life you can't see much noise at 18000Hz around you. The only thing a can remember of are some old TVs that produce that high pitched sound when they're on.

这篇关于我怎样才能让我的iPhone听声音频率超过一定阈值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆