48 #define AAC_MAX_CHANNELS 6
50 #define ERROR_IF(cond, ...) \
52 av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
53 return AVERROR(EINVAL); \
59 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8,
60 12, 12, 12, 12, 12, 16, 16, 24, 28, 36, 44,
61 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
65 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8,
66 12, 12, 12, 16, 16, 16, 20, 24, 24, 28, 36,
67 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40
71 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
72 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28,
73 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
78 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
79 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28,
80 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
84 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
85 12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28,
86 32, 36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
90 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
91 12, 12, 12, 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, 24, 28, 28,
92 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
96 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
97 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 28, 28,
98 32, 36, 36, 40, 44, 48, 52, 56, 60, 64, 80
109 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
113 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
117 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 20
121 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
125 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 16, 20, 20
156 { 2, 0, 1, 4, 5, 3 },
184 #define WINDOW_FUNC(type) \
185 static void apply_ ##type ##_window(AVFloatDSPContext *fdsp, \
186 SingleChannelElement *sce, \
193 float *
out = sce->ret_buf;
195 fdsp->vector_fmul (out, audio, lwindow, 1024);
196 fdsp->vector_fmul_reverse(out + 1024, audio + 1024, pwindow, 1024);
203 float *
out = sce->ret_buf;
205 fdsp->vector_fmul(out, audio, lwindow, 1024);
206 memcpy(out + 1024, audio + 1024,
sizeof(out[0]) * 448);
207 fdsp->vector_fmul_reverse(out + 1024 + 448, audio + 1024 + 448, swindow, 128);
208 memset(out + 1024 + 576, 0,
sizeof(out[0]) * 448);
215 float *
out = sce->ret_buf;
217 memset(out, 0,
sizeof(out[0]) * 448);
218 fdsp->vector_fmul(out + 448, audio + 448, swindow, 128);
219 memcpy(out + 576, audio + 576,
sizeof(out[0]) * 448);
220 fdsp->vector_fmul_reverse(out + 1024, audio + 1024, lwindow, 1024);
227 const float *
in = audio + 448;
228 float *
out = sce->ret_buf;
231 for (w = 0; w < 8; w++) {
232 fdsp->vector_fmul (out, in, w ? pwindow : swindow, 128);
235 fdsp->vector_fmul_reverse(out, in, swindow, 128);
242 const float *audio) = {
260 for (i = 0; i < 1024; i += 128)
262 memcpy(audio, audio + 1024,
sizeof(audio[0]) * 1024);
281 for (w = 1; w < 8; w++)
307 int start, maxsfb, cmaxsfb;
309 for (ch = 0; ch < chans; ch++) {
315 for (g = 0; g < ics->
num_swb; g++) {
325 for (cmaxsfb = ics->
num_swb; cmaxsfb > 0 && cpe->
ch[ch].
zeroes[w+cmaxsfb-1]; cmaxsfb--)
327 maxsfb =
FFMAX(maxsfb, cmaxsfb);
333 for (g = 0; g < ics->
max_sfb; g++) {
335 for (w2 = w; w2 < w + ics->
group_len[w]; w2++) {
336 if (!cpe->
ch[ch].
zeroes[w2*16 + g]) {
353 for (i = 0; i < ics0->
max_sfb; i++)
356 if (msc == 0 || ics0->
max_sfb == 0)
385 if (!sce->
zeroes[w*16 + i]) {
387 if (diff < 0 || diff > 120)
389 off = sce->
sf_idx[w*16 + i];
425 if (sce->
zeroes[w*16 + i]) {
464 int i, namelen, padbits;
466 namelen = strlen(name) + 2;
474 for (i = 0; i < namelen - 2; i++)
486 int end = 2048 + (frame ? frame->
nb_samples : 0);
490 for (ch = 0; ch < s->
channels; ch++) {
506 const AVFrame *frame,
int *got_packet_ptr)
511 int i, ch, w,
g, chans,
tag, start_ch, ret;
512 int chan_el_counter[4];
532 for (i = 0; i < s->
chan_map[0]; i++) {
537 for (ch = 0; ch < chans; ch++) {
539 int cur_channel = start_ch + ch;
540 overlap = &samples[cur_channel][0];
541 samples2 = overlap + 1024;
542 la = samples2 + (448+64);
587 memset(chan_el_counter, 0,
sizeof(chan_el_counter));
588 for (i = 0; i < s->
chan_map[0]; i++) {
596 for (ch = 0; ch < chans; ch++)
599 for (ch = 0; ch < chans; ch++) {
605 && wi[0].window_type[0] == wi[1].window_type[0]
606 && wi[0].window_shape == wi[1].window_shape) {
610 if (wi[0].grouping[w] != wi[1].grouping[w]) {
621 for (g = 0; g < ics->
num_swb; g++)
635 for (ch = 0; ch < chans; ch++) {
643 if (frame_bits <= 6144 * s->channels - 3) {
734 for (i = 0; i < 16; i++)
741 "Unsupported sample rate %d\n", avctx->
sample_rate);
743 "Unsupported number of channels: %d\n", s->
channels);
745 "Unsupported profile %d\n", avctx->
profile);
747 "Too many bits per frame requested\n");
766 for (i = 0; i < s->
chan_map[0]; i++)
777 for (i = 0; i < 428; i++)
789 #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
791 {
"stereo_mode",
"Stereo coding method", offsetof(
AACEncContext,
options.stereo_mode),
AV_OPT_TYPE_INT, {.i64 = 0}, -1, 1,
AACENC_FLAGS,
"stereo_mode"},
794 {
"ms_force",
"Force Mid/Side for the whole frame if possible", 0,
AV_OPT_TYPE_CONST, {.i64 = 1 }, INT_MIN, INT_MAX,
AACENC_FLAGS,
"stereo_mode"},