configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / winmm / tests / capture.c
blob81d62819cc4d6c764bba9fe2176128817eec92df
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 "mmsystem.h"
31 #define NOBITMAP
32 #include "mmreg.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];
43 MMRESULT rc;
45 rc = waveInGetErrorText(error, msg, sizeof(msg));
46 if (rc != MMSYSERR_NOERROR)
47 sprintf(long_msg, "waveInGetErrorText(%x) failed with error %x", error, rc);
48 else
49 sprintf(long_msg, "%s(%s)", mmsys_error(error), msg);
50 return long_msg;
53 static void check_position(int device, HWAVEIN win, DWORD bytes,
54 LPWAVEFORMATEX pwfx )
56 MMTIME mmtime;
57 MMRESULT rc;
58 DWORD returned;
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",
104 dev_name(device));
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",
115 dev_name(device));
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",
126 dev_name(device));
129 static void wave_in_test_deviceIn(int device, LPWAVEFORMATEX pwfx, DWORD format, DWORD flags, LPWAVEINCAPS pcaps)
131 HWAVEIN win;
132 HANDLE hevent;
133 WAVEHDR frag;
134 MMRESULT rc;
135 DWORD res;
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());
142 if (hevent==NULL)
143 return;
145 win=NULL;
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) {
173 CloseHandle(hevent);
174 return;
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;
192 frag.dwUser=0;
193 frag.dwFlags=0;
194 frag.dwLoops=0;
195 frag.lpNext=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);
216 rc=waveInStart(win);
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) {
229 rc=waveInStop(win);
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));
239 rc=waveInClose(win);
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
250 HWAVEOUT wout;
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));
285 else
286 trace("Unable to play back the recorded sound\n");
289 HeapFree(GetProcessHeap(), 0, frag.lpData);
290 CloseHandle(hevent);
293 static void wave_in_test_device(UINT_PTR device)
295 WAVEINCAPSA capsA;
296 WAVEINCAPSW capsW;
297 WAVEFORMATEX format,oformat;
298 WAVEFORMATEXTENSIBLE wfex;
299 HWAVEIN win;
300 MMRESULT rc;
301 UINT f;
302 WCHAR * nameW;
303 CHAR * nameA;
304 DWORD size;
305 DWORD dwPageSize;
306 BYTE * twoPages;
307 SYSTEM_INFO sSysInfo;
308 DWORD flOldProtect;
309 BOOL res;
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)
320 return;
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));
337 if (0)
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));
362 nameA=NULL;
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;
403 format.cbSize=0;
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
414 * checking */
415 twoPages = VirtualAlloc(NULL, 2 * dwPageSize, MEM_RESERVE | MEM_COMMIT,
416 PAGE_READWRITE);
417 ok(twoPages!=NULL,"Failed to allocate 2 pages of memory\n");
418 if (twoPages) {
419 res = VirtualProtect(twoPages + dwPageSize, dwPageSize, PAGE_NOACCESS,
420 &flOldProtect);
421 ok(res, "Failed to set memory access on second page\n");
422 if (res) {
423 LPWAVEFORMATEX pwfx = (LPWAVEFORMATEX)(twoPages + dwPageSize -
424 sizeof(PCMWAVEFORMAT));
425 pwfx->wFormatTag=WAVE_FORMAT_PCM;
426 pwfx->nChannels=1;
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 /* Testing invalid format: 2 MHz sample rate */
443 format.wFormatTag=WAVE_FORMAT_PCM;
444 format.nChannels=2;
445 format.wBitsPerSample=16;
446 format.nSamplesPerSec=2000000;
447 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
448 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
449 format.cbSize=0;
450 oformat=format;
451 rc=waveInOpen(&win,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
452 ok(rc==WAVERR_BADFORMAT || rc==MMSYSERR_INVALFLAG ||
453 rc==MMSYSERR_INVALPARAM,
454 "waveInOpen(%s): opening the device with 2 MHz sample rate should fail: "
455 " rc=%s\n",dev_name(device),wave_in_error(rc));
456 if (rc==MMSYSERR_NOERROR) {
457 trace(" got %dx%2dx%d for %dx%2dx%d\n",
458 format.nSamplesPerSec, format.wBitsPerSample,
459 format.nChannels,
460 oformat.nSamplesPerSec, oformat.wBitsPerSample,
461 oformat.nChannels);
462 waveInClose(win);
465 /* test non PCM formats */
466 format.wFormatTag=WAVE_FORMAT_MULAW;
467 format.nChannels=1;
468 format.wBitsPerSample=8;
469 format.nSamplesPerSec=8000;
470 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
471 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
472 format.cbSize=0;
473 rc=waveInOpen(&win,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
474 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
475 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
476 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
477 if (rc==MMSYSERR_NOERROR) {
478 waveInClose(win);
479 wave_in_test_deviceIn(device,&format,0,0,&capsA);
480 } else
481 trace("waveInOpen(%s): WAVE_FORMAT_MULAW not supported\n",
482 dev_name(device));
484 format.wFormatTag=WAVE_FORMAT_ADPCM;
485 format.nChannels=2;
486 format.wBitsPerSample=4;
487 format.nSamplesPerSec=22050;
488 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
489 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
490 format.cbSize=0;
491 rc=waveInOpen(&win,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
492 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
493 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
494 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
495 if (rc==MMSYSERR_NOERROR) {
496 waveInClose(win);
497 wave_in_test_deviceIn(device,&format,0,0,&capsA);
498 } else
499 trace("waveInOpen(%s): WAVE_FORMAT_ADPCM not supported\n",
500 dev_name(device));
502 /* test if WAVEFORMATEXTENSIBLE supported */
503 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
504 wfex.Format.nChannels=2;
505 wfex.Format.wBitsPerSample=16;
506 wfex.Format.nSamplesPerSec=22050;
507 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
508 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
509 wfex.Format.nBlockAlign;
510 wfex.Format.cbSize=22;
511 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
512 wfex.dwChannelMask=SPEAKER_ALL;
513 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
514 rc=waveInOpen(&win,device,&wfex.Format,0,0,
515 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
516 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
517 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
518 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
519 if (rc==MMSYSERR_NOERROR) {
520 waveInClose(win);
521 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
522 } else
523 trace("waveInOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
524 dev_name(device));
526 /* test if 4 channels supported */
527 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
528 wfex.Format.nChannels=4;
529 wfex.Format.wBitsPerSample=16;
530 wfex.Format.nSamplesPerSec=22050;
531 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
532 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
533 wfex.Format.nBlockAlign;
534 wfex.Format.cbSize=22;
535 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
536 wfex.dwChannelMask=SPEAKER_ALL;
537 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
538 rc=waveInOpen(&win,device,&wfex.Format,0,0,
539 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
540 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
541 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
542 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
543 if (rc==MMSYSERR_NOERROR) {
544 waveInClose(win);
545 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
546 } else
547 trace("waveInOpen(%s): 4 channels not supported\n",
548 dev_name(device));
550 /* test if 6 channels supported */
551 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
552 wfex.Format.nChannels=6;
553 wfex.Format.wBitsPerSample=16;
554 wfex.Format.nSamplesPerSec=22050;
555 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
556 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
557 wfex.Format.nBlockAlign;
558 wfex.Format.cbSize=22;
559 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
560 wfex.dwChannelMask=SPEAKER_ALL;
561 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
562 rc=waveInOpen(&win,device,&wfex.Format,0,0,
563 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
564 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
565 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
566 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
567 if (rc==MMSYSERR_NOERROR) {
568 waveInClose(win);
569 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
570 } else
571 trace("waveInOpen(%s): 6 channels not supported\n",
572 dev_name(device));
574 if (0)
576 /* FIXME: ALSA doesn't like this */
577 /* test if 24 bit samples supported */
578 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
579 wfex.Format.nChannels=2;
580 wfex.Format.wBitsPerSample=24;
581 wfex.Format.nSamplesPerSec=22050;
582 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
583 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
584 wfex.Format.nBlockAlign;
585 wfex.Format.cbSize=22;
586 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
587 wfex.dwChannelMask=SPEAKER_ALL;
588 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
589 rc=waveInOpen(&win,device,&wfex.Format,0,0,
590 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
591 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
592 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
593 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
594 if (rc==MMSYSERR_NOERROR) {
595 waveInClose(win);
596 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
597 } else
598 trace("waveInOpen(%s): 24 bit samples not supported\n",
599 dev_name(device));
602 /* test if 32 bit samples supported */
603 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
604 wfex.Format.nChannels=2;
605 wfex.Format.wBitsPerSample=32;
606 wfex.Format.nSamplesPerSec=22050;
607 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
608 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
609 wfex.Format.nBlockAlign;
610 wfex.Format.cbSize=22;
611 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
612 wfex.dwChannelMask=SPEAKER_ALL;
613 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
614 rc=waveInOpen(&win,device,&wfex.Format,0,0,
615 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
616 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
617 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
618 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
619 if (rc==MMSYSERR_NOERROR) {
620 waveInClose(win);
621 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
622 } else
623 trace("waveInOpen(%s): 32 bit samples not supported\n",
624 dev_name(device));
626 /* test if 32 bit float samples supported */
627 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
628 wfex.Format.nChannels=2;
629 wfex.Format.wBitsPerSample=32;
630 wfex.Format.nSamplesPerSec=22050;
631 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
632 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
633 wfex.Format.nBlockAlign;
634 wfex.Format.cbSize=22;
635 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
636 wfex.dwChannelMask=SPEAKER_ALL;
637 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
638 rc=waveInOpen(&win,device,&wfex.Format,0,0,
639 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
640 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
641 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
642 "waveInOpen(%s): returned: %s\n",dev_name(device),wave_in_error(rc));
643 if (rc==MMSYSERR_NOERROR) {
644 waveInClose(win);
645 wave_in_test_deviceIn(device,&wfex.Format,0,0,&capsA);
646 } else
647 trace("waveInOpen(%s): 32 bit float samples not supported\n",
648 dev_name(device));
651 static void wave_in_tests(void)
653 WAVEINCAPSA capsA;
654 WAVEINCAPSW capsW;
655 WAVEFORMATEX format;
656 HWAVEIN win;
657 MMRESULT rc;
658 UINT ndev,d;
660 ndev=waveInGetNumDevs();
661 trace("found %d WaveIn devices\n",ndev);
663 rc=waveInGetDevCapsA(ndev+1,&capsA,sizeof(capsA));
664 ok(rc==MMSYSERR_BADDEVICEID,
665 "waveInGetDevCapsA(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
666 dev_name(ndev+1),wave_in_error(rc));
668 rc=waveInGetDevCapsA(WAVE_MAPPER,&capsA,sizeof(capsA));
669 if (ndev>0)
670 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NODRIVER,
671 "waveInGetDevCapsA(%s): MMSYSERR_NOERROR or MMSYSERR_NODRIVER "
672 "expected, got %s\n",dev_name(WAVE_MAPPER),wave_in_error(rc));
673 else
674 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER,
675 "waveInGetDevCapsA(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
676 "expected, got %s\n",dev_name(WAVE_MAPPER),wave_in_error(rc));
678 rc=waveInGetDevCapsW(ndev+1,&capsW,sizeof(capsW));
679 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NOTSUPPORTED,
680 "waveInGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
681 "expected, got %s\n",dev_name(ndev+1),wave_in_error(rc));
683 rc=waveInGetDevCapsW(WAVE_MAPPER,&capsW,sizeof(capsW));
684 if (ndev>0)
685 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NODRIVER ||
686 rc==MMSYSERR_NOTSUPPORTED,
687 "waveInGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NODRIVER or "
688 "MMSYSERR_NOTSUPPORTED expected, got %s\n",
689 dev_name(ndev+1),wave_in_error(rc));
690 else
691 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER ||
692 rc==MMSYSERR_NOTSUPPORTED,
693 "waveInGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER or"
694 "MMSYSERR_NOTSUPPORTED expected, got %s\n",
695 dev_name(ndev+1),wave_in_error(rc));
697 format.wFormatTag=WAVE_FORMAT_PCM;
698 format.nChannels=2;
699 format.wBitsPerSample=16;
700 format.nSamplesPerSec=44100;
701 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
702 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
703 format.cbSize=0;
704 rc=waveInOpen(&win,ndev+1,&format,0,0,CALLBACK_NULL);
705 ok(rc==MMSYSERR_BADDEVICEID,
706 "waveInOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
707 dev_name(ndev+1),wave_in_error(rc));
709 for (d=0;d<ndev;d++)
710 wave_in_test_device(d);
712 if (ndev>0)
713 wave_in_test_device(WAVE_MAPPER);
716 START_TEST(capture)
718 wave_in_tests();