93 .num_ele = { 1, 0, 0, 0 },
94 .pairing = { { 0 }, },
101 .num_ele = { 1, 0, 0, 0 },
102 .pairing = { { 1 }, },
105 .reorder_map = { 0, 1 },
109 .num_ele = { 1, 0, 0, 1 },
110 .pairing = { { 1 }, },
111 .index = { { 0 },{ 0 },{ 0 },{ 0 } },
113 .reorder_map = { 0, 1, 2 },
117 .num_ele = { 1, 0, 1, 0 },
118 .pairing = { { 1 },{ 0 },{ 0 } },
119 .index = { { 0 },{ 0 },{ 0 }, },
121 .reorder_map = { 0, 1, 2 },
125 .num_ele = { 2, 0, 0, 0 },
126 .pairing = { { 0, 1 }, },
127 .index = { { 0, 0 }, },
129 .reorder_map = { 2, 0, 1 },
133 .num_ele = { 2, 0, 0, 1 },
134 .pairing = { { 0, 1 }, },
135 .index = { { 0, 0 }, { 0 }, { 0 }, { 0 }, },
137 .reorder_map = { 2, 0, 1, 3 },
141 .num_ele = { 2, 0, 1, 0 },
142 .pairing = { { 0, 1 }, { 0 }, { 0 }, },
143 .index = { { 0, 0 }, { 0 }, { 1 } },
145 .reorder_map = { 2, 0, 1, 3 },
149 .num_ele = { 2, 0, 1, 1 },
150 .pairing = { { 0, 1 }, { 0 }, { 0 }, },
151 .index = { { 0, 0 }, { 0 }, { 1 }, { 0 } },
153 .reorder_map = { 2, 0, 1, 4, 3 },
157 .num_ele = { 1, 0, 1, 0 },
158 .pairing = { { 1 }, { 0 }, { 1 }, },
159 .index = { { 0 }, { 0 }, { 1 } },
161 .reorder_map = { 0, 1, 2, 3 },
165 .num_ele = { 1, 0, 1, 0 },
166 .pairing = { { 1 }, { 0 }, { 1 }, },
167 .index = { { 0 }, { 0 }, { 1 } },
169 .reorder_map = { 0, 1, 2, 3 },
173 .num_ele = { 2, 0, 1, 0 },
174 .pairing = { { 0, 1 }, { 0 }, { 1 } },
175 .index = { { 0, 0 }, { 0 }, { 1 } },
177 .reorder_map = { 2, 0, 1, 3, 4 },
181 .num_ele = { 2, 0, 1, 1 },
182 .pairing = { { 0, 1 }, { 0 }, { 1 }, },
183 .index = { { 0, 0 }, { 0 }, { 1 }, { 0 } },
185 .reorder_map = { 2, 0, 1, 4, 5, 3 },
189 .num_ele = { 2, 0, 1, 0 },
190 .pairing = { { 0, 1 }, { 0 }, { 1 } },
191 .index = { { 0, 0 }, { 0 }, { 1 } },
193 .reorder_map = { 2, 0, 1, 3, 4 },
197 .num_ele = { 2, 0, 1, 1 },
198 .pairing = { { 0, 1 }, { 0 }, { 1 }, },
199 .index = { { 0, 0 }, { 0 }, { 1 }, { 0 } },
201 .reorder_map = { 2, 0, 1, 4, 5, 3 },
205 .num_ele = { 2, 0, 2, 0 },
206 .pairing = { { 0, 1 }, { 0 }, { 1, 0 } },
207 .index = { { 0, 0 }, { 0 }, { 1, 1 } },
209 .reorder_map = { 2, 0, 1, 4, 5, 3 },
213 .num_ele = { 2, 0, 1, 0 },
214 .pairing = { { 1, 1 }, { 0 }, { 1 } },
215 .index = { { 0, 1 }, { 0 }, { 2 }, },
217 .reorder_map = { 2, 3, 0, 1, 4, 5 },
221 .num_ele = { 2, 0, 2, 0 },
222 .pairing = { { 0, 1 }, { 0 }, { 1, 0 } },
223 .index = { { 0, 0 }, { 0 }, { 1, 1 } },
225 .reorder_map = { 2, 0, 1, 3, 4, 5 },
229 .num_ele = { 2, 0, 2, 1 },
230 .pairing = { { 0, 1 }, { 0 }, { 1, 0 }, },
231 .index = { { 0, 0 }, { 0 }, { 1, 1 }, { 0 } },
233 .reorder_map = { 2, 0, 1, 5, 6, 4, 3 },
237 .num_ele = { 2, 0, 2, 1 },
238 .pairing = { { 0, 1 },{ 0 },{ 1, 0 }, },
239 .index = { { 0, 0 },{ 0 },{ 1, 1 },{ 0 } },
241 .reorder_map = { 2, 0, 1, 4, 5, 6, 3 },
245 .num_ele = { 2, 0, 1, 1 },
246 .pairing = { { 1, 1 }, { 0 }, { 1 }, },
247 .index = { { 0, 1 }, { 0 }, { 2 }, { 0 }, },
249 .reorder_map = { 3, 4, 0, 1, 5, 6, 2 },
253 .num_ele = { 2, 0, 2, 0 },
254 .pairing = { { 0, 1 }, { 0 }, { 1, 1 }, },
255 .index = { { 0, 0 }, { 0 }, { 2, 1 }, },
257 .reorder_map = { 2, 0, 1, 3, 4, 5, 6 },
261 .num_ele = { 3, 0, 1, 0 },
262 .pairing = { { 0, 1, 1 }, { 0 }, { 1 }, },
263 .index = { { 0, 0, 1 }, { 0 }, { 2 }, },
265 .reorder_map = { 2, 3, 4, 0, 1, 5, 6 },
269 .num_ele = { 2, 0, 2, 1 },
270 .pairing = { { 0, 1 }, { 0 }, { 1, 1 }, },
271 .index = { { 0, 0 }, { 0 }, { 2, 1 }, { 0 } },
273 .reorder_map = { 2, 0, 1, 4, 5, 6, 7, 3 },
277 .num_ele = { 3, 0, 1, 1 },
278 .pairing = { { 0, 1, 1 }, { 0 }, { 1 }, },
279 .index = { { 0, 0, 1 }, { 0 }, { 2 }, { 0 }, },
281 .reorder_map = { 2, 4, 5, 0, 1, 6, 7, 3 },
285 .num_ele = { 3, 0, 1, 1 },
286 .pairing = { { 0, 1, 1 }, { 0 }, { 1 } },
287 .index = { { 0, 0, 1 }, { 0 }, { 2 }, { 0 } },
289 .reorder_map = { 2, 6, 7, 0, 1, 4, 5, 3 },
293 .num_ele = { 2, 0, 3, 0 },
294 .pairing = { { 0, 1 }, { 0 }, { 1, 1, 0 }, },
295 .index = { { 0, 0 }, { 0 }, { 1, 2, 1 }, },
297 .reorder_map = { 2, 0, 1, 6, 7, 3, 4, 5 },
325 for (
i = 0;
i < 4;
i++) {
326 for (j = 0; j < pce->
num_ele[
i]; j++) {
346 const int max_size = 32;
375 ++
s->quantize_band_cost_cache_generation;
376 if (
s->quantize_band_cost_cache_generation == 0) {
377 memset(
s->quantize_band_cost_cache, 0,
sizeof(
s->quantize_band_cost_cache));
378 s->quantize_band_cost_cache_generation = 1;
382 #define WINDOW_FUNC(type) \
383 static void apply_ ##type ##_window(AVFloatDSPContext *fdsp, \
384 SingleChannelElement *sce, \
391 float *
out = sce->ret_buf;
393 fdsp->vector_fmul (
out, audio, lwindow, 1024);
394 fdsp->vector_fmul_reverse(
out + 1024, audio + 1024, pwindow, 1024);
401 float *
out = sce->ret_buf;
403 fdsp->vector_fmul(
out, audio, lwindow, 1024);
404 memcpy(
out + 1024, audio + 1024,
sizeof(
out[0]) * 448);
405 fdsp->vector_fmul_reverse(
out + 1024 + 448, audio + 1024 + 448, swindow, 128);
406 memset(
out + 1024 + 576, 0,
sizeof(
out[0]) * 448);
413 float *
out = sce->ret_buf;
415 memset(
out, 0,
sizeof(
out[0]) * 448);
416 fdsp->vector_fmul(
out + 448, audio + 448, swindow, 128);
417 memcpy(
out + 576, audio + 576,
sizeof(
out[0]) * 448);
418 fdsp->vector_fmul_reverse(
out + 1024, audio + 1024, lwindow, 1024);
425 const float *in = audio + 448;
426 float *
out = sce->ret_buf;
429 for (
w = 0;
w < 8;
w++) {
430 fdsp->vector_fmul (
out, in,
w ? pwindow : swindow, 128);
433 fdsp->vector_fmul_reverse(
out, in, swindow, 128);
440 const float *audio) = {
458 for (
i = 0;
i < 1024;
i += 128)
460 memcpy(audio, audio + 1024,
sizeof(audio[0]) * 1024);
480 for (
w = 1;
w < 8;
w++)
508 for (ch = 0; ch < chans; ch++) {
513 for (cmaxsfb = ics->
num_swb; cmaxsfb > 0 && cpe->
ch[ch].
zeroes[
w*16+cmaxsfb-1]; cmaxsfb--)
515 maxsfb =
FFMAX(maxsfb, cmaxsfb);
544 if (msc == 0 || ics0->
max_sfb == 0)
559 int start = (
w+w2) * 128;
581 #define NMR_IS_IMG_GATE 8000.0f
584 #define NMR_IS_LOW_LIMIT 6100
587 #define NMR_MS_EQUIV 0.5f
588 #define NMR_MS_MASK 0.0f
593 #define NMR_DECORR_LO 0.20f
596 #define NMR_STICKY 2.0f
599 #define NMR_SDEC_EMA 0.75f
602 #define NMR_PNS_STEREO_DECORR 0.6f
606 int w,
int g,
int start,
int len,
int gl)
611 for (
int w2 = 0; w2 < gl; w2++) {
614 float *
L = sce0->
coeffs + start + (
w+w2)*128;
615 float *
R = sce1->
coeffs + start + (
w+w2)*128;
616 float em = 0.0f, es = 0.0f;
617 for (
int i = 0;
i <
len;
i++) {
618 float m = (
L[
i] +
R[
i]) * 0.5
f;
619 R[
i] = m -
R[
i];
L[
i] = m;
622 b0->threshold =
FFMIN(
b0->threshold,
b1->threshold) * 0.5f;
623 b1->threshold =
b0->threshold;
624 b0->energy = em;
b1->energy = es;
630 int w,
int g,
int start,
int len,
int gl,
631 float ener0,
float ener1,
float dot,
632 float minthr0,
float minthr1,
float *ratio_out,
633 float *scale_out,
float *sr_out,
int *p_out)
635 int p = dot >= 0.0f ? 1 : -1;
636 float ener01 = ener0 + ener1 + 2*
p*dot;
637 *ratio_out = FLT_MAX;
638 if (ener01 <= FLT_MIN)
641 float sr_ =
sqrtf(ener1 / ener0);
642 float img0 = 0.0f, img1 = 0.0f;
643 for (
int w2 = 0; w2 < gl; w2++) {
644 const float *
L = cpe->
ch[0].
coeffs + start + (
w+w2)*128;
645 const float *
R = cpe->
ch[1].
coeffs + start + (
w+w2)*128;
646 for (
int i = 0;
i <
len;
i++) {
648 float dl =
L[
i] -
c, dr =
R[
i] -
p*sr_*
c;
649 img0 += dl*dl; img1 += dr*dr;
652 *ratio_out =
FFMAX(img0 /
FFMAX(minthr0 * gl, FLT_MIN),
653 img1 /
FFMAX(minthr1 * gl, FLT_MIN));
654 *scale_out =
scale; *sr_out = sr_; *p_out =
p;
662 int w,
int g,
int start,
int len,
int gl,
663 float scale,
float sr_,
int p,
664 float ener0,
float ener1)
670 for (
int w2 = 0; w2 < gl; w2++) {
673 float *
L = cpe->
ch[0].
coeffs + start + (
w+w2)*128;
674 float *
R = cpe->
ch[1].
coeffs + start + (
w+w2)*128;
676 for (
int i = 0;
i <
len;
i++) {
682 b0->energy = ec;
b1->energy = 0.0f;
701 int pi = (
s->cur_channel >> 1) & 7;
703 if (!
s->nmr->sinit[pi]) {
706 memset(
s->nmr->smode[pi], 0,
sizeof(
s->nmr->smode[pi]));
707 for (
int b = 0;
b < 128;
b++) {
708 s->nmr->sema_em[pi][
b] = 0.0f;
709 s->nmr->sema_img[pi][
b] = -1.0f;
711 s->nmr->sinit[pi] = 1;
721 float is_ramp =
s->nmr ?
s->nmr->press *
722 av_clipf((
s->nmr->lam_floor - 40.0f) / (120.0f - 40.0f), 0.0f, 1.0f) : 0.0f;
723 const int allow_is =
s->options.intensity_stereo && is_ramp > 0.0f;
725 const int pidx = (
s->cur_channel >> 1) & 15;
726 const int decoupled =
s->psy.pair_decoupled[pidx];
727 int njoint = 0, nbands = 0;
733 float ener0 = 0.0f, ener1 = 0.0f, dot = 0.0f, es_tot = 0.0f, em_tot = 0.0f;
734 float minthr0 = FLT_MAX, minthr1 = FLT_MAX;
739 for (
int w2 = 0; w2 < gl; w2++) {
742 const float *
L = sce0->
coeffs + start + (
w+w2)*128;
743 const float *
R = sce1->
coeffs + start + (
w+w2)*128;
744 float el = 0.0f, er = 0.0f, em = 0.0f, es = 0.0f, d = 0.0f;
745 for (
int i = 0;
i <
len;
i++) {
746 float m = (
L[
i] +
R[
i]) * 0.5
f;
749 em += m*m; es += sv*sv; d +=
L[
i]*
R[
i];
751 ener0 += el; ener1 += er; dot += d; es_tot += es; em_tot += em;
752 minthr0 =
FFMIN(minthr0,
b0->threshold);
753 minthr1 =
FFMIN(minthr1,
b1->threshold);
755 float thr_g =
FFMIN(minthr0, minthr1) * gl;
758 const int sidx =
w*16+
g;
760 float es_w = es_tot, em_w = em_tot;
763 float pe =
s->nmr->sema_es[pi_][sidx];
764 float pm =
s->nmr->sema_em[pi_][sidx];
777 uint8_t *pmode =
s->nmr ?
s->nmr->smode[pi] :
NULL;
778 int prev = pmode ? pmode[sidx] : 0;
779 float eqgate =
NMR_MS_EQUIV * (prev == 1 ? 1.5f : 1.0f);
782 float es_d = es_tot, em_d = em_tot;
784 float *ees = &
s->nmr->sema_es[pi][sidx];
785 float *eem = &
s->nmr->sema_em[pi][sidx];
786 if (*eem <= 0.0
f) { *ees = es_tot; *eem = em_tot; }
791 es_d = *ees; em_d = *eem;
793 int ms_would =
s->options.mid_side &&
794 (
s->options.mid_side == 1 ||
795 es_d < eqgate * em_d ||
797 int ms_ok = ms_would && !decoupled;
798 float scale, sr_, imgratio;
int p;
802 ener0 > FLT_MIN && ener1 > FLT_MIN &&
804 ener0, ener1, dot, minthr0, minthr1,
805 &imgratio, &
scale, &sr_, &
p);
810 float *eim = &
s->nmr->sema_img[pi][sidx];
813 if (*eim < 0.0
f) *eim = imgratio;
816 is_ok = is_cand && *eim >= 0.0f && *eim < imgate;
819 njoint += ms_would || is_ok; nbands++;
821 int m_ = (is_ok && allow_is) ? 2 : ms_ok ? 1 :
822 (is_ok &&
s->options.mid_side) ? 1 : 0;
824 s->nmr->smode_band[(
s->cur_channel >> 1) & 7][
w*16+
g] = m_;
826 if (is_ok && allow_is) {
828 scale, sr_,
p, ener0, ener1);
830 }
else if (ms_ok || (is_ok &&
s->options.mid_side)) {
842 float r = (
float)njoint / nbands;
843 float *pj = &
s->psy.pair_joint[pidx];
844 *pj = *pj > 0.0f ? 0.95f * *pj + 0.05f *
r :
r;
845 s->psy.pair_decoupled[pidx] = *pj <
858 int start = (
w+w2) * 128;
889 if (
s->coder->set_special_band_scalefactors)
890 s->coder->set_special_band_scalefactors(
s, sce);
903 int off_is = 0, noise_flag = 1;
912 if (noise_flag-- > 0) {
966 s->coder->quantize_and_encode_band(
s, &
s->pb,
967 &sce->
coeffs[start + w2*128],
990 float *swb_coeffs = &sce->
coeffs[start +
w*128];
1013 if (
s->coder->encode_tns_info)
1014 s->coder->encode_tns_info(
s, sce);
1025 int i, namelen, padbits;
1027 namelen = strlen(
name) + 2;
1035 for (
i = 0;
i < namelen - 2;
i++)
1047 int end = 2048 + (
frame ?
frame->nb_samples : 0);
1051 for (ch = 0; ch <
s->channels; ch++) {
1053 memcpy(&
s->planar_samples[ch][1024], &
s->planar_samples[ch][2048], 1024 *
sizeof(
s->planar_samples[0][0]));
1057 memcpy(&
s->planar_samples[ch][2048],
1059 frame->nb_samples *
sizeof(
s->planar_samples[0][0]));
1061 memset(&
s->planar_samples[ch][end], 0,
1062 (3072 - end) *
sizeof(
s->planar_samples[0][0]));
1070 float **
samples =
s->planar_samples, *samples2, *la, *overlap;
1074 int i, its, ch,
w, chans,
tag, start_ch,
ret, frame_bits;
1075 int target_bits, rate_bits, too_many_bits, too_few_bits;
1076 int ms_mode = 0, is_mode = 0, tns_mode = 0, pred_mode = 0;
1077 int chan_el_counter[4];
1085 if (!
s->afq.remaining_samples || (!
s->afq.frame_alloc && !
s->afq.frame_count))
1095 for (
i = 0;
i <
s->chan_map[0];
i++) {
1097 tag =
s->chan_map[
i+1];
1105 const float *ov0 = &
samples[start_ch][0], *ov1 = &
samples[start_ch + 1][0];
1106 s->psy.model->window_pair(&
s->psy,
1107 ov0 + 1024, ov0 + 1024 + 448 + 64,
1108 ov1 + 1024, ov1 + 1024 + 448 + 64,
1109 start_ch, start_ch + 1,
1115 for (ch = 0; ch < chans; ch++) {
1117 float clip_avoidance_factor;
1120 s->cur_channel = start_ch + ch;
1121 overlap = &
samples[
s->cur_channel][0];
1122 samples2 = overlap + 1024;
1123 la = samples2 + (448+64);
1137 ics->
num_swb =
s->samplerate_index >= 8 ? 1 : 3;
1138 }
else if (!wi_paired) {
1139 wi[ch] =
s->psy.model->window(&
s->psy, samples2, la,
s->cur_channel,
1161 clip_avoidance_factor = 0.0f;
1163 const float *wbuf = overlap +
w * 128;
1168 for (j = 0; j < wlen; j++)
1175 clip_avoidance_factor =
FFMAX(clip_avoidance_factor, wi[ch].clipping[
w]);
1188 for (k = 0; k < 1024; k++) {
1201 frame_bits = its = 0;
1209 memset(chan_el_counter, 0,
sizeof(chan_el_counter));
1210 for (
i = 0;
i <
s->chan_map[0];
i++) {
1212 const float *coeffs[2];
1213 tag =
s->chan_map[
i+1];
1221 for (ch = 0; ch < chans; ch++) {
1223 coeffs[ch] = sce->
coeffs;
1225 for (
w = 0;
w < 128;
w++)
1229 s->psy.bitres.alloc = -1;
1230 s->psy.bitres.bits =
s->last_frame_pb_count /
s->channels;
1231 s->psy.model->analyze(&
s->psy, start_ch, coeffs, wi);
1232 if (
s->psy.bitres.alloc > 0) {
1234 target_bits +=
s->psy.bitres.alloc
1236 s->psy.bitres.alloc /= chans;
1240 && wi[0].window_type[0] == wi[1].window_type[0]
1241 && wi[0].window_shape == wi[1].window_shape) {
1245 if (wi[0].grouping[
w] != wi[1].grouping[
w]) {
1252 const int use_tns =
s->options.tns &&
s->coder->search_for_tns &&
1253 s->coder->apply_tns_filt;
1258 if (tns_first && use_tns) {
1259 for (ch = 0; ch < chans; ch++) {
1261 s->cur_channel = start_ch + ch;
1264 if (chans == 1 &&
s->options.pns &&
s->coder->mark_pns)
1265 s->coder->mark_pns(
s, avctx, sce);
1266 s->coder->search_for_tns(
s, sce);
1267 s->coder->apply_tns_filt(
s, sce);
1276 s->options.pns &&
s->coder->mark_pns) {
1277 s->cur_channel = start_ch;
s->coder->mark_pns(
s, avctx, &cpe->
ch[0]);
1278 s->cur_channel = start_ch + 1;
s->coder->mark_pns(
s, avctx, &cpe->
ch[1]);
1279 for (
int b = 0;
b < 128;
b++)
1287 (
s->options.mid_side ||
s->options.intensity_stereo)) {
1288 s->cur_channel = start_ch;
1294 s->nmr->pair = (chans == 2);
1295 for (ch = 0; ch < chans; ch++) {
1296 s->cur_channel = start_ch + ch;
1298 if (
s->options.pns &&
s->coder->mark_pns && !tns_first)
1299 s->coder->mark_pns(
s, avctx, &cpe->
ch[ch]);
1300 s->coder->search_for_quantizers(avctx,
s, &cpe->
ch[ch],
s->lambda);
1302 for (ch = 0; ch < chans; ch++) {
1304 s->cur_channel = start_ch + ch;
1305 if (!tns_first && use_tns) {
1306 s->coder->search_for_tns(
s, sce);
1307 s->coder->apply_tns_filt(
s, sce);
1311 if (
s->options.pns &&
s->coder->search_for_pns)
1312 s->coder->search_for_pns(
s, avctx, sce);
1314 s->cur_channel = start_ch;
1315 if (
s->options.intensity_stereo) {
1317 if (
s->coder->search_for_is)
1318 s->coder->search_for_is(
s, avctx, cpe);
1321 if (cpe->
is_mode) is_mode = 1;
1324 if (
s->options.mid_side == -1 &&
s->coder->search_for_ms)
1325 s->coder->search_for_ms(
s, cpe);
1336 if (cpe->
ms_mode) ms_mode = 1;
1339 for (ch = 0; ch < chans; ch++) {
1340 s->cur_channel = start_ch + ch;
1357 frame_bits < 6144 * s->
channels - 3)
1365 rate_bits =
FFMIN(rate_bits, 6144 *
s->channels - 3);
1366 too_many_bits =
FFMAX(target_bits, rate_bits);
1367 too_many_bits =
FFMIN(too_many_bits, 6144 *
s->channels - 3);
1368 too_few_bits =
FFMIN(
FFMAX(rate_bits - rate_bits/4, target_bits), too_many_bits);
1372 if (rate_bits < frame_bits) {
1373 float ratio = ((
float)rate_bits) / frame_bits;
1374 s->lambda *=
FFMIN(0.9
f, ratio);
1383 too_few_bits = too_few_bits - too_few_bits/8;
1384 too_many_bits = too_many_bits + too_many_bits/2;
1387 || (its < 5 && (frame_bits < too_few_bits || frame_bits > too_many_bits))
1388 || frame_bits >= 6144 *
s->channels - 3 )
1390 float ratio = ((
float)rate_bits) / frame_bits;
1392 if (frame_bits >= too_few_bits && frame_bits <= too_many_bits) {
1403 ratio =
sqrtf(ratio);
1405 s->lambda =
av_clipf(
s->lambda * ratio, FLT_EPSILON, 65536.f);
1408 if (ratio > 0.9
f && ratio < 1.1
f) {
1411 if (is_mode || ms_mode || tns_mode || pred_mode) {
1412 for (
i = 0;
i <
s->chan_map[0];
i++) {
1416 for (ch = 0; ch < chans; ch++)
1428 for (
i = 0;
i <
s->chan_map[0];
i++) {
1429 int etag =
s->chan_map[
i + 1], echans = etag ==
TYPE_CPE ? 2 : 1;
1432 for (ch = 0; ch < echans; ch++) {
1438 if (is_short)
s->stat_tns_short++;
1439 else s->stat_tns_long++;
1444 int idx =
w*16 +
g, coded = 0;
1445 for (ch = 0; ch < echans; ch++) {
1455 s->stat_cpe_bands++;
1456 if (ce->
ms_mask[idx])
s->stat_ms++;
1457 if (ce->
is_mask[idx])
s->stat_is++;
1472 for (
i = 0;
i <
s->channels;
i++)
1473 counted +=
s->nmr->counted[
i];
1475 float side = (
float)
s->last_frame_pb_count - counted;
1476 if (
s->nmr->side_inited) {
1477 s->nmr->side_ema += 0.125f * (side -
s->nmr->side_ema);
1479 s->nmr->side_ema = side;
1480 s->nmr->side_inited = 1;
1486 s->lambda_sum += (
s->nmr &&
s->nmr->lam_rc > 0.0f) ?
s->nmr->lam_rc :
s->lambda;
1495 *got_packet_ptr = 1;
1504 "Qavg: %.3f Tr: %.1f%% TNS(L): %.1f%% TNS(S): %.1f%% M/S: %.1f%% I/S: %.1f%% PNS: %.1f%%\n",
1505 s->lambda_count ?
s->lambda_sum /
s->lambda_count :
NAN,
1506 s->stat_chans ? 100.0 *
s->stat_short /
s->stat_chans : 0.0,
1507 s->stat_chans -
s->stat_short ? 100.0 *
s->stat_tns_long / (
s->stat_chans -
s->stat_short) : 0.0,
1508 s->stat_short ? 100.0 *
s->stat_tns_short /
s->stat_short : 0.0,
1509 s->stat_cpe_bands ? 100.0 *
s->stat_ms /
s->stat_cpe_bands : 0.0,
1510 s->stat_cpe_bands ? 100.0 *
s->stat_is /
s->stat_cpe_bands : 0.0,
1511 s->stat_ch_bands ? 100.0 *
s->stat_pns /
s->stat_ch_bands : 0.0);
1528 float scale = 32768.0f;
1535 1024, &
scale, 0)) < 0)
1538 128, &
scale, 0)) < 0)
1551 for(ch = 0; ch <
s->channels; ch++)
1552 s->planar_samples[ch] =
s->buffer.samples + 3 * 1024 * ch;
1568 const uint8_t *
sizes[2];
1573 s->last_frame_pb_count = 0;
1584 s->needs_pce =
s->options.pce;
1599 av_log(avctx,
AV_LOG_INFO,
"Using a PCE to encode channel layout \"%s\"\n", buf);
1601 s->reorder_map =
s->pce.reorder_map;
1602 s->chan_map =
s->pce.config_map;
1610 for (
i = 1;
i <=
s->chan_map[0];
i++) {
1618 for (
int i = 0;;
i++) {
1621 s->samplerate_index =
i;
1628 "Too many bits %f > %d per frame requested, clamping to max\n",
1630 6144 *
s->channels);
1644 "PNS unavailable in the \"mpeg2_aac_low\" profile, turning off\n");
1653 if (
s->channels > 3)
1654 s->options.mid_side = 0;
1661 (avctx->
bit_rate / 2.0f * (
s->lambda / 120.f) * 1.5f) :
1665 static const int rates[] = { 24000, 32000, 48000, 64000, 96000, 192000 };
1666 static const int bws[] = { 14000, 14000, 18500, 20000, 21000, 22000 };
1669 s->bandwidth = bws[bw_i] + (int)((
int64_t)(bws[bw_i + 1] - bws[bw_i]) *
1673 if (
s->options.pns ||
s->options.intensity_stereo)
1684 if (bpc <= 32000 && avctx->sample_rate > 32000)
1686 "%d kb/s per channel at %d Hz: consider resampling the "
1687 "input to 32000 Hz or lower for better quality.\n",
1707 for (
i = 0;
i <
s->chan_map[0];
i++)
1710 s->chan_map[0], grouping,
s->bandwidth)) < 0)
1713 s->random_state = 0x1f2e3d4c;
1722 #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
1724 {
"aac_coder",
"Coding algorithm", offsetof(
AACEncContext,
options.coder),
AV_OPT_TYPE_INT, {.i64 =
AAC_CODER_NMR}, 0,
AAC_CODER_NB-1,
AACENC_FLAGS, .unit =
"coder"},
1733 {
"aac_nmr_speed",
"NMR coder speed level: 0 = slowest/best, higher trades quality for speed", offsetof(
AACEncContext,
options.nmr_speed),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4,
AACENC_FLAGS},