audio-river/test/testRecordCallback.h

97 lines
3.1 KiB
C
Raw Normal View History

2015-03-03 23:17:43 +01:00
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#pragma once
2015-03-03 23:17:43 +01:00
2015-10-14 21:21:03 +02:00
#include <test-debug/debug.h>
2015-03-12 22:28:15 +01:00
2015-03-03 23:17:43 +01:00
namespace river_test_record_callback {
2015-03-13 23:22:17 +01:00
static const std::string configurationRiver =
"{\n"
" microphone:{\n"
" io:'input',\n"
" map-on:{\n"
" interface:'auto',\n"
" name:'default',\n"
" },\n"
" frequency:0,\n"
" channel-map:['front-left', 'front-right'],\n"
" type:'auto',\n"
" nb-chunk:1024\n"
" }\n"
"}\n";
2015-03-12 23:17:14 +01:00
2015-03-03 23:17:43 +01:00
class testInCallback {
public:
std::shared_ptr<audio::river::Manager> m_manager;
std::shared_ptr<audio::river::Interface> m_interface;
2015-03-03 23:17:43 +01:00
public:
testInCallback(std::shared_ptr<audio::river::Manager> _manager, const std::string& _input="microphone") :
2015-03-04 22:15:35 +01:00
m_manager(_manager) {
2015-03-03 23:17:43 +01:00
//Set stereo output:
std::vector<audio::channel> channelMap;
m_interface = m_manager->createInput(48000,
channelMap,
audio::format_int16,
2015-03-13 23:22:17 +01:00
_input);
if(m_interface == nullptr) {
2015-10-14 21:21:03 +02:00
TEST_ERROR("nullptr interface");
return;
}
2015-03-03 23:17:43 +01:00
// set callback mode ...
m_interface->setInputCallback(std::bind(&testInCallback::onDataReceived,
2015-03-03 23:17:43 +01:00
this,
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3,
std::placeholders::_4,
std::placeholders::_5,
std::placeholders::_6));
2015-03-03 23:17:43 +01:00
}
void onDataReceived(const void* _data,
2015-04-13 21:49:48 +02:00
const audio::Time& _time,
2015-03-03 23:17:43 +01:00
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map) {
if (_format != audio::format_int16) {
2015-10-14 21:21:03 +02:00
TEST_ERROR("call wrong type ... (need int16_t)");
2015-03-03 23:17:43 +01:00
}
2015-10-14 21:21:03 +02:00
TEST_SAVE_FILE_MACRO(int16_t, "REC_INPUT.raw", _data, _nbChunk * _map.size());
2015-03-03 23:17:43 +01:00
const int16_t* data = static_cast<const int16_t*>(_data);
int64_t value = 0;
for (size_t iii=0; iii<_nbChunk*_map.size(); ++iii) {
value += std::abs(data[iii]);
}
value /= (_nbChunk*_map.size());
2015-10-14 21:21:03 +02:00
TEST_INFO("Get data ... average=" << int32_t(value));
2015-03-03 23:17:43 +01:00
}
void run() {
if(m_interface == nullptr) {
2015-10-14 21:21:03 +02:00
TEST_ERROR("nullptr interface");
return;
}
2015-03-03 23:17:43 +01:00
m_interface->start();
// wait 2 second ...
2015-03-12 22:28:15 +01:00
usleep(20000000);
2015-03-03 23:17:43 +01:00
m_interface->stop();
}
};
TEST(TestALL, testInputCallBack) {
2015-04-11 09:38:30 +02:00
audio::river::initString(configurationRiver);
std::shared_ptr<audio::river::Manager> manager;
2015-04-11 09:38:30 +02:00
manager = audio::river::Manager::create("testApplication");
2015-10-14 21:21:03 +02:00
TEST_INFO("test input (callback mode)");
std::shared_ptr<testInCallback> process = std::make_shared<testInCallback>(manager);
2015-03-03 23:17:43 +01:00
process->run();
process.reset();
usleep(500000);
2015-04-11 09:38:30 +02:00
audio::river::unInit();
2015-03-03 23:17:43 +01:00
}
};