gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
ALSA::FullDuplex< FRAME_TYPE > Class Template Referenceabstract

#include <FullDuplex.H>

Inheritance diagram for ALSA::FullDuplex< FRAME_TYPE >:
[legend]
Collaboration diagram for ALSA::FullDuplex< FRAME_TYPE >:
[legend]

Public Member Functions

 FullDuplex (const char *devName)
 
 FullDuplex (const char *playDevName, const char *captureDevName)
 
virtual ~FullDuplex (void)
 
int link ()
 
int unLink ()
 
virtual int go ()
 
int resetParams ()
 
int setFormat (snd_pcm_format_t format)
 
int setAccess (snd_pcm_access_t access)
 
int setSampleRate (unsigned int rrate, int dir=0)
 
int setBufSize (snd_pcm_uframes_t bufSize)
 
int setChannels (unsigned int cnt)
 
- Public Member Functions inherited from ALSA::Capture
 Capture (const char *devName)
 
 Capture ()
 Constructor. More...
 
int readBuf (char *buffer, size_t len)
 
template<typename Derived >
int readBuf (const Eigen::DenseBase< Derived > &audioData)
 
template<typename Derived >
Captureoperator>> (const Eigen::DenseBase< Derived > &audioData)
 
- Public Member Functions inherited from ALSA::Stream
 Stream ()
 Constructor. More...
 
int init (const char *device, snd_pcm_stream_t streamType, bool blockIn)
 
virtual ~Stream ()
 Destructor. More...
 
const char * getFormatName (const snd_pcm_format_t format)
 get name of PCM sample format More...
 
int open (const char *device, snd_pcm_stream_t streamType, const int block)
 
int setParams ()
 
int setSilence (void *data, unsigned int samples)
 Silence a PCM samples buffer. More...
 
int link (Stream &s)
 
int wait (int timeOut=1000)
 
int getFormatBits ()
 
- Public Member Functions inherited from ALSA::Software
 Software (void)
 
virtual ~Software (void)
 
int getSWParams ()
 
int setSWParams ()
 
int setSWThreshold (snd_pcm_uframes_t thresh)
 
int setAvailMin (snd_pcm_uframes_t cnt)
 
void * getAddress (const snd_pcm_channel_area_t *areas, snd_pcm_uframes_t offset) const
 
template<typename SAMPLE_TYPE >
int getChannelCount (const snd_pcm_channel_area_t *areas) const
 
int dumpSWParams ()
 
- Public Member Functions inherited from ALSA::Hardware
int getHWParams ()
 
int fillParams ()
 
int resetParams ()
 
 Hardware ()
 
virtual ~Hardware ()
 
void copyFrom (snd_pcm_hw_params_t *hParamsIn)
 
int rateResample (unsigned int state)
 
int setAccess (snd_pcm_access_t access)
 
int getAccess (void)
 
int setFormat (snd_pcm_format_t format)
 
int getFormat (snd_pcm_format_t &format)
 
int getFormatPhysicalWidth ()
 
int setChannels (unsigned int cnt)
 
int getChannels ()
 
int getMaxChannels ()
 
int setSampleRate (unsigned int rrate, int dir=0)
 
int getSampleRate (int dir=0)
 
int getPeriodSize (snd_pcm_uframes_t *p, int *dir=NULL)
 
int getPeriodSize (int *dir=NULL)
 
int setPeriodSize (snd_pcm_uframes_t *p, int *dir=0)
 
int setBufSize (snd_pcm_uframes_t bufSize)
 
const char * formatDescription (const snd_pcm_format_t format) const
 
const char * getDeviceName ()
 
int dumpHWParams ()
 
- Public Member Functions inherited from ALSA::PCM
 PCM ()
 
virtual ~PCM ()
 
virtual snd_pcm_t * getPCM ()
 
snd_pcm_t ** getPCMP ()
 
int open (const char *device, snd_pcm_stream_t streamType, const int block)
 
int close ()
 
int drop ()
 
int drain ()
 
int reset ()
 
void enableLog ()
 
int logEnabled ()
 
int dumpStatus ()
 
int dumpPCM ()
 
int dumpSetup ()
 
int dumpHWSetup ()
 
int dumpSWSetup ()
 
int start ()
 
snd_pcm_state_t getState ()
 
const char * getStateName ()
 
bool prepared ()
 
bool opened ()
 
bool isSetup ()
 
bool running ()
 
bool hasXrun ()
 
bool draining ()
 
bool paused ()
 
bool suspended ()
 
bool disconnected ()
 
- Public Member Functions inherited from ALSA::Playback
 Playback (const char *devName)
 
 Playback ()
 
virtual ~Playback (void)
 
void open (const char *devName="default")
 
int writeBuf (void **buffers, size_t len, int ch)
 
template<typename Derived >
int writeBufN (const Eigen::DenseBase< Derived > &audioData)
 
int writeBuf (char *bufferIn, size_t len)
 
template<typename Derived >
int writeBuf (const Eigen::DenseBase< Derived > &audioData)
 
template<typename Derived >
Playbackoperator<< (const Eigen::DenseBase< Derived > &audioData)
 

Protected Attributes

Eigen::Array< FRAME_TYPE, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > inputAudio
 The input audio variable, columns are channels, rows are frames (samples). More...
 
Eigen::Array< FRAME_TYPE, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > outputAudio
 The output audio variable, columns are channels, rows are frames (samples). More...
 
- Protected Attributes inherited from ALSA::Stream
bool block
 Whether to block or use NONBLOCK. More...
 
- Protected Attributes inherited from ALSA::PCM
snd_output_t * log
 The log stream if enabled. More...
 
snd_pcm_t * handle
 PCM handle. More...
 

Private Member Functions

int writeReadProcess ()
 
virtual int process ()=0
 

Additional Inherited Members

- Protected Member Functions inherited from ALSA::Hardware
int setHWParams ()
 

Detailed Description

template<typename FRAME_TYPE>
class ALSA::FullDuplex< FRAME_TYPE >

Class to operate ALSA in a full duplex mode. The process is write out, read in and process. You implement the process method. An example is like so :

class FullDuplexTest : public FullDuplex {
int N;
int ch;
int process(){
if (inputAudio.rows()!=N || inputAudio.cols()!=ch){ // force resize on the first pass through
inputAudio.resize(N, ch);
outputAudio.resize(N, ch);
}
outputAudio=inputAudio; // copy the input to output.
return 0; // return 0 to continue
}
public:
FullDuplexTest(const char*devName, int latency) : FullDuplex(devName){
ch=2; // use this static number of input and output channels.
N=latency;
inputAudio.resize(0,0); // force zero size to ensure resice on the first process.
outputAudio.resize(0,0);
}
};
Examples:
ALSAFullDuplexTest.C.

Definition at line 50 of file FullDuplex.H.

Constructor & Destructor Documentation

◆ FullDuplex() [1/2]

template<typename FRAME_TYPE >
ALSA::FullDuplex< FRAME_TYPE >::FullDuplex ( const char *  devName)
inline

Constructor using the same device for both capture and playback.

Parameters
devNameThe device name to use

Definition at line 80 of file FullDuplex.H.

◆ FullDuplex() [2/2]

template<typename FRAME_TYPE >
ALSA::FullDuplex< FRAME_TYPE >::FullDuplex ( const char *  playDevName,
const char *  captureDevName 
)
inline

Constructor using the different devices for capture and playback.

Parameters
playDevNameThe device name to use
captureDevNameThe device name to use

Definition at line 86 of file FullDuplex.H.

◆ ~FullDuplex()

template<typename FRAME_TYPE >
virtual ALSA::FullDuplex< FRAME_TYPE >::~FullDuplex ( void  )
inlinevirtual

Destructor

Definition at line 90 of file FullDuplex.H.

Member Function Documentation

◆ go()

template<typename FRAME_TYPE >
virtual int ALSA::FullDuplex< FRAME_TYPE >::go ( )
inlinevirtual

Begin the read and write process. Your process method is called once before starting the ALSA read/write functions. This allows you to initialise your member variables as required in a non-realtime fashion. This method will set the channels as you require them and prepare the playback/capture hardware/software.

Returns
<0 on error, >0 on success.

Definition at line 112 of file FullDuplex.H.

Here is the call graph for this function:

◆ link()

template<typename FRAME_TYPE >
int ALSA::FullDuplex< FRAME_TYPE >::link ( )
inline

link the capture and playback devices.

Returns
<0 on error.

Definition at line 95 of file FullDuplex.H.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

template<typename FRAME_TYPE >
virtual int ALSA::FullDuplex< FRAME_TYPE >::process ( )
privatepure virtual

Your class must inherit this class and implement the process method. The inputAudio and outputAudio variables should be resized to the number of channels and frames you want to process. Note that the number of frames must be the same for both the inputAudio and outputAudio variables.

Returns
<0 on error, 0 to continue and >0 to stop.
Here is the caller graph for this function:

◆ resetParams()

template<typename FRAME_TYPE >
int ALSA::FullDuplex< FRAME_TYPE >::resetParams ( )
inline

Reset the params with a full configuration space for both PCMs. Note you have to call setAccess, setFormat, setChannels, setSampleRate if you call this.

Returns
>= 0 on success

Definition at line 176 of file FullDuplex.H.

Here is the call graph for this function:

◆ setAccess()

template<typename FRAME_TYPE >
int ALSA::FullDuplex< FRAME_TYPE >::setAccess ( snd_pcm_access_t  access)
inline
See also
Hardware::setAccess Set the interleaving of the hardware.

Definition at line 196 of file FullDuplex.H.

Here is the call graph for this function:

◆ setBufSize()

template<typename FRAME_TYPE >
int ALSA::FullDuplex< FRAME_TYPE >::setBufSize ( snd_pcm_uframes_t  bufSize)
inline

Set the buffer size

Parameters
thedesired buffer size
Returns
<0 on error.

Definition at line 220 of file FullDuplex.H.

Here is the call graph for this function:

◆ setChannels()

template<typename FRAME_TYPE >
int ALSA::FullDuplex< FRAME_TYPE >::setChannels ( unsigned int  cnt)
inline

Set the number of channels

Parameters
cntThe number of channels.
Returns
>= 0 on success

Definition at line 231 of file FullDuplex.H.

Here is the call graph for this function:

◆ setFormat()

template<typename FRAME_TYPE >
int ALSA::FullDuplex< FRAME_TYPE >::setFormat ( snd_pcm_format_t  format)
inline
See also
Hardware::setFormat Set the word format of the hardware

Definition at line 186 of file FullDuplex.H.

Here is the call graph for this function:

◆ setSampleRate()

template<typename FRAME_TYPE >
int ALSA::FullDuplex< FRAME_TYPE >::setSampleRate ( unsigned int  rrate,
int  dir = 0 
)
inline

Set the sample rate closest to the desired rate.

See also
Hardware::setSampleRate
Parameters
rrateThe desired sample rate.
dirThe direction to search in (-1,0,1)
Returns
>= 0 on success

Definition at line 209 of file FullDuplex.H.

Here is the call graph for this function:

◆ unLink()

template<typename FRAME_TYPE >
int ALSA::FullDuplex< FRAME_TYPE >::unLink ( )
inline

unlink the capture and playback devices.

Returns
<0 on error.

Definition at line 102 of file FullDuplex.H.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeReadProcess()

template<typename FRAME_TYPE >
int ALSA::FullDuplex< FRAME_TYPE >::writeReadProcess ( )
inlineprivate

write, read and process.

Returns
<0 on error, 0 to continue, >0 to stop

Definition at line 54 of file FullDuplex.H.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ inputAudio

template<typename FRAME_TYPE >
Eigen::Array<FRAME_TYPE, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> ALSA::FullDuplex< FRAME_TYPE >::inputAudio
protected

The input audio variable, columns are channels, rows are frames (samples).

Definition at line 72 of file FullDuplex.H.

◆ outputAudio

template<typename FRAME_TYPE >
Eigen::Array<FRAME_TYPE, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> ALSA::FullDuplex< FRAME_TYPE >::outputAudio
protected

The output audio variable, columns are channels, rows are frames (samples).

Definition at line 74 of file FullDuplex.H.


The documentation for this class was generated from the following file:
gtkIOStream: ALSA::FullDuplex< FRAME_TYPE > Class Template Reference
GTK+ IOStream  Beta