AudioKit(iOS) - 添加频率/幅度变化的观察者 [英] AudioKit (iOS) - Add observer for frequency / amplitude change

查看:877
本文介绍了AudioKit(iOS) - 添加频率/幅度变化的观察者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AudioKit 框架来开发一个能够收听麦克风输入频率和放大器的小型应用程序;我希望每次频率和频率触发一个事件(显然我想触发一个功能)。振幅得到特定值 - > 特定音调的事件。

I'm using the AudioKit framework for developing a small application that is able to listen for the microphone input frequency & amplitude and I want to trigger an event (obviously I want to trigger a function) every time the frequency & the amplitude got specific values -> An event for a specific tone.

现在我正在为我的应用程序使用这个简单的Swift代码:

Right now I'm using this simple Swift code for my application:

mic = AKMicrophone()
tracker = AKFrequencyTracker(mic)
silence = AKBooster(tracker, gain: 1)
AKSettings.audioInputEnabled = true
AudioKit.output = silence
AudioKit.start()

let t = Timer.scheduledTimer( timeInterval: 0.05, target: self, selector: #selector(self.checkFrequencyAmplitude), userInfo: nil, repeats: true)


func checkFrequencyAmplitude() {
   let frequency = tracker.frequency,
       amplitude = tracker.amplitude
   if (frequency > 1000 && frequency < 1200 && amplitude > 0 && amplitude < 0.2) {
      // do stuff if the specific tone appeared
   }
}






但说实话,我得到了马使用 timeInterval 0.05s 的ssive问题,就像我的iPhone加热速度超快&这绝对不是我想要的。


But to be honest I got massive problems using a timeInterval with 0.05s, like my iPhone heats up super fast & thats absolutely not this what I want.


  • 请记住:只需使用另一个timeInterval,例如一秒钟
    timeInterval:1.0 )是不可能的,因为我的应用程序必须能够尽快检测到特定的声音。 (某些输入声音可能很短[0.5秒或更短]。)

  • Keep in mind: Just using another timeInterval for example one second (timeInterval: 1.0) is not possibility because my app must be able to detect the specific sound as fast as possible. (Some of the input sound could be pretty short [0.5 seconds or less].)

也许AudioKit开发者添加了一些事件可以如果输入获得特定频率/幅度,则触发。

Maybe the AudioKit developer added some event can be triggered if the input gets a specific frequency / amplitude.

或者可以将类似Swift观察者的内容添加到 AKFrequencyTracker -subclass ..

Or maybe it is possible to add something like an Swift observer to a AKFrequencyTracker-subclass..

我不知道怎么回事,并且会非常感谢你的帮助。

推荐答案

您应该让DSP检查您的条件,而不是使用计时器。为此,您必须编辑频率跟踪器或创建自己的副本。好消息是,AudioKit的幅度跟踪器已经做了类似的事情,每当听到一定音量就调用一个函数,即。达到幅度阈值:

Instead of using a timer, you should let the DSP check for your conditions for you. To do this you'll have to edit the frequency tracker or create your own copy. The good news is that AudioKit's amplitude tracker already does something like this, calling a function whenever a certain volume is heard ie. an amplitude threshold is reached:

https://github.com/AudioKit/AudioKit/blob/master/AudioKit/Common/Nodes/Analysis/Amplitude%20Tracker/AKAmplitudeTrackerDSPKernel.hpp#L97

如果以一般方式执行此操作,您甚至可以发出拉取请求并将代码提交回AudioKit。事实上,如果你想这样做,我可以帮助你进一步朝着正确的方向前进。但是,我认为你可以使用幅度跟踪器作为模板。

If you do it in a general way, you could even make a pull request and commit the code back to AudioKit. In fact, if you want to do that, I can help steer you in the right direction further. But, I think you can get pretty far using the amplitude tracker as a template.

这篇关于AudioKit(iOS) - 添加频率/幅度变化的观察者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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