[Scummvm-cvs-logs] CVS: tools sword2mp3.c,NONE,1.1 Makefile,1.34,1.35 Makefile.mingw,1.16,1.17 README,1.18,1.19 extract.h,1.12,1.13
Torbjörn Andersson
eriktorbjorn at users.sourceforge.net
Sun Aug 22 23:23:07 CEST 2004
Update of /cvsroot/scummvm/tools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25646
Modified Files:
Makefile Makefile.mingw README extract.h
Added Files:
sword2mp3.c
Log Message:
Added tool to compress the Broken Sword 2 speech and music clusters. Note
that playback support currently only exists for the speech.
--- NEW FILE: sword2mp3.c ---
/* sword2mp3 - Compress Broken Sword II sound clusters into MP3/Ogg Vorbis
* Copyright (C) 2002, 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: /cvsroot/scummvm/tools/sword2mp3.c,v 1.1 2004/08/23 06:22:15 eriktorbjorn Exp $
*
*/
#include "extract.h"
#define TEMP_IDX "tempfile.idx"
#define TEMP_DAT "tempfile.dat"
static FILE *input, *output_idx, *output_snd;
static CompressMode gCompMode = kMP3Mode;
void showhelp(char *exename)
{
printf("\nUsage: %s <params> monster.sou\n", exename);
printf("\nParams:\n");
printf(" --mp3 encode to MP3 format (default)\n");
printf(" --vorbis encode to Vorbis format\n");
printf(" --flac encode to Flac format\n");
printf("(If one of these is specified, it must be the first parameter.)\n");
printf("\nMP3 mode params:\n");
printf(" -b <rate> <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%i)\n", minBitrDef);
printf(" -B <rate> <rate> is the maximum VBR/ABR bitrate (default:%i)\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:%i)\n", vbrqualDef);
printf(" -q <value> specifies the MPEG algorithm quality (0-9; 0=best) (default:%i)\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:%i)\n", oggqualDef);
printf(" --silent the output of oggenc is hidden (default:disabled)\n");
printf("\nFlac mode params:\n");
printf(" [params] optional Arguments passed directly to the Encoder\n");
printf(" recommended is: --best -b 1152\n");
printf("\n --help this help message\n");
printf("\n\nIf a parameter is not given the default value is used\n");
printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n");
exit(2);
}
uint32 append_to_file(FILE *f1, const char *filename) {
FILE *f2;
uint32 length, orig_length;
size_t size;
char fbuf[2048];
f2 = fopen(filename, "rb");
if (!f2) {
printf("Can't open file %s for reading!\n", filename);
exit(-1);
}
orig_length = length = fileSize(f2);
while (length > 0) {
size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : length, f2);
if (size <= 0)
break;
length -= size;
fwrite(fbuf, 1, size, f1);
}
fclose(f2);
return orig_length;
}
#define GetCompressedShift(n) ((n) >> 4)
#define GetCompressedSign(n) (((n) >> 3) & 1)
#define GetCompressedAmplitude(n) ((n) & 7)
int main(int argc, char *argv[]) {
char output_filename[40];
FILE *output, *f;
char *ptr;
int i, j;
uint32 indexSize;
uint32 totalSize;
uint32 length;
if (argc < 2)
showhelp(argv[0]);
i = 1;
if (strcmp(argv[1], "--mp3") == 0) {
gCompMode = kMP3Mode;
i++;
}
else if (strcmp(argv[1], "--vorbis") == 0) {
gCompMode = kVorbisMode;
i++;
} else if (strcmp(argv[1], "--flac") == 0) {
gCompMode = kFlacMode;
i++;
}
switch (gCompMode) {
case kMP3Mode:
tempEncoded = TEMP_MP3;
process_mp3_parms(argc, argv, i);
break;
case kVorbisMode:
tempEncoded = TEMP_OGG;
process_ogg_parms(argc, argv, i);
break;
case kFlacMode:
tempEncoded = TEMP_FLAC;
process_flac_parms(argc, argv, i);
break;
}
i = argc - 1;
input = fopen(argv[i], "rb");
if (!input) {
printf("Cannot open file: %s\n", argv[i]);
return EXIT_FAILURE;
}
indexSize = readUint32LE(input);
totalSize = 12 * (indexSize + 1);
if (readUint32BE(input) != 0xfff0fff0) {
printf("This doesn't look like a cluster file\n");
return EXIT_FAILURE;
}
output_idx = fopen(TEMP_IDX, "wb");
if (!output_idx) {
printf("Can't open file " TEMP_IDX " for writing!\n");
return EXIT_FAILURE;
}
output_snd = fopen(TEMP_DAT, "wb");
if (!output_snd) {
printf("Can't open file " TEMP_DAT " for writing!\n");
return EXIT_FAILURE;
}
writeUint32LE(output_idx, indexSize);
writeUint32BE(output_idx, 0xfff0fff0);
writeUint32BE(output_idx, 0xfff0fff0);
for (j = strlen(argv[i]) - 1; j >= 0; j--) {
if (argv[i][j] == '/' || argv[i][j] == '\\' || argv[i][j] == ':') {
j++;
break;
}
}
if (j < 0)
j = 0;
strncpy(output_filename, argv[i] + j, sizeof(output_filename) - 1);
output_filename[sizeof(output_filename) - 1] = 0;
ptr = output_filename + strlen(output_filename) - 1;
switch (gCompMode) {
case kMP3Mode:
*ptr = '3';
break;
case kVorbisMode:
*ptr = 'g';
break;
case kFlacMode:
*ptr = 'f';
break;
}
for (i = 0; i < indexSize; i++) {
uint32 pos;
uint32 enc_length;
fseek(input, 8 * (i + 1), SEEK_SET);
pos = readUint32LE(input);
length = readUint32LE(input);
if (pos != 0 && length != 0) {
uint16 prev;
f = fopen(TEMP_WAV, "wb");
if (!f) {
printf("Can't open file %s for writing!\n", TEMP_WAV);
return EXIT_FAILURE;
}
/*
* Our encoding function assumes that raw data means
* 8-bit data. Rather than going through the trouble of
* adding support for 16-bit data at various byte
* orders, let's just prepend a simple WAV header.
*/
writeUint32BE(f, 0x52494646); /* "RIFF" */
writeUint32LE(f, 2 * length + 36);
writeUint32BE(f, 0x57415645); /* "WAVE" */
writeUint32BE(f, 0x666d7420); /* "fmt " */
writeUint32LE(f, 16);
writeUint16LE(f, 1); /* PCM */
writeUint16LE(f, 1); /* mono */
writeUint32LE(f, 22050); /* sample rate */
writeUint32LE(f, 44100); /* bytes per second */
writeUint16LE(f, 2); /* basic block size */
writeUint16LE(f, 16); /* sample width */
writeUint32BE(f, 0x64617461); /* "data" */
writeUint32LE(f, 2 * length);
fseek(input, pos, SEEK_SET);
/*
* The first sample is stored uncompressed. Subsequent
* samples are stored as some sort of 8-bit delta.
*/
prev = readUint16LE(input);
writeUint16LE(f, prev);
for (j = 1; j < length; j++) {
byte data;
uint16 out;
data = readByte(input);
if (GetCompressedSign(data))
out = prev - (GetCompressedAmplitude(data) << GetCompressedShift(data));
else
out = prev + (GetCompressedAmplitude(data) << GetCompressedShift(data));
writeUint16LE(f, out);
prev = out;
}
fclose(f);
encodeAudio(TEMP_WAV, false, -1, tempEncoded, gCompMode);
enc_length = append_to_file(output_snd, tempEncoded);
writeUint32LE(output_idx, totalSize);
writeUint32LE(output_idx, length);
writeUint32LE(output_idx, enc_length);
totalSize = totalSize + enc_length;
} else {
writeUint32LE(output_idx, 0);
writeUint32LE(output_idx, 0);
writeUint32LE(output_idx, 0);
}
}
fclose(output_idx);
fclose(output_snd);
output = fopen(output_filename, "wb");
if (!output) {
printf("Can't open file %s for writing!\n", output_filename);
return EXIT_FAILURE;
}
append_to_file(output, TEMP_IDX);
append_to_file(output, TEMP_DAT);
fclose(output);
unlink(TEMP_DAT);
unlink(TEMP_IDX);
unlink(TEMP_MP3);
unlink(TEMP_OGG);
unlink(TEMP_FLAC);
unlink(TEMP_WAV);
return EXIT_SUCCESS;
}
Index: Makefile
===================================================================
RCS file: /cvsroot/scummvm/tools/Makefile,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- Makefile 11 Jul 2004 04:56:58 -0000 1.34
+++ Makefile 23 Aug 2004 06:22:15 -0000 1.35
@@ -27,7 +27,8 @@
queenrebuild$(EXEEXT) \
rescumm$(EXEEXT) \
simon1decr$(EXEEXT) \
- simon2mp3$(EXEEXT)
+ simon2mp3$(EXEEXT) \
+ sword2mp3$(EXEEXT)
all: $(TARGETS)
@@ -67,9 +68,11 @@
simon2mp3$(EXEEXT): simon2mp3.o extract-common.o util.o
$(CC) $(LFLAGS) -o $@ $+
+sword2mp3$(EXEEXT): sword2mp3.o extract-common.o util.o
+ $(CC) $(LFLAGS) -o $@ $+
descumm.o descumm6.o descumm-common.o descumm-tool.o: descumm.h util.h
-extract.o simon2mp3.o extract-common.o: util.h extract.h
+extract.o simon2mp3.o sword2mp3.o extract-common.o: util.h extract.h
desword2.o md5table.o queenrebuild.o rescumm.o util.o: util.h
clean:
Index: Makefile.mingw
===================================================================
RCS file: /cvsroot/scummvm/tools/Makefile.mingw,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- Makefile.mingw 11 Jul 2004 04:56:58 -0000 1.16
+++ Makefile.mingw 23 Aug 2004 06:22:15 -0000 1.17
@@ -20,6 +20,7 @@
strip rescumm.exe -o $(SCUMMVMPATH)/tools/rescumm.exe
strip simon1decr.exe -o $(SCUMMVMPATH)/tools/simon1decr.exe
strip simon2mp3.exe -o $(SCUMMVMPATH)/tools/simon2mp3.exe
+ strip sword2mp3.exe -o $(SCUMMVMPATH)/tools/sword2mp3.exe
cp COPYING $(SCUMMVMPATH)/tools/copying.txt
cp README $(SCUMMVMPATH)/tools/readme.txt
u2d $(SCUMMVMPATH)/tools/*.txt
Index: README
===================================================================
RCS file: /cvsroot/scummvm/tools/README,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- README 26 Jul 2004 10:38:41 -0000 1.18
+++ README 23 Aug 2004 06:22:15 -0000 1.19
@@ -8,17 +8,17 @@
loom_tg16_extract:
Extracts data files from TG16 version of Loom
- There is currently no support for this game in ScummVM!
+ There is currently no support for this game in ScummVM!
mm_nes_extract
Extracts data files from NES version of Maniac Mansion
There is currently no support for this game in ScummVM!
Compression Tools:
- extract
- Used to compress .sou files to .so3 (MP3), .sog (Vorbis),
- or .sof (FLAC)
-
+ extract
+ Used to compress .sou files to .so3 (MP3), .sog (Vorbis),
+ or .sof (FLAC)
+
queenrebuild
Used to rebuild the datafile of Flight of the Amazon Queen,
to allow optional MP3/Ogg/FLAC compression.
@@ -26,41 +26,54 @@
simon2mp3
Compresses Simon voc/wav files to MP3/Ogg/FLAC.
+ sword2mp3
+ Used to compress Broken Sword 2's music and speech cluster
+ files to .cl3 (MP3), .clg (Vorbis) or .clf (FLAC).
+
+ Please note that FLAC is only supported for completeness and
+ consistency. The original sound files are already compressed
+ with a lossy method that achieves a 50% compression rate. FLAC
+ is lossless and generally has a worse compression rate than
+ that, which means that the compressed file is likely to be
+ larger than the original!
+
+ Also note that at the time of writing there is no playback
+ support for compressed music; only for compressed speech.
+
compress_san <inputfile>.san <outputfile>.san [<file>.flu>]
Compresses '.san' smush animation files. It uses lossless zlib
for compressing FOBJ gfx chunks inside a san file.
- Example of usage:
- compress_san opening.san temp_opening.san
+ Example of usage:
+ compress_san opening.san temp_opening.san
- 'san' filenames which have equivalent 'flu' filenames (which exist
- in the Full Throttle 'data' dir, ie 'tovista2.san' and 'tovista2.flu')
- must be compressed together, for example:
- compress_san tovista2.san temp_tovista2.san tovista2.flu
- WARNING: The current status of 'flu' support is not good,
- PLEASE DO NOT COMPRESS this pair of files yet, it will be fixed later.
+ 'san' filenames which have equivalent 'flu' filenames (which exist
+ in the Full Throttle 'data' dir, ie 'tovista2.san' and 'tovista2.flu')
+ must be compressed together, for example:
+ compress_san tovista2.san temp_tovista2.san tovista2.flu
+ WARNING: The current status of 'flu' support is not good,
+ PLEASE DO NOT COMPRESS this pair of files yet, it will be fixed later.
- The original 'tovista2.san' file is not modified and a new
- 'temp_tovista2.san' file is created, but the input file 'tovista2.flu'
- IS MODIFIED while compressing.
+ The original 'tovista2.san' file is not modified and a new
+ 'temp_tovista2.san' file is created, but the input file 'tovista2.flu'
+ IS MODIFIED while compressing.
- After compression, you must rename
- 'temp_tovista2.san' to 'tovista2.san'.
+ After compression, you must rename
+ 'temp_tovista2.san' to 'tovista2.san'.
- ScummVM support requires a zlib enabled build.
+ ScummVM support requires a zlib enabled build.
-Script Tools:
+Script Tools:
descumm
Decompiles SCUMM scripts
-
+
desword2
Disassembles Broken Sword II scripts
-
-
-Other tools:
- simon1decr
+
+Other tools:
+ simon1decr
Used to decrunch the graphics and music files in AGA/ECS
versions of Simon the Sorcerer 1 for Amiga
- convbdf
+ convbdf
Converts BDF (Bitmap Display Format) files to C++ source
Index: extract.h
===================================================================
RCS file: /cvsroot/scummvm/tools/extract.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- extract.h 10 Apr 2004 21:20:57 -0000 1.12
+++ extract.h 23 Aug 2004 06:22:15 -0000 1.13
@@ -55,9 +55,10 @@
extern void extractAndEncodeVOC(const char *outName, FILE *input, CompressMode compMode);
extern void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode);
+extern void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, bool OggOutput);
/*
- * Stuff which is in extract.c / simon2mp3.c
+ * Stuff which is in extract.c / simon2mp3.c / sword2mp3.c
*/
extern void showhelp(char *exename);
More information about the Scummvm-git-logs
mailing list