[Scummvm-git-logs] scummvm-tools master -> c44c25561c9f16897f51ff41a485cc4e7099f088

bonki bonki at users.noreply.github.com
Sun Jun 10 00:00:30 CEST 2018


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

Summary:
c44c25561c TOOLS: Fix internal FLAC encoder


Commit: c44c25561c9f16897f51ff41a485cc4e7099f088
    https://github.com/scummvm/scummvm-tools/commit/c44c25561c9f16897f51ff41a485cc4e7099f088
Author: Adrian Frühwirth (bonki at users.noreply.github.com)
Date: 2018-06-09T23:37:27+02:00

Commit Message:
TOOLS: Fix internal FLAC encoder

This commit fixes the internal FLAC encoder to properly handle
input of different endianness which means compressing audio with FLAC
should now work as expected on all supported platforms.

Up until now the encoder only worked with signed 16-bit PCM in native
endianess which worked in most cases because most games using 16-bit
audio use pcm_s16le and scummvm-tools are usually run on LE x86/x86_64
hardware.

Two cases of s16be audio are the recently unlocked (see commit 72655d8)
speech sample in Indiana Jones and the Fate of Atlantis as well as
certain Mac versions of Broken Sword 1.

Changed paths:
    compress.cpp
    engines/scumm/compress_scumm_sou.cpp


diff --git a/compress.cpp b/compress.cpp
index f62e6e0..218acd3 100644
--- a/compress.cpp
+++ b/compress.cpp
@@ -310,7 +310,6 @@ void CompressionTool::encodeAudio(const char *inname, bool rawInput, int rawSamp
 }
 
 void CompressionTool::encodeRaw(const char *rawData, int length, int samplerate, const char *outname, AudioFormat compmode) {
-
 	print(" - len=%ld, ch=%d, rate=%d, %dbits", length, (rawAudioType.isStereo ? 2 : 1), samplerate, rawAudioType.bitsPerSample);
 
 #ifdef USE_VORBIS
@@ -529,14 +528,19 @@ void CompressionTool::encodeRaw(const char *rawData, int length, int samplerate,
 
 		if (rawAudioType.bitsPerSample == 8) {
 			for (i = 0; i < samplesPerChannel * numChannels; i++) {
-				const FLAC__uint8 *rawDataUnsigned = (const FLAC__uint8 *)rawData;
-				flacData[i] = (FLAC__int32)rawDataUnsigned[i] - 0x80;
+				flacData[i] = (FLAC__int32)(FLAC__uint8)rawData[i] - 0x80;
 			}
 		} else if (rawAudioType.bitsPerSample == 16) {
-			/* The rawData pointer is an 8-bit char so we must create a new pointer to access 16-bit samples */
-			const FLAC__int16 *rawData16 = (const FLAC__int16 *)rawData;
-			for (i = 0; i < samplesPerChannel * numChannels; i++) {
-				flacData[i] = (FLAC__int32)rawData16[i];
+			if (rawAudioType.isLittleEndian) {
+				for (i = 0; i < samplesPerChannel * numChannels; i++) {
+					flacData[i] = (FLAC__int32)((FLAC__int16)(FLAC__int8)(FLAC__byte)rawData[2 * i + 1] << 8 |
+								                (FLAC__int16)(FLAC__byte)rawData[2 * i    ]);
+				}
+			} else {
+				for (i = 0; i < samplesPerChannel * numChannels; i++) {
+					flacData[i] = (FLAC__int32)((FLAC__int16)(FLAC__int8)(FLAC__byte)rawData[2 * i    ] << 8 |
+								                (FLAC__int16)(FLAC__byte)rawData[2 * i + 1]);
+				}
 			}
 		}
 
diff --git a/engines/scumm/compress_scumm_sou.cpp b/engines/scumm/compress_scumm_sou.cpp
index 70cf647..815288a 100644
--- a/engines/scumm/compress_scumm_sou.cpp
+++ b/engines/scumm/compress_scumm_sou.cpp
@@ -178,7 +178,6 @@ bool CompressScummSou::get_part() {
 	_output_idx.writeUint32BE(tot_size);
 
 	updateProgress(_input.pos(), _file_size);
-
 	return true;
 }
 





More information about the Scummvm-git-logs mailing list