[DEV] some River rework
This commit is contained in:
@@ -57,19 +57,27 @@ static std::string basicAutoConfig =
|
||||
|
||||
|
||||
river::io::Manager::Manager() {
|
||||
if (m_config.load("DATA:hardware.json") == false) {
|
||||
RIVER_WARNING("you must set a basic configuration file for harware configuration: DATA:hardware.json (load default interface)");
|
||||
m_config.parse(basicAutoConfig);
|
||||
}
|
||||
// TODO : Load virtual.json and check if all is correct ...
|
||||
|
||||
#ifdef __PORTAUDIO_INFERFACE__
|
||||
PaError err = Pa_Initialize();
|
||||
if(err != paNoError) {
|
||||
RIVER_WARNING("Can not initialize portaudio : " << Pa_GetErrorText(err));
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
void river::io::Manager::init(const std::string _filename) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if (_filename == "") {
|
||||
RIVER_INFO("Load default config");
|
||||
m_config.parse(basicAutoConfig);
|
||||
} else if (m_config.load(_filename) == false) {
|
||||
RIVER_ERROR("you must set a basic configuration file for harware configuration: '" << _filename << "'");
|
||||
}
|
||||
}
|
||||
void river::io::Manager::unInit() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
|
||||
}
|
||||
|
||||
river::io::Manager::~Manager() {
|
||||
#ifdef __PORTAUDIO_INFERFACE__
|
||||
@@ -80,12 +88,85 @@ river::io::Manager::~Manager() {
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
std11::shared_ptr<river::io::Manager> river::io::Manager::getInstance() {
|
||||
if (river::isInit() == false) {
|
||||
return std11::shared_ptr<river::io::Manager>();
|
||||
}
|
||||
static std11::shared_ptr<river::io::Manager> manager(new Manager());
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> river::io::Manager::getListStreamInput() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
std::vector<std::string> output;
|
||||
std::vector<std::string> keys = m_config.getKeys();
|
||||
for (size_t iii=0; iii<keys.size(); ++iii) {
|
||||
const std11::shared_ptr<const ejson::Object> tmppp = m_config.getObject(keys[iii]);
|
||||
if (tmppp != nullptr) {
|
||||
std::string type = tmppp->getStringValue("io", "error");
|
||||
if ( type == "input"
|
||||
|| type == "PAinput") {
|
||||
output.push_back(keys[iii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::vector<std::string> river::io::Manager::getListStreamOutput() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
std::vector<std::string> output;
|
||||
std::vector<std::string> keys = m_config.getKeys();
|
||||
for (size_t iii=0; iii<keys.size(); ++iii) {
|
||||
const std11::shared_ptr<const ejson::Object> tmppp = m_config.getObject(keys[iii]);
|
||||
if (tmppp != nullptr) {
|
||||
std::string type = tmppp->getStringValue("io", "error");
|
||||
if ( type == "output"
|
||||
|| type == "PAoutput") {
|
||||
output.push_back(keys[iii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::vector<std::string> river::io::Manager::getListStreamVirtual() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
std::vector<std::string> output;
|
||||
std::vector<std::string> keys = m_config.getKeys();
|
||||
for (size_t iii=0; iii<keys.size(); ++iii) {
|
||||
const std11::shared_ptr<const ejson::Object> tmppp = m_config.getObject(keys[iii]);
|
||||
if (tmppp != nullptr) {
|
||||
std::string type = tmppp->getStringValue("io", "error");
|
||||
if ( type != "input"
|
||||
&& type != "PAinput"
|
||||
&& type != "output"
|
||||
&& type != "PAoutput"
|
||||
&& type != "error") {
|
||||
output.push_back(keys[iii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::vector<std::string> river::io::Manager::getListStream() {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
std::vector<std::string> output;
|
||||
std::vector<std::string> keys = m_config.getKeys();
|
||||
for (size_t iii=0; iii<keys.size(); ++iii) {
|
||||
const std11::shared_ptr<const ejson::Object> tmppp = m_config.getObject(keys[iii]);
|
||||
if (tmppp != nullptr) {
|
||||
std::string type = tmppp->getStringValue("io", "error");
|
||||
if (type != "error") {
|
||||
output.push_back(keys[iii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std11::shared_ptr<river::io::Node> river::io::Manager::getNode(const std::string& _name) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
RIVER_WARNING("Get node : " << _name);
|
||||
|
@@ -38,7 +38,9 @@ namespace river {
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~Manager();
|
||||
~Manager();
|
||||
void init();
|
||||
void unInit();
|
||||
private:
|
||||
ejson::Document m_config; // harware configuration
|
||||
std::vector<std11::shared_ptr<river::io::Node> > m_listKeepAlive; //!< list of all Node that might be keep alive sone time
|
||||
@@ -49,6 +51,26 @@ namespace river {
|
||||
std::vector<std11::shared_ptr<drain::VolumeElement> > m_volumeGroup;
|
||||
public:
|
||||
std11::shared_ptr<drain::VolumeElement> getVolumeGroup(const std::string& _name);
|
||||
/**
|
||||
* @brief Get all input audio stream.
|
||||
* @return a list of all availlables input stream name
|
||||
*/
|
||||
std::vector<std::string> getListStreamInput();
|
||||
/**
|
||||
* @brief Get all output audio stream.
|
||||
* @return a list of all availlables output stream name
|
||||
*/
|
||||
std::vector<std::string> getListStreamOutput();
|
||||
/**
|
||||
* @brief Get all audio virtual stream.
|
||||
* @return a list of all availlables virtual stream name
|
||||
*/
|
||||
std::vector<std::string> getListStreamVirtual();
|
||||
/**
|
||||
* @brief Get all audio stream.
|
||||
* @return a list of all availlables stream name
|
||||
*/
|
||||
std::vector<std::string> getListStream();
|
||||
|
||||
/**
|
||||
* @brief Set a volume for a specific group
|
||||
@@ -58,26 +80,26 @@ namespace river {
|
||||
* @return false An error occured
|
||||
* @example : setVolume("MASTER", -3.0f);
|
||||
*/
|
||||
virtual bool setVolume(const std::string& _volumeName, float _valuedB);
|
||||
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);
|
||||
float getVolume(const std::string& _volumeName);
|
||||
/**
|
||||
* @brief Get a parameter value
|
||||
* @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::pair<float,float> getVolumeRange(const std::string& _volumeName) const;
|
||||
std::pair<float,float> getVolumeRange(const std::string& _volumeName) const;
|
||||
/**
|
||||
* @brief Generate the dot file corresponding at the actif nodes.
|
||||
* @param[in] _filename Name of the file to write data.
|
||||
*/
|
||||
virtual void generateDot(const std::string& _filename);
|
||||
void generateDot(const std::string& _filename);
|
||||
private:
|
||||
std::map<std::string, std11::shared_ptr<river::io::Group> > m_listGroup; //!< List of all groups
|
||||
std11::shared_ptr<river::io::Group> getGroup(const std::string& _name);
|
||||
|
@@ -13,90 +13,15 @@
|
||||
#undef __class__
|
||||
#define __class__ "io::NodeAEC"
|
||||
|
||||
#if 0
|
||||
int32_t river::io::NodeAEC::airtAudioCallback(void* _outputBuffer,
|
||||
void* _inputBuffer,
|
||||
uint32_t _nbChunk,
|
||||
const std11::chrono::system_clock::time_point& _time,
|
||||
airtaudio::status _status) {
|
||||
std11::unique_lock<std11::mutex> lock(m_mutex);
|
||||
//RIVER_INFO("Time=" << _time);
|
||||
/*
|
||||
for (int32_t iii=0; iii<400; ++iii) {
|
||||
RIVER_VERBOSE("dummy=" << uint64_t(dummy[iii]));
|
||||
}
|
||||
*/
|
||||
if (_outputBuffer != nullptr) {
|
||||
RIVER_VERBOSE("data Output size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size());
|
||||
std::vector<int32_t> output;
|
||||
RIVER_VERBOSE("resize=" << _nbChunk*m_process.getInputConfig().getMap().size());
|
||||
output.resize(_nbChunk*m_process.getInputConfig().getMap().size(), 0);
|
||||
const int32_t* outputTmp = nullptr;
|
||||
std::vector<uint8_t> outputTmp2;
|
||||
RIVER_VERBOSE("resize=" << sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nbChunk);
|
||||
outputTmp2.resize(sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nbChunk, 0);
|
||||
for (auto &it : m_list) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (it->getMode() != river::modeInterface_output) {
|
||||
continue;
|
||||
}
|
||||
RIVER_VERBOSE(" IO name="<< it->getName());
|
||||
// clear datas ...
|
||||
memset(&outputTmp2[0], 0, sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nbChunk);
|
||||
RIVER_VERBOSE(" request Data="<< _nbChunk);
|
||||
it->systemNeedOutputData(_time, &outputTmp2[0], _nbChunk, sizeof(int32_t)*m_process.getInputConfig().getMap().size());
|
||||
RIVER_VERBOSE(" Mix it ...");
|
||||
outputTmp = reinterpret_cast<const int32_t*>(&outputTmp2[0]);
|
||||
// Add data to the output tmp buffer :
|
||||
for (size_t kkk=0; kkk<output.size(); ++kkk) {
|
||||
output[kkk] += outputTmp[kkk];
|
||||
}
|
||||
}
|
||||
RIVER_VERBOSE(" End stack process data ...");
|
||||
m_process.processIn(&outputTmp2[0], _nbChunk, _outputBuffer, _nbChunk);
|
||||
RIVER_VERBOSE(" Feedback :");
|
||||
for (auto &it : m_list) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (it->getMode() != river::modeInterface_feedback) {
|
||||
continue;
|
||||
}
|
||||
RIVER_VERBOSE(" IO name="<< it->getName() << " (feedback)");
|
||||
it->systemNewInputData(_time, _outputBuffer, _nbChunk);
|
||||
}
|
||||
RIVER_VERBOSE("data Output size request :" << _nbChunk << " [ END ]");
|
||||
}
|
||||
if (_inputBuffer != nullptr) {
|
||||
RIVER_VERBOSE("data Input size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size());
|
||||
int16_t* inputBuffer = static_cast<int16_t *>(_inputBuffer);
|
||||
for (auto &it : m_list) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (it->getMode() != river::modeInterface_input) {
|
||||
continue;
|
||||
}
|
||||
RIVER_INFO(" IO name="<< it->getName());
|
||||
it->systemNewInputData(_time, inputBuffer, _nbChunk);
|
||||
}
|
||||
RIVER_VERBOSE("data Input size request :" << _nbChunk << " [ END ]");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
std11::shared_ptr<river::io::NodeAEC> river::io::NodeAEC::create(const std::string& _name, const std11::shared_ptr<const ejson::Object>& _config) {
|
||||
return std11::shared_ptr<river::io::NodeAEC>(new river::io::NodeAEC(_name, _config));
|
||||
}
|
||||
|
||||
std11::shared_ptr<river::Interface> river::io::NodeAEC::createInput(float _freq,
|
||||
const std::vector<audio::channel>& _map,
|
||||
audio::format _format,
|
||||
const std::string& _objectName,
|
||||
const std::string& _name) {
|
||||
const std::vector<audio::channel>& _map,
|
||||
audio::format _format,
|
||||
const std::string& _objectName,
|
||||
const std::string& _name) {
|
||||
// check if the output exist
|
||||
const std11::shared_ptr<const ejson::Object> tmppp = m_config->getObject(_objectName);
|
||||
if (tmppp == nullptr) {
|
||||
@@ -119,7 +44,10 @@ std11::shared_ptr<river::Interface> river::io::NodeAEC::createInput(float _freq,
|
||||
std11::shared_ptr<river::io::Node> node = manager->getNode(streamName);
|
||||
// create user iterface:
|
||||
std11::shared_ptr<river::Interface> interface;
|
||||
interface = river::Interface::create(_name, _freq, _map, _format, node, tmppp);
|
||||
interface = river::Interface::create(_freq, _map, _format, node, tmppp);
|
||||
if (interface != nullptr) {
|
||||
interface->setName(_name);
|
||||
}
|
||||
return interface;
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,10 @@ std11::shared_ptr<river::Interface> river::io::NodeMuxer::createInput(float _fre
|
||||
std11::shared_ptr<river::io::Node> node = manager->getNode(streamName);
|
||||
// create user iterface:
|
||||
std11::shared_ptr<river::Interface> interface;
|
||||
interface = river::Interface::create(_name, _freq, _map, _format, node, tmppp);
|
||||
interface = river::Interface::create(_freq, _map, _format, node, tmppp);
|
||||
if (interface != nullptr) {
|
||||
interface->setName(_name);
|
||||
}
|
||||
return interface;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user