[Scummvm-cvs-logs] scummvm master -> 7c4f772e7e539b7a17d1ae3b7aa9d981b0ade1d5

fuzzie fuzzie at fuzzie.org
Mon Jun 6 10:58:29 CEST 2011


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

Summary:
7c4f772e7e TOON: Tidy up decodeADPCM.


Commit: 7c4f772e7e539b7a17d1ae3b7aa9d981b0ade1d5
    https://github.com/scummvm/scummvm/commit/7c4f772e7e539b7a17d1ae3b7aa9d981b0ade1d5
Author: Alyssa Milburn (fuzzie at fuzzie.org)
Date: 2011-06-06T01:55:36-07:00

Commit Message:
TOON: Tidy up decodeADPCM.

Changed paths:
    engines/toon/audio.cpp
    engines/toon/audio.h



diff --git a/engines/toon/audio.cpp b/engines/toon/audio.cpp
index ae67d19..0bf3316 100644
--- a/engines/toon/audio.cpp
+++ b/engines/toon/audio.cpp
@@ -232,8 +232,8 @@ AudioStreamInstance::AudioStreamInstance(AudioManager *man, Audio::Mixer *mixer,
 	_mixer = mixer;
 	_compBuffer = NULL;
 	_bufferOffset = 0;
-	_lastADPCMval1 = 0;
-	_lastADPCMval2 = 0;
+	_lastSample = 0;
+	_lastStepIndex = 0;
 	_file = stream;
 	_fadingIn = false;
 	_fadingOut = false;
@@ -307,8 +307,8 @@ bool AudioStreamInstance::readPacket() {
 		if (_looping) {
 			_file->seek(8);
 			_currentReadSize = 8;
-			_lastADPCMval1 = 0;
-			_lastADPCMval2 = 0;
+			_lastSample = 0;
+			_lastStepIndex = 0;
 		} else {
 			_bufferSize = 0;
 			stopNow();
@@ -342,52 +342,49 @@ bool AudioStreamInstance::readPacket() {
 void AudioStreamInstance::decodeADPCM(uint8 *comp, int16 *dest, int32 packetSize) {
 	debugC(5, kDebugAudio, "decodeADPCM(comp, dest, %d)", packetSize);
 
+	// standard IMA ADPCM decoding
 	int32 numSamples = 2 * packetSize;
-	int32 v18 = _lastADPCMval1;
-	int32 v19 = _lastADPCMval2;
+	int32 samp = _lastSample;
+	int32 stepIndex = _lastStepIndex;
 	for (int32 i = 0; i < numSamples; i++) {
 		uint8 comm = *comp;
+		bool isOddSample = (i & 1);
 
-		int32 v29 = i & 1;
-		int32 v30;
-		if (v29 == 0)
-			v30 = comm & 0xf;
+		uint8 code;
+		if (!isOddSample)
+			code = comm & 0xf;
 		else
-			v30 = (comm & 0xf0) >> 4;
+			code = (comm & 0xf0) >> 4;
 
-		int32 v31 = v30 & 0x8;
-		int32 v32 = v30 & 0x7;
-		int32 v33 = Audio::Ima_ADPCMStream::_imaTable[v19];
-		int32 v34 = v33 >> 3;
-		if (v32 & 4)
-			v34 += v33;
+		uint8 sample = code & 0x7;
 
-		if (v32 & 2)
-			v34 += v33 >> 1;
+		int32 step = Audio::Ima_ADPCMStream::_imaTable[stepIndex];
+		int32 E = step >> 3;
+		if (sample & 4)
+			E += step;
+		if (sample & 2)
+			E += step >> 1;
+		if (sample & 1)
+			E += step >> 2;
 
-		if (v32 & 1)
-			v34 += v33 >> 2;
+		stepIndex += Audio::ADPCMStream::_stepAdjustTable[sample];
+		stepIndex = CLIP<int32>(stepIndex, 0, ARRAYSIZE(Audio::Ima_ADPCMStream::_imaTable) - 1);
 
-		v19 += Audio::ADPCMStream::_stepAdjustTable[v32];
-		v19 = CLIP<int32>(v19, 0, ARRAYSIZE(Audio::Ima_ADPCMStream::_imaTable) - 1);
-
-		if (v31)
-			v18 -= v34;
+		if (code & 0x8)
+			samp -= E;
 		else
-			v18 += v34;
+			samp += E;
 
-		if (v18 > 32767)
-			v18 = 32767;
-		else if (v18 < -32768)
-			v18 = -32768;
+		samp = CLIP<int32>(samp, -32768, 32767);
 
-		*dest = v18;
-		comp += v29;
+		*dest = samp;
+		if (isOddSample)
+			comp++;
 		dest++;
 	}
 
-	_lastADPCMval1 = v18;
-	_lastADPCMval2 = v19;
+	_lastSample = samp;
+	_lastStepIndex = stepIndex;
 }
 
 void AudioStreamInstance::play(bool fade, Audio::Mixer::SoundType soundType) {
diff --git a/engines/toon/audio.h b/engines/toon/audio.h
index 52ca21b..61a5342 100644
--- a/engines/toon/audio.h
+++ b/engines/toon/audio.h
@@ -84,8 +84,8 @@ protected:
 	Audio::SoundHandle _handle;
 	Audio::Mixer::SoundType _soundType;
 	Audio::Mixer *_mixer;
-	int32 _lastADPCMval1;
-	int32 _lastADPCMval2;
+	int32 _lastSample;
+	int32 _lastStepIndex;
 	bool _stopped;
 	AudioManager *_man;
 	int32 _totalSize;






More information about the Scummvm-git-logs mailing list