home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Sound / LAME / src / parse.c < prev    next >
C/C++ Source or Header  |  2000-08-06  |  29KB  |  863 lines

  1. #include "util.h"
  2. #include "id3tag.h"
  3. #include "get_audio.h"
  4. #include "brhist.h"
  5. #include "version.h"
  6.  
  7.  
  8.  
  9.  
  10. /************************************************************************
  11. *
  12. * license
  13. *
  14. * PURPOSE:  Writes version and license to the file specified by #stdout#
  15. *
  16. ************************************************************************/
  17.  
  18. void lame_print_license(lame_global_flags *gfp,char *name)  /* print version,license & exit */
  19. {
  20.   LAME_PRINT_VERSION1();
  21.   PRINTF1("\n");
  22.   PRINTF1("Read the file \"LICENSE\"\n");
  23.   PRINTF1("\n");
  24.   LAME_NORMAL_EXIT();
  25. }
  26.  
  27.  
  28.  
  29. /************************************************************************
  30. *
  31. * usage
  32. *
  33. * PURPOSE:  Writes command line syntax to the file specified by #stderr#
  34. *
  35. ************************************************************************/
  36.  
  37. void lame_usage(lame_global_flags *gfp,char *name)  /* print syntax & exit */
  38. {
  39.   LAME_PRINT_VERSION2();
  40.   PRINTF2("\n");
  41.   PRINTF2("USAGE   :  %s [options] <infile> [outfile]\n",name);
  42.   PRINTF2("\n<infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n");
  43.   PRINTF2("\n");
  44.   PRINTF2("Try \"%s --help\"     for more information\n",name);
  45.   PRINTF2(" or \"%s --longhelp\" for a complete options list\n",name);
  46.   LAME_ERROR_EXIT();
  47. }
  48.  
  49.  
  50.  
  51. /************************************************************************
  52. *
  53. * usage
  54. *
  55. * PURPOSE:  Writes command line syntax to the file specified by #stdout#
  56. *           but only the most important ones, to fit on a vt100 terminal
  57. *
  58. ************************************************************************/
  59.  
  60. void lame_short_help(lame_global_flags *gfp,char *name)  /* print syntax & exit */
  61. {
  62.   LAME_PRINT_VERSION1(); /* prints two lines */
  63.   PRINTF1("\n");
  64.   PRINTF1("USAGE       :  %s [options] <infile> [outfile]\n",name);
  65.   PRINTF1("\n<infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n");
  66.   PRINTF1("\n");
  67.   PRINTF1("RECOMMENDED :  ");
  68.   PRINTF1("lame -h input.mp3 output.wav\n");
  69.   PRINTF1("\n");
  70.   PRINTF1("OPTIONS :\n");
  71.   PRINTF1("    -b bitrate      set the bitrate, default 128kbps\n");
  72.   PRINTF1("    -f              fast mode (lower quality)\n");
  73.   PRINTF1("    -h              higher quality, but a little slower.  Recommended.\n");
  74.   PRINTF1("    -k              keep ALL frequencies (disables all filters)\n");
  75.   PRINTF1("                    Can cause ringing and twinkling\n");
  76.   PRINTF1("    -m mode         (s)tereo, (j)oint, (f)orce or (m)ono  (default j)\n");
  77.   PRINTF1("                    force = force ms_stereo on all frames.\n");
  78.   PRINTF1("    -V n            quality setting for VBR.  default n=%i\n",gfp->VBR_q);
  79.   PRINTF1("\n");
  80.   PRINTF1("    --preset type   type must be phone, voice, fm, tape, hifi, cd or studio\n");
  81.   PRINTF1("                    \"--preset help\" gives some more infos on these\n");
  82.   PRINTF1("\n");
  83.   PRINTF1("    --longhelp      full list of options\n");
  84.   PRINTF1("\n");
  85.  
  86.   LAME_NORMAL_EXIT();
  87. }
  88.  
  89. /************************************************************************
  90. *
  91. * usage
  92. *
  93. * PURPOSE:  Writes command line syntax to the file specified by #stdout#
  94. *
  95. ************************************************************************/
  96.  
  97. void lame_help(lame_global_flags *gfp,char *name)  /* print syntax & exit */
  98. {
  99.   LAME_PRINT_VERSION1();
  100.   PRINTF1("\n");
  101.   PRINTF1("USAGE   :  %s [options] <infile> [outfile]\n",name);
  102.   PRINTF1("\n<infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n");
  103.   PRINTF1("\n");
  104.   PRINTF1("RECOMMENDED :  ");
  105.   PRINTF1("lame -h input.mp3 output.wav\n");
  106.   PRINTF1("\n");
  107.   PRINTF1("OPTIONS :\n");
  108.   PRINTF1("  Input options:\n");
  109.   PRINTF1("    -r              input is raw pcm\n");
  110.   PRINTF1("    -x              force byte-swapping of input\n");
  111.   PRINTF1("    -s sfreq        sampling frequency of input file(kHz) - default 44.1kHz\n");
  112.   PRINTF1("    --mp3input      input file is a MP3 file\n");
  113.   PRINTF1("    --ogginput      input file is a Ogg Vorbis file\n");
  114.   PRINTF1("\n");
  115.   PRINTF1("  Operational options:\n");
  116.   PRINTF1("    -m <mode>       (s)tereo, (j)oint, (f)orce or (m)ono  (default j)\n");
  117.   PRINTF1("                    force = force ms_stereo on all frames.\n");
  118.   PRINTF1("    -a              downmix from stereo to mono file for mono encoding\n");
  119.   PRINTF1("    -d              allow channels to have different blocktypes\n");
  120.   PRINTF1("    -S              don't print progress report, VBR histograms\n");
  121.   PRINTF1("    --ogg           encode to Ogg Vorbis instead of MP3\n");
  122.   PRINTF1("    --freeformat    produce a free format bitstream\n");
  123.   PRINTF1("    --decode        input=mp3 file, output=wav\n");
  124.   PRINTF1("    -t              disable writing wav header when using --decode\n");
  125.   PRINTF1("    --comp  <arg>   choose bitrate to achive a compression ratio of <arg>\n");
  126.   PRINTF1("    --athonly       only use the ATH for masking\n");
  127.   PRINTF1("    --noath         disable the ATH for masking\n");
  128.   PRINTF1("    --noshort       do not use short blocks\n");
  129.   PRINTF1("    --voice         experimental voice mode\n");
  130.   PRINTF1("    --preset type   type must be phone, voice, fm, tape, hifi, cd or studio\n");
  131.   PRINTF1("                    \"--preset help\" gives some more infos on these\n");
  132.   PRINTF1("\n");
  133.   PRINTF1("  CBR (constant bitrate, the default) options:\n");
  134.   PRINTF1("    -h              higher quality, but a little slower.  Recommended.\n");
  135.   PRINTF1("    -f              fast mode (lower quality)\n");
  136.   PRINTF1("    -b <bitrate>    set the bitrate in kbs, default 128kbps\n");
  137.   PRINTF1("\n");
  138.   PRINTF1("  ABR options:\n");
  139.   PRINTF1("    --abr <bitrate> specify average bitrate desired (instead of quality)\n");
  140.   PRINTF1("\n");
  141.   PRINTF1("  VBR options:\n");
  142.   PRINTF1("    -v              use variable bitrate (VBR)\n");
  143.   PRINTF1("    --vbr-old       use old variable bitrate (VBR) routine\n");
  144.   PRINTF1("    --vbr-new       use new variable bitrate (VBR) routine\n");
  145.   PRINTF1("    -V n            quality setting for VBR.  default n=%i\n",gfp->VBR_q);
  146.   PRINTF1("                    0=high quality,bigger files. 9=smaller files\n");
  147.   PRINTF1("    -b <bitrate>    specify minimum allowed bitrate, default 32kbs\n");
  148.   PRINTF1("    -B <bitrate>    specify maximum allowed bitrate, default 256kbs\n");
  149.   PRINTF1("    -F              strictly enforce the -b option, for use with players that\n");
  150.   PRINTF1("                    do not support low bitrate mp3 (Apex AD600-A DVD/mp3 player)\n");
  151.   PRINTF1("    -t              disable writing Xing VBR informational tag\n");
  152.   PRINTF1("    --nohist        disable VBR histogram display\n");
  153.   PRINTF1("\n");
  154.   PRINTF1("  MP3 header/stream options:\n");
  155.   PRINTF1("    -e <emp>        de-emphasis n/5/c  (obsolete)\n");
  156.   PRINTF1("    -c              mark as copyright\n");
  157.   PRINTF1("    -o              mark as non-original\n");
  158.   PRINTF1("    -p              error protection.  adds 16bit checksum to every frame\n");
  159.   PRINTF1("                    (the checksum is computed correctly)\n");
  160.   PRINTF1("    --nores         disable the bit reservoir\n");
  161.   PRINTF1("    --strictly-enforce-ISO   comply as much as possible to ISO MPEG spec\n");
  162.   PRINTF1("\n");
  163.   PRINTF1("  Filter options:\n");
  164.   PRINTF1("    -k              keep ALL frequencies (disables all filters),\n");
  165.   PRINTF1("                    Can cause ringing and twinkling\n");
  166.   PRINTF1("  --lowpass <freq>        frequency(kHz), lowpass filter cutoff above freq\n");
  167.   PRINTF1("  --lowpass-width <freq>  frequency(kHz) - default 15%% of lowpass freq\n");
  168.   PRINTF1("  --highpass <freq>       frequency(kHz), highpass filter cutoff below freq\n");
  169.   PRINTF1("  --highpass-width <freq> frequency(kHz) - default 15%% of highpass freq\n");
  170.   PRINTF1("  --resample <sfreq>  sampling frequency of output file(kHz)- default=automatic\n");
  171.   PRINTF1("  --cwlimit <freq>    compute tonality up to freq (in kHz) default 8.8717\n");
  172.   PRINTF1("\n");
  173.   PRINTF1("  ID3 tag options:\n");
  174.   PRINTF1("    --tt <title>    audio/song title (max 30 chars for version 1 tag)\n");
  175.   PRINTF1("    --ta <artist>   audio/song artist (max 30 chars for version 1 tag)\n");
  176.   PRINTF1("    --tl <album>    audio/song album (max 30 chars for version 1 tag)\n");
  177.   PRINTF1("    --ty <year>     audio/song year of issue (1 to 9999)\n");
  178.   PRINTF1("    --tc <comment>  user-defined text (max 30 chars for v1 tag, 28 for v1.1)\n");
  179.   PRINTF1("    --tn <track>    audio/song track number (1 to 99, creates v1.1 tag)\n");
  180.   PRINTF1("    --tg <genre>    audio/song genre (name or number in list)\n");
  181.   PRINTF1("    --add-id3v2     force addition of version 2 tag\n");
  182.   PRINTF1("    --id3v1-only    add only a version 1 tag\n");
  183.   PRINTF1("    --id3v2-only    add only a version 2 tag\n");
  184.   PRINTF1("    --space-id3v1   pad version 1 tag with spaces instead of nulls\n");
  185.   PRINTF1("    --pad-id3v2     pad version 2 tag with extra 128 bytes\n");
  186.   PRINTF1("    --genre-list    print alphabetically sorted ID3 genre list and exit\n");
  187.   PRINTF1("\n");
  188.   PRINTF1("    Note: A version 2 tag will NOT be added unless one of the input fields\n");
  189.   PRINTF1("    won't fit in a version 1 tag (e.g. the title string is longer than 30\n");
  190.   PRINTF1("    characters), or the `--add-id3v2' or `--id3v2-only' options are used,\n");
  191.   PRINTF1("    or output is redirected to stdout.\n");
  192.   PRINTF1("\n");
  193. #ifdef HAVEVORBIS
  194.   PRINTF1("    Note: All `--t*' options (except those for track and genre) work for Ogg\n");
  195.   PRINTF1("    Vorbis output, but other ID3-specific options are ignored.\n");
  196.   PRINTF1("\n");
  197. #endif
  198. #ifdef HAVEGTK
  199.   PRINTF1("    -g              run graphical analysis on <infile>\n");
  200. #endif
  201.   DISPLAY_BITRATES1();
  202.   LAME_NORMAL_EXIT();
  203. }
  204.  
  205.  
  206.  
  207. /************************************************************************
  208. *
  209. * usage
  210. *
  211. * PURPOSE:  Writes presetting info to #stdout#
  212. *
  213. ************************************************************************/
  214.  
  215. void lame_presets_info(lame_global_flags *gfp,char *name)  /* print syntax & exit */
  216. {
  217.   LAME_PRINT_VERSION1();
  218.   PRINTF1("\n");
  219.   PRINTF1("Presets are some shortcuts for common settings.\n");
  220.   PRINTF1("They can be combined with -v if you want VBR MP3s.\n");
  221.   PRINTF1("\n");
  222.   PRINTF1("                 phone   sw     am    fm  voice radio  tape  hifi   cd studio\n");
  223.   PRINTF1("=============================================================================\n");
  224.   PRINTF1("--resample        8.0  11.025 16.0  22.05 32.0                               \n");
  225.   PRINTF1("--lowpass         3.2   4.800  7.2   9.95 12.3  15.0  18.5  20.24            \n");
  226.   PRINTF1("--lowpass-width   1.0   0.500  0.5   0.88  2.0   0.0   2.0   2.20            \n");
  227.   PRINTF1("--noshort         yes                      yes                               \n");
  228.   PRINTF1("-h                                                           yes   yes   yes \n");
  229.   PRINTF1("-m                  m     m      m     j     m     j     j     j     s     s \n");
  230.   PRINTF1("-b                 16    24     32    64    56   112   128   160   192   256 \n");
  231.   PRINTF1("-- PLUS WITH -v -------------------------------------------------------------\n");
  232.   PRINTF1("-V                  6     5      5     5     4     4     4     3     2     0 \n");
  233.   PRINTF1("-b                  8     8     16    24    32    64    96   112   128   160 \n");
  234.   PRINTF1("-B                 56    64    128   160   128   256   320   320   320   320 \n");
  235.   PRINTF1("\n");
  236.   PRINTF1("EXAMPLES:\n");
  237.   PRINTF1(" a) --preset fm\n");
  238.   PRINTF1("    equals: --resample 22.05 --lowpass 9.95 --lowpass-width 0.88 -mj -b 64\n");
  239.   PRINTF1(" b) -v --preset studio\n");
  240.   PRINTF1("    equals: -h -m s -V 0 -b 160 -B 320\n");
  241.   PRINTF1("\n");
  242.  
  243.   LAME_NORMAL_EXIT();
  244. }
  245.  
  246.  
  247.  
  248. static void genre_list_handler(int num,const char *name,void *cookie)
  249. {
  250.   PRINTF1("%3d %s\n",num,name);
  251. }
  252.  
  253.  
  254.  
  255. /************************************************************************
  256. *
  257. * parse_args
  258. *
  259. * PURPOSE:  Sets encoding parameters to the specifications of the
  260. * command line.  Default settings are used for parameters
  261. * not specified in the command line.
  262. *
  263. * If the input file is in WAVE or AIFF format, the sampling frequency is read
  264. * from the AIFF header.
  265. *
  266. * The input and output filenames are read into #inpath# and #outpath#.
  267. *
  268. ************************************************************************/
  269. void lame_parse_args(lame_global_flags *gfp,int argc, char **argv)
  270. {
  271.   FLOAT srate;
  272.   int   err = 0, i = 0;
  273.   int autoconvert=0;
  274.   int user_quality=-1;
  275.   char *programName = argv[0]; 
  276.  
  277.   gfp->inPath[0] = '\0';   
  278.   gfp->outPath[0] = '\0';
  279.   /* turn on display options. user settings may turn them off below */
  280.   gfp->silent=0;
  281.   gfp->brhist_disp = 1;
  282.   gfp->id3v1_enabled = 1;
  283.   id3tag_init(&gfp->tag_spec);
  284.  
  285.   /* process args */
  286.   while(++i<argc && err == 0) {
  287.     char c, *token, *arg, *nextArg;
  288.     int  argUsed;
  289.     
  290.     token = argv[i];
  291.     if(*token++ == '-') {
  292.       if(i+1 < argc) nextArg = argv[i+1];
  293.       else           nextArg = "";
  294.       argUsed = 0;
  295.       if (! *token) {
  296.     /* The user wants to use stdin and/or stdout. */
  297.     if(gfp->inPath[0] == '\0')       strncpy(gfp->inPath, argv[i],MAX_NAME_SIZE);
  298.     else if(gfp->outPath[0] == '\0') strncpy(gfp->outPath, argv[i],MAX_NAME_SIZE);
  299.       } 
  300.       if (*token == '-') {
  301.     /* GNU style */
  302.     token++;
  303.  
  304.     if (strcmp(token, "resample")==0) {
  305.       argUsed=1;
  306.       srate = atof( nextArg );
  307.       /* samplerate = rint( 1000.0 * srate ); $A  */
  308.       gfp->out_samplerate =  (( 1000.0 * srate ) + 0.5);
  309.       if (srate  < 1) {
  310.         ERRORF("Must specify a samplerate with --resample\n");
  311.         LAME_ERROR_EXIT();
  312.       }
  313.     }
  314.     else if (strcmp(token, "vbr-old")==0) {
  315.       gfp->VBR = vbr_rh; 
  316.       gfp->quality = 2;
  317.     }
  318.     else if (strcmp(token, "vbr-new")==0) {
  319.       gfp->VBR = vbr_mt; 
  320.       gfp->quality = 2;
  321.     }
  322.     else if (strcmp(token, "abr")==0) {
  323.       argUsed=1;
  324.       gfp->VBR = vbr_abr; 
  325.       gfp->VBR_mean_bitrate_kbps = atoi(nextArg);
  326.       gfp->VBR_mean_bitrate_kbps = Min(gfp->VBR_mean_bitrate_kbps,310); 
  327.       gfp->VBR_mean_bitrate_kbps = Max(gfp->VBR_mean_bitrate_kbps,4); 
  328.     }
  329.     else if (strcmp(token, "mp3input")==0) {
  330.       gfp->input_format=sf_mp3;
  331.     }
  332.     else if (strcmp(token, "ogginput")==0) {
  333. #ifdef HAVEVORBIS
  334.       gfp->input_format=sf_ogg;
  335. #else
  336.       ERRORF("Error: LAME not compiled with Vorbis support\n");
  337.       LAME_ERROR_EXIT();
  338. #endif
  339.     }
  340.     else if (strcmp(token, "ogg")==0) {
  341. #ifdef HAVEVORBIS
  342.       gfp->ogg=1;
  343. #else
  344.       ERRORF("Error: LAME not compiled with Vorbis support\n");
  345.       LAME_ERROR_EXIT();
  346. #endif
  347.  
  348.     }
  349.     else if (strcmp(token, "voice")==0) {
  350.       gfp->lowpassfreq=12000;
  351.       gfp->VBR_max_bitrate_kbps=160;
  352.       gfp->no_short_blocks=1;
  353.     }
  354.     else if (strcmp(token, "noshort")==0) {
  355.       gfp->no_short_blocks=1;
  356.     }
  357.     else if (strcmp(token, "decode")==0) {
  358.       gfp->decode_only=1;
  359.     }
  360.     else if (strcmp(token, "noath")==0) {
  361.       gfp->noATH=1;
  362.     }
  363.     else if (strcmp(token, "nores")==0) {
  364.       gfp->disable_reservoir=1;
  365.       gfp->padding_type=0;
  366.     }
  367.     else if (strcmp(token, "strictly-enforce-ISO")==0) {
  368.       gfp->strict_ISO=1;
  369.     }
  370.     else if (strcmp(token, "athonly")==0) {
  371.       gfp->ATHonly=1;
  372.     }
  373.     else if (strcmp(token, "athlower")==0) {
  374.       argUsed=1;
  375.       gfp->ATHlower = atoi(nextArg);
  376.     }
  377.     else if (strcmp(token, "freeformat")==0) {
  378.       gfp->free_format=1;
  379.     }
  380.     else if (strcmp(token, "athshort")==0) {
  381.       gfp->ATHshort=1;
  382.     }
  383.     else if (strcmp(token, "nohist")==0) {
  384.       gfp->brhist_disp = 0;
  385.     }
  386.     /* options for ID3 tag */
  387.      else if (strcmp(token, "tt")==0) {
  388.        argUsed=1;
  389.        id3tag_set_title(&gfp->tag_spec, nextArg);
  390.      }
  391.      else if (strcmp(token, "ta")==0) {
  392.        argUsed=1;
  393.        id3tag_set_artist(&gfp->tag_spec, nextArg);
  394.      }
  395.      else if (strcmp(token, "tl")==0) {
  396.        argUsed=1;
  397.        id3tag_set_album(&gfp->tag_spec, nextArg);
  398.      }
  399.      else if (strcmp(token, "ty")==0) {
  400.        argUsed=1;
  401.        id3tag_set_year(&gfp->tag_spec, nextArg);
  402.      }
  403.      else if (strcmp(token, "tc")==0) {
  404.        argUsed=1;
  405.        id3tag_set_comment(&gfp->tag_spec, nextArg);
  406.      }
  407.      else if (strcmp(token, "tn")==0) {
  408.        argUsed=1;
  409.        id3tag_set_track(&gfp->tag_spec, nextArg);
  410.      }
  411.      else if (strcmp(token, "tg")==0) {
  412.        argUsed=1;
  413.        if (id3tag_set_genre(&gfp->tag_spec, nextArg)) {
  414.         ERRORF("Unknown genre: %s.  Specify genre name or number\n", nextArg);
  415.         LAME_ERROR_EXIT();
  416.           }
  417.     }
  418.      else if (strcmp(token, "add-id3v2")==0) {
  419.        id3tag_add_v2(&gfp->tag_spec);
  420.      }
  421.      else if (strcmp(token, "id3v1-only")==0) {
  422.        id3tag_v1_only(&gfp->tag_spec);
  423.      }
  424.      else if (strcmp(token, "id3v2-only")==0) {
  425.        id3tag_v2_only(&gfp->tag_spec);
  426.      }
  427.      else if (strcmp(token, "space-id3v1")==0) {
  428.        id3tag_space_v1(&gfp->tag_spec);
  429.      }
  430.      else if (strcmp(token, "pad-id3v2")==0) {
  431.        id3tag_pad_v2(&gfp->tag_spec);
  432.      }
  433.      else if (strcmp(token, "genre-list")==0) {
  434.        id3tag_genre_list(genre_list_handler, NULL);
  435.       LAME_NORMAL_EXIT();
  436.      }
  437.     else if (strcmp(token, "lowpass")==0) {
  438.       argUsed=1;
  439.       gfp->lowpassfreq =  (( 1000.0 * atof( nextArg ) ) + 0.5);
  440.       if (gfp->lowpassfreq  < 1) {
  441.         ERRORF("Must specify lowpass with --lowpass freq, freq >= 0.001 kHz\n");
  442.         LAME_ERROR_EXIT();
  443.       }
  444.     }
  445.     else if (strcmp(token, "lowpass-width")==0) {
  446.       argUsed=1;
  447.       gfp->lowpasswidth =  (( 1000.0 * atof( nextArg ) ) + 0.5);
  448.       if (gfp->lowpasswidth  < 0) {
  449.         ERRORF("Must specify lowpass width with --lowpass-width freq, freq >= 0 kHz\n");
  450.         LAME_ERROR_EXIT();
  451.       }
  452.     }
  453.     else if (strcmp(token, "highpass")==0) {
  454.       argUsed=1;
  455.       gfp->highpassfreq =  (( 1000.0 * atof( nextArg ) ) + 0.5);
  456.       if (gfp->highpassfreq  < 1) {
  457.         ERRORF("Must specify highpass with --highpass freq, freq >= 0.001 kHz\n");
  458.         LAME_ERROR_EXIT();
  459.       }
  460.     }
  461.     else if (strcmp(token, "highpass-width")==0) {
  462.       argUsed=1;
  463.       gfp->highpasswidth =  (( 1000.0 * atof( nextArg ) ) + 0.5);
  464.       if (gfp->highpasswidth  < 0) {
  465.         ERRORF("Must specify highpass width with --highpass-width freq, freq >= 0 kHz\n");
  466.         LAME_ERROR_EXIT();
  467.       }
  468.     }
  469.     else if (strcmp(token, "cwlimit")==0) {
  470.       argUsed=1;
  471.       gfp->cwlimit =  atof( nextArg );
  472.       if (gfp->cwlimit <= 0 ) {
  473.         ERRORF("Must specify cwlimit in kHz\n");
  474.         LAME_ERROR_EXIT();
  475.       }
  476.     } 
  477.     else if (strcmp(token, "comp")==0) {
  478.       argUsed=1;
  479.       gfp->compression_ratio =  atof( nextArg );
  480.       if (gfp->compression_ratio < 1.0 ) {
  481.         ERRORF("Must specify compression ratio >= 1.0\n");
  482.         LAME_ERROR_EXIT();
  483.       }
  484.     }
  485.     else if (strcmp(token, "nspsytune")==0) {
  486.       gfp->exp_nspsytune = TRUE;
  487.       gfp->experimentalZ = TRUE;
  488.     }
  489.     /* some more GNU-ish options could be added
  490.        * version       => complete name, version and license info (normal exit)  
  491.        * quiet/silent  => no messages on screen
  492.        * brief         => few messages on screen (name, status report)
  493.        * verbose       => all infos to screen (brhist, internal flags/filters)
  494.        * o/output file => specifies output filename
  495.        * O             => stdout
  496.        * i/input file  => specifies input filename
  497.        * I             => stdin
  498.        */
  499.     else if (strcmp(token, "version") ==0
  500.            ||strcmp(token, "license")==0){
  501.       lame_print_license(gfp,programName);  /* doesn't return */
  502.     }
  503.     else if (strcmp(token, "help") ==0
  504.            ||strcmp(token, "usage")==0){
  505.       lame_short_help(gfp,programName);  /* doesn't return */
  506.     }
  507.     else if (strcmp(token, "longhelp") ==0){
  508.       lame_help(gfp,programName);  /* doesn't return */
  509.     }
  510.     else if (strcmp(token, "preset")==0) {
  511.       argUsed=1;
  512.       if (strcmp(nextArg,"phone")==0)
  513.       { /* when making changes, please update help text too */
  514.         gfp->out_samplerate =  8000;
  515.         gfp->lowpassfreq=3200;
  516.         gfp->lowpasswidth=1000;
  517.         gfp->no_short_blocks=1;
  518.         gfp->quality = 5;
  519.         gfp->mode = MPG_MD_MONO; 
  520.         gfp->mode_fixed = 1; 
  521.         gfp->brate = 16; 
  522.         gfp->VBR_q=6;
  523.         gfp->VBR_min_bitrate_kbps=8;
  524.         gfp->VBR_max_bitrate_kbps=56;
  525.       }
  526.       else if (strcmp(nextArg,"sw")==0)
  527.       { /* when making changes, please update help text too */
  528.         gfp->out_samplerate =  11025;
  529.         gfp->lowpassfreq=4800;
  530.         gfp->lowpasswidth=500;
  531.         gfp->quality = 5;
  532.         gfp->mode = MPG_MD_MONO; 
  533.         gfp->mode_fixed = 1; 
  534.         gfp->brate = 24; 
  535.         gfp->VBR_q=5;
  536.         gfp->VBR_min_bitrate_kbps=8;
  537.         gfp->VBR_max_bitrate_kbps=64;
  538.       }
  539.       else if (strcmp(nextArg,"am")==0)
  540.       { /* when making changes, please update help text too */
  541.         gfp->out_samplerate =  16000;
  542.         gfp->lowpassfreq=7200;
  543.         gfp->lowpasswidth=500;
  544.         gfp->quality = 5;
  545.         gfp->mode = MPG_MD_MONO; 
  546.         gfp->mode_fixed = 1; 
  547.         gfp->brate = 32; 
  548.         gfp->VBR_q=5;
  549.         gfp->VBR_min_bitrate_kbps=16;
  550.         gfp->VBR_max_bitrate_kbps=128;
  551.       }
  552.       else if (strcmp(nextArg,"fm")==0)
  553.       { /* when making changes, please update help text too */
  554.         gfp->out_samplerate =  22050; 
  555.             gfp->lowpassfreq=9950;
  556.             gfp->lowpasswidth=880;
  557.         gfp->quality = 5;
  558.         gfp->mode = MPG_MD_JOINT_STEREO; 
  559.         gfp->mode_fixed = 1; 
  560.         gfp->brate = 64; 
  561.         gfp->VBR_q=5;
  562.         gfp->VBR_min_bitrate_kbps=24;
  563.         gfp->VBR_max_bitrate_kbps=160;
  564.       }
  565.       else if (strcmp(nextArg,"voice")==0)
  566.       { /* when making changes, please update help text too */
  567.         gfp->out_samplerate =  32000; 
  568.         gfp->lowpassfreq=12300;
  569.         gfp->lowpasswidth=2000;
  570.         gfp->no_short_blocks=1;
  571.         gfp->quality = 5;
  572.         gfp->mode = MPG_MD_MONO; 
  573.         gfp->mode_fixed = 1; 
  574.         gfp->brate = 56; 
  575.         gfp->VBR_q=4;
  576.         gfp->VBR_min_bitrate_kbps=32;
  577.         gfp->VBR_max_bitrate_kbps=128;
  578.       }
  579.       else if (strcmp(nextArg,"radio")==0)
  580.       { /* when making changes, please update help text too */
  581.             gfp->lowpassfreq=15000;
  582.             gfp->lowpasswidth=0;
  583.         gfp->quality = 5;
  584.         gfp->mode = MPG_MD_JOINT_STEREO; 
  585.         gfp->mode_fixed = 1; 
  586.         gfp->brate = 112; 
  587.         gfp->VBR_q=4;
  588.         gfp->VBR_min_bitrate_kbps=64;
  589.         gfp->VBR_max_bitrate_kbps=256;
  590.       }
  591.       else if (strcmp(nextArg,"tape")==0)
  592.       { /* when making changes, please update help text too */
  593.             gfp->lowpassfreq=18500;
  594.             gfp->lowpasswidth=2000;
  595.         gfp->quality = 5;
  596.         gfp->mode = MPG_MD_JOINT_STEREO; 
  597.         gfp->mode_fixed = 1; 
  598.         gfp->brate = 128; 
  599.         gfp->VBR_q=4;
  600.         gfp->VBR_min_bitrate_kbps=96;
  601.         gfp->VBR_max_bitrate_kbps=320;
  602.       }
  603.       else if (strcmp(nextArg,"hifi")==0)
  604.       { /* when making changes, please update help text too */
  605.             gfp->lowpassfreq=20240;
  606.             gfp->lowpasswidth=2200;
  607.         gfp->quality = 2;
  608.         gfp->mode = MPG_MD_JOINT_STEREO; 
  609.         gfp->mode_fixed = 1; 
  610.         gfp->brate = 160;            
  611.         gfp->VBR_q=3;
  612.         gfp->VBR_min_bitrate_kbps=112;
  613.         gfp->VBR_max_bitrate_kbps=320;
  614.       }
  615.       else if (strcmp(nextArg,"cd")==0)
  616.       { /* when making changes, please update help text too */
  617.         gfp->lowpassfreq=-1;
  618.             gfp->highpassfreq=-1;
  619.         gfp->quality = 2;
  620.         gfp->mode = MPG_MD_STEREO; 
  621.         gfp->mode_fixed = 1; 
  622.         gfp->brate = 192;  
  623.         gfp->VBR_q=2;
  624.         gfp->VBR_min_bitrate_kbps=128;
  625.         gfp->VBR_max_bitrate_kbps=320;
  626.       }
  627.       else if (strcmp(nextArg,"studio")==0)
  628.       { /* when making changes, please update help text too */
  629.         gfp->lowpassfreq=-1;
  630.             gfp->highpassfreq=-1;
  631.         gfp->quality = 2; 
  632.         gfp->mode = MPG_MD_STEREO; 
  633.         gfp->mode_fixed = 1; 
  634.         gfp->brate = 256; 
  635.         gfp->VBR_q=0;
  636.         gfp->VBR_min_bitrate_kbps=160;
  637.         gfp->VBR_max_bitrate_kbps=320;
  638.       }
  639.       else if (strcmp(nextArg,"help")==0)
  640.       {
  641.         lame_presets_info(gfp,programName);  /* doesn't return */
  642.       }
  643.       else
  644.         {
  645.           ERRORF("%s: --preset type, type must be phone, voice, fm, tape, hifi, cd or studio, not %s\n",
  646.               programName, nextArg);
  647.           LAME_ERROR_EXIT();
  648.         }
  649.     } /* --preset */
  650.     else
  651.       {
  652.         ERRORF("%s: unrec option --%s\n",
  653.             programName, token);
  654.       }
  655.     i += argUsed;
  656.     
  657.       } else  while( (c = *token++) ) {
  658.     if(*token ) arg = token;
  659.     else                             arg = nextArg;
  660.     switch(c) {
  661.     case 'm':        argUsed = 1;   gfp->mode_fixed = 1;
  662.       if (*arg == 's')
  663.         { gfp->mode = MPG_MD_STEREO; }
  664.       else if (*arg == 'd')
  665.         { gfp->mode = MPG_MD_DUAL_CHANNEL; }
  666.       else if (*arg == 'j')
  667.         { gfp->mode = MPG_MD_JOINT_STEREO; }
  668.       else if (*arg == 'f')
  669.         { gfp->mode = MPG_MD_JOINT_STEREO; gfp->force_ms=1; }
  670.       else if (*arg == 'm')
  671.         { gfp->mode = MPG_MD_MONO; }
  672.       else {
  673.         ERRORF("%s: -m mode must be s/d/j/f/m not %s\n",
  674.             programName, arg);
  675.         err = 1;
  676.       }
  677.       break;
  678.     case 'V':        argUsed = 1;
  679.           /* to change VBR default look in lame.h */
  680.       if (gfp->VBR == vbr_off) gfp->VBR = vbr_default;  
  681.       gfp->VBR_q = atoi(arg);
  682.       if (gfp->VBR_q <0) gfp->VBR_q=0;
  683.       if (gfp->VBR_q >9) gfp->VBR_q=9;
  684.       gfp->quality = 2;
  685.       break;
  686.     case 'q':        argUsed = 1; 
  687.       user_quality = atoi(arg);
  688.       if (user_quality<0) user_quality=0;
  689.       if (user_quality>9) user_quality=9;
  690.       break;
  691.     case 's':
  692.       argUsed = 1;
  693.       srate = atof( arg );
  694.       /* samplerate = rint( 1000.0 * srate ); $A  */
  695.       gfp->in_samplerate =  (( 1000.0 * srate ) + 0.5);
  696.       break;
  697.     case 'b':        
  698.       argUsed = 1;
  699.       gfp->brate = atoi(arg); 
  700.       gfp->VBR_min_bitrate_kbps=gfp->brate;
  701.       break;
  702.     case 'B':        
  703.       argUsed = 1;
  704.       gfp->VBR_max_bitrate_kbps=atoi(arg); 
  705.       break;    
  706.     case 'F':        
  707.       gfp->VBR_hard_min=1;
  708.       break;    
  709.     case 't':  /* dont write VBR tag */
  710.       gfp->bWriteVbrTag=0;
  711.       gfp->disable_waveheader=1;
  712.       break;
  713.     case 'r':  /* force raw pcm input file */
  714. #ifdef LIBSNDFILE
  715.       ERRORF("WARNING: libsndfile may ignore -r and perform fseek's on the input.\n"
  716.              "Compile without libsndfile if this is a problem.\n");
  717. #endif
  718.       gfp->input_format=sf_raw;
  719.       break;
  720.     case 'x':  /* force byte swapping */
  721.       gfp->swapbytes=TRUE;
  722.       break;
  723.     case 'p': /* (jo) error_protection: add crc16 information to stream */
  724.       gfp->error_protection = 1; 
  725.       break;
  726.     case 'a': /* autoconvert input file from stereo to mono - for mono mp3 encoding */
  727.       autoconvert=1;
  728.       gfp->mode=MPG_MD_MONO;
  729.       gfp->mode_fixed=1;
  730.       break;
  731.     case 'h': 
  732.       gfp->quality = 2;
  733.       break;
  734.     case 'k': 
  735.       gfp->lowpassfreq=-1;
  736.       gfp->highpassfreq=-1;
  737.       break;
  738.     case 'd': 
  739.       gfp->allow_diff_short = 1;
  740.       break;
  741.     case 'v': 
  742.           /* to change VBR default look in lame.h */
  743.       gfp->VBR = vbr_default; 
  744.       gfp->quality = 2;
  745.       break;
  746.     case 'S': 
  747.       gfp->silent = TRUE;
  748.       break;
  749.     case 'X':        argUsed = 1;   
  750.       gfp->experimentalX=atoi(arg); 
  751.       break;
  752.  
  753.  
  754.     case 'Y': 
  755.       gfp->experimentalY = TRUE;
  756.       break;
  757.     case 'Z': 
  758.       gfp->experimentalZ = TRUE;
  759.       break;
  760.     case 'f': 
  761.       gfp->quality= 7;
  762.       break;
  763.     case 'g': /* turn on gtk analysis */
  764.       gfp->gtkflag = TRUE;
  765.       break;
  766.  
  767.     case 'e':        argUsed = 1;
  768.       if (*arg == 'n')                    gfp->emphasis = 0;
  769.       else if (*arg == '5')               gfp->emphasis = 1;
  770.       else if (*arg == 'c')               gfp->emphasis = 3;
  771.       else {
  772.         ERRORF("%s: -e emp must be n/5/c not %s\n",
  773.             programName, arg);
  774.         err = 1;
  775.       }
  776.       break;
  777.     case 'c':   gfp->copyright = 1; break;
  778.     case 'o':   gfp->original  = 0; break;
  779.     
  780.     case '?':   lame_help(gfp,programName);  /* doesn't return */
  781.     default:    ERRORF("%s: unrec option %c\n",
  782.                 programName, c);
  783.     err = 1; break;
  784.     }
  785.     if(argUsed) {
  786.       if(arg == token)    token = "";   /* no more from token */
  787.       else                ++i;          /* skip arg we used */
  788.       arg = ""; argUsed = 0;
  789.     }
  790.       }
  791.     } else {
  792.       if(gfp->inPath[0] == '\0')       strncpy(gfp->inPath, argv[i], MAX_NAME_SIZE);
  793.       else if(gfp->outPath[0] == '\0') strncpy(gfp->outPath, argv[i], MAX_NAME_SIZE);
  794.       else {
  795.     ERRORF("%s: excess arg %s\n", programName, argv[i]);
  796.     err = 1;
  797.       }
  798.     }
  799.   }  /* loop over args */
  800.  
  801.   if(err || gfp->inPath[0] == '\0') lame_usage(gfp,programName);  /* never returns */
  802.   if (gfp->inPath[0]=='-') gfp->silent=1;  /* turn off status - it's broken for stdin */
  803.   if(gfp->outPath[0] == '\0') {
  804.     if (gfp->inPath[0]=='-') {
  805.       /* if input is stdin, default output is stdout */
  806.       strcpy(gfp->outPath,"-");
  807.     }else {
  808.       strncpy(gfp->outPath, gfp->inPath, MAX_NAME_SIZE - 4);
  809.       if (gfp->decode_only) {
  810.     strncat(gfp->outPath, ".wav", 4 );
  811.       } else if (gfp->ogg) {
  812.     strncat(gfp->outPath, ".ogg", 4 );
  813.       }else{
  814.     strncat(gfp->outPath, ".mp3", 4 );
  815.       }
  816.     }
  817.   }
  818.   /* some file options not allowed with stdout */
  819.   if (gfp->outPath[0]=='-') {
  820.     gfp->bWriteVbrTag=0; /* turn off VBR tag */
  821.     if (gfp->id3v1_enabled) {
  822.       gfp->id3v1_enabled=0;     /* turn off ID3 version 1 tagging */
  823.       ERRORF("ID3 version 1 tagging not supported for stdout.\n");
  824.       ERRORF("Converting any ID3 tag data to version 2 format.\n");
  825.       id3tag_v2_only(&gfp->tag_spec);
  826.     }
  827.   }
  828.  
  829.  
  830.   /* if user did not explicitly specify input is mp3, check file name */
  831.   if (gfp->input_format != sf_mp3 || gfp->input_format != sf_ogg) {
  832.     if (!(strcmp((char *) &gfp->inPath[strlen(gfp->inPath)-4],".mp3")))
  833.       gfp->input_format = sf_mp3;
  834.     else if (!(strcmp((char *) &gfp->inPath[strlen(gfp->inPath)-4],".ogg")))
  835.       gfp->input_format = sf_ogg;
  836.   }
  837.   
  838. #if !(defined HAVEMPGLIB || defined AMIGA_MPEGA)
  839.   if (gfp->input_format == sf_mp3) {
  840.     ERRORF("Error: libmp3lame not compiled with mp3 *decoding* support \n");
  841.     LAME_ERROR_EXIT();
  842.   }
  843. #endif
  844.   /* default guess for number of channels */
  845.   if (autoconvert) gfp->num_channels=2; 
  846.   else if (gfp->mode == MPG_MD_MONO) gfp->num_channels=1;
  847.   else gfp->num_channels=2;
  848.  
  849.   /* user specified a quality value.  override any defaults set above */
  850.   if (user_quality>=0)   gfp->quality=user_quality;
  851.  
  852.   if (gfp->free_format) {
  853.     if (gfp->brate<8) {
  854.       ERRORF("For free format, specify a bitrate between 8 and 320kbs\n");
  855.       LAME_ERROR_EXIT();
  856.     }
  857.   }
  858.  
  859. }
  860.  
  861.  
  862.  
  863.