[FFmpeg-soc] [soc]: r1694 - in eac3: ac3tab.c eac3.h eac3dec.c
jbr
subversion at mplayerhq.hu
Sun Dec 30 00:56:29 CET 2007
Author: jbr
Date: Sun Dec 30 00:56:29 2007
New Revision: 1694
Log:
fix and simplify GAQ decoding
Modified:
eac3/ac3tab.c
eac3/eac3.h
eac3/eac3dec.c
Modified: eac3/ac3tab.c
==============================================================================
--- eac3/ac3tab.c (original)
+++ eac3/ac3tab.c Sun Dec 30 00:56:29 2007
@@ -274,28 +274,28 @@ const uint8_t ff_eac3_blocks[4] = {
* ff_eac3_gaq_remap[hebap+8][x<0,x>=0][Gk=1,2,4][a,b]
*/
const int16_t ff_eac3_gaq_remap[12][2][3][2] = {
-{{{ 4681, 0}, { -10923, 16384}, { -4681, 8192}},
- {{ 4681, 0}, { -10923, -5461}, { -4681, -1170}}},
-{{{ 2185, 0}, { -14043, 16384}, { -6554, 8192}},
- {{ 2185, 0}, { -14043, -11703}, { -6554, -4915}}},
-{{{ 1057, 0}, { -15292, 16384}, { -7399, 8192}},
- {{ 1057, 0}, { -15292, -14199}, { -7399, -6606}}},
-{{{ 520, 0}, { -15855, 16384}, { -7802, 8192}},
- {{ 520, 0}, { -15855, -15327}, { -7802, -7412}}},
-{{{ 258, 0}, { -16124, 16384}, { -7998, 8192}},
- {{ 258, 0}, { -16124, -15864}, { -7998, -7805}}},
-{{{ 129, 0}, { -16255, 16384}, { -8096, 8192}},
- {{ 129, 0}, { -16255, -16126}, { -8096, -7999}}},
-{{{ 64, 0}, { -16320, 16384}, { -8144, 8192}},
- {{ 64, 0}, { -16320, -16255}, { -8144, -8096}}},
-{{{ 32, 0}, { -16352, 16384}, { -8168, 8192}},
- {{ 32, 0}, { -16352, -16320}, { -8168, -8144}}},
-{{{ 16, 0}, { -16368, 16384}, { -8180, 8192}},
- {{ 16, 0}, { -16368, -16352}, { -8180, -8168}}},
-{{{ 8, 0}, { 0, 0}, { 0, 0}},
- {{ 8, 0}, { 0, 0}, { 0, 0}}},
-{{{ 2, 0}, { 0, 0}, { 0, 0}},
- {{ 2, 0}, { 0, 0}, { 0, 0}}},
+{{{ 0, 4681}, { -10923, 16384}, { -4681, 8192}},
+ {{ 0, 4681}, { -10923, -5461}, { -4681, -1170}}},
+{{{ 0, 2185}, { -14043, 16384}, { -6554, 8192}},
+ {{ 0, 2185}, { -14043, -11703}, { -6554, -4915}}},
+{{{ 0, 1057}, { -15292, 16384}, { -7399, 8192}},
+ {{ 0, 1057}, { -15292, -14199}, { -7399, -6606}}},
+{{{ 0, 520}, { -15855, 16384}, { -7802, 8192}},
+ {{ 0, 520}, { -15855, -15327}, { -7802, -7412}}},
+{{{ 0, 258}, { -16124, 16384}, { -7998, 8192}},
+ {{ 0, 258}, { -16124, -15864}, { -7998, -7805}}},
+{{{ 0, 129}, { -16255, 16384}, { -8096, 8192}},
+ {{ 0, 129}, { -16255, -16126}, { -8096, -7999}}},
+{{{ 0, 64}, { -16320, 16384}, { -8144, 8192}},
+ {{ 0, 64}, { -16320, -16255}, { -8144, -8096}}},
+{{{ 0, 32}, { -16352, 16384}, { -8168, 8192}},
+ {{ 0, 32}, { -16352, -16320}, { -8168, -8144}}},
+{{{ 0, 16}, { -16368, 16384}, { -8180, 8192}},
+ {{ 0, 16}, { -16368, -16352}, { -8180, -8168}}},
+{{{ 0, 8}, { 0, 0}, { 0, 0}},
+ {{ 0, 8}, { 0, 0}, { 0, 0}}},
+{{{ 0, 2}, { 0, 0}, { 0, 0}},
+ {{ 0, 2}, { 0, 0}, { 0, 0}}},
{{{ 0, 0}, { 0, 0}, { 0, 0}},
{{ 0, 0}, { 0, 0}, { 0, 0}}},
};
Modified: eac3/eac3.h
==============================================================================
--- eac3/eac3.h (original)
+++ eac3/eac3.h Sun Dec 30 00:56:29 2007
@@ -81,8 +81,8 @@ typedef struct EAC3Context{
///@defgroup aht Adaptive Hybrid Transform
int channel_uses_aht[AC3_MAX_CHANNELS]; ///< Channel AHT in use (chahtinu)
- int chgaqgain[256]; ///< Channel gain adaptive quantization gain
- float pre_chmant[6][AC3_MAX_CHANNELS][256]; ///< Pre channel mantissas
+ int gaq_gain[256]; ///< Gain adaptive quantization gain
+ float pre_mantissa[6][AC3_MAX_CHANNELS][256]; ///< Pre-IDCT mantissas
///@}
///@defgroup spx Spectral Extension
Modified: eac3/eac3dec.c
==============================================================================
--- eac3/eac3dec.c (original)
+++ eac3/eac3dec.c Sun Dec 30 00:56:29 2007
@@ -26,6 +26,10 @@
static float idct_cos_tab[6][5];
+static int gaq_ungroup_tab[32][3];
+
+static float gaq_scale_factors[3][17];
+
static void log_missing_feature(AVCodecContext *avctx, const char *log){
av_log(avctx, AV_LOG_ERROR, "%s is not implemented. If you want to help, "
"update your FFmpeg version to the newest one from SVN. If the "
@@ -150,101 +154,85 @@ static void spectral_extension(EAC3Conte
#endif
static void get_transform_coeffs_aht_ch(EAC3Context *s, int ch){
- int endbap, bin, n, m;
- int bg, g, bits, pre_chmant, remap, chgaqsections, chgaqmod;
+ int bin, blk, gs;
+ int hebap, end_bap, gaq_mode, bits, pre_mantissa, remap, log_gain, gain;
float mant;
GetBitContext *gbc = &s->gbc;
- chgaqmod = get_bits(gbc, 2);
-
- endbap = chgaqmod<2?12:17;
-
- chgaqsections = 0;
- for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
- if (s->hebap[ch][bin] > 7 && s->hebap[ch][bin] < endbap)
- chgaqsections++;
- }
+ gaq_mode = get_bits(gbc, 2);
+ end_bap = (gaq_mode < 2) ? 12 : 17;
- if (chgaqmod == EAC3_GAQ_12 || chgaqmod == EAC3_GAQ_14) {
- for (n = 0; n < chgaqsections; n++) {
- s->chgaqgain[n] = get_bits1(gbc);
+ if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
+ /* read 1-bit GAQ gain codes */
+ gs = 0;
+ for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
+ if (s->hebap[ch][bin] > 7 && s->hebap[ch][bin] < end_bap)
+ s->gaq_gain[gs++] = ff_gaq_gk[gaq_mode][get_bits1(gbc)];
}
- } else if (chgaqmod == EAC3_GAQ_124) {
- int grpgain;
- chgaqsections = (chgaqsections+2)/3;
- for (n = 0; n < chgaqsections; n++) {
- grpgain = get_bits(gbc, 5);
- s->chgaqgain[3*n] = grpgain/9;
- s->chgaqgain[3*n+1] = (grpgain%9)/3;
- s->chgaqgain[3*n+2] = grpgain%3;
+ } else if (gaq_mode == EAC3_GAQ_124) {
+ /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
+ int gc = 2;
+ gs = 0;
+ for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
+ if (s->hebap[ch][bin] > 7 && s->hebap[ch][bin] < end_bap) {
+ if(gc++ == 2) {
+ int group_gain = get_bits(gbc, 5);
+ s->gaq_gain[gs++] = ff_gaq_gk[gaq_mode][gaq_ungroup_tab[group_gain][0]];
+ s->gaq_gain[gs++] = ff_gaq_gk[gaq_mode][gaq_ungroup_tab[group_gain][1]];
+ s->gaq_gain[gs++] = ff_gaq_gk[gaq_mode][gaq_ungroup_tab[group_gain][2]];
+ gc = 0;
+ }
+ }
}
}
- m=0;
+ gs=0;
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
- int hebap = s->hebap[ch][bin];
- if (hebap > 7) {
- // GAQ (E3.3.4.2)
- // XXX what about gaqmod = 0 ?
- // difference between Gk=1 and gaqmod=0 ?
- if (hebap < endbap) {
- // hebap in active range
- // Gk = 1<<bg
- bg = ff_gaq_gk[chgaqmod][s->chgaqgain[m++]];
+ hebap = s->hebap[ch][bin];
+ bits = ff_bits_vs_hebap[hebap];
+ if (!hebap) {
+ /* hebap=0 TODO:dithering */
+ for (blk = 0; blk < 6; blk++) {
+ s->pre_mantissa[blk][ch][bin] = 0;
+ }
+ } else if (hebap < 8) {
+ /* Vector Quantization */
+ int v = get_bits(gbc, bits);
+ for (blk = 0; blk < 6; blk++) {
+ s->pre_mantissa[blk][ch][bin] = ff_vq_hebap[hebap][v][blk] / 32768.0f;
+ }
+ } else {
+ /* Gain Adaptive Quantization */
+ if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
+ log_gain = s->gaq_gain[gs++];
} else {
- bg = 0;
+ log_gain = 0;
}
- bits = ff_bits_vs_hebap[hebap];
+ gain = 1 << log_gain;
- for (n = 0; n < 6; n++) {
- // pre_chmant[n][ch][bin]
- pre_chmant = get_sbits(gbc, bits-bg);
- if (bg && pre_chmant == -(1 << (bits - bg - 1))) {
+ for (blk = 0; blk < 6; blk++) {
+ pre_mantissa = get_sbits(gbc, bits-log_gain);
+ if (gain == 1) {
+ // Gk = 1, GAQ mode = 0, or hebap is outside of GAQ range
+ mant = pre_mantissa * gaq_scale_factors[0][bits];
+ remap = 1;
+ } else if (pre_mantissa == -(1 << (bits-log_gain-1))) {
// large mantissa
- pre_chmant = get_sbits(gbc, bits - ((bg==1)?1:0));
- if (bg == 1)
- //Gk = 2
- mant = (float)pre_chmant/((1<<(bits-1))-1);
- else
- //Gk = 4
- mant = (float)pre_chmant*3.0f/((1<<(bits+1))-2);
-
- g = 0;
+ pre_mantissa = get_sbits(gbc, bits-(gain==2));
+ mant = pre_mantissa * gaq_scale_factors[log_gain][bits];
remap = 1;
} else {
// small mantissa
- if (bg)
- //Gk = 2 or 4
- mant = (float)pre_chmant/((1<<(bits-1))-1);
- else
- //Gk = 1
- mant = (float)pre_chmant*2.0f/((1<<bits)-1); ///XXX
-
- g = bg;
- remap = (!bg) && (s->hebap[ch][bin] < endbap);
+ mant = pre_mantissa * ff_ac3_scale_factors[bits-1];
+ remap = 0;
}
- //TODO when remap needed ?
if (remap) {
- mant = (float)
- (ff_eac3_gaq_remap[hebap-8][0][g][0]/32768.0f + 1.0f)
- * mant / (1<<g) +
- (ff_eac3_gaq_remap[hebap-8][mant<0][g][1]) / 32768.0f;
- }
- s->pre_chmant[n][ch][bin] = mant;
- }
- } else {
- // hebap = 0 or VQ
- if (hebap) {
- pre_chmant = get_bits(gbc, ff_bits_vs_hebap[hebap]);
- for (n = 0; n < 6; n++) {
- s->pre_chmant[n][ch][bin] =
- ff_vq_hebap[hebap][pre_chmant][n] / 32768.0f;
- }
- } else {
- for (n = 0; n < 6; n++) {
- s->pre_chmant[n][ch][bin] = 0;
+ int a = ff_eac3_gaq_remap[hebap-8][0][log_gain][0] + 32768;
+ int b = ff_eac3_gaq_remap[hebap-8][mant<0][log_gain][1];
+ mant = (a * mant + b) / 32768;
}
+ s->pre_mantissa[blk][ch][bin] = mant;
}
}
}
@@ -255,9 +243,9 @@ static void idct_transform_coeffs_ch(EAC
int bin, i;
float tmp;
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
- tmp = s->pre_chmant[0][ch][bin];
+ tmp = s->pre_mantissa[0][ch][bin];
for (i = 1; i < 6; i++) {
- tmp += idct_cos_tab[blk][i-1] * s->pre_chmant[i][ch][bin];
+ tmp += idct_cos_tab[blk][i-1] * s->pre_mantissa[i][ch][bin];
}
s->transform_coeffs[ch][bin] = tmp * ff_ac3_scale_factors[s->dexps[ch][bin]];
}
@@ -1286,6 +1274,20 @@ static void eac3_tables_init(void) {
idct_cos_tab[blk][i-1] = M_SQRT2 * cos(M_PI*i*(2*blk + 1)/12);
}
}
+
+ // initialize ungrouping table for 1.67-bit GAQ gain codes
+ for(i=0; i<32; i++) {
+ gaq_ungroup_tab[i][0] = i / 9;
+ gaq_ungroup_tab[i][1] = (i % 9) / 3;
+ gaq_ungroup_tab[i][2] = i % 3;
+ }
+
+ // initialize GAQ scale factors
+ for(i=1; i<17; i++) {
+ gaq_scale_factors[0][i] = 2.0f/((1<<i)-1);
+ gaq_scale_factors[1][i] = 1.0f/((1<<(i-1))-1);
+ gaq_scale_factors[2][i] = 3.0f/((1<<(i+1))-2);
+ }
}
static int eac3_decode_init(AVCodecContext *avctx){
More information about the FFmpeg-soc
mailing list