コード例 #1
0
ファイル: Residue0.cs プロジェクト: YJh2046/BlockFun
		override public void pack(Object vr, csBuffer 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++)
			{
				if(ilog(info.secondstages[j])>3)
				{
					/* yes, this is a minor hack due to not thinking ahead */
					opb.write(info.secondstages[j],3); 
					opb.write(1,1);
					opb.write(info.secondstages[j] >> 3,5); 
				}
				else
				{
					opb.write(info.secondstages[j],4); /* trailing zero */
				}
				acc+=icount(info.secondstages[j]);
			}
			for(int j=0;j<acc;j++)
			{
				opb.write(info.booklist[j],8);
			}
		}
コード例 #2
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);
		}
コード例 #3
0
ファイル: CodeBook.cs プロジェクト: YJh2046/BlockFun
		// returns the number of bits and *modifies a* to the quantization value
		internal int encodev(int best, float[] a, csBuffer b)
		{
			for(int k=0;k<dim;k++)
			{
				a[k]=valuelist[best*dim+k];
			}
			return(encode(best,b));
		}
コード例 #4
0
ファイル: Floor0.cs プロジェクト: YJh2046/BlockFun
		override public void pack(Object i, csBuffer opb)
		{
			InfoFloor0 info=(InfoFloor0)i;
			opb.write(info.order,8);
			opb.write(info.rate,16);
			opb.write(info.barkmap,16);
			opb.write(info.ampbits,6);
			opb.write(info.ampdB,8);
			opb.write(info.numbooks-1,4);
			for(int j=0;j<info.numbooks;j++)
				opb.write(info.books[j],8);
		}
コード例 #5
0
ファイル: Mapping0.cs プロジェクト: YJh2046/BlockFun
		override public void pack(Info vi, Object imap, csBuffer opb)
		{
			InfoMapping0 info=(InfoMapping0)imap;

			/* another 'we meant to do it this way' hack...  up to beta 4, we
			   packed 4 binary zeros here to signify one submapping in use.  We
			   now redefine that to mean four bitflags that indicate use of
			   deeper features; bit0:submappings, bit1:coupling,
			   bit2,3:reserved. This is backward compatable with all actual uses
			   of the beta code. */

			if(info.submaps>1)
			{
				opb.write(1,1);
				opb.write(info.submaps-1,4);
			}
			else
			{
				opb.write(0,1);
			}

			if(info.coupling_steps>0)
			{
				opb.write(1,1);
				opb.write(info.coupling_steps-1,8);
				for(int i=0;i<info.coupling_steps;i++)
				{
					opb.write(info.coupling_mag[i],ilog2(vi.channels));
					opb.write(info.coupling_ang[i],ilog2(vi.channels));
				}
			}
			else
			{
				opb.write(0,1);
			}
  
			opb.write(0,2); /* 2,3:reserved */

			/* we don't write the channel submappings if we only have one... */
			if(info.submaps>1)
			{
				for(int i=0;i<vi.channels;i++)
					opb.write(info.chmuxlist[i],4);
			}
			for(int i=0;i<info.submaps;i++)
			{
				opb.write(info.timesubmap[i],8);
				opb.write(info.floorsubmap[i],8);
				opb.write(info.residuesubmap[i],8);
			}
		}
コード例 #6
0
ファイル: Residue0.cs プロジェクト: YJh2046/BlockFun
		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);
		}
コード例 #7
0
ファイル: Floor1.cs プロジェクト: YJh2046/BlockFun
		override public void pack(Object i, csBuffer 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(ilog2(maxposit),4);
			rangebits=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);
				}
			}
		}
コード例 #8
0
ファイル: FuncResidue.cs プロジェクト: YJh2046/BlockFun
		public abstract void pack(Object vr, csBuffer opb);
コード例 #9
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);
        }
コード例 #10
0
ファイル: Info.cs プロジェクト: knot3/OggSharp
        int pack_books(csBuffer opb)
        {
            Encoding AE = Encoding.UTF8;
            byte[] _vorbis_byt = AE.GetBytes(_vorbis);

            opb.write(0x05,8);
            opb.write(_vorbis_byt);

            // books
            opb.write(books-1,8);
            for(int i=0; i<books; i++) {
                if(book_param[i].pack(opb)!=0) {
                    //goto err_out;
                    return(-1);
                }
            }

            // times
            opb.write(times-1,6);
            for(int i=0; i<times; i++) {
                opb.write(time_type[i],16);
                FuncTime.time_P[time_type[i]].pack(this.time_param[i],opb);
            }

            // floors
            opb.write(floors-1,6);
            for(int i=0; i<floors; i++) {
                opb.write(floor_type[i],16);
                FuncFloor.floor_P[floor_type[i]].pack(floor_param[i],opb);
            }

            // residues
            opb.write(residues-1,6);
            for(int i=0; i<residues; i++) {
                opb.write(residue_type[i],16);
                FuncResidue.residue_P[residue_type[i]].pack(residue_param[i],opb);
            }

            // maps
            opb.write(maps-1,6);
            for(int i=0; i<maps; i++) {
                opb.write(map_type[i],16);
                FuncMapping.mapping_P[map_type[i]].pack(this,map_param[i],opb);
            }

            // modes
            opb.write(modes-1,6);
            for(int i=0; i<modes; i++) {
                opb.write(mode_param[i].blockflag,1);
                opb.write(mode_param[i].windowtype,16);
                opb.write(mode_param[i].transformtype,16);
                opb.write(mode_param[i].mapping,8);
            }
            opb.write(1,1);
            return(0);
            //err_out:
            //return(-1);
        }
コード例 #11
0
 public abstract Object unpack(Info info, csBuffer buffer);
コード例 #12
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);
        }
コード例 #13
0
ファイル: Comment.cs プロジェクト: YJh2046/BlockFun
		int pack(csBuffer opb)
		{
			String temp="Xiphophorus libVorbis I 20000508";

			Encoding AE = Encoding.UTF8;
			byte[] temp_byt = AE.GetBytes(temp);
			byte[] _vorbis_byt = AE.GetBytes(_vorbis);
			
			// preamble
			opb.write(0x03,8);
			opb.write(_vorbis_byt);

			// vendor
			opb.write(temp.Length,32);
			opb.write(temp_byt);

			// comments

			opb.write(comments,32);
			if(comments!=0)
			{
				for(int i=0;i<comments;i++)
				{
					if(user_comments[i]!=null)
					{
						opb.write(comment_lengths[i],32);
						opb.write(user_comments[i]);
					}
					else
					{
						opb.write(0,32);
					}
				}
			}
			opb.write(1,1);
			return(0);
		}
コード例 #14
0
ファイル: Floor1.cs プロジェクト: perivar/FindSimilarCore
        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);
        }
コード例 #15
0
ファイル: CodeBook.cs プロジェクト: YJh2046/BlockFun
		internal int decodevs_add(float[]a, int offset, csBuffer b, int n)
		{
			int step=n/dim;
			int entry;
			int i,j,o;

			if(t.Length<step)
			{
				t=new int[step];
			}

			for(i = 0; i < step; i++)
			{
				entry=decode(b);
				if(entry==-1)return(-1);
				t[i]=entry*dim;
			}
			for(i=0,o=0;i<dim;i++,o+=step)
			{
				for(j=0;j<step;j++)
				{
					a[offset+o+j]+=valuelist[t[j]+i];
				}
			}

			return(0);
		}
コード例 #16
0
ファイル: StaticCodeBook.cs プロジェクト: zzbin6210/BlockFun
        /*
         */

        // 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);
        }
コード例 #17
0
ファイル: Info.cs プロジェクト: perivar/FindSimilarCore
        int pack_books(csBuffer opb)
        {
            Encoding AE = Encoding.UTF8;

            byte[] _vorbis_byt = AE.GetBytes(_vorbis);

            opb.write(0x05, 8);
            opb.write(_vorbis_byt);

            // books
            opb.write(books - 1, 8);
            for (int i = 0; i < books; i++)
            {
                if (book_param[i].pack(opb) != 0)
                {
                    //goto err_out;
                    return(-1);
                }
            }

            // times
            opb.write(times - 1, 6);
            for (int i = 0; i < times; i++)
            {
                opb.write(time_type[i], 16);
                FuncTime.time_P[time_type[i]].pack(this.time_param[i], opb);
            }

            // floors
            opb.write(floors - 1, 6);
            for (int i = 0; i < floors; i++)
            {
                opb.write(floor_type[i], 16);
                FuncFloor.floor_P[floor_type[i]].pack(floor_param[i], opb);
            }

            // residues
            opb.write(residues - 1, 6);
            for (int i = 0; i < residues; i++)
            {
                opb.write(residue_type[i], 16);
                FuncResidue.residue_P[residue_type[i]].pack(residue_param[i], opb);
            }

            // maps
            opb.write(maps - 1, 6);
            for (int i = 0; i < maps; i++)
            {
                opb.write(map_type[i], 16);
                FuncMapping.mapping_P[map_type[i]].pack(this, map_param[i], opb);
            }

            // modes
            opb.write(modes - 1, 6);
            for (int i = 0; i < modes; i++)
            {
                opb.write(mode_param[i].blockflag, 1);
                opb.write(mode_param[i].windowtype, 16);
                opb.write(mode_param[i].transformtype, 16);
                opb.write(mode_param[i].mapping, 8);
            }
            opb.write(1, 1);
            return(0);
            //err_out:
            //return(-1);
        }
コード例 #18
0
ファイル: Info.cs プロジェクト: perivar/FindSimilarCore
        // 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);
        }
コード例 #19
0
ファイル: Info.cs プロジェクト: perivar/FindSimilarCore
        // 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);
        }
コード例 #20
0
        // res0 (multistage, interleave, lattice)
        // returns the number of bits and *modifies a* to the remainder value
        internal int encodevs(float[] a, csBuffer b, int step, int addmul)
        {
            int best = besterror(a, step, addmul);

            return(encode(best, b));
        }
コード例 #21
0
ファイル: StaticCodeBook.cs プロジェクト: YJh2046/BlockFun
		internal int pack(csBuffer opb)
		{
			int i;
			bool ordered=false;

			opb.write(0x564342,24);
			opb.write(dim, 16);
			opb.write(entries, 24);

			// pack the codewords.  There are two packings; length ordered and
			// length random.  Decide between the two now.
  
			for(i=1;i<entries;i++)
			{
				if(lengthlist[i]<lengthlist[i-1])break;
			}
			if(i==entries)ordered=true;
  
			if(ordered)
			{
				// length ordered.  We only need to say how many codewords of
				// each length.  The actual codewords are generated
				// deterministically

				int count=0;
				opb.write(1,1);               // ordered
				opb.write(lengthlist[0]-1,5); // 1 to 32

				for(i=1;i<entries;i++)
				{
					int _this=lengthlist[i];
					int _last=lengthlist[i-1];
					if(_this>_last)
					{
						for(int j=_last;j<_this;j++)
						{
							opb.write(i-count,ilog(entries-count));
							count=i;
						}
					}
				}
				opb.write(i-count,ilog(entries-count));
			}
			else
			{
				// length random.  Again, we don't code the codeword itself, just
				// the length.  This time, though, we have to encode each length
				opb.write(0,1);   // unordered
    
				// algortihmic mapping has use for 'unused entries', which we tag
				// here.  The algorithmic mapping happens as usual, but the unused
				// entry has no codeword.
				for(i=0;i<entries;i++)
				{
					if(lengthlist[i]==0)break;
				}

				if(i==entries)
				{
					opb.write(0,1); // no unused entries
					for(i=0;i<entries;i++)
					{
						opb.write(lengthlist[i]-1,5);
					}
				}
				else
				{
					opb.write(1,1); // we have unused entries; thus we tag
					for(i=0;i<entries;i++)
					{
						if(lengthlist[i]==0)
						{
							opb.write(0,1);
						}
						else
						{
							opb.write(1,1);
							opb.write(lengthlist[i]-1,5);
						}
					}
				}
			}

			// is the entry number the desired return value, or do we have a
			// mapping? If we have a mapping, what type?
			opb.write(maptype,4);
			switch(maptype)
			{
				case 0:
					// no mapping
					break;
				case 1:
				case 2:
					// implicitly populated value mapping
					// explicitly populated value mapping
					if(quantlist==null)
					{
						// no quantlist?  error
						return(-1);
					}
    
					// values that define the dequantization
					opb.write(q_min,32);
					opb.write(q_delta,32);
					opb.write(q_quant-1,4);
					opb.write(q_sequencep,1);
    
				{
					int quantvals=0;
					switch(maptype)
					{
						case 1:
							// a single column of (c->entries/c->dim) quantized values for
							// building a full value list algorithmically (square lattice)
							quantvals=maptype1_quantvals();
							break;
						case 2:
							// every value (c->entries*c->dim total) specified explicitly
							quantvals=entries*dim;
							break;
					}

					// quantized values
					for(i=0;i<quantvals;i++)
					{
						opb.write(Math.Abs(quantlist[i]),q_quant);
					}
				}
					break;
				default:
					// error case; we don't have any other map types now
					return(-1);
			}
			return(0);
		}
コード例 #22
0
ファイル: CodeBook.cs プロジェクト: YJh2046/BlockFun
		// res0 (multistage, interleave, lattice)
		// returns the number of bits and *modifies a* to the remainder value
		internal int encodevs(float[] a, csBuffer b, int step,int addmul)
		{
			int best=besterror(a,step,addmul);
			return(encode(best,b));
		}
コード例 #23
0
ファイル: StaticCodeBook.cs プロジェクト: zzbin6210/BlockFun
        internal int pack(csBuffer opb)
        {
            int  i;
            bool ordered = false;

            opb.write(0x564342, 24);
            opb.write(dim, 16);
            opb.write(entries, 24);

            // pack the codewords.  There are two packings; length ordered and
            // length random.  Decide between the two now.

            for (i = 1; i < entries; i++)
            {
                if (lengthlist[i] < lengthlist[i - 1])
                {
                    break;
                }
            }
            if (i == entries)
            {
                ordered = true;
            }

            if (ordered)
            {
                // length ordered.  We only need to say how many codewords of
                // each length.  The actual codewords are generated
                // deterministically

                int count = 0;
                opb.write(1, 1);                              // ordered
                opb.write(lengthlist[0] - 1, 5);              // 1 to 32

                for (i = 1; i < entries; i++)
                {
                    int _this = lengthlist[i];
                    int _last = lengthlist[i - 1];
                    if (_this > _last)
                    {
                        for (int j = _last; j < _this; j++)
                        {
                            opb.write(i - count, ilog(entries - count));
                            count = i;
                        }
                    }
                }
                opb.write(i - count, ilog(entries - count));
            }
            else
            {
                // length random.  Again, we don't code the codeword itself, just
                // the length.  This time, though, we have to encode each length
                opb.write(0, 1);                  // unordered

                // algortihmic mapping has use for 'unused entries', which we tag
                // here.  The algorithmic mapping happens as usual, but the unused
                // entry has no codeword.
                for (i = 0; i < entries; i++)
                {
                    if (lengthlist[i] == 0)
                    {
                        break;
                    }
                }

                if (i == entries)
                {
                    opb.write(0, 1);                    // no unused entries
                    for (i = 0; i < entries; i++)
                    {
                        opb.write(lengthlist[i] - 1, 5);
                    }
                }
                else
                {
                    opb.write(1, 1);                    // we have unused entries; thus we tag
                    for (i = 0; i < entries; i++)
                    {
                        if (lengthlist[i] == 0)
                        {
                            opb.write(0, 1);
                        }
                        else
                        {
                            opb.write(1, 1);
                            opb.write(lengthlist[i] - 1, 5);
                        }
                    }
                }
            }

            // is the entry number the desired return value, or do we have a
            // mapping? If we have a mapping, what type?
            opb.write(maptype, 4);
            switch (maptype)
            {
            case 0:
                // no mapping
                break;

            case 1:
            case 2:
                // implicitly populated value mapping
                // explicitly populated value mapping
                if (quantlist == null)
                {
                    // no quantlist?  error
                    return(-1);
                }

                // values that define the dequantization
                opb.write(q_min, 32);
                opb.write(q_delta, 32);
                opb.write(q_quant - 1, 4);
                opb.write(q_sequencep, 1);

                {
                    int quantvals = 0;
                    switch (maptype)
                    {
                    case 1:
                        // a single column of (c->entries/c->dim) quantized values for
                        // building a full value list algorithmically (square lattice)
                        quantvals = maptype1_quantvals();
                        break;

                    case 2:
                        // every value (c->entries*c->dim total) specified explicitly
                        quantvals = entries * dim;
                        break;
                    }

                    // quantized values
                    for (i = 0; i < quantvals; i++)
                    {
                        opb.write(Math.Abs(quantlist[i]), q_quant);
                    }
                }
                break;

            default:
                // error case; we don't have any other map types now
                return(-1);
            }
            return(0);
        }
コード例 #24
0
ファイル: StaticCodeBook.cs プロジェクト: YJh2046/BlockFun
		/*
		*/

		// 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); 
		}
コード例 #25
0
 public abstract Object unpack(Info vi, csBuffer opb);
コード例 #26
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);
		}
コード例 #27
0
ファイル: FuncMapping.cs プロジェクト: knot3/OggSharp
 public abstract void pack(Info info , Object imap, csBuffer buffer);
コード例 #28
0
ファイル: Comment.cs プロジェクト: YJh2046/BlockFun
		public int header_out(Packet op)
		{
			csBuffer opb=new csBuffer();
			opb.writeinit();

			if(pack(opb)!=0) return OV_EIMPL;

			op.packet_base = new byte[opb.bytes()];
			op.packet=0;
			op.bytes=opb.bytes();
			Array.Copy(opb.buf(), 0, op.packet_base, 0, op.bytes);
			op.b_o_s=0;
			op.e_o_s=0;
			op.granulepos=0;
			return 0;
		}
コード例 #29
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]);
            //    }
        }
コード例 #30
0
 public abstract void pack(Object vr, csBuffer opb);
コード例 #31
0
 public abstract void pack(Info info, Object imap, csBuffer buffer);
コード例 #32
0
ファイル: Mapping0.cs プロジェクト: zzbin6210/BlockFun
        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);
        }
コード例 #33
0
ファイル: CodeBook.cs プロジェクト: YJh2046/BlockFun
		internal int decodev_set(float[] a,int offset, csBuffer b, int n)
		{
			int i,j,entry;
			int t;

			for(i=0;i<n;)
			{
				entry = decode(b);
				if(entry==-1)return(-1);
				t=entry*dim;
				for(j=0;j<dim;)
				{
					a[offset+i++]=valuelist[t+(j++)];
				}
			}
			return(0);
		}
コード例 #34
0
ファイル: FuncMapping.cs プロジェクト: knot3/OggSharp
 public abstract Object unpack(Info info , csBuffer buffer);
コード例 #35
0
ファイル: CodeBook.cs プロジェクト: YJh2046/BlockFun
		internal int decodevv_add(float[][] a, int offset,int ch, csBuffer b,int n)
		{
			int i,j,entry;
			int chptr=0;
			//System.out.println("decodevv_add: a="+a+",b="+b+",valuelist="+valuelist);

			for(i=offset/ch;i<(offset+n)/ch;)
			{
				entry = decode(b);
				if(entry==-1)return(-1);

				int t = entry*dim;
				for(j=0;j<dim;j++)
				{
					a[chptr][i]+=valuelist[t+j];
					chptr++;
					if(chptr==ch)
					{
						chptr=0;
						i++;
					}
				}
			}
			return(0);
		}
コード例 #36
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);
        }
コード例 #37
0
ファイル: CodeBook.cs プロジェクト: YJh2046/BlockFun
		// Decode side is specced and easier, because we don't need to find
		// matches using different criteria; we simply read and map.  There are
		// two things we need to do 'depending':
		//   
		// We may need to support interleave.  We don't really, but it's
		// convenient to do it here rather than rebuild the vector later.
		//
		// Cascades may be additive or multiplicitive; this is not inherent in
		// the codebook, but set in the code using the codebook.  Like
		// interleaving, it's easiest to do it here.  
		// stage==0 -> declarative (set the value)
		// stage==1 -> additive
		// stage==2 -> multiplicitive

		// returns the entry number or -1 on eof
		internal int decode(csBuffer b)
		{
			int ptr=0;
			DecodeAux t=decode_tree;
			int lok=b.look(t.tabn);
			//System.err.println(this+" "+t+" lok="+lok+", tabn="+t.tabn);

			if(lok>=0)
			{
				ptr=t.tab[lok];
				b.adv(t.tabl[lok]);
				if(ptr<=0)
				{
					return -ptr;
				}
			}
			do
			{
				switch(b.read1())
				{
					case 0:
						ptr=t.ptr0[ptr];
						break;
					case 1:
						ptr=t.ptr1[ptr];
						break;
					case -1:
					default:
						return(-1);
				}
			}
			while(ptr>0);
			return(-ptr);
		}
コード例 #38
0
ファイル: Info.cs プロジェクト: knot3/OggSharp
        // pack side
        int pack_info(csBuffer opb)
        {
            Encoding AE = Encoding.UTF8;
            byte[] _vorbis_byt = AE.GetBytes(_vorbis);

            // preamble
            opb.write(0x01,8);
            opb.write(_vorbis_byt);

            // basic information about the stream
            opb.write(0x00,32);
            opb.write(channels,8);
            opb.write(rate,32);

            opb.write(bitrate_upper,32);
            opb.write(bitrate_nominal,32);
            opb.write(bitrate_lower,32);

            opb.write(ilog2(blocksizes[0]),4);
            opb.write(ilog2(blocksizes[1]),4);
            opb.write(1,1);
            return(0);
        }
コード例 #39
0
ファイル: CodeBook.cs プロジェクト: YJh2046/BlockFun
		// returns the entry number or -1 on eof
		internal int decodevs(float[] a, int index, csBuffer b, int step,int addmul)
		{
			int entry=decode(b);
			if(entry==-1)return(-1);
			switch(addmul)
			{
				case -1:
					for(int i=0,o=0;i<dim;i++,o+=step)
						a[index+o]=valuelist[entry*dim+i];
					break;
				case 0:
					for(int i=0,o=0;i<dim;i++,o+=step)
						a[index+o]+=valuelist[entry*dim+i];
					break;
				case 1:
					for(int i=0,o=0;i<dim;i++,o+=step)
						a[index+o]*=valuelist[entry*dim+i];
					break;
				default:
				//nothing
					break;
			}
			return(entry);
		}
コード例 #40
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);
        }
コード例 #41
0
ファイル: CodeBook.cs プロジェクト: YJh2046/BlockFun
		// returns the number of bits
		internal int encode(int a, csBuffer b)
		{
			b.write(codelist[a], c.lengthlist[a]);
			return(c.lengthlist[a]);
		}
コード例 #42
0
ファイル: FuncResidue.cs プロジェクト: YJh2046/BlockFun
		public abstract Object unpack(Info vi, csBuffer opb);
コード例 #43
0
 // returns the number of bits
 internal int encode(int a, csBuffer b)
 {
     b.write(codelist[a], c.lengthlist[a]);
     return(c.lengthlist[a]);
 }