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