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