comparison mpegaudiodec.c @ 11986:11a8d4c1ee81 libavcodec

Use lookup table to avoid division in mp2 decoder
author vitor
date Mon, 28 Jun 2010 04:55:36 +0000
parents ef338bd70180
children 3f3d08bb5cf8
comparison
equal deleted inserted replaced
11985:1cffcc7b1470 11986:11a8d4c1ee81
95 static INTFLOAT is_table_lsf[2][2][16]; 95 static INTFLOAT is_table_lsf[2][2][16];
96 static int32_t csa_table[8][4]; 96 static int32_t csa_table[8][4];
97 static float csa_table_float[8][4]; 97 static float csa_table_float[8][4];
98 static INTFLOAT mdct_win[8][36]; 98 static INTFLOAT mdct_win[8][36];
99 99
100 static int16_t division_tab3[1<<6 ];
101 static int16_t division_tab5[1<<8 ];
102 static int16_t division_tab9[1<<11];
103
104 static int16_t * const division_tabs[4] = {
105 division_tab3, division_tab5, NULL, division_tab9
106 };
107
100 /* lower 2 bits: modulo 3, higher bits: shift */ 108 /* lower 2 bits: modulo 3, higher bits: shift */
101 static uint16_t scale_factor_modshift[64]; 109 static uint16_t scale_factor_modshift[64];
102 /* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */ 110 /* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */
103 static int32_t scale_factor_mult[15][3]; 111 static int32_t scale_factor_mult[15][3];
104 /* mult table for layer 2 group quantization */ 112 /* mult table for layer 2 group quantization */
396 404
397 /* compute n ^ (4/3) and store it in mantissa/exp format */ 405 /* compute n ^ (4/3) and store it in mantissa/exp format */
398 406
399 int_pow_init(); 407 int_pow_init();
400 mpegaudio_tableinit(); 408 mpegaudio_tableinit();
409
410 for (i = 0; i < 4; i++)
411 if (ff_mpa_quant_bits[i] < 0)
412 for (j = 0; j < (1<<(-ff_mpa_quant_bits[i]+1)); j++) {
413 int val1, val2, val3, steps;
414 int val = j;
415 steps = ff_mpa_quant_steps[i];
416 val1 = val % steps;
417 val /= steps;
418 val2 = val % steps;
419 val3 = val / steps;
420 division_tabs[i][j] = val1 + (val2 << 4) + (val3 << 8);
421 }
422
401 423
402 for(i=0;i<7;i++) { 424 for(i=0;i<7;i++) {
403 float f; 425 float f;
404 INTFLOAT v; 426 INTFLOAT v;
405 if (i != 6) { 427 if (i != 6) {
1266 if (b) { 1288 if (b) {
1267 scale = scale_factors[ch][i][k]; 1289 scale = scale_factors[ch][i][k];
1268 qindex = alloc_table[j+b]; 1290 qindex = alloc_table[j+b];
1269 bits = ff_mpa_quant_bits[qindex]; 1291 bits = ff_mpa_quant_bits[qindex];
1270 if (bits < 0) { 1292 if (bits < 0) {
1293 int v2;
1271 /* 3 values at the same time */ 1294 /* 3 values at the same time */
1272 v = get_bits(&s->gb, -bits); 1295 v = get_bits(&s->gb, -bits);
1273 steps = ff_mpa_quant_steps[qindex]; 1296 v2 = division_tabs[qindex][v];
1297 steps = ff_mpa_quant_steps[qindex];
1298
1274 s->sb_samples[ch][k * 12 + l + 0][i] = 1299 s->sb_samples[ch][k * 12 + l + 0][i] =
1275 l2_unscale_group(steps, v % steps, scale); 1300 l2_unscale_group(steps, v2 & 15, scale);
1276 v = v / steps;
1277 s->sb_samples[ch][k * 12 + l + 1][i] = 1301 s->sb_samples[ch][k * 12 + l + 1][i] =
1278 l2_unscale_group(steps, v % steps, scale); 1302 l2_unscale_group(steps, (v2 >> 4) & 15, scale);
1279 v = v / steps;
1280 s->sb_samples[ch][k * 12 + l + 2][i] = 1303 s->sb_samples[ch][k * 12 + l + 2][i] =
1281 l2_unscale_group(steps, v, scale); 1304 l2_unscale_group(steps, v2 >> 8 , scale);
1282 } else { 1305 } else {
1283 for(m=0;m<3;m++) { 1306 for(m=0;m<3;m++) {
1284 v = get_bits(&s->gb, bits); 1307 v = get_bits(&s->gb, bits);
1285 v = l1_unscale(bits - 1, v, scale); 1308 v = l1_unscale(bits - 1, v, scale);
1286 s->sb_samples[ch][k * 12 + l + m][i] = v; 1309 s->sb_samples[ch][k * 12 + l + m][i] = v;