Search code examples
iosswiftfftaccelerate-framework

How to read audio frequency from microphone swift (ultrasonic)?


I am having trouble finding how to read frequencies from audio input. I am trying to listen to very high frequencies (ultrasonic). I've explored several GitHub projects which all were either outdated or malfunctional.

I discovered this guide, but I am having trouble understanding it. https://developer.apple.com/documentation/accelerate/finding_the_component_frequencies_in_a_composite_sine_wave Can anyone provide guidance; has anyone done this before? Thanks


Solution

  • It's worth digging into this piece of sample code: https://developer.apple.com/documentation/accelerate/visualizing_sound_as_an_audio_spectrogram

    The sample calculates the Nyquist frequency of the microphone - for example your device might have a maximum frequency of 20KHz. You can look at the values in each frequency domain page of samples and find the maximum value to derive the dominant frequency.