jlc.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * 11/19/04 1.0 moved to LGPL.
  3. *
  4. * 29/01/00 Initial version. mdm@techie.com
  5. *
  6. * 12/12/99 JavaLayer 0.0.7 mdm@techie.com
  7. *
  8. * 14/02/99 MPEG_Args Based Class - E.B
  9. * Adapted from javalayer and MPEG_Args.
  10. * Doc'ed and integerated with JL converter. Removed
  11. * Win32 specifics from original Maplay code.
  12. *-----------------------------------------------------------------------
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU Library General Public License as published
  15. * by the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Library General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Library General Public
  24. * License along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. *----------------------------------------------------------------------
  27. */
  28. package javazoom.jl.converter;
  29. import java.io.PrintWriter;
  30. import javazoom.jl.decoder.Crc16;
  31. import javazoom.jl.decoder.JavaLayerException;
  32. import javazoom.jl.decoder.OutputChannels;
  33. /**
  34. * The <code>jlc</code> class presents the JavaLayer
  35. * Conversion functionality as a command-line program.
  36. *
  37. * @since 0.0.7
  38. */
  39. public class jlc
  40. {
  41. static public void main(String args[])
  42. {
  43. String[] argv;
  44. long start = System.currentTimeMillis();
  45. int argc = args.length + 1;
  46. argv = new String[argc];
  47. argv[0] = "jlc";
  48. for(int i=0;i<args.length;i++)
  49. argv[i+1] = args[i];
  50. jlcArgs ma = new jlcArgs();
  51. if (!ma.processArgs(argv))
  52. System.exit(1);
  53. Converter conv = new Converter();
  54. int detail = (ma.verbose_mode ?
  55. ma.verbose_level :
  56. Converter.PrintWriterProgressListener.NO_DETAIL);
  57. Converter.ProgressListener listener =
  58. new Converter.PrintWriterProgressListener(
  59. new PrintWriter(System.out, true), detail);
  60. try
  61. {
  62. conv.convert(ma.filename, ma.output_filename, listener);
  63. }
  64. catch (JavaLayerException ex)
  65. {
  66. System.err.println("Convertion failure: "+ex);
  67. }
  68. System.exit(0);
  69. }
  70. /**
  71. * Class to contain arguments for maplay.
  72. */
  73. static class jlcArgs
  74. {
  75. // channel constants moved into OutputChannels class.
  76. //public static final int both = 0;
  77. //public static final int left = 1;
  78. //public static final int right = 2;
  79. //public static final int downmix = 3;
  80. public int which_c;
  81. public int output_mode;
  82. public boolean use_own_scalefactor;
  83. public float scalefactor;
  84. public String output_filename;
  85. public String filename;
  86. //public boolean stdout_mode;
  87. public boolean verbose_mode;
  88. public int verbose_level = 3;
  89. public jlcArgs()
  90. {
  91. which_c = OutputChannels.BOTH_CHANNELS;
  92. use_own_scalefactor = false;
  93. scalefactor = (float) 32768.0;
  94. //stdout_mode = false;
  95. verbose_mode = false;
  96. }
  97. /**
  98. * Process user arguments.
  99. *
  100. * Returns true if successful.
  101. */
  102. public boolean processArgs(String[] argv)
  103. {
  104. filename = null;
  105. Crc16[] crc;
  106. crc = new Crc16[1];
  107. int i;
  108. int argc = argv.length;
  109. //stdout_mode = false;
  110. verbose_mode = false;
  111. output_mode = OutputChannels.BOTH_CHANNELS;
  112. output_filename = "";
  113. if (argc < 2 || argv[1].equals("-h"))
  114. return Usage();
  115. i = 1;
  116. while (i < argc)
  117. {
  118. /* System.out.println("Option = "+argv[i]);*/
  119. if (argv[i].charAt(0) == '-')
  120. {
  121. if (argv[i].startsWith("-v"))
  122. {
  123. verbose_mode = true;
  124. if (argv[i].length()>2)
  125. {
  126. try
  127. {
  128. String level = argv[i].substring(2);
  129. verbose_level = Integer.parseInt(level);
  130. }
  131. catch (NumberFormatException ex)
  132. {
  133. System.err.println("Invalid verbose level. Using default.");
  134. }
  135. }
  136. System.out.println("Verbose Activated (level "+verbose_level+")");
  137. }
  138. /* else if (argv[i].equals("-s"))
  139. ma.stdout_mode = true; */
  140. else if (argv[i].equals("-p"))
  141. {
  142. if (++i == argc)
  143. {
  144. System.out.println("Please specify an output filename after the -p option!");
  145. System.exit (1);
  146. }
  147. //output_mode = O_WAVEFILE;
  148. output_filename = argv[i];
  149. }
  150. /*else if (argv[i].equals("-f"))
  151. {
  152. if (++i == argc)
  153. {
  154. System.out.println("Please specify a new scalefactor after the -f option!");
  155. System.exit(1);
  156. }
  157. ma.use_own_scalefactor = true;
  158. // ma.scalefactor = argv[i];
  159. }*/
  160. else return Usage();
  161. }
  162. else
  163. {
  164. filename = argv[i];
  165. System.out.println("FileName = "+argv[i]);
  166. if (filename == null) return Usage();
  167. }
  168. i++;
  169. }
  170. if (filename == null)
  171. return Usage();
  172. return true;
  173. }
  174. /**
  175. * Usage of JavaLayer.
  176. */
  177. public boolean Usage()
  178. {
  179. System.out.println("JavaLayer Converter :");
  180. System.out.println(" -v[x] verbose mode. ");
  181. System.out.println(" default = 2");
  182. /* System.out.println(" -s write u-law samples at 8 kHz rate to stdout");
  183. System.out.println(" -l decode only the left channel");
  184. System.out.println(" -r decode only the right channel");
  185. System.out.println(" -d downmix mode (layer III only)");
  186. System.out.println(" -s write pcm samples to stdout");
  187. System.out.println(" -d downmix mode (layer III only)");*/
  188. System.out.println(" -p name output as a PCM wave file");
  189. System.out.println("");
  190. System.out.println(" More info on http://www.javazoom.net");
  191. /* System.out.println(" -f ushort use this scalefactor instead of the default value 32768");*/
  192. return false;
  193. }
  194. };
  195. };