Package davaguine.jmac.encoder

Examples of davaguine.jmac.encoder.IAPECompress


    }

    public static void DecompressCore(IAPEDecompress spAPEDecompress, String pOutputFilename, int nOutputMode, int nCompressionLevel, ProgressCallback progressor) throws IOException, JMACSkippedException, JMACStoppedByUserException {
        // variable declares
        java.io.RandomAccessFile spioOutput = null;
        IAPECompress spAPECompress = null;

        try {
            // create the core
            WaveFormat wfeInput = spAPEDecompress.getApeInfoWaveFormatEx();

            // allocate space for the header
            byte[] waveHeaderBuffer = spAPEDecompress.getApeInfoWavHeaderData(spAPEDecompress.getApeInfoWavHeaderBytes());

            // initialize the output
            if (nOutputMode == UNMAC_DECODER_OUTPUT_WAV) {
                // create the file
                spioOutput = new RandomAccessFile(pOutputFilename, "rw");

                // output the header
                spioOutput.write(waveHeaderBuffer);
            } else if (nOutputMode == UNMAC_DECODER_OUTPUT_APE) {
                // quit if there is nothing to do
                if (spAPEDecompress.getApeInfoFileVersion() == Globals.MAC_VERSION_NUMBER && spAPEDecompress.getApeInfoCompressionLevel() == nCompressionLevel)
                    throw new JMACSkippedException();

                // create and start the compressor
                spAPECompress = IAPECompress.CreateIAPECompress();
                spAPECompress.Start(pOutputFilename, wfeInput, spAPEDecompress.getApeInfoDecompressTotalBlocks() * spAPEDecompress.getApeInfoBlockAlign(),
                        nCompressionLevel, waveHeaderBuffer, spAPEDecompress.getApeInfoWavHeaderBytes());
            }

            int blockAlign = spAPEDecompress.getApeInfoBlockAlign();
            // allocate space for decompression
            byte[] spTempBuffer = new byte[blockAlign * BLOCKS_PER_DECODE];

            int nBlocksLeft = spAPEDecompress.getApeInfoDecompressTotalBlocks();

            // create the progress helper
            ProgressHelper spMACProgressHelper = new ProgressHelper(nBlocksLeft / BLOCKS_PER_DECODE, progressor);

            // main decoding loop
            while (nBlocksLeft > 0) {
                // decode data
                int nBlocksDecoded = spAPEDecompress.GetData(spTempBuffer, BLOCKS_PER_DECODE);

                // handle the output
                if (nOutputMode == UNMAC_DECODER_OUTPUT_WAV)
                    spioOutput.write(spTempBuffer, 0, nBlocksDecoded * blockAlign);
                else if (nOutputMode == UNMAC_DECODER_OUTPUT_APE)
                    spAPECompress.AddData(spTempBuffer, nBlocksDecoded * spAPEDecompress.getApeInfoBlockAlign());

                // update amount remaining
                nBlocksLeft -= nBlocksDecoded;

                // update progress and kill flag
                spMACProgressHelper.UpdateProgress();
                if (spMACProgressHelper.isKillFlag())
                    throw new JMACStoppedByUserException();
            }

            // terminate the output
            if (nOutputMode == UNMAC_DECODER_OUTPUT_WAV) {
                // write any terminating WAV data
                if (spAPEDecompress.getApeInfoWavTerminatingBytes() > 0) {
                    byte[] termData = spAPEDecompress.getApeInfoWavTerminatingData(spAPEDecompress.getApeInfoWavTerminatingBytes());

                    int nBytesToWrite = spAPEDecompress.getApeInfoWavTerminatingBytes();
                    spioOutput.write(termData, 0, nBytesToWrite);
                }
            } else if (nOutputMode == UNMAC_DECODER_OUTPUT_APE) {
                // write the WAV data and any tag
                int nTagBytes = spAPEDecompress.getApeInfoTag().GetTagBytes();
                boolean bHasTag = (nTagBytes > 0);
                int nTerminatingBytes = nTagBytes;
                nTerminatingBytes += spAPEDecompress.getApeInfoWavTerminatingBytes();

                if (nTerminatingBytes > 0) {
                    spTempBuffer = spAPEDecompress.getApeInfoWavTerminatingData(nTerminatingBytes);

                    if (bHasTag) {
                        spAPEDecompress.getApeInfoIoSource().seek(spAPEDecompress.getApeInfoIoSource().length() - nTagBytes);
                        spAPEDecompress.getApeInfoIoSource().read(spTempBuffer, spAPEDecompress.getApeInfoWavTerminatingBytes(), nTagBytes);
                    }

                    spAPECompress.Finish(spTempBuffer, nTerminatingBytes, spAPEDecompress.getApeInfoWavTerminatingBytes());
                } else
                    spAPECompress.Finish(null, 0, 0);
            }

            // fire the "complete" progress notification
            spMACProgressHelper.UpdateProgressComplete();
        } finally {
            if (spioOutput != null)
                spioOutput.close();
            if (spAPECompress != null)
                spAPECompress.Kill();
        }
    }
View Full Code Here


        }
    }

    public static void CompressFile(String pInputFilename, String pOutputFilename, int nCompressionLevel, ProgressCallback progressor) throws IOException, JMACStoppedByUserException {
        // declare the variables
        IAPECompress spAPECompress = null;
        InputSource spInputSource = null;

        try {
            byte[] spBuffer = null;

            WaveFormat WaveFormatEx = new WaveFormat();

            // create the input source
            IntegerPointer nAudioBlocks = new IntegerPointer();
            nAudioBlocks.value = 0;
            IntegerPointer nHeaderBytes = new IntegerPointer();
            nHeaderBytes.value = 0;
            IntegerPointer nTerminatingBytes = new IntegerPointer();
            nTerminatingBytes.value = 0;
            spInputSource = InputSource.CreateInputSource(pInputFilename, WaveFormatEx, nAudioBlocks,
                    nHeaderBytes, nTerminatingBytes);

            // create the compressor
            spAPECompress = IAPECompress.CreateIAPECompress();

            // figure the audio bytes
            int nAudioBytes = nAudioBlocks.value * WaveFormatEx.nBlockAlign;

            // start the encoder
            if (nHeaderBytes.value > 0) spBuffer = new byte[nHeaderBytes.value];
            spInputSource.GetHeaderData(spBuffer);
            spAPECompress.Start(pOutputFilename, WaveFormatEx, nAudioBytes,
                    nCompressionLevel, spBuffer, nHeaderBytes.value);

            // set-up the progress
            ProgressHelper spMACProgressHelper = new ProgressHelper(nAudioBytes, progressor);

            // master loop
            int nBytesLeft = nAudioBytes;

            spMACProgressHelper.UpdateStatus("Process data by compressor");

            while (nBytesLeft > 0) {
                int nBytesAdded = spAPECompress.AddDataFromInputSource(spInputSource, nBytesLeft);

                nBytesLeft -= nBytesAdded;

                // update the progress
                spMACProgressHelper.UpdateProgress(nAudioBytes - nBytesLeft);

                // process the kill flag
                if (spMACProgressHelper.isKillFlag())
                    throw new JMACStoppedByUserException();
            }

            spMACProgressHelper.UpdateStatus("Finishing compression");

            // finalize the file
            if (nTerminatingBytes.value > 0) spBuffer = new byte[nTerminatingBytes.value];
            spInputSource.GetTerminatingData(spBuffer);
            spAPECompress.Finish(spBuffer, nTerminatingBytes.value, nTerminatingBytes.value);

            // update the progress to 100%
            spMACProgressHelper.UpdateStatus("Compression finished");
        } finally {
            // kill the compressor if we failed
            if (spAPECompress != null)
                spAPECompress.Kill();
            if (spInputSource != null)
                spInputSource.Close();
        }
    }
View Full Code Here

TOP

Related Classes of davaguine.jmac.encoder.IAPECompress

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.