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.
This commit is contained in:
Adrian Frühwirth
2018-06-07 01:01:55 +02:00
parent 72655d828c
commit c44c25561c
2 changed files with 11 additions and 8 deletions
+11 -7
View File
@@ -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]);
}
}
}
-1
View File
@@ -178,7 +178,6 @@ bool CompressScummSou::get_part() {
_output_idx.writeUint32BE(tot_size);
updateProgress(_input.pos(), _file_size);
return true;
}