Async
0.18.0
|
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 00172 static void setBlocksize(int size); 00173 00178 int blocksize(void); 00179 00192 static void setBlockCount(int count); 00193 00203 static void setChannels(int channels); 00204 00210 AudioIO(const std::string& dev_name, int channel); 00211 00215 ~AudioIO(void); 00216 00222 bool isFullDuplexCapable(void); 00223 00230 bool open(Mode mode); 00231 00235 void close(void); 00236 00247 //int samplesToWrite(void) const; 00248 00249 /* 00250 * @brief Call this method to clear all samples in the buffer 00251 * 00252 * This method is used to clear all the samples that are in the buffer. 00253 * That is, all samples in the buffer will be thrown away. Remaining 00254 * samples that have already been written to the sound card will be 00255 * flushed and when finished, the allSamplesFlushed signal is emitted. 00256 */ 00257 //void clearSamples(void); 00258 00259 /* 00260 * @brief Check if the audio device is busy flushing samples 00261 * @return Returns \em true if flushing the buffer or else \em false 00262 */ 00263 //bool isFlushing(void) const { return is_flushing; } 00264 00265 /* 00266 * @brief Find out the current IO mode 00267 * @return Returns the current IO mode 00268 */ 00269 Mode mode(void) const { return io_mode; } 00270 00280 void setGain(float gain) { m_gain = gain; } 00281 00286 float gain(void) const { return m_gain; } 00287 00292 int sampleRate(void) const { return sample_rate; } 00293 00298 int channel(void) const { return m_channel; } 00299 00307 void resumeOutput(void) {} 00308 00316 void allSamplesFlushed(void) {} 00317 00318 #if 0 00319 00325 int writeSamples(const float *samples, int count); 00326 00334 void flushSamples(void); 00335 #endif 00336 00337 00338 protected: 00339 00340 private: 00341 class InputFifo; 00342 class DelayedFlushAudioReader; 00343 00344 Mode io_mode; 00345 AudioDevice *audio_dev; 00346 float m_gain; 00347 int sample_rate; 00348 int m_channel; 00349 AudioValve *input_valve; 00350 InputFifo *input_fifo; 00351 DelayedFlushAudioReader *audio_reader; 00352 00353 // Methods accessed by the Async::AudioDevice class 00354 friend class AudioDevice; 00355 AudioDevice *device(void) const { return audio_dev; } 00356 int readSamples(float *samples, int count); 00357 bool doFlush(void) const; 00358 bool isIdle(void) const; 00359 int audioRead(float *samples, int count); 00360 unsigned samplesAvailable(void); 00361 00362 }; /* class AudioIO */ 00363 00364 00365 } /* namespace */ 00366 00367 #endif /* ASYNC_AUDIO_IO_INCLUDED */ 00368 00369 00370 /* 00371 * This file has not been truncated 00372 */ 00373