[DEV] start work
This commit is contained in:
@@ -11,12 +11,11 @@
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <stdint.h>
|
||||
#include <std/chrono.hpp>
|
||||
#include <std/function.hpp>
|
||||
#include <audio_algo_core/format.hpp>
|
||||
#include <audio_algo_core/channel.hpp>
|
||||
#include <std/shared_ptr.hpp>
|
||||
#include <std/weak_ptr.hpp>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <airtalgo/format.h>
|
||||
#include <airtalgo/channel.h>
|
||||
#include <memory>
|
||||
|
||||
namespace airtio {
|
||||
namespace io {
|
||||
|
@@ -4,7 +4,8 @@
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include "Node.hpp"
|
||||
#include "Node.h"
|
||||
#include <airtio/debug.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -26,7 +27,7 @@ static int rtAudioCallbackStatic(void* _outputBuffer,
|
||||
void* _inputBuffer,
|
||||
unsigned int _nBufferFrames,
|
||||
double _streamTime,
|
||||
RtAudioStreamStatus _status,
|
||||
airtaudio::streamStatus _status,
|
||||
void* _data) {
|
||||
airtio::io::Node* interface = static_cast<airtio::io::Node*>(_data);
|
||||
return interface->rtAudioCallback(static_cast<int16_t*>(_outputBuffer),
|
||||
@@ -37,23 +38,22 @@ static int rtAudioCallbackStatic(void* _outputBuffer,
|
||||
}
|
||||
|
||||
int airtio::io::Node::rtAudioCallback(int16_t* _outputBuffer,
|
||||
int16_t* _inputBuffer,
|
||||
unsigned int _nBufferFrames,
|
||||
double _streamTime,
|
||||
RtAudioStreamStatus _status) {
|
||||
std::mutex::scoped_lock lock(m_mutex);
|
||||
|
||||
std::chrono::system_clock::time_point ttime = boost::chrono::system_clock::time_point();//boost::chrono::system_clock::now();
|
||||
int16_t* _inputBuffer,
|
||||
unsigned int _nBufferFrames,
|
||||
double _streamTime,
|
||||
airtaudio::streamStatus _status) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::chrono::system_clock::time_point ttime = std::chrono::system_clock::time_point();//std::chrono::system_clock::now();
|
||||
|
||||
if (_outputBuffer != nullptr) {
|
||||
//std::cout << "data Output" << std::endl;
|
||||
AIRTIO_VERBOSE("data Output");
|
||||
std::vector<int32_t> output;
|
||||
output.resize(_nBufferFrames*m_map.size(), 0);
|
||||
std::vector<int16_t> outputTmp;
|
||||
outputTmp.resize(_nBufferFrames*m_map.size());
|
||||
for (size_t iii=0; iii< m_list.size(); ++iii) {
|
||||
if (m_list[iii] != nullptr) {
|
||||
//std::cout << " IO : " << iii+1 << "/" << m_list.size() << " name="<< m_list[iii]->getName() << std::endl;
|
||||
AIRTIO_VERBOSE(" IO : " << iii+1 << "/" << m_list.size() << " name="<< m_list[iii]->getName());
|
||||
m_list[iii]->systemNeedOutputData(ttime, &outputTmp[0], _nBufferFrames, sizeof(int16_t)*m_map.size());
|
||||
//m_list[iii]->systemNeedOutputData(ttime, _outputBuffer, _nBufferFrames, sizeof(int16_t)*m_map.size());
|
||||
// Add data to the output tmp buffer :
|
||||
@@ -70,10 +70,10 @@ int airtio::io::Node::rtAudioCallback(int16_t* _outputBuffer,
|
||||
}
|
||||
}
|
||||
if (_inputBuffer != nullptr) {
|
||||
std::cout << "data Input" << std::endl;
|
||||
AIRTIO_INFO("data Input");
|
||||
for (size_t iii=0; iii< m_list.size(); ++iii) {
|
||||
if (m_list[iii] != nullptr) {
|
||||
std::cout << " IO : " << iii+1 << "/" << m_list.size() << " name="<< m_list[iii]->getName() << std::endl;
|
||||
AIRTIO_INFO(" IO : " << iii+1 << "/" << m_list.size() << " name="<< m_list[iii]->getName());
|
||||
m_list[iii]->systemNewInputData(ttime, _inputBuffer, _nBufferFrames);
|
||||
}
|
||||
}
|
||||
@@ -91,10 +91,11 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
|
||||
m_frequency(48000),
|
||||
m_format(airtalgo::format_int16),
|
||||
m_isInput(_isInput) {
|
||||
std::cout << "-----------------------------------------------------------------" << std::endl;
|
||||
std::cout << "-- CREATE NODE --" << std::endl;
|
||||
std::cout << "-----------------------------------------------------------------" << std::endl;
|
||||
|
||||
AIRTIO_INFO("-----------------------------------------------------------------");
|
||||
AIRTIO_INFO("-- CREATE NODE --");
|
||||
AIRTIO_INFO("-----------------------------------------------------------------");
|
||||
// intanciate specific API ...
|
||||
m_adac.instanciate();
|
||||
|
||||
if (m_streamName == "") {
|
||||
m_streamName = "default";
|
||||
@@ -104,19 +105,19 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
|
||||
m_map.push_back(airtalgo::channel_frontRight);
|
||||
|
||||
// search device ID :
|
||||
std::cout << "Open :" << std::endl;
|
||||
std::cout << " m_streamName=" << m_streamName << std::endl;
|
||||
std::cout << " m_freq=" << m_frequency << std::endl;
|
||||
std::cout << " m_map=" << m_map << std::endl;
|
||||
std::cout << " m_format=" << m_format << std::endl;
|
||||
std::cout << " m_isInput=" << m_isInput << std::endl;
|
||||
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_isInput=" << m_isInput);
|
||||
int32_t deviceId = 0;
|
||||
std::cout << "Device list:" << std::endl;
|
||||
AIRTIO_INFO("Device list:");
|
||||
for (int32_t iii=0; iii<m_adac.getDeviceCount(); ++iii) {
|
||||
m_info = m_adac.getDeviceInfo(iii);
|
||||
std::cout << " " << iii << " name :" << m_info.name << std::endl;
|
||||
AIRTIO_INFO(" " << iii << " name :" << m_info.name);
|
||||
if (m_info.name == m_streamName) {
|
||||
std::cout << " Select ..." << std::endl;
|
||||
AIRTIO_INFO(" Select ...");
|
||||
deviceId = iii;
|
||||
}
|
||||
}
|
||||
@@ -124,48 +125,48 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
|
||||
m_info = m_adac.getDeviceInfo(deviceId);
|
||||
// display property :
|
||||
{
|
||||
std::cout << "Device " << deviceId << " property :" << std::endl;
|
||||
std::cout << " probe=" << (m_info.probed==true?"true":"false") << std::endl;
|
||||
std::cout << " name=" << m_info.name << std::endl;
|
||||
std::cout << " outputChannels=" << m_info.outputChannels << std::endl;
|
||||
std::cout << " inputChannels=" << m_info.inputChannels << std::endl;
|
||||
std::cout << " duplexChannels=" << m_info.duplexChannels << std::endl;
|
||||
std::cout << " isDefaultOutput=" << (m_info.isDefaultOutput==true?"true":"false") << std::endl;
|
||||
std::cout << " isDefaultInput=" << (m_info.isDefaultInput==true?"true":"false") << std::endl;
|
||||
AIRTIO_INFO("Device " << deviceId << " property :");
|
||||
AIRTIO_INFO(" probe=" << (m_info.probed==true?"true":"false"));
|
||||
AIRTIO_INFO(" name=" << m_info.name);
|
||||
AIRTIO_INFO(" outputChannels=" << m_info.outputChannels);
|
||||
AIRTIO_INFO(" inputChannels=" << m_info.inputChannels);
|
||||
AIRTIO_INFO(" duplexChannels=" << m_info.duplexChannels);
|
||||
AIRTIO_INFO(" isDefaultOutput=" << (m_info.isDefaultOutput==true?"true":"false"));
|
||||
AIRTIO_INFO(" isDefaultInput=" << (m_info.isDefaultInput==true?"true":"false"));
|
||||
//std::string rrate;
|
||||
std::stringstream rrate;
|
||||
for (int32_t jjj=0; jjj<m_info.sampleRates.size(); ++jjj) {
|
||||
rrate << m_info.sampleRates[jjj] << ";";
|
||||
}
|
||||
std::cout << " rates=" << rrate.str() << std::endl;
|
||||
AIRTIO_INFO(" rates=" << rrate.str());
|
||||
switch(m_info.nativeFormats) {
|
||||
case RTAUDIO_SINT8:
|
||||
std::cout << " native Format: 8-bit signed integer" << std::endl;
|
||||
case airtaudio::SINT8:
|
||||
AIRTIO_INFO(" native Format: 8-bit signed integer");
|
||||
break;
|
||||
case RTAUDIO_SINT16:
|
||||
std::cout << " native Format: 16-bit signed integer" << std::endl;
|
||||
case airtaudio::SINT16:
|
||||
AIRTIO_INFO(" native Format: 16-bit signed integer");
|
||||
break;
|
||||
case RTAUDIO_SINT24:
|
||||
std::cout << " native Format: 24-bit signed integer" << std::endl;
|
||||
case airtaudio::SINT24:
|
||||
AIRTIO_INFO(" native Format: 24-bit signed integer");
|
||||
break;
|
||||
case RTAUDIO_SINT32:
|
||||
std::cout << " native Format: 32-bit signed integer" << std::endl;
|
||||
case airtaudio::SINT32:
|
||||
AIRTIO_INFO(" native Format: 32-bit signed integer");
|
||||
break;
|
||||
case RTAUDIO_FLOAT32:
|
||||
std::cout << " native Format: Normalized between plus/minus 1.0" << std::endl;
|
||||
case airtaudio::FLOAT32:
|
||||
AIRTIO_INFO(" native Format: Normalized between plus/minus 1.0");
|
||||
break;
|
||||
case RTAUDIO_FLOAT64:
|
||||
std::cout << " native Format: Normalized between plus/minus 1.0" << std::endl;
|
||||
case airtaudio::FLOAT64:
|
||||
AIRTIO_INFO(" native Format: Normalized between plus/minus 1.0");
|
||||
break;
|
||||
default:
|
||||
std::cout << " native Format: Unknow" << std::endl;
|
||||
AIRTIO_INFO(" native Format: Unknow");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// open Audio device:
|
||||
unsigned int nbChunk= 1024;
|
||||
RtAudio::StreamParameters params;
|
||||
airtaudio::StreamParameters params;
|
||||
params.deviceId = deviceId;
|
||||
if (m_isInput == true) {
|
||||
m_info.inputChannels = 2;
|
||||
@@ -176,78 +177,65 @@ airtio::io::Node::Node(const std::string& _streamName, bool _isInput) :
|
||||
}
|
||||
|
||||
m_rtaudioFrameSize = nbChunk;
|
||||
std::cout << "Open output stream nbChannels=" << params.nChannels << std::endl;
|
||||
try {
|
||||
if (m_isInput == true) {
|
||||
m_adac.openStream( nullptr, ¶ms, RTAUDIO_SINT16, m_frequency, &m_rtaudioFrameSize, &rtAudioCallbackStatic, (void *)this );
|
||||
} else {
|
||||
m_adac.openStream( ¶ms, nullptr, RTAUDIO_SINT16, m_frequency, &m_rtaudioFrameSize, &rtAudioCallbackStatic, (void *)this );
|
||||
}
|
||||
} catch ( RtAudioError& e ) {
|
||||
e.printMessage();
|
||||
std::cout << "[ERROR]Can not open device Output" << std::endl;
|
||||
return;
|
||||
AIRTIO_INFO("Open output stream nbChannels=" << params.nChannels);
|
||||
enum airtaudio::errorType err = airtaudio::errorNone;
|
||||
if (m_isInput == true) {
|
||||
err = m_adac.openStream( nullptr, ¶ms, airtaudio::SINT16, m_frequency, &m_rtaudioFrameSize, &rtAudioCallbackStatic, (void *)this );
|
||||
} else {
|
||||
err = m_adac.openStream( ¶ms, nullptr, airtaudio::SINT16, m_frequency, &m_rtaudioFrameSize, &rtAudioCallbackStatic, (void *)this );
|
||||
}
|
||||
if (err != airtaudio::errorNone) {
|
||||
AIRTIO_ERROR("Create stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") << " can not create strem " << err);
|
||||
}
|
||||
}
|
||||
|
||||
airtio::io::Node::~Node() {
|
||||
std::mutex::scoped_lock lock(m_mutex);
|
||||
std::cout << "-----------------------------------------------------------------" << std::endl;
|
||||
std::cout << "-- DESTRO NODE --" << std::endl;
|
||||
std::cout << "-----------------------------------------------------------------" << std::endl;
|
||||
std::cout << "close input stream" << std::endl;
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
AIRTIO_INFO("-----------------------------------------------------------------");
|
||||
AIRTIO_INFO("-- DESTRO NODE --");
|
||||
AIRTIO_INFO("-----------------------------------------------------------------");
|
||||
AIRTIO_INFO("close input stream");
|
||||
if (m_adac.isStreamOpen() ) {
|
||||
m_adac.closeStream();
|
||||
}
|
||||
};
|
||||
|
||||
void airtio::io::Node::start() {
|
||||
std::mutex::scoped_lock lock(m_mutex);
|
||||
std::cout << "[INFO] Start stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output")<< std::endl;
|
||||
try {
|
||||
m_adac.startStream();
|
||||
} catch (RtAudioError& e ) {
|
||||
e.printMessage();
|
||||
std::cout << "[ERROR] Can not start stream Input" << std::endl;
|
||||
if (m_adac.isStreamOpen() ) {
|
||||
m_adac.closeStream();
|
||||
}
|
||||
return;
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
AIRTIO_INFO("Start stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
|
||||
enum airtaudio::errorType err = m_adac.startStream();
|
||||
if (err != airtaudio::errorNone) {
|
||||
AIRTIO_ERROR("Start stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") << " can not start stream ... " << err);
|
||||
}
|
||||
}
|
||||
|
||||
void airtio::io::Node::stop() {
|
||||
std::mutex::scoped_lock lock(m_mutex);
|
||||
std::cout << "[INFO] Stop stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output")<< std::endl;
|
||||
try {
|
||||
m_adac.stopStream();
|
||||
} catch ( RtAudioError& e ) {
|
||||
e.printMessage();
|
||||
std::cout << "[ERROR] Can not stop stream" << std::endl;
|
||||
if (m_adac.isStreamOpen() ) {
|
||||
m_adac.closeStream();
|
||||
}
|
||||
return;
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
AIRTIO_INFO("Stop stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
|
||||
enum airtaudio::errorType err = m_adac.stopStream();
|
||||
if (err != airtaudio::errorNone) {
|
||||
AIRTIO_ERROR("Stop stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") << " can not stop stream ... " << err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void airtio::io::Node::interfaceAdd(const std::shared_ptr<airtio::Interface>& _interface) {
|
||||
for (size_t iii=0; iii< m_list.size(); ++iii) {
|
||||
if (_interface == m_list[iii]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
AIRTIO_INFO("ADD interface for stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
|
||||
m_list.push_back(_interface);
|
||||
start();
|
||||
if (m_list.size() == 1) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
void airtio::io::Node::interfaceRemove(const std::shared_ptr<airtio::Interface>& _interface) {
|
||||
for (size_t iii=0; iii< m_list.size(); ++iii) {
|
||||
if (_interface == m_list[iii]) {
|
||||
m_list.erase(m_list.begin()+iii);
|
||||
AIRTIO_INFO("RM interface for stream : '" << m_streamName << "' mode=" << (m_isInput?"input":"output") );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -15,9 +15,10 @@
|
||||
#include <functional>
|
||||
#include <airtalgo/format.h>
|
||||
#include <airtalgo/channel.h>
|
||||
#include "io/Manager.h"
|
||||
#include "Manager.h"
|
||||
#include <memory>
|
||||
#include <airtio/Interface.h>
|
||||
#include <airtaudio/Interface.h>
|
||||
|
||||
namespace airtio {
|
||||
namespace io {
|
||||
@@ -42,15 +43,15 @@ namespace airtio {
|
||||
void interfaceAdd(const std::shared_ptr<airtio::Interface>& _interface);
|
||||
void interfaceRemove(const std::shared_ptr<airtio::Interface>& _interface);
|
||||
private:
|
||||
RtAudio m_adac; //!< Real audio interface
|
||||
RtAudio::DeviceInfo m_info;
|
||||
airtaudio::Interface m_adac; //!< Real audio interface
|
||||
airtaudio::DeviceInfo m_info;
|
||||
unsigned int m_rtaudioFrameSize;
|
||||
public:
|
||||
int rtAudioCallback(int16_t* _outputBuffer,
|
||||
int16_t* _inputBuffer,
|
||||
unsigned int _nBufferFrames,
|
||||
double _streamTime,
|
||||
RtAudioStreamStatus _status);
|
||||
airtaudio::streamStatus _status);
|
||||
private:
|
||||
std::string m_streamName;
|
||||
public:
|
||||
|
Reference in New Issue
Block a user