Revision f50d9377

View differences:

libavcodec/aacpsy.c
100 100
 * information for single band used by 3GPP TS26.403-inspired psychoacoustic model
101 101
 */
102 102
typedef struct AacPsyBand{
103
    float energy;    ///< band energy
104
    float thr;       ///< energy threshold
105
    float thr_quiet; ///< threshold in quiet
103
    float energy;       ///< band energy
104
    float thr;          ///< energy threshold
105
    float thr_quiet;    ///< threshold in quiet
106 106
    float nz_lines;     ///< number of non-zero spectral lines
107 107
    float active_lines; ///< number of active spectral lines
108 108
    float pe;           ///< perceptual entropy
......
566 566
    float desired_bits, desired_pe, delta_pe, reduction, spread_en[128] = {0};
567 567
    float a = 0.0f, active_lines = 0.0f, norm_fac = 0.0f;
568 568
    float pe = pctx->chan_bitrate > 32000 ? 0.0f : FFMAX(50.0f, 100.0f - pctx->chan_bitrate * 100.0f / 32000.0f);
569
    const int      num_bands  = ctx->num_bands[wi->num_windows == 8];
570
    const uint8_t *band_sizes = ctx->bands[wi->num_windows == 8];
571
    AacPsyCoeffs  *coeffs     = pctx->psy_coef[wi->num_windows == 8];
569
    const int      num_bands   = ctx->num_bands[wi->num_windows == 8];
570
    const uint8_t *band_sizes  = ctx->bands[wi->num_windows == 8];
571
    AacPsyCoeffs  *coeffs      = pctx->psy_coef[wi->num_windows == 8];
572 572
    const float avoid_hole_thr = wi->num_windows == 8 ? PSY_3GPP_AH_THR_SHORT : PSY_3GPP_AH_THR_LONG;
573 573

  
574 574
    //calculate energies, initial thresholds and related values - 5.4.2 "Threshold Calculation"
575 575
    for (w = 0; w < wi->num_windows*16; w += 16) {
576 576
        for (g = 0; g < num_bands; g++) {
577 577
            AacPsyBand *band = &pch->band[w+g];
578

  
578 579
            float form_factor = 0.0f;
579 580
            band->energy = 0.0f;
580 581
            for (i = 0; i < band_sizes[g]; i++) {
581 582
                band->energy += coefs[start+i] * coefs[start+i];
582 583
                form_factor  += sqrtf(fabs(coefs[start+i]));
583 584
            }
584
            band->thr     = band->energy * 0.001258925f;
585
            band->thr      = band->energy * 0.001258925f;
585 586
            band->nz_lines = form_factor / powf(band->energy / band_sizes[g], 0.25f);
586 587

  
587
            start        += band_sizes[g];
588
            start += band_sizes[g];
588 589
        }
589 590
    }
590 591
    //modify thresholds and energies - spread, threshold in quiet, pre-echo control
591 592
    for (w = 0; w < wi->num_windows*16; w += 16) {
592 593
        AacPsyBand *bands = &pch->band[w];
594

  
593 595
        //5.4.2.3 "Spreading" & 5.4.3 "Spreaded Energy Calculation"
594 596
        spread_en[0] = bands[0].energy;
595 597
        for (g = 1; g < num_bands; g++) {
596
            bands[g].thr = FFMAX(bands[g].thr, bands[g-1].thr * coeffs[g].spread_hi[0]);
598
            bands[g].thr   = FFMAX(bands[g].thr,    bands[g-1].thr * coeffs[g].spread_hi[0]);
597 599
            spread_en[w+g] = FFMAX(bands[g].energy, spread_en[w+g-1] * coeffs[g].spread_hi[1]);
598 600
        }
599 601
        for (g = num_bands - 2; g >= 0; g--) {
600
            bands[g].thr = FFMAX(bands[g].thr, bands[g+1].thr * coeffs[g].spread_low[0]);
602
            bands[g].thr   = FFMAX(bands[g].thr,   bands[g+1].thr * coeffs[g].spread_low[0]);
601 603
            spread_en[w+g] = FFMAX(spread_en[w+g], spread_en[w+g+1] * coeffs[g].spread_low[1]);
602 604
        }
603 605
        //5.4.2.4 "Threshold in quiet"
604 606
        for (g = 0; g < num_bands; g++) {
605 607
            AacPsyBand *band = &bands[g];
608

  
606 609
            band->thr_quiet = band->thr = FFMAX(band->thr, coeffs[g].ath);
607 610
            //5.4.2.5 "Pre-echo control"
608 611
            if (!(wi->window_type[0] == LONG_STOP_SEQUENCE || (wi->window_type[1] == LONG_START_SEQUENCE && !w)))

Also available in: Unified diff