[DEV] volume master can be change

This commit is contained in:
Edouard DUPIN 2015-02-03 23:29:34 +01:00
parent d6cc8fce3b
commit dd6f6da518
6 changed files with 130 additions and 26 deletions

View File

@ -45,30 +45,15 @@ std::vector<std::pair<std::string,std::string> > airtio::Manager::getListStreamO
bool airtio::Manager::setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value) {
AIRTIO_DEBUG("setParameter [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "':'" << _value << "'");
bool out = false;
if ( _filter == "volume"
&& _parameter != "FLOW") {
AIRTIO_ERROR("Interface is not allowed to modify '" << _parameter << "' Volume just allowed to modify 'FLOW' volume");
}
AIRTIO_TODO(" IMPLEMENT");
AIRTIO_DEBUG("setParameter [ END ] : '" << out << "'");
return out;
return airtio::io::Manager::getInstance()->setParameter(_flow, _filter, _parameter, _value);
}
std::string airtio::Manager::getParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const {
AIRTIO_DEBUG("getParameter [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "'");
std::string out;
AIRTIO_TODO(" IMPLEMENT");
AIRTIO_DEBUG("getParameter [ END ] : '" << out << "'");
return out;
return airtio::io::Manager::getInstance()->getParameter(_flow, _filter, _parameter);
}
std::string airtio::Manager::getParameterProperty(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const {
AIRTIO_DEBUG("getParameterProperty [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "'");
std::string out;
AIRTIO_TODO(" IMPLEMENT");
AIRTIO_DEBUG("getParameterProperty [ END ] : '" << out << "'");
return out;
return airtio::io::Manager::getInstance()->getParameterProperty(_flow, _filter, _parameter);
}
std::shared_ptr<airtio::Interface>

View File

@ -53,7 +53,7 @@ namespace airtio {
* @param[in] _value Value to set.
* @return true set done
* @return false An error occured
* @example : setParameter("speaker", "volume", "MASTER", "-3dB");
* @example : setParameter("", "volume", "MASTER", "-3dB");
* @example : setParameter("microphone", "LowPassFilter", "cutFrequency", "1000Hz");
*/
virtual bool setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value);
@ -63,7 +63,7 @@ namespace airtio {
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @return The requested value.
* @example : getParameter("speaker", "volume", "MASTER"); can return something like "-3dB"
* @example : getParameter("", "volume", "MASTER"); can return something like "-3dB"
* @example : getParameter("microphone", "LowPassFilter", "cutFrequency"); can return something like "[-120..0]dB"
*/
virtual std::string getParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const;
@ -73,7 +73,7 @@ namespace airtio {
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @return The requested value.
* @example : getParameter("speaker", "volume", "MASTER"); can return something like "[-120..0]dB"
* @example : getParameter("", "volume", "MASTER"); can return something like "[-120..0]dB"
* @example : getParameter("microphone", "LowPassFilter", "cutFreqiency"); can return something like "]100..10000]Hz"
*/
virtual std::string getParameterProperty(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const;

View File

@ -60,4 +60,71 @@ std::shared_ptr<airtalgo::VolumeElement> airtio::io::Manager::getVolumeGroup(con
std::shared_ptr<airtalgo::VolumeElement> tmpVolume = std::make_shared<airtalgo::VolumeElement>(_name);
m_volumeGroup.push_back(tmpVolume);
return tmpVolume;
}
}
bool airtio::io::Manager::setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value) {
AIRTIO_DEBUG("setParameter [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "':'" << _value << "'");
bool out = false;
if ( _flow == ""
&& _filter == "volume") {
// set IO volume
float value = 0;
if (sscanf(_value.c_str(), "%fdB", &value) != 1) {
AIRTIO_ERROR("Can not parse the value of audio volume : '" << _value << "'");
return false;
}
for (auto &it : m_volumeGroup) {
if (it == nullptr) {
continue;
}
if (it->getName() == _parameter) {
it->setVolume(value);
for (auto &it2 : m_list) {
std::shared_ptr<airtio::io::Node> val = it2.lock();
if (val != nullptr) {
// TODO : notify nodes ...
// val->
}
}
return true;
}
}
}
AIRTIO_TODO(" IMPLEMENT");
AIRTIO_DEBUG("setParameter [ END ] : '" << out << "'");
return out;
}
std::string airtio::io::Manager::getParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const {
AIRTIO_DEBUG("getParameter [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "'");
std::string out;
if ( _flow == ""
&& _filter == "volume") {
// get IO volume
for (auto &it : m_volumeGroup) {
if (it == nullptr) {
continue;
}
if (it->getName() == _parameter) {
return std::to_string(it->getVolume()) + "dB";;
}
}
}
AIRTIO_TODO(" IMPLEMENT");
AIRTIO_DEBUG("getParameter [ END ] : '" << out << "'");
return out;
}
std::string airtio::io::Manager::getParameterProperty(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const {
AIRTIO_DEBUG("getParameterProperty [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "'");
std::string out;
if ( _flow == ""
&& _filter == "volume") {
// return generic volumes
return "[-300..300]dB";
}
AIRTIO_TODO(" IMPLEMENT");
AIRTIO_DEBUG("getParameterProperty [ END ] : '" << out << "'");
return out;
}

View File

@ -44,6 +44,39 @@ namespace airtio {
std::vector<std::shared_ptr<airtalgo::VolumeElement>> m_volumeGroup;
public:
std::shared_ptr<airtalgo::VolumeElement> getVolumeGroup(const std::string& _name);
/**
* @brief Set a parameter in the stream flow
* @param[in] _flow Low level Flow name (see json config file)
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @param[in] _value Value to set.
* @return true set done
* @return false An error occured
* @example : setParameter("", "volume", "MASTER", "-3dB");
* @example : setParameter("microphone", "LowPassFilter", "cutFrequency", "1000Hz");
*/
virtual bool setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value);
/**
* @brief Get a parameter value
* @param[in] _flow Low level Flow name (see json config file)
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @return The requested value.
* @example : getParameter("", "volume", "MASTER"); can return something like "-3dB"
* @example : getParameter("microphone", "LowPassFilter", "cutFrequency"); can return something like "[-120..0]dB"
*/
virtual std::string getParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const;
/**
* @brief Get a parameter value
* @param[in] _flow Low level Flow name (see json config file)
* @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @return The requested value.
* @example : getParameter("", "volume", "MASTER"); can return something like "[-120..0]dB"
* @example : getParameter("microphone", "LowPassFilter", "cutFreqiency"); can return something like "]100..10000]Hz"
*/
virtual std::string getParameterProperty(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const;
};
}
}

View File

@ -146,10 +146,10 @@ airtio::io::Node::Node(const std::string& _name, const std::shared_ptr<const ejs
std::string volumeName = m_config->getStringValue("volume-name", "");
if (volumeName != "") {
AIRTIO_INFO("add node volume stage : '" << volumeName << "'");
m_volume = std::make_shared<airtalgo::VolumeElement>(volumeName);
// use global manager for volume ...
m_volume = airtio::io::Manager::getInstance()->getVolumeGroup(volumeName);
}
enum airtalgo::format formatType = airtalgo::format_int16;
if (type == "int16") {
formatType = airtalgo::format_int16;

View File

@ -541,29 +541,48 @@ class testCallbackVolume {
m_interface->start();
usleep(1000000);
m_interface->setParameter("volume", "FLOW", "-3dB");
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
usleep(500000);
/*
m_interface->setParameter("volume", "FLOW", "-6dB");
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
usleep(500000);
m_interface->setParameter("volume", "FLOW", "-9dB");
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
usleep(500000);
m_interface->setParameter("volume", "FLOW", "-12dB");
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
usleep(500000);
m_interface->setParameter("volume", "FLOW", "-3dB");
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
usleep(500000);
*/
m_manager->setParameter("", "volume", "MASTER", "-3dB");
APPL_INFO("get volume MASTER: " << m_manager->getParameter("", "volume", "MASTER") );
usleep(500000);
m_manager->setParameter("", "volume", "MEDIA", "-3dB");
APPL_INFO("get volume MEDIA: " << m_manager->getParameter("", "volume", "MEDIA") );
usleep(500000);
/*
m_interface->setParameter("volume", "FLOW", "3dB");
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
usleep(500000);
m_interface->setParameter("volume", "FLOW", "6dB");
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
usleep(500000);
m_interface->setParameter("volume", "FLOW", "9dB");
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
usleep(500000);
m_interface->setParameter("volume", "FLOW", "0dB");
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
usleep(1000000);
*/
m_interface->stop();
}
};
TEST(testALL, testVolume) {
TEST(TestALL, testVolume) {
std::shared_ptr<airtio::Manager> manager;
manager = airtio::Manager::create("testApplication");
std::shared_ptr<testCallbackVolume> process = std::make_shared<testCallbackVolume>(manager);