void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
                               int snr_offset, int floor, uint8_t *bap)
{
    int i, j, k, end1, v, address;
    if(snr_offset == -960) {
        memset(bap, 0, 256);
        return;
    }
    i = start;
    j = bin_to_band_tab[start];
    do {
        v = (FFMAX(mask[j] - snr_offset - floor, 0) & 0x1FE0) + floor;
        end1 = FFMIN(band_start_tab[j] + ff_ac3_critical_band_size_tab[j], end);
        for (k = i; k < end1; k++) {
            address = av_clip((psd[i] - v) >> 5, 0, 63);
            bap[i] = ff_ac3_bap_tab[address];
            i++;
        }
    } while (end > band_start_tab[j++]);
}
['static int bit_alloc(AC3EncodeContext *s,\n                     int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50],\n                     int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],\n                     uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],\n                     int frame_bits, int coarse_snr_offset, int fine_snr_offset)\n{\n    int i, ch;\n    int snr_offset;\n    snr_offset = (((coarse_snr_offset - 15) << 4) + fine_snr_offset) << 2;\n    for(i=0;i<NB_BLOCKS;i++) {\n        s->mant1_cnt = 0;\n        s->mant2_cnt = 0;\n        s->mant4_cnt = 0;\n        for(ch=0;ch<s->nb_all_channels;ch++) {\n            ff_ac3_bit_alloc_calc_bap(mask[i][ch], psd[i][ch], 0,\n                                      s->nb_coefs[ch], snr_offset,\n                                      s->bit_alloc.floor, bap[i][ch]);\n            frame_bits += compute_mantissa_size(s, bap[i][ch],\n                                                 s->nb_coefs[ch]);\n        }\n    }\n#if 0\n    printf("csnr=%d fsnr=%d frame_bits=%d diff=%d\\n",\n           coarse_snr_offset, fine_snr_offset, frame_bits,\n           16 * s->frame_size - ((frame_bits + 7) & ~7));\n#endif\n    return 16 * s->frame_size - frame_bits;\n}', 'void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,\n                               int snr_offset, int floor, uint8_t *bap)\n{\n    int i, j, k, end1, v, address;\n    if(snr_offset == -960) {\n        memset(bap, 0, 256);\n        return;\n    }\n    i = start;\n    j = bin_to_band_tab[start];\n    do {\n        v = (FFMAX(mask[j] - snr_offset - floor, 0) & 0x1FE0) + floor;\n        end1 = FFMIN(band_start_tab[j] + ff_ac3_critical_band_size_tab[j], end);\n        for (k = i; k < end1; k++) {\n            address = av_clip((psd[i] - v) >> 5, 0, 63);\n            bap[i] = ff_ac3_bap_tab[address];\n            i++;\n        }\n    } while (end > band_start_tab[j++]);\n}']