dsound: Give rougher estimates for fraglen to satisfy alsa
Maarten Lankhorst
m.b.lankhorst at gmail.com
Thu Jun 21 13:40:01 CDT 2007
Alsa works with power of two pointer advancements, so to better optimize
for it just make fraglen power of 2 if possible too.
-------------- next part --------------
>From 4dc21128de6e9440a5b6a3366bce068f06193135 Mon Sep 17 00:00:00 2001
From: Maarten Lankhorst <m.b.lankhorst at gmail.com>
Date: Fri, 8 Jun 2007 13:57:51 +0200
Subject: [PATCH] dsound: Give rougher estimates for fraglen to satisfy alsa
---
dlls/dsound/primary.c | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c
index f229757..3e3fce4 100644
--- a/dlls/dsound/primary.c
+++ b/dlls/dsound/primary.c
@@ -44,8 +44,20 @@ static void DSOUND_RecalcPrimary(DirectSoundDevice *device)
nBlockAlign = device->pwfx->nBlockAlign;
if (device->hwbuf) {
DWORD fraglen;
- /* let fragment size approximate the timer delay */
- fraglen = (device->pwfx->nSamplesPerSec * DS_TIME_DEL / 1000) * nBlockAlign;
+ /* Alsa doesn't have continuous buffers, instead it has buffers with power of 2,
+ * If DS_TIME_DEL is about 10 ms, 512 * nBlockAlign is roughly correct */
+ fraglen = 512 * nBlockAlign;
+
+ /* Compensate for only being rougly accurate */
+ if (device->pwfx->nSamplesPerSec <= 26000)
+ fraglen /= 2;
+
+ if (device->pwfx->nSamplesPerSec <= 12000)
+ fraglen /= 2;
+
+ if (device->pwfx->nSamplesPerSec >= 80000)
+ fraglen *= 2;
+
/* reduce fragment size until an integer number of them fits in the buffer */
/* (FIXME: this may or may not be a good idea) */
while (device->buflen % fraglen) fraglen -= nBlockAlign;
--
1.4.4.2
More information about the wine-patches
mailing list