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 
134 class AudioIO : public Async::AudioSource, public Async::AudioSink
135 {
136  public:
140  typedef enum
141  {
142  MODE_NONE,
143  MODE_RD,
144  MODE_WR,
145  MODE_RDWR
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 
Async::AudioIO::sampleRate
int sampleRate(void) const
Return the sample rate.
Definition: AsyncAudioIO.h:330
Async::AudioIO::setSampleRate
static void setSampleRate(int rate)
Set the sample rate used when doing future opens.
AsyncTimer.h
Contains a single shot or periodic timer that emits a signal on timeout.
Async::AudioIO::channel
int channel(void) const
Return the audio channel used.
Definition: AsyncAudioIO.h:336
Async::AudioDevice
Base class for handling audio devices.
Definition: AsyncAudioDevice.h:142
Async::AudioIO::Mode
Mode
The different modes to open a device in.
Definition: AsyncAudioIO.h:172
Async::AudioValve
Implements a "valve" for audio.
Definition: AsyncAudioValve.h:136
Async::AudioIO::AudioIO
AudioIO(const std::string &dev_name, int channel)
Constructor.
Async::AudioIO::allSamplesFlushed
void allSamplesFlushed(void)
The registered sink has flushed all samples.
Definition: AsyncAudioIO.h:354
Async::AudioIO::gain
float gain(void) const
Return the gain.
Definition: AsyncAudioIO.h:324
Async::AudioIO::setBlocksize
static void setBlocksize(int size)
Set the blocksize used when opening audio devices.
AsyncFdWatch.h
Contains a watch for file descriptors.
Async::AudioSource
The base class for an audio source.
Definition: AsyncAudioSource.h:134
Async::AudioIO::MODE_WR
@ MODE_WR
Write.
Definition: AsyncAudioIO.h:188
Async::AudioIO::setGain
void setGain(float gain)
Set the gain to use.
Definition: AsyncAudioIO.h:318
Async::AudioIO::MODE_RDWR
@ MODE_RDWR
Both read and write.
Definition: AsyncAudioIO.h:189
Async::AudioIO::setBlockCount
static void setBlockCount(int count)
Set the block count used when opening audio devices.
Async::AudioIO::MODE_NONE
@ MODE_NONE
No mode. The same as close.
Definition: AsyncAudioIO.h:186
Async::AudioSink
The base class for an audio sink.
Definition: AsyncAudioSink.h:135
Async::AudioIO::resumeOutput
void resumeOutput(void)
Resume audio output to the sink.
Definition: AsyncAudioIO.h:345
Async::AudioIO::setChannels
static void setChannels(int channels)
Set the number of channels used when doing future opens.
Async::AudioIO::readBlocksize
int readBlocksize(void)
Find out what the read (recording) blocksize is set to.
Async::AudioIO::close
void close(void)
Close the adio device.
Async::AudioSink::flushSamples
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
Definition: AsyncAudioSink.h:210
Async
Namespace for the asynchronous programming classes.
Definition: AsyncApplication.h:75
Async::AudioSink::writeSamples
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
Definition: AsyncAudioSink.h:196
AsyncAudioSink.h
This file contains the base class for an audio sink.
Async::AudioIO::~AudioIO
~AudioIO(void)
Destructor.
Async::AudioIO::open
bool open(Mode mode)
Open the audio device in the specified mode.
AsyncAudioSource.h
This file contains the base class for an audio source.
Async::AudioIO::writeBlocksize
int writeBlocksize(void)
Find out what the write (playback) blocksize is set to.
Async::AudioIO::MODE_RD
@ MODE_RD
Read.
Definition: AsyncAudioIO.h:187
Async::AudioIO::isFullDuplexCapable
bool isFullDuplexCapable(void)
Check if the audio device is capable of full duplex operation.
Async::AudioIO::mode
Mode mode(void) const
Find out how many samples there are in the output buffer.
Definition: AsyncAudioIO.h:307