comparison aaccoder.c @ 10213:cebf6e3381e0 libavcodec

aacenc: Use preprocessor constants for trellis states and stages.
author alexc
date Mon, 21 Sep 2009 04:32:51 +0000
parents 4e2db0d76fad
children bc0012099ba3
comparison
equal deleted inserted replaced
10212:4e2db0d76fad 10213:cebf6e3381e0
461 int prev; 461 int prev;
462 int min_val; 462 int min_val;
463 int max_val; 463 int max_val;
464 } TrellisPath; 464 } TrellisPath;
465 465
466 #define TRELLIS_STAGES 121
467 #define TRELLIS_STATES 256
468
466 static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, 469 static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
467 SingleChannelElement *sce, 470 SingleChannelElement *sce,
468 const float lambda) 471 const float lambda)
469 { 472 {
470 int q, w, w2, g, start = 0; 473 int q, w, w2, g, start = 0;
471 int i, j; 474 int i, j;
472 int idx; 475 int idx;
473 TrellisPath paths[121][256]; 476 TrellisPath paths[TRELLIS_STAGES][TRELLIS_STATES];
474 int bandaddr[121]; 477 int bandaddr[TRELLIS_STAGES];
475 int minq; 478 int minq;
476 float mincost; 479 float mincost;
477 480
478 for (i = 0; i < 256; i++) { 481 for (i = 0; i < TRELLIS_STATES; i++) {
479 paths[0][i].cost = 0.0f; 482 paths[0][i].cost = 0.0f;
480 paths[0][i].prev = -1; 483 paths[0][i].prev = -1;
481 paths[0][i].min_val = i; 484 paths[0][i].min_val = i;
482 paths[0][i].max_val = i; 485 paths[0][i].max_val = i;
483 } 486 }
484 for (j = 1; j < 121; j++) { 487 for (j = 1; j < TRELLIS_STAGES; j++) {
485 for (i = 0; i < 256; i++) { 488 for (i = 0; i < TRELLIS_STATES; i++) {
486 paths[j][i].cost = INFINITY; 489 paths[j][i].cost = INFINITY;
487 paths[j][i].prev = -2; 490 paths[j][i].prev = -2;
488 paths[j][i].min_val = INT_MAX; 491 paths[j][i].min_val = INT_MAX;
489 paths[j][i].max_val = 0; 492 paths[j][i].max_val = 0;
490 } 493 }
536 dist = dists[0]; 539 dist = dists[0];
537 for (i = 1; i <= ESC_BT; i++) 540 for (i = 1; i <= ESC_BT; i++)
538 dist = FFMIN(dist, dists[i]); 541 dist = FFMIN(dist, dists[i]);
539 minrd = FFMIN(minrd, dist); 542 minrd = FFMIN(minrd, dist);
540 543
541 for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, 256); i++) { 544 for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, TRELLIS_STATES); i++) {
542 float cost; 545 float cost;
543 int minv, maxv; 546 int minv, maxv;
544 if (isinf(paths[idx - 1][i].cost)) 547 if (isinf(paths[idx - 1][i].cost))
545 continue; 548 continue;
546 cost = paths[idx - 1][i].cost + dist 549 cost = paths[idx - 1][i].cost + dist
554 paths[idx][q].max_val = maxv; 557 paths[idx][q].max_val = maxv;
555 } 558 }
556 } 559 }
557 } 560 }
558 } else { 561 } else {
559 for (q = 0; q < 256; q++) { 562 for (q = 0; q < TRELLIS_STATES; q++) {
560 if (!isinf(paths[idx - 1][q].cost)) { 563 if (!isinf(paths[idx - 1][q].cost)) {
561 paths[idx][q].cost = paths[idx - 1][q].cost + 1; 564 paths[idx][q].cost = paths[idx - 1][q].cost + 1;
562 paths[idx][q].prev = q; 565 paths[idx][q].prev = q;
563 paths[idx][q].min_val = FFMIN(paths[idx - 1][q].min_val, q); 566 paths[idx][q].min_val = FFMIN(paths[idx - 1][q].min_val, q);
564 paths[idx][q].max_val = FFMAX(paths[idx - 1][q].max_val, q); 567 paths[idx][q].max_val = FFMAX(paths[idx - 1][q].max_val, q);
565 continue; 568 continue;
566 } 569 }
567 for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, 256); i++) { 570 for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, TRELLIS_STATES); i++) {
568 float cost; 571 float cost;
569 int minv, maxv; 572 int minv, maxv;
570 if (isinf(paths[idx - 1][i].cost)) 573 if (isinf(paths[idx - 1][i].cost))
571 continue; 574 continue;
572 cost = paths[idx - 1][i].cost + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO]; 575 cost = paths[idx - 1][i].cost + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO];
587 } 590 }
588 } 591 }
589 idx--; 592 idx--;
590 mincost = paths[idx][0].cost; 593 mincost = paths[idx][0].cost;
591 minq = 0; 594 minq = 0;
592 for (i = 1; i < 256; i++) { 595 for (i = 1; i < TRELLIS_STATES; i++) {
593 if (paths[idx][i].cost < mincost) { 596 if (paths[idx][i].cost < mincost) {
594 mincost = paths[idx][i].cost; 597 mincost = paths[idx][i].cost;
595 minq = i; 598 minq = i;
596 } 599 }
597 } 600 }