Commit 5ce21342 authored by Justin Ruggles's avatar Justin Ruggles

cosmetics: rename ac3 bit allocation variables

Originally committed as revision 11194 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 66ecf18e
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
#include "ac3.h" #include "ac3.h"
#include "bitstream.h" #include "bitstream.h"
static uint8_t bndtab[51]; static uint8_t band_start_tab[51];
static uint8_t masktab[253]; static uint8_t bin_to_band_tab[253];
static inline int calc_lowcomp1(int a, int b0, int b1, int c) static inline int calc_lowcomp1(int a, int b0, int b1, int c)
{ {
...@@ -53,7 +53,7 @@ static inline int calc_lowcomp(int a, int b0, int b1, int bin) ...@@ -53,7 +53,7 @@ static inline int calc_lowcomp(int a, int b0, int b1, int bin)
} }
void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
int16_t *bndpsd) int16_t *band_psd)
{ {
int bin, i, j, k, end1, v; int bin, i, j, k, end1, v;
...@@ -64,26 +64,26 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, ...@@ -64,26 +64,26 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
/* PSD integration */ /* PSD integration */
j=start; j=start;
k=masktab[start]; k=bin_to_band_tab[start];
do { do {
v=psd[j]; v=psd[j];
j++; j++;
end1 = FFMIN(bndtab[k+1], end); end1 = FFMIN(band_start_tab[k+1], end);
for(i=j;i<end1;i++) { for(i=j;i<end1;i++) {
/* logadd */ /* logadd */
int adr = FFMIN(FFABS(v - psd[j]) >> 1, 255); int adr = FFMIN(FFABS(v - psd[j]) >> 1, 255);
v = FFMAX(v, psd[j]) + ff_ac3_log_add_tab[adr]; v = FFMAX(v, psd[j]) + ff_ac3_log_add_tab[adr];
j++; j++;
} }
bndpsd[k]=v; band_psd[k]=v;
k++; k++;
} while (end > bndtab[k]); } while (end > band_start_tab[k]);
} }
void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
int start, int end, int fgain, int is_lfe, int start, int end, int fast_gain, int is_lfe,
int deltbae, int deltnseg, uint8_t *deltoffst, int dba_mode, int dba_nsegs, uint8_t *dba_offsets,
uint8_t *deltlen, uint8_t *deltba, uint8_t *dba_lengths, uint8_t *dba_values,
int16_t *mask) int16_t *mask)
{ {
int16_t excite[50]; /* excitation */ int16_t excite[50]; /* excitation */
...@@ -92,24 +92,24 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, ...@@ -92,24 +92,24 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd,
int lowcomp, fastleak, slowleak; int lowcomp, fastleak, slowleak;
/* excitation function */ /* excitation function */
bndstrt = masktab[start]; bndstrt = bin_to_band_tab[start];
bndend = masktab[end-1] + 1; bndend = bin_to_band_tab[end-1] + 1;
if (bndstrt == 0) { if (bndstrt == 0) {
lowcomp = 0; lowcomp = 0;
lowcomp = calc_lowcomp1(lowcomp, bndpsd[0], bndpsd[1], 384); lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384);
excite[0] = bndpsd[0] - fgain - lowcomp; excite[0] = band_psd[0] - fast_gain - lowcomp;
lowcomp = calc_lowcomp1(lowcomp, bndpsd[1], bndpsd[2], 384); lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384);
excite[1] = bndpsd[1] - fgain - lowcomp; excite[1] = band_psd[1] - fast_gain - lowcomp;
begin = 7; begin = 7;
for (bin = 2; bin < 7; bin++) { for (bin = 2; bin < 7; bin++) {
if (!(is_lfe && bin == 6)) if (!(is_lfe && bin == 6))
lowcomp = calc_lowcomp1(lowcomp, bndpsd[bin], bndpsd[bin+1], 384); lowcomp = calc_lowcomp1(lowcomp, band_psd[bin], band_psd[bin+1], 384);
fastleak = bndpsd[bin] - fgain; fastleak = band_psd[bin] - fast_gain;
slowleak = bndpsd[bin] - s->sgain; slowleak = band_psd[bin] - s->slow_gain;
excite[bin] = fastleak - lowcomp; excite[bin] = fastleak - lowcomp;
if (!(is_lfe && bin == 6)) { if (!(is_lfe && bin == 6)) {
if (bndpsd[bin] <= bndpsd[bin+1]) { if (band_psd[bin] <= band_psd[bin+1]) {
begin = bin + 1; begin = bin + 1;
break; break;
} }
...@@ -121,10 +121,10 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, ...@@ -121,10 +121,10 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd,
for (bin = begin; bin < end1; bin++) { for (bin = begin; bin < end1; bin++) {
if (!(is_lfe && bin == 6)) if (!(is_lfe && bin == 6))
lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin); lowcomp = calc_lowcomp(lowcomp, band_psd[bin], band_psd[bin+1], bin);
fastleak = FFMAX(fastleak - s->fdecay, bndpsd[bin] - fgain); fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);
slowleak = FFMAX(slowleak - s->sdecay, bndpsd[bin] - s->sgain); slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);
excite[bin] = FFMAX(fastleak - lowcomp, slowleak); excite[bin] = FFMAX(fastleak - lowcomp, slowleak);
} }
begin = 22; begin = 22;
...@@ -132,39 +132,39 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, ...@@ -132,39 +132,39 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd,
/* coupling channel */ /* coupling channel */
begin = bndstrt; begin = bndstrt;
fastleak = (s->cplfleak << 8) + 768; fastleak = (s->cpl_fast_leak << 8) + 768;
slowleak = (s->cplsleak << 8) + 768; slowleak = (s->cpl_slow_leak << 8) + 768;
} }
for (bin = begin; bin < bndend; bin++) { for (bin = begin; bin < bndend; bin++) {
fastleak = FFMAX(fastleak - s->fdecay, bndpsd[bin] - fgain); fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);
slowleak = FFMAX(slowleak - s->sdecay, bndpsd[bin] - s->sgain); slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);
excite[bin] = FFMAX(fastleak, slowleak); excite[bin] = FFMAX(fastleak, slowleak);
} }
/* compute masking curve */ /* compute masking curve */
for (bin = bndstrt; bin < bndend; bin++) { for (bin = bndstrt; bin < bndend; bin++) {
tmp = s->dbknee - bndpsd[bin]; tmp = s->db_per_bit - band_psd[bin];
if (tmp > 0) { if (tmp > 0) {
excite[bin] += tmp >> 2; excite[bin] += tmp >> 2;
} }
mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->halfratecod][s->fscod], excite[bin]); mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->sr_shift][s->sr_code], excite[bin]);
} }
/* delta bit allocation */ /* delta bit allocation */
if (deltbae == DBA_REUSE || deltbae == DBA_NEW) { if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {
int band, seg, delta; int band, seg, delta;
band = 0; band = 0;
for (seg = 0; seg < deltnseg; seg++) { for (seg = 0; seg < dba_nsegs; seg++) {
band += deltoffst[seg]; band += dba_offsets[seg];
if (deltba[seg] >= 4) { if (dba_values[seg] >= 4) {
delta = (deltba[seg] - 3) << 7; delta = (dba_values[seg] - 3) << 7;
} else { } else {
delta = (deltba[seg] - 4) << 7; delta = (dba_values[seg] - 4) << 7;
} }
for (k = 0; k < deltlen[seg]; k++) { for (k = 0; k < dba_lengths[seg]; k++) {
mask[band] += delta; mask[band] += delta;
band++; band++;
} }
...@@ -173,49 +173,49 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, ...@@ -173,49 +173,49 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd,
} }
void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
int snroffset, int floor, uint8_t *bap) int snr_offset, int floor, uint8_t *bap)
{ {
int i, j, k, end1, v, address; int i, j, k, end1, v, address;
/* special case, if snroffset is -960, set all bap's to zero */ /* special case, if snr offset is -960, set all bap's to zero */
if(snroffset == -960) { if(snr_offset == -960) {
memset(bap, 0, 256); memset(bap, 0, 256);
return; return;
} }
i = start; i = start;
j = masktab[start]; j = bin_to_band_tab[start];
do { do {
v = (FFMAX(mask[j] - snroffset - floor, 0) & 0x1FE0) + floor; v = (FFMAX(mask[j] - snr_offset - floor, 0) & 0x1FE0) + floor;
end1 = FFMIN(bndtab[j] + ff_ac3_critical_band_size_tab[j], end); end1 = FFMIN(band_start_tab[j] + ff_ac3_critical_band_size_tab[j], end);
for (k = i; k < end1; k++) { for (k = i; k < end1; k++) {
address = av_clip((psd[i] - v) >> 5, 0, 63); address = av_clip((psd[i] - v) >> 5, 0, 63);
bap[i] = ff_ac3_bap_tab[address]; bap[i] = ff_ac3_bap_tab[address];
i++; i++;
} }
} while (end > bndtab[j++]); } while (end > band_start_tab[j++]);
} }
/* AC3 bit allocation. The algorithm is the one described in the AC3 /* AC3 bit allocation. The algorithm is the one described in the AC3
spec. */ spec. */
void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
int8_t *exp, int start, int end, int8_t *exp, int start, int end,
int snroffset, int fgain, int is_lfe, int snr_offset, int fast_gain, int is_lfe,
int deltbae,int deltnseg, int dba_mode, int dba_nsegs,
uint8_t *deltoffst, uint8_t *deltlen, uint8_t *dba_offsets, uint8_t *dba_lengths,
uint8_t *deltba) uint8_t *dba_values)
{ {
int16_t psd[256]; /* scaled exponents */ int16_t psd[256]; /* scaled exponents */
int16_t bndpsd[50]; /* interpolated exponents */ int16_t band_psd[50]; /* interpolated exponents */
int16_t mask[50]; /* masking value */ int16_t mask[50]; /* masking value */
ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, bndpsd); ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd);
ff_ac3_bit_alloc_calc_mask(s, bndpsd, start, end, fgain, is_lfe, ff_ac3_bit_alloc_calc_mask(s, band_psd, start, end, fast_gain, is_lfe,
deltbae, deltnseg, deltoffst, deltlen, deltba, dba_mode, dba_nsegs, dba_offsets, dba_lengths, dba_values,
mask); mask);
ff_ac3_bit_alloc_calc_bap(mask, psd, start, end, snroffset, s->floor, bap); ff_ac3_bit_alloc_calc_bap(mask, psd, start, end, snr_offset, s->floor, bap);
} }
/** /**
...@@ -230,10 +230,10 @@ void ac3_common_init(void) ...@@ -230,10 +230,10 @@ void ac3_common_init(void)
k = 0; k = 0;
l = 0; l = 0;
for(i=0;i<50;i++) { for(i=0;i<50;i++) {
bndtab[i] = l; band_start_tab[i] = l;
v = ff_ac3_critical_band_size_tab[i]; v = ff_ac3_critical_band_size_tab[i];
for(j=0;j<v;j++) masktab[k++]=i; for(j=0;j<v;j++) bin_to_band_tab[k++]=i;
l += v; l += v;
} }
bndtab[50] = l; band_start_tab[50] = l;
} }
...@@ -64,10 +64,10 @@ typedef enum { ...@@ -64,10 +64,10 @@ typedef enum {
} AC3ChannelMode; } AC3ChannelMode;
typedef struct AC3BitAllocParameters { typedef struct AC3BitAllocParameters {
int fscod; /* frequency */ int sr_code;
int halfratecod; int sr_shift;
int sgain, sdecay, fdecay, dbknee, floor; int slow_gain, slow_decay, fast_decay, db_per_bit, floor;
int cplfleak, cplsleak; int cpl_fast_leak, cpl_slow_leak;
} AC3BitAllocParameters; } AC3BitAllocParameters;
/** /**
...@@ -80,7 +80,7 @@ typedef struct { ...@@ -80,7 +80,7 @@ typedef struct {
*/ */
uint16_t sync_word; uint16_t sync_word;
uint16_t crc1; uint16_t crc1;
uint8_t fscod; uint8_t sr_code;
uint8_t frmsizecod; uint8_t frmsizecod;
uint8_t bsid; uint8_t bsid;
uint8_t bsmod; uint8_t bsmod;
...@@ -94,7 +94,7 @@ typedef struct { ...@@ -94,7 +94,7 @@ typedef struct {
/** @defgroup derived Derived values /** @defgroup derived Derived values
* @{ * @{
*/ */
uint8_t halfratecod; uint8_t sr_shift;
uint16_t sample_rate; uint16_t sample_rate;
uint32_t bit_rate; uint32_t bit_rate;
uint8_t channels; uint8_t channels;
...@@ -117,10 +117,10 @@ void ac3_common_init(void); ...@@ -117,10 +117,10 @@ void ac3_common_init(void);
* @param[in] start starting bin location * @param[in] start starting bin location
* @param[in] end ending bin location * @param[in] end ending bin location
* @param[out] psd signal power for each frequency bin * @param[out] psd signal power for each frequency bin
* @param[out] bndpsd signal power for each critical band * @param[out] band_psd signal power for each critical band
*/ */
void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
int16_t *bndpsd); int16_t *band_psd);
/** /**
* Calculates the masking curve. * Calculates the masking curve.
...@@ -131,22 +131,22 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, ...@@ -131,22 +131,22 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd,
* curve, usually to give a closer match to a better psychoacoustic model. * curve, usually to give a closer match to a better psychoacoustic model.
* *
* @param[in] s adjustable bit allocation parameters * @param[in] s adjustable bit allocation parameters
* @param[in] bndpsd signal power for each critical band * @param[in] band_psd signal power for each critical band
* @param[in] start starting bin location * @param[in] start starting bin location
* @param[in] end ending bin location * @param[in] end ending bin location
* @param[in] fgain fast gain (estimated signal-to-mask ratio) * @param[in] fast_gain fast gain (estimated signal-to-mask ratio)
* @param[in] is_lfe whether or not the channel being processed is the LFE * @param[in] is_lfe whether or not the channel being processed is the LFE
* @param[in] deltbae delta bit allocation exists (none, reuse, or new) * @param[in] dba_mode delta bit allocation mode (none, reuse, or new)
* @param[in] deltnseg number of delta segments * @param[in] dba_nsegs number of delta segments
* @param[in] deltoffst location offsets for each segment * @param[in] dba_offsets location offsets for each segment
* @param[in] deltlen length of each segment * @param[in] dba_lengths length of each segment
* @param[in] deltba delta bit allocation for each segment * @param[in] dba_values delta bit allocation for each segment
* @param[out] mask calculated masking curve * @param[out] mask calculated masking curve
*/ */
void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
int start, int end, int fgain, int is_lfe, int start, int end, int fast_gain, int is_lfe,
int deltbae, int deltnseg, uint8_t *deltoffst, int dba_mode, int dba_nsegs, uint8_t *dba_offsets,
uint8_t *deltlen, uint8_t *deltba, uint8_t *dba_lengths, uint8_t *dba_values,
int16_t *mask); int16_t *mask);
/** /**
...@@ -159,17 +159,18 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, ...@@ -159,17 +159,18 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd,
* @param[in] psd signal power for each frequency bin * @param[in] psd signal power for each frequency bin
* @param[in] start starting bin location * @param[in] start starting bin location
* @param[in] end ending bin location * @param[in] end ending bin location
* @param[in] snroffset SNR adjustment * @param[in] snr_offset SNR adjustment
* @param[in] floor noise floor * @param[in] floor noise floor
* @param[out] bap bit allocation pointers * @param[out] bap bit allocation pointers
*/ */
void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end,
int snroffset, int floor, uint8_t *bap); int snr_offset, int floor, uint8_t *bap);
void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
int8_t *exp, int start, int end, int8_t *exp, int start, int end,
int snroffset, int fgain, int is_lfe, int snr_offset, int fast_gain, int is_lfe,
int deltbae,int deltnseg, int dba_mode, int dba_nsegs,
uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba); uint8_t *dba_offsets, uint8_t *dba_lengths,
uint8_t *dba_values);
#endif /* FFMPEG_AC3_H */ #endif /* FFMPEG_AC3_H */
...@@ -52,8 +52,8 @@ int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr) ...@@ -52,8 +52,8 @@ int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr)
return AC3_PARSE_ERROR_BSID; return AC3_PARSE_ERROR_BSID;
hdr->crc1 = get_bits(&gbc, 16); hdr->crc1 = get_bits(&gbc, 16);
hdr->fscod = get_bits(&gbc, 2); hdr->sr_code = get_bits(&gbc, 2);
if(hdr->fscod == 3) if(hdr->sr_code == 3)
return AC3_PARSE_ERROR_SAMPLE_RATE; return AC3_PARSE_ERROR_SAMPLE_RATE;
hdr->frmsizecod = get_bits(&gbc, 6); hdr->frmsizecod = get_bits(&gbc, 6);
...@@ -75,11 +75,11 @@ int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr) ...@@ -75,11 +75,11 @@ int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr)
} }
hdr->lfeon = get_bits1(&gbc); hdr->lfeon = get_bits1(&gbc);
hdr->halfratecod = FFMAX(hdr->bsid, 8) - 8; hdr->sr_shift = FFMAX(hdr->bsid, 8) - 8;
hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->fscod] >> hdr->halfratecod; hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >> hdr->sr_shift;
hdr->bit_rate = (ff_ac3_bitrate_tab[hdr->frmsizecod>>1] * 1000) >> hdr->halfratecod; hdr->bit_rate = (ff_ac3_bitrate_tab[hdr->frmsizecod>>1] * 1000) >> hdr->sr_shift;
hdr->channels = ff_ac3_channels_tab[hdr->acmod] + hdr->lfeon; hdr->channels = ff_ac3_channels_tab[hdr->acmod] + hdr->lfeon;
hdr->frame_size = ff_ac3_frame_size_tab[hdr->frmsizecod][hdr->fscod] * 2; hdr->frame_size = ff_ac3_frame_size_tab[hdr->frmsizecod][hdr->sr_code] * 2;
return 0; return 0;
} }
...@@ -88,8 +88,8 @@ static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, ...@@ -88,8 +88,8 @@ static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
int *bit_rate, int *samples) int *bit_rate, int *samples)
{ {
int err; int err;
unsigned int fscod, acmod, bsid, lfeon; unsigned int sr_code, acmod, bsid, lfeon;
unsigned int strmtyp, substreamid, frmsiz, fscod2, numblkscod; unsigned int strmtyp, substreamid, frmsiz, sr_code2, numblkscod;
GetBitContext bits; GetBitContext bits;
AC3HeaderInfo hdr; AC3HeaderInfo hdr;
...@@ -117,19 +117,19 @@ static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, ...@@ -117,19 +117,19 @@ static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
if(frmsiz*2 < AC3_HEADER_SIZE) if(frmsiz*2 < AC3_HEADER_SIZE)
return 0; return 0;
fscod = get_bits(&bits, 2); sr_code = get_bits(&bits, 2);
if (fscod == 3) { if (sr_code == 3) {
fscod2 = get_bits(&bits, 2); sr_code2 = get_bits(&bits, 2);
numblkscod = 3; numblkscod = 3;
if(fscod2 == 3) if(sr_code2 == 3)
return 0; return 0;
*sample_rate = ff_ac3_sample_rate_tab[fscod2] / 2; *sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2;
} else { } else {
numblkscod = get_bits(&bits, 2); numblkscod = get_bits(&bits, 2);
*sample_rate = ff_ac3_sample_rate_tab[fscod]; *sample_rate = ff_ac3_sample_rate_tab[sr_code];
} }
acmod = get_bits(&bits, 3); acmod = get_bits(&bits, 3);
......
...@@ -141,13 +141,13 @@ typedef struct { ...@@ -141,13 +141,13 @@ typedef struct {
int nrematbnd; ///< number of rematrixing bands int nrematbnd; ///< number of rematrixing bands
int rematflg[4]; ///< rematrixing flags int rematflg[4]; ///< rematrixing flags
int expstr[AC3_MAX_CHANNELS]; ///< exponent strategies int expstr[AC3_MAX_CHANNELS]; ///< exponent strategies
int snroffst[AC3_MAX_CHANNELS]; ///< signal-to-noise ratio offsets int snr_offset[AC3_MAX_CHANNELS]; ///< signal-to-noise ratio offsets
int fgain[AC3_MAX_CHANNELS]; ///< fast gain values (signal-to-mask ratio) int fast_gain[AC3_MAX_CHANNELS]; ///< fast gain values (signal-to-mask ratio)
int deltbae[AC3_MAX_CHANNELS]; ///< delta bit allocation exists int dba_mode[AC3_MAX_CHANNELS]; ///< delta bit allocation mode
int deltnseg[AC3_MAX_CHANNELS]; ///< number of delta segments int dba_nsegs[AC3_MAX_CHANNELS]; ///< number of delta segments
uint8_t deltoffst[AC3_MAX_CHANNELS][8]; ///< delta segment offsets uint8_t dba_offsets[AC3_MAX_CHANNELS][8]; ///< delta segment offsets
uint8_t deltlen[AC3_MAX_CHANNELS][8]; ///< delta segment lengths uint8_t dba_lengths[AC3_MAX_CHANNELS][8]; ///< delta segment lengths
uint8_t deltba[AC3_MAX_CHANNELS][8]; ///< delta values for each segment uint8_t dba_values[AC3_MAX_CHANNELS][8]; ///< delta values for each segment
int sampling_rate; ///< sample frequency, in Hz int sampling_rate; ///< sample frequency, in Hz
int bit_rate; ///< stream bit rate, in bits-per-second int bit_rate; ///< stream bit rate, in bits-per-second
...@@ -173,7 +173,7 @@ typedef struct { ...@@ -173,7 +173,7 @@ typedef struct {
int8_t dexps[AC3_MAX_CHANNELS][256]; ///< decoded exponents int8_t dexps[AC3_MAX_CHANNELS][256]; ///< decoded exponents
uint8_t bap[AC3_MAX_CHANNELS][256]; ///< bit allocation pointers uint8_t bap[AC3_MAX_CHANNELS][256]; ///< bit allocation pointers
int16_t psd[AC3_MAX_CHANNELS][256]; ///< scaled exponents int16_t psd[AC3_MAX_CHANNELS][256]; ///< scaled exponents
int16_t bndpsd[AC3_MAX_CHANNELS][50]; ///< interpolated exponents int16_t band_psd[AC3_MAX_CHANNELS][50]; ///< interpolated exponents
int16_t mask[AC3_MAX_CHANNELS][50]; ///< masking curve values int16_t mask[AC3_MAX_CHANNELS][50]; ///< masking curve values
DECLARE_ALIGNED_16(float, transform_coeffs[AC3_MAX_CHANNELS][256]); ///< transform coefficients DECLARE_ALIGNED_16(float, transform_coeffs[AC3_MAX_CHANNELS][256]); ///< transform coefficients
...@@ -344,13 +344,13 @@ static int ac3_parse_header(AC3DecodeContext *ctx) ...@@ -344,13 +344,13 @@ static int ac3_parse_header(AC3DecodeContext *ctx)
return err; return err;
/* get decoding parameters from header info */ /* get decoding parameters from header info */
ctx->bit_alloc_params.fscod = hdr.fscod; ctx->bit_alloc_params.sr_code = hdr.sr_code;
ctx->acmod = hdr.acmod; ctx->acmod = hdr.acmod;
cmixlev = gain_levels[clevs[hdr.cmixlev]]; cmixlev = gain_levels[clevs[hdr.cmixlev]];
surmixlev = gain_levels[slevs[hdr.surmixlev]]; surmixlev = gain_levels[slevs[hdr.surmixlev]];
ctx->dsurmod = hdr.dsurmod; ctx->dsurmod = hdr.dsurmod;
ctx->lfeon = hdr.lfeon; ctx->lfeon = hdr.lfeon;
ctx->bit_alloc_params.halfratecod = hdr.halfratecod; ctx->bit_alloc_params.sr_shift = hdr.sr_shift;
ctx->sampling_rate = hdr.sample_rate; ctx->sampling_rate = hdr.sample_rate;
ctx->bit_rate = hdr.bit_rate; ctx->bit_rate = hdr.bit_rate;
ctx->nchans = hdr.channels; ctx->nchans = hdr.channels;
...@@ -947,10 +947,10 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) ...@@ -947,10 +947,10 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk)
/* bit allocation information */ /* bit allocation information */
if (get_bits1(gb)) { if (get_bits1(gb)) {
ctx->bit_alloc_params.sdecay = ff_ac3_slow_decay_tab[get_bits(gb, 2)] >> ctx->bit_alloc_params.halfratecod; ctx->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gb, 2)] >> ctx->bit_alloc_params.sr_shift;
ctx->bit_alloc_params.fdecay = ff_ac3_fast_decay_tab[get_bits(gb, 2)] >> ctx->bit_alloc_params.halfratecod; ctx->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gb, 2)] >> ctx->bit_alloc_params.sr_shift;
ctx->bit_alloc_params.sgain = ff_ac3_slow_gain_tab[get_bits(gb, 2)]; ctx->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gb, 2)];
ctx->bit_alloc_params.dbknee = ff_ac3_db_per_bit_tab[get_bits(gb, 2)]; ctx->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gb, 2)];
ctx->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gb, 3)]; ctx->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gb, 3)];
for(ch=!ctx->cplinu; ch<=ctx->nchans; ch++) { for(ch=!ctx->cplinu; ch<=ctx->nchans; ch++) {
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
...@@ -962,16 +962,16 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) ...@@ -962,16 +962,16 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk)
int csnr; int csnr;
csnr = (get_bits(gb, 6) - 15) << 4; csnr = (get_bits(gb, 6) - 15) << 4;
for (ch = !ctx->cplinu; ch <= ctx->nchans; ch++) { /* snr offset and fast gain */ for (ch = !ctx->cplinu; ch <= ctx->nchans; ch++) { /* snr offset and fast gain */
ctx->snroffst[ch] = (csnr + get_bits(gb, 4)) << 2; ctx->snr_offset[ch] = (csnr + get_bits(gb, 4)) << 2;
ctx->fgain[ch] = ff_ac3_fast_gain_tab[get_bits(gb, 3)]; ctx->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gb, 3)];
} }
memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS);
} }
/* coupling leak information */ /* coupling leak information */
if (ctx->cplinu && get_bits1(gb)) { if (ctx->cplinu && get_bits1(gb)) {
ctx->bit_alloc_params.cplfleak = get_bits(gb, 3); ctx->bit_alloc_params.cpl_fast_leak = get_bits(gb, 3);
ctx->bit_alloc_params.cplsleak = get_bits(gb, 3); ctx->bit_alloc_params.cpl_slow_leak = get_bits(gb, 3);
bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2);
} }
...@@ -979,8 +979,8 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) ...@@ -979,8 +979,8 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk)
if (get_bits1(gb)) { if (get_bits1(gb)) {
/* delta bit allocation exists (strategy) */ /* delta bit allocation exists (strategy) */
for (ch = !ctx->cplinu; ch <= nfchans; ch++) { for (ch = !ctx->cplinu; ch <= nfchans; ch++) {
ctx->deltbae[ch] = get_bits(gb, 2); ctx->dba_mode[ch] = get_bits(gb, 2);
if (ctx->deltbae[ch] == DBA_RESERVED) { if (ctx->dba_mode[ch] == DBA_RESERVED) {
av_log(ctx->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); av_log(ctx->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n");
return -1; return -1;
} }
...@@ -988,18 +988,18 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) ...@@ -988,18 +988,18 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk)
} }
/* channel delta offset, len and bit allocation */ /* channel delta offset, len and bit allocation */
for (ch = !ctx->cplinu; ch <= nfchans; ch++) { for (ch = !ctx->cplinu; ch <= nfchans; ch++) {
if (ctx->deltbae[ch] == DBA_NEW) { if (ctx->dba_mode[ch] == DBA_NEW) {
ctx->deltnseg[ch] = get_bits(gb, 3); ctx->dba_nsegs[ch] = get_bits(gb, 3);
for (seg = 0; seg <= ctx->deltnseg[ch]; seg++) { for (seg = 0; seg <= ctx->dba_nsegs[ch]; seg++) {
ctx->deltoffst[ch][seg] = get_bits(gb, 5); ctx->dba_offsets[ch][seg] = get_bits(gb, 5);
ctx->deltlen[ch][seg] = get_bits(gb, 4); ctx->dba_lengths[ch][seg] = get_bits(gb, 4);
ctx->deltba[ch][seg] = get_bits(gb, 3); ctx->dba_values[ch][seg] = get_bits(gb, 3);
} }
} }
} }
} else if(blk == 0) { } else if(blk == 0) {
for(ch=0; ch<=ctx->nchans; ch++) { for(ch=0; ch<=ctx->nchans; ch++) {
ctx->deltbae[ch] = DBA_NONE; ctx->dba_mode[ch] = DBA_NONE;
} }
} }
...@@ -1009,23 +1009,23 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk) ...@@ -1009,23 +1009,23 @@ static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk)
/* Exponent mapping into PSD and PSD integration */ /* Exponent mapping into PSD and PSD integration */
ff_ac3_bit_alloc_calc_psd(ctx->dexps[ch], ff_ac3_bit_alloc_calc_psd(ctx->dexps[ch],
ctx->startmant[ch], ctx->endmant[ch], ctx->startmant[ch], ctx->endmant[ch],
ctx->psd[ch], ctx->bndpsd[ch]); ctx->psd[ch], ctx->band_psd[ch]);
} }
if(bit_alloc_stages[ch] > 1) { if(bit_alloc_stages[ch] > 1) {
/* Compute excitation function, Compute masking curve, and /* Compute excitation function, Compute masking curve, and
Apply delta bit allocation */ Apply delta bit allocation */
ff_ac3_bit_alloc_calc_mask(&ctx->bit_alloc_params, ctx->bndpsd[ch], ff_ac3_bit_alloc_calc_mask(&ctx->bit_alloc_params, ctx->band_psd[ch],
ctx->startmant[ch], ctx->endmant[ch], ctx->startmant[ch], ctx->endmant[ch],
ctx->fgain[ch], (ch == ctx->lfe_ch), ctx->fast_gain[ch], (ch == ctx->lfe_ch),
ctx->deltbae[ch], ctx->deltnseg[ch], ctx->dba_mode[ch], ctx->dba_nsegs[ch],
ctx->deltoffst[ch], ctx->deltlen[ch], ctx->dba_offsets[ch], ctx->dba_lengths[ch],
ctx->deltba[ch], ctx->mask[ch]); ctx->dba_values[ch], ctx->mask[ch]);
} }
if(bit_alloc_stages[ch] > 0) { if(bit_alloc_stages[ch] > 0) {
/* Compute bit allocation */ /* Compute bit allocation */
ff_ac3_bit_alloc_calc_bap(ctx->mask[ch], ctx->psd[ch], ff_ac3_bit_alloc_calc_bap(ctx->mask[ch], ctx->psd[ch],
ctx->startmant[ch], ctx->endmant[ch], ctx->startmant[ch], ctx->endmant[ch],
ctx->snroffst[ch], ctx->snr_offset[ch],
ctx->bit_alloc_params.floor, ctx->bit_alloc_params.floor,
ctx->bap[ch]); ctx->bap[ch]);
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment