[DEV] WORK on a port for BOOST

This commit is contained in:
Edouard DUPIN 2015-02-24 22:20:11 +01:00
parent aa020d5e3c
commit 7af6577e64
21 changed files with 218 additions and 182 deletions

View File

@ -21,8 +21,8 @@ drain::Algo::Algo() :
void drain::Algo::init() {
// set notification callback :
m_input.setCallback(std::bind(&drain::Algo::configurationChangeLocal, this));
m_output.setCallback(std::bind(&drain::Algo::configurationChangeLocal, this));
m_input.setCallback(std11::bind(&drain::Algo::configurationChangeLocal, this));
m_output.setCallback(std11::bind(&drain::Algo::configurationChangeLocal, this));
// first configure ==> update the internal parameters
configurationChange();
}

View File

@ -13,15 +13,21 @@
#include <stdint.h>
#include <audio/format.h>
#include <audio/channel.h>
#include <chrono>
#include <functional>
#include <memory>
#if __cplusplus >= 201103L
#include <chrono>
#include <functional>
#include <memory>
#else
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#endif
#include "AutoLogInOut.h"
#include "IOFormatInterface.h"
#include "debug.h"
namespace drain{
class Algo : public std::enable_shared_from_this<Algo> {
class Algo : public std11::enable_shared_from_this<Algo> {
private:
std::string m_name;
public:
@ -110,7 +116,7 @@ namespace drain{
* @return true The process is done corectly
* @return false An error occured
*/
virtual bool process(std::chrono::system_clock::time_point& _time,
virtual bool process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,
@ -142,19 +148,19 @@ namespace drain{
return m_supportedFormat;
};
protected: // note when nothing ==> support all type
std::vector<std::vector<audio::channel>> m_supportedMap;
std::vector<std::vector<audio::channel> > m_supportedMap;
public:
virtual std::vector<std::vector<audio::channel>> getMapSupportedInput() {
virtual std::vector<std::vector<audio::channel> > getMapSupportedInput() {
if (m_output.getConfigured() == true) {
std::vector<std::vector<audio::channel>> out;
std::vector<std::vector<audio::channel> > out;
out.push_back(m_output.getMap());
return out;
}
return m_supportedMap;
};
virtual std::vector<std::vector<audio::channel>> getMapSupportedOutput() {
virtual std::vector<std::vector<audio::channel> > getMapSupportedOutput() {
if (m_input.getConfigured() == true) {
std::vector<std::vector<audio::channel>> out;
std::vector<std::vector<audio::channel> > out;
out.push_back(m_input.getMap());
return out;
}

View File

@ -23,8 +23,8 @@ void drain::ChannelReorder::init() {
m_type = "ChannelReorder";
}
std::shared_ptr<drain::ChannelReorder> drain::ChannelReorder::create() {
std::shared_ptr<drain::ChannelReorder> tmp(new drain::ChannelReorder());
std11::shared_ptr<drain::ChannelReorder> drain::ChannelReorder::create() {
std11::shared_ptr<drain::ChannelReorder> tmp(new drain::ChannelReorder());
tmp->init();
return tmp;
}
@ -49,7 +49,7 @@ void drain::ChannelReorder::configurationChange() {
}
bool drain::ChannelReorder::process(std::chrono::system_clock::time_point& _time,
bool drain::ChannelReorder::process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,

View File

@ -18,7 +18,7 @@ namespace drain{
ChannelReorder();
void init();
public:
static std::shared_ptr<ChannelReorder> create();
static std11::shared_ptr<ChannelReorder> create();
/**
* @brief Destructor
*/
@ -26,7 +26,7 @@ namespace drain{
protected:
virtual void configurationChange();
public:
virtual bool process(std::chrono::system_clock::time_point& _time,
virtual bool process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,

View File

@ -27,14 +27,14 @@ void drain::EndPointCallback::init(recordFunction _callback) {
m_type = "EndPointCallback";
}
std::shared_ptr<drain::EndPointCallback> drain::EndPointCallback::create(playbackFunction _callback) {
std::shared_ptr<drain::EndPointCallback> tmp(new drain::EndPointCallback());
std11::shared_ptr<drain::EndPointCallback> drain::EndPointCallback::create(playbackFunction _callback) {
std11::shared_ptr<drain::EndPointCallback> tmp(new drain::EndPointCallback());
tmp->init(_callback);
return tmp;
}
std::shared_ptr<drain::EndPointCallback> drain::EndPointCallback::create(recordFunction _callback) {
std::shared_ptr<drain::EndPointCallback> tmp(new drain::EndPointCallback());
std11::shared_ptr<drain::EndPointCallback> drain::EndPointCallback::create(recordFunction _callback) {
std11::shared_ptr<drain::EndPointCallback> tmp(new drain::EndPointCallback());
tmp->init(_callback);
return tmp;
}
@ -46,7 +46,7 @@ void drain::EndPointCallback::configurationChange() {
}
bool drain::EndPointCallback::process(std::chrono::system_clock::time_point& _time,
bool drain::EndPointCallback::process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,

View File

@ -8,22 +8,26 @@
#define __AIRT_ALGO_END_POINT_CALLBACK_H__
#include <drain/EndPoint.h>
#include <functional>
#if __cplusplus >= 201103L
#include <functional>
#else
#include <etk/functional.h>
#endif
namespace drain {
typedef std::function<void (void* _data,
const std::chrono::system_clock::time_point& _playTime,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map)> playbackFunction;
typedef std::function<void (const void* _data,
const std::chrono::system_clock::time_point& _readTime,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map)> recordFunction;
typedef std11::function<void (void* _data,
const std11::chrono::system_clock::time_point& _playTime,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map)> playbackFunction;
typedef std11::function<void (const void* _data,
const std11::chrono::system_clock::time_point& _readTime,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map)> recordFunction;
class EndPointCallback : public EndPoint {
private:
playbackFunction m_outputFunction;
@ -36,14 +40,14 @@ namespace drain {
void init(playbackFunction _callback);
void init(recordFunction _callback);
public:
static std::shared_ptr<EndPointCallback> create(playbackFunction _callback);
static std::shared_ptr<EndPointCallback> create(recordFunction _callback);
static std11::shared_ptr<EndPointCallback> create(playbackFunction _callback);
static std11::shared_ptr<EndPointCallback> create(recordFunction _callback);
/**
* @brief Destructor
*/
virtual ~EndPointCallback() {};
virtual void configurationChange();
virtual bool process(std::chrono::system_clock::time_point& _time,
virtual bool process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,

View File

@ -20,8 +20,8 @@ void drain::EndPointRead::init() {
m_type = "EndPointRead";
}
std::shared_ptr<drain::EndPointRead> drain::EndPointRead::create() {
std::shared_ptr<drain::EndPointRead> tmp(new drain::EndPointRead());
std11::shared_ptr<drain::EndPointRead> drain::EndPointRead::create() {
std11::shared_ptr<drain::EndPointRead> tmp(new drain::EndPointRead());
tmp->init();
return tmp;
}
@ -32,7 +32,7 @@ void drain::EndPointRead::configurationChange() {
}
bool drain::EndPointRead::process(std::chrono::system_clock::time_point& _time,
bool drain::EndPointRead::process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,

View File

@ -18,13 +18,13 @@ namespace drain{
EndPointRead();
void init();
public:
static std::shared_ptr<EndPointRead> create();
static std11::shared_ptr<EndPointRead> create();
/**
* @brief Destructor
*/
virtual ~EndPointRead() {};
virtual void configurationChange();
virtual bool process(std::chrono::system_clock::time_point& _time,
virtual bool process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,

View File

@ -20,8 +20,8 @@ void drain::EndPointWrite::init() {
m_type = "EndPoint";
}
std::shared_ptr<drain::EndPointWrite> drain::EndPointWrite::create() {
std::shared_ptr<drain::EndPointWrite> tmp(new drain::EndPointWrite());
std11::shared_ptr<drain::EndPointWrite> drain::EndPointWrite::create() {
std11::shared_ptr<drain::EndPointWrite> tmp(new drain::EndPointWrite());
tmp->init();
return tmp;
}
@ -32,7 +32,7 @@ void drain::EndPointWrite::configurationChange() {
}
bool drain::EndPointWrite::process(std::chrono::system_clock::time_point& _time,
bool drain::EndPointWrite::process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,
@ -50,7 +50,7 @@ bool drain::EndPointWrite::process(std::chrono::system_clock::time_point& _time,
// set output pointer:
_outputNbChunk = m_outputData.size()/(m_formatSize*m_output.getMap().size());
_output = &m_outputData[0];
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
// check if data in the tmpBuffer
if (m_tmpData.size() == 0) {
DRAIN_WARNING("No data in the user buffer (write null data ... " << _outputNbChunk << " chunks)");
@ -71,7 +71,7 @@ bool drain::EndPointWrite::process(std::chrono::system_clock::time_point& _time,
}
void drain::EndPointWrite::write(const void* _value, size_t _nbChunk) {
std::unique_lock<std::mutex> lock(m_mutex);
std11::unique_lock<std11::mutex> lock(m_mutex);
DRAIN_INFO("[ASYNC] Write data : " << _nbChunk << " chunks"
<< " ==> " << _nbChunk*m_output.getMap().size() << " samples"
<< " formatSize=" << int32_t(m_formatSize)

View File

@ -8,20 +8,25 @@
#define __AIRT_ALGO_ALGO_END_POINT_WRITE_H__
#include <drain/EndPoint.h>
#include <mutex>
#include <functional>
#if __cplusplus >= 201103L
#include <functional>
#include <mutex>
#else
#include <etk/functional.h>
#include <etk/mutex.h>
#endif
namespace drain{
typedef std::function<void (const std::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map)> playbackFunctionWrite;
typedef std11::function<void (const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map)> playbackFunctionWrite;
class EndPointWrite : public EndPoint {
private:
std::vector<int8_t> m_tmpData;
playbackFunctionWrite m_function;
std::mutex m_mutex;
std11::mutex m_mutex;
protected:
/**
* @brief Constructor
@ -29,13 +34,13 @@ namespace drain{
EndPointWrite();
void init();
public:
static std::shared_ptr<EndPointWrite> create();
static std11::shared_ptr<EndPointWrite> create();
/**
* @brief Destructor
*/
virtual ~EndPointWrite() {};
virtual void configurationChange();
virtual bool process(std::chrono::system_clock::time_point& _time,
virtual bool process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,

View File

@ -136,8 +136,8 @@ void drain::FormatUpdate::init() {
m_type = "FormatUpdate";
}
std::shared_ptr<drain::FormatUpdate> drain::FormatUpdate::create() {
std::shared_ptr<drain::FormatUpdate> tmp(new drain::FormatUpdate());
std11::shared_ptr<drain::FormatUpdate> drain::FormatUpdate::create() {
std11::shared_ptr<drain::FormatUpdate> tmp(new drain::FormatUpdate());
tmp->init();
return tmp;
}
@ -243,7 +243,7 @@ void drain::FormatUpdate::configurationChange() {
}
bool drain::FormatUpdate::process(std::chrono::system_clock::time_point& _time,
bool drain::FormatUpdate::process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,

View File

@ -17,7 +17,7 @@ namespace drain {
FormatUpdate();
void init();
public:
static std::shared_ptr<FormatUpdate> create();
static std11::shared_ptr<FormatUpdate> create();
/**
* @brief Destructor
*/
@ -25,7 +25,7 @@ namespace drain {
protected:
virtual void configurationChange();
public:
virtual bool process(std::chrono::system_clock::time_point& _time,
virtual bool process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,

View File

@ -113,7 +113,6 @@ void drain::IOFormatInterface::configurationChange() {
m_ioChangeFunctor();
}
}
void drain::IOFormatInterface::setCallback(const std::function<void()>& _functor) {
void drain::IOFormatInterface::setCallback(const std11::function<void()>& _functor) {
m_ioChangeFunctor = _functor;
}

View File

@ -13,9 +13,15 @@
#include <stdint.h>
#include <audio/format.h>
#include <audio/channel.h>
#include <chrono>
#include <functional>
#include <memory>
#if __cplusplus >= 201103L
#include <chrono>
#include <functional>
#include <memory>
#else
#include <etk/chrono.h>
#include <etk/functional.h>
#include <etk/memory.h>
#endif
#include "AutoLogInOut.h"
#include "debug.h"
@ -70,14 +76,14 @@ namespace drain{
*/
void setFrequency(float _value);
protected:
std::function<void()> m_ioChangeFunctor; //!< function pointer on the upper class
std11::function<void()> m_ioChangeFunctor; //!< function pointer on the upper class
void configurationChange();
public:
/**
* @brief Set the callback function to be notify when the arameter change.
* @param[in] _functor Function to call.
*/
void setCallback(const std::function<void()>& _functor);
void setCallback(const std11::function<void()>& _functor);
};
std::ostream& operator <<(std::ostream& _os, const IOFormatInterface& _obj);
}

View File

@ -15,7 +15,6 @@
#include <drain/ChannelReorder.h>
#include <drain/FormatUpdate.h>
#include <drain/Resampler.h>
#include <chrono>
#undef __class__
#define __class__ "Process"
@ -25,12 +24,12 @@ drain::Process::Process() :
m_data.clear();
}
drain::Process::~Process() {
for (auto &it : m_listAlgo) {
it.reset();
for (size_t iii=0; iii<m_listAlgo.size(); ++iii) {
m_listAlgo[iii].reset();
}
}
bool drain::Process::push(std::chrono::system_clock::time_point& _time,
bool drain::Process::push(std11::chrono::system_clock::time_point& _time,
void* _data,
size_t _nbChunk) {
void* out = nullptr;
@ -40,7 +39,7 @@ bool drain::Process::push(std::chrono::system_clock::time_point& _time,
return true;
}
bool drain::Process::pull(std::chrono::system_clock::time_point& _time,
bool drain::Process::pull(std11::chrono::system_clock::time_point& _time,
void* _data,
size_t _nbChunk,
size_t _chunkSize) {
@ -89,7 +88,7 @@ bool drain::Process::pull(std::chrono::system_clock::time_point& _time,
}
bool drain::Process::process(std::chrono::system_clock::time_point& _time,
bool drain::Process::process(std11::chrono::system_clock::time_point& _time,
void* _inData,
size_t _inNbChunk,
void*& _outData,
@ -112,12 +111,12 @@ bool drain::Process::process(std::chrono::system_clock::time_point& _time,
return true;
}
void drain::Process::pushBack(const std::shared_ptr<drain::Algo>& _algo) {
void drain::Process::pushBack(const std11::shared_ptr<drain::Algo>& _algo) {
removeAlgoDynamic();
m_listAlgo.push_back(_algo);
}
void drain::Process::pushFront(const std::shared_ptr<drain::Algo>& _algo) {
void drain::Process::pushFront(const std11::shared_ptr<drain::Algo>& _algo) {
removeAlgoDynamic();
m_listAlgo.insert(m_listAlgo.begin(), _algo);
}
@ -132,10 +131,10 @@ template<typename T> std::vector<T> getUnion(const std::vector<T>& _out, const s
// next is ok for all format
} else {
// must check all values
for (auto &itOut : _out) {
for (auto &itIn : _in) {
if (itOut == itIn) {
out.push_back(itOut);
for (size_t ooo=0; ooo<_out.size(); ++ooo) {
for (size_t iii=0; iii<_in.size(); ++iii) {
if (_out[ooo] == _in[iii]) {
out.push_back(_out[ooo]);
}
}
}
@ -146,23 +145,23 @@ template<typename T> std::vector<T> getUnion(const std::vector<T>& _out, const s
void drain::Process::displayAlgo() {
DRAIN_DEBUG(" Input : " << m_inputConfig);
for (auto &it : m_listAlgo) {
DRAIN_DEBUG(" [" << it->getType() << "] '" << it->getName() << "'");
if (it->getInputFormat().getConfigured() == true) {
DRAIN_DEBUG(" Input : " << it->getInputFormat());
for (size_t iii=0; iii<m_listAlgo.size(); ++iii) {
DRAIN_DEBUG(" [" << m_listAlgo[iii]->getType() << "] '" << m_listAlgo[iii]->getName() << "'");
if (m_listAlgo[iii]->getInputFormat().getConfigured() == true) {
DRAIN_DEBUG(" Input : " << m_listAlgo[iii]->getInputFormat());
} else {
DRAIN_DEBUG(" Input : Not configured");
DRAIN_DEBUG(" format : " << it->getFormatSupportedInput());
DRAIN_DEBUG(" frequency : " << it->getFrequencySupportedInput());
DRAIN_DEBUG(" map : " << it->getMapSupportedInput());
DRAIN_DEBUG(" format : " << m_listAlgo[iii]->getFormatSupportedInput());
DRAIN_DEBUG(" frequency : " << m_listAlgo[iii]->getFrequencySupportedInput());
DRAIN_DEBUG(" map : " << m_listAlgo[iii]->getMapSupportedInput());
}
if (it->getOutputFormat().getConfigured() == true) {
DRAIN_DEBUG(" Output: " << it->getOutputFormat());
if (m_listAlgo[iii]->getOutputFormat().getConfigured() == true) {
DRAIN_DEBUG(" Output: " << m_listAlgo[iii]->getOutputFormat());
} else {
DRAIN_DEBUG(" Output : Not configured");
DRAIN_DEBUG(" format : " << it->getFormatSupportedOutput());
DRAIN_DEBUG(" frequency : " << it->getFrequencySupportedOutput());
DRAIN_DEBUG(" map : " << it->getMapSupportedOutput());
DRAIN_DEBUG(" format : " << m_listAlgo[iii]->getFormatSupportedOutput());
DRAIN_DEBUG(" frequency : " << m_listAlgo[iii]->getFrequencySupportedOutput());
DRAIN_DEBUG(" map : " << m_listAlgo[iii]->getMapSupportedOutput());
}
}
DRAIN_DEBUG(" Output : " << m_outputConfig);
@ -200,8 +199,8 @@ void drain::Process::updateAlgo(size_t _position) {
DRAIN_DEBUG(" freq union :" << freq);
// step 2 : Check map:
std::vector<std::vector<audio::channel>> mapOut;
std::vector<std::vector<audio::channel>> mapIn;
std::vector<std::vector<audio::channel> > mapOut;
std::vector<std::vector<audio::channel> > mapIn;
if (_position == 0) {
mapOut.push_back(m_inputConfig.getMap());
} else {
@ -212,7 +211,7 @@ void drain::Process::updateAlgo(size_t _position) {
} else {
mapIn = m_listAlgo[_position]->getMapSupportedInput();
}
std::vector<std::vector<audio::channel>> map = getUnion<std::vector<audio::channel>>(mapOut, mapIn);
std::vector<std::vector<audio::channel> > map = getUnion<std::vector<audio::channel> >(mapOut, mapIn);
DRAIN_VERBOSE(" map out :" << mapOut);
DRAIN_VERBOSE(" map in :" << mapIn);
DRAIN_DEBUG(" map union :" << map);
@ -343,7 +342,7 @@ void drain::Process::updateAlgo(size_t _position) {
if ( out.getFormat() != audio::format_int16
/* && out.getFormat() != format_float */) {
// need add a format Updater
std::shared_ptr<drain::FormatUpdate> algo = drain::FormatUpdate::create();
std11::shared_ptr<drain::FormatUpdate> algo = drain::FormatUpdate::create();
algo->setTemporary();
algo->setInputFormat(out);
out.setFormat(audio::format_int16);
@ -353,7 +352,7 @@ void drain::Process::updateAlgo(size_t _position) {
_position++;
}
// need add a resampler
std::shared_ptr<drain::Resampler> algo = drain::Resampler::create();
std11::shared_ptr<drain::Resampler> algo = drain::Resampler::create();
algo->setTemporary();
algo->setInputFormat(out);
out.setFrequency(in.getFrequency());
@ -365,7 +364,7 @@ void drain::Process::updateAlgo(size_t _position) {
}
if (out.getMap() != in.getMap()) {
// need add a channel Reorder
std::shared_ptr<drain::ChannelReorder> algo = drain::ChannelReorder::create();
std11::shared_ptr<drain::ChannelReorder> algo = drain::ChannelReorder::create();
algo->setTemporary();
algo->setInputFormat(out);
out.setMap(in.getMap());
@ -376,7 +375,7 @@ void drain::Process::updateAlgo(size_t _position) {
}
if (out.getFormat() != in.getFormat()) {
// need add a format Updater
std::shared_ptr<drain::FormatUpdate> algo = drain::FormatUpdate::create();
std11::shared_ptr<drain::FormatUpdate> algo = drain::FormatUpdate::create();
algo->setTemporary();
algo->setInputFormat(out);
out.setFormat(in.getFormat());

View File

@ -14,8 +14,13 @@
#include <audio/format.h>
#include <audio/channel.h>
#include <drain/Algo.h>
#include <chrono>
#include <memory>
#if __cplusplus >= 201103L
#include <memory>
#include <chrono>
#else
#include <etk/chrono.h>
#include <etk/memory.h>
#endif
namespace drain{
class Process {
@ -33,7 +38,7 @@ namespace drain{
* @return true The procress is done corectly.
* @return false An error occured.
*/
bool push(std::chrono::system_clock::time_point& _time,
bool push(std11::chrono::system_clock::time_point& _time,
void* _data,
size_t _nbChunk);
/**
@ -45,7 +50,7 @@ namespace drain{
* @return true The procress is done corectly.
* @return false An error occured.
*/
bool pull(std::chrono::system_clock::time_point& _time,
bool pull(std11::chrono::system_clock::time_point& _time,
void* _data,
size_t _nbChunk,
size_t _chunkSize);
@ -59,7 +64,7 @@ namespace drain{
* @return true The procress is done corectly.
* @return false An error occured.
*/
bool process(std::chrono::system_clock::time_point& _time,
bool process(std11::chrono::system_clock::time_point& _time,
void* _inData,
size_t _inNbChunk,
void*& _outData,
@ -68,7 +73,7 @@ namespace drain{
size_t _inNbChunk,
void*& _outData,
size_t& _outNbChunk) {
std::chrono::system_clock::time_point time;
std11::chrono::system_clock::time_point time;
return process(time, _inData, _inNbChunk, _outData, _outNbChunk);
}
bool processIn(void* _inData,
@ -94,10 +99,10 @@ namespace drain{
m_outputConfig = _interface;
}
protected:
std::vector<std::shared_ptr<drain::Algo> > m_listAlgo;
std::vector<std11::shared_ptr<drain::Algo> > m_listAlgo;
public:
void pushBack(const std::shared_ptr<drain::Algo>& _algo);
void pushFront(const std::shared_ptr<drain::Algo>& _algo);
void pushBack(const std11::shared_ptr<drain::Algo>& _algo);
void pushFront(const std11::shared_ptr<drain::Algo>& _algo);
void clear() {
m_isConfigured = false;
m_listAlgo.clear();
@ -105,16 +110,41 @@ namespace drain{
size_t size() {
return m_listAlgo.size();
}
std::vector<std::shared_ptr<drain::Algo> >::iterator begin() {
std::vector<std11::shared_ptr<drain::Algo> >::iterator begin() {
return m_listAlgo.begin();
}
std::vector<std::shared_ptr<drain::Algo> >::iterator end() {
std::vector<std11::shared_ptr<drain::Algo> >::iterator end() {
return m_listAlgo.end();
}
template<typename T> std11::shared_ptr<T> get(const std::string& _name) {
for (size_t iii=0; iii<m_listAlgo.size(); ++iii) {
if (m_listAlgo[iii] == nullptr) {
continue;
}
if (m_listAlgo[iii]->getName() == _name) {
return std11::dynamic_pointer_cast<T>(m_listAlgo[iii]);
}
}
return std11::shared_ptr<T>();
}
template<typename T> std11::shared_ptr<const T> get(const std::string& _name) const {
for (size_t iii=0; iii<m_listAlgo.size(); ++iii) {
if (m_listAlgo[iii] == nullptr) {
continue;
}
if (m_listAlgo[iii]->getName() == _name) {
return std11::dynamic_pointer_cast<T>(m_listAlgo[iii]);
}
}
return std11::shared_ptr<const T>();
}
template<typename T> std11::shared_ptr<T> get(int32_t _id) {
return std11::dynamic_pointer_cast<T>(m_listAlgo[_id]);
}
template<typename T> void removeIfFirst() {
if (m_listAlgo.size() > 0) {
std::shared_ptr<T> algoEP = std::dynamic_pointer_cast<T>(m_listAlgo[0]);
std11::shared_ptr<T> algoEP = get<T>(0);
if (algoEP != nullptr) {
m_listAlgo.erase(m_listAlgo.begin());
}
@ -122,40 +152,15 @@ namespace drain{
}
template<typename T> void removeIfLast() {
if (m_listAlgo.size() > 0) {
std::shared_ptr<T> algoEP = std::dynamic_pointer_cast<T>(m_listAlgo[m_listAlgo.size()-1]);
std11::shared_ptr<T> algoEP = get<T>(m_listAlgo.size()-1);
if (algoEP != nullptr) {
m_listAlgo.erase(m_listAlgo.begin()+m_listAlgo.size()-1);
}
}
}
template<typename T> std::shared_ptr<T> get(int32_t _id) {
return std::dynamic_pointer_cast<T>(m_listAlgo[_id]);
}
template<typename T> std::shared_ptr<T> get(const std::string& _name) {
for (auto &it : m_listAlgo) {
if (it == nullptr) {
continue;
}
if (it->getName() == _name) {
return std::dynamic_pointer_cast<T>(it);
}
}
return nullptr;
}
template<typename T> std::shared_ptr<const T> get(const std::string& _name) const {
for (auto &it : m_listAlgo) {
if (it == nullptr) {
continue;
}
if (it->getName() == _name) {
return std::dynamic_pointer_cast<T>(it);
}
}
return nullptr;
}
template<typename T> bool hasType() {
for (auto &it : m_listAlgo) {
std::shared_ptr<T> tmp = std::dynamic_pointer_cast<T>(it);
for (size_t iii=0; iii<m_listAlgo.size(); ++iii) {
std11::shared_ptr<T> tmp = std11::dynamic_pointer_cast<T>(m_listAlgo[iii]);
if (tmp != nullptr) {
return true;
}

View File

@ -26,8 +26,8 @@ void drain::Resampler::init() {
m_supportedFormat.push_back(audio::format_int16);
}
std::shared_ptr<drain::Resampler> drain::Resampler::create() {
std::shared_ptr<drain::Resampler> tmp(new drain::Resampler());
std11::shared_ptr<drain::Resampler> drain::Resampler::create() {
std11::shared_ptr<drain::Resampler> tmp(new drain::Resampler());
tmp->init();
return tmp;
}
@ -84,8 +84,8 @@ void drain::Resampler::configurationChange() {
}
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;
@ -102,7 +102,7 @@ namespace std {
}
}
bool drain::Resampler::process(std::chrono::system_clock::time_point& _time,
bool drain::Resampler::process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,
@ -126,7 +126,7 @@ bool drain::Resampler::process(std::chrono::system_clock::time_point& _time,
DRAIN_VERBOSE("Resampler correct timestamp : " << _time << " ==> " << (_time - m_residualTimeInResampler));
_time -= m_residualTimeInResampler;
std::chrono::nanoseconds inTime((int64_t(_inputNbChunk)*int64_t(1000000000)) / int64_t(m_input.getFrequency()));
std11::chrono::nanoseconds inTime((int64_t(_inputNbChunk)*int64_t(1000000000)) / int64_t(m_input.getFrequency()));
m_residualTimeInResampler += inTime;
#ifdef HAVE_SPEEX_DSP_RESAMPLE
float nbInputTime = float(_inputNbChunk)/m_input.getFrequency();
@ -165,7 +165,7 @@ bool drain::Resampler::process(std::chrono::system_clock::time_point& _time,
}
_outputNbChunk = nbChunkOutput;
DRAIN_VERBOSE(" process chunk=" << nbChunkInput << " out=" << nbChunkOutput);
std::chrono::nanoseconds outTime((int64_t(_outputNbChunk)*int64_t(1000000000)) / int64_t(m_output.getFrequency()));
std11::chrono::nanoseconds outTime((int64_t(_outputNbChunk)*int64_t(1000000000)) / int64_t(m_output.getFrequency()));
// correct time :
m_residualTimeInResampler -= outTime;
/*

View File

@ -11,7 +11,11 @@
#ifdef HAVE_SPEEX_DSP_RESAMPLE
#include <speex/speex_resampler.h>
#endif
#include <memory>
#if __cplusplus >= 201103L
#include <memory>
#else
#include <etk/memory.h>
#endif
namespace drain {
// TODO: Manage change timestamp when pull mode
@ -30,7 +34,7 @@ namespace drain {
Resampler();
void init();
public:
static std::shared_ptr<Resampler> create();
static std11::shared_ptr<Resampler> create();
/**
* @brief Destructor
*/
@ -38,13 +42,13 @@ namespace drain {
protected:
virtual void configurationChange();
public:
virtual bool process(std::chrono::system_clock::time_point& _time,
virtual bool process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,
size_t& _outputNbChunk);
private:
std::chrono::nanoseconds m_residualTimeInResampler; //!< the time of data locked in the resampler ...
std11::chrono::nanoseconds m_residualTimeInResampler; //!< the time of data locked in the resampler ...
};
};

View File

@ -25,8 +25,8 @@ void drain::Volume::init() {
m_supportedFormat.push_back(audio::format_int16_on_int32);
}
std::shared_ptr<drain::Volume> drain::Volume::create() {
std::shared_ptr<drain::Volume> tmp(new drain::Volume());
std11::shared_ptr<drain::Volume> drain::Volume::create() {
std11::shared_ptr<drain::Volume> tmp(new drain::Volume());
tmp->init();
return tmp;
}
@ -155,15 +155,15 @@ void drain::Volume::configurationChange() {
void drain::Volume::volumeChange() {
//m_volumeAppli = 20 * log(m_volumedB);
float volumedB = 0.0f;
for (auto &it : m_volumeList) {
if (it == nullptr) {
for (size_t iii=0; iii<m_volumeList.size(); ++iii) {
if (m_volumeList[iii] == nullptr) {
continue;
}
volumedB += it->getVolume();
DRAIN_VERBOSE("append volume : '" << it->getName() << " vol=" << it->getVolume() << "dB");
volumedB += m_volumeList[iii]->getVolume();
DRAIN_VERBOSE("append volume : '" << m_volumeList[iii]->getName() << " vol=" << m_volumeList[iii]->getVolume() << "dB");
}
DRAIN_DEBUG(" Total volume : " << volumedB << "dB nbVolume=" << m_volumeList.size());
#if (defined(__TARGET_OS__MacOs) || defined(__TARGET_OS__IOs))
#if (defined(__TARGET_OS__MacOs) || defined(__TARGET_OS__IOs) || __cplusplus < 201103L)
m_volumeAppli = pow(10.0f, volumedB/20.0f);
#else
m_volumeAppli = std::pow(10.0f, volumedB/20.0f);
@ -304,7 +304,7 @@ std::vector<audio::format> drain::Volume::getFormatSupportedOutput() {
};
bool drain::Volume::process(std::chrono::system_clock::time_point& _time,
bool drain::Volume::process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,
@ -334,19 +334,19 @@ bool drain::Volume::process(std::chrono::system_clock::time_point& _time,
return true;
}
void drain::Volume::addVolumeStage(const std::shared_ptr<VolumeElement>& _volume) {
void drain::Volume::addVolumeStage(const std11::shared_ptr<VolumeElement>& _volume) {
if (_volume == nullptr) {
return;
}
for (auto &it : m_volumeList) {
if (it == nullptr) {
for (size_t iii=0; iii<m_volumeList.size(); ++iii) {
if (m_volumeList[iii] == nullptr) {
continue;
}
if (it == _volume) {
if (m_volumeList[iii] == _volume) {
// already done ...
return;
}
if (it->getName() == _volume->getName()) {
if (m_volumeList[iii]->getName() == _volume->getName()) {
return;
}
}
@ -357,11 +357,11 @@ void drain::Volume::addVolumeStage(const std::shared_ptr<VolumeElement>& _volume
bool drain::Volume::setParameter(const std::string& _parameter, const std::string& _value) {
if (_parameter == "FLOW") {
// set Volume ...
for (auto &it : m_volumeList) {
if (it == nullptr) {
for (size_t iii=0; iii<m_volumeList.size(); ++iii) {
if (m_volumeList[iii] == nullptr) {
continue;
}
if (it->getName() == "FLOW") {
if (m_volumeList[iii]->getName() == "FLOW") {
float value = 0;
if (sscanf(_value.c_str(), "%fdB", &value) != 1) {
return false;
@ -371,7 +371,7 @@ bool drain::Volume::setParameter(const std::string& _parameter, const std::strin
DRAIN_ERROR("Can not set volume ... : '" << _parameter << "' out of range : [-300..300]");
return false;
}
it->setVolume(value);
m_volumeList[iii]->setVolume(value);
DRAIN_DEBUG("Set volume : FLOW = " << value << " dB (from:" << _value << ")");
volumeChange();
return true;
@ -385,12 +385,12 @@ bool drain::Volume::setParameter(const std::string& _parameter, const std::strin
std::string drain::Volume::getParameter(const std::string& _parameter) const {
if (_parameter == "FLOW") {
// set Volume ...
for (auto &it : m_volumeList) {
if (it == nullptr) {
for (size_t iii=0; iii<m_volumeList.size(); ++iii) {
if (m_volumeList[iii] == nullptr) {
continue;
}
if (it->getName() == "FLOW") {
return std::to_string(it->getVolume()) + "dB";
if (m_volumeList[iii]->getName() == "FLOW") {
return etk::to_string(m_volumeList[iii]->getVolume()) + "dB";
}
}
}
@ -401,11 +401,11 @@ std::string drain::Volume::getParameter(const std::string& _parameter) const {
std::string drain::Volume::getParameterProperty(const std::string& _parameter) const {
if (_parameter == "FLOW") {
// set Volume ...
for (auto &it : m_volumeList) {
if (it == nullptr) {
for (size_t iii=0; iii<m_volumeList.size(); ++iii) {
if (m_volumeList[iii] == nullptr) {
continue;
}
if (it->getName() == "FLOW") {
if (m_volumeList[iii]->getName() == "FLOW") {
return "[-300..300]dB";
}
}

View File

@ -11,7 +11,11 @@
#ifdef HAVE_SPEEX_DSP_RESAMPLE
#include <speex/speex_resampler.h>
#endif
#include <memory>
#if __cplusplus >= 201103L
#include <memory>
#else
#include <etk/memory.h>
#endif
namespace drain {
// data structure.
@ -45,7 +49,7 @@ namespace drain {
// TODO: Manage set volume
class Volume : public Algo {
private:
std::vector<std::shared_ptr<drain::VolumeElement>> m_volumeList;
std::vector<std11::shared_ptr<drain::VolumeElement> > m_volumeList;
// for float input :
float m_volumeAppli;
// for integer input :
@ -60,7 +64,7 @@ namespace drain {
Volume();
void init();
public:
static std::shared_ptr<Volume> create();
static std11::shared_ptr<Volume> create();
/**
* @brief Destructor
*/
@ -68,7 +72,7 @@ namespace drain {
protected:
virtual void configurationChange();
public:
virtual bool process(std::chrono::system_clock::time_point& _time,
virtual bool process(std11::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,
@ -77,7 +81,7 @@ namespace drain {
virtual std::vector<audio::format> getFormatSupportedInput();
virtual std::vector<audio::format> getFormatSupportedOutput();
public:
virtual void addVolumeStage(const std::shared_ptr<drain::VolumeElement>& _volume);
virtual void addVolumeStage(const std11::shared_ptr<drain::VolumeElement>& _volume);
virtual bool setParameter(const std::string& _parameter, const std::string& _value);
virtual std::string getParameter(const std::string& _parameter) const;
virtual std::string getParameterProperty(const std::string& _parameter) const;

View File

@ -10,7 +10,11 @@
#include <string>
#include <audio/format.h>
#include <drain/channel.h>
#include <chrono>
#if __cplusplus >= 201103L
#include <chrono>
#else
#include <etk/chrono.h>
#endif
namespace drain {
/**