Async  1.5.0
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 
138 
147  bool initialize(void);
148 
164  void setMaxRecordingTime(unsigned time_ms, unsigned hw_time_ms=0);
165 
175  bool closeFile(void);
176 
181  unsigned samplesWritten(void) const { return samples_written; }
182 
187  const struct timeval &beginTimestamp(void) const { return begin_timestamp; }
188 
193  const struct timeval &endTimestamp(void) const { return end_timestamp; }
194 
206  virtual int writeSamples(const float *samples, int count);
207 
216  virtual void flushSamples(void);
217 
226  std::string errorMsg(void) const { return errmsg; }
227 
236  sigc::signal<void> maxRecordingTimeReached;
237 
246  sigc::signal<void> errorOccurred;
247 
248  private:
249  std::string filename;
250  FILE *file;
251  unsigned samples_written;
252  Format format;
253  int sample_rate;
254  unsigned max_samples;
255  unsigned high_water_mark;
256  bool high_water_mark_reached;
257  struct timeval begin_timestamp;
258  struct timeval end_timestamp;
259  std::string errmsg;
260 
262  AudioRecorder& operator=(const AudioRecorder&);
263  bool writeWaveHeader(void);
264  int store32bitValue(char *ptr, uint32_t val);
265  int store16bitValue(char *ptr, uint16_t val);
266  void setErrMsgFromErrno(const std::string &fname);
267 
268 }; /* class AudioRecorder */
269 
270 
271 } /* namespace */
272 
273 #endif /* ASYNC_AUDIO_RECORDER_INCLUDED */
274 
275 
276 
277 /*
278  * This file has not been truncated
279  */
280 
This file contains the base class for an audio sink.
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.
std::string errorMsg(void) const
Return the current error message.
const struct timeval & beginTimestamp(void) const
The timestamp of the first stored sample.
bool initialize(void)
Initialize the recorder.
~AudioRecorder(void)
Destructor.
sigc::signal< void > maxRecordingTimeReached
A signal that's emitted when the max recording time is reached.
sigc::signal< void > errorOccurred
This signal is emitted when an error occurrs in the recorder.
unsigned samplesWritten(void) const
Find out how many samples that have been written so far.
AudioRecorder(const std::string &filename, AudioRecorder::Format fmt=FMT_AUTO, int sample_rate=INTERNAL_SAMPLE_RATE)
Default constuctor.
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
const struct timeval & endTimestamp(void) const
The timestamp of the last stored sample.
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
bool closeFile(void)
Close the file.
The base class for an audio sink.
Namespace for the asynchronous programming classes.