diff --git a/airtio/Interface.cpp b/airtio/Interface.cpp index 27cd082..3aefce2 100644 --- a/airtio/Interface.cpp +++ b/airtio/Interface.cpp @@ -43,6 +43,7 @@ bool airtio::Interface::init(const std::string& _name, // Create convertion interface if (m_node->isInput() == true) { + // TODO : Set an auto update of IO if (m_map != m_node->getMap()) { std::shared_ptr algo = std::make_shared(); algo->setInputFormat(airtalgo::IOFormatInterface(m_node->getMap(), m_node->getFormat(), m_node->getFrequency())); @@ -81,6 +82,7 @@ bool airtio::Interface::init(const std::string& _name, m_process->pushBack(algo); AIRTIO_INFO("add default write node ..."); } + // TODO : Set an auto update of IO if (m_format != m_node->getFormat()) { std::shared_ptr algo = std::make_shared(); algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); @@ -118,8 +120,10 @@ std::shared_ptr airtio::Interface::create(const std::string& } airtio::Interface::~Interface() { + //stop(true, true); std::unique_lock lock(m_mutex); //m_node->interfaceRemove(shared_from_this()); + m_process.reset(); } diff --git a/lutin_airtio.py b/lutin_airtio.py index e12e988..165c95e 100644 --- a/lutin_airtio.py +++ b/lutin_airtio.py @@ -21,8 +21,6 @@ def create(target): myModule.add_module_depend(['airtaudio', 'airtalgo']) myModule.add_export_path(tools.get_current_path(__file__)) - - # add the currrent module at the return myModule diff --git a/test/main.cpp b/test/main.cpp index e448727..541dcdf 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -215,8 +215,7 @@ TEST(TestALL, testOutputCallBack) { usleep(500000); } - -#if 0 +/* class testInRead { private: std::vector m_channelMap; @@ -249,7 +248,17 @@ class testInRead { m_interface->stop(); } }; -#endif + +TEST(TestALL, testInputCallBack) { + std::shared_ptr manager; + manager = airtio::Manager::create("testApplication"); + APPL_INFO("test input (callback mode)"); + std::shared_ptr process = std::make_shared(manager); + process->run(); + process.reset(); + usleep(500000); +} +*/ class testInCallback { private: @@ -314,8 +323,7 @@ TEST(TestALL, testInputCallBack) { } -#if 0 -class testOutCallbackFloat { +class testOutCallbackType { private: std::shared_ptr m_manager; std::shared_ptr m_interface; @@ -325,10 +333,10 @@ class testOutCallbackFloat { float m_generateFreq; public: - testOutCallbackFloat(std::shared_ptr _manager, - float _freq=48000.0f, - int32_t _nbChannels=2, - airtalgo::format _format=airtalgo::format_int16) : + testOutCallbackType(const std::shared_ptr& _manager, + float _freq=48000.0f, + int32_t _nbChannels=2, + airtalgo::format _format=airtalgo::format_int16) : m_manager(_manager), m_phase(0), m_freq(_freq), @@ -350,148 +358,182 @@ class testOutCallbackFloat { APPL_ERROR("Can not generate with channel != 1,2,4"); return; } - switch (_format) { - case airtalgo::format_int16: - m_interface = m_manager->createOutput(m_freq, - channelMap, - _format, - "default", - "WriteModeCallbackI16"); - // set callback mode ... - APPL_ERROR("Set callback"); - m_interface->setOutputCallbackInt16(1024, std::bind(&testOutCallbackFloat::onDataNeededI16, this, _1, _2, _3)); - break; - case airtalgo::format_int16_on_int32: - m_interface = m_manager->createOutput(m_freq, - channelMap, - _format, - "default", - "WriteModeCallbackI16onI32"); - // set callback mode ... - m_interface->setOutputCallbackInt32(1024, std::bind(&testOutCallbackFloat::onDataNeededI16_I32, this, _1, _2, _3)); - break; - case airtalgo::format_int32: - m_interface = m_manager->createOutput(m_freq, - channelMap, - _format, - "default", - "WriteModeCallbackI32"); - // set callback mode ... - m_interface->setOutputCallbackInt32(1024, std::bind(&testOutCallbackFloat::onDataNeededI32, this, _1, _2, _3)); - break; - case airtalgo::format_float: - m_interface = m_manager->createOutput(m_freq, - channelMap, - _format, - "default", - "WriteModeCallbackFloat"); - // set callback mode ... - m_interface->setOutputCallbackFloat(1024, std::bind(&testOutCallbackFloat::onDataNeededFloat, this, _1, _2, _3)); - break; + m_interface = m_manager->createOutput(m_freq, + channelMap, + _format, + "default", + "WriteModeCallbackType"); + // set callback mode ... + m_interface->setOutputCallback(1024, + std::bind(&testOutCallbackType::onDataNeeded, + this, + std::placeholders::_1, + std::placeholders::_2, + std::placeholders::_3, + std::placeholders::_4, + std::placeholders::_5)); + } + void onDataNeeded(const std::chrono::system_clock::time_point& _playTime, + const size_t& _nbChunk, + const std::vector& _map, + void* _data, + enum airtalgo::format _type) { + APPL_DEBUG("Get data ... " << _type << " map=" << _map << " chunk=" << _nbChunk); + double baseCycle = 2.0*M_PI/double(m_freq) * double(m_generateFreq); + if (_type == airtalgo::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 (_type == airtalgo::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 (_type == airtalgo::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 (_type == airtalgo::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; + } + } } } - - ~testOutCallbackFloat() { - - } - - std::vector onDataNeededI16(const std::chrono::system_clock::time_point& _playTime, - const size_t& _nbChunk, - const std::vector& _map) { - std::vector data; - data.resize(_nbChunk*_map.size()); - double baseCycle = 2.0*M_PI/(double)m_freq * (double)m_generateFreq; - APPL_INFO("Get data ... " << _map.size()); - - for (int32_t iii=0; iii= 2*M_PI) { - m_phase -= 2*M_PI; - } - } - return data; - } - - std::vector onDataNeededI16_I32(const std::chrono::system_clock::time_point& _playTime, - const size_t& _nbChunk, - const std::vector& _map) { - std::vector data; - data.resize(_nbChunk*_map.size()); - double baseCycle = 2.0*M_PI/(double)m_freq * (double)m_generateFreq; - APPL_VERBOSE("Get data ..."); - - for (int32_t iii=0; iii= 2*M_PI) { - m_phase -= 2*M_PI; - } - } - return data; - } - - std::vector onDataNeededI32(const std::chrono::system_clock::time_point& _playTime, - const size_t& _nbChunk, - const std::vector& _map) { - std::vector data; - data.resize(_nbChunk*_map.size()); - double baseCycle = 2.0*M_PI/(double)m_freq * (double)m_generateFreq; - APPL_VERBOSE("Get data ..."); - - for (int32_t iii=0; iii= 2*M_PI) { - m_phase -= 2*M_PI; - } - } - return data; - } - - - - std::vector onDataNeededFloat(const std::chrono::system_clock::time_point& _playTime, - const size_t& _nbChunk, - const std::vector& _map) { - std::vector data; - data.resize(_nbChunk*_map.size()); - double baseCycle = 2.0*M_PI/(double)m_freq * (double)m_generateFreq; - APPL_VERBOSE("Get data ..."); - - for (int32_t iii=0; iii= 2*M_PI) { - m_phase -= 2*M_PI; - } - } - return data; - } - void run() { - if (m_interface != NULL) { + if (m_interface != nullptr) { m_interface->start(); // wait 2 second ... usleep(1000000); m_interface->stop(); + usleep(100000); } else { APPL_ERROR("Can not create interface !!!"); } } }; -#endif + +TEST(TestALL, testResampling) { + std::shared_ptr manager; + manager = airtio::Manager::create("testApplication"); + 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); + for (auto &it : listFreq) { + std::shared_ptr process = std::make_shared(manager, it, 2, airtalgo::format_int16); + process->run(); + process.reset(); + usleep(500000); + } +} +TEST(TestALL, testFormat) { + std::shared_ptr manager; + manager = airtio::Manager::create("testApplication"); + std::vector listFormat; + listFormat.push_back(airtalgo::format_int16); + listFormat.push_back(airtalgo::format_int16_on_int32); + listFormat.push_back(airtalgo::format_int32); + listFormat.push_back(airtalgo::format_float); + for (auto &it : listFormat) { + std::shared_ptr process = std::make_shared(manager, 48000, 2, it); + process->run(); + process.reset(); + usleep(500000); + } +} +TEST(TestALL, testChannels) { + std::shared_ptr manager; + manager = airtio::Manager::create("testApplication"); + std::vector listChannel; + listChannel.push_back(1); + listChannel.push_back(2); + listChannel.push_back(4); + for (auto &it : listChannel) { + std::shared_ptr process = std::make_shared(manager, 48000, it, airtalgo::format_int16); + process->run(); + process.reset(); + usleep(500000); + } +} + + +TEST(TestALL, testChannelsFormatResampling) { + std::shared_ptr manager; + manager = airtio::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(airtalgo::format_int16); + listFormat.push_back(airtalgo::format_int16_on_int32); + listFormat.push_back(airtalgo::format_int32); + listFormat.push_back(airtalgo::format_float); + for (auto &itFreq : listFreq) { + for (auto &itChannel : listChannel) { + for (auto &itFormat : listFormat) { + APPL_INFO("freq=" << itFreq << " channel=" << itChannel << " format=" << getFormatString(itFormat)); + std::shared_ptr process = std::make_shared(manager, itFreq, itChannel, itFormat); + process->run(); + process.reset(); + usleep(500000); + } + } + } +} int main(int argc, char **argv) { @@ -533,75 +575,5 @@ int main(int argc, char **argv) { etk::setArgZero(argv[0]); etk::initDefaultFolder("exml_test"); return RUN_ALL_TESTS(); - - #if 0 - APPL_INFO("test output (Write mode)"); - { - std::shared_ptr process = std::make_shared(manager); - process->run(); - process.reset(); - } - usleep(500000); - #endif - - #if 0 - APPL_INFO("test input (Read mode)"); - { - std::shared_ptr process = std::make_shared(manager); - process->run(); - process.reset(); - } - usleep(500000); - #endif - - #if 0 - APPL_INFO("test input (callback mode)"); - { - std::shared_ptr process = std::make_shared(manager); - process->run(); - process.reset(); - } - #endif - - - #if 0 - 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(airtalgo::format_int16); - listFormat.push_back(airtalgo::format_int16_on_int32); - listFormat.push_back(airtalgo::format_int32); - listFormat.push_back(airtalgo::format_float); - for (int32_t iii=0; iii::iterator formatIt = listFormat.begin(); formatIt != listFormat.end(); ++formatIt) { - float freq = listFreq[iii]; - int32_t channel = listChannel[jjj]; - APPL_INFO("freq=" << freq << " channel=" << channel << " format=" << getFormatString(*formatIt)); - std::shared_ptr process = std::make_shared(manager, freq, channel, *formatIt); - process->run(); - process.reset(); - usleep(500000); - } - } - } - #endif }