[DEV] add set parameter update

This commit is contained in:
Edouard DUPIN 2015-01-30 21:44:36 +01:00
parent ef1b25529f
commit 12a60900cc
5 changed files with 112 additions and 69 deletions

View File

@ -176,24 +176,30 @@ void airtio::Interface::abort() {
AIRTIO_DEBUG("abort [ END ]"); AIRTIO_DEBUG("abort [ END ]");
} }
void airtio::Interface::setVolume(float _gainDB) { bool airtio::Interface::setParameter(const std::string& _filter, const std::string& _parameter, const std::string& _value) {
std::unique_lock<std::recursive_mutex> lock(m_mutex); AIRTIO_DEBUG("setParameter [BEGIN] : '" << _filter << "':'" << _parameter << "':'" << _value << "'");
AIRTIO_DEBUG("setVolume [BEGIN]"); bool out = false;
// TODO :... if ( _filter == "volume"
AIRTIO_DEBUG("setVolume [ END ]"); && _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;
} }
std::string airtio::Interface::getParameter(const std::string& _filter, const std::string& _parameter) const {
float airtio::Interface::getVolume() const { AIRTIO_DEBUG("getParameter [BEGIN] : '" << _filter << "':'" << _parameter << "'");
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::string out;
AIRTIO_DEBUG("getVolume [BEGIN]"); AIRTIO_TODO(" IMPLEMENT");
// TODO :... AIRTIO_DEBUG("getParameter [ END ] : '" << out << "'");
AIRTIO_DEBUG("getVolume [ END ]"); return out;
return 0;
} }
std::string airtio::Interface::getParameterProperty(const std::string& _filter, const std::string& _parameter) const {
std::pair<float,float> airtio::Interface::getVolumeRange() const { AIRTIO_DEBUG("getParameterProperty [BEGIN] : '" << _filter << "':'" << _parameter << "'");
std::unique_lock<std::recursive_mutex> lock(m_mutex); std::string out;
return std::make_pair(-120.0f, 0.0f); AIRTIO_TODO(" IMPLEMENT");
AIRTIO_DEBUG("getParameterProperty [ END ] : '" << out << "'");
return out;
} }
void airtio::Interface::write(const void* _value, size_t _nbChunk) { void airtio::Interface::write(const void* _value, size_t _nbChunk) {
@ -274,7 +280,9 @@ void airtio::Interface::systemNewInputData(std::chrono::system_clock::time_point
m_process->push(_time, _data, _nbChunk); m_process->push(_time, _data, _nbChunk);
} }
void airtio::Interface::systemNeedOutputData(std::chrono::system_clock::time_point _time, void*& _data, size_t& _nbChunk, size_t _chunkSize) { void airtio::Interface::systemNeedOutputData(std::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize) {
std::unique_lock<std::recursive_mutex> lockProcess(m_mutex); std::unique_lock<std::recursive_mutex> lockProcess(m_mutex);
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);

View File

@ -87,20 +87,34 @@ namespace airtio {
*/ */
virtual void abort(); virtual void abort();
/** /**
* @brief Set the volume of this interface * @brief Set a parameter in the stream flow
* @param[in] _gainDB Gain in decibel to apply * @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", "FLOW", "-3dB");
* @example : setParameter("LowPassFilter", "cutFrequency", "1000Hz");
*/ */
virtual void setVolume(float _gainDB); virtual bool setParameter(const std::string& _filter, const std::string& _parameter, const std::string& _value);
/** /**
* @brief Get the volume of this interface * @brief Get a parameter value
* @return The gain in decibel applyied * @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @return The requested value.
* @example : getParameter("volume", "FLOW"); can return something like "-3dB"
* @example : getParameter("LowPassFilter", "cutFrequency"); can return something like "[-120..0]dB"
*/ */
virtual float getVolume() const; virtual std::string getParameter(const std::string& _filter, const std::string& _parameter) const;
/** /**
* @brief Get the volume range of this interface * @brief Get a parameter value
* @return The gain in decibel range of this interface * @param[in] _filter name of the filter (if you added some personels)
* @param[in] _parameter Parameter name.
* @return The requested value.
* @example : getParameter("volume", "FLOW"); can return something like "[-120..0]dB"
* @example : getParameter("LowPassFilter", "cutFreqiency"); can return something like "]100..10000]Hz"
*/ */
virtual std::pair<float,float> getVolumeRange() const; virtual std::string getParameterProperty(const std::string& _filter, const std::string& _parameter) const;
/** /**
* @brief write some audio sample in the speakers * @brief write some audio sample in the speakers
* @param[in] _value Data To write on output * @param[in] _value Data To write on output
@ -141,9 +155,8 @@ namespace airtio {
virtual std::chrono::system_clock::time_point getCurrentTime() const; virtual std::chrono::system_clock::time_point getCurrentTime() const;
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);
std::vector<int8_t> m_data;
float m_volume; //!< Local channel Volume float m_volume; //!< Local channel Volume
}; };
}; };

View File

@ -44,6 +44,34 @@ std::vector<std::pair<std::string,std::string> > airtio::Manager::getListStreamO
return output; return output;
} }
bool 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;
}
std::string 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;
}
std::string 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;
}
// TODO : Deprecated ... // TODO : Deprecated ...
void airtio::Manager::setMasterOutputVolume(float _gainDB) { void airtio::Manager::setMasterOutputVolume(float _gainDB) {
if (_gainDB < m_masterVolumeRange.first) { if (_gainDB < m_masterVolumeRange.first) {

View File

@ -44,44 +44,39 @@ namespace airtio {
* @return a list of all availlables output stream (name + description) * @return a list of all availlables output stream (name + description)
*/ */
virtual std::vector<std::pair<std::string,std::string> > getListStreamOutput(); virtual std::vector<std::pair<std::string,std::string> > getListStreamOutput();
protected:
float m_masterVolume;
std::pair<float,float> m_masterVolumeRange;
public:
/**
* @brief Set the output volume master of the Audio interface
* @param[in] _gainDB Gain in decibel to apply in volume Master
*/
virtual void setMasterOutputVolume(float _gainDB);
/**
* @brief Get the output volume master of the Audio interface
* @return The gain in decibel applyied in volume Master
*/
virtual float getMasterOutputVolume();
/**
* @brief Get the output volume master range of the Audio interface
* @return The gain in decibel range of the output volume Master
*/
virtual std::pair<float,float> getMasterOutputVolumeRange();
/** /**
* @brief Set the section volume of the Audio interface * @brief Set a parameter in the stream flow
* @param[in] _gainDB Gain in decibel to apply in volume section * @param[in] _flow Low level Flow name (see json config file)
* @param[in] _section section name to apply volume (a section is : tts, reco, player, interjection ...) * @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("speaker", "volume", "MASTER", "-3dB");
* @example : setParameter("microphone", "LowPassFilter", "cutFrequency", "1000Hz");
*/ */
virtual void setSectionVolume(const std::string& _section, float _gainDB); virtual bool setParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter, const std::string& _value);
/** /**
* @brief Get the section volume of the Audio interface * @brief Get a parameter value
* @param[in] _section section name to apply volume (a section is : tts, reco, player, interjection ...) * @param[in] _flow Low level Flow name (see json config file)
* @return The gain in decibel applyied in volume section * @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("microphone", "LowPassFilter", "cutFrequency"); can return something like "[-120..0]dB"
*/ */
virtual float getSectionVolume(const std::string& _section); virtual std::string getParameter(const std::string& _flow, const std::string& _filter, const std::string& _parameter) const;
/** /**
* @brief Get the section volume range of the Audio interface * @brief Get a parameter value
* @param[in] _section section name to apply volume (a section is : tts, reco, player, interjection ...) * @param[in] _flow Low level Flow name (see json config file)
* @return The gain in decibel range of the section volume * @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("microphone", "LowPassFilter", "cutFreqiency"); can return something like "]100..10000]Hz"
*/ */
virtual std::pair<float,float> getSectionVolumeRange(const std::string& _section); 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

@ -37,20 +37,20 @@ int32_t airtio::io::Node::rtAudioCallback(void* _outputBuffer,
AIRTIO_VERBOSE("data Output"); AIRTIO_VERBOSE("data Output");
std::vector<int32_t> output; std::vector<int32_t> output;
output.resize(_nBufferFrames*m_map.size(), 0); output.resize(_nBufferFrames*m_map.size(), 0);
int16_t* outputTmp = nullptr; const int16_t* outputTmp = nullptr;
void* outputTmp2 = nullptr; std::vector<uint8_t> outputTmp2;
size_t tmpSize = 0; outputTmp2.resize(sizeof(int16_t)*m_map.size()*_nBufferFrames, 0);
for (auto &it : m_list) { for (auto &it : m_list) {
if (it != nullptr) { if (it != nullptr) {
// clear datas ...
memset(&outputTmp2[0], 0, sizeof(int16_t)*m_map.size()*_nBufferFrames);
AIRTIO_VERBOSE(" IO : " /* << std::distance(m_list.begin(), it)*/ << "/" << m_list.size() << " name="<< it->getName()); AIRTIO_VERBOSE(" IO : " /* << std::distance(m_list.begin(), it)*/ << "/" << m_list.size() << " name="<< it->getName());
tmpSize = _nBufferFrames; it->systemNeedOutputData(ttime, &outputTmp2[0], _nBufferFrames, sizeof(int16_t)*m_map.size());
it->systemNeedOutputData(ttime, outputTmp2, tmpSize, sizeof(int16_t)*m_map.size()); outputTmp = reinterpret_cast<const int16_t*>(&outputTmp2[0]);
outputTmp = static_cast<int16_t*>(outputTmp2);
//it->systemNeedOutputData(ttime, _outputBuffer, _nBufferFrames, sizeof(int16_t)*m_map.size()); //it->systemNeedOutputData(ttime, _outputBuffer, _nBufferFrames, sizeof(int16_t)*m_map.size());
// Add data to the output tmp buffer : // Add data to the output tmp buffer :
for (size_t kkk=0; kkk<output.size(); ++kkk) { for (size_t kkk=0; kkk<output.size(); ++kkk) {
output[kkk] += static_cast<int32_t>(outputTmp[kkk]); output[kkk] += static_cast<int32_t>(outputTmp[kkk]);
//*_outputBuffer++ = static_cast<int16_t>(outputTmp[kkk]);
} }
break; break;
} }
@ -58,7 +58,6 @@ int32_t airtio::io::Node::rtAudioCallback(void* _outputBuffer,
int16_t* outputBuffer = static_cast<int16_t*>(_outputBuffer); int16_t* outputBuffer = static_cast<int16_t*>(_outputBuffer);
for (size_t kkk=0; kkk<output.size(); ++kkk) { for (size_t kkk=0; kkk<output.size(); ++kkk) {
*outputBuffer++ = static_cast<int16_t>(std::min(std::max(INT16_MIN, output[kkk]), INT16_MAX)); *outputBuffer++ = static_cast<int16_t>(std::min(std::max(INT16_MIN, output[kkk]), INT16_MAX));
//*_outputBuffer++ = static_cast<int16_t>(output[kkk]);
} }
} }
if (_inputBuffer != nullptr) { if (_inputBuffer != nullptr) {