[Scummvm-cvs-logs] SF.net SVN: scummvm:[42343] scummvm/branches/gsoc2009-mods/sound/mods

nolange at users.sourceforge.net nolange at users.sourceforge.net
Fri Jul 10 18:01:40 CEST 2009


Revision: 42343
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42343&view=rev
Author:   nolange
Date:     2009-07-10 16:01:40 +0000 (Fri, 10 Jul 2009)

Log Message:
-----------
made all structures that are only written when loading song/samples const
fixed volume-handling a bit, still not correct

Modified Paths:
--------------
    scummvm/branches/gsoc2009-mods/sound/mods/maxtrax.cpp
    scummvm/branches/gsoc2009-mods/sound/mods/maxtrax.h

Modified: scummvm/branches/gsoc2009-mods/sound/mods/maxtrax.cpp
===================================================================
--- scummvm/branches/gsoc2009-mods/sound/mods/maxtrax.cpp	2009-07-10 15:46:55 UTC (rev 42342)
+++ scummvm/branches/gsoc2009-mods/sound/mods/maxtrax.cpp	2009-07-10 16:01:40 UTC (rev 42343)
@@ -83,7 +83,7 @@
 	}
 
 	if (_playerCtx.musicPlaying) {
-		Event *curEvent = _playerCtx.nextEvent;
+		const Event *curEvent = _playerCtx.nextEvent;
 		int32 eventTime = _playerCtx.nextEventTime;
 		for (; eventTime <= millis; eventTime += (++curEvent)->startTime) {
 			const byte cmd = curEvent->command;
@@ -170,8 +170,8 @@
 		VoiceContext &voice = _voiceCtx[i]; // a2
 		if (!voice.channel)
 			continue;
-		ChannelContext &channel = *voice.channel; // a3
-		Patch &patch = *voice.patch; // a5, used with start and later
+		const ChannelContext &channel = *voice.channel; // a3
+		const Patch &patch = *voice.patch; // a5, used with start and later
 		voice.lastTicks += _playerCtx.tickUnit;
 		bool envHandling = true;
 		byte newVolume = 0xFF; // if set to 0 this means skip recalc
@@ -230,6 +230,8 @@
 		// .I9 - env managment
 		if (envHandling) {
 			assert(voice.status != VoiceContext::kStatusSustain);
+			assert(voice.envelope);
+			assert(voice.envelopeLeft >= 0);
 			if (voice.ticksLeft > _playerCtx.tickUnit) {
 				voice.baseVolume = (uint16)MIN(MAX(0, voice.baseVolume + voice.incrVolume), 0x8000);
 				voice.ticksLeft -= _playerCtx.tickUnit;
@@ -237,6 +239,7 @@
 			} else {
 				// a0 = voice.envelope
 				voice.baseVolume = voice.envelope->volume;
+				assert(voice.envelopeLeft > 0);
 				if (--voice.envelopeLeft) {
 					++voice.envelope;
 					const uint16 duration = voice.envelope->duration;
@@ -245,6 +248,7 @@
 					voice.incrVolume = (duration) ? (1000 * vol) / (duration * _playerCtx.vBlankFreq) : vol;
 					// goto .l18
 				} else if (voice.status == VoiceContext::kStatusDecay) {
+					voice.envelope = 0;
 					voice.status = VoiceContext::kStatusHalt;
 					// set d4 = 0, goto I17
 					newVolume = 0;
@@ -252,17 +256,19 @@
 					assert(voice.status == VoiceContext::kStatusAttack);
 					voice.status = VoiceContext::kStatusSustain;
 					voice.lastTicks = _playerCtx.tickUnit;
+					voice.envelope = 0;
 					// goto .l18
 				}
 			}
-		}
+		} else
+			assert(voice.envelope == 0);
 
 		// .l18 - recalc 
 		if (newVolume) {
 			// calc volume
 			uint16 vol = (voice.noteVolume < (1 << 7)) ? (voice.noteVolume * _playerCtx.volume) >> 7 : _playerCtx.volume;
 			if (voice.baseVolume < (1 << 15))
-				vol = (vol * (voice.baseVolume >> 8)) >> 7;
+				vol = (uint16)(((uint32)vol * voice.baseVolume) >> 15);
 			if (voice.channel->volume < (1 << 7))
 				vol = (vol * voice.channel->volume) >> 7;
 
@@ -329,13 +335,13 @@
 	voice.uinqueId = 0;
 
 	// "stop" voice, set period to 1, vol to 0
-	Paula::disableChannel(0);
+	Paula::disableChannel(num);
 	Paula::setChannelPeriod(num, 1);
 	Paula::setChannelVolume(num, 0);
 }
 
 int MaxTrax::calcNote(VoiceContext &voice) {
-	ChannelContext &channel = *voice.channel;
+	const ChannelContext &channel = *voice.channel;
 	voice.lastPeriod = 0;
 
 	int16 bend = 0;
@@ -355,7 +361,7 @@
 	// more it-never-worked microtonal code
 	tone += voice.baseNote << 8;
 
-	Patch &patch = *voice.patch;
+	const Patch &patch = *voice.patch;
 	tone += ((int16)patch.tune << 8) / 24;
 
 	tone -= 45 << 8; // MIDI note 45
@@ -387,7 +393,7 @@
 	if (!volume)
 		return -1;
 
-	Patch &patch = *channel.patch;
+	const Patch &patch = *channel.patch;
 	if (!patch.samplePtr)
 		return -1;
 	int8 voiceNum = -1;
@@ -416,7 +422,7 @@
 		// return if no channel found
 		voiceNum = (channel.flags & ChannelContext::kFlagRightChannel) != 0 ? 0 : 1;
 		static int c = 0;
-		voiceNum = (++c) % 4;
+		voiceNum = (&channel - _channelCtx) % 4;
 	}
 	assert(voiceNum >= 0 && voiceNum < ARRAYSIZE(_voiceCtx));
 
@@ -535,7 +541,7 @@
 		delete[] _patch[i].samplePtr;
 		delete[] _patch[i].attackPtr;
 	}
-	memset(_patch, 0, sizeof(_patch));
+	memset(const_cast<Patch *>(_patch), 0, sizeof(_patch));
 }
 
 bool MaxTrax::load(Common::SeekableReadStream &musicData, bool loadScores, bool loadSamples) {
@@ -581,7 +587,8 @@
 		
 		for (int i = tempScores; i > 0; --i, ++curScore) {
 			const uint32 numEvents = musicData.readUint32BE();
-			Event *curEvent = curScore->events = new Event[numEvents];
+			Event *curEvent = new Event[numEvents];
+			curScore->events = curEvent;
 			for (int j = numEvents; j > 0; --j, ++curEvent) {
 				curEvent->command = musicData.readByte();
 				curEvent->parameter = musicData.readByte();
@@ -612,7 +619,7 @@
 			const uint16 number = musicData.readUint16BE();
 			assert(number < ARRAYSIZE(_patch));
 			// pointer to samples needed?
-			Patch &curPatch = _patch[number];
+			Patch &curPatch = const_cast<Patch &>(_patch[number]);
 
 			curPatch.tune = musicData.readUint16BE();
 			curPatch.volume = musicData.readUint16BE();
@@ -641,8 +648,9 @@
 			}
 
 			// read Samples
-			curPatch.samplePtr = new int8[totalSamples];
-			musicData.read(curPatch.samplePtr, totalSamples);
+			int8 *allocSamples = new int8[totalSamples];
+			curPatch.samplePtr = allocSamples;
+			musicData.read(allocSamples, totalSamples);
 		}
 	} else if (wavesInFile > 0){
 		uint32 skipLen = 3 * 2;

Modified: scummvm/branches/gsoc2009-mods/sound/mods/maxtrax.h
===================================================================
--- scummvm/branches/gsoc2009-mods/sound/mods/maxtrax.h	2009-07-10 15:46:55 UTC (rev 42342)
+++ scummvm/branches/gsoc2009-mods/sound/mods/maxtrax.h	2009-07-10 16:01:40 UTC (rev 42343)
@@ -68,7 +68,7 @@
 		bool	musicLoop;
 
 		int		scoreIndex;
-		Event	*nextEvent;
+		const Event	*nextEvent;
 		int32	nextEventTime;
 
 		bool	addedNote;
@@ -82,8 +82,8 @@
 		uint16	volume;
 	};
 
-	struct Patch {
-		Envelope *attackPtr;
+	const struct Patch {
+		const Envelope *attackPtr;
 		//Envelope *releasePtr;
 		uint16	attackLen;
 		uint16	releaseLen;
@@ -92,7 +92,7 @@
 		uint16	volume;
 
 		// this was the SampleData struct in the assembler source
-		int8	*samplePtr;
+		const int8	*samplePtr;
 		uint32	sampleTotalLen;
 		uint32	sampleAttackLen;
 		uint16	sampleOctaves;
@@ -106,14 +106,14 @@
 	};
 
 	struct Score {
-		Event	*events;
+		const Event	*events;
 		uint32	numEvents;
 	} *_scores;
 
 	int _numScores;
 
 	struct ChannelContext {
-		Patch	*patch;
+		const Patch	*patch;
 		uint16	regParamNumber;
 
 		uint16	modulation;
@@ -149,8 +149,8 @@
 
 	struct VoiceContext {
 		ChannelContext *channel;
-		Patch	*patch;
-		Envelope *envelope;
+		const Patch	*patch;
+		const Envelope *envelope;
 		uint32	uinqueId;
 		uint32	lastTicks;
 		uint32	ticksLeft;


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