Mercurial > libavcodec.hg
comparison aaccoder.c @ 12257:ad42f9293ec6 libavcodec
aacenc: Factorize some scalefactor utilities.
| author | alexc |
|---|---|
| date | Fri, 23 Jul 2010 22:37:42 +0000 |
| parents | 0a63bed2a00e |
| children | 86d6c00756cc |
comparison
equal
deleted
inserted
replaced
| 12256:6e6c92d36c4b | 12257:ad42f9293ec6 |
|---|---|
| 513 } | 513 } |
| 514 put_bits(&s->pb, run_bits, count); | 514 put_bits(&s->pb, run_bits, count); |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 | 517 |
| 518 /** Return the minimum scalefactor where the quantized coef does not clip. */ | |
| 519 static av_always_inline uint8_t coef2minsf(float coef) { | |
| 520 return av_clip_uint8(log2(coef)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512); | |
| 521 } | |
| 522 | |
| 523 /** Return the maximum scalefactor where the quantized coef is not zero. */ | |
| 524 static av_always_inline uint8_t coef2maxsf(float coef) { | |
| 525 return av_clip_uint8(log2(coef)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); | |
| 526 } | |
| 527 | |
| 518 typedef struct TrellisPath { | 528 typedef struct TrellisPath { |
| 519 float cost; | 529 float cost; |
| 520 int prev; | 530 int prev; |
| 521 } TrellisPath; | 531 } TrellisPath; |
| 522 | 532 |
| 552 memset(sce->zeroes, 1, sizeof(sce->zeroes)); | 562 memset(sce->zeroes, 1, sizeof(sce->zeroes)); |
| 553 return; | 563 return; |
| 554 } | 564 } |
| 555 | 565 |
| 556 //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped | 566 //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped |
| 557 q0 = av_clip_uint8(log2(q0f)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512); | 567 q0 = coef2minsf(q0f); |
| 558 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero | 568 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero |
| 559 q1 = av_clip_uint8(log2(q1f)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); | 569 q1 = coef2maxsf(q1f); |
| 560 //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); | 570 //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); |
| 561 if (q1 - q0 > 60) { | 571 if (q1 - q0 > 60) { |
| 562 int q0low = q0; | 572 int q0low = q0; |
| 563 int q1high = q1; | 573 int q1high = q1; |
| 564 //minimum scalefactor index is when maximum nonzero coefficient after quantizing is not clipped | 574 //minimum scalefactor index is when maximum nonzero coefficient after quantizing is not clipped |
| 616 if (nz) { | 626 if (nz) { |
| 617 int minscale, maxscale; | 627 int minscale, maxscale; |
| 618 float minrd = INFINITY; | 628 float minrd = INFINITY; |
| 619 float maxval; | 629 float maxval; |
| 620 //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped | 630 //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped |
| 621 minscale = av_clip_uint8(log2(qmin)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512); | 631 minscale = coef2minsf(qmin); |
| 622 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero | 632 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero |
| 623 maxscale = av_clip_uint8(log2(qmax)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); | 633 maxscale = coef2maxsf(qmax); |
| 624 minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1); | 634 minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1); |
| 625 maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES); | 635 maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES); |
| 626 maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start); | 636 maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start); |
| 627 for (q = minscale; q < maxscale; q++) { | 637 for (q = minscale; q < maxscale; q++) { |
| 628 float dist = 0; | 638 float dist = 0; |
