annotate aaccoder.c @ 11629:251ce43203f6 libavcodec

Factorize code in get_bit_rate().
author stefano
date Tue, 13 Apr 2010 23:24:25 +0000
parents bc0012099ba3
children 7dd2a45249a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
1 /*
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
2 * AAC coefficients encoder
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
3 * Copyright (C) 2008-2009 Konstantin Shishkov
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
4 *
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
5 * This file is part of FFmpeg.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
6 *
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
11 *
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
15 * Lesser General Public License for more details.
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
16 *
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
20 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
21
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
22 /**
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
27339a7fee03 Fix an integer overflow in the AAC encoder.
alexc
parents: 9961
diff changeset
75 out[i][0] = (int)FFMIN(qc, (double)maxval);
27339a7fee03 Fix an integer overflow in the AAC encoder.
alexc
parents: 9961
diff changeset
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 */
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
103 static float quantize_and_encode_band_cost(struct AACEncContext *s,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
104 PutBitContext *pb, const float *in,
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
105 const float *scaled, int size, int scale_idx,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
106 int cb, const float lambda, const float uplim,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
107 int *bits)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
108 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
109 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
110 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
111 const float CLIPPED_ESCAPE = 165140.0f*IQ;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
112 int i, j, k;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
113 float cost = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
114 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
115 int resbits = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
116 #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
117 const float Q34 = sqrtf(Q * sqrtf(Q));
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
118 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
119 const int maxval = aac_cb_maxval[cb];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
120 int offs[4];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
121 #endif /* USE_REALLY_FULL_SEARCH */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
122
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
123 if (!cb) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
124 for (i = 0; i < size; i++)
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
125 cost += in[i]*in[i];
9957
6fb2be900484 When calculating AAC quantized band cost, don't leave garbage in the bit count
alexc
parents: 9944
diff changeset
126 if (bits)
6fb2be900484 When calculating AAC quantized band cost, don't leave garbage in the bit count
alexc
parents: 9944
diff changeset
127 *bits = 0;
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
128 return cost * lambda;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
129 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
130 #ifndef USE_REALLY_FULL_SEARCH
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
131 offs[0] = 1;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
132 for (i = 1; i < dim; i++)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
133 offs[i] = offs[i-1]*range;
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
134 if (!scaled) {
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
135 abs_pow34_v(s->scoefs, in, size);
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
136 scaled = s->scoefs;
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
137 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
138 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
139 #endif /* USE_REALLY_FULL_SEARCH */
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
140 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
141 float mincost;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
142 int minidx = 0;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
143 int minbits = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
144 const float *vec;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
145 #ifndef USE_REALLY_FULL_SEARCH
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
146 int (*quants)[2] = &s->qcoefs[i];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
147 mincost = 0.0f;
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
148 for (j = 0; j < dim; j++)
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
149 mincost += in[i+j]*in[i+j];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
150 minidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
151 minbits = ff_aac_spectral_bits[cb-1][minidx];
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
152 mincost = mincost * lambda + minbits;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
153 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
154 float rd = 0.0f;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
155 int curbits;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
156 int curidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
157 int same = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
158 for (k = 0; k < dim; k++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
159 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
160 same = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
161 break;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
162 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
163 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
164 if (same)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
165 continue;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
166 for (k = 0; k < dim; k++)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
167 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
168 curbits = ff_aac_spectral_bits[cb-1][curidx];
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
169 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
170 #else
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
171 mincost = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
172 vec = ff_aac_codebook_vectors[cb-1];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
173 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
174 float rd = 0.0f;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
175 int curbits = ff_aac_spectral_bits[cb-1][j];
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
176 int curidx = j;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
177 #endif /* USE_REALLY_FULL_SEARCH */
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
178 if (IS_CODEBOOK_UNSIGNED(cb)) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
179 for (k = 0; k < dim; k++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
180 float t = fabsf(in[i+k]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
181 float di;
10208
39285535090c aacenc: Don't make unnecessary compares to the escape value in tight loops.
alexc
parents: 10109
diff changeset
182 if (vec[k] == 64.0f) { //FIXME: slow
10209
bc939146f2e1 Cosmetics: Reindent after r19943.
alexc
parents: 10208
diff changeset
183 //do not code with escape sequence small values
bc939146f2e1 Cosmetics: Reindent after r19943.
alexc
parents: 10208
diff changeset
184 if (t < 39.0f*IQ) {
bc939146f2e1 Cosmetics: Reindent after r19943.
alexc
parents: 10208
diff changeset
185 rd = INFINITY;
bc939146f2e1 Cosmetics: Reindent after r19943.
alexc
parents: 10208
diff changeset
186 break;
bc939146f2e1 Cosmetics: Reindent after r19943.
alexc
parents: 10208
diff changeset
187 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
188 if (t >= CLIPPED_ESCAPE) {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
189 di = t - CLIPPED_ESCAPE;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
190 curbits += 21;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
191 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
192 int c = av_clip(quant(t, Q), 0, 8191);
10211
337e5592f985 aacenc: Replace cbrt() with cbrtf() when the result is destined for float
alexc
parents: 10210
diff changeset
193 di = t - c*cbrtf(c)*IQ;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
194 curbits += av_log2(c)*2 - 4 + 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
195 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
196 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
197 di = t - vec[k]*IQ;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
198 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
199 if (vec[k] != 0.0f)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
200 curbits++;
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
201 rd += di*di;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
202 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
203 } else {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
204 for (k = 0; k < dim; k++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
205 float di = in[i+k] - vec[k]*IQ;
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
206 rd += di*di;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
207 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
208 }
10210
47048ee7db4e aacenc: Multiple distortion by lambda after it's summed and not each individual
alexc
parents: 10209
diff changeset
209 rd = rd * lambda + curbits;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
210 if (rd < mincost) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
211 mincost = rd;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
212 minidx = curidx;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
213 minbits = curbits;
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 }
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
216 cost += mincost;
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
217 resbits += minbits;
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
218 if (cost >= uplim)
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
219 return uplim;
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
220 if (pb) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
221 put_bits(pb, ff_aac_spectral_bits[cb-1][minidx], ff_aac_spectral_codes[cb-1][minidx]);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
222 if (IS_CODEBOOK_UNSIGNED(cb))
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
223 for (j = 0; j < dim; j++)
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
224 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
225 put_bits(pb, 1, in[i+j] < 0.0f);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
226 if (cb == ESC_BT) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
227 for (j = 0; j < 2; j++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
228 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
229 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
230 int len = av_log2(coef);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
231
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
232 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
233 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
234 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
235 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
236 }
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
237 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
238 }
11537
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
239
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
240 if (bits)
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
241 *bits = resbits;
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
242 return cost;
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
243 }
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
244 static float quantize_band_cost(struct AACEncContext *s, const float *in,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
245 const float *scaled, int size, int scale_idx,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
246 int cb, const float lambda, const float uplim,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
247 int *bits)
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
248 {
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
249 return quantize_and_encode_band_cost(s, NULL, in, scaled, size, scale_idx,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
250 cb, lambda, uplim, bits);
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
251 }
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
252
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
253 static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
254 const float *in, int size, int scale_idx,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
255 int cb, const float lambda)
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
256 {
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
257 quantize_and_encode_band_cost(s, pb, in, NULL, size, scale_idx, cb, lambda,
bc0012099ba3 aacenc: Merge quantize_band_cost() with quantize_and_encode_band().
alexc
parents: 10213
diff changeset
258 INFINITY, NULL);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
259 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
260
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
261 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
262 * structure used in optimal codebook search
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
263 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
264 typedef struct BandCodingPath {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
265 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
266 float cost; ///< path cost
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
267 int run;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
268 } BandCodingPath;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
269
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
270 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
271 * 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
272 */
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
273 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
274 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
275 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
276 BandCodingPath path[120][12];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
277 int w, swb, cb, start, start2, size;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
278 int i, j;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
279 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
280 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
281 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
282 int idx, ppos, count;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
283 int stackrun[120], stackcb[120], stack_len;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
284 float next_minrd = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
285 int next_mincb = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
286
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
287 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
288 start = win*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
289 for (cb = 0; cb < 12; cb++) {
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
290 path[0][cb].cost = 0.0f;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
291 path[0][cb].prev_idx = -1;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
292 path[0][cb].run = 0;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
293 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
294 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
295 start2 = start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
296 size = sce->ics.swb_sizes[swb];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
297 if (sce->zeroes[win*16 + swb]) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
298 for (cb = 0; cb < 12; cb++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
299 path[swb+1][cb].prev_idx = cb;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
300 path[swb+1][cb].cost = path[swb][cb].cost;
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
301 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
302 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
303 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
304 float minrd = next_minrd;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
305 int mincb = next_mincb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
306 next_minrd = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
307 next_mincb = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
308 for (cb = 0; cb < 12; cb++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
309 float cost_stay_here, cost_get_here;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
310 float rd = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
311 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
312 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
313 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
314 s->scoefs + start + w*128, size,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
315 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
316 lambda / band->threshold, INFINITY, NULL);
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 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
319 cost_get_here = minrd + rd + run_bits + 4;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
320 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
321 != 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
322 cost_stay_here += run_bits;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
323 if (cost_get_here < cost_stay_here) {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
324 path[swb+1][cb].prev_idx = mincb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
325 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
326 path[swb+1][cb].run = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
327 } else {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
328 path[swb+1][cb].prev_idx = cb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
329 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
330 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
331 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
332 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
333 next_minrd = path[swb+1][cb].cost;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
334 next_mincb = cb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
335 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
336 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
337 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
338 start += sce->ics.swb_sizes[swb];
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 //convert resulting path from backward-linked list
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
342 stack_len = 0;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
343 idx = 0;
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
344 for (cb = 1; cb < 12; cb++)
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
345 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
346 idx = cb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
347 ppos = max_sfb;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
348 while (ppos > 0) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
349 cb = idx;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
350 stackrun[stack_len] = path[ppos][cb].run;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
351 stackcb [stack_len] = cb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
352 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
353 ppos -= path[ppos][cb].run;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
354 stack_len++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
355 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
356 //perform actual band info encoding
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
357 start = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
358 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
359 put_bits(&s->pb, 4, stackcb[i]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
360 count = stackrun[i];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
361 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
362 //XXX: memset when band_type is also uint8_t
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
363 for (j = 0; j < count; j++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
364 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
365 start++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
366 }
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
367 while (count >= run_esc) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
368 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
369 count -= run_esc;
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 put_bits(&s->pb, run_bits, count);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
372 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
373 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
374
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
375 typedef struct TrellisPath {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
376 float cost;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
377 int prev;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
378 int min_val;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
379 int max_val;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
380 } TrellisPath;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
381
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
382 #define TRELLIS_STAGES 121
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
383 #define TRELLIS_STATES 256
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
384
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
385 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
386 SingleChannelElement *sce,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
387 const float lambda)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
388 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
389 int q, w, w2, g, start = 0;
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
390 int i, j;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
391 int idx;
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
392 TrellisPath paths[TRELLIS_STAGES][TRELLIS_STATES];
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
393 int bandaddr[TRELLIS_STAGES];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
394 int minq;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
395 float mincost;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
396
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
397 for (i = 0; i < TRELLIS_STATES; i++) {
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
398 paths[0][i].cost = 0.0f;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
399 paths[0][i].prev = -1;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
400 paths[0][i].min_val = i;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
401 paths[0][i].max_val = i;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
402 }
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
403 for (j = 1; j < TRELLIS_STAGES; j++) {
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
404 for (i = 0; i < TRELLIS_STATES; i++) {
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
405 paths[j][i].cost = INFINITY;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
406 paths[j][i].prev = -2;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
407 paths[j][i].min_val = INT_MAX;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
408 paths[j][i].max_val = 0;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
409 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
410 }
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
411 idx = 1;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
412 abs_pow34_v(s->scoefs, sce->coeffs, 1024);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
413 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
414 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
415 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
416 const float *coefs = sce->coeffs + start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
417 float qmin, qmax;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
418 int nz = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
419
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
420 bandaddr[idx] = w * 16 + g;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
421 qmin = INT_MAX;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
422 qmax = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
423 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
424 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
425 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
426 sce->zeroes[(w+w2)*16+g] = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
427 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
428 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
429 sce->zeroes[(w+w2)*16+g] = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
430 nz = 1;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
431 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
432 float t = fabsf(coefs[w2*128+i]);
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
433 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
434 qmin = FFMIN(qmin, t);
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
435 qmax = FFMAX(qmax, t);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
436 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
437 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
438 if (nz) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
439 int minscale, maxscale;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
440 float minrd = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
441 //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
442 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
443 //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
444 maxscale = av_clip_uint8(log2(qmax)*4 + 6 + SCALE_ONE_POS - SCALE_DIV_512);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
445 for (q = minscale; q < maxscale; q++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
446 float dists[12], dist;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
447 memset(dists, 0, sizeof(dists));
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
448 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
449 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
450 int cb;
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
451 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
452 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
453 q, cb, lambda / band->threshold, INFINITY, NULL);
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 dist = dists[0];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
456 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
457 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
458 minrd = FFMIN(minrd, dist);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
459
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
460 for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, TRELLIS_STATES); i++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
461 float cost;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
462 int minv, maxv;
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
463 if (isinf(paths[idx - 1][i].cost))
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
464 continue;
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
465 cost = paths[idx - 1][i].cost + dist
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
466 + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO];
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
467 minv = FFMIN(paths[idx - 1][i].min_val, q);
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
468 maxv = FFMAX(paths[idx - 1][i].max_val, q);
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
469 if (cost < paths[idx][q].cost && maxv-minv < SCALE_MAX_DIFF) {
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
470 paths[idx][q].cost = cost;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
471 paths[idx][q].prev = i;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
472 paths[idx][q].min_val = minv;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
473 paths[idx][q].max_val = maxv;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
474 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
475 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
476 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
477 } else {
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
478 for (q = 0; q < TRELLIS_STATES; q++) {
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
479 if (!isinf(paths[idx - 1][q].cost)) {
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
480 paths[idx][q].cost = paths[idx - 1][q].cost + 1;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
481 paths[idx][q].prev = q;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
482 paths[idx][q].min_val = FFMIN(paths[idx - 1][q].min_val, q);
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
483 paths[idx][q].max_val = FFMAX(paths[idx - 1][q].max_val, q);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
484 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
485 }
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
486 for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, TRELLIS_STATES); i++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
487 float cost;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
488 int minv, maxv;
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
489 if (isinf(paths[idx - 1][i].cost))
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
490 continue;
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
491 cost = paths[idx - 1][i].cost + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO];
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
492 minv = FFMIN(paths[idx - 1][i].min_val, q);
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
493 maxv = FFMAX(paths[idx - 1][i].max_val, q);
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
494 if (cost < paths[idx][q].cost && maxv-minv < SCALE_MAX_DIFF) {
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
495 paths[idx][q].cost = cost;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
496 paths[idx][q].prev = i;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
497 paths[idx][q].min_val = minv;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
498 paths[idx][q].max_val = maxv;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
499 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
500 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
501 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
502 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
503 sce->zeroes[w*16+g] = !nz;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
504 start += sce->ics.swb_sizes[g];
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
505 idx++;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
506 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
507 }
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
508 idx--;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
509 mincost = paths[idx][0].cost;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
510 minq = 0;
10213
cebf6e3381e0 aacenc: Use preprocessor constants for trellis states and stages.
alexc
parents: 10212
diff changeset
511 for (i = 1; i < TRELLIS_STATES; i++) {
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
512 if (paths[idx][i].cost < mincost) {
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
513 mincost = paths[idx][i].cost;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
514 minq = i;
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 }
10212
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
517 while (idx) {
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
518 sce->sf_idx[bandaddr[idx]] = minq;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
519 minq = paths[idx][minq].prev;
4e2db0d76fad aacenc: Split paths in the scalefactor selection trellis into a 2-D array.
alexc
parents: 10211
diff changeset
520 idx--;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
521 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
522 //set the same quantizers inside window groups
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
523 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
524 for (g = 0; g < sce->ics.num_swb; g++)
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
525 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
526 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
527 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
528
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
529 /**
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
530 * 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
531 */
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
532 static void search_for_quantizers_twoloop(AVCodecContext *avctx,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
533 AACEncContext *s,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
534 SingleChannelElement *sce,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
535 const float lambda)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
536 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
537 int start = 0, i, w, w2, g;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
538 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
539 float dists[128], uplims[128];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
540 int fflag, minscaler;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
541 int its = 0;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
542 int allz = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
543 float minthr = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
544
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
545 //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
546 memset(dists, 0, sizeof(dists));
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
547 //determine zero bands and upper limits
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
548 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
549 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
550 int nz = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
551 float uplim = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
552 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
553 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
554 uplim += band->threshold;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
555 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
556 sce->zeroes[(w+w2)*16+g] = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
557 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
558 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
559 nz = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
560 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
561 uplims[w*16+g] = uplim *512;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
562 sce->zeroes[w*16+g] = !nz;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
563 if (nz)
9944
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
564 minthr = FFMIN(minthr, uplim);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
565 allz = FFMAX(allz, nz);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
566 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
567 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
568 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
569 for (g = 0; g < sce->ics.num_swb; g++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
570 if (sce->zeroes[w*16+g]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
571 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
572 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
573 }
9944
c5ca5e520fe1 Change fminf/fmaxf to FFMIN/FFMAX to fix the build on broken operating systems.
alexc
parents: 9939
diff changeset
574 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
575 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
576 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
577
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
578 if (!allz)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
579 return;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
580 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
581 //perform two-loop search
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
582 //outer loop - improve quality
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
583 do {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
584 int tbits, qstep;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
585 minscaler = sce->sf_idx[0];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
586 //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
587 qstep = its ? 1 : 32;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
588 do {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
589 int prev = -1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
590 tbits = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
591 fflag = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
592 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
593 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
594 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
595 const float *coefs = sce->coeffs + start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
596 const float *scaled = s->scoefs + start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
597 int bits = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
598 int cb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
599 float mindist = INFINITY;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
600 int minbits = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
601
9971
4b6f16da6652 Be sure to increment our position in the coefficient array when skipping a zero
alexc
parents: 9967
diff changeset
602 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
603 start += sce->ics.swb_sizes[g];
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
604 continue;
9971
4b6f16da6652 Be sure to increment our position in the coefficient array when skipping a zero
alexc
parents: 9967
diff changeset
605 }
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
606 minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
607 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
608 float dist = 0.0f;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
609 int bb = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
610 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
611 int b;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
612 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
613 scaled + w2*128,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
614 sce->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
615 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
616 cb,
9939
6c5a58b34997 Turn on AAC rate control.
alexc
parents: 9938
diff changeset
617 lambda,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
618 INFINITY,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
619 &b);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
620 bb += b;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
621 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
622 if (dist < mindist) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
623 mindist = dist;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
624 minbits = bb;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
625 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
626 }
9939
6c5a58b34997 Turn on AAC rate control.
alexc
parents: 9938
diff changeset
627 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
628 bits = minbits;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
629 if (prev != -1) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
630 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
631 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
632 tbits += bits;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
633 start += sce->ics.swb_sizes[g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
634 prev = sce->sf_idx[w*16+g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
635 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
636 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
637 if (tbits > destbits) {
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
638 for (i = 0; i < 128; i++)
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
639 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
640 sce->sf_idx[i] += qstep;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
641 } else {
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
642 for (i = 0; i < 128; i++)
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
643 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
644 sce->sf_idx[i] -= qstep;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
645 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
646 qstep >>= 1;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
647 if (!qstep && tbits > destbits*1.02)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
648 qstep = 1;
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
649 if (sce->sf_idx[0] >= 217)
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
650 break;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
651 } while (qstep);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
652
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
653 fflag = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
654 minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
655 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
656 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
657 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
658 int prevsc = sce->sf_idx[w*16+g];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
659 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
660 sce->sf_idx[w*16+g]--;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
661 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
662 sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
663 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
664 fflag = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
665 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
666 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
667 its++;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
668 } while (fflag && its < 10);
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
669 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
670
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
671 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
672 SingleChannelElement *sce,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
673 const float lambda)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
674 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
675 int start = 0, i, w, w2, g;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
676 float uplim[128], maxq[128];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
677 int minq, maxsf;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
678 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
679 int last = 0, lastband = 0, curband = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
680 float avg_energy = 0.0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
681 if (sce->ics.num_windows == 1) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
682 start = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
683 for (i = 0; i < 1024; i++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
684 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
685 start += sce->ics.swb_sizes[curband];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
686 curband++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
687 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
688 if (sce->coeffs[i]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
689 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
690 last = i;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
691 lastband = curband;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
692 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
693 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
694 } else {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
695 for (w = 0; w < 8; w++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
696 const float *coeffs = sce->coeffs + w*128;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
697 start = 0;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
698 for (i = 0; i < 128; i++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
699 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
700 start += sce->ics.swb_sizes[curband];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
701 curband++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
702 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
703 if (coeffs[i]) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
704 avg_energy += coeffs[i] * coeffs[i];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
705 last = FFMAX(last, i);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
706 lastband = FFMAX(lastband, curband);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
707 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
708 }
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 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
711 last++;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
712 avg_energy /= last;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
713 if (avg_energy == 0.0f) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
714 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
715 sce->sf_idx[i] = SCALE_ONE_POS;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
716 return;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
717 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
718 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
719 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
720 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
721 float *coefs = sce->coeffs + start;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
722 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
723 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
724 float maxval = -1, thr = 0.0f, t;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
725 maxq[w*16+g] = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
726 if (g > lastband) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
727 maxq[w*16+g] = 0.0f;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
728 start += size;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
729 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
730 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
731 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
732 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
733 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
734 for (i = 0; i < size; i++) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
735 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
736 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
737 thr += t;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
738 if (sce->ics.num_windows == 1 && maxval < t) {
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
739 maxval = t;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
740 peakpos = start+i;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
741 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
742 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
743 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
744 if (sce->ics.num_windows == 1) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
745 start2 = FFMAX(peakpos - 2, start2);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
746 end2 = FFMIN(peakpos + 3, end2);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
747 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
748 start2 -= start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
749 end2 -= start;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
750 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
751 start += size;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
752 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
753 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
754 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
755 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
756 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
757 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
758 abs_pow34_v(s->scoefs, sce->coeffs, 1024);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
759 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
760 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
761 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
762 const float *coefs = sce->coeffs + start;
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
763 const float *scaled = s->scoefs + start;
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
764 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
765 int scf, prev_scf, step;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
766 int min_scf = 0, max_scf = 255;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
767 float curdiff;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
768 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
769 sce->zeroes[w*16+g] = 1;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
770 start += size;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
771 continue;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
772 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
773 sce->zeroes[w*16+g] = 0;
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
774 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
775 step = 16;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
776 for (;;) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
777 float dist = 0.0f;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
778 int quant_max;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
779
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
780 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
781 int b;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
782 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
783 scaled + w2*128,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
784 sce->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
785 scf,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
786 ESC_BT,
9939
6c5a58b34997 Turn on AAC rate control.
alexc
parents: 9938
diff changeset
787 lambda,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
788 INFINITY,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
789 &b);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
790 dist -= b;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
791 }
9939
6c5a58b34997 Turn on AAC rate control.
alexc
parents: 9938
diff changeset
792 dist *= 1.0f / 512.0f / lambda;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
793 quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[200 - scf + SCALE_ONE_POS - SCALE_DIV_512]);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
794 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
795 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
796 break;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
797 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
798 prev_scf = scf;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
799 curdiff = fabsf(dist - uplim[w*16+g]);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
800 if (curdiff == 0.0f)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
801 step = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
802 else
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
803 step = fabsf(log2(curdiff));
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
804 if (dist > uplim[w*16+g])
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
805 step = -step;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
806 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
807 sce->sf_idx[w*16+g] = scf;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
808 break;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
809 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
810 scf += step;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
811 if (step > 0)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
812 min_scf = scf;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
813 else
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
814 max_scf = scf;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
815 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
816 start += size;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
817 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
818 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
819 minq = sce->sf_idx[0] ? sce->sf_idx[0] : INT_MAX;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
820 for (i = 1; i < 128; i++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
821 if (!sce->sf_idx[i])
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
822 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
823 else
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
824 minq = FFMIN(minq, sce->sf_idx[i]);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
825 }
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
826 if (minq == INT_MAX)
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
827 minq = 0;
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
828 minq = FFMIN(minq, SCALE_MAX_POS);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
829 maxsf = FFMIN(minq + SCALE_MAX_DIFF, SCALE_MAX_POS);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
830 for (i = 126; i >= 0; i--) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
831 if (!sce->sf_idx[i])
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
832 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
833 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
834 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
835 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
836
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
837 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
838 SingleChannelElement *sce,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
839 const float lambda)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
840 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
841 int start = 0, i, w, w2, g;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
842 int minq = 255;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
843
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
844 memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
845 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
846 start = w*128;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
847 for (g = 0; g < sce->ics.num_swb; g++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
848 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
849 FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
850 if (band->energy <= band->threshold) {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
851 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
852 sce->zeroes[(w+w2)*16+g] = 1;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
853 } else {
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
854 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
855 sce->zeroes[(w+w2)*16+g] = 0;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
856 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
857 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
858 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
859 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
860 }
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
861 for (i = 0; i < 128; i++) {
9938
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
862 sce->sf_idx[i] = 140;
6c1ac45b3097 cosmetics: Remove unnecessary {} around if/for blocks;
diego
parents: 9937
diff changeset
863 //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
864 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
865 //set the same quantizers inside window groups
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
866 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
867 for (g = 0; g < sce->ics.num_swb; g++)
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
868 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
869 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
870 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
871
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
872 static void search_for_ms(AACEncContext *s, ChannelElement *cpe,
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
873 const float lambda)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
874 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
875 int start = 0, i, w, w2, g;
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
876 float M[128], S[128];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
877 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
878 SingleChannelElement *sce0 = &cpe->ch[0];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
879 SingleChannelElement *sce1 = &cpe->ch[1];
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
880 if (!cpe->common_window)
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
881 return;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
882 for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
883 for (g = 0; g < sce0->ics.num_swb; g++) {
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
884 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
885 float dist1 = 0.0f, dist2 = 0.0f;
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
886 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
887 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
888 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
889 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
890 float maxthr = FFMAX(band0->threshold, band1->threshold);
9936
7f42ae22c351 Cosmetics: Pretty print the AAC encoder.
alexc
parents: 9935
diff changeset
891 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
892 M[i] = (sce0->coeffs[start+w2*128+i]
9937
3e39dbd2d9eb cosmetics: prettyprinting, K&R style, break overly long lines
diego
parents: 9936
diff changeset
893 + 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
894 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
895 - sce1->coeffs[start+w2*128+i];
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 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
898 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
899 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
900 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
901 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
902 L34,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
903 sce0->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
904 sce0->sf_idx[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
905 sce0->band_type[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
906 lambda / band0->threshold, INFINITY, NULL);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
907 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
908 R34,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
909 sce1->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
910 sce1->sf_idx[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
911 sce1->band_type[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
912 lambda / band1->threshold, INFINITY, NULL);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
913 dist2 += quantize_band_cost(s, M,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
914 M34,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
915 sce0->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
916 sce0->sf_idx[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
917 sce0->band_type[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
918 lambda / maxthr, INFINITY, NULL);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
919 dist2 += quantize_band_cost(s, S,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
920 S34,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
921 sce1->ics.swb_sizes[g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
922 sce1->sf_idx[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
923 sce1->band_type[(w+w2)*16+g],
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
924 lambda / minthr, INFINITY, NULL);
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
925 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
926 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
927 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
928 start += sce0->ics.swb_sizes[g];
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
929 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
930 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
931 }
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
932
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
933 AACCoefficientsEncoder ff_aac_coders[] = {
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 search_for_quantizers_faac,
9939
6c5a58b34997 Turn on AAC rate control.
alexc
parents: 9938
diff changeset
936 encode_window_bands_info,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
937 quantize_and_encode_band,
10109
68f824761c1b Re-add search_for_ms to the coefficients encoders to silence warnings
alexc
parents: 9971
diff changeset
938 search_for_ms,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
939 },
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
940 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
941 search_for_quantizers_anmr,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
942 encode_window_bands_info,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
943 quantize_and_encode_band,
10109
68f824761c1b Re-add search_for_ms to the coefficients encoders to silence warnings
alexc
parents: 9971
diff changeset
944 search_for_ms,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
945 },
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
946 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
947 search_for_quantizers_twoloop,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
948 encode_window_bands_info,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
949 quantize_and_encode_band,
10109
68f824761c1b Re-add search_for_ms to the coefficients encoders to silence warnings
alexc
parents: 9971
diff changeset
950 search_for_ms,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
951 },
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
952 {
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
953 search_for_quantizers_fast,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
954 encode_window_bands_info,
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
955 quantize_and_encode_band,
10109
68f824761c1b Re-add search_for_ms to the coefficients encoders to silence warnings
alexc
parents: 9971
diff changeset
956 search_for_ms,
9935
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
957 },
d09283aeeef8 Merge the AAC encoder from SoC svn. It is still considered experimental.
alexc
parents:
diff changeset
958 };