[FORMATTING] SndRec32 patch by Marco Pagliaricci, bug #4978.
[reactos.git] / reactos / base / applications / sndrec32 / audio_wavein.hpp
1 #ifndef _AUDIOWAVEIN_H_
2 #define _AUDIOWAVEIN_H_
3
4
5
6 #include "audio_def.hpp"
7 #include "audio_format.hpp"
8 #include "audio_receiver.hpp"
9
10
11
12 _AUDIO_NAMESPACE_START_
13
14
15
16
17 enum audio_wavein_status { WAVEIN_NOTREADY, WAVEIN_READY,
18 WAVEIN_RECORDING, WAVEIN_ERR,
19 WAVEIN_STOP, WAVEIN_FLUSHING
20
21 };
22
23
24
25
26
27 class audio_wavein
28 {
29 private:
30
31
32
33 //
34 // The new recording thread sends message to this procedure
35 // about open recording, close, and sound data recorded
36 //
37
38 static DWORD WINAPI recording_procedure( LPVOID );
39
40 //
41 // When this event is signaled, then the previsiously created
42 // recording thread will wake up and start recording audio
43 // and will pass audio data to an `audio_receiver' object.
44 //
45
46 HANDLE wakeup_recthread;
47 HANDLE data_flushed_event;
48
49
50
51
52 protected:
53
54
55 //TODO: puts these structs in private?!
56
57
58
59
60 //
61 // Audio wavein device stuff
62 //
63
64 WAVEFORMATEX wave_format;
65 WAVEHDR * wave_headers;
66 HWAVEIN wavein_handle;
67
68
69
70
71
72 audio_format aud_info;
73
74 audio_receiver & audio_rcvd;
75
76
77
78 //
79 // Audio Recorder Thread id
80 //
81
82 DWORD recthread_id;
83
84
85
86
87 //
88 // Object status
89 //
90
91 audio_wavein_status status;
92
93
94
95
96
97
98
99 //
100 // How many seconds of audio
101 // can record the internal buffer
102 // before flushing audio data
103 // to the `audio_receiver' class?
104 //
105
106 float buf_secs;
107
108
109 //
110 // The temporary buffers for the audio
111 // data incoming from the wavein device
112 // and its size, and its total number.
113 //
114
115 BYTE * main_buffer;
116 unsigned int mb_size;
117
118 unsigned int buffers;
119
120
121
122
123
124 //
125 // Protected Functions
126 //
127
128
129 //initialize all structures and variables.
130 void init_( void );
131
132 void alloc_buffers_mem_( unsigned int, float );
133 void free_buffers_mem_( void );
134
135 void init_headers_( void );
136 void prep_headers_( void );
137 void unprep_headers_( void );
138 void add_buffers_to_driver_( void );
139
140
141
142
143
144
145
146 public:
147
148
149 //
150 // Ctors
151 //
152
153 audio_wavein(
154 const audio_format & a_info, audio_receiver & a_receiver )
155
156 : wave_headers( 0 ),
157 aud_info( a_info ), audio_rcvd( a_receiver ),
158 status( WAVEIN_NOTREADY ), main_buffer( 0 ), mb_size( 0 ),
159 buffers( _AUDIO_DEFAULT_WAVEINBUFFERS )
160 {
161
162 //
163 // Initializing internal wavein data
164 //
165
166
167 init_();
168
169 aud_info = a_info;
170 }
171
172
173
174
175
176
177
178 //
179 // Dtor
180 //
181
182 ~audio_wavein( void )
183 {
184
185 //close(); TODO!
186
187 }
188
189
190
191 //
192 // Public functions
193 //
194
195 void open( void );
196 void close ( void );
197
198
199 void start_recording( void );
200 void stop_recording( void );
201
202
203
204 audio_wavein_status current_status ( void ) const
205 {
206 return status;
207 }
208
209 float buffer_secs( void ) const
210 { return buf_secs; }
211
212
213 void buffer_secs( float bsecs )
214 {
215 //
216 // Some checking
217 //
218
219 if ( bsecs <= 0 )
220 return;
221
222
223 //
224 // Set seconds lenght for each
225 // buffer.
226 //
227
228 buf_secs = bsecs;
229 }
230
231
232 unsigned int total_buffers( void ) const
233 { return buffers; }
234
235
236
237 void total_buffers( unsigned int tot_bufs )
238 {
239
240 //
241 // Some checking
242 //
243
244 if ( tot_bufs == 0 )
245 return;
246
247
248 //
249 // Sets the number of total buffers.
250 //
251
252 buffers = tot_bufs;
253 }
254
255
256 audio_format format( void ) const
257 { return aud_info; }
258
259
260
261 };
262
263
264
265
266 _AUDIO_NAMESPACE_END_
267
268
269
270
271 #endif //ifdef _AUDIOWAVEIN_H_