Browse Source

Add more error handling to rtaudio driver.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
16b273194d
1 changed files with 16 additions and 6 deletions
  1. +16
    -6
      src/rtaudio.cpp

+ 16
- 6
src/rtaudio.cpp View File

@@ -29,18 +29,22 @@ struct RtAudioDevice : audio::Device {
float sampleRate = 0;

RtAudioDevice(RtAudio::Api api, int deviceId) {
rtAudio = new RtAudio(api);
rtAudio->showWarnings(false);
if (!rtAudio) {
throw Exception("Failed to create RtAudio driver %d", api);
// Create RtAudio object
try {
rtAudio = new RtAudio(api);
}
catch (RtAudioError& e) {
throw Exception("Failed to create RtAudio driver %d: %s", api, e.what());
}

rtAudio->showWarnings(false);

// Query device ID
try {
deviceInfo = rtAudio->getDeviceInfo(deviceId);
}
catch (RtAudioError& e) {
throw Exception("Failed to query RtAudio device: %s", e.what());
throw Exception("Failed to query RtAudio device %d: %s", deviceId, e.what());
}

this->deviceId = deviceId;
@@ -208,7 +212,13 @@ struct RtAudioDriver : audio::Driver {
std::map<int, RtAudioDevice*> devices;

RtAudioDriver(RtAudio::Api api) {
rtAudio = new RtAudio(api);
try {
rtAudio = new RtAudio(api);
}
catch (RtAudioError& e) {
throw Exception("Failed to create RtAudio driver %d: %s", api, e.what());
}

rtAudio->showWarnings(false);
}



Loading…
Cancel
Save