dsound: Correct the dsound fraglen calculations.
authorReece Dunn <msclrhd@googlemail.com>
Mon, 22 Dec 2008 13:33:43 +0000 (13:33 +0000)
committerAlexandre Julliard <julliard@winehq.org>
Mon, 22 Dec 2008 13:56:19 +0000 (14:56 +0100)
dlls/dsound/primary.c

index 661cd8ca0482377d3c0d1c2161f5b21121ae3c88..5812f0086f0b03b5dd064e9d66952540445ff8e6 100644 (file)
@@ -46,19 +46,24 @@ WINE_DEFAULT_DEBUG_CHANNEL(dsound);
  */
 DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign)
 {
-    DWORD fraglen = 256 * 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:
+     */
 
-    /* Compensate for only being roughly accurate */
-    if (nSamplesPerSec <= 26000)
-        fraglen /= 2;
+    if (nSamplesPerSec <= 12800)
+        return 128 * nBlockAlign;
 
-    if (nSamplesPerSec <= 10000)
-        fraglen /= 2;
+    if (nSamplesPerSec <= 25600)
+        return 256 * nBlockAlign;
 
-    if (nSamplesPerSec >= 80000)
-        fraglen *= 2;
+    if (nSamplesPerSec <= 51200)
+        return 512 * nBlockAlign;
 
-    return fraglen;
+    return 1024 * nBlockAlign;
 }
 
 static void DSOUND_RecalcPrimary(DirectSoundDevice *device)