Package davaguine.jmac.tools

Examples of davaguine.jmac.tools.JMACException


        //get the number of samples in the frame
        int nBlocks = 0;
        nBlocks = ((FrameIndex + 1) >= m_pAPEDecompress.getApeInfoTotalFrames()) ? m_pAPEDecompress.getApeInfoFinalFrameBlocks() : m_pAPEDecompress.getApeInfoBlocksPerFrame();
        if (nBlocks == 0)
            throw new JMACException("Invalid Frame Index"); //nothing to do (file must be zero length) (have to return error)

        //take care of seeking and frame alignment
        SeekToFrame(FrameIndex);

        //get the checksum
        long nSpecialCodes = 0;
        long nStoredCRC = 0;

        if ((m_pAPEDecompress.getApeInfoFormatFlags() & APEHeader.MAC_FORMAT_FLAG_CRC) <= 0) {
            nStoredCRC = m_pAPEDecompressCore.GetUnBitArrray().DecodeValue(DecodeValueMethod.DECODE_VALUE_METHOD_UNSIGNED_RICE, 30);
            if (nStoredCRC == 0)
                nSpecialCodes = SpecialFrame.SPECIAL_FRAME_LEFT_SILENCE | SpecialFrame.SPECIAL_FRAME_RIGHT_SILENCE;
        } else {
            nStoredCRC = m_pAPEDecompressCore.GetUnBitArrray().DecodeValue(DecodeValueMethod.DECODE_VALUE_METHOD_UNSIGNED_INT);

            //get any 'special' codes if the file uses them (for silence, FALSE stereo, etc.)
            nSpecialCodes = 0;
            if (m_pAPEDecompress.getApeInfoFileVersion() > 3820) {
                if ((nStoredCRC & 0x80000000) > 0)
                    nSpecialCodes = m_pAPEDecompressCore.GetUnBitArrray().DecodeValue(DecodeValueMethod.DECODE_VALUE_METHOD_UNSIGNED_INT);
                nStoredCRC &= 0x7fffffff;
            }
        }

        //decompress and convert from (x,y) -> (l,r)
        //sort of int and ugly.... sorry
        if (m_pAPEDecompress.getApeInfoChannels() == 2) {
            m_pAPEDecompressCore.GenerateDecodedArrays(nBlocks, (int) nSpecialCodes, FrameIndex);

            m_pPrepare.unprepareOld(m_pAPEDecompressCore.m_pDataX, m_pAPEDecompressCore.m_pDataY, nBlocks, m_wfeInput,
                    pOutputData, CRC, m_pAPEDecompress.getApeInfoFileVersion());
        } else if (m_pAPEDecompress.getApeInfoChannels() == 1) {
            m_pAPEDecompressCore.GenerateDecodedArrays(nBlocks, (int) nSpecialCodes, FrameIndex);

            m_pPrepare.unprepareOld(m_pAPEDecompressCore.m_pDataX, null, nBlocks, m_wfeInput,
                    pOutputData, CRC, m_pAPEDecompress.getApeInfoFileVersion());
        }

        if (m_pAPEDecompress.getApeInfoFileVersion() > 3820)
            CRC.finalizeCrc();

        // check the CRC
        if ((m_pAPEDecompress.getApeInfoFormatFlags() & APEHeader.MAC_FORMAT_FLAG_CRC) <= 0) {
            long nChecksum = CalculateOldChecksum(m_pAPEDecompressCore.m_pDataX, m_pAPEDecompressCore.m_pDataY, m_pAPEDecompress.getApeInfoChannels(), nBlocks);
            if (nChecksum != nStoredCRC)
                throw new JMACException("Invalid Checksum");
        } else {
            if (CRC.getCrc() != nStoredCRC)
                throw new JMACException("Invalid Checksum");
        }

        m_LastDecodedFrameIndex = FrameIndex;
        return nBlocks;
    }
View Full Code Here


            tag.m_nSize = reader.readInt();
            tag.m_nFields = reader.readInt();
            tag.m_nFlags = reader.readInt();
            return tag;
        } catch (EOFException e) {
            throw new JMACException("Unsupported Format");
        }
    }
View Full Code Here

    public WAVInputSource(File pIO, WaveFormat pwfeSource, IntegerPointer pTotalBlocks, IntegerPointer pHeaderBytes, IntegerPointer pTerminatingBytes) throws IOException {
        super(pIO, pwfeSource, pTotalBlocks, pHeaderBytes, pTerminatingBytes);
        m_bIsValid = false;

        if (pIO == null || pwfeSource == null)
            throw new JMACException("Bad Parameters");

        m_spIO = pIO;
        m_bOwnsInputIO = false;

        AnalyzeSource();
View Full Code Here

    public WAVInputSource(String pSourceName, WaveFormat pwfeSource, IntegerPointer pTotalBlocks, IntegerPointer pHeaderBytes, IntegerPointer pTerminatingBytes) throws IOException {
        super(pSourceName, pwfeSource, pTotalBlocks, pHeaderBytes, pTerminatingBytes);
        m_bIsValid = false;

        if (pSourceName == null || pwfeSource == null)
            throw new JMACException("Bad Parameters");

        m_spIO = File.createFile(pSourceName, "r");
        m_bOwnsInputIO = true;

        AnalyzeSource();
View Full Code Here

    protected void finalize() {
        try {
            Close();
        } catch (IOException e) {
            throw new JMACException("Error while closing input stream.");
        }
    }
View Full Code Here

    }

    // get data
    public int GetData(ByteBuffer pBuffer, int nBlocks) throws IOException {
        if (!m_bIsValid)
            throw new JMACException("Undefined Error");

        int nBytes = (m_wfeSource.nBlockAlign * nBlocks);

        int nBytesRead = m_spIO.read(pBuffer.getBytes(), pBuffer.getIndex(), nBytes);

View Full Code Here

    }

    // get header / terminating data
    public void GetHeaderData(byte[] pBuffer) throws IOException {
        if (!m_bIsValid)
            throw new JMACException("Undefined Error");

        if (m_nHeaderBytes > 0) {
            long nOriginalFileLocation = m_spIO.getFilePointer();

            m_spIO.seek(0);

            if (m_spIO.read(pBuffer, 0, m_nHeaderBytes) != m_nHeaderBytes)
                throw new JMACException("Undefined Error");

            m_spIO.seek(nOriginalFileLocation);
        }
    }
View Full Code Here

        }
    }

    public void GetTerminatingData(byte[] pBuffer) throws IOException {
        if (!m_bIsValid)
            throw new JMACException("Undefined Error");

        if (m_nTerminatingBytes > 0) {
            long nOriginalFileLocation = m_spIO.getFilePointer();

            m_spIO.seek(m_spIO.length() - m_nTerminatingBytes);

            if (m_spIO.read(pBuffer, 0, m_nTerminatingBytes) != m_nTerminatingBytes)
                throw new JMACException("Undefined Error");

            m_spIO.seek(nOriginalFileLocation);
        }
    }
View Full Code Here

        // get the RIFF header
        int riffSignature = m_spIO.readInt();
        int goalSignature = ('R' << 24) | ('I' << 16) | ('F' << 8) | ('F');
        if (riffSignature != goalSignature)
            throw new JMACException("Invalid Input File");

        m_spIO.readInt();

        // read the data type header
        int dataTypeSignature = m_spIO.readInt();
        goalSignature = ('W' << 24) | ('A' << 16) | ('V' << 8) | ('E');
        // make sure it's the right data type
        if (dataTypeSignature != goalSignature)
            throw new JMACException("Invalid Input File");

        // find the 'fmt ' chunk
        RiffChunkHeader RIFFChunkHeader = new RiffChunkHeader();
        RIFFChunkHeader.read(m_spIO);
        goalSignature = (' ' << 24) | ('t' << 16) | ('m' << 8) | ('f');
        while (RIFFChunkHeader.cChunkLabel != goalSignature) {
            // move the file pointer to the end of this chunk
            m_spIO.seek(m_spIO.getFilePointer() + RIFFChunkHeader.nChunkBytes);

            // check again for the data chunk
            RIFFChunkHeader.read(m_spIO);
        }

        // read the format info
        WaveFormat WAVFormatHeader = new WaveFormat();
        WAVFormatHeader.readHeader(m_spIO);

        // error check the header to see if we support it
        if (WAVFormatHeader.wFormatTag != 1)
            throw new JMACException("Invalid Input File");

        // copy the format information to the WAVEFORMATEX passed in
        WaveFormat.FillWaveFormatEx(m_wfeSource, WAVFormatHeader.nSamplesPerSec, WAVFormatHeader.wBitsPerSample, WAVFormatHeader.nChannels);

        // skip over any extra data in the header
        int nWAVFormatHeaderExtra = (int) (RIFFChunkHeader.nChunkBytes - WaveFormat.WAV_HEADER_SIZE);
        if (nWAVFormatHeaderExtra < 0)
            throw new JMACException("Invalid Input File");
        else
            m_spIO.seek(m_spIO.getFilePointer() + nWAVFormatHeaderExtra);

        // find the data chunk
        RIFFChunkHeader.read(m_spIO);
        goalSignature = ('a' << 24) | ('t' << 16) | ('a' << 8) | ('d');

        while (RIFFChunkHeader.cChunkLabel != goalSignature) {
            // move the file pointer to the end of this chunk
            m_spIO.seek(m_spIO.getFilePointer() + RIFFChunkHeader.nChunkBytes);

            // check again for the data chunk
            RIFFChunkHeader.read(m_spIO);
        }

        // we're at the data block
        m_nHeaderBytes = (int) m_spIO.getFilePointer();
        m_nDataBytes = (int) RIFFChunkHeader.nChunkBytes;
        if (m_nDataBytes < 0)
            m_nDataBytes = m_nFileBytes - m_nHeaderBytes;

        // make sure the data bytes is a whole number of blocks
        if ((m_nDataBytes % m_wfeSource.nBlockAlign) != 0)
            throw new JMACException("Invalid Input File");

        // calculate the terminating byts
        m_nTerminatingBytes = m_nFileBytes - m_nDataBytes - m_nHeaderBytes;
    }
View Full Code Here

    public abstract void Close() throws IOException;

    public static InputSource CreateInputSource(String pSourceName, WaveFormat pwfeSource, IntegerPointer pTotalBlocks, IntegerPointer pHeaderBytes, IntegerPointer pTerminatingBytes) throws IOException {
        // error check the parameters
        if ((pSourceName == null) || (pSourceName.length() == 0))
            throw new JMACException("Bad Parameters");

        // get the extension
        int index = pSourceName.lastIndexOf('.');
        String pExtension = "";
        if (index >= 0)
            pExtension = pSourceName.substring(pSourceName.lastIndexOf('.'));

        // create the proper input source
        if (pExtension.toLowerCase().equals(".wav")) {
            return new WAVInputSource(pSourceName, pwfeSource, pTotalBlocks, pHeaderBytes, pTerminatingBytes);
        } else
            throw new JMACException("Invalid Input File");
    }
View Full Code Here

TOP

Related Classes of davaguine.jmac.tools.JMACException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.