[DEV] work on dynamic channels

This commit is contained in:
Edouard DUPIN 2015-02-01 22:22:42 +01:00
parent 9675696930
commit 57ec4acb9d
17 changed files with 340 additions and 45 deletions

View File

@ -7,10 +7,25 @@
#include <functional>
#include "debug.h"
std::ostream& airtalgo::operator <<(std::ostream& _os, const IOFormatInterface& _obj) {
_os << "{";
if (_obj.getConfigured() == false) {
_os << "Not configured";
} else {
_os << "format=" << _obj.getFormat();
_os << ", frequency=" << _obj.getFrequency();
_os << ", map=" << _obj.getMap();
}
_os << "}";
return _os;
}
#undef __class__
#define __class__ "Algo"
airtalgo::Algo::Algo() :
m_temporary(false),
m_outputData(),
m_formatSize(0),
m_needProcess(false) {
@ -19,8 +34,8 @@ airtalgo::Algo::Algo() :
void airtalgo::Algo::init() {
// set notification callback :
m_input.setCallback(std::bind(&airtalgo::Algo::configurationChange, this));
m_output.setCallback(std::bind(&airtalgo::Algo::configurationChange, this));
m_input.setCallback(std::bind(&airtalgo::Algo::configurationChangeLocal, this));
m_output.setCallback(std::bind(&airtalgo::Algo::configurationChangeLocal, this));
// first configure ==> update the internal parameters
configurationChange();
}
@ -47,6 +62,10 @@ void airtalgo::Algo::configurationChange() {
case format_float:
m_formatSize = sizeof(float);
break;
case format_unknow:
AIRTALGO_ERROR("format not configured...");
m_formatSize = 8;
break;
}
}

View File

@ -34,17 +34,49 @@ namespace airtalgo{
class IOFormatInterface {
public:
IOFormatInterface() :
m_format(airtalgo::format_int16),
m_configured(false),
m_format(airtalgo::format_unknow),
m_map(),
m_frequency(48000) {
m_frequency(0) {
m_map.push_back(airtalgo::channel_frontLeft);
m_map.push_back(airtalgo::channel_frontRight);
}
IOFormatInterface(std::vector<airtalgo::channel> _map, airtalgo::format _format=airtalgo::format_int16, float _frequency=48000) :
IOFormatInterface(std::vector<airtalgo::channel> _map, airtalgo::format _format=airtalgo::format_int16, float _frequency=48000.0f) :
m_configured(true),
m_format(_format),
m_map(_map),
m_frequency(_frequency) {
AIRTALGO_WARNING(" plop : " << m_map << " " << m_format << " " << m_frequency);
}
void set(std::vector<airtalgo::channel> _map, airtalgo::format _format=airtalgo::format_int16, float _frequency=48000.0f) {
bool hasChange = false;
if (m_map != _map) {
m_map = _map;
hasChange = true;
}
if (m_format != _format) {
m_format = _format;
hasChange = true;
}
if (m_frequency == _frequency) {
m_frequency = _frequency;
hasChange = true;
}
if (hasChange == true) {
m_configured = true;
configurationChange();
}
AIRTALGO_WARNING(" plop : " << m_map << " " << m_format << " " << m_frequency);
}
protected:
bool m_configured;
public:
void setConfigured(bool _value) {
m_configured = _value;
}
bool getConfigured() const {
return m_configured;
}
protected:
airtalgo::format m_format; //!< input Algo Format
@ -65,6 +97,7 @@ namespace airtalgo{
return;
}
m_format = _value;
m_configured = true;
configurationChange();
}
protected:
@ -87,6 +120,7 @@ namespace airtalgo{
return;
}
m_map = _value;
m_configured = true;
AIRTALGO_DEBUG(" base2 : " << m_map);
configurationChange();
}
@ -108,6 +142,7 @@ namespace airtalgo{
if (m_frequency == _value) {
return;
}
m_configured = true;
m_frequency = _value;
configurationChange();
}
@ -128,6 +163,7 @@ namespace airtalgo{
}
};
std::ostream& operator <<(std::ostream& _os, const IOFormatInterface& _obj);
class Algo : public std::enable_shared_from_this<Algo> {
private:
@ -139,6 +175,24 @@ namespace airtalgo{
void setName(const std::string& _name) {
m_name = _name;
}
protected:
std::string m_type;
public:
const std::string& getType() const {
return m_type;
}
void setType(const std::string& _name) {
m_type = _name;
}
private:
bool m_temporary;
public:
void setTemporary() {
m_temporary = true;
}
bool getTemporary() const {
return m_temporary;
}
protected:
std::vector<int8_t> m_outputData;
int8_t m_formatSize; //!< sample size
@ -157,24 +211,36 @@ namespace airtalgo{
IOFormatInterface m_input; //!< Input audio property
public:
void setInputFormat(const IOFormatInterface& _format) {
m_input.setFormat(_format.getFormat());
m_input.setFrequency(_format.getFrequency());
m_input.setMap(_format.getMap());
AIRTALGO_WARNING(" plopp : " << _format.getMap() << " " << _format.getFormat() << " " << _format.getFrequency());
m_input.set(_format.getMap(), _format.getFormat(), _format.getFrequency());
}
const IOFormatInterface& getInputFormat() const {
return m_input;
}
IOFormatInterface& getInputFormat() {
return m_input;
}
protected:
IOFormatInterface m_output; //!< Output audio property
public:
void setOutputFormat(const IOFormatInterface& _format) {
m_output.setFormat(_format.getFormat());
m_output.setFrequency(_format.getFrequency());
m_output.setMap(_format.getMap());
AIRTALGO_WARNING(" plopp : " << _format.getMap() << " " << _format.getFormat() << " " << _format.getFrequency());
m_output.set(_format.getMap(), _format.getFormat(), _format.getFrequency());
}
const IOFormatInterface& getOutputFormat() const {
return m_output;
}
IOFormatInterface& getOutputFormat() {
return m_output;
}
private:
void configurationChangeLocal() {
if ( m_output.getConfigured() == true
&& m_output.getConfigured() == true) {
configurationChange();
}
}
public:
/**
* @brief Called when a parameter change
*/
@ -201,6 +267,63 @@ namespace airtalgo{
* @return number of sample needed to have nearly the good number of sample
*/
virtual size_t needInputData(size_t _output);
protected: // note when nothing ==> support all type
std::vector<airtalgo::format> m_supportedFormat;
public:
virtual std::vector<airtalgo::format> getFormatSupportedInput() {
if (m_output.getConfigured() == true) {
std::vector<airtalgo::format> out;
out.push_back(m_output.getFormat());
return out;
}
return m_supportedFormat;
};
virtual std::vector<airtalgo::format> getFormatSupportedOutput() {
if (m_input.getConfigured() == true) {
std::vector<airtalgo::format> out;
out.push_back(m_input.getFormat());
return out;
}
return m_supportedFormat;
};
protected: // note when nothing ==> support all type
std::vector<std::vector<airtalgo::channel>> m_supportedMap;
public:
virtual std::vector<std::vector<airtalgo::channel>> getMapSupportedInput() {
if (m_output.getConfigured() == true) {
std::vector<std::vector<airtalgo::channel>> out;
out.push_back(m_output.getMap());
return out;
}
return m_supportedMap;
};
virtual std::vector<std::vector<airtalgo::channel>> getMapSupportedOutput() {
if (m_input.getConfigured() == true) {
std::vector<std::vector<airtalgo::channel>> out;
out.push_back(m_input.getMap());
return out;
}
return m_supportedMap;
};
protected: // note when nothing ==> support all type
std::vector<float> m_supportedFrequency;
public:
virtual std::vector<float> getFrequencySupportedInput() {
if (m_output.getConfigured() == true) {
std::vector<float> out;
out.push_back(m_output.getFrequency());
return out;
}
return m_supportedFrequency;
};
virtual std::vector<float> getFrequencySupportedOutput() {
if (m_input.getConfigured() == true) {
std::vector<float> out;
out.push_back(m_input.getFrequency());
return out;
}
return m_supportedFrequency;
};
};
};
#include "debugRemove.h"

View File

@ -20,6 +20,7 @@ airtalgo::ChannelReorder::ChannelReorder() {
void airtalgo::ChannelReorder::init() {
airtalgo::Algo::init();
m_type = "ChannelReorder";
}
std::shared_ptr<airtalgo::ChannelReorder> airtalgo::ChannelReorder::create() {

View File

@ -19,10 +19,12 @@ airtalgo::EndPointCallback::EndPointCallback() :
void airtalgo::EndPointCallback::init(needDataFunction _callback) {
m_outputFunction = _callback;
airtalgo::EndPoint::init();
m_type = "EndPointCallback";
}
void airtalgo::EndPointCallback::init(haveNewDataFunction _callback) {
m_inputFunction = _callback;
airtalgo::EndPoint::init();
m_type = "EndPointCallback";
}
std::shared_ptr<airtalgo::EndPointCallback> airtalgo::EndPointCallback::create(needDataFunction _callback) {

View File

@ -17,6 +17,7 @@ airtalgo::EndPointRead::EndPointRead() {
void airtalgo::EndPointRead::init() {
airtalgo::EndPoint::init();
m_type = "EndPointRead";
}
std::shared_ptr<airtalgo::EndPointRead> airtalgo::EndPointRead::create() {

View File

@ -17,6 +17,7 @@ airtalgo::EndPointWrite::EndPointWrite() :
void airtalgo::EndPointWrite::init() {
airtalgo::EndPoint::init();
m_type = "EndPoint";
}
std::shared_ptr<airtalgo::EndPointWrite> airtalgo::EndPointWrite::create() {

View File

@ -133,6 +133,7 @@ airtalgo::FormatUpdate::FormatUpdate() :
void airtalgo::FormatUpdate::init() {
airtalgo::Algo::init();
m_type = "FormatUpdate";
}
std::shared_ptr<airtalgo::FormatUpdate> airtalgo::FormatUpdate::create() {

View File

@ -40,26 +40,6 @@ bool airtalgo::Process::pull(std::chrono::system_clock::time_point& _time,
void* _data,
size_t _nbChunk,
size_t _chunkSize) {
#if 0
void* in = nullptr;
size_t nbChunkIn = _nbChunk;
void* out = nullptr;
size_t nbChunkOut;
if (nbChunkIn < 128) {
nbChunkIn = 128;
}
for (int32_t iii=m_listAlgo.size()-1; iii >=0; --iii) {
if (m_listAlgo[iii] != nullptr) {
nbChunkIn = m_listAlgo[iii]->needInputData(nbChunkIn);
}
}
if (nbChunkIn < 32) {
nbChunkIn = 32;
}
AIRTALGO_VERBOSE("process pull : request out=" << _nbChunk << " input slot request=" << nbChunkIn);
process(_time, in, nbChunkIn, _data, _nbChunk);
AIRTALGO_VERBOSE("process pull : real get " << _nbChunk);
#else
//std::cout << " Interface DIRECT " << std::endl;
while(m_data.size()<_nbChunk*_chunkSize) {
void* in = NULL;
@ -101,7 +81,6 @@ bool airtalgo::Process::pull(std::chrono::system_clock::time_point& _time,
// ERROR
m_data.clear();
}
#endif
return true;
}
@ -136,6 +115,116 @@ void airtalgo::Process::pushFront(const std::shared_ptr<airtalgo::Algo>& _algo)
m_listAlgo.insert(m_listAlgo.begin(), _algo);
}
void airtalgo::Process::updateInterAlgo() {
// TODO : ...
namespace std {
static std::ostream& operator <<(std::ostream& _os, const std::vector<float>& _obj) {
_os << std::string("{");
for (size_t iii=0; iii<_obj.size(); ++iii) {
if (iii!=0) {
_os << std::string(";");
}
_os << _obj[iii];
}
_os << std::string("}");
return _os;
}
}
template<typename T> std::vector<T> getUnion(const std::vector<T>& _out, const std::vector<T>& _in) {
std::vector<T> out;
if (_out.size() == 0) {
// Last is ok for all format
// ==> set the limit with the next element
out = _in;
} else if (_in.size() == 0) {
// 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);
}
}
}
}
return out;
}
void airtalgo::Process::updateInterAlgo() {
AIRTALGO_INFO(" display properties : nbAlgo : " << m_listAlgo.size());
for (auto &it : m_listAlgo) {
AIRTALGO_INFO(" [" << it->getType() << "] '" << it->getName() << "'");
if (it->getInputFormat().getConfigured() == true) {
AIRTALGO_INFO(" Input : " << it->getInputFormat());
} else {
AIRTALGO_INFO(" Input : Not configured");
AIRTALGO_INFO(" format : " << it->getFormatSupportedInput());
AIRTALGO_INFO(" frequency : " << it->getFrequencySupportedInput());
AIRTALGO_INFO(" map : " << it->getMapSupportedInput());
}
if (it->getOutputFormat().getConfigured() == true) {
AIRTALGO_INFO(" Output: " << it->getOutputFormat());
} else {
AIRTALGO_INFO(" Output : Not configured");
AIRTALGO_INFO(" format : " << it->getFormatSupportedOutput());
AIRTALGO_INFO(" frequency : " << it->getFrequencySupportedOutput());
AIRTALGO_INFO(" map : " << it->getMapSupportedOutput());
}
}
AIRTALGO_INFO("********* configuration START *************");
for (size_t iii=1; iii<m_listAlgo.size(); ++iii) {
if ( m_listAlgo[iii-1]->getOutputFormat().getConfigured() == false
&& m_listAlgo[iii]->getInputFormat().getConfigured() == false) {
std::vector<float> freq;
std::vector<std::vector<airtalgo::channel>> map;
std::vector<airtalgo::format> format;
// step 1 : check frequency:
freq = getUnion<float>(m_listAlgo[iii-1]->getFrequencySupportedOutput(),
m_listAlgo[iii]->getFrequencySupportedInput());
// step 2 : Check map:
map = getUnion<std::vector<airtalgo::channel>>(m_listAlgo[iii-1]->getMapSupportedOutput(),
m_listAlgo[iii]->getMapSupportedInput());
// step 3 : Check Format:
format = getUnion<airtalgo::format>(m_listAlgo[iii-1]->getFormatSupportedOutput(),
m_listAlgo[iii]->getFormatSupportedInput());
if ( freq.size() == 1
&& map.size() == 1
&& format.size() == 1) {
AIRTALGO_INFO(" find 1 compatibility :{format=" << format << ",frequency=" << freq << ",map=" << map << "}");
airtalgo::IOFormatInterface tmp(map[0], format[0], freq[0]);
m_listAlgo[iii-1]->setOutputFormat(tmp);
m_listAlgo[iii]->setInputFormat(tmp);
continue;
}
AIRTALGO_INFO(" union:");
AIRTALGO_INFO(" format : " << format);
AIRTALGO_INFO(" frequency : " << freq);
AIRTALGO_INFO(" map : " << map);
} else if ( m_listAlgo[iii-1]->getOutputFormat().getConfigured() == false
|| m_listAlgo[iii]->getInputFormat().getConfigured() == false) {
AIRTALGO_ERROR(" configuration error mode in " << iii-1 << " && " << iii );
}
}
AIRTALGO_INFO("********* configuration will be done *************");
for (auto &it : m_listAlgo) {
AIRTALGO_INFO(" [" << it->getType() << "] '" << it->getName() << "'");
if (it->getInputFormat().getConfigured() == true) {
AIRTALGO_INFO(" Input : " << it->getInputFormat());
} else {
AIRTALGO_ERROR(" Input : Not configured");
}
if (it->getOutputFormat().getConfigured() == true) {
AIRTALGO_INFO(" Output: " << it->getOutputFormat());
} else {
AIRTALGO_ERROR(" Output : Not configured");
}
}
//exit(-1);
}
void airtalgo::Process::removeAlgoDynamic() {
}

View File

@ -69,7 +69,6 @@ namespace airtalgo{
public:
void pushBack(const std::shared_ptr<airtalgo::Algo>& _algo);
void pushFront(const std::shared_ptr<airtalgo::Algo>& _algo);
void updateInterAlgo();
void clear() {
m_listAlgo.clear();
}
@ -92,6 +91,17 @@ namespace airtalgo{
template<typename T> std::shared_ptr<T> get(int32_t _id) {
return std::dynamic_pointer_cast<T>(m_listAlgo[_id]);
}
template<typename T> bool hasType() {
for (auto &it : m_listAlgo) {
std::shared_ptr<T> tmp = std::dynamic_pointer_cast<T>(it);
if (tmp != nullptr) {
return true;
}
}
return false;
}
void updateInterAlgo();
void removeAlgoDynamic();
};
};

View File

@ -22,6 +22,7 @@ airtalgo::Resampler::Resampler() :
void airtalgo::Resampler::init() {
airtalgo::Algo::init();
m_type = "Resampler";
}
std::shared_ptr<airtalgo::Resampler> airtalgo::Resampler::create() {

View File

@ -12,13 +12,16 @@
#define __class__ "Volume"
airtalgo::Volume::Volume() :
m_volume(0.0f),
m_volumedB(0.0f),
m_volumeAppli(1.0f) {
}
void airtalgo::Volume::init() {
airtalgo::Algo::init();
m_type = "Volume";
m_supportedFormat.push_back(format_int16);
m_supportedFormat.push_back(format_int16_on_int32);
}
std::shared_ptr<airtalgo::Volume> airtalgo::Volume::create() {
@ -46,16 +49,26 @@ void airtalgo::Volume::configurationChange() {
m_needProcess = false;
}
std::vector<airtalgo::format> airtalgo::Volume::getFormatSupportedInput() {
return m_supportedFormat;
};
std::vector<airtalgo::format> airtalgo::Volume::getFormatSupportedOutput() {
return m_supportedFormat;
};
bool airtalgo::Volume::process(std::chrono::system_clock::time_point& _time,
void* _input,
size_t _inputNbChunk,
void*& _output,
size_t& _outputNbChunk) {
void* _input,
size_t _inputNbChunk,
void*& _output,
size_t& _outputNbChunk) {
airtalgo::autoLogInOut tmpLog("Volume");
if (m_volumeAppli == 1.0f) {
_output = _input;
_outputNbChunk = _inputNbChunk;
return true;
}
return true;
}

View File

@ -38,6 +38,9 @@ namespace airtalgo {
size_t _inputNbChunk,
void*& _output,
size_t& _outputNbChunk);
public:
virtual std::vector<airtalgo::format> getFormatSupportedInput();
virtual std::vector<airtalgo::format> getFormatSupportedOutput();
};
};

View File

@ -60,7 +60,19 @@ std::string airtalgo::getChannelString(const std::vector<enum airtalgo::channel>
}
std::ostream& airtalgo::operator <<(std::ostream& _os, std::vector<enum airtalgo::channel> _obj) {
std::ostream& airtalgo::operator <<(std::ostream& _os, const std::vector<enum airtalgo::channel>& _obj) {
_os << std::string("{");
for (size_t iii=0; iii<_obj.size(); ++iii) {
if (iii!=0) {
_os << std::string(";");
}
_os << _obj[iii];
}
_os << std::string("}");
return _os;
}
std::ostream& airtalgo::operator <<(std::ostream& _os, const std::vector<std::vector<enum airtalgo::channel>>& _obj) {
_os << std::string("{");
for (size_t iii=0; iii<_obj.size(); ++iii) {
if (iii!=0) {

View File

@ -27,7 +27,8 @@ namespace airtalgo{
std::string getChannelString(const std::vector<enum airtalgo::channel>&);
std::vector<enum airtalgo::channel> getChannelFromString(const std::string& _value);
std::ostream& operator <<(std::ostream& _os, enum airtalgo::channel _obj);
std::ostream& operator <<(std::ostream& _os, std::vector<enum airtalgo::channel> _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<enum airtalgo::channel>& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<std::vector<enum airtalgo::channel>>& _obj);
};

View File

@ -12,8 +12,23 @@ std::ostream& airtalgo::operator <<(std::ostream& _os, enum airtalgo::format _ob
return _os;
}
std::ostream& airtalgo::operator <<(std::ostream& _os, const std::vector<enum airtalgo::format>& _obj) {
_os << std::string("{");
for (size_t iii=0; iii<_obj.size(); ++iii) {
if (iii!=0) {
_os << std::string(";");
}
_os << _obj[iii];
}
_os << std::string("}");
return _os;
}
std::string airtalgo::getFormatString(enum airtalgo::format _value) {
switch (_value) {
case format_unknow:
return "format_unknow";
break;
case format_int16:
return "format_int16";
break;
@ -42,5 +57,5 @@ enum airtalgo::format airtalgo::getFormatFromString(const std::string& _value) {
if (_value == "format_float") {
return format_float;
}
return format_int16;
return format_unknow;
}

View File

@ -11,6 +11,7 @@
namespace airtalgo{
enum format {
format_unknow,
format_int16, //!< Signed 16 bits
format_int16_on_int32, //!< Signed 16 bits on 32bits data (16 bit fixpoint value)
format_int32, //!< Signed 32 bits
@ -19,6 +20,7 @@ namespace airtalgo{
std::string getFormatString(enum airtalgo::format);
enum airtalgo::format getFormatFromString(const std::string& _value);
std::ostream& operator <<(std::ostream& _os, enum airtalgo::format _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<enum airtalgo::format>& _obj);
};

View File

@ -23,7 +23,8 @@ def create(target):
'airtalgo/format.cpp',
'airtalgo/FormatUpdate.cpp',
'airtalgo/Process.cpp',
'airtalgo/Resampler.cpp'
'airtalgo/Resampler.cpp',
'airtalgo/Volume.cpp'
])
# TODO: myModule.add_optionnal_module_depend('speexdsp', "HAVE_SPEEX_DSP_RESAMPLE")