Пример #1
0
// if we do memset, dumb_silence() would be neater...
static int decompress8(DUMBFILE *f, signed char *data, int len, int cmwt)
{
	int blocklen, blockpos;
	byte bitwidth;
	word val;
	char d1, d2;

	memset(data, 0, len * sizeof(*data));

	while (len > 0) {
		//Read a block of compressed data:
		if (readblock(f))
			return -1;
		//Set up a few variables
		blocklen = (len < 0x8000) ? len : 0x8000; //Max block length is 0x8000 bytes
		blockpos = 0;
		bitwidth = 9;
		d1 = d2 = 0;
		//Start the decompression:
		while (blockpos < blocklen) {
			//Read a value:
			val = (word)readbits(bitwidth);
			//Check for bit width change:

			if (bitwidth < 7) { //Method 1:
				if (val == (1 << (bitwidth - 1))) {
					val = (word)readbits(3) + 1;
					bitwidth = (val < bitwidth) ? val : val + 1;
					continue;
				}
			}
			else if (bitwidth < 9) { //Method 2
				byte border = (0xFF >> (9 - bitwidth)) - 4;

				if (val > border && val <= (border + 8)) {
					val -= border;
					bitwidth = (val < bitwidth) ? val : val + 1;
					continue;
				}
			}
			else if (bitwidth == 9) { //Method 3
				if (val & 0x100) {
					bitwidth = (val + 1) & 0xFF;
					continue;
				}
			}
			else { //Illegal width, abort ?
				freeblock();
				return -1;
			}

			//Expand the value to signed byte:
			{
				char v; //The sample value:
				if (bitwidth < 8) {
					byte shift = 8 - bitwidth;
					v = (val << shift);
					v >>= shift;
				}
				else
Пример #2
0
int32_t entropy_decode_value(alac_file* alac,
                             int readSampleSize,
                             int k,
                             int rice_kmodifier_mask)
{
    int32_t x = 0; // decoded value

    // read x, number of 1s before 0 represent the rice value.
    while (x <= RICE_THRESHOLD && readbit(alac))
    {
        x++;
    }

    if (x > RICE_THRESHOLD)
    {
        // read the number from the bit stream (raw value)
        int32_t value;

        value = readbits(alac, readSampleSize);

        // mask value
        value &= (((uint32_t)0xffffffff) >> (32 - readSampleSize));

        x = value;
    }
Пример #3
0
lzw_u read(lzw_t *ctx)
{
	// increase the code size (number of bits) if needed
	if (ctx->max+1 == (1 << ctx->codesize))
		ctx->codesize++;

	return readbits(ctx, ctx->codesize);
}
Пример #4
0
static void aout_addreloclist(struct list *rlst,unsigned long raddr,
                              unsigned long rindex,unsigned long rinfo,int be)
/* add new relocation_info to .text or .data reloc-list */
{
  struct RelocNode *rn = mymalloc(sizeof(struct RelocNode));

  setval(be,rn->r.r_address,4,raddr);
  setbits(be,rn->r.r_info,32,RELB_symbolnum,RELS_symbolnum,rindex);
  setbits(be,rn->r.r_info,32,RELB_reloc,RELS_reloc,rinfo);
  addtail(rlst,&rn->n);

  if (isPIC && !readbits(be,rn->r.r_info,32,RSTDB_pcrel,1)
      && !readbits(be,rn->r.r_info,32,RSTDB_baserel,1)) {
    /* the relocation is probably absolute, so it is no PIC anymore */
    isPIC = 0;
  }
}
Пример #5
0
int main(int argc, char **argv)
{
  int numbits = 6;
  int digit;
  const char *digits = base64digits;
  char *p, *pd, string[BUFSIZ];

  if (argc != 2) {
    printf("usage: %s file\n", argv[0]);
    exit(0);
  }
  if (freopen(argv[1], "r", stdin) == NULL) {
    fprintf(stderr, "file %s not found\n", argv[1]);
    exit(1);
  }
  strcpy(string, argv[1]);

  pd = p  = string;
  while ((p = strchr(p, '/')) != NULL)
    pd=p++;
  p = strchr(pd, '.');
  if (p != NULL)
    *p = '\0';

  printf("const char *%s_au = \"\\\n", pd);

  digit = readbits (numbits, &numbits);
  while (numbits > 0) {
    writechar (digits[digit]);
    digit = readbits (numbits, &numbits);
  }
  padoutput();
  printf("\";\n");

  return 0;
}
Пример #6
0
static unsigned long aoutstd_getrinfo(rlist *rl,int xtern,char *sname,int be)
/* Convert vasm relocation type into standard a.out relocations, */
/* as used by M68k and x86 targets. */
/* For xtern=-1, return true when this relocation requires a base symbol. */
{
  nreloc *nr;
  unsigned long r=0,s=4;
  int b=0;

  if (nr = (nreloc *)rl->reloc) {
    switch (rl->type) {
      case REL_ABS: b=-1; break;
      case REL_PC: b=RSTDB_pcrel; break;
      case REL_SD: b=RSTDB_baserel; break;
    }
    if (xtern == -1)  /* just query symbol-based relocation */
      return b==RSTDB_baserel || b==RSTDB_jmptable;

    if ((nr->offset&7)==0 &&
        (nr->mask & MAKEMASK(nr->size)) == MAKEMASK(nr->size)) {
      switch (nr->size) {
        case 8: s=0; break;
        case 16: s=1; break;
        case 32: s=2; break;
      }
    }

    if (b && s<4) {
      if (b > 0)
        setbits(be,&r,sizeof(r)<<3,(unsigned)b,1,1);
      setbits(be,&r,sizeof(r)<<3,RSTDB_length,RSTDS_length,s);
      setbits(be,&r,sizeof(r)<<3,RSTDB_extern,RSTDS_extern,xtern?1:0);
      return readbits(be,&r,sizeof(r)<<3,RELB_reloc,RELS_reloc);
    }
  }

  unsupp_reloc_error(rl);
  return ~0;
}
Пример #7
0
// read a Differential Data Stream
unsigned char *readDDSfile(const char *filename,size_t *bytes)
   {
   int version=1;

   unsigned int skip,strip;

   unsigned char *data = 0;
   unsigned char *ptr  = 0;

   unsigned int cnt,cnt1,cnt2;
   int bits,act;

   if ((DDS_file=fopen(filename,"rb"))==NULL) return(NULL);

   for (cnt=0; DDS_ID[cnt]!='\0'; cnt++)
      if (fgetc(DDS_file)!=DDS_ID[cnt])
         {
         fclose(DDS_file);
         version=0;
         break;
         }

   if (version==0)
      {
      if ((DDS_file=fopen(filename,"rb"))==NULL) return(NULL);

      for (cnt=0; DDS_ID2[cnt]!='\0'; cnt++)
         if (fgetc(DDS_file)!=DDS_ID2[cnt])
            {
            fclose(DDS_file);
            return(NULL);
            }

      version=2;
      }

   initbuffer();

   skip=readbits(DDS_file,2)+1;
   strip=readbits(DDS_file,16)+1;

   data=NULL;
   cnt=act=0;

   while ((cnt1=readbits(DDS_file,DDS_RL))!=0)
      {
      bits=DDS_decode(readbits(DDS_file,3));

      for (cnt2=0; cnt2<cnt1; cnt2++)
         {
         if (cnt<=strip) act+=readbits(DDS_file,bits)-(1<<bits)/2;
         else act+=*(ptr-strip)-*(ptr-strip-1)+readbits(DDS_file,bits)-(1<<bits)/2;

         while (act<0) act+=256;
         while (act>255) act-=256;

         if (cnt%DDS_BLOCKSIZE==0)
            {
            if (data==NULL)
               {if ((data=(unsigned char *)malloc(DDS_BLOCKSIZE))==NULL) ERRORMSG();}
            else
               if ((data=(unsigned char *)realloc(data,cnt+DDS_BLOCKSIZE))==NULL) ERRORMSG();

            ptr=&data[cnt];
            }

         *ptr++=act;
         cnt++;
         }
      }

   fclose(DDS_file);

   if (cnt==0) return(NULL);

   if ((data=(unsigned char *)realloc(data,cnt))==NULL) ERRORMSG();

   if (version==1) interleave(data,cnt,skip);
   else interleave(data,cnt,skip,DDS_INTERLEAVE);

   *bytes=cnt;

   return(data);
   }
/*************************************************
  Function:       readbits
  Description:    Set value of consecutiv bits
  Calls:          
  Called By:      
  Table Accessed: 
  Table Updated:  
  Input:          pAddr: Address indicated
                  HighBit : The highbit number of 
                            the bit in 32bit register value
                  LowBit :  The lowbit number of 
                            the bit in 32bit register value
                  BitValue: the value to be set.
  Output:         
  Return:         UINT32 
  Others:         
*************************************************/
UINT32 setbits(UINT32 pAddr, int HighBit, int LowBit, UINT32 BitValue)
{

    UINT32 BitNewValue=0x0;
    UINT32 BitMask=0x0;
    UINT32 BitMask_temp;
    UINT32 RawData;
    UINT32 NewData;
    UINT32 BitMaskInv;
    
    int BitWidth;
    int RegRawBit[32]={0};
    int RegNewBit[32]={0};
    int RegBitInput[32]={0};
    int i;
 
    //Get the width of bits that the user need
    BitWidth = HighBit - LowBit + 1;
 
    //Get each bit of the BitValue that user wanna use
    for(i=0;i<BitWidth;i++)
    {
        RegBitInput[i] = (BitValue & (1<<i)) >> i;
    }
 
    //Get each bit of exited Register Bit Value, and then change each bit by new value
    for(i=0;i<BitWidth;i++)
    {
        RegRawBit[i] = readbits(pAddr, (LowBit+i), (LowBit+i)); 
        
        if(RegRawBit[i] == 0)
        {
           RegNewBit[i] = RegBitInput[i] | RegRawBit[i];
        }
        else
        {
           RegNewBit[i] = RegBitInput[i] & RegRawBit[i];
        }
 
        BitNewValue = BitNewValue + (RegNewBit[i] << i);
        
    }
 
    //Get the raw data of the register
    RawData = read32(pAddr);
 
    //Create a Bit Mask
    for(i=0;i<BitWidth;i++)
    {
           BitMask_temp = 1 << (LowBit+i);
           BitMask = BitMask + BitMask_temp;
    } 
 
    //Inverse the Bit Mask to protect the bits that user don't wanna change
    BitMaskInv = ~ BitMask;
 
    //Put the new bits value that user need into 32-bit register value
    NewData = (RawData & BitMaskInv) | (BitNewValue<<LowBit);
 
    // Write the new register value
    set32(pAddr, NewData);
    
    return 0;

}
Пример #9
0
// if we do memset, dumb_silence() would be neater...
static int decompress8(DUMBFILE *f, signed char *data, int len, int it215, int stereo)
{
	int blocklen, blockpos;
	byte bitwidth;
	long val;
	signed char d1, d2;
	readblock_crap crap;

	memset(&crap, 0, sizeof(crap));

	for (blocklen = 0, blockpos = 0; blocklen < len; blocklen++, blockpos += 1 + stereo)
		data[ blockpos ] = 0;

	while (len > 0) {
		//Read a block of compressed data:
		if (readblock(f, &crap))
			return -1;
		//Set up a few variables
		blocklen = (len < 0x8000) ? len : 0x8000; //Max block length is 0x8000 bytes
		blockpos = 0;
		bitwidth = 9;
		d1 = d2 = 0;
		//Start the decompression:
		while (blockpos < blocklen) {
			//Read a value:
			val = readbits(bitwidth, &crap);
			//Check for bit width change:

			if (bitwidth < 7) { //Method 1:
				if (val == (1 << (bitwidth - 1))) {
					val = readbits(3, &crap) + 1;
					bitwidth = (val < bitwidth) ? val : val + 1;
					continue;
				}
			}
			else if (bitwidth < 9) { //Method 2
				byte border = (0xFF >> (9 - bitwidth)) - 4;

				if (val > border && val <= (border + 8)) {
					val -= border;
					bitwidth = (val < bitwidth) ? val : val + 1;
					continue;
				}
			}
			else if (bitwidth == 9) { //Method 3
				if (val & 0x100) {
					bitwidth = (val + 1) & 0xFF;
					continue;
				}
			}
			else { //Illegal width, abort ?
				freeblock(&crap);
				return -1;
			}

			//Expand the value to signed byte:
			{
				signed char v; //The sample value:
				if (bitwidth < 8) {
					byte shift = 8 - bitwidth;
					v = (val << shift);
					v >>= shift;
				}
				else
Пример #10
0
int __attribute__ ((visibility ("internal"))) decompress8 (FILE *module, void *dst, int len, char it215)
{
	sbyte *destbuf;   /* the destination buffer which will be returned */

	word blklen;      /* length of compressed data block in samples */
	word blkpos;      /* position in block */ 
	byte width;       /* actual "bit width" */
	word value;       /* value read from file to be processed */
	sbyte d1, d2;     /* integrator buffers (d2 for it2.15) */
	sbyte *destpos;

	destbuf = (sbyte *)dst;
	if (!destbuf)
		return 0;

	memsetb(destbuf,0,len);
	destpos=destbuf; /* position in output buffer */

	/* now unpack data till the dest buffer is full */
	while (len)
	{
		/* read a new block of compressed data and reset variables */

		if (!readblock(module))
			return 0;
		blklen=(len<0x8000)?len:0x8000;
		blkpos=0;

		width=9;  /* start with width of 9 bits */
		d1=d2=0;  /* reset integrator buffers */

		/* now uncompress the data block */
		while (blkpos<blklen)
		{
			sbyte v;

			value = readbits(width); /* read bits */

			if (width<7) /* method 1 (1-6 bits) */
			{
				if (value==(1<<(width-1))) /* check for "100..." */
				{
					value = readbits(3)+1;                /* yes -> read new width; */
					width = (value<width)?value:value+1;  /* and expand it */
					continue;                             /* ... next value */
				}
			} else if (width<9) /* method 2 (7-8 bits) */
			{
				byte border = (0xFF>>(9-width)) - 4;  /* lower border for width chg */

				if (value>border && value <=(border+8))
				{
					value-=border;                        /* convert width to 1-8 */
					width = (value<width)?value:value+1;  /* and expand it */
					continue;                             /* ... next value */
				}
			} else if (width==9) /* method 3 (9 bits) */
			{
				if (value & 0x100) /* bit 8 set? */
				{
					width=(value+1)&0xff; /* new width... */
					continue;             /* ... and next value */
				}
			} else { /* illegal width, abort */
				freeblock();
				return 0;
			}

			/* now expand value to signed byte */
			/*      sbyte v;  // sample value */
			if (width<8)
			{
				byte shift=8-width;
				v = (value<<shift);
				v>>=shift;
			} else