Beispiel #1
0
        // also responsible for range checking
        internal override Object unpack(Info vi, NVorbis.Ogg.BBuffer opb)
        {
            InfoMapping0 info = new InfoMapping0();

            if (opb.Read(1) != 0)
            {
                info.submaps = opb.Read(4) + 1;
            }
            else
            {
                info.submaps = 1;
            }

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

                for (int i = 0; i < info.coupling_steps; i++)
                {
                    int testM = info.coupling_mag[i] = opb.Read(Util.ilog2(vi.Channels));
                    int testA = info.coupling_ang[i] = opb.Read(Util.ilog2(vi.Channels));

                    if (testM < 0 || testA < 0 || testM == testA || testM >= vi.Channels
                        || testA >= vi.Channels)
                    {
                        //goto err_out;
                        info.free();
                        return (null);
                    }
                }
            }

            if (opb.Read(2) > 0)
            { /* 2,3:reserved */
                info.free();
                return (null);
            }

            if (info.submaps > 1)
            {
                for (int i = 0; i < vi.Channels; i++)
                {
                    info.chmuxlist[i] = opb.Read(4);
                    if (info.chmuxlist[i] >= info.submaps)
                    {
                        info.free();
                        return (null);
                    }
                }
            }

            for (int i = 0; i < info.submaps; i++)
            {
                info.timesubmap[i] = opb.Read(8);
                if (info.timesubmap[i] >= vi.Times)
                {
                    info.free();
                    return (null);
                }
                info.floorsubmap[i] = opb.Read(8);
                if (info.floorsubmap[i] >= vi.floors)
                {
                    info.free();
                    return (null);
                }
                info.residuesubmap[i] = opb.Read(8);
                if (info.residuesubmap[i] >= vi.residues)
                {
                    info.free();
                    return (null);
                }
            }
            return info;
        }
Beispiel #2
0
        /// <summary>
        /// Header packing/unpacking
        /// </summary>
        /// <param name="Buffer"></param>
        /// <returns></returns>
        int UnpackInfo(NVorbis.Ogg.BBuffer Buffer)
        {
            version = Buffer.Read(32);
            if (version != 0) return (-1);

            Channels = Buffer.Read(8);
            Rate = Buffer.Read(32);

            bitrate_upper = Buffer.Read(32);
            bitrate_nominal = Buffer.Read(32);
            bitrate_lower = Buffer.Read(32);

            blocksizes[0] = 1 << Buffer.Read(4);
            blocksizes[1] = 1 << Buffer.Read(4);

            if ((Rate < 1) || (Channels < 1) || (blocksizes[0] < 8) || (blocksizes[1] < blocksizes[0])
                || (Buffer.Read(1) != 1))
            {
                Clear();
                return (-1);
            }
            return (0);
        }
Beispiel #3
0
        internal int unpack(NVorbis.Ogg.BBuffer opb)
        {
            int vendorlen = opb.Read(32);
            if (vendorlen < 0)
            {
                Clear();
                return (-1);
            }
            vendor = new byte[vendorlen + 1];
            opb.Read(vendor, vendorlen);
            comments = opb.Read(32);
            if (comments < 0)
            {
                Clear();
                return (-1);
            }
            user_comments = new byte[comments + 1][];
            comment_lengths = new int[comments + 1];

            for (int i = 0; i < comments; i++)
            {
                int len = opb.Read(32);
                if (len < 0)
                {
                    Clear();
                    return (-1);
                }
                comment_lengths[i] = len;
                user_comments[i] = new byte[len + 1];
                opb.Read(user_comments[i], len);
            }
            if (opb.Read(1) != 1)
            {
                Clear();
                return (-1);

            }
            return (0);
        }
Beispiel #4
0
        /// <summary>
        /// All of the real encoding details are here.  The modes, books, everything.
        /// </summary>
        /// <param name="Buffer"></param>
        /// <returns></returns>
        int UnpackBooks(NVorbis.Ogg.BBuffer Buffer)
        {
            Books = Buffer.Read(8) + 1;

            if (BookParam == null || BookParam.Length != Books) BookParam = new StaticCodeBook[Books];

            for (int i = 0; i < Books; i++)
            {
                BookParam[i] = new StaticCodeBook();
                if (BookParam[i].unpack(Buffer) != 0)
                {
                    Clear();
                    return (-1);
                }
            }

            // time backend settings
            Times = Buffer.Read(6) + 1;
            if (TimeType == null || TimeType.Length != Times) TimeType = new int[Times];
            if (TimeParam == null || TimeParam.Length != Times) TimeParam = new Object[Times];
            for (int i = 0; i < Times; i++)
            {
                TimeType[i] = Buffer.Read(16);
                if (TimeType[i] < 0 || TimeType[i] >= VI_TIMEB)
                {
                    Clear();
                    return (-1);
                }
                TimeParam[i] = FuncTime.time_P[TimeType[i]].unpack(this, Buffer);
                if (TimeParam[i] == null)
                {
                    Clear();
                    return (-1);
                }
            }

            // floor backend settings
            floors = Buffer.Read(6) + 1;
            if (FloorType == null || FloorType.Length != floors) FloorType = new int[floors];
            if (FloorParam == null || FloorParam.Length != floors) FloorParam = new Object[floors];

            for (int i = 0; i < floors; i++)
            {
                FloorType[i] = Buffer.Read(16);
                if (FloorType[i] < 0 || FloorType[i] >= VI_FLOORB)
                {
                    Clear();
                    return (-1);
                }

                FloorParam[i] = FuncFloor.floor_P[FloorType[i]].unpack(this, Buffer);
                if (FloorParam[i] == null)
                {
                    Clear();
                    return (-1);
                }
            }

            // residue backend settings
            residues = Buffer.Read(6) + 1;

            if (residue_type == null || residue_type.Length != residues)
                residue_type = new int[residues];

            if (ResidueParam == null || ResidueParam.Length != residues)
                ResidueParam = new Object[residues];

            for (int i = 0; i < residues; i++)
            {
                residue_type[i] = Buffer.Read(16);
                if (residue_type[i] < 0 || residue_type[i] >= VI_RESB)
                {
                    Clear();
                    return (-1);
                }
                ResidueParam[i] = FuncResidue.residue_P[residue_type[i]].unpack(this, Buffer);
                if (ResidueParam[i] == null)
                {
                    Clear();
                    return (-1);
                }
            }

            // map backend settings
            maps = Buffer.Read(6) + 1;
            if (map_type == null || map_type.Length != maps)
                map_type = new int[maps];
            if (MapParam == null || MapParam.Length != maps)
                MapParam = new Object[maps];
            for (int i = 0; i < maps; i++)
            {
                map_type[i] = Buffer.Read(16);
                if (map_type[i] < 0 || map_type[i] >= VI_MAPB)
                {
                    Clear();
                    return (-1);
                }
                MapParam[i] = FuncMapping.mapping_P[map_type[i]].unpack(this, Buffer);
                if (MapParam[i] == null)
                {
                    Clear();
                    return (-1);
                }
            }

            // mode settings
            Modes = Buffer.Read(6) + 1;
            if (ModeParam == null || ModeParam.Length != Modes)
                ModeParam = new InfoMode[Modes];
            for (int i = 0; i < Modes; i++)
            {
                ModeParam[i] = new InfoMode();
                ModeParam[i].blockflag = Buffer.Read(1);
                ModeParam[i].windowtype = Buffer.Read(16);
                ModeParam[i].transformtype = Buffer.Read(16);
                ModeParam[i].mapping = Buffer.Read(8);

                if ((ModeParam[i].windowtype >= VI_WINDOWB)
                    || (ModeParam[i].transformtype >= VI_WINDOWB)
                    || (ModeParam[i].mapping >= maps))
                {
                    Clear();
                    return (-1);
                }
            }

            if (Buffer.Read(1) != 1)
            {
                Clear();
                return (-1);
            }

            return (0);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        internal override Object unpack(Info vi, NVorbis.Ogg.BBuffer opb)
        {
            InfoFloor0 info = new InfoFloor0();
            info.order = opb.Read(8);
            info.rate = opb.Read(16);
            info.barkmap = opb.Read(16);
            info.ampbits = opb.Read(6);
            info.ampdB = opb.Read(8);
            info.numbooks = opb.Read(4) + 1;

            if ((info.order < 1) || (info.rate < 1) || (info.barkmap < 1) || (info.numbooks < 1))
            {
                return (null);
            }

            for (int j = 0; j < info.numbooks; j++)
            {
                info.books[j] = opb.Read(8);
                if (info.books[j] < 0 || info.books[j] >= vi.Books)
                {
                    return (null);
                }
            }
            return (info);
        }
Beispiel #8
0
        // unpacks a codebook from the packet buffer into the codebook struct,
        // readies the codebook auxiliary structures for decode
        internal int unpack(NVorbis.Ogg.BBuffer opb)
        {
            int i;
            //memset(s,0,sizeof(static_codebook));

            // make sure alignment is correct
            if (opb.Read(24) != 0x564342)
            {
                //    goto _eofout;
                clear();
                return (-1);
            }

            // first the basic parameters
            dim = opb.Read(16);
            entries = opb.Read(24);
            if (entries == -1)
            {
                //    goto _eofout;
                clear();
                return (-1);
            }

            // 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);
                                if (num == -1)
                                {
                                    //            goto _eofout;
                                    clear();
                                    return (-1);
                                }
                                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);
                            if (num == -1)
                            {
                                //          goto _eofout;
                                clear();
                                return (-1);
                            }
                            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(Util.ilog(entries - i));
                            if (num == -1)
                            {
                                //          goto _eofout;
                                clear();
                                return (-1);
                            }
                            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);
                        }
                        if (quantlist[quantvals - 1] == -1)
                        {
                            //        goto _eofout;
                            clear();
                            return (-1);
                        }
                    }
                    break;
                default:
                    //    goto _eofout;
                    clear();
                    return (-1);
            }
            // all set
            return (0);
            //    _errout:
            //    _eofout:
            //    vorbis_staticbook_clear(s);
            //    return(-1);
        }