84 #include "libavutil/opt.h"
102 #include "libavutil/intfloat.h"
120 enum OCStatus oc_type,
int get_new_frame);
122 #define overread_err "Input buffer exhausted before END element found\n"
127 for (i = 0; i < tags; i++) {
128 int syn_ele =
layout[i][0];
130 sum += (1 + (syn_ele ==
TYPE_CPE)) *
150 int type,
int id,
int *channels)
155 if (!ac->
che[type][
id]) {
172 if (ac->
che[type][
id])
185 for (type = 0; type < 4; type++) {
202 for (ch = 0; ch < avctx->
channels; ch++) {
219 uint64_t right,
int pos)
221 if (layout_map[offset][0] ==
TYPE_CPE) {
223 .av_position = left | right,
225 .elem_id = layout_map[
offset][1],
233 .elem_id = layout_map[
offset][1],
237 .av_position = right,
239 .elem_id = layout_map[offset + 1][1],
249 int num_pos_channels = 0;
253 for (i = *current; i < tags; i++) {
254 if (layout_map[i][2] != pos)
264 num_pos_channels += 2;
275 return num_pos_channels;
280 int i,
n, total_non_cc_elements;
282 int num_front_channels, num_side_channels, num_back_channels;
291 if (num_front_channels < 0)
295 if (num_side_channels < 0)
299 if (num_back_channels < 0)
303 if (num_front_channels & 1) {
307 .elem_id = layout_map[i][1],
311 num_front_channels--;
313 if (num_front_channels >= 4) {
318 num_front_channels -= 2;
320 if (num_front_channels >= 2) {
325 num_front_channels -= 2;
327 while (num_front_channels >= 2) {
332 num_front_channels -= 2;
335 if (num_side_channels >= 2) {
340 num_side_channels -= 2;
342 while (num_side_channels >= 2) {
347 num_side_channels -= 2;
350 while (num_back_channels >= 4) {
355 num_back_channels -= 2;
357 if (num_back_channels >= 2) {
362 num_back_channels -= 2;
364 if (num_back_channels) {
368 .elem_id = layout_map[i][1],
379 .elem_id = layout_map[i][1],
388 .elem_id = layout_map[i][1],
395 total_non_cc_elements = n = i;
398 for (i = 1; i <
n; i++)
399 if (e2c_vec[i - 1].av_position > e2c_vec[i].av_position) {
407 for (i = 0; i < total_non_cc_elements; i++) {
408 layout_map[i][0] = e2c_vec[i].
syn_ele;
409 layout_map[i][1] = e2c_vec[i].
elem_id;
411 if (e2c_vec[i].av_position != UINT64_MAX) {
424 ac->
oc[0] = ac->
oc[1];
435 ac->
oc[1] = ac->
oc[0];
450 uint8_t layout_map[MAX_ELEM_ID * 4][3],
int tags,
451 enum OCStatus oc_type,
int get_new_frame)
454 int i, channels = 0,
ret;
458 memcpy(ac->
oc[1].
layout_map, layout_map, tags *
sizeof(layout_map[0]));
466 for (i = 0; i < tags; i++) {
467 int type = layout_map[i][0];
468 int id = layout_map[i][1];
469 int position = layout_map[i][2];
476 if (ac->
oc[1].
m4ac.
ps == 1 && channels == 2) {
503 for (type = 3; type >= 0; type--) {
507 for (j = 0; j <= 1; j++) {
526 if (channel_config < 1 || channel_config > 7) {
528 "invalid default channel configuration (%d)\n",
534 *tags *
sizeof(*layout_map));
548 uint8_t layout_map[MAX_ELEM_ID*4][3];
555 &layout_map_tags, 2) < 0)
567 uint8_t layout_map[MAX_ELEM_ID * 4][3];
574 &layout_map_tags, 1) < 0)
662 layout_map[0][0] = syn_ele;
664 layout_map[0][2] =
type;
678 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc;
688 "Sample rate index in program config element does not "
689 "match the sample rate index configured by the container.\n");
706 if (
get_bits_left(gb) < 4 * (num_front + num_side + num_back + num_lfe + num_assoc_data + num_cc)) {
749 int extension_flag,
ret, ep_config, res_flags;
750 uint8_t layout_map[MAX_ELEM_ID*4][3];
766 if (channel_config == 0) {
768 tags =
decode_pce(avctx, m4ac, layout_map, gb);
773 &tags, channel_config)))
779 }
else if (m4ac->
sbr == 1 && m4ac->
ps == -1)
785 if (extension_flag) {
798 "AAC data resilience (flags %x)",
814 "epConfig %d", ep_config);
826 int ret, ep_config, res_flags;
827 uint8_t layout_map[MAX_ELEM_ID*4][3];
829 const int ELDEXT_TERM = 0;
842 "AAC data resilience (flags %x)",
853 while (
get_bits(gb, 4) != ELDEXT_TERM) {
867 &tags, channel_config)))
876 "epConfig %d", ep_config);
903 av_dlog(avctx,
"audio specific config size %d\n", bit_size >> 3);
904 for (i = 0; i < bit_size >> 3; i++)
905 av_dlog(avctx,
"%02x ", data[i]);
912 sync_extension)) < 0)
916 "invalid sampling rate index %d\n",
923 "invalid low delay sampling rate index %d\n",
947 "Audio object type %s%d",
948 m4ac->
sbr == 1 ?
"SBR+" :
"",
954 "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
971 union {
unsigned u;
int s; }
v = { previous_val * 1664525
u + 1013904223 };
994 if (92017 <= rate)
return 0;
995 else if (75132 <= rate)
return 1;
996 else if (55426 <= rate)
return 2;
997 else if (46009 <= rate)
return 3;
998 else if (37566 <= rate)
return 4;
999 else if (27713 <= rate)
return 5;
1000 else if (23004 <= rate)
return 6;
1001 else if (18783 <= rate)
return 7;
1002 else if (13856 <= rate)
return 8;
1003 else if (11502 <= rate)
return 9;
1004 else if (9391 <= rate)
return 10;
1015 #define AAC_INIT_VLC_STATIC(num, size) \
1016 INIT_VLC_STATIC(&vlc_spectral[num], 8, ff_aac_spectral_sizes[num], \
1017 ff_aac_spectral_bits[num], sizeof(ff_aac_spectral_bits[num][0]), \
1018 sizeof(ff_aac_spectral_bits[num][0]), \
1019 ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), \
1020 sizeof(ff_aac_spectral_codes[num][0]), \
1045 uint8_t layout_map[MAX_ELEM_ID*4][3];
1046 int layout_map_tags;
1155 "Invalid Predictor Reset Group.\n");
1196 "AAC LD is only defined for ONLY_LONG_SEQUENCE but "
1209 for (i = 0; i < 7; i++) {
1247 "Prediction is not allowed in AAC-LC.\n");
1252 "LTP in ER AAC LD not yet implemented.\n");
1263 "Number of scalefactor bands in group (%d) "
1264 "exceeds limit (%d).\n",
1291 while (k < ics->max_sfb) {
1294 int sect_band_type =
get_bits(gb, 4);
1295 if (sect_band_type == 12) {
1300 sect_len_incr =
get_bits(gb, bits);
1301 sect_end += sect_len_incr;
1306 if (sect_end > ics->
max_sfb) {
1308 "Number of bands (%d) exceeds limit (%d).\n",
1312 }
while (sect_len_incr == (1 << bits) - 1);
1313 for (; k < sect_end; k++) {
1314 band_type [idx] = sect_band_type;
1315 band_type_run_end[idx++] = sect_end;
1333 unsigned int global_gain,
1336 int band_type_run_end[120])
1339 int offset[3] = { global_gain, global_gain - 90, 0 };
1343 for (i = 0; i < ics->
max_sfb;) {
1344 int run_end = band_type_run_end[idx];
1345 if (band_type[idx] ==
ZERO_BT) {
1346 for (; i < run_end; i++, idx++)
1350 for (; i < run_end; i++, idx++) {
1351 offset[2] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1352 clipped_offset = av_clip(offset[2], -155, 100);
1353 if (offset[2] != clipped_offset) {
1355 "If you heard an audible artifact, there may be a bug in the decoder. "
1356 "Clipped intensity stereo position (%d -> %d)",
1357 offset[2], clipped_offset);
1361 }
else if (band_type[idx] ==
NOISE_BT) {
1362 for (; i < run_end; i++, idx++) {
1363 if (noise_flag-- > 0)
1364 offset[1] +=
get_bits(gb, 9) - 256;
1366 offset[1] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1367 clipped_offset = av_clip(offset[1], -100, 155);
1368 if (offset[1] != clipped_offset) {
1370 "If you heard an audible artifact, there may be a bug in the decoder. "
1371 "Clipped noise gain (%d -> %d)",
1372 offset[1], clipped_offset);
1377 for (; i < run_end; i++, idx++) {
1378 offset[0] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
1379 if (offset[0] > 255
U) {
1381 "Scalefactor (%d) out of range.\n", offset[0]);
1396 const uint16_t *swb_offset,
int num_swb)
1401 if (pulse_swb >= num_swb)
1403 pulse->
pos[0] = swb_offset[pulse_swb];
1405 if (pulse->
pos[0] > 1023)
1408 for (i = 1; i < pulse->
num_pulse; i++) {
1410 if (pulse->
pos[i] > 1023)
1425 int w,
filt, i, coef_len, coef_res, coef_compress;
1432 for (filt = 0; filt < tns->
n_filt[w]; filt++) {
1436 if ((tns->
order[w][filt] =
get_bits(gb, 5 - 2 * is8)) > tns_max_order) {
1438 "TNS filter order %d is greater than maximum %d.\n",
1439 tns->
order[w][filt], tns_max_order);
1443 if (tns->
order[w][filt]) {
1446 coef_len = coef_res + 3 - coef_compress;
1447 tmp2_idx = 2 * coef_compress + coef_res;
1449 for (i = 0; i < tns->
order[w][
filt]; i++)
1469 if (ms_present == 1) {
1474 }
else if (ms_present == 2) {
1480 static inline float *
VMUL2(
float *dst,
const float *
v,
unsigned idx,
1484 *dst++ = v[idx & 15] *
s;
1485 *dst++ = v[idx>>4 & 15] *
s;
1491 static inline float *
VMUL4(
float *dst,
const float *
v,
unsigned idx,
1495 *dst++ = v[idx & 3] *
s;
1496 *dst++ = v[idx>>2 & 3] *
s;
1497 *dst++ = v[idx>>4 & 3] *
s;
1498 *dst++ = v[idx>>6 & 3] *
s;
1504 static inline float *
VMUL2S(
float *dst,
const float *
v,
unsigned idx,
1505 unsigned sign,
const float *
scale)
1510 s0.
i ^= sign >> 1 << 31;
1513 *dst++ = v[idx & 15] * s0.
f;
1514 *dst++ = v[idx>>4 & 15] * s1.
f;
1521 static inline float *
VMUL4S(
float *dst,
const float *
v,
unsigned idx,
1522 unsigned sign,
const float *
scale)
1524 unsigned nz = idx >> 12;
1528 t.
i = s.
i ^ (sign & 1
U<<31);
1529 *dst++ = v[idx & 3] * t.
f;
1531 sign <<= nz & 1; nz >>= 1;
1532 t.
i = s.
i ^ (sign & 1
U<<31);
1533 *dst++ = v[idx>>2 & 3] * t.
f;
1535 sign <<= nz & 1; nz >>= 1;
1536 t.
i = s.
i ^ (sign & 1
U<<31);
1537 *dst++ = v[idx>>4 & 3] * t.
f;
1540 t.
i = s.
i ^ (sign & 1
U<<31);
1541 *dst++ = v[idx>>6 & 3] * t.
f;
1561 int pulse_present,
const Pulse *pulse,
1565 int i, k,
g, idx = 0;
1568 float *coef_base = coef;
1571 memset(coef + g * 128 + offsets[ics->
max_sfb], 0,
1572 sizeof(
float) * (c - offsets[ics->
max_sfb]));
1577 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1578 const unsigned cbt_m1 = band_type[idx] - 1;
1579 float *cfo = coef + offsets[
i];
1580 int off_len = offsets[i + 1] - offsets[
i];
1584 for (group = 0; group < g_len; group++, cfo+=128) {
1585 memset(cfo, 0, off_len *
sizeof(
float));
1587 }
else if (cbt_m1 ==
NOISE_BT - 1) {
1588 for (group = 0; group < g_len; group++, cfo+=128) {
1592 for (k = 0; k < off_len; k++) {
1598 scale = sf[idx] / sqrtf(band_energy);
1607 switch (cbt_m1 >> 1) {
1609 for (group = 0; group < g_len; group++, cfo+=128) {
1619 cb_idx = cb_vector_idx[code];
1620 cf =
VMUL4(cf, vq, cb_idx, sf + idx);
1626 for (group = 0; group < g_len; group++, cfo+=128) {
1638 cb_idx = cb_vector_idx[code];
1639 nnz = cb_idx >> 8 & 15;
1642 cf =
VMUL4S(cf, vq, cb_idx, bits, sf + idx);
1648 for (group = 0; group < g_len; group++, cfo+=128) {
1658 cb_idx = cb_vector_idx[code];
1659 cf =
VMUL2(cf, vq, cb_idx, sf + idx);
1666 for (group = 0; group < g_len; group++, cfo+=128) {
1678 cb_idx = cb_vector_idx[code];
1679 nnz = cb_idx >> 8 & 15;
1680 sign = nnz ?
SHOW_UBITS(
re, gb, nnz) << (cb_idx >> 12) : 0;
1682 cf =
VMUL2S(cf, vq, cb_idx, sign, sf + idx);
1688 for (group = 0; group < g_len; group++, cfo+=128) {
1690 uint32_t *icf = (uint32_t *) cf;
1709 cb_idx = cb_vector_idx[code];
1715 for (j = 0; j < 2; j++) {
1737 unsigned v = ((
const uint32_t*)vq)[cb_idx & 15];
1738 *icf++ = (bits & 1
U<<31) | v;
1755 if (pulse_present) {
1757 for (i = 0; i < pulse->
num_pulse; i++) {
1758 float co = coef_base[ pulse->
pos[
i] ];
1759 while (offsets[idx + 1] <= pulse->
pos[i])
1761 if (band_type[idx] !=
NOISE_BT && sf[idx]) {
1762 float ico = -pulse->
amp[
i];
1765 ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico);
1767 coef_base[ pulse->
pos[
i] ] =
cbrtf(fabsf(ico)) * ico * sf[idx];
1778 tmp.
i = (tmp.
i + 0x00008000
U) & 0xFFFF0000U;
1786 tmp.
i = (tmp.
i + 0x00007FFF
U + (tmp.
i & 0x00010000
U >> 16)) & 0xFFFF0000
U;
1794 pun.
i &= 0xFFFF0000
U;
1801 const float a = 0.953125;
1802 const float alpha = 0.90625;
1806 float r0 = ps->
r0, r1 = ps->
r1;
1807 float cor0 = ps->
cor0, cor1 = ps->
cor1;
1808 float var0 = ps->
var0, var1 = ps->
var1;
1810 k1 = var0 > 1 ? cor0 *
flt16_even(a / var0) : 0;
1811 k2 = var1 > 1 ? cor1 *
flt16_even(a / var1) : 0;
1846 k < sce->ics.swb_offset[sfb + 1];
1875 int global_gain, eld_syntax, er_syntax, pulse_present = 0;
1891 if (!common_window && !scale_flag) {
1905 if (!eld_syntax && (pulse_present =
get_bits1(gb))) {
1908 "Pulse tool not allowed in eight short sequence.\n");
1913 "Pulse data corrupt or invalid.\n");
1918 if (tns->
present && !er_syntax)
1927 if (tns->
present && er_syntax)
1950 int g,
i, group, idx = 0;
1953 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1957 for (group = 0; group < ics->
group_len[
g]; group++) {
1959 ch1 + group * 128 + offsets[i],
1960 offsets[i+1] - offsets[i]);
1983 int g, group,
i, idx = 0;
1987 for (i = 0; i < ics->
max_sfb;) {
1991 for (; i < bt_run_end; i++, idx++) {
1992 c = -1 + 2 * (sce1->
band_type[idx] - 14);
1994 c *= 1 - 2 * cpe->
ms_mask[idx];
1995 scale = c * sce1->
sf[idx];
1996 for (group = 0; group < ics->
group_len[
g]; group++)
1998 coef0 + group * 128 + offsets[i],
2000 offsets[i + 1] - offsets[i]);
2004 idx += bt_run_end -
i;
2020 int i,
ret, common_window, ms_present = 0;
2023 common_window = eld_syntax ||
get_bits1(gb);
2024 if (common_window) {
2035 if (ms_present == 3) {
2038 }
else if (ms_present)
2041 if ((ret =
decode_ics(ac, &cpe->
ch[0], gb, common_window, 0)))
2043 if ((ret =
decode_ics(ac, &cpe->
ch[1], gb, common_window, 0)))
2046 if (common_window) {
2060 1.09050773266525765921,
2061 1.18920711500272106672,
2096 scale = cce_scale[
get_bits(gb, 2)];
2101 for (c = 0; c < num_gain; c++) {
2105 float gain_cache = 1.0;
2108 gain = cge ?
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60: 0;
2109 gain_cache =
powf(scale, -gain);
2112 coup->
gain[
c][0] = gain_cache;
2115 for (sfb = 0; sfb < sce->
ics.
max_sfb; sfb++, idx++) {
2126 gain_cache =
powf(scale, -t) *
s;
2129 coup->
gain[
c][idx] = gain_cache;
2147 int num_excl_chan = 0;
2150 for (i = 0; i < 7; i++)
2154 return num_excl_chan / 7;
2166 int drc_num_bands = 1;
2187 for (i = 0; i < drc_num_bands; i++) {
2200 for (i = 0; i < drc_num_bands; i++) {
2211 int i, major, minor;
2218 for(i=0; i+1<
sizeof(
buf) && len>=8; i++, len-=8)
2225 if (sscanf(buf,
"libfaac %d.%d", &major, &minor) == 2){
2304 for (filt = 0; filt < tns->
n_filt[w]; filt++) {
2316 if ((size = end - start) <= 0)
2328 for (m = 0; m <
size; m++, start += inc)
2329 for (i = 1; i <=
FFMIN(m, order); i++)
2330 coef[start] -= coef[start - i * inc] * lpc[i - 1];
2333 for (m = 0; m <
size; m++, start += inc) {
2334 tmp[0] = coef[
start];
2335 for (i = 1; i <=
FFMIN(m, order); i++)
2336 coef[start] += tmp[i] * lpc[i - 1];
2337 for (i = order; i > 0; i--)
2338 tmp[i] = tmp[i - 1];
2360 memset(in, 0, 448 *
sizeof(
float));
2367 memset(in + 1024 + 576, 0, 448 *
sizeof(
float));
2382 float *predTime = sce->
ret;
2384 int16_t num_samples = 2048;
2386 if (ltp->
lag < 1024)
2387 num_samples = ltp->
lag + 1024;
2388 for (i = 0; i < num_samples; i++)
2390 memset(&predTime[i], 0, (2048 - i) *
sizeof(
float));
2399 for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
2400 sce->
coeffs[i] += predFreq[i];
2410 float *saved = sce->
saved;
2411 float *saved_ltp = sce->
coeffs;
2417 memcpy(saved_ltp, saved, 512 *
sizeof(
float));
2418 memset(saved_ltp + 576, 0, 448 *
sizeof(
float));
2420 for (i = 0; i < 64; i++)
2421 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * swindow[63 - i];
2423 memcpy(saved_ltp, ac->
buf_mdct + 512, 448 *
sizeof(
float));
2424 memset(saved_ltp + 576, 0, 448 *
sizeof(
float));
2426 for (i = 0; i < 64; i++)
2427 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * swindow[63 - i];
2430 for (i = 0; i < 512; i++)
2431 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * lwindow[511 - i];
2447 float *saved = sce->
saved;
2457 for (i = 0; i < 1024; i += 128)
2472 memcpy( out, saved, 448 *
sizeof(
float));
2480 memcpy( out + 448 + 4*128, temp, 64 *
sizeof(
float));
2483 memcpy( out + 576, buf + 64, 448 *
sizeof(
float));
2489 memcpy( saved, temp + 64, 64 *
sizeof(
float));
2493 memcpy( saved + 448, buf + 7*128 + 64, 64 *
sizeof(
float));
2495 memcpy( saved, buf + 512, 448 *
sizeof(
float));
2496 memcpy( saved + 448, buf + 7*128 + 64, 64 *
sizeof(
float));
2498 memcpy( saved, buf + 512, 512 *
sizeof(
float));
2507 float *saved = sce->
saved;
2518 memcpy(saved, buf + 256, 256 *
sizeof(
float));
2525 float *saved = sce->
saved;
2530 const int n2 = n >> 1;
2531 const int n4 = n >> 2;
2538 for (i = 0; i < n2; i+=2) {
2540 temp = in[
i ]; in[
i ] = -in[n - 1 -
i]; in[n - 1 -
i] =
temp;
2541 temp = -in[i + 1]; in[i + 1] = in[n - 2 -
i]; in[n - 2 -
i] =
temp;
2544 for (i = 0; i <
n; i+=2) {
2554 for (i = n4; i < n2; i ++) {
2555 out[i - n4] = buf[n2 - 1 -
i] * window[i - n4] +
2556 saved[ i + n2] * window[i + n - n4] +
2557 -saved[ n + n2 - 1 -
i] * window[i + 2*n - n4] +
2558 -saved[2*n + n2 +
i] * window[i + 3*n - n4];
2560 for (i = 0; i < n2; i ++) {
2561 out[n4 +
i] = buf[
i] * window[i + n2 - n4] +
2562 -saved[ n - 1 -
i] * window[i + n2 + n - n4] +
2563 -saved[ n +
i] * window[i + n2 + 2*n - n4] +
2564 saved[2*n + n - 1 -
i] * window[i + n2 + 3*n - n4];
2566 for (i = 0; i < n4; i ++) {
2567 out[n2 + n4 +
i] = buf[ i + n2] * window[i + n - n4] +
2568 -saved[ n2 - 1 -
i] * window[i + 2*n - n4] +
2569 -saved[ n + n2 +
i] * window[i + 3*n - n4];
2573 memmove(saved + n, saved, 2 * n *
sizeof(
float));
2574 memcpy( saved, buf, n *
sizeof(
float));
2588 float *dest = target->
coeffs;
2590 int g,
i, group, k, idx = 0;
2593 "Dependent coupling is not supported together with LTP\n");
2597 for (i = 0; i < ics->
max_sfb; i++, idx++) {
2600 for (group = 0; group < ics->
group_len[
g]; group++) {
2601 for (k = offsets[i]; k < offsets[i + 1]; k++) {
2603 dest[group * 128 + k] += gain * src[group * 128 + k];
2625 float *dest = target->
ret;
2628 for (i = 0; i <
len; i++)
2629 dest[i] += gain * src[i];
2652 if (coup->
type[c] == type && coup->
id_select[c] == elem_id) {
2654 apply_coupling_method(ac, &cc->
ch[0], cce, index);
2659 apply_coupling_method(ac, &cc->
ch[1], cce, index++);
2684 for (type = 3; type >= 0; type--) {
2728 uint8_t layout_map[MAX_ELEM_ID*4][3];
2729 int layout_map_tags,
ret;
2737 "More than one AAC RDB per ADTS frame");
2760 layout_map_tags = 2;
2761 layout_map[0][0] = layout_map[1][0] =
TYPE_SCE;
2763 layout_map[0][1] = 0;
2764 layout_map[1][1] = 1;
2805 if (chan_config < 0 || chan_config >= 8) {
2813 if (!(che=
get_che(ac, elem_type, elem_id))) {
2815 "channel element %d.%d is not allocated\n",
2816 elem_type, elem_id);
2821 switch (elem_type) {
2852 int samples = 0, multiplier, audio_found = 0, pce_found = 0;
2853 int is_dmono, sce_count = 0;
2878 if (!(che=
get_che(ac, elem_type, elem_id))) {
2880 elem_type, elem_id);
2887 switch (elem_type) {
2914 uint8_t layout_map[MAX_ELEM_ID*4][3];
2924 "Not evaluating a further program_config_element as this construct is dubious at best.\n");
2953 elem_type_prev = elem_type;
2968 samples <<= multiplier;
2970 is_dmono = ac->
dmono_mode && sce_count == 2 &&
2977 *got_frame_ptr = !!samples;
2986 if (ac->
oc[1].
status && audio_found) {
2995 if (side && side_size>=4)
3005 int *got_frame_ptr,
AVPacket *avpkt)
3009 int buf_size = avpkt->
size;
3014 int new_extradata_size;
3017 &new_extradata_size);
3018 int jp_dualmono_size;
3023 if (new_extradata && 0) {
3030 memcpy(avctx->
extradata, new_extradata, new_extradata_size);
3041 if (jp_dualmono && jp_dualmono_size > 0)
3046 if (INT_MAX / 8 <= buf_size)
3066 for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)
3067 if (buf[buf_offset])
3070 return buf_size > buf_offset ? buf_consumed : buf_size;
3079 for (type = 0; type < 4; type++) {
3080 if (ac->
che[type][i])
3094 #define LOAS_SYNC_WORD 0x2b7
3120 int sync_extension = 0;
3121 int bits_consumed, esize;
3129 if (config_start_bit % 8) {
3131 "Non-byte-aligned audio-specific config");
3137 gb->
buffer + (config_start_bit / 8),
3138 asclen, sync_extension);
3140 if (bits_consumed < 0)
3154 esize = (bits_consumed+7) / 8;
3169 return bits_consumed;
3178 if (audio_mux_version)
3183 if (audio_mux_version)
3203 if (!audio_mux_version) {
3234 if (audio_mux_version) {
3257 int mux_slot_length = 0;
3260 mux_slot_length += tmp;
3261 }
while (tmp == 255);
3262 return mux_slot_length;
3278 if (!use_same_mux) {
3283 "no decoder config found\n");
3291 }
else if (mux_slot_length_bytes * 8 + 256 <
get_bits_left(gb)) {
3293 "frame length mismatch %d << %d\n",
3303 int *got_frame_ptr,
AVPacket *avpkt)
3318 if (muxlength > avpkt->
size)
3342 "ADTS header detected, probably as result of configuration "
3378 #define AACDEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
3380 {
"dual_mono_mode",
"Select the channel to decode for dual mono",
int predictor_initialized
static int decode_fill(AACContext *ac, GetBitContext *gb, int len)
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)
static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce)
Conduct IMDCT and windowing.
#define AVERROR_PATCHWELCOME
uint8_t use_kb_window[2]
If set, use Kaiser-Bessel window, otherwise use a sine 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 void imdct_and_windowing_eld(AACContext *ac, SingleChannelElement *sce)
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.
#define AV_LOG_WARNING
Something somehow does not look correct.
av_cold void ff_kbd_window_init(float *window, float alpha, int n)
Generate a Kaiser-Bessel Derived Window.
#define LIBAVUTIL_VERSION_INT
static void skip_bits_long(GetBitContext *s, int n)
static av_cold int init(AVCodecContext *avctx)
static float * VMUL2S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale)
ChannelElement * che[4][MAX_ELEM_ID]
static void imdct_and_windowing_ld(AACContext *ac, SingleChannelElement *sce)
av_cold void ff_aac_sbr_init(void)
Initialize SBR.
uint8_t ** extended_data
pointers to the data planes/channels.
static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, GetBitContext *gb)
Decode Individual Channel Stream info; reference: table 4.6.
float(* scalarproduct_float)(const float *v1, const float *v2, int len)
Calculate the scalar product of two vectors of floats.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
void(* update_ltp)(AACContext *ac, SingleChannelElement *sce)
void(* imdct_and_windowing)(AACContext *ac, SingleChannelElement *sce)
#define AACDEC_FLAGS
AVOptions for Japanese DTV specific extensions (ADTS only)
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)
void(* vector_fmul_reverse)(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...
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]
Reference: libavcodec/aacdec.c.
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.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
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 *ptr)
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.
int dmono_mode
0->not dmono, 1->use first channel, 2->use second channel
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.
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Overlap/add with window function.
const char * av_default_item_name(void *ctx)
Return the context name.
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]
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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]
const uint16_t *const ff_swb_offset_512[]
static const uint8_t offset[511][2]
static av_cold int end(AVCodecContext *avctx)
N Error Resilient Low Delay.
static int aac_decode_frame_int(AVCodecContext *avctx, void *data, int *got_frame_ptr, GetBitContext *gb, AVPacket *avpkt)
static VLC vlc_scalefactors
const uint8_t ff_aac_scalefactor_bits[121]
CouplingPoint
The point during decoding at which channel coupling is applied.
const char * name
Name of the codec implementation.
int num_coupled
number of target elements
#define AV_CH_LOW_FREQUENCY
int exclude_mask[MAX_CHANNELS]
Channels to be excluded from DRC processing.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
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)
struct AVCodecInternal * internal
Private context used for internal data.
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.
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
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.
#define FFSWAP(type, a, b)
N Error Resilient Low Complexity.
ChannelElement * tag_che_map[4][MAX_ELEM_ID]
const OptionDef options[]
Output configuration set in a global header but not yet locked.
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)
static double alpha(void *priv, double x, double y)
PredictorState predictor_state[MAX_PREDICTORS]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
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(* 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. ...
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
float ff_aac_kbd_long_1024[1024]
Spectral Band Replication definitions and structures.
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
Libavcodec external API header.
#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[]
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
N Error Resilient Scalable.
#define FF_ARRAY_ELEMS(a)
static int read_payload_length_info(struct LATMContext *ctx, GetBitContext *gb)
AAC Spectral Band Replication function declarations.
enum WindowSequence window_sequence[2]
const uint8_t ff_aac_num_swb_512[]
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
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
static void reset_predictor_group(PredictorState *ps, int group_num)
int dyn_rng_ctl[17]
DRC magnitude information.
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int initialized
initialized after a valid extradata was seen
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.
void ff_aacdec_init_mips(AACContext *c)
const float ff_aac_eld_window[1920]
#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
static void flush(AVCodecContext *avctx)
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 force_dmono_mode
0->not dmono, 1->use first channel, 2->use second channel
AVSampleFormat
Audio Sample Formats.
#define AV_LOG_INFO
Standard information.
int warned_num_aac_frames
int audio_mux_version_A
LATM syntax version.
typedef void(RENAME(mix_any_func_type))
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]
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#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.
#define AV_EF_EXPLODE
abort decoding on minor error detection
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#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)
Describe the class of an AVClass context structure.
static void skip_bits(GetBitContext *s, int n)
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.
static const AVClass aac_decoder_class
static av_always_inline int lcg_random(unsigned previous_val)
linear congruential pseudorandom number generator
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Recommmends skipping the specified number of samples.
#define GET_CACHE(name, gb)
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.
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
N Error Resilient Bit-Sliced Arithmetic Coding.
av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr)
Initialize one SBR 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.
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]
static void imdct_and_window(TwinVQContext *tctx, enum TwinVQFrameType ftype, int wtype, float *in, float *prev, int ch)
float ltp_state[3072]
time signal for LTP
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static const int8_t filt[NUMTAPS]
#define FF_DEBUG_PICT_INFO
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
av_cold void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
int band_top[17]
Indicates the top of the i-th DRC band in units of 4 spectral lines.
static void aacdec_init(AACContext *ac)
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.
N Error Resilient Enhanced Low Delay.
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]
An AV_PKT_DATA_JP_DUALMONO side data packet indicates that the packet may contain "dual mono" audio s...
const uint8_t ff_aac_pred_sfb_max[]
void(* apply_ltp)(AACContext *ac, SingleChannelElement *sce)
uint8_t prediction_used[41]
common internal api header.
Single Channel Element - used for both SCE and LFE elements.
#define CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
const uint16_t *const ff_swb_offset_1024[]
static av_cold int aac_decode_init(AVCodecContext *avctx)
Individual Channel Stream.
float ff_aac_pow2sf_tab[428]
float ff_aac_kbd_long_512[512]
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]
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...
channel element - generic struct for SCE/CPE/CCE/LFE
void(* windowing_and_mdct_ltp)(AACContext *ac, float *out, float *in, IndividualChannelStream *ics)
static int aac_decode_er_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, GetBitContext *gb)
#define AVERROR_INVALIDDATA
static uint64_t sniff_channel_order(uint8_t(*layout_map)[3], int tags)
av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
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.
void(* apply_tns)(float coef[1024], TemporalNoiseShaping *tns, IndividualChannelStream *ics, int decode)
static const uint8_t * align_get_bits(GetBitContext *s)
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.
static enum AVSampleFormat sample_fmts[]
static int decode_eld_specific_config(AACContext *ac, AVCodecContext *avctx, GetBitContext *gb, MPEG4AudioConfig *m4ac, int channel_config)
float ret_buf[2048]
PCM output buffer.
void ff_aac_tableinit(void)
int sbr
-1 implicit, 1 presence
static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, GetBitContext *gb)
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
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.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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]
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]
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
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)
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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)