mirror of https://github.com/f1xpl/openauto.git
Use RtAudio for all audio channels
parent
bd6013081a
commit
66610efd33
|
@ -52,8 +52,7 @@ private:
|
|||
uint32_t sampleSize_;
|
||||
uint32_t sampleRate_;
|
||||
SequentialBuffer audioBuffer_;
|
||||
bool playbackStarted_;
|
||||
RtAudio dac_;
|
||||
std::unique_ptr<RtAudio> dac_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
|
|
|
@ -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>(RtAudio::LINUX_PULSE);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
// fallback
|
||||
dac_ = std::make_unique<RtAudio>();
|
||||
}
|
||||
}
|
||||
|
||||
bool RtAudioOutput::open()
|
||||
{
|
||||
std::lock_guard<decltype(mutex_)> 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<void*>(this));
|
||||
uint32_t bufferFrames = 1024;
|
||||
dac_->openStream(¶meters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast<void*>(this));
|
||||
|
||||
return audioBuffer_.open(QIODevice::ReadWrite);
|
||||
}
|
||||
|
@ -76,11 +85,11 @@ void RtAudioOutput::start()
|
|||
{
|
||||
std::lock_guard<decltype(mutex_)> 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<decltype(mutex_)> lock(mutex_);
|
||||
|
||||
if(!dac_.isStreamOpen() && !dac_.isStreamRunning())
|
||||
if(!dac_->isStreamOpen() && !dac_->isStreamRunning())
|
||||
{
|
||||
try
|
||||
{
|
||||
dac_.stopStream();
|
||||
dac_->stopStream();
|
||||
}
|
||||
catch(const RtAudioError& e)
|
||||
{
|
||||
|
|
|
@ -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<RtAudioOutput>(1, 16, 1600));
|
||||
//IAudioOutput::Pointer speechAudioOutput(new QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
auto speechAudioOutput(std::make_shared<RtAudioOutput>(1, 16, 16000));
|
||||
serviceList.emplace_back(std::make_shared<SpeechAudioService>(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<RtAudioOutput>(1, 16, 1600));
|
||||
//IAudioOutput::Pointer systemAudioOutput(new QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1));
|
||||
auto systemAudioOutput(std::make_shared<RtAudioOutput>(1, 16, 16000));
|
||||
serviceList.emplace_back(std::make_shared<SystemAudioService>(ioService_, messenger, std::move(systemAudioOutput)));
|
||||
|
||||
serviceList.emplace_back(std::make_shared<SensorService>(ioService_, messenger));
|
||||
|
|
Loading…
Reference in New Issue