Async
0.18.0
|
00001 00027 #ifndef ASYNC_AUDIO_RECORDER_INCLUDED 00028 #define ASYNC_AUDIO_RECORDER_INCLUDED 00029 00030 00031 /**************************************************************************** 00032 * 00033 * System Includes 00034 * 00035 ****************************************************************************/ 00036 00037 #include <stdio.h> 00038 #include <stdint.h> 00039 #include <sigc++/sigc++.h> 00040 00041 #include <string> 00042 00043 #include <AsyncAudioSink.h> 00044 00045 00046 /**************************************************************************** 00047 * 00048 * Project Includes 00049 * 00050 ****************************************************************************/ 00051 00052 00053 00054 /**************************************************************************** 00055 * 00056 * Local Includes 00057 * 00058 ****************************************************************************/ 00059 00060 00061 00062 /**************************************************************************** 00063 * 00064 * Forward declarations 00065 * 00066 ****************************************************************************/ 00067 00068 00069 00070 /**************************************************************************** 00071 * 00072 * Namespace 00073 * 00074 ****************************************************************************/ 00075 00076 namespace Async 00077 { 00078 00079 00080 /**************************************************************************** 00081 * 00082 * Forward declarations of classes inside of the declared namespace 00083 * 00084 ****************************************************************************/ 00085 00086 00087 00088 /**************************************************************************** 00089 * 00090 * Defines & typedefs 00091 * 00092 ****************************************************************************/ 00093 00094 00095 00096 /**************************************************************************** 00097 * 00098 * Exported Global Variables 00099 * 00100 ****************************************************************************/ 00101 00102 00103 00104 /**************************************************************************** 00105 * 00106 * Class definitions 00107 * 00108 ****************************************************************************/ 00109 00118 class AudioRecorder : public Async::AudioSink 00119 { 00120 public: 00121 typedef enum { FMT_AUTO, FMT_RAW, FMT_WAV } Format; 00122 00129 explicit AudioRecorder(const std::string& filename, 00130 AudioRecorder::Format fmt=FMT_AUTO, 00131 int sample_rate=INTERNAL_SAMPLE_RATE); 00132 00136 ~AudioRecorder(void); 00137 00142 bool initialize(void); 00143 00153 void setMaxRecordingTime(unsigned time_ms); 00154 00166 virtual int writeSamples(const float *samples, int count); 00167 00176 virtual void flushSamples(void); 00177 00178 00179 private: 00180 std::string filename; 00181 FILE *file; 00182 unsigned samples_written; 00183 Format format; 00184 int sample_rate; 00185 unsigned max_samples; 00186 00187 AudioRecorder(const AudioRecorder&); 00188 AudioRecorder& operator=(const AudioRecorder&); 00189 void writeWaveHeader(void); 00190 int store32bitValue(char *ptr, uint32_t val); 00191 int store16bitValue(char *ptr, uint16_t val); 00192 00193 }; /* class AudioRecorder */ 00194 00195 00196 } /* namespace */ 00197 00198 #endif /* ASYNC_AUDIO_RECORDER_INCLUDED */ 00199 00200 00201 00202 /* 00203 * This file has not been truncated 00204 */ 00205