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 /**
23 * @file
24 * AAC coefficients encoder
25 */
26
27 /***********************************
28 * TODOs:
29 * speedup quantizer selection
30 * add sane pulse detection
31 ***********************************/
32
33 #include "libavutil/libm.h" // brought forward to work around cygwin header breakage
34
35 #include <float.h>
42
43 /** bits needed to code codebook run value for long windows */
45 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
46 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10,
47 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
48 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 15
49 };
50
51 /** bits needed to code codebook run value for short windows */
53 3, 3, 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 9
54 };
55
58 };
59
60
61 /**
62 * Quantize one coefficient.
63 * @return absolute value of the quantized coefficient
64 * @see 3GPP TS26.403 5.6.2 "Scalefactor determination"
65 */
67 {
69 return sqrtf(a * sqrtf(a)) + 0.4054;
70 }
71
73 int size,
float Q34,
int is_signed,
int maxval)
74 {
75 int i;
76 double qc;
77 for (i = 0; i <
size; i++) {
78 qc = scaled[i] * Q34;
79 out[i] = (int)
FFMIN(qc + 0.4054, (
double)maxval);
80 if (is_signed && in[i] < 0.0f) {
81 out[i] = -out[i];
82 }
83 }
84 }
85
87 {
88 #ifndef USE_REALLY_FULL_SEARCH
89 int i;
90 for (i = 0; i <
size; i++) {
91 float a = fabsf(in[i]);
92 out[i] = sqrtf(a * sqrtf(a));
93 }
94 #endif /* USE_REALLY_FULL_SEARCH */
95 }
96
97 static const uint8_t aac_cb_range [12] = {0, 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17};
98 static const uint8_t aac_cb_maxval[12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16};
99
100 /**
101 * Calculate rate distortion cost for quantizing with given codebook
102 *
103 * @return quantization distortion
104 */
108 const float *scaled,
int size,
int scale_idx,
109 int cb,
const float lambda,
const float uplim,
110 int *
bits,
int BT_ZERO,
int BT_UNSIGNED,
111 int BT_PAIR, int BT_ESC)
112 {
117 const float CLIPPED_ESCAPE = 165140.0f*IQ;
118 int i, j;
119 float cost = 0;
120 const int dim = BT_PAIR ? 2 : 4;
121 int resbits = 0;
125
126 if (BT_ZERO) {
127 for (i = 0; i <
size; i++)
128 cost += in[i]*in[i];
129 if (bits)
130 *bits = 0;
131 return cost * lambda;
132 }
133 if (!scaled) {
136 }
138 if (BT_UNSIGNED) {
139 off = 0;
140 } else {
141 off = maxval;
142 }
143 for (i = 0; i <
size; i +=
dim) {
144 const float *vec;
145 int *quants = s->
qcoefs + i;
146 int curidx = 0;
147 int curbits;
148 float rd = 0.0f;
149 for (j = 0; j <
dim; j++) {
150 curidx *= range;
151 curidx += quants[j] +
off;
152 }
155 if (BT_UNSIGNED) {
156 for (j = 0; j <
dim; j++) {
157 float t = fabsf(in[i+j]);
158 float di;
159 if (BT_ESC && vec[j] == 64.0f) { //FIXME: slow
160 if (t >= CLIPPED_ESCAPE) {
161 di = t - CLIPPED_ESCAPE;
162 curbits += 21;
163 } else {
164 int c = av_clip(
quant(t, Q), 0, 8191);
165 di = t - c*
cbrtf(c)*IQ;
166 curbits +=
av_log2(c)*2 - 4 + 1;
167 }
168 } else {
169 di = t - vec[j]*IQ;
170 }
171 if (vec[j] != 0.0f)
172 curbits++;
173 rd += di*di;
174 }
175 } else {
176 for (j = 0; j <
dim; j++) {
177 float di = in[i+j] - vec[j]*IQ;
178 rd += di*di;
179 }
180 }
181 cost += rd * lambda + curbits;
182 resbits += curbits;
183 if (cost >= uplim)
184 return uplim;
185 if (pb) {
187 if (BT_UNSIGNED)
188 for (j = 0; j <
dim; j++)
191 if (BT_ESC) {
192 for (j = 0; j < 2; j++) {
194 int coef = av_clip(
quant(fabsf(in[i+j]), Q), 0, 8191);
196
197 put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
198 put_bits(pb, len, coef & ((1 << len) - 1));
199 }
200 }
201 }
202 }
203 }
204
205 if (bits)
206 *bits = resbits;
207 return cost;
208 }
209
210 #define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC) \
211 static float quantize_and_encode_band_cost_ ## NAME( \
212 struct AACEncContext *s, \
213 PutBitContext *pb, const float *in, \
214 const float *scaled, int size, int scale_idx, \
215 int cb, const float lambda, const float uplim, \
216 int *bits) { \
217 return quantize_and_encode_band_cost_template( \
218 s, pb, in, scaled, size, scale_idx, \
219 BT_ESC ? ESC_BT : cb, lambda, uplim, bits, \
220 BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC); \
221 }
222
229
233 const
float *scaled,
int size,
int scale_idx,
234 int cb, const
float lambda, const
float uplim,
236 quantize_and_encode_band_cost_ZERO,
237 quantize_and_encode_band_cost_SQUAD,
238 quantize_and_encode_band_cost_SQUAD,
239 quantize_and_encode_band_cost_UQUAD,
240 quantize_and_encode_band_cost_UQUAD,
241 quantize_and_encode_band_cost_SPAIR,
242 quantize_and_encode_band_cost_SPAIR,
243 quantize_and_encode_band_cost_UPAIR,
244 quantize_and_encode_band_cost_UPAIR,
245 quantize_and_encode_band_cost_UPAIR,
246 quantize_and_encode_band_cost_UPAIR,
247 quantize_and_encode_band_cost_ESC,
248 };
249
250 #define quantize_and_encode_band_cost( \
251 s, pb, in, scaled, size, scale_idx, cb, \
252 lambda, uplim, bits) \
253 quantize_and_encode_band_cost_arr[cb]( \
254 s, pb, in, scaled, size, scale_idx, cb, \
255 lambda, uplim, bits)
256
258 const float *scaled,
int size,
int scale_idx,
259 int cb,
const float lambda,
const float uplim,
261 {
263 cb, lambda, uplim, bits);
264 }
265
267 const float *
in,
int size,
int scale_idx,
268 int cb,
const float lambda)
269 {
272 }
273
274 static float find_max_val(
int group_len,
int swb_size,
const float *scaled) {
275 float maxval = 0.0f;
276 int w2, i;
277 for (w2 = 0; w2 < group_len; w2++) {
278 for (i = 0; i < swb_size; i++) {
279 maxval =
FFMAX(maxval, scaled[w2*128+i]);
280 }
281 }
282 return maxval;
283 }
284
287 float Q34 = sqrtf(Q * sqrtf(Q));
289 qmaxval = maxval * Q34 + 0.4054f;
290 if (qmaxval == 0) cb = 0;
291 else if (qmaxval == 1) cb = 1;
292 else if (qmaxval == 2) cb = 3;
293 else if (qmaxval <= 4) cb = 5;
294 else if (qmaxval <= 7) cb = 7;
295 else if (qmaxval <= 12) cb = 9;
296 else cb = 11;
298 }
299
300 /**
301 * structure used in optimal codebook search
302 */
304 int prev_idx;
///< pointer to the previous path point
308
309 /**
310 * Encode band info for single window group bands.
311 */
313 int win, int group_len, const float lambda)
314 {
317 int i, j;
320 const int run_esc = (1 <<
run_bits) - 1;
321 int idx, ppos,
count;
322 int stackrun[120], stackcb[120], stack_len;
324 int next_mincb = 0;
325
327 start = win*128;
328 for (cb = 0; cb < 12; cb++) {
332 }
333 for (swb = 0; swb < max_sfb; swb++) {
335 if (sce->
zeroes[win*16 + swb]) {
336 for (cb = 0; cb < 12; cb++) {
340 }
341 } else {
342 float minrd = next_minrd;
343 int mincb = next_mincb;
345 next_mincb = 0;
346 for (cb = 0; cb < 12; cb++) {
347 float cost_stay_here, cost_get_here;
348 float rd = 0.0f;
349 for (w = 0; w < group_len; w++) {
352 s->
scoefs + start + w*128, size,
353 sce->
sf_idx[(win+w)*16+swb], cb,
355 }
356 cost_stay_here = path[swb][
cb].
cost + rd;
357 cost_get_here = minrd + rd + run_bits + 4;
361 if (cost_get_here < cost_stay_here) {
363 path[swb+1][
cb].
cost = cost_get_here;
364 path[swb+1][
cb].
run = 1;
365 } else {
367 path[swb+1][
cb].
cost = cost_stay_here;
369 }
370 if (path[swb+1][cb].cost < next_minrd) {
371 next_minrd = path[swb+1][
cb].
cost;
373 }
374 }
375 }
377 }
378
379 //convert resulting path from backward-linked list
380 stack_len = 0;
381 idx = 0;
382 for (cb = 1; cb < 12; cb++)
383 if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
385 ppos = max_sfb;
386 while (ppos > 0) {
387 cb = idx;
388 stackrun[stack_len] = path[ppos][
cb].
run;
389 stackcb [stack_len] =
cb;
391 ppos -= path[ppos][
cb].
run;
392 stack_len++;
393 }
394 //perform actual band info encoding
395 start = 0;
396 for (i = stack_len - 1; i >= 0; i--) {
398 count = stackrun[i];
399 memset(sce->
zeroes + win*16 + start, !stackcb[i], count);
400 //XXX: memset when band_type is also uint8_t
401 for (j = 0; j <
count; j++) {
403 start++;
404 }
405 while (count >= run_esc) {
407 count -= run_esc;
408 }
410 }
411 }
412
414 int win, int group_len, const float lambda)
415 {
418 int i, j;
421 const int run_esc = (1 <<
run_bits) - 1;
422 int idx, ppos,
count;
423 int stackrun[120], stackcb[120], stack_len;
425 int next_mincb = 0;
426
428 start = win*128;
429 for (cb = 0; cb < 12; cb++) {
430 path[0][
cb].
cost = run_bits+4;
433 }
434 for (swb = 0; swb < max_sfb; swb++) {
436 if (sce->
zeroes[win*16 + swb]) {
437 float cost_stay_here = path[swb][0].
cost;
438 float cost_get_here = next_minbits + run_bits + 4;
442 if (cost_get_here < cost_stay_here) {
443 path[swb+1][0].
prev_idx = next_mincb;
444 path[swb+1][0].
cost = cost_get_here;
445 path[swb+1][0].
run = 1;
446 } else {
448 path[swb+1][0].
cost = cost_stay_here;
449 path[swb+1][0].
run = path[swb][0].
run + 1;
450 }
451 next_minbits = path[swb+1][0].
cost;
452 next_mincb = 0;
453 for (cb = 1; cb < 12; cb++) {
454 path[swb+1][
cb].
cost = 61450;
456 path[swb+1][
cb].
run = 0;
457 }
458 } else {
459 float minbits = next_minbits;
460 int mincb = next_mincb;
461 int startcb = sce->
band_type[win*16+swb];
463 next_mincb = 0;
464 for (cb = 0; cb < startcb; cb++) {
465 path[swb+1][
cb].
cost = 61450;
467 path[swb+1][
cb].
run = 0;
468 }
469 for (cb = startcb; cb < 12; cb++) {
470 float cost_stay_here, cost_get_here;
472 for (w = 0; w < group_len; w++) {
474 s->
scoefs + start + w*128, size,
475 sce->
sf_idx[(win+w)*16+swb], cb,
477 }
479 cost_get_here = minbits + bits + run_bits + 4;
483 if (cost_get_here < cost_stay_here) {
485 path[swb+1][
cb].
cost = cost_get_here;
486 path[swb+1][
cb].
run = 1;
487 } else {
489 path[swb+1][
cb].
cost = cost_stay_here;
491 }
492 if (path[swb+1][cb].cost < next_minbits) {
493 next_minbits = path[swb+1][
cb].
cost;
495 }
496 }
497 }
499 }
500
501 //convert resulting path from backward-linked list
502 stack_len = 0;
503 idx = 0;
504 for (cb = 1; cb < 12; cb++)
505 if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
507 ppos = max_sfb;
508 while (ppos > 0) {
510 cb = idx;
511 stackrun[stack_len] = path[ppos][
cb].
run;
512 stackcb [stack_len] =
cb;
514 ppos -= path[ppos][
cb].
run;
515 stack_len++;
516 }
517 //perform actual band info encoding
518 start = 0;
519 for (i = stack_len - 1; i >= 0; i--) {
521 count = stackrun[i];
522 memset(sce->
zeroes + win*16 + start, !stackcb[i], count);
523 //XXX: memset when band_type is also uint8_t
524 for (j = 0; j <
count; j++) {
526 start++;
527 }
528 while (count >= run_esc) {
530 count -= run_esc;
531 }
533 }
534 }
535
536 /** Return the minimum scalefactor where the quantized coef does not clip. */
539 }
540
541 /** Return the maximum scalefactor where the quantized coef is not zero. */
544 }
545
550
551 #define TRELLIS_STAGES 121
552 #define TRELLIS_STATES (SCALE_MAX_DIFF+1)
553
556 const float lambda)
557 {
558 int q, w, w2,
g,
start = 0;
559 int i, j;
560 int idx;
563 int minq;
564 float mincost;
565 float q0f = FLT_MAX, q1f = 0.0f, qnrgf = 0.0f;
566 int q0, q1, qcnt = 0;
567
568 for (i = 0; i < 1024; i++) {
569 float t = fabsf(sce->
coeffs[i]);
570 if (t > 0.0f) {
574 qcnt++;
575 }
576 }
577
578 if (!qcnt) {
581 return;
582 }
583
584 //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped
586 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
588 if (q1 - q0 > 60) {
589 int q0low = q0;
590 int q1high = q1;
591 //minimum scalefactor index is when maximum nonzero coefficient after quantizing is not clipped
593 q1 = qnrg + 30;
594 q0 = qnrg - 30;
595 if (q0 < q0low) {
596 q1 += q0low - q0;
597 q0 = q0low;
598 } else if (q1 > q1high) {
599 q0 -= q1 - q1high;
600 q1 = q1high;
601 }
602 }
603
605 paths[0][i].
cost = 0.0f;
606 paths[0][i].
prev = -1;
607 }
611 paths[j][i].
prev = -2;
612 }
613 }
614 idx = 1;
617 start = w*128;
620 float qmin, qmax;
621 int nz = 0;
622
623 bandaddr[idx] = w * 16 +
g;
624 qmin = INT_MAX;
625 qmax = 0.0f;
629 sce->
zeroes[(w+w2)*16+g] = 1;
630 continue;
631 }
632 sce->
zeroes[(w+w2)*16+g] = 0;
633 nz = 1;
635 float t = fabsf(coefs[w2*128+i]);
636 if (t > 0.0f)
637 qmin =
FFMIN(qmin, t);
638 qmax =
FFMAX(qmax, t);
639 }
640 }
641 if (nz) {
642 int minscale, maxscale;
644 float maxval;
645 //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped
647 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
649 minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);
650 maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);
652 for (q = minscale; q < maxscale; q++) {
653 float dist = 0;
659 }
660 minrd =
FFMIN(minrd, dist);
661
662 for (i = 0; i < q1 - q0; i++) {
663 float cost;
664 cost = paths[idx - 1][i].
cost + dist
666 if (cost < paths[idx][q].cost) {
667 paths[idx][q].
cost = cost;
668 paths[idx][q].
prev = i;
669 }
670 }
671 }
672 } else {
673 for (q = 0; q < q1 - q0; q++) {
674 paths[idx][q].
cost = paths[idx - 1][q].
cost + 1;
675 paths[idx][q].
prev = q;
676 }
677 }
680 idx++;
681 }
682 }
683 idx--;
684 mincost = paths[idx][0].
cost;
685 minq = 0;
687 if (paths[idx][i].cost < mincost) {
688 mincost = paths[idx][i].
cost;
689 minq = i;
690 }
691 }
692 while (idx) {
693 sce->
sf_idx[bandaddr[idx]] = minq + q0;
694 minq = paths[idx][minq].
prev;
695 idx--;
696 }
697 //set the same quantizers inside window groups
702 }
703
704 /**
705 * two-loop quantizers search taken from ISO 13818-7 Appendix C
706 */
710 const float lambda)
711 {
712 int start = 0, i, w, w2,
g;
714 float dists[128] = { 0 }, uplims[128];
715 float maxvals[128];
716 int fflag, minscaler;
717 int its = 0;
718 int allz = 0;
720
721 // for values above this the decoder might end up in an endless loop
722 // due to always having more bits than what can be encoded.
723 destbits =
FFMIN(destbits, 5800);
724 //XXX: some heuristic to determine initial quantizers will reduce search time
725 //determine zero bands and upper limits
728 int nz = 0;
729 float uplim = 0.0f;
734 sce->
zeroes[(w+w2)*16+g] = 1;
735 continue;
736 }
737 nz = 1;
738 }
739 uplims[w*16+
g] = uplim *512;
741 if (nz)
742 minthr =
FFMIN(minthr, uplim);
743 allz |= nz;
744 }
745 }
748 if (sce->
zeroes[w*16+g]) {
750 continue;
751 }
753 }
754 }
755
756 if (!allz)
757 return;
759
761 start = w*128;
766 }
767 }
768
769 //perform two-loop search
770 //outer loop - improve quality
771 do {
772 int tbits, qstep;
773 minscaler = sce->
sf_idx[0];
774 //inner loop - quantize spectrum to fit into given number of bits
775 qstep = its ? 1 : 32;
776 do {
777 int prev = -1;
778 tbits = 0;
779 fflag = 0;
781 start = w*128;
787 float dist = 0.0f;
788
789 if (sce->
zeroes[w*16+g] || sce->
sf_idx[w*16+g] >= 218) {
791 continue;
792 }
798 scaled + w2*128,
801 cb,
802 1.0f,
804 &b);
806 }
807 dists[w*16+
g] = dist -
bits;
808 if (prev != -1) {
810 }
814 }
815 }
816 if (tbits > destbits) {
817 for (i = 0; i < 128; i++)
818 if (sce->
sf_idx[i] < 218 - qstep)
820 } else {
821 for (i = 0; i < 128; i++)
822 if (sce->
sf_idx[i] > 60 - qstep)
824 }
825 qstep >>= 1;
826 if (!qstep && tbits > destbits*1.02 && sce->
sf_idx[0] < 217)
827 qstep = 1;
828 } while (qstep);
829
830 fflag = 0;
834 int prevsc = sce->
sf_idx[w*16+
g];
835 if (dists[w*16+g] > uplims[w*16+g] && sce->
sf_idx[w*16+g] > 60) {
838 else //Try to make sure there is some energy in every band
840 }
843 if (sce->
sf_idx[w*16+g] != prevsc)
844 fflag = 1;
846 }
847 }
848 its++;
849 } while (fflag && its < 10);
850 }
851
854 const float lambda)
855 {
856 int start = 0, i, w, w2,
g;
857 float uplim[128], maxq[128];
858 int minq, maxsf;
859 float distfact = ((sce->
ics.
num_windows > 1) ? 85.80 : 147.84) / lambda;
860 int last = 0, lastband = 0, curband = 0;
861 float avg_energy = 0.0;
863 start = 0;
864 for (i = 0; i < 1024; i++) {
867 curband++;
868 }
871 last = i;
872 lastband = curband;
873 }
874 }
875 } else {
876 for (w = 0; w < 8; w++) {
878 curband = start = 0;
879 for (i = 0; i < 128; i++) {
882 curband++;
883 }
884 if (coeffs[i]) {
885 avg_energy += coeffs[i] * coeffs[i];
886 last =
FFMAX(last, i);
887 lastband =
FFMAX(lastband, curband);
888 }
889 }
890 }
891 }
892 last++;
893 avg_energy /= last;
894 if (avg_energy == 0.0f) {
897 return;
898 }
900 start = w*128;
905 float maxval = -1, thr = 0.0f,
t;
907 if (g > lastband) {
911 memset(coefs + w2*128, 0,
sizeof(coefs[0])*
size);
912 continue;
913 }
915 for (i = 0; i <
size; i++) {
916 float t = coefs[w2*128+i]*coefs[w2*128+i];
917 maxq[w*16+
g] =
FFMAX(maxq[w*16+g], fabsf(coefs[w2*128 + i]));
921 peakpos = start+i;
922 }
923 }
924 }
926 start2 =
FFMAX(peakpos - 2, start2);
927 end2 =
FFMIN(peakpos + 3, end2);
928 } else {
931 }
933 thr = pow(thr / (avg_energy * (end2 - start2)), 0.3 + 0.1*(lastband - g) / lastband);
934 t = 1.0 - (1.0 * start2 / last);
935 uplim[w*16+
g] = distfact / (1.4 * thr +
t*
t*
t + 0.075);
936 }
937 }
941 start = w*128;
946 int scf, prev_scf, step;
947 int min_scf = -1, max_scf = 256;
948 float curdiff;
949 if (maxq[w*16+g] < 21.544) {
952 continue;
953 }
956 step = 16;
957 for (;;) {
958 float dist = 0.0f;
959 int quant_max;
960
964 scaled + w2*128,
966 scf,
968 lambda,
970 &b);
972 }
973 dist *= 1.0f / 512.0f / lambda;
975 if (quant_max >= 8191) { // too much, return to the previous quantizer
976 sce->
sf_idx[w*16+
g] = prev_scf;
977 break;
978 }
979 prev_scf = scf;
980 curdiff = fabsf(dist - uplim[w*16+g]);
981 if (curdiff <= 1.0f)
982 step = 0;
983 else
984 step =
log2f(curdiff);
985 if (dist > uplim[w*16+g])
986 step = -step;
987 scf += step;
988 scf = av_clip_uint8(scf);
989 step = scf - prev_scf;
990 if (
FFABS(step) <= 1 || (step > 0 && scf >= max_scf) || (step < 0 && scf <= min_scf)) {
991 sce->
sf_idx[w*16+
g] = av_clip(scf, min_scf, max_scf);
992 break;
993 }
994 if (step > 0)
995 min_scf = prev_scf;
996 else
997 max_scf = prev_scf;
998 }
1000 }
1001 }
1003 for (i = 1; i < 128; i++) {
1006 else
1008 }
1009 if (minq == INT_MAX)
1010 minq = 0;
1013 for (i = 126; i >= 0; i--) {
1017 }
1018 }
1019
1022 const float lambda)
1023 {
1025 int minq = 255;
1026
1033 sce->
sf_idx[(w+w2)*16+g] = 218;
1034 sce->
zeroes[(w+w2)*16+g] = 1;
1035 } else {
1037 sce->
zeroes[(w+w2)*16+g] = 0;
1038 }
1040 }
1041 }
1042 }
1043 for (i = 0; i < 128; i++) {
1045 //av_clip(sce->sf_idx[i], minq, minq + SCALE_MAX_DIFF - 1);
1046 }
1047 //set the same quantizers inside window groups
1052 }
1053
1055 const float lambda)
1056 {
1057 int start = 0, i, w, w2,
g;
1058 float M[128],
S[128];
1063 return;
1067 float dist1 = 0.0f, dist2 = 0.0f;
1074 M[i] = (sce0->
coeffs[start+w2*128+i]
1075 + sce1->
coeffs[start+w2*128+i]) * 0.5;
1076 S[i] = M[i]
1077 - sce1->
coeffs[start+w2*128+i];
1078 }
1084 L34,
1086 sce0->
sf_idx[(w+w2)*16+g],
1090 R34,
1092 sce1->
sf_idx[(w+w2)*16+g],
1096 M34,
1098 sce0->
sf_idx[(w+w2)*16+g],
1102 S34,
1104 sce1->
sf_idx[(w+w2)*16+g],
1107 }
1108 cpe->
ms_mask[w*16+
g] = dist2 < dist1;
1109 }
1111 }
1112 }
1113 }
1114
1121 },
1127 },
1133 },
1139 },
1140 };