diff --git a/src/autoapp/Projection/RtAudioOutput.cpp b/src/autoapp/Projection/RtAudioOutput.cpp index eb054205..139cd51a 100644 --- a/src/autoapp/Projection/RtAudioOutput.cpp +++ b/src/autoapp/Projection/RtAudioOutput.cpp @@ -51,8 +51,10 @@ bool RtAudioOutput::open() try { - uint32_t bufferFrames = 128; - dac_->openStream(¶meters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast(this), nullptr); + RtAudio::StreamOptions streamOptions; + streamOptions.flags = RTAUDIO_MINIMIZE_LATENCY | RTAUDIO_SCHEDULE_REALTIME; + uint32_t bufferFrames = sampleRate_ == 16000 ? 1024 : 2048; //according to the observation of audio packets + dac_->openStream(¶meters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast(this), &streamOptions); return audioBuffer_.open(QIODevice::ReadWrite); } catch(const RtAudioError& e) @@ -104,8 +106,7 @@ void RtAudioOutput::stop() void RtAudioOutput::suspend() { - std::lock_guard lock(mutex_); - this->doSuspend(); + //not needed } uint32_t RtAudioOutput::getSampleSize() const @@ -125,7 +126,7 @@ uint32_t RtAudioOutput::getSampleRate() const void RtAudioOutput::doSuspend() { - if(!dac_->isStreamOpen() && !dac_->isStreamRunning()) + if(dac_->isStreamOpen() && dac_->isStreamRunning()) { try {