2
* RealAudio 2.0 (28.8K)
3
* Copyright (c) 2003 the ffmpeg project
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
float st1a[111],st1b[37],st1[37];
31
float st2a[38],st2b[11],st2[11];
36
static int ra288_decode_init(AVCodecContext * avctx)
38
Real288_internal *glob=avctx->priv_data;
39
memset(glob,0,sizeof(Real288_internal));
43
static void prodsum(float *tgt, float *src, int len, int n);
44
static void co(int n, int i, int j, float *in, float *out, float *st1, float *st2, const float *table);
45
static int pred(float *in, float *tgt, int n);
46
static void colmult(float *tgt, float *m1, const float *m2, int n);
50
static void unpack(unsigned short *tgt, unsigned char *src, int len)
56
for (x=0;x<len;tgt[x++]=0)
59
for (x=y=z=0;x<len/*was 38*/;x++) {
62
if (n<8) temp&=255>>(8-n);
71
static void update(Real288_internal *glob)
74
float buffer1[40],temp1[37];
75
float buffer2[8],temp2[11];
77
for (x=0,y=glob->phasep+5;x<40;buffer1[x++]=glob->output[(y++)%40]);
78
co(36,40,35,buffer1,temp1,glob->st1a,glob->st1b,table1);
79
if (pred(temp1,glob->st1,36))
80
colmult(glob->pr1,glob->st1,table1a,36);
82
for (x=0,y=glob->phase+1;x<8;buffer2[x++]=glob->history[(y++)%8]);
83
co(10,8,20,buffer2,temp2,glob->st2a,glob->st2b,table2);
84
if (pred(temp2,glob->st2,10))
85
colmult(glob->pr2,glob->st2,table2a,10);
88
/* Decode and produce output */
89
static void decode(Real288_internal *glob, unsigned int input)
98
for (x=36;x--;glob->sb[x+5]=glob->sb[x]);
100
p1=glob->sb+x;p2=glob->pr1;
101
for (sum=0,y=36;y--;sum-=(*(++p1))*(*(p2++)));
106
table=codetable+(input>>3)*5;
108
/* convert log and do rms */
109
for (sum=32,x=10;x--;sum-=glob->pr2[x]*glob->lhist[x]);
110
if (sum<0) sum=0; else if (sum>60) sum=60;
112
sumsum=exp(sum*0.1151292546497)*f; /* pow(10.0,sum/20)*f */
113
for (sum=0,x=5;x--;) { buffer[x]=table[x]*sumsum; sum+=buffer[x]*buffer[x]; }
114
if ((sum/=5)<1) sum=1;
116
/* shift and store */
117
for (x=10;--x;glob->lhist[x]=glob->lhist[x-1]);
118
*glob->lhist=glob->history[glob->phase]=10*log10(sum)-32;
120
for (x=1;x<5;x++) for (y=x;y--;buffer[x]-=glob->pr1[x-y-1]*buffer[y]);
124
f=glob->sb[4-x]+buffer[x];
125
if (f>4095) f=4095; else if (f<-4095) f=-4095;
126
glob->output[glob->phasep+x]=glob->sb[4-x]=f;
130
/* column multiply */
131
static void colmult(float *tgt, float *m1, const float *m2, int n)
134
*(tgt++)=(*(m1++))*(*(m2++));
137
static int pred(float *in, float *tgt, int n)
144
if (in[n]==0) return 0;
145
if ((f0=*in)<=0) return 0;
153
for (y=x;--y;f1+=(*(p1--))*(*(p2++)));
163
if ((f0+=f1*f2)<0) return 0;
167
static void co(int n, int i, int j, float *in, float *out, float *st1, float *st2, const float *table)
176
/* rotate and multiply */
181
work[x]=*(table++)*(*(st1++)=*(fp++));
184
prodsum(buffer1,work+n,i,n);
185
prodsum(buffer2,work+a,j,n);
188
*st2=*st2*(0.5625)+buffer1[x];
189
out[x]=*(st2++)+buffer2[x];
191
*out*=1.00390625; /* to prevent clipping */
194
/* product sum (lsf) */
195
static void prodsum(float *tgt, float *src, int len, int n)
204
for (sum=0,x=len;x--;sum+=(*p1++)*(*p2++));
209
void * decode_block(AVCodecContext * avctx, unsigned char *in, signed short int *out,unsigned len)
212
Real288_internal *glob=avctx->priv_data;
213
unsigned short int buffer[len];
215
unpack(buffer,in,len);
218
glob->phasep=(glob->phase=x&7)*5;
219
decode(glob,buffer[x]);
220
for (y=0;y<5;*(out++)=8*glob->output[glob->phasep+(y++)]);
221
if (glob->phase==3) update(glob);
226
/* Decode a block (celp) */
227
static int ra288_decode_frame(AVCodecContext * avctx,
228
void *data, int *data_size,
229
uint8_t * buf, int buf_size)
231
if(avctx->extradata_size>=6)
233
//((short*)(avctx->extradata))[0]; /* subpacket size */
234
//((short*)(avctx->extradata))[1]; /* subpacket height */
235
//((short*)(avctx->extradata))[2]; /* subpacket flavour */
236
//((short*)(avctx->extradata))[3]; /* coded frame size */
237
//((short*)(avctx->extradata))[4]; /* codec's data length */
238
//((short*)(avctx->extradata))[5...] /* codec's data */
241
int w=avctx->block_align; /* 228 */
242
int h=((short*)(avctx->extradata))[1]; /* 12 */
243
int cfs=((short*)(avctx->extradata))[3]; /* coded frame size 38 */
247
fprintf(stderr,"ffra288: Error! Input buffer is too small [%d<%d]\n",buf_size,w*h);
252
for (j = 0; j < h/2; j++)
253
for (i = 0; i < h; i++)
255
data=decode_block(avctx,&buf[j*cfs+cfs*i*h/2],(signed short *)data,cfs);
258
*data_size = data - datao;
263
fprintf(stderr,"ffra288: Error: need extra data!!!\n");
268
AVCodec ra_288_decoder =
273
sizeof(Real288_internal),