SoDaRadio-5.0.3-master:8901fb5
Public Member Functions | List of all members
SoDa::AudioALSA Class Reference

ALSA audio interface class. More...

#include <AudioALSA.hxx>

Inheritance diagram for SoDa::AudioALSA:
SoDa::AudioIfc SoDa::SoDaBase

Public Member Functions

 AudioALSA (unsigned int _sample_rate, AudioIfc::DataFormat _fmt, unsigned int _sample_count_hint=1024, std::string audio_port_name=std::string("default"))
 constructor More...
 
 ~AudioALSA ()
 
int send (void *buf, unsigned int len)
 send – send a buffer to the audio output More...
 
bool sendBufferReady (unsigned int len)
 sendBufferReady – is there enough space in the audio device send buffer for a call from send? More...
 
int recv (void *buf, unsigned int len, bool block=true)
 recv – get a buffer of data from the audio input More...
 
bool recvBufferReady (unsigned int len)
 recvBufferReady – are there samples waiting in the audio device? More...
 
void sleepOut ()
 stop the output stream so that we don't encounter a buffer underflow while the reciever is muted. More...
 
void wakeOut ()
 start the output stream More...
 
void sleepIn ()
 stop the input stream so that we don't encounter a buffer overflow while the transmitter is inactive. More...
 
void wakeIn ()
 start the input stream More...
 
- Public Member Functions inherited from SoDa::AudioIfc
 AudioIfc (unsigned int _sample_rate, DataFormat _fmt, unsigned int _sample_count_hint, const std::string &name="AudioIfc")
 
virtual bool setOutGain (float gain)
 set the gain for the output device. More...
 
virtual bool setInGain (float gain)
 set the gain for the input device. More...
 
virtual float getOutGain ()
 get the gain for the output device. More...
 
virtual float getInGain ()
 get the gain for the input device. More...
 
virtual std::string currentPlaybackState ()
 
virtual std::string currentCaptureState ()
 
- Public Member Functions inherited from SoDa::SoDaBase
 SoDaBase (const std::string &oname)
 The constructor – pass a name for the object. More...
 
std::string & getObjName ()
 get the name of this object More...
 
SoDaBasefindSoDaObject (const std::string &oname)
 find a SoDa Object by name. More...
 
double getTime ()
 Get a time stamp in nS resolution that monotonically increases and that is very inexpensive (typically < 100nS). More...
 

Additional Inherited Members

- Public Types inherited from SoDa::AudioIfc
enum  DataFormat {
  FLOAT, DFLOAT, INT32, INT16,
  INT8
}
 
- Protected Attributes inherited from SoDa::AudioIfc
unsigned int sample_rate
 
DataFormat format
 
unsigned int sample_count_hint
 
float in_gain
 
float out_gain
 
int datatype_size
 

Detailed Description

ALSA audio interface class.

AudioALSA implements the interface specified by AudioIfc. It should be interchangable with other audio interface handlers.

The first several generations of SoDa used a Port Audio interface, but the PA library tends to spew a lot of extraneous "informational" messages on the console. Though it is quite simple, the noise that PA creates makes it not my (kb1vc) interface of choice.

ALSA on the other hand is documented poorly, organized oddly, and nearly inscrutable. But it is fast, and doesn't make a lot of noise on the console.

Definition at line 63 of file AudioALSA.hxx.

Constructor & Destructor Documentation

◆ AudioALSA()

SoDa::AudioALSA::AudioALSA ( unsigned int  _sample_rate,
AudioIfc::DataFormat  _fmt,
unsigned int  _sample_count_hint = 1024,
std::string  audio_port_name = std::string("default") 
)

constructor

Parameters
_sample_ratein Hz 48000 is a good choice
_fmtthe format of the data (FLOAT, DFLOAT, INT32, INT16, INT8)
_sample_count_hintthe size of the buffers passed to and from the audio device (in samples)
audio_port_namewhich ALSA device are we connecting to?

Definition at line 254 of file AudioALSA.cxx.

◆ ~AudioALSA()

SoDa::AudioALSA::~AudioALSA ( )
inline

Definition at line 78 of file AudioALSA.hxx.

Member Function Documentation

◆ recv()

int SoDa::AudioALSA::recv ( void *  buf,
unsigned int  len,
bool  block = true 
)
inlinevirtual

recv – get a buffer of data from the audio input

Parameters
bufbuffer of type described by the DataFormat selected at init
lennumber of elements in the buffer to get
blockmake this a blocking call — ignored.
Returns
number of elements transferred from the audio input

Implements SoDa::AudioIfc.

Definition at line 107 of file AudioALSA.hxx.

◆ recvBufferReady()

bool SoDa::AudioALSA::recvBufferReady ( unsigned int  len)
inlinevirtual

recvBufferReady – are there samples waiting in the audio device?

Parameters
lenthe number of samples that we wish to get
Returns
true if len samples are waiting in in the device buffer

Implements SoDa::AudioIfc.

Definition at line 115 of file AudioALSA.hxx.

◆ send()

int SoDa::AudioALSA::send ( void *  buf,
unsigned int  len 
)
inlinevirtual

send – send a buffer to the audio output

Parameters
bufbuffer of type described by the DataFormat selected at init
lennumber of elements in the buffer to send
Returns
number of elements transferred to the audio output

Implements SoDa::AudioIfc.

Definition at line 90 of file AudioALSA.hxx.

◆ sendBufferReady()

bool SoDa::AudioALSA::sendBufferReady ( unsigned int  len)
inlinevirtual

sendBufferReady – is there enough space in the audio device send buffer for a call from send?

Parameters
lenthe number of samples that we wish to send
Returns
true if there is sufficient space.

Implements SoDa::AudioIfc.

Definition at line 98 of file AudioALSA.hxx.

◆ sleepIn()

void SoDa::AudioALSA::sleepIn ( )
inlinevirtual

stop the input stream so that we don't encounter a buffer overflow while the transmitter is inactive.

Implements SoDa::AudioIfc.

Definition at line 149 of file AudioALSA.hxx.

◆ sleepOut()

void SoDa::AudioALSA::sleepOut ( )
inlinevirtual

stop the output stream so that we don't encounter a buffer underflow while the reciever is muted.

Implements SoDa::AudioIfc.

Definition at line 121 of file AudioALSA.hxx.

◆ wakeIn()

void SoDa::AudioALSA::wakeIn ( )
inlinevirtual

◆ wakeOut()

void SoDa::AudioALSA::wakeOut ( )
inlinevirtual

start the output stream

Implements SoDa::AudioIfc.

Definition at line 129 of file AudioALSA.hxx.


The documentation for this class was generated from the following files: