[DEV] base test
This commit is contained in:
parent
f9203782e2
commit
72a2776a6f
26
lutin_audio_algo_chunkware_test.py
Normal file
26
lutin_audio_algo_chunkware_test.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/python
|
||||
import lutinModule as module
|
||||
import lutinTools as tools
|
||||
import lutinDebug as debug
|
||||
|
||||
def get_desc():
|
||||
return "audio_algo_aec_test: test for LMS ALGO"
|
||||
|
||||
|
||||
def create(target):
|
||||
myModule = module.Module(__file__, 'audio_algo_chunkware_test', 'BINARY')
|
||||
myModule.add_src_file([
|
||||
'test/main.cpp',
|
||||
'test/debug.cpp'
|
||||
])
|
||||
myModule.add_module_depend(['audio_algo_chunkware'])
|
||||
return myModule
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
13
test/debug.cpp
Normal file
13
test/debug.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
int32_t appl::getLogId() {
|
||||
static int32_t g_val = etk::log::registerInstance("test-LMS");
|
||||
return g_val;
|
||||
}
|
||||
|
41
test/debug.h
Normal file
41
test/debug.h
Normal file
@ -0,0 +1,41 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __APPL_DEBUG_H__
|
||||
#define __APPL_DEBUG_H__
|
||||
|
||||
#include <etk/log.h>
|
||||
|
||||
namespace appl {
|
||||
int32_t getLogId();
|
||||
};
|
||||
|
||||
#define APPL_BASE(info,data) TK_LOG_BASE(appl::getLogId(),info,data)
|
||||
|
||||
#define APPL_CRITICAL(data) APPL_BASE(1, data)
|
||||
#define APPL_ERROR(data) APPL_BASE(2, data)
|
||||
#define APPL_WARNING(data) APPL_BASE(3, data)
|
||||
#ifdef DEBUG
|
||||
#define APPL_INFO(data) APPL_BASE(4, data)
|
||||
#define APPL_DEBUG(data) APPL_BASE(5, data)
|
||||
#define APPL_VERBOSE(data) APPL_BASE(6, data)
|
||||
#define APPL_TODO(data) APPL_BASE(4, "TODO : " << data)
|
||||
#else
|
||||
#define APPL_INFO(data) do { } while(false)
|
||||
#define APPL_DEBUG(data) do { } while(false)
|
||||
#define APPL_VERBOSE(data) do { } while(false)
|
||||
#define APPL_TODO(data) do { } while(false)
|
||||
#endif
|
||||
|
||||
#define APPL_ASSERT(cond,data) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
APPL_CRITICAL(data); \
|
||||
assert(!#cond); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
122
test/main.cpp
Normal file
122
test/main.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <test/debug.h>
|
||||
#include <etk/etk.h>
|
||||
#include <audio/algo/chunkware/.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <etk/chrono.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#undef __class__
|
||||
#define __class__ "test"
|
||||
|
||||
|
||||
static std::vector<double> convert(const std::vector<int16_t>& _data) {
|
||||
std::vector<double> out;
|
||||
out.resize(_data.size(), 0.0);
|
||||
for (size_t iii=0; iii<_data.size(); ++iii) {
|
||||
out[iii] = _data[iii];
|
||||
out[iii] /= 32768.0;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static std::vector<int16_t> convert(const std::vector<double>& _data) {
|
||||
std::vector<int16_t> out;
|
||||
out.resize(_data.size(), 0.0);
|
||||
for (size_t iii=0; iii<_data.size(); ++iii) {
|
||||
out[iii] = int16_t(std::avg(-32768.0, _data[iii]*32768.0, 32767.0));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
int main(int _argc, const char** _argv) {
|
||||
// the only one init for etk:
|
||||
etk::init(_argc, _argv);
|
||||
std::string inputName = "";
|
||||
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,"--in=")) {
|
||||
fbName = &data[5];
|
||||
} 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 : ");
|
||||
APPL_INFO(" ./xxx --fb=file.raw --mic=file.raw");
|
||||
APPL_INFO(" --in=YYY.raw inout file");
|
||||
APPL_INFO(" --perf Enable performence test (little slower but real performence test)");
|
||||
APPL_INFO(" --sample-rate=XXXX Signal sample rate (default 48000)");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
if (inputName == "") {
|
||||
APPL_ERROR("Can not Process missing parameters...");
|
||||
exit(-1);
|
||||
}
|
||||
APPL_INFO("Read input:");
|
||||
std::vector<double> inputData = convert(etk::FSNodeReadAllDataType<int16_t>(inputName));
|
||||
APPL_INFO(" " << inputData.size() << " samples");
|
||||
// resize output :
|
||||
std::vector<double> output;
|
||||
output.resize(inputData.size(), 0);
|
||||
// process in chunk of 256 samples
|
||||
int32_t blockSize = 256;
|
||||
// for CPU consomtion:
|
||||
std11::chrono::nanoseconds totalTimeProcessing(0);
|
||||
std11::chrono::nanoseconds minProcessing(99999999999999LL);
|
||||
std11::chrono::nanoseconds maxProcessing(0);
|
||||
int32_t totalIteration = 0;
|
||||
|
||||
|
||||
audio::algo::aec::Lms algo;
|
||||
if (filterSize != 0) {
|
||||
algo.setFilterSize(filterSize);
|
||||
}
|
||||
if (mu != 0.0f) {
|
||||
algo.setMu(mu);
|
||||
}
|
||||
int32_t lastPourcent = -1;
|
||||
for (int32_t iii=0; iii<output.size()/blockSize; ++iii) {
|
||||
if (lastPourcent != 100*iii / (output.size()/blockSize)) {
|
||||
lastPourcent = 100*iii / (output.size()/blockSize);
|
||||
APPL_INFO("Process : " << iii*blockSize << "/" << int32_t(output.size()/blockSize)*blockSize << " " << lastPourcent << "/100");
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
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 << " %");
|
||||
}
|
||||
etk::FSNodeWriteAllDataType<int16_t>("output.raw", convert(output));
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user