Mercurial > libavcodec.hg
annotate aaccoder.c @ 9960:bd37369189de libavcodec
Dead code removal in the AAC encoder.
author | alexc |
---|---|
date | Fri, 17 Jul 2009 14:06:53 +0000 |
parents | 6fb2be900484 |
children | c0d721961a7f |
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 /** |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
23 * @file libavcodec/aaccoder.c |
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 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
33 #include "avcodec.h" |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
34 #include "put_bits.h" |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
35 #include "aac.h" |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
36 #include "aacenc.h" |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
37 #include "aactab.h" |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
38 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
39 /** 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 }; |
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 /** 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
|
48 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
|
49 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
|
50 }; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
51 |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
52 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
|
53 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
|
54 }; |
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 * Quantize one coefficient. |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
59 * @return absolute value of the quantized coefficient |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
60 * @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
|
61 */ |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
62 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
|
63 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
64 return pow(coef * Q, 0.75) + 0.4054; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
65 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
66 |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
67 static void quantize_bands(int (*out)[2], const float *in, const float *scaled, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
68 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
|
69 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
70 int i; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
71 double qc; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
72 for (i = 0; i < size; i++) { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
73 qc = scaled[i] * Q34; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
74 out[i][0] = (int)FFMIN((int)qc, maxval); |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
75 out[i][1] = (int)FFMIN((int)(qc + 0.4054), maxval); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
76 if (is_signed && in[i] < 0.0f) { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
77 out[i][0] = -out[i][0]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
78 out[i][1] = -out[i][1]; |
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; |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
87 for (i = 0; i < size; i++) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
88 out[i] = pow(fabsf(in[i]), 0.75); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
89 #endif /* USE_REALLY_FULL_SEARCH */ |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
90 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
91 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
92 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
|
93 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
|
94 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
95 /** |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
96 * 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
|
97 * |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
98 * @return quantization distortion |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
99 */ |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
100 static float quantize_band_cost(struct AACEncContext *s, const float *in, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
101 const float *scaled, int size, int scale_idx, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
102 int cb, const float lambda, const float uplim, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
103 int *bits) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
104 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
105 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
|
106 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
|
107 const float CLIPPED_ESCAPE = 165140.0f*IQ; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
108 int i, j, k; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
109 float cost = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
110 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
|
111 int resbits = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
112 #ifndef USE_REALLY_FULL_SEARCH |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
113 const float Q34 = pow(Q, 0.75); |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
114 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
|
115 const int maxval = aac_cb_maxval[cb]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
116 int offs[4]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
117 #endif /* USE_REALLY_FULL_SEARCH */ |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
118 |
9936 | 119 if (!cb) { |
120 for (i = 0; i < size; i++) | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
121 cost += in[i]*in[i]*lambda; |
9957
6fb2be900484
When calculating AAC quantized band cost, don't leave garbage in the bit count
alexc
parents:
9944
diff
changeset
|
122 if (bits) |
6fb2be900484
When calculating AAC quantized band cost, don't leave garbage in the bit count
alexc
parents:
9944
diff
changeset
|
123 *bits = 0; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
124 return cost; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
125 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
126 #ifndef USE_REALLY_FULL_SEARCH |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
127 offs[0] = 1; |
9936 | 128 for (i = 1; i < dim; i++) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
129 offs[i] = offs[i-1]*range; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
130 quantize_bands(s->qcoefs, in, scaled, size, Q34, !IS_CODEBOOK_UNSIGNED(cb), maxval); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
131 #endif /* USE_REALLY_FULL_SEARCH */ |
9936 | 132 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
|
133 float mincost; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
134 int minidx = 0; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
135 int minbits = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
136 const float *vec; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
137 #ifndef USE_REALLY_FULL_SEARCH |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
138 int (*quants)[2] = &s->qcoefs[i]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
139 mincost = 0.0f; |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
140 for (j = 0; j < dim; j++) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
141 mincost += in[i+j]*in[i+j]*lambda; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
142 minidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
143 minbits = ff_aac_spectral_bits[cb-1][minidx]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
144 mincost += minbits; |
9936 | 145 for (j = 0; j < (1<<dim); j++) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
146 float rd = 0.0f; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
147 int curbits; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
148 int curidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
149 int same = 0; |
9936 | 150 for (k = 0; k < dim; k++) { |
151 if ((j & (1 << k)) && quants[k][0] == quants[k][1]) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
152 same = 1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
153 break; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
154 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
155 } |
9936 | 156 if (same) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
157 continue; |
9936 | 158 for (k = 0; k < dim; k++) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
159 curidx += quants[k][!!(j & (1 << k))] * offs[dim - 1 - k]; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
160 curbits = ff_aac_spectral_bits[cb-1][curidx]; |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
161 vec = &ff_aac_codebook_vectors[cb-1][curidx*dim]; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
162 #else |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
163 mincost = INFINITY; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
164 vec = ff_aac_codebook_vectors[cb-1]; |
9936 | 165 for (j = 0; j < ff_aac_spectral_sizes[cb-1]; j++, vec += dim) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
166 float rd = 0.0f; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
167 int curbits = ff_aac_spectral_bits[cb-1][j]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
168 #endif /* USE_REALLY_FULL_SEARCH */ |
9936 | 169 if (IS_CODEBOOK_UNSIGNED(cb)) { |
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 t = fabsf(in[i+k]); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
172 float di; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
173 //do not code with escape sequence small values |
9936 | 174 if (vec[k] == 64.0f && t < 39.0f*IQ) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
175 rd = INFINITY; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
176 break; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
177 } |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
178 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
|
179 if (t >= CLIPPED_ESCAPE) { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
180 di = t - CLIPPED_ESCAPE; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
181 curbits += 21; |
9936 | 182 } else { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
183 int c = av_clip(quant(t, Q), 0, 8191); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
184 di = t - c*cbrt(c)*IQ; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
185 curbits += av_log2(c)*2 - 4 + 1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
186 } |
9936 | 187 } else { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
188 di = t - vec[k]*IQ; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
189 } |
9936 | 190 if (vec[k] != 0.0f) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
191 curbits++; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
192 rd += di*di*lambda; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
193 } |
9936 | 194 } else { |
195 for (k = 0; k < dim; k++) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
196 float di = in[i+k] - vec[k]*IQ; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
197 rd += di*di*lambda; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
198 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
199 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
200 rd += curbits; |
9936 | 201 if (rd < mincost) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
202 mincost = rd; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
203 minidx = j; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
204 minbits = curbits; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
205 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
206 } |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
207 cost += mincost; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
208 resbits += minbits; |
9936 | 209 if (cost >= uplim) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
210 return uplim; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
211 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
212 |
9936 | 213 if (bits) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
214 *bits = resbits; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
215 return cost; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
216 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
217 |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
218 static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
219 const float *in, int size, int scale_idx, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
220 int cb, const float lambda) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
221 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
222 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
|
223 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
|
224 const float CLIPPED_ESCAPE = 165140.0f*IQ; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
225 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
|
226 int i, j, k; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
227 #ifndef USE_REALLY_FULL_SEARCH |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
228 const float Q34 = pow(Q, 0.75); |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
229 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
|
230 const int maxval = aac_cb_maxval[cb]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
231 int offs[4]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
232 float *scaled = s->scoefs; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
233 #endif /* USE_REALLY_FULL_SEARCH */ |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
234 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
235 //START_TIMER |
9936 | 236 if (!cb) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
237 return; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
238 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
239 #ifndef USE_REALLY_FULL_SEARCH |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
240 offs[0] = 1; |
9936 | 241 for (i = 1; i < dim; i++) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
242 offs[i] = offs[i-1]*range; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
243 abs_pow34_v(scaled, in, size); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
244 quantize_bands(s->qcoefs, in, scaled, size, Q34, !IS_CODEBOOK_UNSIGNED(cb), maxval); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
245 #endif /* USE_REALLY_FULL_SEARCH */ |
9936 | 246 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
|
247 float mincost; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
248 int minidx = 0; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
249 int minbits = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
250 const float *vec; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
251 #ifndef USE_REALLY_FULL_SEARCH |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
252 int (*quants)[2] = &s->qcoefs[i]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
253 mincost = 0.0f; |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
254 for (j = 0; j < dim; j++) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
255 mincost += in[i+j]*in[i+j]*lambda; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
256 minidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
257 minbits = ff_aac_spectral_bits[cb-1][minidx]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
258 mincost += minbits; |
9936 | 259 for (j = 0; j < (1<<dim); j++) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
260 float rd = 0.0f; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
261 int curbits; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
262 int curidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
263 int same = 0; |
9936 | 264 for (k = 0; k < dim; k++) { |
265 if ((j & (1 << k)) && quants[k][0] == quants[k][1]) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
266 same = 1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
267 break; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
268 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
269 } |
9936 | 270 if (same) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
271 continue; |
9936 | 272 for (k = 0; k < dim; k++) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
273 curidx += quants[k][!!(j & (1 << k))] * offs[dim - 1 - k]; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
274 curbits = ff_aac_spectral_bits[cb-1][curidx]; |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
275 vec = &ff_aac_codebook_vectors[cb-1][curidx*dim]; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
276 #else |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
277 vec = ff_aac_codebook_vectors[cb-1]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
278 mincost = INFINITY; |
9936 | 279 for (j = 0; j < ff_aac_spectral_sizes[cb-1]; j++, vec += dim) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
280 float rd = 0.0f; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
281 int curbits = ff_aac_spectral_bits[cb-1][j]; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
282 int curidx = j; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
283 #endif /* USE_REALLY_FULL_SEARCH */ |
9936 | 284 if (IS_CODEBOOK_UNSIGNED(cb)) { |
285 for (k = 0; k < dim; k++) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
286 float t = fabsf(in[i+k]); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
287 float di; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
288 //do not code with escape sequence small values |
9936 | 289 if (vec[k] == 64.0f && t < 39.0f*IQ) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
290 rd = INFINITY; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
291 break; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
292 } |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
293 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
|
294 if (t >= CLIPPED_ESCAPE) { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
295 di = t - CLIPPED_ESCAPE; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
296 curbits += 21; |
9936 | 297 } else { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
298 int c = av_clip(quant(t, Q), 0, 8191); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
299 di = t - c*cbrt(c)*IQ; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
300 curbits += av_log2(c)*2 - 4 + 1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
301 } |
9936 | 302 } else { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
303 di = t - vec[k]*IQ; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
304 } |
9936 | 305 if (vec[k] != 0.0f) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
306 curbits++; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
307 rd += di*di*lambda; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
308 } |
9936 | 309 } else { |
310 for (k = 0; k < dim; k++) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
311 float di = in[i+k] - vec[k]*IQ; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
312 rd += di*di*lambda; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
313 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
314 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
315 rd += curbits; |
9936 | 316 if (rd < mincost) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
317 mincost = rd; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
318 minidx = curidx; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
319 minbits = curbits; |
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 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
322 put_bits(pb, ff_aac_spectral_bits[cb-1][minidx], ff_aac_spectral_codes[cb-1][minidx]); |
9936 | 323 if (IS_CODEBOOK_UNSIGNED(cb)) |
324 for (j = 0; j < dim; j++) | |
325 if (ff_aac_codebook_vectors[cb-1][minidx*dim+j] != 0.0f) | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
326 put_bits(pb, 1, in[i+j] < 0.0f); |
9936 | 327 if (cb == ESC_BT) { |
328 for (j = 0; j < 2; j++) { | |
329 if (ff_aac_codebook_vectors[cb-1][minidx*2+j] == 64.0f) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
330 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
|
331 int len = av_log2(coef); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
332 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
333 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
|
334 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
|
335 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
336 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
337 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
338 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
339 //STOP_TIMER("quantize_and_encode") |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
340 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
341 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
342 /** |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
343 * structure used in optimal codebook search |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
344 */ |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
345 typedef struct BandCodingPath { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
346 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
|
347 int codebook; ///< codebook for coding band run |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
348 float cost; ///< path cost |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
349 int run; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
350 } BandCodingPath; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
351 |
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 * 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
|
354 */ |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
355 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
|
356 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
|
357 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
358 BandCodingPath path[120][12]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
359 int w, swb, cb, start, start2, size; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
360 int i, j; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
361 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
|
362 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
|
363 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
|
364 int idx, ppos, count; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
365 int stackrun[120], stackcb[120], stack_len; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
366 float next_minrd = INFINITY; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
367 int next_mincb = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
368 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
369 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
|
370 start = win*128; |
9936 | 371 for (cb = 0; cb < 12; cb++) { |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
372 path[0][cb].cost = 0.0f; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
373 path[0][cb].prev_idx = -1; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
374 path[0][cb].run = 0; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
375 } |
9936 | 376 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
|
377 start2 = start; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
378 size = sce->ics.swb_sizes[swb]; |
9936 | 379 if (sce->zeroes[win*16 + swb]) { |
380 for (cb = 0; cb < 12; cb++) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
381 path[swb+1][cb].prev_idx = cb; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
382 path[swb+1][cb].cost = path[swb][cb].cost; |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
383 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
|
384 } |
9936 | 385 } else { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
386 float minrd = next_minrd; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
387 int mincb = next_mincb; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
388 next_minrd = INFINITY; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
389 next_mincb = 0; |
9936 | 390 for (cb = 0; cb < 12; cb++) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
391 float cost_stay_here, cost_get_here; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
392 float rd = 0.0f; |
9936 | 393 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
|
394 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
|
395 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
|
396 s->scoefs + start + w*128, size, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
397 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
|
398 lambda / band->threshold, INFINITY, NULL); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
399 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
400 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
|
401 cost_get_here = minrd + rd + run_bits + 4; |
9936 | 402 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
|
403 != 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
|
404 cost_stay_here += run_bits; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
405 if (cost_get_here < cost_stay_here) { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
406 path[swb+1][cb].prev_idx = mincb; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
407 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
|
408 path[swb+1][cb].run = 1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
409 } else { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
410 path[swb+1][cb].prev_idx = cb; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
411 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
|
412 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
|
413 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
414 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
|
415 next_minrd = path[swb+1][cb].cost; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
416 next_mincb = cb; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
417 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
418 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
419 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
420 start += sce->ics.swb_sizes[swb]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
421 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
422 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
423 //convert resulting path from backward-linked list |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
424 stack_len = 0; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
425 idx = 0; |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
426 for (cb = 1; cb < 12; cb++) |
9936 | 427 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
|
428 idx = cb; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
429 ppos = max_sfb; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
430 while (ppos > 0) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
431 cb = idx; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
432 stackrun[stack_len] = path[ppos][cb].run; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
433 stackcb [stack_len] = cb; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
434 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
|
435 ppos -= path[ppos][cb].run; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
436 stack_len++; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
437 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
438 //perform actual band info encoding |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
439 start = 0; |
9936 | 440 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
|
441 put_bits(&s->pb, 4, stackcb[i]); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
442 count = stackrun[i]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
443 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
|
444 //XXX: memset when band_type is also uint8_t |
9936 | 445 for (j = 0; j < count; j++) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
446 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
|
447 start++; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
448 } |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
449 while (count >= run_esc) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
450 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
|
451 count -= run_esc; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
452 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
453 put_bits(&s->pb, run_bits, count); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
454 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
455 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
456 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
457 typedef struct TrellisPath { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
458 float cost; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
459 int prev; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
460 int min_val; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
461 int max_val; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
462 } TrellisPath; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
463 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
464 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
|
465 SingleChannelElement *sce, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
466 const float lambda) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
467 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
468 int q, w, w2, g, start = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
469 int i; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
470 int idx; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
471 TrellisPath paths[256*121]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
472 int bandaddr[121]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
473 int minq; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
474 float mincost; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
475 |
9936 | 476 for (i = 0; i < 256; i++) { |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
477 paths[i].cost = 0.0f; |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
478 paths[i].prev = -1; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
479 paths[i].min_val = i; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
480 paths[i].max_val = i; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
481 } |
9936 | 482 for (i = 256; i < 256*121; i++) { |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
483 paths[i].cost = INFINITY; |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
484 paths[i].prev = -2; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
485 paths[i].min_val = INT_MAX; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
486 paths[i].max_val = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
487 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
488 idx = 256; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
489 abs_pow34_v(s->scoefs, sce->coeffs, 1024); |
9936 | 490 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
|
491 start = w*128; |
9936 | 492 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
|
493 const float *coefs = sce->coeffs + start; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
494 float qmin, qmax; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
495 int nz = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
496 |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
497 bandaddr[idx >> 8] = w * 16 + g; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
498 qmin = INT_MAX; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
499 qmax = 0.0f; |
9936 | 500 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
|
501 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; |
9936 | 502 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
|
503 sce->zeroes[(w+w2)*16+g] = 1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
504 continue; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
505 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
506 sce->zeroes[(w+w2)*16+g] = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
507 nz = 1; |
9936 | 508 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
|
509 float t = fabsf(coefs[w2*128+i]); |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
510 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
|
511 qmin = FFMIN(qmin, t); |
c5ca5e520fe1
Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents:
9939
diff
changeset
|
512 qmax = FFMAX(qmax, t); |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
513 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
514 } |
9936 | 515 if (nz) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
516 int minscale, maxscale; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
517 float minrd = INFINITY; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
518 //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
|
519 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
|
520 //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
|
521 maxscale = av_clip_uint8(log2(qmax)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512); |
9936 | 522 for (q = minscale; q < maxscale; q++) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
523 float dists[12], dist; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
524 memset(dists, 0, sizeof(dists)); |
9936 | 525 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
|
526 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
|
527 int cb; |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
528 for (cb = 0; cb <= ESC_BT; cb++) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
529 dists[cb] += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
530 q, cb, lambda / band->threshold, INFINITY, NULL); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
531 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
532 dist = dists[0]; |
9936 | 533 for (i = 1; i <= ESC_BT; i++) |
9944
c5ca5e520fe1
Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents:
9939
diff
changeset
|
534 dist = FFMIN(dist, dists[i]); |
c5ca5e520fe1
Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents:
9939
diff
changeset
|
535 minrd = FFMIN(minrd, dist); |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
536 |
9936 | 537 for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, 256); i++) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
538 float cost; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
539 int minv, maxv; |
9936 | 540 if (isinf(paths[idx - 256 + i].cost)) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
541 continue; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
542 cost = paths[idx - 256 + i].cost + dist |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
543 + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
544 minv = FFMIN(paths[idx - 256 + i].min_val, q); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
545 maxv = FFMAX(paths[idx - 256 + i].max_val, q); |
9936 | 546 if (cost < paths[idx + q].cost && maxv-minv < SCALE_MAX_DIFF) { |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
547 paths[idx + q].cost = cost; |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
548 paths[idx + q].prev = idx - 256 + i; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
549 paths[idx + q].min_val = minv; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
550 paths[idx + q].max_val = maxv; |
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 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
553 } |
9936 | 554 } else { |
555 for (q = 0; q < 256; q++) { | |
556 if (!isinf(paths[idx - 256 + q].cost)) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
557 paths[idx + q].cost = paths[idx - 256 + q].cost + 1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
558 paths[idx + q].prev = idx - 256 + q; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
559 paths[idx + q].min_val = FFMIN(paths[idx - 256 + q].min_val, q); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
560 paths[idx + q].max_val = FFMAX(paths[idx - 256 + q].max_val, q); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
561 continue; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
562 } |
9936 | 563 for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, 256); i++) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
564 float cost; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
565 int minv, maxv; |
9936 | 566 if (isinf(paths[idx - 256 + i].cost)) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
567 continue; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
568 cost = paths[idx - 256 + i].cost + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
569 minv = FFMIN(paths[idx - 256 + i].min_val, q); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
570 maxv = FFMAX(paths[idx - 256 + i].max_val, q); |
9936 | 571 if (cost < paths[idx + q].cost && maxv-minv < SCALE_MAX_DIFF) { |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
572 paths[idx + q].cost = cost; |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
573 paths[idx + q].prev = idx - 256 + i; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
574 paths[idx + q].min_val = minv; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
575 paths[idx + q].max_val = maxv; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
576 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
577 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
578 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
579 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
580 sce->zeroes[w*16+g] = !nz; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
581 start += sce->ics.swb_sizes[g]; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
582 idx += 256; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
583 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
584 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
585 idx -= 256; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
586 mincost = paths[idx].cost; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
587 minq = idx; |
9936 | 588 for (i = 1; i < 256; i++) { |
589 if (paths[idx + i].cost < mincost) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
590 mincost = paths[idx + i].cost; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
591 minq = idx + i; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
592 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
593 } |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
594 while (minq >= 256) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
595 sce->sf_idx[bandaddr[minq>>8]] = minq & 0xFF; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
596 minq = paths[minq].prev; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
597 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
598 //set the same quantizers inside window groups |
9936 | 599 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) |
600 for (g = 0; g < sce->ics.num_swb; g++) | |
601 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
|
602 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
|
603 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
604 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
605 /** |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
606 * 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
|
607 */ |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
608 static void search_for_quantizers_twoloop(AVCodecContext *avctx, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
609 AACEncContext *s, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
610 SingleChannelElement *sce, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
611 const float lambda) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
612 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
613 int start = 0, i, w, w2, g; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
614 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
|
615 float dists[128], uplims[128]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
616 int fflag, minscaler; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
617 int its = 0; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
618 int allz = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
619 float minthr = INFINITY; |
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 //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
|
622 memset(dists, 0, sizeof(dists)); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
623 //determine zero bands and upper limits |
9936 | 624 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
625 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
|
626 int nz = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
627 float uplim = 0.0f; |
9936 | 628 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
|
629 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
|
630 uplim += band->threshold; |
9936 | 631 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
|
632 sce->zeroes[(w+w2)*16+g] = 1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
633 continue; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
634 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
635 nz = 1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
636 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
637 uplims[w*16+g] = uplim *512; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
638 sce->zeroes[w*16+g] = !nz; |
9936 | 639 if (nz) |
9944
c5ca5e520fe1
Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents:
9939
diff
changeset
|
640 minthr = FFMIN(minthr, uplim); |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
641 allz = FFMAX(allz, nz); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
642 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
643 } |
9936 | 644 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
645 for (g = 0; g < sce->ics.num_swb; g++) { | |
646 if (sce->zeroes[w*16+g]) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
647 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
|
648 continue; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
649 } |
9944
c5ca5e520fe1
Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents:
9939
diff
changeset
|
650 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
|
651 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
652 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
653 |
9936 | 654 if (!allz) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
655 return; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
656 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
|
657 //perform two-loop search |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
658 //outer loop - improve quality |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
659 do { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
660 int tbits, qstep; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
661 minscaler = sce->sf_idx[0]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
662 //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
|
663 qstep = its ? 1 : 32; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
664 do { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
665 int prev = -1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
666 tbits = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
667 fflag = 0; |
9936 | 668 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
|
669 start = w*128; |
9936 | 670 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
|
671 const float *coefs = sce->coeffs + start; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
672 const float *scaled = s->scoefs + start; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
673 int bits = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
674 int cb; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
675 float mindist = INFINITY; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
676 int minbits = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
677 |
9936 | 678 if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
679 continue; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
680 minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]); |
9936 | 681 for (cb = 0; cb <= ESC_BT; cb++) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
682 float dist = 0.0f; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
683 int bb = 0; |
9936 | 684 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
|
685 int b; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
686 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
|
687 scaled + w2*128, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
688 sce->ics.swb_sizes[g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
689 sce->sf_idx[w*16+g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
690 ESC_BT, |
9939 | 691 lambda, |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
692 INFINITY, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
693 &b); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
694 bb += b; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
695 } |
9936 | 696 if (dist < mindist) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
697 mindist = dist; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
698 minbits = bb; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
699 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
700 } |
9939 | 701 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
|
702 bits = minbits; |
9936 | 703 if (prev != -1) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
704 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
|
705 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
706 tbits += bits; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
707 start += sce->ics.swb_sizes[g]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
708 prev = sce->sf_idx[w*16+g]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
709 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
710 } |
9936 | 711 if (tbits > destbits) { |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
712 for (i = 0; i < 128; i++) |
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
713 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
|
714 sce->sf_idx[i] += qstep; |
9936 | 715 } else { |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
716 for (i = 0; i < 128; i++) |
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
717 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
|
718 sce->sf_idx[i] -= qstep; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
719 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
720 qstep >>= 1; |
9936 | 721 if (!qstep && tbits > destbits*1.02) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
722 qstep = 1; |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
723 if (sce->sf_idx[0] >= 217) |
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
724 break; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
725 } while (qstep); |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
726 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
727 fflag = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
728 minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF); |
9936 | 729 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
|
730 start = w*128; |
9936 | 731 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
|
732 int prevsc = sce->sf_idx[w*16+g]; |
9936 | 733 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
|
734 sce->sf_idx[w*16+g]--; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
735 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
|
736 sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219); |
9936 | 737 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
|
738 fflag = 1; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
739 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
740 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
741 its++; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
742 } while (fflag && its < 10); |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
743 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
744 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
745 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
|
746 SingleChannelElement *sce, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
747 const float lambda) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
748 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
749 int start = 0, i, w, w2, g; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
750 float uplim[128], maxq[128]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
751 int minq, maxsf; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
752 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
|
753 int last = 0, lastband = 0, curband = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
754 float avg_energy = 0.0; |
9936 | 755 if (sce->ics.num_windows == 1) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
756 start = 0; |
9936 | 757 for (i = 0; i < 1024; i++) { |
758 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
|
759 start += sce->ics.swb_sizes[curband]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
760 curband++; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
761 } |
9936 | 762 if (sce->coeffs[i]) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
763 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
|
764 last = i; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
765 lastband = curband; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
766 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
767 } |
9936 | 768 } else { |
769 for (w = 0; w < 8; w++) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
770 const float *coeffs = sce->coeffs + w*128; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
771 start = 0; |
9936 | 772 for (i = 0; i < 128; i++) { |
773 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
|
774 start += sce->ics.swb_sizes[curband]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
775 curband++; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
776 } |
9936 | 777 if (coeffs[i]) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
778 avg_energy += coeffs[i] * coeffs[i]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
779 last = FFMAX(last, i); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
780 lastband = FFMAX(lastband, curband); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
781 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
782 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
783 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
784 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
785 last++; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
786 avg_energy /= last; |
9936 | 787 if (avg_energy == 0.0f) { |
788 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
|
789 sce->sf_idx[i] = SCALE_ONE_POS; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
790 return; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
791 } |
9936 | 792 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
|
793 start = w*128; |
9936 | 794 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
|
795 float *coefs = sce->coeffs + start; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
796 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
|
797 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
|
798 float maxval = -1, thr = 0.0f, t; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
799 maxq[w*16+g] = 0.0f; |
9936 | 800 if (g > lastband) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
801 maxq[w*16+g] = 0.0f; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
802 start += size; |
9936 | 803 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
|
804 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
|
805 continue; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
806 } |
9936 | 807 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { |
808 for (i = 0; i < size; i++) { | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
809 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
|
810 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
|
811 thr += t; |
9936 | 812 if (sce->ics.num_windows == 1 && maxval < t) { |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
813 maxval = t; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
814 peakpos = start+i; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
815 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
816 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
817 } |
9936 | 818 if (sce->ics.num_windows == 1) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
819 start2 = FFMAX(peakpos - 2, start2); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
820 end2 = FFMIN(peakpos + 3, end2); |
9936 | 821 } else { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
822 start2 -= start; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
823 end2 -= start; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
824 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
825 start += size; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
826 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
|
827 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
|
828 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
|
829 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
830 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
831 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
|
832 abs_pow34_v(s->scoefs, sce->coeffs, 1024); |
9936 | 833 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
|
834 start = w*128; |
9936 | 835 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
|
836 const float *coefs = sce->coeffs + start; |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
837 const float *scaled = s->scoefs + start; |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
838 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
|
839 int scf, prev_scf, step; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
840 int min_scf = 0, max_scf = 255; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
841 float curdiff; |
9936 | 842 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
|
843 sce->zeroes[w*16+g] = 1; |
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 continue; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
846 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
847 sce->zeroes[w*16+g] = 0; |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
848 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
|
849 step = 16; |
9936 | 850 for (;;) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
851 float dist = 0.0f; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
852 int quant_max; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
853 |
9936 | 854 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
|
855 int b; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
856 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
|
857 scaled + w2*128, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
858 sce->ics.swb_sizes[g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
859 scf, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
860 ESC_BT, |
9939 | 861 lambda, |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
862 INFINITY, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
863 &b); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
864 dist -= b; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
865 } |
9939 | 866 dist *= 1.0f / 512.0f / lambda; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
867 quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[200 - scf + SCALE_ONE_POS - SCALE_DIV_512]); |
9936 | 868 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
|
869 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
|
870 break; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
871 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
872 prev_scf = scf; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
873 curdiff = fabsf(dist - uplim[w*16+g]); |
9936 | 874 if (curdiff == 0.0f) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
875 step = 0; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
876 else |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
877 step = fabsf(log2(curdiff)); |
9936 | 878 if (dist > uplim[w*16+g]) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
879 step = -step; |
9936 | 880 if (FFABS(step) <= 1 || (step > 0 && scf >= max_scf) || (step < 0 && scf <= min_scf)) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
881 sce->sf_idx[w*16+g] = scf; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
882 break; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
883 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
884 scf += step; |
9936 | 885 if (step > 0) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
886 min_scf = scf; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
887 else |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
888 max_scf = scf; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
889 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
890 start += size; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
891 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
892 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
893 minq = sce->sf_idx[0] ? sce->sf_idx[0] : INT_MAX; |
9936 | 894 for (i = 1; i < 128; i++) { |
895 if (!sce->sf_idx[i]) | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
896 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
|
897 else |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
898 minq = FFMIN(minq, sce->sf_idx[i]); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
899 } |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
900 if (minq == INT_MAX) |
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
901 minq = 0; |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
902 minq = FFMIN(minq, SCALE_MAX_POS); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
903 maxsf = FFMIN(minq + SCALE_MAX_DIFF, SCALE_MAX_POS); |
9936 | 904 for (i = 126; i >= 0; i--) { |
905 if (!sce->sf_idx[i]) | |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
906 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
|
907 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
|
908 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
909 } |
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 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
|
912 SingleChannelElement *sce, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
913 const float lambda) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
914 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
915 int start = 0, i, w, w2, g; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
916 int minq = 255; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
917 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
918 memset(sce->sf_idx, 0, sizeof(sce->sf_idx)); |
9936 | 919 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
|
920 start = w*128; |
9936 | 921 for (g = 0; g < sce->ics.num_swb; g++) { |
922 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
|
923 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; |
9936 | 924 if (band->energy <= band->threshold) { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
925 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
|
926 sce->zeroes[(w+w2)*16+g] = 1; |
9936 | 927 } else { |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
928 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
|
929 sce->zeroes[(w+w2)*16+g] = 0; |
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 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
|
932 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
933 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
934 } |
9936 | 935 for (i = 0; i < 128; i++) { |
9938
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
936 sce->sf_idx[i] = 140; |
6c1ac45b3097
cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents:
9937
diff
changeset
|
937 //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
|
938 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
939 //set the same quantizers inside window groups |
9936 | 940 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) |
941 for (g = 0; g < sce->ics.num_swb; g++) | |
942 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
|
943 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
|
944 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
945 |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
946 static void search_for_ms(AACEncContext *s, ChannelElement *cpe, |
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
947 const float lambda) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
948 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
949 int start = 0, i, w, w2, g; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
950 float M[128], S[128]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
951 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
|
952 SingleChannelElement *sce0 = &cpe->ch[0]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
953 SingleChannelElement *sce1 = &cpe->ch[1]; |
9936 | 954 if (!cpe->common_window) |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
955 return; |
9936 | 956 for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) { |
957 for (g = 0; g < sce0->ics.num_swb; g++) { | |
958 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
|
959 float dist1 = 0.0f, dist2 = 0.0f; |
9936 | 960 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
|
961 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
|
962 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
|
963 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
|
964 float maxthr = FFMAX(band0->threshold, band1->threshold); |
9936 | 965 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
|
966 M[i] = (sce0->coeffs[start+w2*128+i] |
9937
3e39dbd2d9eb
cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents:
9936
diff
changeset
|
967 + 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
|
968 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
|
969 - sce1->coeffs[start+w2*128+i]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
970 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
971 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
|
972 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
|
973 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
|
974 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
|
975 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
|
976 L34, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
977 sce0->ics.swb_sizes[g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
978 sce0->sf_idx[(w+w2)*16+g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
979 sce0->band_type[(w+w2)*16+g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
980 lambda / band0->threshold, INFINITY, NULL); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
981 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
|
982 R34, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
983 sce1->ics.swb_sizes[g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
984 sce1->sf_idx[(w+w2)*16+g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
985 sce1->band_type[(w+w2)*16+g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
986 lambda / band1->threshold, INFINITY, NULL); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
987 dist2 += quantize_band_cost(s, M, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
988 M34, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
989 sce0->ics.swb_sizes[g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
990 sce0->sf_idx[(w+w2)*16+g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
991 sce0->band_type[(w+w2)*16+g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
992 lambda / maxthr, INFINITY, NULL); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
993 dist2 += quantize_band_cost(s, S, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
994 S34, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
995 sce1->ics.swb_sizes[g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
996 sce1->sf_idx[(w+w2)*16+g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
997 sce1->band_type[(w+w2)*16+g], |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
998 lambda / minthr, INFINITY, NULL); |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
999 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1000 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
|
1001 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1002 start += sce0->ics.swb_sizes[g]; |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1003 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1004 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1005 } |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1006 |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1007 AACCoefficientsEncoder ff_aac_coders[] = { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1008 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1009 search_for_quantizers_faac, |
9939 | 1010 encode_window_bands_info, |
9935
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1011 quantize_and_encode_band, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1012 // search_for_ms, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1013 }, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1014 { |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1015 search_for_quantizers_anmr, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1016 encode_window_bands_info, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1017 quantize_and_encode_band, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1018 // search_for_ms, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1019 }, |
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 search_for_quantizers_twoloop, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1022 encode_window_bands_info, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1023 quantize_and_encode_band, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1024 // search_for_ms, |
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 search_for_quantizers_fast, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1028 encode_window_bands_info, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1029 quantize_and_encode_band, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1030 // search_for_ms, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1031 }, |
d09283aeeef8
Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff
changeset
|
1032 }; |