annotate aaccoder.c @ 11763:3fee94a43e64 libavcodec

Remove useless costly inf checks from the trellis scalefactor search.
author alexc
date Tue, 25 May 2010 18:32:59 +0000
parents 91b9bd17e79c
children e9c024d542f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1 /*
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
2 * AAC coefficients encoder
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
3 * Copyright (C) 2008-2009 Konstantin Shishkov
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
4 *
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
5 * This file is part of FFmpeg.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
6 *
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
11 *
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
15 * Lesser General Public License for more details.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
16 *
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
20 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
21
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
22 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11537
diff changeset
23 * @file
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
24 * AAC coefficients encoder
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
25 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
26
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
27 /***********************************
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
28 * TODOs:
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
29 * speedup quantizer selection
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
30 * add sane pulse detection
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
31 ***********************************/
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
32
11761
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
33 #include <float.h>
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
34 #include "avcodec.h"
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
35 #include "put_bits.h"
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
36 #include "aac.h"
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
37 #include "aacenc.h"
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
38 #include "aactab.h"
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
39
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
40 /** bits needed to code codebook run value for long windows */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
41 static const uint8_t run_value_bits_long[64] = {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
42 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
43 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
44 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
45 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 15
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
46 };
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
47
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
48 /** bits needed to code codebook run value for short windows */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
49 static const uint8_t run_value_bits_short[16] = {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
50 3, 3, 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 9
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
51 };
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
52
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
53 static const uint8_t *run_value_bits[2] = {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
54 run_value_bits_long, run_value_bits_short
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
55 };
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
56
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
57
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
58 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
59 * Quantize one coefficient.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
60 * @return absolute value of the quantized coefficient
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
61 * @see 3GPP TS26.403 5.6.2 "Scalefactor determination"
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
62 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
63 static av_always_inline int quant(float coef, const float Q)
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
64 {
9961
c0d721961a7f Replace pow(x, 0.75) with sqrtf(x * sqrtf(x)) for a 33% speedup.
alexc
parents: 9960
diff changeset
65 float a = coef * Q;
c0d721961a7f Replace pow(x, 0.75) with sqrtf(x * sqrtf(x)) for a 33% speedup.
alexc
parents: 9960
diff changeset
66 return sqrtf(a * sqrtf(a)) + 0.4054;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
67 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
68
11731
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
69 static void quantize_bands(int *out, const float *in, const float *scaled,
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
70 int size, float Q34, int is_signed, int maxval)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
71 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
72 int i;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
73 double qc;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
74 for (i = 0; i < size; i++) {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
75 qc = scaled[i] * Q34;
11731
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
76 out[i] = (int)FFMIN(qc + 0.4054, (double)maxval);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
77 if (is_signed && in[i] < 0.0f) {
11731
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
78 out[i] = -out[i];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
79 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
80 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
81 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
82
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
83 static void abs_pow34_v(float *out, const float *in, const int size)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
84 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
85 #ifndef USE_REALLY_FULL_SEARCH
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
86 int i;
9961
c0d721961a7f Replace pow(x, 0.75) with sqrtf(x * sqrtf(x)) for a 33% speedup.
alexc
parents: 9960
diff changeset
87 for (i = 0; i < size; i++) {
c0d721961a7f Replace pow(x, 0.75) with sqrtf(x * sqrtf(x)) for a 33% speedup.
alexc
parents: 9960
diff changeset
88 float a = fabsf(in[i]);
c0d721961a7f Replace pow(x, 0.75) with sqrtf(x * sqrtf(x)) for a 33% speedup.
alexc
parents: 9960
diff changeset
89 out[i] = sqrtf(a * sqrtf(a));
c0d721961a7f Replace pow(x, 0.75) with sqrtf(x * sqrtf(x)) for a 33% speedup.
alexc
parents: 9960
diff changeset
90 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
91 #endif /* USE_REALLY_FULL_SEARCH */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
92 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
93
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
94 static const uint8_t aac_cb_range [12] = {0, 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17};
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
95 static const uint8_t aac_cb_maxval[12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16};
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
96
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
97 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
98 * Calculate rate distortion cost for quantizing with given codebook
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
99 *
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
100 * @return quantization distortion
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
101 */
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
102 static float quantize_and_encode_band_cost(struct AACEncContext *s,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
103 PutBitContext *pb, const float *in,
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
104 const float *scaled, int size, int scale_idx,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
105 int cb, const float lambda, const float uplim,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
106 int *bits)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
107 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
108 const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
109 const float Q = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
110 const float CLIPPED_ESCAPE = 165140.0f*IQ;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
111 int i, j, k;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
112 float cost = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
113 const int dim = cb < FIRST_PAIR_BT ? 4 : 2;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
114 int resbits = 0;
9961
c0d721961a7f Replace pow(x, 0.75) with sqrtf(x * sqrtf(x)) for a 33% speedup.
alexc
parents: 9960
diff changeset
115 const float Q34 = sqrtf(Q * sqrtf(Q));
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
116 const int range = aac_cb_range[cb];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
117 const int maxval = aac_cb_maxval[cb];
11731
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
118 int off;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
119
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
120 if (!cb) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
121 for (i = 0; i < size; i++)
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
122 cost += in[i]*in[i];
9957
6fb2be900484 When calculating AAC quantized band cost, don't leave garbage in the bit count
alexc
parents: 9944
diff changeset
123 if (bits)
6fb2be900484 When calculating AAC quantized band cost, don't leave garbage in the bit count
alexc
parents: 9944
diff changeset
124 *bits = 0;
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
125 return cost * lambda;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
126 }
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
127 if (!scaled) {
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
128 abs_pow34_v(s->scoefs, in, size);
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
129 scaled = s->scoefs;
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
130 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
131 quantize_bands(s->qcoefs, in, scaled, size, Q34, !IS_CODEBOOK_UNSIGNED(cb), maxval);
11731
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
132 if (IS_CODEBOOK_UNSIGNED(cb)) {
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
133 off = 0;
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
134 } else {
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
135 off = maxval;
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
136 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
137 for (i = 0; i < size; i += dim) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
138 const float *vec;
11731
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
139 int *quants = s->qcoefs + i;
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
140 int curidx = 0;
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
141 int curbits;
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
142 float rd = 0.0f;
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
143 for (j = 0; j < dim; j++) {
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
144 curidx *= range;
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
145 curidx += quants[j] + off;
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
146 }
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
147 curbits = ff_aac_spectral_bits[cb-1][curidx];
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
148 vec = &ff_aac_codebook_vectors[cb-1][curidx*dim];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
149 if (IS_CODEBOOK_UNSIGNED(cb)) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
150 for (k = 0; k < dim; k++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
151 float t = fabsf(in[i+k]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
152 float di;
10208
39285535090c aacenc: Don't make unnecessary compares to the escape value in tight loops.
alexc
parents: 10109
diff changeset
153 if (vec[k] == 64.0f) { //FIXME: slow
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
154 if (t >= CLIPPED_ESCAPE) {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
155 di = t - CLIPPED_ESCAPE;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
156 curbits += 21;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
157 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
158 int c = av_clip(quant(t, Q), 0, 8191);
10211
337e5592f985 aacenc: Replace cbrt() with cbrtf() when the result is destined for float
alexc
parents: 10210
diff changeset
159 di = t - c*cbrtf(c)*IQ;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
160 curbits += av_log2(c)*2 - 4 + 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
161 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
162 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
163 di = t - vec[k]*IQ;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
164 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
165 if (vec[k] != 0.0f)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
166 curbits++;
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
167 rd += di*di;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
168 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
169 } else {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
170 for (k = 0; k < dim; k++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
171 float di = in[i+k] - vec[k]*IQ;
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
172 rd += di*di;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
173 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
174 }
11731
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
175 cost += rd * lambda + curbits;
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
176 resbits += curbits;
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
177 if (cost >= uplim)
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
178 return uplim;
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
179 if (pb) {
11731
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
180 put_bits(pb, ff_aac_spectral_bits[cb-1][curidx], ff_aac_spectral_codes[cb-1][curidx]);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
181 if (IS_CODEBOOK_UNSIGNED(cb))
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
182 for (j = 0; j < dim; j++)
11731
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
183 if (ff_aac_codebook_vectors[cb-1][curidx*dim+j] != 0.0f)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
184 put_bits(pb, 1, in[i+j] < 0.0f);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
185 if (cb == ESC_BT) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
186 for (j = 0; j < 2; j++) {
11731
73f923159384 aacenc: Use exact values when quantizing, not fuzzy values.
alexc
parents: 11730
diff changeset
187 if (ff_aac_codebook_vectors[cb-1][curidx*2+j] == 64.0f) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
188 int coef = av_clip(quant(fabsf(in[i+j]), Q), 0, 8191);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
189 int len = av_log2(coef);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
190
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
191 put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
192 put_bits(pb, len, coef & ((1 << len) - 1));
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
193 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
194 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
195 }
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
196 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
197 }
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
198
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
199 if (bits)
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
200 *bits = resbits;
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
201 return cost;
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
202 }
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
203 static float quantize_band_cost(struct AACEncContext *s, const float *in,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
204 const float *scaled, int size, int scale_idx,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
205 int cb, const float lambda, const float uplim,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
206 int *bits)
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
207 {
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
208 return quantize_and_encode_band_cost(s, NULL, in, scaled, size, scale_idx,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
209 cb, lambda, uplim, bits);
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
210 }
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
211
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
212 static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
213 const float *in, int size, int scale_idx,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
214 int cb, const float lambda)
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
215 {
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
216 quantize_and_encode_band_cost(s, pb, in, NULL, size, scale_idx, cb, lambda,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
217 INFINITY, NULL);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
218 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
219
11760
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
220 static int find_min_book(int sf, int group_len, int swb_size, const float *scaled) {
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
221 float maxval = 0.0f;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
222 float Q = ff_aac_pow2sf_tab[200 - sf + SCALE_ONE_POS - SCALE_DIV_512];
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
223 float Q34 = sqrtf(Q * sqrtf(Q));
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
224 int qmaxval, cb, w2, i;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
225 for (w2 = 0; w2 < group_len; w2++) {
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
226 for (i = 0; i < swb_size; i++) {
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
227 maxval = FFMAX(maxval, scaled[w2*128+i]);
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
228 }
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
229 }
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
230 qmaxval = maxval * Q34 + 0.4054f;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
231 if (qmaxval == 0) cb = 0;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
232 else if (qmaxval == 1) cb = 1;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
233 else if (qmaxval == 2) cb = 3;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
234 else if (qmaxval <= 4) cb = 5;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
235 else if (qmaxval <= 7) cb = 7;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
236 else if (qmaxval <= 12) cb = 9;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
237 else cb = 11;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
238 return cb;
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
239 }
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
240
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
241 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
242 * structure used in optimal codebook search
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
243 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
244 typedef struct BandCodingPath {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
245 int prev_idx; ///< pointer to the previous path point
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
246 float cost; ///< path cost
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
247 int run;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
248 } BandCodingPath;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
249
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
250 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
251 * Encode band info for single window group bands.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
252 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
253 static void encode_window_bands_info(AACEncContext *s, SingleChannelElement *sce,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
254 int win, int group_len, const float lambda)
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
255 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
256 BandCodingPath path[120][12];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
257 int w, swb, cb, start, start2, size;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
258 int i, j;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
259 const int max_sfb = sce->ics.max_sfb;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
260 const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
261 const int run_esc = (1 << run_bits) - 1;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
262 int idx, ppos, count;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
263 int stackrun[120], stackcb[120], stack_len;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
264 float next_minrd = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
265 int next_mincb = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
266
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
267 abs_pow34_v(s->scoefs, sce->coeffs, 1024);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
268 start = win*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
269 for (cb = 0; cb < 12; cb++) {
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
270 path[0][cb].cost = 0.0f;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
271 path[0][cb].prev_idx = -1;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
272 path[0][cb].run = 0;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
273 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
274 for (swb = 0; swb < max_sfb; swb++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
275 start2 = start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
276 size = sce->ics.swb_sizes[swb];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
277 if (sce->zeroes[win*16 + swb]) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
278 for (cb = 0; cb < 12; cb++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
279 path[swb+1][cb].prev_idx = cb;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
280 path[swb+1][cb].cost = path[swb][cb].cost;
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
281 path[swb+1][cb].run = path[swb][cb].run + 1;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
282 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
283 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
284 float minrd = next_minrd;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
285 int mincb = next_mincb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
286 next_minrd = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
287 next_mincb = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
288 for (cb = 0; cb < 12; cb++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
289 float cost_stay_here, cost_get_here;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
290 float rd = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
291 for (w = 0; w < group_len; w++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
292 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(win+w)*16+swb];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
293 rd += quantize_band_cost(s, sce->coeffs + start + w*128,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
294 s->scoefs + start + w*128, size,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
295 sce->sf_idx[(win+w)*16+swb], cb,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
296 lambda / band->threshold, INFINITY, NULL);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
297 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
298 cost_stay_here = path[swb][cb].cost + rd;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
299 cost_get_here = minrd + rd + run_bits + 4;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
300 if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
301 != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
302 cost_stay_here += run_bits;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
303 if (cost_get_here < cost_stay_here) {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
304 path[swb+1][cb].prev_idx = mincb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
305 path[swb+1][cb].cost = cost_get_here;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
306 path[swb+1][cb].run = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
307 } else {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
308 path[swb+1][cb].prev_idx = cb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
309 path[swb+1][cb].cost = cost_stay_here;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
310 path[swb+1][cb].run = path[swb][cb].run + 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
311 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
312 if (path[swb+1][cb].cost < next_minrd) {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
313 next_minrd = path[swb+1][cb].cost;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
314 next_mincb = cb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
315 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
316 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
317 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
318 start += sce->ics.swb_sizes[swb];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
319 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
320
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
321 //convert resulting path from backward-linked list
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
322 stack_len = 0;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
323 idx = 0;
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
324 for (cb = 1; cb < 12; cb++)
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
325 if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
326 idx = cb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
327 ppos = max_sfb;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
328 while (ppos > 0) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
329 cb = idx;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
330 stackrun[stack_len] = path[ppos][cb].run;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
331 stackcb [stack_len] = cb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
332 idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
333 ppos -= path[ppos][cb].run;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
334 stack_len++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
335 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
336 //perform actual band info encoding
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
337 start = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
338 for (i = stack_len - 1; i >= 0; i--) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
339 put_bits(&s->pb, 4, stackcb[i]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
340 count = stackrun[i];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
341 memset(sce->zeroes + win*16 + start, !stackcb[i], count);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
342 //XXX: memset when band_type is also uint8_t
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
343 for (j = 0; j < count; j++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
344 sce->band_type[win*16 + start] = stackcb[i];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
345 start++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
346 }
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
347 while (count >= run_esc) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
348 put_bits(&s->pb, run_bits, run_esc);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
349 count -= run_esc;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
350 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
351 put_bits(&s->pb, run_bits, count);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
352 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
353 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
354
11732
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
355 static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce,
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
356 int win, int group_len, const float lambda)
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
357 {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
358 BandCodingPath path[120][12];
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
359 int w, swb, cb, start, start2, size;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
360 int i, j;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
361 const int max_sfb = sce->ics.max_sfb;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
362 const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
363 const int run_esc = (1 << run_bits) - 1;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
364 int idx, ppos, count;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
365 int stackrun[120], stackcb[120], stack_len;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
366 float next_minrd = INFINITY;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
367 int next_mincb = 0;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
368
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
369 abs_pow34_v(s->scoefs, sce->coeffs, 1024);
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
370 start = win*128;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
371 for (cb = 0; cb < 12; cb++) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
372 path[0][cb].cost = run_bits+4;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
373 path[0][cb].prev_idx = -1;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
374 path[0][cb].run = 0;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
375 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
376 for (swb = 0; swb < max_sfb; swb++) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
377 start2 = start;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
378 size = sce->ics.swb_sizes[swb];
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
379 if (sce->zeroes[win*16 + swb]) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
380 for (cb = 0; cb < 12; cb++) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
381 path[swb+1][cb].prev_idx = cb;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
382 path[swb+1][cb].cost = path[swb][cb].cost;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
383 path[swb+1][cb].run = path[swb][cb].run + 1;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
384 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
385 } else {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
386 float minrd = next_minrd;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
387 int mincb = next_mincb;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
388 int startcb = sce->band_type[win*16+swb];
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
389 next_minrd = INFINITY;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
390 next_mincb = 0;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
391 for (cb = 0; cb < startcb; cb++) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
392 path[swb+1][cb].cost = 61450;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
393 path[swb+1][cb].prev_idx = -1;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
394 path[swb+1][cb].run = 0;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
395 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
396 for (cb = startcb; cb < 12; cb++) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
397 float cost_stay_here, cost_get_here;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
398 float rd = 0.0f;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
399 for (w = 0; w < group_len; w++) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
400 rd += quantize_band_cost(s, sce->coeffs + start + w*128,
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
401 s->scoefs + start + w*128, size,
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
402 sce->sf_idx[(win+w)*16+swb], cb,
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
403 0, INFINITY, NULL);
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
404 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
405 cost_stay_here = path[swb][cb].cost + rd;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
406 cost_get_here = minrd + rd + run_bits + 4;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
407 if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
408 != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
409 cost_stay_here += run_bits;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
410 if (cost_get_here < cost_stay_here) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
411 path[swb+1][cb].prev_idx = mincb;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
412 path[swb+1][cb].cost = cost_get_here;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
413 path[swb+1][cb].run = 1;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
414 } else {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
415 path[swb+1][cb].prev_idx = cb;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
416 path[swb+1][cb].cost = cost_stay_here;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
417 path[swb+1][cb].run = path[swb][cb].run + 1;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
418 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
419 if (path[swb+1][cb].cost < next_minrd) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
420 next_minrd = path[swb+1][cb].cost;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
421 next_mincb = cb;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
422 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
423 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
424 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
425 start += sce->ics.swb_sizes[swb];
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
426 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
427
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
428 //convert resulting path from backward-linked list
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
429 stack_len = 0;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
430 idx = 0;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
431 for (cb = 1; cb < 12; cb++)
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
432 if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
433 idx = cb;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
434 ppos = max_sfb;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
435 while (ppos > 0) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
436 if (idx < 0) abort();
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
437 cb = idx;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
438 stackrun[stack_len] = path[ppos][cb].run;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
439 stackcb [stack_len] = cb;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
440 idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
441 ppos -= path[ppos][cb].run;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
442 stack_len++;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
443 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
444 //perform actual band info encoding
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
445 start = 0;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
446 for (i = stack_len - 1; i >= 0; i--) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
447 put_bits(&s->pb, 4, stackcb[i]);
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
448 count = stackrun[i];
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
449 memset(sce->zeroes + win*16 + start, !stackcb[i], count);
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
450 //XXX: memset when band_type is also uint8_t
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
451 for (j = 0; j < count; j++) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
452 sce->band_type[win*16 + start] = stackcb[i];
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
453 start++;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
454 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
455 while (count >= run_esc) {
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
456 put_bits(&s->pb, run_bits, run_esc);
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
457 count -= run_esc;
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
458 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
459 put_bits(&s->pb, run_bits, count);
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
460 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
461 }
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
462
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
463 typedef struct TrellisPath {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
464 float cost;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
465 int prev;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
466 } TrellisPath;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
467
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
468 #define TRELLIS_STAGES 121
11761
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
469 #define TRELLIS_STATES (SCALE_MAX_DIFF+1)
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
470
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
471 static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
472 SingleChannelElement *sce,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
473 const float lambda)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
474 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
475 int q, w, w2, g, start = 0;
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
476 int i, j;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
477 int idx;
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
478 TrellisPath paths[TRELLIS_STAGES][TRELLIS_STATES];
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
479 int bandaddr[TRELLIS_STAGES];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
480 int minq;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
481 float mincost;
11761
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
482 float q0f = FLT_MAX, q1f = 0.0f, qnrgf = 0.0f;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
483 int q0, q1, qcnt = 0;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
484
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
485 for (i = 0; i < 1024; i++) {
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
486 float t = fabsf(sce->coeffs[i]);
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
487 if (t > 0.0f) {
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
488 q0f = FFMIN(q0f, t);
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
489 q1f = FFMAX(q1f, t);
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
490 qnrgf += t*t;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
491 qcnt++;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
492 }
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
493 }
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
494
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
495 if (!qcnt) {
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
496 memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
497 memset(sce->zeroes, 1, sizeof(sce->zeroes));
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
498 return;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
499 }
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
500
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
501 //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
502 q0 = av_clip_uint8(log2(q0f)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512);
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
503 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
504 q1 = av_clip_uint8(log2(q1f)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512);
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
505 //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1);
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
506 if (q1 - q0 > 60) {
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
507 int q0low = q0;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
508 int q1high = q1;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
509 //minimum scalefactor index is when maximum nonzero coefficient after quantizing is not clipped
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
510 int qnrg = av_clip_uint8(log2(sqrt(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512);
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
511 q1 = qnrg + 30;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
512 q0 = qnrg - 30;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
513 //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1);
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
514 if (q0 < q0low) {
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
515 q1 += q0low - q0;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
516 q0 = q0low;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
517 } else if (q1 > q1high) {
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
518 q0 -= q1 - q1high;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
519 q1 = q1high;
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
520 }
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
521 }
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
522 //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
523
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
524 for (i = 0; i < TRELLIS_STATES; i++) {
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
525 paths[0][i].cost = 0.0f;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
526 paths[0][i].prev = -1;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
527 }
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
528 for (j = 1; j < TRELLIS_STAGES; j++) {
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
529 for (i = 0; i < TRELLIS_STATES; i++) {
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
530 paths[j][i].cost = INFINITY;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
531 paths[j][i].prev = -2;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
532 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
533 }
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
534 idx = 1;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
535 abs_pow34_v(s->scoefs, sce->coeffs, 1024);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
536 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
537 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
538 for (g = 0; g < sce->ics.num_swb; g++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
539 const float *coefs = sce->coeffs + start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
540 float qmin, qmax;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
541 int nz = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
542
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
543 bandaddr[idx] = w * 16 + g;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
544 qmin = INT_MAX;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
545 qmax = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
546 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
547 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
548 if (band->energy <= band->threshold || band->threshold == 0.0f) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
549 sce->zeroes[(w+w2)*16+g] = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
550 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
551 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
552 sce->zeroes[(w+w2)*16+g] = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
553 nz = 1;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
554 for (i = 0; i < sce->ics.swb_sizes[g]; i++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
555 float t = fabsf(coefs[w2*128+i]);
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
556 if (t > 0.0f)
9944
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
557 qmin = FFMIN(qmin, t);
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
558 qmax = FFMAX(qmax, t);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
559 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
560 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
561 if (nz) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
562 int minscale, maxscale;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
563 float minrd = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
564 //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
565 minscale = av_clip_uint8(log2(qmin)*4 - 69 + SCALE_ONE_POS - SCALE_DIV_512);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
566 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
567 maxscale = av_clip_uint8(log2(qmax)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512);
11761
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
568 minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
569 maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
570 for (q = minscale; q < maxscale; q++) {
11762
91b9bd17e79c aacenc: Trellis over scalefactors using an estimated codebook rather than every codebook.
alexc
parents: 11761
diff changeset
571 float dist = 0;
91b9bd17e79c aacenc: Trellis over scalefactors using an estimated codebook rather than every codebook.
alexc
parents: 11761
diff changeset
572 int cb = find_min_book(sce->sf_idx[w*16+g], sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
573 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
574 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
11762
91b9bd17e79c aacenc: Trellis over scalefactors using an estimated codebook rather than every codebook.
alexc
parents: 11761
diff changeset
575 dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g],
11761
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
576 q + q0, cb, lambda / band->threshold, INFINITY, NULL);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
577 }
9944
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
578 minrd = FFMIN(minrd, dist);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
579
11761
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
580 for (i = 0; i < q1 - q0; i++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
581 float cost;
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
582 cost = paths[idx - 1][i].cost + dist
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
583 + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO];
11761
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
584 if (cost < paths[idx][q].cost) {
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
585 paths[idx][q].cost = cost;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
586 paths[idx][q].prev = i;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
587 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
588 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
589 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
590 } else {
11761
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
591 for (q = 0; q < q1 - q0; q++) {
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
592 paths[idx][q].cost = paths[idx - 1][q].cost + 1;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
593 paths[idx][q].prev = q;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
594 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
595 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
596 sce->zeroes[w*16+g] = !nz;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
597 start += sce->ics.swb_sizes[g];
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
598 idx++;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
599 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
600 }
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
601 idx--;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
602 mincost = paths[idx][0].cost;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
603 minq = 0;
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
604 for (i = 1; i < TRELLIS_STATES; i++) {
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
605 if (paths[idx][i].cost < mincost) {
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
606 mincost = paths[idx][i].cost;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
607 minq = i;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
608 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
609 }
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
610 while (idx) {
11761
418455c7e31f aacenc: Only trellis over a column of 61 scalefactors (reduced from 256).
alexc
parents: 11760
diff changeset
611 sce->sf_idx[bandaddr[idx]] = minq + q0;
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
612 minq = paths[idx][minq].prev;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
613 idx--;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
614 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
615 //set the same quantizers inside window groups
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
616 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
617 for (g = 0; g < sce->ics.num_swb; g++)
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
618 for (w2 = 1; w2 < sce->ics.group_len[w]; w2++)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
619 sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
620 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
621
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
622 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
623 * two-loop quantizers search taken from ISO 13818-7 Appendix C
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
624 */
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
625 static void search_for_quantizers_twoloop(AVCodecContext *avctx,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
626 AACEncContext *s,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
627 SingleChannelElement *sce,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
628 const float lambda)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
629 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
630 int start = 0, i, w, w2, g;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
631 int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
632 float dists[128], uplims[128];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
633 int fflag, minscaler;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
634 int its = 0;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
635 int allz = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
636 float minthr = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
637
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
638 //XXX: some heuristic to determine initial quantizers will reduce search time
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
639 memset(dists, 0, sizeof(dists));
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
640 //determine zero bands and upper limits
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
641 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
642 for (g = 0; g < sce->ics.num_swb; g++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
643 int nz = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
644 float uplim = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
645 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
646 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
647 uplim += band->threshold;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
648 if (band->energy <= band->threshold || band->threshold == 0.0f) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
649 sce->zeroes[(w+w2)*16+g] = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
650 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
651 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
652 nz = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
653 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
654 uplims[w*16+g] = uplim *512;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
655 sce->zeroes[w*16+g] = !nz;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
656 if (nz)
9944
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
657 minthr = FFMIN(minthr, uplim);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
658 allz = FFMAX(allz, nz);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
659 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
660 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
661 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
662 for (g = 0; g < sce->ics.num_swb; g++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
663 if (sce->zeroes[w*16+g]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
664 sce->sf_idx[w*16+g] = SCALE_ONE_POS;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
665 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
666 }
9944
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
667 sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2(uplims[w*16+g]/minthr)*4,59);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
668 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
669 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
670
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
671 if (!allz)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
672 return;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
673 abs_pow34_v(s->scoefs, sce->coeffs, 1024);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
674 //perform two-loop search
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
675 //outer loop - improve quality
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
676 do {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
677 int tbits, qstep;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
678 minscaler = sce->sf_idx[0];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
679 //inner loop - quantize spectrum to fit into given number of bits
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
680 qstep = its ? 1 : 32;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
681 do {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
682 int prev = -1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
683 tbits = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
684 fflag = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
685 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
686 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
687 for (g = 0; g < sce->ics.num_swb; g++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
688 const float *coefs = sce->coeffs + start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
689 const float *scaled = s->scoefs + start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
690 int bits = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
691 int cb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
692 float mindist = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
693 int minbits = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
694
9971
4b6f16da6652 Be sure to increment our position in the coefficient array when skipping a zero
alexc
parents: 9967
diff changeset
695 if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) {
4b6f16da6652 Be sure to increment our position in the coefficient array when skipping a zero
alexc
parents: 9967
diff changeset
696 start += sce->ics.swb_sizes[g];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
697 continue;
9971
4b6f16da6652 Be sure to increment our position in the coefficient array when skipping a zero
alexc
parents: 9967
diff changeset
698 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
699 minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]);
11730
5e8702ddbb93 aacenc: Use an estimated codebook for the TLS (two loop search).
alexc
parents: 11688
diff changeset
700 {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
701 float dist = 0.0f;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
702 int bb = 0;
11760
2167bf95c596 aacenc: Factor out find_min_book so it can be used by multiple coefficient coders.
alexc
parents: 11733
diff changeset
703 cb = find_min_book(sce->sf_idx[w*16+g], sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled);
11732
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
704 sce->band_type[w*16+g] = cb;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
705 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
706 int b;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
707 dist += quantize_band_cost(s, coefs + w2*128,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
708 scaled + w2*128,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
709 sce->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
710 sce->sf_idx[w*16+g],
9966
fd487090d901 Actually use all the codebooks we are iterating over in the two-loop scalefactor search.
alexc
parents: 9965
diff changeset
711 cb,
9939
6c5a58b34997 Turn on AAC rate control.
alexc
parents: 9938
diff changeset
712 lambda,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
713 INFINITY,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
714 &b);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
715 bb += b;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
716 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
717 mindist = dist;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
718 minbits = bb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
719 }
9939
6c5a58b34997 Turn on AAC rate control.
alexc
parents: 9938
diff changeset
720 dists[w*16+g] = (mindist - minbits) / lambda;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
721 bits = minbits;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
722 if (prev != -1) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
723 bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
724 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
725 tbits += bits;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
726 start += sce->ics.swb_sizes[g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
727 prev = sce->sf_idx[w*16+g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
728 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
729 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
730 if (tbits > destbits) {
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
731 for (i = 0; i < 128; i++)
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
732 if (sce->sf_idx[i] < 218 - qstep)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
733 sce->sf_idx[i] += qstep;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
734 } else {
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
735 for (i = 0; i < 128; i++)
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
736 if (sce->sf_idx[i] > 60 - qstep)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
737 sce->sf_idx[i] -= qstep;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
738 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
739 qstep >>= 1;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
740 if (!qstep && tbits > destbits*1.02)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
741 qstep = 1;
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
742 if (sce->sf_idx[0] >= 217)
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
743 break;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
744 } while (qstep);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
745
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
746 fflag = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
747 minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
748 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
749 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
750 for (g = 0; g < sce->ics.num_swb; g++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
751 int prevsc = sce->sf_idx[w*16+g];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
752 if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
753 sce->sf_idx[w*16+g]--;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
754 sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler, minscaler + SCALE_MAX_DIFF);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
755 sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
756 if (sce->sf_idx[w*16+g] != prevsc)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
757 fflag = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
758 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
759 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
760 its++;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
761 } while (fflag && its < 10);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
762 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
763
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
764 static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s,
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
765 SingleChannelElement *sce,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
766 const float lambda)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
767 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
768 int start = 0, i, w, w2, g;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
769 float uplim[128], maxq[128];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
770 int minq, maxsf;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
771 float distfact = ((sce->ics.num_windows > 1) ? 85.80 : 147.84) / lambda;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
772 int last = 0, lastband = 0, curband = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
773 float avg_energy = 0.0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
774 if (sce->ics.num_windows == 1) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
775 start = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
776 for (i = 0; i < 1024; i++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
777 if (i - start >= sce->ics.swb_sizes[curband]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
778 start += sce->ics.swb_sizes[curband];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
779 curband++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
780 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
781 if (sce->coeffs[i]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
782 avg_energy += sce->coeffs[i] * sce->coeffs[i];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
783 last = i;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
784 lastband = curband;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
785 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
786 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
787 } else {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
788 for (w = 0; w < 8; w++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
789 const float *coeffs = sce->coeffs + w*128;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
790 start = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
791 for (i = 0; i < 128; i++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
792 if (i - start >= sce->ics.swb_sizes[curband]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
793 start += sce->ics.swb_sizes[curband];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
794 curband++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
795 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
796 if (coeffs[i]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
797 avg_energy += coeffs[i] * coeffs[i];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
798 last = FFMAX(last, i);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
799 lastband = FFMAX(lastband, curband);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
800 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
801 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
802 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
803 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
804 last++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
805 avg_energy /= last;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
806 if (avg_energy == 0.0f) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
807 for (i = 0; i < FF_ARRAY_ELEMS(sce->sf_idx); i++)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
808 sce->sf_idx[i] = SCALE_ONE_POS;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
809 return;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
810 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
811 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
812 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
813 for (g = 0; g < sce->ics.num_swb; g++) {
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
814 float *coefs = sce->coeffs + start;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
815 const int size = sce->ics.swb_sizes[g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
816 int start2 = start, end2 = start + size, peakpos = start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
817 float maxval = -1, thr = 0.0f, t;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
818 maxq[w*16+g] = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
819 if (g > lastband) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
820 maxq[w*16+g] = 0.0f;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
821 start += size;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
822 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
823 memset(coefs + w2*128, 0, sizeof(coefs[0])*size);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
824 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
825 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
826 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
827 for (i = 0; i < size; i++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
828 float t = coefs[w2*128+i]*coefs[w2*128+i];
9944
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
829 maxq[w*16+g] = FFMAX(maxq[w*16+g], fabsf(coefs[w2*128 + i]));
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
830 thr += t;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
831 if (sce->ics.num_windows == 1 && maxval < t) {
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
832 maxval = t;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
833 peakpos = start+i;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
834 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
835 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
836 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
837 if (sce->ics.num_windows == 1) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
838 start2 = FFMAX(peakpos - 2, start2);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
839 end2 = FFMIN(peakpos + 3, end2);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
840 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
841 start2 -= start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
842 end2 -= start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
843 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
844 start += size;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
845 thr = pow(thr / (avg_energy * (end2 - start2)), 0.3 + 0.1*(lastband - g) / lastband);
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
846 t = 1.0 - (1.0 * start2 / last);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
847 uplim[w*16+g] = distfact / (1.4 * thr + t*t*t + 0.075);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
848 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
849 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
850 memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
851 abs_pow34_v(s->scoefs, sce->coeffs, 1024);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
852 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
853 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
854 for (g = 0; g < sce->ics.num_swb; g++) {
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
855 const float *coefs = sce->coeffs + start;
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
856 const float *scaled = s->scoefs + start;
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
857 const int size = sce->ics.swb_sizes[g];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
858 int scf, prev_scf, step;
11686
41a083a2527a Make the faac inspired quantizer search make sense for a slightly narrower definition of "make sense."
alexc
parents: 11644
diff changeset
859 int min_scf = -1, max_scf = 256;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
860 float curdiff;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
861 if (maxq[w*16+g] < 21.544) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
862 sce->zeroes[w*16+g] = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
863 start += size;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
864 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
865 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
866 sce->zeroes[w*16+g] = 0;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
867 scf = prev_scf = av_clip(SCALE_ONE_POS - SCALE_DIV_512 - log2(1/maxq[w*16+g])*16/3, 60, 218);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
868 step = 16;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
869 for (;;) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
870 float dist = 0.0f;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
871 int quant_max;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
872
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
873 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
874 int b;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
875 dist += quantize_band_cost(s, coefs + w2*128,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
876 scaled + w2*128,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
877 sce->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
878 scf,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
879 ESC_BT,
9939
6c5a58b34997 Turn on AAC rate control.
alexc
parents: 9938
diff changeset
880 lambda,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
881 INFINITY,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
882 &b);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
883 dist -= b;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
884 }
9939
6c5a58b34997 Turn on AAC rate control.
alexc
parents: 9938
diff changeset
885 dist *= 1.0f / 512.0f / lambda;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
886 quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[200 - scf + SCALE_ONE_POS - SCALE_DIV_512]);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
887 if (quant_max >= 8191) { // too much, return to the previous quantizer
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
888 sce->sf_idx[w*16+g] = prev_scf;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
889 break;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
890 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
891 prev_scf = scf;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
892 curdiff = fabsf(dist - uplim[w*16+g]);
11686
41a083a2527a Make the faac inspired quantizer search make sense for a slightly narrower definition of "make sense."
alexc
parents: 11644
diff changeset
893 if (curdiff <= 1.0f)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
894 step = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
895 else
11686
41a083a2527a Make the faac inspired quantizer search make sense for a slightly narrower definition of "make sense."
alexc
parents: 11644
diff changeset
896 step = log2(curdiff);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
897 if (dist > uplim[w*16+g])
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
898 step = -step;
11686
41a083a2527a Make the faac inspired quantizer search make sense for a slightly narrower definition of "make sense."
alexc
parents: 11644
diff changeset
899 scf += step;
11688
6f5bee041560 10l: store the result of clipping added in r23035
alexc
parents: 11686
diff changeset
900 scf = av_clip_uint8(scf);
11686
41a083a2527a Make the faac inspired quantizer search make sense for a slightly narrower definition of "make sense."
alexc
parents: 11644
diff changeset
901 step = scf - prev_scf;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
902 if (FFABS(step) <= 1 || (step > 0 && scf >= max_scf) || (step < 0 && scf <= min_scf)) {
11686
41a083a2527a Make the faac inspired quantizer search make sense for a slightly narrower definition of "make sense."
alexc
parents: 11644
diff changeset
903 sce->sf_idx[w*16+g] = av_clip(scf, min_scf, max_scf);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
904 break;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
905 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
906 if (step > 0)
11686
41a083a2527a Make the faac inspired quantizer search make sense for a slightly narrower definition of "make sense."
alexc
parents: 11644
diff changeset
907 min_scf = prev_scf;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
908 else
11686
41a083a2527a Make the faac inspired quantizer search make sense for a slightly narrower definition of "make sense."
alexc
parents: 11644
diff changeset
909 max_scf = prev_scf;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
910 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
911 start += size;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
912 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
913 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
914 minq = sce->sf_idx[0] ? sce->sf_idx[0] : INT_MAX;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
915 for (i = 1; i < 128; i++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
916 if (!sce->sf_idx[i])
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
917 sce->sf_idx[i] = sce->sf_idx[i-1];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
918 else
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
919 minq = FFMIN(minq, sce->sf_idx[i]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
920 }
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
921 if (minq == INT_MAX)
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
922 minq = 0;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
923 minq = FFMIN(minq, SCALE_MAX_POS);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
924 maxsf = FFMIN(minq + SCALE_MAX_DIFF, SCALE_MAX_POS);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
925 for (i = 126; i >= 0; i--) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
926 if (!sce->sf_idx[i])
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
927 sce->sf_idx[i] = sce->sf_idx[i+1];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
928 sce->sf_idx[i] = av_clip(sce->sf_idx[i], minq, maxsf);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
929 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
930 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
931
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
932 static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s,
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
933 SingleChannelElement *sce,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
934 const float lambda)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
935 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
936 int start = 0, i, w, w2, g;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
937 int minq = 255;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
938
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
939 memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
940 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
941 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
942 for (g = 0; g < sce->ics.num_swb; g++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
943 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
944 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
945 if (band->energy <= band->threshold) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
946 sce->sf_idx[(w+w2)*16+g] = 218;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
947 sce->zeroes[(w+w2)*16+g] = 1;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
948 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
949 sce->sf_idx[(w+w2)*16+g] = av_clip(SCALE_ONE_POS - SCALE_DIV_512 + log2(band->threshold), 80, 218);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
950 sce->zeroes[(w+w2)*16+g] = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
951 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
952 minq = FFMIN(minq, sce->sf_idx[(w+w2)*16+g]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
953 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
954 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
955 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
956 for (i = 0; i < 128; i++) {
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
957 sce->sf_idx[i] = 140;
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
958 //av_clip(sce->sf_idx[i], minq, minq + SCALE_MAX_DIFF - 1);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
959 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
960 //set the same quantizers inside window groups
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
961 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
962 for (g = 0; g < sce->ics.num_swb; g++)
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
963 for (w2 = 1; w2 < sce->ics.group_len[w]; w2++)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
964 sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
965 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
966
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
967 static void search_for_ms(AACEncContext *s, ChannelElement *cpe,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
968 const float lambda)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
969 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
970 int start = 0, i, w, w2, g;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
971 float M[128], S[128];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
972 float *L34 = s->scoefs, *R34 = s->scoefs + 128, *M34 = s->scoefs + 128*2, *S34 = s->scoefs + 128*3;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
973 SingleChannelElement *sce0 = &cpe->ch[0];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
974 SingleChannelElement *sce1 = &cpe->ch[1];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
975 if (!cpe->common_window)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
976 return;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
977 for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
978 for (g = 0; g < sce0->ics.num_swb; g++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
979 if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
980 float dist1 = 0.0f, dist2 = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
981 for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
982 FFPsyBand *band0 = &s->psy.psy_bands[(s->cur_channel+0)*PSY_MAX_BANDS+(w+w2)*16+g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
983 FFPsyBand *band1 = &s->psy.psy_bands[(s->cur_channel+1)*PSY_MAX_BANDS+(w+w2)*16+g];
9944
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
984 float minthr = FFMIN(band0->threshold, band1->threshold);
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
985 float maxthr = FFMAX(band0->threshold, band1->threshold);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
986 for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
987 M[i] = (sce0->coeffs[start+w2*128+i]
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
988 + sce1->coeffs[start+w2*128+i]) * 0.5;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
989 S[i] = sce0->coeffs[start+w2*128+i]
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
990 - sce1->coeffs[start+w2*128+i];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
991 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
992 abs_pow34_v(L34, sce0->coeffs+start+w2*128, sce0->ics.swb_sizes[g]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
993 abs_pow34_v(R34, sce1->coeffs+start+w2*128, sce0->ics.swb_sizes[g]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
994 abs_pow34_v(M34, M, sce0->ics.swb_sizes[g]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
995 abs_pow34_v(S34, S, sce0->ics.swb_sizes[g]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
996 dist1 += quantize_band_cost(s, sce0->coeffs + start + w2*128,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
997 L34,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
998 sce0->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
999 sce0->sf_idx[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1000 sce0->band_type[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1001 lambda / band0->threshold, INFINITY, NULL);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1002 dist1 += quantize_band_cost(s, sce1->coeffs + start + w2*128,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1003 R34,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1004 sce1->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1005 sce1->sf_idx[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1006 sce1->band_type[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1007 lambda / band1->threshold, INFINITY, NULL);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1008 dist2 += quantize_band_cost(s, M,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1009 M34,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1010 sce0->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1011 sce0->sf_idx[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1012 sce0->band_type[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1013 lambda / maxthr, INFINITY, NULL);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1014 dist2 += quantize_band_cost(s, S,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1015 S34,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1016 sce1->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1017 sce1->sf_idx[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1018 sce1->band_type[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1019 lambda / minthr, INFINITY, NULL);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1020 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1021 cpe->ms_mask[w*16+g] = dist2 < dist1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1022 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1023 start += sce0->ics.swb_sizes[g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1024 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1025 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1026 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1027
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1028 AACCoefficientsEncoder ff_aac_coders[] = {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1029 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1030 search_for_quantizers_faac,
9939
6c5a58b34997 Turn on AAC rate control.
alexc
parents: 9938
diff changeset
1031 encode_window_bands_info,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1032 quantize_and_encode_band,
10109
68f824761c1b Re-add search_for_ms to the coefficients encoders to silence warnings
alexc
parents: 9971
diff changeset
1033 search_for_ms,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1034 },
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1035 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1036 search_for_quantizers_anmr,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1037 encode_window_bands_info,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1038 quantize_and_encode_band,
10109
68f824761c1b Re-add search_for_ms to the coefficients encoders to silence warnings
alexc
parents: 9971
diff changeset
1039 search_for_ms,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1040 },
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1041 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1042 search_for_quantizers_twoloop,
11732
c40cc26cd23f aacenc: Add a rate only trellis for codebook selection for the TLS.
alexc
parents: 11731
diff changeset
1043 codebook_trellis_rate,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1044 quantize_and_encode_band,
10109
68f824761c1b Re-add search_for_ms to the coefficients encoders to silence warnings
alexc
parents: 9971
diff changeset
1045 search_for_ms,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1046 },
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1047 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1048 search_for_quantizers_fast,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1049 encode_window_bands_info,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1050 quantize_and_encode_band,
10109
68f824761c1b Re-add search_for_ms to the coefficients encoders to silence warnings
alexc
parents: 9971
diff changeset
1051 search_for_ms,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1052 },
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1053 };