NoSound processing

Started by Chris Oakley,

Chris Oakley

If I'm using the NoSound device to create a mixer on like this:
Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
_Mixer = BassMix.BASS_Mixer_StreamCreate(48000, 2, BASSFlag.BASS_MIXER_NONSTOP)
Bass.BASS_ChannelSetAttribute(_Mixer, BASSAttribute.BASS_ATTRIB_BUFFER, 0F)
Bass.BASS_ChannelPlay(_Mixer, False)

Then I load an audio file and add it to the mixer:
_Stream = Bass.BASS_StreamCreateFile(_Filename, 0, 0, BASSFlag.BASS_STREAM_DECODE Or BASSFlag.BASS_ASYNCFILE)
BassMix.BASS_Mixer_StreamAddChannel(_Mixer, _Stream, BASSFlag.BASS_DEFAULT)

What is going on internally to process the playback of the local file? What can happen that could make it pause playback and then continue? I take it there is a loop that clocks against something in order to process the samples?

I'm asking because I'm still getting pausing issues on certain machines and it's not obvious what the problem is.

Ian @ un4seen

The "no sound" device has a high priority thread that periodically (according to the BASS_CONFIG_DEV_PERIOD setting) "mixes" the playback buffers (actually just discards unless DSP/FX is set on the device) from the channels that are playing on it. As you have playback buffering disabled (BASS_ATTRIB_BUFFER=0) on the mixer, that thread will also be doing the mixer's processing, which includes decoding the file that you plugged into it. If the processing takes too long then the device's next update cycle could be delayed, but it will try to catch-up by doing the next cycle immediately in that case. BASS will currently only catch-up one cycle (there'll be an option to configure this in 2.4.18), so if the delay is longer than that then it will affect the total amount of data processed (ie. less than expected). You can reduce the chances of that by using a higher BASS_CONFIG_DEV_PERIOD setting (note it must be set before BASS_Init).

Chris Oakley

Thanks Ian. This is interesting on a couple of fronts...

QuoteAs you have playback buffering disabled (BASS_ATTRIB_BUFFER=0) on the mixer, that thread will also be doing the mixer's processing, which includes decoding the file that you plugged into it.

If I was to change the BASS_ATTRIB_BUFFER to be 100 instead of 0, does that change how it's being processed?

Quote(actually just discards unless DSP/FX is set on the device)

I'm not sure what this means. I do have a DSP applied to the mixer. Is it possible that a delay in the DSP could cause a problem with processing the NoSound device?

As you can imagine I can't believe the problem is the files. They're local to the machine i.e on the C:\ drive, so it can't be a bottle neck there, not to the extent we're seeing.

Ian @ un4seen

Quote from: Chris Oakley
QuoteAs you have playback buffering disabled (BASS_ATTRIB_BUFFER=0) on the mixer, that thread will also be doing the mixer's processing, which includes decoding the file that you plugged into it.

If I was to change the BASS_ATTRIB_BUFFER to be 100 instead of 0, does that change how it's being processed?

Yes. The mixer's procesing would then be in an update thread (see BASS_CONFIG_UPDATETHREADS) instead of the device's thread. Please note BASS_ATTRIB_BUFFER should (when not 0) be set greater than BASS_CONFIG_UPDATEPERIOD.

Quote from: Chris Oakley
Quote(actually just discards unless DSP/FX is set on the device)

I'm not sure what this means.

I was referring to DSP/FX (inc. encoders) set on the "No Sound" device output mix, like this:

DWORD devicestream = BASS_StreamCreate(STREAMPROC_DEVICE, 0, 0, 0, 0); // get the device stream
BASS_ChannelSetDSP(devicestream, DspProc, 0, 0); // set a DSP function on it

If you don't do anything like that then the "No Sound" device can just discard data instead of mixing it (to save some time), because the mix will never be seen/heard anyway.

Quote from: Chris OakleyI do have a DSP applied to the mixer. Is it possible that a delay in the DSP could cause a problem with processing the NoSound device?

Yes, if the delay is longer than one update cycle (eg. takes over 20ms to process 10ms of data) then there would be less data than normal processed. To see if they're related, do your problems go away if you remove the DSP?

Chris Oakley

I do have DSP/FX in place on the NoSound mixers. I do employ the DSP_StreamCopy which copies the NoSound mixer and sends it to another mixer which is set to a physical device, so I suspect underneath it will use a DSPProc. Would you know if that's the case?

The NoSound mixer will have the other DSP Plugin for audio processing using StereoTool. I can't really turn it off because it's broadcasting a live station.

I guess the first thing to try will be BASS_ATTRIB_BUFFER and setting that to something other than 0, but keeping it low to keep latency low.

It's just so frustrating because it can take a few hours for the problem to occur, then other times it can be days or weeks.

Chris Oakley

Actually, with regard to the above, I tried setting the Mixer BASS_ATTRIB_BUFFER to 100 which is the BASS_CONFIG_UPDATEPERIOD but there is too much latency, so using anything other than 0 is not viable.

Ian @ un4seen

Going back to the first post, please clarify what you mean by "pausing issues", ie. what exactly is that and where are you seeing it? Is it in the "No Sound" device's mixer or the "physical" device's mixer, or perhaps the broadcast?

Chris Oakley

Ian I've sent a file to the ftp for you to watch and listen to. It's called bandicam 2025-04-27 05-54-33-954.mp4

What you will see on the screen is two applications. The one that takes the full screen isn't the problem one - that is just a surface so ignore that.

The one causing the issue is the smaller window one. I've uploaded a screenshot of that too so you have a reference Screenshot 2025-06-26 144150.png

You can hear right away that U2 is pausing repeatedly and this continues.

At 3:27 when the next song starts as well as the production you can see that both are having the same problem. It's not like one player is okay and the other isn't. They all suffer equally. Each Player has a mixer going to NoSound.

You should be able to tell that the playback countdown is also affected so the pausing is affecting the playback, not just what is being heard.

Ian @ un4seen

Thanks for the recording. I guess we're hearing the "physical device" mixer in that? Is it created in the same way as the "no sound" mixer in the 1st post, ie. with BASS_MIXER_NONSTOP? Do you have BASS_SYNC_STALL syncs set on any of the mixers or sources, and if so, are any triggered when the problem happens? And is the problem present in the broadcast too? I presume the broadcast is fed by the "no sound" mixer, not the "physical device" mixer?

Chris Oakley

So the NoSound mixer remains as such. Another mixer is then created which is set to the output device. In the case of this example video it's a VB Cable. The audio on the VB Cable is what is being recorded. This mixer doesn't have BASS_MIXER_NONSTOP on it.

The audio gets onto this other mixer using a DSP_StreamCopy with the NoSound mixer as the source and the VB Cable mixer as the target.

I'm not seeing any mixer stalls from what I can see and yes, the problem is in the broadcast.

Ian @ un4seen

Quote from: Chris OakleySo the NoSound mixer remains as such. Another mixer is then created which is set to the output device. In the case of this example video it's a VB Cable. The audio on the VB Cable is what is being recorded. This mixer doesn't have BASS_MIXER_NONSTOP on it.

Do the mixers and VB Cable(s) all have the same sample rate, ie. 48000 as in the first post? If not, try setting them the same. That'll help performance and sound quality even if not the main issue.

Quote from: Chris OakleyI'm not seeing any mixer stalls from what I can see

Are you only setting BASS_SYNC_STALL syncs on the mixers, not the sources? If so, you could try setting them on the sources too and see if they get triggered. Note you should use BASS_ChannelSetSync when a channel is being played by BASS (eg. BASS_ChannelPlay) and BASS_Mixer_ChannelSetSync when it's being played by BASSmix (eg. BASS_Mixer_StreamAddChannel).

Anyway, to see if it'll help, here's a BASS update that includes the "catch-up" config option that I mentioned earlier:

    www.un4seen.com/stuff/bass.zip

The new option is called BASS_CONFIG_NOSOUND_MAXDELAY (defined as 76), which sets the "No Sound" device's catch-up limit in milliseconds. It defaults to 100ms, which is already higher than what you effectively had before (unless you set BASS_CONFIG_DEV_PERIOD >= 100), so you could initially just leave it at that. If it seems better but not totally fixed then you could try higher settings. The setting can be changed at any time, so you could even try raising it if/when the problem begins and see if that stops it.