Author Topic: Using BASS without audio device  (Read 173 times)

Hanuman

  • Posts: 107
Using BASS without audio device
« on: 26 Mar '23 - 23:47 »
Not that I care that much but someone asked me.

Is it possible to use BASS for encoding on a server without audio support?

I made some changes to separate plugins initialization from device output initialization.

If I try to create a Stream without calling Bass.Init, it gives an Init error. And Init will fail on a audio-less server.

Code: [Select]
// ManagedBass.Bass.Init(deviceId, 48000)
chan = Bass.CreateStream(filePath, Flags: BassFlags.Float | BassFlags.Decode).Valid();

btw in what cases is the 48000 parameter used?

Ian @ un4seen

  • Administrator
  • Posts: 25060
Re: Using BASS without audio device
« Reply #1 on: 27 Mar '23 - 11:37 »
You can use device=0 in your BASS_Init call for the "No Sound" device when there is no soundcard, or if you just don't don't need to hear anything. The "freq" parameter is still needed, as the "No Sound" device can still produce output (accessible via the STREAMPROC_DEVICE option) even if it isn't heard. It's also used as a default sample rate by some things (eg. BASS_MusicLoad).

Hanuman

  • Posts: 107
Re: Using BASS without audio device
« Reply #2 on: 27 Mar '23 - 14:37 »
with output, when is that freq parameter used?

It defaults to 44100, I set it to 48000; but is there a need or reason to make this configurable?

Ian @ un4seen

  • Administrator
  • Posts: 25060
Re: Using BASS without audio device
« Reply #3 on: 27 Mar '23 - 17:03 »
On most platforms, BASS can detect and use the device's current rate, and so the BASS_Init "freq" parameter has no effect on the output. An exception is on Linux, where the specified rate will be used if it's supported. It can also be applied on macOS/iOS (changing the device's current rate) with the BASS_DEVICE_FREQ flag. In all cases, BASS's actual output rate can be confirmed with BASS_GetInfo.

Hanuman

  • Posts: 107
Re: Using BASS without audio device
« Reply #4 on: 27 Mar '23 - 18:25 »
OK on Linux, I would create a mixer with the configured "output sample rate", but that won't be enough, because that will then be re-resampled at what was passed in Init?

Is there a way to change the output sample rate at runtime after Init was called?

Ian @ un4seen

  • Administrator
  • Posts: 25060
Re: Using BASS without audio device
« Reply #5 on: 28 Mar '23 - 13:28 »
You can change the output rate (on platforms where the "freq" parameter it used) by calling BASS_Init again with the new rate and the BASS_DEVICE_REINIT flag.

Hanuman

  • Posts: 107
Re: Using BASS without audio device
« Reply #6 on: 3 Apr '23 - 05:18 »
Quote
BASS_DEVICE_REINIT   Reinitialize the device while retaining the device's existing BASS channels and 3D settings. This flag cannot be used with device -1.

Why can't it be used with the default device?

It seems that the ReInit and Software flags are missing from ManagedBass
https://github.com/ManagedBass/ManagedBass/blob/43f9d4b363f51e27819b033c66eae7084257581e/src/Bass/Shared/Bass/Enumerations/DeviceInitFlags.cs

What's the actual flag value? It's not in the doc
http://bass.radio42.com/help/?topic=html/5bf1ebdd-a59c-60b5-4866-6c3ae26e2de5.htm

I also just saw the Win parameter that I hadn't been using. What's the drawback of not using it?

Quote
The win parameter is only used with DirectSound output on Windows and is ignored in all other cases.

Ian @ un4seen

  • Administrator
  • Posts: 25060
Re: Using BASS without audio device
« Reply #7 on: 3 Apr '23 - 12:25 »
Quote
BASS_DEVICE_REINIT   Reinitialize the device while retaining the device's existing BASS channels and 3D settings. This flag cannot be used with device -1.

Why can't it be used with the default device?

It can be used with the "Default" device but not device number -1, which isn't a real device but rather maps to the current default device. To ensure that the correct device is reinitialized, you need to use the real device number, which you can get from BASS_GetDevice.

It seems that the ReInit and Software flags are missing from ManagedBass
https://github.com/ManagedBass/ManagedBass/blob/43f9d4b363f51e27819b033c66eae7084257581e/src/Bass/Shared/Bass/Enumerations/DeviceInitFlags.cs

BASS_DEVICE_REINIT is 128, and BASS_DEVICE_SOFTWARE is 0x80000. If any other flags are missing, you can get their values from the BASS.H file included in the BASS package.

I also just saw the Win parameter that I hadn't been using. What's the drawback of not using it?

Quote
The win parameter is only used with DirectSound output on Windows and is ignored in all other cases.

As stated, it's ignored entirely when not using DirectSound output, but it'll probably be fine to set it to 0 even when DirectSound is used (BASS_Init will give DirectSound the desktop window handle then).