-1

I'm developing an app that would be listening waiting for a certain frequency to be detected by the microphone. As far as I researched, I think the best way to do this is by performing a Fast Fourier Transform to the real time audio signal (if anyone think there's a better way to do it, I would love to hear from you). It works fine on iOS but I can't find a way to make it work on watchOS

I implemented the famous tempi-fft with no problems on iOS and Swift 5, the problems comes with different libraries not present or limited on watchOS SDK, as I can't use AudioUnit, AURenderCallback to detect new data on buffer, can't adjust the preferred buffer duration and sample rate to the AudioSession on WatchOS, etc. I'm not an expert at all with the 'audio engineering' side, so I don't know how to approach this. I researched a lot but i didn't find implementations on watchOS for this.

I only found this project AccelerateWatch, but this was uploaded years ago when Accelerate framework was not available on watchOS yet.

Any help on this would be greatly appreciated.

kildos
  • 58
  • 4
  • 1
    welcome to SO :) your question is quite vague, I think you'll get more helpful answers if you can say specifically what you have tried and what isn't working – lewis May 28 '20 at 12:41
  • If you're only interested in a particular frequency then an FFT is overkill - consider using a Goertzel filter instead. – Paul R May 28 '20 at 15:27

1 Answers1

2

I have a chromatic tuner app for the Apple Watch in the iOS App Store that does exactly this, running completely inside the Apple Watch component.

Both the iOS app and the watchOS Watch app component use an AVAudioInputNode installTapOnBus to acquire AVAudioPCMBuffer microphone sample buffers in near real-time. Then the apps feed blocks of the audio sample data to either Goertzel routines or Accelerate framework vDSP FFT functions for further frequency analysis. Then the app does further processing on the FFT frequency data to detect and estimate audio pitch (which is often very different from the FFT frequency magnitude peak). The watchOS display is then animated at frame rate using SpriteKit to output the results.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153