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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
38 #include "winmm_test.h"
41 * Note that in most of this test we may get MMSYSERR_BADDEVICEID errors
42 * at about any time if the user starts another application that uses the
43 * sound device. So we should not report these as test failures.
45 * This test can play a test tone. But this only makes sense if someone
46 * is going to carefully listen to it, and would only bother everyone else.
47 * So this is only done if the test is being run in interactive mode.
50 #define PI 3.14159265358979323846
51 static char* wave_generate_la(WAVEFORMATEX
* wfx
, double duration
, DWORD
* size
)
57 WAVEFORMATEXTENSIBLE
*wfex
= (WAVEFORMATEXTENSIBLE
*)wfx
;
59 nb_samples
=(int)(duration
*wfx
->nSamplesPerSec
);
60 *size
=nb_samples
*wfx
->nBlockAlign
;
62 for (i
=0;i
<nb_samples
;i
++) {
63 double y
=sin(440.0*2*PI
*i
/wfx
->nSamplesPerSec
);
64 if (wfx
->wBitsPerSample
==8) {
65 unsigned char sample
=(unsigned char)((double)127.5*(y
+1.0));
66 for (j
= 0; j
< wfx
->nChannels
; j
++)
68 } else if (wfx
->wBitsPerSample
==16) {
69 signed short sample
=(signed short)((double)32767.5*y
-0.5);
70 for (j
= 0; j
< wfx
->nChannels
; j
++) {
75 } else if (wfx
->wBitsPerSample
==24) {
76 signed int sample
=(signed int)(((double)0x7fffff+0.5)*y
-0.5);
77 for (j
= 0; j
< wfx
->nChannels
; j
++) {
79 b
[1]=(sample
>> 8) & 0xff;
80 b
[2]=(sample
>> 16) & 0xff;
83 } else if ((wfx
->wBitsPerSample
==32) && ((wfx
->wFormatTag
== WAVE_FORMAT_PCM
) ||
84 ((wfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
) &&
85 IsEqualGUID(&wfex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
)))) {
86 signed int sample
=(signed int)(((double)0x7fffffff+0.5)*y
-0.5);
87 for (j
= 0; j
< wfx
->nChannels
; j
++) {
89 b
[1]=(sample
>> 8) & 0xff;
90 b
[2]=(sample
>> 16) & 0xff;
91 b
[3]=(sample
>> 24) & 0xff;
94 } else if ((wfx
->wBitsPerSample
==32) && (wfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
) &&
95 IsEqualGUID(&wfex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)) {
96 union { float f
; char c
[4]; } sample
;
98 for (j
= 0; j
< wfx
->nChannels
; j
++) {
110 static char* wave_generate_silence(WAVEFORMATEX
* wfx
, double duration
, DWORD
* size
)
116 WAVEFORMATEXTENSIBLE
*wfex
= (WAVEFORMATEXTENSIBLE
*)wfx
;
118 nb_samples
=(int)(duration
*wfx
->nSamplesPerSec
);
119 *size
=nb_samples
*wfx
->nBlockAlign
;
121 for (i
=0;i
<nb_samples
;i
++) {
122 if (wfx
->wBitsPerSample
==8) {
123 for (j
= 0; j
< wfx
->nChannels
; j
++)
125 } else if (wfx
->wBitsPerSample
==16) {
126 for (j
= 0; j
< wfx
->nChannels
; j
++) {
131 } else if (wfx
->wBitsPerSample
==24) {
132 for (j
= 0; j
< wfx
->nChannels
; j
++) {
138 } else if ((wfx
->wBitsPerSample
==32) && ((wfx
->wFormatTag
== WAVE_FORMAT_PCM
) ||
139 ((wfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
) &&
140 IsEqualGUID(&wfex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
)))) {
141 for (j
= 0; j
< wfx
->nChannels
; j
++) {
148 } else if ((wfx
->wBitsPerSample
==32) && (wfx
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
) &&
149 IsEqualGUID(&wfex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
)) {
150 union { float f
; char c
[4]; } sample
;
152 for (j
= 0; j
< wfx
->nChannels
; j
++) {
164 const char * dev_name(int device
)
166 static char name
[16];
167 if (device
== WAVE_MAPPER
)
168 return "WAVE_MAPPER";
169 sprintf(name
, "%d", device
);
173 const char* mmsys_error(MMRESULT error
)
175 #define ERR_TO_STR(dev) case dev: return #dev
176 static char unknown
[32];
178 ERR_TO_STR(MMSYSERR_NOERROR
);
179 ERR_TO_STR(MMSYSERR_ERROR
);
180 ERR_TO_STR(MMSYSERR_BADDEVICEID
);
181 ERR_TO_STR(MMSYSERR_NOTENABLED
);
182 ERR_TO_STR(MMSYSERR_ALLOCATED
);
183 ERR_TO_STR(MMSYSERR_INVALHANDLE
);
184 ERR_TO_STR(MMSYSERR_NODRIVER
);
185 ERR_TO_STR(MMSYSERR_NOMEM
);
186 ERR_TO_STR(MMSYSERR_NOTSUPPORTED
);
187 ERR_TO_STR(MMSYSERR_BADERRNUM
);
188 ERR_TO_STR(MMSYSERR_INVALFLAG
);
189 ERR_TO_STR(MMSYSERR_INVALPARAM
);
190 ERR_TO_STR(WAVERR_BADFORMAT
);
191 ERR_TO_STR(WAVERR_STILLPLAYING
);
192 ERR_TO_STR(WAVERR_UNPREPARED
);
193 ERR_TO_STR(WAVERR_SYNC
);
194 ERR_TO_STR(MIDIERR_UNPREPARED
);
195 ERR_TO_STR(MIDIERR_STILLPLAYING
);
196 ERR_TO_STR(MIDIERR_NOTREADY
);
197 ERR_TO_STR(MIDIERR_NODEVICE
);
198 ERR_TO_STR(MIDIERR_INVALIDSETUP
);
199 ERR_TO_STR(TIMERR_NOCANDO
);
200 ERR_TO_STR(TIMERR_STRUCT
);
201 ERR_TO_STR(JOYERR_PARMS
);
202 ERR_TO_STR(JOYERR_NOCANDO
);
203 ERR_TO_STR(JOYERR_UNPLUGGED
);
204 ERR_TO_STR(MIXERR_INVALLINE
);
205 ERR_TO_STR(MIXERR_INVALCONTROL
);
206 ERR_TO_STR(MIXERR_INVALVALUE
);
207 ERR_TO_STR(MMIOERR_FILENOTFOUND
);
208 ERR_TO_STR(MMIOERR_OUTOFMEMORY
);
209 ERR_TO_STR(MMIOERR_CANNOTOPEN
);
210 ERR_TO_STR(MMIOERR_CANNOTCLOSE
);
211 ERR_TO_STR(MMIOERR_CANNOTREAD
);
212 ERR_TO_STR(MMIOERR_CANNOTWRITE
);
213 ERR_TO_STR(MMIOERR_CANNOTSEEK
);
214 ERR_TO_STR(MMIOERR_CANNOTEXPAND
);
215 ERR_TO_STR(MMIOERR_CHUNKNOTFOUND
);
216 ERR_TO_STR(MMIOERR_UNBUFFERED
);
218 sprintf(unknown
, "Unknown(0x%08x)", error
);
223 const char* wave_out_error(MMRESULT error
)
225 static char msg
[1024];
226 static char long_msg
[1100];
229 rc
= waveOutGetErrorText(error
, msg
, sizeof(msg
));
230 if (rc
!= MMSYSERR_NOERROR
)
231 sprintf(long_msg
, "waveOutGetErrorText(%x) failed with error %x",
234 sprintf(long_msg
, "%s(%s)", mmsys_error(error
), msg
);
238 const char * wave_open_flags(DWORD flags
)
240 static char msg
[1024];
243 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_EVENT
) {
244 strcat(msg
, "CALLBACK_EVENT");
247 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_FUNCTION
) {
248 if (!first
) strcat(msg
, "|");
249 strcat(msg
, "CALLBACK_FUNCTION");
252 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_NULL
) {
253 if (!first
) strcat(msg
, "|");
254 strcat(msg
, "CALLBACK_NULL");
257 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_THREAD
) {
258 if (!first
) strcat(msg
, "|");
259 strcat(msg
, "CALLBACK_THREAD");
262 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_WINDOW
) {
263 if (!first
) strcat(msg
, "|");
264 strcat(msg
, "CALLBACK_WINDOW");
267 if ((flags
& WAVE_ALLOWSYNC
) == WAVE_ALLOWSYNC
) {
268 if (!first
) strcat(msg
, "|");
269 strcat(msg
, "WAVE_ALLOWSYNC");
272 if ((flags
& WAVE_FORMAT_DIRECT
) == WAVE_FORMAT_DIRECT
) {
273 if (!first
) strcat(msg
, "|");
274 strcat(msg
, "WAVE_FORMAT_DIRECT");
277 if ((flags
& WAVE_FORMAT_QUERY
) == WAVE_FORMAT_QUERY
) {
278 if (!first
) strcat(msg
, "|");
279 strcat(msg
, "WAVE_FORMAT_QUERY");
282 if ((flags
& WAVE_MAPPED
) == WAVE_MAPPED
) {
283 if (!first
) strcat(msg
, "|");
284 strcat(msg
, "WAVE_MAPPED");
290 const char * wave_header_flags(DWORD flags
)
292 #define WHDR_MASK (WHDR_BEGINLOOP|WHDR_DONE|WHDR_ENDLOOP|WHDR_INQUEUE|WHDR_PREPARED)
293 static char msg
[1024];
296 if (flags
& WHDR_BEGINLOOP
) {
297 strcat(msg
, "WHDR_BEGINLOOP");
300 if (flags
& WHDR_DONE
) {
301 if (!first
) strcat(msg
, " ");
302 strcat(msg
, "WHDR_DONE");
305 if (flags
& WHDR_ENDLOOP
) {
306 if (!first
) strcat(msg
, " ");
307 strcat(msg
, "WHDR_ENDLOOP");
310 if (flags
& WHDR_INQUEUE
) {
311 if (!first
) strcat(msg
, " ");
312 strcat(msg
, "WHDR_INQUEUE");
315 if (flags
& WHDR_PREPARED
) {
316 if (!first
) strcat(msg
, " ");
317 strcat(msg
, "WHDR_PREPARED");
320 if (flags
& ~WHDR_MASK
) {
322 sprintf(temp
, "UNKNOWN(0x%08lx)", flags
& ~WHDR_MASK
);
323 if (!first
) strcat(msg
, " ");
329 static const char * wave_out_caps(DWORD dwSupport
)
331 #define ADD_FLAG(f) if (dwSupport & f) strcat(msg, " " #f)
332 static char msg
[256];
335 ADD_FLAG(WAVECAPS_PITCH
);
336 ADD_FLAG(WAVECAPS_PLAYBACKRATE
);
337 ADD_FLAG(WAVECAPS_VOLUME
);
338 ADD_FLAG(WAVECAPS_LRVOLUME
);
339 ADD_FLAG(WAVECAPS_SYNC
);
340 ADD_FLAG(WAVECAPS_SAMPLEACCURATE
);
342 return msg
[0] ? msg
+ 1 : "";
346 const char * wave_time_format(UINT type
)
349 #define TIME_FORMAT(f) case f: return #f
351 TIME_FORMAT(TIME_MS
);
352 TIME_FORMAT(TIME_SAMPLES
);
353 TIME_FORMAT(TIME_BYTES
);
354 TIME_FORMAT(TIME_SMPTE
);
355 TIME_FORMAT(TIME_MIDI
);
356 TIME_FORMAT(TIME_TICKS
);
359 sprintf(msg
, "Unknown(0x%04x)", type
);
363 const char * get_format_str(WORD format
)
366 #define WAVE_FORMAT(f) case f: return #f
368 WAVE_FORMAT(WAVE_FORMAT_PCM
);
369 WAVE_FORMAT(WAVE_FORMAT_ADPCM
);
370 WAVE_FORMAT(WAVE_FORMAT_IBM_CVSD
);
371 WAVE_FORMAT(WAVE_FORMAT_ALAW
);
372 WAVE_FORMAT(WAVE_FORMAT_MULAW
);
373 WAVE_FORMAT(WAVE_FORMAT_OKI_ADPCM
);
374 WAVE_FORMAT(WAVE_FORMAT_IMA_ADPCM
);
375 WAVE_FORMAT(WAVE_FORMAT_MEDIASPACE_ADPCM
);
376 WAVE_FORMAT(WAVE_FORMAT_SIERRA_ADPCM
);
377 WAVE_FORMAT(WAVE_FORMAT_G723_ADPCM
);
378 WAVE_FORMAT(WAVE_FORMAT_DIGISTD
);
379 WAVE_FORMAT(WAVE_FORMAT_DIGIFIX
);
380 WAVE_FORMAT(WAVE_FORMAT_DIALOGIC_OKI_ADPCM
);
381 WAVE_FORMAT(WAVE_FORMAT_YAMAHA_ADPCM
);
382 WAVE_FORMAT(WAVE_FORMAT_SONARC
);
383 WAVE_FORMAT(WAVE_FORMAT_DSPGROUP_TRUESPEECH
);
384 WAVE_FORMAT(WAVE_FORMAT_ECHOSC1
);
385 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF36
);
386 WAVE_FORMAT(WAVE_FORMAT_APTX
);
387 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF10
);
388 WAVE_FORMAT(WAVE_FORMAT_DOLBY_AC2
);
389 WAVE_FORMAT(WAVE_FORMAT_GSM610
);
390 WAVE_FORMAT(WAVE_FORMAT_ANTEX_ADPCME
);
391 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_VQLPC
);
392 WAVE_FORMAT(WAVE_FORMAT_DIGIREAL
);
393 WAVE_FORMAT(WAVE_FORMAT_DIGIADPCM
);
394 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_CR10
);
395 WAVE_FORMAT(WAVE_FORMAT_NMS_VBXADPCM
);
396 WAVE_FORMAT(WAVE_FORMAT_G721_ADPCM
);
397 WAVE_FORMAT(WAVE_FORMAT_MPEG
);
398 WAVE_FORMAT(WAVE_FORMAT_MPEGLAYER3
);
399 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_ADPCM
);
400 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH8
);
401 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH10
);
402 WAVE_FORMAT(WAVE_FORMAT_FM_TOWNS_SND
);
403 WAVE_FORMAT(WAVE_FORMAT_OLIGSM
);
404 WAVE_FORMAT(WAVE_FORMAT_OLIADPCM
);
405 WAVE_FORMAT(WAVE_FORMAT_OLICELP
);
406 WAVE_FORMAT(WAVE_FORMAT_OLISBC
);
407 WAVE_FORMAT(WAVE_FORMAT_OLIOPR
);
408 WAVE_FORMAT(WAVE_FORMAT_DEVELOPMENT
);
409 WAVE_FORMAT(WAVE_FORMAT_EXTENSIBLE
);
412 sprintf(msg
, "Unknown(0x%04x)", format
);
416 DWORD
bytes_to_samples(DWORD bytes
, LPWAVEFORMATEX pwfx
)
418 return bytes
/ pwfx
->nBlockAlign
;
421 DWORD
bytes_to_ms(DWORD bytes
, LPWAVEFORMATEX pwfx
)
423 return bytes_to_samples(bytes
, pwfx
) * 1000 / pwfx
->nSamplesPerSec
;
426 DWORD
time_to_bytes(LPMMTIME mmtime
, LPWAVEFORMATEX pwfx
)
428 if (mmtime
->wType
== TIME_BYTES
)
430 else if (mmtime
->wType
== TIME_SAMPLES
)
431 return mmtime
->u
.sample
* pwfx
->nBlockAlign
;
432 else if (mmtime
->wType
== TIME_MS
)
433 return mmtime
->u
.ms
* pwfx
->nAvgBytesPerSec
/ 1000;
434 else if (mmtime
->wType
== TIME_SMPTE
)
435 return ((mmtime
->u
.smpte
.hour
* 60.0 * 60.0) +
436 (mmtime
->u
.smpte
.min
* 60.0) +
437 (mmtime
->u
.smpte
.sec
) +
438 (mmtime
->u
.smpte
.frame
/ 30.0)) * pwfx
->nAvgBytesPerSec
;
440 trace("FIXME: time_to_bytes() type not supported\n");
444 static void check_position(int device
, HWAVEOUT wout
, DWORD bytes
,
445 LPWAVEFORMATEX pwfx
)
453 samples
=bytes
/(pwfx
->wBitsPerSample
/8*pwfx
->nChannels
);
454 duration
=((double)samples
)/pwfx
->nSamplesPerSec
;
456 mmtime
.wType
= TIME_BYTES
;
457 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
458 ok(rc
==MMSYSERR_NOERROR
,
459 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
460 if (mmtime
.wType
!= TIME_BYTES
&& winetest_debug
> 1)
461 trace("waveOutGetPosition(%s): TIME_BYTES not supported, returned %s\n",
462 dev_name(device
),wave_time_format(mmtime
.wType
));
463 returned
= time_to_bytes(&mmtime
, pwfx
);
464 ok(returned
== bytes
, "waveOutGetPosition(%s): returned %ld bytes, "
465 "should be %ld\n", dev_name(device
), returned
, bytes
);
467 mmtime
.wType
= TIME_SAMPLES
;
468 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
469 ok(rc
==MMSYSERR_NOERROR
,
470 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
471 if (mmtime
.wType
!= TIME_SAMPLES
&& winetest_debug
> 1)
472 trace("waveOutGetPosition(%s): TIME_SAMPLES not supported, "
473 "returned %s\n",dev_name(device
),wave_time_format(mmtime
.wType
));
474 returned
= time_to_bytes(&mmtime
, pwfx
);
475 ok(returned
== bytes
, "waveOutGetPosition(%s): returned %ld samples "
476 "(%ld bytes), should be %ld (%ld bytes)\n", dev_name(device
),
477 bytes_to_samples(returned
, pwfx
), returned
,
478 bytes_to_samples(bytes
, pwfx
), bytes
);
480 mmtime
.wType
= TIME_MS
;
481 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
482 ok(rc
==MMSYSERR_NOERROR
,
483 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
484 if (mmtime
.wType
!= TIME_MS
&& winetest_debug
> 1)
485 trace("waveOutGetPosition(%s): TIME_MS not supported, returned %s\n",
486 dev_name(device
), wave_time_format(mmtime
.wType
));
487 returned
= time_to_bytes(&mmtime
, pwfx
);
488 ok(returned
== bytes
, "waveOutGetPosition(%s): returned %ld ms, "
489 "should be %ld\n", dev_name(device
), bytes_to_ms(returned
, pwfx
),
490 bytes_to_ms(bytes
, pwfx
));
492 mmtime
.wType
= TIME_SMPTE
;
493 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
494 ok(rc
==MMSYSERR_NOERROR
,
495 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
496 if (mmtime
.wType
!= TIME_SMPTE
&& winetest_debug
> 1)
497 trace("waveOutGetPosition(%s): TIME_SMPTE not supported, returned %s\n",
498 dev_name(device
),wave_time_format(mmtime
.wType
));
499 returned
= time_to_bytes(&mmtime
, pwfx
);
500 ok(returned
== bytes
, "waveOutGetPosition(%s): SMPTE test failed\n",
503 mmtime
.wType
= TIME_MIDI
;
504 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
505 ok(rc
==MMSYSERR_NOERROR
,
506 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
507 if (mmtime
.wType
!= TIME_MIDI
&& winetest_debug
> 1)
508 trace("waveOutGetPosition(%s): TIME_MIDI not supported, returned %s\n",
509 dev_name(device
),wave_time_format(mmtime
.wType
));
510 returned
= time_to_bytes(&mmtime
, pwfx
);
511 ok(returned
== bytes
, "waveOutGetPosition(%s): MIDI test failed\n",
514 mmtime
.wType
= TIME_TICKS
;
515 rc
=waveOutGetPosition(wout
, &mmtime
, sizeof(mmtime
));
516 ok(rc
==MMSYSERR_NOERROR
,
517 "waveOutGetPosition(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
518 if (mmtime
.wType
!= TIME_TICKS
&& winetest_debug
> 1)
519 trace("waveOutGetPosition(%s): TIME_TICKS not supported, returned %s\n",
520 dev_name(device
),wave_time_format(mmtime
.wType
));
521 returned
= time_to_bytes(&mmtime
, pwfx
);
522 ok(returned
== bytes
, "waveOutGetPosition(%s): TICKS test failed\n",
526 static void CALLBACK
callback_func(HWAVEOUT hwo
, UINT uMsg
,
527 DWORD_PTR dwInstance
,
528 DWORD dwParam1
, DWORD dwParam2
)
530 SetEvent((HANDLE
)dwInstance
);
533 static DWORD WINAPI
callback_thread(LPVOID lpParameter
)
537 while (GetMessage(&msg
, 0, 0, 0)) {
538 UINT message
= msg
.message
;
539 ok (message
== WOM_OPEN
|| message
== WOM_DONE
|| message
== WOM_CLOSE
,
540 "GetMessage returned unexpected message: %u\n", message
);
541 if (message
== WOM_OPEN
|| message
== WOM_DONE
|| message
== WOM_CLOSE
)
542 SetEvent((HANDLE
)lpParameter
);
548 static void wave_out_test_deviceOut(int device
, double duration
,
549 LPWAVEFORMATEX pwfx
, DWORD format
,
550 DWORD flags
, LPWAVEOUTCAPS pcaps
,
551 BOOL interactive
, BOOL sine
, BOOL pause
)
558 WORD nChannels
= pwfx
->nChannels
;
559 WORD wBitsPerSample
= pwfx
->wBitsPerSample
;
560 DWORD nSamplesPerSec
= pwfx
->nSamplesPerSec
;
561 BOOL has_volume
= pcaps
->dwSupport
& WAVECAPS_VOLUME
? TRUE
: FALSE
;
565 DWORD callback_instance
= 0;
568 hevent
=CreateEvent(NULL
,FALSE
,FALSE
,NULL
);
569 ok(hevent
!=NULL
,"CreateEvent(): error=%ld\n",GetLastError());
573 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_EVENT
) {
574 callback
= (DWORD
)hevent
;
575 callback_instance
= 0;
576 } else if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_FUNCTION
) {
577 callback
= (DWORD
)callback_func
;
578 callback_instance
= (DWORD
)hevent
;
579 } else if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_THREAD
) {
581 thread
= CreateThread(NULL
, 0, callback_thread
, hevent
, 0, &thread_id
);
583 callback
= thread_id
;
584 callback_instance
= 0;
586 trace("CreateThread() failed\n");
590 } else if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_WINDOW
) {
591 trace("CALLBACK_THREAD not implemented\n");
594 } else if (flags
&& CALLBACK_TYPEMASK
) {
595 trace("Undefined callback type!\n");
599 trace("CALLBACK_NULL not implemented\n");
604 rc
=waveOutOpen(&wout
,device
,pwfx
,callback
,callback_instance
,flags
);
605 /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */
606 /* It is acceptable to fail on formats that are not specified to work */
607 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_BADDEVICEID
||
608 rc
==MMSYSERR_NOTENABLED
|| rc
==MMSYSERR_NODRIVER
||
609 rc
==MMSYSERR_ALLOCATED
||
610 ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
611 (flags
& WAVE_FORMAT_DIRECT
) && !(pcaps
->dwFormats
& format
)) ||
612 ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
613 (!(flags
& WAVE_FORMAT_DIRECT
) || (flags
& WAVE_MAPPED
)) &&
614 !(pcaps
->dwFormats
& format
)) ||
615 (rc
==MMSYSERR_INVALFLAG
&& (flags
& WAVE_FORMAT_DIRECT
)),
616 "waveOutOpen(%s): format=%ldx%2dx%d flags=%lx(%s) rc=%s\n",
617 dev_name(device
),pwfx
->nSamplesPerSec
,pwfx
->wBitsPerSample
,
618 pwfx
->nChannels
,CALLBACK_EVENT
|flags
,
619 wave_open_flags(CALLBACK_EVENT
|flags
),wave_out_error(rc
));
620 if ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
621 (flags
& WAVE_FORMAT_DIRECT
) && (pcaps
->dwFormats
& format
))
622 trace(" Reason: The device lists this format as supported in it's "
623 "capabilities but opening it failed.\n");
624 if ((rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_NOTSUPPORTED
) &&
625 !(pcaps
->dwFormats
& format
))
626 trace("waveOutOpen(%s): format=%ldx%2dx%d %s rc=%s failed but format "
627 "not supported so OK.\n", dev_name(device
), pwfx
->nSamplesPerSec
,
628 pwfx
->wBitsPerSample
,pwfx
->nChannels
,
629 flags
& WAVE_FORMAT_DIRECT
? "flags=WAVE_FORMAT_DIRECT" :
630 flags
& WAVE_MAPPED
? "flags=WAVE_MAPPED" : "", mmsys_error(rc
));
631 if (rc
!=MMSYSERR_NOERROR
) {
632 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_THREAD
)
633 TerminateThread(thread
, 0);
638 ok(pwfx
->nChannels
==nChannels
&&
639 pwfx
->wBitsPerSample
==wBitsPerSample
&&
640 pwfx
->nSamplesPerSec
==nSamplesPerSec
,
641 "got the wrong format: %ldx%2dx%d instead of %ldx%2dx%d\n",
642 pwfx
->nSamplesPerSec
, pwfx
->wBitsPerSample
,
643 pwfx
->nChannels
, nSamplesPerSec
, wBitsPerSample
, nChannels
);
646 frag
.lpData
=wave_generate_la(pwfx
,duration
,&frag
.dwBufferLength
);
648 frag
.lpData
=wave_generate_silence(pwfx
,duration
,&frag
.dwBufferLength
);
653 rc
=waveOutGetVolume(wout
,0);
654 ok(rc
==MMSYSERR_INVALPARAM
,"waveOutGetVolume(%s,0) expected "
655 "MMSYSERR_INVALPARAM, got %s\n", dev_name(device
),wave_out_error(rc
));
656 rc
=waveOutGetVolume(wout
,&volume
);
657 ok(has_volume
? rc
==MMSYSERR_NOERROR
: rc
==MMSYSERR_NOTSUPPORTED
,
658 "waveOutGetVolume(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
660 rc
=waveOutPrepareHeader(wout
, &frag
, sizeof(frag
));
661 ok(rc
==MMSYSERR_NOERROR
,
662 "waveOutPrepareHeader(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
664 if (interactive
&& rc
==MMSYSERR_NOERROR
) {
666 trace("Playing %g second %s at %5ldx%2dx%d %s %s\n",duration
,
667 sine
? "440Hz tone" : "silence",pwfx
->nSamplesPerSec
,
668 pwfx
->wBitsPerSample
,pwfx
->nChannels
,
669 get_format_str(pwfx
->wFormatTag
),
670 wave_open_flags(flags
));
671 if (sine
&& has_volume
&& volume
== 0)
672 trace("*** Warning the sound is muted, you will not hear the test\n");
674 /* Check that the position is 0 at start */
675 check_position(device
, wout
, 0, pwfx
);
677 rc
=waveOutSetVolume(wout
,0x20002000);
678 ok(has_volume
? rc
==MMSYSERR_NOERROR
: rc
==MMSYSERR_NOTSUPPORTED
,
679 "waveOutSetVolume(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
680 WaitForSingleObject(hevent
,INFINITE
);
682 rc
=waveOutSetVolume(wout
,volume
);
683 ok(has_volume
? rc
==MMSYSERR_NOERROR
: rc
==MMSYSERR_NOTSUPPORTED
,
684 "waveOutSetVolume(%s): rc=%s\n",dev_name(device
),wave_out_error(rc
));
686 start
=GetTickCount();
687 rc
=waveOutWrite(wout
, &frag
, sizeof(frag
));
688 ok(rc
==MMSYSERR_NOERROR
,"waveOutWrite(%s): rc=%s\n",
689 dev_name(device
),wave_out_error(rc
));
691 ok(frag
.dwFlags
==(WHDR_PREPARED
|WHDR_INQUEUE
),
692 "WHDR_INQUEUE WHDR_PREPARED expected, got= %s\n",
693 wave_header_flags(frag
.dwFlags
));
695 rc
=waveOutWrite(wout
, &frag
, sizeof(frag
));
696 ok(rc
==WAVERR_STILLPLAYING
,
697 "waveOutWrite(%s): WAVE_STILLPLAYING expected, got %s\n",
698 dev_name(device
),wave_out_error(rc
));
700 ok(frag
.dwFlags
==(WHDR_PREPARED
|WHDR_INQUEUE
),
701 "WHDR_INQUEUE WHDR_PREPARED expected, got %s\n",
702 wave_header_flags(frag
.dwFlags
));
705 paused
= duration
/ 2;
706 Sleep(paused
* 1000);
707 rc
=waveOutPause(wout
);
708 ok(rc
==MMSYSERR_NOERROR
,"waveOutPause(%s): rc=%s\n",
709 dev_name(device
),wave_out_error(rc
));
710 trace("pausing for %g seconds\n", paused
);
711 Sleep(paused
* 1000);
712 rc
=waveOutRestart(wout
);
713 ok(rc
==MMSYSERR_NOERROR
,"waveOutRestart(%s): rc=%s\n",
714 dev_name(device
),wave_out_error(rc
));
717 WaitForSingleObject(hevent
,INFINITE
);
719 /* Check the sound duration was between -2% and +10% of the expected value */
721 actual
= (end
- start
) / 1000.0;
722 if (winetest_debug
> 1)
723 trace("sound duration=%g ms\n",1000*actual
);
724 ok((actual
> (0.98 * (duration
+paused
))) &&
725 (actual
< (1.1 * (duration
+paused
))),
726 "The sound played for %g ms instead of %g ms\n",
727 1000*actual
,1000*(duration
+paused
));
728 ok(frag
.dwFlags
=(WHDR_DONE
|WHDR_PREPARED
),
729 "WHDR_DONE WHDR_PREPARED expected, got %s\n",
730 wave_header_flags(frag
.dwFlags
));
731 check_position(device
, wout
, frag
.dwBufferLength
, pwfx
);
734 rc
=waveOutUnprepareHeader(wout
, &frag
, sizeof(frag
));
735 ok(rc
==MMSYSERR_NOERROR
,
736 "waveOutUnprepareHeader(%s): rc=%s\n",dev_name(device
),
740 rc
=waveOutClose(wout
);
741 ok(rc
==MMSYSERR_NOERROR
,"waveOutClose(%s): rc=%s\n",dev_name(device
),
743 if ((flags
& CALLBACK_TYPEMASK
) == CALLBACK_THREAD
)
744 TerminateThread(thread
, 0);
748 static void wave_out_test_device(int device
)
752 WAVEFORMATEX format
, oformat
;
753 WAVEFORMATEXTENSIBLE wfex
;
762 SYSTEM_INFO sSysInfo
;
766 GetSystemInfo(&sSysInfo
);
767 dwPageSize
= sSysInfo
.dwPageSize
;
769 rc
=waveOutGetDevCapsA(device
,&capsA
,sizeof(capsA
));
770 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_BADDEVICEID
||
771 rc
==MMSYSERR_NODRIVER
,
772 "waveOutGetDevCapsA(%s): failed to get capabilities: rc=%s\n",
773 dev_name(device
),wave_out_error(rc
));
774 if (rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
)
777 rc
=waveOutGetDevCapsW(device
,&capsW
,sizeof(capsW
));
778 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
779 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
780 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
782 rc
=waveOutGetDevCapsA(device
,0,sizeof(capsA
));
783 ok(rc
==MMSYSERR_INVALPARAM
,
784 "waveOutGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, "
785 "got %s\n",dev_name(device
),wave_out_error(rc
));
787 rc
=waveOutGetDevCapsW(device
,0,sizeof(capsW
));
788 ok(rc
==MMSYSERR_INVALPARAM
|| rc
==MMSYSERR_NOTSUPPORTED
,
789 "waveOutGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
790 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
792 #if 0 /* FIXME: this works on windows but crashes wine */
793 rc
=waveOutGetDevCapsA(device
,(LPWAVEOUTCAPSA
)1,sizeof(capsA
));
794 ok(rc
==MMSYSERR_INVALPARAM
,
795 "waveOutGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
796 dev_name(device
),wave_out_error(rc
));
798 rc
=waveOutGetDevCapsW(device
,(LPWAVEOUTCAPSW
)1,sizeof(capsW
));
799 ok(rc
==MMSYSERR_INVALPARAM
|| rc
==MMSYSERR_NOTSUPPORTED
,
800 "waveOutGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
801 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
804 rc
=waveOutGetDevCapsA(device
,&capsA
,4);
805 ok(rc
==MMSYSERR_NOERROR
,
806 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
807 dev_name(device
),wave_out_error(rc
));
809 rc
=waveOutGetDevCapsW(device
,&capsW
,4);
810 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
811 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
812 "expected, got %s\n",dev_name(device
),wave_out_error(rc
));
815 rc
=waveOutMessage((HWAVEOUT
)device
, DRV_QUERYDEVICEINTERFACESIZE
,
816 (DWORD_PTR
)&size
, 0);
817 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_INVALPARAM
||
818 rc
==MMSYSERR_NOTSUPPORTED
,
819 "waveOutMessage(%s): failed to get interface size, rc=%s\n",
820 dev_name(device
),wave_out_error(rc
));
821 if (rc
==MMSYSERR_NOERROR
) {
822 nameW
= (WCHAR
*)malloc(size
);
823 rc
=waveOutMessage((HWAVEOUT
)device
, DRV_QUERYDEVICEINTERFACE
,
824 (DWORD_PTR
)nameW
, size
);
825 ok(rc
==MMSYSERR_NOERROR
,"waveOutMessage(%s): failed to get interface "
826 "name, rc=%s\n",dev_name(device
),wave_out_error(rc
));
827 ok(lstrlenW(nameW
)+1==size
/sizeof(WCHAR
),"got an incorrect size: "
828 "%ld instead of %d\n",size
,(lstrlenW(nameW
)+1)*sizeof(WCHAR
));
829 if (rc
==MMSYSERR_NOERROR
) {
830 nameA
= malloc(size
/sizeof(WCHAR
));
831 WideCharToMultiByte(CP_ACP
, 0, nameW
, size
/sizeof(WCHAR
), nameA
,
832 size
/sizeof(WCHAR
), NULL
, NULL
);
836 else if (rc
==MMSYSERR_NOTSUPPORTED
) {
837 nameA
=strdup("not supported");
840 trace(" %s: \"%s\" (%s) %d.%d (%d:%d)\n",dev_name(device
),capsA
.szPname
,
841 (nameA
?nameA
:"failed"),capsA
.vDriverVersion
>> 8,
842 capsA
.vDriverVersion
& 0xff, capsA
.wMid
,capsA
.wPid
);
843 trace(" channels=%d formats=%05lx support=%04lx\n",
844 capsA
.wChannels
,capsA
.dwFormats
,capsA
.dwSupport
);
845 trace(" %s\n",wave_out_caps(capsA
.dwSupport
));
848 if (winetest_interactive
&& (device
!= WAVE_MAPPER
))
850 trace("Playing a 5 seconds reference tone.\n");
851 trace("All subsequent tones should be identical to this one.\n");
852 trace("Listen for stutter, changes in pitch, volume, etc.\n");
853 format
.wFormatTag
=WAVE_FORMAT_PCM
;
855 format
.wBitsPerSample
=8;
856 format
.nSamplesPerSec
=22050;
857 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
858 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
860 wave_out_test_deviceOut(device
,5.0,&format
,WAVE_FORMAT_2M08
,
861 CALLBACK_EVENT
,&capsA
,TRUE
,TRUE
,FALSE
);
862 wave_out_test_deviceOut(device
,5.0,&format
,WAVE_FORMAT_2M08
,
863 CALLBACK_FUNCTION
,&capsA
,TRUE
,TRUE
,FALSE
);
864 wave_out_test_deviceOut(device
,5.0,&format
,WAVE_FORMAT_2M08
,
865 CALLBACK_THREAD
,&capsA
,TRUE
,TRUE
,FALSE
);
867 format
.wFormatTag
=WAVE_FORMAT_PCM
;
869 format
.wBitsPerSample
=8;
870 format
.nSamplesPerSec
=22050;
871 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
872 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
874 wave_out_test_deviceOut(device
,1.0,&format
,WAVE_FORMAT_2M08
,
875 CALLBACK_EVENT
,&capsA
,TRUE
,FALSE
,FALSE
);
876 wave_out_test_deviceOut(device
,1.0,&format
,WAVE_FORMAT_2M08
,
877 CALLBACK_EVENT
,&capsA
,TRUE
,FALSE
,TRUE
);
878 wave_out_test_deviceOut(device
,1.0,&format
,WAVE_FORMAT_2M08
,
879 CALLBACK_FUNCTION
,&capsA
,TRUE
,FALSE
,FALSE
);
880 wave_out_test_deviceOut(device
,1.0,&format
,WAVE_FORMAT_2M08
,
881 CALLBACK_FUNCTION
,&capsA
,TRUE
,FALSE
,TRUE
);
882 wave_out_test_deviceOut(device
,1.0,&format
,WAVE_FORMAT_2M08
,
883 CALLBACK_THREAD
,&capsA
,TRUE
,FALSE
,FALSE
);
884 wave_out_test_deviceOut(device
,1.0,&format
,WAVE_FORMAT_2M08
,
885 CALLBACK_THREAD
,&capsA
,TRUE
,FALSE
,TRUE
);
888 for (f
=0;f
<NB_WIN_FORMATS
;f
++) {
889 format
.wFormatTag
=WAVE_FORMAT_PCM
;
890 format
.nChannels
=win_formats
[f
][3];
891 format
.wBitsPerSample
=win_formats
[f
][2];
892 format
.nSamplesPerSec
=win_formats
[f
][1];
893 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
894 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
896 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
897 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
899 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
900 CALLBACK_FUNCTION
,&capsA
,winetest_interactive
,
902 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
903 CALLBACK_THREAD
,&capsA
,winetest_interactive
,
905 if (winetest_interactive
) {
906 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
907 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
909 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
910 CALLBACK_FUNCTION
,&capsA
,winetest_interactive
,
912 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
913 CALLBACK_THREAD
,&capsA
,winetest_interactive
,
916 if (device
!= WAVE_MAPPER
)
918 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
919 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,&capsA
,
920 winetest_interactive
,TRUE
,FALSE
);
921 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
922 CALLBACK_EVENT
|WAVE_MAPPED
,&capsA
,
923 winetest_interactive
,TRUE
,FALSE
);
924 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
925 CALLBACK_FUNCTION
|WAVE_FORMAT_DIRECT
,&capsA
,
926 winetest_interactive
,TRUE
,FALSE
);
927 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
928 CALLBACK_FUNCTION
|WAVE_MAPPED
,&capsA
,
929 winetest_interactive
,TRUE
,FALSE
);
930 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
931 CALLBACK_THREAD
|WAVE_FORMAT_DIRECT
,&capsA
,
932 winetest_interactive
,TRUE
,FALSE
);
933 wave_out_test_deviceOut(device
,1.0,&format
,win_formats
[f
][0],
934 CALLBACK_THREAD
|WAVE_MAPPED
,&capsA
,
935 winetest_interactive
,TRUE
,FALSE
);
939 /* Try a PCMWAVEFORMAT aligned next to an unaccessible page for bounds
941 twoPages
= VirtualAlloc(NULL
, 2 * dwPageSize
, MEM_RESERVE
| MEM_COMMIT
,
943 ok(twoPages
!=NULL
,"Failed to allocate 2 pages of memory\n");
945 res
= VirtualProtect(twoPages
+ dwPageSize
, dwPageSize
, PAGE_NOACCESS
,
947 ok(res
, "Failed to set memory access on second page\n");
949 LPWAVEFORMATEX pwfx
= (LPWAVEFORMATEX
)(twoPages
+ dwPageSize
-
950 sizeof(PCMWAVEFORMAT
));
951 pwfx
->wFormatTag
=WAVE_FORMAT_PCM
;
953 pwfx
->wBitsPerSample
=8;
954 pwfx
->nSamplesPerSec
=22050;
955 pwfx
->nBlockAlign
=pwfx
->nChannels
*pwfx
->wBitsPerSample
/8;
956 pwfx
->nAvgBytesPerSec
=pwfx
->nSamplesPerSec
*pwfx
->nBlockAlign
;
957 wave_out_test_deviceOut(device
,1.0,pwfx
,WAVE_FORMAT_2M08
,
958 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
960 if (device
!= WAVE_MAPPER
)
962 wave_out_test_deviceOut(device
,1.0,pwfx
,WAVE_FORMAT_2M08
,
963 CALLBACK_EVENT
|WAVE_FORMAT_DIRECT
,
964 &capsA
,winetest_interactive
,TRUE
,FALSE
);
965 wave_out_test_deviceOut(device
,1.0,pwfx
,WAVE_FORMAT_2M08
,
966 CALLBACK_EVENT
|WAVE_MAPPED
,&capsA
,
967 winetest_interactive
,TRUE
,FALSE
);
970 VirtualFree(twoPages
, 0, MEM_RELEASE
);
973 /* Testing invalid format: 11 bits per sample */
974 format
.wFormatTag
=WAVE_FORMAT_PCM
;
976 format
.wBitsPerSample
=11;
977 format
.nSamplesPerSec
=22050;
978 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
979 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
982 rc
=waveOutOpen(&wout
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
983 ok(rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_INVALFLAG
||
984 rc
==MMSYSERR_INVALPARAM
,
985 "waveOutOpen(%s): opening the device in 11 bits mode should fail: "
986 "rc=%s\n",dev_name(device
),wave_out_error(rc
));
987 if (rc
==MMSYSERR_NOERROR
) {
988 trace(" got %ldx%2dx%d for %ldx%2dx%d\n",
989 format
.nSamplesPerSec
, format
.wBitsPerSample
,
991 oformat
.nSamplesPerSec
, oformat
.wBitsPerSample
,
996 /* Testing invalid format: 2 MHz sample rate */
997 format
.wFormatTag
=WAVE_FORMAT_PCM
;
999 format
.wBitsPerSample
=16;
1000 format
.nSamplesPerSec
=2000000;
1001 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1002 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1005 rc
=waveOutOpen(&wout
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1006 ok(rc
==WAVERR_BADFORMAT
|| rc
==MMSYSERR_INVALFLAG
||
1007 rc
==MMSYSERR_INVALPARAM
,
1008 "waveOutOpen(%s): opening the device at 2 MHz sample rate should fail: "
1009 "rc=%s\n",dev_name(device
),wave_out_error(rc
));
1010 if (rc
==MMSYSERR_NOERROR
) {
1011 trace(" got %ldx%2dx%d for %ldx%2dx%d\n",
1012 format
.nSamplesPerSec
, format
.wBitsPerSample
,
1014 oformat
.nSamplesPerSec
, oformat
.wBitsPerSample
,
1019 /* try some non PCM formats */
1020 format
.wFormatTag
=WAVE_FORMAT_MULAW
;
1022 format
.wBitsPerSample
=8;
1023 format
.nSamplesPerSec
=8000;
1024 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1025 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1028 rc
=waveOutOpen(&wout
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1029 ok(rc
==MMSYSERR_NOERROR
||rc
==WAVERR_BADFORMAT
||
1030 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1031 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1032 if (rc
==MMSYSERR_NOERROR
) {
1034 wave_out_test_deviceOut(device
,1.0,&format
,0,CALLBACK_EVENT
,
1035 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1037 trace("waveOutOpen(%s): WAVE_FORMAT_MULAW not supported\n",
1040 format
.wFormatTag
=WAVE_FORMAT_ADPCM
;
1042 format
.wBitsPerSample
=4;
1043 format
.nSamplesPerSec
=22050;
1044 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1045 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1048 rc
=waveOutOpen(&wout
,device
,&format
,0,0,CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1049 ok(rc
==MMSYSERR_NOERROR
||rc
==WAVERR_BADFORMAT
||
1050 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1051 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1052 if (rc
==MMSYSERR_NOERROR
) {
1054 wave_out_test_deviceOut(device
,1.0,&format
,0,CALLBACK_EVENT
,
1055 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1057 trace("waveOutOpen(%s): WAVE_FORMAT_ADPCM not supported\n",
1060 /* test if WAVEFORMATEXTENSIBLE supported */
1061 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1062 wfex
.Format
.nChannels
=2;
1063 wfex
.Format
.wBitsPerSample
=16;
1064 wfex
.Format
.nSamplesPerSec
=22050;
1065 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1066 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1067 wfex
.Format
.nBlockAlign
;
1068 wfex
.Format
.cbSize
=22;
1069 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1070 wfex
.dwChannelMask
=SPEAKER_ALL
;
1071 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1072 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1073 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1074 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1075 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1076 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1077 if (rc
==MMSYSERR_NOERROR
) {
1079 wave_out_test_deviceOut(device
,1.0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1080 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1083 trace("waveOutOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
1086 /* test if 4 channels supported */
1087 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1088 wfex
.Format
.nChannels
=4;
1089 wfex
.Format
.wBitsPerSample
=16;
1090 wfex
.Format
.nSamplesPerSec
=22050;
1091 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1092 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1093 wfex
.Format
.nBlockAlign
;
1094 wfex
.Format
.cbSize
=22;
1095 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1096 wfex
.dwChannelMask
=SPEAKER_ALL
;
1097 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1098 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1099 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1100 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1101 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1102 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1103 if (rc
==MMSYSERR_NOERROR
) {
1105 wave_out_test_deviceOut(device
,1.0,&wfex
.Format
,0,CALLBACK_EVENT
,
1106 &capsA
,winetest_interactive
,TRUE
,FALSE
);
1108 trace("waveOutOpen(%s): 4 channels not supported\n",
1111 /* test if 6 channels supported */
1112 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1113 wfex
.Format
.nChannels
=6;
1114 wfex
.Format
.wBitsPerSample
=16;
1115 wfex
.Format
.nSamplesPerSec
=22050;
1116 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1117 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1118 wfex
.Format
.nBlockAlign
;
1119 wfex
.Format
.cbSize
=22;
1120 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1121 wfex
.dwChannelMask
=SPEAKER_ALL
;
1122 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1123 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1124 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1125 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1126 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1127 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1128 if (rc
==MMSYSERR_NOERROR
) {
1130 wave_out_test_deviceOut(device
,1.0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1131 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1134 trace("waveOutOpen(%s): 6 channels not supported\n",
1137 #if 0 /* ALSA doesn't like this format */
1138 /* test if 24 bit samples supported */
1139 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1140 wfex
.Format
.nChannels
=2;
1141 wfex
.Format
.wBitsPerSample
=24;
1142 wfex
.Format
.nSamplesPerSec
=22050;
1143 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1144 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1145 wfex
.Format
.nBlockAlign
;
1146 wfex
.Format
.cbSize
=22;
1147 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1148 wfex
.dwChannelMask
=SPEAKER_ALL
;
1149 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1150 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1151 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1152 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1153 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1154 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1155 if (rc
==MMSYSERR_NOERROR
) {
1157 wave_out_test_deviceOut(device
,1.0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1158 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1161 trace("waveOutOpen(%s): 24 bit samples not supported\n",
1165 /* test if 32 bit samples supported */
1166 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1167 wfex
.Format
.nChannels
=2;
1168 wfex
.Format
.wBitsPerSample
=32;
1169 wfex
.Format
.nSamplesPerSec
=22050;
1170 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1171 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1172 wfex
.Format
.nBlockAlign
;
1173 wfex
.Format
.cbSize
=22;
1174 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1175 wfex
.dwChannelMask
=SPEAKER_ALL
;
1176 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_PCM
;
1177 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1178 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1179 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1180 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1181 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1182 if (rc
==MMSYSERR_NOERROR
) {
1184 wave_out_test_deviceOut(device
,1.0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1185 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1188 trace("waveOutOpen(%s): 32 bit samples not supported\n",
1191 /* test if 32 bit float samples supported */
1192 wfex
.Format
.wFormatTag
=WAVE_FORMAT_EXTENSIBLE
;
1193 wfex
.Format
.nChannels
=2;
1194 wfex
.Format
.wBitsPerSample
=32;
1195 wfex
.Format
.nSamplesPerSec
=22050;
1196 wfex
.Format
.nBlockAlign
=wfex
.Format
.nChannels
*wfex
.Format
.wBitsPerSample
/8;
1197 wfex
.Format
.nAvgBytesPerSec
=wfex
.Format
.nSamplesPerSec
*
1198 wfex
.Format
.nBlockAlign
;
1199 wfex
.Format
.cbSize
=22;
1200 wfex
.Samples
.wValidBitsPerSample
=wfex
.Format
.wBitsPerSample
;
1201 wfex
.dwChannelMask
=SPEAKER_ALL
;
1202 wfex
.SubFormat
=KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
1203 rc
=waveOutOpen(&wout
,device
,&wfex
.Format
,0,0,
1204 CALLBACK_NULL
|WAVE_FORMAT_DIRECT
);
1205 ok(rc
==MMSYSERR_NOERROR
|| rc
==WAVERR_BADFORMAT
||
1206 rc
==MMSYSERR_INVALFLAG
|| rc
==MMSYSERR_INVALPARAM
,
1207 "waveOutOpen(%s): returned %s\n",dev_name(device
),wave_out_error(rc
));
1208 if (rc
==MMSYSERR_NOERROR
) {
1210 wave_out_test_deviceOut(device
,1.0,&wfex
.Format
,WAVE_FORMAT_2M16
,
1211 CALLBACK_EVENT
,&capsA
,winetest_interactive
,
1214 trace("waveOutOpen(%s): 32 bit float samples not supported\n",
1218 static void wave_out_tests(void)
1222 WAVEFORMATEX format
;
1227 ndev
=waveOutGetNumDevs();
1228 trace("found %d WaveOut devices\n",ndev
);
1230 rc
=waveOutGetDevCapsA(ndev
+1,&capsA
,sizeof(capsA
));
1231 ok(rc
==MMSYSERR_BADDEVICEID
,
1232 "waveOutGetDevCapsA(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
1233 dev_name(ndev
+1),mmsys_error(rc
));
1235 rc
=waveOutGetDevCapsW(ndev
+1,&capsW
,sizeof(capsW
));
1236 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NOTSUPPORTED
,
1237 "waveOutGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
1238 "expected, got %s\n",dev_name(ndev
+1),mmsys_error(rc
));
1240 rc
=waveOutGetDevCapsA(WAVE_MAPPER
,&capsA
,sizeof(capsA
));
1242 ok(rc
==MMSYSERR_NOERROR
,
1243 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
1244 dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1246 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
,
1247 "waveOutGetDevCapsA(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
1248 "expected, got %s\n",dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1250 rc
=waveOutGetDevCapsW(WAVE_MAPPER
,&capsW
,sizeof(capsW
));
1252 ok(rc
==MMSYSERR_NOERROR
|| rc
==MMSYSERR_NOTSUPPORTED
,
1253 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
1254 "expected, got %s\n",dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1256 ok(rc
==MMSYSERR_BADDEVICEID
|| rc
==MMSYSERR_NODRIVER
||
1257 rc
==MMSYSERR_NOTSUPPORTED
,
1258 "waveOutGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
1259 " or MMSYSERR_NOTSUPPORTED expected, got %s\n",
1260 dev_name(WAVE_MAPPER
),mmsys_error(rc
));
1262 format
.wFormatTag
=WAVE_FORMAT_PCM
;
1264 format
.wBitsPerSample
=16;
1265 format
.nSamplesPerSec
=44100;
1266 format
.nBlockAlign
=format
.nChannels
*format
.wBitsPerSample
/8;
1267 format
.nAvgBytesPerSec
=format
.nSamplesPerSec
*format
.nBlockAlign
;
1269 rc
=waveOutOpen(&wout
,ndev
+1,&format
,0,0,CALLBACK_NULL
);
1270 ok(rc
==MMSYSERR_BADDEVICEID
,
1271 "waveOutOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
1272 dev_name(ndev
+1),mmsys_error(rc
));
1274 for (d
=0;d
<ndev
;d
++)
1275 wave_out_test_device(d
);
1278 wave_out_test_device(WAVE_MAPPER
);