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
26 #include "wine/test.h"
34 extern GUID KSDATAFORMAT_SUBTYPE_PCM;
35 extern GUID KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
37 #include "winmm_test.h"
39 static const char * wave_in_error(MMRESULT error)
41 static char msg[1024];
42 static char long_msg[1100];
45 rc = waveInGetErrorText(error, msg, sizeof(msg));
46 if (rc != MMSYSERR_NOERROR)
47 sprintf(long_msg, "waveInGetErrorText(%x) failed with error %x", error, rc);
49 sprintf(long_msg, "%s(%s)", mmsys_error(error), msg);
53 static void check_position(int device, HWAVEIN win, DWORD bytes,
60 mmtime.wType = TIME_BYTES;
61 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
62 ok(rc==MMSYSERR_NOERROR,
63 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
64 if (mmtime.wType != TIME_BYTES && winetest_debug > 1)
65 trace("waveInGetPosition(%s): TIME_BYTES not supported, returned %s\n",
66 dev_name(device),wave_time_format(mmtime.wType));
67 returned = time_to_bytes(&mmtime, pwfx);
68 ok(returned == bytes, "waveInGetPosition(%s): returned %d bytes, "
69 "should be %d\n", dev_name(device), returned, bytes);
71 mmtime.wType = TIME_SAMPLES;
72 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
73 ok(rc==MMSYSERR_NOERROR,
74 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
75 if (mmtime.wType != TIME_SAMPLES && winetest_debug > 1)
76 trace("waveInGetPosition(%s): TIME_SAMPLES not supported, "
77 "returned %s\n",dev_name(device),wave_time_format(mmtime.wType));
78 returned = time_to_bytes(&mmtime, pwfx);
79 ok(returned == bytes, "waveInGetPosition(%s): returned %d samples, "
80 "should be %d\n", dev_name(device), bytes_to_samples(returned, pwfx),
81 bytes_to_samples(bytes, pwfx));
83 mmtime.wType = TIME_MS;
84 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
85 ok(rc==MMSYSERR_NOERROR,
86 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
87 if (mmtime.wType != TIME_MS && winetest_debug > 1)
88 trace("waveInGetPosition(%s): TIME_MS not supported, returned %s\n",
89 dev_name(device), wave_time_format(mmtime.wType));
90 returned = time_to_bytes(&mmtime, pwfx);
91 ok(returned == bytes, "waveInGetPosition(%s): returned %d ms, "
92 "should be %d\n", dev_name(device), bytes_to_ms(returned, pwfx),
93 bytes_to_ms(bytes, pwfx));
95 mmtime.wType = TIME_SMPTE;
96 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
97 ok(rc==MMSYSERR_NOERROR,
98 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
99 if (mmtime.wType != TIME_SMPTE && winetest_debug > 1)
100 trace("waveInGetPosition(%s): TIME_SMPTE not supported, returned %s\n",
101 dev_name(device),wave_time_format(mmtime.wType));
102 returned = time_to_bytes(&mmtime, pwfx);
103 ok(returned == bytes, "waveInGetPosition(%s): SMPTE test failed\n",
106 mmtime.wType = TIME_MIDI;
107 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
108 ok(rc==MMSYSERR_NOERROR,
109 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
110 if (mmtime.wType != TIME_MIDI && winetest_debug > 1)
111 trace("waveInGetPosition(%s): TIME_MIDI not supported, returned %s\n",
112 dev_name(device),wave_time_format(mmtime.wType));
113 returned = time_to_bytes(&mmtime, pwfx);
114 ok(returned == bytes, "waveInGetPosition(%s): MIDI test failed\n",
117 mmtime.wType = TIME_TICKS;
118 rc=waveInGetPosition(win, &mmtime, sizeof(mmtime));
119 ok(rc==MMSYSERR_NOERROR,
120 "waveInGetPosition(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
121 if (mmtime.wType != TIME_TICKS && winetest_debug > 1)
122 trace("waveInGetPosition(%s): TIME_TICKS not supported, returned %s\n",
123 dev_name(device),wave_time_format(mmtime.wType));
124 returned = time_to_bytes(&mmtime, pwfx);
125 ok(returned == bytes, "waveInGetPosition(%s): TICKS test failed\n",
129 static void wave_in_test_deviceIn(int device, LPWAVEFORMATEX pwfx, DWORD format, DWORD flags, LPWAVEINCAPS pcaps)
136 WORD nChannels = pwfx->nChannels;
137 WORD wBitsPerSample = pwfx->wBitsPerSample;
138 DWORD nSamplesPerSec = pwfx->nSamplesPerSec;
140 hevent=CreateEvent(NULL,FALSE,FALSE,NULL);
141 ok(hevent!=NULL,"CreateEvent(): error=%d\n",GetLastError());
146 rc=waveInOpen(&win,device,pwfx,(DWORD_PTR)hevent,0,CALLBACK_EVENT|flags);
147 /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */
148 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
149 rc==MMSYSERR_NOTENABLED || rc==MMSYSERR_NODRIVER ||
150 rc==MMSYSERR_ALLOCATED ||
151 ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
152 (flags & WAVE_FORMAT_DIRECT) && !(pcaps->dwFormats & format)) ||
153 ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
154 (!(flags & WAVE_FORMAT_DIRECT) || (flags & WAVE_MAPPED)) &&
155 !(pcaps->dwFormats & format)) ||
156 (rc==MMSYSERR_INVALFLAG && (flags & WAVE_FORMAT_DIRECT)),
157 "waveInOpen(%s): format=%dx%2dx%d flags=%lx(%s) rc=%s\n",
158 dev_name(device),pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
159 pwfx->nChannels,CALLBACK_EVENT|flags,
160 wave_open_flags(CALLBACK_EVENT|flags),wave_in_error(rc));
161 if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
162 (flags & WAVE_FORMAT_DIRECT) && (pcaps->dwFormats & format))
163 trace(" Reason: The device lists this format as supported in it's "
164 "capabilities but opening it failed.\n");
165 if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
166 !(pcaps->dwFormats & format))
167 trace("waveInOpen(%s): format=%dx%2dx%d %s rc=%s failed but format "
168 "not supported so OK.\n",dev_name(device),pwfx->nSamplesPerSec,
169 pwfx->wBitsPerSample,pwfx->nChannels,
170 flags & WAVE_FORMAT_DIRECT ? "flags=WAVE_FORMAT_DIRECT" :
171 flags & WAVE_MAPPED ? "flags=WAVE_MAPPED" : "", mmsys_error(rc));
172 if (rc!=MMSYSERR_NOERROR) {
176 res=WaitForSingleObject(hevent,1000);
177 ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for open\n");
179 ok(pwfx->nChannels==nChannels &&
180 pwfx->wBitsPerSample==wBitsPerSample &&
181 pwfx->nSamplesPerSec==nSamplesPerSec,
182 "got the wrong format: %dx%2dx%d instead of %dx%2dx%d\n",
183 pwfx->nSamplesPerSec, pwfx->wBitsPerSample,
184 pwfx->nChannels, nSamplesPerSec, wBitsPerSample, nChannels);
186 /* Check that the position is 0 at start */
187 check_position(device, win, 0, pwfx);
189 frag.lpData=HeapAlloc(GetProcessHeap(), 0, pwfx->nAvgBytesPerSec);
190 frag.dwBufferLength=pwfx->nAvgBytesPerSec;
191 frag.dwBytesRecorded=0;
197 rc=waveInPrepareHeader(win, &frag, sizeof(frag));
198 ok(rc==MMSYSERR_NOERROR, "waveInPrepareHeader(%s): rc=%s\n",
199 dev_name(device),wave_in_error(rc));
200 ok(frag.dwFlags&WHDR_PREPARED,"waveInPrepareHeader(%s): prepared flag "
201 "not set\n",dev_name(device));
203 if (winetest_interactive && rc==MMSYSERR_NOERROR) {
204 trace("Recording for 1 second at %5dx%2dx%d %s %s\n",
205 pwfx->nSamplesPerSec, pwfx->wBitsPerSample,pwfx->nChannels,
206 get_format_str(pwfx->wFormatTag),
207 flags & WAVE_FORMAT_DIRECT ? "WAVE_FORMAT_DIRECT" :
208 flags & WAVE_MAPPED ? "WAVE_MAPPED" : "");
209 rc=waveInAddBuffer(win, &frag, sizeof(frag));
210 ok(rc==MMSYSERR_NOERROR,"waveInAddBuffer(%s): rc=%s\n",
211 dev_name(device),wave_in_error(rc));
213 /* Check that the position is 0 at start */
214 check_position(device, win, 0, pwfx);
217 ok(rc==MMSYSERR_NOERROR,"waveInStart(%s): rc=%s\n",
218 dev_name(device),wave_in_error(rc));
220 res = WaitForSingleObject(hevent,1200);
221 ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for header\n");
222 ok(frag.dwFlags&WHDR_DONE,"WHDR_DONE not set in frag.dwFlags\n");
223 ok(frag.dwBytesRecorded==pwfx->nAvgBytesPerSec,
224 "frag.dwBytesRecorded=%d, should=%d\n",
225 frag.dwBytesRecorded,pwfx->nAvgBytesPerSec);
227 /* stop playing on error */
228 if (res!=WAIT_OBJECT_0) {
230 ok(rc==MMSYSERR_NOERROR,
231 "waveInStop(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
235 rc=waveInUnprepareHeader(win, &frag, sizeof(frag));
236 ok(rc==MMSYSERR_NOERROR,"waveInUnprepareHeader(%s): rc=%s\n",
237 dev_name(device),wave_in_error(rc));
240 ok(rc==MMSYSERR_NOERROR,
241 "waveInClose(%s): rc=%s\n",dev_name(device),wave_in_error(rc));
242 res=WaitForSingleObject(hevent,1000);
243 ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for close\n");
245 if (winetest_interactive)
248 * Now play back what we recorded
252 trace("Playing back recorded sound\n");
253 rc=waveOutOpen(&wout,WAVE_MAPPER,pwfx,(DWORD_PTR)hevent,0,CALLBACK_EVENT);
254 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
255 rc==MMSYSERR_NOTENABLED || rc==MMSYSERR_NODRIVER ||
256 rc==MMSYSERR_ALLOCATED ||
257 ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
258 !(pcaps->dwFormats & format)),
259 "waveOutOpen(%s) format=%dx%2dx%d flags=%lx(%s) rc=%s\n",
260 dev_name(device),pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
261 pwfx->nChannels,CALLBACK_EVENT|flags,
262 wave_open_flags(CALLBACK_EVENT),wave_out_error(rc));
263 if (rc==MMSYSERR_NOERROR)
265 rc=waveOutPrepareHeader(wout, &frag, sizeof(frag));
266 ok(rc==MMSYSERR_NOERROR,"waveOutPrepareHeader(%s): rc=%s\n",
267 dev_name(device),wave_out_error(rc));
269 if (rc==MMSYSERR_NOERROR)
271 WaitForSingleObject(hevent,INFINITE);
272 rc=waveOutWrite(wout, &frag, sizeof(frag));
273 ok(rc==MMSYSERR_NOERROR,"waveOutWrite(%s): rc=%s\n",
274 dev_name(device),wave_out_error(rc));
275 WaitForSingleObject(hevent,INFINITE);
277 rc=waveOutUnprepareHeader(wout, &frag, sizeof(frag));
278 ok(rc==MMSYSERR_NOERROR,"waveOutUnprepareHeader(%s): rc=%s\n",
279 dev_name(device),wave_out_error(rc));
281 rc=waveOutClose(wout);
282 ok(rc==MMSYSERR_NOERROR,"waveOutClose(%s): rc=%s\n",
283 dev_name(device),wave_out_error(rc));
286 trace("Unable to play back the recorded sound\n");
289 HeapFree(GetProcessHeap(), 0, frag.lpData);
293 static void wave_in_test_device(UINT_PTR device)
298 WAVEFORMATEXTENSIBLE wfex;
307 SYSTEM_INFO sSysInfo;
311 GetSystemInfo(&sSysInfo);
312 dwPageSize = sSysInfo.dwPageSize;
314 rc=waveInGetDevCapsA(device,&capsA,sizeof(capsA));
315 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
316 rc==MMSYSERR_NODRIVER,
317 "waveInGetDevCapsA(%s): failed to get capabilities: rc=%s\n",
318 dev_name(device),wave_in_error(rc));
319 if (rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER)
322 rc=waveInGetDevCapsW(device,&capsW,sizeof(capsW));
323 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED,
324 "waveInGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
325 "expected, got %s\n",dev_name(device),wave_in_error(rc));
327 rc=waveInGetDevCapsA(device,NULL,sizeof(capsA));
328 ok(rc==MMSYSERR_INVALPARAM,
329 "waveInGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
330 dev_name(device),wave_in_error(rc));
332 rc=waveInGetDevCapsW(device,NULL,sizeof(capsW));
333 ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
334 "waveInGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
335 "expected, got %s\n",dev_name(device),wave_in_error(rc));
339 /* FIXME: this works on windows but crashes wine */
340 rc=waveInGetDevCapsA(device,(LPWAVEINCAPSA)1,sizeof(capsA));
341 ok(rc==MMSYSERR_INVALPARAM,
342 "waveInGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
343 dev_name(device),wave_in_error(rc));
345 rc=waveInGetDevCapsW(device,(LPWAVEINCAPSW)1,sizeof(capsW));
346 ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
347 "waveInGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
348 "expected, got %s\n",dev_name(device),wave_in_error(rc));
351 rc=waveInGetDevCapsA(device,&capsA,4);
352 ok(rc==MMSYSERR_NOERROR,
353 "waveInGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
354 dev_name(device),wave_in_error(rc));
356 rc=waveInGetDevCapsW(device,&capsW,4);
357 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED ||
358 rc==MMSYSERR_INVALPARAM, /* Vista, W2K8 */
359 "waveInGetDevCapsW(%s): unexpected return value %s\n",
360 dev_name(device),wave_in_error(rc));
363 rc=waveInMessage((HWAVEIN)device, DRV_QUERYDEVICEINTERFACESIZE,
364 (DWORD_PTR)&size, 0);
365 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_INVALPARAM ||
366 rc==MMSYSERR_NOTSUPPORTED,
367 "waveInMessage(%s): failed to get interface size: rc=%s\n",
368 dev_name(device),wave_in_error(rc));
369 if (rc==MMSYSERR_NOERROR) {
370 nameW = HeapAlloc(GetProcessHeap(), 0, size);
371 rc=waveInMessage((HWAVEIN)device, DRV_QUERYDEVICEINTERFACE,
372 (DWORD_PTR)nameW, size);
373 ok(rc==MMSYSERR_NOERROR,"waveInMessage(%s): failed to get interface "
374 "name: rc=%s\n",dev_name(device),wave_in_error(rc));
375 ok(lstrlenW(nameW)+1==size/sizeof(WCHAR),
376 "got an incorrect size %d\n", size);
377 if (rc==MMSYSERR_NOERROR) {
378 nameA = HeapAlloc(GetProcessHeap(), 0, size/sizeof(WCHAR));
379 WideCharToMultiByte(CP_ACP, 0, nameW, size/sizeof(WCHAR),
380 nameA, size/sizeof(WCHAR), NULL, NULL);
382 HeapFree(GetProcessHeap(), 0, nameW);
383 } else if (rc==MMSYSERR_NOTSUPPORTED) {
384 nameA=HeapAlloc(GetProcessHeap(), 0, sizeof("not supported"));
385 strcpy(nameA, "not supported");
388 trace(" %s: \"%s\" (%s) %d.%d (%d:%d)\n",dev_name(device),capsA.szPname,
389 (nameA?nameA:"failed"),capsA.vDriverVersion >> 8,
390 capsA.vDriverVersion & 0xff,capsA.wMid,capsA.wPid);
391 trace(" channels=%d formats=%05x\n",
392 capsA.wChannels,capsA.dwFormats);
394 HeapFree(GetProcessHeap(), 0, nameA);
396 for (f=0;f<NB_WIN_FORMATS;f++) {
397 format.wFormatTag=WAVE_FORMAT_PCM;
398 format.nChannels=win_formats[f][3];
399 format.wBitsPerSample=win_formats[f][2];
400 format.nSamplesPerSec=win_formats[f][1];
401 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
402 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
404 wave_in_test_deviceIn(device,&format,win_formats[f][0],0, &capsA);
405 if (device != WAVE_MAPPER) {
406 wave_in_test_deviceIn(device,&format,win_formats[f][0],
407 WAVE_FORMAT_DIRECT, &capsA);
408 wave_in_test_deviceIn(device,&format,win_formats[f][0],
409 WAVE_MAPPED, &capsA);
413 /* Try a PCMWAVEFORMAT aligned next to an unaccessible page for bounds
415 twoPages = VirtualAlloc(NULL, 2 * dwPageSize, MEM_RESERVE | MEM_COMMIT,
417 ok(twoPages!=NULL,"Failed to allocate 2 pages of memory\n");
419 res = VirtualProtect(twoPages + dwPageSize, dwPageSize, PAGE_NOACCESS,
421 ok(res, "Failed to set memory access on second page\n");
423 LPWAVEFORMATEX pwfx = (LPWAVEFORMATEX)(twoPages + dwPageSize -
424 sizeof(PCMWAVEFORMAT));
425 pwfx->wFormatTag=WAVE_FORMAT_PCM;
427 pwfx->wBitsPerSample=8;
428 pwfx->nSamplesPerSec=22050;
429 pwfx->nBlockAlign=pwfx->nChannels*pwfx->wBitsPerSample/8;
430 pwfx->nAvgBytesPerSec=pwfx->nSamplesPerSec*pwfx->nBlockAlign;
431 wave_in_test_deviceIn(device,pwfx,WAVE_FORMAT_2M08,0, &capsA);
432 if (device != WAVE_MAPPER) {
433 wave_in_test_deviceIn(device,pwfx,WAVE_FORMAT_2M08,
434 WAVE_FORMAT_DIRECT, &capsA);
435 wave_in_test_deviceIn(device,pwfx,WAVE_FORMAT_2M08,
436 WAVE_MAPPED, &capsA);
439 VirtualFree(twoPages, 2 * dwPageSize, MEM_RELEASE);
442 /* test non PCM formats */
443 format.wFormatTag=WAVE_FORMAT_MULAW;
445 format.wBitsPerSample=8;
446 format.nSamplesPerSec=8000;
447 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
448 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
450 rc=waveInOpen(&win,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
451 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
452 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
453 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
454 if (rc==MMSYSERR_NOERROR) {
456 wave_in_test_deviceIn(device,&format,0,0,&capsA);
458 trace("waveInOpen(%s): WAVE_FORMAT_MULAW not supported\n",
461 format.wFormatTag=WAVE_FORMAT_ADPCM;
463 format.wBitsPerSample=4;
464 format.nSamplesPerSec=22050;
465 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
466 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
468 rc=waveInOpen(&win,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
469 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
470 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
471 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
472 if (rc==MMSYSERR_NOERROR) {
474 wave_in_test_deviceIn(device,&format,0,0,&capsA);
476 trace("waveInOpen(%s): WAVE_FORMAT_ADPCM not supported\n",
479 /* test if WAVEFORMATEXTENSIBLE supported */
480 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
481 wfex.Format.nChannels=2;
482 wfex.Format.wBitsPerSample=16;
483 wfex.Format.nSamplesPerSec=22050;
484 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
485 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
486 wfex.Format.nBlockAlign;
487 wfex.Format.cbSize=22;
488 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
489 wfex.dwChannelMask=SPEAKER_ALL;
490 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
491 rc=waveInOpen(&win,device,&wfex.Format,0,0,
492 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
493 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
494 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
495 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
496 if (rc==MMSYSERR_NOERROR) {
498 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
500 trace("waveInOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
503 /* test if 4 channels supported */
504 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
505 wfex.Format.nChannels=4;
506 wfex.Format.wBitsPerSample=16;
507 wfex.Format.nSamplesPerSec=22050;
508 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
509 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
510 wfex.Format.nBlockAlign;
511 wfex.Format.cbSize=22;
512 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
513 wfex.dwChannelMask=SPEAKER_ALL;
514 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
515 rc=waveInOpen(&win,device,&wfex.Format,0,0,
516 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
517 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
518 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
519 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
520 if (rc==MMSYSERR_NOERROR) {
522 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
524 trace("waveInOpen(%s): 4 channels not supported\n",
527 /* test if 6 channels supported */
528 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
529 wfex.Format.nChannels=6;
530 wfex.Format.wBitsPerSample=16;
531 wfex.Format.nSamplesPerSec=22050;
532 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
533 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
534 wfex.Format.nBlockAlign;
535 wfex.Format.cbSize=22;
536 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
537 wfex.dwChannelMask=SPEAKER_ALL;
538 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
539 rc=waveInOpen(&win,device,&wfex.Format,0,0,
540 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
541 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
542 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
543 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
544 if (rc==MMSYSERR_NOERROR) {
546 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
548 trace("waveInOpen(%s): 6 channels not supported\n",
553 /* FIXME: ALSA doesn't like this */
554 /* test if 24 bit samples supported */
555 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
556 wfex.Format.nChannels=2;
557 wfex.Format.wBitsPerSample=24;
558 wfex.Format.nSamplesPerSec=22050;
559 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
560 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
561 wfex.Format.nBlockAlign;
562 wfex.Format.cbSize=22;
563 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
564 wfex.dwChannelMask=SPEAKER_ALL;
565 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
566 rc=waveInOpen(&win,device,&wfex.Format,0,0,
567 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
568 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
569 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
570 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
571 if (rc==MMSYSERR_NOERROR) {
573 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
575 trace("waveInOpen(%s): 24 bit samples not supported\n",
579 /* test if 32 bit samples supported */
580 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
581 wfex.Format.nChannels=2;
582 wfex.Format.wBitsPerSample=32;
583 wfex.Format.nSamplesPerSec=22050;
584 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
585 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
586 wfex.Format.nBlockAlign;
587 wfex.Format.cbSize=22;
588 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
589 wfex.dwChannelMask=SPEAKER_ALL;
590 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
591 rc=waveInOpen(&win,device,&wfex.Format,0,0,
592 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
593 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
594 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
595 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
596 if (rc==MMSYSERR_NOERROR) {
598 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
600 trace("waveInOpen(%s): 32 bit samples not supported\n",
603 /* test if 32 bit float samples supported */
604 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
605 wfex.Format.nChannels=2;
606 wfex.Format.wBitsPerSample=32;
607 wfex.Format.nSamplesPerSec=22050;
608 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
609 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
610 wfex.Format.nBlockAlign;
611 wfex.Format.cbSize=22;
612 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
613 wfex.dwChannelMask=SPEAKER_ALL;
614 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
615 rc=waveInOpen(&win,device,&wfex.Format,0,0,
616 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
617 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
618 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
619 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
620 if (rc==MMSYSERR_NOERROR) {
622 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
624 trace("waveInOpen(%s): 32 bit float samples not supported\n",
628 static void wave_in_tests(void)
637 ndev=waveInGetNumDevs();
638 trace("found %d WaveIn devices\n",ndev);
640 rc=waveInGetDevCapsA(ndev+1,&capsA,sizeof(capsA));
641 ok(rc==MMSYSERR_BADDEVICEID,
642 "waveInGetDevCapsA(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
643 dev_name(ndev+1),wave_in_error(rc));
645 rc=waveInGetDevCapsA(WAVE_MAPPER,&capsA,sizeof(capsA));
646 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NODRIVER || (!ndev && (rc==MMSYSERR_BADDEVICEID)),
647 "waveInGetDevCapsA(%s): got %s\n",dev_name(WAVE_MAPPER),wave_in_error(rc));
649 rc=waveInGetDevCapsW(ndev+1,&capsW,sizeof(capsW));
650 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NOTSUPPORTED,
651 "waveInGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
652 "expected, got %s\n",dev_name(ndev+1),wave_in_error(rc));
654 rc=waveInGetDevCapsW(WAVE_MAPPER,&capsW,sizeof(capsW));
655 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NODRIVER ||
656 rc==MMSYSERR_NOTSUPPORTED || (!ndev && (rc==MMSYSERR_BADDEVICEID)),
657 "waveInGetDevCapsW(%s): got %s\n", dev_name(ndev+1),wave_in_error(rc));
659 format.wFormatTag=WAVE_FORMAT_PCM;
661 format.wBitsPerSample=16;
662 format.nSamplesPerSec=44100;
663 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
664 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
666 rc=waveInOpen(&win,ndev+1,&format,0,0,CALLBACK_NULL);
667 ok(rc==MMSYSERR_BADDEVICEID,
668 "waveInOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
669 dev_name(ndev+1),wave_in_error(rc));
672 wave_in_test_device(d);
675 wave_in_test_device(WAVE_MAPPER);