Async  1.3.1
AsyncAudioRecorder.h
Go to the documentation of this file.
1 
27 #ifndef ASYNC_AUDIO_RECORDER_INCLUDED
28 #define ASYNC_AUDIO_RECORDER_INCLUDED
29 
30 
31 /****************************************************************************
32  *
33  * System Includes
34  *
35  ****************************************************************************/
36 
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <sigc++/sigc++.h>
40 #include <sys/time.h>
41 
42 #include <string>
43 
44 #include <AsyncAudioSink.h>
45 
46 
47 /****************************************************************************
48  *
49  * Project Includes
50  *
51  ****************************************************************************/
52 
53 
54 
55 /****************************************************************************
56  *
57  * Local Includes
58  *
59  ****************************************************************************/
60 
61 
62 
63 /****************************************************************************
64  *
65  * Forward declarations
66  *
67  ****************************************************************************/
68 
69 
70 
71 /****************************************************************************
72  *
73  * Namespace
74  *
75  ****************************************************************************/
76 
77 namespace Async
78 {
79 
80 
81 /****************************************************************************
82  *
83  * Forward declarations of classes inside of the declared namespace
84  *
85  ****************************************************************************/
86 
87 
88 
89 /****************************************************************************
90  *
91  * Defines & typedefs
92  *
93  ****************************************************************************/
94 
95 
96 
97 /****************************************************************************
98  *
99  * Exported Global Variables
100  *
101  ****************************************************************************/
102 
103 
104 
105 /****************************************************************************
106  *
107  * Class definitions
108  *
109  ****************************************************************************/
110 
120 {
121  public:
122  typedef enum { FMT_AUTO, FMT_RAW, FMT_WAV } Format;
123 
130  explicit AudioRecorder(const std::string& filename,
132  int sample_rate=INTERNAL_SAMPLE_RATE);
133 
137  ~AudioRecorder(void);
138 
145  bool initialize(void);
146 
162  void setMaxRecordingTime(unsigned time_ms, unsigned hw_time_ms=0);
163 
170  void closeFile(void);
171 
176  unsigned samplesWritten(void) const { return samples_written; }
177 
182  const struct timeval &beginTimestamp(void) const { return begin_timestamp; }
183 
188  const struct timeval &endTimestamp(void) const { return end_timestamp; }
189 
201  virtual int writeSamples(const float *samples, int count);
202 
211  virtual void flushSamples(void);
212 
221  sigc::signal<void> maxRecordingTimeReached;
222 
223  private:
224  std::string filename;
225  FILE *file;
226  unsigned samples_written;
227  Format format;
228  int sample_rate;
229  unsigned max_samples;
230  unsigned high_water_mark;
231  bool high_water_mark_reached;
232  struct timeval begin_timestamp;
233  struct timeval end_timestamp;
234 
236  AudioRecorder& operator=(const AudioRecorder&);
237  void writeWaveHeader(void);
238  int store32bitValue(char *ptr, uint32_t val);
239  int store16bitValue(char *ptr, uint16_t val);
240 
241 }; /* class AudioRecorder */
242 
243 
244 } /* namespace */
245 
246 #endif /* ASYNC_AUDIO_RECORDER_INCLUDED */
247 
248 
249 
250 /*
251  * This file has not been truncated
252  */
253 
AudioRecorder(const std::string &filename, AudioRecorder::Format fmt=FMT_AUTO, int sample_rate=INTERNAL_SAMPLE_RATE)
Default constuctor.
~AudioRecorder(void)
Destructor.
const struct timeval & endTimestamp(void) const
The timestamp of the last stored sample.
const struct timeval & beginTimestamp(void) const
The timestamp of the first stored sample.
bool initialize(void)
Initialize the recorder.
unsigned samplesWritten(void) const
Find out how many samples that have been written so far.
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
void closeFile(void)
Close the file.
This file contains the base class for an audio sink.
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
The base class for an audio sink.
Namespace for the asynchronous programming classes.
A class for recording raw audio to a file.
void setMaxRecordingTime(unsigned time_ms, unsigned hw_time_ms=0)
Set the maximum length of this recording.
sigc::signal< void > maxRecordingTimeReached
A signal that's emitted when the max recording time is reached.