comparison ra144.c @ 6895:c63e9357e2a8 libavcodec

Context vars are not global vars. glob is a bad name for it.
author vitor
date Mon, 26 May 2008 16:59:39 +0000
parents eb3c16b99f27
children 5f79e5940b33
comparison
equal deleted inserted replaced
6894:eb3c16b99f27 6895:c63e9357e2a8
44 uint16_t buffer_2[148]; 44 uint16_t buffer_2[148];
45 } RA144Context; 45 } RA144Context;
46 46
47 static int ra144_decode_init(AVCodecContext * avctx) 47 static int ra144_decode_init(AVCodecContext * avctx)
48 { 48 {
49 RA144Context *glob = avctx->priv_data; 49 RA144Context *ractx = avctx->priv_data;
50 50
51 glob->swapbuf1 = glob->swapbuffers[0]; 51 ractx->swapbuf1 = ractx->swapbuffers[0];
52 glob->swapbuf2 = glob->swapbuffers[1]; 52 ractx->swapbuf2 = ractx->swapbuffers[1];
53 glob->swapbuf1alt = glob->swapbuffers[2]; 53 ractx->swapbuf1alt = ractx->swapbuffers[2];
54 glob->swapbuf2alt = glob->swapbuffers[3]; 54 ractx->swapbuf2alt = ractx->swapbuffers[3];
55 55
56 return 0; 56 return 0;
57 } 57 }
58 58
59 /* lookup square roots in table */ 59 /* lookup square roots in table */
197 res = (res * f) >> 10; 197 res = (res * f) >> 10;
198 return res; 198 return res;
199 } 199 }
200 200
201 /* do quarter-block output */ 201 /* do quarter-block output */
202 static void do_output_subblock(RA144Context *glob, 202 static void do_output_subblock(RA144Context *ractx,
203 const uint16_t *gsp, unsigned int gval, 203 const uint16_t *gsp, unsigned int gval,
204 int16_t *output_buffer, GetBitContext *gb) 204 int16_t *output_buffer, GetBitContext *gb)
205 { 205 {
206 uint16_t buffer_a[40]; 206 uint16_t buffer_a[40];
207 uint16_t *block; 207 uint16_t *block;
211 int c = get_bits(gb, 7); 211 int c = get_bits(gb, 7);
212 int m[3]; 212 int m[3];
213 213
214 if (a) { 214 if (a) {
215 a += HALFBLOCK - 1; 215 a += HALFBLOCK - 1;
216 rotate_block(glob->buffer_2, buffer_a, a); 216 rotate_block(ractx->buffer_2, buffer_a, a);
217 m[0] = irms(buffer_a, gval) >> 12; 217 m[0] = irms(buffer_a, gval) >> 12;
218 } else { 218 } else {
219 m[0] = 0; 219 m[0] = 0;
220 } 220 }
221 221
222 m[1] = ((ftable1[b] >> 4) * gval) >> 8; 222 m[1] = ((ftable1[b] >> 4) * gval) >> 8;
223 m[2] = ((ftable2[c] >> 4) * gval) >> 8; 223 m[2] = ((ftable2[c] >> 4) * gval) >> 8;
224 224
225 memmove(glob->buffer_2, glob->buffer_2 + BLOCKSIZE, 225 memmove(ractx->buffer_2, ractx->buffer_2 + BLOCKSIZE,
226 (BUFFERSIZE - BLOCKSIZE) * 2); 226 (BUFFERSIZE - BLOCKSIZE) * 2);
227 227
228 block = glob->buffer_2 + BUFFERSIZE - BLOCKSIZE; 228 block = ractx->buffer_2 + BUFFERSIZE - BLOCKSIZE;
229 229
230 add_wav(d, a, m, buffer_a, etable1[b], etable2[c], block); 230 add_wav(d, a, m, buffer_a, etable1[b], etable2[c], block);
231 231
232 final(gsp, block, output_buffer, glob->buffer, BLOCKSIZE); 232 final(gsp, block, output_buffer, ractx->buffer, BLOCKSIZE);
233 } 233 }
234 234
235 static int dec1(int16_t *decsp, const int *data, const int *inp, int f) 235 static int dec1(int16_t *decsp, const int *data, const int *inp, int f)
236 { 236 {
237 int i; 237 int i;
312 unsigned int a, c; 312 unsigned int a, c;
313 int i; 313 int i;
314 int16_t *data = vdata; 314 int16_t *data = vdata;
315 unsigned int val; 315 unsigned int val;
316 316
317 RA144Context *glob = avctx->priv_data; 317 RA144Context *ractx = avctx->priv_data;
318 GetBitContext gb; 318 GetBitContext gb;
319 319
320 if(buf_size < 20) { 320 if(buf_size < 20) {
321 av_log(avctx, AV_LOG_ERROR, 321 av_log(avctx, AV_LOG_ERROR,
322 "Frame too small (%d bytes). Truncated file?\n", buf_size); 322 "Frame too small (%d bytes). Truncated file?\n", buf_size);
324 } 324 }
325 init_get_bits(&gb, buf, 20 * 8); 325 init_get_bits(&gb, buf, 20 * 8);
326 326
327 for (i=0; i<10; i++) 327 for (i=0; i<10; i++)
328 // "<< 1"? Doesn't this make one value out of two of the table useless? 328 // "<< 1"? Doesn't this make one value out of two of the table useless?
329 glob->swapbuf1[i] = decodetable[i][get_bits(&gb, sizes[i]) << 1]; 329 ractx->swapbuf1[i] = decodetable[i][get_bits(&gb, sizes[i]) << 1];
330 330
331 do_voice(glob->swapbuf1, glob->swapbuf2); 331 do_voice(ractx->swapbuf1, ractx->swapbuf2);
332 332
333 val = decodeval[get_bits(&gb, 5) << 1]; // Useless table entries? 333 val = decodeval[get_bits(&gb, 5) << 1]; // Useless table entries?
334 a = t_sqrt(val*glob->oldval) >> 12; 334 a = t_sqrt(val*ractx->oldval) >> 12;
335 335
336 gbuf1[0] = dec2(gbuf2[0], glob->swapbuf1alt, glob->swapbuf2alt, glob->oldval, glob->swapbuf2, 3); 336 gbuf1[0] = dec2(gbuf2[0], ractx->swapbuf1alt, ractx->swapbuf2alt, ractx->oldval, ractx->swapbuf2, 3);
337 if (glob->oldval < val) { 337 if (ractx->oldval < val) {
338 gbuf1[1] = dec2(gbuf2[1], glob->swapbuf1, glob->swapbuf2, a, glob->swapbuf2alt, 2); 338 gbuf1[1] = dec2(gbuf2[1], ractx->swapbuf1, ractx->swapbuf2, a, ractx->swapbuf2alt, 2);
339 } else { 339 } else {
340 gbuf1[1] = dec2(gbuf2[1], glob->swapbuf1alt, glob->swapbuf2alt, a, glob->swapbuf2, 2); 340 gbuf1[1] = dec2(gbuf2[1], ractx->swapbuf1alt, ractx->swapbuf2alt, a, ractx->swapbuf2, 2);
341 } 341 }
342 gbuf1[2] = dec2(gbuf2[2], glob->swapbuf1, glob->swapbuf2, val, glob->swapbuf2alt, 3); 342 gbuf1[2] = dec2(gbuf2[2], ractx->swapbuf1, ractx->swapbuf2, val, ractx->swapbuf2alt, 3);
343 gbuf1[3] = dec1(gbuf2[3], glob->swapbuf1, glob->swapbuf2, val); 343 gbuf1[3] = dec1(gbuf2[3], ractx->swapbuf1, ractx->swapbuf2, val);
344 344
345 /* do output */ 345 /* do output */
346 for (c=0; c<4; c++) { 346 for (c=0; c<4; c++) {
347 do_output_subblock(glob, gbuf2[c], gbuf1[c], data, &gb); 347 do_output_subblock(ractx, gbuf2[c], gbuf1[c], data, &gb);
348 348
349 for (i=0; i<BLOCKSIZE; i++) { 349 for (i=0; i<BLOCKSIZE; i++) {
350 *data = av_clip_int16(*data << 2); 350 *data = av_clip_int16(*data << 2);
351 data++; 351 data++;
352 } 352 }
353 } 353 }
354 354
355 glob->oldval = val; 355 ractx->oldval = val;
356 356
357 FFSWAP(unsigned int *, glob->swapbuf1alt, glob->swapbuf1); 357 FFSWAP(unsigned int *, ractx->swapbuf1alt, ractx->swapbuf1);
358 FFSWAP(unsigned int *, glob->swapbuf2alt, glob->swapbuf2); 358 FFSWAP(unsigned int *, ractx->swapbuf2alt, ractx->swapbuf2);
359 359
360 *data_size = 2*160; 360 *data_size = 2*160;
361 return 20; 361 return 20;
362 } 362 }
363 363