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 static 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%08x)", 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 %d bytes, "
465 "should be %d\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 %d samples "
476 "(%d bytes), should be %d (%d 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 %d ms, "
489 "(%d bytes), should be %d (%d bytes)\n", dev_name(device),
490 bytes_to_ms(returned, pwfx), returned,
491 bytes_to_ms(bytes, pwfx), bytes);
493 mmtime.wType = TIME_SMPTE;
494 rc=waveOutGetPosition(wout, &mmtime, sizeof(mmtime));
495 ok(rc==MMSYSERR_NOERROR,
496 "waveOutGetPosition(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
497 if (mmtime.wType != TIME_SMPTE && winetest_debug > 1)
498 trace("waveOutGetPosition(%s): TIME_SMPTE not supported, returned %s\n",
499 dev_name(device),wave_time_format(mmtime.wType));
500 returned = time_to_bytes(&mmtime, pwfx);
501 ok(returned == bytes, "waveOutGetPosition(%s): SMPTE test failed\n",
504 mmtime.wType = TIME_MIDI;
505 rc=waveOutGetPosition(wout, &mmtime, sizeof(mmtime));
506 ok(rc==MMSYSERR_NOERROR,
507 "waveOutGetPosition(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
508 if (mmtime.wType != TIME_MIDI && winetest_debug > 1)
509 trace("waveOutGetPosition(%s): TIME_MIDI not supported, returned %s\n",
510 dev_name(device),wave_time_format(mmtime.wType));
511 returned = time_to_bytes(&mmtime, pwfx);
512 ok(returned == bytes, "waveOutGetPosition(%s): MIDI test failed\n",
515 mmtime.wType = TIME_TICKS;
516 rc=waveOutGetPosition(wout, &mmtime, sizeof(mmtime));
517 ok(rc==MMSYSERR_NOERROR,
518 "waveOutGetPosition(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
519 if (mmtime.wType != TIME_TICKS && winetest_debug > 1)
520 trace("waveOutGetPosition(%s): TIME_TICKS not supported, returned %s\n",
521 dev_name(device),wave_time_format(mmtime.wType));
522 returned = time_to_bytes(&mmtime, pwfx);
523 ok(returned == bytes, "waveOutGetPosition(%s): TICKS test failed\n",
527 static void CALLBACK callback_func(HWAVEOUT hwo, UINT uMsg,
528 DWORD_PTR dwInstance,
529 DWORD dwParam1, DWORD dwParam2)
531 SetEvent((HANDLE)dwInstance);
534 static DWORD WINAPI callback_thread(LPVOID lpParameter)
538 SetEvent((HANDLE)lpParameter);
540 while (GetMessage(&msg, 0, 0, 0)) {
541 UINT message = msg.message;
542 /* for some reason XP sends a WM_USER message before WOM_OPEN */
543 ok (message == WOM_OPEN || message == WOM_DONE ||
544 message == WOM_CLOSE || message == WM_USER || message == WM_APP,
545 "GetMessage returned unexpected message: %u\n", message);
546 if (message == WOM_OPEN || message == WOM_DONE || message == WOM_CLOSE)
547 SetEvent((HANDLE)lpParameter);
548 else if (message == WM_APP) {
549 SetEvent((HANDLE)lpParameter);
557 static void wave_out_test_deviceOut(int device, double duration,
558 int headers, int loops,
559 LPWAVEFORMATEX pwfx, DWORD format,
560 DWORD flags, LPWAVEOUTCAPS pcaps,
561 BOOL interactive, BOOL sine, BOOL pause)
568 WORD nChannels = pwfx->nChannels;
569 WORD wBitsPerSample = pwfx->wBitsPerSample;
570 DWORD nSamplesPerSec = pwfx->nSamplesPerSec;
571 BOOL has_volume = pcaps->dwSupport & WAVECAPS_VOLUME ? TRUE : FALSE;
575 DWORD callback_instance = 0;
583 hevent=CreateEvent(NULL,FALSE,FALSE,NULL);
584 ok(hevent!=NULL,"CreateEvent(): error=%d\n",GetLastError());
588 if ((flags & CALLBACK_TYPEMASK) == CALLBACK_EVENT) {
589 callback = (DWORD)hevent;
590 callback_instance = 0;
591 } else if ((flags & CALLBACK_TYPEMASK) == CALLBACK_FUNCTION) {
592 callback = (DWORD)callback_func;
593 callback_instance = (DWORD)hevent;
594 } else if ((flags & CALLBACK_TYPEMASK) == CALLBACK_THREAD) {
595 thread = CreateThread(NULL, 0, callback_thread, hevent, 0, &thread_id);
597 /* make sure thread is running */
598 WaitForSingleObject(hevent,INFINITE);
599 callback = thread_id;
600 callback_instance = 0;
602 trace("CreateThread() failed\n");
606 } else if ((flags & CALLBACK_TYPEMASK) == CALLBACK_WINDOW) {
607 trace("CALLBACK_THREAD not implemented\n");
610 } else if (flags && CALLBACK_TYPEMASK) {
611 trace("Undefined callback type!\n");
615 trace("CALLBACK_NULL not implemented\n");
620 rc=waveOutOpen(&wout,device,pwfx,callback,callback_instance,flags);
621 /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */
622 /* It is acceptable to fail on formats that are not specified to work */
623 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
624 rc==MMSYSERR_NOTENABLED || rc==MMSYSERR_NODRIVER ||
625 rc==MMSYSERR_ALLOCATED ||
626 ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
627 (flags & WAVE_FORMAT_DIRECT) && !(pcaps->dwFormats & format)) ||
628 ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
629 (!(flags & WAVE_FORMAT_DIRECT) || (flags & WAVE_MAPPED)) &&
630 !(pcaps->dwFormats & format)) ||
631 (rc==MMSYSERR_INVALFLAG && (flags & WAVE_FORMAT_DIRECT)),
632 "waveOutOpen(%s): format=%dx%2dx%d flags=%lx(%s) rc=%s\n",
633 dev_name(device),pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
634 pwfx->nChannels,CALLBACK_EVENT|flags,
635 wave_open_flags(CALLBACK_EVENT|flags),wave_out_error(rc));
636 if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
637 (flags & WAVE_FORMAT_DIRECT) && (pcaps->dwFormats & format))
638 trace(" Reason: The device lists this format as supported in it's "
639 "capabilities but opening it failed.\n");
640 if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) &&
641 !(pcaps->dwFormats & format))
642 trace("waveOutOpen(%s): format=%dx%2dx%d %s rc=%s failed but format "
643 "not supported so OK.\n", dev_name(device), pwfx->nSamplesPerSec,
644 pwfx->wBitsPerSample,pwfx->nChannels,
645 flags & WAVE_FORMAT_DIRECT ? "flags=WAVE_FORMAT_DIRECT" :
646 flags & WAVE_MAPPED ? "flags=WAVE_MAPPED" : "", mmsys_error(rc));
647 if (rc!=MMSYSERR_NOERROR)
650 WaitForSingleObject(hevent,INFINITE);
652 ok(pwfx->nChannels==nChannels &&
653 pwfx->wBitsPerSample==wBitsPerSample &&
654 pwfx->nSamplesPerSec==nSamplesPerSec,
655 "got the wrong format: %dx%2dx%d instead of %dx%2dx%d\n",
656 pwfx->nSamplesPerSec, pwfx->wBitsPerSample,
657 pwfx->nChannels, nSamplesPerSec, wBitsPerSample, nChannels);
659 frags = malloc(headers * sizeof(WAVEHDR));
662 buffer=wave_generate_la(pwfx,duration / (loops + 1),&length);
664 buffer=wave_generate_silence(pwfx,duration / (loops + 1),&length);
666 rc=waveOutGetVolume(wout,0);
667 ok(rc==MMSYSERR_INVALPARAM,"waveOutGetVolume(%s,0) expected "
668 "MMSYSERR_INVALPARAM, got %s\n", dev_name(device),wave_out_error(rc));
669 rc=waveOutGetVolume(wout,&volume);
670 ok(has_volume ? rc==MMSYSERR_NOERROR : rc==MMSYSERR_NOTSUPPORTED,
671 "waveOutGetVolume(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
673 /* make sure fragment length is a multiple of block size */
674 frag_length = ((length / headers) / pwfx->nBlockAlign) * pwfx->nBlockAlign;
676 for (i = 0; i < headers; i++) {
677 frags[i].lpData=buffer + (i * frag_length);
678 if (i != (headers-1))
679 frags[i].dwBufferLength=frag_length;
681 /* use remainder of buffer for last fragment */
682 frags[i].dwBufferLength=length - (i * frag_length);
686 rc=waveOutPrepareHeader(wout, &frags[i], sizeof(frags[0]));
687 ok(rc==MMSYSERR_NOERROR,
688 "waveOutPrepareHeader(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
691 if (interactive && rc==MMSYSERR_NOERROR) {
693 trace("Playing %g second %s at %5dx%2dx%d %2d header%s %d loop%s %d bytes %s %s\n",duration,
694 sine ? "440Hz tone" : "silence",pwfx->nSamplesPerSec,
695 pwfx->wBitsPerSample,pwfx->nChannels, headers, headers > 1 ? "s": " ",
696 loops, loops == 1 ? " " : "s", length * (loops + 1),
697 get_format_str(pwfx->wFormatTag),
698 wave_open_flags(flags));
699 if (sine && has_volume && volume == 0)
700 trace("*** Warning the sound is muted, you will not hear the test\n");
702 /* Check that the position is 0 at start */
703 check_position(device, wout, 0, pwfx);
705 rc=waveOutSetVolume(wout,0x20002000);
706 ok(has_volume ? rc==MMSYSERR_NOERROR : rc==MMSYSERR_NOTSUPPORTED,
707 "waveOutSetVolume(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
709 rc=waveOutSetVolume(wout,volume);
710 ok(has_volume ? rc==MMSYSERR_NOERROR : rc==MMSYSERR_NOTSUPPORTED,
711 "waveOutSetVolume(%s): rc=%s\n",dev_name(device),wave_out_error(rc));
713 start=GetTickCount();
715 rc=waveOutWrite(wout, &frags[0], sizeof(frags[0]));
716 ok(rc==MMSYSERR_NOERROR,"waveOutWrite(%s): rc=%s\n",
717 dev_name(device),wave_out_error(rc));
719 ok(frags[0].dwFlags==(WHDR_PREPARED|WHDR_INQUEUE),
720 "WHDR_INQUEUE WHDR_PREPARED expected, got= %s\n",
721 wave_header_flags(frags[0].dwFlags));
723 rc=waveOutWrite(wout, &frags[0], sizeof(frags[0]));
724 ok(rc==WAVERR_STILLPLAYING,
725 "waveOutWrite(%s): WAVE_STILLPLAYING expected, got %s\n",
726 dev_name(device),wave_out_error(rc));
728 ok(frags[0].dwFlags==(WHDR_PREPARED|WHDR_INQUEUE),
729 "WHDR_INQUEUE WHDR_PREPARED expected, got %s\n",
730 wave_header_flags(frags[0].dwFlags));
732 if (headers == 1 && loops == 0 && pause) {
733 paused = duration / 2;
734 Sleep(paused * 1000);
735 rc=waveOutPause(wout);
736 ok(rc==MMSYSERR_NOERROR,"waveOutPause(%s): rc=%s\n",
737 dev_name(device),wave_out_error(rc));
738 trace("pausing for %g seconds\n", paused);
739 Sleep(paused * 1000);
740 rc=waveOutRestart(wout);
741 ok(rc==MMSYSERR_NOERROR,"waveOutRestart(%s): rc=%s\n",
742 dev_name(device),wave_out_error(rc));
745 for (j = 0; j <= loops; j++) {
746 for (i = 0; i < headers; i++) {
747 /* don't do last one */
748 if (!((j == loops) && (i == (headers - 1)))) {
750 frags[(i+1) % headers].dwFlags = WHDR_PREPARED;
751 rc=waveOutWrite(wout, &frags[(i+1) % headers], sizeof(frags[0]));
752 ok(rc==MMSYSERR_NOERROR,"waveOutWrite(%s, header[%d]): rc=%s\n",
753 dev_name(device),(i+1)%headers,wave_out_error(rc));
755 WaitForSingleObject(hevent,INFINITE);
759 /* Check the sound duration was between -2% and +10% of the expected value */
761 actual = (end - start) / 1000.0;
762 if (winetest_debug > 1)
763 trace("sound duration=%g ms\n",1000*actual);
764 ok((actual > (0.97 * (duration+paused))) &&
765 (actual < (1.1 * (duration+paused))),
766 "The sound played for %g ms instead of %g ms\n",
767 1000*actual,1000*(duration+paused));
768 for (i = 0; i < headers; i++) {
769 ok(frags[i].dwFlags=(WHDR_DONE|WHDR_PREPARED),
770 "WHDR_DONE WHDR_PREPARED expected, got %s\n",
771 wave_header_flags(frags[i].dwFlags));
773 check_position(device, wout, length * (loops + 1), pwfx);
776 for (i = 0; i < headers; i++) {
777 rc=waveOutUnprepareHeader(wout, &frags[i], sizeof(frags[0]));
778 ok(rc==MMSYSERR_NOERROR,
779 "waveOutUnprepareHeader(%s): rc=%s\n",dev_name(device),
784 rc=waveOutClose(wout);
785 ok(rc==MMSYSERR_NOERROR,"waveOutClose(%s): rc=%s\n",dev_name(device),
787 WaitForSingleObject(hevent,INFINITE);
789 if ((flags & CALLBACK_TYPEMASK) == CALLBACK_THREAD) {
790 PostThreadMessage(thread_id, WM_APP, 0, 0);
791 WaitForSingleObject(hevent,INFINITE);
797 static void wave_out_test_device(int device)
801 WAVEFORMATEX format, oformat;
802 WAVEFORMATEXTENSIBLE wfex;
811 SYSTEM_INFO sSysInfo;
815 GetSystemInfo(&sSysInfo);
816 dwPageSize = sSysInfo.dwPageSize;
818 rc=waveOutGetDevCapsA(device,&capsA,sizeof(capsA));
819 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID ||
820 rc==MMSYSERR_NODRIVER,
821 "waveOutGetDevCapsA(%s): failed to get capabilities: rc=%s\n",
822 dev_name(device),wave_out_error(rc));
823 if (rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER)
826 rc=waveOutGetDevCapsW(device,&capsW,sizeof(capsW));
827 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED,
828 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
829 "expected, got %s\n",dev_name(device),wave_out_error(rc));
831 rc=waveOutGetDevCapsA(device,0,sizeof(capsA));
832 ok(rc==MMSYSERR_INVALPARAM,
833 "waveOutGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, "
834 "got %s\n",dev_name(device),wave_out_error(rc));
836 rc=waveOutGetDevCapsW(device,0,sizeof(capsW));
837 ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
838 "waveOutGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
839 "expected, got %s\n",dev_name(device),wave_out_error(rc));
841 #if 0 /* FIXME: this works on windows but crashes wine */
842 rc=waveOutGetDevCapsA(device,(LPWAVEOUTCAPSA)1,sizeof(capsA));
843 ok(rc==MMSYSERR_INVALPARAM,
844 "waveOutGetDevCapsA(%s): MMSYSERR_INVALPARAM expected, got %s\n",
845 dev_name(device),wave_out_error(rc));
847 rc=waveOutGetDevCapsW(device,(LPWAVEOUTCAPSW)1,sizeof(capsW));
848 ok(rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
849 "waveOutGetDevCapsW(%s): MMSYSERR_INVALPARAM or MMSYSERR_NOTSUPPORTED "
850 "expected, got %s\n",dev_name(device),wave_out_error(rc));
853 rc=waveOutGetDevCapsA(device,&capsA,4);
854 ok(rc==MMSYSERR_NOERROR,
855 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
856 dev_name(device),wave_out_error(rc));
858 rc=waveOutGetDevCapsW(device,&capsW,4);
859 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED,
860 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
861 "expected, got %s\n",dev_name(device),wave_out_error(rc));
864 rc=waveOutMessage((HWAVEOUT)device, DRV_QUERYDEVICEINTERFACESIZE,
865 (DWORD_PTR)&size, 0);
866 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_INVALPARAM ||
867 rc==MMSYSERR_NOTSUPPORTED,
868 "waveOutMessage(%s): failed to get interface size, rc=%s\n",
869 dev_name(device),wave_out_error(rc));
870 if (rc==MMSYSERR_NOERROR) {
871 nameW = (WCHAR *)malloc(size);
872 rc=waveOutMessage((HWAVEOUT)device, DRV_QUERYDEVICEINTERFACE,
873 (DWORD_PTR)nameW, size);
874 ok(rc==MMSYSERR_NOERROR,"waveOutMessage(%s): failed to get interface "
875 "name, rc=%s\n",dev_name(device),wave_out_error(rc));
876 ok(lstrlenW(nameW)+1==size/sizeof(WCHAR),"got an incorrect size %d\n",size);
877 if (rc==MMSYSERR_NOERROR) {
878 nameA = malloc(size/sizeof(WCHAR));
879 WideCharToMultiByte(CP_ACP, 0, nameW, size/sizeof(WCHAR), nameA,
880 size/sizeof(WCHAR), NULL, NULL);
884 else if (rc==MMSYSERR_NOTSUPPORTED) {
885 nameA=strdup("not supported");
888 trace(" %s: \"%s\" (%s) %d.%d (%d:%d)\n",dev_name(device),capsA.szPname,
889 (nameA?nameA:"failed"),capsA.vDriverVersion >> 8,
890 capsA.vDriverVersion & 0xff, capsA.wMid,capsA.wPid);
891 trace(" channels=%d formats=%05x support=%04x\n",
892 capsA.wChannels,capsA.dwFormats,capsA.dwSupport);
893 trace(" %s\n",wave_out_caps(capsA.dwSupport));
896 if (winetest_interactive && (device != WAVE_MAPPER))
898 trace("Playing a 5 seconds reference tone.\n");
899 trace("All subsequent tones should be identical to this one.\n");
900 trace("Listen for stutter, changes in pitch, volume, etc.\n");
901 format.wFormatTag=WAVE_FORMAT_PCM;
903 format.wBitsPerSample=8;
904 format.nSamplesPerSec=22050;
905 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
906 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
909 wave_out_test_deviceOut(device,5.0,1,0,&format,WAVE_FORMAT_2M08,
910 CALLBACK_EVENT,&capsA,TRUE,TRUE,FALSE);
911 wave_out_test_deviceOut(device,5.0,1,0,&format,WAVE_FORMAT_2M08,
912 CALLBACK_FUNCTION,&capsA,TRUE,TRUE,FALSE);
913 wave_out_test_deviceOut(device,5.0,1,0,&format,WAVE_FORMAT_2M08,
914 CALLBACK_THREAD,&capsA,TRUE,TRUE,FALSE);
916 wave_out_test_deviceOut(device,5.0,10,0,&format,WAVE_FORMAT_2M08,
917 CALLBACK_EVENT,&capsA,TRUE,TRUE,FALSE);
918 wave_out_test_deviceOut(device,5.0,5,1,&format,WAVE_FORMAT_2M08,
919 CALLBACK_EVENT,&capsA,TRUE,TRUE,FALSE);
921 format.wFormatTag=WAVE_FORMAT_PCM;
923 format.wBitsPerSample=8;
924 format.nSamplesPerSec=22050;
925 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
926 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
928 wave_out_test_deviceOut(device,1.0,1,0,&format,WAVE_FORMAT_2M08,
929 CALLBACK_EVENT,&capsA,TRUE,FALSE,FALSE);
930 wave_out_test_deviceOut(device,1.0,1,0,&format,WAVE_FORMAT_2M08,
931 CALLBACK_EVENT,&capsA,TRUE,FALSE,TRUE);
932 wave_out_test_deviceOut(device,1.0,1,0,&format,WAVE_FORMAT_2M08,
933 CALLBACK_FUNCTION,&capsA,TRUE,FALSE,FALSE);
934 wave_out_test_deviceOut(device,1.0,1,0,&format,WAVE_FORMAT_2M08,
935 CALLBACK_FUNCTION,&capsA,TRUE,FALSE,TRUE);
936 wave_out_test_deviceOut(device,1.0,1,0,&format,WAVE_FORMAT_2M08,
937 CALLBACK_THREAD,&capsA,TRUE,FALSE,FALSE);
938 wave_out_test_deviceOut(device,1.0,1,0,&format,WAVE_FORMAT_2M08,
939 CALLBACK_THREAD,&capsA,TRUE,FALSE,TRUE);
941 wave_out_test_deviceOut(device,1.0,10,0,&format,WAVE_FORMAT_2M08,
942 CALLBACK_EVENT,&capsA,TRUE,FALSE,FALSE);
943 wave_out_test_deviceOut(device,1.0,5,1,&format,WAVE_FORMAT_2M08,
944 CALLBACK_EVENT,&capsA,TRUE,FALSE,FALSE);
947 for (f=0;f<NB_WIN_FORMATS;f++) {
948 format.wFormatTag=WAVE_FORMAT_PCM;
949 format.nChannels=win_formats[f][3];
950 format.wBitsPerSample=win_formats[f][2];
951 format.nSamplesPerSec=win_formats[f][1];
952 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
953 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
955 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
956 CALLBACK_EVENT,&capsA,winetest_interactive,
958 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
959 CALLBACK_FUNCTION,&capsA,winetest_interactive,
961 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
962 CALLBACK_THREAD,&capsA,winetest_interactive,
965 wave_out_test_deviceOut(device,1.0,10,0,&format,win_formats[f][0],
966 CALLBACK_EVENT,&capsA,winetest_interactive,
968 wave_out_test_deviceOut(device,1.0,5,1,&format,win_formats[f][0],
969 CALLBACK_EVENT,&capsA,winetest_interactive,
972 if (winetest_interactive) {
973 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
974 CALLBACK_EVENT,&capsA,winetest_interactive,
976 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
977 CALLBACK_FUNCTION,&capsA,winetest_interactive,
979 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
980 CALLBACK_THREAD,&capsA,winetest_interactive,
983 wave_out_test_deviceOut(device,1.0,10,0,&format,win_formats[f][0],
984 CALLBACK_EVENT,&capsA,winetest_interactive,
986 wave_out_test_deviceOut(device,1.0,5,1,&format,win_formats[f][0],
987 CALLBACK_EVENT,&capsA,winetest_interactive,
990 if (device != WAVE_MAPPER)
992 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
993 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,&capsA,
994 winetest_interactive,TRUE,FALSE);
995 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
996 CALLBACK_EVENT|WAVE_MAPPED,&capsA,
997 winetest_interactive,TRUE,FALSE);
998 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
999 CALLBACK_FUNCTION|WAVE_FORMAT_DIRECT,&capsA,
1000 winetest_interactive,TRUE,FALSE);
1001 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1002 CALLBACK_FUNCTION|WAVE_MAPPED,&capsA,
1003 winetest_interactive,TRUE,FALSE);
1004 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1005 CALLBACK_THREAD|WAVE_FORMAT_DIRECT,&capsA,
1006 winetest_interactive,TRUE,FALSE);
1007 wave_out_test_deviceOut(device,1.0,1,0,&format,win_formats[f][0],
1008 CALLBACK_THREAD|WAVE_MAPPED,&capsA,
1009 winetest_interactive,TRUE,FALSE);
1011 wave_out_test_deviceOut(device,1.0,10,0,&format,win_formats[f][0],
1012 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,&capsA,
1013 winetest_interactive,TRUE,FALSE);
1014 wave_out_test_deviceOut(device,1.0,5,1,&format,win_formats[f][0],
1015 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,&capsA,
1016 winetest_interactive,TRUE,FALSE);
1020 /* Try a PCMWAVEFORMAT aligned next to an unaccessible page for bounds
1022 twoPages = VirtualAlloc(NULL, 2 * dwPageSize, MEM_RESERVE | MEM_COMMIT,
1024 ok(twoPages!=NULL,"Failed to allocate 2 pages of memory\n");
1026 res = VirtualProtect(twoPages + dwPageSize, dwPageSize, PAGE_NOACCESS,
1028 ok(res, "Failed to set memory access on second page\n");
1030 LPWAVEFORMATEX pwfx = (LPWAVEFORMATEX)(twoPages + dwPageSize -
1031 sizeof(PCMWAVEFORMAT));
1032 pwfx->wFormatTag=WAVE_FORMAT_PCM;
1034 pwfx->wBitsPerSample=8;
1035 pwfx->nSamplesPerSec=22050;
1036 pwfx->nBlockAlign=pwfx->nChannels*pwfx->wBitsPerSample/8;
1037 pwfx->nAvgBytesPerSec=pwfx->nSamplesPerSec*pwfx->nBlockAlign;
1038 wave_out_test_deviceOut(device,1.0,1,0,pwfx,WAVE_FORMAT_2M08,
1039 CALLBACK_EVENT,&capsA,winetest_interactive,
1041 wave_out_test_deviceOut(device,1.0,10,0,pwfx,WAVE_FORMAT_2M08,
1042 CALLBACK_EVENT,&capsA,winetest_interactive,
1044 wave_out_test_deviceOut(device,1.0,5,1,pwfx,WAVE_FORMAT_2M08,
1045 CALLBACK_EVENT,&capsA,winetest_interactive,
1047 if (device != WAVE_MAPPER)
1049 wave_out_test_deviceOut(device,1.0,1,0,pwfx,WAVE_FORMAT_2M08,
1050 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,
1051 &capsA,winetest_interactive,TRUE,FALSE);
1052 wave_out_test_deviceOut(device,1.0,1,0,pwfx,WAVE_FORMAT_2M08,
1053 CALLBACK_EVENT|WAVE_MAPPED,&capsA,
1054 winetest_interactive,TRUE,FALSE);
1055 wave_out_test_deviceOut(device,1.0,10,0,pwfx,WAVE_FORMAT_2M08,
1056 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,
1057 &capsA,winetest_interactive,TRUE,FALSE);
1058 wave_out_test_deviceOut(device,1.0,10,0,pwfx,WAVE_FORMAT_2M08,
1059 CALLBACK_EVENT|WAVE_MAPPED,&capsA,
1060 winetest_interactive,TRUE,FALSE);
1061 wave_out_test_deviceOut(device,1.0,5,1,pwfx,WAVE_FORMAT_2M08,
1062 CALLBACK_EVENT|WAVE_FORMAT_DIRECT,
1063 &capsA,winetest_interactive,TRUE,FALSE);
1064 wave_out_test_deviceOut(device,1.0,5,1,pwfx,WAVE_FORMAT_2M08,
1065 CALLBACK_EVENT|WAVE_MAPPED,&capsA,
1066 winetest_interactive,TRUE,FALSE);
1069 VirtualFree(twoPages, 0, MEM_RELEASE);
1072 /* Testing invalid format: 11 bits per sample */
1073 format.wFormatTag=WAVE_FORMAT_PCM;
1075 format.wBitsPerSample=11;
1076 format.nSamplesPerSec=22050;
1077 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
1078 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
1081 rc=waveOutOpen(&wout,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1082 ok(rc==WAVERR_BADFORMAT || rc==MMSYSERR_INVALFLAG ||
1083 rc==MMSYSERR_INVALPARAM,
1084 "waveOutOpen(%s): opening the device in 11 bits mode should fail: "
1085 "rc=%s\n",dev_name(device),wave_out_error(rc));
1086 if (rc==MMSYSERR_NOERROR) {
1087 trace(" got %dx%2dx%d for %dx%2dx%d\n",
1088 format.nSamplesPerSec, format.wBitsPerSample,
1090 oformat.nSamplesPerSec, oformat.wBitsPerSample,
1095 /* Testing invalid format: 2 MHz sample rate */
1096 format.wFormatTag=WAVE_FORMAT_PCM;
1098 format.wBitsPerSample=16;
1099 format.nSamplesPerSec=2000000;
1100 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
1101 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
1104 rc=waveOutOpen(&wout,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1105 ok(rc==WAVERR_BADFORMAT || rc==MMSYSERR_INVALFLAG ||
1106 rc==MMSYSERR_INVALPARAM,
1107 "waveOutOpen(%s): opening the device at 2 MHz sample rate should fail: "
1108 "rc=%s\n",dev_name(device),wave_out_error(rc));
1109 if (rc==MMSYSERR_NOERROR) {
1110 trace(" got %dx%2dx%d for %dx%2dx%d\n",
1111 format.nSamplesPerSec, format.wBitsPerSample,
1113 oformat.nSamplesPerSec, oformat.wBitsPerSample,
1118 /* try some non PCM formats */
1119 format.wFormatTag=WAVE_FORMAT_MULAW;
1121 format.wBitsPerSample=8;
1122 format.nSamplesPerSec=8000;
1123 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
1124 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
1127 rc=waveOutOpen(&wout,device,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1128 ok(rc==MMSYSERR_NOERROR ||rc==WAVERR_BADFORMAT ||
1129 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1130 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1131 if (rc==MMSYSERR_NOERROR) {
1133 wave_out_test_deviceOut(device,1.0,1,0,&format,0,CALLBACK_EVENT,
1134 &capsA,winetest_interactive,TRUE,FALSE);
1135 wave_out_test_deviceOut(device,1.0,10,0,&format,0,CALLBACK_EVENT,
1136 &capsA,winetest_interactive,TRUE,FALSE);
1137 wave_out_test_deviceOut(device,1.0,5,1,&format,0,CALLBACK_EVENT,
1138 &capsA,winetest_interactive,TRUE,FALSE);
1140 trace("waveOutOpen(%s): WAVE_FORMAT_MULAW not supported\n",
1143 format.wFormatTag=WAVE_FORMAT_ADPCM;
1145 format.wBitsPerSample=4;
1146 format.nSamplesPerSec=22050;
1147 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
1148 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
1151 rc=waveOutOpen(&wout,device,&format,0,0,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,1,0,&format,0,CALLBACK_EVENT,
1158 &capsA,winetest_interactive,TRUE,FALSE);
1159 wave_out_test_deviceOut(device,1.0,10,0,&format,0,CALLBACK_EVENT,
1160 &capsA,winetest_interactive,TRUE,FALSE);
1161 wave_out_test_deviceOut(device,1.0,5,1,&format,0,CALLBACK_EVENT,
1162 &capsA,winetest_interactive,TRUE,FALSE);
1164 trace("waveOutOpen(%s): WAVE_FORMAT_ADPCM not supported\n",
1167 /* test if WAVEFORMATEXTENSIBLE supported */
1168 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1169 wfex.Format.nChannels=2;
1170 wfex.Format.wBitsPerSample=16;
1171 wfex.Format.nSamplesPerSec=22050;
1172 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1173 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1174 wfex.Format.nBlockAlign;
1175 wfex.Format.cbSize=22;
1176 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1177 wfex.dwChannelMask=SPEAKER_ALL;
1178 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
1179 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1180 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1181 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1182 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1183 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1184 if (rc==MMSYSERR_NOERROR) {
1186 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,WAVE_FORMAT_2M16,
1187 CALLBACK_EVENT,&capsA,winetest_interactive,
1189 wave_out_test_deviceOut(device,1.0,10,0,&wfex.Format,WAVE_FORMAT_2M16,
1190 CALLBACK_EVENT,&capsA,winetest_interactive,
1192 wave_out_test_deviceOut(device,1.0,5,1,&wfex.Format,WAVE_FORMAT_2M16,
1193 CALLBACK_EVENT,&capsA,winetest_interactive,
1196 trace("waveOutOpen(%s): WAVE_FORMAT_EXTENSIBLE not supported\n",
1199 /* test if 4 channels supported */
1200 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1201 wfex.Format.nChannels=4;
1202 wfex.Format.wBitsPerSample=16;
1203 wfex.Format.nSamplesPerSec=22050;
1204 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1205 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1206 wfex.Format.nBlockAlign;
1207 wfex.Format.cbSize=22;
1208 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1209 wfex.dwChannelMask=SPEAKER_ALL;
1210 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
1211 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1212 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1213 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1214 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1215 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1216 if (rc==MMSYSERR_NOERROR) {
1218 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,0,CALLBACK_EVENT,
1219 &capsA,winetest_interactive,TRUE,FALSE);
1220 wave_out_test_deviceOut(device,1.0,10,0,&wfex.Format,0,CALLBACK_EVENT,
1221 &capsA,winetest_interactive,TRUE,FALSE);
1222 wave_out_test_deviceOut(device,1.0,5,1,&wfex.Format,0,CALLBACK_EVENT,
1223 &capsA,winetest_interactive,TRUE,FALSE);
1225 trace("waveOutOpen(%s): 4 channels not supported\n",
1228 /* test if 6 channels supported */
1229 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1230 wfex.Format.nChannels=6;
1231 wfex.Format.wBitsPerSample=16;
1232 wfex.Format.nSamplesPerSec=22050;
1233 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1234 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1235 wfex.Format.nBlockAlign;
1236 wfex.Format.cbSize=22;
1237 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1238 wfex.dwChannelMask=SPEAKER_ALL;
1239 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
1240 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1241 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1242 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1243 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1244 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1245 if (rc==MMSYSERR_NOERROR) {
1247 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,WAVE_FORMAT_2M16,
1248 CALLBACK_EVENT,&capsA,winetest_interactive,
1250 wave_out_test_deviceOut(device,1.0,10,0,&wfex.Format,WAVE_FORMAT_2M16,
1251 CALLBACK_EVENT,&capsA,winetest_interactive,
1253 wave_out_test_deviceOut(device,1.0,5,1,&wfex.Format,WAVE_FORMAT_2M16,
1254 CALLBACK_EVENT,&capsA,winetest_interactive,
1257 trace("waveOutOpen(%s): 6 channels not supported\n",
1260 #if 0 /* ALSA doesn't like this format */
1261 /* test if 24 bit samples supported */
1262 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1263 wfex.Format.nChannels=2;
1264 wfex.Format.wBitsPerSample=24;
1265 wfex.Format.nSamplesPerSec=22050;
1266 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1267 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1268 wfex.Format.nBlockAlign;
1269 wfex.Format.cbSize=22;
1270 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1271 wfex.dwChannelMask=SPEAKER_ALL;
1272 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
1273 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1274 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1275 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1276 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1277 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1278 if (rc==MMSYSERR_NOERROR) {
1280 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,WAVE_FORMAT_2M16,
1281 CALLBACK_EVENT,&capsA,winetest_interactive,
1284 trace("waveOutOpen(%s): 24 bit samples not supported\n",
1288 /* test if 32 bit samples supported */
1289 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1290 wfex.Format.nChannels=2;
1291 wfex.Format.wBitsPerSample=32;
1292 wfex.Format.nSamplesPerSec=22050;
1293 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1294 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1295 wfex.Format.nBlockAlign;
1296 wfex.Format.cbSize=22;
1297 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1298 wfex.dwChannelMask=SPEAKER_ALL;
1299 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_PCM;
1300 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1301 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1302 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1303 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1304 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1305 if (rc==MMSYSERR_NOERROR) {
1307 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,WAVE_FORMAT_2M16,
1308 CALLBACK_EVENT,&capsA,winetest_interactive,
1310 wave_out_test_deviceOut(device,1.0,10,0,&wfex.Format,WAVE_FORMAT_2M16,
1311 CALLBACK_EVENT,&capsA,winetest_interactive,
1313 wave_out_test_deviceOut(device,1.0,5,1,&wfex.Format,WAVE_FORMAT_2M16,
1314 CALLBACK_EVENT,&capsA,winetest_interactive,
1317 trace("waveOutOpen(%s): 32 bit samples not supported\n",
1320 /* test if 32 bit float samples supported */
1321 wfex.Format.wFormatTag=WAVE_FORMAT_EXTENSIBLE;
1322 wfex.Format.nChannels=2;
1323 wfex.Format.wBitsPerSample=32;
1324 wfex.Format.nSamplesPerSec=22050;
1325 wfex.Format.nBlockAlign=wfex.Format.nChannels*wfex.Format.wBitsPerSample/8;
1326 wfex.Format.nAvgBytesPerSec=wfex.Format.nSamplesPerSec*
1327 wfex.Format.nBlockAlign;
1328 wfex.Format.cbSize=22;
1329 wfex.Samples.wValidBitsPerSample=wfex.Format.wBitsPerSample;
1330 wfex.dwChannelMask=SPEAKER_ALL;
1331 wfex.SubFormat=KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
1332 rc=waveOutOpen(&wout,device,&wfex.Format,0,0,
1333 CALLBACK_NULL|WAVE_FORMAT_DIRECT);
1334 ok(rc==MMSYSERR_NOERROR || rc==WAVERR_BADFORMAT ||
1335 rc==MMSYSERR_INVALFLAG || rc==MMSYSERR_INVALPARAM,
1336 "waveOutOpen(%s): returned %s\n",dev_name(device),wave_out_error(rc));
1337 if (rc==MMSYSERR_NOERROR) {
1339 wave_out_test_deviceOut(device,1.0,1,0,&wfex.Format,WAVE_FORMAT_2M16,
1340 CALLBACK_EVENT,&capsA,winetest_interactive,
1342 wave_out_test_deviceOut(device,1.0,10,0,&wfex.Format,WAVE_FORMAT_2M16,
1343 CALLBACK_EVENT,&capsA,winetest_interactive,
1345 wave_out_test_deviceOut(device,1.0,5,1,&wfex.Format,WAVE_FORMAT_2M16,
1346 CALLBACK_EVENT,&capsA,winetest_interactive,
1349 trace("waveOutOpen(%s): 32 bit float samples not supported\n",
1353 static void wave_out_tests(void)
1357 WAVEFORMATEX format;
1362 ndev=waveOutGetNumDevs();
1363 trace("found %d WaveOut devices\n",ndev);
1365 rc=waveOutGetDevCapsA(ndev+1,&capsA,sizeof(capsA));
1366 ok(rc==MMSYSERR_BADDEVICEID,
1367 "waveOutGetDevCapsA(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
1368 dev_name(ndev+1),mmsys_error(rc));
1370 rc=waveOutGetDevCapsW(ndev+1,&capsW,sizeof(capsW));
1371 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NOTSUPPORTED,
1372 "waveOutGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NOTSUPPORTED "
1373 "expected, got %s\n",dev_name(ndev+1),mmsys_error(rc));
1375 rc=waveOutGetDevCapsA(WAVE_MAPPER,&capsA,sizeof(capsA));
1377 ok(rc==MMSYSERR_NOERROR,
1378 "waveOutGetDevCapsA(%s): MMSYSERR_NOERROR expected, got %s\n",
1379 dev_name(WAVE_MAPPER),mmsys_error(rc));
1381 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER,
1382 "waveOutGetDevCapsA(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
1383 "expected, got %s\n",dev_name(WAVE_MAPPER),mmsys_error(rc));
1385 rc=waveOutGetDevCapsW(WAVE_MAPPER,&capsW,sizeof(capsW));
1387 ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_NOTSUPPORTED,
1388 "waveOutGetDevCapsW(%s): MMSYSERR_NOERROR or MMSYSERR_NOTSUPPORTED "
1389 "expected, got %s\n",dev_name(WAVE_MAPPER),mmsys_error(rc));
1391 ok(rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NODRIVER ||
1392 rc==MMSYSERR_NOTSUPPORTED,
1393 "waveOutGetDevCapsW(%s): MMSYSERR_BADDEVICEID or MMSYSERR_NODRIVER "
1394 " or MMSYSERR_NOTSUPPORTED expected, got %s\n",
1395 dev_name(WAVE_MAPPER),mmsys_error(rc));
1397 format.wFormatTag=WAVE_FORMAT_PCM;
1399 format.wBitsPerSample=16;
1400 format.nSamplesPerSec=44100;
1401 format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
1402 format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
1404 rc=waveOutOpen(&wout,ndev+1,&format,0,0,CALLBACK_NULL);
1405 ok(rc==MMSYSERR_BADDEVICEID,
1406 "waveOutOpen(%s): MMSYSERR_BADDEVICEID expected, got %s\n",
1407 dev_name(ndev+1),mmsys_error(rc));
1409 for (d=0;d<ndev;d++)
1410 wave_out_test_device(d);
1413 wave_out_test_device(WAVE_MAPPER);