44 #define NOISE_LOW_LIMIT 4000 
   51      5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,
 
   52      5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5, 10,
 
   53     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
 
   54     10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 15
 
   59     3, 3, 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 9
 
   67 static const uint8_t aac_cb_out_map[
CB_TOT]  = {0,1,2,3,4,5,6,7,8,9,10,11,13};
 
   69 static const uint8_t aac_cb_in_map[
CB_TOT+1] = {0,1,2,3,4,5,6,7,8,9,10,11,0,12};
 
   79     return sqrtf(a * sqrtf(a)) + 0.4054;
 
   83                            int size, 
float Q34, 
int is_signed, 
int maxval)
 
   87     for (i = 0; i < 
size; i++) {
 
   89         out[i] = (int)
FFMIN(qc + 0.4054, (
double)maxval);
 
   90         if (is_signed && in[i] < 0.0f) {
 
   98 #ifndef USE_REALLY_FULL_SEARCH 
  100     for (i = 0; i < 
size; i++) {
 
  101         float a = fabsf(in[i]);
 
  102         out[i] = sqrtf(a * sqrtf(a));
 
  107 static const uint8_t aac_cb_range [12] = {0, 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17};
 
  108 static const uint8_t aac_cb_maxval[12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16};
 
  118                                 const float *scaled, 
int size, 
int scale_idx,
 
  119                                 int cb, 
const float lambda, 
const float uplim,
 
  120                                 int *
bits, 
int BT_ZERO, 
int BT_UNSIGNED,
 
  121                                 int BT_PAIR, 
int BT_ESC, 
int BT_NOISE)
 
  127     const float CLIPPED_ESCAPE = 165140.0f*IQ;
 
  130     const int dim = BT_PAIR ? 2 : 4;
 
  135         for (i = 0; i < 
size; i++)
 
  139         return cost * lambda;
 
  142         for (i = 0; i < 
size; i++)
 
  146         return cost * lambda;
 
  158     for (i = 0; i < 
size; i += 
dim) {
 
  160         int *quants = s->
qcoefs + i;
 
  164         for (j = 0; j < 
dim; j++) {
 
  166             curidx += quants[j] + off;
 
  171             for (j = 0; j < 
dim; j++) {
 
  172                 float t = fabsf(in[i+j]);
 
  174                 if (BT_ESC && vec[j] == 64.0f) { 
 
  175                     if (t >= CLIPPED_ESCAPE) {
 
  176                         di = t - CLIPPED_ESCAPE;
 
  179                         int c = av_clip_uintp2(
quant(t, Q), 13);
 
  180                         di = t - c*
cbrtf(c)*IQ;
 
  181                         curbits += 
av_log2(c)*2 - 4 + 1;
 
  191             for (j = 0; j < 
dim; j++) {
 
  192                 float di = in[i+j] - vec[j]*IQ;
 
  196         cost    += rd * lambda + curbits;
 
  203                 for (j = 0; j < 
dim; j++)
 
  207                 for (j = 0; j < 2; j++) {
 
  209                         int coef = av_clip_uintp2(
quant(fabsf(in[i+j]), Q), 13);
 
  212                         put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
 
  226                                                 const float *
in, 
const float *scaled,
 
  227                                                 int size, 
int scale_idx, 
int cb,
 
  228                                                 const float lambda, 
const float uplim,
 
  234 #define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE) \ 
  235 static float quantize_and_encode_band_cost_ ## NAME(                                    \ 
  236                                 struct AACEncContext *s,                                \ 
  237                                 PutBitContext *pb, const float *in,                     \ 
  238                                 const float *scaled, int size, int scale_idx,           \ 
  239                                 int cb, const float lambda, const float uplim,          \ 
  241     return quantize_and_encode_band_cost_template(                                      \ 
  242                                 s, pb, in, scaled, size, scale_idx,                     \ 
  243                                 BT_ESC ? ESC_BT : cb, lambda, uplim, bits,              \ 
  244                                 BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE);       \ 
  258                                 const 
float *scaled, 
int size, 
int scale_idx,
 
  259                                 int cb, const 
float lambda, const 
float uplim,
 
  261     quantize_and_encode_band_cost_ZERO,
 
  262     quantize_and_encode_band_cost_SQUAD,
 
  263     quantize_and_encode_band_cost_SQUAD,
 
  264     quantize_and_encode_band_cost_UQUAD,
 
  265     quantize_and_encode_band_cost_UQUAD,
 
  266     quantize_and_encode_band_cost_SPAIR,
 
  267     quantize_and_encode_band_cost_SPAIR,
 
  268     quantize_and_encode_band_cost_UPAIR,
 
  269     quantize_and_encode_band_cost_UPAIR,
 
  270     quantize_and_encode_band_cost_UPAIR,
 
  271     quantize_and_encode_band_cost_UPAIR,
 
  272     quantize_and_encode_band_cost_ESC,
 
  274     quantize_and_encode_band_cost_NOISE,
 
  277 #define quantize_and_encode_band_cost(                                  \ 
  278                                 s, pb, in, scaled, size, scale_idx, cb, \ 
  279                                 lambda, uplim, bits)                    \ 
  280     quantize_and_encode_band_cost_arr[cb](                              \ 
  281                                 s, pb, in, scaled, size, scale_idx, cb, \ 
  285                                 const float *scaled, 
int size, 
int scale_idx,
 
  286                                 int cb, 
const float lambda, 
const float uplim,
 
  290                                          cb, lambda, uplim, bits);
 
  294                                      const float *
in, 
int size, 
int scale_idx,
 
  295                                      int cb, 
const float lambda)
 
  301 static float find_max_val(
int group_len, 
int swb_size, 
const float *scaled) {
 
  304     for (w2 = 0; w2 < group_len; w2++) {
 
  305         for (i = 0; i < swb_size; i++) {
 
  306             maxval = 
FFMAX(maxval, scaled[w2*128+i]);
 
  314     float Q34 = sqrtf(Q * sqrtf(Q));
 
  316     qmaxval = maxval * Q34 + 0.4054f;
 
  317     if      (qmaxval ==  0) cb = 0;
 
  318     else if (qmaxval ==  1) cb = 1;
 
  319     else if (qmaxval ==  2) cb = 3;
 
  320     else if (qmaxval <=  4) cb = 5;
 
  321     else if (qmaxval <=  7) cb = 7;
 
  322     else if (qmaxval <= 12) cb = 9;
 
  340                                      int win, 
int group_len, 
const float lambda)
 
  347     const int run_esc  = (1 << 
run_bits) - 1;
 
  348     int idx, ppos, 
count;
 
  349     int stackrun[120], stackcb[120], stack_len;
 
  355     for (cb = 0; cb < 
CB_TOT; cb++) {
 
  360     for (swb = 0; swb < max_sfb; swb++) {
 
  362         if (sce->
zeroes[win*16 + swb]) {
 
  363             for (cb = 0; cb < 
CB_TOT; cb++) {
 
  369             float minrd = next_minrd;
 
  370             int mincb = next_mincb;
 
  373             for (cb = 0; cb < 
CB_TOT; cb++) {
 
  374                 float cost_stay_here, cost_get_here;
 
  376                 for (w = 0; w < group_len; w++) {
 
  379                                              s->
scoefs + start + w*128, size,
 
  383                 cost_stay_here = path[swb][
cb].
cost + rd;
 
  384                 cost_get_here  = minrd              + rd + run_bits + 4;
 
  388                 if (cost_get_here < cost_stay_here) {
 
  390                     path[swb+1][
cb].
cost     = cost_get_here;
 
  391                     path[swb+1][
cb].
run      = 1;
 
  394                     path[swb+1][
cb].
cost     = cost_stay_here;
 
  397                 if (path[swb+1][cb].cost < next_minrd) {
 
  398                     next_minrd = path[swb+1][
cb].
cost;
 
  409     for (cb = 1; cb < 
CB_TOT; cb++)
 
  410         if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
 
  415         stackrun[stack_len] = path[ppos][
cb].
run;
 
  416         stackcb [stack_len] = 
cb;
 
  418         ppos -= path[ppos][
cb].
run;
 
  423     for (i = stack_len - 1; i >= 0; i--) {
 
  427         memset(sce->
zeroes + win*16 + start, !cb, count);
 
  429         for (j = 0; j < 
count; j++) {
 
  433         while (count >= run_esc) {
 
  442                                   int win, 
int group_len, 
const float lambda)
 
  449     const int run_esc  = (1 << 
run_bits) - 1;
 
  450     int idx, ppos, 
count;
 
  451     int stackrun[120], stackcb[120], stack_len;
 
  457     for (cb = 0; cb < 
CB_TOT; cb++) {
 
  458         path[0][
cb].
cost     = run_bits+4;
 
  462     for (swb = 0; swb < max_sfb; swb++) {
 
  464         if (sce->
zeroes[win*16 + swb]) {
 
  465             float cost_stay_here = path[swb][0].
cost;
 
  466             float cost_get_here  = next_minbits + run_bits + 4;
 
  470             if (cost_get_here < cost_stay_here) {
 
  471                 path[swb+1][0].
prev_idx = next_mincb;
 
  472                 path[swb+1][0].
cost     = cost_get_here;
 
  473                 path[swb+1][0].
run      = 1;
 
  476                 path[swb+1][0].
cost     = cost_stay_here;
 
  477                 path[swb+1][0].
run      = path[swb][0].
run + 1;
 
  479             next_minbits = path[swb+1][0].
cost;
 
  481             for (cb = 1; cb < 
CB_TOT; cb++) {
 
  482                 path[swb+1][
cb].
cost = 61450;
 
  484                 path[swb+1][
cb].
run = 0;
 
  487             float minbits = next_minbits;
 
  488             int mincb = next_mincb;
 
  489             int startcb = sce->
band_type[win*16+swb];
 
  493             for (cb = 0; cb < startcb; cb++) {
 
  494                 path[swb+1][
cb].
cost = 61450;
 
  496                 path[swb+1][
cb].
run = 0;
 
  498             for (cb = startcb; cb < 
CB_TOT; cb++) {
 
  499                 float cost_stay_here, cost_get_here;
 
  502                     path[swb+1][
cb].
cost = 61450;
 
  504                     path[swb+1][
cb].
run = 0;
 
  507                 for (w = 0; w < group_len; w++) {
 
  509                                                s->
scoefs + start + w*128, size,
 
  510                                                sce->
sf_idx[(win+w)*16+swb],
 
  515                 cost_get_here  = minbits            + bits + run_bits + 4;
 
  519                 if (cost_get_here < cost_stay_here) {
 
  521                     path[swb+1][
cb].
cost     = cost_get_here;
 
  522                     path[swb+1][
cb].
run      = 1;
 
  525                     path[swb+1][
cb].
cost     = cost_stay_here;
 
  528                 if (path[swb+1][cb].cost < next_minbits) {
 
  529                     next_minbits = path[swb+1][
cb].
cost;
 
  540     for (cb = 1; cb < 
CB_TOT; cb++)
 
  541         if (path[max_sfb][cb].cost < path[max_sfb][idx].cost)
 
  547         stackrun[stack_len] = path[ppos][
cb].
run;
 
  548         stackcb [stack_len] = 
cb;
 
  550         ppos -= path[ppos][
cb].
run;
 
  555     for (i = stack_len - 1; i >= 0; i--) {
 
  559         memset(sce->
zeroes + win*16 + start, !cb, count);
 
  561         for (j = 0; j < 
count; j++) {
 
  565         while (count >= run_esc) {
 
  588 #define TRELLIS_STAGES 121 
  589 #define TRELLIS_STATES (SCALE_MAX_DIFF+1) 
  595     int q, w, w2, 
g, 
start = 0;
 
  602     float q0f = FLT_MAX, q1f = 0.0f, qnrgf = 0.0f;
 
  603     int q0, 
q1, qcnt = 0;
 
  605     for (i = 0; i < 1024; i++) {
 
  606         float t = fabsf(sce->
coeffs[i]);
 
  635         } 
else if (q1 > q1high) {
 
  642         paths[0][i].
cost    = 0.0f;
 
  643         paths[0][i].
prev    = -1;
 
  648             paths[j][i].
prev    = -2;
 
  660             bandaddr[idx] = w * 16 + 
g;
 
  666                     sce->
zeroes[(w+w2)*16+g] = 1;
 
  669                 sce->
zeroes[(w+w2)*16+g] = 0;
 
  672                     float t = fabsf(coefs[w2*128+i]);
 
  674                         qmin = 
FFMIN(qmin, t);
 
  675                     qmax = 
FFMAX(qmax, t);
 
  679                 int minscale, maxscale;
 
  686                 minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);
 
  687                 maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);
 
  689                 for (q = minscale; q < maxscale; q++) {
 
  697                     minrd = 
FFMIN(minrd, dist);
 
  699                     for (i = 0; i < q1 - 
q0; i++) {
 
  701                         cost = paths[idx - 1][i].
cost + dist
 
  703                         if (cost < paths[idx][q].cost) {
 
  704                             paths[idx][q].
cost    = cost;
 
  705                             paths[idx][q].
prev    = i;
 
  710                 for (q = 0; q < q1 - 
q0; q++) {
 
  711                     paths[idx][q].
cost = paths[idx - 1][q].
cost + 1;
 
  712                     paths[idx][q].
prev = q;
 
  721     mincost = paths[idx][0].
cost;
 
  724         if (paths[idx][i].cost < mincost) {
 
  725             mincost = paths[idx][i].
cost;
 
  730         sce->
sf_idx[bandaddr[idx]] = minq + 
q0;
 
  731         minq = paths[idx][minq].
prev;
 
  749     int start = 0, i, w, w2, 
g;
 
  752     float dists[128] = { 0 }, uplims[128] = { 0 };
 
  754     int noise_sf[128] = { 0 };
 
  755     int fflag, minscaler, minscaler_n;
 
  762     destbits = 
FFMIN(destbits, 5800);
 
  769             float uplim = 0.0f, energy = 0.0f;
 
  775                     sce->
zeroes[(w+w2)*16+g] = 1;
 
  780             uplims[w*16+
g] = uplim *512;
 
  782                 noise_sf[w*16+
g] = av_clip(4+
FFMIN(
log2f(energy)*2,255), -100, 155);
 
  790                 minthr = 
FFMIN(minthr, uplim);
 
  797             if (sce->
zeroes[w*16+g]) {
 
  822         minscaler = sce->
sf_idx[0];
 
  823         minscaler_n = sce->
sf_idx[0];
 
  825         qstep = its ? 1 : 32;
 
  839                         minscaler_n = 
FFMIN(minscaler_n, noise_sf[w*16+g]);
 
  842                     } 
else if (sce->
zeroes[w*16+g] || sce->
sf_idx[w*16+g] >= 218) {
 
  860                     dists[w*16+
g] = dist - 
bits;
 
  869             if (tbits > destbits) {
 
  870                 for (i = 0; i < 128; i++)
 
  871                     if (sce->
sf_idx[i] < 218 - qstep)
 
  874                 for (i = 0; i < 128; i++)
 
  875                     if (sce->
sf_idx[i] > 60 - qstep)
 
  879             if (!qstep && tbits > destbits*1.02 && sce->
sf_idx[0] < 217)
 
  893                 int prevsc = sce->
sf_idx[w*16+
g];
 
  896                 if (dists[w*16+g] > uplims[w*16+g] && sce->
sf_idx[w*16+g] > 60) {
 
  904                 if (sce->
sf_idx[w*16+g] != prevsc)
 
  910     } 
while (fflag && its < 10);
 
  917     int start = 0, i, w, w2, 
g;
 
  918     float uplim[128], maxq[128];
 
  920     float distfact = ((sce->
ics.
num_windows > 1) ? 85.80 : 147.84) / lambda;
 
  921     int last = 0, lastband = 0, curband = 0;
 
  922     float avg_energy = 0.0;
 
  925         for (i = 0; i < 1024; i++) {
 
  937         for (w = 0; w < 8; w++) {
 
  938             const float *coeffs = sce->
coeffs + w*128;
 
  940             for (i = 0; i < 128; i++) {
 
  946                     avg_energy += coeffs[i] * coeffs[i];
 
  947                     last = 
FFMAX(last, i);
 
  948                     lastband = 
FFMAX(lastband, curband);
 
  955     if (avg_energy == 0.0f) {
 
  966             float maxval = -1, thr = 0.0f, t;
 
  972                     memset(coefs + w2*128, 0, 
sizeof(coefs[0])*
size);
 
  976                 for (i = 0; i < 
size; i++) {
 
  977                     float t = coefs[w2*128+i]*coefs[w2*128+i];
 
  978                     maxq[w*16+
g] = 
FFMAX(maxq[w*16+g], fabsf(coefs[w2*128 + i]));
 
  987                 start2 = 
FFMAX(peakpos - 2, start2);
 
  988                 end2   = 
FFMIN(peakpos + 3, end2);
 
  994             thr = pow(thr / (avg_energy * (end2 - start2)), 0.3 + 0.1*(lastband - g) / lastband);
 
  995             t   = 1.0 - (1.0 * start2 / last);
 
  996             uplim[w*16+
g] = distfact / (1.4 * thr + t*t*t + 0.075);
 
 1007             int scf, prev_scf, step;
 
 1008             int min_scf = -1, max_scf = 256;
 
 1010             if (maxq[w*16+g] < 21.544) {
 
 1033                 dist *= 1.0f / 512.0f / lambda;
 
 1035                 if (quant_max >= 8191) { 
 
 1036                     sce->
sf_idx[w*16+
g] = prev_scf;
 
 1040                 curdiff = fabsf(dist - uplim[w*16+g]);
 
 1041                 if (curdiff <= 1.0f)
 
 1044                     step = 
log2f(curdiff);
 
 1045                 if (dist > uplim[w*16+g])
 
 1048                 scf = av_clip_uint8(scf);
 
 1049                 step = scf - prev_scf;
 
 1050                 if (
FFABS(step) <= 1 || (step > 0 && scf >= max_scf) || (step < 0 && scf <= min_scf)) {
 
 1051                     sce->
sf_idx[w*16+
g] = av_clip(scf, min_scf, max_scf);
 
 1063     for (i = 1; i < 128; i++) {
 
 1069     if (minq == INT_MAX)
 
 1073     for (i = 126; i >= 0; i--) {
 
 1093                     sce->
sf_idx[(w+w2)*16+g] = 218;
 
 1094                     sce->
zeroes[(w+w2)*16+g] = 1;
 
 1097                     sce->
zeroes[(w+w2)*16+g] = 0;
 
 1103     for (i = 0; i < 128; i++) {
 
 1117     int start = 0, i, w, w2, 
g;
 
 1118     float M[128], 
S[128];
 
 1127                 float dist1 = 0.0f, dist2 = 0.0f;
 
 1134                         M[i] = (sce0->
pcoeffs[start+w2*128+i]
 
 1135                               + sce1->
pcoeffs[start+w2*128+i]) * 0.5;
 
 1137                               - sce1->
pcoeffs[start+w2*128+i];
 
 1146                                                 sce0->
sf_idx[(w+w2)*16+g],
 
 1152                                                 sce1->
sf_idx[(w+w2)*16+g],
 
 1158                                                 sce0->
sf_idx[(w+w2)*16+g],
 
 1164                                                 sce1->
sf_idx[(w+w2)*16+g],
 
 1168                 cpe->
ms_mask[w*16+
g] = dist2 < dist1;
 
static const uint8_t run_value_bits_long[64]
bits needed to code codebook run value for long windows 
 
AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB]
 
static av_always_inline uint8_t coef2maxsf(float coef)
Return the maximum scalefactor where the quantized coef is not zero. 
 
static void encode_window_bands_info(AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
Encode band info for single window group bands. 
 
static void put_sbits(PutBitContext *pb, int n, int32_t value)
 
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit 
 
float pcoeffs[1024]
coefficients for IMDCT, pristine 
 
#define SCALE_DIFF_ZERO
codebook index corresponding to zero scalefactor indices difference 
 
FFPsyBand psy_bands[PSY_MAX_BANDS]
channel bands information 
 
static const uint8_t run_value_bits_short[16]
bits needed to code codebook run value for short windows 
 
#define SCALE_MAX_POS
scalefactor index maximum value 
 
static int find_min_book(float maxval, int sf)
 
#define SCALE_MAX_DIFF
maximum scalefactor difference allowed by standard 
 
static const uint8_t aac_cb_in_map[CB_TOT+1]
Inverse map to convert from codebooks to BandCodingPath indices. 
 
int common_window
Set if channels share a common 'IndividualChannelStream' in bitstream. 
 
#define quantize_and_encode_band_cost(s, pb, in, scaled, size, scale_idx, cb, lambda, uplim, bits)
 
int prev_idx
pointer to the previous path point 
 
#define FF_ARRAY_ELEMS(a)
 
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band. 
 
static const uint8_t q1[256]
 
static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
 
Spectral data are scaled white noise not coded in the bitstream. 
 
#define av_assert0(cond)
assert() equivalent, that is always enabled. 
 
static double cb(void *priv, double x, double y)
 
AACEncOptions options
encoding options 
 
static void search_for_ms(AACEncContext *s, ChannelElement *cpe, const float lambda)
 
SingleChannelElement ch[2]
 
static av_always_inline int quant(float coef, const float Q)
Quantize one coefficient. 
 
const uint8_t ff_aac_scalefactor_bits[121]
 
int qcoefs[96]
quantized coefficients 
 
static const uint8_t run_bits[7][16]
 
single band psychoacoustic information 
 
static const uint8_t aac_cb_range[12]
 
float coeffs[1024]
coefficients for IMDCT, maybe processed 
 
static av_always_inline uint8_t coef2minsf(float coef)
Return the minimum scalefactor where the quantized coef does not clip. 
 
uint8_t max_sfb
number of scalefactor bands per group 
 
int num_swb
number of scalefactor window bands 
 
static void quantize_bands(int *out, const float *in, const float *scaled, int size, float Q34, int is_signed, int maxval)
 
Libavcodec external API header. 
 
static float quantize_band_cost(struct AACEncContext *s, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits)
 
const float *const ff_aac_codebook_vectors[]
 
static const uint8_t q0[256]
 
#define NOISE_LOW_LIMIT
Frequency in Hz for lower limit of noise substitution. 
 
#define POW_SF2_ZERO
ff_aac_pow2sf_tab index corresponding to pow(2, 0); 
 
#define SCALE_DIV_512
scalefactor difference that corresponds to scale difference in 512 times 
 
static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
 
static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, const float *in, int size, int scale_idx, int cb, const float lambda)
 
int bit_rate
the average bitrate 
 
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code. 
 
const uint8_t *const ff_aac_spectral_bits[11]
 
AAC definitions and structures. 
 
static void abs_pow34_v(float *out, const float *in, const int size)
 
float ff_aac_pow34sf_tab[428]
 
int sample_rate
samples per second 
 
static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
 
main external API structure. 
 
#define CB_TOT
Total number of usable codebooks. 
 
static const uint8_t aac_cb_out_map[CB_TOT]
Map to convert values from BandCodingPath index to a codebook index. 
 
IndividualChannelStream ics
 
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){if(!*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));if(!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=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);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);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) 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_log(ac->avr, AV_LOG_TRACE,"%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 av_always_inline float cbrtf(float x)
 
structure used in optimal codebook search 
 
Replacements for frequently missing libm functions. 
 
Spectral data are coded with an escape sequence. 
 
const uint8_t * swb_sizes
table of scalefactor band sizes for a particular window 
 
static float(*const quantize_and_encode_band_cost_arr[])(struct AACEncContext *s, PutBitContext *pb, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits)
 
uint8_t zeroes[128]
band is not coded (used by encoder) 
 
int sf_idx[128]
scalefactor indices (used by encoder) 
 
#define SCALE_ONE_POS
scalefactor index that corresponds to scale=1.0 
 
static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
 
static void search_for_quantizers_twoloop(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
two-loop quantizers search taken from ISO 13818-7 Appendix C 
 
Single Channel Element - used for both SCE and LFE elements. 
 
static const uint8_t aac_cb_maxval[12]
 
static av_always_inline float quantize_and_encode_band_cost_template(struct AACEncContext *s, PutBitContext *pb, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, int BT_ZERO, int BT_UNSIGNED, int BT_PAIR, int BT_ESC, int BT_NOISE)
Calculate rate distortion cost for quantizing with given codebook. 
 
float ff_aac_pow2sf_tab[428]
 
static float find_max_val(int group_len, int swb_size, const float *scaled)
 
channel element - generic struct for SCE/CPE/CCE/LFE 
 
const uint16_t *const ff_aac_spectral_codes[11]
 
int channels
number of audio channels 
 
FFPsyChannel * ch
single channel information 
 
enum BandType band_type[128]
band types 
 
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){if(!*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));if(!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=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);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);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) 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_log(ac->avr, AV_LOG_TRACE,"%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
 
static float quantize_and_encode_band_cost_NONE(struct AACEncContext *s, PutBitContext *pb, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits)
 
static const uint8_t *const run_value_bits[2]
 
#define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE)
 
float scoefs[1024]
scaled coefficients