Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 1 | /* |
| 2 | * AAC coefficients encoder |
| 3 | * Copyright (C) 2008-2009 Konstantin Shishkov |
| 4 | * |
| 5 | * This file is part of FFmpeg. |
| 6 | * |
| 7 | * FFmpeg is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * FFmpeg is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with FFmpeg; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | /** |
Diego Biurrun | ba87f08 | 2010-04-20 14:45:34 | [diff] [blame] | 23 | * @file |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 24 | * AAC coefficients encoder |
| 25 | */ |
| 26 | |
| 27 | /*********************************** |
| 28 | * TODOs: |
| 29 | * speedup quantizer selection |
| 30 | * add sane pulse detection |
| 31 | ***********************************/ |
| 32 | |
Reinhard Tartler | 083e715 | 2011-05-11 11:51:11 | [diff] [blame] | 33 | #include "libavutil/libm.h" // brought forward to work around cygwin header breakage |
| 34 | |
Alex Converse | 144c5e3 | 2010-05-25 18:28:18 | [diff] [blame] | 35 | #include <float.h> |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 36 | |
Mans Rullgard | 85770d6 | 2011-07-17 10:19:35 | [diff] [blame] | 37 | #include "libavutil/mathematics.h" |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 38 | #include "mathops.h" |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 39 | #include "avcodec.h" |
| 40 | #include "put_bits.h" |
| 41 | #include "aac.h" |
| 42 | #include "aacenc.h" |
| 43 | #include "aactab.h" |
Rostislav Pehlivanov | c47c781 | 2015-07-29 04:44:26 | [diff] [blame] | 44 | #include "aacenctab.h" |
Rostislav Pehlivanov | ef8e5a6 | 2015-07-29 04:44:27 | [diff] [blame] | 45 | #include "aacenc_utils.h" |
Rostislav Pehlivanov | 43b378a | 2015-08-21 17:53:14 | [diff] [blame] | 46 | #include "aacenc_quantization.h" |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 47 | |
Rostislav Pehlivanov | d1ca714 | 2015-08-21 18:13:26 | [diff] [blame] | 48 | #include "aacenc_is.h" |
Rostislav Pehlivanov | a1c487e | 2015-08-21 18:27:38 | [diff] [blame] | 49 | #include "aacenc_tns.h" |
Rostislav Pehlivanov | d1ca714 | 2015-08-21 18:13:26 | [diff] [blame] | 50 | |
Claudio Freire | 8df9bf8 | 2015-09-15 06:59:45 | [diff] [blame] | 51 | #include "libavcodec/aaccoder_twoloop.h" |
| 52 | |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 53 | /* Parameter of f(x) = a*(lambda/100), defines the maximum fourier spread |
| 54 | * beyond which no PNS is used (since the SFBs contain tone rather than noise) */ |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 55 | #define NOISE_SPREAD_THRESHOLD 0.9f |
Rostislav Pehlivanov | 38fd4c2 | 2015-07-02 18:13:05 | [diff] [blame] | 56 | |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 57 | /* Parameter of f(x) = a*(100/lambda), defines how much PNS is allowed to |
| 58 | * replace low energy non zero bands */ |
| 59 | #define NOISE_LAMBDA_REPLACE 1.948f |
Rostislav Pehlivanov | c5d4f87 | 2015-04-15 11:18:42 | [diff] [blame] | 60 | |
Claudio Freire | 8df9bf8 | 2015-09-15 06:59:45 | [diff] [blame] | 61 | #include "libavcodec/aaccoder_trellis.h" |
| 62 | |
Andreas Rheinhardt | 57d3052 | 2022-08-01 09:54:25 | [diff] [blame] | 63 | typedef float (*quantize_and_encode_band_func)(struct AACEncContext *s, PutBitContext *pb, |
| 64 | const float *in, float *quant, const float *scaled, |
| 65 | int size, int scale_idx, int cb, |
| 66 | const float lambda, const float uplim, |
| 67 | int *bits, float *energy); |
| 68 | |
| 69 | /** |
| 70 | * Calculate rate distortion cost for quantizing with given codebook |
| 71 | * |
| 72 | * @return quantization distortion |
| 73 | */ |
| 74 | static av_always_inline float quantize_and_encode_band_cost_template( |
| 75 | struct AACEncContext *s, |
| 76 | PutBitContext *pb, const float *in, float *out, |
| 77 | const float *scaled, int size, int scale_idx, |
| 78 | int cb, const float lambda, const float uplim, |
| 79 | int *bits, float *energy, int BT_ZERO, int BT_UNSIGNED, |
| 80 | int BT_PAIR, int BT_ESC, int BT_NOISE, int BT_STEREO, |
| 81 | const float ROUNDING) |
| 82 | { |
| 83 | const int q_idx = POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512; |
| 84 | const float Q = ff_aac_pow2sf_tab [q_idx]; |
| 85 | const float Q34 = ff_aac_pow34sf_tab[q_idx]; |
| 86 | const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512]; |
| 87 | const float CLIPPED_ESCAPE = 165140.0f*IQ; |
| 88 | float cost = 0; |
| 89 | float qenergy = 0; |
| 90 | const int dim = BT_PAIR ? 2 : 4; |
| 91 | int resbits = 0; |
| 92 | int off; |
| 93 | |
| 94 | if (BT_ZERO || BT_NOISE || BT_STEREO) { |
| 95 | for (int i = 0; i < size; i++) |
| 96 | cost += in[i]*in[i]; |
| 97 | if (bits) |
| 98 | *bits = 0; |
| 99 | if (energy) |
| 100 | *energy = qenergy; |
| 101 | if (out) { |
| 102 | for (int i = 0; i < size; i += dim) |
| 103 | for (int j = 0; j < dim; j++) |
| 104 | out[i+j] = 0.0f; |
| 105 | } |
| 106 | return cost * lambda; |
| 107 | } |
| 108 | if (!scaled) { |
Andreas Rheinhardt | 88b3b09 | 2024-02-28 12:29:19 | [diff] [blame] | 109 | s->aacdsp.abs_pow34(s->scoefs, in, size); |
Andreas Rheinhardt | 57d3052 | 2022-08-01 09:54:25 | [diff] [blame] | 110 | scaled = s->scoefs; |
| 111 | } |
Andreas Rheinhardt | 88b3b09 | 2024-02-28 12:29:19 | [diff] [blame] | 112 | s->aacdsp.quant_bands(s->qcoefs, in, scaled, size, !BT_UNSIGNED, aac_cb_maxval[cb], Q34, ROUNDING); |
Andreas Rheinhardt | 57d3052 | 2022-08-01 09:54:25 | [diff] [blame] | 113 | if (BT_UNSIGNED) { |
| 114 | off = 0; |
| 115 | } else { |
| 116 | off = aac_cb_maxval[cb]; |
| 117 | } |
| 118 | for (int i = 0; i < size; i += dim) { |
| 119 | const float *vec; |
| 120 | int *quants = s->qcoefs + i; |
| 121 | int curidx = 0; |
| 122 | int curbits; |
| 123 | float quantized, rd = 0.0f; |
| 124 | for (int j = 0; j < dim; j++) { |
| 125 | curidx *= aac_cb_range[cb]; |
| 126 | curidx += quants[j] + off; |
| 127 | } |
| 128 | curbits = ff_aac_spectral_bits[cb-1][curidx]; |
| 129 | vec = &ff_aac_codebook_vectors[cb-1][curidx*dim]; |
| 130 | if (BT_UNSIGNED) { |
| 131 | for (int j = 0; j < dim; j++) { |
| 132 | float t = fabsf(in[i+j]); |
| 133 | float di; |
| 134 | if (BT_ESC && vec[j] == 64.0f) { //FIXME: slow |
| 135 | if (t >= CLIPPED_ESCAPE) { |
| 136 | quantized = CLIPPED_ESCAPE; |
| 137 | curbits += 21; |
| 138 | } else { |
| 139 | int c = av_clip_uintp2(quant(t, Q, ROUNDING), 13); |
| 140 | quantized = c*cbrtf(c)*IQ; |
| 141 | curbits += av_log2(c)*2 - 4 + 1; |
| 142 | } |
| 143 | } else { |
| 144 | quantized = vec[j]*IQ; |
| 145 | } |
| 146 | di = t - quantized; |
| 147 | if (out) |
| 148 | out[i+j] = in[i+j] >= 0 ? quantized : -quantized; |
| 149 | if (vec[j] != 0.0f) |
| 150 | curbits++; |
| 151 | qenergy += quantized*quantized; |
| 152 | rd += di*di; |
| 153 | } |
| 154 | } else { |
| 155 | for (int j = 0; j < dim; j++) { |
| 156 | quantized = vec[j]*IQ; |
| 157 | qenergy += quantized*quantized; |
| 158 | if (out) |
| 159 | out[i+j] = quantized; |
| 160 | rd += (in[i+j] - quantized)*(in[i+j] - quantized); |
| 161 | } |
| 162 | } |
| 163 | cost += rd * lambda + curbits; |
| 164 | resbits += curbits; |
| 165 | if (cost >= uplim) |
| 166 | return uplim; |
| 167 | if (pb) { |
| 168 | put_bits(pb, ff_aac_spectral_bits[cb-1][curidx], ff_aac_spectral_codes[cb-1][curidx]); |
| 169 | if (BT_UNSIGNED) |
| 170 | for (int j = 0; j < dim; j++) |
| 171 | if (ff_aac_codebook_vectors[cb-1][curidx*dim+j] != 0.0f) |
| 172 | put_bits(pb, 1, in[i+j] < 0.0f); |
| 173 | if (BT_ESC) { |
| 174 | for (int j = 0; j < 2; j++) { |
| 175 | if (ff_aac_codebook_vectors[cb-1][curidx*2+j] == 64.0f) { |
| 176 | int coef = av_clip_uintp2(quant(fabsf(in[i+j]), Q, ROUNDING), 13); |
| 177 | int len = av_log2(coef); |
| 178 | |
| 179 | put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2); |
| 180 | put_sbits(pb, len, coef); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | if (bits) |
| 188 | *bits = resbits; |
| 189 | if (energy) |
| 190 | *energy = qenergy; |
| 191 | return cost; |
| 192 | } |
| 193 | |
| 194 | static inline float quantize_and_encode_band_cost_NONE(struct AACEncContext *s, PutBitContext *pb, |
| 195 | const float *in, float *quant, const float *scaled, |
| 196 | int size, int scale_idx, int cb, |
| 197 | const float lambda, const float uplim, |
| 198 | int *bits, float *energy) { |
| 199 | av_assert0(0); |
| 200 | return 0.0f; |
| 201 | } |
| 202 | |
| 203 | #define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE, BT_STEREO, ROUNDING) \ |
| 204 | static float quantize_and_encode_band_cost_ ## NAME( \ |
| 205 | struct AACEncContext *s, \ |
| 206 | PutBitContext *pb, const float *in, float *quant, \ |
| 207 | const float *scaled, int size, int scale_idx, \ |
| 208 | int cb, const float lambda, const float uplim, \ |
| 209 | int *bits, float *energy) { \ |
| 210 | return quantize_and_encode_band_cost_template( \ |
| 211 | s, pb, in, quant, scaled, size, scale_idx, \ |
| 212 | BT_ESC ? ESC_BT : cb, lambda, uplim, bits, energy, \ |
| 213 | BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE, BT_STEREO, \ |
| 214 | ROUNDING); \ |
| 215 | } |
| 216 | |
| 217 | QUANTIZE_AND_ENCODE_BAND_COST_FUNC(ZERO, 1, 0, 0, 0, 0, 0, ROUND_STANDARD) |
| 218 | QUANTIZE_AND_ENCODE_BAND_COST_FUNC(SQUAD, 0, 0, 0, 0, 0, 0, ROUND_STANDARD) |
| 219 | QUANTIZE_AND_ENCODE_BAND_COST_FUNC(UQUAD, 0, 1, 0, 0, 0, 0, ROUND_STANDARD) |
| 220 | QUANTIZE_AND_ENCODE_BAND_COST_FUNC(SPAIR, 0, 0, 1, 0, 0, 0, ROUND_STANDARD) |
| 221 | QUANTIZE_AND_ENCODE_BAND_COST_FUNC(UPAIR, 0, 1, 1, 0, 0, 0, ROUND_STANDARD) |
| 222 | QUANTIZE_AND_ENCODE_BAND_COST_FUNC(ESC, 0, 1, 1, 1, 0, 0, ROUND_STANDARD) |
| 223 | QUANTIZE_AND_ENCODE_BAND_COST_FUNC(ESC_RTZ, 0, 1, 1, 1, 0, 0, ROUND_TO_ZERO) |
| 224 | QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NOISE, 0, 0, 0, 0, 1, 0, ROUND_STANDARD) |
| 225 | QUANTIZE_AND_ENCODE_BAND_COST_FUNC(STEREO,0, 0, 0, 0, 0, 1, ROUND_STANDARD) |
| 226 | |
Andreas Rheinhardt | b71e2e4 | 2022-10-22 12:02:50 | [diff] [blame] | 227 | static const quantize_and_encode_band_func quantize_and_encode_band_cost_arr[] = |
Andreas Rheinhardt | 57d3052 | 2022-08-01 09:54:25 | [diff] [blame] | 228 | { |
| 229 | quantize_and_encode_band_cost_ZERO, |
| 230 | quantize_and_encode_band_cost_SQUAD, |
| 231 | quantize_and_encode_band_cost_SQUAD, |
| 232 | quantize_and_encode_band_cost_UQUAD, |
| 233 | quantize_and_encode_band_cost_UQUAD, |
| 234 | quantize_and_encode_band_cost_SPAIR, |
| 235 | quantize_and_encode_band_cost_SPAIR, |
| 236 | quantize_and_encode_band_cost_UPAIR, |
| 237 | quantize_and_encode_band_cost_UPAIR, |
| 238 | quantize_and_encode_band_cost_UPAIR, |
| 239 | quantize_and_encode_band_cost_UPAIR, |
| 240 | quantize_and_encode_band_cost_ESC, |
| 241 | quantize_and_encode_band_cost_NONE, /* CB 12 doesn't exist */ |
| 242 | quantize_and_encode_band_cost_NOISE, |
| 243 | quantize_and_encode_band_cost_STEREO, |
| 244 | quantize_and_encode_band_cost_STEREO, |
| 245 | }; |
| 246 | |
Andreas Rheinhardt | b71e2e4 | 2022-10-22 12:02:50 | [diff] [blame] | 247 | static const quantize_and_encode_band_func quantize_and_encode_band_cost_rtz_arr[] = |
Andreas Rheinhardt | 57d3052 | 2022-08-01 09:54:25 | [diff] [blame] | 248 | { |
| 249 | quantize_and_encode_band_cost_ZERO, |
| 250 | quantize_and_encode_band_cost_SQUAD, |
| 251 | quantize_and_encode_band_cost_SQUAD, |
| 252 | quantize_and_encode_band_cost_UQUAD, |
| 253 | quantize_and_encode_band_cost_UQUAD, |
| 254 | quantize_and_encode_band_cost_SPAIR, |
| 255 | quantize_and_encode_band_cost_SPAIR, |
| 256 | quantize_and_encode_band_cost_UPAIR, |
| 257 | quantize_and_encode_band_cost_UPAIR, |
| 258 | quantize_and_encode_band_cost_UPAIR, |
| 259 | quantize_and_encode_band_cost_UPAIR, |
| 260 | quantize_and_encode_band_cost_ESC_RTZ, |
| 261 | quantize_and_encode_band_cost_NONE, /* CB 12 doesn't exist */ |
| 262 | quantize_and_encode_band_cost_NOISE, |
| 263 | quantize_and_encode_band_cost_STEREO, |
| 264 | quantize_and_encode_band_cost_STEREO, |
| 265 | }; |
| 266 | |
| 267 | float ff_quantize_and_encode_band_cost(struct AACEncContext *s, PutBitContext *pb, |
| 268 | const float *in, float *quant, const float *scaled, |
| 269 | int size, int scale_idx, int cb, |
| 270 | const float lambda, const float uplim, |
| 271 | int *bits, float *energy) |
| 272 | { |
| 273 | return quantize_and_encode_band_cost_arr[cb](s, pb, in, quant, scaled, size, |
| 274 | scale_idx, cb, lambda, uplim, |
| 275 | bits, energy); |
| 276 | } |
| 277 | |
| 278 | static inline void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, |
| 279 | const float *in, float *out, int size, int scale_idx, |
| 280 | int cb, const float lambda, int rtz) |
| 281 | { |
| 282 | (rtz ? quantize_and_encode_band_cost_rtz_arr : quantize_and_encode_band_cost_arr)[cb](s, pb, in, out, NULL, size, scale_idx, cb, |
| 283 | lambda, INFINITY, NULL, NULL); |
| 284 | } |
| 285 | |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 286 | /** |
| 287 | * structure used in optimal codebook search |
| 288 | */ |
| 289 | typedef struct BandCodingPath { |
| 290 | int prev_idx; ///< pointer to the previous path point |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 291 | float cost; ///< path cost |
| 292 | int run; |
| 293 | } BandCodingPath; |
| 294 | |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 295 | typedef struct TrellisPath { |
| 296 | float cost; |
| 297 | int prev; |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 298 | } TrellisPath; |
| 299 | |
Alex Converse | f5e82fe | 2009-09-21 04:32:51 | [diff] [blame] | 300 | #define TRELLIS_STAGES 121 |
Alex Converse | 144c5e3 | 2010-05-25 18:28:18 | [diff] [blame] | 301 | #define TRELLIS_STATES (SCALE_MAX_DIFF+1) |
Alex Converse | f5e82fe | 2009-09-21 04:32:51 | [diff] [blame] | 302 | |
Rostislav Pehlivanov | 7c10b87 | 2015-06-26 20:16:34 | [diff] [blame] | 303 | static void set_special_band_scalefactors(AACEncContext *s, SingleChannelElement *sce) |
| 304 | { |
Claudio Freire | 60a76f8 | 2016-01-16 23:44:36 | [diff] [blame] | 305 | int w, g; |
| 306 | int prevscaler_n = -255, prevscaler_i = 0; |
Rostislav Pehlivanov | 7c10b87 | 2015-06-26 20:16:34 | [diff] [blame] | 307 | int bands = 0; |
| 308 | |
| 309 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
Rostislav Pehlivanov | 6612d04 | 2016-08-13 16:34:58 | [diff] [blame] | 310 | for (g = 0; g < sce->ics.num_swb; g++) { |
Claudio Freire | 60a76f8 | 2016-01-16 23:44:36 | [diff] [blame] | 311 | if (sce->zeroes[w*16+g]) |
| 312 | continue; |
Rostislav Pehlivanov | 7c10b87 | 2015-06-26 20:16:34 | [diff] [blame] | 313 | if (sce->band_type[w*16+g] == INTENSITY_BT || sce->band_type[w*16+g] == INTENSITY_BT2) { |
Rostislav Pehlivanov | b9b1fd1 | 2015-09-06 14:07:29 | [diff] [blame] | 314 | sce->sf_idx[w*16+g] = av_clip(roundf(log2f(sce->is_ener[w*16+g])*2), -155, 100); |
Rostislav Pehlivanov | 7c10b87 | 2015-06-26 20:16:34 | [diff] [blame] | 315 | bands++; |
| 316 | } else if (sce->band_type[w*16+g] == NOISE_BT) { |
Rostislav Pehlivanov | da64bd6 | 2015-09-09 09:44:33 | [diff] [blame] | 317 | sce->sf_idx[w*16+g] = av_clip(3+ceilf(log2f(sce->pns_ener[w*16+g])*2), -100, 155); |
Claudio Freire | 60a76f8 | 2016-01-16 23:44:36 | [diff] [blame] | 318 | if (prevscaler_n == -255) |
| 319 | prevscaler_n = sce->sf_idx[w*16+g]; |
Rostislav Pehlivanov | 7c10b87 | 2015-06-26 20:16:34 | [diff] [blame] | 320 | bands++; |
| 321 | } |
Rostislav Pehlivanov | 7c10b87 | 2015-06-26 20:16:34 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | if (!bands) |
| 326 | return; |
| 327 | |
| 328 | /* Clip the scalefactor indices */ |
| 329 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
Rostislav Pehlivanov | 6612d04 | 2016-08-13 16:34:58 | [diff] [blame] | 330 | for (g = 0; g < sce->ics.num_swb; g++) { |
Claudio Freire | 60a76f8 | 2016-01-16 23:44:36 | [diff] [blame] | 331 | if (sce->zeroes[w*16+g]) |
| 332 | continue; |
Rostislav Pehlivanov | 7c10b87 | 2015-06-26 20:16:34 | [diff] [blame] | 333 | if (sce->band_type[w*16+g] == INTENSITY_BT || sce->band_type[w*16+g] == INTENSITY_BT2) { |
Claudio Freire | 60a76f8 | 2016-01-16 23:44:36 | [diff] [blame] | 334 | sce->sf_idx[w*16+g] = prevscaler_i = av_clip(sce->sf_idx[w*16+g], prevscaler_i - SCALE_MAX_DIFF, prevscaler_i + SCALE_MAX_DIFF); |
Rostislav Pehlivanov | 7c10b87 | 2015-06-26 20:16:34 | [diff] [blame] | 335 | } else if (sce->band_type[w*16+g] == NOISE_BT) { |
Claudio Freire | 60a76f8 | 2016-01-16 23:44:36 | [diff] [blame] | 336 | sce->sf_idx[w*16+g] = prevscaler_n = av_clip(sce->sf_idx[w*16+g], prevscaler_n - SCALE_MAX_DIFF, prevscaler_n + SCALE_MAX_DIFF); |
Rostislav Pehlivanov | 7c10b87 | 2015-06-26 20:16:34 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 342 | static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s, |
Diego Biurrun | 99d61d3 | 2009-07-08 21:16:06 | [diff] [blame] | 343 | SingleChannelElement *sce, |
| 344 | const float lambda) |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 345 | { |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 346 | int start = 0, i, w, w2, g; |
Anton Khirnov | 494760f | 2013-05-07 05:20:32 | [diff] [blame] | 347 | int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->ch_layout.nb_channels * (lambda / 120.f); |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 348 | float dists[128] = { 0 }, uplims[128] = { 0 }; |
| 349 | float maxvals[128]; |
| 350 | int fflag, minscaler; |
| 351 | int its = 0; |
| 352 | int allz = 0; |
| 353 | float minthr = INFINITY; |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 354 | |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 355 | // for values above this the decoder might end up in an endless loop |
| 356 | // due to always having more bits than what can be encoded. |
| 357 | destbits = FFMIN(destbits, 5800); |
Rostislav Pehlivanov | 6612d04 | 2016-08-13 16:34:58 | [diff] [blame] | 358 | //some heuristic to determine initial quantizers will reduce search time |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 359 | //determine zero bands and upper limits |
Alex Converse | fd257dc | 2009-07-08 20:36:45 | [diff] [blame] | 360 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 361 | start = 0; |
Rostislav Pehlivanov | 6612d04 | 2016-08-13 16:34:58 | [diff] [blame] | 362 | for (g = 0; g < sce->ics.num_swb; g++) { |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 363 | int nz = 0; |
Andreas Rheinhardt | 01d158d | 2021-12-01 14:22:05 | [diff] [blame] | 364 | float uplim = 0.0f; |
Alex Converse | fd257dc | 2009-07-08 20:36:45 | [diff] [blame] | 365 | for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { |
Nathan Caldwell | 0bc01cc | 2011-06-15 08:50:25 | [diff] [blame] | 366 | FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 367 | uplim += band->threshold; |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 368 | if (band->energy <= band->threshold || band->threshold == 0.0f) { |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 369 | sce->zeroes[(w+w2)*16+g] = 1; |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 370 | continue; |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 371 | } |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 372 | nz = 1; |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 373 | } |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 374 | uplims[w*16+g] = uplim *512; |
| 375 | sce->band_type[w*16+g] = 0; |
| 376 | sce->zeroes[w*16+g] = !nz; |
| 377 | if (nz) |
| 378 | minthr = FFMIN(minthr, uplim); |
| 379 | allz |= nz; |
| 380 | start += sce->ics.swb_sizes[g]; |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 381 | } |
| 382 | } |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 383 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
Rostislav Pehlivanov | 6612d04 | 2016-08-13 16:34:58 | [diff] [blame] | 384 | for (g = 0; g < sce->ics.num_swb; g++) { |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 385 | if (sce->zeroes[w*16+g]) { |
| 386 | sce->sf_idx[w*16+g] = SCALE_ONE_POS; |
| 387 | continue; |
| 388 | } |
| 389 | sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2f(uplims[w*16+g]/minthr)*4,59); |
| 390 | } |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 391 | } |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 392 | |
| 393 | if (!allz) |
| 394 | return; |
Andreas Rheinhardt | 88b3b09 | 2024-02-28 12:29:19 | [diff] [blame] | 395 | s->aacdsp.abs_pow34(s->scoefs, sce->coeffs, 1024); |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 396 | ff_quantize_band_cost_cache_init(s); |
| 397 | |
| 398 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
| 399 | start = w*128; |
Rostislav Pehlivanov | 6612d04 | 2016-08-13 16:34:58 | [diff] [blame] | 400 | for (g = 0; g < sce->ics.num_swb; g++) { |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 401 | const float *scaled = s->scoefs + start; |
| 402 | maxvals[w*16+g] = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled); |
| 403 | start += sce->ics.swb_sizes[g]; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | //perform two-loop search |
| 408 | //outer loop - improve quality |
| 409 | do { |
| 410 | int tbits, qstep; |
| 411 | minscaler = sce->sf_idx[0]; |
| 412 | //inner loop - quantize spectrum to fit into given number of bits |
| 413 | qstep = its ? 1 : 32; |
| 414 | do { |
| 415 | int prev = -1; |
| 416 | tbits = 0; |
| 417 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
| 418 | start = w*128; |
Rostislav Pehlivanov | 6612d04 | 2016-08-13 16:34:58 | [diff] [blame] | 419 | for (g = 0; g < sce->ics.num_swb; g++) { |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 420 | const float *coefs = sce->coeffs + start; |
| 421 | const float *scaled = s->scoefs + start; |
| 422 | int bits = 0; |
| 423 | int cb; |
| 424 | float dist = 0.0f; |
| 425 | |
| 426 | if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) { |
| 427 | start += sce->ics.swb_sizes[g]; |
| 428 | continue; |
| 429 | } |
| 430 | minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]); |
| 431 | cb = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]); |
| 432 | for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { |
| 433 | int b; |
| 434 | dist += quantize_band_cost_cached(s, w + w2, g, |
| 435 | coefs + w2*128, |
| 436 | scaled + w2*128, |
| 437 | sce->ics.swb_sizes[g], |
| 438 | sce->sf_idx[w*16+g], |
| 439 | cb, 1.0f, INFINITY, |
| 440 | &b, NULL, 0); |
| 441 | bits += b; |
| 442 | } |
| 443 | dists[w*16+g] = dist - bits; |
| 444 | if (prev != -1) { |
| 445 | bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO]; |
| 446 | } |
| 447 | tbits += bits; |
| 448 | start += sce->ics.swb_sizes[g]; |
| 449 | prev = sce->sf_idx[w*16+g]; |
| 450 | } |
| 451 | } |
| 452 | if (tbits > destbits) { |
| 453 | for (i = 0; i < 128; i++) |
| 454 | if (sce->sf_idx[i] < 218 - qstep) |
| 455 | sce->sf_idx[i] += qstep; |
| 456 | } else { |
| 457 | for (i = 0; i < 128; i++) |
| 458 | if (sce->sf_idx[i] > 60 - qstep) |
| 459 | sce->sf_idx[i] -= qstep; |
| 460 | } |
| 461 | qstep >>= 1; |
| 462 | if (!qstep && tbits > destbits*1.02 && sce->sf_idx[0] < 217) |
| 463 | qstep = 1; |
| 464 | } while (qstep); |
| 465 | |
| 466 | fflag = 0; |
| 467 | minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF); |
| 468 | |
| 469 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
| 470 | for (g = 0; g < sce->ics.num_swb; g++) { |
| 471 | int prevsc = sce->sf_idx[w*16+g]; |
| 472 | if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60) { |
| 473 | if (find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]-1)) |
| 474 | sce->sf_idx[w*16+g]--; |
| 475 | else //Try to make sure there is some energy in every band |
| 476 | sce->sf_idx[w*16+g]-=2; |
| 477 | } |
| 478 | sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler, minscaler + SCALE_MAX_DIFF); |
| 479 | sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219); |
| 480 | if (sce->sf_idx[w*16+g] != prevsc) |
| 481 | fflag = 1; |
| 482 | sce->band_type[w*16+g] = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]); |
| 483 | } |
| 484 | } |
| 485 | its++; |
| 486 | } while (fflag && its < 10); |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 487 | } |
| 488 | |
Rostislav Pehlivanov | 6d17515 | 2015-07-29 04:44:24 | [diff] [blame] | 489 | static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce) |
Rostislav Pehlivanov | 38fd4c2 | 2015-07-02 18:13:05 | [diff] [blame] | 490 | { |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 491 | FFPsyBand *band; |
Rostislav Pehlivanov | da64bd6 | 2015-09-09 09:44:33 | [diff] [blame] | 492 | int w, g, w2, i; |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 493 | int wlen = 1024 / sce->ics.num_windows; |
| 494 | int bandwidth, cutoff; |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 495 | float *PNS = &s->scoefs[0*128], *PNS34 = &s->scoefs[1*128]; |
| 496 | float *NOR34 = &s->scoefs[3*128]; |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 497 | uint8_t nextband[128]; |
Rostislav Pehlivanov | 6d17515 | 2015-07-29 04:44:24 | [diff] [blame] | 498 | const float lambda = s->lambda; |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 499 | const float freq_mult = avctx->sample_rate*0.5f/wlen; |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 500 | const float thr_mult = NOISE_LAMBDA_REPLACE*(100.0f/lambda); |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 501 | const float spread_threshold = FFMIN(0.75f, NOISE_SPREAD_THRESHOLD*FFMAX(0.5f, lambda/100.f)); |
| 502 | const float dist_bias = av_clipf(4.f * 120 / lambda, 0.25f, 4.0f); |
| 503 | const float pns_transient_energy_r = FFMIN(0.7f, lambda / 140.f); |
| 504 | |
| 505 | int refbits = avctx->bit_rate * 1024.0 / avctx->sample_rate |
Anton Khirnov | 494760f | 2013-05-07 05:20:32 | [diff] [blame] | 506 | / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->ch_layout.nb_channels) |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 507 | * (lambda / 120.f); |
| 508 | |
| 509 | /** Keep this in sync with twoloop's cutoff selection */ |
| 510 | float rate_bandwidth_multiplier = 1.5f; |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 511 | int prev = -1000, prev_sf = -1; |
James Almer | f5c8d00 | 2017-03-26 00:35:15 | [diff] [blame] | 512 | int frame_bit_rate = (avctx->flags & AV_CODEC_FLAG_QSCALE) |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 513 | ? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024) |
Anton Khirnov | 494760f | 2013-05-07 05:20:32 | [diff] [blame] | 514 | : (avctx->bit_rate / avctx->ch_layout.nb_channels); |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 515 | |
| 516 | frame_bit_rate *= 1.15f; |
| 517 | |
| 518 | if (avctx->cutoff > 0) { |
| 519 | bandwidth = avctx->cutoff; |
| 520 | } else { |
| 521 | bandwidth = FFMAX(3000, AAC_CUTOFF_FROM_BITRATE(frame_bit_rate, 1, avctx->sample_rate)); |
| 522 | } |
| 523 | |
| 524 | cutoff = bandwidth * 2 * wlen / avctx->sample_rate; |
Rostislav Pehlivanov | 38fd4c2 | 2015-07-02 18:13:05 | [diff] [blame] | 525 | |
Claudio Freire | 9458a62 | 2015-09-25 06:56:32 | [diff] [blame] | 526 | memcpy(sce->band_alt, sce->band_type, sizeof(sce->band_type)); |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 527 | ff_init_nextband_map(sce, nextband); |
Rostislav Pehlivanov | 38fd4c2 | 2015-07-02 18:13:05 | [diff] [blame] | 528 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
Claudio Freire | 0f98fd3 | 2015-09-26 07:49:16 | [diff] [blame] | 529 | int wstart = w*128; |
Rostislav Pehlivanov | 6612d04 | 2016-08-13 16:34:58 | [diff] [blame] | 530 | for (g = 0; g < sce->ics.num_swb; g++) { |
Rostislav Pehlivanov | da64bd6 | 2015-09-09 09:44:33 | [diff] [blame] | 531 | int noise_sfi; |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 532 | float dist1 = 0.0f, dist2 = 0.0f, noise_amp; |
Claudio Freire | 9458a62 | 2015-09-25 06:56:32 | [diff] [blame] | 533 | float pns_energy = 0.0f, pns_tgt_energy, energy_ratio, dist_thresh; |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 534 | float sfb_energy = 0.0f, threshold = 0.0f, spread = 2.0f; |
| 535 | float min_energy = -1.0f, max_energy = 0.0f; |
Claudio Freire | 0f98fd3 | 2015-09-26 07:49:16 | [diff] [blame] | 536 | const int start = wstart+sce->ics.swb_offset[g]; |
Claudio Freire | 9458a62 | 2015-09-25 06:56:32 | [diff] [blame] | 537 | const float freq = (start-wstart)*freq_mult; |
Rostislav Pehlivanov | da64bd6 | 2015-09-09 09:44:33 | [diff] [blame] | 538 | const float freq_boost = FFMAX(0.88f*freq/NOISE_LOW_LIMIT, 1.0f); |
Claudio Freire | 00d481b | 2016-01-08 07:39:02 | [diff] [blame] | 539 | if (freq < NOISE_LOW_LIMIT || (start-wstart) >= cutoff) { |
| 540 | if (!sce->zeroes[w*16+g]) |
| 541 | prev_sf = sce->sf_idx[w*16+g]; |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 542 | continue; |
Claudio Freire | 00d481b | 2016-01-08 07:39:02 | [diff] [blame] | 543 | } |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 544 | for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { |
| 545 | band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; |
Rostislav Pehlivanov | b6cc8ec | 2015-09-07 11:39:04 | [diff] [blame] | 546 | sfb_energy += band->energy; |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 547 | spread = FFMIN(spread, band->spread); |
Rostislav Pehlivanov | b6cc8ec | 2015-09-07 11:39:04 | [diff] [blame] | 548 | threshold += band->threshold; |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 549 | if (!w2) { |
| 550 | min_energy = max_energy = band->energy; |
| 551 | } else { |
| 552 | min_energy = FFMIN(min_energy, band->energy); |
| 553 | max_energy = FFMAX(max_energy, band->energy); |
| 554 | } |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 555 | } |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 556 | |
Rostislav Pehlivanov | da64bd6 | 2015-09-09 09:44:33 | [diff] [blame] | 557 | /* Ramps down at ~8000Hz and loosens the dist threshold */ |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 558 | dist_thresh = av_clipf(2.5f*NOISE_LOW_LIMIT/freq, 0.5f, 2.5f) * dist_bias; |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 559 | |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 560 | /* PNS is acceptable when all of these are true: |
| 561 | * 1. high spread energy (noise-like band) |
| 562 | * 2. near-threshold energy (high PE means the random nature of PNS content will be noticed) |
| 563 | * 3. on short window groups, all windows have similar energy (variations in energy would be destroyed by PNS) |
| 564 | * |
| 565 | * At this stage, point 2 is relaxed for zeroed bands near the noise threshold (hole avoidance is more important) |
Claudio Freire | 9458a62 | 2015-09-25 06:56:32 | [diff] [blame] | 566 | */ |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 567 | if ((!sce->zeroes[w*16+g] && !ff_sfdelta_can_remove_band(sce, nextband, prev_sf, w*16+g)) || |
| 568 | ((sce->zeroes[w*16+g] || !sce->band_alt[w*16+g]) && sfb_energy < threshold*sqrtf(1.0f/freq_boost)) || spread < spread_threshold || |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 569 | (!sce->zeroes[w*16+g] && sce->band_alt[w*16+g] && sfb_energy > threshold*thr_mult*freq_boost) || |
| 570 | min_energy < pns_transient_energy_r * max_energy ) { |
Rostislav Pehlivanov | da64bd6 | 2015-09-09 09:44:33 | [diff] [blame] | 571 | sce->pns_ener[w*16+g] = sfb_energy; |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 572 | if (!sce->zeroes[w*16+g]) |
| 573 | prev_sf = sce->sf_idx[w*16+g]; |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 574 | continue; |
| 575 | } |
| 576 | |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 577 | pns_tgt_energy = sfb_energy*FFMIN(1.0f, spread*spread); |
Claudio Freire | 9458a62 | 2015-09-25 06:56:32 | [diff] [blame] | 578 | noise_sfi = av_clip(roundf(log2f(pns_tgt_energy)*2), -100, 155); /* Quantize */ |
Rostislav Pehlivanov | b6cc8ec | 2015-09-07 11:39:04 | [diff] [blame] | 579 | noise_amp = -ff_aac_pow2sf_tab[noise_sfi + POW_SF2_ZERO]; /* Dequantize */ |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 580 | if (prev != -1000) { |
| 581 | int noise_sfdiff = noise_sfi - prev + SCALE_DIFF_ZERO; |
| 582 | if (noise_sfdiff < 0 || noise_sfdiff > 2*SCALE_MAX_DIFF) { |
| 583 | if (!sce->zeroes[w*16+g]) |
| 584 | prev_sf = sce->sf_idx[w*16+g]; |
| 585 | continue; |
| 586 | } |
| 587 | } |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 588 | for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { |
Claudio Freire | 9458a62 | 2015-09-25 06:56:32 | [diff] [blame] | 589 | float band_energy, scale, pns_senergy; |
Claudio Freire | 0f98fd3 | 2015-09-26 07:49:16 | [diff] [blame] | 590 | const int start_c = (w+w2)*128+sce->ics.swb_offset[g]; |
Rostislav Pehlivanov | da64bd6 | 2015-09-09 09:44:33 | [diff] [blame] | 591 | band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; |
Rostislav Pehlivanov | 230178d | 2016-10-08 00:47:04 | [diff] [blame] | 592 | for (i = 0; i < sce->ics.swb_sizes[g]; i++) { |
| 593 | s->random_state = lcg_random(s->random_state); |
| 594 | PNS[i] = s->random_state; |
Rostislav Pehlivanov | ade31b9 | 2015-12-14 18:53:09 | [diff] [blame] | 595 | } |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 596 | band_energy = s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]); |
| 597 | scale = noise_amp/sqrtf(band_energy); |
| 598 | s->fdsp->vector_fmul_scalar(PNS, PNS, scale, sce->ics.swb_sizes[g]); |
Claudio Freire | 9458a62 | 2015-09-25 06:56:32 | [diff] [blame] | 599 | pns_senergy = s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]); |
| 600 | pns_energy += pns_senergy; |
Andreas Rheinhardt | 88b3b09 | 2024-02-28 12:29:19 | [diff] [blame] | 601 | s->aacdsp.abs_pow34(NOR34, &sce->coeffs[start_c], sce->ics.swb_sizes[g]); |
| 602 | s->aacdsp.abs_pow34(PNS34, PNS, sce->ics.swb_sizes[g]); |
Rostislav Pehlivanov | da64bd6 | 2015-09-09 09:44:33 | [diff] [blame] | 603 | dist1 += quantize_band_cost(s, &sce->coeffs[start_c], |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 604 | NOR34, |
| 605 | sce->ics.swb_sizes[g], |
| 606 | sce->sf_idx[(w+w2)*16+g], |
| 607 | sce->band_alt[(w+w2)*16+g], |
Andreas Rheinhardt | 386990a | 2022-08-01 07:45:10 | [diff] [blame] | 608 | lambda/band->threshold, INFINITY, NULL, NULL); |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 609 | /* Estimate rd on average as 5 bits for SF, 4 for the CB, plus spread energy * lambda/thr */ |
| 610 | dist2 += band->energy/(band->spread*band->spread)*lambda*dist_thresh/band->threshold; |
| 611 | } |
Claudio Freire | 124c375 | 2015-12-09 20:36:32 | [diff] [blame] | 612 | if (g && sce->band_type[w*16+g-1] == NOISE_BT) { |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 613 | dist2 += 5; |
| 614 | } else { |
| 615 | dist2 += 9; |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 616 | } |
Claudio Freire | 9458a62 | 2015-09-25 06:56:32 | [diff] [blame] | 617 | energy_ratio = pns_tgt_energy/pns_energy; /* Compensates for quantization error */ |
| 618 | sce->pns_ener[w*16+g] = energy_ratio*pns_tgt_energy; |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 619 | if (sce->zeroes[w*16+g] || !sce->band_alt[w*16+g] || (energy_ratio > 0.85f && energy_ratio < 1.25f && dist2 < dist1)) { |
Rostislav Pehlivanov | 033e589 | 2015-09-06 14:13:18 | [diff] [blame] | 620 | sce->band_type[w*16+g] = NOISE_BT; |
| 621 | sce->zeroes[w*16+g] = 0; |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 622 | prev = noise_sfi; |
Claudio Freire | 4720a56 | 2015-12-22 08:26:12 | [diff] [blame] | 623 | } else { |
| 624 | if (!sce->zeroes[w*16+g]) |
| 625 | prev_sf = sce->sf_idx[w*16+g]; |
Rostislav Pehlivanov | 38fd4c2 | 2015-07-02 18:13:05 | [diff] [blame] | 626 | } |
Rostislav Pehlivanov | 38fd4c2 | 2015-07-02 18:13:05 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 631 | static void mark_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce) |
| 632 | { |
| 633 | FFPsyBand *band; |
| 634 | int w, g, w2; |
| 635 | int wlen = 1024 / sce->ics.num_windows; |
| 636 | int bandwidth, cutoff; |
| 637 | const float lambda = s->lambda; |
| 638 | const float freq_mult = avctx->sample_rate*0.5f/wlen; |
| 639 | const float spread_threshold = FFMIN(0.75f, NOISE_SPREAD_THRESHOLD*FFMAX(0.5f, lambda/100.f)); |
| 640 | const float pns_transient_energy_r = FFMIN(0.7f, lambda / 140.f); |
| 641 | |
| 642 | int refbits = avctx->bit_rate * 1024.0 / avctx->sample_rate |
Anton Khirnov | 494760f | 2013-05-07 05:20:32 | [diff] [blame] | 643 | / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->ch_layout.nb_channels) |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 644 | * (lambda / 120.f); |
| 645 | |
| 646 | /** Keep this in sync with twoloop's cutoff selection */ |
| 647 | float rate_bandwidth_multiplier = 1.5f; |
James Almer | f5c8d00 | 2017-03-26 00:35:15 | [diff] [blame] | 648 | int frame_bit_rate = (avctx->flags & AV_CODEC_FLAG_QSCALE) |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 649 | ? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024) |
Anton Khirnov | 494760f | 2013-05-07 05:20:32 | [diff] [blame] | 650 | : (avctx->bit_rate / avctx->ch_layout.nb_channels); |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 651 | |
| 652 | frame_bit_rate *= 1.15f; |
| 653 | |
| 654 | if (avctx->cutoff > 0) { |
| 655 | bandwidth = avctx->cutoff; |
| 656 | } else { |
| 657 | bandwidth = FFMAX(3000, AAC_CUTOFF_FROM_BITRATE(frame_bit_rate, 1, avctx->sample_rate)); |
| 658 | } |
| 659 | |
| 660 | cutoff = bandwidth * 2 * wlen / avctx->sample_rate; |
| 661 | |
| 662 | memcpy(sce->band_alt, sce->band_type, sizeof(sce->band_type)); |
| 663 | for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { |
Rostislav Pehlivanov | 6612d04 | 2016-08-13 16:34:58 | [diff] [blame] | 664 | for (g = 0; g < sce->ics.num_swb; g++) { |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 665 | float sfb_energy = 0.0f, threshold = 0.0f, spread = 2.0f; |
| 666 | float min_energy = -1.0f, max_energy = 0.0f; |
| 667 | const int start = sce->ics.swb_offset[g]; |
| 668 | const float freq = start*freq_mult; |
| 669 | const float freq_boost = FFMAX(0.88f*freq/NOISE_LOW_LIMIT, 1.0f); |
| 670 | if (freq < NOISE_LOW_LIMIT || start >= cutoff) { |
| 671 | sce->can_pns[w*16+g] = 0; |
| 672 | continue; |
| 673 | } |
| 674 | for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { |
| 675 | band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; |
| 676 | sfb_energy += band->energy; |
| 677 | spread = FFMIN(spread, band->spread); |
| 678 | threshold += band->threshold; |
| 679 | if (!w2) { |
| 680 | min_energy = max_energy = band->energy; |
| 681 | } else { |
| 682 | min_energy = FFMIN(min_energy, band->energy); |
| 683 | max_energy = FFMAX(max_energy, band->energy); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | /* PNS is acceptable when all of these are true: |
| 688 | * 1. high spread energy (noise-like band) |
| 689 | * 2. near-threshold energy (high PE means the random nature of PNS content will be noticed) |
| 690 | * 3. on short window groups, all windows have similar energy (variations in energy would be destroyed by PNS) |
| 691 | */ |
| 692 | sce->pns_ener[w*16+g] = sfb_energy; |
| 693 | if (sfb_energy < threshold*sqrtf(1.5f/freq_boost) || spread < spread_threshold || min_energy < pns_transient_energy_r * max_energy) { |
| 694 | sce->can_pns[w*16+g] = 0; |
| 695 | } else { |
| 696 | sce->can_pns[w*16+g] = 1; |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | } |
| 701 | |
Rostislav Pehlivanov | 6d17515 | 2015-07-29 04:44:24 | [diff] [blame] | 702 | static void search_for_ms(AACEncContext *s, ChannelElement *cpe) |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 703 | { |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 704 | int start = 0, i, w, w2, g, sid_sf_boost, prev_mid, prev_side; |
| 705 | uint8_t nextband0[128], nextband1[128]; |
Rostislav Pehlivanov | d2ae5f7 | 2016-10-08 14:59:14 | [diff] [blame] | 706 | float *M = s->scoefs + 128*0, *S = s->scoefs + 128*1; |
| 707 | float *L34 = s->scoefs + 128*2, *R34 = s->scoefs + 128*3; |
| 708 | float *M34 = s->scoefs + 128*4, *S34 = s->scoefs + 128*5; |
Rostislav Pehlivanov | 6d17515 | 2015-07-29 04:44:24 | [diff] [blame] | 709 | const float lambda = s->lambda; |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 710 | const float mslambda = FFMIN(1.0f, lambda / 120.f); |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 711 | SingleChannelElement *sce0 = &cpe->ch[0]; |
| 712 | SingleChannelElement *sce1 = &cpe->ch[1]; |
Alex Converse | fd257dc | 2009-07-08 20:36:45 | [diff] [blame] | 713 | if (!cpe->common_window) |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 714 | return; |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 715 | |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 716 | /** Scout out next nonzero bands */ |
| 717 | ff_init_nextband_map(sce0, nextband0); |
| 718 | ff_init_nextband_map(sce1, nextband1); |
| 719 | |
| 720 | prev_mid = sce0->sf_idx[0]; |
| 721 | prev_side = sce1->sf_idx[0]; |
| 722 | for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) { |
Rostislav Pehlivanov | 57848ef | 2015-07-02 18:13:02 | [diff] [blame] | 723 | start = 0; |
Rostislav Pehlivanov | 6612d04 | 2016-08-13 16:34:58 | [diff] [blame] | 724 | for (g = 0; g < sce0->ics.num_swb; g++) { |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 725 | float bmax = bval2bmax(g * 17.0f / sce0->ics.num_swb) / 0.0045f; |
Claudio Freire | 6711aa2 | 2016-01-08 08:31:32 | [diff] [blame] | 726 | if (!cpe->is_mask[w*16+g]) |
| 727 | cpe->ms_mask[w*16+g] = 0; |
| 728 | if (!sce0->zeroes[w*16+g] && !sce1->zeroes[w*16+g] && !cpe->is_mask[w*16+g]) { |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 729 | float Mmax = 0.0f, Smax = 0.0f; |
| 730 | |
| 731 | /* Must compute mid/side SF and book for the whole window group */ |
Alex Converse | fd257dc | 2009-07-08 20:36:45 | [diff] [blame] | 732 | for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) { |
Alex Converse | fd257dc | 2009-07-08 20:36:45 | [diff] [blame] | 733 | for (i = 0; i < sce0->ics.swb_sizes[g]; i++) { |
Rostislav Pehlivanov | 32be264 | 2015-08-21 17:30:51 | [diff] [blame] | 734 | M[i] = (sce0->coeffs[start+(w+w2)*128+i] |
| 735 | + sce1->coeffs[start+(w+w2)*128+i]) * 0.5; |
Young Han Lee | 92efa2b | 2011-03-24 01:49:36 | [diff] [blame] | 736 | S[i] = M[i] |
Rostislav Pehlivanov | 32be264 | 2015-08-21 17:30:51 | [diff] [blame] | 737 | - sce1->coeffs[start+(w+w2)*128+i]; |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 738 | } |
Andreas Rheinhardt | 88b3b09 | 2024-02-28 12:29:19 | [diff] [blame] | 739 | s->aacdsp.abs_pow34(M34, M, sce0->ics.swb_sizes[g]); |
| 740 | s->aacdsp.abs_pow34(S34, S, sce0->ics.swb_sizes[g]); |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 741 | for (i = 0; i < sce0->ics.swb_sizes[g]; i++ ) { |
| 742 | Mmax = FFMAX(Mmax, M34[i]); |
| 743 | Smax = FFMAX(Smax, S34[i]); |
| 744 | } |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 745 | } |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 746 | |
| 747 | for (sid_sf_boost = 0; sid_sf_boost < 4; sid_sf_boost++) { |
| 748 | float dist1 = 0.0f, dist2 = 0.0f; |
| 749 | int B0 = 0, B1 = 0; |
| 750 | int minidx; |
| 751 | int mididx, sididx; |
| 752 | int midcb, sidcb; |
| 753 | |
| 754 | minidx = FFMIN(sce0->sf_idx[w*16+g], sce1->sf_idx[w*16+g]); |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 755 | mididx = av_clip(minidx, 0, SCALE_MAX_POS - SCALE_DIV_512); |
| 756 | sididx = av_clip(minidx - sid_sf_boost * 3, 0, SCALE_MAX_POS - SCALE_DIV_512); |
Claudio Freire | 6711aa2 | 2016-01-08 08:31:32 | [diff] [blame] | 757 | if (sce0->band_type[w*16+g] != NOISE_BT && sce1->band_type[w*16+g] != NOISE_BT |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 758 | && ( !ff_sfdelta_can_replace(sce0, nextband0, prev_mid, mididx, w*16+g) |
| 759 | || !ff_sfdelta_can_replace(sce1, nextband1, prev_side, sididx, w*16+g))) { |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 760 | /* scalefactor range violation, bad stuff, will decrease quality unacceptably */ |
| 761 | continue; |
| 762 | } |
| 763 | |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 764 | midcb = find_min_book(Mmax, mididx); |
| 765 | sidcb = find_min_book(Smax, sididx); |
| 766 | |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 767 | /* No CB can be zero */ |
| 768 | midcb = FFMAX(1,midcb); |
| 769 | sidcb = FFMAX(1,sidcb); |
| 770 | |
| 771 | for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) { |
| 772 | FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g]; |
| 773 | FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g]; |
| 774 | float minthr = FFMIN(band0->threshold, band1->threshold); |
| 775 | int b1,b2,b3,b4; |
| 776 | for (i = 0; i < sce0->ics.swb_sizes[g]; i++) { |
| 777 | M[i] = (sce0->coeffs[start+(w+w2)*128+i] |
| 778 | + sce1->coeffs[start+(w+w2)*128+i]) * 0.5; |
| 779 | S[i] = M[i] |
| 780 | - sce1->coeffs[start+(w+w2)*128+i]; |
| 781 | } |
| 782 | |
Andreas Rheinhardt | 88b3b09 | 2024-02-28 12:29:19 | [diff] [blame] | 783 | s->aacdsp.abs_pow34(L34, sce0->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]); |
| 784 | s->aacdsp.abs_pow34(R34, sce1->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]); |
| 785 | s->aacdsp.abs_pow34(M34, M, sce0->ics.swb_sizes[g]); |
| 786 | s->aacdsp.abs_pow34(S34, S, sce0->ics.swb_sizes[g]); |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 787 | dist1 += quantize_band_cost(s, &sce0->coeffs[start + (w+w2)*128], |
| 788 | L34, |
| 789 | sce0->ics.swb_sizes[g], |
Claudio Freire | 6711aa2 | 2016-01-08 08:31:32 | [diff] [blame] | 790 | sce0->sf_idx[w*16+g], |
| 791 | sce0->band_type[w*16+g], |
Andreas Rheinhardt | 386990a | 2022-08-01 07:45:10 | [diff] [blame] | 792 | lambda / (band0->threshold + FLT_MIN), INFINITY, &b1, NULL); |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 793 | dist1 += quantize_band_cost(s, &sce1->coeffs[start + (w+w2)*128], |
| 794 | R34, |
| 795 | sce1->ics.swb_sizes[g], |
Claudio Freire | 6711aa2 | 2016-01-08 08:31:32 | [diff] [blame] | 796 | sce1->sf_idx[w*16+g], |
| 797 | sce1->band_type[w*16+g], |
Andreas Rheinhardt | 386990a | 2022-08-01 07:45:10 | [diff] [blame] | 798 | lambda / (band1->threshold + FLT_MIN), INFINITY, &b2, NULL); |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 799 | dist2 += quantize_band_cost(s, M, |
| 800 | M34, |
| 801 | sce0->ics.swb_sizes[g], |
Claudio Freire | 6711aa2 | 2016-01-08 08:31:32 | [diff] [blame] | 802 | mididx, |
| 803 | midcb, |
Andreas Rheinhardt | 386990a | 2022-08-01 07:45:10 | [diff] [blame] | 804 | lambda / (minthr + FLT_MIN), INFINITY, &b3, NULL); |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 805 | dist2 += quantize_band_cost(s, S, |
| 806 | S34, |
| 807 | sce1->ics.swb_sizes[g], |
Claudio Freire | 6711aa2 | 2016-01-08 08:31:32 | [diff] [blame] | 808 | sididx, |
| 809 | sidcb, |
Andreas Rheinhardt | 386990a | 2022-08-01 07:45:10 | [diff] [blame] | 810 | mslambda / (minthr * bmax + FLT_MIN), INFINITY, &b4, NULL); |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 811 | B0 += b1+b2; |
| 812 | B1 += b3+b4; |
Claudio Freire | 6711aa2 | 2016-01-08 08:31:32 | [diff] [blame] | 813 | dist1 -= b1+b2; |
| 814 | dist2 -= b3+b4; |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 815 | } |
| 816 | cpe->ms_mask[w*16+g] = dist2 <= dist1 && B1 < B0; |
| 817 | if (cpe->ms_mask[w*16+g]) { |
Claudio Freire | 6711aa2 | 2016-01-08 08:31:32 | [diff] [blame] | 818 | if (sce0->band_type[w*16+g] != NOISE_BT && sce1->band_type[w*16+g] != NOISE_BT) { |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 819 | sce0->sf_idx[w*16+g] = mididx; |
| 820 | sce1->sf_idx[w*16+g] = sididx; |
| 821 | sce0->band_type[w*16+g] = midcb; |
| 822 | sce1->band_type[w*16+g] = sidcb; |
Claudio Freire | 6711aa2 | 2016-01-08 08:31:32 | [diff] [blame] | 823 | } else if ((sce0->band_type[w*16+g] != NOISE_BT) ^ (sce1->band_type[w*16+g] != NOISE_BT)) { |
| 824 | /* ms_mask unneeded, and it confuses some decoders */ |
| 825 | cpe->ms_mask[w*16+g] = 0; |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 826 | } |
| 827 | break; |
| 828 | } else if (B1 > B0) { |
| 829 | /* More boost won't fix this */ |
| 830 | break; |
| 831 | } |
| 832 | } |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 833 | } |
Claudio Freire | ca203e9 | 2015-12-01 06:28:36 | [diff] [blame] | 834 | if (!sce0->zeroes[w*16+g] && sce0->band_type[w*16+g] < RESERVED_BT) |
| 835 | prev_mid = sce0->sf_idx[w*16+g]; |
| 836 | if (!sce1->zeroes[w*16+g] && !cpe->is_mask[w*16+g] && sce1->band_type[w*16+g] < RESERVED_BT) |
| 837 | prev_side = sce1->sf_idx[w*16+g]; |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 838 | start += sce0->ics.swb_sizes[g]; |
| 839 | } |
| 840 | } |
| 841 | } |
| 842 | |
James Almer | 318778d | 2017-09-26 18:58:40 | [diff] [blame] | 843 | const AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = { |
Timothy Gu | 4bd910d | 2013-09-11 03:23:32 | [diff] [blame] | 844 | [AAC_CODER_TWOLOOP] = { |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 845 | search_for_quantizers_twoloop, |
Alex Converse | 759510e | 2010-05-14 16:49:51 | [diff] [blame] | 846 | codebook_trellis_rate, |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 847 | quantize_and_encode_band, |
Timothy Gu | 21dd527 | 2015-08-22 05:11:23 | [diff] [blame] | 848 | ff_aac_encode_tns_info, |
Rostislav Pehlivanov | f20b671 | 2015-08-29 05:47:31 | [diff] [blame] | 849 | ff_aac_apply_tns, |
Rostislav Pehlivanov | e06578e | 2015-07-02 18:13:04 | [diff] [blame] | 850 | set_special_band_scalefactors, |
Rostislav Pehlivanov | 38fd4c2 | 2015-07-02 18:13:05 | [diff] [blame] | 851 | search_for_pns, |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 852 | mark_pns, |
Timothy Gu | 21dd527 | 2015-08-22 05:11:23 | [diff] [blame] | 853 | ff_aac_search_for_tns, |
Alex Converse | dd0e43e | 2009-08-27 17:46:13 | [diff] [blame] | 854 | search_for_ms, |
Timothy Gu | 21dd527 | 2015-08-22 05:11:23 | [diff] [blame] | 855 | ff_aac_search_for_is, |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 856 | }, |
Timothy Gu | 4bd910d | 2013-09-11 03:23:32 | [diff] [blame] | 857 | [AAC_CODER_FAST] = { |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 858 | search_for_quantizers_fast, |
Rostislav Pehlivanov | c92cc2d | 2016-08-06 23:47:31 | [diff] [blame] | 859 | codebook_trellis_rate, |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 860 | quantize_and_encode_band, |
Timothy Gu | 21dd527 | 2015-08-22 05:11:23 | [diff] [blame] | 861 | ff_aac_encode_tns_info, |
Rostislav Pehlivanov | f20b671 | 2015-08-29 05:47:31 | [diff] [blame] | 862 | ff_aac_apply_tns, |
Rostislav Pehlivanov | e06578e | 2015-07-02 18:13:04 | [diff] [blame] | 863 | set_special_band_scalefactors, |
Rostislav Pehlivanov | 38fd4c2 | 2015-07-02 18:13:05 | [diff] [blame] | 864 | search_for_pns, |
Claudio Freire | 01ecb71 | 2015-10-11 20:29:50 | [diff] [blame] | 865 | mark_pns, |
Timothy Gu | 21dd527 | 2015-08-22 05:11:23 | [diff] [blame] | 866 | ff_aac_search_for_tns, |
Alex Converse | dd0e43e | 2009-08-27 17:46:13 | [diff] [blame] | 867 | search_for_ms, |
Timothy Gu | 21dd527 | 2015-08-22 05:11:23 | [diff] [blame] | 868 | ff_aac_search_for_is, |
Alex Converse | 78e65cd | 2009-07-08 20:01:31 | [diff] [blame] | 869 | }, |
| 870 | }; |