Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 16 samples in 32 bits:
- [31:24]=max-min
- [23:16]=(max+min)/2
- [15: 0]=sample bits
- Here, the block is unpacked into a high and low value, and each bit selects either max(1) or min(0).
- This is tuned more for decoder simplicity than goodness.
- 16 samples in 64 bits:
- [63:54]=predictor sample (high 10 bits of 16-bit sample)
- [53:48]=step bits
- [47: 0]=sample bits (16x 3b)
- Each sample is a delta relative to a predictor scaled according to the a step.
- The step is adjusted based on the sample bits, and is essentially a 4.2 microfloat.
- Each sample has 3 bits:
- 2: sign
- 1: diff+=step>>1
- 0: diff+=step>>2
- */
- #if 1
- int bltac_encblock(s16 *iblk, u32 *oblk)
- {
- u32 blk;
- int m, n, a, b, c, d;
- int n2, m2, c0, c1, d1;
- int s0, s1;
- int i, j, k;
- m=65536;
- n=-65536;
- for(i=0; i<16; i++)
- {
- k=iblk[i];
- if(k<m)m=k;
- if(k>n)n=k;
- }
- a=(m+n)/2;
- m=(m+a)/2;
- n=(n+a)/2;
- m=(3*m+a)/4;
- n=(3*n+a)/4;
- c=(m+n)/2;
- d=n-m;
- c0=(c>>8)+128;
- c=clamp255(((c+127)>>8)+128);
- d=clamp255(d>>8);
- c1=(c-128)<<8;
- d1=d<<8;
- m=c1-(d1>>1);
- n=c1+d1;
- if(((n<m) || (n>32767) || (m<-32767)) && (c!=c0))
- {
- c=c0;
- c1=(c-128)<<8; d1=d<<8;
- m=c1-(d1>>1); n=c1+d1;
- }
- while(((n<m) || (n>32767) || (m<-32767)) && (d>0))
- {
- d--;
- c1=(c-128)<<8; d1=d<<8;
- m=c1-(d1>>1); n=c1+d1;
- }
- b=0; a=c1;
- for(i=0; i<16; i++)
- {
- k=iblk[i];
- if(k>a)
- {
- b|=1<<i;
- a=(3*a+n)/4;
- }else
- {
- a=(3*a+m)/4;
- }
- }
- blk=b|(c<<16)|(d<<24);
- *oblk=blk;
- return(0);
- }
- int bltac_decblock(u32 blk, s16 *oblk)
- {
- int m, n, a, b, c, d;
- int i, j, k;
- a=(blk>>16)&255;
- b=(blk>>24)&255;
- c=(a-128)<<8;
- d=b<<8;
- m=c-(d>>1);
- n=c+d;
- b=blk&65535;
- for(i=0; i<16; i++)
- { oblk[i]=(b&(1<<i))?n:m; }
- return(0);
- }
- #endif
- #if 1
- int bltac_encblock2(s16 *iblk, u64 *oblk)
- {
- static int la=0;
- static int ls=0;
- static u16 *lpn=NULL;
- u64 blk;
- int m, n, a, b, c, d, s;
- int n2, m2, c0, c1, d1;
- int s0, s1;
- int i, j, k, l;
- if(iblk==lpn)
- {
- s0=(la&0xFFC0)|ls;
- s1=ls;
- }else
- {
- la=(iblk[0]+iblk[1])/2;
- ls=8;
- s0=(la&0xFFC0)|ls;
- s1=ls;
- }
- a=(s16)(s0&0xFFC0);
- s=s0&63;
- blk=((u64)s0)<<48;
- for(i=0; i<16; i++)
- {
- k=(s16)(iblk[i]&0xFFC0);
- c0=k-a;
- c1=(c0>=0)?c0:(-c0);
- d=(4|(s&3))<<(s>>2);
- b=(4*c1)/d;
- b=clamp(b, 0, 3);
- if(c0<0)b|=4;
- blk|=((u64)b)<<(i*3);
- d1=d>>3;
- if(b&1)d1+=d>>2;
- if(b&2)d1+=d>>1;
- if(b&4)d1=-d1;
- s+=((b&3)==3)?3:((b&3)-1);
- a+=d1;
- a=clamp(a, -32768, 32767);
- s=clamp(s, 0, 63);
- }
- la=a;
- ls=s;
- lpn=iblk+16;
- *oblk=blk;
- }
- int bltac_decblock2(u64 blk, s16 *oblk)
- {
- int m, n, a, b, c, d, s;
- int n2, m2, c0, c1, d1;
- int s0, s1;
- int i, j, k, l;
- s0=(s16)(blk>>48);
- a=(s16)(s0&0xFFC0);
- s=s0&63;
- for(i=0; i<16; i++)
- {
- b=(blk>>(i*3))&7;
- d=(4|(s&3))<<(s>>2);
- d1=d>>3;
- if(b&1)d1+=d>>2;
- if(b&2)d1+=d>>1;
- if(b&4)d1=-d1;
- s+=((b&3)==3)?3:((b&3)-1);
- a+=d1;
- a=clamp(a, -32768, 32767);
- s=clamp(s, 0, 63);
- oblk[i]=a;
- }
- }
- #endif
Add Comment
Please, Sign In to add comment