public void create(Bitstream stream0, Header header0,
                    SynthesisFilter filtera, SynthesisFilter filterb,
                    Obuffer buffer0, OutputChannels which_ch0)
 {
     stream         = stream0;
     header         = header0;
     filter1        = filtera;
     filter2        = filterb;
     buffer         = buffer0;
     which_channels = which_ch0;
 }
Beispiel #2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            decodedStream.Position = decodedStream.Length;

            Header header = bitStream.readFrame();

            if (header == null)
            {
                return(0);
            }

            decoder.OutputBuffer = outputBuffer;
            Obuffer decoderOutput = decoder.decodeFrame(header, bitStream);

            bitStream.closeFrame();
            decodedStream.Position = readPos;

            int bytesRead = decodedStream.Read(buffer, offset, count);

            readPos += bytesRead;
            return(bytesRead);
        }
Beispiel #3
0
            public virtual void  decodedFrame(int frameNo, Header header, Obuffer o)
            {
                if (isDetail(MAX_DETAIL))
                {
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.Object.toString' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                    System.String headerString = header.ToString();
                    pw.WriteLine("Decoded frame " + frameNo + ": " + headerString);
                    pw.WriteLine("Output: " + o);
                }
                else if (isDetail(VERBOSE_DETAIL))
                {
                    if (frameNo == 0)
                    {
                        pw.Write("Converting.");
                        pw.Flush();
                    }

                    if ((frameNo % 10) == 0)
                    {
                        pw.Write('.');
                        pw.Flush();
                    }
                }
            }
Beispiel #4
0
        //UPGRADE_NOTE: Synchronized keyword was removed from method 'convert'. Lock expression was added. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1027"'
        public virtual void  convert(System.IO.Stream sourceStream, System.String destName, ProgressListener progressListener, Decoder.Params decoderParams)
        {
            lock (this)
            {
                if (progressListener == null)
                {
                    progressListener = PrintWriterProgressListener.newStdOut(PrintWriterProgressListener.NO_DETAIL);
                }
                try
                {
                    if (!(sourceStream is System.IO.BufferedStream))
                    {
                        sourceStream = new System.IO.BufferedStream(sourceStream);
                    }
                    int frameCount = -1;
                    //UPGRADE_ISSUE: Method 'java.io.InputStream.markSupported' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioInputStreammarkSupported"'
                    if (sourceStream.markSupported())
                    {
                        //UPGRADE_ISSUE: Method 'java.io.InputStream.mark' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioInputStreammark_int"'
                        sourceStream.mark(-1);
                        frameCount = countFrames(sourceStream);
                        //UPGRADE_ISSUE: Method 'java.io.InputStream.reset' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioInputStreamreset"'
                        sourceStream.reset();
                    }
                    progressListener.converterUpdate(javazoom.jl.converter.Converter.ProgressListener_Fields.UPDATE_FRAME_COUNT, frameCount, 0);


                    Obuffer   output  = null;
                    Decoder   decoder = new Decoder(decoderParams);
                    Bitstream stream  = new Bitstream(sourceStream);

                    if (frameCount == -1)
                    {
                        frameCount = System.Int32.MaxValue;
                    }

                    int  frame     = 0;
                    long startTime = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

                    try
                    {
                        for (; frame < frameCount; frame++)
                        {
                            try
                            {
                                Header header = stream.readFrame();
                                if (header == null)
                                {
                                    break;
                                }

                                progressListener.readFrame(frame, header);

                                if (output == null)
                                {
                                    // REVIEW: Incorrect functionality.
                                    // the decoder should provide decoded
                                    // frequency and channels output as it may differ from
                                    // the source (e.g. when downmixing stereo to mono.)
                                    int channels = (header.mode() == Header.SINGLE_CHANNEL)?1:2;
                                    int freq     = header.frequency();
                                    output = new WaveFileObuffer(channels, freq, destName);
                                    decoder.OutputBuffer = output;
                                }

                                Obuffer decoderOutput = decoder.decodeFrame(header, stream);

                                // REVIEW: the way the output buffer is set
                                // on the decoder is a bit dodgy. Even though
                                // this exception should never happen, we test to be sure.
                                if (decoderOutput != output)
                                {
                                    throw new System.ApplicationException("Output buffers are different.");
                                }


                                progressListener.decodedFrame(frame, header, output);

                                stream.closeFrame();
                            }
                            catch (System.Exception ex)
                            {
                                bool stop = !progressListener.converterException(ex);

                                if (stop)
                                {
                                    throw new JavaLayerException(ex.Message, ex);
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (output != null)
                        {
                            output.close();
                        }
                    }

                    int time = (int)((System.DateTime.Now.Ticks - 621355968000000000) / 10000 - startTime);
                    progressListener.converterUpdate(javazoom.jl.converter.Converter.ProgressListener_Fields.UPDATE_CONVERT_COMPLETE, time, frame);
                }
                catch (System.IO.IOException ex)
                {
                    throw new JavaLayerException(ex.Message, ex);
                }
            }
        }