[DEV] start work

This commit is contained in:
Edouard DUPIN 2015-01-27 21:26:03 +01:00
parent f9c3b51f93
commit f012027d5b
12 changed files with 86 additions and 54 deletions

View File

@ -7,6 +7,8 @@
#include <functional> #include <functional>
#include "debug.h" #include "debug.h"
#undef __class__
#define __class__ "Algo"
airtalgo::Algo::Algo() : airtalgo::Algo::Algo() :
m_outputData(), m_outputData(),

View File

@ -24,10 +24,10 @@ namespace airtalgo{
public: public:
autoLogInOut(const std::string& _value) : autoLogInOut(const std::string& _value) :
m_value(_value) { m_value(_value) {
AIRTALGO_DEBUG(" '" << m_value << "' [START]"); AIRTALGO_VERBOSE(" '" << m_value << "' [START]");
} }
~autoLogInOut() { ~autoLogInOut() {
AIRTALGO_DEBUG(" '" << m_value << "' [STOP]"); AIRTALGO_VERBOSE(" '" << m_value << "' [STOP]");
} }
}; };
class IOFormatInterface { class IOFormatInterface {

View File

@ -10,6 +10,8 @@
#include "debug.h" #include "debug.h"
#undef __class__
#define __class__ "ChannelReorder"
airtalgo::ChannelReorder::ChannelReorder() { airtalgo::ChannelReorder::ChannelReorder() {
@ -40,9 +42,9 @@ bool airtalgo::ChannelReorder::process(std::chrono::system_clock::time_point& _t
size_t _inputNbChunk, size_t _inputNbChunk,
void*& _output, void*& _output,
size_t& _outputNbChunk) { size_t& _outputNbChunk) {
//airtalgo::autoLogInOut("ChannelReorder"); airtalgo::autoLogInOut("ChannelReorder");
_outputNbChunk = _inputNbChunk; _outputNbChunk = _inputNbChunk;
// chack if we need to process: // check if we need to process:
if (m_needProcess == false) { if (m_needProcess == false) {
_output = _input; _output = _input;
return true; return true;

View File

@ -7,16 +7,17 @@
#include "debug.h" #include "debug.h"
#include <airtalgo/EndPointCallback.h> #include <airtalgo/EndPointCallback.h>
airtalgo::EndPointCallback::EndPointCallback(needDataFunction _callback, enum formatDataType _dataFormat) : #undef __class__
m_dataFormat(_dataFormat), #define __class__ "EndPointCallback"
m_output(_callback),
m_input(nullptr) { airtalgo::EndPointCallback::EndPointCallback(needDataFunction _callback) :
m_outputFunction(_callback),
m_inputFunction(nullptr) {
} }
airtalgo::EndPointCallback::EndPointCallback(haveNewDataFunction _callback, enum formatDataType _dataFormat) : airtalgo::EndPointCallback::EndPointCallback(haveNewDataFunction _callback) :
m_dataFormat(_dataFormat), m_outputFunction(nullptr),
m_output(nullptr), m_inputFunction(_callback) {
m_input(_callback) {
} }
@ -33,33 +34,34 @@ bool airtalgo::EndPointCallback::process(std::chrono::system_clock::time_point&
void*& _output, void*& _output,
size_t& _outputNbChunk){ size_t& _outputNbChunk){
airtalgo::autoLogInOut("EndPointCallback"); airtalgo::autoLogInOut("EndPointCallback");
/* if (m_outputFunction != nullptr) {
if (m_output != nullptr) { // update buffer size ...
m_outputData.resize(_inputNbChunk*m_output.getMap().size()*m_formatSize);
// call user // call user
AIRTALGO_INFO("call user get I16*" << _inputNbChunk << "*" << airtalgo::Algo::m_output.getMap().size() << " " << airtalgo::Algo::m_output.getMap()); AIRTALGO_VERBOSE("call user get I16*" << _inputNbChunk << "*" << m_output.getMap().size() << " " << m_output.getMap());
m_data = m_output(_time, _inputNbChunk, airtalgo::Algo::m_output.getMap()); m_outputFunction(_time,
if (m_data.size() != _inputNbChunk*airtalgo::Algo::m_output.getMap().size()) { _inputNbChunk,
//ERROR m_output.getMap(),
&m_outputData[0],
m_output.getFormat());
if (m_outputData.size() != _inputNbChunk*m_output.getMap().size()*m_formatSize) {
AIRTALGO_ERROR(" can not get enough data from user ... " << m_outputData.size() << " != " << _inputNbChunk*m_output.getMap().size());
return false; return false;
} }
_output = &m_data[0]; _output = &m_outputData[0];
_outputNbChunk = _inputNbChunk; _outputNbChunk = _inputNbChunk;
return true; return true;
} }
if (m_input != nullptr) { if (m_inputFunction != nullptr) {
// convert in data :
// TODO : ...
m_data.resize(_inputNbChunk*airtalgo::Algo::m_input.getMap().size());
int16_t* data = static_cast<int16_t*>(_input);
for (size_t iii; iii<m_data.size(); ++iii) {
m_data[iii] = *data++;
}
// Call user ... // Call user ...
AIRTALGO_INFO("call user set I16*" << _inputNbChunk << "*" << airtalgo::Algo::m_input.getMap().size()); AIRTALGO_VERBOSE("call user set I16*" << _inputNbChunk << "*" << m_input.getMap().size());
m_input(_time, _inputNbChunk, airtalgo::Algo::m_input.getMap(), m_data); m_inputFunction(_time,
_inputNbChunk,
m_input.getMap(),
_input,
m_input.getFormat());
return true; return true;
} }
*/
return false; return false;
} }

View File

@ -12,24 +12,27 @@
namespace airtalgo { namespace airtalgo {
enum formatDataType { typedef std::function<void (const std::chrono::system_clock::time_point& _playTime,
formatDataTypeInt16, size_t _nbChunk,
formatDataTypeInt32, const std::vector<airtalgo::channel>& _map,
}; void* _data,
typedef std::function<void (const std::chrono::system_clock::time_point& _playTime, size_t _nbChunk, const std::vector<airtalgo::channel>& _map, void* _data, enum formatDataType& _type)> needDataFunction; enum airtalgo::format _type)> needDataFunction;
typedef std::function<void (const std::chrono::system_clock::time_point& _readTime, size_t _nbChunk, const std::vector<airtalgo::channel>& _map, const void* _data, enum formatDataType& _type)> haveNewDataFunction; typedef std::function<void (const std::chrono::system_clock::time_point& _readTime,
size_t _nbChunk,
const std::vector<airtalgo::channel>& _map,
const void* _data,
enum airtalgo::format _type)> haveNewDataFunction;
class EndPointCallback : public EndPoint { class EndPointCallback : public EndPoint {
private: private:
enum formatDataType m_dataFormat; needDataFunction m_outputFunction;
needDataFunction m_output; haveNewDataFunction m_inputFunction;
haveNewDataFunction m_input;
std::vector<uint8_t> m_data; std::vector<uint8_t> m_data;
public: public:
/** /**
* @brief Constructor * @brief Constructor
*/ */
EndPointCallback(needDataFunction _callback, enum formatDataType _dataFormat); EndPointCallback(needDataFunction _callback);
EndPointCallback(haveNewDataFunction _callback, enum formatDataType _dataFormat); EndPointCallback(haveNewDataFunction _callback);
/** /**
* @brief Destructor * @brief Destructor
*/ */

View File

@ -7,6 +7,9 @@
#include "debug.h" #include "debug.h"
#include <airtalgo/EndPointRead.h> #include <airtalgo/EndPointRead.h>
#undef __class__
#define __class__ "EndPointRead"
airtalgo::EndPointRead::EndPointRead() { airtalgo::EndPointRead::EndPointRead() {
} }

View File

@ -6,6 +6,10 @@
#include "debug.h" #include "debug.h"
#include <airtalgo/EndPointWrite.h> #include <airtalgo/EndPointWrite.h>
#undef __class__
#define __class__ "EndPointWrite"
airtalgo::EndPointWrite::EndPointWrite() : airtalgo::EndPointWrite::EndPointWrite() :
m_function(nullptr) { m_function(nullptr) {
@ -23,7 +27,7 @@ bool airtalgo::EndPointWrite::process(std::chrono::system_clock::time_point& _ti
size_t _inputNbChunk, size_t _inputNbChunk,
void*& _output, void*& _output,
size_t& _outputNbChunk){ size_t& _outputNbChunk){
//airtalgo::autoLogInOut("EndPointWrite"); airtalgo::autoLogInOut("EndPointWrite");
//AIRTALGO_INFO(" nb Sample in buffer : " << m_tmpData.size()); //AIRTALGO_INFO(" nb Sample in buffer : " << m_tmpData.size());
if (m_function != nullptr) { if (m_function != nullptr) {
if (m_tmpData.size() <= 20000) { if (m_tmpData.size() <= 20000) {
@ -48,18 +52,21 @@ bool airtalgo::EndPointWrite::process(std::chrono::system_clock::time_point& _ti
AIRTALGO_INFO("Write " << _outputNbChunk << " chunks"); AIRTALGO_INFO("Write " << _outputNbChunk << " chunks");
// check if we have enought data: // check if we have enought data:
int32_t nbChunkToCopy = std::min(_inputNbChunk, m_outputData.size()/m_output.getMap().size()); int32_t nbChunkToCopy = std::min(_inputNbChunk, m_outputData.size()/m_output.getMap().size());
AIRTALGO_INFO(" " << nbChunkToCopy << " chunks ==> " << nbChunkToCopy*m_output.getMap().size()*m_formatSize << " Byte");
// copy data to the output: // copy data to the output:
memcpy(_output, &m_tmpData[0], nbChunkToCopy*m_output.getMap().size()*m_formatSize); memcpy(_output, &m_tmpData[0], nbChunkToCopy*m_output.getMap().size()*m_formatSize);
// remove old data: // remove old data:
m_tmpData.erase(m_tmpData.begin(), m_tmpData.begin()+nbChunkToCopy*m_output.getMap().size()); m_tmpData.erase(m_tmpData.begin(), m_tmpData.begin() + nbChunkToCopy*m_output.getMap().size()*m_formatSize);
//AIRTALGO_INFO(" nb Sample in buffer : " << m_tmpData.size()); //AIRTALGO_INFO(" nb Sample in buffer : " << m_tmpData.size());
return true; return true;
} }
void airtalgo::EndPointWrite::write(const int16_t* _value, size_t _nbValue) { void airtalgo::EndPointWrite::write(const void* _value, size_t _nbChunk) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
AIRTALGO_INFO("[ASYNC] Get data : " << _nbValue << " ==> " << _nbValue/m_output.getMap().size() << " chumks"); AIRTALGO_INFO("[ASYNC] Get data : " << _nbChunk << " chunks ==> " << _nbChunk*m_output.getMap().size() << " samples formatSize=" << int32_t(m_formatSize));
for (size_t iii=0; iii<_nbValue; ++iii) { const int8_t* value = static_cast<const int8_t*>(_value);
m_tmpData.push_back(*_value++); for (size_t iii=0; iii<_nbChunk*m_formatSize; ++iii) {
m_tmpData.push_back(*value++);
} }
} }

View File

@ -33,7 +33,7 @@ namespace airtalgo{
size_t _inputNbChunk, size_t _inputNbChunk,
void*& _output, void*& _output,
size_t& _outputNbChunk); size_t& _outputNbChunk);
virtual void write(const int16_t* _value, size_t _nbValue); virtual void write(const void* _value, size_t _nbChunk);
virtual void setCallback(writeNeedDataFunction_int16_t _function) { virtual void setCallback(writeNeedDataFunction_int16_t _function) {
m_function = _function; m_function = _function;
} }

View File

@ -8,6 +8,9 @@
#include <airtalgo/FormatUpdate.h> #include <airtalgo/FormatUpdate.h>
#include <iostream> #include <iostream>
#undef __class__
#define __class__ "FormatUpdate"
#ifndef INT16_MAX #ifndef INT16_MAX
#define INT16_MAX 0x7fff #define INT16_MAX 0x7fff
#endif #endif
@ -234,7 +237,7 @@ bool airtalgo::FormatUpdate::process(std::chrono::system_clock::time_point& _tim
size_t _inputNbChunk, size_t _inputNbChunk,
void*& _output, void*& _output,
size_t& _outputNbChunk) { size_t& _outputNbChunk) {
//airtalgo::autoLogInOut("FormatUpdate"); airtalgo::autoLogInOut("FormatUpdate");
// chack if we need to process: // chack if we need to process:
if (m_needProcess == false) { if (m_needProcess == false) {
_output = _input; _output = _input;

View File

@ -14,6 +14,9 @@
#include <airtalgo/Process.h> #include <airtalgo/Process.h>
#include <chrono> #include <chrono>
#undef __class__
#define __class__ "Process"
airtalgo::Process::Process() { airtalgo::Process::Process() {
} }
@ -60,6 +63,7 @@ bool airtalgo::Process::process(std::chrono::system_clock::time_point& _time,
_outNbChunk = _inNbChunk; _outNbChunk = _inNbChunk;
return true; return true;
} }
AIRTALGO_VERBOSE(" process : " << m_listAlgo.size() << " algos");
for (size_t iii=0; iii<m_listAlgo.size(); ++iii) { for (size_t iii=0; iii<m_listAlgo.size(); ++iii) {
//std::cout << " Algo " << iii+1 << "/" << m_listAlgo.size() << std::endl; //std::cout << " Algo " << iii+1 << "/" << m_listAlgo.size() << std::endl;
if (m_listAlgo[iii] != nullptr) { if (m_listAlgo[iii] != nullptr) {

View File

@ -8,6 +8,8 @@
#include <airtalgo/Resampler.h> #include <airtalgo/Resampler.h>
#include <iostream> #include <iostream>
#undef __class__
#define __class__ "Resampler"
airtalgo::Resampler::Resampler() : airtalgo::Resampler::Resampler() :
#ifdef HAVE_SPEEX_DSP_RESAMPLE #ifdef HAVE_SPEEX_DSP_RESAMPLE
@ -64,11 +66,11 @@ void airtalgo::Resampler::configurationChange() {
bool airtalgo::Resampler::process(std::chrono::system_clock::time_point& _time, bool airtalgo::Resampler::process(std::chrono::system_clock::time_point& _time,
void* _input, void* _input,
size_t _inputNbChunk, size_t _inputNbChunk,
void*& _output, void*& _output,
size_t& _outputNbChunk) { size_t& _outputNbChunk) {
//airtalgo::autoLogInOut("Resampler"); airtalgo::autoLogInOut("Resampler");
_outputNbChunk = 2048; _outputNbChunk = 2048;
// chack if we need to process: // chack if we need to process:
if (m_needProcess == false) { if (m_needProcess == false) {

View File

@ -6,3 +6,7 @@
#include "debug.h" #include "debug.h"
#undef __class__
#define __class__ ""