2 * Unit tests for dsound functions
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
24 #include "wine/test.h"
25 #include "wine/debug.h"
31 static const unsigned int formats
[][3]={
57 #define NB_FORMATS (sizeof(formats)/sizeof(*formats))
59 /* The time slice determines how often we will service the buffer and the
60 * buffer will be four time slices long
62 #define TIME_SLICE 100
63 #define BUFFER_LEN (4*TIME_SLICE)
64 #define TONE_DURATION (6*TIME_SLICE)
66 /* This test can play a test tone. But this only makes sense if someone
67 * is going to carefully listen to it, and would only bother everyone else.
68 * So this is only done if the test is being run in interactive mode.
71 #define PI 3.14159265358979323846
72 static char* wave_generate_la(WAVEFORMATEX
* wfx
, double duration
, DWORD
* size
)
79 nb_samples
=(int)(duration
*wfx
->nSamplesPerSec
);
80 *size
=nb_samples
*wfx
->nBlockAlign
;
82 for (i
=0;i
<nb_samples
;i
++) {
83 double y
=sin(440.0*2*PI
*i
/wfx
->nSamplesPerSec
);
84 if (wfx
->wBitsPerSample
==8) {
85 unsigned char sample
=(unsigned char)((double)127.5*(y
+1.0));
87 if (wfx
->nChannels
==2)
90 signed short sample
=(signed short)((double)32767.5*y
-0.5);
94 if (wfx
->nChannels
==2) {
104 static HWND
get_hwnd()
106 HWND hwnd
=GetForegroundWindow();
108 hwnd
=GetDesktopWindow();
112 static void init_format(WAVEFORMATEX
* wfx
, int rate
, int depth
, int channels
)
114 wfx
->wFormatTag
=WAVE_FORMAT_PCM
;
115 wfx
->nChannels
=channels
;
116 wfx
->wBitsPerSample
=depth
;
117 wfx
->nSamplesPerSec
=rate
;
118 wfx
->nBlockAlign
=wfx
->nChannels
*wfx
->wBitsPerSample
/8;
119 wfx
->nAvgBytesPerSec
=wfx
->nSamplesPerSec
*wfx
->nBlockAlign
;
127 LPDIRECTSOUNDBUFFER dsbo
;
136 static int buffer_refill(play_state_t
* state
, DWORD size
)
142 if (size
>state
->wave_len
-state
->written
)
143 size
=state
->wave_len
-state
->written
;
145 rc
=IDirectSoundBuffer_Lock(state
->dsbo
,state
->offset
,size
,
146 &ptr1
,&len1
,&ptr2
,&len2
,0);
147 ok(rc
==DS_OK
,"Lock: 0x%lx",rc
);
151 memcpy(ptr1
,state
->wave
+state
->written
,len1
);
152 state
->written
+=len1
;
154 memcpy(ptr2
,state
->wave
+state
->written
,len2
);
155 state
->written
+=len2
;
157 state
->offset
=state
->written
% state
->buffer_size
;
158 rc
=IDirectSoundBuffer_Unlock(state
->dsbo
,ptr1
,len1
,ptr2
,len2
);
159 ok(rc
==DS_OK
,"Unlock: 0x%lx",rc
);
165 static int buffer_silence(play_state_t
* state
, DWORD size
)
172 rc
=IDirectSoundBuffer_Lock(state
->dsbo
,state
->offset
,size
,
173 &ptr1
,&len1
,&ptr2
,&len2
,0);
174 ok(rc
==DS_OK
,"Lock: 0x%lx",rc
);
178 s
=(state
->wfx
->wBitsPerSample
==8?0x80:0);
183 state
->offset
=(state
->offset
+size
) % state
->buffer_size
;
184 rc
=IDirectSoundBuffer_Unlock(state
->dsbo
,ptr1
,len1
,ptr2
,len2
);
185 ok(rc
==DS_OK
,"Unlock: 0x%lx",rc
);
191 static int buffer_service(play_state_t
* state
)
193 DWORD play_pos
,write_pos
,buf_free
;
196 rc
=IDirectSoundBuffer_GetCurrentPosition(state
->dsbo
,&play_pos
,&write_pos
);
197 ok(rc
==DS_OK
,"GetCurrentPosition: %lx",rc
);
202 /* Refill the buffer */
203 if (state
->offset
<=play_pos
) {
204 buf_free
=play_pos
-state
->offset
;
206 buf_free
=state
->buffer_size
-state
->offset
+play_pos
;
208 if (winetest_debug
> 1)
209 trace("buf pos=%ld free=%ld written=%ld / %ld\n",
210 play_pos
,buf_free
,state
->written
,state
->wave_len
);
214 if (state
->written
<state
->wave_len
) {
215 int w
=buffer_refill(state
,buf_free
);
219 if (state
->written
==state
->wave_len
) {
220 state
->last_pos
=(state
->offset
<play_pos
)?play_pos
:0;
221 if (winetest_debug
> 1)
222 trace("last sound byte at %ld\n",
223 (state
->written
% state
->buffer_size
));
226 if (state
->last_pos
!=0 && play_pos
<state
->last_pos
) {
227 /* We wrapped around the end of the buffer */
230 if (state
->last_pos
==0 &&
231 play_pos
>(state
->written
% state
->buffer_size
)) {
232 /* Now everything has been played */
238 /* Fill with silence */
239 if (winetest_debug
> 1)
240 trace("writing %ld bytes of silence\n",buf_free
);
241 if (buffer_silence(state
,buf_free
)==-1)
247 if (winetest_debug
> 1)
248 trace("stopping playback\n");
249 rc
=IDirectSoundBuffer_Stop(state
->dsbo
);
250 ok(rc
==DS_OK
,"Stop failed: rc=%ld",rc
);
254 static void test_buffer(LPDIRECTSOUND dso
, LPDIRECTSOUNDBUFFER dsbo
,
255 int primary
, int play
)
259 WAVEFORMATEX wfx
,wfx2
;
260 DWORD size
,status
,freq
;
263 rc
=IDirectSoundBuffer_GetCaps(dsbo
,&dsbcaps
);
264 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: 0x%lx\n",rc
);
266 dsbcaps
.dwSize
=sizeof(dsbcaps
);
267 rc
=IDirectSoundBuffer_GetCaps(dsbo
,&dsbcaps
);
268 ok(rc
==DS_OK
,"GetCaps failed: 0x%lx\n",rc
);
270 trace(" Caps: flags=0x%08lx size=%ld\n",dsbcaps
.dwFlags
,
271 dsbcaps
.dwBufferBytes
);
274 /* Query the format size. Note that it may not match sizeof(wfx) */
276 rc
=IDirectSoundBuffer_GetFormat(dsbo
,NULL
,0,&size
);
277 ok(rc
==DS_OK
&& size
!=0,
278 "GetFormat should have returned the needed size: rc=0x%lx size=%ld\n",
281 rc
=IDirectSoundBuffer_GetFormat(dsbo
,&wfx
,sizeof(wfx
),NULL
);
282 ok(rc
==DS_OK
,"GetFormat failed: 0x%lx\n",rc
);
284 trace(" tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
285 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
286 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
289 rc
=IDirectSoundBuffer_GetFrequency(dsbo
,&freq
);
290 ok(rc
==DS_OK
|| rc
==DSERR_CONTROLUNAVAIL
,"GetFrequency failed: 0x%lx\n",rc
);
292 ok(freq
==wfx
.nSamplesPerSec
,
293 "The frequency returned by GetFrequency %ld does not match the format %ld\n",
294 freq
,wfx
.nSamplesPerSec
);
297 rc
=IDirectSoundBuffer_GetStatus(dsbo
,&status
);
298 ok(rc
==DS_OK
,"GetStatus failed: 0x%lx\n",rc
);
300 trace(" status=0x%04lx\n",status
);
304 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
305 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
306 ok(rc
==DS_OK
,"SetCooperativeLevel failed: 0x%lx\n",rc
);
310 init_format(&wfx2
,11025,16,2);
311 rc
=IDirectSoundBuffer_SetFormat(dsbo
,&wfx2
);
312 ok(rc
==DS_OK
,"SetFormat failed: 0x%lx\n",rc
);
314 /* There is no garantee that SetFormat will actually change the
315 * format to what we asked for. It depends on what the soundcard
316 * supports. So we must re-query the format.
318 rc
=IDirectSoundBuffer_GetFormat(dsbo
,&wfx
,sizeof(wfx
),NULL
);
319 ok(rc
==DS_OK
,"GetFormat failed: 0x%lx\n",rc
);
321 trace(" tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
322 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
323 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
326 /* Set the CooperativeLevel back to normal */
327 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
328 ok(rc
==DS_OK
,"SetCooperativeLevel failed: 0x%lx\n",rc
);
335 trace(" Playing 440Hz LA at %ldx%2dx%d\n",
336 wfx
.nSamplesPerSec
, wfx
.wBitsPerSample
,wfx
.nChannels
);
339 /* We must call SetCooperativeLevel to be allowed to call Lock */
340 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_WRITEPRIMARY
);
341 ok(rc
==DS_OK
,"SetCooperativeLevel failed: 0x%lx\n",rc
);
346 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLVOLUME
) {
347 rc
=IDirectSoundBuffer_GetVolume(dsbo
,&volume
);
348 ok(rc
==DS_OK
,"GetVolume failed: 0x%lx\n",rc
);
350 rc
=IDirectSoundBuffer_SetVolume(dsbo
,-300);
351 ok(rc
==DS_OK
,"SetVolume failed: 0x%lx\n",rc
);
353 rc
=IDirectSoundBuffer_GetVolume(dsbo
,&volume
);
354 ok(rc
==DS_OK
,"GetVolume failed: 0x%lx\n",rc
);
356 trace(" volume=%ld\n",volume
);
359 state
.wave
=wave_generate_la(&wfx
,((double)TONE_DURATION
)/1000,&state
.wave_len
);
363 state
.buffer_size
=dsbcaps
.dwBufferBytes
;
364 state
.written
=state
.offset
=0;
365 buffer_refill(&state
,state
.buffer_size
);
367 rc
=IDirectSoundBuffer_Play(dsbo
,0,0,DSBPLAY_LOOPING
);
368 ok(rc
==DS_OK
,"Play: 0x%lx\n",rc
);
370 rc
=IDirectSoundBuffer_GetStatus(dsbo
,&status
);
371 ok(rc
==DS_OK
,"GetStatus failed: 0x%lx\n",rc
);
372 ok(status
==(DSBSTATUS_PLAYING
|DSBSTATUS_LOOPING
),
373 "GetStatus: bad status: %lx",status
);
375 while (buffer_service(&state
)) {
376 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE
/2);
379 if (dsbcaps
.dwFlags
& DSBCAPS_CTRLVOLUME
) {
380 rc
=IDirectSoundBuffer_SetVolume(dsbo
,volume
);
381 ok(rc
==DS_OK
,"SetVolume failed: 0x%lx\n",rc
);
386 /* Set the CooperativeLevel back to normal */
387 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
388 ok(rc
==DS_OK
,"SetCooperativeLevel failed: 0x%lx\n",rc
);
393 static BOOL WINAPI
dsenum_callback(LPGUID lpGuid
, LPCSTR lpcstrDescription
,
394 LPCSTR lpcstrModule
, LPVOID lpContext
)
397 LPDIRECTSOUND dso
=NULL
;
398 LPDIRECTSOUNDBUFFER dsbo
=NULL
;
399 DSBUFFERDESC bufdesc
;
404 trace("Testing %s - %s : %s\n",lpcstrDescription
,lpcstrModule
,wine_dbgstr_guid(lpGuid
));
405 rc
=DirectSoundCreate(lpGuid
,&dso
,NULL
);
406 ok(rc
==DS_OK
,"DirectSoundCreate failed: 0x%lx\n",rc
);
411 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
412 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: 0x%lx\n",rc
);
414 dscaps
.dwSize
=sizeof(dscaps
);
415 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
416 ok(rc
==DS_OK
,"GetCaps failed: 0x%lx\n",rc
);
418 trace(" DirectSound Caps: flags=0x%08lx secondary min=%ld max=%ld\n",
419 dscaps
.dwFlags
,dscaps
.dwMinSecondarySampleRate
,
420 dscaps
.dwMaxSecondarySampleRate
);
423 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
424 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
425 ok(rc
==DS_OK
,"SetCooperativeLevel failed: 0x%lx\n",rc
);
429 /* Testing the primary buffer */
430 bufdesc
.dwSize
=sizeof(bufdesc
);
431 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
432 bufdesc
.dwBufferBytes
=0;
433 bufdesc
.dwReserved
=0;
434 bufdesc
.lpwfxFormat
=NULL
;
435 trace(" Testing the primary buffer\n");
436 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&dsbo
,NULL
);
437 ok(rc
==DS_OK
,"CreateSoundBuffer failed to create a primary buffer 0x%lx\n",rc
);
439 test_buffer(dso
,dsbo
,1,winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
));
440 IDirectSoundBuffer_Release(dsbo
);
443 /* Set the CooperativeLevel back to normal */
444 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
445 ok(rc
==DS_OK
,"SetCooperativeLevel failed: 0x%lx\n",rc
);
449 /* Testing secondary buffers */
450 for (f
=0;f
<NB_FORMATS
;f
++) {
451 init_format(&wfx
,formats
[f
][0],formats
[f
][1],formats
[f
][2]);
452 bufdesc
.dwSize
=sizeof(bufdesc
);
453 bufdesc
.dwFlags
=DSBCAPS_CTRLDEFAULT
|DSBCAPS_GETCURRENTPOSITION2
;
454 bufdesc
.dwBufferBytes
=wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000;
455 bufdesc
.dwReserved
=0;
456 bufdesc
.lpwfxFormat
=&wfx
;
457 trace(" Testing a secondary buffer at %ldx%dx%d\n",
458 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
);
459 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&dsbo
,NULL
);
460 ok(rc
==DS_OK
,"CreateSoundBuffer failed to create a secondary buffer 0x%lx\n",rc
);
462 test_buffer(dso
,dsbo
,0,winetest_interactive
);
463 IDirectSoundBuffer_Release(dsbo
);
469 IDirectSound_Release(dso
);
473 static void dsound_out_tests()
476 rc
=DirectSoundEnumerateA(&dsenum_callback
,NULL
);
477 ok(rc
==DS_OK
,"DirectSoundEnumerate failed: %ld\n",rc
);
480 #define NOTIFICATIONS 5
486 LPDIRECTSOUNDCAPTUREBUFFER dscbo
;
488 DSBPOSITIONNOTIFY posnotify
[NOTIFICATIONS
];
490 LPDIRECTSOUNDNOTIFY notify
;
500 static int capture_buffer_service(capture_state_t
* state
)
505 DWORD capture_pos
,read_pos
;
507 rc
=IDirectSoundCaptureBuffer_GetCurrentPosition(state
->dscbo
,&capture_pos
,&read_pos
);
508 ok(rc
==DS_OK
,"GetCurrentPosition failed: 0x%lx\n",rc
);
512 rc
=IDirectSoundCaptureBuffer_Lock(state
->dscbo
,state
->offset
,state
->size
,&ptr1
,&len1
,&ptr2
,&len2
,0);
513 ok(rc
==DS_OK
,"Lock failed: 0x%lx\n",rc
);
517 rc
=IDirectSoundCaptureBuffer_Unlock(state
->dscbo
,ptr1
,len1
,ptr2
,len2
);
518 ok(rc
==DS_OK
,"Unlock failed: 0x%lx\n",rc
);
522 state
->offset
= (state
->offset
+ state
->size
) % state
->buffer_size
;
527 static void test_capture_buffer(LPDIRECTSOUNDCAPTURE dsco
, LPDIRECTSOUNDCAPTUREBUFFER dscbo
)
533 capture_state_t state
;
536 /* Private dsound.dll: Error: Invalid caps pointer */
537 rc
=IDirectSoundCaptureBuffer_GetCaps(dscbo
,0);
538 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: 0x%lx\n",rc
);
540 /* Private dsound.dll: Error: Invalid caps pointer */
542 rc
=IDirectSoundCaptureBuffer_GetCaps(dscbo
,&dscbcaps
);
543 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: 0x%lx\n",rc
);
545 dscbcaps
.dwSize
=sizeof(dscbcaps
);
546 rc
=IDirectSoundCaptureBuffer_GetCaps(dscbo
,&dscbcaps
);
547 ok(rc
==DS_OK
,"GetCaps failed: 0x%lx\n",rc
);
549 trace(" Caps: size = %ld flags=0x%08lx buffer size=%ld\n",
550 dscbcaps
.dwSize
,dscbcaps
.dwFlags
,dscbcaps
.dwBufferBytes
);
553 /* Query the format size. Note that it may not match sizeof(wfx) */
554 /* Private dsound.dll: Error: Either pwfxFormat or pdwSizeWritten must be non-NULL */
555 rc
=IDirectSoundCaptureBuffer_GetFormat(dscbo
,NULL
,0,NULL
);
556 ok(rc
==DSERR_INVALIDPARAM
,
557 "GetFormat should have returned an error: rc=0x%lx\n",rc
);
560 rc
=IDirectSoundCaptureBuffer_GetFormat(dscbo
,NULL
,0,&size
);
561 ok(rc
==DS_OK
&& size
!=0,
562 "GetFormat should have returned the needed size: rc=0x%lx size=%ld\n",
565 rc
=IDirectSoundCaptureBuffer_GetFormat(dscbo
,&wfx
,sizeof(wfx
),NULL
);
566 ok(rc
==DS_OK
,"GetFormat failed: 0x%lx\n",rc
);
568 trace(" tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
569 wfx
.wFormatTag
,wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,
570 wfx
.nChannels
,wfx
.nAvgBytesPerSec
,wfx
.nBlockAlign
);
573 /* Private dsound.dll: Error: Invalid status pointer */
574 rc
=IDirectSoundCaptureBuffer_GetStatus(dscbo
,0);
575 ok(rc
==DSERR_INVALIDPARAM
,"GetStatus should have failed: 0x%lx\n",rc
);
577 rc
=IDirectSoundCaptureBuffer_GetStatus(dscbo
,&status
);
578 ok(rc
==DS_OK
,"GetStatus failed: 0x%lx\n",rc
);
580 trace(" status=0x%04lx\n",status
);
583 ZeroMemory(&state
, sizeof(state
));
586 state
.buffer_size
= dscbcaps
.dwBufferBytes
;
587 state
.event
= CreateEvent( NULL
, FALSE
, FALSE
, NULL
);
588 state
.size
= dscbcaps
.dwBufferBytes
/ NOTIFICATIONS
;
590 rc
=IDirectSoundCapture_QueryInterface(dscbo
,&IID_IDirectSoundNotify
,(void **)&(state
.notify
));
591 ok(rc
==DS_OK
,"QueryInterface failed: 0x%lx\n",rc
);
595 for (i
= 0; i
< NOTIFICATIONS
; i
++) {
596 state
.posnotify
[i
].dwOffset
= (i
* state
.size
) + state
.size
- 1;
597 state
.posnotify
[i
].hEventNotify
= state
.event
;
600 rc
=IDirectSoundNotify_SetNotificationPositions(state
.notify
,NOTIFICATIONS
,state
.posnotify
);
601 ok(rc
==DS_OK
,"SetNotificationPositions failed: 0x%lx\n",rc
);
605 rc
=IDirectSoundCaptureBuffer_Start(dscbo
,DSCBSTART_LOOPING
);
606 ok(rc
==DS_OK
,"Start: 0x%lx\n",rc
);
610 rc
=IDirectSoundCaptureBuffer_GetStatus(dscbo
,&status
);
611 ok(rc
==DS_OK
,"GetStatus failed: 0x%lx\n",rc
);
612 ok(status
==(DSCBSTATUS_CAPTURING
|DSCBSTATUS_LOOPING
),
613 "GetStatus: bad status: %lx",status
);
617 /* wait for the notifications */
618 for (i
= 0; i
< (NOTIFICATIONS
* 2); i
++) {
619 rc
=MsgWaitForMultipleObjects( 1, &(state
.event
), FALSE
, 1000, QS_ALLEVENTS
);
620 ok(rc
==WAIT_OBJECT_0
,"MsgWaitForMultipleObjects failed: 0x%lx\n",rc
);
621 if (rc
!=WAIT_OBJECT_0
)
623 if (!capture_buffer_service(&state
))
627 rc
=IDirectSoundCaptureBuffer_Stop(dscbo
);
628 ok(rc
==DS_OK
,"Stop: 0x%lx\n",rc
);
632 rc
=IDirectSoundNotify_Release(state
.notify
);
633 ok(rc
==0,"Release: 0x%lx\n",rc
);
638 static BOOL WINAPI
dscenum_callback(LPGUID lpGuid
, LPCSTR lpcstrDescription
,
639 LPCSTR lpcstrModule
, LPVOID lpContext
)
642 LPDIRECTSOUNDCAPTURE dsco
=NULL
;
643 LPDIRECTSOUNDCAPTUREBUFFER dscbo
=NULL
;
644 DSCBUFFERDESC bufdesc
;
649 /* Private dsound.dll: Error: Invalid interface buffer */
650 trace("Testing %s - %s : %s\n",lpcstrDescription
,lpcstrModule
,wine_dbgstr_guid(lpGuid
));
651 rc
=DirectSoundCaptureCreate(lpGuid
,NULL
,NULL
);
652 ok(rc
==DSERR_INVALIDPARAM
,"DirectSoundCaptureCreate didn't fail: 0x%lx\n",rc
);
654 IDirectSoundCapture_Release(dsco
);
656 rc
=DirectSoundCaptureCreate(lpGuid
,&dsco
,NULL
);
657 ok((rc
==DS_OK
)||(rc
==DSERR_NODRIVER
),"DirectSoundCaptureCreate failed: 0x%lx\n",rc
);
661 /* Private dsound.dll: Error: Invalid caps buffer */
662 rc
=IDirectSoundCapture_GetCaps(dsco
,NULL
);
663 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: 0x%lx\n",rc
);
665 /* Private dsound.dll: Error: Invalid caps buffer */
667 rc
=IDirectSoundCapture_GetCaps(dsco
,&dsccaps
);
668 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: 0x%lx\n",rc
);
670 dsccaps
.dwSize
=sizeof(dsccaps
);
671 rc
=IDirectSoundCapture_GetCaps(dsco
,&dsccaps
);
672 ok(rc
==DS_OK
,"GetCaps failed: 0x%lx\n",rc
);
674 trace(" DirectSoundCapture Caps: size=%ld flags=0x%08lx formats=%ld channels=%ld\n",
675 dsccaps
.dwSize
,dsccaps
.dwFlags
,dsccaps
.dwFormats
,dsccaps
.dwChannels
);
678 /* Private dsound.dll: Error: Invalid size */
679 /* Private dsound.dll: Error: Invalid capture buffer description */
680 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
683 bufdesc
.dwBufferBytes
=0;
684 bufdesc
.dwReserved
=0;
685 bufdesc
.lpwfxFormat
=NULL
;
686 rc
=IDirectSoundCapture_CreateCaptureBuffer(dsco
,&bufdesc
,&dscbo
,NULL
);
687 ok(rc
==DSERR_INVALIDPARAM
,"CreateCaptureBuffer should have failed to create a capture buffer 0x%lx\n",rc
);
689 IDirectSoundCaptureBuffer_Release(dscbo
);
692 /* Private dsound.dll: Error: Invalid buffer size */
693 /* Private dsound.dll: Error: Invalid capture buffer description */
694 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
695 bufdesc
.dwSize
=sizeof(bufdesc
);
697 bufdesc
.dwBufferBytes
=0;
698 bufdesc
.dwReserved
=0;
699 bufdesc
.lpwfxFormat
=NULL
;
700 rc
=IDirectSoundCapture_CreateCaptureBuffer(dsco
,&bufdesc
,&dscbo
,NULL
);
701 ok(rc
==DSERR_INVALIDPARAM
,"CreateCaptureBuffer should have failed to create a capture buffer 0x%lx\n",rc
);
703 IDirectSoundCaptureBuffer_Release(dscbo
);
706 /* Private dsound.dll: Error: Invalid buffer size */
707 /* Private dsound.dll: Error: Invalid capture buffer description */
708 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
709 ZeroMemory(&wfx
, sizeof(wfx
));
710 bufdesc
.dwSize
=sizeof(bufdesc
);
712 bufdesc
.dwBufferBytes
=0;
713 bufdesc
.dwReserved
=0;
714 bufdesc
.lpwfxFormat
=&wfx
;
715 rc
=IDirectSoundCapture_CreateCaptureBuffer(dsco
,&bufdesc
,&dscbo
,NULL
);
716 ok(rc
==DSERR_INVALIDPARAM
,"CreateCaptureBuffer should have failed to create a capture buffer 0x%lx\n",rc
);
718 IDirectSoundCaptureBuffer_Release(dscbo
);
721 /* Private dsound.dll: Error: Invalid buffer size */
722 /* Private dsound.dll: Error: Invalid capture buffer description */
723 init_format(&wfx
,11025,8,1);
724 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
725 bufdesc
.dwSize
=sizeof(bufdesc
);
727 bufdesc
.dwBufferBytes
=0;
728 bufdesc
.dwReserved
=0;
729 bufdesc
.lpwfxFormat
=&wfx
;
730 rc
=IDirectSoundCapture_CreateCaptureBuffer(dsco
,&bufdesc
,&dscbo
,NULL
);
731 ok(rc
==DSERR_INVALIDPARAM
,"CreateCaptureBuffer should have failed to create a capture buffer 0x%lx\n",rc
);
733 IDirectSoundCaptureBuffer_Release(dscbo
);
736 for (f
=0;f
<NB_FORMATS
;f
++) {
737 init_format(&wfx
,formats
[f
][0],formats
[f
][1],formats
[f
][2]);
738 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
739 bufdesc
.dwSize
=sizeof(bufdesc
);
741 bufdesc
.dwBufferBytes
=wfx
.nAvgBytesPerSec
;
742 bufdesc
.dwReserved
=0;
743 bufdesc
.lpwfxFormat
=&wfx
;
744 trace(" Testing the capture buffer at %ldx%dx%d\n",
745 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
);
746 rc
=IDirectSoundCapture_CreateCaptureBuffer(dsco
,&bufdesc
,&dscbo
,NULL
);
747 ok(rc
==DS_OK
,"CreateCaptureBuffer failed to create a capture buffer 0x%lx\n",rc
);
749 test_capture_buffer(dsco
, dscbo
);
750 IDirectSoundCaptureBuffer_Release(dscbo
);
754 /* Try an invalid format to test error handling */
756 init_format(&wfx
,2000000,16,2);
757 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
758 bufdesc
.dwSize
=sizeof(bufdesc
);
759 bufdesc
.dwFlags
=DSCBCAPS_WAVEMAPPED
;
760 bufdesc
.dwBufferBytes
=wfx
.nAvgBytesPerSec
;
761 bufdesc
.dwReserved
=0;
762 bufdesc
.lpwfxFormat
=&wfx
;
763 trace(" Testing the capture buffer at %ldx%dx%d\n",
764 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
);
765 rc
=IDirectSoundCapture_CreateCaptureBuffer(dsco
,&bufdesc
,&dscbo
,NULL
);
766 ok(rc
!=DS_OK
,"CreateCaptureBuffer should have failed at 2 MHz 0x%lx\n",rc
);
771 IDirectSoundCapture_Release(dsco
);
776 static void dsound_in_tests()
779 rc
=DirectSoundCaptureEnumerateA(&dscenum_callback
,NULL
);
780 ok(rc
==DS_OK
,"DirectSoundCaptureEnumerate failed: %ld\n",rc
);