comparison ra144.c @ 6806:e4be053e7d9b libavcodec

Remove unneeded fields from the decoder context
author vitor
date Thu, 15 May 2008 18:34:31 +0000
parents 8faad14a40a5
children c19ef48adf18
comparison
equal deleted inserted replaced
6805:8faad14a40a5 6806:e4be053e7d9b
29 #define BUFFERSIZE 146 /* for do_output */ 29 #define BUFFERSIZE 146 /* for do_output */
30 30
31 31
32 /* internal globals */ 32 /* internal globals */
33 typedef struct { 33 typedef struct {
34 unsigned int resetflag, val, oldval; 34 unsigned int oldval;
35 unsigned int gval;
36 unsigned short *gsp;
37 unsigned int gbuf1[8]; 35 unsigned int gbuf1[8];
38 unsigned short gbuf2[120]; 36 unsigned short gbuf2[120];
39 signed short output_buffer[40];
40 unsigned int *decptr; /* decoder ptr */ 37 unsigned int *decptr; /* decoder ptr */
41 signed short *decsp; 38 signed short *decsp;
42 39
43 /* the swapped buffers */ 40 /* the swapped buffers */
44 unsigned int swapb1a[10]; 41 unsigned int swapbuffers[4][10];
45 unsigned int swapb2a[10];
46 unsigned int swapb1b[10];
47 unsigned int swapb2b[10];
48 unsigned int *swapbuf1; 42 unsigned int *swapbuf1;
49 unsigned int *swapbuf2; 43 unsigned int *swapbuf2;
50 unsigned int *swapbuf1alt; 44 unsigned int *swapbuf1alt;
51 unsigned int *swapbuf2alt; 45 unsigned int *swapbuf2alt;
52 46
53 unsigned int buffer[5]; 47 unsigned int buffer[5];
54 unsigned short int buffer_2[148]; 48 unsigned short int buffer_2[148];
49
50 unsigned short *sptr;
51
52 signed short wavtable1[2304];
53 unsigned short wavtable2[2304];
54 } Real144_internal;
55
56 static int ra144_decode_init(AVCodecContext * avctx)
57 {
58 Real144_internal *glob = avctx->priv_data;
59
60 glob->swapbuf1 = glob->swapbuffers[0];
61 glob->swapbuf2 = glob->swapbuffers[1];
62 glob->swapbuf1alt = glob->swapbuffers[2];
63 glob->swapbuf2alt = glob->swapbuffers[3];
64
65 memcpy(glob->wavtable1, wavtable1, sizeof(wavtable1));
66 memcpy(glob->wavtable2, wavtable2, sizeof(wavtable2));
67
68 return 0;
69 }
70
71 static void final(Real144_internal *glob, short *i1, short *i2, void *out, int *statbuf, int len);
72 static void add_wav(Real144_internal *glob, int n, int f, int m1, int m2, int m3, short *s1, short *s2, short *s3, short *dest);
73 static int irms(short *data, int factor);
74 static void rotate_block(short *source, short *target, int offset);
75
76 /* lookup square roots in table */
77 static int t_sqrt(unsigned int x)
78 {
79 int s = 0;
80 while (x > 0xfff) {
81 s++;
82 x = x >> 2;
83 }
84
85 return (sqrt_table[x] << s) << 2;
86 }
87
88 /* do 'voice' */
89 static void do_voice(int *a1, int *a2)
90 {
91 int buffer[10];
92 int *b1 = buffer;
93 int *b2 = a2;
94 int x, y;
95
96 for (x=0; x < 10; x++) {
97 b1[x] = a1[x] << 4;
98
99 for (y=0; y < x; y++)
100 b1[y] = ((a1[x] * b2[x-y-1]) >> 12) + b2[y];
101
102 FFSWAP(int *, b1, b2);
103 }
104
105 for (x=0; x < 10; x++)
106 a2[x] >>= 4;
107 }
108
109
110 /* do quarter-block output */
111 static void do_output_subblock(Real144_internal *glob, unsigned short *gsp, unsigned int gval, signed short *output_buffer, GetBitContext *gb)
112 {
55 unsigned short int buffer_a[40]; 113 unsigned short int buffer_a[40];
56 unsigned short int buffer_b[40]; 114 unsigned short int buffer_b[40];
57 unsigned short int buffer_c[40]; 115 unsigned short int buffer_c[40];
58 unsigned short int buffer_d[40]; 116 unsigned short int buffer_d[40];
59
60 unsigned short int work[50];
61 unsigned short *sptr;
62
63 int buffer1[10];
64 int buffer2[10];
65
66 signed short wavtable1[2304];
67 unsigned short wavtable2[2304];
68 } Real144_internal;
69
70 static int ra144_decode_init(AVCodecContext * avctx)
71 {
72 Real144_internal *glob = avctx->priv_data;
73
74 glob->resetflag = 1;
75 glob->swapbuf1 = glob->swapb1a;
76 glob->swapbuf2 = glob->swapb2a;
77 glob->swapbuf1alt = glob->swapb1b;
78 glob->swapbuf2alt = glob->swapb2b;
79
80 memcpy(glob->wavtable1, wavtable1, sizeof(wavtable1));
81 memcpy(glob->wavtable2, wavtable2, sizeof(wavtable2));
82
83 return 0;
84 }
85
86 static void final(Real144_internal *glob, short *i1, short *i2, void *out, int *statbuf, int len);
87 static void add_wav(Real144_internal *glob, int n, int f, int m1, int m2, int m3, short *s1, short *s2, short *s3, short *dest);
88 static int irms(short *data, int factor);
89 static void rotate_block(short *source, short *target, int offset);
90
91 /* lookup square roots in table */
92 static int t_sqrt(unsigned int x)
93 {
94 int s = 0;
95 while (x > 0xfff) {
96 s++;
97 x = x >> 2;
98 }
99
100 return (sqrt_table[x] << s) << 2;
101 }
102
103 /* do 'voice' */
104 static void do_voice(int *a1, int *a2)
105 {
106 int buffer[10];
107 int *b1 = buffer;
108 int *b2 = a2;
109 int x, y;
110
111 for (x=0; x < 10; x++) {
112 b1[x] = a1[x] << 4;
113
114 for (y=0; y < x; y++)
115 b1[y] = ((a1[x] * b2[x-y-1]) >> 12) + b2[y];
116
117 FFSWAP(int *, b1, b2);
118 }
119
120 for (x=0; x < 10; x++)
121 a2[x] >>= 4;
122 }
123
124
125 /* do quarter-block output */
126 static void do_output_subblock(Real144_internal *glob, unsigned int x, GetBitContext *gb)
127 {
128 int e, f, g; 117 int e, f, g;
129 int a = get_bits(gb, 7); 118 int a = get_bits(gb, 7);
130 int d = get_bits(gb, 8); 119 int d = get_bits(gb, 8);
131 int b = get_bits(gb, 7); 120 int b = get_bits(gb, 7);
132 int c = get_bits(gb, 7); 121 int c = get_bits(gb, 7);
133 122
134 if (x == 1)
135 memset(glob->buffer, 0, 20);
136
137 if (a) { 123 if (a) {
138 a += HALFBLOCK - 1; 124 a += HALFBLOCK - 1;
139 rotate_block(glob->buffer_2, glob->buffer_a, a); 125 rotate_block(glob->buffer_2, buffer_a, a);
140 } 126 }
141 127
142 memcpy(glob->buffer_b, etable1 + b * BLOCKSIZE, BLOCKSIZE * 2); 128 memcpy(buffer_b, etable1 + b * BLOCKSIZE, BLOCKSIZE * 2);
143 e = ((ftable1[b] >> 4) *glob->gval) >> 8; 129 e = ((ftable1[b] >> 4) * gval) >> 8;
144 memcpy(glob->buffer_c, etable2 + c * BLOCKSIZE, BLOCKSIZE * 2); 130 memcpy(buffer_c, etable2 + c * BLOCKSIZE, BLOCKSIZE * 2);
145 f=((ftable2[c] >> 4) *glob->gval) >> 8; 131 f=((ftable2[c] >> 4) * gval) >> 8;
146 132
147 if (a) 133 if (a)
148 g = irms(glob->buffer_a, glob->gval) >> 12; 134 g = irms(buffer_a, gval) >> 12;
149 else 135 else
150 g = 0; 136 g = 0;
151 137
152 add_wav(glob, d, a, g, e, f, glob->buffer_a, glob->buffer_b, 138 add_wav(glob, d, a, g, e, f, buffer_a, buffer_b,
153 glob->buffer_c, glob->buffer_d); 139 buffer_c, buffer_d);
154 140
155 memmove(glob->buffer_2, glob->buffer_2 + BLOCKSIZE, (BUFFERSIZE - BLOCKSIZE) * 2); 141 memmove(glob->buffer_2, glob->buffer_2 + BLOCKSIZE, (BUFFERSIZE - BLOCKSIZE) * 2);
156 memcpy(glob->buffer_2 + BUFFERSIZE - BLOCKSIZE, glob->buffer_d, BLOCKSIZE * 2); 142 memcpy(glob->buffer_2 + BUFFERSIZE - BLOCKSIZE, buffer_d, BLOCKSIZE * 2);
157 143
158 final(glob,glob->gsp, glob->buffer_d, glob->output_buffer, glob->buffer, 144 final(glob, gsp, buffer_d, output_buffer, glob->buffer, BLOCKSIZE);
159 BLOCKSIZE);
160 } 145 }
161 146
162 /* rotate block */ 147 /* rotate block */
163 static void rotate_block(short *source, short *target, int offset) 148 static void rotate_block(short *source, short *target, int offset)
164 { 149 {
231 { 216 {
232 int x, sum, i; 217 int x, sum, i;
233 int buffer[10]; 218 int buffer[10];
234 short *ptr; 219 short *ptr;
235 short *ptr2; 220 short *ptr2;
236 221 unsigned short int work[50];
237 memcpy(glob->work, statbuf,20); 222
238 memcpy(glob->work + 10, i2, len * 2); 223 memcpy(work, statbuf,20);
224 memcpy(work + 10, i2, len * 2);
239 225
240 for(i=0; i<10; i++) 226 for(i=0; i<10; i++)
241 buffer[9-i] = i1[i]; 227 buffer[9-i] = i1[i];
242 228
243 ptr2 = (ptr = glob->work) + len; 229 ptr2 = (ptr = work) + len;
244 230
245 while (ptr < ptr2) { 231 while (ptr < ptr2) {
246 for(sum=0, x=0; x<=9; x++) 232 for(sum=0, x=0; x<=9; x++)
247 sum += buffer[x] * (ptr[x]); 233 sum += buffer[x] * (ptr[x]);
248 234
318 int c; 304 int c;
319 unsigned int u; 305 unsigned int u;
320 short *sptr; 306 short *sptr;
321 int *ptr1, *ptr2, *ptr3; 307 int *ptr1, *ptr2, *ptr3;
322 int *bp1, *bp2; 308 int *bp1, *bp2;
309 int buffer1[10];
310 int buffer2[10];
323 311
324 retval = 0; 312 retval = 0;
325 bp1 = glob->buffer1; 313 bp1 = buffer1;
326 bp2 = glob->buffer2; 314 bp2 = buffer2;
327 ptr2 = (ptr3 = glob->buffer2) + 9; 315 ptr2 = (ptr3 = buffer2) + 9;
328 sptr = in; 316 sptr = in;
329 317
330 while (ptr2 >= ptr3) 318 while (ptr2 >= ptr3)
331 *(ptr3++) = *(sptr++); 319 *(ptr3++) = *(sptr++);
332 320
414 unsigned int a, b, c; 402 unsigned int a, b, c;
415 int i; 403 int i;
416 signed short *shptr; 404 signed short *shptr;
417 int16_t *datao; 405 int16_t *datao;
418 int16_t *data = vdata; 406 int16_t *data = vdata;
407 unsigned int val;
408
419 Real144_internal *glob = avctx->priv_data; 409 Real144_internal *glob = avctx->priv_data;
420 GetBitContext gb; 410 GetBitContext gb;
421 411
422 if(buf_size == 0) 412 if(buf_size == 0)
423 return 0; 413 return 0;
430 // "<< 1"? Doesn't this make one value out of two of the table useless? 420 // "<< 1"? Doesn't this make one value out of two of the table useless?
431 glob->swapbuf1[i] = decodetable[i][get_bits(&gb, sizes[i]) << 1]; 421 glob->swapbuf1[i] = decodetable[i][get_bits(&gb, sizes[i]) << 1];
432 422
433 do_voice(glob->swapbuf1, glob->swapbuf2); 423 do_voice(glob->swapbuf1, glob->swapbuf2);
434 424
435 glob->val = decodeval[get_bits(&gb, 5) << 1]; // Useless table entries? 425 val = decodeval[get_bits(&gb, 5) << 1]; // Useless table entries?
436 a = t_sqrt(glob->val*glob->oldval) >> 12; 426 a = t_sqrt(val*glob->oldval) >> 12;
437 427
438 for (c=0; c < NBLOCKS; c++) { 428 for (c=0; c < NBLOCKS; c++) {
439 if (c == (NBLOCKS - 1)) { 429 if (c == (NBLOCKS - 1)) {
440 dec1(glob, glob->swapbuf1, glob->swapbuf2, 3, glob->val); 430 dec1(glob, glob->swapbuf1, glob->swapbuf2, 3, val);
441 } else { 431 } else {
442 if (c * 2 == (NBLOCKS - 2)) { 432 if (c * 2 == (NBLOCKS - 2)) {
443 if (glob->oldval < glob->val) { 433 if (glob->oldval < val) {
444 dec2(glob, glob->swapbuf1, glob->swapbuf2, 3, a, glob->swapbuf2alt, c); 434 dec2(glob, glob->swapbuf1, glob->swapbuf2, 3, a, glob->swapbuf2alt, c);
445 } else { 435 } else {
446 dec2(glob, glob->swapbuf1alt, glob->swapbuf2alt, 3, a, glob->swapbuf2, c); 436 dec2(glob, glob->swapbuf1alt, glob->swapbuf2alt, 3, a, glob->swapbuf2, c);
447 } 437 }
448 } else { 438 } else {
449 if (c * 2 < (NBLOCKS - 2)) { 439 if (c * 2 < (NBLOCKS - 2)) {
450 dec2(glob, glob->swapbuf1alt, glob->swapbuf2alt, 3, glob->oldval, glob->swapbuf2, c); 440 dec2(glob, glob->swapbuf1alt, glob->swapbuf2alt, 3, glob->oldval, glob->swapbuf2, c);
451 } else { 441 } else {
452 dec2(glob, glob->swapbuf1, glob->swapbuf2, 3, glob->val, glob->swapbuf2alt, c); 442 dec2(glob, glob->swapbuf1, glob->swapbuf2, 3, val, glob->swapbuf2alt, c);
453 } 443 }
454 } 444 }
455 } 445 }
456 } 446 }
457 447
458 /* do output */ 448 /* do output */
459 for (b=0, c=0; c<4; c++) { 449 for (b=0, c=0; c<4; c++) {
460 glob->gval = glob->gbuf1[c * 2]; 450 unsigned int gval = glob->gbuf1[c * 2];
461 glob->gsp = glob->gbuf2 + b; 451 unsigned short *gsp = glob->gbuf2 + b;
462 do_output_subblock(glob, glob->resetflag, &gb); 452 signed short output_buffer[40];
463 glob->resetflag = 0; 453
464 454 do_output_subblock(glob, gsp, gval, output_buffer, &gb);
465 shptr = glob->output_buffer; 455
466 while (shptr < glob->output_buffer + BLOCKSIZE) 456 shptr = output_buffer;
457 while (shptr < output_buffer + BLOCKSIZE)
467 *data++ = av_clip_int16(*(shptr++) << 2); 458 *data++ = av_clip_int16(*(shptr++) << 2);
468 b += 30; 459 b += 30;
469 } 460 }
470 461
471 glob->oldval = glob->val; 462 glob->oldval = val;
472 463
473 FFSWAP(unsigned int *, glob->swapbuf1alt, glob->swapbuf1); 464 FFSWAP(unsigned int *, glob->swapbuf1alt, glob->swapbuf1);
474 FFSWAP(unsigned int *, glob->swapbuf2alt, glob->swapbuf2); 465 FFSWAP(unsigned int *, glob->swapbuf2alt, glob->swapbuf2);
475 466
476 *data_size = (data-datao)*sizeof(*data); 467 *data_size = (data-datao)*sizeof(*data);