Author Topic: Detecting Audio Device Fail (Disconnect)  (Read 117 times)

David_AVD

  • Posts: 44
Detecting Audio Device Fail (Disconnect)
« on: 28 Mar '21 - 02:44 »
I know it's possible to detect when a stream fails and check BASS_IsStarted to see if a device is ready again, but is it possible to be notified without a stream being used?

For example, I'd like to know if any of the audio devices that I'll be needing have become unavailable well before I try and use them.

I realise I can poll each one at some interval (not sure on the overhead that will add?) but an event would be nice if possible.

It would also be nice to be notified when it connects again so it can be reinitialised.

Ian @ un4seen

  • Administrator
  • Posts: 23470
Re: Detecting Audio Device Fail (Disconnect)
« Reply #1 on: 29 Mar '21 - 17:40 »
You can set a BASS_SYNC_DEV_FAIL sync (via BASS_ChannelSetSync) on the stream to be notified when its device fails. You can then use BASS_Start to resume when the device is ready to go again. BASS doesn't have connected/disconnected device notifications, but on Windows you could use BASSWASAPI for that (see BASS_WASAPI_SetNotify) while still using BASS for playback.

David_AVD

  • Posts: 44
Re: Detecting Audio Device Fail (Disconnect)
« Reply #2 on: 30 Mar '21 - 03:41 »
Thanks, I'll have a play with that.

David_AVD

  • Posts: 44
Re: Detecting Audio Device Fail (Disconnect)
« Reply #3 on: 6 Apr '21 - 23:13 »
I've had a bit of a play around with BASS_WASAPI_SetNotify but the device numbers I'm getting in the callback are not what I expected.

Instead of 0, 1, 2 I'm getting 12, 13 & 78 for the device number.

Ian @ un4seen

  • Administrator
  • Posts: 23470
Re: Detecting Audio Device Fail (Disconnect)
« Reply #4 on: 7 Apr '21 - 17:36 »
Yes, BASS and BASSWASAPI have their own device lists, so the device numbers won't be the same in both. The same device can be identified by it having matching BASS_DEVICEINFO "driver" and BASS_WASAPI_DEVICEINFO "id" values. For example, your WASAPINOTIFYPROC callback function could do this:

Code: [Select]
BASS_WASAPI_DEVICEINFO wi;
BASS_WASAPI_GetDeviceInfo(device, &wi); // get WASAPI device info
BASS_DEVICEINFO di;
int bassdevice = 0;
for (int a = 1; BASS_GetDeviceInfo(a, &di); a++) {
if (!strcmp(di.driver, wi.id)) { // found the corresponding BASS device
bassdevice = a;
break;
}
}

David_AVD

  • Posts: 44
Re: Detecting Audio Device Fail (Disconnect)
« Reply #5 on: 7 Apr '21 - 21:36 »
Excellent. Thank you.