diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index bb774c73bc97972504d35cba3a75c49a71972624..2ad9dc88054636fee8eb4e3150691be45a048854 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3825,67 +3825,57 @@ void ivas_dirac_dec_compute_directional_responses( void ivas_dirac_dec_get_frequency_axis( float *frequency_axis, /* o : array of center frequencies of a real filter bank */ const int32_t output_Fs, /* i : sampling frequency */ - const int16_t num_freq_bands ); /* i : number of frequency bands */ + const int16_t num_freq_bands /* i : number of frequency bands */ +); void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */ float ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector, imaginary part */ - const float beta, /* i : forgetting factor for average filtering */ - const int16_t *band_grouping, /* i : indices of band groups */ - const int16_t N_bands, /* i : number of bands (groups) */ - const int16_t enc_param_start_band, /* i : first band to process */ - float *azi, /* o : array of sector azimuth angles, flat */ - float *ele, /* o : array of sector elevation angles, flat */ - float *diff, /* o : array of sector diffuseness values, flat */ - float *ene /* o : array of sector energy values, flat */ + const float beta, /* i : forgetting factor for average filtering */ + const int16_t *band_grouping, /* i : indices of band groups */ + const int16_t N_bands, /* i : number of bands (groups) */ + const int16_t enc_param_start_band, /* i : first band to process */ + float *azi, /* o : array of sector azimuth angles, flat */ + float *ele, /* o : array of sector elevation angles, flat */ + float *diff, /* o : array of sector diffuseness values, flat */ + float *ene /* o : array of sector energy values, flat */ ); void ivas_mc_paramupmix_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ - float data_f[][L_FRAME48k], /* i/o: input: CICP6, CICP12, CICP14, CICP16 or CICP19 MC data */ - const int16_t input_frame /* i : input frame length */ + Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ + float data_f[][L_FRAME48k], /* i/o: input: CICP6, CICP12, CICP14, CICP16 or CICP19 MC data */ + const int16_t input_frame /* i : input frame length */ ); ivas_error ivas_mc_paramupmix_enc_open( - Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); void ivas_mc_paramupmix_enc_close( - MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ - const int32_t sampling_rate + MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ + const int32_t input_Fs /* i : input sampling rate */ ); void ivas_mc_paramupmix_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - float output_f[][L_FRAME48k] /* i/o: synthesized core-coder transport channels/DirAC output */ -); - -#ifdef FIX_506_WARNINGS -int16_t ivas_mc_paramupmix_enc_getNumTransportChannels( - void -); -#else -int16_t ivas_mc_paramupmix_getNumTransportChannels( - void + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float output_f[][L_FRAME48k] /* i/o: synthesized core-coder transport channels/DirAC output */ ); -#endif ivas_error ivas_mc_paramupmix_dec_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); void ivas_mc_paramupmix_dec_close( - MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix_out /* i/o: Parametric MC decoder handle */ + MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix_out /* i/o: Parametric MC decoder handle */ ); void ivas_mc_paramupmix_dec_read_BS( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - Decoder_State *st, /* i/o: decoder state structure */ - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ - int16_t *nb_bits /* o : number of bits written */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_State *st, /* i/o: decoder state structure */ + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ + int16_t *nb_bits /* o : number of bits written */ ); void ivas_param_mc_metadata_open( diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 6d1482d5f65caed7d598640b9aae9828fd9918be..0368b1970081ae2b7e558f0279af5fdce1db0677 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2523,6 +2523,17 @@ const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_ }; +/*----------------------------------------------------------------------------------* + * Parametric Upmix MC ROM tables + *----------------------------------------------------------------------------------*/ + +const int16_t ivas_param_upmx_mx_qmap[2][33] = +{ + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, + { 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0 } +}; + + /*----------------------------------------------------------------------------------* * MASA ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index ed3ffa6c0892158c271296e7234a2e491b28f53c..8dc958e06c9a0e3ff3c3c37add4c722a0a719888 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -261,6 +261,13 @@ extern const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PA extern const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; +/*----------------------------------------------------------------------------------* + * Parametric Upmix MC ROM tables + *----------------------------------------------------------------------------------*/ + +extern const int16_t ivas_param_upmx_mx_qmap[2][33]; + + /*----------------------------------------------------------------------------------* * MASA ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index e53e11037ed80cc1580042b7e762b847ca3aacee..fb1b367767832901b890a4eba39116f58a86f1f8 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -496,7 +496,7 @@ ivas_error ivas_dec( { ivas_lfe_dec( st_ivas->hLFE, st, output_frame, st_ivas->bfi, output_lfe_ch ); - ivas_mc_paramupmix_dec_read_BS( ivas_total_brate, st, st_ivas, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] ); + ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] ); if ( ( error = ivas_mct_dec( st_ivas, output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index c53fb5280cb0c4858d9ade9fa266bf7d4f30b5b9..6447c2f45607a216fb032c61dcc68c50796b8bc7 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -52,23 +52,21 @@ /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ -static void ps_pred_process( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, float qmf_mod_re[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_mod_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_side_re[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_side_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], int16_t ch ); + +static void ps_pred_process( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, float qmf_mod_re[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_mod_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_side_re[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_side_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], const int16_t ch ); static void paramupmix_td_decorr_process( ivas_td_decorr_state_t *hTdDecorr[], float pcm_in[][L_FRAME48k], float **pp_out_pcm, const int16_t output_frame ); static int huff_read( Decoder_State *st, const int16_t ( *ht )[2] ); -static void huffman_decode( Decoder_State *st, int16_t nv, int16_t ivStart, PAR_TYPE parType, QUANT_TYPE quant_type, int16_t bNoDt, int32_t *vq ); +static void huffman_decode( Decoder_State *st, const int16_t nv, const int16_t ivStart, PAR_TYPE parType, QUANT_TYPE quant_type, const int16_t bNoDt, int32_t *vq ); -static void dequant_alpha( int16_t nv, int16_t ivStart, QUANT_TYPE quant_type, int32_t *vq, float *v ); +static void dequant_alpha( const int16_t nv, const int16_t ivStart, const QUANT_TYPE quant_type, int32_t *vq, float *v ); -static void dequant_beta( int16_t nv, int16_t ivStart, QUANT_TYPE quant_type, int32_t *aq, int32_t *bq, float *beta ); +static void dequant_beta( const int16_t nv, const int16_t ivStart, const QUANT_TYPE quant_type, int32_t *aq, int32_t *bq, float *beta ); -static void get_ec_data( Decoder_State *st, PAR_TYPE parType, QUANT_TYPE quant_type, int16_t nParBand, int16_t parBandStart, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] ); +static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, const QUANT_TYPE quant_type, const int16_t nParBand, const int16_t parBandStart, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] ); -#ifdef FIX_506_WARNINGS -static int16_t ivas_mc_paramupmix_dec_getNumTransportChannels( void ); -#endif /*------------------------------------------------------------------------- * ivas_mc_paramupmix_dec_read_BS() @@ -77,11 +75,10 @@ static int16_t ivas_mc_paramupmix_dec_getNumTransportChannels( void ); *------------------------------------------------------------------------*/ void ivas_mc_paramupmix_dec_read_BS( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - Decoder_State *st, /* i/o: decoder state structure */ - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ - int16_t *nb_bits /* o : number of bits written */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_State *st0, /* i/o: decoder state structure */ + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ + int16_t *nb_bits /* o : number of bits written */ ) { int16_t i, k; @@ -93,7 +90,7 @@ void ivas_mc_paramupmix_dec_read_BS( push_wmops( "mc_paramupmix_read_bs" ); *nb_bits = 0; - if ( st->bfi ) + if ( st0->bfi ) { for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { @@ -107,31 +104,31 @@ void ivas_mc_paramupmix_dec_read_BS( } else /* if (!st->bfi) */ { - bit_stream_orig = st->bit_stream; - next_bit_pos_orig = st->next_bit_pos; - last_bit_pos = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); + bit_stream_orig = st0->bit_stream; + next_bit_pos_orig = st0->next_bit_pos; + last_bit_pos = (int16_t) ( ( st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 ); nb_bits_read_orig = 0; last_bit_pos -= nb_bits_read_orig; /* reverse the bitstream for easier reading of indices */ for ( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ ) { bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i]; } - st->bit_stream = bstr_meta; - st->next_bit_pos = 0; - st->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 ); - st->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ + st0->bit_stream = bstr_meta; + st0->next_bit_pos = 0; + st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 ); + st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { - get_ec_data( st, ALPHA, FINE /*quant_type*/, IVAS_MAX_NUM_BANDS /*nParBand*/, + get_ec_data( st0, ALPHA, FINE /*quant_type*/, IVAS_MAX_NUM_BANDS /*nParBand*/, 0 /*parBandStart*/, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i] ); - get_ec_data( st, BETA, FINE /*quant_type*/, IVAS_MAX_NUM_BANDS /*nParBand*/, + get_ec_data( st0, BETA, FINE /*quant_type*/, IVAS_MAX_NUM_BANDS /*nParBand*/, 0 /*parBandStart*/, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i] ); } - *nb_bits += st->next_bit_pos; - st->bit_stream = bit_stream_orig; - st->next_bit_pos = next_bit_pos_orig; + *nb_bits += st0->next_bit_pos; + st0->bit_stream = bit_stream_orig; + st0->next_bit_pos = next_bit_pos_orig; if ( hMCParamUpmix->first_frame ) { @@ -149,14 +146,16 @@ void ivas_mc_paramupmix_dec_read_BS( return; } + /*------------------------------------------------------------------------- * ivas_mc_paramupmix_dec() * * MC ParamUpmix decoding process *------------------------------------------------------------------------*/ + void ivas_mc_paramupmix_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - float output_f[][L_FRAME48k] /* i/o: synthesized core-coder transport channels */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float output_f[][L_FRAME48k] /* i/o: synthesized core-coder transport channels */ ) { MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; @@ -292,19 +291,6 @@ void ivas_mc_paramupmix_dec( return; } -#ifndef FIX_506_WARNINGS -/*------------------------------------------------------------------------- - * ivas_mc_paramupmix_getNumTransportChannels() - * - * - *------------------------------------------------------------------------*/ -int16_t ivas_mc_paramupmix_getNumTransportChannels() -{ - int16_t nchan_transport; - nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; /* 5.1.2 */ - return nchan_transport; -} -#endif /*------------------------------------------------------------------------- * ivas_mc_paramupmix_dec_open() @@ -334,11 +320,7 @@ ivas_error ivas_mc_paramupmix_dec_open( } output_Fs = st_ivas->hDecoderConfig->output_Fs; hMCParamUpmix->first_frame = 1; -#ifdef FIX_506_WARNINGS - st_ivas->nchan_transport = ivas_mc_paramupmix_dec_getNumTransportChannels(); -#else - st_ivas->nchan_transport = ivas_mc_paramupmix_getNumTransportChannels(); -#endif + st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; nchan_transport = st_ivas->nchan_transport; switch ( nchan_transport ) @@ -353,6 +335,7 @@ ivas_error ivas_mc_paramupmix_dec_open( assert( 0 && "Number of TC not supported for MC ParamUpmix!" ); #endif } + /*-----------------------------------------------------------------* * set input parameters *-----------------------------------------------------------------*/ @@ -378,6 +361,7 @@ ivas_error ivas_mc_paramupmix_dec_open( return error; } + /*------------------------------------------------------------------------- * ivas_mc_paramupmix_dec_close() * @@ -412,6 +396,7 @@ void ivas_mc_paramupmix_dec_close( return; } + /*****************************************************************************************/ /* local functions */ /*****************************************************************************************/ @@ -422,7 +407,7 @@ static void ps_pred_process( float qmf_mod_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float qmf_side_re[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* in/out */ float qmf_side_im[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - int16_t ch ) + const int16_t ch ) { float vmre, vmim, vsre, vsim; int16_t iqmf, ipar, ismp, iismp; @@ -432,7 +417,7 @@ static void ps_pred_process( float *alpha_prev = hMCParamUpmix->alpha_prev[ch]; float *beta_prev = hMCParamUpmix->beta_prev[ch]; - int16_t qmf_to_par_band[] = { + const int16_t qmf_to_par_band[] = { 0, 1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, @@ -475,8 +460,11 @@ static void ps_pred_process( alpha1 = alpha2; beta1 = beta2; } + + return; } + static void paramupmix_td_decorr_process( ivas_td_decorr_state_t *hTdDecorr[], /* i/o: SPAR Covar. decoder handle */ float pcm_in[][L_FRAME48k], /* i : input audio channels */ @@ -523,6 +511,7 @@ static void paramupmix_td_decorr_process( return; } + static int huff_read( Decoder_State *st, const int16_t ( *ht )[2] ) @@ -540,19 +529,19 @@ static int huff_read( return -( node + 1 ); } + static void huffman_decode( Decoder_State *st, - int16_t nv, - int16_t ivStart, - PAR_TYPE parType, - QUANT_TYPE quant_type, - int16_t bNoDt, + const int16_t nv, + const int16_t ivStart, + const PAR_TYPE parType, + const QUANT_TYPE quant_type, + const int16_t bNoDt, int32_t *vq ) { const int16_t( *huff_node_table )[2]; int16_t iv, bdt, nquant, offset; - nquant = 0; switch ( parType ) { @@ -577,6 +566,7 @@ static void huffman_decode( bdt = st->bit_stream[st->next_bit_pos]; st->next_bit_pos++; } + if ( bdt ) { /* Get dt */ switch ( parType ) @@ -629,12 +619,15 @@ static void huffman_decode( vq[iv] = huff_read( st, huff_node_table ) + vq[iv - 1] - offset; } } + + return; } + static void dequant_alpha( - int16_t nv, - int16_t ivStart, - QUANT_TYPE quant_type, + const int16_t nv, + const int16_t ivStart, + const QUANT_TYPE quant_type, int32_t *vq, float *v ) { @@ -650,22 +643,21 @@ static void dequant_alpha( { v[iv] = quant_table->data[vq[iv]]; } + + return; } + static void dequant_beta( - int16_t nv, - int16_t ivStart, - QUANT_TYPE quant_type, + const int16_t nv, + const int16_t ivStart, + const QUANT_TYPE quant_type, int32_t *aq, int32_t *bq, float *beta ) { int16_t iv; ACPL_QUANT_TABLE *quant_table; - const int16_t qmap[2][33] = { - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, - { 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0 } - }; for ( iv = 0; iv < ivStart; iv++ ) { @@ -674,22 +666,26 @@ static void dequant_beta( for ( iv = ivStart; iv < nv; iv++ ) { - quant_table = &beta_quant_table[quant_type][qmap[quant_type][aq[iv]]]; + quant_table = &beta_quant_table[quant_type][ivas_param_upmx_mx_qmap[quant_type][aq[iv]]]; beta[iv] = quant_table->data[bq[iv]]; } + + return; } + static void get_ec_data( Decoder_State *st, - PAR_TYPE parType, - QUANT_TYPE quant_type, - int16_t nParBand, - int16_t parBandStart, + const PAR_TYPE parType, + const QUANT_TYPE quant_type, + const int16_t nParBand, + const int16_t parBandStart, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] ) { huffman_decode( st, nParBand, parBandStart, parType, quant_type, 0, parQ ); + if ( parType == ALPHA ) { dequant_alpha( nParBand, parBandStart, quant_type, parQ, ab ); @@ -699,18 +695,6 @@ static void get_ec_data( { dequant_beta( nParBand, parBandStart, quant_type, alphaQEnv, parQ, ab ); } -} -#ifdef FIX_506_WARNINGS -/*------------------------------------------------------------------------- - * ivas_mc_paramupmix_getNumTransportChannels() - * - * - *------------------------------------------------------------------------*/ -static int16_t ivas_mc_paramupmix_dec_getNumTransportChannels( void ) -{ - int16_t nchan_transport; - nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; /* 5.1.2 */ - return nchan_transport; + return; } -#endif diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index ba2b88648331347876bfcef766813deb7c8b345d..9a82da9a270bfa54a44b100897523326cb730126 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -673,8 +673,7 @@ static void ivas_param_mc_param_est_enc( for ( ts = 0; ts < start_ts; ts++ ) { - ivas_fb_mixer_update_prior_input( hParamMC->hFbMixer, pcm_in, l_ts, - hParamMC->hFbMixer->fb_cfg->num_in_chans ); + ivas_fb_mixer_update_prior_input( hParamMC->hFbMixer, pcm_in, l_ts, hParamMC->hFbMixer->fb_cfg->num_in_chans ); for ( i = 0; i < nchan_input; i++ ) { pcm_in[i] += l_ts; diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index 35439bc02bcc53f287ee788c7f9dd3f05c388af8..f29b152838a0142c56818f62a9507ad7999010ce 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -57,19 +57,20 @@ static void ivas_mc_paramupmix_dmx( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, floa static void ivas_mc_paramupmix_param_est_enc( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, float input_frame_t[][L_FRAME48k], const int16_t input_frame, float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] ); -static void get_huff_table( PAR_TYPE par_type, QUANT_TYPE quant_type, HUFF_TAB *df0, HUFF_TAB *df, HUFF_TAB *dt ); +static void get_huff_table( const PAR_TYPE par_type, const QUANT_TYPE quant_type, HUFF_TAB *df0, HUFF_TAB *df, HUFF_TAB *dt ); -static void write_huff_bits( int32_t value, uint16_t length, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ); +static void write_huff_bits( const int32_t value, const uint16_t length, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ); -static void huffman_encode( int16_t bdfOnly, int16_t bdtAllowed, int16_t nv, int16_t ivStart, int32_t *vqPrev, int32_t *vq, PAR_TYPE parType, QUANT_TYPE quant_type, int16_t nq, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ); +static void huffman_encode( const int16_t bdfOnly, const int16_t bdtAllowed, const int16_t nv, const int16_t ivStart, const int32_t *vqPrev, const int32_t *vq, const PAR_TYPE parType, const QUANT_TYPE quant_type, const int16_t nq, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ); -static void put_ec_data( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, int16_t ch, float pars[IVAS_MAX_NUM_BANDS], float alphas[IVAS_MAX_NUM_BANDS], PAR_TYPE parType, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ); +static void put_ec_data( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, const int16_t ch, const float pars[IVAS_MAX_NUM_BANDS], const float alphas[IVAS_MAX_NUM_BANDS], const PAR_TYPE parType, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ); -static void quantize_alpha( int16_t nv, const float *alpha, QUANT_TYPE quant_type, int16_t *pnq, int32_t aq[IVAS_MAX_NUM_BANDS], float *adeq ); +static void quantize_alpha( const int16_t nv, const float *alpha, const QUANT_TYPE quant_type, int16_t *pnq, int32_t aq[IVAS_MAX_NUM_BANDS], float *adeq ); -static void quantize_pars( int16_t nv, const float *v, int16_t nq, const float *data, int32_t vq[IVAS_MAX_NUM_BANDS], float *vdeq ); +static void quantize_pars( const int16_t nv, const float *v, const int16_t nq, const float *data, int32_t vq[IVAS_MAX_NUM_BANDS], float *vdeq ); + +static void quantize_pars( const int16_t nv, const float *v, const int16_t nq, const float *data, int32_t vq[IVAS_MAX_NUM_BANDS], float *vdeq ); -static void quantize_pars( int16_t nv, const float *v, int16_t nq, const float *data, int32_t vq[IVAS_MAX_NUM_BANDS], float *vdeq ); /*------------------------------------------------------------------------- * ivas_mc_paramupmix_enc() @@ -78,10 +79,10 @@ static void quantize_pars( int16_t nv, const float *v, int16_t nq, const float * *------------------------------------------------------------------------*/ void ivas_mc_paramupmix_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ - BSTR_ENC_HANDLE hBStr, /* i/o: IVAS Metadata bitstream handle */ - float data_f[][L_FRAME48k], /* i/o: input: CICP6, CICP12, CICP14, CICP16 or CICP19 MC data */ - const int16_t input_frame /* i : input frame length */ + Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ + BSTR_ENC_HANDLE hBStr, /* i/o: IVAS Metadata bitstream handle */ + float data_f[][L_FRAME48k], /* i/o: input: CICP6, CICP12, CICP14, CICP16 or CICP19 MC data */ + const int16_t input_frame /* i : input frame length */ ) { MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix; @@ -116,6 +117,7 @@ void ivas_mc_paramupmix_enc( return; } + /*------------------------------------------------------------------------- * ivas_mc_paramupmix_enc_open() * @@ -172,7 +174,6 @@ ivas_error ivas_mc_paramupmix_enc_open( #endif } - /* Transient Detector handle */ for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) { @@ -188,6 +189,7 @@ ivas_error ivas_mc_paramupmix_enc_open( { return error; } + fb_cfg->remix_order = mc_paramupmix_fb_remix_order; /* override latency, could be moved to ivas_fb_set_cfg */ /* assuming parameters are calculated at end of frame, compensate for MCT delay and half of decoder fb */ @@ -211,7 +213,6 @@ ivas_error ivas_mc_paramupmix_enc_open( } } - for ( b = 0; b < MC_PARAMUPMIX_COMBINATIONS; b++ ) { if ( ( hMCParamUpmix->cov_real[b] = (float ***) malloc( MC_PARAMUPMIX_NCH * sizeof( float ** ) ) ) == NULL ) @@ -258,6 +259,7 @@ ivas_error ivas_mc_paramupmix_enc_open( return error; } + /*------------------------------------------------------------------------- * ivas_mc_paramupmix_enc_close() * @@ -265,8 +267,9 @@ ivas_error ivas_mc_paramupmix_enc_open( *------------------------------------------------------------------------*/ void ivas_mc_paramupmix_enc_close( - MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ - const int32_t sampling_rate ) + MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ + const int32_t input_Fs /* i : input sampling rate */ +) { int16_t i, k; int16_t b, j; @@ -275,6 +278,7 @@ void ivas_mc_paramupmix_enc_close( { return; } + for ( b = 0; b < MC_PARAMUPMIX_COMBINATIONS; b++ ) { if ( ( *hMCParamUpmix )->cov_real[b] != NULL ) @@ -295,6 +299,7 @@ void ivas_mc_paramupmix_enc_close( } free( ( *hMCParamUpmix )->cov_real[b] ); } + if ( ( *hMCParamUpmix )->cov_dtx_real[b] != NULL ) { for ( i = 0; i < MC_PARAMUPMIX_NCH; i++ ) @@ -330,7 +335,7 @@ void ivas_mc_paramupmix_enc_close( if ( ( *hMCParamUpmix )->hFbMixer != NULL ) { - ivas_FB_mixer_close( &( *hMCParamUpmix )->hFbMixer, sampling_rate, 0 ); + ivas_FB_mixer_close( &( *hMCParamUpmix )->hFbMixer, input_Fs, 0 ); } for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) @@ -344,37 +349,18 @@ void ivas_mc_paramupmix_enc_close( free( *hMCParamUpmix ); *hMCParamUpmix = NULL; - return; -} - -/*------------------------------------------------------------------------- - * ivas_mc_paramupmix_getNumTransportChannels() - * - * - *------------------------------------------------------------------------*/ - -/* r : number of IVAS transport channels */ -#ifdef FIX_506_WARNINGS -int16_t ivas_mc_paramupmix_enc_getNumTransportChannels( void ) -#else -int16_t ivas_mc_paramupmix_getNumTransportChannels() -#endif -{ - int16_t nchan_transport; - - /* LFE not included */ - nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS - 1; /*5_1_2*/ - return nchan_transport; + return; } /*****************************************************************************************/ /* local functions */ /*****************************************************************************************/ + static void get_huff_table( - PAR_TYPE par_type, - QUANT_TYPE quant_type, + const PAR_TYPE par_type, + const QUANT_TYPE quant_type, HUFF_TAB *df0, HUFF_TAB *df, HUFF_TAB *dt ) @@ -398,31 +384,38 @@ static void get_huff_table( dt->length = huff_beta_table[quant_type].dt.length; break; } + + return; } + static void write_huff_bits( - int32_t value, - uint16_t length, + const int32_t value, + const uint16_t length, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ) { int16_t k; + for ( k = length - 1; k >= 0; k-- ) { bit_buffer[( *bit_pos )++] = (uint16_t) ( ( value >> k ) & 1 ); } + + return; } + static void huffman_encode( - int16_t bdfOnly, - int16_t bdtAllowed, - int16_t nv, - int16_t ivStart, - int32_t *vqPrev, - int32_t *vq, - PAR_TYPE parType, - QUANT_TYPE quant_type, - int16_t nq, + const int16_t bdfOnly, + const int16_t bdtAllowed, + const int16_t nv, + const int16_t ivStart, + const int32_t *vqPrev, + const int32_t *vq, + const PAR_TYPE parType, + const QUANT_TYPE quant_type, + const int16_t nq, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ) { @@ -484,19 +477,24 @@ static void huffman_encode( for ( iv = ivStart; iv < nv; iv++ ) { icode = vq[iv] - vqPrev[iv] + offset; +#ifdef DEBUGGING if ( icode < 0 || icode >= 2 * nq - 1 ) { assert( 0 ); } +#endif write_huff_bits( dt.value[icode], dt.length[icode], bit_buffer, bit_pos ); } } + + return; } + static void quantize_pars( - int16_t nv, + const int16_t nv, const float *v, - int16_t nq, + const int16_t nq, const float *data, int32_t vq[IVAS_MAX_NUM_BANDS], float *vdeq ) @@ -532,12 +530,15 @@ static void quantize_pars( vdeq[iv] = data[iq1]; } } + + return; } + static void quantize_alpha( - int16_t nv, + const int16_t nv, const float *alpha, - QUANT_TYPE quant_type, + const QUANT_TYPE quant_type, int16_t *pnq, int32_t aq[IVAS_MAX_NUM_BANDS], float *adeq ) @@ -551,13 +552,16 @@ static void quantize_alpha( quantize_pars( nv, alpha, nq, data, aq, adeq ); *pnq = nq; + + return; } + static void quantize_beta( - int16_t nv, + const int16_t nv, const float *beta, const int32_t aq[IVAS_MAX_NUM_BANDS], - QUANT_TYPE quant_type, + const QUANT_TYPE quant_type, int16_t *pnq, int32_t bq[IVAS_MAX_NUM_BANDS], float *bdeq ) @@ -565,11 +569,10 @@ static void quantize_beta( int16_t iv, iq, iq0, iq1; ACPL_QUANT_TABLE *tables = beta_quant_table[quant_type]; ACPL_QUANT_TABLE quant_table; - const int16_t qmap[2][33] = { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, - { 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0 } }; + for ( iv = 0; iv < nv; iv++ ) { - quant_table = tables[qmap[quant_type][aq[iv]]]; + quant_table = tables[ivas_param_upmx_mx_qmap[quant_type][aq[iv]]]; iq0 = 0; iq1 = quant_table.nquant - 1; @@ -600,14 +603,17 @@ static void quantize_beta( } *pnq = beta_quant_table[quant_type][0].nquant; + + return; } + static void put_ec_data( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, - int16_t ch, - float pars[IVAS_MAX_NUM_BANDS], - float alphas[IVAS_MAX_NUM_BANDS], - PAR_TYPE parType, + const int16_t ch, + const float pars[IVAS_MAX_NUM_BANDS], + const float alphas[IVAS_MAX_NUM_BANDS], + const PAR_TYPE parType, uint16_t bit_buffer[MC_PARAMUPMIX_MAX_BITS], int16_t *bit_pos ) { @@ -629,6 +635,7 @@ static void put_ec_data( quantize_alpha( npar, alphas, quant_type, &nq, alphaQuant, alphaDequant ); quantize_beta( npar, pars, alphaQuant, quant_type, &nq, betaQuant, betaDequant ); } + if ( hMCParamUpmix->first_frame ) { mvl2l( &( alphaQuant[0] ), &( hMCParamUpmix->alpha_quant_prev[ch][0] ), IVAS_MAX_NUM_BANDS ); @@ -660,8 +667,11 @@ static void put_ec_data( { mvl2l( betaQuant, hMCParamUpmix->beta_quant_prev[ch], IVAS_MAX_NUM_BANDS ); } + + return; } + /*------------------------------------------------------------------------- * ivas_mc_paramupmix_dmx() * @@ -670,15 +680,15 @@ static void put_ec_data( static void ivas_mc_paramupmix_dmx( MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, /* i/o: MC ParamUpmix encoder handle */ - float data_f[][L_FRAME48k], /* i/o : Input, downmix out */ + float data_f[][L_FRAME48k], /* i/o: Input, downmix out */ const int16_t input_frame /* i : Input frame length */ ) { int16_t i, l; - int16_t chan1s[4] = { 4, 5, 8, 9 }; - int16_t chan2s[4] = { 6, 7, 10, 11 }; - int16_t chanOut[4] = { 4, 5, 6, 7 }; - int16_t chanZero[4] = { 8, 9, 10, 11 }; + const int16_t chan1s[4] = { 4, 5, 8, 9 }; + const int16_t chan2s[4] = { 6, 7, 10, 11 }; + const int16_t chanOut[4] = { 4, 5, 6, 7 }; + const int16_t chanZero[4] = { 8, 9, 10, 11 }; /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */ /* 9+11 -> 7 */ @@ -690,16 +700,18 @@ static void ivas_mc_paramupmix_dmx( for ( l = 0; l < input_frame; l++ ) { /* mid */ - hMCParamUpmix->midside[i][0][l] = ( data_f[chan1s[i]][l] + data_f[chan2s[i]][l] ) * (float) 0.5; + hMCParamUpmix->midside[i][0][l] = ( data_f[chan1s[i]][l] + data_f[chan2s[i]][l] ) * 0.5f; /* side */ - hMCParamUpmix->midside[i][1][l] = ( data_f[chan1s[i]][l] - data_f[chan2s[i]][l] ) * (float) 0.5; + hMCParamUpmix->midside[i][1][l] = ( data_f[chan1s[i]][l] - data_f[chan2s[i]][l] ) * 0.5f; data_f[chanOut[i]][l] = hMCParamUpmix->midside[i][0][l]; } } + for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { set_zero( data_f[chanZero[i]], input_frame ); } + return; } @@ -712,7 +724,7 @@ static void ivas_mc_paramupmix_dmx( *------------------------------------------------------------------------*/ static void ivas_mc_paramupmix_param_est_enc( - MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ + MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ float input_frame_t[][L_FRAME48k], /* i : Input frame in the time domain */ const int16_t input_frame, /* i : Input frame length */ float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS], @@ -819,14 +831,14 @@ static void ivas_mc_paramupmix_param_est_enc( rxy = hMCParamUpmix->cov_real[b][1][0][bnd]; ryy = hMCParamUpmix->cov_real[b][1][1][bnd]; cmat = rxy / ( ryy + EPSILON ); - alphas[b][bnd] = (float) 2.0 * cmat - (float) 1.0; + alphas[b][bnd] = 2.0f * cmat - 1.0f; rxx = hMCParamUpmix->cov_real[b][0][0][bnd]; rxxest = cmat * cmat * ryy; drxx = rxx - rxxest; - drxx = (float) max( drxx, 0.0 ); - wetaux = (float) sqrt( drxx / ( ryy + EPSILON ) ); - betas[b][bnd] = (float) 2.0 * wetaux; + drxx = max( drxx, 0.0f ); + wetaux = sqrtf( drxx / ( ryy + EPSILON ) ); + betas[b][bnd] = 2.0f * wetaux; } } if ( maxbands < IVAS_MAX_NUM_BANDS ) @@ -835,8 +847,8 @@ static void ivas_mc_paramupmix_param_est_enc( { for ( bnd = maxbands; bnd < IVAS_MAX_NUM_BANDS; bnd++ ) { - alphas[b][bnd] = 0.0; - betas[b][bnd] = 0.0; + alphas[b][bnd] = 0.0f; + betas[b][bnd] = 0.0f; } } } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 3daae0a87744351bcc3e06438794118eb8f1b980..5fb0561797102fdb98f085866e34e37f983c917c 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -315,11 +315,7 @@ ivas_error create_mct_enc( } else if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) { -#ifdef FIX_506_WARNINGS - hMCT->nchan_out_woLFE = ivas_mc_paramupmix_enc_getNumTransportChannels(); -#else - hMCT->nchan_out_woLFE = ivas_mc_paramupmix_getNumTransportChannels(); -#endif + hMCT->nchan_out_woLFE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS - 1; } else if ( ivas_format == SBA_FORMAT ) { @@ -429,11 +425,7 @@ ivas_error mct_enc_reconfigure( } else if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) { -#ifdef FIX_506_WARNINGS - hMCT->nchan_out_woLFE = ivas_mc_paramupmix_enc_getNumTransportChannels(); -#else - hMCT->nchan_out_woLFE = ivas_mc_paramupmix_getNumTransportChannels(); -#endif + hMCT->nchan_out_woLFE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS - 1; } else if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) {