Async 1.5.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
76namespace 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
119class 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();
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 float max_samp = 0.0f;
169 for (int i=0; i<count; ++i)
170 {
171 if (samples[i] > max_samp)
172 {
173 max_samp = samples[i];
174 }
175 if (-samples[i] > max_samp)
176 {
177 max_samp = -samples[i];
178 }
179 }
180
181 struct timeval time, diff;
182 gettimeofday(&time, 0);
183
184 timersub(&time, &start_time, &diff);
185 uint64_t diff_ms = diff.tv_sec * 1000 + diff.tv_usec / 1000;
186
187 std::cout << name << "::writeSamples: count=" << count
188 << " ret=" << ret << " sample_rate=";
189 if (diff_ms > 0)
190 {
191 std::cout << sample_count * 1000 / diff_ms;
192 }
193 else
194 {
195 std::cout << "inf";
196 }
197 std::cout << " max=" << max_samp;
198 std::cout << std::endl;
199 return ret;
200 }
201
210 virtual void flushSamples(void)
211 {
212 std::cout << name << "::flushSamples\n";
214 }
215
223 virtual void resumeOutput(void)
224 {
225 std::cout << name << "::resumeOutput\n";
227 }
228
236 virtual void allSamplesFlushed(void)
237 {
238 std::cout << name << "::allSamplesFlushed\n";
240 }
241
242 protected:
243
244 private:
245 std::string name;
246 struct timeval start_time;
247 uint64_t sample_count;
248
250 AudioDebugger& operator=(const AudioDebugger&);
251
252}; /* AudioDebugger */
253
254
255} /* namespace */
256
257#endif /* AUDIO_DEBUGGER_INCLUDED */
258
259
260
261/*
262 * This file has not been truncated
263 */
264
This file contains the base class for an audio sink.
This file contains the base class for an audio source.
This class is used to debug an audio stream.
virtual void resumeOutput(void)
Resume audio output to the sink.
void setName(std::string debug_name)
Set the name that is displayed before debug messages.
virtual ~AudioDebugger(void)
Destructor.
AudioDebugger(Async::AudioSource *src=0)
Default constuctor.
virtual void allSamplesFlushed(void)
The registered sink has flushed all samples.
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
The base class for an audio sink.
void sourceAllSamplesFlushed(void)
Tell the source that all samples have been flushed.
bool registerSource(AudioSource *source)
Register an audio source to provide samples to this sink.
void sourceResumeOutput(void)
Tell the source that we are ready to accept more samples.
The base class for an audio source.
bool registerSink(AudioSink *sink, bool managed=false)
Register an audio sink to provide samples to.
AudioSink * sink(void) const
Get the registered audio sink.
void sinkFlushSamples(void)
int sinkWriteSamples(const float *samples, int len)
Namespace for the asynchronous programming classes.