summaryrefslogtreecommitdiff
path: root/songdbj/javazoom/jl/converter
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/javazoom/jl/converter')
-rw-r--r--songdbj/javazoom/jl/converter/Converter.java411
-rw-r--r--songdbj/javazoom/jl/converter/RiffFile.java495
-rw-r--r--songdbj/javazoom/jl/converter/WaveFile.java522
-rw-r--r--songdbj/javazoom/jl/converter/WaveFileObuffer.java141
-rw-r--r--songdbj/javazoom/jl/converter/jlc.java216
5 files changed, 0 insertions, 1785 deletions
diff --git a/songdbj/javazoom/jl/converter/Converter.java b/songdbj/javazoom/jl/converter/Converter.java
deleted file mode 100644
index 845082e626..0000000000
--- a/songdbj/javazoom/jl/converter/Converter.java
+++ /dev/null
@@ -1,411 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 12/12/99 Original verion. mdm@techie.com.
4 *-----------------------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------
19 */
20
21package javazoom.jl.converter;
22
23import java.io.BufferedInputStream;
24import java.io.File;
25import java.io.FileInputStream;
26import java.io.IOException;
27import java.io.InputStream;
28import java.io.PrintWriter;
29
30import javazoom.jl.decoder.Bitstream;
31import javazoom.jl.decoder.Decoder;
32import javazoom.jl.decoder.Header;
33import javazoom.jl.decoder.JavaLayerException;
34import javazoom.jl.decoder.Obuffer;
35
36/**
37 * The <code>Converter</code> class implements the conversion of
38 * an MPEG audio file to a .WAV file. To convert an MPEG audio stream,
39 * just create an instance of this class and call the convert()
40 * method, passing in the names of the input and output files. You can
41 * pass in optional <code>ProgressListener</code> and
42 * <code>Decoder.Params</code> objects also to customize the conversion.
43 *
44 * @author MDM 12/12/99
45 * @since 0.0.7
46 */
47public class Converter
48{
49 /**
50 * Creates a new converter instance.
51 */
52 public Converter()
53 {
54 }
55
56 public synchronized void convert(String sourceName, String destName)
57 throws JavaLayerException
58 {
59 convert(sourceName, destName, null, null);
60 }
61
62 public synchronized void convert(String sourceName, String destName,
63 ProgressListener progressListener)
64 throws JavaLayerException
65 {
66 convert(sourceName, destName, progressListener, null);
67 }
68
69
70 public void convert(String sourceName, String destName,
71 ProgressListener progressListener, Decoder.Params decoderParams)
72 throws JavaLayerException
73 {
74 if (destName.length()==0)
75 destName = null;
76 try {
77 InputStream in = openInput(sourceName);
78 convert(in, destName, progressListener, decoderParams);
79 in.close();
80 } catch(IOException ioe) {
81 throw new JavaLayerException(ioe.getLocalizedMessage(), ioe);
82 }
83 }
84
85 public synchronized void convert(InputStream sourceStream, String destName,
86 ProgressListener progressListener, Decoder.Params decoderParams)
87 throws JavaLayerException
88 {
89 if (progressListener==null)
90 progressListener = PrintWriterProgressListener.newStdOut(
91 PrintWriterProgressListener.NO_DETAIL);
92 try {
93 if (!(sourceStream instanceof BufferedInputStream))
94 sourceStream = new BufferedInputStream(sourceStream);
95 int frameCount = -1;
96 if (sourceStream.markSupported()) {
97 sourceStream.mark(-1);
98 frameCount = countFrames(sourceStream);
99 sourceStream.reset();
100 }
101 progressListener.converterUpdate(ProgressListener.UPDATE_FRAME_COUNT, frameCount, 0);
102
103
104 Obuffer output = null;
105 Decoder decoder = new Decoder(decoderParams);
106 Bitstream stream = new Bitstream(sourceStream);
107
108 if (frameCount==-1)
109 frameCount = Integer.MAX_VALUE;
110
111 int frame = 0;
112 long startTime = System.currentTimeMillis();
113
114 try
115 {
116 for (; frame<frameCount; frame++)
117 {
118 try
119 {
120 Header header = stream.readFrame();
121 if (header==null)
122 break;
123
124 progressListener.readFrame(frame, header);
125
126 if (output==null)
127 {
128 // REVIEW: Incorrect functionality.
129 // the decoder should provide decoded
130 // frequency and channels output as it may differ from
131 // the source (e.g. when downmixing stereo to mono.)
132 int channels = (header.mode()==Header.SINGLE_CHANNEL) ? 1 : 2;
133 int freq = header.frequency();
134 output = new WaveFileObuffer(channels, freq, destName);
135 decoder.setOutputBuffer(output);
136 }
137
138 Obuffer decoderOutput = decoder.decodeFrame(header, stream);
139
140 // REVIEW: the way the output buffer is set
141 // on the decoder is a bit dodgy. Even though
142 // this exception should never happen, we test to be sure.
143 if (decoderOutput!=output)
144 throw new InternalError("Output buffers are different.");
145
146
147 progressListener.decodedFrame(frame, header, output);
148
149 stream.closeFrame();
150
151 }
152 catch (Exception ex)
153 {
154 boolean stop = !progressListener.converterException(ex);
155
156 if (stop)
157 {
158 throw new JavaLayerException(ex.getLocalizedMessage(), ex);
159 }
160 }
161 }
162
163 }
164 finally
165 {
166
167 if (output!=null)
168 output.close();
169 }
170
171 int time = (int)(System.currentTimeMillis()-startTime);
172 progressListener.converterUpdate(ProgressListener.UPDATE_CONVERT_COMPLETE,
173 time, frame);
174 }
175 catch (IOException ex)
176 {
177 throw new JavaLayerException(ex.getLocalizedMessage(), ex);
178 }
179 }
180
181
182 protected int countFrames(InputStream in)
183 {
184 return -1;
185 }
186
187
188 protected InputStream openInput(String fileName)
189 throws IOException
190 {
191 // ensure name is abstract path name
192 File file = new File(fileName);
193 InputStream fileIn = new FileInputStream(file);
194 BufferedInputStream bufIn = new BufferedInputStream(fileIn);
195
196 return bufIn;
197 }
198
199
200 /**
201 * This interface is used by the Converter to provide
202 * notification of tasks being carried out by the converter,
203 * and to provide new information as it becomes available.
204 */
205
206 static public interface ProgressListener
207 {
208 public static final int UPDATE_FRAME_COUNT = 1;
209
210 /**
211 * Conversion is complete. Param1 contains the time
212 * to convert in milliseconds. Param2 contains the number
213 * of MPEG audio frames converted.
214 */
215 public static final int UPDATE_CONVERT_COMPLETE = 2;
216
217
218 /**
219 * Notifies the listener that new information is available.
220 *
221 * @param updateID Code indicating the information that has been
222 * updated.
223 *
224 * @param param1 Parameter whose value depends upon the update code.
225 * @param param2 Parameter whose value depends upon the update code.
226 *
227 * The <code>updateID</code> parameter can take these values:
228 *
229 * UPDATE_FRAME_COUNT: param1 is the frame count, or -1 if not known.
230 * UPDATE_CONVERT_COMPLETE: param1 is the conversion time, param2
231 * is the number of frames converted.
232 */
233 public void converterUpdate(int updateID, int param1, int param2);
234
235 /**
236 * If the converter wishes to make a first pass over the
237 * audio frames, this is called as each frame is parsed.
238 */
239 public void parsedFrame(int frameNo, Header header);
240
241 /**
242 * This method is called after each frame has been read,
243 * but before it has been decoded.
244 *
245 * @param frameNo The 0-based sequence number of the frame.
246 * @param header The Header rerpesenting the frame just read.
247 */
248 public void readFrame(int frameNo, Header header);
249
250 /**
251 * This method is called after a frame has been decoded.
252 *
253 * @param frameNo The 0-based sequence number of the frame.
254 * @param header The Header rerpesenting the frame just read.
255 * @param o The Obuffer the deocded data was written to.
256 */
257 public void decodedFrame(int frameNo, Header header, Obuffer o);
258
259 /**
260 * Called when an exception is thrown during while converting
261 * a frame.
262 *
263 * @param t The <code>Throwable</code> instance that
264 * was thrown.
265 *
266 * @return <code>true</code> to continue processing, or false
267 * to abort conversion.
268 *
269 * If this method returns <code>false</code>, the exception
270 * is propagated to the caller of the convert() method. If
271 * <code>true</code> is returned, the exception is silently
272 * ignored and the converter moves onto the next frame.
273 */
274 public boolean converterException(Throwable t);
275
276 }
277
278
279 /**
280 * Implementation of <code>ProgressListener</code> that writes
281 * notification text to a <code>PrintWriter</code>.
282 */
283 // REVIEW: i18n of text and order required.
284 static public class PrintWriterProgressListener implements ProgressListener
285 {
286 static public final int NO_DETAIL = 0;
287
288 /**
289 * Level of detail typically expected of expert
290 * users.
291 */
292 static public final int EXPERT_DETAIL = 1;
293
294 /**
295 * Verbose detail.
296 */
297 static public final int VERBOSE_DETAIL = 2;
298
299 /**
300 * Debug detail. All frame read notifications are shown.
301 */
302 static public final int DEBUG_DETAIL = 7;
303
304 static public final int MAX_DETAIL = 10;
305
306 private PrintWriter pw;
307
308 private int detailLevel;
309
310 static public PrintWriterProgressListener newStdOut(int detail)
311 {
312 return new PrintWriterProgressListener(
313 new PrintWriter(System.out, true), detail);
314 }
315
316 public PrintWriterProgressListener(PrintWriter writer, int detailLevel)
317 {
318 this.pw = writer;
319 this.detailLevel = detailLevel;
320 }
321
322
323 public boolean isDetail(int detail)
324 {
325 return (this.detailLevel >= detail);
326 }
327
328 public void converterUpdate(int updateID, int param1, int param2)
329 {
330 if (isDetail(VERBOSE_DETAIL))
331 {
332 switch (updateID)
333 {
334 case UPDATE_CONVERT_COMPLETE:
335 // catch divide by zero errors.
336 if (param2==0)
337 param2 = 1;
338
339 pw.println();
340 pw.println("Converted "+param2+" frames in "+param1+" ms ("+
341 (param1/param2)+" ms per frame.)");
342 }
343 }
344 }
345
346 public void parsedFrame(int frameNo, Header header)
347 {
348 if ((frameNo==0) && isDetail(VERBOSE_DETAIL))
349 {
350 String headerString = header.toString();
351 pw.println("File is a "+headerString);
352 }
353 else if (isDetail(MAX_DETAIL))
354 {
355 String headerString = header.toString();
356 pw.println("Prased frame "+frameNo+": "+headerString);
357 }
358 }
359
360 public void readFrame(int frameNo, Header header)
361 {
362 if ((frameNo==0) && isDetail(VERBOSE_DETAIL))
363 {
364 String headerString = header.toString();
365 pw.println("File is a "+headerString);
366 }
367 else if (isDetail(MAX_DETAIL))
368 {
369 String headerString = header.toString();
370 pw.println("Read frame "+frameNo+": "+headerString);
371 }
372 }
373
374 public void decodedFrame(int frameNo, Header header, Obuffer o)
375 {
376 if (isDetail(MAX_DETAIL))
377 {
378 String headerString = header.toString();
379 pw.println("Decoded frame "+frameNo+": "+headerString);
380 pw.println("Output: "+o);
381 }
382 else if (isDetail(VERBOSE_DETAIL))
383 {
384 if (frameNo==0)
385 {
386 pw.print("Converting.");
387 pw.flush();
388 }
389
390 if ((frameNo % 10)==0)
391 {
392 pw.print('.');
393 pw.flush();
394 }
395 }
396 }
397
398 public boolean converterException(Throwable t)
399 {
400 if (this.detailLevel>NO_DETAIL)
401 {
402 t.printStackTrace(pw);
403 pw.flush();
404 }
405 return false;
406 }
407
408 }
409
410
411} \ No newline at end of file
diff --git a/songdbj/javazoom/jl/converter/RiffFile.java b/songdbj/javazoom/jl/converter/RiffFile.java
deleted file mode 100644
index fb5d9e53c6..0000000000
--- a/songdbj/javazoom/jl/converter/RiffFile.java
+++ /dev/null
@@ -1,495 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 02/23/99 JavaConversion by E.B
4 * Don Cross, April 1993.
5 * RIFF file format classes.
6 * See Chapter 8 of "Multimedia Programmer's Reference" in
7 * the Microsoft Windows SDK.
8 *
9 *-----------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library General Public License as published
12 * by the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *----------------------------------------------------------------------
24 */
25
26package javazoom.jl.converter;
27
28import java.io.IOException;
29import java.io.RandomAccessFile;
30
31
32/**
33 * Class to manage RIFF files
34 */
35public class RiffFile
36{
37 class RiffChunkHeader
38 {
39 public int ckID = 0; // Four-character chunk ID
40 public int ckSize = 0; // Length of data in chunk
41 public RiffChunkHeader()
42 {}
43 }
44
45
46 // DDCRET
47 public static final int DDC_SUCCESS = 0; // The operation succeded
48 public static final int DDC_FAILURE = 1; // The operation failed for unspecified reasons
49 public static final int DDC_OUT_OF_MEMORY = 2; // Operation failed due to running out of memory
50 public static final int DDC_FILE_ERROR = 3; // Operation encountered file I/O error
51 public static final int DDC_INVALID_CALL = 4; // Operation was called with invalid parameters
52 public static final int DDC_USER_ABORT = 5; // Operation was aborted by the user
53 public static final int DDC_INVALID_FILE = 6; // File format does not match
54
55 // RiffFileMode
56 public static final int RFM_UNKNOWN = 0; // undefined type (can use to mean "N/A" or "not open")
57 public static final int RFM_WRITE = 1; // open for write
58 public static final int RFM_READ = 2; // open for read
59
60 private RiffChunkHeader riff_header; // header for whole file
61 protected int fmode; // current file I/O mode
62 protected RandomAccessFile file; // I/O stream to use
63
64 /**
65 * Dummy Constructor
66 */
67 public RiffFile()
68 {
69 file = null;
70 fmode = RFM_UNKNOWN;
71 riff_header = new RiffChunkHeader();
72
73 riff_header.ckID = FourCC("RIFF");
74 riff_header.ckSize = 0;
75 }
76
77 /**
78 * Return File Mode.
79 */
80 public int CurrentFileMode()
81 {return fmode;}
82
83 /**
84 * Open a RIFF file.
85 */
86 public int Open(String Filename, int NewMode)
87 {
88 int retcode = DDC_SUCCESS;
89
90 if ( fmode != RFM_UNKNOWN )
91 {
92 retcode = Close();
93 }
94
95 if ( retcode == DDC_SUCCESS )
96 {
97 switch ( NewMode )
98 {
99 case RFM_WRITE:
100 try
101 {
102 file = new RandomAccessFile(Filename,"rw");
103
104 try
105 {
106 // Write the RIFF header...
107 // We will have to come back later and patch it!
108 byte[] br = new byte[8];
109 br[0] = (byte) ((riff_header.ckID >>> 24) & 0x000000FF);
110 br[1] = (byte) ((riff_header.ckID >>> 16) & 0x000000FF);
111 br[2] = (byte) ((riff_header.ckID >>> 8) & 0x000000FF);
112 br[3] = (byte) (riff_header.ckID & 0x000000FF);
113
114 byte br4 = (byte) ((riff_header.ckSize >>> 24)& 0x000000FF);
115 byte br5 = (byte) ((riff_header.ckSize >>> 16)& 0x000000FF);
116 byte br6 = (byte) ((riff_header.ckSize >>> 8)& 0x000000FF);
117 byte br7 = (byte) (riff_header.ckSize & 0x000000FF);
118
119 br[4] = br7;
120 br[5] = br6;
121 br[6] = br5;
122 br[7] = br4;
123
124 file.write(br,0,8);
125 fmode = RFM_WRITE;
126 } catch (IOException ioe)
127 {
128 file.close();
129 fmode = RFM_UNKNOWN;
130 }
131 } catch (IOException ioe)
132 {
133 fmode = RFM_UNKNOWN;
134 retcode = DDC_FILE_ERROR;
135 }
136 break;
137
138 case RFM_READ:
139 try
140 {
141 file = new RandomAccessFile(Filename,"r");
142 try
143 {
144 // Try to read the RIFF header...
145 byte[] br = new byte[8];
146 file.read(br,0,8);
147 fmode = RFM_READ;
148 riff_header.ckID = ((br[0]<<24)& 0xFF000000) | ((br[1]<<16)&0x00FF0000) | ((br[2]<<8)&0x0000FF00) | (br[3]&0x000000FF);
149 riff_header.ckSize = ((br[4]<<24)& 0xFF000000) | ((br[5]<<16)&0x00FF0000) | ((br[6]<<8)&0x0000FF00) | (br[7]&0x000000FF);
150 } catch (IOException ioe)
151 {
152 file.close();
153 fmode = RFM_UNKNOWN;
154 }
155 } catch (IOException ioe)
156 {
157 fmode = RFM_UNKNOWN;
158 retcode = DDC_FILE_ERROR;
159 }
160 break;
161 default:
162 retcode = DDC_INVALID_CALL;
163 }
164 }
165 return retcode;
166 }
167
168 /**
169 * Write NumBytes data.
170 */
171 public int Write(byte[] Data, int NumBytes )
172 {
173 if ( fmode != RFM_WRITE )
174 {
175 return DDC_INVALID_CALL;
176 }
177 try
178 {
179 file.write(Data,0,NumBytes);
180 fmode = RFM_WRITE;
181 }
182 catch (IOException ioe)
183 {
184 return DDC_FILE_ERROR;
185 }
186 riff_header.ckSize += NumBytes;
187 return DDC_SUCCESS;
188 }
189
190
191
192 /**
193 * Write NumBytes data.
194 */
195 public int Write(short[] Data, int NumBytes )
196 {
197 byte[] theData = new byte[NumBytes];
198 int yc = 0;
199 for (int y = 0;y<NumBytes;y=y+2)
200 {
201 theData[y] = (byte) (Data[yc] & 0x00FF);
202 theData[y+1] =(byte) ((Data[yc++] >>> 8) & 0x00FF);
203 }
204 if ( fmode != RFM_WRITE )
205 {
206 return DDC_INVALID_CALL;
207 }
208 try
209 {
210 file.write(theData,0,NumBytes);
211 fmode = RFM_WRITE;
212 }
213 catch (IOException ioe)
214 {
215 return DDC_FILE_ERROR;
216 }
217 riff_header.ckSize += NumBytes;
218 return DDC_SUCCESS;
219 }
220
221 /**
222 * Write NumBytes data.
223 */
224 public int Write(RiffChunkHeader Triff_header, int NumBytes )
225 {
226 byte[] br = new byte[8];
227 br[0] = (byte) ((Triff_header.ckID >>> 24) & 0x000000FF);
228 br[1] = (byte) ((Triff_header.ckID >>> 16) & 0x000000FF);
229 br[2] = (byte) ((Triff_header.ckID >>> 8) & 0x000000FF);
230 br[3] = (byte) (Triff_header.ckID & 0x000000FF);
231
232 byte br4 = (byte) ((Triff_header.ckSize >>> 24)& 0x000000FF);
233 byte br5 = (byte) ((Triff_header.ckSize >>> 16)& 0x000000FF);
234 byte br6 = (byte) ((Triff_header.ckSize >>> 8)& 0x000000FF);
235 byte br7 = (byte) (Triff_header.ckSize & 0x000000FF);
236
237 br[4] = br7;
238 br[5] = br6;
239 br[6] = br5;
240 br[7] = br4;
241
242 if ( fmode != RFM_WRITE )
243 {
244 return DDC_INVALID_CALL;
245 }
246 try
247 {
248 file.write(br,0,NumBytes);
249 fmode = RFM_WRITE;
250 } catch (IOException ioe)
251 {
252 return DDC_FILE_ERROR;
253 }
254 riff_header.ckSize += NumBytes;
255 return DDC_SUCCESS;
256 }
257
258 /**
259 * Write NumBytes data.
260 */
261 public int Write(short Data, int NumBytes )
262 {
263 short theData = (short) ( ((Data>>>8)&0x00FF) | ((Data<<8)&0xFF00) );
264 if ( fmode != RFM_WRITE )
265 {
266 return DDC_INVALID_CALL;
267 }
268 try
269 {
270 file.writeShort(theData);
271 fmode = RFM_WRITE;
272 } catch (IOException ioe)
273 {
274 return DDC_FILE_ERROR;
275 }
276 riff_header.ckSize += NumBytes;
277 return DDC_SUCCESS;
278 }
279 /**
280 * Write NumBytes data.
281 */
282 public int Write(int Data, int NumBytes )
283 {
284 short theDataL = (short) ((Data>>>16)&0x0000FFFF);
285 short theDataR = (short) (Data&0x0000FFFF);
286 short theDataLI = (short) ( ((theDataL>>>8)&0x00FF) | ((theDataL<<8)&0xFF00) );
287 short theDataRI = (short) ( ((theDataR>>>8)&0x00FF) | ((theDataR<<8)&0xFF00) );
288 int theData = ((theDataRI<<16)&0xFFFF0000) | (theDataLI&0x0000FFFF);
289 if ( fmode != RFM_WRITE )
290 {
291 return DDC_INVALID_CALL;
292 }
293 try
294 {
295 file.writeInt(theData);
296 fmode = RFM_WRITE;
297 } catch (IOException ioe)
298 {
299 return DDC_FILE_ERROR;
300 }
301 riff_header.ckSize += NumBytes;
302 return DDC_SUCCESS;
303 }
304
305
306
307 /**
308 * Read NumBytes data.
309 */
310 public int Read (byte[] Data, int NumBytes)
311 {
312 int retcode = DDC_SUCCESS;
313 try
314 {
315 file.read(Data,0,NumBytes);
316 } catch (IOException ioe)
317 {
318 retcode = DDC_FILE_ERROR;
319 }
320 return retcode;
321 }
322
323 /**
324 * Expect NumBytes data.
325 */
326 public int Expect(String Data, int NumBytes )
327 {
328 byte target = 0;
329 int cnt = 0;
330 try
331 {
332 while ((NumBytes--) != 0)
333 {
334 target = file.readByte();
335 if (target != Data.charAt(cnt++)) return DDC_FILE_ERROR;
336 }
337 } catch (IOException ioe)
338 {
339 return DDC_FILE_ERROR;
340 }
341 return DDC_SUCCESS;
342 }
343
344 /**
345 * Close Riff File.
346 * Length is written too.
347 */
348 public int Close()
349 {
350 int retcode = DDC_SUCCESS;
351
352 switch ( fmode )
353 {
354 case RFM_WRITE:
355 try
356 {
357 file.seek(0);
358 try
359 {
360 byte[] br = new byte[8];
361 br[0] = (byte) ((riff_header.ckID >>> 24) & 0x000000FF);
362 br[1] = (byte) ((riff_header.ckID >>> 16) & 0x000000FF);
363 br[2] = (byte) ((riff_header.ckID >>> 8) & 0x000000FF);
364 br[3] = (byte) (riff_header.ckID & 0x000000FF);
365
366 br[7] = (byte) ((riff_header.ckSize >>> 24)& 0x000000FF);
367 br[6] = (byte) ((riff_header.ckSize >>> 16)& 0x000000FF);
368 br[5] = (byte) ((riff_header.ckSize >>> 8)& 0x000000FF);
369 br[4] = (byte) (riff_header.ckSize & 0x000000FF);
370 file.write(br,0,8);
371 file.close();
372 } catch (IOException ioe)
373 {
374 retcode = DDC_FILE_ERROR;
375 }
376 } catch (IOException ioe)
377 {
378 retcode = DDC_FILE_ERROR;
379 }
380 break;
381
382 case RFM_READ:
383 try
384 {
385 file.close();
386 } catch (IOException ioe)
387 {
388 retcode = DDC_FILE_ERROR;
389 }
390 break;
391 }
392 file = null;
393 fmode = RFM_UNKNOWN;
394 return retcode;
395 }
396
397 /**
398 * Return File Position.
399 */
400 public long CurrentFilePosition()
401 {
402 long position;
403 try
404 {
405 position = file.getFilePointer();
406 } catch (IOException ioe)
407 {
408 position = -1;
409 }
410 return position;
411 }
412
413 /**
414 * Write Data to specified offset.
415 */
416 public int Backpatch (long FileOffset, RiffChunkHeader Data, int NumBytes )
417 {
418 if (file == null)
419 {
420 return DDC_INVALID_CALL;
421 }
422 try
423 {
424 file.seek(FileOffset);
425 } catch (IOException ioe)
426 {
427 return DDC_FILE_ERROR;
428 }
429 return Write ( Data, NumBytes );
430 }
431
432 public int Backpatch (long FileOffset, byte[] Data, int NumBytes )
433 {
434 if (file == null)
435 {
436 return DDC_INVALID_CALL;
437 }
438 try
439 {
440 file.seek(FileOffset);
441 } catch (IOException ioe)
442 {
443 return DDC_FILE_ERROR;
444 }
445 return Write ( Data, NumBytes );
446 }
447
448
449 /**
450 * Seek in the File.
451 */
452 protected int Seek(long offset)
453 {
454 int rc;
455 try
456 {
457 file.seek(offset);
458 rc = DDC_SUCCESS;
459 } catch (IOException ioe)
460 {
461 rc = DDC_FILE_ERROR;
462 }
463 return rc;
464 }
465
466 /**
467 * Error Messages.
468 */
469 private String DDCRET_String(int retcode)
470 {
471 switch ( retcode )
472 {
473 case DDC_SUCCESS: return "DDC_SUCCESS";
474 case DDC_FAILURE: return "DDC_FAILURE";
475 case DDC_OUT_OF_MEMORY: return "DDC_OUT_OF_MEMORY";
476 case DDC_FILE_ERROR: return "DDC_FILE_ERROR";
477 case DDC_INVALID_CALL: return "DDC_INVALID_CALL";
478 case DDC_USER_ABORT: return "DDC_USER_ABORT";
479 case DDC_INVALID_FILE: return "DDC_INVALID_FILE";
480 }
481 return "Unknown Error";
482 }
483
484 /**
485 * Fill the header.
486 */
487 public static int FourCC(String ChunkName)
488 {
489 byte[] p = {0x20,0x20,0x20,0x20};
490 ChunkName.getBytes(0,4,p,0);
491 int ret = (((p[0] << 24)& 0xFF000000) | ((p[1] << 16)&0x00FF0000) | ((p[2] << 8)&0x0000FF00) | (p[3]&0x000000FF));
492 return ret;
493 }
494
495}
diff --git a/songdbj/javazoom/jl/converter/WaveFile.java b/songdbj/javazoom/jl/converter/WaveFile.java
deleted file mode 100644
index f158d7a39a..0000000000
--- a/songdbj/javazoom/jl/converter/WaveFile.java
+++ /dev/null
@@ -1,522 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 02/23/99 JavaConversion by E.B
4 * Don Cross, April 1993.
5 * RIFF file format classes.
6 * See Chapter 8 of "Multimedia Programmer's Reference" in
7 * the Microsoft Windows SDK.
8 *
9 *-----------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library General Public License as published
12 * by the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *----------------------------------------------------------------------
24 */
25
26package javazoom.jl.converter;
27
28/**
29 * Class allowing WaveFormat Access
30 */
31public class WaveFile extends RiffFile
32{
33 public static final int MAX_WAVE_CHANNELS = 2;
34
35 class WaveFormat_ChunkData
36 {
37 public short wFormatTag = 0; // Format category (PCM=1)
38 public short nChannels = 0; // Number of channels (mono=1, stereo=2)
39 public int nSamplesPerSec = 0; // Sampling rate [Hz]
40 public int nAvgBytesPerSec = 0;
41 public short nBlockAlign = 0;
42 public short nBitsPerSample = 0;
43
44 public WaveFormat_ChunkData()
45 {
46 wFormatTag = 1; // PCM
47 Config(44100,(short)16,(short)1);
48 }
49
50 public void Config (int NewSamplingRate, short NewBitsPerSample, short NewNumChannels)
51 {
52 nSamplesPerSec = NewSamplingRate;
53 nChannels = NewNumChannels;
54 nBitsPerSample = NewBitsPerSample;
55 nAvgBytesPerSec = (nChannels * nSamplesPerSec * nBitsPerSample) / 8;
56 nBlockAlign = (short) ((nChannels * nBitsPerSample) / 8);
57 }
58 }
59
60
61 class WaveFormat_Chunk
62 {
63 public RiffChunkHeader header;
64 public WaveFormat_ChunkData data;
65
66 public WaveFormat_Chunk()
67 {
68 header = new RiffChunkHeader();
69 data = new WaveFormat_ChunkData();
70 header.ckID = FourCC("fmt ");
71 header.ckSize = 16;
72 }
73
74 public int VerifyValidity()
75 {
76 boolean ret = header.ckID == FourCC("fmt ") &&
77
78 (data.nChannels == 1 || data.nChannels == 2) &&
79
80 data.nAvgBytesPerSec == ( data.nChannels *
81 data.nSamplesPerSec *
82 data.nBitsPerSample ) / 8 &&
83
84 data.nBlockAlign == ( data.nChannels *
85 data.nBitsPerSample ) / 8;
86 if (ret == true) return 1;
87 else return 0;
88 }
89 }
90
91 public class WaveFileSample
92 {
93 public short[] chan;
94
95 public WaveFileSample()
96 {chan = new short[WaveFile.MAX_WAVE_CHANNELS];}
97 }
98
99 private WaveFormat_Chunk wave_format;
100 private RiffChunkHeader pcm_data;
101 private long pcm_data_offset = 0; // offset of 'pcm_data' in output file
102 private int num_samples = 0;
103
104
105 /**
106 * Constructs a new WaveFile instance.
107 */
108 public WaveFile()
109 {
110 pcm_data = new RiffChunkHeader();
111 wave_format = new WaveFormat_Chunk();
112 pcm_data.ckID = FourCC("data");
113 pcm_data.ckSize = 0;
114 num_samples = 0;
115 }
116
117 /**
118 *
119 *
120 public int OpenForRead (String Filename)
121 {
122 // Verify filename parameter as best we can...
123 if (Filename == null)
124 {
125 return DDC_INVALID_CALL;
126 }
127 int retcode = Open ( Filename, RFM_READ );
128
129 if ( retcode == DDC_SUCCESS )
130 {
131 retcode = Expect ( "WAVE", 4 );
132
133 if ( retcode == DDC_SUCCESS )
134 {
135 retcode = Read(wave_format,24);
136
137 if ( retcode == DDC_SUCCESS && !wave_format.VerifyValidity() )
138 {
139 // This isn't standard PCM, so we don't know what it is!
140 retcode = DDC_FILE_ERROR;
141 }
142
143 if ( retcode == DDC_SUCCESS )
144 {
145 pcm_data_offset = CurrentFilePosition();
146
147 // Figure out number of samples from
148 // file size, current file position, and
149 // WAVE header.
150 retcode = Read (pcm_data, 8 );
151 num_samples = filelength(fileno(file)) - CurrentFilePosition();
152 num_samples /= NumChannels();
153 num_samples /= (BitsPerSample() / 8);
154 }
155 }
156 }
157 return retcode;
158 }*/
159
160 /**
161 *
162 */
163 public int OpenForWrite (String Filename, int SamplingRate, short BitsPerSample, short NumChannels)
164 {
165 // Verify parameters...
166 if ( (Filename==null) ||
167 (BitsPerSample != 8 && BitsPerSample != 16) ||
168 NumChannels < 1 || NumChannels > 2 )
169 {
170 return DDC_INVALID_CALL;
171 }
172
173 wave_format.data.Config ( SamplingRate, BitsPerSample, NumChannels );
174
175 int retcode = Open ( Filename, RFM_WRITE );
176
177 if ( retcode == DDC_SUCCESS )
178 {
179 byte [] theWave = {(byte)'W',(byte)'A',(byte)'V',(byte)'E'};
180 retcode = Write ( theWave, 4 );
181
182 if ( retcode == DDC_SUCCESS )
183 {
184 // Ecriture de wave_format
185 retcode = Write (wave_format.header, 8);
186 retcode = Write (wave_format.data.wFormatTag, 2);
187 retcode = Write (wave_format.data.nChannels, 2);
188 retcode = Write (wave_format.data.nSamplesPerSec, 4);
189 retcode = Write (wave_format.data.nAvgBytesPerSec, 4);
190 retcode = Write (wave_format.data.nBlockAlign, 2);
191 retcode = Write (wave_format.data.nBitsPerSample, 2);
192 /* byte[] br = new byte[16];
193 br[0] = (byte) ((wave_format.data.wFormatTag >> 8) & 0x00FF);
194 br[1] = (byte) (wave_format.data.wFormatTag & 0x00FF);
195
196 br[2] = (byte) ((wave_format.data.nChannels >> 8) & 0x00FF);
197 br[3] = (byte) (wave_format.data.nChannels & 0x00FF);
198
199 br[4] = (byte) ((wave_format.data.nSamplesPerSec >> 24)& 0x000000FF);
200 br[5] = (byte) ((wave_format.data.nSamplesPerSec >> 16)& 0x000000FF);
201 br[6] = (byte) ((wave_format.data.nSamplesPerSec >> 8)& 0x000000FF);
202 br[7] = (byte) (wave_format.data.nSamplesPerSec & 0x000000FF);
203
204 br[8] = (byte) ((wave_format.data.nAvgBytesPerSec>> 24)& 0x000000FF);
205 br[9] = (byte) ((wave_format.data.nAvgBytesPerSec >> 16)& 0x000000FF);
206 br[10] = (byte) ((wave_format.data.nAvgBytesPerSec >> 8)& 0x000000FF);
207 br[11] = (byte) (wave_format.data.nAvgBytesPerSec & 0x000000FF);
208
209 br[12] = (byte) ((wave_format.data.nBlockAlign >> 8) & 0x00FF);
210 br[13] = (byte) (wave_format.data.nBlockAlign & 0x00FF);
211
212 br[14] = (byte) ((wave_format.data.nBitsPerSample >> 8) & 0x00FF);
213 br[15] = (byte) (wave_format.data.nBitsPerSample & 0x00FF);
214 retcode = Write (br, 16); */
215
216
217 if ( retcode == DDC_SUCCESS )
218 {
219 pcm_data_offset = CurrentFilePosition();
220 retcode = Write ( pcm_data, 8 );
221 }
222 }
223 }
224
225 return retcode;
226 }
227
228 /**
229 *
230 *
231 public int ReadSample ( short[] Sample )
232 {
233
234 }*/
235
236 /**
237 *
238 *
239 public int WriteSample( short[] Sample )
240 {
241 int retcode = DDC_SUCCESS;
242 switch ( wave_format.data.nChannels )
243 {
244 case 1:
245 switch ( wave_format.data.nBitsPerSample )
246 {
247 case 8:
248 pcm_data.ckSize += 1;
249 retcode = Write ( Sample, 1 );
250 break;
251
252 case 16:
253 pcm_data.ckSize += 2;
254 retcode = Write ( Sample, 2 );
255 break;
256
257 default:
258 retcode = DDC_INVALID_CALL;
259 }
260 break;
261
262 case 2:
263 switch ( wave_format.data.nBitsPerSample )
264 {
265 case 8:
266 retcode = Write ( Sample, 1 );
267 if ( retcode == DDC_SUCCESS )
268 {
269 // &Sample[1]
270 retcode = Write (Sample, 1 );
271 if ( retcode == DDC_SUCCESS )
272 {
273 pcm_data.ckSize += 2;
274 }
275 }
276 break;
277
278 case 16:
279 retcode = Write ( Sample, 2 );
280 if ( retcode == DDC_SUCCESS )
281 {
282 // &Sample[1]
283 retcode = Write (Sample, 2 );
284 if ( retcode == DDC_SUCCESS )
285 {
286 pcm_data.ckSize += 4;
287 }
288 }
289 break;
290
291 default:
292 retcode = DDC_INVALID_CALL;
293 }
294 break;
295
296 default:
297 retcode = DDC_INVALID_CALL;
298 }
299
300 return retcode;
301 }*/
302
303 /**
304 *
305 *
306 public int SeekToSample ( long SampleIndex )
307 {
308 if ( SampleIndex >= NumSamples() )
309 {
310 return DDC_INVALID_CALL;
311 }
312 int SampleSize = (BitsPerSample() + 7) / 8;
313 int rc = Seek ( pcm_data_offset + 8 +
314 SampleSize * NumChannels() * SampleIndex );
315 return rc;
316 }*/
317
318 /**
319 * Write 16-bit audio
320 */
321 public int WriteData ( short[] data, int numData )
322 {
323 int extraBytes = numData * 2;
324 pcm_data.ckSize += extraBytes;
325 return super.Write ( data, extraBytes );
326 }
327
328 /**
329 * Read 16-bit audio.
330 *
331 public int ReadData (short[] data, int numData)
332 {return super.Read ( data, numData * 2);} */
333
334 /**
335 * Write 8-bit audio.
336 *
337 public int WriteData ( byte[] data, int numData )
338 {
339 pcm_data.ckSize += numData;
340 return super.Write ( data, numData );
341 }*/
342
343 /**
344 * Read 8-bit audio.
345 *
346 public int ReadData ( byte[] data, int numData )
347 {return super.Read ( data, numData );} */
348
349
350 /**
351 *
352 *
353 public int ReadSamples (int num, int [] WaveFileSample)
354 {
355
356 }*/
357
358 /**
359 *
360 *
361 public int WriteMonoSample ( short[] SampleData )
362 {
363 switch ( wave_format.data.nBitsPerSample )
364 {
365 case 8:
366 pcm_data.ckSize += 1;
367 return Write ( SampleData, 1 );
368
369 case 16:
370 pcm_data.ckSize += 2;
371 return Write ( SampleData, 2 );
372 }
373 return DDC_INVALID_CALL;
374 }*/
375
376 /**
377 *
378 *
379 public int WriteStereoSample ( short[] LeftSample, short[] RightSample )
380 {
381 int retcode = DDC_SUCCESS;
382 switch ( wave_format.data.nBitsPerSample )
383 {
384 case 8:
385 retcode = Write ( LeftSample, 1 );
386 if ( retcode == DDC_SUCCESS )
387 {
388 retcode = Write ( RightSample, 1 );
389 if ( retcode == DDC_SUCCESS )
390 {
391 pcm_data.ckSize += 2;
392 }
393 }
394 break;
395
396 case 16:
397 retcode = Write ( LeftSample, 2 );
398 if ( retcode == DDC_SUCCESS )
399 {
400 retcode = Write ( RightSample, 2 );
401 if ( retcode == DDC_SUCCESS )
402 {
403 pcm_data.ckSize += 4;
404 }
405 }
406 break;
407
408 default:
409 retcode = DDC_INVALID_CALL;
410 }
411 return retcode;
412 }*/
413
414 /**
415 *
416 *
417 public int ReadMonoSample ( short[] Sample )
418 {
419 int retcode = DDC_SUCCESS;
420 switch ( wave_format.data.nBitsPerSample )
421 {
422 case 8:
423 byte[] x = {0};
424 retcode = Read ( x, 1 );
425 Sample[0] = (short)(x[0]);
426 break;
427
428 case 16:
429 retcode = Read ( Sample, 2 );
430 break;
431
432 default:
433 retcode = DDC_INVALID_CALL;
434 }
435 return retcode;
436 }*/
437
438 /**
439 *
440 *
441 public int ReadStereoSample ( short[] LeftSampleData, short[] RightSampleData )
442 {
443 int retcode = DDC_SUCCESS;
444 byte[] x = new byte[2];
445 short[] y = new short[2];
446 switch ( wave_format.data.nBitsPerSample )
447 {
448 case 8:
449 retcode = Read ( x, 2 );
450 L[0] = (short) ( x[0] );
451 R[0] = (short) ( x[1] );
452 break;
453
454 case 16:
455 retcode = Read ( y, 4 );
456 L[0] = (short) ( y[0] );
457 R[0] = (short) ( y[1] );
458 break;
459
460 default:
461 retcode = DDC_INVALID_CALL;
462 }
463 return retcode;
464 }*/
465
466
467 /**
468 *
469 */
470 public int Close()
471 {
472 int rc = DDC_SUCCESS;
473
474 if ( fmode == RFM_WRITE )
475 rc = Backpatch ( pcm_data_offset, pcm_data, 8 );
476 if ( rc == DDC_SUCCESS )
477 rc = super.Close();
478 return rc;
479 }
480
481 // [Hz]
482 public int SamplingRate()
483 {return wave_format.data.nSamplesPerSec;}
484
485 public short BitsPerSample()
486 {return wave_format.data.nBitsPerSample;}
487
488 public short NumChannels()
489 {return wave_format.data.nChannels;}
490
491 public int NumSamples()
492 {return num_samples;}
493
494
495 /**
496 * Open for write using another wave file's parameters...
497 */
498 public int OpenForWrite (String Filename, WaveFile OtherWave )
499 {
500 return OpenForWrite ( Filename,
501 OtherWave.SamplingRate(),
502 OtherWave.BitsPerSample(),
503 OtherWave.NumChannels() );
504 }
505
506 /**
507 *
508 */
509 public long CurrentFilePosition()
510 {
511 return super.CurrentFilePosition();
512 }
513
514 /* public int FourCC(String ChunkName)
515 {
516 byte[] p = {0x20,0x20,0x20,0x20};
517 ChunkName.getBytes(0,4,p,0);
518 int ret = (((p[0] << 24)& 0xFF000000) | ((p[1] << 16)&0x00FF0000) | ((p[2] << 8)&0x0000FF00) | (p[3]&0x000000FF));
519 return ret;
520 }*/
521
522} \ No newline at end of file
diff --git a/songdbj/javazoom/jl/converter/WaveFileObuffer.java b/songdbj/javazoom/jl/converter/WaveFileObuffer.java
deleted file mode 100644
index eaa1dd46d4..0000000000
--- a/songdbj/javazoom/jl/converter/WaveFileObuffer.java
+++ /dev/null
@@ -1,141 +0,0 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 *
4 * 12/12/99 0.0.7 Renamed class, additional constructor arguments
5 * and larger write buffers. mdm@techie.com.
6 *
7 * 15/02/99 Java Conversion by E.B ,javalayer@javazoom.net
8 *
9 *-----------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library General Public License as published
12 * by the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *----------------------------------------------------------------------
24 */
25
26package javazoom.jl.converter;
27
28import javazoom.jl.decoder.Obuffer;
29
30/**
31 * Implements an Obuffer by writing the data to
32 * a file in RIFF WAVE format.
33 *
34 * @since 0.0
35 */
36
37
38public class WaveFileObuffer extends Obuffer
39{
40 private short[] buffer;
41 private short[] bufferp;
42 private int channels;
43 private WaveFile outWave;
44
45 /**
46 * Creates a new WareFileObuffer instance.
47 *
48 * @param number_of_channels
49 * The number of channels of audio data
50 * this buffer will receive.
51 *
52 * @param freq The sample frequency of the samples in the buffer.
53 *
54 * @param fileName The filename to write the data to.
55 */
56 public WaveFileObuffer(int number_of_channels, int freq, String FileName)
57 {
58 if (FileName==null)
59 throw new NullPointerException("FileName");
60
61 buffer = new short[OBUFFERSIZE];
62 bufferp = new short[MAXCHANNELS];
63 channels = number_of_channels;
64
65 for (int i = 0; i < number_of_channels; ++i)
66 bufferp[i] = (short)i;
67
68 outWave = new WaveFile();
69
70 int rc = outWave.OpenForWrite (FileName,freq,(short)16,(short)channels);
71 }
72
73 /**
74 * Takes a 16 Bit PCM sample.
75 */
76 public void append(int channel, short value)
77 {
78 buffer[bufferp[channel]] = value;
79 bufferp[channel] += channels;
80 }
81
82 /**
83 * Write the samples to the file (Random Acces).
84 */
85 short[] myBuffer = new short[2];
86 public void write_buffer(int val)
87 {
88
89 int k = 0;
90 int rc = 0;
91
92 rc = outWave.WriteData(buffer, bufferp[0]);
93 // REVIEW: handle RiffFile errors.
94 /*
95 for (int j=0;j<bufferp[0];j=j+2)
96 {
97
98 //myBuffer[0] = (short)(((buffer[j]>>8)&0x000000FF) | ((buffer[j]<<8)&0x0000FF00));
99 //myBuffer[1] = (short) (((buffer[j+1]>>8)&0x000000FF) | ((buffer[j+1]<<8)&0x0000FF00));
100 myBuffer[0] = buffer[j];
101 myBuffer[1] = buffer[j+1];
102 rc = outWave.WriteData (myBuffer,2);
103 }
104 */
105 for (int i = 0; i < channels; ++i) bufferp[i] = (short)i;
106 }
107
108 public void close()
109 {
110 outWave.Close();
111 }
112
113 /**
114 *
115 */
116 public void clear_buffer()
117 {}
118
119 /**
120 *
121 */
122 public void set_stop_flag()
123 {}
124
125 /*
126 * Create STDOUT buffer
127 *
128 *
129 public static Obuffer create_stdout_obuffer(MPEG_Args maplay_args)
130 {
131 Obuffer thebuffer = null;
132 int mode = maplay_args.MPEGheader.mode();
133 int which_channels = maplay_args.which_c;
134 if (mode == Header.single_channel || which_channels != MPEG_Args.both)
135 thebuffer = new FileObuffer(1,maplay_args.output_filename);
136 else
137 thebuffer = new FileObuffer(2,maplay_args.output_filename);
138 return(thebuffer);
139 }
140 */
141}
diff --git a/songdbj/javazoom/jl/converter/jlc.java b/songdbj/javazoom/jl/converter/jlc.java
deleted file mode 100644
index 57c84eba4a..0000000000
--- a/songdbj/javazoom/jl/converter/jlc.java
+++ /dev/null
@@ -1,216 +0,0 @@
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
29package javazoom.jl.converter;
30
31import java.io.PrintWriter;
32
33import javazoom.jl.decoder.Crc16;
34import javazoom.jl.decoder.JavaLayerException;
35import javazoom.jl.decoder.OutputChannels;
36
37/**
38 * The <code>jlc</code> class presents the JavaLayer
39 * Conversion functionality as a command-line program.
40 *
41 * @since 0.0.7
42 */
43public class jlc
44{
45
46 static public void main(String args[])
47 {
48 String[] argv;
49 long start = System.currentTimeMillis();
50 int argc = args.length + 1;
51 argv = new String[argc];
52 argv[0] = "jlc";
53 for(int i=0;i<args.length;i++)
54 argv[i+1] = args[i];
55
56 jlcArgs ma = new jlcArgs();
57 if (!ma.processArgs(argv))
58 System.exit(1);
59
60 Converter conv = new Converter();
61
62 int detail = (ma.verbose_mode ?
63 ma.verbose_level :
64 Converter.PrintWriterProgressListener.NO_DETAIL);
65
66 Converter.ProgressListener listener =
67 new Converter.PrintWriterProgressListener(
68 new PrintWriter(System.out, true), detail);
69
70 try
71 {
72 conv.convert(ma.filename, ma.output_filename, listener);
73 }
74 catch (JavaLayerException ex)
75 {
76 System.err.println("Convertion failure: "+ex);
77 }
78
79 System.exit(0);
80 }
81
82
83 /**
84 * Class to contain arguments for maplay.
85 */
86 static class jlcArgs
87 {
88 // channel constants moved into OutputChannels class.
89 //public static final int both = 0;
90 //public static final int left = 1;
91 //public static final int right = 2;
92 //public static final int downmix = 3;
93
94 public int which_c;
95 public int output_mode;
96 public boolean use_own_scalefactor;
97 public float scalefactor;
98 public String output_filename;
99 public String filename;
100 //public boolean stdout_mode;
101 public boolean verbose_mode;
102 public int verbose_level = 3;
103
104 public jlcArgs()
105 {
106 which_c = OutputChannels.BOTH_CHANNELS;
107 use_own_scalefactor = false;
108 scalefactor = (float) 32768.0;
109 //stdout_mode = false;
110 verbose_mode = false;
111 }
112
113 /**
114 * Process user arguments.
115 *
116 * Returns true if successful.
117 */
118 public boolean processArgs(String[] argv)
119 {
120 filename = null;
121 Crc16[] crc;
122 crc = new Crc16[1];
123 int i;
124 int argc = argv.length;
125
126 //stdout_mode = false;
127 verbose_mode = false;
128 output_mode = OutputChannels.BOTH_CHANNELS;
129 output_filename = "";
130 if (argc < 2 || argv[1].equals("-h"))
131 return Usage();
132
133 i = 1;
134 while (i < argc)
135 {
136 /* System.out.println("Option = "+argv[i]);*/
137 if (argv[i].charAt(0) == '-')
138 {
139 if (argv[i].startsWith("-v"))
140 {
141 verbose_mode = true;
142 if (argv[i].length()>2)
143 {
144 try
145 {
146 String level = argv[i].substring(2);
147 verbose_level = Integer.parseInt(level);
148 }
149 catch (NumberFormatException ex)
150 {
151 System.err.println("Invalid verbose level. Using default.");
152 }
153 }
154 System.out.println("Verbose Activated (level "+verbose_level+")");
155 }
156 /* else if (argv[i].equals("-s"))
157 ma.stdout_mode = true; */
158 else if (argv[i].equals("-p"))
159 {
160 if (++i == argc)
161 {
162 System.out.println("Please specify an output filename after the -p option!");
163 System.exit (1);
164 }
165 //output_mode = O_WAVEFILE;
166 output_filename = argv[i];
167 }
168 /*else if (argv[i].equals("-f"))
169 {
170 if (++i == argc)
171 {
172 System.out.println("Please specify a new scalefactor after the -f option!");
173 System.exit(1);
174 }
175 ma.use_own_scalefactor = true;
176 // ma.scalefactor = argv[i];
177 }*/
178 else return Usage();
179 }
180 else
181 {
182 filename = argv[i];
183 System.out.println("FileName = "+argv[i]);
184 if (filename == null) return Usage();
185 }
186 i++;
187 }
188 if (filename == null)
189 return Usage();
190
191 return true;
192 }
193
194
195 /**
196 * Usage of JavaLayer.
197 */
198 public boolean Usage()
199 {
200 System.out.println("JavaLayer Converter :");
201 System.out.println(" -v[x] verbose mode. ");
202 System.out.println(" default = 2");
203 /* System.out.println(" -s write u-law samples at 8 kHz rate to stdout");
204 System.out.println(" -l decode only the left channel");
205 System.out.println(" -r decode only the right channel");
206 System.out.println(" -d downmix mode (layer III only)");
207 System.out.println(" -s write pcm samples to stdout");
208 System.out.println(" -d downmix mode (layer III only)");*/
209 System.out.println(" -p name output as a PCM wave file");
210 System.out.println("");
211 System.out.println(" More info on http://www.javazoom.net");
212 /* System.out.println(" -f ushort use this scalefactor instead of the default value 32768");*/
213 return false;
214 }
215 };
216}; \ No newline at end of file