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
,
62 samples
=bytes
/(pwfx
->wBitsPerSample
/8*pwfx
->nChannels
);
63 duration
=((double)samples
)/pwfx
->nSamplesPerSec
;
65 mmtime
.wType
= TIME_BYTES
;
66 rc
=waveInGetPosition(win
, &mmtime
, sizeof(mmtime
));
67 ok(rc
==MMSYSERR_NOERROR
,
68 "waveInGetPosition(%s): rc=%s\n",dev_name(device
),wave_in_error(rc
));
69 if (mmtime
.wType
!= TIME_BYTES
&& winetest_debug
> 1)
70 trace("waveInGetPosition(%s): TIME_BYTES not supported, returned %s\n",
71 dev_name(device
),wave_time_format(mmtime
.wType
));
72 returned
= time_to_bytes(&mmtime
, pwfx
);
73 ok(returned
== bytes
, "waveInGetPosition(%s): returned %d bytes, "
74 "should be %d\n", dev_name(device
), returned
, bytes
);
76 mmtime
.wType
= TIME_SAMPLES
;
77 rc
=waveInGetPosition(win
, &mmtime
, sizeof(mmtime
));
78 ok(rc
==MMSYSERR_NOERROR
,
79 "waveInGetPosition(%s): rc=%s\n",dev_name(device
),wave_in_error(rc
));
80 if (mmtime
.wType
!= TIME_SAMPLES
&& winetest_debug
> 1)
81 trace("waveInGetPosition(%s): TIME_SAMPLES not supported, "
82 "returned %s\n",dev_name(device
),wave_time_format(mmtime
.wType
));
83 returned
= time_to_bytes(&mmtime
, pwfx
);
84 ok(returned
== bytes
, "waveInGetPosition(%s): returned %d samples, "
85 "should be %d\n", dev_name(device
), bytes_to_samples(returned
, pwfx
),
86 bytes_to_samples(bytes
, pwfx
));
88 mmtime
.wType
= TIME_MS
;
89 rc
=waveInGetPosition(win
, &mmtime
, sizeof(mmtime
));
90 ok(rc
==MMSYSERR_NOERROR
,
91 "waveInGetPosition(%s): rc=%s\n",dev_name(device
),wave_in_error(rc
));
92 if (mmtime
.wType
!= TIME_MS
&& winetest_debug
> 1)
93 trace("waveInGetPosition(%s): TIME_MS not supported, returned %s\n",
94 dev_name(device
), wave_time_format(mmtime
.wType
));
95 returned
= time_to_bytes(&mmtime
, pwfx
);
96 ok(returned
== bytes
, "waveInGetPosition(%s): returned %d ms, "
97 "should be %d\n", dev_name(device
), bytes_to_ms(returned
, pwfx
),
98 bytes_to_ms(bytes
, pwfx
));
100 mmtime
.wType
= TIME_SMPTE
;
101 rc
=waveInGetPosition(win
, &mmtime
, sizeof(mmtime
));
102 ok(rc
==MMSYSERR_NOERROR
,
103 "waveInGetPosition(%s): rc=%s\n",dev_name(device
),wave_in_error(rc
));
104 if (mmtime
.wType
!= TIME_SMPTE
&& winetest_debug
> 1)
105 trace("waveInGetPosition(%s): TIME_SMPTE not supported, returned %s\n",
106 dev_name(device
),wave_time_format(mmtime
.wType
));
107 returned
= time_to_bytes(&mmtime
, pwfx
);
108 ok(returned
== bytes
, "waveInGetPosition(%s): SMPTE test failed\n",
111 mmtime
.wType
= TIME_MIDI
;
112 rc
=waveInGetPosition(win
, &mmtime
, sizeof(mmtime
));
113 ok(rc
==MMSYSERR_NOERROR
,
114 "waveInGetPosition(%s): rc=%s\n",dev_name(device
),wave_in_error(rc
));
115 if (mmtime
.wType
!= TIME_MIDI
&& winetest_debug
> 1)
116 trace("waveInGetPosition(%s): TIME_MIDI not supported, returned %s\n",
117 dev_name(device
),wave_time_format(mmtime
.wType
));
118 returned
= time_to_bytes(&mmtime
, pwfx
);
119 ok(returned
== bytes
, "waveInGetPosition(%s): MIDI test failed\n",
122 mmtime
.wType
= TIME_TICKS
;
123 rc
=waveInGetPosition(win
, &mmtime
, sizeof(mmtime
));
124 ok(rc
==MMSYSERR_NOERROR
,
125 "waveInGetPosition(%s): rc=%s\n",dev_name(device
),wave_in_error(rc
));
126 if (mmtime
.wType
!= TIME_TICKS
&& winetest_debug
> 1)
127 trace("waveInGetPosition(%s): TIME_TICKS not supported, returned %s\n",
128 dev_name(device
),wave_time_format(mmtime
.wType
));
129 returned
= time_to_bytes(&mmtime
, pwfx
);
130 ok(returned
== bytes
, "waveInGetPosition(%s): TICKS test failed\n",
134 static void wave_in_test_deviceIn(int device
, LPWAVEFORMATEX pwfx
, DWORD format
, DWORD flags
, LPWAVEINCAPS pcaps
)
141 WORD nChannels
= pwfx
->nChannels
;
142 WORD wBitsPerSample
= pwfx
->wBitsPerSample
;
143 DWORD nSamplesPerSec
= pwfx
->nSamplesPerSec
;
145 hevent
=CreateEvent(NULL
,FALSE
,FALSE
,NULL
);
146 ok(hevent
!=NULL
,"CreateEvent(): error=%d\n",GetLastError());
151 rc
=waveInOpen(&win
,device
,pwfx
,(DWORD_PTR
)hevent
,0,CALLBACK_EVENT
|flags
);
152 /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */
153 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_BADDEVICEID
||
154 rc
==MMSYSERR_NOTENABLED
|| rc
==MMSYSERR_NODRIVER
||
155 rc
==MMSYSERR_ALLOCATED
||
156 ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
157 (flags
& WAVE_FORMAT_DIRECT
) && !(pcaps
->dwFormats
& format
)) ||
158 ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
159 (!(flags
& WAVE_FORMAT_DIRECT
) || (flags
& WAVE_MAPPED
)) &&
160 !(pcaps
->dwFormats
& format
)) ||
161 (rc
==MMSYSERR_INVALFLAG
&& (flags
& WAVE_FORMAT_DIRECT
)),
162 "waveInOpen(%s): format=%dx%2dx%d flags=%lx(%s) rc=%s\n",
163 dev_name(device
),pwfx
->nSamplesPerSec
,pwfx
->wBitsPerSample
,
164 pwfx
->nChannels
,CALLBACK_EVENT
|flags
,
165 wave_open_flags(CALLBACK_EVENT
|flags
),wave_in_error(rc
));
166 if ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
167 (flags
& WAVE_FORMAT_DIRECT
) && (pcaps
->dwFormats
& format
))
168 trace(" Reason: The device lists this format as supported in it's "
169 "capabilities but opening it failed.\n");
170 if ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
171 !(pcaps
->dwFormats
& format
))
172 trace("waveInOpen(%s): format=%dx%2dx%d %s rc=%s failed but format "
173 "not supported so OK.\n",dev_name(device
),pwfx
->nSamplesPerSec
,
174 pwfx
->wBitsPerSample
,pwfx
->nChannels
,
175 flags
& WAVE_FORMAT_DIRECT
? "flags=WAVE_FORMAT_DIRECT" :
176 flags
& WAVE_MAPPED
? "flags=WAVE_MAPPED" : "", mmsys_error(rc
));
177 if (rc
!=MMSYSERR_NOERROR
) {
181 res
=WaitForSingleObject(hevent
,1000);
182 ok(res
==WAIT_OBJECT_0
,"WaitForSingleObject failed for open\n");
184 ok(pwfx
->nChannels
==nChannels
&&
185 pwfx
->wBitsPerSample
==wBitsPerSample
&&
186 pwfx
->nSamplesPerSec
==nSamplesPerSec
,
187 "got the wrong format: %dx%2dx%d instead of %dx%2dx%d\n",
188 pwfx
->nSamplesPerSec
, pwfx
->wBitsPerSample
,
189 pwfx
->nChannels
, nSamplesPerSec
, wBitsPerSample
, nChannels
);
191 /* Check that the position is 0 at start */
192 check_position(device
, win
, 0, pwfx
);
194 frag
.lpData
=HeapAlloc(GetProcessHeap(), 0, pwfx
->nAvgBytesPerSec
);
195 frag
.dwBufferLength
=pwfx
->nAvgBytesPerSec
;
196 frag
.dwBytesRecorded
=0;
202 rc
=waveInPrepareHeader(win
, &frag
, sizeof(frag
));
203 ok(rc
==MMSYSERR_NOERROR
, "waveInPrepareHeader(%s): rc=%s\n",
204 dev_name(device
),wave_in_error(rc
));
205 ok(frag
.dwFlags
&WHDR_PREPARED
,"waveInPrepareHeader(%s): prepared flag "
206 "not set\n",dev_name(device
));
208 if (winetest_interactive
&& rc
==MMSYSERR_NOERROR
) {
209 trace("Recording for 1 second at %5dx%2dx%d %s %s\n",
210 pwfx
->nSamplesPerSec
, pwfx
->wBitsPerSample
,pwfx
->nChannels
,
211 get_format_str(pwfx
->wFormatTag
),
212 flags
& WAVE_FORMAT_DIRECT
? "WAVE_FORMAT_DIRECT" :
213 flags
& WAVE_MAPPED
? "WAVE_MAPPED" : "");
214 rc
=waveInAddBuffer(win
, &frag
, sizeof(frag
));
215 ok(rc
==MMSYSERR_NOERROR
,"waveInAddBuffer(%s): rc=%s\n",
216 dev_name(device
),wave_in_error(rc
));
218 /* Check that the position is 0 at start */
219 check_position(device
, win
, 0, pwfx
);
222 ok(rc
==MMSYSERR_NOERROR
,"waveInStart(%s): rc=%s\n",
223 dev_name(device
),wave_in_error(rc
));
225 res
= WaitForSingleObject(hevent
,1200);
226 ok(res
==WAIT_OBJECT_0
,"WaitForSingleObject failed for header\n");
227 ok(frag
.dwFlags
&WHDR_DONE
,"WHDR_DONE not set in frag.dwFlags\n");
228 ok(frag
.dwBytesRecorded
==pwfx
->nAvgBytesPerSec
,
229 "frag.dwBytesRecorded=%d, should=%d\n",
230 frag
.dwBytesRecorded
,pwfx
->nAvgBytesPerSec
);
232 /* stop playing on error */
233 if (res
!=WAIT_OBJECT_0
) {
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
));
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
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=%lx(%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
));
291 trace("Unable to play back the recorded sound\n");
294 HeapFree(GetProcessHeap(), 0, frag
.lpData
);
298 static void wave_in_test_device(UINT_PTR device
)
302 WAVEFORMATEX format
,oformat
;
303 WAVEFORMATEXTENSIBLE wfex
;
312 SYSTEM_INFO sSysInfo
;
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
)
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
));
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
));
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
;
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
420 twoPages
= VirtualAlloc(NULL
, 2 * dwPageSize
, MEM_RESERVE
| MEM_COMMIT
,
422 ok(twoPages
!=NULL
,"Failed to allocate 2 pages of memory\n");
424 res
= VirtualProtect(twoPages
+ dwPageSize
, dwPageSize
, PAGE_NOACCESS
,
426 ok(res
, "Failed to set memory access on second page\n");
428 LPWAVEFORMATEX pwfx
= (LPWAVEFORMATEX
)(twoPages
+ dwPageSize
-
429 sizeof(PCMWAVEFORMAT
));
430 pwfx
->wFormatTag
=WAVE_FORMAT_PCM
;
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 /* Testing invalid format: 2 MHz sample rate */
448 format
.wFormatTag
=WAVE_FORMAT_PCM
;
450 format
.wBitsPerSample
=16;
451 format
.nSamplesPerSec
=2000000;
452 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
453 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
456 rc
=waveInOpen(&win
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
457 ok(rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_INVALFLAG
||
458 rc
==MMSYSERR_INVALPARAM
,
459 "waveInOpen(%s): opening the device with 2 MHz sample rate should fail: "
460 " rc=%s\n",dev_name(device
),wave_in_error(rc
));
461 if (rc
==MMSYSERR_NOERROR
) {
462 trace(" got %dx%2dx%d for %dx%2dx%d\n",
463 format
.nSamplesPerSec
, format
.wBitsPerSample
,
465 oformat
.nSamplesPerSec
, oformat
.wBitsPerSample
,
470 /* test non PCM formats */
471 format
.wFormatTag
=WAVE_FORMAT_MULAW
;
473 format
.wBitsPerSample
=8;
474 format
.nSamplesPerSec
=8000;
475 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
476 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
478 rc
=waveInOpen(&win
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
479 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
480 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
481 "waveInOpen(%s): returned: %s\n",dev_name(device
),wave_in_error(rc
));
482 if (rc
==MMSYSERR_NOERROR
) {
484 wave_in_test_deviceIn(device
,&format
,0,0,&capsA
);
486 trace("waveInOpen(%s): WAVE_FORMAT_MULAW not supported\n",
489 format
.wFormatTag
=WAVE_FORMAT_ADPCM
;
491 format
.wBitsPerSample
=4;
492 format
.nSamplesPerSec
=22050;
493 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
494 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
496 rc
=waveInOpen(&win
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
497 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
498 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
499 "waveInOpen(%s): returned: %s\n",dev_name(device
),wave_in_error(rc
));
500 if (rc
==MMSYSERR_NOERROR
) {
502 wave_in_test_deviceIn(device
,&format
,0,0,&capsA
);
504 trace("waveInOpen(%s): WAVE_FORMAT_ADPCM not supported\n",
507 /* test if WAVEFORMATEXTENSIBLE supported */
508 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
509 wfex
.Format
.nChannels
=2;
510 wfex
.Format
.wBitsPerSample
=16;
511 wfex
.Format
.nSamplesPerSec
=22050;
512 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
513 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
514 wfex
.Format
.nBlockAlign
;
515 wfex
.Format
.cbSize
=22;
516 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
517 wfex
.dwChannelMask
=SPEAKER_ALL
;
518 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
519 rc
=waveInOpen(&win
,device
,&wfex
.Format
,0,0,
520 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
521 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
522 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
523 "waveInOpen(%s): returned: %s\n",dev_name(device
),wave_in_error(rc
));
524 if (rc
==MMSYSERR_NOERROR
) {
526 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
528 trace("waveInOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
531 /* test if 4 channels supported */
532 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
533 wfex
.Format
.nChannels
=4;
534 wfex
.Format
.wBitsPerSample
=16;
535 wfex
.Format
.nSamplesPerSec
=22050;
536 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
537 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
538 wfex
.Format
.nBlockAlign
;
539 wfex
.Format
.cbSize
=22;
540 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
541 wfex
.dwChannelMask
=SPEAKER_ALL
;
542 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
543 rc
=waveInOpen(&win
,device
,&wfex
.Format
,0,0,
544 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
545 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
546 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
547 "waveInOpen(%s): returned: %s\n",dev_name(device
),wave_in_error(rc
));
548 if (rc
==MMSYSERR_NOERROR
) {
550 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
552 trace("waveInOpen(%s): 4 channels not supported\n",
555 /* test if 6 channels supported */
556 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
557 wfex
.Format
.nChannels
=6;
558 wfex
.Format
.wBitsPerSample
=16;
559 wfex
.Format
.nSamplesPerSec
=22050;
560 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
561 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
562 wfex
.Format
.nBlockAlign
;
563 wfex
.Format
.cbSize
=22;
564 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
565 wfex
.dwChannelMask
=SPEAKER_ALL
;
566 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
567 rc
=waveInOpen(&win
,device
,&wfex
.Format
,0,0,
568 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
569 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
570 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
571 "waveInOpen(%s): returned: %s\n",dev_name(device
),wave_in_error(rc
));
572 if (rc
==MMSYSERR_NOERROR
) {
574 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
576 trace("waveInOpen(%s): 6 channels not supported\n",
581 /* FIXME: ALSA doesn't like this */
582 /* test if 24 bit samples supported */
583 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
584 wfex
.Format
.nChannels
=2;
585 wfex
.Format
.wBitsPerSample
=24;
586 wfex
.Format
.nSamplesPerSec
=22050;
587 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
588 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
589 wfex
.Format
.nBlockAlign
;
590 wfex
.Format
.cbSize
=22;
591 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
592 wfex
.dwChannelMask
=SPEAKER_ALL
;
593 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
594 rc
=waveInOpen(&win
,device
,&wfex
.Format
,0,0,
595 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
596 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
597 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
598 "waveInOpen(%s): returned: %s\n",dev_name(device
),wave_in_error(rc
));
599 if (rc
==MMSYSERR_NOERROR
) {
601 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
603 trace("waveInOpen(%s): 24 bit samples not supported\n",
607 /* test if 32 bit samples supported */
608 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
609 wfex
.Format
.nChannels
=2;
610 wfex
.Format
.wBitsPerSample
=32;
611 wfex
.Format
.nSamplesPerSec
=22050;
612 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
613 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
614 wfex
.Format
.nBlockAlign
;
615 wfex
.Format
.cbSize
=22;
616 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
617 wfex
.dwChannelMask
=SPEAKER_ALL
;
618 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
619 rc
=waveInOpen(&win
,device
,&wfex
.Format
,0,0,
620 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
621 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
622 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
623 "waveInOpen(%s): returned: %s\n",dev_name(device
),wave_in_error(rc
));
624 if (rc
==MMSYSERR_NOERROR
) {
626 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
628 trace("waveInOpen(%s): 32 bit samples not supported\n",
631 /* test if 32 bit float samples supported */
632 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
633 wfex
.Format
.nChannels
=2;
634 wfex
.Format
.wBitsPerSample
=32;
635 wfex
.Format
.nSamplesPerSec
=22050;
636 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
637 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
638 wfex
.Format
.nBlockAlign
;
639 wfex
.Format
.cbSize
=22;
640 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
641 wfex
.dwChannelMask
=SPEAKER_ALL
;
642 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
643 rc
=waveInOpen(&win
,device
,&wfex
.Format
,0,0,
644 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
645 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
646 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
647 "waveInOpen(%s): returned: %s\n",dev_name(device
),wave_in_error(rc
));
648 if (rc
==MMSYSERR_NOERROR
) {
650 wave_in_test_deviceIn(device
,&wfex
.Format
,0,0,&capsA
);
652 trace("waveInOpen(%s): 32 bit float samples not supported\n",
656 static void wave_in_tests(void)
665 ndev
=waveInGetNumDevs();
666 trace("found %d WaveIn devices\n",ndev
);
668 rc
=waveInGetDevCapsA(ndev
+1,&capsA
,sizeof(capsA
));
669 ok(rc
==MMSYSERR_BADDEVICEID
,
670 "waveInGetDevCapsA(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
671 dev_name(ndev
+1),wave_in_error(rc
));
673 rc
=waveInGetDevCapsA(WAVE_MAPPER
,&capsA
,sizeof(capsA
));
675 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NODRIVER
,
676 "waveInGetDevCapsA(%s): MMSYSERR_NOERROR or MMSYSERR_NODRIVER "
677 "expected, got %s\n",dev_name(WAVE_MAPPER
),wave_in_error(rc
));
679 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
,
680 "waveInGetDevCapsA(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
681 "expected, got %s\n",dev_name(WAVE_MAPPER
),wave_in_error(rc
));
683 rc
=waveInGetDevCapsW(ndev
+1,&capsW
,sizeof(capsW
));
684 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NOTSUPPORTED
,
685 "waveInGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
686 "expected, got %s\n",dev_name(ndev
+1),wave_in_error(rc
));
688 rc
=waveInGetDevCapsW(WAVE_MAPPER
,&capsW
,sizeof(capsW
));
690 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NODRIVER
||
691 rc
==MMSYSERR_NOTSUPPORTED
,
692 "waveInGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NODRIVER or "
693 "MMSYSERR_NOTSUPPORTED expected, got %s\n",
694 dev_name(ndev
+1),wave_in_error(rc
));
696 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
||
697 rc
==MMSYSERR_NOTSUPPORTED
,
698 "waveInGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER or"
699 "MMSYSERR_NOTSUPPORTED expected, got %s\n",
700 dev_name(ndev
+1),wave_in_error(rc
));
702 format
.wFormatTag
=WAVE_FORMAT_PCM
;
704 format
.wBitsPerSample
=16;
705 format
.nSamplesPerSec
=44100;
706 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
707 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
709 rc
=waveInOpen(&win
,ndev
+1,&format
,0,0,CALLBACK_NULL
);
710 ok(rc
==MMSYSERR_BADDEVICEID
,
711 "waveInOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
712 dev_name(ndev
+1),wave_in_error(rc
));
715 wave_in_test_device(d
);
718 wave_in_test_device(WAVE_MAPPER
);