📄 parse.c
字号:
#include "util.h"#include "id3tag.h"#include "get_audio.h"#include "brhist.h"#include "version.h"/************************************************************************** license** PURPOSE: Writes version and license to the file specified by #stdout#*************************************************************************/void lame_print_license(lame_global_flags *gfp,char *name) /* print version,license & exit */{ LAME_PRINT_VERSION1(); PRINTF1("\n"); PRINTF1("Read the file \"LICENSE\"\n"); PRINTF1("\n"); LAME_NORMAL_EXIT();}/************************************************************************** usage** PURPOSE: Writes command line syntax to the file specified by #stderr#*************************************************************************/void lame_usage(lame_global_flags *gfp,char *name) /* print syntax & exit */{ LAME_PRINT_VERSION2(); PRINTF2("\n"); PRINTF2("USAGE : %s [options] <infile> [outfile]\n",name); PRINTF2("\n<infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n"); PRINTF2("\n"); PRINTF2("Try \"%s --help\" for more information\n",name); PRINTF2(" or \"%s --longhelp\" for a complete options list\n",name); LAME_ERROR_EXIT();}/************************************************************************** usage** PURPOSE: Writes command line syntax to the file specified by #stdout#* but only the most important ones, to fit on a vt100 terminal*************************************************************************/void lame_short_help(lame_global_flags *gfp,char *name) /* print syntax & exit */{ LAME_PRINT_VERSION1(); /* prints two lines */ PRINTF1("\n"); PRINTF1("USAGE : %s [options] <infile> [outfile]\n",name); PRINTF1("\n<infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n"); PRINTF1("\n"); PRINTF1("OPTIONS :\n"); PRINTF1(" -b bitrate set the bitrate, default 128kbps\n"); PRINTF1(" -f fast mode (lower quality)\n"); PRINTF1(" -h higher quality, but a little slower. Recommended.\n"); PRINTF1(" -k keep ALL frequencies (disables all filters)\n"); PRINTF1(" -m mode (s)tereo, (j)oint, (f)orce or (m)ono (default j)\n"); PRINTF1(" force = force ms_stereo on all frames.\n"); PRINTF1(" -V n quality setting for VBR. default n=%i\n",gfp->VBR_q); PRINTF1("\n"); PRINTF1(" --preset type type must be phone, voice, fm, tape, hifi, cd or studio\n"); PRINTF1(" \"--preset help\" gives some more infos on these\n"); PRINTF1("\n"); PRINTF1(" --longhelp full list of options\n"); PRINTF1("\n"); LAME_NORMAL_EXIT();}/************************************************************************** usage** PURPOSE: Writes command line syntax to the file specified by #stdout#*************************************************************************/void lame_help(lame_global_flags *gfp,char *name) /* print syntax & exit */{ LAME_PRINT_VERSION1(); PRINTF1("\n"); PRINTF1("USAGE : %s [options] <infile> [outfile]\n",name); PRINTF1("\n<infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n"); PRINTF1("\n"); PRINTF1("OPTIONS :\n"); PRINTF1(" Input options:\n"); PRINTF1(" -r input is raw pcm\n"); PRINTF1(" -x force byte-swapping of input\n"); PRINTF1(" -s sfreq sampling frequency of input file(kHz) - default 44.1kHz\n"); PRINTF1(" --mp3input input file is a MP3 file\n"); PRINTF1(" --ogginput input file is a Ogg Vorbis file\n"); PRINTF1("\n"); PRINTF1(" Operational options:\n"); PRINTF1(" -m <mode> (s)tereo, (j)oint, (f)orce or (m)ono (default j)\n"); PRINTF1(" force = force ms_stereo on all frames.\n"); PRINTF1(" -a downmix from stereo to mono file for mono encoding\n"); PRINTF1(" -d allow channels to have different blocktypes\n"); PRINTF1(" -S don't print progress report, VBR histograms\n"); PRINTF1(" --ogg encode to Ogg Vorbis instead of MP3\n"); PRINTF1(" --freeformat produce a free format bitstream\n"); PRINTF1(" --decode input=mp3 file, output=raw pcm\n"); PRINTF1(" --comp <arg> choose bitrate to achive a compression ratio of <arg>\n"); PRINTF1(" --athonly only use the ATH for masking\n"); PRINTF1(" --noath disable the ATH for masking\n"); PRINTF1(" --noshort do not use short blocks\n"); PRINTF1(" --voice experimental voice mode\n"); PRINTF1(" --preset type type must be phone, voice, fm, tape, hifi, cd or studio\n"); PRINTF1(" \"--preset help\" gives some more infos on these\n"); PRINTF1("\n"); PRINTF1(" CBR (constant bitrate, the default) options:\n"); PRINTF1(" -h higher quality, but a little slower. Recommended.\n"); PRINTF1(" -f fast mode (very low quality)\n"); PRINTF1(" -b <bitrate> set the bitrate in kbs, default 128kbps\n"); PRINTF1("\n"); PRINTF1(" VBR options:\n"); PRINTF1(" -v use variable bitrate (VBR)\n"); PRINTF1(" --vbr-old use old variable bitrate (VBR) routine\n"); PRINTF1(" --vbr-new use new variable bitrate (VBR) routine\n"); PRINTF1(" -V n quality setting for VBR. default n=%i\n",gfp->VBR_q); PRINTF1(" 0=high quality,bigger files. 9=smaller files\n"); PRINTF1(" -b <bitrate> specify minimum allowed bitrate, default 32kbs\n"); PRINTF1(" -B <bitrate> specify maximum allowed bitrate, default 256kbs\n"); PRINTF1(" -F strictly enforce the -b option, for use with players that\n"); PRINTF1(" do not support low bitrate mp3 (Apex AD600-A DVD/mp3 player)\n"); PRINTF1(" -t disable Xing VBR informational tag\n"); PRINTF1(" --nohist disable VBR histogram display\n"); PRINTF1("\n"); PRINTF1(" --abr <bitrate> specify average bitrate desired (instead of quality)\n"); PRINTF1("\n"); PRINTF1(" MP3 header/stream options:\n"); PRINTF1(" -e <emp> de-emphasis n/5/c (obsolete)\n"); PRINTF1(" -c mark as copyright\n"); PRINTF1(" -o mark as non-original\n"); PRINTF1(" -p error protection. adds 16bit checksum to every frame\n"); PRINTF1(" (the checksum is computed correctly)\n"); PRINTF1(" --nores disable the bit reservoir\n"); PRINTF1(" --strictly-enforce-ISO comply as much as possible to ISO MPEG spec\n"); PRINTF1("\n"); PRINTF1(" Filter options:\n"); PRINTF1(" -k keep ALL frequencies (disables all filters)\n"); PRINTF1(" --lowpass <freq> frequency(kHz), lowpass filter cutoff above freq\n"); PRINTF1(" --lowpass-width <freq> frequency(kHz) - default 15%% of lowpass freq\n"); PRINTF1(" --highpass <freq> frequency(kHz), highpass filter cutoff below freq\n"); PRINTF1(" --highpass-width <freq> frequency(kHz) - default 15%% of highpass freq\n"); PRINTF1(" --resample <sfreq> sampling frequency of output file(kHz)- default=automatic\n"); PRINTF1(" --cwlimit <freq> compute tonality up to freq (in kHz) default 8.8717\n"); PRINTF1("\n"); PRINTF1(" Specifying any of the following options will add an ID3 tag:\n"); PRINTF1(" --tt \"title\" title of song (max 30 chars)\n"); PRINTF1(" --ta \"artist\" artist who did the song (max 30 chars)\n"); PRINTF1(" --tl \"album\" album where it came from (max 30 chars)\n"); PRINTF1(" --ty \"year\" year in which the song/album was made (max 4 chars)\n"); PRINTF1(" --tc \"comment\" additional info (max 30 chars)\n"); PRINTF1(" (or max 28 chars if using the \"track\" option)\n"); PRINTF1(" --tn \"track\" track number of the song on the CD (1 to 99)\n"); PRINTF1(" (using this option will add an ID3v1.1 tag)\n"); PRINTF1(" --tg \"genre\" genre of song (name or number)\n"); PRINTF1("\n");#ifdef HAVEGTK PRINTF1(" -g run graphical analysis on <infile>\n");#endif DISPLAY_BITRATES1(); LAME_NORMAL_EXIT();}/************************************************************************** usage** PURPOSE: Writes presetting info to #stdout#*************************************************************************/void lame_presets_info(lame_global_flags *gfp,char *name) /* print syntax & exit */{ LAME_PRINT_VERSION1(); PRINTF1("\n"); PRINTF1("Presets are some shortcuts for common settings.\n"); PRINTF1("They can be combined with -v if you want VBR MP3s.\n"); PRINTF1("\n"); PRINTF1(" phone sw am fm voice radio tape hifi cd studio\n"); PRINTF1("=============================================================================\n"); PRINTF1("--resample 8.0 11.025 16.0 22.05 32.0 \n"); PRINTF1("--lowpass 3.2 4.800 7.2 9.95 12.3 15.0 18.5 20.24 \n"); PRINTF1("--lowpass-width 1.0 0.500 0.5 0.88 2.0 0.0 2.0 2.20 \n"); PRINTF1("--noshort yes yes \n"); PRINTF1("-h yes yes yes \n"); PRINTF1("-m m m m j m j j j s s \n"); PRINTF1("-b 16 24 32 64 56 112 128 160 192 256 \n"); PRINTF1("-- PLUS WITH -v -------------------------------------------------------------\n"); PRINTF1("-V 6 5 5 5 4 4 4 3 2 0 \n"); PRINTF1("-b 8 8 16 24 32 64 96 112 128 160 \n"); PRINTF1("-B 56 64 128 160 128 256 320 320 320 320 \n"); PRINTF1("\n"); PRINTF1("EXAMPLES:\n"); PRINTF1(" a) --preset fm\n"); PRINTF1(" equals: --resample 22.05 --lowpass 9.95 --lowpass-width 0.88 -mj -b 64\n"); PRINTF1(" b) -v --preset studio\n"); PRINTF1(" equals: -h -m s -V 0 -b 160 -B 320\n"); PRINTF1("\n"); LAME_NORMAL_EXIT();}/************************************************************************** parse_args** PURPOSE: Sets encoding parameters to the specifications of the* command line. Default settings are used for parameters* not specified in the command line.** If the input file is in WAVE or AIFF format, the sampling frequency is read* from the AIFF header.** The input and output filenames are read into #inpath# and #outpath#.*************************************************************************/void lame_parse_args(lame_global_flags *gfp,int argc, char **argv){ FLOAT srate; int err = 0, i = 0; int autoconvert=0; int user_quality=0; char *programName = argv[0]; int track = 0; gfp->inPath[0] = '\0'; gfp->outPath[0] = '\0'; /* turn on display options. user settings may turn them off below */ gfp->silent=0; gfp->brhist_disp = 1; id3_inittag(&gfp->id3tag); /* process args */ while(++i<argc && err == 0) { char c, *token, *arg, *nextArg; int argUsed; token = argv[i]; if(*token++ == '-') { if(i+1 < argc) nextArg = argv[i+1]; else nextArg = ""; argUsed = 0; if (! *token) { /* The user wants to use stdin and/or stdout. */ if(gfp->inPath[0] == '\0') strncpy(gfp->inPath, argv[i],MAX_NAME_SIZE); else if(gfp->outPath[0] == '\0') strncpy(gfp->outPath, argv[i],MAX_NAME_SIZE); } if (*token == '-') { /* GNU style */ token++; if (strcmp(token, "resample")==0) { argUsed=1; srate = atof( nextArg ); /* samplerate = rint( 1000.0 * srate ); $A */ gfp->out_samplerate = (( 1000.0 * srate ) + 0.5); if (srate < 1) { ERRORF("Must specify a samplerate with --resample\n"); LAME_ERROR_EXIT(); } } else if (strcmp(token, "vbr-old")==0) { gfp->VBR = vbr_rh; gfp->quality = 2; } else if (strcmp(token, "vbr-new")==0) { gfp->VBR = vbr_mt; gfp->quality = 2; } else if (strcmp(token, "abr")==0) { argUsed=1; gfp->VBR = vbr_abr; gfp->VBR_mean_bitrate_kbps = atoi(nextArg); gfp->VBR_mean_bitrate_kbps = Min(gfp->VBR_mean_bitrate_kbps,310); gfp->VBR_mean_bitrate_kbps = Max(gfp->VBR_mean_bitrate_kbps,4); } else if (strcmp(token, "mp3input")==0) { gfp->input_format=sf_mp3; } else if (strcmp(token, "ogginput")==0) {#ifdef HAVEVORBIS gfp->input_format=sf_ogg;#else ERRORF("Error: LAME not compiled with Vorbis support\n"); LAME_ERROR_EXIT();#endif } else if (strcmp(token, "ogg")==0) {#ifdef HAVEVORBIS gfp->ogg=1;#else ERRORF("Error: LAME not compiled with Vorbis support\n"); LAME_ERROR_EXIT();#endif } else if (strcmp(token, "voice")==0) { gfp->lowpassfreq=12000; gfp->VBR_max_bitrate_kbps=160; gfp->no_short_blocks=1; } else if (strcmp(token, "noshort")==0) { gfp->no_short_blocks=1; } else if (strcmp(token, "decode")==0) { gfp->decode_only=1; } else if (strcmp(token, "noath")==0) { gfp->noATH=1; } else if (strcmp(token, "nores")==0) { gfp->disable_reservoir=1; gfp->padding_type=0; } else if (strcmp(token, "strictly-enforce-ISO")==0) { gfp->strict_ISO=1; } else if (strcmp(token, "athonly")==0) { gfp->ATHonly=1; } else if (strcmp(token, "freeformat")==0) { gfp->free_format=1; } else if (strcmp(token, "athshort")==0) { gfp->ATHshort=1; } else if (strcmp(token, "nohist")==0) { gfp->brhist_disp = 0; } /* options for ID3 tag */ else if (strcmp(token, "tt")==0) { gfp->id3tag_used=1; argUsed = 1; strncpy(gfp->id3tag.title, nextArg, 30); } else if (strcmp(token, "ta")==0) { gfp->id3tag_used=1; argUsed = 1; strncpy(gfp->id3tag.artist, nextArg, 30); } else if (strcmp(token, "tl")==0) { gfp->id3tag_used=1; argUsed = 1; strncpy(gfp->id3tag.album, nextArg, 30); } else if (strcmp(token, "ty")==0) { gfp->id3tag_used=1; argUsed = 1; strncpy(gfp->id3tag.year, nextArg, 4); } else if (strcmp(token, "tc")==0) { gfp->id3tag_used=1; argUsed = 1; strncpy(gfp->id3tag.comment, nextArg, 30); } else if (strcmp(token, "tn")==0) { gfp->id3tag_used=1; argUsed = 1; track = atoi(nextArg); if (track < 1) { track = 1; } if (track > 99) { track = 99; } gfp->id3tag.track = track; } else if (strcmp(token, "tg")==0) { argUsed = strtol (nextArg, &token, 10); if (nextArg==token) { /* Genere was given as a string, so it's number*/ for (argUsed=0; argUsed<=genre_last; argUsed++) { if (!strcmp (genre_list[argUsed], nextArg)) { break; } } } if (argUsed>genre_last) { argUsed=255; ERRORF("Unknown genre: %s. Specifiy genre number \n", nextArg); } argUsed &= 255; c=(char)(argUsed); gfp->id3tag_used=1; argUsed = 1; strncpy(gfp->id3tag.genre, &c, 1); } else if (strcmp(token, "lowpass")==0) { argUsed=1; gfp->lowpassfreq = (( 1000.0 * atof( nextArg ) ) + 0.5); if (gfp->lowpassfreq < 1) { ERRORF("Must specify lowpass with --lowpass freq, freq >= 0.001 kHz\n"); LAME_ERROR_EXIT(); } } else if (strcmp(token, "lowpass-width")==0) { argUsed=1; gfp->lowpasswidth = (( 1000.0 * atof( nextArg ) ) + 0.5); if (gfp->lowpasswidth < 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -