From 8e53a56b2ac407728eadfadc6dfff214964edd75 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 3 Feb 2015 21:29:23 +0100 Subject: [PATCH] [DEV] add multiple volume system --- airtalgo/Algo.h | 21 ++++++++++ airtalgo/Process.h | 11 +++++ airtalgo/Volume.cpp | 97 ++++++++++++++++++++++++++++++++++++++++----- airtalgo/Volume.h | 31 ++++++++++++++- 4 files changed, 150 insertions(+), 10 deletions(-) diff --git a/airtalgo/Algo.h b/airtalgo/Algo.h index 21bb28f..35173d9 100644 --- a/airtalgo/Algo.h +++ b/airtalgo/Algo.h @@ -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" diff --git a/airtalgo/Process.h b/airtalgo/Process.h index fea0c0d..5ec6f7e 100644 --- a/airtalgo/Process.h +++ b/airtalgo/Process.h @@ -92,6 +92,17 @@ namespace airtalgo{ template std::shared_ptr get(int32_t _id) { return std::dynamic_pointer_cast(m_listAlgo[_id]); } + template std::shared_ptr get(const std::string& _name) { + for (auto &it : m_listAlgo) { + if (it == nullptr) { + continue; + } + if (it->getName() == _name) { + return std::dynamic_pointer_cast(it); + } + } + return nullptr; + } template bool hasType() { for (auto &it : m_listAlgo) { std::shared_ptr tmp = std::dynamic_pointer_cast(it); diff --git a/airtalgo/Volume.cpp b/airtalgo/Volume.cpp index 6f45530..99f6e0a 100644 --- a/airtalgo/Volume.cpp +++ b/airtalgo/Volume.cpp @@ -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<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::Volume::getFormatSupportedOutput() { return tmp; }; -static int32_t neareastsss(float _val) { - int32_t out = 0; - while (_val > float(1<& _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]"; +} \ No newline at end of file diff --git a/airtalgo/Volume.h b/airtalgo/Volume.h index 53d4aa9..e175127 100644 --- a/airtalgo/Volume.h +++ b/airtalgo/Volume.h @@ -14,6 +14,30 @@ #include 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> m_volumeList; // for float input : float m_volumeAppli; // for integer input : @@ -54,6 +78,11 @@ namespace airtalgo { virtual std::vector getFormatSupportedOutput(); protected: virtual void updateVolumeValues(); + public: + virtual void addVolumeStage(const std::shared_ptr& _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; }; };