Author Topic: Swapping to using WASAPI and back again  (Read 83 times)

Steve

  • Posts: 16
Swapping to using WASAPI and back again
« on: 5 Dec '17 - 19:29 »
Hi,

In my game I want to swap from playing music in the normal way (a stream from an mp3 say) to playing from an external source using WASAPI.

When playing music normally you call BASS_Init with the device set to -1 (To use the default output)
When using WASAPI you need to call BASS_Init with the device set to 0 (i.e. no sound)

What is the proper was to swap between these two modes?

At the moment when swapping from 'normal' to using WASAPI I just all BASS_Init(0, ... ) again.

This seems to work fine, but is this the correct way?  (Should I call BASS_Free first?)
 
I did try calling BASS_SetDevice(0), but that had an error saying device not initialised.

Thanks...

Wishmaster

  • Posts: 151
Re: Swapping to using WASAPI and back again
« Reply #1 on: 6 Dec '17 - 02:09 »
you can try to initialize all existing devices inc. Device 0 (No Sound)
then just use BASS_SetDevice() to set the Device Nr.  ;)
something like this Delphi Code

Code: [Select]
function Bass_Init_AllDevices(Freq : Cardinal = 44100) : Boolean;
var
 DevInfo  : BASS_DEVICEINFO;
 Device : Integer;
 Flag : Cardinal;
begin
  Result:= False;

 (* Free all Devices *)
   Device:= 0;
  while (BASS_GetDeviceInfo(Device, DevInfo) <> False) do
   begin
    if BASS_SetDevice(Device) then
     begin
      BASS_Free();
     end;
    Inc(Device);
   end;


 (* Init Devices *)
   Flag:= 0; // BASS_DEVICE_LATENCY

   Device:= 0;
  while (BASS_GetDeviceInfo(Device, DevInfo) <> False) do
   begin
    if not BASS_Init(Device, Freq, Flag, AppHWND, nil) then
     begin

     end;

    Inc(Device);
   end;


 Result:= True;
end;

Ian @ un4seen

  • Administrator
  • Posts: 20433
Re: Swapping to using WASAPI and back again
« Reply #2 on: 6 Dec '17 - 14:36 »
Yep, you could keep both devices initialized and set the one that you want to use (eg. when creating a stream) via BASS_SetDevice.

Steve

  • Posts: 16
Re: Swapping to using WASAPI and back again
« Reply #3 on: 7 Dec '17 - 09:28 »
Thanks for the info guys.

I've got it working now. I didn't realise BASS_Init was per device.