2 * Test winmm sound playback 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/test.h"
33 #include "winmm_test.h"
36 * Note that in most of this test we may get MMSYSERR_BADDEVICEID errors
37 * at about any time if the user starts another application that uses the
38 * sound device. So we should not report these as test failures.
40 * This test can play a test tone. But this only makes sense if someone
41 * is going to carefully listen to it, and would only bother everyone else.
42 * So this is only done if the test is being run in interactive mode.
45 #define PI 3.14159265358979323846
46 static char* wave_generate_la(WAVEFORMATEX
* wfx
, double duration
, DWORD
* size
)
53 nb_samples
=(int)(duration
*wfx
->nSamplesPerSec
);
54 *size
=nb_samples
*wfx
->nBlockAlign
;
56 for (i
=0;i
<nb_samples
;i
++) {
57 double y
=sin(440.0*2*PI
*i
/wfx
->nSamplesPerSec
);
58 if (wfx
->wBitsPerSample
==8) {
59 unsigned char sample
=(unsigned char)((double)127.5*(y
+1.0));
61 if (wfx
->nChannels
==2)
64 signed short sample
=(signed short)((double)32767.5*y
-0.5);
68 if (wfx
->nChannels
==2) {
78 const char * dev_name(int device
)
81 if (device
== WAVE_MAPPER
)
83 sprintf(name
, "%d", device
);
87 const char* mmsys_error(MMRESULT error
)
89 #define ERR_TO_STR(dev) case dev: return #dev
90 static char unknown
[32];
92 ERR_TO_STR(MMSYSERR_NOERROR
);
93 ERR_TO_STR(MMSYSERR_ERROR
);
94 ERR_TO_STR(MMSYSERR_BADDEVICEID
);
95 ERR_TO_STR(MMSYSERR_NOTENABLED
);
96 ERR_TO_STR(MMSYSERR_ALLOCATED
);
97 ERR_TO_STR(MMSYSERR_INVALHANDLE
);
98 ERR_TO_STR(MMSYSERR_NODRIVER
);
99 ERR_TO_STR(MMSYSERR_NOMEM
);
100 ERR_TO_STR(MMSYSERR_NOTSUPPORTED
);
101 ERR_TO_STR(MMSYSERR_BADERRNUM
);
102 ERR_TO_STR(MMSYSERR_INVALFLAG
);
103 ERR_TO_STR(MMSYSERR_INVALPARAM
);
104 ERR_TO_STR(WAVERR_BADFORMAT
);
105 ERR_TO_STR(WAVERR_STILLPLAYING
);
106 ERR_TO_STR(WAVERR_UNPREPARED
);
107 ERR_TO_STR(WAVERR_SYNC
);
109 sprintf(unknown
, "Unknown(0x%08x)", error
);
114 static const char * wave_out_error(MMRESULT error
)
116 static char msg
[1024];
117 static char long_msg
[1100];
120 rc
= waveOutGetErrorText(error
, msg
, sizeof(msg
));
121 if (rc
!= MMSYSERR_NOERROR
)
122 sprintf(long_msg
, "waveOutGetErrorText(%x) failed with error %x", error
, rc
);
124 sprintf(long_msg
, "%s(%s)", mmsys_error(error
), msg
);
128 const char * wave_open_flags(DWORD flags
)
130 static char msg
[1024];
133 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_EVENT
) {
134 strcat(msg
, "CALLBACK_EVENT");
137 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_FUNCTION
) {
138 if (!first
) strcat(msg
, "|");
139 strcat(msg
, "CALLBACK_FUNCTION");
142 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_NULL
) {
143 if (!first
) strcat(msg
, "|");
144 strcat(msg
, "CALLBACK_NULL");
147 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_THREAD
) {
148 if (!first
) strcat(msg
, "|");
149 strcat(msg
, "CALLBACK_THREAD");
152 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_WINDOW
) {
153 if (!first
) strcat(msg
, "|");
154 strcat(msg
, "CALLBACK_WINDOW");
157 if ((flags
& WAVE_ALLOWSYNC
) == WAVE_ALLOWSYNC
) {
158 if (!first
) strcat(msg
, "|");
159 strcat(msg
, "WAVE_ALLOWSYNC");
162 if ((flags
& WAVE_FORMAT_DIRECT
) == WAVE_FORMAT_DIRECT
) {
163 if (!first
) strcat(msg
, "|");
164 strcat(msg
, "WAVE_FORMAT_DIRECT");
167 if ((flags
& WAVE_FORMAT_QUERY
) == WAVE_FORMAT_QUERY
) {
168 if (!first
) strcat(msg
, "|");
169 strcat(msg
, "WAVE_FORMAT_QUERY");
172 if ((flags
& WAVE_MAPPED
) == WAVE_MAPPED
) {
173 if (!first
) strcat(msg
, "|");
174 strcat(msg
, "WAVE_MAPPED");
180 static const char * wave_out_caps(DWORD dwSupport
)
182 #define ADD_FLAG(f) if (dwSupport & f) strcat(msg, " " #f)
183 static char msg
[256];
186 ADD_FLAG(WAVECAPS_PITCH
);
187 ADD_FLAG(WAVECAPS_PLAYBACKRATE
);
188 ADD_FLAG(WAVECAPS_VOLUME
);
189 ADD_FLAG(WAVECAPS_LRVOLUME
);
190 ADD_FLAG(WAVECAPS_SYNC
);
191 ADD_FLAG(WAVECAPS_SAMPLEACCURATE
);
193 return msg
[0] ? msg
+ 1 : "";
197 static const char * wave_time_format(UINT type
)
200 #define TIME_FORMAT(f) case f: return #f
202 TIME_FORMAT(TIME_MS
);
203 TIME_FORMAT(TIME_SAMPLES
);
204 TIME_FORMAT(TIME_BYTES
);
205 TIME_FORMAT(TIME_SMPTE
);
206 TIME_FORMAT(TIME_MIDI
);
207 TIME_FORMAT(TIME_TICKS
);
210 sprintf(msg
, "Unknown(0x%04x)", type
);
214 static void check_position(int device
, HWAVEOUT wout
, DWORD bytes
, LPWAVEFORMATEX pwfx
)
221 samples
=bytes
/(pwfx
->wBitsPerSample
/8*pwfx
->nChannels
);
222 duration
=((double)samples
)/pwfx
->nSamplesPerSec
;
224 mmtime
.wType
= TIME_BYTES
;
225 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
226 ok(rc
==MMSYSERR_NOERROR
,
227 "waveOutGetPosition: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
228 if (mmtime
.wType
== TIME_BYTES
)
229 ok(mmtime
.u
.cb
==bytes
,
230 "waveOutGetPosition returned %ld bytes, should be %ld\n",
233 trace("TIME_BYTES not supported, returned %s\n",wave_time_format(mmtime
.wType
));
235 mmtime
.wType
= TIME_SAMPLES
;
236 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
237 ok(rc
==MMSYSERR_NOERROR
,
238 "waveOutGetPosition: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
239 if (mmtime
.wType
== TIME_SAMPLES
)
240 ok(mmtime
.u
.sample
==samples
,
241 "waveOutGetPosition returned %ld samples, should be %ld\n",
242 mmtime
.u
.sample
, samples
);
244 trace("TIME_SAMPLES not supported, returned %s\n",wave_time_format(mmtime
.wType
));
246 mmtime
.wType
= TIME_MS
;
247 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
248 ok(rc
==MMSYSERR_NOERROR
,
249 "waveOutGetPosition: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
250 if (mmtime
.wType
== TIME_MS
)
251 ok(mmtime
.u
.ms
==floor(duration
*1000.0),
252 "waveOutGetPosition returned %ld ms, should be %ld\n",
253 mmtime
.u
.ms
, (long)floor(duration
*1000.0));
255 trace("TIME_MS not supported, returned %s\n",wave_time_format(mmtime
.wType
));
257 mmtime
.wType
= TIME_SMPTE
;
258 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
259 ok(rc
==MMSYSERR_NOERROR
,
260 "waveOutGetPosition: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
261 if (mmtime
.wType
== TIME_SMPTE
)
263 BYTE frames
=ceil(fmod(duration
*mmtime
.u
.smpte
.fps
, mmtime
.u
.smpte
.fps
));
264 ok(mmtime
.u
.smpte
.hour
==(BYTE
)(floor(duration
/(60*60))) &&
265 mmtime
.u
.smpte
.min
==(BYTE
)(fmod(floor(duration
/60), 60)) &&
266 mmtime
.u
.smpte
.sec
==(BYTE
)(fmod(duration
,60)) &&
267 mmtime
.u
.smpte
.frame
==frames
,
268 "waveOutGetPosition returned %d:%d:%d %d, should be %d:%d:%d %d\n",
269 mmtime
.u
.smpte
.hour
, mmtime
.u
.smpte
.min
, mmtime
.u
.smpte
.sec
, mmtime
.u
.smpte
.frame
,
270 (BYTE
)(floor(duration
/(60*60))),
271 (BYTE
)(fmod(floor(duration
/60), 60)),
272 (BYTE
)(fmod(duration
,60)),
276 trace("TIME_SMPTE not supported, returned %s\n",wave_time_format(mmtime
.wType
));
279 static void wave_out_test_deviceOut(int device
, double duration
, LPWAVEFORMATEX pwfx
, DWORD format
, DWORD flags
, LPWAVEOUTCAPS pcaps
)
286 WORD nChannels
= pwfx
->nChannels
;
287 WORD wBitsPerSample
= pwfx
->wBitsPerSample
;
288 DWORD nSamplesPerSec
= pwfx
->nSamplesPerSec
;
290 hevent
=CreateEvent(NULL
,FALSE
,FALSE
,NULL
);
291 ok(hevent
!=NULL
,"CreateEvent: error=%ld\n",GetLastError());
296 rc
=waveOutOpen(&wout
,device
,pwfx
,(DWORD
)hevent
,0,CALLBACK_EVENT
|flags
);
297 /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */
298 /* It is acceptable to fail on formats that are not specified to work */
299 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_BADDEVICEID
||
300 rc
==MMSYSERR_NOTENABLED
|| rc
==MMSYSERR_NODRIVER
|| rc
==MMSYSERR_ALLOCATED
||
301 ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
302 (flags
& WAVE_FORMAT_DIRECT
) && !(pcaps
->dwFormats
& format
)) ||
303 ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
304 (!(flags
& WAVE_FORMAT_DIRECT
) || (flags
& WAVE_MAPPED
)) && !(pcaps
->dwFormats
& format
)) ||
305 (rc
==MMSYSERR_INVALFLAG
&& (flags
& WAVE_FORMAT_DIRECT
)),
306 "waveOutOpen: device=%s format=%ldx%2dx%d flags=%lx(%s) rc=%s\n",dev_name(device
),
307 pwfx
->nSamplesPerSec
,pwfx
->wBitsPerSample
,pwfx
->nChannels
,CALLBACK_EVENT
|flags
,
308 wave_open_flags(CALLBACK_EVENT
|flags
),wave_out_error(rc
));
309 if ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
310 (flags
& WAVE_FORMAT_DIRECT
) && (pcaps
->dwFormats
& format
))
311 trace(" Reason: The device lists this format as supported in it's capabilities but opening it failed.\n");
312 if ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
313 !(pcaps
->dwFormats
& format
))
314 trace("waveOutOpen: device=%s format=%ldx%2dx%d %s rc=%s failed but format not supported so OK.\n",
315 dev_name(device
), pwfx
->nSamplesPerSec
,pwfx
->wBitsPerSample
,pwfx
->nChannels
,
316 flags
& WAVE_FORMAT_DIRECT
? "flags=WAVE_FORMAT_DIRECT" :
317 flags
& WAVE_MAPPED
? "flags=WAVE_MAPPED" : "", mmsys_error(rc
));
318 if (rc
!=MMSYSERR_NOERROR
) {
323 ok(pwfx
->nChannels
==nChannels
&&
324 pwfx
->wBitsPerSample
==wBitsPerSample
&&
325 pwfx
->nSamplesPerSec
==nSamplesPerSec
,
326 "got the wrong format: %ldx%2dx%d instead of %ldx%2dx%d\n",
327 pwfx
->nSamplesPerSec
, pwfx
->wBitsPerSample
,
328 pwfx
->nChannels
, nSamplesPerSec
, wBitsPerSample
, nChannels
);
330 frag
.lpData
=wave_generate_la(pwfx
,duration
,&frag
.dwBufferLength
);
334 rc
=waveOutGetVolume(wout
,&volume
);
335 ok(rc
==MMSYSERR_NOERROR
,"waveOutGetVolume: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
337 rc
=waveOutPrepareHeader(wout
, &frag
, sizeof(frag
));
338 ok(rc
==MMSYSERR_NOERROR
,
339 "waveOutPrepareHeader: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
341 if (winetest_interactive
&& rc
==MMSYSERR_NOERROR
) {
343 trace("Playing %g second 440Hz tone at %5ldx%2dx%d %s\n",duration
,
344 pwfx
->nSamplesPerSec
, pwfx
->wBitsPerSample
,pwfx
->nChannels
,
345 flags
& WAVE_FORMAT_DIRECT
? "WAVE_FORMAT_DIRECT" :
346 flags
& WAVE_MAPPED
? "WAVE_MAPPED" : "");
348 /* Check that the position is 0 at start */
349 check_position(device
, wout
, 0.0, pwfx
);
351 rc
=waveOutSetVolume(wout
,0x20002000);
352 ok(rc
==MMSYSERR_NOERROR
,"waveOutSetVolume: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
353 WaitForSingleObject(hevent
,INFINITE
);
355 start
=GetTickCount();
356 rc
=waveOutWrite(wout
, &frag
, sizeof(frag
));
357 ok(rc
==MMSYSERR_NOERROR
,"waveOutWrite: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
358 WaitForSingleObject(hevent
,INFINITE
);
360 /* Check the sound duration was within 10% of the expected value */
362 trace("sound duration=%ld\n",end
-start
);
363 ok(fabs(1000*duration
-end
+start
)<=100*duration
,"The sound played for %ld ms instead of %g ms\n",end
-start
,1000*duration
);
365 rc
=waveOutSetVolume(wout
,volume
);
366 ok(rc
==MMSYSERR_NOERROR
,"waveOutSetVolume: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
368 check_position(device
, wout
, frag
.dwBufferLength
, pwfx
);
371 rc
=waveOutUnprepareHeader(wout
, &frag
, sizeof(frag
));
372 ok(rc
==MMSYSERR_NOERROR
,
373 "waveOutUnprepareHeader: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
377 rc
=waveOutClose(wout
);
378 ok(rc
==MMSYSERR_NOERROR
,"waveOutClose: device=%s rc=%s\n",dev_name(device
),wave_out_error(rc
));
381 static void wave_out_test_device(int device
)
385 WAVEFORMATEX format
, oformat
;
394 SYSTEM_INFO sSysInfo
;
398 GetSystemInfo(&sSysInfo
);
399 dwPageSize
= sSysInfo
.dwPageSize
;
401 rc
=waveOutGetDevCapsA(device
,&capsA
,sizeof(capsA
));
402 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
,
403 "waveOutGetDevCapsA: failed to get capabilities of device %s: rc=%s\n",dev_name(device
),wave_out_error(rc
));
404 if (rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
)
407 rc
=waveOutGetDevCapsW(device
,&capsW
,sizeof(capsW
));
408 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
409 "waveOutGetDevCapsW: MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED expected, got %s\n",wave_out_error(rc
));
411 rc
=waveOutGetDevCapsA(device
,0,sizeof(capsA
));
412 ok(rc
==MMSYSERR_INVALPARAM
,
413 "waveOutGetDevCapsA: MMSYSERR_INVALPARAM expected, got %s\n",wave_out_error(rc
));
415 rc
=waveOutGetDevCapsW(device
,0,sizeof(capsW
));
416 ok(rc
==MMSYSERR_INVALPARAM
|| rc
==MMSYSERR_NOTSUPPORTED
,
417 "waveOutGetDevCapsW: MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED expected, got %s\n",wave_out_error(rc
));
419 #if 0 /* FIXME: this works on windows but crashes wine */
420 rc
=waveOutGetDevCapsA(device
,(LPWAVEOUTCAPSA
)1,sizeof(capsA
));
421 ok(rc
==MMSYSERR_INVALPARAM
,
422 "waveOutGetDevCapsA: MMSYSERR_INVALPARAM expected, got %s\n",wave_out_error(rc
));
424 rc
=waveOutGetDevCapsW(device
,(LPWAVEOUTCAPSW
)1,sizeof(capsW
));
425 ok(rc
==MMSYSERR_INVALPARAM
|| rc
==MMSYSERR_NOTSUPPORTED
,
426 "waveOutGetDevCapsW: MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED expected, got %s\n",wave_out_error(rc
));
429 rc
=waveOutGetDevCapsA(device
,&capsA
,4);
430 ok(rc
==MMSYSERR_NOERROR
,
431 "waveOutGetDevCapsA: MMSYSERR_NOERROR expected, got %s\n",wave_out_error(rc
));
433 rc
=waveOutGetDevCapsW(device
,&capsW
,4);
434 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
435 "waveOutGetDevCapsW: MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED expected, got %s\n",wave_out_error(rc
));
438 rc
=waveOutMessage((HWAVEOUT
)device
, DRV_QUERYDEVICEINTERFACESIZE
, (DWORD_PTR
)&size
, 0);
439 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_INVALPARAM
|| rc
==MMSYSERR_NOTSUPPORTED
,
440 "waveOutMessage: failed to get interface size for device: %s rc=%s\n",dev_name(device
),wave_out_error(rc
));
441 if (rc
==MMSYSERR_NOERROR
) {
442 nameW
= (WCHAR
*)malloc(size
);
443 rc
=waveOutMessage((HWAVEOUT
)device
, DRV_QUERYDEVICEINTERFACE
, (DWORD_PTR
)nameW
, size
);
444 ok(rc
==MMSYSERR_NOERROR
,"waveOutMessage: failed to get interface name for device: %s rc=%s\n",dev_name(device
),wave_out_error(rc
));
445 ok(lstrlenW(nameW
)+1==size
/sizeof(WCHAR
),"got an incorrect size: %ld instead of %d\n",size
,(lstrlenW(nameW
)+1)*sizeof(WCHAR
));
446 if (rc
==MMSYSERR_NOERROR
) {
447 nameA
= malloc(size
/sizeof(WCHAR
));
448 WideCharToMultiByte(CP_ACP
, 0, nameW
, size
/sizeof(WCHAR
), nameA
, size
/sizeof(WCHAR
), NULL
, NULL
);
452 else if (rc
==MMSYSERR_NOTSUPPORTED
) {
453 nameA
=strdup("not supported");
456 trace(" %s: \"%s\" (%s) %d.%d (%d:%d): channels=%d formats=%05lx support=%04lx(%s)\n",
457 dev_name(device
),capsA
.szPname
,(nameA
?nameA
:"failed"),capsA
.vDriverVersion
>> 8,
458 capsA
.vDriverVersion
& 0xff,
459 capsA
.wMid
,capsA
.wPid
,
460 capsA
.wChannels
,capsA
.dwFormats
,capsA
.dwSupport
,wave_out_caps(capsA
.dwSupport
));
463 if (winetest_interactive
&& (device
!= WAVE_MAPPER
))
465 trace("Playing a 5 seconds reference tone.\n");
466 trace("All subsequent tones should be identical to this one.\n");
467 trace("Listen for stutter, changes in pitch, volume, etc.\n");
468 format
.wFormatTag
=WAVE_FORMAT_PCM
;
470 format
.wBitsPerSample
=8;
471 format
.nSamplesPerSec
=22050;
472 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
473 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
475 wave_out_test_deviceOut(device
,5.0,&format
,WAVE_FORMAT_2M08
,0,&capsA
);
478 for (f
=0;f
<NB_WIN_FORMATS
;f
++) {
479 format
.wFormatTag
=WAVE_FORMAT_PCM
;
480 format
.nChannels
=win_formats
[f
][3];
481 format
.wBitsPerSample
=win_formats
[f
][2];
482 format
.nSamplesPerSec
=win_formats
[f
][1];
483 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
484 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
486 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],0,&capsA
);
487 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],WAVE_FORMAT_DIRECT
,&capsA
);
488 if (device
!= WAVE_MAPPER
)
489 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],WAVE_MAPPED
,&capsA
);
492 /* Try a PCMWAVEFORMAT aligned next to an unaccessable page for bounds checking */
493 twoPages
= VirtualAlloc(NULL
, 2 * dwPageSize
, MEM_RESERVE
| MEM_COMMIT
, PAGE_READWRITE
);
494 ok(twoPages
!=NULL
,"Failed to allocate 2 pages of memory\n");
496 res
= VirtualProtect(twoPages
+ dwPageSize
, dwPageSize
, PAGE_NOACCESS
, &flOldProtect
);
497 ok(res
, "Failed to set memory access on second page\n");
499 LPWAVEFORMATEX pwfx
= (LPWAVEFORMATEX
)(twoPages
+ dwPageSize
- sizeof(PCMWAVEFORMAT
));
500 pwfx
->wFormatTag
=WAVE_FORMAT_PCM
;
502 pwfx
->wBitsPerSample
=8;
503 pwfx
->nSamplesPerSec
=22050;
504 pwfx
->nBlockAlign
=pwfx
->nChannels
*pwfx
->wBitsPerSample
/8;
505 pwfx
->nAvgBytesPerSec
=pwfx
->nSamplesPerSec
*pwfx
->nBlockAlign
;
506 wave_out_test_deviceOut(device
,1.0,pwfx
,WAVE_FORMAT_2M08
,0,&capsA
);
507 wave_out_test_deviceOut(device
,1.0,pwfx
,WAVE_FORMAT_2M08
,WAVE_FORMAT_DIRECT
,&capsA
);
508 if (device
!= WAVE_MAPPER
)
509 wave_out_test_deviceOut(device
,1.0,pwfx
,WAVE_FORMAT_2M08
,WAVE_MAPPED
,&capsA
);
511 VirtualFree(twoPages
, 2 * dwPageSize
, MEM_RELEASE
);
514 /* Try invalid formats to test error handling */
515 trace("Testing invalid format: 11 bits per sample\n");
516 format
.wFormatTag
=WAVE_FORMAT_PCM
;
518 format
.wBitsPerSample
=11;
519 format
.nSamplesPerSec
=22050;
520 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
521 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
524 rc
=waveOutOpen(&wout
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
525 ok(rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
526 "waveOutOpen: opening the device in 11 bits mode should fail %s: rc=%s\n",dev_name(device
),wave_out_error(rc
));
527 if (rc
==MMSYSERR_NOERROR
) {
528 trace(" got %ldx%2dx%d for %ldx%2dx%d\n",
529 format
.nSamplesPerSec
, format
.wBitsPerSample
,
531 oformat
.nSamplesPerSec
, oformat
.wBitsPerSample
,
536 trace("Testing invalid format: 2 MHz sample rate\n");
537 format
.wFormatTag
=WAVE_FORMAT_PCM
;
539 format
.wBitsPerSample
=16;
540 format
.nSamplesPerSec
=2000000;
541 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
542 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
545 rc
=waveOutOpen(&wout
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
546 ok(rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
547 "waveOutOpen: opening the device at 2 MHz sample rate should fail %s: rc=%s\n",dev_name(device
),wave_out_error(rc
));
548 if (rc
==MMSYSERR_NOERROR
) {
549 trace(" got %ldx%2dx%d for %ldx%2dx%d\n",
550 format
.nSamplesPerSec
, format
.wBitsPerSample
,
552 oformat
.nSamplesPerSec
, oformat
.wBitsPerSample
,
558 static void wave_out_tests()
566 ndev
=waveOutGetNumDevs();
567 trace("found %d WaveOut devices\n",ndev
);
569 rc
=waveOutGetDevCapsA(ndev
+1,&caps
,sizeof(caps
));
570 ok(rc
==MMSYSERR_BADDEVICEID
,
571 "waveOutGetDevCapsA: MMSYSERR_BADDEVICEID expected, got %s\n",mmsys_error(rc
));
573 rc
=waveOutGetDevCapsA(WAVE_MAPPER
,&caps
,sizeof(caps
));
575 ok(rc
==MMSYSERR_NOERROR
,
576 "waveOutGetDevCapsA: MMSYSERR_NOERROR expected, got %s\n",mmsys_error(rc
));
578 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
,
579 "waveOutGetDevCapsA: MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER expected, got %s\n",mmsys_error(rc
));
581 format
.wFormatTag
=WAVE_FORMAT_PCM
;
583 format
.wBitsPerSample
=16;
584 format
.nSamplesPerSec
=44100;
585 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
586 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
588 rc
=waveOutOpen(&wout
,ndev
+1,&format
,0,0,CALLBACK_NULL
);
589 ok(rc
==MMSYSERR_BADDEVICEID
,
590 "waveOutOpen: MMSYSERR_BADDEVICEID expected, got %s\n",mmsys_error(rc
));
593 wave_out_test_device(d
);
596 wave_out_test_device(WAVE_MAPPER
);