No sound issue kills sound for all applications on the device

We lose sound (without sound) in our application, but it somehow makes all other applications also lose sound. I do not know how it would be possible for us to block the sound from an external application, such as the Apple Music application.

We discard the contents of our AVAudioSession , and there are no differences that we can see between when the sound is working, not. We confirmed that the route output is still the iPhone speaker, even when we lost sound.

This happens on the iPhone 6s and 6s Plus with a speaker. We can โ€œfixโ€ the sound by changing the output route, for example, connecting and disconnecting headphones.

How can I affect the ability to reproduce sound of other applications, which can help eliminate what is happening?

+5
source share
1 answer

We tracked the source of the problem with bad data in the sound buffer that was sent to Core Audio. In particular, one of the stages of sound processing outputs data that was NaN (Not a Number), instead of float in the allowable range +/- 1.0.

It seems that on some devices, if the data contains NaN, it kills the sound of the entire device.

We worked on this by sorting through the audio data, checking the NaN values, and instead converting them to 0.0. Please note that checking if the float is NaN is a weird check (or it seems strange to me). NaN is not equal to anything, including itself.

Some pseudo codes to get around the problem until we get new libraries that have the correct fix:

 float *interleavedAudio; // pointer to a buffer of the audio data unsigned int numberOfSamples; // number of left/right samples in the audio buffer unsigned int numberOfLeftRightSamples = numberOfSamples * 2; // number of float values in the audio buffer // loop through each float in the audio data for (unsigned int i = 0; i < numberOfLeftRightSamples; i++) { float *sample = interleavedAudio + i; // NaN is never equal to anything, including itself if( *sample != *sample ) { // This sample is NaN - force it to 0.0 so it doesn't corrupt the audio *sample = 0.0; } } 
+2
source

Source: https://habr.com/ru/post/1259557/


All Articles