diff --git a/river/Interface.cpp b/river/Interface.cpp index e826047..8414dbd 100644 --- a/river/Interface.cpp +++ b/river/Interface.cpp @@ -30,13 +30,15 @@ bool river::Interface::init(const std::string& _name, float _freq, const std::vector& _map, audio::format _format, - const std::shared_ptr& _node) { + const std::shared_ptr& _node, + bool _isInput) { m_name = _name; m_node = _node; m_freq = _freq; m_map = _map; m_format = _format; m_volume = 0.0f; + m_isInput = _isInput; // register interface to be notify from the volume change. m_node->registerAsRemote(shared_from_this()); // Create convertion interface @@ -76,9 +78,10 @@ std::shared_ptr river::Interface::create(const std::string& _n float _freq, const std::vector& _map, audio::format _format, - const std::shared_ptr& _node) { + const std::shared_ptr& _node, + bool _isInput) { std::shared_ptr out = std::shared_ptr(new river::Interface()); - out->init(_name, _freq, _map, _format, _node); + out->init(_name, _freq, _map, _format, _node, _isInput); return out; } diff --git a/river/Interface.h b/river/Interface.h index 49c1e11..6980253 100644 --- a/river/Interface.h +++ b/river/Interface.h @@ -41,6 +41,15 @@ namespace river { virtual std::string getName() { return m_name; }; + protected: + bool m_isInput; + public: + bool isInput() { + return m_isInput; + } + bool isOutput() { + return !m_isInput; + } protected: /** * @brief Constructor @@ -50,7 +59,8 @@ namespace river { float _freq, const std::vector& _map, audio::format _format, - const std::shared_ptr& _node); + const std::shared_ptr& _node, + bool _isInput); public: /** * @brief Destructor @@ -60,7 +70,8 @@ namespace river { float _freq, const std::vector& _map, audio::format _format, - const std::shared_ptr& _node); + const std::shared_ptr& _node, + bool _isInput); /** * @brief set the read/write mode enable. */ diff --git a/river/Manager.cpp b/river/Manager.cpp index 5825e29..7088692 100644 --- a/river/Manager.cpp +++ b/river/Manager.cpp @@ -57,34 +57,34 @@ std::pair river::Manager::getVolumeRange(const std::string& _volume } std::shared_ptr river::Manager::createOutput(float _freq, - const std::vector& _map, - audio::format _format, - const std::string& _streamName, - const std::string& _name) { + const std::vector& _map, + audio::format _format, + const std::string& _streamName, + const std::string& _name) { // get global hardware interface: std::shared_ptr manager = river::io::Manager::getInstance(); // get the output or input channel : - std::shared_ptr node = manager->getNode(_streamName);//, false); + std::shared_ptr node = manager->getNode(_streamName); // create user iterface: std::shared_ptr interface; - interface = river::Interface::create(_name, _freq, _map, _format, node); + interface = river::Interface::create(_name, _freq, _map, _format, node, false); // store it in a list (needed to apply some parameters). m_listOpenInterface.push_back(interface); return interface; } std::shared_ptr river::Manager::createInput(float _freq, - const std::vector& _map, - audio::format _format, - const std::string& _streamName, - const std::string& _name) { + const std::vector& _map, + audio::format _format, + const std::string& _streamName, + const std::string& _name) { // get global hardware interface: std::shared_ptr manager = river::io::Manager::getInstance(); // get the output or input channel : - std::shared_ptr node = manager->getNode(_streamName);//, true); + std::shared_ptr node = manager->getNode(_streamName); // create user iterface: std::shared_ptr interface; - interface = river::Interface::create(_name, _freq, _map, _format, node); + interface = river::Interface::create(_name, _freq, _map, _format, node, true); // store it in a list (needed to apply some parameters). m_listOpenInterface.push_back(interface); return interface; diff --git a/river/io/Node.cpp b/river/io/Node.cpp index e05180e..3469a52 100644 --- a/river/io/Node.cpp +++ b/river/io/Node.cpp @@ -25,60 +25,91 @@ #define INT32_MIN (-INT32_MAX - 1L) #endif -int32_t river::io::Node::rtAudioCallback(void* _outputBuffer, - void* _inputBuffer, - unsigned int _nBufferFrames, - double _streamTime, - airtaudio::status _status) { +std::string asString(const std::chrono::system_clock::time_point& tp) { + // convert to system time: + std::time_t t = std::chrono::system_clock::to_time_t(tp); + // convert in human string + std::string ts = std::ctime(&t); + // remove \n + ts.resize(ts.size()-1); + return ts; +} + +namespace std { + std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj) { + std::chrono::microseconds us = std::chrono::duration_cast(_obj.time_since_epoch()); + _os << us.count(); + return _os; + } +} + + +int32_t river::io::Node::airtAudioCallback(void* _outputBuffer, + void* _inputBuffer, + uint32_t _nbChunk, + const std::chrono::system_clock::time_point& _time, + airtaudio::status _status) { std::unique_lock lock(m_mutex); - std::chrono::system_clock::time_point ttime = std::chrono::system_clock::time_point();//std::chrono::system_clock::now(); + //RIVER_INFO("Time=" << _time); /* for (int32_t iii=0; iii<400; ++iii) { RIVER_VERBOSE("dummy=" << uint64_t(dummy[iii])); } */ if (_outputBuffer != nullptr) { - RIVER_VERBOSE("data Output size request :" << _nBufferFrames << " [BEGIN] status=" << _status); + RIVER_VERBOSE("data Output size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size()); std::vector output; - RIVER_VERBOSE("resize=" << _nBufferFrames*m_process.getInputConfig().getMap().size()); - output.resize(_nBufferFrames*m_process.getInputConfig().getMap().size(), 0); + RIVER_VERBOSE("resize=" << _nbChunk*m_process.getInputConfig().getMap().size()); + output.resize(_nbChunk*m_process.getInputConfig().getMap().size(), 0); const int32_t* outputTmp = nullptr; std::vector outputTmp2; - RIVER_VERBOSE("resize=" << sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nBufferFrames); - outputTmp2.resize(sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nBufferFrames, 0); - int32_t id = 1; + RIVER_VERBOSE("resize=" << sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nbChunk); + outputTmp2.resize(sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nbChunk, 0); for (auto &it : m_list) { - RIVER_VERBOSE(" IO : " << id << "/" << m_list.size() << " pointer : " << uint64_t(&(*it))); - if (it != nullptr) { - RIVER_VERBOSE(" name="<< it->getName()); - // clear datas ... - memset(&outputTmp2[0], 0, sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nBufferFrames); - RIVER_VERBOSE(" request Data="<< _nBufferFrames); - it->systemNeedOutputData(ttime, &outputTmp2[0], _nBufferFrames, sizeof(int32_t)*m_process.getInputConfig().getMap().size()); - RIVER_VERBOSE(" Mix it ..."); - outputTmp = reinterpret_cast(&outputTmp2[0]); - // Add data to the output tmp buffer : - for (size_t kkk=0; kkkisOutput() == false) { + continue; + } + RIVER_VERBOSE(" IO name="<< it->getName()); + // clear datas ... + memset(&outputTmp2[0], 0, sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nbChunk); + RIVER_VERBOSE(" request Data="<< _nbChunk); + it->systemNeedOutputData(_time, &outputTmp2[0], _nbChunk, sizeof(int32_t)*m_process.getInputConfig().getMap().size()); + RIVER_VERBOSE(" Mix it ..."); + outputTmp = reinterpret_cast(&outputTmp2[0]); + // Add data to the output tmp buffer : + for (size_t kkk=0; kkkisInput() == false) { + continue; + } + RIVER_VERBOSE(" IO name="<< it->getName() << " (feedback)"); + it->systemNewInputData(_time, _outputBuffer, _nbChunk); + } + RIVER_VERBOSE("data Output size request :" << _nbChunk << " [ END ]"); } if (_inputBuffer != nullptr) { - RIVER_VERBOSE("data Input size request :" << _nBufferFrames << " [BEGIN]"); + RIVER_VERBOSE("data Input size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size()); int16_t* inputBuffer = static_cast(_inputBuffer); - for (size_t iii=0; iii< m_list.size(); ++iii) { - if (m_list[iii] != nullptr) { - RIVER_INFO(" IO : " << iii+1 << "/" << m_list.size() << " name="<< m_list[iii]->getName()); - m_list[iii]->systemNewInputData(ttime, inputBuffer, _nBufferFrames); + for (auto &it : m_list) { + if (it == nullptr) { + continue; } + RIVER_INFO(" IO name="<< it->getName()); + it->systemNewInputData(_time, inputBuffer, _nbChunk); } - RIVER_VERBOSE("data Input size request :" << _nBufferFrames << " [ END ]"); + RIVER_VERBOSE("data Input size request :" << _nbChunk << " [ END ]"); } return 0; } @@ -215,7 +246,7 @@ river::io::Node::Node(const std::string& _name, const std::shared_ptr