[FFmpeg-soc] [soc]: r747 - in eac3: ac3tab.c ac3tab.h eac3_parser.c
bwolowiec
subversion at mplayerhq.hu
Mon Aug 13 19:44:35 CEST 2007
Author: bwolowiec
Date: Mon Aug 13 19:44:35 2007
New Revision: 747
Log:
Spectral extension. Now turned off, because there are no samples for testing it.
Modified:
eac3/ac3tab.c
eac3/ac3tab.h
eac3/eac3_parser.c
Modified: eac3/ac3tab.c
==============================================================================
--- eac3/ac3tab.c (original)
+++ eac3/ac3tab.c Mon Aug 13 19:44:35 2007
@@ -1353,3 +1353,40 @@ const uint8_t ff_eac3_defcplbndstrc[18]
const uint8_t ff_eac3_defspxbndstrc[17] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
+/**
+ * Table E3.14 Spectral Extension Attenuation Table
+ */
+const float ff_eac3_spxattentab[32][3] = {
+ {0.954841604, 0.911722489, 0.870550563},
+ {0.911722489, 0.831237896, 0.757858283},
+ {0.870550563, 0.757858283, 0.659753955},
+ {0.831237896, 0.690956440, 0.574349177},
+ {0.793700526, 0.629960525, 0.500000000},
+ {0.757858283, 0.574349177, 0.435275282},
+ {0.723634619, 0.523647061, 0.378929142},
+ {0.690956440, 0.477420802, 0.329876978},
+ {0.659753955, 0.435275282, 0.287174589},
+ {0.629960525, 0.396850263, 0.250000000},
+ {0.601512518, 0.361817309, 0.217637641},
+ {0.574349177, 0.329876978, 0.189464571},
+ {0.548412490, 0.300756259, 0.164938489},
+ {0.523647061, 0.274206245, 0.143587294},
+ {0.500000000, 0.250000000, 0.125000000},
+ {0.477420802, 0.227930622, 0.108818820},
+ {0.455861244, 0.207809474, 0.094732285},
+ {0.435275282, 0.189464571, 0.082469244},
+ {0.415618948, 0.172739110, 0.071793647},
+ {0.396850263, 0.157490131, 0.062500000},
+ {0.378929142, 0.143587294, 0.054409410},
+ {0.361817309, 0.130911765, 0.047366143},
+ {0.345478220, 0.119355200, 0.041234622},
+ {0.329876978, 0.108818820, 0.035896824},
+ {0.314980262, 0.099212566, 0.031250000},
+ {0.300756259, 0.090454327, 0.027204705},
+ {0.287174589, 0.082469244, 0.023683071},
+ {0.274206245, 0.075189065, 0.020617311},
+ {0.261823531, 0.068551561, 0.017948412},
+ {0.250000000, 0.062500000, 0.015625000},
+ {0.238710401, 0.056982656, 0.013602353},
+ {0.227930622, 0.051952369, 0.011841536}
+};
Modified: eac3/ac3tab.h
==============================================================================
--- eac3/ac3tab.h (original)
+++ eac3/ac3tab.h Mon Aug 13 19:44:35 2007
@@ -58,6 +58,7 @@ extern const int16_t (*ff_vq_hebap[8])[6
extern const uint8_t ff_eac3_frm_expstr[32][6];
extern const uint8_t ff_eac3_defcplbndstrc[18];
extern const uint8_t ff_eac3_defspxbndstrc[17];
+extern const float ff_eac3_spxattentab[32][3];
#endif /* AC3TAB_H */
Modified: eac3/eac3_parser.c
==============================================================================
--- eac3/eac3_parser.c (original)
+++ eac3/eac3_parser.c Mon Aug 13 19:44:35 2007
@@ -39,6 +39,8 @@
#include "eac3.h"
#include "ac3dec.h"
+void spectral_extension(EAC3Context *s);
+
int ff_eac3_parse_syncinfo(GetBitContext *gbc, EAC3Context *s){
GET_BITS(s->syncword, gbc, 16);
return 0;
@@ -440,6 +442,9 @@ int ff_eac3_parse_audfrm(GetBitContext *
GET_BITS(s->spxattencod[ch], gbc, 5);
}
}
+ }else{
+ for(ch = 1; ch <= s->nfchans; ch++)
+ s->chinspxatten[ch]=0;
}
/* These fields for block start information */
if (s->numblkscod != 0x0) {
@@ -1452,6 +1457,10 @@ int ff_eac3_parse_audblk(GetBitContext *
got_cplchan = 1;
}
}
+
+ //apply spectral extension
+ if(s->spxinu)
+ spectral_extension(s);
}
if(s->lfeon) /* mantissas of low frequency effects channel */
@@ -1503,3 +1512,118 @@ int ff_eac3_parse_auxdata(GetBitContext
// TODO
return 0;
}
+
+void spectral_extension(EAC3Context *s){
+#if 0
+ int copystartmant, copyendmant, copyindex, insertindex;
+ int wrapflag[18];
+ int bandsize, bnd, bin, spxmant, filtbin, ch;
+ float nratio, accum, nscale, sscale, spxcotemp;
+ float noffset[AC3_MAX_CHANNELS], nblendfact[AC3_MAX_CHANNELS][18], sblendfact[AC3_MAX_CHANNELS][18];
+ float rmsenergy[AC3_MAX_CHANNELS][18];
+
+ //XXX spxbandtable[bnd] = 25 + 12 * bnd ?
+
+ copystartmant = spxbandtable[s->spxstrtf];
+ copyendmant = spxbandtable[s->spxbegf];
+
+ for(ch = 1; ch <= s->nfchans; ch++){
+ if(!s->chinspx[ch])
+ continue;
+
+ copyindex = copystartmant;
+ insertindex = copyendmant;
+
+ for (bnd = 0; bnd < s->nspxbnds; bnd++){
+ bandsize = s->spxbndsztab[bnd];
+ if ((copyindex + bandsize) > copyendmant){
+ copyindex = copystartmant;
+ wrapflag[bnd] = 1;
+ }else
+ wrapflag[bnd] = 0;
+ for (bin = 0; bin < bandsize; bin++){
+ if (copyindex == copyendmant)
+ copyindex = copystartmant;
+ s->transform_coeffs[ch][insertindex++] = s->transform_coeffs[ch][copyindex++];
+ }
+ }
+
+ noffset[ch] = s->spxblnd[ch] / 32.0;
+ spxmant = spxbandtable[s->spxbegf];
+ if (s->spxcoe[ch]){
+ for (bnd = 0; bnd < s->nspxbnds; bnd++){
+ bandsize = s->spxbndsztab[bnd];
+ nratio = ((spxmant + 0.5*bandsize) / spxbandtable[s->spxendf]) - noffset[ch];
+ if (nratio < 0.0)
+ nratio = 0.0;
+ else if (nratio > 1.0)
+ nratio = 1.0;
+ nblendfact[ch][bnd] = sqrt(nratio);
+ sblendfact[ch][bnd] = sqrt(1 - nratio);
+ spxmant += bandsize;
+ }
+ }
+
+ spxmant = spxbandtable[s->spxbegf];
+ for (bnd = 0; bnd < s->nspxbnds; bnd++){
+ bandsize = s->spxbndsztab[bnd];
+ accum = 0;
+ for (bin = 0; bin < bandsize; bin++){
+ accum += (s->transform_coeffs[ch][spxmant] * s->transform_coeffs[ch][spxmant]);
+ spxmant++;
+ }
+ rmsenergy[ch][bnd] = sqrt(accum / bandsize);
+ }
+
+ if (s->chinspxatten[ch]){
+ /* apply notch filter at baseband / extension region border */
+ filtbin = spxbandtable[s->spxbegf] - 2;
+ for (bin = 0; bin < 3; bin++){
+ s->transform_coeffs[ch][filtbin] *= ff_eac3_spxattentab[s->spxattencod[ch]][bin];
+ filtbin++;
+ }
+ for (bin = 1; bin >= 0; bin--){
+ s->transform_coeffs[ch][filtbin] *= ff_eac3_spxattentab[s->spxattencod[ch]][bin];
+ filtbin++;
+ }
+ filtbin += s->spxbndsztab[0];
+ /* apply notch at all other wrap points */
+ for (bnd = 1; bnd < s->nspxbnds; bnd++){
+ if (wrapflag[bnd]){
+ filtbin = filtbin - 5;
+ for (bin = 0; bin < 3; bin++){
+ s->transform_coeffs[ch][filtbin] *= ff_eac3_spxattentab[s->spxattencod[ch]][bin];
+ filtbin++;
+ }
+ for (bin = 1; bin >= 0; bin--){
+ s->transform_coeffs[ch][filtbin] *= ff_eac3_spxattentab[s->spxattencod[ch]][bin];
+ filtbin++;
+ }
+ }
+ filtbin += s->spxbndsztab[bnd];
+ }
+ }
+
+ spxmant = spxbandtable[s->spxbegf];
+ for (bnd = 0; bnd < s->nspxbnds; bnd++){
+ nscale = rmsenergy[ch][bnd] * nblendfact[ch][bnd];
+ sscale = sblendfact[ch][bnd];
+ for (bin = 0; bin < s->spxbndsztab[bnd]; bin++){
+ //TODO generate noise()
+ s->transform_coeffs[ch][spxmant] =
+ s->transform_coeffs[ch][spxmant] * sscale + noise() * nscale;
+ spxmant++;
+ }
+ }
+
+ spxmant = spxbandtable[s->spxbegf];
+ for (bnd = 0; bnd < s->nspxbnds; bnd++){
+ spxcotemp = s->spxco[ch][bnd];
+ for (bin = 0; bin < s->spxbndsztab[bnd]; bin++){
+ s->transform_coeffs[ch][spxmant] *= spxcotemp * 32;
+ spxmant++;
+ }
+ }
+ }
+#endif
+}
More information about the FFmpeg-soc
mailing list