[DEV] nearly ended muxer
This commit is contained in:
parent
a7b6ddce90
commit
6a3e364cd3
@ -122,6 +122,7 @@
|
|||||||
resampling-type:"speexdsp",
|
resampling-type:"speexdsp",
|
||||||
resampling-option:"quality=10",
|
resampling-option:"quality=10",
|
||||||
},
|
},
|
||||||
|
input-2-remap:["rear-left", "rear-right"],
|
||||||
#classical format configuration:
|
#classical format configuration:
|
||||||
frequency:48000,
|
frequency:48000,
|
||||||
channel-map:[
|
channel-map:[
|
||||||
|
@ -70,6 +70,7 @@ river::io::NodeMuxer::NodeMuxer(const std::string& _name, const std11::shared_pt
|
|||||||
resampling-type:"speexdsp",
|
resampling-type:"speexdsp",
|
||||||
resampling-option:"quality=10",
|
resampling-option:"quality=10",
|
||||||
},
|
},
|
||||||
|
input-2-remap:["rear-left", "rear-right"], # remap the IO inputs ...
|
||||||
# AEC algo definition
|
# AEC algo definition
|
||||||
algo:"river-remover",
|
algo:"river-remover",
|
||||||
algo-mode:"cutter",
|
algo-mode:"cutter",
|
||||||
@ -84,7 +85,21 @@ river::io::NodeMuxer::NodeMuxer(const std::string& _name, const std11::shared_pt
|
|||||||
RIVER_ERROR("Can not opne virtual device ... map-on-input-1 in " << _name);
|
RIVER_ERROR("Can not opne virtual device ... map-on-input-1 in " << _name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_mapInput1 = m_interfaceInput1->getInterfaceFormat().getMap();
|
std11::shared_ptr<const ejson::Array> listChannelMap = m_config->getArray("input-1-remap");
|
||||||
|
if ( listChannelMap == nullptr
|
||||||
|
|| listChannelMap->size() == 0) {
|
||||||
|
m_mapInput1 = m_interfaceInput1->getInterfaceFormat().getMap();
|
||||||
|
} else {
|
||||||
|
m_mapInput1.clear();
|
||||||
|
for (size_t iii=0; iii<listChannelMap->size(); ++iii) {
|
||||||
|
std::string value = listChannelMap->getStringValue(iii);
|
||||||
|
m_mapInput1.push_back(audio::getChannelFromString(value));
|
||||||
|
}
|
||||||
|
if (m_mapInput1.size() != m_interfaceInput1->getInterfaceFormat().getMap().size()) {
|
||||||
|
RIVER_ERROR("Request remap of the Input 1 the 2 size is wrong ... request=");
|
||||||
|
m_mapInput1 = m_interfaceInput1->getInterfaceFormat().getMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RIVER_INFO("Create IN 2 : ");
|
RIVER_INFO("Create IN 2 : ");
|
||||||
m_interfaceInput2 = createInput(hardwareFormat.getFrequency(),
|
m_interfaceInput2 = createInput(hardwareFormat.getFrequency(),
|
||||||
@ -96,7 +111,21 @@ river::io::NodeMuxer::NodeMuxer(const std::string& _name, const std11::shared_pt
|
|||||||
RIVER_ERROR("Can not opne virtual device ... map-on-input-2 in " << _name);
|
RIVER_ERROR("Can not opne virtual device ... map-on-input-2 in " << _name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_mapInput2 = m_interfaceInput1->getInterfaceFormat().getMap();
|
listChannelMap = m_config->getArray("input-2-remap");
|
||||||
|
if ( listChannelMap == nullptr
|
||||||
|
|| listChannelMap->size() == 0) {
|
||||||
|
m_mapInput2 = m_interfaceInput2->getInterfaceFormat().getMap();
|
||||||
|
} else {
|
||||||
|
m_mapInput2.clear();
|
||||||
|
for (size_t iii=0; iii<listChannelMap->size(); ++iii) {
|
||||||
|
std::string value = listChannelMap->getStringValue(iii);
|
||||||
|
m_mapInput2.push_back(audio::getChannelFromString(value));
|
||||||
|
}
|
||||||
|
if (m_mapInput2.size() != m_interfaceInput2->getInterfaceFormat().getMap().size()) {
|
||||||
|
RIVER_ERROR("Request remap of the Input 2 the 2 size is wrong ... request=");
|
||||||
|
m_mapInput2 = m_interfaceInput2->getInterfaceFormat().getMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set callback mode ...
|
// set callback mode ...
|
||||||
m_interfaceInput1->setInputCallback(std11::bind(&river::io::NodeMuxer::onDataReceivedFeedBack,
|
m_interfaceInput1->setInputCallback(std11::bind(&river::io::NodeMuxer::onDataReceivedFeedBack,
|
||||||
@ -245,10 +274,11 @@ void river::io::NodeMuxer::process() {
|
|||||||
std::vector<uint8_t> dataIn2;
|
std::vector<uint8_t> dataIn2;
|
||||||
dataIn1.resize(256*sizeof(int16_t)*m_mapInput1.size(), 0);
|
dataIn1.resize(256*sizeof(int16_t)*m_mapInput1.size(), 0);
|
||||||
dataIn2.resize(256*sizeof(int16_t)*m_mapInput2.size(), 0);
|
dataIn2.resize(256*sizeof(int16_t)*m_mapInput2.size(), 0);
|
||||||
|
m_data.resize(256*sizeof(int16_t)*getInterfaceFormat().getMap().size(), 0);
|
||||||
while (true) {
|
while (true) {
|
||||||
in1Time = m_bufferInput1.getReadTimeStamp();
|
in1Time = m_bufferInput1.getReadTimeStamp();
|
||||||
in2Time = m_bufferInput2.getReadTimeStamp();
|
in2Time = m_bufferInput2.getReadTimeStamp();
|
||||||
RIVER_INFO(" process 256 samples ... in1Time=" << in1Time << " in2Time=" << in2Time << " delta = " << (in1Time-in2Time).count());
|
//RIVER_INFO(" process 256 samples ... in1Time=" << in1Time << " in2Time=" << in2Time << " delta = " << (in1Time-in2Time).count());
|
||||||
m_bufferInput1.read(&dataIn1[0], 256);
|
m_bufferInput1.read(&dataIn1[0], 256);
|
||||||
m_bufferInput2.read(&dataIn2[0], 256);
|
m_bufferInput2.read(&dataIn2[0], 256);
|
||||||
RIVER_SAVE_FILE_MACRO(int16_t, "REC_INPUT1.raw", &dataIn1[0], 256 * m_mapInput1.size());
|
RIVER_SAVE_FILE_MACRO(int16_t, "REC_INPUT1.raw", &dataIn1[0], 256 * m_mapInput1.size());
|
||||||
@ -263,9 +293,139 @@ void river::io::NodeMuxer::process() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void river::io::NodeMuxer::reorder(void* _output, uint32_t _nbChunk, void* _input, const std::vector<audio::channel>& _mapInput) {
|
||||||
|
// real process: (only depend of data size):
|
||||||
|
switch (getInterfaceFormat().getFormat()) {
|
||||||
|
case audio::format_int8:
|
||||||
|
{
|
||||||
|
DRAIN_VERBOSE("convert " << _mapInput << " ==> " << getInterfaceFormat().getMap());
|
||||||
|
int8_t* in = static_cast<int8_t*>(_input);
|
||||||
|
int8_t* out = static_cast<int8_t*>(_output);
|
||||||
|
for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) {
|
||||||
|
int32_t convertId = -1;
|
||||||
|
if ( _mapInput.size() == 1
|
||||||
|
&& _mapInput[0] == audio::channel_frontCenter) {
|
||||||
|
convertId = 0;
|
||||||
|
} else {
|
||||||
|
for (size_t jjj=0; jjj<_mapInput.size(); ++jjj) {
|
||||||
|
if (getInterfaceFormat().getMap()[kkk] == _mapInput[jjj]) {
|
||||||
|
convertId = jjj;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DRAIN_VERBOSE(" " << convertId << " ==> " << kkk);
|
||||||
|
if (convertId != -1) {
|
||||||
|
for (size_t iii=0; iii<_nbChunk; ++iii) {
|
||||||
|
out[iii*getInterfaceFormat().getMap().size()+kkk] = in[iii*_mapInput.size()+convertId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case audio::format_int16:
|
||||||
|
if (getInterfaceFormat().getMap().size() == 1) {
|
||||||
|
DRAIN_VERBOSE("convert " << _mapInput << " ==> " << getInterfaceFormat().getMap());
|
||||||
|
int16_t* in = static_cast<int16_t*>(_input);
|
||||||
|
int16_t* out = static_cast<int16_t*>(_output);
|
||||||
|
for (size_t iii=0; iii<_nbChunk; ++iii) {
|
||||||
|
int32_t val = 0;
|
||||||
|
for (size_t jjj=0; jjj<_mapInput.size(); ++jjj) {
|
||||||
|
val += in[iii*_mapInput.size()+jjj];
|
||||||
|
}
|
||||||
|
out[iii] = val/_mapInput.size();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DRAIN_VERBOSE("convert " << _mapInput << " ==> " << getInterfaceFormat().getMap());
|
||||||
|
int16_t* in = static_cast<int16_t*>(_input);
|
||||||
|
int16_t* out = static_cast<int16_t*>(_output);
|
||||||
|
for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) {
|
||||||
|
int32_t convertId = -1;
|
||||||
|
if ( _mapInput.size() == 1
|
||||||
|
&& _mapInput[0] == audio::channel_frontCenter) {
|
||||||
|
convertId = 0;
|
||||||
|
} else {
|
||||||
|
for (size_t jjj=0; jjj<_mapInput.size(); ++jjj) {
|
||||||
|
if (getInterfaceFormat().getMap()[kkk] == _mapInput[jjj]) {
|
||||||
|
convertId = jjj;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DRAIN_VERBOSE(" " << convertId << " ==> " << kkk);
|
||||||
|
if (convertId != -1) {
|
||||||
|
for (size_t iii=0; iii<_nbChunk; ++iii) {
|
||||||
|
out[iii*getInterfaceFormat().getMap().size()+kkk] = in[iii*_mapInput.size()+convertId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case audio::format_int16_on_int32:
|
||||||
|
case audio::format_int24:
|
||||||
|
case audio::format_int32:
|
||||||
|
case audio::format_float:
|
||||||
|
{
|
||||||
|
DRAIN_VERBOSE("convert (2) " << _mapInput << " ==> " << getInterfaceFormat().getMap());
|
||||||
|
uint32_t* in = static_cast<uint32_t*>(_input);
|
||||||
|
uint32_t* out = static_cast<uint32_t*>(_output);
|
||||||
|
for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) {
|
||||||
|
int32_t convertId = -1;
|
||||||
|
if ( _mapInput.size() == 1
|
||||||
|
&& _mapInput[0] == audio::channel_frontCenter) {
|
||||||
|
convertId = 0;
|
||||||
|
} else {
|
||||||
|
for (size_t jjj=0; jjj<_mapInput.size(); ++jjj) {
|
||||||
|
if (getInterfaceFormat().getMap()[kkk] == _mapInput[jjj]) {
|
||||||
|
convertId = jjj;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (convertId != -1) {
|
||||||
|
for (size_t iii=0; iii<_nbChunk; ++iii) {
|
||||||
|
out[iii*getInterfaceFormat().getMap().size()+kkk] = in[iii*_mapInput.size()+convertId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case audio::format_double:
|
||||||
|
{
|
||||||
|
DRAIN_VERBOSE("convert (2) " << _mapInput << " ==> " << getInterfaceFormat().getMap());
|
||||||
|
uint64_t* in = static_cast<uint64_t*>(_input);
|
||||||
|
uint64_t* out = static_cast<uint64_t*>(_output);
|
||||||
|
for (size_t kkk=0; kkk<getInterfaceFormat().getMap().size(); ++kkk) {
|
||||||
|
int32_t convertId = -1;
|
||||||
|
if ( _mapInput.size() == 1
|
||||||
|
&& _mapInput[0] == audio::channel_frontCenter) {
|
||||||
|
convertId = 0;
|
||||||
|
} else {
|
||||||
|
for (size_t jjj=0; jjj<_mapInput.size(); ++jjj) {
|
||||||
|
if (getInterfaceFormat().getMap()[kkk] == _mapInput[jjj]) {
|
||||||
|
convertId = jjj;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (convertId != -1) {
|
||||||
|
for (size_t iii=0; iii<_nbChunk; ++iii) {
|
||||||
|
out[iii*getInterfaceFormat().getMap().size()+kkk] = in[iii*_mapInput.size()+convertId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void river::io::NodeMuxer::processMuxer(void* _dataIn1, void* _dataIn2, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time) {
|
void river::io::NodeMuxer::processMuxer(void* _dataIn1, void* _dataIn2, uint32_t _nbChunk, const std11::chrono::system_clock::time_point& _time) {
|
||||||
RIVER_INFO("must Mux data : " << m_mapInput1 << " + " << m_mapInput2 << " ==> " << getInterfaceFormat().getMap());
|
//RIVER_INFO("must Mux data : " << m_mapInput1 << " + " << m_mapInput2 << " ==> " << getInterfaceFormat().getMap());
|
||||||
//newInput(_dataIn1, _nbChunk, _time);
|
memset(&m_data[0], 0, m_data.size());
|
||||||
|
reorder(&m_data[0], _nbChunk, _dataIn1, m_mapInput1);
|
||||||
|
reorder(&m_data[0], _nbChunk, _dataIn2, m_mapInput2);
|
||||||
|
newInput(&m_data[0], _nbChunk, _time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +58,8 @@ namespace river {
|
|||||||
std::vector<uint8_t> m_data;
|
std::vector<uint8_t> m_data;
|
||||||
public:
|
public:
|
||||||
virtual void generateDot(etk::FSNode& _node);
|
virtual void generateDot(etk::FSNode& _node);
|
||||||
|
private:
|
||||||
|
void reorder(void* _output, uint32_t _nbChunk, void* _input, const std::vector<audio::channel>& _mapInput);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,32 @@ namespace river_test_muxer {
|
|||||||
private:
|
private:
|
||||||
std11::shared_ptr<river::Manager> m_manager;
|
std11::shared_ptr<river::Manager> m_manager;
|
||||||
std11::shared_ptr<river::Interface> m_interfaceIn;
|
std11::shared_ptr<river::Interface> m_interfaceIn;
|
||||||
|
std11::shared_ptr<river::Interface> m_interfaceOut;
|
||||||
|
double m_phase;
|
||||||
public:
|
public:
|
||||||
TestClass(std11::shared_ptr<river::Manager> _manager) :
|
TestClass(std11::shared_ptr<river::Manager> _manager) :
|
||||||
m_manager(_manager) {
|
m_manager(_manager),
|
||||||
|
m_phase(0) {
|
||||||
|
std::vector<audio::channel> channelMap;
|
||||||
|
channelMap.push_back(audio::channel_frontLeft);
|
||||||
|
channelMap.push_back(audio::channel_frontRight);
|
||||||
|
m_interfaceOut = m_manager->createOutput(48000,
|
||||||
|
channelMap,
|
||||||
|
audio::format_int16,
|
||||||
|
"speaker",
|
||||||
|
"MuxerTestOut");
|
||||||
|
// set callback mode ...
|
||||||
|
m_interfaceOut->setOutputCallback(std11::bind(&TestClass::onDataNeeded,
|
||||||
|
this,
|
||||||
|
std11::placeholders::_1,
|
||||||
|
std11::placeholders::_2,
|
||||||
|
std11::placeholders::_3,
|
||||||
|
std11::placeholders::_4,
|
||||||
|
std11::placeholders::_5,
|
||||||
|
std11::placeholders::_6));
|
||||||
|
m_interfaceOut->addVolumeGroup("FLOW");
|
||||||
|
m_interfaceOut->setParameter("volume", "FLOW", "-6dB");
|
||||||
|
|
||||||
//Set stereo output:
|
//Set stereo output:
|
||||||
m_interfaceIn = m_manager->createInput(48000,
|
m_interfaceIn = m_manager->createInput(48000,
|
||||||
std::vector<audio::channel>(),
|
std::vector<audio::channel>(),
|
||||||
@ -37,6 +60,25 @@ namespace river_test_muxer {
|
|||||||
std11::placeholders::_6));
|
std11::placeholders::_6));
|
||||||
m_manager->generateDotAll("activeProcess.dot");
|
m_manager->generateDotAll("activeProcess.dot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onDataNeeded(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) {
|
||||||
|
int16_t* data = static_cast<int16_t*>(_data);
|
||||||
|
double baseCycle = 2.0*M_PI/(double)48000 * 440;
|
||||||
|
for (int32_t iii=0; iii<_nbChunk; iii++) {
|
||||||
|
for (int32_t jjj=0; jjj<_map.size(); jjj++) {
|
||||||
|
data[_map.size()*iii+jjj] = sin(m_phase) * 30000;
|
||||||
|
}
|
||||||
|
m_phase += baseCycle;
|
||||||
|
if (m_phase >= 2*M_PI) {
|
||||||
|
m_phase -= 2*M_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
void onDataReceived(const void* _data,
|
void onDataReceived(const void* _data,
|
||||||
const std11::chrono::system_clock::time_point& _time,
|
const std11::chrono::system_clock::time_point& _time,
|
||||||
size_t _nbChunk,
|
size_t _nbChunk,
|
||||||
@ -47,11 +89,14 @@ namespace river_test_muxer {
|
|||||||
APPL_ERROR("call wrong type ... (need int16_t)");
|
APPL_ERROR("call wrong type ... (need int16_t)");
|
||||||
}
|
}
|
||||||
RIVER_SAVE_FILE_MACRO(int16_t, "REC_MicrophoneMuxed.raw", _data, _nbChunk*_map.size());
|
RIVER_SAVE_FILE_MACRO(int16_t, "REC_MicrophoneMuxed.raw", _data, _nbChunk*_map.size());
|
||||||
|
APPL_ERROR("Receive data ... " << _nbChunk << " map=" << _map);
|
||||||
}
|
}
|
||||||
void run() {
|
void run() {
|
||||||
|
m_interfaceOut->start();
|
||||||
m_interfaceIn->start();
|
m_interfaceIn->start();
|
||||||
usleep(10000000);
|
usleep(10000000);
|
||||||
m_interfaceIn->stop();
|
m_interfaceIn->stop();
|
||||||
|
m_interfaceOut->stop();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user