From 5d7c9203efa6d47ce0705f59195f569fafbd3e23 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 3 Mar 2015 23:17:43 +0100 Subject: [PATCH] [DEV] rework test --- river/io/NodePortAudio.cpp | 8 - test/main.cpp | 645 +----------------------------------- test/testAEC.h | 20 ++ test/testEchoDelay.h | 129 ++++++++ test/testFormat.h | 220 ++++++++++++ test/testMuxer.h | 20 ++ test/testPlaybackCallback.h | 111 +++++++ test/testPlaybackWrite.h | 153 +++++++++ test/testRecordCallback.h | 84 +++++ test/testRecordRead.h | 20 ++ test/testVolume.h | 117 +++++++ 11 files changed, 886 insertions(+), 641 deletions(-) create mode 100644 test/testAEC.h create mode 100644 test/testEchoDelay.h create mode 100644 test/testFormat.h create mode 100644 test/testMuxer.h create mode 100644 test/testPlaybackCallback.h create mode 100644 test/testPlaybackWrite.h create mode 100644 test/testRecordCallback.h create mode 100644 test/testRecordRead.h create mode 100644 test/testVolume.h diff --git a/river/io/NodePortAudio.cpp b/river/io/NodePortAudio.cpp index fb35812..cad9dbf 100644 --- a/river/io/NodePortAudio.cpp +++ b/river/io/NodePortAudio.cpp @@ -23,14 +23,6 @@ static std::string asString(const std11::chrono::system_clock::time_point& tp) { 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(_obj.time_since_epoch()); - _os << us.count(); - return _os; - } -} - static int portAudioStreamCallback(const void *_input, void *_output, unsigned long _frameCount, diff --git a/test/main.cpp b/test/main.cpp index 2bd6280..c32eaf3 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -13,598 +13,25 @@ #include #include #include +#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__ #define __class__ "test" -class testOutWrite { - private: - std::vector m_channelMap; - std11::shared_ptr m_manager; - std11::shared_ptr m_interface; - public: - testOutWrite(std11::shared_ptr _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 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= 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 manager; - manager = river::Manager::create("testApplication"); - - APPL_INFO("test output (write mode)"); - std11::shared_ptr process = std11::make_shared(manager); - process->run(); - process.reset(); - usleep(500000); -} - -class testOutWriteCallback { - private: - std11::shared_ptr m_manager; - std11::shared_ptr m_interface; - double m_phase; - public: - testOutWriteCallback(std11::shared_ptr _manager) : - m_manager(_manager), - m_phase(0) { - std::vector 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& _map) { - if (_format != audio::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) { - std11::shared_ptr manager; - manager = river::Manager::create("testApplication"); - - APPL_INFO("test output (write with callback event mode)"); - std11::shared_ptr process = std11::make_shared(manager); - process->run(); - process.reset(); - usleep(500000); -} - - -class testOutCallback { - private: - std11::shared_ptr m_manager; - std11::shared_ptr m_interface; - double m_phase; - public: - testOutCallback(std11::shared_ptr _manager, const std::string& _io="speaker") : - m_manager(_manager), - m_phase(0) { - //Set stereo output: - std::vector 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& _map) { - if (_format != audio::format_int16) { - APPL_ERROR("call wrong type ... (need int16_t)"); - } - int16_t* data = static_cast(_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 manager; - manager = river::Manager::create("testApplication"); - - APPL_INFO("test output (callback mode)"); - std11::shared_ptr process = std11::make_shared(manager, "speaker"); - process->run(); - process.reset(); - usleep(500000); -} - -TEST(TestALL, testOutputCallBackPulse) { - std11::shared_ptr manager; - manager = river::Manager::create("testApplication"); - - APPL_INFO("test output (callback mode)"); - std11::shared_ptr process = std11::make_shared(manager, "speaker-pulse"); - process->run(); - process.reset(); - usleep(500000); -} - -TEST(TestALL, testOutputCallBackJack) { - std11::shared_ptr manager; - manager = river::Manager::create("testApplication"); - - APPL_INFO("test output (callback mode)"); - std11::shared_ptr process = std11::make_shared(manager, "speaker-jack"); - process->run(); - process.reset(); - usleep(500000); -} - -/* -class testInRead { - private: - std::vector m_channelMap; - std11::shared_ptr m_manager; - std11::shared_ptr m_interface; - public: - testInRead(std11::shared_ptr _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 data; - for (int32_t kkk=0; kkk<100; ++kkk) { - data = m_interface->read(1024); - int64_t value = 0; - for (size_t iii=0; iii process = std11::make_shared(manager); - process->run(); - process.reset(); - usleep(500000); -} -*/ - -class testInCallback { - private: - std11::shared_ptr m_manager; - std11::shared_ptr m_interface; - double m_phase; - public: - testInCallback(std11::shared_ptr _manager, const std::string& _input="microphone") : - m_manager(_manager), - m_phase(0) { - //Set stereo output: - std::vector 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& _map) { - if (_format != audio::format_int16) { - APPL_ERROR("call wrong type ... (need int16_t)"); - } - const int16_t* data = static_cast(_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 manager; - manager = river::Manager::create("testApplication"); - APPL_INFO("test input (callback mode)"); - std11::shared_ptr process = std11::make_shared(manager); - process->run(); - process.reset(); - usleep(500000); -} -class testOutCallbackType { - private: - std11::shared_ptr m_manager; - std11::shared_ptr m_interface; - double m_phase; - float m_freq; - int32_t m_nbChannels; - float m_generateFreq; - - public: - testOutCallbackType(const std11::shared_ptr& _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 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& _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(_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(_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(_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(_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 {}; -TEST_P(testResampling, base) { - std11::shared_ptr manager; - manager = river::Manager::create("testApplication"); - std11::shared_ptr process = std11::make_shared(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 {}; -TEST_P(testFormat, base) { - std11::shared_ptr manager; - manager = river::Manager::create("testApplication"); - std11::shared_ptr process = std11::make_shared(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 {}; -TEST_P(testChannels, base) { - std11::shared_ptr manager; - manager = river::Manager::create("testApplication"); - std11::shared_ptr process = std11::make_shared(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 m_manager; - std11::shared_ptr m_interface; - double m_phase; - public: - testCallbackVolume(std11::shared_ptr _manager) : - m_manager(_manager), - m_phase(0) { - //Set stereo output: - std::vector 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& _map) { - int16_t* data = static_cast(_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() { std11::shared_ptr manager; manager = river::Manager::create("testApplication"); @@ -630,55 +57,7 @@ TEST(TestALL, testInputCallBackMicClean) { usleep(500000); tmpThread.join(); } - - -TEST(TestALL, testVolume) { - std11::shared_ptr manager; - manager = river::Manager::create("testApplication"); - std11::shared_ptr process = std11::make_shared(manager); - process->run(); - process.reset(); - usleep(500000); -} - -TEST(TestALL, testChannelsFormatResampling) { - std11::shared_ptr manager; - manager = river::Manager::create("testApplication"); - APPL_INFO("test convert flaot to output (callback mode)"); - std::vector 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 listChannel; - listChannel.push_back(1); - listChannel.push_back(2); - listChannel.push_back(4); - std::vector 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 m_manager; + std11::shared_ptr m_interfaceOut; + std11::shared_ptr m_interfaceIn; + double m_phase; + std11::chrono::milliseconds m_delayBetweenEvent; + std11::chrono::system_clock::time_point m_nextTick; + public: + TestClass(std11::shared_ptr _manager) : + m_manager(_manager), + m_phase(0), + m_delayBetweenEvent(2000000000LL) { + //Set stereo output: + std::vector 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& _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(_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& _map) { + if (_format != audio::format_int16) { + APPL_ERROR("call wrong type ... (need int16_t)"); + } + const int16_t* data = static_cast(_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 manager; + manager = river::Manager::create("testApplication"); + std11::shared_ptr process = std11::make_shared(manager); + process->run(); + process.reset(); + usleep(500000); + } +}; + +#undef __class__ +#define __class__ nullptr + +#endif diff --git a/test/testFormat.h b/test/testFormat.h new file mode 100644 index 0000000..ef953dc --- /dev/null +++ b/test/testFormat.h @@ -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 m_manager; + std11::shared_ptr m_interface; + double m_phase; + float m_freq; + int32_t m_nbChannels; + float m_generateFreq; + + public: + testOutCallbackType(const std11::shared_ptr& _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 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& _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(_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(_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(_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(_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 {}; + TEST_P(testResampling, base) { + std11::shared_ptr manager; + manager = river::Manager::create("testApplication"); + std11::shared_ptr process = std11::make_shared(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 {}; + TEST_P(testFormat, base) { + std11::shared_ptr manager; + manager = river::Manager::create("testApplication"); + std11::shared_ptr process = std11::make_shared(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 {}; + TEST_P(testChannels, base) { + std11::shared_ptr manager; + manager = river::Manager::create("testApplication"); + std11::shared_ptr process = std11::make_shared(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 manager; + manager = river::Manager::create("testApplication"); + APPL_INFO("test convert flaot to output (callback mode)"); + std::vector 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 listChannel; + listChannel.push_back(1); + listChannel.push_back(2); + listChannel.push_back(4); + std::vector 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 m_manager; + std11::shared_ptr m_interface; + double m_phase; + public: + testOutCallback(std11::shared_ptr _manager, const std::string& _io="speaker") : + m_manager(_manager), + m_phase(0) { + //Set stereo output: + std::vector 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& _map) { + if (_format != audio::format_int16) { + APPL_ERROR("call wrong type ... (need int16_t)"); + } + int16_t* data = static_cast(_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 manager; + manager = river::Manager::create("testApplication"); + + APPL_INFO("test output (callback mode)"); + std11::shared_ptr process = std11::make_shared(manager, "speaker"); + process->run(); + process.reset(); + usleep(500000); + } + + TEST(TestALL, testOutputCallBackPulse) { + std11::shared_ptr manager; + manager = river::Manager::create("testApplication"); + + APPL_INFO("test output (callback mode)"); + std11::shared_ptr process = std11::make_shared(manager, "speaker-pulse"); + process->run(); + process.reset(); + usleep(500000); + } + + TEST(TestALL, testOutputCallBackJack) { + std11::shared_ptr manager; + manager = river::Manager::create("testApplication"); + + APPL_INFO("test output (callback mode)"); + std11::shared_ptr process = std11::make_shared(manager, "speaker-jack"); + process->run(); + process.reset(); + usleep(500000); + } + + +}; + +#undef __class__ +#define __class__ nullptr + +#endif diff --git a/test/testPlaybackWrite.h b/test/testPlaybackWrite.h new file mode 100644 index 0000000..b1c09fd --- /dev/null +++ b/test/testPlaybackWrite.h @@ -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 m_channelMap; + std11::shared_ptr m_manager; + std11::shared_ptr m_interface; + public: + testOutWrite(std11::shared_ptr _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 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= 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 manager; + manager = river::Manager::create("testApplication"); + + APPL_INFO("test output (write mode)"); + std11::shared_ptr process = std11::make_shared(manager); + process->run(); + process.reset(); + usleep(500000); + } + + class testOutWriteCallback { + private: + std11::shared_ptr m_manager; + std11::shared_ptr m_interface; + double m_phase; + public: + testOutWriteCallback(std11::shared_ptr _manager) : + m_manager(_manager), + m_phase(0) { + std::vector 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& _map) { + if (_format != audio::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) { + std11::shared_ptr manager; + manager = river::Manager::create("testApplication"); + + APPL_INFO("test output (write with callback event mode)"); + std11::shared_ptr process = std11::make_shared(manager); + process->run(); + process.reset(); + usleep(500000); + } + +}; + +#undef __class__ +#define __class__ nullptr + +#endif diff --git a/test/testRecordCallback.h b/test/testRecordCallback.h new file mode 100644 index 0000000..cfe9eed --- /dev/null +++ b/test/testRecordCallback.h @@ -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 m_manager; + std11::shared_ptr m_interface; + double m_phase; + public: + testInCallback(std11::shared_ptr _manager, const std::string& _input="microphone") : + m_manager(_manager), + m_phase(0) { + //Set stereo output: + std::vector 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& _map) { + if (_format != audio::format_int16) { + APPL_ERROR("call wrong type ... (need int16_t)"); + } + const int16_t* data = static_cast(_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 manager; + manager = river::Manager::create("testApplication"); + APPL_INFO("test input (callback mode)"); + std11::shared_ptr process = std11::make_shared(manager); + process->run(); + process.reset(); + usleep(500000); + } + +}; + +#undef __class__ +#define __class__ nullptr + +#endif diff --git a/test/testRecordRead.h b/test/testRecordRead.h new file mode 100644 index 0000000..1a30301 --- /dev/null +++ b/test/testRecordRead.h @@ -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 diff --git a/test/testVolume.h b/test/testVolume.h new file mode 100644 index 0000000..a4102a2 --- /dev/null +++ b/test/testVolume.h @@ -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 m_manager; + std11::shared_ptr m_interface; + double m_phase; + public: + testCallbackVolume(std11::shared_ptr _manager) : + m_manager(_manager), + m_phase(0) { + //Set stereo output: + std::vector 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& _map) { + int16_t* data = static_cast(_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 manager; + manager = river::Manager::create("testApplication"); + std11::shared_ptr process = std11::make_shared(manager); + process->run(); + process.reset(); + usleep(500000); + } + +}; + +#undef __class__ +#define __class__ nullptr + +#endif