Esempio n. 1
0
            internal Object copy_info()
            {
                InfoFloor1 info = this;
                InfoFloor1 ret  = new InfoFloor1();

                ret.Partitions = info.Partitions;
                Array.Copy(info.Partitionclass, 0, ret.Partitionclass, 0, VIF_PARTS);
                Array.Copy(info.class_dim, 0, ret.class_dim, 0, VIF_CLASS);
                Array.Copy(info.class_subs, 0, ret.class_subs, 0, VIF_CLASS);
                Array.Copy(info.class_book, 0, ret.class_book, 0, VIF_CLASS);

                for (int j = 0; j < VIF_CLASS; j++)
                {
                    Array.Copy(info.class_subbook[j], 0, ret.class_subbook[j], 0, 8);
                }

                ret.mult = info.mult;
                Array.Copy(info.postlist, 0, ret.postlist, 0, VIF_POSIT + 2);

                ret.maxover  = info.maxover;
                ret.maxunder = info.maxunder;
                ret.maxerr   = info.maxerr;

                ret.twofitminsize = info.twofitminsize;
                ret.twofitminused = info.twofitminused;
                ret.twofitweight  = info.twofitweight;
                ret.twofitatten   = info.twofitatten;
                ret.unusedminsize = info.unusedminsize;
                ret.unusedmin_n   = info.unusedmin_n;

                ret.n = info.n;

                return(ret);
            }
Esempio n. 2
0
        override internal void pack(Object i, NVorbis.Ogg.BBuffer opb)
        {
            InfoFloor1 info = (InfoFloor1)i;

            int count = 0;
            int rangebits;
            int maxposit = info.postlist[1];
            int maxclass = -1;

            /* save out partitions */
            opb.Write(info.Partitions, 5);             /* only 0 to 31 legal */
            for (int j = 0; j < info.Partitions; j++)
            {
                opb.Write(info.Partitionclass[j], 4);                 /* only 0 to 15 legal */
                if (maxclass < info.Partitionclass[j])
                {
                    maxclass = info.Partitionclass[j];
                }
            }

            /* save out partition classes */
            for (int j = 0; j < maxclass + 1; j++)
            {
                opb.Write(info.class_dim[j] - 1, 3);              /* 1 to 8 */
                opb.Write(info.class_subs[j], 2);                 /* 0 to 3 */
                if (info.class_subs[j] != 0)
                {
                    opb.Write(info.class_book[j], 8);
                }
                for (int k = 0; k < (1 << info.class_subs[j]); k++)
                {
                    opb.Write(info.class_subbook[j][k] + 1, 8);
                }
            }

            /* save out the post list */
            opb.Write(info.mult - 1, 2);             /* only 1,2,3,4 legal now */
            opb.Write(Util.ilog2(maxposit), 4);
            rangebits = Util.ilog2(maxposit);

            for (int j = 0, k = 0; j < info.Partitions; j++)
            {
                count += info.class_dim[info.Partitionclass[j]];
                for (; k < count; k++)
                {
                    opb.Write(info.postlist[k + 2], rangebits);
                }
            }
        }
Esempio n. 3
0
        override internal int inverse2(Block vb, Object i, Object memo, float[] Out)
        {
            LookFloor1 look = (LookFloor1)i;
            InfoFloor1 info = look.vi;
            int        n    = vb.vd.vi.blocksizes[vb.mode] / 2;

            if (memo != null)
            {
                /* render the lines */
                int[] fit_value = (int[])memo;
                int   hx        = 0;
                int   lx        = 0;
                int   ly        = fit_value[0] * info.mult;
                for (int j = 1; j < look.posts; j++)
                {
                    int current = look.forward_index[j];
                    int hy      = fit_value[current] & 0x7fff;
                    if (hy == fit_value[current])
                    {
                        hy *= info.mult;
                        hx  = info.postlist[current];

                        RenderLine(lx, hx, ly, hy, Out);

                        lx = hx;
                        ly = hy;
                    }
                }
                for (int j = hx; j < n; j++)
                {
                    Out[j] *= Out[j - 1];                     /* be certain */
                }
                return(1);
            }
            for (int j = 0; j < n; j++)
            {
                Out[j] = 0.0f;
            }
            return(0);
        }
Esempio n. 4
0
        override internal Object unpack(Info vi, NVorbis.Ogg.BBuffer opb)
        {
            int        count = 0, maxclass = -1, rangebits;
            InfoFloor1 info = new InfoFloor1();

            /* read partitions */
            info.Partitions = opb.Read(5);             /* only 0 to 31 legal */
            for (int j = 0; j < info.Partitions; j++)
            {
                info.Partitionclass[j] = opb.Read(4);                 /* only 0 to 15 legal */
                if (maxclass < info.Partitionclass[j])
                {
                    maxclass = info.Partitionclass[j];
                }
            }

            /* read partition classes */
            for (int j = 0; j < maxclass + 1; j++)
            {
                info.class_dim[j]  = opb.Read(3) + 1;             /* 1 to 8 */
                info.class_subs[j] = opb.Read(2);                 /* 0,1,2,3 bits */
                if (info.class_subs[j] < 0)
                {
                    info.free();
                    return(null);
                }
                if (info.class_subs[j] != 0)
                {
                    info.class_book[j] = opb.Read(8);
                }
                if (info.class_book[j] < 0 || info.class_book[j] >= vi.Books)
                {
                    info.free();
                    return(null);
                }
                for (int k = 0; k < (1 << info.class_subs[j]); k++)
                {
                    info.class_subbook[j][k] = opb.Read(8) - 1;
                    if (info.class_subbook[j][k] < -1 || info.class_subbook[j][k] >= vi.Books)
                    {
                        info.free();
                        return(null);
                    }
                }
            }

            /* read the post list */
            info.mult = opb.Read(2) + 1;             /* only 1,2,3,4 legal now */
            rangebits = opb.Read(4);

            for (int j = 0, k = 0; j < info.Partitions; j++)
            {
                count += info.class_dim[info.Partitionclass[j]];
                for (; k < count; k++)
                {
                    int t = info.postlist[k + 2] = opb.Read(rangebits);
                    if (t < 0 || t >= (1 << rangebits))
                    {
                        info.free();
                        return(null);
                    }
                }
            }
            info.postlist[0] = 0;
            info.postlist[1] = 1 << rangebits;

            return(info);
        }
Esempio n. 5
0
        override internal 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(Util.ilog(look.quant_q - 1));
                fit_value[1] = vb.opb.Read(Util.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;
                    uint cval     = 0;

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

                        if (unchecked (cval == (uint)(-1)))
                        {
                            return(null);
                        }
                    }

                    for (int k = 0; k < cdim; k++)
                    {
                        int book = info.class_subbook[clss][cval & (csub - 1)];
                        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);
            }

            return(null);
        }
Esempio n. 6
0
        override internal Object look(DspState vd, InfoMode mi, Object i)
        {
            int _n = 0;

            int[] sortpointer = new int[VIF_POSIT + 2];

            //    Info vi=vd.vi;

            InfoFloor1 info = (InfoFloor1)i;
            LookFloor1 look = new LookFloor1();

            look.vi = info;
            look.n  = info.postlist[1];

            /* we drop each position value in-between already decoded values,
             * and use linear interpolation to predict each new value past the
             * edges.  The positions are read in the order of the position
             * list... we precompute the bounding positions in the lookup.  Of
             * course, the neighbors can change (if a position is declined), but
             * this is an initial mapping */

            for (int j = 0; j < info.Partitions; j++)
            {
                _n += info.class_dim[info.Partitionclass[j]];
            }
            _n        += 2;
            look.posts = _n;

            /* also store a sorted position index */
            for (int j = 0; j < _n; j++)
            {
                sortpointer[j] = j;
            }
            //    qsort(sortpointer,n,sizeof(int),icomp); // !!

            int foo;

            for (int j = 0; j < _n - 1; j++)
            {
                for (int k = j; k < _n; k++)
                {
                    if (info.postlist[sortpointer[j]] > info.postlist[sortpointer[k]])
                    {
                        foo            = sortpointer[k];
                        sortpointer[k] = sortpointer[j];
                        sortpointer[j] = foo;
                    }
                }
            }

            /* points from sort order back to range number */
            for (int j = 0; j < _n; j++)
            {
                look.forward_index[j] = sortpointer[j];
            }
            /* points from range order to sorted position */
            for (int j = 0; j < _n; j++)
            {
                look.reverse_index[look.forward_index[j]] = j;
            }
            /* we actually need the post values too */
            for (int j = 0; j < _n; j++)
            {
                look.sorted_index[j] = info.postlist[look.forward_index[j]];
            }

            /* quantize values to multiplier spec */
            switch (info.mult)
            {
            case 1:                     /* 1024 -> 256 */
                look.quant_q = 256;
                break;

            case 2:                     /* 1024 -> 128 */
                look.quant_q = 128;
                break;

            case 3:                     /* 1024 -> 86 */
                look.quant_q = 86;
                break;

            case 4:                     /* 1024 -> 64 */
                look.quant_q = 64;
                break;

            default:
                look.quant_q = -1;
                break;
            }

            /* discover our neighbors for decode where we don't use fit flags
             * (that would push the neighbors outward) */
            for (int j = 0; j < _n - 2; j++)
            {
                int lo       = 0;
                int hi       = 1;
                int lx       = 0;
                int hx       = look.n;
                int currentx = info.postlist[j + 2];
                for (int k = 0; k < j + 2; k++)
                {
                    int x = info.postlist[k];
                    if (x > lx && x < currentx)
                    {
                        lo = k;
                        lx = x;
                    }
                    if (x < hx && x > currentx)
                    {
                        hi = k;
                        hx = x;
                    }
                }
                look.loneighbor[j] = lo;
                look.hineighbor[j] = hi;
            }

            return(look);
        }
Esempio n. 7
0
            internal Object copy_info()
            {
                InfoFloor1 info = this;
                InfoFloor1 ret = new InfoFloor1();

                ret.Partitions = info.Partitions;
                Array.Copy(info.Partitionclass, 0, ret.Partitionclass, 0, VIF_PARTS);
                Array.Copy(info.class_dim, 0, ret.class_dim, 0, VIF_CLASS);
                Array.Copy(info.class_subs, 0, ret.class_subs, 0, VIF_CLASS);
                Array.Copy(info.class_book, 0, ret.class_book, 0, VIF_CLASS);

                for (int j = 0; j < VIF_CLASS; j++)
                {
                    Array.Copy(info.class_subbook[j], 0, ret.class_subbook[j], 0, 8);
                }

                ret.mult = info.mult;
                Array.Copy(info.postlist, 0, ret.postlist, 0, VIF_POSIT + 2);

                ret.maxover = info.maxover;
                ret.maxunder = info.maxunder;
                ret.maxerr = info.maxerr;

                ret.twofitminsize = info.twofitminsize;
                ret.twofitminused = info.twofitminused;
                ret.twofitweight = info.twofitweight;
                ret.twofitatten = info.twofitatten;
                ret.unusedminsize = info.unusedminsize;
                ret.unusedmin_n = info.unusedmin_n;

                ret.n = info.n;

                return (ret);
            }
Esempio n. 8
0
        internal override Object unpack(Info vi, NVorbis.Ogg.BBuffer opb)
        {
            int count = 0, maxclass = -1, rangebits;
            InfoFloor1 info = new InfoFloor1();

            /* read partitions */
            info.Partitions = opb.Read(5); /* only 0 to 31 legal */
            for (int j = 0; j < info.Partitions; j++)
            {
                info.Partitionclass[j] = opb.Read(4); /* only 0 to 15 legal */
                if (maxclass < info.Partitionclass[j])
                    maxclass = info.Partitionclass[j];
            }

            /* read partition classes */
            for (int j = 0; j < maxclass + 1; j++)
            {
                info.class_dim[j] = opb.Read(3) + 1; /* 1 to 8 */
                info.class_subs[j] = opb.Read(2); /* 0,1,2,3 bits */
                if (info.class_subs[j] < 0)
                {
                    info.free();
                    return (null);
                }
                if (info.class_subs[j] != 0)
                {
                    info.class_book[j] = opb.Read(8);
                }
                if (info.class_book[j] < 0 || info.class_book[j] >= vi.Books)
                {
                    info.free();
                    return (null);
                }
                for (int k = 0; k < (1 << info.class_subs[j]); k++)
                {
                    info.class_subbook[j][k] = opb.Read(8) - 1;
                    if (info.class_subbook[j][k] < -1 || info.class_subbook[j][k] >= vi.Books)
                    {
                        info.free();
                        return (null);
                    }
                }
            }

            /* read the post list */
            info.mult = opb.Read(2) + 1; /* only 1,2,3,4 legal now */
            rangebits = opb.Read(4);

            for (int j = 0, k = 0; j < info.Partitions; j++)
            {
                count += info.class_dim[info.Partitionclass[j]];
                for (; k < count; k++)
                {
                    int t = info.postlist[k + 2] = opb.Read(rangebits);
                    if (t < 0 || t >= (1 << rangebits))
                    {
                        info.free();
                        return (null);
                    }
                }
            }
            info.postlist[0] = 0;
            info.postlist[1] = 1 << rangebits;

            return (info);
        }