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.

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