35 #  include <alsa/asoundlib.h>    38 #  define ALSA_DEF { throw SoDa::SoDaException("ALSA Sound Library is not enabled in this build version."); }     40 #include <boost/format.hpp>    75           unsigned int _sample_count_hint = 1024,
    76           std::string audio_port_name = std::string(
"default"));
    80       snd_pcm_close(pcm_out);
   107     int recv(
void * buf, 
unsigned int len, 
bool block = 
true) ALSA_DEF ; 
   123       snd_pcm_drain(pcm_out);
   132       if((err = snd_pcm_prepare(pcm_out)) < 0) {
   134       SoDaException((boost::format(
"AudioALSA::wakeOut() Failed to wake after sleepOut() pcm_prepare -- %s")
   135              % snd_strerror(err)).str(), 
this);
   137       if((err = snd_pcm_start(pcm_out)) < 0) {
   139       SoDaException((boost::format(
"AudioALSA::wakeOut() Failed to wake after sleepOut() pcm_start -- %s")
   140              % snd_strerror(err)).str(), 
this);
   151       snd_pcm_drop(pcm_in);
   158     stat = snd_pcm_readi(pcm_in, buf, len);
   160     else if(stat == -EAGAIN) 
continue; 
   172       if((err = snd_pcm_prepare(pcm_in)) < 0) {
   174       SoDaException((boost::format(
"AudioALSA::wakeIn() Failed to wake after sleepIn() -- %s")
   175              % snd_strerror(err)).str(), 
this);
   177       if((err = snd_pcm_start(pcm_in)) < 0) {
   179       SoDaException((boost::format(
"AudioALSA::wakeIn() Failed to wake after sleepIn() -- %s")
   180              % snd_strerror(err)).str(), 
this);
   186       std::string cs = currentState(pcm_out);      
   187       return (boost::format(
"%s  ready_frames = %d") % cs % snd_pcm_avail(pcm_out)).str();
   191       return currentState(pcm_in);
   198     snd_pcm_hw_params_t * hw_in_params;  
   199     snd_pcm_hw_params_t * hw_out_params; 
   204     std::string currentState(snd_pcm_t * dev) {
   205       snd_pcm_state_t st = snd_pcm_state(dev);
   208       case SND_PCM_STATE_OPEN:
   209     return std::string(
"SND_PCM_STATE_OPEN");
   211       case SND_PCM_STATE_SETUP:
   212     return std::string(
"SND_PCM_STATE_SETUP");
   214       case SND_PCM_STATE_PREPARED:
   215     return std::string(
"SND_PCM_STATE_PREPARED");
   217       case SND_PCM_STATE_RUNNING:
   218     return std::string(
"SND_PCM_STATE_RUNNING");
   220       case SND_PCM_STATE_XRUN:
   221     return std::string(
"SND_PCM_STATE_XRUN");
   223       case SND_PCM_STATE_DRAINING:
   224     return std::string(
"SND_PCM_STATE_DRAINING");
   226       case SND_PCM_STATE_PAUSED:
   227     return std::string(
"SND_PCM_STATE_PAUSED");
   229       case SND_PCM_STATE_SUSPENDED:
   230     return std::string(
"SND_PCM_STATE_SUSPENDED");
   232       case SND_PCM_STATE_DISCONNECTED:
   233     return std::string(
"SND_PCM_STATE_DISCONNECTED");
   236     return std::string(
"BADSTATE-UNKNOWN");
   243     void setupPlayback(std::string audio_port_name);
   248     void setupCapture(std::string audio_port_name); 
   255     void setupParams(snd_pcm_t * dev, snd_pcm_hw_params_t * & hw_params);
   270     void checkStatus(
int err, 
const std::string & exp, 
bool fatal = 
false) {
   273     if(fatal) 
throw SoDaException((boost::format(
"%s %s") % exp % snd_strerror(err)).str(), 
this);
   274     else std::cerr << boost::format(
"%s %s %s\n") % 
getObjName() % exp % snd_strerror(err);
   277 #endif // HAVE_LIBASOUND The Baseclass for all SoDa objects, and useful commonly used classes. 
 
int send(void *buf, unsigned int len)
send – send a buffer to the audio output 
 
std::string & getObjName()
get the name of this object 
 
bool sendBufferReady(unsigned int len)
sendBufferReady – is there enough space in the audio device send buffer for a call from send...
 
virtual std::string currentCaptureState()
 
The SoDa Exception class. 
 
void wakeOut()
start the output stream 
 
virtual std::string currentPlaybackState()
 
void sleepOut()
stop the output stream so that we don't encounter a buffer underflow while the reciever is muted...
 
void sleepIn()
stop the input stream so that we don't encounter a buffer overflow while the transmitter is inactive...
 
ALSA audio interface class. 
 
bool recvBufferReady(unsigned int len)
recvBufferReady – are there samples waiting in the audio device? 
 
Generic Audio Interface Class. 
 
int recv(void *buf, unsigned int len, bool block=true)
recv – get a buffer of data from the audio input 
 
void wakeIn()
start the input stream 
 
AudioALSA(unsigned int _sample_rate, AudioIfc::DataFormat _fmt, unsigned int _sample_count_hint=1024, std::string audio_port_name=std::string("default"))
constructor