diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index e88f540752a0cd5888c57ca4cb4f0b61f841b7ad..b3f2f932cf5bcde3863b1a0b6c761214442c3211 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1147,6 +1147,9 @@ enum #endif #define BITS_MASA2TOTTAL_DCT0 6 #define STEP_M2T 0.1f +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +#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 496471f2b8e9b516d39f3c7bd3e923d4d6b971df..a55aacc85de6da49f8988667c23350770c1e26aa 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -759,6 +759,32 @@ int16_t get_igf_startline( float rand_triangular_signed( int16_t *seed ); +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +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, const int16_t num_bits diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 58dc6dc974063e216325393cf6d9a68149c5e306..481abd06f6b12afd59bfa555afb27f06f27303e4 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2833,6 +2833,48 @@ const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = }; /* column wise DCT matrices for 4 5, and 8 dim */ +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +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 +}; +#endif const float dct4[4*4] = { 0.5000f, 0.6533f, 0.5000f, 0.2706f, diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index f597fe8b90efcd7d98788e61c8840f90a1a192af..35e3950fde88dac199953f1f04f3811f45dabf07 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -327,6 +327,12 @@ extern const float dct4[]; extern const float dct5[]; extern const float dct8[]; extern const float dct12[]; +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +extern const Word32 dct4_fx[]; +extern const Word32 dct5_fx[]; +extern const Word32 dct8_fx[]; +extern const Word32 dct12_fx[]; +#endif /*----------------------------------------------------------------------------------* * ISM ROM tables diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index ee7a06ca7d9b7300b7fd00eff316ef8ccf6ed775..85a0b1f6c6c3eac2e51c6c2b16ce215df205ec31 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -41,7 +41,9 @@ #include "ivas_prot.h" #include "wmc_auto.h" #include "ivas_rom_com.h" - +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +#include "basop_settings.h" +#endif /*--------------------------------------------------------------- * sumAbs() * @@ -1252,3 +1254,243 @@ float rand_triangular_signed( return 0.5f - 0.5f * sqrtf( 1.0f - rand_val ); } } + +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +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 + 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 */ + { + 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 ) + 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 */ + { + if ( rowsX != colsY ) + { + return EXIT_FAILURE; + } + for ( j = 0; j < rowsY; ++j ) + { + for ( i = 0; i < colsX; ++i ) + { + ( *Zp_fx ) = 0; + + for ( k = 0; k < colsX; ++k ) + { + 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++; + } + } + } + else /* Regular case */ + { + if ( 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 = 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(); + } + 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; + int64_t 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 ) + { + 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 += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56 */ + } + 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++; + } + } + } + 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 ) + { + 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 += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56 */ + } + W_tmp = W_tmp * 64; /*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 ) + { + 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 += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56*/ + } + W_tmp = W_tmp * 64; /*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 ) + { + 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 += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56*/ + } + W_tmp = W_tmp * 64; /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ + + Zp_fx++; + } + } + } + + return EXIT_SUCCESS; +} +#endif \ No newline at end of file diff --git a/lib_com/options.h b/lib_com/options.h index c7111f22ab1d23e4ce71b989b4ad4934f58f22a4..ab9f2bd72a8ed206fb17fb121fabb5c61b0bfcfe 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -179,6 +179,7 @@ #define NONBE_1273_ISM_METADATA_COUNTER /* VA: FLP issue 1273: fix counter overflow in ISM metadata encoder */ #define NONBE_FIX_GSC_BSTR /* VA: issue 1264 FLP (1189 BASOP): Fix bitstream synchronization between encoder and decoder in ACELP GSC in OMASA */ +#define NONBE_1319_M2R_PRECISION_ALIGN /* Nokia: bring updates from PC code related to OMASA masa2total ratios */ /* #################### End FIXES switches ############################ */ #define BASOP_NOGLOB /* Disable global symbols in BASOPs, Overflow/Carry in BASOPs disabled, additional BASOPs in case of Overflow */ diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 816425197bf9382b1b09d33b7bbecc6d794349b3..0d5fc1bb3ad0e6e51d2b64a0518676b6fd872aa6 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -40,6 +40,9 @@ #include "ivas_rom_dec.h" #include "wmc_auto.h" #include "prot.h" +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +#include "basop_settings.h" +#endif /*-----------------------------------------------------------------------* * Local function prototypes @@ -97,8 +100,11 @@ 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 ); +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +static void read_stream_dct_coeffs_omasa( int16_t *q_idx, Word32 *q_dct_data_fx, const int16_t len_stream, uint16_t *bit_stream, int16_t *index, const int16_t first_line ); +#else 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 ); - +#endif /*-----------------------------------------------------------------------* * Global function definitions @@ -886,14 +892,14 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( #ifdef DEBUG_MODE_QMETADATA bits_diff_sum = #endif - ivas_qmetadata_entropy_decode_diffuseness_hr_512( bitstream, index, &( hQMetaData->q_direction[0] ) ); + ivas_qmetadata_entropy_decode_diffuseness_hr_512( bitstream, index, &( hQMetaData->q_direction[0] ) ); if ( hQMetaData->no_directions == 2 ) { #ifdef DEBUG_MODE_QMETADATA bits_diff_sum += #endif - ivas_qmetadata_entropy_decode_diffuseness_hr_512( bitstream, index, &( hQMetaData->q_direction[1] ) ); + ivas_qmetadata_entropy_decode_diffuseness_hr_512( bitstream, index, &( hQMetaData->q_direction[1] ) ); } @@ -986,7 +992,7 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( #ifdef DEBUG_MODE_QMETADATA bits_sur_coherence = #endif - read_surround_coherence_hr( bitstream, index, hQMetaData ); + read_surround_coherence_hr( bitstream, index, hQMetaData ); } else { @@ -4247,7 +4253,11 @@ static void decode_combined_index( static void read_stream_dct_coeffs_omasa( int16_t *q_idx, +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + Word32 *q_dct_data_fx, +#else float *q_dct_data, +#endif const int16_t len_stream, uint16_t *bit_stream, int16_t *index, @@ -4255,11 +4265,16 @@ static void read_stream_dct_coeffs_omasa( { int16_t sign, nbits; int16_t i, j, i_min; - +#ifndef NONBE_1319_M2R_PRECISION_ALIGN float step; +#endif int16_t GR1, GR2; - +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + int64_t step_fx; + step_fx = STEP_M2T_FX; +#else step = STEP_M2T; +#endif nbits = 0; sign = 1; if ( first_line == 0 ) @@ -4326,6 +4341,20 @@ static void read_stream_dct_coeffs_omasa( } /* deindex */ +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + 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 */ + } + } +#else q_dct_data[0] = q_idx[0] * step; for ( i = 1; i < len_stream; i++ ) { @@ -4338,7 +4367,7 @@ static void read_stream_dct_coeffs_omasa( q_dct_data[i] = ( ( q_idx[i] + 1 ) >> 1 ) * step; } } - +#endif return; } @@ -4357,11 +4386,18 @@ 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_1319_M2R_PRECISION_ALIGN + 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; +#ifndef NONBE_1319_M2R_PRECISION_ALIGN #ifdef NON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL int32_t int_tmp; +#endif #endif /* Setup coding parameters */ n_streams = 1; @@ -4375,10 +4411,95 @@ 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_1319_M2R_PRECISION_ALIGN + &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_1319_M2R_PRECISION_ALIGN + 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 switch ( len_stream ) { case 4: @@ -4433,7 +4554,7 @@ void ivas_omasa_decode_masa_to_total( { masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[0][j]; #ifdef NON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL - int_tmp = (int32_t) ( MASA2TOTAL_PREC_INV_THRESHOLD * masa_to_total_energy_ratio[i][j] ); + int_tmp = (int32_t) ( MASA2TOTAL_PREC_INV_THRESHOLD * masa_to_total_energy_ratio[i][j] ); masa_to_total_energy_ratio[i][j] = (float) ( int_tmp * MASA2TOTAL_PREC_THRESHOLD ); #endif } @@ -4454,6 +4575,6 @@ void ivas_omasa_decode_masa_to_total( } } } - +#endif return; } diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index b08bb928585adfea6d64cf5c9b9536b0018818e5..692551008b2d3d8758129879d132263a4c3933e0 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_1319_M2R_PRECISION_ALIGN +#include "basop_settings.h" +#endif /*-----------------------------------------------------------------------* * Local function prototypes @@ -6016,10 +6018,17 @@ 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_1319_M2R_PRECISION_ALIGN + 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; +#else #ifdef NON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL int32_t int_tmp; #endif - +#endif #ifdef DEBUG_MODE_QMETADATA static FILE *pF = NULL; static FILE *pF_ratio = NULL; @@ -6128,6 +6137,97 @@ void ivas_omasa_encode_masa_to_total( } /* reconstruct masa2total */ +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + 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++ ) { @@ -6187,6 +6287,7 @@ void ivas_omasa_encode_masa_to_total( k++; } } +#endif assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); #ifdef DEBUG_MODE_QMETADATA