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
00043
00044
00045
00046 #include <cstdio>
00047 #include <string>
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include <AsyncFdWatch.h>
00057 #include <AsyncTimer.h>
00058 #include <AsyncAudioSink.h>
00059 #include <AsyncAudioSource.h>
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 namespace Async
00085 {
00086
00087
00088
00089
00090
00091
00092
00093 class AudioDevice;
00094
00095 class AudioValve;
00096 class AudioFifo;
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
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
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
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
00350
00351
00352
00353
00354
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
00363
00364
00365
00366
00367
00368 friend class AudioDevice;
00369 AudioDevice *device(void) const { return audio_dev; }
00370
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 };
00378
00379
00380 }
00381
00382 #endif
00383
00384
00385
00386
00387
00388
00389