diff options
author | rtognimp <rtognimp@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2003-06-08 20:25:28 +0000 |
---|---|---|
committer | rtognimp <rtognimp@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2003-06-08 20:25:28 +0000 |
commit | 7b0c242d34b54e550520e643552e5643cef88778 (patch) | |
tree | dfa186eb0e8c2ffdd0ef52df6b4fa6a20f903b3e /libmpcodecs/native | |
parent | 0e5c9a508fdee6f76bd5032dccfea46cb1054c94 (diff) | |
download | mpv-7b0c242d34b54e550520e643552e5643cef88778.tar.bz2 mpv-7b0c242d34b54e550520e643552e5643cef88778.tar.xz |
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders.
Author unknown, code from a public domain player for Amiga
at http://www.honeypot.net/audio
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@10261 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpcodecs/native')
-rw-r--r-- | libmpcodecs/native/common1428.h | 34 | ||||
-rw-r--r-- | libmpcodecs/native/decode144.c | 437 | ||||
-rw-r--r-- | libmpcodecs/native/decode144.h | 64 | ||||
-rw-r--r-- | libmpcodecs/native/decode288.c | 217 | ||||
-rw-r--r-- | libmpcodecs/native/decode288.h | 27 | ||||
-rw-r--r-- | libmpcodecs/native/tables144.h | 2407 | ||||
-rw-r--r-- | libmpcodecs/native/tables288.h | 184 |
7 files changed, 3370 insertions, 0 deletions
diff --git a/libmpcodecs/native/common1428.h b/libmpcodecs/native/common1428.h new file mode 100644 index 0000000000..e49a7b68c5 --- /dev/null +++ b/libmpcodecs/native/common1428.h @@ -0,0 +1,34 @@ +#ifndef COMMON_H +#define COMMON_H + +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <math.h> + +#define DATABLOCK1 20 /* size of 14.4 input block in bytes */ +#define DATABLOCK2 38 /* size of 28.8 input block in bytes */ +#define DATACHUNK1 1440 /* size of 14.4 input chunk in bytes */ +#define DATACHUNK2 2736 /* size of 28.8 input chunk in bytes */ +#define AUDIOBLOCK 160 /* size of output block in 16-bit words (320 bytes) */ +//#define AUDIOBUFFER 11520 /* size of output buffer in 16-bit words (23040 bytes) */ +#define AUDIOBUFFER 12288 /* size of output buffer in 16-bit words (24576 bytes) */ + +typedef void Real_144; +typedef void Real_288; +typedef void Real_dnet; + +/* common prototypes */ +Real_144 *init_144 (void); +Real_288 *init_288 (void); +Real_dnet *init_dnet (void); +void free_144 (Real_144 *global); +void free_288 (Real_288 *global); +void free_dnet (Real_dnet *global); +void deinterleave (unsigned char *in, unsigned char *out, unsigned int size); +void swapbytes (unsigned char *in, unsigned char *out, unsigned int len); +void decode_144 (Real_144 *global, unsigned char *source, signed short *target); +void decode_288 (Real_288 *global, unsigned char *in, signed short *out); +int decode_dnet (Real_dnet *global, unsigned char *in, signed short *out, int *freq, int chans); + +#endif /* !COMMON_H */ diff --git a/libmpcodecs/native/decode144.c b/libmpcodecs/native/decode144.c new file mode 100644 index 0000000000..e25a6c0820 --- /dev/null +++ b/libmpcodecs/native/decode144.c @@ -0,0 +1,437 @@ +#include "common1428.h" +#include "decode144.h" +#include "tables144.h" + +/* Initialize internal variable structure */ +Real_144 *init_144(void) +{ + Real_internal *glob; + + if ((glob=malloc(sizeof(Real_internal)))) + memset(glob,0,sizeof(Real_internal)); + + glob->resetflag=1; + glob->swapbuf1=glob->swapb1a; + glob->swapbuf2=glob->swapb2a; + glob->swapbuf1alt=glob->swapb1b; + glob->swapbuf2alt=glob->swapb2b; + + memcpy(glob->wavtable1,wavtable1,sizeof(wavtable1)); + memcpy(glob->wavtable2,wavtable2,sizeof(wavtable2)); + + return (Real_144 *)glob; +} + +/* Free internal variable structure */ +void free_144(Real_144 *global) +{ + if (!global) return; + free(global); +} + +/* Uncompress one block (20 bytes -> 160*2 bytes) */ +void decode_144(Real_144 *global, unsigned char *source, signed short *target) +{ + unsigned int a,b,c; + long s; + signed short *shptr; + unsigned int *lptr,*temp; + const short **dptr; + Real_internal *glob; + + if (!global) return; + glob = (Real_internal *)global; + + unpack_input(source,glob->unpacked); + + glob->iptr=glob->unpacked; + glob->val=decodetable[0][(*(glob->iptr++))<<1]; + + dptr=decodetable+1; + lptr=glob->swapbuf1; + while (lptr<glob->swapbuf1+10) + *(lptr++)=(*(dptr++))[(*(glob->iptr++))<<1]; + + do_voice(glob->swapbuf1,glob->swapbuf2); + + a=t_sqrt(glob->val*glob->oldval)>>12; + + for (c=0;c<NBLOCKS;c++) { + if (c==(NBLOCKS-1)) { + dec1(glob,glob->swapbuf1,glob->swapbuf2,3,glob->val); + } else { + if (c*2==(NBLOCKS-2)) { + if (glob->oldval<glob->val) { + dec2(glob,glob->swapbuf1,glob->swapbuf2,3,a,glob->swapbuf2alt,c); + } else { + dec2(glob,glob->swapbuf1alt,glob->swapbuf2alt,3,a,glob->swapbuf2,c); + } + } else { + if (c*2<(NBLOCKS-2)) { + dec2(glob,glob->swapbuf1alt,glob->swapbuf2alt,3,glob->oldval,glob->swapbuf2,c); + } else { + dec2(glob,glob->swapbuf1,glob->swapbuf2,3,glob->val,glob->swapbuf2alt,c); + } + } + } + } + + /* do output */ + for (b=0,c=0;c<4;c++) { + glob->gval=glob->gbuf1[c*2]; + glob->gsp=glob->gbuf2+b; + do_output_subblock(glob,glob->resetflag); + glob->resetflag=0; + + shptr=glob->output_buffer; + while (shptr<glob->output_buffer+BLOCKSIZE) { + s=*(shptr++)<<2; + *target=s; + if (s>32767) *target=32767; + if (s<-32767) *target=-32768; + target++; + } + b+=30; + } + + glob->oldval=glob->val; + temp=glob->swapbuf1alt; + glob->swapbuf1alt=glob->swapbuf1; + glob->swapbuf1=temp; + temp=glob->swapbuf2alt; + glob->swapbuf2alt=glob->swapbuf2; + glob->swapbuf2=temp; +} + +/* lookup square roots in table */ +static int t_sqrt(unsigned int x) +{ + int s=0; + while (x>0xfff) { s++; x=x>>2; } + return (sqrt_table[x]<<s)<<2; +} + +/* do 'voice' */ +static void do_voice(int *a1, int *a2) +{ + int buffer[10]; + int *b1,*b2; + int x,y; + int *ptr,*tmp; + + b1=buffer; + b2=a2; + + for (x=0;x<10;x++) { + b1[x]=(*a1)<<4; + + if(x>0) { + ptr=b2+x; + for (y=0;y<=x-1;y++) + b1[y]=(((*a1)*(*(--ptr)))>>12)+b2[y]; + } + tmp=b1; + b1=b2; + b2=tmp; + a1++; + } + ptr=a2+10; + while (ptr>a2) (*a2++)>>=4; +} + + +/* do quarter-block output */ +static void do_output_subblock(Real_internal *glob, int x) +{ + int a,b,c,d,e,f,g; + + if (x==1) memset(glob->buffer,0,20); + if ((*glob->iptr)==0) a=0; + else a=(*glob->iptr)+HALFBLOCK-1; + glob->iptr++; + b=*(glob->iptr++); + c=*(glob->iptr++); + d=*(glob->iptr++); + if (a) rotate_block(glob->buffer_2,glob->buffer_a,a); + memcpy(glob->buffer_b,etable1+b*BLOCKSIZE,BLOCKSIZE*2); + e=((ftable1[b]>>4)*glob->gval)>>8; + memcpy(glob->buffer_c,etable2+c*BLOCKSIZE,BLOCKSIZE*2); + f=((ftable2[c]>>4)*glob->gval)>>8; + if (a) g=irms(glob->buffer_a,glob->gval)>>12; + else g=0; + add_wav(glob,d,a,g,e,f,glob->buffer_a,glob->buffer_b,glob->buffer_c,glob->buffer_d); + memmove(glob->buffer_2,glob->buffer_2+BLOCKSIZE,(BUFFERSIZE-BLOCKSIZE)*2); + memcpy(glob->buffer_2+BUFFERSIZE-BLOCKSIZE,glob->buffer_d,BLOCKSIZE*2); + final(glob,glob->gsp,glob->buffer_d,glob->output_buffer,glob->buffer,BLOCKSIZE); +} + +/* rotate block */ +static void rotate_block(short *source, short *target, int offset) +{ + short *end; + short *ptr1; + short *ptr2; + short *ptr3; + ptr2=source+BUFFERSIZE; + ptr3=ptr1=ptr2-offset; + end=target+BLOCKSIZE; + while (target<end) { + *(target++)=*(ptr3++); + if (ptr3==ptr2) ptr3=ptr1; + } +} + +/* inverse root mean square */ +static int irms(short *data, int factor) +{ + short *p1,*p2; + unsigned int sum; + p2=(p1=data)+BLOCKSIZE; + for (sum=0;p2>p1;p1++) sum+=(*p1)*(*p1); + if (sum==0) return 0; /* OOPS - division by zero */ + return (0x20000000/(t_sqrt(sum)>>8))*factor; +} + +/* multiply/add wavetable */ +static void add_wav(Real_internal *glob, int n, int f, int m1, int m2, int m3, short *s1, short *s2, short *s3, short *dest) +{ + int a,b,c; + int x; + short *ptr,*ptr2; + + ptr=glob->wavtable1+n*9; + ptr2=glob->wavtable2+n*9; + if (f!=0) { + a=((*ptr)*m1)>>((*ptr2)+1); + } else { + a=0; + } + ptr++;ptr2++; + b=((*ptr)*m2)>>((*ptr2)+1); + ptr++;ptr2++; + c=((*ptr)*m3)>>((*ptr2)+1); + ptr2=(ptr=dest)+BLOCKSIZE; + if (f!=0) + while (ptr<ptr2) + *(ptr++)=((*(s1++))*a+(*(s2++))*b+(*(s3++))*c)>>12; + else + while (ptr<ptr2) + *(ptr++)=((*(s2++))*b+(*(s3++))*c)>>12; +} + + +static void final(Real_internal *glob, short *i1, short *i2, void *out, int *statbuf, int len) +{ + int x,sum; + int buffer[10]; + short *ptr; + short *ptr2; + + memcpy(glob->work,statbuf,20); + memcpy(glob->work+10,i2,len*2); + + buffer[9]=i1[0]; + buffer[8]=i1[1]; + buffer[7]=i1[2]; + buffer[6]=i1[3]; + buffer[5]=i1[4]; + buffer[4]=i1[5]; + buffer[3]=i1[6]; + buffer[2]=i1[7]; + buffer[1]=i1[8]; + buffer[0]=i1[9]; + + ptr2=(ptr=glob->work)+len; + while (ptr<ptr2) { + for(sum=0,x=0;x<=9;x++) + sum+=buffer[x]*(ptr[x]); + sum=sum>>12; + x=ptr[10]-sum; + if (x<-32768 || x>32767) + { + memset(out,0,len*2); + memset(statbuf,0,20); + return; + } + ptr[10]=x; + ptr++; + } + memcpy(out,ptr+10-len,len*2); + memcpy(statbuf,ptr,20); +} + +/* Decode 20-byte input */ +static void unpack_input(unsigned char *input, unsigned int *output) +{ + unsigned int outbuffer[28]; + unsigned short inbuffer[10]; + unsigned int x; + unsigned int *ptr; + + /* fix endianness */ + for (x=0;x<20;x+=2) + inbuffer[x/2]=(input[x]<<8)+input[x+1]; + + /* unpack */ + ptr=outbuffer; + *(ptr++)=27; + *(ptr++)=(inbuffer[0]>>10)&0x3f; + *(ptr++)=(inbuffer[0]>>5)&0x1f; + *(ptr++)=inbuffer[0]&0x1f; + *(ptr++)=(inbuffer[1]>>12)&0xf; + *(ptr++)=(inbuffer[1]>>8)&0xf; + *(ptr++)=(inbuffer[1]>>5)&7; + *(ptr++)=(inbuffer[1]>>2)&7; + *(ptr++)=((inbuffer[1]<<1)&6)|((inbuffer[2]>>15)&1); + *(ptr++)=(inbuffer[2]>>12)&7; + *(ptr++)=(inbuffer[2]>>10)&3; + *(ptr++)=(inbuffer[2]>>5)&0x1f; + *(ptr++)=((inbuffer[2]<<2)&0x7c)|((inbuffer[3]>>14)&3); + *(ptr++)=(inbuffer[3]>>6)&0xff; + *(ptr++)=((inbuffer[3]<<1)&0x7e)|((inbuffer[4]>>15)&1); + *(ptr++)=(inbuffer[4]>>8)&0x7f; + *(ptr++)=(inbuffer[4]>>1)&0x7f; + *(ptr++)=((inbuffer[4]<<7)&0x80)|((inbuffer[5]>>9)&0x7f); + *(ptr++)=(inbuffer[5]>>2)&0x7f; + *(ptr++)=((inbuffer[5]<<5)&0x60)|((inbuffer[6]>>11)&0x1f); + *(ptr++)=(inbuffer[6]>>4)&0x7f; + *(ptr++)=((inbuffer[6]<<4)&0xf0)|((inbuffer[7]>>12)&0xf); + *(ptr++)=(inbuffer[7]>>5)&0x7f; + *(ptr++)=((inbuffer[7]<<2)&0x7c)|((inbuffer[8]>>14)&3); + *(ptr++)=(inbuffer[8]>>7)&0x7f; + *(ptr++)=((inbuffer[8]<<1)&0xfe)|((inbuffer[9]>>15)&1); + *(ptr++)=(inbuffer[9]>>8)&0x7f; + *(ptr++)=(inbuffer[9]>>1)&0x7f; + + *(output++)=outbuffer[11]; + for (x=1;x<11;*(output++)=outbuffer[x++]); + ptr=outbuffer+12; + for (x=0;x<16;x+=4) + { + *(output++)=ptr[x]; + *(output++)=ptr[x+2]; + *(output++)=ptr[x+3]; + *(output++)=ptr[x+1]; + } +} + +static unsigned int rms(int *data, int f) +{ + int *c; + int x; + int d; + unsigned int res; + int b; + + c=data; + b=0; + res=0x10000; + for (x=0;x<10;x++) + { + res=(((0x1000000-(*c)*(*c))>>12)*res)>>12; + if (res==0) return 0; + if (res<=0x3fff) + { + while (res<=0x3fff) + { + b++; + res<<=2; + } + } else { + if (res>0x10000) + return 0; /* We're screwed, might as well go out with a bang. :P */ + } + c++; + } + if (res>0) res=t_sqrt(res); + + res>>=(b+10); + res=(res*f)>>10; + return res; +} + +static void dec1(Real_internal *glob, int *data, int *inp, int n, int f) +{ + short *ptr,*end; + + *(glob->decptr++)=rms(data,f); + glob->decptr++; + end=(ptr=glob->decsp)+(n*10); + while (ptr<end) *(ptr++)=*(inp++); +} + +static void dec2(Real_internal *glob, int *data, int *inp, int n, int f, int *inp2, int l) +{ + unsigned int *ptr1,*ptr2; + int work[10]; + int a,b; + int x; + int result; + + if(l+1<NBLOCKS/2) a=NBLOCKS-(l+1); + else a=l+1; + b=NBLOCKS-a; + if (l==0) + { + glob->decsp=glob->sptr=glob->gbuf2; + glob->decptr=glob->gbuf1; + } + ptr1=inp; + ptr2=inp2; + for (x=0;x<10*n;x++) + *(glob->sptr++)=(a*(*ptr1++)+b*(*ptr2++))>>2; + result=eq(glob,glob->decsp,work); + if (result==1) + { + dec1(glob,data,inp,n,f); + } else { + *(glob->decptr++)=rms(work,f); + glob->decptr++; + } + glob->decsp+=n*10; +} + + +static int eq(Real_internal *glob, short *in, int *target) +{ + int retval; + int a; + int b; + int c; + unsigned int u; + short *sptr; + int *ptr1,*ptr2,*ptr3; + int *bp1,*bp2,*temp; + + retval=0; + bp1=glob->buffer1; + bp2=glob->buffer2; + ptr2=(ptr3=glob->buffer2)+9; + sptr=in; + while (ptr2>=ptr3) + *(ptr3++)=*(sptr++); + + target+=9; + a=bp2[9]; + *target=a; + if (a+0x1000>0x1fff) + return 0; /* We're screwed, might as well go out with a bang. :P */ + c=8;u=a; + while (c>=0) + { + if (u==0x1000) u++; + if (u==0xfffff000) u--; + b=0x1000-((u*u)>>12); + if (b==0) b++; + ptr2=bp1; + ptr1=(ptr3=bp2)+c; + for (u=0;u<=c;u++) + *(ptr2++)=((*(ptr3++)-(((*target)*(*(ptr1--)))>>12))*(0x1000000/b))>>12; + *(--target)=u=bp1[(c--)]; + if ((u+0x1000)>0x1fff) retval=1; + temp=bp2; + bp2=bp1; + bp1=temp; + } + return retval; +} diff --git a/libmpcodecs/native/decode144.h b/libmpcodecs/native/decode144.h new file mode 100644 index 0000000000..597c806b63 --- /dev/null +++ b/libmpcodecs/native/decode144.h @@ -0,0 +1,64 @@ +#ifndef DECODE144_H +#define DECODE144_H + +/* internal globals */ +typedef struct { + unsigned int resetflag, val, oldval; + unsigned int unpacked[28]; /* buffer for unpacked input */ + unsigned int *iptr; /* pointer to current input (from unpacked) */ + unsigned int gval; + unsigned short *gsp; + unsigned int gbuf1[8]; + unsigned short gbuf2[120]; + signed short output_buffer[40]; + unsigned int *decptr; /* decoder ptr */ + signed short *decsp; + + /* the swapped buffers */ + unsigned int swapb1a[10]; + unsigned int swapb2a[10]; + unsigned int swapb1b[10]; + unsigned int swapb2b[10]; + unsigned int *swapbuf1; + unsigned int *swapbuf2; + unsigned int *swapbuf1alt; + unsigned int *swapbuf2alt; + + unsigned int buffer[5]; + unsigned short int buffer_2[148]; + unsigned short int buffer_a[40]; + unsigned short int buffer_b[40]; + unsigned short int buffer_c[40]; + unsigned short int buffer_d[40]; + + unsigned short int work[50]; + unsigned short *sptr; + + int buffer1[10]; + int buffer2[10]; + + signed short wavtable1[2304]; + unsigned short wavtable2[2304]; +} Real_internal; + +/* consts */ +#define NBLOCKS 4 /* number of segments within a block */ +#define BLOCKSIZE 40 /* (quarter) block size in 16-bit words (80 bytes) */ +#define HALFBLOCK 20 /* BLOCKSIZE/2 */ +#define BUFFERSIZE 146 /* for do_output */ + +/* prototypes */ +static int t_sqrt (unsigned int x); +static void do_voice (int *a1, int *a2); +static void do_output_subblock (Real_internal *glob, int x); +static void rotate_block (short *source, short *target, int offset); +static int irms (short *data, int factor); +static void add_wav (Real_internal *glob, int n, int f, int m1, int m2, int m3, short *s1, short *s2, short *s3, short *dest); +static void final (Real_internal *glob, short *i1, short *i2, void *out, int *statbuf, int len); +static void unpack_input (unsigned char *input, unsigned int *output); +static unsigned int rms (int *data, int f); +static void dec1 (Real_internal *glob, int *data, int *inp, int n, int f); +static void dec2 (Real_internal *glob, int *data, int *inp, int n, int f, int *inp2, int l); +static int eq (Real_internal *glob, short *in, int *target); + +#endif /* !DECODE144_H */ diff --git a/libmpcodecs/native/decode288.c b/libmpcodecs/native/decode288.c new file mode 100644 index 0000000000..fb4f350ff6 --- /dev/null +++ b/libmpcodecs/native/decode288.c @@ -0,0 +1,217 @@ +#include "common1428.h" +#include "decode288.h" +#include "tables288.h" + +/* Initialize internal variable structure */ +Real_288 *init_288(void) +{ + Real_internal *glob; + + if ((glob=malloc(sizeof(Real_internal)))) + memset(glob,0,sizeof(Real_internal)); + + return (Real_288 *)glob; +} + +/* Free internal variable structure */ +void free_288(Real_288 *global) +{ + if (!global) return; + free(global); +} + +/* Unlike the 14.4 format, 28.8 blocks are interleaved */ +/* to dilute the effects of transmission errors */ +void deinterleave(unsigned char *in, unsigned char *out, unsigned int size) +{ + unsigned int x=0,y=0,z=0; + if (size>=38) z=size-38; + else return; + + while (x<=z) + { + memcpy(out+y,in+x,38); + x+=38;y+=456; + if (y>z) y-=z; + } +} + +/* Decode a block (celp) */ +void decode_288(Real_288 *global, unsigned char *in, signed short int *out) +{ + int x,y; + unsigned short int buffer[32]; + Real_internal *glob; + + if (!global) return; + glob = (Real_internal *)global; + + unpack(buffer,in,32); + for (x=0;x<32;x++) + { + glob->phasep=(glob->phase=x&7)*5; + decode(glob,buffer[x]); + for (y=0;y<5;*(out++)=8*glob->output[glob->phasep+(y++)]); + if (glob->phase==3) update(glob); + } +} + +/* initial decode */ +static void unpack(unsigned short *tgt, unsigned char *src, int len) +{ + int x,y,z; + int n,temp; + int buffer[38]; + + for (x=0;x<len;tgt[x++]=0) + buffer[x]=9+(x&1); + + for (x=y=z=0;x<38;x++) { + n=buffer[y]-z; + temp=src[x]; + if (n<8) temp&=255>>(8-n); + tgt[y]+=temp<<z; + if (n<=8) { + tgt[++y]+=src[x]>>n; + z=8-n; + } else z+=8; + } +} + +static void update(Real_internal *glob) +{ + int x,y; + float buffer1[40],temp1[37]; + float buffer2[8],temp2[11]; + + for (x=0,y=glob->phasep+5;x<40;buffer1[x++]=glob->output[(y++)%40]); + co(36,40,35,buffer1,temp1,glob->st1a,glob->st1b,table1); + if (pred(temp1,glob->st1,36)) + colmult(glob->pr1,glob->st1,table1a,36); + + for (x=0,y=glob->phase+1;x<8;buffer2[x++]=glob->history[(y++)%8]); + co(10,8,20,buffer2,temp2,glob->st2a,glob->st2b,table2); + if (pred(temp2,glob->st2,10)) + colmult(glob->pr2,glob->st2,table2a,10); +} + +/* Decode and produce output */ +static void decode(Real_internal *glob, unsigned int input) +{ + unsigned int x,y; + float f; + double sum,sumsum; + float *p1,*p2; + float buffer[5]; + const float *table; + + for (x=36;x--;glob->sb[x+5]=glob->sb[x]); + for (x=5;x--;) { + p1=glob->sb+x;p2=glob->pr1; + for (sum=0,y=36;y--;sum-=(*(++p1))*(*(p2++))); + glob->sb[x]=sum; + } + + f=amptable[input&7]; + table=codetable+(input>>3)*5; + + /* convert log and do rms */ + for (sum=32,x=10;x--;sum-=glob->pr2[x]*glob->lhist[x]); + if (sum<0) sum=0; else if (sum>60) sum=60; + + sumsum=exp(sum*0.1151292546497)*f; /* pow(10.0,sum/20)*f */ + for (sum=0,x=5;x--;) { buffer[x]=table[x]*sumsum; sum+=buffer[x]*buffer[x]; } + if ((sum/=5)<1) sum=1; + + /* shift and store */ + for (x=10;--x;glob->lhist[x]=glob->lhist[x-1]); + *glob->lhist=glob->history[glob->phase]=10*log10(sum)-32; + + for (x=1;x<5;x++) for (y=x;y--;buffer[x]-=glob->pr1[x-y-1]*buffer[y]); + + /* output */ + for (x=0;x<5;x++) { + f=glob->sb[4-x]+buffer[x]; + if (f>4095) f=4095; else if (f<-4095) f=-4095; + glob->output[glob->phasep+x]=glob->sb[4-x]=f; + } +} + +/* column multiply */ +static void colmult(float *tgt, float *m1, const float *m2, int n) +{ + while (n--) + *(tgt++)=(*(m1++))*(*(m2++)); +} + +static int pred(float *in, float *tgt, int n) +{ + int x,y; + float *p1,*p2; + double f0,f1,f2; + float temp; + + if (in[n]==0) return 0; + if ((f0=*in)<=0) return 0; + + for (x=1;;x++) { + if (n<x) return 1; + + p1=in+x; + p2=tgt; + f1=*(p1--); + for (y=x;--y;f1+=(*(p1--))*(*(p2++))); + + p1=tgt+x-1; + p2=tgt; + *(p1--)=f2=-f1/f0; + for (y=x>>1;y--;) { + temp=*p2+*p1*f2; + *(p1--)+=*p2*f2; + *(p2++)=temp; + } + if ((f0+=f1*f2)<0) return 0; + } +} + +static void co(int n, int i, int j, float *in, float *out, float *st1, float *st2, const float *table) +{ + int a,b,c; + unsigned int x; + float *fp,*fp2; + float buffer1[37]; + float buffer2[37]; + float work[111]; + + /* rotate and multiply */ + c=(b=(a=n+i)+j)-i; + fp=st1+i; + for (x=0;x<b;x++) { + if (x==c) fp=in; + work[x]=*(table++)*(*(st1++)=*(fp++)); + } + + prodsum(buffer1,work+n,i,n); + prodsum(buffer2,work+a,j,n); + + for (x=0;x<=n;x++) { + *st2=*st2*(0.5625)+buffer1[x]; + out[x]=*(st2++)+buffer2[x]; + } + *out*=1.00390625; /* to prevent clipping */ +} + +/* product sum (lsf) */ +static void prodsum(float *tgt, float *src, int len, int n) +{ + unsigned int x; + float *p1,*p2; + double sum; + + while (n>=0) + { + p1=(p2=src)-n; + for (sum=0,x=len;x--;sum+=(*p1++)*(*p2++)); + tgt[n--]=sum; + } +} diff --git a/libmpcodecs/native/decode288.h b/libmpcodecs/native/decode288.h new file mode 100644 index 0000000000..179dd6131c --- /dev/null +++ b/libmpcodecs/native/decode288.h @@ -0,0 +1,27 @@ +#ifndef DECODE288_H +#define DECODE288_H + +/* internal globals */ +typedef struct { + float history[8]; + float output[40]; + float pr1[36]; + float pr2[10]; + int phase, phasep; + + float st1a[111],st1b[37],st1[37]; + float st2a[38],st2b[11],st2[11]; + float sb[41]; + float lhist[10]; +} Real_internal; + +/* prototypes */ +static void unpack (unsigned short *tgt, unsigned char *src, int len); +static void decode (Real_internal *internal, unsigned int input); +static void update (Real_internal *internal); +static void colmult (float *tgt, float *m1, const float *m2, int n); +static int pred (float *in, float *tgt, int n); +static void co (int n, int i, int j, float *in, float *out, float *st1, float *st2, const float *table); +static void prodsum (float *tgt, float *src, int len, int n); + +#endif /* !DECODE288_H */ diff --git a/libmpcodecs/native/tables144.h b/libmpcodecs/native/tables144.h new file mode 100644 index 0000000000..b78a51bf62 --- /dev/null +++ b/libmpcodecs/native/tables144.h @@ -0,0 +1,2407 @@ +#ifndef TABLES144_H +#define TABLES144_H + +/* 14.4 data tables */ +const unsigned short sqrt_table[4096]={ +0x0000,0x0400,0x05a8,0x06ed,0x0800,0x08f1,0x09cc,0x0a95, +0x0b50,0x0c00,0x0ca6,0x0d44,0x0ddb,0x0e6c,0x0ef7,0x0f7d, +0x1000,0x107e,0x10f8,0x116f,0x11e3,0x1254,0x12c2,0x132e, +0x1398,0x1400,0x1465,0x14c8,0x152a,0x158a,0x15e8,0x1645, +0x16a0,0x16fa,0x1752,0x17aa,0x1800,0x1854,0x18a8,0x18fa, +0x194c,0x199c,0x19ec,0x1a3a,0x1a88,0x1ad5,0x1b21,0x1b6c, +0x1bb6,0x1c00,0x1c48,0x1c90,0x1cd8,0x1d1e,0x1d64,0x1daa, +0x1dee,0x1e33,0x1e76,0x1eb9,0x1efb,0x1f3d,0x1f7e,0x1fbf, +0x2000,0x203f,0x207f,0x20bd,0x20fc,0x2139,0x2177,0x21b4, +0x21f0,0x222d,0x2268,0x22a4,0x22df,0x2319,0x2353,0x238d, +0x23c6,0x2400,0x2438,0x2471,0x24a9,0x24e0,0x2518,0x254f, +0x2585,0x25bc,0x25f2,0x2628,0x265d,0x2693,0x26c8,0x26fc, +0x2731,0x2765,0x2799,0x27cc,0x2800,0x2833,0x2865,0x2898, +0x28ca,0x28fc,0x292e,0x2960,0x2991,0x29c2,0x29f3,0x2a24, +0x2a54,0x2a85,0x2ab5,0x2ae5,0x2b14,0x2b44,0x2b73,0x2ba2, +0x2bd1,0x2c00,0x2c2e,0x2c5c,0x2c8a,0x2cb8,0x2ce6,0x2d13, +0x2d41,0x2d6e,0x2d9b,0x2dc8,0x2df4,0x2e21,0x2e4d,0x2e79, +0x2ea5,0x2ed1,0x2efd,0x2f28,0x2f54,0x2f7f,0x2faa,0x2fd5, +0x3000,0x302a,0x3055,0x307f,0x30a9,0x30d3,0x30fd,0x3127, +0x3150,0x317a,0x31a3,0x31cc,0x31f5,0x321e,0x3247,0x3270, +0x3298,0x32c1,0x32e9,0x3311,0x3339,0x3361,0x3389,0x33b0, +0x33d8,0x3400,0x3427,0x344e,0x3475,0x349c,0x34c3,0x34ea, +0x3510,0x3537,0x355d,0x3584,0x35aa,0x35d0,0x35f6,0x361c, +0x3642,0x3667,0x368d,0x36b2,0x36d8,0x36fd,0x3722,0x3747, +0x376c,0x3791,0x37b6,0x37db,0x3800,0x3824,0x3848,0x386d, +0x3891,0x38b5,0x38d9,0x38fd,0x3921,0x3945,0x3969,0x398c, +0x39b0,0x39d3,0x39f7,0x3a1a,0x3a3d,0x3a60,0x3a83,0x3aa6, +0x3ac9,0x3aec,0x3b0f,0x3b31,0x3b54,0x3b76,0x3b99,0x3bbb, +0x3bdd,0x3c00,0x3c22,0x3c44,0x3c66,0x3c87,0x3ca9,0x3ccb, +0x3ced,0x3d0e,0x3d30,0x3d51,0x3d72,0x3d94,0x3db5,0x3dd6, +0x3df7,0x3e18,0x3e39,0x3e5a,0x3e7b,0x3e9c,0x3ebc,0x3edd, +0x3efd,0x3f1e,0x3f3e,0x3f5f,0x3f7f,0x3f9f,0x3fbf,0x3fdf, +0x4000,0x401f,0x403f,0x405f,0x407f,0x409f,0x40be,0x40de, +0x40fe,0x411d,0x413c,0x415c,0x417b,0x419a,0x41ba,0x41d9, +0x41f8,0x4217,0x4236,0x4255,0x4273,0x4292,0x42b1,0x42d0, +0x42ee,0x430d,0x432b,0x434a,0x4368,0x4387,0x43a5,0x43c3, +0x43e1,0x4400,0x441e,0x443c,0x445a,0x4478,0x4495,0x44b3, +0x44d1,0x44ef,0x450c,0x452a,0x4548,0x4565,0x4583,0x45a0, +0x45be,0x45db,0x45f8,0x4615,0x4633,0x4650,0x466d,0x468a, +0x46a7,0x46c4,0x46e1,0x46fe,0x471b,0x4737,0x4754,0x4771, +0x478d,0x47aa,0x47c7,0x47e3,0x4800,0x481c,0x4838,0x4855, +0x4871,0x488d,0x48a9,0x48c6,0x48e2,0x48fe,0x491a,0x4936, +0x4952,0x496e,0x498a,0x49a5,0x49c1,0x49dd,0x49f9,0x4a14, +0x4a30,0x4a4b,0x4a67,0x4a83,0x4a9e,0x4ab9,0x4ad5,0x4af0, +0x4b0b,0x4b27,0x4b42,0x4b5d,0x4b78,0x4b93,0x4bae,0x4bca, +0x4be5,0x4c00,0x4c1a,0x4c35,0x4c50,0x4c6b,0x4c86,0x4ca1, +0x4cbb,0x4cd6,0x4cf1,0x4d0b,0x4d26,0x4d40,0x4d5b,0x4d75, +0x4d90,0x4daa,0x4dc4,0x4ddf,0x4df9,0x4e13,0x4e2d,0x4e48, +0x4e62,0x4e7c,0x4e96,0x4eb0,0x4eca,0x4ee4,0x4efe,0x4f18, +0x4f32,0x4f4c,0x4f65,0x4f7f,0x4f99,0x4fb3,0x4fcc,0x4fe6, +0x5000,0x5019,0x5033,0x504c,0x5066,0x507f,0x5099,0x50b2, +0x50cb,0x50e5,0x50fe,0x5117,0x5130,0x514a,0x5163,0x517c, +0x5195,0x51ae,0x51c7,0x51e0,0x51f9,0x5212,0x522b,0x5244, +0x525d,0x5276,0x528f,0x52a7,0x52c0,0x52d9,0x52f2,0x530a, +0x5323,0x533c,0x5354,0x536d,0x5385,0x539e,0x53b6,0x53cf, +0x53e7,0x5400,0x5418,0x5430,0x5449,0x5461,0x5479,0x5491, +0x54a9,0x54c2,0x54da,0x54f2,0x550a,0x5522,0x553a,0x5552, +0x556a,0x5582,0x559a,0x55b2,0x55ca,0x55e2,0x55fa,0x5611, +0x5629,0x5641,0x5659,0x5670,0x5688,0x56a0,0x56b7,0x56cf, +0x56e6,0x56fe,0x5716,0x572d,0x5745,0x575c,0x5773,0x578b, +0x57a2,0x57ba,0x57d1,0x57e8,0x5800,0x5817,0x582e,0x5845, +0x585c,0x5874,0x588b,0x58a2,0x58b9,0x58d0,0x58e7,0x58fe, +0x5915,0x592c,0x5943,0x595a,0x5971,0x5988,0x599f,0x59b5, +0x59cc,0x59e3,0x59fa,0x5a11,0x5a27,0x5a3e,0x5a55,0x5a6b, +0x5a82,0x5a99,0x5aaf,0x5ac6,0x5adc,0x5af3,0x5b09,0x5b20, +0x5b36,0x5b4d,0x5b63,0x5b7a,0x5b90,0x5ba6,0x5bbd,0x5bd3, +0x5be9,0x5c00,0x5c16,0x5c2c,0x5c42,0x5c58,0x5c6f,0x5c85, +0x5c9b,0x5cb1,0x5cc7,0x5cdd,0x5cf3,0x5d09,0x5d1f,0x5d35, +0x5d4b,0x5d61,0x5d77,0x5d8d,0x5da3,0x5db9,0x5dce,0x5de4, +0x5dfa,0x5e10,0x5e26,0x5e3b,0x5e51,0x5e67,0x5e7c,0x5e92, +0x5ea8,0x5ebd,0x5ed3,0x5ee9,0x5efe,0x5f14,0x5f29,0x5f3f, +0x5f54,0x5f6a,0x5f7f,0x5f95,0x5faa,0x5fbf,0x5fd5,0x5fea, +0x6000,0x6015,0x602a,0x603f,0x6055,0x606a,0x607f,0x6094, +0x60aa,0x60bf,0x60d4,0x60e9,0x60fe,0x6113,0x6128,0x613d, +0x6152,0x6168,0x617d,0x6192,0x61a7,0x61bb,0x61d0,0x61e5, +0x61fa,0x620f,0x6224,0x6239,0x624e,0x6263,0x6277,0x628c, +0x62a1,0x62b6,0x62ca,0x62df,0x62f4,0x6309,0x631d,0x6332, +0x6347,0x635b,0x6370,0x6384,0x6399,0x63ad,0x63c2,0x63d7, +0x63eb,0x6400,0x6414,0x6428,0x643d,0x6451,0x6466,0x647a, +0x648e,0x64a3,0x64b7,0x64cb,0x64e0,0x64f4,0x6508,0x651d, +0x6531,0x6545,0x6559,0x656e,0x6582,0x6596,0x65aa,0x65be, +0x65d2,0x65e6,0x65fa,0x660f,0x6623,0x6637,0x664b,0x665f, +0x6673,0x6687,0x669b,0x66af,0x66c3,0x66d6,0x66ea,0x66fe, +0x6712,0x6726,0x673a,0x674e,0x6761,0x6775,0x6789,0x679d, +0x67b1,0x67c4,0x67d8,0x67ec,0x6800,0x6813,0x6827,0x683b, +0x684e,0x6862,0x6875,0x6889,0x689d,0x68b0,0x68c4,0x68d7, +0x68eb,0x68fe,0x6912,0x6925,0x6939,0x694c,0x6960,0x6973, +0x6986,0x699a,0x69ad,0x69c1,0x69d4,0x69e7,0x69fb,0x6a0e, +0x6a21,0x6a35,0x6a48,0x6a5b,0x6a6e,0x6a82,0x6a95,0x6aa8, +0x6abb,0x6ace,0x6ae2,0x6af5,0x6b08,0x6b1b,0x6b2e,0x6b41, +0x6b54,0x6b67,0x6b7a,0x6b8d,0x6ba1,0x6bb4,0x6bc7,0x6bda, +0x6bed,0x6c00,0x6c12,0x6c25,0x6c38,0x6c4b,0x6c5e,0x6c71, +0x6c84,0x6c97,0x6caa,0x6cbc,0x6ccf,0x6ce2,0x6cf5,0x6d08, +0x6d1a,0x6d2d,0x6d40,0x6d53,0x6d65,0x6d78,0x6d8b,0x6d9e, +0x6db0,0x6dc3,0x6dd6,0x6de8,0x6dfb,0x6e0d,0x6e20,0x6e33, +0x6e45,0x6e58,0x6e6a,0x6e7d,0x6e8f,0x6ea2,0x6eb4,0x6ec7, +0x6ed9,0x6eec,0x6efe,0x6f11,0x6f23,0x6f36,0x6f48,0x6f5a, +0x6f6d,0x6f7f,0x6f92,0x6fa4,0x6fb6,0x6fc9,0x6fdb,0x6fed, +0x7000,0x7012,0x7024,0x7036,0x7049,0x705b,0x706d,0x707f, +0x7091,0x70a4,0x70b6,0x70c8,0x70da,0x70ec,0x70fe,0x7110, +0x7123,0x7135,0x7147,0x7159,0x716b,0x717d,0x718f,0x71a1, +0x71b3,0x71c5,0x71d7,0x71e9,0x71fb,0x720d,0x721f,0x7231, +0x7243,0x7255,0x7267,0x7279,0x728a,0x729c,0x72ae,0x72c0, +0x72d2,0x72e4,0x72f5,0x7307,0x7319,0x732b,0x733d,0x734e, +0x7360,0x7372,0x7384,0x7395,0x73a7,0x73b9,0x73ca,0x73dc, +0x73ee,0x7400,0x7411,0x7423,0x7434,0x7446,0x7458,0x7469, +0x747b,0x748c,0x749e,0x74b0,0x74c1,0x74d3,0x74e4,0x74f6, +0x7507,0x7519,0x752a,0x753c,0x754d,0x755f,0x7570,0x7581, +0x7593,0x75a4,0x75b6,0x75c7,0x75d8,0x75ea,0x75fb,0x760d, +0x761e,0x762f,0x7641,0x7652,0x7663,0x7674,0x7686,0x7697, +0x76a8,0x76ba,0x76cb,0x76dc,0x76ed,0x76fe,0x7710,0x7721, +0x7732,0x7743,0x7754,0x7766,0x7777,0x7788,0x7799,0x77aa, +0x77bb,0x77cc,0x77dd,0x77ee,0x7800,0x7811,0x7822,0x7833, +0x7844,0x7855,0x7866,0x7877,0x7888,0x7899,0x78aa,0x78bb, +0x78cc,0x78dd,0x78ee,0x78fe,0x790f,0x7920,0x7931,0x7942, +0x7953,0x7964,0x7975,0x7986,0x7996,0x79a7,0x79b8,0x79c9, +0x79da,0x79eb,0x79fb,0x7a0c,0x7a1d,0x7a2e,0x7a3e,0x7a4f, +0x7a60,0x7a71,0x7a81,0x7a92,0x7aa3,0x7ab3,0x7ac4,0x7ad5, +0x7ae5,0x7af6,0x7b07,0x7b17,0x7b28,0x7b39,0x7b49,0x7b5a, +0x7b6b,0x7b7b,0x7b8c,0x7b9c,0x7bad,0x7bbd,0x7bce,0x7bde, +0x7bef,0x7c00,0x7c10,0x7c21,0x7c31,0x7c41,0x7c52,0x7c62, +0x7c73,0x7c83,0x7c94,0x7ca4,0x7cb5,0x7cc5,0x7cd5,0x7ce6, +0x7cf6,0x7d07,0x7d17,0x7d27,0x7d38,0x7d48,0x7d58,0x7d69, +0x7d79,0x7d89,0x7d9a,0x7daa,0x7dba,0x7dcb,0x7ddb,0x7deb, +0x7dfb,0x7e0c,0x7e1c,0x7e2c,0x7e3c,0x7e4d,0x7e5d,0x7e6d, +0x7e7d,0x7e8d,0x7e9e,0x7eae,0x7ebe,0x7ece,0x7ede,0x7eee, +0x7efe,0x7f0f,0x7f1f,0x7f2f,0x7f3f,0x7f4f,0x7f5f,0x7f6f, +0x7f7f,0x7f8f,0x7f9f,0x7faf,0x7fbf,0x7fcf,0x7fdf,0x7fef, +0x8000,0x800f,0x801f,0x802f,0x803f,0x804f,0x805f,0x806f, +0x807f,0x808f,0x809f,0x80af,0x80bf,0x80cf,0x80df,0x80ef, +0x80ff,0x810e,0x811e,0x812e,0x813e,0x814e,0x815e,0x816d, +0x817d,0x818d,0x819d,0x81ad,0x81bc,0x81cc,0x81dc,0x81ec, +0x81fc,0x820b,0x821b,0x822b,0x823b,0x824a,0x825a,0x826a, +0x8279,0x8289,0x8299,0x82a8,0x82b8,0x82c8,0x82d7,0x82e7, +0x82f7,0x8306,0x8316,0x8326,0x8335,0x8345,0x8354,0x8364, +0x8374,0x8383,0x8393,0x83a2,0x83b2,0x83c1,0x83d1,0x83e0, +0x83f0,0x8400,0x840f,0x841f,0x842e,0x843e,0x844d,0x845c, +0x846c,0x847b,0x848b,0x849a,0x84aa,0x84b9,0x84c9,0x84d8, +0x84e7,0x84f7,0x8506,0x8516,0x8525,0x8534,0x8544,0x8553, +0x8562,0x8572,0x8581,0x8591,0x85a0,0x85af,0x85be,0x85ce, +0x85dd,0x85ec,0x85fc,0x860b,0x861a,0x862a,0x8639,0x8648, +0x8657,0x8667,0x8676,0x8685,0x8694,0x86a3,0x86b3,0x86c2, +0x86d1,0x86e0,0x86ef,0x86ff,0x870e,0x871d,0x872c,0x873b, +0x874a,0x8759,0x8769,0x8778,0x8787,0x8796,0x87a5,0x87b4, +0x87c3,0x87d2,0x87e1,0x87f0,0x8800,0x880f,0x881e,0x882d, +0x883c,0x884b,0x885a,0x8869,0x8878,0x8887,0x8896,0x88a5, +0x88b4,0x88c3,0x88d2,0x88e1,0x88f0,0x88ff,0x890e,0x891c, +0x892b,0x893a,0x8949,0x8958,0x8967,0x8976,0x8985,0x8994, +0x89a3,0x89b2,0x89c0,0x89cf,0x89de,0x89ed,0x89fc,0x8a0b, +0x8a19,0x8a28,0x8a37,0x8a46,0x8a55,0x8a64,0x8a72,0x8a81, +0x8a90,0x8a9f,0x8aad,0x8abc,0x8acb,0x8ada,0x8ae8,0x8af7, +0x8b06,0x8b15,0x8b23,0x8b32,0x8b41,0x8b50,0x8b5e,0x8b6d, +0x8b7c,0x8b8a,0x8b99,0x8ba8,0x8bb6,0x8bc5,0x8bd4,0x8be2, +0x8bf1,0x8c00,0x8c0e,0x8c1d,0x8c2b,0x8c3a,0x8c49,0x8c57, +0x8c66,0x8c74,0x8c83,0x8c91,0x8ca0,0x8caf,0x8cbd,0x8ccc, +0x8cda,0x8ce9,0x8cf7,0x8d06,0x8d14,0x8d23,0x8d31,0x8d40, +0x8d4e,0x8d5d,0x8d6b,0x8d7a,0x8d88,0x8d97,0x8da5,0x8db4, +0x8dc2,0x8dd1,0x8ddf,0x8ded,0x8dfc,0x8e0a,0x8e19,0x8e27, +0x8e36,0x8e44,0x8e52,0x8e61,0x8e6f,0x8e7d,0x8e8c,0x8e9a, +0x8ea9,0x8eb7,0x8ec5,0x8ed4,0x8ee2,0x8ef0,0x8eff,0x8f0d, +0x8f1b,0x8f2a,0x8f38,0x8f46,0x8f54,0x8f63,0x8f71,0x8f7f, +0x8f8e,0x8f9c,0x8faa,0x8fb8,0x8fc7,0x8fd5,0x8fe3,0x8ff1, |