[FFmpeg-soc] [soc]: r3720 - in eac3: ac3dec.c eac3dec.c ffmpeg.patch
jbr
subversion at mplayerhq.hu
Sun Sep 7 21:45:41 CEST 2008
Author: jbr
Date: Sun Sep 7 21:45:41 2008
New Revision: 3720
Log:
calculate spectral extension noise and signal blending factors
Modified:
eac3/ac3dec.c
eac3/eac3dec.c
eac3/ffmpeg.patch
Modified: eac3/ac3dec.c
==============================================================================
--- eac3/ac3dec.c (original)
+++ eac3/ac3dec.c Sun Sep 7 21:45:41 2008
@@ -810,9 +810,12 @@ static int decode_audio_block(AC3DecodeC
/* determine which channels use spx */
if (s->channel_mode == AC3_CHMODE_MONO) {
s->channel_in_spx[1] = 1;
+ s->spx_coords_exist[1] = 0;
} else {
- for (ch = 1; ch <= fbw_channels; ch++)
+ for (ch = 1; ch <= fbw_channels; ch++) {
s->channel_in_spx[ch] = get_bits1(gbc);
+ s->spx_coords_exist[ch] = 0;
+ }
}
s->spx_copy_start_freq = get_bits(gbc, 2) * 12 + 25;
@@ -822,6 +825,7 @@ static int decode_audio_block(AC3DecodeC
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;
+ s->spx_end_freq = spx_end_subband * 12 + 25;
decode_band_structure(gbc, blk, s->eac3, s->spx_start_subband,
spx_end_subband, ff_eac3_default_spx_band_struct,
@@ -842,13 +846,26 @@ static int decode_audio_block(AC3DecodeC
for (ch = 1; ch <= fbw_channels; ch++) {
if (s->channel_in_spx[ch]) {
if (s->first_spx_coords[ch] || get_bits1(gbc)) {
+ int bin, spx_blend;
s->first_spx_coords[ch] = 0;
- skip_bits(gbc, 5); // skip spx blend
+ s->spx_coords_exist[ch] = 1;
+ spx_blend = get_bits(gbc, 5) << 18;
skip_bits(gbc, 2); // skip master spx coord
+ bin = s->spx_start_freq;
for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
+ /* calculate blending factors */
+ int bandsize = s->spx_band_sizes[bnd];
+ int nratio = (((bin + (bandsize >> 1)) << 23) / s->spx_end_freq) - spx_blend;
+ nratio = av_clip(nratio, 0, INT24_MAX);
+ s->spx_noise_blend [ch][bnd] = ff_sqrt( nratio) * M_SQRT_INT24_MAX;
+ s->spx_signal_blend[ch][bnd] = ff_sqrt(INT24_MAX - nratio) * M_SQRT_INT24_MAX;
+ bin += bandsize;
+
skip_bits(gbc, 4); // skip spx coord exponent
skip_bits(gbc, 2); // skip spx coord mantissa
}
+ } else {
+ s->spx_coords_exist[ch] = 0;
}
} else {
s->first_spx_coords[ch] = 1;
Modified: eac3/eac3dec.c
==============================================================================
--- eac3/eac3dec.c (original)
+++ eac3/eac3dec.c Sun Sep 7 21:45:41 2008
@@ -77,9 +77,6 @@ void ff_eac3_apply_spectral_extension(AC
insertindex += copy_sizes[bnd];
}
- /* 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
Modified: eac3/ffmpeg.patch
==============================================================================
--- eac3/ffmpeg.patch (original)
+++ eac3/ffmpeg.patch Sun Sep 7 21:45:41 2008
@@ -2,7 +2,18 @@ Index: libavcodec/ac3dec.h
===================================================================
--- libavcodec/ac3dec.h (revision 15141)
+++ libavcodec/ac3dec.h (working copy)
-@@ -88,6 +88,22 @@
+@@ -43,6 +43,10 @@
+ #define AC3_BLOCK_SIZE 256
+ #define MAX_BLOCKS 6
+
++#define INT24_MIN -8388608
++#define INT24_MAX 8388607
++#define M_SQRT_INT24_MAX 2896
++
+ typedef struct {
+ AVCodecContext *avctx; ///< parent context
+ GetBitContext gbc; ///< bitstream reader
+@@ -88,6 +92,24 @@
int cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates (cplco)
///@}
@@ -12,20 +23,22 @@ Index: libavcodec/ac3dec.h
+ 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_end_freq; ///< spx end 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_noise_blend[AC3_MAX_CHANNELS][17]; ///< spx noise blending factor (nblendfact)
++ int spx_signal_blend[AC3_MAX_CHANNELS][17]; ///< spx signal blending factor (sblendfact)
+ 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 @@
+@@ -179,4 +201,6 @@
*/
void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch);
More information about the FFmpeg-soc
mailing list