@ -105,8 +105,8 @@ typedef struct ATRAC9Context {
DECLARE_ALIGNED ( 32 , float , temp ) [ 2048 ] ;
} ATRAC9Context ;
static VLC sf_vlc [ 2 ] [ 8 ] ; /* Signed/unsigned, length */
static VLC coeff_vlc [ 2 ] [ 8 ] [ 4 ] ; /* Cookbook, precision, cookbook index */
static const VLCElem * sf_vlc [ 2 ] [ 8 ] ; /* Signed/unsigned, length */
static const VLCElem * coeff_vlc [ 2 ] [ 8 ] [ 4 ] ; /* Cookbook, precision, cookbook index */
static inline int parse_gradient ( ATRAC9Context * s , ATRAC9BlockData * b ,
GetBitContext * gb )
@ -277,12 +277,12 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b,
const uint8_t * sf_weights = at9_tab_sf_weights [ get_bits ( gb , 3 ) ] ;
const int base = get_bits ( gb , 5 ) ;
const int len = get_bits ( gb , 2 ) + 3 ;
const VLC * tab = & sf_vlc [ 0 ] [ len ] ;
const VLCElem * tab = sf_vlc [ 0 ] [ len ] ;
c - > scalefactors [ 0 ] = get_bits ( gb , len ) ;
for ( int i = 1 ; i < b - > band_ext_q_unit ; i + + ) {
int val = c - > scalefactors [ i - 1 ] + get_vlc2 ( gb , tab - > table ,
int val = c - > scalefactors [ i - 1 ] + get_vlc2 ( gb , tab ,
ATRAC9_SF_VLC_BITS , 1 ) ;
c - > scalefactors [ i ] = val & ( ( 1 < < len ) - 1 ) ;
}
@ -310,10 +310,10 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b,
const int len = get_bits ( gb , 2 ) + 2 ;
const int unit_cnt = FFMIN ( b - > band_ext_q_unit , baseline_len ) ;
const VLC * tab = & sf_vlc [ 1 ] [ len ] ;
const VLCElem * tab = sf_vlc [ 1 ] [ len ] ;
for ( int i = 0 ; i < unit_cnt ; i + + ) {
int dist = get_vlc2 ( gb , tab - > table , ATRAC9_SF_VLC_BITS , 1 ) ;
int dist = get_vlc2 ( gb , tab , ATRAC9_SF_VLC_BITS , 1 ) ;
c - > scalefactors [ i ] = baseline [ i ] + dist ;
}
@ -331,12 +331,12 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b,
const int base = get_bits ( gb , 5 ) - ( 1 < < ( 5 - 1 ) ) ;
const int len = get_bits ( gb , 2 ) + 1 ;
const int unit_cnt = FFMIN ( b - > band_ext_q_unit , baseline_len ) ;
const VLC * tab = & sf_vlc [ 0 ] [ len ] ;
const VLCElem * tab = sf_vlc [ 0 ] [ len ] ;
c - > scalefactors [ 0 ] = get_bits ( gb , len ) ;
for ( int i = 1 ; i < unit_cnt ; i + + ) {
int val = c - > scalefactors [ i - 1 ] + get_vlc2 ( gb , tab - > table ,
int val = c - > scalefactors [ i - 1 ] + get_vlc2 ( gb , tab ,
ATRAC9_SF_VLC_BITS , 1 ) ;
c - > scalefactors [ i ] = val & ( ( 1 < < len ) - 1 ) ;
}
@ -418,12 +418,12 @@ static inline void read_coeffs_coarse(ATRAC9Context *s, ATRAC9BlockData *b,
if ( prec < = max_prec ) {
const int cb = c - > codebookset [ i ] ;
const int cbi = at9_q_unit_to_codebookidx [ i ] ;
const VLC * tab = & coeff_vlc [ cb ] [ prec ] [ cbi ] ;
const VLCElem * tab = coeff_vlc [ cb ] [ prec ] [ cbi ] ;
const HuffmanCodebook * huff = & at9_huffman_coeffs [ cb ] [ prec ] [ cbi ] ;
const int groups = bands > > huff - > value_cnt_pow ;
for ( int j = 0 ; j < groups ; j + + ) {
uint16_t val = get_vlc2 ( gb , tab - > table , ATRAC9_COEFF_VLC_BITS , 2 ) ;
uint16_t val = get_vlc2 ( gb , tab , ATRAC9_COEFF_VLC_BITS , 2 ) ;
for ( int k = 0 ; k < huff - > value_cnt ; k + + ) {
coeffs [ k ] = sign_extend ( val , huff - > value_bits ) ;
@ -841,33 +841,31 @@ static av_cold int atrac9_decode_close(AVCodecContext *avctx)
return 0 ;
}
static av_cold void atrac9_init_vlc ( VLC * vlc , int nb_bits , int nb_codes ,
const uint8_t ( * * tab ) [ 2 ] ,
unsigned * buf_offset , int offset )
static av_cold const VLCElem * atrac9_init_vlc ( VLCInitState * state ,
int nb_bits , int nb_codes ,
const uint8_t ( * * tab ) [ 2 ] , int offset )
{
static VLCElem vlc_buf [ 24812 ] ;
const uint8_t ( * table ) [ 2 ] = * tab ;
vlc - > table = & vlc_buf [ * buf_offset ] ;
vlc - > table_allocated = FF_ARRAY_ELEMS ( vlc_buf ) - * buf_offset ;
ff_vlc_init_from_lengths ( vlc , nb_bits , nb_codes ,
& ( * tab ) [ 0 ] [ 1 ] , 2 , & ( * tab ) [ 0 ] [ 0 ] , 2 , 1 ,
offset , VLC_INIT_STATIC_OVERLONG , NULL ) ;
* buf_offset + = vlc - > table_size ;
* tab + = nb_codes ;
return ff_vlc_init_tables_from_lengths ( state , nb_bits , nb_codes ,
& table [ 0 ] [ 1 ] , 2 , & table [ 0 ] [ 0 ] , 2 , 1 ,
offset , 0 ) ;
}
static av_cold void atrac9_init_static ( void )
{
static VLCElem vlc_buf [ 24812 ] ;
VLCInitState state = VLC_INIT_STATE ( vlc_buf ) ;
const uint8_t ( * tab ) [ 2 ] ;
unsigned offset = 0 ;
/* Unsigned scalefactor VLCs */
tab = at9_sfb_a_tab ;
for ( int i = 1 ; i < 7 ; i + + ) {
const HuffmanCodebook * hf = & at9_huffman_sf_unsigned [ i ] ;
atrac9_init_vlc ( & sf_vlc [ 0 ] [ i ] , ATRAC9_SF_VLC_BITS ,
hf - > size , & tab , & offset , 0 ) ;
sf_vlc [ 0 ] [ i ] = atrac9_init_vlc ( & state , ATRAC9_SF_VLC_BITS ,
hf - > size , & tab , 0 ) ;
}
/* Signed scalefactor VLCs */
@ -878,8 +876,8 @@ static av_cold void atrac9_init_static(void)
/* The symbols are signed integers in the range -16..15;
* the values in the source table are offset by 16 to make
* them fit into an uint8_t ; the - 16 reverses this shift . */
atrac9_init_vlc ( & sf_vlc [ 1 ] [ i ] , ATRAC9_SF_VLC_BITS ,
hf - > size , & tab , & offset , - 16 ) ;
sf_vlc [ 1 ] [ i ] = atrac9_init_vlc ( & state , ATRAC9_SF_VLC_BITS ,
hf - > size , & tab , - 16 ) ;
}
/* Coefficient VLCs */
@ -888,8 +886,8 @@ static av_cold void atrac9_init_static(void)
for ( int j = 2 ; j < 8 ; j + + ) {
for ( int k = i ; k < 4 ; k + + ) {
const HuffmanCodebook * hf = & at9_huffman_coeffs [ i ] [ j ] [ k ] ;
atrac9_init_vlc ( & coeff_vlc [ i ] [ j ] [ k ] , ATRAC9_COEFF_VLC_BITS ,
hf - > size , & tab , & offset , 0 ) ;
coeff_vlc [ i ] [ j ] [ k ] = atrac9_init_vlc ( & state , ATRAC9_COEFF_VLC_BITS ,
hf - > size , & tab , 0 ) ;
}
}
}