gdi32: Pass the brush origin explicitly to the brush backend functions.
[wine.git] / dlls / winmm / tests / capture.c
blob54c379317cd495b3e8db8ba2cb21674c69cfdeb9
1 /*
2 * Test winmm sound capture in each sound format
4 * Copyright (c) 2002 Francois Gouget
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <math.h>
26 #include "wine/test.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnls.h"
30 #include "mmddk.h"
31 #include "mmsystem.h"
32 #define NOBITMAP
33 #include "mmreg.h"
35 extern GUID KSDATAFORMAT_SUBTYPE_PCM;
36 extern GUID KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
38 #include "winmm_test.h"
40 static const char * wave_in_error(MMRESULT error)
42 static char msg[1024];
43 static char long_msg[1100];
44 MMRESULT rc;
46 rc = waveInGetErrorTextA(error, msg, sizeof(msg));
47 if (rc != MMSYSERR_NOERROR)
48 sprintf(long_msg, "waveInGetErrorTextA(%x) failed with error %x", error, rc);
49 else
50 sprintf(long_msg, "%s(%s)", mmsys_error(error), msg);
51 return long_msg;
54 static void check_position(int device, HWAVEIN win, DWORD bytes,
55 LPWAVEFORMATEX pwfx )
57 MMTIME mmtime;
58 MMRESULT rc;
59 DWORD returned;
61 mmtime.wType = TIME_BYTES;
62 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
63 ok(rc==MMSYSERR_NOERROR,
64 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
65 if (mmtime.wType != TIME_BYTES && winetest_debug > 1)
66 trace("waveInGetPosition(%s): TIME_BYTES not supported, returned %s\n",
67 dev_name(device),wave_time_format(mmtime.wType));
68 returned = time_to_bytes(&mmtime, pwfx);
69 ok(returned == bytes, "waveInGetPosition(%s): returned %d bytes, "
70 "should be %d\n", dev_name(device), returned, bytes);
72 mmtime.wType = TIME_SAMPLES;
73 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
74 ok(rc==MMSYSERR_NOERROR,
75 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
76 if (mmtime.wType != TIME_SAMPLES && winetest_debug > 1)
77 trace("waveInGetPosition(%s): TIME_SAMPLES not supported, "
78 "returned %s\n",dev_name(device),wave_time_format(mmtime.wType));
79 returned = time_to_bytes(&mmtime, pwfx);
80 ok(returned == bytes, "waveInGetPosition(%s): returned %d samples, "
81 "should be %d\n", dev_name(device), bytes_to_samples(returned, pwfx),
82 bytes_to_samples(bytes, pwfx));
84 mmtime.wType = TIME_MS;
85 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
86 ok(rc==MMSYSERR_NOERROR,
87 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
88 if (mmtime.wType != TIME_MS && winetest_debug > 1)
89 trace("waveInGetPosition(%s): TIME_MS not supported, returned %s\n",
90 dev_name(device), wave_time_format(mmtime.wType));
91 returned = time_to_bytes(&mmtime, pwfx);
92 ok(returned == bytes, "waveInGetPosition(%s): returned %d ms, "
93 "should be %d\n", dev_name(device), bytes_to_ms(returned, pwfx),
94 bytes_to_ms(bytes, pwfx));
96 mmtime.wType = TIME_SMPTE;
97 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
98 ok(rc==MMSYSERR_NOERROR,
99 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
100 if (mmtime.wType != TIME_SMPTE && winetest_debug > 1)
101 trace("waveInGetPosition(%s): TIME_SMPTE not supported, returned %s\n",
102 dev_name(device),wave_time_format(mmtime.wType));
103 returned = time_to_bytes(&mmtime, pwfx);
104 ok(returned == bytes, "waveInGetPosition(%s): SMPTE test failed\n",
105 dev_name(device));
107 mmtime.wType = TIME_MIDI;
108 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
109 ok(rc==MMSYSERR_NOERROR,
110 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
111 if (mmtime.wType != TIME_MIDI && winetest_debug > 1)
112 trace("waveInGetPosition(%s): TIME_MIDI not supported, returned %s\n",
113 dev_name(device),wave_time_format(mmtime.wType));
114 returned = time_to_bytes(&mmtime, pwfx);
115 ok(returned == bytes, "waveInGetPosition(%s): MIDI test failed\n",
116 dev_name(device));
118 mmtime.wType = TIME_TICKS;
119 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
120 ok(rc==MMSYSERR_NOERROR,
121 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
122 if (mmtime.wType != TIME_TICKS && winetest_debug > 1)
123 trace("waveInGetPosition(%s): TIME_TICKS not supported, returned %s\n",
124 dev_name(device),wave_time_format(mmtime.wType));
125 returned = time_to_bytes(&mmtime, pwfx);
126 ok(returned == bytes, "waveInGetPosition(%s): TICKS test failed\n",
127 dev_name(device));
130 static void wave_in_test_deviceIn(int device, WAVEFORMATEX *pwfx, DWORD format, DWORD flags,
131 WAVEINCAPSA *pcaps)
133 HWAVEIN win;
134 HANDLE hevent = CreateEventW(NULL, FALSE, FALSE, NULL);
135 WAVEHDR frag;
136 MMRESULT rc;
137 DWORD res;
138 MMTIME mmt;
139 WORD nChannels = pwfx->nChannels;
140 WORD wBitsPerSample = pwfx->wBitsPerSample;
141 DWORD nSamplesPerSec = pwfx->nSamplesPerSec;
143 win=NULL;
144 rc=waveInOpen(&win,device,pwfx,(DWORD_PTR)hevent,0,CALLBACK_EVENT|flags);
145 /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */
146 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
147 rc==MMSYSERR_NOTENABLED || rc==MMSYSERR_NODRIVER ||
148 rc==MMSYSERR_ALLOCATED ||
149 ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
150 (flags & WAVE_FORMAT_DIRECT) && !(pcaps->dwFormats & format)) ||
151 ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
152 (!(flags & WAVE_FORMAT_DIRECT) || (flags & WAVE_MAPPED)) &&
153 !(pcaps->dwFormats & format)) ||
154 (rc==MMSYSERR_INVALFLAG && (flags & WAVE_FORMAT_DIRECT)),
155 "waveInOpen(%s): format=%dx%2dx%d flags=%x(%s) rc=%s\n",
156 dev_name(device),pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
157 pwfx->nChannels,CALLBACK_EVENT|flags,
158 wave_open_flags(CALLBACK_EVENT|flags),wave_in_error(rc));
159 if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
160 (flags & WAVE_FORMAT_DIRECT) && (pcaps->dwFormats & format))
161 trace(" Reason: The device lists this format as supported in its "
162 "capabilities but opening it failed.\n");
163 if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
164 !(pcaps->dwFormats & format))
165 trace("waveInOpen(%s): format=%dx%2dx%d %s rc=%s failed but format "
166 "not supported so OK.\n",dev_name(device),pwfx->nSamplesPerSec,
167 pwfx->wBitsPerSample,pwfx->nChannels,
168 flags & WAVE_FORMAT_DIRECT ? "flags=WAVE_FORMAT_DIRECT" :
169 flags & WAVE_MAPPED ? "flags=WAVE_MAPPED" : "", mmsys_error(rc));
170 if (rc!=MMSYSERR_NOERROR) {
171 CloseHandle(hevent);
172 return;
174 res=WaitForSingleObject(hevent,1000);
175 ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for open\n");
177 ok(pwfx->nChannels==nChannels &&
178 pwfx->wBitsPerSample==wBitsPerSample &&
179 pwfx->nSamplesPerSec==nSamplesPerSec,
180 "got the wrong format: %dx%2dx%d instead of %dx%2dx%d\n",
181 pwfx->nSamplesPerSec, pwfx->wBitsPerSample,
182 pwfx->nChannels, nSamplesPerSec, wBitsPerSample, nChannels);
184 /* Check that the position is 0 at start */
185 check_position(device, win, 0, pwfx);
187 frag.lpData=HeapAlloc(GetProcessHeap(), 0, pwfx->nAvgBytesPerSec);
188 frag.dwBufferLength=pwfx->nAvgBytesPerSec;
189 frag.dwBytesRecorded=0;
190 frag.dwUser=0;
191 frag.dwFlags=0;
192 frag.dwLoops=0;
193 frag.lpNext=0;
195 rc=waveInPrepareHeader(win, &frag, sizeof(frag));
196 ok(rc==MMSYSERR_NOERROR, "waveInPrepareHeader(%s): rc=%s\n",
197 dev_name(device),wave_in_error(rc));
198 ok(frag.dwFlags&WHDR_PREPARED,"waveInPrepareHeader(%s): prepared flag "
199 "not set\n",dev_name(device));
201 if (winetest_interactive && rc==MMSYSERR_NOERROR) {
202 trace("Recording for 1 second at %5dx%2dx%d %s %s\n",
203 pwfx->nSamplesPerSec, pwfx->wBitsPerSample,pwfx->nChannels,
204 get_format_str(pwfx->wFormatTag),
205 flags & WAVE_FORMAT_DIRECT ? "WAVE_FORMAT_DIRECT" :
206 flags & WAVE_MAPPED ? "WAVE_MAPPED" : "");
207 rc=waveInAddBuffer(win, &frag, sizeof(frag));
208 ok(rc==MMSYSERR_NOERROR,"waveInAddBuffer(%s): rc=%s\n",
209 dev_name(device),wave_in_error(rc));
211 /* Check that the position is 0 at start */
212 check_position(device, win, 0, pwfx);
214 rc=waveInStart(win);
215 ok(rc==MMSYSERR_NOERROR,"waveInStart(%s): rc=%s\n",
216 dev_name(device),wave_in_error(rc));
218 res = WaitForSingleObject(hevent,1200);
219 ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for header\n");
220 ok(frag.dwFlags&WHDR_DONE,"WHDR_DONE not set in frag.dwFlags\n");
221 ok(frag.dwBytesRecorded==pwfx->nAvgBytesPerSec,
222 "frag.dwBytesRecorded=%d, should=%d\n",
223 frag.dwBytesRecorded,pwfx->nAvgBytesPerSec);
225 mmt.wType = TIME_BYTES;
226 rc=waveInGetPosition(win, &mmt, sizeof(mmt));
227 ok(rc==MMSYSERR_NOERROR,"waveInGetPosition(%s): rc=%s\n",
228 dev_name(device),wave_in_error(rc));
229 ok(mmt.wType == TIME_BYTES, "doesn't support TIME_BYTES: %u\n", mmt.wType);
230 ok(mmt.u.cb == frag.dwBytesRecorded, "Got wrong position: %u\n", mmt.u.cb);
232 /* stop playing on error */
233 if (res!=WAIT_OBJECT_0) {
234 rc=waveInStop(win);
235 ok(rc==MMSYSERR_NOERROR,
236 "waveInStop(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
240 rc=waveInUnprepareHeader(win, &frag, sizeof(frag));
241 ok(rc==MMSYSERR_NOERROR,"waveInUnprepareHeader(%s): rc=%s\n",
242 dev_name(device),wave_in_error(rc));
244 rc=waveInClose(win);
245 ok(rc==MMSYSERR_NOERROR,
246 "waveInClose(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
247 res=WaitForSingleObject(hevent,1000);
248 ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for close\n");
250 if (winetest_interactive)
253 * Now play back what we recorded
255 HWAVEOUT wout;
257 trace("Playing back recorded sound\n");
258 rc=waveOutOpen(&wout,WAVE_MAPPER,pwfx,(DWORD_PTR)hevent,0,CALLBACK_EVENT);
259 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
260 rc==MMSYSERR_NOTENABLED || rc==MMSYSERR_NODRIVER ||
261 rc==MMSYSERR_ALLOCATED ||
262 ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
263 !(pcaps->dwFormats & format)),
264 "waveOutOpen(%s) format=%dx%2dx%d flags=%x(%s) rc=%s\n",
265 dev_name(device),pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
266 pwfx->nChannels,CALLBACK_EVENT|flags,
267 wave_open_flags(CALLBACK_EVENT),wave_out_error(rc));
268 if (rc==MMSYSERR_NOERROR)
270 rc=waveOutPrepareHeader(wout, &frag, sizeof(frag));
271 ok(rc==MMSYSERR_NOERROR,"waveOutPrepareHeader(%s): rc=%s\n",
272 dev_name(device),wave_out_error(rc));
274 if (rc==MMSYSERR_NOERROR)
276 WaitForSingleObject(hevent,INFINITE);
277 rc=waveOutWrite(wout, &frag, sizeof(frag));
278 ok(rc==MMSYSERR_NOERROR,"waveOutWrite(%s): rc=%s\n",
279 dev_name(device),wave_out_error(rc));
280 WaitForSingleObject(hevent,INFINITE);
282 rc=waveOutUnprepareHeader(wout, &frag, sizeof(frag));
283 ok(rc==MMSYSERR_NOERROR,"waveOutUnprepareHeader(%s): rc=%s\n",
284 dev_name(device),wave_out_error(rc));
286 rc=waveOutClose(wout);
287 ok(rc==MMSYSERR_NOERROR,"waveOutClose(%s): rc=%s\n",
288 dev_name(device),wave_out_error(rc));
290 else
291 trace("Unable to play back the recorded sound\n");
294 HeapFree(GetProcessHeap(), 0, frag.lpData);
295 CloseHandle(hevent);
298 static void wave_in_test_device(UINT_PTR device)
300 WAVEINCAPSA capsA;
301 WAVEINCAPSW capsW;
302 WAVEFORMATEX format;
303 WAVEFORMATEXTENSIBLE wfex;
304 HWAVEIN win;
305 MMRESULT rc;
306 UINT f;
307 WCHAR * nameW;
308 CHAR * nameA;
309 DWORD size;
310 DWORD dwPageSize;
311 BYTE * twoPages;
312 SYSTEM_INFO sSysInfo;
313 DWORD flOldProtect;
314 BOOL res;
316 GetSystemInfo(&sSysInfo);
317 dwPageSize = sSysInfo.dwPageSize;
319 rc=waveInGetDevCapsA(device,&capsA,sizeof(capsA));
320 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
321 rc==MMSYSERR_NODRIVER,
322 "waveInGetDevCapsA(%s): failed to get capabilities: rc=%s\n",
323 dev_name(device),wave_in_error(rc));
324 if (rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER)
325 return;
327 rc=waveInGetDevCapsW(device,&capsW,sizeof(capsW));
328 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED,
329 "waveInGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
330 "expected, got %s\n",dev_name(device),wave_in_error(rc));
332 rc=waveInGetDevCapsA(device,NULL,sizeof(capsA));
333 ok(rc==MMSYSERR_INVALPARAM,
334 "waveInGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
335 dev_name(device),wave_in_error(rc));
337 rc=waveInGetDevCapsW(device,NULL,sizeof(capsW));
338 ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
339 "waveInGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
340 "expected, got %s\n",dev_name(device),wave_in_error(rc));
342 if (0)
344 /* FIXME: this works on windows but crashes wine */
345 rc=waveInGetDevCapsA(device,(LPWAVEINCAPSA)1,sizeof(capsA));
346 ok(rc==MMSYSERR_INVALPARAM,
347 "waveInGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
348 dev_name(device),wave_in_error(rc));
350 rc=waveInGetDevCapsW(device,(LPWAVEINCAPSW)1,sizeof(capsW));
351 ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
352 "waveInGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
353 "expected, got %s\n",dev_name(device),wave_in_error(rc));
356 rc=waveInGetDevCapsA(device,&capsA,4);
357 ok(rc==MMSYSERR_NOERROR,
358 "waveInGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
359 dev_name(device),wave_in_error(rc));
361 rc=waveInGetDevCapsW(device,&capsW,4);
362 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED ||
363 rc==MMSYSERR_INVALPARAM, /* Vista, W2K8 */
364 "waveInGetDevCapsW(%s): unexpected return value %s\n",
365 dev_name(device),wave_in_error(rc));
367 nameA=NULL;
368 rc=waveInMessage((HWAVEIN)device, DRV_QUERYDEVICEINTERFACESIZE,
369 (DWORD_PTR)&size, 0);
370 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_INVALPARAM ||
371 rc==MMSYSERR_NOTSUPPORTED,
372 "waveInMessage(%s): failed to get interface size: rc=%s\n",
373 dev_name(device),wave_in_error(rc));
374 if (rc==MMSYSERR_NOERROR) {
375 nameW = HeapAlloc(GetProcessHeap(), 0, size);
376 rc=waveInMessage((HWAVEIN)device, DRV_QUERYDEVICEINTERFACE,
377 (DWORD_PTR)nameW, size);
378 ok(rc==MMSYSERR_NOERROR,"waveInMessage(%s): failed to get interface "
379 "name: rc=%s\n",dev_name(device),wave_in_error(rc));
380 ok(lstrlenW(nameW)+1==size/sizeof(WCHAR),
381 "got an incorrect size %d\n", size);
382 if (rc==MMSYSERR_NOERROR) {
383 nameA = HeapAlloc(GetProcessHeap(), 0, size/sizeof(WCHAR));
384 WideCharToMultiByte(CP_ACP, 0, nameW, size/sizeof(WCHAR),
385 nameA, size/sizeof(WCHAR), NULL, NULL);
387 HeapFree(GetProcessHeap(), 0, nameW);
388 } else if (rc==MMSYSERR_NOTSUPPORTED) {
389 nameA=HeapAlloc(GetProcessHeap(), 0, sizeof("not supported"));
390 strcpy(nameA, "not supported");
393 trace(" %s: \"%s\" (%s) %d.%d (%d:%d)\n",dev_name(device),capsA.szPname,
394 (nameA?nameA:"failed"),capsA.vDriverVersion >> 8,
395 capsA.vDriverVersion & 0xff,capsA.wMid,capsA.wPid);
396 trace(" channels=%d formats=%05x\n",
397 capsA.wChannels,capsA.dwFormats);
399 HeapFree(GetProcessHeap(), 0, nameA);
401 for (f=0;f<NB_WIN_FORMATS;f++) {
402 format.wFormatTag=WAVE_FORMAT_PCM;
403 format.nChannels=win_formats[f][3];
404 format.wBitsPerSample=win_formats[f][2];
405 format.nSamplesPerSec=win_formats[f][1];
406 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
407 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
408 format.cbSize=0;
409 wave_in_test_deviceIn(device,&format,win_formats[f][0],0, &capsA);
410 if (device != WAVE_MAPPER) {
411 wave_in_test_deviceIn(device,&format,win_formats[f][0],
412 WAVE_FORMAT_DIRECT, &capsA);
413 wave_in_test_deviceIn(device,&format,win_formats[f][0],
414 WAVE_MAPPED, &capsA);
418 /* Try a PCMWAVEFORMAT aligned next to an unaccessible page for bounds
419 * checking */
420 twoPages = VirtualAlloc(NULL, 2 * dwPageSize, MEM_RESERVE | MEM_COMMIT,
421 PAGE_READWRITE);
422 ok(twoPages!=NULL,"Failed to allocate 2 pages of memory\n");
423 if (twoPages) {
424 res = VirtualProtect(twoPages + dwPageSize, dwPageSize, PAGE_NOACCESS,
425 &flOldProtect);
426 ok(res, "Failed to set memory access on second page\n");
427 if (res) {
428 LPWAVEFORMATEX pwfx = (LPWAVEFORMATEX)(twoPages + dwPageSize -
429 sizeof(PCMWAVEFORMAT));
430 pwfx->wFormatTag=WAVE_FORMAT_PCM;
431 pwfx->nChannels=1;
432 pwfx->wBitsPerSample=8;
433 pwfx->nSamplesPerSec=22050;
434 pwfx->nBlockAlign=pwfx->nChannels*pwfx->wBitsPerSample/8;
435 pwfx->nAvgBytesPerSec=pwfx->nSamplesPerSec*pwfx->nBlockAlign;
436 wave_in_test_deviceIn(device,pwfx,WAVE_FORMAT_2M08,0, &capsA);
437 if (device != WAVE_MAPPER) {
438 wave_in_test_deviceIn(device,pwfx,WAVE_FORMAT_2M08,
439 WAVE_FORMAT_DIRECT, &capsA);
440 wave_in_test_deviceIn(device,pwfx,WAVE_FORMAT_2M08,
441 WAVE_MAPPED, &capsA);
444 VirtualFree(twoPages, 2 * dwPageSize, MEM_RELEASE);
447 /* test non PCM formats */
448 format.wFormatTag=WAVE_FORMAT_MULAW;
449 format.nChannels=1;
450 format.wBitsPerSample=8;
451 format.nSamplesPerSec=8000;
452 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
453 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
454 format.cbSize=0;
455 rc=waveInOpen(&win,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
456 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
457 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM ||
458 rc==MMSYSERR_ALLOCATED,
459 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
460 if (rc==MMSYSERR_NOERROR) {
461 waveInClose(win);
462 wave_in_test_deviceIn(device,&format,0,0,&capsA);
463 } else
464 trace("waveInOpen(%s): WAVE_FORMAT_MULAW not supported\n",
465 dev_name(device));
467 format.wFormatTag=WAVE_FORMAT_ADPCM;
468 format.nChannels=2;
469 format.wBitsPerSample=4;
470 format.nSamplesPerSec=22050;
471 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
472 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
473 format.cbSize=0;
474 rc=waveInOpen(&win,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
475 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
476 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM ||
477 rc==MMSYSERR_ALLOCATED,
478 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
479 if (rc==MMSYSERR_NOERROR) {
480 waveInClose(win);
481 wave_in_test_deviceIn(device,&format,0,0,&capsA);
482 } else
483 trace("waveInOpen(%s): WAVE_FORMAT_ADPCM not supported\n",
484 dev_name(device));
486 /* test if WAVEFORMATEXTENSIBLE supported */
487 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
488 wfex.Format.nChannels=2;
489 wfex.Format.wBitsPerSample=16;
490 wfex.Format.nSamplesPerSec=22050;
491 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
492 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
493 wfex.Format.nBlockAlign;
494 wfex.Format.cbSize=22;
495 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
496 wfex.dwChannelMask=SPEAKER_ALL;
497 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
498 rc=waveInOpen(&win,device,&wfex.Format,0,0,
499 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
500 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
501 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM ||
502 rc==MMSYSERR_ALLOCATED,
503 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
504 if (rc==MMSYSERR_NOERROR) {
505 waveInClose(win);
506 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
507 } else
508 trace("waveInOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
509 dev_name(device));
511 /* test if 4 channels supported */
512 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
513 wfex.Format.nChannels=4;
514 wfex.Format.wBitsPerSample=16;
515 wfex.Format.nSamplesPerSec=22050;
516 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
517 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
518 wfex.Format.nBlockAlign;
519 wfex.Format.cbSize=22;
520 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
521 wfex.dwChannelMask=SPEAKER_ALL;
522 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
523 rc=waveInOpen(&win,device,&wfex.Format,0,0,
524 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
525 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
526 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM ||
527 rc==MMSYSERR_ALLOCATED,
528 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
529 if (rc==MMSYSERR_NOERROR) {
530 waveInClose(win);
531 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
532 } else
533 trace("waveInOpen(%s): 4 channels not supported\n",
534 dev_name(device));
536 /* test if 6 channels supported */
537 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
538 wfex.Format.nChannels=6;
539 wfex.Format.wBitsPerSample=16;
540 wfex.Format.nSamplesPerSec=22050;
541 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
542 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
543 wfex.Format.nBlockAlign;
544 wfex.Format.cbSize=22;
545 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
546 wfex.dwChannelMask=SPEAKER_ALL;
547 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
548 rc=waveInOpen(&win,device,&wfex.Format,0,0,
549 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
550 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
551 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM ||
552 rc==MMSYSERR_ALLOCATED,
553 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
554 if (rc==MMSYSERR_NOERROR) {
555 waveInClose(win);
556 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
557 } else
558 trace("waveInOpen(%s): 6 channels not supported\n",
559 dev_name(device));
561 if (0)
563 /* FIXME: ALSA doesn't like this */
564 /* test if 24 bit samples supported */
565 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
566 wfex.Format.nChannels=2;
567 wfex.Format.wBitsPerSample=24;
568 wfex.Format.nSamplesPerSec=22050;
569 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
570 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
571 wfex.Format.nBlockAlign;
572 wfex.Format.cbSize=22;
573 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
574 wfex.dwChannelMask=SPEAKER_ALL;
575 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
576 rc=waveInOpen(&win,device,&wfex.Format,0,0,
577 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
578 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
579 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM ||
580 rc==MMSYSERR_ALLOCATED,
581 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
582 if (rc==MMSYSERR_NOERROR) {
583 waveInClose(win);
584 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
585 } else
586 trace("waveInOpen(%s): 24 bit samples not supported\n",
587 dev_name(device));
590 /* test if 32 bit samples supported */
591 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
592 wfex.Format.nChannels=2;
593 wfex.Format.wBitsPerSample=32;
594 wfex.Format.nSamplesPerSec=22050;
595 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
596 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
597 wfex.Format.nBlockAlign;
598 wfex.Format.cbSize=22;
599 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
600 wfex.dwChannelMask=SPEAKER_ALL;
601 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
602 rc=waveInOpen(&win,device,&wfex.Format,0,0,
603 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
604 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
605 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM ||
606 rc==MMSYSERR_ALLOCATED,
607 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
608 if (rc==MMSYSERR_NOERROR) {
609 waveInClose(win);
610 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
611 } else
612 trace("waveInOpen(%s): 32 bit samples not supported\n",
613 dev_name(device));
615 /* test if 32 bit float samples supported */
616 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
617 wfex.Format.nChannels=2;
618 wfex.Format.wBitsPerSample=32;
619 wfex.Format.nSamplesPerSec=22050;
620 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
621 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
622 wfex.Format.nBlockAlign;
623 wfex.Format.cbSize=22;
624 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
625 wfex.dwChannelMask=SPEAKER_ALL;
626 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
627 rc=waveInOpen(&win,device,&wfex.Format,0,0,
628 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
629 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
630 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM ||
631 rc==MMSYSERR_ALLOCATED,
632 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
633 if (rc==MMSYSERR_NOERROR) {
634 waveInClose(win);
635 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
636 } else
637 trace("waveInOpen(%s): 32 bit float samples not supported\n",
638 dev_name(device));
641 static void wave_in_tests(void)
643 WAVEINCAPSA capsA;
644 WAVEINCAPSW capsW;
645 WAVEFORMATEX format;
646 HWAVEIN win;
647 MMRESULT rc;
648 DWORD preferred, status;
649 UINT ndev,d;
651 ndev=waveInGetNumDevs();
652 trace("found %d WaveIn devices\n",ndev);
654 rc = waveInMessage((HWAVEIN)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET,
655 (DWORD_PTR)&preferred, (DWORD_PTR)&status);
656 ok((ndev == 0 && (rc == MMSYSERR_NODRIVER || rc == MMSYSERR_BADDEVICEID)) ||
657 rc == MMSYSERR_NOTSUPPORTED ||
658 rc == MMSYSERR_NOERROR, "waveInMessage(DRVM_MAPPER_PREFERRED_GET) failed: %u\n", rc);
660 if(rc != MMSYSERR_NOTSUPPORTED)
661 ok((ndev == 0 && (preferred == -1 || broken(preferred != -1))) ||
662 preferred < ndev, "Got invalid preferred device: 0x%x\n", preferred);
664 rc=waveInGetDevCapsA(ndev+1,&capsA,sizeof(capsA));
665 ok(rc==MMSYSERR_BADDEVICEID,
666 "waveInGetDevCapsA(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
667 dev_name(ndev+1),wave_in_error(rc));
669 rc=waveInGetDevCapsA(WAVE_MAPPER,&capsA,sizeof(capsA));
670 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NODRIVER || (!ndev && (rc==MMSYSERR_BADDEVICEID)),
671 "waveInGetDevCapsA(%s): got %s\n",dev_name(WAVE_MAPPER),wave_in_error(rc));
673 rc=waveInGetDevCapsW(ndev+1,&capsW,sizeof(capsW));
674 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NOTSUPPORTED,
675 "waveInGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
676 "expected, got %s\n",dev_name(ndev+1),wave_in_error(rc));
678 rc=waveInGetDevCapsW(WAVE_MAPPER,&capsW,sizeof(capsW));
679 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NODRIVER ||
680 rc==MMSYSERR_NOTSUPPORTED || (!ndev && (rc==MMSYSERR_BADDEVICEID)),
681 "waveInGetDevCapsW(%s): got %s\n", dev_name(ndev+1),wave_in_error(rc));
683 format.wFormatTag=WAVE_FORMAT_PCM;
684 format.nChannels=2;
685 format.wBitsPerSample=16;
686 format.nSamplesPerSec=44100;
687 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
688 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
689 format.cbSize=0;
690 rc=waveInOpen(&win,ndev+1,&format,0,0,CALLBACK_NULL);
691 ok(rc==MMSYSERR_BADDEVICEID,
692 "waveInOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
693 dev_name(ndev+1),wave_in_error(rc));
695 for (d=0;d<ndev;d++)
696 wave_in_test_device(d);
698 if (ndev>0)
699 wave_in_test_device(WAVE_MAPPER);
702 START_TEST(capture)
704 wave_in_tests();