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 SampleFifo;
00095 class AudioValve;
00096 class AudioFifo;
00097 
00098 
00099 /****************************************************************************
00100  *
00101  * Defines & typedefs
00102  *
00103  ****************************************************************************/
00104 
00105 
00106   
00107 /****************************************************************************
00108  *
00109  * Exported Global Variables
00110  *
00111  ****************************************************************************/
00112 
00113 
00114 
00115 /****************************************************************************
00116  *
00117  * Class definitions
00118  *
00119  ****************************************************************************/
00120 
00135 class AudioIO : public Async::AudioSource, public Async::AudioSink
00136 {
00137   public:
00141     typedef enum
00142     {
00143       MODE_NONE,  
00144       MODE_RD,    
00145       MODE_WR,    
00146       MODE_RDWR   
00147     } Mode;
00148   
00158     static void setSampleRate(int rate);
00159     
00174     static int setBlocksize(int size);
00175 
00180     static int blocksize(void);
00181     
00195     static int setBufferCount(int count);
00196     
00206     static void setChannels(int channels);
00207     
00213     AudioIO(const std::string& dev_name, int channel);
00214     
00218     ~AudioIO(void);
00219   
00225     bool isFullDuplexCapable(void);
00226   
00233     bool open(Mode mode);
00234   
00238     void close(void);
00239   
00250     //int samplesToWrite(void) const;
00251     
00252     /*
00253      * @brief   Call this method to clear all samples in the buffer
00254      *
00255      * This method is used to clear all the samples that are in the buffer.
00256      * That is, all samples in the buffer will be thrown away. Remaining
00257      * samples that have already been written to the sound card will be
00258      * flushed and when finished, the allSamplesFlushed signal is emitted.
00259      */
00260     //void clearSamples(void);
00261     
00262     /*
00263      * @brief   Check if the audio device is busy flushing samples
00264      * @return  Returns \em true if flushing the buffer or else \em false
00265      */
00266     //bool isFlushing(void) const { return is_flushing; }
00267     
00268     /*
00269      * @brief   Find out the current IO mode
00270      * @return  Returns the current IO mode
00271      */
00272     Mode mode(void) const { return io_mode; }
00273     
00283     void setGain(float gain) { m_gain = gain; }
00284 
00289     float gain(void) const { return m_gain; }
00290     
00295     int sampleRate(void) const { return sample_rate; }
00296     
00301     int channel(void) const { return m_channel; }
00302     
00310     void resumeOutput(void) {}
00311     
00319     void allSamplesFlushed(void) {}
00320 
00321 #if 0
00322 
00328     int writeSamples(const float *samples, int count);
00329     
00337     void flushSamples(void);
00338 #endif
00339 
00340             
00341   protected:
00342     
00343   private:
00344     class InputFifo;
00345     class DelayedFlushAudioReader;
00346     
00347     Mode                    io_mode;
00348     AudioDevice             *audio_dev;
00349     //SampleFifo              *write_fifo;
00350     //SigC::Connection      read_con;
00351     //bool                    do_flush;
00352     //Async::Timer          *flush_timer;
00353     //bool                    is_flushing;
00354     //int                     lead_in_pos;
00355     float                   m_gain;
00356     int                     sample_rate;
00357     int                     m_channel;
00358     AudioValve              *input_valve;
00359     InputFifo               *input_fifo;
00360     DelayedFlushAudioReader *audio_reader;
00361 
00362     //void audioReadHandler(Async::FdWatch *watch);
00363     //void flushSamplesInDevice(int extra_samples=0);
00364     //void flushDone(Timer *timer);
00365     //void fifoBufferFull(bool is_full);
00366     
00367       // Methods accessed by the Async::AudioDevice class
00368     friend class AudioDevice;
00369     AudioDevice *device(void) const { return audio_dev; }
00370     //SampleFifo &writeFifo(void) const { return *write_fifo; }
00371     int readSamples(float *samples, int count);
00372     bool doFlush(void) const;
00373     bool isIdle(void) const;
00374     int audioRead(float *samples, int count);
00375     unsigned samplesAvailable(void);
00376 
00377 };  /* class AudioIO */
00378 
00379 
00380 } /* namespace */
00381 
00382 #endif /* ASYNC_AUDIO_IO_INCLUDED */
00383 
00384 
00385 
00386 /*
00387  * This file has not been truncated
00388  */
00389 

Generated on Thu Feb 26 15:26:30 2009 for Async by  doxygen 1.5.8