aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/aacdec.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-04-28 04:23:36 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-04-28 04:26:01 +0200
commit0665199e438fcdd2000717352fc665a8cf017f7c (patch)
tree41e6d53948b16b9b1c82900da0d28c61efab9333 /libavcodec/aacdec.c
parente5d80c7b2d893422e2e60a97e08bfc48ca1684e6 (diff)
parentb239526873dc81f9b66796ad4d9fe1cb93ec34d3 (diff)
downloadffmpeg-0665199e438fcdd2000717352fc665a8cf017f7c.tar.gz
Merge remote branch 'qatar/master'
* qatar/master: vorbisdec: Rename silly "class_" variable to plain "class". simple_idct_alpha: Drop some useless casts. Simplify av_log_missing_feature(). ac3enc: remove check for mismatching channels and channel_layout If AVCodecContext.channels is 0 and AVCodecContext.channel_layout is non-zero, set channels based on channel_layout. If AVCodecContext.channel_layout and AVCodecContext.channels are both non-zero, check to make sure they do not contradict eachother. cosmetics: indentation Check AVCodec.supported_samplerates and AVCodec.channel_layouts in avcodec_open(). aacdec: remove sf_scale and sf_offset. aacdec: use a scale of 2 in the LTP MDCT rather than doubling the coefficient table values from the spec. Define POW_SF2_ZERO in aac.h and use for ff_aac_pow2sf_tabp[] offsets instead of hardcoding 200 everywhere. Large intensity stereo and PNS indices are legal. Clip them instead of erroring out. A magnitude of 100 corresponds to 2^25 so the will most likely result in clipped output anyway. qpeg: use reget_buffer() in decode_frame() ultimotion: use reget_buffer() in ulti_decode_frame() smacker: remove unnecessary call to avctx->release_buffer in decode_frame() avparser: don't av_malloc(0). Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/aacdec.c')
-rw-r--r--libavcodec/aacdec.c51
1 files changed, 23 insertions, 28 deletions
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 96b1323c19..76b14a194c 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -579,12 +579,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
ac->random_state = 0x1f2e3d4c;
- // -1024 - Compensate wrong IMDCT method.
- // 60 - Required to scale values to the correct range [-32768,32767]
- // for float to int16 conversion. (1 << (60 / 4)) == 32768
- ac->sf_scale = 1. / -1024.;
- ac->sf_offset = 60;
-
ff_aac_tableinit();
INIT_VLC_STATIC(&vlc_scalefactors,7,FF_ARRAY_ELEMS(ff_aac_scalefactor_code),
@@ -592,9 +586,9 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]),
352);
- ff_mdct_init(&ac->mdct, 11, 1, 1.0);
- ff_mdct_init(&ac->mdct_small, 8, 1, 1.0);
- ff_mdct_init(&ac->mdct_ltp, 11, 0, 1.0);
+ ff_mdct_init(&ac->mdct, 11, 1, 1.0/1024.0);
+ ff_mdct_init(&ac->mdct_small, 8, 1, 1.0/128.0);
+ ff_mdct_init(&ac->mdct_ltp, 11, 0, -2.0);
// window initialization
ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
@@ -652,7 +646,7 @@ static void decode_ltp(AACContext *ac, LongTermPrediction *ltp,
int sfb;
ltp->lag = get_bits(gb, 11);
- ltp->coef = ltp_coef[get_bits(gb, 3)] * ac->sf_scale;
+ ltp->coef = ltp_coef[get_bits(gb, 3)];
for (sfb = 0; sfb < FFMIN(max_sfb, MAX_LTP_LONG_SFB); sfb++)
ltp->used[sfb] = get_bits1(gb);
}
@@ -790,9 +784,9 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
enum BandType band_type[120],
int band_type_run_end[120])
{
- const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0);
int g, i, idx = 0;
- int offset[3] = { global_gain, global_gain - 90, 100 };
+ int offset[3] = { global_gain, global_gain - 90, 0 };
+ int clipped_offset;
int noise_flag = 1;
static const char *sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" };
for (g = 0; g < ics->num_window_groups; g++) {
@@ -804,12 +798,14 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
} else if ((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) {
for (; i < run_end; i++, idx++) {
offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
- if (offset[2] > 255U) {
- av_log(ac->avctx, AV_LOG_ERROR,
- "%s (%d) out of range.\n", sf_str[2], offset[2]);
- return -1;
+ clipped_offset = av_clip(offset[2], -155, 100);
+ if (offset[2] != clipped_offset) {
+ av_log_ask_for_sample(ac->avctx, "Intensity stereo "
+ "position clipped (%d -> %d).\nIf you heard an "
+ "audible artifact, there may be a bug in the "
+ "decoder. ", offset[2], clipped_offset);
}
- sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300];
+ sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO];
}
} else if (band_type[idx] == NOISE_BT) {
for (; i < run_end; i++, idx++) {
@@ -817,12 +813,14 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
offset[1] += get_bits(gb, 9) - 256;
else
offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
- if (offset[1] > 255U) {
- av_log(ac->avctx, AV_LOG_ERROR,
- "%s (%d) out of range.\n", sf_str[1], offset[1]);
- return -1;
+ clipped_offset = av_clip(offset[1], -100, 155);
+ if (offset[2] != clipped_offset) {
+ av_log_ask_for_sample(ac->avctx, "Noise gain clipped "
+ "(%d -> %d).\nIf you heard an audible "
+ "artifact, there may be a bug in the decoder. ",
+ offset[1], clipped_offset);
}
- sf[idx] = -ff_aac_pow2sf_tab[offset[1] + sf_offset + 100];
+ sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO];
}
} else {
for (; i < run_end; i++, idx++) {
@@ -832,7 +830,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
"%s (%d) out of range.\n", sf_str[0], offset[0]);
return -1;
}
- sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset];
+ sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO];
}
}
}
@@ -1243,7 +1241,6 @@ static av_always_inline float flt16_trunc(float pf)
}
static av_always_inline void predict(PredictorState *ps, float *coef,
- float sf_scale, float inv_sf_scale,
int output_enable)
{
const float a = 0.953125; // 61.0 / 64
@@ -1260,9 +1257,9 @@ static av_always_inline void predict(PredictorState *ps, float *coef,
pv = flt16_round(k1 * r0 + k2 * r1);
if (output_enable)
- *coef += pv * sf_scale;
+ *coef += pv;
- e0 = *coef * inv_sf_scale;
+ e0 = *coef;
e1 = e0 - k1 * r0;
ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1);
@@ -1280,7 +1277,6 @@ static av_always_inline void predict(PredictorState *ps, float *coef,
static void apply_prediction(AACContext *ac, SingleChannelElement *sce)
{
int sfb, k;
- float sf_scale = ac->sf_scale, inv_sf_scale = 1 / ac->sf_scale;
if (!sce->ics.predictor_initialized) {
reset_all_predictors(sce->predictor_state);
@@ -1291,7 +1287,6 @@ static void apply_prediction(AACContext *ac, SingleChannelElement *sce)
for (sfb = 0; sfb < ff_aac_pred_sfb_max[ac->m4ac.sampling_index]; sfb++) {
for (k = sce->ics.swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) {
predict(&sce->predictor_state[k], &sce->coeffs[k],
- sf_scale, inv_sf_scale,
sce->ics.predictor_present && sce->ics.prediction_used[sfb]);
}
}