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
)
297 WAVEFORMATEX format
,oformat
;
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 /* Testing invalid format: 2 MHz sample rate */
443 format
.wFormatTag
=WAVE_FORMAT_PCM
;
445 format
.wBitsPerSample
=16;
446 format
.nSamplesPerSec
=2000000;
447 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
448 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
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
,
460 oformat
.nSamplesPerSec
, oformat
.wBitsPerSample
,
465 /* test non PCM formats */
466 format
.wFormatTag
=WAVE_FORMAT_MULAW
;
468 format
.wBitsPerSample
=8;
469 format
.nSamplesPerSec
=8000;
470 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
471 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
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
) {
479 wave_in_test_deviceIn(device
,&format
,0,0,&capsA
);
481 trace("waveInOpen(%s): WAVE_FORMAT_MULAW not supported\n",
484 format
.wFormatTag
=WAVE_FORMAT_ADPCM
;
486 format
.wBitsPerSample
=4;
487 format
.nSamplesPerSec
=22050;
488 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
489 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
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
) {
497 wave_in_test_deviceIn(device
,&format
,0,0,&capsA
);
499 trace("waveInOpen(%s): WAVE_FORMAT_ADPCM not supported\n",
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
) {
521 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
523 trace("waveInOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
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
) {
545 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
547 trace("waveInOpen(%s): 4 channels not supported\n",
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
) {
569 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
571 trace("waveInOpen(%s): 6 channels not supported\n",
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
) {
596 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
598 trace("waveInOpen(%s): 24 bit samples not supported\n",
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
) {
621 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
623 trace("waveInOpen(%s): 32 bit samples not supported\n",
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
) {
645 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
647 trace("waveInOpen(%s): 32 bit float samples not supported\n",
651 static void wave_in_tests(void)
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 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NODRIVER
|| (!ndev
&& (rc
==MMSYSERR_BADDEVICEID
)),
670 "waveInGetDevCapsA(%s): got %s\n",dev_name(WAVE_MAPPER
),wave_in_error(rc
));
672 rc
=waveInGetDevCapsW(ndev
+1,&capsW
,sizeof(capsW
));
673 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NOTSUPPORTED
,
674 "waveInGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
675 "expected, got %s\n",dev_name(ndev
+1),wave_in_error(rc
));
677 rc
=waveInGetDevCapsW(WAVE_MAPPER
,&capsW
,sizeof(capsW
));
678 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NODRIVER
||
679 rc
==MMSYSERR_NOTSUPPORTED
|| (!ndev
&& (rc
==MMSYSERR_BADDEVICEID
)),
680 "waveInGetDevCapsW(%s): got %s\n", dev_name(ndev
+1),wave_in_error(rc
));
682 format
.wFormatTag
=WAVE_FORMAT_PCM
;
684 format
.wBitsPerSample
=16;
685 format
.nSamplesPerSec
=44100;
686 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
687 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
689 rc
=waveInOpen(&win
,ndev
+1,&format
,0,0,CALLBACK_NULL
);
690 ok(rc
==MMSYSERR_BADDEVICEID
,
691 "waveInOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
692 dev_name(ndev
+1),wave_in_error(rc
));
695 wave_in_test_device(d
);
698 wave_in_test_device(WAVE_MAPPER
);