Async  1.5.0
AsyncAudioIO.h
Go to the documentation of this file.
1 
36 #ifndef ASYNC_AUDIO_IO_INCLUDED
37 #define ASYNC_AUDIO_IO_INCLUDED
38 
39 
40 /****************************************************************************
41  *
42  * System Includes
43  *
44  ****************************************************************************/
45 
46 #include <cstdio>
47 #include <string>
48 
49 
50 /****************************************************************************
51  *
52  * Project Includes
53  *
54  ****************************************************************************/
55 
56 #include <AsyncFdWatch.h>
57 #include <AsyncTimer.h>
58 #include <AsyncAudioSink.h>
59 #include <AsyncAudioSource.h>
60 
61 
62 /****************************************************************************
63  *
64  * Local Includes
65  *
66  ****************************************************************************/
67 
68 
69 
70 /****************************************************************************
71  *
72  * Forward declarations
73  *
74  ****************************************************************************/
75 
76 
77 
78 /****************************************************************************
79  *
80  * Namespace
81  *
82  ****************************************************************************/
83 
84 namespace Async
85 {
86 
87 /****************************************************************************
88  *
89  * Forward declarations of classes inside of the declared namespace
90  *
91  ****************************************************************************/
92 
93 class AudioDevice;
94 class AudioValve;
95 class AudioFifo;
96 
97 
98 /****************************************************************************
99  *
100  * Defines & typedefs
101  *
102  ****************************************************************************/
103 
104 
105 
106 /****************************************************************************
107  *
108  * Exported Global Variables
109  *
110  ****************************************************************************/
111 
112 
113 
114 /****************************************************************************
115  *
116  * Class definitions
117  *
118  ****************************************************************************/
119 
135 {
136  public:
140  typedef enum
141  {
146  } Mode;
147 
157  static void setSampleRate(int rate);
158 
172  static void setBlocksize(int size);
173 
178  int readBlocksize(void);
179 
184  int writeBlocksize(void);
185 
198  static void setBlockCount(int count);
199 
209  static void setChannels(int channels);
210 
216  AudioIO(const std::string& dev_name, int channel);
217 
221  ~AudioIO(void);
222 
228  bool isFullDuplexCapable(void);
229 
236  bool open(Mode mode);
237 
241  void close(void);
242 
253  //int samplesToWrite(void) const;
254 
255  /*
256  * @brief Call this method to clear all samples in the buffer
257  *
258  * This method is used to clear all the samples that are in the buffer.
259  * That is, all samples in the buffer will be thrown away. Remaining
260  * samples that have already been written to the sound card will be
261  * flushed and when finished, the allSamplesFlushed signal is emitted.
262  */
263  //void clearSamples(void);
264 
265  /*
266  * @brief Check if the audio device is busy flushing samples
267  * @return Returns \em true if flushing the buffer or else \em false
268  */
269  //bool isFlushing(void) const { return is_flushing; }
270 
271  /*
272  * @brief Find out the current IO mode
273  * @return Returns the current IO mode
274  */
275  Mode mode(void) const { return io_mode; }
276 
286  void setGain(float gain) { m_gain = gain; }
287 
292  float gain(void) const { return m_gain; }
293 
298  int sampleRate(void) const { return sample_rate; }
299 
304  int channel(void) const { return m_channel; }
305 
313  void resumeOutput(void) {}
314 
322  void allSamplesFlushed(void) {}
323 
324 #if 0
325 
331  int writeSamples(const float *samples, int count);
332 
340  void flushSamples(void);
341 #endif
342 
343 
344  protected:
345 
346  private:
347  class InputFifo;
348  class DelayedFlushAudioReader;
349 
350  Mode io_mode;
351  AudioDevice *audio_dev;
352  float m_gain;
353  int sample_rate;
354  int m_channel;
355  AudioValve *input_valve;
356  InputFifo *input_fifo;
357  DelayedFlushAudioReader *audio_reader;
358 
359  // Methods accessed by the Async::AudioDevice class
360  friend class AudioDevice;
361  AudioDevice *device(void) const { return audio_dev; }
362  int readSamples(float *samples, int count);
363  bool doFlush(void) const;
364  bool isIdle(void) const;
365  int audioRead(float *samples, int count);
366  unsigned samplesAvailable(void);
367 
368 }; /* class AudioIO */
369 
370 
371 } /* namespace */
372 
373 #endif /* ASYNC_AUDIO_IO_INCLUDED */
374 
375 
376 /*
377  * This file has not been truncated
378  */
379 
float gain(void) const
Return the gain.
Definition: AsyncAudioIO.h:292
static void setChannels(int channels)
Set the number of channels used when doing future opens.
static void setBlockCount(int count)
Set the block count used when opening audio devices.
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
A class for handling audio input/output to an audio device.
Definition: AsyncAudioIO.h:134
void resumeOutput(void)
Resume audio output to the sink.
Definition: AsyncAudioIO.h:313
int readBlocksize(void)
Find out what the read (recording) blocksize is set to.
void close(void)
Close the adio device.
bool open(Mode mode)
Open the audio device in the specified mode.
This file contains the base class for an audio source.
bool isFullDuplexCapable(void)
Check if the audio device is capable of full duplex operation.
int writeBlocksize(void)
Find out what the write (playback) blocksize is set to.
No mode. The same as close.
Definition: AsyncAudioIO.h:142
Contains a single shot or periodic timer that emits a signal on timeout.
~AudioIO(void)
Destructor.
static void setSampleRate(int rate)
Set the sample rate used when doing future opens.
This file contains the base class for an audio sink.
Mode mode(void) const
Find out how many samples there are in the output buffer.
Definition: AsyncAudioIO.h:275
Base class for handling audio devices.
Both read and write.
Definition: AsyncAudioIO.h:145
Mode
The different modes to open a device in.
Definition: AsyncAudioIO.h:140
int channel(void) const
Return the audio channel used.
Definition: AsyncAudioIO.h:304
AudioIO(const std::string &dev_name, int channel)
Constructor.
int sampleRate(void) const
Return the sample rate.
Definition: AsyncAudioIO.h:298
The base class for an audio sink.
Namespace for the asynchronous programming classes.
void allSamplesFlushed(void)
The registered sink has flushed all samples.
Definition: AsyncAudioIO.h:322
void setGain(float gain)
Set the gain to use.
Definition: AsyncAudioIO.h:286
static void setBlocksize(int size)
Set the blocksize used when opening audio devices.
Contains a watch for file descriptors.
The base class for an audio source.
Implements a "valve" for audio.