AudioKit (iOS) - Add an observer to change the frequency / amplitude

I use the AudioKit framework to develop a small application that can listen to the input frequency and amplitude of the microphone and I want to trigger an event (obviously, I want to call a function) every time the frequency and amplitude get certain values ​​-> Event for a certain tone.

I am now 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
   }
}

But honestly, I had serious problems using timeInterval with 0.05 s , for example, my iPhone heats up very quickly, and this is absolutely not what I want.

  • : timeInterval, , (timeInterval: 1.0) , . ( [0,5 ].)

, AudioKit , - , /.

, , - Swift- AKFrequencyTracker -subclass..

, , .

+4

Source: https://habr.com/ru/post/1692101/


All Articles