[DEV] basic volume group work corectly

This commit is contained in:
Edouard DUPIN 2015-02-04 21:08:06 +01:00
parent dd6f6da518
commit fb500717f8
9 changed files with 111 additions and 142 deletions

View File

@ -38,7 +38,8 @@ bool airtio::Interface::init(const std::string& _name,
m_format = _format; m_format = _format;
m_process = std::make_shared<airtalgo::Process>(); m_process = std::make_shared<airtalgo::Process>();
m_volume = 0.0f; m_volume = 0.0f;
// register interface to be notify from the volume change.
m_node->registerAsRemote(shared_from_this());
// Create convertion interface // Create convertion interface
if (m_node->isInput() == true) { if (m_node->isInput() == true) {
// add all time the volume stage : // add all time the volume stage :
@ -310,6 +311,11 @@ void airtio::Interface::systemNeedOutputData(std::chrono::system_clock::time_poi
m_process->pull(_time, _data, _nbChunk, _chunkSize); m_process->pull(_time, _data, _nbChunk, _chunkSize);
} }
bool airtio::Interface::systemSetVolume(const std::string& _parameter, const std::string& _value) { void airtio::Interface::systemVolumeChange() {
return false; std::unique_lock<std::recursive_mutex> lockProcess(m_mutex);
std::shared_ptr<airtalgo::Volume> algo = m_process->get<airtalgo::Volume>("volume");
if (algo == nullptr) {
return;
}
algo->volumeChange();
} }

View File

@ -172,7 +172,7 @@ namespace airtio {
private: private:
virtual void systemNewInputData(std::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk); virtual void systemNewInputData(std::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk);
virtual void systemNeedOutputData(std::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize); virtual void systemNeedOutputData(std::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize);
virtual bool systemSetVolume(const std::string& _parameter, const std::string& _value); virtual void systemVolumeChange();
float m_volume; //!< Local channel Volume float m_volume; //!< Local channel Volume
}; };
}; };

View File

@ -33,31 +33,30 @@ airtio::Manager::~Manager() {
std::vector<std::pair<std::string,std::string> > airtio::Manager::getListStreamInput() { std::vector<std::pair<std::string,std::string> > airtio::Manager::getListStreamInput() {
std::vector<std::pair<std::string,std::string> > output; std::vector<std::pair<std::string,std::string> > output;
output.push_back(std::make_pair<std::string,std::string>("default", "48000 Hz, 16 bits, 2 channels: Default input ")); //output.push_back(std::make_pair<std::string,std::string>("default", "48000 Hz, 16 bits, 2 channels: Default input "));
return output; return output;
} }
std::vector<std::pair<std::string,std::string> > airtio::Manager::getListStreamOutput() { std::vector<std::pair<std::string,std::string> > airtio::Manager::getListStreamOutput() {
std::vector<std::pair<std::string,std::string> > output; std::vector<std::pair<std::string,std::string> > output;
output.push_back(std::make_pair<std::string,std::string>("default", "48000 Hz, 16 bits, 2 channels: Default output ")); //output.push_back(std::make_pair<std::string,std::string>("default", "48000 Hz, 16 bits, 2 channels: Default output "));
return output; return output;
} }
bool airtio::Manager::setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value) { bool airtio::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
return airtio::io::Manager::getInstance()->setParameter(_flow, _filter, _parameter, _value); return airtio::io::Manager::getInstance()->setVolume(_volumeName, _valuedB);
} }
std::string airtio::Manager::getParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const { float airtio::Manager::getVolume(const std::string& _volumeName) const {
return airtio::io::Manager::getInstance()->getParameter(_flow, _filter, _parameter); return airtio::io::Manager::getInstance()->getVolume(_volumeName);
} }
std::string airtio::Manager::getParameterProperty(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const { std::pair<float,float> airtio::Manager::getVolumeRange(const std::string& _volumeName) const {
return airtio::io::Manager::getInstance()->getParameterProperty(_flow, _filter, _parameter); return airtio::io::Manager::getInstance()->getVolumeRange(_volumeName);
} }
std::shared_ptr<airtio::Interface> std::shared_ptr<airtio::Interface> airtio::Manager::createOutput(float _freq,
airtio::Manager::createOutput(float _freq,
const std::vector<airtalgo::channel>& _map, const std::vector<airtalgo::channel>& _map,
airtalgo::format _format, airtalgo::format _format,
const std::string& _streamName, const std::string& _streamName,
@ -71,13 +70,10 @@ airtio::Manager::createOutput(float _freq,
interface = airtio::Interface::create(_name, _freq, _map, _format, node); interface = airtio::Interface::create(_name, _freq, _map, _format, node);
// store it in a list (needed to apply some parameters). // store it in a list (needed to apply some parameters).
m_listOpenInterface.push_back(interface); m_listOpenInterface.push_back(interface);
// TODO : DEPRECATED ...
//interface->setMasterVolume(m_masterVolume);
return interface; return interface;
} }
std::shared_ptr<airtio::Interface> std::shared_ptr<airtio::Interface> airtio::Manager::createInput(float _freq,
airtio::Manager::createInput(float _freq,
const std::vector<airtalgo::channel>& _map, const std::vector<airtalgo::channel>& _map,
airtalgo::format _format, airtalgo::format _format,
const std::string& _streamName, const std::string& _streamName,
@ -91,7 +87,5 @@ airtio::Manager::createInput(float _freq,
interface = airtio::Interface::create(_name, _freq, _map, _format, node); interface = airtio::Interface::create(_name, _freq, _map, _format, node);
// store it in a list (needed to apply some parameters). // store it in a list (needed to apply some parameters).
m_listOpenInterface.push_back(interface); m_listOpenInterface.push_back(interface);
// TODO : DEPRECATED ...
//interface->setMasterVolume(m_masterVolume);
return interface; return interface;
} }

View File

@ -46,37 +46,28 @@ namespace airtio {
virtual std::vector<std::pair<std::string,std::string> > getListStreamOutput(); virtual std::vector<std::pair<std::string,std::string> > getListStreamOutput();
/** /**
* @brief Set a parameter in the stream flow * @brief Set a volume for a specific group
* @param[in] _flow Low level Flow name (see json config file) * @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @param[in] _filter name of the filter (if you added some personels) * @param[in] _value Volume in dB to set.
* @param[in] _parameter Parameter name.
* @param[in] _value Value to set.
* @return true set done * @return true set done
* @return false An error occured * @return false An error occured
* @example : setParameter("", "volume", "MASTER", "-3dB"); * @example : setVolume("MASTER", -3.0f);
* @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); virtual bool setVolume(const std::string& _volumeName, float _valuedB);
/**
* @brief Get a volume value
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @return The Volume value in dB.
* @example ret = getVolume("MASTER"); can return something like ret = -3.0f
*/
virtual float getVolume(const std::string& _volumeName) const;
/** /**
* @brief Get a parameter value * @brief Get a parameter value
* @param[in] _flow Low level Flow name (see json config file) * @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @param[in] _filter name of the filter (if you added some personels) * @return The requested value Range.
* @param[in] _parameter Parameter name. * @example ret = getVolumeRange("MASTER"); can return something like ret=(-120.0f,0.0f)
* @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; virtual std::pair<float,float> getVolumeRange(const std::string& _volumeName) 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;
/** /**
* @brief Create output Interface * @brief Create output Interface

View File

@ -53,7 +53,7 @@ std::shared_ptr<airtalgo::VolumeElement> airtio::io::Manager::getVolumeGroup(con
continue; continue;
} }
if (it->getName() == _name) { if (it->getName() == _name) {
return nullptr; return it;
} }
} }
AIRTIO_DEBUG("Add a new volume group : '" << _name << "'"); AIRTIO_DEBUG("Add a new volume group : '" << _name << "'");
@ -62,69 +62,32 @@ std::shared_ptr<airtalgo::VolumeElement> airtio::io::Manager::getVolumeGroup(con
return tmpVolume; return tmpVolume;
} }
bool airtio::io::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
bool airtio::io::Manager::setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value) { std::shared_ptr<airtalgo::VolumeElement> volume = getVolumeGroup(_volumeName);
AIRTIO_DEBUG("setParameter [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "':'" << _value << "'"); if (volume == nullptr) {
bool out = false; AIRTIO_ERROR("Can not get volume ... : '" << _volumeName << "'");
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; return false;
} }
for (auto &it : m_volumeGroup) { // TODO : Check range ...
if (it == nullptr) { volume->setVolume(_valuedB);
continue;
}
if (it->getName() == _parameter) {
it->setVolume(value);
for (auto &it2 : m_list) { for (auto &it2 : m_list) {
std::shared_ptr<airtio::io::Node> val = it2.lock(); std::shared_ptr<airtio::io::Node> val = it2.lock();
if (val != nullptr) { if (val != nullptr) {
// TODO : notify nodes ... val->volumeChange();
// val->
} }
} }
return true; return true;
} }
float airtio::io::Manager::getVolume(const std::string& _volumeName) {
std::shared_ptr<airtalgo::VolumeElement> volume = getVolumeGroup(_volumeName);
if (volume == nullptr) {
AIRTIO_ERROR("Can not get volume ... : '" << _volumeName << "'");
return 0.0f;
} }
} return volume->getVolume();
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 { std::pair<float,float> airtio::io::Manager::getVolumeRange(const std::string& _volumeName) const {
AIRTIO_DEBUG("getParameter [BEGIN] : '" << _flow << "':'" << _filter << "':'" << _parameter << "'"); return std::make_pair<float,float>(-300, 300);
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

@ -46,37 +46,28 @@ namespace airtio {
std::shared_ptr<airtalgo::VolumeElement> getVolumeGroup(const std::string& _name); std::shared_ptr<airtalgo::VolumeElement> getVolumeGroup(const std::string& _name);
/** /**
* @brief Set a parameter in the stream flow * @brief Set a volume for a specific group
* @param[in] _flow Low level Flow name (see json config file) * @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @param[in] _filter name of the filter (if you added some personels) * @param[in] _value Volume in dB to set.
* @param[in] _parameter Parameter name.
* @param[in] _value Value to set.
* @return true set done * @return true set done
* @return false An error occured * @return false An error occured
* @example : setParameter("", "volume", "MASTER", "-3dB"); * @example : setVolume("MASTER", -3.0f);
* @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); virtual bool setVolume(const std::string& _volumeName, float _valuedB);
/**
* @brief Get a volume value
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @return The Volume value in dB.
* @example ret = getVolume("MASTER"); can return something like ret = -3.0f
*/
virtual float getVolume(const std::string& _volumeName);
/** /**
* @brief Get a parameter value * @brief Get a parameter value
* @param[in] _flow Low level Flow name (see json config file) * @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
* @param[in] _filter name of the filter (if you added some personels) * @return The requested value Range.
* @param[in] _parameter Parameter name. * @example ret = getVolumeRange("MASTER"); can return something like ret=(-120.0f,0.0f)
* @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; virtual std::pair<float,float> getVolumeRange(const std::string& _volumeName) 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

@ -311,6 +311,17 @@ void airtio::io::Node::stop() {
} }
} }
void airtio::io::Node::registerAsRemote(const std::shared_ptr<airtio::Interface>& _interface) {
auto it = m_listAvaillable.begin();
while (it != m_listAvaillable.end()) {
if (it->expired() == true) {
it = m_listAvaillable.erase(it);
}
++it;
}
m_listAvaillable.push_back(_interface);
}
void airtio::io::Node::interfaceAdd(const std::shared_ptr<airtio::Interface>& _interface) { void airtio::io::Node::interfaceAdd(const std::shared_ptr<airtio::Interface>& _interface) {
{ {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
@ -344,3 +355,12 @@ void airtio::io::Node::interfaceRemove(const std::shared_ptr<airtio::Interface>&
return; return;
} }
void airtio::io::Node::volumeChange() {
for (auto &it : m_listAvaillable) {
std::shared_ptr<airtio::Interface> node = it.lock();
if (node != nullptr) {
node->systemVolumeChange();
}
}
}

View File

@ -42,8 +42,10 @@ namespace airtio {
*/ */
virtual ~Node(); virtual ~Node();
private: private:
std::vector<std::weak_ptr<airtio::Interface> > m_listAvaillable; //!< List of all interface that exist on this Node
std::vector<std::shared_ptr<airtio::Interface> > m_list; std::vector<std::shared_ptr<airtio::Interface> > m_list;
public: public:
void registerAsRemote(const std::shared_ptr<airtio::Interface>& _interface);
void interfaceAdd(const std::shared_ptr<airtio::Interface>& _interface); void interfaceAdd(const std::shared_ptr<airtio::Interface>& _interface);
void interfaceRemove(const std::shared_ptr<airtio::Interface>& _interface); void interfaceRemove(const std::shared_ptr<airtio::Interface>& _interface);
private: private:
@ -86,6 +88,8 @@ namespace airtio {
const std::shared_ptr<airtalgo::VolumeElement>& getVolume() { const std::shared_ptr<airtalgo::VolumeElement>& getVolume() {
return m_volume; return m_volume;
} }
public:
void volumeChange();
}; };
} }
} }

View File

@ -557,11 +557,11 @@ class testCallbackVolume {
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") ); APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
usleep(500000); usleep(500000);
*/ */
m_manager->setParameter("", "volume", "MASTER", "-3dB"); m_manager->setVolume("MASTER", -3.0f);
APPL_INFO("get volume MASTER: " << m_manager->getParameter("", "volume", "MASTER") ); APPL_INFO("get volume MASTER: " << m_manager->getVolume("MASTER") );
usleep(500000); usleep(500000);
m_manager->setParameter("", "volume", "MEDIA", "-3dB"); m_manager->setVolume("MEDIA", -3.0f);
APPL_INFO("get volume MEDIA: " << m_manager->getParameter("", "volume", "MEDIA") ); APPL_INFO("get volume MEDIA: " << m_manager->getVolume("MEDIA") );
usleep(500000); usleep(500000);
/* /*
m_interface->setParameter("volume", "FLOW", "3dB"); m_interface->setParameter("volume", "FLOW", "3dB");