예제 #1
0
		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
        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);
                }
            }
        }
예제 #3
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);
				}
			}
		}
예제 #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
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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);
        }
예제 #8
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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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
        // 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);
        }
예제 #12
0
 // returns the number of bits
 internal int encode(int a, csBuffer b)
 {
     b.write(codelist[a], c.lengthlist[a]);
     return(c.lengthlist[a]);
 }
예제 #13
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);
        }
예제 #14
0
        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);
            }
        }
예제 #15
0
파일: Mapping0.cs 프로젝트: knot3/OggSharp
        public override 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);
            }
        }
예제 #16
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);
		}
예제 #17
0
		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);
		}
예제 #18
0
		// returns the number of bits
		internal int encode(int a, csBuffer b)
		{
			b.write(codelist[a], c.lengthlist[a]);
			return(c.lengthlist[a]);
		}