示例#1
0
        public override Object look(DspState vd, InfoMode vm, Object vr)
        {
            InfoResidue0 info = (InfoResidue0)vr;
            LookResidue0 look = new LookResidue0();
            int          acc  = 0;
            int          dim;
            int          maxstage = 0;

            look.info = info;
            look.map  = vm.mapping;

            look.parts      = info.partitions;
            look.fullbooks  = vd.fullbooks;
            look.phrasebook = vd.fullbooks[info.groupbook];

            dim = look.phrasebook.dim;

            look.partbooks = new int[look.parts][];

            for (int j = 0; j < look.parts; j++)
            {
                int stages = VUtils.ilog(info.secondstages[j]);
                if (stages != 0)
                {
                    if (stages > maxstage)
                    {
                        maxstage = stages;
                    }
                    look.partbooks[j] = new int[stages];
                    for (int k = 0; k < stages; k++)
                    {
                        if ((info.secondstages[j] & (1 << k)) != 0)
                        {
                            look.partbooks[j][k] = info.booklist[acc++];
                        }
                    }
                }
            }

            look.partvals  = (int)Math.Round(Math.Pow(look.parts, dim));
            look.stages    = maxstage;
            look.decodemap = new int[look.partvals][];
            for (int j = 0; j < look.partvals; j++)
            {
                int val  = j;
                int mult = look.partvals / look.parts;
                look.decodemap[j] = new int[dim];

                for (int k = 0; k < dim; k++)
                {
                    int deco = val / mult;
                    val  -= deco * mult;
                    mult /= look.parts;
                    look.decodemap[j][k] = deco;
                }
            }
            return(look);
        }
示例#2
0
        // unpacks a codebook from the packet buffer into the codebook struct,
        // readies the codebook auxiliary structures for decode
        internal int unpack(csBuffer opb)
        {
            int i;

            opb.read(24);
            // first the basic parameters
            dim     = opb.read(16);
            entries = opb.read(24);

            // codeword ordering.... length ordered or unordered?
            switch (opb.read(1))
            {
            case 0:
                // unordered
                lengthlist = new int[entries];

                // allocated but unused entries?
                if (opb.read(1) != 0)
                {
                    // yes, unused entries

                    for (i = 0; i < entries; i++)
                    {
                        if (opb.read(1) != 0)
                        {
                            int num = opb.read(5);
                            lengthlist[i] = num + 1;
                        }
                        else
                        {
                            lengthlist[i] = 0;
                        }
                    }
                }
                else
                {
                    // all entries used; no tagging
                    for (i = 0; i < entries; i++)
                    {
                        int num = opb.read(5);
                        lengthlist[i] = num + 1;
                    }
                }
                break;

            case 1:
                // ordered
            {
                int length = opb.read(5) + 1;
                lengthlist = new int[entries];

                for (i = 0; i < entries;)
                {
                    int num = opb.read(VUtils.ilog(entries - i));
                    for (int j = 0; j < num; j++, i++)
                    {
                        lengthlist[i] = length;
                    }
                    length++;
                }
            }
            break;

            default:
                // EOF
                return(-1);
            }

            // Do we have a mapping to unpack?
            switch ((maptype = opb.read(4)))
            {
            case 0:
                // no mapping
                break;

            case 1:
            case 2:
                // implicitly populated value mapping
                // explicitly populated value mapping
                q_min       = opb.read(32);
                q_delta     = opb.read(32);
                q_quant     = opb.read(4) + 1;
                q_sequencep = opb.read(1);

                {
                    int quantvals = 0;
                    switch (maptype)
                    {
                    case 1:
                        quantvals = maptype1_quantvals();
                        break;

                    case 2:
                        quantvals = entries * dim;
                        break;
                    }

                    // quantized values
                    quantlist = new int[quantvals];
                    for (i = 0; i < quantvals; i++)
                    {
                        quantlist[i] = opb.read(q_quant);
                    }
                }
                break;

            default:
                return(-1);
            }
            return(0);
        }
示例#3
0
        // build the decode helper tree from the codewords
        internal DecodeAux make_decode_tree()
        {
            int       top = 0;
            DecodeAux t   = new DecodeAux();

            int[] ptr0     = t.ptr0 = new int[entries * 2];
            int[] ptr1     = t.ptr1 = new int[entries * 2];
            int[] codelist = make_words(c.lengthlist, c.entries);

            if (codelist == null)
            {
                return(null);
            }
            t.aux = entries * 2;

            for (int i = 0; i < entries; i++)
            {
                if (c.lengthlist[i] > 0)
                {
                    int ptr = 0;
                    int j;
                    for (j = 0; j < c.lengthlist[i] - 1; j++)
                    {
                        int bit = (int)(((uint)codelist[i] >> j) & 1);
                        if (bit == 0)
                        {
                            if (ptr0[ptr] == 0)
                            {
                                ptr0[ptr] = ++top;
                            }
                            ptr = ptr0[ptr];
                        }
                        else
                        {
                            if (ptr1[ptr] == 0)
                            {
                                ptr1[ptr] = ++top;
                            }
                            ptr = ptr1[ptr];
                        }
                    }

                    if ((((uint)codelist[i] >> j) & 1) == 0)
                    {
                        ptr0[ptr] = -i;
                    }
                    else
                    {
                        ptr1[ptr] = -i;
                    }
                }
            }
            //free(codelist);

            t.tabn = VUtils.ilog(entries) - 4;

            if (t.tabn < 5)
            {
                t.tabn = 5;
            }
            int n = 1 << t.tabn;

            t.tab  = new int[n];
            t.tabl = new int[n];
            for (int i = 0; i < n; i++)
            {
                int p = 0;
                int j = 0;
                for (j = 0; j < t.tabn && (p > 0 || j == 0); j++)
                {
                    if ((i & (1 << j)) != 0)
                    {
                        p = ptr1[p];
                    }
                    else
                    {
                        p = ptr0[p];
                    }
                }
                t.tab[i]  = p;                 // -code
                t.tabl[i] = j;                 // length
            }

            return(t);
        }
示例#4
0
        public override Object inverse1(Block vb, Object ii, Object memo)
        {
            LookFloor1 look = (LookFloor1)ii;
            InfoFloor1 info = look.vi;

            CodeBook[] books = vb.vd.fullbooks;

            /* unpack wrapped/predicted values from stream */
            if (vb.opb.read(1) == 1)
            {
                int[] fit_value = null;
                if (memo is int[])
                {
                    fit_value = (int[])memo;
                }
                if (fit_value == null || fit_value.Length < look.posts)
                {
                    fit_value = new int[look.posts];
                }
                else
                {
                    for (int i = 0; i < fit_value.Length; i++)
                    {
                        fit_value[i] = 0;
                    }
                }

                fit_value[0] = vb.opb.read(VUtils.ilog(look.quant_q - 1));
                fit_value[1] = vb.opb.read(VUtils.ilog(look.quant_q - 1));

                /* partition by partition */
                for (int i = 0, j = 2; i < info.partitions; i++)
                {
                    int clss     = info.partitionclass[i];
                    int cdim     = info.class_dim[clss];
                    int csubbits = info.class_subs[clss];
                    int csub     = 1 << csubbits;
                    int cval     = 0;

                    /* decode the partition's first stage cascade value */
                    if (csubbits != 0)
                    {
                        cval = books[info.class_book[clss]].decode(vb.opb);

                        if (cval == -1)
                        {
                            //goto eop;
                            return(null);
                        }
                    }

                    for (int k = 0; k < cdim; k++)
                    {
                        int book = info.class_subbook[clss][cval & (csub - 1)];
                        cval = (int)((uint)cval >> csubbits);
                        if (book >= 0)
                        {
                            if ((fit_value[j + k] = books[book].decode(vb.opb)) == -1)
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            fit_value[j + k] = 0;
                        }
                    }
                    j += cdim;
                }

                /* unwrap positive values and reconsitute via linear interpolation */
                for (int i = 2; i < look.posts; i++)
                {
                    int predicted = render_point(info.postlist[look.loneighbor[i - 2]],
                                                 info.postlist[look.hineighbor[i - 2]],
                                                 fit_value[look.loneighbor[i - 2]],
                                                 fit_value[look.hineighbor[i - 2]],
                                                 info.postlist[i]);
                    int hiroom = look.quant_q - predicted;
                    int loroom = predicted;
                    int room   = (hiroom < loroom?hiroom:loroom) << 1;
                    int val    = fit_value[i];

                    if (val != 0)
                    {
                        if (val >= room)
                        {
                            if (hiroom > loroom)
                            {
                                val = val - loroom;
                            }
                            else
                            {
                                val = -1 - (val - hiroom);
                            }
                        }
                        else
                        {
                            if ((val & 1) != 0)
                            {
                                val = (int)(-((uint)(val + 1) >> 1));
                            }
                            else
                            {
                                val >>= 1;
                            }
                        }

                        fit_value[i] = val + predicted;
                        fit_value[look.loneighbor[i - 2]] &= 0x7fff;
                        fit_value[look.hineighbor[i - 2]] &= 0x7fff;
                    }
                    else
                    {
                        fit_value[i] = predicted | 0x8000;
                    }
                }
                return(fit_value);
            }

            //  eop:
            //    return(NULL);
            return(null);
        }