Async  1.5.0
AsyncAudioFifo.h
Go to the documentation of this file.
1 
30 #ifndef ASYNC_AUDIO_FIFO_INCLUDED
31 #define ASYNC_AUDIO_FIFO_INCLUDED
32 
33 
34 /****************************************************************************
35  *
36  * System Includes
37  *
38  ****************************************************************************/
39 
40 
41 
42 /****************************************************************************
43  *
44  * Project Includes
45  *
46  ****************************************************************************/
47 
48 #include <AsyncAudioSink.h>
49 #include <AsyncAudioSource.h>
50 
51 
52 /****************************************************************************
53  *
54  * Local Includes
55  *
56  ****************************************************************************/
57 
58 
59 
60 /****************************************************************************
61  *
62  * Forward declarations
63  *
64  ****************************************************************************/
65 
66 
67 
68 /****************************************************************************
69  *
70  * Namespace
71  *
72  ****************************************************************************/
73 
74 namespace Async
75 {
76 
77 
78 /****************************************************************************
79  *
80  * Forward declarations of classes inside of the declared namespace
81  *
82  ****************************************************************************/
83 
84 
85 
86 /****************************************************************************
87  *
88  * Defines & typedefs
89  *
90  ****************************************************************************/
91 
92 
93 
94 /****************************************************************************
95  *
96  * Exported Global Variables
97  *
98  ****************************************************************************/
99 
100 
101 
102 /****************************************************************************
103  *
104  * Class definitions
105  *
106  ****************************************************************************/
107 
119 class AudioFifo : public AudioSink, public AudioSource
120 {
121  public:
127  explicit AudioFifo(unsigned fifo_size);
128 
132  virtual ~AudioFifo(void);
133 
142  void setSize(unsigned new_size);
143 
148  bool empty(void) const { return !is_full && (tail == head); }
149 
158  bool full(void) const { return is_full; }
159 
166  unsigned samplesInFifo(bool ignore_prebuf=false) const;
167 
179  void setOverwrite(bool overwrite) { do_overwrite = overwrite; }
180 
193  bool overwrite(void) const { return do_overwrite; }
194 
201  void clear(void);
202 
208  void setPrebufSamples(unsigned prebuf_samples);
209 
221  void enableBuffering(bool enable);
222 
227  bool bufferingEnabled(void) const { return buffering_enabled; }
228 
240  virtual int writeSamples(const float *samples, int count);
241 
249  virtual void flushSamples(void);
250 
258  virtual void resumeOutput(void);
259 
260 
261  protected:
269  virtual void allSamplesFlushed(void);
270 
271 
272  private:
273  float *fifo;
274  unsigned fifo_size;
275  unsigned head, tail;
276  bool do_overwrite;
277  bool output_stopped;
278  unsigned prebuf_samples;
279  bool prebuf;
280  bool is_flushing;
281  bool is_full;
282  bool buffering_enabled;
283  bool disable_buffering_when_flushed;
284  bool is_idle;
285  bool input_stopped;
286 
287  void writeSamplesFromFifo(void);
288 
289 }; /* class AudioFifo */
290 
291 
292 } /* namespace */
293 
294 #endif /* ASYNC_AUDIO_FIFO_INCLUDED */
295 
296 
297 /*
298  * This file has not been truncated
299  */
300 
Async::AudioFifo::clear
void clear(void)
Clear all samples from the FIFO.
Async::AudioFifo::allSamplesFlushed
virtual void allSamplesFlushed(void)
The registered sink has flushed all samples.
Async::AudioFifo::enableBuffering
void enableBuffering(bool enable)
Enable/disable the fifo buffer.
Async::AudioFifo::flushSamples
virtual void flushSamples(void)
Tell the FIFO to flush the previously written samples.
Async::AudioFifo::setPrebufSamples
void setPrebufSamples(unsigned prebuf_samples)
Set the number of samples that must be in the fifo before any samples are written out from it.
Async::AudioFifo::full
bool full(void) const
Check if the FIFO is full.
Definition: AsyncAudioFifo.h:214
Async::AudioFifo::resumeOutput
virtual void resumeOutput(void)
Resume audio output to the connected sink.
Async::AudioFifo::overwrite
bool overwrite(void) const
Check the overwrite mode.
Definition: AsyncAudioFifo.h:249
Async::AudioFifo::writeSamples
virtual int writeSamples(const float *samples, int count)
Write samples into the FIFO.
Async::AudioFifo::samplesInFifo
unsigned samplesInFifo(bool ignore_prebuf=false) const
Find out how many samples there are in the FIFO.
Async::AudioFifo::empty
bool empty(void) const
Check if the FIFO is empty.
Definition: AsyncAudioFifo.h:204
Async::AudioFifo::~AudioFifo
virtual ~AudioFifo(void)
Destructor.
Async::AudioFifo::AudioFifo
AudioFifo(unsigned fifo_size)
Constuctor.
Async::AudioFifo::setOverwrite
void setOverwrite(bool overwrite)
Set the overwrite mode.
Definition: AsyncAudioFifo.h:235
Async::AudioFifo::setSize
void setSize(unsigned new_size)
Set the size of the FIFO.
Async::AudioFifo::bufferingEnabled
bool bufferingEnabled(void) const
Check if buffering is enabled or disabled.
Definition: AsyncAudioFifo.h:283
Async
Namespace for the asynchronous programming classes.
Definition: AsyncApplication.h:75
AsyncAudioSink.h
This file contains the base class for an audio sink.
AsyncAudioSource.h
This file contains the base class for an audio source.