[DEBUG] correct some algo think error

This commit is contained in:
Edouard DUPIN 2015-01-28 22:07:11 +01:00
parent 6ab88e627c
commit 65a999c921
16 changed files with 61 additions and 25 deletions

View File

@ -14,12 +14,16 @@ airtalgo::Algo::Algo() :
m_outputData(),
m_formatSize(0),
m_needProcess(false) {
AIRTALGO_VERBOSE("CREATE ALGO");
// set notification callback :
m_input.setCallback(std::bind(&airtalgo::Algo::configurationChange, this));
m_output.setCallback(std::bind(&airtalgo::Algo::configurationChange, this));
// first configure ==> update the internal parameters
configurationChange();
}
airtalgo::Algo::~Algo() {
AIRTALGO_VERBOSE("Remove ALGO");
}
void airtalgo::Algo::configurationChange() {
m_needProcess = false;
@ -48,6 +52,7 @@ void airtalgo::Algo::configurationChange() {
size_t airtalgo::Algo::needInputData(size_t _output) {
size_t input = _output;
/* NOT good at all ...
if (m_input.getFormat() != m_output.getFormat()) {
int32_t inputSize = 3;
switch (m_input.getFormat()) {
@ -67,10 +72,13 @@ size_t airtalgo::Algo::needInputData(size_t _output) {
input /= m_formatSize;
}
}
*/
/*
if (m_input.getMap().size() != m_output.getMap().size()) {
input *= m_input.getMap().size();
input /= m_output.getMap().size();
}
*/
if (m_input.getFrequency() != m_output.getFrequency()) {
input *= m_input.getFrequency();

View File

@ -113,7 +113,7 @@ namespace airtalgo{
protected:
std::function<void()> m_ioChangeFunctor; //!< function pointer on the upper class
void configurationChange() {
if (m_ioChangeFunctor != NULL) {
if (m_ioChangeFunctor != nullptr) {
m_ioChangeFunctor();
}
}
@ -140,7 +140,7 @@ namespace airtalgo{
/**
* @brief Destructor
*/
virtual ~Algo() {};
virtual ~Algo();
protected:
bool m_needProcess; //!< if no change, then no need to process, just forward buffer...
IOFormatInterface m_input; //!< Input audio property

View File

@ -16,6 +16,10 @@
airtalgo::ChannelReorder::ChannelReorder() {
}
airtalgo::ChannelReorder::~ChannelReorder() {
AIRTALGO_INFO("Remove ChannelReorder");
}
void airtalgo::ChannelReorder::configurationChange() {
airtalgo::autoLogInOut("ChannelReorder (config)");
@ -62,7 +66,7 @@ bool airtalgo::ChannelReorder::process(std::chrono::system_clock::time_point& _t
default:
case format_int16:
{
AIRTALGO_INFO("convert " << m_input.getMap() << " ==> " << m_output.getMap());
AIRTALGO_VERBOSE("convert " << m_input.getMap() << " ==> " << m_output.getMap() << " format=" << int32_t(m_formatSize));
int16_t* in = static_cast<int16_t*>(_input);
int16_t* out = static_cast<int16_t*>(_output);
for (size_t kkk=0; kkk<m_output.getMap().size(); ++kkk) {
@ -78,6 +82,7 @@ bool airtalgo::ChannelReorder::process(std::chrono::system_clock::time_point& _t
}
}
}
AIRTALGO_VERBOSE(" " << convertId << " ==> " << kkk);
if (convertId == -1) {
for (size_t iii=0; iii<_outputNbChunk; ++iii) {
out[iii*m_output.getMap().size()+kkk] = 0;
@ -94,7 +99,7 @@ bool airtalgo::ChannelReorder::process(std::chrono::system_clock::time_point& _t
case format_int32:
case format_float:
{
AIRTALGO_INFO("convert (2) " << m_input.getMap() << " ==> " << m_output.getMap());
AIRTALGO_VERBOSE("convert (2) " << m_input.getMap() << " ==> " << m_output.getMap());
uint32_t* in = static_cast<uint32_t*>(_input);
uint32_t* out = static_cast<uint32_t*>(_output);
for (size_t kkk=0; kkk<m_output.getMap().size(); ++kkk) {

View File

@ -19,7 +19,7 @@ namespace airtalgo{
/**
* @brief Destructor
*/
virtual ~ChannelReorder() {};
virtual ~ChannelReorder();
protected:
virtual void configurationChange();
public:

View File

@ -20,10 +20,14 @@ airtalgo::EndPointCallback::EndPointCallback(haveNewDataFunction _callback) :
m_inputFunction(_callback) {
}
airtalgo::EndPointCallback::~EndPointCallback() {
AIRTALGO_INFO("Remove EndPointCallback");
}
void airtalgo::EndPointCallback::configurationChange() {
airtalgo::EndPoint::configurationChange();
AIRTALGO_INFO("update : format=" << m_output.getFormat() << " map=" << m_input.getMap() << " freq=" << m_input.getFrequency() << " size=" << int32_t(m_formatSize));
m_needProcess = true;
}
@ -38,7 +42,7 @@ bool airtalgo::EndPointCallback::process(std::chrono::system_clock::time_point&
// update buffer size ...
m_outputData.resize(_inputNbChunk*m_output.getMap().size()*m_formatSize);
// call user
AIRTALGO_VERBOSE("call user get I16*" << _inputNbChunk << "*" << m_output.getMap().size() << " " << m_output.getMap());
AIRTALGO_VERBOSE("call user get " << _inputNbChunk << "*" << m_output.getMap().size() << " map=" << m_output.getMap() << " datasize=" << int32_t(m_formatSize));
m_outputFunction(_time,
_inputNbChunk,
m_output.getMap(),
@ -54,7 +58,7 @@ bool airtalgo::EndPointCallback::process(std::chrono::system_clock::time_point&
}
if (m_inputFunction != nullptr) {
// Call user ...
AIRTALGO_VERBOSE("call user set I16*" << _inputNbChunk << "*" << m_input.getMap().size());
AIRTALGO_VERBOSE("call user set " << _inputNbChunk << "*" << m_input.getMap().size());
m_inputFunction(_time,
_inputNbChunk,
m_input.getMap(),

View File

@ -26,7 +26,6 @@ namespace airtalgo {
private:
needDataFunction m_outputFunction;
haveNewDataFunction m_inputFunction;
std::vector<uint8_t> m_data;
public:
/**
* @brief Constructor
@ -36,7 +35,7 @@ namespace airtalgo {
/**
* @brief Destructor
*/
virtual ~EndPointCallback() {};
virtual ~EndPointCallback();
virtual void configurationChange();
virtual bool process(std::chrono::system_clock::time_point& _time,
void* _input,

View File

@ -14,6 +14,10 @@ airtalgo::EndPointRead::EndPointRead() {
}
airtalgo::EndPointRead::~EndPointRead() {
AIRTALGO_INFO("Remove EndPointRead");
}
void airtalgo::EndPointRead::configurationChange() {
airtalgo::EndPoint::configurationChange();

View File

@ -19,7 +19,7 @@ namespace airtalgo{
/**
* @brief Destructor
*/
virtual ~EndPointRead() {};
virtual ~EndPointRead();
virtual void configurationChange();
virtual bool process(std::chrono::system_clock::time_point& _time,
void* _input,

View File

@ -16,6 +16,11 @@ airtalgo::EndPointWrite::EndPointWrite() :
}
airtalgo::EndPointWrite::~EndPointWrite() {
AIRTALGO_INFO("Remove EndPointWrite");
}
void airtalgo::EndPointWrite::configurationChange() {
airtalgo::EndPoint::configurationChange();
m_needProcess = true;

View File

@ -29,7 +29,7 @@ namespace airtalgo{
/**
* @brief Destructor
*/
virtual ~EndPointWrite() {};
virtual ~EndPointWrite();
virtual void configurationChange();
virtual bool process(std::chrono::system_clock::time_point& _time,
void* _input,

View File

@ -103,7 +103,7 @@ static void convert__float__to__int16(void* _input, void* _output, size_t _nbSam
float value = in[iii] * static_cast<float>(INT16_MAX);
value = std::min(std::max(static_cast<float>(INT16_MIN), value), static_cast<float>(INT16_MAX));
out[iii] = static_cast<int16_t>(value);
//AIRTALGO_VERBOSE(" in=" << in[iii] << " out=" << out[iii]);
//AIRTALGO_DEBUG(iii << " in=" << in[iii] << " out=" << out[iii]);
}
}
static void convert__float__to__int16_on_int32(void* _input, void* _output, size_t _nbSample) {
@ -130,6 +130,9 @@ airtalgo::FormatUpdate::FormatUpdate() :
m_functionConvert(NULL) {
}
airtalgo::FormatUpdate::~FormatUpdate() {
AIRTALGO_INFO("Remove FormatUpdate");
}
void airtalgo::FormatUpdate::configurationChange() {
airtalgo::Algo::configurationChange();

View File

@ -18,7 +18,7 @@ namespace airtalgo {
/**
* @brief Destructor
*/
virtual ~FormatUpdate() {};
virtual ~FormatUpdate();
protected:
virtual void configurationChange();
public:

View File

@ -20,6 +20,11 @@
airtalgo::Process::Process() {
}
airtalgo::Process::~Process() {
for (auto &it : m_listAlgo) {
it.reset();
}
}
bool airtalgo::Process::push(std::chrono::system_clock::time_point& _time,
void* _data,
@ -63,7 +68,7 @@ bool airtalgo::Process::process(std::chrono::system_clock::time_point& _time,
_outNbChunk = _inNbChunk;
return true;
}
AIRTALGO_VERBOSE(" process : " << m_listAlgo.size() << " algos");
AIRTALGO_VERBOSE(" process : " << m_listAlgo.size() << " algos nbChunk=" << _outNbChunk);
for (size_t iii=0; iii<m_listAlgo.size(); ++iii) {
//std::cout << " Algo " << iii+1 << "/" << m_listAlgo.size() << std::endl;
if (m_listAlgo[iii] != nullptr) {

View File

@ -21,6 +21,7 @@ namespace airtalgo{
class Process {
public:
Process();
virtual ~Process();
public:
/**
* @brief Push data in the algo stream.

View File

@ -20,6 +20,7 @@ airtalgo::Resampler::Resampler() :
}
airtalgo::Resampler::~Resampler() {
AIRTALGO_INFO("Remove Resampler");
#ifdef HAVE_SPEEX_DSP_RESAMPLE
if (m_speexResampler != nullptr) {
speex_resampler_destroy(m_speexResampler);
@ -54,12 +55,12 @@ void airtalgo::Resampler::configurationChange() {
m_speexResampler = nullptr;
}
int err = 0;
m_speexResampler = speex_resampler_init(m_outputMap.size(),
m_inputFrequency,
m_outputFrequency,
m_speexResampler = speex_resampler_init(m_output.getMap().size(),
m_input.getFrequency(),
m_output.getFrequency(),
10, &err);
#else
std::cerr << "SPEEX DSP lib not accessible ==> can not resample" << std::endl;
AIRTALGO_WARNING("SPEEX DSP lib not accessible ==> can not resample");
m_needProcess = false;
#endif
}
@ -86,18 +87,18 @@ bool airtalgo::Resampler::process(std::chrono::system_clock::time_point& _time,
return false;
}
#ifdef HAVE_SPEEX_DSP_RESAMPLE
float nbInputTime = static_cast<float>(_inputNbChunk)/m_input.getFrequency();
float nbInputTime = float(_inputNbChunk)/m_input.getFrequency();
float nbOutputSample = nbInputTime*m_output.getFrequency();
// we add 10% of the buffer size to have all the time enought data in the output to proceed all the input data...
_outputNbChunk = static_cast<size_t>(nbOutputSample*1.5f);
AIRTALGO_VERBOSE(" freq in=" << m_inputFrequency << " out=" << m_outputFrequency);
_outputNbChunk = size_t(nbOutputSample*1.5f);
AIRTALGO_VERBOSE(" freq in=" << m_input.getFrequency() << " out=" << m_output.getFrequency());
AIRTALGO_VERBOSE(" Frame duration=" << nbInputTime);
AIRTALGO_VERBOSE(" nbInput chunk=" << _inputNbChunk << " nbOutputChunk=" << nbOutputSample);
m_outputData.resize(_outputNbChunk*m_input.getMap().size()*m_formatSize);
m_outputData.resize(_outputNbChunk*m_output.getMap().size()*m_formatSize);
_output = &(m_outputData[0]);
if (m_speexResampler == nullptr) {
std::cout << " No speex resampler" << std::endl;
AIRTALGO_ERROR(" No speex resampler");
return false;
}
uint32_t nbChunkInput = _inputNbChunk;

View File

@ -26,8 +26,9 @@ def create(target):
'airtalgo/Resampler.cpp'
])
myModule.add_module_depend(['etk'])
# TODO: myModule.add_optionnal_module_depend('speexdsp', "HAVE_SPEEX_DSP_RESAMPLE")
myModule.compile_flags_CC("-DHAVE_SPEEX_DSP_RESAMPLE")
myModule.add_module_depend(['etk', 'speexdsp'])
myModule.add_export_path(tools.get_current_path(__file__))
# add the currrent module at the