Correct bad indentation in aaccoder Clarify and correct comments in 3GPP psymodel, other cosmetics.
Unified · Split
| @@ -146,34 +146,34 @@ static av_always_inline float quantize_and_encode_band_cost_template( · 145 unmodified lines | ||
| 146 | 146 | curidx *= range; |
| 147 | 147 | curidx += quants[j] + off; |
| 148 | 148 | } |
| 149 | − curbits = ff_aac_spectral_bits[cb-1][curidx]; | |
| 150 | − vec = &ff_aac_codebook_vectors[cb-1][curidx*dim]; | |
| 151 | − if (BT_UNSIGNED) { | |
| 152 | − for (k = 0; k < dim; k++) { | |
| 153 | − float t = fabsf(in[i+k]); | |
| 154 | − float di; | |
| 155 | − if (BT_ESC && vec[k] == 64.0f) { //FIXME: slow | |
| 156 | − if (t >= CLIPPED_ESCAPE) { | |
| 157 | − di = t - CLIPPED_ESCAPE; | |
| 158 | − curbits += 21; | |
| 159 | − } else { | |
| 160 | − int c = av_clip(quant(t, Q), 0, 8191); | |
| 161 | − di = t - c*cbrtf(c)*IQ; | |
| 162 | − curbits += av_log2(c)*2 - 4 + 1; | |
| 163 | − } | |
| 149 | + curbits = ff_aac_spectral_bits[cb-1][curidx]; | |
| 150 | + vec = &ff_aac_codebook_vectors[cb-1][curidx*dim]; | |
| 151 | + if (BT_UNSIGNED) { | |
| 152 | + for (k = 0; k < dim; k++) { | |
| 153 | + float t = fabsf(in[i+k]); | |
| 154 | + float di; | |
| 155 | + if (BT_ESC && vec[k] == 64.0f) { //FIXME: slow | |
| 156 | + if (t >= CLIPPED_ESCAPE) { | |
| 157 | + di = t - CLIPPED_ESCAPE; | |
| 158 | + curbits += 21; | |
| 164 | 159 | } else { |
| 165 | − di = t - vec[k]*IQ; | |
| 160 | + int c = av_clip(quant(t, Q), 0, 8191); | |
| 161 | + di = t - c*cbrtf(c)*IQ; | |
| 162 | + curbits += av_log2(c)*2 - 4 + 1; | |
| 166 | 163 | } |
| 167 | − if (vec[k] != 0.0f) | |
| 168 | − curbits++; | |
| 169 | − rd += di*di; | |
| 170 | − } | |
| 171 | − } else { | |
| 172 | − for (k = 0; k < dim; k++) { | |
| 173 | − float di = in[i+k] - vec[k]*IQ; | |
| 174 | − rd += di*di; | |
| 164 | + } else { | |
| 165 | + di = t - vec[k]*IQ; | |
| 175 | 166 | } |
| 167 | + if (vec[k] != 0.0f) | |
| 168 | + curbits++; | |
| 169 | + rd += di*di; | |
| 176 | 170 | } |
| 171 | + } else { | |
| 172 | + for (k = 0; k < dim; k++) { | |
| 173 | + float di = in[i+k] - vec[k]*IQ; | |
| 174 | + rd += di*di; | |
| 175 | + } | |
| 176 | + } | |
| 177 | 177 | cost += rd * lambda + curbits; |
| 178 | 178 | resbits += curbits; |
| 179 | 179 | if (cost >= uplim) |
| @@ -575,7 +575,7 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, · 395 unmodified lines | ||
| 575 | 575 | int qnrg = av_clip_uint8(log2f(sqrtf(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512); |
| 576 | 576 | q1 = qnrg + 30; |
| 577 | 577 | q0 = qnrg - 30; |
| 578 | − //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); | |
| 578 | + //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); | |
| 579 | 579 | if (q0 < q0low) { |
| 580 | 580 | q1 += q0low - q0; |
| 581 | 581 | q0 = q0low; |
| @@ -39,8 +39,8 @@ · 38 unmodified lines | ||
| 39 | 39 | * constants for 3GPP AAC psychoacoustic model |
| 40 | 40 | * @{ |
| 41 | 41 | */ |
| 42 | −#define PSY_3GPP_SPREAD_HI 1.5f // spreading factor for ascending threshold spreading (15 dB/Bark) | |
| 43 | −#define PSY_3GPP_SPREAD_LOW 3.0f // spreading factor for descending threshold spreading (30 dB/Bark) | |
| 42 | +#define PSY_3GPP_THR_SPREAD_HI 1.5f // spreading factor for low-to-hi threshold spreading (15 dB/Bark) | |
| 43 | +#define PSY_3GPP_THR_SPREAD_LOW 3.0f // spreading factor for hi-to-low threshold spreading (30 dB/Bark) | |
| 44 | 44 | |
| 45 | 45 | #define PSY_3GPP_RPEMIN 0.01f |
| 46 | 46 | #define PSY_3GPP_RPELEV 2.0f |
| @@ -256,8 +256,8 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) { · 209 unmodified lines | ||
| 256 | 256 | for (g = 0; g < ctx->num_bands[j] - 1; g++) { |
| 257 | 257 | AacPsyCoeffs *coeff = &coeffs[g]; |
| 258 | 258 | float bark_width = coeffs[g+1].barks - coeffs->barks; |
| 259 | − coeff->spread_low[0] = pow(10.0, -bark_width * PSY_3GPP_SPREAD_LOW); | |
| 260 | − coeff->spread_hi [0] = pow(10.0, -bark_width * PSY_3GPP_SPREAD_HI); | |
| 259 | + coeff->spread_low[0] = pow(10.0, -bark_width * PSY_3GPP_THR_SPREAD_LOW); | |
| 260 | + coeff->spread_hi [0] = pow(10.0, -bark_width * PSY_3GPP_THR_SPREAD_HI); | |
| 261 | 261 | } |
| 262 | 262 | start = 0; |
| 263 | 263 | for (g = 0; g < ctx->num_bands[j]; g++) { |
| @@ -395,9 +395,9 @@ static void psy_3gpp_analyze(FFPsyContext *ctx, int channel, · 131 unmodified lines | ||
| 395 | 395 | AacPsyChannel *pch = &pctx->ch[channel]; |
| 396 | 396 | int start = 0; |
| 397 | 397 | int i, w, g; |
| 398 | − const int num_bands = ctx->num_bands[wi->num_windows == 8]; | |
| 399 | − const uint8_t* band_sizes = ctx->bands[wi->num_windows == 8]; | |
| 400 | − AacPsyCoeffs *coeffs = &pctx->psy_coef[wi->num_windows == 8]; | |
| 398 | + const int num_bands = ctx->num_bands[wi->num_windows == 8]; | |
| 399 | + const uint8_t *band_sizes = ctx->bands[wi->num_windows == 8]; | |
| 400 | + AacPsyCoeffs *coeffs = &pctx->psy_coef[wi->num_windows == 8]; | |
| 401 | 401 | |
| 402 | 402 | //calculate energies, initial thresholds and related values - 5.4.2 "Threshold Calculation" |
| 403 | 403 | for (w = 0; w < wi->num_windows*16; w += 16) { |
| @@ -410,17 +410,19 @@ static void psy_3gpp_analyze(FFPsyContext *ctx, int channel, · 6 unmodified lines | ||
| 410 | 410 | start += band_sizes[g]; |
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | − //modify thresholds - spread, threshold in quiet - 5.4.3 "Spreaded Energy Calculation" | |
| 413 | + //modify thresholds and energies - spread, threshold in quiet, pre-echo control | |
| 414 | 414 | for (w = 0; w < wi->num_windows*16; w += 16) { |
| 415 | − | |
| 416 | 415 | AacPsyBand *bands = &pch->band[w]; |
| 416 | + //5.4.2.3 "Spreading" & 5.4.3 "Spreaded Energy Calculation" | |
| 417 | 417 | for (g = 1; g < num_bands; g++) |
| 418 | 418 | bands[g].thr = FFMAX(bands[g].thr, bands[g-1].thr * coeffs[g].spread_hi[0]); |
| 419 | 419 | for (g = num_bands - 2; g >= 0; g--) |
| 420 | 420 | bands[g].thr = FFMAX(bands[g].thr, bands[g+1].thr * coeffs[g].spread_low[0]); |
| 421 | + //5.4.2.4 "Threshold in quiet" | |
| 421 | 422 | for (g = 0; g < num_bands; g++) { |
| 422 | 423 | AacPsyBand *band = &bands[g]; |
| 423 | 424 | band->thr_quiet = band->thr = FFMAX(band->thr, coeffs[g].ath); |
| 425 | + //5.4.2.5 "Pre-echo control" | |
| 424 | 426 | if (!(wi->window_type[0] == LONG_STOP_SEQUENCE || (wi->window_type[1] == LONG_START_SEQUENCE && !w))) |
| 425 | 427 | band->thr = FFMAX(PSY_3GPP_RPEMIN*band->thr, FFMIN(band->thr, |
| 426 | 428 | PSY_3GPP_RPELEV*pch->prev_band[w+g].thr_quiet)); |
| @@ -436,6 +438,7 @@ static void psy_3gpp_analyze(FFPsyContext *ctx, int channel, · 9 unmodified lines | ||
| 436 | 438 | psy_band->energy = band->energy; |
| 437 | 439 | } |
| 438 | 440 | } |
| 441 | + | |
| 439 | 442 | memcpy(pch->prev_band, pch->band, sizeof(pch->band)); |
| 440 | 443 | } |
| 441 | 444 | |