[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());
}
#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) {
float output[_nbSample];
float feedback[_nbSample];
float microphone[_nbSample];
for (size_t iii=0; iii<_nbSample; ++iii) {
microphone[iii] = float(_microphone[iii])/32767.0f;
feedback[iii] = float(_feedback[iii])/32767.0f;
bool ret = false;
// due to the fact we allocate the data in the stack:
int32_t nbCycle = _nbSample/MAX_PROCESSING_BLOCK_SIZE;
if (_nbSample - int32_t(_nbSample/MAX_PROCESSING_BLOCK_SIZE)*MAX_PROCESSING_BLOCK_SIZE != 0 ) {
nbCycle++;
}
bool ret = process(output, feedback, microphone, _nbSample);
for (size_t iii=0; iii<_nbSample; ++iii) {
_output[iii] = int16_t(float(output[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);
}
}
return ret;
}

View File

@ -26,17 +26,30 @@ void audio::algo::aec::Nlms::reset(void) {
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) {
float output[_nbSample];
float feedback[_nbSample];
float microphone[_nbSample];
for (size_t iii=0; iii<_nbSample; ++iii) {
microphone[iii] = float(_microphone[iii])/32767.0f;
feedback[iii] = float(_feedback[iii])/32767.0f;
bool ret = false;
// due to the fact we allocate the data in the stack:
int32_t nbCycle = _nbSample/MAX_PROCESSING_BLOCK_SIZE;
if (_nbSample - int32_t(_nbSample/MAX_PROCESSING_BLOCK_SIZE)*MAX_PROCESSING_BLOCK_SIZE != 0 ) {
nbCycle++;
}
bool ret = process(output, feedback, microphone, _nbSample);
for (size_t iii=0; iii<_nbSample; ++iii) {
_output[iii] = int16_t(float(output[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);
}
}
return ret;
}

View File

@ -9,8 +9,9 @@
#include <audio/algo/aec/Lms.h>
#include <audio/algo/aec/Nlms.h>
#include <etk/os/FSNode.h>
#include <etk/chrono.h>
#include <unistd.h>
#undef __class__
#define __class__ "test"
@ -58,6 +59,8 @@ int main(int _argc, const char** _argv) {
int32_t filterSize = 0;
float mu = 0.0f;
bool nlms = false;
bool perf = false;
int64_t sampleRate = 48000;
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
if (etk::start_with(data,"--fb=")) {
@ -72,6 +75,11 @@ int main(int _argc, const char** _argv) {
mu = etk::string_to_float(data);
} else if (data == "--nlms") {
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"
|| data == "--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(" --mu=0.xx Mu value -1.0< mu < -1.0");
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);
}
}
@ -102,6 +112,10 @@ int main(int _argc, const char** _argv) {
int32_t blockSize = 256;
// end 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) {
APPL_INFO("***********************");
APPL_INFO("** LMS **");
@ -121,7 +135,17 @@ int main(int _argc, const char** _argv) {
} else {
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);
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();
} else {
@ -144,6 +168,17 @@ int main(int _argc, const char** _argv) {
}
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("filter.raw", filter);