[DEV] Remove static config of process
This commit is contained in:
parent
29f8b24b2b
commit
7d969673c0
@ -7,9 +7,6 @@
|
||||
#include "debug.h"
|
||||
#include "Interface.h"
|
||||
#include "io/Node.h"
|
||||
#include <airtalgo/ChannelReorder.h>
|
||||
#include <airtalgo/FormatUpdate.h>
|
||||
#include <airtalgo/Resampler.h>
|
||||
#include <airtalgo/EndPointCallback.h>
|
||||
#include <airtalgo/EndPointWrite.h>
|
||||
#include <airtalgo/EndPointRead.h>
|
||||
@ -46,67 +43,18 @@ bool airtio::Interface::init(const std::string& _name,
|
||||
if (m_node->isInput() == true) {
|
||||
// add all time the volume stage :
|
||||
std::shared_ptr<airtalgo::Volume> algo = airtalgo::Volume::create();
|
||||
algo->setInputFormat(airtalgo::IOFormatInterface(m_node->getMap(), m_node->getFormat(), m_node->getFrequency()));
|
||||
algo->setInputFormat(m_node->getInterfaceFormat());
|
||||
algo->setName("volume");
|
||||
m_process->pushBack(algo);
|
||||
AIRTIO_INFO("add basic volume stage");
|
||||
/*
|
||||
// TODO : Set an auto update of IO
|
||||
if (m_map != m_node->getMap()) {
|
||||
std::shared_ptr<airtalgo::ChannelReorder> algo = airtalgo::ChannelReorder::create();
|
||||
algo->setInputFormat(airtalgo::IOFormatInterface(m_node->getMap(), m_node->getFormat(), m_node->getFrequency()));
|
||||
algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_node->getFormat(), m_node->getFrequency()));
|
||||
m_process->pushBack(algo);
|
||||
AIRTIO_INFO("convert " << m_node->getMap() << " -> " << m_map);
|
||||
}
|
||||
if (m_freq != m_node->getFrequency()) {
|
||||
std::shared_ptr<airtalgo::Resampler> algo = airtalgo::Resampler::create();
|
||||
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_node->getFormat(), m_node->getFrequency()));
|
||||
algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_node->getFormat(), m_freq));
|
||||
m_process->pushBack(algo);
|
||||
AIRTIO_INFO("convert " << m_node->getFrequency() << " -> " << m_freq);
|
||||
}
|
||||
if (m_format != m_node->getFormat()) {
|
||||
std::shared_ptr<airtalgo::FormatUpdate> algo = airtalgo::FormatUpdate::create();
|
||||
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_node->getFormat(), m_freq));
|
||||
algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
|
||||
m_process->pushBack(algo);
|
||||
AIRTIO_INFO("convert " << m_node->getFormat() << " -> " << m_format);
|
||||
}
|
||||
*/
|
||||
AIRTIO_INFO("add basic volume stage (1)");
|
||||
} else {
|
||||
// add all time the volume stage :
|
||||
std::shared_ptr<airtalgo::Volume> algo = airtalgo::Volume::create();
|
||||
algo->setOutputFormat(airtalgo::IOFormatInterface(m_node->getMap(), m_node->getFormat(), m_node->getFrequency()));
|
||||
algo->setOutputFormat(m_node->getInterfaceFormat());
|
||||
algo->setName("volume");
|
||||
m_process->pushBack(algo);
|
||||
AIRTIO_INFO("add basic volume stage");
|
||||
/*
|
||||
// TODO : Set an auto update of IO
|
||||
if (m_format != m_node->getFormat()) {
|
||||
std::shared_ptr<airtalgo::FormatUpdate> algo = airtalgo::FormatUpdate::create();
|
||||
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
|
||||
algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_node->getFormat(), m_freq));
|
||||
m_process->pushBack(algo);
|
||||
AIRTIO_INFO("convert " << m_format << " -> " << m_node->getFormat());
|
||||
}
|
||||
if (m_freq != m_node->getFrequency()) {
|
||||
std::shared_ptr<airtalgo::Resampler> algo = airtalgo::Resampler::create();
|
||||
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_node->getFormat(), m_freq));
|
||||
algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_node->getFormat(), m_node->getFrequency()));
|
||||
m_process->pushBack(algo);
|
||||
AIRTIO_INFO("convert " << m_freq << " -> " << m_node->getFrequency());
|
||||
}
|
||||
if (m_map != m_node->getMap()) {
|
||||
std::shared_ptr<airtalgo::ChannelReorder> algo = airtalgo::ChannelReorder::create();
|
||||
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_node->getFormat(), m_node->getFrequency()));
|
||||
algo->setOutputFormat(airtalgo::IOFormatInterface(m_node->getMap(), m_node->getFormat(), m_node->getFrequency()));
|
||||
m_process->pushBack(algo);
|
||||
AIRTIO_INFO("convert " << m_map << " -> " << m_node->getMap());
|
||||
}
|
||||
*/
|
||||
AIRTIO_INFO("add basic volume stage (2)");
|
||||
}
|
||||
//m_node->interfaceAdd(shared_from_this());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -133,6 +81,7 @@ bool airtio::Interface::hasEndPoint() {
|
||||
*/
|
||||
void airtio::Interface::setReadwrite() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
m_process->removeAlgoDynamic();
|
||||
if (m_process->hasType<airtalgo::EndPoint>() ) {
|
||||
AIRTIO_ERROR("Endpoint is already present ==> can not change");
|
||||
return;
|
||||
@ -148,12 +97,13 @@ void airtio::Interface::setReadwrite() {
|
||||
std::shared_ptr<airtalgo::EndPointWrite> algo = airtalgo::EndPointWrite::create();
|
||||
algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
|
||||
//algo->setOutputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
|
||||
m_process->pushBack(algo);
|
||||
m_process->pushFront(algo);
|
||||
}
|
||||
}
|
||||
|
||||
void airtio::Interface::setOutputCallback(size_t _chunkSize, airtalgo::needDataFunction _function) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
m_process->removeAlgoDynamic();
|
||||
m_process->removeIfFirst<airtalgo::EndPoint>();
|
||||
std::shared_ptr<airtalgo::Algo> algo = airtalgo::EndPointCallback::create(_function);
|
||||
AIRTIO_INFO("set property: " << m_map << " " << m_format << " " << m_freq);
|
||||
@ -164,6 +114,7 @@ void airtio::Interface::setOutputCallback(size_t _chunkSize, airtalgo::needDataF
|
||||
|
||||
void airtio::Interface::setInputCallback(size_t _chunkSize, airtalgo::haveNewDataFunction _function) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
m_process->removeAlgoDynamic();
|
||||
m_process->removeIfLast<airtalgo::EndPoint>();
|
||||
std::shared_ptr<airtalgo::Algo> algo = airtalgo::EndPointCallback::create(_function);
|
||||
//algo->setInputFormat(airtalgo::IOFormatInterface(m_map, m_format, m_freq));
|
||||
@ -173,6 +124,7 @@ void airtio::Interface::setInputCallback(size_t _chunkSize, airtalgo::haveNewDat
|
||||
|
||||
void airtio::Interface::setWriteCallback(airtalgo::needDataFunctionWrite _function) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
m_process->removeAlgoDynamic();
|
||||
std::shared_ptr<airtalgo::EndPointWrite> algo = m_process->get<airtalgo::EndPointWrite>(0);
|
||||
if (algo == nullptr) {
|
||||
return;
|
||||
@ -191,7 +143,6 @@ void airtio::Interface::start(const std::chrono::system_clock::time_point& _time
|
||||
void airtio::Interface::stop(bool _fast, bool _abort) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
AIRTIO_DEBUG("stop [BEGIN]");
|
||||
m_process->removeAlgoDynamic();
|
||||
m_node->interfaceRemove(shared_from_this());
|
||||
AIRTIO_DEBUG("stop [ END]");
|
||||
}
|
||||
@ -231,6 +182,7 @@ std::string airtio::Interface::getParameterProperty(const std::string& _filter,
|
||||
|
||||
void airtio::Interface::write(const void* _value, size_t _nbChunk) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
m_process->updateInterAlgo();
|
||||
std::shared_ptr<airtalgo::EndPointWrite> algo = m_process->get<airtalgo::EndPointWrite>(0);
|
||||
if (algo == nullptr) {
|
||||
return;
|
||||
@ -265,6 +217,7 @@ std::vector<int16_t> airtio::Interface::read(size_t _nbChunk) {
|
||||
|
||||
void airtio::Interface::read(void* _value, size_t _nbChunk) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
m_process->updateInterAlgo();
|
||||
// TODO :...
|
||||
|
||||
}
|
||||
@ -277,18 +230,21 @@ size_t airtio::Interface::size() const {
|
||||
|
||||
void airtio::Interface::setBufferSize(size_t _nbChunk) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
m_process->updateInterAlgo();
|
||||
// TODO :...
|
||||
|
||||
}
|
||||
|
||||
void airtio::Interface::setBufferSize(const std::chrono::duration<int64_t, std::micro>& _time) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
m_process->updateInterAlgo();
|
||||
// TODO :...
|
||||
|
||||
}
|
||||
|
||||
void airtio::Interface::clearInternalBuffer() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
m_process->updateInterAlgo();
|
||||
// TODO :...
|
||||
|
||||
}
|
||||
|
@ -36,21 +36,21 @@ int32_t airtio::io::Node::rtAudioCallback(void* _outputBuffer,
|
||||
if (_outputBuffer != nullptr) {
|
||||
AIRTIO_VERBOSE("data Output");
|
||||
std::vector<int32_t> output;
|
||||
output.resize(_nBufferFrames*m_map.size(), 0);
|
||||
const int16_t* outputTmp = nullptr;
|
||||
output.resize(_nBufferFrames*m_interfaceFormat.getMap().size(), 0);
|
||||
const int32_t* outputTmp = nullptr;
|
||||
std::vector<uint8_t> outputTmp2;
|
||||
outputTmp2.resize(sizeof(int16_t)*m_map.size()*_nBufferFrames, 0);
|
||||
outputTmp2.resize(sizeof(int32_t)*m_interfaceFormat.getMap().size()*_nBufferFrames, 0);
|
||||
for (auto &it : m_list) {
|
||||
if (it != nullptr) {
|
||||
// clear datas ...
|
||||
memset(&outputTmp2[0], 0, sizeof(int16_t)*m_map.size()*_nBufferFrames);
|
||||
memset(&outputTmp2[0], 0, sizeof(int32_t)*m_interfaceFormat.getMap().size()*_nBufferFrames);
|
||||
AIRTIO_VERBOSE(" IO : " /* << std::distance(m_list.begin(), it)*/ << "/" << m_list.size() << " name="<< it->getName());
|
||||
it->systemNeedOutputData(ttime, &outputTmp2[0], _nBufferFrames, sizeof(int16_t)*m_map.size());
|
||||
outputTmp = reinterpret_cast<const int16_t*>(&outputTmp2[0]);
|
||||
it->systemNeedOutputData(ttime, &outputTmp2[0], _nBufferFrames, sizeof(int32_t)*m_interfaceFormat.getMap().size());
|
||||
outputTmp = reinterpret_cast<const int32_t*>(&outputTmp2[0]);
|
||||
//it->systemNeedOutputData(ttime, _outputBuffer, _nBufferFrames, sizeof(int16_t)*m_map.size());
|
||||
// Add data to the output tmp buffer :
|
||||
for (size_t kkk=0; kkk<output.size(); ++kkk) {
|
||||
output[kkk] += static_cast<int32_t>(outputTmp[kkk]);
|
||||
output[kkk] += outputTmp[kkk];
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -80,8 +80,6 @@ std::shared_ptr<airtio::io::Node> airtio::io::Node::create(const std::string& _s
|
||||
|
||||
airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
|
||||
m_streamName(_streamName),
|
||||
m_frequency(48000),
|
||||
m_format(airtalgo::format_int16),
|
||||
m_isInput(_isInput) {
|
||||
AIRTIO_INFO("-----------------------------------------------------------------");
|
||||
AIRTIO_INFO("-- CREATE NODE --");
|
||||
@ -92,16 +90,26 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
|
||||
if (m_streamName == "") {
|
||||
m_streamName = "default";
|
||||
}
|
||||
std::vector<airtalgo::channel> map;
|
||||
// set default channel property :
|
||||
m_map.push_back(airtalgo::channel_frontLeft);
|
||||
m_map.push_back(airtalgo::channel_frontRight);
|
||||
map.push_back(airtalgo::channel_frontLeft);
|
||||
map.push_back(airtalgo::channel_frontRight);
|
||||
|
||||
m_hardwareFormat.set(map, airtalgo::format_int16, 48000);
|
||||
if (m_isInput == true) {
|
||||
// for input we just transfert audio with no transformation
|
||||
m_interfaceFormat.set(map, airtalgo::format_int16, 48000);
|
||||
} else {
|
||||
// for output we will do a mix ...
|
||||
m_interfaceFormat.set(map, airtalgo::format_int16_on_int32, 48000);
|
||||
}
|
||||
|
||||
// search device ID :
|
||||
AIRTIO_INFO("Open :");
|
||||
AIRTIO_INFO(" m_streamName=" << m_streamName);
|
||||
AIRTIO_INFO(" m_freq=" << m_frequency);
|
||||
AIRTIO_INFO(" m_map=" << m_map);
|
||||
AIRTIO_INFO(" m_format=" << m_format);
|
||||
AIRTIO_INFO(" m_freq=" << m_hardwareFormat.getFrequency());
|
||||
AIRTIO_INFO(" m_map=" << m_hardwareFormat.getMap());
|
||||
AIRTIO_INFO(" m_format=" << m_hardwareFormat.getFormat());
|
||||
AIRTIO_INFO(" m_isInput=" << m_isInput);
|
||||
int32_t deviceId = 0;
|
||||
AIRTIO_INFO("Device list:");
|
||||
@ -173,7 +181,7 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
|
||||
enum airtaudio::errorType err = airtaudio::errorNone;
|
||||
if (m_isInput == true) {
|
||||
err = m_adac.openStream(nullptr, ¶ms,
|
||||
airtaudio::SINT16, m_frequency, &m_rtaudioFrameSize,
|
||||
airtaudio::SINT16, m_hardwareFormat.getFrequency(), &m_rtaudioFrameSize,
|
||||
std::bind(&airtio::io::Node::rtAudioCallback,
|
||||
this,
|
||||
std::placeholders::_1,
|
||||
@ -184,7 +192,7 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
|
||||
);
|
||||
} else {
|
||||
err = m_adac.openStream(¶ms, nullptr,
|
||||
airtaudio::SINT16, m_frequency, &m_rtaudioFrameSize,
|
||||
airtaudio::SINT16, m_hardwareFormat.getFrequency(), &m_rtaudioFrameSize,
|
||||
std::bind(&airtio::io::Node::rtAudioCallback,
|
||||
this,
|
||||
std::placeholders::_1,
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <memory>
|
||||
#include <airtio/Interface.h>
|
||||
#include <airtaudio/Interface.h>
|
||||
#include <airtalgo/IOFormatInterface.h>
|
||||
|
||||
namespace airtio {
|
||||
namespace io {
|
||||
@ -59,23 +60,13 @@ namespace airtio {
|
||||
return m_streamName;
|
||||
}
|
||||
private:
|
||||
std::vector<airtalgo::channel> m_map;
|
||||
airtalgo::IOFormatInterface m_interfaceFormat;
|
||||
public:
|
||||
const std::vector<airtalgo::channel>& getMap() {
|
||||
return m_map;
|
||||
const airtalgo::IOFormatInterface& getInterfaceFormat() {
|
||||
return m_interfaceFormat;
|
||||
}
|
||||
private:
|
||||
float m_frequency;
|
||||
public:
|
||||
float getFrequency() {
|
||||
return m_frequency;
|
||||
}
|
||||
private:
|
||||
airtalgo::format m_format;
|
||||
public:
|
||||
airtalgo::format getFormat() {
|
||||
return m_format;
|
||||
}
|
||||
airtalgo::IOFormatInterface m_hardwareFormat;
|
||||
private:
|
||||
bool m_isInput;
|
||||
public:
|
||||
|
@ -381,7 +381,7 @@ class testOutCallbackType {
|
||||
const std::vector<airtalgo::channel>& _map,
|
||||
void* _data,
|
||||
enum airtalgo::format _type) {
|
||||
APPL_DEBUG("Get data ... " << _type << " map=" << _map << " chunk=" << _nbChunk);
|
||||
//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<int16_t*>(_data);
|
||||
@ -442,61 +442,50 @@ class testOutCallbackType {
|
||||
}
|
||||
};
|
||||
|
||||
TEST(TestALL, testResampling) {
|
||||
|
||||
class testResampling : public ::testing::TestWithParam<float> {};
|
||||
TEST_P(testResampling, base) {
|
||||
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);
|
||||
}
|
||||
std::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, GetParam(), 2, airtalgo::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));
|
||||
|
||||
TEST(TestALL, testFormat) {
|
||||
|
||||
class testFormat : public ::testing::TestWithParam<airtalgo::format> {};
|
||||
TEST_P(testFormat, base) {
|
||||
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);
|
||||
}
|
||||
std::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, 48000, 2, GetParam());
|
||||
process->run();
|
||||
process.reset();
|
||||
usleep(500000);
|
||||
}
|
||||
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
||||
testFormat,
|
||||
::testing::Values(airtalgo::format_int16, airtalgo::format_int16_on_int32, airtalgo::format_int32, airtalgo::format_float));
|
||||
|
||||
TEST(TestALL, testChannels) {
|
||||
|
||||
class testChannels : public ::testing::TestWithParam<int32_t> {};
|
||||
TEST_P(testChannels, base) {
|
||||
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);
|
||||
}
|
||||
std::shared_ptr<testOutCallbackType> process = std::make_shared<testOutCallbackType>(manager, 48000, GetParam(), airtalgo::format_int16);
|
||||
process->run();
|
||||
process.reset();
|
||||
usleep(500000);
|
||||
}
|
||||
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
||||
testChannels,
|
||||
::testing::Values(1,2,4));
|
||||
|
||||
|
||||
|
||||
|
||||
TEST(TestALL, testChannelsFormatResampling) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user