[Scummvm-cvs-logs] CVS: tools simon2mp3.c,1.8,1.9

Oliver Kiehl olki at users.sourceforge.net
Thu Mar 6 05:52:05 CET 2003


Update of /cvsroot/scummvm/tools
In directory sc8-pr-cvs1:/tmp/cvs-serv22488

Modified Files:
	simon2mp3.c 
Log Message:
added support for simon2mac


Index: simon2mp3.c
===================================================================
RCS file: /cvsroot/scummvm/tools/simon2mp3.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- simon2mp3.c	24 Feb 2003 14:06:48 -0000	1.8
+++ simon2mp3.c	6 Mar 2003 13:51:13 -0000	1.9
@@ -41,6 +41,7 @@
 
 FILE *input, *output_idx, *output_snd;
 
+unsigned int filenums[32768];
 unsigned int offsets[32768];
 
 char infile_base[256];
@@ -116,7 +117,7 @@
 	buf[i] = '\0';
 }
 
-unsigned int get_int(void)
+unsigned int get_int32LE(void)
 {
 	int i;
 	unsigned int ret = 0;
@@ -128,6 +129,30 @@
 	return ret;
 }
 
+unsigned int get_int32BE(void)
+{
+	int i;
+	unsigned int ret = 0;
+	unsigned int c;
+	for (i = 3; i >= 0; i--) {
+		c = fgetc(input);
+		ret |= c << i*8;
+	}
+	return ret;
+}
+
+unsigned int get_int16BE(void)
+{
+	int i;
+	unsigned int ret = 0;
+	unsigned int c;
+	for (i = 1; i >= 0; i--) {
+		c = fgetc(input);
+		ret |= c << i*8;
+	}
+	return ret;
+}
+
 void put_int(unsigned int val)
 {
 	int i;
@@ -147,10 +172,24 @@
 		}
 		fseek(input, -8, SEEK_CUR);
 
-		offsets[i] = get_int();
+		offsets[i] = get_int32LE();
 	}
 }
 
+int get_offsets_mac(void)
+{
+	int i, end;
+	fseek(input, 0, SEEK_END);
+	end = ftell(input);
+	fseek(input, 0, SEEK_SET);
+
+	for (i = 1; i <= end / 6; i++) {
+		filenums[i] = get_int16BE();
+		offsets[i] = get_int32BE();
+	}
+	return(end/6);
+}
+
 void get_voc(void);
 void get_wav(void);
 
@@ -197,7 +236,7 @@
 	char mp3name[256];
 
 	fseek(input, -4, SEEK_CUR);
-	length = get_int();
+	length = get_int32LE();
 	length += 8;
 	fseek(input, -8, SEEK_CUR);
 
@@ -366,7 +405,7 @@
 
 void showhelp(char *exename)
 {
-	printf("\nUsage: %s <params> file\n", 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 (not yet implemented)\n");
@@ -388,6 +427,7 @@
 	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");
 	exit(2);
 }
 
@@ -480,35 +520,59 @@
 		showhelp(argv[0]);
 }
 
-int main(int argc, char *argv[])
+void convert_pc(char *infile)
 {
 	int i, n, size, num;
-	
-	if (argc < 2)
-		showhelp(argv[0]);
-	i = 1;
-	if (strcmp(argv[1], "--mp3") == 0) {
-		oggmode = 0;
-		i++;
+
+	n = strlen(infile);
+	strncpy(infile_base, infile, n - 3);
+
+	input = fopen(infile, "rb");
+	if (!input) {
+		printf("Cannot open file: %s\n", infile);
+		exit(-1);
 	}
-	else if (strcmp(argv[1], "--vorbis") == 0) {
-		oggmode = 1;
-		i++;
+
+	sprintf(tmp, "%sidx", infile_base);
+	output_idx = fopen(tmp, "wb");
+
+	sprintf(tmp, "%sdat", infile_base);
+	output_snd = fopen(tmp, "wb");
+
+	num = get_offsets();
+
+	fclose(input);
+
+	if (!num) {
+		printf("This does not seem to be a valid file\n");
+		exit(-1);
 	}
+	size = num*4;
 
-	if (oggmode)
-		process_ogg_parms(argc, argv, i);
-	else
-		process_mp3_parms(argc, argv, i);
+	put_int(0);
+	put_int(size);
 
-	i = argc - 1;
+	for (i = 1; i < num; i++) {
+		if (offsets[i] == offsets[i+1]) {
+			put_int(size);
+			continue;
+		}
 
-	n = strlen(argv[i]);
-	strncpy(infile_base, argv[i], n - 3);
+		size += get_sound(i);
+		if (i < num - 1)
+			put_int(size);
+	}
+}
 
-	input = fopen(argv[i], "rb");
+void convert_mac(void)
+{
+	int i, size, num;
+
+	sprintf(infile_base, "simon2.");
+
+	input = fopen("voices.idx", "rb");
 	if (!input) {
-		printf("Cannot open file: %s\n", argv[i]);
+		printf("Cannot open file: %s\n", "voices.idx");
 		exit(-1);
 	}
 
@@ -518,7 +582,7 @@
 	sprintf(tmp, "%sdat", infile_base);
 	output_snd = fopen(tmp, "wb");
 
-	num = get_offsets();
+	num = get_offsets_mac();
 
 	if (!num) {
 		printf("This does not seem to be a valid file\n");
@@ -530,17 +594,55 @@
 	put_int(size);
 
 	for (i = 1; i < num; i++) {
-		if (offsets[i] == offsets[i+1]) {
+		if (filenums[i] == filenums[i+1] && offsets[i] == offsets[i+1]) {
 			put_int(size);
 			continue;
 		}
 
+		if (filenums[i] != filenums[i-1]) {
+			sprintf(tmp, "voices%d.dat", filenums[i]);
+			if (input)
+				fclose(input);
+			input = fopen(tmp, "rb"); 
+		}
+
 		size += get_sound(i);
 		if (i < num - 1)
 			put_int(size);
 	}
+}
+
+int main(int argc, char *argv[])
+{
+	int i;
+	
+	if (argc < 2)
+		showhelp(argv[0]);
+	i = 1;
+	if (strcmp(argv[1], "--mp3") == 0) {
+		oggmode = 0;
+		i++;
+	}
+	else if (strcmp(argv[1], "--vorbis") == 0) {
+		oggmode = 1;
+		i++;
+	}
+
+	if (oggmode)
+		process_ogg_parms(argc, argv, i);
+	else
+		process_mp3_parms(argc, argv, i);
+
+	i = argc - 1;
+
+	if (strcmp(argv[i], "mac") == 0) {
+		convert_mac();
+	} else {
+		convert_pc(argv[i]);
+	}
 
 	end();
 
 	return(0);
 }
+





More information about the Scummvm-git-logs mailing list