Skip to content

Commit

Permalink
Add settings for selection of audio output backend
Browse files Browse the repository at this point in the history
  • Loading branch information
f1xpl committed Mar 25, 2018
1 parent b0bb0c7 commit 4d53277
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of openauto project.
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
*
* openauto is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* openauto is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

namespace f1x
{
namespace openauto
{
namespace autoapp
{
namespace configuration
{

enum class AudioOutputBackendType
{
RTAUDIO,
QT
};

}
}
}
}
4 changes: 4 additions & 0 deletions include/f1x/openauto/autoapp/Configuration/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class Configuration: public IConfiguration
void setMusicAudioChannelEnabled(bool value) override;
bool speechAudioChannelEnabled() const override;
void setSpeechAudioChannelEnabled(bool value) override;
AudioOutputBackendType getAudioOutputBackendType() const override;
void setAudioOutputBackendType(AudioOutputBackendType value) override;

private:
void readButtonCodes(boost::property_tree::ptree& iniConfig);
Expand All @@ -88,6 +90,7 @@ class Configuration: public IConfiguration
std::string bluetoothRemoteAdapterAddress_;
bool musicAudioChannelEnabled_;
bool speechAudiochannelEnabled_;
AudioOutputBackendType audioOutputBackendType_;

static const std::string cConfigFileName;

Expand All @@ -103,6 +106,7 @@ class Configuration: public IConfiguration

static const std::string cAudioMusicAudioChannelEnabled;
static const std::string cAudioSpeechAudioChannelEnabled;
static const std::string cAudioOutputBackendType;

static const std::string cBluetoothAdapterTypeKey;
static const std::string cBluetoothRemoteAdapterAddressKey;
Expand Down
3 changes: 3 additions & 0 deletions include/f1x/openauto/autoapp/Configuration/IConfiguration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <aasdk_proto/ButtonCodeEnum.pb.h>
#include <f1x/openauto/autoapp/Configuration/BluetootAdapterType.hpp>
#include <f1x/openauto/autoapp/Configuration/HandednessOfTrafficType.hpp>
#include <f1x/openauto/autoapp/Configuration/AudioOutputBackendType.hpp>

namespace f1x
{
Expand Down Expand Up @@ -77,6 +78,8 @@ class IConfiguration
virtual void setMusicAudioChannelEnabled(bool value) = 0;
virtual bool speechAudioChannelEnabled() const = 0;
virtual void setSpeechAudioChannelEnabled(bool value) = 0;
virtual AudioOutputBackendType getAudioOutputBackendType() const = 0;
virtual void setAudioOutputBackendType(AudioOutputBackendType value) = 0;
};

}
Expand Down
1 change: 1 addition & 0 deletions include/f1x/openauto/autoapp/Projection/ServiceFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ServiceFactory: public IServiceFactory
IService::Pointer createVideoService(aasdk::messenger::IMessenger::Pointer messenger);
IService::Pointer createBluetoothService(aasdk::messenger::IMessenger::Pointer messenger);
IService::Pointer createInputService(aasdk::messenger::IMessenger::Pointer messenger);
void createAudioServices(ServiceList& serviceList, aasdk::messenger::IMessenger::Pointer messenger);

boost::asio::io_service& ioService_;
configuration::IConfiguration::Pointer configuration_;
Expand Down
14 changes: 14 additions & 0 deletions src/autoapp/Configuration/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const std::string Configuration::cVideoMarginHeight = "Video.MarginHeight";

const std::string Configuration::cAudioMusicAudioChannelEnabled = "Audio.MusicAudioChannelEnabled";
const std::string Configuration::cAudioSpeechAudioChannelEnabled = "Audio.SpeechAudioChannelEnabled";
const std::string Configuration::cAudioOutputBackendType = "Audio.OutputBackendType";

const std::string Configuration::cBluetoothAdapterTypeKey = "Bluetooth.AdapterType";
const std::string Configuration::cBluetoothRemoteAdapterAddressKey = "Bluetooth.RemoteAdapterAddress";
Expand Down Expand Up @@ -101,6 +102,7 @@ void Configuration::load()

musicAudioChannelEnabled_ = iniConfig.get<bool>(cAudioMusicAudioChannelEnabled, true);
speechAudiochannelEnabled_ = iniConfig.get<bool>(cAudioSpeechAudioChannelEnabled, true);
audioOutputBackendType_ = static_cast<AudioOutputBackendType>(iniConfig.get<uint32_t>(cAudioOutputBackendType, static_cast<uint32_t>(AudioOutputBackendType::RTAUDIO)));
}
catch(const boost::property_tree::ini_parser_error& e)
{
Expand All @@ -126,6 +128,7 @@ void Configuration::reset()
bluetoothRemoteAdapterAddress_ = "";
musicAudioChannelEnabled_ = true;
speechAudiochannelEnabled_ = true;
audioOutputBackendType_ = AudioOutputBackendType::RTAUDIO;
}

void Configuration::save()
Expand All @@ -149,6 +152,7 @@ void Configuration::save()

iniConfig.put<bool>(cAudioMusicAudioChannelEnabled, musicAudioChannelEnabled_);
iniConfig.put<bool>(cAudioSpeechAudioChannelEnabled, speechAudiochannelEnabled_);
iniConfig.put<uint32_t>(cAudioOutputBackendType, static_cast<uint32_t>(audioOutputBackendType_));
boost::property_tree::ini_parser::write_ini(cConfigFileName, iniConfig);
}

Expand Down Expand Up @@ -282,6 +286,16 @@ void Configuration::setSpeechAudioChannelEnabled(bool value)
speechAudiochannelEnabled_ = value;
}

AudioOutputBackendType Configuration::getAudioOutputBackendType() const
{
return audioOutputBackendType_;
}

void Configuration::setAudioOutputBackendType(AudioOutputBackendType value)
{
audioOutputBackendType_ = value;
}

void Configuration::readButtonCodes(boost::property_tree::ptree& iniConfig)
{
this->insertButtonCode(iniConfig, cInputPlayButtonKey, aasdk::proto::enums::ButtonCode::PLAY);
Expand Down
47 changes: 28 additions & 19 deletions src/autoapp/Projection/ServiceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,7 @@ ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messeng

IAudioInput::Pointer audioInput(new QtAudioInput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1));
serviceList.emplace_back(std::make_shared<AudioInputService>(ioService_, messenger, std::move(audioInput)));

if(configuration_->musicAudioChannelEnabled())
{
//IAudioOutput::Pointer mediaAudioOutput(new QtAudioOutput(2, 16, 48000), std::bind(&QObject::deleteLater, std::placeholders::_1));
auto mediaAudioOutput(std::make_shared<RtAudioOutput>(2, 16, 48000));
serviceList.emplace_back(std::make_shared<MediaAudioService>(ioService_, messenger, std::move(mediaAudioOutput)));
}

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, 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, 16000));
serviceList.emplace_back(std::make_shared<SystemAudioService>(ioService_, messenger, std::move(systemAudioOutput)));

this->createAudioServices(serviceList, messenger);
serviceList.emplace_back(std::make_shared<SensorService>(ioService_, messenger));
serviceList.emplace_back(this->createVideoService(messenger));
serviceList.emplace_back(this->createBluetoothService(messenger));
Expand Down Expand Up @@ -145,6 +127,33 @@ IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenge
return std::make_shared<InputService>(ioService_, messenger, std::move(inputDevice));
}

void ServiceFactory::createAudioServices(ServiceList& serviceList, aasdk::messenger::IMessenger::Pointer messenger)
{
if(configuration_->musicAudioChannelEnabled())
{
auto mediaAudioOutput = configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
std::make_shared<RtAudioOutput>(2, 16, 48000) :
IAudioOutput::Pointer(new QtAudioOutput(2, 16, 48000), std::bind(&QObject::deleteLater, std::placeholders::_1));

serviceList.emplace_back(std::make_shared<MediaAudioService>(ioService_, messenger, std::move(mediaAudioOutput)));
}

if(configuration_->speechAudioChannelEnabled())
{
auto speechAudioOutput = configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
std::make_shared<RtAudioOutput>(1, 16, 16000) :
IAudioOutput::Pointer(new QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1));

serviceList.emplace_back(std::make_shared<SpeechAudioService>(ioService_, messenger, std::move(speechAudioOutput)));
}

auto systemAudioOutput = configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
std::make_shared<RtAudioOutput>(1, 16, 16000) :
IAudioOutput::Pointer(new QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1));

serviceList.emplace_back(std::make_shared<SystemAudioService>(ioService_, messenger, std::move(systemAudioOutput)));
}

}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/autoapp/UI/SettingsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void SettingsWindow::onSave()

configuration_->setMusicAudioChannelEnabled(ui_->checkBoxMusicAudioChannel->isChecked());
configuration_->setSpeechAudioChannelEnabled(ui_->checkBoxSpeechAudioChannel->isChecked());
configuration_->setAudioOutputBackendType(ui_->radioButtonRtAudio->isChecked() ? configuration::AudioOutputBackendType::RTAUDIO : configuration::AudioOutputBackendType::QT);

configuration_->save();
this->close();
Expand Down Expand Up @@ -149,6 +150,10 @@ void SettingsWindow::load()

ui_->checkBoxMusicAudioChannel->setChecked(configuration_->musicAudioChannelEnabled());
ui_->checkBoxSpeechAudioChannel->setChecked(configuration_->speechAudioChannelEnabled());

const auto& audioOutputBackendType = configuration_->getAudioOutputBackendType();
ui_->radioButtonRtAudio->setChecked(audioOutputBackendType == configuration::AudioOutputBackendType::RTAUDIO);
ui_->radioButtonQtAudio->setChecked(audioOutputBackendType == configuration::AudioOutputBackendType::QT);
}

void SettingsWindow::loadButtonCheckBoxes()
Expand Down
41 changes: 41 additions & 0 deletions src/autoapp/UI/settingswindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,45 @@ color: rgb(238, 238, 236);</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBoxAudioOutputBackend">
<property name="geometry">
<rect>
<x>0</x>
<y>130</y>
<width>621</width>
<height>61</height>
</rect>
</property>
<property name="title">
<string>Output backend</string>
</property>
<widget class="QRadioButton" name="radioButtonRtAudio">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>112</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>RT audio</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButtonQtAudio">
<property name="geometry">
<rect>
<x>140</x>
<y>30</y>
<width>112</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Qt</string>
</property>
</widget>
</widget>
</widget>
<widget class="QWidget" name="tabInput">
<attribute name="title">
Expand Down Expand Up @@ -969,6 +1008,8 @@ color: rgb(238, 238, 236);</string>
<tabstop>horizontalSliderScreenDPI</tabstop>
<tabstop>checkBoxMusicAudioChannel</tabstop>
<tabstop>checkBoxSpeechAudioChannel</tabstop>
<tabstop>radioButtonRtAudio</tabstop>
<tabstop>radioButtonQtAudio</tabstop>
<tabstop>checkBoxEnableTouchscreen</tabstop>
<tabstop>listWidgetButtons</tabstop>
<tabstop>checkBoxPlayButton</tabstop>
Expand Down

0 comments on commit 4d53277

Please sign in to comment.