From c7de726785398c4c936b8d7303b9541c8ed66298 Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Sun, 21 Dec 2008 19:27:28 +0000 Subject: [PATCH] dsound: correct the dsound fraglen calculations. --- dlls/dsound/primary.c | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index 661cd8c..50ae7e6 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -46,13 +46,25 @@ WINE_DEFAULT_DEBUG_CHANNEL(dsound); */ DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign) { - DWORD fraglen = 256 * nBlockAlign; - - /* Compensate for only being roughly accurate */ - if (nSamplesPerSec <= 26000) + DWORD fraglen = 512 * nBlockAlign; + + /* Given a timer delay of 10ms, the fragment size is approximately: + * fraglen = (nSamplesPerSecond * 10 / 1000) * nBlockAlign + * ==> fraglen = (nSamplesPerSecond / 100) * nBlockSize + * + * ALSA uses buffers that are powers of 2, so approximate the size for a + * given nSamplesPerSecond. + * (nSamplesPerSecond / 100) < 120 ==> power of 2 = 128 + * (nSamplesPerSecond / 100) < 250 ==> power of 2 = 256 + * (nSamplesPerSecond / 100) < 800 ==> power of 2 = 512 + * (nSamplesPerSecond / 100) > 800 ==> power of 2 = 1024 + * therefore, adjust the buffer accordingly: + */ + + if (nSamplesPerSec <= 12000) fraglen /= 2; - if (nSamplesPerSec <= 10000) + if (nSamplesPerSec <= 25000) fraglen /= 2; if (nSamplesPerSec >= 80000) -- 1.6.0.4