Example #1
0
        public override Object unpack(Info vi, csBuffer opb)
        {
            int          acc  = 0;
            InfoResidue0 info = new InfoResidue0();

            info.begin      = opb.read(24);
            info.end        = opb.read(24);
            info.grouping   = opb.read(24) + 1;
            info.partitions = opb.read(6) + 1;
            info.groupbook  = opb.read(8);

            for (int j = 0; j < info.partitions; j++)
            {
                int cascade = opb.read(3);
                if (opb.read(1) != 0)
                {
                    cascade |= opb.read(5) << 3;
                }
                info.secondstages[j] = cascade;
                acc += VUtils.icount(cascade);
            }

            for (int j = 0; j < acc; j++)
            {
                info.booklist[j] = opb.read(8);
            }
            return(info);
        }
Example #2
0
        public override Object unpack(Info vi, csBuffer opb)
        {
            InfoMapping0 info = new InfoMapping0();

            info.submaps = opb.read(1) != 0
                                ? opb.read(4) + 1 : 1;

            if (opb.read(1) != 0)
            {
                info.coupling_steps = opb.read(8) + 1;

                for (int i = 0; i < info.coupling_steps; i++)
                {
                    info.coupling_mag[i] = opb.read(VUtils.ilog2(vi.channels));
                    info.coupling_ang[i] = opb.read(VUtils.ilog2(vi.channels));
                }
            }
            opb.read(2);

            if (info.submaps > 1)
            {
                for (int i = 0; i < vi.channels; i++)
                {
                    info.chmuxlist[i] = opb.read(4);
                }
            }

            for (int i = 0; i < info.submaps; i++)
            {
                info.timesubmap[i]    = opb.read(8);
                info.floorsubmap[i]   = opb.read(8);
                info.residuesubmap[i] = opb.read(8);
            }
            return(info);
        }
Example #3
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);
        }
Example #4
0
        void init(Info vi)
        {
            this.vi  = vi;
            modebits = VUtils.ilog2(vi.modes);

            transform[0] = new Mdct();
            transform[1] = new Mdct();
            ((Mdct)transform[0]).init(vi.blocksizes[0]);
            ((Mdct)transform[1]).init(vi.blocksizes[1]);

            wnd[0][0][0] = window(vi.blocksizes[0], vi.blocksizes[0] / 2, vi.blocksizes[0] / 2);
            wnd[1][0][0] = window(vi.blocksizes[1], vi.blocksizes[0] / 2, vi.blocksizes[0] / 2);
            wnd[1][0][1] = window(vi.blocksizes[1], vi.blocksizes[0] / 2, vi.blocksizes[1] / 2);
            wnd[1][1][0] = window(vi.blocksizes[1], vi.blocksizes[1] / 2, vi.blocksizes[0] / 2);
            wnd[1][1][1] = window(vi.blocksizes[1], vi.blocksizes[1] / 2, vi.blocksizes[1] / 2);

            fullbooks = new CodeBook[vi.books];
            for (int i = 0; i < vi.books; i++)
            {
                fullbooks[i] = new CodeBook();
                fullbooks[i].init_decode(vi.book_param[i]);
            }

            // initialize the storage vectors to a decent size greater than the minimum

            pcm_storage = 8192;             // we'll assume later that we have a minimum of twice
            // the blocksize of accumulated samples in analysis
            pcm = new float[vi.channels][];
            for (int i = 0; i < vi.channels; i++)
            {
                pcm[i] = new float[pcm_storage];
            }

            // all 1 (large block) or 0 (small block)
            // explicitly set for the sake of clarity
            lW = 0;             // previous window size
            W  = 0;             // current window size

            // all vector indexes; multiples of samples_per_envelope_step
            centerW     = vi.blocksizes[1] / 2;
            pcm_current = centerW;

            // initialize all the mapping/backend lookups
            mode = new Object[vi.modes];

            for (int i = 0; i < vi.modes; i++)
            {
                int         mapnum  = vi.mode_param[i].mapping;
                FuncMapping mapping = vi.map_funcs[mapnum];

                mode[i] = mapping.look(this, vi.mode_param[i], vi.map_param[mapnum]);
            }
        }
Example #5
0
        public int blocksize(Packet op)
        {
            csBuffer opb = new csBuffer();

            opb.readinit(op.packet_base, op.packet, op.bytes);

            /* Check the packet type */
            if (opb.read(1) != 0)
            {
                return(OV_ENOTAUDIO);
            }

            int modebits = VUtils.ilog2(modes);
            int mode     = opb.read(modebits);

            return(blocksizes[mode_param[mode].blockflag]);
        }
Example #6
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);
        }
Example #7
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);
        }
Example #8
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);
        }