[AUDIO-BRINGUP]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 3 Dec 2010 03:42:10 +0000 (03:42 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 3 Dec 2010 03:42:10 +0000 (03:42 +0000)
- Activate dsound rewrite

svn path=/branches/audio-bringup/; revision=49911

25 files changed:
dll/directx/directx.rbuild
dll/directx/dsound/buffer.c [deleted file]
dll/directx/dsound/capture.c [deleted file]
dll/directx/dsound/dsound.c [deleted file]
dll/directx/dsound/dsound.rbuild [deleted file]
dll/directx/dsound/dsound.spec [deleted file]
dll/directx/dsound/dsound_convert.c [deleted file]
dll/directx/dsound/dsound_main.c [deleted file]
dll/directx/dsound/dsound_private.h [deleted file]
dll/directx/dsound/duplex.c [deleted file]
dll/directx/dsound/mixer.c [deleted file]
dll/directx/dsound/primary.c [deleted file]
dll/directx/dsound/propset.c [deleted file]
dll/directx/dsound/regsvr.c [deleted file]
dll/directx/dsound/sound3d.c [deleted file]
dll/directx/dsound/tests/.cvsignore [deleted file]
dll/directx/dsound/tests/Makefile.in [deleted file]
dll/directx/dsound/tests/capture.c [deleted file]
dll/directx/dsound/tests/ds3d.c [deleted file]
dll/directx/dsound/tests/ds3d8.c [deleted file]
dll/directx/dsound/tests/dsound.c [deleted file]
dll/directx/dsound/tests/dsound8.c [deleted file]
dll/directx/dsound/tests/dsound_test.h [deleted file]
dll/directx/dsound/tests/propset.c [deleted file]
dll/directx/dsound/version.rc [deleted file]

index 97839e6..f542c03 100644 (file)
@@ -28,8 +28,8 @@
        <directory name="dplayx">
                <xi:include href="dplayx/dplayx.rbuild" />
        </directory>
-       <directory name="dsound">
-               <xi:include href="dsound/dsound.rbuild" />
+       <directory name="dsound_new">
+               <xi:include href="dsound_new/dsound.rbuild" />
        </directory>
        <directory name="dxdiagn">
                <xi:include href="dxdiagn/dxdiagn.rbuild" />
diff --git a/dll/directx/dsound/buffer.c b/dll/directx/dsound/buffer.c
deleted file mode 100644 (file)
index 251c436..0000000
+++ /dev/null
@@ -1,1558 +0,0 @@
-/*                     DirectSound
- *
- * Copyright 1998 Marcus Meissner
- * Copyright 1998 Rob Riggs
- * Copyright 2000-2002 TransGaming Technologies, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#include <stdarg.h>
-
-#define NONAMELESSSTRUCT
-#define NONAMELESSUNION
-#include "windef.h"
-#include "winbase.h"
-#include "winuser.h"
-#include "mmsystem.h"
-#include "winternl.h"
-#include "wine/debug.h"
-#include "dsound.h"
-#include "dsdriver.h"
-#include "dsound_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(dsound);
-
-static HRESULT SecondaryBufferImpl_Destroy(SecondaryBufferImpl *pdsb);
-
-/*******************************************************************************
- *             IDirectSoundNotify
- */
-
-struct IDirectSoundNotifyImpl
-{
-    /* IUnknown fields */
-    const IDirectSoundNotifyVtbl *lpVtbl;
-    LONG                        ref;
-    IDirectSoundBufferImpl*     dsb;
-};
-
-static HRESULT IDirectSoundNotifyImpl_Create(IDirectSoundBufferImpl *dsb,
-                                             IDirectSoundNotifyImpl **pdsn);
-static HRESULT IDirectSoundNotifyImpl_Destroy(IDirectSoundNotifyImpl *pdsn);
-
-static HRESULT WINAPI IDirectSoundNotifyImpl_QueryInterface(
-       LPDIRECTSOUNDNOTIFY iface,REFIID riid,LPVOID *ppobj
-) {
-       IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
-       TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-
-       if (This->dsb == NULL) {
-               WARN("invalid parameter\n");
-               return E_INVALIDARG;
-       }
-
-       return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER)This->dsb, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSoundNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface)
-{
-    IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface)
-{
-    IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-
-    if (!ref) {
-        IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)This->dsb);
-        This->dsb->notify = NULL;
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(
-       LPDIRECTSOUNDNOTIFY iface,DWORD howmuch,LPCDSBPOSITIONNOTIFY notify
-) {
-       IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
-       TRACE("(%p,0x%08x,%p)\n",This,howmuch,notify);
-
-        if (howmuch > 0 && notify == NULL) {
-           WARN("invalid parameter: notify == NULL\n");
-           return DSERR_INVALIDPARAM;
-       }
-
-       if (TRACE_ON(dsound)) {
-           unsigned int        i;
-           for (i=0;i<howmuch;i++)
-               TRACE("notify at %d to %p\n",
-                   notify[i].dwOffset,notify[i].hEventNotify);
-       }
-
-       if (This->dsb->hwnotify) {
-           HRESULT hres;
-           hres = IDsDriverNotify_SetNotificationPositions(This->dsb->hwnotify, howmuch, notify);
-           if (hres != DS_OK)
-                   WARN("IDsDriverNotify_SetNotificationPositions failed\n");
-           return hres;
-        } else if (howmuch > 0) {
-           /* Make an internal copy of the caller-supplied array.
-            * Replace the existing copy if one is already present. */
-           HeapFree(GetProcessHeap(), 0, This->dsb->notifies);
-           This->dsb->notifies = HeapAlloc(GetProcessHeap(), 0,
-                       howmuch * sizeof(DSBPOSITIONNOTIFY));
-
-           if (This->dsb->notifies == NULL) {
-                   WARN("out of memory\n");
-                   return DSERR_OUTOFMEMORY;
-           }
-           CopyMemory(This->dsb->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
-           This->dsb->nrofnotifies = howmuch;
-        } else {
-           HeapFree(GetProcessHeap(), 0, This->dsb->notifies);
-           This->dsb->notifies = NULL;
-           This->dsb->nrofnotifies = 0;
-        }
-
-       return S_OK;
-}
-
-static const IDirectSoundNotifyVtbl dsnvt =
-{
-    IDirectSoundNotifyImpl_QueryInterface,
-    IDirectSoundNotifyImpl_AddRef,
-    IDirectSoundNotifyImpl_Release,
-    IDirectSoundNotifyImpl_SetNotificationPositions,
-};
-
-static HRESULT IDirectSoundNotifyImpl_Create(
-    IDirectSoundBufferImpl * dsb,
-    IDirectSoundNotifyImpl **pdsn)
-{
-    IDirectSoundNotifyImpl * dsn;
-    TRACE("(%p,%p)\n",dsb,pdsn);
-
-    dsn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*dsn));
-
-    if (dsn == NULL) {
-        WARN("out of memory\n");
-        return DSERR_OUTOFMEMORY;
-    }
-
-    dsn->ref = 0;
-    dsn->lpVtbl = &dsnvt;
-    dsn->dsb = dsb;
-    dsb->notify = dsn;
-    IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);
-
-    *pdsn = dsn;
-    return DS_OK;
-}
-
-static HRESULT IDirectSoundNotifyImpl_Destroy(
-    IDirectSoundNotifyImpl *pdsn)
-{
-    TRACE("(%p)\n",pdsn);
-
-    while (IDirectSoundNotifyImpl_Release((LPDIRECTSOUNDNOTIFY)pdsn) > 0);
-
-    return DS_OK;
-}
-
-/*******************************************************************************
- *             IDirectSoundBuffer
- */
-
-static HRESULT WINAPI IDirectSoundBufferImpl_SetFormat(
-       LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-
-       TRACE("(%p,%p)\n",This,wfex);
-       /* This method is not available on secondary buffers */
-       WARN("invalid call\n");
-       return DSERR_INVALIDCALL;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(
-       LPDIRECTSOUNDBUFFER8 iface,LONG vol
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       LONG oldVol;
-       HRESULT hres = DS_OK;
-
-       TRACE("(%p,%d)\n",This,vol);
-
-       if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
-               WARN("control unavailable: This->dsbd.dwFlags = 0x%08x\n", This->dsbd.dwFlags);
-               return DSERR_CONTROLUNAVAIL;
-       }
-
-       if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
-               WARN("invalid parameter: vol = %d\n", vol);
-               return DSERR_INVALIDPARAM;
-       }
-
-       /* **** */
-       RtlAcquireResourceExclusive(&This->lock, TRUE);
-
-       if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) {
-               oldVol = This->ds3db_lVolume;
-               This->ds3db_lVolume = vol;
-               if (vol != oldVol)
-                       /* recalc 3d volume, which in turn recalcs the pans */
-                       DSOUND_Calc3DBuffer(This);
-       } else {
-               oldVol = This->volpan.lVolume;
-               This->volpan.lVolume = vol;
-               if (vol != oldVol)
-                       DSOUND_RecalcVolPan(&(This->volpan));
-       }
-
-       if (vol != oldVol) {
-               if (This->hwbuf) {
-                       hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
-                       if (hres != DS_OK)
-                               WARN("IDsDriverBuffer_SetVolumePan failed\n");
-               }
-       }
-
-       RtlReleaseResource(&This->lock);
-       /* **** */
-
-       return hres;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_GetVolume(
-       LPDIRECTSOUNDBUFFER8 iface,LPLONG vol
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       TRACE("(%p,%p)\n",This,vol);
-
-       if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
-               WARN("control unavailable\n");
-               return DSERR_CONTROLUNAVAIL;
-       }
-
-       if (vol == NULL) {
-               WARN("invalid parameter: vol == NULL\n");
-               return DSERR_INVALIDPARAM;
-       }
-
-       *vol = This->volpan.lVolume;
-
-       return DS_OK;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD freq
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       DWORD oldFreq;
-
-       TRACE("(%p,%d)\n",This,freq);
-
-       if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
-               WARN("control unavailable\n");
-               return DSERR_CONTROLUNAVAIL;
-       }
-
-       if (freq == DSBFREQUENCY_ORIGINAL)
-               freq = This->pwfx->nSamplesPerSec;
-
-       if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX)) {
-               WARN("invalid parameter: freq = %d\n", freq);
-               return DSERR_INVALIDPARAM;
-       }
-
-       /* **** */
-       RtlAcquireResourceExclusive(&This->lock, TRUE);
-
-       oldFreq = This->freq;
-       This->freq = freq;
-       if (freq != oldFreq) {
-               This->freqAdjust = ((DWORD64)This->freq << DSOUND_FREQSHIFT) / This->device->pwfx->nSamplesPerSec;
-               This->nAvgBytesPerSec = freq * This->pwfx->nBlockAlign;
-               DSOUND_RecalcFormat(This);
-               DSOUND_MixToTemporary(This, 0, This->buflen, FALSE);
-       }
-
-       RtlReleaseResource(&This->lock);
-       /* **** */
-
-       return DS_OK;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_Play(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
-) {
-       HRESULT hres = DS_OK;
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       TRACE("(%p,%08x,%08x,%08x)\n",This,reserved1,reserved2,flags);
-
-       /* **** */
-       RtlAcquireResourceExclusive(&This->lock, TRUE);
-
-       This->playflags = flags;
-       if (This->state == STATE_STOPPED && !This->hwbuf) {
-               This->leadin = TRUE;
-               This->state = STATE_STARTING;
-       } else if (This->state == STATE_STOPPING)
-               This->state = STATE_PLAYING;
-       if (This->hwbuf) {
-               hres = IDsDriverBuffer_Play(This->hwbuf, 0, 0, This->playflags);
-               if (hres != DS_OK)
-                       WARN("IDsDriverBuffer_Play failed\n");
-               else
-                       This->state = STATE_PLAYING;
-       }
-
-       RtlReleaseResource(&This->lock);
-       /* **** */
-
-       return hres;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
-{
-       HRESULT hres = DS_OK;
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       TRACE("(%p)\n",This);
-
-       /* **** */
-       RtlAcquireResourceExclusive(&This->lock, TRUE);
-
-       if (This->state == STATE_PLAYING)
-               This->state = STATE_STOPPING;
-       else if (This->state == STATE_STARTING)
-       {
-               This->state = STATE_STOPPED;
-               DSOUND_CheckEvent(This, 0, 0);
-       }
-       if (This->hwbuf) {
-               hres = IDsDriverBuffer_Stop(This->hwbuf);
-               if (hres != DS_OK)
-                       WARN("IDsDriverBuffer_Stop failed\n");
-               else
-                       This->state = STATE_STOPPED;
-       }
-
-       RtlReleaseResource(&This->lock);
-       /* **** */
-
-       return hres;
-}
-
-static ULONG WINAPI IDirectSoundBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
-{
-    IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
-{
-    IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-
-    if (!ref) {
-       DirectSoundDevice_RemoveBuffer(This->device, This);
-       RtlDeleteResource(&This->lock);
-
-       if (This->hwbuf)
-               IDsDriverBuffer_Release(This->hwbuf);
-       if (!This->hwbuf || (This->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY)) {
-               This->buffer->ref--;
-               list_remove(&This->entry);
-               if (This->buffer->ref==0) {
-                       HeapFree(GetProcessHeap(),0,This->buffer->memory);
-                       HeapFree(GetProcessHeap(),0,This->buffer);
-               }
-       }
-
-       HeapFree(GetProcessHeap(), 0, This->tmp_buffer);
-       HeapFree(GetProcessHeap(), 0, This->notifies);
-       HeapFree(GetProcessHeap(), 0, This->pwfx);
-       HeapFree(GetProcessHeap(), 0, This);
-
-       TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
-       LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
-) {
-       HRESULT hres;
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       TRACE("(%p,%p,%p)\n",This,playpos,writepos);
-
-       RtlAcquireResourceShared(&This->lock, TRUE);
-       if (This->hwbuf) {
-               hres=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
-               if (hres != DS_OK) {
-                   WARN("IDsDriverBuffer_GetPosition failed\n");
-                   return hres;
-               }
-       } else {
-               DWORD pos = This->sec_mixpos;
-
-               /* sanity */
-               if (pos >= This->buflen){
-                       FIXME("Bad play position. playpos: %d, buflen: %d\n", pos, This->buflen);
-                       pos %= This->buflen;
-               }
-
-               if (playpos)
-                       *playpos = pos;
-               if (writepos)
-                       *writepos = pos;
-       }
-       if (writepos && This->state != STATE_STOPPED && (!This->hwbuf || !(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDWRITELEAD))) {
-               /* apply the documented 10ms lead to writepos */
-               *writepos += This->writelead;
-               *writepos %= This->buflen;
-       }
-       RtlReleaseResource(&This->lock);
-
-       TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n",
-               playpos?*playpos:-1, writepos?*writepos:-1, This->buflen, This, GetTickCount());
-
-       return DS_OK;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(
-       LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       TRACE("(%p,%p), thread is %04x\n",This,status,GetCurrentThreadId());
-
-       if (status == NULL) {
-               WARN("invalid parameter: status = NULL\n");
-               return DSERR_INVALIDPARAM;
-       }
-
-       *status = 0;
-       RtlAcquireResourceShared(&This->lock, TRUE);
-       if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
-               *status |= DSBSTATUS_PLAYING;
-               if (This->playflags & DSBPLAY_LOOPING)
-                       *status |= DSBSTATUS_LOOPING;
-       }
-       RtlReleaseResource(&This->lock);
-
-       TRACE("status=%x\n", *status);
-       return DS_OK;
-}
-
-
-static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
-    LPDIRECTSOUNDBUFFER8 iface,
-    LPWAVEFORMATEX lpwf,
-    DWORD wfsize,
-    LPDWORD wfwritten)
-{
-    DWORD size;
-    IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-    TRACE("(%p,%p,%d,%p)\n",This,lpwf,wfsize,wfwritten);
-
-    size = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
-
-    if (lpwf) { /* NULL is valid */
-        if (wfsize >= size) {
-            CopyMemory(lpwf,This->pwfx,size);
-            if (wfwritten)
-                *wfwritten = size;
-        } else {
-            WARN("invalid parameter: wfsize too small\n");
-            CopyMemory(lpwf,This->pwfx,wfsize);
-            if (wfwritten)
-                *wfwritten = wfsize;
-            return DSERR_INVALIDPARAM;
-        }
-    } else {
-        if (wfwritten)
-            *wfwritten = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
-        else {
-            WARN("invalid parameter: wfwritten == NULL\n");
-            return DSERR_INVALIDPARAM;
-        }
-    }
-
-    return DS_OK;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID *lplpaudioptr1,LPDWORD audiobytes1,LPVOID *lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
-) {
-       HRESULT hres = DS_OK;
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-
-       TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n",
-               This,
-               writecursor,
-               writebytes,
-               lplpaudioptr1,
-               audiobytes1,
-               lplpaudioptr2,
-               audiobytes2,
-               flags,
-               GetTickCount()
-       );
-
-        if (!audiobytes1)
-            return DSERR_INVALIDPARAM;
-
-        /* when this flag is set, writecursor is meaningless and must be calculated */
-       if (flags & DSBLOCK_FROMWRITECURSOR) {
-               /* GetCurrentPosition does too much magic to duplicate here */
-               hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writecursor);
-               if (hres != DS_OK) {
-                       WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
-                       return hres;
-               }
-       }
-
-        /* when this flag is set, writebytes is meaningless and must be set */
-       if (flags & DSBLOCK_ENTIREBUFFER)
-               writebytes = This->buflen;
-
-       if (writecursor >= This->buflen) {
-               WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
-                    writecursor, This->buflen);
-               return DSERR_INVALIDPARAM;
-        }
-
-       if (writebytes > This->buflen) {
-               WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
-                    writebytes, This->buflen);
-               return DSERR_INVALIDPARAM;
-        }
-
-       /* **** */
-       RtlAcquireResourceShared(&This->lock, TRUE);
-
-       if (!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
-               hres = IDsDriverBuffer_Lock(This->hwbuf,
-                                    lplpaudioptr1, audiobytes1,
-                                    lplpaudioptr2, audiobytes2,
-                                    writecursor, writebytes,
-                                    0);
-               if (hres != DS_OK) {
-                       WARN("IDsDriverBuffer_Lock failed\n");
-                       RtlReleaseResource(&This->lock);
-                       return hres;
-               }
-       } else {
-               if (writecursor+writebytes <= This->buflen) {
-                       *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
-                       if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING)
-                               WARN("Overwriting mixing position, case 1\n");
-                       *audiobytes1 = writebytes;
-                       if (lplpaudioptr2)
-                               *(LPBYTE*)lplpaudioptr2 = NULL;
-                       if (audiobytes2)
-                               *audiobytes2 = 0;
-                       TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n",
-                         *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
-                       TRACE("->%d.0\n",writebytes);
-               } else {
-                       DWORD remainder = writebytes + writecursor - This->buflen;
-                       *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
-                       *audiobytes1 = This->buflen-writecursor;
-                       if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING)
-                               WARN("Overwriting mixing position, case 2\n");
-                       if (lplpaudioptr2)
-                               *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
-                       if (audiobytes2)
-                               *audiobytes2 = writebytes-(This->buflen-writecursor);
-                       if (audiobytes2 && This->sec_mixpos < remainder && This->state == STATE_PLAYING)
-                               WARN("Overwriting mixing position, case 3\n");
-                       TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
-               }
-       }
-
-       RtlReleaseResource(&This->lock);
-       /* **** */
-
-       return DS_OK;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
-) {
-       HRESULT hres = DS_OK;
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       DWORD oldpos;
-       TRACE("(%p,%d)\n",This,newpos);
-
-       /* **** */
-       RtlAcquireResourceExclusive(&This->lock, TRUE);
-
-       oldpos = This->sec_mixpos;
-
-       /* start mixing from this new location instead */
-       newpos %= This->buflen;
-       newpos -= newpos%This->pwfx->nBlockAlign;
-       This->sec_mixpos = newpos;
-
-       /* at this point, do not attempt to reset buffers, mess with primary mix position,
-           or anything like that to reduce latancy. The data already prebuffered cannot be changed */
-
-       /* position HW buffer if applicable, else just start mixing from new location instead */
-       if (This->hwbuf) {
-               hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
-               if (hres != DS_OK)
-                       WARN("IDsDriverBuffer_SetPosition failed\n");
-       }
-       else if (oldpos != newpos)
-               /* FIXME: Perhaps add a call to DSOUND_MixToTemporary here? Not sure it's needed */
-               This->buf_mixpos = DSOUND_secpos_to_bufpos(This, newpos, 0, NULL);
-
-       RtlReleaseResource(&This->lock);
-       /* **** */
-
-       return hres;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
-       LPDIRECTSOUNDBUFFER8 iface,LONG pan
-) {
-       HRESULT hres = DS_OK;
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-
-       TRACE("(%p,%d)\n",This,pan);
-
-       if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
-               WARN("invalid parameter: pan = %d\n", pan);
-               return DSERR_INVALIDPARAM;
-       }
-
-       /* You cannot use both pan and 3D controls */
-       if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
-           (This->dsbd.dwFlags & DSBCAPS_CTRL3D)) {
-               WARN("control unavailable\n");
-               return DSERR_CONTROLUNAVAIL;
-       }
-
-       /* **** */
-       RtlAcquireResourceExclusive(&This->lock, TRUE);
-
-       if (This->volpan.lPan != pan) {
-               This->volpan.lPan = pan;
-               DSOUND_RecalcVolPan(&(This->volpan));
-
-               if (This->hwbuf) {
-                       hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
-                       if (hres != DS_OK)
-                               WARN("IDsDriverBuffer_SetVolumePan failed\n");
-               }
-       }
-
-       RtlReleaseResource(&This->lock);
-       /* **** */
-
-       return hres;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
-       LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       TRACE("(%p,%p)\n",This,pan);
-
-       if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
-               WARN("control unavailable\n");
-               return DSERR_CONTROLUNAVAIL;
-       }
-
-       if (pan == NULL) {
-               WARN("invalid parameter: pan = NULL\n");
-               return DSERR_INVALIDPARAM;
-       }
-
-       *pan = This->volpan.lPan;
-
-       return DS_OK;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
-       LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface, *iter;
-       HRESULT hres = DS_OK;
-
-       TRACE("(%p,%p,%d,%p,%d)\n", This,p1,x1,p2,x2);
-
-       /* **** */
-       RtlAcquireResourceShared(&This->lock, TRUE);
-
-       if (!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
-               hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
-               if (hres != DS_OK)
-                       WARN("IDsDriverBuffer_Unlock failed\n");
-       }
-
-       RtlReleaseResource(&This->lock);
-       /* **** */
-
-       if (!p2)
-               x2 = 0;
-
-       if (!This->hwbuf && (x1 || x2))
-       {
-               RtlAcquireResourceShared(&This->device->buffer_list_lock, TRUE);
-               LIST_FOR_EACH_ENTRY(iter, &This->buffer->buffers, IDirectSoundBufferImpl, entry )
-               {
-                       RtlAcquireResourceShared(&iter->lock, TRUE);
-                       if (x1)
-                        {
-                           if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory > iter->buflen)
-                             hres = DSERR_INVALIDPARAM;
-                           else
-                             DSOUND_MixToTemporary(iter, (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory, x1, FALSE);
-                        }
-                       if (x2)
-                               DSOUND_MixToTemporary(iter, 0, x2, FALSE);
-                       RtlReleaseResource(&iter->lock);
-               }
-               RtlReleaseResource(&This->device->buffer_list_lock);
-       }
-
-       return hres;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_Restore(
-       LPDIRECTSOUNDBUFFER8 iface
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       FIXME("(%p):stub\n",This);
-       return DS_OK;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(
-       LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       TRACE("(%p,%p)\n",This,freq);
-
-       if (freq == NULL) {
-               WARN("invalid parameter: freq = NULL\n");
-               return DSERR_INVALIDPARAM;
-       }
-
-       *freq = This->freq;
-       TRACE("-> %d\n", *freq);
-
-       return DS_OK;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       DWORD u;
-
-       FIXME("(%p,%u,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
-
-       if (pdwResultCodes)
-               for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
-
-       WARN("control unavailable\n");
-       return DSERR_CONTROLUNAVAIL;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       DWORD u;
-
-       FIXME("(%p,%08u,%u,%p): stub\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
-
-       if (pdwResultCodes)
-               for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
-
-       WARN("control unavailable\n");
-       return DSERR_CONTROLUNAVAIL;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(
-       LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-
-       FIXME("(%p,%s,%u,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
-
-       WARN("control unavailable\n");
-       return DSERR_CONTROLUNAVAIL;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(
-       LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       WARN("(%p) already initialized\n", This);
-       return DSERR_ALREADYINITIALIZED;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(
-       LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-       TRACE("(%p)->(%p)\n",This,caps);
-
-       if (caps == NULL) {
-               WARN("invalid parameter: caps == NULL\n");
-               return DSERR_INVALIDPARAM;
-       }
-
-       if (caps->dwSize < sizeof(*caps)) {
-               WARN("invalid parameter: caps->dwSize = %d\n",caps->dwSize);
-               return DSERR_INVALIDPARAM;
-       }
-
-       caps->dwFlags = This->dsbd.dwFlags;
-       if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
-       else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
-
-       caps->dwBufferBytes = This->buflen;
-
-       /* According to windows, this is zero*/
-       caps->dwUnlockTransferRate = 0;
-       caps->dwPlayCpuOverhead = 0;
-
-       return DS_OK;
-}
-
-static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
-       LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
-) {
-       IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-
-       TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-
-       if (ppobj == NULL) {
-               WARN("invalid parameter\n");
-               return E_INVALIDARG;
-       }
-
-       *ppobj = NULL;  /* assume failure */
-
-       if ( IsEqualGUID(riid, &IID_IUnknown) ||
-            IsEqualGUID(riid, &IID_IDirectSoundBuffer) ||
-            IsEqualGUID(riid, &IID_IDirectSoundBuffer8) ) {
-               if (!This->secondary)
-                       SecondaryBufferImpl_Create(This, &(This->secondary));
-               if (This->secondary) {
-                       IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)This->secondary);
-                       *ppobj = This->secondary;
-                       return S_OK;
-               }
-               WARN("IID_IDirectSoundBuffer\n");
-               return E_NOINTERFACE;
-       }
-
-       if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
-               if (!This->notify)
-                       IDirectSoundNotifyImpl_Create(This, &(This->notify));
-               if (This->notify) {
-                       IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
-                       *ppobj = This->notify;
-                       return S_OK;
-               }
-               WARN("IID_IDirectSoundNotify\n");
-               return E_NOINTERFACE;
-       }
-
-       if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
-               if (!This->ds3db)
-                       IDirectSound3DBufferImpl_Create(This, &(This->ds3db));
-               if (This->ds3db) {
-                       IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->ds3db);
-                       *ppobj = This->ds3db;
-                       return S_OK;
-               }
-               WARN("IID_IDirectSound3DBuffer\n");
-               return E_NOINTERFACE;
-       }
-
-       if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
-               ERR("app requested IDirectSound3DListener on secondary buffer\n");
-               return E_NOINTERFACE;
-       }
-
-       if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
-               if (!This->iks)
-                       IKsBufferPropertySetImpl_Create(This, &(This->iks));
-               if (This->iks) {
-                       IKsPropertySet_AddRef((LPKSPROPERTYSET)This->iks);
-                       *ppobj = This->iks;
-                       return S_OK;
-               }
-               WARN("IID_IKsPropertySet\n");
-               return E_NOINTERFACE;
-       }
-
-       FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
-
-       return E_NOINTERFACE;
-}
-
-static const IDirectSoundBuffer8Vtbl dsbvt =
-{
-       IDirectSoundBufferImpl_QueryInterface,
-       IDirectSoundBufferImpl_AddRef,
-       IDirectSoundBufferImpl_Release,
-       IDirectSoundBufferImpl_GetCaps,
-       IDirectSoundBufferImpl_GetCurrentPosition,
-       IDirectSoundBufferImpl_GetFormat,
-       IDirectSoundBufferImpl_GetVolume,
-       IDirectSoundBufferImpl_GetPan,
-       IDirectSoundBufferImpl_GetFrequency,
-       IDirectSoundBufferImpl_GetStatus,
-       IDirectSoundBufferImpl_Initialize,
-       IDirectSoundBufferImpl_Lock,
-       IDirectSoundBufferImpl_Play,
-       IDirectSoundBufferImpl_SetCurrentPosition,
-       IDirectSoundBufferImpl_SetFormat,
-       IDirectSoundBufferImpl_SetVolume,
-       IDirectSoundBufferImpl_SetPan,
-       IDirectSoundBufferImpl_SetFrequency,
-       IDirectSoundBufferImpl_Stop,
-       IDirectSoundBufferImpl_Unlock,
-       IDirectSoundBufferImpl_Restore,
-       IDirectSoundBufferImpl_SetFX,
-       IDirectSoundBufferImpl_AcquireResources,
-       IDirectSoundBufferImpl_GetObjectInPath
-};
-
-HRESULT IDirectSoundBufferImpl_Create(
-       DirectSoundDevice * device,
-       IDirectSoundBufferImpl **pdsb,
-       LPCDSBUFFERDESC dsbd)
-{
-       IDirectSoundBufferImpl *dsb;
-       LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
-       HRESULT err = DS_OK;
-       DWORD capf = 0;
-       int use_hw, alloc_size, cp_size;
-       TRACE("(%p,%p,%p)\n",device,pdsb,dsbd);
-
-       if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
-               WARN("invalid parameter: dsbd->dwBufferBytes = %d\n", dsbd->dwBufferBytes);
-               *pdsb = NULL;
-               return DSERR_INVALIDPARAM; /* FIXME: which error? */
-       }
-
-       dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
-
-       if (dsb == 0) {
-               WARN("out of memory\n");
-               *pdsb = NULL;
-               return DSERR_OUTOFMEMORY;
-       }
-
-       TRACE("Created buffer at %p\n", dsb);
-
-       dsb->ref = 0;
-       dsb->secondary = 0;
-       dsb->device = device;
-       dsb->lpVtbl = &dsbvt;
-       dsb->iks = NULL;
-
-       /* size depends on version */
-       CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize);
-
-       /* variable sized struct so calculate size based on format */
-       if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
-               alloc_size = sizeof(WAVEFORMATEX);
-               cp_size = sizeof(PCMWAVEFORMAT);
-       } else 
-               alloc_size = cp_size = sizeof(WAVEFORMATEX) + wfex->cbSize;
-
-       dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,alloc_size);
-       if (dsb->pwfx == NULL) {
-               WARN("out of memory\n");
-               HeapFree(GetProcessHeap(),0,dsb);
-               *pdsb = NULL;
-               return DSERR_OUTOFMEMORY;
-       }
-
-       CopyMemory(dsb->pwfx, wfex, cp_size);
-
-       if (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign)
-               dsb->buflen = dsbd->dwBufferBytes + 
-                       (dsbd->lpwfxFormat->nBlockAlign - 
-                       (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign));
-       else
-               dsb->buflen = dsbd->dwBufferBytes;
-
-       dsb->freq = dsbd->lpwfxFormat->nSamplesPerSec;
-       dsb->notify = NULL;
-       dsb->notifies = NULL;
-       dsb->nrofnotifies = 0;
-       dsb->hwnotify = 0;
-
-       /* Check necessary hardware mixing capabilities */
-       if (wfex->nChannels==2) capf |= DSCAPS_SECONDARYSTEREO;
-       else capf |= DSCAPS_SECONDARYMONO;
-       if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
-       else capf |= DSCAPS_SECONDARY8BIT;
-
-       use_hw = !!(dsbd->dwFlags & DSBCAPS_LOCHARDWARE);
-       TRACE("use_hw = %d, capf = 0x%08x, device->drvcaps.dwFlags = 0x%08x\n", use_hw, capf, device->drvcaps.dwFlags);
-       if (use_hw && ((device->drvcaps.dwFlags & capf) != capf || !device->driver))
-       {
-               if (device->driver)
-                       WARN("Format not supported for hardware buffer\n");
-               HeapFree(GetProcessHeap(),0,dsb->pwfx);
-               HeapFree(GetProcessHeap(),0,dsb);
-               *pdsb = NULL;
-               if ((device->drvcaps.dwFlags & capf) != capf)
-                       return DSERR_BADFORMAT;
-               return DSERR_GENERIC;
-       }
-
-       /* FIXME: check hardware sample rate mixing capabilities */
-       /* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
-       /* FIXME: check whether any hardware buffers are left */
-       /* FIXME: handle DSDHEAP_CREATEHEAP for hardware buffers */
-
-       /* Allocate an empty buffer */
-       dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
-       if (dsb->buffer == NULL) {
-               WARN("out of memory\n");
-               HeapFree(GetProcessHeap(),0,dsb->pwfx);
-               HeapFree(GetProcessHeap(),0,dsb);
-               *pdsb = NULL;
-               return DSERR_OUTOFMEMORY;
-       }
-
-       /* Allocate system memory for buffer if applicable */
-       if ((device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
-               dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
-               if (dsb->buffer->memory == NULL) {
-                       WARN("out of memory\n");
-                       HeapFree(GetProcessHeap(),0,dsb->pwfx);
-                       HeapFree(GetProcessHeap(),0,dsb->buffer);
-                       HeapFree(GetProcessHeap(),0,dsb);
-                       *pdsb = NULL;
-                       return DSERR_OUTOFMEMORY;
-               }
-       }
-
-       /* Allocate the hardware buffer */
-       if (use_hw) {
-               err = IDsDriver_CreateSoundBuffer(device->driver,wfex,dsbd->dwFlags,0,
-                                                 &(dsb->buflen),&(dsb->buffer->memory),
-                                                 (LPVOID*)&(dsb->hwbuf));
-               if (FAILED(err))
-               {
-                       WARN("Failed to create hardware secondary buffer: %08x\n", err);
-                       if (device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY)
-                               HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
-                       HeapFree(GetProcessHeap(),0,dsb->buffer);
-                       HeapFree(GetProcessHeap(),0,dsb->pwfx);
-                       HeapFree(GetProcessHeap(),0,dsb);
-                       *pdsb = NULL;
-                       return DSERR_GENERIC;
-               }
-       }
-
-       dsb->buffer->ref = 1;
-       list_init(&dsb->buffer->buffers);
-       list_add_head(&dsb->buffer->buffers, &dsb->entry);
-       FillMemory(dsb->buffer->memory, dsb->buflen, dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0);
-
-       /* It's not necessary to initialize values to zero since */
-       /* we allocated this structure with HEAP_ZERO_MEMORY... */
-       dsb->buf_mixpos = dsb->sec_mixpos = 0;
-       dsb->state = STATE_STOPPED;
-
-       dsb->freqAdjust = ((DWORD64)dsb->freq << DSOUND_FREQSHIFT) / device->pwfx->nSamplesPerSec;
-       dsb->nAvgBytesPerSec = dsb->freq *
-               dsbd->lpwfxFormat->nBlockAlign;
-
-       /* calculate fragment size and write lead */
-       DSOUND_RecalcFormat(dsb);
-
-       if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
-               dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
-               dsb->ds3db_ds3db.vPosition.x = 0.0;
-               dsb->ds3db_ds3db.vPosition.y = 0.0;
-               dsb->ds3db_ds3db.vPosition.z = 0.0;
-               dsb->ds3db_ds3db.vVelocity.x = 0.0;
-               dsb->ds3db_ds3db.vVelocity.y = 0.0;
-               dsb->ds3db_ds3db.vVelocity.z = 0.0;
-               dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
-               dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
-               dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
-               dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
-               dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
-               dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
-               dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
-               dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
-               dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
-
-               dsb->ds3db_need_recalc = FALSE;
-               DSOUND_Calc3DBuffer(dsb);
-       } else
-               DSOUND_RecalcVolPan(&(dsb->volpan));
-
-       RtlInitializeResource(&dsb->lock);
-
-       /* register buffer if not primary */
-       if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
-               err = DirectSoundDevice_AddBuffer(device, dsb);
-               if (err != DS_OK) {
-                       HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
-                       HeapFree(GetProcessHeap(),0,dsb->buffer);
-                       RtlDeleteResource(&dsb->lock);
-                       HeapFree(GetProcessHeap(),0,dsb->pwfx);
-                       HeapFree(GetProcessHeap(),0,dsb);
-                       dsb = NULL;
-               }
-       }
-
-       *pdsb = dsb;
-       return err;
-}
-
-HRESULT IDirectSoundBufferImpl_Destroy(
-    IDirectSoundBufferImpl *pdsb)
-{
-    TRACE("(%p)\n",pdsb);
-
-    /* This keeps the *_Destroy functions from possibly deleting
-     * this object until it is ready to be deleted */
-    IDirectSoundBufferImpl_AddRef((LPDIRECTSOUNDBUFFER8)pdsb);
-
-    if (pdsb->iks) {
-        WARN("iks not NULL\n");
-        IKsBufferPropertySetImpl_Destroy(pdsb->iks);
-        pdsb->iks = NULL;
-    }
-
-    if (pdsb->ds3db) {
-        WARN("ds3db not NULL\n");
-        IDirectSound3DBufferImpl_Destroy(pdsb->ds3db);
-        pdsb->ds3db = NULL;
-    }
-
-    if (pdsb->notify) {
-        WARN("notify not NULL\n");
-        IDirectSoundNotifyImpl_Destroy(pdsb->notify);
-        pdsb->notify = NULL;
-    }
-
-    if (pdsb->secondary) {
-        WARN("dsb not NULL\n");
-        SecondaryBufferImpl_Destroy(pdsb->secondary);
-        pdsb->secondary = NULL;
-    }
-
-    while (IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);
-
-    return S_OK;
-}
-
-HRESULT IDirectSoundBufferImpl_Duplicate(
-    DirectSoundDevice *device,
-    IDirectSoundBufferImpl **ppdsb,
-    IDirectSoundBufferImpl *pdsb)
-{
-    IDirectSoundBufferImpl *dsb;
-    HRESULT hres = DS_OK;
-    int size;
-    TRACE("(%p,%p,%p)\n", device, pdsb, pdsb);
-
-    dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
-
-    if (dsb == NULL) {
-        WARN("out of memory\n");
-        *ppdsb = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    CopyMemory(dsb, pdsb, sizeof(IDirectSoundBufferImpl));
-
-    if (pdsb->hwbuf) {
-        TRACE("duplicating hardware buffer\n");
-
-        hres = IDsDriver_DuplicateSoundBuffer(device->driver, pdsb->hwbuf,
-                                              (LPVOID *)&dsb->hwbuf);
-        if (FAILED(hres)) {
-            WARN("IDsDriver_DuplicateSoundBuffer failed (%08x)\n", hres);
-            HeapFree(GetProcessHeap(),0,dsb);
-            *ppdsb = NULL;
-            return hres;
-        }
-    }
-
-    dsb->buffer->ref++;
-    list_add_head(&dsb->buffer->buffers, &dsb->entry);
-    dsb->ref = 0;
-    dsb->state = STATE_STOPPED;
-    dsb->buf_mixpos = dsb->sec_mixpos = 0;
-    dsb->device = device;
-    dsb->ds3db = NULL;
-    dsb->iks = NULL; /* FIXME? */
-    dsb->secondary = NULL;
-    dsb->tmp_buffer = NULL;
-    DSOUND_RecalcFormat(dsb);
-    DSOUND_MixToTemporary(dsb, 0, dsb->buflen, FALSE);
-
-    /* variable sized struct so calculate size based on format */
-    size = sizeof(WAVEFORMATEX) + pdsb->pwfx->cbSize;
-
-    dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
-    if (dsb->pwfx == NULL) {
-            WARN("out of memory\n");
-            HeapFree(GetProcessHeap(),0,dsb->buffer);
-            HeapFree(GetProcessHeap(),0,dsb);
-            *ppdsb = NULL;
-            return DSERR_OUTOFMEMORY;
-    }
-
-    CopyMemory(dsb->pwfx, pdsb->pwfx, size);
-
-    RtlInitializeResource(&dsb->lock);
-
-    /* register buffer */
-    hres = DirectSoundDevice_AddBuffer(device, dsb);
-    if (hres != DS_OK) {
-        RtlDeleteResource(&dsb->lock);
-        HeapFree(GetProcessHeap(),0,dsb->tmp_buffer);
-        HeapFree(GetProcessHeap(),0,dsb->buffer);
-        HeapFree(GetProcessHeap(),0,dsb->pwfx);
-        HeapFree(GetProcessHeap(),0,dsb);
-        *ppdsb = 0;
-    }
-
-    *ppdsb = dsb;
-    return hres;
-}
-
-/*******************************************************************************
- *             SecondaryBuffer
- */
-
-static HRESULT WINAPI SecondaryBufferImpl_QueryInterface(
-       LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-
-       return IDirectSoundBufferImpl_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb,riid,ppobj);
-}
-
-static ULONG WINAPI SecondaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
-{
-    SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI SecondaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
-{
-    SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-    ULONG ref;
-    TRACE("(%p)\n", This);
-    ref = InterlockedDecrement(&(This->ref));
-    TRACE("ref was %d\n", ref + 1);
-
-    if (!ref) {
-        This->dsb->secondary = NULL;
-        IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_GetCaps(
-       LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p)->(%p)\n",This,caps);
-
-       return IDirectSoundBufferImpl_GetCaps((LPDIRECTSOUNDBUFFER8)This->dsb,caps);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_GetCurrentPosition(
-       LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%p,%p)\n",This,playpos,writepos);
-
-       return IDirectSoundBufferImpl_GetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,playpos,writepos);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_GetFormat(
-       LPDIRECTSOUNDBUFFER8 iface,LPWAVEFORMATEX lpwf,DWORD wfsize,LPDWORD wfwritten)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%p,%d,%p)\n",This,lpwf,wfsize,wfwritten);
-
-       return IDirectSoundBufferImpl_GetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,lpwf,wfsize,wfwritten);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_GetVolume(
-       LPDIRECTSOUNDBUFFER8 iface,LPLONG vol)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%p)\n",This,vol);
-
-       return IDirectSoundBufferImpl_GetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_GetPan(
-       LPDIRECTSOUNDBUFFER8 iface,LPLONG pan)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%p)\n",This,pan);
-
-       return IDirectSoundBufferImpl_GetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_GetFrequency(
-       LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%p)\n",This,freq);
-
-       return IDirectSoundBufferImpl_GetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_GetStatus(
-       LPDIRECTSOUNDBUFFER8 iface,LPDWORD status)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%p)\n",This,status);
-
-       return IDirectSoundBufferImpl_GetStatus((LPDIRECTSOUNDBUFFER8)This->dsb,status);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_Initialize(
-       LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%p,%p)\n",This,dsound,dbsd);
-
-       return IDirectSoundBufferImpl_Initialize((LPDIRECTSOUNDBUFFER8)This->dsb,dsound,dbsd);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_Lock(
-    LPDIRECTSOUNDBUFFER8 iface,
-    DWORD writecursor,
-    DWORD writebytes,
-    LPVOID *lplpaudioptr1,
-    LPDWORD audiobytes1,
-    LPVOID *lplpaudioptr2,
-    LPDWORD audiobytes2,
-    DWORD dwFlags)
-{
-    SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-    TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x)\n",
-        This,writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
-
-    return IDirectSoundBufferImpl_Lock((LPDIRECTSOUNDBUFFER8)This->dsb,
-        writecursor,writebytes,lplpaudioptr1,audiobytes1,lplpaudioptr2,audiobytes2,dwFlags);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_Play(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%08x,%08x,%08x)\n",This,reserved1,reserved2,flags);
-
-       return IDirectSoundBufferImpl_Play((LPDIRECTSOUNDBUFFER8)This->dsb,reserved1,reserved2,flags);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_SetCurrentPosition(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD newpos)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%d)\n",This,newpos);
-
-       return IDirectSoundBufferImpl_SetCurrentPosition((LPDIRECTSOUNDBUFFER8)This->dsb,newpos);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_SetFormat(
-       LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%p)\n",This,wfex);
-
-       return IDirectSoundBufferImpl_SetFormat((LPDIRECTSOUNDBUFFER8)This->dsb,wfex);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_SetVolume(
-       LPDIRECTSOUNDBUFFER8 iface,LONG vol)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%d)\n",This,vol);
-
-       return IDirectSoundBufferImpl_SetVolume((LPDIRECTSOUNDBUFFER8)This->dsb,vol);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_SetPan(
-       LPDIRECTSOUNDBUFFER8 iface,LONG pan)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%d)\n",This,pan);
-
-       return IDirectSoundBufferImpl_SetPan((LPDIRECTSOUNDBUFFER8)This->dsb,pan);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_SetFrequency(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD freq)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%d)\n",This,freq);
-
-       return IDirectSoundBufferImpl_SetFrequency((LPDIRECTSOUNDBUFFER8)This->dsb,freq);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p)\n",This);
-
-       return IDirectSoundBufferImpl_Stop((LPDIRECTSOUNDBUFFER8)This->dsb);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_Unlock(
-    LPDIRECTSOUNDBUFFER8 iface,
-    LPVOID lpvAudioPtr1,
-    DWORD dwAudioBytes1,
-    LPVOID lpvAudioPtr2,
-    DWORD dwAudioBytes2)
-{
-    SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-    TRACE("(%p,%p,%d,%p,%d)\n",
-        This, lpvAudioPtr1, dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
-
-    return IDirectSoundBufferImpl_Unlock((LPDIRECTSOUNDBUFFER8)This->dsb,
-        lpvAudioPtr1,dwAudioBytes1,lpvAudioPtr2,dwAudioBytes2);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_Restore(
-       LPDIRECTSOUNDBUFFER8 iface)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p)\n",This);
-
-       return IDirectSoundBufferImpl_Restore((LPDIRECTSOUNDBUFFER8)This->dsb);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_SetFX(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%u,%p,%p)\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
-
-       return IDirectSoundBufferImpl_SetFX((LPDIRECTSOUNDBUFFER8)This->dsb,dwEffectsCount,pDSFXDesc,pdwResultCodes);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_AcquireResources(
-       LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%08u,%u,%p)\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
-
-       return IDirectSoundBufferImpl_AcquireResources((LPDIRECTSOUNDBUFFER8)This->dsb,dwFlags,dwEffectsCount,pdwResultCodes);
-}
-
-static HRESULT WINAPI SecondaryBufferImpl_GetObjectInPath(
-       LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject)
-{
-       SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
-       TRACE("(%p,%s,%u,%s,%p)\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
-
-       return IDirectSoundBufferImpl_GetObjectInPath((LPDIRECTSOUNDBUFFER8)This->dsb,rguidObject,dwIndex,rguidInterface,ppObject);
-}
-
-static const IDirectSoundBuffer8Vtbl sbvt =
-{
-       SecondaryBufferImpl_QueryInterface,
-       SecondaryBufferImpl_AddRef,
-       SecondaryBufferImpl_Release,
-       SecondaryBufferImpl_GetCaps,
-       SecondaryBufferImpl_GetCurrentPosition,
-       SecondaryBufferImpl_GetFormat,
-       SecondaryBufferImpl_GetVolume,
-       SecondaryBufferImpl_GetPan,
-       SecondaryBufferImpl_GetFrequency,
-       SecondaryBufferImpl_GetStatus,
-       SecondaryBufferImpl_Initialize,
-       SecondaryBufferImpl_Lock,
-       SecondaryBufferImpl_Play,
-       SecondaryBufferImpl_SetCurrentPosition,
-       SecondaryBufferImpl_SetFormat,
-       SecondaryBufferImpl_SetVolume,
-       SecondaryBufferImpl_SetPan,
-       SecondaryBufferImpl_SetFrequency,
-       SecondaryBufferImpl_Stop,
-       SecondaryBufferImpl_Unlock,
-       SecondaryBufferImpl_Restore,
-       SecondaryBufferImpl_SetFX,
-       SecondaryBufferImpl_AcquireResources,
-       SecondaryBufferImpl_GetObjectInPath
-};
-
-HRESULT SecondaryBufferImpl_Create(
-       IDirectSoundBufferImpl *dsb,
-       SecondaryBufferImpl **psb)
-{
-       SecondaryBufferImpl *sb;
-       TRACE("(%p,%p)\n",dsb,psb);
-
-       sb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*sb));
-
-       if (sb == 0) {
-               WARN("out of memory\n");
-               *psb = NULL;
-               return DSERR_OUTOFMEMORY;
-       }
-       sb->ref = 0;
-       sb->dsb = dsb;
-       sb->lpVtbl = &sbvt;
-
-       IDirectSoundBuffer8_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
-       *psb = sb;
-       return S_OK;
-}
-
-static HRESULT SecondaryBufferImpl_Destroy(
-    SecondaryBufferImpl *pdsb)
-{
-    TRACE("(%p)\n",pdsb);
-
-    while (SecondaryBufferImpl_Release((LPDIRECTSOUNDBUFFER8)pdsb) > 0);
-
-    return S_OK;
-}
diff --git a/dll/directx/dsound/capture.c b/dll/directx/dsound/capture.c
deleted file mode 100644 (file)
index 312c90f..0000000
+++ /dev/null
@@ -1,1658 +0,0 @@
-/*              DirectSoundCapture
- *
- * Copyright 1998 Marcus Meissner
- * Copyright 1998 Rob Riggs
- * Copyright 2000-2001 TransGaming Technologies, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-/*
- * TODO:
- *     Implement FX support.
- *     Implement both IDirectSoundCaptureBuffer and IDirectSoundCaptureBuffer8
- *     Make DirectSoundCaptureCreate and DirectSoundCaptureCreate8 behave differently
- */
-
-#include <stdarg.h>
-
-#define NONAMELESSSTRUCT
-#define NONAMELESSUNION
-#include "windef.h"
-#include "winbase.h"
-#include "winuser.h"
-#include "mmsystem.h"
-#include "mmddk.h"
-#include "winternl.h"
-#include "winnls.h"
-#include "wine/debug.h"
-#include "dsound.h"
-#include "dsdriver.h"
-#include "dsound_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(dsound);
-
-/*****************************************************************************
- * IDirectSoundCapture implementation structure
- */
-struct IDirectSoundCaptureImpl
-{
-    /* IUnknown fields */
-    const IDirectSoundCaptureVtbl     *lpVtbl;
-    LONG                               ref;
-
-    DirectSoundCaptureDevice          *device;
-};
-
-static HRESULT IDirectSoundCaptureImpl_Create(LPDIRECTSOUNDCAPTURE8 * ppds);
-
-
-/*****************************************************************************
- * IDirectSoundCaptureNotify implementation structure
- */
-struct IDirectSoundCaptureNotifyImpl
-{
-    /* IUnknown fields */
-    const IDirectSoundNotifyVtbl       *lpVtbl;
-    LONG                                ref;
-    IDirectSoundCaptureBufferImpl*      dscb;
-};
-
-static HRESULT IDirectSoundCaptureNotifyImpl_Create(IDirectSoundCaptureBufferImpl *dscb,
-                                                    IDirectSoundCaptureNotifyImpl ** pdscn);
-
-
-DirectSoundCaptureDevice * DSOUND_capture[MAXWAVEDRIVERS];
-
-static HRESULT DirectSoundCaptureDevice_Create(DirectSoundCaptureDevice ** ppDevice);
-
-static const char * const captureStateString[] = {
-    "STATE_STOPPED",
-    "STATE_STARTING",
-    "STATE_CAPTURING",
-    "STATE_STOPPING"
-};
-
-HRESULT DSOUND_CaptureCreate(
-    REFIID riid,
-    LPDIRECTSOUNDCAPTURE *ppDSC)
-{
-    LPDIRECTSOUNDCAPTURE pDSC;
-    HRESULT hr;
-    TRACE("(%s, %p)\n", debugstr_guid(riid), ppDSC);
-
-    if (!IsEqualIID(riid, &IID_IUnknown) &&
-        !IsEqualIID(riid, &IID_IDirectSoundCapture)) {
-        *ppDSC = 0;
-        return E_NOINTERFACE;
-    }
-
-    /* Get dsound configuration */
-    setup_dsound_options();
-
-    hr = IDirectSoundCaptureImpl_Create(&pDSC);
-    if (hr == DS_OK) {
-        IDirectSoundCapture_AddRef(pDSC);
-        *ppDSC = pDSC;
-    } else {
-        WARN("IDirectSoundCaptureImpl_Create failed\n");
-        *ppDSC = 0;
-    }
-
-    return hr;
-}
-
-HRESULT DSOUND_CaptureCreate8(
-    REFIID riid,
-    LPDIRECTSOUNDCAPTURE8 *ppDSC8)
-{
-    LPDIRECTSOUNDCAPTURE8 pDSC8;
-    HRESULT hr;
-    TRACE("(%s, %p)\n", debugstr_guid(riid), ppDSC8);
-
-    if (!IsEqualIID(riid, &IID_IUnknown) &&
-        !IsEqualIID(riid, &IID_IDirectSoundCapture8)) {
-        *ppDSC8 = 0;
-        return E_NOINTERFACE;
-    }
-
-    /* Get dsound configuration */
-    setup_dsound_options();
-
-    hr = IDirectSoundCaptureImpl_Create(&pDSC8);
-    if (hr == DS_OK) {
-        IDirectSoundCapture_AddRef(pDSC8);
-        *ppDSC8 = pDSC8;
-    } else {
-        WARN("IDirectSoundCaptureImpl_Create failed\n");
-        *ppDSC8 = 0;
-    }
-
-    return hr;
-}
-
-/***************************************************************************
- * DirectSoundCaptureCreate [DSOUND.6]
- *
- * Create and initialize a DirectSoundCapture interface.
- *
- * PARAMS
- *    lpcGUID   [I] Address of the GUID that identifies the sound capture device.
- *    lplpDSC   [O] Address of a variable to receive the interface pointer.
- *    pUnkOuter [I] Must be NULL.
- *
- * RETURNS
- *    Success: DS_OK
- *    Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
- *             DSERR_OUTOFMEMORY
- *
- * NOTES
- *    lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
- *    or NULL for the default device or DSDEVID_DefaultCapture or
- *    DSDEVID_DefaultVoiceCapture.
- *
- *    DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
- */
-HRESULT WINAPI DirectSoundCaptureCreate(
-    LPCGUID lpcGUID,
-    LPDIRECTSOUNDCAPTURE *ppDSC,
-    LPUNKNOWN pUnkOuter)
-{
-    HRESULT hr;
-    LPDIRECTSOUNDCAPTURE pDSC;
-    TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), ppDSC, pUnkOuter);
-
-    if (ppDSC == NULL) {
-       WARN("invalid parameter: ppDSC == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (pUnkOuter) {
-       WARN("invalid parameter: pUnkOuter != NULL\n");
-        *ppDSC = NULL;
-        return DSERR_NOAGGREGATION;
-    }
-
-    hr = DSOUND_CaptureCreate(&IID_IDirectSoundCapture, &pDSC);
-    if (hr == DS_OK) {
-        hr = IDirectSoundCapture_Initialize(pDSC, lpcGUID);
-        if (hr != DS_OK) {
-            IDirectSoundCapture_Release(pDSC);
-            pDSC = 0;
-        }
-    }
-
-    *ppDSC = pDSC;
-
-    return hr;
-}
-
-/***************************************************************************
- * DirectSoundCaptureCreate8 [DSOUND.12]
- *
- * Create and initialize a DirectSoundCapture interface.
- *
- * PARAMS
- *    lpcGUID   [I] Address of the GUID that identifies the sound capture device.
- *    lplpDSC   [O] Address of a variable to receive the interface pointer.
- *    pUnkOuter [I] Must be NULL.
- *
- * RETURNS
- *    Success: DS_OK
- *    Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
- *             DSERR_OUTOFMEMORY
- *
- * NOTES
- *    lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
- *    or NULL for the default device or DSDEVID_DefaultCapture or
- *    DSDEVID_DefaultVoiceCapture.
- *
- *    DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
- */
-HRESULT WINAPI DirectSoundCaptureCreate8(
-    LPCGUID lpcGUID,
-    LPDIRECTSOUNDCAPTURE8 *ppDSC8,
-    LPUNKNOWN pUnkOuter)
-{
-    HRESULT hr;
-    LPDIRECTSOUNDCAPTURE8 pDSC8;
-    TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), ppDSC8, pUnkOuter);
-
-    if (ppDSC8 == NULL) {
-       WARN("invalid parameter: ppDSC8 == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (pUnkOuter) {
-       WARN("invalid parameter: pUnkOuter != NULL\n");
-        *ppDSC8 = NULL;
-        return DSERR_NOAGGREGATION;
-    }
-
-    hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, &pDSC8);
-    if (hr == DS_OK) {
-        hr = IDirectSoundCapture_Initialize(pDSC8, lpcGUID);
-        if (hr != DS_OK) {
-            IDirectSoundCapture_Release(pDSC8);
-            pDSC8 = 0;
-        }
-    }
-
-    *ppDSC8 = pDSC8;
-
-    return hr;
-}
-
-/***************************************************************************
- * DirectSoundCaptureEnumerateA [DSOUND.7]
- *
- * Enumerate all DirectSound drivers installed in the system.
- *
- * PARAMS
- *    lpDSEnumCallback  [I] Address of callback function.
- *    lpContext         [I] Address of user defined context passed to callback function.
- *
- * RETURNS
- *    Success: DS_OK
- *    Failure: DSERR_INVALIDPARAM
- */
-HRESULT WINAPI
-DirectSoundCaptureEnumerateA(
-    LPDSENUMCALLBACKA lpDSEnumCallback,
-    LPVOID lpContext)
-{
-    unsigned devs, wid;
-    DSDRIVERDESC desc;
-    GUID guid;
-    int err;
-
-    TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
-
-    if (lpDSEnumCallback == NULL) {
-       WARN("invalid parameter: lpDSEnumCallback == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    devs = waveInGetNumDevs();
-    if (devs > 0) {
-       if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
-           for (wid = 0; wid < devs; ++wid) {
-                if (IsEqualGUID( &guid, &DSOUND_capture_guids[wid] ) ) {
-                    err = mmErr(waveInMessage(UlongToHandle(wid),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
-                    if (err == DS_OK) {
-                        TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
-                              "Primary Sound Capture Driver",desc.szDrvname,lpContext);
-                        if (lpDSEnumCallback(NULL, "Primary Sound Capture Driver", desc.szDrvname, lpContext) == FALSE)
-                            return DS_OK;
-                    }
-                }
-           }
-       }
-    }
-
-    for (wid = 0; wid < devs; ++wid) {
-        err = mmErr(waveInMessage(UlongToHandle(wid),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
-       if (err == DS_OK) {
-            TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
-                  debugstr_guid(&DSOUND_capture_guids[wid]),desc.szDesc,desc.szDrvname,lpContext);
-            if (lpDSEnumCallback(&DSOUND_capture_guids[wid], desc.szDesc, desc.szDrvname, lpContext) == FALSE)
-                return DS_OK;
-       }
-    }
-
-    return DS_OK;
-}
-
-/***************************************************************************
- * DirectSoundCaptureEnumerateW [DSOUND.8]
- *
- * Enumerate all DirectSound drivers installed in the system.
- *
- * PARAMS
- *    lpDSEnumCallback  [I] Address of callback function.
- *    lpContext         [I] Address of user defined context passed to callback function.
- *
- * RETURNS
- *    Success: DS_OK
- *    Failure: DSERR_INVALIDPARAM
- */
-HRESULT WINAPI
-DirectSoundCaptureEnumerateW(
-    LPDSENUMCALLBACKW lpDSEnumCallback,
-    LPVOID lpContext)
-{
-    unsigned devs, wid;
-    DSDRIVERDESC desc;
-    GUID guid;
-    int err;
-    WCHAR wDesc[MAXPNAMELEN];
-    WCHAR wName[MAXPNAMELEN];
-
-    TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
-
-    if (lpDSEnumCallback == NULL) {
-       WARN("invalid parameter: lpDSEnumCallback == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    devs = waveInGetNumDevs();
-    if (devs > 0) {
-       if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
-           for (wid = 0; wid < devs; ++wid) {
-                if (IsEqualGUID( &guid, &DSOUND_capture_guids[wid] ) ) {
-                    err = mmErr(waveInMessage(UlongToHandle(wid),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
-                    if (err == DS_OK) {
-                        TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
-                              "Primary Sound Capture Driver",desc.szDrvname,lpContext);
-                        MultiByteToWideChar( CP_ACP, 0, "Primary Sound Capture Driver", -1,
-                                             wDesc, sizeof(wDesc)/sizeof(WCHAR) );
-                        MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
-                                             wName, sizeof(wName)/sizeof(WCHAR) );
-                        if (lpDSEnumCallback(NULL, wDesc, wName, lpContext) == FALSE)
-                            return DS_OK;
-                    }
-                }
-           }
-       }
-    }
-
-    for (wid = 0; wid < devs; ++wid) {
-        err = mmErr(waveInMessage(UlongToHandle(wid),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
-       if (err == DS_OK) {
-            TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
-                  debugstr_guid(&DSOUND_capture_guids[wid]),desc.szDesc,desc.szDrvname,lpContext);
-            MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
-                                 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
-            MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
-                                 wName, sizeof(wName)/sizeof(WCHAR) );
-            if (lpDSEnumCallback(&DSOUND_capture_guids[wid], wDesc, wName, lpContext) == FALSE)
-                return DS_OK;
-       }
-    }
-
-    return DS_OK;
-}
-
-static void capture_CheckNotify(IDirectSoundCaptureBufferImpl *This, DWORD from, DWORD len)
-{
-    int i;
-    for (i = 0; i < This->nrofnotifies; ++i) {
-        LPDSBPOSITIONNOTIFY event = This->notifies + i;
-        DWORD offset = event->dwOffset;
-        TRACE("checking %d, position %d, event = %p\n", i, offset, event->hEventNotify);
-
-        if (offset == DSBPN_OFFSETSTOP) {
-            if (!from && !len) {
-                SetEvent(event->hEventNotify);
-                TRACE("signalled event %p (%d)\n", event->hEventNotify, i);
-                return;
-            }
-            else return;
-        }
-
-        if (offset >= from && offset < (from + len))
-        {
-            TRACE("signalled event %p (%d)\n", event->hEventNotify, i);
-            SetEvent(event->hEventNotify);
-        }
-    }
-}
-
-static void CALLBACK
-DSOUND_capture_callback(HWAVEIN hwi, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1,
-                        DWORD_PTR dw2)
-{
-    DirectSoundCaptureDevice * This = (DirectSoundCaptureDevice*)dwUser;
-    IDirectSoundCaptureBufferImpl * Moi = This->capture_buffer;
-    TRACE("(%p,%08x(%s),%08lx,%08lx,%08lx) entering at %d\n",hwi,msg,
-       msg == MM_WIM_OPEN ? "MM_WIM_OPEN" : msg == MM_WIM_CLOSE ? "MM_WIM_CLOSE" :
-       msg == MM_WIM_DATA ? "MM_WIM_DATA" : "UNKNOWN",dwUser,dw1,dw2,GetTickCount());
-
-    if (msg == MM_WIM_DATA) {
-       EnterCriticalSection( &(This->lock) );
-       TRACE("DirectSoundCapture msg=MM_WIM_DATA, old This->state=%s, old This->index=%d\n",
-           captureStateString[This->state],This->index);
-       if (This->state != STATE_STOPPED) {
-           int index = This->index;
-           if (This->state == STATE_STARTING)
-               This->state = STATE_CAPTURING;
-           capture_CheckNotify(Moi, (DWORD_PTR)This->pwave[index].lpData - (DWORD_PTR)This->buffer, This->pwave[index].dwBufferLength);
-           This->index = (This->index + 1) % This->nrofpwaves;
-           if ( (This->index == 0) && !(This->capture_buffer->flags & DSCBSTART_LOOPING) ) {
-               TRACE("end of buffer\n");
-               This->state = STATE_STOPPED;
-               capture_CheckNotify(Moi, 0, 0);
-           } else {
-               if (This->state == STATE_CAPTURING) {
-                   waveInUnprepareHeader(hwi, &(This->pwave[index]), sizeof(WAVEHDR));
-                   waveInPrepareHeader(hwi, &(This->pwave[index]), sizeof(WAVEHDR));
-                   waveInAddBuffer(hwi, &(This->pwave[index]), sizeof(WAVEHDR));
-               } else if (This->state == STATE_STOPPING) {
-                   TRACE("stopping\n");
-                   This->state = STATE_STOPPED;
-               }
-           }
-       }
-       TRACE("DirectSoundCapture new This->state=%s, new This->index=%d\n",
-           captureStateString[This->state],This->index);
-       LeaveCriticalSection( &(This->lock) );
-    }
-
-    TRACE("completed\n");
-}
-
-/***************************************************************************
- * IDirectSoundCaptureImpl
- */
-static HRESULT WINAPI
-IDirectSoundCaptureImpl_QueryInterface(
-    LPDIRECTSOUNDCAPTURE iface,
-    REFIID riid,
-    LPVOID* ppobj )
-{
-    IDirectSoundCaptureImpl *This = (IDirectSoundCaptureImpl *)iface;
-    TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
-
-    if (ppobj == NULL) {
-       WARN("invalid parameter\n");
-       return E_INVALIDARG;
-    }
-
-    *ppobj = NULL;
-
-    if (IsEqualIID(riid, &IID_IUnknown)) {
-        IDirectSoundCapture_AddRef((LPDIRECTSOUNDCAPTURE)This);
-        *ppobj = This;
-        return DS_OK;
-    } else if (IsEqualIID(riid, &IID_IDirectSoundCapture)) {
-        IDirectSoundCapture_AddRef((LPDIRECTSOUNDCAPTURE)This);
-        *ppobj = This;
-        return DS_OK;
-    }
-
-    WARN("unsupported riid: %s\n", debugstr_guid(riid));
-    return E_NOINTERFACE;
-}
-
-static ULONG WINAPI
-IDirectSoundCaptureImpl_AddRef( LPDIRECTSOUNDCAPTURE iface )
-{
-    IDirectSoundCaptureImpl *This = (IDirectSoundCaptureImpl *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI
-IDirectSoundCaptureImpl_Release( LPDIRECTSOUNDCAPTURE iface )
-{
-    IDirectSoundCaptureImpl *This = (IDirectSoundCaptureImpl *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-
-    if (!ref) {
-        if (This->device)
-            DirectSoundCaptureDevice_Release(This->device);
-
-        HeapFree( GetProcessHeap(), 0, This );
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-HRESULT WINAPI IDirectSoundCaptureImpl_CreateCaptureBuffer(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPCDSCBUFFERDESC lpcDSCBufferDesc,
-    LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
-    LPUNKNOWN pUnk )
-{
-    HRESULT hr;
-    IDirectSoundCaptureImpl *This = (IDirectSoundCaptureImpl *)iface;
-
-    TRACE( "(%p,%p,%p,%p)\n",iface,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk);
-
-    if (lpcDSCBufferDesc == NULL) {
-       WARN("invalid parameter: lpcDSCBufferDesc == NULL)\n");
-       return DSERR_INVALIDPARAM;
-    }
-
-    if (lplpDSCaptureBuffer == NULL) {
-       WARN("invalid parameter: lplpDSCaptureBuffer == NULL\n");
-       return DSERR_INVALIDPARAM;
-    }
-
-    if (pUnk != NULL) {
-       WARN("invalid parameter: pUnk != NULL\n");
-       return DSERR_INVALIDPARAM;
-    }
-
-    /* FIXME: We can only have one buffer so what do we do here? */
-    if (This->device->capture_buffer) {
-       WARN("lnvalid parameter: already has buffer\n");
-       return DSERR_INVALIDPARAM;    /* DSERR_GENERIC ? */
-    }
-
-    hr = IDirectSoundCaptureBufferImpl_Create(This->device,
-        (IDirectSoundCaptureBufferImpl **)lplpDSCaptureBuffer, lpcDSCBufferDesc);
-
-    if (hr != DS_OK)
-       WARN("IDirectSoundCaptureBufferImpl_Create failed\n");
-
-    return hr;
-}
-
-HRESULT WINAPI IDirectSoundCaptureImpl_GetCaps(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPDSCCAPS lpDSCCaps )
-{
-    IDirectSoundCaptureImpl *This = (IDirectSoundCaptureImpl *)iface;
-    TRACE("(%p,%p)\n",This,lpDSCCaps);
-
-    if (This->device == NULL) {
-       WARN("not initialized\n");
-       return DSERR_UNINITIALIZED;
-    }
-
-    if (lpDSCCaps== NULL) {
-       WARN("invalid parameter: lpDSCCaps== NULL\n");
-       return DSERR_INVALIDPARAM;
-    }
-
-    if (lpDSCCaps->dwSize < sizeof(*lpDSCCaps)) {
-       WARN("invalid parameter: lpDSCCaps->dwSize = %d\n", lpDSCCaps->dwSize);
-       return DSERR_INVALIDPARAM;
-    }
-
-    lpDSCCaps->dwFlags = This->device->drvcaps.dwFlags;
-    lpDSCCaps->dwFormats = This->device->drvcaps.dwFormats;
-    lpDSCCaps->dwChannels = This->device->drvcaps.dwChannels;
-
-    TRACE("(flags=0x%08x,format=0x%08x,channels=%d)\n",lpDSCCaps->dwFlags,
-        lpDSCCaps->dwFormats, lpDSCCaps->dwChannels);
-
-    return DS_OK;
-}
-
-HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPCGUID lpcGUID )
-{
-    IDirectSoundCaptureImpl *This = (IDirectSoundCaptureImpl *)iface;
-    TRACE("(%p,%s)\n", This, debugstr_guid(lpcGUID));
-
-    if (This->device != NULL) {
-       WARN("already initialized\n");
-       return DSERR_ALREADYINITIALIZED;
-    }
-    return DirectSoundCaptureDevice_Initialize(&This->device, lpcGUID);
-}
-
-static const IDirectSoundCaptureVtbl dscvt =
-{
-    /* IUnknown methods */
-    IDirectSoundCaptureImpl_QueryInterface,
-    IDirectSoundCaptureImpl_AddRef,
-    IDirectSoundCaptureImpl_Release,
-
-    /* IDirectSoundCapture methods */
-    IDirectSoundCaptureImpl_CreateCaptureBuffer,
-    IDirectSoundCaptureImpl_GetCaps,
-    IDirectSoundCaptureImpl_Initialize
-};
-
-static HRESULT IDirectSoundCaptureImpl_Create(
-    LPDIRECTSOUNDCAPTURE8 * ppDSC)
-{
-    IDirectSoundCaptureImpl *pDSC;
-    TRACE("(%p)\n", ppDSC);
-
-    /* Allocate memory */
-    pDSC = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectSoundCaptureImpl));
-    if (pDSC == NULL) {
-        WARN("out of memory\n");
-        *ppDSC = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pDSC->lpVtbl = &dscvt;
-    pDSC->ref    = 0;
-    pDSC->device = NULL;
-
-    *ppDSC = (LPDIRECTSOUNDCAPTURE8)pDSC;
-
-    return DS_OK;
-}
-
-/*******************************************************************************
- *             IDirectSoundCaptureNotify
- */
-static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_QueryInterface(
-    LPDIRECTSOUNDNOTIFY iface,
-    REFIID riid,
-    LPVOID *ppobj)
-{
-    IDirectSoundCaptureNotifyImpl *This = (IDirectSoundCaptureNotifyImpl *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-
-    if (This->dscb == NULL) {
-       WARN("invalid parameter\n");
-       return E_INVALIDARG;
-    }
-
-    return IDirectSoundCaptureBuffer_QueryInterface((LPDIRECTSOUNDCAPTUREBUFFER)This->dscb, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSoundCaptureNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface)
-{
-    IDirectSoundCaptureNotifyImpl *This = (IDirectSoundCaptureNotifyImpl *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSoundCaptureNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface)
-{
-    IDirectSoundCaptureNotifyImpl *This = (IDirectSoundCaptureNotifyImpl *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-
-    if (!ref) {
-        if (This->dscb->hwnotify)
-            IDsDriverNotify_Release(This->dscb->hwnotify);
-       This->dscb->notify=NULL;
-       IDirectSoundCaptureBuffer_Release((LPDIRECTSOUNDCAPTUREBUFFER)This->dscb);
-       HeapFree(GetProcessHeap(),0,This);
-       TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_SetNotificationPositions(
-    LPDIRECTSOUNDNOTIFY iface,
-    DWORD howmuch,
-    LPCDSBPOSITIONNOTIFY notify)
-{
-    IDirectSoundCaptureNotifyImpl *This = (IDirectSoundCaptureNotifyImpl *)iface;
-    TRACE("(%p,0x%08x,%p)\n",This,howmuch,notify);
-
-    if (howmuch > 0 && notify == NULL) {
-       WARN("invalid parameter: notify == NULL\n");
-       return DSERR_INVALIDPARAM;
-    }
-
-    if (TRACE_ON(dsound)) {
-       unsigned int i;
-       for (i=0;i<howmuch;i++)
-            TRACE("notify at %d to %p\n",
-           notify[i].dwOffset,notify[i].hEventNotify);
-    }
-
-    if (This->dscb->hwnotify) {
-       HRESULT hres;
-       hres = IDsDriverNotify_SetNotificationPositions(This->dscb->hwnotify, howmuch, notify);
-       if (hres != DS_OK)
-           WARN("IDsDriverNotify_SetNotificationPositions failed\n");
-       return hres;
-    } else if (howmuch > 0) {
-       /* Make an internal copy of the caller-supplied array.
-        * Replace the existing copy if one is already present. */
-       if (This->dscb->notifies)
-           This->dscb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-               This->dscb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
-       else
-           This->dscb->notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-               howmuch * sizeof(DSBPOSITIONNOTIFY));
-
-       if (This->dscb->notifies == NULL) {
-           WARN("out of memory\n");
-           return DSERR_OUTOFMEMORY;
-       }
-       CopyMemory(This->dscb->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
-       This->dscb->nrofnotifies = howmuch;
-    } else {
-        HeapFree(GetProcessHeap(), 0, This->dscb->notifies);
-        This->dscb->notifies = NULL;
-        This->dscb->nrofnotifies = 0;
-    }
-
-    return S_OK;
-}
-
-static const IDirectSoundNotifyVtbl dscnvt =
-{
-    IDirectSoundCaptureNotifyImpl_QueryInterface,
-    IDirectSoundCaptureNotifyImpl_AddRef,
-    IDirectSoundCaptureNotifyImpl_Release,
-    IDirectSoundCaptureNotifyImpl_SetNotificationPositions,
-};
-
-static HRESULT IDirectSoundCaptureNotifyImpl_Create(
-    IDirectSoundCaptureBufferImpl *dscb,
-    IDirectSoundCaptureNotifyImpl **pdscn)
-{
-    IDirectSoundCaptureNotifyImpl * dscn;
-    TRACE("(%p,%p)\n",dscb,pdscn);
-
-    dscn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*dscn));
-
-    if (dscn == NULL) {
-       WARN("out of memory\n");
-       return DSERR_OUTOFMEMORY;
-    }
-
-    dscn->ref = 0;
-    dscn->lpVtbl = &dscnvt;
-    dscn->dscb = dscb;
-    dscb->notify = dscn;
-    IDirectSoundCaptureBuffer_AddRef((LPDIRECTSOUNDCAPTUREBUFFER)dscb);
-
-    *pdscn = dscn;
-    return DS_OK;
-}
-
-/*******************************************************************************
- *             IDirectSoundCaptureBuffer
- */
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_QueryInterface(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    REFIID riid,
-    LPVOID* ppobj )
-{
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    HRESULT hres;
-    TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
-
-    if (ppobj == NULL) {
-       WARN("invalid parameter\n");
-       return E_INVALIDARG;
-    }
-
-    *ppobj = NULL;
-
-    if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
-       if (!This->notify)
-           hres = IDirectSoundCaptureNotifyImpl_Create(This, &This->notify);
-       if (This->notify) {
-           IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
-           if (This->device->hwbuf && !This->hwnotify) {
-               hres = IDsCaptureDriverBuffer_QueryInterface(This->device->hwbuf,
-                   &IID_IDsDriverNotify, (LPVOID*)&(This->hwnotify));
-               if (hres != DS_OK) {
-                   WARN("IDsCaptureDriverBuffer_QueryInterface failed\n");
-                   IDirectSoundNotify_Release((LPDIRECTSOUNDNOTIFY)This->notify);
-                   *ppobj = 0;
-                   return hres;
-               }
-           }
-
-            *ppobj = This->notify;
-           return DS_OK;
-       }
-
-       WARN("IID_IDirectSoundNotify\n");
-       return E_FAIL;
-    }
-
-    if ( IsEqualGUID( &IID_IDirectSoundCaptureBuffer, riid ) ||
-         IsEqualGUID( &IID_IDirectSoundCaptureBuffer8, riid ) ) {
-       IDirectSoundCaptureBuffer8_AddRef(iface);
-       *ppobj = This;
-       return NO_ERROR;
-    }
-
-    FIXME("(%p,%s,%p) unsupported GUID\n", This, debugstr_guid(riid), ppobj);
-    return E_NOINTERFACE;
-}
-
-static ULONG WINAPI
-IDirectSoundCaptureBufferImpl_AddRef( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
-{
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI
-IDirectSoundCaptureBufferImpl_Release( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
-{
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-
-    if (!ref) {
-        TRACE("deleting object\n");
-       if (This->device->state == STATE_CAPTURING)
-           This->device->state = STATE_STOPPING;
-
-        HeapFree(GetProcessHeap(),0, This->pdscbd);
-
-       if (This->device->hwi) {
-           waveInReset(This->device->hwi);
-           waveInClose(This->device->hwi);
-            HeapFree(GetProcessHeap(),0, This->device->pwave);
-            This->device->pwave = 0;
-           This->device->hwi = 0;
-       }
-
-       if (This->device->hwbuf)
-           IDsCaptureDriverBuffer_Release(This->device->hwbuf);
-
-        /* remove from DirectSoundCaptureDevice */
-        This->device->capture_buffer = NULL;
-
-        if (This->notify)
-           IDirectSoundNotify_Release((LPDIRECTSOUNDNOTIFY)This->notify);
-
-        /* If driver manages its own buffer, IDsCaptureDriverBuffer_Release
-           should have freed the buffer. Prevent freeing it again in
-           IDirectSoundCaptureBufferImpl_Create */
-        if (!(This->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY))
-           This->device->buffer = NULL;
-
-       HeapFree(GetProcessHeap(), 0, This->notifies);
-        HeapFree( GetProcessHeap(), 0, This );
-       TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_GetCaps(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    LPDSCBCAPS lpDSCBCaps )
-{
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    TRACE( "(%p,%p)\n", This, lpDSCBCaps );
-
-    if (lpDSCBCaps == NULL) {
-        WARN("invalid parameter: lpDSCBCaps == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (lpDSCBCaps->dwSize < sizeof(DSCBCAPS)) {
-        WARN("invalid parameter: lpDSCBCaps->dwSize = %d\n", lpDSCBCaps->dwSize);
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (This->device == NULL) {
-        WARN("invalid parameter: This->device == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    lpDSCBCaps->dwSize = sizeof(DSCBCAPS);
-    lpDSCBCaps->dwFlags = This->flags;
-    lpDSCBCaps->dwBufferBytes = This->pdscbd->dwBufferBytes;
-    lpDSCBCaps->dwReserved = 0;
-
-    TRACE("returning DS_OK\n");
-    return DS_OK;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_GetCurrentPosition(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    LPDWORD lpdwCapturePosition,
-    LPDWORD lpdwReadPosition )
-{
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    HRESULT hres = DS_OK;
-    TRACE( "(%p,%p,%p)\n", This, lpdwCapturePosition, lpdwReadPosition );
-
-    if (This->device == NULL) {
-        WARN("invalid parameter: This->device == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (This->device->driver) {
-        hres = IDsCaptureDriverBuffer_GetPosition(This->device->hwbuf, lpdwCapturePosition, lpdwReadPosition );
-       if (hres != DS_OK)
-           WARN("IDsCaptureDriverBuffer_GetPosition failed\n");
-    } else if (This->device->hwi) {
-        DWORD pos;
-
-        EnterCriticalSection(&This->device->lock);
-        pos = (DWORD_PTR)This->device->pwave[This->device->index].lpData - (DWORD_PTR)This->device->buffer;
-        if (lpdwCapturePosition)
-            *lpdwCapturePosition = (This->device->pwave[This->device->index].dwBufferLength + pos) % This->device->buflen;
-        if (lpdwReadPosition)
-            *lpdwReadPosition = pos;
-        LeaveCriticalSection(&This->device->lock);
-
-    } else {
-        WARN("no driver\n");
-        hres = DSERR_NODRIVER;
-    }
-
-    TRACE("cappos=%d readpos=%d\n", (lpdwCapturePosition?*lpdwCapturePosition:-1), (lpdwReadPosition?*lpdwReadPosition:-1));
-    TRACE("returning %08x\n", hres);
-    return hres;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_GetFormat(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    LPWAVEFORMATEX lpwfxFormat,
-    DWORD dwSizeAllocated,
-    LPDWORD lpdwSizeWritten )
-{
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    HRESULT hres = DS_OK;
-    TRACE( "(%p,%p,0x%08x,%p)\n", This, lpwfxFormat, dwSizeAllocated,
-        lpdwSizeWritten );
-
-    if (This->device == NULL) {
-        WARN("invalid parameter: This->device == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (dwSizeAllocated > (sizeof(WAVEFORMATEX) + This->device->pwfx->cbSize))
-        dwSizeAllocated = sizeof(WAVEFORMATEX) + This->device->pwfx->cbSize;
-
-    if (lpwfxFormat) { /* NULL is valid (just want size) */
-        CopyMemory(lpwfxFormat, This->device->pwfx, dwSizeAllocated);
-        if (lpdwSizeWritten)
-            *lpdwSizeWritten = dwSizeAllocated;
-    } else {
-        if (lpdwSizeWritten)
-            *lpdwSizeWritten = sizeof(WAVEFORMATEX) + This->device->pwfx->cbSize;
-        else {
-            TRACE("invalid parameter: lpdwSizeWritten = NULL\n");
-            hres = DSERR_INVALIDPARAM;
-        }
-    }
-
-    TRACE("returning %08x\n", hres);
-    return hres;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_GetStatus(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    LPDWORD lpdwStatus )
-{
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    TRACE( "(%p, %p), thread is %04x\n", This, lpdwStatus, GetCurrentThreadId() );
-
-    if (This->device == NULL) {
-        WARN("invalid parameter: This->device == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (lpdwStatus == NULL) {
-        WARN("invalid parameter: lpdwStatus == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    *lpdwStatus = 0;
-    EnterCriticalSection(&(This->device->lock));
-
-    TRACE("old This->device->state=%s, old lpdwStatus=%08x\n",
-       captureStateString[This->device->state],*lpdwStatus);
-    if ((This->device->state == STATE_STARTING) ||
-        (This->device->state == STATE_CAPTURING)) {
-        *lpdwStatus |= DSCBSTATUS_CAPTURING;
-        if (This->flags & DSCBSTART_LOOPING)
-            *lpdwStatus |= DSCBSTATUS_LOOPING;
-    }
-    TRACE("new This->device->state=%s, new lpdwStatus=%08x\n",
-       captureStateString[This->device->state],*lpdwStatus);
-    LeaveCriticalSection(&(This->device->lock));
-
-    TRACE("status=%x\n", *lpdwStatus);
-    TRACE("returning DS_OK\n");
-    return DS_OK;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_Initialize(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    LPDIRECTSOUNDCAPTURE lpDSC,
-    LPCDSCBUFFERDESC lpcDSCBDesc )
-{
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-
-    FIXME( "(%p,%p,%p): stub\n", This, lpDSC, lpcDSCBDesc );
-
-    return DS_OK;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_Lock(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    DWORD dwReadCusor,
-    DWORD dwReadBytes,
-    LPVOID* lplpvAudioPtr1,
-    LPDWORD lpdwAudioBytes1,
-    LPVOID* lplpvAudioPtr2,
-    LPDWORD lpdwAudioBytes2,
-    DWORD dwFlags )
-{
-    HRESULT hres = DS_OK;
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    TRACE( "(%p,%08u,%08u,%p,%p,%p,%p,0x%08x) at %d\n", This, dwReadCusor,
-        dwReadBytes, lplpvAudioPtr1, lpdwAudioBytes1, lplpvAudioPtr2,
-        lpdwAudioBytes2, dwFlags, GetTickCount() );
-
-    if (This->device == NULL) {
-        WARN("invalid parameter: This->device == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (lplpvAudioPtr1 == NULL) {
-        WARN("invalid parameter: lplpvAudioPtr1 == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (lpdwAudioBytes1 == NULL) {
-        WARN("invalid parameter: lpdwAudioBytes1 == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    EnterCriticalSection(&(This->device->lock));
-
-    if (This->device->driver) {
-        hres = IDsCaptureDriverBuffer_Lock(This->device->hwbuf, lplpvAudioPtr1,
-                                           lpdwAudioBytes1, lplpvAudioPtr2,
-                                           lpdwAudioBytes2, dwReadCusor,
-                                           dwReadBytes, dwFlags);
-       if (hres != DS_OK)
-           WARN("IDsCaptureDriverBuffer_Lock failed\n");
-    } else if (This->device->hwi) {
-        *lplpvAudioPtr1 = This->device->buffer + dwReadCusor;
-        if ( (dwReadCusor + dwReadBytes) > This->device->buflen) {
-            *lpdwAudioBytes1 = This->device->buflen - dwReadCusor;
-           if (lplpvAudioPtr2)
-               *lplpvAudioPtr2 = This->device->buffer;
-           if (lpdwAudioBytes2)
-               *lpdwAudioBytes2 = dwReadBytes - *lpdwAudioBytes1;
-        } else {
-            *lpdwAudioBytes1 = dwReadBytes;
-           if (lplpvAudioPtr2)
-               *lplpvAudioPtr2 = 0;
-           if (lpdwAudioBytes2)
-               *lpdwAudioBytes2 = 0;
-        }
-    } else {
-        TRACE("invalid call\n");
-        hres = DSERR_INVALIDCALL;   /* DSERR_NODRIVER ? */
-    }
-
-    LeaveCriticalSection(&(This->device->lock));
-
-    TRACE("returning %08x\n", hres);
-    return hres;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_Start(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    DWORD dwFlags )
-{
-    HRESULT hres = DS_OK;
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    TRACE( "(%p,0x%08x)\n", This, dwFlags );
-
-    if (This->device == NULL) {
-        WARN("invalid parameter: This->device == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if ( (This->device->driver == 0) && (This->device->hwi == 0) ) {
-        WARN("no driver\n");
-        return DSERR_NODRIVER;
-    }
-
-    EnterCriticalSection(&(This->device->lock));
-
-    This->flags = dwFlags;
-    TRACE("old This->state=%s\n",captureStateString[This->device->state]);
-    if (This->device->state == STATE_STOPPED)
-        This->device->state = STATE_STARTING;
-    else if (This->device->state == STATE_STOPPING)
-        This->device->state = STATE_CAPTURING;
-    TRACE("new This->device->state=%s\n",captureStateString[This->device->state]);
-
-    LeaveCriticalSection(&(This->device->lock));
-
-    if (This->device->driver) {
-        hres = IDsCaptureDriverBuffer_Start(This->device->hwbuf, dwFlags);
-       if (hres != DS_OK)
-           WARN("IDsCaptureDriverBuffer_Start failed\n");
-    } else if (This->device->hwi) {
-        DirectSoundCaptureDevice *device = This->device;
-
-        if (device->buffer) {
-            int c;
-            DWORD blocksize = DSOUND_fraglen(device->pwfx->nSamplesPerSec, device->pwfx->nBlockAlign);
-            device->nrofpwaves = device->buflen / blocksize + !!(device->buflen % blocksize);
-            TRACE("nrofpwaves=%d\n", device->nrofpwaves);
-
-            /* prepare headers */
-            if (device->pwave)
-                device->pwave = HeapReAlloc(GetProcessHeap(), 0,device->pwave, device->nrofpwaves*sizeof(WAVEHDR));
-            else
-                device->pwave = HeapAlloc(GetProcessHeap(), 0, device->nrofpwaves*sizeof(WAVEHDR));
-
-            for (c = 0; c < device->nrofpwaves; ++c) {
-                device->pwave[c].lpData = (char *)device->buffer + c * blocksize;
-                if (c + 1 == device->nrofpwaves)
-                    device->pwave[c].dwBufferLength = device->buflen - c * blocksize;
-                else
-                    device->pwave[c].dwBufferLength = blocksize;
-                device->pwave[c].dwBytesRecorded = 0;
-                device->pwave[c].dwUser = (DWORD_PTR)device;
-                device->pwave[c].dwFlags = 0;
-                device->pwave[c].dwLoops = 0;
-                hres = mmErr(waveInPrepareHeader(device->hwi, &(device->pwave[c]),sizeof(WAVEHDR)));
-                if (hres != DS_OK) {
-                    WARN("waveInPrepareHeader failed\n");
-                    while (c--)
-                        waveInUnprepareHeader(device->hwi, &(device->pwave[c]),sizeof(WAVEHDR));
-                    break;
-                }
-
-                hres = mmErr(waveInAddBuffer(device->hwi, &(device->pwave[c]), sizeof(WAVEHDR)));
-                if (hres != DS_OK) {
-                    WARN("waveInAddBuffer failed\n");
-                    while (c--)
-                        waveInUnprepareHeader(device->hwi, &(device->pwave[c]),sizeof(WAVEHDR));
-                    break;
-                }
-            }
-
-            FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0);
-        }
-
-        device->index = 0;
-
-       if (hres == DS_OK) {
-           /* start filling the first buffer */
-           hres = mmErr(waveInStart(device->hwi));
-            if (hres != DS_OK)
-                WARN("waveInStart failed\n");
-        }
-
-        if (hres != DS_OK) {
-            WARN("calling waveInClose because of error\n");
-            waveInClose(device->hwi);
-            device->hwi = 0;
-        }
-    } else {
-        WARN("no driver\n");
-        hres = DSERR_NODRIVER;
-    }
-
-    TRACE("returning %08x\n", hres);
-    return hres;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_Stop( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
-{
-    HRESULT hres = DS_OK;
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    TRACE( "(%p)\n", This );
-
-    if (This->device == NULL) {
-        WARN("invalid parameter: This->device == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    EnterCriticalSection(&(This->device->lock));
-
-    TRACE("old This->device->state=%s\n",captureStateString[This->device->state]);
-    if (This->device->state == STATE_CAPTURING)
-       This->device->state = STATE_STOPPING;
-    else if (This->device->state == STATE_STARTING)
-       This->device->state = STATE_STOPPED;
-    TRACE("new This->device->state=%s\n",captureStateString[This->device->state]);
-
-    LeaveCriticalSection(&(This->device->lock));
-
-    if (This->device->driver) {
-        hres = IDsCaptureDriverBuffer_Stop(This->device->hwbuf);
-        if (hres != DS_OK)
-            WARN("IDsCaptureDriverBuffer_Stop() failed\n");
-    } else if (This->device->hwi) {
-        hres = mmErr(waveInReset(This->device->hwi));
-        if (hres != DS_OK)
-            WARN("waveInReset() failed\n");
-    } else {
-       WARN("no driver\n");
-        hres = DSERR_NODRIVER;
-    }
-
-    TRACE("returning %08x\n", hres);
-    return hres;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_Unlock(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    LPVOID lpvAudioPtr1,
-    DWORD dwAudioBytes1,
-    LPVOID lpvAudioPtr2,
-    DWORD dwAudioBytes2 )
-{
-    HRESULT hres = DS_OK;
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    TRACE( "(%p,%p,%08u,%p,%08u)\n", This, lpvAudioPtr1, dwAudioBytes1,
-        lpvAudioPtr2, dwAudioBytes2 );
-
-    if (lpvAudioPtr1 == NULL) {
-        WARN("invalid parameter: lpvAudioPtr1 == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (This->device->driver) {
-        hres = IDsCaptureDriverBuffer_Unlock(This->device->hwbuf, lpvAudioPtr1,
-                                             dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
-       if (hres != DS_OK)
-           WARN("IDsCaptureDriverBuffer_Unlock failed\n");
-    } else if (!This->device->hwi) {
-        WARN("invalid call\n");
-        hres = DSERR_INVALIDCALL;
-    }
-
-    TRACE("returning %08x\n", hres);
-    return hres;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_GetObjectInPath(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    REFGUID rguidObject,
-    DWORD dwIndex,
-    REFGUID rguidInterface,
-    LPVOID* ppObject )
-{
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-
-    FIXME( "(%p,%s,%u,%s,%p): stub\n", This, debugstr_guid(rguidObject),
-        dwIndex, debugstr_guid(rguidInterface), ppObject );
-
-    return DS_OK;
-}
-
-static HRESULT WINAPI
-IDirectSoundCaptureBufferImpl_GetFXStatus(
-    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
-    DWORD dwFXCount,
-    LPDWORD pdwFXStatus )
-{
-    IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-
-    FIXME( "(%p,%u,%p): stub\n", This, dwFXCount, pdwFXStatus );
-
-    return DS_OK;
-}
-
-static const IDirectSoundCaptureBuffer8Vtbl dscbvt =
-{
-    /* IUnknown methods */
-    IDirectSoundCaptureBufferImpl_QueryInterface,
-    IDirectSoundCaptureBufferImpl_AddRef,
-    IDirectSoundCaptureBufferImpl_Release,
-
-    /* IDirectSoundCaptureBuffer methods */
-    IDirectSoundCaptureBufferImpl_GetCaps,
-    IDirectSoundCaptureBufferImpl_GetCurrentPosition,
-    IDirectSoundCaptureBufferImpl_GetFormat,
-    IDirectSoundCaptureBufferImpl_GetStatus,
-    IDirectSoundCaptureBufferImpl_Initialize,
-    IDirectSoundCaptureBufferImpl_Lock,
-    IDirectSoundCaptureBufferImpl_Start,
-    IDirectSoundCaptureBufferImpl_Stop,
-    IDirectSoundCaptureBufferImpl_Unlock,
-
-    /* IDirectSoundCaptureBuffer methods */
-    IDirectSoundCaptureBufferImpl_GetObjectInPath,
-    IDirectSoundCaptureBufferImpl_GetFXStatus
-};
-
-HRESULT IDirectSoundCaptureBufferImpl_Create(
-    DirectSoundCaptureDevice *device,
-    IDirectSoundCaptureBufferImpl ** ppobj,
-    LPCDSCBUFFERDESC lpcDSCBufferDesc)
-{
-    LPWAVEFORMATEX  wfex;
-    TRACE( "(%p,%p,%p)\n", device, ppobj, lpcDSCBufferDesc);
-
-    if (ppobj == NULL) {
-       WARN("invalid parameter: ppobj == NULL\n");
-       return DSERR_INVALIDPARAM;
-    }
-
-    if (!device) {
-       WARN("not initialized\n");
-        *ppobj = NULL;
-       return DSERR_UNINITIALIZED;
-    }
-
-    if (lpcDSCBufferDesc == NULL) {
-       WARN("invalid parameter: lpcDSCBufferDesc == NULL\n");
-        *ppobj = NULL;
-       return DSERR_INVALIDPARAM;
-    }
-
-    if ( ((lpcDSCBufferDesc->dwSize != sizeof(DSCBUFFERDESC)) &&
-          (lpcDSCBufferDesc->dwSize != sizeof(DSCBUFFERDESC1))) ||
-        (lpcDSCBufferDesc->dwBufferBytes == 0) ||
-        (lpcDSCBufferDesc->lpwfxFormat == NULL) ) {
-       WARN("invalid lpcDSCBufferDesc\n");
-       *ppobj = NULL;
-       return DSERR_INVALIDPARAM;
-    }
-
-    wfex = lpcDSCBufferDesc->lpwfxFormat;
-
-    if (wfex) {
-        TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
-            "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
-            wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
-            wfex->nAvgBytesPerSec, wfex->nBlockAlign,
-            wfex->wBitsPerSample, wfex->cbSize);
-
-        if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
-           device->pwfx = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEFORMATEX));
-            *device->pwfx = *wfex;
-           device->pwfx->cbSize = 0;
-       } else {
-           device->pwfx = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEFORMATEX)+wfex->cbSize);
-            CopyMemory(device->pwfx, wfex, sizeof(WAVEFORMATEX)+wfex->cbSize);
-        }
-    } else {
-       WARN("lpcDSCBufferDesc->lpwfxFormat == 0\n");
-       *ppobj = NULL;
-       return DSERR_INVALIDPARAM; /* FIXME: DSERR_BADFORMAT ? */
-    }
-
-    *ppobj = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
-        sizeof(IDirectSoundCaptureBufferImpl));
-
-    if ( *ppobj == NULL ) {
-       WARN("out of memory\n");
-       *ppobj = NULL;
-       return DSERR_OUTOFMEMORY;
-    } else {
-       HRESULT err = DS_OK;
-        LPBYTE newbuf;
-        DWORD buflen;
-        IDirectSoundCaptureBufferImpl *This = *ppobj;
-
-        This->ref = 1;
-        This->device = device;
-        This->device->capture_buffer = This;
-       This->notify = NULL;
-       This->nrofnotifies = 0;
-       This->hwnotify = NULL;
-
-        This->pdscbd = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
-            lpcDSCBufferDesc->dwSize);
-        if (This->pdscbd)
-            CopyMemory(This->pdscbd, lpcDSCBufferDesc, lpcDSCBufferDesc->dwSize);
-        else {
-            WARN("no memory\n");
-            This->device->capture_buffer = 0;
-            HeapFree( GetProcessHeap(), 0, This );
-            *ppobj = NULL;
-            return DSERR_OUTOFMEMORY;
-        }
-
-        This->lpVtbl = &dscbvt;
-
-       if (device->driver) {
-            if (This->device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMOPEN)
-                FIXME("DSDDESC_DOMMSYSTEMOPEN not supported\n");
-
-            if (This->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
-                /* allocate buffer from system memory */
-                buflen = lpcDSCBufferDesc->dwBufferBytes;
-                TRACE("desired buflen=%d, old buffer=%p\n", buflen, device->buffer);
-                if (device->buffer)
-                    newbuf = HeapReAlloc(GetProcessHeap(),0,device->buffer,buflen);
-                else
-                    newbuf = HeapAlloc(GetProcessHeap(),0,buflen);
-
-                if (newbuf == NULL) {
-                    WARN("failed to allocate capture buffer\n");
-                    err = DSERR_OUTOFMEMORY;
-                    /* but the old buffer might still exist and must be re-prepared */
-                } else {
-                    device->buffer = newbuf;
-                    device->buflen = buflen;
-                }
-            } else {
-                /* let driver allocate memory */
-                device->buflen = lpcDSCBufferDesc->dwBufferBytes;
-                /* FIXME: */
-                HeapFree( GetProcessHeap(), 0, device->buffer);
-                device->buffer = NULL;
-            }
-
-           err = IDsCaptureDriver_CreateCaptureBuffer(device->driver,
-               device->pwfx,0,0,&(device->buflen),&(device->buffer),(LPVOID*)&(device->hwbuf));
-           if (err != DS_OK) {
-               WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
-               This->device->capture_buffer = 0;
-               HeapFree( GetProcessHeap(), 0, This );
-               *ppobj = NULL;
-               return err;
-           }
-       } else {
-           DWORD flags = CALLBACK_FUNCTION;
-            err = mmErr(waveInOpen(&(device->hwi),
-                device->drvdesc.dnDevNode, device->pwfx,
-                (DWORD_PTR)DSOUND_capture_callback, (DWORD_PTR)device, flags));
-            if (err != DS_OK) {
-                WARN("waveInOpen failed\n");
-               This->device->capture_buffer = 0;
-               HeapFree( GetProcessHeap(), 0, This );
-               *ppobj = NULL;
-               return err;
-            }
-
-           buflen = lpcDSCBufferDesc->dwBufferBytes;
-            TRACE("desired buflen=%d, old buffer=%p\n", buflen, device->buffer);
-           if (device->buffer)
-                newbuf = HeapReAlloc(GetProcessHeap(),0,device->buffer,buflen);
-           else
-               newbuf = HeapAlloc(GetProcessHeap(),0,buflen);
-            if (newbuf == NULL) {
-                WARN("failed to allocate capture buffer\n");
-                err = DSERR_OUTOFMEMORY;
-                /* but the old buffer might still exist and must be re-prepared */
-            } else {
-                device->buffer = newbuf;
-                device->buflen = buflen;
-            }
-       }
-    }
-
-    TRACE("returning DS_OK\n");
-    return DS_OK;
-}
-
-/*******************************************************************************
- * DirectSoundCaptureDevice
- */
-HRESULT DirectSoundCaptureDevice_Initialize(
-    DirectSoundCaptureDevice ** ppDevice,
-    LPCGUID lpcGUID)
-{
-    HRESULT err = DSERR_INVALIDPARAM;
-    unsigned wid, widn;
-    BOOLEAN found = FALSE;
-    GUID devGUID;
-    DirectSoundCaptureDevice *device = *ppDevice;
-    TRACE("(%p, %s)\n", ppDevice, debugstr_guid(lpcGUID));
-
-    /* Default device? */
-    if ( !lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL) )
-       lpcGUID = &DSDEVID_DefaultCapture;
-
-    if (GetDeviceID(lpcGUID, &devGUID) != DS_OK) {
-        WARN("invalid parameter: lpcGUID\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    widn = waveInGetNumDevs();
-    if (!widn) {
-       WARN("no audio devices found\n");
-       return DSERR_NODRIVER;
-    }
-
-    /* enumerate WINMM audio devices and find the one we want */
-    for (wid=0; wid<widn; wid++) {
-       if (IsEqualGUID( &devGUID, &DSOUND_capture_guids[wid]) ) {
-           found = TRUE;
-           break;
-       }
-    }
-
-    if (found == FALSE) {
-       WARN("No device found matching given ID!\n");
-       return DSERR_NODRIVER;
-    }
-
-    if (DSOUND_capture[wid]) {
-        WARN("already in use\n");
-        return DSERR_ALLOCATED;
-    }
-
-    err = DirectSoundCaptureDevice_Create(&(device));
-    if (err != DS_OK) {
-        WARN("DirectSoundCaptureDevice_Create failed\n");
-        return err;
-    }
-
-    *ppDevice = device;
-    device->guid = devGUID;
-
-    /* Disable the direct sound driver to force emulation if requested. */
-    device->driver = NULL;
-    if (ds_hw_accel != DS_HW_ACCEL_EMULATION)
-    {
-        err = mmErr(waveInMessage(UlongToHandle(wid),DRV_QUERYDSOUNDIFACE,(DWORD_PTR)&device->driver,0));
-        if ( (err != DS_OK) && (err != DSERR_UNSUPPORTED) ) {
-            WARN("waveInMessage failed; err=%x\n",err);
-            return err;
-        }
-    }
-    err = DS_OK;
-
-    /* Get driver description */
-    if (device->driver) {
-        TRACE("using DirectSound driver\n");
-        err = IDsCaptureDriver_GetDriverDesc(device->driver, &(device->drvdesc));
-       if (err != DS_OK) {
-           WARN("IDsCaptureDriver_GetDriverDesc failed\n");
-           return err;
-       }
-    } else {
-        TRACE("using WINMM\n");
-        /* if no DirectSound interface available, use WINMM API instead */
-        device->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN |
-            DSDDESC_DOMMSYSTEMSETFORMAT;
-    }
-
-    device->drvdesc.dnDevNode = wid;
-
-    /* open the DirectSound driver if available */
-    if (device->driver && (err == DS_OK))
-        err = IDsCaptureDriver_Open(device->driver);
-
-    if (err == DS_OK) {
-        *ppDevice = device;
-
-        /* the driver is now open, so it's now allowed to call GetCaps */
-        if (device->driver) {
-           device->drvcaps.dwSize = sizeof(device->drvcaps);
-            err = IDsCaptureDriver_GetCaps(device->driver,&(device->drvcaps));
-           if (err != DS_OK) {
-               WARN("IDsCaptureDriver_GetCaps failed\n");
-               return err;
-           }
-        } else /*if (device->hwi)*/ {
-            WAVEINCAPSA    wic;
-            err = mmErr(waveInGetDevCapsA((UINT)device->drvdesc.dnDevNode, &wic, sizeof(wic)));
-
-            if (err == DS_OK) {
-                device->drvcaps.dwFlags = 0;
-                lstrcpynA(device->drvdesc.szDrvname, wic.szPname,
-                          sizeof(device->drvdesc.szDrvname));
-
-                device->drvcaps.dwFlags |= DSCCAPS_EMULDRIVER;
-                device->drvcaps.dwFormats = wic.dwFormats;
-                device->drvcaps.dwChannels = wic.wChannels;
-            }
-        }
-    }
-
-    return err;
-}
-
-static HRESULT DirectSoundCaptureDevice_Create(
-    DirectSoundCaptureDevice ** ppDevice)
-{
-    DirectSoundCaptureDevice * device;
-    TRACE("(%p)\n", ppDevice);
-
-    /* Allocate memory */
-    device = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DirectSoundCaptureDevice));
-
-    if (device == NULL) {
-       WARN("out of memory\n");
-        return DSERR_OUTOFMEMORY;
-    }
-
-    device->ref = 1;
-    device->state = STATE_STOPPED;
-
-    InitializeCriticalSection( &(device->lock) );
-    device->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DirectSoundCaptureDevice.lock");
-
-    *ppDevice = device;
-
-    return DS_OK;
-}
-
-ULONG DirectSoundCaptureDevice_Release(
-    DirectSoundCaptureDevice * device)
-{
-    ULONG ref = InterlockedDecrement(&(device->ref));
-    TRACE("(%p) ref was %d\n", device, ref + 1);
-
-    if (!ref) {
-        TRACE("deleting object\n");
-        if (device->capture_buffer)
-            IDirectSoundCaptureBufferImpl_Release(
-               (LPDIRECTSOUNDCAPTUREBUFFER8) device->capture_buffer);
-
-        if (device->driver) {
-            IDsCaptureDriver_Close(device->driver);
-            IDsCaptureDriver_Release(device->driver);
-        }
-
-        HeapFree(GetProcessHeap(), 0, device->pwfx);
-        device->lock.DebugInfo->Spare[0] = 0;
-        DeleteCriticalSection( &(device->lock) );
-        DSOUND_capture[device->drvdesc.dnDevNode] = NULL;
-        HeapFree(GetProcessHeap(), 0, device);
-       TRACE("(%p) released\n", device);
-    }
-    return ref;
-}
diff --git a/dll/directx/dsound/dsound.c b/dll/directx/dsound/dsound.c
deleted file mode 100644 (file)
index 1f60f37..0000000
+++ /dev/null
@@ -1,1863 +0,0 @@
-/* DirectSound
- *
- * Copyright 1998 Marcus Meissner
- * Copyright 1998 Rob Riggs
- * Copyright 2000-2002 TransGaming Technologies, Inc.
- * Copyright 2004 Robert Reif
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#include <stdarg.h>
-#include <stdio.h>
-
-#define NONAMELESSSTRUCT
-#define NONAMELESSUNION
-#include "windef.h"
-#include "winbase.h"
-#include "winuser.h"
-#include "mmsystem.h"
-#include "winternl.h"
-#include "mmddk.h"
-#include "wingdi.h"
-#include "mmreg.h"
-#include "ks.h"
-#include "ksmedia.h"
-#include "wine/debug.h"
-#include "dsound.h"
-#include "dsdriver.h"
-#include "dsound_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(dsound);
-
-/*****************************************************************************
- * IDirectSound COM components
- */
-struct IDirectSound_IUnknown {
-    const IUnknownVtbl         *lpVtbl;
-    LONG                        ref;
-    LPDIRECTSOUND8              pds;
-};
-
-static HRESULT IDirectSound_IUnknown_Create(LPDIRECTSOUND8 pds, LPUNKNOWN * ppunk);
-
-struct IDirectSound_IDirectSound {
-    const IDirectSoundVtbl     *lpVtbl;
-    LONG                        ref;
-    LPDIRECTSOUND8              pds;
-};
-
-static HRESULT IDirectSound_IDirectSound_Create(LPDIRECTSOUND8 pds, LPDIRECTSOUND * ppds);
-
-/*****************************************************************************
- * IDirectSound8 COM components
- */
-struct IDirectSound8_IUnknown {
-    const IUnknownVtbl         *lpVtbl;
-    LONG                        ref;
-    LPDIRECTSOUND8              pds;
-};
-
-static HRESULT IDirectSound8_IUnknown_Create(LPDIRECTSOUND8 pds, LPUNKNOWN * ppunk);
-static ULONG WINAPI IDirectSound8_IUnknown_AddRef(LPUNKNOWN iface);
-
-struct IDirectSound8_IDirectSound {
-    const IDirectSoundVtbl     *lpVtbl;
-    LONG                        ref;
-    LPDIRECTSOUND8              pds;
-};
-
-static HRESULT IDirectSound8_IDirectSound_Create(LPDIRECTSOUND8 pds, LPDIRECTSOUND * ppds);
-static ULONG WINAPI IDirectSound8_IDirectSound_AddRef(LPDIRECTSOUND iface);
-
-struct IDirectSound8_IDirectSound8 {
-    const IDirectSound8Vtbl    *lpVtbl;
-    LONG                        ref;
-    LPDIRECTSOUND8              pds;
-};
-
-static HRESULT IDirectSound8_IDirectSound8_Create(LPDIRECTSOUND8 pds, LPDIRECTSOUND8 * ppds);
-static ULONG WINAPI IDirectSound8_IDirectSound8_AddRef(LPDIRECTSOUND8 iface);
-
-/*****************************************************************************
- * IDirectSound implementation structure
- */
-struct IDirectSoundImpl
-{
-    LONG                        ref;
-
-    DirectSoundDevice          *device;
-    LPUNKNOWN                   pUnknown;
-    LPDIRECTSOUND               pDS;
-    LPDIRECTSOUND8              pDS8;
-};
-
-static HRESULT IDirectSoundImpl_Create(LPDIRECTSOUND8 * ppds);
-
-static ULONG WINAPI IDirectSound_IUnknown_AddRef(LPUNKNOWN iface);
-static ULONG WINAPI IDirectSound_IDirectSound_AddRef(LPDIRECTSOUND iface);
-
-static HRESULT DirectSoundDevice_VerifyCertification(DirectSoundDevice * device, LPDWORD pdwCertified);
-
-const char * dumpCooperativeLevel(DWORD level)
-{
-    static char unknown[32];
-#define LE(x) case x: return #x
-    switch (level) {
-        LE(DSSCL_NORMAL);
-        LE(DSSCL_PRIORITY);
-        LE(DSSCL_EXCLUSIVE);
-        LE(DSSCL_WRITEPRIMARY);
-    }
-#undef LE
-    sprintf(unknown, "Unknown(%08x)", (UINT)level);
-    return unknown;
-}
-
-static void _dump_DSCAPS(DWORD xmask) {
-    struct {
-        DWORD   mask;
-        const char    *name;
-    } flags[] = {
-#define FE(x) { x, #x },
-        FE(DSCAPS_PRIMARYMONO)
-        FE(DSCAPS_PRIMARYSTEREO)
-        FE(DSCAPS_PRIMARY8BIT)
-        FE(DSCAPS_PRIMARY16BIT)
-        FE(DSCAPS_CONTINUOUSRATE)
-        FE(DSCAPS_EMULDRIVER)
-        FE(DSCAPS_CERTIFIED)
-        FE(DSCAPS_SECONDARYMONO)
-        FE(DSCAPS_SECONDARYSTEREO)
-        FE(DSCAPS_SECONDARY8BIT)
-        FE(DSCAPS_SECONDARY16BIT)
-#undef FE
-    };
-    unsigned int     i;
-
-    for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
-        if ((flags[i].mask & xmask) == flags[i].mask)
-            TRACE("%s ",flags[i].name);
-}
-
-static void _dump_DSBCAPS(DWORD xmask) {
-    struct {
-        DWORD   mask;
-        const char    *name;
-    } flags[] = {
-#define FE(x) { x, #x },
-        FE(DSBCAPS_PRIMARYBUFFER)
-        FE(DSBCAPS_STATIC)
-        FE(DSBCAPS_LOCHARDWARE)
-        FE(DSBCAPS_LOCSOFTWARE)
-        FE(DSBCAPS_CTRL3D)
-        FE(DSBCAPS_CTRLFREQUENCY)
-        FE(DSBCAPS_CTRLPAN)
-        FE(DSBCAPS_CTRLVOLUME)
-        FE(DSBCAPS_CTRLPOSITIONNOTIFY)
-        FE(DSBCAPS_STICKYFOCUS)
-        FE(DSBCAPS_GLOBALFOCUS)
-        FE(DSBCAPS_GETCURRENTPOSITION2)
-        FE(DSBCAPS_MUTE3DATMAXDISTANCE)
-#undef FE
-    };
-    unsigned int     i;
-
-    for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
-        if ((flags[i].mask & xmask) == flags[i].mask)
-            TRACE("%s ",flags[i].name);
-}
-
-/*******************************************************************************
- *             IDirectSoundImpl_DirectSound
- */
-static HRESULT DSOUND_QueryInterface(
-    LPDIRECTSOUND8 iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSoundImpl *This = (IDirectSoundImpl *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-
-    if (ppobj == NULL) {
-        WARN("invalid parameter\n");
-        return E_INVALIDARG;
-    }
-
-    if (IsEqualIID(riid, &IID_IUnknown)) {
-        if (!This->pUnknown) {
-            IDirectSound_IUnknown_Create(iface, &This->pUnknown);
-            if (!This->pUnknown) {
-                WARN("IDirectSound_IUnknown_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSound_IUnknown_AddRef(This->pUnknown);
-        *ppobj = This->pUnknown;
-        return S_OK;
-    } else if (IsEqualIID(riid, &IID_IDirectSound)) {
-        if (!This->pDS) {
-            IDirectSound_IDirectSound_Create(iface, &This->pDS);
-            if (!This->pDS) {
-                WARN("IDirectSound_IDirectSound_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSound_IDirectSound_AddRef(This->pDS);
-        *ppobj = This->pDS;
-        return S_OK;
-    }
-
-    *ppobj = NULL;
-    WARN("Unknown IID %s\n",debugstr_guid(riid));
-    return E_NOINTERFACE;
-}
-
-static HRESULT DSOUND_QueryInterface8(
-    LPDIRECTSOUND8 iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSoundImpl *This = (IDirectSoundImpl *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-
-    if (ppobj == NULL) {
-        WARN("invalid parameter\n");
-        return E_INVALIDARG;
-    }
-
-    if (IsEqualIID(riid, &IID_IUnknown)) {
-        if (!This->pUnknown) {
-            IDirectSound8_IUnknown_Create(iface, &This->pUnknown);
-            if (!This->pUnknown) {
-                WARN("IDirectSound8_IUnknown_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSound8_IUnknown_AddRef(This->pUnknown);
-        *ppobj = This->pUnknown;
-        return S_OK;
-    } else if (IsEqualIID(riid, &IID_IDirectSound)) {
-        if (!This->pDS) {
-            IDirectSound8_IDirectSound_Create(iface, &This->pDS);
-            if (!This->pDS) {
-                WARN("IDirectSound8_IDirectSound_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSound8_IDirectSound_AddRef(This->pDS);
-        *ppobj = This->pDS;
-        return S_OK;
-    } else if (IsEqualIID(riid, &IID_IDirectSound8)) {
-        if (!This->pDS8) {
-            IDirectSound8_IDirectSound8_Create(iface, &This->pDS8);
-            if (!This->pDS8) {
-                WARN("IDirectSound8_IDirectSound8_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSound8_IDirectSound8_AddRef(This->pDS8);
-        *ppobj = This->pDS8;
-        return S_OK;
-    }
-
-    *ppobj = NULL;
-    WARN("Unknown IID %s\n",debugstr_guid(riid));
-    return E_NOINTERFACE;
-}
-
-static ULONG IDirectSoundImpl_AddRef(
-    LPDIRECTSOUND8 iface)
-{
-    IDirectSoundImpl *This = (IDirectSoundImpl *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG IDirectSoundImpl_Release(
-    LPDIRECTSOUND8 iface)
-{
-    IDirectSoundImpl *This = (IDirectSoundImpl *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-
-    if (!ref) {
-        if (This->device)
-            DirectSoundDevice_Release(This->device);
-        HeapFree(GetProcessHeap(),0,This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT IDirectSoundImpl_Create(
-    LPDIRECTSOUND8 * ppDS)
-{
-    IDirectSoundImpl* pDS;
-    TRACE("(%p)\n",ppDS);
-
-    /* Allocate memory */
-    pDS = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectSoundImpl));
-    if (pDS == NULL) {
-        WARN("out of memory\n");
-        *ppDS = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pDS->ref    = 0;
-    pDS->device = NULL;
-
-    *ppDS = (LPDIRECTSOUND8)pDS;
-
-    return DS_OK;
-}
-
-/*******************************************************************************
- *             IDirectSound_IUnknown
- */
-static HRESULT WINAPI IDirectSound_IUnknown_QueryInterface(
-    LPUNKNOWN iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return DSOUND_QueryInterface(This->pds, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSound_IUnknown_AddRef(
-    LPUNKNOWN iface)
-{
-    IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSound_IUnknown_Release(
-    LPUNKNOWN iface)
-{
-    IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        ((IDirectSoundImpl*)This->pds)->pUnknown = NULL;
-        IDirectSoundImpl_Release(This->pds);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static const IUnknownVtbl DirectSound_Unknown_Vtbl =
-{
-    IDirectSound_IUnknown_QueryInterface,
-    IDirectSound_IUnknown_AddRef,
-    IDirectSound_IUnknown_Release
-};
-
-static HRESULT IDirectSound_IUnknown_Create(
-    LPDIRECTSOUND8 pds,
-    LPUNKNOWN * ppunk)
-{
-    IDirectSound_IUnknown * pdsunk;
-    TRACE("(%p,%p)\n",pds,ppunk);
-
-    if (ppunk == NULL) {
-        ERR("invalid parameter: ppunk == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (pds == NULL) {
-        ERR("invalid parameter: pds == NULL\n");
-        *ppunk = NULL;
-        return DSERR_INVALIDPARAM;
-    }
-
-    pdsunk = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsunk));
-    if (pdsunk == NULL) {
-        WARN("out of memory\n");
-        *ppunk = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsunk->lpVtbl = &DirectSound_Unknown_Vtbl;
-    pdsunk->ref = 0;
-    pdsunk->pds = pds;
-
-    IDirectSoundImpl_AddRef(pds);
-    *ppunk = (LPUNKNOWN)pdsunk;
-
-    return DS_OK;
-}
-
-/*******************************************************************************
- *             IDirectSound_IDirectSound
- */
-static HRESULT WINAPI IDirectSound_IDirectSound_QueryInterface(
-    LPDIRECTSOUND iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return DSOUND_QueryInterface(This->pds, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSound_IDirectSound_AddRef(
-    LPDIRECTSOUND iface)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSound_IDirectSound_Release(
-    LPDIRECTSOUND iface)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        ((IDirectSoundImpl*)This->pds)->pDS = NULL;
-        IDirectSoundImpl_Release(This->pds);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI IDirectSound_IDirectSound_CreateSoundBuffer(
-    LPDIRECTSOUND iface,
-    LPCDSBUFFERDESC dsbd,
-    LPLPDIRECTSOUNDBUFFER ppdsb,
-    LPUNKNOWN lpunk)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
-    return DirectSoundDevice_CreateSoundBuffer(((IDirectSoundImpl *)This->pds)->device,dsbd,ppdsb,lpunk,FALSE);
-}
-
-static HRESULT WINAPI IDirectSound_IDirectSound_GetCaps(
-    LPDIRECTSOUND iface,
-    LPDSCAPS lpDSCaps)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    TRACE("(%p,%p)\n",This,lpDSCaps);
-    return DirectSoundDevice_GetCaps(((IDirectSoundImpl *)This->pds)->device, lpDSCaps);
-}
-
-static HRESULT WINAPI IDirectSound_IDirectSound_DuplicateSoundBuffer(
-    LPDIRECTSOUND iface,
-    LPDIRECTSOUNDBUFFER psb,
-    LPLPDIRECTSOUNDBUFFER ppdsb)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
-    return DirectSoundDevice_DuplicateSoundBuffer(((IDirectSoundImpl *)This->pds)->device,psb,ppdsb);
-}
-
-static HRESULT WINAPI IDirectSound_IDirectSound_SetCooperativeLevel(
-    LPDIRECTSOUND iface,
-    HWND hwnd,
-    DWORD level)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    TRACE("(%p,%p,%s)\n",This,hwnd,dumpCooperativeLevel(level));
-    return DirectSoundDevice_SetCooperativeLevel(((IDirectSoundImpl *)This->pds)->device, hwnd, level);
-}
-
-static HRESULT WINAPI IDirectSound_IDirectSound_Compact(
-    LPDIRECTSOUND iface)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    TRACE("(%p)\n", This);
-    return DirectSoundDevice_Compact(((IDirectSoundImpl *)This->pds)->device);
-}
-
-static HRESULT WINAPI IDirectSound_IDirectSound_GetSpeakerConfig(
-    LPDIRECTSOUND iface,
-    LPDWORD lpdwSpeakerConfig)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    TRACE("(%p, %p)\n", This, lpdwSpeakerConfig);
-    return DirectSoundDevice_GetSpeakerConfig(((IDirectSoundImpl *)This->pds)->device,lpdwSpeakerConfig);
-}
-
-static HRESULT WINAPI IDirectSound_IDirectSound_SetSpeakerConfig(
-    LPDIRECTSOUND iface,
-    DWORD config)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    TRACE("(%p,0x%08x)\n",This,config);
-    return DirectSoundDevice_SetSpeakerConfig(((IDirectSoundImpl *)This->pds)->device,config);
-}
-
-static HRESULT WINAPI IDirectSound_IDirectSound_Initialize(
-    LPDIRECTSOUND iface,
-    LPCGUID lpcGuid)
-{
-    IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
-    return DirectSoundDevice_Initialize(&((IDirectSoundImpl *)This->pds)->device,lpcGuid);
-}
-
-static const IDirectSoundVtbl DirectSound_DirectSound_Vtbl =
-{
-    IDirectSound_IDirectSound_QueryInterface,
-    IDirectSound_IDirectSound_AddRef,
-    IDirectSound_IDirectSound_Release,
-    IDirectSound_IDirectSound_CreateSoundBuffer,
-    IDirectSound_IDirectSound_GetCaps,
-    IDirectSound_IDirectSound_DuplicateSoundBuffer,
-    IDirectSound_IDirectSound_SetCooperativeLevel,
-    IDirectSound_IDirectSound_Compact,
-    IDirectSound_IDirectSound_GetSpeakerConfig,
-    IDirectSound_IDirectSound_SetSpeakerConfig,
-    IDirectSound_IDirectSound_Initialize
-};
-
-static HRESULT IDirectSound_IDirectSound_Create(
-    LPDIRECTSOUND8  pds,
-    LPDIRECTSOUND * ppds)
-{
-    IDirectSound_IDirectSound * pdsds;
-    TRACE("(%p,%p)\n",pds,ppds);
-
-    if (ppds == NULL) {
-        ERR("invalid parameter: ppds == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (pds == NULL) {
-        ERR("invalid parameter: pds == NULL\n");
-        *ppds = NULL;
-        return DSERR_INVALIDPARAM;
-    }
-
-    pdsds = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsds));
-    if (pdsds == NULL) {
-        WARN("out of memory\n");
-        *ppds = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsds->lpVtbl = &DirectSound_DirectSound_Vtbl;
-    pdsds->ref = 0;
-    pdsds->pds = pds;
-
-    IDirectSoundImpl_AddRef(pds);
-    *ppds = (LPDIRECTSOUND)pdsds;
-
-    return DS_OK;
-}
-
-/*******************************************************************************
- *             IDirectSound8_IUnknown
- */
-static HRESULT WINAPI IDirectSound8_IUnknown_QueryInterface(
-    LPUNKNOWN iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return DSOUND_QueryInterface8(This->pds, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSound8_IUnknown_AddRef(
-    LPUNKNOWN iface)
-{
-    IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSound8_IUnknown_Release(
-    LPUNKNOWN iface)
-{
-    IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        ((IDirectSoundImpl*)This->pds)->pUnknown = NULL;
-        IDirectSoundImpl_Release(This->pds);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static const IUnknownVtbl DirectSound8_Unknown_Vtbl =
-{
-    IDirectSound8_IUnknown_QueryInterface,
-    IDirectSound8_IUnknown_AddRef,
-    IDirectSound8_IUnknown_Release
-};
-
-static HRESULT IDirectSound8_IUnknown_Create(
-    LPDIRECTSOUND8 pds,
-    LPUNKNOWN * ppunk)
-{
-    IDirectSound8_IUnknown * pdsunk;
-    TRACE("(%p,%p)\n",pds,ppunk);
-
-    if (ppunk == NULL) {
-        ERR("invalid parameter: ppunk == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (pds == NULL) {
-        ERR("invalid parameter: pds == NULL\n");
-        *ppunk = NULL;
-        return DSERR_INVALIDPARAM;
-    }
-
-    pdsunk = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsunk));
-    if (pdsunk == NULL) {
-        WARN("out of memory\n");
-        *ppunk = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsunk->lpVtbl = &DirectSound8_Unknown_Vtbl;
-    pdsunk->ref = 0;
-    pdsunk->pds = pds;
-
-    IDirectSoundImpl_AddRef(pds);
-    *ppunk = (LPUNKNOWN)pdsunk;
-
-    return DS_OK;
-}
-
-/*******************************************************************************
- *             IDirectSound8_IDirectSound
- */
-static HRESULT WINAPI IDirectSound8_IDirectSound_QueryInterface(
-    LPDIRECTSOUND iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return DSOUND_QueryInterface8(This->pds, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSound8_IDirectSound_AddRef(
-    LPDIRECTSOUND iface)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSound8_IDirectSound_Release(
-    LPDIRECTSOUND iface)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        ((IDirectSoundImpl*)This->pds)->pDS = NULL;
-        IDirectSoundImpl_Release(This->pds);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound_CreateSoundBuffer(
-    LPDIRECTSOUND iface,
-    LPCDSBUFFERDESC dsbd,
-    LPLPDIRECTSOUNDBUFFER ppdsb,
-    LPUNKNOWN lpunk)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
-    return DirectSoundDevice_CreateSoundBuffer(((IDirectSoundImpl *)This->pds)->device,dsbd,ppdsb,lpunk,TRUE);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound_GetCaps(
-    LPDIRECTSOUND iface,
-    LPDSCAPS lpDSCaps)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p,%p)\n",This,lpDSCaps);
-    return DirectSoundDevice_GetCaps(((IDirectSoundImpl *)This->pds)->device, lpDSCaps);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound_DuplicateSoundBuffer(
-    LPDIRECTSOUND iface,
-    LPDIRECTSOUNDBUFFER psb,
-    LPLPDIRECTSOUNDBUFFER ppdsb)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
-    return DirectSoundDevice_DuplicateSoundBuffer(((IDirectSoundImpl *)This->pds)->device,psb,ppdsb);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound_SetCooperativeLevel(
-    LPDIRECTSOUND iface,
-    HWND hwnd,
-    DWORD level)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p,%p,%s)\n",This,hwnd,dumpCooperativeLevel(level));
-    return DirectSoundDevice_SetCooperativeLevel(((IDirectSoundImpl *)This->pds)->device, hwnd, level);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound_Compact(
-    LPDIRECTSOUND iface)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p)\n", This);
-    return DirectSoundDevice_Compact(((IDirectSoundImpl *)This->pds)->device);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound_GetSpeakerConfig(
-    LPDIRECTSOUND iface,
-    LPDWORD lpdwSpeakerConfig)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p, %p)\n", This, lpdwSpeakerConfig);
-    return DirectSoundDevice_GetSpeakerConfig(((IDirectSoundImpl *)This->pds)->device,lpdwSpeakerConfig);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound_SetSpeakerConfig(
-    LPDIRECTSOUND iface,
-    DWORD config)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p,0x%08x)\n",This,config);
-    return DirectSoundDevice_SetSpeakerConfig(((IDirectSoundImpl *)This->pds)->device,config);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound_Initialize(
-    LPDIRECTSOUND iface,
-    LPCGUID lpcGuid)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
-    return DirectSoundDevice_Initialize(&((IDirectSoundImpl *)This->pds)->device,lpcGuid);
-}
-
-static const IDirectSoundVtbl DirectSound8_DirectSound_Vtbl =
-{
-    IDirectSound8_IDirectSound_QueryInterface,
-    IDirectSound8_IDirectSound_AddRef,
-    IDirectSound8_IDirectSound_Release,
-    IDirectSound8_IDirectSound_CreateSoundBuffer,
-    IDirectSound8_IDirectSound_GetCaps,
-    IDirectSound8_IDirectSound_DuplicateSoundBuffer,
-    IDirectSound8_IDirectSound_SetCooperativeLevel,
-    IDirectSound8_IDirectSound_Compact,
-    IDirectSound8_IDirectSound_GetSpeakerConfig,
-    IDirectSound8_IDirectSound_SetSpeakerConfig,
-    IDirectSound8_IDirectSound_Initialize
-};
-
-static HRESULT IDirectSound8_IDirectSound_Create(
-    LPDIRECTSOUND8 pds,
-    LPDIRECTSOUND * ppds)
-{
-    IDirectSound8_IDirectSound * pdsds;
-    TRACE("(%p,%p)\n",pds,ppds);
-
-    if (ppds == NULL) {
-        ERR("invalid parameter: ppds == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (pds == NULL) {
-        ERR("invalid parameter: pds == NULL\n");
-        *ppds = NULL;
-        return DSERR_INVALIDPARAM;
-    }
-
-    pdsds = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsds));
-    if (pdsds == NULL) {
-        WARN("out of memory\n");
-        *ppds = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsds->lpVtbl = &DirectSound8_DirectSound_Vtbl;
-    pdsds->ref = 0;
-    pdsds->pds = pds;
-
-    IDirectSoundImpl_AddRef(pds);
-    *ppds = (LPDIRECTSOUND)pdsds;
-
-    return DS_OK;
-}
-
-/*******************************************************************************
- *             IDirectSound8_IDirectSound8
- */
-static HRESULT WINAPI IDirectSound8_IDirectSound8_QueryInterface(
-    LPDIRECTSOUND8 iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return DSOUND_QueryInterface8(This->pds, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSound8_IDirectSound8_AddRef(
-    LPDIRECTSOUND8 iface)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSound8_IDirectSound8_Release(
-    LPDIRECTSOUND8 iface)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        ((IDirectSoundImpl*)This->pds)->pDS8 = NULL;
-        IDirectSoundImpl_Release(This->pds);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound8_CreateSoundBuffer(
-    LPDIRECTSOUND8 iface,
-    LPCDSBUFFERDESC dsbd,
-    LPLPDIRECTSOUNDBUFFER ppdsb,
-    LPUNKNOWN lpunk)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
-    return DirectSoundDevice_CreateSoundBuffer(((IDirectSoundImpl *)This->pds)->device,dsbd,ppdsb,lpunk,TRUE);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound8_GetCaps(
-    LPDIRECTSOUND8 iface,
-    LPDSCAPS lpDSCaps)
-{
-    IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p,%p)\n",This,lpDSCaps);
-    return DirectSoundDevice_GetCaps(((IDirectSoundImpl *)This->pds)->device, lpDSCaps);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound8_DuplicateSoundBuffer(
-    LPDIRECTSOUND8 iface,
-    LPDIRECTSOUNDBUFFER psb,
-    LPLPDIRECTSOUNDBUFFER ppdsb)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
-    return DirectSoundDevice_DuplicateSoundBuffer(((IDirectSoundImpl *)This->pds)->device,psb,ppdsb);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound8_SetCooperativeLevel(
-    LPDIRECTSOUND8 iface,
-    HWND hwnd,
-    DWORD level)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    TRACE("(%p,%p,%s)\n",This,hwnd,dumpCooperativeLevel(level));
-    return DirectSoundDevice_SetCooperativeLevel(((IDirectSoundImpl *)This->pds)->device, hwnd, level);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound8_Compact(
-    LPDIRECTSOUND8 iface)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    TRACE("(%p)\n", This);
-    return DirectSoundDevice_Compact(((IDirectSoundImpl *)This->pds)->device);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound8_GetSpeakerConfig(
-    LPDIRECTSOUND8 iface,
-    LPDWORD lpdwSpeakerConfig)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    TRACE("(%p, %p)\n", This, lpdwSpeakerConfig);
-    return DirectSoundDevice_GetSpeakerConfig(((IDirectSoundImpl *)This->pds)->device,lpdwSpeakerConfig);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound8_SetSpeakerConfig(
-    LPDIRECTSOUND8 iface,
-    DWORD config)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    TRACE("(%p,0x%08x)\n",This,config);
-    return DirectSoundDevice_SetSpeakerConfig(((IDirectSoundImpl *)This->pds)->device,config);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound8_Initialize(
-    LPDIRECTSOUND8 iface,
-    LPCGUID lpcGuid)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
-    return DirectSoundDevice_Initialize(&((IDirectSoundImpl *)This->pds)->device,lpcGuid);
-}
-
-static HRESULT WINAPI IDirectSound8_IDirectSound8_VerifyCertification(
-    LPDIRECTSOUND8 iface,
-    LPDWORD pdwCertified)
-{
-    IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    TRACE("(%p, %p)\n", This, pdwCertified);
-    return DirectSoundDevice_VerifyCertification(((IDirectSoundImpl *)This->pds)->device,pdwCertified);
-}
-
-static const IDirectSound8Vtbl DirectSound8_DirectSound8_Vtbl =
-{
-    IDirectSound8_IDirectSound8_QueryInterface,
-    IDirectSound8_IDirectSound8_AddRef,
-    IDirectSound8_IDirectSound8_Release,
-    IDirectSound8_IDirectSound8_CreateSoundBuffer,
-    IDirectSound8_IDirectSound8_GetCaps,
-    IDirectSound8_IDirectSound8_DuplicateSoundBuffer,
-    IDirectSound8_IDirectSound8_SetCooperativeLevel,
-    IDirectSound8_IDirectSound8_Compact,
-    IDirectSound8_IDirectSound8_GetSpeakerConfig,
-    IDirectSound8_IDirectSound8_SetSpeakerConfig,
-    IDirectSound8_IDirectSound8_Initialize,
-    IDirectSound8_IDirectSound8_VerifyCertification
-};
-
-static HRESULT IDirectSound8_IDirectSound8_Create(
-    LPDIRECTSOUND8 pds,
-    LPDIRECTSOUND8 * ppds)
-{
-    IDirectSound8_IDirectSound8 * pdsds;
-    TRACE("(%p,%p)\n",pds,ppds);
-
-    if (ppds == NULL) {
-        ERR("invalid parameter: ppds == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (pds == NULL) {
-        ERR("invalid parameter: pds == NULL\n");
-        *ppds = NULL;
-        return DSERR_INVALIDPARAM;
-    }
-
-    pdsds = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsds));
-    if (pdsds == NULL) {
-        WARN("out of memory\n");
-        *ppds = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsds->lpVtbl = &DirectSound8_DirectSound8_Vtbl;
-    pdsds->ref = 0;
-    pdsds->pds = pds;
-
-    IDirectSoundImpl_AddRef(pds);
-    *ppds = (LPDIRECTSOUND8)pdsds;
-
-    return DS_OK;
-}
-
-HRESULT DSOUND_Create(
-    REFIID riid,
-    LPDIRECTSOUND *ppDS)
-{
-    LPDIRECTSOUND8 pDS;
-    HRESULT hr;
-    TRACE("(%s, %p)\n", debugstr_guid(riid), ppDS);
-
-    if (!IsEqualIID(riid, &IID_IUnknown) &&
-        !IsEqualIID(riid, &IID_IDirectSound)) {
-        *ppDS = 0;
-        return E_NOINTERFACE;
-    }
-
-    /* Get dsound configuration */
-    setup_dsound_options();
-
-    hr = IDirectSoundImpl_Create(&pDS);
-    if (hr == DS_OK) {
-        hr = IDirectSound_IDirectSound_Create(pDS, ppDS);
-        if (*ppDS)
-            IDirectSound_IDirectSound_AddRef(*ppDS);
-        else {
-            WARN("IDirectSound_IDirectSound_Create failed\n");
-            IDirectSound8_Release(pDS);
-        }
-    } else {
-        WARN("IDirectSoundImpl_Create failed\n");
-        *ppDS = 0;
-    }
-
-    return hr;
-}
-
-/*******************************************************************************
- *             DirectSoundCreate (DSOUND.1)
- *
- *  Creates and initializes a DirectSound interface.
- *
- *  PARAMS
- *     lpcGUID   [I] Address of the GUID that identifies the sound device.
- *     ppDS      [O] Address of a variable to receive the interface pointer.
- *     pUnkOuter [I] Must be NULL.
- *
- *  RETURNS
- *     Success: DS_OK
- *     Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
- *              DSERR_NODRIVER, DSERR_OUTOFMEMORY
- */
-HRESULT WINAPI DirectSoundCreate(
-    LPCGUID lpcGUID,
-    LPDIRECTSOUND *ppDS,
-    IUnknown *pUnkOuter)
-{
-    HRESULT hr;
-    LPDIRECTSOUND pDS;
-
-    TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
-
-    if (ppDS == NULL) {
-        WARN("invalid parameter: ppDS == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (pUnkOuter != NULL) {
-        WARN("invalid parameter: pUnkOuter != NULL\n");
-        *ppDS = 0;
-        return DSERR_INVALIDPARAM;
-    }
-
-    hr = DSOUND_Create(&IID_IDirectSound, &pDS);
-    if (hr == DS_OK) {
-        hr = IDirectSound_Initialize(pDS, lpcGUID);
-        if (hr != DS_OK) {
-            if (hr != DSERR_ALREADYINITIALIZED) {
-                IDirectSound_Release(pDS);
-                pDS = 0;
-            } else
-                hr = DS_OK;
-        }
-    }
-
-    *ppDS = pDS;
-
-    return hr;
-}
-
-HRESULT DSOUND_Create8(
-    REFIID riid,
-    LPDIRECTSOUND8 *ppDS)
-{
-    LPDIRECTSOUND8 pDS;
-    HRESULT hr;
-    TRACE("(%s, %p)\n", debugstr_guid(riid), ppDS);
-
-    if (!IsEqualIID(riid, &IID_IUnknown) &&
-        !IsEqualIID(riid, &IID_IDirectSound) &&
-        !IsEqualIID(riid, &IID_IDirectSound8)) {
-        *ppDS = 0;
-        return E_NOINTERFACE;
-    }
-
-    /* Get dsound configuration */
-    setup_dsound_options();
-
-    hr = IDirectSoundImpl_Create(&pDS);
-    if (hr == DS_OK) {
-        hr = IDirectSound8_IDirectSound8_Create(pDS, ppDS);
-        if (*ppDS)
-            IDirectSound8_IDirectSound8_AddRef(*ppDS);
-        else {
-            WARN("IDirectSound8_IDirectSound8_Create failed\n");
-            IDirectSound8_Release(pDS);
-        }
-    } else {
-        WARN("IDirectSoundImpl_Create failed\n");
-        *ppDS = 0;
-    }
-
-    return hr;
-}
-
-/*******************************************************************************
- *        DirectSoundCreate8 (DSOUND.11)
- *
- *  Creates and initializes a DirectSound8 interface.
- *
- *  PARAMS
- *     lpcGUID   [I] Address of the GUID that identifies the sound device.
- *     ppDS      [O] Address of a variable to receive the interface pointer.
- *     pUnkOuter [I] Must be NULL.
- *
- *  RETURNS
- *     Success: DS_OK
- *     Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
- *              DSERR_NODRIVER, DSERR_OUTOFMEMORY
- */
-HRESULT WINAPI DirectSoundCreate8(
-    LPCGUID lpcGUID,
-    LPDIRECTSOUND8 *ppDS,
-    IUnknown *pUnkOuter)
-{
-    HRESULT hr;
-    LPDIRECTSOUND8 pDS;
-
-    TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
-
-    if (ppDS == NULL) {
-        WARN("invalid parameter: ppDS == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (pUnkOuter != NULL) {
-        WARN("invalid parameter: pUnkOuter != NULL\n");
-        *ppDS = 0;
-        return DSERR_INVALIDPARAM;
-    }
-
-    hr = DSOUND_Create8(&IID_IDirectSound8, &pDS);
-    if (hr == DS_OK) {
-        hr = IDirectSound8_Initialize(pDS, lpcGUID);
-        if (hr != DS_OK) {
-            if (hr != DSERR_ALREADYINITIALIZED) {
-                IDirectSound8_Release(pDS);
-                pDS = 0;
-            } else
-                hr = DS_OK;
-        }
-    }
-
-    *ppDS = pDS;
-
-    return hr;
-}
-
-/*******************************************************************************
- *        DirectSoundDevice
- */
-static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice)
-{
-    DirectSoundDevice * device;
-    TRACE("(%p)\n", ppDevice);
-
-    /* Allocate memory */
-    device = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DirectSoundDevice));
-    if (device == NULL) {
-        WARN("out of memory\n");
-        return DSERR_OUTOFMEMORY;
-    }
-
-    device->ref            = 1;
-    device->priolevel      = DSSCL_NORMAL;
-    device->state          = STATE_STOPPED;
-    device->speaker_config = DSSPEAKER_STEREO | (DSSPEAKER_GEOMETRY_NARROW << 16);
-
-    /* 3D listener initial parameters */
-    device->ds3dl.dwSize   = sizeof(DS3DLISTENER);
-    device->ds3dl.vPosition.x = 0.0;
-    device->ds3dl.vPosition.y = 0.0;
-    device->ds3dl.vPosition.z = 0.0;
-    device->ds3dl.vVelocity.x = 0.0;
-    device->ds3dl.vVelocity.y = 0.0;
-    device->ds3dl.vVelocity.z = 0.0;
-    device->ds3dl.vOrientFront.x = 0.0;
-    device->ds3dl.vOrientFront.y = 0.0;
-    device->ds3dl.vOrientFront.z = 1.0;
-    device->ds3dl.vOrientTop.x = 0.0;
-    device->ds3dl.vOrientTop.y = 1.0;
-    device->ds3dl.vOrientTop.z = 0.0;
-    device->ds3dl.flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
-    device->ds3dl.flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
-    device->ds3dl.flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
-
-    device->prebuf = ds_snd_queue_max;
-    device->guid = GUID_NULL;
-
-    /* Set default wave format (may need it for waveOutOpen) */
-    device->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(WAVEFORMATEX));
-    if (device->pwfx == NULL) {
-        WARN("out of memory\n");
-        HeapFree(GetProcessHeap(),0,device);
-        return DSERR_OUTOFMEMORY;
-    }
-
-    /* We rely on the sound driver to return the actual sound format of
-     * the device if it does not support 22050x8x2 and is given the
-     * WAVE_DIRECTSOUND flag.
-     */
-    device->pwfx->wFormatTag = WAVE_FORMAT_PCM;
-    device->pwfx->nSamplesPerSec = ds_default_sample_rate;
-    device->pwfx->wBitsPerSample = ds_default_bits_per_sample;
-    device->pwfx->nChannels = 2;
-    device->pwfx->nBlockAlign = device->pwfx->wBitsPerSample * device->pwfx->nChannels / 8;
-    device->pwfx->nAvgBytesPerSec = device->pwfx->nSamplesPerSec * device->pwfx->nBlockAlign;
-    device->pwfx->cbSize = 0;
-
-    InitializeCriticalSection(&(device->mixlock));
-    device->mixlock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DirectSoundDevice.mixlock");
-
-    RtlInitializeResource(&(device->buffer_list_lock));
-
-   *ppDevice = device;
-
-    return DS_OK;
-}
-
-static ULONG DirectSoundDevice_AddRef(DirectSoundDevice * device)
-{
-    ULONG ref = InterlockedIncrement(&(device->ref));
-    TRACE("(%p) ref was %d\n", device, ref - 1);
-    return ref;
-}
-
-ULONG DirectSoundDevice_Release(DirectSoundDevice * device)
-{
-    HRESULT hr;
-    ULONG ref = InterlockedDecrement(&(device->ref));
-    TRACE("(%p) ref was %u\n", device, ref + 1);
-    if (!ref) {
-        int i;
-        timeKillEvent(device->timerID);
-        timeEndPeriod(DS_TIME_RES);
-
-        /* The kill event should have allowed the timer process to expire
-         * but try to grab the lock just in case. Can't hold lock because
-         * IDirectSoundBufferImpl_Destroy also grabs the lock */
-        RtlAcquireResourceShared(&(device->buffer_list_lock), TRUE);
-        RtlReleaseResource(&(device->buffer_list_lock));
-
-        /* It is allowed to release this object even when buffers are playing */
-        if (device->buffers) {
-            WARN("%d secondary buffers not released\n", device->nrofbuffers);
-            for( i=0;i<device->nrofbuffers;i++)
-                IDirectSoundBufferImpl_Destroy(device->buffers[i]);
-        }
-
-        if (device->primary) {
-            WARN("primary buffer not released\n");
-            IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)device->primary);
-        }
-
-        hr = DSOUND_PrimaryDestroy(device);
-        if (hr != DS_OK)
-            WARN("DSOUND_PrimaryDestroy failed\n");
-
-        if (device->driver)
-            IDsDriver_Close(device->driver);
-
-        if (device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMOPEN)
-            waveOutClose(device->hwo);
-
-        if (device->driver)
-            IDsDriver_Release(device->driver);
-
-        DSOUND_renderer[device->drvdesc.dnDevNode] = NULL;
-
-        HeapFree(GetProcessHeap(), 0, device->tmp_buffer);
-        HeapFree(GetProcessHeap(), 0, device->mix_buffer);
-        if (device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY)
-            HeapFree(GetProcessHeap(), 0, device->buffer);
-        RtlDeleteResource(&device->buffer_list_lock);
-        device->mixlock.DebugInfo->Spare[0] = 0;
-        DeleteCriticalSection(&device->mixlock);
-        HeapFree(GetProcessHeap(),0,device);
-        TRACE("(%p) released\n", device);
-    }
-    return ref;
-}
-
-HRESULT DirectSoundDevice_GetCaps(
-    DirectSoundDevice * device,
-    LPDSCAPS lpDSCaps)
-{
-    TRACE("(%p,%p)\n",device,lpDSCaps);
-
-    if (device == NULL) {
-        WARN("not initialized\n");
-        return DSERR_UNINITIALIZED;
-    }
-
-    if (lpDSCaps == NULL) {
-        WARN("invalid parameter: lpDSCaps = NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    /* check if there is enough room */
-    if (lpDSCaps->dwSize < sizeof(*lpDSCaps)) {
-        WARN("invalid parameter: lpDSCaps->dwSize = %d\n", lpDSCaps->dwSize);
-        return DSERR_INVALIDPARAM;
-    }
-
-    lpDSCaps->dwFlags                           = device->drvcaps.dwFlags;
-    if (TRACE_ON(dsound)) {
-        TRACE("(flags=0x%08x:\n",lpDSCaps->dwFlags);
-        _dump_DSCAPS(lpDSCaps->dwFlags);
-        TRACE(")\n");
-    }
-    lpDSCaps->dwMinSecondarySampleRate          = device->drvcaps.dwMinSecondarySampleRate;
-    lpDSCaps->dwMaxSecondarySampleRate          = device->drvcaps.dwMaxSecondarySampleRate;
-    lpDSCaps->dwPrimaryBuffers                  = device->drvcaps.dwPrimaryBuffers;
-    lpDSCaps->dwMaxHwMixingAllBuffers           = device->drvcaps.dwMaxHwMixingAllBuffers;
-    lpDSCaps->dwMaxHwMixingStaticBuffers        = device->drvcaps.dwMaxHwMixingStaticBuffers;
-    lpDSCaps->dwMaxHwMixingStreamingBuffers     = device->drvcaps.dwMaxHwMixingStreamingBuffers;
-    lpDSCaps->dwFreeHwMixingAllBuffers          = device->drvcaps.dwFreeHwMixingAllBuffers;
-    lpDSCaps->dwFreeHwMixingStaticBuffers       = device->drvcaps.dwFreeHwMixingStaticBuffers;
-    lpDSCaps->dwFreeHwMixingStreamingBuffers    = device->drvcaps.dwFreeHwMixingStreamingBuffers;
-    lpDSCaps->dwMaxHw3DAllBuffers               = device->drvcaps.dwMaxHw3DAllBuffers;
-    lpDSCaps->dwMaxHw3DStaticBuffers            = device->drvcaps.dwMaxHw3DStaticBuffers;
-    lpDSCaps->dwMaxHw3DStreamingBuffers         = device->drvcaps.dwMaxHw3DStreamingBuffers;
-    lpDSCaps->dwFreeHw3DAllBuffers              = device->drvcaps.dwFreeHw3DAllBuffers;
-    lpDSCaps->dwFreeHw3DStaticBuffers           = device->drvcaps.dwFreeHw3DStaticBuffers;
-    lpDSCaps->dwFreeHw3DStreamingBuffers        = device->drvcaps.dwFreeHw3DStreamingBuffers;
-    lpDSCaps->dwTotalHwMemBytes                 = device->drvcaps.dwTotalHwMemBytes;
-    lpDSCaps->dwFreeHwMemBytes                  = device->drvcaps.dwFreeHwMemBytes;
-    lpDSCaps->dwMaxContigFreeHwMemBytes         = device->drvcaps.dwMaxContigFreeHwMemBytes;
-
-    /* driver doesn't have these */
-    lpDSCaps->dwUnlockTransferRateHwBuffers     = 4096; /* But we have none... */
-    lpDSCaps->dwPlayCpuOverheadSwBuffers        = 1;    /* 1% */
-
-    return DS_OK;
-}
-
-HRESULT DirectSoundDevice_Initialize(DirectSoundDevice ** ppDevice, LPCGUID lpcGUID)
-{
-    HRESULT hr = DS_OK;
-    unsigned wod, wodn;
-    BOOLEAN found = FALSE;
-    GUID devGUID;
-    DirectSoundDevice * device = *ppDevice;
-    TRACE("(%p,%s)\n",ppDevice,debugstr_guid(lpcGUID));
-
-    if (*ppDevice != NULL) {
-        WARN("already initialized\n");
-        return DSERR_ALREADYINITIALIZED;
-    }
-
-    /* Default device? */
-    if (!lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL))
-        lpcGUID = &DSDEVID_DefaultPlayback;
-
-    if (GetDeviceID(lpcGUID, &devGUID) != DS_OK) {
-        WARN("invalid parameter: lpcGUID\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    /* Enumerate WINMM audio devices and find the one we want */
-    wodn = waveOutGetNumDevs();
-    if (!wodn) {
-        WARN("no driver\n");
-        return DSERR_NODRIVER;
-    }
-
-    for (wod=0; wod<wodn; wod++) {
-        if (IsEqualGUID( &devGUID, &DSOUND_renderer_guids[wod])) {
-            found = TRUE;
-            break;
-        }
-    }
-
-    if (found == FALSE) {
-        WARN("No device found matching given ID!\n");
-        return DSERR_NODRIVER;
-    }
-
-    if (DSOUND_renderer[wod]) {
-        if (IsEqualGUID(&devGUID, &DSOUND_renderer[wod]->guid)) {
-            device = DSOUND_renderer[wod];
-            DirectSoundDevice_AddRef(device);
-            *ppDevice = device;
-            return DS_OK;
-        } else {
-            ERR("device GUID doesn't match\n");
-            hr = DSERR_GENERIC;
-            return hr;
-        }
-    } else {
-        hr = DirectSoundDevice_Create(&device);
-        if (hr != DS_OK) {
-            WARN("DirectSoundDevice_Create failed\n");
-            return hr;
-        }
-    }
-
-    *ppDevice = device;
-    device->guid = devGUID;
-    device->driver = NULL;
-
-    device->drvdesc.dnDevNode = wod;
-    hr = DSOUND_ReopenDevice(device, FALSE);
-    if (FAILED(hr))
-    {
-        WARN("DSOUND_ReopenDevice failed: %08x\n", hr);
-        return hr;
-    }
-
-    if (device->driver) {
-        /* the driver is now open, so it's now allowed to call GetCaps */
-        hr = IDsDriver_GetCaps(device->driver,&(device->drvcaps));
-        if (hr != DS_OK) {
-            WARN("IDsDriver_GetCaps failed\n");
-            return hr;
-        }
-    } else {
-        WAVEOUTCAPSA woc;
-        hr = mmErr(waveOutGetDevCapsA(device->drvdesc.dnDevNode, &woc, sizeof(woc)));
-        if (hr != DS_OK) {
-            WARN("waveOutGetDevCaps failed\n");
-            return hr;
-        }
-        ZeroMemory(&device->drvcaps, sizeof(device->drvcaps));
-        if ((woc.dwFormats & WAVE_FORMAT_1M08) ||
-            (woc.dwFormats & WAVE_FORMAT_2M08) ||
-            (woc.dwFormats & WAVE_FORMAT_4M08) ||
-            (woc.dwFormats & WAVE_FORMAT_48M08) ||
-            (woc.dwFormats & WAVE_FORMAT_96M08)) {
-            device->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT;
-            device->drvcaps.dwFlags |= DSCAPS_PRIMARYMONO;
-        }
-        if ((woc.dwFormats & WAVE_FORMAT_1M16) ||
-            (woc.dwFormats & WAVE_FORMAT_2M16) ||
-            (woc.dwFormats & WAVE_FORMAT_4M16) ||
-            (woc.dwFormats & WAVE_FORMAT_48M16) ||
-            (woc.dwFormats & WAVE_FORMAT_96M16)) {
-            device->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT;
-            device->drvcaps.dwFlags |= DSCAPS_PRIMARYMONO;
-        }
-        if ((woc.dwFormats & WAVE_FORMAT_1S08) ||
-            (woc.dwFormats & WAVE_FORMAT_2S08) ||
-            (woc.dwFormats & WAVE_FORMAT_4S08) ||
-            (woc.dwFormats & WAVE_FORMAT_48S08) ||
-            (woc.dwFormats & WAVE_FORMAT_96S08)) {
-            device->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT;
-            device->drvcaps.dwFlags |= DSCAPS_PRIMARYSTEREO;
-        }
-        if ((woc.dwFormats & WAVE_FORMAT_1S16) ||
-            (woc.dwFormats & WAVE_FORMAT_2S16) ||
-            (woc.dwFormats & WAVE_FORMAT_4S16) ||
-            (woc.dwFormats & WAVE_FORMAT_48S16) ||
-            (woc.dwFormats & WAVE_FORMAT_96S16)) {
-            device->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT;
-            device->drvcaps.dwFlags |= DSCAPS_PRIMARYSTEREO;
-        }
-        if (ds_emuldriver)
-            device->drvcaps.dwFlags |= DSCAPS_EMULDRIVER;
-        device->drvcaps.dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
-        device->drvcaps.dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
-        ZeroMemory(&device->volpan, sizeof(device->volpan));
-    }
-
-    hr = DSOUND_PrimaryCreate(device);
-    if (hr == DS_OK) {
-        UINT triggertime = DS_TIME_DEL, res = DS_TIME_RES, id;
-        TIMECAPS time;
-
-        DSOUND_renderer[device->drvdesc.dnDevNode] = device;
-        timeGetDevCaps(&time, sizeof(TIMECAPS));
-        TRACE("Minimum timer resolution: %u, max timer: %u\n", time.wPeriodMin, time.wPeriodMax);
-        if (triggertime < time.wPeriodMin)
-            triggertime = time.wPeriodMin;
-        if (res < time.wPeriodMin)
-            res = time.wPeriodMin;
-        if (timeBeginPeriod(res) == TIMERR_NOCANDO)
-            WARN("Could not set minimum resolution, don't expect sound\n");
-        id = timeSetEvent(triggertime, res, DSOUND_timer, (DWORD_PTR)device, TIME_PERIODIC | TIME_KILL_SYNCHRONOUS);
-        if (!id)
-        {
-            WARN("Timer not created! Retrying without TIME_KILL_SYNCHRONOUS\n");
-            id = timeSetEvent(triggertime, res, DSOUND_timer, (DWORD_PTR)device, TIME_PERIODIC);
-            if (!id) ERR("Could not create timer, sound playback will not occur\n");
-        }
-        DSOUND_renderer[device->drvdesc.dnDevNode]->timerID = id;
-    } else {
-        WARN("DSOUND_PrimaryCreate failed\n");
-    }
-
-    return hr;
-}
-
-HRESULT DirectSoundDevice_CreateSoundBuffer(
-    DirectSoundDevice * device,
-    LPCDSBUFFERDESC dsbd,
-    LPLPDIRECTSOUNDBUFFER ppdsb,
-    LPUNKNOWN lpunk,
-    BOOL from8)
-{
-    HRESULT hres = DS_OK;
-    TRACE("(%p,%p,%p,%p)\n",device,dsbd,ppdsb,lpunk);
-
-    if (device == NULL) {
-        WARN("not initialized\n");
-        return DSERR_UNINITIALIZED;
-    }
-
-    if (dsbd == NULL) {
-        WARN("invalid parameter: dsbd == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (dsbd->dwSize != sizeof(DSBUFFERDESC) &&
-        dsbd->dwSize != sizeof(DSBUFFERDESC1)) {
-        WARN("invalid parameter: dsbd\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppdsb == NULL) {
-        WARN("invalid parameter: ppdsb == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-    *ppdsb = NULL;
-
-    if (TRACE_ON(dsound)) {
-        TRACE("(structsize=%d)\n",dsbd->dwSize);
-        TRACE("(flags=0x%08x:\n",dsbd->dwFlags);
-        _dump_DSBCAPS(dsbd->dwFlags);
-        TRACE(")\n");
-        TRACE("(bufferbytes=%d)\n",dsbd->dwBufferBytes);
-        TRACE("(lpwfxFormat=%p)\n",dsbd->lpwfxFormat);
-    }
-
-    if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) {
-        if (dsbd->lpwfxFormat != NULL) {
-            WARN("invalid parameter: dsbd->lpwfxFormat must be NULL for "
-                 "primary buffer\n");
-            return DSERR_INVALIDPARAM;
-        }
-
-        if (device->primary) {
-            WARN("Primary Buffer already created\n");
-            IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)(device->primary));
-            *ppdsb = (LPDIRECTSOUNDBUFFER)(device->primary);
-        } else {
-           device->dsbd = *dsbd;
-           device->dsbd.dwFlags &= ~(DSBCAPS_LOCHARDWARE | DSBCAPS_LOCSOFTWARE);
-           if (device->hwbuf)
-               device->dsbd.dwFlags |= DSBCAPS_LOCHARDWARE;
-           else device->dsbd.dwFlags |= DSBCAPS_LOCSOFTWARE;
-           hres = PrimaryBufferImpl_Create(device, &(device->primary), &(device->dsbd));
-           if (device->primary) {
-               IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)(device->primary));
-               *ppdsb = (LPDIRECTSOUNDBUFFER)(device->primary);
-           } else
-               WARN("PrimaryBufferImpl_Create failed\n");
-        }
-    } else {
-        IDirectSoundBufferImpl * dsb;
-        WAVEFORMATEXTENSIBLE *pwfxe;
-
-        if (dsbd->lpwfxFormat == NULL) {
-            WARN("invalid parameter: dsbd->lpwfxFormat can't be NULL for "
-                 "secondary buffer\n");
-            return DSERR_INVALIDPARAM;
-        }
-        pwfxe = (WAVEFORMATEXTENSIBLE*)dsbd->lpwfxFormat;
-
-        if (pwfxe->Format.wBitsPerSample != 16 && pwfxe->Format.wBitsPerSample != 8 && pwfxe->Format.wFormatTag != WAVE_FORMAT_EXTENSIBLE)
-        {
-            WARN("wBitsPerSample=%d needs a WAVEFORMATEXTENSIBLE\n", dsbd->lpwfxFormat->wBitsPerSample);
-            return DSERR_CONTROLUNAVAIL;
-        }
-        if (pwfxe->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE)
-        {
-            if (pwfxe->Format.cbSize < (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)))
-            {
-                WARN("Too small a cbSize %u\n", pwfxe->Format.cbSize);
-                return DSERR_INVALIDPARAM;
-            }
-
-            if (pwfxe->Format.cbSize > (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)))
-            {
-                WARN("Too big a cbSize %u\n", pwfxe->Format.cbSize);
-                return DSERR_CONTROLUNAVAIL;
-            }
-
-            if (!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))
-            {
-                if (!IsEqualGUID(&pwfxe->SubFormat, &GUID_NULL))
-                    FIXME("SubFormat %s not supported right now.\n", debugstr_guid(&pwfxe->SubFormat));
-                return DSERR_INVALIDPARAM;
-            }
-            if (pwfxe->Samples.wValidBitsPerSample > dsbd->lpwfxFormat->wBitsPerSample)
-            {
-                WARN("Samples.wValidBitsPerSample(%d) > Format.wBitsPerSample (%d)\n", pwfxe->Samples.wValidBitsPerSample, pwfxe->Format.wBitsPerSample);
-                return DSERR_INVALIDPARAM;
-            }
-            if (pwfxe->Samples.wValidBitsPerSample && pwfxe->Samples.wValidBitsPerSample < dsbd->lpwfxFormat->wBitsPerSample)
-            {
-                FIXME("Non-packed formats not supported right now: %d/%d\n", pwfxe->Samples.wValidBitsPerSample, dsbd->lpwfxFormat->wBitsPerSample);
-                return DSERR_CONTROLUNAVAIL;
-            }
-        }
-
-        TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
-              "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
-              dsbd->lpwfxFormat->wFormatTag, dsbd->lpwfxFormat->nChannels,
-              dsbd->lpwfxFormat->nSamplesPerSec,
-              dsbd->lpwfxFormat->nAvgBytesPerSec,
-              dsbd->lpwfxFormat->nBlockAlign,
-              dsbd->lpwfxFormat->wBitsPerSample, dsbd->lpwfxFormat->cbSize);
-
-        if (from8 && (dsbd->dwFlags & DSBCAPS_CTRL3D) && (dsbd->lpwfxFormat->nChannels != 1)) {
-            WARN("invalid parameter: 3D buffer format must be mono\n");
-            return DSERR_INVALIDPARAM;
-        }
-
-        hres = IDirectSoundBufferImpl_Create(device, &dsb, dsbd);
-        if (dsb) {
-            hres = SecondaryBufferImpl_Create(dsb, (SecondaryBufferImpl**)ppdsb);
-            if (*ppdsb) {
-                dsb->secondary = (SecondaryBufferImpl*)*ppdsb;
-                IDirectSoundBuffer_AddRef(*ppdsb);
-            } else
-                WARN("SecondaryBufferImpl_Create failed\n");
-        } else
-           WARN("IDirectSoundBufferImpl_Create failed\n");
-   }
-
-   return hres;
-}
-
-HRESULT DirectSoundDevice_DuplicateSoundBuffer(
-    DirectSoundDevice * device,
-    LPDIRECTSOUNDBUFFER psb,
-    LPLPDIRECTSOUNDBUFFER ppdsb)
-{
-    HRESULT hres = DS_OK;
-    IDirectSoundBufferImpl* dsb;
-    TRACE("(%p,%p,%p)\n",device,psb,ppdsb);
-
-    if (device == NULL) {
-        WARN("not initialized\n");
-        return DSERR_UNINITIALIZED;
-    }
-
-    if (psb == NULL) {
-        WARN("invalid parameter: psb == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppdsb == NULL) {
-        WARN("invalid parameter: ppdsb == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    /* make sure we have a secondary buffer */
-    if ((PrimaryBufferImpl *)psb == device->primary) {
-        WARN("trying to duplicate primary buffer\n");
-        *ppdsb = NULL;
-        return DSERR_INVALIDCALL;
-    }
-
-    /* duplicate the actual buffer implementation */
-    hres = IDirectSoundBufferImpl_Duplicate(device, &dsb,
-                                           ((SecondaryBufferImpl *)psb)->dsb);
-
-    if (hres == DS_OK) {
-        /* create a new secondary buffer using the new implementation */
-        hres = SecondaryBufferImpl_Create(dsb, (SecondaryBufferImpl**)ppdsb);
-        if (*ppdsb) {
-            dsb->secondary = (SecondaryBufferImpl*)*ppdsb;
-            IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)*ppdsb);
-        } else {
-            WARN("SecondaryBufferImpl_Create failed\n");
-            IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)dsb);
-            IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)dsb);
-        }
-    }
-
-    return hres;
-}
-
-HRESULT DirectSoundDevice_SetCooperativeLevel(
-    DirectSoundDevice * device,
-    HWND hwnd,
-    DWORD level)
-{
-    TRACE("(%p,%p,%s)\n",device,hwnd,dumpCooperativeLevel(level));
-
-    if (device == NULL) {
-        WARN("not initialized\n");
-        return DSERR_UNINITIALIZED;
-    }
-
-    if (level==DSSCL_PRIORITY || level==DSSCL_EXCLUSIVE) {
-        WARN("level=%s not fully supported\n",
-             level==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE");
-    }
-
-    device->priolevel = level;
-    return DS_OK;
-}
-
-HRESULT DirectSoundDevice_Compact(
-    DirectSoundDevice * device)
-{
-    TRACE("(%p)\n", device);
-
-    if (device == NULL) {
-        WARN("not initialized\n");
-        return DSERR_UNINITIALIZED;
-    }
-
-    if (device->priolevel < DSSCL_PRIORITY) {
-        WARN("incorrect priority level\n");
-        return DSERR_PRIOLEVELNEEDED;
-    }
-
-    return DS_OK;
-}
-
-HRESULT DirectSoundDevice_GetSpeakerConfig(
-    DirectSoundDevice * device,
-    LPDWORD lpdwSpeakerConfig)
-{
-    TRACE("(%p, %p)\n", device, lpdwSpeakerConfig);
-
-    if (device == NULL) {
-        WARN("not initialized\n");
-        return DSERR_UNINITIALIZED;
-    }
-
-    if (lpdwSpeakerConfig == NULL) {
-        WARN("invalid parameter: lpdwSpeakerConfig == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    WARN("not fully functional\n");
-    *lpdwSpeakerConfig = device->speaker_config;
-    return DS_OK;
-}
-
-HRESULT DirectSoundDevice_SetSpeakerConfig(
-    DirectSoundDevice * device,
-    DWORD config)
-{
-    TRACE("(%p,0x%08x)\n",device,config);
-
-    if (device == NULL) {
-        WARN("not initialized\n");
-        return DSERR_UNINITIALIZED;
-    }
-
-    device->speaker_config = config;
-    WARN("not fully functional\n");
-    return DS_OK;
-}
-
-static HRESULT DirectSoundDevice_VerifyCertification(
-    DirectSoundDevice * device,
-    LPDWORD pdwCertified)
-{
-    TRACE("(%p, %p)\n",device,pdwCertified);
-
-    if (device == NULL) {
-        WARN("not initialized\n");
-        return DSERR_UNINITIALIZED;
-    }
-
-    if (device->drvcaps.dwFlags & DSCAPS_CERTIFIED)
-        *pdwCertified = DS_CERTIFIED;
-    else
-        *pdwCertified = DS_UNCERTIFIED;
-
-    return DS_OK;
-}
-
-/*
- * Add secondary buffer to buffer list.
- * Gets exclusive access to buffer for writing.
- */
-HRESULT DirectSoundDevice_AddBuffer(
-    DirectSoundDevice * device,
-    IDirectSoundBufferImpl * pDSB)
-{
-    IDirectSoundBufferImpl **newbuffers;
-    HRESULT hr = DS_OK;
-
-    TRACE("(%p, %p)\n", device, pDSB);
-
-    RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
-
-    if (device->buffers)
-        newbuffers = HeapReAlloc(GetProcessHeap(),0,device->buffers,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
-    else
-        newbuffers = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
-
-    if (newbuffers) {
-        device->buffers = newbuffers;
-        device->buffers[device->nrofbuffers] = pDSB;
-        device->nrofbuffers++;
-        TRACE("buffer count is now %d\n", device->nrofbuffers);
-    } else {
-        ERR("out of memory for buffer list! Current buffer count is %d\n", device->nrofbuffers);
-        hr = DSERR_OUTOFMEMORY;
-    }
-
-    RtlReleaseResource(&(device->buffer_list_lock));
-
-    return hr;
-}
-
-/*
- * Remove secondary buffer from buffer list.
- * Gets exclusive access to buffer for writing.
- */
-HRESULT DirectSoundDevice_RemoveBuffer(
-    DirectSoundDevice * device,
-    IDirectSoundBufferImpl * pDSB)
-{
-    int i;
-    HRESULT hr = DS_OK;
-
-    TRACE("(%p, %p)\n", device, pDSB);
-
-    RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
-
-    for (i = 0; i < device->nrofbuffers; i++)
-        if (device->buffers[i] == pDSB)
-            break;
-
-    if (i < device->nrofbuffers) {
-        /* Put the last buffer of the list in the (now empty) position */
-        device->buffers[i] = device->buffers[device->nrofbuffers - 1];
-        device->nrofbuffers--;
-        device->buffers = HeapReAlloc(GetProcessHeap(),0,device->buffers,sizeof(LPDIRECTSOUNDBUFFER8)*device->nrofbuffers);
-        TRACE("buffer count is now %d\n", device->nrofbuffers);
-    }
-
-    if (device->nrofbuffers == 0) {
-        HeapFree(GetProcessHeap(),0,device->buffers);
-        device->buffers = NULL;
-    }
-
-    RtlReleaseResource(&(device->buffer_list_lock));
-
-    return hr;
-}
diff --git a/dll/directx/dsound/dsound.rbuild b/dll/directx/dsound/dsound.rbuild
deleted file mode 100644 (file)
index 41453e4..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
-<module name="dsound" type="win32dll" baseaddress="${BASEADDRESS_DSOUND}" installbase="system32" installname="dsound.dll" crt="msvcrt">
-       <autoregister infsection="OleControlDlls" type="DllRegisterServer" />
-       <importlibrary definition="dsound.spec" />
-       <include base="dsound">.</include>
-       <include base="ReactOS">include/reactos/wine</include>
-       <define name="_WINE" />
-       <library>wine</library>
-       <library>uuid</library>
-       <library>ntdll</library>
-       <library>user32</library>
-       <library>advapi32</library>
-       <library>ole32</library>
-       <library>winmm</library>
-       <library>dxguid</library>
-       <file>version.rc</file>
-       <file>buffer.c</file>
-       <file>capture.c</file>
-       <file>dsound.c</file>
-       <file>dsound_convert.c</file>
-       <file>dsound_main.c</file>
-       <file>duplex.c</file>
-       <file>mixer.c</file>
-       <file>primary.c</file>
-       <file>propset.c</file>
-       <file>regsvr.c</file>
-       <file>sound3d.c</file>
-</module>
diff --git a/dll/directx/dsound/dsound.spec b/dll/directx/dsound/dsound.spec
deleted file mode 100644 (file)
index e4878a8..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-1 stdcall DirectSoundCreate(ptr ptr ptr)
-2 stdcall DirectSoundEnumerateA(ptr ptr)
-3 stdcall DirectSoundEnumerateW(ptr ptr)
-6 stdcall DirectSoundCaptureCreate(ptr ptr ptr)
-7 stdcall DirectSoundCaptureEnumerateA(ptr ptr)
-8 stdcall DirectSoundCaptureEnumerateW(ptr ptr)
-9 stdcall GetDeviceID(ptr ptr)
-10 stdcall DirectSoundFullDuplexCreate(ptr ptr ptr ptr long long ptr ptr ptr ptr)
-11 stdcall DirectSoundCreate8(ptr ptr ptr)
-12 stdcall DirectSoundCaptureCreate8(ptr ptr ptr)
-@ stdcall -private DllCanUnloadNow()
-@ stdcall -private DllGetClassObject(ptr ptr ptr)
-@ stdcall -private DllRegisterServer()
-@ stdcall -private DllUnregisterServer()
diff --git a/dll/directx/dsound/dsound_convert.c b/dll/directx/dsound/dsound_convert.c
deleted file mode 100644 (file)
index 0a6e474..0000000
+++ /dev/null
@@ -1,435 +0,0 @@
-/* DirectSound format conversion and mixing routines
- *
- * Copyright 2007 Maarten Lankhorst
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-/* 8 bits is unsigned, the rest is signed.
- * First I tried to reuse existing stuff from alsa-lib, after that
- * didn't work, I gave up and just went for individual hacks.
- *
- * 24 bit is expensive to do, due to unaligned access.
- * In dlls/winex11.drv/dib_convert.c convert_888_to_0888_asis there is a way
- * around it, but I'm happy current code works, maybe something for later.
- *
- * The ^ 0x80 flips the signed bit, this is the conversion from
- * signed (-128.. 0.. 127) to unsigned (0...255)
- * This is only temporary: All 8 bit data should be converted to signed.
- * then when fed to the sound card, it should be converted to unsigned again.
- *
- * Sound is LITTLE endian
- */
-
-#include "config.h"
-
-#include <stdarg.h>
-
-#define NONAMELESSSTRUCT
-#define NONAMELESSUNION
-#include "windef.h"
-#include "winbase.h"
-#include "mmsystem.h"
-#include "winternl.h"
-#include "wine/debug.h"
-#include "dsound.h"
-#include "dsdriver.h"
-#include "dsound_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(dsound);
-
-#ifdef WORDS_BIGENDIAN
-#define le16(x) RtlUshortByteSwap((x))
-#define le32(x) RtlUlongByteSwap((x))
-#else
-#define le16(x) (x)
-#define le32(x) (x)
-#endif
-
-static inline void src_advance(const void **src, UINT stride, INT *count, UINT *freqAcc, UINT adj)
-{
-    *freqAcc += adj;
-    if (*freqAcc >= (1 << DSOUND_FREQSHIFT))
-    {
-        ULONG adv = (*freqAcc >> DSOUND_FREQSHIFT);
-        *freqAcc &= (1 << DSOUND_FREQSHIFT) - 1;
-        *(const char **)src += adv * stride;
-        *count -= adv;
-    }
-}
-
-static void convert_8_to_8 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        *(BYTE *)dst = *(const BYTE *)src;
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_8_to_16 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        WORD dest = *(const BYTE *)src, *dest16 = dst;
-        *dest16 = le16(dest * 257 - 32768);
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_8_to_24 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        BYTE dest = *(const BYTE *)src;
-        BYTE *dest24 = dst;
-        dest24[0] = dest;
-        dest24[1] = dest;
-        dest24[2] = dest - 0x80;
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_8_to_32 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        DWORD dest = *(const BYTE *)src, *dest32 = dst;
-        *dest32 = le32(dest * 16843009 - 2147483648U);
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_16_to_8 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        BYTE *dst8 = dst;
-        *dst8 = (le16(*(const WORD *)src)) / 256;
-        *dst8 -= 0x80;
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_16_to_16 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        *(WORD *)dst = *(const WORD *)src;
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_16_to_24 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        WORD dest = le16(*(const WORD *)src);
-        BYTE *dest24 = dst;
-
-        dest24[0] = dest / 256;
-        dest24[1] = dest;
-        dest24[2] = dest / 256;
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_16_to_32 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        DWORD dest = *(const WORD *)src, *dest32 = dst;
-        *dest32 = dest * 65537;
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_24_to_8 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        BYTE *dst8 = dst;
-        *dst8 = ((const BYTE *)src)[2];
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_24_to_16 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        WORD *dest16 = dst;
-        const BYTE *source = src;
-        *dest16 = le16(source[2] * 256 + source[1]);
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_24_to_24 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        BYTE *dest24 = dst;
-        const BYTE *src24 = src;
-
-        dest24[0] = src24[0];
-        dest24[1] = src24[1];
-        dest24[2] = src24[2];
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_24_to_32 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        DWORD *dest32 = dst;
-        const BYTE *source = src;
-        *dest32 = le32(source[2] * 16777217 + source[1] * 65536 + source[0] * 256);
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_32_to_8 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        BYTE *dst8 = dst;
-        *dst8 = (le32(*(const DWORD *)src) / 16777216);
-        *dst8 -= 0x80;
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_32_to_16 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        WORD *dest16 = dst;
-        *dest16 = le16(le32(*(const DWORD *)src) / 65536);
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_32_to_24 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        DWORD dest = le32(*(const DWORD *)src);
-        BYTE *dest24 = dst;
-
-        dest24[0] = dest / 256;
-        dest24[1] = dest / 65536;
-        dest24[2] = dest / 16777216;
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-static void convert_32_to_32 (const void *src, void *dst, UINT src_stride,
-        UINT dst_stride, INT count, UINT freqAcc, UINT adj)
-{
-    while (count > 0)
-    {
-        DWORD *dest = dst;
-        *dest = *(const DWORD *)src;
-
-        dst = (char *)dst + dst_stride;
-        src_advance(&src, src_stride, &count, &freqAcc, adj);
-    }
-}
-
-const bitsconvertfunc convertbpp[4][4] = {
-    { convert_8_to_8, convert_8_to_16, convert_8_to_24, convert_8_to_32 },
-    { convert_16_to_8, convert_16_to_16, convert_16_to_24, convert_16_to_32 },
-    { convert_24_to_8, convert_24_to_16, convert_24_to_24, convert_24_to_32 },
-    { convert_32_to_8, convert_32_to_16, convert_32_to_24, convert_32_to_32 },
-};
-
-static void mix8(signed char *src, INT *dst, unsigned len)
-{
-    TRACE("%p - %p %d\n", src, dst, len);
-    while (len--)
-        /* 8-bit WAV is unsigned, it's here converted to signed, normalize function will convert it back again */
-        *(dst++) += (signed char)((BYTE)*(src++) - (BYTE)0x80);
-}
-
-static void mix16(SHORT *src, INT *dst, unsigned len)
-{
-    TRACE("%p - %p %d\n", src, dst, len);
-    len /= 2;
-    while (len--)
-    {
-        *dst += le16(*src);
-        ++dst; ++src;
-    }
-}
-
-static void mix24(BYTE *src, INT *dst, unsigned len)
-{
-    TRACE("%p - %p %d\n", src, dst, len);
-    len /= 3;
-    while (len--)
-    {
-        DWORD field;
-        field = ((DWORD)src[2] << 16) + ((DWORD)src[1] << 8) + (DWORD)src[0];
-        if (src[2] & 0x80)
-            field |= 0xFF000000U;
-        *(dst++) += field;
-        ++src;
-    }
-}
-
-static void mix32(INT *src, LONGLONG *dst, unsigned len)
-{
-    TRACE("%p - %p %d\n", src, dst, len);
-    len /= 4;
-    while (len--)
-        *(dst++) += le32(*(src++));
-}
-
-const mixfunc mixfunctions[4] = {
-    (mixfunc)mix8,
-    (mixfunc)mix16,
-    (mixfunc)mix24,
-    (mixfunc)mix32
-};
-
-static void norm8(INT *src, signed char *dst, unsigned len)
-{
-    TRACE("%p - %p %d\n", src, dst, len);
-    while (len--)
-    {
-        *dst = (*src) + 0x80;
-        if (*src < -0x80)
-            *dst = 0;
-        else if (*src > 0x7f)
-            *dst = 0xff;
-        ++dst;
-        ++src;
-    }
-}
-
-static void norm16(INT *src, SHORT *dst, unsigned len)
-{
-    TRACE("%p - %p %d\n", src, dst, len);
-    len /= 2;
-    while (len--)
-    {
-        *dst = le16(*src);
-        if (*src <= -0x8000)
-            *dst = le16(0x8000);
-        else if (*src > 0x7fff)
-            *dst = le16(0x7fff);
-        ++dst;
-        ++src;
-    }
-}
-
-static void norm24(INT *src, BYTE *dst, unsigned len)
-{
-    TRACE("%p - %p %d\n", src, dst, len);
-    len /= 3;
-    while (len--)
-    {
-        if (*src <= -0x800000)
-        {
-            dst[0] = 0;
-            dst[1] = 0;
-            dst[2] = 0x80;
-        }
-        else if (*src > 0x7fffff)
-        {
-            dst[0] = 0xff;
-            dst[1] = 0xff;
-            dst[2] = 0x7f;
-        }
-        else
-        {
-            dst[0] = *src;
-            dst[1] = *src >> 8;
-            dst[2] = *src >> 16;
-        }
-        ++dst;
-        ++src;
-    }
-}
-
-static void norm32(LONGLONG *src, INT *dst, unsigned len)
-{
-    TRACE("%p - %p %d\n", src, dst, len);
-    len /= 4;
-    while (len--)
-    {
-        *dst = le32(*src);
-        if (*src <= -(LONGLONG)0x80000000)
-            *dst = le32(0x80000000);
-        else if (*src > 0x7fffffff)
-            *dst = le32(0x7fffffff);
-        ++dst;
-        ++src;
-    }
-}
-
-const normfunc normfunctions[4] = {
-    (normfunc)norm8,
-    (normfunc)norm16,
-    (normfunc)norm24,
-    (normfunc)norm32,
-};
diff --git a/dll/directx/dsound/dsound_main.c b/dll/directx/dsound/dsound_main.c
deleted file mode 100644 (file)
index 44897bc..0000000
+++ /dev/null
@@ -1,595 +0,0 @@
-/*                     DirectSound
- *
- * Copyright 1998 Marcus Meissner
- * Copyright 1998 Rob Riggs
- * Copyright 2000-2002 TransGaming Technologies, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- *
- * Most thread locking is complete. There may be a few race
- * conditions still lurking.
- *
- * TODO:
- *     Implement SetCooperativeLevel properly (need to address focus issues)
- *     Implement DirectSound3DBuffers (stubs in place)
- *     Use hardware 3D support if available
- *      Add critical section locking inside Release and AddRef methods
- *      Handle static buffers - put those in hardware, non-static not in hardware
- *      Hardware DuplicateSoundBuffer
- *      Proper volume calculation for 3d buffers
- *      Remove DS_HEL_FRAGS and use mixer fragment length for it
- */
-
-#include <stdarg.h>
-
-#define COBJMACROS
-#define NONAMELESSSTRUCT
-#define NONAMELESSUNION
-#include "windef.h"
-#include "winbase.h"
-#include "winuser.h"
-#include "winnls.h"
-#include "winreg.h"
-#include "mmsystem.h"
-#include "winternl.h"
-#include "mmddk.h"
-#include "wine/debug.h"
-#include "dsound.h"
-#include "dsconf.h"
-#include "ks.h"
-#include "initguid.h"
-#include "ksmedia.h"
-#include "dsdriver.h"
-
-#include "dsound_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(dsound);
-
-DirectSoundDevice*     DSOUND_renderer[MAXWAVEDRIVERS];
-GUID                    DSOUND_renderer_guids[MAXWAVEDRIVERS];
-GUID                    DSOUND_capture_guids[MAXWAVEDRIVERS];
-
-HRESULT mmErr(UINT err)
-{
-       switch(err) {
-       case MMSYSERR_NOERROR:
-               return DS_OK;
-       case MMSYSERR_ALLOCATED:
-               return DSERR_ALLOCATED;
-       case MMSYSERR_ERROR:
-       case MMSYSERR_INVALHANDLE:
-       case WAVERR_STILLPLAYING:
-               return DSERR_GENERIC; /* FIXME */
-       case MMSYSERR_NODRIVER:
-               return DSERR_NODRIVER;
-       case MMSYSERR_NOMEM:
-               return DSERR_OUTOFMEMORY;
-       case MMSYSERR_INVALPARAM:
-       case WAVERR_BADFORMAT:
-       case WAVERR_UNPREPARED:
-               return DSERR_INVALIDPARAM;
-       case MMSYSERR_NOTSUPPORTED:
-               return DSERR_UNSUPPORTED;
-       default:
-               FIXME("Unknown MMSYS error %d\n",err);
-               return DSERR_GENERIC;
-       }
-}
-
-/* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
-int ds_emuldriver = 0;
-int ds_hel_buflen = 32768 * 2;
-int ds_snd_queue_max = 10;
-int ds_snd_queue_min = 6;
-int ds_snd_shadow_maxsize = 2;
-int ds_hw_accel = DS_HW_ACCEL_FULL;
-int ds_default_sample_rate = 44100;
-int ds_default_bits_per_sample = 16;
-static int ds_default_playback;
-static int ds_default_capture;
-
-/*
- * Get a config key from either the app-specific or the default config
- */
-
-static inline DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
-                                    char *buffer, DWORD size )
-{
-    if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
-    if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE)buffer, &size )) return 0;
-    return ERROR_FILE_NOT_FOUND;
-}
-
-
-/*
- * Setup the dsound options.
- */
-
-void setup_dsound_options(void)
-{
-    char buffer[MAX_PATH+16];
-    HKEY hkey, appkey = 0;
-    DWORD len;
-
-    buffer[MAX_PATH]='\0';
-
-    /* @@ Wine registry key: HKCU\Software\Wine\DirectSound */
-    if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\DirectSound", &hkey )) hkey = 0;
-
-    len = GetModuleFileNameA( 0, buffer, MAX_PATH );
-    if (len && len < MAX_PATH)
-    {
-        HKEY tmpkey;
-        /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DirectSound */
-        if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
-        {
-            char *p, *appname = buffer;
-            if ((p = strrchr( appname, '/' ))) appname = p + 1;
-            if ((p = strrchr( appname, '\\' ))) appname = p + 1;
-            strcat( appname, "\\DirectSound" );
-            TRACE("appname = [%s]\n", appname);
-            if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
-            RegCloseKey( tmpkey );
-        }
-    }
-
-    /* get options */
-
-    if (!get_config_key( hkey, appkey, "EmulDriver", buffer, MAX_PATH ))
-        ds_emuldriver = strcmp(buffer, "N");
-
-    if (!get_config_key( hkey, appkey, "HelBuflen", buffer, MAX_PATH ))
-        ds_hel_buflen = atoi(buffer);
-
-    if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
-        ds_snd_queue_max = atoi(buffer);
-
-    if (!get_config_key( hkey, appkey, "SndQueueMin", buffer, MAX_PATH ))
-        ds_snd_queue_min = atoi(buffer);
-
-    if (!get_config_key( hkey, appkey, "HardwareAcceleration", buffer, MAX_PATH )) {
-       if (strcmp(buffer, "Full") == 0)
-           ds_hw_accel = DS_HW_ACCEL_FULL;
-       else if (strcmp(buffer, "Standard") == 0)
-           ds_hw_accel = DS_HW_ACCEL_STANDARD;
-       else if (strcmp(buffer, "Basic") == 0)
-           ds_hw_accel = DS_HW_ACCEL_BASIC;
-       else if (strcmp(buffer, "Emulation") == 0)
-           ds_hw_accel = DS_HW_ACCEL_EMULATION;
-    }
-
-    if (!get_config_key( hkey, appkey, "DefaultPlayback", buffer, MAX_PATH ))
-        ds_default_playback = atoi(buffer);
-
-    if (!get_config_key( hkey, appkey, "MaxShadowSize", buffer, MAX_PATH ))
-        ds_snd_shadow_maxsize = atoi(buffer);
-
-    if (!get_config_key( hkey, appkey, "DefaultCapture", buffer, MAX_PATH ))
-        ds_default_capture = atoi(buffer);
-
-    if (!get_config_key( hkey, appkey, "DefaultSampleRate", buffer, MAX_PATH ))
-        ds_default_sample_rate = atoi(buffer);
-
-    if (!get_config_key( hkey, appkey, "DefaultBitsPerSample", buffer, MAX_PATH ))
-        ds_default_bits_per_sample = atoi(buffer);
-
-    if (appkey) RegCloseKey( appkey );
-    if (hkey) RegCloseKey( hkey );
-
-    TRACE("ds_emuldriver = %d\n", ds_emuldriver);
-    TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
-    TRACE("ds_snd_queue_max = %d\n", ds_snd_queue_max);
-    TRACE("ds_snd_queue_min = %d\n", ds_snd_queue_min);
-    TRACE("ds_hw_accel = %s\n",
-        ds_hw_accel==DS_HW_ACCEL_FULL ? "Full" :
-        ds_hw_accel==DS_HW_ACCEL_STANDARD ? "Standard" :
-        ds_hw_accel==DS_HW_ACCEL_BASIC ? "Basic" :
-        ds_hw_accel==DS_HW_ACCEL_EMULATION ? "Emulation" :
-        "Unknown");
-    TRACE("ds_default_playback = %d\n", ds_default_playback);
-    TRACE("ds_default_capture = %d\n", ds_default_playback);
-    TRACE("ds_default_sample_rate = %d\n", ds_default_sample_rate);
-    TRACE("ds_default_bits_per_sample = %d\n", ds_default_bits_per_sample);
-    TRACE("ds_snd_shadow_maxsize = %d\n", ds_snd_shadow_maxsize);
-}
-
-static const char * get_device_id(LPCGUID pGuid)
-{
-    if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuid))
-        return "DSDEVID_DefaultPlayback";
-    else if (IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuid))
-        return "DSDEVID_DefaultVoicePlayback";
-    else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuid))
-        return "DSDEVID_DefaultCapture";
-    else if (IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuid))
-        return "DSDEVID_DefaultVoiceCapture";
-    return debugstr_guid(pGuid);
-}
-
-/***************************************************************************
- * GetDeviceID [DSOUND.9]
- *
- * Retrieves unique identifier of default device specified
- *
- * PARAMS
- *    pGuidSrc  [I] Address of device GUID.
- *    pGuidDest [O] Address to receive unique device GUID.
- *
- * RETURNS
- *    Success: DS_OK
- *    Failure: DSERR_INVALIDPARAM
- *
- * NOTES
- *    pGuidSrc is a valid device GUID or DSDEVID_DefaultPlayback,
- *    DSDEVID_DefaultCapture, DSDEVID_DefaultVoicePlayback, or
- *    DSDEVID_DefaultVoiceCapture.
- *    Returns pGuidSrc if pGuidSrc is a valid device or the device
- *    GUID for the specified constants.
- */
-HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
-{
-    TRACE("(%s,%p)\n", get_device_id(pGuidSrc),pGuidDest);
-
-    if ( pGuidSrc == NULL) {
-       WARN("invalid parameter: pGuidSrc == NULL\n");
-       return DSERR_INVALIDPARAM;
-    }
-
-    if ( pGuidDest == NULL ) {
-       WARN("invalid parameter: pGuidDest == NULL\n");
-       return DSERR_INVALIDPARAM;
-    }
-
-    if ( IsEqualGUID( &DSDEVID_DefaultPlayback, pGuidSrc ) ||
-        IsEqualGUID( &DSDEVID_DefaultVoicePlayback, pGuidSrc ) ) {
-       *pGuidDest = DSOUND_renderer_guids[ds_default_playback];
-        TRACE("returns %s\n", get_device_id(pGuidDest));
-       return DS_OK;
-    }
-
-    if ( IsEqualGUID( &DSDEVID_DefaultCapture, pGuidSrc ) ||
-        IsEqualGUID( &DSDEVID_DefaultVoiceCapture, pGuidSrc ) ) {
-       *pGuidDest = DSOUND_capture_guids[ds_default_capture];
-        TRACE("returns %s\n", get_device_id(pGuidDest));
-       return DS_OK;
-    }
-
-    *pGuidDest = *pGuidSrc;
-    TRACE("returns %s\n", get_device_id(pGuidDest));
-
-    return DS_OK;
-}
-
-
-/***************************************************************************
- * DirectSoundEnumerateA [DSOUND.2]
- *
- * Enumerate all DirectSound drivers installed in the system
- *
- * PARAMS
- *    lpDSEnumCallback  [I] Address of callback function.
- *    lpContext         [I] Address of user defined context passed to callback function.
- *
- * RETURNS
- *    Success: DS_OK
- *    Failure: DSERR_INVALIDPARAM
- */
-HRESULT WINAPI DirectSoundEnumerateA(
-    LPDSENUMCALLBACKA lpDSEnumCallback,
-    LPVOID lpContext)
-{
-    unsigned devs, wod;
-    DSDRIVERDESC desc;
-    GUID guid;
-    int err;
-
-    TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
-       lpDSEnumCallback, lpContext);
-
-    if (lpDSEnumCallback == NULL) {
-       WARN("invalid parameter: lpDSEnumCallback == NULL\n");
-       return DSERR_INVALIDPARAM;
-    }
-
-    devs = waveOutGetNumDevs();
-    if (devs > 0) {
-       if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
-           for (wod = 0; wod < devs; ++wod) {
-                if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod]) ) {
-                    err = mmErr(waveOutMessage(UlongToHandle(wod),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
-                    if (err == DS_OK) {
-                        TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
-                              "Primary Sound Driver","",lpContext);
-                        if (lpDSEnumCallback(NULL, "Primary Sound Driver", "", lpContext) == FALSE)
-                            return DS_OK;
-                   }
-               }
-           }
-       }
-    }
-
-    for (wod = 0; wod < devs; ++wod) {
-        err = mmErr(waveOutMessage(UlongToHandle(wod),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
-       if (err == DS_OK) {
-            TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
-                  debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
-            if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], desc.szDesc, desc.szDrvname, lpContext) == FALSE)
-                return DS_OK;
-       }
-    }
-    return DS_OK;
-}
-
-/***************************************************************************
- * DirectSoundEnumerateW [DSOUND.3]
- *
- * Enumerate all DirectSound drivers installed in the system
- *
- * PARAMS
- *    lpDSEnumCallback  [I] Address of callback function.
- *    lpContext         [I] Address of user defined context passed to callback function.
- *
- * RETURNS
- *    Success: DS_OK
- *    Failure: DSERR_INVALIDPARAM
- */
-HRESULT WINAPI DirectSoundEnumerateW(
-       LPDSENUMCALLBACKW lpDSEnumCallback,
-       LPVOID lpContext )
-{
-    unsigned devs, wod;
-    DSDRIVERDESC desc;
-    GUID guid;
-    int err;
-    WCHAR wDesc[MAXPNAMELEN];
-    WCHAR wName[MAXPNAMELEN];
-
-    TRACE("lpDSEnumCallback = %p, lpContext = %p\n",
-       lpDSEnumCallback, lpContext);
-
-    if (lpDSEnumCallback == NULL) {
-       WARN("invalid parameter: lpDSEnumCallback == NULL\n");
-       return DSERR_INVALIDPARAM;
-    }
-
-    devs = waveOutGetNumDevs();
-    if (devs > 0) {
-       if (GetDeviceID(&DSDEVID_DefaultPlayback, &guid) == DS_OK) {
-            static const WCHAR empty[] = { 0 };
-           for (wod = 0; wod < devs; ++wod) {
-                if (IsEqualGUID( &guid, &DSOUND_renderer_guids[wod] ) ) {
-                    err = mmErr(waveOutMessage(UlongToHandle(wod),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
-                    if (err == DS_OK) {
-                        TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
-                              "Primary Sound Driver",desc.szDrvname,lpContext);
-                        MultiByteToWideChar( CP_ACP, 0, "Primary Sound Driver", -1,
-                                             wDesc, sizeof(wDesc)/sizeof(WCHAR) );
-                        if (lpDSEnumCallback(NULL, wDesc, empty, lpContext) == FALSE)
-                            return DS_OK;
-                   }
-               }
-           }
-       }
-    }
-
-    for (wod = 0; wod < devs; ++wod) {
-        err = mmErr(waveOutMessage(UlongToHandle(wod),DRV_QUERYDSOUNDDESC,(DWORD_PTR)&desc,0));
-       if (err == DS_OK) {
-            TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
-                  debugstr_guid(&DSOUND_renderer_guids[wod]),desc.szDesc,desc.szDrvname,lpContext);
-            MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
-                                 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
-            MultiByteToWideChar( CP_ACP, 0, desc.szDrvname, -1,
-                                 wName, sizeof(wName)/sizeof(WCHAR) );
-            if (lpDSEnumCallback(&DSOUND_renderer_guids[wod], wDesc, wName, lpContext) == FALSE)
-                return DS_OK;
-       }
-    }
-    return DS_OK;
-}
-
-/*******************************************************************************
- * DirectSound ClassFactory
- */
-
-typedef  HRESULT (*FnCreateInstance)(REFIID riid, LPVOID *ppobj);
-typedef struct {
-    const IClassFactoryVtbl *lpVtbl;
-    LONG ref;
-    REFCLSID rclsid;
-    FnCreateInstance pfnCreateInstance;
-} IClassFactoryImpl;
-
-static HRESULT WINAPI
-DSCF_QueryInterface(LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj)
-{
-    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-    TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppobj);
-    if (ppobj == NULL)
-        return E_POINTER;
-    if (IsEqualIID(riid, &IID_IUnknown) ||
-        IsEqualIID(riid, &IID_IClassFactory))
-    {
-        *ppobj = iface;
-        IUnknown_AddRef(iface);
-        return S_OK;
-    }
-    *ppobj = NULL;
-    return E_NOINTERFACE;
-}
-
-static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
-{
-    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
-{
-    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-    /* static class, won't be freed */
-    return ref;
-}
-
-static HRESULT WINAPI DSCF_CreateInstance(
-    LPCLASSFACTORY iface,
-    LPUNKNOWN pOuter,
-    REFIID riid,
-    LPVOID *ppobj)
-{
-    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-    TRACE("(%p, %p, %s, %p)\n", This, pOuter, debugstr_guid(riid), ppobj);
-
-    if (pOuter)
-        return CLASS_E_NOAGGREGATION;
-
-    if (ppobj == NULL) {
-        WARN("invalid parameter\n");
-        return DSERR_INVALIDPARAM;
-    }
-    *ppobj = NULL;
-    return This->pfnCreateInstance(riid, ppobj);
-}
-static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
-{
-    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-    FIXME("(%p, %d) stub!\n", This, dolock);
-    return S_OK;
-}
-
-static const IClassFactoryVtbl DSCF_Vtbl = {
-    DSCF_QueryInterface,
-    DSCF_AddRef,
-    DSCF_Release,
-    DSCF_CreateInstance,
-    DSCF_LockServer
-};
-
-static IClassFactoryImpl DSOUND_CF[] = {
-    { &DSCF_Vtbl, 1, &CLSID_DirectSound, (FnCreateInstance)DSOUND_Create },
-    { &DSCF_Vtbl, 1, &CLSID_DirectSound8, (FnCreateInstance)DSOUND_Create8 },
-    { &DSCF_Vtbl, 1, &CLSID_DirectSoundCapture, (FnCreateInstance)DSOUND_CaptureCreate },
-    { &DSCF_Vtbl, 1, &CLSID_DirectSoundCapture8, (FnCreateInstance)DSOUND_CaptureCreate8 },
-    { &DSCF_Vtbl, 1, &CLSID_DirectSoundFullDuplex, (FnCreateInstance)DSOUND_FullDuplexCreate },
-    { &DSCF_Vtbl, 1, &CLSID_DirectSoundPrivate, (FnCreateInstance)IKsPrivatePropertySetImpl_Create },
-    { NULL, 0, NULL, NULL }
-};
-
-/*******************************************************************************
- * DllGetClassObject [DSOUND.@]
- * Retrieves class object from a DLL object
- *
- * NOTES
- *    Docs say returns STDAPI
- *
- * PARAMS
- *    rclsid [I] CLSID for the class object
- *    riid   [I] Reference to identifier of interface for class object
- *    ppv    [O] Address of variable to receive interface pointer for riid
- *
- * RETURNS
- *    Success: S_OK
- *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
- *             E_UNEXPECTED
- */
-HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
-{
-    int i = 0;
-    TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
-
-    if (ppv == NULL) {
-        WARN("invalid parameter\n");
-        return E_INVALIDARG;
-    }
-
-    *ppv = NULL;
-
-    if (!IsEqualIID(riid, &IID_IClassFactory) &&
-        !IsEqualIID(riid, &IID_IUnknown)) {
-        WARN("no interface for %s\n", debugstr_guid(riid));
-        return E_NOINTERFACE;
-    }
-
-    while (NULL != DSOUND_CF[i].rclsid) {
-        if (IsEqualGUID(rclsid, DSOUND_CF[i].rclsid)) {
-            DSCF_AddRef((IClassFactory*) &DSOUND_CF[i]);
-            *ppv = &DSOUND_CF[i];
-            return S_OK;
-        }
-        i++;
-    }
-
-    WARN("(%s, %s, %p): no class found.\n", debugstr_guid(rclsid),
-         debugstr_guid(riid), ppv);
-    return CLASS_E_CLASSNOTAVAILABLE;
-}
-
-
-/*******************************************************************************
- * DllCanUnloadNow [DSOUND.4]
- * Determines whether the DLL is in use.
- *
- * RETURNS
- *    Success: S_OK
- *    Failure: S_FALSE
- */
-HRESULT WINAPI DllCanUnloadNow(void)
-{
-    FIXME("(void): stub\n");
-    return S_FALSE;
-}
-
-#define INIT_GUID(guid, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)      \
-        guid.Data1 = l; guid.Data2 = w1; guid.Data3 = w2;               \
-        guid.Data4[0] = b1; guid.Data4[1] = b2; guid.Data4[2] = b3;     \
-        guid.Data4[3] = b4; guid.Data4[4] = b5; guid.Data4[5] = b6;     \
-        guid.Data4[6] = b7; guid.Data4[7] = b8;
-
-/***********************************************************************
- *           DllMain (DSOUND.init)
- */
-BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
-{
-    int i;
-    TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpvReserved);
-
-    switch (fdwReason) {
-    case DLL_PROCESS_ATTACH:
-        TRACE("DLL_PROCESS_ATTACH\n");
-        for (i = 0; i < MAXWAVEDRIVERS; i++) {
-            DSOUND_renderer[i] = NULL;
-            DSOUND_capture[i] = NULL;
-            INIT_GUID(DSOUND_renderer_guids[i], 0xbd6dd71a, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
-            INIT_GUID(DSOUND_capture_guids[i],  0xbd6dd71b, 0x3deb, 0x11d1, 0xb1, 0x71, 0x00, 0xc0, 0x4f, 0xc2, 0x00, 0x00 + i);
-        }
-        DisableThreadLibraryCalls(hInstDLL);
-        /* Increase refcount on dsound by 1 */
-        GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL);
-        break;
-    case DLL_PROCESS_DETACH:
-        TRACE("DLL_PROCESS_DETACH\n");
-        break;
-    default:
-        TRACE("UNKNOWN REASON\n");
-        break;
-    }
-    return TRUE;
-}
diff --git a/dll/directx/dsound/dsound_private.h b/dll/directx/dsound/dsound_private.h
deleted file mode 100644 (file)
index 221433f..0000000
+++ /dev/null
@@ -1,495 +0,0 @@
-/*                     DirectSound
- *
- * Copyright 1998 Marcus Meissner
- * Copyright 1998 Rob Riggs
- * Copyright 2000-2001 TransGaming Technologies, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-/* Linux does not support better timing than 10ms */
-#define DS_TIME_RES 2  /* Resolution of multimedia timer */
-#define DS_TIME_DEL 10  /* Delay of multimedia timer callback, and duration of HEL fragment */
-
-#include "wine/list.h"
-
-/* direct sound hardware acceleration levels */
-#define DS_HW_ACCEL_FULL        0      /* default on Windows 98 */
-#define DS_HW_ACCEL_STANDARD    1      /* default on Windows 2000 */
-#define DS_HW_ACCEL_BASIC       2
-#define DS_HW_ACCEL_EMULATION   3
-
-extern int ds_emuldriver;
-extern int ds_hel_buflen;
-extern int ds_snd_queue_max;
-extern int ds_snd_queue_min;
-extern int ds_snd_shadow_maxsize;
-extern int ds_hw_accel;
-extern int ds_default_sample_rate;
-extern int ds_default_bits_per_sample;
-
-/*****************************************************************************
- * Predeclare the interface implementation structures
- */
-typedef struct IDirectSoundImpl              IDirectSoundImpl;
-typedef struct IDirectSound_IUnknown         IDirectSound_IUnknown;
-typedef struct IDirectSound_IDirectSound     IDirectSound_IDirectSound;
-typedef struct IDirectSound8_IUnknown        IDirectSound8_IUnknown;
-typedef struct IDirectSound8_IDirectSound    IDirectSound8_IDirectSound;
-typedef struct IDirectSound8_IDirectSound8   IDirectSound8_IDirectSound8;
-typedef struct IDirectSoundBufferImpl        IDirectSoundBufferImpl;
-typedef struct IDirectSoundCaptureImpl       IDirectSoundCaptureImpl;
-typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
-typedef struct IDirectSoundFullDuplexImpl    IDirectSoundFullDuplexImpl;
-typedef struct IDirectSoundFullDuplex_IUnknown IDirectSoundFullDuplex_IUnknown;
-typedef struct IDirectSoundFullDuplex_IDirectSound IDirectSoundFullDuplex_IDirectSound;
-typedef struct IDirectSoundFullDuplex_IDirectSound8 IDirectSoundFullDuplex_IDirectSound8;
-typedef struct IDirectSoundFullDuplex_IDirectSoundCapture IDirectSoundFullDuplex_IDirectSoundCapture;
-typedef struct IDirectSoundNotifyImpl        IDirectSoundNotifyImpl;
-typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl;
-typedef struct IDirectSound3DListenerImpl    IDirectSound3DListenerImpl;
-typedef struct IDirectSound3DBufferImpl      IDirectSound3DBufferImpl;
-typedef struct IKsBufferPropertySetImpl      IKsBufferPropertySetImpl;
-typedef struct IKsPrivatePropertySetImpl     IKsPrivatePropertySetImpl;
-typedef struct PrimaryBufferImpl             PrimaryBufferImpl;
-typedef struct SecondaryBufferImpl           SecondaryBufferImpl;
-typedef struct DirectSoundDevice             DirectSoundDevice;
-typedef struct DirectSoundCaptureDevice      DirectSoundCaptureDevice;
-
-/* dsound_convert.h */
-typedef void (*bitsconvertfunc)(const void *, void *, UINT, UINT, INT, UINT, UINT);
-extern const bitsconvertfunc convertbpp[4][4];
-typedef void (*mixfunc)(const void *, void *, unsigned);
-extern const mixfunc mixfunctions[4];
-typedef void (*normfunc)(const void *, void *, unsigned);
-extern const normfunc normfunctions[4];
-
-/*****************************************************************************
- * IDirectSoundDevice implementation structure
- */
-struct DirectSoundDevice
-{
-    LONG                        ref;
-
-    GUID                        guid;
-    PIDSDRIVER                  driver;
-    DSDRIVERDESC                drvdesc;
-    DSDRIVERCAPS                drvcaps;
-    DWORD                       priolevel;
-    PWAVEFORMATEX               pwfx;
-    HWAVEOUT                    hwo;
-    LPWAVEHDR                   pwave;
-    UINT                        timerID, pwplay, pwqueue, prebuf, helfrags;
-    DWORD                       fraglen;
-    PIDSDRIVERBUFFER            hwbuf;
-    LPBYTE                      buffer;
-    DWORD                       writelead, buflen, state, playpos, mixpos;
-    int                         nrofbuffers;
-    IDirectSoundBufferImpl**    buffers;
-    RTL_RWLOCK                  buffer_list_lock;
-    CRITICAL_SECTION            mixlock;
-    PrimaryBufferImpl*          primary;
-    DSBUFFERDESC                dsbd;
-    DWORD                       speaker_config;
-    LPBYTE                      tmp_buffer, mix_buffer;
-    DWORD                       tmp_buffer_len, mix_buffer_len;
-
-    DSVOLUMEPAN                 volpan;
-
-    mixfunc mixfunction;
-    normfunc normfunction;
-
-    /* DirectSound3DListener fields */
-    IDirectSound3DListenerImpl*        listener;
-    DS3DLISTENER                ds3dl;
-    BOOL                        ds3dl_need_recalc;
-};
-
-/* reference counted buffer memory for duplicated buffer memory */
-typedef struct BufferMemory
-{
-    LONG                        ref;
-    LPBYTE                      memory;
-    struct list buffers;
-} BufferMemory;
-
-ULONG DirectSoundDevice_Release(DirectSoundDevice * device);
-HRESULT DirectSoundDevice_Initialize(
-    DirectSoundDevice ** ppDevice,
-    LPCGUID lpcGUID);
-HRESULT DirectSoundDevice_AddBuffer(
-    DirectSoundDevice * device,
-    IDirectSoundBufferImpl * pDSB);
-HRESULT DirectSoundDevice_RemoveBuffer(
-    DirectSoundDevice * device,
-    IDirectSoundBufferImpl * pDSB);
-HRESULT DirectSoundDevice_GetCaps(DirectSoundDevice * device, LPDSCAPS lpDSCaps);
-HRESULT DirectSoundDevice_CreateSoundBuffer(
-    DirectSoundDevice * device,
-    LPCDSBUFFERDESC dsbd,
-    LPLPDIRECTSOUNDBUFFER ppdsb,
-    LPUNKNOWN lpunk,
-    BOOL from8);
-HRESULT DirectSoundDevice_DuplicateSoundBuffer(
-    DirectSoundDevice * device,
-    LPDIRECTSOUNDBUFFER psb,
-    LPLPDIRECTSOUNDBUFFER ppdsb);
-HRESULT DirectSoundDevice_SetCooperativeLevel(
-    DirectSoundDevice * devcie,
-    HWND hwnd,
-    DWORD level);
-HRESULT DirectSoundDevice_Compact(DirectSoundDevice * device);
-HRESULT DirectSoundDevice_GetSpeakerConfig(
-    DirectSoundDevice * device,
-    LPDWORD lpdwSpeakerConfig);
-HRESULT DirectSoundDevice_SetSpeakerConfig(
-    DirectSoundDevice * device,
-    DWORD config);
-
-/*****************************************************************************
- * IDirectSoundBuffer implementation structure
- */
-struct IDirectSoundBufferImpl
-{
-    /* FIXME: document */
-    /* IUnknown fields */
-    const IDirectSoundBuffer8Vtbl *lpVtbl;
-    LONG                        ref;
-    /* IDirectSoundBufferImpl fields */
-    SecondaryBufferImpl*        secondary;
-    DirectSoundDevice*          device;
-    RTL_RWLOCK                  lock;
-    PIDSDRIVERBUFFER            hwbuf;
-    PWAVEFORMATEX               pwfx;
-    BufferMemory*               buffer;
-    LPBYTE                      tmp_buffer;
-    DWORD                       playflags,state,leadin;
-    DWORD                       writelead,buflen;
-    DWORD                       nAvgBytesPerSec;
-    DWORD                       freq, tmp_buffer_len, max_buffer_len;
-    DSVOLUMEPAN                 volpan;
-    DSBUFFERDESC                dsbd;
-    /* used for frequency conversion (PerfectPitch) */
-    ULONG                       freqneeded, freqAdjust, freqAcc, freqAccNext, resampleinmixer;
-    /* used for mixing */
-    DWORD                       primary_mixpos, buf_mixpos, sec_mixpos;
-
-    /* IDirectSoundNotifyImpl fields */
-    IDirectSoundNotifyImpl*     notify;
-    LPDSBPOSITIONNOTIFY         notifies;
-    int                         nrofnotifies;
-    PIDSDRIVERNOTIFY            hwnotify;
-
-    /* DirectSound3DBuffer fields */
-    IDirectSound3DBufferImpl*   ds3db;
-    DS3DBUFFER                  ds3db_ds3db;
-    LONG                        ds3db_lVolume;
-    BOOL                        ds3db_need_recalc;
-
-    /* IKsPropertySet fields */
-    IKsBufferPropertySetImpl*   iks;
-    bitsconvertfunc convert;
-    struct list entry;
-};
-
-HRESULT IDirectSoundBufferImpl_Create(
-    DirectSoundDevice *device,
-    IDirectSoundBufferImpl **ppdsb,
-    LPCDSBUFFERDESC dsbd);
-HRESULT IDirectSoundBufferImpl_Destroy(
-    IDirectSoundBufferImpl *pdsb);
-HRESULT IDirectSoundBufferImpl_Duplicate(
-    DirectSoundDevice *device,
-    IDirectSoundBufferImpl **ppdsb,
-    IDirectSoundBufferImpl *pdsb);
-
-/*****************************************************************************
- * SecondaryBuffer implementation structure
- */
-struct SecondaryBufferImpl
-{
-    const IDirectSoundBuffer8Vtbl *lpVtbl;
-    LONG                        ref;
-    IDirectSoundBufferImpl*     dsb;
-};
-
-HRESULT SecondaryBufferImpl_Create(
-    IDirectSoundBufferImpl *dsb,
-    SecondaryBufferImpl **pdsb);
-
-/*****************************************************************************
- * PrimaryBuffer implementation structure
- */
-struct PrimaryBufferImpl
-{
-    const IDirectSoundBufferVtbl *lpVtbl;
-    LONG                        ref;
-    DirectSoundDevice*          device;
-};
-
-HRESULT PrimaryBufferImpl_Create(
-    DirectSoundDevice * device,
-    PrimaryBufferImpl **ppdsb,
-    LPCDSBUFFERDESC dsbd);
-
-/*****************************************************************************
- * DirectSoundCaptureDevice implementation structure
- */
-struct DirectSoundCaptureDevice
-{
-    /* IDirectSoundCaptureImpl fields */
-    GUID                               guid;
-    LONG                               ref;
-
-    /* DirectSound driver stuff */
-    PIDSCDRIVER                        driver;
-    DSDRIVERDESC                       drvdesc;
-    DSCDRIVERCAPS                      drvcaps;
-    PIDSCDRIVERBUFFER                  hwbuf;
-
-    /* wave driver info */
-    HWAVEIN                            hwi;
-
-    /* more stuff */
-    LPBYTE                             buffer;
-    DWORD                              buflen;
-
-    PWAVEFORMATEX                      pwfx;
-
-    IDirectSoundCaptureBufferImpl*     capture_buffer;
-    DWORD                              state;
-    LPWAVEHDR                          pwave;
-    int                                nrofpwaves;
-    int                                index;
-    CRITICAL_SECTION                   lock;
-};
-
-HRESULT DirectSoundCaptureDevice_Initialize(
-    DirectSoundCaptureDevice ** ppDevice,
-    LPCGUID lpcGUID);
-ULONG DirectSoundCaptureDevice_Release(
-    DirectSoundCaptureDevice * device);
-
-/*****************************************************************************
- * IDirectSoundCaptureBuffer implementation structure
- */
-struct IDirectSoundCaptureBufferImpl
-{
-    /* IUnknown fields */
-    const IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
-    LONG                                ref;
-
-    /* IDirectSoundCaptureBufferImpl fields */
-    DirectSoundCaptureDevice*           device;
-    /* FIXME: don't need this */
-    LPDSCBUFFERDESC                     pdscbd;
-    DWORD                               flags;
-
-    /* IDirectSoundCaptureNotifyImpl fields */
-    IDirectSoundCaptureNotifyImpl*      notify;
-    LPDSBPOSITIONNOTIFY                 notifies;
-    int                                 nrofnotifies;
-    PIDSDRIVERNOTIFY                    hwnotify;
-};
-
-HRESULT IDirectSoundCaptureBufferImpl_Create(
-    DirectSoundCaptureDevice *device,
-    IDirectSoundCaptureBufferImpl ** ppobj,
-    LPCDSCBUFFERDESC lpcDSCBufferDesc);
-
-/*****************************************************************************
- * IDirectSoundFullDuplex implementation structure
- */
-struct IDirectSoundFullDuplexImpl
-{
-    /* IUnknown fields */
-    const IDirectSoundFullDuplexVtbl *lpVtbl;
-    LONG                              ref;
-
-    /* IDirectSoundFullDuplexImpl fields */
-    DirectSoundDevice                *renderer_device;
-    DirectSoundCaptureDevice         *capture_device;
-
-    LPUNKNOWN                         pUnknown;
-    LPDIRECTSOUND                     pDS;
-    LPDIRECTSOUND8                    pDS8;
-    LPDIRECTSOUNDCAPTURE              pDSC;
-};
-
-/*****************************************************************************
- * IDirectSoundFullDuplex COM components
- */
-struct IDirectSoundFullDuplex_IUnknown {
-    const IUnknownVtbl         *lpVtbl;
-    LONG                        ref;
-    IDirectSoundFullDuplexImpl *pdsfd;
-};
-
-struct IDirectSoundFullDuplex_IDirectSound {
-    const IDirectSoundVtbl     *lpVtbl;
-    LONG                        ref;
-    IDirectSoundFullDuplexImpl *pdsfd;
-};
-
-struct IDirectSoundFullDuplex_IDirectSound8 {
-    const IDirectSound8Vtbl    *lpVtbl;
-    LONG                        ref;
-    IDirectSoundFullDuplexImpl *pdsfd;
-};
-
-struct IDirectSoundFullDuplex_IDirectSoundCapture {
-    const IDirectSoundCaptureVtbl *lpVtbl;
-    LONG                           ref;
-    IDirectSoundFullDuplexImpl    *pdsfd;
-};
-
-/*****************************************************************************
- *  IDirectSound3DListener implementation structure
- */
-struct IDirectSound3DListenerImpl
-{
-    /* IUnknown fields */
-    const IDirectSound3DListenerVtbl *lpVtbl;
-    LONG                        ref;
-    /* IDirectSound3DListenerImpl fields */
-    DirectSoundDevice*          device;
-};
-
-HRESULT IDirectSound3DListenerImpl_Create(
-    DirectSoundDevice           *device,
-    IDirectSound3DListenerImpl **pdsl);
-
-/*****************************************************************************
- *  IKsBufferPropertySet implementation structure
- */
-struct IKsBufferPropertySetImpl
-{
-    /* IUnknown fields */
-    const IKsPropertySetVtbl   *lpVtbl;
-    LONG                       ref;
-    /* IKsPropertySetImpl fields */
-    IDirectSoundBufferImpl*    dsb;
-};
-
-HRESULT IKsBufferPropertySetImpl_Create(
-    IDirectSoundBufferImpl *dsb,
-    IKsBufferPropertySetImpl **piks);
-HRESULT IKsBufferPropertySetImpl_Destroy(
-    IKsBufferPropertySetImpl *piks);
-
-/*****************************************************************************
- *  IKsPrivatePropertySet implementation structure
- */
-struct IKsPrivatePropertySetImpl
-{
-    /* IUnknown fields */
-    const IKsPropertySetVtbl   *lpVtbl;
-    LONG                       ref;
-};
-
-HRESULT IKsPrivatePropertySetImpl_Create(
-    REFIID riid,
-    IKsPrivatePropertySetImpl **piks);
-
-/*****************************************************************************
- * IDirectSound3DBuffer implementation structure
- */
-struct IDirectSound3DBufferImpl
-{
-    /* IUnknown fields */
-    const IDirectSound3DBufferVtbl *lpVtbl;
-    LONG                        ref;
-    /* IDirectSound3DBufferImpl fields */
-    IDirectSoundBufferImpl*     dsb;
-};
-
-HRESULT IDirectSound3DBufferImpl_Create(
-    IDirectSoundBufferImpl *dsb,
-    IDirectSound3DBufferImpl **pds3db);
-HRESULT IDirectSound3DBufferImpl_Destroy(
-    IDirectSound3DBufferImpl *pds3db);
-
-/*******************************************************************************
- */
-
-/* dsound.c */
-
-HRESULT DSOUND_Create(REFIID riid, LPDIRECTSOUND *ppDS);
-HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS);
-
-/* primary.c */
-
-DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign);
-HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device);
-HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device);
-HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device);
-HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device);
-HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos);
-HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex, BOOL forced);
-HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave);
-
-/* duplex.c */
-HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD);
-
-/* mixer.c */
-DWORD DSOUND_bufpos_to_mixpos(const DirectSoundDevice* device, DWORD pos);
-void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len);
-void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
-void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan);
-void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
-void DSOUND_MixToTemporary(const IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen, BOOL inmixer);
-DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, DWORD* overshot);
-
-void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
-void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
-
-/* sound3d.c */
-
-void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
-
-/* capture.c */
-HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC);
-HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8);
-HRESULT WINAPI IDirectSoundCaptureImpl_CreateCaptureBuffer(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPCDSCBUFFERDESC lpcDSCBufferDesc,
-    LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
-    LPUNKNOWN pUnk);
-HRESULT WINAPI IDirectSoundCaptureImpl_GetCaps(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPDSCCAPS lpDSCCaps);
-HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPCGUID lpcGUID);
-
-#define STATE_STOPPED   0
-#define STATE_STARTING  1
-#define STATE_PLAYING   2
-#define STATE_CAPTURING 2
-#define STATE_STOPPING  3
-
-#define DSOUND_FREQSHIFT (20)
-
-extern DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
-extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
-
-extern DirectSoundCaptureDevice * DSOUND_capture[MAXWAVEDRIVERS];
-extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
-
-HRESULT mmErr(UINT err);
-void setup_dsound_options(void);
-const char * dumpCooperativeLevel(DWORD level);
diff --git a/dll/directx/dsound/duplex.c b/dll/directx/dsound/duplex.c
deleted file mode 100644 (file)
index 1fe6bbc..0000000
+++ /dev/null
@@ -1,910 +0,0 @@
-/*              DirectSoundFullDuplex
- *
- * Copyright 1998 Marcus Meissner
- * Copyright 1998 Rob Riggs
- * Copyright 2000-2001 TransGaming Technologies, Inc.
- * Copyright 2005 Robert Reif
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#include <stdarg.h>
-
-#define NONAMELESSSTRUCT
-#define NONAMELESSUNION
-#include "windef.h"
-#include "winbase.h"
-#include "winuser.h"
-#include "mmsystem.h"
-#include "mmddk.h"
-#include "winternl.h"
-#include "wine/debug.h"
-#include "dsound.h"
-#include "dsdriver.h"
-#include "dsound_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(dsound);
-
-/*******************************************************************************
- * IUnknown
- */
-static HRESULT WINAPI IDirectSoundFullDuplex_IUnknown_QueryInterface(
-    LPUNKNOWN iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSoundFullDuplex_IUnknown *This = (IDirectSoundFullDuplex_IUnknown *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This->pdsfd, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSoundFullDuplex_IUnknown_AddRef(
-    LPUNKNOWN iface)
-{
-    IDirectSoundFullDuplex_IUnknown *This = (IDirectSoundFullDuplex_IUnknown *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSoundFullDuplex_IUnknown_Release(
-    LPUNKNOWN iface)
-{
-    IDirectSoundFullDuplex_IUnknown *This = (IDirectSoundFullDuplex_IUnknown *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        IDirectSound_Release(This->pdsfd->pUnknown);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static const IUnknownVtbl DirectSoundFullDuplex_Unknown_Vtbl =
-{
-    IDirectSoundFullDuplex_IUnknown_QueryInterface,
-    IDirectSoundFullDuplex_IUnknown_AddRef,
-    IDirectSoundFullDuplex_IUnknown_Release
-};
-
-static HRESULT IDirectSoundFullDuplex_IUnknown_Create(
-    LPDIRECTSOUNDFULLDUPLEX pdsfd,
-    LPUNKNOWN * ppunk)
-{
-    IDirectSoundFullDuplex_IUnknown * pdsfdunk;
-    TRACE("(%p,%p)\n",pdsfd,ppunk);
-
-    if (pdsfd == NULL) {
-        ERR("invalid parameter: pdsfd == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppunk == NULL) {
-        ERR("invalid parameter: ppunk == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    pdsfdunk = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsfdunk));
-    if (pdsfdunk == NULL) {
-        WARN("out of memory\n");
-        *ppunk = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsfdunk->lpVtbl = &DirectSoundFullDuplex_Unknown_Vtbl;
-    pdsfdunk->ref = 0;
-    pdsfdunk->pdsfd = (IDirectSoundFullDuplexImpl *)pdsfd;
-
-    *ppunk = (LPUNKNOWN)pdsfdunk;
-
-    return DS_OK;
-}
-
-/*******************************************************************************
- * IDirectSoundFullDuplex_IDirectSound
- */
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_QueryInterface(
-    LPDIRECTSOUND iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This->pdsfd, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSoundFullDuplex_IDirectSound_AddRef(
-    LPDIRECTSOUND iface)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSoundFullDuplex_IDirectSound_Release(
-    LPDIRECTSOUND iface)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        IDirectSound_Release(This->pdsfd->pDS);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_CreateSoundBuffer(
-    LPDIRECTSOUND iface,
-    LPCDSBUFFERDESC dsbd,
-    LPLPDIRECTSOUNDBUFFER ppdsb,
-    LPUNKNOWN lpunk)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
-    return DirectSoundDevice_CreateSoundBuffer(This->pdsfd->renderer_device,dsbd,ppdsb,lpunk,FALSE);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_GetCaps(
-    LPDIRECTSOUND iface,
-    LPDSCAPS lpDSCaps)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    TRACE("(%p,%p)\n",This,lpDSCaps);
-    return DirectSoundDevice_GetCaps(This->pdsfd->renderer_device, lpDSCaps);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_DuplicateSoundBuffer(
-    LPDIRECTSOUND iface,
-    LPDIRECTSOUNDBUFFER psb,
-    LPLPDIRECTSOUNDBUFFER ppdsb)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
-    return DirectSoundDevice_DuplicateSoundBuffer(This->pdsfd->renderer_device,psb,ppdsb);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_SetCooperativeLevel(
-    LPDIRECTSOUND iface,
-    HWND hwnd,
-    DWORD level)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    TRACE("(%p,%p,%s)\n",This,hwnd,dumpCooperativeLevel(level));
-    return DirectSoundDevice_SetCooperativeLevel(This->pdsfd->renderer_device,hwnd,level);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_Compact(
-    LPDIRECTSOUND iface)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    TRACE("(%p)\n", This);
-    return DirectSoundDevice_Compact(This->pdsfd->renderer_device);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_GetSpeakerConfig(
-    LPDIRECTSOUND iface,
-    LPDWORD lpdwSpeakerConfig)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    TRACE("(%p, %p)\n", This, lpdwSpeakerConfig);
-    return DirectSoundDevice_GetSpeakerConfig(This->pdsfd->renderer_device,lpdwSpeakerConfig);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_SetSpeakerConfig(
-    LPDIRECTSOUND iface,
-    DWORD config)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    TRACE("(%p,0x%08x)\n",This,config);
-    return DirectSoundDevice_SetSpeakerConfig(This->pdsfd->renderer_device,config);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_Initialize(
-    LPDIRECTSOUND iface,
-    LPCGUID lpcGuid)
-{
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
-    return DirectSoundDevice_Initialize(&This->pdsfd->renderer_device,lpcGuid);
-}
-
-static const IDirectSoundVtbl DirectSoundFullDuplex_DirectSound_Vtbl =
-{
-    IDirectSoundFullDuplex_IDirectSound_QueryInterface,
-    IDirectSoundFullDuplex_IDirectSound_AddRef,
-    IDirectSoundFullDuplex_IDirectSound_Release,
-    IDirectSoundFullDuplex_IDirectSound_CreateSoundBuffer,
-    IDirectSoundFullDuplex_IDirectSound_GetCaps,
-    IDirectSoundFullDuplex_IDirectSound_DuplicateSoundBuffer,
-    IDirectSoundFullDuplex_IDirectSound_SetCooperativeLevel,
-    IDirectSoundFullDuplex_IDirectSound_Compact,
-    IDirectSoundFullDuplex_IDirectSound_GetSpeakerConfig,
-    IDirectSoundFullDuplex_IDirectSound_SetSpeakerConfig,
-    IDirectSoundFullDuplex_IDirectSound_Initialize
-};
-
-static HRESULT IDirectSoundFullDuplex_IDirectSound_Create(
-    LPDIRECTSOUNDFULLDUPLEX pdsfd,
-    LPDIRECTSOUND * ppds)
-{
-    IDirectSoundFullDuplex_IDirectSound * pdsfdds;
-    TRACE("(%p,%p)\n",pdsfd,ppds);
-
-    if (pdsfd == NULL) {
-        ERR("invalid parameter: pdsfd == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppds == NULL) {
-        ERR("invalid parameter: ppds == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (((IDirectSoundFullDuplexImpl*)pdsfd)->renderer_device == NULL) {
-        WARN("not initialized\n");
-        *ppds = NULL;
-        return DSERR_UNINITIALIZED;
-    }
-
-    pdsfdds = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsfdds));
-    if (pdsfdds == NULL) {
-        WARN("out of memory\n");
-        *ppds = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsfdds->lpVtbl = &DirectSoundFullDuplex_DirectSound_Vtbl;
-    pdsfdds->ref = 0;
-    pdsfdds->pdsfd = (IDirectSoundFullDuplexImpl *)pdsfd;
-
-    *ppds = (LPDIRECTSOUND)pdsfdds;
-
-    return DS_OK;
-}
-
-/*******************************************************************************
- * IDirectSoundFullDuplex_IDirectSound8
- */
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_QueryInterface(
-    LPDIRECTSOUND8 iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This->pdsfd, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSoundFullDuplex_IDirectSound8_AddRef(
-    LPDIRECTSOUND8 iface)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSoundFullDuplex_IDirectSound8_Release(
-    LPDIRECTSOUND8 iface)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        IDirectSound_Release(This->pdsfd->pDS8);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_CreateSoundBuffer(
-    LPDIRECTSOUND8 iface,
-    LPCDSBUFFERDESC dsbd,
-    LPLPDIRECTSOUNDBUFFER ppdsb,
-    LPUNKNOWN lpunk)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
-    return DirectSoundDevice_CreateSoundBuffer(This->pdsfd->renderer_device,dsbd,ppdsb,lpunk,TRUE);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_GetCaps(
-    LPDIRECTSOUND8 iface,
-    LPDSCAPS lpDSCaps)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    TRACE("(%p,%p)\n",This,lpDSCaps);
-    return DirectSoundDevice_GetCaps(This->pdsfd->renderer_device, lpDSCaps);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_DuplicateSoundBuffer(
-    LPDIRECTSOUND8 iface,
-    LPDIRECTSOUNDBUFFER psb,
-    LPLPDIRECTSOUNDBUFFER ppdsb)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
-    return DirectSoundDevice_DuplicateSoundBuffer(This->pdsfd->renderer_device,psb,ppdsb);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_SetCooperativeLevel(
-    LPDIRECTSOUND8 iface,
-    HWND hwnd,
-    DWORD level)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    TRACE("(%p,%p,%s)\n",This,hwnd,dumpCooperativeLevel(level));
-    return DirectSoundDevice_SetCooperativeLevel(This->pdsfd->renderer_device,hwnd,level);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_Compact(
-    LPDIRECTSOUND8 iface)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    TRACE("(%p)\n", This);
-    return DirectSoundDevice_Compact(This->pdsfd->renderer_device);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_GetSpeakerConfig(
-    LPDIRECTSOUND8 iface,
-    LPDWORD lpdwSpeakerConfig)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    TRACE("(%p, %p)\n", This, lpdwSpeakerConfig);
-    return DirectSoundDevice_GetSpeakerConfig(This->pdsfd->renderer_device,lpdwSpeakerConfig);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_SetSpeakerConfig(
-    LPDIRECTSOUND8 iface,
-    DWORD config)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    TRACE("(%p,0x%08x)\n",This,config);
-    return DirectSoundDevice_SetSpeakerConfig(This->pdsfd->renderer_device,config);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_Initialize(
-    LPDIRECTSOUND8 iface,
-    LPCGUID lpcGuid)
-{
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
-    return DirectSoundDevice_Initialize(&This->pdsfd->renderer_device,lpcGuid);
-}
-
-static const IDirectSound8Vtbl DirectSoundFullDuplex_DirectSound8_Vtbl =
-{
-    IDirectSoundFullDuplex_IDirectSound8_QueryInterface,
-    IDirectSoundFullDuplex_IDirectSound8_AddRef,
-    IDirectSoundFullDuplex_IDirectSound8_Release,
-    IDirectSoundFullDuplex_IDirectSound8_CreateSoundBuffer,
-    IDirectSoundFullDuplex_IDirectSound8_GetCaps,
-    IDirectSoundFullDuplex_IDirectSound8_DuplicateSoundBuffer,
-    IDirectSoundFullDuplex_IDirectSound8_SetCooperativeLevel,
-    IDirectSoundFullDuplex_IDirectSound8_Compact,
-    IDirectSoundFullDuplex_IDirectSound8_GetSpeakerConfig,
-    IDirectSoundFullDuplex_IDirectSound8_SetSpeakerConfig,
-    IDirectSoundFullDuplex_IDirectSound8_Initialize
-};
-
-static HRESULT IDirectSoundFullDuplex_IDirectSound8_Create(
-    LPDIRECTSOUNDFULLDUPLEX pdsfd,
-    LPDIRECTSOUND8 * ppds8)
-{
-    IDirectSoundFullDuplex_IDirectSound8 * pdsfdds8;
-    TRACE("(%p,%p)\n",pdsfd,ppds8);
-
-    if (pdsfd == NULL) {
-        ERR("invalid parameter: pdsfd == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppds8 == NULL) {
-        ERR("invalid parameter: ppds8 == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (((IDirectSoundFullDuplexImpl*)pdsfd)->renderer_device == NULL) {
-        WARN("not initialized\n");
-        *ppds8 = NULL;
-        return DSERR_UNINITIALIZED;
-    }
-
-    pdsfdds8 = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsfdds8));
-    if (pdsfdds8 == NULL) {
-        WARN("out of memory\n");
-        *ppds8 = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsfdds8->lpVtbl = &DirectSoundFullDuplex_DirectSound8_Vtbl;
-    pdsfdds8->ref = 0;
-    pdsfdds8->pdsfd = (IDirectSoundFullDuplexImpl *)pdsfd;
-
-    *ppds8 = (LPDIRECTSOUND8)pdsfdds8;
-
-    return DS_OK;
-}
-
-/*******************************************************************************
- * IDirectSoundFullDuplex_IDirectSoundCapture
- */
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_QueryInterface(
-    LPDIRECTSOUNDCAPTURE iface,
-    REFIID riid,
-    LPVOID * ppobj)
-{
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
-    TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This->pdsfd, riid, ppobj);
-}
-
-static ULONG WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_AddRef(
-    LPDIRECTSOUNDCAPTURE iface)
-{
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_Release(
-    LPDIRECTSOUNDCAPTURE iface)
-{
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        IDirectSoundCapture_Release(This->pdsfd->pDSC);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_CreateCaptureBuffer(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPCDSCBUFFERDESC lpcDSCBufferDesc,
-    LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
-    LPUNKNOWN pUnk)
-{
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
-    TRACE("(%p,%p,%p,%p)\n",This,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk);
-    return IDirectSoundCaptureImpl_CreateCaptureBuffer(This->pdsfd->pDSC,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_GetCaps(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPDSCCAPS lpDSCCaps)
-{
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
-    TRACE("(%p,%p)\n",This,lpDSCCaps);
-    return IDirectSoundCaptureImpl_GetCaps(This->pdsfd->pDSC, lpDSCCaps);
-}
-
-static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_Initialize(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPCGUID lpcGUID)
-{
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
-    TRACE("(%p, %s)\n", This, debugstr_guid(lpcGUID));
-    return IDirectSoundCaptureImpl_Initialize(This->pdsfd->pDSC,lpcGUID);
-}
-
-static const IDirectSoundCaptureVtbl DirectSoundFullDuplex_DirectSoundCapture_Vtbl =
-{
-    IDirectSoundFullDuplex_IDirectSoundCapture_QueryInterface,
-    IDirectSoundFullDuplex_IDirectSoundCapture_AddRef,
-    IDirectSoundFullDuplex_IDirectSoundCapture_Release,
-    IDirectSoundFullDuplex_IDirectSoundCapture_CreateCaptureBuffer,
-    IDirectSoundFullDuplex_IDirectSoundCapture_GetCaps,
-    IDirectSoundFullDuplex_IDirectSoundCapture_Initialize
-};
-
-static HRESULT IDirectSoundFullDuplex_IDirectSoundCapture_Create(
-    LPDIRECTSOUNDFULLDUPLEX pdsfd,
-    LPDIRECTSOUNDCAPTURE8 * ppdsc8)
-{
-    IDirectSoundFullDuplex_IDirectSoundCapture * pdsfddsc;
-    TRACE("(%p,%p)\n",pdsfd,ppdsc8);
-
-    if (pdsfd == NULL) {
-        ERR("invalid parameter: pdsfd == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppdsc8 == NULL) {
-        ERR("invalid parameter: ppdsc8 == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (((IDirectSoundFullDuplexImpl*)pdsfd)->capture_device == NULL) {
-        WARN("not initialized\n");
-        *ppdsc8 = NULL;
-        return DSERR_UNINITIALIZED;
-    }
-
-    pdsfddsc = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsfddsc));
-    if (pdsfddsc == NULL) {
-        WARN("out of memory\n");
-        *ppdsc8 = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsfddsc->lpVtbl = &DirectSoundFullDuplex_DirectSoundCapture_Vtbl;
-    pdsfddsc->ref = 0;
-    pdsfddsc->pdsfd = (IDirectSoundFullDuplexImpl *)pdsfd;
-
-    *ppdsc8 = (LPDIRECTSOUNDCAPTURE)pdsfddsc;
-
-    return DS_OK;
-}
-
-/***************************************************************************
- * IDirectSoundFullDuplexImpl
- */
-static ULONG WINAPI
-IDirectSoundFullDuplexImpl_AddRef( LPDIRECTSOUNDFULLDUPLEX iface )
-{
-    IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static HRESULT WINAPI
-IDirectSoundFullDuplexImpl_QueryInterface(
-    LPDIRECTSOUNDFULLDUPLEX iface,
-    REFIID riid,
-    LPVOID* ppobj )
-{
-    IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface;
-    TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
-
-    if (ppobj == NULL) {
-       WARN("invalid parameter\n");
-       return E_INVALIDARG;
-    }
-
-    *ppobj = NULL;
-
-    if (IsEqualIID(riid, &IID_IUnknown)) {
-        if (!This->pUnknown) {
-            IDirectSoundFullDuplex_IUnknown_Create(iface, &This->pUnknown);
-            if (!This->pUnknown) {
-                WARN("IDirectSoundFullDuplex_IUnknown_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSoundFullDuplex_IUnknown_AddRef(This->pUnknown);
-        *ppobj = This->pUnknown;
-        return S_OK;
-    } else if (IsEqualIID(riid, &IID_IDirectSoundFullDuplex)) {
-        IDirectSoundFullDuplexImpl_AddRef(iface);
-        *ppobj = This;
-        return S_OK;
-    } else if (IsEqualIID(riid, &IID_IDirectSound)) {
-        if (!This->pDS) {
-            IDirectSoundFullDuplex_IDirectSound_Create(iface, &This->pDS);
-            if (!This->pDS) {
-                WARN("IDirectSoundFullDuplex_IDirectSound_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSoundFullDuplex_IDirectSound_AddRef(This->pDS);
-        *ppobj = This->pDS;
-        return S_OK;
-    } else if (IsEqualIID(riid, &IID_IDirectSound8)) {
-        if (!This->pDS8) {
-            IDirectSoundFullDuplex_IDirectSound8_Create(iface, &This->pDS8);
-            if (!This->pDS8) {
-                WARN("IDirectSoundFullDuplex_IDirectSound8_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSoundFullDuplex_IDirectSound8_AddRef(This->pDS8);
-        *ppobj = This->pDS8;
-        return S_OK;
-    } else if (IsEqualIID(riid, &IID_IDirectSoundCapture)) {
-        if (!This->pDSC) {
-            IDirectSoundFullDuplex_IDirectSoundCapture_Create(iface, &This->pDSC);
-            if (!This->pDSC) {
-                WARN("IDirectSoundFullDuplex_IDirectSoundCapture_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSoundFullDuplex_IDirectSoundCapture_AddRef(This->pDSC);
-        *ppobj = This->pDSC;
-        return S_OK;
-    }
-
-    return E_NOINTERFACE;
-}
-
-static ULONG WINAPI
-IDirectSoundFullDuplexImpl_Release( LPDIRECTSOUNDFULLDUPLEX iface )
-{
-    IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-
-    if (!ref) {
-        if (This->capture_device)
-            DirectSoundCaptureDevice_Release(This->capture_device);
-        if (This->renderer_device)
-            DirectSoundDevice_Release(This->renderer_device);
-        HeapFree( GetProcessHeap(), 0, This );
-       TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI
-IDirectSoundFullDuplexImpl_Initialize(
-    LPDIRECTSOUNDFULLDUPLEX iface,
-    LPCGUID pCaptureGuid,
-    LPCGUID pRendererGuid,
-    LPCDSCBUFFERDESC lpDscBufferDesc,
-    LPCDSBUFFERDESC lpDsBufferDesc,
-    HWND hWnd,
-    DWORD dwLevel,
-    LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8,
-    LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8 )
-{
-    HRESULT hr;
-    IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface;
-    IDirectSoundBufferImpl * dsb;
-
-    TRACE("(%p,%s,%s,%p,%p,%p,%x,%p,%p)\n", This,
-        debugstr_guid(pCaptureGuid), debugstr_guid(pRendererGuid),
-        lpDscBufferDesc, lpDsBufferDesc, hWnd, dwLevel,
-        lplpDirectSoundCaptureBuffer8, lplpDirectSoundBuffer8);
-
-    if (This->renderer_device != NULL || This->capture_device != NULL) {
-        WARN("already initialized\n");
-        *lplpDirectSoundCaptureBuffer8 = NULL;
-        *lplpDirectSoundBuffer8 = NULL;
-        return DSERR_ALREADYINITIALIZED;
-    }
-
-    hr = DirectSoundDevice_Initialize(&This->renderer_device, pRendererGuid);
-    if (hr != DS_OK) {
-        WARN("DirectSoundDevice_Initialize() failed\n");
-        *lplpDirectSoundCaptureBuffer8 = NULL;
-        *lplpDirectSoundBuffer8 = NULL;
-        return hr;
-    }
-
-    if (dwLevel==DSSCL_PRIORITY || dwLevel==DSSCL_EXCLUSIVE) {
-        WARN("level=%s not fully supported\n",
-             dwLevel==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE");
-    }
-    This->renderer_device->priolevel = dwLevel;
-
-    hr = DSOUND_PrimarySetFormat(This->renderer_device, lpDsBufferDesc->lpwfxFormat, dwLevel == DSSCL_EXCLUSIVE);
-    if (hr != DS_OK) {
-        WARN("DSOUND_PrimarySetFormat() failed\n");
-        *lplpDirectSoundCaptureBuffer8 = NULL;
-        *lplpDirectSoundBuffer8 = NULL;
-        return hr;
-    }
-    hr = IDirectSoundBufferImpl_Create(This->renderer_device, &dsb, lpDsBufferDesc);
-    if (hr != DS_OK) {
-        WARN("IDirectSoundBufferImpl_Create() failed\n");
-        *lplpDirectSoundCaptureBuffer8 = NULL;
-        *lplpDirectSoundBuffer8 = NULL;
-        return hr;
-    }
-
-    hr = SecondaryBufferImpl_Create(dsb, (SecondaryBufferImpl **)lplpDirectSoundBuffer8);
-    if (hr != DS_OK) {
-        WARN("SecondaryBufferImpl_Create() failed\n");
-        *lplpDirectSoundCaptureBuffer8 = NULL;
-        *lplpDirectSoundBuffer8 = NULL;
-        return hr;
-    }
-    IDirectSoundBuffer8_AddRef(*lplpDirectSoundBuffer8);
-
-    hr = DirectSoundCaptureDevice_Initialize(&This->capture_device, pCaptureGuid);
-    if (hr != DS_OK) {
-        WARN("DirectSoundCaptureDevice_Initialize() failed\n");
-        *lplpDirectSoundCaptureBuffer8 = NULL;
-        *lplpDirectSoundBuffer8 = NULL;
-        return hr;
-    }
-
-    hr = IDirectSoundCaptureBufferImpl_Create(This->capture_device,
-         (IDirectSoundCaptureBufferImpl **)lplpDirectSoundCaptureBuffer8,
-         lpDscBufferDesc);
-    if (hr != DS_OK) {
-        WARN("IDirectSoundCaptureBufferImpl_Create() failed\n");
-        *lplpDirectSoundCaptureBuffer8 = NULL;
-        *lplpDirectSoundBuffer8 = NULL;
-        return hr;
-    }
-
-    return hr;
-}
-
-static const IDirectSoundFullDuplexVtbl dsfdvt =
-{
-    /* IUnknown methods */
-    IDirectSoundFullDuplexImpl_QueryInterface,
-    IDirectSoundFullDuplexImpl_AddRef,
-    IDirectSoundFullDuplexImpl_Release,
-
-    /* IDirectSoundFullDuplex methods */
-    IDirectSoundFullDuplexImpl_Initialize
-};
-
-HRESULT DSOUND_FullDuplexCreate(
-    REFIID riid,
-    LPDIRECTSOUNDFULLDUPLEX* ppDSFD)
-{
-    IDirectSoundFullDuplexImpl *This = NULL;
-    TRACE("(%s, %p)\n", debugstr_guid(riid), ppDSFD);
-
-    if (ppDSFD == NULL) {
-        WARN("invalid parameter: ppDSFD == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (!IsEqualIID(riid, &IID_IUnknown) &&
-        !IsEqualIID(riid, &IID_IDirectSoundFullDuplex)) {
-        *ppDSFD = 0;
-        return E_NOINTERFACE;
-    }
-
-    /* Get dsound configuration */
-    setup_dsound_options();
-
-    This = HeapAlloc(GetProcessHeap(),
-        HEAP_ZERO_MEMORY, sizeof(IDirectSoundFullDuplexImpl));
-
-    if (This == NULL) {
-        WARN("out of memory\n");
-        *ppDSFD = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    This->lpVtbl = &dsfdvt;
-    This->ref = 1;
-    This->capture_device = NULL;
-    This->renderer_device = NULL;
-
-    *ppDSFD = (LPDIRECTSOUNDFULLDUPLEX)This;
-
-    return DS_OK;
-}
-
-/***************************************************************************
- * DirectSoundFullDuplexCreate [DSOUND.10]
- *
- * Create and initialize a DirectSoundFullDuplex interface.
- *
- * PARAMS
- *    pcGuidCaptureDevice [I] Address of sound capture device GUID.
- *    pcGuidRenderDevice  [I] Address of sound render device GUID.
- *    pcDSCBufferDesc     [I] Address of capture buffer description.
- *    pcDSBufferDesc      [I] Address of  render buffer description.
- *    hWnd                [I] Handle to application window.
- *    dwLevel             [I] Cooperative level.
- *    ppDSFD              [O] Address where full duplex interface returned.
- *    ppDSCBuffer8        [0] Address where capture buffer interface returned.
- *    ppDSBuffer8         [0] Address where render buffer interface returned.
- *    pUnkOuter           [I] Must be NULL.
- *
- * RETURNS
- *    Success: DS_OK
- *    Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
- *             DSERR_OUTOFMEMORY DSERR_INVALIDCALL DSERR_NODRIVER
- */
-HRESULT WINAPI
-DirectSoundFullDuplexCreate(
-    LPCGUID pcGuidCaptureDevice,
-    LPCGUID pcGuidRenderDevice,
-    LPCDSCBUFFERDESC pcDSCBufferDesc,
-    LPCDSBUFFERDESC pcDSBufferDesc,
-    HWND hWnd,
-    DWORD dwLevel,
-    LPDIRECTSOUNDFULLDUPLEX *ppDSFD,
-    LPDIRECTSOUNDCAPTUREBUFFER8 *ppDSCBuffer8,
-    LPDIRECTSOUNDBUFFER8 *ppDSBuffer8,
-    LPUNKNOWN pUnkOuter)
-{
-    HRESULT hres;
-    IDirectSoundFullDuplexImpl *This = NULL;
-    TRACE("(%s,%s,%p,%p,%p,%x,%p,%p,%p,%p)\n",
-        debugstr_guid(pcGuidCaptureDevice), debugstr_guid(pcGuidRenderDevice),
-        pcDSCBufferDesc, pcDSBufferDesc, hWnd, dwLevel, ppDSFD, ppDSCBuffer8,
-        ppDSBuffer8, pUnkOuter);
-
-    if (pUnkOuter) {
-        WARN("pUnkOuter != 0\n");
-        *ppDSFD = NULL;
-        return DSERR_NOAGGREGATION;
-    }
-
-    if (pcDSCBufferDesc == NULL) {
-        WARN("invalid parameter: pcDSCBufferDesc == NULL\n");
-        *ppDSFD = NULL;
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (pcDSBufferDesc == NULL) {
-        WARN("invalid parameter: pcDSBufferDesc == NULL\n");
-        *ppDSFD = NULL;
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppDSFD == NULL) {
-        WARN("invalid parameter: ppDSFD == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppDSCBuffer8 == NULL) {
-        WARN("invalid parameter: ppDSCBuffer8 == NULL\n");
-        *ppDSFD = NULL;
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppDSBuffer8 == NULL) {
-        WARN("invalid parameter: ppDSBuffer8 == NULL\n");
-        *ppDSFD = NULL;
-        return DSERR_INVALIDPARAM;
-    }
-
-    /* Get dsound configuration */
-    setup_dsound_options();
-
-    This = HeapAlloc(GetProcessHeap(),
-        HEAP_ZERO_MEMORY, sizeof(IDirectSoundFullDuplexImpl));
-
-    if (This == NULL) {
-        WARN("out of memory\n");
-        *ppDSFD = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    This->lpVtbl = &dsfdvt;
-    This->ref = 1;
-    This->capture_device = NULL;
-    This->renderer_device = NULL;
-
-    hres = IDirectSoundFullDuplexImpl_Initialize((LPDIRECTSOUNDFULLDUPLEX)This,
-                                                 pcGuidCaptureDevice,
-                                                 pcGuidRenderDevice,
-                                                 pcDSCBufferDesc,
-                                                 pcDSBufferDesc,
-                                                 hWnd, dwLevel, ppDSCBuffer8,
-                                                 ppDSBuffer8);
-    if (hres != DS_OK) {
-        HeapFree(GetProcessHeap(), 0, This);
-        WARN("IDirectSoundFullDuplexImpl_Initialize failed\n");
-        *ppDSFD = NULL;
-    } else
-        *ppDSFD = (LPDIRECTSOUNDFULLDUPLEX)This;
-
-    return hres;
-}
diff --git a/dll/directx/dsound/mixer.c b/dll/directx/dsound/mixer.c
deleted file mode 100644 (file)
index d014c4b..0000000
+++ /dev/null
@@ -1,1047 +0,0 @@
-/*                     DirectSound
- *
- * Copyright 1998 Marcus Meissner
- * Copyright 1998 Rob Riggs
- * Copyright 2000-2002 TransGaming Technologies, Inc.
- * Copyright 2007 Peter Dons Tychsen
- * Copyright 2007 Maarten Lankhorst
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#include <assert.h>
-#include <stdarg.h>
-#include <math.h>      /* Insomnia - pow() function */
-
-#define NONAMELESSSTRUCT
-#define NONAMELESSUNION
-#include "windef.h"
-#include "winbase.h"
-#include "mmsystem.h"
-#include "winternl.h"
-#include "wine/debug.h"
-#include "dsound.h"
-#include "dsdriver.h"
-#include "dsound_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(dsound);
-
-void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan)
-{
-       double temp;
-       TRACE("(%p)\n",volpan);
-
-       TRACE("Vol=%d Pan=%d\n", volpan->lVolume, volpan->lPan);
-       /* the AmpFactors are expressed in 16.16 fixed point */
-       volpan->dwVolAmpFactor = (ULONG) (pow(2.0, volpan->lVolume / 600.0) * 0xffff);
-       /* FIXME: dwPan{Left|Right}AmpFactor */
-
-       /* FIXME: use calculated vol and pan ampfactors */
-       temp = (double) (volpan->lVolume - (volpan->lPan > 0 ? volpan->lPan : 0));
-       volpan->dwTotalLeftAmpFactor = (ULONG) (pow(2.0, temp / 600.0) * 0xffff);
-       temp = (double) (volpan->lVolume + (volpan->lPan < 0 ? volpan->lPan : 0));
-       volpan->dwTotalRightAmpFactor = (ULONG) (pow(2.0, temp / 600.0) * 0xffff);
-
-       TRACE("left = %x, right = %x\n", volpan->dwTotalLeftAmpFactor, volpan->dwTotalRightAmpFactor);
-}
-
-void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan)
-{
-    double left,right;
-    TRACE("(%p)\n",volpan);
-
-    TRACE("left=%x, right=%x\n",volpan->dwTotalLeftAmpFactor,volpan->dwTotalRightAmpFactor);
-    if (volpan->dwTotalLeftAmpFactor==0)
-        left=-10000;
-    else
-        left=600 * log(((double)volpan->dwTotalLeftAmpFactor) / 0xffff) / log(2);
-    if (volpan->dwTotalRightAmpFactor==0)
-        right=-10000;
-    else
-        right=600 * log(((double)volpan->dwTotalRightAmpFactor) / 0xffff) / log(2);
-    if (left<right)
-    {
-        volpan->lVolume=right;
-        volpan->dwVolAmpFactor=volpan->dwTotalRightAmpFactor;
-    }
-    else
-    {
-        volpan->lVolume=left;
-        volpan->dwVolAmpFactor=volpan->dwTotalLeftAmpFactor;
-    }
-    if (volpan->lVolume < -10000)
-        volpan->lVolume=-10000;
-    volpan->lPan=right-left;
-    if (volpan->lPan < -10000)
-        volpan->lPan=-10000;
-
-    TRACE("Vol=%d Pan=%d\n", volpan->lVolume, volpan->lPan);
-}
-
-/** Convert a primary buffer position to a pointer position for device->mix_buffer
- * device: DirectSoundDevice for which to calculate
- * pos: Primary buffer position to converts
- * Returns: Offset for mix_buffer
- */
-DWORD DSOUND_bufpos_to_mixpos(const DirectSoundDevice* device, DWORD pos)
-{
-    DWORD ret = pos * 32 / device->pwfx->wBitsPerSample;
-    if (device->pwfx->wBitsPerSample == 32)
-        ret *= 2;
-    return ret;
-}
-
-/* NOTE: Not all secpos have to always be mapped to a bufpos, other way around is always the case
- * DWORD64 is used here because a single DWORD wouldn't be big enough to fit the freqAcc for big buffers
- */
-/** This function converts a 'native' sample pointer to a resampled pointer that fits for primary
- * secmixpos is used to decide which freqAcc is needed
- * overshot tells what the 'actual' secpos is now (optional)
- */
-DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, DWORD* overshot)
-{
-       DWORD64 framelen = secpos / dsb->pwfx->nBlockAlign;
-       DWORD64 freqAdjust = dsb->freqAdjust;
-       DWORD64 acc, freqAcc;
-
-       if (secpos < secmixpos)
-               freqAcc = dsb->freqAccNext;
-       else freqAcc = dsb->freqAcc;
-       acc = (framelen << DSOUND_FREQSHIFT) + (freqAdjust - 1 - freqAcc);
-       acc /= freqAdjust;
-       if (overshot)
-       {
-               DWORD64 oshot = acc * freqAdjust + freqAcc;
-               assert(oshot >= framelen << DSOUND_FREQSHIFT);
-               oshot -= framelen << DSOUND_FREQSHIFT;
-               *overshot = (DWORD)oshot;
-               assert(*overshot < dsb->freqAdjust);
-       }
-       return (DWORD)acc * dsb->device->pwfx->nBlockAlign;
-}
-
-/** Convert a resampled pointer that fits for primary to a 'native' sample pointer
- * freqAccNext is used here rather than freqAcc: In case the app wants to fill up to
- * the play position it won't overwrite it
- */
-static DWORD DSOUND_bufpos_to_secpos(const IDirectSoundBufferImpl *dsb, DWORD bufpos)
-{
-       DWORD oAdv = dsb->device->pwfx->nBlockAlign, iAdv = dsb->pwfx->nBlockAlign, pos;
-       DWORD64 framelen;
-       DWORD64 acc;
-
-       framelen = bufpos/oAdv;
-       acc = framelen * (DWORD64)dsb->freqAdjust + (DWORD64)dsb->freqAccNext;
-       acc = acc >> DSOUND_FREQSHIFT;
-       pos = (DWORD)acc * iAdv;
-       if (pos >= dsb->buflen)
-               /* Because of differences between freqAcc and freqAccNext, this might happen */
-               pos = dsb->buflen - iAdv;
-       TRACE("Converted %d/%d to %d/%d\n", bufpos, dsb->tmp_buffer_len, pos, dsb->buflen);
-       return pos;
-}
-
-/**
- * Move freqAccNext to freqAcc, and find new values for buffer length and freqAccNext
- */
-static void DSOUND_RecalcFreqAcc(IDirectSoundBufferImpl *dsb)
-{
-       if (!dsb->freqneeded) return;
-       dsb->freqAcc = dsb->freqAccNext;
-       dsb->tmp_buffer_len = DSOUND_secpos_to_bufpos(dsb, dsb->buflen, 0, &dsb->freqAccNext);
-       TRACE("New freqadjust: %04x, new buflen: %d\n", dsb->freqAccNext, dsb->tmp_buffer_len);
-}
-
-/**
- * Recalculate the size for temporary buffer, and new writelead
- * Should be called when one of the following things occur:
- * - Primary buffer format is changed
- * - This buffer format (frequency) is changed
- *
- * After this, DSOUND_MixToTemporary(dsb, 0, dsb->buflen) should
- * be called to refill the temporary buffer with data.
- */
-void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb)
-{
-       BOOL needremix = TRUE, needresample = (dsb->freq != dsb->device->pwfx->nSamplesPerSec);
-       DWORD bAlign = dsb->pwfx->nBlockAlign, pAlign = dsb->device->pwfx->nBlockAlign;
-
-       TRACE("(%p)\n",dsb);
-
-       /* calculate the 10ms write lead */
-       dsb->writelead = (dsb->freq / 100) * dsb->pwfx->nBlockAlign;
-
-       if ((dsb->pwfx->wBitsPerSample == dsb->device->pwfx->wBitsPerSample) &&
-           (dsb->pwfx->nChannels == dsb->device->pwfx->nChannels) && !needresample)
-               needremix = FALSE;
-       HeapFree(GetProcessHeap(), 0, dsb->tmp_buffer);
-       dsb->tmp_buffer = NULL;
-       dsb->max_buffer_len = dsb->freqAcc = dsb->freqAccNext = 0;
-       dsb->freqneeded = needresample;
-
-       dsb->convert = convertbpp[dsb->pwfx->wBitsPerSample/8 - 1][dsb->device->pwfx->wBitsPerSample/8 - 1];
-
-       dsb->resampleinmixer = FALSE;
-
-       if (needremix)
-       {
-               if (needresample)
-                       DSOUND_RecalcFreqAcc(dsb);
-               else
-                       dsb->tmp_buffer_len = dsb->buflen / bAlign * pAlign;
-               dsb->max_buffer_len = dsb->tmp_buffer_len;
-               if ((dsb->max_buffer_len <= dsb->device->buflen || dsb->max_buffer_len < ds_snd_shadow_maxsize * 1024 * 1024) && ds_snd_shadow_maxsize >= 0)
-                       dsb->tmp_buffer = HeapAlloc(GetProcessHeap(), 0, dsb->max_buffer_len);
-               if (dsb->tmp_buffer)
-                       FillMemory(dsb->tmp_buffer, dsb->tmp_buffer_len, dsb->device->pwfx->wBitsPerSample == 8 ? 128 : 0);
-               else
-                       dsb->resampleinmixer = TRUE;
-       }
-       else dsb->max_buffer_len = dsb->tmp_buffer_len = dsb->buflen;
-       dsb->buf_mixpos = DSOUND_secpos_to_bufpos(dsb, dsb->sec_mixpos, 0, NULL);
-}
-
-/**
- * Check for application callback requests for when the play position
- * reaches certain points.
- *
- * The offsets that will be triggered will be those between the recorded
- * "last played" position for the buffer (i.e. dsb->playpos) and "len" bytes
- * beyond that position.
- */
-void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len)
-{
-       int                     i;
-       DWORD                   offset;
-       LPDSBPOSITIONNOTIFY     event;
-       TRACE("(%p,%d)\n",dsb,len);
-
-       if (dsb->nrofnotifies == 0)
-               return;
-
-       TRACE("(%p) buflen = %d, playpos = %d, len = %d\n",
-               dsb, dsb->buflen, playpos, len);
-       for (i = 0; i < dsb->nrofnotifies ; i++) {
-               event = dsb->notifies + i;
-               offset = event->dwOffset;
-               TRACE("checking %d, position %d, event = %p\n",
-                       i, offset, event->hEventNotify);
-               /* DSBPN_OFFSETSTOP has to be the last element. So this is */
-               /* OK. [Inside DirectX, p274] */
-               /* Windows does not seem to enforce this, and some apps rely */
-               /* on that, so we can't stop there. */
-               /*  */
-               /* This also means we can't sort the entries by offset, */
-               /* because DSBPN_OFFSETSTOP == -1 */
-               if (offset == DSBPN_OFFSETSTOP) {
-                       if (dsb->state == STATE_STOPPED) {
-                               SetEvent(event->hEventNotify);
-                               TRACE("signalled event %p (%d)\n", event->hEventNotify, i);
-                       }
-                        continue;
-               }
-               if ((playpos + len) >= dsb->buflen) {
-                       if ((offset < ((playpos + len) % dsb->buflen)) ||
-                           (offset >= playpos)) {
-                               TRACE("signalled event %p (%d)\n", event->hEventNotify, i);
-                               SetEvent(event->hEventNotify);
-                       }
-               } else {
-                       if ((offset >= playpos) && (offset < (playpos + len))) {
-                               TRACE("signalled event %p (%d)\n", event->hEventNotify, i);
-                               SetEvent(event->hEventNotify);
-                       }
-               }
-       }
-}
-
-/**
- * Copy a single frame from the given input buffer to the given output buffer.
- * Translate 8 <-> 16 bits and mono <-> stereo
- */
-static inline void cp_fields(const IDirectSoundBufferImpl *dsb, const BYTE *ibuf, BYTE *obuf,
-        UINT istride, UINT ostride, UINT count, UINT freqAcc, UINT adj)
-{
-    DirectSoundDevice *device = dsb->device;
-    INT istep = dsb->pwfx->wBitsPerSample / 8, ostep = device->pwfx->wBitsPerSample / 8;
-
-    if (device->pwfx->nChannels == dsb->pwfx->nChannels) {
-        dsb->convert(ibuf, obuf, istride, ostride, count, freqAcc, adj);
-        if (device->pwfx->nChannels == 2)
-            dsb->convert(ibuf + istep, obuf + ostep, istride, ostride, count, freqAcc, adj);
-    }
-
-    if (device->pwfx->nChannels == 1 && dsb->pwfx->nChannels == 2)
-    {
-        dsb->convert(ibuf, obuf, istride, ostride, count, freqAcc, adj);
-    }
-
-    if (device->pwfx->nChannels == 2 && dsb->pwfx->nChannels == 1)
-    {
-        dsb->convert(ibuf, obuf, istride, ostride, count, freqAcc, adj);
-        dsb->convert(ibuf, obuf + ostep, istride, ostride, count, freqAcc, adj);
-    }
-}
-
-/**
- * Calculate the distance between two buffer offsets, taking wraparound
- * into account.
- */
-static inline DWORD DSOUND_BufPtrDiff(DWORD buflen, DWORD ptr1, DWORD ptr2)
-{
-/* If these asserts fail, the problem is not here, but in the underlying code */
-       assert(ptr1 < buflen);
-       assert(ptr2 < buflen);
-       if (ptr1 >= ptr2) {
-               return ptr1 - ptr2;
-       } else {
-               return buflen + ptr1 - ptr2;
-       }
-}
-/**
- * Mix at most the given amount of data into the allocated temporary buffer
- * of the given secondary buffer, starting from the dsb's first currently
- * unsampled frame (writepos), translating frequency (pitch), stereo/mono
- * and bits-per-sample so that it is ideal for the primary buffer.
- * Doesn't perform any mixing - this is a straight copy/convert operation.
- *
- * dsb = the secondary buffer
- * writepos = Starting position of changed buffer
- * len = number of bytes to resample from writepos
- *
- * NOTE: writepos + len <= buflen. When called by mixer, MixOne makes sure of this.
- */
-void DSOUND_MixToTemporary(const IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD len, BOOL inmixer)
-{
-       INT     size;
-       BYTE    *ibp, *obp, *obp_begin;
-       INT     iAdvance = dsb->pwfx->nBlockAlign;
-       INT     oAdvance = dsb->device->pwfx->nBlockAlign;
-       DWORD freqAcc, target_writepos = 0, overshot, maxlen;
-
-       /* We resample only when needed */
-       if ((dsb->tmp_buffer && inmixer) || (!dsb->tmp_buffer && !inmixer) || dsb->resampleinmixer != inmixer)
-               return;
-
-       assert(writepos + len <= dsb->buflen);
-       if (inmixer && writepos + len < dsb->buflen)
-               len += dsb->pwfx->nBlockAlign;
-
-       maxlen = DSOUND_secpos_to_bufpos(dsb, len, 0, NULL);
-
-       ibp = dsb->buffer->memory + writepos;
-       if (!inmixer)
-               obp_begin = dsb->tmp_buffer;
-       else if (dsb->device->tmp_buffer_len < maxlen || !dsb->device->tmp_buffer)
-       {
-               dsb->device->tmp_buffer_len = maxlen;
-               if (dsb->device->tmp_buffer)
-                       dsb->device->tmp_buffer = HeapReAlloc(GetProcessHeap(), 0, dsb->device->tmp_buffer, maxlen);
-               else
-                       dsb->device->tmp_buffer = HeapAlloc(GetProcessHeap(), 0, maxlen);
-               obp_begin = dsb->device->tmp_buffer;
-       }
-       else
-               obp_begin = dsb->device->tmp_buffer;
-
-       TRACE("(%p, %p)\n", dsb, ibp);
-       size = len / iAdvance;
-
-       /* Check for same sample rate */
-       if (dsb->freq == dsb->device->pwfx->nSamplesPerSec) {
-               TRACE("(%p) Same sample rate %d = primary %d\n", dsb,
-                       dsb->freq, dsb->device->pwfx->nSamplesPerSec);
-               obp = obp_begin;
-               if (!inmixer)
-                        obp += writepos/iAdvance*oAdvance;
-
-               cp_fields(dsb, ibp, obp, iAdvance, oAdvance, size, 0, 1 << DSOUND_FREQSHIFT);
-               return;
-       }
-
-       /* Mix in different sample rates */
-       TRACE("(%p) Adjusting frequency: %d -> %d\n", dsb, dsb->freq, dsb->device->pwfx->nSamplesPerSec);
-
-       target_writepos = DSOUND_secpos_to_bufpos(dsb, writepos, dsb->sec_mixpos, &freqAcc);
-       overshot = freqAcc >> DSOUND_FREQSHIFT;
-       if (overshot)
-       {
-               if (overshot >= size)
-                       return;
-               size -= overshot;
-               writepos += overshot * iAdvance;
-               if (writepos >= dsb->buflen)
-                       return;
-               ibp = dsb->buffer->memory + writepos;
-               freqAcc &= (1 << DSOUND_FREQSHIFT) - 1;
-               TRACE("Overshot: %d, freqAcc: %04x\n", overshot, freqAcc);
-       }
-
-       if (!inmixer)
-               obp = obp_begin + target_writepos;
-       else obp = obp_begin;
-
-       /* FIXME: Small problem here when we're overwriting buf_mixpos, it then STILL uses old freqAcc, not sure if it matters or not */
-       cp_fields(dsb, ibp, obp, iAdvance, oAdvance, size, freqAcc, dsb->freqAdjust);
-}
-
-/** Apply volume to the given soundbuffer from (primary) position writepos and length len
- * Returns: NULL if no volume needs to be applied
- * or else a memory handle that holds 'len' volume adjusted buffer */
-static LPBYTE DSOUND_MixerVol(const IDirectSoundBufferImpl *dsb, INT len)
-{
-       INT     i;
-       BYTE    *bpc;
-       INT16   *bps, *mems;
-       DWORD vLeft, vRight;
-       INT nChannels = dsb->device->pwfx->nChannels;
-       LPBYTE mem = (dsb->tmp_buffer ? dsb->tmp_buffer : dsb->buffer->memory) + dsb->buf_mixpos;
-
-       if (dsb->resampleinmixer)
-               mem = dsb->device->tmp_buffer;
-
-       TRACE("(%p,%d)\n",dsb,len);
-       TRACE("left = %x, right = %x\n", dsb->volpan.dwTotalLeftAmpFactor,
-               dsb->volpan.dwTotalRightAmpFactor);
-
-       if ((!(dsb->dsbd.dwFlags & DSBCAPS_CTRLPAN) || (dsb->volpan.lPan == 0)) &&
-           (!(dsb->dsbd.dwFlags & DSBCAPS_CTRLVOLUME) || (dsb->volpan.lVolume == 0)) &&
-            !(dsb->dsbd.dwFlags & DSBCAPS_CTRL3D))
-               return NULL; /* Nothing to do */
-
-       if (nChannels != 1 && nChannels != 2)
-       {
-               FIXME("There is no support for %d channels\n", nChannels);
-               return NULL;
-       }
-
-       if (dsb->device->pwfx->wBitsPerSample != 8 && dsb->device->pwfx->wBitsPerSample != 16)
-       {
-               FIXME("There is no support for %d bpp\n", dsb->device->pwfx->wBitsPerSample);
-               return NULL;
-       }
-
-       if (dsb->device->tmp_buffer_len < len || !dsb->device->tmp_buffer)
-       {
-               /* If we just resampled in DSOUND_MixToTemporary, we shouldn't need to resize here */
-               assert(!dsb->resampleinmixer);
-               dsb->device->tmp_buffer_len = len;
-               if (dsb->device->tmp_buffer)
-                       dsb->device->tmp_buffer = HeapReAlloc(GetProcessHeap(), 0, dsb->device->tmp_buffer, len);
-               else
-                       dsb->device->tmp_buffer = HeapAlloc(GetProcessHeap(), 0, len);
-       }
-
-       bpc = dsb->device->tmp_buffer;
-       bps = (INT16 *)bpc;
-       mems = (INT16 *)mem;
-       vLeft = dsb->volpan.dwTotalLeftAmpFactor;
-       if (nChannels > 1)
-               vRight = dsb->volpan.dwTotalRightAmpFactor;
-       else
-               vRight = vLeft;
-
-       switch (dsb->device->pwfx->wBitsPerSample) {
-       case 8:
-               /* 8-bit WAV is unsigned, but we need to operate */
-               /* on signed data for this to work properly */
-               for (i = 0; i < len-1; i+=2) {
-                       *(bpc++) = (((*(mem++) - 128) * vLeft) >> 16) + 128;
-                       *(bpc++) = (((*(mem++) - 128) * vRight) >> 16) + 128;
-               }
-               if (len % 2 == 1 && nChannels == 1)
-                       *(bpc++) = (((*(mem++) - 128) * vLeft) >> 16) + 128;
-               break;
-       case 16:
-               /* 16-bit WAV is signed -- much better */
-               for (i = 0; i < len-3; i += 4) {
-                       *(bps++) = (*(mems++) * vLeft) >> 16;
-                       *(bps++) = (*(mems++) * vRight) >> 16;
-               }
-               if (len % 4 == 2 && nChannels == 1)
-                       *(bps++) = ((INT)*(mems++) * vLeft) >> 16;
-               break;
-       }
-       return dsb->device->tmp_buffer;
-}
-
-/**
- * Mix (at most) the given number of bytes into the given position of the
- * device buffer, from the secondary buffer "dsb" (starting at the current
- * mix position for that buffer).
- *
- * Returns the number of bytes actually mixed into the device buffer. This
- * will match fraglen unless the end of the secondary buffer is reached
- * (and it is not looping).
- *
- * dsb  = the secondary buffer to mix from
- * writepos = position (offset) in device buffer to write at
- * fraglen = number of bytes to mix
- */
-static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD fraglen)
-{
-       INT len = fraglen, ilen;
-       BYTE *ibuf = (dsb->tmp_buffer ? dsb->tmp_buffer : dsb->buffer->memory) + dsb->buf_mixpos, *volbuf;
-       DWORD oldpos, mixbufpos;
-
-       TRACE("buf_mixpos=%d/%d sec_mixpos=%d/%d\n", dsb->buf_mixpos, dsb->tmp_buffer_len, dsb->sec_mixpos, dsb->buflen);
-       TRACE("(%p,%d,%d)\n",dsb,writepos,fraglen);
-
-       assert(dsb->buf_mixpos + len <= dsb->tmp_buffer_len);
-
-       if (len % dsb->device->pwfx->nBlockAlign) {
-               INT nBlockAlign = dsb->device->pwfx->nBlockAlign;
-               ERR("length not a multiple of block size, len = %d, block size = %d\n", len, nBlockAlign);
-               len -= len % nBlockAlign; /* data alignment */
-       }
-
-       /* Resample buffer to temporary buffer specifically allocated for this purpose, if needed */
-       DSOUND_MixToTemporary(dsb, dsb->sec_mixpos, DSOUND_bufpos_to_secpos(dsb, dsb->buf_mixpos+len) - dsb->sec_mixpos, TRUE);
-       if (dsb->resampleinmixer)
-               ibuf = dsb->device->tmp_buffer;
-
-       /* Apply volume if needed */
-       volbuf = DSOUND_MixerVol(dsb, len);
-       if (volbuf)
-               ibuf = volbuf;
-
-       mixbufpos = DSOUND_bufpos_to_mixpos(dsb->device, writepos);
-       /* Now mix the temporary buffer into the devices main buffer */
-       if ((writepos + len) <= dsb->device->buflen)
-               dsb->device->mixfunction(ibuf, dsb->device->mix_buffer + mixbufpos, len);
-       else
-       {
-               DWORD todo = dsb->device->buflen - writepos;
-               dsb->device->mixfunction(ibuf, dsb->device->mix_buffer + mixbufpos, todo);
-               dsb->device->mixfunction(ibuf + todo, dsb->device->mix_buffer, len - todo);
-       }
-
-       oldpos = dsb->sec_mixpos;
-       dsb->buf_mixpos += len;
-
-       if (dsb->buf_mixpos >= dsb->tmp_buffer_len) {
-               if (dsb->buf_mixpos > dsb->tmp_buffer_len)
-                       ERR("Mixpos (%u) past buflen (%u), capping...\n", dsb->buf_mixpos, dsb->tmp_buffer_len);
-               if (dsb->playflags & DSBPLAY_LOOPING) {
-                       dsb->buf_mixpos -= dsb->tmp_buffer_len;
-               } else if (dsb->buf_mixpos >= dsb->tmp_buffer_len) {
-                       dsb->buf_mixpos = dsb->sec_mixpos = 0;
-                       dsb->state = STATE_STOPPED;
-               }
-               DSOUND_RecalcFreqAcc(dsb);
-       }
-
-       dsb->sec_mixpos = DSOUND_bufpos_to_secpos(dsb, dsb->buf_mixpos);
-       ilen = DSOUND_BufPtrDiff(dsb->buflen, dsb->sec_mixpos, oldpos);
-       /* check for notification positions */
-       if (dsb->dsbd.dwFlags & DSBCAPS_CTRLPOSITIONNOTIFY &&
-           dsb->state != STATE_STARTING) {
-               DSOUND_CheckEvent(dsb, oldpos, ilen);
-       }
-
-       /* increase mix position */
-       dsb->primary_mixpos += len;
-       if (dsb->primary_mixpos >= dsb->device->buflen)
-               dsb->primary_mixpos -= dsb->device->buflen;
-       return len;
-}
-
-/**
- * Mix some frames from the given secondary buffer "dsb" into the device
- * primary buffer.
- *
- * dsb = the secondary buffer
- * playpos = the current play position in the device buffer (primary buffer)
- * writepos = the current safe-to-write position in the device buffer
- * mixlen = the maximum number of bytes in the primary buffer to mix, from the
- *          current writepos.
- *
- * Returns: the number of bytes beyond the writepos that were mixed.
- */
-static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen)
-{
-       /* The buffer's primary_mixpos may be before or after the device
-        * buffer's mixpos, but both must be ahead of writepos. */
-       DWORD primary_done;
-
-       TRACE("(%p,%d,%d)\n",dsb,writepos,mixlen);
-       TRACE("writepos=%d, buf_mixpos=%d, primary_mixpos=%d, mixlen=%d\n", writepos, dsb->buf_mixpos, dsb->primary_mixpos, mixlen);
-       TRACE("looping=%d, leadin=%d, buflen=%d\n", dsb->playflags, dsb->leadin, dsb->tmp_buffer_len);
-
-       /* If leading in, only mix about 20 ms, and 'skip' mixing the rest, for more fluid pointer advancement */
-       if (dsb->leadin && dsb->state == STATE_STARTING)
-       {
-               if (mixlen > 2 * dsb->device->fraglen)
-               {
-                       dsb->primary_mixpos += mixlen - 2 * dsb->device->fraglen;
-                       dsb->primary_mixpos %= dsb->device->buflen;
-               }
-       }
-       dsb->leadin = FALSE;
-
-       /* calculate how much pre-buffering has already been done for this buffer */
-       primary_done = DSOUND_BufPtrDiff(dsb->device->buflen, dsb->primary_mixpos, writepos);
-
-       /* sanity */
-       if(mixlen < primary_done)
-       {
-               /* Should *NEVER* happen */
-               ERR("Fatal error. Under/Overflow? primary_done=%d, mixpos=%d/%d (%d/%d), primary_mixpos=%d, writepos=%d, mixlen=%d\n", primary_done,dsb->buf_mixpos,dsb->tmp_buffer_len,dsb->sec_mixpos, dsb->buflen, dsb->primary_mixpos, writepos, mixlen);
-               return 0;
-       }
-
-       /* take into account already mixed data */
-       mixlen -= primary_done;
-
-       TRACE("primary_done=%d, mixlen (primary) = %i\n", primary_done, mixlen);
-
-       if (!mixlen)
-               return primary_done;
-
-       /* First try to mix to the end of the buffer if possible
-        * Theoretically it would allow for better optimization
-       */
-       if (mixlen + dsb->buf_mixpos >= dsb->tmp_buffer_len)
-       {
-               DWORD newmixed, mixfirst = dsb->tmp_buffer_len - dsb->buf_mixpos;
-               newmixed = DSOUND_MixInBuffer(dsb, dsb->primary_mixpos, mixfirst);
-               mixlen -= newmixed;
-
-               if (dsb->playflags & DSBPLAY_LOOPING)
-                       while (newmixed && mixlen)
-                       {
-                               mixfirst = (dsb->tmp_buffer_len < mixlen ? dsb->tmp_buffer_len : mixlen);
-                               newmixed = DSOUND_MixInBuffer(dsb, dsb->primary_mixpos, mixfirst);
-                               mixlen -= newmixed;
-                       }
-       }
-       else DSOUND_MixInBuffer(dsb, dsb->primary_mixpos, mixlen);
-
-       /* re-calculate the primary done */
-       primary_done = DSOUND_BufPtrDiff(dsb->device->buflen, dsb->primary_mixpos, writepos);
-
-       TRACE("new primary_mixpos=%d, total mixed data=%d\n", dsb->primary_mixpos, primary_done);
-
-       /* Report back the total prebuffered amount for this buffer */
-       return primary_done;
-}
-
-/**
- * For a DirectSoundDevice, go through all the currently playing buffers and
- * mix them in to the device buffer.
- *
- * writepos = the current safe-to-write position in the primary buffer
- * mixlen = the maximum amount to mix into the primary buffer
- *          (beyond the current writepos)
- * mustlock = Do we have to fight for lock because we otherwise risk an underrun?
- * recover = true if the sound device may have been reset and the write
- *           position in the device buffer changed
- * all_stopped = reports back if all buffers have stopped
- *
- * Returns:  the length beyond the writepos that was mixed to.
- */
-
-static DWORD DSOUND_MixToPrimary(const DirectSoundDevice *device, DWORD writepos, DWORD mixlen, BOOL mustlock, BOOL recover, BOOL *all_stopped)
-{
-       INT i, len;
-       DWORD minlen = 0;
-       IDirectSoundBufferImpl  *dsb;
-       BOOL gotall = TRUE;
-
-       /* unless we find a running buffer, all have stopped */
-       *all_stopped = TRUE;
-
-       TRACE("(%d,%d,%d)\n", writepos, mixlen, recover);
-       for (i = 0; i < device->nrofbuffers; i++) {
-               dsb = device->buffers[i];
-
-               TRACE("MixToPrimary for %p, state=%d\n", dsb, dsb->state);
-
-               if (dsb->buflen && dsb->state && !dsb->hwbuf) {
-                       TRACE("Checking %p, mixlen=%d\n", dsb, mixlen);
-                       if (!RtlAcquireResourceShared(&dsb->lock, mustlock))
-                       {
-                               gotall = FALSE;
-                               continue;
-                       }
-                       /* if buffer is stopping it is stopped now */
-                       if (dsb->state == STATE_STOPPING) {
-                               dsb->state = STATE_STOPPED;
-                               DSOUND_CheckEvent(dsb, 0, 0);
-                       } else if (dsb->state != STATE_STOPPED) {
-
-                               /* if recovering, reset the mix position */
-                               if ((dsb->state == STATE_STARTING) || recover) {
-                                       dsb->primary_mixpos = writepos;
-                               }
-
-                               /* if the buffer was starting, it must be playing now */
-                               if (dsb->state == STATE_STARTING)
-                                       dsb->state = STATE_PLAYING;
-
-                               /* mix next buffer into the main buffer */
-                               len = DSOUND_MixOne(dsb, writepos, mixlen);
-
-                               if (!minlen) minlen = len;
-
-                               /* record the minimum length mixed from all buffers */
-                               /* we only want to return the length which *all* buffers have mixed */
-                               else if (len) minlen = (len < minlen) ? len : minlen;
-
-                               *all_stopped = FALSE;
-                       }
-                       RtlReleaseResource(&dsb->lock);
-               }
-       }
-
-       TRACE("Mixed at least %d from all buffers\n", minlen);
-       if (!gotall) return 0;
-       return minlen;
-}
-
-/**
- * Add buffers to the emulated wave device system.
- *
- * device = The current dsound playback device
- * force = If TRUE, the function will buffer up as many frags as possible,
- *         even though and will ignore the actual state of the primary buffer.
- *
- * Returns:  None
- */
-
-static void DSOUND_WaveQueue(DirectSoundDevice *device, BOOL force)
-{
-       DWORD prebuf_frags, wave_writepos, wave_fragpos, i;
-       TRACE("(%p)\n", device);
-
-       /* calculate the current wave frag position */
-       wave_fragpos = (device->pwplay + device->pwqueue) % device->helfrags;
-
-       /* calculate the current wave write position */
-       wave_writepos = wave_fragpos * device->fraglen;
-
-       TRACE("wave_fragpos = %i, wave_writepos = %i, pwqueue = %i, prebuf = %i\n",
-               wave_fragpos, wave_writepos, device->pwqueue, device->prebuf);
-
-       if (!force)
-       {
-               /* check remaining prebuffered frags */
-               prebuf_frags = device->mixpos / device->fraglen;
-               if (prebuf_frags == device->helfrags)
-                       --prebuf_frags;
-               TRACE("wave_fragpos = %d, mixpos_frags = %d\n", wave_fragpos, prebuf_frags);
-               if (prebuf_frags < wave_fragpos)
-                       prebuf_frags += device->helfrags;
-               prebuf_frags -= wave_fragpos;
-               TRACE("wanted prebuf_frags = %d\n", prebuf_frags);
-       }
-       else
-               /* buffer the maximum amount of frags */
-               prebuf_frags = device->prebuf;
-
-       /* limit to the queue we have left */
-       if ((prebuf_frags + device->pwqueue) > device->prebuf)
-               prebuf_frags = device->prebuf - device->pwqueue;
-
-       TRACE("prebuf_frags = %i\n", prebuf_frags);
-
-       /* adjust queue */
-       device->pwqueue += prebuf_frags;
-
-       /* get out of CS when calling the wave system */
-       LeaveCriticalSection(&(device->mixlock));
-       /* **** */
-
-       /* queue up the new buffers */
-       for(i=0; i<prebuf_frags; i++){
-               TRACE("queueing wave buffer %i\n", wave_fragpos);
-               waveOutWrite(device->hwo, &device->pwave[wave_fragpos], sizeof(WAVEHDR));
-               wave_fragpos++;
-               wave_fragpos %= device->helfrags;
-       }
-
-       /* **** */
-       EnterCriticalSection(&(device->mixlock));
-
-       TRACE("queue now = %i\n", device->pwqueue);
-}
-
-/**
- * Perform mixing for a Direct Sound device. That is, go through all the
- * secondary buffers (the sound bites currently playing) and mix them in
- * to the primary buffer (the device buffer).
- */
-static void DSOUND_PerformMix(DirectSoundDevice *device)
-{
-       TRACE("(%p)\n", device);
-
-       /* **** */
-       EnterCriticalSection(&(device->mixlock));
-
-       if (device->priolevel != DSSCL_WRITEPRIMARY) {
-               BOOL recover = FALSE, all_stopped = FALSE;
-               DWORD playpos, writepos, writelead, maxq, frag, prebuff_max, prebuff_left, size1, size2, mixplaypos, mixplaypos2;
-               LPVOID buf1, buf2;
-               BOOL lock = (device->hwbuf && !(device->drvdesc.dwFlags & DSDDESC_DONTNEEDPRIMARYLOCK));
-               BOOL mustlock = FALSE;
-               int nfiller;
-
-               /* the sound of silence */
-               nfiller = device->pwfx->wBitsPerSample == 8 ? 128 : 0;
-
-               /* get the position in the primary buffer */
-               if (DSOUND_PrimaryGetPosition(device, &playpos, &writepos) != 0){
-                       LeaveCriticalSection(&(device->mixlock));
-                       return;
-               }
-
-               TRACE("primary playpos=%d, writepos=%d, clrpos=%d, mixpos=%d, buflen=%d\n",
-                     playpos,writepos,device->playpos,device->mixpos,device->buflen);
-               assert(device->playpos < device->buflen);
-
-               mixplaypos = DSOUND_bufpos_to_mixpos(device, device->playpos);
-               mixplaypos2 = DSOUND_bufpos_to_mixpos(device, playpos);
-
-               /* calc maximum prebuff */
-               prebuff_max = (device->prebuf * device->fraglen);
-               if (!device->hwbuf && playpos + prebuff_max >= device->helfrags * device->fraglen)
-                       prebuff_max += device->buflen - device->helfrags * device->fraglen;
-
-               /* check how close we are to an underrun. It occurs when the writepos overtakes the mixpos */
-               prebuff_left = DSOUND_BufPtrDiff(device->buflen, device->mixpos, playpos);
-               writelead = DSOUND_BufPtrDiff(device->buflen, writepos, playpos);
-
-               /* check for underrun. underrun occurs when the write position passes the mix position
-                * also wipe out just-played sound data */
-               if((prebuff_left > prebuff_max) || (device->state == STATE_STOPPED) || (device->state == STATE_STARTING)){
-                       if (device->state == STATE_STOPPING || device->state == STATE_PLAYING)
-                               WARN("Probable buffer underrun\n");
-                       else TRACE("Buffer starting or buffer underrun\n");
-
-                       /* recover mixing for all buffers */
-                       recover = TRUE;
-
-                       /* reset mix position to write position */
-                       device->mixpos = writepos;
-
-                       ZeroMemory(device->mix_buffer, device->mix_buffer_len);
-                       ZeroMemory(device->buffer, device->buflen);
-               } else if (playpos < device->playpos) {
-                       buf1 = device->buffer + device->playpos;
-                       buf2 = device->buffer;
-                       size1 = device->buflen - device->playpos;
-                       size2 = playpos;
-                       FillMemory(device->mix_buffer + mixplaypos, device->mix_buffer_len - mixplaypos, 0);
-                       FillMemory(device->mix_buffer, mixplaypos2, 0);
-                       if (lock)
-                               IDsDriverBuffer_Lock(device->hwbuf, &buf1, &size1, &buf2, &size2, device->playpos, size1+size2, 0);
-                       FillMemory(buf1, size1, nfiller);
-                       if (playpos && (!buf2 || !size2))
-                               FIXME("%d: (%d, %d)=>(%d, %d) There should be an additional buffer here!!\n", __LINE__, device->playpos, device->mixpos, playpos, writepos);
-                       FillMemory(buf2, size2, nfiller);
-                       if (lock)
-                               IDsDriverBuffer_Unlock(device->hwbuf, buf1, size1, buf2, size2);
-               } else {
-                       buf1 = device->buffer + device->playpos;
-                       buf2 = NULL;
-                       size1 = playpos - device->playpos;
-                       size2 = 0;
-                       FillMemory(device->mix_buffer + mixplaypos, mixplaypos2 - mixplaypos, 0);
-                       if (lock)
-                               IDsDriverBuffer_Lock(device->hwbuf, &buf1, &size1, &buf2, &size2, device->playpos, size1+size2, 0);
-                       FillMemory(buf1, size1, nfiller);
-                       if (buf2 && size2)
-                       {
-                               FIXME("%d: There should be no additional buffer here!!\n", __LINE__);
-                               FillMemory(buf2, size2, nfiller);
-                       }
-                       if (lock)
-                               IDsDriverBuffer_Unlock(device->hwbuf, buf1, size1, buf2, size2);
-               }
-               device->playpos = playpos;
-
-               /* find the maximum we can prebuffer from current write position */
-               maxq = (writelead < prebuff_max) ? (prebuff_max - writelead) : 0;
-
-               TRACE("prebuff_left = %d, prebuff_max = %dx%d=%d, writelead=%d\n",
-                       prebuff_left, device->prebuf, device->fraglen, prebuff_max, writelead);
-
-               /* Do we risk an 'underrun' if we don't advance pointer? */
-               if (writelead/device->fraglen <= ds_snd_queue_min || recover)
-                       mustlock = TRUE;
-
-               if (lock)
-                       IDsDriverBuffer_Lock(device->hwbuf, &buf1, &size1, &buf2, &size2, writepos, maxq, 0);
-
-               /* do the mixing */
-               frag = DSOUND_MixToPrimary(device, writepos, maxq, mustlock, recover, &all_stopped);
-
-               if (frag + writepos > device->buflen)
-               {
-                       DWORD todo = device->buflen - writepos;
-                       device->normfunction(device->mix_buffer + DSOUND_bufpos_to_mixpos(device, writepos), device->buffer + writepos, todo);
-                       device->normfunction(device->mix_buffer, device->buffer, frag - todo);
-               }
-               else
-                       device->normfunction(device->mix_buffer + DSOUND_bufpos_to_mixpos(device, writepos), device->buffer + writepos, frag);
-
-               /* update the mix position, taking wrap-around into account */
-               device->mixpos = writepos + frag;
-               device->mixpos %= device->buflen;
-
-               if (lock)
-               {
-                       DWORD frag2 = (frag > size1 ? frag - size1 : 0);
-                       frag -= frag2;
-                       if (frag2 > size2)
-                       {
-                               FIXME("Buffering too much! (%d, %d, %d, %d)\n", maxq, frag, size2, frag2 - size2);
-                               frag2 = size2;
-                       }
-                       IDsDriverBuffer_Unlock(device->hwbuf, buf1, frag, buf2, frag2);
-               }
-
-               /* update prebuff left */
-               prebuff_left = DSOUND_BufPtrDiff(device->buflen, device->mixpos, playpos);
-
-               /* check if have a whole fragment */
-               if (prebuff_left >= device->fraglen){
-
-                       /* update the wave queue if using wave system */
-                       if (!device->hwbuf)
-                               DSOUND_WaveQueue(device, FALSE);
-
-                       /* buffers are full. start playing if applicable */
-                       if(device->state == STATE_STARTING){
-                               TRACE("started primary buffer\n");
-                               if(DSOUND_PrimaryPlay(device) != DS_OK){
-                                       WARN("DSOUND_PrimaryPlay failed\n");
-                               }
-                               else{
-                                       /* we are playing now */
-                                       device->state = STATE_PLAYING;
-                               }
-                       }
-
-                       /* buffers are full. start stopping if applicable */
-                       if(device->state == STATE_STOPPED){
-                               TRACE("restarting primary buffer\n");
-                               if(DSOUND_PrimaryPlay(device) != DS_OK){
-                                       WARN("DSOUND_PrimaryPlay failed\n");
-                               }
-                               else{
-                                       /* start stopping again. as soon as there is no more data, it will stop */
-                                       device->state = STATE_STOPPING;
-                               }
-                       }
-               }
-
-               /* if device was stopping, its for sure stopped when all buffers have stopped */
-               else if((all_stopped == TRUE) && (device->state == STATE_STOPPING)){
-                       TRACE("All buffers have stopped. Stopping primary buffer\n");
-                       device->state = STATE_STOPPED;
-
-                       /* stop the primary buffer now */
-                       DSOUND_PrimaryStop(device);
-               }
-
-       } else {
-
-               /* update the wave queue if using wave system */
-               if (!device->hwbuf)
-                       DSOUND_WaveQueue(device, TRUE);
-               else
-                       /* Keep alsa happy, which needs GetPosition called once every 10 ms */
-                       IDsDriverBuffer_GetPosition(device->hwbuf, NULL, NULL);
-
-               /* in the DSSCL_WRITEPRIMARY mode, the app is totally in charge... */
-               if (device->state == STATE_STARTING) {
-                       if (DSOUND_PrimaryPlay(device) != DS_OK)
-                               WARN("DSOUND_PrimaryPlay failed\n");
-                       else
-                               device->state = STATE_PLAYING;
-               }
-               else if (device->state == STATE_STOPPING) {
-                       if (DSOUND_PrimaryStop(device) != DS_OK)
-                               WARN("DSOUND_PrimaryStop failed\n");
-                       else
-                               device->state = STATE_STOPPED;
-               }
-       }
-
-       LeaveCriticalSection(&(device->mixlock));
-       /* **** */
-}
-
-void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser,
-                           DWORD_PTR dw1, DWORD_PTR dw2)
-{
-       DirectSoundDevice * device = (DirectSoundDevice*)dwUser;
-       DWORD start_time =  GetTickCount();
-       DWORD end_time;
-       TRACE("(%d,%d,0x%lx,0x%lx,0x%lx)\n",timerID,msg,dwUser,dw1,dw2);
-       TRACE("entering at %d\n", start_time);
-
-       if (DSOUND_renderer[device->drvdesc.dnDevNode] != device) {
-               ERR("dsound died without killing us?\n");
-               timeKillEvent(timerID);
-               timeEndPeriod(DS_TIME_RES);
-               return;
-       }
-
-       RtlAcquireResourceShared(&(device->buffer_list_lock), TRUE);
-
-       if (device->ref)
-               DSOUND_PerformMix(device);
-
-       RtlReleaseResource(&(device->buffer_list_lock));
-
-       end_time = GetTickCount();
-       TRACE("completed processing at %d, duration = %d\n", end_time, end_time - start_time);
-}
-
-void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
-{
-       DirectSoundDevice * device = (DirectSoundDevice*)dwUser;
-       TRACE("(%p,%x,%lx,%lx,%lx)\n",hwo,msg,dwUser,dw1,dw2);
-       TRACE("entering at %d, msg=%08x(%s)\n", GetTickCount(), msg,
-               msg==MM_WOM_DONE ? "MM_WOM_DONE" : msg==MM_WOM_CLOSE ? "MM_WOM_CLOSE" : 
-               msg==MM_WOM_OPEN ? "MM_WOM_OPEN" : "UNKNOWN");
-
-       /* check if packet completed from wave driver */
-       if (msg == MM_WOM_DONE) {
-
-               /* **** */
-               EnterCriticalSection(&(device->mixlock));
-
-               TRACE("done playing primary pos=%d\n", device->pwplay * device->fraglen);
-
-               /* update playpos */
-               device->pwplay++;
-               device->pwplay %= device->helfrags;
-
-               /* sanity */
-               if(device->pwqueue == 0){
-                       ERR("Wave queue corrupted!\n");
-               }
-
-               /* update queue */
-               device->pwqueue--;
-
-               LeaveCriticalSection(&(device->mixlock));
-               /* **** */
-       }
-       TRACE("completed\n");
-}
diff --git a/dll/directx/dsound/primary.c b/dll/directx/dsound/primary.c
deleted file mode 100644 (file)
index b35a4eb..0000000
+++ /dev/null
@@ -1,1208 +0,0 @@
-/*                     DirectSound
- *
- * Copyright 1998 Marcus Meissner
- * Copyright 1998 Rob Riggs
- * Copyright 2000-2002 TransGaming Technologies, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#include <stdarg.h>
-
-#define NONAMELESSSTRUCT
-#define NONAMELESSUNION
-#include "windef.h"
-#include "winbase.h"
-#include "winuser.h"
-#include "mmsystem.h"
-#include "winternl.h"
-#include "mmddk.h"
-#include "wine/debug.h"
-#include "dsound.h"
-#include "dsdriver.h"
-#include "dsound_private.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(dsound);
-
-/** Calculate how long a fragment length of about 10 ms should be in frames
- *
- * nSamplesPerSec: Frequency rate in samples per second
- * nBlockAlign: Size of a single blockalign
- *
- * Returns:
- * Size in bytes of a single fragment
- */
-DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign)
-{
-    /* Given a timer delay of 10ms, the fragment size is approximately:
-     *     fraglen = (nSamplesPerSec * 10 / 1000) * nBlockAlign
-     * ==> fraglen = (nSamplesPerSec / 100) * nBlockSize
-     *
-     * ALSA uses buffers that are powers of 2. Because of this, fraglen
-     * is rounded up to the nearest power of 2:
-     */
-
-    if (nSamplesPerSec <= 12800)
-        return 128 * nBlockAlign;
-
-    if (nSamplesPerSec <= 25600)
-        return 256 * nBlockAlign;
-
-    if (nSamplesPerSec <= 51200)
-        return 512 * nBlockAlign;
-
-    return 1024 * nBlockAlign;
-}
-
-static void DSOUND_RecalcPrimary(DirectSoundDevice *device)
-{
-    TRACE("(%p)\n", device);
-
-    device->fraglen = DSOUND_fraglen(device->pwfx->nSamplesPerSec, device->pwfx->nBlockAlign);
-    device->helfrags = device->buflen / device->fraglen;
-    TRACE("fraglen=%d helfrags=%d\n", device->fraglen, device->helfrags);
-
-    if (device->hwbuf && device->drvdesc.dwFlags & DSDDESC_DONTNEEDWRITELEAD)
-        device->writelead = 0;
-    else
-        /* calculate the 10ms write lead */
-        device->writelead = (device->pwfx->nSamplesPerSec / 100) * device->pwfx->nBlockAlign;
-}
-
-HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
-{
-       HRESULT hres = DS_OK;
-       TRACE("(%p, %d)\n", device, forcewave);
-
-       if (device->driver)
-       {
-               IDsDriver_Close(device->driver);
-               if (device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMOPEN)
-                       waveOutClose(device->hwo);
-               IDsDriver_Release(device->driver);
-               device->driver = NULL;
-               device->buffer = NULL;
-               device->hwo = 0;
-       }
-       else if (device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMOPEN)
-               waveOutClose(device->hwo);
-
-       /* DRV_QUERYDSOUNDIFACE is a "Wine extension" to get the DSound interface */
-       if (ds_hw_accel != DS_HW_ACCEL_EMULATION && !forcewave)
-               waveOutMessage((HWAVEOUT)device->drvdesc.dnDevNode, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&device->driver, 0);
-
-       /* Get driver description */
-       if (device->driver) {
-               DWORD wod = device->drvdesc.dnDevNode;
-               hres = IDsDriver_GetDriverDesc(device->driver,&(device->drvdesc));
-               device->drvdesc.dnDevNode = wod;
-               if (FAILED(hres)) {
-                       WARN("IDsDriver_GetDriverDesc failed: %08x\n", hres);
-                       IDsDriver_Release(device->driver);
-                       device->driver = NULL;
-               }
-        }
-
-        /* if no DirectSound interface available, use WINMM API instead */
-       if (!device->driver)
-               device->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN | DSDDESC_DOMMSYSTEMSETFORMAT;
-
-       if (device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMOPEN)
-       {
-               DWORD flags = CALLBACK_FUNCTION;
-
-               if (device->driver)
-                       flags |= WAVE_DIRECTSOUND;
-
-               hres = mmErr(waveOutOpen(&(device->hwo), device->drvdesc.dnDevNode, device->pwfx, (DWORD_PTR)DSOUND_callback, (DWORD_PTR)device, flags));
-               if (FAILED(hres)) {
-                       WARN("waveOutOpen failed\n");
-                       if (device->driver)
-                       {
-                               IDsDriver_Release(device->driver);
-                               device->driver = NULL;
-                       }
-                       return hres;
-               }
-       }
-
-       if (device->driver)
-               hres = IDsDriver_Open(device->driver);
-
-       return hres;
-}
-
-static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device)
-{
-       DWORD buflen;
-       HRESULT err = DS_OK;
-       TRACE("(%p)\n", device);
-
-       /* on original windows, the buffer it set to a fixed size, no matter what the settings are.
-          on windows this size is always fixed (tested on win-xp) */
-       if (!device->buflen)
-               device->buflen = ds_hel_buflen;
-       buflen = device->buflen;
-       buflen -= buflen % device->pwfx->nBlockAlign;
-       device->buflen = buflen;
-
-       if (device->driver)
-       {
-               err = IDsDriver_CreateSoundBuffer(device->driver,device->pwfx,
-                                                 DSBCAPS_PRIMARYBUFFER,0,
-                                                 &(device->buflen),&(device->buffer),
-                                                 (LPVOID*)&(device->hwbuf));
-
-               if (err != DS_OK) {
-                       WARN("IDsDriver_CreateSoundBuffer failed (%08x), falling back to waveout\n", err);
-                       err = DSOUND_ReopenDevice(device, TRUE);
-                       if (FAILED(err))
-                       {
-                               WARN("Falling back to waveout failed too! Giving up\n");
-                               return err;
-                       }
-               }
-                if (device->hwbuf)
-                    IDsDriverBuffer_SetVolumePan(device->hwbuf, &device->volpan);
-
-                DSOUND_RecalcPrimary(device);
-               device->prebuf = ds_snd_queue_max;
-               if (device->helfrags < ds_snd_queue_min)
-               {
-                       WARN("Too little sound buffer to be effective (%d/%d) falling back to waveout\n", device->buflen, ds_snd_queue_min * device->fraglen);
-                       device->buflen = buflen;
-                       IDsDriverBuffer_Release(device->hwbuf);
-                       device->hwbuf = NULL;
-                       err = DSOUND_ReopenDevice(device, TRUE);
-                       if (FAILED(err))
-                       {
-                               WARN("Falling back to waveout failed too! Giving up\n");
-                               return err;
-                       }
-               }
-               else if (device->helfrags < ds_snd_queue_max)
-                       device->prebuf = device->helfrags;
-       }
-
-       device->mix_buffer_len = DSOUND_bufpos_to_mixpos(device, device->buflen);
-       device->mix_buffer = HeapAlloc(GetProcessHeap(), 0, device->mix_buffer_len);
-       if (!device->mix_buffer)
-       {
-               if (device->hwbuf)
-                       IDsDriverBuffer_Release(device->hwbuf);
-               device->hwbuf = NULL;
-               return DSERR_OUTOFMEMORY;
-       }
-
-       if (device->state == STATE_PLAYING) device->state = STATE_STARTING;
-       else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED;
-
-       /* are we using waveOut stuff? */
-       if (!device->driver) {
-               LPBYTE newbuf;
-               LPWAVEHDR headers = NULL;
-               DWORD overshot;
-               unsigned int c;
-
-               /* Start in pause mode, to allow buffers to get filled */
-               waveOutPause(device->hwo);
-
-               TRACE("desired buflen=%d, old buffer=%p\n", buflen, device->buffer);
-
-               /* reallocate emulated primary buffer */
-               if (device->buffer)
-                       newbuf = HeapReAlloc(GetProcessHeap(),0,device->buffer, buflen);
-               else
-                       newbuf = HeapAlloc(GetProcessHeap(),0, buflen);
-
-               if (!newbuf) {
-                       ERR("failed to allocate primary buffer\n");
-                       return DSERR_OUTOFMEMORY;
-                       /* but the old buffer might still exist and must be re-prepared */
-               }
-
-               DSOUND_RecalcPrimary(device);
-               if (device->pwave)
-                       headers = HeapReAlloc(GetProcessHeap(),0,device->pwave, device->helfrags * sizeof(WAVEHDR));
-               else
-                       headers = HeapAlloc(GetProcessHeap(),0,device->helfrags * sizeof(WAVEHDR));
-
-               if (!headers) {
-                       ERR("failed to allocate wave headers\n");
-                       HeapFree(GetProcessHeap(), 0, newbuf);
-                       DSOUND_RecalcPrimary(device);
-                       return DSERR_OUTOFMEMORY;
-               }
-
-               device->buffer = newbuf;
-               device->pwave = headers;
-
-               /* prepare fragment headers */
-               for (c=0; c<device->helfrags; c++) {
-                       device->pwave[c].lpData = (char*)device->buffer + c*device->fraglen;
-                       device->pwave[c].dwBufferLength = device->fraglen;
-                       device->pwave[c].dwUser = (DWORD_PTR)device;
-                       device->pwave[c].dwFlags = 0;
-                       device->pwave[c].dwLoops = 0;
-                       err = mmErr(waveOutPrepareHeader(device->hwo,&device->pwave[c],sizeof(WAVEHDR)));
-                       if (err != DS_OK) {
-                               while (c--)
-                                       waveOutUnprepareHeader(device->hwo,&device->pwave[c],sizeof(WAVEHDR));
-                               break;
-                       }
-               }
-
-               overshot = device->buflen % device->fraglen;
-               /* sanity */
-               if(overshot)
-               {
-                       overshot -= overshot % device->pwfx->nBlockAlign;
-                       device->pwave[device->helfrags - 1].dwBufferLength += overshot;
-               }
-
-               TRACE("fraglen=%d, overshot=%d\n", device->fraglen, overshot);
-       }
-       device->mixfunction = mixfunctions[device->pwfx->wBitsPerSample/8 - 1];
-       device->normfunction = normfunctions[device->pwfx->wBitsPerSample/8 - 1];
-       FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0);
-       FillMemory(device->mix_buffer, device->mix_buffer_len, 0);
-       device->pwplay = device->pwqueue = device->playpos = device->mixpos = 0;
-       return err;
-}
-
-
-static void DSOUND_PrimaryClose(DirectSoundDevice *device)
-{
-       TRACE("(%p)\n", device);
-
-       /* are we using waveOut stuff? */
-       if (!device->hwbuf) {
-               unsigned c;
-
-               /* get out of CS when calling the wave system */
-               LeaveCriticalSection(&(device->mixlock));
-               /* **** */
-               device->pwqueue = (DWORD)-1; /* resetting queues */
-               waveOutReset(device->hwo);
-               for (c=0; c<device->helfrags; c++)
-                       waveOutUnprepareHeader(device->hwo, &device->pwave[c], sizeof(WAVEHDR));
-               /* **** */
-               EnterCriticalSection(&(device->mixlock));
-
-               /* clear the queue */
-               device->pwqueue = 0;
-       } else {
-               ULONG ref = IDsDriverBuffer_Release(device->hwbuf);
-               if (!ref)
-                       device->hwbuf = 0;
-               else
-                       ERR("Still %d references on primary buffer, refcount leak?\n", ref);
-       }
-}
-
-HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device)
-{
-       HRESULT err = DS_OK;
-       TRACE("(%p)\n", device);
-
-       device->buflen = ds_hel_buflen;
-       err = DSOUND_PrimaryOpen(device);
-
-       if (err != DS_OK) {
-               WARN("DSOUND_PrimaryOpen failed\n");
-               return err;
-       }
-
-       device->state = STATE_STOPPED;
-       return DS_OK;
-}
-
-HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device)
-{
-       TRACE("(%p)\n", device);
-
-       /* **** */
-       EnterCriticalSection(&(device->mixlock));
-
-       DSOUND_PrimaryClose(device);
-       if (device->driver) {
-               if (device->hwbuf) {
-                       if (IDsDriverBuffer_Release(device->hwbuf) == 0)
-                               device->hwbuf = 0;
-               }
-       } else
-                HeapFree(GetProcessHeap(),0,device->pwave);
-        HeapFree(GetProcessHeap(),0,device->pwfx);
-        device->pwfx=NULL;
-
-       LeaveCriticalSection(&(device->mixlock));
-       /* **** */
-
-       return DS_OK;
-}
-
-HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device)
-{
-       HRESULT err = DS_OK;
-       TRACE("(%p)\n", device);
-
-       if (device->hwbuf) {
-               err = IDsDriverBuffer_Play(device->hwbuf, 0, 0, DSBPLAY_LOOPING);
-               if (err != DS_OK)
-                       WARN("IDsDriverBuffer_Play failed\n");
-       } else {
-               err = mmErr(waveOutRestart(device->hwo));
-               if (err != DS_OK)
-                       WARN("waveOutRestart failed\n");
-       }
-
-       return err;
-}
-
-HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device)
-{
-       HRESULT err = DS_OK;
-       TRACE("(%p)\n", device);
-
-       if (device->hwbuf) {
-               err = IDsDriverBuffer_Stop(device->hwbuf);
-               if (err == DSERR_BUFFERLOST) {
-                       DSOUND_PrimaryClose(device);
-                       err = DSOUND_ReopenDevice(device, FALSE);
-                       if (FAILED(err))
-                               ERR("DSOUND_ReopenDevice failed\n");
-                       else
-                       {
-                               err = DSOUND_PrimaryOpen(device);
-                               if (FAILED(err))
-                                       WARN("DSOUND_PrimaryOpen failed\n");
-                       }
-               } else if (err != DS_OK) {
-                       WARN("IDsDriverBuffer_Stop failed\n");
-               }
-       } else {
-
-               /* don't call the wave system with the lock set */
-               LeaveCriticalSection(&(device->mixlock));
-               /* **** */
-
-               err = mmErr(waveOutPause(device->hwo));
-
-               /* **** */
-               EnterCriticalSection(&(device->mixlock));
-
-               if (err != DS_OK)
-                       WARN("waveOutPause failed\n");
-       }
-
-       return err;
-}
-
-HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos)
-{
-       TRACE("(%p,%p,%p)\n", device, playpos, writepos);
-
-       if (device->hwbuf) {
-               HRESULT err=IDsDriverBuffer_GetPosition(device->hwbuf,playpos,writepos);
-               if (err != S_OK) {
-                       WARN("IDsDriverBuffer_GetPosition failed\n");
-                       return err;
-               }
-       } else {
-               TRACE("pwplay=%i, pwqueue=%i\n", device->pwplay, device->pwqueue);
-
-               /* check if playpos was requested */
-               if (playpos)
-                       /* use the cached play position */
-                       *playpos = device->pwplay * device->fraglen;
-
-               /* check if writepos was requested */
-               if (writepos)
-                       /* the writepos is the first non-queued position */
-                       *writepos = ((device->pwplay + device->pwqueue) % device->helfrags) * device->fraglen;
-       }
-       TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:-1, writepos?*writepos:-1, device, GetTickCount());
-       return DS_OK;
-}
-
-HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex, BOOL forced)
-{
-       HRESULT err = DSERR_BUFFERLOST;
-       int i, alloc_size, cp_size;
-       DWORD nSamplesPerSec, bpp, chans;
-       TRACE("(%p,%p)\n", device, wfex);
-
-       if (device->priolevel == DSSCL_NORMAL) {
-               WARN("failed priority check!\n");
-               return DSERR_PRIOLEVELNEEDED;
-       }
-
-       /* Let's be pedantic! */
-       if (wfex == NULL) {
-               WARN("invalid parameter: wfex==NULL!\n");
-               return DSERR_INVALIDPARAM;
-       }
-       TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
-              "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
-             wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
-             wfex->nAvgBytesPerSec, wfex->nBlockAlign,
-             wfex->wBitsPerSample, wfex->cbSize);
-
-       /* **** */
-       RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
-       EnterCriticalSection(&(device->mixlock));
-
-        if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
-            alloc_size = sizeof(WAVEFORMATEX);
-            cp_size = sizeof(PCMWAVEFORMAT);
-        } else
-            alloc_size = cp_size = sizeof(WAVEFORMATEX) + wfex->cbSize;
-
-        device->pwfx = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,device->pwfx,alloc_size);
-
-       nSamplesPerSec = device->pwfx->nSamplesPerSec;
-       bpp = device->pwfx->wBitsPerSample;
-       chans = device->pwfx->nChannels;
-
-        CopyMemory(device->pwfx, wfex, cp_size);
-
-       if (!(device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMSETFORMAT) && device->hwbuf) {
-               err = IDsDriverBuffer_SetFormat(device->hwbuf, device->pwfx);
-
-               /* On bad format, try to re-create, big chance it will work then, only do this if we <HAVE> to */
-               if (forced && (device->pwfx->nSamplesPerSec/100 != wfex->nSamplesPerSec/100 || err == DSERR_BADFORMAT))
-               {
-                       err = DSERR_BUFFERLOST;
-                       CopyMemory(device->pwfx, wfex, cp_size);
-               }
-
-               if (err != DSERR_BUFFERLOST && FAILED(err)) {
-                       WARN("IDsDriverBuffer_SetFormat failed\n");
-                       if (!forced)
-                               err = DS_OK;
-                       goto done;
-               }
-
-               if (err == S_FALSE)
-               {
-                       /* ALSA specific: S_FALSE tells that recreation was successful,
-                        * but size and location may be changed, and buffer has to be restarted
-                        * I put it here, so if frequency doesn't match the error will be changed to DSERR_BUFFERLOST
-                        * and the entire re-initialization will occur anyway
-                        */
-                       IDsDriverBuffer_Lock(device->hwbuf, (LPVOID *)&device->buffer, &device->buflen, NULL, NULL, 0, 0, DSBLOCK_ENTIREBUFFER);
-                       IDsDriverBuffer_Unlock(device->hwbuf, device->buffer, 0, NULL, 0);
-
-                       if (device->state == STATE_PLAYING) device->state = STATE_STARTING;
-                       else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED;
-                       device->pwplay = device->pwqueue = device->playpos = device->mixpos = 0;
-                       err = DS_OK;
-               }
-               DSOUND_RecalcPrimary(device);
-       }
-
-       if (err == DSERR_BUFFERLOST)
-       {
-               DSOUND_PrimaryClose(device);
-
-               err = DSOUND_ReopenDevice(device, FALSE);
-               if (FAILED(err))
-               {
-                       WARN("DSOUND_ReopenDevice failed: %08x\n", err);
-                       goto done;
-               }
-               err = DSOUND_PrimaryOpen(device);
-               if (err != DS_OK) {
-                       WARN("DSOUND_PrimaryOpen failed\n");
-                       goto done;
-               }
-
-               if (wfex->nSamplesPerSec/100 != device->pwfx->nSamplesPerSec/100 && forced && device->buffer)
-               {
-                       DSOUND_PrimaryClose(device);
-                       device->pwfx->nSamplesPerSec = wfex->nSamplesPerSec;
-                       err = DSOUND_ReopenDevice(device, TRUE);
-                       if (FAILED(err))
-                               WARN("DSOUND_ReopenDevice(2) failed: %08x\n", err);
-                       else if (FAILED((err = DSOUND_PrimaryOpen(device))))
-                               WARN("DSOUND_PrimaryOpen(2) failed: %08x\n", err);
-               }
-       }
-
-       device->mix_buffer_len = DSOUND_bufpos_to_mixpos(device, device->buflen);
-       device->mix_buffer = HeapReAlloc(GetProcessHeap(), 0, device->mix_buffer, device->mix_buffer_len);
-       FillMemory(device->mix_buffer, device->mix_buffer_len, 0);
-       device->mixfunction = mixfunctions[device->pwfx->wBitsPerSample/8 - 1];
-       device->normfunction = normfunctions[device->pwfx->wBitsPerSample/8 - 1];
-
-       if (nSamplesPerSec != device->pwfx->nSamplesPerSec || bpp != device->pwfx->wBitsPerSample || chans != device->pwfx->nChannels) {
-               IDirectSoundBufferImpl** dsb = device->buffers;
-               for (i = 0; i < device->nrofbuffers; i++, dsb++) {
-                       /* **** */
-                       RtlAcquireResourceExclusive(&(*dsb)->lock, TRUE);
-
-                       (*dsb)->freqAdjust = ((DWORD64)(*dsb)->freq << DSOUND_FREQSHIFT) / device->pwfx->nSamplesPerSec;
-                       DSOUND_RecalcFormat((*dsb));
-                       DSOUND_MixToTemporary((*dsb), 0, (*dsb)->buflen, FALSE);
-                       (*dsb)->primary_mixpos = 0;
-
-                       RtlReleaseResource(&(*dsb)->lock);
-                       /* **** */
-               }
-       }
-
-done:
-       LeaveCriticalSection(&(device->mixlock));
-       RtlReleaseResource(&(device->buffer_list_lock));
-       /* **** */
-
-       return err;
-}
-
-/*******************************************************************************
- *             PrimaryBuffer
- */
-/* This sets this format for the <em>Primary Buffer Only</em> */
-/* See file:///cdrom/sdk52/docs/worddoc/dsound.doc page 120 */
-static HRESULT WINAPI PrimaryBufferImpl_SetFormat(
-    LPDIRECTSOUNDBUFFER iface,
-    LPCWAVEFORMATEX wfex)
-{
-    DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
-    TRACE("(%p,%p)\n", iface, wfex);
-    return DSOUND_PrimarySetFormat(device, wfex, device->priolevel == DSSCL_WRITEPRIMARY);
-}
-
-static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
-       LPDIRECTSOUNDBUFFER iface,LONG vol
-) {
-       DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
-       DWORD ampfactors;
-        HRESULT hres = DS_OK;
-       TRACE("(%p,%d)\n", iface, vol);
-
-       if (!(device->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
-               WARN("control unavailable\n");
-               return DSERR_CONTROLUNAVAIL;
-       }
-
-       if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
-               WARN("invalid parameter: vol = %d\n", vol);
-               return DSERR_INVALIDPARAM;
-       }
-
-       /* **** */
-       EnterCriticalSection(&(device->mixlock));
-
-        waveOutGetVolume(device->hwo, &ampfactors);
-        device->volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
-        device->volpan.dwTotalRightAmpFactor=ampfactors >> 16;
-        DSOUND_AmpFactorToVolPan(&device->volpan);
-        if (vol != device->volpan.lVolume) {
-            device->volpan.lVolume=vol;
-            DSOUND_RecalcVolPan(&device->volpan);
-            if (device->hwbuf) {
-                hres = IDsDriverBuffer_SetVolumePan(device->hwbuf, &device->volpan);
-                if (hres != DS_OK)
-                    WARN("IDsDriverBuffer_SetVolumePan failed\n");
-            } else {
-                ampfactors = (device->volpan.dwTotalLeftAmpFactor & 0xffff) | (device->volpan.dwTotalRightAmpFactor << 16);
-                waveOutSetVolume(device->hwo, ampfactors);
-            }
-        }
-
-       LeaveCriticalSection(&(device->mixlock));
-       /* **** */
-
-       return hres;
-}
-
-static HRESULT WINAPI PrimaryBufferImpl_GetVolume(
-       LPDIRECTSOUNDBUFFER iface,LPLONG vol
-) {
-       DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
-       DWORD ampfactors;
-       TRACE("(%p,%p)\n", iface, vol);
-
-       if (!(device->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
-               WARN("control unavailable\n");
-               return DSERR_CONTROLUNAVAIL;
-       }
-
-       if (vol == NULL) {
-               WARN("invalid parameter: vol = NULL\n");
-               return DSERR_INVALIDPARAM;
-       }
-
-        if (!device->hwbuf)
-        {
-           waveOutGetVolume(device->hwo, &ampfactors);
-           device->volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
-           device->volpan.dwTotalRightAmpFactor=ampfactors >> 16;
-           DSOUND_AmpFactorToVolPan(&device->volpan);
-        }
-        *vol = device->volpan.lVolume;
-       return DS_OK;
-}
-
-static HRESULT WINAPI PrimaryBufferImpl_SetFrequency(
-       LPDIRECTSOUNDBUFFER iface,DWORD freq
-) {
-       PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
-       TRACE("(%p,%d)\n",This,freq);
-
-       /* You cannot set the frequency of the primary buffer */
-       WARN("control unavailable\n");
-       return DSERR_CONTROLUNAVAIL;
-}
-
-static HRESULT WINAPI PrimaryBufferImpl_Play(
-       LPDIRECTSOUNDBUFFER iface,DWORD reserved1,DWORD reserved2,DWORD flags
-) {
-       DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
-       TRACE("(%p,%08x,%08x,%08x)\n", iface, reserved1, reserved2, flags);
-
-       if (!(flags & DSBPLAY_LOOPING)) {
-               WARN("invalid parameter: flags = %08x\n", flags);
-               return DSERR_INVALIDPARAM;
-       }
-
-       /* **** */
-       EnterCriticalSection(&(device->mixlock));
-
-       if (device->state == STATE_STOPPED)
-               device->state = STATE_STARTING;
-       else if (device->state == STATE_STOPPING)
-               device->state = STATE_PLAYING;
-
-       LeaveCriticalSection(&(device->mixlock));
-       /* **** */
-
-       return DS_OK;
-}
-
-static HRESULT WINAPI PrimaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER iface)
-{
-       DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
-       TRACE("(%p)\n", iface);
-
-       /* **** */
-       EnterCriticalSection(&(device->mixlock));
-
-       if (device->state == STATE_PLAYING)
-               device->state = STATE_STOPPING;
-       else if (device->state == STATE_STARTING)
-               device->state = STATE_STOPPED;
-
-       LeaveCriticalSection(&(device->mixlock));
-       /* **** */
-
-       return DS_OK;
-}
-
-static ULONG WINAPI PrimaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER iface)
-{
-    PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref - 1);
-    return ref;
-}
-
-static ULONG WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER iface)
-{
-    PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
-    DWORD ref = InterlockedDecrement(&(This->ref));
-    TRACE("(%p) ref was %d\n", This, ref + 1);
-
-    if (!ref) {
-        This->device->primary = NULL;
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
-    return ref;
-}
-
-static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(
-       LPDIRECTSOUNDBUFFER iface,LPDWORD playpos,LPDWORD writepos
-) {
-       HRESULT hres;
-        DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
-       TRACE("(%p,%p,%p)\n", iface, playpos, writepos);
-
-       /* **** */
-       EnterCriticalSection(&(device->mixlock));
-
-       hres = DSOUND_PrimaryGetPosition(device, playpos, writepos);
-       if (hres != DS_OK) {
-               WARN("DSOUND_PrimaryGetPosition failed\n");
-               LeaveCriticalSection(&(device->mixlock));
-               return hres;
-       }
-       if (writepos) {
-               if (device->state != STATE_STOPPED)
-                       /* apply the documented 10ms lead to writepos */
-                       *writepos += device->writelead;
-               while (*writepos >= device->buflen) *writepos -= device->buflen;
-       }
-
-       LeaveCriticalSection(&(device->mixlock));
-       /* **** */
-
-       TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:0, writepos?*writepos:0, device, GetTickCount());
-       return DS_OK;
-}
-
-static HRESULT WINAPI PrimaryBufferImpl_GetStatus(
-       LPDIRECTSOUNDBUFFER iface,LPDWORD status
-) {
-        DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
-       TRACE("(%p,%p)\n", iface, status);
-
-       if (status == NULL) {
-               WARN("invalid parameter: status == NULL\n");
-               return DSERR_INVALIDPARAM;
-       }
-
-       *status = 0;
-       if ((device->state == STATE_STARTING) ||
-           (device->state == STATE_PLAYING))
-               *status |= DSBSTATUS_PLAYING | DSBSTATUS_LOOPING;
-
-       TRACE("status=%x\n", *status);
-       return DS_OK;
-}
-
-
-static HRESULT WINAPI PrimaryBufferImpl_GetFormat(
-    LPDIRECTSOUNDBUFFER iface,
-    LPWAVEFORMATEX lpwf,
-    DWORD wfsize,
-    LPDWORD wfwritten)
-{
-    DWORD size;
-    DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
-    TRACE("(%p,%p,%d,%p)\n", iface, lpwf, wfsize, wfwritten);
-
-    size = sizeof(WAVEFORMATEX) + device->pwfx->cbSize;
-
-    if (lpwf) {        /* NULL is valid */
-        if (wfsize >= size) {
-            CopyMemory(lpwf,device->pwfx,size);
-            if (wfwritten)
-                *wfwritten = size;
-        } else {
-            WARN("invalid parameter: wfsize too small\n");
-            if (wfwritten)
-                *wfwritten = 0;
-            return DSERR_INVALIDPARAM;
-        }
-    } else {
-        if (wfwritten)
-            *wfwritten = sizeof(WAVEFORMATEX) + device->pwfx->cbSize;
-        else {
-            WARN("invalid parameter: wfwritten == NULL\n");
-            return DSERR_INVALIDPARAM;
-        }
-    }
-
-    return DS_OK;
-}
-
-static HRESULT WINAPI PrimaryBufferImpl_Lock(
-       LPDIRECTSOUNDBUFFER iface,DWORD writecursor,DWORD writebytes,LPVOID *lplpaudioptr1,LPDWORD audiobytes1,LPVOID *lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
-) {
-       HRESULT hres;
-        DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
-       TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n",
-               iface,
-               writecursor,
-               writebytes,
-               lplpaudioptr1,
-               audiobytes1,
-               lplpaudioptr2,
-               audiobytes2,
-               flags,
-               GetTickCount()
-       );
-
-        if (!audiobytes1)
-            return DSERR_INVALIDPARAM;
-
-       if (device->priolevel != DSSCL_WRITEPRIMARY) {
-               WARN("failed priority check!\n");
-               return DSERR_PRIOLEVELNEEDED;
-       }
-
-        /* when this flag is set, writecursor is meaningless and must be calculated */
-       if (flags & DSBLOCK_FROMWRITECURSOR) {
-               /* GetCurrentPosition does too much magic to duplicate here */
-               hres = IDirectSoundBuffer_GetCurrentPosition(iface, NULL, &writecursor);
-               if (hres != DS_OK) {
-                       WARN("IDirectSoundBuffer_GetCurrentPosition failed\n");
-                       return hres;
-               }
-       }
-
-        /* when this flag is set, writebytes is meaningless and must be set */
-       if (flags & DSBLOCK_ENTIREBUFFER)
-               writebytes = device->buflen;
-
-        if (writecursor >= device->buflen) {
-                WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
-                    writecursor, device->buflen);
-                return DSERR_INVALIDPARAM;
-        }
-
-        if (writebytes > device->buflen) {
-                WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
-                    writebytes, device->buflen);
-                return DSERR_INVALIDPARAM;
-        }
-
-       if (!(device->drvdesc.dwFlags & DSDDESC_DONTNEEDPRIMARYLOCK) && device->hwbuf) {
-               hres = IDsDriverBuffer_Lock(device->hwbuf,
-                                           lplpaudioptr1, audiobytes1,
-                                           lplpaudioptr2, audiobytes2,
-                                           writecursor, writebytes,
-                                           0);
-               if (hres != DS_OK) {
-                       WARN("IDsDriverBuffer_Lock failed\n");
-                       return hres;
-               }
-       } else {
-               if (writecursor+writebytes <= device->buflen) {
-                       *(LPBYTE*)lplpaudioptr1 = device->buffer+writecursor;
-                       *audiobytes1 = writebytes;
-                       if (lplpaudioptr2)
-                               *(LPBYTE*)lplpaudioptr2 = NULL;
-                       if (audiobytes2)
-                               *audiobytes2 = 0;
-           &nbs