From 7039a05147b8bbfc829babea1c65bd436450b505 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Mon, 8 Jan 2007 23:53:00 +0000 Subject: Splitting out songdbj git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11953 a1c6a512-1295-4272-9138-f99709370657 --- songdbj/javazoom/jl/converter/Converter.java | 411 ---------------- songdbj/javazoom/jl/converter/RiffFile.java | 495 ------------------- songdbj/javazoom/jl/converter/WaveFile.java | 522 --------------------- songdbj/javazoom/jl/converter/WaveFileObuffer.java | 141 ------ songdbj/javazoom/jl/converter/jlc.java | 216 --------- 5 files changed, 1785 deletions(-) delete mode 100644 songdbj/javazoom/jl/converter/Converter.java delete mode 100644 songdbj/javazoom/jl/converter/RiffFile.java delete mode 100644 songdbj/javazoom/jl/converter/WaveFile.java delete mode 100644 songdbj/javazoom/jl/converter/WaveFileObuffer.java delete mode 100644 songdbj/javazoom/jl/converter/jlc.java (limited to 'songdbj/javazoom/jl/converter') 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 @@ -/* - * 11/19/04 1.0 moved to LGPL. - * 12/12/99 Original verion. mdm@techie.com. - *----------------------------------------------------------------------- - * 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 Converter 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 ProgressListener and - * Decoder.Params 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 (; frameupdateID 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 Throwable instance that - * was thrown. - * - * @return true to continue processing, or false - * to abort conversion. - * - * If this method returns false, the exception - * is propagated to the caller of the convert() method. If - * true is returned, the exception is silently - * ignored and the converter moves onto the next frame. - */ - public boolean converterException(Throwable t); - - } - - - /** - * Implementation of ProgressListener that writes - * notification text to a PrintWriter. - */ - // 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 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 @@ -/* - * 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>> 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; - } - -} 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 @@ -/* - * 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 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 @@ -/* - * 11/19/04 1.0 moved to LGPL. - * - * 12/12/99 0.0.7 Renamed class, additional constructor arguments - * and larger write buffers. mdm@techie.com. - * - * 15/02/99 Java Conversion by E.B ,javalayer@javazoom.net - * - *----------------------------------------------------------------------- - * 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>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); - } - */ -} 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 @@ -/* - * 11/19/04 1.0 moved to LGPL. - * - * 29/01/00 Initial version. mdm@techie.com - * - * 12/12/99 JavaLayer 0.0.7 mdm@techie.com - * - * 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 jlc 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;i2) - { - 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 -- cgit v1.2.3