📄 parse.c
字号:
do { c1 = tolower(*s1); c2 = tolower(*s2); if (!c1) { break; } ++s1; ++s2; } while (c1 == c2); return c1 - c2;}/* LAME is a simple frontend which just uses the file extension *//* to determine the file type. Trying to analyze the file *//* contents is well beyond the scope of LAME and should not be added. */static int filename_to_type ( const char* FileName ){ int len = strlen (FileName); if ( len < 4 ) return sf_unknown; FileName += len-4; if ( 0 == local_strcasecmp ( FileName, ".mpg" ) ) return sf_mp1; if ( 0 == local_strcasecmp ( FileName, ".mp1" ) ) return sf_mp1; if ( 0 == local_strcasecmp ( FileName, ".mp2" ) ) return sf_mp2; if ( 0 == local_strcasecmp ( FileName, ".mp3" ) ) return sf_mp3; if ( 0 == local_strcasecmp ( FileName, ".wav" ) ) return sf_wave; if ( 0 == local_strcasecmp ( FileName, ".aif" ) ) return sf_aiff; if ( 0 == local_strcasecmp ( FileName, ".raw" ) ) return sf_raw; return sf_unknown;}static int resample_rate ( double freq ){ if (freq >= 1.e3) freq *= 1.e-3; switch ( (int)freq ) { case 8: return 8000; case 11: return 11025; case 12: return 12000; case 16: return 16000; case 22: return 22050; case 24: return 24000; case 32: return 32000; case 44: return 44100; case 48: return 48000; default: fprintf(stderr,"Illegal resample frequency: %.3f kHz\n", freq ); return 0; }}/* Ugly, NOT final version */#define T_IF(str) if ( 0 == local_strcasecmp (token,str) ) {#define T_ELIF(str) } else if ( 0 == local_strcasecmp (token,str) ) {#define T_ELIF_INTERNAL(str) } else if (INTERNAL_OPTS && (0 == local_strcasecmp (token,str)) ) {#define T_ELIF2(str1,str2) } else if ( 0 == local_strcasecmp (token,str1) || 0 == local_strcasecmp (token,str2) ) {#define T_ELSE } else {#define T_END }int parse_args ( lame_global_flags* gfp, int argc, char** argv, char* const inPath, char* const outPath, char **nogap_inPath, int *num_nogap){ int err; int input_file=0; /* set to 1 if we parse an input file name */ int i; int autoconvert = 0; double val; int nogap=0; int nogap_tags=0; /* set to 1 to use VBR tags in NOGAP mode */ const char* ProgramName = argv[0]; int count_nogap=0; int noreplaygain=0; /* is RG explicitly disabled by the user */ inPath [0] = '\0'; outPath[0] = '\0'; /* turn on display options. user settings may turn them off below */ silent = 0; ignore_tag_errors = 0; brhist = 1; enc_padding=-1; enc_delay=-1; mp3_delay = 0; mp3_delay_set=0; print_clipping_info = 0; disable_wav_header=0; id3tag_init (gfp); /* process args */ for ( i = 0, err = 0; ++i < argc && !err; ) { char c; char* token; char* arg; char* nextArg; int argUsed; token = argv[i]; if ( *token++ == '-' ) { argUsed = 0; nextArg = i+1 < argc ? argv[i+1] : ""; if (! *token) { /* The user wants to use stdin and/or stdout. */ input_file = 1; if (inPath [0] == '\0') strncpy (inPath, argv[i], PATH_MAX + 1); else if (outPath[0] == '\0') strncpy (outPath, argv[i], PATH_MAX + 1); } if (*token == '-') { /* GNU style */ token++; T_IF ("resample") argUsed = 1; (void) lame_set_out_samplerate( gfp, resample_rate ( atof (nextArg) ) ); T_ELIF ("vbr-old") lame_set_VBR(gfp,vbr_rh); T_ELIF ("vbr-new") lame_set_VBR(gfp,vbr_mtrh); T_ELIF ("vbr-mtrh") lame_set_VBR(gfp,vbr_mtrh); T_ELIF ("cbr") lame_set_VBR(gfp,vbr_off); T_ELIF ("abr") argUsed=1; lame_set_VBR(gfp,vbr_abr); lame_set_VBR_mean_bitrate_kbps(gfp,atoi(nextArg)); /* values larger than 8000 are bps (like Fraunhofer), so it's strange to get 320000 bps MP3 when specifying 8000 bps MP3 */ if ( lame_get_VBR_mean_bitrate_kbps(gfp) >= 8000 ) lame_set_VBR_mean_bitrate_kbps(gfp,( lame_get_VBR_mean_bitrate_kbps(gfp) + 500 ) / 1000); lame_set_VBR_mean_bitrate_kbps(gfp,Min(lame_get_VBR_mean_bitrate_kbps(gfp), 320)); lame_set_VBR_mean_bitrate_kbps(gfp,Max(lame_get_VBR_mean_bitrate_kbps(gfp),8)); T_ELIF ("r3mix") lame_set_preset(gfp, R3MIX); T_ELIF ("bitwidth") argUsed=1; in_bitwidth=atoi(nextArg); T_ELIF ("signed") in_signed=1; T_ELIF ("unsigned") in_signed=0; T_ELIF ("little-endian") in_endian=order_littleEndian; T_ELIF ("big-endian") in_endian=order_bigEndian; T_ELIF ("mp1input") input_format=sf_mp1; T_ELIF ("mp2input") input_format=sf_mp2; T_ELIF ("mp3input") input_format=sf_mp3; T_ELIF ("ogginput") fprintf(stderr, "sorry, vorbis support in LAME is deprecated.\n"); return -1; T_ELIF ("phone") if (presets_set( gfp, 0, 0, token, ProgramName ) < 0) return -1; fprintf(stderr, "Warning: --phone is deprecated, use --preset phone instead!"); T_ELIF ("voice") if (presets_set( gfp, 0, 0, token, ProgramName ) < 0) return -1; fprintf(stderr, "Warning: --voice is deprecated, use --preset voice instead!"); T_ELIF ("radio") if (presets_set( gfp, 0, 0, token, ProgramName ) < 0) return -1; fprintf(stderr, "Warning: --radio is deprecated, use --preset radio instead!"); T_ELIF ("tape") if (presets_set( gfp, 0, 0, token, ProgramName ) < 0) return -1; fprintf(stderr, "Warning: --tape is deprecated, use --preset tape instead!"); T_ELIF ("cd") if (presets_set( gfp, 0, 0, token, ProgramName ) < 0) return -1; fprintf(stderr, "Warning: --cd is deprecated, use --preset cd instead!"); T_ELIF ("studio") if (presets_set( gfp, 0, 0, token, ProgramName ) < 0) return -1; fprintf(stderr, "Warning: --studio is deprecated, use --preset studio instead!"); T_ELIF ("noshort") (void) lame_set_no_short_blocks( gfp, 1 ); T_ELIF ("short") (void) lame_set_no_short_blocks( gfp, 0 ); T_ELIF ("allshort") (void) lame_set_force_short_blocks( gfp, 1 ); T_ELIF ("decode") (void) lame_set_decode_only( gfp, 1 ); T_ELIF ("decode-mp3delay") mp3_delay = atoi( nextArg ); mp3_delay_set=1; argUsed=1; T_ELIF ("nores") lame_set_disable_reservoir(gfp,1); T_ELIF ("strictly-enforce-ISO") lame_set_strict_ISO(gfp,1); T_ELIF ("scale") argUsed=1; (void) lame_set_scale( gfp, atof(nextArg) ); T_ELIF ("scale-l") argUsed=1; (void) lame_set_scale_left( gfp, atof(nextArg) ); T_ELIF ("scale-r") argUsed=1; (void) lame_set_scale_right( gfp, atof(nextArg) ); T_ELIF ("noasm") argUsed=1; if (!strcmp(nextArg, "mmx")) (void) lame_set_asm_optimizations( gfp, MMX, 0 ); if (!strcmp(nextArg, "3dnow")) (void) lame_set_asm_optimizations( gfp, AMD_3DNOW, 0 ); if (!strcmp(nextArg, "sse")) (void) lame_set_asm_optimizations( gfp, SSE, 0 ); T_ELIF ("freeformat") lame_set_free_format(gfp,1); T_ELIF ("replaygain-fast") lame_set_findReplayGain(gfp,1); #ifdef DECODE_ON_THE_FLY T_ELIF ("replaygain-accurate") lame_set_decode_on_the_fly(gfp,1); lame_set_findReplayGain(gfp,1);#endif T_ELIF ("noreplaygain") noreplaygain = 1; lame_set_findReplayGain(gfp,0); #ifdef DECODE_ON_THE_FLY T_ELIF ("clipdetect") print_clipping_info = 1; lame_set_decode_on_the_fly(gfp,1);#endif T_ELIF ("nohist") brhist = 0; #if defined(__OS2__) || defined(WIN32) T_ELIF ("priority") char *endptr; int priority = (int)strtol(nextArg, &endptr, 10); if (endptr != nextArg) { argUsed=1; }# if defined(__OS2__) setOS2Priority(gfp, priority);# else /* WIN32 */ setWin32Priority(gfp, priority);# endif#endif /* options for ID3 tag */ T_ELIF ("tt") argUsed=1; id3tag_set_title(gfp, nextArg); T_ELIF ("ta") argUsed=1; id3tag_set_artist(gfp, nextArg); T_ELIF ("tl") argUsed=1; id3tag_set_album(gfp, nextArg); T_ELIF ("ty") argUsed=1; id3tag_set_year(gfp, nextArg); T_ELIF ("tc") argUsed=1; id3tag_set_comment(gfp, nextArg); T_ELIF ("tn") argUsed=1; if( 0 == ignore_tag_errors ) { if (nextArg && *nextArg) { int num = atoi(nextArg); if ( num < 0 || num > 255 ) { if( silent < 10 ) { fprintf(stderr, "The track number has to be between 0 and 255.\n"); } return -1; } } } id3tag_set_track(gfp, nextArg); T_ELIF ("tg") argUsed=1; if ( id3tag_set_genre(gfp, nextArg) ) { if ( ignore_tag_errors ) { if( silent < 10 ) { fprintf(stderr, "Unknown genre: '%s'. Setting to 'Other'\n", nextArg); } id3tag_set_genre(gfp, "other"); } else { fprintf(stderr, "Unknown genre: '%s'. Specify genre name or number\n", nextArg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -