Author Topic: Debugging Underflow (redux)  (Read 427 times)

elan

  • Posts: 33
Debugging Underflow (redux)
« on: 11 Jul '19 - 00:39 »
On iOS, we're getting reports of audio dropouts; I've captured some logs and they are indeed getting BASS_SYNC_STALL triggered on the mixer. I'm not entirely sure how to go about diagnosing the root cause (in these cases, the source stream (network or disk) should be entirely buffered, so it would appear to be an issue between those two ends).

This is the configuration:

  BASS_SetConfig(BASS_CONFIG_UPDATETHREADS, 3);
  BASS_SetConfig(BASS_CONFIG_DEV_PERIOD, 150);
  BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD, 75);
  BASS_SetConfig(BASS_CONFIG_BUFFER, 150);
  BASS_SetConfig(BASS_CONFIG_IOS_MIXAUDIO, 0);
  BASS_SetConfig(BASS_CONFIG_IOS_NOCATEGORY, 1);
  BASS_SetConfig(BASS_CONFIG_ASYNCFILE_BUFFER, 1024 * 256);

(and we're setting the final device output buffer to 150ms via macOS calls directly, but since we're seeing BASS_SYNC_STALL that seems not to be the issue)

The stream graph looks like:

1. Mixer
2. Decode stream with STREAMPROC for gapless
3a. If on disk, decode stream BASS_StreamCreateFileUser BASS_ASYNCFILE | STREAMFILE_NOBUFFER with standard buffered I/O functions. Have also tried BASS_StreamCreateFile but same issue.
3b. If over network, BASS_StreamCreateFileUser with BASS_ASYNCFILE | STREAMFILE_NOBUFFER with our custom buffered I/O functions (essentially VFS).

Now I understand that the mixer stream has to have a small buffer for real-time effects such as fading. But if it's stalling, my theory is that perhaps one of the decode streams is underflowing, perhaps because it has little/no buffer? It seems like BASS_ATTRIB_BUFFER is not what I want (doesn't work on decode streams).

Looking for advice about how to diagnose and tweak streams to prevent this from happening. As I said above, the data in 3a or 3b should be readily available (via disk or via our custom network buffering code).

Many thanks in advance!
« Last Edit: 11 Jul '19 - 03:05 by elan »

Ian @ un4seen

  • Administrator
  • Posts: 22253
Re: Debugging Underflow (redux)
« Reply #1 on: 11 Jul '19 - 14:55 »
To help narrow down where the problem is, please try setting a "mixtime" BASS_SYNC_STALL sync on the mixer source too via BASS_Mixer_ChannelSetSync and see if that gets triggered. Also, does raising the BASS_CONFIG_BUFFER setting (before creating the mixer) prevent the stalling?

elan

  • Posts: 33
Re: Debugging Underflow (redux)
« Reply #2 on: 12 Jul '19 - 20:36 »
Thanks as always for the quick and helpful reply!

Raising BASS_CONFIG_BUFFER to 250 actually seemed to resolve the issue. I may be slightly confused about how that affects latency.

  • Clearly any chances to mixer sources will have this added latency because data has to travel through the buffer.
  • If I use BASS_FX_VOLUME on the mixer, that seems to take effect at the "leading edge" meaning it seems to only be affected by device latency, and not mixer latency / buffer size.
  • If I use BASS_FX_BFX_PEAKEQ on the mixer, that seems to take effect at the "trailing edge" meaning it is affected by the mixer buffer size.

Am I picturing this correctly?

Ian @ un4seen

  • Administrator
  • Posts: 22253
Re: Debugging Underflow (redux)
« Reply #3 on: 15 Jul '19 - 14:19 »
Do you mean BASS_ATTRIB_VOL rather than BASS_FX_VOLUME? The BASS_ATTRIB_VOL/PAN/FREQ settings are applied last thing, as the buffered data from all playing channels is mixed together for the final output, so they aren't delayed by the playback buffer length. Most other attributes and all FX settings are applied when the data is put in the playback buffer, so they are delayed by the buffer's length.

It is possible to avoid buffer latency affecting FX by applying the FX to the final output instead of the mixer. You can do that by getting the device's stream from BASS_StreamCreate (with STREAMPROC_DEVICE) and setting the FX on that stream. Note the FX will apply to the entire output (from BASS) then, not only the mixer (in case you're playing other things too).

elan

  • Posts: 33
Re: Debugging Underflow (redux)
« Reply #4 on: 18 Jul '19 - 08:34 »
Yes, I meant BASS_ATTRIB_VOL, sorry for misspeaking (I'm using BASS_FX_VOLUME on some other streams, hence my confusion). Thanks for the clarification and the hint on STREAMPROC_DEVICE, that's super useful.

Really appreciate your support, and BASS in general; in my decades of experience with software, it's rare to come across a project which works as well and reliably across as many platforms as BASS does.