[DEV] update interface

This commit is contained in:
Edouard DUPIN 2015-01-28 22:07:11 +01:00
parent 2bc30c5517
commit 7be8623614
3 changed files with 182 additions and 208 deletions

View File

@ -43,6 +43,7 @@ bool airtio::Interface::init(const std::string& _name,
// Create convertion interface // Create convertion interface
if (m_node->isInput() == true) { if (m_node->isInput() == true) {
// TODO : Set an auto update of IO
if (m_map != m_node->getMap()) { if (m_map != m_node->getMap()) {
std::shared_ptr<airtalgo::ChannelReorder> algo = std::make_shared<airtalgo::ChannelReorder>(); std::shared_ptr<airtalgo::ChannelReorder> algo = std::make_shared<airtalgo::ChannelReorder>();
algo->setInputFormat(airtalgo::IOFormatInterface(m_node->getMap(), m_node->getFormat(), m_node->getFrequency())); 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); m_process->pushBack(algo);
AIRTIO_INFO("add default write node ..."); AIRTIO_INFO("add default write node ...");
} }
// TODO : Set an auto update of IO
if (m_format != m_node->getFormat()) { if (m_format != m_node->getFormat()) {
std::shared_ptr<airtalgo::FormatUpdate> algo = std::make_shared<airtalgo::FormatUpdate>(); std::shared_ptr<airtalgo::FormatUpdate> algo = std::make_shared<airtalgo::FormatUpdate>();
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq)); algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
@ -118,8 +120,10 @@ std::shared_ptr<airtio::Interface> airtio::Interface::create(const std::string&
} }
airtio::Interface::~Interface() { airtio::Interface::~Interface() {
//stop(true, true);
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
//m_node->interfaceRemove(shared_from_this()); //m_node->interfaceRemove(shared_from_this());
m_process.reset();
} }

View File

@ -21,8 +21,6 @@ def create(target):
myModule.add_module_depend(['airtaudio', 'airtalgo']) myModule.add_module_depend(['airtaudio', 'airtalgo'])
myModule.add_export_path(tools.get_current_path(__file__)) myModule.add_export_path(tools.get_current_path(__file__))
# add the currrent module at the # add the currrent module at the
return myModule return myModule

View File

@ -215,8 +215,7 @@ TEST(TestALL, testOutputCallBack) {
usleep(500000); usleep(500000);
} }
/*
#if 0
class testInRead { class testInRead {
private: private:
std::vector<airtalgo::channel> m_channelMap; std::vector<airtalgo::channel> m_channelMap;
@ -249,7 +248,17 @@ class testInRead {
m_interface->stop(); m_interface->stop();
} }
}; };
#endif
TEST(TestALL, testInputCallBack) {
std::shared_ptr<airtio::Manager> manager;
manager = airtio::Manager::create("testApplication");
APPL_INFO("test input (callback mode)");
std::shared_ptr<testInCallback> process = std::make_shared<testInCallback>(manager);
process->run();
process.reset();
usleep(500000);
}
*/
class testInCallback { class testInCallback {
private: private:
@ -314,8 +323,7 @@ TEST(TestALL, testInputCallBack) {
} }
#if 0 class testOutCallbackType {
class testOutCallbackFloat {
private: private:
std::shared_ptr<airtio::Manager> m_manager; std::shared_ptr<airtio::Manager> m_manager;
std::shared_ptr<airtio::Interface> m_interface; std::shared_ptr<airtio::Interface> m_interface;
@ -325,10 +333,10 @@ class testOutCallbackFloat {
float m_generateFreq; float m_generateFreq;
public: public:
testOutCallbackFloat(std::shared_ptr<airtio::Manager> _manager, testOutCallbackType(const std::shared_ptr<airtio::Manager>& _manager,
float _freq=48000.0f, float _freq=48000.0f,
int32_t _nbChannels=2, int32_t _nbChannels=2,
airtalgo::format _format=airtalgo::format_int16) : airtalgo::format _format=airtalgo::format_int16) :
m_manager(_manager), m_manager(_manager),
m_phase(0), m_phase(0),
m_freq(_freq), m_freq(_freq),
@ -350,148 +358,182 @@ class testOutCallbackFloat {
APPL_ERROR("Can not generate with channel != 1,2,4"); APPL_ERROR("Can not generate with channel != 1,2,4");
return; return;
} }
switch (_format) { m_interface = m_manager->createOutput(m_freq,
case airtalgo::format_int16: channelMap,
m_interface = m_manager->createOutput(m_freq, _format,
channelMap, "default",
_format, "WriteModeCallbackType");
"default", // set callback mode ...
"WriteModeCallbackI16"); m_interface->setOutputCallback(1024,
// set callback mode ... std::bind(&testOutCallbackType::onDataNeeded,
APPL_ERROR("Set callback"); this,
m_interface->setOutputCallbackInt16(1024, std::bind(&testOutCallbackFloat::onDataNeededI16, this, _1, _2, _3)); std::placeholders::_1,
break; std::placeholders::_2,
case airtalgo::format_int16_on_int32: std::placeholders::_3,
m_interface = m_manager->createOutput(m_freq, std::placeholders::_4,
channelMap, std::placeholders::_5));
_format, }
"default", void onDataNeeded(const std::chrono::system_clock::time_point& _playTime,
"WriteModeCallbackI16onI32"); const size_t& _nbChunk,
// set callback mode ... const std::vector<airtalgo::channel>& _map,
m_interface->setOutputCallbackInt32(1024, std::bind(&testOutCallbackFloat::onDataNeededI16_I32, this, _1, _2, _3)); void* _data,
break; enum airtalgo::format _type) {
case airtalgo::format_int32: APPL_DEBUG("Get data ... " << _type << " map=" << _map << " chunk=" << _nbChunk);
m_interface = m_manager->createOutput(m_freq, double baseCycle = 2.0*M_PI/double(m_freq) * double(m_generateFreq);
channelMap, if (_type == airtalgo::format_int16) {
_format, int16_t* data = static_cast<int16_t*>(_data);
"default", for (int32_t iii=0; iii<_nbChunk; iii++) {
"WriteModeCallbackI32"); for (int32_t jjj=0; jjj<_map.size(); jjj++) {
// set callback mode ... data[_map.size()*iii+jjj] = cos(m_phase) * double(INT16_MAX);
m_interface->setOutputCallbackInt32(1024, std::bind(&testOutCallbackFloat::onDataNeededI32, this, _1, _2, _3)); }
break; m_phase += baseCycle;
case airtalgo::format_float: if (m_phase >= 2*M_PI) {
m_interface = m_manager->createOutput(m_freq, m_phase -= 2*M_PI;
channelMap, }
_format, }
"default", } else if (_type == airtalgo::format_int16_on_int32) {
"WriteModeCallbackFloat"); int32_t* data = static_cast<int32_t*>(_data);
// set callback mode ... for (int32_t iii=0; iii<_nbChunk; iii++) {
m_interface->setOutputCallbackFloat(1024, std::bind(&testOutCallbackFloat::onDataNeededFloat, this, _1, _2, _3)); for (int32_t jjj=0; jjj<_map.size(); jjj++) {
break; 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<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 (_type == airtalgo::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;
}
}
} }
} }
~testOutCallbackFloat() {
}
std::vector<int16_t> onDataNeededI16(const std::chrono::system_clock::time_point& _playTime,
const size_t& _nbChunk,
const std::vector<airtalgo::channel>& _map) {
std::vector<int16_t> 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<data.size()/_map.size(); 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;
}
}
return data;
}
std::vector<int32_t> onDataNeededI16_I32(const std::chrono::system_clock::time_point& _playTime,
const size_t& _nbChunk,
const std::vector<airtalgo::channel>& _map) {
std::vector<int32_t> 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<data.size()/_map.size(); 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;
}
}
return data;
}
std::vector<int32_t> onDataNeededI32(const std::chrono::system_clock::time_point& _playTime,
const size_t& _nbChunk,
const std::vector<airtalgo::channel>& _map) {
std::vector<int32_t> 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<data.size()/_map.size(); 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;
}
}
return data;
}
std::vector<float> onDataNeededFloat(const std::chrono::system_clock::time_point& _playTime,
const size_t& _nbChunk,
const std::vector<airtalgo::channel>& _map) {
std::vector<float> 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<data.size()/_map.size(); 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;
}
}
return data;
}
void run() { void run() {
if (m_interface != NULL) { if (m_interface != nullptr) {
m_interface->start(); m_interface->start();
// wait 2 second ... // wait 2 second ...
usleep(1000000); usleep(1000000);
m_interface->stop(); m_interface->stop();
usleep(100000);
} else { } else {
APPL_ERROR("Can not create interface !!!"); APPL_ERROR("Can not create interface !!!");
} }
} }
}; };
#endif
TEST(TestALL, testResampling) {
std::shared_ptr<airtio::Manager> manager;
manager = airtio::Manager::create("testApplication");
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);
for (auto &it : listFreq) {
std::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, it, 2, airtalgo::format_int16);
process->run();
process.reset();
usleep(500000);
}
}
TEST(TestALL, testFormat) {
std::shared_ptr<airtio::Manager> manager;
manager = airtio::Manager::create("testApplication");
std::vector<airtalgo::format> 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<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, 48000, 2, it);
process->run();
process.reset();
usleep(500000);
}
}
TEST(TestALL, testChannels) {
std::shared_ptr<airtio::Manager> manager;
manager = airtio::Manager::create("testApplication");
std::vector<int32_t> listChannel;
listChannel.push_back(1);
listChannel.push_back(2);
listChannel.push_back(4);
for (auto &it : listChannel) {
std::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, 48000, it, airtalgo::format_int16);
process->run();
process.reset();
usleep(500000);
}
}
TEST(TestALL, testChannelsFormatResampling) {
std::shared_ptr<airtio::Manager> manager;
manager = airtio::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<airtalgo::format> 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<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, itFreq, itChannel, itFormat);
process->run();
process.reset();
usleep(500000);
}
}
}
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -533,75 +575,5 @@ int main(int argc, char **argv) {
etk::setArgZero(argv[0]); etk::setArgZero(argv[0]);
etk::initDefaultFolder("exml_test"); etk::initDefaultFolder("exml_test");
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
#if 0
APPL_INFO("test output (Write mode)");
{
std::shared_ptr<testOutWrite> process = std::make_shared<testOutWrite>(manager);
process->run();
process.reset();
}
usleep(500000);
#endif
#if 0
APPL_INFO("test input (Read mode)");
{
std::shared_ptr<testInRead> process = std::make_shared<testInRead>(manager);
process->run();
process.reset();
}
usleep(500000);
#endif
#if 0
APPL_INFO("test input (callback mode)");
{
std::shared_ptr<testInCallback> process = std::make_shared<testInCallback>(manager);
process->run();
process.reset();
}
#endif
#if 0
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<airtalgo::format> 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<listFreq.size(); ++iii) {
for (int32_t jjj=0; jjj<listChannel.size(); ++jjj) {
for (std::vector<airtalgo::format>::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<testOutCallbackFloat> process = std::make_shared<testOutCallbackFloat>(manager, freq, channel, *formatIt);
process->run();
process.reset();
usleep(500000);
}
}
}
#endif
} }