2626#undef UNICODE
2727#include " ASIOSDK/common/asiosys.h"
2828#include " ASIOSDK/common/asio.h"
29+ #include " ASIOSDK/common/iasiodrv.h"
2930#include " ASIOSDK/host/asiodrivers.h"
3031
3132#include " log.h"
@@ -36,6 +37,7 @@ using namespace muse::audio;
3637struct AsioData {
3738 // Drivers list
3839 AsioDrivers drivers;
40+ std::set<std::string> baddrivers;
3941
4042 // ASIOInit()
4143 ASIODriverInfo driverInfo;
@@ -612,6 +614,40 @@ std::vector<sample_rate_t> AsioAudioDriver::availableOutputDeviceSampleRates() c
612614 };
613615}
614616
617+ static bool isDriverAvailable (long index, const char * name)
618+ {
619+ // ! NOTE We remember drivers that are not loaded or initialized
620+ // ! until the end of the application's operation.
621+ // ! Because there are drivers that cannot be reloaded after closing
622+ // ! (to implement checking every time)
623+ // ! For example: Audient USB Audio ASIO Driver
624+ // ! When we reopen it, it crashes.
625+ if (s_adata.baddrivers .find (std::string (name)) != s_adata.baddrivers .end ()) {
626+ return false ;
627+ }
628+
629+ IASIO* driver = 0 ;
630+ LONG ret = s_adata.drivers .asioOpenDriver (index, (void **)&driver);
631+ if (ret == DRVERR_DEVICE_ALREADY_OPEN) {
632+ return true ;
633+ }
634+
635+ if (ret != 0 ) {
636+ s_adata.baddrivers .insert (std::string (name));
637+ return false ;
638+ }
639+
640+ void * sysRef = nullptr ;
641+ bool ok = driver->init (sysRef) == ASIOTrue;
642+ if (!ok) {
643+ s_adata.baddrivers .insert (std::string (name));
644+ }
645+
646+ s_adata.drivers .asioCloseDriver (index);
647+
648+ return ok;
649+ }
650+
615651AudioDeviceList AsioAudioDriver::availableOutputDevices () const
616652{
617653 char names[16 ][32 ];
@@ -626,10 +662,12 @@ AudioDeviceList AsioAudioDriver::availableOutputDevices() const
626662 AudioDeviceList devices;
627663 devices.reserve (count);
628664 for (long i = 0 ; i < count; i++) {
629- AudioDevice d;
630- d.id = names[i];
631- d.name = d.id ;
632- devices.push_back (std::move (d));
665+ if (isDriverAvailable (i, names[i])) {
666+ AudioDevice d;
667+ d.id = names[i];
668+ d.name = d.id ;
669+ devices.push_back (std::move (d));
670+ }
633671 }
634672
635673 return devices;
0 commit comments