1 /* PROJECT: ReactOS sndrec32
2 * LICENSE: GPL - See COPYING in the top level directory
3 * FILE: base/applications/sndrec32/audio_wavein.hpp
4 * PURPOSE: Windows MM wave in abstraction
5 * PROGRAMMERS: Marco Pagliaricci (irc: rendar)
9 #ifndef _AUDIOWAVEIN_H_
10 #define _AUDIOWAVEIN_H_
14 #include "audio_def.hpp"
15 #include "audio_format.hpp"
16 #include "audio_receiver.hpp"
20 _AUDIO_NAMESPACE_START_
25 enum audio_wavein_status { WAVEIN_NOTREADY, WAVEIN_READY,
26 WAVEIN_RECORDING, WAVEIN_ERR,
27 WAVEIN_STOP, WAVEIN_FLUSHING
42 // The new recording thread sends message to this procedure
43 // about open recording, close, and sound data recorded
46 static DWORD WINAPI recording_procedure( LPVOID );
49 // When this event is signaled, then the previsiously created
50 // recording thread will wake up and start recording audio
51 // and will pass audio data to an `audio_receiver' object.
54 HANDLE wakeup_recthread;
55 HANDLE data_flushed_event;
63 //TODO: puts these structs in private?!
69 // Audio wavein device stuff
72 WAVEFORMATEX wave_format;
73 WAVEHDR * wave_headers;
74 HWAVEIN wavein_handle;
80 audio_format aud_info;
82 audio_receiver & audio_rcvd;
87 // Audio Recorder Thread id
99 audio_wavein_status status;
108 // How many seconds of audio
109 // can record the internal buffer
110 // before flushing audio data
111 // to the `audio_receiver' class?
118 // The temporary buffers for the audio
119 // data incoming from the wavein device
120 // and its size, and its total number.
124 unsigned int mb_size;
126 unsigned int buffers;
133 // Protected Functions
137 //initialize all structures and variables.
140 void alloc_buffers_mem_( unsigned int, float );
141 void free_buffers_mem_( void );
143 void init_headers_( void );
144 void prep_headers_( void );
145 void unprep_headers_( void );
146 void add_buffers_to_driver_( void );
162 const audio_format & a_info, audio_receiver & a_receiver )
165 aud_info( a_info ), audio_rcvd( a_receiver ),
166 status( WAVEIN_NOTREADY ), main_buffer( 0 ), mb_size( 0 ),
167 buffers( _AUDIO_DEFAULT_WAVEINBUFFERS )
171 // Initializing internal wavein data
190 ~audio_wavein( void )
207 void start_recording( void );
208 void stop_recording( void );
212 audio_wavein_status current_status ( void ) const
217 float buffer_secs( void ) const
221 void buffer_secs( float bsecs )
232 // Set seconds lenght for each
240 unsigned int total_buffers( void ) const
245 void total_buffers( unsigned int tot_bufs )
257 // Sets the number of total buffers.
264 audio_format format( void ) const
270 BYTE * buf( void ) { return main_buffer; }
271 unsigned int bufsz( void ) { return mb_size; }
274 unsigned int samplevalue_max( void )
277 if ( aud_info.bits() == 16 )
278 return (unsigned int )65535;
280 else if ( aud_info.bits() == 8 )
281 return (unsigned int)255;
288 unsigned tot_samples_buf( void )
292 return aud_info.samples_in_bytes( mb_size );
297 unsigned int nsample ( unsigned int nsamp )
305 if ( aud_info.bits() == 16 )
306 svalue = ( unsigned int ) abs( *(( short * ) (main_buffer + aud_info.bytes_in_samples( nsamp ))));
307 else if ( aud_info.bits() == 8 )
308 svalue = (unsigned int)(( ptrdiff_t ) *(main_buffer + aud_info.bytes_in_samples( nsamp )));
323 _AUDIO_NAMESPACE_END_
328 #endif //ifdef _AUDIOWAVEIN_H_