Author Topic: Occasional garbled audio on iOS  (Read 249 times)

saga

  • Posts: 2624
Occasional garbled audio on iOS
« on: 24 May '22 - 15:12 »
We've encountered some really odd behaviour with the audio output of our app on iOS. I'm not really sure how we could only notice now, because I can even reproduce it with older versions of our app, so maybe the problem started happening with an iOS update (although my iPad is on 15.4.1, so I didn't update it very recently at least). Updating BASS and BASSMIX to the latest "stuff" versions also didn't help.

Anyway, on to what is actually happening: Once our app has been outputting sound for a while (it could be anything from 10 to 40 minutes), the output becomes garbled - it sounds like there are dropouts and earlier audio frames are being repeated. So for example if there is some speech signal, you can hear the words being played at normal speed, but with a lot of crackling, and then half a second later or so you hear the same word again, still garbled. After about half a minute or so the audio output becomes stable again.

Has anyone else encountered something similar? Based on the error description, can you identify what the issue could be, Ian?

Ian @ un4seen

  • Administrator
  • Posts: 24495
Re: Occasional garbled audio on iOS
« Reply #1 on: 24 May '22 - 17:25 »
Does the problem depend on what you're playing (eg. a type of stream), or does it happen regardless?

To narrow-down what/where the problem is, please try writing the output to a WAV file (using BASS_Encode_Start + BASS_ENCODE_PCM) and see if the problem is present in that. If you're playing a single stream then you can set the WAV writer on that. If that WAV sounds fine, or if you're playing multiple streams simultaneously and the problem is affecting all equally (ie. not any individually), then set a WAV writer on the BASS output mix like this:

Code: [Select]
mixstream = BASS_StreamCreate(0, 0, 0, STREAMPROC_DEVICE, 0); // get output mix stream
wavwriter = BASS_Encode_Start(mixstream, wavfilename, BASS_ENCODE_PCM | BASS_ENCODE_QUEUE, 0, 0); // set WAV writer on it

saga

  • Posts: 2624
Re: Occasional garbled audio on iOS
« Reply #2 on: 25 May '22 - 09:56 »
We're mixing everything into one global mixer, everything coming out of that mixer is affected. I'll try to create a WAV recording as suggested.

saga

  • Posts: 2624
Re: Occasional garbled audio on iOS
« Reply #3 on: 30 May '22 - 12:09 »
As expected, the issue is not in the encoded data. I have uploaded an example recording to the FTP as ios-output-issue.zip. "bass output.flac" shows what's being played, and "speaker output.flac" is what I recorded with a microphone from the iPad's speaker.

Ian @ un4seen

  • Administrator
  • Posts: 24495
Re: Occasional garbled audio on iOS
« Reply #4 on: 30 May '22 - 14:08 »
Was the "bass output.flac" recording taken from the mixer or STREAMPROC_DEVICE stream? If the former, please try getting a recording form the latter too. The STREAMPROC_DEVICE stream recording will show what's being given to iOS, so if the problem isn't present in that then it would seem to be introduced afterwards by iOS. In that case, does it go away if you call BASS_Stop/Pause and BASS_Start again? If that doesn't fix it, does BASS_Init with BASS_DEVICE_REINIT help? Also, does it only happen when using the "voice" output device and/or a specific BASS_CONFIG_IOS_SESSION setting?

saga

  • Posts: 2624
Re: Occasional garbled audio on iOS
« Reply #5 on: 31 May '22 - 17:17 »
- The recording was done with the STREAMPROC_DEVICE code you provided above.
- BASS_Pause/BASS_Start does not appear to help, either.
- It doesn't matter if the Default or Voice output device is used.
- I haven't been able to do the BASS_DEVICE_REINIT test yet, that will follow next, together with removing other iOS session parameters.

It could be coincidence, but the moment I switched to the iOS task switcher, the audio immediately stabilized again in my latest test.

saga

  • Posts: 2624
Re: Occasional garbled audio on iOS
« Reply #6 on: 1 Jun '22 - 12:13 »
Update: BASS_DEVICE_REINIT also didn't help. But once again the artifacts went away immediately when I "grabbed" the application with the 4 finger gesture to show the app overview. Really strange.

Ian @ un4seen

  • Administrator
  • Posts: 24495
Re: Occasional garbled audio on iOS
« Reply #7 on: 1 Jun '22 - 15:56 »
Strange indeed. If you set a DSPPROC callback on the DEVICE stream (via BASS_ChannelSetDSP), and have that log the "length" parameter and a timestamp, does that show the "length" parameter and/or callback interval changing when the problem begins and ends?

Also, are you able to reproduce the problem on multiple devices, and if so, are they running the same iOS version? Are there any devices that you've tried where it isn't happening, and are they running a different iOS version?

saga

  • Posts: 2624
Re: Occasional garbled audio on iOS
« Reply #8 on: 1 Jun '22 - 17:29 »
We have been able the reproduce the problem on iPads of various generations. At the very least iOS 15.4 and 15.5 are affected. A colleague tested on iOS 14.8 for a while and didn't encounter the issue, but since it is rather random in nature, that doesn't have to mean anything. I haven't been able to test without the session flags yet, but I will try to do that tomorrow and also check the callback lengths.

Now that I toyed around with the 4 finger gesture to open the app overview, I also noticed that audio becomes unstable in a similar way when switching to other apps (such as the iOS control panel). It's nowhere near as extreme, so it's hard to tell if it's just some missing frames or if they are reordered similarly to what can be heard in the recording.

saga

  • Posts: 2624
Re: Occasional garbled audio on iOS
« Reply #9 on: 2 Jun '22 - 17:35 »
I was now also able to confirm that removing our custom BASS_CONFIG_IOS_SESSION config didn't help. I wasn't able to reproduce the issue yet with the DSP callback length logging, but that will hopefully happen tomorrow.

saga

  • Posts: 2624
Re: Occasional garbled audio on iOS
« Reply #10 on: 3 Jun '22 - 12:04 »
Strange indeed. If you set a DSPPROC callback on the DEVICE stream (via BASS_ChannelSetDSP), and have that log the "length" parameter and a timestamp, does that show the "length" parameter and/or callback interval changing when the problem begins and ends?
The DSP callback length stays at 8192 at all times.

Ian @ un4seen

  • Administrator
  • Posts: 24495
Re: Occasional garbled audio on iOS
« Reply #11 on: 3 Jun '22 - 13:08 »
OK. Did the time interval between callbacks stay the same too?

Have you so far only reproduced the problem in your main app? If so, can you try reproducing it in a simpler test app, to see if UI/other stuff may be triggering it somehow? For example, does it happen if you just open and play a file in a loop (with BASS_SAMPLE_LOOP set) without any UI updates/etc? If a simple test isn't affected, you could then try temporarily disabling stuff in your main app to hopefully find what's triggering the problem.

I think it's unlikely to make a difference, but I'll also send you the latest dynamic library BASS build to try just in case. BASS and the add-ons will be switching from static to dynamic libraries on iOS (as on the other platforms) at the next BASS release.