[DEV] start add volume interface
This commit is contained in:
parent
fac1f70107
commit
9675696930
@ -130,6 +130,15 @@ namespace airtalgo{
|
||||
};
|
||||
|
||||
class Algo : public std::enable_shared_from_this<Algo> {
|
||||
private:
|
||||
std::string m_name;
|
||||
public:
|
||||
const std::string& getName() const {
|
||||
return m_name;
|
||||
}
|
||||
void setName(const std::string& _name) {
|
||||
m_name = _name;
|
||||
}
|
||||
protected:
|
||||
std::vector<int8_t> m_outputData;
|
||||
int8_t m_formatSize; //!< sample size
|
||||
|
@ -37,8 +37,10 @@ bool airtalgo::Process::push(std::chrono::system_clock::time_point& _time,
|
||||
}
|
||||
|
||||
bool airtalgo::Process::pull(std::chrono::system_clock::time_point& _time,
|
||||
void*& _data,
|
||||
size_t& _nbChunk) {
|
||||
void* _data,
|
||||
size_t _nbChunk,
|
||||
size_t _chunkSize) {
|
||||
#if 0
|
||||
void* in = nullptr;
|
||||
size_t nbChunkIn = _nbChunk;
|
||||
void* out = nullptr;
|
||||
@ -54,10 +56,56 @@ bool airtalgo::Process::pull(std::chrono::system_clock::time_point& _time,
|
||||
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;
|
||||
size_t nbChunkIn = _nbChunk - m_data.size()/_chunkSize;
|
||||
void* out = NULL;
|
||||
size_t nbChunkOut;
|
||||
if (nbChunkIn < 128) {
|
||||
nbChunkIn = 128;
|
||||
}
|
||||
// TODO : maybe remove this for input data ...
|
||||
for (int32_t iii=m_listAlgo.size()-1; iii >=0; --iii) {
|
||||
if (m_listAlgo[iii] != NULL) {
|
||||
nbChunkIn = m_listAlgo[iii]->needInputData(nbChunkIn);
|
||||
}
|
||||
}
|
||||
if (nbChunkIn < 32) {
|
||||
nbChunkIn = 32;
|
||||
}
|
||||
|
||||
// get data from the upstream
|
||||
//std::cout << " * request " << nbChunkIn << " chunk" << std::endl;
|
||||
process(_time, in, nbChunkIn, out, nbChunkOut);
|
||||
//std::cout << " * get " << nbChunkOut << " chunk" << std::endl;
|
||||
if (nbChunkOut > 0) {
|
||||
size_t position = m_data.size();
|
||||
m_data.resize(m_data.size() + nbChunkOut*_chunkSize);
|
||||
memcpy(&m_data[position], out, nbChunkOut*_chunkSize);
|
||||
} else {
|
||||
// TODO : ERROR ...
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_data.size()>=_nbChunk*_chunkSize) {
|
||||
//std::cout << " * copy needed data" << std::endl;
|
||||
memcpy(_data, &m_data[0], _nbChunk*_chunkSize);
|
||||
m_data.erase(m_data.begin(), m_data.begin()+_nbChunk*_chunkSize);
|
||||
} else {
|
||||
//std::cout << " * soft underflow" << std::endl;
|
||||
// ERROR
|
||||
m_data.clear();
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool airtalgo::Process::process(std::chrono::system_clock::time_point& _time,
|
||||
void* _inData,
|
||||
size_t _inNbChunk,
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
namespace airtalgo{
|
||||
class Process {
|
||||
protected:
|
||||
std::vector<int8_t> m_data; //!< temporary overlap output buffer (change size of the output data)
|
||||
public:
|
||||
Process();
|
||||
virtual ~Process();
|
||||
@ -39,12 +41,14 @@ namespace airtalgo{
|
||||
* @param[in] _time Time of the first sample requested.
|
||||
* @param[in] _data Pointer on the data pushed.
|
||||
* @param[in,out] _nbChunk Number of chunk present in the pointer (set at the number of chunk requested(hope)).
|
||||
* @param[out] _chunkSize size of a single chunk. TODO : Not needed ... Remove it ...
|
||||
* @return true The procress is done corectly.
|
||||
* @return false An error occured.
|
||||
*/
|
||||
bool pull(std::chrono::system_clock::time_point& _time,
|
||||
void*& _data,
|
||||
size_t& _nbChunk);
|
||||
void* _data,
|
||||
size_t _nbChunk,
|
||||
size_t _chunkSize);
|
||||
/**
|
||||
* @brief Push data in the algo stream.
|
||||
* @param[in] _time Time of the first sample pushed.
|
||||
|
61
airtalgo/Volume.cpp
Normal file
61
airtalgo/Volume.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
#include <airtalgo/Volume.h>
|
||||
#include <iostream>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Volume"
|
||||
|
||||
airtalgo::Volume::Volume() :
|
||||
m_volume(0.0f),
|
||||
m_volumeAppli(1.0f) {
|
||||
|
||||
}
|
||||
|
||||
void airtalgo::Volume::init() {
|
||||
airtalgo::Algo::init();
|
||||
}
|
||||
|
||||
std::shared_ptr<airtalgo::Volume> airtalgo::Volume::create() {
|
||||
std::shared_ptr<airtalgo::Volume> tmp(new airtalgo::Volume());
|
||||
tmp->init();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
airtalgo::Volume::~Volume() {
|
||||
|
||||
}
|
||||
|
||||
void airtalgo::Volume::configurationChange() {
|
||||
airtalgo::Algo::configurationChange();
|
||||
if (m_input.getFormat() != m_output.getFormat()) {
|
||||
AIRTALGO_ERROR("Volume format change is not supported");
|
||||
}
|
||||
if (m_input.getMap() != m_output.getMap()) {
|
||||
AIRTALGO_ERROR("Volume map change is not supported");
|
||||
}
|
||||
if (m_input.getFrequency() != m_output.getFrequency()) {
|
||||
AIRTALGO_ERROR("Volume frequency change is not supported");
|
||||
}
|
||||
// nee to process all time (the format not change (just a simple filter))
|
||||
m_needProcess = false;
|
||||
}
|
||||
|
||||
bool airtalgo::Volume::process(std::chrono::system_clock::time_point& _time,
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
44
airtalgo/Volume.h
Normal file
44
airtalgo/Volume.h
Normal file
@ -0,0 +1,44 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __AIRT_ALGO_VOLUME_H__
|
||||
#define __AIRT_ALGO_VOLUME_H__
|
||||
|
||||
#include <airtalgo/Algo.h>
|
||||
#ifdef HAVE_SPEEX_DSP_RESAMPLE
|
||||
#include <speex/speex_resampler.h>
|
||||
#endif
|
||||
#include <memory>
|
||||
|
||||
namespace airtalgo {
|
||||
class Volume : public Algo {
|
||||
private:
|
||||
float m_volumedB;
|
||||
float m_volumeAppli;
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
Volume();
|
||||
void init();
|
||||
public:
|
||||
static std::shared_ptr<Volume> create();
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~Volume();
|
||||
protected:
|
||||
virtual void configurationChange();
|
||||
public:
|
||||
virtual bool process(std::chrono::system_clock::time_point& _time,
|
||||
void* _input,
|
||||
size_t _inputNbChunk,
|
||||
void*& _output,
|
||||
size_t& _outputNbChunk);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user