Async  1.5.0
AsyncAudioStreamStateDetector.h
Go to the documentation of this file.
1 
29 #ifndef ASYNC_AUDIO_STREAM_STATE_DETECTOR_INCLUDED
30 #define ASYNC_AUDIO_STREAM_STATE_DETECTOR_INCLUDED
31 
32 
33 /****************************************************************************
34  *
35  * System Includes
36  *
37  ****************************************************************************/
38 
39 #include <sigc++/sigc++.h>
40 
41 
42 /****************************************************************************
43  *
44  * Project Includes
45  *
46  ****************************************************************************/
47 
48 #include <AsyncAudioPassthrough.h>
49 
50 
51 /****************************************************************************
52  *
53  * Local Includes
54  *
55  ****************************************************************************/
56 
57 
58 
59 /****************************************************************************
60  *
61  * Forward declarations
62  *
63  ****************************************************************************/
64 
65 
66 
67 /****************************************************************************
68  *
69  * Namespace
70  *
71  ****************************************************************************/
72 
73 namespace Async
74 {
75 
76 
77 /****************************************************************************
78  *
79  * Forward declarations of classes inside of the declared namespace
80  *
81  ****************************************************************************/
82 
83 
84 
85 /****************************************************************************
86  *
87  * Defines & typedefs
88  *
89  ****************************************************************************/
90 
91 
92 
93 /****************************************************************************
94  *
95  * Exported Global Variables
96  *
97  ****************************************************************************/
98 
99 
100 
101 /****************************************************************************
102  *
103  * Class definitions
104  *
105  ****************************************************************************/
106 
111 class AudioStreamStateDetector : public AudioPassthrough, public sigc::trackable
112 {
113  public:
117  AudioStreamStateDetector(void) : stream_state(STREAM_IDLE) {}
118 
122  virtual ~AudioStreamStateDetector(void) {}
123 
135  virtual int writeSamples(const float *samples, int count)
136  {
137  if (stream_state != STREAM_ACTIVE)
138  {
139  stream_state = STREAM_ACTIVE;
140  sigStreamStateChanged(true, false);
141  }
142  return AudioPassthrough::writeSamples(samples, count);
143  }
144 
153  virtual void flushSamples(void)
154  {
155  if (stream_state != STREAM_FLUSHING)
156  {
157  stream_state = STREAM_FLUSHING;
158  sigStreamStateChanged(false, false);
159  }
161  }
162 
170  virtual void allSamplesFlushed(void)
171  {
172  if (stream_state != STREAM_IDLE)
173  {
174  stream_state = STREAM_IDLE;
175  sigStreamStateChanged(false, true);
176  }
178  }
179 
184  bool isIdle(void) const { return (stream_state == STREAM_IDLE); }
185 
191  bool isActive(void) const { return (stream_state == STREAM_ACTIVE); }
192 
198  bool isFlushing(void) const { return (stream_state == STREAM_FLUSHING); }
199 
205  sigc::signal<void, bool, bool> sigStreamStateChanged;
206 
207 
208  private:
211 
212  typedef enum
213  {
214  STREAM_IDLE, STREAM_ACTIVE, STREAM_FLUSHING
215  } StreamState;
216 
217  StreamState stream_state;
218 
219 }; /* AudioStreamStateDetector */
220 
221 
222 } /* namespace */
223 
224 #endif /* ASYNC_AUDIO_STREAM_STATE_DETECTOR_INCLUDED */
225 
226 
227 
228 /*
229  * This file has not been truncated
230  */
231 
virtual void allSamplesFlushed(void)
The registered sink has flushed all samples.
bool isIdle(void) const
Check if the steam is idle or not.
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
virtual void allSamplesFlushed(void)
The registered sink has flushed all samples.
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
virtual ~AudioStreamStateDetector(void)
Destructor.
AudioStreamStateDetector(void)
Default constuctor.
This class just let the audio pass through.
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
bool isFlushing(void) const
Check if the steam is flushing or not.
sigc::signal< void, bool, bool > sigStreamStateChanged
A signal that is emitted when the stream state changes.
bool isActive(void) const
Check if the steam is active or not.
Namespace for the asynchronous programming classes.
This file contains a class that just pass the audio through.
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
A class that just passes the audio through and fires an event when the stream state changes...