Exemple #1
0
        override internal 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 i      = info.secondstages[j];
                int stages = Util.ilog(i);
                if (stages != 0)
                {
                    if (stages > maxstage)
                    {
                        maxstage = stages;
                    }
                    look.partbooks[j] = new int[stages];
                    for (int k = 0; k < stages; k++)
                    {
                        if ((i & (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);
        }
Exemple #2
0
        override internal Object unpack(Info vi, NVorbis.Ogg.BBuffer 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 += Util.icount(cascade);
            }

            for (int j = 0; j < acc; j++)
            {
                info.booklist[j] = opb.Read(8);
            }

            if (info.groupbook >= vi.Books)
            {
                free_info(info);
                return(null);
            }

            for (int j = 0; j < acc; j++)
            {
                if (info.booklist[j] >= vi.Books)
                {
                    free_info(info);
                    return(null);
                }
            }
            return(info);
        }
Exemple #3
0
        override internal void pack(Object vr, NVorbis.Ogg.BBuffer opb)
        {
            InfoResidue0 info = (InfoResidue0)vr;
            int          acc  = 0;

            opb.Write(info.begin, 24);
            opb.Write(info.end, 24);

            opb.Write(info.grouping - 1, 24);         /* residue vectors to group and
                                                      *  code with a partitioned book */
            opb.Write(info.partitions - 1, 6);        /* possible partition choices */
            opb.Write(info.groupbook, 8);             /* group huffman book */

            /* secondstages is a bitmask; as encoding progresses pass by pass, a
             * bitmask of one indicates this partition class has bits to write
             * this pass */
            for (int j = 0; j < info.partitions; j++)
            {
                int i = info.secondstages[j];
                if (Util.ilog(i) > 3)
                {
                    /* yes, this is a minor hack due to not thinking ahead */
                    opb.Write(i, 3);
                    opb.Write(1, 1);
                    opb.Write((int)(((uint)i) >> 3), 5);
                }
                else
                {
                    opb.Write(i, 4);                     /* trailing zero */
                }
                acc += Util.icount(i);
            }
            for (int j = 0; j < acc; j++)
            {
                opb.Write(info.booklist[j], 8);
            }
        }
Exemple #4
0
        internal override Object unpack(Info vi, NVorbis.Ogg.BBuffer 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 += Util.icount(cascade);
            }

            for (int j = 0; j < acc; j++)
            {
                info.booklist[j] = opb.Read(8);
            }

            if (info.groupbook >= vi.Books)
            {
                free_info(info);
                return (null);
            }

            for (int j = 0; j < acc; j++)
            {
                if (info.booklist[j] >= vi.Books)
                {
                    free_info(info);
                    return (null);
                }
            }
            return (info);
        }
Exemple #5
0
        static internal int _2inverse(Block vb, Object vl, float[][] In, int ch)
        {
            lock (StatickLock)
            {
                int          i, k, l, s;
                LookResidue0 look = (LookResidue0)vl;
                InfoResidue0 info = look.info;

                // move all this setup out later
                int samples_per_partition = info.grouping;
                int partitions_per_word   = look.phrasebook.dim;
                int n = info.end - info.begin;

                int partvals  = n / samples_per_partition;
                int partwords = (partvals + partitions_per_word - 1) / partitions_per_word;

                if (_2inverse_partword == null || _2inverse_partword.Length < partwords)
                {
                    _2inverse_partword = new int[partwords][];
                }
                for (s = 0; s < look.stages; s++)
                {
                    for (i = 0, l = 0; i < partvals; l++)
                    {
                        if (s == 0)
                        {
                            // fetch the partition word for each channel
                            int temp = look.phrasebook.decode(vb.opb);
                            if (temp == -1)
                            {
                                return(0);
                            }
                            _2inverse_partword[l] = look.decodemap[temp];
                            if (_2inverse_partword[l] == null)
                            {
                                return(0);
                            }
                        }

                        // now we decode residual values for the partitions
                        for (k = 0; k < partitions_per_word && i < partvals; k++, i++)
                        {
                            int offset = info.begin + i * samples_per_partition;
                            int index  = _2inverse_partword[l][k];
                            if ((info.secondstages[index] & (1 << s)) != 0)
                            {
                                CodeBook stagebook = look.fullbooks[look.partbooks[index][s]];
                                if (stagebook != null)
                                {
                                    if (stagebook.decodevv_add(In, offset, ch, vb.opb,
                                                               samples_per_partition) == -1)
                                    {
                                        return(0);
                                    }
                                }
                            }
                        }
                    }
                }
                return(0);
            }
        }