Search code examples
iphonecore-audioaudiounitaudio-aliasing

Rendering very high frequency sounds on iOS


I'm trying to use AudioUnit to render a range of high-frequency sounds for a iPhone project (on the order of 8-20KHz), but everything above 12KHz comes out heavily distorted and/or completely the wrong tone. I've rendered the waveforms to an image, and realized that, because the iPhone's hardware sample rate is 44,100Hz, aliasing is to blame (my 22KHz sine wave comes out more like a 100Hz sine wave).

Is there any solution to this? I see a number of "dog whistle" apps on the store, but I'm guessing they're not likely "for reals". Changing the AudioStreamBasicDescription's sample rate doesn't seem to help all that much, but maybe I'm doing it wrong.


Solution

  • You can't really do a great job of rendering a 22KHz sine wave at 44.1K samples/sec, and you can't increase the maximum sample rate above that, I believe. You might be able to use 48KHz, I vaguely remember that being a supported rate.

    On the other hand, you absolutely can do a 22.05 KHz square wave at 44.1ks/s, which will have some insanely-high harmonic frequencies. Maybe that's how the dog whistle apps work?

    If absolute frequency control isn't critical, you'll get better results by rounding your frequencies to multiples of the sample rate. That way, you can at least ensure the aliasing doesn't give you low-frequency beats.