mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
cosmetics: rename ac3 bit allocation variables
Originally committed as revision 11194 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
66ecf18e38
commit
5ce2134258
112
libavcodec/ac3.c
112
libavcodec/ac3.c
@ -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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|||||||
|
|
||||||
/* 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,
|
|||||||
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,
|
|||||||
|
|
||||||
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,
|
|||||||
/* 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,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|||||||
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 {
|
|||||||
} 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 {
|
|||||||
*/
|
*/
|
||||||
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 {
|
|||||||
/** @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);
|
|||||||
* @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,
|
|||||||
* 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,
|
|||||||
* @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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
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,
|
|||||||
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,
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
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)
|
|||||||
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)
|
|||||||
|
|
||||||
/* 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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
/* 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)
|
|||||||
/* 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]);
|
||||||
}
|
}
|
||||||
|
@ -42,9 +42,9 @@ typedef struct AC3EncodeContext {
|
|||||||
unsigned int frame_size; /* current frame size in words */
|
unsigned int frame_size; /* current frame size in words */
|
||||||
unsigned int bits_written;
|
unsigned int bits_written;
|
||||||
unsigned int samples_written;
|
unsigned int samples_written;
|
||||||
int halfratecod;
|
int sr_shift;
|
||||||
unsigned int frmsizecod;
|
unsigned int frmsizecod;
|
||||||
unsigned int fscod; /* frequency */
|
unsigned int sr_code; /* frequency */
|
||||||
unsigned int acmod;
|
unsigned int acmod;
|
||||||
int lfe;
|
int lfe;
|
||||||
unsigned int bsmod;
|
unsigned int bsmod;
|
||||||
@ -53,11 +53,11 @@ typedef struct AC3EncodeContext {
|
|||||||
int nb_coefs[AC3_MAX_CHANNELS];
|
int nb_coefs[AC3_MAX_CHANNELS];
|
||||||
|
|
||||||
/* bitrate allocation control */
|
/* bitrate allocation control */
|
||||||
int sgaincod, sdecaycod, fdecaycod, dbkneecod, floorcod;
|
int slow_gain_code, slow_decay_code, fast_decay_code, db_per_bit_code, floor_code;
|
||||||
AC3BitAllocParameters bit_alloc;
|
AC3BitAllocParameters bit_alloc;
|
||||||
int csnroffst;
|
int coarse_snr_offset;
|
||||||
int fgaincod[AC3_MAX_CHANNELS];
|
int fast_gain_code[AC3_MAX_CHANNELS];
|
||||||
int fsnroffst[AC3_MAX_CHANNELS];
|
int fine_snr_offset[AC3_MAX_CHANNELS];
|
||||||
/* mantissa encoding */
|
/* mantissa encoding */
|
||||||
int mant1_cnt, mant2_cnt, mant4_cnt;
|
int mant1_cnt, mant2_cnt, mant4_cnt;
|
||||||
} AC3EncodeContext;
|
} AC3EncodeContext;
|
||||||
@ -438,7 +438,7 @@ static void bit_alloc_masking(AC3EncodeContext *s,
|
|||||||
int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50])
|
int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50])
|
||||||
{
|
{
|
||||||
int blk, ch;
|
int blk, ch;
|
||||||
int16_t bndpsd[NB_BLOCKS][AC3_MAX_CHANNELS][50];
|
int16_t band_psd[NB_BLOCKS][AC3_MAX_CHANNELS][50];
|
||||||
|
|
||||||
for(blk=0; blk<NB_BLOCKS; blk++) {
|
for(blk=0; blk<NB_BLOCKS; blk++) {
|
||||||
for(ch=0;ch<s->nb_all_channels;ch++) {
|
for(ch=0;ch<s->nb_all_channels;ch++) {
|
||||||
@ -448,10 +448,10 @@ static void bit_alloc_masking(AC3EncodeContext *s,
|
|||||||
} else {
|
} else {
|
||||||
ff_ac3_bit_alloc_calc_psd(encoded_exp[blk][ch], 0,
|
ff_ac3_bit_alloc_calc_psd(encoded_exp[blk][ch], 0,
|
||||||
s->nb_coefs[ch],
|
s->nb_coefs[ch],
|
||||||
psd[blk][ch], bndpsd[blk][ch]);
|
psd[blk][ch], band_psd[blk][ch]);
|
||||||
ff_ac3_bit_alloc_calc_mask(&s->bit_alloc, bndpsd[blk][ch],
|
ff_ac3_bit_alloc_calc_mask(&s->bit_alloc, band_psd[blk][ch],
|
||||||
0, s->nb_coefs[ch],
|
0, s->nb_coefs[ch],
|
||||||
ff_ac3_fast_gain_tab[s->fgaincod[ch]],
|
ff_ac3_fast_gain_tab[s->fast_gain_code[ch]],
|
||||||
ch == s->lfe_channel,
|
ch == s->lfe_channel,
|
||||||
DBA_NONE, 0, NULL, NULL, NULL,
|
DBA_NONE, 0, NULL, NULL, NULL,
|
||||||
mask[blk][ch]);
|
mask[blk][ch]);
|
||||||
@ -464,12 +464,12 @@ static int bit_alloc(AC3EncodeContext *s,
|
|||||||
int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50],
|
int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50],
|
||||||
int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
|
int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
|
||||||
uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
|
uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
|
||||||
int frame_bits, int csnroffst, int fsnroffst)
|
int frame_bits, int coarse_snr_offset, int fine_snr_offset)
|
||||||
{
|
{
|
||||||
int i, ch;
|
int i, ch;
|
||||||
int snroffset;
|
int snr_offset;
|
||||||
|
|
||||||
snroffset = (((csnroffst - 15) << 4) + fsnroffst) << 2;
|
snr_offset = (((coarse_snr_offset - 15) << 4) + fine_snr_offset) << 2;
|
||||||
|
|
||||||
/* compute size */
|
/* compute size */
|
||||||
for(i=0;i<NB_BLOCKS;i++) {
|
for(i=0;i<NB_BLOCKS;i++) {
|
||||||
@ -478,7 +478,7 @@ static int bit_alloc(AC3EncodeContext *s,
|
|||||||
s->mant4_cnt = 0;
|
s->mant4_cnt = 0;
|
||||||
for(ch=0;ch<s->nb_all_channels;ch++) {
|
for(ch=0;ch<s->nb_all_channels;ch++) {
|
||||||
ff_ac3_bit_alloc_calc_bap(mask[i][ch], psd[i][ch], 0,
|
ff_ac3_bit_alloc_calc_bap(mask[i][ch], psd[i][ch], 0,
|
||||||
s->nb_coefs[ch], snroffset,
|
s->nb_coefs[ch], snr_offset,
|
||||||
s->bit_alloc.floor, bap[i][ch]);
|
s->bit_alloc.floor, bap[i][ch]);
|
||||||
frame_bits += compute_mantissa_size(s, bap[i][ch],
|
frame_bits += compute_mantissa_size(s, bap[i][ch],
|
||||||
s->nb_coefs[ch]);
|
s->nb_coefs[ch]);
|
||||||
@ -486,7 +486,7 @@ static int bit_alloc(AC3EncodeContext *s,
|
|||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
printf("csnr=%d fsnr=%d frame_bits=%d diff=%d\n",
|
printf("csnr=%d fsnr=%d frame_bits=%d diff=%d\n",
|
||||||
csnroffst, fsnroffst, frame_bits,
|
coarse_snr_offset, fine_snr_offset, frame_bits,
|
||||||
16 * s->frame_size - ((frame_bits + 7) & ~7));
|
16 * s->frame_size - ((frame_bits + 7) & ~7));
|
||||||
#endif
|
#endif
|
||||||
return 16 * s->frame_size - frame_bits;
|
return 16 * s->frame_size - frame_bits;
|
||||||
@ -501,29 +501,29 @@ static int compute_bit_allocation(AC3EncodeContext *s,
|
|||||||
int frame_bits)
|
int frame_bits)
|
||||||
{
|
{
|
||||||
int i, ch;
|
int i, ch;
|
||||||
int csnroffst, fsnroffst;
|
int coarse_snr_offset, fine_snr_offset;
|
||||||
uint8_t bap1[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
|
uint8_t bap1[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
|
||||||
int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
|
int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
|
||||||
int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50];
|
int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50];
|
||||||
static int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
|
static int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
|
||||||
|
|
||||||
/* init default parameters */
|
/* init default parameters */
|
||||||
s->sdecaycod = 2;
|
s->slow_decay_code = 2;
|
||||||
s->fdecaycod = 1;
|
s->fast_decay_code = 1;
|
||||||
s->sgaincod = 1;
|
s->slow_gain_code = 1;
|
||||||
s->dbkneecod = 2;
|
s->db_per_bit_code = 2;
|
||||||
s->floorcod = 4;
|
s->floor_code = 4;
|
||||||
for(ch=0;ch<s->nb_all_channels;ch++)
|
for(ch=0;ch<s->nb_all_channels;ch++)
|
||||||
s->fgaincod[ch] = 4;
|
s->fast_gain_code[ch] = 4;
|
||||||
|
|
||||||
/* compute real values */
|
/* compute real values */
|
||||||
s->bit_alloc.fscod = s->fscod;
|
s->bit_alloc.sr_code = s->sr_code;
|
||||||
s->bit_alloc.halfratecod = s->halfratecod;
|
s->bit_alloc.sr_shift = s->sr_shift;
|
||||||
s->bit_alloc.sdecay = ff_ac3_slow_decay_tab[s->sdecaycod] >> s->halfratecod;
|
s->bit_alloc.slow_decay = ff_ac3_slow_decay_tab[s->slow_decay_code] >> s->sr_shift;
|
||||||
s->bit_alloc.fdecay = ff_ac3_fast_decay_tab[s->fdecaycod] >> s->halfratecod;
|
s->bit_alloc.fast_decay = ff_ac3_fast_decay_tab[s->fast_decay_code] >> s->sr_shift;
|
||||||
s->bit_alloc.sgain = ff_ac3_slow_gain_tab[s->sgaincod];
|
s->bit_alloc.slow_gain = ff_ac3_slow_gain_tab[s->slow_gain_code];
|
||||||
s->bit_alloc.dbknee = ff_ac3_db_per_bit_tab[s->dbkneecod];
|
s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code];
|
||||||
s->bit_alloc.floor = ff_ac3_floor_tab[s->floorcod];
|
s->bit_alloc.floor = ff_ac3_floor_tab[s->floor_code];
|
||||||
|
|
||||||
/* header size */
|
/* header size */
|
||||||
frame_bits += 65;
|
frame_bits += 65;
|
||||||
@ -568,43 +568,43 @@ static int compute_bit_allocation(AC3EncodeContext *s,
|
|||||||
/* now the big work begins : do the bit allocation. Modify the snr
|
/* now the big work begins : do the bit allocation. Modify the snr
|
||||||
offset until we can pack everything in the requested frame size */
|
offset until we can pack everything in the requested frame size */
|
||||||
|
|
||||||
csnroffst = s->csnroffst;
|
coarse_snr_offset = s->coarse_snr_offset;
|
||||||
while (csnroffst >= 0 &&
|
while (coarse_snr_offset >= 0 &&
|
||||||
bit_alloc(s, mask, psd, bap, frame_bits, csnroffst, 0) < 0)
|
bit_alloc(s, mask, psd, bap, frame_bits, coarse_snr_offset, 0) < 0)
|
||||||
csnroffst -= SNR_INC1;
|
coarse_snr_offset -= SNR_INC1;
|
||||||
if (csnroffst < 0) {
|
if (coarse_snr_offset < 0) {
|
||||||
av_log(NULL, AV_LOG_ERROR, "Bit allocation failed, try increasing the bitrate, -ab 384k for example!\n");
|
av_log(NULL, AV_LOG_ERROR, "Bit allocation failed, try increasing the bitrate, -ab 384k for example!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while ((csnroffst + SNR_INC1) <= 63 &&
|
while ((coarse_snr_offset + SNR_INC1) <= 63 &&
|
||||||
bit_alloc(s, mask, psd, bap1, frame_bits,
|
bit_alloc(s, mask, psd, bap1, frame_bits,
|
||||||
csnroffst + SNR_INC1, 0) >= 0) {
|
coarse_snr_offset + SNR_INC1, 0) >= 0) {
|
||||||
csnroffst += SNR_INC1;
|
coarse_snr_offset += SNR_INC1;
|
||||||
memcpy(bap, bap1, sizeof(bap1));
|
memcpy(bap, bap1, sizeof(bap1));
|
||||||
}
|
}
|
||||||
while ((csnroffst + 1) <= 63 &&
|
while ((coarse_snr_offset + 1) <= 63 &&
|
||||||
bit_alloc(s, mask, psd, bap1, frame_bits, csnroffst + 1, 0) >= 0) {
|
bit_alloc(s, mask, psd, bap1, frame_bits, coarse_snr_offset + 1, 0) >= 0) {
|
||||||
csnroffst++;
|
coarse_snr_offset++;
|
||||||
memcpy(bap, bap1, sizeof(bap1));
|
memcpy(bap, bap1, sizeof(bap1));
|
||||||
}
|
}
|
||||||
|
|
||||||
fsnroffst = 0;
|
fine_snr_offset = 0;
|
||||||
while ((fsnroffst + SNR_INC1) <= 15 &&
|
while ((fine_snr_offset + SNR_INC1) <= 15 &&
|
||||||
bit_alloc(s, mask, psd, bap1, frame_bits,
|
bit_alloc(s, mask, psd, bap1, frame_bits,
|
||||||
csnroffst, fsnroffst + SNR_INC1) >= 0) {
|
coarse_snr_offset, fine_snr_offset + SNR_INC1) >= 0) {
|
||||||
fsnroffst += SNR_INC1;
|
fine_snr_offset += SNR_INC1;
|
||||||
memcpy(bap, bap1, sizeof(bap1));
|
memcpy(bap, bap1, sizeof(bap1));
|
||||||
}
|
}
|
||||||
while ((fsnroffst + 1) <= 15 &&
|
while ((fine_snr_offset + 1) <= 15 &&
|
||||||
bit_alloc(s, mask, psd, bap1, frame_bits,
|
bit_alloc(s, mask, psd, bap1, frame_bits,
|
||||||
csnroffst, fsnroffst + 1) >= 0) {
|
coarse_snr_offset, fine_snr_offset + 1) >= 0) {
|
||||||
fsnroffst++;
|
fine_snr_offset++;
|
||||||
memcpy(bap, bap1, sizeof(bap1));
|
memcpy(bap, bap1, sizeof(bap1));
|
||||||
}
|
}
|
||||||
|
|
||||||
s->csnroffst = csnroffst;
|
s->coarse_snr_offset = coarse_snr_offset;
|
||||||
for(ch=0;ch<s->nb_all_channels;ch++)
|
for(ch=0;ch<s->nb_all_channels;ch++)
|
||||||
s->fsnroffst[ch] = fsnroffst;
|
s->fine_snr_offset[ch] = fine_snr_offset;
|
||||||
#if defined(DEBUG_BITALLOC)
|
#if defined(DEBUG_BITALLOC)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
@ -663,22 +663,22 @@ static int AC3_encode_init(AVCodecContext *avctx)
|
|||||||
return -1;
|
return -1;
|
||||||
found:
|
found:
|
||||||
s->sample_rate = freq;
|
s->sample_rate = freq;
|
||||||
s->halfratecod = i;
|
s->sr_shift = i;
|
||||||
s->fscod = j;
|
s->sr_code = j;
|
||||||
s->bsid = 8 + s->halfratecod;
|
s->bsid = 8 + s->sr_shift;
|
||||||
s->bsmod = 0; /* complete main audio service */
|
s->bsmod = 0; /* complete main audio service */
|
||||||
|
|
||||||
/* bitrate & frame size */
|
/* bitrate & frame size */
|
||||||
bitrate /= 1000;
|
bitrate /= 1000;
|
||||||
for(i=0;i<19;i++) {
|
for(i=0;i<19;i++) {
|
||||||
if ((ff_ac3_bitrate_tab[i] >> s->halfratecod) == bitrate)
|
if ((ff_ac3_bitrate_tab[i] >> s->sr_shift) == bitrate)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i == 19)
|
if (i == 19)
|
||||||
return -1;
|
return -1;
|
||||||
s->bit_rate = bitrate;
|
s->bit_rate = bitrate;
|
||||||
s->frmsizecod = i << 1;
|
s->frmsizecod = i << 1;
|
||||||
s->frame_size_min = ff_ac3_frame_size_tab[s->frmsizecod][s->fscod];
|
s->frame_size_min = ff_ac3_frame_size_tab[s->frmsizecod][s->sr_code];
|
||||||
s->bits_written = 0;
|
s->bits_written = 0;
|
||||||
s->samples_written = 0;
|
s->samples_written = 0;
|
||||||
s->frame_size = s->frame_size_min;
|
s->frame_size = s->frame_size_min;
|
||||||
@ -695,7 +695,7 @@ static int AC3_encode_init(AVCodecContext *avctx)
|
|||||||
s->nb_coefs[s->lfe_channel] = 7; /* fixed */
|
s->nb_coefs[s->lfe_channel] = 7; /* fixed */
|
||||||
}
|
}
|
||||||
/* initial snr offset */
|
/* initial snr offset */
|
||||||
s->csnroffst = 40;
|
s->coarse_snr_offset = 40;
|
||||||
|
|
||||||
/* mdct init */
|
/* mdct init */
|
||||||
fft_init(MDCT_NBITS - 2);
|
fft_init(MDCT_NBITS - 2);
|
||||||
@ -718,7 +718,7 @@ static void output_frame_header(AC3EncodeContext *s, unsigned char *frame)
|
|||||||
|
|
||||||
put_bits(&s->pb, 16, 0x0b77); /* frame header */
|
put_bits(&s->pb, 16, 0x0b77); /* frame header */
|
||||||
put_bits(&s->pb, 16, 0); /* crc1: will be filled later */
|
put_bits(&s->pb, 16, 0); /* crc1: will be filled later */
|
||||||
put_bits(&s->pb, 2, s->fscod);
|
put_bits(&s->pb, 2, s->sr_code);
|
||||||
put_bits(&s->pb, 6, s->frmsizecod + (s->frame_size - s->frame_size_min));
|
put_bits(&s->pb, 6, s->frmsizecod + (s->frame_size - s->frame_size_min));
|
||||||
put_bits(&s->pb, 5, s->bsid);
|
put_bits(&s->pb, 5, s->bsid);
|
||||||
put_bits(&s->pb, 3, s->bsmod);
|
put_bits(&s->pb, 3, s->bsmod);
|
||||||
@ -900,20 +900,20 @@ static void output_audio_block(AC3EncodeContext *s,
|
|||||||
baie = (block_num == 0);
|
baie = (block_num == 0);
|
||||||
put_bits(&s->pb, 1, baie);
|
put_bits(&s->pb, 1, baie);
|
||||||
if (baie) {
|
if (baie) {
|
||||||
put_bits(&s->pb, 2, s->sdecaycod);
|
put_bits(&s->pb, 2, s->slow_decay_code);
|
||||||
put_bits(&s->pb, 2, s->fdecaycod);
|
put_bits(&s->pb, 2, s->fast_decay_code);
|
||||||
put_bits(&s->pb, 2, s->sgaincod);
|
put_bits(&s->pb, 2, s->slow_gain_code);
|
||||||
put_bits(&s->pb, 2, s->dbkneecod);
|
put_bits(&s->pb, 2, s->db_per_bit_code);
|
||||||
put_bits(&s->pb, 3, s->floorcod);
|
put_bits(&s->pb, 3, s->floor_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* snr offset */
|
/* snr offset */
|
||||||
put_bits(&s->pb, 1, baie); /* always present with bai */
|
put_bits(&s->pb, 1, baie); /* always present with bai */
|
||||||
if (baie) {
|
if (baie) {
|
||||||
put_bits(&s->pb, 6, s->csnroffst);
|
put_bits(&s->pb, 6, s->coarse_snr_offset);
|
||||||
for(ch=0;ch<s->nb_all_channels;ch++) {
|
for(ch=0;ch<s->nb_all_channels;ch++) {
|
||||||
put_bits(&s->pb, 4, s->fsnroffst[ch]);
|
put_bits(&s->pb, 4, s->fine_snr_offset[ch]);
|
||||||
put_bits(&s->pb, 3, s->fgaincod[ch]);
|
put_bits(&s->pb, 3, s->fast_gain_code[ch]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user