[DEV] test added
This commit is contained in:
parent
cf167d3c5f
commit
2bc30c5517
@ -142,6 +142,14 @@ void airtio::Interface::setInputCallback(size_t _chunkSize, airtalgo::haveNewDat
|
|||||||
m_process->pushBack(algo);
|
m_process->pushBack(algo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void airtio::Interface::setWriteCallback(airtalgo::needDataFunctionWrite _function) {
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
std::shared_ptr<airtalgo::EndPointWrite> algo = m_process->get<airtalgo::EndPointWrite>(0);
|
||||||
|
if (algo == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
algo->setCallback(_function);
|
||||||
|
}
|
||||||
|
|
||||||
void airtio::Interface::start(const std::chrono::system_clock::time_point& _time) {
|
void airtio::Interface::start(const std::chrono::system_clock::time_point& _time) {
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <airtalgo/channel.h>
|
#include <airtalgo/channel.h>
|
||||||
#include <airtalgo/Process.h>
|
#include <airtalgo/Process.h>
|
||||||
#include <airtalgo/EndPointCallback.h>
|
#include <airtalgo/EndPointCallback.h>
|
||||||
|
#include <airtalgo/EndPointWrite.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace airtio {
|
namespace airtio {
|
||||||
@ -64,7 +65,7 @@ namespace airtio {
|
|||||||
/**
|
/**
|
||||||
* @brief When we want to implement a Callback Mode :
|
* @brief When we want to implement a Callback Mode :
|
||||||
*/
|
*/
|
||||||
//virtual void setWriteCallback(size_t _chunkSize, writeNeedDataFunction_int16_t _function) {};
|
virtual void setWriteCallback(airtalgo::needDataFunctionWrite _function);
|
||||||
virtual void setOutputCallback(size_t _chunkSize, airtalgo::needDataFunction _function);
|
virtual void setOutputCallback(size_t _chunkSize, airtalgo::needDataFunction _function);
|
||||||
virtual void setInputCallback(size_t _chunkSize, airtalgo::haveNewDataFunction _function);
|
virtual void setInputCallback(size_t _chunkSize, airtalgo::haveNewDataFunction _function);
|
||||||
public:
|
public:
|
||||||
|
@ -34,11 +34,24 @@ class testOutWrite {
|
|||||||
"WriteMode");
|
"WriteMode");
|
||||||
}
|
}
|
||||||
void run() {
|
void run() {
|
||||||
m_interface->start();
|
|
||||||
double phase=0;
|
double phase=0;
|
||||||
std::vector<int16_t> data;
|
std::vector<int16_t> data;
|
||||||
data.resize(1024*m_channelMap.size());
|
data.resize(1024*m_channelMap.size());
|
||||||
double baseCycle = 2.0*M_PI/48000.0 * 440.0;
|
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 kkk=0; kkk<100; ++kkk) {
|
||||||
for (int32_t iii=0; iii<data.size()/m_channelMap.size(); iii++) {
|
for (int32_t iii=0; iii<data.size()/m_channelMap.size(); iii++) {
|
||||||
for (int32_t jjj=0; jjj<m_channelMap.size(); jjj++) {
|
for (int32_t jjj=0; jjj<m_channelMap.size(); jjj++) {
|
||||||
@ -61,7 +74,7 @@ TEST(TestALL, testOutputWrite) {
|
|||||||
std::shared_ptr<airtio::Manager> manager;
|
std::shared_ptr<airtio::Manager> manager;
|
||||||
manager = airtio::Manager::create("testApplication");
|
manager = airtio::Manager::create("testApplication");
|
||||||
|
|
||||||
APPL_INFO("test output (callback mode)");
|
APPL_INFO("test output (write mode)");
|
||||||
std::shared_ptr<testOutWrite> process = std::make_shared<testOutWrite>(manager);
|
std::shared_ptr<testOutWrite> process = std::make_shared<testOutWrite>(manager);
|
||||||
process->run();
|
process->run();
|
||||||
process.reset();
|
process.reset();
|
||||||
@ -69,6 +82,72 @@ TEST(TestALL, testOutputWrite) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class testOutWriteCallback {
|
||||||
|
private:
|
||||||
|
std::shared_ptr<airtio::Manager> m_manager;
|
||||||
|
std::shared_ptr<airtio::Interface> m_interface;
|
||||||
|
double m_phase;
|
||||||
|
public:
|
||||||
|
testOutWriteCallback(std::shared_ptr<airtio::Manager> _manager) :
|
||||||
|
m_manager(_manager),
|
||||||
|
m_phase(0) {
|
||||||
|
std::vector<airtalgo::channel> channelMap;
|
||||||
|
//Set stereo output:
|
||||||
|
channelMap.push_back(airtalgo::channel_frontLeft);
|
||||||
|
channelMap.push_back(airtalgo::channel_frontRight);
|
||||||
|
m_interface = m_manager->createOutput(48000,
|
||||||
|
channelMap,
|
||||||
|
airtalgo::format_int16,
|
||||||
|
"default",
|
||||||
|
"WriteMode+Callback");
|
||||||
|
m_interface->setWriteCallback(std::bind(&testOutWriteCallback::onDataNeeded,
|
||||||
|
this,
|
||||||
|
std::placeholders::_1,
|
||||||
|
std::placeholders::_2,
|
||||||
|
std::placeholders::_3,
|
||||||
|
std::placeholders::_4));
|
||||||
|
}
|
||||||
|
void onDataNeeded(const std::chrono::system_clock::time_point& _playTime,
|
||||||
|
const size_t& _nbChunk,
|
||||||
|
const std::vector<airtalgo::channel>& _map,
|
||||||
|
enum airtalgo::format _type) {
|
||||||
|
if (_type != airtalgo::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) {
|
||||||
|
std::shared_ptr<airtio::Manager> manager;
|
||||||
|
manager = airtio::Manager::create("testApplication");
|
||||||
|
|
||||||
|
APPL_INFO("test output (write with callback event mode)");
|
||||||
|
std::shared_ptr<testOutWriteCallback> process = std::make_shared<testOutWriteCallback>(manager);
|
||||||
|
process->run();
|
||||||
|
process.reset();
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class testOutCallback {
|
class testOutCallback {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<airtio::Manager> m_manager;
|
std::shared_ptr<airtio::Manager> m_manager;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user