From 092d2e62f138c7d5040f31ea0d3c2342b969dc4e Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Sun, 21 Dec 2008 21:07:31 +0000 Subject: [PATCH] dsound: correct the dsound fraglen calculations. --- dlls/dsound/primary.c | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-) diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index 661cd8c..2c52d95 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -46,17 +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, the fraglen + * is rounded up to the nearest power of 2: + */ - /* Compensate for only being roughly accurate */ - if (nSamplesPerSec <= 26000) - fraglen /= 2; + DWORD fraglen = 1024 * nBlockAlign; /* power = 1024 */ - if (nSamplesPerSec <= 10000) - fraglen /= 2; + if (nSamplesPerSec <= 51200) + fraglen /= 2; /* power = 512 */ - if (nSamplesPerSec >= 80000) - fraglen *= 2; + if (nSamplesPerSec <= 25600) + fraglen /= 2; /* power = 256 */ + + if (nSamplesPerSec <= 12800) + fraglen /= 2; /* power = 128 */ return fraglen; } -- 1.6.0.4