sync with trunk r46493
[reactos.git] / base / applications / sndrec32 / audio_waveout.hpp
1 /* PROJECT: ReactOS sndrec32
2 * LICENSE: GPL - See COPYING in the top level directory
3 * FILE: base/applications/sndrec32/audio_waveout.hpp
4 * PURPOSE: Windows MM wave out abstraction
5 * PROGRAMMERS: Marco Pagliaricci (irc: rendar)
6 */
7
8
9
10
11 #ifndef _AUDIOWAVEOUT__H_
12 #define _AUDIOWAVEOUT__H_
13
14
15 #include "audio_def.hpp"
16 #include "audio_format.hpp"
17
18
19 #include "audio_producer.hpp"
20
21
22
23 _AUDIO_NAMESPACE_START_
24
25
26
27
28
29 enum audio_waveout_status { WAVEOUT_NOTREADY, WAVEOUT_READY,
30 WAVEOUT_PLAYING, WAVEOUT_FLUSHING,
31 WAVEOUT_PAUSED, WAVEOUT_STOP,
32 WAVEOUT_ERR,
33
34 };
35
36
37
38
39
40 class audio_waveout
41 {
42
43 friend class audio_buffer;
44
45
46
47 private:
48
49
50 static DWORD WINAPI
51 playing_procedure( LPVOID );
52
53
54
55 HANDLE wakeup_playthread;
56
57
58
59
60 protected:
61
62
63 WAVEFORMATEX wave_format;
64 WAVEHDR * wave_headers;
65 HWAVEOUT waveout_handle;
66
67
68
69
70
71 const audio_format & aud_info;
72 audio_producer & audio_buf;
73
74
75
76
77
78
79 //
80 // Audio Playing Thread id
81 //
82
83 DWORD playthread_id;
84
85
86
87
88
89 audio_waveout_status status;
90
91
92
93
94 float buf_secs;
95
96
97
98 //
99 // The temporary buffers for the audio
100 // data outgoing to the waveout device
101 // and its size, and its total number.
102 //
103
104
105 //base address for entire memory
106 BYTE * main_buffer;
107
108 //size in bytes for the entire memory
109 unsigned int mb_size;
110
111 //number of little buffers
112 unsigned int buffers;
113
114
115
116
117
118
119 //
120 // Protected Functions
121 //
122
123 void init_( void );
124 void alloc_buffers_mem_( unsigned int, float );
125 void free_buffers_mem_( void );
126
127
128 void init_headers_( void );
129 void prep_headers_( void );
130 void unprep_headers_( void );
131
132
133
134
135
136
137
138 public:
139
140 //
141 // Ctors
142 //
143
144 audio_waveout( const audio_format & aud_fmt,
145 audio_producer & a_buf )
146
147 : wave_headers( 0 ), aud_info( aud_fmt ),
148 audio_buf( a_buf ), status( WAVEOUT_NOTREADY ),
149 main_buffer( 0 ), mb_size( 0 ),
150 buffers( _AUDIO_DEFAULT_WAVEOUTBUFFERS )
151 {
152
153 //
154 // Initializing internal wavein data
155 //
156
157
158 init_();
159
160 }
161
162
163
164
165
166
167 //
168 // Dtor
169 //
170
171 ~audio_waveout( void )
172 { }
173
174
175
176
177 //
178 // Public Functions
179 //
180
181 void open ( void );
182 void play ( void );
183 void pause ( void );
184 void stop ( void );
185 void close ( void );
186
187
188 audio_waveout_status current_status( void )
189 { return status; }
190
191
192
193
194 BYTE * buf( void ) { return main_buffer; }
195 unsigned int bufsz( void ) { return mb_size; }
196
197
198 unsigned int samplevalue_max( void )
199 {
200
201 if ( aud_info.bits() == 16 )
202 return (unsigned int )65535;
203
204 else if ( aud_info.bits() == 8 )
205 return (unsigned int)255;
206
207 else
208 return 0;
209 }
210
211
212 unsigned tot_samples_buf( void )
213 {
214
215
216 return aud_info.samples_in_bytes( mb_size );
217
218
219 }
220
221 unsigned int nsample ( unsigned int nsamp )
222 {
223
224
225 unsigned int svalue;
226
227
228
229 if ( aud_info.bits() == 16 )
230 svalue = ( unsigned int ) abs( *(( short * ) (main_buffer + aud_info.bytes_in_samples( nsamp ))));
231 else if ( aud_info.bits() == 8 )
232 svalue = (unsigned int)(( ptrdiff_t ) *(main_buffer + aud_info.bytes_in_samples( nsamp )));
233
234 else
235 svalue = 0;
236
237 return svalue;
238
239 }
240
241
242 };
243
244
245
246 _AUDIO_NAMESPACE_END_
247
248
249
250
251 #endif //ifdef _AUDIOWAVEOUT__H_