[DEV] rework test
This commit is contained in:
parent
39424279ef
commit
5d7c9203ef
@ -23,14 +23,6 @@ static std::string asString(const std11::chrono::system_clock::time_point& tp) {
|
|||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std {
|
|
||||||
static std::ostream& operator <<(std::ostream& _os, const std11::chrono::system_clock::time_point& _obj) {
|
|
||||||
std11::chrono::microseconds us = std11::chrono::duration_cast<std11::chrono::microseconds>(_obj.time_since_epoch());
|
|
||||||
_os << us.count();
|
|
||||||
return _os;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int portAudioStreamCallback(const void *_input,
|
static int portAudioStreamCallback(const void *_input,
|
||||||
void *_output,
|
void *_output,
|
||||||
unsigned long _frameCount,
|
unsigned long _frameCount,
|
||||||
|
645
test/main.cpp
645
test/main.cpp
@ -13,598 +13,25 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <etk/thread.h>
|
#include <etk/thread.h>
|
||||||
|
#include "testAEC.h"
|
||||||
|
#include "testEchoDelay.h"
|
||||||
|
#include "testFormat.h"
|
||||||
|
#include "testMuxer.h"
|
||||||
|
#include "testPlaybackCallback.h"
|
||||||
|
#include "testPlaybackWrite.h"
|
||||||
|
#include "testRecordCallback.h"
|
||||||
|
#include "testRecordRead.h"
|
||||||
|
#include "testVolume.h"
|
||||||
|
|
||||||
|
|
||||||
#undef __class__
|
#undef __class__
|
||||||
#define __class__ "test"
|
#define __class__ "test"
|
||||||
|
|
||||||
class testOutWrite {
|
|
||||||
private:
|
|
||||||
std::vector<audio::channel> m_channelMap;
|
|
||||||
std11::shared_ptr<river::Manager> m_manager;
|
|
||||||
std11::shared_ptr<river::Interface> m_interface;
|
|
||||||
public:
|
|
||||||
testOutWrite(std11::shared_ptr<river::Manager> _manager) :
|
|
||||||
m_manager(_manager) {
|
|
||||||
//Set stereo output:
|
|
||||||
m_channelMap.push_back(audio::channel_frontLeft);
|
|
||||||
m_channelMap.push_back(audio::channel_frontRight);
|
|
||||||
m_interface = m_manager->createOutput(48000,
|
|
||||||
m_channelMap,
|
|
||||||
audio::format_int16,
|
|
||||||
"speaker",
|
|
||||||
"WriteMode");
|
|
||||||
m_interface->setReadwrite();
|
|
||||||
}
|
|
||||||
void run() {
|
|
||||||
double phase=0;
|
|
||||||
std::vector<int16_t> data;
|
|
||||||
data.resize(1024*m_channelMap.size());
|
|
||||||
double baseCycle = 2.0*M_PI/48000.0 * 440.0;
|
|
||||||
// start fill buffer
|
|
||||||
for (int32_t kkk=0; kkk<10; ++kkk) {
|
|
||||||
for (int32_t iii=0; iii<data.size()/m_channelMap.size(); iii++) {
|
|
||||||
for (int32_t jjj=0; jjj<m_channelMap.size(); jjj++) {
|
|
||||||
data[m_channelMap.size()*iii+jjj] = cos(phase) * 30000.0;
|
|
||||||
}
|
|
||||||
phase += baseCycle;
|
|
||||||
if (phase >= 2*M_PI) {
|
|
||||||
phase -= 2*M_PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_interface->write(&data[0], data.size()/m_channelMap.size());
|
|
||||||
}
|
|
||||||
m_interface->start();
|
|
||||||
for (int32_t kkk=0; kkk<100; ++kkk) {
|
|
||||||
for (int32_t iii=0; iii<data.size()/m_channelMap.size(); iii++) {
|
|
||||||
for (int32_t jjj=0; jjj<m_channelMap.size(); jjj++) {
|
|
||||||
data[m_channelMap.size()*iii+jjj] = cos(phase) * 30000.0;
|
|
||||||
}
|
|
||||||
phase += baseCycle;
|
|
||||||
if (phase >= 2*M_PI) {
|
|
||||||
phase -= 2*M_PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_interface->write(&data[0], data.size()/m_channelMap.size());
|
|
||||||
// TODO : Add a function to get number of time we need to wait enought time ...
|
|
||||||
usleep(15000);
|
|
||||||
}
|
|
||||||
m_interface->stop();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST(TestALL, testOutputWrite) {
|
|
||||||
std11::shared_ptr<river::Manager> manager;
|
|
||||||
manager = river::Manager::create("testApplication");
|
|
||||||
|
|
||||||
APPL_INFO("test output (write mode)");
|
|
||||||
std11::shared_ptr<testOutWrite> process = std11::make_shared<testOutWrite>(manager);
|
|
||||||
process->run();
|
|
||||||
process.reset();
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
|
|
||||||
class testOutWriteCallback {
|
|
||||||
private:
|
|
||||||
std11::shared_ptr<river::Manager> m_manager;
|
|
||||||
std11::shared_ptr<river::Interface> m_interface;
|
|
||||||
double m_phase;
|
|
||||||
public:
|
|
||||||
testOutWriteCallback(std11::shared_ptr<river::Manager> _manager) :
|
|
||||||
m_manager(_manager),
|
|
||||||
m_phase(0) {
|
|
||||||
std::vector<audio::channel> channelMap;
|
|
||||||
//Set stereo output:
|
|
||||||
channelMap.push_back(audio::channel_frontLeft);
|
|
||||||
channelMap.push_back(audio::channel_frontRight);
|
|
||||||
m_interface = m_manager->createOutput(48000,
|
|
||||||
channelMap,
|
|
||||||
audio::format_int16,
|
|
||||||
"speaker",
|
|
||||||
"WriteMode+Callback");
|
|
||||||
m_interface->setReadwrite();
|
|
||||||
m_interface->setWriteCallback(std11::bind(&testOutWriteCallback::onDataNeeded,
|
|
||||||
this,
|
|
||||||
std11::placeholders::_1,
|
|
||||||
std11::placeholders::_2,
|
|
||||||
std11::placeholders::_3,
|
|
||||||
std11::placeholders::_4,
|
|
||||||
std11::placeholders::_5));
|
|
||||||
}
|
|
||||||
void onDataNeeded(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)");
|
|
||||||
}
|
|
||||||
std::vector<int16_t> data;
|
|
||||||
data.resize(1024*_map.size());
|
|
||||||
double baseCycle = 2.0*M_PI/48000.0 * 440.0;
|
|
||||||
// start fill buffer
|
|
||||||
for (int32_t iii=0; iii<data.size()/_map.size(); iii++) {
|
|
||||||
for (int32_t jjj=0; jjj<_map.size(); jjj++) {
|
|
||||||
data[_map.size()*iii+jjj] = cos(m_phase) * 30000.0;
|
|
||||||
}
|
|
||||||
m_phase += baseCycle;
|
|
||||||
if (m_phase >= 2*M_PI) {
|
|
||||||
m_phase -= 2*M_PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_interface->write(&data[0], data.size()/_map.size());
|
|
||||||
}
|
|
||||||
void run() {
|
|
||||||
m_interface->start();
|
|
||||||
usleep(1000000);
|
|
||||||
m_interface->stop();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST(TestALL, testOutputWriteWithCallback) {
|
|
||||||
std11::shared_ptr<river::Manager> manager;
|
|
||||||
manager = river::Manager::create("testApplication");
|
|
||||||
|
|
||||||
APPL_INFO("test output (write with callback event mode)");
|
|
||||||
std11::shared_ptr<testOutWriteCallback> process = std11::make_shared<testOutWriteCallback>(manager);
|
|
||||||
process->run();
|
|
||||||
process.reset();
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class testOutCallback {
|
|
||||||
private:
|
|
||||||
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,
|
|
||||||
_io,
|
|
||||||
"WriteModeCallback");
|
|
||||||
// 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() {
|
|
||||||
m_interface->start();
|
|
||||||
// wait 2 second ...
|
|
||||||
usleep(2000000);
|
|
||||||
m_interface->stop();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST(TestALL, testOutputCallBack) {
|
|
||||||
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");
|
|
||||||
process->run();
|
|
||||||
process.reset();
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(TestALL, testOutputCallBackPulse) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(TestALL, testOutputCallBackJack) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
class testInRead {
|
|
||||||
private:
|
|
||||||
std::vector<audio::channel> m_channelMap;
|
|
||||||
std11::shared_ptr<river::Manager> m_manager;
|
|
||||||
std11::shared_ptr<river::Interface> m_interface;
|
|
||||||
public:
|
|
||||||
testInRead(std11::shared_ptr<river::Manager> _manager) :
|
|
||||||
m_manager(_manager){
|
|
||||||
//Set stereo output:
|
|
||||||
m_channelMap.push_back(audio::channel_frontLeft);
|
|
||||||
m_channelMap.push_back(audio::channel_frontRight);
|
|
||||||
m_interface = m_manager->createInput(48000,
|
|
||||||
m_channelMap,
|
|
||||||
audio::format_int16,
|
|
||||||
"microphone",
|
|
||||||
"WriteMode");
|
|
||||||
m_interface->setReadwrite();
|
|
||||||
}
|
|
||||||
void run() {
|
|
||||||
m_interface->start();
|
|
||||||
std::vector<int16_t> data;
|
|
||||||
for (int32_t kkk=0; kkk<100; ++kkk) {
|
|
||||||
data = m_interface->read(1024);
|
|
||||||
int64_t value = 0;
|
|
||||||
for (size_t iii=0; iii<data.size(); ++iii) {
|
|
||||||
value += std::abs(data[iii]);
|
|
||||||
}
|
|
||||||
value /= data.size();
|
|
||||||
APPL_INFO("Get data ... average=" << int32_t(value));
|
|
||||||
}
|
|
||||||
m_interface->stop();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST(TestALL, testInputCallBack) {
|
|
||||||
std11::shared_ptr<river::Manager> manager;
|
|
||||||
manager = river::Manager::create("testApplication");
|
|
||||||
APPL_INFO("test input (callback mode)");
|
|
||||||
std11::shared_ptr<testInCallback> process = std11::make_shared<testInCallback>(manager);
|
|
||||||
process->run();
|
|
||||||
process.reset();
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
class testInCallback {
|
|
||||||
private:
|
|
||||||
std11::shared_ptr<river::Manager> m_manager;
|
|
||||||
std11::shared_ptr<river::Interface> m_interface;
|
|
||||||
double m_phase;
|
|
||||||
public:
|
|
||||||
testInCallback(std11::shared_ptr<river::Manager> _manager, const std::string& _input="microphone") :
|
|
||||||
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->createInput(48000,
|
|
||||||
channelMap,
|
|
||||||
audio::format_int16,
|
|
||||||
_input,
|
|
||||||
"WriteModeCallback");
|
|
||||||
// set callback mode ...
|
|
||||||
m_interface->setInputCallback(std11::bind(&testInCallback::onDataReceived,
|
|
||||||
this,
|
|
||||||
std11::placeholders::_1,
|
|
||||||
std11::placeholders::_2,
|
|
||||||
std11::placeholders::_3,
|
|
||||||
std11::placeholders::_4,
|
|
||||||
std11::placeholders::_5,
|
|
||||||
std11::placeholders::_6));
|
|
||||||
}
|
|
||||||
void onDataReceived(const 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)");
|
|
||||||
}
|
|
||||||
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());
|
|
||||||
APPL_INFO("Get data ... average=" << int32_t(value));
|
|
||||||
}
|
|
||||||
void run() {
|
|
||||||
m_interface->start();
|
|
||||||
// wait 2 second ...
|
|
||||||
usleep(2000000);
|
|
||||||
|
|
||||||
m_manager->generateDotAll("activeProcess.dot");
|
|
||||||
m_interface->stop();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST(TestALL, testInputCallBack) {
|
|
||||||
std11::shared_ptr<river::Manager> manager;
|
|
||||||
manager = river::Manager::create("testApplication");
|
|
||||||
APPL_INFO("test input (callback mode)");
|
|
||||||
std11::shared_ptr<testInCallback> process = std11::make_shared<testInCallback>(manager);
|
|
||||||
process->run();
|
|
||||||
process.reset();
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class testOutCallbackType {
|
/*
|
||||||
private:
|
|
||||||
std11::shared_ptr<river::Manager> m_manager;
|
|
||||||
std11::shared_ptr<river::Interface> m_interface;
|
|
||||||
double m_phase;
|
|
||||||
float m_freq;
|
|
||||||
int32_t m_nbChannels;
|
|
||||||
float m_generateFreq;
|
|
||||||
|
|
||||||
public:
|
|
||||||
testOutCallbackType(const std11::shared_ptr<river::Manager>& _manager,
|
|
||||||
float _freq=48000.0f,
|
|
||||||
int32_t _nbChannels=2,
|
|
||||||
audio::format _format=audio::format_int16) :
|
|
||||||
m_manager(_manager),
|
|
||||||
m_phase(0),
|
|
||||||
m_freq(_freq),
|
|
||||||
m_nbChannels(_nbChannels),
|
|
||||||
m_generateFreq(550.0f) {
|
|
||||||
//Set stereo output:
|
|
||||||
std::vector<audio::channel> channelMap;
|
|
||||||
if (m_nbChannels == 1) {
|
|
||||||
channelMap.push_back(audio::channel_frontCenter);
|
|
||||||
} else if (m_nbChannels == 2) {
|
|
||||||
channelMap.push_back(audio::channel_frontLeft);
|
|
||||||
channelMap.push_back(audio::channel_frontRight);
|
|
||||||
} else if (m_nbChannels == 4) {
|
|
||||||
channelMap.push_back(audio::channel_frontLeft);
|
|
||||||
channelMap.push_back(audio::channel_frontRight);
|
|
||||||
channelMap.push_back(audio::channel_rearLeft);
|
|
||||||
channelMap.push_back(audio::channel_rearRight);
|
|
||||||
} else {
|
|
||||||
APPL_ERROR("Can not generate with channel != 1,2,4");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_interface = m_manager->createOutput(m_freq,
|
|
||||||
channelMap,
|
|
||||||
_format,
|
|
||||||
"speaker",
|
|
||||||
"WriteModeCallbackType");
|
|
||||||
// set callback mode ...
|
|
||||||
m_interface->setOutputCallback(std11::bind(&testOutCallbackType::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) {
|
|
||||||
//APPL_DEBUG("Get data ... " << _format << " map=" << _map << " chunk=" << _nbChunk);
|
|
||||||
double baseCycle = 2.0*M_PI/double(m_freq) * double(m_generateFreq);
|
|
||||||
if (_format == audio::format_int16) {
|
|
||||||
int16_t* data = static_cast<int16_t*>(_data);
|
|
||||||
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) * double(INT16_MAX);
|
|
||||||
}
|
|
||||||
m_phase += baseCycle;
|
|
||||||
if (m_phase >= 2*M_PI) {
|
|
||||||
m_phase -= 2*M_PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (_format == audio::format_int16_on_int32) {
|
|
||||||
int32_t* data = static_cast<int32_t*>(_data);
|
|
||||||
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) * double(INT16_MAX);
|
|
||||||
}
|
|
||||||
m_phase += baseCycle;
|
|
||||||
if (m_phase >= 2*M_PI) {
|
|
||||||
m_phase -= 2*M_PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (_format == audio::format_int32) {
|
|
||||||
int32_t* data = static_cast<int32_t*>(_data);
|
|
||||||
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) * double(INT32_MAX);
|
|
||||||
}
|
|
||||||
m_phase += baseCycle;
|
|
||||||
if (m_phase >= 2*M_PI) {
|
|
||||||
m_phase -= 2*M_PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (_format == audio::format_float) {
|
|
||||||
float* data = static_cast<float*>(_data);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
m_phase += baseCycle;
|
|
||||||
if (m_phase >= 2*M_PI) {
|
|
||||||
m_phase -= 2*M_PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void run() {
|
|
||||||
if (m_interface != nullptr) {
|
|
||||||
m_interface->start();
|
|
||||||
// wait 2 second ...
|
|
||||||
usleep(1000000);
|
|
||||||
m_interface->stop();
|
|
||||||
usleep(100000);
|
|
||||||
} else {
|
|
||||||
APPL_ERROR("Can not create interface !!!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class testResampling : public ::testing::TestWithParam<float> {};
|
|
||||||
TEST_P(testResampling, base) {
|
|
||||||
std11::shared_ptr<river::Manager> manager;
|
|
||||||
manager = river::Manager::create("testApplication");
|
|
||||||
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, GetParam(), 2, audio::format_int16);
|
|
||||||
process->run();
|
|
||||||
process.reset();
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
|
||||||
testResampling,
|
|
||||||
::testing::Values(4000, 8000, 16000, 32000, 48000, 48001, 64000, 96000, 11250, 2250, 44100, 88200));
|
|
||||||
|
|
||||||
|
|
||||||
class testFormat : public ::testing::TestWithParam<audio::format> {};
|
|
||||||
TEST_P(testFormat, base) {
|
|
||||||
std11::shared_ptr<river::Manager> manager;
|
|
||||||
manager = river::Manager::create("testApplication");
|
|
||||||
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, 48000, 2, GetParam());
|
|
||||||
process->run();
|
|
||||||
process.reset();
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
|
||||||
testFormat,
|
|
||||||
::testing::Values(audio::format_int16, audio::format_int16_on_int32, audio::format_int32, audio::format_float));
|
|
||||||
|
|
||||||
|
|
||||||
class testChannels : public ::testing::TestWithParam<int32_t> {};
|
|
||||||
TEST_P(testChannels, base) {
|
|
||||||
std11::shared_ptr<river::Manager> manager;
|
|
||||||
manager = river::Manager::create("testApplication");
|
|
||||||
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, 48000, GetParam(), audio::format_int16);
|
|
||||||
process->run();
|
|
||||||
process.reset();
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
|
||||||
testChannels,
|
|
||||||
::testing::Values(1,2,4));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class testCallbackVolume {
|
|
||||||
private:
|
|
||||||
std11::shared_ptr<river::Manager> m_manager;
|
|
||||||
std11::shared_ptr<river::Interface> m_interface;
|
|
||||||
double m_phase;
|
|
||||||
public:
|
|
||||||
testCallbackVolume(std11::shared_ptr<river::Manager> _manager) :
|
|
||||||
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,
|
|
||||||
"speaker",
|
|
||||||
"WriteModeCallback");
|
|
||||||
// set callback mode ...
|
|
||||||
m_interface->setOutputCallback(std11::bind(&testCallbackVolume::onDataNeeded,
|
|
||||||
this,
|
|
||||||
std11::placeholders::_1,
|
|
||||||
std11::placeholders::_2,
|
|
||||||
std11::placeholders::_3,
|
|
||||||
std11::placeholders::_4,
|
|
||||||
std11::placeholders::_5,
|
|
||||||
std11::placeholders::_6));
|
|
||||||
m_interface->addVolumeGroup("MEDIA");
|
|
||||||
m_interface->addVolumeGroup("FLOW");
|
|
||||||
}
|
|
||||||
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) {
|
|
||||||
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() {
|
|
||||||
m_interface->start();
|
|
||||||
usleep(1000000);
|
|
||||||
m_interface->setParameter("volume", "FLOW", "-3dB");
|
|
||||||
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
|
||||||
usleep(500000);
|
|
||||||
m_interface->setParameter("volume", "FLOW", "-6dB");
|
|
||||||
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
|
||||||
usleep(500000);
|
|
||||||
m_interface->setParameter("volume", "FLOW", "-9dB");
|
|
||||||
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
|
||||||
usleep(500000);
|
|
||||||
m_interface->setParameter("volume", "FLOW", "-12dB");
|
|
||||||
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
|
||||||
usleep(500000);
|
|
||||||
m_interface->setParameter("volume", "FLOW", "-3dB");
|
|
||||||
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
|
||||||
usleep(500000);
|
|
||||||
m_interface->setParameter("volume", "FLOW", "3dB");
|
|
||||||
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
|
||||||
usleep(500000);
|
|
||||||
m_interface->setParameter("volume", "FLOW", "6dB");
|
|
||||||
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
|
||||||
usleep(500000);
|
|
||||||
m_interface->setParameter("volume", "FLOW", "9dB");
|
|
||||||
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
|
||||||
usleep(500000);
|
|
||||||
m_interface->setParameter("volume", "FLOW", "0dB");
|
|
||||||
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
|
||||||
usleep(500000);
|
|
||||||
m_manager->setVolume("MASTER", -3.0f);
|
|
||||||
APPL_INFO("get volume MASTER: " << m_manager->getVolume("MASTER") );
|
|
||||||
usleep(500000);
|
|
||||||
m_manager->setVolume("MEDIA", -3.0f);
|
|
||||||
APPL_INFO("get volume MEDIA: " << m_manager->getVolume("MEDIA") );
|
|
||||||
usleep(1000000);
|
|
||||||
m_interface->stop();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void threadVolume() {
|
static void threadVolume() {
|
||||||
std11::shared_ptr<river::Manager> manager;
|
std11::shared_ptr<river::Manager> manager;
|
||||||
manager = river::Manager::create("testApplication");
|
manager = river::Manager::create("testApplication");
|
||||||
@ -630,55 +57,7 @@ TEST(TestALL, testInputCallBackMicClean) {
|
|||||||
usleep(500000);
|
usleep(500000);
|
||||||
tmpThread.join();
|
tmpThread.join();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
TEST(TestALL, testVolume) {
|
|
||||||
std11::shared_ptr<river::Manager> manager;
|
|
||||||
manager = river::Manager::create("testApplication");
|
|
||||||
std11::shared_ptr<testCallbackVolume> process = std11::make_shared<testCallbackVolume>(manager);
|
|
||||||
process->run();
|
|
||||||
process.reset();
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(TestALL, testChannelsFormatResampling) {
|
|
||||||
std11::shared_ptr<river::Manager> manager;
|
|
||||||
manager = river::Manager::create("testApplication");
|
|
||||||
APPL_INFO("test convert flaot to output (callback mode)");
|
|
||||||
std::vector<float> listFreq;
|
|
||||||
listFreq.push_back(4000);
|
|
||||||
listFreq.push_back(8000);
|
|
||||||
listFreq.push_back(16000);
|
|
||||||
listFreq.push_back(32000);
|
|
||||||
listFreq.push_back(48000);
|
|
||||||
listFreq.push_back(48001);
|
|
||||||
listFreq.push_back(64000);
|
|
||||||
listFreq.push_back(96000);
|
|
||||||
listFreq.push_back(11250);
|
|
||||||
listFreq.push_back(2250);
|
|
||||||
listFreq.push_back(44100);
|
|
||||||
listFreq.push_back(88200);
|
|
||||||
std::vector<int32_t> listChannel;
|
|
||||||
listChannel.push_back(1);
|
|
||||||
listChannel.push_back(2);
|
|
||||||
listChannel.push_back(4);
|
|
||||||
std::vector<audio::format> listFormat;
|
|
||||||
listFormat.push_back(audio::format_int16);
|
|
||||||
listFormat.push_back(audio::format_int16_on_int32);
|
|
||||||
listFormat.push_back(audio::format_int32);
|
|
||||||
listFormat.push_back(audio::format_float);
|
|
||||||
for (size_t fff=0; fff<listFreq.size(); ++fff) {
|
|
||||||
for (size_t ccc=0; ccc<listChannel.size(); ++ccc) {
|
|
||||||
for (size_t iii=0; iii<listFormat.size(); ++iii) {
|
|
||||||
APPL_INFO("freq=" << listFreq[fff] << " channel=" << listChannel[ccc] << " format=" << getFormatString(listFormat[iii]));
|
|
||||||
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, listFreq[fff], listChannel[ccc], listFormat[iii]);
|
|
||||||
process->run();
|
|
||||||
process.reset();
|
|
||||||
usleep(500000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
20
test/testAEC.h
Normal file
20
test/testAEC.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RIVER_TEST_AEC_H__
|
||||||
|
#define __RIVER_TEST_AEC_H__
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ "test_aec"
|
||||||
|
|
||||||
|
namespace river_test_aec {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ nullptr
|
||||||
|
|
||||||
|
#endif
|
129
test/testEchoDelay.h
Normal file
129
test/testEchoDelay.h
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RIVER_TEST_ECHO_DELAY_H__
|
||||||
|
#define __RIVER_TEST_ECHO_DELAY_H__
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ "test_echo_delay"
|
||||||
|
|
||||||
|
namespace river_test_echo_delay {
|
||||||
|
class TestClass {
|
||||||
|
private:
|
||||||
|
std11::shared_ptr<river::Manager> m_manager;
|
||||||
|
std11::shared_ptr<river::Interface> m_interfaceOut;
|
||||||
|
std11::shared_ptr<river::Interface> m_interfaceIn;
|
||||||
|
double m_phase;
|
||||||
|
std11::chrono::milliseconds m_delayBetweenEvent;
|
||||||
|
std11::chrono::system_clock::time_point m_nextTick;
|
||||||
|
public:
|
||||||
|
TestClass(std11::shared_ptr<river::Manager> _manager) :
|
||||||
|
m_manager(_manager),
|
||||||
|
m_phase(0),
|
||||||
|
m_delayBetweenEvent(2000000000LL) {
|
||||||
|
//Set stereo output:
|
||||||
|
std::vector<audio::channel> channelMap;
|
||||||
|
channelMap.push_back(audio::channel_frontLeft);
|
||||||
|
channelMap.push_back(audio::channel_frontRight);
|
||||||
|
m_interfaceOut = m_manager->createOutput(48000,
|
||||||
|
channelMap,
|
||||||
|
audio::format_int16,
|
||||||
|
"speaker",
|
||||||
|
"delayTestOut");
|
||||||
|
// set callback mode ...
|
||||||
|
m_interfaceOut->setOutputCallback(std11::bind(&TestClass::onDataNeeded,
|
||||||
|
this,
|
||||||
|
std11::placeholders::_1,
|
||||||
|
std11::placeholders::_2,
|
||||||
|
std11::placeholders::_3,
|
||||||
|
std11::placeholders::_4,
|
||||||
|
std11::placeholders::_5,
|
||||||
|
std11::placeholders::_6));
|
||||||
|
m_interfaceOut->addVolumeGroup("FLOW");
|
||||||
|
m_interfaceIn = m_manager->createInput(48000,
|
||||||
|
channelMap,
|
||||||
|
audio::format_int16,
|
||||||
|
"microphone",
|
||||||
|
"delayTestIn");
|
||||||
|
// set callback mode ...
|
||||||
|
m_interfaceIn->setOutputCallback(std11::bind(&TestClass::onDataReceived,
|
||||||
|
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) {
|
||||||
|
// TODO : Do it better ...
|
||||||
|
if (m_nextTick == std11::chrono::system_clock::time_point()) {
|
||||||
|
m_nextTick = _time + m_delayBetweenEvent;
|
||||||
|
}
|
||||||
|
if (m_nextTick < _time) {
|
||||||
|
m_nextTick += m_delayBetweenEvent;
|
||||||
|
m_phase = 0;
|
||||||
|
}
|
||||||
|
if (m_phase >= 0) {
|
||||||
|
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;
|
||||||
|
m_phase = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void onDataReceived(const 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)");
|
||||||
|
}
|
||||||
|
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());
|
||||||
|
APPL_INFO("Get data ... average=" << int32_t(value));
|
||||||
|
}
|
||||||
|
void run() {
|
||||||
|
m_interfaceOut->start();
|
||||||
|
m_interfaceIn->start();
|
||||||
|
usleep(30000000);
|
||||||
|
m_interfaceIn->stop();
|
||||||
|
m_interfaceOut->stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(TestTime, testDelay) {
|
||||||
|
std11::shared_ptr<river::Manager> manager;
|
||||||
|
manager = river::Manager::create("testApplication");
|
||||||
|
std11::shared_ptr<TestClass> process = std11::make_shared<TestClass>(manager);
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ nullptr
|
||||||
|
|
||||||
|
#endif
|
220
test/testFormat.h
Normal file
220
test/testFormat.h
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RIVER_TEST_FORMAT_H__
|
||||||
|
#define __RIVER_TEST_FORMAT_H__
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ "test_format"
|
||||||
|
|
||||||
|
namespace river_test_format {
|
||||||
|
class testOutCallbackType {
|
||||||
|
private:
|
||||||
|
std11::shared_ptr<river::Manager> m_manager;
|
||||||
|
std11::shared_ptr<river::Interface> m_interface;
|
||||||
|
double m_phase;
|
||||||
|
float m_freq;
|
||||||
|
int32_t m_nbChannels;
|
||||||
|
float m_generateFreq;
|
||||||
|
|
||||||
|
public:
|
||||||
|
testOutCallbackType(const std11::shared_ptr<river::Manager>& _manager,
|
||||||
|
float _freq=48000.0f,
|
||||||
|
int32_t _nbChannels=2,
|
||||||
|
audio::format _format=audio::format_int16) :
|
||||||
|
m_manager(_manager),
|
||||||
|
m_phase(0),
|
||||||
|
m_freq(_freq),
|
||||||
|
m_nbChannels(_nbChannels),
|
||||||
|
m_generateFreq(550.0f) {
|
||||||
|
//Set stereo output:
|
||||||
|
std::vector<audio::channel> channelMap;
|
||||||
|
if (m_nbChannels == 1) {
|
||||||
|
channelMap.push_back(audio::channel_frontCenter);
|
||||||
|
} else if (m_nbChannels == 2) {
|
||||||
|
channelMap.push_back(audio::channel_frontLeft);
|
||||||
|
channelMap.push_back(audio::channel_frontRight);
|
||||||
|
} else if (m_nbChannels == 4) {
|
||||||
|
channelMap.push_back(audio::channel_frontLeft);
|
||||||
|
channelMap.push_back(audio::channel_frontRight);
|
||||||
|
channelMap.push_back(audio::channel_rearLeft);
|
||||||
|
channelMap.push_back(audio::channel_rearRight);
|
||||||
|
} else {
|
||||||
|
APPL_ERROR("Can not generate with channel != 1,2,4");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_interface = m_manager->createOutput(m_freq,
|
||||||
|
channelMap,
|
||||||
|
_format,
|
||||||
|
"speaker",
|
||||||
|
"WriteModeCallbackType");
|
||||||
|
// set callback mode ...
|
||||||
|
m_interface->setOutputCallback(std11::bind(&testOutCallbackType::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) {
|
||||||
|
//APPL_DEBUG("Get data ... " << _format << " map=" << _map << " chunk=" << _nbChunk);
|
||||||
|
double baseCycle = 2.0*M_PI/double(m_freq) * double(m_generateFreq);
|
||||||
|
if (_format == audio::format_int16) {
|
||||||
|
int16_t* data = static_cast<int16_t*>(_data);
|
||||||
|
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) * double(INT16_MAX);
|
||||||
|
}
|
||||||
|
m_phase += baseCycle;
|
||||||
|
if (m_phase >= 2*M_PI) {
|
||||||
|
m_phase -= 2*M_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (_format == audio::format_int16_on_int32) {
|
||||||
|
int32_t* data = static_cast<int32_t*>(_data);
|
||||||
|
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) * double(INT16_MAX);
|
||||||
|
}
|
||||||
|
m_phase += baseCycle;
|
||||||
|
if (m_phase >= 2*M_PI) {
|
||||||
|
m_phase -= 2*M_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (_format == audio::format_int32) {
|
||||||
|
int32_t* data = static_cast<int32_t*>(_data);
|
||||||
|
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) * double(INT32_MAX);
|
||||||
|
}
|
||||||
|
m_phase += baseCycle;
|
||||||
|
if (m_phase >= 2*M_PI) {
|
||||||
|
m_phase -= 2*M_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (_format == audio::format_float) {
|
||||||
|
float* data = static_cast<float*>(_data);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
m_phase += baseCycle;
|
||||||
|
if (m_phase >= 2*M_PI) {
|
||||||
|
m_phase -= 2*M_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void run() {
|
||||||
|
if (m_interface != nullptr) {
|
||||||
|
m_interface->start();
|
||||||
|
// wait 2 second ...
|
||||||
|
usleep(1000000);
|
||||||
|
m_interface->stop();
|
||||||
|
usleep(100000);
|
||||||
|
} else {
|
||||||
|
APPL_ERROR("Can not create interface !!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class testResampling : public ::testing::TestWithParam<float> {};
|
||||||
|
TEST_P(testResampling, base) {
|
||||||
|
std11::shared_ptr<river::Manager> manager;
|
||||||
|
manager = river::Manager::create("testApplication");
|
||||||
|
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, GetParam(), 2, audio::format_int16);
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
||||||
|
testResampling,
|
||||||
|
::testing::Values(4000, 8000, 16000, 32000, 48000, 48001, 64000, 96000, 11250, 2250, 44100, 88200));
|
||||||
|
|
||||||
|
|
||||||
|
class testFormat : public ::testing::TestWithParam<audio::format> {};
|
||||||
|
TEST_P(testFormat, base) {
|
||||||
|
std11::shared_ptr<river::Manager> manager;
|
||||||
|
manager = river::Manager::create("testApplication");
|
||||||
|
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, 48000, 2, GetParam());
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
||||||
|
testFormat,
|
||||||
|
::testing::Values(audio::format_int16, audio::format_int16_on_int32, audio::format_int32, audio::format_float));
|
||||||
|
|
||||||
|
|
||||||
|
class testChannels : public ::testing::TestWithParam<int32_t> {};
|
||||||
|
TEST_P(testChannels, base) {
|
||||||
|
std11::shared_ptr<river::Manager> manager;
|
||||||
|
manager = river::Manager::create("testApplication");
|
||||||
|
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, 48000, GetParam(), audio::format_int16);
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
||||||
|
testChannels,
|
||||||
|
::testing::Values(1,2,4));
|
||||||
|
|
||||||
|
|
||||||
|
TEST(TestALL, testChannelsFormatResampling) {
|
||||||
|
std11::shared_ptr<river::Manager> manager;
|
||||||
|
manager = river::Manager::create("testApplication");
|
||||||
|
APPL_INFO("test convert flaot to output (callback mode)");
|
||||||
|
std::vector<float> listFreq;
|
||||||
|
listFreq.push_back(4000);
|
||||||
|
listFreq.push_back(8000);
|
||||||
|
listFreq.push_back(16000);
|
||||||
|
listFreq.push_back(32000);
|
||||||
|
listFreq.push_back(48000);
|
||||||
|
listFreq.push_back(48001);
|
||||||
|
listFreq.push_back(64000);
|
||||||
|
listFreq.push_back(96000);
|
||||||
|
listFreq.push_back(11250);
|
||||||
|
listFreq.push_back(2250);
|
||||||
|
listFreq.push_back(44100);
|
||||||
|
listFreq.push_back(88200);
|
||||||
|
std::vector<int32_t> listChannel;
|
||||||
|
listChannel.push_back(1);
|
||||||
|
listChannel.push_back(2);
|
||||||
|
listChannel.push_back(4);
|
||||||
|
std::vector<audio::format> listFormat;
|
||||||
|
listFormat.push_back(audio::format_int16);
|
||||||
|
listFormat.push_back(audio::format_int16_on_int32);
|
||||||
|
listFormat.push_back(audio::format_int32);
|
||||||
|
listFormat.push_back(audio::format_float);
|
||||||
|
for (size_t fff=0; fff<listFreq.size(); ++fff) {
|
||||||
|
for (size_t ccc=0; ccc<listChannel.size(); ++ccc) {
|
||||||
|
for (size_t iii=0; iii<listFormat.size(); ++iii) {
|
||||||
|
APPL_INFO("freq=" << listFreq[fff] << " channel=" << listChannel[ccc] << " format=" << getFormatString(listFormat[iii]));
|
||||||
|
std11::shared_ptr<testOutCallbackType> process = std11::make_shared<testOutCallbackType>(manager, listFreq[fff], listChannel[ccc], listFormat[iii]);
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ nullptr
|
||||||
|
|
||||||
|
#endif
|
20
test/testMuxer.h
Normal file
20
test/testMuxer.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RIVER_TEST_MUXER_H__
|
||||||
|
#define __RIVER_TEST_MUXER_H__
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ "test_muxer"
|
||||||
|
|
||||||
|
namespace river_test_muxer {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ nullptr
|
||||||
|
|
||||||
|
#endif
|
111
test/testPlaybackCallback.h
Normal file
111
test/testPlaybackCallback.h
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
/** @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 {
|
||||||
|
private:
|
||||||
|
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,
|
||||||
|
_io,
|
||||||
|
"WriteModeCallback");
|
||||||
|
// 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() {
|
||||||
|
m_interface->start();
|
||||||
|
// wait 2 second ...
|
||||||
|
usleep(2000000);
|
||||||
|
m_interface->stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(TestALL, testOutputCallBack) {
|
||||||
|
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");
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TestALL, testOutputCallBackPulse) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TestALL, testOutputCallBackJack) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ nullptr
|
||||||
|
|
||||||
|
#endif
|
153
test/testPlaybackWrite.h
Normal file
153
test/testPlaybackWrite.h
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RIVER_TEST_PLAYBACK_WRITE_H__
|
||||||
|
#define __RIVER_TEST_PLAYBACK_WRITE_H__
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ "test_playback_write"
|
||||||
|
|
||||||
|
namespace river_test_playback_write {
|
||||||
|
class testOutWrite {
|
||||||
|
private:
|
||||||
|
std::vector<audio::channel> m_channelMap;
|
||||||
|
std11::shared_ptr<river::Manager> m_manager;
|
||||||
|
std11::shared_ptr<river::Interface> m_interface;
|
||||||
|
public:
|
||||||
|
testOutWrite(std11::shared_ptr<river::Manager> _manager) :
|
||||||
|
m_manager(_manager) {
|
||||||
|
//Set stereo output:
|
||||||
|
m_channelMap.push_back(audio::channel_frontLeft);
|
||||||
|
m_channelMap.push_back(audio::channel_frontRight);
|
||||||
|
m_interface = m_manager->createOutput(48000,
|
||||||
|
m_channelMap,
|
||||||
|
audio::format_int16,
|
||||||
|
"speaker",
|
||||||
|
"WriteMode");
|
||||||
|
m_interface->setReadwrite();
|
||||||
|
}
|
||||||
|
void run() {
|
||||||
|
double phase=0;
|
||||||
|
std::vector<int16_t> data;
|
||||||
|
data.resize(1024*m_channelMap.size());
|
||||||
|
double baseCycle = 2.0*M_PI/48000.0 * 440.0;
|
||||||
|
// start fill buffer
|
||||||
|
for (int32_t kkk=0; kkk<10; ++kkk) {
|
||||||
|
for (int32_t iii=0; iii<data.size()/m_channelMap.size(); iii++) {
|
||||||
|
for (int32_t jjj=0; jjj<m_channelMap.size(); jjj++) {
|
||||||
|
data[m_channelMap.size()*iii+jjj] = cos(phase) * 30000.0;
|
||||||
|
}
|
||||||
|
phase += baseCycle;
|
||||||
|
if (phase >= 2*M_PI) {
|
||||||
|
phase -= 2*M_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_interface->write(&data[0], data.size()/m_channelMap.size());
|
||||||
|
}
|
||||||
|
m_interface->start();
|
||||||
|
for (int32_t kkk=0; kkk<100; ++kkk) {
|
||||||
|
for (int32_t iii=0; iii<data.size()/m_channelMap.size(); iii++) {
|
||||||
|
for (int32_t jjj=0; jjj<m_channelMap.size(); jjj++) {
|
||||||
|
data[m_channelMap.size()*iii+jjj] = cos(phase) * 30000.0;
|
||||||
|
}
|
||||||
|
phase += baseCycle;
|
||||||
|
if (phase >= 2*M_PI) {
|
||||||
|
phase -= 2*M_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_interface->write(&data[0], data.size()/m_channelMap.size());
|
||||||
|
// TODO : Add a function to get number of time we need to wait enought time ...
|
||||||
|
usleep(15000);
|
||||||
|
}
|
||||||
|
m_interface->stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(TestALL, testOutputWrite) {
|
||||||
|
std11::shared_ptr<river::Manager> manager;
|
||||||
|
manager = river::Manager::create("testApplication");
|
||||||
|
|
||||||
|
APPL_INFO("test output (write mode)");
|
||||||
|
std11::shared_ptr<testOutWrite> process = std11::make_shared<testOutWrite>(manager);
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
class testOutWriteCallback {
|
||||||
|
private:
|
||||||
|
std11::shared_ptr<river::Manager> m_manager;
|
||||||
|
std11::shared_ptr<river::Interface> m_interface;
|
||||||
|
double m_phase;
|
||||||
|
public:
|
||||||
|
testOutWriteCallback(std11::shared_ptr<river::Manager> _manager) :
|
||||||
|
m_manager(_manager),
|
||||||
|
m_phase(0) {
|
||||||
|
std::vector<audio::channel> channelMap;
|
||||||
|
//Set stereo output:
|
||||||
|
channelMap.push_back(audio::channel_frontLeft);
|
||||||
|
channelMap.push_back(audio::channel_frontRight);
|
||||||
|
m_interface = m_manager->createOutput(48000,
|
||||||
|
channelMap,
|
||||||
|
audio::format_int16,
|
||||||
|
"speaker",
|
||||||
|
"WriteMode+Callback");
|
||||||
|
m_interface->setReadwrite();
|
||||||
|
m_interface->setWriteCallback(std11::bind(&testOutWriteCallback::onDataNeeded,
|
||||||
|
this,
|
||||||
|
std11::placeholders::_1,
|
||||||
|
std11::placeholders::_2,
|
||||||
|
std11::placeholders::_3,
|
||||||
|
std11::placeholders::_4,
|
||||||
|
std11::placeholders::_5));
|
||||||
|
}
|
||||||
|
void onDataNeeded(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)");
|
||||||
|
}
|
||||||
|
std::vector<int16_t> data;
|
||||||
|
data.resize(1024*_map.size());
|
||||||
|
double baseCycle = 2.0*M_PI/48000.0 * 440.0;
|
||||||
|
// start fill buffer
|
||||||
|
for (int32_t iii=0; iii<data.size()/_map.size(); iii++) {
|
||||||
|
for (int32_t jjj=0; jjj<_map.size(); jjj++) {
|
||||||
|
data[_map.size()*iii+jjj] = cos(m_phase) * 30000.0;
|
||||||
|
}
|
||||||
|
m_phase += baseCycle;
|
||||||
|
if (m_phase >= 2*M_PI) {
|
||||||
|
m_phase -= 2*M_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_interface->write(&data[0], data.size()/_map.size());
|
||||||
|
}
|
||||||
|
void run() {
|
||||||
|
m_interface->start();
|
||||||
|
usleep(1000000);
|
||||||
|
m_interface->stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(TestALL, testOutputWriteWithCallback) {
|
||||||
|
std11::shared_ptr<river::Manager> manager;
|
||||||
|
manager = river::Manager::create("testApplication");
|
||||||
|
|
||||||
|
APPL_INFO("test output (write with callback event mode)");
|
||||||
|
std11::shared_ptr<testOutWriteCallback> process = std11::make_shared<testOutWriteCallback>(manager);
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ nullptr
|
||||||
|
|
||||||
|
#endif
|
84
test/testRecordCallback.h
Normal file
84
test/testRecordCallback.h
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RIVER_TEST_RECORD_CALLBACK_H__
|
||||||
|
#define __RIVER_TEST_RECORD_CALLBACK_H__
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ "test_record_callback"
|
||||||
|
|
||||||
|
namespace river_test_record_callback {
|
||||||
|
class testInCallback {
|
||||||
|
private:
|
||||||
|
std11::shared_ptr<river::Manager> m_manager;
|
||||||
|
std11::shared_ptr<river::Interface> m_interface;
|
||||||
|
double m_phase;
|
||||||
|
public:
|
||||||
|
testInCallback(std11::shared_ptr<river::Manager> _manager, const std::string& _input="microphone") :
|
||||||
|
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->createInput(48000,
|
||||||
|
channelMap,
|
||||||
|
audio::format_int16,
|
||||||
|
_input,
|
||||||
|
"WriteModeCallback");
|
||||||
|
// set callback mode ...
|
||||||
|
m_interface->setInputCallback(std11::bind(&testInCallback::onDataReceived,
|
||||||
|
this,
|
||||||
|
std11::placeholders::_1,
|
||||||
|
std11::placeholders::_2,
|
||||||
|
std11::placeholders::_3,
|
||||||
|
std11::placeholders::_4,
|
||||||
|
std11::placeholders::_5,
|
||||||
|
std11::placeholders::_6));
|
||||||
|
}
|
||||||
|
void onDataReceived(const 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)");
|
||||||
|
}
|
||||||
|
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());
|
||||||
|
APPL_INFO("Get data ... average=" << int32_t(value));
|
||||||
|
}
|
||||||
|
void run() {
|
||||||
|
m_interface->start();
|
||||||
|
// wait 2 second ...
|
||||||
|
usleep(2000000);
|
||||||
|
|
||||||
|
m_manager->generateDotAll("activeProcess.dot");
|
||||||
|
m_interface->stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(TestALL, testInputCallBack) {
|
||||||
|
std11::shared_ptr<river::Manager> manager;
|
||||||
|
manager = river::Manager::create("testApplication");
|
||||||
|
APPL_INFO("test input (callback mode)");
|
||||||
|
std11::shared_ptr<testInCallback> process = std11::make_shared<testInCallback>(manager);
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ nullptr
|
||||||
|
|
||||||
|
#endif
|
20
test/testRecordRead.h
Normal file
20
test/testRecordRead.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RIVER_TEST_RECORD_READ_H__
|
||||||
|
#define __RIVER_TEST_RECORD_READ_H__
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ "test_record_read"
|
||||||
|
|
||||||
|
namespace river_test_record_read {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ nullptr
|
||||||
|
|
||||||
|
#endif
|
117
test/testVolume.h
Normal file
117
test/testVolume.h
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||||
|
* @license APACHE v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RIVER_TEST_VOLUME_H__
|
||||||
|
#define __RIVER_TEST_VOLUME_H__
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ "test_volume"
|
||||||
|
|
||||||
|
namespace river_test_volume {
|
||||||
|
|
||||||
|
class testCallbackVolume {
|
||||||
|
private:
|
||||||
|
std11::shared_ptr<river::Manager> m_manager;
|
||||||
|
std11::shared_ptr<river::Interface> m_interface;
|
||||||
|
double m_phase;
|
||||||
|
public:
|
||||||
|
testCallbackVolume(std11::shared_ptr<river::Manager> _manager) :
|
||||||
|
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,
|
||||||
|
"speaker",
|
||||||
|
"WriteModeCallback");
|
||||||
|
// set callback mode ...
|
||||||
|
m_interface->setOutputCallback(std11::bind(&testCallbackVolume::onDataNeeded,
|
||||||
|
this,
|
||||||
|
std11::placeholders::_1,
|
||||||
|
std11::placeholders::_2,
|
||||||
|
std11::placeholders::_3,
|
||||||
|
std11::placeholders::_4,
|
||||||
|
std11::placeholders::_5,
|
||||||
|
std11::placeholders::_6));
|
||||||
|
m_interface->addVolumeGroup("MEDIA");
|
||||||
|
m_interface->addVolumeGroup("FLOW");
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
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() {
|
||||||
|
m_interface->start();
|
||||||
|
usleep(1000000);
|
||||||
|
m_interface->setParameter("volume", "FLOW", "-3dB");
|
||||||
|
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
||||||
|
usleep(500000);
|
||||||
|
m_interface->setParameter("volume", "FLOW", "-6dB");
|
||||||
|
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
||||||
|
usleep(500000);
|
||||||
|
m_interface->setParameter("volume", "FLOW", "-9dB");
|
||||||
|
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
||||||
|
usleep(500000);
|
||||||
|
m_interface->setParameter("volume", "FLOW", "-12dB");
|
||||||
|
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
||||||
|
usleep(500000);
|
||||||
|
m_interface->setParameter("volume", "FLOW", "-3dB");
|
||||||
|
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
||||||
|
usleep(500000);
|
||||||
|
m_interface->setParameter("volume", "FLOW", "3dB");
|
||||||
|
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
||||||
|
usleep(500000);
|
||||||
|
m_interface->setParameter("volume", "FLOW", "6dB");
|
||||||
|
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
||||||
|
usleep(500000);
|
||||||
|
m_interface->setParameter("volume", "FLOW", "9dB");
|
||||||
|
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
||||||
|
usleep(500000);
|
||||||
|
m_interface->setParameter("volume", "FLOW", "0dB");
|
||||||
|
APPL_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
|
||||||
|
usleep(500000);
|
||||||
|
m_manager->setVolume("MASTER", -3.0f);
|
||||||
|
APPL_INFO("get volume MASTER: " << m_manager->getVolume("MASTER") );
|
||||||
|
usleep(500000);
|
||||||
|
m_manager->setVolume("MEDIA", -3.0f);
|
||||||
|
APPL_INFO("get volume MEDIA: " << m_manager->getVolume("MEDIA") );
|
||||||
|
usleep(1000000);
|
||||||
|
m_interface->stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(TestALL, testVolume) {
|
||||||
|
std11::shared_ptr<river::Manager> manager;
|
||||||
|
manager = river::Manager::create("testApplication");
|
||||||
|
std11::shared_ptr<testCallbackVolume> process = std11::make_shared<testCallbackVolume>(manager);
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#undef __class__
|
||||||
|
#define __class__ nullptr
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user