Index: trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp	(revision 61342)
+++ trunk/src/VBox/Devices/Audio/AudioMixBuffer.cpp	(revision 61343)
@@ -42,4 +42,6 @@
 #include <iprt/mem.h>
 #include <iprt/string.h> /* For RT_BZERO. */
+
+#define VBOX_AUDIO_TESTCASE
 
 #ifdef VBOX_AUDIO_TESTCASE
@@ -1616,20 +1618,15 @@
 {
     AssertPtrReturn(pMixBuf, VERR_INVALID_POINTER);
-    AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
+    AssertPtrReturn(pvBuf,   VERR_INVALID_POINTER);
     /* pcWritten is optional. */
 
-    uint32_t cDstSamples = pMixBuf->pParent
-                         ? pMixBuf->pParent->cSamples : pMixBuf->cSamples;
-    uint32_t cLive = pMixBuf->cUsed;
-
-    uint32_t cDead = cDstSamples - cLive;
-    uint32_t cToProcess = (uint32_t)AUDIOMIXBUF_S2S_RATIO(pMixBuf, cDead);
-    cToProcess = RT_MIN(cToProcess, AUDIOMIXBUF_B2S(pMixBuf, cbBuf));
-
-    AUDMIXBUF_LOG(("%s: offSamples=%RU32, cLive=%RU32, cDead=%RU32, cToProcess=%RU32\n",
-                   pMixBuf->pszName, offSamples, cLive, cDead, cToProcess));
-
-    if (offSamples + cToProcess > pMixBuf->cSamples)
-        return VERR_BUFFER_OVERFLOW;
+    uint32_t cToWrite = AUDIOMIXBUF_B2S(pMixBuf, cbBuf);
+
+    int rc = VINF_SUCCESS;
+
+    if (offSamples + cToWrite > pMixBuf->cSamples)
+        rc = VINF_BUFFER_OVERFLOW;
+
+    cToWrite = RT_MIN(cToWrite, pMixBuf->cSamples - offSamples);
 
     PPDMAUDMIXBUF_FN_CONVFROM pConv;
@@ -1643,35 +1640,37 @@
 
     if (!pConv)
-        return VERR_NOT_SUPPORTED;
-
-    int rc;
+        rc = VERR_NOT_SUPPORTED;
+
     uint32_t cWritten;
 
 #ifdef AUDIOMIXBUF_DEBUG_DUMP_PCM_DATA
     RTFILE fh;
-    rc = RTFileOpen(&fh, AUDIOMIXBUF_DEBUG_DUMP_PCM_DATA_PATH "mixbuf_writeat.pcm",
-                    RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
-    if (RT_SUCCESS(rc))
-    {
-        RTFileWrite(fh, pvBuf, cbBuf, NULL);
+    int rc2 = RTFileOpen(&fh, AUDIOMIXBUF_DEBUG_DUMP_PCM_DATA_PATH "mixbuf_writeat.pcm",
+                         RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
+    if (RT_SUCCESS(rc2))
+    {
+        RTFileWrite(fh, pvBuf, AUDIOMIXBUF_S2B(pMixBuf, cToWrite), NULL);
         RTFileClose(fh);
     }
 #endif
 
-    if (cToProcess)
-    {
-        PDMAUDMIXBUF_CONVOPTS convOpts = { cToProcess, pMixBuf->Volume };
-
-        cWritten = pConv(pMixBuf->pSamples + offSamples, pvBuf, cbBuf, &convOpts);
+    if (   pConv
+        && cToWrite)
+    {
+        PDMAUDMIXBUF_CONVOPTS convOpts = { cToWrite, pMixBuf->Volume };
+
+        cWritten = pConv(pMixBuf->pSamples + offSamples, pvBuf, AUDIOMIXBUF_S2B(pMixBuf, cToWrite), &convOpts);
+    }
+    else
+        cWritten = 0;
+
 #ifdef DEBUG
-        audioMixBufDbgPrintInternal(pMixBuf);
-#endif
-        rc = cWritten ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Fudge! */
-    }
-    else
-    {
-        cWritten = 0;
-        rc = VINF_SUCCESS;
-    }
+    audioMixBufDbgPrintInternal(pMixBuf);
+#endif
+
+    AUDMIXBUF_LOG(("%s: offSamples=%RU32, cbBuf=%RU32, cToWrite=%RU32 (%zu bytes), cWritten=%RU32 (%zu bytes), rc=%Rrc\n",
+                   pMixBuf->pszName, offSamples, cbBuf,
+                   cToWrite, AUDIOMIXBUF_S2B(pMixBuf, cToWrite),
+                   cWritten, AUDIOMIXBUF_S2B(pMixBuf, cWritten), rc));
 
     if (RT_SUCCESS(rc))
@@ -1681,5 +1680,4 @@
     }
 
-    AUDMIXBUF_LOG(("cWritten=%RU32, rc=%Rrc\n", cWritten, rc));
     return rc;
 }
Index: trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp	(revision 61342)
+++ trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp	(revision 61343)
@@ -139,5 +139,6 @@
 static int tstParentChild(RTTEST hTest)
 {
-    uint32_t cBufSize = RTRandU32() % 256;
+    uint32_t cSamples = 16;
+    uint32_t cBufSize = RTRandU32Ex(cSamples /* Min */, 256 /* Max */);
 
     PDMAUDIOSTREAMCFG cfg_p =
@@ -205,11 +206,11 @@
     uint32_t cChild1Free     = cBufSize;
     uint32_t cChild1Mixed    = 0;
-    uint32_t cSamplesParent1 = 16;
-    uint32_t cSamplesChild1  = 16;
+    uint32_t cSamplesParent1 = cSamples;
+    uint32_t cSamplesChild1  = cSamples;
 
     uint32_t cChild2Free     = cBufSize;
     uint32_t cChild2Mixed    = 0;
-    uint32_t cSamplesParent2 = 16;
-    uint32_t cSamplesChild2  = 16;
+    uint32_t cSamplesParent2 = cSamples;
+    uint32_t cSamplesChild2  = cSamples;
 
     uint32_t t = RTRandU32() % 1024;
