[Scummvm-git-logs] scummvm master -> 3e220fd3f3bbbf6213dec543d794b8fb9fb5021e

NMIError noreply at scummvm.org
Wed Sep 24 20:13:17 UTC 2025


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:
3e220fd3f3 AUDIO: Improve AdLib additive operator volume handling


Commit: 3e220fd3f3bbbf6213dec543d794b8fb9fb5021e
    https://github.com/scummvm/scummvm/commit/3e220fd3f3bbbf6213dec543d794b8fb9fb5021e
Author: Coen Rampen (crampen at gmail.com)
Date: 2025-09-24T22:13:10+02:00

Commit Message:
AUDIO: Improve AdLib additive operator volume handling

Changed paths:
    audio/adlib_ctmidi.cpp
    audio/adlib_ms.cpp
    audio/adlib_ms.h


diff --git a/audio/adlib_ctmidi.cpp b/audio/adlib_ctmidi.cpp
index 30e802795d0..8c6fdbaa1cc 100644
--- a/audio/adlib_ctmidi.cpp
+++ b/audio/adlib_ctmidi.cpp
@@ -375,7 +375,6 @@ MidiDriver_ADLIB_CTMIDI::MidiDriver_ADLIB_CTMIDI(OPL::Config::OplType oplType, i
 	_modulationDepth = MODULATION_DEPTH_LOW;
 	_vibratoDepth = VIBRATO_DEPTH_LOW;
 	_rhythmModeRewriteSharedRegister = true;
-	_scaleAdditiveOperatorLevel = false;
 	// CTMIDI.DRV actually uses default volume 0x80, which is not a valid MIDI value.
 	// This might cause marginally lower volumes in this implementation if a track
 	// does not set volume controller values.
@@ -555,6 +554,13 @@ uint16 MidiDriver_ADLIB_CTMIDI::calculateFrequency(uint8 channel, uint8 source,
 
 uint8 MidiDriver_ADLIB_CTMIDI::calculateUnscaledVolume(uint8 channel, uint8 source, uint8 velocity,
 		const OplInstrumentDefinition &instrumentDef, uint8 operatorNum) {
+	if ((instrumentDef.rhythmType == RHYTHM_TYPE_UNDEFINED || instrumentDef.rhythmType == RHYTHM_TYPE_BASS_DRUM) &&
+			operatorNum == 0) {
+		// Original code does not apply velocity and channel volume to additive operators,
+		// which is probably a bug.
+		return instrumentDef.getOperatorDefinition(operatorNum).level & 0x3F;
+	}
+
 	// Determine a modifier value for the instrument definition operator volume
 	// based on the note velocity and MIDI channel volume
 	uint16 volumeModifierIndex = (((velocity << 1) | 1) * (_controlData[source][channel].volume << 1)) >> 11;
diff --git a/audio/adlib_ms.cpp b/audio/adlib_ms.cpp
index 32f299b6c04..d13015b0762 100644
--- a/audio/adlib_ms.cpp
+++ b/audio/adlib_ms.cpp
@@ -453,7 +453,6 @@ MidiDriver_ADLIB_Multisource::MidiDriver_ADLIB_Multisource(OPL::Config::OplType
 		_accuracyMode(ACCURACY_MODE_SB16_WIN95),
 		_allocationMode(ALLOCATION_MODE_DYNAMIC),
 		_instrumentWriteMode(INSTRUMENT_WRITE_MODE_NOTE_ON),
-		_scaleAdditiveOperatorLevel(true),
 		_rhythmModeIgnoreNoteOffs(false),
 		_rhythmInstrumentMode(RHYTHM_INSTRUMENT_MODE_CHANNEL_10),
 		_defaultChannelVolume(0),
@@ -1724,15 +1723,13 @@ int32 MidiDriver_ADLIB_Multisource::calculatePitchBend(uint8 channel, uint8 sour
 }
 
 uint8 MidiDriver_ADLIB_Multisource::calculateVolume(uint8 channel, uint8 source, uint8 velocity, const OplInstrumentDefinition &instrumentDef, uint8 operatorNum) {
-	// Get the volume (level) for this operator from the instrument definition.
-	uint8 operatorDefVolume = instrumentDef.getOperatorDefinition(operatorNum).level & 0x3F;
-
 	// Determine if volume settings should be applied to this operator.
-	if (!isVolumeApplicableToOperator(instrumentDef, operatorNum))
+	if (!isVolumeApplicableToOperator(instrumentDef, operatorNum)) {
 		// No need to apply volume settings; just use the instrument definition
 		// operator volume.
-		return operatorDefVolume;
-
+		return instrumentDef.getOperatorDefinition(operatorNum).level & 0x3F;
+	}
+	
 	// Calculate the volume based on note velocity, channel volume and
 	// expression.
 	uint8 unscaledVolume = calculateUnscaledVolume(channel, source, velocity, instrumentDef, operatorNum);
@@ -1800,15 +1797,7 @@ bool MidiDriver_ADLIB_Multisource::isVolumeApplicableToOperator(const OplInstrum
 	// instrument definition volume.
 	bool applyVolume = false;
 	if (instrumentDef.rhythmType != RHYTHM_TYPE_UNDEFINED) {
-		if (instrumentDef.rhythmType == RHYTHM_TYPE_BASS_DRUM) {
-			// Only apply volume to operator 1, or to both operators
-			// if connection is additive.
-			applyVolume = ((operatorNum == 1) || (_scaleAdditiveOperatorLevel && (instrumentDef.connectionFeedback0 & 0x01) == 0x01));
-		}
-		else {
-			// Always apply volume to other rhythm instruments
-			applyVolume = true;
-		}
+		applyVolume = (instrumentDef.rhythmType != RHYTHM_TYPE_BASS_DRUM || operatorNum == 1);
 	} else if (instrumentDef.fourOperator) {
 		// 4 operator instruments have 4 different operator connections.
 		uint8 connection = (instrumentDef.connectionFeedback0 & 0x01) | ((instrumentDef.connectionFeedback1 & 0x01) << 1);
@@ -1821,7 +1810,7 @@ bool MidiDriver_ADLIB_Multisource::isVolumeApplicableToOperator(const OplInstrum
 		case 0x01:
 			// 1ADD+3FM
 			// Operator 0 is additive and operator 3 is a carrier.
-			applyVolume = ((_scaleAdditiveOperatorLevel && operatorNum == 0) || operatorNum == 3);
+			applyVolume = (operatorNum == 0 || operatorNum == 3);
 			break;
 		case 0x10:
 			// 2FM+2FM
@@ -1831,7 +1820,7 @@ bool MidiDriver_ADLIB_Multisource::isVolumeApplicableToOperator(const OplInstrum
 		case 0x11:
 			// 1ADD+2FM+1ADD
 			// Operators 0 and 3 are additive and operator 2 is a carrier.
-			applyVolume = ((_scaleAdditiveOperatorLevel && (operatorNum == 0 || operatorNum == 3)) || operatorNum == 2);
+			applyVolume = (operatorNum == 0 || operatorNum == 2 || operatorNum == 3);
 			break;
 		default:
 			// Should not happen.
@@ -1844,7 +1833,7 @@ bool MidiDriver_ADLIB_Multisource::isVolumeApplicableToOperator(const OplInstrum
 		// volume settings applied; modulator operators just use the instrument
 		// definition volume. In FM synthesis connection, operator 1 is a
 		// carrier.
-		applyVolume = (_scaleAdditiveOperatorLevel && (instrumentDef.connectionFeedback0 & 0x01) == 0x01) || operatorNum == 1;
+		applyVolume = (instrumentDef.connectionFeedback0 & 0x01) == 0x01 || operatorNum == 1;
 	}
 	return applyVolume;
 }
diff --git a/audio/adlib_ms.h b/audio/adlib_ms.h
index 122cad32d87..fc2d30555c8 100644
--- a/audio/adlib_ms.h
+++ b/audio/adlib_ms.h
@@ -1230,8 +1230,6 @@ protected:
 	ChannelAllocationMode _allocationMode;
 	// Controls when the instrument definitions are written.
 	InstrumentWriteMode _instrumentWriteMode;
-	// Controls if the level of additive operators should be scaled by volume or not.
-	bool _scaleAdditiveOperatorLevel;
 	// In instrument write mode First Note On or Program Change, this flag controls if the Cx register,
 	// which is shared between rhythm mode instrument definitions (except bass drum), is rewritten
 	// before each note on.




More information about the Scummvm-git-logs mailing list