diff --git a/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp b/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp index 1e111b8..7bfba51 100644 --- a/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp @@ -52,8 +52,7 @@ private: uint32_t sampleSize_; uint32_t sampleRate_; SequentialBuffer audioBuffer_; - bool playbackStarted_; - RtAudio dac_; + std::unique_ptr dac_; std::mutex mutex_; }; diff --git a/src/autoapp/Projection/RtAudioOutput.cpp b/src/autoapp/Projection/RtAudioOutput.cpp index 68a1756..d84428b 100644 --- a/src/autoapp/Projection/RtAudioOutput.cpp +++ b/src/autoapp/Projection/RtAudioOutput.cpp @@ -32,25 +32,34 @@ RtAudioOutput::RtAudioOutput(uint32_t channelCount, uint32_t sampleSize, uint32_ : channelCount_(channelCount) , sampleSize_(sampleSize) , sampleRate_(sampleRate) - , playbackStarted_(false) + , dac_() { + try + { + dac_ = std::make_unique(RtAudio::LINUX_PULSE); + } + catch(...) + { + // fallback + dac_ = std::make_unique(); + } } bool RtAudioOutput::open() { std::lock_guard lock(mutex_); - if(dac_.getDeviceCount() > 0) + if(dac_->getDeviceCount() > 0) { RtAudio::StreamParameters parameters; - parameters.deviceId = dac_.getDefaultOutputDevice(); + parameters.deviceId = dac_->getDefaultOutputDevice(); parameters.nChannels = channelCount_; parameters.firstChannel = 0; try { - uint32_t bufferFrames = 256; - dac_.openStream(¶meters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast(this)); + uint32_t bufferFrames = 1024; + dac_->openStream(¶meters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast(this)); return audioBuffer_.open(QIODevice::ReadWrite); } @@ -76,11 +85,11 @@ void RtAudioOutput::start() { std::lock_guard lock(mutex_); - if(dac_.isStreamOpen() && !dac_.isStreamRunning()) + if(dac_->isStreamOpen() && !dac_->isStreamRunning()) { try { - dac_.startStream(); + dac_->startStream(); } catch(const RtAudioError& e) { @@ -95,9 +104,9 @@ void RtAudioOutput::stop() this->suspend(); - if(dac_.isStreamOpen()) + if(dac_->isStreamOpen()) { - dac_.closeStream(); + dac_->closeStream(); } } @@ -105,11 +114,11 @@ void RtAudioOutput::suspend() { std::lock_guard lock(mutex_); - if(!dac_.isStreamOpen() && !dac_.isStreamRunning()) + if(!dac_->isStreamOpen() && !dac_->isStreamRunning()) { try { - dac_.stopStream(); + dac_->stopStream(); } catch(const RtAudioError& e) { diff --git a/src/autoapp/Projection/ServiceFactory.cpp b/src/autoapp/Projection/ServiceFactory.cpp index 2e54710..82ede87 100644 --- a/src/autoapp/Projection/ServiceFactory.cpp +++ b/src/autoapp/Projection/ServiceFactory.cpp @@ -72,13 +72,13 @@ ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messeng if(configuration_->speechAudioChannelEnabled()) { - IAudioOutput::Pointer speechAudioOutput(new QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); - //auto speechAudioOutput(std::make_shared(1, 16, 1600)); + //IAudioOutput::Pointer speechAudioOutput(new QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); + auto speechAudioOutput(std::make_shared(1, 16, 16000)); serviceList.emplace_back(std::make_shared(ioService_, messenger, std::move(speechAudioOutput))); } - IAudioOutput::Pointer systemAudioOutput(new QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); - //auto systemAudioOutput(std::make_shared(1, 16, 1600)); + //IAudioOutput::Pointer systemAudioOutput(new QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); + auto systemAudioOutput(std::make_shared(1, 16, 16000)); serviceList.emplace_back(std::make_shared(ioService_, messenger, std::move(systemAudioOutput))); serviceList.emplace_back(std::make_shared(ioService_, messenger));