Async  1.3.1
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  {
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 blocksize(void) = 0;
191 
205  static void setBlockCount(int count)
206  {
207  block_count_hint = (count <= 0) ? 0 : count;
208  }
209 
219  static void setChannels(int channels)
220  {
222  }
223 
224 
230  virtual bool isFullDuplexCapable(void) = 0;
231 
237  bool open(Mode mode);
238 
242  void close(void);
243 
248  Mode mode(void) const { return current_mode; }
249 
254  virtual void audioToWriteAvailable(void) = 0;
255 
256  /*
257  * @brief Tell the audio device to flush its buffers
258  */
259  virtual void flushSamples(void) = 0;
260 
271  virtual int samplesToWrite(void) const = 0;
272 
277  int sampleRate(void) const { return sample_rate; }
278 
283  const std::string& devName(void) const { return dev_name; }
284 
285 
286  protected:
287  static int sample_rate;
288  static int block_size_hint;
289  static int block_count_hint;
290  static int channels;
291 
292  std::string dev_name;
293 
298  explicit AudioDevice(const std::string& dev_name);
299 
303  virtual ~AudioDevice(void);
304 
310  virtual bool openDevice(Mode mode) = 0;
311 
315  virtual void closeDevice(void) = 0;
316 
317  void putBlocks(int16_t *buf, int frame_cnt);
318  int getBlocks(int16_t *buf, int block_cnt);
319 
320 
321  private:
322  static const int DEFAULT_SAMPLE_RATE = INTERNAL_SAMPLE_RATE;
323  static const int DEFAULT_CHANNELS = 2;
324  static const int DEFAULT_BLOCK_COUNT_HINT = 4;
325  static const int DEFAULT_BLOCK_SIZE_HINT = 256; // Samples/channel/block
326 
327  static std::map<std::string, AudioDevice*> devices;
328 
329  Mode current_mode;
330  int use_count;
331  std::list<AudioIO*> aios;
332 
333 }; /* class AudioDevice */
334 
335 
336 } /* namespace */
337 
338 #endif /* ASYNC_AUDIO_DEVICE_INCLUDED */
339 
340 
341 
342 /*
343  * This file has not been truncated
344  */
345 
int getBlocks(int16_t *buf, int block_cnt)
virtual bool openDevice(Mode mode)=0
Open the audio device.
A class for handling audio input/output to an audio device.
Definition: AsyncAudioIO.h:134
virtual int samplesToWrite(void) const =0
Find out how many samples there are in the output buffer.
virtual void closeDevice(void)=0
Close the audio device.
virtual void flushSamples(void)=0
const std::string & devName(void) const
Return the device name.
static void setChannels(int channels)
Set the number of channels used when doing future opens.
No mode. The same as close.
Base class for handling audio devices.
virtual ~AudioDevice(void)
Destructor.
static AudioDevice * registerAudioIO(const std::string &dev_designator, AudioIO *audio_io)
Register an AudioIO object with the given device name.
virtual void audioToWriteAvailable(void)=0
Tell the audio device handler that there are audio to be written in the buffer.
Namespace for the asynchronous programming classes.
void putBlocks(int16_t *buf, int frame_cnt)
Mode mode(void) const
Get the current operating mode of this audio device.
bool open(Mode mode)
Open the audio device.
AudioDevice(const std::string &dev_name)
Constuctor.
static void setBlockCount(int count)
Set the buffer count used when opening audio devices.
virtual int blocksize(void)=0
Find out what the blocksize is set to.
static int block_count_hint
static void setSampleRate(int rate)
Set the sample rate used when doing future opens.
static void unregisterAudioIO(AudioIO *audio_io)
Unregister a previously registered AudioIO object.
static int block_size_hint
virtual bool isFullDuplexCapable(void)=0
Check if the audio device has full duplex capability.
void close(void)
Close the audio device.
static void setBlocksize(int size)
Set the blocksize used when opening audio devices.
Mode
The different modes to open a device in.
int sampleRate(void) const
Return the sample rate.