audio-river/test/testPlaybackCallback.h

142 lines
4.3 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)
*/
#ifndef __RIVER_TEST_PLAYBACK_CALLBACK_H__
#define __RIVER_TEST_PLAYBACK_CALLBACK_H__
#undef __class__
#define __class__ "test_playback_callback"
namespace river_test_playback_callback {
class testOutCallback {
2015-03-13 23:22:17 +01:00
public:
2015-03-03 23:17:43 +01:00
std11::shared_ptr<river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface;
double m_phase;
public:
testOutCallback(std11::shared_ptr<river::Manager> _manager, const std::string& _io="speaker") :
m_manager(_manager),
m_phase(0) {
//Set stereo output:
std::vector<audio::channel> channelMap;
channelMap.push_back(audio::channel_frontLeft);
channelMap.push_back(audio::channel_frontRight);
m_interface = m_manager->createOutput(48000,
channelMap,
audio::format_int16,
2015-03-13 23:22:17 +01:00
_io);
if(m_interface == nullptr) {
APPL_ERROR("nullptr interface");
return;
}
2015-03-03 23:17:43 +01:00
// set callback mode ...
m_interface->setOutputCallback(std11::bind(&testOutCallback::onDataNeeded,
this,
std11::placeholders::_1,
std11::placeholders::_2,
std11::placeholders::_3,
std11::placeholders::_4,
std11::placeholders::_5,
std11::placeholders::_6));
}
void onDataNeeded(void* _data,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map) {
if (_format != audio::format_int16) {
APPL_ERROR("call wrong type ... (need int16_t)");
}
int16_t* data = static_cast<int16_t*>(_data);
double baseCycle = 2.0*M_PI/(double)48000 * (double)550;
for (int32_t iii=0; iii<_nbChunk; iii++) {
for (int32_t jjj=0; jjj<_map.size(); jjj++) {
data[_map.size()*iii+jjj] = cos(m_phase) * 30000;
}
m_phase += baseCycle;
if (m_phase >= 2*M_PI) {
m_phase -= 2*M_PI;
}
}
}
void run() {
if(m_interface == nullptr) {
APPL_ERROR("nullptr interface");
return;
}
2015-03-03 23:17:43 +01:00
m_interface->start();
// wait 2 second ...
usleep(2000000);
m_interface->stop();
}
};
2015-03-13 23:22:17 +01:00
static const std::string configurationRiver =
"{\n"
" speaker:{\n"
" io:'output',\n"
" map-on:{\n"
" interface:'auto',\n"
2015-03-23 22:46:21 +01:00
" name:'hw:2,0',\n"
2015-03-13 23:22:17 +01:00
" },\n"
" frequency:0,\n"
" channel-map:['front-left', 'front-right'],\n"
" type:'auto',\n"
" nb-chunk:1024,\n"
" volume-name:'MASTER'\n"
" }\n"
"}\n";
2015-03-12 23:17:14 +01:00
2015-03-03 23:17:43 +01:00
TEST(TestALL, testOutputCallBack) {
2015-03-12 23:17:14 +01:00
river::initString(configurationRiver);
2015-03-03 23:17:43 +01:00
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test output (callback mode)");
std11::shared_ptr<testOutCallback> process = std11::make_shared<testOutCallback>(manager, "speaker");
2015-03-13 23:22:17 +01:00
ASSERT_NE(process, nullptr);
2015-03-03 23:17:43 +01:00
process->run();
process.reset();
usleep(500000);
2015-03-12 23:17:14 +01:00
river::unInit();
2015-03-03 23:17:43 +01:00
}
TEST(TestALL, testOutputCallBackPulse) {
2015-03-12 23:17:14 +01:00
river::initString(configurationRiver);
2015-03-03 23:17:43 +01:00
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test output (callback mode)");
std11::shared_ptr<testOutCallback> process = std11::make_shared<testOutCallback>(manager, "speaker-pulse");
process->run();
process.reset();
usleep(500000);
2015-03-12 23:17:14 +01:00
river::unInit();
2015-03-03 23:17:43 +01:00
}
TEST(TestALL, testOutputCallBackJack) {
2015-03-12 23:17:14 +01:00
river::initString(configurationRiver);
2015-03-03 23:17:43 +01:00
std11::shared_ptr<river::Manager> manager;
manager = river::Manager::create("testApplication");
APPL_INFO("test output (callback mode)");
std11::shared_ptr<testOutCallback> process = std11::make_shared<testOutCallback>(manager, "speaker-jack");
process->run();
process.reset();
usleep(500000);
2015-03-12 23:17:14 +01:00
river::unInit();
2015-03-03 23:17:43 +01:00
}
};
#undef __class__
#define __class__ nullptr
#endif