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,34 @@ std::vector<sample_rate_t> AsioAudioDriver::availableOutputDeviceSampleRates() c
612614 };
613615}
614616
617+ static bool isDriverAvailable (long index, const char * name)
618+ {
619+ if (s_adata.baddrivers .find (std::string (name)) != s_adata.baddrivers .end ()) {
620+ return false ;
621+ }
622+
623+ IASIO* driver = 0 ;
624+ LONG ret = s_adata.drivers .asioOpenDriver (index, (void **)&driver);
625+ if (ret == DRVERR_DEVICE_ALREADY_OPEN) {
626+ return true ;
627+ }
628+
629+ if (ret != 0 ) {
630+ s_adata.baddrivers .insert (std::string (name));
631+ return false ;
632+ }
633+
634+ void * sysRef = nullptr ;
635+ bool ok = driver->init (sysRef) == ASIOTrue;
636+ if (!ok) {
637+ s_adata.baddrivers .insert (std::string (name));
638+ }
639+
640+ s_adata.drivers .asioCloseDriver (index);
641+
642+ return ok;
643+ }
644+
615645AudioDeviceList AsioAudioDriver::availableOutputDevices () const
616646{
617647 char names[16 ][32 ];
@@ -626,10 +656,12 @@ AudioDeviceList AsioAudioDriver::availableOutputDevices() const
626656 AudioDeviceList devices;
627657 devices.reserve (count);
628658 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));
659+ if (isDriverAvailable (i, names[i])) {
660+ AudioDevice d;
661+ d.id = names[i];
662+ d.name = d.id ;
663+ devices.push_back (std::move (d));
664+ }
633665 }
634666
635667 return devices;
0 commit comments