[DEV] add basic tools and change some API

This commit is contained in:
Edouard DUPIN 2015-06-11 21:39:56 +02:00
parent bb16adc099
commit fa618958b8
22 changed files with 166 additions and 128 deletions

View File

@ -55,7 +55,7 @@ namespace audio {
void setName(const std::string& _name) {
m_name = _name;
}
virtual audio::orchestra::type getCurrentApi() = 0;
virtual const std::string& getCurrentApi() = 0;
virtual uint32_t getDeviceCount() = 0;
virtual audio::orchestra::DeviceInfo getDeviceInfo(uint32_t _device) = 0;
// TODO : Check API ...
@ -173,9 +173,5 @@ namespace audio {
};
}
}
/**
* @brief Debug operator To display the curent element in a Human redeable information
*/
std::ostream& operator <<(std::ostream& _os, const audio::orchestra::type& _obj);
#endif

View File

@ -13,8 +13,8 @@
#undef __class__
#define __class__ "Interface"
std::vector<enum audio::orchestra::type> audio::orchestra::Interface::getCompiledApi() {
std::vector<enum audio::orchestra::type> apis;
std::vector<std::string> audio::orchestra::Interface::getListApi() {
std::vector<std::string> apis;
// The order here will control the order of RtAudio's API search in
// the constructor.
for (size_t iii=0; iii<m_apiAvaillable.size(); ++iii) {
@ -25,7 +25,7 @@ std::vector<enum audio::orchestra::type> audio::orchestra::Interface::getCompile
void audio::orchestra::Interface::openRtApi(enum audio::orchestra::type _api) {
void audio::orchestra::Interface::openApi(const std::string& _api) {
delete m_rtapi;
m_rtapi = nullptr;
for (size_t iii=0; iii<m_apiAvaillable.size(); ++iii) {
@ -47,61 +47,62 @@ audio::orchestra::Interface::Interface() :
m_rtapi(nullptr) {
ATA_DEBUG("Add interface:");
#if defined(ORCHESTRA_BUILD_JACK)
ATA_DEBUG(" JACK");
addInterface(audio::orchestra::type_jack, audio::orchestra::api::Jack::create);
#endif
#if defined(ORCHESTRA_BUILD_ALSA)
ATA_DEBUG(" ALSA");
addInterface(audio::orchestra::type_alsa, audio::orchestra::api::Alsa::create);
#endif
#if defined(ORCHESTRA_BUILD_PULSE)
ATA_DEBUG(" PULSE");
addInterface(audio::orchestra::type_pulse, audio::orchestra::api::Pulse::create);
#endif
#if defined(ORCHESTRA_BUILD_OSS)
ATA_DEBUG(" OSS");
addInterface(audio::orchestra::type_oss, audio::orchestra::api::Oss::create);
#endif
#if defined(ORCHESTRA_BUILD_ASIO)
ATA_DEBUG(" ASIO");
addInterface(audio::orchestra::type_asio, audio::orchestra::api::Asio::create);
#endif
#if defined(ORCHESTRA_BUILD_DS)
ATA_DEBUG(" DS");
addInterface(audio::orchestra::type_ds, audio::orchestra::api::Ds::create);
#endif
#if defined(ORCHESTRA_BUILD_MACOSX_CORE)
ATA_DEBUG(" CORE OSX");
addInterface(audio::orchestra::type_coreOSX, audio::orchestra::api::Core::create);
#endif
#if defined(ORCHESTRA_BUILD_IOS_CORE)
ATA_DEBUG(" CORE IOS");
addInterface(audio::orchestra::type_coreIOS, audio::orchestra::api::CoreIos::create);
#endif
#if defined(ORCHESTRA_BUILD_JAVA)
ATA_DEBUG(" JAVA");
addInterface(audio::orchestra::type_java, audio::orchestra::api::Android::create);
#endif
#if defined(ORCHESTRA_BUILD_DUMMY)
ATA_DEBUG(" DUMMY");
addInterface(audio::orchestra::type_dummy, audio::orchestra::api::Dummy::create);
#endif
}
void audio::orchestra::Interface::addInterface(enum audio::orchestra::type _api, Api* (*_callbackCreate)()) {
m_apiAvaillable.push_back(std::pair<enum audio::orchestra::type, Api* (*)()>(_api, _callbackCreate));
void audio::orchestra::Interface::addInterface(const std::string& _api, Api* (*_callbackCreate)()) {
m_apiAvaillable.push_back(std::pair<std::string, Api* (*)()>(_api, _callbackCreate));
}
enum audio::orchestra::error audio::orchestra::Interface::instanciate(enum audio::orchestra::type _api) {
enum audio::orchestra::error audio::orchestra::Interface::clear() {
ATA_INFO("Clear API ...");
if (m_rtapi == nullptr) {
ATA_WARNING("Interface NOT started!");
return audio::orchestra::error_none;
}
delete m_rtapi;
m_rtapi = nullptr;
return audio::orchestra::error_none;
}
enum audio::orchestra::error audio::orchestra::Interface::instanciate(const std::string& _api) {
ATA_INFO("Instanciate API ...");
if (m_rtapi != nullptr) {
ATA_WARNING("Interface already started ...!");
ATA_WARNING("Interface already started!");
return audio::orchestra::error_none;
}
if (_api != audio::orchestra::type_undefined) {
ATA_INFO("API specified : " << _api);
// Attempt to open the specified API.
openRtApi(_api);
openApi(_api);
if (m_rtapi != nullptr) {
if (m_rtapi->getDeviceCount() != 0) {
ATA_INFO(" ==> api open");
@ -116,11 +117,11 @@ enum audio::orchestra::error audio::orchestra::Interface::instanciate(enum audio
ATA_INFO("Auto choice API :");
// Iterate through the compiled APIs and return as soon as we find
// one with at least one device or we reach the end of the list.
std::vector<enum audio::orchestra::type> apis = getCompiledApi();
std::vector<std::string> apis = getListApi();
ATA_INFO(" find : " << apis.size() << " apis.");
for (size_t iii=0; iii<apis.size(); ++iii) {
ATA_INFO("try open ...");
openRtApi(apis[iii]);
openApi(apis[iii]);
if(m_rtapi == nullptr) {
ATA_ERROR(" ==> can not create ...");
continue;

View File

@ -38,7 +38,7 @@ namespace audio {
*/
class Interface {
protected:
std::vector<std::pair<enum audio::orchestra::type, Api* (*)()> > m_apiAvaillable;
std::vector<std::pair<std::string, Api* (*)()> > m_apiAvaillable;
protected:
audio::orchestra::Api *m_rtapi;
public:
@ -50,13 +50,16 @@ namespace audio {
m_rtapi->setName(_name);
}
/**
* @brief A static function to determine the available compiled audio APIs.
*
* The values returned in the std::vector can be compared against
* the enumerated list values. Note that there can be more than one
* API compiled for certain operating systems.
* @brief Get the list of all availlable API in the system.
* @return the list of all APIs
*/
std::vector<enum audio::orchestra::type> getCompiledApi();
std::vector<std::string> getListApi();
/**
* @brief Add an interface of the Possible List.
* @param[in] _api Type of the interface.
* @param[in] _callbackCreate API creation callback.
*/
void addInterface(const std::string& _api, Api* (*_callbackCreate)());
/**
* @brief The class constructor.
* @note the creating of the basic instance is done by Instanciate
@ -70,19 +73,17 @@ namespace audio {
*/
virtual ~Interface();
/**
* @brief Add an interface of the Possible List.
* @param[in] _api Type of the interface.
* @param[in] _callbackCreate API creation callback.
* @brief Clear the current Interface
*/
void addInterface(enum audio::orchestra::type _api, Api* (*_callbackCreate)());
enum audio::orchestra::error clear();
/**
* @brief Create an interface instance
*/
enum audio::orchestra::error instanciate(enum audio::orchestra::type _api = audio::orchestra::type_undefined);
enum audio::orchestra::error instanciate(const std::string& _api = audio::orchestra::type_undefined);
/**
* @return the audio API specifier for the current instance of airtaudio.
*/
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
if (m_rtapi == nullptr) {
return audio::orchestra::type_undefined;
}
@ -312,7 +313,7 @@ namespace audio {
}
bool isMasterOf(audio::orchestra::Interface& _interface);
protected:
void openRtApi(enum audio::orchestra::type _api);
void openApi(const std::string& _api);
};
}
}

View File

@ -18,7 +18,7 @@ namespace audio {
public:
Alsa();
virtual ~Alsa();
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
return audio::orchestra::type_alsa;
}
uint32_t getDeviceCount();

View File

@ -17,7 +17,7 @@ namespace audio {
public:
Android();
virtual ~Android();
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
return audio::orchestra::type_java;
}
uint32_t getDeviceCount();

View File

@ -18,7 +18,7 @@ namespace audio {
public:
Asio();
virtual ~Asio();
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
return audio::orchestra::WINDOWS_ASIO;
}
uint32_t getDeviceCount();

View File

@ -21,7 +21,7 @@ namespace audio {
public:
Core();
virtual ~Core();
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
return audio::orchestra::type_coreOSX;
}
uint32_t getDeviceCount();

View File

@ -19,7 +19,7 @@ namespace audio {
public:
CoreIos();
virtual ~CoreIos();
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
return audio::orchestra::type_coreIOS;
}
uint32_t getDeviceCount();

View File

@ -19,7 +19,7 @@ namespace audio {
public:
Ds();
virtual ~Ds();
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
return audio::orchestra::type_ds;
}
uint32_t getDeviceCount();

View File

@ -19,7 +19,7 @@ namespace audio {
static audio::orchestra::Api* create();
public:
Dummy();
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
return audio::orchestra::type_dummy;
}
uint32_t getDeviceCount();

View File

@ -20,7 +20,7 @@ namespace audio {
public:
Jack();
virtual ~Jack();
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
return audio::orchestra::type_jack;
}
uint32_t getDeviceCount();

View File

@ -19,7 +19,7 @@ namespace audio {
public:
Oss();
virtual ~Oss();
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
return audio::orchestra::type_oss;
}
uint32_t getDeviceCount();

View File

@ -19,7 +19,7 @@ namespace audio {
public:
Pulse();
virtual ~Pulse();
enum audio::orchestra::type getCurrentApi() {
const std::string& getCurrentApi() {
return audio::orchestra::type_pulse;
}
uint32_t getDeviceCount();

View File

@ -15,59 +15,14 @@
#undef __class__
#define __class__ "type"
static const char* listType[] = {
"undefined",
"alsa",
"pulse",
"oss",
"jack",
"coreOSX",
"corIOS",
"asio",
"ds",
"java",
"dummy",
"user1",
"user2",
"user3",
"user4"
};
static int32_t listTypeSize = sizeof(listType)/sizeof(char*);
std::ostream& audio::orchestra::operator <<(std::ostream& _os, const enum audio::orchestra::type& _obj) {
_os << listType[_obj];
return _os;
}
std::ostream& audio::orchestra::operator <<(std::ostream& _os, const std::vector<enum audio::orchestra::type>& _obj) {
_os << std::string("{");
for (size_t iii=0; iii<_obj.size(); ++iii) {
if (iii!=0) {
_os << std::string(";");
}
_os << _obj[iii];
}
_os << std::string("}");
return _os;
}
/*
template <enum audio::format> std::string to_string(const enum audio::format& _variable) {
return listType[_value];
}
*/
std::string audio::orchestra::getTypeString(enum audio::orchestra::type _value) {
return listType[_value];
}
enum audio::orchestra::type audio::orchestra::getTypeFromString(const std::string& _value) {
for (int32_t iii=0; iii<listTypeSize; ++iii) {
if (_value == listType[iii]) {
return static_cast<enum audio::orchestra::type>(iii);
}
}
if (_value == "auto") {
return audio::orchestra::type_undefined;
}
return audio::orchestra::type_undefined;
}
const std::string audio::orchestra::type_undefined = "undefined";
const std::string audio::orchestra::type_alsa = "alsa";
const std::string audio::orchestra::type_pulse = "pulse";
const std::string audio::orchestra::type_oss = "oss";
const std::string audio::orchestra::type_jack = "jack";
const std::string audio::orchestra::type_coreOSX = "coreOSX";
const std::string audio::orchestra::type_coreIOS = "coreIOS";
const std::string audio::orchestra::type_asio = "asio";
const std::string audio::orchestra::type_ds = "ds";
const std::string audio::orchestra::type_java = "java";
const std::string audio::orchestra::type_dummy = "dummy";

View File

@ -17,27 +17,17 @@ namespace audio {
/**
* @brief Audio API specifier arguments.
*/
enum type {
type_undefined, //!< Error API.
type_alsa, //!< LINUX The Advanced Linux Sound Architecture.
type_pulse, //!< LINUX The Linux PulseAudio.
type_oss, //!< LINUX The Linux Open Sound System.
type_jack, //!< UNIX The Jack Low-Latency Audio Server.
type_coreOSX, //!< Macintosh OSX Core Audio.
type_coreIOS, //!< Macintosh iOS Core Audio.
type_asio, //!< WINDOWS The Steinberg Audio Stream I/O.
type_ds, //!< WINDOWS The Microsoft Direct Sound.
type_java, //!< ANDROID Interface.
type_dummy, //!< Empty wrapper (non-functional).
type_user1, //!< User interface 1.
type_user2, //!< User interface 2.
type_user3, //!< User interface 3.
type_user4, //!< User interface 4.
};
std::ostream& operator <<(std::ostream& _os, const enum audio::orchestra::type& _obj);
std::ostream& operator <<(std::ostream& _os, const std::vector<enum audio::orchestra::type>& _obj);
std::string getTypeString(enum audio::orchestra::type _value);
enum audio::orchestra::type getTypeFromString(const std::string& _value);
extern const std::string type_undefined; //!< Error API.
extern const std::string type_alsa; //!< LINUX The Advanced Linux Sound Architecture.
extern const std::string type_pulse; //!< LINUX The Linux PulseAudio.
extern const std::string type_oss; //!< LINUX The Linux Open Sound System.
extern const std::string type_jack; //!< UNIX The Jack Low-Latency Audio Server.
extern const std::string type_coreOSX; //!< Macintosh OSX Core Audio.
extern const std::string type_coreIOS; //!< Macintosh iOS Core Audio.
extern const std::string type_asio; //!< WINDOWS The Steinberg Audio Stream I/O.
extern const std::string type_ds; //!< WINDOWS The Microsoft Direct Sound.
extern const std::string type_java; //!< ANDROID Interface.
extern const std::string type_dummy; //!< Empty wrapper (non-functional).
}
}

View File

@ -4,7 +4,7 @@ import lutin.tools as tools
import lutin.debug as debug
def get_desc():
return "audio_orchestra : Generic wrapper on all audio interface"
return "Generic wrapper on all audio interface"
def create(target):
@ -71,7 +71,6 @@ def create(target):
myModule.add_export_path(tools.get_current_path(__file__))
# add the currrent module at the
return myModule

View File

@ -0,0 +1,19 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
import lutin.debug as debug
def get_desc():
return "'in' tool for orchestra"
def create(target):
myModule = module.Module(__file__, 'orchestra-in', 'BINARY')
myModule.add_src_file([
'orchestra-in.cpp'
])
myModule.add_module_depend(['audio_orchestra', 'test-debug'])
return myModule

View File

@ -0,0 +1,19 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
import lutin.debug as debug
def get_desc():
return "'list' i/o tool for orchestra"
def create(target):
myModule = module.Module(__file__, 'orchestra-list', 'BINARY')
myModule.add_src_file([
'orchestra-list.cpp'
])
myModule.add_module_depend(['audio_orchestra', 'test-debug'])
return myModule

View File

@ -0,0 +1,19 @@
#!/usr/bin/python
import lutin.module as module
import lutin.tools as tools
import lutin.debug as debug
def get_desc():
return "'out' tool for orchestra"
def create(target):
myModule = module.Module(__file__, 'orchestra-out', 'BINARY')
myModule.add_src_file([
'orchestra-out.cpp'
])
myModule.add_module_depend(['audio_orchestra', 'test-debug'])
return myModule

0
tools/orchestra-in.cpp Normal file
View File

39
tools/orchestra-list.cpp Normal file
View File

@ -0,0 +1,39 @@
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <etk/etk.h>
#include <test-debug/debug.h>
#include <unistd.h>
#include <audio/orchestra/Interface.h>
int main(int _argc, const char **_argv) {
// the only one init for etk:
etk::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
std::cout << "Help : " << std::endl;
std::cout << " ./xxx ---" << std::endl;
exit(0);
}
}
audio::orchestra::Interface interface;
std::vector<std::string> apis = interface.getListApi();
TEST_PRINT("Find : " << apis.size() << " apis.");
for (auto &it : apis) {
interface.instanciate(it);
TEST_PRINT("Device list for : '" << it << "'");
for (int32_t iii=0; iii<interface.getDeviceCount(); ++iii) {
audio::orchestra::DeviceInfo info = interface.getDeviceInfo(iii);
TEST_PRINT(" " << iii << " name :" << info.name);
info.display(2);
}
interface.clear();
}
return 0;
}

0
tools/orchestra-out.cpp Normal file
View File