How to Fix Sine Tone in AUSampler

Imagine you are writing an app that uses an AUSampler. For a while the app is happily playing samples as intended, either live via MIDI, live via onscreen keyboard, per MIDI file, or by any other means. Suddenly some samplers (or sampler, if you have only one) are playing a sine tone instead of the preset it was playing before.

This may have happened due to an AVAudioSessionInterruption. In your handler you may have restarted AVAudioEngine. Or you may have restarted AVAudioEngine due to some circumstance.

The sine tone is the default setting of AUSampler. This is also the state after the Audio Unit is reset. This happens for example when AVAudioEngine is stopped. When this happens you can simply reload the SoundFont preset, and the sine tone is gone.

I assume this works not only with SoundFonts but also with other formats such as EXS24 or raw WAVE files. In my app I used samplers only with SoundFonts.