mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-11-10 04:37:37 +01:00
Make compatible with rtaudio API 5 and 6.
Recent rtaudio changed the API to not throw exceptions anymore and also have DeviceIDs not queried by index but IDs that are provided separately ( https://github.com/thestk/rtaudio/releases ). Adapt the code-base to be compatible with the old and the new API as we have to exepect that in a transition period both APIs are common on various build platforms.
This commit is contained in:
parent
052167962d
commit
23ae66151b
@ -31,6 +31,10 @@ public:
|
|||||||
monoPacker.init(&s2m.out, 512);
|
monoPacker.init(&s2m.out, 512);
|
||||||
stereoPacker.init(_stream->sinkOut, 512);
|
stereoPacker.init(_stream->sinkOut, 512);
|
||||||
|
|
||||||
|
#if RTAUDIO_VERSION_MAJOR >= 6
|
||||||
|
audio.setErrorCallback(&reportErrorsAsException);
|
||||||
|
#endif
|
||||||
|
|
||||||
bool created = false;
|
bool created = false;
|
||||||
std::string device = "";
|
std::string device = "";
|
||||||
config.acquire();
|
config.acquire();
|
||||||
@ -42,12 +46,15 @@ public:
|
|||||||
device = config.conf[_streamName]["device"];
|
device = config.conf[_streamName]["device"];
|
||||||
config.release(created);
|
config.release(created);
|
||||||
|
|
||||||
int count = audio.getDeviceCount();
|
|
||||||
RtAudio::DeviceInfo info;
|
RtAudio::DeviceInfo info;
|
||||||
|
#if RTAUDIO_VERSION_MAJOR >= 6
|
||||||
|
for (int i : audio.getDeviceIds()) {
|
||||||
|
#else
|
||||||
|
int count = audio.getDeviceCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
|
#endif
|
||||||
try {
|
try {
|
||||||
info = audio.getDeviceInfo(i);
|
info = audio.getDeviceInfo(i);
|
||||||
if (!info.probed) { continue; }
|
|
||||||
if (info.outputChannels == 0) { continue; }
|
if (info.outputChannels == 0) { continue; }
|
||||||
if (info.isDefaultOutput) { defaultDevId = devList.size(); }
|
if (info.isDefaultOutput) { defaultDevId = devList.size(); }
|
||||||
devList.push_back(info);
|
devList.push_back(info);
|
||||||
@ -55,8 +62,8 @@ public:
|
|||||||
txtDevList += info.name;
|
txtDevList += info.name;
|
||||||
txtDevList += '\0';
|
txtDevList += '\0';
|
||||||
}
|
}
|
||||||
catch (std::exception e) {
|
catch (const std::exception& e) {
|
||||||
flog::error("AudioSinkModule Error getting audio device info: {0}", e.what());
|
flog::error("AudioSinkModule Error getting audio device info: id={0}: {1}", i, e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectByName(device);
|
selectByName(device);
|
||||||
@ -156,6 +163,23 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if RTAUDIO_VERSION_MAJOR >= 6
|
||||||
|
static void reportErrorsAsException(RtAudioErrorType type,
|
||||||
|
const std::string& errorText) {
|
||||||
|
switch (type) {
|
||||||
|
case RtAudioErrorType::RTAUDIO_NO_ERROR:
|
||||||
|
return;
|
||||||
|
case RtAudioErrorType::RTAUDIO_WARNING:
|
||||||
|
case RtAudioErrorType::RTAUDIO_NO_DEVICES_FOUND:
|
||||||
|
case RtAudioErrorType::RTAUDIO_DEVICE_DISCONNECT:
|
||||||
|
flog::warn("AudioSink: {0} ({1})", errorText, (int)type);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw std::runtime_error(errorText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool doStart() {
|
bool doStart() {
|
||||||
RtAudio::StreamParameters parameters;
|
RtAudio::StreamParameters parameters;
|
||||||
@ -172,8 +196,8 @@ private:
|
|||||||
audio.startStream();
|
audio.startStream();
|
||||||
stereoPacker.start();
|
stereoPacker.start();
|
||||||
}
|
}
|
||||||
catch (RtAudioError& e) {
|
catch (const std::exception& e) {
|
||||||
flog::error("Could not open audio device");
|
flog::error("Could not open audio device {0}", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,10 @@ public:
|
|||||||
AudioSourceModule(std::string name) {
|
AudioSourceModule(std::string name) {
|
||||||
this->name = name;
|
this->name = name;
|
||||||
|
|
||||||
|
#if RTAUDIO_VERSION_MAJOR >= 6
|
||||||
|
audio.setErrorCallback(&reportErrorsAsException);
|
||||||
|
#endif
|
||||||
|
|
||||||
sampleRate = 48000.0;
|
sampleRate = 48000.0;
|
||||||
|
|
||||||
handler.ctx = this;
|
handler.ctx = this;
|
||||||
@ -83,21 +87,25 @@ public:
|
|||||||
void refresh() {
|
void refresh() {
|
||||||
devices.clear();
|
devices.clear();
|
||||||
|
|
||||||
|
#if RTAUDIO_VERSION_MAJOR >= 6
|
||||||
|
for (int i : audio.getDeviceIds()) {
|
||||||
|
#else
|
||||||
int count = audio.getDeviceCount();
|
int count = audio.getDeviceCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
|
#endif
|
||||||
try {
|
try {
|
||||||
// Get info
|
// Get info
|
||||||
auto info = audio.getDeviceInfo(i);
|
auto info = audio.getDeviceInfo(i);
|
||||||
|
|
||||||
// Check that it has a stereo input
|
// Check that it has a stereo input
|
||||||
if (info.probed && info.inputChannels < 2) { continue; }
|
if (info.inputChannels < 2) { continue; }
|
||||||
|
|
||||||
// Save info
|
// Save info
|
||||||
DeviceInfo dinfo = { info, i };
|
DeviceInfo dinfo = { info, i };
|
||||||
devices.define(info.name, info.name, dinfo);
|
devices.define(info.name, info.name, dinfo);
|
||||||
}
|
}
|
||||||
catch (std::exception e) {
|
catch (const std::exception& e) {
|
||||||
flog::error("Error getting audio device info: {0}", e.what());
|
flog::error("Error getting audio device info: id={0}: {1}", i, e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,6 +262,23 @@ private:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if RTAUDIO_VERSION_MAJOR >= 6
|
||||||
|
static void reportErrorsAsException(RtAudioErrorType type,
|
||||||
|
const std::string& errorText) {
|
||||||
|
switch (type) {
|
||||||
|
case RtAudioErrorType::RTAUDIO_NO_ERROR:
|
||||||
|
return;
|
||||||
|
case RtAudioErrorType::RTAUDIO_WARNING:
|
||||||
|
case RtAudioErrorType::RTAUDIO_NO_DEVICES_FOUND:
|
||||||
|
case RtAudioErrorType::RTAUDIO_DEVICE_DISCONNECT:
|
||||||
|
flog::warn("AudioSource: {0} ({1})", errorText, (int)type);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw std::runtime_error(errorText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
dsp::stream<dsp::complex_t> stream;
|
dsp::stream<dsp::complex_t> stream;
|
||||||
@ -290,4 +315,4 @@ MOD_EXPORT void _DELETE_INSTANCE_(ModuleManager::Instance* instance) {
|
|||||||
MOD_EXPORT void _END_() {
|
MOD_EXPORT void _END_() {
|
||||||
config.disableAutoSave();
|
config.disableAutoSave();
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user