Florian Will : dsound: Skip resampling/mixing inaudible buffers.

Alexandre Julliard julliard at winehq.org
Mon Dec 6 16:08:00 CST 2021


Module: wine
Branch: master
Commit: 835dfaab023175028161974c5cd8585b77df101c
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=835dfaab023175028161974c5cd8585b77df101c

Author: Florian Will <florian.will at gmail.com>
Date:   Mon Dec  6 13:08:24 2021 -0600

dsound: Skip resampling/mixing inaudible buffers.

In some situations, "ZUSI 3" has a lot of secondary buffers in the
PLAYING state, but most of these buffers have a really low volume, so
these buffers are multiplied by 0 before mixing (and possibly after
resampling). There can be hundreds of inaudible buffers at the same
time.

In these situations, the dsound mixthread is unable to mix fast enough,
resulting in sound stuttering and generally poor performance.

To resolve this performance issue, skip the mixing (and possibly
resampling) step for all inaudible secondary buffers.

Signed-off-by: Florian Will <florian.will at gmail.com>
Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dsound/buffer.c         | 11 +++++++++++
 dlls/dsound/dsound_private.h |  1 +
 dlls/dsound/mixer.c          | 18 +++++++++++++-----
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c
index c595b19dd63..9084ccd9928 100644
--- a/dlls/dsound/buffer.c
+++ b/dlls/dsound/buffer.c
@@ -1197,6 +1197,17 @@ void secondarybuffer_destroy(IDirectSoundBufferImpl *This)
     TRACE("(%p) released\n", This);
 }
 
+BOOL secondarybuffer_is_audible(IDirectSoundBufferImpl *This)
+{
+    UINT i;
+    for (i = 0; i < This->device->pwfx->nChannels; i++) {
+        if (This->volpan.dwTotalAmpFactor[i] != 0)
+            return TRUE;
+    }
+
+   return FALSE;
+}
+
 HRESULT IDirectSoundBufferImpl_Duplicate(
     DirectSoundDevice *device,
     IDirectSoundBufferImpl **ppdsb,
diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h
index 9ec96504a50..18dc369db5c 100644
--- a/dlls/dsound/dsound_private.h
+++ b/dlls/dsound/dsound_private.h
@@ -193,6 +193,7 @@ HRESULT IDirectSoundBufferImpl_Duplicate(
     IDirectSoundBufferImpl **ppdsb,
     IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
 void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
+BOOL secondarybuffer_is_audible(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
 extern const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN;
 extern const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN;
 extern const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN;
diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c
index e9d8a6e3cdd..d28cc8dc5aa 100644
--- a/dlls/dsound/mixer.c
+++ b/dlls/dsound/mixer.c
@@ -290,6 +290,9 @@ static UINT cp_fields_noresample(IDirectSoundBufferImpl *dsb, UINT count)
     UINT committed_samples = 0;
     DWORD channel, i;
 
+    if (!secondarybuffer_is_audible(dsb))
+        return count;
+
     if(dsb->use_committed) {
         committed_samples = (dsb->writelead - dsb->committed_mixpos) / istride;
         committed_samples = committed_samples <= count ? committed_samples : count;
@@ -329,6 +332,11 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 *
     len += fir_cachesize;
     len *= sizeof(float);
 
+    *freqAccNum = freqAcc_end % dsb->freqAdjustDen;
+
+    if (!secondarybuffer_is_audible(dsb))
+        return max_ipos;
+
     if (!dsb->device->cp_buffer) {
         dsb->device->cp_buffer = HeapAlloc(GetProcessHeap(), 0, len);
         dsb->device->cp_buffer_len = len;
@@ -386,8 +394,6 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 *
         }
     }
 
-    *freqAccNum = freqAcc_end % dsb->freqAdjustDen;
-
     return max_ipos;
 }
 
@@ -535,10 +541,12 @@ static DWORD DSOUND_MixInBuffer(IDirectSoundBufferImpl *dsb, float *mix_buffer,
 	DSOUND_MixToTemporary(dsb, frames);
 	ibuf = dsb->device->tmp_buffer;
 
-	/* Apply volume if needed */
-	DSOUND_MixerVol(dsb, frames);
+	if (secondarybuffer_is_audible(dsb)) {
+		/* Apply volume if needed */
+		DSOUND_MixerVol(dsb, frames);
 
-	mixieee32(ibuf, mix_buffer, frames * dsb->device->pwfx->nChannels);
+		mixieee32(ibuf, mix_buffer, frames * dsb->device->pwfx->nChannels);
+	}
 
 	/* check for notification positions */
 	if (dsb->dsbd.dwFlags & DSBCAPS_CTRLPOSITIONNOTIFY &&




More information about the wine-cvs mailing list