Author Topic: Bass.BASS_Init Method  (Read 157 times)

Chris Oakley

  • Posts: 167
Bass.BASS_Init Method
« on: 12 Oct '21 - 14:28 »
I was just wondering if anyone knows the score with this scenario:

If I do:

Code: [Select]
Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)

Then call it again it will return False as it's already been initialized. That's fine. No issues there.

However, what if I (or the user of the app, let's be honest) decides to switch to DirectSound, which would then raise:

Code: [Select]
Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DSOUND, IntPtr.Zero)

This would also return false.

So, how do I reinit the device to make the switch to DSOUND?

I really struggle getting my head around the DS and WASAPI side of things in the library.

Chris

  • Posts: 1989
Re: Bass.BASS_Init Method
« Reply #1 on: 12 Oct '21 - 14:52 »
Code: [Select]
Bass_Free();
Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DSOUND, IntPtr.Zero);

or if using multiple Devices and you want switch all  device to DirectSound

Code: [Select]
Bass_SetDevice(DevNr);
Bass_Free();
Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_DSOUND, IntPtr.Zero);
« Last Edit: 12 Oct '21 - 15:05 by Chris »

Chris Oakley

  • Posts: 167
Re: Bass.BASS_Init Method
« Reply #2 on: 12 Oct '21 - 14:56 »
Ahhhh - Thanks Chris. I saw that but wasn't sure if that was the way to go. Brilliant  :)

Ian @ un4seen

  • Administrator
  • Posts: 23997
Re: Bass.BASS_Init Method
« Reply #3 on: 12 Oct '21 - 15:34 »
Since BASS 2.4.16, you can actually change the initialization settings without first freeing the device, by using the new BASS_DEVICE_REINIT flag. For example:

Code: [Select]
BASS_Init(2, 44100, BASS_DEVICE_DSOUND | BASS_DEVICE_REINIT, NULL, NULL);

If you're using BASS.Net (it looks like you are), I don't think it includes the BASS_DEVICE_REINIT flag yet, but it should be possible to use it via "(BASSInit)128" instead in the meantime. Note the "device" parameter cannot be -1 when using the BASS_DEVICE_REINIT flag.

Chris Oakley

  • Posts: 167
Re: Bass.BASS_Init Method
« Reply #4 on: 12 Oct '21 - 18:38 »
Thanks Ian, that's good to know. Could you possibly clear something up for me regarding the following. If I run this code I get the name of the device and its index number:

Code: [Select]
                    For i As Integer = 1 To Bass.BASS_GetDeviceCount - 1
                        Dim info As BASS_DEVICEINFO = Bass.BASS_GetDeviceInfo(i)
                        If info IsNot Nothing Then
                            Debug.Print(info.name & " : " & i)
                        End If
                    Next

However when I run this I get different index numbers:

Code: [Select]
                Dim info As BASS_WASAPI_DEVICEINFO
                For a As Integer = 0 To BassWasapi.BASS_WASAPI_GetDeviceCount - 1
                    info = BassWasapi.BASS_WASAPI_GetDeviceInfo(a)
                      If info.IsEnabled AndAlso info.IsLoopback Then
                            Debug.Print(info.name & " : " & a)
                      End If
                Next

I realise one is WASAPI and the other is just using whatever the default init is, which I believe is WASAPI on Windows 10, but I would have thought if these were both WASAPI, wouldn't they be the same numbers?

Or am I missing something?

Ian @ un4seen

  • Administrator
  • Posts: 23997
Re: Bass.BASS_Init Method
« Reply #5 on: 13 Oct '21 - 14:53 »
BASS and BASSWASAPI have different device lists. For example, BASS has separate lists for playback and recording devices, while BASSWASAPI has a single list for both. If you would like to find a corresponding device in both lists, you can do that by looking for matching BASS_DEVICEINFO "driver" and BASS_WASAPI_DEVICEINFO "id" members (also check that the BASS_DEVICE_LOOPBACK flag presence matches).

Note that since BASS includes support for shared mode WASAPI itself these days, the BASSWASAPI add-on isn't needed for that any more. It's only really still needed for exclusive mode.

Chris Oakley

  • Posts: 167
Re: Bass.BASS_Init Method
« Reply #6 on: 14 Oct '21 - 16:44 »
Brilliant Ian, thanks for clearing that up. I just couldn't make head-nor-tail of it. That new ReInit is great and sorted out exactly what I needed to do.