[DEV] update to the new river API

This commit is contained in:
Edouard DUPIN 2015-03-20 23:18:16 +01:00
parent 8cd0fe0b88
commit 6aac7ed0bb
8 changed files with 180 additions and 190 deletions

View File

@ -10,7 +10,7 @@
#include <eaudiofx/core/BufferAudioRaw.h>
#include <airtaudio/Interface.h>
eaudiofx::GeneratorRtAudio::GeneratorRtAudio() {
eaudiofx::GeneratorRiver::GeneratorRiver() {
setLive(true);
// set output :
m_io.insert(

View File

@ -6,16 +6,16 @@
* @license BSD v3 (see license file)
*/
#ifndef __EAUDIOFX_GENERATOR_RTAUDIO_H__
#define __EAUDIOFX_GENERATOR_RTAUDIO_H__
#ifndef __EAUDIOFX_GENERATOR_RIVER_H__
#define __EAUDIOFX_GENERATOR_RIVER_H__
#include <eaudiofx/core/BlockGenerator.h>
namespace eaudiofx {
class GeneratorRtAudio : public eaudiofx::BlockGenerator {
class GeneratorRiver : public eaudiofx::BlockGenerator {
public:
GeneratorRtAudio();
virtual ~GeneratorRtAudio() {};
GeneratorRiver();
virtual ~GeneratorRiver() {};
public:
int32_t pull(double _currentTime, int32_t _request, float _timeout);
};

View File

@ -0,0 +1,116 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <eaudiofx/debug.h>
#include <eaudiofx/base/ReceiverRiver.h>
#include <eaudiofx/core/BufferAudio.h>
#include <airtaudio/Interface.h>
#undef __class__
#define __class__ "ReceiverRiver"
int32_t eaudiofx::ReceiverRiver::algoProcess(int64_t _currentTime, int64_t _processTimeSlot) {
EAUDIOFX_INFO("Process: " << _currentTime << " chunkTime=" << _processTimeSlot);
return eaudiofx::ERR_NONE;
}
void eaudiofx::ReceiverRiver::init() {
eaudiofx::Block::init();
}
eaudiofx::ReceiverRiver::ReceiverRiver() :
m_processStarted(false),
m_input(*this, "in", "Input audio flow", "{ type:'audio', freq:[8000, 16000, 32000, 48000, 64000, 96000, 128000, 192000], format:['int8','int16','int32','float']}") {
addObjectType("eaudiofx::ReceiverRtAudio");
};
void eaudiofx::ReceiverRiver::onDataNeeded(void* _data,
const std11::chrono::system_clock::time_point& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const std::vector<audio::channel>& _map) {
if (_format != audio::format_int16) {
EAUDIOFX_ERROR("call wrong type ... (need int16_t)");
}
int16_t* data = static_cast<int16_t*>(_data);
int32_t nbData = std::min(m_buffer.size()/2, _nbChunk*2);
for (int32_t iii=0; iii<nbData*2; ++iii) {
((int8_t*)_data)[iii] = m_buffer[iii];
//EAUDIOFX_ERROR("write : " << data[iii]);
}
}
int32_t eaudiofx::ReceiverRiver::algoInit() {
EAUDIOFX_DEBUG("Intanciate river Manager ...");
m_manager = river::Manager::create("eaudio-fx-output");
if (m_manager == nullptr) {
EAUDIOFX_ERROR("Can not intanciate RIVER interface");
return eaudiofx::ERR_FAIL;
}
//Set stereo output:
std::vector<audio::channel> channelMap;
channelMap.push_back(audio::channel_frontLeft);
channelMap.push_back(audio::channel_frontRight);
m_interface = m_manager->createOutput(48000,
channelMap,
audio::format_int16,
"speaker");
if(m_interface == nullptr) {
EAUDIOFX_ERROR("nullptr interface");
return eaudiofx::ERR_FAIL;
}
// set callback mode ...
m_interface->setOutputCallback(std11::bind(&ReceiverRiver::onDataNeeded,
this,
std11::placeholders::_1,
std11::placeholders::_2,
std11::placeholders::_3,
std11::placeholders::_4,
std11::placeholders::_5,
std11::placeholders::_6));
m_interface->start();
return eaudiofx::ERR_NONE;
};
int32_t eaudiofx::ReceiverRiver::algoUnInit() {
EAUDIOFX_DEBUG("un-init Stream ...");
if(m_interface == nullptr) {
EAUDIOFX_ERROR("nullptr interface");
return eaudiofx::ERR_FAIL;
}
m_interface.reset();
m_manager.reset();
return eaudiofx::ERR_NONE;
};
int32_t eaudiofx::ReceiverRiver::algoStart() {
EAUDIOFX_DEBUG("Start stream ...");
if(m_interface == nullptr) {
EAUDIOFX_ERROR("nullptr interface");
return eaudiofx::ERR_FAIL;
}
m_interface->start();
return eaudiofx::ERR_NONE;
};
int32_t eaudiofx::ReceiverRiver::algoStop() {
EAUDIOFX_DEBUG("Stop Stream ...");
if(m_interface == nullptr) {
EAUDIOFX_ERROR("nullptr interface");
return eaudiofx::ERR_FAIL;
}
m_interface->stop();
return eaudiofx::ERR_NONE;
};

View File

@ -0,0 +1,53 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EAUDIOFX_RECEIVER_RIVER_H__
#define __EAUDIOFX_RECEIVER_RIVER_H__
#include <eaudiofx/core/Block.h>
#include <river/Interface.h>
#include <river/Manager.h>
#include <eaudiofx/core/BufferAudio.h>
namespace eaudiofx {
class ReceiverRiver : public eaudiofx::Block {
private:
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<audio::channel>& _map);
protected:
ReceiverRiver();
void init();
public:
DECLARE_FACTORY(ReceiverRiver);
virtual ~ReceiverRiver() {};
public: // herieted function :
virtual int32_t algoInit();
virtual int32_t algoUnInit();
private:
bool m_processStarted;
public:
virtual int32_t algoStart();
virtual int32_t algoStop();
protected:
std11::shared_ptr<river::Manager> m_manager;
std11::shared_ptr<river::Interface> m_interface;
std::vector<int8_t> m_buffer;
public:
int32_t algoProcess(int64_t _currentTime, int64_t _processTimeSlot);
protected:
eaudiofx::flow::Input<eaudiofx::BufferAudio> m_input;
};
};
#endif

View File

@ -1,122 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <eaudiofx/debug.h>
#include <eaudiofx/base/ReceiverRtAudio.h>
#include <eaudiofx/core/BufferAudio.h>
#include <airtaudio/Interface.h>
#undef __class__
#define __class__ "ReceiverRtAudio"
int eaudiofx::ReceiverRtAudio::rtAudioCallBack(void *_outputBuffer,
void *_inputBuffer,
unsigned int _nBufferFrames,
double _streamTime,
airtaudio::streamStatus _status,
void* _userData) {
if (_userData == NULL) {
EAUDIOFX_ERROR("Null class pointer");
return -1;
}
if (_outputBuffer == NULL) {
EAUDIOFX_ERROR("Null output buffer pointer");
return -1;
}
eaudiofx::ReceiverRtAudio* classPointer = static_cast<eaudiofx::ReceiverRtAudio*>(_userData);
if (classPointer == NULL) {
EAUDIOFX_ERROR("Wrong class pointer data");
return -1;
}
return classPointer->needData((float*)_outputBuffer, _nBufferFrames, _streamTime, _status);
}
int32_t eaudiofx::ReceiverRtAudio::needData(void* _outputBuffer,
size_t _nBufferFrames,
double _streamTime,
airtaudio::streamStatus _status) {
EAUDIOFX_INFO("NEED DATA : " << _nBufferFrames);
if (m_processStarted == false) {
for (int32_t iii=0; iii<_nBufferFrames*2; ++iii) {
((int8_t*)_outputBuffer)[iii] = 0;
}
return 0;
}
int32_t nbData = std::min(m_buffer.size()/2, _nBufferFrames*2);
for (int32_t iii=0; iii<nbData*2; ++iii) {
((int8_t*)_outputBuffer)[iii] = m_buffer[iii];
//EAUDIOFX_ERROR("write : " << data[iii]);
}
return 0;
}
int32_t eaudiofx::ReceiverRtAudio::algoProcess(int64_t _currentTime, int64_t _processTimeSlot) {
EAUDIOFX_INFO("Process: " << _currentTime << " chunkTime=" << _processTimeSlot);
return eaudiofx::ERR_NONE;
}
void eaudiofx::ReceiverRtAudio::init() {
eaudiofx::Block::init();
}
eaudiofx::ReceiverRtAudio::ReceiverRtAudio() :
m_processStarted(false),
m_input(*this, "in", "Input audio flow", "{ type:'audio', freq:[8000, 16000, 32000, 48000, 64000, 96000, 128000, 192000], format:['int8','int16','int32','float']}") {
addObjectType("eaudiofx::ReceiverRtAudio");
};
int32_t eaudiofx::ReceiverRtAudio::algoInit() {
EAUDIOFX_DEBUG("Intanciat AirTAudio Interface ...");
m_dac.instanciate();
EAUDIOFX_DEBUG("Create RTAudio receiver ...");
if ( m_dac.getDeviceCount() < 1 ) {
EAUDIOFX_ERROR("No audio devices found!");
return eaudiofx::ERR_FAIL;
}
EAUDIOFX_DEBUG("nb devices :" << m_dac.getDeviceCount() << " default device ID : " << m_dac.getDefaultOutputDevice());
m_parameters.deviceId = m_dac.getDefaultOutputDevice();
m_parameters.nChannels = 2;
m_parameters.firstChannel = 0;
unsigned int bufferFrames = 256;
EAUDIOFX_DEBUG("init Stream ...");
// TODO : Check return error
//m_dac.openStream(&m_parameters, NULL, airtaudio::FLOAT32, 48000, &bufferFrames, &rtAudioCallBack, (void *)this);
m_dac.openStream(&m_parameters, NULL, airtaudio::SINT16, 48000, &bufferFrames, &rtAudioCallBack, (void *)this);
// TODO : Check return error
m_dac.startStream();
return eaudiofx::ERR_NONE;
};
int32_t eaudiofx::ReceiverRtAudio::algoUnInit() {
EAUDIOFX_DEBUG("un-init Stream ...");
// Stop the stream
m_dac.stopStream();
// TODO : Check return error
if ( m_dac.isStreamOpen() ) {
m_dac.closeStream();
}
return eaudiofx::ERR_NONE;
};
int32_t eaudiofx::ReceiverRtAudio::algoStart() {
EAUDIOFX_DEBUG("Start stream ...");
m_processStarted = true;
return eaudiofx::ERR_NONE;
};
int32_t eaudiofx::ReceiverRtAudio::algoStop() {
EAUDIOFX_DEBUG("Stop Stream ...");
m_processStarted = false;
return eaudiofx::ERR_NONE;
};

View File

@ -1,57 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EAUDIOFX_RECEIVER_RTAUDIO_H__
#define __EAUDIOFX_RECEIVER_RTAUDIO_H__
#include <eaudiofx/core/Block.h>
#include <airtaudio/Interface.h>
#include <eaudiofx/core/BufferAudio.h>
namespace eaudiofx {
class ReceiverRtAudio : public eaudiofx::Block {
private:
static int rtAudioCallBack(void *_outputBuffer,
void *_inputBuffer,
unsigned int _nBufferFrames,
double _streamTime,
airtaudio::streamStatus _status,
void* _userData);
// class callback
int32_t needData(void* _outputBuffer,
size_t _nBufferFrames,
double _streamTime,
airtaudio::streamStatus _status);
protected:
ReceiverRtAudio();
void init();
public:
DECLARE_FACTORY(ReceiverRtAudio);
virtual ~ReceiverRtAudio() {};
public: // herieted function :
virtual int32_t algoInit();
virtual int32_t algoUnInit();
private:
bool m_processStarted;
public:
virtual int32_t algoStart();
virtual int32_t algoStop();
protected:
airtaudio::Interface m_dac;
airtaudio::StreamParameters m_parameters;
std::vector<int8_t> m_buffer;
public:
int32_t algoProcess(int64_t _currentTime, int64_t _processTimeSlot);
protected:
eaudiofx::flow::Input<eaudiofx::BufferAudio> m_input;
};
};
#endif

View File

@ -27,13 +27,13 @@ def create(target):
myModule.add_src_file([
#'eaudiofx/base/GeneratorFile.cpp',
#'eaudiofx/base/ReceiverFile.cpp',
#'eaudiofx/base/GeneratorRtAudio.cpp',
'eaudiofx/base/ReceiverRtAudio.cpp',
#'eaudiofx/base/GeneratorRiver.cpp',
'eaudiofx/base/ReceiverRiver.cpp',
'eaudiofx/base/GeneratorSignal.cpp'
])
# name of the dependency
myModule.add_module_depend(['airtaudio', 'ewol', 'ejson'])
myModule.add_module_depend(['river', 'ewol', 'ejson'])
myModule.add_export_path(tools.get_current_path(__file__))

View File

@ -16,7 +16,7 @@
#include <unistd.h>
#include <eaudiofx/base/GeneratorSignal.h>
#include <eaudiofx/base/ReceiverRtAudio.h>
#include <eaudiofx/base/ReceiverRiver.h>
#undef __class__
#define __class__ "Windows"
@ -128,7 +128,7 @@ void appl::Windows::onCallbackPlay() {
process->addBlock(generator);
APPL_INFO("Create Receiver ...");
std::shared_ptr<eaudiofx::ReceiverRtAudio> receiver = eaudiofx::ReceiverRtAudio::create();
std::shared_ptr<eaudiofx::ReceiverRiver> receiver = eaudiofx::ReceiverRiver::create();
if (receiver == NULL) {
APPL_ERROR("can not create Receiver ...");
return;