ReactOS  0.4.12-dev-51-ge94618b
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 
15 void
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 
50 void
52 {
53  MMRESULT err;
54 
55  /* Opens ACM stream */
57  0,
58  &wformat_src,
59  &wformat_dst,
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 */
74  src_buflen,
75  &dst_buflen,
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 
88  acm_header.dwUser = 0;
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 
112 void
114 {
115  MMRESULT err;
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 
149  err = acmStreamClose(acm_stream, 0);
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 
192 void
193 audio_resampler_acm::audio_receive(unsigned char *data, unsigned int size)
194 {
195  MMRESULT err;
196 
197  /* Checking for acm stream opened */
198  if (stream_opened)
199  {
200  /* Copy audio data from extern to internal source buffer */
201  memcpy(acm_header.pbSrc, data, size);
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 
unsigned int sample_rate(void) const
DWORD cbDstLength
Definition: msacm.h:558
#define ACM_STREAMCONVERTF_BLOCKALIGN
Definition: msacm.h:205
LPBYTE pbSrc
Definition: msacm.h:553
#define ZeroMemory
Definition: winbase.h:1635
UINT MMRESULT
Definition: mmsystem.h:962
DWORD_PTR dwDstUser
Definition: msacm.h:560
struct tWAVEFORMATEX WAVEFORMATEX
Definition: austream.idl:23
DWORD cbSrcLengthUsed
Definition: msacm.h:555
#define _AUDIO_NAMESPACE_START_
Definition: audio_def.hpp:24
unsigned short int bits(void) const
#define ACMSTREAMHEADER_STATUSF_DONE
Definition: msacm.h:209
DWORD cbDstLengthUsed
Definition: msacm.h:559
DWORD cbSrcLength
Definition: msacm.h:554
#define WAVE_FORMAT_PCM
Definition: constants.h:425
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int byte_rate(void) const
WORD wBitsPerSample
Definition: audioclient.idl:45
MMRESULT WINAPI acmStreamUnprepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwUnprepare)
Definition: stream.c:449
LPBYTE pbDst
Definition: msacm.h:557
DWORD cbStruct
Definition: msacm.h:550
DWORD nSamplesPerSec
Definition: audioclient.idl:42
unsigned int block_align(void) const
#define _T(x)
Definition: vfdio.h:22
GLsizeiptr size
Definition: glext.h:5919
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
void audio_receive(unsigned char *, unsigned int)
#define ACM_STREAMSIZEF_SOURCE
Definition: msacm.h:217
struct _ACMSTREAMHEADER ACMSTREAMHEADER
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static const WCHAR L[]
Definition: oid.c:1087
#define MB_ICONERROR
Definition: winuser.h:781
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define MessageBox
Definition: winuser.h:5688
#define err(...)
DWORD_PTR dwSrcUser
Definition: msacm.h:556
unsigned char BYTE
Definition: ntddk_ex.h:96
DWORD_PTR dwUser
Definition: msacm.h:552
DWORD fdwStatus
Definition: msacm.h:551
DWORD nAvgBytesPerSec
Definition: audioclient.idl:43
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
MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwPrepare)
Definition: stream.c:299
unsigned short int channels(void) const
#define _AUDIO_NAMESPACE_END_
Definition: audio_def.hpp:25
MMRESULT WINAPI acmStreamSize(HACMSTREAM has, DWORD cbInput, LPDWORD pdwOutputBytes, DWORD fdwSize)
Definition: stream.c:394
#define ACM_STREAMOPENF_NONREALTIME
Definition: msacm.h:215
#define ACMSTREAMHEADER_STATUSF_PREPARED
Definition: msacm.h:210
ACMSTREAMHEADER acm_header
MMRESULT WINAPI acmStreamConvert(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwConvert)
Definition: stream.c:89
MMRESULT WINAPI acmStreamClose(HACMSTREAM has, DWORD fdwClose)
Definition: stream.c:65
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:29