Browse Source

Use closest sample rate in AudioIO::openStream()

tags/v0.6.0
Andrew Belt 6 years ago
parent
commit
ca5d43ed9d
2 changed files with 10 additions and 5 deletions
  1. +8
    -1
      src/audio.cpp
  2. +2
    -4
      src/core/AudioInterface.cpp

+ 8
- 1
src/audio.cpp View File

@@ -130,12 +130,19 @@ void AudioIO::openStream() {
RtAudio::StreamOptions options;
// options.flags |= RTAUDIO_SCHEDULE_REALTIME;

int closestSampleRate = deviceInfo.preferredSampleRate;
for (int sr : deviceInfo.sampleRates) {
if (abs(sr - sampleRate) < abs(closestSampleRate - sampleRate)) {
closestSampleRate = sr;
}
}

try {
debug("Opening audio stream %d", device);
stream->openStream(
numOutputs == 0 ? NULL : &outParameters,
numInputs == 0 ? NULL : &inParameters,
RTAUDIO_FLOAT32, sampleRate, (unsigned int*) &blockSize, &rtCallback, this, &options, NULL);
RTAUDIO_FLOAT32, closestSampleRate, (unsigned int*) &blockSize, &rtCallback, this, &options, NULL);
}
catch (RtAudioError &e) {
warn("Failed to open audio stream: %s", e.what());


+ 2
- 4
src/core/AudioInterface.cpp View File

@@ -96,8 +96,8 @@ struct AudioInterface : Module {

AudioInterfaceIO audioIO;

SampleRateConverter<8> inputSrc;
SampleRateConverter<8> outputSrc;
SampleRateConverter<MAX_INPUTS> inputSrc;
SampleRateConverter<MAX_OUTPUTS> outputSrc;

// in rack's sample rate
DoubleRingBuffer<Frame<MAX_INPUTS>, 16> inputBuffer;
@@ -107,8 +107,6 @@ struct AudioInterface : Module {
}

void step() override;
void stepStream(const float *input, float *output, int numFrames);


json_t *toJson() override {
json_t *rootJ = json_object();


Loading…
Cancel
Save