Пример #1
0
        public void decodeSectionData(BitStream inStream, bool sectionDataResilienceUsed)
        {
            Array.Clear(sfbCB, 0, sfbCB.Length);
            Array.Clear(sectEnd, 0, sectEnd.Length);
            int bits   = info.isEightShortFrame() ? 3 : 5;
            int escVal = (1 << bits) - 1;

            int windowGroupCount = info.getWindowGroupCount();
            int maxSFB           = info.getMaxSFB();

            int end, cb, incr;
            int idx = 0;

            for (int g = 0; g < windowGroupCount; g++)
            {
                int k = 0;
                while (k < maxSFB)
                {
                    end = k;
                    cb  = inStream.readBits(4);
                    if (cb == 12)
                    {
                        throw new AACException("invalid huffman codebook: 12");
                    }
                    while ((incr = inStream.readBits(bits)) == escVal)
                    {
                        end += incr;
                    }
                    end += incr;
                    if (end > maxSFB)
                    {
                        throw new AACException("too many bands: " + end + ", allowed: " + maxSFB);
                    }
                    for (; k < end; k++)
                    {
                        sfbCB[idx]     = cb;
                        sectEnd[idx++] = end;
                    }
                }
            }
        }
Пример #2
0
        void decode(BitStream inStream, DecoderConfig conf)
        {
            couplingPoint = 2 * inStream.readBit();
            coupledCount  = inStream.readBits(3);
            int gainCount = 0;

            for (int i = 0; i <= coupledCount; i++)
            {
                gainCount++;
                channelPair[i] = inStream.readBool();
                idSelect[i]    = inStream.readBits(4);
                if (channelPair[i])
                {
                    chSelect[i] = inStream.readBits(2);
                    if (chSelect[i] == 3)
                    {
                        gainCount++;
                    }
                }
                else
                {
                    chSelect[i] = 2;
                }
            }
            couplingPoint += inStream.readBit();
            couplingPoint |= (couplingPoint >> 1);

            bool   sign  = inStream.readBool();
            double scale = CCE_SCALE[inStream.readBits(2)];

            ics.decode(inStream, false, conf);
            ICSInfo info             = ics.getInfo();
            int     windowGroupCount = info.getWindowGroupCount();
            int     maxSFB           = info.getMaxSFB();

            //TODO:
            int[,] sfbCB = null;//ics.getSectionData().getSfbCB();

            for (int i = 0; i < gainCount; i++)
            {
                int   idx       = 0;
                int   cge       = 1;
                int   xg        = 0;
                float gainCache = 1.0f;
                if (i > 0)
                {
                    cge       = couplingPoint == 2 ? 1 : inStream.readBit();
                    xg        = cge == 0 ? 0 : Huffman.decodeScaleFactor(inStream) - 60;
                    gainCache = (float)Math.Pow(scale, -xg);
                }
                if (couplingPoint == 2)
                {
                    gain[i, 0] = gainCache;
                }
                else
                {
                    for (int g = 0; g < windowGroupCount; g++)
                    {
                        for (int sfb = 0; sfb < maxSFB; sfb++, idx++)
                        {
                            if (sfbCB[g, sfb] != ZERO_HCB)
                            {
                                if (cge == 0)
                                {
                                    int t = Huffman.decodeScaleFactor(inStream) - 60;
                                    if (t != 0)
                                    {
                                        int s = 1;
                                        t = xg += t;
                                        if (!sign)
                                        {
                                            s  -= 2 * (t & 0x1);
                                            t >>= 1;
                                        }
                                        gainCache = (float)(Math.Pow(scale, -t) * s);
                                    }
                                }
                                gain[i, idx] = gainCache;
                            }
                        }
                    }
                }
            }
        }