Ticket #8110: extract.diff
File extract.diff, 6.9 KB (added by , 22 years ago) |
---|
-
extract.c
? extract.diff RCS file: /cvsroot/scummvm/tools/extract.c,v retrieving revision 1.13 diff -u -r1.13 extract.c
15 15 #define algqualDef 2 16 16 #define vbrqualDef 4 17 17 18 /* The default for oggenc invocation is to use the --quality option only */ 19 #define oggqualDef 3 20 18 21 FILE *input, *output_idx, *output_snd; 19 22 20 23 char fbuf_temp[1024]; … … 42 45 unsigned int vbrqual; 43 46 unsigned int silent; 44 47 } encparms = { minBitrDef, maxBitrDef, abrDef, vbrDef, algqualDef, vbrqualDef, 0 }; 45 48 49 struct oggencparams { 50 int nominalBitr; 51 int minBitr; 52 int maxBitr; 53 int quality; 54 int silent; 55 } oggparms = { -1, -1, -1, oggqualDef, 0 }; 56 57 int oggmode = 0; 58 46 59 void put_int(unsigned int val); 47 60 48 61 void end_of_file(void) … … 55 68 fclose(output_snd); 56 69 fclose(output_idx); 57 70 58 output_idx = fopen( "monster.so3", "wb");71 output_idx = fopen(oggmode ? "monster.sog" : "monster.so3", "wb"); 59 72 put_int(idx_size); 60 73 61 74 in = fopen("monster.idx", "rb"); … … 63 76 fwrite(buf, 1, size, output_idx); 64 77 } 65 78 fclose(in); 66 in = fopen("monster. mp3", "rb");79 in = fopen("monster.dat", "rb"); 67 80 while ((size = fread(buf, 1, 2048, in)) > 0) { 68 81 fwrite(buf, 1, size, output_idx); 69 82 } … … 73 86 74 87 /* And some clean-up :-) */ 75 88 unlink("monster.idx"); 76 unlink("monster. mp3");89 unlink("monster.dat"); 77 90 unlink("tempfile.raw"); 78 unlink( "tempfile.mp3");91 unlink(oggmode ? "tempfile.ogg" : "tempfile.mp3"); 79 92 80 93 exit(-1); 81 94 } … … 197 210 exit(-1); 198 211 } 199 212 sprintf(rawname, "tempfile.raw"); 200 sprintf(mp3name, "tempfile.mp3");213 sprintf(mp3name, oggmode ? "tempfile.ogg" : "tempfile.mp3"); 201 214 202 215 f = fopen(rawname, "wb"); 203 216 length -= 2; … … 213 226 fwrite(fbuf_o, 1, 2 * size, f); 214 227 } 215 228 fclose(f); 216 217 if (encparms.abr == 1) 218 sprintf(fbuf_temp,"--abr %i",encparms.minBitr); 219 else 220 sprintf(fbuf_temp,"--vbr-new -b %i",encparms.minBitr); 221 if (encparms.silent == 1) 222 strcat(fbuf_temp," --silent"); 223 sprintf(fbuf, 224 "lame -t -q %i %s -V %i -B %i --resample 22.05 -m m -r -s %d %s %s", 225 encparms.algqual, fbuf_temp, encparms.vbrqual, 226 encparms.maxBitr, real_samplerate, rawname, mp3name); 227 system(fbuf); 229 230 if (oggmode) { 231 sprintf(fbuf, "oggenc "); 232 if (oggparms.nominalBitr != -1) { 233 sprintf(fbuf_temp, "-b %i ", oggparms.nominalBitr); 234 strcat(fbuf, fbuf_temp); 235 } 236 if (oggparms.minBitr != -1) { 237 sprintf(fbuf_temp, "-m %i ", oggparms.minBitr); 238 strcat(fbuf, fbuf_temp); 239 } 240 if (oggparms.maxBitr != -1) { 241 sprintf(fbuf_temp, "-M %i ", oggparms.maxBitr); 242 strcat(fbuf, fbuf_temp); 243 } 244 if (oggparms.silent) { 245 strcat(fbuf, "--quiet "); 246 } 247 sprintf(fbuf_temp, "-q %i -r -C 1 --raw-endianness=1 -R %i --resample 22050 %s -o %s", 248 oggparms.quality, real_samplerate, 249 rawname, mp3name); 250 strcat(fbuf, fbuf_temp); 251 system(fbuf); 252 } 253 else { 254 if (encparms.abr == 1) 255 sprintf(fbuf_temp,"--abr %i",encparms.minBitr); 256 else 257 sprintf(fbuf_temp,"--vbr-new -b %i",encparms.minBitr); 258 if (encparms.silent == 1) 259 strcat(fbuf_temp," --silent"); 260 sprintf(fbuf, 261 "lame -t -q %i %s -V %i -B %i --resample 22.05 -m m -r -s %d %s %s", 262 encparms.algqual, fbuf_temp, encparms.vbrqual, 263 encparms.maxBitr, real_samplerate, rawname, mp3name); 264 system(fbuf); 265 } 228 266 229 267 f = fopen(mp3name, "rb"); 230 268 tot_size = 0; … … 247 285 { 248 286 printf("\nUsage: %s <params> monster.sou\n", exename); 249 287 printf("\nParams:\n"); 288 printf("--mp3 encode to MP3 format (default)\n"); 289 printf("--vorbis encode to Vorbis format\n"); 290 printf("(If one of these is specified, it must be the first parameter.)\n"); 291 printf("\nMP3 mode params:\n"); 250 292 printf("-b <rate> <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:%i)\n", minBitrDef); 251 293 printf("-B <rate> <rate> is the maximum VBR/ABR bitrate (default:%i)\n", maxBitrDef); 252 294 printf("--vbr LAME uses the VBR mode (default)\n"); … … 254 296 printf("-V <value> specifies the value (0 - 9) of VBR quality (0=best) (default:%i)\n", vbrqualDef); 255 297 printf("-q <value> specifies the MPEG algorithm quality (0-9; 0=best) (default:%i)\n", algqualDef); 256 298 printf("--silent the output of LAME is hidden (default:disabled)\n"); 257 printf("--help this help message\n"); 299 printf("\nVorbis mode params:\n"); 300 printf("-b <rate> <rate> is the nominal bitrate (default:unset)\n"); 301 printf("-m <rate> <rate> is the minimum bitrate (default:unset)\n"); 302 printf("-M <rate> <rate> is the maximum bitrate (default:unset)\n"); 303 printf("-q <value> specifies the value (0 - 10) of VBR quality (10=best) (default:%i)\n", oggqualDef); 304 printf("--silent the output of oggenc is hidden (default:disabled)\n"); 305 printf("\n--help this help message\n"); 258 306 printf("\n\nIf a parameter is not given the default value is used\n"); 259 printf("If using VBR mode -b and -B must be multiples of 8; the maximum is 160!\n");307 printf("If using VBR mode for MP3 -b and -B must be multiples of 8; the maximum is 160!\n"); 260 308 exit(2); 261 309 } 262 310 263 int main(int argc, char *argv[]) 264 { 265 int i; 266 if (argc < 2) 267 showhelp(argv[0]); 268 for(i = 1; i < argc; i++) { 311 void process_mp3_parms(int argc, char *argv[], int i) { 312 for(; i < argc; i++) { 269 313 if (strcmp(argv[i], "--vbr") == 0) { 270 314 encparms.vbr=1; 271 315 encparms.abr=0; … … 317 361 if (i != (argc - 1)) { 318 362 showhelp(argv[0]); 319 363 } 364 } 365 366 void process_ogg_parms(int argc, char *argv[], int i) { 367 for (; i < argc; i++) { 368 if (strcmp(argv[i], "-b") == 0) { 369 oggparms.nominalBitr = atoi(argv[i + 1]); 370 i++; 371 } 372 else if (strcmp(argv[i], "-m") == 0) { 373 oggparms.minBitr = atoi(argv[i + 1]); 374 i++; 375 } 376 else if (strcmp(argv[i], "-M") == 0) { 377 oggparms.maxBitr = atoi(argv[i + 1]); 378 i++; 379 } 380 else if (strcmp(argv[i], "-q") == 0) { 381 oggparms.quality = atoi(argv[i + 1]); 382 i++; 383 } 384 else if (strcmp(argv[i], "--silent") == 0) { 385 oggparms.silent = 1; 386 } 387 else if (strcmp(argv[i], "--help") == 0) { 388 showhelp(argv[0]); 389 } 390 else if (argv[i][0] == '-') { 391 showhelp(argv[0]); 392 } 393 else 394 break; 395 } 396 if (i != argc - 1) 397 showhelp(argv[0]); 398 } 399 400 int main(int argc, char *argv[]) 401 { 402 int i; 403 if (argc < 2) 404 showhelp(argv[0]); 405 i = 1; 406 if (strcmp(argv[1], "--mp3") == 0) { 407 oggmode = 0; 408 i++; 409 } 410 else if (strcmp(argv[1], "--vorbis") == 0) { 411 oggmode = 1; 412 i++; 413 } 414 415 if (oggmode) 416 process_ogg_parms(argc, argv, i); 417 else 418 process_mp3_parms(argc, argv, i); 419 420 i = argc - 1; 320 421 input = fopen(argv[i], "rb"); 321 422 if (!input) { 322 423 printf("Cannot open file: %s\n", argv[i]); … … 324 425 } 325 426 326 427 output_idx = fopen("monster.idx", "wb"); 327 output_snd = fopen("monster. mp3", "wb");428 output_snd = fopen("monster.dat", "wb"); 328 429 329 430 /* Get the 'SOU ....' header */ 330 431 get_string(8);