-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_asio.cpp
117 lines (92 loc) · 2.76 KB
/
test_asio.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <juce_audio_devices/juce_audio_devices.h>
#include <combaseapi.h>
using namespace juce;
class MyLogger : public Logger
{
protected:
virtual void logMessage(const String& message)
{
std::cout << message << std::endl;
}
};
class ASIOAudioIODeviceCallback : public AudioIODeviceCallback
{
public:
ASIOAudioIODeviceCallback(bool& started) : _started(started)
{
}
virtual void audioDeviceIOCallbackWithContext(const float* const* inputChannelData, int numInputChannels, float* const* outputChannelData, int numOutputChannels,
int numSamples, const AudioIODeviceCallbackContext& context) override
{
}
void audioDeviceAboutToStart(AudioIODevice* device) override
{
_started = true;
}
void audioDeviceStopped() override
{
}
private:
bool &_started;
};
int main(int argc, char* argv[])
{
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " ASIO_Device_Name\n";
return 1;
}
CoInitialize(nullptr);
ConsoleApplication app;
ConsoleApplication::Command command;
command.command = ([](const auto& args) {
String asioDeviceName = args.arguments[0].text;
AudioDeviceManager audioDeviceManager;
audioDeviceManager.initialiseWithDefaultDevices(0, 2); // Stereo output
AudioIODeviceType* asioDeviceType = nullptr;
for (auto deviceType : audioDeviceManager.getAvailableDeviceTypes()) {
if (deviceType->getTypeName() == "ASIO") {
asioDeviceType = deviceType;
}
}
if (asioDeviceType == nullptr) {
std::cerr << "ASIO not available!\n";
return;
}
StringArray asioDeviceNames = asioDeviceType->getDeviceNames();
int asioDeviceIndex = asioDeviceNames.indexOf(asioDeviceName);
if (asioDeviceIndex == -1) {
std::cerr << "ASIO device '" << asioDeviceName << "' not found!\n";
for (auto name : asioDeviceNames) {
std::cerr << name << std::endl;
}
return;
}
AudioIODevice* asioDevice = asioDeviceType->createDevice(asioDeviceNames[asioDeviceIndex], String());
if (asioDevice == nullptr) {
std::cerr << "Failed to create ASIO device!\n";
return;
}
BigInteger inputChannelMask;
inputChannelMask.setRange(1, 1, true);
String openMessage = asioDevice->open(inputChannelMask, inputChannelMask, 48000.0, 128);
if (openMessage.isNotEmpty()) {
std::cerr << "Failed to open ASIO device: " << openMessage.toStdString() << std::endl;
return;
}
bool started = false;
asioDevice->start(new ASIOAudioIODeviceCallback(started));
// Wait 5 seconds
Thread::sleep(5000);
if (started) {
std::cout << "ASIO device started successfully!\n";
} else {
std::cout << "Failed to start ASIO device!\n";
}
return;
});
app.addDefaultCommand(command);
auto mm = MessageManager::getInstance();
juce::Logger::setCurrentLogger(new MyLogger());
initialiseJuce_GUI();
app.findAndRunCommand(argc, argv);
}