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)
8 #ifndef _AUDIOWAVEIN_H_
9 #define _AUDIOWAVEIN_H_
11 #include "audio_format.hpp"
12 #include "audio_receiver.hpp"
14 _AUDIO_NAMESPACE_START_
16 enum audio_wavein_status
29 /* The new recording thread sends message to this procedure
30 about open recording, close, and sound data recorded */
31 static DWORD WINAPI recording_procedure(LPVOID);
33 /* When this event is signaled, then the previously created
34 recording thread will wake up and start recording audio
35 and will pass audio data to an `audio_receiver' object. */
36 HANDLE wakeup_recthread;
37 HANDLE data_flushed_event;
40 /* TODO: puts these structs in private?! */
42 /* Audio wavein device stuff */
43 WAVEFORMATEX wave_format;
44 WAVEHDR *wave_headers;
45 HWAVEIN wavein_handle;
47 audio_format aud_info;
48 audio_receiver &audio_rcvd;
50 /* Audio Recorder Thread id */
54 audio_wavein_status status;
56 /* How many seconds of audio can record the internal buffer before
57 flushing audio data to the `audio_receiver' class? */
60 /* The temporary buffers for the audio data incoming from the wavein
61 device and its size, and its total number */
66 /* Protected Functions */
68 /* initialize all structures and variables */
71 void alloc_buffers_mem_(unsigned int, float);
72 void free_buffers_mem_(void);
74 void init_headers_(void);
75 void prep_headers_(void);
76 void unprep_headers_(void);
77 void add_buffers_to_driver_(void);
81 audio_wavein(const audio_format &a_info,
82 audio_receiver &a_receiver) : wave_headers(0),
84 audio_rcvd(a_receiver),
85 status(WAVEIN_NOTREADY),
88 buffers(_AUDIO_DEFAULT_WAVEINBUFFERS)
90 /* Initializing internal wavein data */
101 /* Public functions */
106 void start_recording(void);
107 void stop_recording(void);
109 audio_wavein_status current_status (void) const
114 float buffer_secs(void) const
119 void buffer_secs(float bsecs)
125 /* Set seconds length for each buffer */
129 unsigned int total_buffers(void) const
134 void total_buffers(unsigned int tot_bufs)
140 /* Sets the number of total buffers */
144 audio_format format(void) const
154 unsigned int bufsz(void)
159 unsigned int samplevalue_max(void)
161 if (aud_info.bits() == 16)
162 return (unsigned int)65535;
164 else if (aud_info.bits() == 8)
165 return (unsigned int)255;
171 unsigned tot_samples_buf(void)
173 return aud_info.samples_in_bytes(mb_size);
176 unsigned int nsample(unsigned int nsamp)
180 if (aud_info.bits() == 16)
181 svalue = (unsigned int)abs(*((short *)(main_buffer + aud_info.bytes_in_samples(nsamp))));
182 else if (aud_info.bits() == 8)
183 svalue = (unsigned int)((ptrdiff_t) *(main_buffer + aud_info.bytes_in_samples(nsamp)));
191 _AUDIO_NAMESPACE_END_
193 #endif /* _AUDIOWAVEIN_H_ */