コード例 #1
0
 /// <summary>
 ///     Creates a new stream instance using the provided stream as a source.
 ///     Will also read the first frame of the MP3 into the internal buffer.
 ///     TODO: allow selecting stereo or mono in the constructor (note that this also requires "implementing" the stereo format).
 ///     UPDATE: (Giperion) I hate that TODO above
 /// </summary>
 public MP3Stream(Stream sourceStream, int chunkSize, bool IsMono)
 {
     IsEOF          = false;
     m_SourceStream = sourceStream;
     pushback       = new PushbackStream(m_SourceStream, chunkSize);
     m_BitStream    = new Bitstream(pushback);
     if (IsMono)
     {
         Decoder.Params ParamsCustom = new Decoder.Params();
         ParamsCustom.OutputChannels = OutputChannels.LEFT;
         m_Decoder         = new Decoder(ParamsCustom);
         m_Buffer          = new Buffer16BitMono();
         FormatRep         = SoundFormat.Pcm16BitMono;
         m_ChannelCountRep = 1;
     }
     else
     {
         m_Buffer          = new Buffer16BitStereo();
         FormatRep         = SoundFormat.Pcm16BitStereo;
         m_ChannelCountRep = 2;
     }
     m_Decoder.OutputBuffer = m_Buffer;
     // read the first frame. This will fill the initial buffer with data, and get our frequency!
     if (!ReadFrame())
     {
         IsEOF = true;
     }
 }
コード例 #2
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);
                }
            }
        }
コード例 #3
0
 public virtual void  convert(System.String sourceName, System.String destName, ProgressListener progressListener, Decoder.Params decoderParams)
 {
     if (destName.Length == 0)
     {
         destName = null;
     }
     try
     {
         System.IO.Stream in_Renamed = openInput(sourceName);
         convert(in_Renamed, destName, progressListener, decoderParams);
         in_Renamed.Close();
     }
     catch (System.IO.IOException ioe)
     {
         throw new JavaLayerException(ioe.Message, ioe);
     }
 }