Example #1
0
        VorbisInfoFloor UnpackFloor0(OggBitStream input)
        {
            var info     = new VorbisInfoFloor();
            int order    = input.ReadBits(8);
            int rate     = input.ReadBits(16);
            int barkmap  = input.ReadBits(16);
            int ampbits  = input.ReadBits(6);
            int ampdB    = input.ReadBits(8);
            int numbooks = input.ReadBits(4) + 1;

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

            for (int j = 0; j < numbooks; ++j)
            {
                int books = input.ReadByte();
                if (books < 0 || books >= CodecSetup.Books)
                {
                    return(null);
                }
            }
            return(info);
        }
Example #2
0
        VorbisInfoMapping UnpackMapping(OggBitStream input)
        {
            var info = new VorbisInfoMapping();

            int b = input.ReadBits(1);

            if (b < 0)
            {
                return(null);
            }
            if (b > 0)
            {
                info.submaps = input.ReadBits(4) + 1;
                if (info.submaps <= 0)
                {
                    return(null);
                }
            }
            else
            {
                info.submaps = 1;
            }

            b = input.ReadBits(1);
            if (b < 0)
            {
                return(null);
            }
            if (b > 0)
            {
                info.coupling_steps = input.ReadBits(8) + 1;
                if (info.coupling_steps <= 0)
                {
                    return(null);
                }
                for (int i = 0; i < info.coupling_steps; ++i)
                {
                    int bits  = CountBits((uint)Channels);
                    int testM = input.ReadBits(bits);
                    int testA = input.ReadBits(bits);
                    if (testM < 0 || testA < 0 || testM == testA ||
                        testM >= Channels || testA >= Channels)
                    {
                        return(null);
                    }
                }
            }

            if (input.ReadBits(2) != 0)
            {
                return(null);
            }

            if (info.submaps > 1)
            {
                for (int i = 0; i < Channels; ++i)
                {
                    int chmuxlist = input.ReadBits(4);
                    if (chmuxlist >= info.submaps || chmuxlist < 0)
                    {
                        return(null);
                    }
                }
            }
            for (int i = 0; i < info.submaps; ++i)
            {
                input.ReadByte(); // time submap unused
                int floorsubmap = input.ReadByte();
                if (floorsubmap >= CodecSetup.Floors || floorsubmap < 0)
                {
                    return(null);
                }
                int residuesubmap = input.ReadByte();
                if (residuesubmap >= CodecSetup.Residues || residuesubmap < 0)
                {
                    return(null);
                }
            }
            return(info);
        }