[DEV] dot error and update test delay
This commit is contained in:
parent
5d7c9203ef
commit
8a59126beb
@ -1,4 +1,22 @@
|
||||
{
|
||||
speaker:{
|
||||
io:"output",
|
||||
map-on:{
|
||||
interface:"alsa",
|
||||
#name:"default",
|
||||
name:"hw:0,0",
|
||||
timestamp-mode:"trigered",
|
||||
},
|
||||
group:"baseIOSynchrone",
|
||||
frequency:48000,
|
||||
channel-map:[
|
||||
"front-left", "front-right",
|
||||
],
|
||||
type:"int16",
|
||||
nb-chunk:1024,
|
||||
volume-name:"MASTER",
|
||||
mux-demux-type:"int16-on-int32",
|
||||
},
|
||||
# name of the device
|
||||
microphone:{
|
||||
# input or output
|
||||
@ -26,24 +44,6 @@
|
||||
nb-chunk:1024,
|
||||
mux-demux-type:"int16",
|
||||
},
|
||||
speaker:{
|
||||
io:"output",
|
||||
map-on:{
|
||||
interface:"alsa",
|
||||
#name:"default",
|
||||
name:"hw:0,0",
|
||||
timestamp-mode:"trigered",
|
||||
},
|
||||
group:"baseIOSynchrone",
|
||||
frequency:48000,
|
||||
channel-map:[
|
||||
"front-left", "front-right",
|
||||
],
|
||||
type:"int16",
|
||||
nb-chunk:1024,
|
||||
volume-name:"MASTER",
|
||||
mux-demux-type:"int16-on-int32",
|
||||
},
|
||||
speaker-pulse:{
|
||||
io:"output",
|
||||
map-on:{
|
||||
|
@ -80,11 +80,13 @@ bool river::Interface::init(const std::string& _name,
|
||||
} else if ( m_node->isOutput() == true
|
||||
&& m_mode == river::modeInterface_feedback) {
|
||||
m_process.setInputConfig(m_node->getHarwareFormat());
|
||||
/*
|
||||
// add all time the volume stage :
|
||||
std11::shared_ptr<drain::Volume> algo = drain::Volume::create();
|
||||
//algo->setInputFormat(m_node->getInterfaceFormat());
|
||||
algo->setName("volume");
|
||||
m_process.pushBack(algo);
|
||||
*/
|
||||
// note : feedback has no volume stage ...
|
||||
m_process.setOutputConfig(drain::IOFormatInterface(_map, _format, _freq));
|
||||
} else {
|
||||
@ -135,6 +137,10 @@ void river::Interface::setReadwrite() {
|
||||
|
||||
void river::Interface::setOutputCallback(drain::playbackFunction _function) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if (m_mode != river::modeInterface_output) {
|
||||
RIVER_ERROR("Can not set output endpoint on other than a output IO");
|
||||
return;
|
||||
}
|
||||
m_process.removeAlgoDynamic();
|
||||
m_process.removeIfFirst<drain::EndPoint>();
|
||||
std11::shared_ptr<drain::Algo> algo = drain::EndPointCallback::create(_function);
|
||||
@ -143,6 +149,10 @@ void river::Interface::setOutputCallback(drain::playbackFunction _function) {
|
||||
|
||||
void river::Interface::setInputCallback(drain::recordFunction _function) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if (m_mode == river::modeInterface_output) {
|
||||
RIVER_ERROR("Can not set output endpoint on other than a input or feedback IO");
|
||||
return;
|
||||
}
|
||||
m_process.removeAlgoDynamic();
|
||||
m_process.removeIfLast<drain::EndPoint>();
|
||||
std11::shared_ptr<drain::Algo> algo = drain::EndPointCallback::create(_function);
|
||||
@ -151,6 +161,10 @@ void river::Interface::setInputCallback(drain::recordFunction _function) {
|
||||
|
||||
void river::Interface::setWriteCallback(drain::playbackFunctionWrite _function) {
|
||||
std11::unique_lock<std11::recursive_mutex> lock(m_mutex);
|
||||
if (m_mode != river::modeInterface_output) {
|
||||
RIVER_ERROR("Can not set output endpoint on other than a output IO");
|
||||
return;
|
||||
}
|
||||
m_process.removeAlgoDynamic();
|
||||
std11::shared_ptr<drain::EndPointWrite> algo = m_process.get<drain::EndPointWrite>(0);
|
||||
if (algo == nullptr) {
|
||||
@ -325,6 +339,7 @@ void river::Interface::systemNewInputData(std11::chrono::system_clock::time_poin
|
||||
|
||||
void river::Interface::systemNeedOutputData(std11::chrono::system_clock::time_point _time, void* _data, size_t _nbChunk, size_t _chunkSize) {
|
||||
std11::unique_lock<std11::recursive_mutex> lockProcess(m_mutex);
|
||||
//RIVER_INFO("time : " << _time);
|
||||
m_process.pull(_time, _data, _nbChunk, _chunkSize);
|
||||
}
|
||||
|
||||
@ -337,16 +352,24 @@ void river::Interface::systemVolumeChange() {
|
||||
algo->volumeChange();
|
||||
}
|
||||
|
||||
static void link(etk::FSNode& _node, const std::string& _first, const std::string& _op, const std::string& _second) {
|
||||
static void link(etk::FSNode& _node, const std::string& _first, const std::string& _op, const std::string& _second, bool _isLink=true) {
|
||||
if (_op == "->") {
|
||||
_node << " " << _first << " -> " << _second << ";\n";
|
||||
if (_isLink) {
|
||||
_node << " " << _first << " -> " << _second << ";\n";
|
||||
} else {
|
||||
_node << " " << _first << " -> " << _second << " [style=dashed];\n";
|
||||
}
|
||||
} else if (_op == "<-") {
|
||||
_node << " " << _first << " -> " <<_second<< " [color=transparent];\n";
|
||||
_node << " " << _second << " -> " << _first << " [constraint=false];\n";
|
||||
if (_isLink) {
|
||||
_node << " " << _second << " -> " << _first << " [constraint=false];\n";
|
||||
} else {
|
||||
_node << " " << _second << " -> " << _first << " [constraint=false, style=dashed];\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void river::Interface::generateDot(etk::FSNode& _node, const std::string& _nameIO) {
|
||||
void river::Interface::generateDot(etk::FSNode& _node, const std::string& _nameIO, bool _isLink) {
|
||||
_node << "subgraph clusterInterface_" << m_uid << " {\n";
|
||||
_node << " color=orange;\n";
|
||||
_node << " label=\"[" << m_uid << "] Interface : " << m_name << "\";\n";
|
||||
@ -359,10 +382,10 @@ void river::Interface::generateDot(etk::FSNode& _node, const std::string& _nameI
|
||||
_node << " }\n";
|
||||
if ( m_mode == river::modeInterface_input
|
||||
|| m_mode == river::modeInterface_feedback) {
|
||||
link(_node, _nameIO, "->", "INTERFACE_ALGO_" + etk::to_string(m_uid) + "_in");
|
||||
link(_node, _nameIO, "->", "INTERFACE_ALGO_" + etk::to_string(m_uid) + "_in", _isLink);
|
||||
link(_node, "INTERFACE_ALGO_" + etk::to_string(m_uid) + "_in", "->", "INTERFACE_ALGO_" + etk::to_string(m_uid) + "_out");
|
||||
} else {
|
||||
link(_node, _nameIO, "<-", "INTERFACE_ALGO_" + etk::to_string(m_uid) + "_out");
|
||||
link(_node, _nameIO, "<-", "INTERFACE_ALGO_" + etk::to_string(m_uid) + "_out", _isLink);
|
||||
link(_node, "INTERFACE_ALGO_" + etk::to_string(m_uid) + "_out", "<-", "INTERFACE_ALGO_" + etk::to_string(m_uid) + "_in");
|
||||
}
|
||||
_node << " node [shape=Mdiamond];\n";
|
||||
|
@ -206,7 +206,7 @@ namespace river {
|
||||
virtual void systemVolumeChange();
|
||||
float m_volume; //!< Local channel Volume
|
||||
public:
|
||||
virtual void generateDot(etk::FSNode& _node, const std::string& _nameIO);
|
||||
virtual void generateDot(etk::FSNode& _node, const std::string& _nameIO, bool _isLink=true);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -112,11 +112,15 @@ std11::shared_ptr<river::Interface> river::Manager::createOutput(float _freq,
|
||||
RIVER_ERROR("can not open in output a virtual interface: '" << _streamName << "' configured has : " << type);
|
||||
return std11::shared_ptr<river::Interface>();
|
||||
}
|
||||
|
||||
std::string mapOn = tmppp->getStringValue("map-on", "");
|
||||
if (mapOn == "") {
|
||||
RIVER_ERROR("can not open in output a virtual interface: '" << _streamName << "' No 'map-on' element in json file ... ");
|
||||
return std11::shared_ptr<river::Interface>();
|
||||
}
|
||||
// get global hardware interface:
|
||||
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
||||
// get the output or input channel :
|
||||
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
|
||||
std11::shared_ptr<river::io::Node> node = manager->getNode(mapOn);
|
||||
// create user iterface:
|
||||
std11::shared_ptr<river::Interface> interface;
|
||||
interface = river::Interface::create(_name, _freq, _map, _format, node, tmppp);
|
||||
@ -143,10 +147,15 @@ std11::shared_ptr<river::Interface> river::Manager::createInput(float _freq,
|
||||
RIVER_ERROR("can not open in output a virtual interface: '" << _streamName << "' configured has : " << type);
|
||||
return std11::shared_ptr<river::Interface>();
|
||||
}
|
||||
std::string mapOn = tmppp->getStringValue("map-on", "");
|
||||
if (mapOn == "") {
|
||||
RIVER_ERROR("can not open in output a virtual interface: '" << _streamName << "' No 'map-on' element in json file ... ");
|
||||
return std11::shared_ptr<river::Interface>();
|
||||
}
|
||||
// get global hardware interface:
|
||||
std11::shared_ptr<river::io::Manager> manager = river::io::Manager::getInstance();
|
||||
// get the output or input channel :
|
||||
std11::shared_ptr<river::io::Node> node = manager->getNode(_streamName);
|
||||
std11::shared_ptr<river::io::Node> node = manager->getNode(mapOn);
|
||||
// create user iterface:
|
||||
std11::shared_ptr<river::Interface> interface;
|
||||
interface = river::Interface::create(_name, _freq, _map, _format, node, tmppp);
|
||||
|
@ -47,5 +47,26 @@ namespace river {
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define RIVER_SAVE_FILE_MACRO(type,fileName,dataPointer,nbElement) \
|
||||
do { \
|
||||
static FILE *pointerOnFile = nullptr; \
|
||||
static bool errorOpen = false; \
|
||||
if (NULL==pointerOnFile) { \
|
||||
RIVER_WARNING("open file '" << fileName << "' type=" << #type); \
|
||||
pointerOnFile = fopen(fileName,"w"); \
|
||||
if ( errorOpen == false \
|
||||
&& pointerOnFile == nullptr) { \
|
||||
RIVER_ERROR("ERROR OPEN file ... '" << fileName << "' type=" << #type); \
|
||||
errorOpen=true; \
|
||||
} \
|
||||
} \
|
||||
if (pointerOnFile != nullptr) { \
|
||||
fwrite((dataPointer), sizeof(type), (nbElement), pointerOnFile); \
|
||||
/* fflush(pointerOnFile);*/ \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -133,3 +133,11 @@ void river::io::Group::stop() {
|
||||
}
|
||||
}
|
||||
|
||||
void river::io::Group::generateDot(etk::FSNode& _node) {
|
||||
for (size_t iii=0; iii<m_list.size(); ++iii) {
|
||||
if (m_list[iii] != nullptr) {
|
||||
m_list[iii]->generateDot(_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <ejson/ejson.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
namespace river {
|
||||
namespace io {
|
||||
@ -26,6 +27,7 @@ namespace river {
|
||||
std11::shared_ptr<river::io::Node> getNode(const std::string& _name);
|
||||
void start();
|
||||
void stop();
|
||||
void generateDot(etk::FSNode& _node);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -228,12 +228,20 @@ void river::io::Manager::generateDot(const std::string& _filename) {
|
||||
}
|
||||
node << "digraph G {" << "\n";
|
||||
node << " rankdir=\"LR\";\n";
|
||||
// standalone
|
||||
for (size_t iii=0; iii<m_list.size(); ++iii) {
|
||||
std11::shared_ptr<river::io::Node> val = m_list[iii].lock();
|
||||
if (val != nullptr) {
|
||||
val->generateDot(node);
|
||||
}
|
||||
}
|
||||
for (std::map<std::string, std11::shared_ptr<river::io::Group> >::iterator it(m_listGroup.begin());
|
||||
it != m_listGroup.end();
|
||||
++it) {
|
||||
if (it->second != nullptr) {
|
||||
it->second->generateDot(node);
|
||||
}
|
||||
}
|
||||
node << "}" << "\n";
|
||||
node.fileClose();
|
||||
RIVER_INFO("Generate the DOT files: " << node << " (DONE)");
|
||||
|
@ -113,6 +113,19 @@ size_t river::io::Node::getNumberOfInterface(enum river::modeInterface _interfac
|
||||
}
|
||||
return out;
|
||||
}
|
||||
size_t river::io::Node::getNumberOfInterfaceAvaillable(enum river::modeInterface _interfaceType) {
|
||||
size_t out = 0;
|
||||
for (size_t iii=0; iii<m_listAvaillable.size(); ++iii) {
|
||||
std11::shared_ptr<river::Interface> element = m_listAvaillable[iii].lock();
|
||||
if (element == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (element->getMode() == _interfaceType) {
|
||||
out++;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void river::io::Node::registerAsRemote(const std11::shared_ptr<river::Interface>& _interface) {
|
||||
std::vector<std11::weak_ptr<river::Interface> >::iterator it = m_listAvaillable.begin();
|
||||
@ -269,8 +282,8 @@ void river::io::Node::generateDot(etk::FSNode& _node) {
|
||||
_node << " node_ALGO_" << m_uid << "_in -> node_ALGO_" << m_uid << "_out [arrowhead=\"open\"];\n";
|
||||
_node << " node_ALGO_" << m_uid << "_out -> NODE_" << m_uid << "_demuxer [arrowhead=\"open\"];\n";
|
||||
} else {
|
||||
size_t nbOutput = getNumberOfInterface(river::modeInterface_output);
|
||||
size_t nbfeedback = getNumberOfInterface(river::modeInterface_feedback);
|
||||
size_t nbOutput = getNumberOfInterfaceAvaillable(river::modeInterface_output);
|
||||
size_t nbfeedback = getNumberOfInterfaceAvaillable(river::modeInterface_feedback);
|
||||
_node << " node [shape=larrow];\n";
|
||||
_node << " NODE_" << m_uid << "_HW_interface [ label=\"HW interface\n interface=ALSA\n stream=SPEAKER\n type=output\" ];\n";
|
||||
if (nbOutput>0) {
|
||||
@ -305,14 +318,27 @@ void river::io::Node::generateDot(etk::FSNode& _node) {
|
||||
}
|
||||
_node << "}\n";
|
||||
|
||||
for (size_t iii=0; iii< m_list.size(); ++iii) {
|
||||
if (m_list[iii] != nullptr) {
|
||||
if (m_list[iii]->getMode() == modeInterface_input) {
|
||||
m_list[iii]->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer");
|
||||
} else if (m_list[iii]->getMode() == modeInterface_output) {
|
||||
m_list[iii]->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_muxer");
|
||||
} else if (m_list[iii]->getMode() == modeInterface_feedback) {
|
||||
m_list[iii]->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer");
|
||||
for (size_t iii=0; iii< m_listAvaillable.size(); ++iii) {
|
||||
if (m_listAvaillable[iii].expired() == true) {
|
||||
continue;
|
||||
}
|
||||
std11::shared_ptr<river::Interface> element = m_listAvaillable[iii].lock();
|
||||
if (element == nullptr) {
|
||||
continue;
|
||||
}
|
||||
bool isLink = false;
|
||||
for (size_t jjj=0; jjj<m_list.size(); ++jjj) {
|
||||
if (element == m_list[jjj]) {
|
||||
isLink = true;
|
||||
}
|
||||
}
|
||||
if (element != nullptr) {
|
||||
if (element->getMode() == modeInterface_input) {
|
||||
element->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer", isLink);
|
||||
} else if (element->getMode() == modeInterface_output) {
|
||||
element->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_muxer", isLink);
|
||||
} else if (element->getMode() == modeInterface_feedback) {
|
||||
element->generateDot(_node, "NODE_" + etk::to_string(m_uid) + "_demuxer", isLink);
|
||||
} else {
|
||||
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ namespace river {
|
||||
std::vector<std11::weak_ptr<river::Interface> > m_listAvaillable; //!< List of all interface that exist on this Node
|
||||
std::vector<std11::shared_ptr<river::Interface> > m_list;
|
||||
size_t getNumberOfInterface(enum river::modeInterface _interfaceType);
|
||||
size_t getNumberOfInterfaceAvaillable(enum river::modeInterface _interfaceType);
|
||||
public:
|
||||
size_t getNumberOfInterface() {
|
||||
return m_list.size();
|
||||
|
@ -231,25 +231,6 @@ void river::io::NodeAEC::stop() {
|
||||
}
|
||||
}
|
||||
|
||||
#define SAVE_FILE_MACRO(type,fileName,dataPointer,nbElement) \
|
||||
do { \
|
||||
static FILE *pointerOnFile = nullptr; \
|
||||
static bool errorOpen = false; \
|
||||
if (NULL==pointerOnFile) { \
|
||||
RIVER_WARNING("open file '" << fileName << "' type=" << #type); \
|
||||
pointerOnFile = fopen(fileName,"w"); \
|
||||
if ( errorOpen == false \
|
||||
&& pointerOnFile == nullptr) { \
|
||||
RIVER_ERROR("ERROR OPEN file ... '" << fileName << "' type=" << #type); \
|
||||
errorOpen=true; \
|
||||
} \
|
||||
} \
|
||||
if (pointerOnFile != nullptr) { \
|
||||
fwrite((dataPointer), sizeof(type), (nbElement), pointerOnFile); \
|
||||
/* fflush(pointerOnFile);*/ \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
|
||||
void river::io::NodeAEC::onDataReceivedMicrophone(const void* _data,
|
||||
const std11::chrono::system_clock::time_point& _time,
|
||||
@ -265,7 +246,7 @@ void river::io::NodeAEC::onDataReceivedMicrophone(const void* _data,
|
||||
// push data synchronize
|
||||
std11::unique_lock<std11::mutex> lock(m_mutex);
|
||||
m_bufferMicrophone.write(_data, _nbChunk, _time);
|
||||
//SAVE_FILE_MACRO(int16_t, "REC_Microphone.raw", _data, _nbChunk*_map.size());
|
||||
//RIVER_SAVE_FILE_MACRO(int16_t, "REC_Microphone.raw", _data, _nbChunk*_map.size());
|
||||
process();
|
||||
}
|
||||
|
||||
@ -283,7 +264,7 @@ void river::io::NodeAEC::onDataReceivedFeedBack(const void* _data,
|
||||
// push data synchronize
|
||||
std11::unique_lock<std11::mutex> lock(m_mutex);
|
||||
m_bufferFeedBack.write(_data, _nbChunk, _time);
|
||||
//SAVE_FILE_MACRO(int16_t, "REC_FeedBack.raw", _data, _nbChunk*_map.size());
|
||||
//RIVER_SAVE_FILE_MACRO(int16_t, "REC_FeedBack.raw", _data, _nbChunk*_map.size());
|
||||
process();
|
||||
}
|
||||
|
||||
@ -344,8 +325,8 @@ void river::io::NodeAEC::process() {
|
||||
RIVER_INFO(" process 256 samples ... micTime=" << MicTime << " fbTime=" << fbTime << " delta = " << (MicTime-fbTime).count());
|
||||
m_bufferMicrophone.read(&dataMic[0], 256);
|
||||
m_bufferFeedBack.read(&dataFB[0], 256);
|
||||
SAVE_FILE_MACRO(int16_t, "REC_Microphone_sync.raw", &dataMic[0], 256*2);
|
||||
SAVE_FILE_MACRO(int16_t, "REC_FeedBack_sync.raw", &dataFB[0], 256);
|
||||
RIVER_SAVE_FILE_MACRO(int16_t, "REC_Microphone_sync.raw", &dataMic[0], 256*2);
|
||||
RIVER_SAVE_FILE_MACRO(int16_t, "REC_FeedBack_sync.raw", &dataFB[0], 256);
|
||||
// if threaded : send event / otherwise, process ...
|
||||
//processAEC(&dataMic[0], &dataFB[0], 256, _time);
|
||||
if (m_bufferMicrophone.getSize() <= 256) {
|
||||
|
@ -7,6 +7,8 @@
|
||||
#ifndef __RIVER_TEST_ECHO_DELAY_H__
|
||||
#define __RIVER_TEST_ECHO_DELAY_H__
|
||||
|
||||
#include <river/debug.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "test_echo_delay"
|
||||
|
||||
@ -16,14 +18,24 @@ namespace river_test_echo_delay {
|
||||
std11::shared_ptr<river::Manager> m_manager;
|
||||
std11::shared_ptr<river::Interface> m_interfaceOut;
|
||||
std11::shared_ptr<river::Interface> m_interfaceIn;
|
||||
std11::shared_ptr<river::Interface> m_interfaceFB;
|
||||
double m_phase;
|
||||
double m_freq;
|
||||
int32_t m_nextSampleCount;
|
||||
std11::chrono::milliseconds m_delayBetweenEvent;
|
||||
std11::chrono::system_clock::time_point m_nextTick;
|
||||
std11::chrono::system_clock::time_point m_currentTick;
|
||||
int32_t m_stateFB;
|
||||
int32_t m_stateMic;
|
||||
public:
|
||||
TestClass(std11::shared_ptr<river::Manager> _manager) :
|
||||
m_manager(_manager),
|
||||
m_phase(0),
|
||||
m_delayBetweenEvent(2000000000LL) {
|
||||
m_freq(400),
|
||||
m_nextSampleCount(0),
|
||||
m_delayBetweenEvent(400),
|
||||
m_stateFB(3),
|
||||
m_stateMic(3) {
|
||||
//Set stereo output:
|
||||
std::vector<audio::channel> channelMap;
|
||||
channelMap.push_back(audio::channel_frontLeft);
|
||||
@ -43,20 +55,38 @@ namespace river_test_echo_delay {
|
||||
std11::placeholders::_5,
|
||||
std11::placeholders::_6));
|
||||
m_interfaceOut->addVolumeGroup("FLOW");
|
||||
|
||||
m_interfaceIn = m_manager->createInput(48000,
|
||||
channelMap,
|
||||
audio::format_int16,
|
||||
"microphone",
|
||||
"delayTestIn");
|
||||
// set callback mode ...
|
||||
m_interfaceIn->setOutputCallback(std11::bind(&TestClass::onDataReceived,
|
||||
this,
|
||||
std11::placeholders::_1,
|
||||
std11::placeholders::_2,
|
||||
std11::placeholders::_3,
|
||||
std11::placeholders::_4,
|
||||
std11::placeholders::_5,
|
||||
std11::placeholders::_6));
|
||||
m_interfaceIn->setInputCallback(std11::bind(&TestClass::onDataReceived,
|
||||
this,
|
||||
std11::placeholders::_1,
|
||||
std11::placeholders::_2,
|
||||
std11::placeholders::_3,
|
||||
std11::placeholders::_4,
|
||||
std11::placeholders::_5,
|
||||
std11::placeholders::_6));
|
||||
|
||||
m_interfaceFB = m_manager->createInput(48000,
|
||||
channelMap,
|
||||
audio::format_int16,
|
||||
"feedback",
|
||||
"delayTestFB");
|
||||
// set callback mode ...
|
||||
m_interfaceFB->setInputCallback(std11::bind(&TestClass::onDataReceivedFeedBack,
|
||||
this,
|
||||
std11::placeholders::_1,
|
||||
std11::placeholders::_2,
|
||||
std11::placeholders::_3,
|
||||
std11::placeholders::_4,
|
||||
std11::placeholders::_5,
|
||||
std11::placeholders::_6));
|
||||
|
||||
m_manager->generateDotAll("activeProcess.dot");
|
||||
}
|
||||
void onDataNeeded(void* _data,
|
||||
const std11::chrono::system_clock::time_point& _time,
|
||||
@ -64,25 +94,117 @@ namespace river_test_echo_delay {
|
||||
enum audio::format _format,
|
||||
uint32_t _frequency,
|
||||
const std::vector<audio::channel>& _map) {
|
||||
// TODO : Do it better ...
|
||||
if (m_nextTick == std11::chrono::system_clock::time_point()) {
|
||||
m_nextTick = _time + m_delayBetweenEvent;
|
||||
}
|
||||
if (m_nextTick < _time) {
|
||||
m_nextTick += m_delayBetweenEvent;
|
||||
m_phase = 0;
|
||||
}
|
||||
if (m_phase >= 0) {
|
||||
int16_t* data = static_cast<int16_t*>(_data);
|
||||
double baseCycle = 2.0*M_PI/(double)48000 * (double)550;
|
||||
int16_t* data = static_cast<int16_t*>(_data);
|
||||
double baseCycle = 2.0*M_PI/(double)48000 * m_freq;
|
||||
if (_time == std11::chrono::system_clock::time_point()) {
|
||||
for (int32_t iii=0; iii<_nbChunk; iii++) {
|
||||
for (int32_t jjj=0; jjj<_map.size(); jjj++) {
|
||||
data[_map.size()*iii+jjj] = cos(m_phase) * 30000;
|
||||
data[_map.size()*iii+jjj] = 0;
|
||||
}
|
||||
m_phase += baseCycle;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (m_nextTick == std11::chrono::system_clock::time_point()) {
|
||||
m_nextTick = _time + m_delayBetweenEvent;
|
||||
m_nextSampleCount = m_delayBetweenEvent.count()*int64_t(_frequency)/1000;
|
||||
m_phase = -1;
|
||||
}
|
||||
//APPL_INFO("sample : " << m_nextSampleCount);
|
||||
for (int32_t iii=0; iii<_nbChunk; iii++) {
|
||||
if (m_nextSampleCount > 0) {
|
||||
m_nextSampleCount--;
|
||||
} else {
|
||||
m_phase = 0;
|
||||
m_nextSampleCount = m_delayBetweenEvent.count()*int64_t(_frequency)/1000;
|
||||
m_currentTick = m_nextTick;
|
||||
m_nextTick += m_delayBetweenEvent;
|
||||
}
|
||||
if (m_phase >= 0) {
|
||||
for (int32_t jjj=0; jjj<_map.size(); jjj++) {
|
||||
data[_map.size()*iii+jjj] = sin(m_phase) * 30000;
|
||||
}
|
||||
double newPhase = m_phase+baseCycle;
|
||||
if ( m_phase < M_PI
|
||||
&& newPhase >= M_PI) {
|
||||
// the zero crossing position :
|
||||
m_currentTick = getInterpolateTime(_time, iii, sin(m_phase) * 30000, sin(newPhase) * 30000, _frequency);
|
||||
// start detection ...
|
||||
m_stateFB = 0;
|
||||
m_stateMic = 0;
|
||||
APPL_WARNING("Time Pulse zero crossing: " << m_currentTick << " id=" << iii);
|
||||
}
|
||||
m_phase = newPhase;
|
||||
if (m_phase >= 2*M_PI) {
|
||||
//m_phase -= 2*M_PI;
|
||||
m_phase = -1;
|
||||
//m_freq += 50.0;
|
||||
if (m_freq>20000.0) {
|
||||
m_freq = 400.0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int32_t jjj=0; jjj<_map.size(); jjj++) {
|
||||
data[_map.size()*iii+jjj] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std11::chrono::system_clock::time_point getInterpolateTime(std11::chrono::system_clock::time_point _time, int32_t _pos, int16_t _val1, int16_t _val2, uint32_t _frequency) {
|
||||
if (_val1 == 0) {
|
||||
return _time + std11::chrono::nanoseconds(int64_t(_pos)*1000000000LL/int64_t(_frequency));
|
||||
} else if (_val2 == 0) {
|
||||
return _time + std11::chrono::nanoseconds(int64_t(_pos+1)*1000000000LL/int64_t(_frequency));
|
||||
}
|
||||
double xxx = double(-_val1) / double(_val2 - _val1);
|
||||
APPL_VERBOSE("deltaPos:" << xxx);
|
||||
return _time + std11::chrono::nanoseconds(int64_t((double(_pos)+xxx)*1000000000.0)/int64_t(_frequency));
|
||||
}
|
||||
|
||||
void onDataReceivedFeedBack(const void* _data,
|
||||
const std11::chrono::system_clock::time_point& _time,
|
||||
size_t _nbChunk,
|
||||
enum audio::format _format,
|
||||
uint32_t _frequency,
|
||||
const std::vector<audio::channel>& _map) {
|
||||
if (_format != audio::format_int16) {
|
||||
APPL_ERROR("call wrong type ... (need int16_t)");
|
||||
}
|
||||
RIVER_SAVE_FILE_MACRO(int16_t, "REC_FeedBack.raw", _data, _nbChunk*_map.size());
|
||||
const int16_t* data = static_cast<const int16_t*>(_data);
|
||||
// Detect Zero crossing after a max/min ...
|
||||
for (size_t iii=0; iii<_nbChunk; ++iii) {
|
||||
//for (size_t jjj=0; jjj<_map.size(); ++jjj) {
|
||||
size_t jjj=0; {
|
||||
if (m_stateFB == 0) {
|
||||
if (data[iii*_map.size() + jjj] > INT16_MAX/5) {
|
||||
m_stateFB = 1;
|
||||
APPL_VERBOSE("FB: detect Normal " << iii);
|
||||
} else if (data[iii*_map.size() + jjj] < -INT16_MAX/5) {
|
||||
m_stateFB = 2;
|
||||
APPL_VERBOSE("FB: detect inverse " << iii);
|
||||
}
|
||||
} else if (m_stateFB == 1) {
|
||||
// normale phase
|
||||
if (data[iii*_map.size() + jjj] <= 0) {
|
||||
// detect inversion of signe ...
|
||||
m_stateFB = 3;
|
||||
std11::chrono::system_clock::time_point time = getInterpolateTime(_time, iii-1, data[(iii-1)*_map.size() + jjj], data[iii*_map.size() + jjj], _frequency);
|
||||
APPL_VERBOSE("FB: 1 position -1: " << iii-1 << " " << data[(iii-1)*_map.size() + jjj]);
|
||||
APPL_VERBOSE("FB: 1 position 0: " << iii << " " << data[iii*_map.size() + jjj]);
|
||||
APPL_WARNING("FB: 1 time detected: " << time << " delay = " << float((time-m_currentTick).count())/1000.0f << "µs");
|
||||
}
|
||||
} else if (m_stateFB == 2) {
|
||||
// inverse phase
|
||||
if (data[iii*_map.size() + jjj] >= 0) {
|
||||
// detect inversion of signe ...
|
||||
m_stateFB = 3;
|
||||
std11::chrono::system_clock::time_point time = getInterpolateTime(_time, iii-1, data[(iii-1)*_map.size() + jjj], data[iii*_map.size() + jjj], _frequency);
|
||||
APPL_VERBOSE("FB: 2 position -1: " << iii-1 << " " << data[(iii-1)*_map.size() + jjj]);
|
||||
APPL_VERBOSE("FB: 2 position 0: " << iii << " " << data[iii*_map.size() + jjj]);
|
||||
APPL_WARNING("FB: 2 time detected: " << time << " delay = " << float((time-m_currentTick).count())/1000.0f << "µs");
|
||||
}
|
||||
} else if (m_stateFB == 3) {
|
||||
// TODO : Detect the pic ...
|
||||
// do nothing ...
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -96,18 +218,62 @@ namespace river_test_echo_delay {
|
||||
if (_format != audio::format_int16) {
|
||||
APPL_ERROR("call wrong type ... (need int16_t)");
|
||||
}
|
||||
RIVER_SAVE_FILE_MACRO(int16_t, "REC_Microphone.raw", _data, _nbChunk*_map.size());
|
||||
const int16_t* data = static_cast<const int16_t*>(_data);
|
||||
int64_t value = 0;
|
||||
for (size_t iii=0; iii<_nbChunk*_map.size(); ++iii) {
|
||||
value += std::abs(data[iii]);
|
||||
// Detect Zero crossing after a max/min ...
|
||||
for (size_t iii=0; iii<_nbChunk; ++iii) {
|
||||
//for (size_t jjj=0; jjj<_map.size(); ++jjj) {
|
||||
size_t jjj=0; {
|
||||
if (m_stateMic == 0) {
|
||||
if (data[iii*_map.size() + jjj] > 400/*INT16_MAX/15*/) {
|
||||
m_stateMic = 1;
|
||||
APPL_VERBOSE("Mic: detect Normal " << iii);
|
||||
} else if (data[iii*_map.size() + jjj] < -400/*INT16_MAX/15*/) {
|
||||
m_stateMic = 2;
|
||||
APPL_VERBOSE("Mic: detect inverse " << iii);
|
||||
}
|
||||
} else if (m_stateMic == 1) {
|
||||
// normale phase
|
||||
if (data[iii*_map.size() + jjj] <= 0) {
|
||||
// detect inversion of signe ...
|
||||
m_stateFB = 3;
|
||||
std11::chrono::system_clock::time_point time = getInterpolateTime(_time, iii-1, data[(iii-1)*_map.size() + jjj], data[iii*_map.size() + jjj], _frequency);
|
||||
APPL_VERBOSE("MIC: 1 position -1: " << iii-1 << " " << data[(iii-1)*_map.size() + jjj]);
|
||||
APPL_VERBOSE("MIC: 1 position 0: " << iii << " " << data[iii*_map.size() + jjj]);
|
||||
APPL_WARNING("MIC: 1 time detected: " << time << " delay = " << float((time-m_currentTick).count())/1000.0f << "µs");
|
||||
}
|
||||
} else if (m_stateMic == 2) {
|
||||
// inverse phase
|
||||
if (data[iii*_map.size() + jjj] >= 0) {
|
||||
// detect inversion of signe ...
|
||||
m_stateMic = 3;
|
||||
std11::chrono::system_clock::time_point time = getInterpolateTime(_time, iii-1, data[(iii-1)*_map.size() + jjj], data[iii*_map.size() + jjj], _frequency);
|
||||
APPL_VERBOSE("MIC: 2 position -1: " << iii-1 << " " << data[(iii-1)*_map.size() + jjj]);
|
||||
APPL_VERBOSE("MIC: 2 position 0: " << iii << " " << data[iii*_map.size() + jjj]);
|
||||
APPL_WARNING("MIC: 2 time detected: " << time << " delay = " << float((time-m_currentTick).count())/1000.0f << "µs");
|
||||
}
|
||||
} else if (m_stateMic == 3) {
|
||||
// TODO : Detect the pic ...
|
||||
// do nothing ...
|
||||
}
|
||||
}
|
||||
}
|
||||
value /= (_nbChunk*_map.size());
|
||||
APPL_INFO("Get data ... average=" << int32_t(value));
|
||||
/*
|
||||
const int16_t* data = static_cast<const int16_t*>(_data);
|
||||
int16_t value = 0;
|
||||
for (size_t iii=0; iii<_nbChunk*_map.size(); ++iii) {
|
||||
//APPL_INFO("value=" << data[iii]);
|
||||
value = std::max(int16_t(std::abs(data[iii])), value);
|
||||
}
|
||||
APPL_INFO("Get data ... max=" << value);
|
||||
*/
|
||||
}
|
||||
void run() {
|
||||
m_interfaceOut->start();
|
||||
m_interfaceIn->start();
|
||||
m_interfaceFB->start();
|
||||
usleep(30000000);
|
||||
m_interfaceFB->stop();
|
||||
m_interfaceIn->stop();
|
||||
m_interfaceOut->stop();
|
||||
}
|
||||
|
@ -15,11 +15,9 @@ namespace river_test_record_callback {
|
||||
private:
|
||||
std11::shared_ptr<river::Manager> m_manager;
|
||||
std11::shared_ptr<river::Interface> m_interface;
|
||||
double m_phase;
|
||||
public:
|
||||
testInCallback(std11::shared_ptr<river::Manager> _manager, const std::string& _input="microphone") :
|
||||
m_manager(_manager),
|
||||
m_phase(0) {
|
||||
m_manager(_manager) {
|
||||
//Set stereo output:
|
||||
std::vector<audio::channel> channelMap;
|
||||
channelMap.push_back(audio::channel_frontLeft);
|
||||
@ -61,7 +59,7 @@ namespace river_test_record_callback {
|
||||
// wait 2 second ...
|
||||
usleep(2000000);
|
||||
|
||||
m_manager->generateDotAll("activeProcess.dot");
|
||||
|
||||
m_interface->stop();
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user