diff --git a/airtio/Interface.cpp b/airtio/Interface.cpp index 93892aa..cdce5fd 100644 --- a/airtio/Interface.cpp +++ b/airtio/Interface.cpp @@ -176,24 +176,30 @@ void airtio::Interface::abort() { AIRTIO_DEBUG("abort [ END ]"); } -void airtio::Interface::setVolume(float _gainDB) { - std::unique_lock lock(m_mutex); - AIRTIO_DEBUG("setVolume [BEGIN]"); - // TODO :... - AIRTIO_DEBUG("setVolume [ END ]"); +bool airtio::Interface::setParameter(const std::string& _filter, const std::string& _parameter, const std::string& _value) { + AIRTIO_DEBUG("setParameter [BEGIN] : '" << _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; } - -float airtio::Interface::getVolume() const { - std::unique_lock lock(m_mutex); - AIRTIO_DEBUG("getVolume [BEGIN]"); - // TODO :... - AIRTIO_DEBUG("getVolume [ END ]"); - return 0; +std::string airtio::Interface::getParameter(const std::string& _filter, const std::string& _parameter) const { + AIRTIO_DEBUG("getParameter [BEGIN] : '" << _filter << "':'" << _parameter << "'"); + std::string out; + AIRTIO_TODO(" IMPLEMENT"); + AIRTIO_DEBUG("getParameter [ END ] : '" << out << "'"); + return out; } - -std::pair airtio::Interface::getVolumeRange() const { - std::unique_lock lock(m_mutex); - return std::make_pair(-120.0f, 0.0f); +std::string airtio::Interface::getParameterProperty(const std::string& _filter, const std::string& _parameter) const { + AIRTIO_DEBUG("getParameterProperty [BEGIN] : '" << _filter << "':'" << _parameter << "'"); + std::string out; + AIRTIO_TODO(" IMPLEMENT"); + AIRTIO_DEBUG("getParameterProperty [ END ] : '" << out << "'"); + return out; } 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); } -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 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); \ No newline at end of file diff --git a/airtio/Interface.h b/airtio/Interface.h index 125e0d1..28737a4 100644 --- a/airtio/Interface.h +++ b/airtio/Interface.h @@ -87,20 +87,34 @@ namespace airtio { */ virtual void abort(); /** - * @brief Set the volume of this interface - * @param[in] _gainDB Gain in decibel to apply + * @brief Set a parameter in the stream flow + * @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 - * @return The gain in decibel applyied + * @brief Get a parameter value + * @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 - * @return The gain in decibel range of this interface + * @brief Get a parameter value + * @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 getVolumeRange() const; + virtual std::string getParameterProperty(const std::string& _filter, const std::string& _parameter) const; /** * @brief write some audio sample in the speakers * @param[in] _value Data To write on output @@ -141,9 +155,8 @@ namespace airtio { virtual std::chrono::system_clock::time_point getCurrentTime() const; 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); - - std::vector m_data; + 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); float m_volume; //!< Local channel Volume }; }; diff --git a/airtio/Manager.cpp b/airtio/Manager.cpp index 16e8dcd..3ae195d 100644 --- a/airtio/Manager.cpp +++ b/airtio/Manager.cpp @@ -44,6 +44,34 @@ std::vector > airtio::Manager::getListStreamO 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 ... void airtio::Manager::setMasterOutputVolume(float _gainDB) { if (_gainDB < m_masterVolumeRange.first) { diff --git a/airtio/Manager.h b/airtio/Manager.h index 4fa0cda..fedb56b 100644 --- a/airtio/Manager.h +++ b/airtio/Manager.h @@ -44,44 +44,39 @@ namespace airtio { * @return a list of all availlables output stream (name + description) */ virtual std::vector > getListStreamOutput(); - protected: - float m_masterVolume; - std::pair 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 getMasterOutputVolumeRange(); /** - * @brief Set the section volume of the Audio interface - * @param[in] _gainDB Gain in decibel to apply in volume section - * @param[in] _section section name to apply volume (a section is : tts, reco, player, interjection ...) + * @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("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 - * @param[in] _section section name to apply volume (a section is : tts, reco, player, interjection ...) - * @return The gain in decibel applyied in volume section + * @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("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 - * @param[in] _section section name to apply volume (a section is : tts, reco, player, interjection ...) - * @return The gain in decibel range of the section volume + * @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("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 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 diff --git a/airtio/io/Node.cpp b/airtio/io/Node.cpp index 3bbe74f..de635c8 100644 --- a/airtio/io/Node.cpp +++ b/airtio/io/Node.cpp @@ -37,20 +37,20 @@ int32_t airtio::io::Node::rtAudioCallback(void* _outputBuffer, AIRTIO_VERBOSE("data Output"); std::vector output; output.resize(_nBufferFrames*m_map.size(), 0); - int16_t* outputTmp = nullptr; - void* outputTmp2 = nullptr; - size_t tmpSize = 0; + const int16_t* outputTmp = nullptr; + std::vector outputTmp2; + outputTmp2.resize(sizeof(int16_t)*m_map.size()*_nBufferFrames, 0); for (auto &it : m_list) { 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()); - tmpSize = _nBufferFrames; - it->systemNeedOutputData(ttime, outputTmp2, tmpSize, sizeof(int16_t)*m_map.size()); - outputTmp = static_cast(outputTmp2); + it->systemNeedOutputData(ttime, &outputTmp2[0], _nBufferFrames, sizeof(int16_t)*m_map.size()); + outputTmp = reinterpret_cast(&outputTmp2[0]); //it->systemNeedOutputData(ttime, _outputBuffer, _nBufferFrames, sizeof(int16_t)*m_map.size()); // Add data to the output tmp buffer : for (size_t kkk=0; kkk(outputTmp[kkk]); - //*_outputBuffer++ = static_cast(outputTmp[kkk]); } break; } @@ -58,7 +58,6 @@ int32_t airtio::io::Node::rtAudioCallback(void* _outputBuffer, int16_t* outputBuffer = static_cast(_outputBuffer); for (size_t kkk=0; kkk(std::min(std::max(INT16_MIN, output[kkk]), INT16_MAX)); - //*_outputBuffer++ = static_cast(output[kkk]); } } if (_inputBuffer != nullptr) {