[DEV] WORK on a port for BOOST

This commit is contained in:
Edouard DUPIN 2015-02-24 22:20:11 +01:00
parent 62cb1ef639
commit 0b50032cab
17 changed files with 436 additions and 381 deletions

View File

@ -67,7 +67,7 @@ void river::CircularBuffer::setCapacity(size_t _capacity, size_t _chunkSize, uin
m_write = &m_data[0];
}
void river::CircularBuffer::setCapacity(std::chrono::milliseconds _capacity, size_t _chunkSize, uint32_t _frequency) {
void river::CircularBuffer::setCapacity(std11::chrono::milliseconds _capacity, size_t _chunkSize, uint32_t _frequency) {
uint32_t nbSampleNeeded = _frequency*_capacity.count()/1000;
RIVER_DEBUG("buffer setCapacity(" << _capacity.count() << "ms ," << _chunkSize << ")");
setCapacity(nbSampleNeeded, _chunkSize, _frequency);
@ -102,7 +102,7 @@ size_t river::CircularBuffer::getFreeSizeBeforEnd() const {
return size;
}
size_t river::CircularBuffer::write(const void* _data, size_t _nbChunk, const std::chrono::system_clock::time_point& _time) {
size_t river::CircularBuffer::write(const void* _data, size_t _nbChunk, const std11::chrono::system_clock::time_point& _time) {
size_t nbElementDrop = 0;
size_t freeSizeBeforeEnd = getFreeSizeBeforEnd();
size_t freeSize = m_capacity - m_size;
@ -168,14 +168,14 @@ size_t river::CircularBuffer::read(void* _data, size_t _nbChunk) {
return read(_data, _nbChunk, m_timeRead);
}
size_t river::CircularBuffer::read(void* _data, size_t _nbChunk, const std::chrono::system_clock::time_point& _time) {
size_t river::CircularBuffer::read(void* _data, size_t _nbChunk, const std11::chrono::system_clock::time_point& _time) {
size_t nbElementDrop = 0;
// Critical section (theoriquely protected by Mutex)
size_t usedSizeBeforeEnd = getUsedSizeBeforEnd();
// verify if we have elements in the Buffer
if (0 < m_size) {
// check the time of the read :
std::chrono::nanoseconds deltaTime = m_timeRead - _time;
std11::chrono::nanoseconds deltaTime = m_timeRead - _time;
if (deltaTime.count() == 0) {
// nothing to do ==> just copy data ...
} else if (deltaTime.count() > 0) {
@ -196,7 +196,7 @@ size_t river::CircularBuffer::read(void* _data, size_t _nbChunk, const std::chro
nbElementDrop = _nbChunk - m_size;
_nbChunk = m_size;
}
m_timeRead += std::chrono::microseconds(_nbChunk*1000000/m_frequency);
m_timeRead += std11::chrono::microseconds(_nbChunk*1000000/m_frequency);
if (usedSizeBeforeEnd >= _nbChunk) {
// all Data will be copy
memcpy(_data, m_read, _nbChunk * m_sizeChunk);
@ -234,16 +234,16 @@ size_t river::CircularBuffer::read(void* _data, size_t _nbChunk, const std::chro
// return the number of element droped
return nbElementDrop;
}
void river::CircularBuffer::setReadPosition(const std::chrono::system_clock::time_point& _time) {
void river::CircularBuffer::setReadPosition(const std11::chrono::system_clock::time_point& _time) {
// Critical section (theoriquely protected by Mutex)
size_t usedSizeBeforeEnd = getUsedSizeBeforEnd();
if (0 < m_size) {
// check the time of the read :
std::chrono::nanoseconds deltaTime = _time - m_timeRead;
std11::chrono::nanoseconds deltaTime = _time - m_timeRead;
size_t nbSampleToRemove = m_frequency*deltaTime.count()/1000000000;
nbSampleToRemove = std::min(nbSampleToRemove, m_size);
RIVER_WARNING("Remove sample in the buffer " << nbSampleToRemove << " / " << m_size);
std::chrono::nanoseconds updateTime((nbSampleToRemove*1000000000)/int64_t(m_frequency));
std11::chrono::nanoseconds updateTime((nbSampleToRemove*1000000000)/int64_t(m_frequency));
if (usedSizeBeforeEnd >= nbSampleToRemove) {
usedSizeBeforeEnd -= nbSampleToRemove;
m_size -= nbSampleToRemove;
@ -256,7 +256,7 @@ void river::CircularBuffer::setReadPosition(const std::chrono::system_clock::tim
m_timeRead += updateTime;
//m_timeRead += deltaTime;
} else {
m_timeRead = std::chrono::system_clock::time_point();
m_timeRead = std11::chrono::system_clock::time_point();
}
}

View File

@ -10,7 +10,11 @@
#include <etk/types.h>
#include <vector>
#include <chrono>
#if __cplusplus >= 201103L
#include <chrono>
#else
#include <etk/chrono.h>
#endif
namespace river {
/**
@ -43,7 +47,7 @@ namespace river {
std::vector<uint8_t> m_data; //!< data pointer
void* m_write; //!< write pointer
void* m_read; //!< read pointer
std::chrono::system_clock::time_point m_timeRead; //!< current read time
std11::chrono::system_clock::time_point m_timeRead; //!< current read time
uint32_t m_frequency;
// TODO : Remove the m_size ==> this is a bad element to be mutex-less
size_t m_size; //!< number of chunk availlable in this buffer
@ -75,7 +79,7 @@ namespace river {
* @param[in] _chunkSize Size of one chunk.
* @param[in] _frequency Frequency of the buffer
*/
void setCapacity(std::chrono::milliseconds _capacity, size_t _chunkSize, uint32_t _frequency);
void setCapacity(std11::chrono::milliseconds _capacity, size_t _chunkSize, uint32_t _frequency);
/**
* @brief get free size of the buffer.
* @return Number of free chunk.
@ -102,7 +106,7 @@ namespace river {
* @param[in] _time Time to start write data (if before end ==> not replace data, write only if after end)
* @return Number of chunk copied.
*/
size_t write(const void* _data, size_t _nbChunk, const std::chrono::system_clock::time_point& _time);
size_t write(const void* _data, size_t _nbChunk, const std11::chrono::system_clock::time_point& _time);
/**
* @brief Read Chunk from the buffer to the pointer data.
* @param[out] _data Pointer on the data.
@ -110,12 +114,12 @@ namespace river {
* @param[in] _time Time to start read data (if before start ==> add 0 at start, if after, remove unread data)
* @return Number of chunk copied.
*/
size_t read(void* _data, size_t _nbChunk, const std::chrono::system_clock::time_point& _time);
size_t read(void* _data, size_t _nbChunk, const std11::chrono::system_clock::time_point& _time);
//! @previous
size_t read(void* _data, size_t _nbChunk);
void setReadPosition(const std::chrono::system_clock::time_point& _time);
void setReadPosition(const std11::chrono::system_clock::time_point& _time);
std::chrono::system_clock::time_point getReadTimeStamp() {
std11::chrono::system_clock::time_point getReadTimeStamp() {
return m_timeRead;
}
/**

View File

@ -17,7 +17,7 @@
#define __class__ "Interface"
river::Interface::Interface(void) :
m_node(nullptr),
m_node(),
m_name(""),
m_volume(0.0f) {
static uint32_t uid = 0;
@ -29,8 +29,8 @@ bool river::Interface::init(const std::string& _name,
float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::shared_ptr<river::io::Node>& _node,
const std::shared_ptr<const ejson::Object>& _config) {
const std11::shared_ptr<river::io::Node>& _node,
const std11::shared_ptr<const ejson::Object>& _config) {
m_name = _name;
m_node = _node;
m_volume = 0.0f;
@ -51,12 +51,12 @@ bool river::Interface::init(const std::string& _name,
&& m_mode == river::modeInterface_input) {
m_process.setInputConfig(m_node->getInterfaceFormat());
// add all time the volume stage :
std::shared_ptr<drain::Volume> algo = drain::Volume::create();
std11::shared_ptr<drain::Volume> algo = drain::Volume::create();
//algo->setInputFormat(m_node->getInterfaceFormat());
algo->setName("volume");
m_process.pushBack(algo);
RIVER_INFO("add basic volume stage (1)");
std::shared_ptr<drain::VolumeElement> tmpVolume = m_node->getVolume();
std11::shared_ptr<drain::VolumeElement> tmpVolume = m_node->getVolume();
if (tmpVolume != nullptr) {
RIVER_INFO(" add volume for node");
algo->addVolumeStage(tmpVolume);
@ -66,12 +66,12 @@ bool river::Interface::init(const std::string& _name,
&& m_mode == river::modeInterface_output) {
m_process.setInputConfig(drain::IOFormatInterface(_map, _format, _freq));
// add all time the volume stage :
std::shared_ptr<drain::Volume> algo = drain::Volume::create();
std11::shared_ptr<drain::Volume> algo = drain::Volume::create();
//algo->setOutputFormat(m_node->getInterfaceFormat());
algo->setName("volume");
m_process.pushBack(algo);
RIVER_INFO("add basic volume stage (2)");
std::shared_ptr<drain::VolumeElement> tmpVolume = m_node->getVolume();
std11::shared_ptr<drain::VolumeElement> tmpVolume = m_node->getVolume();
if (tmpVolume != nullptr) {
RIVER_INFO(" add volume for node");
algo->addVolumeStage(tmpVolume);
@ -81,7 +81,7 @@ bool river::Interface::init(const std::string& _name,
&& m_mode == river::modeInterface_feedback) {
m_process.setInputConfig(m_node->getHarwareFormat());
// add all time the volume stage :
std::shared_ptr<drain::Volume> algo = drain::Volume::create();
std11::shared_ptr<drain::Volume> algo = drain::Volume::create();
//algo->setInputFormat(m_node->getInterfaceFormat());
algo->setName("volume");
m_process.pushBack(algo);
@ -94,20 +94,20 @@ bool river::Interface::init(const std::string& _name,
return true;
}
std::shared_ptr<river::Interface> river::Interface::create(const std::string& _name,
std11::shared_ptr<river::Interface> river::Interface::create(const std::string& _name,
float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::shared_ptr<river::io::Node>& _node,
const std::shared_ptr<const ejson::Object>& _config) {
std::shared_ptr<river::Interface> out = std::shared_ptr<river::Interface>(new river::Interface());
const std11::shared_ptr<river::io::Node>& _node,
const std11::shared_ptr<const ejson::Object>& _config) {
std11::shared_ptr<river::Interface> out = std11::shared_ptr<river::Interface>(new river::Interface());
out->init(_name, _freq, _map, _format, _node, _config);
return out;
}
river::Interface::~Interface() {
//stop(true, true);
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
//m_node->interfaceRemove(shared_from_this());
}
/*
@ -116,7 +116,7 @@ bool river::Interface::hasEndPoint() {
}
*/
void river::Interface::setReadwrite() {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.removeAlgoDynamic();
if (m_process.hasType<drain::EndPoint>() ) {
RIVER_ERROR("Endpoint is already present ==> can not change");
@ -124,43 +124,43 @@ void river::Interface::setReadwrite() {
}
if (m_node->isInput() == true) {
m_process.removeIfLast<drain::EndPoint>();
std::shared_ptr<drain::EndPointRead> algo = drain::EndPointRead::create();
std11::shared_ptr<drain::EndPointRead> algo = drain::EndPointRead::create();
m_process.pushBack(algo);
} else {
m_process.removeIfFirst<drain::EndPoint>();
std::shared_ptr<drain::EndPointWrite> algo = drain::EndPointWrite::create();
std11::shared_ptr<drain::EndPointWrite> algo = drain::EndPointWrite::create();
m_process.pushFront(algo);
}
}
void river::Interface::setOutputCallback(drain::playbackFunction _function) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.removeAlgoDynamic();
m_process.removeIfFirst<drain::EndPoint>();
std::shared_ptr<drain::Algo> algo = drain::EndPointCallback::create(_function);
std11::shared_ptr<drain::Algo> algo = drain::EndPointCallback::create(_function);
m_process.pushFront(algo);
}
void river::Interface::setInputCallback(drain::recordFunction _function) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.removeAlgoDynamic();
m_process.removeIfLast<drain::EndPoint>();
std::shared_ptr<drain::Algo> algo = drain::EndPointCallback::create(_function);
std11::shared_ptr<drain::Algo> algo = drain::EndPointCallback::create(_function);
m_process.pushBack(algo);
}
void river::Interface::setWriteCallback(drain::playbackFunctionWrite _function) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.removeAlgoDynamic();
std::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0);
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0);
if (algo == nullptr) {
return;
}
algo->setCallback(_function);
}
void river::Interface::start(const std::chrono::system_clock::time_point& _time) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
void river::Interface::start(const std11::chrono::system_clock::time_point& _time) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
RIVER_DEBUG("start [BEGIN]");
m_process.updateInterAlgo();
m_node->interfaceAdd(shared_from_this());
@ -168,14 +168,14 @@ void river::Interface::start(const std::chrono::system_clock::time_point& _time)
}
void river::Interface::stop(bool _fast, bool _abort) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
RIVER_DEBUG("stop [BEGIN]");
m_node->interfaceRemove(shared_from_this());
RIVER_DEBUG("stop [ END]");
}
void river::Interface::abort() {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
RIVER_DEBUG("abort [BEGIN]");
// TODO :...
RIVER_DEBUG("abort [ END ]");
@ -189,7 +189,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");
return false;
}
std::shared_ptr<drain::Algo> algo = m_process.get<drain::Algo>(_filter);
std11::shared_ptr<drain::Algo> algo = m_process.get<drain::Algo>(_filter);
if (algo == nullptr) {
RIVER_ERROR("setParameter(" << _filter << ") ==> no filter named like this ...");
return false;
@ -201,7 +201,7 @@ bool river::Interface::setParameter(const std::string& _filter, const std::strin
std::string river::Interface::getParameter(const std::string& _filter, const std::string& _parameter) const {
RIVER_DEBUG("getParameter [BEGIN] : '" << _filter << "':'" << _parameter << "'");
std::string out;
std::shared_ptr<const drain::Algo> algo = m_process.get<const drain::Algo>(_filter);
std11::shared_ptr<const drain::Algo> algo = m_process.get<const drain::Algo>(_filter);
if (algo == nullptr) {
RIVER_ERROR("setParameter(" << _filter << ") ==> no filter named like this ...");
return "[ERROR]";
@ -213,7 +213,7 @@ std::string river::Interface::getParameter(const std::string& _filter, const std
std::string river::Interface::getParameterProperty(const std::string& _filter, const std::string& _parameter) const {
RIVER_DEBUG("getParameterProperty [BEGIN] : '" << _filter << "':'" << _parameter << "'");
std::string out;
std::shared_ptr<const drain::Algo> algo = m_process.get<const drain::Algo>(_filter);
std11::shared_ptr<const drain::Algo> algo = m_process.get<const drain::Algo>(_filter);
if (algo == nullptr) {
RIVER_ERROR("setParameter(" << _filter << ") ==> no filter named like this ...");
return "[ERROR]";
@ -224,9 +224,9 @@ std::string river::Interface::getParameterProperty(const std::string& _filter, c
}
void river::Interface::write(const void* _value, size_t _nbChunk) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.updateInterAlgo();
std::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0);
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0);
if (algo == nullptr) {
return;
}
@ -259,78 +259,78 @@ std::vector<int16_t> river::Interface::read(size_t _nbChunk) {
#endif
void river::Interface::read(void* _value, size_t _nbChunk) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.updateInterAlgo();
// TODO :...
}
size_t river::Interface::size() const {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
// TODO :...
return 0;
}
void river::Interface::setBufferSize(size_t _nbChunk) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.updateInterAlgo();
// TODO :...
}
void river::Interface::setBufferSize(const std::chrono::duration<int64_t, std::micro>& _time) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
void river::Interface::setBufferSize(const std11::chrono::microseconds& _time) {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.updateInterAlgo();
// TODO :...
}
void river::Interface::clearInternalBuffer() {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
m_process.updateInterAlgo();
// TODO :...
}
std::chrono::system_clock::time_point river::Interface::getCurrentTime() const {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::chrono::system_clock::time_point river::Interface::getCurrentTime() const {
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
// TODO :...
return std::chrono::system_clock::time_point();
return std::chrono::system_clock::now();
return std11::chrono::system_clock::time_point();
return std11::chrono::system_clock::now();
}
void river::Interface::addVolumeGroup(const std::string& _name) {
std::unique_lock<std::recursive_mutex> lock(m_mutex);
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
RIVER_DEBUG("addVolumeGroup(" << _name << ")");
std::shared_ptr<drain::Volume> algo = m_process.get<drain::Volume>("volume");
std11::shared_ptr<drain::Volume> algo = m_process.get<drain::Volume>("volume");
if (algo == nullptr) {
RIVER_ERROR("addVolumeGroup(" << _name << ") ==> no volume stage ... can not add it ...");
return;
}
if (_name == "FLOW") {
// Local volume name
algo->addVolumeStage(std::make_shared<drain::VolumeElement>(_name));
algo->addVolumeStage(std11::make_shared<drain::VolumeElement>(_name));
} else {
// get manager unique instance:
std::shared_ptr<river::io::Manager> mng = river::io::Manager::getInstance();
std11::shared_ptr<river::io::Manager> mng = river::io::Manager::getInstance();
algo->addVolumeStage(mng->getVolumeGroup(_name));
}
}
void river::Interface::systemNewInputData(std::chrono::system_clock::time_point _time, const void* _data, size_t _nbChunk) {
std::unique_lock<std::recursive_mutex> lockProcess(m_mutex);
void 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);
void * tmpData = const_cast<void*>(_data);
m_process.push(_time, tmpData, _nbChunk);
}
void river::Interface::systemNeedOutputData(std::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize) {
std::unique_lock<std::recursive_mutex> lockProcess(m_mutex);
void 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);
m_process.pull(_time, _data, _nbChunk, _chunkSize);
}
void river::Interface::systemVolumeChange() {
std::unique_lock<std::recursive_mutex> lockProcess(m_mutex);
std::shared_ptr<drain::Volume> algo = m_process.get<drain::Volume>("volume");
std11::unique_lock<std11::recursive_mutex> lockProcess(m_mutex);
std11::shared_ptr<drain::Volume> algo = m_process.get<drain::Volume>("volume");
if (algo == nullptr) {
return;
}

View File

@ -10,15 +10,22 @@
#include <string>
#include <vector>
#include <stdint.h>
#include <chrono>
#include <functional>
#include <mutex>
#if __cplusplus >= 201103L
#include <mutex>
#include <chrono>
#include <functional>
#include <memory>
#else
#include <etk/mutex.h>
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#endif
#include <audio/format.h>
#include <audio/channel.h>
#include <drain/Process.h>
#include <drain/EndPointCallback.h>
#include <drain/EndPointWrite.h>
#include <memory>
#include <ejson/ejson.h>
#include <etk/os/FSNode.h>
@ -34,7 +41,7 @@ namespace river {
modeInterface_output,
modeInterface_feedback,
};
class Interface : public std::enable_shared_from_this<Interface> {
class Interface : public std11::enable_shared_from_this<Interface> {
friend class io::Node;
friend class io::NodeAirTAudio;
friend class io::NodeAEC;
@ -50,23 +57,23 @@ namespace river {
float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::shared_ptr<river::io::Node>& _node,
const std::shared_ptr<const ejson::Object>& _config);
const std11::shared_ptr<river::io::Node>& _node,
const std11::shared_ptr<const ejson::Object>& _config);
public:
/**
* @brief Destructor
*/
virtual ~Interface();
static std::shared_ptr<Interface> create(const std::string& _name,
static std11::shared_ptr<Interface> create(const std::string& _name,
float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::shared_ptr<river::io::Node>& _node,
const std::shared_ptr<const ejson::Object>& _config);
const std11::shared_ptr<river::io::Node>& _node,
const std11::shared_ptr<const ejson::Object>& _config);
protected:
mutable std::recursive_mutex m_mutex;
std::shared_ptr<const ejson::Object> m_config;
mutable std11::recursive_mutex m_mutex;
std11::shared_ptr<const ejson::Object> m_config;
protected:
enum modeInterface m_mode;
public:
@ -85,7 +92,7 @@ namespace river {
}
protected:
std::shared_ptr<river::io::Node> m_node;
std11::shared_ptr<river::io::Node> m_node;
protected:
std::string m_name;
public:
@ -122,7 +129,7 @@ namespace river {
* @note _time to play buffer when output interface (if possible)
* @note _time to read buffer when inut interface (if possible)
*/
virtual void start(const std::chrono::system_clock::time_point& _time = std::chrono::system_clock::time_point());
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.
@ -190,7 +197,7 @@ namespace river {
* @brief Set buffer size in chunk number
* @param[in] _nbChunk Number of chunk in the buffer
*/
virtual void setBufferSize(const std::chrono::duration<int64_t, std::micro>& _time);
virtual void setBufferSize(const std11::chrono::microseconds& _time);
/**
* @brief Remove internal Buffer
*/
@ -199,10 +206,10 @@ namespace river {
* @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 std::chrono::system_clock::time_point getCurrentTime() const;
virtual std11::chrono::system_clock::time_point getCurrentTime() const;
private:
virtual void systemNewInputData(std::chrono::system_clock::time_point _time, const void* _data, size_t _nbChunk);
virtual void systemNeedOutputData(std::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize);
virtual void systemNewInputData(std11::chrono::system_clock::time_point _time, const void* _data, size_t _nbChunk);
virtual void systemNeedOutputData(std11::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize);
virtual void systemVolumeChange();
float m_volume; //!< Local channel Volume
public:

View File

@ -6,7 +6,6 @@
#include "Manager.h"
#include "Interface.h"
#include <memory>
#include <stdexcept>
#include "io/Manager.h"
@ -33,8 +32,8 @@ static std::string basicAutoConfig =
"}\n";
std::shared_ptr<river::Manager> river::Manager::create(const std::string& _applicationUniqueId) {
return std::shared_ptr<river::Manager>(new river::Manager(_applicationUniqueId));
std11::shared_ptr<river::Manager> river::Manager::create(const std::string& _applicationUniqueId) {
return std11::shared_ptr<river::Manager>(new river::Manager(_applicationUniqueId));
}
river::Manager::Manager(const std::string& _applicationUniqueId) :
@ -54,13 +53,14 @@ river::Manager::~Manager() {
std::vector<std::pair<std::string,std::string> > river::Manager::getListStreamInput() {
std::vector<std::pair<std::string,std::string> > output;
for (auto &it : m_config.getKeys()) {
const std::shared_ptr<const ejson::Object> tmppp = m_config.getObject(it);
std::vector<std::string> keys = m_config.getKeys();
for (size_t iii=0; iii<keys.size(); ++iii) {
const std11::shared_ptr<const ejson::Object> tmppp = m_config.getObject(keys[iii]);
if (tmppp != nullptr) {
std::string type = tmppp->getStringValue("io", "error");
if ( type == "input"
|| type == "feedback") {
output.push_back(std::make_pair<std::string,std::string>(std::string(it), std::string("---")));
output.push_back(std::make_pair<std::string,std::string>(keys[iii], std::string("---")));
}
}
}
@ -69,12 +69,13 @@ std::vector<std::pair<std::string,std::string> > river::Manager::getListStreamIn
std::vector<std::pair<std::string,std::string> > river::Manager::getListStreamOutput() {
std::vector<std::pair<std::string,std::string> > output;
for (auto &it : m_config.getKeys()) {
const std::shared_ptr<const ejson::Object> tmppp = m_config.getObject(it);
std::vector<std::string> keys = m_config.getKeys();
for (size_t iii=0; iii<keys.size(); ++iii) {
const std11::shared_ptr<const ejson::Object> tmppp = m_config.getObject(keys[iii]);
if (tmppp != nullptr) {
std::string type = tmppp->getStringValue("io", "error");
if (type == "output") {
output.push_back(std::make_pair<std::string,std::string>(std::string(it), std::string("---")));
output.push_back(std::make_pair<std::string,std::string>(keys[iii], std::string("---")));
}
}
}
@ -94,60 +95,60 @@ std::pair<float,float> river::Manager::getVolumeRange(const std::string& _volume
return river::io::Manager::getInstance()->getVolumeRange(_volumeName);
}
std::shared_ptr<river::Interface> river::Manager::createOutput(float _freq,
std11::shared_ptr<river::Interface> river::Manager::createOutput(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName,
const std::string& _name) {
// check if the output exist
const std::shared_ptr<const ejson::Object> tmppp = m_config.getObject(_streamName);
const std11::shared_ptr<const ejson::Object> tmppp = m_config.getObject(_streamName);
if (tmppp == nullptr) {
RIVER_ERROR("can not open a non existance virtual input: '" << _streamName << "' not present in : " << m_config.getKeys());
return nullptr;
return std11::shared_ptr<river::Interface>();
}
// check if it is an Output:
std::string type = tmppp->getStringValue("io", "error");
if (type != "output") {
RIVER_ERROR("can not open in output a virtual interface: '" << _streamName << "' configured has : " << type);
return nullptr;
return std11::shared_ptr<river::Interface>();
}
// get global hardware interface:
std::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
// get the output or input channel :
std::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
// create user iterface:
std::shared_ptr<river::Interface> interface;
std11::shared_ptr<river::Interface> interface;
interface = river::Interface::create(_name, _freq, _map, _format, node, tmppp);
// store it in a list (needed to apply some parameters).
m_listOpenInterface.push_back(interface);
return interface;
}
std::shared_ptr<river::Interface> river::Manager::createInput(float _freq,
std11::shared_ptr<river::Interface> river::Manager::createInput(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName,
const std::string& _name) {
// check if the output exist
const std::shared_ptr<const ejson::Object> tmppp = m_config.getObject(_streamName);
const std11::shared_ptr<const ejson::Object> tmppp = m_config.getObject(_streamName);
if (tmppp == nullptr) {
RIVER_ERROR("can not open a non existance virtual interface: '" << _streamName << "' not present in : " << m_config.getKeys());
return nullptr;
return std11::shared_ptr<river::Interface>();
}
// check if it is an Output:
std::string type = tmppp->getStringValue("io", "error");
if ( type != "input"
&& type != "feedback") {
RIVER_ERROR("can not open in output a virtual interface: '" << _streamName << "' configured has : " << type);
return nullptr;
return std11::shared_ptr<river::Interface>();
}
// get global hardware interface:
std::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
// get the output or input channel :
std::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
// create user iterface:
std::shared_ptr<river::Interface> interface;
std11::shared_ptr<river::Interface> interface;
interface = river::Interface::create(_name, _freq, _map, _format, node, tmppp);
// store it in a list (needed to apply some parameters).
m_listOpenInterface.push_back(interface);
@ -156,7 +157,7 @@ std::shared_ptr<river::Interface> river::Manager::createInput(float _freq,
void river::Manager::generateDotAll(const std::string& _filename) {
// get global hardware interface:
std::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
if (manager == nullptr) {
RIVER_ERROR("Can not get the harware manager");
return;

View File

@ -9,7 +9,11 @@
#include <string>
#include <stdint.h>
#include <memory>
#if __cplusplus >= 201103L
#include <memory>
#else
#include <etk/memory.h>
#endif
#include <river/Interface.h>
#include <audio/format.h>
#include <audio/channel.h>
@ -23,14 +27,14 @@ namespace river {
private:
ejson::Document m_config; // virtual configuration
const std::string& m_applicationUniqueId; //!< name of the application that open the Audio Interface.
std::vector<std::weak_ptr<river::Interface> > m_listOpenInterface; //!< List of all open Stream.
std::vector<std11::weak_ptr<river::Interface> > m_listOpenInterface; //!< List of all open Stream.
protected:
/**
* @brief Constructor
*/
Manager(const std::string& _applicationUniqueId);
public:
static std::shared_ptr<river::Manager> create(const std::string& _applicationUniqueId);
static std11::shared_ptr<river::Manager> create(const std::string& _applicationUniqueId);
/**
* @brief Destructor
*/
@ -80,7 +84,7 @@ namespace river {
* @param[in] _name Name of this interface
* @return a pointer on the interface
*/
virtual std::shared_ptr<Interface> createOutput(float _freq,
virtual std11::shared_ptr<Interface> createOutput(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName = "",
@ -94,7 +98,7 @@ namespace river {
* @param[in] _name Name of this interface
* @return a pointer on the interface
*/
virtual std::shared_ptr<Interface> createInput(float _freq,
virtual std11::shared_ptr<Interface> createInput(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _streamName = "",

View File

@ -5,7 +5,6 @@
*/
#include "Manager.h"
#include <memory>
#include <river/debug.h>
#include "Node.h"
#include "NodeAEC.h"
@ -78,15 +77,15 @@ river::io::Manager::~Manager() {
};
std::shared_ptr<river::io::Manager> river::io::Manager::getInstance() {
static std::shared_ptr<river::io::Manager> manager(new Manager());
std11::shared_ptr<river::io::Manager> river::io::Manager::getInstance() {
static std11::shared_ptr<river::io::Manager> manager(new Manager());
return manager;
}
std::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string& _name) {
std11::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string& _name) {
RIVER_WARNING("Get node : " << _name);
for (auto &it : m_list) {
std::shared_ptr<river::io::Node> tmppp = it.lock();
for (size_t iii=0; iii<m_list.size(); ++iii) {
std11::shared_ptr<river::io::Node> tmppp = m_list[iii].lock();
if ( tmppp != nullptr
&& _name == tmppp->getName()) {
RIVER_WARNING(" find it ... ");
@ -95,14 +94,14 @@ std::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string&
}
RIVER_WARNING("Create a new one : " << _name);
// check if the node can be open :
const std::shared_ptr<const ejson::Object> tmpObject = m_config.getObject(_name);
const std11::shared_ptr<const ejson::Object> tmpObject = m_config.getObject(_name);
if (tmpObject != nullptr) {
// get type : io
std::string ioType = tmpObject->getStringValue("io", "error");
#ifdef __AIRTAUDIO_INFERFACE__
if ( ioType == "input"
|| ioType == "output") {
std::shared_ptr<river::io::Node> tmp = river::io::NodeAirTAudio::create(_name, tmpObject);
std11::shared_ptr<river::io::Node> tmp = river::io::NodeAirTAudio::create(_name, tmpObject);
m_list.push_back(tmp);
return tmp;
} else
@ -110,42 +109,42 @@ std::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string&
#ifdef __PORTAUDIO_INFERFACE__
if ( ioType == "PAinput"
|| ioType == "PAoutput") {
std::shared_ptr<river::io::Node> tmp = river::io::NodePortAudio::create(_name, tmpObject);
std11::shared_ptr<river::io::Node> tmp = river::io::NodePortAudio::create(_name, tmpObject);
m_list.push_back(tmp);
return tmp;
} else
#endif
if (ioType == "aec") {
std::shared_ptr<river::io::Node> tmp = river::io::NodeAEC::create(_name, tmpObject);
std11::shared_ptr<river::io::Node> tmp = river::io::NodeAEC::create(_name, tmpObject);
m_list.push_back(tmp);
return tmp;
}
}
RIVER_ERROR("Can not create the interface : '" << _name << "' the node is not DEFINED in the configuration file availlable : " << m_config.getKeys());
return nullptr;
return std11::shared_ptr<river::io::Node>();
}
std::shared_ptr<drain::VolumeElement> river::io::Manager::getVolumeGroup(const std::string& _name) {
std11::shared_ptr<drain::VolumeElement> river::io::Manager::getVolumeGroup(const std::string& _name) {
if (_name == "") {
RIVER_ERROR("Try to create an audio group with no name ...");
return nullptr;
return std11::shared_ptr<drain::VolumeElement>();
}
for (auto &it : m_volumeGroup) {
if (it == nullptr) {
for (size_t iii=0; iii<m_volumeGroup.size(); ++iii) {
if (m_volumeGroup[iii] == nullptr) {
continue;
}
if (it->getName() == _name) {
return it;
if (m_volumeGroup[iii]->getName() == _name) {
return m_volumeGroup[iii];
}
}
RIVER_DEBUG("Add a new volume group : '" << _name << "'");
std::shared_ptr<drain::VolumeElement> tmpVolume = std::make_shared<drain::VolumeElement>(_name);
std11::shared_ptr<drain::VolumeElement> tmpVolume = std11::make_shared<drain::VolumeElement>(_name);
m_volumeGroup.push_back(tmpVolume);
return tmpVolume;
}
bool river::io::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
std::shared_ptr<drain::VolumeElement> volume = getVolumeGroup(_volumeName);
std11::shared_ptr<drain::VolumeElement> volume = getVolumeGroup(_volumeName);
if (volume == nullptr) {
RIVER_ERROR("Can not set volume ... : '" << _volumeName << "'");
return false;
@ -156,8 +155,8 @@ bool river::io::Manager::setVolume(const std::string& _volumeName, float _valued
return false;
}
volume->setVolume(_valuedB);
for (auto &it2 : m_list) {
std::shared_ptr<river::io::Node> val = it2.lock();
for (size_t iii=0; iii<m_list.size(); ++iii) {
std11::shared_ptr<river::io::Node> val = m_list[iii].lock();
if (val != nullptr) {
val->volumeChange();
}
@ -166,7 +165,7 @@ bool river::io::Manager::setVolume(const std::string& _volumeName, float _valued
}
float river::io::Manager::getVolume(const std::string& _volumeName) {
std::shared_ptr<drain::VolumeElement> volume = getVolumeGroup(_volumeName);
std11::shared_ptr<drain::VolumeElement> volume = getVolumeGroup(_volumeName);
if (volume == nullptr) {
RIVER_ERROR("Can not get volume ... : '" << _volumeName << "'");
return 0.0f;
@ -187,12 +186,10 @@ void river::io::Manager::generateDot(const std::string& _filename) {
}
node << "digraph G {" << "\n";
node << " rankdir=\"LR\";\n";
int32_t id = 0;
for (auto &it2 : m_list) {
std::shared_ptr<river::io::Node> val = it2.lock();
for (size_t iii=0; iii<m_list.size(); ++iii) {
std11::shared_ptr<river::io::Node> val = m_list[iii].lock();
if (val != nullptr) {
val->generateDot(node);
id++;
}
}
node << "}" << "\n";

View File

@ -11,12 +11,18 @@
#include <vector>
#include <list>
#include <stdint.h>
#include <chrono>
#include <functional>
#if __cplusplus >= 201103L
#include <chrono>
#include <functional>
#include <memory>
#else
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#endif
#include <audio/format.h>
#include <audio/channel.h>
#include <ejson/ejson.h>
#include <memory>
#include <drain/Volume.h>
namespace river {
@ -29,21 +35,21 @@ namespace river {
*/
Manager();
public:
static std::shared_ptr<Manager> getInstance();
static std11::shared_ptr<Manager> getInstance();
/**
* @brief Destructor
*/
virtual ~Manager();
private:
ejson::Document m_config; // harware configuration
std::vector<std::shared_ptr<river::io::Node> > m_listKeepAlive; //!< list of all Node that might be keep alive sone time
std::vector<std::weak_ptr<river::io::Node> > m_list; //!< List of all IO node
std::vector<std11::shared_ptr<river::io::Node> > m_listKeepAlive; //!< list of all Node that might be keep alive sone time
std::vector<std11::weak_ptr<river::io::Node> > m_list; //!< List of all IO node
public:
std::shared_ptr<river::io::Node> getNode(const std::string& _name);
std11::shared_ptr<river::io::Node> getNode(const std::string& _name);
private:
std::vector<std::shared_ptr<drain::VolumeElement>> m_volumeGroup;
std::vector<std11::shared_ptr<drain::VolumeElement> > m_volumeGroup;
public:
std::shared_ptr<drain::VolumeElement> getVolumeGroup(const std::string& _name);
std11::shared_ptr<drain::VolumeElement> getVolumeGroup(const std::string& _name);
/**
* @brief Set a volume for a specific group

View File

@ -7,13 +7,11 @@
#include "Node.h"
#include <river/debug.h>
#include <memory>
#undef __class__
#define __class__ "io::Node"
river::io::Node::Node(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config) :
river::io::Node::Node(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) :
m_config(_config),
m_name(_name),
m_isInput(false) {
@ -58,7 +56,7 @@ river::io::Node::Node(const std::string& _name, const std::shared_ptr<const ejso
}
// Get map type :
std::vector<audio::channel> map;
const std::shared_ptr<const ejson::Array> listChannelMap = m_config->getArray("channel-map");
const std11::shared_ptr<const ejson::Array> listChannelMap = m_config->getArray("channel-map");
if ( listChannelMap == nullptr
|| listChannelMap->size() == 0) {
// set default channel property:
@ -105,19 +103,19 @@ river::io::Node::~Node() {
size_t river::io::Node::getNumberOfInterface(enum river::modeInterface _interfaceType) {
size_t out = 0;
for (auto &it : m_list) {
if (it == nullptr) {
for (size_t iii=0; iii<m_list.size(); ++iii) {
if (m_list[iii] == nullptr) {
continue;
}
if (it->getMode() == _interfaceType) {
if (m_list[iii]->getMode() == _interfaceType) {
out++;
}
}
return out;
}
void river::io::Node::registerAsRemote(const std::shared_ptr<river::Interface>& _interface) {
auto it = m_listAvaillable.begin();
void river::io::Node::registerAsRemote(const std11::shared_ptr<river::Interface>& _interface) {
std::vector<std11::weak_ptr<river::Interface> >::iterator it = m_listAvaillable.begin();
while (it != m_listAvaillable.end()) {
if (it->expired() == true) {
it = m_listAvaillable.erase(it);
@ -127,11 +125,11 @@ void river::io::Node::registerAsRemote(const std::shared_ptr<river::Interface>&
m_listAvaillable.push_back(_interface);
}
void river::io::Node::interfaceAdd(const std::shared_ptr<river::Interface>& _interface) {
void river::io::Node::interfaceAdd(const std11::shared_ptr<river::Interface>& _interface) {
{
std::unique_lock<std::mutex> lock(m_mutex);
for (auto &it : m_list) {
if (_interface == it) {
std11::unique_lock<std11::mutex> lock(m_mutex);
for (size_t iii=0; iii<m_list.size(); ++iii) {
if (_interface == m_list[iii]) {
return;
}
}
@ -143,9 +141,9 @@ void river::io::Node::interfaceAdd(const std::shared_ptr<river::Interface>& _int
}
}
void river::io::Node::interfaceRemove(const std::shared_ptr<river::Interface>& _interface) {
void river::io::Node::interfaceRemove(const std11::shared_ptr<river::Interface>& _interface) {
{
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
for (size_t iii=0; iii< m_list.size(); ++iii) {
if (_interface == m_list[iii]) {
m_list.erase(m_list.begin()+iii);
@ -162,8 +160,8 @@ void river::io::Node::interfaceRemove(const std::shared_ptr<river::Interface>& _
void river::io::Node::volumeChange() {
for (auto &it : m_listAvaillable) {
std::shared_ptr<river::Interface> node = it.lock();
for (size_t iii=0; iii< m_listAvaillable.size(); ++iii) {
std11::shared_ptr<river::Interface> node = m_listAvaillable[iii].lock();
if (node != nullptr) {
node->systemVolumeChange();
}
@ -172,20 +170,20 @@ void river::io::Node::volumeChange() {
int32_t river::io::Node::newInput(const void* _inputBuffer,
uint32_t _nbChunk,
const std::chrono::system_clock::time_point& _time) {
const std11::chrono::system_clock::time_point& _time) {
if (_inputBuffer == nullptr) {
return -1;
}
const int16_t* inputBuffer = static_cast<const int16_t *>(_inputBuffer);
for (auto &it : m_list) {
if (it == nullptr) {
for (size_t iii=0; iii< m_list.size(); ++iii) {
if (m_list[iii] == nullptr) {
continue;
}
if (it->getMode() != river::modeInterface_input) {
if (m_list[iii]->getMode() != river::modeInterface_input) {
continue;
}
RIVER_VERBOSE(" IO name="<< it->getName());
it->systemNewInputData(_time, inputBuffer, _nbChunk);
RIVER_VERBOSE(" IO name="<< m_list[iii]->getName());
m_list[iii]->systemNewInputData(_time, inputBuffer, _nbChunk);
}
RIVER_VERBOSE("data Input size request :" << _nbChunk << " [ END ]");
return 0;
@ -193,7 +191,7 @@ int32_t river::io::Node::newInput(const void* _inputBuffer,
int32_t river::io::Node::newOutput(void* _outputBuffer,
uint32_t _nbChunk,
const std::chrono::system_clock::time_point& _time) {
const std11::chrono::system_clock::time_point& _time) {
if (_outputBuffer == nullptr) {
return -1;
}
@ -204,18 +202,18 @@ int32_t river::io::Node::newOutput(void* _outputBuffer,
std::vector<uint8_t> outputTmp2;
RIVER_VERBOSE("resize=" << sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nbChunk);
outputTmp2.resize(sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nbChunk, 0);
for (auto &it : m_list) {
if (it == nullptr) {
for (size_t iii=0; iii< m_list.size(); ++iii) {
if (m_list[iii] == nullptr) {
continue;
}
if (it->getMode() != river::modeInterface_output) {
if (m_list[iii]->getMode() != river::modeInterface_output) {
continue;
}
RIVER_VERBOSE(" IO name="<< it->getName());
RIVER_VERBOSE(" IO name="<< m_list[iii]->getName());
// clear datas ...
memset(&outputTmp2[0], 0, sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nbChunk);
RIVER_VERBOSE(" request Data="<< _nbChunk);
it->systemNeedOutputData(_time, &outputTmp2[0], _nbChunk, sizeof(int32_t)*m_process.getInputConfig().getMap().size());
m_list[iii]->systemNeedOutputData(_time, &outputTmp2[0], _nbChunk, sizeof(int32_t)*m_process.getInputConfig().getMap().size());
RIVER_VERBOSE(" Mix it ...");
outputTmp = reinterpret_cast<const int32_t*>(&outputTmp2[0]);
// Add data to the output tmp buffer :
@ -226,15 +224,15 @@ int32_t river::io::Node::newOutput(void* _outputBuffer,
RIVER_VERBOSE(" End stack process data ...");
m_process.processIn(&outputTmp2[0], _nbChunk, _outputBuffer, _nbChunk);
RIVER_VERBOSE(" Feedback :");
for (auto &it : m_list) {
if (it == nullptr) {
for (size_t iii=0; iii< m_list.size(); ++iii) {
if (m_list[iii] == nullptr) {
continue;
}
if (it->getMode() != river::modeInterface_feedback) {
if (m_list[iii]->getMode() != river::modeInterface_feedback) {
continue;
}
RIVER_VERBOSE(" IO name="<< it->getName() << " (feedback)");
it->systemNewInputData(_time, _outputBuffer, _nbChunk);
RIVER_VERBOSE(" IO name="<< m_list[iii]->getName() << " (feedback)");
m_list[iii]->systemNewInputData(_time, _outputBuffer, _nbChunk);
}
RIVER_VERBOSE("data Output size request :" << _nbChunk << " [ END ]");
return 0;
@ -307,14 +305,14 @@ void river::io::Node::generateDot(etk::FSNode& _node) {
}
_node << "}\n";
for (auto &it : m_list) {
if (it != nullptr) {
if (it->getMode() == modeInterface_input) {
it->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer");
} else if (it->getMode() == modeInterface_output) {
it->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_muxer");
} else if (it->getMode() == modeInterface_feedback) {
it->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer");
for (size_t iii=0; iii< m_list.size(); ++iii) {
if (m_list[iii] != nullptr) {
if (m_list[iii]->getMode() == modeInterface_input) {
m_list[iii]->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer");
} else if (m_list[iii]->getMode() == modeInterface_output) {
m_list[iii]->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_muxer");
} else if (m_list[iii]->getMode() == modeInterface_feedback) {
m_list[iii]->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer");
} else {
}

View File

@ -11,12 +11,19 @@
#include <vector>
#include <list>
#include <stdint.h>
#include <chrono>
#include <functional>
#if __cplusplus >= 201103L
#include <chrono>
#include <functional>
#include <memory>
#else
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#endif
#include <audio/format.h>
#include <audio/channel.h>
#include "Manager.h"
#include <memory>
#include <river/Interface.h>
#include <airtaudio/Interface.h>
#include <drain/IOFormatInterface.h>
@ -26,14 +33,14 @@
namespace river {
namespace io {
class Manager;
class Node : public std::enable_shared_from_this<Node> {
class Node : public std11::enable_shared_from_this<Node> {
protected:
uint32_t m_uid; // uniqueNodeID
protected:
/**
* @brief Constructor
*/
Node(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config);
Node(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
/**
* @brief Destructor
@ -41,8 +48,8 @@ namespace river {
virtual ~Node();
protected:
mutable std::mutex m_mutex;
std::shared_ptr<const ejson::Object> m_config;
mutable std11::mutex m_mutex;
std11::shared_ptr<const ejson::Object> m_config;
protected:
drain::Process m_process;
public:
@ -62,16 +69,16 @@ namespace river {
}
protected:
std::shared_ptr<drain::VolumeElement> m_volume; //!< if a volume is set it is set here ...
std11::shared_ptr<drain::VolumeElement> m_volume; //!< if a volume is set it is set here ...
protected:
std::vector<std::weak_ptr<river::Interface> > m_listAvaillable; //!< List of all interface that exist on this Node
std::vector<std::shared_ptr<river::Interface> > m_list;
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;
size_t getNumberOfInterface(enum river::modeInterface _interfaceType);
public:
void registerAsRemote(const std::shared_ptr<river::Interface>& _interface);
void interfaceAdd(const std::shared_ptr<river::Interface>& _interface);
void interfaceRemove(const std::shared_ptr<river::Interface>& _interface);
void registerAsRemote(const std11::shared_ptr<river::Interface>& _interface);
void interfaceAdd(const std11::shared_ptr<river::Interface>& _interface);
void interfaceRemove(const std11::shared_ptr<river::Interface>& _interface);
protected:
std::string m_name; //!< Harware.json configuration name
public:
@ -91,7 +98,7 @@ namespace river {
virtual void start() = 0;
virtual void stop() = 0;
public:
const std::shared_ptr<drain::VolumeElement>& getVolume() {
const std11::shared_ptr<drain::VolumeElement>& getVolume() {
return m_volume;
}
public:
@ -99,10 +106,10 @@ namespace river {
protected:
int32_t newInput(const void* _inputBuffer,
uint32_t _nbChunk,
const std::chrono::system_clock::time_point& _time);
const std11::chrono::system_clock::time_point& _time);
int32_t newOutput(void* _outputBuffer,
uint32_t _nbChunk,
const std::chrono::system_clock::time_point& _time);
const std11::chrono::system_clock::time_point& _time);
public:
virtual void generateDot(etk::FSNode& _node);

View File

@ -6,8 +6,15 @@
#include <river/io/NodeAEC.h>
#include <river/debug.h>
#include <etk/types.h>
#include <memory>
#if __cplusplus >= 201103L
#include <memory>
#include <functional>
#else
#include <etk/memory.h>
#include <etk/functional.h>
#endif
#undef __class__
#define __class__ "io::NodeAEC"
@ -16,9 +23,9 @@
int32_t river::io::NodeAEC::airtAudioCallback(void* _outputBuffer,
void* _inputBuffer,
uint32_t _nbChunk,
const std::chrono::system_clock::time_point& _time,
const std11::chrono::system_clock::time_point& _time,
airtaudio::status _status) {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
//RIVER_INFO("Time=" << _time);
/*
for (int32_t iii=0; iii<400; ++iii) {
@ -87,20 +94,20 @@ int32_t river::io::NodeAEC::airtAudioCallback(void* _outputBuffer,
}
#endif
std::shared_ptr<river::io::NodeAEC> river::io::NodeAEC::create(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config) {
return std::shared_ptr<river::io::NodeAEC>(new river::io::NodeAEC(_name, _config));
std11::shared_ptr<river::io::NodeAEC> 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));
}
std::shared_ptr<river::Interface> river::io::NodeAEC::createInput(float _freq,
std11::shared_ptr<river::Interface> river::io::NodeAEC::createInput(float _freq,
const std::vector<audio::channel>& _map,
audio::format _format,
const std::string& _objectName,
const std::string& _name) {
// check if the output exist
const std::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) {
RIVER_ERROR("can not open a non existance virtual interface: '" << _objectName << "' not present in : " << m_config->getKeys());
return nullptr;
return std11::shared_ptr<river::Interface>();
}
std::string streamName = tmppp->getStringValue("map-on", "error");
@ -110,24 +117,24 @@ std::shared_ptr<river::Interface> river::io::NodeAEC::createInput(float _freq,
if ( type != "input"
&& type != "feedback") {
RIVER_ERROR("can not open in output a virtual interface: '" << streamName << "' configured has : " << type);
return nullptr;
return std11::shared_ptr<river::Interface>();
}
// get global hardware interface:
std::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
// get the output or input channel :
std::shared_ptr<river::io::Node> node = manager->getNode(streamName);
std11::shared_ptr<river::io::Node> node = manager->getNode(streamName);
// create user iterface:
std::shared_ptr<river::Interface> interface;
std11::shared_ptr<river::Interface> interface;
interface = river::Interface::create(_name, _freq, _map, _format, node, tmppp);
return interface;
}
river::io::NodeAEC::NodeAEC(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config) :
river::io::NodeAEC::NodeAEC(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) :
Node(_name, _config) {
drain::IOFormatInterface interfaceFormat = getInterfaceFormat();
drain::IOFormatInterface hardwareFormat = getHarwareFormat();
m_sampleTime = std::chrono::nanoseconds(1000000000/int64_t(hardwareFormat.getFrequency()));
m_sampleTime = std11::chrono::nanoseconds(1000000000/int64_t(hardwareFormat.getFrequency()));
/**
# connect in input mode
map-on-microphone:{
@ -172,28 +179,36 @@ river::io::NodeAEC::NodeAEC(const std::string& _name, const std::shared_ptr<cons
}
// set callback mode ...
m_interfaceFeedBack->setInputCallback(std::bind(&river::io::NodeAEC::onDataReceivedFeedBack,
this,
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3,
std::placeholders::_4,
std::placeholders::_5,
std::placeholders::_6));
// set callback mode ...
m_interfaceMicrophone->setInputCallback(std::bind(&river::io::NodeAEC::onDataReceivedMicrophone,
m_interfaceFeedBack->setInputCallback(std11::bind(&river::io::NodeAEC::onDataReceivedFeedBack,
this,
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3,
std::placeholders::_4,
std::placeholders::_5,
std::placeholders::_6));
#if __cplusplus >= 201103L
std11::placeholders::_1,
std11::placeholders::_2,
std11::placeholders::_3,
std11::placeholders::_4,
std11::placeholders::_5,
std11::placeholders::_6));
#else
_1, _2, _3, _4, _5, _6));
#endif
// set callback mode ...
m_interfaceMicrophone->setInputCallback(std11::bind(&river::io::NodeAEC::onDataReceivedMicrophone,
this,
#if __cplusplus >= 201103L
std11::placeholders::_1,
std11::placeholders::_2,
std11::placeholders::_3,
std11::placeholders::_4,
std11::placeholders::_5,
std11::placeholders::_6));
#else
_1, _2, _3, _4, _5, _6));
#endif
m_bufferMicrophone.setCapacity(std::chrono::milliseconds(1000),
m_bufferMicrophone.setCapacity(std11::chrono::milliseconds(1000),
audio::getFormatBytes(hardwareFormat.getFormat())*hardwareFormat.getMap().size(),
hardwareFormat.getFrequency());
m_bufferFeedBack.setCapacity(std::chrono::milliseconds(1000),
m_bufferFeedBack.setCapacity(std11::chrono::milliseconds(1000),
audio::getFormatBytes(hardwareFormat.getFormat()), // only one channel ...
hardwareFormat.getFrequency());
@ -208,7 +223,7 @@ river::io::NodeAEC::~NodeAEC() {
};
void river::io::NodeAEC::start() {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
if (m_interfaceFeedBack != nullptr) {
RIVER_INFO("Start FEEDBACK : ");
@ -221,7 +236,7 @@ void river::io::NodeAEC::start() {
}
void river::io::NodeAEC::stop() {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
if (m_interfaceFeedBack != nullptr) {
m_interfaceFeedBack->stop();
}
@ -231,8 +246,8 @@ void river::io::NodeAEC::stop() {
}
namespace std {
static std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj) {
std::chrono::nanoseconds ns = std::chrono::duration_cast<std::chrono::nanoseconds>(_obj.time_since_epoch());
static std::ostream& operator <<(std::ostream& _os, const std11::chrono::system_clock::time_point& _obj) {
std11::chrono::nanoseconds ns = std11::chrono::duration_cast<std11::chrono::nanoseconds>(_obj.time_since_epoch());
int64_t totalSecond = ns.count()/1000000000;
int64_t millisecond = (ns.count()%1000000000)/1000000;
int64_t microsecond = (ns.count()%1000000)/1000;
@ -269,7 +284,7 @@ namespace std {
void river::io::NodeAEC::onDataReceivedMicrophone(const void* _data,
const std::chrono::system_clock::time_point& _time,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
@ -279,14 +294,14 @@ void river::io::NodeAEC::onDataReceivedMicrophone(const void* _data,
RIVER_ERROR("call wrong type ... (need int16_t)");
}
// push data synchronize
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
m_bufferMicrophone.write(_data, _nbChunk, _time);
SAVE_FILE_MACRO(int16_t, "REC_Microphone.raw", _data, _nbChunk*_map.size());
process();
}
void river::io::NodeAEC::onDataReceivedFeedBack(const void* _data,
const std::chrono::system_clock::time_point& _time,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
@ -296,7 +311,7 @@ void river::io::NodeAEC::onDataReceivedFeedBack(const void* _data,
RIVER_ERROR("call wrong type ... (need int16_t)");
}
// push data synchronize
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
m_bufferFeedBack.write(_data, _nbChunk, _time);
SAVE_FILE_MACRO(int16_t, "REC_FeedBack.raw", _data, _nbChunk*_map.size());
process();
@ -309,9 +324,9 @@ void river::io::NodeAEC::process() {
if (m_bufferFeedBack.getSize() <= 256) {
return;
}
std::chrono::system_clock::time_point MicTime = m_bufferMicrophone.getReadTimeStamp();
std::chrono::system_clock::time_point fbTime = m_bufferFeedBack.getReadTimeStamp();
std::chrono::nanoseconds delta;
std11::chrono::system_clock::time_point MicTime = m_bufferMicrophone.getReadTimeStamp();
std11::chrono::system_clock::time_point fbTime = m_bufferFeedBack.getReadTimeStamp();
std11::chrono::nanoseconds delta;
if (MicTime < fbTime) {
delta = fbTime - MicTime;
} else {
@ -373,7 +388,7 @@ void river::io::NodeAEC::process() {
}
void river::io::NodeAEC::processAEC(void* _dataMic, void* _dataFB, uint32_t _nbChunk, const std::chrono::system_clock::time_point& _time) {
void river::io::NodeAEC::processAEC(void* _dataMic, void* _dataFB, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time) {
newInput(_dataMic, _nbChunk, _time);
}
@ -407,14 +422,14 @@ void river::io::NodeAEC::generateDot(etk::FSNode& _node) {
_node << " API_" << m_interfaceFeedBack->m_uid << "_feedback -> NODE_" << m_uid << "_HW_AEC;\n";
}
for (auto &it : m_list) {
if (it != nullptr) {
if (it->getMode() == modeInterface_input) {
it->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer");
} else if (it->getMode() == modeInterface_output) {
it->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_muxer");
} else if (it->getMode() == modeInterface_feedback) {
it->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer");
for (size_t iii=0; iii<m_list.size(); ++iii) {
if (m_list[iii] != nullptr) {
if (m_list[iii]->getMode() == modeInterface_input) {
m_list[iii]->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer");
} else if (m_list[iii]->getMode() == modeInterface_output) {
m_list[iii]->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_muxer");
} else if (m_list[iii]->getMode() == modeInterface_feedback) {
m_list[iii]->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer");
} else {
}

View File

@ -19,9 +19,9 @@ namespace river {
/**
* @brief Constructor
*/
NodeAEC(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config);
NodeAEC(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
static std::shared_ptr<NodeAEC> create(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config);
static std11::shared_ptr<NodeAEC> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
@ -29,30 +29,30 @@ namespace river {
protected:
virtual void start();
virtual void stop();
std::shared_ptr<river::Interface> m_interfaceMicrophone;
std::shared_ptr<river::Interface> m_interfaceFeedBack;
std::shared_ptr<river::Interface> createInput(float _freq,
std11::shared_ptr<river::Interface> m_interfaceMicrophone;
std11::shared_ptr<river::Interface> m_interfaceFeedBack;
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 onDataReceivedMicrophone(const void* _data,
const std::chrono::system_clock::time_point& _time,
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 onDataReceivedFeedBack(const void* _data,
const std::chrono::system_clock::time_point& _time,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map);
river::CircularBuffer m_bufferMicrophone;
river::CircularBuffer m_bufferFeedBack;
std::chrono::nanoseconds m_sampleTime; //!< represent the sample time at the specify frequency.
std11::chrono::nanoseconds m_sampleTime; //!< represent the sample time at the specify frequency.
void process();
void processAEC(void* _dataMic, void* _dataFB, uint32_t _nbChunk, const std::chrono::system_clock::time_point& _time);
void processAEC(void* _dataMic, void* _dataFB, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time);
public:
virtual void generateDot(etk::FSNode& _node);
};

View File

@ -9,14 +9,18 @@
#include <river/io/NodeAirTAudio.h>
#include <river/debug.h>
#include <memory>
#if __cplusplus >= 201103L
#include <memory>
#else
#include <etk/memory.h>
#endif
#undef __class__
#define __class__ "io::NodeAirTAudio"
static std::string asString(const std::chrono::system_clock::time_point& tp) {
static std::string asString(const std11::chrono::system_clock::time_point& tp) {
// convert to system time:
std::time_t t = std::chrono::system_clock::to_time_t(tp);
std::time_t t = std11::chrono::system_clock::to_time_t(tp);
// convert in human string
std::string ts = std::ctime(&t);
// remove \n
@ -25,8 +29,8 @@ static std::string asString(const std::chrono::system_clock::time_point& tp) {
}
namespace std {
static std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj) {
std::chrono::microseconds us = std::chrono::duration_cast<std::chrono::microseconds>(_obj.time_since_epoch());
static std::ostream& operator <<(std::ostream& _os, const std11::chrono::system_clock::time_point& _obj) {
std11::chrono::microseconds us = std11::chrono::duration_cast<std11::chrono::microseconds>(_obj.time_since_epoch());
_os << us.count();
return _os;
}
@ -34,12 +38,12 @@ namespace std {
int32_t river::io::NodeAirTAudio::duplexCallback(const void* _inputBuffer,
const std::chrono::system_clock::time_point& _timeInput,
const std11::chrono::system_clock::time_point& _timeInput,
void* _outputBuffer,
const std::chrono::system_clock::time_point& _timeOutput,
const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk,
const std::vector<airtaudio::status>& _status) {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
// TODO : Manage status ...
if (_inputBuffer != nullptr) {
RIVER_VERBOSE("data Input size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size());
@ -53,10 +57,10 @@ int32_t river::io::NodeAirTAudio::duplexCallback(const void* _inputBuffer,
}
int32_t river::io::NodeAirTAudio::recordCallback(const void* _inputBuffer,
const std::chrono::system_clock::time_point& _timeInput,
const std11::chrono::system_clock::time_point& _timeInput,
uint32_t _nbChunk,
const std::vector<airtaudio::status>& _status) {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
// TODO : Manage status ...
RIVER_VERBOSE("data Input size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size());
newInput(_inputBuffer, _nbChunk, _timeInput);
@ -64,10 +68,10 @@ int32_t river::io::NodeAirTAudio::recordCallback(const void* _inputBuffer,
}
int32_t river::io::NodeAirTAudio::playbackCallback(void* _outputBuffer,
const std::chrono::system_clock::time_point& _timeOutput,
const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk,
const std::vector<airtaudio::status>& _status) {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
// TODO : Manage status ...
RIVER_VERBOSE("data Output size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size());
newOutput(_outputBuffer, _nbChunk, _timeOutput);
@ -76,11 +80,11 @@ int32_t river::io::NodeAirTAudio::playbackCallback(void* _outputBuffer,
std::shared_ptr<river::io::NodeAirTAudio> river::io::NodeAirTAudio::create(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config) {
return std::shared_ptr<river::io::NodeAirTAudio>(new river::io::NodeAirTAudio(_name, _config));
std11::shared_ptr<river::io::NodeAirTAudio> river::io::NodeAirTAudio::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));
}
river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config) :
river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) :
Node(_name, _config) {
drain::IOFormatInterface interfaceFormat = getInterfaceFormat();
drain::IOFormatInterface hardwareFormat = getHarwareFormat();
@ -93,7 +97,7 @@ river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std::sha
*/
enum airtaudio::type typeInterface = airtaudio::type_undefined;
std::string streamName = "default";
const std::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) {
RIVER_WARNING("missing node : 'map-on' ==> auto map : 'auto:default'");
} else {
@ -214,22 +218,30 @@ river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std::sha
if (m_isInput == true) {
err = m_adac.openStream(nullptr, &params,
hardwareFormat.getFormat(), hardwareFormat.getFrequency(), &m_rtaudioFrameSize,
std::bind(&river::io::NodeAirTAudio::recordCallback,
this,
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_5,
std::placeholders::_6)
std11::bind(&river::io::NodeAirTAudio::recordCallback,
this,
#if __cplusplus >= 201103L
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_5,
std::placeholders::_6)
#else
_1, _2, _5, _6)
#endif
);
} else {
err = m_adac.openStream(&params, nullptr,
hardwareFormat.getFormat(), hardwareFormat.getFrequency(), &m_rtaudioFrameSize,
std::bind(&river::io::NodeAirTAudio::playbackCallback,
this,
std::placeholders::_3,
std::placeholders::_4,
std::placeholders::_5,
std::placeholders::_6)
std11::bind(&river::io::NodeAirTAudio::playbackCallback,
this,
#if __cplusplus >= 201103L
std::placeholders::_3,
std::placeholders::_4,
std::placeholders::_5,
std::placeholders::_6)
#else
_3, _4, _5, _6)
#endif
);
}
if (err != airtaudio::error_none) {
@ -239,7 +251,7 @@ river::io::NodeAirTAudio::NodeAirTAudio(const std::string& _name, const std::sha
}
river::io::NodeAirTAudio::~NodeAirTAudio() {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("close input stream");
if (m_adac.isStreamOpen() ) {
m_adac.closeStream();
@ -247,7 +259,7 @@ river::io::NodeAirTAudio::~NodeAirTAudio() {
};
void river::io::NodeAirTAudio::start() {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
enum airtaudio::error err = m_adac.startStream();
if (err != airtaudio::error_none) {
@ -256,7 +268,7 @@ void river::io::NodeAirTAudio::start() {
}
void river::io::NodeAirTAudio::stop() {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Stop stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
enum airtaudio::error err = m_adac.stopStream();
if (err != airtaudio::error_none) {

View File

@ -19,9 +19,9 @@ namespace river {
/**
* @brief Constructor
*/
NodeAirTAudio(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config);
NodeAirTAudio(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
static std::shared_ptr<NodeAirTAudio> create(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config);
static std11::shared_ptr<NodeAirTAudio> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
@ -32,17 +32,17 @@ namespace river {
unsigned int m_rtaudioFrameSize;
public:
int32_t duplexCallback(const void* _inputBuffer,
const std::chrono::system_clock::time_point& _timeInput,
const std11::chrono::system_clock::time_point& _timeInput,
void* _outputBuffer,
const std::chrono::system_clock::time_point& _timeOutput,
const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk,
const std::vector<airtaudio::status>& _status);
int32_t recordCallback(const void* _inputBuffer,
const std::chrono::system_clock::time_point& _timeInput,
const std11::chrono::system_clock::time_point& _timeInput,
uint32_t _nbChunk,
const std::vector<airtaudio::status>& _status);
int32_t playbackCallback(void* _outputBuffer,
const std::chrono::system_clock::time_point& _timeOutput,
const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk,
const std::vector<airtaudio::status>& _status);
protected:

View File

@ -9,14 +9,18 @@
#include <river/io/NodePortAudio.h>
#include <river/debug.h>
#include <memory>
#if __cplusplus >= 201103L
#include <memory>
#else
#include <etk/memory.h>
#endif
#undef __class__
#define __class__ "io::NodePortAudio"
static std::string asString(const std::chrono::system_clock::time_point& tp) {
static std::string asString(const std11::chrono::system_clock::time_point& tp) {
// convert to system time:
std::time_t t = std::chrono::system_clock::to_time_t(tp);
std::time_t t = std11::chrono::system_clock::to_time_t(tp);
// convert in human string
std::string ts = std::ctime(&t);
// remove \n
@ -25,8 +29,8 @@ static std::string asString(const std::chrono::system_clock::time_point& tp) {
}
namespace std {
static std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj) {
std::chrono::microseconds us = std::chrono::duration_cast<std::chrono::microseconds>(_obj.time_since_epoch());
static std::ostream& operator <<(std::ostream& _os, const std11::chrono::system_clock::time_point& _obj) {
std11::chrono::microseconds us = std11::chrono::duration_cast<std::chrono::microseconds>(_obj.time_since_epoch());
_os << us.count();
return _os;
}
@ -41,10 +45,10 @@ static int portAudioStreamCallback(const void *_input,
river::io::NodePortAudio* myClass = reinterpret_cast<river::io::NodePortAudio*>(_userData);
int64_t sec = int64_t(_timeInfo->inputBufferAdcTime);
int64_t nsec = (_timeInfo->inputBufferAdcTime-double(sec))*1000000000LL;
std::chrono::system_clock::time_point timeInput = std::chrono::system_clock::from_time_t(sec) + std::chrono::nanoseconds(nsec);
std11::chrono::system_clock::time_point timeInput = std11::chrono::system_clock::from_time_t(sec) + std::chrono::nanoseconds(nsec);
sec = int64_t(_timeInfo->outputBufferDacTime);
nsec = (_timeInfo->outputBufferDacTime-double(sec))*1000000000LL;
std::chrono::system_clock::time_point timeOutput = std::chrono::system_clock::from_time_t(sec) + std::chrono::nanoseconds(nsec);
std11::chrono::system_clock::time_point timeOutput = std11::chrono::system_clock::from_time_t(sec) + std::chrono::nanoseconds(nsec);
return myClass->duplexCallback(_input,
timeInput,
_output,
@ -54,12 +58,12 @@ static int portAudioStreamCallback(const void *_input,
}
int32_t river::io::NodePortAudio::duplexCallback(const void* _inputBuffer,
const std::chrono::system_clock::time_point& _timeInput,
const std11::chrono::system_clock::time_point& _timeInput,
void* _outputBuffer,
const std::chrono::system_clock::time_point& _timeOutput,
const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk,
PaStreamCallbackFlags _status) {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
// TODO : Manage status ...
if (_inputBuffer != nullptr) {
RIVER_VERBOSE("data Input size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size());
@ -73,11 +77,11 @@ int32_t river::io::NodePortAudio::duplexCallback(const void* _inputBuffer,
}
std::shared_ptr<river::io::NodePortAudio> river::io::NodePortAudio::create(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config) {
return std::shared_ptr<river::io::NodePortAudio>(new river::io::NodePortAudio(_name, _config));
std11::shared_ptr<river::io::NodePortAudio> 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));
}
river::io::NodePortAudio::NodePortAudio(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config) :
river::io::NodePortAudio::NodePortAudio(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) :
Node(_name, _config) {
drain::IOFormatInterface interfaceFormat = getInterfaceFormat();
drain::IOFormatInterface hardwareFormat = getHarwareFormat();
@ -90,7 +94,7 @@ river::io::NodePortAudio::NodePortAudio(const std::string& _name, const std::sha
*/
enum airtaudio::type typeInterface = airtaudio::type_undefined;
std::string streamName = "default";
const std::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) {
RIVER_WARNING("missing node : 'map-on' ==> auto map : 'auto:default'");
} else {
@ -127,7 +131,7 @@ river::io::NodePortAudio::NodePortAudio(const std::string& _name, const std::sha
}
river::io::NodePortAudio::~NodePortAudio() {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("close input stream");
PaError err = Pa_CloseStream( m_stream );
if( err != paNoError ) {
@ -136,7 +140,7 @@ river::io::NodePortAudio::~NodePortAudio() {
};
void river::io::NodePortAudio::start() {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Start stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
PaError err = Pa_StartStream(m_stream);
if( err != paNoError ) {
@ -145,7 +149,7 @@ void river::io::NodePortAudio::start() {
}
void river::io::NodePortAudio::stop() {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
RIVER_INFO("Stop stream : '" << m_name << "' mode=" << (m_isInput?"input":"output") );
PaError err = Pa_StopStream(m_stream);
if( err != paNoError ) {

View File

@ -21,9 +21,9 @@ namespace river {
/**
* @brief Constructor
*/
NodePortAudio(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config);
NodePortAudio(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
public:
static std::shared_ptr<NodePortAudio> create(const std::string& _name, const std::shared_ptr<const ejson::Object>& _config);
static std11::shared_ptr<NodePortAudio> create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config);
/**
* @brief Destructor
*/
@ -32,9 +32,9 @@ namespace river {
PaStream* m_stream;
public:
int32_t duplexCallback(const void* _inputBuffer,
const std::chrono::system_clock::time_point& _timeInput,
const std11::chrono::system_clock::time_point& _timeInput,
void* _outputBuffer,
const std::chrono::system_clock::time_point& _timeOutput,
const std11::chrono::system_clock::time_point& _timeOutput,
uint32_t _nbChunk,
PaStreamCallbackFlags _status);
protected:

View File

@ -21,10 +21,10 @@
class testOutWrite {
private:
std::vector<audio::channel> m_channelMap;
std::shared_ptr<river::Manager> m_manager;
std::shared_ptr<river::Interface> m_interface;
std11::shared_ptr<river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface;
public:
testOutWrite(std::shared_ptr<river::Manager> _manager) :
testOutWrite(std11::shared_ptr<river::Manager> _manager) :
m_manager(_manager) {
//Set stereo output:
m_channelMap.push_back(audio::channel_frontLeft);
@ -74,11 +74,11 @@ class testOutWrite {
};
TEST(TestALL, testOutputWrite) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test output (write mode)");
std::shared_ptr<testOutWrite> process = std::make_shared<testOutWrite>(manager);
std11::shared_ptr<testOutWrite> process = std::make_shared<testOutWrite>(manager);
process->run();
process.reset();
usleep(500000);
@ -87,11 +87,11 @@ TEST(TestALL, testOutputWrite) {
class testOutWriteCallback {
private:
std::shared_ptr<river::Manager> m_manager;
std::shared_ptr<river::Interface> m_interface;
std11::shared_ptr<river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface;
double m_phase;
public:
testOutWriteCallback(std::shared_ptr<river::Manager> _manager) :
testOutWriteCallback(std11::shared_ptr<river::Manager> _manager) :
m_manager(_manager),
m_phase(0) {
std::vector<audio::channel> channelMap;
@ -112,7 +112,7 @@ class testOutWriteCallback {
std::placeholders::_4,
std::placeholders::_5));
}
void onDataNeeded(const std::chrono::system_clock::time_point& _time,
void onDataNeeded(const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
@ -143,11 +143,11 @@ class testOutWriteCallback {
};
TEST(TestALL, testOutputWriteWithCallback) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test output (write with callback event mode)");
std::shared_ptr<testOutWriteCallback> process = std::make_shared<testOutWriteCallback>(manager);
std11::shared_ptr<testOutWriteCallback> process = std::make_shared<testOutWriteCallback>(manager);
process->run();
process.reset();
usleep(500000);
@ -156,11 +156,11 @@ TEST(TestALL, testOutputWriteWithCallback) {
class testOutCallback {
private:
std::shared_ptr<river::Manager> m_manager;
std::shared_ptr<river::Interface> m_interface;
std11::shared_ptr<river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface;
double m_phase;
public:
testOutCallback(std::shared_ptr<river::Manager> _manager, const std::string& _io="speaker") :
testOutCallback(std11::shared_ptr<river::Manager> _manager, const std::string& _io="speaker") :
m_manager(_manager),
m_phase(0) {
//Set stereo output:
@ -183,7 +183,7 @@ class testOutCallback {
std::placeholders::_6));
}
void onDataNeeded(void* _data,
const std::chrono::system_clock::time_point& _time,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
@ -212,33 +212,33 @@ class testOutCallback {
};
TEST(TestALL, testOutputCallBack) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test output (callback mode)");
std::shared_ptr<testOutCallback> process = std::make_shared<testOutCallback>(manager, "speaker");
std11::shared_ptr<testOutCallback> process = std::make_shared<testOutCallback>(manager, "speaker");
process->run();
process.reset();
usleep(500000);
}
TEST(TestALL, testOutputCallBackPulse) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test output (callback mode)");
std::shared_ptr<testOutCallback> process = std::make_shared<testOutCallback>(manager, "speaker-pulse");
std11::shared_ptr<testOutCallback> process = std::make_shared<testOutCallback>(manager, "speaker-pulse");
process->run();
process.reset();
usleep(500000);
}
TEST(TestALL, testOutputCallBackJack) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test output (callback mode)");
std::shared_ptr<testOutCallback> process = std::make_shared<testOutCallback>(manager, "speaker-jack");
std11::shared_ptr<testOutCallback> process = std::make_shared<testOutCallback>(manager, "speaker-jack");
process->run();
process.reset();
usleep(500000);
@ -248,10 +248,10 @@ TEST(TestALL, testOutputCallBackJack) {
class testInRead {
private:
std::vector<audio::channel> m_channelMap;
std::shared_ptr<river::Manager> m_manager;
std::shared_ptr<river::Interface> m_interface;
std11::shared_ptr<river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface;
public:
testInRead(std::shared_ptr<river::Manager> _manager) :
testInRead(std11::shared_ptr<river::Manager> _manager) :
m_manager(_manager){
//Set stereo output:
m_channelMap.push_back(audio::channel_frontLeft);
@ -280,10 +280,10 @@ class testInRead {
};
TEST(TestALL, testInputCallBack) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test input (callback mode)");
std::shared_ptr<testInCallback> process = std::make_shared<testInCallback>(manager);
std11::shared_ptr<testInCallback> process = std::make_shared<testInCallback>(manager);
process->run();
process.reset();
usleep(500000);
@ -292,11 +292,11 @@ TEST(TestALL, testInputCallBack) {
class testInCallback {
private:
std::shared_ptr<river::Manager> m_manager;
std::shared_ptr<river::Interface> m_interface;
std11::shared_ptr<river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface;
double m_phase;
public:
testInCallback(std::shared_ptr<river::Manager> _manager, const std::string& _input="microphone") :
testInCallback(std11::shared_ptr<river::Manager> _manager, const std::string& _input="microphone") :
m_manager(_manager),
m_phase(0) {
//Set stereo output:
@ -319,7 +319,7 @@ class testInCallback {
std::placeholders::_6));
}
void onDataReceived(const void* _data,
const std::chrono::system_clock::time_point& _time,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
@ -346,10 +346,10 @@ class testInCallback {
};
TEST(TestALL, testInputCallBack) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test input (callback mode)");
std::shared_ptr<testInCallback> process = std::make_shared<testInCallback>(manager);
std11::shared_ptr<testInCallback> process = std::make_shared<testInCallback>(manager);
process->run();
process.reset();
usleep(500000);
@ -359,15 +359,15 @@ TEST(TestALL, testInputCallBack) {
class testOutCallbackType {
private:
std::shared_ptr<river::Manager> m_manager;
std::shared_ptr<river::Interface> m_interface;
std11::shared_ptr<river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface;
double m_phase;
float m_freq;
int32_t m_nbChannels;
float m_generateFreq;
public:
testOutCallbackType(const std::shared_ptr<river::Manager>& _manager,
testOutCallbackType(const std11::shared_ptr<river::Manager>& _manager,
float _freq=48000.0f,
int32_t _nbChannels=2,
audio::format _format=audio::format_int16) :
@ -408,7 +408,7 @@ class testOutCallbackType {
std::placeholders::_6));
}
void onDataNeeded(void* _data,
const std::chrono::system_clock::time_point& _time,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
@ -477,9 +477,9 @@ class testOutCallbackType {
class testResampling : public ::testing::TestWithParam<float> {};
TEST_P(testResampling, base) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
std::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, GetParam(), 2, audio::format_int16);
std11::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, GetParam(), 2, audio::format_int16);
process->run();
process.reset();
usleep(500000);
@ -492,9 +492,9 @@ INSTANTIATE_TEST_CASE_P(InstantiationName,
class testFormat : public ::testing::TestWithParam<audio::format> {};
TEST_P(testFormat, base) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
std::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, 48000, 2, GetParam());
std11::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, 48000, 2, GetParam());
process->run();
process.reset();
usleep(500000);
@ -506,9 +506,9 @@ INSTANTIATE_TEST_CASE_P(InstantiationName,
class testChannels : public ::testing::TestWithParam<int32_t> {};
TEST_P(testChannels, base) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
std::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, 48000, GetParam(), audio::format_int16);
std11::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, 48000, GetParam(), audio::format_int16);
process->run();
process.reset();
usleep(500000);
@ -521,11 +521,11 @@ INSTANTIATE_TEST_CASE_P(InstantiationName,
class testCallbackVolume {
private:
std::shared_ptr<river::Manager> m_manager;
std::shared_ptr<river::Interface> m_interface;
std11::shared_ptr<river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface;
double m_phase;
public:
testCallbackVolume(std::shared_ptr<river::Manager> _manager) :
testCallbackVolume(std11::shared_ptr<river::Manager> _manager) :
m_manager(_manager),
m_phase(0) {
//Set stereo output:
@ -550,7 +550,7 @@ class testCallbackVolume {
m_interface->addVolumeGroup("FLOW");
}
void onDataNeeded(void* _data,
const std::chrono::system_clock::time_point& _time,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
@ -608,22 +608,22 @@ class testCallbackVolume {
};
void threadVolume(void* _userData) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
std::shared_ptr<testCallbackVolume> process = std::make_shared<testCallbackVolume>(manager);
std11::shared_ptr<testCallbackVolume> process = std::make_shared<testCallbackVolume>(manager);
process->run();
process.reset();
usleep(500000);
}
TEST(TestALL, testInputCallBackMicClean) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
std::thread tmpThread(&threadVolume, nullptr);
std11::thread tmpThread(&threadVolume, nullptr);
usleep(100000);
APPL_INFO("test input (callback mode)");
std::shared_ptr<testInCallback> process = std::make_shared<testInCallback>(manager, "microphone-clean");
std11::shared_ptr<testInCallback> process = std::make_shared<testInCallback>(manager, "microphone-clean");
process->run();
process.reset();
usleep(500000);
@ -632,16 +632,16 @@ TEST(TestALL, testInputCallBackMicClean) {
TEST(TestALL, testVolume) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
std::shared_ptr<testCallbackVolume> process = std::make_shared<testCallbackVolume>(manager);
std11::shared_ptr<testCallbackVolume> process = std::make_shared<testCallbackVolume>(manager);
process->run();
process.reset();
usleep(500000);
}
TEST(TestALL, testChannelsFormatResampling) {
std::shared_ptr<river::Manager> manager;
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test convert flaot to output (callback mode)");
std::vector<float> listFreq;
@ -670,7 +670,7 @@ TEST(TestALL, testChannelsFormatResampling) {
for (auto &itChannel : listChannel) {
for (auto &itFormat : listFormat) {
APPL_INFO("freq=" << itFreq << " channel=" << itChannel << " format=" << getFormatString(itFormat));
std::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, itFreq, itChannel, itFormat);
std11::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, itFreq, itChannel, itFormat);
process->run();
process.reset();
usleep(500000);