@ -579,12 +579,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
ac - > random_state = 0x1f2e3d4c ;
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 ( ) ;
ff_aac_tableinit ( ) ;
INIT_VLC_STATIC ( & vlc_scalefactors , 7 , FF_ARRAY_ELEMS ( ff_aac_scalefactor_code ) ,
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 ] ) ,
ff_aac_scalefactor_code , sizeof ( ff_aac_scalefactor_code [ 0 ] ) , sizeof ( ff_aac_scalefactor_code [ 0 ] ) ,
352 ) ;
352 ) ;
ff_mdct_init ( & ac - > mdct , 11 , 1 , 1.0 ) ;
ff_mdct_init ( & ac - > mdct , 11 , 1 , 1.0 / 1024.0 ) ;
ff_mdct_init ( & ac - > mdct_small , 8 , 1 , 1.0 ) ;
ff_mdct_init ( & ac - > mdct_small , 8 , 1 , 1.0 / 128.0 ) ;
ff_mdct_init ( & ac - > mdct_ltp , 11 , 0 , 1 .0) ;
ff_mdct_init ( & ac - > mdct_ltp , 11 , 0 , - 2 .0) ;
// window initialization
// window initialization
ff_kbd_window_init ( ff_aac_kbd_long_1024 , 4.0 , 1024 ) ;
ff_kbd_window_init ( ff_aac_kbd_long_1024 , 4.0 , 1024 ) ;
ff_kbd_window_init ( ff_aac_kbd_short_128 , 6.0 , 128 ) ;
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 ;
int sfb ;
ltp - > lag = get_bits ( gb , 11 ) ;
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 + + )
for ( sfb = 0 ; sfb < FFMIN ( max_sfb , MAX_LTP_LONG_SFB ) ; sfb + + )
ltp - > used [ sfb ] = get_bits1 ( gb ) ;
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 ] ,
enum BandType band_type [ 120 ] ,
int band_type_run_end [ 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 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 ;
int noise_flag = 1 ;
static const char * sf_str [ 3 ] = { " Global gain " , " Noise gain " , " Intensity stereo position " } ;
static const char * sf_str [ 3 ] = { " Global gain " , " Noise gain " , " Intensity stereo position " } ;
for ( g = 0 ; g < ics - > num_window_groups ; g + + ) {
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 ) ) {
} else if ( ( band_type [ idx ] = = INTENSITY_BT ) | | ( band_type [ idx ] = = INTENSITY_BT2 ) ) {
for ( ; i < run_end ; i + + , idx + + ) {
for ( ; i < run_end ; i + + , idx + + ) {
offset [ 2 ] + = get_vlc2 ( gb , vlc_scalefactors . table , 7 , 3 ) - 60 ;
offset [ 2 ] + = get_vlc2 ( gb , vlc_scalefactors . table , 7 , 3 ) - 60 ;
if ( offset [ 2 ] > 255U ) {
clipped_offset = av_clip ( offset [ 2 ] , - 155 , 100 ) ;
av_log ( ac - > avctx , AV_LOG_ERROR ,
if ( offset [ 2 ] ! = clipped_offset ) {
" %s (%d) out of range. \n " , sf_str [ 2 ] , offset [ 2 ] ) ;
av_log_ask_for_sample ( ac - > avctx , " Intensity stereo "
return - 1 ;
" position clipped (%d -> %d). \n If 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 ) {
} else if ( band_type [ idx ] = = NOISE_BT ) {
for ( ; i < run_end ; i + + , idx + + ) {
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 ;
offset [ 1 ] + = get_bits ( gb , 9 ) - 256 ;
else
else
offset [ 1 ] + = get_vlc2 ( gb , vlc_scalefactors . table , 7 , 3 ) - 60 ;
offset [ 1 ] + = get_vlc2 ( gb , vlc_scalefactors . table , 7 , 3 ) - 60 ;
if ( offset [ 1 ] > 255U ) {
clipped_offset = av_clip ( offset [ 1 ] , - 100 , 155 ) ;
av_log ( ac - > avctx , AV_LOG_ERROR ,
if ( offset [ 2 ] ! = clipped_offset ) {
" %s (%d) out of range. \n " , sf_str [ 1 ] , offset [ 1 ] ) ;
av_log_ask_for_sample ( ac - > avctx , " Noise gain clipped "
return - 1 ;
" (%d -> %d). \n If 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 {
} else {
for ( ; i < run_end ; i + + , idx + + ) {
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 ] ) ;
" %s (%d) out of range. \n " , sf_str [ 0 ] , offset [ 0 ] ) ;
return - 1 ;
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 ,
static av_always_inline void predict ( PredictorState * ps , float * coef ,
float sf_scale , float inv_sf_scale ,
int output_enable )
int output_enable )
{
{
const float a = 0.953125 ; // 61.0 / 64
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 ) ;
pv = flt16_round ( k1 * r0 + k2 * r1 ) ;
if ( output_enable )
if ( output_enable )
* coef + = pv * sf_scale ;
* coef + = pv ;
e0 = * coef * inv_sf_scale ;
e0 = * coef ;
e1 = e0 - k1 * r0 ;
e1 = e0 - k1 * r0 ;
ps - > cor1 = flt16_trunc ( alpha * cor1 + r1 * e1 ) ;
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 )
static void apply_prediction ( AACContext * ac , SingleChannelElement * sce )
{
{
int sfb , k ;
int sfb , k ;
float sf_scale = ac - > sf_scale , inv_sf_scale = 1 / ac - > sf_scale ;
if ( ! sce - > ics . predictor_initialized ) {
if ( ! sce - > ics . predictor_initialized ) {
reset_all_predictors ( sce - > predictor_state ) ;
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 ( 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 + + ) {
for ( k = sce - > ics . swb_offset [ sfb ] ; k < sce - > ics . swb_offset [ sfb + 1 ] ; k + + ) {
predict ( & sce - > predictor_state [ k ] , & sce - > coeffs [ k ] ,
predict ( & sce - > predictor_state [ k ] , & sce - > coeffs [ k ] ,
sf_scale , inv_sf_scale ,
sce - > ics . predictor_present & & sce - > ics . prediction_used [ sfb ] ) ;
sce - > ics . predictor_present & & sce - > ics . prediction_used [ sfb ] ) ;
}
}
}
}