ReactOS 0.4.15-dev-7918-g2a2556c
audio_resampler_acm.cpp
Go to the documentation of this file.
1/* PROJECT: ReactOS sndrec32
2 * LICENSE: GPL - See COPYING in the top level directory
3 * FILE: base/applications/sndrec32/audio_resampler_acm.cpp
4 * PURPOSE: Sound recording
5 * PROGRAMMERS: Marco Pagliaricci (irc: rendar)
6 */
7
8#include "stdafx.h"
10
12
13/* Private Functions */
14
15void
17{
18 /* Zeroing structures */
22
23 /* Setting structures sizes */
27
28 /* Setting WAVEFORMATEX structure parameters
29 according to `audio_format' in/out classes */
30
37
44
45 /* Init acm structures completed successful */
46}
47
48/* Public Functions */
49
50void
52{
54
55 /* Opens ACM stream */
57 0,
60 0, 0, 0,
62
63 if (err != MMSYSERR_NOERROR)
64 {
65 /* TODO: throw error */
66 MessageBox(0, _T("acmOpen error: %i"), _T("ERROR"), MB_ICONERROR);
67 }
68
69 /* Calcs source buffer length */
70 src_buflen = (unsigned int)((float)audfmt_in.byte_rate() * (float)buf_secs);
71
72 /* Calcs destination source buffer length with help of ACM apis */
77
78 if (err != MMSYSERR_NOERROR)
79 {
80 /* TODO: throw error */
81 MessageBox(0, _T("acmStreamSize error"), _T("ERROR"), MB_ICONERROR);
82 }
83
84 /* Initialize ACMSTREAMHEADER structure,
85 and alloc memory for source and destination buffers */
86
89
94
99
100 /* Give ACMSTREAMHEADER initialized correctly to the driver */
102 if (err != MMSYSERR_NOERROR)
103 {
104 /* TODO: throw error */
105 MessageBox(0, _T("acmStreamPrepareHeader error"), _T("ERROR"), MB_ICONERROR);
106 }
107
108 /* ACM stream successfully opened */
109 stream_opened = true;
110}
111
112void
114{
116
117 if (acm_stream)
118 {
120 {
123
125 if (err != MMSYSERR_NOERROR)
126 {
127 /* Free buffer memory */
128 if (acm_header.pbSrc != 0)
129 {
130 delete[] acm_header.pbSrc;
131 acm_header.pbSrc = 0;
132 }
133
134 if (acm_header.pbDst != 0)
135 {
136 delete[] acm_header.pbDst;
137 acm_header.pbDst = 0;
138 }
139
140 /* Re-init structures */
141 init_();
142 /* Updating status */
143 stream_opened = false;
144 /* TODO: throw error */
145 MessageBox(0, _T("acmStreamUnPrepareHeader error"), _T("ERROR"), MB_ICONERROR);
146 }
147 }
148
150 acm_stream = 0;
151
152 if (err != MMSYSERR_NOERROR)
153 {
154 /* Free buffer memory */
155 if (acm_header.pbSrc != 0)
156 {
157 delete[] acm_header.pbSrc;
158 acm_header.pbSrc = 0;
159 }
160
161 if (acm_header.pbDst != 0)
162 {
163 delete[] acm_header.pbDst;
164 acm_header.pbDst = 0;
165 }
166
167 /* Re-init structures */
168 init_();
169 /* Updating status */
170 stream_opened = false;
171 /* TODO: throw error! */
172 MessageBox(0, _T("acmStreamClose error"), _T("ERROR"), MB_ICONERROR);
173 }
174
175 } /* if acm_stream != 0 */
176
177 /* Free buffer memory */
178 if (acm_header.pbSrc != 0)
179 delete[] acm_header.pbSrc;
180
181 if (acm_header.pbDst != 0)
182 delete[] acm_header.pbDst;
183
184 /* Re-init structures */
185 init_();
186 /* Updating status */
187 stream_opened = false;
188
189 /* ACM sream successfully closed */
190}
191
192void
193audio_resampler_acm::audio_receive(unsigned char *data, unsigned int size)
194{
196
197 /* Checking for acm stream opened */
198 if (stream_opened)
199 {
200 /* Copy audio data from extern to internal source buffer */
202
205
207
208 if (err != MMSYSERR_NOERROR)
209 {
210 /* TODO: throw error */
211 MessageBox(0, _T("acmStreamConvert error"), _T("ERROR"), MB_ICONERROR);
212 }
213
214 /* Wait for sound conversion */
216
217 /* Copy resampled audio, to destination buffer */
218 //memcpy(pbOutputData, acm_header.pbDst, acm_header.cbDstLengthUsed);
219 }
220}
221
#define _AUDIO_NAMESPACE_START_
Definition: audio_def.hpp:24
#define _AUDIO_NAMESPACE_END_
Definition: audio_def.hpp:25
#define WAVE_FORMAT_PCM
Definition: constants.h:425
unsigned short int bits(void) const
unsigned int byte_rate(void) const
unsigned int sample_rate(void) const
unsigned short int channels(void) const
unsigned int block_align(void) const
ACMSTREAMHEADER acm_header
void audio_receive(unsigned char *, unsigned int)
MMRESULT WINAPI acmStreamClose(HACMSTREAM has, DWORD fdwClose)
Definition: stream.c:65
MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwPrepare)
Definition: stream.c:299
MMRESULT WINAPI acmStreamConvert(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwConvert)
Definition: stream.c:89
MMRESULT WINAPI acmStreamSize(HACMSTREAM has, DWORD cbInput, LPDWORD pdwOutputBytes, DWORD fdwSize)
Definition: stream.c:394
MMRESULT WINAPI acmStreamUnprepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwUnprepare)
Definition: stream.c:449
MMRESULT WINAPI acmStreamOpen(PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pwfxSrc, PWAVEFORMATEX pwfxDst, PWAVEFILTER pwfltr, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen)
Definition: stream.c:149
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
UINT MMRESULT
Definition: mmsystem.h:962
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
static float(__cdecl *square_half_float)(float x
#define ACM_STREAMCONVERTF_BLOCKALIGN
Definition: msacm.h:205
#define ACMSTREAMHEADER_STATUSF_PREPARED
Definition: msacm.h:210
#define ACM_STREAMOPENF_NONREALTIME
Definition: msacm.h:215
struct _ACMSTREAMHEADER ACMSTREAMHEADER
#define ACMSTREAMHEADER_STATUSF_DONE
Definition: msacm.h:209
#define ACM_STREAMSIZEF_SOURCE
Definition: msacm.h:217
#define L(x)
Definition: ntvdm.h:50
#define err(...)
DWORD nAvgBytesPerSec
Definition: audioclient.idl:43
WORD wBitsPerSample
Definition: audioclient.idl:45
DWORD nSamplesPerSec
Definition: audioclient.idl:42
DWORD fdwStatus
Definition: msacm.h:551
DWORD cbSrcLengthUsed
Definition: msacm.h:555
DWORD cbStruct
Definition: msacm.h:550
LPBYTE pbDst
Definition: msacm.h:557
DWORD_PTR dwUser
Definition: msacm.h:552
DWORD cbDstLength
Definition: msacm.h:558
DWORD cbSrcLength
Definition: msacm.h:554
DWORD_PTR dwDstUser
Definition: msacm.h:560
DWORD cbDstLengthUsed
Definition: msacm.h:559
LPBYTE pbSrc
Definition: msacm.h:553
DWORD_PTR dwSrcUser
Definition: msacm.h:556
unsigned char * LPBYTE
Definition: typedefs.h:53
#define _T(x)
Definition: vfdio.h:22
#define ZeroMemory
Definition: winbase.h:1712
#define MB_ICONERROR
Definition: winuser.h:787
#define MessageBox
Definition: winuser.h:5822
unsigned char BYTE
Definition: xxhash.c:193