[DEV] add multiple volume system

This commit is contained in:
Edouard DUPIN 2015-02-03 21:29:23 +01:00
parent 87e3cf9747
commit 8e53a56b2a
4 changed files with 150 additions and 10 deletions

View File

@ -178,6 +178,27 @@ namespace airtalgo{
}
return m_supportedFrequency;
};
public:
/**
* @brief Set a parameter in the stream flow
* @param[in] _parameter Parameter name.
* @param[in] _value Value to set.
* @return true set done
* @return false An error occured
*/
virtual bool setParameter(const std::string& _parameter, const std::string& _value) { return false; }
/**
* @brief Get a parameter value
* @param[in] _parameter Parameter name.
* @return The requested value.
*/
virtual std::string getParameter(const std::string& _parameter) const { return "[ERROR]"; }
/**
* @brief Get a parameter value
* @param[in] _parameter Parameter name.
* @return The requested value.
*/
virtual std::string getParameterProperty(const std::string& _parameter) const { return "[ERROR]"; };
};
};
#include "debugRemove.h"

View File

@ -92,6 +92,17 @@ namespace airtalgo{
template<typename T> std::shared_ptr<T> get(int32_t _id) {
return std::dynamic_pointer_cast<T>(m_listAlgo[_id]);
}
template<typename T> std::shared_ptr<T> get(const std::string& _name) {
for (auto &it : m_listAlgo) {
if (it == nullptr) {
continue;
}
if (it->getName() == _name) {
return std::dynamic_pointer_cast<T>(it);
}
}
return nullptr;
}
template<typename T> bool hasType() {
for (auto &it : m_listAlgo) {
std::shared_ptr<T> tmp = std::dynamic_pointer_cast<T>(it);

View File

@ -12,7 +12,6 @@
#define __class__ "Volume"
airtalgo::Volume::Volume() :
m_volumedB(0.0f),
m_volumeAppli(1.0f),
m_functionConvert(nullptr) {
@ -35,6 +34,13 @@ airtalgo::Volume::~Volume() {
}
static int32_t neareastsss(float _val) {
int32_t out = 0;
while (_val > float(1<<out)) {
out++;
}
return std::min(16,out);
}
static void convert__int16__to__int16(void* _input, void* _output, size_t _nbSample, int32_t _volumeCoef, int32_t _volumeDecalage, float _volumeAppli) {
@ -146,7 +152,16 @@ void airtalgo::Volume::configurationChange() {
void airtalgo::Volume::updateVolumeValues() {
//m_volumeAppli = 20 * log(m_volumedB);
m_volumeAppli = std::pow(10.0f, m_volumedB/20.0f);
float volumedB = 0.0f;
for (auto &it : m_volumeList) {
if (it == nullptr) {
continue;
}
volumedB += it->getVolume();
AIRTALGO_DEBUG("append volume : '" << it->getName() << " vol=" << it->getVolume() << "dB");
}
AIRTALGO_DEBUG(" Total volume : " << volumedB << "dB nbVolume=" << m_volumeList.size());
m_volumeAppli = std::pow(10.0f, volumedB/20.0f);
switch (m_input.getFormat()) {
default:
case format_int16:
@ -282,13 +297,6 @@ std::vector<airtalgo::format> airtalgo::Volume::getFormatSupportedOutput() {
return tmp;
};
static int32_t neareastsss(float _val) {
int32_t out = 0;
while (_val > float(1<<out)) {
out++;
}
return std::min(16,out);
}
bool airtalgo::Volume::process(std::chrono::system_clock::time_point& _time,
void* _input,
@ -321,3 +329,74 @@ bool airtalgo::Volume::process(std::chrono::system_clock::time_point& _time,
m_functionConvert(_input, _output, _outputNbChunk*m_input.getMap().size(), m_volumeCoef, m_volumeDecalage, m_volumeAppli);
return true;
}
void airtalgo::Volume::addVolumeStage(const std::shared_ptr<VolumeElement>& _volume) {
if (_volume == nullptr) {
return;
}
for (auto &it : m_volumeList) {
if (it == nullptr) {
continue;
}
if (it == _volume) {
return;
}
if (it->getName() == _volume->getName()) {
return;
}
}
m_volumeList.push_back(_volume);
}
bool airtalgo::Volume::setParameter(const std::string& _parameter, const std::string& _value) {
if (_parameter == "FLOW") {
// set Volume ...
for (auto &it : m_volumeList) {
if (it == nullptr) {
continue;
}
if (it->getName() == "FLOW") {
float value = 0;
sscanf(_value.c_str(), "%fdB", &value);
// TODO : Check if out of range ...
it->setVolume(value);
AIRTALGO_DEBUG("Set volume : FLOW = " << value << " dB (from:" << _value << ")");
return true;
}
}
}
AIRTALGO_ERROR("unknow set Parameter : '" << _parameter << "' with Value: '" << _value << "'");
return false;
}
std::string airtalgo::Volume::getParameter(const std::string& _parameter) const {
if (_parameter == "FLOW") {
// set Volume ...
for (auto &it : m_volumeList) {
if (it == nullptr) {
continue;
}
if (it->getName() == "FLOW") {
return std::to_string(it->getVolume()) + "dB";
}
}
}
AIRTALGO_ERROR("unknow get Parameter : '" << _parameter << "'");
return "[ERROR]";
}
std::string airtalgo::Volume::getParameterProperty(const std::string& _parameter) const {
if (_parameter == "FLOW") {
// set Volume ...
for (auto &it : m_volumeList) {
if (it == nullptr) {
continue;
}
if (it->getName() == "FLOW") {
return "[-300..300]dB";
}
}
}
AIRTALGO_ERROR("unknow Parameter property for: '" << _parameter << "'");
return "[ERROR]";
}

View File

@ -14,6 +14,30 @@
#include <memory>
namespace airtalgo {
// data structure.
class VolumeElement {
public:
VolumeElement(const std::string& _name="ERROR-VOLUME-NAME", float _volumedB=0.0f) :
m_name(_name),
m_volumedB(_volumedB) {
}
private:
std::string m_name;
public:
std::string getName() const {
return m_name;
}
private:
float m_volumedB;
public:
float getVolume() const {
return m_volumedB;
}
void setVolume(float _volumedB) {
m_volumedB = _volumedB;
}
};
// TODO: Optimisation
// TODO: Zero crossing
// TODO: Continuous update volume
@ -21,7 +45,7 @@ namespace airtalgo {
// TODO: Manage set volume
class Volume : public Algo {
private:
float m_volumedB;
std::vector<std::shared_ptr<airtalgo::VolumeElement>> m_volumeList;
// for float input :
float m_volumeAppli;
// for integer input :
@ -54,6 +78,11 @@ namespace airtalgo {
virtual std::vector<airtalgo::format> getFormatSupportedOutput();
protected:
virtual void updateVolumeValues();
public:
virtual void addVolumeStage(const std::shared_ptr<airtalgo::VolumeElement>& _volume);
virtual bool setParameter(const std::string& _parameter, const std::string& _value);
virtual std::string getParameter(const std::string& _parameter) const;
virtual std::string getParameterProperty(const std::string& _parameter) const;
};
};