[FFmpeg-soc] [soc]: r3716 - in eac3: ac3dec.c eac3dec.c ffmpeg.patch
jbr
subversion at mplayerhq.hu
Sun Sep 7 19:50:10 CEST 2008
Author: jbr
Date: Sun Sep 7 19:50:10 2008
New Revision: 3716
Log:
copy spectral extension coeffs. scaling and noise blending are not yet
implemented, so it sounds a little weird for now.
Modified:
eac3/ac3dec.c
eac3/eac3dec.c
eac3/ffmpeg.patch
Modified: eac3/ac3dec.c
==============================================================================
--- eac3/ac3dec.c (original)
+++ eac3/ac3dec.c Sun Sep 7 19:50:10 2008
@@ -719,15 +719,15 @@ static void decode_band_structure(GetBit
int start_subband, int end_subband,
const uint8_t *default_band_struct,
uint8_t *band_struct, int *num_subbands,
- int *num_bands)
+ int *num_bands, int *band_sizes)
{
- int bnd, n_subbands, n_bands;
+ int subbnd, bnd, n_subbands, n_bands, bnd_sz[22];
n_subbands = n_bands = end_subband - start_subband;
if (!eac3 || get_bits1(gbc)) {
- for (bnd = 0; bnd < n_subbands - 1; bnd++) {
- band_struct[bnd] = get_bits1(gbc);
+ for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) {
+ band_struct[subbnd] = get_bits1(gbc);
}
} else if (!blk) {
memcpy(band_struct,
@@ -737,14 +737,25 @@ static void decode_band_structure(GetBit
band_struct[n_subbands-1] = 0;
/* calculate number of bands based on band structure */
- for (bnd = 0; bnd < n_subbands-1; bnd++) {
- n_bands -= band_struct[bnd];
+ bnd = 0;
+ bnd_sz[0] = 12;
+ for (bnd = 0, subbnd = 0; subbnd < n_subbands-1; subbnd++) {
+ if (band_struct[subbnd]) {
+ n_bands--;
+ bnd_sz[bnd] += 12;
+ } else {
+ //av_log(NULL, AV_LOG_INFO, "bnd_sz[%d]=%d\n", bnd, bnd_sz[bnd]);
+ bnd_sz[++bnd] = 12;
+ }
}
+ //av_log(NULL, AV_LOG_INFO, "n_bands=%d\n", n_bands);
if (num_subbands)
*num_subbands = n_subbands;
if (num_bands)
*num_bands = n_bands;
+ if (band_sizes)
+ memcpy(band_sizes, bnd_sz, sizeof(int)*n_bands);
}
/**
@@ -806,16 +817,18 @@ static int decode_audio_block(AC3DecodeC
s->channel_in_spx[ch] = get_bits1(gbc);
}
- skip_bits(gbc, 2); // skip spx start copy freq
+ s->spx_copy_start_freq = get_bits(gbc, 2) * 12 + 25;
begf = get_bits(gbc, 3);
endf = get_bits(gbc, 3);
s->spx_start_subband = begf < 6 ? begf+2 : 2*begf-3;
spx_end_subband = endf < 4 ? endf+5 : 2*endf+3;
+ s->num_spx_subbands = spx_end_subband - s->spx_start_subband;
s->spx_start_freq = s->spx_start_subband * 12 + 25;
decode_band_structure(gbc, blk, s->eac3, s->spx_start_subband,
spx_end_subband, ff_eac3_default_spx_band_struct,
- s->spx_band_struct, NULL, &s->num_spx_bands);
+ s->spx_band_struct, NULL, &s->num_spx_bands,
+ s->spx_band_sizes);
} else {
for (ch = 1; ch <= fbw_channels; ch++) {
s->channel_in_spx[ch] = 0;
@@ -897,7 +910,7 @@ static int decode_audio_block(AC3DecodeC
decode_band_structure(gbc, blk, s->eac3, cpl_start_subband,
cpl_end_subband, ff_eac3_default_cpl_band_struct,
s->cpl_band_struct, &s->num_cpl_subbands,
- &s->num_cpl_bands);
+ &s->num_cpl_bands, NULL);
} else {
/* coupling not in use */
for (ch = 1; ch <= fbw_channels; ch++) {
@@ -1182,12 +1195,12 @@ static int decode_audio_block(AC3DecodeC
/* TODO: generate enhanced coupling coordinates and uncouple */
- /* TODO: apply spectral extension */
-
/* recover coefficients if rematrixing is in use */
if(s->channel_mode == AC3_CHMODE_STEREO)
do_rematrixing(s);
+ ff_eac3_apply_spectral_extension(s);
+
/* apply scaling to coefficients (headroom, dynrng) */
for(ch=1; ch<=s->channels; ch++) {
float gain = s->mul_bias / 4194304.0f;
Modified: eac3/eac3dec.c
==============================================================================
--- eac3/eac3dec.c (original)
+++ eac3/eac3dec.c Sun Sep 7 19:50:10 2008
@@ -36,6 +36,56 @@ typedef enum {
#define EAC3_SR_CODE_REDUCED 3
+
+void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
+{
+ int bin, bnd, ch;
+ int copyindex, insertindex;
+ int wrapflag[17], copy_index_tab[256];
+
+ /* Set copy index mapping table. Set wrap flags to apply a notch filter at
+ wrap points later on. */
+ copyindex = s->spx_copy_start_freq;
+ insertindex = s->spx_start_freq;
+ memset(wrapflag, 0, sizeof(wrapflag));
+ for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
+ int bandsize = s->spx_band_sizes[bnd];
+ if ((copyindex + bandsize) > s->spx_start_freq) {
+ copyindex = s->spx_copy_start_freq;
+ wrapflag[bnd] = 1;
+ }
+ for (bin = 0; bin < bandsize; bin++) {
+ if (copyindex == s->spx_start_freq)
+ copyindex = s->spx_copy_start_freq;
+ copy_index_tab[insertindex++] = copyindex++;
+ }
+ }
+
+ for (ch = 1; ch <= s->fbw_channels; ch++) {
+ if (!s->channel_in_spx[ch])
+ continue;
+
+ /* Copy coeffs from normal bands to extension bands */
+ /* note: maybe try using wrap intervals instead so memcpy can be used */
+ for (bin = s->spx_start_freq; bin < s->spx_start_freq+s->num_spx_subbands*12; bin++) {
+ s->fixed_coeffs[ch][bin] = s->fixed_coeffs[ch][copy_index_tab[bin]];
+ }
+
+ /* Calculate blending factors based on center points of SPX bands
+ and the offset decoded from the bitstream for each channel. */
+
+ /* Calculate RMS energy for each SPX band. */
+
+ /* Apply a notch filter at transitions between normal and extension
+ bands and at all wrap points. */
+
+ /* Apply coefficient and noise scaling based on previously calculated
+ RMS energy and blending factors for each band. */
+
+ /* Scale coefficients using spectral extension coordinates */
+ }
+}
+
/** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
#define COEFF_0 10273905LL
Modified: eac3/ffmpeg.patch
==============================================================================
--- eac3/ffmpeg.patch (original)
+++ eac3/ffmpeg.patch Sun Sep 7 19:50:10 2008
@@ -1,45 +1,37 @@
-Index: libavutil/Makefile
-===================================================================
---- libavutil/Makefile (revision 15141)
-+++ libavutil/Makefile (working copy)
-@@ -23,6 +23,7 @@
- string.o \
- tree.o \
- utils.o \
-+ znrng.o \
-
- HEADERS = adler32.h \
- avstring.h \
-@@ -41,7 +42,7 @@
- rational.h \
- sha1.h
-
--TESTS = $(addsuffix -test$(EXESUF), adler32 aes crc des lls md5 pca random sha1 softfloat tree)
-+TESTS = $(addsuffix -test$(EXESUF), adler32 aes crc des lls md5 pca random sha1 softfloat tree znrng)
-
- include $(SUBDIR)../subdir.mak
-
Index: libavcodec/ac3dec.h
===================================================================
--- libavcodec/ac3dec.h (revision 15141)
+++ libavcodec/ac3dec.h (working copy)
-@@ -88,6 +88,16 @@
+@@ -88,6 +88,22 @@
int cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates (cplco)
///@}
+///@defgroup spx spectral extension
+ int spx_in_use[MAX_BLOCKS]; ///< spectral extension in use (spxinu)
+ int channel_in_spx[AC3_MAX_CHANNELS]; ///< channel in spectral extension (chinspx)
++ int spx_coords_exist[AC3_MAX_CHANNELS]; ///< indicates if a channel has spx coords (spxcoe)
+ int spx_start_subband; ///< spx beginning frequency band (spxbegf)
+ int spx_start_freq; ///< spx start frequency bin
++ int spx_copy_start_freq; ///< spx starting frequency for copying (copystartmant)
++ int num_spx_subbands; ///< number of spectral extension subbands
+ int num_spx_bands; ///< number of spectral extension bands (nspxbnds)
+ uint8_t spx_band_struct[17]; ///< spectral extension band structure (spxbndstrc)
++ int spx_band_sizes[17]; ///< number of bins in each band (spxbndsztab)
+ int first_spx_coords[AC3_MAX_CHANNELS]; ///< first spx coordinates states (firstspxcos)
++ int spx_blend[AC3_MAX_CHANNELS]; ///< spectral extension blend (spxblnd)
++ int spx_coords[AC3_MAX_CHANNELS][17]; ///< spectral extension coordinates (spxco)
+///@}
+
///@defgroup aht adaptive hybrid transform
int channel_uses_aht[AC3_MAX_CHANNELS]; ///< channel AHT in use (chahtinu)
int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][MAX_BLOCKS]; ///< pre-IDCT mantissas
+@@ -179,4 +195,6 @@
+ */
+ void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch);
+
++void ff_eac3_apply_spectral_extension(AC3DecodeContext *s);
++
+ #endif /* AVCODEC_AC3DEC_H */
Index: libavcodec/ac3dec_data.c
===================================================================
--- libavcodec/ac3dec_data.c (revision 15141)
@@ -69,3 +61,24 @@ Index: libavcodec/ac3dec_data.h
extern const uint8_t ff_ac3_rematrix_band_tab[5];
+Index: libavutil/Makefile
+===================================================================
+--- libavutil/Makefile (revision 15141)
++++ libavutil/Makefile (working copy)
+@@ -23,6 +23,7 @@
+ string.o \
+ tree.o \
+ utils.o \
++ znrng.o \
+
+ HEADERS = adler32.h \
+ avstring.h \
+@@ -41,7 +42,7 @@
+ rational.h \
+ sha1.h
+
+-TESTS = $(addsuffix -test$(EXESUF), adler32 aes crc des lls md5 pca random sha1 softfloat tree)
++TESTS = $(addsuffix -test$(EXESUF), adler32 aes crc des lls md5 pca random sha1 softfloat tree znrng)
+
+ include $(SUBDIR)../subdir.mak
+
More information about the FFmpeg-soc
mailing list