2015-01-25 22:10:49 +01:00
|
|
|
/** @file
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
|
|
|
* @license APACHE v2.0 (see license file)
|
|
|
|
*/
|
2015-04-10 23:00:13 +02:00
|
|
|
#include <audio/drain/Algo.h>
|
2015-01-25 22:10:49 +01:00
|
|
|
#include <functional>
|
|
|
|
#include "debug.h"
|
|
|
|
|
2015-02-01 22:22:42 +01:00
|
|
|
|
2015-01-27 21:26:03 +01:00
|
|
|
#undef __class__
|
|
|
|
#define __class__ "Algo"
|
2015-01-25 22:10:49 +01:00
|
|
|
|
2015-04-10 23:00:13 +02:00
|
|
|
audio::drain::Algo::Algo() :
|
2015-02-01 22:22:42 +01:00
|
|
|
m_temporary(false),
|
2015-01-25 22:10:49 +01:00
|
|
|
m_outputData(),
|
|
|
|
m_formatSize(0),
|
|
|
|
m_needProcess(false) {
|
2015-02-09 21:44:32 +01:00
|
|
|
|
2015-01-29 21:46:01 +01:00
|
|
|
}
|
|
|
|
|
2015-04-10 23:00:13 +02:00
|
|
|
void audio::drain::Algo::init() {
|
2015-01-25 22:10:49 +01:00
|
|
|
// set notification callback :
|
2015-04-10 23:00:13 +02:00
|
|
|
m_input.setCallback(std11::bind(&audio::drain::Algo::configurationChangeLocal, this));
|
|
|
|
m_output.setCallback(std11::bind(&audio::drain::Algo::configurationChangeLocal, this));
|
2015-01-25 22:10:49 +01:00
|
|
|
// first configure ==> update the internal parameters
|
|
|
|
configurationChange();
|
|
|
|
}
|
|
|
|
|
2015-04-10 23:00:13 +02:00
|
|
|
void audio::drain::Algo::configurationChange() {
|
2015-01-25 22:10:49 +01:00
|
|
|
m_needProcess = false;
|
|
|
|
if (m_input.getFormat() != m_output.getFormat()) {
|
|
|
|
m_needProcess = true;
|
|
|
|
}
|
|
|
|
if (m_input.getMap() != m_output.getMap()) {
|
|
|
|
m_needProcess = true;
|
|
|
|
}
|
|
|
|
if (m_input.getFrequency() != m_output.getFrequency()) {
|
|
|
|
m_needProcess = true;
|
|
|
|
}
|
|
|
|
switch (m_output.getFormat()) {
|
2015-02-04 22:39:05 +01:00
|
|
|
case audio::format_int8:
|
|
|
|
m_formatSize = sizeof(int8_t);
|
|
|
|
break;
|
|
|
|
case audio::format_int16:
|
2015-01-25 22:10:49 +01:00
|
|
|
m_formatSize = sizeof(int16_t);
|
|
|
|
break;
|
2015-02-04 22:39:05 +01:00
|
|
|
case audio::format_int24:
|
|
|
|
case audio::format_int16_on_int32:
|
|
|
|
case audio::format_int32:
|
2015-01-25 22:10:49 +01:00
|
|
|
m_formatSize = sizeof(int32_t);
|
|
|
|
break;
|
2015-02-04 22:39:05 +01:00
|
|
|
case audio::format_float:
|
2015-01-25 22:10:49 +01:00
|
|
|
m_formatSize = sizeof(float);
|
|
|
|
break;
|
2015-02-04 22:39:05 +01:00
|
|
|
case audio::format_double:
|
|
|
|
m_formatSize = sizeof(double);
|
|
|
|
break;
|
|
|
|
case audio::format_unknow:
|
2015-03-03 21:28:07 +01:00
|
|
|
DRAIN_VERBOSE("format not configured...");
|
2015-02-01 22:22:42 +01:00
|
|
|
m_formatSize = 8;
|
|
|
|
break;
|
2015-01-25 22:10:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-10 23:00:13 +02:00
|
|
|
size_t audio::drain::Algo::needInputData(size_t _output) {
|
2015-01-25 22:10:49 +01:00
|
|
|
size_t input = _output;
|
2015-01-28 22:07:11 +01:00
|
|
|
/* NOT good at all ...
|
2015-01-25 22:10:49 +01:00
|
|
|
if (m_input.getFormat() != m_output.getFormat()) {
|
|
|
|
int32_t inputSize = 3;
|
|
|
|
switch (m_input.getFormat()) {
|
|
|
|
case format_int16:
|
|
|
|
inputSize = sizeof(int16_t);
|
|
|
|
break;
|
|
|
|
case format_int16_on_int32:
|
|
|
|
case format_int32:
|
|
|
|
inputSize = sizeof(int32_t);
|
|
|
|
break;
|
|
|
|
case format_float:
|
|
|
|
inputSize = sizeof(float);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (inputSize != m_formatSize) {
|
|
|
|
input *= inputSize;
|
|
|
|
input /= m_formatSize;
|
|
|
|
}
|
|
|
|
}
|
2015-01-28 22:07:11 +01:00
|
|
|
*/
|
|
|
|
/*
|
2015-01-25 22:10:49 +01:00
|
|
|
if (m_input.getMap().size() != m_output.getMap().size()) {
|
|
|
|
input *= m_input.getMap().size();
|
|
|
|
input /= m_output.getMap().size();
|
|
|
|
}
|
2015-01-28 22:07:11 +01:00
|
|
|
*/
|
2015-01-25 22:10:49 +01:00
|
|
|
|
|
|
|
if (m_input.getFrequency() != m_output.getFrequency()) {
|
|
|
|
input *= m_input.getFrequency();
|
|
|
|
input /= m_output.getFrequency();
|
|
|
|
// to prevent missing data in the resampler
|
|
|
|
input += 2;
|
|
|
|
}
|
|
|
|
return input;
|
|
|
|
}
|
2015-03-18 21:47:27 +01:00
|
|
|
|
2015-04-10 23:00:13 +02:00
|
|
|
void audio::drain::Algo::setStatusFunction(algoStatusFunction _newFunction) {
|
2015-03-18 21:47:27 +01:00
|
|
|
m_statusFunction = _newFunction;
|
|
|
|
}
|
|
|
|
|
2015-04-10 23:00:13 +02:00
|
|
|
void audio::drain::Algo::generateStatus(const std::string& _status) {
|
2015-03-18 21:47:27 +01:00
|
|
|
if (m_statusFunction != nullptr) {
|
|
|
|
if (m_name.size() == 0) {
|
|
|
|
m_statusFunction(m_type, _status);
|
|
|
|
} else {
|
|
|
|
m_statusFunction(m_name, _status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|