Windows set output to NULL device

Started by Decker97, 5 Nov '24 - 17:46

Decker97

This is a radio station broadcaster project. I want to be able to let the DJ set the output of the windows program to a NULL device so there is no sound coming from the local speakers, but the channel is still playing for the listeners.

I have this code for adding the null device to a select list for the user:

        public List<BASS_DEVICEINFO> GetOutputDevices(System.IntPtr MainWindowHandle)
        {
            List<BASS_DEVICEINFO> ret = new List<BASS_DEVICEINFO>();
            BASS_DEVICEINFO info = new BASS_DEVICEINFO();

            //Add a device going to null:
            BASS_DEVICEINFO nl = new BASS_DEVICEINFO();
            nl.name = "NULL - No audio output";
            nl.driver = null;
            nl.id = "0";
            nl.flags = BASSDeviceInfo.BASS_DEVICE_ENABLED | BASSDeviceInfo.BASS_DEVICE_TYPE_DIGITAL;
            ret.Add(nl);
            int Count = Bass.BASS_GetDeviceCount();
            for (int n = 0; n < Count; n++)
            {
                BASS_DEVICEINFO add = new BASS_DEVICEINFO();
                Bass.BASS_GetDeviceInfo(n, add);
                if (add.id != null)
                {
                    ret.Add(add);
                }
            }
            return ret;
        }

But, when I try to change to this device, the id is null:
(see attached image).
and it still plays on the default device.

What am I doing wrong?

TIA.

-Mike


Ian @ un4seen

The "No sound" device is always device 0. So you can use it like this, for example:

Bass.BASS_Init(0, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle);

If you want to move a BASS channel between devices then you can use BASS_ChannelSetDevice for that. Note that the new device needs to be initialized before you can do that. Please see the documentation for details.

Decker97

hmm, I'm currently using SetDevice, not SetChannelDevice:

            LogText("InitBass()");
            if (!BassInitialized)
            {
                int i = 1;
                Devices = new List<Device>();
                foreach (var item in GetOutputDevices(MainWindowHandle))
                {
                    Bass.BASS_Init(i, 44100, BASSInit.BASS_DEVICE_DEFAULT, m_output_handle);
                    Device d = new Device();
                    d.DeviceIndex = i;
                    d.Handle = item.ToString();
                    Devices.Add(d);
                    i++;
                }
                Bass.BASS_SetDevice(CurrentDeviceIndex);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, LATENCY);
                BassInitialized = true;
            }

Decker97

I got it working with ChannelSetDevice and controlling my devices better. Had to start the InitBass at zero as well.

-Mike