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