Browse Source

Refactor Port a bit. Use default sample rate from audio::Device.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
bc08eccddc
2 changed files with 20 additions and 16 deletions
  1. +15
    -15
      src/audio.cpp
  2. +5
    -1
      src/rtaudio.cpp

+ 15
- 15
src/audio.cpp View File

@@ -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;
}
}
}


+ 5
- 1
src/rtaudio.cpp View File

@@ -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();


Loading…
Cancel
Save