[Scummvm-cvs-logs] scummvm master -> 83bb4fdb38fa2bdff7ea2cdded7c7afbbff40812

criezy criezy at scummvm.org
Mon Sep 8 22:44:53 CEST 2014


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:
83bb4fdb38 I18N: Really fix speech endianness heuristic on big endian system


Commit: 83bb4fdb38fa2bdff7ea2cdded7c7afbbff40812
    https://github.com/scummvm/scummvm/commit/83bb4fdb38fa2bdff7ea2cdded7c7afbbff40812
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2014-09-08T21:42:29+01:00

Commit Message:
I18N: Really fix speech endianness heuristic on big endian system

The previous commit was wrong because the endianness does not only
impact the data sample values but also the way the speech is uncompressed.

Changed paths:
    engines/sword1/sound.cpp
    engines/sword1/sound.h



diff --git a/engines/sword1/sound.cpp b/engines/sword1/sound.cpp
index ef4a2ee..37f92fc 100644
--- a/engines/sword1/sound.cpp
+++ b/engines/sword1/sound.cpp
@@ -126,51 +126,42 @@ void Sound::checkSpeechFileEndianness() {
 	if (sampleSize) {
 		uint32 size;
 		// Compute average of difference between two consecutive samples for both BE and LE
-		// The way uncompressSpeech works we may get un incorrect number of identical consecutive samples
-		// when using the wrong endianess. To avoid biasing the result we this we skip all duplicate values.
 		_bigEndianSpeech = false;
 		int16 *data = uncompressSpeech(index + _cowHeaderSize, sampleSize, &size);
-		if (data) {
-			uint32 max_cpt = size > 2000 ? 2000 : size;
-			double le_diff_sum = 0.;
-			uint32 le_cpt = 0;
-			for (uint32 i = 1; i < size && le_cpt < max_cpt; ++i) {
-				if (data[i] != data[i-1]) {
-					le_diff_sum += fabs((double)(data[i] - data[i - 1]));
-					++le_cpt;
-				}
-			}
-			le_diff_sum /= le_cpt;
-			delete[] data;
-			_bigEndianSpeech = true;
-			data = uncompressSpeech(index + _cowHeaderSize, sampleSize, &size);
-			if (data) {
-				double be_diff_sum = 0.;
-				uint32 be_cpt = 0;
-				for (uint32 i = 1; i < size && be_cpt < le_cpt; ++i) {
-					if (data[i] != data[i-1]) {
-						be_diff_sum += fabs((double)(data[i] - data[i - 1]));
-						++be_cpt;
-					}
-				}
-				be_diff_sum /= be_cpt;
-				delete [] data;
-				// Set the big endian flag
-				// uncompreesSpeech gives data in little endian, so on big endian systems the heuristic is actually reversed
-#ifdef SCUMM_BIG_ENDIAN
-				_bigEndianSpeech = (le_diff_sum < be_diff_sum);
-#else
-				_bigEndianSpeech = (be_diff_sum < le_diff_sum);
-#endif
-				if (_bigEndianSpeech)
-					debug(6, "Mac version: using big endian speech file");
-				else
-					debug(6, "Mac version: using little endian speech file");
-				debug(8, "Speech endianness heuristic: average = %f for BE (%d samples) and %f for LE (%d samples)", be_diff_sum, be_cpt, le_diff_sum, le_cpt);
-			} else
-				_bigEndianSpeech = false;
+		uint32 maxSamples = size > 2000 ? 2000 : size;
+		double le_diff = endiannessHeuristicValue(data, size, maxSamples);
+		delete[] data;
+		_bigEndianSpeech = true;
+		data = uncompressSpeech(index + _cowHeaderSize, sampleSize, &size);
+		double be_diff = endiannessHeuristicValue(data, size, maxSamples);
+		delete [] data;
+		// Set the big endian flag
+		_bigEndianSpeech = (be_diff < le_diff);
+		if (_bigEndianSpeech)
+			debug(6, "Mac version: using big endian speech file");
+		else
+			debug(6, "Mac version: using little endian speech file");
+		debug(8, "Speech endianness heuristic: average = %f for BE and %f for LE (%d samples)", be_diff, le_diff, maxSamples);
+	}
+}
+											   
+double Sound::endiannessHeuristicValue(int16* data, uint32 dataSize, uint32 &maxSamples) {
+	if (!data)
+		return 50000.; // the heuristic value for the wrong endianess is about 21000 (1/3rd of the 16 bits range)
+
+	double diff_sum = 0.;
+	uint32 cpt = 0;
+	int16 prev_value = (int16)FROM_LE_16(*((uint16 *)(data)));
+	for (uint32 i = 1; i < dataSize && cpt < maxSamples; ++i) {
+		int16 value = (int16)FROM_LE_16(*((uint16 *)(data + i)));
+		if (value != prev_value) {
+			diff_sum += fabs((double)(value - prev_value));
+			++cpt;
+			prev_value = value;
 		}
 	}
+	maxSamples = cpt;
+	return diff_sum / cpt;
 }
 
 
diff --git a/engines/sword1/sound.h b/engines/sword1/sound.h
index 54006bd..e65e797 100644
--- a/engines/sword1/sound.h
+++ b/engines/sword1/sound.h
@@ -102,6 +102,7 @@ public:
 	void engine();
 
 	void checkSpeechFileEndianness();
+	double endiannessHeuristicValue(int16* data, uint32 dataSize, uint32 &maxSamples);
 
 private:
 	uint8 _sfxVolL, _sfxVolR, _speechVolL, _speechVolR;






More information about the Scummvm-git-logs mailing list