[DEV] basic volume group work corectly
This commit is contained in:
parent
dd6f6da518
commit
fb500717f8
@ -38,7 +38,8 @@ bool airtio::Interface::init(const std::string& _name,
|
||||
m_format = _format;
|
||||
m_process = std::make_shared<airtalgo::Process>();
|
||||
m_volume = 0.0f;
|
||||
|
||||
// register interface to be notify from the volume change.
|
||||
m_node->registerAsRemote(shared_from_this());
|
||||
// Create convertion interface
|
||||
if (m_node->isInput() == true) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
bool airtio::Interface::systemSetVolume(const std::string& _parameter, const std::string& _value) {
|
||||
return false;
|
||||
void airtio::Interface::systemVolumeChange() {
|
||||
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();
|
||||
}
|
@ -172,7 +172,7 @@ namespace airtio {
|
||||
private:
|
||||
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 bool systemSetVolume(const std::string& _parameter, const std::string& _value);
|
||||
virtual void systemVolumeChange();
|
||||
float m_volume; //!< Local channel Volume
|
||||
};
|
||||
};
|
||||
|
@ -33,35 +33,34 @@ airtio::Manager::~Manager() {
|
||||
|
||||
std::vector<std::pair<std::string,std::string> > airtio::Manager::getListStreamInput() {
|
||||
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;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string,std::string> > airtio::Manager::getListStreamOutput() {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
bool airtio::Manager::setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value) {
|
||||
return airtio::io::Manager::getInstance()->setParameter(_flow, _filter, _parameter, _value);
|
||||
bool airtio::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
|
||||
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 {
|
||||
return airtio::io::Manager::getInstance()->getParameter(_flow, _filter, _parameter);
|
||||
float airtio::Manager::getVolume(const std::string& _volumeName) const {
|
||||
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 {
|
||||
return airtio::io::Manager::getInstance()->getParameterProperty(_flow, _filter, _parameter);
|
||||
std::pair<float,float> airtio::Manager::getVolumeRange(const std::string& _volumeName) const {
|
||||
return airtio::io::Manager::getInstance()->getVolumeRange(_volumeName);
|
||||
}
|
||||
|
||||
std::shared_ptr<airtio::Interface>
|
||||
airtio::Manager::createOutput(float _freq,
|
||||
const std::vector<airtalgo::channel>& _map,
|
||||
airtalgo::format _format,
|
||||
const std::string& _streamName,
|
||||
const std::string& _name) {
|
||||
std::shared_ptr<airtio::Interface> airtio::Manager::createOutput(float _freq,
|
||||
const std::vector<airtalgo::channel>& _map,
|
||||
airtalgo::format _format,
|
||||
const std::string& _streamName,
|
||||
const std::string& _name) {
|
||||
// get global hardware interface:
|
||||
std::shared_ptr<airtio::io::Manager> manager = airtio::io::Manager::getInstance();
|
||||
// get the output or input channel :
|
||||
@ -71,17 +70,14 @@ airtio::Manager::createOutput(float _freq,
|
||||
interface = airtio::Interface::create(_name, _freq, _map, _format, node);
|
||||
// store it in a list (needed to apply some parameters).
|
||||
m_listOpenInterface.push_back(interface);
|
||||
// TODO : DEPRECATED ...
|
||||
//interface->setMasterVolume(m_masterVolume);
|
||||
return interface;
|
||||
}
|
||||
|
||||
std::shared_ptr<airtio::Interface>
|
||||
airtio::Manager::createInput(float _freq,
|
||||
const std::vector<airtalgo::channel>& _map,
|
||||
airtalgo::format _format,
|
||||
const std::string& _streamName,
|
||||
const std::string& _name) {
|
||||
std::shared_ptr<airtio::Interface> airtio::Manager::createInput(float _freq,
|
||||
const std::vector<airtalgo::channel>& _map,
|
||||
airtalgo::format _format,
|
||||
const std::string& _streamName,
|
||||
const std::string& _name) {
|
||||
// get global hardware interface:
|
||||
std::shared_ptr<airtio::io::Manager> manager = airtio::io::Manager::getInstance();
|
||||
// get the output or input channel :
|
||||
@ -91,7 +87,5 @@ airtio::Manager::createInput(float _freq,
|
||||
interface = airtio::Interface::create(_name, _freq, _map, _format, node);
|
||||
// store it in a list (needed to apply some parameters).
|
||||
m_listOpenInterface.push_back(interface);
|
||||
// TODO : DEPRECATED ...
|
||||
//interface->setMasterVolume(m_masterVolume);
|
||||
return interface;
|
||||
}
|
||||
|
@ -46,37 +46,28 @@ namespace airtio {
|
||||
virtual std::vector<std::pair<std::string,std::string> > getListStreamOutput();
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @brief Set a volume for a specific group
|
||||
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
|
||||
* @param[in] _value Volume in dB to set.
|
||||
* @return true set done
|
||||
* @return false An error occured
|
||||
* @example : setParameter("", "volume", "MASTER", "-3dB");
|
||||
* @example : setParameter("microphone", "LowPassFilter", "cutFrequency", "1000Hz");
|
||||
* @example : setVolume("MASTER", -3.0f);
|
||||
*/
|
||||
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
|
||||
* @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"
|
||||
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
|
||||
* @return The requested value Range.
|
||||
* @example ret = getVolumeRange("MASTER"); can return something like ret=(-120.0f,0.0f)
|
||||
*/
|
||||
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;
|
||||
virtual std::pair<float,float> getVolumeRange(const std::string& _volumeName) const;
|
||||
|
||||
/**
|
||||
* @brief Create output Interface
|
||||
|
@ -53,7 +53,7 @@ std::shared_ptr<airtalgo::VolumeElement> airtio::io::Manager::getVolumeGroup(con
|
||||
continue;
|
||||
}
|
||||
if (it->getName() == _name) {
|
||||
return nullptr;
|
||||
return it;
|
||||
}
|
||||
}
|
||||
AIRTIO_DEBUG("Add a new volume group : '" << _name << "'");
|
||||
@ -62,69 +62,32 @@ std::shared_ptr<airtalgo::VolumeElement> airtio::io::Manager::getVolumeGroup(con
|
||||
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;
|
||||
}
|
||||
bool airtio::io::Manager::setVolume(const std::string& _volumeName, float _valuedB) {
|
||||
std::shared_ptr<airtalgo::VolumeElement> volume = getVolumeGroup(_volumeName);
|
||||
if (volume == nullptr) {
|
||||
AIRTIO_ERROR("Can not get volume ... : '" << _volumeName << "'");
|
||||
return false;
|
||||
}
|
||||
// TODO : Check range ...
|
||||
volume->setVolume(_valuedB);
|
||||
for (auto &it2 : m_list) {
|
||||
std::shared_ptr<airtio::io::Node> val = it2.lock();
|
||||
if (val != nullptr) {
|
||||
val->volumeChange();
|
||||
}
|
||||
}
|
||||
AIRTIO_TODO(" IMPLEMENT");
|
||||
AIRTIO_DEBUG("setParameter [ END ] : '" << out << "'");
|
||||
return out;
|
||||
return true;
|
||||
}
|
||||
|
||||
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";;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
AIRTIO_TODO(" IMPLEMENT");
|
||||
AIRTIO_DEBUG("getParameter [ END ] : '" << out << "'");
|
||||
return out;
|
||||
return volume->getVolume();
|
||||
}
|
||||
|
||||
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;
|
||||
std::pair<float,float> airtio::io::Manager::getVolumeRange(const std::string& _volumeName) const {
|
||||
return std::make_pair<float,float>(-300, 300);
|
||||
}
|
||||
|
@ -44,39 +44,30 @@ 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.
|
||||
* @brief Set a volume for a specific group
|
||||
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
|
||||
* @param[in] _value Volume in dB to set.
|
||||
* @return true set done
|
||||
* @return false An error occured
|
||||
* @example : setParameter("", "volume", "MASTER", "-3dB");
|
||||
* @example : setParameter("microphone", "LowPassFilter", "cutFrequency", "1000Hz");
|
||||
* @example : setVolume("MASTER", -3.0f);
|
||||
*/
|
||||
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
|
||||
* @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"
|
||||
* @param[in] _volumeName Name of the volume (MASTER, MATER_BT ...)
|
||||
* @return The requested value Range.
|
||||
* @example ret = getVolumeRange("MASTER"); can return something like ret=(-120.0f,0.0f)
|
||||
*/
|
||||
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;
|
||||
virtual std::pair<float,float> getVolumeRange(const std::string& _volumeName) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
@ -344,3 +355,12 @@ void airtio::io::Node::interfaceRemove(const std::shared_ptr<airtio::Interface>&
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void airtio::io::Node::volumeChange() {
|
||||
for (auto &it : m_listAvaillable) {
|
||||
std::shared_ptr<airtio::Interface> node = it.lock();
|
||||
if (node != nullptr) {
|
||||
node->systemVolumeChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,10 @@ namespace airtio {
|
||||
*/
|
||||
virtual ~Node();
|
||||
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;
|
||||
public:
|
||||
void registerAsRemote(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);
|
||||
private:
|
||||
@ -86,6 +88,8 @@ namespace airtio {
|
||||
const std::shared_ptr<airtalgo::VolumeElement>& getVolume() {
|
||||
return m_volume;
|
||||
}
|
||||
public:
|
||||
void volumeChange();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -557,11 +557,11 @@ class testCallbackVolume {
|
||||
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") );
|
||||
m_manager->setVolume("MASTER", -3.0f);
|
||||
APPL_INFO("get volume MASTER: " << m_manager->getVolume("MASTER") );
|
||||
usleep(500000);
|
||||
m_manager->setParameter("", "volume", "MEDIA", "-3dB");
|
||||
APPL_INFO("get volume MEDIA: " << m_manager->getParameter("", "volume", "MEDIA") );
|
||||
m_manager->setVolume("MEDIA", -3.0f);
|
||||
APPL_INFO("get volume MEDIA: " << m_manager->getVolume("MEDIA") );
|
||||
usleep(500000);
|
||||
/*
|
||||
m_interface->setParameter("volume", "FLOW", "3dB");
|
||||
|
Loading…
Reference in New Issue
Block a user