822 changes: 644 additions & 178 deletions mythtv/external/FFmpeg/libavcodec/aacdec.c

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions mythtv/external/FFmpeg/libavcodec/aacdectab.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@

#include <stdint.h>

/* @name ltp_coef
* Table of the LTP coefficient (multiplied by 2)
*/
static const float ltp_coef[8] = {
1.141658, 1.393232, 1.626008, 1.822608,
1.969800, 2.135788, 2.2389202, 2.739066,
};

/* @name tns_tmp2_map
* Tables of the tmp2[] arrays of LPC coefficients used for TNS.
* The suffix _M_N[] indicate the values of coef_compress and coef_res
Expand Down
38 changes: 16 additions & 22 deletions mythtv/external/FFmpeg/libavcodec/aacsbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
#include "aacsbrdata.h"
#include "fft.h"
#include "aacps.h"
#include "libavutil/libm.h"

#include <stdint.h>
#include <float.h>
#include <math.h>

#define ENVELOPE_ADJUSTMENT_OFFSET 2
#define NOISE_FLOOR_OFFSET 6.0f
Expand Down Expand Up @@ -127,11 +129,13 @@ av_cold void ff_aac_sbr_init(void)

av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr)
{
if(sbr->mdct.mdct_bits)
return;
sbr->kx[0] = sbr->kx[1] = 32; //Typo in spec, kx' inits to 32
sbr->data[0].e_a[1] = sbr->data[1].e_a[1] = -1;
sbr->data[0].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128);
sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128);
ff_mdct_init(&sbr->mdct, 7, 1, 1.0/64);
ff_mdct_init(&sbr->mdct, 7, 1, 1.0 / 64.0);
ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0);
ff_ps_ctx_init(&sbr->ps);
}
Expand Down Expand Up @@ -1134,16 +1138,12 @@ static void sbr_dequant(SpectralBandReplication *sbr, int id_aac)
* @param W array of complex-valued samples split into subbands
*/
static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, const float *in, float *x,
float z[320], float W[2][32][32][2],
float scale)
float z[320], float W[2][32][32][2])
{
int i, k;
memcpy(W[0], W[1], sizeof(W[0]));
memcpy(x , x+1024, (320-32)*sizeof(x[0]));
if (scale != 1.0f)
dsp->vector_fmul_scalar(x+288, in, scale, 1024);
else
memcpy(x+288, in, 1024*sizeof(*x));
memcpy(x+288, in, 1024*sizeof(x[0]));
for (i = 0; i < 32; i++) { // numTimeSlots*RATE = 16*2 as 960 sample frames
// are not supported
dsp->vector_fmul_reverse(z, sbr_qmf_window_ds, x, 320);
Expand All @@ -1159,7 +1159,7 @@ static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, const float *in,
}
z[64+63] = z[32];

ff_imdct_half(mdct, z, z+64);
mdct->imdct_half(mdct, z, z+64);
for (k = 0; k < 32; k++) {
W[1][i][k][0] = -z[63-k];
W[1][i][k][1] = z[k];
Expand All @@ -1175,12 +1175,10 @@ static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, const float *in,
static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct,
float *out, float X[2][38][64],
float mdct_buf[2][64],
float *v0, int *v_off, const unsigned int div,
float bias, float scale)
float *v0, int *v_off, const unsigned int div)
{
int i, n;
const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us;
int scale_and_bias = scale != 1.0f || bias != 0.0f;
float *v;
for (i = 0; i < 32; i++) {
if (*v_off == 0) {
Expand All @@ -1196,7 +1194,7 @@ static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct,
X[0][i][ n] = -X[0][i][n];
X[0][i][32+n] = X[1][i][31-n];
}
ff_imdct_half(mdct, mdct_buf[0], X[0][i]);
mdct->imdct_half(mdct, mdct_buf[0], X[0][i]);
for (n = 0; n < 32; n++) {
v[ n] = mdct_buf[0][63 - 2*n];
v[63 - n] = -mdct_buf[0][62 - 2*n];
Expand All @@ -1205,8 +1203,8 @@ static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct,
for (n = 1; n < 64; n+=2) {
X[1][i][n] = -X[1][i][n];
}
ff_imdct_half(mdct, mdct_buf[0], X[0][i]);
ff_imdct_half(mdct, mdct_buf[1], X[1][i]);
mdct->imdct_half(mdct, mdct_buf[0], X[0][i]);
mdct->imdct_half(mdct, mdct_buf[1], X[1][i]);
for (n = 0; n < 64; n++) {
v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ];
v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ];
Expand All @@ -1222,9 +1220,6 @@ static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct,
dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div);
dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div);
dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div);
if (scale_and_bias)
for (n = 0; n < 64 >> div; n++)
out[n] = out[n] * scale + bias;
out += 64 >> div;
}
}
Expand Down Expand Up @@ -1459,6 +1454,7 @@ static void sbr_mapping(AACContext *ac, SpectralBandReplication *sbr,
uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow;
int k;

//av_assert0(sbr->kx[1] <= table[0]);
for (i = 0; i < ilim; i++)
for (m = table[i]; m < table[i + 1]; m++)
sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i];
Expand Down Expand Up @@ -1727,7 +1723,7 @@ void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac,
/* decode channel */
sbr_qmf_analysis(&ac->dsp, &sbr->mdct_ana, ch ? R : L, sbr->data[ch].analysis_filterbank_samples,
(float*)sbr->qmf_filter_scratch,
sbr->data[ch].W, 1/(-1024 * ac->sf_scale));
sbr->data[ch].W);
sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W);
if (sbr->start) {
sbr_hf_inverse_filter(sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]);
Expand Down Expand Up @@ -1760,12 +1756,10 @@ void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac,
sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, L, sbr->X[0], sbr->qmf_filter_scratch,
sbr->data[0].synthesis_filterbank_samples,
&sbr->data[0].synthesis_filterbank_samples_offset,
downsampled,
ac->add_bias, -1024 * ac->sf_scale);
downsampled);
if (nch == 2)
sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, R, sbr->X[1], sbr->qmf_filter_scratch,
sbr->data[1].synthesis_filterbank_samples,
&sbr->data[1].synthesis_filterbank_samples_offset,
downsampled,
ac->add_bias, -1024 * ac->sf_scale);
downsampled);
}