3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2002 TransGaming Technologies, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <sys/types.h>
26 #include <sys/fcntl.h>
32 #include <math.h> /* Insomnia - pow() function */
42 #include "wine/windef16.h"
43 #include "wine/debug.h"
46 #include "dsound_private.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
50 static HRESULT mmErr(UINT err)
53 case MMSYSERR_NOERROR:
55 case MMSYSERR_ALLOCATED:
56 return DSERR_ALLOCATED;
57 case MMSYSERR_INVALHANDLE:
58 return DSERR_GENERIC; /* FIXME */
59 case MMSYSERR_NODRIVER:
60 return DSERR_NODRIVER;
62 return DSERR_OUTOFMEMORY;
63 case MMSYSERR_INVALPARAM:
64 return DSERR_INVALIDPARAM;
66 FIXME("Unknown MMSYS error %d\n",err);
71 void DSOUND_RecalcPrimary(IDirectSoundImpl *This)
75 sw = This->wfx.nChannels * (This->wfx.wBitsPerSample / 8);
78 /* let fragment size approximate the timer delay */
79 fraglen = (This->wfx.nSamplesPerSec * DS_TIME_DEL / 1000) * sw;
80 /* reduce fragment size until an integer number of them fits in the buffer */
81 /* (FIXME: this may or may not be a good idea) */
82 while (This->buflen % fraglen) fraglen -= sw;
83 This->fraglen = fraglen;
84 TRACE("fraglen=%ld\n", This->fraglen);
86 /* calculate the 10ms write lead */
87 This->writelead = (This->wfx.nSamplesPerSec / 100) * sw;
90 static HRESULT DSOUND_PrimaryOpen(IDirectSoundImpl *This)
94 /* are we using waveOut stuff? */
99 /* Start in pause mode, to allow buffers to get filled */
100 waveOutPause(This->hwo);
101 if (This->state == STATE_PLAYING) This->state = STATE_STARTING;
102 else if (This->state == STATE_STOPPING) This->state = STATE_STOPPED;
103 /* use fragments of 10ms (1/100s) each (which should get us within
104 * the documented write cursor lead of 10-15ms) */
105 buflen = ((This->wfx.nAvgBytesPerSec / 100) & ~3) * DS_HEL_FRAGS;
106 TRACE("desired buflen=%ld, old buffer=%p\n", buflen, This->buffer);
107 /* reallocate emulated primary buffer */
108 newbuf = (LPBYTE)HeapReAlloc(GetProcessHeap(),0,This->buffer,buflen);
109 if (newbuf == NULL) {
110 ERR("failed to allocate primary buffer\n");
111 merr = DSERR_OUTOFMEMORY;
112 /* but the old buffer might still exist and must be re-prepared */
114 This->buffer = newbuf;
115 This->buflen = buflen;
120 This->fraglen = This->buflen / DS_HEL_FRAGS;
122 /* prepare fragment headers */
123 for (c=0; c<DS_HEL_FRAGS; c++) {
124 This->pwave[c]->lpData = This->buffer + c*This->fraglen;
125 This->pwave[c]->dwBufferLength = This->fraglen;
126 This->pwave[c]->dwUser = (DWORD)This;
127 This->pwave[c]->dwFlags = 0;
128 This->pwave[c]->dwLoops = 0;
129 err = mmErr(waveOutPrepareHeader(This->hwo,This->pwave[c],sizeof(WAVEHDR)));
132 waveOutUnprepareHeader(This->hwo,This->pwave[c],sizeof(WAVEHDR));
140 memset(This->buffer, (This->wfx.wBitsPerSample == 16) ? 0 : 128, This->buflen);
141 TRACE("fraglen=%ld\n", This->fraglen);
142 DSOUND_WaveQueue(This, (DWORD)-1);
144 if ((err == DS_OK) && (merr != DS_OK))
151 static void DSOUND_PrimaryClose(IDirectSoundImpl *This)
153 /* are we using waveOut stuff? */
157 This->pwqueue = (DWORD)-1; /* resetting queues */
158 waveOutReset(This->hwo);
159 for (c=0; c<DS_HEL_FRAGS; c++)
160 waveOutUnprepareHeader(This->hwo, This->pwave[c], sizeof(WAVEHDR));
165 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This)
169 This->buflen = This->wfx.nAvgBytesPerSec;
171 /* FIXME: verify that hardware capabilities (DSCAPS_PRIMARY flags) match */
174 err = IDsDriver_CreateSoundBuffer(This->driver,&(This->wfx),
175 DSBCAPS_PRIMARYBUFFER,0,
176 &(This->buflen),&(This->buffer),
177 (LPVOID*)&(This->hwbuf));
180 /* Allocate memory for HEL buffer headers */
182 for (c=0; c<DS_HEL_FRAGS; c++) {
183 This->pwave[c] = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(WAVEHDR));
184 if (!This->pwave[c]) {
185 /* Argh, out of memory */
187 HeapFree(GetProcessHeap(),0,This->pwave[c]);
189 err=DSERR_OUTOFMEMORY;
195 err = DSOUND_PrimaryOpen(This);
198 /* calculate fragment size and write lead */
199 DSOUND_RecalcPrimary(This);
200 This->state = STATE_STOPPED;
204 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This)
206 DSOUND_PrimaryClose(This);
208 IDsDriverBuffer_Release(This->hwbuf);
211 for (c=0; c<DS_HEL_FRAGS; c++) {
212 HeapFree(GetProcessHeap(),0,This->pwave[c]);
218 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This)
222 err = IDsDriverBuffer_Play(This->hwbuf, 0, 0, DSBPLAY_LOOPING);
224 err = mmErr(waveOutRestart(This->hwo));
228 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This)
235 err = IDsDriverBuffer_Stop(This->hwbuf);
236 if (err == DSERR_BUFFERLOST) {
237 /* Wine-only: the driver wants us to reopen the device */
238 /* FIXME: check for errors */
239 IDsDriverBuffer_Release(This->hwbuf);
240 waveOutClose(This->hwo);
242 err = mmErr(waveOutOpen(&(This->hwo), This->drvdesc.dnDevNode,
243 &(This->wfx), (DWORD)DSOUND_callback, (DWORD)This,
244 CALLBACK_FUNCTION | WAVE_DIRECTSOUND));
246 err = IDsDriver_CreateSoundBuffer(This->driver,&(This->wfx),
247 DSBCAPS_PRIMARYBUFFER,0,
248 &(This->buflen),&(This->buffer),
249 (LPVOID)&(This->hwbuf));
253 err = mmErr(waveOutPause(This->hwo));
257 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos)
260 HRESULT err=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
266 mtime.wType = TIME_BYTES;
267 waveOutGetPosition(This->hwo, &mtime, sizeof(mtime));
268 mtime.u.cb = mtime.u.cb % This->buflen;
269 *playpos = mtime.u.cb;
272 /* the writepos should only be used by apps with WRITEPRIMARY priority,
273 * in which case our software mixer is disabled anyway */
274 *writepos = (This->pwplay + ds_hel_margin) * This->fraglen;
275 while (*writepos >= This->buflen)
276 *writepos -= This->buflen;
279 TRACE("playpos = %ld, writepos = %ld (%p, time=%ld)\n", playpos?*playpos:0, writepos?*writepos:0, This, GetTickCount());
284 /*******************************************************************************
287 /* This sets this format for the <em>Primary Buffer Only</em> */
288 /* See file:///cdrom/sdk52/docs/worddoc/dsound.doc page 120 */
289 static HRESULT WINAPI PrimaryBufferImpl_SetFormat(
290 LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX wfex
292 ICOM_THIS(PrimaryBufferImpl,iface);
293 IDirectSoundImpl* dsound = This->dsound;
294 IDirectSoundBufferImpl** dsb;
298 if (This->dsound->priolevel == DSSCL_NORMAL) {
299 TRACE("failed priority check!\n");
300 return DSERR_PRIOLEVELNEEDED;
303 /* Let's be pedantic! */
305 TRACE("wfex==NULL!\n");
306 return DSERR_INVALIDPARAM;
308 TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
309 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
310 wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
311 wfex->nAvgBytesPerSec, wfex->nBlockAlign,
312 wfex->wBitsPerSample, wfex->cbSize);
314 if ((wfex->wFormatTag != WAVE_FORMAT_PCM) ||
315 (wfex->nChannels < 1) || (wfex->nChannels > 2) ||
316 (wfex->nSamplesPerSec < 1) ||
317 ((wfex->wBitsPerSample != 8) && (wfex->wBitsPerSample != 16))) {
318 TRACE("unsupported format!\n");
319 return DSERR_INVALIDPARAM;
323 RtlAcquireResourceExclusive(&(dsound->lock), TRUE);
325 if (dsound->wfx.nSamplesPerSec != wfex->nSamplesPerSec) {
326 dsb = dsound->buffers;
327 for (i = 0; i < dsound->nrofbuffers; i++, dsb++) {
329 EnterCriticalSection(&((*dsb)->lock));
331 (*dsb)->freqAdjust = ((*dsb)->freq << DSOUND_FREQSHIFT) /
332 wfex->nSamplesPerSec;
334 LeaveCriticalSection(&((*dsb)->lock));
339 dsound->wfx.nSamplesPerSec = wfex->nSamplesPerSec;
340 dsound->wfx.nChannels = wfex->nChannels;
341 dsound->wfx.wBitsPerSample = wfex->wBitsPerSample;
342 dsound->wfx.nBlockAlign = dsound->wfx.wBitsPerSample / 8 * dsound->wfx.nChannels;
343 dsound->wfx.nAvgBytesPerSec =
344 dsound->wfx.nSamplesPerSec * dsound->wfx.nBlockAlign;
346 if (dsound->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMSETFORMAT) {
347 /* FIXME: check for errors */
348 DSOUND_PrimaryClose(dsound);
349 waveOutClose(dsound->hwo);
351 err = mmErr(waveOutOpen(&(dsound->hwo), dsound->drvdesc.dnDevNode,
352 &(dsound->wfx), (DWORD)DSOUND_callback, (DWORD)dsound,
353 CALLBACK_FUNCTION | WAVE_DIRECTSOUND));
355 DSOUND_PrimaryOpen(dsound);
358 err = IDsDriverBuffer_SetFormat(dsound->hwbuf, &(dsound->wfx));
359 if (err == DSERR_BUFFERLOST) {
360 /* Wine-only: the driver wants us to recreate the HW buffer */
361 IDsDriverBuffer_Release(dsound->hwbuf);
362 err = IDsDriver_CreateSoundBuffer(dsound->driver,&(dsound->wfx),
363 DSBCAPS_PRIMARYBUFFER,0,
364 &(dsound->buflen),&(dsound->buffer),
365 (LPVOID)&(dsound->hwbuf));
366 if (dsound->state == STATE_PLAYING) dsound->state = STATE_STARTING;
367 else if (dsound->state == STATE_STOPPING) dsound->state = STATE_STOPPED;
369 /* FIXME: should we set err back to DS_OK in all cases ? */
371 DSOUND_RecalcPrimary(dsound);
373 RtlReleaseResource(&(dsound->lock));
379 static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
380 LPDIRECTSOUNDBUFFER8 iface,LONG vol
382 ICOM_THIS(PrimaryBufferImpl,iface);
383 IDirectSoundImpl* dsound = This->dsound;
386 TRACE("(%p,%ld)\n",This,vol);
388 /* I'm not sure if we need this for primary buffer */
389 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME))
390 return DSERR_CONTROLUNAVAIL;
392 if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN))
393 return DSERR_INVALIDPARAM;
396 EnterCriticalSection(&(dsound->mixlock));
398 oldVol = dsound->volpan.lVolume;
399 dsound->volpan.lVolume = vol;
400 DSOUND_RecalcVolPan(&dsound->volpan);
404 IDsDriverBuffer_SetVolumePan(dsound->hwbuf, &(dsound->volpan));
407 #if 0 /* should we really do this? */
408 /* the DS volume ranges from 0 (max, 0dB attenuation) to -10000 (min, 100dB attenuation) */
409 /* the MM volume ranges from 0 to 0xffff in an unspecified logarithmic scale */
410 WORD cvol = 0xffff + vol*6 + vol/2;
411 DWORD vol = cvol | ((DWORD)cvol << 16)
412 waveOutSetVolume(dsound->hwo, vol);
417 LeaveCriticalSection(&(dsound->mixlock));
423 static HRESULT WINAPI PrimaryBufferImpl_GetVolume(
424 LPDIRECTSOUNDBUFFER8 iface,LPLONG vol
426 ICOM_THIS(PrimaryBufferImpl,iface);
427 TRACE("(%p,%p)\n",This,vol);
430 return DSERR_INVALIDPARAM;
432 *vol = This->dsound->volpan.lVolume;
436 static HRESULT WINAPI PrimaryBufferImpl_SetFrequency(
437 LPDIRECTSOUNDBUFFER8 iface,DWORD freq
439 ICOM_THIS(PrimaryBufferImpl,iface);
441 TRACE("(%p,%ld)\n",This,freq);
443 /* You cannot set the frequency of the primary buffer */
444 return DSERR_CONTROLUNAVAIL;
447 static HRESULT WINAPI PrimaryBufferImpl_Play(
448 LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
450 ICOM_THIS(PrimaryBufferImpl,iface);
451 IDirectSoundImpl* dsound = This->dsound;
453 TRACE("(%p,%08lx,%08lx,%08lx)\n",
454 This,reserved1,reserved2,flags
457 if (!(flags & DSBPLAY_LOOPING))
458 return DSERR_INVALIDPARAM;
461 EnterCriticalSection(&(dsound->mixlock));
463 if (dsound->state == STATE_STOPPED)
464 dsound->state = STATE_STARTING;
465 else if (dsound->state == STATE_STOPPING)
466 dsound->state = STATE_PLAYING;
468 LeaveCriticalSection(&(dsound->mixlock));
474 static HRESULT WINAPI PrimaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
476 ICOM_THIS(PrimaryBufferImpl,iface);
477 IDirectSoundImpl* dsound = This->dsound;
479 TRACE("(%p)\n",This);
482 EnterCriticalSection(&(dsound->mixlock));
484 if (dsound->state == STATE_PLAYING)
485 dsound->state = STATE_STOPPING;
486 else if (dsound->state == STATE_STARTING)
487 dsound->state = STATE_STOPPED;
489 LeaveCriticalSection(&(dsound->mixlock));
495 static DWORD WINAPI PrimaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface) {
496 ICOM_THIS(PrimaryBufferImpl,iface);
499 TRACE("(%p) ref was %ld, thread is %lx\n",This, This->ref, GetCurrentThreadId());
501 ref = InterlockedIncrement(&(This->ref));
503 FIXME("thread-safety alert! AddRef-ing with a zero refcount!\n");
507 static DWORD WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface) {
508 ICOM_THIS(PrimaryBufferImpl,iface);
511 TRACE("(%p) ref was %ld, thread is %lx\n",This, This->ref, GetCurrentThreadId());
513 ref = InterlockedDecrement(&(This->ref));
516 IDirectSound_Release((LPDIRECTSOUND)This->dsound);
520 HeapFree(GetProcessHeap(), 0, This->iks);
524 HeapFree(GetProcessHeap(),0,This);
529 static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(
530 LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
532 ICOM_THIS(PrimaryBufferImpl,iface);
533 IDirectSoundImpl* dsound = This->dsound;
535 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
536 DSOUND_PrimaryGetPosition(dsound, playpos, writepos);
538 if (dsound->state != STATE_STOPPED)
539 /* apply the documented 10ms lead to writepos */
540 *writepos += dsound->writelead;
541 while (*writepos >= dsound->buflen) *writepos -= dsound->buflen;
543 TRACE("playpos = %ld, writepos = %ld (%p, time=%ld)\n", playpos?*playpos:0, writepos?*writepos:0, This, GetTickCount());
547 static HRESULT WINAPI PrimaryBufferImpl_GetStatus(
548 LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
550 ICOM_THIS(PrimaryBufferImpl,iface);
551 TRACE("(%p,%p), thread is %lx\n",This,status,GetCurrentThreadId());
554 return DSERR_INVALIDPARAM;
557 if ((This->dsound->state == STATE_STARTING) ||
558 (This->dsound->state == STATE_PLAYING))
559 *status |= DSBSTATUS_PLAYING | DSBSTATUS_LOOPING;
561 TRACE("status=%lx\n", *status);
566 static HRESULT WINAPI PrimaryBufferImpl_GetFormat(
567 LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten
569 ICOM_THIS(PrimaryBufferImpl,iface);
570 TRACE("(%p,%p,%ld,%p)\n",This,lpwf,wfsize,wfwritten);
572 if (wfsize>sizeof(This->dsound->wfx))
573 wfsize = sizeof(This->dsound->wfx);
574 if (lpwf) { /* NULL is valid */
575 memcpy(lpwf,&(This->dsound->wfx),wfsize);
580 *wfwritten = sizeof(This->dsound->wfx);
582 return DSERR_INVALIDPARAM;
587 static HRESULT WINAPI PrimaryBufferImpl_Lock(
588 LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID lplpaudioptr1,LPDWORD audiobytes1,LPVOID lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
590 ICOM_THIS(PrimaryBufferImpl,iface);
591 IDirectSoundImpl* dsound = This->dsound;
593 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n",
605 if (dsound->priolevel != DSSCL_WRITEPRIMARY)
606 return DSERR_PRIOLEVELNEEDED;
608 if (flags & DSBLOCK_FROMWRITECURSOR) {
610 /* GetCurrentPosition does too much magic to duplicate here */
611 IDirectSoundBuffer_GetCurrentPosition(iface, NULL, &writepos);
612 writecursor += writepos;
614 while (writecursor >= dsound->buflen)
615 writecursor -= dsound->buflen;
616 if (flags & DSBLOCK_ENTIREBUFFER)
617 writebytes = dsound->buflen;
618 if (writebytes > dsound->buflen)
619 writebytes = dsound->buflen;
621 assert(audiobytes1!=audiobytes2);
622 assert(lplpaudioptr1!=lplpaudioptr2);
624 if (!(dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDPRIMARYLOCK) && dsound->hwbuf) {
625 IDsDriverBuffer_Lock(dsound->hwbuf,
626 lplpaudioptr1, audiobytes1,
627 lplpaudioptr2, audiobytes2,
628 writecursor, writebytes,
632 if (writecursor+writebytes <= dsound->buflen) {
633 *(LPBYTE*)lplpaudioptr1 = dsound->buffer+writecursor;
634 *audiobytes1 = writebytes;
636 *(LPBYTE*)lplpaudioptr2 = NULL;
639 TRACE("->%ld.0\n",writebytes);
641 *(LPBYTE*)lplpaudioptr1 = dsound->buffer+writecursor;
642 *audiobytes1 = dsound->buflen-writecursor;
644 *(LPBYTE*)lplpaudioptr2 = dsound->buffer;
646 *audiobytes2 = writebytes-(dsound->buflen-writecursor);
647 TRACE("->%ld.%ld\n",*audiobytes1,audiobytes2?*audiobytes2:0);
653 static HRESULT WINAPI PrimaryBufferImpl_SetCurrentPosition(
654 LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
656 ICOM_THIS(PrimaryBufferImpl,iface);
657 TRACE("(%p,%ld)\n",This,newpos);
659 /* You cannot set the position of the primary buffer */
660 return DSERR_INVALIDCALL;
663 static HRESULT WINAPI PrimaryBufferImpl_SetPan(
664 LPDIRECTSOUNDBUFFER8 iface,LONG pan
666 ICOM_THIS(PrimaryBufferImpl,iface);
667 TRACE("(%p,%ld)\n",This,pan);
669 /* You cannot set the pan of the primary buffer */
670 return DSERR_CONTROLUNAVAIL;
673 static HRESULT WINAPI PrimaryBufferImpl_GetPan(
674 LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
676 ICOM_THIS(PrimaryBufferImpl,iface);
677 TRACE("(%p,%p)\n",This,pan);
680 return DSERR_INVALIDPARAM;
682 *pan = This->dsound->volpan.lPan;
687 static HRESULT WINAPI PrimaryBufferImpl_Unlock(
688 LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
690 ICOM_THIS(PrimaryBufferImpl,iface);
691 IDirectSoundImpl* dsound = This->dsound;
693 TRACE("(%p,%p,%ld,%p,%ld):stub\n", This,p1,x1,p2,x2);
695 if (dsound->priolevel != DSSCL_WRITEPRIMARY)
696 return DSERR_PRIOLEVELNEEDED;
698 if (!(dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDPRIMARYLOCK) && dsound->hwbuf) {
699 IDsDriverBuffer_Unlock(dsound->hwbuf, p1, x1, p2, x2);
705 static HRESULT WINAPI PrimaryBufferImpl_Restore(
706 LPDIRECTSOUNDBUFFER8 iface
708 ICOM_THIS(PrimaryBufferImpl,iface);
709 FIXME("(%p):stub\n",This);
713 static HRESULT WINAPI PrimaryBufferImpl_GetFrequency(
714 LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
716 ICOM_THIS(PrimaryBufferImpl,iface);
717 TRACE("(%p,%p)\n",This,freq);
720 return DSERR_INVALIDPARAM;
722 *freq = This->dsound->wfx.nSamplesPerSec;
723 TRACE("-> %ld\n", *freq);
728 static HRESULT WINAPI PrimaryBufferImpl_SetFX(
729 LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes
731 ICOM_THIS(PrimaryBufferImpl,iface);
734 FIXME("(%p,%lu,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
737 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
739 return DSERR_CONTROLUNAVAIL;
742 static HRESULT WINAPI PrimaryBufferImpl_AcquireResources(
743 LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes
745 ICOM_THIS(PrimaryBufferImpl,iface);
748 FIXME("(%p,%08lu,%lu,%p): stub\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
751 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
753 return DSERR_CONTROLUNAVAIL;
756 static HRESULT WINAPI PrimaryBufferImpl_GetObjectInPath(
757 LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject
759 ICOM_THIS(PrimaryBufferImpl,iface);
761 FIXME("(%p,%s,%lu,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
763 return DSERR_CONTROLUNAVAIL;
766 static HRESULT WINAPI PrimaryBufferImpl_Initialize(
767 LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND8 dsound,LPDSBUFFERDESC dbsd
769 ICOM_THIS(PrimaryBufferImpl,iface);
770 FIXME("(%p,%p,%p):stub\n",This,dsound,dbsd);
771 DPRINTF("Re-Init!!!\n");
772 return DSERR_ALREADYINITIALIZED;
775 static HRESULT WINAPI PrimaryBufferImpl_GetCaps(
776 LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
778 ICOM_THIS(PrimaryBufferImpl,iface);
779 TRACE("(%p)->(%p)\n",This,caps);
781 if (caps == NULL || caps->dwSize!=sizeof(*caps))
782 return DSERR_INVALIDPARAM;
784 caps->dwFlags = This->dsbd.dwFlags;
785 if (This->dsound->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
786 else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
788 caps->dwBufferBytes = This->dsound->buflen;
790 /* This value represents the speed of the "unlock" command.
791 As unlock is quite fast (it does not do anything), I put
792 4096 ko/s = 4 Mo / s */
793 /* FIXME: hwbuf speed */
794 caps->dwUnlockTransferRate = 4096;
795 caps->dwPlayCpuOverhead = 0;
800 static HRESULT WINAPI PrimaryBufferImpl_QueryInterface(
801 LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
803 ICOM_THIS(PrimaryBufferImpl,iface);
805 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
807 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
808 ERR("app requested IDirectSoundNotify on primary buffer\n");
809 /* should we support this? */
814 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
815 ERR("app requested IDirectSound3DBuffer on primary buffer\n");
817 return E_NOINTERFACE;
820 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
821 if (!This->dsound->listener)
822 IDirectSound3DListenerImpl_Create(This, &This->dsound->listener);
823 *ppobj = This->dsound->listener;
824 if (This->dsound->listener) {
825 IDirectSound3DListener_AddRef((LPDIRECTSOUND3DLISTENER)*ppobj);
831 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
834 IKsPropertySetImpl_Create(This, &This->iks);
837 IKsPropertySet_AddRef((LPKSPROPERTYSET)*ppobj);
842 FIXME("app requested IKsPropertySet on primary buffer\n");
848 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
852 return E_NOINTERFACE;
855 static ICOM_VTABLE(IDirectSoundBuffer8) dspbvt =
857 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
858 PrimaryBufferImpl_QueryInterface,
859 PrimaryBufferImpl_AddRef,
860 PrimaryBufferImpl_Release,
861 PrimaryBufferImpl_GetCaps,
862 PrimaryBufferImpl_GetCurrentPosition,
863 PrimaryBufferImpl_GetFormat,
864 PrimaryBufferImpl_GetVolume,
865 PrimaryBufferImpl_GetPan,
866 PrimaryBufferImpl_GetFrequency,
867 PrimaryBufferImpl_GetStatus,
868 PrimaryBufferImpl_Initialize,
869 PrimaryBufferImpl_Lock,
870 PrimaryBufferImpl_Play,
871 PrimaryBufferImpl_SetCurrentPosition,
872 PrimaryBufferImpl_SetFormat,
873 PrimaryBufferImpl_SetVolume,
874 PrimaryBufferImpl_SetPan,
875 PrimaryBufferImpl_SetFrequency,
876 PrimaryBufferImpl_Stop,
877 PrimaryBufferImpl_Unlock,
878 PrimaryBufferImpl_Restore,
879 PrimaryBufferImpl_SetFX,
880 PrimaryBufferImpl_AcquireResources,
881 PrimaryBufferImpl_GetObjectInPath
884 HRESULT WINAPI PrimaryBuffer_Create(
885 IDirectSoundImpl *This,
886 PrimaryBufferImpl **pdsb,
889 PrimaryBufferImpl *dsb;
891 if (dsbd->lpwfxFormat)
892 return DSERR_INVALIDPARAM;
894 dsb = (PrimaryBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
897 ICOM_VTBL(dsb) = &dspbvt;
899 memcpy(&dsb->dsbd, dsbd, sizeof(*dsbd));
901 TRACE("Created primary buffer at %p\n", dsb);
903 if (dsbd->dwFlags & DSBCAPS_CTRL3D) {
904 /* FIXME: IDirectSound3DListener */
907 IDirectSound8_AddRef((LPDIRECTSOUND8)This);