00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "avcodec.h"
00028 #include "aacpsy.h"
00029 #include "aactab.h"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00049 static av_always_inline int quant(float coef, const float Q)
00050 {
00051 return av_clip((int)(pow(fabsf(coef) * Q, 0.75) + 0.4054), 0, 8191);
00052 }
00053
00054 static inline float get_approximate_quant_error(float *c, int size, int scale_idx)
00055 {
00056 int i;
00057 int q;
00058 float coef, unquant, sum = 0.0f;
00059 const float Q = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
00060 const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
00061 for(i = 0; i < size; i++){
00062 coef = fabs(c[i]);
00063 q = quant(c[i], Q);
00064 unquant = (q * cbrt(q)) * IQ;
00065 sum += (coef - unquant) * (coef - unquant);
00066 }
00067 return sum;
00068 }
00069
00074 #define PSY_3GPP_SPREAD_LOW 1.5f // spreading factor for ascending threshold spreading (15 dB/Bark)
00075 #define PSY_3GPP_SPREAD_HI 3.0f // spreading factor for descending threshold spreading (30 dB/Bark)
00076
00083 typedef struct Psy3gppBand{
00084 float energy;
00085 float ffac;
00086 }Psy3gppBand;
00087
00091 typedef struct Psy3gppCoeffs{
00092 float ath [64];
00093 float barks [64];
00094 float spread_low[64];
00095 float spread_hi [64];
00096 }Psy3gppCoeffs;
00097
00101 static inline float calc_bark(float f)
00102 {
00103 return 13.3f * atanf(0.00076f * f) + 3.5f * atanf((f / 7500.0f) * (f / 7500.0f));
00104 }