automatic initialization through callback function after abnormal sound card

Started by dreamnyj,

dreamnyj

Hello everyone.

I want to implement the function of automatically reconnecting after a sound card abnormality.

See a routine.

Demonstrating the use of Bass_ The Init function, the last parameter, passes in the callback function.

However, in the header file of Delphi, the defined parameters are not callback functions.


So I want to ask how to implement callback. Or is it true that the header file in Delphi is incomplete and can be added again according to VC's method?

delphi
procedure BASS_DeviceCallback(handle: HDSP; event: DWORD); stdcall;
begin
  if event = BASS_DEVICE_ERROR then 
  begin
    BASS_Free;                     
    BASS_Init(-1, 44100, 0, 0, nil);
  end;
end;

begin
                                        //===============
  BASS_Init(-1, 44100, 0, 0, @BASS_DeviceCallback); 
 
  ...
 
  BASS_Free;     
end;


Ian @ un4seen

The final BASS_Init parameter isn't for a callback function, so that code won't work, but you can detect when a device fails by setting a BASS_SYNC_DEV_FAIL sync (via BASS_ChannelSetSync) on a stream that's on the device. But also BASS will automatically try to recover/reinitialize from a device failure before triggering that sync, so trying to reinitialize in the callback is unlikely to succeed. You would generally just need to call BASS_Start to resume the device once it's available again, eg. when it's reconnected (if it was disconnected).

Note that the BASS_SYNC_DEV_FAIL sync's stream doesn't need to be playing for the sync to be triggered, but the device does need to be active for a failure to be detected, ie. you need to be playing something on the device or enable the BASS_CONFIG_DEV_NONSTOP option (via BASS_SetConfig).

dreamnyj

Quote from: Ian @ un4seenThe final BASS_Init parameter isn't for a callback function, so that code won't work, but you can detect when a device fails by setting a BASS_SYNC_DEV_FAIL sync (via BASS_ChannelSetSync) on a stream that's on the device. But also BASS will automatically try to recover/reinitialize from a device failure before triggering that sync, so trying to reinitialize in the callback is unlikely to succeed. You would generally just need to call BASS_Start to resume the device once it's available again, eg. when it's reconnected (if it was disconnected).

Note that the BASS_SYNC_DEV_FAIL sync's stream doesn't need to be playing for the sync to be triggered, but the device does need to be active for a failure to be detected, ie. you need to be playing something on the device or enable the BASS_CONFIG_DEV_NONSTOP option (via BASS_SetConfig).

I used the recently popular AI for question based coding, and he gave me such an answer, which I am really at a loss. Thank you for the official response. I understand. Thank you.