Skip to content

Commit 0df9681

Browse files
committed
added check of available asio drivers
1 parent edd9fea commit 0df9681

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/framework/audio/driver/platform/win/asio/asioaudiodriver.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
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;
3637
struct 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+
615645
AudioDeviceList 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;

src/framework/audio/driver/platform/win/asio/asioaudiodriver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class AsioAudioDriver : public IAudioDriver, public async::Asyncable
5959
std::thread m_thread;
6060
std::atomic<bool> m_running = false;
6161

62+
AudioDeviceID m_audioDeviceId;
6263
async::Channel<Spec> m_activeSpecChanged;
6364
async::Notification m_availableOutputDevicesChanged;
6465
};

0 commit comments

Comments
 (0)