2014-03-11 21:46:00 +01:00
|
|
|
/**
|
|
|
|
* @author Gary P. SCAVONE
|
|
|
|
*
|
|
|
|
* @copyright 2001-2013 Gary P. Scavone, all right reserved
|
|
|
|
*
|
|
|
|
* @license like MIT (see license file)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __AIRTAUDIO_API_H__
|
|
|
|
#define __AIRTAUDIO_API_H__
|
|
|
|
|
|
|
|
#include <sstream>
|
2014-05-01 16:37:05 +02:00
|
|
|
#include <airtaudio/debug.h>
|
2014-03-11 21:46:00 +01:00
|
|
|
|
|
|
|
namespace airtaudio {
|
2015-02-06 00:14:14 +01:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
};
|
|
|
|
enum state {
|
|
|
|
state_closed,
|
|
|
|
state_stopped,
|
|
|
|
state_stopping,
|
|
|
|
state_running
|
|
|
|
};
|
|
|
|
enum mode {
|
|
|
|
mode_unknow,
|
|
|
|
mode_output,
|
|
|
|
mode_input,
|
|
|
|
mode_duplex
|
|
|
|
};
|
|
|
|
// A protected structure used for buffer conversion.
|
|
|
|
class ConvertInfo {
|
|
|
|
public:
|
2014-03-11 21:46:00 +01:00
|
|
|
int32_t channels;
|
2015-02-06 00:14:14 +01:00
|
|
|
int32_t inJump;
|
|
|
|
int32_t outJump;
|
|
|
|
enum audio::format inFormat;
|
|
|
|
enum audio::format outFormat;
|
2014-03-11 21:46:00 +01:00
|
|
|
std::vector<int> inOffset;
|
|
|
|
std::vector<int> outOffset;
|
2015-02-06 00:14:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace api {
|
2014-03-11 21:46:00 +01:00
|
|
|
// A protected structure for audio streams.
|
|
|
|
class Stream {
|
|
|
|
public:
|
|
|
|
uint32_t device[2]; // Playback and record, respectively.
|
|
|
|
void *apiHandle; // void pointer for API specific stream handle information
|
2015-02-06 00:14:14 +01:00
|
|
|
enum airtaudio::mode mode; // OUTPUT, INPUT, or DUPLEX.
|
|
|
|
enum airtaudio::state state; // STOPPED, RUNNING, or CLOSED
|
2014-03-11 21:46:00 +01:00
|
|
|
char *userBuffer[2]; // Playback and record, respectively.
|
|
|
|
char *deviceBuffer;
|
|
|
|
bool doConvertBuffer[2]; // Playback and record, respectively.
|
|
|
|
bool userInterleaved;
|
|
|
|
bool deviceInterleaved[2]; // Playback and record, respectively.
|
|
|
|
bool doByteSwap[2]; // Playback and record, respectively.
|
|
|
|
uint32_t sampleRate;
|
|
|
|
uint32_t bufferSize;
|
|
|
|
uint32_t nBuffers;
|
|
|
|
uint32_t nUserChannels[2]; // Playback and record, respectively.
|
|
|
|
uint32_t nDeviceChannels[2]; // Playback and record channels, respectively.
|
|
|
|
uint32_t channelOffset[2]; // Playback and record, respectively.
|
|
|
|
uint64_t latency[2]; // Playback and record, respectively.
|
2015-02-06 00:14:14 +01:00
|
|
|
enum audio::format userFormat;
|
|
|
|
enum audio::format deviceFormat[2]; // Playback and record, respectively.
|
2014-03-11 21:46:00 +01:00
|
|
|
std::mutex mutex;
|
|
|
|
airtaudio::CallbackInfo callbackInfo;
|
2015-02-06 00:14:14 +01:00
|
|
|
airtaudio::ConvertInfo convertInfo[2];
|
2014-03-11 21:46:00 +01:00
|
|
|
double streamTime; // Number of elapsed seconds since the stream started.
|
|
|
|
|
|
|
|
#if defined(HAVE_GETTIMEOFDAY)
|
|
|
|
struct timeval lastTickTimestamp;
|
|
|
|
#endif
|
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
Stream() :
|
2015-02-06 00:14:14 +01:00
|
|
|
apiHandle(nullptr),
|
|
|
|
deviceBuffer(nullptr) {
|
2014-03-11 21:46:00 +01:00
|
|
|
device[0] = 11111;
|
|
|
|
device[1] = 11111;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
class Api {
|
|
|
|
public:
|
2014-05-15 21:37:39 +02:00
|
|
|
Api();
|
|
|
|
virtual ~Api();
|
2015-02-06 00:14:14 +01:00
|
|
|
virtual airtaudio::type getCurrentApi() = 0;
|
2014-05-15 21:37:39 +02:00
|
|
|
virtual uint32_t getDeviceCount() = 0;
|
2014-03-11 21:46:00 +01:00
|
|
|
virtual airtaudio::DeviceInfo getDeviceInfo(uint32_t _device) = 0;
|
2014-05-15 21:37:39 +02:00
|
|
|
virtual uint32_t getDefaultInputDevice();
|
|
|
|
virtual uint32_t getDefaultOutputDevice();
|
2014-03-11 22:37:22 +01:00
|
|
|
enum airtaudio::errorType openStream(airtaudio::StreamParameters *_outputParameters,
|
|
|
|
airtaudio::StreamParameters *_inputParameters,
|
2015-02-05 23:31:22 +01:00
|
|
|
audio::format _format,
|
2014-03-11 22:37:22 +01:00
|
|
|
uint32_t _sampleRate,
|
|
|
|
uint32_t *_bufferFrames,
|
|
|
|
airtaudio::AirTAudioCallback _callback,
|
2014-03-12 23:55:49 +01:00
|
|
|
airtaudio::StreamOptions *_options);
|
2014-05-15 21:37:39 +02:00
|
|
|
virtual enum airtaudio::errorType closeStream();
|
|
|
|
virtual enum airtaudio::errorType startStream() = 0;
|
|
|
|
virtual enum airtaudio::errorType stopStream() = 0;
|
|
|
|
virtual enum airtaudio::errorType abortStream() = 0;
|
|
|
|
long getStreamLatency();
|
|
|
|
uint32_t getStreamSampleRate();
|
|
|
|
virtual double getStreamTime();
|
|
|
|
bool isStreamOpen() const {
|
2015-02-06 00:14:14 +01:00
|
|
|
return m_stream.state != airtaudio::state_closed;
|
2014-03-11 21:46:00 +01:00
|
|
|
}
|
2014-05-15 21:37:39 +02:00
|
|
|
bool isStreamRunning() const {
|
2015-02-06 00:14:14 +01:00
|
|
|
return m_stream.state == airtaudio::state_running;
|
2014-03-11 21:46:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
airtaudio::api::Stream m_stream;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Protected, api-specific method that attempts to open a device
|
|
|
|
with the given parameters. This function MUST be implemented by
|
|
|
|
all subclasses. If an error is encountered during the probe, a
|
2014-03-13 21:16:30 +01:00
|
|
|
"warning" message is reported and false is returned. A
|
|
|
|
successful probe is indicated by a return value of true.
|
2014-03-11 21:46:00 +01:00
|
|
|
*/
|
|
|
|
virtual bool probeDeviceOpen(uint32_t _device,
|
2015-02-06 00:14:14 +01:00
|
|
|
enum airtaudio::mode _mode,
|
2014-03-11 21:46:00 +01:00
|
|
|
uint32_t _channels,
|
|
|
|
uint32_t _firstChannel,
|
|
|
|
uint32_t _sampleRate,
|
2015-02-06 00:14:14 +01:00
|
|
|
enum audio::format _format,
|
2014-03-11 21:46:00 +01:00
|
|
|
uint32_t *_bufferSize,
|
|
|
|
airtaudio::StreamOptions *_options);
|
|
|
|
|
|
|
|
//! A protected function used to increment the stream time.
|
2014-05-15 21:37:39 +02:00
|
|
|
void tickStreamTime();
|
2014-03-11 21:46:00 +01:00
|
|
|
|
|
|
|
//! Protected common method to clear an RtApiStream structure.
|
2014-05-15 21:37:39 +02:00
|
|
|
void clearStreamInfo();
|
2014-03-11 21:46:00 +01:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Protected common method that throws an RtError (type =
|
|
|
|
INVALID_USE) if a stream is not open.
|
|
|
|
*/
|
2014-05-15 21:37:39 +02:00
|
|
|
enum airtaudio::errorType verifyStream();
|
2014-03-11 21:46:00 +01:00
|
|
|
/**
|
|
|
|
* @brief Protected method used to perform format, channel number, and/or interleaving
|
|
|
|
* conversions between the user and device buffers.
|
|
|
|
*/
|
2015-02-06 00:14:14 +01:00
|
|
|
void convertBuffer(char *_outBuffer,
|
|
|
|
char *_inBuffer,
|
|
|
|
airtaudio::ConvertInfo& _info);
|
2014-03-11 21:46:00 +01:00
|
|
|
|
|
|
|
//! Protected common method used to perform byte-swapping on buffers.
|
2015-02-06 00:14:14 +01:00
|
|
|
void byteSwapBuffer(char *_buffer,
|
|
|
|
uint32_t _samples,
|
|
|
|
enum audio::format _format);
|
2014-03-11 21:46:00 +01:00
|
|
|
|
|
|
|
//! Protected common method that sets up the parameters for buffer conversion.
|
2015-02-06 00:14:14 +01:00
|
|
|
void setConvertInfo(enum airtaudio::mode _mode,
|
|
|
|
uint32_t _firstChannel);
|
2014-03-11 21:46:00 +01:00
|
|
|
};
|
|
|
|
};
|
2014-03-20 10:25:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Debug operator To display the curent element in a Human redeable information
|
|
|
|
*/
|
2015-02-06 00:14:14 +01:00
|
|
|
std::ostream& operator <<(std::ostream& _os, const airtaudio::type& _obj);
|
2014-03-11 21:46:00 +01:00
|
|
|
|
|
|
|
#endif
|