AsyncAudioIO.h

Go to the documentation of this file.
00001 
00036 #ifndef ASYNC_AUDIO_IO_INCLUDED
00037 #define ASYNC_AUDIO_IO_INCLUDED
00038 
00039 
00040 /****************************************************************************
00041  *
00042  * System Includes
00043  *
00044  ****************************************************************************/
00045 
00046 #include <cstdio>
00047 #include <string>
00048 
00049 
00050 /****************************************************************************
00051  *
00052  * Project Includes
00053  *
00054  ****************************************************************************/
00055 
00056 #include <AsyncFdWatch.h>
00057 #include <AsyncTimer.h>
00058 #include <AsyncAudioSink.h>
00059 #include <AsyncAudioSource.h>
00060 
00061 
00062 /****************************************************************************
00063  *
00064  * Local Includes
00065  *
00066  ****************************************************************************/
00067 
00068 
00069 
00070 /****************************************************************************
00071  *
00072  * Forward declarations
00073  *
00074  ****************************************************************************/
00075 
00076 
00077 
00078 /****************************************************************************
00079  *
00080  * Namespace
00081  *
00082  ****************************************************************************/
00083 
00084 namespace Async
00085 {
00086 
00087 /****************************************************************************
00088  *
00089  * Forward declarations of classes inside of the declared namespace
00090  *
00091  ****************************************************************************/
00092 
00093 class AudioDevice;
00094 class AudioValve;
00095 class AudioFifo;
00096 
00097 
00098 /****************************************************************************
00099  *
00100  * Defines & typedefs
00101  *
00102  ****************************************************************************/
00103 
00104 
00105   
00106 /****************************************************************************
00107  *
00108  * Exported Global Variables
00109  *
00110  ****************************************************************************/
00111 
00112 
00113 
00114 /****************************************************************************
00115  *
00116  * Class definitions
00117  *
00118  ****************************************************************************/
00119 
00134 class AudioIO : public Async::AudioSource, public Async::AudioSink
00135 {
00136   public:
00140     typedef enum
00141     {
00142       MODE_NONE,  
00143       MODE_RD,    
00144       MODE_WR,    
00145       MODE_RDWR   
00146     } Mode;
00147   
00157     static void setSampleRate(int rate);
00158     
00173     static int setBlocksize(int size);
00174 
00179     static int blocksize(void);
00180     
00194     static int setBufferCount(int count);
00195     
00205     static void setChannels(int channels);
00206     
00212     AudioIO(const std::string& dev_name, int channel);
00213     
00217     ~AudioIO(void);
00218   
00224     bool isFullDuplexCapable(void);
00225   
00232     bool open(Mode mode);
00233   
00237     void close(void);
00238   
00249     //int samplesToWrite(void) const;
00250     
00251     /*
00252      * @brief   Call this method to clear all samples in the buffer
00253      *
00254      * This method is used to clear all the samples that are in the buffer.
00255      * That is, all samples in the buffer will be thrown away. Remaining
00256      * samples that have already been written to the sound card will be
00257      * flushed and when finished, the allSamplesFlushed signal is emitted.
00258      */
00259     //void clearSamples(void);
00260     
00261     /*
00262      * @brief   Check if the audio device is busy flushing samples
00263      * @return  Returns \em true if flushing the buffer or else \em false
00264      */
00265     //bool isFlushing(void) const { return is_flushing; }
00266     
00267     /*
00268      * @brief   Find out the current IO mode
00269      * @return  Returns the current IO mode
00270      */
00271     Mode mode(void) const { return io_mode; }
00272     
00282     void setGain(float gain) { m_gain = gain; }
00283 
00288     float gain(void) const { return m_gain; }
00289     
00294     int sampleRate(void) const { return sample_rate; }
00295     
00300     int channel(void) const { return m_channel; }
00301     
00309     void resumeOutput(void) {}
00310     
00318     void allSamplesFlushed(void) {}
00319 
00320 #if 0
00321 
00327     int writeSamples(const float *samples, int count);
00328     
00336     void flushSamples(void);
00337 #endif
00338 
00339             
00340   protected:
00341     
00342   private:
00343     class InputFifo;
00344     class DelayedFlushAudioReader;
00345     
00346     Mode                    io_mode;
00347     AudioDevice             *audio_dev;
00348     float                   m_gain;
00349     int                     sample_rate;
00350     int                     m_channel;
00351     AudioValve              *input_valve;
00352     InputFifo               *input_fifo;
00353     DelayedFlushAudioReader *audio_reader;
00354 
00355       // Methods accessed by the Async::AudioDevice class
00356     friend class AudioDevice;
00357     AudioDevice *device(void) const { return audio_dev; }
00358     int readSamples(float *samples, int count);
00359     bool doFlush(void) const;
00360     bool isIdle(void) const;
00361     int audioRead(float *samples, int count);
00362     unsigned samplesAvailable(void);
00363 
00364 };  /* class AudioIO */
00365 
00366 
00367 } /* namespace */
00368 
00369 #endif /* ASYNC_AUDIO_IO_INCLUDED */
00370 
00371 
00372 /*
00373  * This file has not been truncated
00374  */
00375 
Generated by  doxygen 1.6.2-20100208