diff --git a/src/audio.cpp b/src/audio.cpp index 1690684e..1aeca4bc 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -167,10 +167,12 @@ int Port::getDeviceId() { } void Port::setDeviceId(int deviceId) { + if (!driver) + return; if (deviceId == this->deviceId) return; // Destroy device - if (driver && this->deviceId >= 0) { + if (this->deviceId >= 0) { try { driver->unsubscribe(this->deviceId, this); } @@ -182,7 +184,7 @@ void Port::setDeviceId(int deviceId) { this->deviceId = -1; // Create device - if (driver && deviceId >= 0) { + if (deviceId >= 0) { try { device = driver->subscribe(deviceId, this); this->deviceId = deviceId; @@ -367,19 +369,17 @@ void Port::fromJson(json_t* rootJ) { if (driverJ) setDriverId(json_number_value(driverJ)); - if (driver) { - json_t* deviceNameJ = json_object_get(rootJ, "deviceName"); - if (deviceNameJ) { - std::string deviceName = json_string_value(deviceNameJ); - // Search for device ID with equal name - for (int deviceId : getDeviceIds()) { - std::string deviceNameCurr = getDeviceName(deviceId); - if (deviceNameCurr == "") - continue; - if (deviceNameCurr == deviceName) { - setDeviceId(deviceId); - break; - } + json_t* deviceNameJ = json_object_get(rootJ, "deviceName"); + if (deviceNameJ) { + std::string deviceName = json_string_value(deviceNameJ); + // Search for device ID with equal name + for (int deviceId : getDeviceIds()) { + std::string deviceNameCurr = getDeviceName(deviceId); + if (deviceNameCurr == "") + continue; + if (deviceNameCurr == deviceName) { + setDeviceId(deviceId); + break; } } } diff --git a/src/rtaudio.cpp b/src/rtaudio.cpp index 7e77f41d..49b9a9ee 100644 --- a/src/rtaudio.cpp +++ b/src/rtaudio.cpp @@ -26,7 +26,7 @@ struct RtAudioDevice : audio::Device { RtAudio::StreamParameters outputParameters; RtAudio::StreamOptions options; int blockSize = 0; - float sampleRate = 44100; + float sampleRate = 0; RtAudioDevice(RtAudio::Api api, int deviceId) { rtAudio = new RtAudio(api); @@ -161,6 +161,8 @@ struct RtAudioDevice : audio::Device { return sampleRate; } void setSampleRate(float sampleRate) override { + if (sampleRate == this->sampleRate) + return; closeStream(); this->sampleRate = sampleRate; openStream(); @@ -178,6 +180,8 @@ struct RtAudioDevice : audio::Device { return blockSize; } void setBlockSize(int blockSize) override { + if (blockSize == this->blockSize) + return; closeStream(); this->blockSize = blockSize; openStream();