You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1081 lines
43KB

  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. * @file
  23. * AAC coefficients encoder
  24. */
  25. /***********************************
  26. * TODOs:
  27. * speedup quantizer selection
  28. * add sane pulse detection
  29. ***********************************/
  30. #include "libavutil/libm.h" // brought forward to work around cygwin header breakage
  31. #include <float.h>
  32. #include "libavutil/mathematics.h"
  33. #include "avcodec.h"
  34. #include "put_bits.h"
  35. #include "aac.h"
  36. #include "aacenc.h"
  37. #include "aactab.h"
  38. #include "aacenctab.h"
  39. #include "aacenc_utils.h"
  40. #include "aacenc_quantization.h"
  41. #include "aac_tablegen_decl.h"
  42. #include "aacenc_is.h"
  43. #include "aacenc_tns.h"
  44. #include "aacenc_pred.h"
  45. /** Frequency in Hz for lower limit of noise substitution **/
  46. #define NOISE_LOW_LIMIT 4000
  47. /* Parameter of f(x) = a*(lambda/100), defines the maximum fourier spread
  48. * beyond which no PNS is used (since the SFBs contain tone rather than noise) */
  49. #define NOISE_SPREAD_THRESHOLD 0.9673f
  50. /* Parameter of f(x) = a*(100/lambda), defines how much PNS is allowed to
  51. * replace low energy non zero bands */
  52. #define NOISE_LAMBDA_REPLACE 1.948f
  53. /**
  54. * structure used in optimal codebook search
  55. */
  56. typedef struct BandCodingPath {
  57. int prev_idx; ///< pointer to the previous path point
  58. float cost; ///< path cost
  59. int run;
  60. } BandCodingPath;
  61. /**
  62. * Encode band info for single window group bands.
  63. */
  64. static void encode_window_bands_info(AACEncContext *s, SingleChannelElement *sce,
  65. int win, int group_len, const float lambda)
  66. {
  67. BandCodingPath path[120][CB_TOT_ALL];
  68. int w, swb, cb, start, size;
  69. int i, j;
  70. const int max_sfb = sce->ics.max_sfb;
  71. const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;
  72. const int run_esc = (1 << run_bits) - 1;
  73. int idx, ppos, count;
  74. int stackrun[120], stackcb[120], stack_len;
  75. float next_minrd = INFINITY;
  76. int next_mincb = 0;
  77. abs_pow34_v(s->scoefs, sce->coeffs, 1024);
  78. start = win*128;
  79. for (cb = 0; cb < CB_TOT_ALL; cb++) {
  80. path[0][cb].cost = 0.0f;
  81. path[0][cb].prev_idx = -1;
  82. path[0][cb].run = 0;
  83. }
  84. for (swb = 0; swb < max_sfb; swb++) {
  85. size = sce->ics.swb_sizes[swb];
  86. if (sce->zeroes[win*16 + swb]) {
  87. for (cb = 0; cb < CB_TOT_ALL; cb++) {
  88. path[swb+1][cb].prev_idx = cb;
  89. path[swb+1][cb].cost = path[swb][cb].cost;
  90. path[swb+1][cb].run = path[swb][cb].run + 1;
  91. }
  92. } else {
  93. float minrd = next_minrd;
  94. int mincb = next_mincb;
  95. next_minrd = INFINITY;
  96. next_mincb = 0;
  97. for (cb = 0; cb < CB_TOT_ALL; cb++) {
  98. float cost_stay_here, cost_get_here;
  99. float rd = 0.0f;
  100. if (cb >= 12 && sce->band_type[win*16+swb] < aac_cb_out_map[cb] ||
  101. cb < aac_cb_in_map[sce->band_type[win*16+swb]] && sce->band_type[win*16+swb] > aac_cb_out_map[cb]) {
  102. path[swb+1][cb].prev_idx = -1;
  103. path[swb+1][cb].cost = INFINITY;
  104. path[swb+1][cb].run = path[swb][cb].run + 1;
  105. continue;
  106. }
  107. for (w = 0; w < group_len; w++) {
  108. FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(win+w)*16+swb];
  109. rd += quantize_band_cost(s, &sce->coeffs[start + w*128],
  110. &s->scoefs[start + w*128], size,
  111. sce->sf_idx[(win+w)*16+swb], aac_cb_out_map[cb],
  112. lambda / band->threshold, INFINITY, NULL, 0);
  113. }
  114. cost_stay_here = path[swb][cb].cost + rd;
  115. cost_get_here = minrd + rd + run_bits + 4;
  116. if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]
  117. != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])
  118. cost_stay_here += run_bits;
  119. if (cost_get_here < cost_stay_here) {
  120. path[swb+1][cb].prev_idx = mincb;
  121. path[swb+1][cb].cost = cost_get_here;
  122. path[swb+1][cb].run = 1;
  123. } else {
  124. path[swb+1][cb].prev_idx = cb;
  125. path[swb+1][cb].cost = cost_stay_here;
  126. path[swb+1][cb].run = path[swb][cb].run + 1;
  127. }
  128. if (path[swb+1][cb].cost < next_minrd) {
  129. next_minrd = path[swb+1][cb].cost;
  130. next_mincb = cb;
  131. }
  132. }
  133. }
  134. start += sce->ics.swb_sizes[swb];
  135. }
  136. //convert resulting path from backward-linked list
  137. stack_len = 0;
  138. idx = 0;
  139. for (cb = 1; cb < CB_TOT_ALL; cb++)
  140. if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
  141. idx = cb;
  142. ppos = max_sfb;
  143. while (ppos > 0) {
  144. av_assert1(idx >= 0);
  145. cb = idx;
  146. stackrun[stack_len] = path[ppos][cb].run;
  147. stackcb [stack_len] = cb;
  148. idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx;
  149. ppos -= path[ppos][cb].run;
  150. stack_len++;
  151. }
  152. //perform actual band info encoding
  153. start = 0;
  154. for (i = stack_len - 1; i >= 0; i--) {
  155. cb = aac_cb_out_map[stackcb[i]];
  156. put_bits(&s->pb, 4, cb);
  157. count = stackrun[i];
  158. memset(sce->zeroes + win*16 + start, !cb, count);
  159. //XXX: memset when band_type is also uint8_t
  160. for (j = 0; j < count; j++) {
  161. sce->band_type[win*16 + start] = cb;
  162. start++;
  163. }
  164. while (count >= run_esc) {
  165. put_bits(&s->pb, run_bits, run_esc);
  166. count -= run_esc;
  167. }
  168. put_bits(&s->pb, run_bits, count);
  169. }
  170. }
  171. static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce,
  172. int win, int group_len, const float lambda)
  173. {
  174. BandCodingPath path[120][CB_TOT_ALL];
  175. int w, swb, cb, start, size;
  176. int i, j;
  177. const int max_sfb = sce->ics.max_sfb;
  178. const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;
  179. const int run_esc = (1 << run_bits) - 1;
  180. int idx, ppos, count;
  181. int stackrun[120], stackcb[120], stack_len;
  182. float next_minbits = INFINITY;
  183. int next_mincb = 0;
  184. abs_pow34_v(s->scoefs, sce->coeffs, 1024);
  185. start = win*128;
  186. for (cb = 0; cb < CB_TOT_ALL; cb++) {
  187. path[0][cb].cost = run_bits+4;
  188. path[0][cb].prev_idx = -1;
  189. path[0][cb].run = 0;
  190. }
  191. for (swb = 0; swb < max_sfb; swb++) {
  192. size = sce->ics.swb_sizes[swb];
  193. if (sce->zeroes[win*16 + swb]) {
  194. float cost_stay_here = path[swb][0].cost;
  195. float cost_get_here = next_minbits + run_bits + 4;
  196. if ( run_value_bits[sce->ics.num_windows == 8][path[swb][0].run]
  197. != run_value_bits[sce->ics.num_windows == 8][path[swb][0].run+1])
  198. cost_stay_here += run_bits;
  199. if (cost_get_here < cost_stay_here) {
  200. path[swb+1][0].prev_idx = next_mincb;
  201. path[swb+1][0].cost = cost_get_here;
  202. path[swb+1][0].run = 1;
  203. } else {
  204. path[swb+1][0].prev_idx = 0;
  205. path[swb+1][0].cost = cost_stay_here;
  206. path[swb+1][0].run = path[swb][0].run + 1;
  207. }
  208. next_minbits = path[swb+1][0].cost;
  209. next_mincb = 0;
  210. for (cb = 1; cb < CB_TOT_ALL; cb++) {
  211. path[swb+1][cb].cost = 61450;
  212. path[swb+1][cb].prev_idx = -1;
  213. path[swb+1][cb].run = 0;
  214. }
  215. } else {
  216. float minbits = next_minbits;
  217. int mincb = next_mincb;
  218. int startcb = sce->band_type[win*16+swb];
  219. startcb = aac_cb_in_map[startcb];
  220. next_minbits = INFINITY;
  221. next_mincb = 0;
  222. for (cb = 0; cb < startcb; cb++) {
  223. path[swb+1][cb].cost = 61450;
  224. path[swb+1][cb].prev_idx = -1;
  225. path[swb+1][cb].run = 0;
  226. }
  227. for (cb = startcb; cb < CB_TOT_ALL; cb++) {
  228. float cost_stay_here, cost_get_here;
  229. float bits = 0.0f;
  230. if (cb >= 12 && sce->band_type[win*16+swb] != aac_cb_out_map[cb]) {
  231. path[swb+1][cb].cost = 61450;
  232. path[swb+1][cb].prev_idx = -1;
  233. path[swb+1][cb].run = 0;
  234. continue;
  235. }
  236. for (w = 0; w < group_len; w++) {
  237. bits += quantize_band_cost(s, &sce->coeffs[start + w*128],
  238. &s->scoefs[start + w*128], size,
  239. sce->sf_idx[win*16+swb],
  240. aac_cb_out_map[cb],
  241. 0, INFINITY, NULL, 0);
  242. }
  243. cost_stay_here = path[swb][cb].cost + bits;
  244. cost_get_here = minbits + bits + run_bits + 4;
  245. if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]
  246. != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])
  247. cost_stay_here += run_bits;
  248. if (cost_get_here < cost_stay_here) {
  249. path[swb+1][cb].prev_idx = mincb;
  250. path[swb+1][cb].cost = cost_get_here;
  251. path[swb+1][cb].run = 1;
  252. } else {
  253. path[swb+1][cb].prev_idx = cb;
  254. path[swb+1][cb].cost = cost_stay_here;
  255. path[swb+1][cb].run = path[swb][cb].run + 1;
  256. }
  257. if (path[swb+1][cb].cost < next_minbits) {
  258. next_minbits = path[swb+1][cb].cost;
  259. next_mincb = cb;
  260. }
  261. }
  262. }
  263. start += sce->ics.swb_sizes[swb];
  264. }
  265. //convert resulting path from backward-linked list
  266. stack_len = 0;
  267. idx = 0;
  268. for (cb = 1; cb < CB_TOT_ALL; cb++)
  269. if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
  270. idx = cb;
  271. ppos = max_sfb;
  272. while (ppos > 0) {
  273. av_assert1(idx >= 0);
  274. cb = idx;
  275. stackrun[stack_len] = path[ppos][cb].run;
  276. stackcb [stack_len] = cb;
  277. idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx;
  278. ppos -= path[ppos][cb].run;
  279. stack_len++;
  280. }
  281. //perform actual band info encoding
  282. start = 0;
  283. for (i = stack_len - 1; i >= 0; i--) {
  284. cb = aac_cb_out_map[stackcb[i]];
  285. put_bits(&s->pb, 4, cb);
  286. count = stackrun[i];
  287. memset(sce->zeroes + win*16 + start, !cb, count);
  288. //XXX: memset when band_type is also uint8_t
  289. for (j = 0; j < count; j++) {
  290. sce->band_type[win*16 + start] = cb;
  291. start++;
  292. }
  293. while (count >= run_esc) {
  294. put_bits(&s->pb, run_bits, run_esc);
  295. count -= run_esc;
  296. }
  297. put_bits(&s->pb, run_bits, count);
  298. }
  299. }
  300. typedef struct TrellisPath {
  301. float cost;
  302. int prev;
  303. } TrellisPath;
  304. #define TRELLIS_STAGES 121
  305. #define TRELLIS_STATES (SCALE_MAX_DIFF+1)
  306. static void set_special_band_scalefactors(AACEncContext *s, SingleChannelElement *sce)
  307. {
  308. int w, g, start = 0;
  309. int minscaler_n = sce->sf_idx[0], minscaler_i = sce->sf_idx[0];
  310. int bands = 0;
  311. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  312. start = 0;
  313. for (g = 0; g < sce->ics.num_swb; g++) {
  314. if (sce->band_type[w*16+g] == INTENSITY_BT || sce->band_type[w*16+g] == INTENSITY_BT2) {
  315. sce->sf_idx[w*16+g] = av_clip(roundf(log2f(sce->is_ener[w*16+g])*2), -155, 100);
  316. minscaler_i = FFMIN(minscaler_i, sce->sf_idx[w*16+g]);
  317. bands++;
  318. } else if (sce->band_type[w*16+g] == NOISE_BT) {
  319. sce->sf_idx[w*16+g] = av_clip(roundf(log2f(sce->pns_ener[w*16+g])*2), -100, 155);
  320. minscaler_n = FFMIN(minscaler_n, sce->sf_idx[w*16+g]);
  321. bands++;
  322. }
  323. start += sce->ics.swb_sizes[g];
  324. }
  325. }
  326. if (!bands)
  327. return;
  328. /* Clip the scalefactor indices */
  329. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  330. for (g = 0; g < sce->ics.num_swb; g++) {
  331. if (sce->band_type[w*16+g] == INTENSITY_BT || sce->band_type[w*16+g] == INTENSITY_BT2) {
  332. sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler_i, minscaler_i + SCALE_MAX_DIFF);
  333. } else if (sce->band_type[w*16+g] == NOISE_BT) {
  334. sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler_n, minscaler_n + SCALE_MAX_DIFF);
  335. }
  336. }
  337. }
  338. }
  339. static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s,
  340. SingleChannelElement *sce,
  341. const float lambda)
  342. {
  343. int q, w, w2, g, start = 0;
  344. int i, j;
  345. int idx;
  346. TrellisPath paths[TRELLIS_STAGES][TRELLIS_STATES];
  347. int bandaddr[TRELLIS_STAGES];
  348. int minq;
  349. float mincost;
  350. float q0f = FLT_MAX, q1f = 0.0f, qnrgf = 0.0f;
  351. int q0, q1, qcnt = 0;
  352. for (i = 0; i < 1024; i++) {
  353. float t = fabsf(sce->coeffs[i]);
  354. if (t > 0.0f) {
  355. q0f = FFMIN(q0f, t);
  356. q1f = FFMAX(q1f, t);
  357. qnrgf += t*t;
  358. qcnt++;
  359. }
  360. }
  361. if (!qcnt) {
  362. memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
  363. memset(sce->zeroes, 1, sizeof(sce->zeroes));
  364. return;
  365. }
  366. //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped
  367. q0 = coef2minsf(q0f);
  368. //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
  369. q1 = coef2maxsf(q1f);
  370. if (q1 - q0 > 60) {
  371. int q0low = q0;
  372. int q1high = q1;
  373. //minimum scalefactor index is when maximum nonzero coefficient after quantizing is not clipped
  374. int qnrg = av_clip_uint8(log2f(sqrtf(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512);
  375. q1 = qnrg + 30;
  376. q0 = qnrg - 30;
  377. if (q0 < q0low) {
  378. q1 += q0low - q0;
  379. q0 = q0low;
  380. } else if (q1 > q1high) {
  381. q0 -= q1 - q1high;
  382. q1 = q1high;
  383. }
  384. }
  385. for (i = 0; i < TRELLIS_STATES; i++) {
  386. paths[0][i].cost = 0.0f;
  387. paths[0][i].prev = -1;
  388. }
  389. for (j = 1; j < TRELLIS_STAGES; j++) {
  390. for (i = 0; i < TRELLIS_STATES; i++) {
  391. paths[j][i].cost = INFINITY;
  392. paths[j][i].prev = -2;
  393. }
  394. }
  395. idx = 1;
  396. abs_pow34_v(s->scoefs, sce->coeffs, 1024);
  397. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  398. start = w*128;
  399. for (g = 0; g < sce->ics.num_swb; g++) {
  400. const float *coefs = &sce->coeffs[start];
  401. float qmin, qmax;
  402. int nz = 0;
  403. bandaddr[idx] = w * 16 + g;
  404. qmin = INT_MAX;
  405. qmax = 0.0f;
  406. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  407. FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
  408. if (band->energy <= band->threshold || band->threshold == 0.0f) {
  409. sce->zeroes[(w+w2)*16+g] = 1;
  410. continue;
  411. }
  412. sce->zeroes[(w+w2)*16+g] = 0;
  413. nz = 1;
  414. for (i = 0; i < sce->ics.swb_sizes[g]; i++) {
  415. float t = fabsf(coefs[w2*128+i]);
  416. if (t > 0.0f)
  417. qmin = FFMIN(qmin, t);
  418. qmax = FFMAX(qmax, t);
  419. }
  420. }
  421. if (nz) {
  422. int minscale, maxscale;
  423. float minrd = INFINITY;
  424. float maxval;
  425. //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped
  426. minscale = coef2minsf(qmin);
  427. //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
  428. maxscale = coef2maxsf(qmax);
  429. minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);
  430. maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);
  431. maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start);
  432. for (q = minscale; q < maxscale; q++) {
  433. float dist = 0;
  434. int cb = find_min_book(maxval, sce->sf_idx[w*16+g]);
  435. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  436. FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
  437. dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g],
  438. q + q0, cb, lambda / band->threshold, INFINITY, NULL, 0);
  439. }
  440. minrd = FFMIN(minrd, dist);
  441. for (i = 0; i < q1 - q0; i++) {
  442. float cost;
  443. cost = paths[idx - 1][i].cost + dist
  444. + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO];
  445. if (cost < paths[idx][q].cost) {
  446. paths[idx][q].cost = cost;
  447. paths[idx][q].prev = i;
  448. }
  449. }
  450. }
  451. } else {
  452. for (q = 0; q < q1 - q0; q++) {
  453. paths[idx][q].cost = paths[idx - 1][q].cost + 1;
  454. paths[idx][q].prev = q;
  455. }
  456. }
  457. sce->zeroes[w*16+g] = !nz;
  458. start += sce->ics.swb_sizes[g];
  459. idx++;
  460. }
  461. }
  462. idx--;
  463. mincost = paths[idx][0].cost;
  464. minq = 0;
  465. for (i = 1; i < TRELLIS_STATES; i++) {
  466. if (paths[idx][i].cost < mincost) {
  467. mincost = paths[idx][i].cost;
  468. minq = i;
  469. }
  470. }
  471. while (idx) {
  472. sce->sf_idx[bandaddr[idx]] = minq + q0;
  473. minq = paths[idx][minq].prev;
  474. idx--;
  475. }
  476. //set the same quantizers inside window groups
  477. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])
  478. for (g = 0; g < sce->ics.num_swb; g++)
  479. for (w2 = 1; w2 < sce->ics.group_len[w]; w2++)
  480. sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g];
  481. }
  482. /**
  483. * two-loop quantizers search taken from ISO 13818-7 Appendix C
  484. */
  485. static void search_for_quantizers_twoloop(AVCodecContext *avctx,
  486. AACEncContext *s,
  487. SingleChannelElement *sce,
  488. const float lambda)
  489. {
  490. int start = 0, i, w, w2, g;
  491. int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels * (lambda / 120.f);
  492. float dists[128] = { 0 }, uplims[128] = { 0 };
  493. float maxvals[128];
  494. int fflag, minscaler;
  495. int its = 0;
  496. int allz = 0;
  497. float minthr = INFINITY;
  498. // for values above this the decoder might end up in an endless loop
  499. // due to always having more bits than what can be encoded.
  500. destbits = FFMIN(destbits, 5800);
  501. //XXX: some heuristic to determine initial quantizers will reduce search time
  502. //determine zero bands and upper limits
  503. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  504. for (g = 0; g < sce->ics.num_swb; g++) {
  505. int nz = 0;
  506. float uplim = 0.0f, energy = 0.0f;
  507. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  508. FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
  509. uplim += band->threshold;
  510. energy += band->energy;
  511. if (band->energy <= band->threshold || band->threshold == 0.0f) {
  512. sce->zeroes[(w+w2)*16+g] = 1;
  513. continue;
  514. }
  515. nz = 1;
  516. }
  517. uplims[w*16+g] = uplim *512;
  518. sce->zeroes[w*16+g] = !nz;
  519. if (nz)
  520. minthr = FFMIN(minthr, uplim);
  521. allz |= nz;
  522. }
  523. }
  524. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  525. for (g = 0; g < sce->ics.num_swb; g++) {
  526. if (sce->zeroes[w*16+g]) {
  527. sce->sf_idx[w*16+g] = SCALE_ONE_POS;
  528. continue;
  529. }
  530. sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2f(uplims[w*16+g]/minthr)*4,59);
  531. }
  532. }
  533. if (!allz)
  534. return;
  535. abs_pow34_v(s->scoefs, sce->coeffs, 1024);
  536. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  537. start = w*128;
  538. for (g = 0; g < sce->ics.num_swb; g++) {
  539. const float *scaled = s->scoefs + start;
  540. maxvals[w*16+g] = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled);
  541. start += sce->ics.swb_sizes[g];
  542. }
  543. }
  544. //perform two-loop search
  545. //outer loop - improve quality
  546. do {
  547. int tbits, qstep;
  548. minscaler = sce->sf_idx[0];
  549. //inner loop - quantize spectrum to fit into given number of bits
  550. qstep = its ? 1 : 32;
  551. do {
  552. int prev = -1;
  553. tbits = 0;
  554. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  555. start = w*128;
  556. for (g = 0; g < sce->ics.num_swb; g++) {
  557. const float *coefs = &sce->coeffs[start];
  558. const float *scaled = &s->scoefs[start];
  559. int bits = 0;
  560. int cb;
  561. float dist = 0.0f;
  562. if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) {
  563. start += sce->ics.swb_sizes[g];
  564. continue;
  565. }
  566. minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]);
  567. cb = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);
  568. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  569. int b;
  570. dist += quantize_band_cost(s, coefs + w2*128,
  571. scaled + w2*128,
  572. sce->ics.swb_sizes[g],
  573. sce->sf_idx[w*16+g],
  574. cb,
  575. 1.0f,
  576. INFINITY,
  577. &b,
  578. 0);
  579. bits += b;
  580. }
  581. dists[w*16+g] = dist - bits;
  582. if (prev != -1) {
  583. bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO];
  584. }
  585. tbits += bits;
  586. start += sce->ics.swb_sizes[g];
  587. prev = sce->sf_idx[w*16+g];
  588. }
  589. }
  590. if (tbits > destbits) {
  591. for (i = 0; i < 128; i++)
  592. if (sce->sf_idx[i] < 218 - qstep)
  593. sce->sf_idx[i] += qstep;
  594. } else {
  595. for (i = 0; i < 128; i++)
  596. if (sce->sf_idx[i] > 60 - qstep)
  597. sce->sf_idx[i] -= qstep;
  598. }
  599. qstep >>= 1;
  600. if (!qstep && tbits > destbits*1.02 && sce->sf_idx[0] < 217)
  601. qstep = 1;
  602. } while (qstep);
  603. fflag = 0;
  604. minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF);
  605. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  606. for (g = 0; g < sce->ics.num_swb; g++) {
  607. int prevsc = sce->sf_idx[w*16+g];
  608. if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60) {
  609. if (find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]-1))
  610. sce->sf_idx[w*16+g]--;
  611. else //Try to make sure there is some energy in every band
  612. sce->sf_idx[w*16+g]-=2;
  613. }
  614. sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler, minscaler + SCALE_MAX_DIFF);
  615. sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219);
  616. if (sce->sf_idx[w*16+g] != prevsc)
  617. fflag = 1;
  618. sce->band_type[w*16+g] = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);
  619. }
  620. }
  621. its++;
  622. } while (fflag && its < 10);
  623. }
  624. static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s,
  625. SingleChannelElement *sce,
  626. const float lambda)
  627. {
  628. int start = 0, i, w, w2, g;
  629. float uplim[128], maxq[128];
  630. int minq, maxsf;
  631. float distfact = ((sce->ics.num_windows > 1) ? 85.80 : 147.84) / lambda;
  632. int last = 0, lastband = 0, curband = 0;
  633. float avg_energy = 0.0;
  634. if (sce->ics.num_windows == 1) {
  635. start = 0;
  636. for (i = 0; i < 1024; i++) {
  637. if (i - start >= sce->ics.swb_sizes[curband]) {
  638. start += sce->ics.swb_sizes[curband];
  639. curband++;
  640. }
  641. if (sce->coeffs[i]) {
  642. avg_energy += sce->coeffs[i] * sce->coeffs[i];
  643. last = i;
  644. lastband = curband;
  645. }
  646. }
  647. } else {
  648. for (w = 0; w < 8; w++) {
  649. const float *coeffs = &sce->coeffs[w*128];
  650. curband = start = 0;
  651. for (i = 0; i < 128; i++) {
  652. if (i - start >= sce->ics.swb_sizes[curband]) {
  653. start += sce->ics.swb_sizes[curband];
  654. curband++;
  655. }
  656. if (coeffs[i]) {
  657. avg_energy += coeffs[i] * coeffs[i];
  658. last = FFMAX(last, i);
  659. lastband = FFMAX(lastband, curband);
  660. }
  661. }
  662. }
  663. }
  664. last++;
  665. avg_energy /= last;
  666. if (avg_energy == 0.0f) {
  667. for (i = 0; i < FF_ARRAY_ELEMS(sce->sf_idx); i++)
  668. sce->sf_idx[i] = SCALE_ONE_POS;
  669. return;
  670. }
  671. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  672. start = w*128;
  673. for (g = 0; g < sce->ics.num_swb; g++) {
  674. float *coefs = &sce->coeffs[start];
  675. const int size = sce->ics.swb_sizes[g];
  676. int start2 = start, end2 = start + size, peakpos = start;
  677. float maxval = -1, thr = 0.0f, t;
  678. maxq[w*16+g] = 0.0f;
  679. if (g > lastband) {
  680. maxq[w*16+g] = 0.0f;
  681. start += size;
  682. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++)
  683. memset(coefs + w2*128, 0, sizeof(coefs[0])*size);
  684. continue;
  685. }
  686. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  687. for (i = 0; i < size; i++) {
  688. float t = coefs[w2*128+i]*coefs[w2*128+i];
  689. maxq[w*16+g] = FFMAX(maxq[w*16+g], fabsf(coefs[w2*128 + i]));
  690. thr += t;
  691. if (sce->ics.num_windows == 1 && maxval < t) {
  692. maxval = t;
  693. peakpos = start+i;
  694. }
  695. }
  696. }
  697. if (sce->ics.num_windows == 1) {
  698. start2 = FFMAX(peakpos - 2, start2);
  699. end2 = FFMIN(peakpos + 3, end2);
  700. } else {
  701. start2 -= start;
  702. end2 -= start;
  703. }
  704. start += size;
  705. thr = pow(thr / (avg_energy * (end2 - start2)), 0.3 + 0.1*(lastband - g) / lastband);
  706. t = 1.0 - (1.0 * start2 / last);
  707. uplim[w*16+g] = distfact / (1.4 * thr + t*t*t + 0.075);
  708. }
  709. }
  710. memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
  711. abs_pow34_v(s->scoefs, sce->coeffs, 1024);
  712. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  713. start = w*128;
  714. for (g = 0; g < sce->ics.num_swb; g++) {
  715. const float *coefs = &sce->coeffs[start];
  716. const float *scaled = &s->scoefs[start];
  717. const int size = sce->ics.swb_sizes[g];
  718. int scf, prev_scf, step;
  719. int min_scf = -1, max_scf = 256;
  720. float curdiff;
  721. if (maxq[w*16+g] < 21.544) {
  722. sce->zeroes[w*16+g] = 1;
  723. start += size;
  724. continue;
  725. }
  726. sce->zeroes[w*16+g] = 0;
  727. scf = prev_scf = av_clip(SCALE_ONE_POS - SCALE_DIV_512 - log2f(1/maxq[w*16+g])*16/3, 60, 218);
  728. for (;;) {
  729. float dist = 0.0f;
  730. int quant_max;
  731. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  732. int b;
  733. dist += quantize_band_cost(s, coefs + w2*128,
  734. scaled + w2*128,
  735. sce->ics.swb_sizes[g],
  736. scf,
  737. ESC_BT,
  738. lambda,
  739. INFINITY,
  740. &b,
  741. 0);
  742. dist -= b;
  743. }
  744. dist *= 1.0f / 512.0f / lambda;
  745. quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[POW_SF2_ZERO - scf + SCALE_ONE_POS - SCALE_DIV_512], ROUND_STANDARD);
  746. if (quant_max >= 8191) { // too much, return to the previous quantizer
  747. sce->sf_idx[w*16+g] = prev_scf;
  748. break;
  749. }
  750. prev_scf = scf;
  751. curdiff = fabsf(dist - uplim[w*16+g]);
  752. if (curdiff <= 1.0f)
  753. step = 0;
  754. else
  755. step = log2f(curdiff);
  756. if (dist > uplim[w*16+g])
  757. step = -step;
  758. scf += step;
  759. scf = av_clip_uint8(scf);
  760. step = scf - prev_scf;
  761. if (FFABS(step) <= 1 || (step > 0 && scf >= max_scf) || (step < 0 && scf <= min_scf)) {
  762. sce->sf_idx[w*16+g] = av_clip(scf, min_scf, max_scf);
  763. break;
  764. }
  765. if (step > 0)
  766. min_scf = prev_scf;
  767. else
  768. max_scf = prev_scf;
  769. }
  770. start += size;
  771. }
  772. }
  773. minq = sce->sf_idx[0] ? sce->sf_idx[0] : INT_MAX;
  774. for (i = 1; i < 128; i++) {
  775. if (!sce->sf_idx[i])
  776. sce->sf_idx[i] = sce->sf_idx[i-1];
  777. else
  778. minq = FFMIN(minq, sce->sf_idx[i]);
  779. }
  780. if (minq == INT_MAX)
  781. minq = 0;
  782. minq = FFMIN(minq, SCALE_MAX_POS);
  783. maxsf = FFMIN(minq + SCALE_MAX_DIFF, SCALE_MAX_POS);
  784. for (i = 126; i >= 0; i--) {
  785. if (!sce->sf_idx[i])
  786. sce->sf_idx[i] = sce->sf_idx[i+1];
  787. sce->sf_idx[i] = av_clip(sce->sf_idx[i], minq, maxsf);
  788. }
  789. }
  790. static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s,
  791. SingleChannelElement *sce,
  792. const float lambda)
  793. {
  794. int i, w, w2, g;
  795. int minq = 255;
  796. memset(sce->sf_idx, 0, sizeof(sce->sf_idx));
  797. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  798. for (g = 0; g < sce->ics.num_swb; g++) {
  799. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  800. FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
  801. if (band->energy <= band->threshold) {
  802. sce->sf_idx[(w+w2)*16+g] = 218;
  803. sce->zeroes[(w+w2)*16+g] = 1;
  804. } else {
  805. sce->sf_idx[(w+w2)*16+g] = av_clip(SCALE_ONE_POS - SCALE_DIV_512 + log2f(band->threshold), 80, 218);
  806. sce->zeroes[(w+w2)*16+g] = 0;
  807. }
  808. minq = FFMIN(minq, sce->sf_idx[(w+w2)*16+g]);
  809. }
  810. }
  811. }
  812. for (i = 0; i < 128; i++) {
  813. sce->sf_idx[i] = 140;
  814. //av_clip(sce->sf_idx[i], minq, minq + SCALE_MAX_DIFF - 1);
  815. }
  816. //set the same quantizers inside window groups
  817. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])
  818. for (g = 0; g < sce->ics.num_swb; g++)
  819. for (w2 = 1; w2 < sce->ics.group_len[w]; w2++)
  820. sce->sf_idx[(w+w2)*16+g] = sce->sf_idx[w*16+g];
  821. }
  822. static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
  823. {
  824. FFPsyBand *band;
  825. int w, g, w2, i, start, count = 0;
  826. float *PNS = &s->scoefs[0*128], *PNS34 = &s->scoefs[1*128];
  827. float *NOR34 = &s->scoefs[3*128];
  828. const float lambda = s->lambda;
  829. const float freq_mult = avctx->sample_rate/(1024.0f/sce->ics.num_windows)/2.0f;
  830. const float thr_mult = NOISE_LAMBDA_REPLACE*(100.0f/lambda);
  831. const float spread_threshold = NOISE_SPREAD_THRESHOLD*(lambda/100.f);
  832. for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
  833. start = 0;
  834. for (g = 0; g < sce->ics.num_swb; g++) {
  835. int noise_sfi, try_pns = 0;
  836. float dist1 = 0.0f, dist2 = 0.0f, noise_amp;
  837. float pns_energy = 0.0f, energy_ratio, dist_thresh;
  838. float sfb_energy = 0.0f, threshold = 0.0f, spread = 0.0f;
  839. float freq_boost = FFMAX(0.88f*start*freq_mult/NOISE_LOW_LIMIT, 1.0f);
  840. if (start*freq_mult < NOISE_LOW_LIMIT) {
  841. start += sce->ics.swb_sizes[g];
  842. continue;
  843. } else {
  844. dist_thresh = FFMIN(0.008f*(NOISE_LOW_LIMIT/start*freq_mult), 1.11f);
  845. }
  846. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  847. band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g];
  848. sfb_energy += band->energy;
  849. spread += band->spread;
  850. threshold += band->threshold;
  851. }
  852. if (sce->zeroes[w*16+g]) {
  853. try_pns = 1;
  854. } else if (sfb_energy < threshold*freq_boost) {
  855. try_pns = 1;
  856. } else if (spread > spread_threshold) {
  857. try_pns = 0;
  858. } else if (sfb_energy < threshold*thr_mult*freq_boost) {
  859. try_pns = 1;
  860. }
  861. if (!try_pns || !sfb_energy) {
  862. start += sce->ics.swb_sizes[g];
  863. continue;
  864. }
  865. noise_sfi = av_clip(roundf(log2f(sfb_energy)*2), -100, 155); /* Quantize */
  866. noise_amp = -ff_aac_pow2sf_tab[noise_sfi + POW_SF2_ZERO]; /* Dequantize */
  867. for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
  868. float band_energy, scale;
  869. band = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];
  870. for (i = 0; i < sce->ics.swb_sizes[g]; i++)
  871. PNS[i] = s->random_state = lcg_random(s->random_state);
  872. band_energy = s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]);
  873. scale = noise_amp/sqrtf(band_energy);
  874. s->fdsp->vector_fmul_scalar(PNS, PNS, scale, sce->ics.swb_sizes[g]);
  875. pns_energy += s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]);
  876. abs_pow34_v(NOR34, &sce->coeffs[start+(w+w2)*128], sce->ics.swb_sizes[g]);
  877. abs_pow34_v(PNS34, PNS, sce->ics.swb_sizes[g]);
  878. dist1 += quantize_band_cost(s, &sce->coeffs[start + (w+w2)*128],
  879. NOR34,
  880. sce->ics.swb_sizes[g],
  881. sce->sf_idx[(w+w2)*16+g],
  882. sce->band_alt[(w+w2)*16+g],
  883. lambda/band->threshold, INFINITY, NULL, 0);
  884. dist2 += quantize_band_cost(s, PNS,
  885. PNS34,
  886. sce->ics.swb_sizes[g],
  887. noise_sfi,
  888. NOISE_BT,
  889. lambda/band->threshold, INFINITY, NULL, 0);
  890. }
  891. energy_ratio = sfb_energy/pns_energy; /* Compensates for quantization error */
  892. sce->pns_ener[w*16+g] = energy_ratio*sfb_energy;
  893. if (energy_ratio > 0.80f && energy_ratio < 1.20f && dist1/dist2 > dist_thresh) {
  894. sce->band_type[w*16+g] = NOISE_BT;
  895. sce->zeroes[w*16+g] = 0;
  896. if (sce->band_type[w*16+g-1] != NOISE_BT && /* Prevent holes */
  897. sce->band_type[w*16+g-2] == NOISE_BT) {
  898. sce->band_type[w*16+g-1] = NOISE_BT;
  899. sce->zeroes[w*16+g-1] = 0;
  900. }
  901. count++;
  902. }
  903. start += sce->ics.swb_sizes[g];
  904. }
  905. }
  906. }
  907. static void search_for_ms(AACEncContext *s, ChannelElement *cpe)
  908. {
  909. int start = 0, i, w, w2, g;
  910. float M[128], S[128];
  911. float *L34 = s->scoefs, *R34 = s->scoefs + 128, *M34 = s->scoefs + 128*2, *S34 = s->scoefs + 128*3;
  912. const float lambda = s->lambda;
  913. SingleChannelElement *sce0 = &cpe->ch[0];
  914. SingleChannelElement *sce1 = &cpe->ch[1];
  915. if (!cpe->common_window)
  916. return;
  917. for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) {
  918. start = 0;
  919. for (g = 0; g < sce0->ics.num_swb; g++) {
  920. if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) {
  921. float dist1 = 0.0f, dist2 = 0.0f;
  922. for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) {
  923. FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g];
  924. FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g];
  925. float minthr = FFMIN(band0->threshold, band1->threshold);
  926. float maxthr = FFMAX(band0->threshold, band1->threshold);
  927. for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {
  928. M[i] = (sce0->coeffs[start+(w+w2)*128+i]
  929. + sce1->coeffs[start+(w+w2)*128+i]) * 0.5;
  930. S[i] = M[i]
  931. - sce1->coeffs[start+(w+w2)*128+i];
  932. }
  933. abs_pow34_v(L34, sce0->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]);
  934. abs_pow34_v(R34, sce1->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]);
  935. abs_pow34_v(M34, M, sce0->ics.swb_sizes[g]);
  936. abs_pow34_v(S34, S, sce0->ics.swb_sizes[g]);
  937. dist1 += quantize_band_cost(s, &sce0->coeffs[start + (w+w2)*128],
  938. L34,
  939. sce0->ics.swb_sizes[g],
  940. sce0->sf_idx[(w+w2)*16+g],
  941. sce0->band_type[(w+w2)*16+g],
  942. lambda / band0->threshold, INFINITY, NULL, 0);
  943. dist1 += quantize_band_cost(s, &sce1->coeffs[start + (w+w2)*128],
  944. R34,
  945. sce1->ics.swb_sizes[g],
  946. sce1->sf_idx[(w+w2)*16+g],
  947. sce1->band_type[(w+w2)*16+g],
  948. lambda / band1->threshold, INFINITY, NULL, 0);
  949. dist2 += quantize_band_cost(s, M,
  950. M34,
  951. sce0->ics.swb_sizes[g],
  952. sce0->sf_idx[(w+w2)*16+g],
  953. sce0->band_type[(w+w2)*16+g],
  954. lambda / maxthr, INFINITY, NULL, 0);
  955. dist2 += quantize_band_cost(s, S,
  956. S34,
  957. sce1->ics.swb_sizes[g],
  958. sce1->sf_idx[(w+w2)*16+g],
  959. sce1->band_type[(w+w2)*16+g],
  960. lambda / minthr, INFINITY, NULL, 0);
  961. }
  962. cpe->ms_mask[w*16+g] = dist2 < dist1;
  963. }
  964. start += sce0->ics.swb_sizes[g];
  965. }
  966. }
  967. }
  968. AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = {
  969. [AAC_CODER_FAAC] = {
  970. search_for_quantizers_faac,
  971. encode_window_bands_info,
  972. quantize_and_encode_band,
  973. ff_aac_encode_tns_info,
  974. ff_aac_encode_main_pred,
  975. ff_aac_adjust_common_prediction,
  976. ff_aac_apply_main_pred,
  977. ff_aac_apply_tns,
  978. set_special_band_scalefactors,
  979. search_for_pns,
  980. ff_aac_search_for_tns,
  981. search_for_ms,
  982. ff_aac_search_for_is,
  983. ff_aac_search_for_pred,
  984. },
  985. [AAC_CODER_ANMR] = {
  986. search_for_quantizers_anmr,
  987. encode_window_bands_info,
  988. quantize_and_encode_band,
  989. ff_aac_encode_tns_info,
  990. ff_aac_encode_main_pred,
  991. ff_aac_adjust_common_prediction,
  992. ff_aac_apply_main_pred,
  993. ff_aac_apply_tns,
  994. set_special_band_scalefactors,
  995. search_for_pns,
  996. ff_aac_search_for_tns,
  997. search_for_ms,
  998. ff_aac_search_for_is,
  999. ff_aac_search_for_pred,
  1000. },
  1001. [AAC_CODER_TWOLOOP] = {
  1002. search_for_quantizers_twoloop,
  1003. codebook_trellis_rate,
  1004. quantize_and_encode_band,
  1005. ff_aac_encode_tns_info,
  1006. ff_aac_encode_main_pred,
  1007. ff_aac_adjust_common_prediction,
  1008. ff_aac_apply_main_pred,
  1009. ff_aac_apply_tns,
  1010. set_special_band_scalefactors,
  1011. search_for_pns,
  1012. ff_aac_search_for_tns,
  1013. search_for_ms,
  1014. ff_aac_search_for_is,
  1015. ff_aac_search_for_pred,
  1016. },
  1017. [AAC_CODER_FAST] = {
  1018. search_for_quantizers_fast,
  1019. encode_window_bands_info,
  1020. quantize_and_encode_band,
  1021. ff_aac_encode_tns_info,
  1022. ff_aac_encode_main_pred,
  1023. ff_aac_adjust_common_prediction,
  1024. ff_aac_apply_main_pred,
  1025. ff_aac_apply_tns,
  1026. set_special_band_scalefactors,
  1027. search_for_pns,
  1028. ff_aac_search_for_tns,
  1029. search_for_ms,
  1030. ff_aac_search_for_is,
  1031. ff_aac_search_for_pred,
  1032. },
  1033. };