30 #include <boost/format.hpp> 34 AudioPA::AudioPA(
unsigned int _sample_rate, DataFormat _fmt,
unsigned int _sample_count_hint) :
35 AudioIfc(_sample_rate, _fmt, _sample_count_hint,
"AudioPA Port Audio Interface") {
36 checkStatus(pa_stat = Pa_Initialize(),
"Init");
46 int bavail = Pa_GetStreamWriteAvailable(pa_outstream);
48 checkStatus(bavail,
"sendBufferReady:");
54 int bavail = Pa_GetStreamReadAvailable(pa_instream);
63 if(!Pa_IsStreamActive(pa_outstream)) {
64 checkStatus(Pa_StartStream(pa_outstream),
"sendWake");
66 pa_stat = Pa_WriteStream(pa_outstream, buf, len);
69 std::cerr << boost::format(
"write to audio interface failed (%s)\n") % Pa_GetErrorText(pa_stat);
78 if(!Pa_IsStreamActive(pa_instream)) {
79 checkStatus(Pa_StartStream(pa_instream),
"recvWake");
81 pa_stat = Pa_ReadStream(pa_instream, buf, len);
82 if(pa_stat != paNoError) {
83 std::cerr << boost::format(
"read from audio interface failed (%s)\n") % Pa_GetErrorText(pa_stat);
91 case FLOAT:
return paFloat32;
94 throw (
new SoDaException(
"Unsupported data type DFLOAT for PortAudio driver.",
this));
96 case INT32:
return paInt32;
98 case INT16:
return paInt16;
100 case INT8:
return paInt8;
108 AudioIfc(_sample_rate, _fmt, _sample_count_hint,
"AudioPA Port Audio Interface") {
109 throw SoDaException(
"PortAudio Library is not enabled in this build version.");
111 #endif // HAVE_LIBPORTAUDIO
int send(void *buf, unsigned int len)
sendBuf – send a buffer to the audio output
The SoDa Exception class.
unsigned int sample_count_hint
int recv(void *buf, unsigned int len, bool block=true)
recvBuf – get a buffer of data from the audio input
bool sendBufferReady(unsigned int len)
sendBufferReady – is there enough space in the audio device send buffer for a call from send...
bool recvBufferReady(unsigned int len)
recvBufferReady – is there enough space in the audio device recv buffer for a call from recv...
Generic Audio Interface Class.
AudioPA(unsigned int _sample_rate, AudioIfc::DataFormat _fmt, unsigned int _sample_count_hint=1024)
constructor