Async  1.5.0
AsyncAudioDevice.h
Go to the documentation of this file.
1 
28 #ifndef ASYNC_AUDIO_DEVICE_INCLUDED
29 #define ASYNC_AUDIO_DEVICE_INCLUDED
30 
31 
32 /****************************************************************************
33  *
34  * System Includes
35  *
36  ****************************************************************************/
37 
38 #include <sigc++/sigc++.h>
39 #include <stdint.h>
40 
41 #include <string>
42 #include <map>
43 #include <list>
44 
45 
46 /****************************************************************************
47  *
48  * Project Includes
49  *
50  ****************************************************************************/
51 
52 
53 
54 /****************************************************************************
55  *
56  * Local Includes
57  *
58  ****************************************************************************/
59 
60 
61 
62 /****************************************************************************
63  *
64  * Forward declarations
65  *
66  ****************************************************************************/
67 
68 
69 
70 /****************************************************************************
71  *
72  * Namespace
73  *
74  ****************************************************************************/
75 
76 namespace Async
77 {
78 
79 
80 /****************************************************************************
81  *
82  * Forward declarations of classes inside of the declared namespace
83  *
84  ****************************************************************************/
85 
86 class AudioIO;
87 class FdWatch;
88 
89 
90 /****************************************************************************
91  *
92  * Defines & typedefs
93  *
94  ****************************************************************************/
95 
96 
97 
98 /****************************************************************************
99  *
100  * Exported Global Variables
101  *
102  ****************************************************************************/
103 
104 
105 
106 /****************************************************************************
107  *
108  * Class definitions
109  *
110  ****************************************************************************/
111 
122 class AudioDevice : public sigc::trackable
123 {
124  public:
128  typedef enum
129  {
130  MODE_NONE,
131  MODE_RD,
132  MODE_WR,
133  MODE_RDWR
134  } Mode;
135 
147  static AudioDevice *registerAudioIO(const std::string& dev_designator,
148  AudioIO *audio_io);
149 
154  static void unregisterAudioIO(AudioIO *audio_io);
155 
165  static void setSampleRate(int rate) { sample_rate = rate; }
166 
181  static void setBlocksize(int size)
182  {
183  block_size_hint = size;
184  }
185 
190  virtual int readBlocksize(void) = 0;
191 
196  virtual int writeBlocksize(void) = 0;
197 
211  static void setBlockCount(int count)
212  {
213  block_count_hint = (count <= 0) ? 0 : count;
214  }
215 
225  static void setChannels(int channels)
226  {
228  }
229 
230 
236  virtual bool isFullDuplexCapable(void) = 0;
237 
243  bool open(Mode mode);
244 
248  void close(void);
249 
254  Mode mode(void) const { return current_mode; }
255 
260  virtual void audioToWriteAvailable(void) = 0;
261 
262  /*
263  * @brief Tell the audio device to flush its buffers
264  */
265  virtual void flushSamples(void) = 0;
266 
277  virtual int samplesToWrite(void) const = 0;
278 
283  int sampleRate(void) const { return sample_rate; }
284 
289  const std::string& devName(void) const { return dev_name; }
290 
291 
292  protected:
293  static int sample_rate;
294  static int block_size_hint;
295  static int block_count_hint;
296  static int channels;
297 
298  std::string dev_name;
299 
304  explicit AudioDevice(const std::string& dev_name);
305 
309  virtual ~AudioDevice(void);
310 
316  virtual bool openDevice(Mode mode) = 0;
317 
321  virtual void closeDevice(void) = 0;
322 
323  void putBlocks(int16_t *buf, int frame_cnt);
324  int getBlocks(int16_t *buf, int block_cnt);
325 
326 
327  private:
328  static const int DEFAULT_SAMPLE_RATE = INTERNAL_SAMPLE_RATE;
329  static const int DEFAULT_CHANNELS = 2;
330  static const int DEFAULT_BLOCK_COUNT_HINT = 4;
331  static const int DEFAULT_BLOCK_SIZE_HINT = 256; // Samples/channel/block
332 
333  static std::map<std::string, AudioDevice*> devices;
334 
335  Mode current_mode;
336  int use_count;
337  std::list<AudioIO*> aios;
338 
339 }; /* class AudioDevice */
340 
341 
342 } /* namespace */
343 
344 #endif /* ASYNC_AUDIO_DEVICE_INCLUDED */
345 
346 
347 
348 /*
349  * This file has not been truncated
350  */
351 
Async::AudioDevice::channels
static int channels
Definition: AsyncAudioDevice.h:328
Async::AudioDevice::block_size_hint
static int block_size_hint
Definition: AsyncAudioDevice.h:326
Async::AudioDevice::audioToWriteAvailable
virtual void audioToWriteAvailable(void)=0
Tell the audio device handler that there are audio to be written in the buffer.
Async::AudioDevice::getBlocks
int getBlocks(int16_t *buf, int block_cnt)
Async::AudioDevice::~AudioDevice
virtual ~AudioDevice(void)
Destructor.
Async::AudioDevice::Mode
Mode
The different modes to open a device in.
Definition: AsyncAudioDevice.h:160
Async::AudioDevice::sample_rate
static int sample_rate
Definition: AsyncAudioDevice.h:325
Async::AudioDevice::writeBlocksize
virtual int writeBlocksize(void)=0
Find out what the write (playback) blocksize is set to.
Async::AudioDevice::openDevice
virtual bool openDevice(Mode mode)=0
Open the audio device.
Async::AudioDevice::isFullDuplexCapable
virtual bool isFullDuplexCapable(void)=0
Check if the audio device has full duplex capability.
Async::AudioDevice::putBlocks
void putBlocks(int16_t *buf, int frame_cnt)
Async::AudioDevice::MODE_RDWR
@ MODE_RDWR
Both read and write.
Definition: AsyncAudioDevice.h:177
Async::AudioDevice::block_count_hint
static int block_count_hint
Definition: AsyncAudioDevice.h:327
Async::AudioDevice::MODE_NONE
@ MODE_NONE
No mode. The same as close.
Definition: AsyncAudioDevice.h:174
Async::AudioDevice::flushSamples
virtual void flushSamples(void)=0
Async::AudioDevice::MODE_WR
@ MODE_WR
Write.
Definition: AsyncAudioDevice.h:176
Async::AudioDevice::readBlocksize
virtual int readBlocksize(void)=0
Find out what the read (recording) blocksize is set to.
Async::AudioDevice::devName
const std::string & devName(void) const
Return the device name.
Definition: AsyncAudioDevice.h:321
Async::AudioDevice::AudioDevice
AudioDevice(const std::string &dev_name)
Constuctor.
Async::AudioDevice::open
bool open(Mode mode)
Open the audio device.
Async::AudioDevice::setChannels
static void setChannels(int channels)
Set the number of channels used when doing future opens.
Definition: AsyncAudioDevice.h:257
Async::AudioDevice::samplesToWrite
virtual int samplesToWrite(void) const =0
Find out how many samples there are in the output buffer.
Async::AudioDevice::dev_name
std::string dev_name
Definition: AsyncAudioDevice.h:330
Async
Namespace for the asynchronous programming classes.
Definition: AsyncApplication.h:75
Async::AudioDevice::close
void close(void)
Close the audio device.
Async::AudioDevice::setBlocksize
static void setBlocksize(int size)
Set the blocksize used when opening audio devices.
Definition: AsyncAudioDevice.h:213
Async::AudioDevice::setSampleRate
static void setSampleRate(int rate)
Set the sample rate used when doing future opens.
Definition: AsyncAudioDevice.h:197
Async::AudioDevice::mode
Mode mode(void) const
Get the current operating mode of this audio device.
Definition: AsyncAudioDevice.h:286
Async::AudioDevice::registerAudioIO
static AudioDevice * registerAudioIO(const std::string &dev_designator, AudioIO *audio_io)
Register an AudioIO object with the given device name.
Async::AudioDevice::unregisterAudioIO
static void unregisterAudioIO(AudioIO *audio_io)
Unregister a previously registered AudioIO object.
Async::AudioDevice::MODE_RD
@ MODE_RD
Read.
Definition: AsyncAudioDevice.h:175
Async::AudioDevice::sampleRate
int sampleRate(void) const
Return the sample rate.
Definition: AsyncAudioDevice.h:315
Async::AudioDevice::closeDevice
virtual void closeDevice(void)=0
Close the audio device.
Async::AudioDevice::setBlockCount
static void setBlockCount(int count)
Set the buffer count used when opening audio devices.
Definition: AsyncAudioDevice.h:243