115 static const char overread_err[] =
"Input buffer exhausted before END element found\n";
120 for (i = 0; i < tags; i++) {
121 int syn_ele =
layout[i][0];
123 sum += (1 + (syn_ele ==
TYPE_CPE)) *
143 int type,
int id,
int *channels)
148 if (!ac->
che[type][
id]) {
161 if (ac->
che[type][
id])
171 int type,
id, ch, ret;
174 for (type = 0; type < 4; type++) {
192 for (ch = 0; ch < avctx->
channels; ch++) {
208 uint8_t (*layout_map)[3],
int offset, uint64_t left,
209 uint64_t right,
int pos)
211 if (layout_map[offset][0] ==
TYPE_CPE) {
213 .av_position = left | right,
215 .elem_id = layout_map[offset][1],
223 .elem_id = layout_map[offset][1],
227 .av_position = right,
229 .elem_id = layout_map[offset + 1][1],
239 int num_pos_channels = 0;
243 for (i = *current; i < tags; i++) {
244 if (layout_map[i][2] != pos)
254 num_pos_channels += 2;
265 return num_pos_channels;
270 int i, n, total_non_cc_elements;
272 int num_front_channels, num_side_channels, num_back_channels;
281 if (num_front_channels < 0)
285 if (num_side_channels < 0)
289 if (num_back_channels < 0)
293 if (num_front_channels & 1) {
297 .elem_id = layout_map[i][1],
301 num_front_channels--;
303 if (num_front_channels >= 4) {
308 num_front_channels -= 2;
310 if (num_front_channels >= 2) {
315 num_front_channels -= 2;
317 while (num_front_channels >= 2) {
322 num_front_channels -= 2;
325 if (num_side_channels >= 2) {
330 num_side_channels -= 2;
332 while (num_side_channels >= 2) {
337 num_side_channels -= 2;
340 while (num_back_channels >= 4) {
345 num_back_channels -= 2;
347 if (num_back_channels >= 2) {
352 num_back_channels -= 2;
354 if (num_back_channels) {
358 .elem_id = layout_map[i][1],
369 .elem_id = layout_map[i][1],
378 .elem_id = layout_map[i][1],
385 total_non_cc_elements = n = i;
388 for (i = 1; i < n; i++)
389 if (e2c_vec[i - 1].av_position > e2c_vec[i].av_position) {
397 for (i = 0; i < total_non_cc_elements; i++) {
398 layout_map[i][0] = e2c_vec[i].
syn_ele;
399 layout_map[i][1] = e2c_vec[i].
elem_id;
401 if (e2c_vec[i].av_position != UINT64_MAX) {
414 ac->
oc[0] = ac->
oc[1];
425 ac->
oc[1] = ac->
oc[0];
438 uint8_t layout_map[MAX_ELEM_ID * 4][3],
int tags,
439 enum OCStatus oc_type,
int get_new_frame)
442 int i, channels = 0, ret;
446 memcpy(ac->
oc[1].
layout_map, layout_map, tags *
sizeof(layout_map[0]));
454 for (i = 0; i < tags; i++) {
455 int type = layout_map[i][0];
456 int id = layout_map[i][1];
457 int position = layout_map[i][2];
464 if (ac->
oc[1].
m4ac.
ps == 1 && channels == 2) {
496 if (channel_config < 1 || channel_config > 7) {
498 "invalid default channel configuration (%d)\n",
504 *tags *
sizeof(*layout_map));
518 uint8_t layout_map[MAX_ELEM_ID*4][3];
523 &layout_map_tags, 2) < 0)
535 uint8_t layout_map[MAX_ELEM_ID * 4][3];
540 &layout_map_tags, 1) < 0)
626 layout_map[0][0] = syn_ele;
628 layout_map[0][2] = type;
642 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc;
652 "Sample rate index in program config element does not "
653 "match the sample rate index configured by the container.\n");
709 int extension_flag, ret;
710 uint8_t layout_map[MAX_ELEM_ID*4][3];
726 if (channel_config == 0) {
728 tags =
decode_pce(avctx, m4ac, layout_map, gb);
733 &tags, channel_config)))
739 }
else if (m4ac->
sbr == 1 && m4ac->
ps == -1)
745 if (extension_flag) {
796 sync_extension)) < 0)
800 "invalid sampling rate index %d\n",
817 "Audio object type %s%d is not supported.\n",
818 m4ac->
sbr == 1 ?
"SBR+" :
"",
824 "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
841 union {
unsigned u;
int s; } v = { previous_val * 1664525u + 1013904223 };
864 if (92017 <= rate)
return 0;
865 else if (75132 <= rate)
return 1;
866 else if (55426 <= rate)
return 2;
867 else if (46009 <= rate)
return 3;
868 else if (37566 <= rate)
return 4;
869 else if (27713 <= rate)
return 5;
870 else if (23004 <= rate)
return 6;
871 else if (18783 <= rate)
return 7;
872 else if (13856 <= rate)
return 8;
873 else if (11502 <= rate)
return 9;
874 else if (9391 <= rate)
return 10;
885 #define AAC_INIT_VLC_STATIC(num, size) \
886 INIT_VLC_STATIC(&vlc_spectral[num], 8, ff_aac_spectral_sizes[num], \
887 ff_aac_spectral_bits[num], sizeof(ff_aac_spectral_bits[num][0]), \
888 sizeof(ff_aac_spectral_bits[num][0]), \
889 ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), \
890 sizeof(ff_aac_spectral_codes[num][0]), \
911 uint8_t layout_map[MAX_ELEM_ID*4][3];
1017 "Invalid Predictor Reset Group.\n");
1060 for (i = 0; i < 7; i++) {
1088 "Prediction is not allowed in AAC-LC.\n");
1099 "Number of scalefactor bands in group (%d) "
1100 "exceeds limit (%d).\n",
1124 while (k < ics->max_sfb) {
1127 int sect_band_type =
get_bits(gb, 4);
1128 if (sect_band_type == 12) {
1133 sect_len_incr =
get_bits(gb, bits);
1134 sect_end += sect_len_incr;
1139 if (sect_end > ics->
max_sfb) {
1141 "Number of bands (%d) exceeds limit (%d).\n",
1145 }
while (sect_len_incr == (1 << bits) - 1);
1146 for (; k < sect_end; k++) {
1147 band_type [idx] = sect_band_type;
1148 band_type_run_end[idx++] = sect_end;
1166 unsigned int global_gain,
1169 int band_type_run_end[120])
1172 int offset[3] = { global_gain, global_gain - 90, 0 };
1176 for (i = 0; i < ics->
max_sfb;) {
1177 int run_end = band_type_run_end[idx];
1178 if (band_type[idx] ==
ZERO_BT) {
1179 for (; i < run_end; i++, idx++)
1183 for (; i < run_end; i++, idx++) {
1184 offset[2] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1185 clipped_offset = av_clip(offset[2], -155, 100);
1186 if (offset[2] != clipped_offset) {
1188 "position clipped (%d -> %d).\nIf you heard an "
1189 "audible artifact, there may be a bug in the "
1190 "decoder. ", offset[2], clipped_offset);
1194 }
else if (band_type[idx] ==
NOISE_BT) {
1195 for (; i < run_end; i++, idx++) {
1196 if (noise_flag-- > 0)
1197 offset[1] +=
get_bits(gb, 9) - 256;
1199 offset[1] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1200 clipped_offset = av_clip(offset[1], -100, 155);
1201 if (offset[1] != clipped_offset) {
1203 "(%d -> %d).\nIf you heard an audible "
1204 "artifact, there may be a bug in the decoder. ",
1205 offset[1], clipped_offset);
1210 for (; i < run_end; i++, idx++) {
1211 offset[0] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1212 if (offset[0] > 255
U) {
1214 "Scalefactor (%d) out of range.\n", offset[0]);
1229 const uint16_t *swb_offset,
int num_swb)
1234 if (pulse_swb >= num_swb)
1236 pulse->
pos[0] = swb_offset[pulse_swb];
1238 if (pulse->
pos[0] > 1023)
1241 for (i = 1; i < pulse->
num_pulse; i++) {
1243 if (pulse->
pos[i] > 1023)
1258 int w, filt, i, coef_len, coef_res, coef_compress;
1265 for (filt = 0; filt < tns->
n_filt[w]; filt++) {
1269 if ((tns->
order[w][filt] =
get_bits(gb, 5 - 2 * is8)) > tns_max_order) {
1271 "TNS filter order %d is greater than maximum %d.\n",
1272 tns->
order[w][filt], tns_max_order);
1273 tns->
order[w][filt] = 0;
1276 if (tns->
order[w][filt]) {
1279 coef_len = coef_res + 3 - coef_compress;
1280 tmp2_idx = 2 * coef_compress + coef_res;
1282 for (i = 0; i < tns->
order[w][filt]; i++)
1302 if (ms_present == 1) {
1307 }
else if (ms_present == 2) {
1313 static inline float *
VMUL2(
float *dst,
const float *v,
unsigned idx,
1317 *dst++ = v[idx & 15] * s;
1318 *dst++ = v[idx>>4 & 15] * s;
1324 static inline float *
VMUL4(
float *dst,
const float *v,
unsigned idx,
1328 *dst++ = v[idx & 3] * s;
1329 *dst++ = v[idx>>2 & 3] * s;
1330 *dst++ = v[idx>>4 & 3] * s;
1331 *dst++ = v[idx>>6 & 3] * s;
1337 static inline float *
VMUL2S(
float *dst,
const float *v,
unsigned idx,
1338 unsigned sign,
const float *
scale)
1343 s0.
i ^= sign >> 1 << 31;
1346 *dst++ = v[idx & 15] * s0.
f;
1347 *dst++ = v[idx>>4 & 15] * s1.
f;
1354 static inline float *
VMUL4S(
float *dst,
const float *v,
unsigned idx,
1355 unsigned sign,
const float *
scale)
1357 unsigned nz = idx >> 12;
1361 t.
i = s.
i ^ (sign & 1
U<<31);
1362 *dst++ = v[idx & 3] * t.
f;
1364 sign <<= nz & 1; nz >>= 1;
1365 t.
i = s.
i ^ (sign & 1
U<<31);
1366 *dst++ = v[idx>>2 & 3] * t.
f;
1368 sign <<= nz & 1; nz >>= 1;
1369 t.
i = s.
i ^ (sign & 1
U<<31);
1370 *dst++ = v[idx>>4 & 3] * t.
f;
1373 t.
i = s.
i ^ (sign & 1
U<<31);
1374 *dst++ = v[idx>>6 & 3] * t.
f;
1394 int pulse_present,
const Pulse *pulse,
1398 int i, k,
g, idx = 0;
1401 float *coef_base = coef;
1404 memset(coef + g * 128 + offsets[ics->
max_sfb], 0,
1405 sizeof(
float) * (c - offsets[ics->
max_sfb]));
1410 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1411 const unsigned cbt_m1 = band_type[idx] - 1;
1412 float *cfo = coef + offsets[
i];
1413 int off_len = offsets[i + 1] - offsets[
i];
1417 for (group = 0; group < g_len; group++, cfo+=128) {
1418 memset(cfo, 0, off_len *
sizeof(
float));
1420 }
else if (cbt_m1 ==
NOISE_BT - 1) {
1421 for (group = 0; group < g_len; group++, cfo+=128) {
1425 for (k = 0; k < off_len; k++) {
1431 scale = sf[idx] / sqrtf(band_energy);
1440 switch (cbt_m1 >> 1) {
1442 for (group = 0; group < g_len; group++, cfo+=128) {
1452 cb_idx = cb_vector_idx[code];
1453 cf =
VMUL4(cf, vq, cb_idx, sf + idx);
1459 for (group = 0; group < g_len; group++, cfo+=128) {
1471 cb_idx = cb_vector_idx[code];
1472 nnz = cb_idx >> 8 & 15;
1475 cf =
VMUL4S(cf, vq, cb_idx, bits, sf + idx);
1481 for (group = 0; group < g_len; group++, cfo+=128) {
1491 cb_idx = cb_vector_idx[code];
1492 cf =
VMUL2(cf, vq, cb_idx, sf + idx);
1499 for (group = 0; group < g_len; group++, cfo+=128) {
1511 cb_idx = cb_vector_idx[code];
1512 nnz = cb_idx >> 8 & 15;
1513 sign = nnz ?
SHOW_UBITS(
re, gb, nnz) << (cb_idx >> 12) : 0;
1515 cf =
VMUL2S(cf, vq, cb_idx, sign, sf + idx);
1521 for (group = 0; group < g_len; group++, cfo+=128) {
1523 uint32_t *icf = (uint32_t *) cf;
1542 cb_idx = cb_vector_idx[code];
1548 for (j = 0; j < 2; j++) {
1570 unsigned v = ((
const uint32_t*)vq)[cb_idx & 15];
1571 *icf++ = (bits & 1
U<<31) | v;
1588 if (pulse_present) {
1590 for (i = 0; i < pulse->
num_pulse; i++) {
1591 float co = coef_base[ pulse->
pos[
i] ];
1592 while (offsets[idx + 1] <= pulse->
pos[i])
1594 if (band_type[idx] !=
NOISE_BT && sf[idx]) {
1595 float ico = -pulse->
amp[
i];
1598 ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico);
1600 coef_base[ pulse->
pos[
i] ] =
cbrtf(fabsf(ico)) * ico * sf[idx];
1611 tmp.
i = (tmp.
i + 0x00008000
U) & 0xFFFF0000U;
1619 tmp.
i = (tmp.
i + 0x00007FFF
U + (tmp.
i & 0x00010000
U >> 16)) & 0xFFFF0000
U;
1627 pun.
i &= 0xFFFF0000
U;
1634 const float a = 0.953125;
1635 const float alpha = 0.90625;
1639 float r0 = ps->
r0, r1 = ps->
r1;
1640 float cor0 = ps->
cor0, cor1 = ps->
cor1;
1641 float var0 = ps->
var0, var1 = ps->
var1;
1643 k1 = var0 > 1 ? cor0 *
flt16_even(a / var0) : 0;
1644 k2 = var1 > 1 ? cor1 *
flt16_even(a / var1) : 0;
1679 k < sce->ics.swb_offset[sfb + 1];
1707 float *out = sce->
coeffs;
1708 int global_gain, pulse_present = 0;
1718 if (!common_window && !scale_flag) {
1735 "Pulse tool not allowed in eight short sequence.\n");
1740 "Pulse data corrupt or invalid.\n");
1770 int g,
i, group, idx = 0;
1773 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1777 for (group = 0; group < ics->
group_len[
g]; group++) {
1779 ch1 + group * 128 + offsets[i],
1780 offsets[i+1] - offsets[i]);
1803 int g, group,
i, idx = 0;
1807 for (i = 0; i < ics->
max_sfb;) {
1811 for (; i < bt_run_end; i++, idx++) {
1812 c = -1 + 2 * (sce1->
band_type[idx] - 14);
1814 c *= 1 - 2 * cpe->
ms_mask[idx];
1815 scale = c * sce1->
sf[idx];
1816 for (group = 0; group < ics->
group_len[
g]; group++)
1818 coef0 + group * 128 + offsets[i],
1820 offsets[i + 1] - offsets[i]);
1824 idx += bt_run_end -
i;
1840 int i, ret, common_window, ms_present = 0;
1843 if (common_window) {
1854 if (ms_present == 3) {
1857 }
else if (ms_present)
1860 if ((ret =
decode_ics(ac, &cpe->
ch[0], gb, common_window, 0)))
1862 if ((ret =
decode_ics(ac, &cpe->
ch[1], gb, common_window, 0)))
1865 if (common_window) {
1879 1.09050773266525765921,
1880 1.18920711500272106672,
1915 scale = cce_scale[
get_bits(gb, 2)];
1920 for (c = 0; c < num_gain; c++) {
1924 float gain_cache = 1.;
1927 gain = cge ?
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60: 0;
1928 gain_cache =
powf(scale, -gain);
1931 coup->
gain[c][0] = gain_cache;
1934 for (sfb = 0; sfb < sce->
ics.
max_sfb; sfb++, idx++) {
1945 gain_cache =
powf(scale, -t) * s;
1948 coup->
gain[c][idx] = gain_cache;
1966 int num_excl_chan = 0;
1969 for (i = 0; i < 7; i++)
1973 return num_excl_chan / 7;
1985 int drc_num_bands = 1;
2006 for (i = 0; i < drc_num_bands; i++) {
2019 for (i = 0; i < drc_num_bands; i++) {
2089 int bottom, top, order, start, end,
size, inc;
2095 for (filt = 0; filt < tns->
n_filt[w]; filt++) {
2098 order = tns->
order[w][filt];
2107 if ((size = end - start) <= 0)
2119 for (m = 0; m <
size; m++, start += inc)
2120 for (i = 1; i <=
FFMIN(m, order); i++)
2121 coef[start] -= coef[start - i * inc] * lpc[i - 1];
2124 for (m = 0; m <
size; m++, start += inc) {
2125 tmp[0] = coef[start];
2126 for (i = 1; i <=
FFMIN(m, order); i++)
2127 coef[start] += tmp[i] * lpc[i - 1];
2128 for (i = order; i > 0; i--)
2129 tmp[i] = tmp[i - 1];
2151 memset(in, 0, 448 *
sizeof(
float));
2158 memset(in + 1024 + 576, 0, 448 *
sizeof(
float));
2173 float *predTime = sce->
ret;
2175 int16_t num_samples = 2048;
2177 if (ltp->
lag < 1024)
2178 num_samples = ltp->
lag + 1024;
2179 for (i = 0; i < num_samples; i++)
2181 memset(&predTime[i], 0, (2048 - i) *
sizeof(
float));
2190 for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
2191 sce->
coeffs[i] += predFreq[i];
2201 float *saved = sce->
saved;
2202 float *saved_ltp = sce->
coeffs;
2208 memcpy(saved_ltp, saved, 512 *
sizeof(
float));
2209 memset(saved_ltp + 576, 0, 448 *
sizeof(
float));
2211 for (i = 0; i < 64; i++)
2212 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * swindow[63 - i];
2214 memcpy(saved_ltp, ac->
buf_mdct + 512, 448 *
sizeof(
float));
2215 memset(saved_ltp + 576, 0, 448 *
sizeof(
float));
2217 for (i = 0; i < 64; i++)
2218 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * swindow[63 - i];
2221 for (i = 0; i < 512; i++)
2222 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * lwindow[511 - i];
2237 float *out = sce->
ret;
2238 float *saved = sce->
saved;
2243 float *temp = ac->
temp;
2248 for (i = 0; i < 1024; i += 128)
2263 memcpy( out, saved, 448 *
sizeof(
float));
2271 memcpy( out + 448 + 4*128, temp, 64 *
sizeof(
float));
2274 memcpy( out + 576, buf + 64, 448 *
sizeof(
float));
2280 memcpy( saved, temp + 64, 64 *
sizeof(
float));
2284 memcpy( saved + 448, buf + 7*128 + 64, 64 *
sizeof(
float));
2286 memcpy( saved, buf + 512, 448 *
sizeof(
float));
2287 memcpy( saved + 448, buf + 7*128 + 64, 64 *
sizeof(
float));
2289 memcpy( saved, buf + 512, 512 *
sizeof(
float));
2304 float *dest = target->
coeffs;
2305 const float *src = cce->
ch[0].
coeffs;
2306 int g,
i, group, k, idx = 0;
2309 "Dependent coupling is not supported together with LTP\n");
2313 for (i = 0; i < ics->
max_sfb; i++, idx++) {
2316 for (group = 0; group < ics->
group_len[
g]; group++) {
2317 for (k = offsets[i]; k < offsets[i + 1]; k++) {
2319 dest[group * 128 + k] += gain * src[group * 128 + k];
2340 const float *src = cce->
ch[0].
ret;
2341 float *dest = target->
ret;
2344 for (i = 0; i <
len; i++)
2345 dest[i] += gain * src[i];
2368 if (coup->
type[c] == type && coup->
id_select[c] == elem_id) {
2370 apply_coupling_method(ac, &cc->
ch[0], cce, index);
2375 apply_coupling_method(ac, &cc->
ch[1], cce, index++);
2389 for (type = 3; type >= 0; type--) {
2433 uint8_t layout_map[MAX_ELEM_ID*4][3];
2434 int layout_map_tags;
2476 int samples = 0, multiplier, audio_found = 0, pce_found = 0;
2502 if (!(che=
get_che(ac, elem_type, elem_id))) {
2504 elem_type, elem_id);
2511 switch (elem_type) {
2537 uint8_t layout_map[MAX_ELEM_ID*4][3];
2547 "Not evaluating a further program_config_element as this construct is dubious at best.\n");
2575 elem_type_prev = elem_type;
2590 samples <<= multiplier;
2598 if (ac->
oc[1].
status && audio_found) {
2611 int *got_frame_ptr,
AVPacket *avpkt)
2615 int buf_size = avpkt->
size;
2620 int new_extradata_size;
2623 &new_extradata_size);
2625 if (new_extradata) {
2632 memcpy(avctx->
extradata, new_extradata, new_extradata_size);
2649 for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)
2650 if (buf[buf_offset])
2653 return buf_size > buf_offset ? buf_consumed : buf_size;
2662 for (type = 0; type < 4; type++) {
2663 if (ac->
che[type][i])
2676 #define LOAS_SYNC_WORD 0x2b7
2702 int sync_extension = 0;
2703 int bits_consumed, esize;
2711 if (config_start_bit % 8) {
2713 "Non-byte-aligned audio-specific config", 1);
2719 gb->
buffer + (config_start_bit / 8),
2720 asclen, sync_extension);
2722 if (bits_consumed < 0)
2731 esize = (bits_consumed+7) / 8;
2746 return bits_consumed;
2752 int ret, audio_mux_version =
get_bits(gb, 1);
2755 if (audio_mux_version)
2760 if (audio_mux_version)
2768 "Multiple programs", 1);
2777 "Multiple layers", 1);
2782 if (!audio_mux_version) {
2813 if (audio_mux_version) {
2836 int mux_slot_length = 0;
2839 mux_slot_length += tmp;
2840 }
while (tmp == 255);
2841 return mux_slot_length;
2857 if (!use_same_mux) {
2862 "no decoder config found\n");
2870 }
else if (mux_slot_length_bytes * 8 + 256 <
get_bits_left(gb)) {
2872 "frame length mismatch %d << %d\n",
2882 int *got_frame_ptr,
AVPacket *avpkt)
2897 if (muxlength > avpkt->
size)
2921 "ADTS header detected, probably as result of configuration "
int predictor_initialized
static int output_configure(AACContext *ac, uint8_t layout_map[MAX_ELEM_ID *4][3], int tags, enum OCStatus oc_type, int get_new_frame)
Configure output channel order based on the current program configuration element.
static float * VMUL4S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale)
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce)
Conduct IMDCT and windowing.
#define CODEC_FLAG_BITEXACT
uint8_t use_kb_window[2]
If set, use Kaiser-Bessel window, otherwise use a sinus window.
static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
This structure describes decoded (raw) audio or video data.
static int decode_audio_specific_config(AACContext *ac, AVCodecContext *avctx, MPEG4AudioConfig *m4ac, const uint8_t *data, int bit_size, int sync_extension)
Decode audio specific configuration; reference: table 1.13.
static const int8_t tags_per_config[16]
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
static void push_output_configuration(AACContext *ac)
Save current output configuration if and only if it has been locked.
static void apply_intensity_stereo(AACContext *ac, ChannelElement *cpe, int ms_present)
intensity stereo decoding; reference: 4.6.8.2.3
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
av_cold void ff_kbd_window_init(float *window, float alpha, int n)
Generate a Kaiser-Bessel Derived Window.
static void skip_bits_long(GetBitContext *s, int n)
AVFrame * coded_frame
the picture in the bitstream
static float * VMUL2S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale)
static void align_get_bits(GetBitContext *s)
ChannelElement * che[4][MAX_ELEM_ID]
av_cold void ff_aac_sbr_init(void)
Initialize SBR.
static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, GetBitContext *gb)
Decode Individual Channel Stream info; reference: table 4.6.
static int assign_pair(struct elem_to_channel e2c_vec[MAX_ELEM_ID], uint8_t(*layout_map)[3], int offset, uint64_t left, uint64_t right, int pos)
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
static void apply_independent_coupling(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply independent channel coupling (applied after IMDCT).
static int frame_configure_elements(AVCodecContext *avctx)
static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, uint8_t(*layout_map)[3], GetBitContext *gb)
Decode program configuration element; reference: table 4.2.
Dynamic Range Control - decoded from the bitstream but not processed further.
float coef[8][4][TNS_MAX_ORDER]
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
enum RawDataBlockType type[8]
Type of channel element to be coupled - SCE or CPE.
Spectral data are scaled white noise not coded in the bitstream.
static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], GetBitContext *gb, const float sf[120], int pulse_present, const Pulse *pulse, const IndividualChannelStream *ics, enum BandType band_type[120])
Decode spectral data; reference: table 4.50.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int band_incr
Number of DRC bands greater than 1 having DRC info.
const uint8_t ff_aac_num_swb_128[]
av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr)
Close one SBR context.
const uint16_t * swb_offset
table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular wind...
N Error Resilient Long Term Prediction.
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
static av_always_inline int lcg_random(int previous_val)
linear congruential pseudorandom number generator
#define FFSWAP(type, a, b)
enum AVSampleFormat sample_fmt
audio sample format
static void apply_prediction(AACContext *ac, SingleChannelElement *sce)
Apply AAC-Main style frequency domain prediction.
static const uint8_t aac_channel_layout_map[7][5][3]
uint8_t layout_map[MAX_ELEM_ID *4][3]
Output configuration under trial specified by an inband PCE.
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
SingleChannelElement ch[2]
N Error Resilient Low Delay.
static VLC vlc_scalefactors
const uint8_t ff_aac_scalefactor_bits[121]
CouplingPoint
The point during decoding at which channel coupling is applied.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int num_coupled
number of target elements
#define AV_CH_LOW_FREQUENCY
int exclude_mask[MAX_CHANNELS]
Channels to be excluded from DRC processing.
static int aac_decode_frame_int(AVCodecContext *avctx, void *data, int *got_frame_ptr, GetBitContext *gb)
int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb_host, int crc, int cnt, int id_aac)
Decode Spectral Band Replication extension data; reference: table 4.55.
static int decode_band_types(AACContext *ac, enum BandType band_type[120], int band_type_run_end[120], GetBitContext *gb, IndividualChannelStream *ics)
Decode band types (section_data payload); reference: table 4.46.
SingleChannelElement * output_element[MAX_CHANNELS]
Points to each SingleChannelElement.
static int decode_pulses(Pulse *pulse, GetBitContext *gb, const uint16_t *swb_offset, int num_swb)
Decode pulse data; reference: table 4.7.
static int count_paired_channels(uint8_t(*layout_map)[3], int tags, int pos, int *current)
static int get_bits_count(const GetBitContext *s)
Scalefactor data are intensity stereo positions.
bitstream reader API header.
static int read_stream_mux_config(struct LATMContext *latmctx, GetBitContext *gb)
static av_cold int che_configure(AACContext *ac, enum ChannelPosition che_pos, int type, int id, int *channels)
Check for the channel element in the current channel position configuration.
int id_select[8]
element id
const float *const ff_aac_codebook_vector_vals[]
static int decode_dynamic_range(DynamicRangeControl *che_drc, GetBitContext *gb)
Decode dynamic range information; reference: table 4.52.
N Error Resilient Low Complexity.
ChannelElement * tag_che_map[4][MAX_ELEM_ID]
Output configuration set in a global header but not yet locked.
static int init(AVCodecParserContext *s)
AACContext aac_ctx
containing AACContext
static void apply_channel_coupling(AACContext *ac, ChannelElement *cc, enum RawDataBlockType type, int elem_id, enum CouplingPoint coupling_point, void(*apply_coupling_method)(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index))
channel coupling transformation interface
static uint32_t latm_get_value(GetBitContext *b)
static av_cold int aac_decode_close(AVCodecContext *avctx)
static int get_bits_left(GetBitContext *gb)
int dyn_rng_sgn[17]
DRC sign information; 0 - positive, 1 - negative.
float coeffs[1024]
coefficients for IMDCT
#define UPDATE_CACHE(name, gb)
PredictorState predictor_state[MAX_PREDICTORS]
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, ChannelElement *che, enum RawDataBlockType elem_type)
Decode extension data (incomplete); reference: table 4.51.
SpectralBandReplication sbr
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Calculate the product of two vectors of floats and store the result in a vector of floats...
enum CouplingPoint coupling_point
The point during decoding at which coupling is applied.
int frame_length_type
0/1 variable/fixed frame length
const uint8_t ff_aac_num_swb_1024[]
FmtConvertContext fmt_conv
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
float ff_aac_kbd_long_1024[1024]
Spectral Band Replication definitions and structures.
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
uint8_t max_sfb
number of scalefactor bands per group
static int latm_decode_frame(AVCodecContext *avctx, void *out, int *got_frame_ptr, AVPacket *avpkt)
void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, float *L, float *R)
Apply one SBR element to one AAC element.
#define LOAS_SYNC_WORD
11 bits LOAS sync word
AVCodec ff_aac_latm_decoder
#define CLOSE_READER(name, gb)
int num_swb
number of scalefactor window bands
#define AAC_INIT_VLC_STATIC(num, size)
int prog_ref_level
A reference level for the long-term program audio level for all channels combined.
Output configuration locked in place.
uint64_t channel_layout
Audio channel layout.
#define SKIP_BITS(name, gb, num)
#define POW_SF2_ZERO
ff_aac_pow2sf_tab index corresponding to pow(2, 0);
static const float cce_scale[]
N Error Resilient Scalable.
static int read_payload_length_info(struct LATMContext *ctx, GetBitContext *gb)
AAC Spectral Band Replication function declarations.
enum WindowSequence window_sequence[2]
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
static void pop_output_configuration(AACContext *ac)
Restore the previous output configuration if and only if the current configuration is unlocked...
int predictor_reset_group
static void reset_predictor_group(PredictorState *ps, int group_num)
int dyn_rng_ctl[17]
DRC magnitude information.
int initialized
initilized after a valid extradata was seen
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb, int ms_present)
Decode Mid/Side data; reference: table 4.54.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define LAST_SKIP_BITS(name, gb, num)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
AAC definitions and structures.
#define AV_CH_FRONT_LEFT_OF_CENTER
const uint8_t ff_tns_max_bands_1024[]
#define GET_VLC(code, name, gb, table, bits, max_depth)
If the vlc code is invalid and max_depth=1, then no bits will be removed.
static void cbrt_tableinit(void)
#define AV_CH_FRONT_CENTER
static void apply_dependent_coupling(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply dependent channel coupling (applied before IMDCT).
int pce_instance_tag
Indicates with which program the DRC info is associated.
static int decode_drc_channel_exclusions(DynamicRangeControl *che_drc, GetBitContext *gb)
Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4...
#define SHOW_UBITS(name, gb, num)
#define AV_CH_FRONT_RIGHT_OF_CENTER
int interpolation_scheme
Indicates the interpolation scheme used in the SBR QMF domain.
static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, GetBitContext *gb, MPEG4AudioConfig *m4ac, int channel_config)
Decode GA "General Audio" specific configuration; reference: table 4.1.
int ch_select[8]
[0] shared list of gains; [1] list of gains for right channel; [2] list of gains for left channel; [3...
static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe)
Mid/Side stereo decoding; reference: 4.6.8.1.3.
int frame_size
Number of samples per channel in an audio frame.
int frame_length
frame length for fixed frame length
int audio_mux_version_A
LATM syntax version.
int sample_rate
samples per second
float ff_aac_kbd_short_128[128]
static int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order, LPC_TYPE *lpc, int lpc_stride, int fail, int normalize)
Levinson-Durbin recursion.
static uint32_t cbrt_tab[1<< 13]
#define AV_CH_LAYOUT_NATIVE
Channel mask value used for AVCodecContext.request_channel_layout to indicate that the user requests ...
static void update_ltp(AACContext *ac, SingleChannelElement *sce)
Update the LTP buffer for next frame.
main external API structure.
static void close(AVCodecParserContext *s)
static int decode_ics(AACContext *ac, SingleChannelElement *sce, GetBitContext *gb, int common_window, int scale_flag)
Decode an individual_channel_stream payload; reference: table 4.44.
void(* butterflies_float)(float *restrict v1, float *restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
#define OPEN_READER(name, gb)
IndividualChannelStream ics
int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
Parse AAC frame header.
static av_always_inline float cbrtf(float x)
void(* imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
static void skip_bits(GetBitContext *s, int n)
#define FF_ARRAY_ELEMS(a)
static av_cold int latm_decode_init(AVCodecContext *avctx)
static void spectral_to_sample(AACContext *ac)
Convert spectral data to float samples, applying all supported tools as appropriate.
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define GET_CACHE(name, gb)
#define FF_INPUT_BUFFER_PADDING_SIZE
static int read_audio_mux_element(struct LATMContext *latmctx, GetBitContext *gb)
static int latm_decode_audio_specific_config(struct LATMContext *latmctx, GetBitContext *gb, int asclen)
static void apply_ltp(AACContext *ac, SingleChannelElement *sce)
Apply the long term prediction.
static float * VMUL2(float *dst, const float *v, unsigned idx, const float *scale)
OCStatus
Output configuration status.
N Error Resilient Bit-Sliced Arithmetic Coding.
av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr)
Initialize one SBR context.
struct AACContext AACContext
main AAC context
static void reset_all_predictors(PredictorState *ps)
const uint32_t ff_aac_scalefactor_code[121]
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static const char overread_err[]
void(* vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len)
Output configuration under trial specified by a frame header.
const uint8_t ff_tns_max_bands_128[]
static const uint64_t aac_channel_layout[8]
float ltp_state[3072]
time signal for LTP
int band_type_run_end[120]
band type run end points
float sf[120]
scalefactors
static const uint16_t scale[4]
#define AV_CH_BACK_CENTER
int band_top[17]
Indicates the top of the i-th DRC band in units of 4 spectral lines.
static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns, GetBitContext *gb, const IndividualChannelStream *ics)
Decode Temporal Noise Shaping data; reference: table 4.48.
Scalefactor data are intensity stereo positions.
static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe)
Decode a channel_pair_element; reference: table 4.4.
DynamicRangeControl che_drc
static av_always_inline void reset_predict_state(PredictorState *ps)
OutputConfiguration oc[2]
const uint8_t ff_aac_pred_sfb_max[]
uint8_t prediction_used[41]
common internal api header.
Single Channel Element - used for both SCE and LFE elements.
const uint16_t *const ff_swb_offset_1024[]
#define AVERROR_INVALIDDATA
static av_cold int aac_decode_init(AVCodecContext *avctx)
AVSampleFormat
Audio Sample Formats.
Individual Channel Stream.
float ff_aac_pow2sf_tab[428]
static ChannelElement * get_che(AACContext *ac, int type, int elem_id)
int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int bit_size, int sync_extension)
Parse MPEG-4 systems extradata to retrieve audio configuration.
static const float ltp_coef[8]
#define AVERROR_PATCHWELCOME
const uint16_t *const ff_aac_codebook_vector_idx[]
static void windowing_and_mdct_ltp(AACContext *ac, float *out, float *in, IndividualChannelStream *ics)
Apply windowing and MDCT to obtain the spectral coefficient from the predicted sample by LTP...
float(* scalarproduct_float)(const float *v1, const float *v2, int len)
Calculate the scalar product of two vectors of floats.
channel element - generic struct for SCE/CPE/CCE/LFE
static uint64_t sniff_channel_order(uint8_t(*layout_map)[3], int tags)
av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
#define CODEC_CAP_CHANNEL_CONF
Scalefactors and spectral data are all zero.
int channels
number of audio channels
const uint8_t ff_mpeg4audio_channels[8]
VLC_TYPE(* table)[2]
code, bits
static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, unsigned int global_gain, IndividualChannelStream *ics, enum BandType band_type[120], int band_type_run_end[120])
Decode scalefactors; reference: table 4.47.
enum BandType band_type[128]
band types
static int set_default_channel_config(AVCodecContext *avctx, uint8_t(*layout_map)[3], int *tags, int channel_config)
Set up channel positions based on a default channel configuration as specified in table 1...
static int sample_rate_idx(int rate)
static void decode_channel_map(uint8_t layout_map[][3], enum ChannelPosition type, GetBitContext *gb, int n)
Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit...
#define AV_CH_FRONT_RIGHT
static int skip_data_stream_element(AACContext *ac, GetBitContext *gb)
Skip data_stream_element; reference: table 4.10.
float ret_buf[2048]
PCM output buffer.
void ff_aac_tableinit(void)
int sbr
-1 implicit, 1 presence
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, GetBitContext *gb)
static void apply_tns(float coef[1024], TemporalNoiseShaping *tns, IndividualChannelStream *ics, int decode)
Decode Temporal Noise Shaping filter coefficients and apply all-pole filters; reference: 4...
static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che)
Decode coupling_channel_element; reference: table 4.8.
static int aac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
int ps
-1 implicit, 1 presence
int8_t used[MAX_LTP_LONG_SFB]
void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
static av_always_inline float flt16_trunc(float pf)
const uint16_t *const ff_swb_offset_128[]
static av_always_inline float flt16_even(float pf)
static const float *const tns_tmp2_map[4]
uint8_t ** extended_data
pointers to the data planes/channels.
uint64_t request_channel_layout
Request decoder to use this channel layout if it can (0 for default)
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static VLC vlc_spectral[11]
static int count_channels(uint8_t(*layout)[3], int tags)
void ff_init_ff_sine_windows(int index)
initialize the specified entry of ff_sine_windows
static av_always_inline float flt16_round(float pf)
static void decode_ltp(LongTermPrediction *ltp, GetBitContext *gb, uint8_t max_sfb)
Decode Long Term Prediction data; reference: table 4.xx.
static float * VMUL4(float *dst, const float *v, unsigned idx, const float *scale)
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)