[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 "debug.h"
#undef __class__
#define __class__ "Algo"
airtalgo::Algo::Algo() :
m_outputData(),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,6 +6,10 @@
#include "debug.h"
#include <airtalgo/EndPointWrite.h>
#undef __class__
#define __class__ "EndPointWrite"
airtalgo::EndPointWrite::EndPointWrite() :
m_function(nullptr) {
@ -23,7 +27,7 @@ bool airtalgo::EndPointWrite::process(std::chrono::system_clock::time_point& _ti
size_t _inputNbChunk,
void*& _output,
size_t& _outputNbChunk){
//airtalgo::autoLogInOut("EndPointWrite");
airtalgo::autoLogInOut("EndPointWrite");
//AIRTALGO_INFO(" nb Sample in buffer : " << m_tmpData.size());
if (m_function != nullptr) {
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");
// check if we have enought data:
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:
memcpy(_output, &m_tmpData[0], nbChunkToCopy*m_output.getMap().size()*m_formatSize);
// 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());
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);
AIRTALGO_INFO("[ASYNC] Get data : " << _nbValue << " ==> " << _nbValue/m_output.getMap().size() << " chumks");
for (size_t iii=0; iii<_nbValue; ++iii) {
m_tmpData.push_back(*_value++);
AIRTALGO_INFO("[ASYNC] Get data : " << _nbChunk << " chunks ==> " << _nbChunk*m_output.getMap().size() << " samples formatSize=" << int32_t(m_formatSize));
const int8_t* value = static_cast<const int8_t*>(_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,
void*& _output,
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) {
m_function = _function;
}

View File

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

View File

@ -14,6 +14,9 @@
#include <airtalgo/Process.h>
#include <chrono>
#undef __class__
#define __class__ "Process"
airtalgo::Process::Process() {
}
@ -60,6 +63,7 @@ bool airtalgo::Process::process(std::chrono::system_clock::time_point& _time,
_outNbChunk = _inNbChunk;
return true;
}
AIRTALGO_VERBOSE(" process : " << m_listAlgo.size() << " algos");
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

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

View File

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