|
From: <to...@us...> - 2007-02-15 21:37:02
|
Revision: 70
http://techne-dev.svn.sourceforge.net/techne-dev/?rev=70&view=rev
Author: tonit
Date: 2007-02-15 13:37:01 -0800 (Thu, 15 Feb 2007)
Log Message:
-----------
transfered library to maven2/maven-bundle-plugin project because it is not listed on maven mirrors..:-(
Added Paths:
-----------
sandbox/tonit/org.javazoom.jl/.classpath
sandbox/tonit/org.javazoom.jl/.project
sandbox/tonit/org.javazoom.jl/pom.xml
sandbox/tonit/org.javazoom.jl/src/
sandbox/tonit/org.javazoom.jl/src/main/
sandbox/tonit/org.javazoom.jl/src/main/java/
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/Converter.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/RiffFile.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/WaveFile.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/WaveFileObuffer.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/jlc.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/BitReserve.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/Bitstream.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/BitstreamErrors.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/BitstreamException.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/Control.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/Crc16.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/Decoder.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/DecoderErrors.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/DecoderException.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/Equalizer.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/FrameDecoder.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/Header.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/InputStreamSource.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/JavaLayerError.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/JavaLayerErrors.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/JavaLayerException.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/JavaLayerHook.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/JavaLayerUtils.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/LayerIDecoder.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/LayerIIDecoder.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/LayerIIIDecoder.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/Manager.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/Obuffer.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/OutputChannels.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/SampleBuffer.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/Source.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/SynthesisFilter.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/au2lin.ser
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/huffcodetab.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/l3reorder.ser
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/lin2au.ser
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/readme.txt
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/sfd.ser
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/AudioDevice.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/AudioDeviceBase.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/AudioDeviceFactory.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/FactoryRegistry.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/JavaSoundAudioDevice.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/JavaSoundAudioDeviceFactory.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/NullAudioDevice.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/Player.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/PlayerApplet.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/advanced/
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/advanced/AdvancedPlayer.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/advanced/PlaybackEvent.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/advanced/PlaybackListener.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/advanced/jlap.java
sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/player/jlp.java
sandbox/tonit/org.javazoom.jl/src/test/
sandbox/tonit/org.javazoom.jl/src/test/java/
sandbox/tonit/org.javazoom.jl/src/test/java/org/
sandbox/tonit/org.javazoom.jl/src/test/java/org/javazoom/
sandbox/tonit/org.javazoom.jl/src/test/java/org/javazoom/AppTest.java
Added: sandbox/tonit/org.javazoom.jl/.classpath
===================================================================
--- sandbox/tonit/org.javazoom.jl/.classpath (rev 0)
+++ sandbox/tonit/org.javazoom.jl/.classpath 2007-02-15 21:37:01 UTC (rev 70)
@@ -0,0 +1,7 @@
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+</classpath>
\ No newline at end of file
Added: sandbox/tonit/org.javazoom.jl/.project
===================================================================
--- sandbox/tonit/org.javazoom.jl/.project (rev 0)
+++ sandbox/tonit/org.javazoom.jl/.project 2007-02-15 21:37:01 UTC (rev 70)
@@ -0,0 +1,13 @@
+<projectDescription>
+ <name>org.javazoom.jl</name>
+ <comment/>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
\ No newline at end of file
Added: sandbox/tonit/org.javazoom.jl/pom.xml
===================================================================
--- sandbox/tonit/org.javazoom.jl/pom.xml (rev 0)
+++ sandbox/tonit/org.javazoom.jl/pom.xml 2007-02-15 21:37:01 UTC (rev 70)
@@ -0,0 +1,18 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.javazoom</groupId>
+ <artifactId>org.javazoom.jl</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>org.javazoom.jl</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/Converter.java
===================================================================
--- sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/Converter.java (rev 0)
+++ sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/Converter.java 2007-02-15 21:37:01 UTC (rev 70)
@@ -0,0 +1,411 @@
+/*
+ * 11/19/04 1.0 moved to LGPL.
+ * 12/12/99 Original verion. md...@te....
+ *-----------------------------------------------------------------------
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *----------------------------------------------------------------------
+ */
+
+package javazoom.jl.converter;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+
+import javazoom.jl.decoder.Bitstream;
+import javazoom.jl.decoder.Decoder;
+import javazoom.jl.decoder.Header;
+import javazoom.jl.decoder.JavaLayerException;
+import javazoom.jl.decoder.Obuffer;
+
+/**
+ * The <code>Converter</code> class implements the conversion of
+ * an MPEG audio file to a .WAV file. To convert an MPEG audio stream,
+ * just create an instance of this class and call the convert()
+ * method, passing in the names of the input and output files. You can
+ * pass in optional <code>ProgressListener</code> and
+ * <code>Decoder.Params</code> objects also to customize the conversion.
+ *
+ * @author MDM 12/12/99
+ * @since 0.0.7
+ */
+public class Converter
+{
+ /**
+ * Creates a new converter instance.
+ */
+ public Converter()
+ {
+ }
+
+ public synchronized void convert(String sourceName, String destName)
+ throws JavaLayerException
+ {
+ convert(sourceName, destName, null, null);
+ }
+
+ public synchronized void convert(String sourceName, String destName,
+ ProgressListener progressListener)
+ throws JavaLayerException
+ {
+ convert(sourceName, destName, progressListener, null);
+ }
+
+
+ public void convert(String sourceName, String destName,
+ ProgressListener progressListener, Decoder.Params decoderParams)
+ throws JavaLayerException
+ {
+ if (destName.length()==0)
+ destName = null;
+ try {
+ InputStream in = openInput(sourceName);
+ convert(in, destName, progressListener, decoderParams);
+ in.close();
+ } catch(IOException ioe) {
+ throw new JavaLayerException(ioe.getLocalizedMessage(), ioe);
+ }
+ }
+
+ public synchronized void convert(InputStream sourceStream, String destName,
+ ProgressListener progressListener, Decoder.Params decoderParams)
+ throws JavaLayerException
+ {
+ if (progressListener==null)
+ progressListener = PrintWriterProgressListener.newStdOut(
+ PrintWriterProgressListener.NO_DETAIL);
+ try {
+ if (!(sourceStream instanceof BufferedInputStream))
+ sourceStream = new BufferedInputStream(sourceStream);
+ int frameCount = -1;
+ if (sourceStream.markSupported()) {
+ sourceStream.mark(-1);
+ frameCount = countFrames(sourceStream);
+ sourceStream.reset();
+ }
+ progressListener.converterUpdate(ProgressListener.UPDATE_FRAME_COUNT, frameCount, 0);
+
+
+ Obuffer output = null;
+ Decoder decoder = new Decoder(decoderParams);
+ Bitstream stream = new Bitstream(sourceStream);
+
+ if (frameCount==-1)
+ frameCount = Integer.MAX_VALUE;
+
+ int frame = 0;
+ long startTime = System.currentTimeMillis();
+
+ try
+ {
+ for (; frame<frameCount; frame++)
+ {
+ try
+ {
+ Header header = stream.readFrame();
+ if (header==null)
+ break;
+
+ progressListener.readFrame(frame, header);
+
+ if (output==null)
+ {
+ // REVIEW: Incorrect functionality.
+ // the decoder should provide decoded
+ // frequency and channels output as it may differ from
+ // the source (e.g. when downmixing stereo to mono.)
+ int channels = (header.mode()==Header.SINGLE_CHANNEL) ? 1 : 2;
+ int freq = header.frequency();
+ output = new WaveFileObuffer(channels, freq, destName);
+ decoder.setOutputBuffer(output);
+ }
+
+ Obuffer decoderOutput = decoder.decodeFrame(header, stream);
+
+ // REVIEW: the way the output buffer is set
+ // on the decoder is a bit dodgy. Even though
+ // this exception should never happen, we test to be sure.
+ if (decoderOutput!=output)
+ throw new InternalError("Output buffers are different.");
+
+
+ progressListener.decodedFrame(frame, header, output);
+
+ stream.closeFrame();
+
+ }
+ catch (Exception ex)
+ {
+ boolean stop = !progressListener.converterException(ex);
+
+ if (stop)
+ {
+ throw new JavaLayerException(ex.getLocalizedMessage(), ex);
+ }
+ }
+ }
+
+ }
+ finally
+ {
+
+ if (output!=null)
+ output.close();
+ }
+
+ int time = (int)(System.currentTimeMillis()-startTime);
+ progressListener.converterUpdate(ProgressListener.UPDATE_CONVERT_COMPLETE,
+ time, frame);
+ }
+ catch (IOException ex)
+ {
+ throw new JavaLayerException(ex.getLocalizedMessage(), ex);
+ }
+ }
+
+
+ protected int countFrames(InputStream in)
+ {
+ return -1;
+ }
+
+
+ protected InputStream openInput(String fileName)
+ throws IOException
+ {
+ // ensure name is abstract path name
+ File file = new File(fileName);
+ InputStream fileIn = new FileInputStream(file);
+ BufferedInputStream bufIn = new BufferedInputStream(fileIn);
+
+ return bufIn;
+ }
+
+
+ /**
+ * This interface is used by the Converter to provide
+ * notification of tasks being carried out by the converter,
+ * and to provide new information as it becomes available.
+ */
+
+ static public interface ProgressListener
+ {
+ public static final int UPDATE_FRAME_COUNT = 1;
+
+ /**
+ * Conversion is complete. Param1 contains the time
+ * to convert in milliseconds. Param2 contains the number
+ * of MPEG audio frames converted.
+ */
+ public static final int UPDATE_CONVERT_COMPLETE = 2;
+
+
+ /**
+ * Notifies the listener that new information is available.
+ *
+ * @param updateID Code indicating the information that has been
+ * updated.
+ *
+ * @param param1 Parameter whose value depends upon the update code.
+ * @param param2 Parameter whose value depends upon the update code.
+ *
+ * The <code>updateID</code> parameter can take these values:
+ *
+ * UPDATE_FRAME_COUNT: param1 is the frame count, or -1 if not known.
+ * UPDATE_CONVERT_COMPLETE: param1 is the conversion time, param2
+ * is the number of frames converted.
+ */
+ public void converterUpdate(int updateID, int param1, int param2);
+
+ /**
+ * If the converter wishes to make a first pass over the
+ * audio frames, this is called as each frame is parsed.
+ */
+ public void parsedFrame(int frameNo, Header header);
+
+ /**
+ * This method is called after each frame has been read,
+ * but before it has been decoded.
+ *
+ * @param frameNo The 0-based sequence number of the frame.
+ * @param header The Header rerpesenting the frame just read.
+ */
+ public void readFrame(int frameNo, Header header);
+
+ /**
+ * This method is called after a frame has been decoded.
+ *
+ * @param frameNo The 0-based sequence number of the frame.
+ * @param header The Header rerpesenting the frame just read.
+ * @param o The Obuffer the deocded data was written to.
+ */
+ public void decodedFrame(int frameNo, Header header, Obuffer o);
+
+ /**
+ * Called when an exception is thrown during while converting
+ * a frame.
+ *
+ * @param t The <code>Throwable</code> instance that
+ * was thrown.
+ *
+ * @return <code>true</code> to continue processing, or false
+ * to abort conversion.
+ *
+ * If this method returns <code>false</code>, the exception
+ * is propagated to the caller of the convert() method. If
+ * <code>true</code> is returned, the exception is silently
+ * ignored and the converter moves onto the next frame.
+ */
+ public boolean converterException(Throwable t);
+
+ }
+
+
+ /**
+ * Implementation of <code>ProgressListener</code> that writes
+ * notification text to a <code>PrintWriter</code>.
+ */
+ // REVIEW: i18n of text and order required.
+ static public class PrintWriterProgressListener implements ProgressListener
+ {
+ static public final int NO_DETAIL = 0;
+
+ /**
+ * Level of detail typically expected of expert
+ * users.
+ */
+ static public final int EXPERT_DETAIL = 1;
+
+ /**
+ * Verbose detail.
+ */
+ static public final int VERBOSE_DETAIL = 2;
+
+ /**
+ * Debug detail. All frame read notifications are shown.
+ */
+ static public final int DEBUG_DETAIL = 7;
+
+ static public final int MAX_DETAIL = 10;
+
+ private PrintWriter pw;
+
+ private int detailLevel;
+
+ static public PrintWriterProgressListener newStdOut(int detail)
+ {
+ return new PrintWriterProgressListener(
+ new PrintWriter(System.out, true), detail);
+ }
+
+ public PrintWriterProgressListener(PrintWriter writer, int detailLevel)
+ {
+ this.pw = writer;
+ this.detailLevel = detailLevel;
+ }
+
+
+ public boolean isDetail(int detail)
+ {
+ return (this.detailLevel >= detail);
+ }
+
+ public void converterUpdate(int updateID, int param1, int param2)
+ {
+ if (isDetail(VERBOSE_DETAIL))
+ {
+ switch (updateID)
+ {
+ case UPDATE_CONVERT_COMPLETE:
+ // catch divide by zero errors.
+ if (param2==0)
+ param2 = 1;
+
+ pw.println();
+ pw.println("Converted "+param2+" frames in "+param1+" ms ("+
+ (param1/param2)+" ms per frame.)");
+ }
+ }
+ }
+
+ public void parsedFrame(int frameNo, Header header)
+ {
+ if ((frameNo==0) && isDetail(VERBOSE_DETAIL))
+ {
+ String headerString = header.toString();
+ pw.println("File is a "+headerString);
+ }
+ else if (isDetail(MAX_DETAIL))
+ {
+ String headerString = header.toString();
+ pw.println("Prased frame "+frameNo+": "+headerString);
+ }
+ }
+
+ public void readFrame(int frameNo, Header header)
+ {
+ if ((frameNo==0) && isDetail(VERBOSE_DETAIL))
+ {
+ String headerString = header.toString();
+ pw.println("File is a "+headerString);
+ }
+ else if (isDetail(MAX_DETAIL))
+ {
+ String headerString = header.toString();
+ pw.println("Read frame "+frameNo+": "+headerString);
+ }
+ }
+
+ public void decodedFrame(int frameNo, Header header, Obuffer o)
+ {
+ if (isDetail(MAX_DETAIL))
+ {
+ String headerString = header.toString();
+ pw.println("Decoded frame "+frameNo+": "+headerString);
+ pw.println("Output: "+o);
+ }
+ else if (isDetail(VERBOSE_DETAIL))
+ {
+ if (frameNo==0)
+ {
+ pw.print("Converting.");
+ pw.flush();
+ }
+
+ if ((frameNo % 10)==0)
+ {
+ pw.print('.');
+ pw.flush();
+ }
+ }
+ }
+
+ public boolean converterException(Throwable t)
+ {
+ if (this.detailLevel>NO_DETAIL)
+ {
+ t.printStackTrace(pw);
+ pw.flush();
+ }
+ return false;
+ }
+
+ }
+
+
+}
\ No newline at end of file
Added: sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/RiffFile.java
===================================================================
--- sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/RiffFile.java (rev 0)
+++ sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/RiffFile.java 2007-02-15 21:37:01 UTC (rev 70)
@@ -0,0 +1,495 @@
+/*
+ * 11/19/04 1.0 moved to LGPL.
+ * 02/23/99 JavaConversion by E.B
+ * Don Cross, April 1993.
+ * RIFF file format classes.
+ * See Chapter 8 of "Multimedia Programmer's Reference" in
+ * the Microsoft Windows SDK.
+ *
+ *-----------------------------------------------------------------------
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *----------------------------------------------------------------------
+ */
+
+package javazoom.jl.converter;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+
+/**
+ * Class to manage RIFF files
+ */
+public class RiffFile
+{
+ class RiffChunkHeader
+ {
+ public int ckID = 0; // Four-character chunk ID
+ public int ckSize = 0; // Length of data in chunk
+ public RiffChunkHeader()
+ {}
+ }
+
+
+ // DDCRET
+ public static final int DDC_SUCCESS = 0; // The operation succeded
+ public static final int DDC_FAILURE = 1; // The operation failed for unspecified reasons
+ public static final int DDC_OUT_OF_MEMORY = 2; // Operation failed due to running out of memory
+ public static final int DDC_FILE_ERROR = 3; // Operation encountered file I/O error
+ public static final int DDC_INVALID_CALL = 4; // Operation was called with invalid parameters
+ public static final int DDC_USER_ABORT = 5; // Operation was aborted by the user
+ public static final int DDC_INVALID_FILE = 6; // File format does not match
+
+ // RiffFileMode
+ public static final int RFM_UNKNOWN = 0; // undefined type (can use to mean "N/A" or "not open")
+ public static final int RFM_WRITE = 1; // open for write
+ public static final int RFM_READ = 2; // open for read
+
+ private RiffChunkHeader riff_header; // header for whole file
+ protected int fmode; // current file I/O mode
+ protected RandomAccessFile file; // I/O stream to use
+
+ /**
+ * Dummy Constructor
+ */
+ public RiffFile()
+ {
+ file = null;
+ fmode = RFM_UNKNOWN;
+ riff_header = new RiffChunkHeader();
+
+ riff_header.ckID = FourCC("RIFF");
+ riff_header.ckSize = 0;
+ }
+
+ /**
+ * Return File Mode.
+ */
+ public int CurrentFileMode()
+ {return fmode;}
+
+ /**
+ * Open a RIFF file.
+ */
+ public int Open(String Filename, int NewMode)
+ {
+ int retcode = DDC_SUCCESS;
+
+ if ( fmode != RFM_UNKNOWN )
+ {
+ retcode = Close();
+ }
+
+ if ( retcode == DDC_SUCCESS )
+ {
+ switch ( NewMode )
+ {
+ case RFM_WRITE:
+ try
+ {
+ file = new RandomAccessFile(Filename,"rw");
+
+ try
+ {
+ // Write the RIFF header...
+ // We will have to come back later and patch it!
+ byte[] br = new byte[8];
+ br[0] = (byte) ((riff_header.ckID >>> 24) & 0x000000FF);
+ br[1] = (byte) ((riff_header.ckID >>> 16) & 0x000000FF);
+ br[2] = (byte) ((riff_header.ckID >>> 8) & 0x000000FF);
+ br[3] = (byte) (riff_header.ckID & 0x000000FF);
+
+ byte br4 = (byte) ((riff_header.ckSize >>> 24)& 0x000000FF);
+ byte br5 = (byte) ((riff_header.ckSize >>> 16)& 0x000000FF);
+ byte br6 = (byte) ((riff_header.ckSize >>> 8)& 0x000000FF);
+ byte br7 = (byte) (riff_header.ckSize & 0x000000FF);
+
+ br[4] = br7;
+ br[5] = br6;
+ br[6] = br5;
+ br[7] = br4;
+
+ file.write(br,0,8);
+ fmode = RFM_WRITE;
+ } catch (IOException ioe)
+ {
+ file.close();
+ fmode = RFM_UNKNOWN;
+ }
+ } catch (IOException ioe)
+ {
+ fmode = RFM_UNKNOWN;
+ retcode = DDC_FILE_ERROR;
+ }
+ break;
+
+ case RFM_READ:
+ try
+ {
+ file = new RandomAccessFile(Filename,"r");
+ try
+ {
+ // Try to read the RIFF header...
+ byte[] br = new byte[8];
+ file.read(br,0,8);
+ fmode = RFM_READ;
+ riff_header.ckID = ((br[0]<<24)& 0xFF000000) | ((br[1]<<16)&0x00FF0000) | ((br[2]<<8)&0x0000FF00) | (br[3]&0x000000FF);
+ riff_header.ckSize = ((br[4]<<24)& 0xFF000000) | ((br[5]<<16)&0x00FF0000) | ((br[6]<<8)&0x0000FF00) | (br[7]&0x000000FF);
+ } catch (IOException ioe)
+ {
+ file.close();
+ fmode = RFM_UNKNOWN;
+ }
+ } catch (IOException ioe)
+ {
+ fmode = RFM_UNKNOWN;
+ retcode = DDC_FILE_ERROR;
+ }
+ break;
+ default:
+ retcode = DDC_INVALID_CALL;
+ }
+ }
+ return retcode;
+ }
+
+ /**
+ * Write NumBytes data.
+ */
+ public int Write(byte[] Data, int NumBytes )
+ {
+ if ( fmode != RFM_WRITE )
+ {
+ return DDC_INVALID_CALL;
+ }
+ try
+ {
+ file.write(Data,0,NumBytes);
+ fmode = RFM_WRITE;
+ }
+ catch (IOException ioe)
+ {
+ return DDC_FILE_ERROR;
+ }
+ riff_header.ckSize += NumBytes;
+ return DDC_SUCCESS;
+ }
+
+
+
+ /**
+ * Write NumBytes data.
+ */
+ public int Write(short[] Data, int NumBytes )
+ {
+ byte[] theData = new byte[NumBytes];
+ int yc = 0;
+ for (int y = 0;y<NumBytes;y=y+2)
+ {
+ theData[y] = (byte) (Data[yc] & 0x00FF);
+ theData[y+1] =(byte) ((Data[yc++] >>> 8) & 0x00FF);
+ }
+ if ( fmode != RFM_WRITE )
+ {
+ return DDC_INVALID_CALL;
+ }
+ try
+ {
+ file.write(theData,0,NumBytes);
+ fmode = RFM_WRITE;
+ }
+ catch (IOException ioe)
+ {
+ return DDC_FILE_ERROR;
+ }
+ riff_header.ckSize += NumBytes;
+ return DDC_SUCCESS;
+ }
+
+ /**
+ * Write NumBytes data.
+ */
+ public int Write(RiffChunkHeader Triff_header, int NumBytes )
+ {
+ byte[] br = new byte[8];
+ br[0] = (byte) ((Triff_header.ckID >>> 24) & 0x000000FF);
+ br[1] = (byte) ((Triff_header.ckID >>> 16) & 0x000000FF);
+ br[2] = (byte) ((Triff_header.ckID >>> 8) & 0x000000FF);
+ br[3] = (byte) (Triff_header.ckID & 0x000000FF);
+
+ byte br4 = (byte) ((Triff_header.ckSize >>> 24)& 0x000000FF);
+ byte br5 = (byte) ((Triff_header.ckSize >>> 16)& 0x000000FF);
+ byte br6 = (byte) ((Triff_header.ckSize >>> 8)& 0x000000FF);
+ byte br7 = (byte) (Triff_header.ckSize & 0x000000FF);
+
+ br[4] = br7;
+ br[5] = br6;
+ br[6] = br5;
+ br[7] = br4;
+
+ if ( fmode != RFM_WRITE )
+ {
+ return DDC_INVALID_CALL;
+ }
+ try
+ {
+ file.write(br,0,NumBytes);
+ fmode = RFM_WRITE;
+ } catch (IOException ioe)
+ {
+ return DDC_FILE_ERROR;
+ }
+ riff_header.ckSize += NumBytes;
+ return DDC_SUCCESS;
+ }
+
+ /**
+ * Write NumBytes data.
+ */
+ public int Write(short Data, int NumBytes )
+ {
+ short theData = (short) ( ((Data>>>8)&0x00FF) | ((Data<<8)&0xFF00) );
+ if ( fmode != RFM_WRITE )
+ {
+ return DDC_INVALID_CALL;
+ }
+ try
+ {
+ file.writeShort(theData);
+ fmode = RFM_WRITE;
+ } catch (IOException ioe)
+ {
+ return DDC_FILE_ERROR;
+ }
+ riff_header.ckSize += NumBytes;
+ return DDC_SUCCESS;
+ }
+ /**
+ * Write NumBytes data.
+ */
+ public int Write(int Data, int NumBytes )
+ {
+ short theDataL = (short) ((Data>>>16)&0x0000FFFF);
+ short theDataR = (short) (Data&0x0000FFFF);
+ short theDataLI = (short) ( ((theDataL>>>8)&0x00FF) | ((theDataL<<8)&0xFF00) );
+ short theDataRI = (short) ( ((theDataR>>>8)&0x00FF) | ((theDataR<<8)&0xFF00) );
+ int theData = ((theDataRI<<16)&0xFFFF0000) | (theDataLI&0x0000FFFF);
+ if ( fmode != RFM_WRITE )
+ {
+ return DDC_INVALID_CALL;
+ }
+ try
+ {
+ file.writeInt(theData);
+ fmode = RFM_WRITE;
+ } catch (IOException ioe)
+ {
+ return DDC_FILE_ERROR;
+ }
+ riff_header.ckSize += NumBytes;
+ return DDC_SUCCESS;
+ }
+
+
+
+ /**
+ * Read NumBytes data.
+ */
+ public int Read (byte[] Data, int NumBytes)
+ {
+ int retcode = DDC_SUCCESS;
+ try
+ {
+ file.read(Data,0,NumBytes);
+ } catch (IOException ioe)
+ {
+ retcode = DDC_FILE_ERROR;
+ }
+ return retcode;
+ }
+
+ /**
+ * Expect NumBytes data.
+ */
+ public int Expect(String Data, int NumBytes )
+ {
+ byte target = 0;
+ int cnt = 0;
+ try
+ {
+ while ((NumBytes--) != 0)
+ {
+ target = file.readByte();
+ if (target != Data.charAt(cnt++)) return DDC_FILE_ERROR;
+ }
+ } catch (IOException ioe)
+ {
+ return DDC_FILE_ERROR;
+ }
+ return DDC_SUCCESS;
+ }
+
+ /**
+ * Close Riff File.
+ * Length is written too.
+ */
+ public int Close()
+ {
+ int retcode = DDC_SUCCESS;
+
+ switch ( fmode )
+ {
+ case RFM_WRITE:
+ try
+ {
+ file.seek(0);
+ try
+ {
+ byte[] br = new byte[8];
+ br[0] = (byte) ((riff_header.ckID >>> 24) & 0x000000FF);
+ br[1] = (byte) ((riff_header.ckID >>> 16) & 0x000000FF);
+ br[2] = (byte) ((riff_header.ckID >>> 8) & 0x000000FF);
+ br[3] = (byte) (riff_header.ckID & 0x000000FF);
+
+ br[7] = (byte) ((riff_header.ckSize >>> 24)& 0x000000FF);
+ br[6] = (byte) ((riff_header.ckSize >>> 16)& 0x000000FF);
+ br[5] = (byte) ((riff_header.ckSize >>> 8)& 0x000000FF);
+ br[4] = (byte) (riff_header.ckSize & 0x000000FF);
+ file.write(br,0,8);
+ file.close();
+ } catch (IOException ioe)
+ {
+ retcode = DDC_FILE_ERROR;
+ }
+ } catch (IOException ioe)
+ {
+ retcode = DDC_FILE_ERROR;
+ }
+ break;
+
+ case RFM_READ:
+ try
+ {
+ file.close();
+ } catch (IOException ioe)
+ {
+ retcode = DDC_FILE_ERROR;
+ }
+ break;
+ }
+ file = null;
+ fmode = RFM_UNKNOWN;
+ return retcode;
+ }
+
+ /**
+ * Return File Position.
+ */
+ public long CurrentFilePosition()
+ {
+ long position;
+ try
+ {
+ position = file.getFilePointer();
+ } catch (IOException ioe)
+ {
+ position = -1;
+ }
+ return position;
+ }
+
+ /**
+ * Write Data to specified offset.
+ */
+ public int Backpatch (long FileOffset, RiffChunkHeader Data, int NumBytes )
+ {
+ if (file == null)
+ {
+ return DDC_INVALID_CALL;
+ }
+ try
+ {
+ file.seek(FileOffset);
+ } catch (IOException ioe)
+ {
+ return DDC_FILE_ERROR;
+ }
+ return Write ( Data, NumBytes );
+ }
+
+ public int Backpatch (long FileOffset, byte[] Data, int NumBytes )
+ {
+ if (file == null)
+ {
+ return DDC_INVALID_CALL;
+ }
+ try
+ {
+ file.seek(FileOffset);
+ } catch (IOException ioe)
+ {
+ return DDC_FILE_ERROR;
+ }
+ return Write ( Data, NumBytes );
+ }
+
+
+ /**
+ * Seek in the File.
+ */
+ protected int Seek(long offset)
+ {
+ int rc;
+ try
+ {
+ file.seek(offset);
+ rc = DDC_SUCCESS;
+ } catch (IOException ioe)
+ {
+ rc = DDC_FILE_ERROR;
+ }
+ return rc;
+ }
+
+ /**
+ * Error Messages.
+ */
+ private String DDCRET_String(int retcode)
+ {
+ switch ( retcode )
+ {
+ case DDC_SUCCESS: return "DDC_SUCCESS";
+ case DDC_FAILURE: return "DDC_FAILURE";
+ case DDC_OUT_OF_MEMORY: return "DDC_OUT_OF_MEMORY";
+ case DDC_FILE_ERROR: return "DDC_FILE_ERROR";
+ case DDC_INVALID_CALL: return "DDC_INVALID_CALL";
+ case DDC_USER_ABORT: return "DDC_USER_ABORT";
+ case DDC_INVALID_FILE: return "DDC_INVALID_FILE";
+ }
+ return "Unknown Error";
+ }
+
+ /**
+ * Fill the header.
+ */
+ public static int FourCC(String ChunkName)
+ {
+ byte[] p = {0x20,0x20,0x20,0x20};
+ ChunkName.getBytes(0,4,p,0);
+ int ret = (((p[0] << 24)& 0xFF000000) | ((p[1] << 16)&0x00FF0000) | ((p[2] << 8)&0x0000FF00) | (p[3]&0x000000FF));
+ return ret;
+ }
+
+}
Added: sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/WaveFile.java
===================================================================
--- sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/WaveFile.java (rev 0)
+++ sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/WaveFile.java 2007-02-15 21:37:01 UTC (rev 70)
@@ -0,0 +1,522 @@
+/*
+ * 11/19/04 1.0 moved to LGPL.
+ * 02/23/99 JavaConversion by E.B
+ * Don Cross, April 1993.
+ * RIFF file format classes.
+ * See Chapter 8 of "Multimedia Programmer's Reference" in
+ * the Microsoft Windows SDK.
+ *
+ *-----------------------------------------------------------------------
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *----------------------------------------------------------------------
+ */
+
+package javazoom.jl.converter;
+
+/**
+ * Class allowing WaveFormat Access
+ */
+public class WaveFile extends RiffFile
+{
+ public static final int MAX_WAVE_CHANNELS = 2;
+
+ class WaveFormat_ChunkData
+ {
+ public short wFormatTag = 0; // Format category (PCM=1)
+ public short nChannels = 0; // Number of channels (mono=1, stereo=2)
+ public int nSamplesPerSec = 0; // Sampling rate [Hz]
+ public int nAvgBytesPerSec = 0;
+ public short nBlockAlign = 0;
+ public short nBitsPerSample = 0;
+
+ public WaveFormat_ChunkData()
+ {
+ wFormatTag = 1; // PCM
+ Config(44100,(short)16,(short)1);
+ }
+
+ public void Config (int NewSamplingRate, short NewBitsPerSample, short NewNumChannels)
+ {
+ nSamplesPerSec = NewSamplingRate;
+ nChannels = NewNumChannels;
+ nBitsPerSample = NewBitsPerSample;
+ nAvgBytesPerSec = (nChannels * nSamplesPerSec * nBitsPerSample) / 8;
+ nBlockAlign = (short) ((nChannels * nBitsPerSample) / 8);
+ }
+ }
+
+
+ class WaveFormat_Chunk
+ {
+ public RiffChunkHeader header;
+ public WaveFormat_ChunkData data;
+
+ public WaveFormat_Chunk()
+ {
+ header = new RiffChunkHeader();
+ data = new WaveFormat_ChunkData();
+ header.ckID = FourCC("fmt ");
+ header.ckSize = 16;
+ }
+
+ public int VerifyValidity()
+ {
+ boolean ret = header.ckID == FourCC("fmt ") &&
+
+ (data.nChannels == 1 || data.nChannels == 2) &&
+
+ data.nAvgBytesPerSec == ( data.nChannels *
+ data.nSamplesPerSec *
+ data.nBitsPerSample ) / 8 &&
+
+ data.nBlockAlign == ( data.nChannels *
+ data.nBitsPerSample ) / 8;
+ if (ret == true) return 1;
+ else return 0;
+ }
+ }
+
+ public class WaveFileSample
+ {
+ public short[] chan;
+
+ public WaveFileSample()
+ {chan = new short[WaveFile.MAX_WAVE_CHANNELS];}
+ }
+
+ private WaveFormat_Chunk wave_format;
+ private RiffChunkHeader pcm_data;
+ private long pcm_data_offset = 0; // offset of 'pcm_data' in output file
+ private int num_samples = 0;
+
+
+ /**
+ * Constructs a new WaveFile instance.
+ */
+ public WaveFile()
+ {
+ pcm_data = new RiffChunkHeader();
+ wave_format = new WaveFormat_Chunk();
+ pcm_data.ckID = FourCC("data");
+ pcm_data.ckSize = 0;
+ num_samples = 0;
+ }
+
+ /**
+ *
+ *
+ public int OpenForRead (String Filename)
+ {
+ // Verify filename parameter as best we can...
+ if (Filename == null)
+ {
+ return DDC_INVALID_CALL;
+ }
+ int retcode = Open ( Filename, RFM_READ );
+
+ if ( retcode == DDC_SUCCESS )
+ {
+ retcode = Expect ( "WAVE", 4 );
+
+ if ( retcode == DDC_SUCCESS )
+ {
+ retcode = Read(wave_format,24);
+
+ if ( retcode == DDC_SUCCESS && !wave_format.VerifyValidity() )
+ {
+ // This isn't standard PCM, so we don't know what it is!
+ retcode = DDC_FILE_ERROR;
+ }
+
+ if ( retcode == DDC_SUCCESS )
+ {
+ pcm_data_offset = CurrentFilePosition();
+
+ // Figure out number of samples from
+ // file size, current file position, and
+ // WAVE header.
+ retcode = Read (pcm_data, 8 );
+ num_samples = filelength(fileno(file)) - CurrentFilePosition();
+ num_samples /= NumChannels();
+ num_samples /= (BitsPerSample() / 8);
+ }
+ }
+ }
+ return retcode;
+ }*/
+
+ /**
+ *
+ */
+ public int OpenForWrite (String Filename, int SamplingRate, short BitsPerSample, short NumChannels)
+ {
+ // Verify parameters...
+ if ( (Filename==null) ||
+ (BitsPerSample != 8 && BitsPerSample != 16) ||
+ NumChannels < 1 || NumChannels > 2 )
+ {
+ return DDC_INVALID_CALL;
+ }
+
+ wave_format.data.Config ( SamplingRate, BitsPerSample, NumChannels );
+
+ int retcode = Open ( Filename, RFM_WRITE );
+
+ if ( retcode == DDC_SUCCESS )
+ {
+ byte [] theWave = {(byte)'W',(byte)'A',(byte)'V',(byte)'E'};
+ retcode = Write ( theWave, 4 );
+
+ if ( retcode == DDC_SUCCESS )
+ {
+ // Ecriture de wave_format
+ retcode = Write (wave_format.header, 8);
+ retcode = Write (wave_format.data.wFormatTag, 2);
+ retcode = Write (wave_format.data.nChannels, 2);
+ retcode = Write (wave_format.data.nSamplesPerSec, 4);
+ retcode = Write (wave_format.data.nAvgBytesPerSec, 4);
+ retcode = Write (wave_format.data.nBlockAlign, 2);
+ retcode = Write (wave_format.data.nBitsPerSample, 2);
+ /* byte[] br = new byte[16];
+ br[0] = (byte) ((wave_format.data.wFormatTag >> 8) & 0x00FF);
+ br[1] = (byte) (wave_format.data.wFormatTag & 0x00FF);
+
+ br[2] = (byte) ((wave_format.data.nChannels >> 8) & 0x00FF);
+ br[3] = (byte) (wave_format.data.nChannels & 0x00FF);
+
+ br[4] = (byte) ((wave_format.data.nSamplesPerSec >> 24)& 0x000000FF);
+ br[5] = (byte) ((wave_format.data.nSamplesPerSec >> 16)& 0x000000FF);
+ br[6] = (byte) ((wave_format.data.nSamplesPerSec >> 8)& 0x000000FF);
+ br[7] = (byte) (wave_format.data.nSamplesPerSec & 0x000000FF);
+
+ br[8] = (byte) ((wave_format.data.nAvgBytesPerSec>> 24)& 0x000000FF);
+ br[9] = (byte) ((wave_format.data.nAvgBytesPerSec >> 16)& 0x000000FF);
+ br[10] = (byte) ((wave_format.data.nAvgBytesPerSec >> 8)& 0x000000FF);
+ br[11] = (byte) (wave_format.data.nAvgBytesPerSec & 0x000000FF);
+
+ br[12] = (byte) ((wave_format.data.nBlockAlign >> 8) & 0x00FF);
+ br[13] = (byte) (wave_format.data.nBlockAlign & 0x00FF);
+
+ br[14] = (byte) ((wave_format.data.nBitsPerSample >> 8) & 0x00FF);
+ br[15] = (byte) (wave_format.data.nBitsPerSample & 0x00FF);
+ retcode = Write (br, 16); */
+
+
+ if ( retcode == DDC_SUCCESS )
+ {
+ pcm_data_offset = CurrentFilePosition();
+ retcode = Write ( pcm_data, 8 );
+ }
+ }
+ }
+
+ return retcode;
+ }
+
+ /**
+ *
+ *
+ public int ReadSample ( short[] Sample )
+ {
+
+ }*/
+
+ /**
+ *
+ *
+ public int WriteSample( short[] Sample )
+ {
+ int retcode = DDC_SUCCESS;
+ switch ( wave_format.data.nChannels )
+ {
+ case 1:
+ switch ( wave_format.data.nBitsPerSample )
+ {
+ case 8:
+ pcm_data.ckSize += 1;
+ retcode = Write ( Sample, 1 );
+ break;
+
+ case 16:
+ pcm_data.ckSize += 2;
+ retcode = Write ( Sample, 2 );
+ break;
+
+ default:
+ retcode = DDC_INVALID_CALL;
+ }
+ break;
+
+ case 2:
+ switch ( wave_format.data.nBitsPerSample )
+ {
+ case 8:
+ retcode = Write ( Sample, 1 );
+ if ( retcode == DDC_SUCCESS )
+ {
+ // &Sample[1]
+ retcode = Write (Sample, 1 );
+ if ( retcode == DDC_SUCCESS )
+ {
+ pcm_data.ckSize += 2;
+ }
+ }
+ break;
+
+ case 16:
+ retcode = Write ( Sample, 2 );
+ if ( retcode == DDC_SUCCESS )
+ {
+ // &Sample[1]
+ retcode = Write (Sample, 2 );
+ if ( retcode == DDC_SUCCESS )
+ {
+ pcm_data.ckSize += 4;
+ }
+ }
+ break;
+
+ default:
+ retcode = DDC_INVALID_CALL;
+ }
+ break;
+
+ default:
+ retcode = DDC_INVALID_CALL;
+ }
+
+ return retcode;
+ }*/
+
+ /**
+ *
+ *
+ public int SeekToSample ( long SampleIndex )
+ {
+ if ( SampleIndex >= NumSamples() )
+ {
+ return DDC_INVALID_CALL;
+ }
+ int SampleSize = (BitsPerSample() + 7) / 8;
+ int rc = Seek ( pcm_data_offset + 8 +
+ SampleSize * NumChannels() * SampleIndex );
+ return rc;
+ }*/
+
+ /**
+ * Write 16-bit audio
+ */
+ public int WriteData ( short[] data, int numData )
+ {
+ int extraBytes = numData * 2;
+ pcm_data.ckSize += extraBytes;
+ return super.Write ( data, extraBytes );
+ }
+
+ /**
+ * Read 16-bit audio.
+ *
+ public int ReadData (short[] data, int numData)
+ {return super.Read ( data, numData * 2);} */
+
+ /**
+ * Write 8-bit audio.
+ *
+ public int WriteData ( byte[] data, int numData )
+ {
+ pcm_data.ckSize += numData;
+ return super.Write ( data, numData );
+ }*/
+
+ /**
+ * Read 8-bit audio.
+ *
+ public int ReadData ( byte[] data, int numData )
+ {return super.Read ( data, numData );} */
+
+
+ /**
+ *
+ *
+ public int ReadSamples (int num, int [] WaveFileSample)
+ {
+
+ }*/
+
+ /**
+ *
+ *
+ public int WriteMonoSample ( short[] SampleData )
+ {
+ switch ( wave_format.data.nBitsPerSample )
+ {
+ case 8:
+ pcm_data.ckSize += 1;
+ return Write ( SampleData, 1 );
+
+ case 16:
+ pcm_data.ckSize += 2;
+ return Write ( SampleData, 2 );
+ }
+ return DDC_INVALID_CALL;
+ }*/
+
+ /**
+ *
+ *
+ public int WriteStereoSample ( short[] LeftSample, short[] RightSample )
+ {
+ int retcode = DDC_SUCCESS;
+ switch ( wave_format.data.nBitsPerSample )
+ {
+ case 8:
+ retcode = Write ( LeftSample, 1 );
+ if ( retcode == DDC_SUCCESS )
+ {
+ retcode = Write ( RightSample, 1 );
+ if ( retcode == DDC_SUCCESS )
+ {
+ pcm_data.ckSize += 2;
+ }
+ }
+ break;
+
+ case 16:
+ retcode = Write ( LeftSample, 2 );
+ if ( retcode == DDC_SUCCESS )
+ {
+ retcode = Write ( RightSample, 2 );
+ if ( retcode == DDC_SUCCESS )
+ {
+ pcm_data.ckSize += 4;
+ }
+ }
+ break;
+
+ default:
+ retcode = DDC_INVALID_CALL;
+ }
+ return retcode;
+ }*/
+
+ /**
+ *
+ *
+ public int ReadMonoSample ( short[] Sample )
+ {
+ int retcode = DDC_SUCCESS;
+ switch ( wave_format.data.nBitsPerSample )
+ {
+ case 8:
+ byte[] x = {0};
+ retcode = Read ( x, 1 );
+ Sample[0] = (short)(x[0]);
+ break;
+
+ case 16:
+ retcode = Read ( Sample, 2 );
+ break;
+
+ default:
+ retcode = DDC_INVALID_CALL;
+ }
+ return retcode;
+ }*/
+
+ /**
+ *
+ *
+ public int ReadStereoSample ( short[] LeftSampleData, short[] RightSampleData )
+ {
+ int retcode = DDC_SUCCESS;
+ byte[] x = new byte[2];
+ short[] y = new short[2];
+ switch ( wave_format.data.nBitsPerSample )
+ {
+ case 8:
+ retcode = Read ( x, 2 );
+ L[0] = (short) ( x[0] );
+ R[0] = (short) ( x[1] );
+ break;
+
+ case 16:
+ retcode = Read ( y, 4 );
+ L[0] = (short) ( y[0] );
+ R[0] = (short) ( y[1] );
+ break;
+
+ default:
+ retcode = DDC_INVALID_CALL;
+ }
+ return retcode;
+ }*/
+
+
+ /**
+ *
+ */
+ public int Close()
+ {
+ int rc = DDC_SUCCESS;
+
+ if ( fmode == RFM_WRITE )
+ rc = Backpatch ( pcm_data_offset, pcm_data, 8 );
+ if ( rc == DDC_SUCCESS )
+ rc = super.Close();
+ return rc;
+ }
+
+ // [Hz]
+ public int SamplingRate()
+ {return wave_format.data.nSamplesPerSec;}
+
+ public short BitsPerSample()
+ {return wave_format.data.nBitsPerSample;}
+
+ public short NumChannels()
+ {return wave_format.data.nChannels;}
+
+ public int NumSamples()
+ {return num_samples;}
+
+
+ /**
+ * Open for write using another wave file's parameters...
+ */
+ public int OpenForWrite (String Filename, WaveFile OtherWave )
+ {
+ return OpenForWrite ( Filename,
+ OtherWave.SamplingRate(),
+ OtherWave.BitsPerSample(),
+ OtherWave.NumChannels() );
+ }
+
+ /**
+ *
+ */
+ public long CurrentFilePosition()
+ {
+ return super.CurrentFilePosition();
+ }
+
+ /* public int FourCC(String ChunkName)
+ {
+ byte[] p = {0x20,0x20,0x20,0x20};
+ ChunkName.getBytes(0,4,p,0);
+ int ret = (((p[0] << 24)& 0xFF000000) | ((p[1] << 16)&0x00FF0000) | ((p[2] << 8)&0x0000FF00) | (p[3]&0x000000FF));
+ return ret;
+ }*/
+
+}
\ No newline at end of file
Added: sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/WaveFileObuffer.java
===================================================================
--- sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/WaveFileObuffer.java (rev 0)
+++ sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/WaveFileObuffer.java 2007-02-15 21:37:01 UTC (rev 70)
@@ -0,0 +1,141 @@
+/*
+ * 11/19/04 1.0 moved to LGPL.
+ *
+ * 12/12/99 0.0.7 Renamed class, additional constructor arguments
+ * and larger write buffers. md...@te....
+ *
+ * 15/02/99 Java Conversion by E.B ,jav...@ja...
+ *
+ *-----------------------------------------------------------------------
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *----------------------------------------------------------------------
+ */
+
+package javazoom.jl.converter;
+
+import javazoom.jl.decoder.Obuffer;
+
+/**
+ * Implements an Obuffer by writing the data to
+ * a file in RIFF WAVE format.
+ *
+ * @since 0.0
+ */
+
+
+public class WaveFileObuffer extends Obuffer
+{
+ private short[] buffer;
+ private short[] bufferp;
+ private int channels;
+ private WaveFile outWave;
+
+ /**
+ * Creates a new WareFileObuffer instance.
+ *
+ * @param number_of_channels
+ * The number of channels of audio data
+ * this buffer will receive.
+ *
+ * @param freq The sample frequency of the samples in the buffer.
+ *
+ * @param fileName The filename to write the data to.
+ */
+ public WaveFileObuffer(int number_of_channels, int freq, String FileName)
+ {
+ if (FileName==null)
+ throw new NullPointerException("FileName");
+
+ buffer = new short[OBUFFERSIZE];
+ bufferp = new short[MAXCHANNELS];
+ channels = number_of_channels;
+
+ for (int i = 0; i < number_of_channels; ++i)
+ bufferp[i] = (short)i;
+
+ outWave = new WaveFile();
+
+ int rc = outWave.OpenForWrite (FileName,freq,(short)16,(short)channels);
+ }
+
+ /**
+ * Takes a 16 Bit PCM sample.
+ */
+ public void append(int channel, short value)
+ {
+ buffer[bufferp[channel]] = value;
+ bufferp[channel] += channels;
+ }
+
+ /**
+ * Write the samples to the file (Random Acces).
+ */
+ short[] myBuffer = new short[2];
+ public void write_buffer(int val)
+ {
+
+ int k = 0;
+ int rc = 0;
+
+ rc = outWave.WriteData(buffer, bufferp[0]);
+ // REVIEW: handle RiffFile errors.
+ /*
+ for (int j=0;j<bufferp[0];j=j+2)
+ {
+
+ //myBuffer[0] = (short)(((buffer[j]>>8)&0x000000FF) | ((buffer[j]<<8)&0x0000FF00));
+ //myBuffer[1] = (short) (((buffer[j+1]>>8)&0x000000FF) | ((buffer[j+1]<<8)&0x0000FF00));
+ myBuffer[0] = buffer[j];
+ myBuffer[1] = buffer[j+1];
+ rc = outWave.WriteData (myBuffer,2);
+ }
+ */
+ for (int i = 0; i < channels; ++i) bufferp[i] = (short)i;
+ }
+
+ public void close()
+ {
+ outWave.Close();
+ }
+
+ /**
+ *
+ */
+ public void clear_buffer()
+ {}
+
+ /**
+ *
+ */
+ public void set_stop_flag()
+ {}
+
+ /*
+ * Create STDOUT buffer
+ *
+ *
+ public static Obuffer create_stdout_obuffer(MPEG_Args maplay_args)
+ {
+ Obuffer thebuffer = null;
+ int mode = maplay_args.MPEGheader.mode();
+ int which_channels = maplay_args.which_c;
+ if (mode == Header.single_channel || which_channels != MPEG_Args.both)
+ thebuffer = new FileObuffer(1,maplay_args.output_filename);
+ else
+ thebuffer = new FileObuffer(2,maplay_args.output_filename);
+ return(thebuffer);
+ }
+ */
+}
Added: sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/jlc.java
===================================================================
--- sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/jlc.java (rev 0)
+++ sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/converter/jlc.java 2007-02-15 21:37:01 UTC (rev 70)
@@ -0,0 +1,216 @@
+/*
+ * 11/19/04 1.0 moved to LGPL.
+ *
+ * 29/01/00 Initial version. md...@te...
+ *
+ * 12/12/99 JavaLayer 0.0.7 md...@te...
+ *
+ * 14/02/99 MPEG_Args Based Class - E.B
+ * Adapted from javalayer and MPEG_Args.
+ * Doc'ed and integerated with JL converter. Removed
+ * Win32 specifics from original Maplay code.
+ *-----------------------------------------------------------------------
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *----------------------------------------------------------------------
+ */
+
+package javazoom.jl.converter;
+
+import java.io.PrintWriter;
+
+import javazoom.jl.decoder.Crc16;
+import javazoom.jl.decoder.JavaLayerException;
+import javazoom.jl.decoder.OutputChannels;
+
+/**
+ * The <code>jlc</code> class presents the JavaLayer
+ * Conversion functionality as a command-line program.
+ *
+ * @since 0.0.7
+ */
+public class jlc
+{
+
+ static public void main(String args[])
+ {
+ String[] argv;
+ long start = System.currentTimeMillis();
+ int argc = args.length + 1;
+ argv = new String[argc];
+ argv[0] = "jlc";
+ for(int i=0;i<args.length;i++)
+ argv[i+1] = args[i];
+
+ jlcArgs ma = new jlcArgs();
+ if (!ma.processArgs(argv))
+ System.exit(1);
+
+ Converter conv = new Converter();
+
+ int detail = (ma.verbose_mode ?
+ ma.verbose_level :
+ Converter.PrintWriterProgressListener.NO_DETAIL);
+
+ Converter.ProgressListener listener =
+ new Converter.PrintWriterProgressListener(
+ new PrintWriter(System.out, true), detail);
+
+ try
+ {
+ conv.convert(ma.filename, ma.output_filename, listener);
+ }
+ catch (JavaLayerException ex)
+ {
+ System.err.println("Convertion failure: "+ex);
+ }
+
+ System.exit(0);
+ }
+
+
+ /**
+ * Class to contain arguments for maplay.
+ */
+ static class jlcArgs
+ {
+ // channel constants moved into OutputChannels class.
+ //public static final int both = 0;
+ //public static final int left = 1;
+ //public static final int right = 2;
+ //public static final int downmix = 3;
+
+ public int which_c;
+ public int output_mode;
+ public boolean use_own_scalefactor;
+ public float scalefactor;
+ public String output_filename;
+ public String filename;
+ //public boolean stdout_mode;
+ public boolean verbose_mode;
+ public int verbose_level = 3;
+
+ public jlcArgs()
+ {
+ which_c = OutputChannels.BOTH_CHANNELS;
+ use_own_scalefactor = false;
+ scalefactor = (float) 32768.0;
+ //stdout_mode = false;
+ verbose_mode = false;
+ }
+
+ /**
+ * Process user arguments.
+ *
+ * Returns true if successful.
+ */
+ public boolean processArgs(String[] argv)
+ {
+ filename = null;
+ Crc16[] crc;
+ crc = new Crc16[1];
+ int i;
+ int argc = argv.length;
+
+ //stdout_mode = false;
+ verbose_mode = false;
+ output_mode = OutputChannels.BOTH_CHANNELS;
+ output_filename = "";
+ if (argc < 2 || argv[1].equals("-h"))
+ return Usage();
+
+ i = 1;
+ while (i < argc)
+ {
+ /* System.out.println("Option = "+argv[i]);*/
+ if (argv[i].charAt(0) == '-')
+ {
+ if (argv[i].startsWith("-v"))
+ {
+ verbose_mode = true;
+ if (argv[i].length()>2)
+ {
+ try
+ {
+ String level = argv[i].substring(2);
+ verbose_level = Integer.parseInt(level);
+ }
+ catch (NumberFormatException ex)
+ {
+ System.err.println("Invalid verbose level. Using default.");
+ }
+ }
+ System.out.println("Verbose Activated (level "+verbose_level+")");
+ }
+ /* else if (argv[i].equals("-s"))
+ ma.stdout_mode = true; */
+ else if (argv[i].equals("-p"))
+ {
+ if (++i == argc)
+ {
+ System.out.println("Please specify an output filename after the -p option!");
+ System.exit (1);
+ }
+ //output_mode = O_WAVEFILE;
+ output_filename = argv[i];
+ }
+ /*else if (argv[i].equals("-f"))
+ {
+ if (++i == argc)
+ {
+ System.out.println("Please specify a new scalefactor after the -f option!");
+ System.exit(1);
+ }
+ ma.use_own_scalefactor = true;
+ // ma.scalefactor = argv[i];
+ }*/
+ else return Usage();
+ }
+ else
+ {
+ filename = argv[i];
+ System.out.println("FileName = "+argv[i]);
+ if (filename == null) return Usage();
+ }
+ i++;
+ }
+ if (filename == null)
+ return Usage();
+
+ return true;
+ }
+
+
+ /**
+ * Usage of JavaLayer.
+ */
+ public boolean Usage()
+ {
+ System.out.println("JavaLayer Converter :");
+ System.out.println(" -v[x] verbose mode. ");
+ System.out.println(" default = 2");
+ /* System.out.println(" -s write u-law samples at 8 kHz rate to stdout");
+ System.out.println(" -l decode only the left channel");
+ System.out.println(" -r decode only the right channel");
+ System.out.println(" -d downmix mode (layer III only)");
+ System.out.println(" -s write pcm samples to stdout");
+ System.out.println(" -d downmix mode (layer III only)");*/
+ System.out.println(" -p name output as a PCM wave file");
+ System.out.println("");
+ System.out.println(" More info on http://www.javazoom.net");
+ /* System.out.println(" -f ushort use this scalefactor instead of the default value 32768");*/
+ return false;
+ }
+ };
+};
\ No newline at end of file
Added: sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/BitReserve.java
===================================================================
--- sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/BitReserve.java (rev 0)
+++ sandbox/tonit/org.javazoom.jl/src/main/java/javazoom/jl/decoder/BitReserve.java 2007-02-15 21:37:01 UTC (rev 70)
@@ -0,0 +1,223 @@
+/*
+ * 11/19/04 1.0 moved to LGPL.
+ *
+ * 12/12/99 0.0.7 Implementation stores single bits
+ * as ints for better performance. md...@te....
+ *
+ * 02/28/99 0.0 Java Conversion by E.B, jav...@ja...
+ *
+ * Adapted from the public c code by Jeff Tsay.
+ *
+ *-----------------------------------------------------------------------
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *----------------------------------------------------------------------
+ */
+
+package javazoom.jl.decoder;
+
+/**
+ * Implementation of Bit Reservoir for Layer III.
+ * <p>
+ * The implementation stores single bits as a word in the buffer. If
+ * a bit is set, the corresponding word in the buffer will be non-zero.
+ * If a bit is clear, the corresponding word is zero. Although this
+ * may seem waseful, this can be a factor of two quicker than
+ * packing 8 bits to a byte and extracting.
+ * <p>
+ */
+
+// REVIEW: there is no range checking, so buffer underflow or overflow
+// can silently occur.
+final class BitReserve
+{
+ /**
+ * Size of the internal buffer to store the reserved bits.
+ * Must be a power of 2. And x8, as each bit is stored as a single
+ ...
[truncated message content] |