Async  1.3.1
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 blocksize(void);
179 
192  static void setBlockCount(int count);
193 
203  static void setChannels(int channels);
204 
210  AudioIO(const std::string& dev_name, int channel);
211 
215  ~AudioIO(void);
216 
222  bool isFullDuplexCapable(void);
223 
230  bool open(Mode mode);
231 
235  void close(void);
236 
247  //int samplesToWrite(void) const;
248 
249  /*
250  * @brief Call this method to clear all samples in the buffer
251  *
252  * This method is used to clear all the samples that are in the buffer.
253  * That is, all samples in the buffer will be thrown away. Remaining
254  * samples that have already been written to the sound card will be
255  * flushed and when finished, the allSamplesFlushed signal is emitted.
256  */
257  //void clearSamples(void);
258 
259  /*
260  * @brief Check if the audio device is busy flushing samples
261  * @return Returns \em true if flushing the buffer or else \em false
262  */
263  //bool isFlushing(void) const { return is_flushing; }
264 
265  /*
266  * @brief Find out the current IO mode
267  * @return Returns the current IO mode
268  */
269  Mode mode(void) const { return io_mode; }
270 
280  void setGain(float gain) { m_gain = gain; }
281 
286  float gain(void) const { return m_gain; }
287 
292  int sampleRate(void) const { return sample_rate; }
293 
298  int channel(void) const { return m_channel; }
299 
307  void resumeOutput(void) {}
308 
316  void allSamplesFlushed(void) {}
317 
318 #if 0
319 
325  int writeSamples(const float *samples, int count);
326 
334  void flushSamples(void);
335 #endif
336 
337 
338  protected:
339 
340  private:
341  class InputFifo;
342  class DelayedFlushAudioReader;
343 
344  Mode io_mode;
345  AudioDevice *audio_dev;
346  float m_gain;
347  int sample_rate;
348  int m_channel;
349  AudioValve *input_valve;
350  InputFifo *input_fifo;
351  DelayedFlushAudioReader *audio_reader;
352 
353  // Methods accessed by the Async::AudioDevice class
354  friend class AudioDevice;
355  AudioDevice *device(void) const { return audio_dev; }
356  int readSamples(float *samples, int count);
357  bool doFlush(void) const;
358  bool isIdle(void) const;
359  int audioRead(float *samples, int count);
360  unsigned samplesAvailable(void);
361 
362 }; /* class AudioIO */
363 
364 
365 } /* namespace */
366 
367 #endif /* ASYNC_AUDIO_IO_INCLUDED */
368 
369 
370 /*
371  * This file has not been truncated
372  */
373 
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:307
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.
int blocksize(void)
Find out what the blocksize is set to.
bool isFullDuplexCapable(void)
Check if the audio device is capable of full duplex operation.
No mode. The same as close.
Definition: AsyncAudioIO.h:142
float gain(void) const
Return the gain.
Definition: AsyncAudioIO.h:286
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.
int sampleRate(void) const
Return the sample rate.
Definition: AsyncAudioIO.h:292
Base class for handling audio devices.
Both read and write.
Definition: AsyncAudioIO.h:145
int channel(void) const
Return the audio channel used.
Definition: AsyncAudioIO.h:298
Mode
The different modes to open a device in.
Definition: AsyncAudioIO.h:140
AudioIO(const std::string &dev_name, int channel)
Constructor.
Mode mode(void) const
Find out how many samples there are in the output buffer.
Definition: AsyncAudioIO.h:269
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:316
void setGain(float gain)
Set the gain to use.
Definition: AsyncAudioIO.h:280
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.