예제 #1
0
파일: Floor0.cs 프로젝트: YJh2046/BlockFun
		override public Object unpack(Info vi , csBuffer 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))
			{
				//free_info(info);
				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)
				{
					//free_info(info);
					return(null);
				}
			}
			return(info);  
			//  err_out:
			//    free_info(info);
			//    return(NULL);
		}
예제 #2
0
		override public 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+=icount(cascade);
			}

			for(int j=0;j<acc;j++)
			{
				info.booklist[j]=opb.read(8);
				//    if(info.booklist[j]==255)info.booklist[j]=-1;
			}

			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);
			//  errout:
			//    free_info(info);
			//    return(NULL);
		}
예제 #3
0
        internal int unpack(csBuffer opb)
        {
            int vendorlen = opb.read(32);

            if (vendorlen < 0)
            {
                //goto err_out;
                clear();
                return(-1);
            }
            vendor = new byte[vendorlen + 1];
            opb.read(vendor, vendorlen);
            comments = opb.read(32);
            if (comments < 0)
            {
                //goto err_out;
                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)
                {
                    //goto err_out;
                    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)
            {
                //goto err_out; // EOP check
                clear();
                return(-1);
            }
            return(0);
            //  err_out:
            //    comment_clear(vc);
            //    return(-1);
        }
예제 #4
0
        // The Vorbis header is in three packets; the initial small packet in
        // the first page that identifies basic parameters, a second packet
        // with bitstream comments and a third packet that holds the
        // codebook.

        public int synthesis_headerin(Comment vc, Packet op)
        {
            csBuffer opb = new csBuffer();

            if (op != null)
            {
                opb.readinit(op.packet_base, op.packet, op.bytes);

                // Which of the three types of header is this?
                // Also verify header-ness, vorbis
                {
                    byte[] buffer   = new byte[6];
                    int    packtype = opb.read(8);
                    //memset(buffer,0,6);
                    opb.read(buffer, 6);
                    if (buffer[0] != 'v' || buffer[1] != 'o' || buffer[2] != 'r' ||
                        buffer[3] != 'b' || buffer[4] != 'i' || buffer[5] != 's')
                    {
                        // not a vorbis header
                        return(-1);
                    }
                    switch (packtype)
                    {
                    case 0x01:                     // least significant *bit* is read first
                        if (op.b_o_s == 0)
                        {
                            // Not the initial packet
                            return(-1);
                        }
                        if (rate != 0)
                        {
                            // previously initialized info header
                            return(-1);
                        }
                        return(unpack_info(opb));

                    case 0x03:                     // least significant *bit* is read first
                        if (rate == 0)
                        {
                            // um... we didn't get the initial header
                            return(-1);
                        }
                        return(vc.unpack(opb));

                    case 0x05:                     // least significant *bit* is read first
                        if (rate == 0 || vc.vendor == null)
                        {
                            // um... we didn;t get the initial header or comments yet
                            return(-1);
                        }
                        return(unpack_books(opb));

                    default:
                        // Not a valid vorbis header type
                        //return(-1);
                        break;
                    }
                }
            }
            return(-1);
        }
예제 #5
0
        // all of the real encoding details are here.  The modes, books,
        // everything
        int unpack_books(csBuffer opb)
        {
            //d* codebooks
            books = opb.read(8) + 1;

            if (book_param == null || book_param.Length != books)
            {
                book_param = new StaticCodeBook[books];
            }
            for (int i = 0; i < books; i++)
            {
                book_param[i] = new StaticCodeBook();
                if (book_param[i].unpack(opb) != 0)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }
            }

            // time backend settings
            times = opb.read(6) + 1;
            if (time_type == null || time_type.Length != times)
            {
                time_type = new int[times];
            }
            if (time_param == null || time_param.Length != times)
            {
                time_param = new Object[times];
            }
            for (int i = 0; i < times; i++)
            {
                time_type[i] = opb.read(16);
                if (time_type[i] < 0 || time_type[i] >= VI_TIMEB)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }
                time_param[i] = FuncTime.time_P[time_type[i]].unpack(this, opb);
                if (time_param[i] == null)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }
            }

            // floor backend settings
            floors = opb.read(6) + 1;
            if (floor_type == null || floor_type.Length != floors)
            {
                floor_type = new int[floors];
            }
            if (floor_param == null || floor_param.Length != floors)
            {
                floor_param = new Object[floors];
            }

            for (int i = 0; i < floors; i++)
            {
                floor_type[i] = opb.read(16);
                if (floor_type[i] < 0 || floor_type[i] >= VI_FLOORB)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }

                floor_param[i] = FuncFloor.floor_P[floor_type[i]].unpack(this, opb);
                if (floor_param[i] == null)
                {
                    //goto err_out;
                    clear();
                    return(-1);
                }
            }

            // residue backend settings
            residues = opb.read(6) + 1;

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

            if (residue_param == null || residue_param.Length != residues)
            {
                residue_param = new Object[residues];
            }

            for (int i = 0; i < residues; i++)
            {
                residue_type[i] = opb.read(16);
                if (residue_type[i] < 0 || residue_type[i] >= VI_RESB)
                {
                    //	goto err_out;
                    clear();
                    return(-1);
                }
                residue_param[i] = FuncResidue.residue_P[residue_type[i]].unpack(this, opb);
                if (residue_param[i] == null)
                {
                    //	goto err_out;
                    clear();
                    return(-1);
                }
            }

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

            // mode settings
            modes = opb.read(6) + 1;
            if (mode_param == null || mode_param.Length != modes)
            {
                mode_param = new InfoMode[modes];
            }
            for (int i = 0; i < modes; i++)
            {
                mode_param[i]               = new InfoMode();
                mode_param[i].blockflag     = opb.read(1);
                mode_param[i].windowtype    = opb.read(16);
                mode_param[i].transformtype = opb.read(16);
                mode_param[i].mapping       = opb.read(8);

                if ((mode_param[i].windowtype >= VI_WINDOWB) ||
                    (mode_param[i].transformtype >= VI_WINDOWB) ||
                    (mode_param[i].mapping >= maps))
                {
                    //      goto err_out;
                    clear();
                    return(-1);
                }
            }

            if (opb.read(1) != 1)
            {
                //goto err_out; // top level EOP check
                clear();
                return(-1);
            }

            return(0);
            // err_out:
            //  vorbis_info_clear(vi);
            //  return(-1);
        }
예제 #6
0
파일: Info.cs 프로젝트: knot3/OggSharp
        // Header packing/unpacking
        int unpack_info(csBuffer opb)
        {
            version=opb.read(32);
            if(version!=0) { return(-1); }

            channels=opb.read(8);
            rate=opb.read(32);

            bitrate_upper=opb.read(32);
            bitrate_nominal=opb.read(32);
            bitrate_lower=opb.read(32);

            blocksizes[0]=1<<opb.read(4);
            blocksizes[1]=1<<opb.read(4);

            if((rate<1) ||
                    (channels<1)||
                    (blocksizes[0]<8)||
                    (blocksizes[1]<blocksizes[0]) ||
                    (opb.read(1)!=1)) {
                //goto err_out; // EOP check
                clear();
                return(-1);
            }
            return(0);
            // err_out:
            // vorbis_info_clear(vi);
            // return(-1);
        }
예제 #7
0
파일: Info.cs 프로젝트: knot3/OggSharp
        // all of the real encoding details are here.  The modes, books,
        // everything
        int unpack_books(csBuffer opb)
        {
            //d* codebooks
            books=opb.read(8)+1;

            if(book_param==null || book_param.Length!=books) {
                book_param=new StaticCodeBook[books];
            }
            for(int i=0; i<books; i++) {
                book_param[i]=new StaticCodeBook();
                if(book_param[i].unpack(opb)!=0) {
                    //goto err_out;
                    clear();
                    return(-1);
                }
            }

            // time backend settings
            times=opb.read(6)+1;
            if(time_type==null || time_type.Length!=times) { time_type=new int[times]; }
            if(time_param==null || time_param.Length!=times) {
                time_param=new Object[times];
            }
            for(int i=0; i<times; i++) {
                time_type[i]=opb.read(16);
                if(time_type[i]<0 || time_type[i]>=VI_TIMEB) {
                    //goto err_out;
                    clear();
                    return(-1);
                }
                time_param[i]=FuncTime.time_P[time_type[i]].unpack(this, opb);
                if(time_param[i]==null) {
                    //goto err_out;
                    clear();
                    return(-1);
                }
            }

            // floor backend settings
            floors=opb.read(6)+1;
            if(floor_type==null || floor_type.Length!=floors) {
                floor_type=new int[floors];
            }
            if(floor_param==null || floor_param.Length!=floors) {
                floor_param=new Object[floors];
            }

            for(int i=0; i<floors; i++) {
                floor_type[i]=opb.read(16);
                if(floor_type[i]<0 || floor_type[i]>=VI_FLOORB) {
                    //goto err_out;
                    clear();
                    return(-1);
                }

                floor_param[i]=FuncFloor.floor_P[floor_type[i]].unpack(this,opb);
                if(floor_param[i]==null) {
                    //goto err_out;
                    clear();
                    return(-1);
                }
            }

            // residue backend settings
            residues=opb.read(6)+1;

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

            if(residue_param==null || residue_param.Length!=residues) {
                residue_param=new Object[residues];
            }

            for(int i=0; i<residues; i++) {
                residue_type[i]=opb.read(16);
                if(residue_type[i]<0 || residue_type[i]>=VI_RESB) {
                    //	goto err_out;
                    clear();
                    return(-1);
                }
                residue_param[i]=FuncResidue.residue_P[residue_type[i]].unpack(this,opb);
                if(residue_param[i]==null) {
                    //	goto err_out;
                    clear();
                    return(-1);
                }
            }

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

            // mode settings
            modes=opb.read(6)+1;
            if(mode_param==null || mode_param.Length!=modes) {
                mode_param=new InfoMode[modes];
            }
            for(int i=0; i<modes; i++) {
                mode_param[i]=new InfoMode();
                mode_param[i].blockflag=opb.read(1);
                mode_param[i].windowtype=opb.read(16);
                mode_param[i].transformtype=opb.read(16);
                mode_param[i].mapping=opb.read(8);

                if((mode_param[i].windowtype>=VI_WINDOWB)||
                        (mode_param[i].transformtype>=VI_WINDOWB)||
                        (mode_param[i].mapping>=maps)) {
                    //      goto err_out;
                    clear();
                    return(-1);
                }
            }

            if(opb.read(1)!=1) {
                //goto err_out; // top level EOP check
                clear();
                return(-1);
            }

            return(0);
            // err_out:
            //  vorbis_info_clear(vi);
            //  return(-1);
        }
예제 #8
0
파일: Info.cs 프로젝트: knot3/OggSharp
        // The Vorbis header is in three packets; the initial small packet in
        // the first page that identifies basic parameters, a second packet
        // with bitstream comments and a third packet that holds the
        // codebook.
        public int synthesis_headerin(Comment vc, Packet op)
        {
            csBuffer opb=new csBuffer();

            if(op!=null) {
                opb.readinit(op.packet_base, op.packet, op.bytes);

                // Which of the three types of header is this?
                // Also verify header-ness, vorbis
                {
                    byte[] buffer=new byte[6];
                    int packtype=opb.read(8);
                    //memset(buffer,0,6);
                    opb.read(buffer,6);
                    if(buffer[0]!='v' || buffer[1]!='o' || buffer[2]!='r' ||
                            buffer[3]!='b' || buffer[4]!='i' || buffer[5]!='s') {
                        // not a vorbis header
                        return(-1);
                    }
                    switch(packtype) {
                    case 0x01: // least significant *bit* is read first
                        if(op.b_o_s==0) {
                            // Not the initial packet
                            return(-1);
                        }
                        if(rate!=0) {
                            // previously initialized info header
                            return(-1);
                        }
                        return(unpack_info(opb));
                    case 0x03: // least significant *bit* is read first
                        if(rate==0) {
                            // um... we didn't get the initial header
                            return(-1);
                        }
                        return(vc.unpack(opb));
                    case 0x05: // least significant *bit* is read first
                        if(rate==0 || vc.vendor==null) {
                            // um... we didn;t get the initial header or comments yet
                            return(-1);
                        }
                        return(unpack_books(opb));
                    default:
                        // Not a valid vorbis header type
                        //return(-1);
                        break;
                    }
                }
            }
            return(-1);
        }
예제 #9
0
        public int synthesis(Packet op)
        {
            Info vi = vd.vi;

            // first things first.  Make sure decode is ready
            // ripcord();
            opb.readinit(op.packet_base, op.packet, op.bytes);

            // Check the packet type
            if (opb.read(1) != 0)
            {
                // Oops.  This is not an audio data packet
                return(-1);
            }

            // read our mode and pre/post windowsize
            int _mode = opb.read(vd.modebits);

            if (_mode == -1)
            {
                return(-1);
            }

            mode = _mode;
            W    = vi.mode_param[mode].blockflag;
            if (W != 0)
            {
                lW = opb.read(1);
                nW = opb.read(1);
                if (nW == -1)
                {
                    return(-1);
                }
            }
            else
            {
                lW = 0;
                nW = 0;
            }

            // more setup
            granulepos = op.granulepos;
            sequence   = op.packetno - 3; // first block is third packet
            eofflag    = op.e_o_s;

            // alloc pcm passback storage
            pcmend = vi.blocksizes[W];
            //pcm=alloc(vi.channels);
            if (pcm.Length < vi.channels)
            {
                pcm = new float[vi.channels][];
            }
            for (int i = 0; i < vi.channels; i++)
            {
                if (pcm[i] == null || pcm[i].Length < pcmend)
                {
                    pcm[i] = new float[pcmend];
                    //pcm[i]=alloc(pcmend);
                }
                else
                {
                    for (int j = 0; j < pcmend; j++)
                    {
                        pcm[i][j] = 0;
                    }
                }
            }

            // unpack_header enforces range checking
            int type = vi.map_type[vi.mode_param[mode].mapping];

            return(FuncMapping.mapping_P[type].inverse(this, vd.mode[mode]));
        }
예제 #10
0
        override public Object unpack(Info vi, csBuffer opb)
        {
            // also responsible for range checking
            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(ilog2(vi.channels));
                    int testA = info.coupling_ang[i] = opb.read(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 */
                //goto err_out;
                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)
                    {
                        //goto err_out;
                        info.free();
                        return(null);
                    }
                }
            }

            for (int i = 0; i < info.submaps; i++)
            {
                info.timesubmap[i] = opb.read(8);
                if (info.timesubmap[i] >= vi.times)
                {
                    //goto err_out;
                    info.free();
                    return(null);
                }
                info.floorsubmap[i] = opb.read(8);
                if (info.floorsubmap[i] >= vi.floors)
                {
                    //goto err_out;
                    info.free();
                    return(null);
                }
                info.residuesubmap[i] = opb.read(8);
                if (info.residuesubmap[i] >= vi.residues)
                {
                    //goto err_out;
                    info.free();
                    return(null);
                }
            }
            return(info);
            //err_out:
            //free_info(info);
            //return(NULL);
        }
예제 #11
0
파일: Mapping0.cs 프로젝트: knot3/OggSharp
        public override Object unpack(Info vi, csBuffer opb)
        {
            // also responsible for range checking
            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(ilog2(vi.channels));
                    int testA=info.coupling_ang[i]=opb.read(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 */
                //goto err_out;
                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) {
                        //goto err_out;
                        info.free();
                        return(null);
                    }
                }
            }

            for(int i=0; i<info.submaps; i++) {
                info.timesubmap[i]=opb.read(8);
                if(info.timesubmap[i]>=vi.times) {
                    //goto err_out;
                    info.free();
                    return(null);
                }
                info.floorsubmap[i]=opb.read(8);
                if(info.floorsubmap[i]>=vi.floors) {
                    //goto err_out;
                    info.free();
                    return(null);
                }
                info.residuesubmap[i]=opb.read(8);
                if(info.residuesubmap[i]>=vi.residues) {
                    //goto err_out;
                    info.free();
                    return(null);
                }
            }
            return info;
            //err_out:
            //free_info(info);
            //return(NULL);
        }
예제 #12
0
파일: Comment.cs 프로젝트: YJh2046/BlockFun
		internal int unpack(csBuffer opb)
		{
			int vendorlen=opb.read(32);
			if(vendorlen<0)
			{
				//goto err_out;
				clear();
				return(-1);
			}
			vendor=new byte[vendorlen+1];
			opb.read(vendor,vendorlen);
			comments=opb.read(32);
			if(comments<0)
			{
				//goto err_out;
				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)
				{
					//goto err_out;
					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)
			{
				//goto err_out; // EOP check
				clear();
				return(-1);

			}
			return(0);
			//  err_out:
			//    comment_clear(vc);
			//    return(-1);
		}
예제 #13
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;
			//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(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); 
		}
예제 #14
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;

            //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(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);
        }
예제 #15
0
파일: Info.cs 프로젝트: knot3/OggSharp
        //  static void v_writestring(csBuffer o, byte[] s){
        //    int i=0;
        //    while(s[i]!=0){
        //      o.write(s[i++],8);
        //    }
        //  }
        //  static void v_readstring(csBuffer o, byte[] buf, int bytes){
        //    int i=0
        //    while(bytes--!=0){
        //      buf[i++]=o.read(8);
        //    }
        //  }
        //  private csBuffer opb_blocksize=new csBuffer();
        public int blocksize(Packet op)
        {
            //codec_setup_info     *ci=vi->codec_setup;
            csBuffer opb=new csBuffer();
            //    synchronized(opb_blocksize){
            int mode;

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

            /* Check the packet type */
            if(opb.read(1)!=0) {
                /* Oops.  This is not an audio data packet */
                return(OV_ENOTAUDIO);
            }
            {
                int modebits=0;
                int v=modes;
                while(v>1) {
                    modebits++;
                    v = (int)((uint)v >> 1);
                }

                /* read our mode and pre/post windowsize */
                mode=opb.read(modebits);
            }
            if(mode==-1) { return(OV_EBADPACKET); }
            return(blocksizes[mode_param[mode].blockflag]);
            //    }
        }
예제 #16
0
        override public Object unpack(Info vi, csBuffer 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)
                {
                    //goto err_out;
                    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)
                {
                    //goto err_out;
                    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)
                    {
                        //goto err_out;
                        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))
                    {
                        //goto err_out;
                        info.free();
                        return(null);
                    }
                }
            }
            info.postlist[0] = 0;
            info.postlist[1] = 1 << rangebits;

            return(info);
            //  err_out:
            //    info.free();
            //    return(null);
        }
예제 #17
0
파일: Floor1.cs 프로젝트: YJh2046/BlockFun
		override public Object unpack(Info vi , csBuffer 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)
				{
					//goto err_out;
					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)
				{
					//goto err_out;
					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)
					{
						//goto err_out;
						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))
					{
						//goto err_out;
						info.free();
						return(null);
					}
				}
			}
			info.postlist[0]=0;
			info.postlist[1]=1<<rangebits;

			return(info);
			//  err_out:
			//    info.free();
			//    return(null);
		}