mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
eac3dec: use 16-bit pre-mantissas instead of 24-bit in AHT decoding. it is
simpler and also fixes a bug in GAQ dequantization. Originally committed as revision 18860 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
db2f209352
commit
9a7a71ed4c
@ -568,7 +568,7 @@ static void decode_transform_coeffs_ch(AC3DecodeContext *s, int blk, int ch,
|
|||||||
if (!blk)
|
if (!blk)
|
||||||
ff_eac3_decode_transform_coeffs_aht_ch(s, ch);
|
ff_eac3_decode_transform_coeffs_aht_ch(s, ch);
|
||||||
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
|
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
|
||||||
s->fixed_coeffs[ch][bin] = s->pre_mantissa[ch][bin][blk] >> s->dexps[ch][bin];
|
s->fixed_coeffs[ch][bin] = (s->pre_mantissa[ch][bin][blk] << 8) >> s->dexps[ch][bin];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,19 +87,18 @@ const int16_t ff_eac3_gaq_remap_2_4_a[9][2] = {
|
|||||||
/**
|
/**
|
||||||
* Table E3.6, Gk=2 & Gk=4, B
|
* Table E3.6, Gk=2 & Gk=4, B
|
||||||
* Large mantissa inverse quantization, negative mantissa remapping offsets
|
* Large mantissa inverse quantization, negative mantissa remapping offsets
|
||||||
* Table values from the spec are right-shifted by 8 to simplify calculations.
|
|
||||||
* ff_eac3_gaq_remap_3_4_b[hebap-8][Gk=2,4]
|
* ff_eac3_gaq_remap_3_4_b[hebap-8][Gk=2,4]
|
||||||
*/
|
*/
|
||||||
const int8_t ff_eac3_gaq_remap_2_4_b[9][2] = {
|
const int16_t ff_eac3_gaq_remap_2_4_b[9][2] = {
|
||||||
{ -22, -5 },
|
{ -5461, -1170 },
|
||||||
{ -46, -20 },
|
{ -11703, -4915 },
|
||||||
{ -56, -26 },
|
{ -14199, -6606 },
|
||||||
{ -60, -29 },
|
{ -15327, -7412 },
|
||||||
{ -62, -31 },
|
{ -15864, -7805 },
|
||||||
{ -63, -32 },
|
{ -16126, -7999 },
|
||||||
{ -64, -32 },
|
{ -16255, -8096 },
|
||||||
{ -64, -32 },
|
{ -16320, -8144 },
|
||||||
{ -64, -32 },
|
{ -16352, -8168 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int16_t vq_hebap1[4][6] = {
|
static const int16_t vq_hebap1[4][6] = {
|
||||||
|
@ -29,7 +29,7 @@ extern const uint8_t ff_eac3_hebap_tab[64];
|
|||||||
extern const uint8_t ff_eac3_bits_vs_hebap[20];
|
extern const uint8_t ff_eac3_bits_vs_hebap[20];
|
||||||
extern const int16_t ff_eac3_gaq_remap_1[12];
|
extern const int16_t ff_eac3_gaq_remap_1[12];
|
||||||
extern const int16_t ff_eac3_gaq_remap_2_4_a[9][2];
|
extern const int16_t ff_eac3_gaq_remap_2_4_a[9][2];
|
||||||
extern const int8_t ff_eac3_gaq_remap_2_4_b[9][2];
|
extern const int16_t ff_eac3_gaq_remap_2_4_b[9][2];
|
||||||
|
|
||||||
extern const int16_t (* const ff_eac3_mantissa_vq[8])[6];
|
extern const int16_t (* const ff_eac3_mantissa_vq[8])[6];
|
||||||
extern const uint8_t ff_eac3_frm_expstr[32][6];
|
extern const uint8_t ff_eac3_frm_expstr[32][6];
|
||||||
|
@ -66,18 +66,18 @@ typedef enum {
|
|||||||
|
|
||||||
#define EAC3_SR_CODE_REDUCED 3
|
#define EAC3_SR_CODE_REDUCED 3
|
||||||
|
|
||||||
/** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
|
/** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<15)) */
|
||||||
#define COEFF_0 10273905LL
|
#define COEFF_0 40132
|
||||||
|
|
||||||
/** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
|
/** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<15)) = lrint(M_SQRT2*(1<<15)) */
|
||||||
#define COEFF_1 11863283LL
|
#define COEFF_1 46341
|
||||||
|
|
||||||
/** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
|
/** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<15)) */
|
||||||
#define COEFF_2 3070444LL
|
#define COEFF_2 11994
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate 6-point IDCT of the pre-mantissas.
|
* Calculate 6-point IDCT of the pre-mantissas.
|
||||||
* All calculations are 24-bit fixed-point.
|
* All calculations are 16-bit fixed-point.
|
||||||
*/
|
*/
|
||||||
static void idct6(int pre_mant[6])
|
static void idct6(int pre_mant[6])
|
||||||
{
|
{
|
||||||
@ -86,9 +86,9 @@ static void idct6(int pre_mant[6])
|
|||||||
|
|
||||||
odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
|
odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
|
||||||
|
|
||||||
even2 = ( pre_mant[2] * COEFF_0) >> 23;
|
even2 = ( pre_mant[2] * COEFF_0) >> 15;
|
||||||
tmp = ( pre_mant[4] * COEFF_1) >> 23;
|
tmp = ( pre_mant[4] * COEFF_1) >> 15;
|
||||||
odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
|
odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 15;
|
||||||
|
|
||||||
even0 = pre_mant[0] + (tmp >> 1);
|
even0 = pre_mant[0] + (tmp >> 1);
|
||||||
even1 = pre_mant[0] - tmp;
|
even1 = pre_mant[0] - tmp;
|
||||||
@ -155,13 +155,13 @@ void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
|
|||||||
if (!hebap) {
|
if (!hebap) {
|
||||||
/* zero-mantissa dithering */
|
/* zero-mantissa dithering */
|
||||||
for (blk = 0; blk < 6; blk++) {
|
for (blk = 0; blk < 6; blk++) {
|
||||||
s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
|
s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFF) - 0x4000;
|
||||||
}
|
}
|
||||||
} else if (hebap < 8) {
|
} else if (hebap < 8) {
|
||||||
/* Vector Quantization */
|
/* Vector Quantization */
|
||||||
int v = get_bits(gbc, bits);
|
int v = get_bits(gbc, bits);
|
||||||
for (blk = 0; blk < 6; blk++) {
|
for (blk = 0; blk < 6; blk++) {
|
||||||
s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8;
|
s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Gain Adaptive Quantization */
|
/* Gain Adaptive Quantization */
|
||||||
@ -175,22 +175,24 @@ void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
|
|||||||
|
|
||||||
for (blk = 0; blk < 6; blk++) {
|
for (blk = 0; blk < 6; blk++) {
|
||||||
int mant = get_sbits(gbc, gbits);
|
int mant = get_sbits(gbc, gbits);
|
||||||
if (mant == -(1 << (gbits-1))) {
|
if (log_gain > 0 && mant == -(1 << (gbits-1))) {
|
||||||
/* large mantissa */
|
/* large mantissa */
|
||||||
int b;
|
int b;
|
||||||
mant = get_sbits(gbc, bits-2+log_gain) << (26-log_gain-bits);
|
int mbits = bits - (2 - log_gain);
|
||||||
|
mant = get_sbits(gbc, mbits);
|
||||||
|
mant <<= (15 - (mbits - 1));
|
||||||
/* remap mantissa value to correct for asymmetric quantization */
|
/* remap mantissa value to correct for asymmetric quantization */
|
||||||
if (mant >= 0)
|
if (mant >= 0)
|
||||||
b = 32768 >> (log_gain+8);
|
b = 32768 >> log_gain;
|
||||||
else
|
else
|
||||||
b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1];
|
b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1];
|
||||||
mant += (ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (mant>>8) + b) >> 7;
|
mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * mant) >> 15) + b;
|
||||||
} else {
|
} else {
|
||||||
/* small mantissa, no GAQ, or Gk=1 */
|
/* small mantissa, no GAQ, or Gk=1 */
|
||||||
mant <<= 24 - bits;
|
mant <<= 15 - (bits-1);
|
||||||
if (!log_gain) {
|
if (!log_gain) {
|
||||||
/* remap mantissa value for no GAQ or Gk=1 */
|
/* remap mantissa value for no GAQ or Gk=1 */
|
||||||
mant += (ff_eac3_gaq_remap_1[hebap-8] * (mant>>8)) >> 7;
|
mant += (ff_eac3_gaq_remap_1[hebap-8] * mant) >> 15;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s->pre_mantissa[ch][bin][blk] = mant;
|
s->pre_mantissa[ch][bin][blk] = mant;
|
||||||
|
Loading…
Reference in New Issue
Block a user