[Scummvm-git-logs] scummvm master -> 86a119020013f7ad8994a8c0ef53e31b73745516

bluegr noreply at scummvm.org
Thu Sep 19 15:10:38 UTC 2024


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

Summary:
962e711b8e AUDIO: Adapt maxtrax debug code to our standards
86a1190200 AUDIO: Remove most goto statements from the Maxtrax decoder


Commit: 962e711b8e91693769661a5e1fbb6baf5dbd4e9e
    https://github.com/scummvm/scummvm/commit/962e711b8e91693769661a5e1fbb6baf5dbd4e9e
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2024-09-19T17:21:27+03:00

Commit Message:
AUDIO: Adapt maxtrax debug code to our standards

The debug information is now tied to a debug level, similar to
how it's implemented in the rest of our codebase

Changed paths:
    audio/mods/maxtrax.cpp


diff --git a/audio/mods/maxtrax.cpp b/audio/mods/maxtrax.cpp
index 64e1478f23e..42aef6bb590 100644
--- a/audio/mods/maxtrax.cpp
+++ b/audio/mods/maxtrax.cpp
@@ -996,7 +996,6 @@ allocError:
 	return false;
 }
 
-#if !defined(NDEBUG) && 0
 void MaxTrax::outPutEvent(const Event &ev, int num) {
 	struct {
 		byte cmd;
@@ -1019,24 +1018,23 @@ void MaxTrax::outPutEvent(const Event &ev, int num) {
 		;
 
 	if (num == -1)
-		debug("Event    : %02X %s %s %02X %04X %04X", ev.command, COMMANDS[i].name, COMMANDS[i].param, ev.parameter, ev.startTime, ev.stopTime);
+		debug(6, "Event    : %02X %s %s %02X %04X %04X", ev.command, COMMANDS[i].name, COMMANDS[i].param, ev.parameter, ev.startTime, ev.stopTime);
 	else
-		debug("Event %3d: %02X %s %s %02X %04X %04X", num, ev.command, COMMANDS[i].name, COMMANDS[i].param, ev.parameter, ev.startTime, ev.stopTime);
+		debug(6, "Event %3d: %02X %s %s %02X %04X %04X", num, ev.command, COMMANDS[i].name, COMMANDS[i].param, ev.parameter, ev.startTime, ev.stopTime);
 }
 
 void MaxTrax::outPutScore(const Score &sc, int num) {
+	if (gDebugLevel < 6)
+		return;
+
 	if (num == -1)
-		debug("score   : %i Events", sc.numEvents);
+		debug(6, "score   : %i Events", sc.numEvents);
 	else
-		debug("score %2d: %i Events", num, sc.numEvents);
+		debug(6, "score %2d: %i Events", num, sc.numEvents);
 	for (uint i = 0; i < sc.numEvents; ++i)
 		outPutEvent(sc.events[i], i);
-	debug("");
+	debug(6, "");
 }
-#else
-void MaxTrax::outPutEvent(const Event &ev, int num) {}
-void MaxTrax::outPutScore(const Score &sc, int num) {}
-#endif	// #ifndef NDEBUG
 
 } // End of namespace Audio
 


Commit: 86a119020013f7ad8994a8c0ef53e31b73745516
    https://github.com/scummvm/scummvm/commit/86a119020013f7ad8994a8c0ef53e31b73745516
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2024-09-19T18:10:05+03:00

Commit Message:
AUDIO: Remove most goto statements from the Maxtrax decoder

Changed paths:
    audio/mods/maxtrax.cpp
    audio/mods/maxtrax.h


diff --git a/audio/mods/maxtrax.cpp b/audio/mods/maxtrax.cpp
index 42aef6bb590..5286e62ede3 100644
--- a/audio/mods/maxtrax.cpp
+++ b/audio/mods/maxtrax.cpp
@@ -484,12 +484,12 @@ void MaxTrax::controlCh(ChannelContext &channel, const byte command, const byte
 		break;
 	case 0x7E:	// MONO mode
 		channel.flags |= ChannelContext::kFlagMono;
-		goto allNotesOff;
+		// Fallthrough
 	case 0x7F:	// POLY mode
-		channel.flags &= ~ChannelContext::kFlagMono;
+		if (command == 0x7F)
+			channel.flags &= ~ChannelContext::kFlagMono;
 		// Fallthrough
 	case 0x7B:	// All Notes Off
-allNotesOff:
 		for (int i = 0; i < ARRAYSIZE(_voiceCtx); ++i) {
 			if (_voiceCtx[i].channel == &channel) {
 				if ((channel.flags & ChannelContext::kFlagDamper) != 0)
@@ -818,6 +818,13 @@ void MaxTrax::resetChannel(ChannelContext &chan, bool rightChannel) {
 		chan.flags |= ChannelContext::kFlagRightChannel;
 }
 
+void MaxTrax::freeResources(bool loadScores, bool loadSamples) {
+	if (loadSamples)
+		freePatches();
+	if (loadScores)
+		freeScores();
+}
+
 void MaxTrax::freeScores() {
 	if (_scores) {
 		for (int i = 0; i < _numScores; ++i)
@@ -862,11 +869,7 @@ int MaxTrax::playNote(byte note, byte patch, uint16 duration, uint16 volume, boo
 bool MaxTrax::load(Common::SeekableReadStream &musicData, bool loadScores, bool loadSamples) {
 	Common::StackLock lock(_mutex);
 	stopMusic();
-	if (loadSamples)
-		freePatches();
-	if (loadScores)
-		freeScores();
-	const char *errorMsg = 0;
+	freeResources(loadScores, loadSamples);
 	// 0x0000: 4 Bytes Header "MXTX"
 	// 0x0004: uint16 tempo
 	// 0x0006: uint16 flags. bit0 = lowpassfilter, bit1 = attackvolume, bit15 = microtonal
@@ -899,21 +902,32 @@ bool MaxTrax::load(Common::SeekableReadStream &musicData, bool loadScores, bool
 	// uint16 number of Scores
 	const uint16 scoresInFile = musicData.readUint16BE();
 
-	if (musicData.err() || musicData.eos())
-		goto ioError;
+	if (musicData.err() || musicData.eos()) {
+		warning("Maxtrax: Encountered IO-Error");
+		freeResources(loadScores, loadSamples);
+		return false;
+	}
 
 	if (loadScores) {
 		const uint16 tempScores = MIN(scoresInFile, _playerCtx.maxScoreNum);
 		Score *curScore = new Score[tempScores];
-		if (!curScore)
-			goto allocError;
+		if (!curScore) {
+			warning("Maxtrax: Could not allocate Memory");
+			freeResources(loadScores, loadSamples);
+			return false;
+		}
+
 		_scores = curScore;
 
 		for (scoresLoaded = 0; scoresLoaded < tempScores; ++scoresLoaded, ++curScore) {
 			const uint32 numEvents = musicData.readUint32BE();
 			Event *curEvent = new Event[numEvents];
-			if (!curEvent)
-				goto allocError;
+			if (!curEvent) {
+				warning("Maxtrax: Could not allocate Memory");
+				freeResources(loadScores, loadSamples);
+				return false;
+			}
+
 			curScore->events = curEvent;
 			for (int j = numEvents; j > 0; --j, ++curEvent) {
 				curEvent->command = musicData.readByte();
@@ -959,8 +973,11 @@ bool MaxTrax::load(Common::SeekableReadStream &musicData, bool loadScores, bool
 
 			// Allocate space for both attack and release Segment.
 			Envelope *envPtr = new Envelope[totalEnvs];
-			if (!envPtr)
-				goto allocError;
+			if (!envPtr) {
+				warning("Maxtrax: Could not allocate Memory");
+				freeResources(loadScores, loadSamples);
+				return false;
+			}
 			// Attack Segment
 			curPatch.attackPtr = envPtr;
 			// Release Segment
@@ -974,25 +991,20 @@ bool MaxTrax::load(Common::SeekableReadStream &musicData, bool loadScores, bool
 
 			// read Samples
 			int8 *allocSamples = new int8[totalSamples];
-			if (!allocSamples)
-				goto allocError;
+			if (!allocSamples) {
+				warning("Maxtrax: Could not allocate Memory");
+				freeResources(loadScores, loadSamples);
+				return false;
+			}
 			curPatch.samplePtr = allocSamples;
 			musicData.read(allocSamples, totalSamples);
 		}
 	}
 	if (!musicData.err() && !musicData.eos())
 		return true;
-ioError:
-	errorMsg = "Maxtrax: Encountered IO-Error";
-allocError:
-	if (!errorMsg)
-		errorMsg = "Maxtrax: Could not allocate Memory";
 
-	warning("%s", errorMsg);
-	if (loadSamples)
-		freePatches();
-	if (loadScores)
-		freeScores();
+	warning("Maxtrax: Encountered IO-Error");
+	freeResources(loadScores, loadSamples);
 	return false;
 }
 
diff --git a/audio/mods/maxtrax.h b/audio/mods/maxtrax.h
index ec60ae50a3c..7db9f2b2878 100644
--- a/audio/mods/maxtrax.h
+++ b/audio/mods/maxtrax.h
@@ -209,6 +209,7 @@ private:
 	uint16 calcNote(const VoiceContext &voice);
 	int8 noteOn(ChannelContext &channel, byte note, uint16 volume, uint16 pri);
 	void killVoice(byte num);
+	void freeResources(bool loadScores, bool loadSamples);
 
 	static void outPutEvent(const Event &ev, int num = -1);
 	static void outPutScore(const Score &sc, int num = -1);




More information about the Scummvm-git-logs mailing list