[Scummvm-cvs-logs] SF.net SVN: scummvm: [24593] tools/trunk

cyx at users.sourceforge.net cyx at users.sourceforge.net
Fri Nov 3 22:32:43 CET 2006


Revision: 24593
          http://svn.sourceforge.net/scummvm/?rev=24593&view=rev
Author:   cyx
Date:     2006-11-03 13:32:34 -0800 (Fri, 03 Nov 2006)

Log Message:
-----------
added compression tool for touche speech data files

Modified Paths:
--------------
    tools/trunk/Makefile
    tools/trunk/Makefile.mingw
    tools/trunk/README
    tools/trunk/compress.c

Added Paths:
-----------
    tools/trunk/compress_touche.c

Modified: tools/trunk/Makefile
===================================================================
--- tools/trunk/Makefile	2006-11-03 21:23:07 UTC (rev 24592)
+++ tools/trunk/Makefile	2006-11-03 21:32:34 UTC (rev 24593)
@@ -13,7 +13,7 @@
 CFLAGS+= -pedantic
 CFLAGS+= -Wpointer-arith -Wcast-qual -Wcast-align
 # -Wconversion
-CFLAGS+= -Wshadow -Wimplicit -Wundef -Wwrite-strings 
+CFLAGS+= -Wshadow -Wimplicit -Wundef -Wwrite-strings
 
 TARGETS := \
 	compress_kyra$(EXEEXT) \
@@ -25,6 +25,7 @@
 	compress_simon$(EXEEXT) \
 	compress_sword1$(EXEEXT) \
 	compress_sword2$(EXEEXT) \
+	compress_touche$(EXEEXT) \
 	dekyra$(EXEEXT) \
 	descumm$(EXEEXT) \
 	desword2$(EXEEXT) \
@@ -74,6 +75,9 @@
 compress_sword2$(EXEEXT): compress_sword2.o compress.o util.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
+compress_touche$(EXEEXT): compress_touche.o compress.o util.o
+	$(CC) $(LDFLAGS) -o $@ $+
+
 dekyra$(EXEEXT): dekyra.o dekyra_v1.o util.o
 	$(CXX) $(LDFLAGS) -o $@ $+
 

Modified: tools/trunk/Makefile.mingw
===================================================================
--- tools/trunk/Makefile.mingw	2006-11-03 21:23:07 UTC (rev 24592)
+++ tools/trunk/Makefile.mingw	2006-11-03 21:32:34 UTC (rev 24593)
@@ -20,6 +20,7 @@
 	strip compress_simon.exe -o $(SCUMMVMPATH)/tools/compress_simon.exe
 	strip compress_sword1.exe -o $(SCUMMVMPATH)/tools/compress_sword1.exe
 	strip compress_sword2.exe -o $(SCUMMVMPATH)/tools/compress_sword2.exe
+	strip compress_touche.exe -o $(SCUMMVMPATH)/tools/compress_touche.exe
 	strip dekyra.exe -o $(SCUMMVMPATH)/tools/dekyra.exe
 	strip descumm.exe -o $(SCUMMVMPATH)/tools/descumm.exe
 	strip desword2.exe -o $(SCUMMVMPATH)/tools/desword2.exe

Modified: tools/trunk/README
===================================================================
--- tools/trunk/README	2006-11-03 21:23:07 UTC (rev 24592)
+++ tools/trunk/README	2006-11-03 21:32:34 UTC (rev 24593)
@@ -39,7 +39,7 @@
                 McKracken.
 
 Compression Tools:
-        compress_scumm_sou 
+        compress_scumm_sou
                 Used to compress .sou files to .so3 (MP3), .sog (Vorbis),
                 or .sof (FLAC).
 
@@ -69,6 +69,9 @@
                 than the original! This is because the original files already
                 use lossy compression.
 
+        compress_touche
+                Used to compress Touche speech files to MP3, Vorbis or FLAC.
+
         compress_scumm_san <inputfile> <inputdir> <outputdir> [--ogg]
                 Compresses '.san' smush animation files. It uses lossless
                 zlib for compressing FOBJ gfx chunks inside a san file.
@@ -77,18 +80,18 @@
                 Example of usage:
                 compress_Scumm_san opening.san uncomp comp
 
-                In order to use such compressed files, your ScummVM binary 
+                In order to use such compressed files, your ScummVM binary
                 must have been built with zlib support enabled (you can find
                 out whether that's the case by looking at the About dialog).
                 For the Ogg or Mad compression feature, your ScummVM binary
                 naturally must have been built with Ogg or Mad support enabled.
-                
+
                 NOTE: For some '.san' files there is a corresponding '.flu'
                 file, which contains offsets into the '.san' file. Hence, the
                 compress_scumm_san has to modify the '.flu' file. This happens
                 automatically, if the '.san' and '.flu' files are in the
                 same directory (which is normally the case). If you want to
-                move the '.san' files before compressing them, make sure to 
+                move the '.san' files before compressing them, make sure to
                 move the '.flu' files, too!
 
         compress_scumm_bun <inputfile> <inputdir> <outputdir> [--ogg]
@@ -102,7 +105,7 @@
                 naturally must have been built with Ogg or Mad support enabled.
 
         compress_kyra
-                Used to compress The Legend of Kyrandia's speech files with 
+                Used to compress The Legend of Kyrandia's speech files with
                 MP3, Vorbis or FLAC.
 
                 Example of usage:

Modified: tools/trunk/compress.c
===================================================================
--- tools/trunk/compress.c	2006-11-03 21:23:07 UTC (rev 24592)
+++ tools/trunk/compress.c	2006-11-03 21:32:34 UTC (rev 24593)
@@ -24,7 +24,7 @@
 
 typedef struct  {
 	uint32 minBitr;
-	uint32 maxBitr; 
+	uint32 maxBitr;
 	bool abr;
 	uint32 algqual;
 	uint32 vbrqual;
@@ -101,7 +101,7 @@
     if (freq <= 24000) return 24000;
     if (freq <= 32000) return 32000;
     if (freq <= 44100) return 44100;
-    
+
     return 48000;
 }
 
@@ -201,7 +201,7 @@
 		printf("Encoder Commandline: %s\n", fbuf );
 		exit(-1);
 	}
-} 
+}
 
 void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode) {
 	int length;
@@ -231,7 +231,9 @@
 
 void extractAndEncodeVOC(const char *outName, FILE *input, CompressMode compMode) {
 	FILE *f;
+	int bits;
 	int blocktype;
+	int channels;
 	int length;
 	int sample_rate;
 	int comp;
@@ -242,7 +244,7 @@
 	f = fopen(outName, "wb");
 
 	while ((blocktype = fgetc(input))) {
-		if (blocktype != 1) {
+		if (blocktype != 1 && blocktype != 9) {
 			/*
 			   We only generate a warning, instead of erroring out, because
 			   at least the monster.sou file of Full Throttle contains VOCs
@@ -253,18 +255,29 @@
 			warning("Unsupported VOC block type: %02x", blocktype);
 			break;
 		}
-	
+
 		/* Sound Data */
 		printf(" Sound Data\n");
 		length = fgetc(input);
 		length |= fgetc(input) << 8;
 		length |= fgetc(input) << 16;
-		length -= 2;
-		sample_rate = fgetc(input);
-		comp = fgetc(input);
+		if (blocktype == 1) {
+			length -= 2;
+			sample_rate = fgetc(input);
+			comp = fgetc(input);
+			real_samplerate = getSampleRateFromVOCRate(sample_rate);
+		} else { /* (blocktype == 9) */
+			length -= 12;
+			real_samplerate = sample_rate = readUint32LE(input);
+			bits = fgetc(input);
+			channels = fgetc(input);
+			if (bits != 8 || channels != 1) {
+				error("Unsupported VOC file format (%d bits per sample, %d channels)", bits, channels);
+			}
+			comp = readUint16LE(input);
+			readUint32LE(input);
+		}
 
-		real_samplerate = getSampleRateFromVOCRate(sample_rate);
-
 		printf(" - length = %d\n", length);
 		printf(" - sample rate = %d (%02x)\n", real_samplerate, sample_rate);
 		printf(" - compression = %s (%02x)\n",
@@ -282,13 +295,13 @@
 			size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : (uint32)length, input);
 			if (size <= 0)
 				break;
-			length -= (int)size; 
+			length -= (int)size;
 			fwrite(fbuf, 1, size, f);
 		}
 	}
 
 	fclose(f);
-	
+
 	assert(real_samplerate != -1);
 
 	setRawAudioType(false, false, 8);

Added: tools/trunk/compress_touche.c
===================================================================
--- tools/trunk/compress_touche.c	                        (rev 0)
+++ tools/trunk/compress_touche.c	2006-11-03 21:32:34 UTC (rev 24593)
@@ -0,0 +1,245 @@
+/* compress_touche - Compress Touche Speech Data Files
+ * Copyright (C) 2006  The ScummVM Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id: $
+ *
+ */
+
+#include "compress.h"
+
+#define CURRENT_VER     1
+#define HEADER_SIZE     4
+#define MAX_OFFSETS   140
+#define OBJ_HDR_LEN   200
+#define Vxx_HDR_LEN  1024
+
+#define OUTPUT_MP3   "TOUCHE.SO3"
+#define OUTPUT_OGG   "TOUCHE.SOG"
+#define OUTPUT_FLA   "TOUCHE.SOF"
+
+static CompressMode g_mode = kMP3Mode;
+static const char *g_output_filename = OUTPUT_MP3;
+static const char *g_input_directory = NULL;
+
+static uint32 input_OBJ_offs[OBJ_HDR_LEN];
+static uint32 input_OBJ_size[OBJ_HDR_LEN];
+static uint32 input_Vxx_offs[Vxx_HDR_LEN];
+static uint32 input_Vxx_size[Vxx_HDR_LEN];
+
+static uint32 compress_sound_data_file(uint32 current_offset, FILE *output, FILE *input, uint32 *offs_table, uint32 *size_table, int len) {
+	FILE *temp;
+	int i, size;
+	uint8 buf[2048];
+	uint32 start_offset = current_offset;
+
+	/* write 0 offsets/sizes table */
+	for (i = 0; i < len; ++i) {
+		offs_table[i] = readUint32LE(input);
+		size_table[i] = readUint32LE(input);
+		writeUint32LE(output, 0);
+		writeUint32LE(output, 0);
+		current_offset += 8;
+	}
+	for (i = 0; i < len; ++i) {
+		if (size_table[i] == 0) {
+			offs_table[i] = 0;
+		} else {
+			fseek(input, offs_table[i], SEEK_SET);
+			fread(buf, 1, 8, input);
+			if (memcmp(buf, "Creative", 8) != 0) {
+				error("Invalid VOC data found");
+			}
+			printf("VOC found (pos = %d) :\n", offs_table[i]);
+			fseek(input, 18, SEEK_CUR);
+			extractAndEncodeVOC(TEMP_RAW, input, g_mode);
+
+			/* append converted data to output file */
+			temp = fopen(tempEncoded, "rb");
+			if (!temp) {
+				error("Cannot open file '%s' for reading", tempEncoded);
+			}
+			size_table[i] = 0;
+			while ((size = fread(buf, 1, 2048, temp)) > 0) {
+				fwrite(buf, 1, size, output);
+				size_table[i] += size;
+			}
+			fclose(temp);
+			offs_table[i] = current_offset;
+			current_offset += size_table[i];
+		}
+	}
+
+	/* fix data offsets table */
+	fseek(output, start_offset, SEEK_SET);
+	for (i = 0; i < len; ++i) {
+		writeUint32LE(output, offs_table[i]);
+		writeUint32LE(output, size_table[i]);
+	}
+	fseek(output, 0, SEEK_END);
+
+	fclose(input);
+
+	return current_offset;
+}
+
+static void compress_sound_data() {
+	int i;
+	char filepath[512];
+	FILE *output, *input;
+	uint32 current_offset;
+	uint32 offsets_table[MAX_OFFSETS];
+
+	output = fopen(g_output_filename, "wb");
+	if (!output) {
+		error("Cannot open file '%s' for writing", g_output_filename);
+	}
+
+	writeUint16LE(output, 1); /* current version */
+	writeUint16LE(output, 0); /* flags */
+
+	current_offset = HEADER_SIZE;
+
+	/* write 0 offsets table */
+	for (i = 0; i < MAX_OFFSETS; ++i) {
+		offsets_table[i] = 0;
+		writeUint32LE(output, offsets_table[i]);
+		current_offset += 4;
+	}
+
+	/* process 'OBJ' file */
+	sprintf(filepath, "%s/OBJ", g_input_directory);
+	input = fopen(filepath, "rb");
+	if (!input) {
+		error("Cannot open file 'OBJ' for reading");
+	}
+	offsets_table[0] = current_offset;
+	current_offset = compress_sound_data_file(current_offset, output, input, input_OBJ_offs, input_OBJ_size, OBJ_HDR_LEN);
+	fclose(input);
+	printf("Processed '%s'.\n", filepath);
+
+	/* process Vxx files */
+	for (i = 1; i < MAX_OFFSETS; ++i) {
+		sprintf(filepath, "%s/V%d", g_input_directory, i);
+		input = fopen(filepath, "rb");
+		if (input) {
+			offsets_table[i] = current_offset;
+			current_offset = compress_sound_data_file(current_offset, output, input, input_Vxx_offs, input_Vxx_size, Vxx_HDR_LEN);
+			fclose(input);
+			printf("Processed '%s'.\n", filepath);
+		}
+	}
+
+	/* fix global offsets table at the beginning of the file */
+	fseek(output, HEADER_SIZE, SEEK_SET);
+	for (i = 0; i < MAX_OFFSETS; ++i) {
+		writeUint32LE(output, offsets_table[i]);
+	}
+
+	fclose(output);
+
+	/* cleanup */
+	unlink(TEMP_RAW);
+	unlink(tempEncoded);
+
+	printf("Done.\n");
+}
+
+static void showhelp(const char *exename) {
+	printf("\nUsage: %s <params> input_directory\n", exename);
+
+	printf("\nParams:\n");
+	printf(" --mp3        encode to MP3 format (default)\n");
+	printf(" --vorbis     encode to Vorbis format\n");
+	printf(" --flac       encode to Flac format\n");
+	printf("(If one of these is specified, it must be the first parameter.)\n");
+
+	printf("\nMP3 mode params:\n");
+	printf(" -b <rate>    <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%d)\n", minBitrDef);
+	printf(" -B <rate>    <rate> is the maximum VBR/ABR bitrate (default:%d)\n", maxBitrDef);
+	printf(" --vbr        LAME uses the VBR mode (default)\n");
+	printf(" --abr        LAME uses the ABR mode\n");
+	printf(" -V <value>   specifies the value (0 - 9) of VBR quality (0=best) (default:%d)\n", vbrqualDef);
+	printf(" -q <value>   specifies the MPEG algorithm quality (0-9; 0=best) (default:%d)\n", algqualDef);
+	printf(" --silent     the output of LAME is hidden (default:disabled)\n");
+
+	printf("\nVorbis mode params:\n");
+	printf(" -b <rate>    <rate> is the nominal bitrate (default:unset)\n");
+	printf(" -m <rate>    <rate> is the minimum bitrate (default:unset)\n");
+	printf(" -M <rate>    <rate> is the maximum bitrate (default:unset)\n");
+	printf(" -q <value>   specifies the value (0 - 10) of VBR quality (10=best) (default:%d)\n", oggqualDef);
+	printf(" --silent     the output of oggenc is hidden (default:disabled)\n");
+
+	printf("\nFlac mode params:\n");
+	printf(" [params]     optional arguments passed directly to the encoder\n");
+	printf("              recommended is: --best -b 1152\n");
+
+	printf("\n --help     this help message\n");
+
+	printf("\n\nIf a parameter is not given the default value is used\n");
+	printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
+	exit(2);
+}
+
+int main(int argc, char *argv[]) {
+	int i;
+
+	if (argc < 2) {
+		showhelp(argv[0]);
+	}
+
+	i = 1;
+	if (strcmp(argv[1], "--mp3") == 0) {
+		g_mode = kMP3Mode;
+		g_output_filename = OUTPUT_MP3;
+		++i;
+	} else if (strcmp(argv[1], "--vorbis") == 0) {
+		g_mode = kVorbisMode;
+		g_output_filename = OUTPUT_OGG;
+		++i;
+	} else if (strcmp(argv[1], "--flac") == 0) {
+		g_mode = kFlacMode;
+		g_output_filename = OUTPUT_FLA;
+		++i;
+	}
+
+	g_input_directory = argv[argc - 1];
+
+	switch (g_mode) {
+	case kMP3Mode:
+		tempEncoded = TEMP_MP3;
+		if (!process_mp3_parms(argc, argv, i)) {
+			showhelp(argv[0]);
+		}
+		break;
+	case kVorbisMode:
+		tempEncoded = TEMP_OGG;
+		if (!process_ogg_parms(argc, argv, i)) {
+			showhelp(argv[0]);
+		}
+		break;
+	case kFlacMode:
+		tempEncoded = TEMP_FLAC;
+		if (!process_flac_parms(argc, argv, i)) {
+			showhelp(argv[0]);
+		}
+		break;
+	}
+
+	compress_sound_data();
+	return 0;
+}


Property changes on: tools/trunk/compress_touche.c
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + "Date Rev Author URL Id"
Name: svn:eol-style
   + native


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list