-void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
- int snr_offset, int floor,
- const uint8_t *bap_tab, uint8_t *bap)
-{
- int bin, band;
-
- /* special case, if snr offset is -960, set all bap's to zero */
- if (snr_offset == -960) {
- memset(bap, 0, 256);
- return;
- }
-
- bin = start;
- band = bin_to_band_tab[start];
- do {
- int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor;
- int band_end = FFMIN(band_start_tab[band] + ff_ac3_critical_band_size_tab[band], end);
- for (; bin < band_end; bin++) {
- int address = av_clip((psd[bin] - m) >> 5, 0, 63);
- bap[bin] = bap_tab[address];
- }
- } while (end > band_start_tab[band++]);
-}
-
-/* AC-3 bit allocation. The algorithm is the one described in the AC-3
- spec. */
-void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
- int8_t *exp, int start, int end,
- int snr_offset, int fast_gain, int is_lfe,
- int dba_mode, int dba_nsegs,
- uint8_t *dba_offsets, uint8_t *dba_lengths,
- uint8_t *dba_values)
-{
- int16_t psd[256]; /* scaled exponents */
- int16_t band_psd[50]; /* interpolated exponents */
- int16_t mask[50]; /* masking value */
-
- ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd);
-
- ff_ac3_bit_alloc_calc_mask(s, band_psd, start, end, fast_gain, is_lfe,
- dba_mode, dba_nsegs, dba_offsets, dba_lengths,
- dba_values, mask);
-
- ff_ac3_bit_alloc_calc_bap(mask, psd, start, end, snr_offset, s->floor,
- ff_ac3_bap_tab, bap);
-}
-