[Scummvm-cvs-logs] SF.net SVN: scummvm: [28597] scummvm/trunk/engines/agi/sound.cpp

buddha_ at users.sourceforge.net buddha_ at users.sourceforge.net
Mon Aug 13 18:05:46 CEST 2007


Revision: 28597
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28597&view=rev
Author:   buddha_
Date:     2007-08-13 09:05:46 -0700 (Mon, 13 Aug 2007)

Log Message:
-----------
Grouped wave lists together into oscillators (Oscillators always consists of two waves).

Modified Paths:
--------------
    scummvm/trunk/engines/agi/sound.cpp

Modified: scummvm/trunk/engines/agi/sound.cpp
===================================================================
--- scummvm/trunk/engines/agi/sound.cpp	2007-08-13 15:57:04 UTC (rev 28596)
+++ scummvm/trunk/engines/agi/sound.cpp	2007-08-13 16:05:46 UTC (rev 28597)
@@ -140,10 +140,49 @@
 	}
 };
 
-// Maximum number of waves in an Apple IIGS instrument's wave list.
+// Number of waves per Apple IIGS sound oscillator
+#define WAVES_PER_OSCILLATOR 2
+
+/** An Apple IIGS sound oscillator. Consists always of two waves. */
+struct IIgsOscillator {
+	IIgsWaveInfo waves[WAVES_PER_OSCILLATOR];
+
+	bool finalize(Common::SeekableReadStream &uint8Wave) {
+		for (uint i = 0; i < WAVES_PER_OSCILLATOR; i++)
+			if (!waves[i].finalize(uint8Wave))
+				return false;
+		return true;
+	}
+};
+
+// Maximum number of oscillators in an Apple IIGS instrument.
 // Chosen empirically based on Apple IIGS AGI game data, increase if needed.
-#define MAX_WAVE_COUNT 4
+#define MAX_OSCILLATORS 4
 
+/** An Apple IIGS sound oscillator list. */
+struct IIgsOscillatorList {
+	uint count; ///< Oscillator count
+	IIgsOscillator osc[MAX_OSCILLATORS]; ///< The oscillators
+
+	bool read(Common::SeekableReadStream &stream, uint oscillatorCount, bool ignoreAddr = false) {
+		// First read the A waves and then the B waves for the oscillators
+		for (uint waveNum = 0; waveNum < WAVES_PER_OSCILLATOR; waveNum++)
+			for (uint oscNum = 0; oscNum < oscillatorCount; oscNum++)
+				if (!osc[oscNum].waves[waveNum].read(stream, ignoreAddr))
+					return false;
+
+		count = oscillatorCount; // Set the oscillator count
+		return true;
+	}
+
+	bool finalize(Common::SeekableReadStream &uint8Wave) {
+		for (uint i = 0; i < count; i++)
+			if (!osc[i].finalize(uint8Wave))
+				return false;
+		return true;
+	}
+};
+
 struct IIgsInstrumentHeader {
 	IIgsEnvelope env;
 	uint8 relseg;
@@ -152,10 +191,7 @@
 	uint8 vibdepth;
 	uint8 vibspeed;
 	uint8 spare;
-	uint8 wac;
-	uint8 wbc;
-	IIgsWaveInfo wal[MAX_WAVE_COUNT];
-	IIgsWaveInfo wbl[MAX_WAVE_COUNT];
+	IIgsOscillatorList oscList;
 
 	/**
 	 * Read an Apple IIGS instrument header from the given stream.
@@ -171,23 +207,14 @@
 		vibdepth  = stream.readByte();
 		vibspeed  = stream.readByte();
 		spare     = stream.readByte();
-		wac       = stream.readByte();
-		wbc       = stream.readByte();
-		for (int waveA = 0; waveA < wac; waveA++) // Read A wave lists
-			wal[waveA].read(stream, ignoreAddr);
-		for (int waveB = 0; waveB < wbc; waveB++) // Read B wave lists
-			wbl[waveB].read(stream, ignoreAddr);
-		return !stream.ioFailed();
+		byte wac  = stream.readByte(); // Read A wave count
+		byte wbc  = stream.readByte(); // Read B wave count
+		oscList.read(stream, wac, ignoreAddr); // Read the oscillators
+		return (wac == wbc) && !stream.ioFailed(); // A and B wave counts must match
 	}
 
 	bool finalize(Common::SeekableReadStream &uint8Wave) {
-		for (int waveA = 0; waveA < wac; waveA++) // Finalize A-waves
-			if (!wal[waveA].finalize(uint8Wave))
-				return false;
-		for (int waveB = 0; waveB < wbc; waveB++) // Finalize B-waves
-			if (!wbl[waveB].finalize(uint8Wave))
-				return false;
-		return true;
+		return oscList.finalize(uint8Wave);
 	}
 };
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list