comparison aacpsy.c @ 12159:25ac974ce96d libavcodec

aacenc: psy_3gpp_init(): Calculate barks on demand.
author alexc
date Wed, 14 Jul 2010 04:10:31 +0000
parents 2e7db647fef8
children e0bed2f0f9f9
comparison
equal deleted inserted replaced
12158:3212dfbe4c96 12159:25ac974ce96d
112 + (0.6 + 0.04 * add) * 0.001 * f * f * f * f; 112 + (0.6 + 0.04 * add) * 0.001 * f * f * f * f;
113 } 113 }
114 114
115 static av_cold int psy_3gpp_init(FFPsyContext *ctx) { 115 static av_cold int psy_3gpp_init(FFPsyContext *ctx) {
116 Psy3gppContext *pctx; 116 Psy3gppContext *pctx;
117 float barks[1024]; 117 float bark;
118 int i, j, g, start; 118 int i, j, g, start;
119 float prev, minscale, minath; 119 float prev, minscale, minath;
120 120
121 ctx->model_priv_data = av_mallocz(sizeof(Psy3gppContext)); 121 ctx->model_priv_data = av_mallocz(sizeof(Psy3gppContext));
122 pctx = (Psy3gppContext*) ctx->model_priv_data; 122 pctx = (Psy3gppContext*) ctx->model_priv_data;
123 123
124 for (i = 0; i < 1024; i++)
125 barks[i] = calc_bark(i * ctx->avctx->sample_rate / 2048.0);
126 minath = ath(3410, ATH_ADD); 124 minath = ath(3410, ATH_ADD);
127 for (j = 0; j < 2; j++) { 125 for (j = 0; j < 2; j++) {
128 Psy3gppCoeffs *coeffs = &pctx->psy_coef[j]; 126 Psy3gppCoeffs *coeffs = &pctx->psy_coef[j];
129 i = 0; 127 i = 0;
130 prev = 0.0; 128 prev = 0.0;
131 for (g = 0; g < ctx->num_bands[j]; g++) { 129 for (g = 0; g < ctx->num_bands[j]; g++) {
132 i += ctx->bands[j][g]; 130 i += ctx->bands[j][g];
133 coeffs->barks[g] = (barks[i - 1] + prev) / 2.0; 131 bark = calc_bark((i-1) * ctx->avctx->sample_rate / 2048.0);
134 prev = barks[i - 1]; 132 coeffs->barks[g] = (bark + prev) / 2.0;
133 prev = bark;
135 } 134 }
136 for (g = 0; g < ctx->num_bands[j] - 1; g++) { 135 for (g = 0; g < ctx->num_bands[j] - 1; g++) {
137 coeffs->spread_low[g] = pow(10.0, -(coeffs->barks[g+1] - coeffs->barks[g]) * PSY_3GPP_SPREAD_LOW); 136 coeffs->spread_low[g] = pow(10.0, -(coeffs->barks[g+1] - coeffs->barks[g]) * PSY_3GPP_SPREAD_LOW);
138 coeffs->spread_hi [g] = pow(10.0, -(coeffs->barks[g+1] - coeffs->barks[g]) * PSY_3GPP_SPREAD_HI); 137 coeffs->spread_hi [g] = pow(10.0, -(coeffs->barks[g+1] - coeffs->barks[g]) * PSY_3GPP_SPREAD_HI);
139 } 138 }