Logo Search packages:      
Sourcecode: aften version File versions  Download package

void a52_bit_alloc_calc_mask ( A52BitAllocParams *  s,
int16_t *  band_psd,
int  start,
int  end,
int  fast_gain,
int  dba_mode,
int  dba_nsegs,
uint8_t *  dba_offsets,
uint8_t *  dba_lengths,
uint8_t *  dba_values,
int16_t *  mask 
)

Calculates the masking curve. First, the excitation is calculated using parameters in s and the signal power in each critical band. The excitation is compared with a predefined hearing threshold table to produce the masking curve. If delta bit allocation information is provided, it is used for adjusting the masking curve, usually to give a closer match to a better psychoacoustic model.

Parameters:
[in] s adjustable bit allocation parameters
[in] band_psd signal power for each critical band
[in] start starting bin location
[in] end ending bin location
[in] fast_gain fast gain (estimated signal-to-mask ratio)
[in] dba_mode delta bit allocation mode (none, reuse, or new)
[in] dba_nsegs number of delta segments
[in] dba_offsets location offsets for each segment
[in] dba_lengths length of each segment
[in] dba_values delta bit allocation for each segment
[out] mask calculated masking curve

Definition at line 77 of file a52.c.

References a52_hearing_threshold_tab.

Referenced by a52_bit_allocation_prepare().

{
    int16_t excite[50]; /* excitation */
    int band;
    int band_start, band_end, begin, end1;
    int lowcomp, fastleak, slowleak;

    /* excitation function */
    band_start = bin_to_band_tab[start];
    band_end = bin_to_band_tab[end-1] + 1;

    if (band_start == 0) {
        lowcomp = 0;
        lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384);
        excite[0] = band_psd[0] - fast_gain - lowcomp;
        lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384);
        excite[1] = band_psd[1] - fast_gain - lowcomp;
        begin = 7;
        for (band = 2; band < 7; band++) {
            if (!(band_end == 7 && band == 6))
                lowcomp = calc_lowcomp1(lowcomp, band_psd[band], band_psd[band+1], 384);
            fastleak = band_psd[band] - fast_gain;
            slowleak = band_psd[band] - s->sgain;
            excite[band] = fastleak - lowcomp;
            if (!(band_end == 7 && band == 6)) {
                if (band_psd[band] <= band_psd[band+1]) {
                    begin = band + 1;
                    break;
                }
            }
        }

        end1 = MIN(band_end, 22);

        for (band = begin; band < end1; band++) {
            if (!(band_end == 7 && band == 6))
                lowcomp = calc_lowcomp(lowcomp, band_psd[band], band_psd[band+1], band);

            fastleak = MAX(fastleak - s->fdecay, band_psd[band] - fast_gain);
            slowleak = MAX(slowleak - s->sdecay, band_psd[band] - s->sgain);
            excite[band] = MAX(fastleak - lowcomp, slowleak);
        }
        begin = 22;
    } else {
        /* coupling channel */
        begin = band_start;
        fastleak = (s->cplfleak << 8) + 768;
        slowleak = (s->cplsleak << 8) + 768;
    }

    for (band = begin; band < band_end; band++) {
        fastleak = MAX(fastleak - s->fdecay, band_psd[band] - fast_gain);
        slowleak = MAX(slowleak - s->sdecay, band_psd[band] - s->sgain);
        excite[band] = MAX(fastleak, slowleak);
    }

    /* compute masking curve */

    for (band = band_start; band < band_end; band++) {
        int tmp = s->dbknee - band_psd[band];
        if (tmp > 0)
            excite[band] += tmp >> 2;
        mask[band] = MAX(a52_hearing_threshold_tab[band >> s->halfratecod][s->fscod], excite[band]);
    }

    /* delta bit allocation */
    if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {
        int i, band, seg, delta;
        dba_nsegs = MIN(dba_nsegs, 8);
        band = 0;
        for (seg = 0; seg < dba_nsegs; seg++) {
            band += dba_offsets[seg];
            if (dba_values[seg] >= 4)
                delta = (dba_values[seg] - 3) << 7;
            else
                delta = (dba_values[seg] - 4) << 7;
            for (i = 0; i < dba_lengths[seg] && band < 50; i++)
                mask[band++] += delta;
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index