Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/feature/audio_enhancemen…
Browse files Browse the repository at this point in the history
…ts' into development
  • Loading branch information
f1xpl committed Mar 25, 2018
2 parents 4b8861f + 4d53277 commit 4623f6b
Show file tree
Hide file tree
Showing 19 changed files with 486 additions and 70 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ find_package(libusb-1.0 REQUIRED)
find_package(Qt5 COMPONENTS Multimedia MultimediaWidgets Bluetooth)
find_package(Protobuf REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(rtaudio REQUIRED)

if(WIN32)
set(WINSOCK2_LIBRARIES "ws2_32")
Expand All @@ -54,6 +55,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}
${LIBUSB_1_INCLUDE_DIRS}
${PROTOBUF_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
${RTAUDIO_INCLUDE_DIRS}
${AASDK_PROTO_INCLUDE_DIRS}
${AASDK_INCLUDE_DIRS}
${BCM_HOST_INCLUDE_DIRS}
Expand All @@ -80,6 +82,7 @@ target_link_libraries(autoapp
${BCM_HOST_LIBRARIES}
${ILCLIENT_LIBRARIES}
${WINSOCK2_LIBRARIES}
${RTAUDIO_LIBRARIES}
${AASDK_PROTO_LIBRARIES}
${AASDK_LIBRARIES})

Expand Down
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Copyrights (c) 2018 f1x.studio (Michal Szwaj)
- [Boost libraries](http://www.boost.org/)
- [Qt libraries](https://www.qt.io/)
- [CMake](https://cmake.org/)
- [RtAudio](https://www.music.mcgill.ca/~gary/rtaudio/playback.html)
- Broadcom ilclient from RaspberryPI 3 firmware
- OpenMAX IL API

Expand Down
70 changes: 70 additions & 0 deletions cmake_modules/Findrtaudio.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
# 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/>.
#

if (RTAUDIO_LIBRARIES AND RTAUDIO_INCLUDE_DIRS)
# in cache already
set(RTAUDIO_FOUND TRUE)
else (RTAUDIO_LIBRARIES AND RTAUDIO_INCLUDE_DIRS)
find_path(RTAUDIO_INCLUDE_DIR
NAMES
RtAudio.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
PATH_SUFFIXES
rtaudio
)

find_library(RTAUDIO_LIBRARY
NAMES
rtaudio
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)

set(RTAUDIO_INCLUDE_DIRS
${RTAUDIO_INCLUDE_DIR}
)
set(RTAUDIO_LIBRARIES
${RTAUDIO_LIBRARY}
)

if (RTAUDIO_INCLUDE_DIRS AND RTAUDIO_LIBRARIES)
set(RTAUDIO_FOUND TRUE)
endif (RTAUDIO_INCLUDE_DIRS AND RTAUDIO_LIBRARIES)

if (RTAUDIO_FOUND)
if (NOT rtaudio_FIND_QUIETLY)
message(STATUS "Found rtaudio:")
message(STATUS " - Includes: ${RTAUDIO_INCLUDE_DIRS}")
message(STATUS " - Libraries: ${RTAUDIO_LIBRARIES}")
endif (NOT rtaudio_FIND_QUIETLY)
else (RTAUDIO_FOUND)
if (rtaudio_FIND_REQUIRED)
message(FATAL_ERROR "Could not find rtaudio")
endif (rtaudio_FIND_REQUIRED)
endif (RTAUDIO_FOUND)

mark_as_advanced(RTAUDIO_INCLUDE_DIRS RTAUDIO_LIBRARIES)

endif (RTAUDIO_LIBRARIES AND RTAUDIO_INCLUDE_DIRS)
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
3 changes: 2 additions & 1 deletion include/f1x/openauto/autoapp/Projection/IAudioOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include <memory>
#include <f1x/aasdk/Messenger/Timestamp.hpp>
#include <f1x/aasdk/Common/Data.hpp>

namespace f1x
Expand All @@ -39,7 +40,7 @@ class IAudioOutput
virtual ~IAudioOutput() = default;

virtual bool open() = 0;
virtual void write(const aasdk::common::DataConstBuffer& buffer) = 0;
virtual void write(aasdk::messenger::Timestamp::ValueType timestamp, const aasdk::common::DataConstBuffer& buffer) = 0;
virtual void start() = 0;
virtual void stop() = 0;
virtual void suspend() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ namespace autoapp
namespace projection
{

class AudioInput: public QObject, public IAudioInput
class QtAudioInput: public QObject, public IAudioInput
{
Q_OBJECT
public:
AudioInput(uint32_t channelCount, uint32_t sampleSize, uint32_t sampleRate);
QtAudioInput(uint32_t channelCount, uint32_t sampleSize, uint32_t sampleRate);

bool open() override;
bool isActive() const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ namespace autoapp
namespace projection
{

class AudioOutput: public QObject, public IAudioOutput
class QtAudioOutput: public QObject, public IAudioOutput
{
Q_OBJECT

public:
AudioOutput(uint32_t channelCount, uint32_t sampleSize, uint32_t sampleRate);
QtAudioOutput(uint32_t channelCount, uint32_t sampleSize, uint32_t sampleRate);
bool open() override;
void write(const aasdk::common::DataConstBuffer& buffer) override;
void write(aasdk::messenger::Timestamp::ValueType, const aasdk::common::DataConstBuffer& buffer) override;
void start() override;
void stop() override;
void suspend() override;
Expand Down
63 changes: 63 additions & 0 deletions include/f1x/openauto/autoapp/Projection/RtAudioOutput.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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

#include <RtAudio.h>
#include <f1x/openauto/autoapp/Projection/IAudioOutput.hpp>
#include <f1x/openauto/autoapp/Projection/SequentialBuffer.hpp>

namespace f1x
{
namespace openauto
{
namespace autoapp
{
namespace projection
{

class RtAudioOutput: public IAudioOutput
{
public:
RtAudioOutput(uint32_t channelCount, uint32_t sampleSize, uint32_t sampleRate);
bool open() override;
void write(aasdk::messenger::Timestamp::ValueType timestamp, const aasdk::common::DataConstBuffer& buffer) override;
void start() override;
void stop() override;
void suspend() override;
uint32_t getSampleSize() const override;
uint32_t getChannelCount() const override;
uint32_t getSampleRate() const override;

private:
void doSuspend();
static int audioBufferReadHandler(void* outputBuffer, void* inputBuffer, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void* userData);

uint32_t channelCount_;
uint32_t sampleSize_;
uint32_t sampleRate_;
SequentialBuffer audioBuffer_;
std::unique_ptr<RtAudio> dac_;
std::mutex mutex_;
};

}
}
}
}
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
20 changes: 13 additions & 7 deletions src/autoapp/Projection/AudioService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ void AudioService::onChannelOpenRequest(const aasdk::proto::messages::ChannelOpe
OPENAUTO_LOG(info) << "[AudioService] open request"
<< ", channel: " << aasdk::messenger::channelIdToString(channel_->getId())
<< ", priority: " << request.priority();

OPENAUTO_LOG(debug) << "[AudioService] channel: " << aasdk::messenger::channelIdToString(channel_->getId())
<< " audio output sample rate: " << audioOutput_->getSampleRate()
<< ", sample size: " << audioOutput_->getSampleSize()
<< ", channel count: " << audioOutput_->getChannelCount();

const aasdk::proto::enums::Status::Enum status = audioOutput_->open() ? aasdk::proto::enums::Status::OK : aasdk::proto::enums::Status::FAIL;
OPENAUTO_LOG(info) << "[AudioService] open status: " << status
<< ", channel: " << aasdk::messenger::channelIdToString(channel_->getId());
Expand Down Expand Up @@ -146,14 +152,9 @@ void AudioService::onAVChannelStopIndication(const aasdk::proto::messages::AVCha
channel_->receive(this->shared_from_this());
}

void AudioService::onAVMediaWithTimestampIndication(aasdk::messenger::Timestamp::ValueType, const aasdk::common::DataConstBuffer& buffer)
{
this->onAVMediaIndication(buffer);
}

void AudioService::onAVMediaIndication(const aasdk::common::DataConstBuffer& buffer)
void AudioService::onAVMediaWithTimestampIndication(aasdk::messenger::Timestamp::ValueType timestamp, const aasdk::common::DataConstBuffer& buffer)
{
audioOutput_->write(buffer);
audioOutput_->write(timestamp, buffer);
aasdk::proto::messages::AVMediaAckIndication indication;
indication.set_session(session_);
indication.set_value(1);
Expand All @@ -164,6 +165,11 @@ void AudioService::onAVMediaIndication(const aasdk::common::DataConstBuffer& buf
channel_->receive(this->shared_from_this());
}

void AudioService::onAVMediaIndication(const aasdk::common::DataConstBuffer& buffer)
{
this->onAVMediaWithTimestampIndication(0, buffer);
}

void AudioService::onChannelError(const aasdk::error::Error& e)
{
OPENAUTO_LOG(error) << "[AudioService] channel error: " << e.what()
Expand Down
Loading

0 comments on commit 4623f6b

Please sign in to comment.