The Bistream class is responsible for parsing an MPEG audio bitstream. * REVIEW: much of the parsing currently occurs in the various decoders. This should be moved into this class and associated inner classes.
Inheritance: BitstreamErrors
Ejemplo n.º 1
0
 public virtual 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;
 }
Ejemplo n.º 2
0
        public Player(System.IO.Stream stream, AudioDevice device)
        {
            bitstream = new Bitstream(stream);
            decoder = new Decoder();

            if (device != null)
            {
                audio = device;
            }
            else
            {
                FactoryRegistry r = FactoryRegistry.systemRegistry();
                audio = r.createAudioDevice();
            }
            audio.open(decoder);
        }
Ejemplo n.º 3
0
 public abstract void read_allocation(Bitstream stream, Header header, Crc16 crc);
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary> Read a 32-bit header from the bitstream.
        /// </summary>
        internal void read_header(Bitstream stream, Crc16[] crcp)
        {
            int headerstring;
            int channel_bitrate;

            bool sync = false;

            do
            {

                headerstring = stream.syncHeader(syncmode);
                _headerstring = headerstring; // E.B

                if (syncmode == Bitstream.INITIAL_SYNC)
                {
                    h_version = ((SupportClass.URShift(headerstring, 19)) & 1);
                    if (((SupportClass.URShift(headerstring, 20)) & 1) == 0)
                    // SZD: MPEG2.5 detection
                        if (h_version == MPEG2_LSF)
                            h_version = MPEG25_LSF;
                        else
                            throw stream.newBitstreamException(javazoom.jl.decoder.BitstreamErrors_Fields.UNKNOWN_ERROR);

                    if ((h_sample_frequency = ((SupportClass.URShift(headerstring, 10)) & 3)) == 3)
                    {
                        throw stream.newBitstreamException(javazoom.jl.decoder.BitstreamErrors_Fields.UNKNOWN_ERROR);
                    }
                }

                h_layer = 4 - (SupportClass.URShift(headerstring, 17)) & 3;
                h_protection_bit = (SupportClass.URShift(headerstring, 16)) & 1;
                h_bitrate_index = (SupportClass.URShift(headerstring, 12)) & 0xF;
                h_padding_bit = (SupportClass.URShift(headerstring, 9)) & 1;
                h_mode = ((SupportClass.URShift(headerstring, 6)) & 3);
                h_mode_extension = (SupportClass.URShift(headerstring, 4)) & 3;
                if (h_mode == JOINT_STEREO)
                    h_intensity_stereo_bound = (h_mode_extension << 2) + 4;
                else
                    h_intensity_stereo_bound = 0;
                // should never be used
                if (((SupportClass.URShift(headerstring, 3)) & 1) == 1)
                    h_copyright = true;
                if (((SupportClass.URShift(headerstring, 2)) & 1) == 1)
                    h_original = true;

                // calculate number of subbands:
                if (h_layer == 1)
                    h_number_of_subbands = 32;
                else
                {
                    channel_bitrate = h_bitrate_index;
                    // calculate bitrate per channel:
                    if (h_mode != SINGLE_CHANNEL)
                        if (channel_bitrate == 4)
                            channel_bitrate = 1;
                        else
                            channel_bitrate -= 4;

                    if ((channel_bitrate == 1) || (channel_bitrate == 2))
                        if (h_sample_frequency == THIRTYTWO)
                            h_number_of_subbands = 12;
                        else
                            h_number_of_subbands = 8;
                    else if ((h_sample_frequency == FOURTYEIGHT) || ((channel_bitrate >= 3) && (channel_bitrate <= 5)))
                        h_number_of_subbands = 27;
                    else
                        h_number_of_subbands = 30;
                }
                if (h_intensity_stereo_bound > h_number_of_subbands)
                    h_intensity_stereo_bound = h_number_of_subbands;
                // calculate framesize and nSlots
                calculate_framesize();

                // read framedata:
                stream.read_frame_data(framesize);

                if (stream.isSyncCurrentPosition(syncmode))
                {
                    if (syncmode == Bitstream.INITIAL_SYNC)
                    {
                        syncmode = Bitstream.STRICT_SYNC;
                        stream.set_syncword(headerstring & unchecked((int)0xFFF80CC0));
                    }
                    sync = true;
                }
                else
                {
                    stream.unreadFrame();
                }
            }
            while (!sync);

            stream.parse_frame();

            if (h_protection_bit == 0)
            {
                // frame contains a crc checksum
                checksum = (short) stream.get_bits(16);
                if (crc == null)
                    crc = new Crc16();
                crc.add_bits(headerstring, 16);
                crcp[0] = crc;
            }
            else
                crcp[0] = null;
            if (h_sample_frequency == FOURTYFOUR_POINT_ONE)
            {
                /*
                if (offset == null)
                {
                int max = max_number_of_frames(stream);
                offset = new int[max];
                for(int i=0; i<max; i++) offset[i] = 0;
                }
                // Bizarre, y avait ici une acollade ouvrante
                int cf = stream.current_frame();
                int lf = stream.last_frame();
                if ((cf > 0) && (cf == lf))
                {
                offset[cf] = offset[cf-1] + h_padding_bit;
                }
                else
                {
                offset[0] = h_padding_bit;
                }
                */
            }
        }
Ejemplo n.º 6
0
            /// <summary>*
            /// </summary>
            public override void read_allocation(Bitstream stream, Header header, Crc16 crc)
            {
                allocation = stream.get_bits(4);
                channel2_allocation = stream.get_bits(4);

                                // try/catch block to handle invalid allocation
                                // (catch array bounds error)
                                try
                                {
                                   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];
                                   }
                                }
                                catch (IndexOutOfRangeException )
                                {
                                   // array bounds error? Invalid allocation
                                   // (or unsupported). Ignore for now.
                                }
            }
Ejemplo n.º 7
0
 /// <summary>*
 /// </summary>
 public override 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)];
 }
Ejemplo n.º 8
0
 /// <summary>*
 /// </summary>
 public override void read_allocation(Bitstream stream, Header header, Crc16 crc)
 {
     if ((allocation = stream.get_bits(4)) == 15)
     {
     }
     //	 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];
     }
 }
Ejemplo n.º 9
0
 /// <summary>*
 /// </summary>
 public override void read_allocation(Bitstream stream, Header header, Crc16 crc)
 {
     base.read_allocation(stream, header, crc);
 }
Ejemplo n.º 10
0
            /// <summary>*
            /// </summary>
            public override bool 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;
            }
Ejemplo n.º 11
0
            /// <summary>*
            /// </summary>
            public override 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);
                }
            }
Ejemplo n.º 12
0
 /// <summary>*
 /// </summary>
 public override void  read_allocation(Bitstream stream, Header header, Crc16 crc)
 {
     base.read_allocation(stream, header, crc);
 }
Ejemplo n.º 13
0
 /// <summary>*
 /// </summary>
 public override bool read_sampledata(Bitstream stream)
 {
     return(base.read_sampledata(stream));
 }
Ejemplo n.º 14
0
 public abstract bool read_sampledata(Bitstream stream);
Ejemplo n.º 15
0
 public abstract void  read_scalefactor(Bitstream stream, Header header);
Ejemplo n.º 16
0
 public abstract void  read_allocation(Bitstream stream, Header header, Crc16 crc);
Ejemplo n.º 17
0
 public abstract bool read_sampledata(Bitstream stream);
Ejemplo n.º 18
0
 /// <summary>*
 /// </summary>
 public virtual void read_scalefactor_selection(Bitstream stream, Crc16 crc)
 {
     if (allocation != 0)
     {
         scfsi = stream.get_bits(2);
         if (crc != null)
             crc.add_bits(scfsi, 2);
     }
 }
Ejemplo n.º 19
0
 public abstract void read_scalefactor(Bitstream stream, Header header);
Ejemplo n.º 20
0
            /// <summary>*
            /// </summary>
            public override void read_scalefactor(Bitstream stream, Header header)
            {
                if (allocation != 0)
                {
                    base.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;
                        }
                }
            }
Ejemplo n.º 21
0
 /// <summary>*
 /// </summary>
 public override bool read_sampledata(Bitstream stream)
 {
     if (allocation != 0)
     {
         sample = (float) (stream.get_bits(samplelength));
     }
     if (++samplenumber == 12)
     {
         samplenumber = 0;
         return true;
     }
     return false;
 }
Ejemplo n.º 22
0
 /// <summary>*
 /// </summary>
 public override 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);
     }
 }
Ejemplo n.º 23
0
 /// <summary>*
 /// </summary>
 public override bool read_sampledata(Bitstream stream)
 {
     return base.read_sampledata(stream);
 }
Ejemplo n.º 24
0
        /// <summary> Constructor.
        /// </summary>
        // REVIEW: these constructor arguments should be moved to the
        // decodeFrame() method, where possible, so that one
        public LayerIIIDecoder(Bitstream stream0, Header header0, SynthesisFilter filtera, SynthesisFilter filterb, Obuffer buffer0, int which_ch0)
        {
            InitBlock();
            huffcodetab.inithuff();
            is_1d = new int[SBLIMIT * SSLIMIT + 4];
            ro = new float[2][][];
            for (int i = 0; i < 2; i++)
            {
                ro[i] = new float[SBLIMIT][];
                for (int i2 = 0; i2 < SBLIMIT; i2++)
                {
                    ro[i][i2] = new float[SSLIMIT];
                }
            }
            lr = new float[2][][];
            for (int i3 = 0; i3 < 2; i3++)
            {
                lr[i3] = new float[SBLIMIT][];
                for (int i4 = 0; i4 < SBLIMIT; i4++)
                {
                    lr[i3][i4] = new float[SSLIMIT];
                }
            }
            out_1d = new float[SBLIMIT * SSLIMIT];
            prevblck = new float[2][];
            for (int i5 = 0; i5 < 2; i5++)
            {
                prevblck[i5] = new float[SBLIMIT * SSLIMIT];
            }
            k = new float[2][];
            for (int i6 = 0; i6 < 2; i6++)
            {
                k[i6] = new float[SBLIMIT * SSLIMIT];
            }
            nonzero = new int[2];

            //III_scalefact_t
            III_scalefac_t = new temporaire2[2];
            III_scalefac_t[0] = new temporaire2();
            III_scalefac_t[1] = new temporaire2();
            scalefac = III_scalefac_t;
            // L3TABLE INIT

            sfBandIndex = new SBI[9]; // SZD: MPEG2.5 +3 indices
            int[] l0 = new int[]{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576};
            int[] s0 = new int[]{0, 4, 8, 12, 18, 24, 32, 42, 56, 74, 100, 132, 174, 192};
            int[] l1 = new int[]{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232, 278, 330, 394, 464, 540, 576};
            int[] s1 = new int[]{0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 136, 180, 192};
            int[] l2 = new int[]{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576};
            int[] s2 = new int[]{0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192};

            int[] l3 = new int[]{0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196, 238, 288, 342, 418, 576};
            int[] s3 = new int[]{0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84, 106, 136, 192};
            int[] l4 = new int[]{0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190, 230, 276, 330, 384, 576};
            int[] s4 = new int[]{0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80, 100, 126, 192};
            int[] l5 = new int[]{0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240, 296, 364, 448, 550, 576};
            int[] s5 = new int[]{0, 4, 8, 12, 16, 22, 30, 42, 58, 78, 104, 138, 180, 192};
            // SZD: MPEG2.5
            int[] l6 = new int[]{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576};
            int[] s6 = new int[]{0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192};
            int[] l7 = new int[]{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576};
            int[] s7 = new int[]{0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192};
            int[] l8 = new int[]{0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400, 476, 566, 568, 570, 572, 574, 576};
            int[] s8 = new int[]{0, 8, 16, 24, 36, 52, 72, 96, 124, 160, 162, 164, 166, 192};

            sfBandIndex[0] = new SBI(l0, s0);
            sfBandIndex[1] = new SBI(l1, s1);
            sfBandIndex[2] = new SBI(l2, s2);

            sfBandIndex[3] = new SBI(l3, s3);
            sfBandIndex[4] = new SBI(l4, s4);
            sfBandIndex[5] = new SBI(l5, s5);
            //SZD: MPEG2.5
            sfBandIndex[6] = new SBI(l6, s6);
            sfBandIndex[7] = new SBI(l7, s7);
            sfBandIndex[8] = new SBI(l8, s8);
            // END OF L3TABLE INIT

            if (reorder_table == null)
            {
                // SZD: generate LUT
                reorder_table = new int[9][];
                for (int i = 0; i < 9; i++)
                    reorder_table[i] = reorder(sfBandIndex[i].s);
            }

            // Sftable
            int[] ll0 = new int[]{0, 6, 11, 16, 21};
            int[] ss0 = new int[]{0, 6, 12};
            sftable = new Sftable(this, ll0, ss0);
            // END OF Sftable

            // scalefac_buffer
            scalefac_buffer = new int[54];
            // END OF scalefac_buffer

            stream = stream0;
            header = header0;
            filter1 = filtera;
            filter2 = filterb;
            buffer = buffer0;
            which_channels = which_ch0;

            frame_start = 0;
            channels = (header.mode() == Header.SINGLE_CHANNEL)?1:2;
            max_gr = (header.version() == Header.MPEG1)?2:1;

            sfreq = header.sample_frequency() + ((header.version() == Header.MPEG1)?3:(header.version() == Header.MPEG25_LSF)?6:0); // SZD

            if (channels == 2)
            {
                switch (which_channels)
                {

                    case (int)OutputChannelsEnum.LEFT_CHANNEL:
                    case (int)OutputChannelsEnum.DOWNMIX_CHANNELS:
                        first_channel = last_channel = 0;
                        break;

                    case (int)OutputChannelsEnum.RIGHT_CHANNEL:
                        first_channel = last_channel = 1;
                        break;

                    case (int)OutputChannelsEnum.BOTH_CHANNELS:
                    default:
                        first_channel = 0;
                        last_channel = 1;
                        break;
                    }
            }
            else
            {
                first_channel = last_channel = 0;
            }

            for (int ch = 0; ch < 2; ch++)
                for (int j = 0; j < 576; j++)
                    prevblck[ch][j] = 0.0f;

            nonzero[0] = nonzero[1] = 576;

            br = new BitReserve();
            si = new III_side_info_t();
        }
Ejemplo n.º 25
0
 /// <summary>*
 /// </summary>
 public override bool read_sampledata(Bitstream stream)
 {
     bool returnvalue = base.read_sampledata(stream);
     if (channel2_allocation != 0)
     {
         channel2_sample = (float) (stream.get_bits(channel2_samplelength));
     }
     return (returnvalue);
 }
Ejemplo n.º 26
0
        protected internal virtual FrameDecoder retrieveDecoder(Header header, Bitstream stream, int layer)
        {
            FrameDecoder decoder = null;

            // REVIEW: allow channel output selection type
            // (LEFT, RIGHT, BOTH, DOWNMIX)
            switch (layer)
            {

                case 3:
                    if (l3decoder == null)
                    {
                        l3decoder = new LayerIIIDecoder(stream, header, filter1, filter2, output, (int)OutputChannelsEnum.BOTH_CHANNELS);
                    }

                    decoder = l3decoder;
                    break;

                case 2:
                    if (l2decoder == null)
                    {
                        l2decoder = new LayerIIDecoder();
                        l2decoder.create(stream, header, filter1, filter2, output, (int)OutputChannelsEnum.BOTH_CHANNELS);
                    }
                    decoder = l2decoder;
                    break;

                case 1:
                    if (l1decoder == null)
                    {
                        l1decoder = new LayerIDecoder();
                        l1decoder.create(stream, header, filter1, filter2, output, (int)OutputChannelsEnum.BOTH_CHANNELS);
                    }
                    decoder = l1decoder;
                    break;
                }

            if (decoder == null)
            {
                throw newDecoderException(javazoom.jl.decoder.DecoderErrors_Fields.UNSUPPORTED_LAYER, null);
            }

            return decoder;
        }
Ejemplo n.º 27
0
            /// <summary>*
            /// </summary>
            public override bool read_sampledata(Bitstream stream)
            {
                bool returnvalue = base.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;
            }
Ejemplo n.º 28
0
        /// <summary> Read a 32-bit header from the bitstream.
        /// </summary>
        internal void  read_header(Bitstream stream, Crc16[] crcp)
        {
            int headerstring;
            int channel_bitrate;

            bool sync = false;

            do
            {
                headerstring  = stream.syncHeader(syncmode);
                _headerstring = headerstring;                 // E.B

                if (syncmode == Bitstream.INITIAL_SYNC)
                {
                    h_version = ((SupportClass.URShift(headerstring, 19)) & 1);
                    if (((SupportClass.URShift(headerstring, 20)) & 1) == 0)
                    {
                        // SZD: MPEG2.5 detection
                        if (h_version == MPEG2_LSF)
                        {
                            h_version = MPEG25_LSF;
                        }
                        else
                        {
                            throw stream.newBitstreamException(javazoom.jl.decoder.BitstreamErrors_Fields.UNKNOWN_ERROR);
                        }
                    }


                    if ((h_sample_frequency = ((SupportClass.URShift(headerstring, 10)) & 3)) == 3)
                    {
                        throw stream.newBitstreamException(javazoom.jl.decoder.BitstreamErrors_Fields.UNKNOWN_ERROR);
                    }
                }

                h_layer          = 4 - (SupportClass.URShift(headerstring, 17)) & 3;
                h_protection_bit = (SupportClass.URShift(headerstring, 16)) & 1;
                h_bitrate_index  = (SupportClass.URShift(headerstring, 12)) & 0xF;
                h_padding_bit    = (SupportClass.URShift(headerstring, 9)) & 1;
                h_mode           = ((SupportClass.URShift(headerstring, 6)) & 3);
                h_mode_extension = (SupportClass.URShift(headerstring, 4)) & 3;
                if (h_mode == JOINT_STEREO)
                {
                    h_intensity_stereo_bound = (h_mode_extension << 2) + 4;
                }
                else
                {
                    h_intensity_stereo_bound = 0;
                }
                // should never be used
                if (((SupportClass.URShift(headerstring, 3)) & 1) == 1)
                {
                    h_copyright = true;
                }
                if (((SupportClass.URShift(headerstring, 2)) & 1) == 1)
                {
                    h_original = true;
                }


                // calculate number of subbands:
                if (h_layer == 1)
                {
                    h_number_of_subbands = 32;
                }
                else
                {
                    channel_bitrate = h_bitrate_index;
                    // calculate bitrate per channel:
                    if (h_mode != SINGLE_CHANNEL)
                    {
                        if (channel_bitrate == 4)
                        {
                            channel_bitrate = 1;
                        }
                        else
                        {
                            channel_bitrate -= 4;
                        }
                    }

                    if ((channel_bitrate == 1) || (channel_bitrate == 2))
                    {
                        if (h_sample_frequency == THIRTYTWO)
                        {
                            h_number_of_subbands = 12;
                        }
                        else
                        {
                            h_number_of_subbands = 8;
                        }
                    }
                    else if ((h_sample_frequency == FOURTYEIGHT) || ((channel_bitrate >= 3) && (channel_bitrate <= 5)))
                    {
                        h_number_of_subbands = 27;
                    }
                    else
                    {
                        h_number_of_subbands = 30;
                    }
                }
                if (h_intensity_stereo_bound > h_number_of_subbands)
                {
                    h_intensity_stereo_bound = h_number_of_subbands;
                }
                // calculate framesize and nSlots
                calculate_framesize();

                // read framedata:
                stream.read_frame_data(framesize);

                if (stream.isSyncCurrentPosition(syncmode))
                {
                    if (syncmode == Bitstream.INITIAL_SYNC)
                    {
                        syncmode = Bitstream.STRICT_SYNC;
                        stream.set_syncword(headerstring & unchecked ((int)0xFFF80CC0));
                    }
                    sync = true;
                }
                else
                {
                    stream.unreadFrame();
                }
            }while (!sync);

            stream.parse_frame();

            if (h_protection_bit == 0)
            {
                // frame contains a crc checksum
                checksum = (short)stream.get_bits(16);
                if (crc == null)
                {
                    crc = new Crc16();
                }
                crc.add_bits(headerstring, 16);
                crcp[0] = crc;
            }
            else
            {
                crcp[0] = null;
            }
            if (h_sample_frequency == FOURTYFOUR_POINT_ONE)
            {
                /*
                 * if (offset == null)
                 * {
                 * int max = max_number_of_frames(stream);
                 * offset = new int[max];
                 * for(int i=0; i<max; i++) offset[i] = 0;
                 * }
                 * // Bizarre, y avait ici une acollade ouvrante
                 * int cf = stream.current_frame();
                 * int lf = stream.last_frame();
                 * if ((cf > 0) && (cf == lf))
                 * {
                 * offset[cf] = offset[cf-1] + h_padding_bit;
                 * }
                 * else
                 * {
                 * offset[0] = h_padding_bit;
                 * }
                 */
            }
        }
Ejemplo n.º 29
0
        /// <summary> Decodes one frame from an MPEG audio bitstream.
        /// 
        /// </summary>
        /// <param name="header		The">header describing the frame to decode.
        /// </param>
        /// <param name="bitstream		The">bistream that provides the bits for te body of the frame. 
        /// 
        /// </param>
        /// <returns> A SampleBuffer containing the decoded samples.
        /// 
        /// </returns>
        public virtual Obuffer decodeFrame(Header header, Bitstream stream)
        {
            if (!initialized)
            {
                initialize(header);
            }

            int layer = header.layer();

            output.clear_buffer();

            FrameDecoder decoder = retrieveDecoder(header, stream, layer);

            decoder.decodeFrame();

            output.write_buffer(1);

            return output;
        }
Ejemplo n.º 30
0
            /// <summary>*
            /// </summary>
            public override void read_scalefactor(Bitstream stream, Header header)
            {
                base.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);
                }
            }
Ejemplo n.º 31
0
 /// <summary>*
 /// </summary>
 public override 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);
     }
 }
Ejemplo n.º 32
0
 /// <summary>*
 /// </summary>
 public override void read_allocation(Bitstream stream, Header header, Crc16 crc)
 {
     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];
     }
 }