aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorThierry Crozat2014-09-05 07:46:42 +0100
committerThierry Crozat2014-09-05 07:46:42 +0100
commit8eb82fd6c1c65ad0590462853ade281101068afa (patch)
tree30b7669c373f291b56890fceb0041ebd62460f6a /engines
parentbfbcc9f3e402f4b3180553374f6eeb8f7136808b (diff)
downloadscummvm-rg350-8eb82fd6c1c65ad0590462853ade281101068afa.tar.gz
scummvm-rg350-8eb82fd6c1c65ad0590462853ade281101068afa.tar.bz2
scummvm-rg350-8eb82fd6c1c65ad0590462853ade281101068afa.zip
SWORD1: Fix heuristic to determine the endianess of the speech in mac version
Because the data is compressed (a repeated sample is coded as a negative length followed by the value), when the length is read with the wrong endianess we get completely wrong data. So to get the BE data we cannot just read them assuming LE and byteswap afterward.
Diffstat (limited to 'engines')
-rw-r--r--engines/sword1/sound.cpp38
1 files changed, 23 insertions, 15 deletions
diff --git a/engines/sword1/sound.cpp b/engines/sword1/sound.cpp
index 0b4d3829d6..ddde7f4235 100644
--- a/engines/sword1/sound.cpp
+++ b/engines/sword1/sound.cpp
@@ -125,31 +125,39 @@ void Sound::checkSpeechFileEndianness() {
uint32 index = _cowHeader[locIndex + (localNo * 2) - 1];
if (sampleSize) {
uint32 size;
- double be_diff_sum = 0., le_diff_sum = 0.;
+ // Compute average of difference between two consecutive samples for both BE and LE
_bigEndianSpeech = false;
int16 *data = uncompressSpeech(index + _cowHeaderSize, sampleSize, &size);
- // Compute average of difference between two consecutive samples for both BE and LE
if (data) {
if (size > 4000)
size = 2000;
else
size /= 2;
- int16 prev_be_value = (int16)SWAP_BYTES_16(*((uint16 *)(data)));
- for (uint32 i = 1; i < size; ++i) {
+ double le_diff_sum = 0.;
+ for (uint32 i = 1; i < size; ++i)
le_diff_sum += fabs((double)(data[i] - data[i - 1]));
- int16 be_value = (int16)SWAP_BYTES_16(*((uint16 *)(data + i)));
- be_diff_sum += fabs((double)(be_value - prev_be_value));
- prev_be_value = be_value;
- }
delete[] data;
+ _bigEndianSpeech = true;
+ data = uncompressSpeech(index + _cowHeaderSize, sampleSize, &size);
+ if (data) {
+ if (size > 4000)
+ size = 2000;
+ else
+ size /= 2;
+ double be_diff_sum = 0.;
+ for (uint32 i = 1; i < size; ++i)
+ be_diff_sum += fabs((double)(data[i] - data[i - 1]));
+ delete [] data;
+ // Set the big endian flag
+ _bigEndianSpeech = (be_diff_sum < le_diff_sum);
+ 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, computed on %d samples)", be_diff_sum / (size - 1), le_diff_sum / (size - 1), size);
+ } else
+ _bigEndianSpeech = false;
}
- // Set the big endian flag
- _bigEndianSpeech = (be_diff_sum < le_diff_sum);
- 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, computed on %d samples)", be_diff_sum / (size - 1), le_diff_sum / (size - 1), size);
}
}