diff --git a/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp b/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp index f3d69d5f..4aae81b5 100644 --- a/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp @@ -55,6 +55,7 @@ class RtAudioOutput: public IAudioOutput SequentialBuffer audioBuffer_; std::unique_ptr dac_; std::mutex mutex_; + bool playbackRequested_; }; } diff --git a/src/autoapp/Projection/RtAudioOutput.cpp b/src/autoapp/Projection/RtAudioOutput.cpp index e0d70371..0da5cfb8 100644 --- a/src/autoapp/Projection/RtAudioOutput.cpp +++ b/src/autoapp/Projection/RtAudioOutput.cpp @@ -32,6 +32,7 @@ RtAudioOutput::RtAudioOutput(uint32_t channelCount, uint32_t sampleSize, uint32_ : channelCount_(channelCount) , sampleSize_(sampleSize) , sampleRate_(sampleRate) + , playbackRequested_(false) { std::vector apis; RtAudio::getCompiledApi(apis); @@ -54,7 +55,7 @@ bool RtAudioOutput::open() RtAudio::StreamOptions streamOptions; streamOptions.numberOfBuffers = 1; streamOptions.flags = RTAUDIO_MINIMIZE_LATENCY | RTAUDIO_SCHEDULE_REALTIME; - uint32_t bufferFrames = 64; + uint32_t bufferFrames = 256; dac_->openStream(¶meters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast(this), &streamOptions); return audioBuffer_.open(QIODevice::ReadWrite); } @@ -74,13 +75,10 @@ bool RtAudioOutput::open() void RtAudioOutput::write(const aasdk::common::DataConstBuffer& buffer) { audioBuffer_.write(reinterpret_cast(buffer.cdata), buffer.size); -} -void RtAudioOutput::start() -{ std::lock_guard lock(mutex_); - if(dac_->isStreamOpen() && !dac_->isStreamRunning()) + if(playbackRequested_ && dac_->isStreamOpen() && !dac_->isStreamRunning()) { try { @@ -91,6 +89,15 @@ void RtAudioOutput::start() OPENAUTO_LOG(error) << "[RtAudioOutput] Failed to start audio output, what: " << e.what(); } } + + playbackRequested_ = false; +} + +void RtAudioOutput::start() +{ + std::lock_guard lock(mutex_); + + playbackRequested_ = true; } void RtAudioOutput::stop()