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 
Async::AudioPassthrough::writeSamples
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
Definition: AsyncAudioPassthrough.h:197
Async::AudioStreamStateDetector::writeSamples
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
Definition: AsyncAudioStreamStateDetector.h:191
Async::AudioStreamStateDetector::flushSamples
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
Definition: AsyncAudioStreamStateDetector.h:209
Async::AudioStreamStateDetector::isActive
bool isActive(void) const
Check if the steam is active or not.
Definition: AsyncAudioStreamStateDetector.h:247
Async::AudioStreamStateDetector::~AudioStreamStateDetector
virtual ~AudioStreamStateDetector(void)
Destructor.
Definition: AsyncAudioStreamStateDetector.h:178
Async::AudioStreamStateDetector::allSamplesFlushed
virtual void allSamplesFlushed(void)
The registered sink has flushed all samples.
Definition: AsyncAudioStreamStateDetector.h:226
Async::AudioPassthrough::flushSamples
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
Definition: AsyncAudioPassthrough.h:210
Async::AudioStreamStateDetector::sigStreamStateChanged
sigc::signal< void, bool, bool > sigStreamStateChanged
A signal that is emitted when the stream state changes.
Definition: AsyncAudioStreamStateDetector.h:261
Async::AudioStreamStateDetector::isFlushing
bool isFlushing(void) const
Check if the steam is flushing or not.
Definition: AsyncAudioStreamStateDetector.h:254
Async::AudioStreamStateDetector::AudioStreamStateDetector
AudioStreamStateDetector(void)
Default constuctor.
Definition: AsyncAudioStreamStateDetector.h:173
Async::AudioStreamStateDetector::isIdle
bool isIdle(void) const
Check if the steam is idle or not.
Definition: AsyncAudioStreamStateDetector.h:240
AsyncAudioPassthrough.h
This file contains a class that just pass the audio through.
Async
Namespace for the asynchronous programming classes.
Definition: AsyncApplication.h:75
Async::AudioStreamStateDetector
A class that just passes the audio through and fires an event when the stream state changes.
Definition: AsyncAudioStreamStateDetector.h:131
Async::AudioPassthrough::allSamplesFlushed
virtual void allSamplesFlushed(void)
The registered sink has flushed all samples.
Definition: AsyncAudioPassthrough.h:234