[PATCH 2/2] dsound: Skip resampling/mixing inaudible buffers.

Florian Will florian.will at gmail.com
Thu Dec 2 09:37:08 CST 2021


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>
---
There is space indentation at the top of the patch and tab indentation
at the bottom, but that matches surrounding code.
---
 dlls/dsound/mixer.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

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 &&
-- 
2.32.0




More information about the wine-devel mailing list