[DEV] rename lib river in audio::river

This commit is contained in:
Edouard DUPIN 2015-04-11 09:38:30 +02:00
parent bf05f46f24
commit 26e71b2a92
46 changed files with 1806 additions and 1799 deletions

View File

@ -7,16 +7,16 @@
#include "debug.h" #include "debug.h"
#include "Interface.h" #include "Interface.h"
#include "io/Node.h" #include "io/Node.h"
#include <drain/EndPointCallback.h> #include <audio/drain/EndPointCallback.h>
#include <drain/EndPointWrite.h> #include <audio/drain/EndPointWrite.h>
#include <drain/EndPointRead.h> #include <audio/drain/EndPointRead.h>
#include <drain/Volume.h> #include <audio/drain/Volume.h>
#undef __class__ #undef __class__
#define __class__ "Interface" #define __class__ "Interface"
river::Interface::Interface(void) : audio::river::Interface::Interface(void) :
m_node(), m_node(),
m_name("") { m_name("") {
static uint32_t uid = 0; static uint32_t uid = 0;
@ -24,24 +24,24 @@ river::Interface::Interface(void) :
} }
bool river::Interface::init(float _freq, bool audio::river::Interface::init(float _freq,
const std::vector<audio::channel>& _map, const std::vector<audio::channel>& _map,
audio::format _format, audio::format _format,
const std11::shared_ptr<river::io::Node>& _node, const std11::shared_ptr<audio::river::io::Node>& _node,
const std11::shared_ptr<const ejson::Object>& _config) { const std11::shared_ptr<const ejson::Object>& _config) {
std::vector<audio::channel> map(_map); std::vector<audio::channel> map(_map);
m_node = _node; m_node = _node;
m_config = _config; m_config = _config;
m_mode = river::modeInterface_unknow; m_mode = audio::river::modeInterface_unknow;
std::string type = m_config->getStringValue("io", "error"); std::string type = m_config->getStringValue("io", "error");
static int32_t uid=0; static int32_t uid=0;
m_name = _node->getName() + "__" + (_node->isInput()==true?"input":"output") + "__" + type + "__" + etk::to_string(uid++); m_name = _node->getName() + "__" + (_node->isInput()==true?"input":"output") + "__" + type + "__" + etk::to_string(uid++);
if (type == "output") { if (type == "output") {
m_mode = river::modeInterface_output; m_mode = audio::river::modeInterface_output;
} else if (type == "input") { } else if (type == "input") {
m_mode = river::modeInterface_input; m_mode = audio::river::modeInterface_input;
} else if (type == "feedback") { } else if (type == "feedback") {
m_mode = river::modeInterface_feedback; m_mode = audio::river::modeInterface_feedback;
} }
// register interface to be notify from the volume change. // register interface to be notify from the volume change.
m_node->registerAsRemote(shared_from_this()); m_node->registerAsRemote(shared_from_this());
@ -54,28 +54,28 @@ bool river::Interface::init(float _freq,
// Create convertion interface // Create convertion interface
if ( m_node->isInput() == true if ( m_node->isInput() == true
&& m_mode == river::modeInterface_input) { && m_mode == audio::river::modeInterface_input) {
m_process.setInputConfig(m_node->getInterfaceFormat()); m_process.setInputConfig(m_node->getInterfaceFormat());
// Add volume only if the Low level has a volume (otherwise it will be added by the application) // Add volume only if the Low level has a volume (otherwise it will be added by the application)
std11::shared_ptr<drain::VolumeElement> tmpVolume = m_node->getVolume(); std11::shared_ptr<audio::drain::VolumeElement> tmpVolume = m_node->getVolume();
if (tmpVolume != nullptr) { if (tmpVolume != nullptr) {
// add all time the volume stage : // add all time the volume stage :
std11::shared_ptr<drain::Volume> algo = drain::Volume::create(); std11::shared_ptr<audio::drain::Volume> algo = audio::drain::Volume::create();
//algo->setInputFormat(m_node->getInterfaceFormat()); //algo->setInputFormat(m_node->getInterfaceFormat());
algo->setName("volume"); algo->setName("volume");
m_process.pushBack(algo); m_process.pushBack(algo);
RIVER_INFO(" add volume for node"); RIVER_INFO(" add volume for node");
algo->addVolumeStage(tmpVolume); algo->addVolumeStage(tmpVolume);
} }
m_process.setOutputConfig(drain::IOFormatInterface(map, _format, _freq)); m_process.setOutputConfig(audio::drain::IOFormatInterface(map, _format, _freq));
} else if ( m_node->isOutput() == true } else if ( m_node->isOutput() == true
&& m_mode == river::modeInterface_output) { && m_mode == audio::river::modeInterface_output) {
m_process.setInputConfig(drain::IOFormatInterface(map, _format, _freq)); m_process.setInputConfig(audio::drain::IOFormatInterface(map, _format, _freq));
// Add volume only if the Low level has a volume (otherwise it will be added by the application) // Add volume only if the Low level has a volume (otherwise it will be added by the application)
std11::shared_ptr<drain::VolumeElement> tmpVolume = m_node->getVolume(); std11::shared_ptr<audio::drain::VolumeElement> tmpVolume = m_node->getVolume();
if (tmpVolume != nullptr) { if (tmpVolume != nullptr) {
// add all time the volume stage : // add all time the volume stage :
std11::shared_ptr<drain::Volume> algo = drain::Volume::create(); std11::shared_ptr<audio::drain::Volume> algo = audio::drain::Volume::create();
//algo->setOutputFormat(m_node->getInterfaceFormat()); //algo->setOutputFormat(m_node->getInterfaceFormat());
algo->setName("volume"); algo->setName("volume");
m_process.pushBack(algo); m_process.pushBack(algo);
@ -84,10 +84,10 @@ bool river::Interface::init(float _freq,
} }
m_process.setOutputConfig(m_node->getInterfaceFormat()); m_process.setOutputConfig(m_node->getInterfaceFormat());
} else if ( m_node->isOutput() == true } else if ( m_node->isOutput() == true
&& m_mode == river::modeInterface_feedback) { && m_mode == audio::river::modeInterface_feedback) {
m_process.setInputConfig(m_node->getHarwareFormat()); m_process.setInputConfig(m_node->getHarwareFormat());
// note : feedback has no volume stage ... // note : feedback has no volume stage ...
m_process.setOutputConfig(drain::IOFormatInterface(map, _format, _freq)); m_process.setOutputConfig(audio::drain::IOFormatInterface(map, _format, _freq));
} else { } else {
RIVER_ERROR("Can not link virtual interface with type : " << m_mode << " to a hardware interface " << (m_node->isInput()==true?"input":"output")); RIVER_ERROR("Can not link virtual interface with type : " << m_mode << " to a hardware interface " << (m_node->isInput()==true?"input":"output"));
return false; return false;
@ -95,83 +95,83 @@ bool river::Interface::init(float _freq,
return true; return true;
} }
std11::shared_ptr<river::Interface> river::Interface::create(float _freq, std11::shared_ptr<audio::river::Interface> audio::river::Interface::create(float _freq,
const std::vector<audio::channel>& _map, const std::vector<audio::channel>& _map,
audio::format _format, audio::format _format,
const std11::shared_ptr<river::io::Node>& _node, const std11::shared_ptr<audio::river::io::Node>& _node,
const std11::shared_ptr<const ejson::Object>& _config) { const std11::shared_ptr<const ejson::Object>& _config) {
std11::shared_ptr<river::Interface> out = std11::shared_ptr<river::Interface>(new river::Interface()); std11::shared_ptr<audio::river::Interface> out = std11::shared_ptr<audio::river::Interface>(new audio::river::Interface());
out->init(_freq, _map, _format, _node, _config); out->init(_freq, _map, _format, _node, _config);
return out; return out;
} }
river::Interface::~Interface() { audio::river::Interface::~Interface() {
//stop(true, true); //stop(true, true);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
//m_node->interfaceRemove(shared_from_this()); //m_node->interfaceRemove(shared_from_this());
} }
/* /*
bool river::Interface::hasEndPoint() { bool audio::river::Interface::hasEndPoint() {
} }
*/ */
void river::Interface::setReadwrite() { void audio::river::Interface::setReadwrite() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.removeAlgoDynamic(); m_process.removeAlgoDynamic();
if (m_process.hasType<drain::EndPoint>() ) { if (m_process.hasType<audio::drain::EndPoint>() ) {
RIVER_ERROR("Endpoint is already present ==> can not change"); RIVER_ERROR("Endpoint is already present ==> can not change");
return; return;
} }
if (m_node->isInput() == true) { if (m_node->isInput() == true) {
m_process.removeIfLast<drain::EndPoint>(); m_process.removeIfLast<audio::drain::EndPoint>();
std11::shared_ptr<drain::EndPointRead> algo = drain::EndPointRead::create(); std11::shared_ptr<audio::drain::EndPointRead> algo = audio::drain::EndPointRead::create();
m_process.pushBack(algo); m_process.pushBack(algo);
} else { } else {
m_process.removeIfFirst<drain::EndPoint>(); m_process.removeIfFirst<audio::drain::EndPoint>();
std11::shared_ptr<drain::EndPointWrite> algo = drain::EndPointWrite::create(); std11::shared_ptr<audio::drain::EndPointWrite> algo = audio::drain::EndPointWrite::create();
m_process.pushFront(algo); m_process.pushFront(algo);
} }
} }
void river::Interface::setOutputCallback(drain::playbackFunction _function) { void audio::river::Interface::setOutputCallback(audio::drain::playbackFunction _function) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_mode != river::modeInterface_output) { if (m_mode != audio::river::modeInterface_output) {
RIVER_ERROR("Can not set output endpoint on other than a output IO"); RIVER_ERROR("Can not set output endpoint on other than a output IO");
return; return;
} }
m_process.removeAlgoDynamic(); m_process.removeAlgoDynamic();
m_process.removeIfFirst<drain::EndPoint>(); m_process.removeIfFirst<audio::drain::EndPoint>();
std11::shared_ptr<drain::Algo> algo = drain::EndPointCallback::create(_function); std11::shared_ptr<audio::drain::Algo> algo = audio::drain::EndPointCallback::create(_function);
m_process.pushFront(algo); m_process.pushFront(algo);
} }
void river::Interface::setInputCallback(drain::recordFunction _function) { void audio::river::Interface::setInputCallback(audio::drain::recordFunction _function) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_mode == river::modeInterface_output) { if (m_mode == audio::river::modeInterface_output) {
RIVER_ERROR("Can not set output endpoint on other than a input or feedback IO"); RIVER_ERROR("Can not set output endpoint on other than a input or feedback IO");
return; return;
} }
m_process.removeAlgoDynamic(); m_process.removeAlgoDynamic();
m_process.removeIfLast<drain::EndPoint>(); m_process.removeIfLast<audio::drain::EndPoint>();
std11::shared_ptr<drain::Algo> algo = drain::EndPointCallback::create(_function); std11::shared_ptr<audio::drain::Algo> algo = audio::drain::EndPointCallback::create(_function);
m_process.pushBack(algo); m_process.pushBack(algo);
} }
void river::Interface::setWriteCallback(drain::playbackFunctionWrite _function) { void audio::river::Interface::setWriteCallback(audio::drain::playbackFunctionWrite _function) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_mode != river::modeInterface_output) { if (m_mode != audio::river::modeInterface_output) {
RIVER_ERROR("Can not set output endpoint on other than a output IO"); RIVER_ERROR("Can not set output endpoint on other than a output IO");
return; return;
} }
m_process.removeAlgoDynamic(); m_process.removeAlgoDynamic();
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0); std11::shared_ptr<audio::drain::EndPointWrite> algo = m_process.get<audio::drain::EndPointWrite>(0);
if (algo == nullptr) { if (algo == nullptr) {
return; return;
} }
algo->setCallback(_function); algo->setCallback(_function);
} }
void river::Interface::start(const std11::chrono::system_clock::time_point& _time) { void audio::river::Interface::start(const std11::chrono::system_clock::time_point& _time) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
RIVER_DEBUG("start [BEGIN]"); RIVER_DEBUG("start [BEGIN]");
m_process.updateInterAlgo(); m_process.updateInterAlgo();
@ -179,21 +179,21 @@ void river::Interface::start(const std11::chrono::system_clock::time_point& _tim
RIVER_DEBUG("start [ END ]"); RIVER_DEBUG("start [ END ]");
} }
void river::Interface::stop(bool _fast, bool _abort) { void audio::river::Interface::stop(bool _fast, bool _abort) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
RIVER_DEBUG("stop [BEGIN]"); RIVER_DEBUG("stop [BEGIN]");
m_node->interfaceRemove(shared_from_this()); m_node->interfaceRemove(shared_from_this());
RIVER_DEBUG("stop [ END]"); RIVER_DEBUG("stop [ END]");
} }
void river::Interface::abort() { void audio::river::Interface::abort() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
RIVER_DEBUG("abort [BEGIN]"); RIVER_DEBUG("abort [BEGIN]");
// TODO :... // TODO :...
RIVER_DEBUG("abort [ END ]"); RIVER_DEBUG("abort [ END ]");
} }
bool river::Interface::setParameter(const std::string& _filter, const std::string& _parameter, const std::string& _value) { bool audio::river::Interface::setParameter(const std::string& _filter, const std::string& _parameter, const std::string& _value) {
RIVER_DEBUG("setParameter [BEGIN] : '" << _filter << "':'" << _parameter << "':'" << _value << "'"); RIVER_DEBUG("setParameter [BEGIN] : '" << _filter << "':'" << _parameter << "':'" << _value << "'");
bool out = false; bool out = false;
if ( _filter == "volume" if ( _filter == "volume"
@ -201,7 +201,7 @@ bool river::Interface::setParameter(const std::string& _filter, const std::strin
RIVER_ERROR("Interface is not allowed to modify '" << _parameter << "' Volume just allowed to modify 'FLOW' volume"); RIVER_ERROR("Interface is not allowed to modify '" << _parameter << "' Volume just allowed to modify 'FLOW' volume");
return false; return false;
} }
std11::shared_ptr<drain::Algo> algo = m_process.get<drain::Algo>(_filter); std11::shared_ptr<audio::drain::Algo> algo = m_process.get<audio::drain::Algo>(_filter);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("setParameter(" << _filter << ") ==> no filter named like this ..."); RIVER_ERROR("setParameter(" << _filter << ") ==> no filter named like this ...");
return false; return false;
@ -210,10 +210,10 @@ bool river::Interface::setParameter(const std::string& _filter, const std::strin
RIVER_DEBUG("setParameter [ END ] : '" << out << "'"); RIVER_DEBUG("setParameter [ END ] : '" << out << "'");
return out; return out;
} }
std::string river::Interface::getParameter(const std::string& _filter, const std::string& _parameter) const { std::string audio::river::Interface::getParameter(const std::string& _filter, const std::string& _parameter) const {
RIVER_DEBUG("getParameter [BEGIN] : '" << _filter << "':'" << _parameter << "'"); RIVER_DEBUG("getParameter [BEGIN] : '" << _filter << "':'" << _parameter << "'");
std::string out; std::string out;
std11::shared_ptr<const drain::Algo> algo = m_process.get<const drain::Algo>(_filter); std11::shared_ptr<const audio::drain::Algo> algo = m_process.get<const audio::drain::Algo>(_filter);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("setParameter(" << _filter << ") ==> no filter named like this ..."); RIVER_ERROR("setParameter(" << _filter << ") ==> no filter named like this ...");
return "[ERROR]"; return "[ERROR]";
@ -222,10 +222,10 @@ std::string river::Interface::getParameter(const std::string& _filter, const std
RIVER_DEBUG("getParameter [ END ] : '" << out << "'"); RIVER_DEBUG("getParameter [ END ] : '" << out << "'");
return out; return out;
} }
std::string river::Interface::getParameterProperty(const std::string& _filter, const std::string& _parameter) const { std::string audio::river::Interface::getParameterProperty(const std::string& _filter, const std::string& _parameter) const {
RIVER_DEBUG("getParameterProperty [BEGIN] : '" << _filter << "':'" << _parameter << "'"); RIVER_DEBUG("getParameterProperty [BEGIN] : '" << _filter << "':'" << _parameter << "'");
std::string out; std::string out;
std11::shared_ptr<const drain::Algo> algo = m_process.get<const drain::Algo>(_filter); std11::shared_ptr<const audio::drain::Algo> algo = m_process.get<const audio::drain::Algo>(_filter);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("setParameter(" << _filter << ") ==> no filter named like this ..."); RIVER_ERROR("setParameter(" << _filter << ") ==> no filter named like this ...");
return "[ERROR]"; return "[ERROR]";
@ -235,10 +235,10 @@ std::string river::Interface::getParameterProperty(const std::string& _filter, c
return out; return out;
} }
void river::Interface::write(const void* _value, size_t _nbChunk) { void audio::river::Interface::write(const void* _value, size_t _nbChunk) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.updateInterAlgo(); m_process.updateInterAlgo();
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0); std11::shared_ptr<audio::drain::EndPointWrite> algo = m_process.get<audio::drain::EndPointWrite>(0);
if (algo == nullptr) { if (algo == nullptr) {
return; return;
} }
@ -247,7 +247,7 @@ void river::Interface::write(const void* _value, size_t _nbChunk) {
#if 0 #if 0
// TODO : add API aCCess mutex for Read and write... // TODO : add API aCCess mutex for Read and write...
std::vector<int16_t> river::Interface::read(size_t _nbChunk) { std::vector<int16_t> audio::river::Interface::read(size_t _nbChunk) {
// TODO :... // TODO :...
std::vector<int16_t> data; std::vector<int16_t> data;
/* /*
@ -270,14 +270,14 @@ std::vector<int16_t> river::Interface::read(size_t _nbChunk) {
} }
#endif #endif
void river::Interface::read(void* _value, size_t _nbChunk) { void audio::river::Interface::read(void* _value, size_t _nbChunk) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.updateInterAlgo(); m_process.updateInterAlgo();
// TODO :... // TODO :...
} }
size_t river::Interface::size() const { size_t audio::river::Interface::size() const {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
// TODO :... // TODO :...
return 0; return 0;
@ -287,10 +287,10 @@ size_t river::Interface::size() const {
void river::Interface::setBufferSize(size_t _nbChunk) { void audio::river::Interface::setBufferSize(size_t _nbChunk) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_node->isInput() == true) { if (m_node->isInput() == true) {
std11::shared_ptr<drain::EndPointRead> algo = m_process.get<drain::EndPointRead>(m_process.size()-1); std11::shared_ptr<audio::drain::EndPointRead> algo = m_process.get<audio::drain::EndPointRead>(m_process.size()-1);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request set buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request set buffer size for Interface that is not READ or WRITE mode ...");
return; return;
@ -298,7 +298,7 @@ void river::Interface::setBufferSize(size_t _nbChunk) {
algo->setBufferSize(_nbChunk); algo->setBufferSize(_nbChunk);
return; return;
} }
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0); std11::shared_ptr<audio::drain::EndPointWrite> algo = m_process.get<audio::drain::EndPointWrite>(0);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request set buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request set buffer size for Interface that is not READ or WRITE mode ...");
return; return;
@ -306,10 +306,10 @@ void river::Interface::setBufferSize(size_t _nbChunk) {
algo->setBufferSize(_nbChunk); algo->setBufferSize(_nbChunk);
} }
void river::Interface::setBufferSize(const std11::chrono::microseconds& _time) { void audio::river::Interface::setBufferSize(const std11::chrono::microseconds& _time) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_node->isInput() == true) { if (m_node->isInput() == true) {
std11::shared_ptr<drain::EndPointRead> algo = m_process.get<drain::EndPointRead>(m_process.size()-1); std11::shared_ptr<audio::drain::EndPointRead> algo = m_process.get<audio::drain::EndPointRead>(m_process.size()-1);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request set buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request set buffer size for Interface that is not READ or WRITE mode ...");
return; return;
@ -317,7 +317,7 @@ void river::Interface::setBufferSize(const std11::chrono::microseconds& _time) {
algo->setBufferSize(_time); algo->setBufferSize(_time);
return; return;
} }
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0); std11::shared_ptr<audio::drain::EndPointWrite> algo = m_process.get<audio::drain::EndPointWrite>(0);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request set buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request set buffer size for Interface that is not READ or WRITE mode ...");
return; return;
@ -325,17 +325,17 @@ void river::Interface::setBufferSize(const std11::chrono::microseconds& _time) {
algo->setBufferSize(_time); algo->setBufferSize(_time);
} }
size_t river::Interface::getBufferSize() { size_t audio::river::Interface::getBufferSize() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_node->isInput() == true) { if (m_node->isInput() == true) {
std11::shared_ptr<drain::EndPointRead> algo = m_process.get<drain::EndPointRead>(m_process.size()-1); std11::shared_ptr<audio::drain::EndPointRead> algo = m_process.get<audio::drain::EndPointRead>(m_process.size()-1);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ...");
return 0; return 0;
} }
return algo->getBufferSize(); return algo->getBufferSize();
} }
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0); std11::shared_ptr<audio::drain::EndPointWrite> algo = m_process.get<audio::drain::EndPointWrite>(0);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ...");
return 0; return 0;
@ -343,17 +343,17 @@ size_t river::Interface::getBufferSize() {
return algo->getBufferSize(); return algo->getBufferSize();
} }
std11::chrono::microseconds river::Interface::getBufferSizeMicrosecond() { std11::chrono::microseconds audio::river::Interface::getBufferSizeMicrosecond() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_node->isInput() == true) { if (m_node->isInput() == true) {
std11::shared_ptr<drain::EndPointRead> algo = m_process.get<drain::EndPointRead>(m_process.size()-1); std11::shared_ptr<audio::drain::EndPointRead> algo = m_process.get<audio::drain::EndPointRead>(m_process.size()-1);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ...");
return std11::chrono::microseconds(0); return std11::chrono::microseconds(0);
} }
return algo->getBufferSizeMicrosecond(); return algo->getBufferSizeMicrosecond();
} }
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0); std11::shared_ptr<audio::drain::EndPointWrite> algo = m_process.get<audio::drain::EndPointWrite>(0);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ...");
return std11::chrono::microseconds(0); return std11::chrono::microseconds(0);
@ -361,17 +361,17 @@ std11::chrono::microseconds river::Interface::getBufferSizeMicrosecond() {
return algo->getBufferSizeMicrosecond(); return algo->getBufferSizeMicrosecond();
} }
size_t river::Interface::getBufferFillSize() { size_t audio::river::Interface::getBufferFillSize() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_node->isInput() == true) { if (m_node->isInput() == true) {
std11::shared_ptr<drain::EndPointRead> algo = m_process.get<drain::EndPointRead>(m_process.size()-1); std11::shared_ptr<audio::drain::EndPointRead> algo = m_process.get<audio::drain::EndPointRead>(m_process.size()-1);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ...");
return 0; return 0;
} }
return algo->getBufferFillSize(); return algo->getBufferFillSize();
} }
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0); std11::shared_ptr<audio::drain::EndPointWrite> algo = m_process.get<audio::drain::EndPointWrite>(0);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ...");
return 0; return 0;
@ -380,17 +380,17 @@ size_t river::Interface::getBufferFillSize() {
} }
std11::chrono::microseconds river::Interface::getBufferFillSizeMicrosecond() { std11::chrono::microseconds audio::river::Interface::getBufferFillSizeMicrosecond() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (m_node->isInput() == true) { if (m_node->isInput() == true) {
std11::shared_ptr<drain::EndPointRead> algo = m_process.get<drain::EndPointRead>(m_process.size()-1); std11::shared_ptr<audio::drain::EndPointRead> algo = m_process.get<audio::drain::EndPointRead>(m_process.size()-1);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ...");
return std11::chrono::microseconds(0); return std11::chrono::microseconds(0);
} }
return algo->getBufferFillSizeMicrosecond(); return algo->getBufferFillSizeMicrosecond();
} }
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0); std11::shared_ptr<audio::drain::EndPointWrite> algo = m_process.get<audio::drain::EndPointWrite>(0);
if (algo == nullptr) { if (algo == nullptr) {
RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ..."); RIVER_ERROR("Request get buffer size for Interface that is not READ or WRITE mode ...");
return std11::chrono::microseconds(0); return std11::chrono::microseconds(0);
@ -400,28 +400,28 @@ std11::chrono::microseconds river::Interface::getBufferFillSizeMicrosecond() {
void river::Interface::clearInternalBuffer() { void audio::river::Interface::clearInternalBuffer() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.updateInterAlgo(); m_process.updateInterAlgo();
// TODO :... // TODO :...
} }
std11::chrono::system_clock::time_point river::Interface::getCurrentTime() const { std11::chrono::system_clock::time_point audio::river::Interface::getCurrentTime() const {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
// TODO :... // TODO :...
return std11::chrono::system_clock::time_point(); return std11::chrono::system_clock::time_point();
return std11::chrono::system_clock::now(); return std11::chrono::system_clock::now();
} }
void river::Interface::addVolumeGroup(const std::string& _name) { void audio::river::Interface::addVolumeGroup(const std::string& _name) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
RIVER_DEBUG("addVolumeGroup(" << _name << ")"); RIVER_DEBUG("addVolumeGroup(" << _name << ")");
std11::shared_ptr<drain::Volume> algo = m_process.get<drain::Volume>("volume"); std11::shared_ptr<audio::drain::Volume> algo = m_process.get<audio::drain::Volume>("volume");
if (algo == nullptr) { if (algo == nullptr) {
m_process.removeAlgoDynamic(); m_process.removeAlgoDynamic();
// add all time the volume stage : // add all time the volume stage :
algo = drain::Volume::create(); algo = audio::drain::Volume::create();
algo->setName("volume"); algo->setName("volume");
if (m_node->isInput() == true) { if (m_node->isInput() == true) {
m_process.pushFront(algo); m_process.pushFront(algo);
@ -431,29 +431,29 @@ void river::Interface::addVolumeGroup(const std::string& _name) {
} }
if (_name == "FLOW") { if (_name == "FLOW") {
// Local volume name // Local volume name
algo->addVolumeStage(std11::make_shared<drain::VolumeElement>(_name)); algo->addVolumeStage(std11::make_shared<audio::drain::VolumeElement>(_name));
} else { } else {
// get manager unique instance: // get manager unique instance:
std11::shared_ptr<river::io::Manager> mng = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> mng = audio::river::io::Manager::getInstance();
algo->addVolumeStage(mng->getVolumeGroup(_name)); algo->addVolumeStage(mng->getVolumeGroup(_name));
} }
} }
void river::Interface::systemNewInputData(std11::chrono::system_clock::time_point _time, const void* _data, size_t _nbChunk) { void audio::river::Interface::systemNewInputData(std11::chrono::system_clock::time_point _time, const void* _data, size_t _nbChunk) {
std11::unique_lock<std11::recursive_mutex> lockProcess(m_mutex); std11::unique_lock<std11::recursive_mutex> lockProcess(m_mutex);
void * tmpData = const_cast<void*>(_data); void * tmpData = const_cast<void*>(_data);
m_process.push(_time, tmpData, _nbChunk); m_process.push(_time, tmpData, _nbChunk);
} }
void river::Interface::systemNeedOutputData(std11::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize) { void audio::river::Interface::systemNeedOutputData(std11::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize) {
std11::unique_lock<std11::recursive_mutex> lockProcess(m_mutex); std11::unique_lock<std11::recursive_mutex> lockProcess(m_mutex);
//RIVER_INFO("time : " << _time); //RIVER_INFO("time : " << _time);
m_process.pull(_time, _data, _nbChunk, _chunkSize); m_process.pull(_time, _data, _nbChunk, _chunkSize);
} }
void river::Interface::systemVolumeChange() { void audio::river::Interface::systemVolumeChange() {
std11::unique_lock<std11::recursive_mutex> lockProcess(m_mutex); std11::unique_lock<std11::recursive_mutex> lockProcess(m_mutex);
std11::shared_ptr<drain::Volume> algo = m_process.get<drain::Volume>("volume"); std11::shared_ptr<audio::drain::Volume> algo = m_process.get<audio::drain::Volume>("volume");
if (algo == nullptr) { if (algo == nullptr) {
return; return;
} }
@ -477,45 +477,45 @@ static void link(etk::FSNode& _node, const std::string& _first, const std::strin
} }
} }
std::string river::Interface::getDotNodeName() const { std::string audio::river::Interface::getDotNodeName() const {
if (m_mode == river::modeInterface_input) { if (m_mode == audio::river::modeInterface_input) {
return "API_" + etk::to_string(m_uid) + "_input"; return "API_" + etk::to_string(m_uid) + "_input";
} else if (m_mode == river::modeInterface_feedback) { } else if (m_mode == audio::river::modeInterface_feedback) {
return "API_" + etk::to_string(m_uid) + "_feedback"; return "API_" + etk::to_string(m_uid) + "_feedback";
} else if (m_mode == river::modeInterface_output) { } else if (m_mode == audio::river::modeInterface_output) {
return "API_" + etk::to_string(m_uid) + "_output"; return "API_" + etk::to_string(m_uid) + "_output";
} }
return "error"; return "error";
} }
void river::Interface::generateDot(etk::FSNode& _node, const std::string& _nameIO, bool _isLink) { void audio::river::Interface::generateDot(etk::FSNode& _node, const std::string& _nameIO, bool _isLink) {
_node << " subgraph clusterInterface_" << m_uid << " {\n"; _node << " subgraph clusterInterface_" << m_uid << " {\n";
_node << " color=orange;\n"; _node << " color=orange;\n";
_node << " label=\"[" << m_uid << "] Interface : " << m_name << "\";\n"; _node << " label=\"[" << m_uid << "] Interface : " << m_name << "\";\n";
std::string nameIn; std::string nameIn;
std::string nameOut; std::string nameOut;
if ( m_mode == river::modeInterface_input if ( m_mode == audio::river::modeInterface_input
|| m_mode == river::modeInterface_feedback) { || m_mode == audio::river::modeInterface_feedback) {
m_process.generateDot(_node, 3, 10000+m_uid, nameIn, nameOut, false); m_process.generateDot(_node, 3, 10000+m_uid, nameIn, nameOut, false);
} else { } else {
m_process.generateDot(_node, 3, 10000+m_uid, nameIn, nameOut, true); m_process.generateDot(_node, 3, 10000+m_uid, nameIn, nameOut, true);
} }
if ( m_mode == river::modeInterface_input if ( m_mode == audio::river::modeInterface_input
|| m_mode == river::modeInterface_feedback) { || m_mode == audio::river::modeInterface_feedback) {
link(_node, _nameIO, "->", nameIn, _isLink); link(_node, _nameIO, "->", nameIn, _isLink);
} else { } else {
link(_node, _nameIO, "<-", nameOut, _isLink); link(_node, _nameIO, "<-", nameOut, _isLink);
} }
_node << " node [shape=Mdiamond];\n"; _node << " node [shape=Mdiamond];\n";
if (m_mode == river::modeInterface_input) { if (m_mode == audio::river::modeInterface_input) {
_node << " " << getDotNodeName() << " [ label=\"API\\nINPUT\" ];\n"; _node << " " << getDotNodeName() << " [ label=\"API\\nINPUT\" ];\n";
link(_node, nameOut, "->", getDotNodeName()); link(_node, nameOut, "->", getDotNodeName());
} else if (m_mode == river::modeInterface_feedback) { } else if (m_mode == audio::river::modeInterface_feedback) {
_node << " " << getDotNodeName() << " [ label=\"API\\nFEEDBACK\" ];\n"; _node << " " << getDotNodeName() << " [ label=\"API\\nFEEDBACK\" ];\n";
link(_node, nameOut, "->", getDotNodeName()); link(_node, nameOut, "->", getDotNodeName());
} else if (m_mode == river::modeInterface_output) { } else if (m_mode == audio::river::modeInterface_output) {
_node << " " << getDotNodeName() << " [ label=\"API\\nOUTPUT\" ];\n"; _node << " " << getDotNodeName() << " [ label=\"API\\nOUTPUT\" ];\n";
link(_node, nameIn, "<-", getDotNodeName()); link(_node, nameIn, "<-", getDotNodeName());
} }

334
audio/river/Interface.h Normal file
View File

@ -0,0 +1,334 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_RIVER_INTERFACE_H__
#define __AUDIO_RIVER_INTERFACE_H__
#include <string>
#include <vector>
#include <stdint.h>
#include <etk/mutex.h>
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#include <audio/format.h>
#include <audio/channel.h>
#include <audio/drain/Process.h>
#include <audio/drain/EndPointCallback.h>
#include <audio/drain/EndPointWrite.h>
#include <ejson/ejson.h>
#include <etk/os/FSNode.h>
namespace audio {
namespace river {
namespace io {
class Node;
class NodeAirTAudio;
class NodeAEC;
class NodeMuxer;
}
enum modeInterface {
modeInterface_unknow,
modeInterface_input,
modeInterface_output,
modeInterface_feedback,
};
/**
* @brief Interface is the basic handle to manage the input output stream
* @note To create this class see @ref audio::river::Manager class
*/
class Interface : public std11::enable_shared_from_this<Interface> {
friend class io::Node;
friend class io::NodeAirTAudio;
friend class io::NodeAEC;
friend class io::NodeMuxer;
friend class Manager;
protected:
uint32_t m_uid; //!< unique ID for interface
protected:
/**
* @brief Constructor (use factory)
*/
Interface();
/**
* @brief Initilize the Class (do all that is not manage by constructor) Call by factory.
* @param[in] _freq Frequency.
* @param[in] _map Channel map organization.
* @param[in] _format Sample format
* @param[in] _node Low level interface to connect the flow.
* @param[in] _config Special configuration of this interface.
* @return true Configuration done corectly.
* @return false the configuration has an error.
*/
bool init(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std11::shared_ptr<audio::river::io::Node>& _node,
const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Factory of this interface (called by class audio::river::Manager)
* @param[in] _freq Frequency.
* @param[in] _map Channel map organization.
* @param[in] _format Sample format
* @param[in] _node Low level interface to connect the flow.
* @param[in] _config Special configuration of this interface.
* @return nullptr The configuration does not work.
* @return pointer The interface has been corectly created.
*/
static std11::shared_ptr<Interface> create(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std11::shared_ptr<audio::river::io::Node>& _node,
const std11::shared_ptr<const ejson::Object>& _config);
public:
/**
* @brief Destructor
*/
virtual ~Interface();
protected:
mutable std11::recursive_mutex m_mutex; //!< Local mutex to protect data
std11::shared_ptr<const ejson::Object> m_config; //!< configuration set by the user.
protected:
enum modeInterface m_mode; //!< interface type (input/output/feedback)
public:
/**
* @brief Get mode type of the current interface.
* @return The mode requested.
*/
enum modeInterface getMode() {
return m_mode;
}
protected:
audio::drain::Process m_process; //!< Algorithme processing engine
public:
/**
* @brief Get the interface format configuration.
* @return The current format.
*/
const audio::drain::IOFormatInterface& getInterfaceFormat() {
if ( m_mode == modeInterface_input
|| m_mode == modeInterface_feedback) {
return m_process.getOutputConfig();
} else {
return m_process.getInputConfig();
}
}
protected:
std11::shared_ptr<audio::river::io::Node> m_node; //!< Hardware interface to/from stream audio flow.
protected:
std::string m_name; //!< Name of the interface.
public:
/**
* @brief Get interface name.
* @return The current name.
*/
virtual std::string getName() {
return m_name;
};
/**
* @brief Set the interface name
* @param[in] _name new name of the interface
*/
virtual void setName(const std::string& _name) {
m_name = _name;
};
/**
* @brief set the read/write mode enable.
* @note If you not set a output/input callback you must call this function.
*/
virtual void setReadwrite();
/**
* @brief When we want to implement a Callback Mode:
*/
/**
* @brief Set a callback on the write mode interface to know when data is needed in the buffer
* @param[in] _function Function to call
*/
virtual void setWriteCallback(audio::drain::playbackFunctionWrite _function);
/**
* @brief Set Output callback mode with the specify callback.
* @param[in] _function Function to call
*/
virtual void setOutputCallback(audio::drain::playbackFunction _function);
/**
* @brief Set Input callback mode with the specify callback.
* @param[in] _function Function to call
*/
virtual void setInputCallback(audio::drain::recordFunction _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 noise volume control.
*/
virtual void addVolumeGroup(const std::string& _name);
public:
/**
* @brief Start the Audio interface flow.
* @param[in] _time Time to start the flow (0) to start as fast as possible...
* @note _time to play buffer when output interface (if possible)
* @note _time to read buffer when inut interface (if possible)
*/
virtual void start(const std11::chrono::system_clock::time_point& _time = std11::chrono::system_clock::time_point());
/**
* @brief Stop the current flow.
* @param[in] _fast The stream stop as fast as possible (not write all the buffer in speaker) but apply cross fade out.
* @param[in] _abort The stream stop whith no garenty of good audio stop.
*/
virtual void stop(bool _fast=false, bool _abort=false);
/**
* @brief Abort flow (no audio garenty)
*/
virtual void abort();
/**
* @brief Set a parameter in the stream flow
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @param[in] _value Value to set.
* @return true set done
* @return false An error occured
* @example : setParameter("volume", "FLOW", "-3dB");
* @example : setParameter("LowPassFilter", "cutFrequency", "1000Hz");
*/
virtual bool setParameter(const std::string& _filter, const std::string& _parameter, const std::string& _value);
/**
* @brief Get a parameter value
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @return The requested value.
* @example : getParameter("volume", "FLOW"); can return something like "-3dB"
* @example : getParameter("LowPassFilter", "cutFrequency"); can return something like "[-120..0]dB"
*/
virtual std::string getParameter(const std::string& _filter, const std::string& _parameter) const;
/**
* @brief Get a parameter value
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @return The requested value.
* @example : getParameter("volume", "FLOW"); can return something like "[-120..0]dB"
* @example : getParameter("LowPassFilter", "cutFreqiency"); can return something like "]100..10000]Hz"
*/
virtual std::string getParameterProperty(const std::string& _filter, const std::string& _parameter) const;
/**
* @brief write some audio sample in the speakers
* @param[in] _value Data To write on output
* @param[in] _nbChunk Number of audio chunk to write
*/
// TODO : TimeOut ???
virtual void write(const void* _value, size_t _nbChunk);
/**
* @brief read some audio sample from Microphone
* @param[in] _value Data To write on output
* @param[in] _nbChunk Number of audio chunk to write
*/
// TODO : TimeOut ???
virtual void read(void* _value, size_t _nbChunk);
/**
* @brief Get number of chunk in the local buffer
* @return Number of chunk
*/
virtual size_t size() const;
/**
* @brief Set buffer size in chunk number
* @param[in] _nbChunk Number of chunk in the buffer
*/
virtual void setBufferSize(size_t _nbChunk);
/**
* @brief Set buffer size size of the buffer with the stored time in µs
* @param[in] _time Time in microsecond of the buffer
*/
virtual void setBufferSize(const std11::chrono::microseconds& _time);
/**
* @brief get buffer size in chunk number
* @return Number of chunk that can be written in the buffer
*/
virtual size_t getBufferSize();
/**
* @brief Set buffer size size of the buffer with the stored time in µs
* @return Time in microsecond that can be written in the buffer
*/
virtual std11::chrono::microseconds getBufferSizeMicrosecond();
/**
* @brief Get buffer size filled in chunk number
* @return Number of chunk in the buffer (that might be read/write)
*/
virtual size_t getBufferFillSize();
/**
* @brief Set buffer size size of the buffer with the stored time in µs
* @return Time in microsecond of the buffer (that might be read/write)
*/
virtual std11::chrono::microseconds getBufferFillSizeMicrosecond();
/**
* @brief Remove internal Buffer
*/
virtual void clearInternalBuffer();
/**
* @brief Write : Get the time of the next sample time to write in the local buffer
* @brief Read : Get the time of the next sample time to read in the local buffer
*/
virtual std11::chrono::system_clock::time_point getCurrentTime() const;
private:
/**
* @brief Node Call interface : Input interface node has new data.
* @param[in] _time Time where the first sample has been capture.
* @param[in] _data Pointer on the new data.
* @param[in] _nbChunk Number of chunk in the buffer.
*/
virtual void systemNewInputData(std11::chrono::system_clock::time_point _time, const void* _data, size_t _nbChunk);
/**
* @brief Node Call interface: Output interface node need new data.
* @param[in] _time Time where the data might be played
* @param[in] _data Pointer on the data.
* @param[in] _nbChunk Number of chunk that might be write
* @param[in] _chunkSize Chunk size.
*/
virtual void systemNeedOutputData(std11::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize);
/**
* @brief Node Call interface: A volume has change.
*/
virtual void systemVolumeChange();
public:
/**
* @brief Create the dot in the FileNode stream.
* @param[in,out] _node File node to write data.
* @param[in] _nameIO Name to link the interface node
* @param[in] _isLink True if the node is connected on the current interface.
*/
virtual void generateDot(etk::FSNode& _node, const std::string& _nameIO, bool _isLink=true);
/**
* @brief Get the current 'dot' name of the interface
* @return The anme requested.
*/
virtual std::string getDotNodeName() const;
protected:
/**
* @brief Interfanel generate of status
* @param[in] _origin status source
* @param[in] _status Event status
*/
void generateStatus(const std::string& _origin, const std::string& _status) {
m_process.generateStatus(_origin, _status);
}
public:
/**
* @brief Set status callback
* @param[in] _newFunction Function to call
*/
void setStatusFunction(audio::drain::statusFunction _newFunction) {
m_process.setStatusFunction(_newFunction);
}
};
}
}
#endif

View File

@ -16,12 +16,12 @@
#undef __class__ #undef __class__
#define __class__ "Manager" #define __class__ "Manager"
static std11::mutex g_mutex; static std11::mutex g_mutex;
static std::vector<std11::weak_ptr<river::Manager> > g_listOfAllManager; static std::vector<std11::weak_ptr<audio::river::Manager> > g_listOfAllManager;
std11::shared_ptr<river::Manager> river::Manager::create(const std::string& _applicationUniqueId) { std11::shared_ptr<audio::river::Manager> audio::river::Manager::create(const std::string& _applicationUniqueId) {
std11::unique_lock<std11::mutex> lock(g_mutex); std11::unique_lock<std11::mutex> lock(g_mutex);
for (size_t iii=0; iii<g_listOfAllManager.size() ; ++iii) { for (size_t iii=0; iii<g_listOfAllManager.size() ; ++iii) {
std11::shared_ptr<river::Manager> tmp = g_listOfAllManager[iii].lock(); std11::shared_ptr<audio::river::Manager> tmp = g_listOfAllManager[iii].lock();
if (tmp == nullptr) { if (tmp == nullptr) {
continue; continue;
} }
@ -30,7 +30,7 @@ std11::shared_ptr<river::Manager> river::Manager::create(const std::string& _app
} }
} }
// create a new one: // create a new one:
std11::shared_ptr<river::Manager> out = std11::shared_ptr<river::Manager>(new river::Manager(_applicationUniqueId)); std11::shared_ptr<audio::river::Manager> out = std11::shared_ptr<audio::river::Manager>(new audio::river::Manager(_applicationUniqueId));
// add it at the list: // add it at the list:
for (size_t iii=0; iii<g_listOfAllManager.size() ; ++iii) { for (size_t iii=0; iii<g_listOfAllManager.size() ; ++iii) {
if (g_listOfAllManager[iii].expired() == true) { if (g_listOfAllManager[iii].expired() == true) {
@ -42,20 +42,20 @@ std11::shared_ptr<river::Manager> river::Manager::create(const std::string& _app
return out; return out;
} }
river::Manager::Manager(const std::string& _applicationUniqueId) : audio::river::Manager::Manager(const std::string& _applicationUniqueId) :
m_applicationUniqueId(_applicationUniqueId), m_applicationUniqueId(_applicationUniqueId),
m_listOpenInterface() { m_listOpenInterface() {
} }
river::Manager::~Manager() { audio::river::Manager::~Manager() {
// TODO : Stop all interfaces... // TODO : Stop all interfaces...
} }
std::vector<std::string> river::Manager::getListStreamInput() { std::vector<std::string> audio::river::Manager::getListStreamInput() {
std::vector<std::string> output; std::vector<std::string> output;
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... "); RIVER_ERROR("Unable to load harware IO manager ... ");
} else { } else {
@ -64,9 +64,9 @@ std::vector<std::string> river::Manager::getListStreamInput() {
return output; return output;
} }
std::vector<std::string> river::Manager::getListStreamOutput() { std::vector<std::string> audio::river::Manager::getListStreamOutput() {
std::vector<std::string> output; std::vector<std::string> output;
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... "); RIVER_ERROR("Unable to load harware IO manager ... ");
} else { } else {
@ -75,9 +75,9 @@ std::vector<std::string> river::Manager::getListStreamOutput() {
return output; return output;
} }
std::vector<std::string> river::Manager::getListStreamVirtual() { std::vector<std::string> audio::river::Manager::getListStreamVirtual() {
std::vector<std::string> output; std::vector<std::string> output;
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... "); RIVER_ERROR("Unable to load harware IO manager ... ");
} else { } else {
@ -86,9 +86,9 @@ std::vector<std::string> river::Manager::getListStreamVirtual() {
return output; return output;
} }
std::vector<std::string> river::Manager::getListStream() { std::vector<std::string> audio::river::Manager::getListStream() {
std::vector<std::string> output; std::vector<std::string> output;
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... "); RIVER_ERROR("Unable to load harware IO manager ... ");
} else { } else {
@ -97,8 +97,8 @@ std::vector<std::string> river::Manager::getListStream() {
return output; return output;
} }
bool river::Manager::setVolume(const std::string& _volumeName, float _valuedB) { bool audio::river::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... "); RIVER_ERROR("Unable to load harware IO manager ... ");
return false; return false;
@ -106,8 +106,8 @@ bool river::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
return manager->setVolume(_volumeName, _valuedB); return manager->setVolume(_volumeName, _valuedB);
} }
float river::Manager::getVolume(const std::string& _volumeName) const { float audio::river::Manager::getVolume(const std::string& _volumeName) const {
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... "); RIVER_ERROR("Unable to load harware IO manager ... ");
return false; return false;
@ -115,8 +115,8 @@ float river::Manager::getVolume(const std::string& _volumeName) const {
return manager->getVolume(_volumeName); return manager->getVolume(_volumeName);
} }
std::pair<float,float> river::Manager::getVolumeRange(const std::string& _volumeName) const { std::pair<float,float> audio::river::Manager::getVolumeRange(const std::string& _volumeName) const {
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... "); RIVER_ERROR("Unable to load harware IO manager ... ");
return std::make_pair<float,float>(0.0f,0.0f); return std::make_pair<float,float>(0.0f,0.0f);
@ -124,103 +124,103 @@ std::pair<float,float> river::Manager::getVolumeRange(const std::string& _volume
return manager->getVolumeRange(_volumeName); return manager->getVolumeRange(_volumeName);
} }
std11::shared_ptr<river::Interface> river::Manager::createOutput(float _freq, std11::shared_ptr<audio::river::Interface> audio::river::Manager::createOutput(float _freq,
const std::vector<audio::channel>& _map, const std::vector<audio::channel>& _map,
audio::format _format, audio::format _format,
const std::string& _streamName, const std::string& _streamName,
const std::string& _options) { const std::string& _options) {
// get global hardware interface: // get global hardware interface:
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... "); RIVER_ERROR("Unable to load harware IO manager ... ");
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
// get the output or input channel : // get the output or input channel :
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName); std11::shared_ptr<audio::river::io::Node> node = manager->getNode(_streamName);
if (node == nullptr) { if (node == nullptr) {
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream()); RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
if (node->isOutput() != true) { if (node->isOutput() != true) {
RIVER_ERROR("Can not Connect output on other thing than output ... for stream '" << _streamName << "'");; RIVER_ERROR("Can not Connect output on other thing than output ... for stream '" << _streamName << "'");;
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
// create user iterface: // create user iterface:
std11::shared_ptr<river::Interface> interface; std11::shared_ptr<audio::river::Interface> interface;
std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options); std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options);
tmpOption->addString("io", "output"); tmpOption->addString("io", "output");
interface = river::Interface::create(_freq, _map, _format, node, tmpOption); interface = audio::river::Interface::create(_freq, _map, _format, node, tmpOption);
// store it in a list (needed to apply some parameters). // store it in a list (needed to apply some parameters).
m_listOpenInterface.push_back(interface); m_listOpenInterface.push_back(interface);
return interface; return interface;
} }
std11::shared_ptr<river::Interface> river::Manager::createInput(float _freq, std11::shared_ptr<audio::river::Interface> audio::river::Manager::createInput(float _freq,
const std::vector<audio::channel>& _map, const std::vector<audio::channel>& _map,
audio::format _format, audio::format _format,
const std::string& _streamName, const std::string& _streamName,
const std::string& _options) { const std::string& _options) {
// get global hardware interface: // get global hardware interface:
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... "); RIVER_ERROR("Unable to load harware IO manager ... ");
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
// get the output or input channel : // get the output or input channel :
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName); std11::shared_ptr<audio::river::io::Node> node = manager->getNode(_streamName);
if (node == nullptr) { if (node == nullptr) {
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream()); RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
if (node->isInput() != true) { if (node->isInput() != true) {
RIVER_ERROR("Can not Connect input on other thing than input ... for stream '" << _streamName << "'");; RIVER_ERROR("Can not Connect input on other thing than input ... for stream '" << _streamName << "'");;
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
// create user iterface: // create user iterface:
std11::shared_ptr<river::Interface> interface; std11::shared_ptr<audio::river::Interface> interface;
std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options); std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options);
tmpOption->addString("io", "input"); tmpOption->addString("io", "input");
interface = river::Interface::create(_freq, _map, _format, node, tmpOption); interface = audio::river::Interface::create(_freq, _map, _format, node, tmpOption);
// store it in a list (needed to apply some parameters). // store it in a list (needed to apply some parameters).
m_listOpenInterface.push_back(interface); m_listOpenInterface.push_back(interface);
return interface; return interface;
} }
std11::shared_ptr<river::Interface> river::Manager::createFeedback(float _freq, std11::shared_ptr<audio::river::Interface> audio::river::Manager::createFeedback(float _freq,
const std::vector<audio::channel>& _map, const std::vector<audio::channel>& _map,
audio::format _format, audio::format _format,
const std::string& _streamName, const std::string& _streamName,
const std::string& _options) { const std::string& _options) {
// get global hardware interface: // get global hardware interface:
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Unable to load harware IO manager ... "); RIVER_ERROR("Unable to load harware IO manager ... ");
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
// get the output or input channel : // get the output or input channel :
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName); std11::shared_ptr<audio::river::io::Node> node = manager->getNode(_streamName);
if (node == nullptr) { if (node == nullptr) {
RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream()); RIVER_ERROR("Can not get the Requested stream '" << _streamName << "' ==> not listed in : " << manager->getListStream());
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
if (node->isOutput() != true) { if (node->isOutput() != true) {
RIVER_ERROR("Can not Connect feedback on other thing than output ... for stream '" << _streamName << "'");; RIVER_ERROR("Can not Connect feedback on other thing than output ... for stream '" << _streamName << "'");;
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
// create user iterface: // create user iterface:
std11::shared_ptr<river::Interface> interface; std11::shared_ptr<audio::river::Interface> interface;
std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options); std11::shared_ptr<ejson::Object> tmpOption = ejson::Object::create(_options);
tmpOption->addString("io", "feedback"); tmpOption->addString("io", "feedback");
interface = river::Interface::create(_freq, _map, _format, node, tmpOption); interface = audio::river::Interface::create(_freq, _map, _format, node, tmpOption);
// store it in a list (needed to apply some parameters). // store it in a list (needed to apply some parameters).
m_listOpenInterface.push_back(interface); m_listOpenInterface.push_back(interface);
return interface; return interface;
} }
void river::Manager::generateDotAll(const std::string& _filename) { void audio::river::Manager::generateDotAll(const std::string& _filename) {
// get global hardware interface: // get global hardware interface:
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
if (manager == nullptr) { if (manager == nullptr) {
RIVER_ERROR("Can not get the harware manager"); RIVER_ERROR("Can not get the harware manager");
return; return;

140
audio/river/Manager.h Normal file
View File

@ -0,0 +1,140 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_RIVER_MANAGER_H__
#define __AUDIO_RIVER_MANAGER_H__
#include <string>
#include <stdint.h>
#include <etk/memory.h>
#include <audio/river/Interface.h>
#include <audio/format.h>
#include <audio/channel.h>
#include <ejson/ejson.h>
namespace audio {
namespace river {
/**
* @brief Audio interface manager : Single interface for every application that want to access on the Audio input/output
*/
class Manager : public std11::enable_shared_from_this<Manager> {
private:
const std::string& m_applicationUniqueId; //!< name of the application that open the Audio Interface.
std::vector<std11::weak_ptr<audio::river::Interface> > m_listOpenInterface; //!< List of all open Stream.
protected:
/**
* @brief Constructor
*/
Manager(const std::string& _applicationUniqueId);
public:
/**
* @brief factory of the manager. Every Application will have only one maager for all his flow. this permit to manage all of it
* @param[in] _applicationUniqueId Unique name of the application
* @return Pointer on the manager or nullptr if an error occured
*/
static std11::shared_ptr<audio::river::Manager> create(const std::string& _applicationUniqueId);
/**
* @brief Destructor
*/
virtual ~Manager();
public:
/**
* @brief Get all input audio stream.
* @return a list of all availlables input stream name
*/
std::vector<std::string> getListStreamInput();
/**
* @brief Get all output audio stream.
* @return a list of all availlables output stream name
*/
std::vector<std::string> getListStreamOutput();
/**
* @brief Get all audio virtual stream.
* @return a list of all availlables virtual stream name
*/
std::vector<std::string> getListStreamVirtual();
/**
* @brief Get all audio stream.
* @return a list of all availlables stream name
*/
std::vector<std::string> getListStream();
/**
* @brief Set a volume for a specific group
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @param[in] _value Volume in dB to set.
* @return true set done
* @return false An error occured
* @example : setVolume("MASTER", -3.0f);
*/
virtual bool setVolume(const std::string& _volumeName, float _valuedB);
/**
* @brief Get a volume value
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @return The Volume value in dB.
* @example ret = getVolume("MASTER"); can return something like ret = -3.0f
*/
virtual float getVolume(const std::string& _volumeName) const;
/**
* @brief Get a parameter value
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @return The requested value Range.
* @example ret = getVolumeRange("MASTER"); can return something like ret=(-120.0f,0.0f)
*/
virtual std::pair<float,float> getVolumeRange(const std::string& _volumeName) const;
/**
* @brief Create output Interface
* @param[in] _freq Frequency to open Interface [8,16,22,32,48] kHz
* @param[in] _map ChannelMap of the Output
* @param[in] _format Sample Format to open the stream [int8_t, int16_t, ...]
* @param[in] _streamName Stream name to open: "" or "default" open current selected output
* @param[in] _options Json option to configure default resampling and many other things.
* @return a pointer on the interface
*/
virtual std11::shared_ptr<Interface> createOutput(float _freq = 48000,
const std::vector<audio::channel>& _map = std::vector<audio::channel>(),
audio::format _format = audio::format_int16,
const std::string& _streamName = "",
const std::string& _options = "");
/**
* @brief Create input Interface
* @param[in] _freq Frequency to open Interface [8,16,22,32,48] kHz
* @param[in] _map ChannelMap of the Output
* @param[in] _format Sample Format to open the stream [int8_t, int16_t, ...]
* @param[in] _streamName Stream name to open: "" or "default" open current selected input
* @param[in] _options Json option to configure default resampling and many other things.
* @return a pointer on the interface
*/
virtual std11::shared_ptr<Interface> createInput(float _freq = 48000,
const std::vector<audio::channel>& _map = std::vector<audio::channel>(),
audio::format _format = audio::format_int16,
const std::string& _streamName = "",
const std::string& _options = "");
/**
* @brief Create input Feedback Interface
* @param[in] _freq Frequency to open Interface [8,16,22,32,48] kHz
* @param[in] _map ChannelMap of the Output
* @param[in] _format Sample Format to open the stream [int8_t, int16_t, ...]
* @param[in] _streamName Stream name to open: "" or "default" open current selected input
* @param[in] _options Json option to configure default resampling and many other things.
* @return a pointer on the interface
*/
virtual std11::shared_ptr<Interface> createFeedback(float _freq = 48000,
const std::vector<audio::channel>& _map = std::vector<audio::channel>(),
audio::format _format = audio::format_int16,
const std::string& _streamName = "",
const std::string& _options = "");
/**
* @brief Generate the dot file corresponding at all the actif nodes.
* @param[in] _filename Name of the file to write data.
*/
virtual void generateDotAll(const std::string& _filename);
};
}
}
#endif

View File

@ -4,10 +4,10 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <river/debug.h> #include <audio/river/debug.h>
int32_t river::getLogId() { int32_t audio::river::getLogId() {
static int32_t g_val = etk::log::registerInstance("river"); static int32_t g_val = etk::log::registerInstance("river");
return g_val; return g_val;
} }

View File

@ -5,15 +5,17 @@
*/ */
#ifndef __RIVER_DEBUG_H__ #ifndef __AUDIO_RIVER_DEBUG_H__
#define __RIVER_DEBUG_H__ #define __AUDIO_RIVER_DEBUG_H__
#include <etk/log.h> #include <etk/log.h>
namespace river { namespace audio {
namespace river {
int32_t getLogId(); int32_t getLogId();
}; }
#define RIVER_BASE(info,data) TK_LOG_BASE(river::getLogId(),info,data) }
#define RIVER_BASE(info,data) TK_LOG_BASE(audio::river::getLogId(),info,data)
#define RIVER_CRITICAL(data) RIVER_BASE(1, data) #define RIVER_CRITICAL(data) RIVER_BASE(1, data)
#define RIVER_ERROR(data) RIVER_BASE(2, data) #define RIVER_ERROR(data) RIVER_BASE(2, data)

View File

@ -4,8 +4,8 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#ifdef __RIVER_DEBUG_H__ #ifdef __AUDIO_RIVER_DEBUG_H__
#undef __RIVER_DEBUG_H__ #undef __AUDIO_RIVER_DEBUG_H__
#undef RIVER_BASE #undef RIVER_BASE
#undef RIVER_CRITICAL #undef RIVER_CRITICAL

View File

@ -4,18 +4,18 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <river/io/Group.h> #include <audio/river/io/Group.h>
#include <river/debug.h> #include <audio/river/debug.h>
#include "Node.h" #include "Node.h"
#include "NodeAEC.h" #include "NodeAEC.h"
#include "NodeAirTAudio.h" #include "NodeOrchestra.h"
#include "NodePortAudio.h" #include "NodePortAudio.h"
#include "Node.h" #include "Node.h"
#undef __class__ #undef __class__
#define __class__ "io::Group" #define __class__ "io::Group"
void river::io::Group::createFrom(const ejson::Document& _obj, const std::string& _name) { void audio::river::io::Group::createFrom(const ejson::Document& _obj, const std::string& _name) {
RIVER_INFO("Create Group[" << _name << "] (START) ___________________________"); RIVER_INFO("Create Group[" << _name << "] (START) ___________________________");
for (size_t iii=0; iii<_obj.size(); ++iii) { for (size_t iii=0; iii<_obj.size(); ++iii) {
const std11::shared_ptr<const ejson::Object> tmpObject = _obj.getObject(_obj.getKey(iii)); const std11::shared_ptr<const ejson::Object> tmpObject = _obj.getObject(_obj.getKey(iii));
@ -30,7 +30,7 @@ void river::io::Group::createFrom(const ejson::Document& _obj, const std::string
#ifdef __AIRTAUDIO_INFERFACE__ #ifdef __AIRTAUDIO_INFERFACE__
if ( ioType == "input" if ( ioType == "input"
|| ioType == "output") { || ioType == "output") {
std11::shared_ptr<river::io::Node> tmp = river::io::NodeAirTAudio::create(_obj.getKey(iii), tmpObject); std11::shared_ptr<audio::river::io::Node> tmp = audio::river::io::NodeOrchestra::create(_obj.getKey(iii), tmpObject);
tmp->setGroup(shared_from_this()); tmp->setGroup(shared_from_this());
m_list.push_back(tmp); m_list.push_back(tmp);
} }
@ -38,7 +38,7 @@ void river::io::Group::createFrom(const ejson::Document& _obj, const std::string
#ifdef __PORTAUDIO_INFERFACE__ #ifdef __PORTAUDIO_INFERFACE__
if ( ioType == "PAinput" if ( ioType == "PAinput"
|| ioType == "PAoutput") { || ioType == "PAoutput") {
std11::shared_ptr<river::io::Node> tmp = river::io::NodePortAudio::create(_obj.getKey(iii), tmpObject); std11::shared_ptr<audio::river::io::Node> tmp = audio::river::io::NodePortAudio::create(_obj.getKey(iii), tmpObject);
tmp->setGroup(shared_from_this()); tmp->setGroup(shared_from_this());
m_list.push_back(tmp); m_list.push_back(tmp);
} }
@ -49,10 +49,10 @@ void river::io::Group::createFrom(const ejson::Document& _obj, const std::string
// Note : The interlink work only for alsa (NOW) and with AirTAudio... // Note : The interlink work only for alsa (NOW) and with AirTAudio...
if(m_list.size() > 1) { if(m_list.size() > 1) {
#ifdef __AIRTAUDIO_INFERFACE__ #ifdef __AIRTAUDIO_INFERFACE__
std11::shared_ptr<river::io::NodeAirTAudio> linkRef = std11::dynamic_pointer_cast<river::io::NodeAirTAudio>(m_list[0]); std11::shared_ptr<audio::river::io::NodeOrchestra> linkRef = std11::dynamic_pointer_cast<audio::river::io::NodeOrchestra>(m_list[0]);
for (size_t iii=1; iii<m_list.size(); ++iii) { for (size_t iii=1; iii<m_list.size(); ++iii) {
if (m_list[iii] != nullptr) { if (m_list[iii] != nullptr) {
std11::shared_ptr<river::io::NodeAirTAudio> link = std11::dynamic_pointer_cast<river::io::NodeAirTAudio>(m_list[iii]); std11::shared_ptr<audio::river::io::NodeOrchestra> link = std11::dynamic_pointer_cast<audio::river::io::NodeOrchestra>(m_list[iii]);
linkRef->m_adac.isMasterOf(link->m_adac); linkRef->m_adac.isMasterOf(link->m_adac);
} }
} }
@ -62,7 +62,7 @@ void river::io::Group::createFrom(const ejson::Document& _obj, const std::string
// manage Link Between Nodes : // manage Link Between Nodes :
if (m_link != nullptr) { if (m_link != nullptr) {
RIVER_INFO("******** START LINK ************"); RIVER_INFO("******** START LINK ************");
std11::shared_ptr<river::io::NodeAirTAudio> link = std11::dynamic_pointer_cast<river::io::NodeAirTAudio>(m_link); std11::shared_ptr<audio::river::io::NodeOrchestra> link = std11::dynamic_pointer_cast<audio::river::io::NodeOrchestra>(m_link);
if (link == nullptr) { if (link == nullptr) {
RIVER_ERROR("Can not link 2 Interface with not the same type (reserved for HW interface)"); RIVER_ERROR("Can not link 2 Interface with not the same type (reserved for HW interface)");
return; return;
@ -82,7 +82,7 @@ void river::io::Group::createFrom(const ejson::Document& _obj, const std::string
} }
std11::shared_ptr<river::io::Node> river::io::Group::getNode(const std::string& _name) { std11::shared_ptr<audio::river::io::Node> audio::river::io::Group::getNode(const std::string& _name) {
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
if (m_list[iii] != nullptr) { if (m_list[iii] != nullptr) {
if (m_list[iii]->getName() == _name) { if (m_list[iii]->getName() == _name) {
@ -90,10 +90,10 @@ std11::shared_ptr<river::io::Node> river::io::Group::getNode(const std::string&
} }
} }
} }
return std11::shared_ptr<river::io::Node>(); return std11::shared_ptr<audio::river::io::Node>();
} }
void river::io::Group::start() { void audio::river::io::Group::start() {
RIVER_ERROR("request start "); RIVER_ERROR("request start ");
int32_t count = 0; int32_t count = 0;
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
@ -113,7 +113,7 @@ void river::io::Group::start() {
} }
} }
void river::io::Group::stop() { void audio::river::io::Group::stop() {
RIVER_ERROR("request stop "); RIVER_ERROR("request stop ");
int32_t count = 0; int32_t count = 0;
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
@ -133,7 +133,7 @@ void river::io::Group::stop() {
} }
} }
void river::io::Group::generateDot(etk::FSNode& _node, bool _hardwareNode) { void audio::river::io::Group::generateDot(etk::FSNode& _node, bool _hardwareNode) {
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
if (m_list[iii] != nullptr) { if (m_list[iii] != nullptr) {
if (m_list[iii]->isHarwareNode() == _hardwareNode) { if (m_list[iii]->isHarwareNode() == _hardwareNode) {

78
audio/river/io/Group.h Normal file
View File

@ -0,0 +1,78 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_RIVER_IO_GROUP_H__
#define __AUDIO_RIVER_IO_GROUP_H__
#include <string>
#include <vector>
#include <ejson/ejson.h>
#include <etk/os/FSNode.h>
namespace audio {
namespace river {
namespace io {
class Node;
class Manager;
/**
* @brief Group is contituate to manage some input and output in the same start and stop.
* It link N interface in a group. The start and the sopt is requested in Node inside the
* group they will start and stop when the first start is requested and stop when the last
* is stopped.
* @note For the Alsa interface a low level link is availlable with AirTAudio for Alsa (One thread)
*/
class Group : public std11::enable_shared_from_this<Group> {
public:
/**
* @brief Contructor. No special thing to do.
*/
Group() {}
/**
* @brief Destructor
*/
~Group() {
// TODO : ...
}
private:
std::vector< std11::shared_ptr<Node> > m_list; //!< List of all node in the group
public:
/**
* @brief Create a group with all node needed to syncronize together
* @param[in] _obj json document to create all the node in the group named _name
* @param[in] _name Name of the group to create
*/
void createFrom(const ejson::Document& _obj, const std::string& _name);
/**
* @brief Get a node in the group (if the node is not in the group nothing append).
* @param[in] _name Name of the node requested.
* @return nullptr The node named _name was not found.
* @return pointer The node was find in this group.
*/
std11::shared_ptr<audio::river::io::Node> getNode(const std::string& _name);
/**
* @brief Start the group.
* @note all sub-node will be started.
*/
void start();
/**
* @brief Stop the group.
* @note All sub-node will be stopped at the reserve order that they start.
*/
void stop();
/**
* @brief Create the dot in the FileNode stream.
* @param[in,out] _node File node to write data.
* @param[in] _hardwareNode true if user want only display the hardware
* node and not the software node. false The oposite.
*/
void generateDot(etk::FSNode& _node, bool _hardwareNode);
};
}
}
}
#endif

View File

@ -4,14 +4,14 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <river/io/Manager.h> #include <audio/river/io/Manager.h>
#include <river/debug.h> #include <audio/river/debug.h>
#include <river/river.h> #include <audio/river/river.h>
#include <river/io/Node.h> #include <audio/river/io/Node.h>
#include <river/io/NodeAEC.h> #include <audio/river/io/NodeAEC.h>
#include <river/io/NodeMuxer.h> #include <audio/river/io/NodeMuxer.h>
#include <river/io/NodeAirTAudio.h> #include <audio/river/io/NodeOrchestra.h>
#include <river/io/NodePortAudio.h> #include <audio/river/io/NodePortAudio.h>
#include <etk/os/FSNode.h> #include <etk/os/FSNode.h>
#include <etk/memory.h> #include <etk/memory.h>
#include <etk/types.h> #include <etk/types.h>
@ -57,7 +57,7 @@ static std::string basicAutoConfig =
river::io::Manager::Manager() { audio::river::io::Manager::Manager() {
#ifdef __PORTAUDIO_INFERFACE__ #ifdef __PORTAUDIO_INFERFACE__
PaError err = Pa_Initialize(); PaError err = Pa_Initialize();
if(err != paNoError) { if(err != paNoError) {
@ -66,7 +66,7 @@ river::io::Manager::Manager() {
#endif #endif
} }
void river::io::Manager::init(const std::string& _filename) { void audio::river::io::Manager::init(const std::string& _filename) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (_filename == "") { if (_filename == "") {
RIVER_INFO("Load default config"); RIVER_INFO("Load default config");
@ -76,17 +76,17 @@ void river::io::Manager::init(const std::string& _filename) {
} }
} }
void river::io::Manager::initString(const std::string& _data) { void audio::river::io::Manager::initString(const std::string& _data) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_config.parse(_data); m_config.parse(_data);
} }
void river::io::Manager::unInit() { void audio::river::io::Manager::unInit() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
// TODO : ... // TODO : ...
} }
river::io::Manager::~Manager() { audio::river::io::Manager::~Manager() {
#ifdef __PORTAUDIO_INFERFACE__ #ifdef __PORTAUDIO_INFERFACE__
PaError err = Pa_Terminate(); PaError err = Pa_Terminate();
if(err != paNoError) { if(err != paNoError) {
@ -95,16 +95,16 @@ river::io::Manager::~Manager() {
#endif #endif
}; };
std11::shared_ptr<river::io::Manager> river::io::Manager::getInstance() { std11::shared_ptr<audio::river::io::Manager> audio::river::io::Manager::getInstance() {
if (river::isInit() == false) { if (audio::river::isInit() == false) {
return std11::shared_ptr<river::io::Manager>(); return std11::shared_ptr<audio::river::io::Manager>();
} }
static std11::shared_ptr<river::io::Manager> manager(new Manager()); static std11::shared_ptr<audio::river::io::Manager> manager(new Manager());
return manager; return manager;
} }
std::vector<std::string> river::io::Manager::getListStreamInput() { std::vector<std::string> audio::river::io::Manager::getListStreamInput() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
std::vector<std::string> output; std::vector<std::string> output;
std::vector<std::string> keys = m_config.getKeys(); std::vector<std::string> keys = m_config.getKeys();
@ -121,7 +121,7 @@ std::vector<std::string> river::io::Manager::getListStreamInput() {
return output; return output;
} }
std::vector<std::string> river::io::Manager::getListStreamOutput() { std::vector<std::string> audio::river::io::Manager::getListStreamOutput() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
std::vector<std::string> output; std::vector<std::string> output;
std::vector<std::string> keys = m_config.getKeys(); std::vector<std::string> keys = m_config.getKeys();
@ -138,7 +138,7 @@ std::vector<std::string> river::io::Manager::getListStreamOutput() {
return output; return output;
} }
std::vector<std::string> river::io::Manager::getListStreamVirtual() { std::vector<std::string> audio::river::io::Manager::getListStreamVirtual() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
std::vector<std::string> output; std::vector<std::string> output;
std::vector<std::string> keys = m_config.getKeys(); std::vector<std::string> keys = m_config.getKeys();
@ -158,7 +158,7 @@ std::vector<std::string> river::io::Manager::getListStreamVirtual() {
return output; return output;
} }
std::vector<std::string> river::io::Manager::getListStream() { std::vector<std::string> audio::river::io::Manager::getListStream() {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
std::vector<std::string> output; std::vector<std::string> output;
std::vector<std::string> keys = m_config.getKeys(); std::vector<std::string> keys = m_config.getKeys();
@ -174,12 +174,12 @@ std::vector<std::string> river::io::Manager::getListStream() {
return output; return output;
} }
std11::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string& _name) { std11::shared_ptr<audio::river::io::Node> audio::river::io::Manager::getNode(const std::string& _name) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
RIVER_WARNING("Get node : " << _name); RIVER_WARNING("Get node : " << _name);
// search in the standalone list : // search in the standalone list :
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
std11::shared_ptr<river::io::Node> tmppp = m_list[iii].lock(); std11::shared_ptr<audio::river::io::Node> tmppp = m_list[iii].lock();
if ( tmppp != nullptr if ( tmppp != nullptr
&& _name == tmppp->getName()) { && _name == tmppp->getName()) {
RIVER_WARNING(" find it ... in standalone"); RIVER_WARNING(" find it ... in standalone");
@ -188,11 +188,11 @@ std11::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string
} }
// search in the group list: // search in the group list:
{ {
for (std::map<std::string, std11::shared_ptr<river::io::Group> >::iterator it(m_listGroup.begin()); for (std::map<std::string, std11::shared_ptr<audio::river::io::Group> >::iterator it(m_listGroup.begin());
it != m_listGroup.end(); it != m_listGroup.end();
++it) { ++it) {
if (it->second != nullptr) { if (it->second != nullptr) {
std11::shared_ptr<river::io::Node> node = it->second->getNode(_name); std11::shared_ptr<audio::river::io::Node> node = it->second->getNode(_name);
if (node != nullptr) { if (node != nullptr) {
RIVER_WARNING(" find it ... in group: " << it->first); RIVER_WARNING(" find it ... in group: " << it->first);
return node; return node;
@ -213,10 +213,10 @@ std11::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string
|| ioType == "output" || ioType == "output"
|| ioType == "PAinput" || ioType == "PAinput"
|| ioType == "PAoutput") ) { || ioType == "PAoutput") ) {
std11::shared_ptr<river::io::Group> tmpGroup = getGroup(groupName); std11::shared_ptr<audio::river::io::Group> tmpGroup = getGroup(groupName);
if (tmpGroup == nullptr) { if (tmpGroup == nullptr) {
RIVER_WARNING("Can not get group ... '" << groupName << "'"); RIVER_WARNING("Can not get group ... '" << groupName << "'");
return std11::shared_ptr<river::io::Node>(); return std11::shared_ptr<audio::river::io::Node>();
} }
return tmpGroup->getNode(_name); return tmpGroup->getNode(_name);
} else { } else {
@ -227,7 +227,7 @@ std11::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string
#ifdef __AIRTAUDIO_INFERFACE__ #ifdef __AIRTAUDIO_INFERFACE__
if ( ioType == "input" if ( ioType == "input"
|| ioType == "output") { || ioType == "output") {
std11::shared_ptr<river::io::Node> tmp = river::io::NodeAirTAudio::create(_name, tmpObject); std11::shared_ptr<audio::river::io::Node> tmp = audio::river::io::NodeOrchestra::create(_name, tmpObject);
m_list.push_back(tmp); m_list.push_back(tmp);
return tmp; return tmp;
} }
@ -235,32 +235,32 @@ std11::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string
#ifdef __PORTAUDIO_INFERFACE__ #ifdef __PORTAUDIO_INFERFACE__
if ( ioType == "PAinput" if ( ioType == "PAinput"
|| ioType == "PAoutput") { || ioType == "PAoutput") {
std11::shared_ptr<river::io::Node> tmp = river::io::NodePortAudio::create(_name, tmpObject); std11::shared_ptr<audio::river::io::Node> tmp = audio::river::io::NodePortAudio::create(_name, tmpObject);
m_list.push_back(tmp); m_list.push_back(tmp);
return tmp; return tmp;
} }
#endif #endif
if (ioType == "aec") { if (ioType == "aec") {
std11::shared_ptr<river::io::Node> tmp = river::io::NodeAEC::create(_name, tmpObject); std11::shared_ptr<audio::river::io::Node> tmp = audio::river::io::NodeAEC::create(_name, tmpObject);
m_list.push_back(tmp); m_list.push_back(tmp);
return tmp; return tmp;
} }
if (ioType == "muxer") { if (ioType == "muxer") {
std11::shared_ptr<river::io::Node> tmp = river::io::NodeMuxer::create(_name, tmpObject); std11::shared_ptr<audio::river::io::Node> tmp = audio::river::io::NodeMuxer::create(_name, tmpObject);
m_list.push_back(tmp); m_list.push_back(tmp);
return tmp; return tmp;
} }
} }
} }
RIVER_ERROR("Can not create the interface : '" << _name << "' the node is not DEFINED in the configuration file availlable : " << m_config.getKeys()); RIVER_ERROR("Can not create the interface : '" << _name << "' the node is not DEFINED in the configuration file availlable : " << m_config.getKeys());
return std11::shared_ptr<river::io::Node>(); return std11::shared_ptr<audio::river::io::Node>();
} }
std11::shared_ptr<drain::VolumeElement> river::io::Manager::getVolumeGroup(const std::string& _name) { std11::shared_ptr<audio::drain::VolumeElement> audio::river::io::Manager::getVolumeGroup(const std::string& _name) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
if (_name == "") { if (_name == "") {
RIVER_ERROR("Try to create an audio group with no name ..."); RIVER_ERROR("Try to create an audio group with no name ...");
return std11::shared_ptr<drain::VolumeElement>(); return std11::shared_ptr<audio::drain::VolumeElement>();
} }
for (size_t iii=0; iii<m_volumeGroup.size(); ++iii) { for (size_t iii=0; iii<m_volumeGroup.size(); ++iii) {
if (m_volumeGroup[iii] == nullptr) { if (m_volumeGroup[iii] == nullptr) {
@ -271,14 +271,14 @@ std11::shared_ptr<drain::VolumeElement> river::io::Manager::getVolumeGroup(const
} }
} }
RIVER_DEBUG("Add a new volume group : '" << _name << "'"); RIVER_DEBUG("Add a new volume group : '" << _name << "'");
std11::shared_ptr<drain::VolumeElement> tmpVolume = std11::make_shared<drain::VolumeElement>(_name); std11::shared_ptr<audio::drain::VolumeElement> tmpVolume = std11::make_shared<audio::drain::VolumeElement>(_name);
m_volumeGroup.push_back(tmpVolume); m_volumeGroup.push_back(tmpVolume);
return tmpVolume; return tmpVolume;
} }
bool river::io::Manager::setVolume(const std::string& _volumeName, float _valuedB) { bool audio::river::io::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
std11::shared_ptr<drain::VolumeElement> volume = getVolumeGroup(_volumeName); std11::shared_ptr<audio::drain::VolumeElement> volume = getVolumeGroup(_volumeName);
if (volume == nullptr) { if (volume == nullptr) {
RIVER_ERROR("Can not set volume ... : '" << _volumeName << "'"); RIVER_ERROR("Can not set volume ... : '" << _volumeName << "'");
return false; return false;
@ -290,7 +290,7 @@ bool river::io::Manager::setVolume(const std::string& _volumeName, float _valued
} }
volume->setVolume(_valuedB); volume->setVolume(_valuedB);
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
std11::shared_ptr<river::io::Node> val = m_list[iii].lock(); std11::shared_ptr<audio::river::io::Node> val = m_list[iii].lock();
if (val != nullptr) { if (val != nullptr) {
val->volumeChange(); val->volumeChange();
} }
@ -298,9 +298,9 @@ bool river::io::Manager::setVolume(const std::string& _volumeName, float _valued
return true; return true;
} }
float river::io::Manager::getVolume(const std::string& _volumeName) { float audio::river::io::Manager::getVolume(const std::string& _volumeName) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
std11::shared_ptr<drain::VolumeElement> volume = getVolumeGroup(_volumeName); std11::shared_ptr<audio::drain::VolumeElement> volume = getVolumeGroup(_volumeName);
if (volume == nullptr) { if (volume == nullptr) {
RIVER_ERROR("Can not get volume ... : '" << _volumeName << "'"); RIVER_ERROR("Can not get volume ... : '" << _volumeName << "'");
return 0.0f; return 0.0f;
@ -308,11 +308,11 @@ float river::io::Manager::getVolume(const std::string& _volumeName) {
return volume->getVolume(); return volume->getVolume();
} }
std::pair<float,float> river::io::Manager::getVolumeRange(const std::string& _volumeName) const { std::pair<float,float> audio::river::io::Manager::getVolumeRange(const std::string& _volumeName) const {
return std::make_pair<float,float>(-300, 300); return std::make_pair<float,float>(-300, 300);
} }
void river::io::Manager::generateDot(const std::string& _filename) { void audio::river::io::Manager::generateDot(const std::string& _filename) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
etk::FSNode node(_filename); etk::FSNode node(_filename);
RIVER_INFO("Generate the DOT files: " << node); RIVER_INFO("Generate the DOT files: " << node);
@ -326,14 +326,14 @@ void river::io::Manager::generateDot(const std::string& _filename) {
{ {
// standalone // standalone
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
std11::shared_ptr<river::io::Node> val = m_list[iii].lock(); std11::shared_ptr<audio::river::io::Node> val = m_list[iii].lock();
if (val != nullptr) { if (val != nullptr) {
if (val->isHarwareNode() == true) { if (val->isHarwareNode() == true) {
val->generateDot(node); val->generateDot(node);
} }
} }
} }
for (std::map<std::string, std11::shared_ptr<river::io::Group> >::iterator it(m_listGroup.begin()); for (std::map<std::string, std11::shared_ptr<audio::river::io::Group> >::iterator it(m_listGroup.begin());
it != m_listGroup.end(); it != m_listGroup.end();
++it) { ++it) {
if (it->second != nullptr) { if (it->second != nullptr) {
@ -345,14 +345,14 @@ void river::io::Manager::generateDot(const std::string& _filename) {
{ {
// standalone // standalone
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
std11::shared_ptr<river::io::Node> val = m_list[iii].lock(); std11::shared_ptr<audio::river::io::Node> val = m_list[iii].lock();
if (val != nullptr) { if (val != nullptr) {
if (val->isHarwareNode() == false) { if (val->isHarwareNode() == false) {
val->generateDot(node); val->generateDot(node);
} }
} }
} }
for (std::map<std::string, std11::shared_ptr<river::io::Group> >::iterator it(m_listGroup.begin()); for (std::map<std::string, std11::shared_ptr<audio::river::io::Group> >::iterator it(m_listGroup.begin());
it != m_listGroup.end(); it != m_listGroup.end();
++it) { ++it) {
if (it->second != nullptr) { if (it->second != nullptr) {
@ -366,16 +366,16 @@ void river::io::Manager::generateDot(const std::string& _filename) {
RIVER_INFO("Generate the DOT files: " << node << " (DONE)"); RIVER_INFO("Generate the DOT files: " << node << " (DONE)");
} }
std11::shared_ptr<river::io::Group> river::io::Manager::getGroup(const std::string& _name) { std11::shared_ptr<audio::river::io::Group> audio::river::io::Manager::getGroup(const std::string& _name) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex); std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
std11::shared_ptr<river::io::Group> out; std11::shared_ptr<audio::river::io::Group> out;
std::map<std::string, std11::shared_ptr<river::io::Group> >::iterator it = m_listGroup.find(_name); std::map<std::string, std11::shared_ptr<audio::river::io::Group> >::iterator it = m_listGroup.find(_name);
if (it == m_listGroup.end()) { if (it == m_listGroup.end()) {
RIVER_INFO("Create a new group: " << _name << " (START)"); RIVER_INFO("Create a new group: " << _name << " (START)");
out = std11::make_shared<river::io::Group>(); out = std11::make_shared<audio::river::io::Group>();
if (out != nullptr) { if (out != nullptr) {
out->createFrom(m_config, _name); out->createFrom(m_config, _name);
std::pair<std::string, std11::shared_ptr<river::io::Group> > plop(std::string(_name), out); std::pair<std::string, std11::shared_ptr<audio::river::io::Group> > plop(std::string(_name), out);
m_listGroup.insert(plop); m_listGroup.insert(plop);
RIVER_INFO("Create a new group: " << _name << " ( END )"); RIVER_INFO("Create a new group: " << _name << " ( END )");
} else { } else {

145
audio/river/io/Manager.h Normal file
View File

@ -0,0 +1,145 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_RIVER_IO_MANAGER_H__
#define __AUDIO_RIVER_IO_MANAGER_H__
#include <string>
#include <vector>
#include <map>
#include <list>
#include <stdint.h>
#include <etk/mutex.h>
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#include <audio/format.h>
#include <audio/channel.h>
#include <ejson/ejson.h>
#include <audio/drain/Volume.h>
#include <audio/river/io/Group.h>
namespace audio {
namespace river {
namespace io {
class Node;
/**
* @brief Internal sigleton of all Flow hadware and virtuals.
* @note this class will be initialize by the audio::river::init() function at the start of the application.
*/
class Manager : public std11::enable_shared_from_this<Manager> {
private:
mutable std11::recursive_mutex m_mutex; //!< prevent multiple access
private:
/**
* @brief Constructor
*/
Manager();
public:
static std11::shared_ptr<Manager> getInstance();
/**
* @brief Destructor
*/
~Manager();
/**
* @brief Called by audio::river::init() to set the hardware configuration file.
* @param[in] _filename Name of the file to initialize.
*/
void init(const std::string& _filename);
/**
* @brief Called by audio::river::initString() to set the hardware configuration string.
* @param[in] _data json configuration string.
*/
void initString(const std::string& _data);
/**
* @brief Called by audio::river::inInit() to uninitialize all the low level interface.
*/
void unInit();
private:
ejson::Document m_config; //!< harware configuration
std::vector<std11::shared_ptr<audio::river::io::Node> > m_listKeepAlive; //!< list of all Node that might be keep alive sone/all time
std::vector<std11::weak_ptr<audio::river::io::Node> > m_list; //!< List of all IO node
public:
/**
* @brief Get a node with his name (the name is set in the description file.
* @param[in] _name Name of the node
* @return Pointer on the noe or a nullptr if the node does not exist in the file or an error occured.
*/
std11::shared_ptr<audio::river::io::Node> getNode(const std::string& _name);
private:
std::vector<std11::shared_ptr<audio::drain::VolumeElement> > m_volumeGroup; //!< List of All global volume in the Low level interface.
public:
/**
* @brief Get a volume in the global list of vilume
* @param[in] _name Name of the volume.
* @return pointer on the requested volume (create it if does not exist). nullptr if the name is empty.
*/
std11::shared_ptr<audio::drain::VolumeElement> getVolumeGroup(const std::string& _name);
/**
* @brief Get all input audio stream.
* @return a list of all availlables input stream name
*/
std::vector<std::string> getListStreamInput();
/**
* @brief Get all output audio stream.
* @return a list of all availlables output stream name
*/
std::vector<std::string> getListStreamOutput();
/**
* @brief Get all audio virtual stream.
* @return a list of all availlables virtual stream name
*/
std::vector<std::string> getListStreamVirtual();
/**
* @brief Get all audio stream.
* @return a list of all availlables stream name
*/
std::vector<std::string> getListStream();
/**
* @brief Set a volume for a specific group
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @param[in] _value Volume in dB to set.
* @return true set done
* @return false An error occured
* @example : setVolume("MASTER", -3.0f);
*/
bool setVolume(const std::string& _volumeName, float _valuedB);
/**
* @brief Get a volume value
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @return The Volume value in dB.
* @example ret = getVolume("MASTER"); can return something like ret = -3.0f
*/
float getVolume(const std::string& _volumeName);
/**
* @brief Get a parameter value
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @return The requested value Range.
* @example ret = getVolumeRange("MASTER"); can return something like ret=(-120.0f,0.0f)
*/
std::pair<float,float> getVolumeRange(const std::string& _volumeName) const;
/**
* @brief Generate the dot file corresponding at the actif nodes.
* @param[in] _filename Name of the file to write data.
*/
void generateDot(const std::string& _filename);
private:
std::map<std::string, std11::shared_ptr<audio::river::io::Group> > m_listGroup; //!< List of all groups
/**
* @brief get a low level interface group.
* @param[in] _name Name of the group.
* @return Pointer on the requested group or nullptr if the group does not existed.
*/
std11::shared_ptr<audio::river::io::Group> getGroup(const std::string& _name);
};
}
}
}
#endif

View File

@ -5,13 +5,13 @@
*/ */
#include "Node.h" #include "Node.h"
#include <river/debug.h> #include <audio/river/debug.h>
#undef __class__ #undef __class__
#define __class__ "io::Node" #define __class__ "io::Node"
river::io::Node::Node(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) : audio::river::io::Node::Node(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) :
m_config(_config), m_config(_config),
m_name(_name), m_name(_name),
m_isInput(false) { m_isInput(false) {
@ -20,8 +20,8 @@ river::io::Node::Node(const std::string& _name, const std11::shared_ptr<const ej
RIVER_INFO("-----------------------------------------------------------------"); RIVER_INFO("-----------------------------------------------------------------");
RIVER_INFO("-- CREATE NODE --"); RIVER_INFO("-- CREATE NODE --");
RIVER_INFO("-----------------------------------------------------------------"); RIVER_INFO("-----------------------------------------------------------------");
drain::IOFormatInterface interfaceFormat; audio::drain::IOFormatInterface interfaceFormat;
drain::IOFormatInterface hardwareFormat; audio::drain::IOFormatInterface hardwareFormat;
/** /**
io:"input", # input, output or aec io:"input", # input, output or aec
frequency:48000, # frequency to open device frequency:48000, # frequency to open device
@ -54,7 +54,7 @@ river::io::Node::Node(const std::string& _name, const std11::shared_ptr<const ej
if (volumeName != "") { if (volumeName != "") {
RIVER_INFO("add node volume stage : '" << volumeName << "'"); RIVER_INFO("add node volume stage : '" << volumeName << "'");
// use global manager for volume ... // use global manager for volume ...
m_volume = river::io::Manager::getInstance()->getVolumeGroup(volumeName); m_volume = audio::river::io::Manager::getInstance()->getVolumeGroup(volumeName);
} }
// Get map type : // Get map type :
std::vector<audio::channel> map; std::vector<audio::channel> map;
@ -102,13 +102,13 @@ river::io::Node::Node(const std::string& _name, const std11::shared_ptr<const ej
//m_process.updateInterAlgo(); //m_process.updateInterAlgo();
} }
river::io::Node::~Node() { audio::river::io::Node::~Node() {
RIVER_INFO("-----------------------------------------------------------------"); RIVER_INFO("-----------------------------------------------------------------");
RIVER_INFO("-- DESTROY NODE --"); RIVER_INFO("-- DESTROY NODE --");
RIVER_INFO("-----------------------------------------------------------------"); RIVER_INFO("-----------------------------------------------------------------");
}; };
size_t river::io::Node::getNumberOfInterface(enum river::modeInterface _interfaceType) { size_t audio::river::io::Node::getNumberOfInterface(enum audio::river::modeInterface _interfaceType) {
size_t out = 0; size_t out = 0;
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
if (m_list[iii] == nullptr) { if (m_list[iii] == nullptr) {
@ -120,10 +120,10 @@ size_t river::io::Node::getNumberOfInterface(enum river::modeInterface _interfac
} }
return out; return out;
} }
size_t river::io::Node::getNumberOfInterfaceAvaillable(enum river::modeInterface _interfaceType) { size_t audio::river::io::Node::getNumberOfInterfaceAvaillable(enum audio::river::modeInterface _interfaceType) {
size_t out = 0; size_t out = 0;
for (size_t iii=0; iii<m_listAvaillable.size(); ++iii) { for (size_t iii=0; iii<m_listAvaillable.size(); ++iii) {
std11::shared_ptr<river::Interface> element = m_listAvaillable[iii].lock(); std11::shared_ptr<audio::river::Interface> element = m_listAvaillable[iii].lock();
if (element == nullptr) { if (element == nullptr) {
continue; continue;
} }
@ -134,8 +134,8 @@ size_t river::io::Node::getNumberOfInterfaceAvaillable(enum river::modeInterface
return out; return out;
} }
void river::io::Node::registerAsRemote(const std11::shared_ptr<river::Interface>& _interface) { void audio::river::io::Node::registerAsRemote(const std11::shared_ptr<audio::river::Interface>& _interface) {
std::vector<std11::weak_ptr<river::Interface> >::iterator it = m_listAvaillable.begin(); std::vector<std11::weak_ptr<audio::river::Interface> >::iterator it = m_listAvaillable.begin();
while (it != m_listAvaillable.end()) { while (it != m_listAvaillable.end()) {
if (it->expired() == true) { if (it->expired() == true) {
it = m_listAvaillable.erase(it); it = m_listAvaillable.erase(it);
@ -146,7 +146,7 @@ void river::io::Node::registerAsRemote(const std11::shared_ptr<river::Interface>
m_listAvaillable.push_back(_interface); m_listAvaillable.push_back(_interface);
} }
void river::io::Node::interfaceAdd(const std11::shared_ptr<river::Interface>& _interface) { void audio::river::io::Node::interfaceAdd(const std11::shared_ptr<audio::river::Interface>& _interface) {
{ {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
@ -162,7 +162,7 @@ void river::io::Node::interfaceAdd(const std11::shared_ptr<river::Interface>& _i
} }
} }
void river::io::Node::interfaceRemove(const std11::shared_ptr<river::Interface>& _interface) { void audio::river::io::Node::interfaceRemove(const std11::shared_ptr<audio::river::Interface>& _interface) {
{ {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
for (size_t iii=0; iii< m_list.size(); ++iii) { for (size_t iii=0; iii< m_list.size(); ++iii) {
@ -180,16 +180,16 @@ void river::io::Node::interfaceRemove(const std11::shared_ptr<river::Interface>&
} }
void river::io::Node::volumeChange() { void audio::river::io::Node::volumeChange() {
for (size_t iii=0; iii< m_listAvaillable.size(); ++iii) { for (size_t iii=0; iii< m_listAvaillable.size(); ++iii) {
std11::shared_ptr<river::Interface> node = m_listAvaillable[iii].lock(); std11::shared_ptr<audio::river::Interface> node = m_listAvaillable[iii].lock();
if (node != nullptr) { if (node != nullptr) {
node->systemVolumeChange(); node->systemVolumeChange();
} }
} }
} }
void river::io::Node::newInput(const void* _inputBuffer, void audio::river::io::Node::newInput(const void* _inputBuffer,
uint32_t _nbChunk, uint32_t _nbChunk,
const std11::chrono::system_clock::time_point& _time) { const std11::chrono::system_clock::time_point& _time) {
if (_inputBuffer == nullptr) { if (_inputBuffer == nullptr) {
@ -200,7 +200,7 @@ void river::io::Node::newInput(const void* _inputBuffer,
if (m_list[iii] == nullptr) { if (m_list[iii] == nullptr) {
continue; continue;
} }
if (m_list[iii]->getMode() != river::modeInterface_input) { if (m_list[iii]->getMode() != audio::river::modeInterface_input) {
continue; continue;
} }
RIVER_VERBOSE(" IO name="<< m_list[iii]->getName()); RIVER_VERBOSE(" IO name="<< m_list[iii]->getName());
@ -210,7 +210,7 @@ void river::io::Node::newInput(const void* _inputBuffer,
return; return;
} }
void river::io::Node::newOutput(void* _outputBuffer, void audio::river::io::Node::newOutput(void* _outputBuffer,
uint32_t _nbChunk, uint32_t _nbChunk,
const std11::chrono::system_clock::time_point& _time) { const std11::chrono::system_clock::time_point& _time) {
if (_outputBuffer == nullptr) { if (_outputBuffer == nullptr) {
@ -229,7 +229,7 @@ void river::io::Node::newOutput(void* _outputBuffer,
if (m_list[iii] == nullptr) { if (m_list[iii] == nullptr) {
continue; continue;
} }
if (m_list[iii]->getMode() != river::modeInterface_output) { if (m_list[iii]->getMode() != audio::river::modeInterface_output) {
continue; continue;
} }
RIVER_VERBOSE(" IO name="<< m_list[iii]->getName() << " " << iii); RIVER_VERBOSE(" IO name="<< m_list[iii]->getName() << " " << iii);
@ -252,7 +252,7 @@ void river::io::Node::newOutput(void* _outputBuffer,
if (m_list[iii] == nullptr) { if (m_list[iii] == nullptr) {
continue; continue;
} }
if (m_list[iii]->getMode() != river::modeInterface_feedback) { if (m_list[iii]->getMode() != audio::river::modeInterface_feedback) {
continue; continue;
} }
RIVER_VERBOSE(" IO name="<< m_list[iii]->getName() << " (feedback) time=" << _time); RIVER_VERBOSE(" IO name="<< m_list[iii]->getName() << " (feedback) time=" << _time);
@ -272,7 +272,7 @@ static void link(etk::FSNode& _node, const std::string& _first, const std::strin
} }
void river::io::Node::generateDot(etk::FSNode& _node) { void audio::river::io::Node::generateDot(etk::FSNode& _node) {
_node << " subgraph clusterNode_" << m_uid << " {\n"; _node << " subgraph clusterNode_" << m_uid << " {\n";
_node << " color=blue;\n"; _node << " color=blue;\n";
_node << " label=\"[" << m_uid << "] IO::Node : " << m_name << "\";\n"; _node << " label=\"[" << m_uid << "] IO::Node : " << m_name << "\";\n";
@ -288,8 +288,8 @@ void river::io::Node::generateDot(etk::FSNode& _node) {
_node << " NODE_" << m_uid << "_HW_interface -> " << nameIn << " [arrowhead=\"open\"];\n"; _node << " NODE_" << m_uid << "_HW_interface -> " << nameIn << " [arrowhead=\"open\"];\n";
_node << " " << nameOut << " -> NODE_" << m_uid << "_demuxer [arrowhead=\"open\"];\n"; _node << " " << nameOut << " -> NODE_" << m_uid << "_demuxer [arrowhead=\"open\"];\n";
} else { } else {
size_t nbOutput = getNumberOfInterfaceAvaillable(river::modeInterface_output); size_t nbOutput = getNumberOfInterfaceAvaillable(audio::river::modeInterface_output);
size_t nbfeedback = getNumberOfInterfaceAvaillable(river::modeInterface_feedback); size_t nbfeedback = getNumberOfInterfaceAvaillable(audio::river::modeInterface_feedback);
_node << " node [shape=larrow];\n"; _node << " node [shape=larrow];\n";
_node << " NODE_" << m_uid << "_HW_interface [ label=\"HW interface\\n interface=ALSA\\n stream=" << m_name << "\\n type=output\" ];\n"; _node << " NODE_" << m_uid << "_HW_interface [ label=\"HW interface\\n interface=ALSA\\n stream=" << m_name << "\\n type=output\" ];\n";
std::string nameIn; std::string nameIn;
@ -324,7 +324,7 @@ void river::io::Node::generateDot(etk::FSNode& _node) {
if (m_listAvaillable[iii].expired() == true) { if (m_listAvaillable[iii].expired() == true) {
continue; continue;
} }
std11::shared_ptr<river::Interface> element = m_listAvaillable[iii].lock(); std11::shared_ptr<audio::river::Interface> element = m_listAvaillable[iii].lock();
if (element == nullptr) { if (element == nullptr) {
continue; continue;
} }
@ -349,8 +349,8 @@ void river::io::Node::generateDot(etk::FSNode& _node) {
} }
void river::io::Node::startInGroup() { void audio::river::io::Node::startInGroup() {
std11::shared_ptr<river::io::Group> group = m_group.lock(); std11::shared_ptr<audio::river::io::Group> group = m_group.lock();
if (group != nullptr) { if (group != nullptr) {
group->start(); group->start();
} else { } else {
@ -358,8 +358,8 @@ void river::io::Node::startInGroup() {
} }
} }
void river::io::Node::stopInGroup() { void audio::river::io::Node::stopInGroup() {
std11::shared_ptr<river::io::Group> group = m_group.lock(); std11::shared_ptr<audio::river::io::Group> group = m_group.lock();
if (group != nullptr) { if (group != nullptr) {
group->stop(); group->stop();
} else { } else {

226
audio/river/io/Node.h Normal file
View File

@ -0,0 +1,226 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_RIVER_IO_NODE_H__
#define __AUDIO_RIVER_IO_NODE_H__
#include <string>
#include <vector>
#include <list>
#include <stdint.h>
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#include <audio/format.h>
#include <audio/channel.h>
#include "Manager.h"
#include <audio/river/Interface.h>
#include <audio/drain/IOFormatInterface.h>
#include <audio/drain/Volume.h>
#include <etk/os/FSNode.h>
namespace audio {
namespace river {
namespace io {
class Manager;
class Group;
/**
* @brief A node is the base for input/output interface. When a output id declared, we automaticly have a feedback associated.
* this manage the muxing of data for output an the demuxing for input.
*/
class Node : public std11::enable_shared_from_this<Node> {
friend class audio::river::io::Group;
protected:
uint32_t m_uid; //!< uniqueNodeID use for debug an dot generation.
protected:
/**
* @brief Constructor
* @param[in] _name Name of the node.
* @param[in] _config Configuration of the node.
*/
Node(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
/**
* @brief Destructor
*/
virtual ~Node();
/**
* @brief Get the status of this node acces on harware or acces on other node (virtual).
* @return true This is an harware interface.
* @return false this is a virtual interface.
*/
virtual bool isHarwareNode() {
return false;
};
protected:
mutable std11::mutex m_mutex; //!< prevent open/close/write/read access that is multi-threaded.
std11::shared_ptr<const ejson::Object> m_config; //!< configuration description.
protected:
audio::drain::Process m_process; //!< Low level algorithms
public:
/**
* @brief Get the uper client interface configuration.
* @return process configuration.
*/
const audio::drain::IOFormatInterface& getInterfaceFormat() {
if (m_isInput == true) {
return m_process.getOutputConfig();
} else {
return m_process.getInputConfig();
}
}
/**
* @brief Get the harware client interface configuration.
* @return process configuration.
*/
const audio::drain::IOFormatInterface& getHarwareFormat() {
if (m_isInput == true) {
return m_process.getInputConfig();
} else {
return m_process.getOutputConfig();
}
}
protected:
std11::shared_ptr<audio::drain::VolumeElement> m_volume; //!< if a volume is set it is set here ... for hardware interface only.
protected:
std::vector<std11::weak_ptr<audio::river::Interface> > m_listAvaillable; //!< List of all interface that exist on this Node
std::vector<std11::shared_ptr<audio::river::Interface> > m_list; //!< List of all connected interface at this node.
/**
* @brief Get the number of interface with a specific type.
* @param[in] _interfaceType Type of the interface.
* @return Number of interface connected.
*/
size_t getNumberOfInterface(enum audio::river::modeInterface _interfaceType);
/**
* @brief Get the number of interface with a specific type that can connect on the Node.
* @param[in] _interfaceType Type of the interface.
* @return Number of interface that can connect.
*/
size_t getNumberOfInterfaceAvaillable(enum audio::river::modeInterface _interfaceType);
public:
/**
* @brief Get the number of interface connected
* @return Number of interfaces.
*/
size_t getNumberOfInterface() {
return m_list.size();
}
public:
/**
* @brief Register an interface that can connect on it. (might be done in the Interface Init)
* @note We keep a std::weak_ptr. this is the reason why we do not have a remove.
* @param[in] _interface Pointer on the interface to register.
*/
void registerAsRemote(const std11::shared_ptr<audio::river::Interface>& _interface);
/**
* @brief Request this interface might receve/send dat on the flow. (start/resume)
* @param[in] _interface Pointer on the interface to register.
*/
void interfaceAdd(const std11::shared_ptr<audio::river::Interface>& _interface);
/**
* @brief Un-register the interface as an availlable read/write interface. (suspend/stop)
* @param[in] _interface Pointer on the interface to register.
*/
void interfaceRemove(const std11::shared_ptr<audio::river::Interface>& _interface);
protected:
std::string m_name; //!< Name of the interface
public:
/**
* @brief Get the interface name.
* @return Current name.
*/
const std::string& getName() {
return m_name;
}
protected:
bool m_isInput; //!< sense of the stream
public:
/**
* @brief Check if it is an input stream
* @return true if it is an input/ false otherwise
*/
bool isInput() {
return m_isInput;
}
/**
* @brief Check if it is an output stream
* @return true if it is an output/ false otherwise
*/
bool isOutput() {
return !m_isInput;
}
protected:
std11::weak_ptr<audio::river::io::Group> m_group; //!< reference on the group. If available.
public:
/**
* @brief Set this node in a low level group.
* @param[in] _group Group reference.
*/
void setGroup(std11::shared_ptr<audio::river::io::Group> _group) {
m_group = _group;
}
protected:
/**
* @brief Start the flow in the group (start if no group)
*/
void startInGroup();
/**
* @brief Stop the flow in the group (stop if no group)
*/
void stopInGroup();
/**
* @brief Real start of the stream
*/
virtual void start() = 0;
/**
* @brief Real stop of the stream
*/
virtual void stop() = 0;
public:
/**
* @brief If this iss an hardware interface we can have a resuest of the volume stage:
* @return pointer on the requested volume.
*/
const std11::shared_ptr<audio::drain::VolumeElement>& getVolume() {
return m_volume;
}
public:
/**
* @brief Called when a group wolume has been change to update all volume stage.
*/
void volumeChange();
protected:
/**
* @brief Call by child classes to process data in all interface linked on the current Node. Have new input to process.
* @param[in] _inputBuffer Pointer on the data.
* @param[in] _nbChunk Number of chunk in the buffer.
* @param[in] _time Time where the first sample has been capture.
*/
void newInput(const void* _inputBuffer,
uint32_t _nbChunk,
const std11::chrono::system_clock::time_point& _time);
/**
* @brief Call by child classes to process data in all interface linked on the current Node. Have new output to get. this call the feedback too.
* @param[in,out] _outputBuffer Pointer on the buffer to write the data.
* @param[in] _nbChunk Number of chunk to write in the buffer.
* @param[in] _time Time where the data might be played.
*/
void newOutput(void* _outputBuffer,
uint32_t _nbChunk,
const std11::chrono::system_clock::time_point& _time);
public:
/**
* @brief Generate the node dot file section
* @param[in] _node File node to generate the data.
*/
virtual void generateDot(etk::FSNode& _node);
};
}
}
}
#endif

View File

@ -4,8 +4,8 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <river/io/NodeAEC.h> #include <audio/river/io/NodeAEC.h>
#include <river/debug.h> #include <audio/river/debug.h>
#include <etk/types.h> #include <etk/types.h>
#include <etk/memory.h> #include <etk/memory.h>
#include <etk/functional.h> #include <etk/functional.h>
@ -13,11 +13,11 @@
#undef __class__ #undef __class__
#define __class__ "io::NodeAEC" #define __class__ "io::NodeAEC"
std11::shared_ptr<river::io::NodeAEC> river::io::NodeAEC::create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) { std11::shared_ptr<audio::river::io::NodeAEC> audio::river::io::NodeAEC::create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) {
return std11::shared_ptr<river::io::NodeAEC>(new river::io::NodeAEC(_name, _config)); return std11::shared_ptr<audio::river::io::NodeAEC>(new audio::river::io::NodeAEC(_name, _config));
} }
std11::shared_ptr<river::Interface> river::io::NodeAEC::createInput(float _freq, std11::shared_ptr<audio::river::Interface> audio::river::io::NodeAEC::createInput(float _freq,
const std::vector<audio::channel>& _map, const std::vector<audio::channel>& _map,
audio::format _format, audio::format _format,
const std::string& _objectName, const std::string& _objectName,
@ -26,7 +26,7 @@ std11::shared_ptr<river::Interface> river::io::NodeAEC::createInput(float _freq,
const std11::shared_ptr<const ejson::Object> tmppp = m_config->getObject(_objectName); const std11::shared_ptr<const ejson::Object> tmppp = m_config->getObject(_objectName);
if (tmppp == nullptr) { if (tmppp == nullptr) {
RIVER_ERROR("can not open a non existance virtual interface: '" << _objectName << "' not present in : " << m_config->getKeys()); RIVER_ERROR("can not open a non existance virtual interface: '" << _objectName << "' not present in : " << m_config->getKeys());
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
std::string streamName = tmppp->getStringValue("map-on", "error"); std::string streamName = tmppp->getStringValue("map-on", "error");
@ -36,15 +36,15 @@ std11::shared_ptr<river::Interface> river::io::NodeAEC::createInput(float _freq,
if ( type != "input" if ( type != "input"
&& type != "feedback") { && type != "feedback") {
RIVER_ERROR("can not open in output a virtual interface: '" << streamName << "' configured has : " << type); RIVER_ERROR("can not open in output a virtual interface: '" << streamName << "' configured has : " << type);
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
// get global hardware interface: // get global hardware interface:
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
// get the output or input channel : // get the output or input channel :
std11::shared_ptr<river::io::Node> node = manager->getNode(streamName); std11::shared_ptr<audio::river::io::Node> node = manager->getNode(streamName);
// create user iterface: // create user iterface:
std11::shared_ptr<river::Interface> interface; std11::shared_ptr<audio::river::Interface> interface;
interface = river::Interface::create(_freq, _map, _format, node, tmppp); interface = audio::river::Interface::create(_freq, _map, _format, node, tmppp);
if (interface != nullptr) { if (interface != nullptr) {
interface->setName(_name); interface->setName(_name);
} }
@ -52,15 +52,15 @@ std11::shared_ptr<river::Interface> river::io::NodeAEC::createInput(float _freq,
} }
river::io::NodeAEC::NodeAEC(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) : audio::river::io::NodeAEC::NodeAEC(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) :
Node(_name, _config), Node(_name, _config),
m_P_attaqueTime(1), m_P_attaqueTime(1),
m_P_releaseTime(100), m_P_releaseTime(100),
m_P_minimumGain(10), m_P_minimumGain(10),
m_P_threshold(2), m_P_threshold(2),
m_P_latencyTime(100) { m_P_latencyTime(100) {
drain::IOFormatInterface interfaceFormat = getInterfaceFormat(); audio::drain::IOFormatInterface interfaceFormat = getInterfaceFormat();
drain::IOFormatInterface hardwareFormat = getHarwareFormat(); audio::drain::IOFormatInterface hardwareFormat = getHarwareFormat();
m_sampleTime = std11::chrono::nanoseconds(1000000000/int64_t(hardwareFormat.getFrequency())); m_sampleTime = std11::chrono::nanoseconds(1000000000/int64_t(hardwareFormat.getFrequency()));
/** /**
# connect in input mode # connect in input mode
@ -106,7 +106,7 @@ river::io::NodeAEC::NodeAEC(const std::string& _name, const std11::shared_ptr<co
} }
// set callback mode ... // set callback mode ...
m_interfaceFeedBack->setInputCallback(std11::bind(&river::io::NodeAEC::onDataReceivedFeedBack, m_interfaceFeedBack->setInputCallback(std11::bind(&audio::river::io::NodeAEC::onDataReceivedFeedBack,
this, this,
std11::placeholders::_1, std11::placeholders::_1,
std11::placeholders::_2, std11::placeholders::_2,
@ -115,7 +115,7 @@ river::io::NodeAEC::NodeAEC(const std::string& _name, const std11::shared_ptr<co
std11::placeholders::_5, std11::placeholders::_5,
std11::placeholders::_6)); std11::placeholders::_6));
// set callback mode ... // set callback mode ...
m_interfaceMicrophone->setInputCallback(std11::bind(&river::io::NodeAEC::onDataReceivedMicrophone, m_interfaceMicrophone->setInputCallback(std11::bind(&audio::river::io::NodeAEC::onDataReceivedMicrophone,
this, this,
std11::placeholders::_1, std11::placeholders::_1,
std11::placeholders::_2, std11::placeholders::_2,
@ -134,14 +134,14 @@ river::io::NodeAEC::NodeAEC(const std::string& _name, const std11::shared_ptr<co
m_process.updateInterAlgo(); m_process.updateInterAlgo();
} }
river::io::NodeAEC::~NodeAEC() { audio::river::io::NodeAEC::~NodeAEC() {
RIVER_INFO("close input stream"); RIVER_INFO("close input stream");
stop(); stop();
m_interfaceFeedBack.reset(); m_interfaceFeedBack.reset();
m_interfaceMicrophone.reset(); m_interfaceMicrophone.reset();
}; };
void river::io::NodeAEC::start() { void audio::river::io::NodeAEC::start() {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") ); RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
if (m_interfaceFeedBack != nullptr) { if (m_interfaceFeedBack != nullptr) {
@ -154,7 +154,7 @@ void river::io::NodeAEC::start() {
} }
} }
void river::io::NodeAEC::stop() { void audio::river::io::NodeAEC::stop() {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
if (m_interfaceFeedBack != nullptr) { if (m_interfaceFeedBack != nullptr) {
m_interfaceFeedBack->stop(); m_interfaceFeedBack->stop();
@ -165,7 +165,7 @@ void river::io::NodeAEC::stop() {
} }
void river::io::NodeAEC::onDataReceivedMicrophone(const void* _data, void audio::river::io::NodeAEC::onDataReceivedMicrophone(const void* _data,
const std11::chrono::system_clock::time_point& _time, const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk, size_t _nbChunk,
enum audio::format _format, enum audio::format _format,
@ -183,7 +183,7 @@ void river::io::NodeAEC::onDataReceivedMicrophone(const void* _data,
process(); process();
} }
void river::io::NodeAEC::onDataReceivedFeedBack(const void* _data, void audio::river::io::NodeAEC::onDataReceivedFeedBack(const void* _data,
const std11::chrono::system_clock::time_point& _time, const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk, size_t _nbChunk,
enum audio::format _format, enum audio::format _format,
@ -201,7 +201,7 @@ void river::io::NodeAEC::onDataReceivedFeedBack(const void* _data,
process(); process();
} }
void river::io::NodeAEC::process() { void audio::river::io::NodeAEC::process() {
if ( m_bufferMicrophone.getSize() <= m_nbChunk if ( m_bufferMicrophone.getSize() <= m_nbChunk
|| m_bufferFeedBack.getSize() <= m_nbChunk) { || m_bufferFeedBack.getSize() <= m_nbChunk) {
return; return;
@ -266,8 +266,8 @@ void river::io::NodeAEC::process() {
} }
void river::io::NodeAEC::processAEC(void* _dataMic, void* _dataFB, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time) { void audio::river::io::NodeAEC::processAEC(void* _dataMic, void* _dataFB, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time) {
drain::IOFormatInterface hardwareFormat = getHarwareFormat(); audio::drain::IOFormatInterface hardwareFormat = getHarwareFormat();
// TODO : Set all these parameter in the parameter configuration section ... // TODO : Set all these parameter in the parameter configuration section ...
int32_t attaqueTime = std::min(std::max(0,m_P_attaqueTime),1000); int32_t attaqueTime = std::min(std::max(0,m_P_attaqueTime),1000);
int32_t releaseTime = std::min(std::max(0,m_P_releaseTime),1000); int32_t releaseTime = std::min(std::max(0,m_P_releaseTime),1000);
@ -320,7 +320,7 @@ void river::io::NodeAEC::processAEC(void* _dataMic, void* _dataFB, uint32_t _nbC
} }
void river::io::NodeAEC::generateDot(etk::FSNode& _node) { void audio::river::io::NodeAEC::generateDot(etk::FSNode& _node) {
_node << " subgraph clusterNode_" << m_uid << " {\n"; _node << " subgraph clusterNode_" << m_uid << " {\n";
_node << " color=blue;\n"; _node << " color=blue;\n";
_node << " label=\"[" << m_uid << "] IO::Node : " << m_name << "\";\n"; _node << " label=\"[" << m_uid << "] IO::Node : " << m_name << "\";\n";
@ -346,7 +346,7 @@ void river::io::NodeAEC::generateDot(etk::FSNode& _node) {
if (m_listAvaillable[iii].expired() == true) { if (m_listAvaillable[iii].expired() == true) {
continue; continue;
} }
std11::shared_ptr<river::Interface> element = m_listAvaillable[iii].lock(); std11::shared_ptr<audio::river::Interface> element = m_listAvaillable[iii].lock();
if (element == nullptr) { if (element == nullptr) {
continue; continue;
} }

110
audio/river/io/NodeAEC.h Normal file
View File

@ -0,0 +1,110 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_RIVER_IO_NODE_AEC_H__
#define __AUDIO_RIVER_IO_NODE_AEC_H__
#include <audio/river/io/Node.h>
#include <audio/river/Interface.h>
#include <audio/drain/CircularBuffer.h>
namespace audio {
namespace river {
namespace io {
class Manager;
class NodeAEC : public Node {
protected:
/**
* @brief Constructor
*/
NodeAEC(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
/**
* @brief Factory of this Virtual Node.
* @param[in] _name Name of the node.
* @param[in] _config Configuration of the node.
*/
static std11::shared_ptr<NodeAEC> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
virtual ~NodeAEC();
protected:
virtual void start();
virtual void stop();
std11::shared_ptr<audio::river::Interface> m_interfaceMicrophone; //!< Interface on the Microphone.
std11::shared_ptr<audio::river::Interface> m_interfaceFeedBack; //!< Interface on the feedback of speaker.
/**
* @brief Internal: create an input with the specific parameter:
* @param[in] _freq Frequency.
* @param[in] _map Channel map organization.
* @param[in] _format Sample format
* @param[in] _streamName
* @param[in] _name
* @return Interfae Pointer.
*/
std11::shared_ptr<audio::river::Interface> createInput(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName,
const std::string& _name);
/**
* @brief Stream data input callback
* @todo : copy doc ..
*/
void onDataReceivedMicrophone(const void* _data,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map);
/**
* @brief Stream data input callback
* @todo : copy doc ..
*/
void onDataReceivedFeedBack(const void* _data,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map);
protected:
audio::drain::CircularBuffer m_bufferMicrophone; //!< temporary buffer to synchronize data.
audio::drain::CircularBuffer m_bufferFeedBack; //!< temporary buffer to synchronize data.
std11::chrono::nanoseconds m_sampleTime; //!< represent the sample time at the specify frequency.
/**
* @brief Process synchronization on the 2 flow.
*/
void process();
/**
* @brief Process algorithm on the current 2 syncronize flow.
* @param[in] _dataMic Pointer in the Microphione interface.
* @param[in] _dataFB Pointer on the beedback buffer.
* @param[in] _nbChunk Number of chunk to process.
* @param[in] _time Time on the firsta sample that data has been captured.
* @return
*/
void processAEC(void* _dataMic, void* _dataFB, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time);
public:
virtual void generateDot(etk::FSNode& _node);
private:
int32_t m_nbChunk;
int32_t m_gainValue;
int32_t m_sampleCount;
int32_t m_P_attaqueTime; //ms
int32_t m_P_releaseTime; //ms
int32_t m_P_minimumGain; // %
int32_t m_P_threshold; // %
int32_t m_P_latencyTime; // ms
};
}
}
}
#endif

View File

@ -4,8 +4,8 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <river/io/NodeMuxer.h> #include <audio/river/io/NodeMuxer.h>
#include <river/debug.h> #include <audio/river/debug.h>
#include <etk/types.h> #include <etk/types.h>
#include <etk/memory.h> #include <etk/memory.h>
#include <etk/functional.h> #include <etk/functional.h>
@ -13,11 +13,11 @@
#undef __class__ #undef __class__
#define __class__ "io::NodeMuxer" #define __class__ "io::NodeMuxer"
std11::shared_ptr<river::io::NodeMuxer> river::io::NodeMuxer::create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) { std11::shared_ptr<audio::river::io::NodeMuxer> audio::river::io::NodeMuxer::create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) {
return std11::shared_ptr<river::io::NodeMuxer>(new river::io::NodeMuxer(_name, _config)); return std11::shared_ptr<audio::river::io::NodeMuxer>(new audio::river::io::NodeMuxer(_name, _config));
} }
std11::shared_ptr<river::Interface> river::io::NodeMuxer::createInput(float _freq, std11::shared_ptr<audio::river::Interface> audio::river::io::NodeMuxer::createInput(float _freq,
const std::vector<audio::channel>& _map, const std::vector<audio::channel>& _map,
audio::format _format, audio::format _format,
const std::string& _objectName, const std::string& _objectName,
@ -26,7 +26,7 @@ std11::shared_ptr<river::Interface> river::io::NodeMuxer::createInput(float _fre
const std11::shared_ptr<const ejson::Object> tmppp = m_config->getObject(_objectName); const std11::shared_ptr<const ejson::Object> tmppp = m_config->getObject(_objectName);
if (tmppp == nullptr) { if (tmppp == nullptr) {
RIVER_ERROR("can not open a non existance virtual interface: '" << _objectName << "' not present in : " << m_config->getKeys()); RIVER_ERROR("can not open a non existance virtual interface: '" << _objectName << "' not present in : " << m_config->getKeys());
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
std::string streamName = tmppp->getStringValue("map-on", "error"); std::string streamName = tmppp->getStringValue("map-on", "error");
@ -36,15 +36,15 @@ std11::shared_ptr<river::Interface> river::io::NodeMuxer::createInput(float _fre
if ( type != "input" if ( type != "input"
&& type != "feedback") { && type != "feedback") {
RIVER_ERROR("can not open in output a virtual interface: '" << streamName << "' configured has : " << type); RIVER_ERROR("can not open in output a virtual interface: '" << streamName << "' configured has : " << type);
return std11::shared_ptr<river::Interface>(); return std11::shared_ptr<audio::river::Interface>();
} }
// get global hardware interface: // get global hardware interface:
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> manager = audio::river::io::Manager::getInstance();
// get the output or input channel : // get the output or input channel :
std11::shared_ptr<river::io::Node> node = manager->getNode(streamName); std11::shared_ptr<audio::river::io::Node> node = manager->getNode(streamName);
// create user iterface: // create user iterface:
std11::shared_ptr<river::Interface> interface; std11::shared_ptr<audio::river::Interface> interface;
interface = river::Interface::create(_freq, _map, _format, node, tmppp); interface = audio::river::Interface::create(_freq, _map, _format, node, tmppp);
if (interface != nullptr) { if (interface != nullptr) {
interface->setName(_name); interface->setName(_name);
} }
@ -52,10 +52,10 @@ std11::shared_ptr<river::Interface> river::io::NodeMuxer::createInput(float _fre
} }
river::io::NodeMuxer::NodeMuxer(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) : audio::river::io::NodeMuxer::NodeMuxer(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) :
Node(_name, _config) { Node(_name, _config) {
drain::IOFormatInterface interfaceFormat = getInterfaceFormat(); audio::drain::IOFormatInterface interfaceFormat = getInterfaceFormat();
drain::IOFormatInterface hardwareFormat = getHarwareFormat(); audio::drain::IOFormatInterface hardwareFormat = getHarwareFormat();
m_sampleTime = std11::chrono::nanoseconds(1000000000/int64_t(hardwareFormat.getFrequency())); m_sampleTime = std11::chrono::nanoseconds(1000000000/int64_t(hardwareFormat.getFrequency()));
/** /**
# connect in input mode # connect in input mode
@ -131,7 +131,7 @@ river::io::NodeMuxer::NodeMuxer(const std::string& _name, const std11::shared_pt
} }
// set callback mode ... // set callback mode ...
m_interfaceInput1->setInputCallback(std11::bind(&river::io::NodeMuxer::onDataReceivedInput1, m_interfaceInput1->setInputCallback(std11::bind(&audio::river::io::NodeMuxer::onDataReceivedInput1,
this, this,
std11::placeholders::_1, std11::placeholders::_1,
std11::placeholders::_2, std11::placeholders::_2,
@ -140,7 +140,7 @@ river::io::NodeMuxer::NodeMuxer(const std::string& _name, const std11::shared_pt
std11::placeholders::_5, std11::placeholders::_5,
std11::placeholders::_6)); std11::placeholders::_6));
// set callback mode ... // set callback mode ...
m_interfaceInput2->setInputCallback(std11::bind(&river::io::NodeMuxer::onDataReceivedInput2, m_interfaceInput2->setInputCallback(std11::bind(&audio::river::io::NodeMuxer::onDataReceivedInput2,
this, this,
std11::placeholders::_1, std11::placeholders::_1,
std11::placeholders::_2, std11::placeholders::_2,
@ -159,14 +159,14 @@ river::io::NodeMuxer::NodeMuxer(const std::string& _name, const std11::shared_pt
m_process.updateInterAlgo(); m_process.updateInterAlgo();
} }
river::io::NodeMuxer::~NodeMuxer() { audio::river::io::NodeMuxer::~NodeMuxer() {
RIVER_INFO("close input stream"); RIVER_INFO("close input stream");
stop(); stop();
m_interfaceInput1.reset(); m_interfaceInput1.reset();
m_interfaceInput2.reset(); m_interfaceInput2.reset();
}; };
void river::io::NodeMuxer::start() { void audio::river::io::NodeMuxer::start() {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") ); RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
if (m_interfaceInput1 != nullptr) { if (m_interfaceInput1 != nullptr) {
@ -179,7 +179,7 @@ void river::io::NodeMuxer::start() {
} }
} }
void river::io::NodeMuxer::stop() { void audio::river::io::NodeMuxer::stop() {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
if (m_interfaceInput1 != nullptr) { if (m_interfaceInput1 != nullptr) {
m_interfaceInput1->stop(); m_interfaceInput1->stop();
@ -190,7 +190,7 @@ void river::io::NodeMuxer::stop() {
} }
void river::io::NodeMuxer::onDataReceivedInput1(const void* _data, void audio::river::io::NodeMuxer::onDataReceivedInput1(const void* _data,
const std11::chrono::system_clock::time_point& _time, const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk, size_t _nbChunk,
enum audio::format _format, enum audio::format _format,
@ -208,7 +208,7 @@ void river::io::NodeMuxer::onDataReceivedInput1(const void* _data,
process(); process();
} }
void river::io::NodeMuxer::onDataReceivedInput2(const void* _data, void audio::river::io::NodeMuxer::onDataReceivedInput2(const void* _data,
const std11::chrono::system_clock::time_point& _time, const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk, size_t _nbChunk,
enum audio::format _format, enum audio::format _format,
@ -226,7 +226,7 @@ void river::io::NodeMuxer::onDataReceivedInput2(const void* _data,
process(); process();
} }
void river::io::NodeMuxer::process() { void audio::river::io::NodeMuxer::process() {
if (m_bufferInput1.getSize() <= 256) { if (m_bufferInput1.getSize() <= 256) {
return; return;
} }
@ -296,12 +296,12 @@ void river::io::NodeMuxer::process() {
} }
void river::io::NodeMuxer::reorder(void* _output, uint32_t _nbChunk, void* _input, const std::vector<audio::channel>& _mapInput) { void audio::river::io::NodeMuxer::reorder(void* _output, uint32_t _nbChunk, void* _input, const std::vector<audio::channel>& _mapInput) {
// real process: (only depend of data size): // real process: (only depend of data size):
switch (getInterfaceFormat().getFormat()) { switch (getInterfaceFormat().getFormat()) {
case audio::format_int8: case audio::format_int8:
{ {
DRAIN_VERBOSE("convert " << _mapInput << " ==> " << getInterfaceFormat().getMap()); RIVER_VERBOSE("convert " << _mapInput << " ==> " << getInterfaceFormat().getMap());
int8_t* in = static_cast<int8_t*>(_input); int8_t* in = static_cast<int8_t*>(_input);
int8_t* out = static_cast<int8_t*>(_output); int8_t* out = static_cast<int8_t*>(_output);
for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) { for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) {
@ -317,7 +317,7 @@ void river::io::NodeMuxer::reorder(void* _output, uint32_t _nbChunk, void* _inpu
} }
} }
} }
DRAIN_VERBOSE(" " << convertId << " ==> " << kkk); RIVER_VERBOSE(" " << convertId << " ==> " << kkk);
if (convertId != -1) { if (convertId != -1) {
for (size_t iii=0; iii<_nbChunk; ++iii) { for (size_t iii=0; iii<_nbChunk; ++iii) {
out[iii*getInterfaceFormat().getMap().size()+kkk] = in[iii*_mapInput.size()+convertId]; out[iii*getInterfaceFormat().getMap().size()+kkk] = in[iii*_mapInput.size()+convertId];
@ -329,7 +329,7 @@ void river::io::NodeMuxer::reorder(void* _output, uint32_t _nbChunk, void* _inpu
default: default:
case audio::format_int16: case audio::format_int16:
if (getInterfaceFormat().getMap().size() == 1) { if (getInterfaceFormat().getMap().size() == 1) {
DRAIN_VERBOSE("convert " << _mapInput << " ==> " << getInterfaceFormat().getMap()); RIVER_VERBOSE("convert " << _mapInput << " ==> " << getInterfaceFormat().getMap());
int16_t* in = static_cast<int16_t*>(_input); int16_t* in = static_cast<int16_t*>(_input);
int16_t* out = static_cast<int16_t*>(_output); int16_t* out = static_cast<int16_t*>(_output);
for (size_t iii=0; iii<_nbChunk; ++iii) { for (size_t iii=0; iii<_nbChunk; ++iii) {
@ -340,7 +340,7 @@ void river::io::NodeMuxer::reorder(void* _output, uint32_t _nbChunk, void* _inpu
out[iii] = val/_mapInput.size(); out[iii] = val/_mapInput.size();
} }
} else { } else {
DRAIN_VERBOSE("convert " << _mapInput << " ==> " << getInterfaceFormat().getMap()); RIVER_VERBOSE("convert " << _mapInput << " ==> " << getInterfaceFormat().getMap());
int16_t* in = static_cast<int16_t*>(_input); int16_t* in = static_cast<int16_t*>(_input);
int16_t* out = static_cast<int16_t*>(_output); int16_t* out = static_cast<int16_t*>(_output);
for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) { for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) {
@ -356,7 +356,7 @@ void river::io::NodeMuxer::reorder(void* _output, uint32_t _nbChunk, void* _inpu
} }
} }
} }
DRAIN_VERBOSE(" " << convertId << " ==> " << kkk); RIVER_VERBOSE(" " << convertId << " ==> " << kkk);
if (convertId != -1) { if (convertId != -1) {
for (size_t iii=0; iii<_nbChunk; ++iii) { for (size_t iii=0; iii<_nbChunk; ++iii) {
out[iii*getInterfaceFormat().getMap().size()+kkk] = in[iii*_mapInput.size()+convertId]; out[iii*getInterfaceFormat().getMap().size()+kkk] = in[iii*_mapInput.size()+convertId];
@ -370,7 +370,7 @@ void river::io::NodeMuxer::reorder(void* _output, uint32_t _nbChunk, void* _inpu
case audio::format_int32: case audio::format_int32:
case audio::format_float: case audio::format_float:
{ {
DRAIN_VERBOSE("convert (2) " << _mapInput << " ==> " << getInterfaceFormat().getMap()); RIVER_VERBOSE("convert (2) " << _mapInput << " ==> " << getInterfaceFormat().getMap());
uint32_t* in = static_cast<uint32_t*>(_input); uint32_t* in = static_cast<uint32_t*>(_input);
uint32_t* out = static_cast<uint32_t*>(_output); uint32_t* out = static_cast<uint32_t*>(_output);
for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) { for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) {
@ -396,7 +396,7 @@ void river::io::NodeMuxer::reorder(void* _output, uint32_t _nbChunk, void* _inpu
break; break;
case audio::format_double: case audio::format_double:
{ {
DRAIN_VERBOSE("convert (2) " << _mapInput << " ==> " << getInterfaceFormat().getMap()); RIVER_VERBOSE("convert (2) " << _mapInput << " ==> " << getInterfaceFormat().getMap());
uint64_t* in = static_cast<uint64_t*>(_input); uint64_t* in = static_cast<uint64_t*>(_input);
uint64_t* out = static_cast<uint64_t*>(_output); uint64_t* out = static_cast<uint64_t*>(_output);
for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) { for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) {
@ -423,7 +423,7 @@ void river::io::NodeMuxer::reorder(void* _output, uint32_t _nbChunk, void* _inpu
} }
} }
void river::io::NodeMuxer::processMuxer(void* _dataIn1, void* _dataIn2, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time) { void audio::river::io::NodeMuxer::processMuxer(void* _dataIn1, void* _dataIn2, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time) {
//RIVER_INFO("must Mux data : " << m_mapInput1 << " + " << m_mapInput2 << " ==> " << getInterfaceFormat().getMap()); //RIVER_INFO("must Mux data : " << m_mapInput1 << " + " << m_mapInput2 << " ==> " << getInterfaceFormat().getMap());
memset(&m_data[0], 0, m_data.size()); memset(&m_data[0], 0, m_data.size());
reorder(&m_data[0], _nbChunk, _dataIn1, m_mapInput1); reorder(&m_data[0], _nbChunk, _dataIn1, m_mapInput1);
@ -432,7 +432,7 @@ void river::io::NodeMuxer::processMuxer(void* _dataIn1, void* _dataIn2, uint32_t
} }
void river::io::NodeMuxer::generateDot(etk::FSNode& _node) { void audio::river::io::NodeMuxer::generateDot(etk::FSNode& _node) {
_node << " subgraph clusterNode_" << m_uid << " {\n"; _node << " subgraph clusterNode_" << m_uid << " {\n";
_node << " color=blue;\n"; _node << " color=blue;\n";
_node << " label=\"[" << m_uid << "] IO::Node : " << m_name << "\";\n"; _node << " label=\"[" << m_uid << "] IO::Node : " << m_name << "\";\n";
@ -460,7 +460,7 @@ void river::io::NodeMuxer::generateDot(etk::FSNode& _node) {
if (m_listAvaillable[iii].expired() == true) { if (m_listAvaillable[iii].expired() == true) {
continue; continue;
} }
std11::shared_ptr<river::Interface> element = m_listAvaillable[iii].lock(); std11::shared_ptr<audio::river::Interface> element = m_listAvaillable[iii].lock();
if (element == nullptr) { if (element == nullptr) {
continue; continue;
} }

View File

@ -0,0 +1,70 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_RIVER_IO_NODE_MUXER_H__
#define __AUDIO_RIVER_IO_NODE_MUXER_H__
#include <audio/river/io/Node.h>
#include <audio/river/Interface.h>
#include <audio/drain/CircularBuffer.h>
namespace audio {
namespace river {
namespace io {
class Manager;
class NodeMuxer : public Node {
protected:
/**
* @brief Constructor
*/
NodeMuxer(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
static std11::shared_ptr<NodeMuxer> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
virtual ~NodeMuxer();
protected:
virtual void start();
virtual void stop();
std11::shared_ptr<audio::river::Interface> m_interfaceInput1;
std11::shared_ptr<audio::river::Interface> m_interfaceInput2;
std11::shared_ptr<audio::river::Interface> createInput(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName,
const std::string& _name);
void onDataReceivedInput1(const void* _data,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map);
void onDataReceivedInput2(const void* _data,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map);
std::vector<audio::channel> m_mapInput1;
std::vector<audio::channel> m_mapInput2;
audio::drain::CircularBuffer m_bufferInput1;
audio::drain::CircularBuffer m_bufferInput2;
std11::chrono::nanoseconds m_sampleTime; //!< represent the sample time at the specify frequency.
void process();
void processMuxer(void* _dataMic, void* _dataFB, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time);
std::vector<uint8_t> m_data;
public:
virtual void generateDot(etk::FSNode& _node);
private:
void reorder(void* _output, uint32_t _nbChunk, void* _input, const std::vector<audio::channel>& _mapInput);
};
}
}
}
#endif

View File

@ -4,14 +4,14 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#ifdef __AIRTAUDIO_INFERFACE__ #ifdef AUDIO_RIVER_BUILD_ORCHESTRA
#include <river/io/NodeAirTAudio.h> #include <audio/river/io/NodeOrchestra.h>
#include <river/debug.h> #include <audio/river/debug.h>
#include <etk/memory.h> #include <etk/memory.h>
#undef __class__ #undef __class__
#define __class__ "io::NodeAirTAudio" #define __class__ "io::NodeOrchestra"
static std::string asString(const std11::chrono::system_clock::time_point& tp) { static std::string asString(const std11::chrono::system_clock::time_point& tp) {
// convert to system time: // convert to system time:
@ -23,10 +23,10 @@ static std::string asString(const std11::chrono::system_clock::time_point& tp) {
return ts; return ts;
} }
int32_t river::io::NodeAirTAudio::recordCallback(const void* _inputBuffer, int32_t audio::river::io::NodeOrchestra::recordCallback(const void* _inputBuffer,
const std11::chrono::system_clock::time_point& _timeInput, const std11::chrono::system_clock::time_point& _timeInput,
uint32_t _nbChunk, uint32_t _nbChunk,
const std::vector<airtaudio::status>& _status) { const std::vector<audio::orchestra::status>& _status) {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
// TODO : Manage status ... // TODO : Manage status ...
RIVER_VERBOSE("data Input size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size()); RIVER_VERBOSE("data Input size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size());
@ -34,10 +34,10 @@ int32_t river::io::NodeAirTAudio::recordCallback(const void* _inputBuffer,
return 0; return 0;
} }
int32_t river::io::NodeAirTAudio::playbackCallback(void* _outputBuffer, int32_t audio::river::io::NodeOrchestra::playbackCallback(void* _outputBuffer,
const std11::chrono::system_clock::time_point& _timeOutput, const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk, uint32_t _nbChunk,
const std::vector<airtaudio::status>& _status) { const std::vector<audio::orchestra::status>& _status) {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
// TODO : Manage status ... // TODO : Manage status ...
RIVER_VERBOSE("data Output size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size()); RIVER_VERBOSE("data Output size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size());
@ -47,14 +47,14 @@ int32_t river::io::NodeAirTAudio::playbackCallback(void* _outputBuffer,
std11::shared_ptr<river::io::NodeAirTAudio> river::io::NodeAirTAudio::create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) { std11::shared_ptr<audio::river::io::NodeOrchestra> audio::river::io::NodeOrchestra::create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) {
return std11::shared_ptr<river::io::NodeAirTAudio>(new river::io::NodeAirTAudio(_name, _config)); return std11::shared_ptr<audio::river::io::NodeOrchestra>(new audio::river::io::NodeOrchestra(_name, _config));
} }
river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) : audio::river::io::NodeOrchestra::NodeOrchestra(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) :
Node(_name, _config) { Node(_name, _config) {
drain::IOFormatInterface interfaceFormat = getInterfaceFormat(); audio::drain::IOFormatInterface interfaceFormat = getInterfaceFormat();
drain::IOFormatInterface hardwareFormat = getHarwareFormat(); audio::drain::IOFormatInterface hardwareFormat = getHarwareFormat();
/** /**
map-on:{ # select hardware interface and name map-on:{ # select hardware interface and name
interface:"alsa", # interface : "alsa", "pulse", "core", ... interface:"alsa", # interface : "alsa", "pulse", "core", ...
@ -62,14 +62,14 @@ river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std11::s
}, },
nb-chunk:1024 # number of chunk to open device (create the latency anf the frequency to call user) nb-chunk:1024 # number of chunk to open device (create the latency anf the frequency to call user)
*/ */
enum airtaudio::type typeInterface = airtaudio::type_undefined; enum audio::orchestra::type typeInterface = audio::orchestra::type_undefined;
std::string streamName = "default"; std::string streamName = "default";
const std11::shared_ptr<const ejson::Object> tmpObject = m_config->getObject("map-on"); const std11::shared_ptr<const ejson::Object> tmpObject = m_config->getObject("map-on");
if (tmpObject == nullptr) { if (tmpObject == nullptr) {
RIVER_WARNING("missing node : 'map-on' ==> auto map : 'auto:default'"); RIVER_WARNING("missing node : 'map-on' ==> auto map : 'auto:default'");
} else { } else {
std::string value = tmpObject->getStringValue("interface", "default"); std::string value = tmpObject->getStringValue("interface", "default");
typeInterface = airtaudio::getTypeFromString(value); typeInterface = audio::orchestra::getTypeFromString(value);
streamName = tmpObject->getStringValue("name", "default"); streamName = tmpObject->getStringValue("name", "default");
} }
int32_t nbChunk = m_config->getNumberValue("nb-chunk", 1024); int32_t nbChunk = m_config->getNumberValue("nb-chunk", 1024);
@ -187,7 +187,7 @@ river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std11::s
} }
// open Audio device: // open Audio device:
airtaudio::StreamParameters params; audio::orchestra::StreamParameters params;
params.deviceId = deviceId; params.deviceId = deviceId;
params.deviceName = streamName; params.deviceName = streamName;
params.nChannels = hardwareFormat.getMap().size(); params.nChannels = hardwareFormat.getMap().size();
@ -200,7 +200,7 @@ river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std11::s
RIVER_CRITICAL("Can not open hardware device with more channel (" << params.nChannels << ") that is autorized by hardware (" << m_info.inputChannels << ")."); RIVER_CRITICAL("Can not open hardware device with more channel (" << params.nChannels << ") that is autorized by hardware (" << m_info.inputChannels << ").");
} }
} }
airtaudio::StreamOptions option; audio::orchestra::StreamOptions option;
etk::from_string(option.mode, tmpObject->getStringValue("timestamp-mode", "soft")); etk::from_string(option.mode, tmpObject->getStringValue("timestamp-mode", "soft"));
RIVER_DEBUG("interfaceFormat=" << interfaceFormat); RIVER_DEBUG("interfaceFormat=" << interfaceFormat);
@ -208,13 +208,13 @@ river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std11::s
m_rtaudioFrameSize = nbChunk; m_rtaudioFrameSize = nbChunk;
RIVER_INFO("Open output stream nbChannels=" << params.nChannels); RIVER_INFO("Open output stream nbChannels=" << params.nChannels);
enum airtaudio::error err = airtaudio::error_none; enum audio::orchestra::error err = audio::orchestra::error_none;
if (m_isInput == true) { if (m_isInput == true) {
m_process.setInputConfig(hardwareFormat); m_process.setInputConfig(hardwareFormat);
m_process.setOutputConfig(interfaceFormat); m_process.setOutputConfig(interfaceFormat);
err = m_adac.openStream(nullptr, &params, err = m_adac.openStream(nullptr, &params,
hardwareFormat.getFormat(), hardwareFormat.getFrequency(), &m_rtaudioFrameSize, hardwareFormat.getFormat(), hardwareFormat.getFrequency(), &m_rtaudioFrameSize,
std11::bind(&river::io::NodeAirTAudio::recordCallback, std11::bind(&audio::river::io::NodeOrchestra::recordCallback,
this, this,
std11::placeholders::_1, std11::placeholders::_1,
std11::placeholders::_2, std11::placeholders::_2,
@ -227,7 +227,7 @@ river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std11::s
m_process.setOutputConfig(hardwareFormat); m_process.setOutputConfig(hardwareFormat);
err = m_adac.openStream(&params, nullptr, err = m_adac.openStream(&params, nullptr,
hardwareFormat.getFormat(), hardwareFormat.getFrequency(), &m_rtaudioFrameSize, hardwareFormat.getFormat(), hardwareFormat.getFrequency(), &m_rtaudioFrameSize,
std11::bind(&river::io::NodeAirTAudio::playbackCallback, std11::bind(&audio::river::io::NodeOrchestra::playbackCallback,
this, this,
std11::placeholders::_3, std11::placeholders::_3,
std11::placeholders::_4, std11::placeholders::_4,
@ -236,13 +236,13 @@ river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std11::s
option option
); );
} }
if (err != airtaudio::error_none) { if (err != audio::orchestra::error_none) {
RIVER_ERROR("Create stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") << " can not create stream " << err); RIVER_ERROR("Create stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") << " can not create stream " << err);
} }
m_process.updateInterAlgo(); m_process.updateInterAlgo();
} }
river::io::NodeAirTAudio::~NodeAirTAudio() { audio::river::io::NodeOrchestra::~NodeOrchestra() {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("close input stream"); RIVER_INFO("close input stream");
if (m_adac.isStreamOpen() ) { if (m_adac.isStreamOpen() ) {
@ -250,20 +250,20 @@ river::io::NodeAirTAudio::~NodeAirTAudio() {
} }
}; };
void river::io::NodeAirTAudio::start() { void audio::river::io::NodeOrchestra::start() {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") ); RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
enum airtaudio::error err = m_adac.startStream(); enum audio::orchestra::error err = m_adac.startStream();
if (err != airtaudio::error_none) { if (err != audio::orchestra::error_none) {
RIVER_ERROR("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") << " can not start stream ... " << err); RIVER_ERROR("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") << " can not start stream ... " << err);
} }
} }
void river::io::NodeAirTAudio::stop() { void audio::river::io::NodeOrchestra::stop() {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Stop stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") ); RIVER_INFO("Stop stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
enum airtaudio::error err = m_adac.stopStream(); enum audio::orchestra::error err = m_adac.stopStream();
if (err != airtaudio::error_none) { if (err != audio::orchestra::error_none) {
RIVER_ERROR("Stop stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") << " can not stop stream ... " << err); RIVER_ERROR("Stop stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") << " can not stop stream ... " << err);
} }
} }

View File

@ -0,0 +1,78 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_RIVER_IO_NODE_AIRTAUDIO_H__
#define __AUDIO_RIVER_IO_NODE_AIRTAUDIO_H__
#ifdef AUDIO_RIVER_BUILD_ORCHESTRA
#include <audio/river/io/Node.h>
#include <audio/orchestra/Interface.h>
namespace audio {
namespace river {
namespace io {
class Manager;
class Group;
/**
* @brief Low level node that is manage on the interface with the extern lib airtaudio
*/
class NodeOrchestra : public audio::river::io::Node {
friend class audio::river::io::Group;
protected:
/**
* @brief Constructor
*/
NodeOrchestra(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
static std11::shared_ptr<NodeOrchestra> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
virtual ~NodeOrchestra();
virtual bool isHarwareNode() {
return true;
};
protected:
audio::orchestra::Interface m_adac; //!< Real airtaudio interface
audio::orchestra::DeviceInfo m_info; //!< information on the stream.
unsigned int m_rtaudioFrameSize; // DEPRECATED soon...
public:
/**
* @brief Input Callback . Have recaive new data to process.
* @param[in] _inputBuffer Pointer on the data buffer.
* @param[in] _timeInput Time on the fist sample has been recorded.
* @param[in] _nbChunk Number of chunk in the buffer
* @param[in] _status DEPRECATED soon
* @return DEPRECATED soon
*/
int32_t recordCallback(const void* _inputBuffer,
const std11::chrono::system_clock::time_point& _timeInput,
uint32_t _nbChunk,
const std::vector<audio::orchestra::status>& _status);
/**
* @brief Playback callback. Request new data on output
* @param[in,out] _outputBuffer Pointer on the buffer to fill data.
* @param[in] _timeOutput Time on wich the data might be played.
* @param[in] _nbChunk Number of chunk in the buffer
* @param[in] _status DEPRECATED soon
* @return DEPRECATED soon
*/
int32_t playbackCallback(void* _outputBuffer,
const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk,
const std::vector<audio::orchestra::status>& _status);
protected:
virtual void start();
virtual void stop();
};
}
}
}
#endif
#endif

View File

@ -4,10 +4,10 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#ifdef __PORTAUDIO_INFERFACE__ #ifdef AUDIO_RIVER_BUILD_PORTAUDIO
#include <river/io/NodePortAudio.h> #include <audio/river/io/NodePortAudio.h>
#include <river/debug.h> #include <audio/river/debug.h>
#include <etk/memory.h> #include <etk/memory.h>
#undef __class__ #undef __class__
@ -29,7 +29,7 @@ static int portAudioStreamCallback(const void *_input,
const PaStreamCallbackTimeInfo* _timeInfo, const PaStreamCallbackTimeInfo* _timeInfo,
PaStreamCallbackFlags _statusFlags, PaStreamCallbackFlags _statusFlags,
void *_userData) { void *_userData) {
river::io::NodePortAudio* myClass = reinterpret_cast<river::io::NodePortAudio*>(_userData); audio::river::io::NodePortAudio* myClass = reinterpret_cast<audio::river::io::NodePortAudio*>(_userData);
int64_t sec = int64_t(_timeInfo->inputBufferAdcTime); int64_t sec = int64_t(_timeInfo->inputBufferAdcTime);
int64_t nsec = (_timeInfo->inputBufferAdcTime-double(sec))*1000000000LL; int64_t nsec = (_timeInfo->inputBufferAdcTime-double(sec))*1000000000LL;
std11::chrono::system_clock::time_point timeInput = std11::chrono::system_clock::from_time_t(sec) + std11::chrono::nanoseconds(nsec); std11::chrono::system_clock::time_point timeInput = std11::chrono::system_clock::from_time_t(sec) + std11::chrono::nanoseconds(nsec);
@ -44,7 +44,7 @@ static int portAudioStreamCallback(const void *_input,
_statusFlags); _statusFlags);
} }
int32_t river::io::NodePortAudio::duplexCallback(const void* _inputBuffer, int32_t audio::river::io::NodePortAudio::duplexCallback(const void* _inputBuffer,
const std11::chrono::system_clock::time_point& _timeInput, const std11::chrono::system_clock::time_point& _timeInput,
void* _outputBuffer, void* _outputBuffer,
const std11::chrono::system_clock::time_point& _timeOutput, const std11::chrono::system_clock::time_point& _timeOutput,
@ -64,14 +64,14 @@ int32_t river::io::NodePortAudio::duplexCallback(const void* _inputBuffer,
} }
std11::shared_ptr<river::io::NodePortAudio> river::io::NodePortAudio::create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) { std11::shared_ptr<audio::river::io::NodePortAudio> audio::river::io::NodePortAudio::create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) {
return std11::shared_ptr<river::io::NodePortAudio>(new river::io::NodePortAudio(_name, _config)); return std11::shared_ptr<audio::river::io::NodePortAudio>(new audio::river::io::NodePortAudio(_name, _config));
} }
river::io::NodePortAudio::NodePortAudio(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) : audio::river::io::NodePortAudio::NodePortAudio(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) :
Node(_name, _config) { Node(_name, _config) {
drain::IOFormatInterface interfaceFormat = getInterfaceFormat(); audio::drain::IOFormatInterface interfaceFormat = getInterfaceFormat();
drain::IOFormatInterface hardwareFormat = getHarwareFormat(); audio::drain::IOFormatInterface hardwareFormat = getHarwareFormat();
/** /**
map-on:{ # select hardware interface and name map-on:{ # select hardware interface and name
interface:"alsa", # interface : "alsa", "pulse", "core", ... interface:"alsa", # interface : "alsa", "pulse", "core", ...
@ -79,14 +79,14 @@ river::io::NodePortAudio::NodePortAudio(const std::string& _name, const std11::s
}, },
nb-chunk:1024 # number of chunk to open device (create the latency anf the frequency to call user) nb-chunk:1024 # number of chunk to open device (create the latency anf the frequency to call user)
*/ */
enum airtaudio::type typeInterface = airtaudio::type_undefined; enum audio::orchestra::type typeInterface = audio::orchestra::type_undefined;
std::string streamName = "default"; std::string streamName = "default";
const std11::shared_ptr<const ejson::Object> tmpObject = m_config->getObject("map-on"); const std11::shared_ptr<const ejson::Object> tmpObject = m_config->getObject("map-on");
if (tmpObject == nullptr) { if (tmpObject == nullptr) {
RIVER_WARNING("missing node : 'map-on' ==> auto map : 'auto:default'"); RIVER_WARNING("missing node : 'map-on' ==> auto map : 'auto:default'");
} else { } else {
std::string value = tmpObject->getStringValue("interface", "default"); std::string value = tmpObject->getStringValue("interface", "default");
typeInterface = airtaudio::getTypeFromString(value); typeInterface = audio::orchestra::getTypeFromString(value);
streamName = tmpObject->getStringValue("name", "default"); streamName = tmpObject->getStringValue("name", "default");
} }
int32_t nbChunk = m_config->getNumberValue("nb-chunk", 1024); int32_t nbChunk = m_config->getNumberValue("nb-chunk", 1024);
@ -117,7 +117,7 @@ river::io::NodePortAudio::NodePortAudio(const std::string& _name, const std11::s
m_process.updateInterAlgo(); m_process.updateInterAlgo();
} }
river::io::NodePortAudio::~NodePortAudio() { audio::river::io::NodePortAudio::~NodePortAudio() {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("close input stream"); RIVER_INFO("close input stream");
PaError err = Pa_CloseStream( m_stream ); PaError err = Pa_CloseStream( m_stream );
@ -126,7 +126,7 @@ river::io::NodePortAudio::~NodePortAudio() {
} }
}; };
void river::io::NodePortAudio::start() { void audio::river::io::NodePortAudio::start() {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") ); RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
PaError err = Pa_StartStream(m_stream); PaError err = Pa_StartStream(m_stream);
@ -135,7 +135,7 @@ void river::io::NodePortAudio::start() {
} }
} }
void river::io::NodePortAudio::stop() { void audio::river::io::NodePortAudio::stop() {
std11::unique_lock<std11::mutex> lock(m_mutex); std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Stop stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") ); RIVER_INFO("Stop stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
PaError err = Pa_StopStream(m_stream); PaError err = Pa_StopStream(m_stream);

View File

@ -0,0 +1,55 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_RIVER_IO_NODE_PORTAUDIO_H__
#define __AUDIO_RIVER_IO_NODE_PORTAUDIO_H__
#ifdef AUDIO_RIVER_BUILD_PORTAUDIO
#include <audio/river/Interface.h>
#include <audio/river/io/Node.h>
#include <portaudio.h>
namespace audio {
namespace river {
namespace io {
class Manager;
//! @not-in-doc
class NodePortAudio : public Node {
protected:
/**
* @brief Constructor
*/
NodePortAudio(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
static std11::shared_ptr<NodePortAudio> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
virtual ~NodePortAudio();
virtual bool isHarwareNode() {
return true;
};
protected:
PaStream* m_stream;
public:
int32_t duplexCallback(const void* _inputBuffer,
const std11::chrono::system_clock::time_point& _timeInput,
void* _outputBuffer,
const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk,
PaStreamCallbackFlags _status);
protected:
virtual void start();
virtual void stop();
};
}
}
}
#endif
#endif

View File

@ -4,21 +4,21 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <river/river.h> #include <audio/river/river.h>
#include <river/debug.h> #include <audio/river/debug.h>
#include <river/io/Manager.h> #include <audio/river/io/Manager.h>
static bool river_isInit = false; static bool river_isInit = false;
static std::string river_configFile = ""; static std::string river_configFile = "";
void river::init(const std::string& _filename) { void audio::river::init(const std::string& _filename) {
if (river_isInit == false) { if (river_isInit == false) {
river_isInit = true; river_isInit = true;
river_configFile = _filename; river_configFile = _filename;
RIVER_DEBUG("init RIVER :" << river_configFile); RIVER_DEBUG("init RIVER :" << river_configFile);
std11::shared_ptr<river::io::Manager> mng = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> mng = audio::river::io::Manager::getInstance();
if (mng != nullptr) { if (mng != nullptr) {
mng->init(river_configFile); mng->init(river_configFile);
} }
@ -27,12 +27,12 @@ void river::init(const std::string& _filename) {
} }
} }
void river::initString(const std::string& _config) { void audio::river::initString(const std::string& _config) {
if (river_isInit == false) { if (river_isInit == false) {
river_isInit = true; river_isInit = true;
river_configFile = _config; river_configFile = _config;
RIVER_DEBUG("init RIVER with config."); RIVER_DEBUG("init RIVER with config.");
std11::shared_ptr<river::io::Manager> mng = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> mng = audio::river::io::Manager::getInstance();
if (mng != nullptr) { if (mng != nullptr) {
mng->initString(river_configFile); mng->initString(river_configFile);
} }
@ -41,11 +41,11 @@ void river::initString(const std::string& _config) {
} }
} }
void river::unInit() { void audio::river::unInit() {
if (river_isInit == true) { if (river_isInit == true) {
river_isInit = false; river_isInit = false;
RIVER_DEBUG("un-init RIVER."); RIVER_DEBUG("un-init RIVER.");
std11::shared_ptr<river::io::Manager> mng = river::io::Manager::getInstance(); std11::shared_ptr<audio::river::io::Manager> mng = audio::river::io::Manager::getInstance();
if (mng != nullptr) { if (mng != nullptr) {
RIVER_ERROR("Can not get on the RIVER hardware manager !!!"); RIVER_ERROR("Can not get on the RIVER hardware manager !!!");
mng->unInit(); mng->unInit();
@ -53,7 +53,7 @@ void river::unInit() {
} }
} }
bool river::isInit() { bool audio::river::isInit() {
return river_isInit; return river_isInit;
} }

40
audio/river/river.h Normal file
View File

@ -0,0 +1,40 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __AUDIO_RIVER_H__
#define __AUDIO_RIVER_H__
#include <etk/types.h>
namespace audio {
namespace river {
/**
* @brief Initialize the River Library
* @param[in] _filename Name of the configuration file (if "" ==> default config file)
*/
void init(const std::string& _filename);
/**
* @brief Initialize the River Library with a json data string
* @param[in] _config json sting data
*/
void initString(const std::string& _config);
/**
* @brief Un-initialize the River Library
* @note this close all stream of all interfaces.
* @note really good for test.
*/
void unInit();
/**
* @brief Get the status of initialisation
* @return true River is init
* @return false River is NOT init
*/
bool isInit();
}
}
#endif

41
lutin_audio_river.py Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/python
import lutinModule as module
import lutinTools as tools
import lutinDebug as debug
def get_desc():
return "audio_river : Multi-nodal audio interface"
def create(target):
myModule = module.Module(__file__, 'audio_river', 'LIBRARY')
myModule.add_src_file([
'audio/river/debug.cpp',
'audio/river/river.cpp',
'audio/river/Manager.cpp',
'audio/river/Interface.cpp',
'audio/river/io/Group.cpp',
'audio/river/io/Node.cpp',
'audio/river/io/NodeOrchestra.cpp',
'audio/river/io/NodePortAudio.cpp',
'audio/river/io/NodeAEC.cpp',
'audio/river/io/NodeMuxer.cpp',
'audio/river/io/Manager.cpp'
])
myModule.add_optionnal_module_depend('audio_orchestra', "AUDIO_RIVER_BUILD_ORCHESTRA")
myModule.add_optionnal_module_depend('portaudio', "AUDIO_RIVER_BUILD_PORTAUDIO")
myModule.add_module_depend(['audio', 'audio_drain', 'ejson'])
myModule.add_export_path(tools.get_current_path(__file__))
# add the currrent module at the
return myModule

29
lutin_audio_river_test.py Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/python
import lutinModule as module
import lutinTools as tools
import lutinDebug as debug
def get_desc():
return "river_test : Multi-nodal audio interface test"
def create(target):
myModule = module.Module(__file__, 'audio_river_test', 'BINARY')
myModule.add_src_file([
'test/main.cpp',
'test/debug.cpp'
])
myModule.add_module_depend(['audio_river', 'gtest', 'etk'])
return myModule

View File

@ -1,41 +0,0 @@
#!/usr/bin/python
import lutinModule as module
import lutinTools as tools
import lutinDebug as debug
def get_desc():
return "river : Multi-nodal audio interface"
def create(target):
myModule = module.Module(__file__, 'river', 'LIBRARY')
myModule.add_src_file([
'river/debug.cpp',
'river/river.cpp',
'river/Manager.cpp',
'river/Interface.cpp',
'river/io/Group.cpp',
'river/io/Node.cpp',
'river/io/NodeAirTAudio.cpp',
'river/io/NodePortAudio.cpp',
'river/io/NodeAEC.cpp',
'river/io/NodeMuxer.cpp',
'river/io/Manager.cpp'
])
myModule.add_optionnal_module_depend('airtaudio', "__AIRTAUDIO_INFERFACE__")
myModule.add_optionnal_module_depend('portaudio', "__PORTAUDIO_INFERFACE__")
myModule.add_module_depend(['audio', 'drain', 'ejson'])
myModule.add_export_path(tools.get_current_path(__file__))
# add the currrent module at the
return myModule

View File

@ -1,43 +0,0 @@
#!/usr/bin/python
import lutinModule as module
import lutinTools as tools
import lutinDebug as debug
def get_desc():
return "river_test : Multi-nodal audio interface test"
def create(target):
myModule = module.Module(__file__, 'river_test', 'BINARY')
myModule.add_src_file([
'test/main.cpp',
'test/debug.cpp'
])
"""
if target.name=="Windows":
myModule.copy_file('data/hardwareWindows.json', 'hardware.json')
elif target.name=="Linux":
myModule.copy_file('data/hardwareLinux.json', 'hardware.json')
elif target.name=="MacOs":
myModule.copy_file('data/hardwareMacOs.json', 'hardware.json')
elif target.name=="IOs":
myModule.copy_file('data/hardwareIOs.json', 'hardware.json')
elif target.name=="Android":
myModule.copy_file('data/hardwareAndroid.json', 'hardware.json')
else:
debug.warning("unknow target for AIRTAudio : " + target.name);
"""
myModule.add_module_depend(['river', 'gtest', 'etk'])
return myModule

View File

@ -1,333 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __RIVER_INTERFACE_H__
#define __RIVER_INTERFACE_H__
#include <string>
#include <vector>
#include <stdint.h>
#include <etk/mutex.h>
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#include <audio/format.h>
#include <audio/channel.h>
#include <drain/Process.h>
#include <drain/EndPointCallback.h>
#include <drain/EndPointWrite.h>
#include <ejson/ejson.h>
#include <etk/os/FSNode.h>
namespace river {
namespace io {
class Node;
class NodeAirTAudio;
class NodeAEC;
class NodeMuxer;
}
enum modeInterface {
modeInterface_unknow,
modeInterface_input,
modeInterface_output,
modeInterface_feedback,
};
/**
* @brief Interface is the basic handle to manage the input output stream
* @note To create this class see @ref river::Manager class
*/
class Interface : public std11::enable_shared_from_this<Interface> {
friend class io::Node;
friend class io::NodeAirTAudio;
friend class io::NodeAEC;
friend class io::NodeMuxer;
friend class Manager;
protected:
uint32_t m_uid; //!< unique ID for interface
protected:
/**
* @brief Constructor (use factory)
*/
Interface();
/**
* @brief Initilize the Class (do all that is not manage by constructor) Call by factory.
* @param[in] _freq Frequency.
* @param[in] _map Channel map organization.
* @param[in] _format Sample format
* @param[in] _node Low level interface to connect the flow.
* @param[in] _config Special configuration of this interface.
* @return true Configuration done corectly.
* @return false the configuration has an error.
*/
bool init(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std11::shared_ptr<river::io::Node>& _node,
const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Factory of this interface (called by class river::Manager)
* @param[in] _freq Frequency.
* @param[in] _map Channel map organization.
* @param[in] _format Sample format
* @param[in] _node Low level interface to connect the flow.
* @param[in] _config Special configuration of this interface.
* @return nullptr The configuration does not work.
* @return pointer The interface has been corectly created.
*/
static std11::shared_ptr<Interface> create(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std11::shared_ptr<river::io::Node>& _node,
const std11::shared_ptr<const ejson::Object>& _config);
public:
/**
* @brief Destructor
*/
virtual ~Interface();
protected:
mutable std11::recursive_mutex m_mutex; //!< Local mutex to protect data
std11::shared_ptr<const ejson::Object> m_config; //!< configuration set by the user.
protected:
enum modeInterface m_mode; //!< interface type (input/output/feedback)
public:
/**
* @brief Get mode type of the current interface.
* @return The mode requested.
*/
enum modeInterface getMode() {
return m_mode;
}
protected:
drain::Process m_process; //!< Algorithme processing engine
public:
/**
* @brief Get the interface format configuration.
* @return The current format.
*/
const drain::IOFormatInterface& getInterfaceFormat() {
if ( m_mode == modeInterface_input
|| m_mode == modeInterface_feedback) {
return m_process.getOutputConfig();
} else {
return m_process.getInputConfig();
}
}
protected:
std11::shared_ptr<river::io::Node> m_node; //!< Hardware interface to/from stream audio flow.
protected:
std::string m_name; //!< Name of the interface.
public:
/**
* @brief Get interface name.
* @return The current name.
*/
virtual std::string getName() {
return m_name;
};
/**
* @brief Set the interface name
* @param[in] _name new name of the interface
*/
virtual void setName(const std::string& _name) {
m_name = _name;
};
/**
* @brief set the read/write mode enable.
* @note If you not set a output/input callback you must call this function.
*/
virtual void setReadwrite();
/**
* @brief When we want to implement a Callback Mode:
*/
/**
* @brief Set a callback on the write mode interface to know when data is needed in the buffer
* @param[in] _function Function to call
*/
virtual void setWriteCallback(drain::playbackFunctionWrite _function);
/**
* @brief Set Output callback mode with the specify callback.
* @param[in] _function Function to call
*/
virtual void setOutputCallback(drain::playbackFunction _function);
/**
* @brief Set Input callback mode with the specify callback.
* @param[in] _function Function to call
*/
virtual void setInputCallback(drain::recordFunction _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 noise volume control.
*/
virtual void addVolumeGroup(const std::string& _name);
public:
/**
* @brief Start the Audio interface flow.
* @param[in] _time Time to start the flow (0) to start as fast as possible...
* @note _time to play buffer when output interface (if possible)
* @note _time to read buffer when inut interface (if possible)
*/
virtual void start(const std11::chrono::system_clock::time_point& _time = std11::chrono::system_clock::time_point());
/**
* @brief Stop the current flow.
* @param[in] _fast The stream stop as fast as possible (not write all the buffer in speaker) but apply cross fade out.
* @param[in] _abort The stream stop whith no garenty of good audio stop.
*/
virtual void stop(bool _fast=false, bool _abort=false);
/**
* @brief Abort flow (no audio garenty)
*/
virtual void abort();
/**
* @brief Set a parameter in the stream flow
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @param[in] _value Value to set.
* @return true set done
* @return false An error occured
* @example : setParameter("volume", "FLOW", "-3dB");
* @example : setParameter("LowPassFilter", "cutFrequency", "1000Hz");
*/
virtual bool setParameter(const std::string& _filter, const std::string& _parameter, const std::string& _value);
/**
* @brief Get a parameter value
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @return The requested value.
* @example : getParameter("volume", "FLOW"); can return something like "-3dB"
* @example : getParameter("LowPassFilter", "cutFrequency"); can return something like "[-120..0]dB"
*/
virtual std::string getParameter(const std::string& _filter, const std::string& _parameter) const;
/**
* @brief Get a parameter value
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @return The requested value.
* @example : getParameter("volume", "FLOW"); can return something like "[-120..0]dB"
* @example : getParameter("LowPassFilter", "cutFreqiency"); can return something like "]100..10000]Hz"
*/
virtual std::string getParameterProperty(const std::string& _filter, const std::string& _parameter) const;
/**
* @brief write some audio sample in the speakers
* @param[in] _value Data To write on output
* @param[in] _nbChunk Number of audio chunk to write
*/
// TODO : TimeOut ???
virtual void write(const void* _value, size_t _nbChunk);
/**
* @brief read some audio sample from Microphone
* @param[in] _value Data To write on output
* @param[in] _nbChunk Number of audio chunk to write
*/
// TODO : TimeOut ???
virtual void read(void* _value, size_t _nbChunk);
/**
* @brief Get number of chunk in the local buffer
* @return Number of chunk
*/
virtual size_t size() const;
/**
* @brief Set buffer size in chunk number
* @param[in] _nbChunk Number of chunk in the buffer
*/
virtual void setBufferSize(size_t _nbChunk);
/**
* @brief Set buffer size size of the buffer with the stored time in µs
* @param[in] _time Time in microsecond of the buffer
*/
virtual void setBufferSize(const std11::chrono::microseconds& _time);
/**
* @brief get buffer size in chunk number
* @return Number of chunk that can be written in the buffer
*/
virtual size_t getBufferSize();
/**
* @brief Set buffer size size of the buffer with the stored time in µs
* @return Time in microsecond that can be written in the buffer
*/
virtual std11::chrono::microseconds getBufferSizeMicrosecond();
/**
* @brief Get buffer size filled in chunk number
* @return Number of chunk in the buffer (that might be read/write)
*/
virtual size_t getBufferFillSize();
/**
* @brief Set buffer size size of the buffer with the stored time in µs
* @return Time in microsecond of the buffer (that might be read/write)
*/
virtual std11::chrono::microseconds getBufferFillSizeMicrosecond();
/**
* @brief Remove internal Buffer
*/
virtual void clearInternalBuffer();
/**
* @brief Write : Get the time of the next sample time to write in the local buffer
* @brief Read : Get the time of the next sample time to read in the local buffer
*/
virtual std11::chrono::system_clock::time_point getCurrentTime() const;
private:
/**
* @brief Node Call interface : Input interface node has new data.
* @param[in] _time Time where the first sample has been capture.
* @param[in] _data Pointer on the new data.
* @param[in] _nbChunk Number of chunk in the buffer.
*/
virtual void systemNewInputData(std11::chrono::system_clock::time_point _time, const void* _data, size_t _nbChunk);
/**
* @brief Node Call interface: Output interface node need new data.
* @param[in] _time Time where the data might be played
* @param[in] _data Pointer on the data.
* @param[in] _nbChunk Number of chunk that might be write
* @param[in] _chunkSize Chunk size.
*/
virtual void systemNeedOutputData(std11::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize);
/**
* @brief Node Call interface: A volume has change.
*/
virtual void systemVolumeChange();
public:
/**
* @brief Create the dot in the FileNode stream.
* @param[in,out] _node File node to write data.
* @param[in] _nameIO Name to link the interface node
* @param[in] _isLink True if the node is connected on the current interface.
*/
virtual void generateDot(etk::FSNode& _node, const std::string& _nameIO, bool _isLink=true);
/**
* @brief Get the current 'dot' name of the interface
* @return The anme requested.
*/
virtual std::string getDotNodeName() const;
protected:
/**
* @brief Interfanel generate of status
* @param[in] _origin status source
* @param[in] _status Event status
*/
void generateStatus(const std::string& _origin, const std::string& _status) {
m_process.generateStatus(_origin, _status);
}
public:
/**
* @brief Set status callback
* @param[in] _newFunction Function to call
*/
void setStatusFunction(drain::statusFunction _newFunction) {
m_process.setStatusFunction(_newFunction);
}
};
};
#endif

View File

@ -1,138 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __RIVER_MANAGER_H__
#define __RIVER_MANAGER_H__
#include <string>
#include <stdint.h>
#include <etk/memory.h>
#include <river/Interface.h>
#include <audio/format.h>
#include <audio/channel.h>
#include <ejson/ejson.h>
namespace river {
/**
* @brief Audio interface manager : Single interface for every application that want to access on the Audio input/output
*/
class Manager : public std11::enable_shared_from_this<Manager> {
private:
const std::string& m_applicationUniqueId; //!< name of the application that open the Audio Interface.
std::vector<std11::weak_ptr<river::Interface> > m_listOpenInterface; //!< List of all open Stream.
protected:
/**
* @brief Constructor
*/
Manager(const std::string& _applicationUniqueId);
public:
/**
* @brief factory of the manager. Every Application will have only one maager for all his flow. this permit to manage all of it
* @param[in] _applicationUniqueId Unique name of the application
* @return Pointer on the manager or nullptr if an error occured
*/
static std11::shared_ptr<river::Manager> create(const std::string& _applicationUniqueId);
/**
* @brief Destructor
*/
virtual ~Manager();
public:
/**
* @brief Get all input audio stream.
* @return a list of all availlables input stream name
*/
std::vector<std::string> getListStreamInput();
/**
* @brief Get all output audio stream.
* @return a list of all availlables output stream name
*/
std::vector<std::string> getListStreamOutput();
/**
* @brief Get all audio virtual stream.
* @return a list of all availlables virtual stream name
*/
std::vector<std::string> getListStreamVirtual();
/**
* @brief Get all audio stream.
* @return a list of all availlables stream name
*/
std::vector<std::string> getListStream();
/**
* @brief Set a volume for a specific group
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @param[in] _value Volume in dB to set.
* @return true set done
* @return false An error occured
* @example : setVolume("MASTER", -3.0f);
*/
virtual bool setVolume(const std::string& _volumeName, float _valuedB);
/**
* @brief Get a volume value
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @return The Volume value in dB.
* @example ret = getVolume("MASTER"); can return something like ret = -3.0f
*/
virtual float getVolume(const std::string& _volumeName) const;
/**
* @brief Get a parameter value
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @return The requested value Range.
* @example ret = getVolumeRange("MASTER"); can return something like ret=(-120.0f,0.0f)
*/
virtual std::pair<float,float> getVolumeRange(const std::string& _volumeName) const;
/**
* @brief Create output Interface
* @param[in] _freq Frequency to open Interface [8,16,22,32,48] kHz
* @param[in] _map ChannelMap of the Output
* @param[in] _format Sample Format to open the stream [int8_t, int16_t, ...]
* @param[in] _streamName Stream name to open: "" or "default" open current selected output
* @param[in] _options Json option to configure default resampling and many other things.
* @return a pointer on the interface
*/
virtual std11::shared_ptr<Interface> createOutput(float _freq = 48000,
const std::vector<audio::channel>& _map = std::vector<audio::channel>(),
audio::format _format = audio::format_int16,
const std::string& _streamName = "",
const std::string& _options = "");
/**
* @brief Create input Interface
* @param[in] _freq Frequency to open Interface [8,16,22,32,48] kHz
* @param[in] _map ChannelMap of the Output
* @param[in] _format Sample Format to open the stream [int8_t, int16_t, ...]
* @param[in] _streamName Stream name to open: "" or "default" open current selected input
* @param[in] _options Json option to configure default resampling and many other things.
* @return a pointer on the interface
*/
virtual std11::shared_ptr<Interface> createInput(float _freq = 48000,
const std::vector<audio::channel>& _map = std::vector<audio::channel>(),
audio::format _format = audio::format_int16,
const std::string& _streamName = "",
const std::string& _options = "");
/**
* @brief Create input Feedback Interface
* @param[in] _freq Frequency to open Interface [8,16,22,32,48] kHz
* @param[in] _map ChannelMap of the Output
* @param[in] _format Sample Format to open the stream [int8_t, int16_t, ...]
* @param[in] _streamName Stream name to open: "" or "default" open current selected input
* @param[in] _options Json option to configure default resampling and many other things.
* @return a pointer on the interface
*/
virtual std11::shared_ptr<Interface> createFeedback(float _freq = 48000,
const std::vector<audio::channel>& _map = std::vector<audio::channel>(),
audio::format _format = audio::format_int16,
const std::string& _streamName = "",
const std::string& _options = "");
/**
* @brief Generate the dot file corresponding at all the actif nodes.
* @param[in] _filename Name of the file to write data.
*/
virtual void generateDotAll(const std::string& _filename);
};
};
#endif

View File

@ -1,76 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __RIVER_IO_GROUP_H__
#define __RIVER_IO_GROUP_H__
#include <string>
#include <vector>
#include <ejson/ejson.h>
#include <etk/os/FSNode.h>
namespace river {
namespace io {
class Node;
class Manager;
/**
* @brief Group is contituate to manage some input and output in the same start and stop.
* It link N interface in a group. The start and the sopt is requested in Node inside the
* group they will start and stop when the first start is requested and stop when the last
* is stopped.
* @note For the Alsa interface a low level link is availlable with AirTAudio for Alsa (One thread)
*/
class Group : public std11::enable_shared_from_this<Group> {
public:
/**
* @brief Contructor. No special thing to do.
*/
Group() {}
/**
* @brief Destructor
*/
~Group() {
// TODO : ...
}
private:
std::vector< std11::shared_ptr<Node> > m_list; //!< List of all node in the group
public:
/**
* @brief Create a group with all node needed to syncronize together
* @param[in] _obj json document to create all the node in the group named _name
* @param[in] _name Name of the group to create
*/
void createFrom(const ejson::Document& _obj, const std::string& _name);
/**
* @brief Get a node in the group (if the node is not in the group nothing append).
* @param[in] _name Name of the node requested.
* @return nullptr The node named _name was not found.
* @return pointer The node was find in this group.
*/
std11::shared_ptr<river::io::Node> getNode(const std::string& _name);
/**
* @brief Start the group.
* @note all sub-node will be started.
*/
void start();
/**
* @brief Stop the group.
* @note All sub-node will be stopped at the reserve order that they start.
*/
void stop();
/**
* @brief Create the dot in the FileNode stream.
* @param[in,out] _node File node to write data.
* @param[in] _hardwareNode true if user want only display the hardware
* node and not the software node. false The oposite.
*/
void generateDot(etk::FSNode& _node, bool _hardwareNode);
};
}
}
#endif

View File

@ -1,143 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __RIVER_IO_MANAGER_H__
#define __RIVER_IO_MANAGER_H__
#include <string>
#include <vector>
#include <map>
#include <list>
#include <stdint.h>
#include <etk/mutex.h>
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#include <audio/format.h>
#include <audio/channel.h>
#include <ejson/ejson.h>
#include <drain/Volume.h>
#include <river/io/Group.h>
namespace river {
namespace io {
class Node;
/**
* @brief Internal sigleton of all Flow hadware and virtuals.
* @note this class will be initialize by the river::init() function at the start of the application.
*/
class Manager : public std11::enable_shared_from_this<Manager> {
private:
mutable std11::recursive_mutex m_mutex; //!< prevent multiple access
private:
/**
* @brief Constructor
*/
Manager();
public:
static std11::shared_ptr<Manager> getInstance();
/**
* @brief Destructor
*/
~Manager();
/**
* @brief Called by river::init() to set the hardware configuration file.
* @param[in] _filename Name of the file to initialize.
*/
void init(const std::string& _filename);
/**
* @brief Called by river::initString() to set the hardware configuration string.
* @param[in] _data json configuration string.
*/
void initString(const std::string& _data);
/**
* @brief Called by river::inInit() to uninitialize all the low level interface.
*/
void unInit();
private:
ejson::Document m_config; //!< harware configuration
std::vector<std11::shared_ptr<river::io::Node> > m_listKeepAlive; //!< list of all Node that might be keep alive sone/all time
std::vector<std11::weak_ptr<river::io::Node> > m_list; //!< List of all IO node
public:
/**
* @brief Get a node with his name (the name is set in the description file.
* @param[in] _name Name of the node
* @return Pointer on the noe or a nullptr if the node does not exist in the file or an error occured.
*/
std11::shared_ptr<river::io::Node> getNode(const std::string& _name);
private:
std::vector<std11::shared_ptr<drain::VolumeElement> > m_volumeGroup; //!< List of All global volume in the Low level interface.
public:
/**
* @brief Get a volume in the global list of vilume
* @param[in] _name Name of the volume.
* @return pointer on the requested volume (create it if does not exist). nullptr if the name is empty.
*/
std11::shared_ptr<drain::VolumeElement> getVolumeGroup(const std::string& _name);
/**
* @brief Get all input audio stream.
* @return a list of all availlables input stream name
*/
std::vector<std::string> getListStreamInput();
/**
* @brief Get all output audio stream.
* @return a list of all availlables output stream name
*/
std::vector<std::string> getListStreamOutput();
/**
* @brief Get all audio virtual stream.
* @return a list of all availlables virtual stream name
*/
std::vector<std::string> getListStreamVirtual();
/**
* @brief Get all audio stream.
* @return a list of all availlables stream name
*/
std::vector<std::string> getListStream();
/**
* @brief Set a volume for a specific group
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @param[in] _value Volume in dB to set.
* @return true set done
* @return false An error occured
* @example : setVolume("MASTER", -3.0f);
*/
bool setVolume(const std::string& _volumeName, float _valuedB);
/**
* @brief Get a volume value
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @return The Volume value in dB.
* @example ret = getVolume("MASTER"); can return something like ret = -3.0f
*/
float getVolume(const std::string& _volumeName);
/**
* @brief Get a parameter value
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @return The requested value Range.
* @example ret = getVolumeRange("MASTER"); can return something like ret=(-120.0f,0.0f)
*/
std::pair<float,float> getVolumeRange(const std::string& _volumeName) const;
/**
* @brief Generate the dot file corresponding at the actif nodes.
* @param[in] _filename Name of the file to write data.
*/
void generateDot(const std::string& _filename);
private:
std::map<std::string, std11::shared_ptr<river::io::Group> > m_listGroup; //!< List of all groups
/**
* @brief get a low level interface group.
* @param[in] _name Name of the group.
* @return Pointer on the requested group or nullptr if the group does not existed.
*/
std11::shared_ptr<river::io::Group> getGroup(const std::string& _name);
};
}
}
#endif

View File

@ -1,225 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __RIVER_IO_NODE_H__
#define __RIVER_IO_NODE_H__
#include <string>
#include <vector>
#include <list>
#include <stdint.h>
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#include <audio/format.h>
#include <audio/channel.h>
#include "Manager.h"
#include <river/Interface.h>
#include <airtaudio/Interface.h>
#include <drain/IOFormatInterface.h>
#include <drain/Volume.h>
#include <etk/os/FSNode.h>
namespace river {
namespace io {
class Manager;
class Group;
/**
* @brief A node is the base for input/output interface. When a output id declared, we automaticly have a feedback associated.
* this manage the muxing of data for output an the demuxing for input.
*/
class Node : public std11::enable_shared_from_this<Node> {
friend class river::io::Group;
protected:
uint32_t m_uid; //!< uniqueNodeID use for debug an dot generation.
protected:
/**
* @brief Constructor
* @param[in] _name Name of the node.
* @param[in] _config Configuration of the node.
*/
Node(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
/**
* @brief Destructor
*/
virtual ~Node();
/**
* @brief Get the status of this node acces on harware or acces on other node (virtual).
* @return true This is an harware interface.
* @return false this is a virtual interface.
*/
virtual bool isHarwareNode() {
return false;
};
protected:
mutable std11::mutex m_mutex; //!< prevent open/close/write/read access that is multi-threaded.
std11::shared_ptr<const ejson::Object> m_config; //!< configuration description.
protected:
drain::Process m_process; //!< Low level algorithms
public:
/**
* @brief Get the uper client interface configuration.
* @return process configuration.
*/
const drain::IOFormatInterface& getInterfaceFormat() {
if (m_isInput == true) {
return m_process.getOutputConfig();
} else {
return m_process.getInputConfig();
}
}
/**
* @brief Get the harware client interface configuration.
* @return process configuration.
*/
const drain::IOFormatInterface& getHarwareFormat() {
if (m_isInput == true) {
return m_process.getInputConfig();
} else {
return m_process.getOutputConfig();
}
}
protected:
std11::shared_ptr<drain::VolumeElement> m_volume; //!< if a volume is set it is set here ... for hardware interface only.
protected:
std::vector<std11::weak_ptr<river::Interface> > m_listAvaillable; //!< List of all interface that exist on this Node
std::vector<std11::shared_ptr<river::Interface> > m_list; //!< List of all connected interface at this node.
/**
* @brief Get the number of interface with a specific type.
* @param[in] _interfaceType Type of the interface.
* @return Number of interface connected.
*/
size_t getNumberOfInterface(enum river::modeInterface _interfaceType);
/**
* @brief Get the number of interface with a specific type that can connect on the Node.
* @param[in] _interfaceType Type of the interface.
* @return Number of interface that can connect.
*/
size_t getNumberOfInterfaceAvaillable(enum river::modeInterface _interfaceType);
public:
/**
* @brief Get the number of interface connected
* @return Number of interfaces.
*/
size_t getNumberOfInterface() {
return m_list.size();
}
public:
/**
* @brief Register an interface that can connect on it. (might be done in the Interface Init)
* @note We keep a std::weak_ptr. this is the reason why we do not have a remove.
* @param[in] _interface Pointer on the interface to register.
*/
void registerAsRemote(const std11::shared_ptr<river::Interface>& _interface);
/**
* @brief Request this interface might receve/send dat on the flow. (start/resume)
* @param[in] _interface Pointer on the interface to register.
*/
void interfaceAdd(const std11::shared_ptr<river::Interface>& _interface);
/**
* @brief Un-register the interface as an availlable read/write interface. (suspend/stop)
* @param[in] _interface Pointer on the interface to register.
*/
void interfaceRemove(const std11::shared_ptr<river::Interface>& _interface);
protected:
std::string m_name; //!< Name of the interface
public:
/**
* @brief Get the interface name.
* @return Current name.
*/
const std::string& getName() {
return m_name;
}
protected:
bool m_isInput; //!< sense of the stream
public:
/**
* @brief Check if it is an input stream
* @return true if it is an input/ false otherwise
*/
bool isInput() {
return m_isInput;
}
/**
* @brief Check if it is an output stream
* @return true if it is an output/ false otherwise
*/
bool isOutput() {
return !m_isInput;
}
protected:
std11::weak_ptr<river::io::Group> m_group; //!< reference on the group. If available.
public:
/**
* @brief Set this node in a low level group.
* @param[in] _group Group reference.
*/
void setGroup(std11::shared_ptr<river::io::Group> _group) {
m_group = _group;
}
protected:
/**
* @brief Start the flow in the group (start if no group)
*/
void startInGroup();
/**
* @brief Stop the flow in the group (stop if no group)
*/
void stopInGroup();
/**
* @brief Real start of the stream
*/
virtual void start() = 0;
/**
* @brief Real stop of the stream
*/
virtual void stop() = 0;
public:
/**
* @brief If this iss an hardware interface we can have a resuest of the volume stage:
* @return pointer on the requested volume.
*/
const std11::shared_ptr<drain::VolumeElement>& getVolume() {
return m_volume;
}
public:
/**
* @brief Called when a group wolume has been change to update all volume stage.
*/
void volumeChange();
protected:
/**
* @brief Call by child classes to process data in all interface linked on the current Node. Have new input to process.
* @param[in] _inputBuffer Pointer on the data.
* @param[in] _nbChunk Number of chunk in the buffer.
* @param[in] _time Time where the first sample has been capture.
*/
void newInput(const void* _inputBuffer,
uint32_t _nbChunk,
const std11::chrono::system_clock::time_point& _time);
/**
* @brief Call by child classes to process data in all interface linked on the current Node. Have new output to get. this call the feedback too.
* @param[in,out] _outputBuffer Pointer on the buffer to write the data.
* @param[in] _nbChunk Number of chunk to write in the buffer.
* @param[in] _time Time where the data might be played.
*/
void newOutput(void* _outputBuffer,
uint32_t _nbChunk,
const std11::chrono::system_clock::time_point& _time);
public:
/**
* @brief Generate the node dot file section
* @param[in] _node File node to generate the data.
*/
virtual void generateDot(etk::FSNode& _node);
};
}
}
#endif

View File

@ -1,108 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __RIVER_IO_NODE_AEC_H__
#define __RIVER_IO_NODE_AEC_H__
#include <river/io/Node.h>
#include <river/Interface.h>
#include <drain/CircularBuffer.h>
namespace river {
namespace io {
class Manager;
class NodeAEC : public Node {
protected:
/**
* @brief Constructor
*/
NodeAEC(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
/**
* @brief Factory of this Virtual Node.
* @param[in] _name Name of the node.
* @param[in] _config Configuration of the node.
*/
static std11::shared_ptr<NodeAEC> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
virtual ~NodeAEC();
protected:
virtual void start();
virtual void stop();
std11::shared_ptr<river::Interface> m_interfaceMicrophone; //!< Interface on the Microphone.
std11::shared_ptr<river::Interface> m_interfaceFeedBack; //!< Interface on the feedback of speaker.
/**
* @brief Internal: create an input with the specific parameter:
* @param[in] _freq Frequency.
* @param[in] _map Channel map organization.
* @param[in] _format Sample format
* @param[in] _streamName
* @param[in] _name
* @return Interfae Pointer.
*/
std11::shared_ptr<river::Interface> createInput(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName,
const std::string& _name);
/**
* @brief Stream data input callback
* @todo : copy doc ..
*/
void onDataReceivedMicrophone(const void* _data,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map);
/**
* @brief Stream data input callback
* @todo : copy doc ..
*/
void onDataReceivedFeedBack(const void* _data,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map);
protected:
drain::CircularBuffer m_bufferMicrophone; //!< temporary buffer to synchronize data.
drain::CircularBuffer m_bufferFeedBack; //!< temporary buffer to synchronize data.
std11::chrono::nanoseconds m_sampleTime; //!< represent the sample time at the specify frequency.
/**
* @brief Process synchronization on the 2 flow.
*/
void process();
/**
* @brief Process algorithm on the current 2 syncronize flow.
* @param[in] _dataMic Pointer in the Microphione interface.
* @param[in] _dataFB Pointer on the beedback buffer.
* @param[in] _nbChunk Number of chunk to process.
* @param[in] _time Time on the firsta sample that data has been captured.
* @return
*/
void processAEC(void* _dataMic, void* _dataFB, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time);
public:
virtual void generateDot(etk::FSNode& _node);
private:
int32_t m_nbChunk;
int32_t m_gainValue;
int32_t m_sampleCount;
int32_t m_P_attaqueTime; //ms
int32_t m_P_releaseTime; //ms
int32_t m_P_minimumGain; // %
int32_t m_P_threshold; // %
int32_t m_P_latencyTime; // ms
};
}
}
#endif

View File

@ -1,75 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __RIVER_IO_NODE_AIRTAUDIO_H__
#define __RIVER_IO_NODE_AIRTAUDIO_H__
#ifdef __AIRTAUDIO_INFERFACE__
#include <river/io/Node.h>
namespace river {
namespace io {
class Manager;
class Group;
/**
* @brief Low level node that is manage on the interface with the extern lib airtaudio
*/
class NodeAirTAudio : public river::io::Node {
friend class river::io::Group;
protected:
/**
* @brief Constructor
*/
NodeAirTAudio(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
static std11::shared_ptr<NodeAirTAudio> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
virtual ~NodeAirTAudio();
virtual bool isHarwareNode() {
return true;
};
protected:
airtaudio::Interface m_adac; //!< Real airtaudio interface
airtaudio::DeviceInfo m_info; //!< information on the stream.
unsigned int m_rtaudioFrameSize; // DEPRECATED soon...
public:
/**
* @brief Input Callback . Have recaive new data to process.
* @param[in] _inputBuffer Pointer on the data buffer.
* @param[in] _timeInput Time on the fist sample has been recorded.
* @param[in] _nbChunk Number of chunk in the buffer
* @param[in] _status DEPRECATED soon
* @return DEPRECATED soon
*/
int32_t recordCallback(const void* _inputBuffer,
const std11::chrono::system_clock::time_point& _timeInput,
uint32_t _nbChunk,
const std::vector<airtaudio::status>& _status);
/**
* @brief Playback callback. Request new data on output
* @param[in,out] _outputBuffer Pointer on the buffer to fill data.
* @param[in] _timeOutput Time on wich the data might be played.
* @param[in] _nbChunk Number of chunk in the buffer
* @param[in] _status DEPRECATED soon
* @return DEPRECATED soon
*/
int32_t playbackCallback(void* _outputBuffer,
const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk,
const std::vector<airtaudio::status>& _status);
protected:
virtual void start();
virtual void stop();
};
}
}
#endif
#endif

View File

@ -1,68 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __RIVER_IO_NODE_MUXER_H__
#define __RIVER_IO_NODE_MUXER_H__
#include <river/io/Node.h>
#include <river/Interface.h>
#include <drain/CircularBuffer.h>
namespace river {
namespace io {
class Manager;
class NodeMuxer : public Node {
protected:
/**
* @brief Constructor
*/
NodeMuxer(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
static std11::shared_ptr<NodeMuxer> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
virtual ~NodeMuxer();
protected:
virtual void start();
virtual void stop();
std11::shared_ptr<river::Interface> m_interfaceInput1;
std11::shared_ptr<river::Interface> m_interfaceInput2;
std11::shared_ptr<river::Interface> createInput(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName,
const std::string& _name);
void onDataReceivedInput1(const void* _data,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map);
void onDataReceivedInput2(const void* _data,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map);
std::vector<audio::channel> m_mapInput1;
std::vector<audio::channel> m_mapInput2;
drain::CircularBuffer m_bufferInput1;
drain::CircularBuffer m_bufferInput2;
std11::chrono::nanoseconds m_sampleTime; //!< represent the sample time at the specify frequency.
void process();
void processMuxer(void* _dataMic, void* _dataFB, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time);
std::vector<uint8_t> m_data;
public:
virtual void generateDot(etk::FSNode& _node);
private:
void reorder(void* _output, uint32_t _nbChunk, void* _input, const std::vector<audio::channel>& _mapInput);
};
}
}
#endif

View File

@ -1,53 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __RIVER_IO_NODE_PORTAUDIO_H__
#define __RIVER_IO_NODE_PORTAUDIO_H__
#ifdef __PORTAUDIO_INFERFACE__
#include <river/Interface.h>
#include <river/io/Node.h>
#include <portaudio.h>
namespace river {
namespace io {
class Manager;
//! @not-in-doc
class NodePortAudio : public Node {
protected:
/**
* @brief Constructor
*/
NodePortAudio(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
static std11::shared_ptr<NodePortAudio> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
virtual ~NodePortAudio();
virtual bool isHarwareNode() {
return true;
};
protected:
PaStream* m_stream;
public:
int32_t duplexCallback(const void* _inputBuffer,
const std11::chrono::system_clock::time_point& _timeInput,
void* _outputBuffer,
const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk,
PaStreamCallbackFlags _status);
protected:
virtual void start();
virtual void stop();
};
}
}
#endif
#endif

View File

@ -1,38 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#ifndef __RIVER_H__
#define __RIVER_H__
#include <etk/types.h>
namespace river {
/**
* @brief Initialize the River Library
* @param[in] _filename Name of the configuration file (if "" ==> default config file)
*/
void init(const std::string& _filename);
/**
* @brief Initialize the River Library with a json data string
* @param[in] _config json sting data
*/
void initString(const std::string& _config);
/**
* @brief Un-initialize the River Library
* @note this close all stream of all interfaces.
* @note really good for test.
*/
void unInit();
/**
* @brief Get the status of initialisation
* @return true River is init
* @return false River is NOT init
*/
bool isInit();
}
#endif

View File

@ -5,9 +5,9 @@
*/ */
#include "debug.h" #include "debug.h"
#include <river/river.h> #include <audio/river/river.h>
#include <river/Manager.h> #include <audio/river/Manager.h>
#include <river/Interface.h> #include <audio/river/Interface.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <etk/etk.h> #include <etk/etk.h>
#include <etk/os/FSNode.h> #include <etk/os/FSNode.h>
@ -29,7 +29,7 @@
#undef __class__ #undef __class__
#define __class__ "test" #define __class__ "test"
int main(int _argc, char** _argv) { int main(int _argc, const char** _argv) {
// init Google test : // init Google test :
::testing::InitGoogleTest(&_argc, const_cast<char **>(_argv)); ::testing::InitGoogleTest(&_argc, const_cast<char **>(_argv));
// the only one init for etk: // the only one init for etk:

View File

@ -14,12 +14,12 @@ namespace river_test_aec {
class Linker { class Linker {
private: private:
std11::shared_ptr<river::Manager> m_manager; std11::shared_ptr<audio::river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interfaceOut; std11::shared_ptr<audio::river::Interface> m_interfaceOut;
std11::shared_ptr<river::Interface> m_interfaceIn; std11::shared_ptr<audio::river::Interface> m_interfaceIn;
drain::CircularBuffer m_buffer; audio::drain::CircularBuffer m_buffer;
public: public:
Linker(std11::shared_ptr<river::Manager> _manager, const std::string& _input, const std::string& _output) : Linker(std11::shared_ptr<audio::river::Manager> _manager, const std::string& _input, const std::string& _output) :
m_manager(_manager) { m_manager(_manager) {
//Set stereo output: //Set stereo output:
std::vector<audio::channel> channelMap; std::vector<audio::channel> channelMap;
@ -199,9 +199,9 @@ namespace river_test_aec {
"}\n"; "}\n";
TEST(TestUser, testAECManually) { TEST(TestUser, testAECManually) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
std11::shared_ptr<Linker> processLink1 = std11::make_shared<Linker>(manager, "microphone-clean", "speaker"); std11::shared_ptr<Linker> processLink1 = std11::make_shared<Linker>(manager, "microphone-clean", "speaker");
std11::shared_ptr<Linker> processLink2 = std11::make_shared<Linker>(manager, "microphone", "speaker-test"); std11::shared_ptr<Linker> processLink2 = std11::make_shared<Linker>(manager, "microphone", "speaker-test");
processLink1->start(); processLink1->start();
@ -213,7 +213,7 @@ namespace river_test_aec {
processLink1.reset(); processLink1.reset();
processLink2.reset(); processLink2.reset();
manager.reset(); manager.reset();
river::unInit(); audio::river::unInit();
} }
}; };

View File

@ -7,7 +7,7 @@
#ifndef __RIVER_TEST_ECHO_DELAY_H__ #ifndef __RIVER_TEST_ECHO_DELAY_H__
#define __RIVER_TEST_ECHO_DELAY_H__ #define __RIVER_TEST_ECHO_DELAY_H__
#include <river/debug.h> #include <audio/river/debug.h>
#undef __class__ #undef __class__
#define __class__ "test_echo_delay" #define __class__ "test_echo_delay"
@ -15,10 +15,10 @@
namespace river_test_echo_delay { namespace river_test_echo_delay {
class TestClass { class TestClass {
private: private:
std11::shared_ptr<river::Manager> m_manager; std11::shared_ptr<audio::river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interfaceOut; std11::shared_ptr<audio::river::Interface> m_interfaceOut;
std11::shared_ptr<river::Interface> m_interfaceIn; std11::shared_ptr<audio::river::Interface> m_interfaceIn;
std11::shared_ptr<river::Interface> m_interfaceFB; std11::shared_ptr<audio::river::Interface> m_interfaceFB;
double m_phase; double m_phase;
double m_freq; double m_freq;
int32_t m_nextSampleCount; int32_t m_nextSampleCount;
@ -33,7 +33,7 @@ namespace river_test_echo_delay {
int16_t m_volumeInputMin; int16_t m_volumeInputMin;
float m_gain; float m_gain;
public: public:
TestClass(std11::shared_ptr<river::Manager> _manager) : TestClass(std11::shared_ptr<audio::river::Manager> _manager) :
m_manager(_manager), m_manager(_manager),
m_phase(0), m_phase(0),
m_freq(400), m_freq(400),
@ -417,14 +417,14 @@ namespace river_test_echo_delay {
"}\n"; "}\n";
TEST(TestTime, testDelay) { TEST(TestTime, testDelay) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
std11::shared_ptr<TestClass> process = std11::make_shared<TestClass>(manager); std11::shared_ptr<TestClass> process = std11::make_shared<TestClass>(manager);
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
}; };

View File

@ -28,15 +28,15 @@ namespace river_test_format {
"}\n"; "}\n";
class testOutCallbackType { class testOutCallbackType {
private: private:
std11::shared_ptr<river::Manager> m_manager; std11::shared_ptr<audio::river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface; std11::shared_ptr<audio::river::Interface> m_interface;
double m_phase; double m_phase;
float m_freq; float m_freq;
int32_t m_nbChannels; int32_t m_nbChannels;
float m_generateFreq; float m_generateFreq;
public: public:
testOutCallbackType(const std11::shared_ptr<river::Manager>& _manager, testOutCallbackType(const std11::shared_ptr<audio::river::Manager>& _manager,
float _freq=48000.0f, float _freq=48000.0f,
int32_t _nbChannels=2, int32_t _nbChannels=2,
audio::format _format=audio::format_int16) : audio::format _format=audio::format_int16) :
@ -150,14 +150,14 @@ namespace river_test_format {
class testResampling : public ::testing::TestWithParam<float> {}; class testResampling : public ::testing::TestWithParam<float> {};
TEST_P(testResampling, base) { TEST_P(testResampling, base) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, GetParam(), 2, audio::format_int16); std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, GetParam(), 2, audio::format_int16);
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
INSTANTIATE_TEST_CASE_P(InstantiationName, INSTANTIATE_TEST_CASE_P(InstantiationName,
@ -167,14 +167,14 @@ namespace river_test_format {
class testFormat : public ::testing::TestWithParam<audio::format> {}; class testFormat : public ::testing::TestWithParam<audio::format> {};
TEST_P(testFormat, base) { TEST_P(testFormat, base) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, 48000, 2, GetParam()); std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, 48000, 2, GetParam());
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
INSTANTIATE_TEST_CASE_P(InstantiationName, INSTANTIATE_TEST_CASE_P(InstantiationName,
testFormat, testFormat,
@ -183,14 +183,14 @@ namespace river_test_format {
class testChannels : public ::testing::TestWithParam<int32_t> {}; class testChannels : public ::testing::TestWithParam<int32_t> {};
TEST_P(testChannels, base) { TEST_P(testChannels, base) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, 48000, GetParam(), audio::format_int16); std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, 48000, GetParam(), audio::format_int16);
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
INSTANTIATE_TEST_CASE_P(InstantiationName, INSTANTIATE_TEST_CASE_P(InstantiationName,
testChannels, testChannels,
@ -198,9 +198,9 @@ namespace river_test_format {
TEST(TestALL, testChannelsFormatResampling) { TEST(TestALL, testChannelsFormatResampling) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
APPL_INFO("test convert flaot to output (callback mode)"); APPL_INFO("test convert flaot to output (callback mode)");
std::vector<float> listFreq; std::vector<float> listFreq;
listFreq.push_back(4000); listFreq.push_back(4000);
@ -235,7 +235,7 @@ namespace river_test_format {
} }
} }
} }
river::unInit(); audio::river::unInit();
} }

View File

@ -7,7 +7,7 @@
#ifndef __RIVER_TEST_MUXER_H__ #ifndef __RIVER_TEST_MUXER_H__
#define __RIVER_TEST_MUXER_H__ #define __RIVER_TEST_MUXER_H__
#include <river/debug.h> #include <audio/river/debug.h>
#undef __class__ #undef __class__
#define __class__ "test_muxer" #define __class__ "test_muxer"
@ -15,12 +15,12 @@
namespace river_test_muxer { namespace river_test_muxer {
class TestClass { class TestClass {
private: private:
std11::shared_ptr<river::Manager> m_manager; std11::shared_ptr<audio::river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interfaceIn; std11::shared_ptr<audio::river::Interface> m_interfaceIn;
std11::shared_ptr<river::Interface> m_interfaceOut; std11::shared_ptr<audio::river::Interface> m_interfaceOut;
double m_phase; double m_phase;
public: public:
TestClass(std11::shared_ptr<river::Manager> _manager) : TestClass(std11::shared_ptr<audio::river::Manager> _manager) :
m_manager(_manager), m_manager(_manager),
m_phase(0) { m_phase(0) {
std::vector<audio::channel> channelMap; std::vector<audio::channel> channelMap;
@ -167,14 +167,14 @@ namespace river_test_muxer {
"}\n"; "}\n";
TEST(TestMuxer, testMuxing) { TEST(TestMuxer, testMuxing) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
std11::shared_ptr<TestClass> process = std11::make_shared<TestClass>(manager); std11::shared_ptr<TestClass> process = std11::make_shared<TestClass>(manager);
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
}; };

View File

@ -14,11 +14,11 @@ namespace river_test_playback_callback {
class testOutCallback { class testOutCallback {
public: public:
std11::shared_ptr<river::Manager> m_manager; std11::shared_ptr<audio::river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface; std11::shared_ptr<audio::river::Interface> m_interface;
double m_phase; double m_phase;
public: public:
testOutCallback(std11::shared_ptr<river::Manager> _manager, const std::string& _io="speaker") : testOutCallback(std11::shared_ptr<audio::river::Manager> _manager, const std::string& _io="speaker") :
m_manager(_manager), m_manager(_manager),
m_phase(0) { m_phase(0) {
//Set stereo output: //Set stereo output:
@ -93,9 +93,9 @@ namespace river_test_playback_callback {
"}\n"; "}\n";
TEST(TestALL, testOutputCallBack) { TEST(TestALL, testOutputCallBack) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
APPL_INFO("test output (callback mode)"); APPL_INFO("test output (callback mode)");
std11::shared_ptr<testOutCallback> process = std11::make_shared<testOutCallback>(manager, "speaker"); std11::shared_ptr<testOutCallback> process = std11::make_shared<testOutCallback>(manager, "speaker");
@ -103,33 +103,33 @@ namespace river_test_playback_callback {
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
TEST(TestALL, testOutputCallBackPulse) { TEST(TestALL, testOutputCallBackPulse) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
APPL_INFO("test output (callback mode)"); APPL_INFO("test output (callback mode)");
std11::shared_ptr<testOutCallback> process = std11::make_shared<testOutCallback>(manager, "speaker-pulse"); std11::shared_ptr<testOutCallback> process = std11::make_shared<testOutCallback>(manager, "speaker-pulse");
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
TEST(TestALL, testOutputCallBackJack) { TEST(TestALL, testOutputCallBackJack) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
APPL_INFO("test output (callback mode)"); APPL_INFO("test output (callback mode)");
std11::shared_ptr<testOutCallback> process = std11::make_shared<testOutCallback>(manager, "speaker-jack"); std11::shared_ptr<testOutCallback> process = std11::make_shared<testOutCallback>(manager, "speaker-jack");
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }

View File

@ -30,10 +30,10 @@ namespace river_test_playback_write {
class testOutWrite { class testOutWrite {
public: public:
std::vector<audio::channel> m_channelMap; std::vector<audio::channel> m_channelMap;
std11::shared_ptr<river::Manager> m_manager; std11::shared_ptr<audio::river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface; std11::shared_ptr<audio::river::Interface> m_interface;
public: public:
testOutWrite(std11::shared_ptr<river::Manager> _manager) : testOutWrite(std11::shared_ptr<audio::river::Manager> _manager) :
m_manager(_manager) { m_manager(_manager) {
//Set stereo output: //Set stereo output:
m_channelMap.push_back(audio::channel_frontLeft); m_channelMap.push_back(audio::channel_frontLeft);
@ -90,25 +90,25 @@ namespace river_test_playback_write {
}; };
TEST(TestALL, testOutputWrite) { TEST(TestALL, testOutputWrite) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
APPL_INFO("test output (write mode)"); APPL_INFO("test output (write mode)");
std11::shared_ptr<testOutWrite> process = std11::make_shared<testOutWrite>(manager); std11::shared_ptr<testOutWrite> process = std11::make_shared<testOutWrite>(manager);
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
class testOutWriteCallback { class testOutWriteCallback {
public: public:
std11::shared_ptr<river::Manager> m_manager; std11::shared_ptr<audio::river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface; std11::shared_ptr<audio::river::Interface> m_interface;
double m_phase; double m_phase;
public: public:
testOutWriteCallback(std11::shared_ptr<river::Manager> _manager) : testOutWriteCallback(std11::shared_ptr<audio::river::Manager> _manager) :
m_manager(_manager), m_manager(_manager),
m_phase(0) { m_phase(0) {
std::vector<audio::channel> channelMap; std::vector<audio::channel> channelMap;
@ -167,16 +167,16 @@ namespace river_test_playback_write {
}; };
TEST(TestALL, testOutputWriteWithCallback) { TEST(TestALL, testOutputWriteWithCallback) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
APPL_INFO("test output (write with callback event mode)"); APPL_INFO("test output (write with callback event mode)");
std11::shared_ptr<testOutWriteCallback> process = std11::make_shared<testOutWriteCallback>(manager); std11::shared_ptr<testOutWriteCallback> process = std11::make_shared<testOutWriteCallback>(manager);
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
}; };

View File

@ -7,7 +7,7 @@
#ifndef __RIVER_TEST_RECORD_CALLBACK_H__ #ifndef __RIVER_TEST_RECORD_CALLBACK_H__
#define __RIVER_TEST_RECORD_CALLBACK_H__ #define __RIVER_TEST_RECORD_CALLBACK_H__
#include <river/debug.h> #include <audio/river/debug.h>
#undef __class__ #undef __class__
#define __class__ "test_record_callback" #define __class__ "test_record_callback"
@ -30,10 +30,10 @@ namespace river_test_record_callback {
class testInCallback { class testInCallback {
public: public:
std11::shared_ptr<river::Manager> m_manager; std11::shared_ptr<audio::river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface; std11::shared_ptr<audio::river::Interface> m_interface;
public: public:
testInCallback(std11::shared_ptr<river::Manager> _manager, const std::string& _input="microphone") : testInCallback(std11::shared_ptr<audio::river::Manager> _manager, const std::string& _input="microphone") :
m_manager(_manager) { m_manager(_manager) {
//Set stereo output: //Set stereo output:
std::vector<audio::channel> channelMap; std::vector<audio::channel> channelMap;
@ -86,15 +86,15 @@ namespace river_test_record_callback {
}; };
TEST(TestALL, testInputCallBack) { TEST(TestALL, testInputCallBack) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
APPL_INFO("test input (callback mode)"); APPL_INFO("test input (callback mode)");
std11::shared_ptr<testInCallback> process = std11::make_shared<testInCallback>(manager); std11::shared_ptr<testInCallback> process = std11::make_shared<testInCallback>(manager);
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
}; };

View File

@ -29,11 +29,11 @@ namespace river_test_volume {
class testCallbackVolume { class testCallbackVolume {
private: private:
std11::shared_ptr<river::Manager> m_manager; std11::shared_ptr<audio::river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface; std11::shared_ptr<audio::river::Interface> m_interface;
double m_phase; double m_phase;
public: public:
testCallbackVolume(std11::shared_ptr<river::Manager> _manager) : testCallbackVolume(std11::shared_ptr<audio::river::Manager> _manager) :
m_manager(_manager), m_manager(_manager),
m_phase(0) { m_phase(0) {
//Set stereo output: //Set stereo output:
@ -123,14 +123,14 @@ namespace river_test_volume {
}; };
TEST(TestALL, testVolume) { TEST(TestALL, testVolume) {
river::initString(configurationRiver); audio::river::initString(configurationRiver);
std11::shared_ptr<river::Manager> manager; std11::shared_ptr<audio::river::Manager> manager;
manager = river::Manager::create("testApplication"); manager = audio::river::Manager::create("testApplication");
std11::shared_ptr<testCallbackVolume> process = std11::make_shared<testCallbackVolume>(manager); std11::shared_ptr<testCallbackVolume> process = std11::make_shared<testCallbackVolume>(manager);
process->run(); process->run();
process.reset(); process.reset();
usleep(500000); usleep(500000);
river::unInit(); audio::river::unInit();
} }
}; };