diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index e938701b3db371267ea3962a0b8f735035c2c610..653581bd6beca8877ce19d4dac537de84c5c5f0a 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -490,6 +490,28 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( hCPE->nchan_out, 1 ) ) { stereo_dft_unify_dmx( hCPE->hStereoDft, sts[0], DFT, hCPE->input_mem[1], hCPE->hStereoCng->prev_sid_nodata ); +#ifdef IVAS_FLOAT_FIXED + { + float max_val = 0.0; + int i_max_val =0; + for (int ii = 0; ii < sizeof(DFT) / sizeof(DFT[0]); ii++) + { + for (int jj = 0; jj < sizeof(DFT[0]) / sizeof(DFT[0][0]); jj++) + { + if (max_val < fabs(DFT[ii][jj])) + { + max_val = (float)fabs(DFT[ii][jj]); + } + } + } + i_max_val = (int)max_val; + hCPE->hStereoDft->q_dft = norm_l(i_max_val) - Q10; + IF (hCPE->hStereoDft->q_dft > Q15) + { + hCPE->hStereoDft->q_dft = Q15; + } + } +#endif } ELSE { @@ -518,7 +540,7 @@ ivas_error ivas_cpe_dec_fx( } } i_max_val = (int)max_val; - hCPE->hStereoDft->q_dft = norm_l(i_max_val) - 6; + hCPE->hStereoDft->q_dft = norm_l(i_max_val) - Q6; IF (hCPE->hStereoDft->q_dft > Q15) { hCPE->hStereoDft->q_dft = Q15; @@ -617,9 +639,21 @@ ivas_error ivas_cpe_dec_fx( /* synthesis iFFT */ FOR( n = 0; n < hCPE->nchan_out; n++ ) { +#ifndef IVAS_FLOAT_FIXED stereo_dft_dec_synthesize( hCPE, DFT, n, output_flt[n], output_frame ); +#else + hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft; + hCPE->lt_es_em_fx = floatToFixed(hCPE->lt_es_em, Q15); + floatToFixed_arrL(&DFT[n][0], &DFT_fx[n][0],hCPE->hStereoDft->q_dft, sizeof(DFT[n]) / sizeof(DFT[0][0])); + floatToFixed_arrL(&hCPE->output_mem[n][0], &hCPE->output_mem_fx[n][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); + stereo_dft_dec_synthesize_fx( hCPE, DFT_fx, n, output[n], output_frame ); + fixedToFloat_arrL(&hCPE->output_mem_fx[n][0], &hCPE->output_mem[n][0], hCPE->hStereoDft->q_dft, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS )); + fixedToFloat_arrL(&DFT_fx[n][0], &DFT[n][0],hCPE->hStereoDft->q_dft, sizeof(DFT_fx[n]) / sizeof(DFT_fx[0][0])); + hCPE->lt_es_em = fixedToFloat(hCPE->lt_es_em_fx, Q15); +#endif } +#if 0 //delete below for (int j = 0; j < output_frame; j++) { @@ -628,6 +662,18 @@ ivas_error ivas_cpe_dec_fx( outputHB_fx[0][j] = (Word32)(outputHB[0][j] * (1 << *q_output)); outputHB_fx[1][j] = (Word32)(outputHB[1][j] * (1 << *q_output)); } +#else + //delete below + for (int j = 0; j < output_frame; j++) + { + output_flt[0][j] = ((float)output[0][j] / (1 << hCPE->hStereoDft->q_dft)); + output_flt[1][j] = ((float)output[1][j] / (1 << hCPE->hStereoDft->q_dft)); + output[0][j] = L_shl(output[0][j], sub(*q_output, hCPE->hStereoDft->q_dft)); + output[1][j] = L_shl(output[1][j], sub(*q_output, hCPE->hStereoDft->q_dft)); + outputHB_fx[0][j] = (Word32)(outputHB[0][j] * (1 << *q_output)); + outputHB_fx[1][j] = (Word32)(outputHB[1][j] * (1 << *q_output)); + } +#endif } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { @@ -901,7 +947,7 @@ ivas_error create_cpe_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); } set32_fx( hCPE->output_mem_fx[i], 0, NS2SA_fx2( output_Fs, STEREO_DFT32MS_OVL_NS ) ); - + hCPE->q_output_mem_fx[i] = 0; IF( LT_16( i, hCPE->nchan_out ) ) { IF( ( hCPE->prev_synth_chs_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_fx2( output_Fs, FRAME_SIZE_NS ) ) ) == NULL ) @@ -939,6 +985,7 @@ ivas_error create_cpe_dec( hCPE->input_mem_BPF_fx[0] = NULL; } hCPE->output_mem_fx[i] = NULL; + hCPE->q_output_mem_fx[i] = 0; hCPE->prev_synth_chs_fx[i] = NULL; #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED hCPE->input_mem[i] = NULL; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 8277e7386ae3417af661e0b796ac1c0bd741b139..8d8612a5b6af08867d647737b0d034cb6098a308 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -965,6 +965,7 @@ typedef struct cpe_dec_data_structure Word32 *input_mem_BPF_fx[1]; Word32 *output_mem_fx[CPE_CHANNELS]; + Word16 q_output_mem_fx[CPE_CHANNELS]; Word32 *prev_synth_chs_fx[CPE_CHANNELS]; /* buffers used for fading between MDCT and DFT Stereo */ diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 85077f96c60f24eaf04ca3378bb0e861e7a1e5b7..f5fd395a10f4c19d6c372b3226d6479813000e87 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -1460,7 +1460,7 @@ void stereo_cna_update_params_fx( } dotLR_fx = Mpy_32_32((Word32)dotLR_fx, energy_xy_fx); dotLR_fx_q = dotLR_fx_q + (31 - temp_res_q) - 31; - dotLR_fx = W_shl(dotLR_fx, 31 - dotLR_fx_q); + dotLR_fx = (Word64)L_shl_sat((Word32)dotLR_fx, 31 - dotLR_fx_q); /* estimate L/R correlation factor and ILD in time domain */ c_LR_fx = extract_h((Word32)dotLR_fx); @@ -1468,7 +1468,7 @@ void stereo_cna_update_params_fx( c_fx = BASOP_Util_Divide3232_Scale((Word32)enrL_fx, (Word32)enrR_fx, &temp_res_q); c_q = 15 - temp_res_q + (y_q - x_q); - Word32 one_in_c_q = 1 << c_q; + Word32 one_in_c_q = L_shl(1 , c_q); Word32 num_c_fx = L_sub(c_fx, one_in_c_q); Word32 denom_c_fx = L_add(c_fx, one_in_c_q); Word16 num_c_headroom = norm_l(L_sub(c_fx, one_in_c_q)); diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 502a4d21031de1fb0abf32f93d98934f6c22c5f1..1c7ab24ca2df5e9a0f0f1dbdb96a06882a6f0e78 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -617,6 +617,7 @@ void stereo_dft_dec_synthesize_fx( Word16 ovl2, flat_portion_end; Word32 ola_buff[STEREO_DFT32MS_OVL2_MAX]; Word16 moffset; + //Word16 scale_dft; push_wmops( "DFT_synthesis" ); /*-----------------------------------------------------------------* @@ -653,7 +654,8 @@ void stereo_dft_dec_synthesize_fx( IF ( EQ_16(hCPE->stereo_switching_counter, 0) ) { /* Set the level of dispersion */ - hCPE->NbFrameMod = (int16_t) ( 12.0f * max( -0.1f, min( 0.4, hCPE->lt_es_em ) ) + 1.2f + 0.5f ); /* -0.1: -0.4 ; -0.1 -> 0, 0.4 -> 6*/ + Word16 tmp = extract_l(L_max( (Word16)0xF333, L_min( (Word16)0x3333, hCPE->lt_es_em_fx ) )); + hCPE->NbFrameMod = extract_h(L_add( L_mult0(12, tmp) , 0x0000D99A )); /* -0.1: -0.4 ; -0.1 -> 0, 0.4 -> 6*/ } moffset = max( 0, 6 - hCPE->NbFrameMod ); @@ -675,7 +677,7 @@ void stereo_dft_dec_synthesize_fx( FOR ( k = 0; k < STEREO_DFT_NBDIV; k++ ) { /* scrambling the spectrum */ - IF ( LE_16(hCPE->stereo_switching_counter , 6) && EQ_16(chan, 1) && ( hCPE->lt_es_em > -0.4f || GT_16(hCPE->NbFrameMod, 4) ) ) + IF ( LE_16(hCPE->stereo_switching_counter , 6) && EQ_16(chan, 1) && ( GT_32(hCPE->lt_es_em_fx , (Word16)0xCCCD) || GT_16(hCPE->NbFrameMod, 4) ) ) { FOR ( i = 3; i < NFFT - moffset - 1; i++ ) { @@ -683,7 +685,7 @@ void stereo_dft_dec_synthesize_fx( move32(); } } - ELSE IF ( LT_16(hCPE->stereo_switching_counter, 7) && ( hCPE->lt_es_em > 0.2f || GT_16(hCPE->NbFrameMod , 4) ) ) + ELSE IF ( LT_16(hCPE->stereo_switching_counter, 7) && ( GT_32(hCPE->lt_es_em_fx , (Word16)0x199A) || GT_16(hCPE->NbFrameMod , 4) ) ) { FOR ( i = sub(16 , hCPE->NbFrameMod); i < sub(NFFT, add(moffset, 1)); i++ ) { @@ -693,7 +695,11 @@ void stereo_dft_dec_synthesize_fx( } /*IFFT*/ + //scale_dft = getScaleFactor32(p_DFT, NFFT); + //scale_dft = find_guarded_bits_fx(NFFT) - scale_dft; + //v_shr(p_DFT, scale_dft, p_DFT, NFFT); rfft_fx( p_DFT, trigo_dec, NFFT, +1 ); + //v_shr(p_DFT, negate(scale_dft), p_DFT, NFFT); IF ( EQ_16(k , 0) ) { @@ -703,7 +709,7 @@ void stereo_dft_dec_synthesize_fx( /* Left OLA - 3.125ms */ FOR ( i = 0; i < ovl; i++ ) { - output[offset + i] = Mpy_32_16_1(L_add(hCPE->output_mem_fx[chan][i], p_DFT[zp + i]), win[STEREO_DFT32MS_STEP * i]); + output[offset + i] = Madd_32_16(L_shr(hCPE->output_mem_fx[chan][i], sub(hCPE->q_output_mem_fx[chan], hCPE->hStereoDft->q_dft)), p_DFT[zp + i], win[STEREO_DFT32MS_STEP * i]); move32(); } /* Flat Portion */ @@ -742,6 +748,7 @@ void stereo_dft_dec_synthesize_fx( hCPE->output_mem_fx[chan][i] = Mpy_32_16_1(p_DFT[NFFT - zp - ovl + i], win[STEREO_DFT32MS_STEP * ( ovl - 1 - i )]); move32(); } + hCPE->q_output_mem_fx[chan] = hCPE->hStereoDft->q_dft; } p_DFT += STEREO_DFT32MS_N_MAX; }