2015-01-25 22:17:06 +01:00
|
|
|
/** @file
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
|
|
|
* @license APACHE v2.0 (see license file)
|
|
|
|
*/
|
|
|
|
|
2015-02-05 21:33:12 +01:00
|
|
|
#ifndef __RIVER_INTERFACE_H__
|
|
|
|
#define __RIVER_INTERFACE_H__
|
2015-01-25 22:17:06 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <stdint.h>
|
2015-02-25 22:05:00 +01:00
|
|
|
#include <etk/mutex.h>
|
|
|
|
#include <etk/chrono.h>
|
|
|
|
#include <etk/functional.h>
|
|
|
|
#include <etk/memory.h>
|
2015-02-04 22:39:05 +01:00
|
|
|
#include <audio/format.h>
|
|
|
|
#include <audio/channel.h>
|
2015-02-05 19:10:53 +01:00
|
|
|
#include <drain/Process.h>
|
|
|
|
#include <drain/EndPointCallback.h>
|
|
|
|
#include <drain/EndPointWrite.h>
|
2015-02-12 22:08:23 +01:00
|
|
|
#include <ejson/ejson.h>
|
2015-02-19 22:00:21 +01:00
|
|
|
#include <etk/os/FSNode.h>
|
2015-01-25 22:17:06 +01:00
|
|
|
|
2015-02-05 19:10:53 +01:00
|
|
|
namespace river {
|
2015-01-25 22:17:06 +01:00
|
|
|
namespace io {
|
|
|
|
class Node;
|
2015-02-16 21:04:18 +01:00
|
|
|
class NodeAirTAudio;
|
|
|
|
class NodeAEC;
|
2015-01-25 22:17:06 +01:00
|
|
|
}
|
2015-02-12 22:08:23 +01:00
|
|
|
enum modeInterface {
|
|
|
|
modeInterface_unknow,
|
|
|
|
modeInterface_input,
|
|
|
|
modeInterface_output,
|
|
|
|
modeInterface_feedback,
|
|
|
|
};
|
2015-02-24 22:20:11 +01:00
|
|
|
class Interface : public std11::enable_shared_from_this<Interface> {
|
2015-01-25 22:17:06 +01:00
|
|
|
friend class io::Node;
|
2015-02-16 21:04:18 +01:00
|
|
|
friend class io::NodeAirTAudio;
|
|
|
|
friend class io::NodeAEC;
|
2015-01-25 22:17:06 +01:00
|
|
|
friend class Manager;
|
2015-02-18 23:37:09 +01:00
|
|
|
protected:
|
|
|
|
uint32_t m_uid; //!< unique ID for interface
|
2015-01-25 22:17:06 +01:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @brief Constructor
|
|
|
|
*/
|
|
|
|
Interface();
|
|
|
|
bool init(const std::string& _name,
|
|
|
|
float _freq,
|
2015-02-04 22:39:05 +01:00
|
|
|
const std::vector<audio::channel>& _map,
|
|
|
|
audio::format _format,
|
2015-02-24 22:20:11 +01:00
|
|
|
const std11::shared_ptr<river::io::Node>& _node,
|
|
|
|
const std11::shared_ptr<const ejson::Object>& _config);
|
2015-01-25 22:17:06 +01:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Destructor
|
|
|
|
*/
|
2015-01-26 22:04:29 +01:00
|
|
|
virtual ~Interface();
|
2015-02-24 22:20:11 +01:00
|
|
|
static std11::shared_ptr<Interface> create(const std::string& _name,
|
2015-01-25 22:17:06 +01:00
|
|
|
float _freq,
|
2015-02-04 22:39:05 +01:00
|
|
|
const std::vector<audio::channel>& _map,
|
|
|
|
audio::format _format,
|
2015-02-24 22:20:11 +01:00
|
|
|
const std11::shared_ptr<river::io::Node>& _node,
|
|
|
|
const std11::shared_ptr<const ejson::Object>& _config);
|
2015-02-16 21:04:18 +01:00
|
|
|
|
|
|
|
protected:
|
2015-02-24 22:20:11 +01:00
|
|
|
mutable std11::recursive_mutex m_mutex;
|
|
|
|
std11::shared_ptr<const ejson::Object> m_config;
|
2015-02-16 21:04:18 +01:00
|
|
|
protected:
|
|
|
|
enum modeInterface m_mode;
|
|
|
|
public:
|
|
|
|
enum modeInterface getMode() {
|
|
|
|
return m_mode;
|
|
|
|
}
|
|
|
|
drain::Process m_process;
|
|
|
|
public:
|
|
|
|
const drain::IOFormatInterface& getInterfaceFormat() {
|
|
|
|
if ( m_mode == modeInterface_input
|
|
|
|
|| m_mode == modeInterface_feedback) {
|
|
|
|
return m_process.getOutputConfig();
|
|
|
|
} else {
|
|
|
|
return m_process.getInputConfig();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-02-24 22:20:11 +01:00
|
|
|
std11::shared_ptr<river::io::Node> m_node;
|
2015-02-16 21:04:18 +01:00
|
|
|
protected:
|
|
|
|
std::string m_name;
|
|
|
|
public:
|
|
|
|
virtual std::string getName() {
|
|
|
|
return m_name;
|
|
|
|
};
|
2015-01-25 22:17:06 +01:00
|
|
|
/**
|
2015-02-01 22:21:03 +01:00
|
|
|
* @brief set the read/write mode enable.
|
|
|
|
*/
|
|
|
|
virtual void setReadwrite();
|
|
|
|
/**
|
|
|
|
* @brief When we want to implement a Callback Mode:
|
2015-01-25 22:17:06 +01:00
|
|
|
*/
|
2015-02-17 21:08:15 +01:00
|
|
|
virtual void setWriteCallback(drain::playbackFunctionWrite _function);
|
|
|
|
virtual void setOutputCallback(drain::playbackFunction _function);
|
|
|
|
virtual void setInputCallback(drain::recordFunction _function);
|
2015-02-01 22:21:03 +01:00
|
|
|
/**
|
|
|
|
* @brief Add a volume group of the current channel.
|
|
|
|
* @note If you do not call this function with the group "FLOW" you chan not have a channel volume.
|
|
|
|
* @note the set volume stage can not be set after the start.
|
|
|
|
* @param[in] _name Name of the group classicle common group:
|
|
|
|
* - FLOW for channel volume.
|
|
|
|
* - MEDIA for multimedia volume control (audio player, player video, web streaming ...).
|
|
|
|
* - TTS for Test-to-speech volume control.
|
|
|
|
* - COMMUNICATION for user communication volume control.
|
|
|
|
* - NOTIFICATION for urgent notification volume control.
|
2015-02-03 21:29:23 +01:00
|
|
|
* - NOISE for small noise volume control.
|
2015-02-01 22:21:03 +01:00
|
|
|
*/
|
2015-02-03 21:29:23 +01:00
|
|
|
virtual void addVolumeGroup(const std::string& _name);
|
2015-01-25 22:17:06 +01:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Start the Audio interface flow.
|
|
|
|
* @param[in] _time Time to start the flow (0) to start as fast as possible...
|
|
|
|
* @note _time to play buffer when output interface (if possible)
|
|
|
|
* @note _time to read buffer when inut interface (if possible)
|
|
|
|
*/
|
2015-02-24 22:20:11 +01:00
|
|
|
virtual void start(const std11::chrono::system_clock::time_point& _time = std11::chrono::system_clock::time_point());
|
2015-01-25 22:17:06 +01:00
|
|
|
/**
|
|
|
|
* @brief Stop the current flow.
|
|
|
|
* @param[in] _fast The stream stop as fast as possible (not write all the buffer in speaker) but apply cross fade out.
|
|
|
|
* @param[in] _abort The stream stop whith no garenty of good audio stop.
|
|
|
|
*/
|
|
|
|
virtual void stop(bool _fast=false, bool _abort=false);
|
|
|
|
/**
|
|
|
|
* @brief Abort flow (no audio garenty)
|
|
|
|
*/
|
|
|
|
virtual void abort();
|
|
|
|
/**
|
2015-01-30 21:44:36 +01:00
|
|
|
* @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 bool setParameter(const std::string& _filter, const std::string& _parameter, const std::string& _value);
|
|
|
|
/**
|
|
|
|
* @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 std::string getParameter(const std::string& _filter, const std::string& _parameter) const;
|
|
|
|
/**
|
|
|
|
* @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::string getParameterProperty(const std::string& _filter, const std::string& _parameter) const;
|
2015-01-25 22:17:06 +01:00
|
|
|
/**
|
|
|
|
* @brief write some audio sample in the speakers
|
|
|
|
* @param[in] _value Data To write on output
|
|
|
|
* @param[in] _nbChunk Number of audio chunk to write
|
|
|
|
*/
|
|
|
|
// TODO : TimeOut ???
|
2015-01-27 21:01:52 +01:00
|
|
|
virtual void write(const void* _value, size_t _nbChunk);
|
2015-01-25 22:17:06 +01:00
|
|
|
/**
|
|
|
|
* @brief read some audio sample from Microphone
|
|
|
|
* @param[in] _value Data To write on output
|
|
|
|
* @param[in] _nbChunk Number of audio chunk to write
|
|
|
|
*/
|
|
|
|
// TODO : TimeOut ???
|
2015-01-27 21:01:52 +01:00
|
|
|
virtual void read(void* _value, size_t _nbChunk);
|
2015-01-25 22:17:06 +01:00
|
|
|
/**
|
|
|
|
* @brief Get number of chunk in the local buffer
|
|
|
|
* @return Number of chunk
|
|
|
|
*/
|
|
|
|
virtual size_t size() const;
|
|
|
|
/**
|
|
|
|
* @brief Set buffer size in chunk number
|
|
|
|
* @param[in] _nbChunk Number of chunk in the buffer
|
|
|
|
*/
|
|
|
|
virtual void setBufferSize(size_t _nbChunk);
|
|
|
|
/**
|
|
|
|
* @brief Set buffer size in chunk number
|
|
|
|
* @param[in] _nbChunk Number of chunk in the buffer
|
|
|
|
*/
|
2015-02-24 22:20:11 +01:00
|
|
|
virtual void setBufferSize(const std11::chrono::microseconds& _time);
|
2015-01-25 22:17:06 +01:00
|
|
|
/**
|
|
|
|
* @brief Remove internal Buffer
|
|
|
|
*/
|
|
|
|
virtual void clearInternalBuffer();
|
|
|
|
/**
|
|
|
|
* @brief Write : Get the time of the next sample time to write in the local buffer
|
|
|
|
* @brief Read : Get the time of the next sample time to read in the local buffer
|
|
|
|
*/
|
2015-02-24 22:20:11 +01:00
|
|
|
virtual std11::chrono::system_clock::time_point getCurrentTime() const;
|
2015-01-25 22:17:06 +01:00
|
|
|
private:
|
2015-02-24 22:20:11 +01:00
|
|
|
virtual void systemNewInputData(std11::chrono::system_clock::time_point _time, const void* _data, size_t _nbChunk);
|
|
|
|
virtual void systemNeedOutputData(std11::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize);
|
2015-02-04 21:08:06 +01:00
|
|
|
virtual void systemVolumeChange();
|
2015-01-25 22:17:06 +01:00
|
|
|
float m_volume; //!< Local channel Volume
|
2015-02-19 22:00:21 +01:00
|
|
|
public:
|
2015-03-04 22:15:35 +01:00
|
|
|
virtual void generateDot(etk::FSNode& _node, const std::string& _nameIO, bool _isLink=true);
|
2015-01-25 22:17:06 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|