Mercurial > libavcodec.hg
changeset 10212:4e2db0d76fad libavcodec
aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
author | alexc |
---|---|
date | Mon, 21 Sep 2009 04:15:12 +0000 |
parents | 337e5592f985 |
children | cebf6e3381e0 |
files | aaccoder.c |
diffstat | 1 files changed, 49 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/aaccoder.c Mon Sep 21 03:53:39 2009 +0000 +++ b/aaccoder.c Mon Sep 21 04:15:12 2009 +0000 @@ -468,26 +468,28 @@ const float lambda) { int q, w, w2, g, start = 0; - int i; + int i, j; int idx; - TrellisPath paths[256*121]; + TrellisPath paths[121][256]; int bandaddr[121]; int minq; float mincost; for (i = 0; i < 256; i++) { - paths[i].cost = 0.0f; - paths[i].prev = -1; - paths[i].min_val = i; - paths[i].max_val = i; + paths[0][i].cost = 0.0f; + paths[0][i].prev = -1; + paths[0][i].min_val = i; + paths[0][i].max_val = i; } - for (i = 256; i < 256*121; i++) { - paths[i].cost = INFINITY; - paths[i].prev = -2; - paths[i].min_val = INT_MAX; - paths[i].max_val = 0; + for (j = 1; j < 121; j++) { + for (i = 0; i < 256; i++) { + paths[j][i].cost = INFINITY; + paths[j][i].prev = -2; + paths[j][i].min_val = INT_MAX; + paths[j][i].max_val = 0; + } } - idx = 256; + idx = 1; abs_pow34_v(s->scoefs, sce->coeffs, 1024); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = w*128; @@ -496,7 +498,7 @@ float qmin, qmax; int nz = 0; - bandaddr[idx >> 8] = w * 16 + g; + bandaddr[idx] = w * 16 + g; qmin = INT_MAX; qmax = 0.0f; for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { @@ -539,63 +541,64 @@ for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, 256); i++) { float cost; int minv, maxv; - if (isinf(paths[idx - 256 + i].cost)) + if (isinf(paths[idx - 1][i].cost)) continue; - cost = paths[idx - 256 + i].cost + dist + cost = paths[idx - 1][i].cost + dist + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO]; - minv = FFMIN(paths[idx - 256 + i].min_val, q); - maxv = FFMAX(paths[idx - 256 + i].max_val, q); - if (cost < paths[idx + q].cost && maxv-minv < SCALE_MAX_DIFF) { - paths[idx + q].cost = cost; - paths[idx + q].prev = idx - 256 + i; - paths[idx + q].min_val = minv; - paths[idx + q].max_val = maxv; + minv = FFMIN(paths[idx - 1][i].min_val, q); + maxv = FFMAX(paths[idx - 1][i].max_val, q); + if (cost < paths[idx][q].cost && maxv-minv < SCALE_MAX_DIFF) { + paths[idx][q].cost = cost; + paths[idx][q].prev = i; + paths[idx][q].min_val = minv; + paths[idx][q].max_val = maxv; } } } } else { for (q = 0; q < 256; q++) { - if (!isinf(paths[idx - 256 + q].cost)) { - paths[idx + q].cost = paths[idx - 256 + q].cost + 1; - paths[idx + q].prev = idx - 256 + q; - paths[idx + q].min_val = FFMIN(paths[idx - 256 + q].min_val, q); - paths[idx + q].max_val = FFMAX(paths[idx - 256 + q].max_val, q); + if (!isinf(paths[idx - 1][q].cost)) { + paths[idx][q].cost = paths[idx - 1][q].cost + 1; + paths[idx][q].prev = q; + paths[idx][q].min_val = FFMIN(paths[idx - 1][q].min_val, q); + paths[idx][q].max_val = FFMAX(paths[idx - 1][q].max_val, q); continue; } for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, 256); i++) { float cost; int minv, maxv; - if (isinf(paths[idx - 256 + i].cost)) + if (isinf(paths[idx - 1][i].cost)) continue; - cost = paths[idx - 256 + i].cost + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO]; - minv = FFMIN(paths[idx - 256 + i].min_val, q); - maxv = FFMAX(paths[idx - 256 + i].max_val, q); - if (cost < paths[idx + q].cost && maxv-minv < SCALE_MAX_DIFF) { - paths[idx + q].cost = cost; - paths[idx + q].prev = idx - 256 + i; - paths[idx + q].min_val = minv; - paths[idx + q].max_val = maxv; + cost = paths[idx - 1][i].cost + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO]; + minv = FFMIN(paths[idx - 1][i].min_val, q); + maxv = FFMAX(paths[idx - 1][i].max_val, q); + if (cost < paths[idx][q].cost && maxv-minv < SCALE_MAX_DIFF) { + paths[idx][q].cost = cost; + paths[idx][q].prev = i; + paths[idx][q].min_val = minv; + paths[idx][q].max_val = maxv; } } } } sce->zeroes[w*16+g] = !nz; start += sce->ics.swb_sizes[g]; - idx += 256; + idx++; } } - idx -= 256; - mincost = paths[idx].cost; - minq = idx; + idx--; + mincost = paths[idx][0].cost; + minq = 0; for (i = 1; i < 256; i++) { - if (paths[idx + i].cost < mincost) { - mincost = paths[idx + i].cost; - minq = idx + i; + if (paths[idx][i].cost < mincost) { + mincost = paths[idx][i].cost; + minq = i; } } - while (minq >= 256) { - sce->sf_idx[bandaddr[minq>>8]] = minq & 0xFF; - minq = paths[minq].prev; + while (idx) { + sce->sf_idx[bandaddr[idx]] = minq; + minq = paths[idx][minq].prev; + idx--; } //set the same quantizers inside window groups for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])