84 sbr->
kx[0] = sbr->
kx[1];
128 return *(
const int16_t *)
a - *(
const int16_t *)
b;
134 for (
i = 0;
i <= last_el;
i++)
145 static const INTFLOAT bands_warped[3] = {
Q23(1.32715174233856803909f),
146 Q23(1.18509277094158210129f),
147 Q23(1.11987160404675912501f) };
149 int16_t patch_borders[7];
152 patch_borders[0] = sbr->
kx[1];
159 memcpy(sbr->
f_tablelim + sbr->
n[0] + 1, patch_borders + 1,
160 (sbr->
num_patches - 1) *
sizeof(patch_borders[0]));
169 if ((*in << 23) >= *
out * lim_bands_per_octave_warped) {
171 if (*in >= *
out * lim_bands_per_octave_warped) {
174 }
else if (*in == *
out ||
196 uint8_t bs_header_extra_1;
197 uint8_t bs_header_extra_2;
221 if (bs_header_extra_1) {
235 if (bs_header_extra_2) {
256 for (
i = 1;
i < nel;
i++)
268 if (bs_xover_band >= n_master) {
270 "Invalid bitstream, crossover band index beyond array bounds: %d\n",
281 unsigned int temp, max_qmf_subbands = 0;
282 unsigned int start_min, stop_min;
284 const int8_t *sbr_offset_ptr;
300 case 44100:
case 48000:
case 64000:
303 case 88200:
case 96000:
case 128000:
case 176400:
case 192000:
308 "Unsupported sample rate for SBR: %d\n", sbr->
sample_rate);
325 sbr->
k[2] = stop_min;
329 sbr->
k[2] += stop_dk[k];
331 sbr->
k[2] = 2*sbr->
k[0];
333 sbr->
k[2] = 3*sbr->
k[0];
339 sbr->
k[2] =
FFMIN(64, sbr->
k[2]);
343 max_qmf_subbands = 48;
345 max_qmf_subbands = 35;
347 max_qmf_subbands = 32;
351 if (sbr->
k[2] - sbr->
k[0] > max_qmf_subbands) {
353 "Invalid bitstream, too many QMF subbands: %d\n", sbr->
k[2] - sbr->
k[0]);
361 sbr->
n_master = ((sbr->
k[2] - sbr->
k[0] + (dk&2)) >> dk) << 1;
365 for (k = 1; k <= sbr->
n_master; k++)
368 k2diff = sbr->
k[2] - sbr->
k[0] - sbr->
n_master * dk;
377 for (k = 1; k <= sbr->
n_master; k++)
382 int two_regions, num_bands_0;
383 int vdk0_max, vdk1_min;
389 if (49 * sbr->
k[2] > 110 * sbr->
k[0]) {
391 sbr->
k[1] = 2 * sbr->
k[0];
394 sbr->
k[1] = sbr->
k[2];
398 tmp = (sbr->
k[1] << 23) / sbr->
k[0];
399 while (
tmp < 0x40000000) {
405 tmp = (((
tmp + 0x80) >> 8) + ((8 - nz) << 23)) * half_bands;
406 num_bands_0 = ((
tmp + 0x400000) >> 23) * 2;
408 num_bands_0 =
lrintf(half_bands *
log2f(sbr->
k[1] / (
float)sbr->
k[0])) * 2;
411 if (num_bands_0 <= 0) {
421 vdk0_max = vk0[num_bands_0];
424 for (k = 1; k <= num_bands_0; k++) {
437 tmp = (sbr->
k[2] << 23) / sbr->
k[1];
439 while (
tmp < 0x40000000) {
445 tmp = (((
tmp + 0x80) >> 8) + ((8 - nz) << 23)) * half_bands;
448 num_bands_1 = ((
tmp + 0x400000) >> 23) * 2;
450 float invwarp = spectrum->
bs_alter_scale ? 0.76923076923076923077f
452 int num_bands_1 =
lrintf(half_bands * invwarp *
453 log2f(sbr->
k[2] / (
float)sbr->
k[1])) * 2;
459 if (vdk1_min < vdk0_max) {
462 change =
FFMIN(vdk0_max - vk1[1], (vk1[num_bands_1] - vk1[1]) >> 1);
464 vk1[num_bands_1] -= change;
470 for (k = 1; k <= num_bands_1; k++) {
478 sbr->
n_master = num_bands_0 + num_bands_1;
482 (num_bands_0 + 1) *
sizeof(sbr->
f_master[0]));
483 memcpy(&sbr->
f_master[num_bands_0 + 1], vk1 + 1,
484 num_bands_1 *
sizeof(sbr->
f_master[0]));
500 int i, k, last_k = -1, last_msb = -1, sb = 0;
502 int usb = sbr->
kx[1];
507 if (goal_sb < sbr->kx[1] + sbr->
m[1]) {
508 for (k = 0; sbr->
f_master[k] < goal_sb; k++) ;
514 if (k == last_k && msb == last_msb) {
520 for (
i = k;
i == k || sb > (sbr->
k[0] - 1 + msb - odd);
i--) {
522 odd = (sb + sbr->
k[0]) & 1;
546 }
while (sb != sbr->
kx[1] + sbr->
m[1]);
564 sbr->
n[0] = (sbr->
n[1] + 1) >> 1;
567 (sbr->
n[1] + 1) *
sizeof(sbr->
f_master[0]));
572 if (sbr->
kx[1] + sbr->
m[1] > 64) {
574 "Stop frequency border too high: %d\n", sbr->
kx[1] + sbr->
m[1]);
577 if (sbr->
kx[1] > 32) {
583 temp = sbr->
n[1] & 1;
584 for (k = 1; k <= sbr->
n[0]; k++)
587 temp = (sbr->
k[2] << 23) / sbr->
kx[1];
588 while (
temp < 0x40000000) {
596 sbr->
n_q = (
temp + 0x400000) >> 23;
601 log2f(sbr->
k[2] / (
float)sbr->
kx[1])));
612 for (k = 1; k <= sbr->
n_q; k++) {
647 int abs_bord_trail = numTimeSlots;
648 int num_rel_lead, num_rel_trail;
649 unsigned bs_num_env_old = ch_data->
bs_num_env;
650 int bs_frame_class, bs_num_env;
656 switch (bs_frame_class =
get_bits(gb, 2)) {
659 if (bs_num_env > (sbr->
usac ? 8 : 5)) {
661 "Invalid bitstream, too many SBR envelopes in FIXFIX type SBR frame: %d\n",
671 ch_data->
t_env[0] = 0;
674 abs_bord_trail = (abs_bord_trail + (ch_data->
bs_num_env >> 1)) /
676 for (
i = 0;
i < num_rel_lead;
i++)
677 ch_data->
t_env[
i + 1] = ch_data->
t_env[
i] + abs_bord_trail;
687 ch_data->
t_env[0] = 0;
690 for (
i = 0;
i < num_rel_trail;
i++)
705 for (
i = 0;
i < num_rel_lead;
i++)
717 bs_num_env = num_rel_lead + num_rel_trail + 1;
719 if (bs_num_env > 5) {
721 "Invalid bitstream, too many SBR envelopes in VARVAR type SBR frame: %d\n",
729 for (
i = 0;
i < num_rel_lead;
i++)
731 for (
i = 0;
i < num_rel_trail;
i++)
745 "Invalid bitstream, bs_pointer points to a middle noise border outside the time borders table: %d\n",
759 ch_data->
t_q[0] = ch_data->
t_env[0];
770 else if (bs_pointer == 1)
773 idx = bs_pointer - 1;
775 ch_data->
t_q[1] = ch_data->
t_env[idx];
778 ch_data->
e_a[0] = -(ch_data->
e_a[1] != bs_num_env_old);
779 ch_data->
e_a[1] = -1;
783 ch_data->
e_a[1] = bs_pointer - 1;
790 dst->bs_freq_res[0] =
dst->bs_freq_res[
dst->bs_num_env];
791 dst->t_env_num_env_old =
dst->t_env[
dst->bs_num_env];
792 dst->e_a[0] = -(
dst->e_a[1] !=
dst->bs_num_env);
795 memcpy(
dst->bs_freq_res+1,
src->bs_freq_res+1,
sizeof(
dst->bs_freq_res)-
sizeof(*
dst->bs_freq_res));
796 memcpy(
dst->t_env,
src->t_env,
sizeof(
dst->t_env));
797 memcpy(
dst->t_q,
src->t_q,
sizeof(
dst->t_q));
798 dst->bs_num_env =
src->bs_num_env;
799 dst->bs_amp_res =
src->bs_amp_res;
800 dst->bs_num_noise =
src->bs_num_noise;
801 dst->bs_frame_class =
src->bs_frame_class;
802 dst->e_a[1] =
src->e_a[1];
807 SBRData *ch_data,
int indep_flag)
836 for (
i = 0;
i < sbr->
n_q;
i++)
845 const VLCElem *t_huff, *f_huff;
847 const int odd = sbr->
n[1] & 1;
893 k = j ? 2*j - odd : 0;
931 const VLCElem *t_huff, *f_huff;
944 for (j = 0; j < sbr->
n_q; j++) {
953 for (j = 1; j < sbr->
n_q; j++) {
971 int bs_extension_id,
int *num_bits_left)
973 switch (bs_extension_id) {
976 av_log(ac->
avctx,
AV_LOG_ERROR,
"Parametric Stereo signaled to be not-present but was found in the bitstream.\n");
988 if (bs_extension_id || *num_bits_left > 16 ||
show_bits(gb, *num_bits_left))
1092 "Invalid bitstream - cannot apply SBR to element type %d\n", id_aac);
1097 int num_bits_left =
get_bits(gb, 4);
1098 if (num_bits_left == 15)
1101 num_bits_left <<= 3;
1102 while (num_bits_left > 7) {
1106 if (num_bits_left < 0) {
1109 if (num_bits_left > 0)
1124 "SBR reset failed. Switching SBR to pure upsampling mode.\n");
1139 int cnt,
int id_aac,
int fl960)
1142 unsigned int num_sbr_bits = 0, num_align_bits;
1143 unsigned bytes_read;
1145 int numTimeSlots = fl960 ? 15 : 16;
1151 sbr->
sample_rate = 2 * ac->oc[1].m4ac.sample_rate;
1152 if (!ac->oc[1].m4ac.ext_sample_rate)
1153 ac->oc[1].m4ac.ext_sample_rate = 2 * ac->oc[1].m4ac.sample_rate;
1161 sbr->
kx[0] = sbr->
kx[1];
1162 sbr->
m[0] = sbr->
m[1];
1173 num_sbr_bits +=
read_sbr_data(ac, sbr, gb, id_aac, numTimeSlots);
1175 num_align_bits = ((cnt << 3) - 4 - num_sbr_bits) & 7;
1176 bytes_read = ((num_sbr_bits + num_align_bits + 4) >> 3);
1178 if (bytes_read > cnt) {
1180 "Expected to read %d SBR bytes actually read %d.\n", cnt, bytes_read);
1215 int sbr_ch,
int indep_flag)
1219 int info_present = 1;
1220 int header_present = 1;
1244 if (header_present) {
1267 sbr->
kx[0] = sbr->
kx[1];
1268 sbr->
m[0] = sbr->
m[1];
1367#ifndef sbr_qmf_analysis
1383 int nb = numTimeSlots * 64;
1384 memcpy(x , x+nb, (320-32)*
sizeof(x[0]));
1385 memcpy(x+288, in, nb*
sizeof(x[0]));
1386 for (
i = 0;
i < numTimeSlots*2;
i++) {
1389 sbrdsp->qmf_pre_shuffle(z);
1391 for (j = 64; j < 128; j++) {
1394 "sbr_qmf_analysis: value %09d too large, setting to %09d\n",
1397 }
else if (z[j] < -(1<<24)) {
1399 "sbr_qmf_analysis: value %09d too small, setting to %09d\n",
1405 mdct_fn(mdct, z, z + 64,
sizeof(
INTFLOAT));
1406 sbrdsp->qmf_post_shuffle(
W[buf_idx][
i], z);
1416#ifndef sbr_qmf_synthesis
1425 INTFLOAT *v0,
int *v_off,
int numTimeSlots,
1426 const unsigned int div)
1430 const int step = 128 >> div;
1432 for (
i = 0;
i < numTimeSlots*2;
i++) {
1433 if (*v_off < step) {
1434 int saved_samples = (1280 - 128) >> div;
1442 for (n = 0; n < 32; n++) {
1443 X[0][
i][ n] = -
X[0][
i][n];
1444 X[0][
i][32+n] =
X[1][
i][31-n];
1446 mdct_fn(mdct, mdct_buf[0],
X[0][
i],
sizeof(
INTFLOAT));
1447 sbrdsp->qmf_deint_neg(v, mdct_buf[0]);
1449 sbrdsp->neg_odd_64(
X[1][
i]);
1450 mdct_fn(mdct, mdct_buf[0],
X[0][
i],
sizeof(
INTFLOAT));
1451 mdct_fn(mdct, mdct_buf[1],
X[1][
i],
sizeof(
INTFLOAT));
1452 sbrdsp->qmf_deint_bfly(v, mdct_buf[1], mdct_buf[0]);
1472 int buf_idx,
int numTimeSlots)
1475 const int t_HFGen = 8;
1476 const int i_f = numTimeSlots*2;
1477 memset(X_low, 0, 32*
sizeof(*X_low));
1478 for (k = 0; k < sbr->
kx[1]; k++) {
1479 for (
i = t_HFGen;
i < i_f + t_HFGen;
i++) {
1480 X_low[k][
i][0] =
W[buf_idx][
i - t_HFGen][k][0];
1481 X_low[k][
i][1] =
W[buf_idx][
i - t_HFGen][k][1];
1484 buf_idx = 1-buf_idx;
1485 for (k = 0; k < sbr->
kx[0]; k++) {
1486 for (
i = 0;
i < t_HFGen;
i++) {
1487 X_low[k][
i][0] =
W[buf_idx][
i + i_f - t_HFGen][k][0];
1488 X_low[k][
i][1] =
W[buf_idx][
i + i_f - t_HFGen][k][1];
1498 const INTFLOAT bw_array[5],
const uint8_t *t_env,
1513 "ERROR : no subband found for frequency %d\n", k);
1519 alpha0[p], alpha1[p], bw_array[
g],
1520 2 * t_env[0], 2 * t_env[bs_num_env]);
1523 if (k < sbr->m[1] + sbr->
kx[1])
1524 memset(X_high + k, 0, (sbr->
m[1] + sbr->
kx[1] - k) *
sizeof(*X_high));
1532 const INTFLOAT X_low[32][40][2],
int ch,
int numTimeSlots)
1535 const int i_f = numTimeSlots*2;
1537 memset(
X, 0, 2*
sizeof(*
X));
1538 for (k = 0; k < sbr->
kx[0]; k++) {
1539 for (
i = 0;
i < i_Temp;
i++) {
1544 for (; k < sbr->
kx[0] + sbr->
m[0]; k++) {
1545 for (
i = 0;
i < i_Temp;
i++) {
1546 X[0][
i][k] = Y0[
i + i_f][k][0];
1547 X[1][
i][k] = Y0[
i + i_f][k][1];
1551 for (k = 0; k < sbr->
kx[1]; k++) {
1552 for (
i = i_Temp;
i < 38;
i++) {
1557 for (; k < sbr->
kx[1] + sbr->
m[1]; k++) {
1558 for (
i = i_Temp;
i < i_f;
i++) {
1559 X[0][
i][k] = Y1[
i][k][0];
1560 X[1][
i][k] = Y1[
i][k][1];
1576 const unsigned int ilim = sbr->
n[ch_data->
bs_freq_res[e + 1]];
1582 "Derived frequency tables were not regenerated.\n");
1586 for (
i = 0;
i < ilim;
i++)
1592 for (
i = 0;
i < sbr->
n_q;
i++)
1593 for (m = sbr->
f_tablenoise[
i]; m < sbr->f_tablenoise[
i + 1]; m++)
1596 for (
i = 0;
i < sbr->
n[1];
i++) {
1598 const unsigned int m_midpoint =
1602 (e >= e_a[1] || (ch_data->
s_indexmapped[0][m_midpoint - sbr->
kx[1]] == 1));
1606 for (
i = 0;
i < ilim;
i++) {
1607 int additional_sinusoid_present = 0;
1610 additional_sinusoid_present = 1;
1614 memset(&sbr->
s_mapped[e][
table[
i] - sbr->
kx[1]], additional_sinusoid_present,
1628 int kx1 = sbr->
kx[1];
1635 const float recip_env_size = 0.5f / (ch_data->
t_env[e + 1] - ch_data->
t_env[e]);
1643 for (m = 0; m < sbr->
m[1]; m++) {
1646 e_curr[e][m] =
av_mul_sf(sum, recip_env_size);
1648 e_curr[e][m] = sum * recip_env_size;
1656 const int env_size = 2 * (ch_data->
t_env[e + 1] - ch_data->
t_env[e]);
1664 for (p = 0; p < sbr->
n[ch_data->
bs_freq_res[e + 1]]; p++) {
1674 const int den = env_size * (
table[p + 1] -
table[p]);
1682 e_curr[e][k - kx1] = sum;
1690 int id_aac,
int fl960,
void *L_,
void *R_)
1694 int downsampled = ac->oc[1].m4ac.ext_sample_rate < sbr->
sample_rate;
1696 int nch = (id_aac ==
TYPE_CPE) ? 2 : 1;
1698 int numTimeSlots = fl960 ? 15 : 16;
1700 if (id_aac != sbr->
id_aac) {
1702 "element type mismatch %d != %d\n", id_aac, sbr->
id_aac);
1708 "No quantized data read for sbr_dequant.\n");
1713 sbr->
kx[0] = sbr->
kx[1];
1714 sbr->
m[0] = sbr->
m[1];
1723 for (ch = 0; ch < nch; ch++) {
1752 sbr, &sbr->
data[ch],
1764 if (ac->oc[1].m4ac.ps == 1) {
1768 memcpy(sbr->
X[1], sbr->
X[0],
sizeof(sbr->
X[0]));
1777 numTimeSlots, downsampled);
1783 numTimeSlots, downsampled);
AAC decoder definitions and structures.
const VLCElem * ff_aac_sbr_vlc[10]
av_cold void AAC_RENAME ff_ps_init(void)
int AAC_RENAME ff_ps_apply(PSContext *ps, INTFLOAT L[2][38][64], INTFLOAT R[2][38][64], int top)
int ff_ps_read_data(void *logctx, GetBitContext *gb, PSCommonContext *ps, int bits_left)
static void AAC_RENAME ff_ps_ctx_init(PSContext *ps)
static void sbr_hf_assemble(float Y1[38][64][2], const float X_high[64][40][2], SpectralBandReplication *sbr, SBRData *ch_data, const int e_a[2])
Assembling HF Signals (14496-3 sp04 p220)
static void sbr_hf_inverse_filter(SBRDSPContext *dsp, float(*alpha0)[2], float(*alpha1)[2], const float X_low[32][40][2], int k0)
High Frequency Generation (14496-3 sp04 p214+) and Inverse Filtering (14496-3 sp04 p214) Warning: Thi...
static void sbr_gain_calc(SpectralBandReplication *sbr, SBRData *ch_data, const int e_a[2])
Calculation of levels of additional HF signal components (14496-3 sp04 p219) and Calculation of gain ...
static void make_bands(int16_t *bands, int start, int stop, int num_bands)
static void sbr_dequant(SpectralBandReplication *sbr, int id_aac)
Dequantization and stereo decoding (14496-3 sp04 p203)
static void sbr_chirp(SpectralBandReplication *sbr, SBRData *ch_data)
Chirp Factors (14496-3 sp04 p214)
FF_VISIBILITY_PUSH_HIDDEN void ff_aac_sbr_init(void)
Initialize SBR.
int ff_aac_sbr_decode_extension(AACDecContext *ac, ChannelElement *che, GetBitContext *gb, int crc, int cnt, int id_aac, int fl960)
Decode one SBR element.
#define ENVELOPE_ADJUSTMENT_OFFSET
void ff_aac_sbr_ctx_close(ChannelElement *che)
Close the SBR context implicitly contained in a ChannelElement.
@ F_HUFFMAN_ENV_BAL_3_0DB
@ T_HUFFMAN_ENV_BAL_1_5DB
@ T_HUFFMAN_NOISE_BAL_3_0DB
@ F_HUFFMAN_ENV_BAL_1_5DB
@ T_HUFFMAN_ENV_BAL_3_0DB
void ff_aac_sbr_apply(AACDecContext *ac, ChannelElement *che, int id_aac, int fl960, void *L, void *R)
Apply one SBR element to one AAC element.
int ff_aac_sbr_ctx_alloc_init(AACDecContext *ac, ChannelElement **che, int id_aac)
Allocate an ExtChannelElement (if necessary) and initialize the SBR context contained in it.
static int fixed_log(int x)
static const int CONST_076923
static const int CONST_RECIP_LN2
static unsigned int read_sbr_data(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, int id_aac, int numTimeSlots)
static int sbr_make_f_derived(AACDecContext *ac, SpectralBandReplication *sbr)
Derived Frequency Band Tables (14496-3 sp04 p197)
static int read_sbr_grid(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data, int numTimeSlots)
static SpectralBandReplication * get_sbr(ChannelElement *ch)
static int read_sbr_channel_pair_element(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, int numTimeSlots)
static unsigned int read_sbr_header(SpectralBandReplication *sbr, GetBitContext *gb, int is_usac)
static void sbr_qmf_analysis(AVFloatDSPContext *dsp, AVTXContext *mdct, av_tx_fn mdct_fn, SBRDSPContext *sbrdsp, const INTFLOAT *in, INTFLOAT *x, INTFLOAT z[320], INTFLOAT W[2][32][32][2], int buf_idx, int numTimeSlots)
Analysis QMF Bank (14496-3 sp04 p206)
static av_always_inline void get_bits1_vector(GetBitContext *gb, uint8_t *vec, int elements)
static const int8_t ceil_log2[]
ceil(log2(index+1))
static int in_table_int16(const int16_t *table, int last_el, int16_t needle)
static void sbr_qmf_synthesis(AVTXContext *mdct, av_tx_fn mdct_fn, SBRDSPContext *sbrdsp, AVFloatDSPContext *dsp, INTFLOAT *out, INTFLOAT X[2][38][64], INTFLOAT mdct_buf[2][64], INTFLOAT *v0, int *v_off, int numTimeSlots, const unsigned int div)
Synthesis QMF Bank (14496-3 sp04 p206) and Downsampled Synthesis QMF Bank (14496-3 sp04 p206)
static int array_min_int16(const int16_t *array, int nel)
static void aacsbr_func_ptr_init(AACSBRContext *c)
static void sbr_turnoff(SpectralBandReplication *sbr)
Places SBR in pure upsampling mode.
static void copy_sbr_grid(SBRData *dst, const SBRData *src)
int ff_aac_sbr_config_usac(AACDecContext *ac, ChannelElement *che, AACUsacElemConfig *ue)
Due to channel allocation not being known upon SBR parameter transmission, supply the parameters sepa...
static void sbr_reset(AACDecContext *ac, SpectralBandReplication *sbr)
static int sbr_hf_calc_npatches(AACDecContext *ac, SpectralBandReplication *sbr)
High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46)
static int sbr_make_f_master(AACDecContext *ac, SpectralBandReplication *sbr, SpectrumParameters *spectrum)
Master Frequency Band Table (14496-3 sp04 p194)
static int read_sbr_noise(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data, int ch)
static void sbr_env_estimate(AAC_FLOAT(*e_curr)[48], INTFLOAT X_high[64][40][2], SpectralBandReplication *sbr, SBRData *ch_data)
Estimation of current envelope (14496-3 sp04 p218)
static int sbr_x_gen(SpectralBandReplication *sbr, INTFLOAT X[2][38][64], const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2], const INTFLOAT X_low[32][40][2], int ch, int numTimeSlots)
Generate the subband filtered lowband.
static int sbr_mapping(AACDecContext *ac, SpectralBandReplication *sbr, SBRData *ch_data, int e_a[2])
High Frequency Adjustment (14496-3 sp04 p217) and Mapping (14496-3 sp04 p217)
int ff_aac_sbr_decode_usac_data(AACDecContext *ac, ChannelElement *che, AACUsacElemConfig *ue, GetBitContext *gb, int sbr_ch, int indep_flag)
Decode frame SBR data, USAC.
static void read_sbr_extension(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, int bs_extension_id, int *num_bits_left)
static int sbr_lf_gen(SpectralBandReplication *sbr, INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2], int buf_idx, int numTimeSlots)
Generate the subband filtered lowband.
static int qsort_comparison_function_int16(const void *a, const void *b)
static int check_n_master(AVCodecContext *avctx, int n_master, int bs_xover_band)
static void copy_usac_default_header(SpectralBandReplication *sbr, AACUsacElemConfig *ue)
static int read_sbr_envelope(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data, int ch)
static int sbr_hf_gen(AACDecContext *ac, SpectralBandReplication *sbr, INTFLOAT X_high[64][40][2], const INTFLOAT X_low[32][40][2], const INTFLOAT(*alpha0)[2], const INTFLOAT(*alpha1)[2], const INTFLOAT bw_array[5], const uint8_t *t_env, int bs_num_env)
High Frequency Generator (14496-3 sp04 p215)
static void read_sbr_dtdf(SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data, int indep_flag)
Read how the envelope and noise floor data is delta coded.
static void sbr_make_f_tablelim(SpectralBandReplication *sbr)
Limiter Frequency Band Table (14496-3 sp04 p198)
static int read_sbr_single_channel_element(AACDecContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, int numTimeSlots)
static void read_sbr_invf(SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data)
Read inverse filtering data.
static const int8_t sbr_offset[6][16]
static const INTFLOAT sbr_qmf_window_ds[320]
window coefficients for analysis/synthesis QMF banks
static const INTFLOAT sbr_qmf_window_us[640]
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define ue(name, range_min, range_max)
#define i(width, name, range_min, range_max)
#define AV_PROFILE_AAC_HE_V2
static const uint8_t bits[8]
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Memory handling functions.
static const uint16_t table[]
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
#define SBR_SYNTHESIS_BUF_SIZE
void AAC_RENAME ff_sbrdsp_init(SBRDSPContext *s)
static const ElemCat * elements[ELEMENT_COUNT]
static av_const SoftFloat av_add_sf(SoftFloat a, SoftFloat b)
static av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b)
static const SoftFloat FLOAT_0
0.0
static av_const SoftFloat av_int2sf(int v, int frac_bits)
Converts a mantisse and exponent to a SoftFloat.
main AAC decoding context
struct AVCodecContext * avctx
OutputConfiguration oc[2]
aacsbr functions pointers
int(* sbr_lf_gen)(SpectralBandReplication *sbr, INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2], int buf_idx, int numTimeSlots)
int(* sbr_x_gen)(SpectralBandReplication *sbr, INTFLOAT X[2][38][64], const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2], const INTFLOAT X_low[32][40][2], int ch, int numTimeSlots)
void(* sbr_hf_inverse_filter)(SBRDSPContext *dsp, INTFLOAT(*alpha0)[2], INTFLOAT(*alpha1)[2], const INTFLOAT X_low[32][40][2], int k0)
void(* sbr_hf_assemble)(INTFLOAT Y1[38][64][2], const INTFLOAT X_high[64][40][2], SpectralBandReplication *sbr, SBRData *ch_data, const int e_a[2])
main external API structure.
void(* vector_fmul_add)(int *dst, const int *src0, const int *src1, const int *src2, int len)
Calculate the entry wise product of two vectors of integers, add a third vector of integers and store...
void(* vector_fmul)(int *dst, const int *src0, const int *src1, int len)
Fixed-point multiplication that calculates the entry wise product of two vectors of integers and stor...
void(* vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats, and store the result in a vector of floats...
channel element - generic struct for SCE/CPE/CCE/LFE
SingleChannelElement ch[2]
SpectralBandReplication sbr
PredictorState predictor_state[2][MAX_PREDICTORS]
int ps
-1 implicit, 1 presence
AAC_FLOAT(* sum_square)(INTFLOAT(*x)[2], int n)
void(* hf_gen)(INTFLOAT(*X_high)[2], const INTFLOAT(*X_low)[2], const INTFLOAT alpha0[2], const INTFLOAT alpha1[2], INTFLOAT bw, int start, int end)
Spectral Band Replication per channel data.
AAC_FLOAT env_facs[9][48]
INTFLOAT bw_array[5]
Chirp factors.
uint8_t t_q[3]
Noise time borders.
uint8_t s_indexmapped[9][48]
uint8_t temp_shape_mode[6]
unsigned bs_add_harmonic_flag
uint8_t noise_facs_q[3][5]
Noise scalefactors.
int e_a[2]
l_APrev and l_A
int Ypos
QMF output of the HF adjustor.
INTFLOAT analysis_filterbank_samples[1312]
uint8_t t_env_num_env_old
Envelope time border of the last envelope of the previous frame.
uint8_t env_facs_q[9][48]
Envelope scalefactors.
uint8_t bs_invf_mode[2][5]
AAC_FLOAT noise_facs[3][5]
int synthesis_filterbank_samples_offset
uint8_t bs_add_harmonic[48]
INTFLOAT synthesis_filterbank_samples[SBR_SYNTHESIS_BUF_SIZE]
uint8_t t_env[9]
Envelope time borders.
INTFLOAT W[2][32][32][2]
QMF values of the original signal.
Spectral Band Replication.
uint16_t f_tablehigh[49]
Frequency borders for high resolution SBR.
INTFLOAT alpha1[64][2]
First coefficient used to filter the subband signals.
uint8_t patch_num_subbands[6]
SpectrumParameters spectrum_params
unsigned bs_interpol_freq
AAC_SIGNE m[2]
M' and M respectively, M is the number of QMF subbands that use SBR.
unsigned bs_limiter_bands
uint16_t f_tablenoise[6]
Frequency borders for noise floors.
unsigned bs_smoothing_mode
unsigned bs_limiter_gains
AAC_SIGNE kx[2]
kx', and kx respectively, kx is the first QMF subband where SBR is used.
uint16_t f_tablelow[25]
Frequency borders for low resolution SBR.
INTFLOAT X[2][2][38][64]
QMF values of the reconstructed signal.
INTFLOAT alpha0[64][2]
Zeroth coefficient used to filter the subband signals.
uint8_t s_mapped[8][48]
Sinusoidal presence, remapped.
AAC_FLOAT e_origmapped[8][48]
Dequantized envelope scalefactors, remapped.
AAC_SIGNE n_q
Number of noise floor bands.
AAC_SIGNE n_lim
Number of limiter bands.
uint16_t f_tablelim[30]
Frequency borders for the limiter.
INTFLOAT X_low[32][40][2]
QMF low frequency input to the HF generator.
INTFLOAT X_high[64][40][2]
QMF output of the HF generator.
AAC_SIGNE n_master
The number of frequency bands in f_master.
uint8_t patch_start_subband[6]
AAC_FLOAT q_mapped[8][48]
Dequantized noise scalefactors, remapped.
uint16_t f_master[49]
The master QMF frequency grouping.
AAC_FLOAT e_curr[8][48]
Estimated envelope.
INTFLOAT qmf_filter_scratch[5][64]
AAC_SIGNE n[2]
N_Low and N_High respectively, the number of frequency bands for low and high resolution.
Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the pr...
#define avpriv_request_sample(...)
static int array[MAX_W *MAX_W]
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respectively.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.