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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Feb 25 15:37:17 CET 2008


Revision: 30964
          http://scummvm.svn.sourceforge.net/scummvm/?rev=30964&view=rev
Author:   fingolfin
Date:     2008-02-25 06:37:16 -0800 (Mon, 25 Feb 2008)

Log Message:
-----------
Moved all tools sources to C++; grafted parts of the main ScummVM build system onto the tools build system, allowing e.g. automatic dependency tracking

Modified Paths:
--------------
    tools/trunk/Makefile
    tools/trunk/dist/msvc8/compress_agos.vcproj
    tools/trunk/dist/msvc8/compress_kyra.vcproj
    tools/trunk/dist/msvc8/compress_queen.vcproj
    tools/trunk/dist/msvc8/compress_saga.vcproj
    tools/trunk/dist/msvc8/compress_scumm_bun.vcproj
    tools/trunk/dist/msvc8/compress_scumm_san.vcproj
    tools/trunk/dist/msvc8/compress_scumm_sou.vcproj
    tools/trunk/dist/msvc8/compress_sword1.vcproj
    tools/trunk/dist/msvc8/compress_sword2.vcproj
    tools/trunk/dist/msvc8/compress_touche.vcproj
    tools/trunk/dist/msvc8/dekyra.vcproj
    tools/trunk/dist/msvc8/descumm.vcproj
    tools/trunk/dist/msvc8/desword2.vcproj
    tools/trunk/dist/msvc8/encode_dxa.vcproj
    tools/trunk/dist/msvc8/extract_agos.vcproj
    tools/trunk/dist/msvc8/extract_kyra.vcproj
    tools/trunk/dist/msvc8/extract_loom_tg16.vcproj
    tools/trunk/dist/msvc8/extract_mm_apple.vcproj
    tools/trunk/dist/msvc8/extract_mm_c64.vcproj
    tools/trunk/dist/msvc8/extract_mm_nes.vcproj
    tools/trunk/dist/msvc8/extract_parallaction.vcproj
    tools/trunk/dist/msvc8/extract_scumm_mac.vcproj
    tools/trunk/dist/msvc8/extract_zak_c64.vcproj
    tools/trunk/dist/msvc9/compress_agos.vcproj
    tools/trunk/dist/msvc9/compress_kyra.vcproj
    tools/trunk/dist/msvc9/compress_queen.vcproj
    tools/trunk/dist/msvc9/compress_saga.vcproj
    tools/trunk/dist/msvc9/compress_scumm_bun.vcproj
    tools/trunk/dist/msvc9/compress_scumm_san.vcproj
    tools/trunk/dist/msvc9/compress_scumm_sou.vcproj
    tools/trunk/dist/msvc9/compress_sword1.vcproj
    tools/trunk/dist/msvc9/compress_sword2.vcproj
    tools/trunk/dist/msvc9/compress_touche.vcproj
    tools/trunk/dist/msvc9/dekyra.vcproj
    tools/trunk/dist/msvc9/descumm.vcproj
    tools/trunk/dist/msvc9/desword2.vcproj
    tools/trunk/dist/msvc9/encode_dxa.vcproj
    tools/trunk/dist/msvc9/extract_agos.vcproj
    tools/trunk/dist/msvc9/extract_kyra.vcproj
    tools/trunk/dist/msvc9/extract_loom_tg16.vcproj
    tools/trunk/dist/msvc9/extract_mm_apple.vcproj
    tools/trunk/dist/msvc9/extract_mm_c64.vcproj
    tools/trunk/dist/msvc9/extract_mm_nes.vcproj
    tools/trunk/dist/msvc9/extract_parallaction.vcproj
    tools/trunk/dist/msvc9/extract_scumm_mac.vcproj
    tools/trunk/dist/msvc9/extract_zak_c64.vcproj

Added Paths:
-----------
    tools/trunk/compress.cpp
    tools/trunk/compress_agos.cpp
    tools/trunk/compress_queen.cpp
    tools/trunk/compress_scumm_sou.cpp
    tools/trunk/compress_sword1.cpp
    tools/trunk/compress_sword2.cpp
    tools/trunk/compress_touche.cpp
    tools/trunk/desword2.cpp
    tools/trunk/extract_agos.cpp
    tools/trunk/extract_loom_tg16.cpp
    tools/trunk/extract_mm_apple.cpp
    tools/trunk/extract_mm_c64.cpp
    tools/trunk/extract_mm_nes.cpp
    tools/trunk/extract_scumm_mac.cpp
    tools/trunk/extract_zak_c64.cpp
    tools/trunk/util.cpp

Removed Paths:
-------------
    tools/trunk/compress.c
    tools/trunk/compress_agos.c
    tools/trunk/compress_queen.c
    tools/trunk/compress_scumm_sou.c
    tools/trunk/compress_sword1.c
    tools/trunk/compress_sword2.c
    tools/trunk/compress_touche.c
    tools/trunk/desword2.c
    tools/trunk/extract_agos.c
    tools/trunk/extract_loom_tg16.c
    tools/trunk/extract_mm_apple.c
    tools/trunk/extract_mm_c64.c
    tools/trunk/extract_mm_nes.c
    tools/trunk/extract_scumm_mac.c
    tools/trunk/extract_zak_c64.c
    tools/trunk/util.c

Property Changed:
----------------
    tools/trunk/
    tools/trunk/utils/


Property changes on: tools/trunk
___________________________________________________________________
Name: svn:ignore
   - compress_agos
compress_kyra
compress_queen
compress_saga
compress_scumm_bun
compress_scumm_san
compress_scumm_sou
compress_sword1
compress_sword2
compress_touche
dekyra
descumm
desword2
encode_dxa
extract_agos
extract_kyra
extract_loom_tg16
extract_mm_apple
extract_mm_nes
extract_mm_c64
extract_parallaction
extract_scumm_mac
extract_zak_c64
tools_gui


   + .deps
compress_agos
compress_kyra
compress_queen
compress_saga
compress_scumm_bun
compress_scumm_san
compress_scumm_sou
compress_sword1
compress_sword2
compress_touche
dekyra
descumm
desword2
encode_dxa
extract_agos
extract_kyra
extract_loom_tg16
extract_mm_apple
extract_mm_nes
extract_mm_c64
extract_parallaction
extract_scumm_mac
extract_zak_c64
tools_gui



Modified: tools/trunk/Makefile
===================================================================
--- tools/trunk/Makefile	2008-02-25 14:13:12 UTC (rev 30963)
+++ tools/trunk/Makefile	2008-02-25 14:37:16 UTC (rev 30964)
@@ -1,20 +1,61 @@
 # $URL$
 # $Id$
 
-SRC=.
+#######################################################################
+# Default compilation parameters. Normally don't edit these           #
+#######################################################################
 
+srcdir      ?= .
+
+DEFINES     := -DUNIX
+LDFLAGS     :=
+INCLUDES    := -I. -I$(srcdir)
+LIBS        :=
+OBJS        :=
+DEPDIR      := .deps
+
+# Load the make rules generated by configure
+# HACK: We don't yet support configure in the tools SVN module, but at least one can
+# manually create a config.mk files with overrides, if needed.
+-include config.mk
+
+CXXFLAGS  += -g -O -Wuninitialized
+
+# Additional warnings
+CXXFLAGS:= -Wall $(CXXFLAGS)
+# Turn off some annoying and not-so-useful warnings
+CXXFLAGS+= -Wno-long-long -Wno-multichar -Wno-unknown-pragmas -Wno-reorder
+# Enable even more warnings...
+CXXFLAGS+= -pedantic -Wpointer-arith -Wcast-qual -Wconversion
+CXXFLAGS+= -Wshadow -Wimplicit -Wundef -Wnon-virtual-dtor -Wwrite-strings
+
+# Disable RTTI and exceptions, and enabled checking of pointers returned by "new"
+CXXFLAGS+= -fno-rtti -fno-exceptions -fcheck-new
+
+#######################################################################
+# Default commands - put the necessary replacements in config.mk      #
+#######################################################################
+
+CAT     ?= cat
+CP      ?= cp
+ECHO    ?= printf
+INSTALL ?= install
+MKDIR   ?= mkdir -p
+RM      ?= rm -f
+RM_REC  ?= $(RM) -r
+ZIP     ?= zip -q
+
 CC      := gcc
 CXX     := g++
-CFLAGS  += -g -O -Wall -Wuninitialized -Wno-long-long -Wno-multichar -DUNIX
-# LDFLAGS +=
 
-# Additional warnings
-CFLAGS+= -Wshadow
-#CFLAGS+= -pedantic
-CFLAGS+= -Wpointer-arith -Wcast-qual -Wcast-align
-# -Wconversion
-CFLAGS+= -Wshadow -Wimplicit -Wundef -Wwrite-strings
+#######################################################################
 
+# HACK: Until we get proper module support, add these "module dirs" to 
+# get the dependency tracking code working.
+MODULE_DIRS := ./ utils/
+
+#######################################################################
+
 TARGETS := \
 	compress_agos$(EXEEXT) \
 	compress_kyra$(EXEEXT) \
@@ -58,18 +99,18 @@
 	mkdir -p $(bundle_name)/Contents/MacOS
 	mkdir -p $(bundle_name)/Contents/Resources
 	echo "APPL????" > $(bundle_name)/Contents/PkgInfo
-	cp $(SRC)/dist/macosx/Info.plist $(bundle_name)/Contents/
+	cp $(srcdir)/dist/macosx/Info.plist $(bundle_name)/Contents/
 	cp $(TARGETS) $(bundle_name)/Contents/Resources/
 	mv $(bundle_name)/Contents/Resources/tools_gui $(bundle_name)/Contents/MacOS/
 
 compress_agos$(EXEEXT): compress_agos.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
+	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_kyra$(EXEEXT): compress_kyra.o kyra_pak.o compress.o util.o
 	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_queen$(EXEEXT): compress_queen.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
+	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_saga$(EXEEXT): compress_saga.o compress.o util.o $(UTILS)
 	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
@@ -81,16 +122,16 @@
 	$(CXX) $(LDFLAGS) -o $@ $+ -lz -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_scumm_sou$(EXEEXT): compress_scumm_sou.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
+	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_sword1$(EXEEXT): compress_sword1.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
+	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_sword2$(EXEEXT): compress_sword2.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
+	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 compress_touche$(EXEEXT): compress_touche.o compress.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
+	$(CXX) $(LDFLAGS) -o $@ $+ -lvorbis -logg -lvorbisenc -lFLAC
 
 dekyra$(EXEEXT): dekyra.o dekyra_v1.o util.o
 	$(CXX) $(LDFLAGS) -o $@ $+
@@ -105,77 +146,61 @@
 	$(CXX) $(LDFLAGS) -o $@ $+ -lpng -lz -lvorbis -logg -lvorbisenc -lFLAC
 
 extract_agos$(EXEEXT): extract_agos.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CXX) $(LDFLAGS) -o $@ $+
 
 extract_kyra$(EXEEXT): extract_kyra.o kyra_pak.o util.o
 	$(CXX) $(LDFLAGS) -o $@ $+
 
 extract_loom_tg16$(EXEEXT): extract_loom_tg16.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CXX) $(LDFLAGS) -o $@ $+
 
 extract_mm_apple$(EXEEXT): extract_mm_apple.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CXX) $(LDFLAGS) -o $@ $+
 
 extract_mm_c64$(EXEEXT): extract_mm_c64.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CXX) $(LDFLAGS) -o $@ $+
 
 extract_mm_nes$(EXEEXT): extract_mm_nes.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CXX) $(LDFLAGS) -o $@ $+
 
 extract_parallaction$(EXEEXT): extract_parallaction.o util.o
 	$(CXX) $(LDFLAGS) -o $@ $+
 
 extract_scumm_mac$(EXEEXT): extract_scumm_mac.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CXX) $(LDFLAGS) -o $@ $+
 
 extract_zak_c64$(EXEEXT): extract_zak_c64.o util.o
-	$(CC) $(LDFLAGS) -o $@ $+
+	$(CXX) $(LDFLAGS) -o $@ $+
 
 tools_gui$(EXEEXT): tools_gui.o
 	$(CXX) $(LDFLAGS) -o $@ $+ `wx-config --libs`
 
 
-descumm.o descumm6.o descumm-common.o descumm-tool.o: descumm.h
+clean:
+	rm -f *.o utils/*.o $(TARGETS)
 
-# All compress_* tools use compress.h
-compress_agos.o compress_saga.o compress_scumm_sou.o \
-compress_scumm_bun.o compress_sword1.o compress_sword2.o \
-compress_kyra.o compress_queen.o compress.o encode_dxa.o: compress.h
+tools_gui.o: tools_gui.cpp tools_gui.h
+	$(CXX) $(CXXFLAGS) $(CPPFLAGS) `wx-config --cxxflags` -c tools_gui.cpp -o tools_gui.o
 
-# extract_parallaction.h
-extract_parallaction.o: extract_parallaction.h
 
-# Virtually everything depends on util.h
-compress_agos.o  compress_saga.o compress_scumm_sou.o \
-compress_scumm_bun.o compress_sword1.o compress_sword2.o \
-compress.o \
-compress_queen.o \
-compress_kyra.o \
-descumm.o descumm6.o descumm-common.o descumm-tool.o \
-dekyra.o \
-dekyra_v1.o \
-desword2.o \
-encode_dxa.o \
-extract_kyra.o \
-extract_loom_tg16.o \
-extract_mm_apple.o \
-extract_mm_c64.o \
-extract_mm_nes.o \
-extract_parallaction.o \
-extract_scumm_mac.o \
-extract_zak_c64.o \
-kyra_pak.o \
-util.o: util.h
+######################################################################
+# The build rules follow - normally you should have no need to
+# touch whatever comes after here.
+######################################################################
 
-clean:
-	rm -f *.o utils/*.o $(TARGETS)
+# Concat DEFINES and INCLUDES to form the CPPFLAGS
+CPPFLAGS := $(DEFINES) $(INCLUDES)
 
+# Include the build instructions for all modules
+#-include $(addprefix $(srcdir)/, $(addsuffix /module.mk,$(MODULES)))
 
-tools_gui.o: tools_gui.cpp tools_gui.h
-	$(CXX) $(CFLAGS) $(CPPFLAGS) `wx-config --cxxflags` -c tools_gui.cpp -o tools_gui.o
+# Depdir information
+DEPDIRS = $(addsuffix $(DEPDIR),$(MODULE_DIRS))
+DEPFILES =
 
-.cpp.o:
-	$(CXX) $(CFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+%.o: %.cpp
+	$(MKDIR) $(*D)/$(DEPDIR)
+	$(CXX) -Wp,-MMD,"$(*D)/$(DEPDIR)/$(*F).d",-MQ,"$@",-MP $(CXXFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
 
-.c.o:
-	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(<) -o $*.o
+# Include the dependency tracking files.
+-include $(wildcard $(addsuffix /*.d,$(DEPDIRS)))

Deleted: tools/trunk/compress.c
===================================================================
--- tools/trunk/compress.c	2008-02-25 14:13:12 UTC (rev 30963)
+++ tools/trunk/compress.c	2008-02-25 14:37:16 UTC (rev 30964)
@@ -1,904 +0,0 @@
-/* Scumm Tools
- * Copyright (C) 2003-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"
-
-typedef struct  {
-	uint32 minBitr;
-	uint32 maxBitr;
-	bool abr;
-	uint32 algqual;
-	uint32 vbrqual;
-	bool silent;
-} lameparams;
-
-typedef struct {
-	int nominalBitr;
-	int minBitr;
-	int maxBitr;
-	float quality;
-	bool silent;
-} oggencparams;
-
-typedef struct {
-	int compressionLevel;
-	int blocksize;
-	bool verify;
-	bool silent;
-} flaccparams;
-
-typedef struct {
-	bool isLittleEndian, isStereo;
-	uint8 bitsPerSample;
-} rawtype;
-
-lameparams encparms = { minBitrDef, maxBitrDef, false, algqualDef, vbrqualDef, 0 };
-oggencparams oggparms = { -1, -1, -1, oggqualDef, 0 };
-flaccparams flacparms = { flacCompressDef, flacBlocksizeDef, false, false };
-rawtype	rawAudioType = { false, false, 8 };
-
-const char *tempEncoded = TEMP_MP3;
-
-void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample) {
-	rawAudioType.isLittleEndian = isLittleEndian;
-	rawAudioType.isStereo = isStereo;
-	rawAudioType.bitsPerSample = bitsPerSample;
-}
-
-int getSampleRateFromVOCRate(int vocSR) {
-	if (vocSR == 0xa5 || vocSR == 0xa6 || vocSR == 0x83) {
-		return 11025;
-	} else if (vocSR == 0xd2 || vocSR == 0xd3) {
-		return 22050;
-	} else {
-		int sr = 1000000L / (256L - vocSR);
-		/* inexact sampling rates occur e.g. in the kitchen in Monkey
-		 * Island, very easy to reach right from the start of the game.
-		 * warning("inexact sample rate used: %i (0x%x)", sr, vocSR);
-		 */
-		return sr;
-	}
-}
-
-/* map frequency to a valid MP3 sample frequency
- *
- * Robert Hegemann 2000-07-01
- *
- * Copied from lame 3.96.1
- */
-static int map2MP3Frequency(int freq)
-{
-    if (freq <=  8000) return  8000;
-    if (freq <= 11025) return 11025;
-    if (freq <= 12000) return 12000;
-    if (freq <= 16000) return 16000;
-    if (freq <= 22050) return 22050;
-    if (freq <= 24000) return 24000;
-    if (freq <= 32000) return 32000;
-    if (freq <= 44100) return 44100;
-
-    return 48000;
-}
-
-void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, CompressMode compmode) {
-	bool err = false;
-	char fbuf[2048];
-	char *tmp = fbuf;
-
-	if (compmode == kMP3Mode) {
-		tmp += sprintf(tmp, "lame -t ");
-		if (rawInput) {
-			tmp += sprintf(tmp, "-r ");
-			tmp += sprintf(tmp, "--bitwidth %d ", rawAudioType.bitsPerSample);
-
-			if (rawAudioType.isLittleEndian) {
-				tmp += sprintf(tmp, "-x ");
-			}
-
-			tmp += sprintf(tmp, (rawAudioType.isStereo ? "-m j " : "-m m "));
-			tmp += sprintf(tmp, "-s %d ", rawSamplerate);
-		}
-
-		if (encparms.abr)
-			tmp += sprintf(tmp, "--abr %d ", encparms.minBitr);
-		else
-			tmp += sprintf(tmp, "--vbr-new -b %d ", encparms.minBitr);
-
-		/* Explicitly specify a target sample rate, to work around a bug (?)
-		* in newer lame versions (>= 3.95) which causes it to malfunction
-		* for odd sample rates when in VBR mode. See also bug #934026.
-		* We essentially duplicate the old behaviour of lame (found in e.g.
-		* version 3.93.1): we round the input sample rate up to the next
-		* higher valid MP3 sample rate, with a margin of 3%.
-		*/
-		if (rawSamplerate != -1) {
-			tmp += sprintf(tmp, "--resample %d ", map2MP3Frequency(97 * rawSamplerate / 100));
-		}
-
-		if (encparms.silent) {
-			tmp += sprintf(tmp, " --silent ");
-		}
-
-		tmp += sprintf(tmp, "-q %d ", encparms.algqual);
-		tmp += sprintf(tmp, "-V %d ", encparms.vbrqual);
-		tmp += sprintf(tmp, "-B %d ", encparms.maxBitr);
-		tmp += sprintf(tmp, "\"%s\" \"%s\" ", inname, outname);
-
-		err = system(fbuf) != 0;
-
-		if (err) {
-			printf("Got error from encoder. (check your parameters)\n");
-			printf("Encoder Commandline: %s\n", fbuf );
-			exit(-1);
-		} else {
-			return;
-		}
-	}
-
-#ifdef DISABLE_VORBIS
-		if (compmode == kVorbisMode) {
-			tmp += sprintf(tmp, "oggenc ");
-			if (rawInput) {
-				tmp += sprintf(tmp, "--raw ");
-				tmp += sprintf(tmp, "--raw-chan=%d ", (rawAudioType.isStereo ? 2 : 1));
-				tmp += sprintf(tmp, "--raw-bits=%d ", rawAudioType.bitsPerSample);
-				tmp += sprintf(tmp, "--raw-rate=%d ", rawSamplerate);
-				tmp += sprintf(tmp, "--raw-endianness=%d ", (rawAudioType.isLittleEndian ? 0 : 1));
-			}
-
-			if (oggparms.nominalBitr != -1) {
-				tmp += sprintf(tmp, "--bitrate=%d ", oggparms.nominalBitr);
-			} else {
-				tmp += sprintf(tmp, "--quality=%d ", oggparms.quality);
-			}
-
-			if (oggparms.minBitr != -1) {
-				tmp += sprintf(tmp, "--min-bitrate=%d ", oggparms.minBitr);
-			}
-
-			if (oggparms.maxBitr != -1) {
-				tmp += sprintf(tmp, "--max-bitrate=%d ", oggparms.maxBitr);
-			}
-
-			if (oggparms.silent) {
-				tmp += sprintf(tmp, "--quiet ");
-			}
-
-			tmp += sprintf(tmp, "--output=\"%s\" ", outname);
-			tmp += sprintf(tmp, "\"%s\" ", inname);
-
-			err = system(fbuf) != 0;
-
-			if (err) {
-				printf("Got error from encoder. (check your parameters)\n");
-				printf("Encoder Commandline: %s\n", fbuf );
-				exit(-1);
-			} else {
-				return;
-			}
-		}
-#endif
-
-#ifdef DISABLE_FLAC
-		if (compmode == kFlacMode) {
-			/* --lax is needed to allow 11kHz, we dont need place for meta-tags, and no seektable */
-			/* -f is reqired to force override of unremoved temp file. See bug #1294648 */
-			tmp += sprintf(tmp, "flac -f --lax --no-padding --no-seektable --no-ogg ");
-
-			if (rawInput) {
-				tmp += sprintf(tmp, "--force-raw-format ");
-				tmp += sprintf(tmp, "--sign=%s ", ((rawAudioType.bitsPerSample == 8) ? "unsigned" : "signed"));
-				tmp += sprintf(tmp, "--channels=%d ", (rawAudioType.isStereo ? 2 : 1));
-				tmp += sprintf(tmp, "--bps=%d ", rawAudioType.bitsPerSample);
-				tmp += sprintf(tmp, "--sample-rate=%d ", rawSamplerate);
-				tmp += sprintf(tmp, "--endian=%s ", (rawAudioType.isLittleEndian ? "little" : "big"));
-			}
-
-			if (flacparms.silent) {
-				tmp += sprintf(tmp, "--silent ");
-			}
-
-			if (flacparms.verify) {
-				tmp += sprintf(tmp, "--verify ");
-			}
-
-			tmp += sprintf(tmp, "--compression-level-%d ", flacparms.compressionLevel);
-			tmp += sprintf(tmp, "-b %d ", flacparms.blocksize);
-			tmp += sprintf(tmp, "-o \"%s\" ", outname);
-			tmp += sprintf(tmp, "\"%s\" ", inname);
-
-			err = system(fbuf) != 0;
-
-			if (err) {
-				printf("Got error from encoder. (check your parameters)\n");
-				printf("Encoder Commandline: %s\n", fbuf );
-				exit(-1);
-			} else {
-				return;
-			}
-		}
-#endif
-		if (rawInput) {
-			FILE *inputRaw;
-			long length;
-			char *rawData;
-
-			inputRaw = fopen(inname, "rb");
-			length = fileSize(inputRaw);
-			rawData = (char *)malloc(length);
-			fread(rawData, 1, length, inputRaw);
-
-			printf(" - length = %ld\n", length);
-			printf(" - channels = %d\n", (rawAudioType.isStereo ? 2 : 1));
-			printf(" - sample rate = %d\n", rawSamplerate);
-			printf(" - compression = %dbits\n", rawAudioType.bitsPerSample);
-
-			encodeRaw(rawData, length, rawSamplerate, outname, compmode);
-
-			fclose(inputRaw);
-			free(rawData);
-		} else {
-			FILE *inputWav;
-			int fmtHeaderSize, length, numChannels, sampleRate, bitsPerSample;
-			char *wavData;
-
-			inputWav = fopen(inname, "rb");
-
-			/* Standard PCM fmt header is 16 bits, but at least Simon 1 and 2 use 18 bits */
-			fseek(inputWav, 16, SEEK_SET);
-			fmtHeaderSize = readUint32LE(inputWav);
-
-			fseek(inputWav, 22, SEEK_SET);
-			numChannels = readUint16LE(inputWav);
-			sampleRate = readUint32LE(inputWav);
-
-			fseek(inputWav, 34, SEEK_SET);
-			bitsPerSample = readUint16LE(inputWav);
-
-			/* The size of the raw audio is after the RIFF chunk (12 bytes), fmt chunk (8 + fmtHeaderSize bytes), and data chunk id (4 bytes) */
-			fseek(inputWav, 24 + fmtHeaderSize, SEEK_SET);
-			length = readUint32LE(inputWav);
-
-			wavData = (char *)malloc(length);
-			fread(wavData, 1, length, inputWav);
-
-			printf(" - length = %d\n", length);
-			printf(" - channels = %d\n", numChannels);
-			printf(" - sample rate = %d\n", sampleRate);
-			printf(" - compression = %dbits\n", bitsPerSample);
-
-			setRawAudioType(true, numChannels == 2, bitsPerSample);
-			encodeRaw(wavData, length, sampleRate, outname, compmode);
-
-			fclose(inputWav);
-			free (wavData);
-		}
-}
-
-void encodeRaw(char *rawData, int length, int samplerate, const char *outname, CompressMode compmode) {
-#ifndef DISABLE_VORBIS
-	if (compmode == kVorbisMode) {
-		FILE *outputOgg;
-		char outputString[256] = "";
-		int numChannels = (rawAudioType.isStereo ? 2 : 1);
-		int totalSamples = length / ((rawAudioType.bitsPerSample / 8) * numChannels);
-		int samplesLeft = totalSamples;
-		int eos = 0;
-		int totalBytes = 0;
-
-		vorbis_info vi;
-		vorbis_comment vc;
-		vorbis_dsp_state vd;
-		vorbis_block vb;
-
-		ogg_stream_state os;
-		ogg_page og;
-		ogg_packet op;
-
-		ogg_packet header;
-		ogg_packet header_comm;
-		ogg_packet header_code;
-
-		outputOgg = fopen(outname,"wb");
-
-		vorbis_info_init(&vi);
-
-		if (oggparms.nominalBitr > 0) {
-			int result = 0;
-
-			/* Input is in kbps, function takes bps */
-			result = vorbis_encode_setup_managed(&vi, numChannels, samplerate, (oggparms.maxBitr > 0 ? 1000 * oggparms.maxBitr : -1), (1000 * oggparms.nominalBitr), (oggparms.minBitr > 0 ? 1000 * oggparms.minBitr : -1));
-
-			if (result == OV_EFAULT) {
-				printf("Error: Internal Logic Fault.\n\n");
-				vorbis_info_clear(&vi);
-				exit(-1);
-			} else if ((result == OV_EINVAL) || (result == OV_EIMPL)) {
-				printf("Error: Invalid bitrate parameters.\n\n");
-				vorbis_info_clear(&vi);
-				exit(-1);
-			}
-
-			if (!oggparms.silent) {
-				sprintf(outputString, "Encoding to\n         \"%s\"\nat average bitrate %i kbps (", outname, oggparms.nominalBitr);
-
-				if (oggparms.minBitr > 0) {
-					sprintf(outputString + strlen(outputString), "min %i kbps, ", oggparms.minBitr);
-				} else {
-					sprintf(outputString + strlen(outputString), "no min, ");
-				}
-
-				if (oggparms.maxBitr > 0) {
-					sprintf(outputString + strlen(outputString), "max %i kbps),\nusing full bitrate management engine\nSet optional hard quality restrictions\n", oggparms.maxBitr);
-				} else {
-					sprintf(outputString + strlen(outputString), "no max),\nusing full bitrate management engine\nSet optional hard quality restrictions\n");
-				}
-			}
-		} else {
-			int result = 0;
-
-			/* Quality input is 1 - 10, function takes -0.1 through 1.0 */
-			result = vorbis_encode_setup_vbr(&vi, numChannels, samplerate, oggparms.quality * 0.1);
-
-			if (result == OV_EFAULT) {
-				printf("Error: Internal Logic Fault.\n\n");
-				vorbis_info_clear(&vi);
-				exit(-1);
-			} else if ((result == OV_EINVAL) || (result == OV_EIMPL)) {
-				printf("Error: Invalid bitrate parameters.\n\n");
-				vorbis_info_clear(&vi);
-				exit(-1);
-			}
-
-			if (!oggparms.silent) {
-				sprintf(outputString, "Encoding to\n         \"%s\"\nat quality %2.2f", outname, oggparms.quality);
-			}
-
-			if ((oggparms.minBitr > 0) || (oggparms.maxBitr > 0)) {
-				struct ovectl_ratemanage_arg extraParam;
-				vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_GET, &extraParam);
-
-				extraParam.bitrate_hard_min = (oggparms.minBitr > 0 ? (1000 * oggparms.minBitr) : -1);
-				extraParam.bitrate_hard_max = (oggparms.maxBitr > 0 ? (1000 * oggparms.maxBitr) : -1);
-				extraParam.management_active = 1;
-
-				vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_SET, &extraParam);
-
-				if (!oggparms.silent) {
-					sprintf(outputString + strlen(outputString), " using constrained VBR (");
-
-					if (oggparms.minBitr != -1) {
-						sprintf(outputString + strlen(outputString), "min %i kbps, ", oggparms.minBitr);
-					} else {
-						sprintf(outputString + strlen(outputString), "no min, ");
-					}
-
-					if (oggparms.maxBitr != -1) {
-						sprintf(outputString + strlen(outputString), "max %i kbps)\nSet optional hard quality restrictions\n", oggparms.maxBitr);
-					} else {
-						sprintf(outputString + strlen(outputString), "no max)\nSet optional hard quality restrictions\n");
-					}
-				}
-			} else {
-				sprintf(outputString + strlen(outputString), "\n");
-			}
-		}
-
-		printf(outputString);
-
-		vorbis_encode_setup_init(&vi);
-		vorbis_comment_init(&vc);
-		vorbis_analysis_init(&vd, &vi);
-		vorbis_block_init(&vd, &vb);
-		ogg_stream_init(&os, 0);
-		vorbis_analysis_headerout(&vd, &vc, &header, &header_comm, &header_code);
-
-		ogg_stream_packetin(&os, &header);
-		ogg_stream_packetin(&os, &header_comm);
-		ogg_stream_packetin(&os, &header_code);
-
-		while (!eos) {
-			int result = ogg_stream_flush(&os,&og);
-
-			if (result == 0) {
-				break;
-			}
-
-			fwrite(og.header, 1, og.header_len, outputOgg);
-			fwrite(og.body, 1, og.body_len, outputOgg);
-		}
-
-		while (!eos) {
-			int i, j;
-			int numSamples = ((samplesLeft < 2048) ? samplesLeft : 2048);
-			float **buffer = vorbis_analysis_buffer(&vd, numSamples);
-
-			/* We must tell the encoder that we have reached the end of the stream */
-			if (numSamples == 0) {
-				vorbis_analysis_wrote(&vd, 0);
-			} else {
-				/* Adapted from oggenc 1.1.1 */
-				if (rawAudioType.bitsPerSample == 8) {
-					unsigned char *rawDataUnsigned = (unsigned char *)rawData;
-					for (i = 0; i < numSamples; i++) {
-						for (j = 0; j < numChannels; j++) {
-							buffer[j][i] = ((int)(rawDataUnsigned[i * numChannels + j]) - 128) / 128.0f;
-						}
-					}
-				} else if(rawAudioType.bitsPerSample == 16) {
-					if(rawAudioType.isLittleEndian) {
-						for(i = 0; i < numSamples; i++) {
-							for(j = 0; j < numChannels; j++) {
-								buffer[j][i] = ((rawData[(i * 2 * numChannels) + (2 * j) + 1] << 8) | (rawData[(i * 2 * numChannels) + (2 * j)] & 0xff)) / 32768.0f;
-							}
-						}
-					}
-					else {
-						for(i = 0; i < numSamples; i++) {
-							for(j = 0; j < numChannels; j++) {
-								buffer[j][i] = ((rawData[(i * 2 * numChannels) + (2 * j)] << 8) | (rawData[(i * 2 * numChannels) + (2 * j) + 1] & 0xff)) / 32768.0f;
-							}
-						}
-					}
-				}
-
-				vorbis_analysis_wrote(&vd, numSamples);
-			}
-
-			while (vorbis_analysis_blockout(&vd, &vb) == 1) {
-				vorbis_analysis(&vb, NULL);
-				vorbis_bitrate_addblock(&vb);
-
-				while (vorbis_bitrate_flushpacket(&vd, &op)) {
-					ogg_stream_packetin(&os, &op);
-
-					while (!eos) {
-						int result = ogg_stream_pageout(&os, &og);
-
-						if(result == 0) {
-							break;
-						}
-
-						totalBytes += fwrite(og.header, 1, og.header_len, outputOgg);
-						totalBytes += fwrite(og.body, 1, og.body_len, outputOgg);
-
-						if(ogg_page_eos(&og)) {
-							eos = 1;
-						}
-					}
-				}
-			}
-
-			rawData += 2048 * (rawAudioType.bitsPerSample / 8) * numChannels;
-			samplesLeft -= 2048;
-		}
-
-		ogg_stream_clear(&os);
-		vorbis_block_clear(&vb);
-		vorbis_dsp_clear(&vd);
-		vorbis_info_clear(&vi);
-
-		fclose(outputOgg);
-
-		if (!oggparms.silent) {
-			printf("\nDone encoding file \"%s\"\n", outname);
-			printf("\n\tFile length:  %dm %ds\n", (int)(totalSamples / samplerate / 60), (totalSamples / samplerate % 60));
-			printf("\tAverage bitrate: %.1f kb/s\n\n", (8.0 * (double)totalBytes / 1000.0) / ((double)totalSamples / (double)samplerate));
-		}
-	}
-#endif
-
-#ifndef DISABLE_FLAC
-	if (compmode == kFlacMode) {
-		int i;
-		int numChannels = (rawAudioType.isStereo ? 2 : 1);
-		int samplesPerChannel = length / ((rawAudioType.bitsPerSample / 8) * numChannels);
-		FLAC__StreamEncoder *encoder;
-		FLAC__StreamEncoderInitStatus initStatus;
-		FLAC__int32 *flacData;
-
-		flacData = (FLAC__int32 *)malloc(samplesPerChannel * numChannels * sizeof(FLAC__int32));
-
-		if (rawAudioType.bitsPerSample == 8) {
-			for (i = 0; i < samplesPerChannel * numChannels; i++) {
-				FLAC__uint8 *rawDataUnsigned;
-				rawDataUnsigned = (FLAC__uint8 *)rawData;
-				flacData[i] = (FLAC__int32)rawDataUnsigned[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 */
-			FLAC__int16 *rawData16;
-			rawData16 = (FLAC__int16 *)rawData;
-			for (i = 0; i < samplesPerChannel * numChannels; i++) {
-				flacData[i] = (FLAC__int32)rawData16[i];
-			}
-		}
-
-		if (!flacparms.silent) {
-			printf("Encoding to\n         \"%s\"\nat compression level %d using blocksize %d\n\n", outname, flacparms.compressionLevel, flacparms.blocksize);
-		}
-
-		encoder = FLAC__stream_encoder_new();
-
-		FLAC__stream_encoder_set_bits_per_sample(encoder, rawAudioType.bitsPerSample);
-		FLAC__stream_encoder_set_blocksize(encoder, flacparms.blocksize);
-		FLAC__stream_encoder_set_channels(encoder, numChannels);
-		FLAC__stream_encoder_set_compression_level(encoder, flacparms.compressionLevel);
-		FLAC__stream_encoder_set_sample_rate(encoder, samplerate);
-		FLAC__stream_encoder_set_streamable_subset(encoder, false);
-		FLAC__stream_encoder_set_total_samples_estimate(encoder, samplesPerChannel);
-		FLAC__stream_encoder_set_verify(encoder, flacparms.verify);
-
-		initStatus = FLAC__stream_encoder_init_file(encoder, outname, NULL, NULL);
-
-		if (initStatus != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
-			printf("Got error from encoder. (check your paramters)\n");
-			printf("FLAC error: %s\n\n", FLAC__StreamEncoderInitStatusString[initStatus]);
-			exit(-1);
-		} else {
-			FLAC__stream_encoder_process_interleaved(encoder, flacData, samplesPerChannel);
-		}
-
-		FLAC__stream_encoder_finish(encoder);
-		FLAC__stream_encoder_delete(encoder);
-
-		free(flacData);
-
-		if (!flacparms.silent) {
-			printf("\nDone encoding file \"%s\"\n", outname);
-			printf("\n\tFile length:  %dm %ds\n\n", (int)(samplesPerChannel / samplerate / 60), (samplesPerChannel / samplerate % 60));
-		}
-	}
-#endif
-}
-
-void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode) {
-	int length;
-	FILE *f;
-	char fbuf[2048];
-	size_t size;
-
-	fseek(input, -4, SEEK_CUR);
-	length = readUint32LE(input);
-	length += 8;
-	fseek(input, -8, SEEK_CUR);
-
-	/* Copy the WAV data to a temporary file */
-	f = fopen(outName, "wb");
-	while (length > 0) {
-		size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : length, input);
-		if (size <= 0)
-			break;
-		length -= (int)size;
-		fwrite(fbuf, 1, size, f);
-	}
-	fclose(f);
-
-	/* Convert the WAV temp file to OGG/MP3 */
-	encodeAudio(outName, false, -1, tempEncoded, compMode);
-}
-
-void extractAndEncodeVOC(const char *outName, FILE *input, CompressMode compMode) {
-	FILE *f;
-	int bits;
-	int blocktype;
-	int channels;
-	int length;
-	int sample_rate;
-	int comp;
-	char fbuf[2048];
-	size_t size;
-	int real_samplerate = -1;
-
-	f = fopen(outName, "wb");
-
-	while ((blocktype = fgetc(input))) {
-		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
-			   with an invalid length field (value to small). So we encounter
-			   the "block types" 0x80, 0x82 etc.. Not sure if there is another
-			   (maybe even better) way to work around that... ?
-			 */
-			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;
-
-		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);
-		}
-
-		printf(" - length = %d\n", length);
-		printf(" - sample rate = %d (%02x)\n", real_samplerate, sample_rate);
-		printf(" - compression = %s (%02x)\n",
-			   (comp ==	   0 ? "8bits"   :
-				(comp ==   1 ? "4bits"   :
-				 (comp ==  2 ? "2.6bits" :
-				  (comp == 3 ? "2bits"   :
-								"Multi")))), comp);
-
-		if (comp != 0) {
-			error("Cannot handle compressed VOC data");
-		}
-
-		/* Copy the raw data to a temporary file */
-		while (length > 0) {
-			size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : (uint32)length, input);
-
-			if (size <= 0) {
-				break;
-			}
-
-			length -= (int)size;
-			fwrite(fbuf, 1, size, f);
-		}
-	}
-
-	fclose(f);
-
-	assert(real_samplerate != -1);
-
-	setRawAudioType(false, false, 8);
-
-	/* Convert the raw temp file to OGG/MP3 */
-	encodeAudio(outName, true, real_samplerate, tempEncoded, compMode);
-}
-
-int process_mp3_parms(int argc, char *argv[], int i) {
-	for (; i < argc; i++) {
-		if (strcmp(argv[i], "--vbr") == 0) {
-			encparms.abr = 0;
-		} else if (strcmp(argv[i], "--abr") == 0) {
-			encparms.abr = 1;
-		} else if (strcmp(argv[i], "-b") == 0) {
-			encparms.minBitr = atoi(argv[i + 1]);
-
-			if ((encparms.minBitr % 8) != 0) {
-				encparms.minBitr -= encparms.minBitr % 8;
-			}
-
-			if (encparms.minBitr > 160) {
-				encparms.minBitr = 160;
-			}
-
-			if (encparms.minBitr < 8) {
-				encparms.minBitr = 8;
-			}
-
-			i++;
-		} else if (strcmp(argv[i], "-B") == 0) {
-			encparms.maxBitr = atoi(argv[i + 1]);
-
-			if ((encparms.maxBitr % 8) != 0) {
-				encparms.maxBitr -= encparms.maxBitr % 8;
-			}
-
-			if (encparms.maxBitr > 160) {
-				encparms.maxBitr = 160;
-			}
-
-			if (encparms.maxBitr < 8) {
-				encparms.maxBitr = 8;
-			}
-
-			i++;
-		} else if (strcmp(argv[i], "-V") == 0) {
-			encparms.vbrqual = atoi(argv[i + 1]);
-
-			if(encparms.vbrqual < 0) {
-				encparms.vbrqual = 0;
-			}
-
-			if(encparms.vbrqual > 9) {
-				encparms.vbrqual = 9;
-			}
-
-			i++;
-		} else if (strcmp(argv[i], "-q") == 0) {
-			encparms.algqual = atoi(argv[i + 1]);
-
-			if (encparms.algqual < 0) {
-				encparms.algqual = 0;
-			}
-
-			if (encparms.algqual > 9) {
-				encparms.algqual = 9;
-			}
-
-			i++;
-		} else if (strcmp(argv[i], "--silent") == 0) {
-			encparms.silent = 1;
-		} else if (strcmp(argv[i], "--help") == 0) {
-			return 0;
-		} else if (argv[i][0] == '-') {
-			return 0;
-		} else {
-			break;
-		}
-	}
-
-	if (i != (argc - 1)) {
-		return 0;
-	}
-
-	return 1;
-}
-
-int process_ogg_parms(int argc, char *argv[], int i) {
-	for (; i < argc; i++) {
-		if (strcmp(argv[i], "-b") == 0) {
-			oggparms.nominalBitr = atoi(argv[i + 1]);
-
-			if ((oggparms.nominalBitr % 8) != 0) {
-				oggparms.nominalBitr -= oggparms.nominalBitr % 8;
-			}
-
-			if (oggparms.nominalBitr >160) {
-				oggparms.nominalBitr = 160;
-			}
-
-			if (oggparms.nominalBitr < 8) {
-				oggparms.nominalBitr = 8;
-			}
-
-			i++;
-		} else if (strcmp(argv[i], "-m") == 0) {
-			oggparms.minBitr = atoi(argv[i + 1]);
-
-			if ((oggparms.minBitr % 8) != 0) {
-				oggparms.minBitr -= oggparms.minBitr % 8;
-			}
-
-			if (oggparms.minBitr >160) {
-				oggparms.minBitr = 160;
-			}
-
-			if (oggparms.minBitr < 8) {
-				oggparms.minBitr = 8;
-			}
-
-			i++;
-		}
-		else if (strcmp(argv[i], "-M") == 0) {
-			oggparms.maxBitr = atoi(argv[i + 1]);
-
-			if ((oggparms.maxBitr % 8) != 0) {
-				oggparms.maxBitr -= encparms.minBitr % 8;
-			}
-
-			if (oggparms.maxBitr >160) {
-				oggparms.maxBitr = 160;
-			}
-
-			if (oggparms.maxBitr < 8) {
-				oggparms.maxBitr = 8;
-			}
-
-			i++;
-		}
-		else if (strcmp(argv[i], "-q") == 0) {
-			oggparms.quality = atoi(argv[i + 1]);
-			i++;
-		}
-		else if (strcmp(argv[i], "--silent") == 0) {
-			oggparms.silent = 1;
-		}
-		else if (strcmp(argv[i], "--help") == 0) {
-			return 0;
-		}
-		else if (argv[i][0] == '-') {
-			return 0;
-		}
-		else {
-			break;
-		}
-	}
-
-	if (i != argc - 1) {
-		return 0;
-	}
-
-	return 1;
-}
-
-int process_flac_parms(int argc, char *argv[], int i){
-	for (; i < argc; i++) {
-		if (strcmp(argv[i], "-b") == 0) {
-			flacparms.blocksize = atoi(argv[i + 1]);
-			i++;
-		}
-		else if (strcmp(argv[i], "--fast") == 0) {
-			flacparms.compressionLevel = 0;
-		}
-		else if (strcmp(argv[i], "--best") == 0) {
-			flacparms.compressionLevel = 8;
-		}
-		else if (strcmp(argv[i], "-0") == 0) {
-			flacparms.compressionLevel = 0;
-		}
-		else if (strcmp(argv[i], "-1") == 0) {
-			flacparms.compressionLevel = 1;
-		}
-		else if (strcmp(argv[i], "-2") == 0) {
-			flacparms.compressionLevel = 2;
-		}
-		else if (strcmp(argv[i], "-3") == 0) {
-			flacparms.compressionLevel = 3;
-		}
-		else if (strcmp(argv[i], "-4") == 0) {
-			flacparms.compressionLevel = 4;
-		}
-		else if (strcmp(argv[i], "-5") == 0) {
-			flacparms.compressionLevel = 5;
-		}
-		else if (strcmp(argv[i], "-6") == 0) {
-			flacparms.compressionLevel = 6;
-		}
-		else if (strcmp(argv[i], "-7") == 0) {
-			flacparms.compressionLevel = 7;
-		}
-		else if (strcmp(argv[i], "-8") == 0) {
-			flacparms.compressionLevel = 8;
-		}
-		else if (strcmp(argv[i], "--verify") == 0) {
-			flacparms.verify = true;
-		}
-		else if (strcmp(argv[i], "--silent") == 0) {
-			flacparms.silent = true;
-		}
-		else if (strcmp(argv[i], "--help") == 0) {
-			return 0;
-		}
-		else if (argv[i][0] == '-') {
-			return 0;
-		}
-		else {
-			break;
-		}
-	}
-
-	if (i != argc - 1) {
-		return 0;
-	}
-
-	return 1;
-}

Copied: tools/trunk/compress.cpp (from rev 30960, tools/trunk/compress.c)
===================================================================
--- tools/trunk/compress.cpp	                        (rev 0)
+++ tools/trunk/compress.cpp	2008-02-25 14:37:16 UTC (rev 30964)
@@ -0,0 +1,904 @@
+/* Scumm Tools
+ * Copyright (C) 2003-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"
+
+typedef struct  {
+	uint32 minBitr;
+	uint32 maxBitr;
+	bool abr;
+	uint32 algqual;
+	uint32 vbrqual;
+	bool silent;
+} lameparams;
+
+typedef struct {
+	int nominalBitr;
+	int minBitr;
+	int maxBitr;
+	float quality;
+	bool silent;
+} oggencparams;
+
+typedef struct {
+	int compressionLevel;
+	int blocksize;
+	bool verify;
+	bool silent;
+} flaccparams;
+
+typedef struct {
+	bool isLittleEndian, isStereo;
+	uint8 bitsPerSample;
+} rawtype;
+
+lameparams encparms = { minBitrDef, maxBitrDef, false, algqualDef, vbrqualDef, 0 };
+oggencparams oggparms = { -1, -1, -1, oggqualDef, 0 };
+flaccparams flacparms = { flacCompressDef, flacBlocksizeDef, false, false };
+rawtype	rawAudioType = { false, false, 8 };
+
+const char *tempEncoded = TEMP_MP3;
+
+void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample) {
+	rawAudioType.isLittleEndian = isLittleEndian;
+	rawAudioType.isStereo = isStereo;
+	rawAudioType.bitsPerSample = bitsPerSample;
+}
+
+int getSampleRateFromVOCRate(int vocSR) {
+	if (vocSR == 0xa5 || vocSR == 0xa6 || vocSR == 0x83) {
+		return 11025;
+	} else if (vocSR == 0xd2 || vocSR == 0xd3) {
+		return 22050;
+	} else {
+		int sr = 1000000L / (256L - vocSR);
+		/* inexact sampling rates occur e.g. in the kitchen in Monkey
+		 * Island, very easy to reach right from the start of the game.
+		 * warning("inexact sample rate used: %i (0x%x)", sr, vocSR);
+		 */
+		return sr;
+	}
+}
+
+/* map frequency to a valid MP3 sample frequency
+ *
+ * Robert Hegemann 2000-07-01
+ *
+ * Copied from lame 3.96.1
+ */
+static int map2MP3Frequency(int freq)
+{
+    if (freq <=  8000) return  8000;
+    if (freq <= 11025) return 11025;
+    if (freq <= 12000) return 12000;
+    if (freq <= 16000) return 16000;
+    if (freq <= 22050) return 22050;
+    if (freq <= 24000) return 24000;
+    if (freq <= 32000) return 32000;
+    if (freq <= 44100) return 44100;
+
+    return 48000;
+}
+
+void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, CompressMode compmode) {
+	bool err = false;
+	char fbuf[2048];
+	char *tmp = fbuf;
+
+	if (compmode == kMP3Mode) {
+		tmp += sprintf(tmp, "lame -t ");
+		if (rawInput) {
+			tmp += sprintf(tmp, "-r ");
+			tmp += sprintf(tmp, "--bitwidth %d ", rawAudioType.bitsPerSample);
+
+			if (rawAudioType.isLittleEndian) {
+				tmp += sprintf(tmp, "-x ");
+			}
+
+			tmp += sprintf(tmp, (rawAudioType.isStereo ? "-m j " : "-m m "));
+			tmp += sprintf(tmp, "-s %d ", rawSamplerate);
+		}
+
+		if (encparms.abr)
+			tmp += sprintf(tmp, "--abr %d ", encparms.minBitr);
+		else
+			tmp += sprintf(tmp, "--vbr-new -b %d ", encparms.minBitr);
+
+		/* Explicitly specify a target sample rate, to work around a bug (?)
+		* in newer lame versions (>= 3.95) which causes it to malfunction
+		* for odd sample rates when in VBR mode. See also bug #934026.
+		* We essentially duplicate the old behaviour of lame (found in e.g.
+		* version 3.93.1): we round the input sample rate up to the next
+		* higher valid MP3 sample rate, with a margin of 3%.
+		*/
+		if (rawSamplerate != -1) {
+			tmp += sprintf(tmp, "--resample %d ", map2MP3Frequency(97 * rawSamplerate / 100));
+		}
+
+		if (encparms.silent) {
+			tmp += sprintf(tmp, " --silent ");
+		}
+
+		tmp += sprintf(tmp, "-q %d ", encparms.algqual);
+		tmp += sprintf(tmp, "-V %d ", encparms.vbrqual);
+		tmp += sprintf(tmp, "-B %d ", encparms.maxBitr);
+		tmp += sprintf(tmp, "\"%s\" \"%s\" ", inname, outname);
+
+		err = system(fbuf) != 0;
+
+		if (err) {
+			printf("Got error from encoder. (check your parameters)\n");
+			printf("Encoder Commandline: %s\n", fbuf );
+			exit(-1);
+		} else {
+			return;
+		}
+	}
+
+#ifdef DISABLE_VORBIS
+		if (compmode == kVorbisMode) {
+			tmp += sprintf(tmp, "oggenc ");
+			if (rawInput) {
+				tmp += sprintf(tmp, "--raw ");
+				tmp += sprintf(tmp, "--raw-chan=%d ", (rawAudioType.isStereo ? 2 : 1));
+				tmp += sprintf(tmp, "--raw-bits=%d ", rawAudioType.bitsPerSample);
+				tmp += sprintf(tmp, "--raw-rate=%d ", rawSamplerate);
+				tmp += sprintf(tmp, "--raw-endianness=%d ", (rawAudioType.isLittleEndian ? 0 : 1));
+			}
+
+			if (oggparms.nominalBitr != -1) {
+				tmp += sprintf(tmp, "--bitrate=%d ", oggparms.nominalBitr);
+			} else {
+				tmp += sprintf(tmp, "--quality=%d ", oggparms.quality);
+			}
+
+			if (oggparms.minBitr != -1) {
+				tmp += sprintf(tmp, "--min-bitrate=%d ", oggparms.minBitr);
+			}
+
+			if (oggparms.maxBitr != -1) {
+				tmp += sprintf(tmp, "--max-bitrate=%d ", oggparms.maxBitr);
+			}
+
+			if (oggparms.silent) {
+				tmp += sprintf(tmp, "--quiet ");
+			}
+
+			tmp += sprintf(tmp, "--output=\"%s\" ", outname);
+			tmp += sprintf(tmp, "\"%s\" ", inname);
+
+			err = system(fbuf) != 0;
+
+			if (err) {
+				printf("Got error from encoder. (check your parameters)\n");
+				printf("Encoder Commandline: %s\n", fbuf );
+				exit(-1);
+			} else {
+				return;
+			}
+		}
+#endif
+
+#ifdef DISABLE_FLAC
+		if (compmode == kFlacMode) {
+			/* --lax is needed to allow 11kHz, we dont need place for meta-tags, and no seektable */
+			/* -f is reqired to force override of unremoved temp file. See bug #1294648 */
+			tmp += sprintf(tmp, "flac -f --lax --no-padding --no-seektable --no-ogg ");
+
+			if (rawInput) {
+				tmp += sprintf(tmp, "--force-raw-format ");
+				tmp += sprintf(tmp, "--sign=%s ", ((rawAudioType.bitsPerSample == 8) ? "unsigned" : "signed"));
+				tmp += sprintf(tmp, "--channels=%d ", (rawAudioType.isStereo ? 2 : 1));
+				tmp += sprintf(tmp, "--bps=%d ", rawAudioType.bitsPerSample);
+				tmp += sprintf(tmp, "--sample-rate=%d ", rawSamplerate);
+				tmp += sprintf(tmp, "--endian=%s ", (rawAudioType.isLittleEndian ? "little" : "big"));
+			}
+
+			if (flacparms.silent) {
+				tmp += sprintf(tmp, "--silent ");
+			}
+
+			if (flacparms.verify) {
+				tmp += sprintf(tmp, "--verify ");
+			}
+
+			tmp += sprintf(tmp, "--compression-level-%d ", flacparms.compressionLevel);
+			tmp += sprintf(tmp, "-b %d ", flacparms.blocksize);
+			tmp += sprintf(tmp, "-o \"%s\" ", outname);
+			tmp += sprintf(tmp, "\"%s\" ", inname);
+
+			err = system(fbuf) != 0;
+
+			if (err) {
+				printf("Got error from encoder. (check your parameters)\n");
+				printf("Encoder Commandline: %s\n", fbuf );
+				exit(-1);
+			} else {
+				return;
+			}
+		}
+#endif
+		if (rawInput) {
+			FILE *inputRaw;
+			long length;
+			char *rawData;
+
+			inputRaw = fopen(inname, "rb");
+			length = fileSize(inputRaw);
+			rawData = (char *)malloc(length);
+			fread(rawData, 1, length, inputRaw);
+
+			printf(" - length = %ld\n", length);
+			printf(" - channels = %d\n", (rawAudioType.isStereo ? 2 : 1));
+			printf(" - sample rate = %d\n", rawSamplerate);
+			printf(" - compression = %dbits\n", rawAudioType.bitsPerSample);
+
+			encodeRaw(rawData, length, rawSamplerate, outname, compmode);
+
+			fclose(inputRaw);
+			free(rawData);
+		} else {
+			FILE *inputWav;
+			int fmtHeaderSize, length, numChannels, sampleRate, bitsPerSample;
+			char *wavData;
+
+			inputWav = fopen(inname, "rb");
+
+			/* Standard PCM fmt header is 16 bits, but at least Simon 1 and 2 use 18 bits */
+			fseek(inputWav, 16, SEEK_SET);
+			fmtHeaderSize = readUint32LE(inputWav);
+
+			fseek(inputWav, 22, SEEK_SET);
+			numChannels = readUint16LE(inputWav);
+			sampleRate = readUint32LE(inputWav);
+
+			fseek(inputWav, 34, SEEK_SET);
+			bitsPerSample = readUint16LE(inputWav);
+
+			/* The size of the raw audio is after the RIFF chunk (12 bytes), fmt chunk (8 + fmtHeaderSize bytes), and data chunk id (4 bytes) */
+			fseek(inputWav, 24 + fmtHeaderSize, SEEK_SET);
+			length = readUint32LE(inputWav);
+
+			wavData = (char *)malloc(length);
+			fread(wavData, 1, length, inputWav);
+
+			printf(" - length = %d\n", length);
+			printf(" - channels = %d\n", numChannels);
+			printf(" - sample rate = %d\n", sampleRate);
+			printf(" - compression = %dbits\n", bitsPerSample);
+
+			setRawAudioType(true, numChannels == 2, bitsPerSample);
+			encodeRaw(wavData, length, sampleRate, outname, compmode);
+
+			fclose(inputWav);
+			free (wavData);
+		}
+}
+
+void encodeRaw(char *rawData, int length, int samplerate, const char *outname, CompressMode compmode) {
+#ifndef DISABLE_VORBIS
+	if (compmode == kVorbisMode) {
+		FILE *outputOgg;
+		char outputString[256] = "";
+		int numChannels = (rawAudioType.isStereo ? 2 : 1);
+		int totalSamples = length / ((rawAudioType.bitsPerSample / 8) * numChannels);
+		int samplesLeft = totalSamples;
+		int eos = 0;
+		int totalBytes = 0;
+
+		vorbis_info vi;
+		vorbis_comment vc;
+		vorbis_dsp_state vd;
+		vorbis_block vb;
+
+		ogg_stream_state os;
+		ogg_page og;
+		ogg_packet op;
+
+		ogg_packet header;
+		ogg_packet header_comm;
+		ogg_packet header_code;
+
+		outputOgg = fopen(outname,"wb");
+
+		vorbis_info_init(&vi);
+
+		if (oggparms.nominalBitr > 0) {
+			int result = 0;
+
+			/* Input is in kbps, function takes bps */
+			result = vorbis_encode_setup_managed(&vi, numChannels, samplerate, (oggparms.maxBitr > 0 ? 1000 * oggparms.maxBitr : -1), (1000 * oggparms.nominalBitr), (oggparms.minBitr > 0 ? 1000 * oggparms.minBitr : -1));
+
+			if (result == OV_EFAULT) {
+				printf("Error: Internal Logic Fault.\n\n");
+				vorbis_info_clear(&vi);
+				exit(-1);
+			} else if ((result == OV_EINVAL) || (result == OV_EIMPL)) {
+				printf("Error: Invalid bitrate parameters.\n\n");
+				vorbis_info_clear(&vi);
+				exit(-1);
+			}
+
+			if (!oggparms.silent) {
+				sprintf(outputString, "Encoding to\n         \"%s\"\nat average bitrate %i kbps (", outname, oggparms.nominalBitr);
+
+				if (oggparms.minBitr > 0) {
+					sprintf(outputString + strlen(outputString), "min %i kbps, ", oggparms.minBitr);
+				} else {
+					sprintf(outputString + strlen(outputString), "no min, ");
+				}
+
+				if (oggparms.maxBitr > 0) {
+					sprintf(outputString + strlen(outputString), "max %i kbps),\nusing full bitrate management engine\nSet optional hard quality restrictions\n", oggparms.maxBitr);
+				} else {
+					sprintf(outputString + strlen(outputString), "no max),\nusing full bitrate management engine\nSet optional hard quality restrictions\n");
+				}
+			}
+		} else {
+			int result = 0;
+
+			/* Quality input is 1 - 10, function takes -0.1 through 1.0 */
+			result = vorbis_encode_setup_vbr(&vi, numChannels, samplerate, oggparms.quality * 0.1);
+
+			if (result == OV_EFAULT) {
+				printf("Error: Internal Logic Fault.\n\n");
+				vorbis_info_clear(&vi);
+				exit(-1);
+			} else if ((result == OV_EINVAL) || (result == OV_EIMPL)) {
+				printf("Error: Invalid bitrate parameters.\n\n");
+				vorbis_info_clear(&vi);
+				exit(-1);
+			}
+
+			if (!oggparms.silent) {
+				sprintf(outputString, "Encoding to\n         \"%s\"\nat quality %2.2f", outname, oggparms.quality);
+			}
+
+			if ((oggparms.minBitr > 0) || (oggparms.maxBitr > 0)) {
+				struct ovectl_ratemanage_arg extraParam;
+				vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_GET, &extraParam);
+
+				extraParam.bitrate_hard_min = (oggparms.minBitr > 0 ? (1000 * oggparms.minBitr) : -1);
+				extraParam.bitrate_hard_max = (oggparms.maxBitr > 0 ? (1000 * oggparms.maxBitr) : -1);
+				extraParam.management_active = 1;
+
+				vorbis_encode_ctl(&vi, OV_ECTL_RATEMANAGE_SET, &extraParam);
+
+				if (!oggparms.silent) {
+					sprintf(outputString + strlen(outputString), " using constrained VBR (");
+
+					if (oggparms.minBitr != -1) {
+						sprintf(outputString + strlen(outputString), "min %i kbps, ", oggparms.minBitr);
+					} else {
+						sprintf(outputString + strlen(outputString), "no min, ");
+					}
+
+					if (oggparms.maxBitr != -1) {
+						sprintf(outputString + strlen(outputString), "max %i kbps)\nSet optional hard quality restrictions\n", oggparms.maxBitr);
+					} else {
+						sprintf(outputString + strlen(outputString), "no max)\nSet optional hard quality restrictions\n");
+					}
+				}
+			} else {
+				sprintf(outputString + strlen(outputString), "\n");
+			}
+		}
+
+		printf(outputString);
+
+		vorbis_encode_setup_init(&vi);
+		vorbis_comment_init(&vc);
+		vorbis_analysis_init(&vd, &vi);
+		vorbis_block_init(&vd, &vb);
+		ogg_stream_init(&os, 0);
+		vorbis_analysis_headerout(&vd, &vc, &header, &header_comm, &header_code);
+
+		ogg_stream_packetin(&os, &header);
+		ogg_stream_packetin(&os, &header_comm);
+		ogg_stream_packetin(&os, &header_code);
+
+		while (!eos) {
+			int result = ogg_stream_flush(&os,&og);
+
+			if (result == 0) {
+				break;
+			}
+
+			fwrite(og.header, 1, og.header_len, outputOgg);
+			fwrite(og.body, 1, og.body_len, outputOgg);
+		}
+
+		while (!eos) {
+			int i, j;
+			int numSamples = ((samplesLeft < 2048) ? samplesLeft : 2048);
+			float **buffer = vorbis_analysis_buffer(&vd, numSamples);
+
+			/* We must tell the encoder that we have reached the end of the stream */
+			if (numSamples == 0) {
+				vorbis_analysis_wrote(&vd, 0);
+			} else {
+				/* Adapted from oggenc 1.1.1 */
+				if (rawAudioType.bitsPerSample == 8) {
+					unsigned char *rawDataUnsigned = (unsigned char *)rawData;
+					for (i = 0; i < numSamples; i++) {
+						for (j = 0; j < numChannels; j++) {
+							buffer[j][i] = ((int)(rawDataUnsigned[i * numChannels + j]) - 128) / 128.0f;
+						}
+					}
+				} else if(rawAudioType.bitsPerSample == 16) {
+					if(rawAudioType.isLittleEndian) {
+						for(i = 0; i < numSamples; i++) {
+							for(j = 0; j < numChannels; j++) {
+								buffer[j][i] = ((rawData[(i * 2 * numChannels) + (2 * j) + 1] << 8) | (rawData[(i * 2 * numChannels) + (2 * j)] & 0xff)) / 32768.0f;
+							}
+						}
+					}
+					else {
+						for(i = 0; i < numSamples; i++) {
+							for(j = 0; j < numChannels; j++) {
+								buffer[j][i] = ((rawData[(i * 2 * numChannels) + (2 * j)] << 8) | (rawData[(i * 2 * numChannels) + (2 * j) + 1] & 0xff)) / 32768.0f;
+							}
+						}
+					}
+				}
+
+				vorbis_analysis_wrote(&vd, numSamples);
+			}
+
+			while (vorbis_analysis_blockout(&vd, &vb) == 1) {
+				vorbis_analysis(&vb, NULL);
+				vorbis_bitrate_addblock(&vb);
+
+				while (vorbis_bitrate_flushpacket(&vd, &op)) {
+					ogg_stream_packetin(&os, &op);
+
+					while (!eos) {
+						int result = ogg_stream_pageout(&os, &og);
+
+						if(result == 0) {
+							break;
+						}
+
+						totalBytes += fwrite(og.header, 1, og.header_len, outputOgg);
+						totalBytes += fwrite(og.body, 1, og.body_len, outputOgg);
+
+						if(ogg_page_eos(&og)) {
+							eos = 1;
+						}
+					}
+				}
+			}
+
+			rawData += 2048 * (rawAudioType.bitsPerSample / 8) * numChannels;
+			samplesLeft -= 2048;
+		}
+
+		ogg_stream_clear(&os);
+		vorbis_block_clear(&vb);
+		vorbis_dsp_clear(&vd);
+		vorbis_info_clear(&vi);
+
+		fclose(outputOgg);
+
+		if (!oggparms.silent) {
+			printf("\nDone encoding file \"%s\"\n", outname);
+			printf("\n\tFile length:  %dm %ds\n", (int)(totalSamples / samplerate / 60), (totalSamples / samplerate % 60));
+			printf("\tAverage bitrate: %.1f kb/s\n\n", (8.0 * (double)totalBytes / 1000.0) / ((double)totalSamples / (double)samplerate));
+		}
+	}
+#endif
+
+#ifndef DISABLE_FLAC
+	if (compmode == kFlacMode) {
+		int i;
+		int numChannels = (rawAudioType.isStereo ? 2 : 1);
+		int samplesPerChannel = length / ((rawAudioType.bitsPerSample / 8) * numChannels);
+		FLAC__StreamEncoder *encoder;
+		FLAC__StreamEncoderInitStatus initStatus;
+		FLAC__int32 *flacData;
+
+		flacData = (FLAC__int32 *)malloc(samplesPerChannel * numChannels * sizeof(FLAC__int32));
+
+		if (rawAudioType.bitsPerSample == 8) {
+			for (i = 0; i < samplesPerChannel * numChannels; i++) {
+				FLAC__uint8 *rawDataUnsigned;
+				rawDataUnsigned = (FLAC__uint8 *)rawData;
+				flacData[i] = (FLAC__int32)rawDataUnsigned[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 */
+			FLAC__int16 *rawData16;
+			rawData16 = (FLAC__int16 *)rawData;
+			for (i = 0; i < samplesPerChannel * numChannels; i++) {
+				flacData[i] = (FLAC__int32)rawData16[i];
+			}
+		}
+
+		if (!flacparms.silent) {
+			printf("Encoding to\n         \"%s\"\nat compression level %d using blocksize %d\n\n", outname, flacparms.compressionLevel, flacparms.blocksize);
+		}
+
+		encoder = FLAC__stream_encoder_new();
+
+		FLAC__stream_encoder_set_bits_per_sample(encoder, rawAudioType.bitsPerSample);
+		FLAC__stream_encoder_set_blocksize(encoder, flacparms.blocksize);
+		FLAC__stream_encoder_set_channels(encoder, numChannels);
+		FLAC__stream_encoder_set_compression_level(encoder, flacparms.compressionLevel);
+		FLAC__stream_encoder_set_sample_rate(encoder, samplerate);
+		FLAC__stream_encoder_set_streamable_subset(encoder, false);
+		FLAC__stream_encoder_set_total_samples_estimate(encoder, samplesPerChannel);
+		FLAC__stream_encoder_set_verify(encoder, flacparms.verify);
+
+		initStatus = FLAC__stream_encoder_init_file(encoder, outname, NULL, NULL);
+
+		if (initStatus != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
+			printf("Got error from encoder. (check your paramters)\n");
+			printf("FLAC error: %s\n\n", FLAC__StreamEncoderInitStatusString[initStatus]);
+			exit(-1);
+		} else {
+			FLAC__stream_encoder_process_interleaved(encoder, flacData, samplesPerChannel);
+		}
+
+		FLAC__stream_encoder_finish(encoder);
+		FLAC__stream_encoder_delete(encoder);
+
+		free(flacData);
+
+		if (!flacparms.silent) {
+			printf("\nDone encoding file \"%s\"\n", outname);
+			printf("\n\tFile length:  %dm %ds\n\n", (int)(samplesPerChannel / samplerate / 60), (samplesPerChannel / samplerate % 60));
+		}
+	}
+#endif
+}
+
+void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode) {
+	unsigned int length;
+	FILE *f;
+	char fbuf[2048];
+	size_t size;
+
+	fseek(input, -4, SEEK_CUR);
+	length = readUint32LE(input);
+	length += 8;
+	fseek(input, -8, SEEK_CUR);
+
+	/* Copy the WAV data to a temporary file */
+	f = fopen(outName, "wb");
+	while (length > 0) {
+		size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : length, input);
+		if (size <= 0)
+			break;
+		length -= (int)size;
+		fwrite(fbuf, 1, size, f);
+	}
+	fclose(f);
+
+	/* Convert the WAV temp file to OGG/MP3 */
+	encodeAudio(outName, false, -1, tempEncoded, compMode);
+}
+
+void extractAndEncodeVOC(const char *outName, FILE *input, CompressMode compMode) {
+	FILE *f;
+	int bits;
+	int blocktype;
+	int channels;
+	unsigned int length;
+	int sample_rate;
+	int comp;
+	char fbuf[2048];
+	size_t size;
+	int real_samplerate = -1;
+
+	f = fopen(outName, "wb");
+
+	while ((blocktype = fgetc(input))) {
+		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
+			   with an invalid length field (value to small). So we encounter
+			   the "block types" 0x80, 0x82 etc.. Not sure if there is another
+			   (maybe even better) way to work around that... ?
+			 */
+			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;
+
+		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);
+		}
+
+		printf(" - length = %d\n", length);
+		printf(" - sample rate = %d (%02x)\n", real_samplerate, sample_rate);
+		printf(" - compression = %s (%02x)\n",
+			   (comp ==	   0 ? "8bits"   :
+				(comp ==   1 ? "4bits"   :
+				 (comp ==  2 ? "2.6bits" :
+				  (comp == 3 ? "2bits"   :
+								"Multi")))), comp);
+
+		if (comp != 0) {
+			error("Cannot handle compressed VOC data");
+		}
+
+		/* Copy the raw data to a temporary file */
+		while (length > 0) {
+			size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : (uint32)length, input);
+
+			if (size <= 0) {
+				break;
+			}
+
+			length -= (int)size;
+			fwrite(fbuf, 1, size, f);
+		}
+	}
+
+	fclose(f);
+
+	assert(real_samplerate != -1);
+
+	setRawAudioType(false, false, 8);
+
+	/* Convert the raw temp file to OGG/MP3 */
+	encodeAudio(outName, true, real_samplerate, tempEncoded, compMode);
+}
+
+int process_mp3_parms(int argc, char *argv[], int i) {
+	for (; i < argc; i++) {
+		if (strcmp(argv[i], "--vbr") == 0) {
+			encparms.abr = 0;
+		} else if (strcmp(argv[i], "--abr") == 0) {
+			encparms.abr = 1;
+		} else if (strcmp(argv[i], "-b") == 0) {
+			encparms.minBitr = atoi(argv[i + 1]);
+
+			if ((encparms.minBitr % 8) != 0) {
+				encparms.minBitr -= encparms.minBitr % 8;
+			}
+
+			if (encparms.minBitr > 160) {
+				encparms.minBitr = 160;
+			}
+
+			if (encparms.minBitr < 8) {
+				encparms.minBitr = 8;
+			}
+
+			i++;
+		} else if (strcmp(argv[i], "-B") == 0) {
+			encparms.maxBitr = atoi(argv[i + 1]);
+
+			if ((encparms.maxBitr % 8) != 0) {
+				encparms.maxBitr -= encparms.maxBitr % 8;
+			}
+
+			if (encparms.maxBitr > 160) {
+				encparms.maxBitr = 160;
+			}
+
+			if (encparms.maxBitr < 8) {
+				encparms.maxBitr = 8;
+			}
+
+			i++;
+		} else if (strcmp(argv[i], "-V") == 0) {
+			encparms.vbrqual = atoi(argv[i + 1]);
+
+			if(encparms.vbrqual < 0) {
+				encparms.vbrqual = 0;
+			}
+
+			if(encparms.vbrqual > 9) {
+				encparms.vbrqual = 9;
+			}
+
+			i++;
+		} else if (strcmp(argv[i], "-q") == 0) {
+			encparms.algqual = atoi(argv[i + 1]);
+
+			if (encparms.algqual < 0) {
+				encparms.algqual = 0;
+			}
+
+			if (encparms.algqual > 9) {
+				encparms.algqual = 9;
+			}
+
+			i++;
+		} else if (strcmp(argv[i], "--silent") == 0) {
+			encparms.silent = 1;
+		} else if (strcmp(argv[i], "--help") == 0) {
+			return 0;
+		} else if (argv[i][0] == '-') {
+			return 0;
+		} else {
+			break;
+		}
+	}
+
+	if (i != (argc - 1)) {
+		return 0;
+	}
+
+	return 1;
+}
+
+int process_ogg_parms(int argc, char *argv[], int i) {
+	for (; i < argc; i++) {
+		if (strcmp(argv[i], "-b") == 0) {
+			oggparms.nominalBitr = atoi(argv[i + 1]);
+
+			if ((oggparms.nominalBitr % 8) != 0) {
+				oggparms.nominalBitr -= oggparms.nominalBitr % 8;
+			}
+
+			if (oggparms.nominalBitr >160) {
+				oggparms.nominalBitr = 160;
+			}
+
+			if (oggparms.nominalBitr < 8) {
+				oggparms.nominalBitr = 8;
+			}
+
+			i++;
+		} else if (strcmp(argv[i], "-m") == 0) {
+			oggparms.minBitr = atoi(argv[i + 1]);
+
+			if ((oggparms.minBitr % 8) != 0) {
+				oggparms.minBitr -= oggparms.minBitr % 8;
+			}
+
+			if (oggparms.minBitr >160) {
+				oggparms.minBitr = 160;
+			}
+
+			if (oggparms.minBitr < 8) {
+				oggparms.minBitr = 8;
+			}
+
+			i++;
+		}
+		else if (strcmp(argv[i], "-M") == 0) {
+			oggparms.maxBitr = atoi(argv[i + 1]);
+
+			if ((oggparms.maxBitr % 8) != 0) {
+				oggparms.maxBitr -= encparms.minBitr % 8;
+			}
+
+			if (oggparms.maxBitr >160) {
+				oggparms.maxBitr = 160;
+			}
+
+			if (oggparms.maxBitr < 8) {
+				oggparms.maxBitr = 8;
+			}
+
+			i++;
+		}
+		else if (strcmp(argv[i], "-q") == 0) {
+			oggparms.quality = atoi(argv[i + 1]);
+			i++;
+		}
+		else if (strcmp(argv[i], "--silent") == 0) {
+			oggparms.silent = 1;
+		}
+		else if (strcmp(argv[i], "--help") == 0) {
+			return 0;
+		}
+		else if (argv[i][0] == '-') {
+			return 0;
+		}
+		else {
+			break;
+		}
+	}
+
+	if (i != argc - 1) {
+		return 0;
+	}
+
+	return 1;
+}
+
+int process_flac_parms(int argc, char *argv[], int i){
+	for (; i < argc; i++) {
+		if (strcmp(argv[i], "-b") == 0) {
+			flacparms.blocksize = atoi(argv[i + 1]);
+			i++;
+		}
+		else if (strcmp(argv[i], "--fast") == 0) {
+			flacparms.compressionLevel = 0;
+		}
+		else if (strcmp(argv[i], "--best") == 0) {
+			flacparms.compressionLevel = 8;
+		}
+		else if (strcmp(argv[i], "-0") == 0) {
+			flacparms.compressionLevel = 0;
+		}
+		else if (strcmp(argv[i], "-1") == 0) {
+			flacparms.compressionLevel = 1;
+		}
+		else if (strcmp(argv[i], "-2") == 0) {
+			flacparms.compressionLevel = 2;
+		}
+		else if (strcmp(argv[i], "-3") == 0) {
+			flacparms.compressionLevel = 3;
+		}
+		else if (strcmp(argv[i], "-4") == 0) {
+			flacparms.compressionLevel = 4;
+		}
+		else if (strcmp(argv[i], "-5") == 0) {
+			flacparms.compressionLevel = 5;
+		}
+		else if (strcmp(argv[i], "-6") == 0) {
+			flacparms.compressionLevel = 6;
+		}
+		else if (strcmp(argv[i], "-7") == 0) {
+			flacparms.compressionLevel = 7;
+		}
+		else if (strcmp(argv[i], "-8") == 0) {
+			flacparms.compressionLevel = 8;
+		}
+		else if (strcmp(argv[i], "--verify") == 0) {
+			flacparms.verify = true;
+		}
+		else if (strcmp(argv[i], "--silent") == 0) {
+			flacparms.silent = true;
+		}
+		else if (strcmp(argv[i], "--help") == 0) {
+			return 0;
+		}
+		else if (argv[i][0] == '-') {
+			return 0;
+		}
+		else {
+			break;
+		}
+	}
+
+	if (i != argc - 1) {
+		return 0;
+	}
+
+	return 1;
+}

Deleted: tools/trunk/compress_agos.c
===================================================================
--- tools/trunk/compress_agos.c	2008-02-25 14:13:12 UTC (rev 30963)
+++ tools/trunk/compress_agos.c	2008-02-25 14:37:16 UTC (rev 30964)
@@ -1,381 +0,0 @@
-/* compress_agos - Compress Simon the Sorcerer 1/2 digital sound files into MP3-format
- * Copyright (C) 2004-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 TEMP_DAT	"tempfile.dat"
-#define TEMP_IDX	"tempfile.idx"
-
-static FILE *input, *output_idx, *output_snd;
-
-static CompressMode gCompMode = kMP3Mode;
-
-static void end(char *inputPath, char* inputFile) {
-	int size;
-	char fbuf[2048];
-	char tmp[1024];
-	char *p;
-	const char *head;
-
-	switch (gCompMode) {
-	case kMP3Mode:
-		head = "mp3";
-		break;
-	case kVorbisMode:
-		head = "ogg";
-		break;
-	case kFlacMode:
-		head = "fla";
-		break;
-	default:
-		error("Unknown compression mode");
-	}
-
-	fclose(output_snd);
-	fclose(output_idx);
-	fclose(input);
-
-	/* Remove the extension from the filename if it exists
-	 * so that we can append the new extension
-	*/
-	p = strrchr(inputFile, '.');
-	if (p) {
-		*p = '\0';
-	}
-
-	sprintf(tmp, "%s/%s.%s", inputPath, inputFile, head);
-	output_idx = fopen(tmp, "wb");
-
-	input = fopen(TEMP_IDX, "rb");
-	while ((size = fread(fbuf, 1, 2048, input)) > 0) {
-		fwrite(fbuf, 1, size, output_idx);
-	}
-
-	fclose(input);
-
-	input = fopen(TEMP_DAT, "rb");
-	while ((size = fread(fbuf, 1, 2048, input)) > 0) {
-		fwrite(fbuf, 1, size, output_idx);
-	}
-
-	fclose(input);
-	fclose(output_idx);
-
-	/* And some clean-up :-) */
-	unlink(TEMP_IDX);
-	unlink(TEMP_DAT);
-	unlink(TEMP_RAW);
-	unlink(tempEncoded);
-	unlink(TEMP_WAV);
-
-	exit(0);
-}
-
-
-static int get_offsets(uint32 filenums[], uint32 offsets[]) {
-	int i;
-	char buf[8];
-
-	for (i = 0;; i++) {
-		fread(buf, 1, 8, input);
-		if (!memcmp(buf, "Creative", 8) || !memcmp(buf, "RIFF", 4)) {
-			return i;
-		}
-		fseek(input, -8, SEEK_CUR);
-
-		offsets[i] = readUint32LE(input);
-	}
-}
-
-static int get_offsets_mac(uint32 filenums[], uint32 offsets[]) {
-	int i, size;
-	size = fileSize(input);
-
-	for (i = 1; i <= size / 6; i++) {
-		filenums[i] = readUint16BE(input);
-		offsets[i] = readUint32BE(input);
-	}
-
-	return(size/6);
-}
-
-
-static uint32 get_sound(uint32 offset) {
-	FILE *f;
-	uint32 tot_size;
-	char outname[256];
-	int size;
-	char fbuf[2048];
-	char buf[8];
-
-	fseek(input, offset, SEEK_SET);
-
-	fread(buf, 1, 8, input);
-	if (!memcmp(buf, "Creative", 8)) {
-		printf("VOC found (pos = %d) :\n", offset);
-		fseek(input, 18, SEEK_CUR);
-		extractAndEncodeVOC(TEMP_RAW, input, gCompMode);
-	} else if (!memcmp(buf, "RIFF", 4)) {
-		printf("WAV found (pos = %d) :\n", offset);
-		extractAndEncodeWAV(TEMP_WAV, input, gCompMode);
-	} else {
-		error("Unexpected data at offset: %d", offset);
-	}
-
-	/* Append the converted data to the master output file */
-	sprintf(outname, tempEncoded);
-	f = fopen(outname, "rb");
-	tot_size = 0;
-	while ((size = fread(fbuf, 1, 2048, f)) > 0) {
-		tot_size += size;
-		fwrite(fbuf, 1, size, output_snd);
-	}
-	fclose(f);
-
-	return(tot_size);
-}
-
-void showhelp(char *exename) {
-	printf("\nUsage: %s [params] [--mac] <file>\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(" --mac        encode simon2mac sounds\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(" --fast       FLAC uses compresion level 0\n");
- 	printf(" --best       FLAC uses compresion level 8\n");
- 	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
- 	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
-	printf(" --verify     files are encoded and then decoded to check accuracy\n");
- 	printf(" --silent     the output of FLAC is hidden (default:disabled)\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");
-	printf("\nIf converting simon2mac sounds, use the --mac option\n");
-	printf("and replace <file> with the path to the 'voices' folder\n");
-	printf("If the input directory is the same as the current directory use '.'\n");
-	exit(2);
-}
-
-
-static void convert_pc(char *inputPath, char *inputFile) {
-	int i, size, num;
-	char tmp[1024];
-	uint32 filenums[32768];
-	uint32 offsets[32768];
-
-	sprintf(tmp, "%s/%s", inputPath, inputFile);
-	input = fopen(tmp, "rb");
-	if (!input) {
-		printf("Cannot open file: %s\n", tmp);
-		exit(-1);
-	}
-
-	output_idx = fopen(TEMP_IDX, "wb");
-	if (!output_idx) {
-		printf("Can't open file " TEMP_IDX " for write!\n" );
-		exit(-1);
-	}
-
-	output_snd = fopen(TEMP_DAT, "wb");
-	if (!output_snd) {
-		printf("Can't open file " TEMP_DAT " for write!\n" );
-		exit(-1);
-	}
-
-	num = get_offsets(filenums, offsets);
-	if (!num) {
-		printf("This does not seem to be a valid file\n");
-		exit(-1);
-	}
-	size = num * 4;
-
-	writeUint32LE(output_idx, 0);
-	writeUint32LE(output_idx, size);
-
-	for (i = 1; i < num; i++) {
-		if (offsets[i] == offsets[i + 1]) {
-			writeUint32LE(output_idx, size);
-			continue;
-		}
-
-		if (offsets[i] != 0)
-			size += get_sound(offsets[i]);
-		if (i < num - 1)
-			writeUint32LE(output_idx, size);
-	}
-}
-
-static void convert_mac(char *inputPath) {
-	int i, size, num;
-	char tmp[1024];
-	uint32 filenums[32768];
-	uint32 offsets[32768];
-
-	sprintf(tmp, "%s/voices.idx", inputPath);
-	input = fopen(tmp, "rb");
-	if (!input) {
-		printf("Cannot open file: %s\n", "voices.idx");
-		exit(-1);
-	}
-
-	output_idx = fopen(TEMP_IDX, "wb");
-	if (!output_idx) {
-		printf("Can't open file " TEMP_IDX " for write!\n" );
-		exit(-1);
-	}
-
-	output_snd = fopen(TEMP_DAT, "wb");
-	if (!output_snd) {
-		printf("Can't open file " TEMP_DAT " for write!\n" );
-		exit(-1);
-	}
-
-	num = get_offsets_mac(filenums, offsets);
-	if (!num) {
-		printf("This does not seem to be a valid file\n");
-		exit(-1);
-	}
-	size = num * 4;
-
-	writeUint32LE(output_idx, 0);
-	writeUint32LE(output_idx, size);
-
-	for (i = 1; i < num; i++) {
-		if (filenums[i] == filenums[i + 1] && offsets[i] == offsets[i + 1]) {
-			writeUint32LE(output_idx, size);
-			continue;
-		}
-
-		if (filenums[i] != filenums[i - 1]) {
-			sprintf(tmp, "%s/voices%d.dat", inputPath, filenums[i]);
-
-			if (input) {
-				fclose(input);
-			}
-
-			input = fopen(tmp, "rb");
-			if (!input) {
-				printf("Cannot open file: %s\n", tmp);
-				exit(-1);
-			}
-		}
-
-		size += get_sound(offsets[i]);
-
-		if (i < num - 1) {
-			writeUint32LE(output_idx, size);
-		}
-	}
-}
-
-int main(int argc, char *argv[]) {
-	int i;
-	char inputFile[256];
-	char inputPath[768];
-	bool convertMac = false;
-
-	if (argc < 2) {
-		showhelp(argv[0]);
-	}
-
-	/* compression mode */
-	gCompMode = kMP3Mode;
-	i = 1;
-
-	if (strcmp(argv[i], "--mp3") == 0) {
-		gCompMode = kMP3Mode;
-		i++;
-	} else if (strcmp(argv[i], "--vorbis") == 0) {
-		gCompMode = kVorbisMode;
-		i++;
-	} else if (strcmp(argv[i], "--flac") == 0) {
-		gCompMode = kFlacMode;
-		i++;
-	}
-
-	if (strcmp(argv[i], "--mac") == 0) {
-		convertMac = true;
-		i++;
-	}
-
-	switch (gCompMode) {
-	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;
-	}
-
-	if (convertMac) {
-		strcpy(inputFile, "simon2");
-		strcpy(inputPath, argv[argc - 1]);
-		convert_mac(inputPath);
-	} else {
-		getPath(argv[argc - 1], inputPath);
-		getFilename(argv[argc - 1], inputFile);
-		convert_pc(inputPath, inputFile);
-	}
-
-	end(inputPath, inputFile);
-
-	return(0);
-}
-

Copied: tools/trunk/compress_agos.cpp (from rev 30960, tools/trunk/compress_agos.c)
===================================================================
--- tools/trunk/compress_agos.cpp	                        (rev 0)
+++ tools/trunk/compress_agos.cpp	2008-02-25 14:37:16 UTC (rev 30964)
@@ -0,0 +1,381 @@
+/* compress_agos - Compress Simon the Sorcerer 1/2 digital sound files into MP3-format
+ * Copyright (C) 2004-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 TEMP_DAT	"tempfile.dat"
+#define TEMP_IDX	"tempfile.idx"
+
+static FILE *input, *output_idx, *output_snd;
+
+static CompressMode gCompMode = kMP3Mode;
+
+static void end(char *inputPath, char* inputFile) {
+	int size;
+	char fbuf[2048];
+	char tmp[1024];
+	char *p;
+	const char *head;
+
+	switch (gCompMode) {
+	case kMP3Mode:
+		head = "mp3";
+		break;
+	case kVorbisMode:
+		head = "ogg";
+		break;
+	case kFlacMode:
+		head = "fla";
+		break;
+	default:
+		error("Unknown compression mode");
+	}
+
+	fclose(output_snd);
+	fclose(output_idx);
+	fclose(input);
+
+	/* Remove the extension from the filename if it exists
+	 * so that we can append the new extension
+	*/
+	p = strrchr(inputFile, '.');
+	if (p) {
+		*p = '\0';
+	}
+
+	sprintf(tmp, "%s/%s.%s", inputPath, inputFile, head);
+	output_idx = fopen(tmp, "wb");
+
+	input = fopen(TEMP_IDX, "rb");
+	while ((size = fread(fbuf, 1, 2048, input)) > 0) {
+		fwrite(fbuf, 1, size, output_idx);
+	}
+
+	fclose(input);
+
+	input = fopen(TEMP_DAT, "rb");
+	while ((size = fread(fbuf, 1, 2048, input)) > 0) {
+		fwrite(fbuf, 1, size, output_idx);
+	}
+
+	fclose(input);
+	fclose(output_idx);
+
+	/* And some clean-up :-) */
+	unlink(TEMP_IDX);
+	unlink(TEMP_DAT);
+	unlink(TEMP_RAW);
+	unlink(tempEncoded);
+	unlink(TEMP_WAV);
+
+	exit(0);
+}
+
+
+static int get_offsets(uint32 filenums[], uint32 offsets[]) {
+	int i;
+	char buf[8];
+
+	for (i = 0;; i++) {
+		fread(buf, 1, 8, input);
+		if (!memcmp(buf, "Creative", 8) || !memcmp(buf, "RIFF", 4)) {
+			return i;
+		}
+		fseek(input, -8, SEEK_CUR);
+
+		offsets[i] = readUint32LE(input);
+	}
+}
+
+static int get_offsets_mac(uint32 filenums[], uint32 offsets[]) {
+	int i, size;
+	size = fileSize(input);
+
+	for (i = 1; i <= size / 6; i++) {
+		filenums[i] = readUint16BE(input);
+		offsets[i] = readUint32BE(input);
+	}
+
+	return(size/6);
+}
+
+
+static uint32 get_sound(uint32 offset) {
+	FILE *f;
+	uint32 tot_size;
+	char outname[256];
+	int size;
+	char fbuf[2048];
+	char buf[8];
+
+	fseek(input, offset, SEEK_SET);
+
+	fread(buf, 1, 8, input);
+	if (!memcmp(buf, "Creative", 8)) {
+		printf("VOC found (pos = %d) :\n", offset);
+		fseek(input, 18, SEEK_CUR);
+		extractAndEncodeVOC(TEMP_RAW, input, gCompMode);
+	} else if (!memcmp(buf, "RIFF", 4)) {
+		printf("WAV found (pos = %d) :\n", offset);
+		extractAndEncodeWAV(TEMP_WAV, input, gCompMode);
+	} else {
+		error("Unexpected data at offset: %d", offset);
+	}
+
+	/* Append the converted data to the master output file */
+	sprintf(outname, tempEncoded);
+	f = fopen(outname, "rb");
+	tot_size = 0;
+	while ((size = fread(fbuf, 1, 2048, f)) > 0) {
+		tot_size += size;
+		fwrite(fbuf, 1, size, output_snd);
+	}
+	fclose(f);
+
+	return(tot_size);
+}
+
+void showhelp(char *exename) {
+	printf("\nUsage: %s [params] [--mac] <file>\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(" --mac        encode simon2mac sounds\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(" --fast       FLAC uses compresion level 0\n");
+ 	printf(" --best       FLAC uses compresion level 8\n");
+ 	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+ 	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+ 	printf(" --silent     the output of FLAC is hidden (default:disabled)\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");
+	printf("\nIf converting simon2mac sounds, use the --mac option\n");
+	printf("and replace <file> with the path to the 'voices' folder\n");
+	printf("If the input directory is the same as the current directory use '.'\n");
+	exit(2);
+}
+
+
+static void convert_pc(char *inputPath, char *inputFile) {
+	int i, size, num;
+	char tmp[1024];
+	uint32 filenums[32768];
+	uint32 offsets[32768];
+
+	sprintf(tmp, "%s/%s", inputPath, inputFile);
+	input = fopen(tmp, "rb");
+	if (!input) {
+		printf("Cannot open file: %s\n", tmp);
+		exit(-1);
+	}
+
+	output_idx = fopen(TEMP_IDX, "wb");
+	if (!output_idx) {
+		printf("Can't open file " TEMP_IDX " for write!\n" );
+		exit(-1);
+	}
+
+	output_snd = fopen(TEMP_DAT, "wb");
+	if (!output_snd) {
+		printf("Can't open file " TEMP_DAT " for write!\n" );
+		exit(-1);
+	}
+
+	num = get_offsets(filenums, offsets);
+	if (!num) {
+		printf("This does not seem to be a valid file\n");
+		exit(-1);
+	}
+	size = num * 4;
+
+	writeUint32LE(output_idx, 0);
+	writeUint32LE(output_idx, size);
+
+	for (i = 1; i < num; i++) {
+		if (offsets[i] == offsets[i + 1]) {
+			writeUint32LE(output_idx, size);
+			continue;
+		}
+
+		if (offsets[i] != 0)
+			size += get_sound(offsets[i]);
+		if (i < num - 1)
+			writeUint32LE(output_idx, size);
+	}
+}
+
+static void convert_mac(char *inputPath) {
+	int i, size, num;
+	char tmp[1024];
+	uint32 filenums[32768];
+	uint32 offsets[32768];
+
+	sprintf(tmp, "%s/voices.idx", inputPath);
+	input = fopen(tmp, "rb");
+	if (!input) {
+		printf("Cannot open file: %s\n", "voices.idx");
+		exit(-1);
+	}
+
+	output_idx = fopen(TEMP_IDX, "wb");
+	if (!output_idx) {
+		printf("Can't open file " TEMP_IDX " for write!\n" );
+		exit(-1);
+	}
+
+	output_snd = fopen(TEMP_DAT, "wb");
+	if (!output_snd) {
+		printf("Can't open file " TEMP_DAT " for write!\n" );
+		exit(-1);
+	}
+
+	num = get_offsets_mac(filenums, offsets);
+	if (!num) {
+		printf("This does not seem to be a valid file\n");
+		exit(-1);
+	}
+	size = num * 4;
+
+	writeUint32LE(output_idx, 0);
+	writeUint32LE(output_idx, size);
+
+	for (i = 1; i < num; i++) {
+		if (filenums[i] == filenums[i + 1] && offsets[i] == offsets[i + 1]) {
+			writeUint32LE(output_idx, size);
+			continue;
+		}
+
+		if (filenums[i] != filenums[i - 1]) {
+			sprintf(tmp, "%s/voices%d.dat", inputPath, filenums[i]);
+
+			if (input) {
+				fclose(input);
+			}
+
+			input = fopen(tmp, "rb");
+			if (!input) {
+				printf("Cannot open file: %s\n", tmp);
+				exit(-1);
+			}
+		}
+
+		size += get_sound(offsets[i]);
+
+		if (i < num - 1) {
+			writeUint32LE(output_idx, size);
+		}
+	}
+}
+
+int main(int argc, char *argv[]) {
+	int i;
+	char inputFile[256];
+	char inputPath[768];
+	bool convertMac = false;
+
+	if (argc < 2) {
+		showhelp(argv[0]);
+	}
+
+	/* compression mode */
+	gCompMode = kMP3Mode;
+	i = 1;
+
+	if (strcmp(argv[i], "--mp3") == 0) {
+		gCompMode = kMP3Mode;
+		i++;
+	} else if (strcmp(argv[i], "--vorbis") == 0) {
+		gCompMode = kVorbisMode;
+		i++;
+	} else if (strcmp(argv[i], "--flac") == 0) {
+		gCompMode = kFlacMode;
+		i++;
+	}
+
+	if (strcmp(argv[i], "--mac") == 0) {
+		convertMac = true;
+		i++;
+	}
+
+	switch (gCompMode) {
+	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;
+	}
+
+	if (convertMac) {
+		strcpy(inputFile, "simon2");
+		strcpy(inputPath, argv[argc - 1]);
+		convert_mac(inputPath);
+	} else {
+		getPath(argv[argc - 1], inputPath);
+		getFilename(argv[argc - 1], inputFile);
+		convert_pc(inputPath, inputFile);
+	}
+
+	end(inputPath, inputFile);
+
+	return(0);
+}
+

Deleted: tools/trunk/compress_queen.c
===================================================================
--- tools/trunk/compress_queen.c	2008-02-25 14:13:12 UTC (rev 30963)
+++ tools/trunk/compress_queen.c	2008-02-25 14:37:16 UTC (rev 30964)
@@ -1,445 +0,0 @@
-/* compress_queen - Rebuild QUEEN.1 file to contain Resource Table (and optionally compress sound & speech)
- * Copyright (C) 2003-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"
-
-static const uint32 QTBL = 'QTBL';
-static CompressMode gCompMode = kMP3Mode;
-
-#define INPUT_TBL	"queen.tbl"
-#define FINAL_OUT	"queen.1c"
-
-#define TEMP_DAT	"tempfile.dat"
-#define TEMP_TBL	"tempfile.tbl"
-#define TEMP_SB		"tempfile.sb"
-
-#define CURRENT_TBL_VERSION	2
-#define EXTRA_TBL_HEADER 8
-#define SB_HEADER_SIZE_V104 110
-#define SB_HEADER_SIZE_V110 122
-
-enum {
-	COMPRESSION_NONE = 0,
-	COMPRESSION_MP3 = 1,
-	COMPRESSION_OGG = 2,
-	COMPRESSION_FLAC = 3
-};
-
-enum {
-	VER_ENG_FLOPPY     = 0,
-	VER_ENG_TALKIE     = 1,
-	VER_FRE_FLOPPY     = 2,
-	VER_FRE_TALKIE     = 3,
-	VER_GER_FLOPPY     = 4,
-	VER_GER_TALKIE     = 5,
-	VER_ITA_FLOPPY     = 6,
-	VER_ITA_TALKIE     = 7,
-	VER_SPA_TALKIE     = 8,
-	VER_HEB_TALKIE     = 9,
-	VER_DEMO_PCGAMES   = 10,
-	VER_DEMO           = 11,
-	VER_INTERVIEW      = 12,
-	VER_AMI_ENG_FLOPPY = 13,
-	VER_AMI_DEMO       = 14,
-	VER_AMI_INTERVIEW  = 15,
-
-	VER_PC_COUNT       = 13 /* PC versions */
-};
-
-struct GameVersion {
-	char versionString[6];
-	uint8 isFloppy;
-	uint8 isDemo;
-	uint32 tableOffset;
-	uint32 dataFileSize;
-};
-
-struct {
-	char filename[13];
-	uint8 bundle;
-	uint32 offset;
-	uint32 size;
-} entry;
-
-struct {
-	uint8	compression;
-	uint16	entries;
-} versionExtra;
-
-struct PatchFile {
-	const char *filename;
-	char lang;
-};
-
-const struct GameVersion gameVersions[] = {
-	{ "PEM10", 1, 0, 0x00000008,  22677657 },
-	{ "CEM10", 0, 0, 0x0000584E, 190787021 },
-	{ "PFM10", 1, 0, 0x0002CD93,  22157304 },
-	{ "CFM10", 0, 0, 0x00032585, 186689095 },
-	{ "PGM10", 1, 0, 0x00059ACA,  22240013 },
-	{ "CGM10", 0, 0, 0x0005F2A7, 217648975 },
-	{ "PIM10", 1, 0, 0x000866B1,  22461366 },
-	{ "CIM10", 0, 0, 0x0008BEE2, 190795582 },
-	{ "CSM10", 0, 0, 0x000B343C, 190730602 },
-	{ "CHM10", 0, 0, 0x000DA981, 190705558 },
-	{ "PE100", 1, 1, 0x00101EC6,   3724538 },
-	{ "PE100", 1, 1, 0x00102B7F,   3732177 },
-	{ "PEint", 1, 1, 0x00103838,   1915913 },
-	{ "aEM10", 1, 0, 0x00103F1E,    351775 },
-	{ "CE101", 1, 1, 0x00107D8D,    563335 },
-	{ "PE100", 1, 1, 0x001086D4,    597032 }
-};
-
-const struct PatchFile patchFiles[] = {
-	{ "CHIEF1.DOG", 'F' },
-	{ "CHIEF2.DOG", 'F' },
-	{ "BUD1.DOG",   'I' }
-};
-
-const struct GameVersion *version;
-
-void showhelp(char *exename) {
-	printf("\nUsage: %s [params] queen.1\n", exename);
-
-	printf("\nParams:\n");
-
-	printf(" --mp3        encode to MP3 format (default)\n");
-	printf(" --vorbis     encode to Ogg 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(" --fast       FLAC uses compresion level 0\n");
-	printf(" --best       FLAC uses compresion level 8\n");
-	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
-	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
-	printf(" --verify     files are encoded and then decoded to check accuracy\n");
-	printf(" --silent     the output of FLAC is hidden (default:disabled)\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);
-}
-
-const struct GameVersion *detectGameVersion(uint32 size) {
-	const struct GameVersion *pgv = gameVersions;
-	int i;
-
-	/* Compressing/rebuiling an Amiga version is not supported */
-	for (i = 0; i < VER_PC_COUNT; ++i, ++pgv) {
-		if (pgv->dataFileSize == size) {
-			return pgv;
-		}
- 	}
-
-	printf("Unknown/unsupported FOTAQ version!\n");
-
-	exit(1);
-	return NULL;
-}
-
-void checkOpen(FILE *fp, const char *filename) {
-	if (!fp) {
-		printf("Cannot open file: %s\n", filename);
-		exit(-1);
-	}
-}
-
-void fromFileToFile(FILE *in, FILE *out, uint32 amount) {
-	char fBuf[2048];
-	uint32 numRead;
-
-	while (amount > 0) {
-		numRead = fread(fBuf, 1, amount > 2048 ? 2048 : amount, in);
-		if (numRead <= 0) {
-			break;
-		}
-
-		amount -= numRead;
-		fwrite(fBuf, 1, numRead, out);
-	}
-}
-
-void createFinalFile(char *inputPath) {
-	FILE *inTbl, *inData, *outFinal;
-	char tmp[1024];
-	int i;
-	uint32 dataStartOffset;
-	uint32 dataSize;
-
-	inTbl = fopen(TEMP_TBL, "rb");
-	checkOpen(inTbl, TEMP_TBL);
-	inData = fopen(TEMP_DAT, "rb");
-	checkOpen(inData, TEMP_DAT);
-	sprintf(tmp, "%s/%s", inputPath, FINAL_OUT);
-	outFinal = fopen(tmp, "wb");
-	checkOpen(outFinal, FINAL_OUT);
-
-	dataStartOffset = fileSize(inTbl) + EXTRA_TBL_HEADER;
-	dataSize = fileSize(inData);
-
-	fseek(inTbl, 7, SEEK_SET);	/* Skip past header */
-
-	/* Write new header */
-	writeUint32BE(outFinal, QTBL);
-	fwrite(version->versionString, 6, 1, outFinal);
-	writeByte(outFinal, version->isFloppy);
-	writeByte(outFinal, version->isDemo);
-	writeByte(outFinal, versionExtra.compression);
-	writeUint16BE(outFinal, versionExtra.entries);
-
-	for (i = 0; i < versionExtra.entries; i++) {
-		fromFileToFile(inTbl, outFinal, 12);
-		writeByte(outFinal, readByte(inTbl));
-		writeUint32BE(outFinal, dataStartOffset + readUint32BE(inTbl));
-		writeUint32BE(outFinal, readUint32BE(inTbl));
-	}
-
-	/* Append contents of temporary datafile to final datafile */
-	fromFileToFile(inData, outFinal, dataSize);
-
-	fclose(inTbl);
-	fclose(inData);
-	fclose(outFinal);
-
-	/* Cleanup */
-	unlink(TEMP_TBL);
-	unlink(TEMP_DAT);
-}
-
-int main(int argc, char *argv[]) {
-	FILE *inputData, *inputTbl, *outputTbl, *outputData, *tmpFile, *compFile;
-	uint8 compressionType = COMPRESSION_NONE;
-	char inputPath[768];
-	char tblPath[1024];
-	char tmp[5];
-	int size, i = 1;
-	uint32 prevOffset;
-
-	if (argc < 2) {
-		showhelp(argv[0]);
-	}
-
-	/* compression mode */
-	compressionType = COMPRESSION_MP3;
-	gCompMode = kMP3Mode;
-
-	if (strcmp(argv[1], "--mp3") == 0) {
-		compressionType = COMPRESSION_MP3;
-		gCompMode = kMP3Mode;
-		i++;
-	} else if (strcmp(argv[1], "--vorbis") == 0) {
-		compressionType = COMPRESSION_OGG;
-		gCompMode = kVorbisMode;
-		i++;
-	} else if (strcmp(argv[1], "--flac") == 0) {
-		compressionType = COMPRESSION_FLAC;
-		gCompMode = kFlacMode;
-		i++;
-	}
-
-	switch (gCompMode) {
-	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;
-	}
-
-	getPath(argv[argc - 1], inputPath);
-
-	/* Open input file (QUEEN.1) */
-	inputData = fopen(argv[argc-1], "rb");
-	checkOpen(inputData, argv[argc-1]);
-
-	/* Open TBL file (QUEEN.TBL) */
-	sprintf(tblPath, "%s/%s", inputPath, INPUT_TBL);
-	inputTbl = fopen(tblPath, "rb");
-	checkOpen(inputTbl, INPUT_TBL);
-
-	size = fileSize(inputData);
-	fread(tmp, 1, 4, inputTbl);
-	tmp[4] = '\0';
-
-	if (memcmp(tmp, "QTBL", 4)) {
-		error("Invalid TBL file");
-	}
-
-	if (readUint32BE(inputTbl) != CURRENT_TBL_VERSION) {
-		error("You are using an incorrect (outdated?) version of the queen.tbl file");
-	}
-
-	version = detectGameVersion(size);
-	fseek(inputTbl, version->tableOffset, SEEK_SET);
-
-	versionExtra.compression = compressionType;
-	versionExtra.entries = readUint16BE(inputTbl);
-
-	outputTbl = fopen(TEMP_TBL, "wb");
-	checkOpen(outputTbl, TEMP_TBL);
-
-	outputData = fopen(TEMP_DAT, "wb");
-	checkOpen(outputData, TEMP_DAT);
-
-	/* Write tablefile header */
-	writeUint32BE(outputTbl, QTBL);
-	writeByte(outputTbl, versionExtra.compression);
-	writeUint16BE(outputTbl, versionExtra.entries);
-
-	for (i = 0; i < versionExtra.entries; i++) {
-		prevOffset = ftell(outputData);
-
-		/* Read entry */
-		fread(entry.filename, 1, 12, inputTbl);
-		entry.filename[12] = '\0';
-		entry.bundle = readByte(inputTbl);
-		entry.offset = readUint32BE(inputTbl);
-		entry.size = readUint32BE(inputTbl);
-
-		printf("Processing entry: %s\n", entry.filename);
-		fseek(inputData, entry.offset, SEEK_SET);
-
-		if (versionExtra.compression && strstr(entry.filename, ".SB")) { /* Do we want to compress? */
-			uint16 sbVersion;
-			int headerSize;
-
-			/* Read in .SB */
-			tmpFile = fopen(TEMP_SB, "wb");
-			fseek(inputData, entry.offset, SEEK_SET);
-
-			fseek(inputData, 2, SEEK_CUR);
-			sbVersion = readUint16LE(inputData);
-
-			switch (sbVersion) {
-			case 104:
-				headerSize = SB_HEADER_SIZE_V104;
-				break;
-			case 110:
-				headerSize = SB_HEADER_SIZE_V110;
-				break;
-			default:
-				warning("Unhandled SB file version %d, defaulting to 104\n", sbVersion);
-				headerSize = SB_HEADER_SIZE_V104;
-				break;
-			}
-
-			fseek(inputData, headerSize - 4, SEEK_CUR);
-			entry.size -= headerSize;
-
-			fromFileToFile(inputData, tmpFile, entry.size);
-			fclose(tmpFile);
-
-			/* Invoke encoder */
-			setRawAudioType(false, false, 8);
-			encodeAudio(TEMP_SB, true, 11025, tempEncoded, gCompMode);
-
-			/* Append MP3/OGG to data file */
-			compFile = fopen(tempEncoded, "rb");
-			entry.size = fileSize(compFile);
-			fromFileToFile(compFile, outputData, entry.size);
-			fclose(compFile);
-
-			/* Delete temporary files */
-			unlink(TEMP_SB);
-			unlink(tempEncoded);
-		} else {
-			/* Non .SB file */
-			bool patched = false;
-			/* Check for external files */
-
-			uint8 j;
-			for (j = 0; j < ARRAYSIZE(patchFiles); ++j) {
-				const struct PatchFile *pf = &patchFiles[j];
-
-				if (version->versionString[1] == pf->lang && strcmp(pf->filename, entry.filename) == 0) {
-					/* XXX patched data files are supposed to be in cwd */
-					FILE *fpPatch = fopen(pf->filename, "rb");
-
-					if (fpPatch) {
-						entry.size = fileSize(fpPatch);
-						printf("Patching entry, new size = %d bytes\n", entry.size);
-						fromFileToFile(fpPatch, outputData, entry.size);
-						fclose(fpPatch);
-						patched = true;
-					}
-
-					break;
-				}
-			}
-
-			if (!patched) {
-				fromFileToFile(inputData, outputData, entry.size);
-			}
-		}
-
-		/* Write entry to table */
-		fwrite(entry.filename, 12, 1, outputTbl);
-		writeByte(outputTbl, entry.bundle);
-		writeUint32BE(outputTbl, prevOffset);
-		writeUint32BE(outputTbl, entry.size);
-	}
-
-	/* Close files */
-	fclose(outputTbl);
-	fclose(outputData);
-	fclose(inputTbl);
-	fclose(inputData);
-
-	/* Merge the temporary table and temporary datafile to create final file */
-	createFinalFile(inputPath);
-
-	return 0;
-}

Copied: tools/trunk/compress_queen.cpp (from rev 30960, tools/trunk/compress_queen.c)
===================================================================
--- tools/trunk/compress_queen.cpp	                        (rev 0)
+++ tools/trunk/compress_queen.cpp	2008-02-25 14:37:16 UTC (rev 30964)
@@ -0,0 +1,445 @@
+/* compress_queen - Rebuild QUEEN.1 file to contain Resource Table (and optionally compress sound & speech)
+ * Copyright (C) 2003-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"
+
+static const uint32 QTBL = 'QTBL';
+static CompressMode gCompMode = kMP3Mode;
+
+#define INPUT_TBL	"queen.tbl"
+#define FINAL_OUT	"queen.1c"
+
+#define TEMP_DAT	"tempfile.dat"
+#define TEMP_TBL	"tempfile.tbl"
+#define TEMP_SB		"tempfile.sb"
+
+#define CURRENT_TBL_VERSION	2
+#define EXTRA_TBL_HEADER 8
+#define SB_HEADER_SIZE_V104 110
+#define SB_HEADER_SIZE_V110 122
+
+enum {
+	COMPRESSION_NONE = 0,
+	COMPRESSION_MP3 = 1,
+	COMPRESSION_OGG = 2,
+	COMPRESSION_FLAC = 3
+};
+
+enum {
+	VER_ENG_FLOPPY     = 0,
+	VER_ENG_TALKIE     = 1,
+	VER_FRE_FLOPPY     = 2,
+	VER_FRE_TALKIE     = 3,
+	VER_GER_FLOPPY     = 4,
+	VER_GER_TALKIE     = 5,
+	VER_ITA_FLOPPY     = 6,
+	VER_ITA_TALKIE     = 7,
+	VER_SPA_TALKIE     = 8,
+	VER_HEB_TALKIE     = 9,
+	VER_DEMO_PCGAMES   = 10,
+	VER_DEMO           = 11,
+	VER_INTERVIEW      = 12,
+	VER_AMI_ENG_FLOPPY = 13,
+	VER_AMI_DEMO       = 14,
+	VER_AMI_INTERVIEW  = 15,
+
+	VER_PC_COUNT       = 13 /* PC versions */
+};
+
+struct GameVersion {
+	char versionString[6];
+	uint8 isFloppy;
+	uint8 isDemo;
+	uint32 tableOffset;
+	uint32 dataFileSize;
+};
+
+struct {
+	char filename[13];
+	uint8 bundle;
+	uint32 offset;
+	uint32 size;
+} entry;
+
+struct {
+	uint8	compression;
+	uint16	entries;
+} versionExtra;
+
+struct PatchFile {
+	const char *filename;
+	char lang;
+};
+
+const struct GameVersion gameVersions[] = {
+	{ "PEM10", 1, 0, 0x00000008,  22677657 },
+	{ "CEM10", 0, 0, 0x0000584E, 190787021 },
+	{ "PFM10", 1, 0, 0x0002CD93,  22157304 },
+	{ "CFM10", 0, 0, 0x00032585, 186689095 },
+	{ "PGM10", 1, 0, 0x00059ACA,  22240013 },
+	{ "CGM10", 0, 0, 0x0005F2A7, 217648975 },
+	{ "PIM10", 1, 0, 0x000866B1,  22461366 },
+	{ "CIM10", 0, 0, 0x0008BEE2, 190795582 },
+	{ "CSM10", 0, 0, 0x000B343C, 190730602 },
+	{ "CHM10", 0, 0, 0x000DA981, 190705558 },
+	{ "PE100", 1, 1, 0x00101EC6,   3724538 },
+	{ "PE100", 1, 1, 0x00102B7F,   3732177 },
+	{ "PEint", 1, 1, 0x00103838,   1915913 },
+	{ "aEM10", 1, 0, 0x00103F1E,    351775 },
+	{ "CE101", 1, 1, 0x00107D8D,    563335 },
+	{ "PE100", 1, 1, 0x001086D4,    597032 }
+};
+
+const struct PatchFile patchFiles[] = {
+	{ "CHIEF1.DOG", 'F' },
+	{ "CHIEF2.DOG", 'F' },
+	{ "BUD1.DOG",   'I' }
+};
+
+const struct GameVersion *version;
+
+void showhelp(char *exename) {
+	printf("\nUsage: %s [params] queen.1\n", exename);
+
+	printf("\nParams:\n");
+
+	printf(" --mp3        encode to MP3 format (default)\n");
+	printf(" --vorbis     encode to Ogg 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(" --fast       FLAC uses compresion level 0\n");
+	printf(" --best       FLAC uses compresion level 8\n");
+	printf(" -<value>     specifies the value (0 - 8) of compresion (8=best)(default:%d)\n", flacCompressDef);
+	printf(" -b <value>   specifies a blocksize of <value> samples (default:%d)\n", flacBlocksizeDef);
+	printf(" --verify     files are encoded and then decoded to check accuracy\n");
+	printf(" --silent     the output of FLAC is hidden (default:disabled)\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);
+}
+
+const struct GameVersion *detectGameVersion(uint32 size) {
+	const struct GameVersion *pgv = gameVersions;
+	int i;
+
+	/* Compressing/rebuiling an Amiga version is not supported */
+	for (i = 0; i < VER_PC_COUNT; ++i, ++pgv) {
+		if (pgv->dataFileSize == size) {
+			return pgv;
+		}
+ 	}
+
+	printf("Unknown/unsupported FOTAQ version!\n");
+
+	exit(1);
+	return NULL;
+}
+
+void checkOpen(FILE *fp, const char *filename) {
+	if (!fp) {
+		printf("Cannot open file: %s\n", filename);
+		exit(-1);
+	}
+}
+
+void fromFileToFile(FILE *in, FILE *out, uint32 amount) {
+	char fBuf[2048];
+	uint32 numRead;
+
+	while (amount > 0) {
+		numRead = fread(fBuf, 1, amount > 2048 ? 2048 : amount, in);
+		if (numRead <= 0) {
+			break;
+		}
+
+		amount -= numRead;
+		fwrite(fBuf, 1, numRead, out);
+	}
+}
+
+void createFinalFile(char *inputPath) {
+	FILE *inTbl, *inData, *outFinal;
+	char tmp[1024];
+	int i;
+	uint32 dataStartOffset;
+	uint32 dataSize;
+
+	inTbl = fopen(TEMP_TBL, "rb");
+	checkOpen(inTbl, TEMP_TBL);
+	inData = fopen(TEMP_DAT, "rb");
+	checkOpen(inData, TEMP_DAT);
+	sprintf(tmp, "%s/%s", inputPath, FINAL_OUT);
+	outFinal = fopen(tmp, "wb");
+	checkOpen(outFinal, FINAL_OUT);
+
+	dataStartOffset = fileSize(inTbl) + EXTRA_TBL_HEADER;
+	dataSize = fileSize(inData);
+
+	fseek(inTbl, 7, SEEK_SET);	/* Skip past header */
+
+	/* Write new header */
+	writeUint32BE(outFinal, QTBL);
+	fwrite(version->versionString, 6, 1, outFinal);
+	writeByte(outFinal, version->isFloppy);
+	writeByte(outFinal, version->isDemo);
+	writeByte(outFinal, versionExtra.compression);
+	writeUint16BE(outFinal, versionExtra.entries);
+
+	for (i = 0; i < versionExtra.entries; i++) {
+		fromFileToFile(inTbl, outFinal, 12);
+		writeByte(outFinal, readByte(inTbl));
+		writeUint32BE(outFinal, dataStartOffset + readUint32BE(inTbl));
+		writeUint32BE(outFinal, readUint32BE(inTbl));
+	}
+
+	/* Append contents of temporary datafile to final datafile */
+	fromFileToFile(inData, outFinal, dataSize);
+
+	fclose(inTbl);
+	fclose(inData);
+	fclose(outFinal);
+
+	/* Cleanup */
+	unlink(TEMP_TBL);
+	unlink(TEMP_DAT);
+}
+
+int main(int argc, char *argv[]) {
+	FILE *inputData, *inputTbl, *outputTbl, *outputData, *tmpFile, *compFile;
+	uint8 compressionType = COMPRESSION_NONE;
+	char inputPath[768];
+	char tblPath[1024];
+	char tmp[5];
+	int size, i = 1;
+	uint32 prevOffset;
+
+	if (argc < 2) {
+		showhelp(argv[0]);
+	}
+
+	/* compression mode */
+	compressionType = COMPRESSION_MP3;
+	gCompMode = kMP3Mode;
+
+	if (strcmp(argv[1], "--mp3") == 0) {
+		compressionType = COMPRESSION_MP3;
+		gCompMode = kMP3Mode;
+		i++;
+	} else if (strcmp(argv[1], "--vorbis") == 0) {
+		compressionType = COMPRESSION_OGG;
+		gCompMode = kVorbisMode;
+		i++;
+	} else if (strcmp(argv[1], "--flac") == 0) {
+		compressionType = COMPRESSION_FLAC;
+		gCompMode = kFlacMode;
+		i++;
+	}
+
+	switch (gCompMode) {
+	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;
+	}
+
+	getPath(argv[argc - 1], inputPath);
+
+	/* Open input file (QUEEN.1) */
+	inputData = fopen(argv[argc-1], "rb");
+	checkOpen(inputData, argv[argc-1]);
+
+	/* Open TBL file (QUEEN.TBL) */
+	sprintf(tblPath, "%s/%s", inputPath, INPUT_TBL);
+	inputTbl = fopen(tblPath, "rb");
+	checkOpen(inputTbl, INPUT_TBL);
+
+	size = fileSize(inputData);
+	fread(tmp, 1, 4, inputTbl);
+	tmp[4] = '\0';
+
+	if (memcmp(tmp, "QTBL", 4)) {
+		error("Invalid TBL file");
+	}
+
+	if (readUint32BE(inputTbl) != CURRENT_TBL_VERSION) {
+		error("You are using an incorrect (outdated?) version of the queen.tbl file");
+	}
+
+	version = detectGameVersion(size);
+	fseek(inputTbl, version->tableOffset, SEEK_SET);
+
+	versionExtra.compression = compressionType;
+	versionExtra.entries = readUint16BE(inputTbl);
+
+	outputTbl = fopen(TEMP_TBL, "wb");
+	checkOpen(outputTbl, TEMP_TBL);
+

@@ Diff output truncated at 100000 characters. @@

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