Reputation: 45
I want to access the list of driver's names with the C++ ASIO SDK of Steinberg to select the driver then load it. So I try to use the hostsample.cpp exemple to write my code, it compile but dont want to execute:
#include <iostream>
#include <thread>
#include "asio.h"
#include "asiodrivers.h"
//----DBG MACROS----//
#define DBG(x) std::cout << #x << ": " << x << std::endl;
#define NL std::cout << std::endl; //new line
//------------------//
extern AsioDrivers *asioDrivers;
bool loadAsioDriver(char *name);
void audioTask(void)
{
auto maxDrivers {asioDrivers->asioGetNumDev()}; //The problem is here
ASIODriverInfo drvInfo{};
ASIOInit(&drvInfo);
//print info
NL;
DBG(drvInfo.asioVersion);
DBG(drvInfo.driverVersion);
DBG(drvInfo.errorMessage);
DBG(drvInfo.name);
DBG(drvInfo.sysRef);
}
int main(void)
{
std::thread audioThread(audioTask);
audioThread.join();
return 0;
}
the make command return this:
make: *** [makefile:31: run] Error -1073741819
Can you tell me where I'm going wrong and what I should do? the ASIO doc is not very user friendly...
My configuration is as follows:
OS: Window 11
compiler: g++ (MinGW64)
compile with: handmade makefile
c++ version: 23
compiler flags: -Wall -Wextra -Wpedantic
I'm trying to include other headers, I can't find another topic on this. I also ask chatGPT but it's complicated to get the right code.
Upvotes: 0
Views: 223
Reputation: 45
I found the solution, to load an ASIO driver you must:
asioDrivers->getDriverNames(char **names, long maxDrivers)
asioDrivers->loadDriver(char *name)
with a name taken from the list of devices just before#include <iostream>
#include <thread>
#include <string>
#include <vector>
#include "asio.h"
#include "asiodrivers.h"
extern AsioDrivers *asioDrivers;
void audioTask(void)
{
asioDrivers = new AsioDrivers();
//get number of devices
long deviceCount { asioDrivers->asioGetNumDev() };
//create a array of 32-char strings
std::vector<std::string> devicesNames(deviceCount, std::string(32, '\0'));
//print the index and name of each device
for(std::size_t i {0}; i < devicesNames.size(); ++i)
{
asioDrivers->asioGetDriverName(i, devicesNames[i].data(), 32);
std::cout << '[' << i << "]: " << devicesNames[i] << std::endl;
}
//select a device and load it
int index;
std::cin >> index;
asioDrivers->loadDriver(devicesNames[index].data());
delete asioDrivers;
}
int main(void)
{
std::thread audioThread(audioTask);
audioThread.join();
return 0;
}
Upvotes: 1