115 static const char overread_err[] =
"Input buffer exhausted before END element found\n";
168 int i, type, sum = 0;
170 for (type = 0; type < 4; type++) {
193 int type,
int id,
int *channels)
197 if (che_pos[type][
id]) {
198 if (!ac->
che[type][
id]) {
211 if (ac->
che[type][
id])
229 int channel_config,
enum OCStatus oc_type)
232 int i, type, channels = 0, ret;
234 if (new_che_pos != che_pos)
235 memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID *
sizeof(new_che_pos[0][0]));
237 if (channel_config) {
246 memset(ac->
tag_che_map, 0, 4 * MAX_ELEM_ID *
sizeof(ac->
che[0][0]));
260 for (type = 0; type < 4; type++) {
307 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc, sampling_index;
314 av_log(avctx,
AV_LOG_WARNING,
"Sample rate index in program config element does not match the sample rate index configured by the container.\n");
364 if (channel_config < 1 || channel_config > 7) {
381 if (channel_config != 2)
383 if (channel_config > 1)
385 if (channel_config == 4)
387 if (channel_config > 4)
388 new_che_pos[
TYPE_CPE][(channel_config == 7) + 1]
390 if (channel_config > 5)
392 if (channel_config == 7)
412 int extension_flag, ret;
427 memset(new_che_pos, 0, 4 *
MAX_ELEM_ID *
sizeof(new_che_pos[0][0]));
428 if (channel_config == 0) {
430 if ((ret =
decode_pce(avctx, m4ac, new_che_pos, gb)))
439 }
else if (m4ac->
sbr == 1 && m4ac->
ps == -1)
445 if (extension_flag) {
481 const uint8_t *
data,
int bit_size,
518 av_dlog(avctx,
"AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n",
534 return previous_val * 1664525 + 1013904223;
556 if (92017 <= rate)
return 0;
557 else if (75132 <= rate)
return 1;
558 else if (55426 <= rate)
return 2;
559 else if (46009 <= rate)
return 3;
560 else if (37566 <= rate)
return 4;
561 else if (27713 <= rate)
return 5;
562 else if (23004 <= rate)
return 6;
563 else if (18783 <= rate)
return 7;
564 else if (13856 <= rate)
return 8;
565 else if (11502 <= rate)
return 9;
566 else if (9391 <= rate)
return 10;
577 #define AAC_INIT_VLC_STATIC(num, size) \
578 INIT_VLC_STATIC(&vlc_spectral[num], 8, ff_aac_spectral_sizes[num], \
579 ff_aac_spectral_bits[num], sizeof( ff_aac_spectral_bits[num][0]), sizeof( ff_aac_spectral_bits[num][0]), \
580 ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), sizeof(ff_aac_spectral_codes[num][0]), \
587 float output_scale_factor;
626 output_scale_factor = 1.0 / 32768.0;
629 output_scale_factor = 1.0;
745 for (i = 0; i < 7; i++) {
783 "Number of scalefactor bands in group (%d) exceeds limit (%d).\n",
807 while (k < ics->max_sfb) {
808 uint8_t sect_end = k;
810 int sect_band_type =
get_bits(gb, 4);
811 if (sect_band_type == 12) {
817 sect_end += sect_len_incr;
824 "Number of bands (%d) exceeds limit (%d).\n",
828 }
while (sect_len_incr == (1 << bits) - 1);
829 for (; k < sect_end; k++) {
830 band_type [idx] = sect_band_type;
831 band_type_run_end[idx++] = sect_end;
849 unsigned int global_gain,
852 int band_type_run_end[120])
855 int offset[3] = { global_gain, global_gain - 90, 0 };
858 static const char *sf_str[3] = {
"Global gain",
"Noise gain",
"Intensity stereo position" };
860 for (i = 0; i < ics->
max_sfb;) {
861 int run_end = band_type_run_end[idx];
862 if (band_type[idx] ==
ZERO_BT) {
863 for (; i < run_end; i++, idx++)
866 for (; i < run_end; i++, idx++) {
867 offset[2] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
868 clipped_offset = av_clip(offset[2], -155, 100);
869 if (offset[2] != clipped_offset) {
871 "position clipped (%d -> %d).\nIf you heard an "
872 "audible artifact, there may be a bug in the "
873 "decoder. ", offset[2], clipped_offset);
877 }
else if (band_type[idx] ==
NOISE_BT) {
878 for (; i < run_end; i++, idx++) {
879 if (noise_flag-- > 0)
882 offset[1] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
883 clipped_offset = av_clip(offset[1], -100, 155);
884 if (offset[1] != clipped_offset) {
886 "(%d -> %d).\nIf you heard an audible "
887 "artifact, there may be a bug in the decoder. ",
888 offset[1], clipped_offset);
893 for (; i < run_end; i++, idx++) {
894 offset[0] +=
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60;
895 if (offset[0] > 255
U) {
897 "%s (%d) out of range.\n", sf_str[0], offset[0]);
912 const uint16_t *swb_offset,
int num_swb)
917 if (pulse_swb >= num_swb)
919 pulse->
pos[0] = swb_offset[pulse_swb];
921 if (pulse->
pos[0] > 1023)
926 if (pulse->
pos[i] > 1023)
941 int w, filt, i, coef_len, coef_res, coef_compress;
948 for (filt = 0; filt < tns->
n_filt[w]; filt++) {
952 if ((tns->
order[w][filt] =
get_bits(gb, 5 - 2 * is8)) > tns_max_order) {
954 tns->
order[w][filt], tns_max_order);
955 tns->
order[w][filt] = 0;
958 if (tns->
order[w][filt]) {
961 coef_len = coef_res + 3 - coef_compress;
962 tmp2_idx = 2 * coef_compress + coef_res;
964 for (i = 0; i < tns->
order[w][filt]; i++)
984 if (ms_present == 1) {
987 }
else if (ms_present == 2) {
993 static inline float *
VMUL2(
float *dst,
const float *
v,
unsigned idx,
997 *dst++ = v[idx & 15] * s;
998 *dst++ = v[idx>>4 & 15] * s;
1004 static inline float *
VMUL4(
float *dst,
const float *
v,
unsigned idx,
1008 *dst++ = v[idx & 3] * s;
1009 *dst++ = v[idx>>2 & 3] * s;
1010 *dst++ = v[idx>>4 & 3] * s;
1011 *dst++ = v[idx>>6 & 3] * s;
1017 static inline float *
VMUL2S(
float *dst,
const float *
v,
unsigned idx,
1018 unsigned sign,
const float *
scale)
1023 s0.
i ^= sign >> 1 << 31;
1026 *dst++ = v[idx & 15] * s0.
f;
1027 *dst++ = v[idx>>4 & 15] * s1.
f;
1034 static inline float *
VMUL4S(
float *dst,
const float *
v,
unsigned idx,
1035 unsigned sign,
const float *
scale)
1037 unsigned nz = idx >> 12;
1041 t.
i = s.
i ^ (sign & 1
U<<31);
1042 *dst++ = v[idx & 3] * t.
f;
1044 sign <<= nz & 1; nz >>= 1;
1045 t.
i = s.
i ^ (sign & 1
U<<31);
1046 *dst++ = v[idx>>2 & 3] * t.
f;
1048 sign <<= nz & 1; nz >>= 1;
1049 t.
i = s.
i ^ (sign & 1
U<<31);
1050 *dst++ = v[idx>>4 & 3] * t.
f;
1052 sign <<= nz & 1; nz >>= 1;
1053 t.
i = s.
i ^ (sign & 1
U<<31);
1054 *dst++ = v[idx>>6 & 3] * t.
f;
1074 int pulse_present,
const Pulse *pulse,
1078 int i, k,
g, idx = 0;
1081 float *coef_base = coef;
1084 memset(coef + g * 128 + offsets[ics->
max_sfb], 0,
sizeof(
float) * (c - offsets[ics->
max_sfb]));
1089 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1090 const unsigned cbt_m1 = band_type[idx] - 1;
1091 float *cfo = coef + offsets[
i];
1092 int off_len = offsets[i + 1] - offsets[
i];
1096 for (group = 0; group < g_len; group++, cfo+=128) {
1097 memset(cfo, 0, off_len *
sizeof(
float));
1099 }
else if (cbt_m1 ==
NOISE_BT - 1) {
1100 for (group = 0; group < g_len; group++, cfo+=128) {
1104 for (k = 0; k < off_len; k++) {
1110 scale = sf[idx] / sqrtf(band_energy);
1119 switch (cbt_m1 >> 1) {
1121 for (group = 0; group < g_len; group++, cfo+=128) {
1131 cb_idx = cb_vector_idx[code];
1132 cf =
VMUL4(cf, vq, cb_idx, sf + idx);
1138 for (group = 0; group < g_len; group++, cfo+=128) {
1150 cb_idx = cb_vector_idx[code];
1151 nnz = cb_idx >> 8 & 15;
1154 cf =
VMUL4S(cf, vq, cb_idx, bits, sf + idx);
1160 for (group = 0; group < g_len; group++, cfo+=128) {
1170 cb_idx = cb_vector_idx[code];
1171 cf =
VMUL2(cf, vq, cb_idx, sf + idx);
1178 for (group = 0; group < g_len; group++, cfo+=128) {
1190 cb_idx = cb_vector_idx[code];
1191 nnz = cb_idx >> 8 & 15;
1192 sign = nnz ?
SHOW_UBITS(
re, gb, nnz) << (cb_idx >> 12) : 0;
1194 cf =
VMUL2S(cf, vq, cb_idx, sign, sf + idx);
1200 for (group = 0; group < g_len; group++, cfo+=128) {
1202 uint32_t *icf = (uint32_t *) cf;
1221 cb_idx = cb_vector_idx[code];
1227 for (j = 0; j < 2; j++) {
1235 b = 31 - av_log2(~b);
1249 unsigned v = ((
const uint32_t*)vq)[cb_idx & 15];
1250 *icf++ = (bits & 1
U<<31) | v;
1267 if (pulse_present) {
1269 for (i = 0; i < pulse->
num_pulse; i++) {
1270 float co = coef_base[ pulse->
pos[
i] ];
1271 while (offsets[idx + 1] <= pulse->
pos[i])
1273 if (band_type[idx] !=
NOISE_BT && sf[idx]) {
1274 float ico = -pulse->
amp[
i];
1277 ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico);
1279 coef_base[ pulse->
pos[
i] ] = cbrtf(fabsf(ico)) * ico * sf[idx];
1290 tmp.
i = (tmp.
i + 0x00008000
U) & 0xFFFF0000U;
1298 tmp.
i = (tmp.
i + 0x00007FFF
U + (tmp.
i & 0x00010000
U >> 16)) & 0xFFFF0000
U;
1306 pun.
i &= 0xFFFF0000
U;
1313 const float a = 0.953125;
1314 const float alpha = 0.90625;
1318 float r0 = ps->
r0, r1 = ps->
r1;
1319 float cor0 = ps->
cor0, cor1 = ps->
cor1;
1320 float var0 = ps->
var0, var1 = ps->
var1;
1322 k1 = var0 > 1 ? cor0 *
flt16_even(a / var0) : 0;
1323 k2 = var1 > 1 ? cor1 *
flt16_even(a / var1) : 0;
1355 for (k = sce->
ics.
swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) {
1380 float *out = sce->
coeffs;
1381 int global_gain, pulse_present = 0;
1391 if (!common_window && !scale_flag) {
1440 int g,
i, group, idx = 0;
1443 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1446 for (group = 0; group < ics->
group_len[
g]; group++) {
1448 ch1 + group * 128 + offsets[i],
1449 offsets[i+1] - offsets[i]);
1471 int g, group,
i, idx = 0;
1475 for (i = 0; i < ics->
max_sfb;) {
1478 for (; i < bt_run_end; i++, idx++) {
1479 c = -1 + 2 * (sce1->
band_type[idx] - 14);
1481 c *= 1 - 2 * cpe->
ms_mask[idx];
1482 scale = c * sce1->
sf[idx];
1483 for (group = 0; group < ics->
group_len[
g]; group++)
1485 coef0 + group * 128 + offsets[i],
1487 offsets[i + 1] - offsets[i]);
1491 idx += bt_run_end -
i;
1507 int i, ret, common_window, ms_present = 0;
1510 if (common_window) {
1520 if (ms_present == 3) {
1523 }
else if (ms_present)
1526 if ((ret =
decode_ics(ac, &cpe->
ch[0], gb, common_window, 0)))
1528 if ((ret =
decode_ics(ac, &cpe->
ch[1], gb, common_window, 0)))
1531 if (common_window) {
1545 1.09050773266525765921,
1546 1.18920711500272106672,
1586 for (c = 0; c < num_gain; c++) {
1590 float gain_cache = 1.;
1593 gain = cge ?
get_vlc2(gb, vlc_scalefactors.
table, 7, 3) - 60: 0;
1594 gain_cache = powf(scale, -gain);
1597 coup->
gain[c][0] = gain_cache;
1600 for (sfb = 0; sfb < sce->
ics.
max_sfb; sfb++, idx++) {
1611 gain_cache = powf(scale, -t) * s;
1614 coup->
gain[c][idx] = gain_cache;
1632 int num_excl_chan = 0;
1635 for (i = 0; i < 7; i++)
1639 return num_excl_chan / 7;
1653 int drc_num_bands = 1;
1674 for (i = 0; i < drc_num_bands; i++) {
1687 for (i = 0; i < drc_num_bands; i++) {
1756 int bottom, top, order, start, end,
size, inc;
1762 for (filt = 0; filt < tns->
n_filt[w]; filt++) {
1765 order = tns->
order[w][filt];
1774 if ((size = end - start) <= 0)
1786 for (m = 0; m <
size; m++, start += inc)
1787 for (i = 1; i <=
FFMIN(m, order); i++)
1788 coef[start] -= coef[start - i * inc] * lpc[i - 1];
1791 for (m = 0; m <
size; m++, start += inc) {
1792 tmp[0] = coef[start];
1793 for (i = 1; i <=
FFMIN(m, order); i++)
1794 coef[start] += tmp[i] * lpc[i - 1];
1795 for (i = order; i > 0; i--)
1796 tmp[i] = tmp[i - 1];
1818 memset(in, 0, 448 *
sizeof(
float));
1825 memset(in + 1024 + 576, 0, 448 *
sizeof(
float));
1840 float *predTime = sce->
ret;
1842 int16_t num_samples = 2048;
1844 if (ltp->
lag < 1024)
1845 num_samples = ltp->
lag + 1024;
1846 for (i = 0; i < num_samples; i++)
1848 memset(&predTime[i], 0, (2048 - i) *
sizeof(
float));
1857 for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
1858 sce->
coeffs[i] += predFreq[i];
1868 float *saved = sce->
saved;
1869 float *saved_ltp = sce->
coeffs;
1875 memcpy(saved_ltp, saved, 512 *
sizeof(
float));
1876 memset(saved_ltp + 576, 0, 448 *
sizeof(
float));
1878 for (i = 0; i < 64; i++)
1879 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * swindow[63 - i];
1881 memcpy(saved_ltp, ac->
buf_mdct + 512, 448 *
sizeof(
float));
1882 memset(saved_ltp + 576, 0, 448 *
sizeof(
float));
1884 for (i = 0; i < 64; i++)
1885 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * swindow[63 - i];
1888 for (i = 0; i < 512; i++)
1889 saved_ltp[i + 512] = ac->
buf_mdct[1023 - i] * lwindow[511 - i];
1904 float *out = sce->
ret;
1905 float *saved = sce->
saved;
1910 float *temp = ac->
temp;
1915 for (i = 0; i < 1024; i += 128)
1930 memcpy( out, saved, 448 *
sizeof(
float));
1938 memcpy( out + 448 + 4*128, temp, 64 *
sizeof(
float));
1941 memcpy( out + 576, buf + 64, 448 *
sizeof(
float));
1947 memcpy( saved, temp + 64, 64 *
sizeof(
float));
1951 memcpy( saved + 448, buf + 7*128 + 64, 64 *
sizeof(
float));
1953 memcpy( saved, buf + 512, 448 *
sizeof(
float));
1954 memcpy( saved + 448, buf + 7*128 + 64, 64 *
sizeof(
float));
1956 memcpy( saved, buf + 512, 512 *
sizeof(
float));
1971 float *dest = target->
coeffs;
1972 const float *src = cce->
ch[0].
coeffs;
1973 int g,
i, group, k, idx = 0;
1976 "Dependent coupling is not supported together with LTP\n");
1980 for (i = 0; i < ics->
max_sfb; i++, idx++) {
1983 for (group = 0; group < ics->
group_len[
g]; group++) {
1984 for (k = offsets[i]; k < offsets[i + 1]; k++) {
1986 dest[group * 128 + k] += gain * src[group * 128 + k];
2007 const float *src = cce->
ch[0].
ret;
2008 float *dest = target->
ret;
2011 for (i = 0; i <
len; i++)
2012 dest[i] += gain * src[i];
2035 if (coup->
type[c] == type && coup->
id_select[c] == elem_id) {
2037 apply_coupling_method(ac, &cc->
ch[0], cce, index);
2042 apply_coupling_method(ac, &cc->
ch[1], cce, index++);
2056 for (type = 3; type >= 0; type--) {
2105 memset(new_che_pos, 0, 4 *
MAX_ELEM_ID *
sizeof(new_che_pos[0][0]));
2143 int samples = 0, multiplier, audio_found = 0;
2162 if (!(che=
get_che(ac, elem_type, elem_id))) {
2164 elem_type, elem_id);
2170 switch (elem_type) {
2197 memset(new_che_pos, 0, 4 *
MAX_ELEM_ID *
sizeof(new_che_pos[0][0]));
2202 "Not evaluating a further program_config_element as this construct is dubious at best.\n");
2226 elem_type_prev = elem_type;
2240 samples <<= multiplier;
2274 int *got_frame_ptr,
AVPacket *avpkt)
2277 const uint8_t *buf = avpkt->
data;
2278 int buf_size = avpkt->
size;
2283 int new_extradata_size;
2286 &new_extradata_size);
2288 if (new_extradata) {
2295 memcpy(avctx->
extradata, new_extradata, new_extradata_size);
2309 for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)
2310 if (buf[buf_offset])
2313 return buf_size > buf_offset ? buf_consumed : buf_size;
2322 for (type = 0; type < 4; type++) {
2323 if (ac->
che[type][i])
2336 #define LOAS_SYNC_WORD 0x2b7
2362 int sync_extension = 0;
2363 int bits_consumed, esize;
2371 if (config_start_bit % 8) {
2373 "config not byte aligned.\n", 1);
2379 gb->
buffer + (config_start_bit / 8),
2380 asclen, sync_extension);
2382 if (bits_consumed < 0)
2391 esize = (bits_consumed+7) / 8;
2406 return bits_consumed;
2412 int ret, audio_mux_version =
get_bits(gb, 1);
2415 if (audio_mux_version)
2420 if (audio_mux_version)
2428 "multiple programs are not supported\n", 1);
2437 "multiple layers are not supported\n", 1);
2442 if (!audio_mux_version) {
2473 if (audio_mux_version) {
2496 int mux_slot_length = 0;
2499 mux_slot_length += tmp;
2500 }
while (tmp == 255);
2501 return mux_slot_length;
2516 uint8_t use_same_mux =
get_bits(gb, 1);
2517 if (!use_same_mux) {
2522 "no decoder config found\n");
2530 }
else if (mux_slot_length_bytes * 8 + 256 <
get_bits_left(gb)) {
2532 "frame length mismatch %d << %d\n",
2542 int *got_frame_ptr,
AVPacket *avpkt)
2557 if (muxlength > avpkt->
size)
2578 "ADTS header detected, probably as result of configuration "
int predictor_initialized
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_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce)
Conduct IMDCT and windowing.
uint8_t use_kb_window[2]
If set, use Kaiser-Bessel window, otherwise use a sinus window.
enum ChannelPosition che_pos[4][MAX_ELEM_ID]
channel element channel mapping with the first index as the first 4 raw data block types ...
static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
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 apply_intensity_stereo(AACContext *ac, ChannelElement *cpe, int ms_present)
intensity stereo decoding; reference: 4.6.8.2.3
static void decode_channel_map(enum ChannelPosition *cpe_map, enum ChannelPosition *sce_map, enum ChannelPosition type, GetBitContext *gb, int n)
Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit...
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)
#define AV_LOG_WARNING
Something somehow does not look correct.
static void align_get_bits(GetBitContext *s)
ChannelElement * che[4][MAX_ELEM_ID]
av_cold void ff_aac_sbr_init(void)
Initialize SBR.
static av_cold int che_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_ELEM_ID], int type, int id, int *channels)
Check for the channel element in the current channel position configuration.
static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, GetBitContext *gb)
Decode Individual Channel Stream info; reference: table 4.6.
#define FF_ARRAY_ELEMS(a)
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
static void apply_independent_coupling(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply independent channel coupling (applied after IMDCT).
enum OCStatus output_configured
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.
void(* float_interleave)(float *dst, const float **src, unsigned int len, int channels)
Convert multiple arrays of float to an array of interleaved float.
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
void(* float_to_int16_interleave)(int16_t *dst, const float **src, long len, int channels)
Convert multiple arrays of float to an interleaved array of int16_t.
enum AVSampleFormat sample_fmt
audio sample format
static void apply_prediction(AACContext *ac, SingleChannelElement *sce)
Apply AAC-Main style frequency domain prediction.
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
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.
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 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)
int id_select[8]
element id
const float *const ff_aac_codebook_vector_vals[]
N Error Resilient Low Complexity.
ChannelElement * tag_che_map[4][MAX_ELEM_ID]
static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], GetBitContext *gb)
Decode program configuration element; reference: table 4.2.
av_cold void dsputil_init(DSPContext *c, AVCodecContext *avctx)
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
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static uint32_t latm_get_value(GetBitContext *b)
#define CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
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
float * output_data[MAX_CHANNELS]
Points to each element's 'ret' buffer (PCM output).
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
enum AVSampleFormat request_sample_fmt
Used to request a sample format from the decoder.
#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.
struct AACContext AACContext
Output configuration locked in place.
uint64_t channel_layout
Audio channel layout.
#define SKIP_BITS(name, gb, num)
static const float cce_scale[]
N Error Resilient Scalable.
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
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.
int predictor_reset_group
static void reset_predictor_group(PredictorState *ps, int group_num)
int dyn_rng_ctl[17]
DRC magnitude information.
float ret[2048]
PCM output.
int initialized
initilized after a valid extradata was seen
int ff_get_buffer(AVCodecContext *avctx, AVFrame *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.
AAC definitions and structures.
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)
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 av_dlog(pctx,...)
av_dlog macros Useful to print debug messages that shouldn't get compiled in normally.
#define SHOW_UBITS(name, gb, num)
int interpolation_scheme
Indicates the interpolation scheme used in the SBR QMF domain.
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
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
Samples per packet, initialized when calling 'init'.
int frame_length
frame length for fixed frame length
static const uint8_t aac_channel_layout_map[7][5][2]
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]
static void update_ltp(AACContext *ac, SingleChannelElement *sce)
Update the LTP buffer for next frame.
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
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 AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define OPEN_READER(name, gb)
IndividualChannelStream ics
int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
Parse AAC frame header.
static int count_channels(enum ChannelPosition che_pos[4][MAX_ELEM_ID])
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 * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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 int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#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.
N Error Resilient Bit-Sliced Arithmetic Coding.
av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr)
Initialize one SBR context.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
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]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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.
static int decode_dynamic_range(DynamicRangeControl *che_drc, GetBitContext *gb, int cnt)
Decode dynamic range information; reference: table 4.52.
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)
const uint8_t ff_aac_pred_sfb_max[]
uint8_t prediction_used[41]
common internal api header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Single Channel Element - used for both SCE and LFE elements.
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
const uint16_t *const ff_swb_offset_1024[]
static av_cold int aac_decode_init(AVCodecContext *avctx)
AVSampleFormat
all in native-endian format
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]
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
av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
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 av_cold int output_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_ELEM_ID], enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], int channel_config, enum OCStatus oc_type)
Configure output channel order based on the current program configuration element.
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 sample_rate_idx(int rate)
#define POW_SF2_ZERO
ff_aac_pow2sf_tab index corresponding to pow(2, 0);
static int skip_data_stream_element(AACContext *ac, GetBitContext *gb)
Skip data_stream_element; reference: table 4.10.
static void decode_ltp(AACContext *ac, LongTermPrediction *ltp, GetBitContext *gb, uint8_t max_sfb)
Decode Long Term Prediction data; reference: table 4.xx.
void ff_aac_tableinit(void)
int sbr
-1 implicit, 1 presence
void avcodec_get_frame_defaults(AVFrame *pic)
Set the fields of the given AVFrame to default values.
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]
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]
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
static av_cold int set_default_channel_config(AVCodecContext *avctx, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], int channel_config)
Set up channel positions based on a default channel configuration as specified in table 1...
int nb_samples
number of audio samples (per channel) described by this frame
static VLC vlc_spectral[11]
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 float * VMUL4(float *dst, const float *v, unsigned idx, const float *scale)