From a1475f7cd524bce56bad75c46a74beee6438f308 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Fri, 13 Dec 2024 12:27:48 +0200 Subject: [PATCH 1/7] Issue 1231 fix - align to Basop --- lib_com/ivas_cnst.h | 5 +++++ lib_com/options.h | 2 +- lib_dec/ivas_qmetadata_dec.c | 16 +++++++++++++++- lib_enc/ivas_qmetadata_enc.c | 8 +++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index db01bdfe89..8c5be1b706 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1141,7 +1141,12 @@ enum #define MASA_TRANSP_BITS 1 #define NO_BITS_MASA_ISM_NO_OBJ 2 + +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL +#define MASA2TOTAL_THR 0.9799999f +#else #define MASA2TOTAL_THR 0.98f +#endif #define BITS_MASA2TOTTAL_DCT0 6 #define STEP_M2T 0.1f #define MASA_HEADER_BITS 2 diff --git a/lib_com/options.h b/lib_com/options.h index 51db29c99c..e1d7a0f267 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -171,7 +171,7 @@ #define NONBE_FIX_1176_OSBA_REVERB_JBM_ASAN_ERROR /* Ericsson: Issue 1176, fix in TDREND_firfilt for subframes shorter than the filter length */ #define NONBE_1220_OMASA_JBM_BRATE_SW_FLUSH /* VA: issue 1220: fix bug in renderer flush in OMASA 1ISM JBM bitrate switching */ - +#define NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL /* Nokia: add fix for precision limitation in comparison with masa2total energy ratio threshold to be aligned with BASOP*/ /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index ef5da3cb5d..4df30297fd 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -4359,7 +4359,9 @@ void ivas_omasa_decode_masa_to_total( float q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS], dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; int16_t n_streams, len_stream; - +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + int32_t int_tmp; +#endif /* Setup coding parameters */ n_streams = 1; len_stream = nbands * nblocks; @@ -4414,6 +4416,10 @@ void ivas_omasa_decode_masa_to_total( { masa_to_total_energy_ratio[i][j] = max( 0.0f, q_dct_data[k] ); masa_to_total_energy_ratio[i][j] = min( 1.0f, masa_to_total_energy_ratio[i][j] ); +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + int_tmp = (int32_t) ( MASA_SUR_COH_PRECISION * masa_to_total_energy_ratio[i][j] ); + masa_to_total_energy_ratio[i][j] = (float) ( int_tmp * MASA_SUR_COH_THRESHOLD ); +#endif k++; } } @@ -4425,6 +4431,10 @@ void ivas_omasa_decode_masa_to_total( for ( j = 0; j < nbands; j++ ) { masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[0][j]; +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + int_tmp = (int32_t) ( MASA_SUR_COH_PRECISION * masa_to_total_energy_ratio[i][j] ); + masa_to_total_energy_ratio[i][j] = (float) ( int_tmp * MASA_SUR_COH_THRESHOLD ); +#endif } } } @@ -4436,6 +4446,10 @@ void ivas_omasa_decode_masa_to_total( for ( i = 0; i < nblocks; i++ ) { masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[i][0]; +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + int_tmp = (int32_t) ( MASA_SUR_COH_PRECISION * masa_to_total_energy_ratio[i][j] ); + masa_to_total_energy_ratio[i][j] = (float) ( int_tmp * MASA_SUR_COH_THRESHOLD ); +#endif } } } diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 562a4fa14e..d178cbf62c 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -6035,7 +6035,9 @@ void ivas_omasa_encode_masa_to_total( float dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; int16_t bits_pos, nb_bits; int16_t n_streams, len_stream; - +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + int32_t int_tmp; +#endif #ifdef DEBUG_MODE_QMETADATA static FILE *pF = NULL; static FILE *pF_ratio = NULL; @@ -6196,6 +6198,10 @@ void ivas_omasa_encode_masa_to_total( { masa_to_total_energy_ratio[i][j] = max( 0.0f, q_dct_data[k] ); masa_to_total_energy_ratio[i][j] = min( 1.0f, masa_to_total_energy_ratio[i][j] ); +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + int_tmp = (int32_t) ( MASA_SUR_COH_PRECISION * masa_to_total_energy_ratio[i][j] ); + masa_to_total_energy_ratio[i][j] = (float) ( int_tmp * MASA_SUR_COH_THRESHOLD ); +#endif k++; } } -- GitLab From 5ff54f093d76969e91041fa34eb42e626d674d33 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Mon, 3 Feb 2025 19:46:54 +0200 Subject: [PATCH 2/7] bring DCT_FX to FP --- lib_com/ivas_rom_com.c | 44 ++++++- lib_com/ivas_rom_com.h | 8 +- lib_com/ivas_tools.c | 245 +++++++++++++++++++++++++++++++++++ lib_dec/ivas_qmetadata_dec.c | 117 +++++++++++++++-- 4 files changed, 404 insertions(+), 10 deletions(-) diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 5f81d801f7..d7969f99c1 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2778,6 +2778,48 @@ const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = }; /* column wise DCT matrices for 4 5, and 8 dim */ +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL +const Word32 dct4_fx[4 * 4] = { // Q31 + 1073741824, 1402951040, 1073741824, 581109056, + 1073741824, 581109056, -1073741824, -1402951040, + 1073741824, -581109056, -1073741824, 1402951040, + 1073741824, -1402951040, 1073741824, -581109056 +}; + +const Word32 dct5_fx[5 * 5] = { // Q31 + 960354688, 1291711360, 1098867328, 798219648, 419618304, + 960354688, 798219648, -419618304, -1291711360, -1098867328, + 960354688, 0, -1358283392, 0, 1358283392, + 960354688, -798219648, -419618304, 1291711360, -1098867328, + 960354688, -1291711360, 1098867328, -798219648, 419618304 +}; + +const Word32 dct8_fx[8 * 8] = { // Q31 + 759350208, 1053125952, 991922688, 892708928, 759350208, 596570944, 410813632, 209379648, + 759350208, 892708928, 410813632, -209379648, -759350208, -1053125952, -991922688, -596570944, + 759350208, 596570944, -410813632, -1053125952, -759350208, 209379648, 991922688, 892708928, + 759350208, 209379648, -991922688, -596570944, 759350208, 892708928, -410813632, -1053125952, + 759350208, -209379648, -991922688, 596570944, 759350208, -892708928, -410813632, 1053125952, + 759350208, -596570944, -410813632, 1053125952, -759350208, -209379648, 991922688, -892708928, + 759350208, -892708928, 410813632, 209379648, -759350208, 1053125952, -991922688, 596570944, + 759350208, -1053125952, 991922688, -892708928, 759350208, -596570944, 410813632, -209379648 +}; + +const Word32 dct12_fx[12 * 12] = { // Q31 + 619978560, 869301376, 846752832, 810030848, 759350208, 695569984, 619978560, 533649696, 438301408, 335436960, 226989024, 114460880, + 619978560, 810030848, 619978560, 335436960, 0, -335436960, -619978560, -810030848, -876602816, -810030848, -619978560, -335436960, + 619978560, 695569984, 226989024, -335436960, -759350208, -869301376, -619978560, -114460880, 438301408, 810030848, 846752832, 533649696, + 619978560, 533649696, -226989024, -810030848, -759350208, -114460880, 619978560, 869301376, 438301408, -335436960, -846752832, -695569984, + 619978560, 335436960, -619978560, -810030848, 0, 810030848, 619978560, -335436960, -876602816, -335436960, 619978560, 810030848, 619978560, + 114460880, -846752832, -335436960, 759350208, 533649696, -619978560, -695569984, 438301408, 810030848, -226989024, -869301376, 619978560, + -114460880, -846752832, 335436960, 759350208, -533649696, -619978560, 695569984, 438301408, -810030848, -226989024, 869301376, 619978560, + -335436960, -619978560, 810030848, 0, -810030848, 619978560, 335436960, -876602816, 335436960, 619978560, -810030848, 619978560, -533649696, + -226989024, 810030848, -759350208, 114460880, 619978560, -869301376, 438301408, 335436960, -846752832, 695569984, 619978560, -695569984, + 226989024, 335436960, -759350208, 869301376, -619978560, 114460880, 438301408, -810030848, 846752832, -533649696, 619978560, -810030848, + 619978560, -335436960, 0, 335436960, -619978560, 810030848, -876602816, 810030848, -619978560, 335436960, 619978560, -869301376, 846752832, + -810030848, 759350208, -695569984, 619978560, -533649696, 438301408, -335436960, 226989024, -114460880 +}; +#else const float dct4[4*4] = { 0.5000f, 0.6533f, 0.5000f, 0.2706f, @@ -2822,7 +2864,7 @@ const float dct12[12*12]= 0.2887f, -0.3772f, 0.2887f, -0.1562f, -0.0000f, 0.1562f, -0.2887f, 0.3772f, -0.4082f, 0.3772f, -0.2887f, 0.1562f, 0.2887f, -0.4048f, 0.3943f, -0.3772f, 0.3536f, -0.3239f, 0.2887f, -0.2485f, 0.2041f, -0.1562f, 0.1057f, -0.0533f }; - +#endif /*----------------------------------------------------------------------------------* * ISM ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index c6c8250b03..f9a0075605 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -325,11 +325,17 @@ extern const float McMASA_LFEGain_vectors[64]; *----------------------------------------------------------------------------------*/ extern const int32_t sep_object_brate[][MAX_NUM_OBJECTS]; +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL +extern const Word32 dct4_fx[]; +extern const Word32 dct5_fx[]; +extern const Word32 dct8_fx[]; +extern const Word32 dct12_fx[]; +#else extern const float dct4[]; extern const float dct5[]; extern const float dct8[]; extern const float dct12[]; - +#endif /*----------------------------------------------------------------------------------* * ISM ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index f91dc214c8..bd02a9a5d2 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1274,3 +1274,248 @@ float rand_triangular_signed( return 0.5f - 0.5f * sqrtf( 1.0f - rand_val ); } } +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL +Word16 matrix_product_fx( + const Word32 *X_fx, /* i : left hand matrix Qx*/ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Qy*/ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication Qx + Qy - 31*/ +) +{ + Word16 i, j, k; + Word16 x_idx, y_idx; + Word32 *Zp_fx = Z_fx; + + /* Processing */ + + if( transpX == 1 && transpY == 0 ) /* We use X transpose */ + { + if( rowsX != rowsY ) + { + return EXIT_FAILURE; + } + for( j = 0; j < colsY; ++j ) + { + for( i = 0; i < colsX; ++i ) + { + ( *Zp_fx ) = 0; + + for( k = 0; k < rowsX; ++k ) + { + x_idx = k + i*rowsX; /*Q0*/ + y_idx = k + j*rowsY; /*Q0*/ + ( *Zp_fx ) = *Zp_fx + ( X_fx[x_idx] * Y_fx[y_idx] ); /*Qx + Qy - 31*/ + } + Zp_fx++; + } + } + } + else if( transpX == 0 && transpY == 1 ) /* We use Y transpose */ + { + if( colsX != colsY ) + { + return EXIT_FAILURE; + } + for( j = 0; j < rowsY; ++j ) + { + for( i = 0; i < rowsX; ++i ) + { + ( *Zp_fx ) = 0; + for( k = 0; k < colsX; ++k ) + { + x_idx = i + k*rowsX; /*Q0*/ + y_idx = j + k*rowsY; /*Q0*/ + ( *Zp_fx ) = (*Zp_fx) + ( X_fx[x_idx] * Y_fx[y_idx] ); /*Qx + Qy - 31*/ + } + Zp_fx++; + } + } + } + else if( transpX == 1 && transpY == 1 ) /* We use both transpose */ + { + if( rowsX != colsY ) + { + return EXIT_FAILURE; + } + for( j = 0; j < rowsY; ++j ) + { + for( i = 0; i < colsX; ++i ) + { + ( *Zp_fx ) = 0; + move32(); + for( k = 0; k < colsX; ++k ) + { + x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/ + y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/ + ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/ + move32(); + } + + Zp_fx++; + } + } + } + else /* Regular case */ + { + if( NE_16( colsX, rowsY ) ) + { + return EXIT_FAILURE; + } + + for( j = 0; j < colsY; ++j ) + { + for( i = 0; i < rowsX; ++i ) + { + ( *Zp_fx ) = 0; + + for( k = 0; k < colsX; ++k ) + { + x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/ + y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ + ( *Zp_fx ) = L_add_sat( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/ + // TODO: overflow of Z_fx to be checked + move32(); + } + Zp_fx++; + } + } + } + + return EXIT_SUCCESS; +} + +Word16 matrix_product_q30_fx( + const Word32 *X_fx, /* i : left hand matrix Q31*/ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Q25*/ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication Q30*/ +) +{ + Word16 i, j, k; + Word16 x_idx, y_idx; + Word32 *Zp_fx = Z_fx; + long long int W_tmp; + + /* Processing */ + test(); + test(); + test(); + if( transpX == 1 && transpY == 0 ) /* We use X transpose */ + { + if( rowsX != rowsY ) + { + return EXIT_FAILURE; + } + for( j = 0; j < colsY; ++j ) + { + for( i = 0; i < colsX; ++i ) + { + //( *Zp_fx ) = 0; + W_tmp = 0; + for( k = 0; k < rowsX; ++k ) + { + //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); + x_idx = k + i * rowsX; /* Q0 */ + y_idx = k + j * rowsY; /* Q0 */ + W_tmp += X_fx[x_idx] * Y_fx[y_idx]; /* Q56 */ + } + W_tmp = W_tmp << 6; /* W_shl( W_tmp, 6 ); */ /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /* W_round64_L( W_tmp ); */ /*Q30*/ + Zp_fx++; + } + } + } + else if( transpX == 0 && transpY ==1 ) /* We use Y transpose */ + { + if( colsX != colsY ) + { + return EXIT_FAILURE; + } + for( j = 0; j < rowsY; ++j ) + { + for( i = 0; i < rowsX; ++i ) + { + //( *Zp_fx ) = 0; + W_tmp = 0; + + for( k = 0; k < colsX; ++k ) + { + //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); + x_idx = i + k * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + W_tmp += X_fx[x_idx]*Y_fx[y_idx]; /* Q56 */ + } + W_tmp = W_tmp << 6; /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ + Zp_fx++; + } + } + } + else if( transpX == 1 && transpY ==1 ) /* We use both transpose */ + { + if( rowsX != colsY ) + { + return EXIT_FAILURE; + } + for( j = 0; j < rowsY; ++j ) + { + for( i = 0; i < colsX; ++i ) + { + //( *Zp_fx ) = 0; + W_tmp = 0; + for( k = 0; k < colsX; ++k ) + { + //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); + x_idx = k + i * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + W_tmp += X_fx[x_idx] * Y_fx[y_idx]; // Q56 + } + W_tmp = W_tmp << 6; /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ + + Zp_fx++; + } + } + } + else /* Regular case */ + { + if( colsX != rowsY ) + { + return EXIT_FAILURE; + } + + for( j = 0; j < colsY; ++j ) + { + for( i = 0; i < rowsX; ++i ) + { + //( *Zp_fx ) = 0; + W_tmp = 0; + + for( k = 0; k < colsX; ++k ) + { + //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); + x_idx = i + k * rowsX; /*Q0*/ + y_idx = k + j * rowsY; /*Q0*/ + W_tmp += X_fx[x_idx] * Y_fx[y_idx]; // Q56 + } + W_tmp = W_tmp << 6; /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ + + Zp_fx++; + } + } + } + + return EXIT_SUCCESS; +} +#endif \ No newline at end of file diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 4df30297fd..8181e06e39 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -97,7 +97,13 @@ static int16_t read_surround_coherence_hr( uint16_t *bitstream, int16_t *p_bit_p static int16_t read_coherence_data_hr_512( uint16_t *bitstream, int16_t *p_bit_pos, IVAS_QMETADATA *hQMetaData, const int16_t idx_dir, const int16_t nbits_coh ); -static void read_stream_dct_coeffs_omasa( int16_t *q_idx, float *q_dct_data, const int16_t len_stream, uint16_t *bit_stream, int16_t *index, const int16_t first_line ); +static void read_stream_dct_coeffs_omasa( int16_t *q_idx, +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + Word32 * q_dct_data_fx, +#else + float *q_dct_data, +#endif + const int16_t len_stream, uint16_t *bit_stream, int16_t *index, const int16_t first_line ); /*-----------------------------------------------------------------------* @@ -4248,7 +4254,11 @@ static void decode_combined_index( static void read_stream_dct_coeffs_omasa( int16_t *q_idx, +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + Word32 * q_dct_data_fx, +#else float *q_dct_data, +#endif const int16_t len_stream, uint16_t *bit_stream, int16_t *index, @@ -4325,6 +4335,20 @@ static void read_stream_dct_coeffs_omasa( } /* deindex */ +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + q_dct_data_fx[0] = L_shl( Mpy_32_16_1( step, shl( q_idx[0], 7 ) ), 2 ); // q = 25 + FOR( i = 1; i < len_stream; i++ ) + { + IF( s_and( q_idx[i], 1 ) == 0 ) + { + q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, negate( shl( q_idx[i], 6 ) ) ), 2 ); /*Q25*/ + } + ELSE + { + q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, shl( q_idx[i] + 1, 6 ) ), 2 ); /*Q25*/ + } + } +#else q_dct_data[0] = q_idx[0] * step; for ( i = 1; i < len_stream; i++ ) { @@ -4337,7 +4361,7 @@ static void read_stream_dct_coeffs_omasa( q_dct_data[i] = ( ( q_idx[i] + 1 ) >> 1 ) * step; } } - +#endif return; } @@ -4356,8 +4380,13 @@ void ivas_omasa_decode_masa_to_total( { int16_t i, j, k; int16_t q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + Word32 q_dct_data_fx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS], + dct_data_tmp_fx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; +#else float q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS], dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; +#endif int16_t n_streams, len_stream; #ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL int32_t int_tmp; @@ -4374,10 +4403,86 @@ void ivas_omasa_decode_masa_to_total( set_s( q_idx, 0, nbands * nblocks ); for ( i = 0; i < n_streams; i++ ) { - read_stream_dct_coeffs_omasa( &q_idx[i * len_stream], &q_dct_data[i * len_stream], len_stream, bit_stream, index, i == 0 ); + read_stream_dct_coeffs_omasa( &q_idx[i * len_stream], +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + &q_dct_data_fx[i * len_stream], +#else + &q_dct_data[i * len_stream], +#endif + len_stream, bit_stream, index, i == 0 ); } /* inverse DCT2 transform */ +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + SWITCH( len_stream ) + { + case 4: + matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 1, q_dct_data_fx, nblocks, 1, 0, dct_data_tmp_fx ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q30*/ + BREAK; + case 5: + matrix_product_q30_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 8: + matrix_product_q30_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 12: + matrix_product_q30_fx( dct12_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 20: + matrix_product_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); + matrix_product_q30_fx( dct_data_tmp_fx, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 0, q_dct_data_fx ); /* reuse of variable*/ + BREAK; + case 32: + matrix_product_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); + matrix_product_q30_fx( dct_data_tmp_fx, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 0, q_dct_data_fx ); + BREAK; + default: + printf( "Incorrect number of coefficients for OMASA.\n" ); + BREAK; + } + k = 0; + move16(); + FOR( i = 0; i < nblocks; i++ ) + { + FOR( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio_fx[i][j] = L_max( 0, q_dct_data_fx[k] ); // Q30 + move32(); + masa_to_total_energy_ratio_fx[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio_fx[i][j] ); /*Q30*/ + move32(); + k = add( k, 1 ); + } + } + + IF( EQ_16( nblocks, 1 ) ) + { + FOR( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + FOR( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[0][j]; /*Q30*/ + move32(); + } + } + } + + IF( EQ_16( nbands, 1 ) ) + { + FOR( j = 1; j < 5; j++ ) + { + FOR( i = 0; i < nblocks; i++ ) + { + masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[i][0]; /*Q30*/ + move32(); + } + } + } + +#else switch ( len_stream ) { case 4: @@ -4446,13 +4551,9 @@ void ivas_omasa_decode_masa_to_total( for ( i = 0; i < nblocks; i++ ) { masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[i][0]; -#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - int_tmp = (int32_t) ( MASA_SUR_COH_PRECISION * masa_to_total_energy_ratio[i][j] ); - masa_to_total_energy_ratio[i][j] = (float) ( int_tmp * MASA_SUR_COH_THRESHOLD ); -#endif } } } - +#endif return; } -- GitLab From 4e79c6a0bf028edab2cd338392a2d6ed3c9c7118 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Thu, 6 Feb 2025 16:55:55 +0200 Subject: [PATCH 3/7] update fix 1231 --- lib_com/ivas_cnst.h | 9 +-- lib_com/ivas_prot.h | 26 ++++++ lib_com/ivas_rom_com.c | 4 +- lib_com/ivas_rom_com.h | 4 +- lib_com/ivas_tools.c | 148 ++++++++++++++++++----------------- lib_dec/ivas_qmetadata_dec.c | 123 +++++++++++++++-------------- lib_enc/ivas_qmetadata_enc.c | 103 +++++++++++++++++++++++- 7 files changed, 276 insertions(+), 141 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 47ef7ce7a1..cde0689360 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1141,14 +1141,13 @@ enum #define MASA_TRANSP_BITS 1 #define NO_BITS_MASA_ISM_NO_OBJ 2 - -#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL -#define MASA2TOTAL_THR 0.9799999f -#else #define MASA2TOTAL_THR 0.98f -#endif + #define BITS_MASA2TOTTAL_DCT0 6 #define STEP_M2T 0.1f +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL +#define STEP_M2T_FX 214748365 // Q31 +#endif #define MASA_HEADER_BITS 2 #define MASA_SUBFRAME_BITS 1 #define MASA_LOWBITRATE_MODE_BITS 1 diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 987455ea7c..ba42beb541 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -756,6 +756,32 @@ int16_t get_igf_startline( float rand_triangular_signed( int16_t *seed ); +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL +Word16 matrix_product_fx( + const Word32 *X_fx, /* i : left hand matrix Qx*/ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Qy*/ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication Qx + Qy - 31*/ +); + +Word16 matrix_product_q30_fx( + const Word32 *X_fx, /* i : left hand matrix Q31*/ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Q25*/ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication Q30*/ +); +#endif + void dtx_read_padding_bits( DEC_CORE_HANDLE st, diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index d7969f99c1..2e55c8799a 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2819,7 +2819,7 @@ const Word32 dct12_fx[12 * 12] = { // Q31 619978560, -335436960, 0, 335436960, -619978560, 810030848, -876602816, 810030848, -619978560, 335436960, 619978560, -869301376, 846752832, -810030848, 759350208, -695569984, 619978560, -533649696, 438301408, -335436960, 226989024, -114460880 }; -#else +#endif const float dct4[4*4] = { 0.5000f, 0.6533f, 0.5000f, 0.2706f, @@ -2864,7 +2864,7 @@ const float dct12[12*12]= 0.2887f, -0.3772f, 0.2887f, -0.1562f, -0.0000f, 0.1562f, -0.2887f, 0.3772f, -0.4082f, 0.3772f, -0.2887f, 0.1562f, 0.2887f, -0.4048f, 0.3943f, -0.3772f, 0.3536f, -0.3239f, 0.2887f, -0.2485f, 0.2041f, -0.1562f, 0.1057f, -0.0533f }; -#endif + /*----------------------------------------------------------------------------------* * ISM ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index f9a0075605..b19ae93c17 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -330,12 +330,12 @@ extern const Word32 dct4_fx[]; extern const Word32 dct5_fx[]; extern const Word32 dct8_fx[]; extern const Word32 dct12_fx[]; -#else +#endif extern const float dct4[]; extern const float dct5[]; extern const float dct8[]; extern const float dct12[]; -#endif + /*----------------------------------------------------------------------------------* * ISM ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index bd02a9a5d2..2b6835190c 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -41,6 +41,9 @@ #include "ivas_prot.h" #include "wmc_auto.h" #include "ivas_rom_com.h" +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL +#include "basop_settings.h" +#endif /*--------------------------------------------------------------- * sumAbs() @@ -1292,68 +1295,67 @@ Word16 matrix_product_fx( Word32 *Zp_fx = Z_fx; /* Processing */ - - if( transpX == 1 && transpY == 0 ) /* We use X transpose */ + + if ( transpX == 1 && transpY == 0 ) /* We use X transpose */ { - if( rowsX != rowsY ) + if ( rowsX != rowsY ) { return EXIT_FAILURE; } - for( j = 0; j < colsY; ++j ) + for ( j = 0; j < colsY; ++j ) { - for( i = 0; i < colsX; ++i ) + for ( i = 0; i < colsX; ++i ) { ( *Zp_fx ) = 0; - - for( k = 0; k < rowsX; ++k ) + + for ( k = 0; k < rowsX; ++k ) { - x_idx = k + i*rowsX; /*Q0*/ - y_idx = k + j*rowsY; /*Q0*/ - ( *Zp_fx ) = *Zp_fx + ( X_fx[x_idx] * Y_fx[y_idx] ); /*Qx + Qy - 31*/ + x_idx = k + i * rowsX; /*Q0*/ + y_idx = k + j * rowsY; /*Q0*/ + ( *Zp_fx ) = *Zp_fx + Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Qx + Qy - 31*/ } Zp_fx++; } } } - else if( transpX == 0 && transpY == 1 ) /* We use Y transpose */ + else if ( transpX == 0 && transpY == 1 ) /* We use Y transpose */ { - if( colsX != colsY ) + if ( colsX != colsY ) { return EXIT_FAILURE; } - for( j = 0; j < rowsY; ++j ) + for ( j = 0; j < rowsY; ++j ) { - for( i = 0; i < rowsX; ++i ) + for ( i = 0; i < rowsX; ++i ) { ( *Zp_fx ) = 0; - for( k = 0; k < colsX; ++k ) + for ( k = 0; k < colsX; ++k ) { - x_idx = i + k*rowsX; /*Q0*/ - y_idx = j + k*rowsY; /*Q0*/ - ( *Zp_fx ) = (*Zp_fx) + ( X_fx[x_idx] * Y_fx[y_idx] ); /*Qx + Qy - 31*/ + x_idx = i + k * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + ( *Zp_fx ) = ( *Zp_fx ) + Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Qx + Qy - 31*/ } Zp_fx++; } } } - else if( transpX == 1 && transpY == 1 ) /* We use both transpose */ + else if ( transpX == 1 && transpY == 1 ) /* We use both transpose */ { - if( rowsX != colsY ) + if ( rowsX != colsY ) { return EXIT_FAILURE; } - for( j = 0; j < rowsY; ++j ) + for ( j = 0; j < rowsY; ++j ) { - for( i = 0; i < colsX; ++i ) + for ( i = 0; i < colsX; ++i ) { ( *Zp_fx ) = 0; - move32(); - for( k = 0; k < colsX; ++k ) + + for ( k = 0; k < colsX; ++k ) { - x_idx = add( k, imult1616( i, rowsX ) ); /*Q0*/ - y_idx = add( j, imult1616( k, rowsY ) ); /*Q0*/ - ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/ - move32(); + x_idx = k + i * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + ( *Zp_fx ) = ( *Zp_fx ) + Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Qx + Qy - 31*/ } Zp_fx++; @@ -1362,22 +1364,22 @@ Word16 matrix_product_fx( } else /* Regular case */ { - if( NE_16( colsX, rowsY ) ) + if ( colsX != rowsY ) { return EXIT_FAILURE; } - for( j = 0; j < colsY; ++j ) + for ( j = 0; j < colsY; ++j ) { - for( i = 0; i < rowsX; ++i ) + for ( i = 0; i < rowsX; ++i ) { ( *Zp_fx ) = 0; - - for( k = 0; k < colsX; ++k ) + + for ( k = 0; k < colsX; ++k ) { - x_idx = add( i, imult1616( k, rowsX ) ); /*Q0*/ - y_idx = add( k, imult1616( j, rowsY ) ); /*Q0*/ - ( *Zp_fx ) = L_add_sat( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/ + x_idx = i + k * rowsX; /*Q0*/ + y_idx = k + j * rowsY; /*Q0*/ + ( *Zp_fx ) = ( *Zp_fx ) + Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Qx + Qy - 31 L_sat_add() */ // TODO: overflow of Z_fx to be checked move32(); } @@ -1410,75 +1412,75 @@ Word16 matrix_product_q30_fx( test(); test(); test(); - if( transpX == 1 && transpY == 0 ) /* We use X transpose */ + if ( transpX == 1 && transpY == 0 ) /* We use X transpose */ { - if( rowsX != rowsY ) + if ( rowsX != rowsY ) { return EXIT_FAILURE; } - for( j = 0; j < colsY; ++j ) + for ( j = 0; j < colsY; ++j ) { - for( i = 0; i < colsX; ++i ) + for ( i = 0; i < colsX; ++i ) { //( *Zp_fx ) = 0; W_tmp = 0; - for( k = 0; k < rowsX; ++k ) + for ( k = 0; k < rowsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); - x_idx = k + i * rowsX; /* Q0 */ - y_idx = k + j * rowsY; /* Q0 */ - W_tmp += X_fx[x_idx] * Y_fx[y_idx]; /* Q56 */ + x_idx = k + i * rowsX; /* Q0 */ + y_idx = k + j * rowsY; /* Q0 */ + W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); /* Q56 */ } - W_tmp = W_tmp << 6; /* W_shl( W_tmp, 6 ); */ /*Q62*/ - ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /* W_round64_L( W_tmp ); */ /*Q30*/ + W_tmp = W_tmp << 6; /* W_shl( W_tmp, 6 ); */ /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /* W_round64_L( W_tmp ); */ /*Q30*/ Zp_fx++; } } } - else if( transpX == 0 && transpY ==1 ) /* We use Y transpose */ + else if ( transpX == 0 && transpY == 1 ) /* We use Y transpose */ { - if( colsX != colsY ) + if ( colsX != colsY ) { return EXIT_FAILURE; } - for( j = 0; j < rowsY; ++j ) + for ( j = 0; j < rowsY; ++j ) { - for( i = 0; i < rowsX; ++i ) + for ( i = 0; i < rowsX; ++i ) { //( *Zp_fx ) = 0; W_tmp = 0; - for( k = 0; k < colsX; ++k ) + for ( k = 0; k < colsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); - x_idx = i + k * rowsX; /*Q0*/ - y_idx = j + k * rowsY; /*Q0*/ - W_tmp += X_fx[x_idx]*Y_fx[y_idx]; /* Q56 */ + x_idx = i + k * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); /* Q56 */ } - W_tmp = W_tmp << 6; /*Q62*/ - ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ + W_tmp = W_tmp << 6; /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ Zp_fx++; } } } - else if( transpX == 1 && transpY ==1 ) /* We use both transpose */ + else if ( transpX == 1 && transpY == 1 ) /* We use both transpose */ { - if( rowsX != colsY ) + if ( rowsX != colsY ) { return EXIT_FAILURE; } - for( j = 0; j < rowsY; ++j ) + for ( j = 0; j < rowsY; ++j ) { - for( i = 0; i < colsX; ++i ) + for ( i = 0; i < colsX; ++i ) { //( *Zp_fx ) = 0; W_tmp = 0; - for( k = 0; k < colsX; ++k ) + for ( k = 0; k < colsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); - x_idx = k + i * rowsX; /*Q0*/ - y_idx = j + k * rowsY; /*Q0*/ - W_tmp += X_fx[x_idx] * Y_fx[y_idx]; // Q56 + x_idx = k + i * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); // Q56 } W_tmp = W_tmp << 6; /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ @@ -1489,28 +1491,28 @@ Word16 matrix_product_q30_fx( } else /* Regular case */ { - if( colsX != rowsY ) + if ( colsX != rowsY ) { return EXIT_FAILURE; } - for( j = 0; j < colsY; ++j ) + for ( j = 0; j < colsY; ++j ) { - for( i = 0; i < rowsX; ++i ) + for ( i = 0; i < rowsX; ++i ) { //( *Zp_fx ) = 0; W_tmp = 0; - - for( k = 0; k < colsX; ++k ) + + for ( k = 0; k < colsX; ++k ) { //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); - x_idx = i + k * rowsX; /*Q0*/ - y_idx = k + j * rowsY; /*Q0*/ - W_tmp += X_fx[x_idx] * Y_fx[y_idx]; // Q56 + x_idx = i + k * rowsX; /*Q0*/ + y_idx = k + j * rowsY; /*Q0*/ + W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); // Q56 } W_tmp = W_tmp << 6; /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ - + Zp_fx++; } } diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 8181e06e39..2462065d03 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -40,6 +40,10 @@ #include "ivas_rom_dec.h" #include "wmc_auto.h" #include "prot.h" +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL +#include "basop_settings.h" +#endif + /*-----------------------------------------------------------------------* * Local function prototypes @@ -97,13 +101,16 @@ static int16_t read_surround_coherence_hr( uint16_t *bitstream, int16_t *p_bit_p static int16_t read_coherence_data_hr_512( uint16_t *bitstream, int16_t *p_bit_pos, IVAS_QMETADATA *hQMetaData, const int16_t idx_dir, const int16_t nbits_coh ); -static void read_stream_dct_coeffs_omasa( int16_t *q_idx, -#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - Word32 * q_dct_data_fx, -#else - float *q_dct_data, -#endif - const int16_t len_stream, uint16_t *bit_stream, int16_t *index, const int16_t first_line ); +static void read_stream_dct_coeffs_omasa( int16_t *q_idx, +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + Word32 *q_dct_data_fx, +#else + float *q_dct_data, +#endif + const int16_t len_stream, + uint16_t *bit_stream, + int16_t *index, + const int16_t first_line ); /*-----------------------------------------------------------------------* @@ -4254,8 +4261,8 @@ static void decode_combined_index( static void read_stream_dct_coeffs_omasa( int16_t *q_idx, -#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - Word32 * q_dct_data_fx, +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + Word32 *q_dct_data_fx, #else float *q_dct_data, #endif @@ -4268,8 +4275,12 @@ static void read_stream_dct_coeffs_omasa( int16_t i, j, i_min; float step; - int16_t GR1, GR2; + int16_t GR1, GR2; +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + int64_t step_fx; + step_fx = STEP_M2T_FX; +#endif step = STEP_M2T; sign = 1; if ( first_line == 0 ) @@ -4335,17 +4346,17 @@ static void read_stream_dct_coeffs_omasa( } /* deindex */ -#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - q_dct_data_fx[0] = L_shl( Mpy_32_16_1( step, shl( q_idx[0], 7 ) ), 2 ); // q = 25 - FOR( i = 1; i < len_stream; i++ ) +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + q_dct_data_fx[0] = (Word32) ( ( step_fx * q_idx[0] ) >> 6 ); // Q25 + for ( i = 1; i < len_stream; i++ ) { - IF( s_and( q_idx[i], 1 ) == 0 ) + if ( ( q_idx[i] & 1 ) == 0 ) { - q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, negate( shl( q_idx[i], 6 ) ) ), 2 ); /*Q25*/ + q_dct_data_fx[i] = (Word32) ( ( step_fx * ( -q_idx[i] ) ) >> 7 ); // Q25 } ELSE { - q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, shl( q_idx[i] + 1, 6 ) ), 2 ); /*Q25*/ + q_dct_data_fx[i] = (Word32) ( ( step_fx * ( q_idx[i] + 1 ) ) >> 7 ); // Q25 } } #else @@ -4388,9 +4399,7 @@ void ivas_omasa_decode_masa_to_total( dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; #endif int16_t n_streams, len_stream; -#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - int32_t int_tmp; -#endif + /* Setup coding parameters */ n_streams = 1; len_stream = nbands * nblocks; @@ -4404,33 +4413,33 @@ void ivas_omasa_decode_masa_to_total( for ( i = 0; i < n_streams; i++ ) { read_stream_dct_coeffs_omasa( &q_idx[i * len_stream], -#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - &q_dct_data_fx[i * len_stream], -#else - &q_dct_data[i * len_stream], -#endif - len_stream, bit_stream, index, i == 0 ); +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + &q_dct_data_fx[i * len_stream], +#else + &q_dct_data[i * len_stream], +#endif + len_stream, bit_stream, index, i == 0 ); } /* inverse DCT2 transform */ -#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - SWITCH( len_stream ) +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + SWITCH( len_stream ) { case 4: matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 1, q_dct_data_fx, nblocks, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q30*/ + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q30*/ BREAK; case 5: matrix_product_q30_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ BREAK; case 8: matrix_product_q30_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ BREAK; case 12: matrix_product_q30_fx( dct12_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ BREAK; case 20: matrix_product_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); @@ -4444,40 +4453,48 @@ void ivas_omasa_decode_masa_to_total( printf( "Incorrect number of coefficients for OMASA.\n" ); BREAK; } + + /* this is to make sure the comparison to the threshold 0.98 will go the same way in fixed point and floating + point without having to drag the fixed point values to the comparison place in the code; 1052266987 is 0.98 in Q30 + it is not needed in the fixed point*/ + for ( i = 0; i < nblocks * nbands; i++ ) + { + if ( q_dct_data_fx[i] >= 1052266987 && q_dct_data_fx[i] < 1052400000 ) + { + q_dct_data_fx[i] = 1052400000; + } + } + k = 0; - move16(); - FOR( i = 0; i < nblocks; i++ ) + for ( i = 0; i < nblocks; i++ ) { - FOR( j = 0; j < nbands; j++ ) + for ( j = 0; j < nbands; j++ ) { - masa_to_total_energy_ratio_fx[i][j] = L_max( 0, q_dct_data_fx[k] ); // Q30 - move32(); - masa_to_total_energy_ratio_fx[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio_fx[i][j] ); /*Q30*/ - move32(); - k = add( k, 1 ); + masa_to_total_energy_ratio[i][j] = q_dct_data_fx[k] / (float) ( 1 << 30 ); + masa_to_total_energy_ratio[i][j] = max( 0.0f, masa_to_total_energy_ratio[i][j] ); + masa_to_total_energy_ratio[i][j] = min( 1.0f, masa_to_total_energy_ratio[i][j] ); + k++; } } - IF( EQ_16( nblocks, 1 ) ) + if ( nblocks == 1 ) { - FOR( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - FOR( j = 0; j < nbands; j++ ) + for ( j = 0; j < nbands; j++ ) { - masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[0][j]; /*Q30*/ - move32(); + masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[0][j]; } } } - IF( EQ_16( nbands, 1 ) ) + if ( nbands == 1 ) { - FOR( j = 1; j < 5; j++ ) + for ( j = 1; j < 5; j++ ) { - FOR( i = 0; i < nblocks; i++ ) + for ( i = 0; i < nblocks; i++ ) { - masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[i][0]; /*Q30*/ - move32(); + masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[i][0]; } } } @@ -4521,10 +4538,6 @@ void ivas_omasa_decode_masa_to_total( { masa_to_total_energy_ratio[i][j] = max( 0.0f, q_dct_data[k] ); masa_to_total_energy_ratio[i][j] = min( 1.0f, masa_to_total_energy_ratio[i][j] ); -#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - int_tmp = (int32_t) ( MASA_SUR_COH_PRECISION * masa_to_total_energy_ratio[i][j] ); - masa_to_total_energy_ratio[i][j] = (float) ( int_tmp * MASA_SUR_COH_THRESHOLD ); -#endif k++; } } @@ -4536,10 +4549,6 @@ void ivas_omasa_decode_masa_to_total( for ( j = 0; j < nbands; j++ ) { masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[0][j]; -#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - int_tmp = (int32_t) ( MASA_SUR_COH_PRECISION * masa_to_total_energy_ratio[i][j] ); - masa_to_total_energy_ratio[i][j] = (float) ( int_tmp * MASA_SUR_COH_THRESHOLD ); -#endif } } } diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index d178cbf62c..87162a945d 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -41,7 +41,9 @@ #include "ivas_stat_enc.h" #include "wmc_auto.h" #include "prot.h" - +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL +#include "basop_settings.h" +#endif /*-----------------------------------------------------------------------* * Local function prototypes @@ -6033,10 +6035,16 @@ void ivas_omasa_encode_masa_to_total( int16_t q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + int16_t bits_pos, nb_bits; int16_t n_streams, len_stream; + #ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - int32_t int_tmp; + Word32 q_dct_data_fx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS], + dct_data_tmp_fx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + + int64_t step_fx; + step_fx = STEP_M2T_FX; #endif #ifdef DEBUG_MODE_QMETADATA static FILE *pF = NULL; @@ -6146,6 +6154,96 @@ void ivas_omasa_encode_masa_to_total( } /* reconstruct masa2total */ +#ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL + q_dct_data_fx[0] = (Word32) ( ( step_fx * q_idx[0] ) >> 6 ); // Q25 + for ( i = 1; i < len_stream; i++ ) + { + if ( ( q_idx[i] & 1 ) == 0 ) + { + q_dct_data_fx[i] = (Word32) ( ( step_fx * ( -q_idx[i] ) ) >> 7 ); // Q25 + } + ELSE + { + q_dct_data_fx[i] = (Word32) ( ( step_fx * ( q_idx[i] + 1 ) ) >> 7 ); // Q25 + } + } + SWITCH( len_stream ) + { + case 4: + matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 1, q_dct_data_fx, nblocks, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q30*/ + BREAK; + case 5: + matrix_product_q30_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 8: + matrix_product_q30_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 12: + matrix_product_q30_fx( dct12_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 20: + matrix_product_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); + matrix_product_q30_fx( dct_data_tmp_fx, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 0, q_dct_data_fx ); /* reuse of variable*/ + BREAK; + case 32: + matrix_product_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); + matrix_product_q30_fx( dct_data_tmp_fx, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 0, q_dct_data_fx ); + BREAK; + default: + printf( "Incorrect number of coefficients for OMASA.\n" ); + BREAK; + } + + /* this is to make sure the comparison to the threshold 0.98 will go the same way in fixed point and floating + point without having to drag the fixed point values to the comparison place in the code; 1052266987 is 0.98 in Q30 + it is not needed in the fixed point*/ + for ( i = 0; i < nblocks * nbands; i++ ) + { + if ( q_dct_data_fx[i] >= 1052266987 && q_dct_data_fx[i] < 1052400000 ) + { + q_dct_data_fx[i] = 1052400000; + } + } + + k = 0; + for ( i = 0; i < nblocks; i++ ) + { + for ( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio[i][j] = q_dct_data_fx[k] / (float) ( 1 << 30 ); + masa_to_total_energy_ratio[i][j] = max( 0.0f, masa_to_total_energy_ratio[i][j] ); + masa_to_total_energy_ratio[i][j] = min( 1.0f, masa_to_total_energy_ratio[i][j] ); + k++; + } + } + + if ( nblocks == 1 ) + { + for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[0][j]; + } + } + } + + if ( nbands == 1 ) + { + for ( j = 1; j < 5; j++ ) + { + for ( i = 0; i < nblocks; i++ ) + { + masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[i][0]; + } + } + } + +#else q_dct_data[0] = q_idx[0] * step; for ( i = 1; i < len_stream; i++ ) { @@ -6205,6 +6303,7 @@ void ivas_omasa_encode_masa_to_total( k++; } } +#endif assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); #ifdef DEBUG_MODE_QMETADATA -- GitLab From cba90f9d7e9fe26f6801cb588823b8ff820bcae3 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Fri, 7 Feb 2025 12:01:52 +0200 Subject: [PATCH 4/7] clang review --- lib_com/ivas_tools.c | 20 +++++++++----------- lib_enc/ivas_qmetadata_enc.c | 7 ++++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 2b6835190c..053cd714e5 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1380,7 +1380,7 @@ Word16 matrix_product_fx( x_idx = i + k * rowsX; /*Q0*/ y_idx = k + j * rowsY; /*Q0*/ ( *Zp_fx ) = ( *Zp_fx ) + Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Qx + Qy - 31 L_sat_add() */ - // TODO: overflow of Z_fx to be checked + /* TODO: overflow of Z_fx to be checked */ move32(); } Zp_fx++; @@ -1422,11 +1422,10 @@ Word16 matrix_product_q30_fx( { for ( i = 0; i < colsX; ++i ) { - //( *Zp_fx ) = 0; W_tmp = 0; for ( k = 0; k < rowsX; ++k ) { - //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); + /*( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); */ x_idx = k + i * rowsX; /* Q0 */ y_idx = k + j * rowsY; /* Q0 */ W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); /* Q56 */ @@ -1447,12 +1446,12 @@ Word16 matrix_product_q30_fx( { for ( i = 0; i < rowsX; ++i ) { - //( *Zp_fx ) = 0; + W_tmp = 0; for ( k = 0; k < colsX; ++k ) { - //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); + /* ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); */ x_idx = i + k * rowsX; /*Q0*/ y_idx = j + k * rowsY; /*Q0*/ W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); /* Q56 */ @@ -1473,14 +1472,13 @@ Word16 matrix_product_q30_fx( { for ( i = 0; i < colsX; ++i ) { - //( *Zp_fx ) = 0; W_tmp = 0; for ( k = 0; k < colsX; ++k ) { - //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); + /* ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); */ x_idx = k + i * rowsX; /*Q0*/ y_idx = j + k * rowsY; /*Q0*/ - W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); // Q56 + W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); /* Q56*/ } W_tmp = W_tmp << 6; /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ @@ -1500,15 +1498,15 @@ Word16 matrix_product_q30_fx( { for ( i = 0; i < rowsX; ++i ) { - //( *Zp_fx ) = 0; W_tmp = 0; for ( k = 0; k < colsX; ++k ) { - //( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); + /* ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); */ x_idx = i + k * rowsX; /*Q0*/ y_idx = k + j * rowsY; /*Q0*/ - W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); // Q56 + W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); /* Q56*/ + } W_tmp = W_tmp << 6; /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 87162a945d..9d6cdf4350 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -6198,9 +6198,10 @@ void ivas_omasa_encode_masa_to_total( BREAK; } - /* this is to make sure the comparison to the threshold 0.98 will go the same way in fixed point and floating - point without having to drag the fixed point values to the comparison place in the code; 1052266987 is 0.98 in Q30 - it is not needed in the fixed point*/ + /* this is to make sure the comparison to the threshold 0.98 will go the same way in */ + /* fixed point and floating point without having to drag the fixed point values to the */ + /* comparison place in the code; */ + /* 1052266987 is 0.98 in Q30 it is not needed in the fixed point */ for ( i = 0; i < nblocks * nbands; i++ ) { if ( q_dct_data_fx[i] >= 1052266987 && q_dct_data_fx[i] < 1052400000 ) -- GitLab From 43bfd73a58d2386095bcc4684642cdf06da581a0 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Fri, 7 Feb 2025 12:38:25 +0200 Subject: [PATCH 5/7] clang review --- lib_com/ivas_tools.c | 29 +++++++++++++---------------- lib_dec/ivas_qmetadata_dec.c | 15 ++++++++------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 053cd714e5..16bdc4f000 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1406,7 +1406,7 @@ Word16 matrix_product_q30_fx( Word16 i, j, k; Word16 x_idx, y_idx; Word32 *Zp_fx = Z_fx; - long long int W_tmp; + int64_t W_tmp; /* Processing */ test(); @@ -1426,9 +1426,9 @@ Word16 matrix_product_q30_fx( for ( k = 0; k < rowsX; ++k ) { /*( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); */ - x_idx = k + i * rowsX; /* Q0 */ - y_idx = k + j * rowsY; /* Q0 */ - W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); /* Q56 */ + x_idx = k + i * rowsX; /* Q0 */ + y_idx = k + j * rowsY; /* Q0 */ + W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56 */ } W_tmp = W_tmp << 6; /* W_shl( W_tmp, 6 ); */ /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /* W_round64_L( W_tmp ); */ /*Q30*/ @@ -1446,15 +1446,13 @@ Word16 matrix_product_q30_fx( { for ( i = 0; i < rowsX; ++i ) { - W_tmp = 0; - for ( k = 0; k < colsX; ++k ) { /* ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); */ - x_idx = i + k * rowsX; /*Q0*/ - y_idx = j + k * rowsY; /*Q0*/ - W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); /* Q56 */ + x_idx = i + k * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56 */ } W_tmp = W_tmp << 6; /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ @@ -1476,9 +1474,9 @@ Word16 matrix_product_q30_fx( for ( k = 0; k < colsX; ++k ) { /* ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); */ - x_idx = k + i * rowsX; /*Q0*/ - y_idx = j + k * rowsY; /*Q0*/ - W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); /* Q56*/ + x_idx = k + i * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56*/ } W_tmp = W_tmp << 6; /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ @@ -1503,10 +1501,9 @@ Word16 matrix_product_q30_fx( for ( k = 0; k < colsX; ++k ) { /* ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); */ - x_idx = i + k * rowsX; /*Q0*/ - y_idx = k + j * rowsY; /*Q0*/ - W_tmp += ( (long long int) X_fx[x_idx] * (long long int) Y_fx[y_idx] ); /* Q56*/ - + x_idx = i + k * rowsX; /*Q0*/ + y_idx = k + j * rowsY; /*Q0*/ + W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56*/ } W_tmp = W_tmp << 6; /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 2462065d03..e66d03c965 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -4121,7 +4121,7 @@ static int16_t read_surround_coherence_hr( } else { - idx_ER[j] = 7; // masa_sq( error_ratio_surr, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + idx_ER[j] = 7; /* masa_sq( error_ratio_surr, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); */ no_cv_vec[j] = idx_cb_sur_coh_masa[idx_ER[j]] + 2; } } @@ -4347,16 +4347,16 @@ static void read_stream_dct_coeffs_omasa( /* deindex */ #ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL - q_dct_data_fx[0] = (Word32) ( ( step_fx * q_idx[0] ) >> 6 ); // Q25 + q_dct_data_fx[0] = (Word32) ( ( step_fx * q_idx[0] ) >> 6 ); /* Q25 */ for ( i = 1; i < len_stream; i++ ) { if ( ( q_idx[i] & 1 ) == 0 ) { - q_dct_data_fx[i] = (Word32) ( ( step_fx * ( -q_idx[i] ) ) >> 7 ); // Q25 + q_dct_data_fx[i] = (Word32) ( ( step_fx * ( -q_idx[i] ) ) >> 7 ); /* Q25 */ } ELSE { - q_dct_data_fx[i] = (Word32) ( ( step_fx * ( q_idx[i] + 1 ) ) >> 7 ); // Q25 + q_dct_data_fx[i] = (Word32) ( ( step_fx * ( q_idx[i] + 1 ) ) >> 7 ); /* Q25 */ } } #else @@ -4454,9 +4454,10 @@ void ivas_omasa_decode_masa_to_total( BREAK; } - /* this is to make sure the comparison to the threshold 0.98 will go the same way in fixed point and floating - point without having to drag the fixed point values to the comparison place in the code; 1052266987 is 0.98 in Q30 - it is not needed in the fixed point*/ + /* this is to make sure the comparison to the threshold 0.98 will go the same way in */ + /* fixed point and floating point without having to drag the fixed point values to the */ + /* comparison place in the code; 1052266987 is 0.98 in Q30 it is not needed in the fixed point*/ + for ( i = 0; i < nblocks * nbands; i++ ) { if ( q_dct_data_fx[i] >= 1052266987 && q_dct_data_fx[i] < 1052400000 ) -- GitLab From 23c46267b5c8d72efbca787bce4c6d107105d133 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Fri, 7 Feb 2025 14:26:26 +0200 Subject: [PATCH 6/7] clang review --- lib_com/ivas_tools.c | 2 +- lib_dec/ivas_qmetadata_dec.c | 7 ++++--- lib_enc/ivas_qmetadata_enc.c | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 16bdc4f000..29915d341d 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1515,4 +1515,4 @@ Word16 matrix_product_q30_fx( return EXIT_SUCCESS; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index e66d03c965..349cf13a45 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -4273,15 +4273,16 @@ static void read_stream_dct_coeffs_omasa( { int16_t sign; int16_t i, j, i_min; - +#ifndef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL float step; - +#endif int16_t GR1, GR2; #ifdef NONBE_1231_BASOP_819_THRESHOLD_MASA2TOTAL int64_t step_fx; step_fx = STEP_M2T_FX; -#endif +#else step = STEP_M2T; +#endif sign = 1; if ( first_line == 0 ) { diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 9d6cdf4350..550f1fb697 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -6032,6 +6032,7 @@ void ivas_omasa_encode_masa_to_total( float data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float step = STEP_M2T; + int16_t q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; -- GitLab From 45afd0eb6ca5ba5214c19771c67673323142a60a Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Mon, 10 Feb 2025 21:26:03 +0200 Subject: [PATCH 7/7] fix usan --- lib_com/ivas_tools.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 29915d341d..a38c105028 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1430,7 +1430,7 @@ Word16 matrix_product_q30_fx( y_idx = k + j * rowsY; /* Q0 */ W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56 */ } - W_tmp = W_tmp << 6; /* W_shl( W_tmp, 6 ); */ /*Q62*/ + W_tmp = W_tmp * 64; /* W_shl( W_tmp, 6 ); */ /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /* W_round64_L( W_tmp ); */ /*Q30*/ Zp_fx++; } @@ -1454,7 +1454,7 @@ Word16 matrix_product_q30_fx( y_idx = j + k * rowsY; /*Q0*/ W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56 */ } - W_tmp = W_tmp << 6; /*Q62*/ + W_tmp = W_tmp * 64; /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ Zp_fx++; } @@ -1478,7 +1478,7 @@ Word16 matrix_product_q30_fx( y_idx = j + k * rowsY; /*Q0*/ W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56*/ } - W_tmp = W_tmp << 6; /*Q62*/ + W_tmp = W_tmp * 64; /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ Zp_fx++; @@ -1505,7 +1505,7 @@ Word16 matrix_product_q30_fx( y_idx = k + j * rowsY; /*Q0*/ W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56*/ } - W_tmp = W_tmp << 6; /*Q62*/ + W_tmp = W_tmp * 64; /*Q62*/ ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ Zp_fx++; -- GitLab