Index: /trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp	(revision 62908)
+++ /trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp	(revision 62909)
@@ -1362,9 +1362,7 @@
  * @param   pcRead                  Number of audio samples read. Optional.
  */
-int AudioMixBufReadCirc(PPDMAUDIOMIXBUF pMixBuf,
-                        void *pvBuf, uint32_t cbBuf, uint32_t *pcRead)
-{
-    return AudioMixBufReadCircEx(pMixBuf, pMixBuf->AudioFmt,
-                                 pvBuf, cbBuf, pcRead);
+int AudioMixBufReadCirc(PPDMAUDIOMIXBUF pMixBuf, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead)
+{
+    return AudioMixBufReadCircEx(pMixBuf, pMixBuf->AudioFmt, pvBuf, cbBuf, pcRead);
 }
 
@@ -1381,6 +1379,5 @@
  * @param   pcRead                  Number of audio samples read. Optional.
  */
-int AudioMixBufReadCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt,
-                          void *pvBuf, uint32_t cbBuf, uint32_t *pcRead)
+int AudioMixBufReadCircEx(PPDMAUDIOMIXBUF pMixBuf, PDMAUDIOMIXBUFFMT enmFmt, void *pvBuf, uint32_t cbBuf, uint32_t *pcRead)
 {
     AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER);
Index: /trunk/src/VBox/Devices/Audio/AudioMixBuffer.h
===================================================================
--- /trunk/src/VBox/Devices/Audio/AudioMixBuffer.h	(revision 62908)
+++ /trunk/src/VBox/Devices/Audio/AudioMixBuffer.h	(revision 62909)
@@ -1,6 +1,5 @@
 /* $Id$ */
 /** @file
- * VBox audio: Mixing buffer to convert audio samples to/from different
- *             rates / formats.
+ * VBox audio - Mixing buffer to convert audio samples to/from different rates / formats.
  */
 
@@ -82,4 +81,4 @@
 #endif
 
-#endif /* AUDIO_MIXBUF_H */
+#endif
 
Index: /trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp
===================================================================
--- /trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp	(revision 62908)
+++ /trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp	(revision 62909)
@@ -14,9 +14,14 @@
  * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
  * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
- * --------------------------------------------------------------------
  *
  */
+
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
 #define LOG_GROUP LOG_GROUP_DRV_HOST_AUDIO
 #include <VBox/log.h>
+#include <iprt/win/windows.h>
 #include <dsound.h>
 
@@ -28,4 +33,8 @@
 #include "VBoxDD.h"
 
+
+/*********************************************************************************************************************************
+*   Defined Constants And Macros                                                                                                 *
+*********************************************************************************************************************************/
 /*
  * IDirectSound* interface uses HRESULT status codes and the driver callbacks use
@@ -45,24 +54,33 @@
  */
 /* General code behavior. */
-#define DSLOG(a) do { LogRel2(a); } while(0)
+#define DSLOG(a)    do { LogRel2(a); } while(0)
 /* Something which produce a lot of logging during playback/recording. */
-#define DSLOGF(a) do { LogRel3(a); } while(0)
+#define DSLOGF(a)   do { LogRel3(a); } while(0)
 /* Important messages like errors. Limited in the default release log to avoid log flood. */
-#define DSLOGREL(a)                 \
-    do {                            \
-        static int8_t scLogged = 0; \
-        if (scLogged < 8) {         \
-            ++scLogged;             \
-            LogRel(a);              \
-        }                           \
-        else {                      \
-            DSLOG(a);               \
-        }                           \
+#define DSLOGREL(a) \
+    do {  \
+        static int8_t s_cLogged = 0; \
+        if (s_cLogged < 8) { \
+            ++s_cLogged; \
+            LogRel(a); \
+        } else DSLOG(a); \
     } while (0)
 
+
+/** Maximum number of attempts to restore the sound buffer before giving up. */
+#define DRV_DSOUND_RESTORE_ATTEMPTS_MAX         3
+
+/** Makes DRVHOSTDSOUND out of PDMIHOSTAUDIO. */
+#define PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface) \
+    ( (PDRVHOSTDSOUND)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTDSOUND, IHostAudio)) )
+
+
+/*********************************************************************************************************************************
+*   Structures and Typedefs                                                                                                      *
+*********************************************************************************************************************************/
 /* Dynamically load dsound.dll. */
-typedef HRESULT WINAPI FNDIRECTSOUNDENUMERATEW(LPDSENUMCALLBACKW pDSEnumCallback, LPVOID pContext);
+typedef HRESULT WINAPI FNDIRECTSOUNDENUMERATEW(LPDSENUMCALLBACKW pDSEnumCallback, PVOID pContext);
 typedef FNDIRECTSOUNDENUMERATEW *PFNDIRECTSOUNDENUMERATEW;
-typedef HRESULT WINAPI FNDIRECTSOUNDCAPTUREENUMERATEW(LPDSENUMCALLBACKW pDSEnumCallback, LPVOID pContext);
+typedef HRESULT WINAPI FNDIRECTSOUNDCAPTUREENUMERATEW(LPDSENUMCALLBACKW pDSEnumCallback, PVOID pContext);
 typedef FNDIRECTSOUNDCAPTUREENUMERATEW *PFNDIRECTSOUNDCAPTUREENUMERATEW;
 
@@ -95,6 +113,6 @@
     LPDIRECTSOUND8       pDS;     /** @todo Move this out of this structure! Not required per-stream (e.g. for multi-channel). */
     LPDIRECTSOUNDBUFFER8 pDSB;
-    DWORD                cbPlayWritePos;
-    DWORD                csPlaybackBufferSize;
+    DWORD                offPlayWritePos;
+    DWORD                cMaxSamplesInBuffer;
     bool                 fEnabled;
     bool                 fRestartPlayback;
@@ -183,26 +201,14 @@
 
 /*********************************************************************************************************************************
-*   Defines                                                                                                                      *
+*   Internal Functions                                                                                                           *
 *********************************************************************************************************************************/
-
-/** Maximum number of attempts to restore the sound buffer before giving up. */
-#define DRV_DSOUND_RESTORE_ATTEMPTS_MAX         3
-
-/** Makes DRVHOSTDSOUND out of PDMIHOSTAUDIO. */
-#define PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface) \
-    ( (PDRVHOSTDSOUND)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTDSOUND, IHostAudio)) )
-
-
-/*********************************************************************************************************************************
-*   Prototypes                                                                                                                   *
-*********************************************************************************************************************************/
-
-static HRESULT directSoundPlayRestore(PDRVHOSTDSOUND pThis, LPDIRECTSOUNDBUFFER8 pDSB);
-
-static void dsoundDeviceRemove(PDSOUNDDEV pDev);
-static int dsoundDevicesEnumerate(PDRVHOSTDSOUND pThis, PPDMAUDIOBACKENDCFG pCfg);
+static HRESULT  directSoundPlayRestore(PDRVHOSTDSOUND pThis, LPDIRECTSOUNDBUFFER8 pDSB);
+static void     dsoundDeviceRemove(PDSOUNDDEV pDev);
+static int      dsoundDevicesEnumerate(PDRVHOSTDSOUND pThis, PPDMAUDIOBACKENDCFG pCfg);
 #ifdef VBOX_WITH_AUDIO_CALLBACKS
-static int dsoundNotifyThread(PDRVHOSTDSOUND pThis, bool fShutdown);
+static int      dsoundNotifyThread(PDRVHOSTDSOUND pThis, bool fShutdown);
 #endif
+
+
 
 static DWORD dsoundRingDistance(DWORD offEnd, DWORD offBegin, DWORD cSize)
@@ -259,7 +265,7 @@
     AssertPtrReturn(pThis,         VERR_INVALID_POINTER);
     AssertPtrReturn(pDSoundStream, VERR_INVALID_POINTER);
-    /* pdwBuffer is optional. */
-    /* pdwFree is optional. */
-    /* pdwPlayPos is optional. */
+    AssertPtrNull(pdwBuffer);
+    AssertPtrNull(pdwFree);
+    AssertPtrNull(pdwPlayPos);
 
     LPDIRECTSOUNDBUFFER8 pDSB = pDSoundStream->pDSB;
@@ -267,49 +273,33 @@
         return VERR_INVALID_POINTER;
 
-    DWORD cbBuffer = AUDIOMIXBUF_S2B(&pDSoundStream->Stream.MixBuf, pDSoundStream->csPlaybackBufferSize);
-
     /* Get the current play position which is used for calculating the free space in the buffer. */
     DWORD cbPlayPos;
-
-    HRESULT hr;
+    HRESULT hr = E_FAIL;
     for (unsigned i = 0; i < DRV_DSOUND_RESTORE_ATTEMPTS_MAX; i++)
     {
         hr = IDirectSoundBuffer8_GetCurrentPosition(pDSB, &cbPlayPos, NULL);
-        if (   SUCCEEDED(hr)
-            || hr != DSERR_BUFFERLOST) /** @todo: MSDN doesn't state this error for GetCurrentPosition(). */
-        {
-            break;
-        }
-        else
-        {
-            LogFlowFunc(("Getting playing position failed due to lost buffer, restoring ...\n"));
-            directSoundPlayRestore(pThis, pDSB);
-        }
-    }
-
-    int rc = VINF_SUCCESS;
-
-    if (FAILED(hr))
-    {
-        if (hr != DSERR_BUFFERLOST) /* Avoid log flooding if the error is still there. */
-            DSLOGREL(("DSound: Getting current playback position failed with %Rhrc\n", hr));
-        LogFlowFunc(("Failed with %Rhrc\n", hr));
-
-        rc = VERR_NOT_AVAILABLE;
-    }
-    else
-    {
-        if (pdwBuffer)
-            *pdwBuffer = cbBuffer;
-
-        if (pdwFree)
-            *pdwFree = cbBuffer - dsoundRingDistance(pDSoundStream->cbPlayWritePos, cbPlayPos, cbBuffer);
-
-        if (pdwPlayPos)
-            *pdwPlayPos = cbPlayPos;
-    }
-
-    if (RT_FAILURE(rc))
-        LogFlowFuncLeaveRC(rc);
+        if (SUCCEEDED(hr))
+        {
+            DWORD const cbBuffer = AUDIOMIXBUF_S2B(&pDSoundStream->Stream.MixBuf, pDSoundStream->cMaxSamplesInBuffer);
+            if (pdwBuffer)
+                *pdwBuffer  = cbBuffer;
+            if (pdwFree)
+                *pdwFree    = cbBuffer - dsoundRingDistance(pDSoundStream->offPlayWritePos, cbPlayPos, cbBuffer);
+            if (pdwPlayPos)
+                *pdwPlayPos = cbPlayPos;
+            return VINF_SUCCESS;
+        }
+        if (hr != DSERR_BUFFERLOST) /** @todo MSDN doesn't state this error for GetCurrentPosition(). */
+            break;
+        LogFlowFunc(("Getting playing position failed due to lost buffer, restoring ...\n"));
+        directSoundPlayRestore(pThis, pDSB);
+    }
+
+    if (hr != DSERR_BUFFERLOST) /* Avoid log flooding if the error is still there. */
+        DSLOGREL(("DSound: Getting current playback position failed with %Rhrc\n", hr));
+    LogFlowFunc(("Failed with %Rhrc\n", hr));
+
+    int rc = VERR_NOT_AVAILABLE;
+    LogFlowFuncLeaveRC(rc);
     return rc;
 }
@@ -359,4 +349,5 @@
 static HRESULT directSoundPlayRestore(PDRVHOSTDSOUND pThis, LPDIRECTSOUNDBUFFER8 pDSB)
 {
+    RT_NOREF(pThis);
     HRESULT hr = IDirectSoundBuffer8_Restore(pDSB);
     if (FAILED(hr))
@@ -366,7 +357,8 @@
 
 static HRESULT directSoundPlayUnlock(PDRVHOSTDSOUND pThis, LPDIRECTSOUNDBUFFER8 pDSB,
-                                     LPVOID pv1, LPVOID pv2,
+                                     PVOID pv1, PVOID pv2,
                                      DWORD cb1, DWORD cb2)
 {
+    RT_NOREF(pThis);
     HRESULT hr = IDirectSoundBuffer8_Unlock(pDSB, pv1, cb1, pv2, cb2);
     if (FAILED(hr))
@@ -376,5 +368,5 @@
 
 static HRESULT directSoundCaptureUnlock(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB,
-                                        LPVOID pv1, LPVOID pv2,
+                                        PVOID pv1, PVOID pv2,
                                         DWORD cb1, DWORD cb2)
 {
@@ -388,58 +380,45 @@
                                    LPDIRECTSOUNDBUFFER8 pDSB, PDMPCMPROPS *pProps,
                                    DWORD dwOffset, DWORD dwBytes,
-                                   LPVOID *ppv1, LPVOID *ppv2,
+                                   PVOID *ppv1, PVOID *ppv2,
                                    DWORD *pcb1, DWORD *pcb2,
                                    DWORD dwFlags)
 {
-    LPVOID pv1 = NULL;
-    LPVOID pv2 = NULL;
-    DWORD cb1 = 0;
-    DWORD cb2 = 0;
-
-    HRESULT hr;
+    HRESULT hr = E_FAIL;
+    AssertCompile(DRV_DSOUND_RESTORE_ATTEMPTS_MAX > 0);
     for (unsigned i = 0; i < DRV_DSOUND_RESTORE_ATTEMPTS_MAX; i++)
     {
-        hr = IDirectSoundBuffer8_Lock(pDSB, dwOffset, dwBytes, &pv1, &cb1, &pv2, &cb2, dwFlags);
-        if (   SUCCEEDED(hr)
-            || hr != DSERR_BUFFERLOST)
-            break;
-        else
-        {
-            LogFlowFunc(("Locking failed due to lost buffer, restoring ...\n"));
-            directSoundPlayRestore(pThis, pDSB);
-        }
-    }
-
-    if (FAILED(hr))
-    {
-        DSLOGREL(("DSound: Locking playback buffer failed with %Rhrc\n", hr));
-        return hr;
-    }
-
-    if (   (pv1 && (cb1 & pProps->uAlign))
-        || (pv2 && (cb2 & pProps->uAlign)))
-    {
-        DSLOGREL(("DSound: Locking playback buffer returned misaligned buffer: cb1=%RI32, cb2=%RI32 (alignment: %RU32)\n",
-                  cb1, cb2, pProps->uAlign));
-        directSoundPlayUnlock(pThis, pDSB, pv1, pv2, cb1, cb2);
-        return E_FAIL;
-    }
-
-    *ppv1 = pv1;
-    *ppv2 = pv2;
-    *pcb1 = cb1;
-    *pcb2 = cb2;
-
-    return S_OK;
+        *ppv1 = *ppv2 = NULL;
+        *pcb1 = *pcb2 = 0;
+        hr = IDirectSoundBuffer8_Lock(pDSB, dwOffset, dwBytes, ppv1, pcb1, ppv2, pcb2, dwFlags);
+        if (SUCCEEDED(hr))
+        {
+            if (   (!*ppv1 || !(*pcb1 & pProps->uAlign))
+                && (!*ppv2 || !(*pcb2 & pProps->uAlign)) )
+                return S_OK;
+            DSLOGREL(("DSound: Locking playback buffer returned misaligned buffer: cb1=%#RX32, cb2=%#RX32 (alignment: %#RX32)\n",
+                      *pcb1, *pcb2, pProps->uAlign));
+            directSoundPlayUnlock(pThis, pDSB, *ppv1, *ppv2, *pcb1, *pcb2);
+            return E_FAIL;
+        }
+
+        if (hr != DSERR_BUFFERLOST)
+            break;
+
+        LogFlowFunc(("Locking failed due to lost buffer, restoring ...\n"));
+        directSoundPlayRestore(pThis, pDSB);
+    }
+
+    DSLOGREL(("DSound: Locking playback buffer failed with %Rhrc\n", hr));
+    return hr;
 }
 
 static HRESULT directSoundCaptureLock(LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB, PPDMPCMPROPS pProps,
                                       DWORD dwOffset, DWORD dwBytes,
-                                      LPVOID *ppv1, LPVOID *ppv2,
+                                      PVOID *ppv1, PVOID *ppv2,
                                       DWORD *pcb1, DWORD *pcb2,
                                       DWORD dwFlags)
 {
-    LPVOID pv1 = NULL;
-    LPVOID pv2 = NULL;
+    PVOID pv1 = NULL;
+    PVOID pv2 = NULL;
     DWORD cb1 = 0;
     DWORD cb2 = 0;
@@ -628,5 +607,5 @@
 
         /* "Upgrade" to IDirectSoundBuffer8 interface. */
-        hr = IDirectSoundBuffer_QueryInterface(pDSB, IID_IDirectSoundBuffer8, (LPVOID *)&pDSoundStream->pDSB);
+        hr = IDirectSoundBuffer_QueryInterface(pDSB, IID_IDirectSoundBuffer8, (PVOID *)&pDSoundStream->pDSB);
         IDirectSoundBuffer_Release(pDSB);
         if (FAILED(hr))
@@ -689,6 +668,6 @@
          * playback buffer position.
          */
-        pDSoundStream->csPlaybackBufferSize = bc.dwBufferBytes >> pDSoundStream->Stream.Props.cShift;
-        DSLOG(("DSound: csPlaybackBufferSize=%RU32\n", pDSoundStream->csPlaybackBufferSize));
+        pDSoundStream->cMaxSamplesInBuffer = bc.dwBufferBytes >> pDSoundStream->Stream.Props.cShift;
+        DSLOG(("DSound: cMaxSamplesInBuffer=%RU32\n", pDSoundStream->cMaxSamplesInBuffer));
 
 #ifdef VBOX_WITH_AUDIO_CALLBACKS
@@ -707,5 +686,5 @@
 
         LPDIRECTSOUNDNOTIFY8 pNotify;
-        hr = IDirectSoundNotify_QueryInterface(pDSoundStream->pDSB, IID_IDirectSoundNotify8, (LPVOID *)&pNotify);
+        hr = IDirectSoundNotify_QueryInterface(pDSoundStream->pDSB, IID_IDirectSoundNotify8, (PVOID *)&pNotify);
         if (SUCCEEDED(hr))
         {
@@ -754,8 +733,8 @@
     PPDMAUDIOSTREAM pStream = &pDSoundStream->Stream;
 
-    LPVOID pv1, pv2;
+    PVOID pv1, pv2;
     DWORD cb1, cb2;
     HRESULT hr = directSoundPlayLock(pThis, pDSoundStream->pDSB, &pDSoundStream->Stream.Props,
-                                     0 /* dwOffset */, AUDIOMIXBUF_S2B(&pStream->MixBuf, pDSoundStream->csPlaybackBufferSize),
+                                     0 /* dwOffset */, AUDIOMIXBUF_S2B(&pStream->MixBuf, pDSoundStream->cMaxSamplesInBuffer),
                                      &pv1, &pv2, &cb1, &cb2, DSBLOCK_ENTIREBUFFER);
     if (SUCCEEDED(hr))
@@ -778,9 +757,8 @@
     AssertPtrReturn(pThis, E_POINTER);
     AssertPtrReturn(pDSB,  E_POINTER);
-    /* pdwStatus is optional. */
+    AssertPtrNull(pdwStatus);
 
     DWORD dwStatus = 0;
-
-    HRESULT hr;
+    HRESULT hr = E_FAIL;
     for (unsigned i = 0; i < DRV_DSOUND_RESTORE_ATTEMPTS_MAX; i++)
     {
@@ -1282,5 +1260,5 @@
 
 static BOOL CALLBACK dsoundDevicesEnumCbPlayback(LPGUID lpGUID, LPCWSTR lpwstrDescription,
-                                                 LPCWSTR lpwstrModule, LPVOID lpContext)
+                                                 LPCWSTR lpwstrModule, PVOID lpContext)
 {
     PDSOUNDENUMCBCTX pCtx = (PDSOUNDENUMCBCTX)lpContext;
@@ -1308,5 +1286,5 @@
 
 static BOOL CALLBACK dsoundDevicesEnumCbCapture(LPGUID lpGUID, LPCWSTR lpwstrDescription,
-                                                LPCWSTR lpwstrModule, LPVOID lpContext)
+                                                LPCWSTR lpwstrModule, PVOID lpContext)
 {
     PDSOUNDENUMCBCTX pCtx = (PDSOUNDENUMCBCTX)lpContext;
@@ -1458,7 +1436,7 @@
         pDSoundStream->pDS = NULL;
         pDSoundStream->pDSB = NULL;
-        pDSoundStream->cbPlayWritePos = 0;
+        pDSoundStream->offPlayWritePos = 0;
         pDSoundStream->fRestartPlayback = true;
-        pDSoundStream->csPlaybackBufferSize = 0;
+        pDSoundStream->cMaxSamplesInBuffer = 0;
 
         if (pcSamples)
@@ -1560,5 +1538,5 @@
 
         /*
-         * Check for full buffer, do not allow the cbPlayWritePos to catch cbPlayPos during playback,
+         * Check for full buffer, do not allow the offPlayWritePos to catch cbPlayPos during playback,
          * i.e. always leave a free space for 1 audio sample.
          */
@@ -1573,10 +1551,9 @@
         /* Do not write more than available space in the DirectSound playback buffer. */
         cbLive = RT_MIN(cbFree, cbLive);
-
         cbLive &= ~pStream->Props.uAlign;
         if (cbLive == 0 || cbLive > cbBuffer)
         {
-            DSLOG(("DSound: cbLive=%RU32, cbBuffer=%ld, cbPlayWritePos=%ld, cbPlayPos=%ld\n",
-                   cbLive, cbBuffer, pDSoundStream->cbPlayWritePos, cbPlayPos));
+            DSLOG(("DSound: cbLive=%RU32, cbBuffer=%ld, offPlayWritePos=%ld, cbPlayPos=%ld\n",
+                   cbLive, cbBuffer, pDSoundStream->offPlayWritePos, cbPlayPos));
             break;
         }
@@ -1585,7 +1562,7 @@
         AssertPtr(pDSB);
 
-        LPVOID pv1, pv2;
+        PVOID pv1, pv2;
         DWORD cb1, cb2;
-        HRESULT hr = directSoundPlayLock(pThis, pDSB, &pStream->Props, pDSoundStream->cbPlayWritePos, cbLive,
+        HRESULT hr = directSoundPlayLock(pThis, pDSB, &pStream->Props, pDSoundStream->offPlayWritePos, cbLive,
                                          &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */);
         if (FAILED(hr))
@@ -1595,7 +1572,8 @@
         }
 
-        DWORD len1 = AUDIOMIXBUF_B2S(&pStream->MixBuf, cb1);
-        DWORD len2 = AUDIOMIXBUF_B2S(&pStream->MixBuf, cb2);
-
+        /** @todo r=bird: Can pv1/cb1 really be NULL? Docs says they're always set
+         *        and pv2/cb2 only used when there is a buffer wrap araound. */
+
+        DWORD cSamplesIn1 = AUDIOMIXBUF_B2S(&pStream->MixBuf, cb1);
         uint32_t cRead = 0;
 
@@ -1608,5 +1586,5 @@
 
         if (   RT_SUCCESS(rc)
-            && cReadTotal == len1
+            && cReadTotal == cSamplesIn1
             && pv2 && cb2)
         {
@@ -1618,11 +1596,11 @@
         directSoundPlayUnlock(pThis, pDSB, pv1, pv2, cb1, cb2);
 
-        pDSoundStream->cbPlayWritePos =
-            (pDSoundStream->cbPlayWritePos + AUDIOMIXBUF_S2B(&pStream->MixBuf, cReadTotal)) % cbBuffer;
+        pDSoundStream->offPlayWritePos = (pDSoundStream->offPlayWritePos + AUDIOMIXBUF_S2B(&pStream->MixBuf, cReadTotal))
+                                       % cbBuffer;
 
         DSLOGF(("DSound: %RU32 (%RU32 samples) out of %RU32%s, buffer write pos %ld, rc=%Rrc\n",
                 AUDIOMIXBUF_S2B(&pStream->MixBuf, cReadTotal), cReadTotal, cbLive,
                 cbLive != AUDIOMIXBUF_S2B(&pStream->MixBuf, cReadTotal) ? " !!!": "",
-                pDSoundStream->cbPlayWritePos, rc));
+                pDSoundStream->offPlayWritePos, rc));
 
         if (cReadTotal)
@@ -1672,12 +1650,7 @@
 
     if (RT_FAILURE(rc))
-    {
         dsoundUpdateStatusInternal(pThis);
-    }
-    else
-    {
-        if (pcSamplesPlayed)
-            *pcSamplesPlayed = cReadTotal;
-    }
+    else if (pcSamplesPlayed)
+        *pcSamplesPlayed = cReadTotal;
 
     LogFlowFuncLeaveRC(rc);
@@ -1692,7 +1665,7 @@
     directSoundPlayClose(pThis, pDSoundStream);
 
-    pDSoundStream->cbPlayWritePos       = 0;
+    pDSoundStream->offPlayWritePos      = 0;
     pDSoundStream->fRestartPlayback     = true;
-    pDSoundStream->csPlaybackBufferSize = 0;
+    pDSoundStream->cMaxSamplesInBuffer  = 0;
 
     RT_ZERO(pDSoundStream->streamCfg);
@@ -1862,5 +1835,5 @@
 
         /* Lock relevant range in the DirectSound capture buffer. */
-        LPVOID pv1, pv2;
+        PVOID pv1, pv2;
         DWORD cb1, cb2;
         hr = directSoundCaptureLock(pDSCB, &pStream->Props,
@@ -1926,5 +1899,5 @@
 static int dsoundDestroyStreamIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
 {
-    PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface);
+    RT_NOREF(pInterface);
     PDSOUNDSTREAMIN pDSoundStream = (PDSOUNDSTREAMIN)pStream;
 
@@ -2078,5 +2051,7 @@
         CloseHandle(pThis->aEvents[DSOUNDEVENT_NOTIFY]);
         pThis->aEvents[DSOUNDEVENT_NOTIFY] = NULL;
-}
+    }
+#else
+    RT_NOREF_PV(pThis);
 #endif
 
@@ -2191,4 +2166,5 @@
 static DECLCALLBACK(PDMAUDIOBACKENDSTS) drvHostDSoundGetStatus(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
 {
+    RT_NOREF(enmDir);
     AssertPtrReturn(pInterface, PDMAUDIOBACKENDSTS_UNKNOWN);
 
@@ -2279,4 +2255,5 @@
 }
 
+
 static DECLCALLBACK(int) drvHostDSoundStreamIterate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
 {
@@ -2290,4 +2267,8 @@
 }
 
+
+/**
+ * @callback_method_impl{FNPDMDRVDESTRUCT, pfnDestruct}
+ */
 static DECLCALLBACK(void) drvHostDSoundDestruct(PPDMDRVINS pDrvIns)
 {
@@ -2302,11 +2283,12 @@
 }
 
+
 /**
- * Construct a DirectSound Audio driver instance.
- *
- * @copydoc FNPDMDRVCONSTRUCT
+ * @callback_method_impl{FNPDMDRVCONSTRUCT,
+ *      Construct a DirectSound Audio driver instance.}
  */
 static DECLCALLBACK(int) drvHostDSoundConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
 {
+    RT_NOREF(fFlags);
     PDRVHOSTDSOUND pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTDSOUND);
 
