From 2bc30c551762bc54a692de0c6ea828576f367c9d Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 27 Jan 2015 22:47:09 +0100 Subject: [PATCH] [DEV] test added --- airtio/Interface.cpp | 8 +++++ airtio/Interface.h | 3 +- test/main.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/airtio/Interface.cpp b/airtio/Interface.cpp index 0427e4c..27cd082 100644 --- a/airtio/Interface.cpp +++ b/airtio/Interface.cpp @@ -142,6 +142,14 @@ void airtio::Interface::setInputCallback(size_t _chunkSize, airtalgo::haveNewDat m_process->pushBack(algo); } +void airtio::Interface::setWriteCallback(airtalgo::needDataFunctionWrite _function) { + std::unique_lock lock(m_mutex); + std::shared_ptr algo = m_process->get(0); + if (algo == nullptr) { + return; + } + algo->setCallback(_function); +} void airtio::Interface::start(const std::chrono::system_clock::time_point& _time) { std::unique_lock lock(m_mutex); diff --git a/airtio/Interface.h b/airtio/Interface.h index ed4bd9a..bed99cb 100644 --- a/airtio/Interface.h +++ b/airtio/Interface.h @@ -17,6 +17,7 @@ #include #include #include +#include #include namespace airtio { @@ -64,7 +65,7 @@ namespace airtio { /** * @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 setInputCallback(size_t _chunkSize, airtalgo::haveNewDataFunction _function); public: diff --git a/test/main.cpp b/test/main.cpp index 5bb5585..e448727 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -34,11 +34,24 @@ class testOutWrite { "WriteMode"); } void run() { - m_interface->start(); double phase=0; std::vector 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= 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 manager; manager = airtio::Manager::create("testApplication"); - APPL_INFO("test output (callback mode)"); + APPL_INFO("test output (write mode)"); std::shared_ptr process = std::make_shared(manager); process->run(); process.reset(); @@ -69,6 +82,72 @@ TEST(TestALL, testOutputWrite) { } +class testOutWriteCallback { + private: + std::shared_ptr m_manager; + std::shared_ptr m_interface; + double m_phase; + public: + testOutWriteCallback(std::shared_ptr _manager) : + m_manager(_manager), + m_phase(0) { + std::vector 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& _map, + enum airtalgo::format _type) { + if (_type != airtalgo::format_int16) { + APPL_ERROR("call wrong type ... (need int16_t)"); + } + std::vector 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= 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 manager; + manager = airtio::Manager::create("testApplication"); + + APPL_INFO("test output (write with callback event mode)"); + std::shared_ptr process = std::make_shared(manager); + process->run(); + process.reset(); + usleep(500000); +} + + class testOutCallback { private: std::shared_ptr m_manager;