Beispiel #1
0
 public ICStream(int frameLength)
 {
     this.frameLength = frameLength;
     info             = new ICSInfo(frameLength);
     sfbCB            = new int[MAX_SECTIONS];
     sectEnd          = new int[MAX_SECTIONS];
     data             = new float[frameLength];
     scaleFactors     = new float[MAX_SECTIONS];
 }
        public void decode(BitStream inStream, ICSInfo info, Profile profile)
        {
            lag = 0;
            if (profile.type == Profile.ProfileType.AAC_LD)
            {
                lagUpdate = inStream.readBool();
                if (lagUpdate)
                {
                    lag = inStream.readBits(10);
                }
            }
            else
            {
                lag = inStream.readBits(11);
            }
            if (lag > (frameLength << 1))
            {
                throw new AACException("LTP lag too large: " + lag);
            }
            coef = inStream.readBits(3);

            int windowCount = info.getWindowCount();

            if (info.isEightShortFrame())
            {
                shortUsed       = new bool[windowCount];
                shortLagPresent = new bool[windowCount];
                shortLag        = new int[windowCount];
                for (int w = 0; w < windowCount; w++)
                {
                    if (shortUsed[w] = inStream.readBool())
                    {
                        shortLagPresent[w] = inStream.readBool();
                        if (shortLagPresent[w])
                        {
                            shortLag[w] = inStream.readBits(4);
                        }
                    }
                }
            }
            else
            {
                lastBand = Math.Min(info.getMaxSFB(), MAX_LTP_SFB);
                longUsed = new bool[lastBand];
                for (int i = 0; i < lastBand; i++)
                {
                    longUsed[i] = inStream.readBool();
                }
            }
        }
 public void setData(ICSInfo info)
 {
     windowSequence        = info.windowSequence;
     windowShape[PREVIOUS] = windowShape[CURRENT];
     windowShape[CURRENT]  = info.windowShape[CURRENT];
     maxSFB = info.maxSFB;
     predictionDataPresent = info.predictionDataPresent;
     if (predictionDataPresent)
     {
         icPredict = info.icPredict;
     }
     ltpData1Present = info.ltpData1Present;
     if (ltpData1Present)
     {
         throw new NotImplementedException();
         //ltPredict1.copy(info.ltPredict1);
         //ltPredict2.copy(info.ltPredict2);
     }
     windowCount       = info.windowCount;
     windowGroupCount  = info.windowGroupCount;
     windowGroupLength = info.windowGroupLength.ToArray();
     swbCount          = info.swbCount;
     swbOffsets        = info.swbOffsets.ToArray();
 }
Beispiel #4
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;
                            }
                        }
                    }
                }
            }
        }