[Scummvm-git-logs] scummvm branch-2-5 -> 2432a8aec318639b114ab7e40f6a2279733c550e

eriktorbjorn eriktorbjorn at telia.com
Tue Nov 2 07:41:52 UTC 2021


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

Summary:
5afcb058b4 AGOS: Fix Waxworks AdLib music (bug #13048)
0412e1a3f5 AGOS: Further work on Waxworks AdLib volume
2432a8aec3 AGOS: Use the music volume setting for Accolade AdLib driver


Commit: 5afcb058b4ab768ab4c42ec18a0687935135dce5
    https://github.com/scummvm/scummvm/commit/5afcb058b4ab768ab4c42ec18a0687935135dce5
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2021-11-02T08:39:51+01:00

Commit Message:
AGOS: Fix Waxworks AdLib music (bug #13048)

Because only the unused channelVolueAdjust value was clipped, the actual
velocity of the note would often overflow, causing the note to be almost
muted instead of played at full volume.

I assume it was an oversight that chanelVolumeAdjust wasn't used, so
I've fixed that and moved the clipping to after all adjustments have
been made. Also eliminated some unneeded floating-point math.

Is it correct now? I honestly don't know. It seems that, at least in
Waxworks, almost all notes end up being played at max volume. But maybe
that's how it should be?

Changed paths:
    engines/agos/drivers/accolade/adlib.cpp


diff --git a/engines/agos/drivers/accolade/adlib.cpp b/engines/agos/drivers/accolade/adlib.cpp
index 9d013f9722..20182391d7 100644
--- a/engines/agos/drivers/accolade/adlib.cpp
+++ b/engines/agos/drivers/accolade/adlib.cpp
@@ -286,19 +286,16 @@ void MidiDriver_Accolade_AdLib::setTimerCallback(void *timerParam, Common::Timer
 
 void MidiDriver_Accolade_AdLib::noteOn(byte FMvoiceChannel, byte note, byte velocity) {
 	byte adjustedNote     = note;
-	byte adjustedVelocity = velocity;
 	byte regValueA0h      = 0;
 	byte regValueB0h      = 0;
 
 	// adjust velocity
-	int16 channelVolumeAdjust = _channels[FMvoiceChannel].volumeAdjust;
-	channelVolumeAdjust += adjustedVelocity;
-	channelVolumeAdjust = CLIP<int16>(channelVolumeAdjust, 0, 0x7F);
-
+	int16 channelVolumeAdjust = velocity + _channels[FMvoiceChannel].volumeAdjust;
 	// adjust velocity with the master volume
-	byte volumeAdjust = adjustedVelocity * ((float) (128 + _masterVolume) / 128);
+	channelVolumeAdjust = (channelVolumeAdjust * (128 + _masterVolume)) / 128;
+	channelVolumeAdjust = CLIP<int16>(channelVolumeAdjust, 0, 0x7F);
 
-	adjustedVelocity = volumeAdjust;
+	byte adjustedVelocity = channelVolumeAdjust;
 
 	if (!_musicDrvMode) {
 		// INSTR.DAT


Commit: 0412e1a3f5334591c2ef21840490df8aa033df59
    https://github.com/scummvm/scummvm/commit/0412e1a3f5334591c2ef21840490df8aa033df59
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2021-11-02T08:39:59+01:00

Commit Message:
AGOS: Further work on Waxworks AdLib volume

After feedback from NMIError, and some more guesswork. The master volume
isn't applied until noteOnSetVolume(), so that the correct adjusted
volume can be stored in the channel data structure.

Now the volume seems too low to me, but of course that could be fixed by
having some other default value than 15 for _masterVolume.

Changed paths:
    engines/agos/drivers/accolade/adlib.cpp
    engines/agos/drivers/accolade/adlib.h


diff --git a/engines/agos/drivers/accolade/adlib.cpp b/engines/agos/drivers/accolade/adlib.cpp
index 20182391d7..c573bdf05f 100644
--- a/engines/agos/drivers/accolade/adlib.cpp
+++ b/engines/agos/drivers/accolade/adlib.cpp
@@ -169,12 +169,11 @@ void MidiDriver_Accolade_AdLib::setVolume(byte volume) {
 	// Set the master volume in range from -128 to 127
 	_masterVolume = CLIP<int>(-128 + volume, -128, 127);
 	for (int i = 0; i < AGOS_ADLIB_VOICES_COUNT; i++) {
-		// Adjust channel volume with the master volume and re-set registers
-		byte adjustedVelocity = _channels[i].velocity * ((float) (128 + _masterVolume) / 128);
-		noteOnSetVolume(i, 1, adjustedVelocity);
+		// Re-set registers
+		noteOnSetVolume(i, 1, _channels[i].velocity);
 		if (i <= AGOS_ADLIB_VOICES_PERCUSSION_START) {
 			// Set second operator for FM voices + first percussion
-			noteOnSetVolume(i, 2, adjustedVelocity);
+			noteOnSetVolume(i, 2, _channels[i].velocity);
 		}
 	}
 }
@@ -290,12 +289,11 @@ void MidiDriver_Accolade_AdLib::noteOn(byte FMvoiceChannel, byte note, byte velo
 	byte regValueB0h      = 0;
 
 	// adjust velocity
-	int16 channelVolumeAdjust = velocity + _channels[FMvoiceChannel].volumeAdjust;
-	// adjust velocity with the master volume
-	channelVolumeAdjust = (channelVolumeAdjust * (128 + _masterVolume)) / 128;
-	channelVolumeAdjust = CLIP<int16>(channelVolumeAdjust, 0, 0x7F);
+	int16 volumeAdjust = _channels[FMvoiceChannel].volumeAdjust;
+	volumeAdjust += velocity;
+	volumeAdjust = CLIP<int16>(volumeAdjust, 0, 0x7F);
 
-	byte adjustedVelocity = channelVolumeAdjust;
+	byte adjustedVelocity = volumeAdjust;
 
 	if (!_musicDrvMode) {
 		// INSTR.DAT
@@ -432,11 +430,14 @@ void MidiDriver_Accolade_AdLib::noteOn(byte FMvoiceChannel, byte note, byte velo
 
 // 100% the same for INSTR.DAT and MUSIC.DRV variants
 // except for a bug, that was introduced for MUSIC.DRV
-void MidiDriver_Accolade_AdLib::noteOnSetVolume(byte FMvoiceChannel, byte operatorNr, byte adjustedVelocity) {
+void MidiDriver_Accolade_AdLib::noteOnSetVolume(byte FMvoiceChannel, byte operatorNr, byte velocity) {
 	byte operatorReg = 0;
 	byte regValue40h = 0;
 	const InstrumentEntry *curInstrument = NULL;
 
+	// Adjust velocity with the master volume
+	uint16 adjustedVelocity = (velocity * (128 + _masterVolume)) / 256;
+
 	regValue40h = (63 - adjustedVelocity) & 0x3F;
 
 	if ((operatorNr == 1) && (FMvoiceChannel <= AGOS_ADLIB_VOICES_PERCUSSION_START)) {
diff --git a/engines/agos/drivers/accolade/adlib.h b/engines/agos/drivers/accolade/adlib.h
index eb1dc20f21..e01e038844 100644
--- a/engines/agos/drivers/accolade/adlib.h
+++ b/engines/agos/drivers/accolade/adlib.h
@@ -114,7 +114,7 @@ private:
 	void programChangeSetInstrument(byte FMvoiceChannel, byte mappedInstrumentNr, byte MIDIinstrumentNr);
 	void setRegister(int reg, int value);
 	void noteOn(byte FMvoiceChannel, byte note, byte velocity);
-	void noteOnSetVolume(byte FMvoiceChannel, byte operatorReg, byte adjustedVelocity);
+	void noteOnSetVolume(byte FMvoiceChannel, byte operatorReg, byte velocity);
 	void noteOff(byte FMvoiceChannel, byte note, bool dontCheckNote);
 };
 


Commit: 2432a8aec318639b114ab7e40f6a2279733c550e
    https://github.com/scummvm/scummvm/commit/2432a8aec318639b114ab7e40f6a2279733c550e
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2021-11-02T08:40:12+01:00

Commit Message:
AGOS: Use the music volume setting for Accolade AdLib driver

At this point, the driver still tries to play notes at the maximum
allowed volume or louder, but ScummVM's music volume setting can bring
them back down to the expected range. That may have to be good enough
for now.

Also, since the master volume is only used internally there's no need to
keep converting back and forth. Just use the interval 0-255 throughout.

Changed paths:
    engines/agos/drivers/accolade/adlib.cpp
    engines/agos/midi.cpp


diff --git a/engines/agos/drivers/accolade/adlib.cpp b/engines/agos/drivers/accolade/adlib.cpp
index c573bdf05f..a3c2153044 100644
--- a/engines/agos/drivers/accolade/adlib.cpp
+++ b/engines/agos/drivers/accolade/adlib.cpp
@@ -95,7 +95,7 @@ const uint16 frequencyLookUpTableMusicDrv[12] = {
 // I have currently not implemented dynamic channel allocation.
 
 MidiDriver_Accolade_AdLib::MidiDriver_Accolade_AdLib()
-		: _masterVolume(15), _opl(0),
+		: _masterVolume(143), _opl(0),
 		  _adlibTimerProc(0), _adlibTimerParam(0), _isOpen(false) {
 	memset(_channelMapping, 0, sizeof(_channelMapping));
 	memset(_instrumentMapping, 0, sizeof(_instrumentMapping));
@@ -166,8 +166,7 @@ void MidiDriver_Accolade_AdLib::close() {
 }
 
 void MidiDriver_Accolade_AdLib::setVolume(byte volume) {
-	// Set the master volume in range from -128 to 127
-	_masterVolume = CLIP<int>(-128 + volume, -128, 127);
+	_masterVolume = volume;
 	for (int i = 0; i < AGOS_ADLIB_VOICES_COUNT; i++) {
 		// Re-set registers
 		noteOnSetVolume(i, 1, _channels[i].velocity);
@@ -289,11 +288,7 @@ void MidiDriver_Accolade_AdLib::noteOn(byte FMvoiceChannel, byte note, byte velo
 	byte regValueB0h      = 0;
 
 	// adjust velocity
-	int16 volumeAdjust = _channels[FMvoiceChannel].volumeAdjust;
-	volumeAdjust += velocity;
-	volumeAdjust = CLIP<int16>(volumeAdjust, 0, 0x7F);
-
-	byte adjustedVelocity = volumeAdjust;
+	byte adjustedVelocity = velocity + _channels[FMvoiceChannel].volumeAdjust;
 
 	if (!_musicDrvMode) {
 		// INSTR.DAT
@@ -436,7 +431,7 @@ void MidiDriver_Accolade_AdLib::noteOnSetVolume(byte FMvoiceChannel, byte operat
 	const InstrumentEntry *curInstrument = NULL;
 
 	// Adjust velocity with the master volume
-	uint16 adjustedVelocity = (velocity * (128 + _masterVolume)) / 256;
+	uint16 adjustedVelocity = CLIP<uint16>((velocity * _masterVolume) / 255, 0, 0x3F);
 
 	regValue40h = (63 - adjustedVelocity) & 0x3F;
 
diff --git a/engines/agos/midi.cpp b/engines/agos/midi.cpp
index 8aca0bbf8c..3ae0f4fd33 100644
--- a/engines/agos/midi.cpp
+++ b/engines/agos/midi.cpp
@@ -493,7 +493,7 @@ void MidiPlayer::pause(bool b) {
 	Common::StackLock lock(_mutex);
 	// if using the driver Accolade_AdLib call setVolume() to turn off\on the volume on all channels
 	if (musicType == MT_ADLIB && _musicMode == kMusicModeAccolade) {
-		static_cast <MidiDriver_Accolade_AdLib*> (_driver)->setVolume(_paused ? 0 : 128);
+		static_cast <MidiDriver_Accolade_AdLib*> (_driver)->setVolume(_paused ? 0 : ConfMan.getInt("music_volume"));
 	} else if (_musicMode == kMusicModePC98) {
 		_driver->property(0x30, _paused ? 1 : 0);
 	}
@@ -519,6 +519,8 @@ void MidiPlayer::setVolume(int musicVol, int sfxVol) {
 	if (_musicMode == kMusicModePC98) {
 		_driver->property(0x10, _musicVolume);
 		_driver->property(0x20, _sfxVolume);
+	} else if (_musicMode == kMusicModeAccolade && musicType == MT_ADLIB) {
+		static_cast <MidiDriver_Accolade_AdLib*> (_driver)->setVolume(_musicVolume);
 	}
 
 	// Now tell all the channels this.




More information about the Scummvm-git-logs mailing list