Async  0.18.0
AsyncAudioDebugger.h
Go to the documentation of this file.
1 
28 #ifndef AUDIO_DEBUGGER_INCLUDED
29 #define AUDIO_DEBUGGER_INCLUDED
30 
31 
32 /****************************************************************************
33  *
34  * System Includes
35  *
36  ****************************************************************************/
37 
38 #include <sys/time.h>
39 #include <iostream>
40 #include <string>
41 #include <stdint.h>
42 
43 
44 /****************************************************************************
45  *
46  * Project Includes
47  *
48  ****************************************************************************/
49 
50 #include <AsyncAudioSink.h>
51 #include <AsyncAudioSource.h>
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 
87 
88 /****************************************************************************
89  *
90  * Defines & typedefs
91  *
92  ****************************************************************************/
93 
94 
95 
96 /****************************************************************************
97  *
98  * Exported Global Variables
99  *
100  ****************************************************************************/
101 
102 
103 
104 /****************************************************************************
105  *
106  * Class definitions
107  *
108  ****************************************************************************/
109 
119 class AudioDebugger : public AudioSink, public AudioSource
120 {
121  public:
126  : name("AudioDebugger"), sample_count(0)
127  {
128  gettimeofday(&start_time, 0);
129  if (src != 0)
130  {
131  Async::AudioSink *sink = src->sink();
132  if (sink != 0)
133  {
134  src->unregisterSink();
135  registerSink(sink);
136  }
137  registerSource(src);
138  }
139  }
140 
144  virtual ~AudioDebugger(void) {}
145 
150  void setName(std::string debug_name) { name = debug_name; }
151 
163  virtual int writeSamples(const float *samples, int count)
164  {
165  int ret = sinkWriteSamples(samples, count);
166  sample_count += ret;
167 
168  struct timeval time, diff;
169  gettimeofday(&time, 0);
170 
171  timersub(&time, &start_time, &diff);
172  uint64_t diff_ms = diff.tv_sec * 1000 + diff.tv_usec / 1000;
173 
174  std::cout << name << "::writeSamples: count=" << count
175  << " ret=" << ret << " sample_rate=";
176  if (diff_ms > 0)
177  {
178  std::cout << sample_count * 1000 / diff_ms << std::endl;
179  }
180  else
181  {
182  std::cout << "inf\n";
183  }
184  return ret;
185  }
186 
195  virtual void flushSamples(void)
196  {
197  std::cout << name << "::flushSamples\n";
199  }
200 
208  virtual void resumeOutput(void)
209  {
210  std::cout << name << "::resumeOutput\n";
212  }
213 
221  virtual void allSamplesFlushed(void)
222  {
223  std::cout << name << "::allSamplesFlushed\n";
225  }
226 
227  protected:
228 
229  private:
230  std::string name;
231  struct timeval start_time;
232  uint64_t sample_count;
233 
235  AudioDebugger& operator=(const AudioDebugger&);
236 
237 }; /* AudioDebugger */
238 
239 
240 } /* namespace */
241 
242 #endif /* AUDIO_DEBUGGER_INCLUDED */
243 
244 
245 
246 /*
247  * This file has not been truncated
248  */
249