comparison ra288.c @ 7167:9b93a3cf6440 libavcodec

Reindent the whole file
author vitor
date Mon, 30 Jun 2008 16:53:33 +0000
parents e943e1409077
children c2691f22708b
comparison
equal deleted inserted replaced
7166:74488eb735a6 7167:9b93a3cf6440
21 21
22 #include "avcodec.h" 22 #include "avcodec.h"
23 #include "ra288.h" 23 #include "ra288.h"
24 24
25 typedef struct { 25 typedef struct {
26 float history[8]; 26 float history[8];
27 float output[40]; 27 float output[40];
28 float pr1[36]; 28 float pr1[36];
29 float pr2[10]; 29 float pr2[10];
30 int phase, phasep; 30 int phase, phasep;
31 31
32 float st1a[111],st1b[37],st1[37]; 32 float st1a[111], st1b[37], st1[37];
33 float st2a[38],st2b[11],st2[11]; 33 float st2a[38], st2b[11], st2[11];
34 float sb[41]; 34 float sb[41];
35 float lhist[10]; 35 float lhist[10];
36 } Real288_internal; 36 } Real288_internal;
37 37
38 static int ra288_decode_init(AVCodecContext * avctx) 38 static int ra288_decode_init(AVCodecContext * avctx)
39 { 39 {
40 Real288_internal *glob=avctx->priv_data; 40 Real288_internal *glob = avctx->priv_data;
41 memset(glob,0,sizeof(Real288_internal)); 41 memset(glob, 0, sizeof(Real288_internal));
42 return 0; 42 return 0;
43 } 43 }
44 44
45 static void prodsum(float *tgt, float *src, int len, int n); 45 static void prodsum(float *tgt, float *src, int len, int n);
46 static void co(int n, int i, int j, float *in, float *out, float *st1, float *st2, const float *table); 46 static void co(int n, int i, int j, float *in, float *out, float *st1, float *st2, const float *table);
47 static int pred(float *in, float *tgt, int n); 47 static int pred(float *in, float *tgt, int n);
48 static void colmult(float *tgt, float *m1, const float *m2, int n); 48 static void colmult(float *tgt, float *m1, const float *m2, int n);
49 49
50 50
51 /* initial decode */ 51 /* initial decode */
52 static void unpack(unsigned short *tgt, const unsigned char *src, unsigned int len) 52 static void unpack(unsigned short *tgt, const unsigned char *src,
53 { 53 unsigned int len)
54 int x,y,z; 54 {
55 int n,temp; 55 int x, y, z;
56 int buffer[len]; 56 int n, temp;
57 57 int buffer[len];
58 for (x=0;x<len;tgt[x++]=0) 58
59 buffer[x]=9+(x&1); 59 for (x=0; x < len; tgt[x++] = 0)
60 60 buffer[x] = 9 + (x & 1);
61 for (x=y=z=0;x<len/*was 38*/;x++) { 61
62 n=buffer[y]-z; 62 for (x=y=z=0; x < len/*was 38*/; x++) {
63 temp=src[x]; 63 n = buffer[y] - z;
64 if (n<8) temp&=255>>(8-n); 64 temp = src[x];
65 tgt[y]+=temp<<z; 65
66 if (n<=8) { 66 if (n < 8)
67 tgt[++y]+=src[x]>>n; 67 temp &= 255 >> (8 - n);
68 z=8-n; 68
69 } else z+=8; 69 tgt[y] += temp << z;
70
71 if (n <= 8) {
72 tgt[++y] += src[x] >> n;
73 z = 8 - n;
74 } else
75 z += 8;
70 } 76 }
71 } 77 }
72 78
73 static void update(Real288_internal *glob) 79 static void update(Real288_internal *glob)
74 { 80 {
75 int x,y; 81 int x,y;
76 float buffer1[40],temp1[37]; 82 float buffer1[40], temp1[37];
77 float buffer2[8],temp2[11]; 83 float buffer2[8], temp2[11];
78 84
79 for (x=0,y=glob->phasep+5;x<40;buffer1[x++]=glob->output[(y++)%40]); 85 for (x=0, y=glob->phasep+5; x < 40; buffer1[x++] = glob->output[(y++)%40]);
80 co(36,40,35,buffer1,temp1,glob->st1a,glob->st1b,table1); 86
81 if (pred(temp1,glob->st1,36)) 87 co(36, 40, 35, buffer1, temp1, glob->st1a, glob->st1b, table1);
82 colmult(glob->pr1,glob->st1,table1a,36); 88
83 89 if (pred(temp1, glob->st1, 36))
84 for (x=0,y=glob->phase+1;x<8;buffer2[x++]=glob->history[(y++)%8]); 90 colmult(glob->pr1, glob->st1, table1a, 36);
85 co(10,8,20,buffer2,temp2,glob->st2a,glob->st2b,table2); 91
86 if (pred(temp2,glob->st2,10)) 92 for (x=0, y=glob->phase + 1; x < 8; buffer2[x++] = glob->history[(y++) % 8]);
87 colmult(glob->pr2,glob->st2,table2a,10); 93
94 co(10, 8, 20, buffer2, temp2, glob->st2a, glob->st2b, table2);
95
96 if (pred(temp2, glob->st2, 10))
97 colmult(glob->pr2, glob->st2, table2a, 10);
88 } 98 }
89 99
90 /* Decode and produce output */ 100 /* Decode and produce output */
91 static void decode(Real288_internal *glob, unsigned int input) 101 static void decode(Real288_internal *glob, unsigned int input)
92 { 102 {
93 unsigned int x,y; 103 unsigned int x, y;
94 float f; 104 float f;
95 double sum,sumsum; 105 double sum, sumsum;
96 float *p1,*p2; 106 float *p1, *p2;
97 float buffer[5]; 107 float buffer[5];
98 const float *table; 108 const float *table;
99 109
100 for (x=36;x--;glob->sb[x+5]=glob->sb[x]); 110 for (x=36; x--; glob->sb[x+5] = glob->sb[x]);
101 for (x=5;x--;) { 111
102 p1=glob->sb+x;p2=glob->pr1; 112 for (x=5; x--;) {
103 for (sum=0,y=36;y--;sum-=(*(++p1))*(*(p2++))); 113 p1 = glob->sb+x;
104 glob->sb[x]=sum; 114 p2 = glob->pr1;
105 } 115 for (sum=0, y=36; y--; sum -= (*(++p1))*(*(p2++)));
106 116
107 f=amptable[input&7]; 117 glob->sb[x] = sum;
108 table=codetable+(input>>3)*5; 118 }
109 119
110 /* convert log and do rms */ 120 f = amptable[input & 7];
111 for (sum=32,x=10;x--;sum-=glob->pr2[x]*glob->lhist[x]); 121 table = codetable + (input >> 3) * 5;
112 if (sum<0) sum=0; else if (sum>60) sum=60; 122
113 123 /* convert log and do rms */
114 sumsum=exp(sum*0.1151292546497)*f; /* pow(10.0,sum/20)*f */ 124 for (sum=32, x=10; x--; sum -= glob->pr2[x] * glob->lhist[x]);
115 for (sum=0,x=5;x--;) { buffer[x]=table[x]*sumsum; sum+=buffer[x]*buffer[x]; } 125
116 if ((sum/=5)<1) sum=1; 126 if (sum < 0)
117 127 sum = 0;
118 /* shift and store */ 128 else if (sum > 60)
119 for (x=10;--x;glob->lhist[x]=glob->lhist[x-1]); 129 sum = 60;
120 *glob->lhist=glob->history[glob->phase]=10*log10(sum)-32; 130
121 131 sumsum = exp(sum * 0.1151292546497) * f; /* pow(10.0,sum/20)*f */
122 for (x=1;x<5;x++) for (y=x;y--;buffer[x]-=glob->pr1[x-y-1]*buffer[y]); 132
123 133 for (sum=0, x=5; x--;) {
124 /* output */ 134 buffer[x] = table[x] * sumsum;
125 for (x=0;x<5;x++) { 135 sum += buffer[x] * buffer[x];
126 f=glob->sb[4-x]+buffer[x]; 136 }
127 if (f>4095) f=4095; else if (f<-4095) f=-4095; 137
128 glob->output[glob->phasep+x]=glob->sb[4-x]=f; 138 if ((sum /= 5) < 1)
129 } 139 sum = 1;
140
141 /* shift and store */
142 for (x=10; --x; glob->lhist[x] = glob->lhist[x-1]);
143
144 *glob->lhist = glob->history[glob->phase] = 10 * log10(sum) - 32;
145
146 for (x=1; x < 5; x++)
147 for (y=x; y--; buffer[x] -= glob->pr1[x-y-1] * buffer[y]);
148
149 /* output */
150 for (x=0; x < 5; x++) {
151 f = glob->sb[4-x] + buffer[x];
152
153 if (f > 4095)
154 f = 4095;
155 else if (f < -4095)
156 f = -4095;
157
158 glob->output[glob->phasep+x] = glob->sb[4-x] = f;
159 }
130 } 160 }
131 161
132 /* column multiply */ 162 /* column multiply */
133 static void colmult(float *tgt, float *m1, const float *m2, int n) 163 static void colmult(float *tgt, float *m1, const float *m2, int n)
134 { 164 {
135 while (n--) 165 while (n--)
136 *(tgt++)=(*(m1++))*(*(m2++)); 166 *(tgt++) = (*(m1++)) * (*(m2++));
137 } 167 }
138 168
139 static int pred(float *in, float *tgt, int n) 169 static int pred(float *in, float *tgt, int n)
140 { 170 {
141 int x,y; 171 int x, y;
142 float *p1,*p2; 172 float *p1, *p2;
143 double f0,f1,f2; 173 double f0, f1, f2;
144 float temp; 174 float temp;
145 175
146 if (in[n]==0) return 0; 176 if (in[n] == 0)
147 if ((f0=*in)<=0) return 0; 177 return 0;
148 178
149 for (x=1;;x++) { 179 if ((f0 = *in) <= 0)
150 if (n<x) return 1; 180 return 0;
151 181
152 p1=in+x; 182 for (x=1 ; ; x++) {
153 p2=tgt; 183 if (n < x)
154 f1=*(p1--); 184 return 1;
155 for (y=x;--y;f1+=(*(p1--))*(*(p2++))); 185
156 186 p1 = in + x;
157 p1=tgt+x-1; 187 p2 = tgt;
158 p2=tgt; 188 f1 = *(p1--);
159 *(p1--)=f2=-f1/f0; 189 for (y=x; --y; f1 += (*(p1--))*(*(p2++)));
160 for (y=x>>1;y--;) { 190
161 temp=*p2+*p1*f2; 191 p1 = tgt + x - 1;
162 *(p1--)+=*p2*f2; 192 p2 = tgt;
163 *(p2++)=temp; 193 *(p1--) = f2 = -f1/f0;
164 } 194 for (y=x >> 1; y--;) {
165 if ((f0+=f1*f2)<0) return 0; 195 temp = *p2 + *p1 * f2;
166 } 196 *(p1--) += *p2 * f2;
167 } 197 *(p2++) = temp;
168 198 }
169 static void co(int n, int i, int j, float *in, float *out, float *st1, float *st2, const float *table) 199 if ((f0 += f1*f2) < 0)
170 { 200 return 0;
171 int a,b,c; 201 }
172 unsigned int x; 202 }
173 float *fp; 203
174 float buffer1[37]; 204 static void co(int n, int i, int j, float *in, float *out, float *st1,
175 float buffer2[37]; 205 float *st2, const float *table)
176 float work[111]; 206 {
177 207 int a, b, c;
178 /* rotate and multiply */ 208 unsigned int x;
179 c=(b=(a=n+i)+j)-i; 209 float *fp;
180 fp=st1+i; 210 float buffer1[37];
181 for (x=0;x<b;x++) { 211 float buffer2[37];
182 if (x==c) fp=in; 212 float work[111];
183 work[x]=*(table++)*(*(st1++)=*(fp++)); 213
184 } 214 /* rotate and multiply */
185 215 c = (b = (a = n + i) + j) - i;
186 prodsum(buffer1,work+n,i,n); 216 fp = st1 + i;
187 prodsum(buffer2,work+a,j,n); 217 for (x=0; x < b; x++) {
188 218 if (x == c)
189 for (x=0;x<=n;x++) { 219 fp=in;
190 *st2=*st2*(0.5625)+buffer1[x]; 220 work[x] = *(table++) * (*(st1++) = *(fp++));
191 out[x]=*(st2++)+buffer2[x]; 221 }
192 } 222
193 *out*=1.00390625; /* to prevent clipping */ 223 prodsum(buffer1, work + n, i, n);
224 prodsum(buffer2, work + a, j, n);
225
226 for (x=0;x<=n;x++) {
227 *st2 = *st2 * (0.5625) + buffer1[x];
228 out[x] = *(st2++) + buffer2[x];
229 }
230 *out *= 1.00390625; /* to prevent clipping */
194 } 231 }
195 232
196 /* product sum (lsf) */ 233 /* product sum (lsf) */
197 static void prodsum(float *tgt, float *src, int len, int n) 234 static void prodsum(float *tgt, float *src, int len, int n)
198 { 235 {
199 unsigned int x; 236 unsigned int x;
200 float *p1,*p2; 237 float *p1, *p2;
201 double sum; 238 double sum;
202 239
203 while (n>=0) 240 while (n >= 0) {
204 { 241 p1 = (p2 = src) - n;
205 p1=(p2=src)-n; 242 for (sum=0, x=len; x--; sum += (*p1++) * (*p2++));
206 for (sum=0,x=len;x--;sum+=(*p1++)*(*p2++)); 243 tgt[n--] = sum;
207 tgt[n--]=sum; 244 }
208 } 245 }
209 } 246
210 247 static void * decode_block(AVCodecContext * avctx, const unsigned char *in,
211 static void * decode_block(AVCodecContext * avctx, const unsigned char *in, signed short int *out,unsigned len) 248 signed short int *out, unsigned len)
212 { 249 {
213 int x,y; 250 int x, y;
214 Real288_internal *glob=avctx->priv_data; 251 Real288_internal *glob = avctx->priv_data;
215 unsigned short int buffer[len]; 252 unsigned short int buffer[len];
216 253
217 unpack(buffer,in,len); 254 unpack(buffer, in, len);
218 for (x=0;x<32;x++) 255
219 { 256 for (x=0; x < 32; x++) {
220 glob->phasep=(glob->phase=x&7)*5; 257 glob->phasep = (glob->phase = x & 7) * 5;
221 decode(glob,buffer[x]); 258 decode(glob, buffer[x]);
222 for (y=0;y<5;*(out++)=8*glob->output[glob->phasep+(y++)]); 259
223 if (glob->phase==3) update(glob); 260 for (y=0; y<5; *(out++) = 8 * glob->output[glob->phasep+(y++)]);
224 } 261
225 return out; 262 if (glob->phase == 3)
263 update(glob);
264 }
265
266 return out;
226 } 267 }
227 268
228 /* Decode a block (celp) */ 269 /* Decode a block (celp) */
229 static int ra288_decode_frame(AVCodecContext * avctx, 270 static int ra288_decode_frame(AVCodecContext * avctx, void *data,
230 void *data, int *data_size, 271 int *data_size, const uint8_t * buf,
231 const uint8_t * buf, int buf_size) 272 int buf_size)
232 { 273 {
233 void *datao; 274 void *datao;
234 275
235 if (buf_size < avctx->block_align) 276 if (buf_size < avctx->block_align) {
236 { 277 av_log(avctx, AV_LOG_ERROR,
237 av_log(avctx, AV_LOG_ERROR, "ffra288: Error! Input buffer is too small [%d<%d]\n",buf_size,avctx->block_align); 278 "ffra288: Error! Input buffer is too small [%d<%d]\n",
279 buf_size, avctx->block_align);
238 return 0; 280 return 0;
239 } 281 }
240 282
241 datao = data; 283 datao = data;
242 data = decode_block(avctx, buf, (signed short *)data, avctx->block_align); 284 data = decode_block(avctx, buf, (signed short *)data, avctx->block_align);