aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorAlex Converse <alex.converse@gmail.com>2009-09-21 04:15:12 +0000
committerAlex Converse <alex.converse@gmail.com>2009-09-21 04:15:12 +0000
commit9072c29e40284d2ddf9d1f2cc0921e20a91f89c6 (patch)
tree435a1d73da58316fa01c551e28106746ca6433d4 /libavcodec
parent9d4f6f10aedff4722e726811dd31209fc8873f15 (diff)
downloadffmpeg-9072c29e40284d2ddf9d1f2cc0921e20a91f89c6.tar.gz
aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
Originally committed as revision 19947 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/aaccoder.c95
1 files changed, 49 insertions, 46 deletions
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index b4c1e8e656..a6e69f0ac6 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -468,26 +468,28 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
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 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
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 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
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])