Solving 6S distorted audio - avoid bad audio format assumptions

This thread has been locked by a moderator.

The internal speaker on the iPhone 6S models only support a sample rate of 48kHz while previous iPhone models supported a collection of sample rates.

Some developers are running into problems (generally classified as distorted or "bad" sounding audio) due to some incorrect assumptions being made when the requested “preferred" sample rate ends up being different than the "current" actual hardware sample rate.

If you ignore these types of difference and for example set the client format to the hardware format expecting 44.1kHz when the actual sample rate is 48kHz, your application will suffer problems like audio distortion with the further possibility of other failures.


Additionally, even if your application is specifying a client format of 44.1kHz, for example the render callback (in the case of the AURemoteIO (kAudioUnitSubType_RemoteIO)) may call you for a varying number of frames in cases where sample rate conversion is involved. Therefore, it is important that the application never assume it will always be rendering a fixed number of audio frames.

In the reported cases we've investigated, this specific issue was always related to developers code making some bad assumptions about audio formats.

Audit your code if you are getting these types of reports from your users, especially if the internal speaker is mentioned.

For more information regarding requesting AVAudioSession Preferences see the Audio Session Programming Guide < https://developer.apple.com/library/ios/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/OptimizingForDeviceHardware/OptimizingForDeviceHardware.html >

Q&A 1631 AVAudioSession - Requesting Audio Session Preferences < https://developer.apple.com/library/ios/qa/qa1631/_index.html> also contains this information.

Q&A 1777 Remote I/O Audio Unit - Handling changes in the inNumberOfFrames value when rendering output < https://developer.apple.com/library/ios/qa/qa1777/_index.html>

See AVAudioSession.h (AVAudioSessionHardwareConfiguration) for methods and properties supporting these settings.


Remember, properties such as the current hardware sample rate may indeed be different then what was preferred by the client and remember to always check and never assume anything when dealing with audio formats.

Up vote post of theanalogkid
12k views