[Scummvm-cvs-logs] CVS: tools extract-common.c,1.5,1.6 extract.c,1.37,1.38 extract.h,1.9,1.10 queenrebuild.c,1.9,1.10 simon2mp3.c,1.29,1.30

Max Horn fingolfin at users.sourceforge.net
Sun Feb 22 05:08:01 CET 2004


Update of /cvsroot/scummvm/tools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17855

Modified Files:
	extract-common.c extract.c extract.h queenrebuild.c 
	simon2mp3.c 
Log Message:
FLAC support (patch #885904 with some tweaks of mine)

Index: extract-common.c
===================================================================
RCS file: /cvsroot/scummvm/tools/extract-common.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- extract-common.c	9 Nov 2003 23:45:44 -0000	1.5
+++ extract-common.c	22 Feb 2004 12:54:27 -0000	1.6
@@ -27,7 +27,7 @@
 	bool abr;
 	uint32 algqual;
 	uint32 vbrqual;
-	uint32 silent;
+	bool silent;
 } lameparams;
 
 typedef struct {
@@ -35,16 +35,23 @@
 	int minBitr;
 	int maxBitr;
 	int quality;
-	int silent;
+	bool silent;
 } oggencparams;
 
+typedef struct {
+	char * const* argv;
+	int numArgs;
+} flaccparams;
 
 FILE *input, *output_idx, *output_snd;
 
 lameparams encparms = { minBitrDef, maxBitrDef, false, algqualDef, vbrqualDef, 0 };
 oggencparams oggparms = { -1, -1, -1, oggqualDef, 0 };
+flaccparams flacparms;
 
-bool oggmode = 0;
+CompressMode gCompMode = kMP3Mode;
+
+const char *tempEncoded = TEMP_MP3;
 
 
 int getSampleRateFromVOCRate(int vocSR) {
@@ -59,11 +66,14 @@
 	}
 }
 
-void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, bool oggOutput) {
+void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, CompressMode compmode) {
 	char fbuf[2048];
 	char *tmp = fbuf;
+	int i;
+	bool err = false;
 
-	if (oggOutput) {
+	switch (compmode) {
+	case kVorbisMode:
 		tmp += sprintf(tmp, "oggenc ");
 		if (rawInput) {
 			tmp += sprintf(tmp, "--raw --raw-chan=1 --raw-bits=8 ");
@@ -81,25 +91,54 @@
 		tmp += sprintf(tmp, "--quality=%i ", oggparms.quality);
 		tmp += sprintf(tmp, "--output=%s ", outname);
 		tmp += sprintf(tmp, "%s ", inname);
-		system(fbuf);
-	} else {
+		err = system(fbuf) != 0;
+		break;
+
+	case kMP3Mode:
 		tmp += sprintf(tmp, "lame -t -m m ");
 		if (rawInput) {
 			tmp += sprintf(tmp, "-r --bitwidth 8 ");
 			tmp += sprintf(tmp, "-s %d ", rawSamplerate);
 		}
 
-		if (encparms.abr == 1)
+		if (encparms.abr)
 			tmp += sprintf(tmp, "--abr %i ", encparms.minBitr);
 		else
 			tmp += sprintf(tmp, "--vbr-new -b %i ", encparms.minBitr);
-		if (encparms.silent == 1)
+		if (encparms.silent)
 			tmp += sprintf(tmp, " --silent ");
 		tmp += sprintf(tmp, "-q %i ", encparms.algqual);
 		tmp += sprintf(tmp, "-V %i ", encparms.vbrqual);
 		tmp += sprintf(tmp, "-B %i ", encparms.maxBitr);
 		tmp += sprintf(tmp, "%s %s ", inname, outname);
-		system(fbuf);
+		err = system(fbuf) != 0;
+		break;
+
+	case kFlacMode:
+		/* --lax is needed to allow 11kHz, we dont need place for meta-tags, and no seektable */
+		tmp += sprintf(tmp, "flac --lax --no-padding --no-seektable --no-ogg " );
+
+		if (rawInput) {
+			tmp += sprintf(tmp, "--force-raw-format --endian=little --sign=unsigned ");
+			tmp += sprintf(tmp, "--bps=8 --channels=1 --sample-rate=%d ", rawSamplerate );
+		}
+
+		for (i = 0; i < flacparms.numArgs; i++) {
+			/* Append optional encoder arguments */
+			tmp += sprintf(tmp, "%s ", flacparms.argv[i]);
+		}
+
+		tmp += sprintf(tmp, "-o %s ", outname);
+		tmp += sprintf(tmp, "%s ", inname);
+
+		err = system(fbuf) != 0;
+		break;
+	}
+
+	if (err) {
+		printf("Got error from encoder. (check your parameters)\n");
+		printf("Encoder Commandline: %s\n", fbuf );
+		exit(-1);
 	}
 } 
 
@@ -126,11 +165,10 @@
 	fclose(f);
 
 	/* Convert the WAV temp file to OGG/MP3 */
-	encodeAudio(TEMP_WAV, false, -1, oggmode ? TEMP_OGG : TEMP_MP3, oggmode);
+	encodeAudio(TEMP_WAV, false, -1, tempEncoded, gCompMode);
 }
 
-void get_voc(void)
-{
+void get_voc(void) {
 	int blocktype;
 
 	blocktype = fgetc(input);
@@ -179,7 +217,7 @@
 		fclose(f);
 
 		/* Convert the raw temp file to OGG/MP3 */
-		encodeAudio(TEMP_RAW, true, real_samplerate, oggmode ? TEMP_OGG : TEMP_MP3, oggmode);
+		encodeAudio(TEMP_RAW, true, real_samplerate, tempEncoded, gCompMode);
 		break;
 	}
 
@@ -190,7 +228,7 @@
 }
 
 void process_mp3_parms(int argc, char *argv[], int i) {
-	for(; i < argc; i++) {
+	for (; i < argc; i++) {
 		if (strcmp(argv[i], "--vbr") == 0) {
 			encparms.abr=0;
 		} else if (strcmp(argv[i], "--abr") == 0) {
@@ -276,3 +314,11 @@
 		showhelp(argv[0]);
 }
 
+void process_flac_parms(int argc, char *argv[], int i){
+	flacparms.argv = &argv[i];
+	flacparms.numArgs = argc - 1 - i;
+
+	if (i >= argc)
+		showhelp(argv[0]);
+}
+

Index: extract.c
===================================================================
RCS file: /cvsroot/scummvm/tools/extract.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- extract.c	24 Nov 2003 13:18:52 -0000	1.37
+++ extract.c	22 Feb 2004 12:54:27 -0000	1.38
@@ -37,11 +37,15 @@
 
 #define OUTPUT_MP3	"monster.so3"
 #define OUTPUT_OGG	"monster.sog"
+#define OUTPUT_FLAC	"monster.sof"
+
+const char *outputName = OUTPUT_MP3;
 
 #define TEMP_DAT	"tempfile.dat"
 #define TEMP_IDX	"tempfile.idx"
 
 
+
 void end_of_file(void)
 {
 	FILE *in;
@@ -52,7 +56,7 @@
 	fclose(output_snd);
 	fclose(output_idx);
 
-	output_idx = fopen(oggmode ? OUTPUT_OGG : OUTPUT_MP3, "wb");
+	output_idx = fopen(outputName , "wb");
 	writeUint32BE(output_idx, (uint32)idx_size);
 
 	in = fopen(TEMP_IDX, "rb");
@@ -72,7 +76,7 @@
 	unlink(TEMP_IDX);
 	unlink(TEMP_DAT);
 	unlink(TEMP_RAW);
-	unlink(oggmode ? TEMP_OGG : TEMP_MP3);
+	unlink(tempEncoded);
 	
 	exit(-1);
 }
@@ -134,7 +138,7 @@
 	get_voc();
 	
 	/* Append the converted data to the master output file */
-	sprintf(outname, oggmode ? TEMP_OGG : TEMP_MP3);
+	sprintf(outname, tempEncoded);
 	f = fopen(outname, "rb");
 	tot_size = 0;
 	while ((size = fread(fbuf, 1, 2048, f)) > 0) {
@@ -149,10 +153,13 @@
 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);
@@ -161,13 +168,20 @@
 	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);
@@ -179,20 +193,40 @@
 	int i;
 	if (argc < 2)
 		showhelp(argv[0]);
+	/* Compression mode */
+	gCompMode = kMP3Mode;
 	i = 1;
 	if (strcmp(argv[1], "--mp3") == 0) {
-		oggmode = 0;
+		gCompMode = kMP3Mode;
 		i++;
 	}
 	else if (strcmp(argv[1], "--vorbis") == 0) {
-		oggmode = 1;
+		gCompMode = kVorbisMode;
+		i++;
+	}
+	else if (strcmp(argv[1], "--flac") == 0) {
+		gCompMode = kFlacMode;
 		i++;
 	}
 
-	if (oggmode)
-		process_ogg_parms(argc, argv, i);
-	else
+	switch (gCompMode) {
+	case kMP3Mode:
+		outputName = OUTPUT_MP3;
+		tempEncoded = TEMP_MP3;
 		process_mp3_parms(argc, argv, i);
+		break;
+	case kVorbisMode:
+		outputName = OUTPUT_OGG;
+		tempEncoded = TEMP_OGG;
+		process_ogg_parms(argc, argv, i);
+		break;
+	case kFlacMode:
+		outputName = OUTPUT_FLAC;
+		tempEncoded = TEMP_FLAC;
+		process_flac_parms(argc, argv, i);
+		break;
+	}
+
 
 	i = argc - 1;
 	input = fopen(argv[i], "rb");
@@ -203,7 +237,7 @@
 
 	output_idx = fopen(TEMP_IDX, "wb");
 	if (!output_idx) {
-		printf("Can't open file " TEMP_IDX " for write!\n");
+		printf("Can't open file " TEMP_IDX " for write!\n" );
 		exit(-1);
 	}
 	output_snd = fopen(TEMP_DAT, "wb");

Index: extract.h
===================================================================
RCS file: /cvsroot/scummvm/tools/extract.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- extract.h	6 Jan 2004 12:44:02 -0000	1.9
+++ extract.h	22 Feb 2004 12:54:27 -0000	1.10
@@ -38,16 +38,23 @@
 #define TEMP_RAW	"tempfile.raw"
 #define TEMP_MP3	"tempfile.mp3"
 #define TEMP_OGG	"tempfile.ogg"
+#define TEMP_FLAC	"tempfile.fla"
+
+typedef enum { kMP3Mode, kVorbisMode, kFlacMode } CompressMode;
 
 /*
  * Stuff which is in extract-common.c
  */
 extern FILE *input, *output_idx, *output_snd;
 
-extern bool oggmode;
+const extern char *tempEncoded;
+
+extern CompressMode gCompMode;
+
 
 extern void process_mp3_parms(int argc, char *argv[], int i);
 extern void process_ogg_parms(int argc, char *argv[], int i);
+extern void process_flac_parms(int argc, char *argv[], int i);
 
 extern void get_voc(void);
 extern void get_wav(void);

Index: queenrebuild.c
===================================================================
RCS file: /cvsroot/scummvm/tools/queenrebuild.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- queenrebuild.c	11 Feb 2004 21:08:39 -0000	1.9
+++ queenrebuild.c	22 Feb 2004 12:54:27 -0000	1.10
@@ -29,8 +29,12 @@
 #define TEMP_DAT	"tempfile.dat"
 #define TEMP_TBL	"tempfile.tbl"
 #define TEMP_SB		"tempfile.sb"
+
 #define TEMP_MP3	"tempfile.mp3"
 #define TEMP_OGG	"tempfile.ogg"
+#define TEMP_FLAC	"tempfile.fla"
+
+const char *tempEncoded;
 
 #define CURRENT_TBL_VERSION	1
 #define EXTRA_TBL_HEADER 8
@@ -40,7 +44,8 @@
 enum {
 	COMPRESSION_NONE = 0,
 	COMPRESSION_MP3 = 1,
-	COMPRESSION_OGG = 2	
+	COMPRESSION_OGG = 2,
+	COMPRESSION_FLAC = 3
 };
 
 enum {
@@ -104,10 +109,11 @@
 
 void showhelp(char *exename)
 {
-	printf("\nUsage: %s [--mp3/--ogg <args>] queen.1\n", exename);
+	printf("\nUsage: %s [--mp3/--ogg/--flac <args>] queen.1\n", exename);
 	printf("\nParams:\n");
 	printf(" --mp3 <args>         encode to MP3 format\n"); 
 	printf(" --ogg <args>         encode to Ogg Vorbis Format\n");
+	printf(" --flac <args>        encode to Flac Format\n");
 	printf("                      (Optional: <args> are passed on to the encoder)\n");
 	printf("\nExample: %s --mp3 -q 5 queen.1\n", exename);
 	exit(2);
@@ -205,23 +211,39 @@
 	
 	if (strcmp(argv[1], "--mp3") == 0) {
 		compressionType = COMPRESSION_MP3;
+		tempEncoded = TEMP_MP3;
 		i++;
 		ptr += sprintf(ptr, "lame -r -h -s 11 --bitwidth 8 -m m ");
 		for (; i < (argc - 1); i++) {
 			/* Append optional encoder arguments */
 			ptr += sprintf(ptr, "%s ", argv[i]);
 		}
-		ptr += sprintf(ptr, "%s %s", TEMP_SB, TEMP_MP3);
+		ptr += sprintf(ptr, "%s %s", TEMP_SB, tempEncoded);
 	}
 
 	if (strcmp(argv[1], "--ogg") == 0) {
 		compressionType = COMPRESSION_OGG;
+		tempEncoded = TEMP_OGG;
 		i++;
-		ptr += sprintf(ptr, "oggenc -r -B 8 -C 1 -R 11025 %s -o %s ", TEMP_SB, TEMP_OGG);
+		ptr += sprintf(ptr, "oggenc -r -B 8 -C 1 -R 11025 %s -o %s ", TEMP_SB, tempEncoded);
+		for (; i < (argc - 1); i++) {
+			/* Append optional encoder arguments */
+			ptr += sprintf(ptr, "%s ", argv[i]);
+		}
+	}
+
+	if (strcmp(argv[1], "--flac") == 0) {
+		compressionType = COMPRESSION_FLAC;
+		tempEncoded = TEMP_FLAC;
+		i++;
+		ptr += sprintf(ptr, "flac --force-raw-format --endian=little --sign=unsigned --bps=8 --channels=1 --sample-rate=11025 " );
+		ptr += sprintf(ptr, "--no-padding --lax --no-seektable --no-ogg " );
 		for (; i < (argc - 1); i++) {
 			/* Append optional encoder arguments */
 			ptr += sprintf(ptr, "%s ", argv[i]);
 		}
+
+		ptr += sprintf(ptr, "-o %s %s", tempEncoded, TEMP_SB );
 	}
 
 	/* Open input file (QUEEN.1) */
@@ -289,14 +311,14 @@
 			}
 
 			/* Append MP3/OGG to data file */
-			compFile = fopen((compressionType == COMPRESSION_MP3) ? TEMP_MP3 : TEMP_OGG, "rb");
+			compFile = fopen(tempEncoded, "rb");
 			entry.size = fileSize(compFile);
 			fromFileToFile(compFile, outputData, entry.size);
 			fclose(compFile);
 
 			/* Delete temporary files */
 			unlink(TEMP_SB);
-			unlink((compressionType == COMPRESSION_MP3) ? TEMP_MP3 : TEMP_OGG);
+			unlink(tempEncoded);
 		} else {
 			/* Non .SB file */
 			fromFileToFile(inputData, outputData, entry.size);

Index: simon2mp3.c
===================================================================
RCS file: /cvsroot/scummvm/tools/simon2mp3.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- simon2mp3.c	17 Jan 2004 12:56:10 -0000	1.29
+++ simon2mp3.c	22 Feb 2004 12:54:27 -0000	1.30
@@ -28,12 +28,24 @@
 	int size;
 	char fbuf[2048];
 	char tmp[256];
+	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);
 
-	sprintf(tmp, "%s%s", infile_base, oggmode ? "ogg" : "mp3");
+	sprintf(tmp, "%s%s", infile_base, head);
 	output_idx = fopen(tmp, "wb");
 
 	sprintf(tmp, "%sidx", infile_base);
@@ -56,8 +68,8 @@
 	sprintf(tmp, "%sdat", infile_base);
 	unlink(tmp);
 	unlink(TEMP_RAW);
-	unlink(oggmode ? TEMP_OGG : TEMP_MP3);
-	unlink("tempfile.wav");
+	unlink(tempEncoded);
+	unlink(TEMP_WAV);
 	
 	exit(0);
 }
@@ -118,7 +130,7 @@
 	}
 
 	/* Append the converted data to the master output file */
-	sprintf(outname, oggmode ? TEMP_OGG : TEMP_MP3);
+	sprintf(outname, tempEncoded);
 	f = fopen(outname, "rb");
 	tot_size = 0;
 	while ((size = fread(fbuf, 1, 2048, f)) > 0) {
@@ -133,10 +145,14 @@
 void showhelp(char *exename)
 {
 	printf("\nUsage: %s <params> [<file> | mac]\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);
@@ -145,13 +161,20 @@
 	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 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");
 	printf("Use the `mac' option instead of a filename if converting simon2mac sounds\n");
@@ -272,20 +295,37 @@
 	
 	if (argc < 2)
 		showhelp(argv[0]);
+
+	/* compression mode */
+	gCompMode = kMP3Mode;
 	i = 1;
 	if (strcmp(argv[1], "--mp3") == 0) {
-		oggmode = 0;
+		gCompMode = kMP3Mode;
 		i++;
 	}
 	else if (strcmp(argv[1], "--vorbis") == 0) {
-		oggmode = 1;
+		gCompMode = kVorbisMode;
+		i++;
+	}
+	else if (strcmp(argv[1], "--flac") == 0) {
+		gCompMode = kFlacMode;
 		i++;
 	}
 
-	if (oggmode)
-		process_ogg_parms(argc, argv, i);
-	else
+	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;
 





More information about the Scummvm-git-logs mailing list