From 29f8b24b2b171b1e1cd0ef47ff94824f07249361 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 1 Feb 2015 22:21:03 +0100 Subject: [PATCH] [DEV] start work on dynamic chain --- airtio/Interface.cpp | 69 +++++++++++++++++++++++++++++++------------- airtio/Interface.h | 20 +++++++++++-- airtio/Manager.cpp | 52 ++++----------------------------- data/hardware.json | 30 +++++++++++++++++++ data/virtual.json | 29 +++++++++++++++++++ test/main.cpp | 9 ++++-- 6 files changed, 137 insertions(+), 72 deletions(-) create mode 100644 data/hardware.json create mode 100644 data/virtual.json diff --git a/airtio/Interface.cpp b/airtio/Interface.cpp index cdce5fd..b2d369c 100644 --- a/airtio/Interface.cpp +++ b/airtio/Interface.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #undef __class__ @@ -43,6 +44,13 @@ bool airtio::Interface::init(const std::string& _name, // Create convertion interface if (m_node->isInput() == true) { + // add all time the volume stage : + std::shared_ptr algo = airtalgo::Volume::create(); + algo->setInputFormat(airtalgo::IOFormatInterface(m_node->getMap(), m_node->getFormat(), m_node->getFrequency())); + algo->setName("volume"); + m_process->pushBack(algo); + AIRTIO_INFO("add basic volume stage"); + /* // TODO : Set an auto update of IO if (m_map != m_node->getMap()) { std::shared_ptr algo = airtalgo::ChannelReorder::create(); @@ -65,23 +73,15 @@ bool airtio::Interface::init(const std::string& _name, m_process->pushBack(algo); AIRTIO_INFO("convert " << m_node->getFormat() << " -> " << m_format); } - // by default we add a read node - if (true) { - std::shared_ptr algo = airtalgo::EndPointRead::create(); - algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); - algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); - m_process->pushBack(algo); - AIRTIO_INFO("add default read node ..."); - } + */ } else { - // by default we add a write node: - if (true) { - std::shared_ptr algo = airtalgo::EndPointWrite::create(); - algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); - algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); - m_process->pushBack(algo); - AIRTIO_INFO("add default write node ..."); - } + // add all time the volume stage : + std::shared_ptr algo = airtalgo::Volume::create(); + algo->setOutputFormat(airtalgo::IOFormatInterface(m_node->getMap(), m_node->getFormat(), m_node->getFrequency())); + algo->setName("volume"); + m_process->pushBack(algo); + AIRTIO_INFO("add basic volume stage"); + /* // TODO : Set an auto update of IO if (m_format != m_node->getFormat()) { std::shared_ptr algo = airtalgo::FormatUpdate::create(); @@ -104,6 +104,7 @@ bool airtio::Interface::init(const std::string& _name, m_process->pushBack(algo); AIRTIO_INFO("convert " << m_map << " -> " << m_node->getMap()); } + */ } //m_node->interfaceAdd(shared_from_this()); return true; @@ -125,7 +126,31 @@ airtio::Interface::~Interface() { //m_node->interfaceRemove(shared_from_this()); m_process.reset(); } - +/* +bool airtio::Interface::hasEndPoint() { + +} +*/ +void airtio::Interface::setReadwrite() { + std::unique_lock lock(m_mutex); + if (m_process->hasType() ) { + AIRTIO_ERROR("Endpoint is already present ==> can not change"); + return; + } + if (m_node->isInput() == true) { + m_process->removeIfLast(); + std::shared_ptr algo = airtalgo::EndPointRead::create(); + ///algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); + algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); + m_process->pushBack(algo); + } else { + m_process->removeIfFirst(); + std::shared_ptr algo = airtalgo::EndPointWrite::create(); + algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); + //algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); + m_process->pushBack(algo); + } +} void airtio::Interface::setOutputCallback(size_t _chunkSize, airtalgo::needDataFunction _function) { std::unique_lock lock(m_mutex); @@ -133,7 +158,7 @@ void airtio::Interface::setOutputCallback(size_t _chunkSize, airtalgo::needDataF std::shared_ptr algo = airtalgo::EndPointCallback::create(_function); AIRTIO_INFO("set property: " << m_map << " " << m_format << " " << m_freq); algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); - algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); + //algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); m_process->pushFront(algo); } @@ -141,7 +166,7 @@ void airtio::Interface::setInputCallback(size_t _chunkSize, airtalgo::haveNewDat std::unique_lock lock(m_mutex); m_process->removeIfLast(); std::shared_ptr algo = airtalgo::EndPointCallback::create(_function); - algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); + //algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); m_process->pushBack(algo); } @@ -158,6 +183,7 @@ void airtio::Interface::setWriteCallback(airtalgo::needDataFunctionWrite _functi void airtio::Interface::start(const std::chrono::system_clock::time_point& _time) { std::unique_lock lock(m_mutex); AIRTIO_DEBUG("start [BEGIN]"); + m_process->updateInterAlgo(); m_node->interfaceAdd(shared_from_this()); AIRTIO_DEBUG("start [ END ]"); } @@ -165,6 +191,7 @@ void airtio::Interface::start(const std::chrono::system_clock::time_point& _time void airtio::Interface::stop(bool _fast, bool _abort) { std::unique_lock lock(m_mutex); AIRTIO_DEBUG("stop [BEGIN]"); + m_process->removeAlgoDynamic(); m_node->interfaceRemove(shared_from_this()); AIRTIO_DEBUG("stop [ END]"); } @@ -285,4 +312,6 @@ void airtio::Interface::systemNeedOutputData(std::chrono::system_clock::time_poi m_process->pull(_time, _data, _nbChunk, _chunkSize); } -bool airtio::Interface::systemSetVolume(const std::string& _parameter, const std::string& _value); \ No newline at end of file +bool airtio::Interface::systemSetVolume(const std::string& _parameter, const std::string& _value) { + return false; +} \ No newline at end of file diff --git a/airtio/Interface.h b/airtio/Interface.h index 28737a4..7d0b62d 100644 --- a/airtio/Interface.h +++ b/airtio/Interface.h @@ -61,13 +61,29 @@ namespace airtio { const std::vector& _map, airtalgo::format _format, const std::shared_ptr& _node); - public: /** - * @brief When we want to implement a Callback Mode : + * @brief set the read/write mode enable. + */ + virtual void setReadwrite(); + /** + * @brief When we want to implement a Callback Mode: */ virtual void setWriteCallback(airtalgo::needDataFunctionWrite _function); virtual void setOutputCallback(size_t _chunkSize, airtalgo::needDataFunction _function); virtual void setInputCallback(size_t _chunkSize, airtalgo::haveNewDataFunction _function); + /** + * @brief Add a volume group of the current channel. + * @note If you do not call this function with the group "FLOW" you chan not have a channel volume. + * @note the set volume stage can not be set after the start. + * @param[in] _name Name of the group classicle common group: + * - FLOW for channel volume. + * - MEDIA for multimedia volume control (audio player, player video, web streaming ...). + * - TTS for Test-to-speech volume control. + * - COMMUNICATION for user communication volume control. + * - NOTIFICATION for urgent notification volume control. + * - NOISE for small nose volume control. + */ + virtual void addVolumeGroup(const std::string& _name) {} public: /** * @brief Start the Audio interface flow. diff --git a/airtio/Manager.cpp b/airtio/Manager.cpp index 3ae195d..d520a9f 100644 --- a/airtio/Manager.cpp +++ b/airtio/Manager.cpp @@ -11,6 +11,7 @@ #include "io/Manager.h" #include "io/Node.h" +#include "debug.h" #undef __class__ #define __class__ "Manager" @@ -21,9 +22,7 @@ std::shared_ptr airtio::Manager::create(const std::string& _app airtio::Manager::Manager(const std::string& _applicationUniqueId) : m_applicationUniqueId(_applicationUniqueId), - m_listOpenInterface(), - m_masterVolume(0.0f), - m_masterVolumeRange(std::make_pair(-120.0f, 0.0f)) { + m_listOpenInterface() { } @@ -45,7 +44,7 @@ std::vector > airtio::Manager::getListStreamO } -bool setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value) { +bool airtio::Manager::setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value) { AIRTIO_DEBUG("setParameter [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "':'" << _value << "'"); bool out = false; if ( _filter == "volume" @@ -56,7 +55,7 @@ bool setParameter(const std::string& _flow, const std::string& _filter, const st AIRTIO_DEBUG("setParameter [ END ] : '" << out << "'"); return out; } -std::string getParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const { +std::string airtio::Manager::getParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const { AIRTIO_DEBUG("getParameter [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "'"); std::string out; AIRTIO_TODO(" IMPLEMENT"); @@ -64,7 +63,7 @@ std::string getParameter(const std::string& _flow, const std::string& _filter, c return out; } -std::string getParameterProperty(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const { +std::string airtio::Manager::getParameterProperty(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const { AIRTIO_DEBUG("getParameterProperty [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "'"); std::string out; AIRTIO_TODO(" IMPLEMENT"); @@ -72,47 +71,6 @@ std::string getParameterProperty(const std::string& _flow, const std::string& _f return out; } -// TODO : Deprecated ... -void airtio::Manager::setMasterOutputVolume(float _gainDB) { - if (_gainDB < m_masterVolumeRange.first) { - //throw std::range_error(std::string(_gainDB) + " is out of bonds : [" + m_masterVolumeRange.first + ".." + m_masterVolumeRange.second + "]"); - return; - } - if (_gainDB > m_masterVolumeRange.second) { - //throw std::range_error(std::string(_gainDB) + " is out of bonds : [" + m_masterVolumeRange.first + ".." + m_masterVolumeRange.second + "]"); - return; - } - m_masterVolume = _gainDB; - for (auto &it : m_listOpenInterface) { - std::shared_ptr tmpElem = it.lock(); - if (tmpElem == nullptr) { - continue; - } - // TODO : Deprecated ... - //tmpElem->setMasterVolume(m_masterVolume); - } -} - -float airtio::Manager::getMasterOutputVolume() { - return m_masterVolume; -} - -std::pair airtio::Manager::getMasterOutputVolumeRange() { - return m_masterVolumeRange; -} - -void airtio::Manager::setSectionVolume(const std::string& _section, float _gainDB) { - -} - -float airtio::Manager::getSectionVolume(const std::string& _section) { - return 0.0f; -} - -std::pair airtio::Manager::getSectionVolumeRange(const std::string& _section) { - return std::make_pair(0.0f, 0.0f); -} - std::shared_ptr airtio::Manager::createOutput(float _freq, const std::vector& _map, diff --git a/data/hardware.json b/data/hardware.json new file mode 100644 index 0000000..dc18811 --- /dev/null +++ b/data/hardware.json @@ -0,0 +1,30 @@ +{ + microphone:{ # name of the device + io:"input", # input or output + map-on:{ # select hardware interface and name + interface:"alsa", # interface : "alsa", "pulse", "core", ... + name:"default", # name of the interface + }, + frequency:48000, # frequency to open device + channel-map:[ # mapping of the harware device (to change map if needed) + "front-left", "front-right", + "read-left", "rear-right", + ], + type:"int16", # format to open device (int8, int16, int16-on-ont32, int24, int32, float) + nb-chunk:1024 # number of chunk to open device (create the latency anf the frequency to call user) + }, + speaker:{ + io:"output", + map-on:{ + interface:"alsa", + name:"default", + }, + frequency:48000, + channel-map:[ + "front-left", "front-right", + ], + type:"int16", + nb-chunk:1024, + volume-name:"MASTER" + } +} \ No newline at end of file diff --git a/data/virtual.json b/data/virtual.json new file mode 100644 index 0000000..a204c9a --- /dev/null +++ b/data/virtual.json @@ -0,0 +1,29 @@ +{ + microphone:{ # name of the virtual interface + io:"input", # input or output + map-on:"microphone", # name of the harware device + resampling-type:"speexdsp", # name of the resampler + resampling-option:"quality=10" # some option to the resampler + }, + speaker:{ + io:"output", + map-on:"speaker", + resampling-type:"speexdsp", + resampling-option:"quality=10" + }, + feedback:{ + io:"input", + map-on:"speaker", + resampling-type:"speexdsp", + resampling-option:"quality=10" + }, + microphone-cleaned:{ + io:"input", + map-on:"speaker", + resampling-type:"speexdsp", + resampling-option:"quality=10", + aec-map-on:"microphone", the second input of the AEC (get a single + aec-type:"airtio-remover", # some type is "airtio-remover", + aec-option:"mode=cutter" + } +} \ No newline at end of file diff --git a/test/main.cpp b/test/main.cpp index 541dcdf..ff0c64e 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -32,6 +32,7 @@ class testOutWrite { airtalgo::format_int16, "default", "WriteMode"); + m_interface->setReadwrite(); } void run() { double phase=0; @@ -100,6 +101,7 @@ class testOutWriteCallback { airtalgo::format_int16, "default", "WriteMode+Callback"); + m_interface->setReadwrite(); m_interface->setWriteCallback(std::bind(&testOutWriteCallback::onDataNeeded, this, std::placeholders::_1, @@ -232,6 +234,7 @@ class testInRead { airtalgo::format_int16, "default", "WriteMode"); + m_interface->setReadwrite(); } void run() { m_interface->start(); @@ -468,10 +471,10 @@ TEST(TestALL, testFormat) { std::shared_ptr manager; manager = airtio::Manager::create("testApplication"); std::vector listFormat; - listFormat.push_back(airtalgo::format_int16); - listFormat.push_back(airtalgo::format_int16_on_int32); + //listFormat.push_back(airtalgo::format_int16); + //listFormat.push_back(airtalgo::format_int16_on_int32); listFormat.push_back(airtalgo::format_int32); - listFormat.push_back(airtalgo::format_float); + //listFormat.push_back(airtalgo::format_float); for (auto &it : listFormat) { std::shared_ptr process = std::make_shared(manager, 48000, 2, it); process->run();