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

void vbw_bit_allocation ( A52ThreadContext *  tctx  ) 

Variable bandwidth bit allocation This estimates the bandwidth code which will give quality around 240.

Definition at line 427 of file bitalloc.c.

References bit_alloc(), and start_bit_allocation().

{
    A52Context *ctx = tctx->ctx;
    A52Frame *frame = &tctx->frame;
    FLOAT mant_bits;
    int blk, ch, bw, nc;
    int avail_bits, bits;
    int wmin, wmax, ncmin, ncmax;

    start_bit_allocation(tctx);
    avail_bits = (16 * frame->frame_size) - frame->frame_bits;

    bit_alloc_prepare(tctx);
    bit_alloc(tctx, 240);

    // deduct any LFE exponent and mantissa bits
    if (ctx->lfe) {
        FLOAT lfe_bits = FCONST(0.0);
        ch = ctx->lfe_channel;
        lfe_bits += expstr_set_bits[frame->expstr_set[ch]][7];
        for (blk = 0; blk < A52_NUM_BLOCKS; blk++) {
            uint8_t *bap = frame->blocks[blk].bap[ch];
            for (nc = 0; nc < 7; nc++)
                lfe_bits += mant_est_tab[bap[nc]];
        }
        avail_bits -= (int)lfe_bits;
    }

    // set limits
    wmin = ctx->params.min_bwcode;
    wmax = ctx->params.max_bwcode;
    ncmin = wmin * 3 + 73;
    ncmax = wmax * 3 + 73;

    // sum up mantissa bits up to bin 72
    mant_bits = FCONST(0.0);
    for (ch = 0; ch < ctx->n_channels; ch++) {
        for (blk = 0; blk < A52_NUM_BLOCKS; blk++) {
            uint8_t *bap = frame->blocks[blk].bap[ch];
            for (nc = 0; nc < ncmin; nc++)
                mant_bits += mant_est_tab[bap[nc]];
        }
    }

    // add bins while estimated bits fit in the frame
    for (nc = ncmin; nc <= ncmax; nc++) {
        bw = (nc - 73) / 3;
        bits = 0;
        for (ch = 0; ch < ctx->n_channels; ch++) {
            bits += expstr_set_bits[frame->expstr_set[ch]][nc];
            for (blk = 0; blk < A52_NUM_BLOCKS; blk++)
                mant_bits += mant_est_tab[frame->blocks[blk].bap[ch][nc]];
        }
        if ((bits + (int)mant_bits) > avail_bits)
            break;
    }

    // set frame bandwidth parameters
    bw = CLIP((nc - 73) / 3, 0, 60);
    nc = bw * 3 + 73;
    frame->bwcode = bw;
    for (ch = 0; ch < ctx->n_channels; ch++)
        frame->ncoefs[ch] = nc;
}


Generated by  Doxygen 1.6.0   Back to index