[Scummvm-git-logs] scummvm master -> 31ee298a69e4c2249bc7e43f39c4cd252e9e114a

mikrosk noreply at scummvm.org
Tue Jun 23 09:45:35 UTC 2026


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
31ee298a69 AUDIO: Don't clamp muted channels


Commit: 31ee298a69e4c2249bc7e43f39c4cd252e9e114a
    https://github.com/scummvm/scummvm/commit/31ee298a69e4c2249bc7e43f39c4cd252e9e114a
Author: Miro Kropacek (miro.kropacek at gmail.com)
Date: 2026-06-23T19:42:16+10:00

Commit Message:
AUDIO: Don't clamp muted channels

Changed paths:
    audio/mixer.cpp


diff --git a/audio/mixer.cpp b/audio/mixer.cpp
index 0f6ab5298e9..f48f1c1021f 100644
--- a/audio/mixer.cpp
+++ b/audio/mixer.cpp
@@ -143,6 +143,11 @@ public:
 	 */
 	uint8 getFaderR() const;
 
+	/**
+	 * Queries whether the channel is silent, i.e. will produce no audio output.
+	 */
+	bool isSilent() const { return _volL == 0 && _volR == 0; }
+
 	/**
 	 * Set the channel's sample rate.
 	 *
@@ -346,15 +351,13 @@ int MixerImpl::mixCallback(byte *samples, uint len) {
 	// Since the mixer callback has been called, the mixer must be ready...
 	_mixerReady = true;
 
-	// zero the sample buffer
-	memset(samples, 0, len);
-
 	// we store samples of size defined by the backend
 	const uint bytesPerFrame = _outBytesPerSample * (_stereo ? 2 : 1);
 	assert(len % bytesPerFrame == 0);
-	len /= bytesPerFrame;
+	const uint numFrames = len / bytesPerFrame;
 
-	// mix all channels
+	// mix all channels, zeroing the buffer lazily on first non-silent channel
+	bool zeroed = false;
 	int res = 0, tmp;
 	for (int i = 0; i != NUM_CHANNELS; i++)
 		if (_channels[i]) {
@@ -362,13 +365,25 @@ int MixerImpl::mixCallback(byte *samples, uint len) {
 				delete _channels[i];
 				_channels[i] = nullptr;
 			} else if (!_channels[i]->isPaused()) {
-				tmp = _channels[i]->mix(samples, len);
+				if (!_channels[i]->isSilent() && !zeroed) {
+					memset(samples, 0, len);
+					zeroed = true;
+				}
+				tmp = _channels[i]->mix(samples, numFrames);
 
 				if (tmp > res)
 					res = tmp;
 			}
 		}
 
+	if (!zeroed) {
+		if (_clamp) {
+			memset(samples, 0, len);
+		} else {
+			// optimization: let the caller know that there's nothing to clamp
+			res = 0;
+		}
+	}
 	return res;
 }
 




More information about the Scummvm-git-logs mailing list