[DEV] add support of multiple input stream type

This commit is contained in:
Edouard DUPIN 2016-08-22 21:52:31 +02:00
parent 9a37b437c6
commit 2566843a66
6 changed files with 87 additions and 70 deletions

View File

@ -14,6 +14,7 @@ namespace audio {
} }
#define RIVER_BASE(info,data) ELOG_BASE(audio::river::getLogId(),info,data) #define RIVER_BASE(info,data) ELOG_BASE(audio::river::getLogId(),info,data)
#define RIVER_PRINT(data) RIVER_BASE(-1, data)
#define RIVER_CRITICAL(data) RIVER_BASE(1, data) #define RIVER_CRITICAL(data) RIVER_BASE(1, data)
#define RIVER_ERROR(data) RIVER_BASE(2, data) #define RIVER_ERROR(data) RIVER_BASE(2, data)
#define RIVER_WARNING(data) RIVER_BASE(3, data) #define RIVER_WARNING(data) RIVER_BASE(3, data)

View File

@ -77,9 +77,7 @@ audio::river::io::Node::Node(const std::string& _name, const ejson::Object& _con
} }
enum audio::format muxerFormatType = audio::getFormatFromString(muxerDemuxerConfig); enum audio::format muxerFormatType = audio::getFormatFromString(muxerDemuxerConfig);
if (m_isInput == true) { if (m_isInput == true) {
if (muxerFormatType != audio::format_int16) { // Support all ...
RIVER_CRITICAL("not supported demuxer type ... " << muxerFormatType << " for INPUT set in file:" << muxerDemuxerConfig);
}
} else { } else {
if (muxerFormatType != audio::format_int16_on_int32) { if (muxerFormatType != audio::format_int16_on_int32) {
RIVER_CRITICAL("not supported demuxer type ... " << muxerFormatType << " for OUTPUT set in file:" << muxerDemuxerConfig); RIVER_CRITICAL("not supported demuxer type ... " << muxerFormatType << " for OUTPUT set in file:" << muxerDemuxerConfig);
@ -191,7 +189,6 @@ void audio::river::io::Node::newInput(const void* _inputBuffer,
if (_inputBuffer == nullptr) { if (_inputBuffer == nullptr) {
return; return;
} }
const int16_t* inputBuffer = static_cast<const int16_t *>(_inputBuffer);
for (size_t iii=0; iii< m_list.size(); ++iii) { for (size_t iii=0; iii< m_list.size(); ++iii) {
if (m_list[iii] == nullptr) { if (m_list[iii] == nullptr) {
continue; continue;
@ -200,7 +197,7 @@ void audio::river::io::Node::newInput(const void* _inputBuffer,
continue; continue;
} }
RIVER_VERBOSE(" IO name="<< m_list[iii]->getName()); RIVER_VERBOSE(" IO name="<< m_list[iii]->getName());
m_list[iii]->systemNewInputData(_time, inputBuffer, _nbChunk); m_list[iii]->systemNewInputData(_time, _inputBuffer, _nbChunk);
} }
RIVER_VERBOSE("data Input size request :" << _nbChunk << " [ END ]"); RIVER_VERBOSE("data Input size request :" << _nbChunk << " [ END ]");
return; return;

View File

@ -193,15 +193,17 @@ void audio::river::io::NodeMuxer::onDataReceivedInput1(const void* _data,
enum audio::format _format, enum audio::format _format,
uint32_t _frequency, uint32_t _frequency,
const std::vector<audio::channel>& _map) { const std::vector<audio::channel>& _map) {
RIVER_DEBUG("Microphone Time=" << _time << " _nbChunk=" << _nbChunk << " _map=" << _map << " _format=" << _format << " freq=" << _frequency); RIVER_PRINT("Input-1 Time=" << _time << " _nbChunk=" << _nbChunk << " _map=" << _map << " _format=" << _format << " freq=" << _frequency);
RIVER_DEBUG(" next=" << _time + audio::Duration(0, _nbChunk*1000000000LL/int64_t(_frequency)) ); RIVER_DEBUG(" next=" << _time + audio::Duration(0, _nbChunk*1000000000LL/int64_t(_frequency)) );
/*
if (_format != audio::format_int16) { if (_format != audio::format_int16) {
RIVER_ERROR("call wrong type ... (need int16_t)"); RIVER_ERROR("call wrong type ... (need int16_t)");
} }
*/
// push data synchronize // push data synchronize
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
m_bufferInput1.write(_data, _nbChunk, _time); m_bufferInput1.write(_data, _nbChunk, _time);
//RIVER_SAVE_FILE_MACRO(int16_t, "REC_Microphone.raw", _data, _nbChunk*_map.size()); //RIVER_SAVE_FILE_MACRO(int16_t, "REC_muxer_input_1.raw", _data, _nbChunk*_map.size());
process(); process();
} }
@ -211,15 +213,17 @@ void audio::river::io::NodeMuxer::onDataReceivedInput2(const void* _data,
enum audio::format _format, enum audio::format _format,
uint32_t _frequency, uint32_t _frequency,
const std::vector<audio::channel>& _map) { const std::vector<audio::channel>& _map) {
RIVER_DEBUG("FeedBack Time=" << _time << " _nbChunk=" << _nbChunk << " _map=" << _map << " _format=" << _format << " freq=" << _frequency); RIVER_PRINT("Input-2 Time=" << _time << " _nbChunk=" << _nbChunk << " _map=" << _map << " _format=" << _format << " freq=" << _frequency);
RIVER_DEBUG(" next=" << _time + audio::Duration(0, _nbChunk*1000000000LL/int64_t(_frequency)) ); RIVER_DEBUG(" next=" << _time + audio::Duration(0, _nbChunk*1000000000LL/int64_t(_frequency)) );
/*
if (_format != audio::format_int16) { if (_format != audio::format_int16) {
RIVER_ERROR("call wrong type ... (need int16_t)"); RIVER_ERROR("call wrong type ... (need int16_t)");
} }
*/
// push data synchronize // push data synchronize
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
m_bufferInput2.write(_data, _nbChunk, _time); m_bufferInput2.write(_data, _nbChunk, _time);
//RIVER_SAVE_FILE_MACRO(int16_t, "REC_FeedBack.raw", _data, _nbChunk*_map.size()); //RIVER_SAVE_FILE_MACRO(int16_t, "REC_muxer_input_2.raw", _data, _nbChunk*_map.size());
process(); process();
} }
@ -230,6 +234,7 @@ void audio::river::io::NodeMuxer::process() {
if (m_bufferInput2.getSize() <= 256) { if (m_bufferInput2.getSize() <= 256) {
return; return;
} }
RIVER_PRINT("process : s1=" << m_bufferInput1.getSize() << " s2=" << m_bufferInput2.getSize());
audio::Time in1Time = m_bufferInput1.getReadTimeStamp(); audio::Time in1Time = m_bufferInput1.getReadTimeStamp();
audio::Time in2Time = m_bufferInput2.getReadTimeStamp(); audio::Time in2Time = m_bufferInput2.getReadTimeStamp();
audio::Duration delta; audio::Duration delta;
@ -238,18 +243,17 @@ void audio::river::io::NodeMuxer::process() {
} else { } else {
delta = in1Time - in2Time; delta = in1Time - in2Time;
} }
RIVER_VERBOSE("check delta " << delta.count() << " > " << m_sampleTime.count());
RIVER_INFO("check delta " << delta.count() << " > " << m_sampleTime.count());
if (delta > m_sampleTime) { if (delta > m_sampleTime) {
// Synchronize if possible // Synchronize if possible
if (in1Time < in2Time) { if (in1Time < in2Time) {
RIVER_INFO("in1Time < in2Time : Change Microphone time start " << in2Time); RIVER_INFO("in1Time < in2Time : Change Input-1 time start " << in2Time);
RIVER_INFO(" old time stamp=" << m_bufferInput1.getReadTimeStamp()); RIVER_INFO(" old time stamp=" << m_bufferInput1.getReadTimeStamp());
m_bufferInput1.setReadPosition(in2Time); m_bufferInput1.setReadPosition(in2Time);
RIVER_INFO(" new time stamp=" << m_bufferInput1.getReadTimeStamp()); RIVER_INFO(" new time stamp=" << m_bufferInput1.getReadTimeStamp());
} }
if (in1Time > in2Time) { if (in1Time > in2Time) {
RIVER_INFO("in1Time > in2Time : Change FeedBack time start " << in1Time); RIVER_INFO("in1Time > in2Time : Change Input-2 time start " << in1Time);
RIVER_INFO(" old time stamp=" << m_bufferInput2.getReadTimeStamp()); RIVER_INFO(" old time stamp=" << m_bufferInput2.getReadTimeStamp());
m_bufferInput2.setReadPosition(in1Time); m_bufferInput2.setReadPosition(in1Time);
RIVER_INFO(" new time stamp=" << m_bufferInput2.getReadTimeStamp()); RIVER_INFO(" new time stamp=" << m_bufferInput2.getReadTimeStamp());
@ -272,17 +276,17 @@ void audio::river::io::NodeMuxer::process() {
} }
std::vector<uint8_t> dataIn1; std::vector<uint8_t> dataIn1;
std::vector<uint8_t> dataIn2; std::vector<uint8_t> dataIn2;
dataIn1.resize(256*sizeof(int16_t)*m_mapInput1.size(), 0); dataIn1.resize(256*audio::getFormatBytes(getInterfaceFormat().getFormat())*m_mapInput1.size(), 0);
dataIn2.resize(256*sizeof(int16_t)*m_mapInput2.size(), 0); dataIn2.resize(256*audio::getFormatBytes(getInterfaceFormat().getFormat())*m_mapInput2.size(), 0);
m_data.resize(256*sizeof(int16_t)*getInterfaceFormat().getMap().size(), 0); m_data.resize(256*audio::getFormatBytes(getInterfaceFormat().getFormat())*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_muxer_output_1.raw", &dataIn1[0], 256 * m_mapInput1.size());
//RIVER_SAVE_FILE_MACRO(int16_t, "REC_INPUT2.raw", &dataIn2[0], 256 * m_mapInput2.size()); //RIVER_SAVE_FILE_MACRO(int16_t, "REC_muxer_output_2.raw", &dataIn2[0], 256 * m_mapInput2.size());
// if threaded : send event / otherwise, process ... // if threaded : send event / otherwise, process ...
processMuxer(&dataIn1[0], &dataIn2[0], 256, in1Time); processMuxer(&dataIn1[0], &dataIn2[0], 256, in1Time);
if ( m_bufferInput1.getSize() <= 256 if ( m_bufferInput1.getSize() <= 256

View File

@ -145,7 +145,8 @@ audio::river::io::NodeOrchestra::NodeOrchestra(const std::string& _name, const e
RIVER_CRITICAL("auto set format no element in the configuration: " << m_info.nativeFormats); RIVER_CRITICAL("auto set format no element in the configuration: " << m_info.nativeFormats);
} }
} else { } else {
RIVER_CRITICAL("Can not manage input transforamtion: " << hardwareFormat.getFormat() << " not in " << m_info.nativeFormats); RIVER_ERROR("Can not manage input transforamtion: " << hardwareFormat.getFormat() << " not in " << m_info.nativeFormats);
hardwareFormat.setFormat(hardwareFormat.getFormat());
} }
} }
if (etk::isIn(hardwareFormat.getFrequency(), m_info.sampleRates) == false) { if (etk::isIn(hardwareFormat.getFrequency(), m_info.sampleRates) == false) {
@ -171,7 +172,7 @@ audio::river::io::NodeOrchestra::NodeOrchestra(const std::string& _name, const e
hardwareFormat.setFrequency(m_info.sampleRates[0]); hardwareFormat.setFrequency(m_info.sampleRates[0]);
RIVER_INFO("auto set frequency: " << hardwareFormat.getFrequency() << "(first element in list) in " << m_info.sampleRates); RIVER_INFO("auto set frequency: " << hardwareFormat.getFrequency() << "(first element in list) in " << m_info.sampleRates);
} else { } else {
RIVER_CRITICAL("Can not manage input transforamtion:" << hardwareFormat.getFrequency() << " not in " << m_info.sampleRates); RIVER_ERROR("Can not manage input transforamtion:" << hardwareFormat.getFrequency() << " not in " << m_info.sampleRates);
} }
interfaceFormat.setFrequency(hardwareFormat.getFrequency()); interfaceFormat.setFrequency(hardwareFormat.getFrequency());
} }
@ -183,7 +184,7 @@ audio::river::io::NodeOrchestra::NodeOrchestra(const std::string& _name, const e
params.deviceName = streamName; params.deviceName = streamName;
params.nChannels = hardwareFormat.getMap().size(); params.nChannels = hardwareFormat.getMap().size();
if (m_info.channels.size() < params.nChannels) { if (m_info.channels.size() < params.nChannels) {
RIVER_CRITICAL("Can not open hardware device with more channel (" << params.nChannels << ") that is autorized by hardware (" << m_info.channels.size() << ")."); RIVER_ERROR("Can not open hardware device with more channel (" << params.nChannels << ") that is autorized by hardware (" << m_info.channels.size() << ").");
} }
audio::orchestra::StreamOptions option; audio::orchestra::StreamOptions option;
etk::from_string(option.mode, tmpObject["timestamp-mode"].toString().get("soft")); etk::from_string(option.mode, tmpObject["timestamp-mode"].toString().get("soft"));

View File

@ -19,6 +19,7 @@ static const std::string configurationRiver =
" map-on:{\n" " map-on:{\n"
" interface:'auto',\n" " interface:'auto',\n"
" name:'default',\n" " name:'default',\n"
//" timestamp-mode:'trigered',\n"
" },\n" " },\n"
" frequency:0,\n" " frequency:0,\n"
" channel-map:['front-left', 'front-right'],\n" " channel-map:['front-left', 'front-right'],\n"
@ -35,10 +36,13 @@ void onDataReceived(const void* _data,
uint32_t _frequency, uint32_t _frequency,
const std::vector<audio::channel>& _map, const std::vector<audio::channel>& _map,
etk::FSNode* _outputNode) { etk::FSNode* _outputNode) {
if (_format != audio::format_int16) { if ( _format != audio::format_int16
std::cout << "[ERROR] call wrong type ... (need int16_t)" << std::endl; && _format != audio::format_float) {
std::cout << "[ERROR] call wrong type ... (need int16_t.float)" << std::endl;
return;
} }
if (_outputNode->fileIsOpen() == false) { if (_outputNode->fileIsOpen() == false) {
if (_format != audio::format_int16) {
// get the curent power of the signal. // get the curent power of the signal.
const int16_t* data = static_cast<const int16_t*>(_data); const int16_t* data = static_cast<const int16_t*>(_data);
int64_t value = 0; int64_t value = 0;
@ -47,9 +51,19 @@ void onDataReceived(const void* _data,
} }
value /= (_nbChunk*_map.size()); value /= (_nbChunk*_map.size());
std::cout << "Get data ... average=" << int32_t(value) << std::endl; std::cout << "Get data ... average=" << int32_t(value) << std::endl;
} else {
// get the curent power of the signal.
const float* data = static_cast<const float*>(_data);
float value = 0;
for (size_t iii=0; iii<_nbChunk*_map.size(); ++iii) {
value += std::abs(data[iii]);
}
value /= (_nbChunk*_map.size());
std::cout << "Get data ... average=" << float(value) << std::endl;
}
} else { } else {
// just write data // just write data
std::cout << "Get data ... chunks=" << _nbChunk << " time=" << _time << std::endl; //std::cout << "Get data ... chunks=" << _nbChunk << " time=" << _time << std::endl;
_outputNode->fileWrite(_data, _map.size()*audio::getFormatBytes(_format), _nbChunk); _outputNode->fileWrite(_data, _map.size()*audio::getFormatBytes(_format), _nbChunk);
} }
} }

View File

@ -17,12 +17,12 @@ static const std::string configurationRiver =
" io:'output',\n" " io:'output',\n"
" map-on:{\n" " map-on:{\n"
" interface:'alsa',\n" " interface:'alsa',\n"
" name:'hw:2,0',\n" " name:'hw:0,0',\n"
" },\n" " },\n"
" frequency:0,\n" " frequency:48000,\n"
//" channel-map:['front-left', 'front-right', 'rear-left', 'rear-right'],\n" //" channel-map:['front-left', 'front-right', 'rear-left', 'rear-right'],\n"
" channel-map:['front-left', 'front-right'],\n" " channel-map:['front-left', 'front-right'],\n"
" type:'int32',\n" " type:'int16',\n"
" nb-chunk:1024,\n" " nb-chunk:1024,\n"
" volume-name:'MASTER'\n" " volume-name:'MASTER'\n"
" }\n" " }\n"