trying to put annotations on mp3 decoder source codes using the current ssjava scheme.
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * \r
+ * 12/12/99 0.0.7 Implementation stores single bits \r
+ * as ints for better performance. mdm@techie.com.\r
+ *\r
+ * 02/28/99 0.0 Java Conversion by E.B, javalayer@javazoom.net\r
+ *\r
+ * Adapted from the public c code by Jeff Tsay.\r
+ *\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+ \r
+/**\r
+ * Implementation of Bit Reservoir for Layer III.\r
+ * <p>\r
+ * The implementation stores single bits as a word in the buffer. If\r
+ * a bit is set, the corresponding word in the buffer will be non-zero.\r
+ * If a bit is clear, the corresponding word is zero. Although this\r
+ * may seem waseful, this can be a factor of two quicker than \r
+ * packing 8 bits to a byte and extracting. \r
+ * <p> \r
+ */\r
+\r
+// REVIEW: there is no range checking, so buffer underflow or overflow\r
+// can silently occur.\r
+final class BitReserve\r
+{\r
+ /**\r
+ * Size of the internal buffer to store the reserved bits.\r
+ * Must be a power of 2. And x8, as each bit is stored as a single\r
+ * entry.\r
+ */\r
+ private static final int BUFSIZE = 4096*8;\r
+ \r
+ /**\r
+ * Mask that can be used to quickly implement the\r
+ * modulus operation on BUFSIZE.\r
+ */\r
+ private static final int BUFSIZE_MASK = BUFSIZE-1;\r
+ \r
+ private int offset, totbit, buf_byte_idx;\r
+ private final int[] buf = new int[BUFSIZE];\r
+ private int buf_bit_idx;\r
+ \r
+ BitReserve()\r
+ {\r
+ \r
+ offset = 0;\r
+ totbit = 0;\r
+ buf_byte_idx = 0; \r
+ }\r
+ \r
+ \r
+ /**\r
+ * Return totbit Field.\r
+ */\r
+ public int hsstell() \r
+ { \r
+ return(totbit); \r
+ }\r
+\r
+ /**\r
+ * Read a number bits from the bit stream.\r
+ * @param N the number of\r
+ */\r
+ public int hgetbits(int N)\r
+ {\r
+ totbit += N;\r
+ \r
+ int val = 0;\r
+ \r
+ int pos = buf_byte_idx;\r
+ if (pos+N < BUFSIZE)\r
+ {\r
+ while (N-- > 0)\r
+ {\r
+ val <<= 1;\r
+ val |= ((buf[pos++]!=0) ? 1 : 0); \r
+ }\r
+ }\r
+ else\r
+ { \r
+ while (N-- > 0)\r
+ {\r
+ val <<= 1; \r
+ val |= ((buf[pos]!=0) ? 1 : 0);\r
+ pos = (pos+1) & BUFSIZE_MASK;\r
+ } \r
+ } \r
+ buf_byte_idx = pos;\r
+ return val;\r
+ }\r
+ \r
+ \r
+ \r
+ /**\r
+ * Read 1 bit from the bit stream.\r
+ */\r
+/*\r
+ public int hget1bit_old()\r
+ {\r
+ int val;\r
+ totbit++;\r
+ if (buf_bit_idx == 0)\r
+ {\r
+ buf_bit_idx = 8;\r
+ buf_byte_idx++; \r
+ }\r
+ // BUFSIZE = 4096 = 2^12, so\r
+ // buf_byte_idx%BUFSIZE == buf_byte_idx & 0xfff\r
+ val = buf[buf_byte_idx & BUFSIZE_MASK] & putmask[buf_bit_idx];\r
+ buf_bit_idx--;\r
+ val = val >>> buf_bit_idx;\r
+ return val; \r
+ }\r
+ */\r
+ /**\r
+ * Returns next bit from reserve.\r
+ * @returns 0 if next bit is reset, or 1 if next bit is set.\r
+ */\r
+ public int hget1bit()\r
+ { \r
+ totbit++; \r
+ int val = buf[buf_byte_idx];\r
+ buf_byte_idx = (buf_byte_idx+1) & BUFSIZE_MASK;\r
+ return val;\r
+ }\r
+ \r
+ /**\r
+ * Retrieves bits from the reserve. \r
+ */\r
+/* \r
+ public int readBits(int[] out, int len)\r
+ {\r
+ if (buf_bit_idx == 0)\r
+ {\r
+ buf_bit_idx = 8;\r
+ buf_byte_idx++;\r
+ current = buf[buf_byte_idx & BUFSIZE_MASK];\r
+ } \r
+ \r
+ \r
+ \r
+ // save total number of bits returned\r
+ len = buf_bit_idx;\r
+ buf_bit_idx = 0;\r
+ \r
+ int b = current;\r
+ int count = len-1;\r
+ \r
+ while (count >= 0)\r
+ {\r
+ out[count--] = (b & 0x1);\r
+ b >>>= 1;\r
+ }\r
+ \r
+ totbit += len;\r
+ return len;\r
+ }\r
+ */\r
+ \r
+ /**\r
+ * Write 8 bits into the bit stream.\r
+ */\r
+ public void hputbuf(int val)\r
+ { \r
+ int ofs = offset;\r
+ buf[ofs++] = val & 0x80;\r
+ buf[ofs++] = val & 0x40;\r
+ buf[ofs++] = val & 0x20;\r
+ buf[ofs++] = val & 0x10;\r
+ buf[ofs++] = val & 0x08;\r
+ buf[ofs++] = val & 0x04;\r
+ buf[ofs++] = val & 0x02;\r
+ buf[ofs++] = val & 0x01;\r
+ \r
+ if (ofs==BUFSIZE)\r
+ offset = 0;\r
+ else\r
+ offset = ofs;\r
+ \r
+ }\r
+ \r
+ /**\r
+ * Rewind N bits in Stream.\r
+ */\r
+ public void rewindNbits(int N)\r
+ {\r
+ totbit -= N; \r
+ buf_byte_idx -= N;\r
+ if (buf_byte_idx<0)\r
+ buf_byte_idx += BUFSIZE;\r
+ }\r
+ \r
+ /**\r
+ * Rewind N bytes in Stream.\r
+ */\r
+ public void rewindNbytes(int N)\r
+ {\r
+ int bits = (N << 3);\r
+ totbit -= bits;\r
+ buf_byte_idx -= bits; \r
+ if (buf_byte_idx<0)\r
+ buf_byte_idx += BUFSIZE;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * \r
+ * 11/17/04 Uncomplete frames discarded. E.B, javalayer@javazoom.net \r
+ *\r
+ * 12/05/03 ID3v2 tag returned. E.B, javalayer@javazoom.net \r
+ *\r
+ * 12/12/99 Based on Ibitstream. Exceptions thrown on errors,\r
+ * Temporary removed seek functionality. mdm@techie.com\r
+ *\r
+ * 02/12/99 : Java Conversion by E.B , javalayer@javazoom.net\r
+ *\r
+ * 04/14/97 : Added function prototypes for new syncing and seeking\r
+ * mechanisms. Also made this file portable. Changes made by Jeff Tsay\r
+ *\r
+ * @(#) ibitstream.h 1.5, last edit: 6/15/94 16:55:34\r
+ * @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)\r
+ * @(#) Berlin University of Technology\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+import java.io.BufferedInputStream;\r
+import java.io.ByteArrayInputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.PushbackInputStream;\r
+\r
+\r
+/**\r
+ * The <code>Bistream</code> class is responsible for parsing\r
+ * an MPEG audio bitstream.\r
+ *\r
+ * <b>REVIEW:</b> much of the parsing currently occurs in the\r
+ * various decoders. This should be moved into this class and associated\r
+ * inner classes.\r
+ */\r
+public final class Bitstream implements BitstreamErrors\r
+{\r
+ /**\r
+ * Synchronization control constant for the initial\r
+ * synchronization to the start of a frame.\r
+ */\r
+ static byte INITIAL_SYNC = 0;\r
+\r
+ /**\r
+ * Synchronization control constant for non-initial frame\r
+ * synchronizations.\r
+ */\r
+ static byte STRICT_SYNC = 1;\r
+\r
+ // max. 1730 bytes per frame: 144 * 384kbit/s / 32000 Hz + 2 Bytes CRC\r
+ /**\r
+ * Maximum size of the frame buffer.\r
+ */\r
+ private static final int BUFFER_INT_SIZE = 433;\r
+\r
+ /**\r
+ * The frame buffer that holds the data for the current frame.\r
+ */\r
+ private final int[] framebuffer = new int[BUFFER_INT_SIZE];\r
+\r
+ /**\r
+ * Number of valid bytes in the frame buffer.\r
+ */\r
+ private int framesize;\r
+\r
+ /**\r
+ * The bytes read from the stream.\r
+ */\r
+ private byte[] frame_bytes = new byte[BUFFER_INT_SIZE*4];\r
+\r
+ /**\r
+ * Index into <code>framebuffer</code> where the next bits are\r
+ * retrieved.\r
+ */\r
+ private int wordpointer;\r
+\r
+ /**\r
+ * Number (0-31, from MSB to LSB) of next bit for get_bits()\r
+ */\r
+ private int bitindex;\r
+\r
+ /**\r
+ * The current specified syncword\r
+ */\r
+ private int syncword;\r
+ \r
+ /**\r
+ * Audio header position in stream.\r
+ */\r
+ private int header_pos = 0;\r
+\r
+ /**\r
+ *\r
+ */\r
+ private boolean single_ch_mode;\r
+ //private int current_frame_number;\r
+ //private int last_frame_number;\r
+\r
+ private final int bitmask[] = {0, // dummy\r
+ 0x00000001, 0x00000003, 0x00000007, 0x0000000F,\r
+ 0x0000001F, 0x0000003F, 0x0000007F, 0x000000FF,\r
+ 0x000001FF, 0x000003FF, 0x000007FF, 0x00000FFF,\r
+ 0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF,\r
+ 0x0001FFFF };\r
+\r
+ private final PushbackInputStream source;\r
+\r
+ private final Header header = new Header();\r
+\r
+ private final byte syncbuf[] = new byte[4];\r
+\r
+ private Crc16[] crc = new Crc16[1];\r
+\r
+ private byte[] rawid3v2 = null;\r
+\r
+ private boolean firstframe = true;\r
+\r
+\r
+ /**\r
+ * Construct a IBitstream that reads data from a\r
+ * given InputStream.\r
+ *\r
+ * @param in The InputStream to read from.\r
+ */\r
+ public Bitstream(InputStream in)\r
+ {\r
+ if (in==null) throw new NullPointerException("in");\r
+ in = new BufferedInputStream(in); \r
+ loadID3v2(in);\r
+ firstframe = true;\r
+ //source = new PushbackInputStream(in, 1024);\r
+ source = new PushbackInputStream(in, BUFFER_INT_SIZE*4);\r
+ \r
+ closeFrame();\r
+ //current_frame_number = -1;\r
+ //last_frame_number = -1;\r
+ }\r
+\r
+ /**\r
+ * Return position of the first audio header.\r
+ * @return size of ID3v2 tag frames.\r
+ */\r
+ public int header_pos()\r
+ {\r
+ return header_pos;\r
+ }\r
+ \r
+ /**\r
+ * Load ID3v2 frames.\r
+ * @param in MP3 InputStream.\r
+ * @author JavaZOOM\r
+ */\r
+ private void loadID3v2(InputStream in)\r
+ { \r
+ int size = -1;\r
+ try\r
+ {\r
+ // Read ID3v2 header (10 bytes).\r
+ in.mark(10); \r
+ size = readID3v2Header(in);\r
+ header_pos = size; \r
+ }\r
+ catch (IOException e)\r
+ {}\r
+ finally\r
+ {\r
+ try\r
+ {\r
+ // Unread ID3v2 header (10 bytes).\r
+ in.reset();\r
+ }\r
+ catch (IOException e)\r
+ {}\r
+ }\r
+ // Load ID3v2 tags.\r
+ try\r
+ {\r
+ if (size > 0)\r
+ {\r
+ rawid3v2 = new byte[size];\r
+ in.read(rawid3v2,0,rawid3v2.length);\r
+ } \r
+ }\r
+ catch (IOException e)\r
+ {}\r
+ }\r
+ \r
+ /**\r
+ * Parse ID3v2 tag header to find out size of ID3v2 frames. \r
+ * @param in MP3 InputStream\r
+ * @return size of ID3v2 frames + header\r
+ * @throws IOException\r
+ * @author JavaZOOM\r
+ */\r
+ private int readID3v2Header(InputStream in) throws IOException\r
+ { \r
+ byte[] id3header = new byte[4];\r
+ int size = -10;\r
+ in.read(id3header,0,3);\r
+ // Look for ID3v2\r
+ if ( (id3header[0]=='I') && (id3header[1]=='D') && (id3header[2]=='3'))\r
+ {\r
+ in.read(id3header,0,3);\r
+ int majorVersion = id3header[0];\r
+ int revision = id3header[1];\r
+ in.read(id3header,0,4);\r
+ size = (int) (id3header[0] << 21) + (id3header[1] << 14) + (id3header[2] << 7) + (id3header[3]);\r
+ }\r
+ return (size+10);\r
+ }\r
+ \r
+ /**\r
+ * Return raw ID3v2 frames + header.\r
+ * @return ID3v2 InputStream or null if ID3v2 frames are not available.\r
+ */\r
+ public InputStream getRawID3v2()\r
+ {\r
+ if (rawid3v2 == null) return null;\r
+ else\r
+ {\r
+ ByteArrayInputStream bain = new ByteArrayInputStream(rawid3v2); \r
+ return bain;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Close the Bitstream.\r
+ * @throws BitstreamException\r
+ */\r
+ public void close() throws BitstreamException\r
+ {\r
+ try\r
+ {\r
+ source.close();\r
+ }\r
+ catch (IOException ex)\r
+ {\r
+ throw newBitstreamException(STREAM_ERROR, ex);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Reads and parses the next frame from the input source.\r
+ * @return the Header describing details of the frame read,\r
+ * or null if the end of the stream has been reached.\r
+ */\r
+ public Header readFrame() throws BitstreamException\r
+ {\r
+ Header result = null;\r
+ try\r
+ {\r
+ result = readNextFrame();\r
+ // E.B, Parse VBR (if any) first frame.\r
+ if (firstframe == true)\r
+ {\r
+ result.parseVBR(frame_bytes);\r
+ firstframe = false;\r
+ } \r
+ }\r
+ catch (BitstreamException ex)\r
+ {\r
+ if ((ex.getErrorCode()==INVALIDFRAME))\r
+ {\r
+ // Try to skip this frame.\r
+ //System.out.println("INVALIDFRAME");\r
+ try\r
+ {\r
+ closeFrame();\r
+ result = readNextFrame();\r
+ }\r
+ catch (BitstreamException e)\r
+ {\r
+ if ((e.getErrorCode()!=STREAM_EOF))\r
+ {\r
+ // wrap original exception so stack trace is maintained.\r
+ throw newBitstreamException(e.getErrorCode(), e);\r
+ }\r
+ }\r
+ }\r
+ else if ((ex.getErrorCode()!=STREAM_EOF))\r
+ {\r
+ // wrap original exception so stack trace is maintained.\r
+ throw newBitstreamException(ex.getErrorCode(), ex);\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Read next MP3 frame.\r
+ * @return MP3 frame header.\r
+ * @throws BitstreamException\r
+ */\r
+ private Header readNextFrame() throws BitstreamException\r
+ {\r
+ if (framesize == -1)\r
+ {\r
+ nextFrame();\r
+ }\r
+ return header;\r
+ }\r
+\r
+\r
+ /**\r
+ * Read next MP3 frame.\r
+ * @throws BitstreamException\r
+ */\r
+ private void nextFrame() throws BitstreamException\r
+ {\r
+ // entire frame is read by the header class.\r
+ header.read_header(this, crc);\r
+ }\r
+\r
+ /**\r
+ * Unreads the bytes read from the frame.\r
+ * @throws BitstreamException\r
+ */\r
+ // REVIEW: add new error codes for this.\r
+ public void unreadFrame() throws BitstreamException\r
+ {\r
+ if (wordpointer==-1 && bitindex==-1 && (framesize>0))\r
+ {\r
+ try\r
+ {\r
+ source.unread(frame_bytes, 0, framesize);\r
+ }\r
+ catch (IOException ex)\r
+ {\r
+ throw newBitstreamException(STREAM_ERROR);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Close MP3 frame.\r
+ */\r
+ public void closeFrame()\r
+ {\r
+ framesize = -1;\r
+ wordpointer = -1;\r
+ bitindex = -1;\r
+ }\r
+\r
+ /**\r
+ * Determines if the next 4 bytes of the stream represent a\r
+ * frame header.\r
+ */\r
+ public boolean isSyncCurrentPosition(int syncmode) throws BitstreamException\r
+ {\r
+ int read = readBytes(syncbuf, 0, 4);\r
+ int headerstring = ((syncbuf[0] << 24) & 0xFF000000) | ((syncbuf[1] << 16) & 0x00FF0000) | ((syncbuf[2] << 8) & 0x0000FF00) | ((syncbuf[3] << 0) & 0x000000FF);\r
+\r
+ try\r
+ {\r
+ source.unread(syncbuf, 0, read);\r
+ }\r
+ catch (IOException ex)\r
+ {\r
+ }\r
+\r
+ boolean sync = false;\r
+ switch (read)\r
+ {\r
+ case 0:\r
+ sync = true;\r
+ break;\r
+ case 4:\r
+ sync = isSyncMark(headerstring, syncmode, syncword);\r
+ break;\r
+ }\r
+\r
+ return sync;\r
+ }\r
+\r
+\r
+ // REVIEW: this class should provide inner classes to\r
+ // parse the frame contents. Eventually, readBits will\r
+ // be removed.\r
+ public int readBits(int n)\r
+ {\r
+ return get_bits(n);\r
+ }\r
+\r
+ public int readCheckedBits(int n)\r
+ {\r
+ // REVIEW: implement CRC check.\r
+ return get_bits(n);\r
+ }\r
+\r
+ protected BitstreamException newBitstreamException(int errorcode)\r
+ {\r
+ return new BitstreamException(errorcode, null);\r
+ }\r
+ protected BitstreamException newBitstreamException(int errorcode, Throwable throwable)\r
+ {\r
+ return new BitstreamException(errorcode, throwable);\r
+ }\r
+\r
+ /**\r
+ * Get next 32 bits from bitstream.\r
+ * They are stored in the headerstring.\r
+ * syncmod allows Synchro flag ID\r
+ * The returned value is False at the end of stream.\r
+ */\r
+\r
+ int syncHeader(byte syncmode) throws BitstreamException\r
+ {\r
+ boolean sync;\r
+ int headerstring;\r
+ // read additional 2 bytes\r
+ int bytesRead = readBytes(syncbuf, 0, 3);\r
+\r
+ if (bytesRead!=3) throw newBitstreamException(STREAM_EOF, null);\r
+\r
+ headerstring = ((syncbuf[0] << 16) & 0x00FF0000) | ((syncbuf[1] << 8) & 0x0000FF00) | ((syncbuf[2] << 0) & 0x000000FF);\r
+\r
+ do\r
+ {\r
+ headerstring <<= 8;\r
+\r
+ if (readBytes(syncbuf, 3, 1)!=1)\r
+ throw newBitstreamException(STREAM_EOF, null);\r
+\r
+ headerstring |= (syncbuf[3] & 0x000000FF);\r
+\r
+ sync = isSyncMark(headerstring, syncmode, syncword);\r
+ }\r
+ while (!sync);\r
+\r
+ //current_frame_number++;\r
+ //if (last_frame_number < current_frame_number) last_frame_number = current_frame_number;\r
+\r
+ return headerstring;\r
+ }\r
+\r
+ public boolean isSyncMark(int headerstring, int syncmode, int word)\r
+ {\r
+ boolean sync = false;\r
+\r
+ if (syncmode == INITIAL_SYNC)\r
+ {\r
+ //sync = ((headerstring & 0xFFF00000) == 0xFFF00000);\r
+ sync = ((headerstring & 0xFFE00000) == 0xFFE00000); // SZD: MPEG 2.5\r
+ }\r
+ else\r
+ {\r
+ sync = ((headerstring & 0xFFF80C00) == word) &&\r
+ (((headerstring & 0x000000C0) == 0x000000C0) == single_ch_mode);\r
+ }\r
+\r
+ // filter out invalid sample rate\r
+ if (sync)\r
+ sync = (((headerstring >>> 10) & 3)!=3);\r
+ // filter out invalid layer\r
+ if (sync)\r
+ sync = (((headerstring >>> 17) & 3)!=0);\r
+ // filter out invalid version\r
+ if (sync)\r
+ sync = (((headerstring >>> 19) & 3)!=1);\r
+\r
+ return sync;\r
+ }\r
+\r
+ /**\r
+ * Reads the data for the next frame. The frame is not parsed\r
+ * until parse frame is called.\r
+ */\r
+ int read_frame_data(int bytesize) throws BitstreamException\r
+ {\r
+ int numread = 0;\r
+ numread = readFully(frame_bytes, 0, bytesize);\r
+ framesize = bytesize;\r
+ wordpointer = -1;\r
+ bitindex = -1;\r
+ return numread;\r
+ }\r
+\r
+ /**\r
+ * Parses the data previously read with read_frame_data().\r
+ */\r
+ void parse_frame() throws BitstreamException\r
+ {\r
+ // Convert Bytes read to int\r
+ int b=0;\r
+ byte[] byteread = frame_bytes;\r
+ int bytesize = framesize;\r
+\r
+ // Check ID3v1 TAG (True only if last frame).\r
+ //for (int t=0;t<(byteread.length)-2;t++)\r
+ //{\r
+ // if ((byteread[t]=='T') && (byteread[t+1]=='A') && (byteread[t+2]=='G'))\r
+ // {\r
+ // System.out.println("ID3v1 detected at offset "+t);\r
+ // throw newBitstreamException(INVALIDFRAME, null);\r
+ // } \r
+ //}\r
+ \r
+ for (int k=0;k<bytesize;k=k+4)\r
+ {\r
+ int convert = 0;\r
+ byte b0 = 0;\r
+ byte b1 = 0;\r
+ byte b2 = 0;\r
+ byte b3 = 0;\r
+ b0 = byteread[k];\r
+ if (k+1<bytesize) b1 = byteread[k+1];\r
+ if (k+2<bytesize) b2 = byteread[k+2];\r
+ if (k+3<bytesize) b3 = byteread[k+3];\r
+ framebuffer[b++] = ((b0 << 24) &0xFF000000) | ((b1 << 16) & 0x00FF0000) | ((b2 << 8) & 0x0000FF00) | (b3 & 0x000000FF);\r
+ }\r
+ wordpointer = 0;\r
+ bitindex = 0;\r
+ }\r
+\r
+ /**\r
+ * Read bits from buffer into the lower bits of an unsigned int.\r
+ * The LSB contains the latest read bit of the stream.\r
+ * (1 <= number_of_bits <= 16)\r
+ */\r
+ public int get_bits(int number_of_bits)\r
+ {\r
+ int returnvalue = 0;\r
+ int sum = bitindex + number_of_bits;\r
+\r
+ // E.B\r
+ // There is a problem here, wordpointer could be -1 ?!\r
+ if (wordpointer < 0) wordpointer = 0;\r
+ // E.B : End.\r
+\r
+ if (sum <= 32)\r
+ {\r
+ // all bits contained in *wordpointer\r
+ returnvalue = (framebuffer[wordpointer] >>> (32 - sum)) & bitmask[number_of_bits];\r
+ // returnvalue = (wordpointer[0] >> (32 - sum)) & bitmask[number_of_bits];\r
+ if ((bitindex += number_of_bits) == 32)\r
+ {\r
+ bitindex = 0;\r
+ wordpointer++; // added by me!\r
+ }\r
+ return returnvalue;\r
+ }\r
+\r
+ // E.B : Check that ?\r
+ //((short[])&returnvalue)[0] = ((short[])wordpointer + 1)[0];\r
+ //wordpointer++; // Added by me!\r
+ //((short[])&returnvalue + 1)[0] = ((short[])wordpointer)[0];\r
+ int Right = (framebuffer[wordpointer] & 0x0000FFFF);\r
+ wordpointer++;\r
+ int Left = (framebuffer[wordpointer] & 0xFFFF0000);\r
+ returnvalue = ((Right << 16) & 0xFFFF0000) | ((Left >>> 16)& 0x0000FFFF);\r
+\r
+ returnvalue >>>= 48 - sum; // returnvalue >>= 16 - (number_of_bits - (32 - bitindex))\r
+ returnvalue &= bitmask[number_of_bits];\r
+ bitindex = sum - 32;\r
+ return returnvalue;\r
+}\r
+\r
+ /**\r
+ * Set the word we want to sync the header to.\r
+ * In Big-Endian byte order\r
+ */\r
+ void set_syncword(int syncword0)\r
+ {\r
+ syncword = syncword0 & 0xFFFFFF3F;\r
+ single_ch_mode = ((syncword0 & 0x000000C0) == 0x000000C0);\r
+ }\r
+ /**\r
+ * Reads the exact number of bytes from the source\r
+ * input stream into a byte array.\r
+ *\r
+ * @param b The byte array to read the specified number\r
+ * of bytes into.\r
+ * @param offs The index in the array where the first byte\r
+ * read should be stored.\r
+ * @param len the number of bytes to read.\r
+ *\r
+ * @exception BitstreamException is thrown if the specified\r
+ * number of bytes could not be read from the stream.\r
+ */\r
+ private int readFully(byte[] b, int offs, int len)\r
+ throws BitstreamException\r
+ { \r
+ int nRead = 0;\r
+ try\r
+ {\r
+ while (len > 0)\r
+ {\r
+ int bytesread = source.read(b, offs, len);\r
+ if (bytesread == -1)\r
+ {\r
+ while (len-->0)\r
+ {\r
+ b[offs++] = 0;\r
+ }\r
+ break;\r
+ //throw newBitstreamException(UNEXPECTED_EOF, new EOFException());\r
+ }\r
+ nRead = nRead + bytesread;\r
+ offs += bytesread;\r
+ len -= bytesread;\r
+ }\r
+ }\r
+ catch (IOException ex)\r
+ {\r
+ throw newBitstreamException(STREAM_ERROR, ex);\r
+ }\r
+ return nRead;\r
+ }\r
+\r
+ /**\r
+ * Simlar to readFully, but doesn't throw exception when\r
+ * EOF is reached.\r
+ */\r
+ private int readBytes(byte[] b, int offs, int len)\r
+ throws BitstreamException\r
+ {\r
+ int totalBytesRead = 0;\r
+ try\r
+ {\r
+ while (len > 0)\r
+ {\r
+ int bytesread = source.read(b, offs, len);\r
+ if (bytesread == -1)\r
+ {\r
+ break;\r
+ }\r
+ totalBytesRead += bytesread;\r
+ offs += bytesread;\r
+ len -= bytesread;\r
+ }\r
+ }\r
+ catch (IOException ex)\r
+ {\r
+ throw newBitstreamException(STREAM_ERROR, ex);\r
+ }\r
+ return totalBytesRead;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 11/17/04 INVALIDFRAME code added. javalayer@javazoom.net\r
+ * 12/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * This interface describes all error codes that can be thrown \r
+ * in <code>BistreamException</code>s.\r
+ * \r
+ * @see BitstreamException\r
+ * \r
+ * @author MDM 12/12/99\r
+ * @since 0.0.6\r
+ */\r
+\r
+public interface BitstreamErrors extends JavaLayerErrors\r
+{\r
+ \r
+ /**\r
+ * An undeterminable error occurred. \r
+ */\r
+ static public final int UNKNOWN_ERROR = BITSTREAM_ERROR + 0;\r
+ \r
+ /**\r
+ * The header describes an unknown sample rate.\r
+ */\r
+ static public final int UNKNOWN_SAMPLE_RATE = BITSTREAM_ERROR + 1;\r
+\r
+ /**\r
+ * A problem occurred reading from the stream.\r
+ */\r
+ static public final int STREAM_ERROR = BITSTREAM_ERROR + 2;\r
+ \r
+ /**\r
+ * The end of the stream was reached prematurely. \r
+ */\r
+ static public final int UNEXPECTED_EOF = BITSTREAM_ERROR + 3;\r
+ \r
+ /**\r
+ * The end of the stream was reached. \r
+ */\r
+ static public final int STREAM_EOF = BITSTREAM_ERROR + 4;\r
+ \r
+ /**\r
+ * Frame data are missing. \r
+ */\r
+ static public final int INVALIDFRAME = BITSTREAM_ERROR + 5;\r
+\r
+ /**\r
+ * \r
+ */\r
+ static public final int BITSTREAM_LAST = 0x1ff;\r
+ \r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 12/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * Instances of <code>BitstreamException</code> are thrown \r
+ * when operations on a <code>Bitstream</code> fail. \r
+ * <p>\r
+ * The exception provides details of the exception condition \r
+ * in two ways:\r
+ * <ol><li>\r
+ * as an error-code describing the nature of the error\r
+ * </li><br></br><li>\r
+ * as the <code>Throwable</code> instance, if any, that was thrown\r
+ * indicating that an exceptional condition has occurred. \r
+ * </li></ol></p>\r
+ * \r
+ * @since 0.0.6\r
+ * @author MDM 12/12/99\r
+ */\r
+\r
+public class BitstreamException extends JavaLayerException\r
+ implements BitstreamErrors\r
+{ \r
+ private int errorcode = UNKNOWN_ERROR;\r
+ \r
+ public BitstreamException(String msg, Throwable t)\r
+ {\r
+ super(msg, t); \r
+ }\r
+ \r
+ public BitstreamException(int errorcode, Throwable t)\r
+ {\r
+ this(getErrorString(errorcode), t);\r
+ this.errorcode = errorcode;\r
+ }\r
+ \r
+ public int getErrorCode()\r
+ {\r
+ return errorcode; \r
+ }\r
+ \r
+ \r
+ static public String getErrorString(int errorcode)\r
+ {\r
+ // REVIEW: use resource bundle to map error codes\r
+ // to locale-sensitive strings.\r
+ \r
+ return "Bitstream errorcode "+Integer.toHexString(errorcode);\r
+ }\r
+ \r
+ \r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL. \r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * Work in progress.\r
+ */\r
+\r
+public interface Control\r
+{\r
+ \r
+ /**\r
+ * Starts playback of the media presented by this control.\r
+ */\r
+ public void start();\r
+ \r
+ /**\r
+ * Stops playback of the media presented by this control.\r
+ */\r
+ public void stop();\r
+ \r
+ public boolean isPlaying();\r
+ \r
+ public void pause();\r
+ \r
+ \r
+ public boolean isRandomAccess();\r
+ \r
+ /**\r
+ * Retrieves the current position.\r
+ */\r
+ public double getPosition();\r
+ \r
+ /**\r
+ * \r
+ */\r
+ public void setPosition(double d);\r
+ \r
+ \r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 : 1.0 moved to LGPL.\r
+ * \r
+ * 02/12/99 : Java Conversion by E.B , javalayer@javazoom.net\r
+ *\r
+ * @(#) crc.h 1.5, last edit: 6/15/94 16:55:32\r
+ * @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)\r
+ * @(#) Berlin University of Technology\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * 16-Bit CRC checksum\r
+ */\r
+public final class Crc16\r
+{\r
+ private static short polynomial=(short)0x8005;\r
+ private short crc;\r
+\r
+ /**\r
+ * Dummy Constructor\r
+ */\r
+ public Crc16()\r
+ { \r
+ crc = (short) 0xFFFF;\r
+ }\r
+\r
+ /**\r
+ * Feed a bitstring to the crc calculation (0 < length <= 32).\r
+ */\r
+ public void add_bits (int bitstring, int length)\r
+ {\r
+ int bitmask = 1 << (length - 1);\r
+ do\r
+ if (((crc & 0x8000) == 0) ^ ((bitstring & bitmask) == 0 ))\r
+ {\r
+ crc <<= 1;\r
+ crc ^= polynomial;\r
+ }\r
+ else\r
+ crc <<= 1;\r
+ while ((bitmask >>>= 1) != 0);\r
+ }\r
+\r
+ /**\r
+ * Return the calculated checksum.\r
+ * Erase it for next calls to add_bits().\r
+ */\r
+ public short checksum()\r
+ {\r
+ short sum = crc;\r
+ crc = (short) 0xFFFF;\r
+ return sum;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 01/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+ \r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * The <code>Decoder</code> class encapsulates the details of\r
+ * decoding an MPEG audio frame. \r
+ * \r
+ * @author MDM \r
+ * @version 0.0.7 12/12/99\r
+ * @since 0.0.5\r
+ */\r
+public class Decoder implements DecoderErrors\r
+{\r
+ static private final Params DEFAULT_PARAMS = new Params();\r
+ \r
+ /**\r
+ * The Bistream from which the MPEG audio frames are read.\r
+ */\r
+ //private Bitstream stream;\r
+ \r
+ /**\r
+ * The Obuffer instance that will receive the decoded\r
+ * PCM samples.\r
+ */\r
+ private Obuffer output;\r
+ \r
+ /**\r
+ * Synthesis filter for the left channel.\r
+ */\r
+ private SynthesisFilter filter1;\r
+ \r
+ /**\r
+ * Sythesis filter for the right channel.\r
+ */\r
+ private SynthesisFilter filter2; \r
+ \r
+ /**\r
+ * The decoder used to decode layer III frames.\r
+ */\r
+ private LayerIIIDecoder l3decoder;\r
+ private LayerIIDecoder l2decoder;\r
+ private LayerIDecoder l1decoder;\r
+ \r
+ private int outputFrequency;\r
+ private int outputChannels;\r
+ \r
+ private Equalizer equalizer = new Equalizer();\r
+ \r
+ private Params params;\r
+ \r
+ private boolean initialized;\r
+ \r
+ \r
+ /**\r
+ * Creates a new <code>Decoder</code> instance with default \r
+ * parameters.\r
+ */\r
+ \r
+ public Decoder()\r
+ {\r
+ this(null);\r
+ }\r
+\r
+ /**\r
+ * Creates a new <code>Decoder</code> instance with default \r
+ * parameters.\r
+ * \r
+ * @param params The <code>Params</code> instance that describes\r
+ * the customizable aspects of the decoder. \r
+ */\r
+ public Decoder(Params params0)\r
+ {\r
+ if (params0==null)\r
+ params0 = DEFAULT_PARAMS;\r
+ \r
+ params = params0;\r
+ \r
+ Equalizer eq = params.getInitialEqualizerSettings();\r
+ if (eq!=null)\r
+ {\r
+ equalizer.setFrom(eq);\r
+ }\r
+ }\r
+ \r
+ static public Params getDefaultParams()\r
+ {\r
+ return (Params)DEFAULT_PARAMS.clone();\r
+ }\r
+ \r
+ public void setEqualizer(Equalizer eq)\r
+ {\r
+ if (eq==null)\r
+ eq = Equalizer.PASS_THRU_EQ;\r
+ \r
+ equalizer.setFrom(eq);\r
+ \r
+ float[] factors = equalizer.getBandFactors();\r
+\r
+ if (filter1!=null)\r
+ filter1.setEQ(factors);\r
+ \r
+ if (filter2!=null)\r
+ filter2.setEQ(factors); \r
+ }\r
+ \r
+ /**\r
+ * Decodes one frame from an MPEG audio bitstream.\r
+ * \r
+ * @param header The header describing the frame to decode.\r
+ * @param bitstream The bistream that provides the bits for te body of the frame. \r
+ * \r
+ * @return A SampleBuffer containing the decoded samples.\r
+ */\r
+ public Obuffer decodeFrame(Header header, Bitstream stream)\r
+ throws DecoderException\r
+ {\r
+ if (!initialized)\r
+ {\r
+ initialize(header);\r
+ }\r
+ \r
+ int layer = header.layer();\r
+ \r
+ output.clear_buffer();\r
+ \r
+ FrameDecoder decoder = retrieveDecoder(header, stream, layer);\r
+ \r
+ decoder.decodeFrame();\r
+ \r
+ output.write_buffer(1);\r
+ \r
+ return output; \r
+ }\r
+ \r
+ /**\r
+ * Changes the output buffer. This will take effect the next time\r
+ * decodeFrame() is called. \r
+ */\r
+ public void setOutputBuffer(Obuffer out)\r
+ {\r
+ output = out;\r
+ }\r
+ \r
+ /**\r
+ * Retrieves the sample frequency of the PCM samples output\r
+ * by this decoder. This typically corresponds to the sample\r
+ * rate encoded in the MPEG audio stream.\r
+ * \r
+ * @param the sample rate (in Hz) of the samples written to the\r
+ * output buffer when decoding. \r
+ */\r
+ public int getOutputFrequency()\r
+ {\r
+ return outputFrequency;\r
+ }\r
+ \r
+ /**\r
+ * Retrieves the number of channels of PCM samples output by\r
+ * this decoder. This usually corresponds to the number of\r
+ * channels in the MPEG audio stream, although it may differ.\r
+ * \r
+ * @return The number of output channels in the decoded samples: 1 \r
+ * for mono, or 2 for stereo.\r
+ * \r
+ */\r
+ public int getOutputChannels()\r
+ {\r
+ return outputChannels; \r
+ }\r
+ \r
+ /**\r
+ * Retrieves the maximum number of samples that will be written to\r
+ * the output buffer when one frame is decoded. This can be used to\r
+ * help calculate the size of other buffers whose size is based upon \r
+ * the number of samples written to the output buffer. NB: this is\r
+ * an upper bound and fewer samples may actually be written, depending\r
+ * upon the sample rate and number of channels.\r
+ * \r
+ * @return The maximum number of samples that are written to the \r
+ * output buffer when decoding a single frame of MPEG audio.\r
+ */\r
+ public int getOutputBlockSize()\r
+ {\r
+ return Obuffer.OBUFFERSIZE;\r
+ }\r
+ \r
+ \r
+ protected DecoderException newDecoderException(int errorcode)\r
+ {\r
+ return new DecoderException(errorcode, null);\r
+ }\r
+ \r
+ protected DecoderException newDecoderException(int errorcode, Throwable throwable)\r
+ {\r
+ return new DecoderException(errorcode, throwable);\r
+ }\r
+ \r
+ protected FrameDecoder retrieveDecoder(Header header, Bitstream stream, int layer)\r
+ throws DecoderException\r
+ {\r
+ FrameDecoder decoder = null;\r
+ \r
+ // REVIEW: allow channel output selection type\r
+ // (LEFT, RIGHT, BOTH, DOWNMIX)\r
+ switch (layer)\r
+ {\r
+ case 3:\r
+ if (l3decoder==null)\r
+ {\r
+ l3decoder = new LayerIIIDecoder(stream, \r
+ header, filter1, filter2, \r
+ output, OutputChannels.BOTH_CHANNELS);\r
+ } \r
+ \r
+ decoder = l3decoder;\r
+ break;\r
+ case 2:\r
+ if (l2decoder==null)\r
+ {\r
+ l2decoder = new LayerIIDecoder();\r
+ l2decoder.create(stream, \r
+ header, filter1, filter2, \r
+ output, OutputChannels.BOTH_CHANNELS); \r
+ }\r
+ decoder = l2decoder;\r
+ break;\r
+ case 1:\r
+ if (l1decoder==null)\r
+ {\r
+ l1decoder = new LayerIDecoder();\r
+ l1decoder.create(stream, \r
+ header, filter1, filter2, \r
+ output, OutputChannels.BOTH_CHANNELS); \r
+ }\r
+ decoder = l1decoder;\r
+ break;\r
+ }\r
+ \r
+ if (decoder==null)\r
+ {\r
+ throw newDecoderException(UNSUPPORTED_LAYER, null);\r
+ }\r
+ \r
+ return decoder;\r
+ }\r
+ \r
+ private void initialize(Header header)\r
+ throws DecoderException\r
+ {\r
+ \r
+ // REVIEW: allow customizable scale factor\r
+ float scalefactor = 32700.0f;\r
+ \r
+ int mode = header.mode();\r
+ int layer = header.layer();\r
+ int channels = mode==Header.SINGLE_CHANNEL ? 1 : 2;\r
+\r
+ \r
+ // set up output buffer if not set up by client.\r
+ if (output==null)\r
+ output = new SampleBuffer(header.frequency(), channels);\r
+ \r
+ float[] factors = equalizer.getBandFactors();\r
+ filter1 = new SynthesisFilter(0, scalefactor, factors);\r
+ \r
+ // REVIEW: allow mono output for stereo\r
+ if (channels==2) \r
+ filter2 = new SynthesisFilter(1, scalefactor, factors);\r
+\r
+ outputChannels = channels;\r
+ outputFrequency = header.frequency();\r
+ \r
+ initialized = true;\r
+ }\r
+ \r
+ /**\r
+ * The <code>Params</code> class presents the customizable\r
+ * aspects of the decoder. \r
+ * <p>\r
+ * Instances of this class are not thread safe. \r
+ */\r
+ public static class Params implements Cloneable\r
+ {\r
+ private OutputChannels outputChannels = OutputChannels.BOTH;\r
+ \r
+ private Equalizer equalizer = new Equalizer();\r
+ \r
+ public Params()\r
+ { \r
+ }\r
+ \r
+ public Object clone()\r
+ {\r
+ try\r
+ {\r
+ return super.clone();\r
+ }\r
+ catch (CloneNotSupportedException ex)\r
+ { \r
+ throw new InternalError(this+": "+ex);\r
+ }\r
+ }\r
+ \r
+ public void setOutputChannels(OutputChannels out)\r
+ {\r
+ if (out==null)\r
+ throw new NullPointerException("out");\r
+ \r
+ outputChannels = out;\r
+ }\r
+ \r
+ public OutputChannels getOutputChannels()\r
+ {\r
+ return outputChannels;\r
+ }\r
+ \r
+ /**\r
+ * Retrieves the equalizer settings that the decoder's equalizer\r
+ * will be initialized from.\r
+ * <p>\r
+ * The <code>Equalizer</code> instance returned \r
+ * cannot be changed in real time to affect the \r
+ * decoder output as it is used only to initialize the decoders\r
+ * EQ settings. To affect the decoder's output in realtime,\r
+ * use the Equalizer returned from the getEqualizer() method on\r
+ * the decoder. \r
+ * \r
+ * @return The <code>Equalizer</code> used to initialize the\r
+ * EQ settings of the decoder. \r
+ */\r
+ public Equalizer getInitialEqualizerSettings()\r
+ {\r
+ return equalizer; \r
+ }\r
+ \r
+ };\r
+}\r
+\r
--- /dev/null
+/*\r
+ * 09/26/08 throw exception on subbband alloc error: Christopher G. Jennings (cjennings@acm.org)\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 01/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * This interface provides constants describing the error\r
+ * codes used by the Decoder to indicate errors. \r
+ * \r
+ * @author MDM\r
+ */\r
+public interface DecoderErrors extends JavaLayerErrors\r
+{\r
+ \r
+ static public final int UNKNOWN_ERROR = DECODER_ERROR + 0;\r
+ \r
+ /**\r
+ * Layer not supported by the decoder. \r
+ */\r
+ static public final int UNSUPPORTED_LAYER = DECODER_ERROR + 1;\r
+\r
+ /**\r
+ * Illegal allocation in subband layer. Indicates a corrupt stream.\r
+ */\r
+ static public final int ILLEGAL_SUBBAND_ALLOCATION = DECODER_ERROR + 2;\r
+\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 01/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * The <code>DecoderException</code> represents the class of\r
+ * errors that can occur when decoding MPEG audio. \r
+ * \r
+ * @author MDM\r
+ */\r
+public class DecoderException extends JavaLayerException\r
+ implements DecoderErrors\r
+{ \r
+ private int errorcode = UNKNOWN_ERROR;\r
+ \r
+ public DecoderException(String msg, Throwable t)\r
+ {\r
+ super(msg, t); \r
+ }\r
+ \r
+ public DecoderException(int errorcode, Throwable t)\r
+ {\r
+ this(getErrorString(errorcode), t);\r
+ this.errorcode = errorcode;\r
+ }\r
+ \r
+ public int getErrorCode()\r
+ {\r
+ return errorcode; \r
+ }\r
+ \r
+ \r
+ static public String getErrorString(int errorcode)\r
+ {\r
+ // REVIEW: use resource file to map error codes\r
+ // to locale-sensitive strings. \r
+ \r
+ return "Decoder errorcode "+Integer.toHexString(errorcode);\r
+ }\r
+ \r
+ \r
+}\r
+\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 12/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * The <code>Equalizer</code> class can be used to specify\r
+ * equalization settings for the MPEG audio decoder. \r
+ * <p>\r
+ * The equalizer consists of 32 band-pass filters. \r
+ * Each band of the equalizer can take on a fractional value between \r
+ * -1.0 and +1.0.\r
+ * At -1.0, the input signal is attenuated by 6dB, at +1.0 the signal is\r
+ * amplified by 6dB. \r
+ * \r
+ * @see Decoder\r
+ * \r
+ * @author MDM\r
+ */\r
+public final class Equalizer\r
+{ \r
+ /**\r
+ * Equalizer setting to denote that a given band will not be\r
+ * present in the output signal.\r
+ */\r
+ static public final float BAND_NOT_PRESENT = Float.NEGATIVE_INFINITY;\r
+ \r
+ static public final Equalizer PASS_THRU_EQ = new Equalizer();\r
+ \r
+ private static final int BANDS = 32;\r
+ \r
+ private final float[] settings = new float[BANDS];\r
+ \r
+ /**\r
+ * Creates a new <code>Equalizer</code> instance. \r
+ */\r
+ public Equalizer()\r
+ { \r
+ }\r
+ \r
+// private Equalizer(float b1, float b2, float b3, float b4, float b5,\r
+// float b6, float b7, float b8, float b9, float b10, float b11,\r
+// float b12, float b13, float b14, float b15, float b16,\r
+// float b17, float b18, float b19, float b20);\r
+\r
+ public Equalizer(float[] settings)\r
+ {\r
+ setFrom(settings);\r
+ }\r
+ \r
+ public Equalizer(EQFunction eq)\r
+ {\r
+ setFrom(eq);\r
+ }\r
+ \r
+ public void setFrom(float[] eq)\r
+ {\r
+ reset();\r
+ int max = (eq.length > BANDS) ? BANDS : eq.length;\r
+ \r
+ for (int i=0; i<max; i++)\r
+ {\r
+ settings[i] = limit(eq[i]);\r
+ }\r
+ }\r
+\r
+ public void setFrom(EQFunction eq)\r
+ {\r
+ reset();\r
+ int max = BANDS;\r
+ \r
+ for (int i=0; i<max; i++)\r
+ {\r
+ settings[i] = limit(eq.getBand(i));\r
+ } \r
+ }\r
+ \r
+ /**\r
+ * Sets the bands of this equalizer to the value the bands of\r
+ * another equalizer. Bands that are not present in both equalizers are ignored. \r
+ */\r
+ public void setFrom(Equalizer eq)\r
+ {\r
+ if (eq!=this)\r
+ {\r
+ setFrom(eq.settings);\r
+ }\r
+ }\r
+ \r
+ \r
+ \r
+ \r
+ /**\r
+ * Sets all bands to 0.0\r
+ */\r
+ public void reset()\r
+ {\r
+ for (int i=0; i<BANDS; i++)\r
+ {\r
+ settings[i] = 0.0f;\r
+ }\r
+ }\r
+\r
+ \r
+ /**\r
+ * Retrieves the number of bands present in this equalizer.\r
+ */\r
+ public int getBandCount()\r
+ {\r
+ return settings.length; \r
+ }\r
+ \r
+ public float setBand(int band, float neweq)\r
+ {\r
+ float eq = 0.0f;\r
+ \r
+ if ((band>=0) && (band<BANDS))\r
+ {\r
+ eq = settings[band];\r
+ settings[band] = limit(neweq);\r
+ }\r
+ \r
+ return eq; \r
+ }\r
+ \r
+ \r
+ \r
+ /**\r
+ * Retrieves the eq setting for a given band.\r
+ */\r
+ public float getBand(int band)\r
+ {\r
+ float eq = 0.0f;\r
+ \r
+ if ((band>=0) && (band<BANDS))\r
+ {\r
+ eq = settings[band];\r
+ }\r
+ \r
+ return eq;\r
+ }\r
+ \r
+ private float limit(float eq)\r
+ {\r
+ if (eq==BAND_NOT_PRESENT)\r
+ return eq;\r
+ if (eq > 1.0f)\r
+ return 1.0f;\r
+ if (eq < -1.0f)\r
+ return -1.0f;\r
+ \r
+ return eq;\r
+ }\r
+ \r
+ /**\r
+ * Retrieves an array of floats whose values represent a\r
+ * scaling factor that can be applied to linear samples\r
+ * in each band to provide the equalization represented by\r
+ * this instance. \r
+ * \r
+ * @return an array of factors that can be applied to the\r
+ * subbands.\r
+ */\r
+ float[] getBandFactors()\r
+ {\r
+ float[] factors = new float[BANDS];\r
+ for (int i=0, maxCount=BANDS; i<maxCount; i++)\r
+ {\r
+ factors[i] = getBandFactor(settings[i]);\r
+ }\r
+ \r
+ return factors;\r
+ }\r
+ \r
+ /**\r
+ * Converts an equalizer band setting to a sample factor.\r
+ * The factor is determined by the function f = 2^n where\r
+ * n is the equalizer band setting in the range [-1.0,1.0].\r
+ * \r
+ */\r
+ float getBandFactor(float eq)\r
+ {\r
+ if (eq==BAND_NOT_PRESENT)\r
+ return 0.0f;\r
+ \r
+ float f = (float)Math.pow(2.0, eq);\r
+ return f;\r
+ }\r
+ \r
+ \r
+ static abstract public class EQFunction\r
+ {\r
+ /**\r
+ * Returns the setting of a band in the equalizer. \r
+ * \r
+ * @param band The index of the band to retrieve the setting\r
+ * for. \r
+ * \r
+ * @return the setting of the specified band. This is a value between\r
+ * -1 and +1.\r
+ */\r
+ public float getBand(int band)\r
+ {\r
+ return 0.0f; \r
+ }\r
+ \r
+ }\r
+ \r
+}\r
--- /dev/null
+/*\r
+ * 09/26/08 throw exception on subbband alloc error: Christopher G. Jennings (cjennings@acm.org)\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 12/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * Implementations of FrameDecoder are responsible for decoding\r
+ * an MPEG audio frame.\r
+ * \r
+ */\r
+//REVIEW: the interface currently is too thin. There should be\r
+// methods to specify the output buffer, the synthesis filters and\r
+// possibly other objects used by the decoder. \r
+public interface FrameDecoder\r
+{\r
+ /**\r
+ * Decodes one frame of MPEG audio. \r
+ */\r
+ public void decodeFrame() throws DecoderException;\r
+ \r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 : 1.0 moved to LGPL.\r
+ * VBRI header support added, E.B javalayer@javazoom.net\r
+ * \r
+ * 12/04/03 : VBR (XING) header support added, E.B javalayer@javazoom.net\r
+ *\r
+ * 02/13/99 : Java Conversion by JavaZOOM , E.B javalayer@javazoom.net\r
+ *\r
+ * Declarations for MPEG header class\r
+ * A few layer III, MPEG-2 LSF, and seeking modifications made by Jeff Tsay.\r
+ * Last modified : 04/19/97\r
+ *\r
+ * @(#) header.h 1.7, last edit: 6/15/94 16:55:33\r
+ * @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)\r
+ * @(#) Berlin University of Technology\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * Class for extracting information from a frame header.\r
+ */\r
+public final class Header\r
+{\r
+ public static final int[][] frequencies =\r
+ {{22050, 24000, 16000, 1},\r
+ {44100, 48000, 32000, 1},\r
+ {11025, 12000, 8000, 1}}; // SZD: MPEG25\r
+\r
+ /**\r
+ * Constant for MPEG-2 LSF version\r
+ */\r
+ public static final int MPEG2_LSF = 0;\r
+ public static final int MPEG25_LSF = 2; // SZD\r
+\r
+ /**\r
+ * Constant for MPEG-1 version\r
+ */\r
+ public static final int MPEG1 = 1;\r
+\r
+ public static final int STEREO = 0;\r
+ public static final int JOINT_STEREO = 1;\r
+ public static final int DUAL_CHANNEL = 2;\r
+ public static final int SINGLE_CHANNEL = 3;\r
+ public static final int FOURTYFOUR_POINT_ONE = 0;\r
+ public static final int FOURTYEIGHT=1;\r
+ public static final int THIRTYTWO=2;\r
+\r
+ private int h_layer, h_protection_bit, h_bitrate_index,\r
+ h_padding_bit, h_mode_extension;\r
+ private int h_version;\r
+ private int h_mode;\r
+ private int h_sample_frequency;\r
+ private int h_number_of_subbands, h_intensity_stereo_bound;\r
+ private boolean h_copyright, h_original;\r
+ // VBR support added by E.B\r
+ private double[] h_vbr_time_per_frame = {-1, 384, 1152, 1152};\r
+ private boolean h_vbr;\r
+ private int h_vbr_frames;\r
+ private int h_vbr_scale;\r
+ private int h_vbr_bytes;\r
+ private byte[] h_vbr_toc;\r
+ \r
+ private byte syncmode = Bitstream.INITIAL_SYNC;\r
+ private Crc16 crc;\r
+\r
+ public short checksum;\r
+ public int framesize;\r
+ public int nSlots;\r
+\r
+ private int _headerstring = -1; // E.B\r
+\r
+ Header()\r
+ {\r
+ }\r
+ public String toString()\r
+ {\r
+ StringBuffer buffer = new StringBuffer(200);\r
+ buffer.append("Layer ");\r
+ buffer.append(layer_string());\r
+ buffer.append(" frame ");\r
+ buffer.append(mode_string());\r
+ buffer.append(' ');\r
+ buffer.append(version_string());\r
+ if (!checksums())\r
+ buffer.append(" no");\r
+ buffer.append(" checksums");\r
+ buffer.append(' ');\r
+ buffer.append(sample_frequency_string());\r
+ buffer.append(',');\r
+ buffer.append(' ');\r
+ buffer.append(bitrate_string());\r
+\r
+ String s = buffer.toString();\r
+ return s;\r
+ }\r
+\r
+ /**\r
+ * Read a 32-bit header from the bitstream.\r
+ */\r
+ void read_header(Bitstream stream, Crc16[] crcp) throws BitstreamException\r
+ {\r
+ int headerstring;\r
+ int channel_bitrate;\r
+ boolean sync = false;\r
+ do\r
+ {\r
+ headerstring = stream.syncHeader(syncmode);\r
+ _headerstring = headerstring; // E.B\r
+ if (syncmode == Bitstream.INITIAL_SYNC)\r
+ {\r
+ h_version = ((headerstring >>> 19) & 1);\r
+ if (((headerstring >>> 20) & 1) == 0) // SZD: MPEG2.5 detection\r
+ if (h_version == MPEG2_LSF)\r
+ h_version = MPEG25_LSF;\r
+ else\r
+ throw stream.newBitstreamException(Bitstream.UNKNOWN_ERROR);\r
+ if ((h_sample_frequency = ((headerstring >>> 10) & 3)) == 3)\r
+ {\r
+ throw stream.newBitstreamException(Bitstream.UNKNOWN_ERROR);\r
+ }\r
+ }\r
+ h_layer = 4 - (headerstring >>> 17) & 3;\r
+ h_protection_bit = (headerstring >>> 16) & 1;\r
+ h_bitrate_index = (headerstring >>> 12) & 0xF;\r
+ h_padding_bit = (headerstring >>> 9) & 1;\r
+ h_mode = ((headerstring >>> 6) & 3);\r
+ h_mode_extension = (headerstring >>> 4) & 3;\r
+ if (h_mode == JOINT_STEREO)\r
+ h_intensity_stereo_bound = (h_mode_extension << 2) + 4;\r
+ else\r
+ h_intensity_stereo_bound = 0; // should never be used\r
+ if (((headerstring >>> 3) & 1) == 1)\r
+ h_copyright = true;\r
+ if (((headerstring >>> 2) & 1) == 1)\r
+ h_original = true;\r
+ // calculate number of subbands:\r
+ if (h_layer == 1)\r
+ h_number_of_subbands = 32;\r
+ else\r
+ {\r
+ channel_bitrate = h_bitrate_index;\r
+ // calculate bitrate per channel:\r
+ if (h_mode != SINGLE_CHANNEL)\r
+ if (channel_bitrate == 4)\r
+ channel_bitrate = 1;\r
+ else\r
+ channel_bitrate -= 4;\r
+ if ((channel_bitrate == 1) || (channel_bitrate == 2))\r
+ if (h_sample_frequency == THIRTYTWO)\r
+ h_number_of_subbands = 12;\r
+ else\r
+ h_number_of_subbands = 8;\r
+ else if ((h_sample_frequency == FOURTYEIGHT) || ((channel_bitrate >= 3) && (channel_bitrate <= 5)))\r
+ h_number_of_subbands = 27;\r
+ else\r
+ h_number_of_subbands = 30;\r
+ }\r
+ if (h_intensity_stereo_bound > h_number_of_subbands)\r
+ h_intensity_stereo_bound = h_number_of_subbands;\r
+ // calculate framesize and nSlots\r
+ calculate_framesize();\r
+ // read framedata:\r
+ int framesizeloaded = stream.read_frame_data(framesize);\r
+ if ((framesize >=0) && (framesizeloaded != framesize))\r
+ {\r
+ // Data loaded does not match to expected framesize,\r
+ // it might be an ID3v1 TAG. (Fix 11/17/04).\r
+ throw stream.newBitstreamException(Bitstream.INVALIDFRAME);\r
+ }\r
+ if (stream.isSyncCurrentPosition(syncmode))\r
+ {\r
+ if (syncmode == Bitstream.INITIAL_SYNC)\r
+ {\r
+ syncmode = Bitstream.STRICT_SYNC;\r
+ stream.set_syncword(headerstring & 0xFFF80CC0);\r
+ }\r
+ sync = true;\r
+ }\r
+ else\r
+ {\r
+ stream.unreadFrame();\r
+ }\r
+ }\r
+ while (!sync);\r
+ stream.parse_frame();\r
+ if (h_protection_bit == 0)\r
+ {\r
+ // frame contains a crc checksum\r
+ checksum = (short) stream.get_bits(16);\r
+ if (crc == null)\r
+ crc = new Crc16();\r
+ crc.add_bits(headerstring, 16);\r
+ crcp[0] = crc;\r
+ }\r
+ else\r
+ crcp[0] = null;\r
+ if (h_sample_frequency == FOURTYFOUR_POINT_ONE)\r
+ {\r
+ /*\r
+ if (offset == null)\r
+ {\r
+ int max = max_number_of_frames(stream);\r
+ offset = new int[max];\r
+ for(int i=0; i<max; i++) offset[i] = 0;\r
+ }\r
+ // E.B : Investigate more\r
+ int cf = stream.current_frame();\r
+ int lf = stream.last_frame();\r
+ if ((cf > 0) && (cf == lf))\r
+ {\r
+ offset[cf] = offset[cf-1] + h_padding_bit;\r
+ }\r
+ else\r
+ {\r
+ offset[0] = h_padding_bit;\r
+ }\r
+ */\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Parse frame to extract optionnal VBR frame.\r
+ * @param firstframe\r
+ * @author E.B (javalayer@javazoom.net)\r
+ */\r
+ void parseVBR(byte[] firstframe) throws BitstreamException\r
+ {\r
+ // Trying Xing header.\r
+ String xing = "Xing";\r
+ byte tmp[] = new byte[4];\r
+ int offset = 0;\r
+ // Compute "Xing" offset depending on MPEG version and channels.\r
+ if (h_version == MPEG1) \r
+ {\r
+ if (h_mode == SINGLE_CHANNEL) offset=21-4;\r
+ else offset=36-4;\r
+ } \r
+ else \r
+ {\r
+ if (h_mode == SINGLE_CHANNEL) offset=13-4;\r
+ else offset = 21-4; \r
+ }\r
+ try\r
+ {\r
+ System.arraycopy(firstframe, offset, tmp, 0, 4);\r
+ // Is "Xing" ?\r
+ if (xing.equals(new String(tmp)))\r
+ {\r
+ //Yes.\r
+ h_vbr = true;\r
+ h_vbr_frames = -1;\r
+ h_vbr_bytes = -1;\r
+ h_vbr_scale = -1;\r
+ h_vbr_toc = new byte[100];\r
+ \r
+ int length = 4;\r
+ // Read flags.\r
+ byte flags[] = new byte[4];\r
+ System.arraycopy(firstframe, offset + length, flags, 0, flags.length);\r
+ length += flags.length;\r
+ // Read number of frames (if available).\r
+ if ((flags[3] & (byte) (1 << 0)) != 0)\r
+ {\r
+ System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);\r
+ h_vbr_frames = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;\r
+ length += 4; \r
+ }\r
+ // Read size (if available).\r
+ if ((flags[3] & (byte) (1 << 1)) != 0)\r
+ {\r
+ System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);\r
+ h_vbr_bytes = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;\r
+ length += 4; \r
+ }\r
+ // Read TOC (if available).\r
+ if ((flags[3] & (byte) (1 << 2)) != 0)\r
+ {\r
+ System.arraycopy(firstframe, offset + length, h_vbr_toc, 0, h_vbr_toc.length);\r
+ length += h_vbr_toc.length; \r
+ }\r
+ // Read scale (if available).\r
+ if ((flags[3] & (byte) (1 << 3)) != 0)\r
+ {\r
+ System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);\r
+ h_vbr_scale = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;\r
+ length += 4; \r
+ }\r
+ //System.out.println("VBR:"+xing+" Frames:"+ h_vbr_frames +" Size:"+h_vbr_bytes); \r
+ } \r
+ }\r
+ catch (ArrayIndexOutOfBoundsException e)\r
+ {\r
+ throw new BitstreamException("XingVBRHeader Corrupted",e);\r
+ }\r
+ \r
+ // Trying VBRI header. \r
+ String vbri = "VBRI";\r
+ offset = 36-4;\r
+ try\r
+ {\r
+ System.arraycopy(firstframe, offset, tmp, 0, 4);\r
+ // Is "VBRI" ?\r
+ if (vbri.equals(new String(tmp)))\r
+ {\r
+ //Yes.\r
+ h_vbr = true;\r
+ h_vbr_frames = -1;\r
+ h_vbr_bytes = -1;\r
+ h_vbr_scale = -1;\r
+ h_vbr_toc = new byte[100];\r
+ // Bytes. \r
+ int length = 4 + 6;\r
+ System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);\r
+ h_vbr_bytes = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;\r
+ length += 4; \r
+ // Frames. \r
+ System.arraycopy(firstframe, offset + length, tmp, 0, tmp.length);\r
+ h_vbr_frames = (tmp[0] << 24)&0xFF000000 | (tmp[1] << 16)&0x00FF0000 | (tmp[2] << 8)&0x0000FF00 | tmp[3]&0x000000FF;\r
+ length += 4; \r
+ //System.out.println("VBR:"+vbri+" Frames:"+ h_vbr_frames +" Size:"+h_vbr_bytes);\r
+ // TOC\r
+ // TODO \r
+ }\r
+ }\r
+ catch (ArrayIndexOutOfBoundsException e)\r
+ {\r
+ throw new BitstreamException("VBRIVBRHeader Corrupted",e);\r
+ }\r
+ }\r
+ \r
+ // Functions to query header contents:\r
+ /**\r
+ * Returns version.\r
+ */\r
+ public int version() { return h_version; }\r
+\r
+ /**\r
+ * Returns Layer ID.\r
+ */\r
+ public int layer() { return h_layer; }\r
+\r
+ /**\r
+ * Returns bitrate index.\r
+ */\r
+ public int bitrate_index() { return h_bitrate_index; }\r
+\r
+ /**\r
+ * Returns Sample Frequency.\r
+ */\r
+ public int sample_frequency() { return h_sample_frequency; }\r
+\r
+ /**\r
+ * Returns Frequency.\r
+ */\r
+ public int frequency() {return frequencies[h_version][h_sample_frequency];}\r
+\r
+ /**\r
+ * Returns Mode.\r
+ */\r
+ public int mode() { return h_mode; }\r
+\r
+ /**\r
+ * Returns Protection bit.\r
+ */\r
+ public boolean checksums()\r
+ {\r
+ if (h_protection_bit == 0) return true;\r
+ else return false;\r
+ }\r
+\r
+ /**\r
+ * Returns Copyright.\r
+ */\r
+ public boolean copyright() { return h_copyright; }\r
+\r
+ /**\r
+ * Returns Original.\r
+ */\r
+ public boolean original() { return h_original; }\r
+\r
+ /**\r
+ * Return VBR.\r
+ * @return true if VBR header is found\r
+ */\r
+ public boolean vbr() { return h_vbr; }\r
+\r
+ /**\r
+ * Return VBR scale.\r
+ * @return scale of -1 if not available\r
+ */\r
+ public int vbr_scale() { return h_vbr_scale; }\r
+\r
+ /**\r
+ * Return VBR TOC.\r
+ * @return vbr toc ot null if not available\r
+ */\r
+ public byte[] vbr_toc() { return h_vbr_toc; }\r
+\r
+ /**\r
+ * Returns Checksum flag.\r
+ * Compares computed checksum with stream checksum.\r
+ */\r
+ public boolean checksum_ok () { return (checksum == crc.checksum()); }\r
+\r
+ // Seeking and layer III stuff\r
+ /**\r
+ * Returns Layer III Padding bit.\r
+ */\r
+ public boolean padding()\r
+ {\r
+ if (h_padding_bit == 0) return false;\r
+ else return true;\r
+ }\r
+\r
+ /**\r
+ * Returns Slots.\r
+ */\r
+ public int slots() { return nSlots; }\r
+\r
+ /**\r
+ * Returns Mode Extension.\r
+ */\r
+ public int mode_extension() { return h_mode_extension; }\r
+\r
+ // E.B -> private to public\r
+ public static final int bitrates[][][] = {\r
+ {{0 /*free format*/, 32000, 48000, 56000, 64000, 80000, 96000,\r
+ 112000, 128000, 144000, 160000, 176000, 192000 ,224000, 256000, 0},\r
+ {0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,\r
+ 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0},\r
+ {0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,\r
+ 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0}},\r
+\r
+ {{0 /*free format*/, 32000, 64000, 96000, 128000, 160000, 192000,\r
+ 224000, 256000, 288000, 320000, 352000, 384000, 416000, 448000, 0},\r
+ {0 /*free format*/, 32000, 48000, 56000, 64000, 80000, 96000,\r
+ 112000, 128000, 160000, 192000, 224000, 256000, 320000, 384000, 0},\r
+ {0 /*free format*/, 32000, 40000, 48000, 56000, 64000, 80000,\r
+ 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000, 0}},\r
+ // SZD: MPEG2.5\r
+ {{0 /*free format*/, 32000, 48000, 56000, 64000, 80000, 96000,\r
+ 112000, 128000, 144000, 160000, 176000, 192000 ,224000, 256000, 0},\r
+ {0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,\r
+ 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0},\r
+ {0 /*free format*/, 8000, 16000, 24000, 32000, 40000, 48000,\r
+ 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 0}},\r
+\r
+ };\r
+\r
+ // E.B -> private to public\r
+ /**\r
+ * Calculate Frame size.\r
+ * Calculates framesize in bytes excluding header size.\r
+ */\r
+ public int calculate_framesize()\r
+ {\r
+\r
+ if (h_layer == 1)\r
+ {\r
+ framesize = (12 * bitrates[h_version][0][h_bitrate_index]) /\r
+ frequencies[h_version][h_sample_frequency];\r
+ if (h_padding_bit != 0 ) framesize++;\r
+ framesize <<= 2; // one slot is 4 bytes long\r
+ nSlots = 0;\r
+ }\r
+ else\r
+ {\r
+ framesize = (144 * bitrates[h_version][h_layer - 1][h_bitrate_index]) /\r
+ frequencies[h_version][h_sample_frequency];\r
+ if (h_version == MPEG2_LSF || h_version == MPEG25_LSF) framesize >>= 1; // SZD\r
+ if (h_padding_bit != 0) framesize++;\r
+ // Layer III slots\r
+ if (h_layer == 3)\r
+ {\r
+ if (h_version == MPEG1)\r
+ {\r
+ nSlots = framesize - ((h_mode == SINGLE_CHANNEL) ? 17 : 32) // side info size\r
+ - ((h_protection_bit!=0) ? 0 : 2) // CRC size\r
+ - 4; // header size\r
+ }\r
+ else\r
+ { // MPEG-2 LSF, SZD: MPEG-2.5 LSF\r
+ nSlots = framesize - ((h_mode == SINGLE_CHANNEL) ? 9 : 17) // side info size\r
+ - ((h_protection_bit!=0) ? 0 : 2) // CRC size\r
+ - 4; // header size\r
+ }\r
+ }\r
+ else\r
+ {\r
+ nSlots = 0;\r
+ }\r
+ }\r
+ framesize -= 4; // subtract header size\r
+ return framesize;\r
+ }\r
+\r
+ /**\r
+ * Returns the maximum number of frames in the stream.\r
+ * @param streamsize\r
+ * @return number of frames\r
+ */\r
+ public int max_number_of_frames(int streamsize) // E.B\r
+ {\r
+ if (h_vbr == true) return h_vbr_frames;\r
+ else\r
+ {\r
+ if ((framesize + 4 - h_padding_bit) == 0) return 0;\r
+ else return(streamsize / (framesize + 4 - h_padding_bit));\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Returns the maximum number of frames in the stream.\r
+ * @param streamsize\r
+ * @return number of frames\r
+ */\r
+ public int min_number_of_frames(int streamsize) // E.B\r
+ {\r
+ if (h_vbr == true) return h_vbr_frames;\r
+ else\r
+ {\r
+ if ((framesize + 5 - h_padding_bit) == 0) return 0;\r
+ else return(streamsize / (framesize + 5 - h_padding_bit));\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * Returns ms/frame.\r
+ * @return milliseconds per frame\r
+ */\r
+ public float ms_per_frame() // E.B\r
+ {\r
+ if (h_vbr == true)\r
+ { \r
+ double tpf = h_vbr_time_per_frame[layer()] / frequency();\r
+ if ((h_version == MPEG2_LSF) || (h_version == MPEG25_LSF)) tpf /= 2;\r
+ return ((float) (tpf * 1000));\r
+ }\r
+ else\r
+ {\r
+ float ms_per_frame_array[][] = {{8.707483f, 8.0f, 12.0f},\r
+ {26.12245f, 24.0f, 36.0f},\r
+ {26.12245f, 24.0f, 36.0f}};\r
+ return(ms_per_frame_array[h_layer-1][h_sample_frequency]);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Returns total ms.\r
+ * @param streamsize\r
+ * @return total milliseconds\r
+ */\r
+ public float total_ms(int streamsize) // E.B\r
+ {\r
+ return(max_number_of_frames(streamsize) * ms_per_frame());\r
+ }\r
+\r
+ /**\r
+ * Returns synchronized header.\r
+ */\r
+ public int getSyncHeader() // E.B\r
+ {\r
+ return _headerstring;\r
+ }\r
+\r
+ // functions which return header informations as strings:\r
+ /**\r
+ * Return Layer version.\r
+ */\r
+ public String layer_string()\r
+ {\r
+ switch (h_layer)\r
+ {\r
+ case 1:\r
+ return "I";\r
+ case 2:\r
+ return "II";\r
+ case 3:\r
+ return "III";\r
+ }\r
+ return null;\r
+ }\r
+\r
+ // E.B -> private to public\r
+ public static final String bitrate_str[][][] = {\r
+ {{"free format", "32 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s",\r
+ "80 kbit/s", "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s",\r
+ "160 kbit/s", "176 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s",\r
+ "forbidden"},\r
+ {"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",\r
+ "40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",\r
+ "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",\r
+ "forbidden"},\r
+ {"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",\r
+ "40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",\r
+ "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",\r
+ "forbidden"}},\r
+\r
+ {{"free format", "32 kbit/s", "64 kbit/s", "96 kbit/s", "128 kbit/s",\r
+ "160 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s", "288 kbit/s",\r
+ "320 kbit/s", "352 kbit/s", "384 kbit/s", "416 kbit/s", "448 kbit/s",\r
+ "forbidden"},\r
+ {"free format", "32 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s",\r
+ "80 kbit/s", "96 kbit/s", "112 kbit/s", "128 kbit/s", "160 kbit/s",\r
+ "192 kbit/s", "224 kbit/s", "256 kbit/s", "320 kbit/s", "384 kbit/s",\r
+ "forbidden"},\r
+ {"free format", "32 kbit/s", "40 kbit/s", "48 kbit/s", "56 kbit/s",\r
+ "64 kbit/s", "80 kbit/s" , "96 kbit/s", "112 kbit/s", "128 kbit/s",\r
+ "160 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s", "320 kbit/s",\r
+ "forbidden"}},\r
+ // SZD: MPEG2.5\r
+ {{"free format", "32 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s",\r
+ "80 kbit/s", "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s",\r
+ "160 kbit/s", "176 kbit/s", "192 kbit/s", "224 kbit/s", "256 kbit/s",\r
+ "forbidden"},\r
+ {"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",\r
+ "40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",\r
+ "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",\r
+ "forbidden"},\r
+ {"free format", "8 kbit/s", "16 kbit/s", "24 kbit/s", "32 kbit/s",\r
+ "40 kbit/s", "48 kbit/s", "56 kbit/s", "64 kbit/s", "80 kbit/s",\r
+ "96 kbit/s", "112 kbit/s", "128 kbit/s", "144 kbit/s", "160 kbit/s",\r
+ "forbidden"}},\r
+ };\r
+\r
+ /**\r
+ * Return Bitrate.\r
+ * @return bitrate in bps\r
+ */\r
+ public String bitrate_string()\r
+ {\r
+ if (h_vbr == true)\r
+ {\r
+ return Integer.toString(bitrate()/1000)+" kb/s"; \r
+ }\r
+ else return bitrate_str[h_version][h_layer - 1][h_bitrate_index];\r
+ }\r
+\r
+ /**\r
+ * Return Bitrate.\r
+ * @return bitrate in bps and average bitrate for VBR header\r
+ */\r
+ public int bitrate()\r
+ {\r
+ if (h_vbr == true)\r
+ {\r
+ return ((int) ((h_vbr_bytes * 8) / (ms_per_frame() * h_vbr_frames)))*1000; \r
+ }\r
+ else return bitrates[h_version][h_layer - 1][h_bitrate_index];\r
+ }\r
+\r
+ /**\r
+ * Return Instant Bitrate.\r
+ * Bitrate for VBR is not constant.\r
+ * @return bitrate in bps\r
+ */\r
+ public int bitrate_instant()\r
+ {\r
+ return bitrates[h_version][h_layer - 1][h_bitrate_index];\r
+ }\r
+\r
+ /**\r
+ * Returns Frequency\r
+ * @return frequency string in kHz\r
+ */\r
+ public String sample_frequency_string()\r
+ {\r
+ switch (h_sample_frequency)\r
+ {\r
+ case THIRTYTWO:\r
+ if (h_version == MPEG1)\r
+ return "32 kHz";\r
+ else if (h_version == MPEG2_LSF)\r
+ return "16 kHz";\r
+ else // SZD\r
+ return "8 kHz";\r
+ case FOURTYFOUR_POINT_ONE:\r
+ if (h_version == MPEG1)\r
+ return "44.1 kHz";\r
+ else if (h_version == MPEG2_LSF)\r
+ return "22.05 kHz";\r
+ else // SZD\r
+ return "11.025 kHz";\r
+ case FOURTYEIGHT:\r
+ if (h_version == MPEG1)\r
+ return "48 kHz";\r
+ else if (h_version == MPEG2_LSF)\r
+ return "24 kHz";\r
+ else // SZD\r
+ return "12 kHz";\r
+ }\r
+ return(null);\r
+ }\r
+\r
+ /**\r
+ * Returns Mode.\r
+ */\r
+ public String mode_string()\r
+ {\r
+ switch (h_mode)\r
+ {\r
+ case STEREO:\r
+ return "Stereo";\r
+ case JOINT_STEREO:\r
+ return "Joint stereo";\r
+ case DUAL_CHANNEL:\r
+ return "Dual channel";\r
+ case SINGLE_CHANNEL:\r
+ return "Single channel";\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * Returns Version.\r
+ * @return MPEG-1 or MPEG-2 LSF or MPEG-2.5 LSF\r
+ */\r
+ public String version_string()\r
+ {\r
+ switch (h_version)\r
+ {\r
+ case MPEG1:\r
+ return "MPEG-1";\r
+ case MPEG2_LSF:\r
+ return "MPEG-2 LSF";\r
+ case MPEG25_LSF: // SZD\r
+ return "MPEG-2.5 LSF";\r
+ }\r
+ return(null);\r
+ }\r
+\r
+ /**\r
+ * Returns the number of subbands in the current frame.\r
+ * @return number of subbands\r
+ */\r
+ public int number_of_subbands() {return h_number_of_subbands;}\r
+\r
+ /**\r
+ * Returns Intensity Stereo.\r
+ * (Layer II joint stereo only).\r
+ * Returns the number of subbands which are in stereo mode,\r
+ * subbands above that limit are in intensity stereo mode.\r
+ * @return intensity\r
+ */\r
+ public int intensity_stereo_bound() {return h_intensity_stereo_bound;}\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 12/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+\r
+/**\r
+ * <i>Work In Progress.</i>\r
+ * \r
+ * An instance of <code>InputStreamSource</code> implements a\r
+ * <code>Source</code> that provides data from an <code>InputStream\r
+ * </code>. Seeking functionality is not supported. \r
+ * \r
+ * @author MDM\r
+ */\r
+public class InputStreamSource implements Source\r
+{\r
+ private final InputStream in;\r
+ \r
+ public InputStreamSource(InputStream in)\r
+ {\r
+ if (in==null)\r
+ throw new NullPointerException("in");\r
+ \r
+ this.in = in; \r
+ }\r
+ \r
+ public int read(byte[] b, int offs, int len)\r
+ throws IOException\r
+ {\r
+ int read = in.read(b, offs, len);\r
+ return read;\r
+ }\r
+ \r
+ public boolean willReadBlock()\r
+ {\r
+ return true;\r
+ //boolean block = (in.available()==0);\r
+ //return block;\r
+ }\r
+ \r
+ public boolean isSeekable()\r
+ {\r
+ return false; \r
+ }\r
+ \r
+ public long tell()\r
+ {\r
+ return -1; \r
+ }\r
+ \r
+ public long seek(long to)\r
+ {\r
+ return -1; \r
+ }\r
+ \r
+ public long length()\r
+ {\r
+ return -1;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 12/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * Work in progress.\r
+ * \r
+ * API usage errors may be handled by throwing an instance of this\r
+ * class, as per JMF 2.0. \r
+ */\r
+public class JavaLayerError extends Error\r
+{ \r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 12/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * Exception erorr codes for components of the JavaLayer API.\r
+ */\r
+public interface JavaLayerErrors\r
+{\r
+ /**\r
+ * The first bitstream error code. See the {@link DecoderErrors DecoderErrors}\r
+ * interface for other bitstream error codes.\r
+ */\r
+ static public final int BITSTREAM_ERROR = 0x100;\r
+\r
+ /**\r
+ * The first decoder error code. See the {@link DecoderErrors DecoderErrors}\r
+ * interface for other decoder error codes.\r
+ */\r
+ static public final int DECODER_ERROR = 0x200;\r
+\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 12/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+import java.io.PrintStream;\r
+\r
+\r
+/**\r
+ * The JavaLayerException is the base class for all API-level\r
+ * exceptions thrown by JavaLayer. To facilitate conversion and \r
+ * common handling of exceptions from other domains, the class \r
+ * can delegate some functionality to a contained Throwable instance. \r
+ * <p> \r
+ * \r
+ * @author MDM\r
+ */\r
+public class JavaLayerException extends Exception\r
+{\r
+ \r
+ private Throwable exception;\r
+ \r
+ \r
+ public JavaLayerException()\r
+ {\r
+ }\r
+ \r
+ public JavaLayerException(String msg)\r
+ {\r
+ super(msg);\r
+ }\r
+ \r
+ public JavaLayerException(String msg, Throwable t)\r
+ {\r
+ super(msg);\r
+ exception = t;\r
+ }\r
+ \r
+ public Throwable getException()\r
+ {\r
+ return exception; \r
+ }\r
+ \r
+ \r
+ public void printStackTrace()\r
+ {\r
+ printStackTrace(System.err); \r
+ }\r
+ \r
+ public void printStackTrace(PrintStream ps)\r
+ {\r
+ if (this.exception==null)\r
+ {\r
+ super.printStackTrace(ps); \r
+ }\r
+ else\r
+ {\r
+ exception.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ \r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+import java.io.InputStream;\r
+\r
+/**\r
+ * The <code>JavaLayerHooks</code> class allows developers to change\r
+ * the way the JavaLayer library uses Resources. \r
+ */\r
+\r
+public interface JavaLayerHook\r
+{\r
+ /**\r
+ * Retrieves the named resource. This allows resources to be\r
+ * obtained without specifying how they are retrieved. \r
+ */\r
+ public InputStream getResourceAsStream(String name);\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 12/12/99 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.InvalidClassException;\r
+import java.io.InvalidObjectException;\r
+import java.io.ObjectInputStream;\r
+import java.io.ObjectOutputStream;\r
+import java.io.OutputStream;\r
+import java.lang.reflect.Array;\r
+\r
+/**\r
+ * The JavaLayerUtils class is not strictly part of the JavaLayer API.\r
+ * It serves to provide useful methods and system-wide hooks.\r
+ * \r
+ * @author MDM\r
+ */\r
+public class JavaLayerUtils\r
+{\r
+ static private JavaLayerHook hook = null;\r
+ \r
+ /**\r
+ * Deserializes the object contained in the given input stream.\r
+ * @param in The input stream to deserialize an object from.\r
+ * @param cls The expected class of the deserialized object. \r
+ */\r
+ static public Object deserialize(InputStream in, Class cls)\r
+ throws IOException\r
+ {\r
+ if (cls==null)\r
+ throw new NullPointerException("cls");\r
+ \r
+ Object obj = deserialize(in, cls);\r
+ if (!cls.isInstance(obj))\r
+ {\r
+ throw new InvalidObjectException("type of deserialized instance not of required class.");\r
+ }\r
+ \r
+ return obj;\r
+ }\r
+ \r
+ /**\r
+ * Deserializes an object from the given <code>InputStream</code>.\r
+ * The deserialization is delegated to an <code>\r
+ * ObjectInputStream</code> instance. \r
+ * \r
+ * @param in The <code>InputStream</code> to deserialize an object\r
+ * from.\r
+ * \r
+ * @return The object deserialized from the stream. \r
+ * @exception IOException is thrown if there was a problem reading\r
+ * the underlying stream, or an object could not be deserialized\r
+ * from the stream.\r
+ * \r
+ * @see java.io.ObjectInputStream\r
+ */\r
+ static public Object deserialize(InputStream in)\r
+ throws IOException\r
+ {\r
+ if (in==null)\r
+ throw new NullPointerException("in");\r
+ \r
+ ObjectInputStream objIn = new ObjectInputStream(in);\r
+ \r
+ Object obj;\r
+ \r
+ try\r
+ {\r
+ obj = objIn.readObject();\r
+ }\r
+ catch (ClassNotFoundException ex)\r
+ {\r
+ throw new InvalidClassException(ex.toString());\r
+ }\r
+ \r
+ return obj;\r
+ }\r
+\r
+ /**\r
+ * Deserializes an array from a given <code>InputStream</code>.\r
+ * \r
+ * @param in The <code>InputStream</code> to \r
+ * deserialize an object from.\r
+ * \r
+ * @param elemType The class denoting the type of the array\r
+ * elements.\r
+ * @param length The expected length of the array, or -1 if\r
+ * any length is expected.\r
+ */\r
+ static public Object deserializeArray(InputStream in, Class elemType, int length)\r
+ throws IOException\r
+ {\r
+ if (elemType==null)\r
+ throw new NullPointerException("elemType");\r
+ \r
+ if (length<-1)\r
+ throw new IllegalArgumentException("length");\r
+ \r
+ Object obj = deserialize(in);\r
+ \r
+ Class cls = obj.getClass();\r
+ \r
+ \r
+ if (!cls.isArray())\r
+ throw new InvalidObjectException("object is not an array");\r
+ \r
+ Class arrayElemType = cls.getComponentType();\r
+ if (arrayElemType!=elemType)\r
+ throw new InvalidObjectException("unexpected array component type");\r
+ \r
+ if (length != -1)\r
+ {\r
+ int arrayLength = Array.getLength(obj);\r
+ if (arrayLength!=length)\r
+ throw new InvalidObjectException("array length mismatch");\r
+ }\r
+ \r
+ return obj;\r
+ }\r
+\r
+ static public Object deserializeArrayResource(String name, Class elemType, int length)\r
+ throws IOException\r
+ { \r
+ InputStream str = getResourceAsStream(name);\r
+ if (str==null)\r
+ throw new IOException("unable to load resource '"+name+"'");\r
+ \r
+ Object obj = deserializeArray(str, elemType, length);\r
+ \r
+ return obj;\r
+ } \r
+ \r
+ static public void serialize(OutputStream out, Object obj)\r
+ throws IOException\r
+ {\r
+ if (out==null)\r
+ throw new NullPointerException("out");\r
+ \r
+ if (obj==null)\r
+ throw new NullPointerException("obj");\r
+ \r
+ ObjectOutputStream objOut = new ObjectOutputStream(out);\r
+ objOut.writeObject(obj);\r
+ \r
+ }\r
+\r
+ /**\r
+ * Sets the system-wide JavaLayer hook.\r
+ */\r
+ static synchronized public void setHook(JavaLayerHook hook0) \r
+ {\r
+ hook = hook0;\r
+ }\r
+ \r
+ static synchronized public JavaLayerHook getHook()\r
+ {\r
+ return hook; \r
+ }\r
+ \r
+ /**\r
+ * Retrieves an InputStream for a named resource. \r
+ * \r
+ * @param name The name of the resource. This must be a simple\r
+ * name, and not a qualified package name.\r
+ * \r
+ * @return The InputStream for the named resource, or null if\r
+ * the resource has not been found. If a hook has been \r
+ * provided, its getResourceAsStream() method is called\r
+ * to retrieve the resource. \r
+ */\r
+ static synchronized public InputStream getResourceAsStream(String name)\r
+ {\r
+ InputStream is = null;\r
+ \r
+ if (hook!=null)\r
+ {\r
+ is = hook.getResourceAsStream(name); \r
+ }\r
+ else\r
+ {\r
+ Class cls = JavaLayerUtils.class;\r
+ is = cls.getResourceAsStream(name);\r
+ }\r
+ \r
+ return is; \r
+ }\r
+}\r
--- /dev/null
+/*
+ * 09/26/08 throw exception on subbband alloc error: Christopher G. Jennings (cjennings@acm.org)
+ *
+ * 11/19/04 1.0 moved to LGPL.
+ *
+ * 12/12/99 Initial version. Adapted from javalayer.java
+ * and Subband*.java. mdm@techie.com
+ *
+ * 02/28/99 Initial version : javalayer.java by E.B
+ *-----------------------------------------------------------------------
+ * 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;
+
+/**
+ * Implements decoding of MPEG Audio Layer I frames.
+ */
+class LayerIDecoder implements FrameDecoder
+{
+ protected Bitstream stream;
+ protected Header header;
+ protected SynthesisFilter filter1, filter2;
+ protected Obuffer buffer;
+ protected int which_channels;
+ protected int mode;
+
+ protected int num_subbands;
+ protected Subband[] subbands;
+ protected Crc16 crc = null; // new Crc16[1] to enable CRC checking.
+
+ public LayerIDecoder()
+ {
+ crc = new Crc16();
+ }
+
+ public void create(Bitstream stream0, Header header0,
+ SynthesisFilter filtera, SynthesisFilter filterb,
+ Obuffer buffer0, int which_ch0)
+ {
+ stream = stream0;
+ header = header0;
+ filter1 = filtera;
+ filter2 = filterb;
+ buffer = buffer0;
+ which_channels = which_ch0;
+
+ }
+
+ public void decodeFrame() throws DecoderException
+ {
+
+ num_subbands = header.number_of_subbands();
+ subbands = new Subband[32];
+ mode = header.mode();
+
+ createSubbands();
+
+ readAllocation();
+ readScaleFactorSelection();
+
+ if ((crc != null) || header.checksum_ok())
+ {
+ readScaleFactors();
+
+ readSampleData();
+ }
+
+ }
+
+ protected void createSubbands()
+ {
+ int i;
+ if (mode == Header.SINGLE_CHANNEL)
+ for (i = 0; i < num_subbands; ++i)
+ subbands[i] = new SubbandLayer1(i);
+ else if (mode == Header.JOINT_STEREO)
+ {
+ for (i = 0; i < header.intensity_stereo_bound(); ++i)
+ subbands[i] = new SubbandLayer1Stereo(i);
+ for (; i < num_subbands; ++i)
+ subbands[i] = new SubbandLayer1IntensityStereo(i);
+ }
+ else
+ {
+ for (i = 0; i < num_subbands; ++i)
+ subbands[i] = new SubbandLayer1Stereo(i);
+ }
+ }
+
+ protected void readAllocation() throws DecoderException
+ {
+ // start to read audio data:
+ for (int i = 0; i < num_subbands; ++i)
+ subbands[i].read_allocation(stream, header, crc);
+
+ }
+
+ protected void readScaleFactorSelection()
+ {
+ // scale factor selection not present for layer I.
+ }
+
+ protected void readScaleFactors()
+ {
+ for (int i = 0; i < num_subbands; ++i)
+ subbands[i].read_scalefactor(stream, header);
+ }
+
+ protected void readSampleData()
+ {
+ boolean read_ready = false;
+ boolean write_ready = false;
+ int mode = header.mode();
+ int i;
+ do
+ {
+ for (i = 0; i < num_subbands; ++i)
+ read_ready = subbands[i].read_sampledata(stream);
+ do
+ {
+ for (i = 0; i < num_subbands; ++i)
+ write_ready = subbands[i].put_next_sample(which_channels,filter1, filter2);
+
+ filter1.calculate_pcm_samples(buffer);
+ if ((which_channels == OutputChannels.BOTH_CHANNELS) && (mode != Header.SINGLE_CHANNEL))
+ filter2.calculate_pcm_samples(buffer);
+ } while (!write_ready);
+ } while (!read_ready);
+
+ }
+
+ /**
+ * Abstract base class for subband classes of layer I and II
+ */
+ static abstract class Subband
+ {
+ /*
+ * Changes from version 1.1 to 1.2:
+ * - array size increased by one, although a scalefactor with index 63
+ * is illegal (to prevent segmentation faults)
+ */
+ // Scalefactors for layer I and II, Annex 3-B.1 in ISO/IEC DIS 11172:
+ public static final float scalefactors[] =
+ {
+ 2.00000000000000f, 1.58740105196820f, 1.25992104989487f, 1.00000000000000f,
+ 0.79370052598410f, 0.62996052494744f, 0.50000000000000f, 0.39685026299205f,
+ 0.31498026247372f, 0.25000000000000f, 0.19842513149602f, 0.15749013123686f,
+ 0.12500000000000f, 0.09921256574801f, 0.07874506561843f, 0.06250000000000f,
+ 0.04960628287401f, 0.03937253280921f, 0.03125000000000f, 0.02480314143700f,
+ 0.01968626640461f, 0.01562500000000f, 0.01240157071850f, 0.00984313320230f,
+ 0.00781250000000f, 0.00620078535925f, 0.00492156660115f, 0.00390625000000f,
+ 0.00310039267963f, 0.00246078330058f, 0.00195312500000f, 0.00155019633981f,
+ 0.00123039165029f, 0.00097656250000f, 0.00077509816991f, 0.00061519582514f,
+ 0.00048828125000f, 0.00038754908495f, 0.00030759791257f, 0.00024414062500f,
+ 0.00019377454248f, 0.00015379895629f, 0.00012207031250f, 0.00009688727124f,
+ 0.00007689947814f, 0.00006103515625f, 0.00004844363562f, 0.00003844973907f,
+ 0.00003051757813f, 0.00002422181781f, 0.00001922486954f, 0.00001525878906f,
+ 0.00001211090890f, 0.00000961243477f, 0.00000762939453f, 0.00000605545445f,
+ 0.00000480621738f, 0.00000381469727f, 0.00000302772723f, 0.00000240310869f,
+ 0.00000190734863f, 0.00000151386361f, 0.00000120155435f, 0.00000000000000f /* illegal scalefactor */
+ };
+
+ public abstract void read_allocation (Bitstream stream, Header header, Crc16 crc) throws DecoderException;
+ public abstract void read_scalefactor (Bitstream stream, Header header);
+ public abstract boolean read_sampledata (Bitstream stream);
+ public abstract boolean put_next_sample (int channels, SynthesisFilter filter1, SynthesisFilter filter2);
+ };
+
+ /**
+ * Class for layer I subbands in single channel mode.
+ * Used for single channel mode
+ * and in derived class for intensity stereo mode
+ */
+ static class SubbandLayer1 extends Subband
+ {
+
+ // Factors and offsets for sample requantization
+ public static final float table_factor[] = {
+ 0.0f, (1.0f/2.0f) * (4.0f/3.0f), (1.0f/4.0f) * (8.0f/7.0f), (1.0f/8.0f) * (16.0f/15.0f),
+ (1.0f/16.0f) * (32.0f/31.0f), (1.0f/32.0f) * (64.0f/63.0f), (1.0f/64.0f) * (128.0f/127.0f),
+ (1.0f/128.0f) * (256.0f/255.0f), (1.0f/256.0f) * (512.0f/511.0f),
+ (1.0f/512.0f) * (1024.0f/1023.0f), (1.0f/1024.0f) * (2048.0f/2047.0f),
+ (1.0f/2048.0f) * (4096.0f/4095.0f), (1.0f/4096.0f) * (8192.0f/8191.0f),
+ (1.0f/8192.0f) * (16384.0f/16383.0f), (1.0f/16384.0f) * (32768.0f/32767.0f)
+ };
+
+ public static final float table_offset[] = {
+ 0.0f, ((1.0f/2.0f)-1.0f) * (4.0f/3.0f), ((1.0f/4.0f)-1.0f) * (8.0f/7.0f), ((1.0f/8.0f)-1.0f) * (16.0f/15.0f),
+ ((1.0f/16.0f)-1.0f) * (32.0f/31.0f), ((1.0f/32.0f)-1.0f) * (64.0f/63.0f), ((1.0f/64.0f)-1.0f) * (128.0f/127.0f),
+ ((1.0f/128.0f)-1.0f) * (256.0f/255.0f), ((1.0f/256.0f)-1.0f) * (512.0f/511.0f),
+ ((1.0f/512.0f)-1.0f) * (1024.0f/1023.0f), ((1.0f/1024.0f)-1.0f) * (2048.0f/2047.0f),
+ ((1.0f/2048.0f)-1.0f) * (4096.0f/4095.0f), ((1.0f/4096.0f)-1.0f) * (8192.0f/8191.0f),
+ ((1.0f/8192.0f)-1.0f) * (16384.0f/16383.0f), ((1.0f/16384.0f)-1.0f) * (32768.0f/32767.0f)
+ };
+
+ protected int subbandnumber;
+ protected int samplenumber;
+ protected int allocation;
+ protected float scalefactor;
+ protected int samplelength;
+ protected float sample;
+ protected float factor, offset;
+
+ /**
+ * Construtor.
+ */
+ public SubbandLayer1(int subbandnumber)
+ {
+ this.subbandnumber = subbandnumber;
+ samplenumber = 0;
+ }
+
+ /**
+ *
+ */
+ public void read_allocation(Bitstream stream, Header header, Crc16 crc) throws DecoderException
+ {
+ if ((allocation = stream.get_bits (4)) == 15)
+ {
+ // CGJ: catch this condition and throw appropriate exception
+ throw new DecoderException(DecoderErrors.ILLEGAL_SUBBAND_ALLOCATION, null);
+ // cerr << "WARNING: stream contains an illegal allocation!\n";
+ // MPEG-stream is corrupted!
+ }
+
+ if (crc != null) crc.add_bits (allocation, 4);
+ if (allocation != 0)
+ {
+ samplelength = allocation + 1;
+ factor = table_factor[allocation];
+ offset = table_offset[allocation];
+ }
+ }
+
+ /**
+ *
+ */
+ public void read_scalefactor(Bitstream stream, Header header)
+ {
+ if (allocation != 0) scalefactor = scalefactors[stream.get_bits(6)];
+ }
+
+ /**
+ *
+ */
+ public boolean read_sampledata(Bitstream stream)
+ {
+ if (allocation != 0)
+ {
+ sample = (float) (stream.get_bits(samplelength));
+ }
+ if (++samplenumber == 12)
+ {
+ samplenumber = 0;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ *
+ */
+ public boolean put_next_sample(int channels, SynthesisFilter filter1, SynthesisFilter filter2)
+ {
+ if ((allocation !=0) && (channels != OutputChannels.RIGHT_CHANNEL))
+ {
+ float scaled_sample = (sample * factor + offset) * scalefactor;
+ filter1.input_sample (scaled_sample, subbandnumber);
+ }
+ return true;
+ }
+ };
+
+ /**
+ * Class for layer I subbands in joint stereo mode.
+ */
+ static class SubbandLayer1IntensityStereo extends SubbandLayer1
+ {
+ protected float channel2_scalefactor;
+
+ /**
+ * Constructor
+ */
+ public SubbandLayer1IntensityStereo(int subbandnumber)
+ {
+ super(subbandnumber);
+ }
+
+ /**
+ *
+ */
+ public void read_allocation(Bitstream stream, Header header, Crc16 crc) throws DecoderException
+ {
+ super.read_allocation (stream, header, crc);
+ }
+
+ /**
+ *
+ */
+ public void read_scalefactor (Bitstream stream, Header header)
+ {
+ if (allocation != 0)
+ {
+ scalefactor = scalefactors[stream.get_bits(6)];
+ channel2_scalefactor = scalefactors[stream.get_bits(6)];
+ }
+ }
+
+ /**
+ *
+ */
+ public boolean read_sampledata(Bitstream stream)
+ {
+ return super.read_sampledata (stream);
+ }
+
+ /**
+ *
+ */
+ public boolean put_next_sample (int channels, SynthesisFilter filter1, SynthesisFilter filter2)
+ {
+ if (allocation !=0 )
+ {
+ sample = sample * factor + offset; // requantization
+ if (channels == OutputChannels.BOTH_CHANNELS)
+ {
+ float sample1 = sample * scalefactor,
+ sample2 = sample * channel2_scalefactor;
+ filter1.input_sample(sample1, subbandnumber);
+ filter2.input_sample(sample2, subbandnumber);
+ }
+ else if (channels == OutputChannels.LEFT_CHANNEL)
+ {
+ float sample1 = sample * scalefactor;
+ filter1.input_sample(sample1, subbandnumber);
+ }
+ else
+ {
+ float sample2 = sample * channel2_scalefactor;
+ filter1.input_sample(sample2, subbandnumber);
+ }
+ }
+ return true;
+ }
+ };
+
+ /**
+ * Class for layer I subbands in stereo mode.
+ */
+ static class SubbandLayer1Stereo extends SubbandLayer1
+ {
+ protected int channel2_allocation;
+ protected float channel2_scalefactor;
+ protected int channel2_samplelength;
+ protected float channel2_sample;
+ protected float channel2_factor, channel2_offset;
+
+
+ /**
+ * Constructor
+ */
+ public SubbandLayer1Stereo(int subbandnumber)
+ {
+ super(subbandnumber);
+ }
+
+ /**
+ *
+ */
+ public void read_allocation (Bitstream stream, Header header, Crc16 crc) throws DecoderException
+ {
+ allocation = stream.get_bits(4);
+ channel2_allocation = stream.get_bits(4);
+ if (crc != null)
+ {
+ crc.add_bits (allocation, 4);
+ crc.add_bits (channel2_allocation, 4);
+ }
+ if (allocation != 0)
+ {
+ samplelength = allocation + 1;
+ factor = table_factor[allocation];
+ offset = table_offset[allocation];
+ }
+ if (channel2_allocation != 0)
+ {
+ channel2_samplelength = channel2_allocation + 1;
+ channel2_factor = table_factor[channel2_allocation];
+ channel2_offset = table_offset[channel2_allocation];
+ }
+ }
+
+ /**
+ *
+ */
+ public void read_scalefactor(Bitstream stream, Header header)
+ {
+ if (allocation != 0) scalefactor = scalefactors[stream.get_bits(6)];
+ if (channel2_allocation != 0) channel2_scalefactor = scalefactors[stream.get_bits(6)];
+ }
+
+ /**
+ *
+ */
+ public boolean read_sampledata (Bitstream stream)
+ {
+ boolean returnvalue = super.read_sampledata(stream);
+ if (channel2_allocation != 0)
+ {
+ channel2_sample = (float) (stream.get_bits(channel2_samplelength));
+ }
+ return(returnvalue);
+ }
+
+ /**
+ *
+ */
+ public boolean put_next_sample(int channels, SynthesisFilter filter1, SynthesisFilter filter2)
+ {
+ super.put_next_sample (channels, filter1, filter2);
+ if ((channel2_allocation != 0) && (channels != OutputChannels.LEFT_CHANNEL))
+ {
+ float sample2 = (channel2_sample * channel2_factor + channel2_offset) *
+ channel2_scalefactor;
+ if (channels == OutputChannels.BOTH_CHANNELS)
+ filter2.input_sample (sample2, subbandnumber);
+ else
+ filter1.input_sample (sample2, subbandnumber);
+ }
+ return true;
+ }
+ };
+
+}
--- /dev/null
+/*
+ * 11/19/04 1.0 moved to LGPL.
+ *
+ * 29/05/01 Michael Scheerer, Fixed some C++ to Java porting bugs.
+ *
+ * 16/07/01 Michael Scheerer, Catched a bug in method
+ * read_sampledata, which causes an outOfIndexException.
+ *
+ * 12/12/99 Initial version. Adapted from javalayer.java
+ * and Subband*.java. mdm@techie.com
+ *
+ * 02/28/99 Initial version : javalayer.java by E.B
+ *-----------------------------------------------------------------------
+ * 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;
+
+/**
+ * Implements decoding of MPEG Audio Layer II frames.
+ */
+class LayerIIDecoder extends LayerIDecoder implements FrameDecoder
+{
+
+ public LayerIIDecoder()
+ {
+ }
+
+
+ protected void createSubbands()
+ {
+ int i;
+ if (mode == Header.SINGLE_CHANNEL)
+ for (i = 0; i < num_subbands; ++i)
+ subbands[i] = new SubbandLayer2(i);
+ else if (mode == Header.JOINT_STEREO)
+ {
+ for (i = 0; i < header.intensity_stereo_bound(); ++i)
+ subbands[i] = new SubbandLayer2Stereo(i);
+ for (; i < num_subbands; ++i)
+ subbands[i] = new SubbandLayer2IntensityStereo(i);
+ }
+ else
+ {
+ for (i = 0; i < num_subbands; ++i)
+ subbands[i] = new SubbandLayer2Stereo(i);
+ }
+
+ }
+
+ protected void readScaleFactorSelection()
+ {
+ for (int i = 0; i < num_subbands; ++i)
+ ((SubbandLayer2)subbands[i]).read_scalefactor_selection(stream, crc);
+ }
+
+
+
+ /**
+ * Class for layer II subbands in single channel mode.
+ */
+ static class SubbandLayer2 extends Subband
+ {
+ // this table contains 3 requantized samples for each legal codeword
+ // when grouped in 5 bits, i.e. 3 quantizationsteps per sample
+ public static final float grouping_5bits[] = new float[]
+ {
+ -2.0f/3.0f, -2.0f/3.0f, -2.0f/3.0f,
+ 0.0f, -2.0f/3.0f, -2.0f/3.0f,
+ 2.0f/3.0f, -2.0f/3.0f, -2.0f/3.0f,
+ -2.0f/3.0f, 0.0f, -2.0f/3.0f,
+ 0.0f, 0.0f, -2.0f/3.0f,
+ 2.0f/3.0f, 0.0f, -2.0f/3.0f,
+ -2.0f/3.0f, 2.0f/3.0f, -2.0f/3.0f,
+ 0.0f, 2.0f/3.0f, -2.0f/3.0f,
+ 2.0f/3.0f, 2.0f/3.0f, -2.0f/3.0f,
+ -2.0f/3.0f, -2.0f/3.0f, 0.0f,
+ 0.0f, -2.0f/3.0f, 0.0f,
+ 2.0f/3.0f, -2.0f/3.0f, 0.0f,
+ -2.0f/3.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f,
+ 2.0f/3.0f, 0.0f, 0.0f,
+ -2.0f/3.0f, 2.0f/3.0f, 0.0f,
+ 0.0f, 2.0f/3.0f, 0.0f,
+ 2.0f/3.0f, 2.0f/3.0f, 0.0f,
+ -2.0f/3.0f, -2.0f/3.0f, 2.0f/3.0f,
+ 0.0f, -2.0f/3.0f, 2.0f/3.0f,
+ 2.0f/3.0f, -2.0f/3.0f, 2.0f/3.0f,
+ -2.0f/3.0f, 0.0f, 2.0f/3.0f,
+ 0.0f, 0.0f, 2.0f/3.0f,
+ 2.0f/3.0f, 0.0f, 2.0f/3.0f,
+ -2.0f/3.0f, 2.0f/3.0f, 2.0f/3.0f,
+ 0.0f, 2.0f/3.0f, 2.0f/3.0f,
+ 2.0f/3.0f, 2.0f/3.0f, 2.0f/3.0f
+ };
+
+ // this table contains 3 requantized samples for each legal codeword
+ // when grouped in 7 bits, i.e. 5 quantizationsteps per sample
+ public static final float grouping_7bits[] = new float[]
+ {
+ -0.8f, -0.8f, -0.8f, -0.4f, -0.8f, -0.8f, 0.0f, -0.8f, -0.8f, 0.4f, -0.8f, -0.8f, 0.8f, -0.8f, -0.8f,
+ -0.8f, -0.4f, -0.8f, -0.4f, -0.4f, -0.8f, 0.0f, -0.4f, -0.8f, 0.4f, -0.4f, -0.8f, 0.8f, -0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f, 0.8f,
+ -0.8f, 0.8f, 0.8f, -0.4f, 0.8f, 0.8f, 0.0f, 0.8f, 0.8f, 0.4f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f
+ };
+
+ // this table contains 3 requantized samples for each legal codeword
+ // when grouped in 10 bits, i.e. 9 quantizationsteps per sample
+ public static final float grouping_10bits[] =
+ {
+ -8.0f/9.0f, -8.0f/9.0f, -8.0f/9.0f, -6.0f/9.0f, -8.0f/9.0f, -8.0f/9.0f, -4.0f/9.0f, -8.0f/9.0f, -8.0f/9.0f,
+ -2.0f/9.0f, -8.0f/9.0f, -8.0f/9.0f, 0.0f, -8.0f/9.0f, -8.0f/9.0f, 2.0f/9.0f, -8.0f/9.0f, -8.0f/9.0f,
+ 4.0f/9.0f, -8.0f/9.0f, -8.0f/9.0f, 6.0f/9.0f, -8.0f/9.0f, -8.0f/9.0f, 8.0f/9.0f, -8.0f/9.0f, -8.0f/9.0f,
+ -8.0f/9.0f, -6.0f/9.0f, -8.0f/9.0f, -6.0f/9.0f, -6.0f/9.0f, -8.0f/9.0f, -4.0f/9.0f, -6.0f/9.0f, -8.0f/9.0f,
+ -2.0f/9.0f, -6.0f/9.0f, -8.0f/9.0f, 0.0f, -6.0f/9.0f, -8.0f/9.0f, 2.0f/9.0f, -6.0f/9.0f, -8.0f/9.0f,
+ 4.0f/9.0f, -6.0f/9.0f, -8.0f/9.0f, 6.0f/9.0f, -6.0f/9.0f, -8.0f/9.0f, 8.0f/9.0f, -6.0f/9.0f, -8.0f/9.0f,
+ -8.0f/9.0f, -4.0f/9.0f, -8.0f/9.0f, -6.0f/9.0f, -4.0f/9.0f, -8.0f/9.0f, -4.0f/9.0f, -4.0f/9.0f, -8.0f/9.0f,
+ -2.0f/9.0f, -4.0f/9.0f, -8.0f/9.0f, 0.0f, -4.0f/9.0f, -8.0f/9.0f, 2.0f/9.0f, -4.0f/9.0f, -8.0f/9.0f,
+ 4.0f/9.0f, -4.0f/9.0f, -8.0f/9.0f, 6.0f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f,
+ -2.0f/9.0f, 8.0f/9.0f, 8.0f/9.0f, 0.0f, 8.0f/9.0f, 8.0f/9.0f, 2.0f/9.0f, 8.0f/9.0f, 8.0f/9.0f,
+ 4.0f/9.0f, 8.0f/9.0f, 8.0f/9.0f, 6.0f/9.0f, 8.0f/9.0f, 8.0f/9.0f, 8.0f/9.0f, 8.0f/9.0f, 8.0f/9.0f
+ };
+
+ // data taken from ISO/IEC DIS 11172, Annexes 3-B.2[abcd] and 3-B.4:
+
+ // subbands 0-2 in tables 3-B.2a and 2b: (index is allocation)
+ public static final int table_ab1_codelength[] =
+ // bits per codeword
+ { 0, 5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+ public static final float table_ab1_groupingtables[][] =
+ // pointer to sample grouping table, or NULL-pointer if ungrouped
+ { null, grouping_5bits, null, null, null, null, null, null, null, null, null, null, null, null, null, null };
+
+ public static final float table_ab1_factor[] =
+ // factor for requantization: (real)sample * factor - 1.0 gives requantized sample
+ { 0.0f, 1.0f/2.0f, 1.0f/4.0f, 1.0f/8.0f, 1.0f/16.0f, 1.0f/32.0f, 1.0f/64.0f,
+ 1.0f/128.0f, 1.0f/256.0f, 1.0f/512.0f, 1.0f/1024.0f, 1.0f/2048.0f,
+ 1.0f/4096.0f, 1.0f/8192.0f, 1.0f/16384.0f, 1.0f/32768.0f };
+
+ public static final float table_ab1_c[] =
+ // factor c for requantization from table 3-B.4
+ { 0.0f, 1.33333333333f, 1.14285714286f, 1.06666666666f, 1.03225806452f,
+ 1.01587301587f, 1.00787401575f, 1.00392156863f, 1.00195694716f, 1.00097751711f,
+ 1.00048851979f, 1.00024420024f, 1.00012208522f, 1.00006103888f, 1.00003051851f,
+ 1.00001525902f };
+
+ public static final float table_ab1_d[] =
+ // addend d for requantization from table 3-B.4
+ { 0.0f, 0.50000000000f, 0.25000000000f, 0.12500000000f, 0.06250000000f,
+ 0.03125000000f, 0.01562500000f, 0.00781250000f, 0.00390625000f, 0.00195312500f,
+ 0.00097656250f, 0.00048828125f, 0.00024414063f, 0.00012207031f, 0.00006103516f,
+ 0.00003051758f };
+
+ // subbands 3-... tables 3-B.2a and 2b:
+ public static final float[] table_ab234_groupingtables[] =
+ { null, grouping_5bits, grouping_7bits, null, grouping_10bits, null, null, null, null, null, null, null, null, null, null, null };
+
+ // subbands 3-10 in tables 3-B.2a and 2b:
+ public static final int table_ab2_codelength[] =
+ { 0, 5, 7, 3, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 };
+ public static final float table_ab2_factor[] =
+ { 0.0f, 1.0f/2.0f, 1.0f/4.0f, 1.0f/4.0f, 1.0f/8.0f, 1.0f/8.0f, 1.0f/16.0f,
+ 1.0f/32.0f, 1.0f/64.0f, 1.0f/128.0f, 1.0f/256.0f, 1.0f/512.0f,
+ 1.0f/1024.0f, 1.0f/2048.0f, 1.0f/4096.0f, 1.0f/32768.0f };
+ public static final float table_ab2_c[] =
+ { 0.0f, 1.33333333333f, 1.60000000000f, 1.14285714286f, 1.77777777777f,
+ 1.06666666666f, 1.03225806452f, 1.01587301587f, 1.00787401575f, 1.00392156863f,
+ 1.00195694716f, 1.00097751711f, 1.00048851979f, 1.00024420024f, 1.00012208522f,
+ 1.00001525902f };
+ public static final float table_ab2_d[] =
+ { 0.0f, 0.50000000000f, 0.50000000000f, 0.25000000000f, 0.50000000000f,
+ 0.12500000000f, 0.06250000000f, 0.03125000000f, 0.01562500000f, 0.00781250000f,
+ 0.00390625000f, 0.00195312500f, 0.00097656250f, 0.00048828125f, 0.00024414063f,
+ 0.00003051758f };
+
+ // subbands 11-22 in tables 3-B.2a and 2b:
+ public static final int table_ab3_codelength[] = { 0, 5, 7, 3, 10, 4, 5, 16 };
+ public static final float table_ab3_factor[] =
+ { 0.0f, 1.0f/2.0f, 1.0f/4.0f, 1.0f/4.0f, 1.0f/8.0f, 1.0f/8.0f, 1.0f/16.0f, 1.0f/32768.0f };
+ public static final float table_ab3_c[] =
+ { 0.0f, 1.33333333333f, 1.60000000000f, 1.14285714286f, 1.77777777777f,
+ 1.06666666666f, 1.03225806452f, 1.00001525902f };
+ public static final float table_ab3_d[] =
+ { 0.0f, 0.50000000000f, 0.50000000000f, 0.25000000000f, 0.50000000000f,
+ 0.12500000000f, 0.06250000000f, 0.00003051758f };
+
+ // subbands 23-... in tables 3-B.2a and 2b:
+ public static final int table_ab4_codelength[] = { 0, 5, 7, 16 };
+ public static final float table_ab4_factor[] = { 0.0f, 1.0f/2.0f, 1.0f/4.0f, 1.0f/32768.0f };
+ public static final float table_ab4_c[] = { 0.0f, 1.33333333333f, 1.60000000000f, 1.00001525902f };
+ public static final float table_ab4_d[] = { 0.0f, 0.50000000000f, 0.50000000000f, 0.00003051758f };
+
+ // subbands in tables 3-B.2c and 2d:
+ public static final int table_cd_codelength[] =
+ { 0, 5, 7, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
+ public static final float table_cd_groupingtables[][] =
+ { null, grouping_5bits, grouping_7bits, grouping_10bits, null, null, null, null, null, null, null, null, null, null, null, null };
+ public static final float table_cd_factor[] =
+ { 0.0f, 1.0f/2.0f, 1.0f/4.0f, 1.0f/8.0f, 1.0f/8.0f, 1.0f/16.0f, 1.0f/32.0f, 1.0f/64.0f,
+ 1.0f/128.0f, 1.0f/256.0f, 1.0f/512.0f, 1.0f/1024.0f, 1.0f/2048.0f, 1.0f/4096.0f,
+ 1.0f/8192.0f, 1.0f/16384.0f };
+ public static final float table_cd_c[] =
+ { 0.0f, 1.33333333333f, 1.60000000000f, 1.77777777777f, 1.06666666666f,
+ 1.03225806452f, 1.01587301587f, 1.00787401575f, 1.00392156863f, 1.00195694716f,
+ 1.00097751711f, 1.00048851979f, 1.00024420024f, 1.00012208522f, 1.00006103888f,
+ 1.00003051851f };
+ public static final float table_cd_d[] =
+ { 0.0f, 0.50000000000f, 0.50000000000f, 0.50000000000f, 0.12500000000f,
+ 0.06250000000f, 0.03125000000f, 0.01562500000f, 0.00781250000f, 0.00390625000f,
+ 0.00195312500f, 0.00097656250f, 0.00048828125f, 0.00024414063f, 0.00012207031f,
+ 0.00006103516f };
+
+
+
+ protected int subbandnumber;
+ protected int allocation;
+ protected int scfsi;
+ protected float scalefactor1, scalefactor2, scalefactor3;
+ protected int[] codelength = {0};
+ protected float groupingtable[][] = new float[2][];
+ //protected float[][] groupingtable = {{0},{0}} ;
+ protected float[] factor = {0.0f};
+ protected int groupnumber;
+ protected int samplenumber;
+ protected float[] samples = new float[3];
+ protected float[] c = {0};
+ protected float[] d = {0};
+ /**
+ * Constructor
+ */
+ public SubbandLayer2(int subbandnumber)
+ {
+ this.subbandnumber = subbandnumber;
+ groupnumber = samplenumber = 0;
+ }
+
+
+ /**
+ *
+ */
+ protected int get_allocationlength (Header header)
+ {
+ if (header.version() == Header.MPEG1)
+ {
+ int channel_bitrate = header.bitrate_index();
+
+ // calculate bitrate per channel:
+ if (header.mode() != Header.SINGLE_CHANNEL)
+ if (channel_bitrate == 4)
+ channel_bitrate = 1;
+ else
+ channel_bitrate -= 4;
+
+ if (channel_bitrate == 1 || channel_bitrate == 2)
+ // table 3-B.2c or 3-B.2d
+ if (subbandnumber <= 1)
+ return 4;
+ else
+ return 3;
+ else
+ // tables 3-B.2a or 3-B.2b
+ if (subbandnumber <= 10)
+ return 4;
+ else if (subbandnumber <= 22)
+ return 3;
+ else
+ return 2;
+ }
+ else
+ { // MPEG-2 LSF -- Jeff
+
+ // table B.1 of ISO/IEC 13818-3
+ if (subbandnumber <= 3)
+ return 4;
+ else if (subbandnumber <= 10)
+ return 3;
+ else
+ return 2;
+ }
+ }
+
+ /**
+ *
+ */
+ protected void prepare_sample_reading(Header header, int allocation,
+ //float[][] groupingtable,
+ int channel,
+ float[] factor, int[] codelength,
+ float[] c, float[] d)
+ {
+ int channel_bitrate = header.bitrate_index();
+ // calculate bitrate per channel:
+ if (header.mode() != Header.SINGLE_CHANNEL)
+ if (channel_bitrate == 4)
+ channel_bitrate = 1;
+ else
+ channel_bitrate -= 4;
+
+ if (channel_bitrate == 1 || channel_bitrate == 2)
+ {
+ // table 3-B.2c or 3-B.2d
+ groupingtable[channel] = table_cd_groupingtables[allocation];
+ factor[0] = table_cd_factor[allocation];
+ codelength[0] = table_cd_codelength[allocation];
+ c[0] = table_cd_c[allocation];
+ d[0] = table_cd_d[allocation];
+ }
+ else
+ {
+ // tables 3-B.2a or 3-B.2b
+ if (subbandnumber <= 2)
+ {
+ groupingtable[channel] = table_ab1_groupingtables[allocation];
+ factor[0] = table_ab1_factor[allocation];
+ codelength[0] = table_ab1_codelength[allocation];
+ c[0] = table_ab1_c[allocation];
+ d[0] = table_ab1_d[allocation];
+ }
+ else
+ {
+ groupingtable[channel] = table_ab234_groupingtables[allocation];
+ if (subbandnumber <= 10)
+ {
+ factor[0] = table_ab2_factor[allocation];
+ codelength[0] = table_ab2_codelength[allocation];
+ c[0] = table_ab2_c[allocation];
+ d[0] = table_ab2_d[allocation];
+ }
+ else if (subbandnumber <= 22)
+ {
+ factor[0] = table_ab3_factor[allocation];
+ codelength[0] = table_ab3_codelength[allocation];
+ c[0] = table_ab3_c[allocation];
+ d[0] = table_ab3_d[allocation];
+ }
+ else
+ {
+ factor[0] = table_ab4_factor[allocation];
+ codelength[0] = table_ab4_codelength[allocation];
+ c[0] = table_ab4_c[allocation];
+ d[0] = table_ab4_d[allocation];
+ }
+ }
+ }
+ }
+
+
+ /**
+ *
+ */
+ public void read_allocation(Bitstream stream, Header header, Crc16 crc)
+ {
+ int length = get_allocationlength(header);
+ allocation = stream.get_bits(length);
+ if (crc != null)
+ crc.add_bits(allocation, length);
+ }
+
+ /**
+ *
+ */
+ public void read_scalefactor_selection (Bitstream stream, Crc16 crc)
+ {
+ if (allocation != 0)
+ {
+ scfsi = stream.get_bits(2);
+ if (crc != null) crc.add_bits(scfsi, 2);
+ }
+ }
+
+ /**
+ *
+ */
+ public void read_scalefactor (Bitstream stream, Header header)
+ {
+ if (allocation != 0)
+ {
+ switch (scfsi)
+ {
+ case 0:
+ scalefactor1 = scalefactors[stream.get_bits(6)];
+ scalefactor2 = scalefactors[stream.get_bits(6)];
+ scalefactor3 = scalefactors[stream.get_bits(6)];
+ break;
+ case 1:
+ scalefactor1 = scalefactor2 = scalefactors[stream.get_bits(6)];
+ scalefactor3 = scalefactors[stream.get_bits(6)];
+ break;
+ case 2:
+ scalefactor1 = scalefactor2 = scalefactor3 = scalefactors[stream.get_bits(6)];
+ break;
+ case 3:
+ scalefactor1 = scalefactors[stream.get_bits(6)];
+ scalefactor2 = scalefactor3 = scalefactors[stream.get_bits(6)];
+ break;
+ }
+ prepare_sample_reading(header, allocation, 0,
+ factor, codelength, c, d);
+ }
+ }
+
+ /**
+ *
+ */
+ public boolean read_sampledata (Bitstream stream)
+ {
+ if (allocation != 0)
+ if (groupingtable[0] != null)
+ {
+ int samplecode = stream.get_bits(codelength[0]);
+ // create requantized samples:
+ samplecode += samplecode << 1;
+ float[] target = samples;
+ float[] source = groupingtable[0];
+ /*
+ int tmp = 0;
+ int temp = 0;
+ target[tmp++] = source[samplecode + temp];
+ temp++;
+ target[tmp++] = source[samplecode + temp];
+ temp++;
+ target[tmp] = source[samplecode + temp];
+ */
+ //Bugfix:
+ int tmp = 0;
+ int temp = samplecode;
+
+ if(temp > source.length - 3) temp = source.length - 3;
+
+ target[tmp] = source[temp];
+ temp++;tmp++;
+ target[tmp] = source[temp];
+ temp++;tmp++;
+ target[tmp] = source[temp];
+
+ // memcpy (samples, groupingtable + samplecode, 3 * sizeof (real));
+ }
+ else
+ {
+ samples[0] = (float) ((stream.get_bits(codelength[0])) * factor[0] - 1.0);
+ samples[1] = (float) ((stream.get_bits(codelength[0])) * factor[0] - 1.0);
+ samples[2] = (float) ((stream.get_bits(codelength[0])) * factor[0] - 1.0);
+ }
+
+ samplenumber = 0;
+ if (++groupnumber == 12)
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ *
+ */
+ public boolean put_next_sample(int channels, SynthesisFilter filter1, SynthesisFilter filter2)
+ {
+ if ((allocation != 0) && (channels != OutputChannels.RIGHT_CHANNEL))
+ {
+ float sample = samples[samplenumber];
+
+ if (groupingtable[0] == null)
+ sample = (sample + d[0]) * c[0];
+ if (groupnumber <= 4)
+ sample *= scalefactor1;
+ else if (groupnumber <= 8)
+ sample *= scalefactor2;
+ else
+ sample *= scalefactor3;
+ filter1.input_sample(sample, subbandnumber);
+ }
+
+ if (++samplenumber == 3)
+ return true;
+ else
+ return false;
+ }
+ };
+
+ /**
+ * Class for layer II subbands in joint stereo mode.
+ */
+ static class SubbandLayer2IntensityStereo extends SubbandLayer2
+ {
+ protected int channel2_scfsi;
+ protected float channel2_scalefactor1, channel2_scalefactor2, channel2_scalefactor3;
+
+ /**
+ * Constructor
+ */
+ public SubbandLayer2IntensityStereo (int subbandnumber)
+ {
+ super(subbandnumber);
+ }
+
+ /**
+ *
+ */
+ public void read_allocation(Bitstream stream, Header header, Crc16 crc)
+ {
+ super.read_allocation (stream, header, crc);
+ }
+
+ /**
+ *
+ */
+ public void read_scalefactor_selection(Bitstream stream, Crc16 crc)
+ {
+ if (allocation != 0)
+ {
+ scfsi = stream.get_bits(2);
+ channel2_scfsi = stream.get_bits(2);
+ if (crc != null)
+ {
+ crc.add_bits(scfsi, 2);
+ crc.add_bits(channel2_scfsi, 2);
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public void read_scalefactor(Bitstream stream, Header header)
+ {
+ if (allocation != 0)
+ {
+ super.read_scalefactor(stream, header);
+ switch (channel2_scfsi)
+ {
+ case 0:
+ channel2_scalefactor1 = scalefactors[stream.get_bits(6)];
+ channel2_scalefactor2 = scalefactors[stream.get_bits(6)];
+ channel2_scalefactor3 = scalefactors[stream.get_bits(6)];
+ break;
+
+ case 1:
+ channel2_scalefactor1 = channel2_scalefactor2 = scalefactors[stream.get_bits (6)];
+ channel2_scalefactor3 = scalefactors[stream.get_bits(6)];
+ break;
+
+ case 2:
+ channel2_scalefactor1 = channel2_scalefactor2 =
+ channel2_scalefactor3 = scalefactors[stream.get_bits(6)];
+ break;
+
+ case 3:
+ channel2_scalefactor1 = scalefactors[stream.get_bits(6)];
+ channel2_scalefactor2 = channel2_scalefactor3 = scalefactors[stream.get_bits (6)];
+ break;
+ }
+ }
+
+ }
+
+ /**
+ *
+ */
+ public boolean read_sampledata(Bitstream stream)
+ {
+ return super.read_sampledata (stream);
+ }
+
+ /**
+ *
+ */
+ public boolean put_next_sample(int channels, SynthesisFilter filter1, SynthesisFilter filter2)
+ {
+ if (allocation != 0)
+ {
+ float sample = samples[samplenumber];
+
+ if (groupingtable[0] == null)
+ sample = (sample + d[0]) * c[0];
+ if (channels == OutputChannels.BOTH_CHANNELS)
+ {
+ float sample2 = sample;
+ if (groupnumber <= 4)
+ {
+ sample *= scalefactor1;
+ sample2 *= channel2_scalefactor1;
+ }
+ else if (groupnumber <= 8)
+ {
+ sample *= scalefactor2;
+ sample2 *= channel2_scalefactor2;
+ }
+ else
+ {
+ sample *= scalefactor3;
+ sample2 *= channel2_scalefactor3;
+ }
+ filter1.input_sample(sample, subbandnumber);
+ filter2.input_sample(sample2, subbandnumber);
+ }
+ else if (channels == OutputChannels.LEFT_CHANNEL)
+ {
+ if (groupnumber <= 4)
+ sample *= scalefactor1;
+ else if (groupnumber <= 8)
+ sample *= scalefactor2;
+ else
+ sample *= scalefactor3;
+ filter1.input_sample(sample, subbandnumber);
+ }
+ else
+ {
+ if (groupnumber <= 4)
+ sample *= channel2_scalefactor1;
+ else if (groupnumber <= 8)
+ sample *= channel2_scalefactor2;
+ else
+ sample *= channel2_scalefactor3;
+ filter1.input_sample(sample, subbandnumber);
+ }
+ }
+
+ if (++samplenumber == 3)
+ return true;
+ else
+ return false;
+ }
+ };
+
+ /**
+ * Class for layer II subbands in stereo mode.
+ */
+ static class SubbandLayer2Stereo extends SubbandLayer2
+ {
+ protected int channel2_allocation;
+ protected int channel2_scfsi;
+ protected float channel2_scalefactor1, channel2_scalefactor2, channel2_scalefactor3;
+ //protected boolean channel2_grouping; ???? Never used!
+ protected int[] channel2_codelength = {0};
+ //protected float[][] channel2_groupingtable = {{0},{0}};
+ protected float[] channel2_factor = {0};
+ protected float[] channel2_samples;
+ protected float[] channel2_c = {0};
+ protected float[] channel2_d = {0};
+
+ /**
+ * Constructor
+ */
+ public SubbandLayer2Stereo(int subbandnumber)
+ {
+ super(subbandnumber);
+ channel2_samples = new float[3];
+ }
+
+ /**
+ *
+ */
+ public void read_allocation (Bitstream stream, Header header, Crc16 crc)
+ {
+ int length = get_allocationlength(header);
+ allocation = stream.get_bits(length);
+ channel2_allocation = stream.get_bits(length);
+ if (crc != null)
+ {
+ crc.add_bits(allocation, length);
+ crc.add_bits(channel2_allocation, length);
+ }
+ }
+
+ /**
+ *
+ */
+ public void read_scalefactor_selection(Bitstream stream, Crc16 crc)
+ {
+ if (allocation != 0)
+ {
+ scfsi = stream.get_bits(2);
+ if (crc != null)
+ crc.add_bits(scfsi, 2);
+ }
+ if (channel2_allocation != 0)
+ {
+ channel2_scfsi = stream.get_bits(2);
+ if (crc != null)
+ crc.add_bits(channel2_scfsi, 2);
+ }
+ }
+
+ /**
+ *
+ */
+ public void read_scalefactor(Bitstream stream, Header header)
+ {
+ super.read_scalefactor(stream, header);
+ if (channel2_allocation != 0)
+ {
+ switch (channel2_scfsi)
+ {
+ case 0:
+ channel2_scalefactor1 = scalefactors[stream.get_bits(6)];
+ channel2_scalefactor2 = scalefactors[stream.get_bits(6)];
+ channel2_scalefactor3 = scalefactors[stream.get_bits(6)];
+ break;
+
+ case 1:
+ channel2_scalefactor1 = channel2_scalefactor2 =
+ scalefactors[stream.get_bits(6)];
+ channel2_scalefactor3 = scalefactors[stream.get_bits(6)];
+ break;
+
+ case 2:
+ channel2_scalefactor1 = channel2_scalefactor2 =
+ channel2_scalefactor3 = scalefactors[stream.get_bits(6)];
+ break;
+
+ case 3:
+ channel2_scalefactor1 = scalefactors[stream.get_bits(6)];
+ channel2_scalefactor2 = channel2_scalefactor3 =
+ scalefactors[stream.get_bits(6)];
+ break;
+ }
+ prepare_sample_reading(header, channel2_allocation, 1,
+ channel2_factor, channel2_codelength, channel2_c,
+ channel2_d);
+ }
+ }
+
+ /**
+ *
+ */
+ public boolean read_sampledata (Bitstream stream)
+ {
+ boolean returnvalue = super.read_sampledata(stream);
+
+ if (channel2_allocation != 0)
+ if (groupingtable[1] != null)
+ {
+ int samplecode = stream.get_bits(channel2_codelength[0]);
+ // create requantized samples:
+ samplecode += samplecode << 1;
+ /*
+ float[] target = channel2_samples;
+ float[] source = channel2_groupingtable[0];
+ int tmp = 0;
+ int temp = 0;
+ target[tmp++] = source[samplecode + temp];
+ temp++;
+ target[tmp++] = source[samplecode + temp];
+ temp++;
+ target[tmp] = source[samplecode + temp];
+ // memcpy (channel2_samples, channel2_groupingtable + samplecode, 3 * sizeof (real));
+ */
+ float[] target = channel2_samples;
+ float[] source = groupingtable[1];
+ int tmp = 0;
+ int temp = samplecode;
+ target[tmp] = source[temp];
+ temp++;tmp++;
+ target[tmp] = source[temp];
+ temp++;tmp++;
+ target[tmp] = source[temp];
+
+ }
+ else
+ {
+ channel2_samples[0] = (float) ((stream.get_bits(channel2_codelength[0])) *
+ channel2_factor[0] - 1.0);
+ channel2_samples[1] = (float) ((stream.get_bits(channel2_codelength[0])) *
+ channel2_factor[0] - 1.0);
+ channel2_samples[2] = (float) ((stream.get_bits(channel2_codelength[0])) *
+ channel2_factor[0] - 1.0);
+ }
+ return returnvalue;
+ }
+
+ /**
+ *
+ */
+ public boolean put_next_sample(int channels, SynthesisFilter filter1, SynthesisFilter filter2)
+ {
+ boolean returnvalue = super.put_next_sample(channels, filter1, filter2);
+ if ((channel2_allocation != 0) && (channels != OutputChannels.LEFT_CHANNEL))
+ {
+ float sample = channel2_samples[samplenumber - 1];
+
+ if (groupingtable[1] == null)
+ sample = (sample + channel2_d[0]) * channel2_c[0];
+
+ if (groupnumber <= 4)
+ sample *= channel2_scalefactor1;
+ else if (groupnumber <= 8)
+ sample *= channel2_scalefactor2;
+ else
+ sample *= channel2_scalefactor3;
+ if (channels == OutputChannels.BOTH_CHANNELS)
+ filter2.input_sample(sample, subbandnumber);
+ else
+ filter1.input_sample(sample, subbandnumber);
+ }
+ return returnvalue;
+ }
+ }
+}
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * \r
+ * 18/06/01 Michael Scheerer, Fixed bugs which causes\r
+ * negative indexes in method huffmann_decode and in method \r
+ * dequanisize_sample.\r
+ *\r
+ * 16/07/01 Michael Scheerer, Catched a bug in method\r
+ * huffmann_decode, which causes an outOfIndexException.\r
+ * Cause : Indexnumber of 24 at SfBandIndex,\r
+ * which has only a length of 22. I have simply and dirty \r
+ * fixed the index to <= 22, because I'm not really be able\r
+ * to fix the bug. The Indexnumber is taken from the MP3 \r
+ * file and the origin Ma-Player with the same code works \r
+ * well. \r
+ * \r
+ * 02/19/99 Java Conversion by E.B, javalayer@javazoom.net\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * Class Implementing Layer 3 Decoder.\r
+ * \r
+ * @since 0.0\r
+ */\r
+final class LayerIIIDecoder implements FrameDecoder {\r
+ final double d43 = (4.0 / 3.0);\r
+\r
+ public int[] scalefac_buffer;\r
+\r
+ // MDM: removed, as this wasn't being used.\r
+ // private float CheckSumOut1d = 0.0f;\r
+ private int CheckSumHuff = 0;\r
+ private int[] is_1d;\r
+ private float[][][] ro;\r
+ private float[][][] lr;\r
+ private float[] out_1d;\r
+ private float[][] prevblck;\r
+ private float[][] k;\r
+ private int[] nonzero;\r
+ private Bitstream stream;\r
+ @HEADER private Header header;\r
+ private SynthesisFilter filter1, filter2;\r
+ private Obuffer buffer;\r
+ private int which_channels;\r
+ private BitReserve br;\r
+ private III_side_info_t si;\r
+\r
+ private temporaire2[] III_scalefac_t;\r
+ private temporaire2[] scalefac;\r
+ // private III_scalefac_t scalefac;\r
+\r
+ private int max_gr;\r
+ private int frame_start;\r
+ private int part2_start;\r
+ private int channels;\r
+ private int first_channel;\r
+ private int last_channel;\r
+ private int sfreq;\r
+\r
+ /**\r
+ * Constructor.\r
+ */\r
+ // REVIEW: these constructor arguments should be moved to the\r
+ // decodeFrame() method, where possible, so that one\r
+ public LayerIIIDecoder(Bitstream stream0, Header header0, SynthesisFilter filtera,\r
+ SynthesisFilter filterb, Obuffer buffer0, int which_ch0) {\r
+ huffcodetab.inithuff();\r
+ is_1d = new int[SBLIMIT * SSLIMIT + 4];\r
+ ro = new float[2][SBLIMIT][SSLIMIT];\r
+ lr = new float[2][SBLIMIT][SSLIMIT];\r
+ out_1d = new float[SBLIMIT * SSLIMIT];\r
+ prevblck = new float[2][SBLIMIT * SSLIMIT];\r
+ k = new float[2][SBLIMIT * SSLIMIT];\r
+ nonzero = new int[2];\r
+\r
+ // III_scalefact_t\r
+ III_scalefac_t = new temporaire2[2];\r
+ III_scalefac_t[0] = new temporaire2();\r
+ III_scalefac_t[1] = new temporaire2();\r
+ scalefac = III_scalefac_t;\r
+ // L3TABLE INIT\r
+\r
+ sfBandIndex = new SBI[9]; // SZD: MPEG2.5 +3 indices\r
+ int[] l0 =\r
+ { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396,\r
+ 464, 522, 576 };\r
+ int[] s0 = { 0, 4, 8, 12, 18, 24, 32, 42, 56, 74, 100, 132, 174, 192 };\r
+ int[] l1 =\r
+ { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232, 278, 330, 394,\r
+ 464, 540, 576 };\r
+ int[] s1 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 136, 180, 192 };\r
+ int[] l2 =\r
+ { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396,\r
+ 464, 522, 576 };\r
+ int[] s2 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192 };\r
+\r
+ int[] l3 =\r
+ { 0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196, 238, 288, 342,\r
+ 418, 576 };\r
+ int[] s3 = { 0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84, 106, 136, 192 };\r
+ int[] l4 =\r
+ { 0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190, 230, 276, 330,\r
+ 384, 576 };\r
+ int[] s4 = { 0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80, 100, 126, 192 };\r
+ int[] l5 =\r
+ { 0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240, 296, 364, 448,\r
+ 550, 576 };\r
+ int[] s5 = { 0, 4, 8, 12, 16, 22, 30, 42, 58, 78, 104, 138, 180, 192 };\r
+ // SZD: MPEG2.5\r
+ int[] l6 =\r
+ { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396,\r
+ 464, 522, 576 };\r
+ int[] s6 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192 };\r
+ int[] l7 =\r
+ { 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396,\r
+ 464, 522, 576 };\r
+ int[] s7 = { 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192 };\r
+ int[] l8 =\r
+ { 0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400, 476, 566, 568,\r
+ 570, 572, 574, 576 };\r
+ int[] s8 = { 0, 8, 16, 24, 36, 52, 72, 96, 124, 160, 162, 164, 166, 192 };\r
+\r
+ sfBandIndex[0] = new SBI(l0, s0);\r
+ sfBandIndex[1] = new SBI(l1, s1);\r
+ sfBandIndex[2] = new SBI(l2, s2);\r
+\r
+ sfBandIndex[3] = new SBI(l3, s3);\r
+ sfBandIndex[4] = new SBI(l4, s4);\r
+ sfBandIndex[5] = new SBI(l5, s5);\r
+ // SZD: MPEG2.5\r
+ sfBandIndex[6] = new SBI(l6, s6);\r
+ sfBandIndex[7] = new SBI(l7, s7);\r
+ sfBandIndex[8] = new SBI(l8, s8);\r
+ // END OF L3TABLE INIT\r
+\r
+ if (reorder_table == null) { // SZD: generate LUT\r
+ reorder_table = new int[9][];\r
+ for (int i = 0; i < 9; i++)\r
+ reorder_table[i] = reorder(sfBandIndex[i].s);\r
+ }\r
+\r
+ // Sftable\r
+ int[] ll0 = { 0, 6, 11, 16, 21 };\r
+ int[] ss0 = { 0, 6, 12 };\r
+ sftable = new Sftable(ll0, ss0);\r
+ // END OF Sftable\r
+\r
+ // scalefac_buffer\r
+ scalefac_buffer = new int[54];\r
+ // END OF scalefac_buffer\r
+\r
+ stream = stream0;\r
+ header = header0;\r
+ filter1 = filtera;\r
+ filter2 = filterb;\r
+ buffer = buffer0;\r
+ which_channels = which_ch0;\r
+\r
+ frame_start = 0;\r
+ channels = (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2;\r
+ max_gr = (header.version() == Header.MPEG1) ? 2 : 1;\r
+\r
+ sfreq =\r
+ header.sample_frequency()\r
+ + ((header.version() == Header.MPEG1) ? 3 : (header.version() == Header.MPEG25_LSF) ? 6\r
+ : 0); // SZD\r
+\r
+ if (channels == 2) {\r
+ switch (which_channels) {\r
+ case OutputChannels.LEFT_CHANNEL:\r
+ case OutputChannels.DOWNMIX_CHANNELS:\r
+ first_channel = last_channel = 0;\r
+ break;\r
+\r
+ case OutputChannels.RIGHT_CHANNEL:\r
+ first_channel = last_channel = 1;\r
+ break;\r
+\r
+ case OutputChannels.BOTH_CHANNELS:\r
+ default:\r
+ first_channel = 0;\r
+ last_channel = 1;\r
+ break;\r
+ }\r
+ } else {\r
+ first_channel = last_channel = 0;\r
+ }\r
+\r
+ for (int ch = 0; ch < 2; ch++)\r
+ for (int j = 0; j < 576; j++)\r
+ prevblck[ch][j] = 0.0f;\r
+\r
+ nonzero[0] = nonzero[1] = 576;\r
+\r
+ br = new BitReserve();\r
+ si = new III_side_info_t();\r
+ }\r
+\r
+ /**\r
+ * Notify decoder that a seek is being made.\r
+ */\r
+ public void seek_notify() {\r
+ frame_start = 0;\r
+ for (int ch = 0; ch < 2; ch++)\r
+ for (int j = 0; j < 576; j++)\r
+ prevblck[ch][j] = 0.0f;\r
+ br = new BitReserve();\r
+ }\r
+\r
+ public void decodeFrame() {\r
+ decode();\r
+ }\r
+\r
+ /**\r
+ * Decode one frame, filling the buffer with the output samples.\r
+ */\r
+\r
+ // subband samples are buffered and passed to the\r
+ // SynthesisFilter in one go.\r
+ private float[] samples1 = new float[32];\r
+ private float[] samples2 = new float[32];\r
+\r
+ /* location hierarchy of decode()\r
+{header} {stream} {si}\r
+{br, flush_main, main_data_end,frame_start,nSlots,bytes_to_discard}* \r
+{gr,max_gr} // granule\r
+{ch,channels,first_channel, last_channel, which_channels} // channel\r
+{part2_start} \r
+{sb18, ss}\r
+{out_1d}*\r
+{sb}*\r
+{samples1,sample2} {filter1,filter2}\r
+ */\r
+ public void decode() {\r
+ int nSlots = header.slots();\r
+ int flush_main;\r
+ int gr, ch, ss, sb, sb18;\r
+ int main_data_end;\r
+ int bytes_to_discard;\r
+ int i;\r
+\r
+ get_side_info();\r
+\r
+ for (i = 0; i < nSlots; i++)\r
+ br.hputbuf(stream.get_bits(8)); // br < stream\r
+\r
+ // br < main_data_end\r
+ main_data_end = br.hsstell() >>> 3; // of previous frame \r
+ \r
+\r
+ if ((flush_main = (br.hsstell() & 7)) != 0) { // flush_main < br\r
+ br.hgetbits(8 - flush_main); // br < flush_main\r
+ main_data_end++; // main_data_end*\r
+ }\r
+\r
+ // bytes_to_discard < GLB(frame_start,main_data_end,si)\r
+ // TODO does bytes_to_discard need to go back to si??? \r
+ bytes_to_discard = frame_start - main_data_end - si.main_data_begin;\r
+\r
+ // frame_start should be *\r
+ frame_start += nSlots;\r
+\r
+ if (bytes_to_discard < 0)\r
+ return;\r
+\r
+ if (main_data_end > 4096) { // main_data_end should be > than 'frame_start' and 'br'\r
+ frame_start -= 4096;\r
+ br.rewindNbytes(4096);\r
+ }\r
+\r
+ for (; bytes_to_discard > 0; bytes_to_discard--) // bytes_to_discard > br\r
+ br.hgetbits(8);\r
+ \r
+ // here 'gr' and 'max_gr' should be higher than 'ch','channels', and more\r
+ for (gr = 0; gr < max_gr; gr++) { \r
+ // in the loop body, access set={part2_start} \r
+ \r
+ // 'ch', 'channels' should be higher than all locs in the below body\r
+ for (ch = 0; ch < channels; ch++) { \r
+ part2_start = br.hsstell(); // part2_start < br\r
+\r
+ if (header.version() == Header.MPEG1)\r
+ get_scale_factors(ch, gr); // no need to care from this side\r
+ else\r
+ // MPEG-2 LSF, SZD: MPEG-2.5 LSF\r
+ get_LSF_scale_factors(ch, gr); // no need to care from this side\r
+\r
+ huffman_decode(ch, gr); // no need to care from this side\r
+ // System.out.println("CheckSum HuffMan = " + CheckSumHuff);\r
+ dequantize_sample(ro[ch], ch, gr); // no need to care from this side\r
+ }\r
+\r
+ stereo(gr); // no need to care from this side\r
+\r
+ if ((which_channels == OutputChannels.DOWNMIX_CHANNELS) && (channels > 1))\r
+ do_downmix();\r
+\r
+ for (ch = first_channel; ch <= last_channel; ch++) { // 'ch' and 'first_channel' > the body\r
+\r
+ // in the body\r
+ // read set= lr,ch,gr,out_1d, sb18, ss, SSLIMIT, out_1d\r
+ // write set= out_1d\r
+ \r
+ reorder(lr[ch], ch, gr); \r
+ antialias(ch, gr);\r
+ // for (int hb = 0;hb<576;hb++) CheckSumOut1d = CheckSumOut1d +\r
+ // out_1d[hb];\r
+ // System.out.println("CheckSumOut1d = "+CheckSumOut1d);\r
+\r
+ hybrid(ch, gr);\r
+\r
+ // for (int hb = 0;hb<576;hb++) CheckSumOut1d = CheckSumOut1d +\r
+ // out_1d[hb];\r
+ // System.out.println("CheckSumOut1d = "+CheckSumOut1d);\r
+\r
+ for (sb18 = 18; sb18 < 576; sb18 += 36) // sb18 > ss, SSLIMIT, out1d\r
+ // Frequency inversion\r
+ for (ss = 1; ss < SSLIMIT; ss += 2) // 'ss','SSLIMIT' > out_1d\r
+ out_1d[sb18 + ss] = -out_1d[sb18 + ss]; // out1d*\r
+\r
+ // 'ch', 'which_channels' should be higher than if/else body!\r
+ // location set written by if/else body \r
+ // = {samples1, samples2, filter1, filter2} \r
+ if ((ch == 0) || (which_channels == OutputChannels.RIGHT_CHANNEL)) {\r
+ for (ss = 0; ss < SSLIMIT; ss++) { // Polyphase synthesis\r
+ sb = 0;\r
+ for (sb18 = 0; sb18 < 576; sb18 += 18) {\r
+ samples1[sb] = out_1d[sb18 + ss]; // out_1d > samples1\r
+ // filter1.input_sample(out_1d[sb18+ss], sb);\r
+ sb++; // sb should be loc*\r
+ }\r
+ filter1.input_samples(samples1);\r
+ filter1.calculate_pcm_samples(buffer);\r
+ }\r
+ } else {\r
+ for (ss = 0; ss < SSLIMIT; ss++) { // Polyphase synthesis\r
+ sb = 0;\r
+ for (sb18 = 0; sb18 < 576; sb18 += 18) {\r
+ samples2[sb] = out_1d[sb18 + ss]; // out_1d > samples2\r
+ // filter2.input_sample(out_1d[sb18+ss], sb);\r
+ sb++;\r
+ }\r
+ filter2.input_samples(samples2);\r
+ filter2.calculate_pcm_samples(buffer);\r
+ }\r
+\r
+ }\r
+ } // channels\r
+ } // granule\r
+\r
+ // System.out.println("Counter = ................................."+counter);\r
+ // if (counter < 609)\r
+ // {\r
+ counter++; // count should be loc*\r
+ buffer.write_buffer(1); // buffer!!!\r
+ // }\r
+ // else if (counter == 609)\r
+ // {\r
+ // buffer.close();\r
+ // counter++;\r
+ // }\r
+ // else\r
+ // {\r
+ // }\r
+\r
+ }\r
+\r
+ /**\r
+ * Reads the side info from the stream, assuming the entire. frame has been\r
+ * read already. Mono : 136 bits (= 17 bytes) Stereo : 256 bits (= 32 bytes)\r
+ */\r
+ private boolean get_side_info() {\r
+ int ch, gr;\r
+ if (header.version() == Header.MPEG1) {\r
+\r
+ si.main_data_begin = stream.get_bits(9);\r
+ if (channels == 1)\r
+ si.private_bits = stream.get_bits(5);\r
+ else\r
+ si.private_bits = stream.get_bits(3);\r
+\r
+ for (ch = 0; ch < channels; ch++) {\r
+ si.ch[ch].scfsi[0] = stream.get_bits(1);\r
+ si.ch[ch].scfsi[1] = stream.get_bits(1);\r
+ si.ch[ch].scfsi[2] = stream.get_bits(1);\r
+ si.ch[ch].scfsi[3] = stream.get_bits(1);\r
+ }\r
+\r
+ for (gr = 0; gr < 2; gr++) {\r
+ for (ch = 0; ch < channels; ch++) {\r
+ si.ch[ch].gr[gr].part2_3_length = stream.get_bits(12);\r
+ si.ch[ch].gr[gr].big_values = stream.get_bits(9);\r
+ si.ch[ch].gr[gr].global_gain = stream.get_bits(8);\r
+ si.ch[ch].gr[gr].scalefac_compress = stream.get_bits(4);\r
+ si.ch[ch].gr[gr].window_switching_flag = stream.get_bits(1);\r
+ if ((si.ch[ch].gr[gr].window_switching_flag) != 0) {\r
+ si.ch[ch].gr[gr].block_type = stream.get_bits(2);\r
+ si.ch[ch].gr[gr].mixed_block_flag = stream.get_bits(1);\r
+\r
+ si.ch[ch].gr[gr].table_select[0] = stream.get_bits(5);\r
+ si.ch[ch].gr[gr].table_select[1] = stream.get_bits(5);\r
+\r
+ si.ch[ch].gr[gr].subblock_gain[0] = stream.get_bits(3);\r
+ si.ch[ch].gr[gr].subblock_gain[1] = stream.get_bits(3);\r
+ si.ch[ch].gr[gr].subblock_gain[2] = stream.get_bits(3);\r
+\r
+ // Set region_count parameters since they are implicit in this case.\r
+\r
+ if (si.ch[ch].gr[gr].block_type == 0) {\r
+ // Side info bad: block_type == 0 in split block\r
+ return false;\r
+ } else if (si.ch[ch].gr[gr].block_type == 2 && si.ch[ch].gr[gr].mixed_block_flag == 0) {\r
+ si.ch[ch].gr[gr].region0_count = 8;\r
+ } else {\r
+ si.ch[ch].gr[gr].region0_count = 7;\r
+ }\r
+ si.ch[ch].gr[gr].region1_count = 20 - si.ch[ch].gr[gr].region0_count;\r
+ } else {\r
+ si.ch[ch].gr[gr].table_select[0] = stream.get_bits(5);\r
+ si.ch[ch].gr[gr].table_select[1] = stream.get_bits(5);\r
+ si.ch[ch].gr[gr].table_select[2] = stream.get_bits(5);\r
+ si.ch[ch].gr[gr].region0_count = stream.get_bits(4);\r
+ si.ch[ch].gr[gr].region1_count = stream.get_bits(3);\r
+ si.ch[ch].gr[gr].block_type = 0;\r
+ }\r
+ si.ch[ch].gr[gr].preflag = stream.get_bits(1);\r
+ si.ch[ch].gr[gr].scalefac_scale = stream.get_bits(1);\r
+ si.ch[ch].gr[gr].count1table_select = stream.get_bits(1);\r
+ }\r
+ }\r
+\r
+ } else { // MPEG-2 LSF, SZD: MPEG-2.5 LSF\r
+\r
+ si.main_data_begin = stream.get_bits(8);\r
+ if (channels == 1)\r
+ si.private_bits = stream.get_bits(1);\r
+ else\r
+ si.private_bits = stream.get_bits(2);\r
+\r
+ for (ch = 0; ch < channels; ch++) {\r
+\r
+ si.ch[ch].gr[0].part2_3_length = stream.get_bits(12);\r
+ si.ch[ch].gr[0].big_values = stream.get_bits(9);\r
+ si.ch[ch].gr[0].global_gain = stream.get_bits(8);\r
+ si.ch[ch].gr[0].scalefac_compress = stream.get_bits(9);\r
+ si.ch[ch].gr[0].window_switching_flag = stream.get_bits(1);\r
+\r
+ if ((si.ch[ch].gr[0].window_switching_flag) != 0) {\r
+\r
+ si.ch[ch].gr[0].block_type = stream.get_bits(2);\r
+ si.ch[ch].gr[0].mixed_block_flag = stream.get_bits(1);\r
+ si.ch[ch].gr[0].table_select[0] = stream.get_bits(5);\r
+ si.ch[ch].gr[0].table_select[1] = stream.get_bits(5);\r
+\r
+ si.ch[ch].gr[0].subblock_gain[0] = stream.get_bits(3);\r
+ si.ch[ch].gr[0].subblock_gain[1] = stream.get_bits(3);\r
+ si.ch[ch].gr[0].subblock_gain[2] = stream.get_bits(3);\r
+\r
+ // Set region_count parameters since they are implicit in this case.\r
+\r
+ if (si.ch[ch].gr[0].block_type == 0) {\r
+ // Side info bad: block_type == 0 in split block\r
+ return false;\r
+ } else if (si.ch[ch].gr[0].block_type == 2 && si.ch[ch].gr[0].mixed_block_flag == 0) {\r
+ si.ch[ch].gr[0].region0_count = 8;\r
+ } else {\r
+ si.ch[ch].gr[0].region0_count = 7;\r
+ si.ch[ch].gr[0].region1_count = 20 - si.ch[ch].gr[0].region0_count;\r
+ }\r
+\r
+ } else {\r
+ si.ch[ch].gr[0].table_select[0] = stream.get_bits(5);\r
+ si.ch[ch].gr[0].table_select[1] = stream.get_bits(5);\r
+ si.ch[ch].gr[0].table_select[2] = stream.get_bits(5);\r
+ si.ch[ch].gr[0].region0_count = stream.get_bits(4);\r
+ si.ch[ch].gr[0].region1_count = stream.get_bits(3);\r
+ si.ch[ch].gr[0].block_type = 0;\r
+ }\r
+\r
+ si.ch[ch].gr[0].scalefac_scale = stream.get_bits(1);\r
+ si.ch[ch].gr[0].count1table_select = stream.get_bits(1);\r
+ } // for(ch=0; ch<channels; ch++)\r
+ } // if (header.version() == MPEG1)\r
+ return true;\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ private void get_scale_factors(int ch, int gr) {\r
+ int sfb, window;\r
+ gr_info_s gr_info = (si.ch[ch].gr[gr]);\r
+ int scale_comp = gr_info.scalefac_compress;\r
+ int length0 = slen[0][scale_comp];\r
+ int length1 = slen[1][scale_comp];\r
+\r
+ if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) {\r
+ if ((gr_info.mixed_block_flag) != 0) { // MIXED\r
+ for (sfb = 0; sfb < 8; sfb++)\r
+ scalefac[ch].l[sfb] = br.hgetbits(slen[0][gr_info.scalefac_compress]);\r
+ for (sfb = 3; sfb < 6; sfb++)\r
+ for (window = 0; window < 3; window++)\r
+ scalefac[ch].s[window][sfb] = br.hgetbits(slen[0][gr_info.scalefac_compress]);\r
+ for (sfb = 6; sfb < 12; sfb++)\r
+ for (window = 0; window < 3; window++)\r
+ scalefac[ch].s[window][sfb] = br.hgetbits(slen[1][gr_info.scalefac_compress]);\r
+ for (sfb = 12, window = 0; window < 3; window++)\r
+ scalefac[ch].s[window][sfb] = 0;\r
+\r
+ } else { // SHORT\r
+\r
+ scalefac[ch].s[0][0] = br.hgetbits(length0);\r
+ scalefac[ch].s[1][0] = br.hgetbits(length0);\r
+ scalefac[ch].s[2][0] = br.hgetbits(length0);\r
+ scalefac[ch].s[0][1] = br.hgetbits(length0);\r
+ scalefac[ch].s[1][1] = br.hgetbits(length0);\r
+ scalefac[ch].s[2][1] = br.hgetbits(length0);\r
+ scalefac[ch].s[0][2] = br.hgetbits(length0);\r
+ scalefac[ch].s[1][2] = br.hgetbits(length0);\r
+ scalefac[ch].s[2][2] = br.hgetbits(length0);\r
+ scalefac[ch].s[0][3] = br.hgetbits(length0);\r
+ scalefac[ch].s[1][3] = br.hgetbits(length0);\r
+ scalefac[ch].s[2][3] = br.hgetbits(length0);\r
+ scalefac[ch].s[0][4] = br.hgetbits(length0);\r
+ scalefac[ch].s[1][4] = br.hgetbits(length0);\r
+ scalefac[ch].s[2][4] = br.hgetbits(length0);\r
+ scalefac[ch].s[0][5] = br.hgetbits(length0);\r
+ scalefac[ch].s[1][5] = br.hgetbits(length0);\r
+ scalefac[ch].s[2][5] = br.hgetbits(length0);\r
+ scalefac[ch].s[0][6] = br.hgetbits(length1);\r
+ scalefac[ch].s[1][6] = br.hgetbits(length1);\r
+ scalefac[ch].s[2][6] = br.hgetbits(length1);\r
+ scalefac[ch].s[0][7] = br.hgetbits(length1);\r
+ scalefac[ch].s[1][7] = br.hgetbits(length1);\r
+ scalefac[ch].s[2][7] = br.hgetbits(length1);\r
+ scalefac[ch].s[0][8] = br.hgetbits(length1);\r
+ scalefac[ch].s[1][8] = br.hgetbits(length1);\r
+ scalefac[ch].s[2][8] = br.hgetbits(length1);\r
+ scalefac[ch].s[0][9] = br.hgetbits(length1);\r
+ scalefac[ch].s[1][9] = br.hgetbits(length1);\r
+ scalefac[ch].s[2][9] = br.hgetbits(length1);\r
+ scalefac[ch].s[0][10] = br.hgetbits(length1);\r
+ scalefac[ch].s[1][10] = br.hgetbits(length1);\r
+ scalefac[ch].s[2][10] = br.hgetbits(length1);\r
+ scalefac[ch].s[0][11] = br.hgetbits(length1);\r
+ scalefac[ch].s[1][11] = br.hgetbits(length1);\r
+ scalefac[ch].s[2][11] = br.hgetbits(length1);\r
+ scalefac[ch].s[0][12] = 0;\r
+ scalefac[ch].s[1][12] = 0;\r
+ scalefac[ch].s[2][12] = 0;\r
+ } // SHORT\r
+\r
+ } else { // LONG types 0,1,3\r
+\r
+ if ((si.ch[ch].scfsi[0] == 0) || (gr == 0)) {\r
+ scalefac[ch].l[0] = br.hgetbits(length0);\r
+ scalefac[ch].l[1] = br.hgetbits(length0);\r
+ scalefac[ch].l[2] = br.hgetbits(length0);\r
+ scalefac[ch].l[3] = br.hgetbits(length0);\r
+ scalefac[ch].l[4] = br.hgetbits(length0);\r
+ scalefac[ch].l[5] = br.hgetbits(length0);\r
+ }\r
+ if ((si.ch[ch].scfsi[1] == 0) || (gr == 0)) {\r
+ scalefac[ch].l[6] = br.hgetbits(length0);\r
+ scalefac[ch].l[7] = br.hgetbits(length0);\r
+ scalefac[ch].l[8] = br.hgetbits(length0);\r
+ scalefac[ch].l[9] = br.hgetbits(length0);\r
+ scalefac[ch].l[10] = br.hgetbits(length0);\r
+ }\r
+ if ((si.ch[ch].scfsi[2] == 0) || (gr == 0)) {\r
+ scalefac[ch].l[11] = br.hgetbits(length1);\r
+ scalefac[ch].l[12] = br.hgetbits(length1);\r
+ scalefac[ch].l[13] = br.hgetbits(length1);\r
+ scalefac[ch].l[14] = br.hgetbits(length1);\r
+ scalefac[ch].l[15] = br.hgetbits(length1);\r
+ }\r
+ if ((si.ch[ch].scfsi[3] == 0) || (gr == 0)) {\r
+ scalefac[ch].l[16] = br.hgetbits(length1);\r
+ scalefac[ch].l[17] = br.hgetbits(length1);\r
+ scalefac[ch].l[18] = br.hgetbits(length1);\r
+ scalefac[ch].l[19] = br.hgetbits(length1);\r
+ scalefac[ch].l[20] = br.hgetbits(length1);\r
+ }\r
+\r
+ scalefac[ch].l[21] = 0;\r
+ scalefac[ch].l[22] = 0;\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ // MDM: new_slen is fully initialized before use, no need\r
+ // to reallocate array.\r
+ private final int[] new_slen = new int[4];\r
+\r
+ private void get_LSF_scale_data(int ch, int gr) {\r
+\r
+ int scalefac_comp, int_scalefac_comp;\r
+ int mode_ext = header.mode_extension();\r
+ int m;\r
+ int blocktypenumber;\r
+ int blocknumber = 0;\r
+\r
+ gr_info_s gr_info = (si.ch[ch].gr[gr]);\r
+\r
+ scalefac_comp = gr_info.scalefac_compress;\r
+\r
+ if (gr_info.block_type == 2) {\r
+ if (gr_info.mixed_block_flag == 0)\r
+ blocktypenumber = 1;\r
+ else if (gr_info.mixed_block_flag == 1)\r
+ blocktypenumber = 2;\r
+ else\r
+ blocktypenumber = 0;\r
+ } else {\r
+ blocktypenumber = 0;\r
+ }\r
+\r
+ if (!(((mode_ext == 1) || (mode_ext == 3)) && (ch == 1))) {\r
+\r
+ if (scalefac_comp < 400) {\r
+\r
+ new_slen[0] = (scalefac_comp >>> 4) / 5;\r
+ new_slen[1] = (scalefac_comp >>> 4) % 5;\r
+ new_slen[2] = (scalefac_comp & 0xF) >>> 2;\r
+ new_slen[3] = (scalefac_comp & 3);\r
+ si.ch[ch].gr[gr].preflag = 0;\r
+ blocknumber = 0;\r
+\r
+ } else if (scalefac_comp < 500) {\r
+\r
+ new_slen[0] = ((scalefac_comp - 400) >>> 2) / 5;\r
+ new_slen[1] = ((scalefac_comp - 400) >>> 2) % 5;\r
+ new_slen[2] = (scalefac_comp - 400) & 3;\r
+ new_slen[3] = 0;\r
+ si.ch[ch].gr[gr].preflag = 0;\r
+ blocknumber = 1;\r
+\r
+ } else if (scalefac_comp < 512) {\r
+\r
+ new_slen[0] = (scalefac_comp - 500) / 3;\r
+ new_slen[1] = (scalefac_comp - 500) % 3;\r
+ new_slen[2] = 0;\r
+ new_slen[3] = 0;\r
+ si.ch[ch].gr[gr].preflag = 1;\r
+ blocknumber = 2;\r
+ }\r
+ }\r
+\r
+ if ((((mode_ext == 1) || (mode_ext == 3)) && (ch == 1))) {\r
+ int_scalefac_comp = scalefac_comp >>> 1;\r
+\r
+ if (int_scalefac_comp < 180) {\r
+ new_slen[0] = int_scalefac_comp / 36;\r
+ new_slen[1] = (int_scalefac_comp % 36) / 6;\r
+ new_slen[2] = (int_scalefac_comp % 36) % 6;\r
+ new_slen[3] = 0;\r
+ si.ch[ch].gr[gr].preflag = 0;\r
+ blocknumber = 3;\r
+ } else if (int_scalefac_comp < 244) {\r
+ new_slen[0] = ((int_scalefac_comp - 180) & 0x3F) >>> 4;\r
+ new_slen[1] = ((int_scalefac_comp - 180) & 0xF) >>> 2;\r
+ new_slen[2] = (int_scalefac_comp - 180) & 3;\r
+ new_slen[3] = 0;\r
+ si.ch[ch].gr[gr].preflag = 0;\r
+ blocknumber = 4;\r
+ } else if (int_scalefac_comp < 255) {\r
+ new_slen[0] = (int_scalefac_comp - 244) / 3;\r
+ new_slen[1] = (int_scalefac_comp - 244) % 3;\r
+ new_slen[2] = 0;\r
+ new_slen[3] = 0;\r
+ si.ch[ch].gr[gr].preflag = 0;\r
+ blocknumber = 5;\r
+ }\r
+ }\r
+\r
+ for (int x = 0; x < 45; x++)\r
+ // why 45, not 54?\r
+ scalefac_buffer[x] = 0;\r
+\r
+ m = 0;\r
+ for (int i = 0; i < 4; i++) {\r
+ for (int j = 0; j < nr_of_sfb_block[blocknumber][blocktypenumber][i]; j++) {\r
+ scalefac_buffer[m] = (new_slen[i] == 0) ? 0 : br.hgetbits(new_slen[i]);\r
+ m++;\r
+\r
+ } // for (unint32 j ...\r
+ } // for (uint32 i ...\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ private void get_LSF_scale_factors(int ch, int gr) {\r
+ int m = 0;\r
+ int sfb, window;\r
+ gr_info_s gr_info = (si.ch[ch].gr[gr]);\r
+\r
+ get_LSF_scale_data(ch, gr);\r
+\r
+ if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) {\r
+ if (gr_info.mixed_block_flag != 0) { // MIXED\r
+ for (sfb = 0; sfb < 8; sfb++) {\r
+ scalefac[ch].l[sfb] = scalefac_buffer[m];\r
+ m++;\r
+ }\r
+ for (sfb = 3; sfb < 12; sfb++) {\r
+ for (window = 0; window < 3; window++) {\r
+ scalefac[ch].s[window][sfb] = scalefac_buffer[m];\r
+ m++;\r
+ }\r
+ }\r
+ for (window = 0; window < 3; window++)\r
+ scalefac[ch].s[window][12] = 0;\r
+\r
+ } else { // SHORT\r
+\r
+ for (sfb = 0; sfb < 12; sfb++) {\r
+ for (window = 0; window < 3; window++) {\r
+ scalefac[ch].s[window][sfb] = scalefac_buffer[m];\r
+ m++;\r
+ }\r
+ }\r
+\r
+ for (window = 0; window < 3; window++)\r
+ scalefac[ch].s[window][12] = 0;\r
+ }\r
+ } else { // LONG types 0,1,3\r
+\r
+ for (sfb = 0; sfb < 21; sfb++) {\r
+ scalefac[ch].l[sfb] = scalefac_buffer[m];\r
+ m++;\r
+ }\r
+ scalefac[ch].l[21] = 0; // Jeff\r
+ scalefac[ch].l[22] = 0;\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ int[] x = { 0 };\r
+ int[] y = { 0 };\r
+ int[] v = { 0 };\r
+ int[] w = { 0 };\r
+\r
+ private void huffman_decode(int ch, int gr) {\r
+ x[0] = 0;\r
+ y[0] = 0;\r
+ v[0] = 0;\r
+ w[0] = 0;\r
+\r
+ int part2_3_end = part2_start + si.ch[ch].gr[gr].part2_3_length;\r
+ int num_bits;\r
+ int region1Start;\r
+ int region2Start;\r
+ int index;\r
+\r
+ int buf, buf1;\r
+\r
+ huffcodetab h;\r
+\r
+ // Find region boundary for short block case\r
+\r
+ if (((si.ch[ch].gr[gr].window_switching_flag) != 0) && (si.ch[ch].gr[gr].block_type == 2)) {\r
+\r
+ // Region2.\r
+ // MS: Extrahandling for 8KHZ\r
+ region1Start = (sfreq == 8) ? 72 : 36; // sfb[9/3]*3=36 or in case 8KHZ =\r
+ // 72\r
+ region2Start = 576; // No Region2 for short block case\r
+\r
+ } else { // Find region boundary for long block case\r
+\r
+ buf = si.ch[ch].gr[gr].region0_count + 1;\r
+ buf1 = buf + si.ch[ch].gr[gr].region1_count + 1;\r
+\r
+ if (buf1 > sfBandIndex[sfreq].l.length - 1)\r
+ buf1 = sfBandIndex[sfreq].l.length - 1;\r
+\r
+ region1Start = sfBandIndex[sfreq].l[buf];\r
+ region2Start = sfBandIndex[sfreq].l[buf1]; /* MI */\r
+ }\r
+\r
+ index = 0;\r
+ // Read bigvalues area\r
+ for (int i = 0; i < (si.ch[ch].gr[gr].big_values << 1); i += 2) {\r
+ if (i < region1Start)\r
+ h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[0]];\r
+ else if (i < region2Start)\r
+ h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[1]];\r
+ else\r
+ h = huffcodetab.ht[si.ch[ch].gr[gr].table_select[2]];\r
+\r
+ huffcodetab.huffman_decoder(h, x, y, v, w, br);\r
+ // if (index >= is_1d.length)\r
+ // System.out.println("i0="+i+"/"+(si.ch[ch].gr[gr].big_values<<1)+" Index="+index+" is_1d="+is_1d.length);\r
+\r
+ is_1d[index++] = x[0];\r
+ is_1d[index++] = y[0];\r
+\r
+ CheckSumHuff = CheckSumHuff + x[0] + y[0];\r
+ // System.out.println("x = "+x[0]+" y = "+y[0]);\r
+ }\r
+\r
+ // Read count1 area\r
+ h = huffcodetab.ht[si.ch[ch].gr[gr].count1table_select + 32];\r
+ num_bits = br.hsstell();\r
+\r
+ while ((num_bits < part2_3_end) && (index < 576)) {\r
+\r
+ huffcodetab.huffman_decoder(h, x, y, v, w, br);\r
+\r
+ is_1d[index++] = v[0];\r
+ is_1d[index++] = w[0];\r
+ is_1d[index++] = x[0];\r
+ is_1d[index++] = y[0];\r
+ CheckSumHuff = CheckSumHuff + v[0] + w[0] + x[0] + y[0];\r
+ // System.out.println("v = "+v[0]+" w = "+w[0]);\r
+ // System.out.println("x = "+x[0]+" y = "+y[0]);\r
+ num_bits = br.hsstell();\r
+ }\r
+\r
+ if (num_bits > part2_3_end) {\r
+ br.rewindNbits(num_bits - part2_3_end);\r
+ index -= 4;\r
+ }\r
+\r
+ num_bits = br.hsstell();\r
+\r
+ // Dismiss stuffing bits\r
+ if (num_bits < part2_3_end)\r
+ br.hgetbits(part2_3_end - num_bits);\r
+\r
+ // Zero out rest\r
+\r
+ if (index < 576)\r
+ nonzero[ch] = index;\r
+ else\r
+ nonzero[ch] = 576;\r
+\r
+ if (index < 0)\r
+ index = 0;\r
+\r
+ // may not be necessary\r
+ for (; index < 576; index++)\r
+ is_1d[index] = 0;\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ private void i_stereo_k_values(int is_pos, int io_type, int i) {\r
+ if (is_pos == 0) {\r
+ k[0][i] = 1.0f;\r
+ k[1][i] = 1.0f;\r
+ } else if ((is_pos & 1) != 0) {\r
+ k[0][i] = io[io_type][(is_pos + 1) >>> 1];\r
+ k[1][i] = 1.0f;\r
+ } else {\r
+ k[0][i] = 1.0f;\r
+ k[1][i] = io[io_type][is_pos >>> 1];\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ private void dequantize_sample(float xr[][], int ch, int gr) {\r
+ gr_info_s gr_info = (si.ch[ch].gr[gr]);\r
+ int cb = 0;\r
+ int next_cb_boundary;\r
+ int cb_begin = 0;\r
+ int cb_width = 0;\r
+ int index = 0, t_index, j;\r
+ float g_gain;\r
+ float[][] xr_1d = xr;\r
+\r
+ // choose correct scalefactor band per block type, initalize boundary\r
+\r
+ if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) {\r
+ if (gr_info.mixed_block_flag != 0)\r
+ next_cb_boundary = sfBandIndex[sfreq].l[1]; // LONG blocks: 0,1,3\r
+ else {\r
+ cb_width = sfBandIndex[sfreq].s[1];\r
+ next_cb_boundary = (cb_width << 2) - cb_width;\r
+ cb_begin = 0;\r
+ }\r
+ } else {\r
+ next_cb_boundary = sfBandIndex[sfreq].l[1]; // LONG blocks: 0,1,3\r
+ }\r
+\r
+ // Compute overall (global) scaling.\r
+\r
+ g_gain = (float) Math.pow(2.0, (0.25 * (gr_info.global_gain - 210.0)));\r
+\r
+ for (j = 0; j < nonzero[ch]; j++) {\r
+ // Modif E.B 02/22/99\r
+ int reste = j % SSLIMIT;\r
+ int quotien = (int) ((j - reste) / SSLIMIT);\r
+ if (is_1d[j] == 0)\r
+ xr_1d[quotien][reste] = 0.0f;\r
+ else {\r
+ int abv = is_1d[j];\r
+ // Pow Array fix (11/17/04)\r
+ if (abv < t_43.length) {\r
+ if (is_1d[j] > 0)\r
+ xr_1d[quotien][reste] = g_gain * t_43[abv];\r
+ else {\r
+ if (-abv < t_43.length)\r
+ xr_1d[quotien][reste] = -g_gain * t_43[-abv];\r
+ else\r
+ xr_1d[quotien][reste] = -g_gain * (float) Math.pow(-abv, d43);\r
+ }\r
+ } else {\r
+ if (is_1d[j] > 0)\r
+ xr_1d[quotien][reste] = g_gain * (float) Math.pow(abv, d43);\r
+ else\r
+ xr_1d[quotien][reste] = -g_gain * (float) Math.pow(-abv, d43);\r
+ }\r
+ }\r
+ }\r
+\r
+ // apply formula per block type\r
+ for (j = 0; j < nonzero[ch]; j++) {\r
+ // Modif E.B 02/22/99\r
+ int reste = j % SSLIMIT;\r
+ int quotien = (int) ((j - reste) / SSLIMIT);\r
+\r
+ if (index == next_cb_boundary) { /* Adjust critical band boundary */\r
+ if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) {\r
+ if (gr_info.mixed_block_flag != 0) {\r
+\r
+ if (index == sfBandIndex[sfreq].l[8]) {\r
+ next_cb_boundary = sfBandIndex[sfreq].s[4];\r
+ next_cb_boundary = (next_cb_boundary << 2) - next_cb_boundary;\r
+ cb = 3;\r
+ cb_width = sfBandIndex[sfreq].s[4] - sfBandIndex[sfreq].s[3];\r
+\r
+ cb_begin = sfBandIndex[sfreq].s[3];\r
+ cb_begin = (cb_begin << 2) - cb_begin;\r
+\r
+ } else if (index < sfBandIndex[sfreq].l[8]) {\r
+\r
+ next_cb_boundary = sfBandIndex[sfreq].l[(++cb) + 1];\r
+\r
+ } else {\r
+\r
+ next_cb_boundary = sfBandIndex[sfreq].s[(++cb) + 1];\r
+ next_cb_boundary = (next_cb_boundary << 2) - next_cb_boundary;\r
+\r
+ cb_begin = sfBandIndex[sfreq].s[cb];\r
+ cb_width = sfBandIndex[sfreq].s[cb + 1] - cb_begin;\r
+ cb_begin = (cb_begin << 2) - cb_begin;\r
+ }\r
+\r
+ } else {\r
+\r
+ next_cb_boundary = sfBandIndex[sfreq].s[(++cb) + 1];\r
+ next_cb_boundary = (next_cb_boundary << 2) - next_cb_boundary;\r
+\r
+ cb_begin = sfBandIndex[sfreq].s[cb];\r
+ cb_width = sfBandIndex[sfreq].s[cb + 1] - cb_begin;\r
+ cb_begin = (cb_begin << 2) - cb_begin;\r
+ }\r
+\r
+ } else { // long blocks\r
+\r
+ next_cb_boundary = sfBandIndex[sfreq].l[(++cb) + 1];\r
+\r
+ }\r
+ }\r
+\r
+ // Do long/short dependent scaling operations\r
+\r
+ if ((gr_info.window_switching_flag != 0)\r
+ && (((gr_info.block_type == 2) && (gr_info.mixed_block_flag == 0)) || ((gr_info.block_type == 2)\r
+ && (gr_info.mixed_block_flag != 0) && (j >= 36)))) {\r
+\r
+ t_index = (index - cb_begin) / cb_width;\r
+ /*\r
+ * xr[sb][ss] *= pow(2.0, ((-2.0 * gr_info.subblock_gain[t_index]) -(0.5\r
+ * * (1.0 + gr_info.scalefac_scale) scalefac[ch].s[t_index][cb])));\r
+ */\r
+ int idx = scalefac[ch].s[t_index][cb] << gr_info.scalefac_scale;\r
+ idx += (gr_info.subblock_gain[t_index] << 2);\r
+\r
+ xr_1d[quotien][reste] *= two_to_negative_half_pow[idx];\r
+\r
+ } else { // LONG block types 0,1,3 & 1st 2 subbands of switched blocks\r
+ /*\r
+ * xr[sb][ss] *= pow(2.0, -0.5 * (1.0+gr_info.scalefac_scale)\r
+ * (scalefac[ch].l[cb] + gr_info.preflag * pretab[cb]));\r
+ */\r
+ int idx = scalefac[ch].l[cb];\r
+\r
+ if (gr_info.preflag != 0)\r
+ idx += pretab[cb];\r
+\r
+ idx = idx << gr_info.scalefac_scale;\r
+ xr_1d[quotien][reste] *= two_to_negative_half_pow[idx];\r
+ }\r
+ index++;\r
+ }\r
+\r
+ for (j = nonzero[ch]; j < 576; j++) {\r
+ // Modif E.B 02/22/99\r
+ int reste = j % SSLIMIT;\r
+ int quotien = (int) ((j - reste) / SSLIMIT);\r
+ if (reste < 0)\r
+ reste = 0;\r
+ if (quotien < 0)\r
+ quotien = 0;\r
+ xr_1d[quotien][reste] = 0.0f;\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ private void reorder(float xr[][], int ch, int gr) {\r
+ gr_info_s gr_info = (si.ch[ch].gr[gr]);\r
+ int freq, freq3;\r
+ int index;\r
+ int sfb, sfb_start, sfb_lines;\r
+ int src_line, des_line;\r
+ float[][] xr_1d = xr;\r
+\r
+ if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) {\r
+\r
+ for (index = 0; index < 576; index++)\r
+ out_1d[index] = 0.0f;\r
+\r
+ if (gr_info.mixed_block_flag != 0) {\r
+ // NO REORDER FOR LOW 2 SUBBANDS\r
+ for (index = 0; index < 36; index++) {\r
+ // Modif E.B 02/22/99\r
+ int reste = index % SSLIMIT;\r
+ int quotien = (int) ((index - reste) / SSLIMIT);\r
+ out_1d[index] = xr_1d[quotien][reste];\r
+ }\r
+ // REORDERING FOR REST SWITCHED SHORT\r
+ /*\r
+ * for( sfb=3,sfb_start=sfBandIndex[sfreq].s[3],\r
+ * sfb_lines=sfBandIndex[sfreq].s[4] - sfb_start; sfb < 13;\r
+ * sfb++,sfb_start = sfBandIndex[sfreq].s[sfb], sfb_lines =\r
+ * sfBandIndex[sfreq].s[sfb+1] - sfb_start ) {\r
+ */\r
+ for (sfb = 3; sfb < 13; sfb++) {\r
+ // System.out.println("sfreq="+sfreq+" sfb="+sfb+" sfBandIndex="+sfBandIndex.length+" sfBandIndex[sfreq].s="+sfBandIndex[sfreq].s.length);\r
+ sfb_start = sfBandIndex[sfreq].s[sfb];\r
+ sfb_lines = sfBandIndex[sfreq].s[sfb + 1] - sfb_start;\r
+\r
+ int sfb_start3 = (sfb_start << 2) - sfb_start;\r
+\r
+ for (freq = 0, freq3 = 0; freq < sfb_lines; freq++, freq3 += 3) {\r
+\r
+ src_line = sfb_start3 + freq;\r
+ des_line = sfb_start3 + freq3;\r
+ // Modif E.B 02/22/99\r
+ int reste = src_line % SSLIMIT;\r
+ int quotien = (int) ((src_line - reste) / SSLIMIT);\r
+\r
+ out_1d[des_line] = xr_1d[quotien][reste];\r
+ src_line += sfb_lines;\r
+ des_line++;\r
+\r
+ reste = src_line % SSLIMIT;\r
+ quotien = (int) ((src_line - reste) / SSLIMIT);\r
+\r
+ out_1d[des_line] = xr_1d[quotien][reste];\r
+ src_line += sfb_lines;\r
+ des_line++;\r
+\r
+ reste = src_line % SSLIMIT;\r
+ quotien = (int) ((src_line - reste) / SSLIMIT);\r
+\r
+ out_1d[des_line] = xr_1d[quotien][reste];\r
+ }\r
+ }\r
+\r
+ } else { // pure short\r
+ for (index = 0; index < 576; index++) {\r
+ int j = reorder_table[sfreq][index];\r
+ int reste = j % SSLIMIT;\r
+ int quotien = (int) ((j - reste) / SSLIMIT);\r
+ out_1d[index] = xr_1d[quotien][reste];\r
+ }\r
+ }\r
+ } else { // long blocks\r
+ for (index = 0; index < 576; index++) {\r
+ // Modif E.B 02/22/99\r
+ int reste = index % SSLIMIT;\r
+ int quotien = (int) ((index - reste) / SSLIMIT);\r
+ out_1d[index] = xr_1d[quotien][reste];\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+\r
+ int[] is_pos = new int[576];\r
+ float[] is_ratio = new float[576];\r
+\r
+ private void stereo(int gr) {\r
+ int sb, ss;\r
+\r
+ if (channels == 1) { // mono , bypass xr[0][][] to lr[0][][]\r
+\r
+ for (sb = 0; sb < SBLIMIT; sb++)\r
+ for (ss = 0; ss < SSLIMIT; ss += 3) {\r
+ lr[0][sb][ss] = ro[0][sb][ss];\r
+ lr[0][sb][ss + 1] = ro[0][sb][ss + 1];\r
+ lr[0][sb][ss + 2] = ro[0][sb][ss + 2];\r
+ }\r
+\r
+ } else {\r
+\r
+ gr_info_s gr_info = (si.ch[0].gr[gr]);\r
+ int mode_ext = header.mode_extension();\r
+ int sfb;\r
+ int i;\r
+ int lines, temp, temp2;\r
+\r
+ boolean ms_stereo = ((header.mode() == Header.JOINT_STEREO) && ((mode_ext & 0x2) != 0));\r
+ boolean i_stereo = ((header.mode() == Header.JOINT_STEREO) && ((mode_ext & 0x1) != 0));\r
+ boolean lsf =\r
+ ((header.version() == Header.MPEG2_LSF || header.version() == Header.MPEG25_LSF)); // SZD\r
+\r
+ int io_type = (gr_info.scalefac_compress & 1);\r
+\r
+ // initialization\r
+\r
+ for (i = 0; i < 576; i++) {\r
+ is_pos[i] = 7;\r
+\r
+ is_ratio[i] = 0.0f;\r
+ }\r
+\r
+ if (i_stereo) {\r
+ if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) {\r
+ if (gr_info.mixed_block_flag != 0) {\r
+\r
+ int max_sfb = 0;\r
+\r
+ for (int j = 0; j < 3; j++) {\r
+ int sfbcnt;\r
+ sfbcnt = 2;\r
+ for (sfb = 12; sfb >= 3; sfb--) {\r
+ i = sfBandIndex[sfreq].s[sfb];\r
+ lines = sfBandIndex[sfreq].s[sfb + 1] - i;\r
+ i = (i << 2) - i + (j + 1) * lines - 1;\r
+\r
+ while (lines > 0) {\r
+ if (ro[1][i / 18][i % 18] != 0.0f) {\r
+ // MDM: in java, array access is very slow.\r
+ // Is quicker to compute div and mod values.\r
+ // if (ro[1][ss_div[i]][ss_mod[i]] != 0.0f) {\r
+ sfbcnt = sfb;\r
+ sfb = -10;\r
+ lines = -10;\r
+ }\r
+\r
+ lines--;\r
+ i--;\r
+\r
+ } // while (lines > 0)\r
+\r
+ } // for (sfb=12 ...\r
+ sfb = sfbcnt + 1;\r
+\r
+ if (sfb > max_sfb)\r
+ max_sfb = sfb;\r
+\r
+ while (sfb < 12) {\r
+ temp = sfBandIndex[sfreq].s[sfb];\r
+ sb = sfBandIndex[sfreq].s[sfb + 1] - temp;\r
+ i = (temp << 2) - temp + j * sb;\r
+\r
+ for (; sb > 0; sb--) {\r
+ is_pos[i] = scalefac[1].s[j][sfb];\r
+ if (is_pos[i] != 7)\r
+ if (lsf)\r
+ i_stereo_k_values(is_pos[i], io_type, i);\r
+ else\r
+ is_ratio[i] = TAN12[is_pos[i]];\r
+\r
+ i++;\r
+ } // for (; sb>0...\r
+ sfb++;\r
+ } // while (sfb < 12)\r
+ sfb = sfBandIndex[sfreq].s[10];\r
+ sb = sfBandIndex[sfreq].s[11] - sfb;\r
+ sfb = (sfb << 2) - sfb + j * sb;\r
+ temp = sfBandIndex[sfreq].s[11];\r
+ sb = sfBandIndex[sfreq].s[12] - temp;\r
+ i = (temp << 2) - temp + j * sb;\r
+\r
+ for (; sb > 0; sb--) {\r
+ is_pos[i] = is_pos[sfb];\r
+\r
+ if (lsf) {\r
+ k[0][i] = k[0][sfb];\r
+ k[1][i] = k[1][sfb];\r
+ } else {\r
+ is_ratio[i] = is_ratio[sfb];\r
+ }\r
+ i++;\r
+ } // for (; sb > 0 ...\r
+ }\r
+ if (max_sfb <= 3) {\r
+ i = 2;\r
+ ss = 17;\r
+ sb = -1;\r
+ while (i >= 0) {\r
+ if (ro[1][i][ss] != 0.0f) {\r
+ sb = (i << 4) + (i << 1) + ss;\r
+ i = -1;\r
+ } else {\r
+ ss--;\r
+ if (ss < 0) {\r
+ i--;\r
+ ss = 17;\r
+ }\r
+ } // if (ro ...\r
+ } // while (i>=0)\r
+ i = 0;\r
+ while (sfBandIndex[sfreq].l[i] <= sb)\r
+ i++;\r
+ sfb = i;\r
+ i = sfBandIndex[sfreq].l[i];\r
+ for (; sfb < 8; sfb++) {\r
+ sb = sfBandIndex[sfreq].l[sfb + 1] - sfBandIndex[sfreq].l[sfb];\r
+ for (; sb > 0; sb--) {\r
+ is_pos[i] = scalefac[1].l[sfb];\r
+ if (is_pos[i] != 7)\r
+ if (lsf)\r
+ i_stereo_k_values(is_pos[i], io_type, i);\r
+ else\r
+ is_ratio[i] = TAN12[is_pos[i]];\r
+ i++;\r
+ } // for (; sb>0 ...\r
+ } // for (; sfb<8 ...\r
+ } // for (j=0 ...\r
+ } else { // if (gr_info.mixed_block_flag)\r
+ for (int j = 0; j < 3; j++) {\r
+ int sfbcnt;\r
+ sfbcnt = -1;\r
+ for (sfb = 12; sfb >= 0; sfb--) {\r
+ temp = sfBandIndex[sfreq].s[sfb];\r
+ lines = sfBandIndex[sfreq].s[sfb + 1] - temp;\r
+ i = (temp << 2) - temp + (j + 1) * lines - 1;\r
+\r
+ while (lines > 0) {\r
+ if (ro[1][i / 18][i % 18] != 0.0f) {\r
+ // MDM: in java, array access is very slow.\r
+ // Is quicker to compute div and mod values.\r
+ // if (ro[1][ss_div[i]][ss_mod[i]] != 0.0f) {\r
+ sfbcnt = sfb;\r
+ sfb = -10;\r
+ lines = -10;\r
+ }\r
+ lines--;\r
+ i--;\r
+ } // while (lines > 0) */\r
+\r
+ } // for (sfb=12 ...\r
+ sfb = sfbcnt + 1;\r
+ while (sfb < 12) {\r
+ temp = sfBandIndex[sfreq].s[sfb];\r
+ sb = sfBandIndex[sfreq].s[sfb + 1] - temp;\r
+ i = (temp << 2) - temp + j * sb;\r
+ for (; sb > 0; sb--) {\r
+ is_pos[i] = scalefac[1].s[j][sfb];\r
+ if (is_pos[i] != 7)\r
+ if (lsf)\r
+ i_stereo_k_values(is_pos[i], io_type, i);\r
+ else\r
+ is_ratio[i] = TAN12[is_pos[i]];\r
+ i++;\r
+ } // for (; sb>0 ...\r
+ sfb++;\r
+ } // while (sfb<12)\r
+\r
+ temp = sfBandIndex[sfreq].s[10];\r
+ temp2 = sfBandIndex[sfreq].s[11];\r
+ sb = temp2 - temp;\r
+ sfb = (temp << 2) - temp + j * sb;\r
+ sb = sfBandIndex[sfreq].s[12] - temp2;\r
+ i = (temp2 << 2) - temp2 + j * sb;\r
+\r
+ for (; sb > 0; sb--) {\r
+ is_pos[i] = is_pos[sfb];\r
+\r
+ if (lsf) {\r
+ k[0][i] = k[0][sfb];\r
+ k[1][i] = k[1][sfb];\r
+ } else {\r
+ is_ratio[i] = is_ratio[sfb];\r
+ }\r
+ i++;\r
+ } // for (; sb>0 ...\r
+ } // for (sfb=12\r
+ } // for (j=0 ...\r
+ } else { // if (gr_info.window_switching_flag ...\r
+ i = 31;\r
+ ss = 17;\r
+ sb = 0;\r
+ while (i >= 0) {\r
+ if (ro[1][i][ss] != 0.0f) {\r
+ sb = (i << 4) + (i << 1) + ss;\r
+ i = -1;\r
+ } else {\r
+ ss--;\r
+ if (ss < 0) {\r
+ i--;\r
+ ss = 17;\r
+ }\r
+ }\r
+ }\r
+ i = 0;\r
+ while (sfBandIndex[sfreq].l[i] <= sb)\r
+ i++;\r
+\r
+ sfb = i;\r
+ i = sfBandIndex[sfreq].l[i];\r
+ for (; sfb < 21; sfb++) {\r
+ sb = sfBandIndex[sfreq].l[sfb + 1] - sfBandIndex[sfreq].l[sfb];\r
+ for (; sb > 0; sb--) {\r
+ is_pos[i] = scalefac[1].l[sfb];\r
+ if (is_pos[i] != 7)\r
+ if (lsf)\r
+ i_stereo_k_values(is_pos[i], io_type, i);\r
+ else\r
+ is_ratio[i] = TAN12[is_pos[i]];\r
+ i++;\r
+ }\r
+ }\r
+ sfb = sfBandIndex[sfreq].l[20];\r
+ for (sb = 576 - sfBandIndex[sfreq].l[21]; (sb > 0) && (i < 576); sb--) {\r
+ is_pos[i] = is_pos[sfb]; // error here : i >=576\r
+\r
+ if (lsf) {\r
+ k[0][i] = k[0][sfb];\r
+ k[1][i] = k[1][sfb];\r
+ } else {\r
+ is_ratio[i] = is_ratio[sfb];\r
+ }\r
+ i++;\r
+ } // if (gr_info.mixed_block_flag)\r
+ } // if (gr_info.window_switching_flag ...\r
+ } // if (i_stereo)\r
+\r
+ i = 0;\r
+ for (sb = 0; sb < SBLIMIT; sb++)\r
+ for (ss = 0; ss < SSLIMIT; ss++) {\r
+ if (is_pos[i] == 7) {\r
+ if (ms_stereo) {\r
+ lr[0][sb][ss] = (ro[0][sb][ss] + ro[1][sb][ss]) * 0.707106781f;\r
+ lr[1][sb][ss] = (ro[0][sb][ss] - ro[1][sb][ss]) * 0.707106781f;\r
+ } else {\r
+ lr[0][sb][ss] = ro[0][sb][ss];\r
+ lr[1][sb][ss] = ro[1][sb][ss];\r
+ }\r
+ } else if (i_stereo) {\r
+\r
+ if (lsf) {\r
+ lr[0][sb][ss] = ro[0][sb][ss] * k[0][i];\r
+ lr[1][sb][ss] = ro[0][sb][ss] * k[1][i];\r
+ } else {\r
+ lr[1][sb][ss] = ro[0][sb][ss] / (float) (1 + is_ratio[i]);\r
+ lr[0][sb][ss] = lr[1][sb][ss] * is_ratio[i];\r
+ }\r
+ }\r
+ /*\r
+ * else { System.out.println("Error in stereo processing\n"); }\r
+ */\r
+ i++;\r
+ }\r
+\r
+ } // channels == 2\r
+\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ private void antialias(int ch, int gr) {\r
+ int sb18, ss, sb18lim;\r
+ gr_info_s gr_info = (si.ch[ch].gr[gr]);\r
+ // 31 alias-reduction operations between each pair of sub-bands\r
+ // with 8 butterflies between each pair\r
+\r
+ if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)\r
+ && !(gr_info.mixed_block_flag != 0))\r
+ return;\r
+\r
+ if ((gr_info.window_switching_flag != 0) && (gr_info.mixed_block_flag != 0)\r
+ && (gr_info.block_type == 2)) {\r
+ sb18lim = 18;\r
+ } else {\r
+ sb18lim = 558;\r
+ }\r
+\r
+ for (sb18 = 0; sb18 < sb18lim; sb18 += 18) {\r
+ for (ss = 0; ss < 8; ss++) {\r
+ int src_idx1 = sb18 + 17 - ss;\r
+ int src_idx2 = sb18 + 18 + ss;\r
+ float bu = out_1d[src_idx1];\r
+ float bd = out_1d[src_idx2];\r
+ out_1d[src_idx1] = (bu * cs[ss]) - (bd * ca[ss]);\r
+ out_1d[src_idx2] = (bd * cs[ss]) + (bu * ca[ss]);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+\r
+ // MDM: tsOutCopy and rawout do not need initializing, so the arrays\r
+ // can be reused.\r
+ float[] tsOutCopy = new float[18];\r
+ float[] rawout = new float[36];\r
+\r
+ private void hybrid(int ch, int gr) {\r
+ int bt;\r
+ int sb18;\r
+ gr_info_s gr_info = (si.ch[ch].gr[gr]);\r
+ float[] tsOut;\r
+\r
+ float[][] prvblk;\r
+\r
+ for (sb18 = 0; sb18 < 576; sb18 += 18) {\r
+ bt =\r
+ ((gr_info.window_switching_flag != 0) && (gr_info.mixed_block_flag != 0) && (sb18 < 36))\r
+ ? 0 : gr_info.block_type;\r
+\r
+ tsOut = out_1d;\r
+ // Modif E.B 02/22/99\r
+ for (int cc = 0; cc < 18; cc++)\r
+ tsOutCopy[cc] = tsOut[cc + sb18];\r
+\r
+ inv_mdct(tsOutCopy, rawout, bt);\r
+\r
+ for (int cc = 0; cc < 18; cc++)\r
+ tsOut[cc + sb18] = tsOutCopy[cc];\r
+ // Fin Modif\r
+\r
+ // overlap addition\r
+ prvblk = prevblck;\r
+\r
+ tsOut[0 + sb18] = rawout[0] + prvblk[ch][sb18 + 0];\r
+ prvblk[ch][sb18 + 0] = rawout[18];\r
+ tsOut[1 + sb18] = rawout[1] + prvblk[ch][sb18 + 1];\r
+ prvblk[ch][sb18 + 1] = rawout[19];\r
+ tsOut[2 + sb18] = rawout[2] + prvblk[ch][sb18 + 2];\r
+ prvblk[ch][sb18 + 2] = rawout[20];\r
+ tsOut[3 + sb18] = rawout[3] + prvblk[ch][sb18 + 3];\r
+ prvblk[ch][sb18 + 3] = rawout[21];\r
+ tsOut[4 + sb18] = rawout[4] + prvblk[ch][sb18 + 4];\r
+ prvblk[ch][sb18 + 4] = rawout[22];\r
+ tsOut[5 + sb18] = rawout[5] + prvblk[ch][sb18 + 5];\r
+ prvblk[ch][sb18 + 5] = rawout[23];\r
+ tsOut[6 + sb18] = rawout[6] + prvblk[ch][sb18 + 6];\r
+ prvblk[ch][sb18 + 6] = rawout[24];\r
+ tsOut[7 + sb18] = rawout[7] + prvblk[ch][sb18 + 7];\r
+ prvblk[ch][sb18 + 7] = rawout[25];\r
+ tsOut[8 + sb18] = rawout[8] + prvblk[ch][sb18 + 8];\r
+ prvblk[ch][sb18 + 8] = rawout[26];\r
+ tsOut[9 + sb18] = rawout[9] + prvblk[ch][sb18 + 9];\r
+ prvblk[ch][sb18 + 9] = rawout[27];\r
+ tsOut[10 + sb18] = rawout[10] + prvblk[ch][sb18 + 10];\r
+ prvblk[ch][sb18 + 10] = rawout[28];\r
+ tsOut[11 + sb18] = rawout[11] + prvblk[ch][sb18 + 11];\r
+ prvblk[ch][sb18 + 11] = rawout[29];\r
+ tsOut[12 + sb18] = rawout[12] + prvblk[ch][sb18 + 12];\r
+ prvblk[ch][sb18 + 12] = rawout[30];\r
+ tsOut[13 + sb18] = rawout[13] + prvblk[ch][sb18 + 13];\r
+ prvblk[ch][sb18 + 13] = rawout[31];\r
+ tsOut[14 + sb18] = rawout[14] + prvblk[ch][sb18 + 14];\r
+ prvblk[ch][sb18 + 14] = rawout[32];\r
+ tsOut[15 + sb18] = rawout[15] + prvblk[ch][sb18 + 15];\r
+ prvblk[ch][sb18 + 15] = rawout[33];\r
+ tsOut[16 + sb18] = rawout[16] + prvblk[ch][sb18 + 16];\r
+ prvblk[ch][sb18 + 16] = rawout[34];\r
+ tsOut[17 + sb18] = rawout[17] + prvblk[ch][sb18 + 17];\r
+ prvblk[ch][sb18 + 17] = rawout[35];\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ private void do_downmix() {\r
+ for (int sb = 0; sb < SSLIMIT; sb++) {\r
+ for (int ss = 0; ss < SSLIMIT; ss += 3) {\r
+ lr[0][sb][ss] = (lr[0][sb][ss] + lr[1][sb][ss]) * 0.5f;\r
+ lr[0][sb][ss + 1] = (lr[0][sb][ss + 1] + lr[1][sb][ss + 1]) * 0.5f;\r
+ lr[0][sb][ss + 2] = (lr[0][sb][ss + 2] + lr[1][sb][ss + 2]) * 0.5f;\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Fast INV_MDCT.\r
+ */\r
+\r
+ public void inv_mdct(float[] in, float[] out, int block_type) {\r
+ float[] win_bt;\r
+ int i;\r
+\r
+ float tmpf_0, tmpf_1, tmpf_2, tmpf_3, tmpf_4, tmpf_5, tmpf_6, tmpf_7, tmpf_8, tmpf_9;\r
+ float tmpf_10, tmpf_11, tmpf_12, tmpf_13, tmpf_14, tmpf_15, tmpf_16, tmpf_17;\r
+\r
+ tmpf_0 =\r
+ tmpf_1 =\r
+ tmpf_2 =\r
+ tmpf_3 =\r
+ tmpf_4 =\r
+ tmpf_5 =\r
+ tmpf_6 =\r
+ tmpf_7 =\r
+ tmpf_8 =\r
+ tmpf_9 =\r
+ tmpf_10 =\r
+ tmpf_11 =\r
+ tmpf_12 =\r
+ tmpf_13 =\r
+ tmpf_14 =\r
+ tmpf_15 = tmpf_16 = tmpf_17 = 0.0f;\r
+\r
+ if (block_type == 2) {\r
+\r
+ /*\r
+ * \r
+ * Under MicrosoftVM 2922, This causes a GPF, or At best, an\r
+ * ArrayIndexOutOfBoundsExceptin. for(int p=0;p<36;p+=9) { out[p] =\r
+ * out[p+1] = out[p+2] = out[p+3] = out[p+4] = out[p+5] = out[p+6] =\r
+ * out[p+7] = out[p+8] = 0.0f; }\r
+ */\r
+ out[0] = 0.0f;\r
+ out[1] = 0.0f;\r
+ out[2] = 0.0f;\r
+ out[3] = 0.0f;\r
+ out[4] = 0.0f;\r
+ out[5] = 0.0f;\r
+ out[6] = 0.0f;\r
+ out[7] = 0.0f;\r
+ out[8] = 0.0f;\r
+ out[9] = 0.0f;\r
+ out[10] = 0.0f;\r
+ out[11] = 0.0f;\r
+ out[12] = 0.0f;\r
+ out[13] = 0.0f;\r
+ out[14] = 0.0f;\r
+ out[15] = 0.0f;\r
+ out[16] = 0.0f;\r
+ out[17] = 0.0f;\r
+ out[18] = 0.0f;\r
+ out[19] = 0.0f;\r
+ out[20] = 0.0f;\r
+ out[21] = 0.0f;\r
+ out[22] = 0.0f;\r
+ out[23] = 0.0f;\r
+ out[24] = 0.0f;\r
+ out[25] = 0.0f;\r
+ out[26] = 0.0f;\r
+ out[27] = 0.0f;\r
+ out[28] = 0.0f;\r
+ out[29] = 0.0f;\r
+ out[30] = 0.0f;\r
+ out[31] = 0.0f;\r
+ out[32] = 0.0f;\r
+ out[33] = 0.0f;\r
+ out[34] = 0.0f;\r
+ out[35] = 0.0f;\r
+\r
+ int six_i = 0;\r
+\r
+ for (i = 0; i < 3; i++) {\r
+ // 12 point IMDCT\r
+ // Begin 12 point IDCT\r
+ // Input aliasing for 12 pt IDCT\r
+ in[15 + i] += in[12 + i];\r
+ in[12 + i] += in[9 + i];\r
+ in[9 + i] += in[6 + i];\r
+ in[6 + i] += in[3 + i];\r
+ in[3 + i] += in[0 + i];\r
+\r
+ // Input aliasing on odd indices (for 6 point IDCT)\r
+ in[15 + i] += in[9 + i];\r
+ in[9 + i] += in[3 + i];\r
+\r
+ // 3 point IDCT on even indices\r
+ float pp1, pp2, sum;\r
+ pp2 = in[12 + i] * 0.500000000f;\r
+ pp1 = in[6 + i] * 0.866025403f;\r
+ sum = in[0 + i] + pp2;\r
+ tmpf_1 = in[0 + i] - in[12 + i];\r
+ tmpf_0 = sum + pp1;\r
+ tmpf_2 = sum - pp1;\r
+\r
+ // End 3 point IDCT on even indices\r
+ // 3 point IDCT on odd indices (for 6 point IDCT)\r
+ pp2 = in[15 + i] * 0.500000000f;\r
+ pp1 = in[9 + i] * 0.866025403f;\r
+ sum = in[3 + i] + pp2;\r
+ tmpf_4 = in[3 + i] - in[15 + i];\r
+ tmpf_5 = sum + pp1;\r
+ tmpf_3 = sum - pp1;\r
+ // End 3 point IDCT on odd indices\r
+ // Twiddle factors on odd indices (for 6 point IDCT)\r
+\r
+ tmpf_3 *= 1.931851653f;\r
+ tmpf_4 *= 0.707106781f;\r
+ tmpf_5 *= 0.517638090f;\r
+\r
+ // Output butterflies on 2 3 point IDCT's (for 6 point IDCT)\r
+ float save = tmpf_0;\r
+ tmpf_0 += tmpf_5;\r
+ tmpf_5 = save - tmpf_5;\r
+ save = tmpf_1;\r
+ tmpf_1 += tmpf_4;\r
+ tmpf_4 = save - tmpf_4;\r
+ save = tmpf_2;\r
+ tmpf_2 += tmpf_3;\r
+ tmpf_3 = save - tmpf_3;\r
+\r
+ // End 6 point IDCT\r
+ // Twiddle factors on indices (for 12 point IDCT)\r
+\r
+ tmpf_0 *= 0.504314480f;\r
+ tmpf_1 *= 0.541196100f;\r
+ tmpf_2 *= 0.630236207f;\r
+ tmpf_3 *= 0.821339815f;\r
+ tmpf_4 *= 1.306562965f;\r
+ tmpf_5 *= 3.830648788f;\r
+\r
+ // End 12 point IDCT\r
+\r
+ // Shift to 12 point modified IDCT, multiply by window type 2\r
+ tmpf_8 = -tmpf_0 * 0.793353340f;\r
+ tmpf_9 = -tmpf_0 * 0.608761429f;\r
+ tmpf_7 = -tmpf_1 * 0.923879532f;\r
+ tmpf_10 = -tmpf_1 * 0.382683432f;\r
+ tmpf_6 = -tmpf_2 * 0.991444861f;\r
+ tmpf_11 = -tmpf_2 * 0.130526192f;\r
+\r
+ tmpf_0 = tmpf_3;\r
+ tmpf_1 = tmpf_4 * 0.382683432f;\r
+ tmpf_2 = tmpf_5 * 0.608761429f;\r
+\r
+ tmpf_3 = -tmpf_5 * 0.793353340f;\r
+ tmpf_4 = -tmpf_4 * 0.923879532f;\r
+ tmpf_5 = -tmpf_0 * 0.991444861f;\r
+\r
+ tmpf_0 *= 0.130526192f;\r
+\r
+ out[six_i + 6] += tmpf_0;\r
+ out[six_i + 7] += tmpf_1;\r
+ out[six_i + 8] += tmpf_2;\r
+ out[six_i + 9] += tmpf_3;\r
+ out[six_i + 10] += tmpf_4;\r
+ out[six_i + 11] += tmpf_5;\r
+ out[six_i + 12] += tmpf_6;\r
+ out[six_i + 13] += tmpf_7;\r
+ out[six_i + 14] += tmpf_8;\r
+ out[six_i + 15] += tmpf_9;\r
+ out[six_i + 16] += tmpf_10;\r
+ out[six_i + 17] += tmpf_11;\r
+\r
+ six_i += 6;\r
+ }\r
+ } else {\r
+ // 36 point IDCT\r
+ // input aliasing for 36 point IDCT\r
+ in[17] += in[16];\r
+ in[16] += in[15];\r
+ in[15] += in[14];\r
+ in[14] += in[13];\r
+ in[13] += in[12];\r
+ in[12] += in[11];\r
+ in[11] += in[10];\r
+ in[10] += in[9];\r
+ in[9] += in[8];\r
+ in[8] += in[7];\r
+ in[7] += in[6];\r
+ in[6] += in[5];\r
+ in[5] += in[4];\r
+ in[4] += in[3];\r
+ in[3] += in[2];\r
+ in[2] += in[1];\r
+ in[1] += in[0];\r
+\r
+ // 18 point IDCT for odd indices\r
+ // input aliasing for 18 point IDCT\r
+ in[17] += in[15];\r
+ in[15] += in[13];\r
+ in[13] += in[11];\r
+ in[11] += in[9];\r
+ in[9] += in[7];\r
+ in[7] += in[5];\r
+ in[5] += in[3];\r
+ in[3] += in[1];\r
+\r
+ float tmp0, tmp1, tmp2, tmp3, tmp4, tmp0_, tmp1_, tmp2_, tmp3_;\r
+ float tmp0o, tmp1o, tmp2o, tmp3o, tmp4o, tmp0_o, tmp1_o, tmp2_o, tmp3_o;\r
+\r
+ // Fast 9 Point Inverse Discrete Cosine Transform\r
+ //\r
+ // By Francois-Raymond Boyer\r
+ // mailto:boyerf@iro.umontreal.ca\r
+ // http://www.iro.umontreal.ca/~boyerf\r
+ //\r
+ // The code has been optimized for Intel processors\r
+ // (takes a lot of time to convert float to and from iternal FPU\r
+ // representation)\r
+ //\r
+ // It is a simple "factorization" of the IDCT matrix.\r
+\r
+ // 9 point IDCT on even indices\r
+\r
+ // 5 points on odd indices (not realy an IDCT)\r
+ float i00 = in[0] + in[0];\r
+ float iip12 = i00 + in[12];\r
+\r
+ tmp0 =\r
+ iip12 + in[4] * 1.8793852415718f + in[8] * 1.532088886238f + in[16] * 0.34729635533386f;\r
+ tmp1 = i00 + in[4] - in[8] - in[12] - in[12] - in[16];\r
+ tmp2 =\r
+ iip12 - in[4] * 0.34729635533386f - in[8] * 1.8793852415718f + in[16] * 1.532088886238f;\r
+ tmp3 =\r
+ iip12 - in[4] * 1.532088886238f + in[8] * 0.34729635533386f - in[16] * 1.8793852415718f;\r
+ tmp4 = in[0] - in[4] + in[8] - in[12] + in[16];\r
+\r
+ // 4 points on even indices\r
+ float i66_ = in[6] * 1.732050808f; // Sqrt[3]\r
+\r
+ tmp0_ =\r
+ in[2] * 1.9696155060244f + i66_ + in[10] * 1.2855752193731f + in[14] * 0.68404028665134f;\r
+ tmp1_ = (in[2] - in[10] - in[14]) * 1.732050808f;\r
+ tmp2_ =\r
+ in[2] * 1.2855752193731f - i66_ - in[10] * 0.68404028665134f + in[14] * 1.9696155060244f;\r
+ tmp3_ =\r
+ in[2] * 0.68404028665134f - i66_ + in[10] * 1.9696155060244f - in[14] * 1.2855752193731f;\r
+\r
+ // 9 point IDCT on odd indices\r
+ // 5 points on odd indices (not realy an IDCT)\r
+ float i0 = in[0 + 1] + in[0 + 1];\r
+ float i0p12 = i0 + in[12 + 1];\r
+\r
+ tmp0o =\r
+ i0p12 + in[4 + 1] * 1.8793852415718f + in[8 + 1] * 1.532088886238f + in[16 + 1]\r
+ * 0.34729635533386f;\r
+ tmp1o = i0 + in[4 + 1] - in[8 + 1] - in[12 + 1] - in[12 + 1] - in[16 + 1];\r
+ tmp2o =\r
+ i0p12 - in[4 + 1] * 0.34729635533386f - in[8 + 1] * 1.8793852415718f + in[16 + 1]\r
+ * 1.532088886238f;\r
+ tmp3o =\r
+ i0p12 - in[4 + 1] * 1.532088886238f + in[8 + 1] * 0.34729635533386f - in[16 + 1]\r
+ * 1.8793852415718f;\r
+ tmp4o = (in[0 + 1] - in[4 + 1] + in[8 + 1] - in[12 + 1] + in[16 + 1]) * 0.707106781f; // Twiddled\r
+\r
+ // 4 points on even indices\r
+ float i6_ = in[6 + 1] * 1.732050808f; // Sqrt[3]\r
+\r
+ tmp0_o =\r
+ in[2 + 1] * 1.9696155060244f + i6_ + in[10 + 1] * 1.2855752193731f + in[14 + 1]\r
+ * 0.68404028665134f;\r
+ tmp1_o = (in[2 + 1] - in[10 + 1] - in[14 + 1]) * 1.732050808f;\r
+ tmp2_o =\r
+ in[2 + 1] * 1.2855752193731f - i6_ - in[10 + 1] * 0.68404028665134f + in[14 + 1]\r
+ * 1.9696155060244f;\r
+ tmp3_o =\r
+ in[2 + 1] * 0.68404028665134f - i6_ + in[10 + 1] * 1.9696155060244f - in[14 + 1]\r
+ * 1.2855752193731f;\r
+\r
+ // Twiddle factors on odd indices\r
+ // and\r
+ // Butterflies on 9 point IDCT's\r
+ // and\r
+ // twiddle factors for 36 point IDCT\r
+\r
+ float e, o;\r
+ e = tmp0 + tmp0_;\r
+ o = (tmp0o + tmp0_o) * 0.501909918f;\r
+ tmpf_0 = e + o;\r
+ tmpf_17 = e - o;\r
+ e = tmp1 + tmp1_;\r
+ o = (tmp1o + tmp1_o) * 0.517638090f;\r
+ tmpf_1 = e + o;\r
+ tmpf_16 = e - o;\r
+ e = tmp2 + tmp2_;\r
+ o = (tmp2o + tmp2_o) * 0.551688959f;\r
+ tmpf_2 = e + o;\r
+ tmpf_15 = e - o;\r
+ e = tmp3 + tmp3_;\r
+ o = (tmp3o + tmp3_o) * 0.610387294f;\r
+ tmpf_3 = e + o;\r
+ tmpf_14 = e - o;\r
+ tmpf_4 = tmp4 + tmp4o;\r
+ tmpf_13 = tmp4 - tmp4o;\r
+ e = tmp3 - tmp3_;\r
+ o = (tmp3o - tmp3_o) * 0.871723397f;\r
+ tmpf_5 = e + o;\r
+ tmpf_12 = e - o;\r
+ e = tmp2 - tmp2_;\r
+ o = (tmp2o - tmp2_o) * 1.183100792f;\r
+ tmpf_6 = e + o;\r
+ tmpf_11 = e - o;\r
+ e = tmp1 - tmp1_;\r
+ o = (tmp1o - tmp1_o) * 1.931851653f;\r
+ tmpf_7 = e + o;\r
+ tmpf_10 = e - o;\r
+ e = tmp0 - tmp0_;\r
+ o = (tmp0o - tmp0_o) * 5.736856623f;\r
+ tmpf_8 = e + o;\r
+ tmpf_9 = e - o;\r
+\r
+ // end 36 point IDCT */\r
+ // shift to modified IDCT\r
+ win_bt = win[block_type];\r
+\r
+ out[0] = -tmpf_9 * win_bt[0];\r
+ out[1] = -tmpf_10 * win_bt[1];\r
+ out[2] = -tmpf_11 * win_bt[2];\r
+ out[3] = -tmpf_12 * win_bt[3];\r
+ out[4] = -tmpf_13 * win_bt[4];\r
+ out[5] = -tmpf_14 * win_bt[5];\r
+ out[6] = -tmpf_15 * win_bt[6];\r
+ out[7] = -tmpf_16 * win_bt[7];\r
+ out[8] = -tmpf_17 * win_bt[8];\r
+ out[9] = tmpf_17 * win_bt[9];\r
+ out[10] = tmpf_16 * win_bt[10];\r
+ out[11] = tmpf_15 * win_bt[11];\r
+ out[12] = tmpf_14 * win_bt[12];\r
+ out[13] = tmpf_13 * win_bt[13];\r
+ out[14] = tmpf_12 * win_bt[14];\r
+ out[15] = tmpf_11 * win_bt[15];\r
+ out[16] = tmpf_10 * win_bt[16];\r
+ out[17] = tmpf_9 * win_bt[17];\r
+ out[18] = tmpf_8 * win_bt[18];\r
+ out[19] = tmpf_7 * win_bt[19];\r
+ out[20] = tmpf_6 * win_bt[20];\r
+ out[21] = tmpf_5 * win_bt[21];\r
+ out[22] = tmpf_4 * win_bt[22];\r
+ out[23] = tmpf_3 * win_bt[23];\r
+ out[24] = tmpf_2 * win_bt[24];\r
+ out[25] = tmpf_1 * win_bt[25];\r
+ out[26] = tmpf_0 * win_bt[26];\r
+ out[27] = tmpf_0 * win_bt[27];\r
+ out[28] = tmpf_1 * win_bt[28];\r
+ out[29] = tmpf_2 * win_bt[29];\r
+ out[30] = tmpf_3 * win_bt[30];\r
+ out[31] = tmpf_4 * win_bt[31];\r
+ out[32] = tmpf_5 * win_bt[32];\r
+ out[33] = tmpf_6 * win_bt[33];\r
+ out[34] = tmpf_7 * win_bt[34];\r
+ out[35] = tmpf_8 * win_bt[35];\r
+ }\r
+ }\r
+\r
+ private int counter = 0;\r
+ private static final int SSLIMIT = 18;\r
+ private static final int SBLIMIT = 32;\r
+\r
+ // Size of the table of whole numbers raised to 4/3 power.\r
+ // This may be adjusted for performance without any problems.\r
+ // public static final int POW_TABLE_LIMIT=512;\r
+\r
+ /************************************************************/\r
+ /* L3TABLE */\r
+ /************************************************************/\r
+\r
+ static class SBI {\r
+ public int[] l;\r
+ public int[] s;\r
+\r
+ public SBI() {\r
+ l = new int[23];\r
+ s = new int[14];\r
+ }\r
+\r
+ public SBI(int[] thel, int[] thes) {\r
+ l = thel;\r
+ s = thes;\r
+ }\r
+ }\r
+\r
+ static class gr_info_s {\r
+ public int part2_3_length = 0;\r
+ public int big_values = 0;\r
+ public int global_gain = 0;\r
+ public int scalefac_compress = 0;\r
+ public int window_switching_flag = 0;\r
+ public int block_type = 0;\r
+ public int mixed_block_flag = 0;\r
+ public int[] table_select;\r
+ public int[] subblock_gain;\r
+ public int region0_count = 0;\r
+ public int region1_count = 0;\r
+ public int preflag = 0;\r
+ public int scalefac_scale = 0;\r
+ public int count1table_select = 0;\r
+\r
+ /**\r
+ * Dummy Constructor\r
+ */\r
+ public gr_info_s() {\r
+ table_select = new int[3];\r
+ subblock_gain = new int[3];\r
+ }\r
+ }\r
+\r
+ static class temporaire {\r
+ public int[] scfsi;\r
+ public gr_info_s[] gr;\r
+\r
+ /**\r
+ * Dummy Constructor\r
+ */\r
+ public temporaire() {\r
+ scfsi = new int[4];\r
+ gr = new gr_info_s[2];\r
+ gr[0] = new gr_info_s();\r
+ gr[1] = new gr_info_s();\r
+ }\r
+ }\r
+\r
+ static class III_side_info_t {\r
+\r
+ public int main_data_begin = 0;\r
+ public int private_bits = 0;\r
+ public temporaire[] ch;\r
+\r
+ /**\r
+ * Dummy Constructor\r
+ */\r
+ public III_side_info_t() {\r
+ ch = new temporaire[2];\r
+ ch[0] = new temporaire();\r
+ ch[1] = new temporaire();\r
+ }\r
+ }\r
+\r
+ static class temporaire2 {\r
+ public int[] l; /* [cb] */\r
+ public int[][] s; /* [window][cb] */\r
+\r
+ /**\r
+ * Dummy Constructor\r
+ */\r
+ public temporaire2() {\r
+ l = new int[23];\r
+ s = new int[3][13];\r
+ }\r
+ }\r
+\r
+ // class III_scalefac_t\r
+ // {\r
+ // public temporaire2[] tab;\r
+ // /**\r
+ // * Dummy Constructor\r
+ // */\r
+ // public III_scalefac_t()\r
+ // {\r
+ // tab = new temporaire2[2];\r
+ // }\r
+ // }\r
+\r
+ private static final int slen[][] = { { 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },\r
+ { 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 } };\r
+\r
+ public static final int pretab[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3,\r
+ 2, 0 };\r
+\r
+ private SBI[] sfBandIndex; // Init in the constructor.\r
+\r
+ public static final float two_to_negative_half_pow[] = { 1.0000000000E+00f, 7.0710678119E-01f,\r
+ 5.0000000000E-01f, 3.5355339059E-01f, 2.5000000000E-01f, 1.7677669530E-01f,\r
+ 1.2500000000E-01f, 8.8388347648E-02f, 6.2500000000E-02f, 4.4194173824E-02f,\r
+ 3.1250000000E-02f, 2.2097086912E-02f, 1.5625000000E-02f, 1.1048543456E-02f,\r
+ 7.8125000000E-03f, 5.5242717280E-03f, 3.9062500000E-03f, 2.7621358640E-03f,\r
+ 1.9531250000E-03f, 1.3810679320E-03f, 9.7656250000E-04f, 6.9053396600E-04f,\r
+ 4.8828125000E-04f, 3.4526698300E-04f, 2.4414062500E-04f, 1.7263349150E-04f,\r
+ 1.2207031250E-04f, 8.6316745750E-05f, 6.1035156250E-05f, 4.3158372875E-05f,\r
+ 3.0517578125E-05f, 2.1579186438E-05f, 1.5258789062E-05f, 1.0789593219E-05f,\r
+ 7.6293945312E-06f, 5.3947966094E-06f, 3.8146972656E-06f, 2.6973983047E-06f,\r
+ 1.9073486328E-06f, 1.3486991523E-06f, 9.5367431641E-07f, 6.7434957617E-07f,\r
+ 4.7683715820E-07f, 3.3717478809E-07f, 2.3841857910E-07f, 1.6858739404E-07f,\r
+ 1.1920928955E-07f, 8.4293697022E-08f, 5.9604644775E-08f, 4.2146848511E-08f,\r
+ 2.9802322388E-08f, 2.1073424255E-08f, 1.4901161194E-08f, 1.0536712128E-08f,\r
+ 7.4505805969E-09f, 5.2683560639E-09f, 3.7252902985E-09f, 2.6341780319E-09f,\r
+ 1.8626451492E-09f, 1.3170890160E-09f, 9.3132257462E-10f, 6.5854450798E-10f,\r
+ 4.6566128731E-10f, 3.2927225399E-10f };\r
+\r
+ public static final float t_43[] = create_t_43();\r
+\r
+ static private float[] create_t_43() {\r
+ float[] t43 = new float[8192];\r
+ final double d43 = (4.0 / 3.0);\r
+\r
+ for (int i = 0; i < 8192; i++) {\r
+ t43[i] = (float) Math.pow(i, d43);\r
+ }\r
+ return t43;\r
+ }\r
+\r
+ public static final float io[][] = {\r
+ { 1.0000000000E+00f, 8.4089641526E-01f, 7.0710678119E-01f, 5.9460355751E-01f,\r
+ 5.0000000001E-01f, 4.2044820763E-01f, 3.5355339060E-01f, 2.9730177876E-01f,\r
+ 2.5000000001E-01f, 2.1022410382E-01f, 1.7677669530E-01f, 1.4865088938E-01f,\r
+ 1.2500000000E-01f, 1.0511205191E-01f, 8.8388347652E-02f, 7.4325444691E-02f,\r
+ 6.2500000003E-02f, 5.2556025956E-02f, 4.4194173826E-02f, 3.7162722346E-02f,\r
+ 3.1250000002E-02f, 2.6278012978E-02f, 2.2097086913E-02f, 1.8581361173E-02f,\r
+ 1.5625000001E-02f, 1.3139006489E-02f, 1.1048543457E-02f, 9.2906805866E-03f,\r
+ 7.8125000006E-03f, 6.5695032447E-03f, 5.5242717285E-03f, 4.6453402934E-03f },\r
+ { 1.0000000000E+00f, 7.0710678119E-01f, 5.0000000000E-01f, 3.5355339060E-01f,\r
+ 2.5000000000E-01f, 1.7677669530E-01f, 1.2500000000E-01f, 8.8388347650E-02f,\r
+ 6.2500000001E-02f, 4.4194173825E-02f, 3.1250000001E-02f, 2.2097086913E-02f,\r
+ 1.5625000000E-02f, 1.1048543456E-02f, 7.8125000002E-03f, 5.5242717282E-03f,\r
+ 3.9062500001E-03f, 2.7621358641E-03f, 1.9531250001E-03f, 1.3810679321E-03f,\r
+ 9.7656250004E-04f, 6.9053396603E-04f, 4.8828125002E-04f, 3.4526698302E-04f,\r
+ 2.4414062501E-04f, 1.7263349151E-04f, 1.2207031251E-04f, 8.6316745755E-05f,\r
+ 6.1035156254E-05f, 4.3158372878E-05f, 3.0517578127E-05f, 2.1579186439E-05f } };\r
+\r
+ public static final float TAN12[] = { 0.0f, 0.26794919f, 0.57735027f, 1.0f, 1.73205081f,\r
+ 3.73205081f, 9.9999999e10f, -3.73205081f, -1.73205081f, -1.0f, -0.57735027f, -0.26794919f,\r
+ 0.0f, 0.26794919f, 0.57735027f, 1.0f };\r
+\r
+ // REVIEW: in java, the array lookup may well be slower than\r
+ // the actual calculation\r
+ // 576 / 18\r
+ /*\r
+ * private static final int ss_div[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+ * 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,\r
+ * 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,\r
+ * 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,\r
+ * 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6,\r
+ * 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,\r
+ * 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,\r
+ * 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10,\r
+ * 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,\r
+ * 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12,\r
+ * 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13,\r
+ * 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14,\r
+ * 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,\r
+ * 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,\r
+ * 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,\r
+ * 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,\r
+ * 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,\r
+ * 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,\r
+ * 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,\r
+ * 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,\r
+ * 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,\r
+ * 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25,\r
+ * 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26,\r
+ * 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27,\r
+ * 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28,\r
+ * 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29,\r
+ * 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30,\r
+ * 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31,\r
+ * 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31 };\r
+ * \r
+ * // 576 % 18 private static final int ss_mod[] = { 0, 1, 2, 3, 4, 5, 6, 7,\r
+ * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,\r
+ * 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,\r
+ * 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\r
+ * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3,\r
+ * 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7,\r
+ * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,\r
+ * 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,\r
+ * 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\r
+ * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3,\r
+ * 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7,\r
+ * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,\r
+ * 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,\r
+ * 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\r
+ * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3,\r
+ * 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7,\r
+ * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,\r
+ * 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,\r
+ * 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\r
+ * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3,\r
+ * 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7,\r
+ * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,\r
+ * 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,\r
+ * 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\r
+ * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3,\r
+ * 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7,\r
+ * 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,\r
+ * 12, 13, 14, 15, 16, 17 };\r
+ */\r
+ private static/* final */int reorder_table[][]/* = loadReorderTable() */; // SZD:\r
+ // will\r
+ // be\r
+ // generated\r
+ // on\r
+ // demand\r
+\r
+ /**\r
+ * Loads the data for the reorder\r
+ */\r
+ /*\r
+ * private static int[][] loadReorderTable() // SZD: table will be generated {\r
+ * try { Class elemType = int[][].class.getComponentType(); Object o =\r
+ * JavaLayerUtils.deserializeArrayResource("l3reorder.ser", elemType, 6);\r
+ * return (int[][])o; } catch (IOException ex) { throw new\r
+ * ExceptionInInitializerError(ex); } }\r
+ */\r
+\r
+ static int[] reorder(int scalefac_band[]) { // SZD: converted from LAME\r
+ int j = 0;\r
+ int ix[] = new int[576];\r
+ for (int sfb = 0; sfb < 13; sfb++) {\r
+ int start = scalefac_band[sfb];\r
+ int end = scalefac_band[sfb + 1];\r
+ for (int window = 0; window < 3; window++)\r
+ for (int i = start; i < end; i++)\r
+ ix[3 * i + window] = j++;\r
+ }\r
+ return ix;\r
+ }\r
+\r
+ /*\r
+ * static final int reorder_table_data[][]; = { { 0, 4, 8, 1, 5, 9, 2, 6, 10,\r
+ * 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19, 23, 24, 28, 32, 25,\r
+ * 29, 33, 26, 30, 34, 27, 31, 35, 36, 42, 48, 37, 43, 49, 38, 44, 50, 39, 45,\r
+ * 51, 40, 46, 52, 41, 47, 53, 54, 60, 66, 55, 61, 67, 56, 62, 68, 57, 63, 69,\r
+ * 58, 64, 70, 59, 65, 71, 72, 80, 88, 73, 81, 89, 74, 82, 90, 75, 83, 91, 76,\r
+ * 84, 92, 77, 85, 93, 78, 86, 94, 79, 87, 95, 96,106,116, 97,107,117,\r
+ * 98,108,118, 99,109,119,100,110,120,101,\r
+ * 111,121,102,112,122,103,113,123,104,114,124,105,115,125,126,140,\r
+ * 154,127,141,155,128,142,156,129,143,157,130,144,158,131,145,159,\r
+ * 132,146,160,133,147,161,134,148,162,135,149,163,136,150,164,137,\r
+ * 151,165,138,152,166,139,153,167,168,186,204,169,187,205,170,188,\r
+ * 206,171,189,207,172,190,208,173,191,209,174,192,210,175,193,211,\r
+ * 176,194,212,177,195,213,178,196,214,179,197,215,180,198,216,181,\r
+ * 199,217,182,200,218,183,201,219,184,202,220,185,203,221,222,248,\r
+ * 274,223,249,275,224,250,276,225,251,277,226,252,278,227,253,279,\r
+ * 228,254,280,229,255,281,230,256,282,231,257,283,232,258,284,233,\r
+ * 259,285,234,260,286,235,261,287,236,262,288,237,263,289,238,264,\r
+ * 290,239,265,291,240,266,292,241,267,293,242,268,294,243,269,295,\r
+ * 244,270,296,245,271,297,246,272,298,247,273,299,300,332,364,301,\r
+ * 333,365,302,334,366,303,335,367,304,336,368,305,337,369,306,338,\r
+ * 370,307,339,371,308,340,372,309,341,373,310,342,374,311,343,375,\r
+ * 312,344,376,313,345,377,314,346,378,315,347,379,316,348,380,317,\r
+ * 349,381,318,350,382,319,351,383,320,352,384,321,353,385,322,354,\r
+ * 386,323,355,387,324,356,388,325,357,389,326,358,390,327,359,391,\r
+ * 328,360,392,329,361,393,330,362,394,331,363,395,396,438,480,397,\r
+ * 439,481,398,440,482,399,441,483,400,442,484,401,443,485,402,444,\r
+ * 486,403,445,487,404,446,488,405,447,489,406,448,490,407,449,491,\r
+ * 408,450,492,409,451,493,410,452,494,411,453,495,412,454,496,413,\r
+ * 455,497,414,456,498,415,457,499,416,458,500,417,459,501,418,460,\r
+ * 502,419,461,503,420,462,504,421,463,505,422,464,506,423,465,507,\r
+ * 424,466,508,425,467,509,426,468,510,427,469,511,428,470,512,429,\r
+ * 471,513,430,472,514,431,473,515,432,474,516,433,475,517,434,476,\r
+ * 518,435,477,519,436,478,520,437,479,521,522,540,558,523,541,559,\r
+ * 524,542,560,525,543,561,526,544,562,527,545,563,528,546,564,529,\r
+ * 547,565,530,548,566,531,549,567,532,550,568,533,551,569,534,552,\r
+ * 570,535,553,571,536,554,572,537,555,573,538,556,574,539,557,575}, { 0, 4,\r
+ * 8, 1, 5, 9, 2, 6, 10, 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19,\r
+ * 23, 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35, 36, 42, 48, 37, 43, 49,\r
+ * 38, 44, 50, 39, 45, 51, 40, 46, 52, 41, 47, 53, 54, 62, 70, 55, 63, 71, 56,\r
+ * 64, 72, 57, 65, 73, 58, 66, 74, 59, 67, 75, 60, 68, 76, 61, 69, 77, 78, 88,\r
+ * 98, 79, 89, 99, 80, 90,100, 81, 91,101, 82, 92,102, 83, 93,103, 84, 94,104,\r
+ * 85, 95,105, 86, 96,106, 87, 97,107,108,120,132,109,\r
+ * 121,133,110,122,134,111,123,135,112,124,136,113,125,137,114,126,\r
+ * 138,115,127,139,116,128,140,117,129,141,118,130,142,119,131,143,\r
+ * 144,158,172,145,159,173,146,160,174,147,161,175,148,162,176,149,\r
+ * 163,177,150,164,178,151,165,179,152,166,180,153,167,181,154,168,\r
+ * 182,155,169,183,156,170,184,157,171,185,186,204,222,187,205,223,\r
+ * 188,206,224,189,207,225,190,208,226,191,209,227,192,210,228,193,\r
+ * 211,229,194,212,230,195,213,231,196,214,232,197,215,233,198,216,\r
+ * 234,199,217,235,200,218,236,201,219,237,202,220,238,203,221,239,\r
+ * 240,264,288,241,265,289,242,266,290,243,267,291,244,268,292,245,\r
+ * 269,293,246,270,294,247,271,295,248,272,296,249,273,297,250,274,\r
+ * 298,251,275,299,252,276,300,253,277,301,254,278,302,255,279,303,\r
+ * 256,280,304,257,281,305,258,282,306,259,283,307,260,284,308,261,\r
+ * 285,309,262,286,310,263,287,311,312,344,376,313,345,377,314,346,\r
+ * 378,315,347,379,316,348,380,317,349,381,318,350,382,319,351,383,\r
+ * 320,352,384,321,353,385,322,354,386,323,355,387,324,356,388,325,\r
+ * 357,389,326,358,390,327,359,391,328,360,392,329,361,393,330,362,\r
+ * 394,331,363,395,332,364,396,333,365,397,334,366,398,335,367,399,\r
+ * 336,368,400,337,369,401,338,370,402,339,371,403,340,372,404,341,\r
+ * 373,405,342,374,406,343,375,407,408,452,496,409,453,497,410,454,\r
+ * 498,411,455,499,412,456,500,413,457,501,414,458,502,415,459,503,\r
+ * 416,460,504,417,461,505,418,462,506,419,463,507,420,464,508,421,\r
+ * 465,509,422,466,510,423,467,511,424,468,512,425,469,513,426,470,\r
+ * 514,427,471,515,428,472,516,429,473,517,430,474,518,431,475,519,\r
+ * 432,476,520,433,477,521,434,478,522,435,479,523,436,480,524,437,\r
+ * 481,525,438,482,526,439,483,527,440,484,528,441,485,529,442,486,\r
+ * 530,443,487,531,444,488,532,445,489,533,446,490,534,447,491,535,\r
+ * 448,492,536,449,493,537,450,494,538,451,495,539,540,552,564,541,\r
+ * 553,565,542,554,566,543,555,567,544,556,568,545,557,569,546,558,\r
+ * 570,547,559,571,548,560,572,549,561,573,550,562,574,551,563,575}, { 0, 4,\r
+ * 8, 1, 5, 9, 2, 6, 10, 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19,\r
+ * 23, 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35, 36, 42, 48, 37, 43, 49,\r
+ * 38, 44, 50, 39, 45, 51, 40, 46, 52, 41, 47, 53, 54, 62, 70, 55, 63, 71, 56,\r
+ * 64, 72, 57, 65, 73, 58, 66, 74, 59, 67, 75, 60, 68, 76, 61, 69, 77, 78, 88,\r
+ * 98, 79, 89, 99, 80, 90,100, 81, 91,101, 82, 92,102, 83, 93,103, 84, 94,104,\r
+ * 85, 95,105, 86, 96,106, 87, 97,107,108,120,132,109,\r
+ * 121,133,110,122,134,111,123,135,112,124,136,113,125,137,114,126,\r
+ * 138,115,127,139,116,128,140,117,129,141,118,130,142,119,131,143,\r
+ * 144,158,172,145,159,173,146,160,174,147,161,175,148,162,176,149,\r
+ * 163,177,150,164,178,151,165,179,152,166,180,153,167,181,154,168,\r
+ * 182,155,169,183,156,170,184,157,171,185,186,204,222,187,205,223,\r
+ * 188,206,224,189,207,225,190,208,226,191,209,227,192,210,228,193,\r
+ * 211,229,194,212,230,195,213,231,196,214,232,197,215,233,198,216,\r
+ * 234,199,217,235,200,218,236,201,219,237,202,220,238,203,221,239,\r
+ * 240,264,288,241,265,289,242,266,290,243,267,291,244,268,292,245,\r
+ * 269,293,246,270,294,247,271,295,248,272,296,249,273,297,250,274,\r
+ * 298,251,275,299,252,276,300,253,277,301,254,278,302,255,279,303,\r
+ * 256,280,304,257,281,305,258,282,306,259,283,307,260,284,308,261,\r
+ * 285,309,262,286,310,263,287,311,312,342,372,313,343,373,314,344,\r
+ * 374,315,345,375,316,346,376,317,347,377,318,348,378,319,349,379,\r
+ * 320,350,380,321,351,381,322,352,382,323,353,383,324,354,384,325,\r
+ * 355,385,326,356,386,327,357,387,328,358,388,329,359,389,330,360,\r
+ * 390,331,361,391,332,362,392,333,363,393,334,364,394,335,365,395,\r
+ * 336,366,396,337,367,397,338,368,398,339,369,399,340,370,400,341,\r
+ * 371,401,402,442,482,403,443,483,404,444,484,405,445,485,406,446,\r
+ * 486,407,447,487,408,448,488,409,449,489,410,450,490,411,451,491,\r
+ * 412,452,492,413,453,493,414,454,494,415,455,495,416,456,496,417,\r
+ * 457,497,418,458,498,419,459,499,420,460,500,421,461,501,422,462,\r
+ * 502,423,463,503,424,464,504,425,465,505,426,466,506,427,467,507,\r
+ * 428,468,508,429,469,509,430,470,510,431,471,511,432,472,512,433,\r
+ * 473,513,434,474,514,435,475,515,436,476,516,437,477,517,438,478,\r
+ * 518,439,479,519,440,480,520,441,481,521,522,540,558,523,541,559,\r
+ * 524,542,560,525,543,561,526,544,562,527,545,563,528,546,564,529,\r
+ * 547,565,530,548,566,531,549,567,532,550,568,533,551,569,534,552,\r
+ * 570,535,553,571,536,554,572,537,555,573,538,556,574,539,557,575}, { 0, 4,\r
+ * 8, 1, 5, 9, 2, 6, 10, 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19,\r
+ * 23, 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35, 36, 40, 44, 37, 41, 45,\r
+ * 38, 42, 46, 39, 43, 47, 48, 54, 60, 49, 55, 61, 50, 56, 62, 51, 57, 63, 52,\r
+ * 58, 64, 53, 59, 65, 66, 74, 82, 67, 75, 83, 68, 76, 84, 69, 77, 85, 70, 78,\r
+ * 86, 71, 79, 87, 72, 80, 88, 73, 81, 89, 90,100,110, 91,101,111, 92,102,112,\r
+ * 93,103,113, 94,104,114, 95,105,115, 96,106,116, 97, 107,117, 98,108,118,\r
+ * 99,109,119,120,132,144,121,133,145,122,134,\r
+ * 146,123,135,147,124,136,148,125,137,149,126,138,150,127,139,151,\r
+ * 128,140,152,129,141,153,130,142,154,131,143,155,156,170,184,157,\r
+ * 171,185,158,172,186,159,173,187,160,174,188,161,175,189,162,176,\r
+ * 190,163,177,191,164,178,192,165,179,193,166,180,194,167,181,195,\r
+ * 168,182,196,169,183,197,198,216,234,199,217,235,200,218,236,201,\r
+ * 219,237,202,220,238,203,221,239,204,222,240,205,223,241,206,224,\r
+ * 242,207,225,243,208,226,244,209,227,245,210,228,246,211,229,247,\r
+ * 212,230,248,213,231,249,214,232,250,215,233,251,252,274,296,253,\r
+ * 275,297,254,276,298,255,277,299,256,278,300,257,279,301,258,280,\r
+ * 302,259,281,303,260,282,304,261,283,305,262,284,306,263,285,307,\r
+ * 264,286,308,265,287,309,266,288,310,267,289,311,268,290,312,269,\r
+ * 291,313,270,292,314,271,293,315,272,294,316,273,295,317,318,348,\r
+ * 378,319,349,379,320,350,380,321,351,381,322,352,382,323,353,383,\r
+ * 324,354,384,325,355,385,326,356,386,327,357,387,328,358,388,329,\r
+ * 359,389,330,360,390,331,361,391,332,362,392,333,363,393,334,364,\r
+ * 394,335,365,395,336,366,396,337,367,397,338,368,398,339,369,399,\r
+ * 340,370,400,341,371,401,342,372,402,343,373,403,344,374,404,345,\r
+ * 375,405,346,376,406,347,377,407,408,464,520,409,465,521,410,466,\r
+ * 522,411,467,523,412,468,524,413,469,525,414,470,526,415,471,527,\r
+ * 416,472,528,417,473,529,418,474,530,419,475,531,420,476,532,421,\r
+ * 477,533,422,478,534,423,479,535,424,480,536,425,481,537,426,482,\r
+ * 538,427,483,539,428,484,540,429,485,541,430,486,542,431,487,543,\r
+ * 432,488,544,433,489,545,434,490,546,435,491,547,436,492,548,437,\r
+ * 493,549,438,494,550,439,495,551,440,496,552,441,497,553,442,498,\r
+ * 554,443,499,555,444,500,556,445,501,557,446,502,558,447,503,559,\r
+ * 448,504,560,449,505,561,450,506,562,451,507,563,452,508,564,453,\r
+ * 509,565,454,510,566,455,511,567,456,512,568,457,513,569,458,514,\r
+ * 570,459,515,571,460,516,572,461,517,573,462,518,574,463,519,575}, { 0, 4,\r
+ * 8, 1, 5, 9, 2, 6, 10, 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19,\r
+ * 23, 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35, 36, 40, 44, 37, 41, 45,\r
+ * 38, 42, 46, 39, 43, 47, 48, 54, 60, 49, 55, 61, 50, 56, 62, 51, 57, 63, 52,\r
+ * 58, 64, 53, 59, 65, 66, 72, 78, 67, 73, 79, 68, 74, 80, 69, 75, 81, 70, 76,\r
+ * 82, 71, 77, 83, 84, 94,104, 85, 95,105, 86, 96,106, 87, 97,107, 88, 98,108,\r
+ * 89, 99,109, 90,100,110, 91,101,111, 92,102,112, 93,\r
+ * 103,113,114,126,138,115,127,139,116,128,140,117,129,141,118,130,\r
+ * 142,119,131,143,120,132,144,121,133,145,122,134,146,123,135,147,\r
+ * 124,136,148,125,137,149,150,164,178,151,165,179,152,166,180,153,\r
+ * 167,181,154,168,182,155,169,183,156,170,184,157,171,185,158,172,\r
+ * 186,159,173,187,160,174,188,161,175,189,162,176,190,163,177,191,\r
+ * 192,208,224,193,209,225,194,210,226,195,211,227,196,212,228,197,\r
+ * 213,229,198,214,230,199,215,231,200,216,232,201,217,233,202,218,\r
+ * 234,203,219,235,204,220,236,205,221,237,206,222,238,207,223,239,\r
+ * 240,260,280,241,261,281,242,262,282,243,263,283,244,264,284,245,\r
+ * 265,285,246,266,286,247,267,287,248,268,288,249,269,289,250,270,\r
+ * 290,251,271,291,252,272,292,253,273,293,254,274,294,255,275,295,\r
+ * 256,276,296,257,277,297,258,278,298,259,279,299,300,326,352,301,\r
+ * 327,353,302,328,354,303,329,355,304,330,356,305,331,357,306,332,\r
+ * 358,307,333,359,308,334,360,309,335,361,310,336,362,311,337,363,\r
+ * 312,338,364,313,339,365,314,340,366,315,341,367,316,342,368,317,\r
+ * 343,369,318,344,370,319,345,371,320,346,372,321,347,373,322,348,\r
+ * 374,323,349,375,324,350,376,325,351,377,378,444,510,379,445,511,\r
+ * 380,446,512,381,447,513,382,448,514,383,449,515,384,450,516,385,\r
+ * 451,517,386,452,518,387,453,519,388,454,520,389,455,521,390,456,\r
+ * 522,391,457,523,392,458,524,393,459,525,394,460,526,395,461,527,\r
+ * 396,462,528,397,463,529,398,464,530,399,465,531,400,466,532,401,\r
+ * 467,533,402,468,534,403,469,535,404,470,536,405,471,537,406,472,\r
+ * 538,407,473,539,408,474,540,409,475,541,410,476,542,411,477,543,\r
+ * 412,478,544,413,479,545,414,480,546,415,481,547,416,482,548,417,\r
+ * 483,549,418,484,550,419,485,551,420,486,552,421,487,553,422,488,\r
+ * 554,423,489,555,424,490,556,425,491,557,426,492,558,427,493,559,\r
+ * 428,494,560,429,495,561,430,496,562,431,497,563,432,498,564,433,\r
+ * 499,565,434,500,566,435,501,567,436,502,568,437,503,569,438,504,\r
+ * 570,439,505,571,440,506,572,441,507,573,442,508,574,443,509,575}, { 0, 4,\r
+ * 8, 1, 5, 9, 2, 6, 10, 3, 7, 11, 12, 16, 20, 13, 17, 21, 14, 18, 22, 15, 19,\r
+ * 23, 24, 28, 32, 25, 29, 33, 26, 30, 34, 27, 31, 35, 36, 40, 44, 37, 41, 45,\r
+ * 38, 42, 46, 39, 43, 47, 48, 54, 60, 49, 55, 61, 50, 56, 62, 51, 57, 63, 52,\r
+ * 58, 64, 53, 59, 65, 66, 74, 82, 67, 75, 83, 68, 76, 84, 69, 77, 85, 70, 78,\r
+ * 86, 71, 79, 87, 72, 80, 88, 73, 81, 89, 90,102,114, 91,103,115, 92,104,116,\r
+ * 93,105,117, 94,106,118, 95,107,119, 96,108,120, 97, 109,121, 98,110,122,\r
+ * 99,111,123,100,112,124,101,113,125,126,142,\r
+ * 158,127,143,159,128,144,160,129,145,161,130,146,162,131,147,163,\r
+ * 132,148,164,133,149,165,134,150,166,135,151,167,136,152,168,137,\r
+ * 153,169,138,154,170,139,155,171,140,156,172,141,157,173,174,194,\r
+ * 214,175,195,215,176,196,216,177,197,217,178,198,218,179,199,219,\r
+ * 180,200,220,181,201,221,182,202,222,183,203,223,184,204,224,185,\r
+ * 205,225,186,206,226,187,207,227,188,208,228,189,209,229,190,210,\r
+ * 230,191,211,231,192,212,232,193,213,233,234,260,286,235,261,287,\r
+ * 236,262,288,237,263,289,238,264,290,239,265,291,240,266,292,241,\r
+ * 267,293,242,268,294,243,269,295,244,270,296,245,271,297,246,272,\r
+ * 298,247,273,299,248,274,300,249,275,301,250,276,302,251,277,303,\r
+ * 252,278,304,253,279,305,254,280,306,255,281,307,256,282,308,257,\r
+ * 283,309,258,284,310,259,285,311,312,346,380,313,347,381,314,348,\r
+ * 382,315,349,383,316,350,384,317,351,385,318,352,386,319,353,387,\r
+ * 320,354,388,321,355,389,322,356,390,323,357,391,324,358,392,325,\r
+ * 359,393,326,360,394,327,361,395,328,362,396,329,363,397,330,364,\r
+ * 398,331,365,399,332,366,400,333,367,401,334,368,402,335,369,403,\r
+ * 336,370,404,337,371,405,338,372,406,339,373,407,340,374,408,341,\r
+ * 375,409,342,376,410,343,377,411,344,378,412,345,379,413,414,456,\r
+ * 498,415,457,499,416,458,500,417,459,501,418,460,502,419,461,503,\r
+ * 420,462,504,421,463,505,422,464,506,423,465,507,424,466,508,425,\r
+ * 467,509,426,468,510,427,469,511,428,470,512,429,471,513,430,472,\r
+ * 514,431,473,515,432,474,516,433,475,517,434,476,518,435,477,519,\r
+ * 436,478,520,437,479,521,438,480,522,439,481,523,440,482,524,441,\r
+ * 483,525,442,484,526,443,485,527,444,486,528,445,487,529,446,488,\r
+ * 530,447,489,531,448,490,532,449,491,533,450,492,534,451,493,535,\r
+ * 452,494,536,453,495,537,454,496,538,455,497,539,540,552,564,541,\r
+ * 553,565,542,554,566,543,555,567,544,556,568,545,557,569,546,558,\r
+ * 570,547,559,571,548,560,572,549,561,573,550,562,574,551,563,575} };\r
+ */\r
+\r
+ private static final float cs[] = { 0.857492925712f, 0.881741997318f, 0.949628649103f,\r
+ 0.983314592492f, 0.995517816065f, 0.999160558175f, 0.999899195243f, 0.999993155067f };\r
+\r
+ private static final float ca[] = { -0.5144957554270f, -0.4717319685650f, -0.3133774542040f,\r
+ -0.1819131996110f, -0.0945741925262f, -0.0409655828852f, -0.0141985685725f,\r
+ -0.00369997467375f };\r
+\r
+ /************************************************************/\r
+ /* END OF L3TABLE */\r
+ /************************************************************/\r
+\r
+ /************************************************************/\r
+ /* L3TYPE */\r
+ /************************************************************/\r
+\r
+ /***************************************************************/\r
+ /* END OF L3TYPE */\r
+ /***************************************************************/\r
+\r
+ /***************************************************************/\r
+ /* INV_MDCT */\r
+ /***************************************************************/\r
+ public static final float win[][] = {\r
+ { -1.6141214951E-02f, -5.3603178919E-02f, -1.0070713296E-01f, -1.6280817573E-01f,\r
+ -4.9999999679E-01f, -3.8388735032E-01f, -6.2061144372E-01f, -1.1659756083E+00f,\r
+ -3.8720752656E+00f, -4.2256286556E+00f, -1.5195289984E+00f, -9.7416483388E-01f,\r
+ -7.3744074053E-01f, -1.2071067773E+00f, -5.1636156596E-01f, -4.5426052317E-01f,\r
+ -4.0715656898E-01f, -3.6969460527E-01f, -3.3876269197E-01f, -3.1242222492E-01f,\r
+ -2.8939587111E-01f, -2.6880081906E-01f, -5.0000000266E-01f, -2.3251417468E-01f,\r
+ -2.1596714708E-01f, -2.0004979098E-01f, -1.8449493497E-01f, -1.6905846094E-01f,\r
+ -1.5350360518E-01f, -1.3758624925E-01f, -1.2103922149E-01f, -2.0710679058E-01f,\r
+ -8.4752577594E-02f, -6.4157525656E-02f, -4.1131172614E-02f, -1.4790705759E-02f },\r
+\r
+ { -1.6141214951E-02f, -5.3603178919E-02f, -1.0070713296E-01f, -1.6280817573E-01f,\r
+ -4.9999999679E-01f, -3.8388735032E-01f, -6.2061144372E-01f, -1.1659756083E+00f,\r
+ -3.8720752656E+00f, -4.2256286556E+00f, -1.5195289984E+00f, -9.7416483388E-01f,\r
+ -7.3744074053E-01f, -1.2071067773E+00f, -5.1636156596E-01f, -4.5426052317E-01f,\r
+ -4.0715656898E-01f, -3.6969460527E-01f, -3.3908542600E-01f, -3.1511810350E-01f,\r
+ -2.9642226150E-01f, -2.8184548650E-01f, -5.4119610000E-01f, -2.6213228100E-01f,\r
+ -2.5387916537E-01f, -2.3296291359E-01f, -1.9852728987E-01f, -1.5233534808E-01f,\r
+ -9.6496400054E-02f, -3.3423828516E-02f, 0.0000000000E+00f, 0.0000000000E+00f,\r
+ 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f },\r
+\r
+ { -4.8300800645E-02f, -1.5715656932E-01f, -2.8325045177E-01f, -4.2953747763E-01f,\r
+ -1.2071067795E+00f, -8.2426483178E-01f, -1.1451749106E+00f, -1.7695290101E+00f,\r
+ -4.5470225061E+00f, -3.4890531002E+00f, -7.3296292804E-01f, -1.5076514758E-01f,\r
+ 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f,\r
+ 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f,\r
+ 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f,\r
+ 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f,\r
+ 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f,\r
+ 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f },\r
+\r
+ { 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f, 0.0000000000E+00f,\r
+ 0.0000000000E+00f, 0.0000000000E+00f, -1.5076513660E-01f, -7.3296291107E-01f,\r
+ -3.4890530566E+00f, -4.5470224727E+00f, -1.7695290031E+00f, -1.1451749092E+00f,\r
+ -8.3137738100E-01f, -1.3065629650E+00f, -5.4142014250E-01f, -4.6528974900E-01f,\r
+ -4.1066990750E-01f, -3.7004680800E-01f, -3.3876269197E-01f, -3.1242222492E-01f,\r
+ -2.8939587111E-01f, -2.6880081906E-01f, -5.0000000266E-01f, -2.3251417468E-01f,\r
+ -2.1596714708E-01f, -2.0004979098E-01f, -1.8449493497E-01f, -1.6905846094E-01f,\r
+ -1.5350360518E-01f, -1.3758624925E-01f, -1.2103922149E-01f, -2.0710679058E-01f,\r
+ -8.4752577594E-02f, -6.4157525656E-02f, -4.1131172614E-02f, -1.4790705759E-02f } };\r
+\r
+ /***************************************************************/\r
+ /* END OF INV_MDCT */\r
+ /***************************************************************/\r
+\r
+ class Sftable {\r
+ public int[] l;\r
+ public int[] s;\r
+\r
+ public Sftable() {\r
+ l = new int[5];\r
+ s = new int[3];\r
+ }\r
+\r
+ public Sftable(int[] thel, int[] thes) {\r
+ l = thel;\r
+ s = thes;\r
+ }\r
+ }\r
+\r
+ public Sftable sftable;\r
+\r
+ public static final int nr_of_sfb_block[][][] = {\r
+ { { 6, 5, 5, 5 }, { 9, 9, 9, 9 }, { 6, 9, 9, 9 } },\r
+ { { 6, 5, 7, 3 }, { 9, 9, 12, 6 }, { 6, 9, 12, 6 } },\r
+ { { 11, 10, 0, 0 }, { 18, 18, 0, 0 }, { 15, 18, 0, 0 } },\r
+ { { 7, 7, 7, 0 }, { 12, 12, 12, 0 }, { 6, 15, 12, 0 } },\r
+ { { 6, 6, 6, 3 }, { 12, 9, 9, 6 }, { 6, 12, 9, 6 } },\r
+ { { 8, 8, 5, 0 }, { 15, 12, 9, 0 }, { 6, 18, 9, 0 } } };\r
+\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL. \r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * Work in progress.\r
+ * \r
+ * Manages a number of controls.\r
+ */\r
+public class Manager //implements Control\r
+{\r
+ public void addControl(Control c)\r
+ {\r
+ \r
+ }\r
+ \r
+ public void removeControl(Control c)\r
+ {\r
+ \r
+ }\r
+ \r
+ public void removeAll()\r
+ {\r
+ \r
+ }\r
+ \r
+ // control interface delegates to a managed control\r
+ \r
+}\r
--- /dev/null
+/* \r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 12/12/99 Added appendSamples() method for efficiency. MDM.\r
+ * 15/02/99 ,Java Conversion by E.B ,ebsp@iname.com, JavaLayer\r
+ *\r
+ * Declarations for output buffer, includes operating system\r
+ * implementation of the virtual Obuffer. Optional routines\r
+ * enabling seeks and stops added by Jeff Tsay. \r
+ *\r
+ * @(#) obuffer.h 1.8, last edit: 6/15/94 16:51:56\r
+ * @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)\r
+ * @(#) Berlin University of Technology\r
+ *\r
+ * Idea and first implementation for u-law output with fast downsampling by\r
+ * Jim Boucher (jboucher@flash.bu.edu)\r
+ *\r
+ * LinuxObuffer class written by\r
+ * Louis P. Kruger (lpkruger@phoenix.princeton.edu)\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * Base Class for audio output.\r
+ */\r
+public abstract class Obuffer\r
+{\r
+ public static final int OBUFFERSIZE = 2 * 1152; // max. 2 * 1152 samples per frame\r
+ public static final int MAXCHANNELS = 2; // max. number of channels\r
+\r
+ /**\r
+ * Takes a 16 Bit PCM sample.\r
+ */\r
+ public abstract void append(int channel, short value);\r
+\r
+ /**\r
+ * Accepts 32 new PCM samples. \r
+ */\r
+ public void appendSamples(int channel, float[] f)\r
+ {\r
+ short s;\r
+ for (int i=0; i<32;)\r
+ {\r
+ s = clip(f[i++]);\r
+ append(channel, s); \r
+ }\r
+ }\r
+\r
+ /**\r
+ * Clip Sample to 16 Bits\r
+ */\r
+ private final short clip(float sample)\r
+ {\r
+ return ((sample > 32767.0f) ? 32767 :\r
+ ((sample < -32768.0f) ? -32768 :\r
+ (short) sample));\r
+ }\r
+ \r
+ /**\r
+ * Write the samples to the file or directly to the audio hardware.\r
+ */\r
+ public abstract void write_buffer(int val);\r
+ public abstract void close();\r
+\r
+ /**\r
+ * Clears all data in the buffer (for seeking).\r
+ */\r
+ public abstract void clear_buffer();\r
+\r
+ /**\r
+ * Notify the buffer that the user has stopped the stream.\r
+ */\r
+ public abstract void set_stop_flag();\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 12/12/99 Initial implementation. mdm@techie.com. \r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+\r
+/**\r
+ * A Type-safe representation of the the supported output channel\r
+ * constants. \r
+ * \r
+ * This class is immutable and, hence, is thread safe. \r
+ * \r
+ * @author Mat McGowan 12/12/99 \r
+ * @since 0.0.7\r
+ */\r
+public class OutputChannels\r
+{ \r
+ /**\r
+ * Flag to indicate output should include both channels. \r
+ */\r
+ public static final int BOTH_CHANNELS = 0;\r
+ \r
+ /**\r
+ * Flag to indicate output should include the left channel only. \r
+ */\r
+ public static final int LEFT_CHANNEL = 1;\r
+\r
+ /**\r
+ * Flag to indicate output should include the right channel only. \r
+ */\r
+ public static final int RIGHT_CHANNEL = 2;\r
+ \r
+ /**\r
+ * Flag to indicate output is mono. \r
+ */\r
+ public static final int DOWNMIX_CHANNELS = 3;\r
+\r
+ \r
+ public static final OutputChannels LEFT = new OutputChannels(LEFT_CHANNEL);\r
+ public static final OutputChannels RIGHT = new OutputChannels(RIGHT_CHANNEL);\r
+ public static final OutputChannels BOTH = new OutputChannels(BOTH_CHANNELS);\r
+ public static final OutputChannels DOWNMIX = new OutputChannels(DOWNMIX_CHANNELS);\r
+ \r
+ \r
+ private /*final*/ int outputChannels;\r
+ \r
+ /**\r
+ * Creates an <code>OutputChannels</code> instance\r
+ * corresponding to the given channel code.\r
+ * \r
+ * @param code one of the OutputChannels channel code constants.\r
+ * \r
+ * @throws IllegalArgumentException if code is not a valid\r
+ * channel code. \r
+ */\r
+ static public OutputChannels fromInt(int code)\r
+ {\r
+ switch (code)\r
+ {\r
+ case LEFT_CHANNEL:\r
+ return LEFT;\r
+ case RIGHT_CHANNEL:\r
+ return RIGHT;\r
+ case BOTH_CHANNELS:\r
+ return BOTH;\r
+ case DOWNMIX_CHANNELS:\r
+ return DOWNMIX;\r
+ default:\r
+ throw new IllegalArgumentException("Invalid channel code: "+code);\r
+ }\r
+ }\r
+ \r
+ private OutputChannels(int channels)\r
+ {\r
+ outputChannels = channels;\r
+ \r
+ if (channels<0 || channels>3)\r
+ throw new IllegalArgumentException("channels");\r
+ }\r
+ \r
+ /**\r
+ * Retrieves the code representing the desired output channels.\r
+ * Will be one of LEFT_CHANNEL, RIGHT_CHANNEL, BOTH_CHANNELS\r
+ * or DOWNMIX_CHANNELS.\r
+ * \r
+ * @return the channel code represented by this instance.\r
+ */\r
+ public int getChannelsOutputCode()\r
+ {\r
+ return outputChannels; \r
+ }\r
+ \r
+ /**\r
+ * Retrieves the number of output channels represented \r
+ * by this channel output type.\r
+ * \r
+ * @return The number of output channels for this channel output\r
+ * type. This will be 2 for BOTH_CHANNELS only, and 1\r
+ * for all other types. \r
+ */\r
+ public int getChannelCount()\r
+ {\r
+ int count = (outputChannels==BOTH_CHANNELS) ? 2 : 1;\r
+ return count;\r
+ }\r
+ \r
+ \r
+ public boolean equals(Object o)\r
+ {\r
+ boolean equals = false;\r
+ \r
+ if (o instanceof OutputChannels)\r
+ {\r
+ OutputChannels oc = (OutputChannels)o;\r
+ equals = (oc.outputChannels == outputChannels);\r
+ }\r
+ \r
+ return equals;\r
+ }\r
+ \r
+ public int hashCode()\r
+ {\r
+ return outputChannels; \r
+ }\r
+ \r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 29/01/00 Initial version. mdm@techie.com\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.player;\r
+\r
+import java.io.InputStream;\r
+\r
+import javazoom.jl.decoder.Bitstream;\r
+import javazoom.jl.decoder.BitstreamException;\r
+import javazoom.jl.decoder.Decoder;\r
+import javazoom.jl.decoder.Header;\r
+import javazoom.jl.decoder.JavaLayerException;\r
+import javazoom.jl.decoder.SampleBuffer;\r
+ \r
+/**\r
+ * The <code>Player</code> class implements a simple player for playback\r
+ * of an MPEG audio stream. \r
+ * \r
+ * @author Mat McGowan\r
+ * @since 0.0.8\r
+ */\r
+\r
+// REVIEW: the audio device should not be opened until the\r
+// first MPEG audio frame has been decoded. \r
+public class Player\r
+{ \r
+ /**\r
+ * The current frame number. \r
+ */\r
+ private int frame = 0;\r
+ \r
+ /**\r
+ * The MPEG audio bitstream. \r
+ */\r
+ // javac blank final bug. \r
+ /*final*/ private Bitstream bitstream;\r
+ \r
+ /**\r
+ * The MPEG audio decoder. \r
+ */\r
+ /*final*/ private Decoder decoder; \r
+ \r
+ /**\r
+ * The AudioDevice the audio samples are written to. \r
+ */\r
+ private AudioDevice audio;\r
+ \r
+ /**\r
+ * Has the player been closed?\r
+ */\r
+ private boolean closed = false;\r
+ \r
+ /**\r
+ * Has the player played back all frames from the stream?\r
+ */\r
+ private boolean complete = false;\r
+\r
+ private int lastPosition = 0;\r
+ \r
+ /**\r
+ * Creates a new <code>Player</code> instance. \r
+ */\r
+ public Player(InputStream stream) throws JavaLayerException\r
+ {\r
+ this(stream, null); \r
+ }\r
+ \r
+ public Player(InputStream stream, AudioDevice device) throws JavaLayerException\r
+ {\r
+ bitstream = new Bitstream(stream); \r
+ decoder = new Decoder();\r
+ \r
+ if (device!=null)\r
+ { \r
+ audio = device;\r
+ }\r
+ else\r
+ { \r
+ FactoryRegistry r = FactoryRegistry.systemRegistry();\r
+ audio = r.createAudioDevice();\r
+ }\r
+ audio.open(decoder);\r
+ }\r
+ \r
+ public void play() throws JavaLayerException\r
+ {\r
+ play(Integer.MAX_VALUE);\r
+ }\r
+ \r
+ /**\r
+ * Plays a number of MPEG audio frames. \r
+ * \r
+ * @param frames The number of frames to play. \r
+ * @return true if the last frame was played, or false if there are\r
+ * more frames. \r
+ */\r
+ public boolean play(int frames) throws JavaLayerException\r
+ {\r
+ boolean ret = true;\r
+ \r
+ while (frames-- > 0 && ret)\r
+ {\r
+ ret = decodeFrame(); \r
+ }\r
+ \r
+ if (!ret)\r
+ {\r
+ // last frame, ensure all data flushed to the audio device. \r
+ AudioDevice out = audio;\r
+ if (out!=null)\r
+ { \r
+ out.flush();\r
+ synchronized (this)\r
+ {\r
+ complete = (!closed);\r
+ close();\r
+ } \r
+ }\r
+ }\r
+ return ret;\r
+ }\r
+ \r
+ /**\r
+ * Cloases this player. Any audio currently playing is stopped\r
+ * immediately. \r
+ */\r
+ public synchronized void close()\r
+ { \r
+ AudioDevice out = audio;\r
+ if (out!=null)\r
+ { \r
+ closed = true;\r
+ audio = null; \r
+ // this may fail, so ensure object state is set up before\r
+ // calling this method. \r
+ out.close();\r
+ lastPosition = out.getPosition();\r
+ try\r
+ {\r
+ bitstream.close();\r
+ }\r
+ catch (BitstreamException ex)\r
+ {\r
+ }\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Returns the completed status of this player.\r
+ * \r
+ * @return true if all available MPEG audio frames have been\r
+ * decoded, or false otherwise. \r
+ */\r
+ public synchronized boolean isComplete()\r
+ {\r
+ return complete; \r
+ }\r
+ \r
+ /**\r
+ * Retrieves the position in milliseconds of the current audio\r
+ * sample being played. This method delegates to the <code>\r
+ * AudioDevice</code> that is used by this player to sound\r
+ * the decoded audio samples. \r
+ */\r
+ public int getPosition()\r
+ {\r
+ int position = lastPosition;\r
+ \r
+ AudioDevice out = audio; \r
+ if (out!=null)\r
+ {\r
+ position = out.getPosition(); \r
+ }\r
+ return position;\r
+ } \r
+ \r
+ /**\r
+ * Decodes a single frame.\r
+ * \r
+ * @return true if there are no more frames to decode, false otherwise.\r
+ */\r
+ protected boolean decodeFrame() throws JavaLayerException\r
+ { \r
+ try\r
+ {\r
+ AudioDevice out = audio;\r
+ if (out==null)\r
+ return false;\r
+\r
+ Header h = bitstream.readFrame(); \r
+ \r
+ if (h==null)\r
+ return false;\r
+ \r
+ // sample buffer set when decoder constructed\r
+ SampleBuffer output = (SampleBuffer)decoder.decodeFrame(h, bitstream);\r
+ \r
+ synchronized (this)\r
+ {\r
+ out = audio;\r
+ if (out!=null)\r
+ { \r
+ out.write(output.getBuffer(), 0, output.getBufferLength());\r
+ } \r
+ }\r
+ \r
+ bitstream.closeFrame();\r
+ } \r
+ catch (RuntimeException ex)\r
+ {\r
+ throw new JavaLayerException("Exception decoding audio frame", ex);\r
+ }\r
+/*\r
+ catch (IOException ex)\r
+ {\r
+ System.out.println("exception decoding audio frame: "+ex);\r
+ return false; \r
+ }\r
+ catch (BitstreamException bitex)\r
+ {\r
+ System.out.println("exception decoding audio frame: "+bitex);\r
+ return false; \r
+ }\r
+ catch (DecoderException decex)\r
+ {\r
+ System.out.println("exception decoding audio frame: "+decex);\r
+ return false; \r
+ }\r
+*/ \r
+ return true;\r
+ }\r
+\r
+ \r
+}\r
--- /dev/null
+/* \r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * \r
+ * 12/12/99 Initial Version based on FileObuffer. mdm@techie.com.\r
+ * \r
+ * FileObuffer:\r
+ * 15/02/99 Java Conversion by E.B ,javalayer@javazoom.net\r
+ *\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * The <code>SampleBuffer</code> class implements an output buffer\r
+ * that provides storage for a fixed size block of samples. \r
+ */\r
+public class SampleBuffer extends Obuffer\r
+{\r
+ private short[] buffer;\r
+ private int[] bufferp;\r
+ private int channels;\r
+ private int frequency;\r
+ \r
+ /**\r
+ * Constructor\r
+ */\r
+ public SampleBuffer(int sample_frequency, int number_of_channels)\r
+ {\r
+ buffer = new short[OBUFFERSIZE];\r
+ bufferp = new int[MAXCHANNELS];\r
+ channels = number_of_channels;\r
+ frequency = sample_frequency;\r
+ \r
+ for (int i = 0; i < number_of_channels; ++i) \r
+ bufferp[i] = (short)i;\r
+ \r
+ }\r
+\r
+ public int getChannelCount()\r
+ {\r
+ return this.channels; \r
+ }\r
+ \r
+ public int getSampleFrequency()\r
+ {\r
+ return this.frequency;\r
+ }\r
+ \r
+ public short[] getBuffer()\r
+ {\r
+ return this.buffer; \r
+ }\r
+ \r
+ public int getBufferLength()\r
+ {\r
+ return bufferp[0];\r
+ }\r
+ \r
+ /**\r
+ * Takes a 16 Bit PCM sample.\r
+ */\r
+ public void append(int channel, short value)\r
+ {\r
+ buffer[bufferp[channel]] = value;\r
+ bufferp[channel] += channels; \r
+ }\r
+ \r
+ public void appendSamples(int channel, float[] f)\r
+ {\r
+ int pos = bufferp[channel];\r
+ \r
+ short s;\r
+ float fs;\r
+ for (int i=0; i<32;)\r
+ {\r
+ fs = f[i++];\r
+ fs = (fs>32767.0f ? 32767.0f \r
+ : (fs < -32767.0f ? -32767.0f : fs));\r
+ \r
+ s = (short)fs;\r
+ buffer[pos] = s;\r
+ pos += channels;\r
+ }\r
+ \r
+ bufferp[channel] = pos;\r
+ }\r
+ \r
+ \r
+ /**\r
+ * Write the samples to the file (Random Acces).\r
+ */\r
+ public void write_buffer(int val)\r
+ {\r
+ \r
+ //for (int i = 0; i < channels; ++i) \r
+ // bufferp[i] = (short)i;\r
+\r
+ }\r
+\r
+ public void close()\r
+ {}\r
+ \r
+ /**\r
+ *\r
+ */\r
+ public void clear_buffer()\r
+ {\r
+ for (int i = 0; i < channels; ++i) \r
+ bufferp[i] = (short)i;\r
+ }\r
+\r
+ /**\r
+ *\r
+ */\r
+ public void set_stop_flag()\r
+ {}\r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL. \r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+import java.io.IOException;\r
+\r
+/**\r
+ * Work in progress.\r
+ * \r
+ * Class to describe a seekable data source. \r
+ * \r
+ */\r
+public interface Source\r
+{\r
+ \r
+ public static final long LENGTH_UNKNOWN = -1;\r
+ \r
+ public int read(byte[] b, int offs, int len)\r
+ throws IOException;\r
+ \r
+ \r
+ public boolean willReadBlock();\r
+ \r
+ public boolean isSeekable();\r
+ \r
+ public long length();\r
+ \r
+ public long tell();\r
+ \r
+ public long seek(long pos);\r
+ \r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * \r
+ * 04/01/00 Fixes for running under build 23xx Microsoft JVM. mdm.\r
+ * \r
+ * 19/12/99 Performance improvements to compute_pcm_samples(). \r
+ * Mat McGowan. mdm@techie.com. \r
+ *\r
+ * 16/02/99 Java Conversion by E.B , javalayer@javazoom.net\r
+ *\r
+ * @(#) synthesis_filter.h 1.8, last edit: 6/15/94 16:52:00\r
+ * @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)\r
+ * @(#) Berlin University of Technology\r
+ *\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+package javazoom.jl.decoder;\r
+\r
+import java.io.IOException;\r
+\r
+/**\r
+ * A class for the synthesis filter bank.\r
+ * This class does a fast downsampling from 32, 44.1 or 48 kHz to 8 kHz, if ULAW is defined.\r
+ * Frequencies above 4 kHz are removed by ignoring higher subbands.\r
+ */\r
+final class SynthesisFilter\r
+{\r
+ private float[] v1;\r
+ private float[] v2;\r
+ private float[] actual_v; // v1 or v2\r
+ private int actual_write_pos; // 0-15\r
+ private float[] samples; // 32 new subband samples\r
+ private int channel;\r
+ private float scalefactor;\r
+ private float[] eq;\r
+ \r
+ /**\r
+ * Quality value for controlling CPU usage/quality tradeoff. \r
+ */\r
+ /*\r
+ private int quality;\r
+ \r
+ private int v_inc;\r
+ \r
+ \r
+ \r
+ public static final int HIGH_QUALITY = 1;\r
+ public static final int MEDIUM_QUALITY = 2;\r
+ public static final int LOW_QUALITY = 4;\r
+ */\r
+ \r
+ /**\r
+ * Contructor.\r
+ * The scalefactor scales the calculated float pcm samples to short values\r
+ * (raw pcm samples are in [-1.0, 1.0], if no violations occur).\r
+ */\r
+ public SynthesisFilter(int channelnumber, float factor, float[] eq0)\r
+ { \r
+ if (d==null)\r
+ {\r
+ d = load_d();\r
+ d16 = splitArray(d, 16);\r
+ }\r
+ \r
+ v1 = new float[512];\r
+ v2 = new float[512];\r
+ samples = new float[32];\r
+ channel = channelnumber;\r
+ scalefactor = factor;\r
+ setEQ(eq); \r
+ //setQuality(HIGH_QUALITY);\r
+ \r
+ reset();\r
+ }\r
+ \r
+ public void setEQ(float[] eq0)\r
+ {\r
+ this.eq = eq0; \r
+ if (eq==null)\r
+ {\r
+ eq = new float[32];\r
+ for (int i=0; i<32; i++)\r
+ eq[i] = 1.0f;\r
+ }\r
+ if (eq.length<32)\r
+ {\r
+ throw new IllegalArgumentException("eq0"); \r
+ }\r
+ \r
+ }\r
+ \r
+ /*\r
+ private void setQuality(int quality0)\r
+ {\r
+ switch (quality0)\r
+ { \r
+ case HIGH_QUALITY:\r
+ case MEDIUM_QUALITY:\r
+ case LOW_QUALITY: \r
+ v_inc = 16 * quality0; \r
+ quality = quality0;\r
+ break; \r
+ default :\r
+ throw new IllegalArgumentException("Unknown quality value");\r
+ } \r
+ }\r
+ \r
+ public int getQuality()\r
+ {\r
+ return quality; \r
+ }\r
+ */\r
+ \r
+ /**\r
+ * Reset the synthesis filter.\r
+ */\r
+ public void reset()\r
+ {\r
+ //float[] floatp;\r
+ // float[] floatp2;\r
+\r
+ // initialize v1[] and v2[]:\r
+ //for (floatp = v1 + 512, floatp2 = v2 + 512; floatp > v1; )\r
+ // *--floatp = *--floatp2 = 0.0;\r
+ for (int p=0;p<512;p++) \r
+ v1[p] = v2[p] = 0.0f;\r
+\r
+ // initialize samples[]:\r
+ //for (floatp = samples + 32; floatp > samples; )\r
+ // *--floatp = 0.0;\r
+ for (int p2=0;p2<32;p2++) \r
+ samples[p2] = 0.0f;\r
+\r
+ actual_v = v1;\r
+ actual_write_pos = 15;\r
+ }\r
+\r
+\r
+ /**\r
+ * Inject Sample.\r
+ */\r
+ public void input_sample(float sample, int subbandnumber)\r
+ { \r
+ samples[subbandnumber] = eq[subbandnumber]*sample;\r
+ }\r
+\r
+ public void input_samples(float[] s)\r
+ {\r
+ for (int i=31; i>=0; i--)\r
+ { \r
+ samples[i] = s[i]*eq[i];\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * Compute new values via a fast cosine transform.\r
+ */\r
+ private void compute_new_v()\r
+ {\r
+ // p is fully initialized from x1\r
+ //float[] p = _p;\r
+ // pp is fully initialized from p\r
+ //float[] pp = _pp; \r
+ \r
+ //float[] new_v = _new_v;\r
+ \r
+ //float[] new_v = new float[32]; // new V[0-15] and V[33-48] of Figure 3-A.2 in ISO DIS 11172-3\r
+ //float[] p = new float[16];\r
+ //float[] pp = new float[16];\r
+ \r
+ /*\r
+ for (int i=31; i>=0; i--)\r
+ {\r
+ new_v[i] = 0.0f;\r
+ }\r
+ */\r
+ \r
+ float new_v0, new_v1, new_v2, new_v3, new_v4, new_v5, new_v6, new_v7, new_v8, new_v9;\r
+ float new_v10, new_v11, new_v12, new_v13, new_v14, new_v15, new_v16, new_v17, new_v18, new_v19;\r
+ float new_v20, new_v21, new_v22, new_v23, new_v24, new_v25, new_v26, new_v27, new_v28, new_v29;\r
+ float new_v30, new_v31;\r
+ \r
+ new_v0 = new_v1 = new_v2 = new_v3 = new_v4 = new_v5 = new_v6 = new_v7 = new_v8 = new_v9 = \r
+ new_v10 = new_v11 = new_v12 = new_v13 = new_v14 = new_v15 = new_v16 = new_v17 = new_v18 = new_v19 = \r
+ new_v20 = new_v21 = new_v22 = new_v23 = new_v24 = new_v25 = new_v26 = new_v27 = new_v28 = new_v29 = \r
+ new_v30 = new_v31 = 0.0f;\r
+ \r
+ \r
+// float[] new_v = new float[32]; // new V[0-15] and V[33-48] of Figure 3-A.2 in ISO DIS 11172-3\r
+// float[] p = new float[16];\r
+// float[] pp = new float[16];\r
+\r
+ float[] s = samples;\r
+ \r
+ float s0 = s[0];\r
+ float s1 = s[1];\r
+ float s2 = s[2];\r
+ float s3 = s[3];\r
+ float s4 = s[4];\r
+ float s5 = s[5];\r
+ float s6 = s[6];\r
+ float s7 = s[7];\r
+ float s8 = s[8];\r
+ float s9 = s[9];\r
+ float s10 = s[10]; \r
+ float s11 = s[11];\r
+ float s12 = s[12];\r
+ float s13 = s[13];\r
+ float s14 = s[14];\r
+ float s15 = s[15];\r
+ float s16 = s[16];\r
+ float s17 = s[17];\r
+ float s18 = s[18];\r
+ float s19 = s[19];\r
+ float s20 = s[20]; \r
+ float s21 = s[21];\r
+ float s22 = s[22];\r
+ float s23 = s[23];\r
+ float s24 = s[24];\r
+ float s25 = s[25];\r
+ float s26 = s[26];\r
+ float s27 = s[27];\r
+ float s28 = s[28];\r
+ float s29 = s[29];\r
+ float s30 = s[30]; \r
+ float s31 = s[31];\r
+ \r
+ float p0 = s0 + s31;\r
+ float p1 = s1 + s30;\r
+ float p2 = s2 + s29;\r
+ float p3 = s3 + s28;\r
+ float p4 = s4 + s27;\r
+ float p5 = s5 + s26;\r
+ float p6 = s6 + s25;\r
+ float p7 = s7 + s24;\r
+ float p8 = s8 + s23;\r
+ float p9 = s9 + s22;\r
+ float p10 = s10 + s21;\r
+ float p11 = s11 + s20;\r
+ float p12 = s12 + s19;\r
+ float p13 = s13 + s18;\r
+ float p14 = s14 + s17;\r
+ float p15 = s15 + s16;\r
+ \r
+ float pp0 = p0 + p15;\r
+ float pp1 = p1 + p14;\r
+ float pp2 = p2 + p13;\r
+ float pp3 = p3 + p12;\r
+ float pp4 = p4 + p11;\r
+ float pp5 = p5 + p10;\r
+ float pp6 = p6 + p9;\r
+ float pp7 = p7 + p8;\r
+ float pp8 = (p0 - p15) * cos1_32;\r
+ float pp9 = (p1 - p14) * cos3_32;\r
+ float pp10 = (p2 - p13) * cos5_32;\r
+ float pp11 = (p3 - p12) * cos7_32;\r
+ float pp12 = (p4 - p11) * cos9_32;\r
+ float pp13 = (p5 - p10) * cos11_32;\r
+ float pp14 = (p6 - p9) * cos13_32;\r
+ float pp15 = (p7 - p8) * cos15_32;\r
+\r
+ p0 = pp0 + pp7;\r
+ p1 = pp1 + pp6;\r
+ p2 = pp2 + pp5;\r
+ p3 = pp3 + pp4;\r
+ p4 = (pp0 - pp7) * cos1_16;\r
+ p5 = (pp1 - pp6) * cos3_16;\r
+ p6 = (pp2 - pp5) * cos5_16;\r
+ p7 = (pp3 - pp4) * cos7_16;\r
+ p8 = pp8 + pp15;\r
+ p9 = pp9 + pp14;\r
+ p10 = pp10 + pp13;\r
+ p11 = pp11 + pp12;\r
+ p12 = (pp8 - pp15) * cos1_16;\r
+ p13 = (pp9 - pp14) * cos3_16;\r
+ p14 = (pp10 - pp13) * cos5_16;\r
+ p15 = (pp11 - pp12) * cos7_16;\r
+ \r
+\r
+ pp0 = p0 + p3;\r
+ pp1 = p1 + p2;\r
+ pp2 = (p0 - p3) * cos1_8;\r
+ pp3 = (p1 - p2) * cos3_8;\r
+ pp4 = p4 + p7;\r
+ pp5 = p5 + p6;\r
+ pp6 = (p4 - p7) * cos1_8;\r
+ pp7 = (p5 - p6) * cos3_8;\r
+ pp8 = p8 + p11;\r
+ pp9 = p9 + p10;\r
+ pp10 = (p8 - p11) * cos1_8;\r
+ pp11 = (p9 - p10) * cos3_8;\r
+ pp12 = p12 + p15;\r
+ pp13 = p13 + p14;\r
+ pp14 = (p12 - p15) * cos1_8;\r
+ pp15 = (p13 - p14) * cos3_8;\r
+\r
+ p0 = pp0 + pp1;\r
+ p1 = (pp0 - pp1) * cos1_4;\r
+ p2 = pp2 + pp3;\r
+ p3 = (pp2 - pp3) * cos1_4;\r
+ p4 = pp4 + pp5;\r
+ p5 = (pp4 - pp5) * cos1_4;\r
+ p6 = pp6 + pp7;\r
+ p7 = (pp6 - pp7) * cos1_4;\r
+ p8 = pp8 + pp9;\r
+ p9 = (pp8 - pp9) * cos1_4;\r
+ p10 = pp10 + pp11;\r
+ p11 = (pp10 - pp11) * cos1_4;\r
+ p12 = pp12 + pp13;\r
+ p13 = (pp12 - pp13) * cos1_4;\r
+ p14 = pp14 + pp15;\r
+ p15 = (pp14 - pp15) * cos1_4;\r
+\r
+ // this is pretty insane coding\r
+ float tmp1;\r
+ new_v19/*36-17*/ = -(new_v4 = (new_v12 = p7) + p5) - p6;\r
+ new_v27/*44-17*/ = -p6 - p7 - p4;\r
+ new_v6 = (new_v10 = (new_v14 = p15) + p11) + p13;\r
+ new_v17/*34-17*/ = -(new_v2 = p15 + p13 + p9) - p14;\r
+ new_v21/*38-17*/ = (tmp1 = -p14 - p15 - p10 - p11) - p13;\r
+ new_v29/*46-17*/ = -p14 - p15 - p12 - p8;\r
+ new_v25/*42-17*/ = tmp1 - p12;\r
+ new_v31/*48-17*/ = -p0;\r
+ new_v0 = p1;\r
+ new_v23/*40-17*/ = -(new_v8 = p3) - p2;\r
+ \r
+ p0 = (s0 - s31) * cos1_64;\r
+ p1 = (s1 - s30) * cos3_64;\r
+ p2 = (s2 - s29) * cos5_64;\r
+ p3 = (s3 - s28) * cos7_64;\r
+ p4 = (s4 - s27) * cos9_64;\r
+ p5 = (s5 - s26) * cos11_64;\r
+ p6 = (s6 - s25) * cos13_64;\r
+ p7 = (s7 - s24) * cos15_64;\r
+ p8 = (s8 - s23) * cos17_64;\r
+ p9 = (s9 - s22) * cos19_64;\r
+ p10 = (s10 - s21) * cos21_64;\r
+ p11 = (s11 - s20) * cos23_64;\r
+ p12 = (s12 - s19) * cos25_64;\r
+ p13 = (s13 - s18) * cos27_64;\r
+ p14 = (s14 - s17) * cos29_64;\r
+ p15 = (s15 - s16) * cos31_64;\r
+\r
+ \r
+ pp0 = p0 + p15;\r
+ pp1 = p1 + p14;\r
+ pp2 = p2 + p13;\r
+ pp3 = p3 + p12;\r
+ pp4 = p4 + p11;\r
+ pp5 = p5 + p10;\r
+ pp6 = p6 + p9;\r
+ pp7 = p7 + p8;\r
+ pp8 = (p0 - p15) * cos1_32;\r
+ pp9 = (p1 - p14) * cos3_32;\r
+ pp10 = (p2 - p13) * cos5_32;\r
+ pp11 = (p3 - p12) * cos7_32;\r
+ pp12 = (p4 - p11) * cos9_32;\r
+ pp13 = (p5 - p10) * cos11_32;\r
+ pp14 = (p6 - p9) * cos13_32;\r
+ pp15 = (p7 - p8) * cos15_32;\r
+ \r
+\r
+ p0 = pp0 + pp7;\r
+ p1 = pp1 + pp6;\r
+ p2 = pp2 + pp5;\r
+ p3 = pp3 + pp4;\r
+ p4 = (pp0 - pp7) * cos1_16;\r
+ p5 = (pp1 - pp6) * cos3_16;\r
+ p6 = (pp2 - pp5) * cos5_16;\r
+ p7 = (pp3 - pp4) * cos7_16;\r
+ p8 = pp8 + pp15;\r
+ p9 = pp9 + pp14;\r
+ p10 = pp10 + pp13;\r
+ p11 = pp11 + pp12;\r
+ p12 = (pp8 - pp15) * cos1_16;\r
+ p13 = (pp9 - pp14) * cos3_16;\r
+ p14 = (pp10 - pp13) * cos5_16;\r
+ p15 = (pp11 - pp12) * cos7_16;\r
+\r
+\r
+ pp0 = p0 + p3;\r
+ pp1 = p1 + p2;\r
+ pp2 = (p0 - p3) * cos1_8;\r
+ pp3 = (p1 - p2) * cos3_8;\r
+ pp4 = p4 + p7;\r
+ pp5 = p5 + p6;\r
+ pp6 = (p4 - p7) * cos1_8;\r
+ pp7 = (p5 - p6) * cos3_8;\r
+ pp8 = p8 + p11;\r
+ pp9 = p9 + p10;\r
+ pp10 = (p8 - p11) * cos1_8;\r
+ pp11 = (p9 - p10) * cos3_8;\r
+ pp12 = p12 + p15;\r
+ pp13 = p13 + p14;\r
+ pp14 = (p12 - p15) * cos1_8;\r
+ pp15 = (p13 - p14) * cos3_8;\r
+\r
+ \r
+ p0 = pp0 + pp1;\r
+ p1 = (pp0 - pp1) * cos1_4;\r
+ p2 = pp2 + pp3;\r
+ p3 = (pp2 - pp3) * cos1_4;\r
+ p4 = pp4 + pp5;\r
+ p5 = (pp4 - pp5) * cos1_4;\r
+ p6 = pp6 + pp7;\r
+ p7 = (pp6 - pp7) * cos1_4;\r
+ p8 = pp8 + pp9;\r
+ p9 = (pp8 - pp9) * cos1_4;\r
+ p10 = pp10 + pp11;\r
+ p11 = (pp10 - pp11) * cos1_4;\r
+ p12 = pp12 + pp13;\r
+ p13 = (pp12 - pp13) * cos1_4;\r
+ p14 = pp14 + pp15;\r
+ p15 = (pp14 - pp15) * cos1_4;\r
+ \r
+\r
+ // manually doing something that a compiler should handle sucks\r
+ // coding like this is hard to read\r
+ float tmp2;\r
+ new_v5 = (new_v11 = (new_v13 = (new_v15 = p15) + p7) + p11)\r
+ + p5 + p13;\r
+ new_v7 = (new_v9 = p15 + p11 + p3) + p13;\r
+ new_v16/*33-17*/ = -(new_v1 = (tmp1 = p13 + p15 + p9) + p1) - p14;\r
+ new_v18/*35-17*/ = -(new_v3 = tmp1 + p5 + p7) - p6 - p14;\r
+\r
+ new_v22/*39-17*/ = (tmp1 = -p10 - p11 - p14 - p15)\r
+ - p13 - p2 - p3;\r
+ new_v20/*37-17*/ = tmp1 - p13 - p5 - p6 - p7;\r
+ new_v24/*41-17*/ = tmp1 - p12 - p2 - p3;\r
+ new_v26/*43-17*/ = tmp1 - p12 - (tmp2 = p4 + p6 + p7);\r
+ new_v30/*47-17*/ = (tmp1 = -p8 - p12 - p14 - p15) - p0;\r
+ new_v28/*45-17*/ = tmp1 - tmp2;\r
+\r
+ // insert V[0-15] (== new_v[0-15]) into actual v: \r
+ // float[] x2 = actual_v + actual_write_pos;\r
+ float dest[] = actual_v;\r
+ \r
+ int pos = actual_write_pos;\r
+ \r
+ dest[0 + pos] = new_v0;\r
+ dest[16 + pos] = new_v1;\r
+ dest[32 + pos] = new_v2;\r
+ dest[48 + pos] = new_v3;\r
+ dest[64 + pos] = new_v4;\r
+ dest[80 + pos] = new_v5;\r
+ dest[96 + pos] = new_v6;\r
+ dest[112 + pos] = new_v7;\r
+ dest[128 + pos] = new_v8;\r
+ dest[144 + pos] = new_v9;\r
+ dest[160 + pos] = new_v10;\r
+ dest[176 + pos] = new_v11;\r
+ dest[192 + pos] = new_v12;\r
+ dest[208 + pos] = new_v13;\r
+ dest[224 + pos] = new_v14;\r
+ dest[240 + pos] = new_v15;\r
+\r
+ // V[16] is always 0.0:\r
+ dest[256 + pos] = 0.0f;\r
+\r
+ // insert V[17-31] (== -new_v[15-1]) into actual v:\r
+ dest[272 + pos] = -new_v15;\r
+ dest[288 + pos] = -new_v14;\r
+ dest[304 + pos] = -new_v13;\r
+ dest[320 + pos] = -new_v12;\r
+ dest[336 + pos] = -new_v11;\r
+ dest[352 + pos] = -new_v10;\r
+ dest[368 + pos] = -new_v9;\r
+ dest[384 + pos] = -new_v8;\r
+ dest[400 + pos] = -new_v7;\r
+ dest[416 + pos] = -new_v6;\r
+ dest[432 + pos] = -new_v5;\r
+ dest[448 + pos] = -new_v4;\r
+ dest[464 + pos] = -new_v3;\r
+ dest[480 + pos] = -new_v2;\r
+ dest[496 + pos] = -new_v1;\r
+\r
+ // insert V[32] (== -new_v[0]) into other v:\r
+ dest = (actual_v==v1) ? v2 : v1;\r
+ \r
+ dest[0 + pos] = -new_v0;\r
+ // insert V[33-48] (== new_v[16-31]) into other v:\r
+ dest[16 + pos] = new_v16;\r
+ dest[32 + pos] = new_v17;\r
+ dest[48 + pos] = new_v18;\r
+ dest[64 + pos] = new_v19;\r
+ dest[80 + pos] = new_v20;\r
+ dest[96 + pos] = new_v21;\r
+ dest[112 + pos] = new_v22;\r
+ dest[128 + pos] = new_v23;\r
+ dest[144 + pos] = new_v24;\r
+ dest[160 + pos] = new_v25;\r
+ dest[176 + pos] = new_v26;\r
+ dest[192 + pos] = new_v27;\r
+ dest[208 + pos] = new_v28;\r
+ dest[224 + pos] = new_v29;\r
+ dest[240 + pos] = new_v30;\r
+ dest[256 + pos] = new_v31;\r
+ \r
+ // insert V[49-63] (== new_v[30-16]) into other v:\r
+ dest[272 + pos] = new_v30;\r
+ dest[288 + pos] = new_v29;\r
+ dest[304 + pos] = new_v28;\r
+ dest[320 + pos] = new_v27;\r
+ dest[336 + pos] = new_v26;\r
+ dest[352 + pos] = new_v25;\r
+ dest[368 + pos] = new_v24;\r
+ dest[384 + pos] = new_v23;\r
+ dest[400 + pos] = new_v22;\r
+ dest[416 + pos] = new_v21;\r
+ dest[432 + pos] = new_v20;\r
+ dest[448 + pos] = new_v19;\r
+ dest[464 + pos] = new_v18;\r
+ dest[480 + pos] = new_v17;\r
+ dest[496 + pos] = new_v16; \r
+/*\r
+ }\r
+ else\r
+ {\r
+ v1[0 + actual_write_pos] = -new_v0;\r
+ // insert V[33-48] (== new_v[16-31]) into other v:\r
+ v1[16 + actual_write_pos] = new_v16;\r
+ v1[32 + actual_write_pos] = new_v17;\r
+ v1[48 + actual_write_pos] = new_v18;\r
+ v1[64 + actual_write_pos] = new_v19;\r
+ v1[80 + actual_write_pos] = new_v20;\r
+ v1[96 + actual_write_pos] = new_v21;\r
+ v1[112 + actual_write_pos] = new_v22;\r
+ v1[128 + actual_write_pos] = new_v23;\r
+ v1[144 + actual_write_pos] = new_v24;\r
+ v1[160 + actual_write_pos] = new_v25;\r
+ v1[176 + actual_write_pos] = new_v26;\r
+ v1[192 + actual_write_pos] = new_v27;\r
+ v1[208 + actual_write_pos] = new_v28;\r
+ v1[224 + actual_write_pos] = new_v29;\r
+ v1[240 + actual_write_pos] = new_v30;\r
+ v1[256 + actual_write_pos] = new_v31;\r
+\r
+ // insert V[49-63] (== new_v[30-16]) into other v:\r
+ v1[272 + actual_write_pos] = new_v30;\r
+ v1[288 + actual_write_pos] = new_v29;\r
+ v1[304 + actual_write_pos] = new_v28;\r
+ v1[320 + actual_write_pos] = new_v27;\r
+ v1[336 + actual_write_pos] = new_v26;\r
+ v1[352 + actual_write_pos] = new_v25;\r
+ v1[368 + actual_write_pos] = new_v24;\r
+ v1[384 + actual_write_pos] = new_v23;\r
+ v1[400 + actual_write_pos] = new_v22;\r
+ v1[416 + actual_write_pos] = new_v21;\r
+ v1[432 + actual_write_pos] = new_v20;\r
+ v1[448 + actual_write_pos] = new_v19;\r
+ v1[464 + actual_write_pos] = new_v18;\r
+ v1[480 + actual_write_pos] = new_v17;\r
+ v1[496 + actual_write_pos] = new_v16; \r
+ }\r
+*/ \r
+ }\r
+ \r
+ /**\r
+ * Compute new values via a fast cosine transform.\r
+ */\r
+ private void compute_new_v_old()\r
+ {\r
+ // p is fully initialized from x1\r
+ //float[] p = _p;\r
+ // pp is fully initialized from p\r
+ //float[] pp = _pp; \r
+ \r
+ //float[] new_v = _new_v;\r
+ \r
+ float[] new_v = new float[32]; // new V[0-15] and V[33-48] of Figure 3-A.2 in ISO DIS 11172-3\r
+ float[] p = new float[16];\r
+ float[] pp = new float[16];\r
+ \r
+ \r
+ for (int i=31; i>=0; i--)\r
+ {\r
+ new_v[i] = 0.0f;\r
+ }\r
+ \r
+// float[] new_v = new float[32]; // new V[0-15] and V[33-48] of Figure 3-A.2 in ISO DIS 11172-3\r
+// float[] p = new float[16];\r
+// float[] pp = new float[16];\r
+\r
+ float[] x1 = samples;\r
+ \r
+ p[0] = x1[0] + x1[31];\r
+ p[1] = x1[1] + x1[30];\r
+ p[2] = x1[2] + x1[29];\r
+ p[3] = x1[3] + x1[28];\r
+ p[4] = x1[4] + x1[27];\r
+ p[5] = x1[5] + x1[26];\r
+ p[6] = x1[6] + x1[25];\r
+ p[7] = x1[7] + x1[24];\r
+ p[8] = x1[8] + x1[23];\r
+ p[9] = x1[9] + x1[22];\r
+ p[10] = x1[10] + x1[21];\r
+ p[11] = x1[11] + x1[20];\r
+ p[12] = x1[12] + x1[19];\r
+ p[13] = x1[13] + x1[18];\r
+ p[14] = x1[14] + x1[17];\r
+ p[15] = x1[15] + x1[16];\r
+ \r
+ pp[0] = p[0] + p[15];\r
+ pp[1] = p[1] + p[14];\r
+ pp[2] = p[2] + p[13];\r
+ pp[3] = p[3] + p[12];\r
+ pp[4] = p[4] + p[11];\r
+ pp[5] = p[5] + p[10];\r
+ pp[6] = p[6] + p[9];\r
+ pp[7] = p[7] + p[8];\r
+ pp[8] = (p[0] - p[15]) * cos1_32;\r
+ pp[9] = (p[1] - p[14]) * cos3_32;\r
+ pp[10] = (p[2] - p[13]) * cos5_32;\r
+ pp[11] = (p[3] - p[12]) * cos7_32;\r
+ pp[12] = (p[4] - p[11]) * cos9_32;\r
+ pp[13] = (p[5] - p[10]) * cos11_32;\r
+ pp[14] = (p[6] - p[9]) * cos13_32;\r
+ pp[15] = (p[7] - p[8]) * cos15_32;\r
+\r
+ p[0] = pp[0] + pp[7];\r
+ p[1] = pp[1] + pp[6];\r
+ p[2] = pp[2] + pp[5];\r
+ p[3] = pp[3] + pp[4];\r
+ p[4] = (pp[0] - pp[7]) * cos1_16;\r
+ p[5] = (pp[1] - pp[6]) * cos3_16;\r
+ p[6] = (pp[2] - pp[5]) * cos5_16;\r
+ p[7] = (pp[3] - pp[4]) * cos7_16;\r
+ p[8] = pp[8] + pp[15];\r
+ p[9] = pp[9] + pp[14];\r
+ p[10] = pp[10] + pp[13];\r
+ p[11] = pp[11] + pp[12];\r
+ p[12] = (pp[8] - pp[15]) * cos1_16;\r
+ p[13] = (pp[9] - pp[14]) * cos3_16;\r
+ p[14] = (pp[10] - pp[13]) * cos5_16;\r
+ p[15] = (pp[11] - pp[12]) * cos7_16;\r
+ \r
+\r
+ pp[0] = p[0] + p[3];\r
+ pp[1] = p[1] + p[2];\r
+ pp[2] = (p[0] - p[3]) * cos1_8;\r
+ pp[3] = (p[1] - p[2]) * cos3_8;\r
+ pp[4] = p[4] + p[7];\r
+ pp[5] = p[5] + p[6];\r
+ pp[6] = (p[4] - p[7]) * cos1_8;\r
+ pp[7] = (p[5] - p[6]) * cos3_8;\r
+ pp[8] = p[8] + p[11];\r
+ pp[9] = p[9] + p[10];\r
+ pp[10] = (p[8] - p[11]) * cos1_8;\r
+ pp[11] = (p[9] - p[10]) * cos3_8;\r
+ pp[12] = p[12] + p[15];\r
+ pp[13] = p[13] + p[14];\r
+ pp[14] = (p[12] - p[15]) * cos1_8;\r
+ pp[15] = (p[13] - p[14]) * cos3_8;\r
+\r
+ p[0] = pp[0] + pp[1];\r
+ p[1] = (pp[0] - pp[1]) * cos1_4;\r
+ p[2] = pp[2] + pp[3];\r
+ p[3] = (pp[2] - pp[3]) * cos1_4;\r
+ p[4] = pp[4] + pp[5];\r
+ p[5] = (pp[4] - pp[5]) * cos1_4;\r
+ p[6] = pp[6] + pp[7];\r
+ p[7] = (pp[6] - pp[7]) * cos1_4;\r
+ p[8] = pp[8] + pp[9];\r
+ p[9] = (pp[8] - pp[9]) * cos1_4;\r
+ p[10] = pp[10] + pp[11];\r
+ p[11] = (pp[10] - pp[11]) * cos1_4;\r
+ p[12] = pp[12] + pp[13];\r
+ p[13] = (pp[12] - pp[13]) * cos1_4;\r
+ p[14] = pp[14] + pp[15];\r
+ p[15] = (pp[14] - pp[15]) * cos1_4;\r
+\r
+ // this is pretty insane coding\r
+ float tmp1;\r
+ new_v[36-17] = -(new_v[4] = (new_v[12] = p[7]) + p[5]) - p[6];\r
+ new_v[44-17] = -p[6] - p[7] - p[4];\r
+ new_v[6] = (new_v[10] = (new_v[14] = p[15]) + p[11]) + p[13];\r
+ new_v[34-17] = -(new_v[2] = p[15] + p[13] + p[9]) - p[14];\r
+ new_v[38-17] = (tmp1 = -p[14] - p[15] - p[10] - p[11]) - p[13];\r
+ new_v[46-17] = -p[14] - p[15] - p[12] - p[8];\r
+ new_v[42-17] = tmp1 - p[12];\r
+ new_v[48-17] = -p[0];\r
+ new_v[0] = p[1];\r
+ new_v[40-17] = -(new_v[8] = p[3]) - p[2];\r
+ \r
+ p[0] = (x1[0] - x1[31]) * cos1_64;\r
+ p[1] = (x1[1] - x1[30]) * cos3_64;\r
+ p[2] = (x1[2] - x1[29]) * cos5_64;\r
+ p[3] = (x1[3] - x1[28]) * cos7_64;\r
+ p[4] = (x1[4] - x1[27]) * cos9_64;\r
+ p[5] = (x1[5] - x1[26]) * cos11_64;\r
+ p[6] = (x1[6] - x1[25]) * cos13_64;\r
+ p[7] = (x1[7] - x1[24]) * cos15_64;\r
+ p[8] = (x1[8] - x1[23]) * cos17_64;\r
+ p[9] = (x1[9] - x1[22]) * cos19_64;\r
+ p[10] = (x1[10] - x1[21]) * cos21_64;\r
+ p[11] = (x1[11] - x1[20]) * cos23_64;\r
+ p[12] = (x1[12] - x1[19]) * cos25_64;\r
+ p[13] = (x1[13] - x1[18]) * cos27_64;\r
+ p[14] = (x1[14] - x1[17]) * cos29_64;\r
+ p[15] = (x1[15] - x1[16]) * cos31_64;\r
+\r
+ \r
+ pp[0] = p[0] + p[15];\r
+ pp[1] = p[1] + p[14];\r
+ pp[2] = p[2] + p[13];\r
+ pp[3] = p[3] + p[12];\r
+ pp[4] = p[4] + p[11];\r
+ pp[5] = p[5] + p[10];\r
+ pp[6] = p[6] + p[9];\r
+ pp[7] = p[7] + p[8];\r
+ pp[8] = (p[0] - p[15]) * cos1_32;\r
+ pp[9] = (p[1] - p[14]) * cos3_32;\r
+ pp[10] = (p[2] - p[13]) * cos5_32;\r
+ pp[11] = (p[3] - p[12]) * cos7_32;\r
+ pp[12] = (p[4] - p[11]) * cos9_32;\r
+ pp[13] = (p[5] - p[10]) * cos11_32;\r
+ pp[14] = (p[6] - p[9]) * cos13_32;\r
+ pp[15] = (p[7] - p[8]) * cos15_32;\r
+ \r
+\r
+ p[0] = pp[0] + pp[7];\r
+ p[1] = pp[1] + pp[6];\r
+ p[2] = pp[2] + pp[5];\r
+ p[3] = pp[3] + pp[4];\r
+ p[4] = (pp[0] - pp[7]) * cos1_16;\r
+ p[5] = (pp[1] - pp[6]) * cos3_16;\r
+ p[6] = (pp[2] - pp[5]) * cos5_16;\r
+ p[7] = (pp[3] - pp[4]) * cos7_16;\r
+ p[8] = pp[8] + pp[15];\r
+ p[9] = pp[9] + pp[14];\r
+ p[10] = pp[10] + pp[13];\r
+ p[11] = pp[11] + pp[12];\r
+ p[12] = (pp[8] - pp[15]) * cos1_16;\r
+ p[13] = (pp[9] - pp[14]) * cos3_16;\r
+ p[14] = (pp[10] - pp[13]) * cos5_16;\r
+ p[15] = (pp[11] - pp[12]) * cos7_16;\r
+\r
+\r
+ pp[0] = p[0] + p[3];\r
+ pp[1] = p[1] + p[2];\r
+ pp[2] = (p[0] - p[3]) * cos1_8;\r
+ pp[3] = (p[1] - p[2]) * cos3_8;\r
+ pp[4] = p[4] + p[7];\r
+ pp[5] = p[5] + p[6];\r
+ pp[6] = (p[4] - p[7]) * cos1_8;\r
+ pp[7] = (p[5] - p[6]) * cos3_8;\r
+ pp[8] = p[8] + p[11];\r
+ pp[9] = p[9] + p[10];\r
+ pp[10] = (p[8] - p[11]) * cos1_8;\r
+ pp[11] = (p[9] - p[10]) * cos3_8;\r
+ pp[12] = p[12] + p[15];\r
+ pp[13] = p[13] + p[14];\r
+ pp[14] = (p[12] - p[15]) * cos1_8;\r
+ pp[15] = (p[13] - p[14]) * cos3_8;\r
+\r
+ \r
+ p[0] = pp[0] + pp[1];\r
+ p[1] = (pp[0] - pp[1]) * cos1_4;\r
+ p[2] = pp[2] + pp[3];\r
+ p[3] = (pp[2] - pp[3]) * cos1_4;\r
+ p[4] = pp[4] + pp[5];\r
+ p[5] = (pp[4] - pp[5]) * cos1_4;\r
+ p[6] = pp[6] + pp[7];\r
+ p[7] = (pp[6] - pp[7]) * cos1_4;\r
+ p[8] = pp[8] + pp[9];\r
+ p[9] = (pp[8] - pp[9]) * cos1_4;\r
+ p[10] = pp[10] + pp[11];\r
+ p[11] = (pp[10] - pp[11]) * cos1_4;\r
+ p[12] = pp[12] + pp[13];\r
+ p[13] = (pp[12] - pp[13]) * cos1_4;\r
+ p[14] = pp[14] + pp[15];\r
+ p[15] = (pp[14] - pp[15]) * cos1_4;\r
+ \r
+\r
+ // manually doing something that a compiler should handle sucks\r
+ // coding like this is hard to read\r
+ float tmp2;\r
+ new_v[5] = (new_v[11] = (new_v[13] = (new_v[15] = p[15]) + p[7]) + p[11])\r
+ + p[5] + p[13];\r
+ new_v[7] = (new_v[9] = p[15] + p[11] + p[3]) + p[13];\r
+ new_v[33-17] = -(new_v[1] = (tmp1 = p[13] + p[15] + p[9]) + p[1]) - p[14];\r
+ new_v[35-17] = -(new_v[3] = tmp1 + p[5] + p[7]) - p[6] - p[14];\r
+\r
+ new_v[39-17] = (tmp1 = -p[10] - p[11] - p[14] - p[15])\r
+ - p[13] - p[2] - p[3];\r
+ new_v[37-17] = tmp1 - p[13] - p[5] - p[6] - p[7];\r
+ new_v[41-17] = tmp1 - p[12] - p[2] - p[3];\r
+ new_v[43-17] = tmp1 - p[12] - (tmp2 = p[4] + p[6] + p[7]);\r
+ new_v[47-17] = (tmp1 = -p[8] - p[12] - p[14] - p[15]) - p[0];\r
+ new_v[45-17] = tmp1 - tmp2;\r
+\r
+ // insert V[0-15] (== new_v[0-15]) into actual v:\r
+ x1 = new_v;\r
+ // float[] x2 = actual_v + actual_write_pos;\r
+ float[] dest = actual_v;\r
+ \r
+ dest[0 + actual_write_pos] = x1[0];\r
+ dest[16 + actual_write_pos] = x1[1];\r
+ dest[32 + actual_write_pos] = x1[2];\r
+ dest[48 + actual_write_pos] = x1[3];\r
+ dest[64 + actual_write_pos] = x1[4];\r
+ dest[80 + actual_write_pos] = x1[5];\r
+ dest[96 + actual_write_pos] = x1[6];\r
+ dest[112 + actual_write_pos] = x1[7];\r
+ dest[128 + actual_write_pos] = x1[8];\r
+ dest[144 + actual_write_pos] = x1[9];\r
+ dest[160 + actual_write_pos] = x1[10];\r
+ dest[176 + actual_write_pos] = x1[11];\r
+ dest[192 + actual_write_pos] = x1[12];\r
+ dest[208 + actual_write_pos] = x1[13];\r
+ dest[224 + actual_write_pos] = x1[14];\r
+ dest[240 + actual_write_pos] = x1[15];\r
+\r
+ // V[16] is always 0.0:\r
+ dest[256 + actual_write_pos] = 0.0f;\r
+\r
+ // insert V[17-31] (== -new_v[15-1]) into actual v:\r
+ dest[272 + actual_write_pos] = -x1[15];\r
+ dest[288 + actual_write_pos] = -x1[14];\r
+ dest[304 + actual_write_pos] = -x1[13];\r
+ dest[320 + actual_write_pos] = -x1[12];\r
+ dest[336 + actual_write_pos] = -x1[11];\r
+ dest[352 + actual_write_pos] = -x1[10];\r
+ dest[368 + actual_write_pos] = -x1[9];\r
+ dest[384 + actual_write_pos] = -x1[8];\r
+ dest[400 + actual_write_pos] = -x1[7];\r
+ dest[416 + actual_write_pos] = -x1[6];\r
+ dest[432 + actual_write_pos] = -x1[5];\r
+ dest[448 + actual_write_pos] = -x1[4];\r
+ dest[464 + actual_write_pos] = -x1[3];\r
+ dest[480 + actual_write_pos] = -x1[2];\r
+ dest[496 + actual_write_pos] = -x1[1];\r
+\r
+ // insert V[32] (== -new_v[0]) into other v:\r
+ \r
+ }\r
+\r
+ /**\r
+ * Compute PCM Samples.\r
+ */\r
+ \r
+ private float[] _tmpOut = new float[32];\r
+ \r
+ \r
+ private void compute_pcm_samples0(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v; \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ float pcm_sample;\r
+ final float[] dp = d16[i];\r
+ pcm_sample = (float)(((vp[0 + dvp] * dp[0]) +\r
+ (vp[15 + dvp] * dp[1]) +\r
+ (vp[14 + dvp] * dp[2]) +\r
+ (vp[13 + dvp] * dp[3]) +\r
+ (vp[12 + dvp] * dp[4]) +\r
+ (vp[11 + dvp] * dp[5]) +\r
+ (vp[10 + dvp] * dp[6]) +\r
+ (vp[9 + dvp] * dp[7]) +\r
+ (vp[8 + dvp] * dp[8]) +\r
+ (vp[7 + dvp] * dp[9]) +\r
+ (vp[6 + dvp] * dp[10]) +\r
+ (vp[5 + dvp] * dp[11]) +\r
+ (vp[4 + dvp] * dp[12]) +\r
+ (vp[3 + dvp] * dp[13]) +\r
+ (vp[2 + dvp] * dp[14]) +\r
+ (vp[1 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ \r
+ private void compute_pcm_samples1(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v; \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[1 + dvp] * dp[0]) +\r
+ (vp[0 + dvp] * dp[1]) +\r
+ (vp[15 + dvp] * dp[2]) +\r
+ (vp[14 + dvp] * dp[3]) +\r
+ (vp[13 + dvp] * dp[4]) +\r
+ (vp[12 + dvp] * dp[5]) +\r
+ (vp[11 + dvp] * dp[6]) +\r
+ (vp[10 + dvp] * dp[7]) +\r
+ (vp[9 + dvp] * dp[8]) +\r
+ (vp[8 + dvp] * dp[9]) +\r
+ (vp[7 + dvp] * dp[10]) +\r
+ (vp[6 + dvp] * dp[11]) +\r
+ (vp[5 + dvp] * dp[12]) +\r
+ (vp[4 + dvp] * dp[13]) +\r
+ (vp[3 + dvp] * dp[14]) +\r
+ (vp[2 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ private void compute_pcm_samples2(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[2 + dvp] * dp[0]) +\r
+ (vp[1 + dvp] * dp[1]) +\r
+ (vp[0 + dvp] * dp[2]) +\r
+ (vp[15 + dvp] * dp[3]) +\r
+ (vp[14 + dvp] * dp[4]) +\r
+ (vp[13 + dvp] * dp[5]) +\r
+ (vp[12 + dvp] * dp[6]) +\r
+ (vp[11 + dvp] * dp[7]) +\r
+ (vp[10 + dvp] * dp[8]) +\r
+ (vp[9 + dvp] * dp[9]) +\r
+ (vp[8 + dvp] * dp[10]) +\r
+ (vp[7 + dvp] * dp[11]) +\r
+ (vp[6 + dvp] * dp[12]) +\r
+ (vp[5 + dvp] * dp[13]) +\r
+ (vp[4 + dvp] * dp[14]) +\r
+ (vp[3 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ \r
+ private void compute_pcm_samples3(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ int idx = 0;\r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[3 + dvp] * dp[0]) +\r
+ (vp[2 + dvp] * dp[1]) +\r
+ (vp[1 + dvp] * dp[2]) +\r
+ (vp[0 + dvp] * dp[3]) +\r
+ (vp[15 + dvp] * dp[4]) +\r
+ (vp[14 + dvp] * dp[5]) +\r
+ (vp[13 + dvp] * dp[6]) +\r
+ (vp[12 + dvp] * dp[7]) +\r
+ (vp[11 + dvp] * dp[8]) +\r
+ (vp[10 + dvp] * dp[9]) +\r
+ (vp[9 + dvp] * dp[10]) +\r
+ (vp[8 + dvp] * dp[11]) +\r
+ (vp[7 + dvp] * dp[12]) +\r
+ (vp[6 + dvp] * dp[13]) +\r
+ (vp[5 + dvp] * dp[14]) +\r
+ (vp[4 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ \r
+ private void compute_pcm_samples4(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[4 + dvp] * dp[0]) +\r
+ (vp[3 + dvp] * dp[1]) +\r
+ (vp[2 + dvp] * dp[2]) +\r
+ (vp[1 + dvp] * dp[3]) +\r
+ (vp[0 + dvp] * dp[4]) +\r
+ (vp[15 + dvp] * dp[5]) +\r
+ (vp[14 + dvp] * dp[6]) +\r
+ (vp[13 + dvp] * dp[7]) +\r
+ (vp[12 + dvp] * dp[8]) +\r
+ (vp[11 + dvp] * dp[9]) +\r
+ (vp[10 + dvp] * dp[10]) +\r
+ (vp[9 + dvp] * dp[11]) +\r
+ (vp[8 + dvp] * dp[12]) +\r
+ (vp[7 + dvp] * dp[13]) +\r
+ (vp[6 + dvp] * dp[14]) +\r
+ (vp[5 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ \r
+ private void compute_pcm_samples5(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[5 + dvp] * dp[0]) +\r
+ (vp[4 + dvp] * dp[1]) +\r
+ (vp[3 + dvp] * dp[2]) +\r
+ (vp[2 + dvp] * dp[3]) +\r
+ (vp[1 + dvp] * dp[4]) +\r
+ (vp[0 + dvp] * dp[5]) +\r
+ (vp[15 + dvp] * dp[6]) +\r
+ (vp[14 + dvp] * dp[7]) +\r
+ (vp[13 + dvp] * dp[8]) +\r
+ (vp[12 + dvp] * dp[9]) +\r
+ (vp[11 + dvp] * dp[10]) +\r
+ (vp[10 + dvp] * dp[11]) +\r
+ (vp[9 + dvp] * dp[12]) +\r
+ (vp[8 + dvp] * dp[13]) +\r
+ (vp[7 + dvp] * dp[14]) +\r
+ (vp[6 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ \r
+ private void compute_pcm_samples6(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v; \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[6 + dvp] * dp[0]) +\r
+ (vp[5 + dvp] * dp[1]) +\r
+ (vp[4 + dvp] * dp[2]) +\r
+ (vp[3 + dvp] * dp[3]) +\r
+ (vp[2 + dvp] * dp[4]) +\r
+ (vp[1 + dvp] * dp[5]) +\r
+ (vp[0 + dvp] * dp[6]) +\r
+ (vp[15 + dvp] * dp[7]) +\r
+ (vp[14 + dvp] * dp[8]) +\r
+ (vp[13 + dvp] * dp[9]) +\r
+ (vp[12 + dvp] * dp[10]) +\r
+ (vp[11 + dvp] * dp[11]) +\r
+ (vp[10 + dvp] * dp[12]) +\r
+ (vp[9 + dvp] * dp[13]) +\r
+ (vp[8 + dvp] * dp[14]) +\r
+ (vp[7 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ \r
+ private void compute_pcm_samples7(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[7 + dvp] * dp[0]) +\r
+ (vp[6 + dvp] * dp[1]) +\r
+ (vp[5 + dvp] * dp[2]) +\r
+ (vp[4 + dvp] * dp[3]) +\r
+ (vp[3 + dvp] * dp[4]) +\r
+ (vp[2 + dvp] * dp[5]) +\r
+ (vp[1 + dvp] * dp[6]) +\r
+ (vp[0 + dvp] * dp[7]) +\r
+ (vp[15 + dvp] * dp[8]) +\r
+ (vp[14 + dvp] * dp[9]) +\r
+ (vp[13 + dvp] * dp[10]) +\r
+ (vp[12 + dvp] * dp[11]) +\r
+ (vp[11 + dvp] * dp[12]) +\r
+ (vp[10 + dvp] * dp[13]) +\r
+ (vp[9 + dvp] * dp[14]) +\r
+ (vp[8 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ private void compute_pcm_samples8(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[8 + dvp] * dp[0]) +\r
+ (vp[7 + dvp] * dp[1]) +\r
+ (vp[6 + dvp] * dp[2]) +\r
+ (vp[5 + dvp] * dp[3]) +\r
+ (vp[4 + dvp] * dp[4]) +\r
+ (vp[3 + dvp] * dp[5]) +\r
+ (vp[2 + dvp] * dp[6]) +\r
+ (vp[1 + dvp] * dp[7]) +\r
+ (vp[0 + dvp] * dp[8]) +\r
+ (vp[15 + dvp] * dp[9]) +\r
+ (vp[14 + dvp] * dp[10]) +\r
+ (vp[13 + dvp] * dp[11]) +\r
+ (vp[12 + dvp] * dp[12]) +\r
+ (vp[11 + dvp] * dp[13]) +\r
+ (vp[10 + dvp] * dp[14]) +\r
+ (vp[9 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ \r
+ private void compute_pcm_samples9(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[9 + dvp] * dp[0]) +\r
+ (vp[8 + dvp] * dp[1]) +\r
+ (vp[7 + dvp] * dp[2]) +\r
+ (vp[6 + dvp] * dp[3]) +\r
+ (vp[5 + dvp] * dp[4]) +\r
+ (vp[4 + dvp] * dp[5]) +\r
+ (vp[3 + dvp] * dp[6]) +\r
+ (vp[2 + dvp] * dp[7]) +\r
+ (vp[1 + dvp] * dp[8]) +\r
+ (vp[0 + dvp] * dp[9]) +\r
+ (vp[15 + dvp] * dp[10]) +\r
+ (vp[14 + dvp] * dp[11]) +\r
+ (vp[13 + dvp] * dp[12]) +\r
+ (vp[12 + dvp] * dp[13]) +\r
+ (vp[11 + dvp] * dp[14]) +\r
+ (vp[10 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ \r
+ private void compute_pcm_samples10(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v; \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[10 + dvp] * dp[0]) +\r
+ (vp[9 + dvp] * dp[1]) +\r
+ (vp[8 + dvp] * dp[2]) +\r
+ (vp[7 + dvp] * dp[3]) +\r
+ (vp[6 + dvp] * dp[4]) +\r
+ (vp[5 + dvp] * dp[5]) +\r
+ (vp[4 + dvp] * dp[6]) +\r
+ (vp[3 + dvp] * dp[7]) +\r
+ (vp[2 + dvp] * dp[8]) +\r
+ (vp[1 + dvp] * dp[9]) +\r
+ (vp[0 + dvp] * dp[10]) +\r
+ (vp[15 + dvp] * dp[11]) +\r
+ (vp[14 + dvp] * dp[12]) +\r
+ (vp[13 + dvp] * dp[13]) +\r
+ (vp[12 + dvp] * dp[14]) +\r
+ (vp[11 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ private void compute_pcm_samples11(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[11 + dvp] * dp[0]) +\r
+ (vp[10 + dvp] * dp[1]) +\r
+ (vp[9 + dvp] * dp[2]) +\r
+ (vp[8 + dvp] * dp[3]) +\r
+ (vp[7 + dvp] * dp[4]) +\r
+ (vp[6 + dvp] * dp[5]) +\r
+ (vp[5 + dvp] * dp[6]) +\r
+ (vp[4 + dvp] * dp[7]) +\r
+ (vp[3 + dvp] * dp[8]) +\r
+ (vp[2 + dvp] * dp[9]) +\r
+ (vp[1 + dvp] * dp[10]) +\r
+ (vp[0 + dvp] * dp[11]) +\r
+ (vp[15 + dvp] * dp[12]) +\r
+ (vp[14 + dvp] * dp[13]) +\r
+ (vp[13 + dvp] * dp[14]) +\r
+ (vp[12 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ private void compute_pcm_samples12(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v; \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[12 + dvp] * dp[0]) +\r
+ (vp[11 + dvp] * dp[1]) +\r
+ (vp[10 + dvp] * dp[2]) +\r
+ (vp[9 + dvp] * dp[3]) +\r
+ (vp[8 + dvp] * dp[4]) +\r
+ (vp[7 + dvp] * dp[5]) +\r
+ (vp[6 + dvp] * dp[6]) +\r
+ (vp[5 + dvp] * dp[7]) +\r
+ (vp[4 + dvp] * dp[8]) +\r
+ (vp[3 + dvp] * dp[9]) +\r
+ (vp[2 + dvp] * dp[10]) +\r
+ (vp[1 + dvp] * dp[11]) +\r
+ (vp[0 + dvp] * dp[12]) +\r
+ (vp[15 + dvp] * dp[13]) +\r
+ (vp[14 + dvp] * dp[14]) +\r
+ (vp[13 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ private void compute_pcm_samples13(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[13 + dvp] * dp[0]) +\r
+ (vp[12 + dvp] * dp[1]) +\r
+ (vp[11 + dvp] * dp[2]) +\r
+ (vp[10 + dvp] * dp[3]) +\r
+ (vp[9 + dvp] * dp[4]) +\r
+ (vp[8 + dvp] * dp[5]) +\r
+ (vp[7 + dvp] * dp[6]) +\r
+ (vp[6 + dvp] * dp[7]) +\r
+ (vp[5 + dvp] * dp[8]) +\r
+ (vp[4 + dvp] * dp[9]) +\r
+ (vp[3 + dvp] * dp[10]) +\r
+ (vp[2 + dvp] * dp[11]) +\r
+ (vp[1 + dvp] * dp[12]) +\r
+ (vp[0 + dvp] * dp[13]) +\r
+ (vp[15 + dvp] * dp[14]) +\r
+ (vp[14 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ private void compute_pcm_samples14(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ final float[] dp = d16[i];\r
+ float pcm_sample;\r
+\r
+ pcm_sample = (float)(((vp[14 + dvp] * dp[0]) +\r
+ (vp[13 + dvp] * dp[1]) +\r
+ (vp[12 + dvp] * dp[2]) +\r
+ (vp[11 + dvp] * dp[3]) +\r
+ (vp[10 + dvp] * dp[4]) +\r
+ (vp[9 + dvp] * dp[5]) +\r
+ (vp[8 + dvp] * dp[6]) +\r
+ (vp[7 + dvp] * dp[7]) +\r
+ (vp[6 + dvp] * dp[8]) +\r
+ (vp[5 + dvp] * dp[9]) +\r
+ (vp[4 + dvp] * dp[10]) +\r
+ (vp[3 + dvp] * dp[11]) +\r
+ (vp[2 + dvp] * dp[12]) +\r
+ (vp[1 + dvp] * dp[13]) +\r
+ (vp[0 + dvp] * dp[14]) +\r
+ (vp[15 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample;\r
+ \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ private void compute_pcm_samples15(Obuffer buffer)\r
+ {\r
+ final float[] vp = actual_v;\r
+ \r
+ //int inc = v_inc;\r
+ final float[] tmpOut = _tmpOut;\r
+ int dvp =0;\r
+ \r
+ // fat chance of having this loop unroll\r
+ for( int i=0; i<32; i++)\r
+ {\r
+ float pcm_sample;\r
+ final float dp[] = d16[i];\r
+ pcm_sample = (float)(((vp[15 + dvp] * dp[0]) +\r
+ (vp[14 + dvp] * dp[1]) +\r
+ (vp[13 + dvp] * dp[2]) +\r
+ (vp[12 + dvp] * dp[3]) +\r
+ (vp[11 + dvp] * dp[4]) +\r
+ (vp[10 + dvp] * dp[5]) +\r
+ (vp[9 + dvp] * dp[6]) +\r
+ (vp[8 + dvp] * dp[7]) +\r
+ (vp[7 + dvp] * dp[8]) +\r
+ (vp[6 + dvp] * dp[9]) +\r
+ (vp[5 + dvp] * dp[10]) +\r
+ (vp[4 + dvp] * dp[11]) +\r
+ (vp[3 + dvp] * dp[12]) +\r
+ (vp[2 + dvp] * dp[13]) +\r
+ (vp[1 + dvp] * dp[14]) +\r
+ (vp[0 + dvp] * dp[15])\r
+ ) * scalefactor);\r
+\r
+ tmpOut[i] = pcm_sample; \r
+ dvp += 16;\r
+ } // for\r
+ }\r
+ \r
+private void compute_pcm_samples(Obuffer buffer)\r
+{\r
+ \r
+ switch (actual_write_pos)\r
+ {\r
+ case 0: \r
+ compute_pcm_samples0(buffer);\r
+ break;\r
+ case 1: \r
+ compute_pcm_samples1(buffer);\r
+ break;\r
+ case 2: \r
+ compute_pcm_samples2(buffer);\r
+ break;\r
+ case 3: \r
+ compute_pcm_samples3(buffer);\r
+ break;\r
+ case 4: \r
+ compute_pcm_samples4(buffer);\r
+ break;\r
+ case 5: \r
+ compute_pcm_samples5(buffer);\r
+ break;\r
+ case 6: \r
+ compute_pcm_samples6(buffer);\r
+ break;\r
+ case 7: \r
+ compute_pcm_samples7(buffer);\r
+ break;\r
+ case 8: \r
+ compute_pcm_samples8(buffer);\r
+ break;\r
+ case 9: \r
+ compute_pcm_samples9(buffer);\r
+ break;\r
+ case 10: \r
+ compute_pcm_samples10(buffer);\r
+ break;\r
+ case 11: \r
+ compute_pcm_samples11(buffer);\r
+ break;\r
+ case 12: \r
+ compute_pcm_samples12(buffer);\r
+ break;\r
+ case 13: \r
+ compute_pcm_samples13(buffer);\r
+ break;\r
+ case 14: \r
+ compute_pcm_samples14(buffer);\r
+ break;\r
+ case 15: \r
+ compute_pcm_samples15(buffer);\r
+ break;\r
+ }\r
+ \r
+ if (buffer!=null)\r
+ { \r
+ buffer.appendSamples(channel, _tmpOut);\r
+ }\r
+ \r
+/*\r
+ // MDM: I was considering putting in quality control for\r
+ // low-spec CPUs, but the performance gain (about 10-15%) \r
+ // did not justify the considerable drop in audio quality.\r
+ switch (inc)\r
+ {\r
+ case 16: \r
+ buffer.appendSamples(channel, tmpOut);\r
+ break;\r
+ case 32:\r
+ for (int i=0; i<16; i++)\r
+ {\r
+ buffer.append(channel, (short)tmpOut[i]);\r
+ buffer.append(channel, (short)tmpOut[i]); \r
+ }\r
+ break; \r
+ case 64:\r
+ for (int i=0; i<8; i++)\r
+ {\r
+ buffer.append(channel, (short)tmpOut[i]);\r
+ buffer.append(channel, (short)tmpOut[i]);\r
+ buffer.append(channel, (short)tmpOut[i]);\r
+ buffer.append(channel, (short)tmpOut[i]); \r
+ }\r
+ break; \r
+ \r
+ }\r
+*/ \r
+ }\r
+\r
+ /**\r
+ * Calculate 32 PCM samples and put the into the Obuffer-object.\r
+ */\r
+ \r
+ public void calculate_pcm_samples(Obuffer buffer)\r
+ {\r
+ compute_new_v(); \r
+ compute_pcm_samples(buffer);\r
+ \r
+ actual_write_pos = (actual_write_pos + 1) & 0xf;\r
+ actual_v = (actual_v == v1) ? v2 : v1;\r
+\r
+ // initialize samples[]: \r
+ //for (register float *floatp = samples + 32; floatp > samples; )\r
+ // *--floatp = 0.0f; \r
+ \r
+ // MDM: this may not be necessary. The Layer III decoder always\r
+ // outputs 32 subband samples, but I haven't checked layer I & II.\r
+ for (int p=0;p<32;p++) \r
+ samples[p] = 0.0f;\r
+ }\r
+ \r
+ \r
+ private static final double MY_PI = 3.14159265358979323846;\r
+ private static final float cos1_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI / 64.0)));\r
+ private static final float cos3_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 3.0 / 64.0)));\r
+ private static final float cos5_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 5.0 / 64.0)));\r
+ private static final float cos7_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 7.0 / 64.0)));\r
+ private static final float cos9_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 9.0 / 64.0)));\r
+ private static final float cos11_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 11.0 / 64.0)));\r
+ private static final float cos13_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 13.0 / 64.0)));\r
+ private static final float cos15_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 15.0 / 64.0)));\r
+ private static final float cos17_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 17.0 / 64.0)));\r
+ private static final float cos19_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 19.0 / 64.0)));\r
+ private static final float cos21_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 21.0 / 64.0)));\r
+ private static final float cos23_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 23.0 / 64.0)));\r
+ private static final float cos25_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 25.0 / 64.0)));\r
+ private static final float cos27_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 27.0 / 64.0)));\r
+ private static final float cos29_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 29.0 / 64.0)));\r
+ private static final float cos31_64 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 31.0 / 64.0)));\r
+ private static final float cos1_32 =(float) (1.0 / (2.0 * Math.cos(MY_PI / 32.0)));\r
+ private static final float cos3_32 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 3.0 / 32.0)));\r
+ private static final float cos5_32 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 5.0 / 32.0)));\r
+ private static final float cos7_32 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 7.0 / 32.0)));\r
+ private static final float cos9_32 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 9.0 / 32.0)));\r
+ private static final float cos11_32 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 11.0 / 32.0)));\r
+ private static final float cos13_32 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 13.0 / 32.0)));\r
+ private static final float cos15_32 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 15.0 / 32.0)));\r
+ private static final float cos1_16 =(float) (1.0 / (2.0 * Math.cos(MY_PI / 16.0)));\r
+ private static final float cos3_16 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 3.0 / 16.0)));\r
+ private static final float cos5_16 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 5.0 / 16.0)));\r
+ private static final float cos7_16 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 7.0 / 16.0)));\r
+ private static final float cos1_8 =(float) (1.0 / (2.0 * Math.cos(MY_PI / 8.0)));\r
+ private static final float cos3_8 =(float) (1.0 / (2.0 * Math.cos(MY_PI * 3.0 / 8.0)));\r
+ private static final float cos1_4 =(float) (1.0 / (2.0 * Math.cos(MY_PI / 4.0)));\r
+ \r
+ // Note: These values are not in the same order\r
+ // as in Annex 3-B.3 of the ISO/IEC DIS 11172-3 \r
+ // private float d[] = {0.000000000, -4.000442505};\r
+ \r
+ private static float d[] = null;\r
+ \r
+ /** \r
+ * d[] split into subarrays of length 16. This provides for\r
+ * more faster access by allowing a block of 16 to be addressed\r
+ * with constant offset. \r
+ **/\r
+ private static float d16[][] = null; \r
+ \r
+ /**\r
+ * Loads the data for the d[] from the resource SFd.ser. \r
+ * @return the loaded values for d[].\r
+ */\r
+ static private float[] load_d()\r
+ {\r
+ try\r
+ {\r
+ Class elemType = Float.TYPE;\r
+ Object o = JavaLayerUtils.deserializeArrayResource("sfd.ser", elemType, 512);\r
+ return (float[])o;\r
+ }\r
+ catch (IOException ex)\r
+ {\r
+ throw new ExceptionInInitializerError(ex);\r
+ } \r
+ }\r
+ \r
+ /**\r
+ * Converts a 1D array into a number of smaller arrays. This is used\r
+ * to achieve offset + constant indexing into an array. Each sub-array\r
+ * represents a block of values of the original array. \r
+ * @param array The array to split up into blocks.\r
+ * @param blockSize The size of the blocks to split the array\r
+ * into. This must be an exact divisor of\r
+ * the length of the array, or some data\r
+ * will be lost from the main array.\r
+ * \r
+ * @return An array of arrays in which each element in the returned\r
+ * array will be of length <code>blockSize</code>.\r
+ */\r
+ static private float[][] splitArray(final float[] array, final int blockSize)\r
+ {\r
+ int size = array.length / blockSize;\r
+ float[][] split = new float[size][];\r
+ for (int i=0; i<size; i++)\r
+ {\r
+ split[i] = subArray(array, i*blockSize, blockSize);\r
+ }\r
+ return split;\r
+ }\r
+ \r
+ /**\r
+ * Returns a subarray of an existing array.\r
+ * \r
+ * @param array The array to retrieve a subarra from.\r
+ * @param offs The offset in the array that corresponds to\r
+ * the first index of the subarray.\r
+ * @param len The number of indeces in the subarray.\r
+ * @return The subarray, which may be of length 0.\r
+ */\r
+ static private float[] subArray(final float[] array, final int offs, int len)\r
+ {\r
+ if (offs+len > array.length)\r
+ {\r
+ len = array.length-offs;\r
+ }\r
+ \r
+ if (len < 0)\r
+ len = 0;\r
+ \r
+ float[] subarray = new float[len];\r
+ for (int i=0; i<len; i++)\r
+ {\r
+ subarray[i] = array[offs+i];\r
+ }\r
+ \r
+ return subarray;\r
+ }\r
+ \r
+ // The original data for d[]. This data is loaded from a file\r
+ // to reduce the overall package size and to improve performance. \r
+/* \r
+ static final float d_data[] = {\r
+ 0.000000000f, -0.000442505f, 0.003250122f, -0.007003784f,\r
+ 0.031082153f, -0.078628540f, 0.100311279f, -0.572036743f,\r
+ 1.144989014f, 0.572036743f, 0.100311279f, 0.078628540f,\r
+ 0.031082153f, 0.007003784f, 0.003250122f, 0.000442505f,\r
+ -0.000015259f, -0.000473022f, 0.003326416f, -0.007919312f,\r
+ 0.030517578f, -0.084182739f, 0.090927124f, -0.600219727f,\r
+ 1.144287109f, 0.543823242f, 0.108856201f, 0.073059082f,\r
+ 0.031478882f, 0.006118774f, 0.003173828f, 0.000396729f,\r
+ -0.000015259f, -0.000534058f, 0.003387451f, -0.008865356f,\r
+ 0.029785156f, -0.089706421f, 0.080688477f, -0.628295898f,\r
+ 1.142211914f, 0.515609741f, 0.116577148f, 0.067520142f,\r
+ 0.031738281f, 0.005294800f, 0.003082275f, 0.000366211f,\r
+ -0.000015259f, -0.000579834f, 0.003433228f, -0.009841919f,\r
+ 0.028884888f, -0.095169067f, 0.069595337f, -0.656219482f,\r
+ 1.138763428f, 0.487472534f, 0.123474121f, 0.061996460f,\r
+ 0.031845093f, 0.004486084f, 0.002990723f, 0.000320435f,\r
+ -0.000015259f, -0.000625610f, 0.003463745f, -0.010848999f,\r
+ 0.027801514f, -0.100540161f, 0.057617188f, -0.683914185f,\r
+ 1.133926392f, 0.459472656f, 0.129577637f, 0.056533813f,\r
+ 0.031814575f, 0.003723145f, 0.002899170f, 0.000289917f,\r
+ -0.000015259f, -0.000686646f, 0.003479004f, -0.011886597f,\r
+ 0.026535034f, -0.105819702f, 0.044784546f, -0.711318970f,\r
+ 1.127746582f, 0.431655884f, 0.134887695f, 0.051132202f,\r
+ 0.031661987f, 0.003005981f, 0.002792358f, 0.000259399f,\r
+ -0.000015259f, -0.000747681f, 0.003479004f, -0.012939453f,\r
+ 0.025085449f, -0.110946655f, 0.031082153f, -0.738372803f,\r
+ 1.120223999f, 0.404083252f, 0.139450073f, 0.045837402f,\r
+ 0.031387329f, 0.002334595f, 0.002685547f, 0.000244141f,\r
+ -0.000030518f, -0.000808716f, 0.003463745f, -0.014022827f,\r
+ 0.023422241f, -0.115921021f, 0.016510010f, -0.765029907f,\r
+ 1.111373901f, 0.376800537f, 0.143264771f, 0.040634155f,\r
+ 0.031005859f, 0.001693726f, 0.002578735f, 0.000213623f,\r
+ -0.000030518f, -0.000885010f, 0.003417969f, -0.015121460f,\r
+ 0.021575928f, -0.120697021f, 0.001068115f, -0.791213989f,\r
+ 1.101211548f, 0.349868774f, 0.146362305f, 0.035552979f,\r
+ 0.030532837f, 0.001098633f, 0.002456665f, 0.000198364f,\r
+ -0.000030518f, -0.000961304f, 0.003372192f, -0.016235352f,\r
+ 0.019531250f, -0.125259399f, -0.015228271f, -0.816864014f,\r
+ 1.089782715f, 0.323318481f, 0.148773193f, 0.030609131f,\r
+ 0.029937744f, 0.000549316f, 0.002349854f, 0.000167847f,\r
+ -0.000030518f, -0.001037598f, 0.003280640f, -0.017349243f,\r
+ 0.017257690f, -0.129562378f, -0.032379150f, -0.841949463f,\r
+ 1.077117920f, 0.297210693f, 0.150497437f, 0.025817871f,\r
+ 0.029281616f, 0.000030518f, 0.002243042f, 0.000152588f,\r
+ -0.000045776f, -0.001113892f, 0.003173828f, -0.018463135f,\r
+ 0.014801025f, -0.133590698f, -0.050354004f, -0.866363525f,\r
+ 1.063217163f, 0.271591187f, 0.151596069f, 0.021179199f,\r
+ 0.028533936f, -0.000442505f, 0.002120972f, 0.000137329f,\r
+ -0.000045776f, -0.001205444f, 0.003051758f, -0.019577026f,\r
+ 0.012115479f, -0.137298584f, -0.069168091f, -0.890090942f,\r
+ 1.048156738f, 0.246505737f, 0.152069092f, 0.016708374f,\r
+ 0.027725220f, -0.000869751f, 0.002014160f, 0.000122070f,\r
+ -0.000061035f, -0.001296997f, 0.002883911f, -0.020690918f,\r
+ 0.009231567f, -0.140670776f, -0.088775635f, -0.913055420f,\r
+ 1.031936646f, 0.221984863f, 0.151962280f, 0.012420654f,\r
+ 0.026840210f, -0.001266479f, 0.001907349f, 0.000106812f,\r
+ -0.000061035f, -0.001388550f, 0.002700806f, -0.021789551f,\r
+ 0.006134033f, -0.143676758f, -0.109161377f, -0.935195923f,\r
+ 1.014617920f, 0.198059082f, 0.151306152f, 0.008316040f,\r
+ 0.025909424f, -0.001617432f, 0.001785278f, 0.000106812f,\r
+ -0.000076294f, -0.001480103f, 0.002487183f, -0.022857666f,\r
+ 0.002822876f, -0.146255493f, -0.130310059f, -0.956481934f,\r
+ 0.996246338f, 0.174789429f, 0.150115967f, 0.004394531f,\r
+ 0.024932861f, -0.001937866f, 0.001693726f, 0.000091553f,\r
+ -0.000076294f, -0.001586914f, 0.002227783f, -0.023910522f,\r
+ -0.000686646f, -0.148422241f, -0.152206421f, -0.976852417f,\r
+ 0.976852417f, 0.152206421f, 0.148422241f, 0.000686646f,\r
+ 0.023910522f, -0.002227783f, 0.001586914f, 0.000076294f,\r
+ -0.000091553f, -0.001693726f, 0.001937866f, -0.024932861f,\r
+ -0.004394531f, -0.150115967f, -0.174789429f, -0.996246338f,\r
+ 0.956481934f, 0.130310059f, 0.146255493f, -0.002822876f,\r
+ 0.022857666f, -0.002487183f, 0.001480103f, 0.000076294f,\r
+ -0.000106812f, -0.001785278f, 0.001617432f, -0.025909424f,\r
+ -0.008316040f, -0.151306152f, -0.198059082f, -1.014617920f,\r
+ 0.935195923f, 0.109161377f, 0.143676758f, -0.006134033f,\r
+ 0.021789551f, -0.002700806f, 0.001388550f, 0.000061035f,\r
+ -0.000106812f, -0.001907349f, 0.001266479f, -0.026840210f,\r
+ -0.012420654f, -0.151962280f, -0.221984863f, -1.031936646f,\r
+ 0.913055420f, 0.088775635f, 0.140670776f, -0.009231567f,\r
+ 0.020690918f, -0.002883911f, 0.001296997f, 0.000061035f,\r
+ -0.000122070f, -0.002014160f, 0.000869751f, -0.027725220f,\r
+ -0.016708374f, -0.152069092f, -0.246505737f, -1.048156738f,\r
+ 0.890090942f, 0.069168091f, 0.137298584f, -0.012115479f,\r
+ 0.019577026f, -0.003051758f, 0.001205444f, 0.000045776f,\r
+ -0.000137329f, -0.002120972f, 0.000442505f, -0.028533936f,\r
+ -0.021179199f, -0.151596069f, -0.271591187f, -1.063217163f,\r
+ 0.866363525f, 0.050354004f, 0.133590698f, -0.014801025f,\r
+ 0.018463135f, -0.003173828f, 0.001113892f, 0.000045776f,\r
+ -0.000152588f, -0.002243042f, -0.000030518f, -0.029281616f,\r
+ -0.025817871f, -0.150497437f, -0.297210693f, -1.077117920f,\r
+ 0.841949463f, 0.032379150f, 0.129562378f, -0.017257690f,\r
+ 0.017349243f, -0.003280640f, 0.001037598f, 0.000030518f,\r
+ -0.000167847f, -0.002349854f, -0.000549316f, -0.029937744f,\r
+ -0.030609131f, -0.148773193f, -0.323318481f, -1.089782715f,\r
+ 0.816864014f, 0.015228271f, 0.125259399f, -0.019531250f,\r
+ 0.016235352f, -0.003372192f, 0.000961304f, 0.000030518f,\r
+ -0.000198364f, -0.002456665f, -0.001098633f, -0.030532837f,\r
+ -0.035552979f, -0.146362305f, -0.349868774f, -1.101211548f,\r
+ 0.791213989f, -0.001068115f, 0.120697021f, -0.021575928f,\r
+ 0.015121460f, -0.003417969f, 0.000885010f, 0.000030518f,\r
+ -0.000213623f, -0.002578735f, -0.001693726f, -0.031005859f,\r
+ -0.040634155f, -0.143264771f, -0.376800537f, -1.111373901f,\r
+ 0.765029907f, -0.016510010f, 0.115921021f, -0.023422241f,\r
+ 0.014022827f, -0.003463745f, 0.000808716f, 0.000030518f,\r
+ -0.000244141f, -0.002685547f, -0.002334595f, -0.031387329f,\r
+ -0.045837402f, -0.139450073f, -0.404083252f, -1.120223999f,\r
+ 0.738372803f, -0.031082153f, 0.110946655f, -0.025085449f,\r
+ 0.012939453f, -0.003479004f, 0.000747681f, 0.000015259f,\r
+ -0.000259399f, -0.002792358f, -0.003005981f, -0.031661987f,\r
+ -0.051132202f, -0.134887695f, -0.431655884f, -1.127746582f,\r
+ 0.711318970f, -0.044784546f, 0.105819702f, -0.026535034f,\r
+ 0.011886597f, -0.003479004f, 0.000686646f, 0.000015259f,\r
+ -0.000289917f, -0.002899170f, -0.003723145f, -0.031814575f,\r
+ -0.056533813f, -0.129577637f, -0.459472656f, -1.133926392f,\r
+ 0.683914185f, -0.057617188f, 0.100540161f, -0.027801514f,\r
+ 0.010848999f, -0.003463745f, 0.000625610f, 0.000015259f,\r
+ -0.000320435f, -0.002990723f, -0.004486084f, -0.031845093f,\r
+ -0.061996460f, -0.123474121f, -0.487472534f, -1.138763428f,\r
+ 0.656219482f, -0.069595337f, 0.095169067f, -0.028884888f,\r
+ 0.009841919f, -0.003433228f, 0.000579834f, 0.000015259f,\r
+ -0.000366211f, -0.003082275f, -0.005294800f, -0.031738281f,\r
+ -0.067520142f, -0.116577148f, -0.515609741f, -1.142211914f,\r
+ 0.628295898f, -0.080688477f, 0.089706421f, -0.029785156f,\r
+ 0.008865356f, -0.003387451f, 0.000534058f, 0.000015259f,\r
+ -0.000396729f, -0.003173828f, -0.006118774f, -0.031478882f,\r
+ -0.073059082f, -0.108856201f, -0.543823242f, -1.144287109f,\r
+ 0.600219727f, -0.090927124f, 0.084182739f, -0.030517578f,\r
+ 0.007919312f, -0.003326416f, 0.000473022f, 0.000015259f\r
+ };\r
+ */\r
+ \r
+}\r
--- /dev/null
+/*\r
+ * 11/19/04 1.0 moved to LGPL.\r
+ * 16/11/99 Renamed class, added javadoc, and changed table\r
+ * name from String to 3 chars. mdm@techie.com\r
+ * 02/15/99 Java Conversion by E.B, javalayer@javazoom.net\r
+ *\r
+ * 04/19/97 : Adapted from the ISO MPEG Audio Subgroup Software Simulation\r
+ * Group's public c source for its MPEG audio decoder. Miscellaneous\r
+ * changes by Jeff Tsay (ctsay@pasteur.eecs.berkeley.edu).\r
+ *-----------------------------------------------------------------------\r
+ * Copyright (c) 1991 MPEG/audio software simulation group, All Rights Reserved\r
+ * MPEG/audio coding/decoding software, work in progress \r
+ * NOT for public distribution until verified and approved by the \r
+ * MPEG/audio committee. For further information, please contact \r
+ * Davis Pan, 508-493-2241, e-mail: pan@3d.enet.dec.com \r
+ * \r
+ * VERSION 4.1 \r
+ * changes made since last update: \r
+ * date programmers comment \r
+ * 27.2.92 F.O.Witte (ITT Intermetall) \r
+ * 8/24/93 M. Iwadare Changed for 1 pass decoding. \r
+ * 7/14/94 J. Koller useless 'typedef' before huffcodetab removed\r
+ *-----------------------------------------------------------------------\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Library General Public License as published\r
+ * by the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ *----------------------------------------------------------------------\r
+ */\r
+\r
+package javazoom.jl.decoder;\r
+\r
+/**\r
+ * Class to implements Huffman decoder.\r
+ */\r
+final class huffcodetab\r
+{\r
+ private static final int MXOFF=250;\r
+ private static final int HTN=34;\r
+ \r
+ private char tablename0 = ' '; /* string, containing table_description */\r
+ private char tablename1 = ' '; /* string, containing table_description */\r
+ private char tablename2 = ' '; /* string, containing table_description */\r
+ \r
+ private int xlen; /* max. x-index+ */\r
+ private int ylen; /* max. y-index+ */\r
+ private int linbits; /* number of linbits */\r
+ private int linmax; /* max number to be stored in linbits */\r
+ private int ref; /* a positive value indicates a reference */\r
+ private int[] table=null; /* pointer to array[xlen][ylen] */\r
+ private int[] hlen=null; /* pointer to array[xlen][ylen] */\r
+ private int[][] val=null; /* decoder tree */\r
+ private int treelen; /* length of decoder tree */\r
+\r
+ private static int ValTab0[][] = {\r
+ {0,0} // dummy\r
+ };\r
+\r
+ private static int ValTab1[][] = {\r
+ {2,1},{0,0},{2,1},{0,16},{2,1},{0,1},{0,17},\r
+ };\r
+ \r
+ private static int ValTab2[][] = {\r
+ {2,1},{0,0},{4,1},{2,1},{0,16},{0,1},{2,1},{0,17},{4,1},{2,1},\r
+ {0,32},{0,33},{2,1},{0,18},{2,1},{0,2},{0,34},\r
+ };\r
+ \r
+ private static int ValTab3[][] = {\r
+ {4,1},{2,1},{0,0},{0,1},{2,1},{0,17},{2,1},{0,16},{4,1},{2,1},\r
+ {0,32},{0,33},{2,1},{0,18},{2,1},{0,2},{0,34},\r
+ };\r
+\r
+ private static int ValTab4[][] = {{0,0}}; // dummy\r
+\r
+ private static int ValTab5[][] = {\r
+ {2,1},{0,0},{4,1},{2,1},{0,16},{0,1},{2,1},{0,17},{8,1},{4,1},\r
+ {2,1},{0,32},{0,2},{2,1},{0,33},{0,18},{8,1},{4,1},{2,1},{0,34},\r
+ {0,48},{2,1},{0,3},{0,19},{2,1},{0,49},{2,1},{0,50},{2,1},{0,35},\r
+ {0,51},\r
+ };\r
+\r
+ private static int ValTab6[][] = {\r
+ {6,1},{4,1},{2,1},{0,0},{0,16},{0,17},{6,1},{2,1},{0,1},{2,1},\r
+ {0,32},{0,33},{6,1},{2,1},{0,18},{2,1},{0,2},{0,34},{4,1},{2,1},\r
+ {0,49},{0,19},{4,1},{2,1},{0,48},{0,50},{2,1},{0,35},{2,1},{0,3},\r
+ {0,51},\r
+ };\r
+ \r
+ private static int ValTab7[][] = {\r
+ {2,1},{0,0},{4,1},{2,1},{0,16},{0,1},{8,1},{2,1},{0,17},{4,1},\r
+ {2,1},{0,32},{0,2},{0,33},{18,1},{6,1},{2,1},{0,18},{2,1},{0,34},\r
+ {0,48},{4,1},{2,1},{0,49},{0,19},{4,1},{2,1},{0,3},{0,50},{2,1},\r
+ {0,35},{0,4},{10,1},{4,1},{2,1},{0,64},{0,65},{2,1},{0,20},{2,1},\r
+ {0,66},{0,36},{12,1},{6,1},{4,1},{2,1},{0,51},{0,67},{0,80},{4,1},\r
+ {2,1},{0,52},{0,5},{0,81},{6,1},{2,1},{0,21},{2,1},{0,82},{0,37},\r
+ {4,1},{2,1},{0,68},{0,53},{4,1},{2,1},{0,83},{0,84},{2,1},{0,69},\r
+ {0,85},\r
+ };\r
+ \r
+ private static int ValTab8[][] = {\r
+ {6,1},{2,1},{0,0},{2,1},{0,16},{0,1},{2,1},{0,17},{4,1},{2,1},\r
+ {0,33},{0,18},{14,1},{4,1},{2,1},{0,32},{0,2},{2,1},{0,34},{4,1},\r
+ {2,1},{0,48},{0,3},{2,1},{0,49},{0,19},{14,1},{8,1},{4,1},{2,1},\r
+ {0,50},{0,35},{2,1},{0,64},{0,4},{2,1},{0,65},{2,1},{0,20},{0,66},\r
+ {12,1},{6,1},{2,1},{0,36},{2,1},{0,51},{0,80},{4,1},{2,1},{0,67},\r
+ {0,52},{0,81},{6,1},{2,1},{0,21},{2,1},{0,5},{0,82},{6,1},{2,1},\r
+ {0,37},{2,1},{0,68},{0,53},{2,1},{0,83},{2,1},{0,69},{2,1},{0,84},\r
+ {0,85},\r
+ };\r
+ \r
+ private static int ValTab9[][] = {\r
+ {8,1},{4,1},{2,1},{0,0},{0,16},{2,1},{0,1},{0,17},{10,1},{4,1},\r
+ {2,1},{0,32},{0,33},{2,1},{0,18},{2,1},{0,2},{0,34},{12,1},{6,1},\r
+ {4,1},{2,1},{0,48},{0,3},{0,49},{2,1},{0,19},{2,1},{0,50},{0,35},\r
+ {12,1},{4,1},{2,1},{0,65},{0,20},{4,1},{2,1},{0,64},{0,51},{2,1},\r
+ {0,66},{0,36},{10,1},{6,1},{4,1},{2,1},{0,4},{0,80},{0,67},{2,1},\r
+ {0,52},{0,81},{8,1},{4,1},{2,1},{0,21},{0,82},{2,1},{0,37},{0,68},\r
+ {6,1},{4,1},{2,1},{0,5},{0,84},{0,83},{2,1},{0,53},{2,1},{0,69},\r
+ {0,85},\r
+ };\r
+ \r
+ private static int ValTab10[][] = {\r
+ {2,1},{0,0},{4,1},{2,1},{0,16},{0,1},{10,1},{2,1},{0,17},{4,1},\r
+ {2,1},{0,32},{0,2},{2,1},{0,33},{0,18},{28,1},{8,1},{4,1},{2,1},\r
+ {0,34},{0,48},{2,1},{0,49},{0,19},{8,1},{4,1},{2,1},{0,3},{0,50},\r
+ {2,1},{0,35},{0,64},{4,1},{2,1},{0,65},{0,20},{4,1},{2,1},{0,4},\r
+ {0,51},{2,1},{0,66},{0,36},{28,1},{10,1},{6,1},{4,1},{2,1},{0,80},\r
+ {0,5},{0,96},{2,1},{0,97},{0,22},{12,1},{6,1},{4,1},{2,1},{0,67},\r
+ {0,52},{0,81},{2,1},{0,21},{2,1},{0,82},{0,37},{4,1},{2,1},{0,38},\r
+ {0,54},{0,113},{20,1},{8,1},{2,1},{0,23},{4,1},{2,1},{0,68},{0,83},\r
+ {0,6},{6,1},{4,1},{2,1},{0,53},{0,69},{0,98},{2,1},{0,112},{2,1},\r
+ {0,7},{0,100},{14,1},{4,1},{2,1},{0,114},{0,39},{6,1},{2,1},{0,99},\r
+ {2,1},{0,84},{0,85},{2,1},{0,70},{0,115},{8,1},{4,1},{2,1},{0,55},\r
+ {0,101},{2,1},{0,86},{0,116},{6,1},{2,1},{0,71},{2,1},{0,102},{0,117},\r
+ {4,1},{2,1},{0,87},{0,118},{2,1},{0,103},{0,119},\r
+ };\r
+\r
+ private static int ValTab11[][] = {\r
+ {6,1},{2,1},{0,0},{2,1},{0,16},{0,1},{8,1},{2,1},{0,17},{4,1},\r
+ {2,1},{0,32},{0,2},{0,18},{24,1},{8,1},{2,1},{0,33},{2,1},{0,34},\r
+ {2,1},{0,48},{0,3},{4,1},{2,1},{0,49},{0,19},{4,1},{2,1},{0,50},\r
+ {0,35},{4,1},{2,1},{0,64},{0,4},{2,1},{0,65},{0,20},{30,1},{16,1},\r
+ {10,1},{4,1},{2,1},{0,66},{0,36},{4,1},{2,1},{0,51},{0,67},{0,80},\r
+ {4,1},{2,1},{0,52},{0,81},{0,97},{6,1},{2,1},{0,22},{2,1},{0,6},\r
+ {0,38},{2,1},{0,98},{2,1},{0,21},{2,1},{0,5},{0,82},{16,1},{10,1},\r
+ {6,1},{4,1},{2,1},{0,37},{0,68},{0,96},{2,1},{0,99},{0,54},{4,1},\r
+ {2,1},{0,112},{0,23},{0,113},{16,1},{6,1},{4,1},{2,1},{0,7},{0,100},\r
+ {0,114},{2,1},{0,39},{4,1},{2,1},{0,83},{0,53},{2,1},{0,84},{0,69},\r
+ {10,1},{4,1},{2,1},{0,70},{0,115},{2,1},{0,55},{2,1},{0,101},{0,86},\r
+ {10,1},{6,1},{4,1},{2,1},{0,85},{0,87},{0,116},{2,1},{0,71},{0,102},\r
+ {4,1},{2,1},{0,117},{0,118},{2,1},{0,103},{0,119},\r
+ };\r
+\r
+ private static int ValTab12[][] = {\r
+ {12,1},{4,1},{2,1},{0,16},{0,1},{2,1},{0,17},{2,1},{0,0},{2,1},\r
+ {0,32},{0,2},{16,1},{4,1},{2,1},{0,33},{0,18},{4,1},{2,1},{0,34},\r
+ {0,49},{2,1},{0,19},{2,1},{0,48},{2,1},{0,3},{0,64},{26,1},{8,1},\r
+ {4,1},{2,1},{0,50},{0,35},{2,1},{0,65},{0,51},{10,1},{4,1},{2,1},\r
+ {0,20},{0,66},{2,1},{0,36},{2,1},{0,4},{0,80},{4,1},{2,1},{0,67},\r
+ {0,52},{2,1},{0,81},{0,21},{28,1},{14,1},{8,1},{4,1},{2,1},{0,82},\r
+ {0,37},{2,1},{0,83},{0,53},{4,1},{2,1},{0,96},{0,22},{0,97},{4,1},\r
+ {2,1},{0,98},{0,38},{6,1},{4,1},{2,1},{0,5},{0,6},{0,68},{2,1},\r
+ {0,84},{0,69},{18,1},{10,1},{4,1},{2,1},{0,99},{0,54},{4,1},{2,1},\r
+ {0,112},{0,7},{0,113},{4,1},{2,1},{0,23},{0,100},{2,1},{0,70},{0,114},\r
+ {10,1},{6,1},{2,1},{0,39},{2,1},{0,85},{0,115},{2,1},{0,55},{0,86},\r
+ {8,1},{4,1},{2,1},{0,101},{0,116},{2,1},{0,71},{0,102},{4,1},{2,1},\r
+ {0,117},{0,87},{2,1},{0,118},{2,1},{0,103},{0,119},\r
+ };\r
+\r
+ private static int ValTab13[][] = {\r
+ {2,1},{0,0},{6,1},{2,1},{0,16},{2,1},{0,1},{0,17},{28,1},{8,1},\r
+ {4,1},{2,1},{0,32},{0,2},{2,1},{0,33},{0,18},{8,1},{4,1},{2,1},\r
+ {0,34},{0,48},{2,1},{0,3},{0,49},{6,1},{2,1},{0,19},{2,1},{0,50},\r
+ {0,35},{4,1},{2,1},{0,64},{0,4},{0,65},{70,1},{28,1},{14,1},{6,1},\r
+ {2,1},{0,20},{2,1},{0,51},{0,66},{4,1},{2,1},{0,36},{0,80},{2,1},\r
+ {0,67},{0,52},{4,1},{2,1},{0,81},{0,21},{4,1},{2,1},{0,5},{0,82},\r
+ {2,1},{0,37},{2,1},{0,68},{0,83},{14,1},{8,1},{4,1},{2,1},{0,96},\r
+ {0,6},{2,1},{0,97},{0,22},{4,1},{2,1},{0,128},{0,8},{0,129},{16,1},\r
+ {8,1},{4,1},{2,1},{0,53},{0,98},{2,1},{0,38},{0,84},{4,1},{2,1},\r
+ {0,69},{0,99},{2,1},{0,54},{0,112},{6,1},{4,1},{2,1},{0,7},{0,85},\r
+ {0,113},{2,1},{0,23},{2,1},{0,39},{0,55},{72,1},{24,1},{12,1},{4,1},\r
+ {2,1},{0,24},{0,130},{2,1},{0,40},{4,1},{2,1},{0,100},{0,70},{0,114},\r
+ {8,1},{4,1},{2,1},{0,132},{0,72},{2,1},{0,144},{0,9},{2,1},{0,145},\r
+ {0,25},{24,1},{14,1},{8,1},{4,1},{2,1},{0,115},{0,101},{2,1},{0,86},\r
+ {0,116},{4,1},{2,1},{0,71},{0,102},{0,131},{6,1},{2,1},{0,56},{2,1},\r
+ {0,117},{0,87},{2,1},{0,146},{0,41},{14,1},{8,1},{4,1},{2,1},{0,103},\r
+ {0,133},{2,1},{0,88},{0,57},{2,1},{0,147},{2,1},{0,73},{0,134},{6,1},\r
+ {2,1},{0,160},{2,1},{0,104},{0,10},{2,1},{0,161},{0,26},{68,1},{24,1},\r
+ {12,1},{4,1},{2,1},{0,162},{0,42},{4,1},{2,1},{0,149},{0,89},{2,1},\r
+ {0,163},{0,58},{8,1},{4,1},{2,1},{0,74},{0,150},{2,1},{0,176},{0,11},\r
+ {2,1},{0,177},{0,27},{20,1},{8,1},{2,1},{0,178},{4,1},{2,1},{0,118},\r
+ {0,119},{0,148},{6,1},{4,1},{2,1},{0,135},{0,120},{0,164},{4,1},{2,1},\r
+ {0,105},{0,165},{0,43},{12,1},{6,1},{4,1},{2,1},{0,90},{0,136},{0,179},\r
+ {2,1},{0,59},{2,1},{0,121},{0,166},{6,1},{4,1},{2,1},{0,106},{0,180},\r
+ {0,192},{4,1},{2,1},{0,12},{0,152},{0,193},{60,1},{22,1},{10,1},{6,1},\r
+ {2,1},{0,28},{2,1},{0,137},{0,181},{2,1},{0,91},{0,194},{4,1},{2,1},\r
+ {0,44},{0,60},{4,1},{2,1},{0,182},{0,107},{2,1},{0,196},{0,76},{16,1},\r
+ {8,1},{4,1},{2,1},{0,168},{0,138},{2,1},{0,208},{0,13},{2,1},{0,209},\r
+ {2,1},{0,75},{2,1},{0,151},{0,167},{12,1},{6,1},{2,1},{0,195},{2,1},\r
+ {0,122},{0,153},{4,1},{2,1},{0,197},{0,92},{0,183},{4,1},{2,1},{0,29},\r
+ {0,210},{2,1},{0,45},{2,1},{0,123},{0,211},{52,1},{28,1},{12,1},{4,1},\r
+ {2,1},{0,61},{0,198},{4,1},{2,1},{0,108},{0,169},{2,1},{0,154},{0,212},\r
+ {8,1},{4,1},{2,1},{0,184},{0,139},{2,1},{0,77},{0,199},{4,1},{2,1},\r
+ {0,124},{0,213},{2,1},{0,93},{0,224},{10,1},{4,1},{2,1},{0,225},{0,30},\r
+ {4,1},{2,1},{0,14},{0,46},{0,226},{8,1},{4,1},{2,1},{0,227},{0,109},\r
+ {2,1},{0,140},{0,228},{4,1},{2,1},{0,229},{0,186},{0,240},{38,1},{16,1},\r
+ {4,1},{2,1},{0,241},{0,31},{6,1},{4,1},{2,1},{0,170},{0,155},{0,185},\r
+ {2,1},{0,62},{2,1},{0,214},{0,200},{12,1},{6,1},{2,1},{0,78},{2,1},\r
+ {0,215},{0,125},{2,1},{0,171},{2,1},{0,94},{0,201},{6,1},{2,1},{0,15},\r
+ {2,1},{0,156},{0,110},{2,1},{0,242},{0,47},{32,1},{16,1},{6,1},{4,1},\r
+ {2,1},{0,216},{0,141},{0,63},{6,1},{2,1},{0,243},{2,1},{0,230},{0,202},\r
+ {2,1},{0,244},{0,79},{8,1},{4,1},{2,1},{0,187},{0,172},{2,1},{0,231},\r
+ {0,245},{4,1},{2,1},{0,217},{0,157},{2,1},{0,95},{0,232},{30,1},{12,1},\r
+ {6,1},{2,1},{0,111},{2,1},{0,246},{0,203},{4,1},{2,1},{0,188},{0,173},\r
+ {0,218},{8,1},{2,1},{0,247},{4,1},{2,1},{0,126},{0,127},{0,142},{6,1},\r
+ {4,1},{2,1},{0,158},{0,174},{0,204},{2,1},{0,248},{0,143},{18,1},{8,1},\r
+ {4,1},{2,1},{0,219},{0,189},{2,1},{0,234},{0,249},{4,1},{2,1},{0,159},\r
+ {0,235},{2,1},{0,190},{2,1},{0,205},{0,250},{14,1},{4,1},{2,1},{0,221},\r
+ {0,236},{6,1},{4,1},{2,1},{0,233},{0,175},{0,220},{2,1},{0,206},{0,251},\r
+ {8,1},{4,1},{2,1},{0,191},{0,222},{2,1},{0,207},{0,238},{4,1},{2,1},\r
+ {0,223},{0,239},{2,1},{0,255},{2,1},{0,237},{2,1},{0,253},{2,1},{0,252},\r
+ {0,254},\r
+ };\r
+\r
+ private static int ValTab14[][] = {\r
+ {0,0} // dummy\r
+ };\r
+\r
+ private static int ValTab15[][] = {\r
+ {16,1},{6,1},{2,1},{0,0},{2,1},{0,16},{0,1},{2,1},{0,17},{4,1},\r
+ {2,1},{0,32},{0,2},{2,1},{0,33},{0,18},{50,1},{16,1},{6,1},{2,1},\r
+ {0,34},{2,1},{0,48},{0,49},{6,1},{2,1},{0,19},{2,1},{0,3},{0,64},\r
+ {2,1},{0,50},{0,35},{14,1},{6,1},{4,1},{2,1},{0,4},{0,20},{0,65},\r
+ {4,1},{2,1},{0,51},{0,66},{2,1},{0,36},{0,67},{10,1},{6,1},{2,1},\r
+ {0,52},{2,1},{0,80},{0,5},{2,1},{0,81},{0,21},{4,1},{2,1},{0,82},\r
+ {0,37},{4,1},{2,1},{0,68},{0,83},{0,97},{90,1},{36,1},{18,1},{10,1},\r
+ {6,1},{2,1},{0,53},{2,1},{0,96},{0,6},{2,1},{0,22},{0,98},{4,1},\r
+ {2,1},{0,38},{0,84},{2,1},{0,69},{0,99},{10,1},{6,1},{2,1},{0,54},\r
+ {2,1},{0,112},{0,7},{2,1},{0,113},{0,85},{4,1},{2,1},{0,23},{0,100},\r
+ {2,1},{0,114},{0,39},{24,1},{16,1},{8,1},{4,1},{2,1},{0,70},{0,115},\r
+ {2,1},{0,55},{0,101},{4,1},{2,1},{0,86},{0,128},{2,1},{0,8},{0,116},\r
+ {4,1},{2,1},{0,129},{0,24},{2,1},{0,130},{0,40},{16,1},{8,1},{4,1},\r
+ {2,1},{0,71},{0,102},{2,1},{0,131},{0,56},{4,1},{2,1},{0,117},{0,87},\r
+ {2,1},{0,132},{0,72},{6,1},{4,1},{2,1},{0,144},{0,25},{0,145},{4,1},\r
+ {2,1},{0,146},{0,118},{2,1},{0,103},{0,41},{92,1},{36,1},{18,1},{10,1},\r
+ {4,1},{2,1},{0,133},{0,88},{4,1},{2,1},{0,9},{0,119},{0,147},{4,1},\r
+ {2,1},{0,57},{0,148},{2,1},{0,73},{0,134},{10,1},{6,1},{2,1},{0,104},\r
+ {2,1},{0,160},{0,10},{2,1},{0,161},{0,26},{4,1},{2,1},{0,162},{0,42},\r
+ {2,1},{0,149},{0,89},{26,1},{14,1},{6,1},{2,1},{0,163},{2,1},{0,58},\r
+ {0,135},{4,1},{2,1},{0,120},{0,164},{2,1},{0,74},{0,150},{6,1},{4,1},\r
+ {2,1},{0,105},{0,176},{0,177},{4,1},{2,1},{0,27},{0,165},{0,178},{14,1},\r
+ {8,1},{4,1},{2,1},{0,90},{0,43},{2,1},{0,136},{0,151},{2,1},{0,179},\r
+ {2,1},{0,121},{0,59},{8,1},{4,1},{2,1},{0,106},{0,180},{2,1},{0,75},\r
+ {0,193},{4,1},{2,1},{0,152},{0,137},{2,1},{0,28},{0,181},{80,1},{34,1},\r
+ {16,1},{6,1},{4,1},{2,1},{0,91},{0,44},{0,194},{6,1},{4,1},{2,1},\r
+ {0,11},{0,192},{0,166},{2,1},{0,167},{0,122},{10,1},{4,1},{2,1},{0,195},\r
+ {0,60},{4,1},{2,1},{0,12},{0,153},{0,182},{4,1},{2,1},{0,107},{0,196},\r
+ {2,1},{0,76},{0,168},{20,1},{10,1},{4,1},{2,1},{0,138},{0,197},{4,1},\r
+ {2,1},{0,208},{0,92},{0,209},{4,1},{2,1},{0,183},{0,123},{2,1},{0,29},\r
+ {2,1},{0,13},{0,45},{12,1},{4,1},{2,1},{0,210},{0,211},{4,1},{2,1},\r
+ {0,61},{0,198},{2,1},{0,108},{0,169},{6,1},{4,1},{2,1},{0,154},{0,184},\r
+ {0,212},{4,1},{2,1},{0,139},{0,77},{2,1},{0,199},{0,124},{68,1},{34,1},\r
+ {18,1},{10,1},{4,1},{2,1},{0,213},{0,93},{4,1},{2,1},{0,224},{0,14},\r
+ {0,225},{4,1},{2,1},{0,30},{0,226},{2,1},{0,170},{0,46},{8,1},{4,1},\r
+ {2,1},{0,185},{0,155},{2,1},{0,227},{0,214},{4,1},{2,1},{0,109},{0,62},\r
+ {2,1},{0,200},{0,140},{16,1},{8,1},{4,1},{2,1},{0,228},{0,78},{2,1},\r
+ {0,215},{0,125},{4,1},{2,1},{0,229},{0,186},{2,1},{0,171},{0,94},{8,1},\r
+ {4,1},{2,1},{0,201},{0,156},{2,1},{0,241},{0,31},{6,1},{4,1},{2,1},\r
+ {0,240},{0,110},{0,242},{2,1},{0,47},{0,230},{38,1},{18,1},{8,1},{4,1},\r
+ {2,1},{0,216},{0,243},{2,1},{0,63},{0,244},{6,1},{2,1},{0,79},{2,1},\r
+ {0,141},{0,217},{2,1},{0,187},{0,202},{8,1},{4,1},{2,1},{0,172},{0,231},\r
+ {2,1},{0,126},{0,245},{8,1},{4,1},{2,1},{0,157},{0,95},{2,1},{0,232},\r
+ {0,142},{2,1},{0,246},{0,203},{34,1},{18,1},{10,1},{6,1},{4,1},{2,1},\r
+ {0,15},{0,174},{0,111},{2,1},{0,188},{0,218},{4,1},{2,1},{0,173},{0,247},\r
+ {2,1},{0,127},{0,233},{8,1},{4,1},{2,1},{0,158},{0,204},{2,1},{0,248},\r
+ {0,143},{4,1},{2,1},{0,219},{0,189},{2,1},{0,234},{0,249},{16,1},{8,1},\r
+ {4,1},{2,1},{0,159},{0,220},{2,1},{0,205},{0,235},{4,1},{2,1},{0,190},\r
+ {0,250},{2,1},{0,175},{0,221},{14,1},{6,1},{4,1},{2,1},{0,236},{0,206},\r
+ {0,251},{4,1},{2,1},{0,191},{0,237},{2,1},{0,222},{0,252},{6,1},{4,1},\r
+ {2,1},{0,207},{0,253},{0,238},{4,1},{2,1},{0,223},{0,254},{2,1},{0,239},\r
+ {0,255},\r
+ };\r
+\r
+ private static int ValTab16[][] = {\r
+ {2,1},{0,0},{6,1},{2,1},{0,16},{2,1},{0,1},{0,17},{42,1},{8,1},\r
+ {4,1},{2,1},{0,32},{0,2},{2,1},{0,33},{0,18},{10,1},{6,1},{2,1},\r
+ {0,34},{2,1},{0,48},{0,3},{2,1},{0,49},{0,19},{10,1},{4,1},{2,1},\r
+ {0,50},{0,35},{4,1},{2,1},{0,64},{0,4},{0,65},{6,1},{2,1},{0,20},\r
+ {2,1},{0,51},{0,66},{4,1},{2,1},{0,36},{0,80},{2,1},{0,67},{0,52},\r
+ {138,1},{40,1},{16,1},{6,1},{4,1},{2,1},{0,5},{0,21},{0,81},{4,1},\r
+ {2,1},{0,82},{0,37},{4,1},{2,1},{0,68},{0,53},{0,83},{10,1},{6,1},\r
+ {4,1},{2,1},{0,96},{0,6},{0,97},{2,1},{0,22},{0,98},{8,1},{4,1},\r
+ {2,1},{0,38},{0,84},{2,1},{0,69},{0,99},{4,1},{2,1},{0,54},{0,112},\r
+ {0,113},{40,1},{18,1},{8,1},{2,1},{0,23},{2,1},{0,7},{2,1},{0,85},\r
+ {0,100},{4,1},{2,1},{0,114},{0,39},{4,1},{2,1},{0,70},{0,101},{0,115},\r
+ {10,1},{6,1},{2,1},{0,55},{2,1},{0,86},{0,8},{2,1},{0,128},{0,129},\r
+ {6,1},{2,1},{0,24},{2,1},{0,116},{0,71},{2,1},{0,130},{2,1},{0,40},\r
+ {0,102},{24,1},{14,1},{8,1},{4,1},{2,1},{0,131},{0,56},{2,1},{0,117},\r
+ {0,132},{4,1},{2,1},{0,72},{0,144},{0,145},{6,1},{2,1},{0,25},{2,1},\r
+ {0,9},{0,118},{2,1},{0,146},{0,41},{14,1},{8,1},{4,1},{2,1},{0,133},\r
+ {0,88},{2,1},{0,147},{0,57},{4,1},{2,1},{0,160},{0,10},{0,26},{8,1},\r
+ {2,1},{0,162},{2,1},{0,103},{2,1},{0,87},{0,73},{6,1},{2,1},{0,148},\r
+ {2,1},{0,119},{0,134},{2,1},{0,161},{2,1},{0,104},{0,149},{220,1},{126,1},\r
+ {50,1},{26,1},{12,1},{6,1},{2,1},{0,42},{2,1},{0,89},{0,58},{2,1},\r
+ {0,163},{2,1},{0,135},{0,120},{8,1},{4,1},{2,1},{0,164},{0,74},{2,1},\r
+ {0,150},{0,105},{4,1},{2,1},{0,176},{0,11},{0,177},{10,1},{4,1},{2,1},\r
+ {0,27},{0,178},{2,1},{0,43},{2,1},{0,165},{0,90},{6,1},{2,1},{0,179},\r
+ {2,1},{0,166},{0,106},{4,1},{2,1},{0,180},{0,75},{2,1},{0,12},{0,193},\r
+ {30,1},{14,1},{6,1},{4,1},{2,1},{0,181},{0,194},{0,44},{4,1},{2,1},\r
+ {0,167},{0,195},{2,1},{0,107},{0,196},{8,1},{2,1},{0,29},{4,1},{2,1},\r
+ {0,136},{0,151},{0,59},{4,1},{2,1},{0,209},{0,210},{2,1},{0,45},{0,211},\r
+ {18,1},{6,1},{4,1},{2,1},{0,30},{0,46},{0,226},{6,1},{4,1},{2,1},\r
+ {0,121},{0,152},{0,192},{2,1},{0,28},{2,1},{0,137},{0,91},{14,1},{6,1},\r
+ {2,1},{0,60},{2,1},{0,122},{0,182},{4,1},{2,1},{0,76},{0,153},{2,1},\r
+ {0,168},{0,138},{6,1},{2,1},{0,13},{2,1},{0,197},{0,92},{4,1},{2,1},\r
+ {0,61},{0,198},{2,1},{0,108},{0,154},{88,1},{86,1},{36,1},{16,1},{8,1},\r
+ {4,1},{2,1},{0,139},{0,77},{2,1},{0,199},{0,124},{4,1},{2,1},{0,213},\r
+ {0,93},{2,1},{0,224},{0,14},{8,1},{2,1},{0,227},{4,1},{2,1},{0,208},\r
+ {0,183},{0,123},{6,1},{4,1},{2,1},{0,169},{0,184},{0,212},{2,1},{0,225},\r
+ {2,1},{0,170},{0,185},{24,1},{10,1},{6,1},{4,1},{2,1},{0,155},{0,214},\r
+ {0,109},{2,1},{0,62},{0,200},{6,1},{4,1},{2,1},{0,140},{0,228},{0,78},\r
+ {4,1},{2,1},{0,215},{0,229},{2,1},{0,186},{0,171},{12,1},{4,1},{2,1},\r
+ {0,156},{0,230},{4,1},{2,1},{0,110},{0,216},{2,1},{0,141},{0,187},{8,1},\r
+ {4,1},{2,1},{0,231},{0,157},{2,1},{0,232},{0,142},{4,1},{2,1},{0,203},\r
+ {0,188},{0,158},{0,241},{2,1},{0,31},{2,1},{0,15},{0,47},{66,1},{56,1},\r
+ {2,1},{0,242},{52,1},{50,1},{20,1},{8,1},{2,1},{0,189},{2,1},{0,94},\r
+ {2,1},{0,125},{0,201},{6,1},{2,1},{0,202},{2,1},{0,172},{0,126},{4,1},\r
+ {2,1},{0,218},{0,173},{0,204},{10,1},{6,1},{2,1},{0,174},{2,1},{0,219},\r
+ {0,220},{2,1},{0,205},{0,190},{6,1},{4,1},{2,1},{0,235},{0,237},{0,238},\r
+ {6,1},{4,1},{2,1},{0,217},{0,234},{0,233},{2,1},{0,222},{4,1},{2,1},\r
+ {0,221},{0,236},{0,206},{0,63},{0,240},{4,1},{2,1},{0,243},{0,244},{2,1},\r
+ {0,79},{2,1},{0,245},{0,95},{10,1},{2,1},{0,255},{4,1},{2,1},{0,246},\r
+ {0,111},{2,1},{0,247},{0,127},{12,1},{6,1},{2,1},{0,143},{2,1},{0,248},\r
+ {0,249},{4,1},{2,1},{0,159},{0,250},{0,175},{8,1},{4,1},{2,1},{0,251},\r
+ {0,191},{2,1},{0,252},{0,207},{4,1},{2,1},{0,253},{0,223},{2,1},{0,254},\r
+ {0,239},\r
+ };\r
+ \r
+ private static int ValTab24[][] = {\r
+ {60,1},{8,1},{4,1},{2,1},{0,0},{0,16},{2,1},{0,1},{0,17},{14,1},\r
+ {6,1},{4,1},{2,1},{0,32},{0,2},{0,33},{2,1},{0,18},{2,1},{0,34},\r
+ {2,1},{0,48},{0,3},{14,1},{4,1},{2,1},{0,49},{0,19},{4,1},{2,1},\r
+ {0,50},{0,35},{4,1},{2,1},{0,64},{0,4},{0,65},{8,1},{4,1},{2,1},\r
+ {0,20},{0,51},{2,1},{0,66},{0,36},{6,1},{4,1},{2,1},{0,67},{0,52},\r
+ {0,81},{6,1},{4,1},{2,1},{0,80},{0,5},{0,21},{2,1},{0,82},{0,37},\r
+ {250,1},{98,1},{34,1},{18,1},{10,1},{4,1},{2,1},{0,68},{0,83},{2,1},\r
+ {0,53},{2,1},{0,96},{0,6},{4,1},{2,1},{0,97},{0,22},{2,1},{0,98},\r
+ {0,38},{8,1},{4,1},{2,1},{0,84},{0,69},{2,1},{0,99},{0,54},{4,1},\r
+ {2,1},{0,113},{0,85},{2,1},{0,100},{0,70},{32,1},{14,1},{6,1},{2,1},\r
+ {0,114},{2,1},{0,39},{0,55},{2,1},{0,115},{4,1},{2,1},{0,112},{0,7},\r
+ {0,23},{10,1},{4,1},{2,1},{0,101},{0,86},{4,1},{2,1},{0,128},{0,8},\r
+ {0,129},{4,1},{2,1},{0,116},{0,71},{2,1},{0,24},{0,130},{16,1},{8,1},\r
+ {4,1},{2,1},{0,40},{0,102},{2,1},{0,131},{0,56},{4,1},{2,1},{0,117},\r
+ {0,87},{2,1},{0,132},{0,72},{8,1},{4,1},{2,1},{0,145},{0,25},{2,1},\r
+ {0,146},{0,118},{4,1},{2,1},{0,103},{0,41},{2,1},{0,133},{0,88},{92,1},\r
+ {34,1},{16,1},{8,1},{4,1},{2,1},{0,147},{0,57},{2,1},{0,148},{0,73},\r
+ {4,1},{2,1},{0,119},{0,134},{2,1},{0,104},{0,161},{8,1},{4,1},{2,1},\r
+ {0,162},{0,42},{2,1},{0,149},{0,89},{4,1},{2,1},{0,163},{0,58},{2,1},\r
+ {0,135},{2,1},{0,120},{0,74},{22,1},{12,1},{4,1},{2,1},{0,164},{0,150},\r
+ {4,1},{2,1},{0,105},{0,177},{2,1},{0,27},{0,165},{6,1},{2,1},{0,178},\r
+ {2,1},{0,90},{0,43},{2,1},{0,136},{0,179},{16,1},{10,1},{6,1},{2,1},\r
+ {0,144},{2,1},{0,9},{0,160},{2,1},{0,151},{0,121},{4,1},{2,1},{0,166},\r
+ {0,106},{0,180},{12,1},{6,1},{2,1},{0,26},{2,1},{0,10},{0,176},{2,1},\r
+ {0,59},{2,1},{0,11},{0,192},{4,1},{2,1},{0,75},{0,193},{2,1},{0,152},\r
+ {0,137},{67,1},{34,1},{16,1},{8,1},{4,1},{2,1},{0,28},{0,181},{2,1},\r
+ {0,91},{0,194},{4,1},{2,1},{0,44},{0,167},{2,1},{0,122},{0,195},{10,1},\r
+ {6,1},{2,1},{0,60},{2,1},{0,12},{0,208},{2,1},{0,182},{0,107},{4,1},\r
+ {2,1},{0,196},{0,76},{2,1},{0,153},{0,168},{16,1},{8,1},{4,1},{2,1},\r
+ {0,138},{0,197},{2,1},{0,92},{0,209},{4,1},{2,1},{0,183},{0,123},{2,1},\r
+ {0,29},{0,210},{9,1},{4,1},{2,1},{0,45},{0,211},{2,1},{0,61},{0,198},\r
+ {85,250},{4,1},{2,1},{0,108},{0,169},{2,1},{0,154},{0,212},{32,1},{16,1},\r
+ {8,1},{4,1},{2,1},{0,184},{0,139},{2,1},{0,77},{0,199},{4,1},{2,1},\r
+ {0,124},{0,213},{2,1},{0,93},{0,225},{8,1},{4,1},{2,1},{0,30},{0,226},\r
+ {2,1},{0,170},{0,185},{4,1},{2,1},{0,155},{0,227},{2,1},{0,214},{0,109},\r
+ {20,1},{10,1},{6,1},{2,1},{0,62},{2,1},{0,46},{0,78},{2,1},{0,200},\r
+ {0,140},{4,1},{2,1},{0,228},{0,215},{4,1},{2,1},{0,125},{0,171},{0,229},\r
+ {10,1},{4,1},{2,1},{0,186},{0,94},{2,1},{0,201},{2,1},{0,156},{0,110},\r
+ {8,1},{2,1},{0,230},{2,1},{0,13},{2,1},{0,224},{0,14},{4,1},{2,1},\r
+ {0,216},{0,141},{2,1},{0,187},{0,202},{74,1},{2,1},{0,255},{64,1},{58,1},\r
+ {32,1},{16,1},{8,1},{4,1},{2,1},{0,172},{0,231},{2,1},{0,126},{0,217},\r
+ {4,1},{2,1},{0,157},{0,232},{2,1},{0,142},{0,203},{8,1},{4,1},{2,1},\r
+ {0,188},{0,218},{2,1},{0,173},{0,233},{4,1},{2,1},{0,158},{0,204},{2,1},\r
+ {0,219},{0,189},{16,1},{8,1},{4,1},{2,1},{0,234},{0,174},{2,1},{0,220},\r
+ {0,205},{4,1},{2,1},{0,235},{0,190},{2,1},{0,221},{0,236},{8,1},{4,1},\r
+ {2,1},{0,206},{0,237},{2,1},{0,222},{0,238},{0,15},{4,1},{2,1},{0,240},\r
+ {0,31},{0,241},{4,1},{2,1},{0,242},{0,47},{2,1},{0,243},{0,63},{18,1},\r
+ {8,1},{4,1},{2,1},{0,244},{0,79},{2,1},{0,245},{0,95},{4,1},{2,1},\r
+ {0,246},{0,111},{2,1},{0,247},{2,1},{0,127},{0,143},{10,1},{4,1},{2,1},\r
+ {0,248},{0,249},{4,1},{2,1},{0,159},{0,175},{0,250},{8,1},{4,1},{2,1},\r
+ {0,251},{0,191},{2,1},{0,252},{0,207},{4,1},{2,1},{0,253},{0,223},{2,1},\r
+ {0,254},{0,239},\r
+ };\r
+ \r
+ private static int ValTab32[][] = {\r
+ {2,1},{0,0},{8,1},{4,1},{2,1},{0,8},{0,4},{2,1},{0,1},{0,2},\r
+ {8,1},{4,1},{2,1},{0,12},{0,10},{2,1},{0,3},{0,6},{6,1},{2,1},\r
+ {0,9},{2,1},{0,5},{0,7},{4,1},{2,1},{0,14},{0,13},{2,1},{0,15},\r
+ {0,11},\r
+ };\r
+\r
+ private static int ValTab33[][] = {\r
+ {16,1},{8,1},{4,1},{2,1},{0,0},{0,1},{2,1},{0,2},{0,3},{4,1},\r
+ {2,1},{0,4},{0,5},{2,1},{0,6},{0,7},{8,1},{4,1},{2,1},{0,8},\r
+ {0,9},{2,1},{0,10},{0,11},{4,1},{2,1},{0,12},{0,13},{2,1},{0,14},\r
+ {0,15},\r
+ };\r
+\r
+\r
+ public static huffcodetab[] ht = null; /* Simulate extern struct */\r
+\r
+ private static int[] bitbuf = new int[32];\r
+ \r
+ /**\r
+ * Big Constructor : Computes all Huffman Tables.\r
+ */\r
+ private huffcodetab(String S,int XLEN, int YLEN, int LINBITS, int LINMAX, int REF,\r
+ int[] TABLE, int[] HLEN, int[][] VAL, int TREELEN) \r
+ {\r
+ tablename0 = S.charAt(0);\r
+ tablename1 = S.charAt(1);\r
+ tablename2 = S.charAt(2);\r
+ xlen = XLEN;\r
+ ylen = YLEN;\r
+ linbits = LINBITS;\r
+ linmax = LINMAX;\r
+ ref = REF;\r
+ table = TABLE;\r
+ hlen = HLEN;\r
+ val = VAL;\r
+ treelen = TREELEN;\r
+ }\r
+\r
+ \r
+ \r
+ /**\r
+ * Do the huffman-decoding.\r
+ * note! for counta,countb -the 4 bit value is returned in y,\r
+ * discard x.\r
+ */\r
+ public static int huffman_decoder(huffcodetab h, int[] x, int[] y, int[] v, int[] w, BitReserve br)\r
+ {\r
+ // array of all huffcodtable headers\r
+ // 0..31 Huffman code table 0..31\r
+ // 32,33 count1-tables\r
+\r
+ int dmask = 1 << ((4 * 8) - 1);\r
+ int hs = 4 * 8;\r
+ int level;\r
+ int point = 0;\r
+ int error = 1;\r
+ level = dmask;\r
+\r
+ if (h.val == null) return 2;\r
+\r
+ /* table 0 needs no bits */\r
+ if ( h.treelen == 0)\r
+ { \r
+ x[0] = y[0] = 0;\r
+ return 0;\r
+ }\r
+\r
+ /* Lookup in Huffman table. */\r
+\r
+ /*int bitsAvailable = 0; \r
+ int bitIndex = 0;\r
+ \r
+ int bits[] = bitbuf;*/\r
+ do \r
+ {\r
+ if (h.val[point][0]==0)\r
+ { /*end of tree*/\r
+ x[0] = h.val[point][1] >>> 4;\r
+ y[0] = h.val[point][1] & 0xf;\r
+ error = 0;\r
+ break;\r
+ }\r
+ \r
+ // hget1bit() is called thousands of times, and so needs to be\r
+ // ultra fast. \r
+ /*\r
+ if (bitIndex==bitsAvailable)\r
+ {\r
+ bitsAvailable = br.readBits(bits, 32); \r
+ bitIndex = 0;\r
+ }\r
+ */\r
+ //if (bits[bitIndex++]!=0)\r
+ if (br.hget1bit()!=0)\r
+ {\r
+ while (h.val[point][1] >= MXOFF) point += h.val[point][1];\r
+ point += h.val[point][1];\r
+ }\r
+ else\r
+ {\r
+ while (h.val[point][0] >= MXOFF) point += h.val[point][0];\r
+ point += h.val[point][0];\r
+ }\r
+ level >>>= 1;\r
+ // MDM: ht[0] is always 0;\r
+ } while ((level !=0 ) || (point < 0 /*ht[0].treelen*/) );\r
+ \r
+ // put back any bits not consumed\r
+ /* \r
+ int unread = (bitsAvailable-bitIndex);\r
+ if (unread>0)\r
+ br.rewindNbits(unread);\r
+ */\r
+ /* Process sign encodings for quadruples tables. */\r
+ // System.out.println(h.tablename);\r
+ if (h.tablename0 == '3' && (h.tablename1 == '2' || h.tablename1 == '3'))\r
+ {\r
+ v[0] = (y[0]>>3) & 1;\r
+ w[0] = (y[0]>>2) & 1;\r
+ x[0] = (y[0]>>1) & 1;\r
+ y[0] = y[0] & 1;\r
+\r
+ /* v, w, x and y are reversed in the bitstream.\r
+ switch them around to make test bistream work. */\r
+\r
+ if (v[0]!=0)\r
+ if (br.hget1bit() != 0) v[0] = -v[0];\r
+ if (w[0]!=0)\r
+ if (br.hget1bit() != 0) w[0] = -w[0];\r
+ if (x[0]!=0)\r
+ if (br.hget1bit() != 0) x[0] = -x[0];\r
+ if (y[0]!=0)\r
+ if (br.hget1bit() != 0) y[0] = -y[0];\r
+ }\r
+ else\r
+ {\r
+ // Process sign and escape encodings for dual tables.\r
+ // x and y are reversed in the test bitstream.\r
+ // Reverse x and y here to make test bitstream work.\r
+\r
+ if (h.linbits != 0)\r
+ if ((h.xlen-1) == x[0])\r
+ x[0] += br.hgetbits(h.linbits);\r
+ if (x[0] != 0)\r
+ if (br.hget1bit() != 0) x[0] = -x[0];\r
+ if (h.linbits != 0)\r
+ if ((h.ylen-1) == y[0])\r
+ y[0] += br.hgetbits(h.linbits);\r
+ if (y[0] != 0)\r
+ if (br.hget1bit() != 0) y[0] = -y[0];\r
+ }\r
+ return error;\r
+ }\r
+\r
+ public static void inithuff()\r
+ {\r
+ \r
+ if (ht!=null)\r
+ return;\r
+ \r
+ ht = new huffcodetab[HTN];\r
+ ht[0] = new huffcodetab("0 ",0,0,0,0,-1,null,null,ValTab0,0);\r
+ ht[1] = new huffcodetab("1 ",2,2,0,0,-1,null,null,ValTab1,7);\r
+ ht[2] = new huffcodetab("2 ",3,3,0,0,-1,null,null,ValTab2,17);\r
+ ht[3] = new huffcodetab("3 ",3,3,0,0,-1,null,null,ValTab3,17);\r
+ ht[4] = new huffcodetab("4 ",0,0,0,0,-1,null,null,ValTab4,0); \r
+ ht[5] = new huffcodetab("5 ",4,4,0,0,-1,null,null,ValTab5,31);\r
+ ht[6] = new huffcodetab("6 ",4,4,0,0,-1,null,null,ValTab6,31);\r
+ ht[7] = new huffcodetab("7 ",6,6,0,0,-1,null,null,ValTab7,71);\r
+ ht[8] = new huffcodetab("8 ",6,6,0,0,-1,null,null,ValTab8,71);\r
+ ht[9] = new huffcodetab("9 ",6,6,0,0,-1,null,null,ValTab9,71);\r
+ ht[10] = new huffcodetab("10 ",8,8,0,0,-1,null,null,ValTab10,127); \r
+ ht[11] = new huffcodetab("11 ",8,8,0,0,-1,null,null,ValTab11,127);\r
+ ht[12] = new huffcodetab("12 ",8,8,0,0,-1,null,null,ValTab12,127);\r
+ ht[13] = new huffcodetab("13 ",16,16,0,0,-1,null,null,ValTab13,511);\r
+ ht[14] = new huffcodetab("14 ",0,0,0,0,-1,null,null,ValTab14,0);\r
+ ht[15] = new huffcodetab("15 ",16,16,0,0,-1,null,null,ValTab15,511);\r
+ ht[16] = new huffcodetab("16 ",16,16,1,1,-1,null,null,ValTab16,511);\r
+ ht[17] = new huffcodetab("17 ",16,16,2,3,16,null,null,ValTab16,511);\r
+ ht[18] = new huffcodetab("18 ",16,16,3,7,16,null,null,ValTab16,511);\r
+ ht[19] = new huffcodetab("19 ",16,16,4,15,16,null,null,ValTab16,511);\r
+ ht[20] = new huffcodetab("20 ",16,16,6,63,16,null,null,ValTab16,511);\r
+ ht[21] = new huffcodetab("21 ",16,16,8,255,16,null,null,ValTab16,511);\r
+ ht[22] = new huffcodetab("22 ",16,16,10,1023,16,null,null,ValTab16,511);\r
+ ht[23] = new huffcodetab("23 ",16,16,13,8191,16,null,null,ValTab16,511);\r
+ ht[24] = new huffcodetab("24 ",16,16,4,15,-1,null,null,ValTab24,512);\r
+ ht[25] = new huffcodetab("25 ",16,16,5,31,24,null,null,ValTab24,512);\r
+ ht[26] = new huffcodetab("26 ",16,16,6,63,24,null,null,ValTab24,512);\r
+ ht[27] = new huffcodetab("27 ",16,16,7,127,24,null,null,ValTab24,512);\r
+ ht[28] = new huffcodetab("28 ",16,16,8,255,24,null,null,ValTab24,512); \r
+ ht[29] = new huffcodetab("29 ",16,16,9,511,24,null,null,ValTab24,512);\r
+ ht[30] = new huffcodetab("30 ",16,16,11,2047,24,null,null,ValTab24,512);\r
+ ht[31] = new huffcodetab("31 ",16,16,13,8191,24,null,null,ValTab24,512);\r
+ ht[32] = new huffcodetab("32 ",1,16,0,0,-1,null,null,ValTab32,31);\r
+ ht[33] = new huffcodetab("33 ",1,16,0,0,-1,null,null,ValTab33,31);\r
+ }\r
+}\r