📄 parse.c
字号:
#ifdef LAMEPARSE
#include "util.h"
#include "id3tag.h"
#include "get_audio.h"
#include "brhist.h"
#include "version.h"
#define MAX_NAME_SIZE 300
char inPath[MAX_NAME_SIZE];
char outPath[MAX_NAME_SIZE];
/************************************************************************
*
* 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_version(stderr);
fprintf(stderr,"\n");
fprintf(stderr,"USAGE : %s [options] <infile> [outfile]\n",name);
fprintf(stderr,"\n<infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n");
fprintf(stderr,"\n");
fprintf(stderr,"Try \"%s --help\" for more information\n",name);
exit(1);
}
/************************************************************************
*
* 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_version(stdout);
fprintf(stdout,"\n");
fprintf(stdout,"USAGE : %s [options] <infile> [outfile]\n",name);
fprintf(stdout,"\n<infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n");
fprintf(stdout,"\n");
fprintf(stdout,"OPTIONS :\n");
fprintf(stdout," Input options:\n");
fprintf(stdout," -r input is raw pcm\n");
fprintf(stdout," -x force byte-swapping of input\n");
fprintf(stdout," -s sfreq sampling frequency of input file(kHz) - default 44.1kHz\n");
fprintf(stdout," --mp3input input file is a MP3 file\n");
fprintf(stdout,"\n");
fprintf(stdout," Filter options:\n");
fprintf(stdout," -k keep ALL frequencies (disables all filters)\n");
fprintf(stdout," --lowpass freq frequency(kHz), lowpass filter cutoff above freq\n");
fprintf(stdout," --lowpass-width freq frequency(kHz) - default 15%% of lowpass freq\n");
fprintf(stdout," --highpass freq frequency(kHz), highpass filter cutoff below freq\n");
fprintf(stdout," --highpass-width freq frequency(kHz) - default 15%% of highpass freq\n");
fprintf(stdout," --resample sfreq sampling frequency of output file(kHz)- default=input sfreq\n");
fprintf(stdout," --cwlimit freq compute tonality up to freq (in kHz) default 8.8717\n");
fprintf(stdout,"\n");
fprintf(stdout," Operational options:\n");
fprintf(stdout," -m mode (s)tereo, (j)oint, (f)orce or (m)ono (default j)\n");
fprintf(stdout," force = force ms_stereo on all frames. Faster\n");
fprintf(stdout," -a downmix from stereo to mono file for mono encoding\n");
fprintf(stdout," -d allow channels to have different blocktypes\n");
fprintf(stdout," -S don't print progress report, VBR histograms\n");
fprintf(stdout," --athonly only use the ATH for masking\n");
fprintf(stdout," --noath disable the ATH for masking\n");
fprintf(stdout," --noshort do not use short blocks\n");
fprintf(stdout," --voice experimental voice mode\n");
fprintf(stdout," --preset type type must be phone, voice, fm, tape, hifi, cd or studio\n");
fprintf(stdout," help gives some more infos on these\n");
fprintf(stdout,"\n");
fprintf(stdout," CBR (constant bitrate, the default) options:\n");
fprintf(stdout," -h higher quality, but a little slower. Recommended.\n");
fprintf(stdout," -f fast mode (very low quality)\n");
fprintf(stdout," -b bitrate set the bitrate, default 128kbps\n");
fprintf(stdout,"\n");
fprintf(stdout," VBR options:\n");
fprintf(stdout," -v use variable bitrate (VBR)\n");
fprintf(stdout," -V n quality setting for VBR. default n=%i\n",gfp->VBR_q);
fprintf(stdout," 0=high quality,bigger files. 9=smaller files\n");
fprintf(stdout," -b bitrate specify minimum allowed bitrate, default 32kbs\n");
fprintf(stdout," -B bitrate specify maximum allowed bitrate, default 256kbs\n");
fprintf(stdout," -t disable Xing VBR informational tag\n");
fprintf(stdout," --nohist disable VBR histogram display\n");
fprintf(stdout,"\n");
fprintf(stdout," MP3 header/stream options:\n");
fprintf(stdout," -e emp de-emphasis n/5/c (obsolete)\n");
fprintf(stdout," -c mark as copyright\n");
fprintf(stdout," -o mark as non-original\n");
fprintf(stdout," -p error protection. adds 16bit checksum to every frame\n");
fprintf(stdout," (the checksum is computed correctly)\n");
fprintf(stdout," --nores disable the bit reservoir\n");
fprintf(stdout,"\n");
fprintf(stdout," Specifying any of the following options will add an ID3 tag:\n");
fprintf(stdout," --tt \"title\" title of song (max 30 chars)\n");
fprintf(stdout," --ta \"artist\" artist who did the song (max 30 chars)\n");
fprintf(stdout," --tl \"album\" album where it came from (max 30 chars)\n");
fprintf(stdout," --ty \"year\" year in which the song/album was made (max 4 chars)\n");
fprintf(stdout," --tc \"comment\" additional info (max 30 chars)\n");
fprintf(stdout," (or max 28 chars if using the \"track\" option)\n");
fprintf(stdout," --tn \"track\" track number of the song on the CD (1 to 99)\n");
fprintf(stdout," (using this option will add an ID3v1.1 tag)\n");
fprintf(stdout," --tg \"genre\" genre of song (name or number)\n");
fprintf(stdout,"\n");
#ifdef HAVEGTK
fprintf(stdout," -g run graphical analysis on <infile>\n");
#endif
display_bitrates(stdout);
exit(0);
}
/************************************************************************
*
* usage
*
* PURPOSE: Writes presetting info to #stdout#
*
************************************************************************/
void lame_presets_info(lame_global_flags *gfp,char *name) /* print syntax & exit */
{
lame_print_version(stdout);
fprintf(stdout,"\n");
fprintf(stdout,"Presets are some shortcuts for common settings.\n");
fprintf(stdout,"They can be combined with -v if you want VBR MP3s.\n");
fprintf(stdout,"\n");
fprintf(stdout," --preset phone => --resample 16\n");
fprintf(stdout," --highpass 0.260\n");
fprintf(stdout," --highpasswidth 0.040\n");
fprintf(stdout," --lowpass 3.700\n");
fprintf(stdout," --lowpasswidth 0.300\n");
fprintf(stdout," --noshort\n");
fprintf(stdout," -m m\n");
fprintf(stdout," -b 16\n");
fprintf(stdout," plus -b 8 \\\n");
fprintf(stdout," -B 56 > in combination with -v\n");
fprintf(stdout," -V 5 /\n");
fprintf(stdout,"\n");
fprintf(stdout," --preset voice: => --resample 24\n");
fprintf(stdout," --highpass 0.100\n");
fprintf(stdout," --highpasswidth 0.020\n");
fprintf(stdout," --lowpass 11\n");
fprintf(stdout," --lowpasswidth 2\n");
fprintf(stdout," --noshort\n");
fprintf(stdout," -m m\n");
fprintf(stdout," -b 32\n");
fprintf(stdout," plus -b 8 \\\n");
fprintf(stdout," -B 96 > in combination with -v\n");
fprintf(stdout," -V 4 /\n");
fprintf(stdout,"\n");
fprintf(stdout," --preset fm: => --resample 32\n");
fprintf(stdout," --highpass 0.030\n");
fprintf(stdout," --highpasswidth 0\n");
fprintf(stdout," --lowpass 11.4\n");
fprintf(stdout," --lowpasswidth 0\n");
fprintf(stdout," -m j\n");
fprintf(stdout," -b 96\n");
fprintf(stdout," plus -b 32 \\\n");
fprintf(stdout," -B 192 > in combination with -v\n");
fprintf(stdout," -V 4 /\n");
fprintf(stdout,"\n");
fprintf(stdout," --preset tape: => --lowpass 17\n");
fprintf(stdout," --lowpasswidth 2\n");
fprintf(stdout," --highpass 0.015\n");
fprintf(stdout," --highpasswidth 0.015\n");
fprintf(stdout," -m j\n");
fprintf(stdout," -b 128\n");
fprintf(stdout," plus -b 32 \\\n");
fprintf(stdout," -B 192 > in combination with -v\n");
fprintf(stdout," -V 4 /\n");
fprintf(stdout,"\n");
fprintf(stdout," --preset hifi: => --lowpass 20\n");
fprintf(stdout," --lowpasswidth 3\n");
fprintf(stdout," --highpass 0.015\n");
fprintf(stdout," --highpasswidth 0.015\n");
fprintf(stdout," -h\n");
fprintf(stdout," -m j\n");
fprintf(stdout," -b 160\n");
fprintf(stdout," plus -b 32 \\\n");
fprintf(stdout," -B 224 > in combination with -v\n");
fprintf(stdout," -V 3 /\n");
fprintf(stdout,"\n");
fprintf(stdout," --preset cd: => -k\n");
fprintf(stdout," -h\n");
fprintf(stdout," -m s\n");
fprintf(stdout," -b 192\n");
fprintf(stdout," plus -b 80 \\\n");
fprintf(stdout," -B 256 > in combination with -v\n");
fprintf(stdout," -V 2 /\n");
fprintf(stdout,"\n");
fprintf(stdout," --preset studio: => -k\n");
fprintf(stdout," -h\n");
fprintf(stdout," -m s\n");
fprintf(stdout," -b 256\n");
fprintf(stdout," plus -b 112 \\\n");
fprintf(stdout," -B 320 > in combination with -v\n");
fprintf(stdout," -V 0 /\n");
fprintf(stdout,"\n");
exit(0);
}
/************************************************************************
*
* 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;
inPath[0] = '\0';
outPath[0] = '\0';
gfp->inPath=inPath;
gfp->outPath=outPath;
id3_inittag(&id3tag);
id3tag.used = 0;
/* 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(inPath[0] == '\0') strncpy(inPath, argv[i],MAX_NAME_SIZE);
else if(outPath[0] == '\0') strncpy(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) {
fprintf(stderr,"Must specify a samplerate with --resample\n");
exit(1);
}
}
else if (strcmp(token, "mp3input")==0) {
gfp->input_format=sf_mp3;
}
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, "noath")==0) {
gfp->noATH=1;
}
else if (strcmp(token, "nores")==0) {
gfp->disable_reservoir=1;
gfp->padding=0;
}
else if (strcmp(token, "athonly")==0) {
gfp->ATHonly=1;
}
else if (strcmp(token, "nohist")==0) {
#ifdef BRHIST
disp_brhist = 0;
#endif
}
/* options for ID3 tag */
else if (strcmp(token, "tt")==0) {
id3tag.used=1; argUsed = 1;
strncpy(id3tag.title, nextArg, 30);
}
else if (strcmp(token, "ta")==0) {
id3tag.used=1; argUsed = 1;
strncpy(id3tag.artist, nextArg, 30);
}
else if (strcmp(token, "tl")==0) {
id3tag.used=1; argUsed = 1;
strncpy(id3tag.album, nextArg, 30);
}
else if (strcmp(token, "ty")==0) {
id3tag.used=1; argUsed = 1;
strncpy(id3tag.year, nextArg, 4);
}
else if (strcmp(token, "tc")==0) {
id3tag.used=1; argUsed = 1;
strncpy(id3tag.comment, nextArg, 30);
}
else if (strcmp(token, "tn")==0) {
id3tag.used=1; argUsed = 1;
track = atoi(nextArg);
if (track < 1) { track = 1; }
if (track > 99) { track = 99; }
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;
fprintf(stderr,"Unknown genre: %s. Specifiy genre number \n", nextArg);
}
argUsed &= 255; c=(char)(argUsed);
id3tag.used=1; argUsed = 1;
strncpy(id3tag.genre, &c, 1);
}
else if (strcmp(token, "lowpass")==0) {
argUsed=1;
gfp->lowpassfreq = (( 1000.0 * atof( nextArg ) ) + 0.5);
if (gfp->lowpassfreq < 1) {
fprintf(stderr,"Must specify lowpass with --lowpass freq, freq >= 0.001 kHz\n");
exit(1);
}
}
else if (strcmp(token, "lowpass-width")==0) {
argUsed=1;
gfp->lowpasswidth = (( 1000.0 * atof( nextArg ) ) + 0.5);
if (gfp->lowpasswidth < 0) {
fprintf(stderr,"Must specify lowpass width with --lowpass-width freq, freq >= 0 kHz\n");
exit(1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -