[DEV] update new time mode
This commit is contained in:
parent
d3e2aa1d43
commit
3f1ac849a8
@ -30,13 +30,15 @@ bool river::Interface::init(const std::string& _name,
|
||||
float _freq,
|
||||
const std::vector<audio::channel>& _map,
|
||||
audio::format _format,
|
||||
const std::shared_ptr<river::io::Node>& _node) {
|
||||
const std::shared_ptr<river::io::Node>& _node,
|
||||
bool _isInput) {
|
||||
m_name = _name;
|
||||
m_node = _node;
|
||||
m_freq = _freq;
|
||||
m_map = _map;
|
||||
m_format = _format;
|
||||
m_volume = 0.0f;
|
||||
m_isInput = _isInput;
|
||||
// register interface to be notify from the volume change.
|
||||
m_node->registerAsRemote(shared_from_this());
|
||||
// Create convertion interface
|
||||
@ -76,9 +78,10 @@ std::shared_ptr<river::Interface> river::Interface::create(const std::string& _n
|
||||
float _freq,
|
||||
const std::vector<audio::channel>& _map,
|
||||
audio::format _format,
|
||||
const std::shared_ptr<river::io::Node>& _node) {
|
||||
const std::shared_ptr<river::io::Node>& _node,
|
||||
bool _isInput) {
|
||||
std::shared_ptr<river::Interface> out = std::shared_ptr<river::Interface>(new river::Interface());
|
||||
out->init(_name, _freq, _map, _format, _node);
|
||||
out->init(_name, _freq, _map, _format, _node, _isInput);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,15 @@ namespace river {
|
||||
virtual std::string getName() {
|
||||
return m_name;
|
||||
};
|
||||
protected:
|
||||
bool m_isInput;
|
||||
public:
|
||||
bool isInput() {
|
||||
return m_isInput;
|
||||
}
|
||||
bool isOutput() {
|
||||
return !m_isInput;
|
||||
}
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
@ -50,7 +59,8 @@ namespace river {
|
||||
float _freq,
|
||||
const std::vector<audio::channel>& _map,
|
||||
audio::format _format,
|
||||
const std::shared_ptr<river::io::Node>& _node);
|
||||
const std::shared_ptr<river::io::Node>& _node,
|
||||
bool _isInput);
|
||||
public:
|
||||
/**
|
||||
* @brief Destructor
|
||||
@ -60,7 +70,8 @@ namespace river {
|
||||
float _freq,
|
||||
const std::vector<audio::channel>& _map,
|
||||
audio::format _format,
|
||||
const std::shared_ptr<river::io::Node>& _node);
|
||||
const std::shared_ptr<river::io::Node>& _node,
|
||||
bool _isInput);
|
||||
/**
|
||||
* @brief set the read/write mode enable.
|
||||
*/
|
||||
|
@ -57,34 +57,34 @@ std::pair<float,float> river::Manager::getVolumeRange(const std::string& _volume
|
||||
}
|
||||
|
||||
std::shared_ptr<river::Interface> river::Manager::createOutput(float _freq,
|
||||
const std::vector<audio::channel>& _map,
|
||||
audio::format _format,
|
||||
const std::string& _streamName,
|
||||
const std::string& _name) {
|
||||
const std::vector<audio::channel>& _map,
|
||||
audio::format _format,
|
||||
const std::string& _streamName,
|
||||
const std::string& _name) {
|
||||
// get global hardware interface:
|
||||
std::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
||||
// get the output or input channel :
|
||||
std::shared_ptr<river::io::Node> node = manager->getNode(_streamName);//, false);
|
||||
std::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
|
||||
// create user iterface:
|
||||
std::shared_ptr<river::Interface> interface;
|
||||
interface = river::Interface::create(_name, _freq, _map, _format, node);
|
||||
interface = river::Interface::create(_name, _freq, _map, _format, node, false);
|
||||
// store it in a list (needed to apply some parameters).
|
||||
m_listOpenInterface.push_back(interface);
|
||||
return interface;
|
||||
}
|
||||
|
||||
std::shared_ptr<river::Interface> river::Manager::createInput(float _freq,
|
||||
const std::vector<audio::channel>& _map,
|
||||
audio::format _format,
|
||||
const std::string& _streamName,
|
||||
const std::string& _name) {
|
||||
const std::vector<audio::channel>& _map,
|
||||
audio::format _format,
|
||||
const std::string& _streamName,
|
||||
const std::string& _name) {
|
||||
// get global hardware interface:
|
||||
std::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
||||
// get the output or input channel :
|
||||
std::shared_ptr<river::io::Node> node = manager->getNode(_streamName);//, true);
|
||||
std::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
|
||||
// create user iterface:
|
||||
std::shared_ptr<river::Interface> interface;
|
||||
interface = river::Interface::create(_name, _freq, _map, _format, node);
|
||||
interface = river::Interface::create(_name, _freq, _map, _format, node, true);
|
||||
// store it in a list (needed to apply some parameters).
|
||||
m_listOpenInterface.push_back(interface);
|
||||
return interface;
|
||||
|
@ -25,60 +25,91 @@
|
||||
#define INT32_MIN (-INT32_MAX - 1L)
|
||||
#endif
|
||||
|
||||
int32_t river::io::Node::rtAudioCallback(void* _outputBuffer,
|
||||
void* _inputBuffer,
|
||||
unsigned int _nBufferFrames,
|
||||
double _streamTime,
|
||||
airtaudio::status _status) {
|
||||
std::string asString(const std::chrono::system_clock::time_point& tp) {
|
||||
// convert to system time:
|
||||
std::time_t t = std::chrono::system_clock::to_time_t(tp);
|
||||
// convert in human string
|
||||
std::string ts = std::ctime(&t);
|
||||
// remove \n
|
||||
ts.resize(ts.size()-1);
|
||||
return ts;
|
||||
}
|
||||
|
||||
namespace std {
|
||||
std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj) {
|
||||
std::chrono::microseconds us = std::chrono::duration_cast<std::chrono::microseconds>(_obj.time_since_epoch());
|
||||
_os << us.count();
|
||||
return _os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t river::io::Node::airtAudioCallback(void* _outputBuffer,
|
||||
void* _inputBuffer,
|
||||
uint32_t _nbChunk,
|
||||
const std::chrono::system_clock::time_point& _time,
|
||||
airtaudio::status _status) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::chrono::system_clock::time_point ttime = std::chrono::system_clock::time_point();//std::chrono::system_clock::now();
|
||||
//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 :" << _nBufferFrames << " [BEGIN] status=" << _status);
|
||||
RIVER_VERBOSE("data Output size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size());
|
||||
std::vector<int32_t> output;
|
||||
RIVER_VERBOSE("resize=" << _nBufferFrames*m_process.getInputConfig().getMap().size());
|
||||
output.resize(_nBufferFrames*m_process.getInputConfig().getMap().size(), 0);
|
||||
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()*_nBufferFrames);
|
||||
outputTmp2.resize(sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nBufferFrames, 0);
|
||||
int32_t id = 1;
|
||||
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) {
|
||||
RIVER_VERBOSE(" IO : " << id << "/" << m_list.size() << " pointer : " << uint64_t(&(*it)));
|
||||
if (it != nullptr) {
|
||||
RIVER_VERBOSE(" name="<< it->getName());
|
||||
// clear datas ...
|
||||
memset(&outputTmp2[0], 0, sizeof(int32_t)*m_process.getInputConfig().getMap().size()*_nBufferFrames);
|
||||
RIVER_VERBOSE(" request Data="<< _nBufferFrames);
|
||||
it->systemNeedOutputData(ttime, &outputTmp2[0], _nBufferFrames, 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];
|
||||
}
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (it->isOutput() == false) {
|
||||
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];
|
||||
}
|
||||
++id;
|
||||
}
|
||||
RIVER_VERBOSE(" End stack process data ...");
|
||||
m_process.processIn(&outputTmp2[0], _nBufferFrames, _outputBuffer, _nBufferFrames);
|
||||
// TODO : Call feedback ...
|
||||
RIVER_VERBOSE("data Output size request :" << _nBufferFrames << " [ END ]");
|
||||
m_process.processIn(&outputTmp2[0], _nbChunk, _outputBuffer, _nbChunk);
|
||||
RIVER_VERBOSE(" Feedback :");
|
||||
for (auto &it : m_list) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (it->isInput() == false) {
|
||||
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 :" << _nBufferFrames << " [BEGIN]");
|
||||
RIVER_VERBOSE("data Input size request :" << _nbChunk << " [BEGIN] status=" << _status << " nbIO=" << m_list.size());
|
||||
int16_t* inputBuffer = static_cast<int16_t *>(_inputBuffer);
|
||||
for (size_t iii=0; iii< m_list.size(); ++iii) {
|
||||
if (m_list[iii] != nullptr) {
|
||||
RIVER_INFO(" IO : " << iii+1 << "/" << m_list.size() << " name="<< m_list[iii]->getName());
|
||||
m_list[iii]->systemNewInputData(ttime, inputBuffer, _nBufferFrames);
|
||||
for (auto &it : m_list) {
|
||||
if (it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
RIVER_INFO(" IO name="<< it->getName());
|
||||
it->systemNewInputData(_time, inputBuffer, _nbChunk);
|
||||
}
|
||||
RIVER_VERBOSE("data Input size request :" << _nBufferFrames << " [ END ]");
|
||||
RIVER_VERBOSE("data Input size request :" << _nbChunk << " [ END ]");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -215,7 +246,7 @@ river::io::Node::Node(const std::string& _name, const std::shared_ptr<const ejso
|
||||
if (m_isInput == true) {
|
||||
err = m_adac.openStream(nullptr, ¶ms,
|
||||
hardwareFormat.getFormat(), hardwareFormat.getFrequency(), &m_rtaudioFrameSize,
|
||||
std::bind(&river::io::Node::rtAudioCallback,
|
||||
std::bind(&river::io::Node::airtAudioCallback,
|
||||
this,
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2,
|
||||
@ -226,7 +257,7 @@ river::io::Node::Node(const std::string& _name, const std::shared_ptr<const ejso
|
||||
} else {
|
||||
err = m_adac.openStream(¶ms, nullptr,
|
||||
hardwareFormat.getFormat(), hardwareFormat.getFrequency(), &m_rtaudioFrameSize,
|
||||
std::bind(&river::io::Node::rtAudioCallback,
|
||||
std::bind(&river::io::Node::airtAudioCallback,
|
||||
this,
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2,
|
||||
|
@ -53,11 +53,11 @@ namespace river {
|
||||
airtaudio::DeviceInfo m_info;
|
||||
unsigned int m_rtaudioFrameSize;
|
||||
public:
|
||||
int32_t rtAudioCallback(void* _outputBuffer,
|
||||
void * _inputBuffer,
|
||||
unsigned int _nBufferFrames,
|
||||
double _streamTime,
|
||||
airtaudio::status _status);
|
||||
int32_t airtAudioCallback(void* _outputBuffer,
|
||||
void * _inputBuffer,
|
||||
uint32_t _nbChunk,
|
||||
const std::chrono::system_clock::time_point& _time,
|
||||
airtaudio::status _status);
|
||||
private:
|
||||
std::string m_name; //!< Harware.json configuration name
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user