[DEV] add perf and basic interface

This commit is contained in:
Edouard DUPIN 2015-04-03 23:25:51 +02:00
parent b3ddc41dae
commit 848b8a454a
3 changed files with 80 additions and 19 deletions

View File

@ -28,17 +28,30 @@ void audio::algo::aec::Lms::reset(void) {
setFilterSize(m_filter.size()); setFilterSize(m_filter.size());
} }
#define MAX_PROCESSING_BLOCK_SIZE (256)
bool audio::algo::aec::Lms::process(int16_t* _output, const int16_t* _feedback, const int16_t* _microphone, int32_t _nbSample) { bool audio::algo::aec::Lms::process(int16_t* _output, const int16_t* _feedback, const int16_t* _microphone, int32_t _nbSample) {
float output[_nbSample]; bool ret = false;
float feedback[_nbSample]; // due to the fact we allocate the data in the stack:
float microphone[_nbSample]; int32_t nbCycle = _nbSample/MAX_PROCESSING_BLOCK_SIZE;
for (size_t iii=0; iii<_nbSample; ++iii) { if (_nbSample - int32_t(_nbSample/MAX_PROCESSING_BLOCK_SIZE)*MAX_PROCESSING_BLOCK_SIZE != 0 ) {
microphone[iii] = float(_microphone[iii])/32767.0f; nbCycle++;
feedback[iii] = float(_feedback[iii])/32767.0f; }
for (int32_t bbb=0; bbb<nbCycle; ++bbb) {
float output[MAX_PROCESSING_BLOCK_SIZE];
float feedback[MAX_PROCESSING_BLOCK_SIZE];
float microphone[MAX_PROCESSING_BLOCK_SIZE];
int32_t offset = bbb*MAX_PROCESSING_BLOCK_SIZE;
int32_t nbData = std::min(MAX_PROCESSING_BLOCK_SIZE,
_nbSample - offset);
for (size_t iii=0; iii<nbData; ++iii) {
microphone[iii] = float(_microphone[offset+iii])/32767.0f;
feedback[iii] = float(_feedback[offset+iii])/32767.0f;
}
ret = process(output, feedback, microphone, nbData);
for (size_t iii=0; iii<nbData; ++iii) {
_output[offset+iii] = int16_t(float(output[iii])*32767.0f);
} }
bool ret = process(output, feedback, microphone, _nbSample);
for (size_t iii=0; iii<_nbSample; ++iii) {
_output[iii] = int16_t(float(output[iii])*32767.0f);
} }
return ret; return ret;
} }

View File

@ -26,17 +26,30 @@ void audio::algo::aec::Nlms::reset(void) {
setFilterSize(m_filter.size()); setFilterSize(m_filter.size());
} }
#define MAX_PROCESSING_BLOCK_SIZE (256)
bool audio::algo::aec::Nlms::process(int16_t* _output, const int16_t* _feedback, const int16_t* _microphone, int32_t _nbSample) { bool audio::algo::aec::Nlms::process(int16_t* _output, const int16_t* _feedback, const int16_t* _microphone, int32_t _nbSample) {
float output[_nbSample]; bool ret = false;
float feedback[_nbSample]; // due to the fact we allocate the data in the stack:
float microphone[_nbSample]; int32_t nbCycle = _nbSample/MAX_PROCESSING_BLOCK_SIZE;
for (size_t iii=0; iii<_nbSample; ++iii) { if (_nbSample - int32_t(_nbSample/MAX_PROCESSING_BLOCK_SIZE)*MAX_PROCESSING_BLOCK_SIZE != 0 ) {
microphone[iii] = float(_microphone[iii])/32767.0f; nbCycle++;
feedback[iii] = float(_feedback[iii])/32767.0f; }
for (int32_t bbb=0; bbb<nbCycle; ++bbb) {
float output[MAX_PROCESSING_BLOCK_SIZE];
float feedback[MAX_PROCESSING_BLOCK_SIZE];
float microphone[MAX_PROCESSING_BLOCK_SIZE];
int32_t offset = bbb*MAX_PROCESSING_BLOCK_SIZE;
int32_t nbData = std::min(MAX_PROCESSING_BLOCK_SIZE,
_nbSample - offset);
for (size_t iii=0; iii<nbData; ++iii) {
microphone[iii] = float(_microphone[offset+iii])/32767.0f;
feedback[iii] = float(_feedback[offset+iii])/32767.0f;
}
ret = process(output, feedback, microphone, nbData);
for (size_t iii=0; iii<nbData; ++iii) {
_output[offset+iii] = int16_t(float(output[iii])*32767.0f);
} }
bool ret = process(output, feedback, microphone, _nbSample);
for (size_t iii=0; iii<_nbSample; ++iii) {
_output[iii] = int16_t(float(output[iii])*32767.0f);
} }
return ret; return ret;
} }

View File

@ -9,8 +9,9 @@
#include <audio/algo/aec/Lms.h> #include <audio/algo/aec/Lms.h>
#include <audio/algo/aec/Nlms.h> #include <audio/algo/aec/Nlms.h>
#include <etk/os/FSNode.h> #include <etk/os/FSNode.h>
#include <etk/chrono.h>
#include <unistd.h>
#undef __class__ #undef __class__
#define __class__ "test" #define __class__ "test"
@ -58,6 +59,8 @@ int main(int _argc, const char** _argv) {
int32_t filterSize = 0; int32_t filterSize = 0;
float mu = 0.0f; float mu = 0.0f;
bool nlms = false; bool nlms = false;
bool perf = false;
int64_t sampleRate = 48000;
for (int32_t iii=0; iii<_argc ; ++iii) { for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii]; std::string data = _argv[iii];
if (etk::start_with(data,"--fb=")) { if (etk::start_with(data,"--fb=")) {
@ -72,6 +75,11 @@ int main(int _argc, const char** _argv) {
mu = etk::string_to_float(data); mu = etk::string_to_float(data);
} else if (data == "--nlms") { } else if (data == "--nlms") {
nlms = true; nlms = true;
} else if (data == "--perf") {
perf = true;
} else if (etk::start_with(data,"--sample-rate=")) {
data = &data[14];
sampleRate = etk::string_to_int32_t(data);
} else if ( data == "-h" } else if ( data == "-h"
|| data == "--help") { || data == "--help") {
APPL_INFO("Help : "); APPL_INFO("Help : ");
@ -81,6 +89,8 @@ int main(int _argc, const char** _argv) {
APPL_INFO(" --filter-size=xxx Size of the filter"); APPL_INFO(" --filter-size=xxx Size of the filter");
APPL_INFO(" --mu=0.xx Mu value -1.0< mu < -1.0"); APPL_INFO(" --mu=0.xx Mu value -1.0< mu < -1.0");
APPL_INFO(" --nlms NLMS version"); APPL_INFO(" --nlms NLMS version");
APPL_INFO(" --perf Enable performence test (little slower but real performence test)");
APPL_INFO(" --sample-rate=XXXX Signal sample rate (default 48000)");
exit(0); exit(0);
} }
} }
@ -102,6 +112,10 @@ int main(int _argc, const char** _argv) {
int32_t blockSize = 256; int32_t blockSize = 256;
// end filter : // end filter :
std::vector<float> filter; std::vector<float> filter;
std11::chrono::nanoseconds totalTimeProcessing(0);
std11::chrono::nanoseconds minProcessing(99999999999999LL);
std11::chrono::nanoseconds maxProcessing(0);
int32_t totalIteration = 0;
if (nlms == false) { if (nlms == false) {
APPL_INFO("***********************"); APPL_INFO("***********************");
APPL_INFO("** LMS **"); APPL_INFO("** LMS **");
@ -121,7 +135,17 @@ int main(int _argc, const char** _argv) {
} else { } else {
APPL_VERBOSE("Process : " << iii*blockSize << "/" << int32_t(output.size()/blockSize)*blockSize); APPL_VERBOSE("Process : " << iii*blockSize << "/" << int32_t(output.size()/blockSize)*blockSize);
} }
std11::chrono::steady_clock::time_point timeStart = std11::chrono::steady_clock::now();
algo.process(&output[iii*blockSize], &fbData[iii*blockSize], &micData[iii*blockSize], blockSize); algo.process(&output[iii*blockSize], &fbData[iii*blockSize], &micData[iii*blockSize], blockSize);
if (perf == true) {
std11::chrono::steady_clock::time_point timeEnd = std11::chrono::steady_clock::now();
std11::chrono::nanoseconds time = timeEnd - timeStart;
minProcessing = std::min(minProcessing, time);
maxProcessing = std::max(maxProcessing, time);
totalTimeProcessing += time;
totalIteration++;
usleep(10000);
}
} }
filter = algo.getFilter(); filter = algo.getFilter();
} else { } else {
@ -144,6 +168,17 @@ int main(int _argc, const char** _argv) {
} }
filter = algo.getFilter(); filter = algo.getFilter();
} }
if (perf == true) {
APPL_INFO("Performance Result: ");
APPL_INFO(" blockSize=" << blockSize << " sample");
APPL_INFO(" min=" << minProcessing.count() << " ns");
APPL_INFO(" max=" << maxProcessing.count() << " ns");
APPL_INFO(" avg=" << totalTimeProcessing.count()/totalIteration << " ns");
APPL_INFO(" min=" << (float((minProcessing.count()*sampleRate)/blockSize)/1000000000.0)*100.0 << " %");
APPL_INFO(" max=" << (float((maxProcessing.count()*sampleRate)/blockSize)/1000000000.0)*100.0 << " %");
APPL_INFO(" avg=" << (float(((totalTimeProcessing.count()/totalIteration)*sampleRate)/blockSize)/1000000000.0)*100.0 << " %");
}
write("output.raw", output); write("output.raw", output);
write("filter.raw", filter); write("filter.raw", filter);