Async 1.8.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
84namespace Async
85{
86
87/****************************************************************************
88 *
89 * Forward declarations of classes inside of the declared namespace
90 *
91 ****************************************************************************/
92
93class AudioDevice;
94class AudioValve;
95class 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:
147
157 static void setSampleRate(int rate);
158
172 static void setBlocksize(size_t size);
173
178 size_t readBlocksize(void);
179
184 size_t writeBlocksize(void);
185
198 static void setBlockCount(size_t count);
199
209 static void setChannels(size_t channels);
210
216 AudioIO(const std::string& dev_name, size_t channel);
217
221 ~AudioIO(void);
222
229
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 size_t channel(void) const { return m_channel; }
305
313 void resumeOutput(void) {}
314
322 void allSamplesFlushed(void) {}
323
324#if 0
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 size_t 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
This file contains the base class for an audio sink.
This file contains the base class for an audio source.
Contains a watch for file descriptors.
Contains a single shot or periodic timer that emits a signal on timeout.
Base class for handling audio devices.
A class for handling audio input/output to an audio device.
static void setBlocksize(size_t size)
Set the blocksize used when opening audio devices.
size_t readBlocksize(void)
Find out what the read (recording) blocksize is set to.
bool isFullDuplexCapable(void)
Check if the audio device is capable of full duplex operation.
float gain(void) const
Return the gain.
static void setBlockCount(size_t count)
Set the block count used when opening audio devices.
size_t writeBlocksize(void)
Find out what the write (playback) blocksize is set to.
bool open(Mode mode)
Open the audio device in the specified mode.
int sampleRate(void) const
Return the sample rate.
static void setChannels(size_t channels)
Set the number of channels used when doing future opens.
void resumeOutput(void)
Resume audio output to the sink.
~AudioIO(void)
Destructor.
size_t channel(void) const
Return the audio channel used.
Mode
The different modes to open a device in.
@ MODE_NONE
No mode. The same as close.
@ MODE_RDWR
Both read and write.
void close(void)
Close the adio device.
AudioIO(const std::string &dev_name, size_t channel)
Constructor.
void setGain(float gain)
Set the gain to use.
Mode mode(void) const
Find out how many samples there are in the output buffer.
static void setSampleRate(int rate)
Set the sample rate used when doing future opens.
void allSamplesFlushed(void)
The registered sink has flushed all samples.
The base class for an audio sink.
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.
The base class for an audio source.
Implements a "valve" for audio.
Namespace for the asynchronous programming classes.