Commit fb97ac08 authored by emerit's avatar emerit
Browse files

Merge branch 'main' into update_crend

parents 0eecbb1b 1bedf9e1
Loading
Loading
Loading
Loading
+21 −26
Original line number Diff line number Diff line
@@ -2866,29 +2866,29 @@ void GenShapedSHBExcitation_ivas_fx(

    FOR( i = 0; i < L_FRAME32k; i = i + 2 )
    {
        exc32k[i] = negate( bwe_exc_extended[i] );
        exc32k[i] = negate( bwe_exc_extended[i] ); // Q_bwe_exc
        move16();
        exc32k[i + 1] = bwe_exc_extended[i + 1];
        exc32k[i + 1] = bwe_exc_extended[i + 1]; // Q_bwe_exc
        move16();
    }

    /* Decimate by 2 */
    Decimate_allpass_steep_fx( exc32k, mem_genSHBexc_filt_down_shb, 2 * L_FRAME16k, exc16k );
    Decimate_allpass_steep_fx( exc32k, mem_genSHBexc_filt_down_shb, 2 * L_FRAME16k, exc16k ); // Q_bwe_exc
    /* i: exc32k in Q_bwe_exc */
    /* o: exc16k in Q_bwe_exc */

    autocorr_fx( exc16k, LPC_WHTN_ORDER + 1, R_h, R_l, &Q_R, L_FRAME16k, win_flatten_fx, 0, 1 );
    autocorr_fx( exc16k, LPC_WHTN_ORDER + 1, R_h, R_l, &Q_R, L_FRAME16k, win_flatten_fx, 0, 1 ); // Q_R
    /* Ensure R[0] isn't zero when entering Levinson Durbin */
    R_l[0] = s_max( R_l[0], 1 );
    move16();
    FOR( i = 1; i <= LPC_WHTN_ORDER; i++ )
    {
        L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] );
        L_Extract( L_tmp, &R_h[i], &R_l[i] );
        L_Extract( L_tmp, &R_h[i], &R_l[i] ); // Q_R
    }
    E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER, NULL );
    Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER + 1, sub( norm_s( lpc_whtn[0] ), 2 ) );
    fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 );
    Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER + 1, sub( norm_s( lpc_whtn[0] ), 2 ) ); // Q12
    fir_fx( exc16k, lpc_whtn, exc16kWhtnd, wht_fil_mem, L_FRAME16k, LPC_WHTN_ORDER, 0, 3 );    // Q_bwe_exc

    /* i: exc16k in Q_bwe_exc */
    /* o: exc16kWhtnd in Q_bwe_exc */
@@ -2907,7 +2907,7 @@ void GenShapedSHBExcitation_ivas_fx(
            move16();
            FOR( i = 0; i < 80; i++ )
            {
                exc16kWhtnd[temp2 + i] = round_fx( L_shl( L_mult( exc16kWhtnd[temp2 + i], temp1 ), 1 ) );
                exc16kWhtnd[temp2 + i] = round_fx( L_shl( L_mult( exc16kWhtnd[temp2 + i], temp1 ), 1 ) ); // Q_bwe_exc
                move16();
                /* exc16kWhtnd in Q_bwe_exc, shb_res_gshape in Q14 */
            }
@@ -2982,9 +2982,9 @@ void GenShapedSHBExcitation_ivas_fx(
    varEnvShape = s_max( varEnvShape, 9830 /*0.3f Q15*/ );
    varEnvShape = s_min( varEnvShape, 16368 /*0.4995f Q15*/ );
    varEnvShape = shl( varEnvShape, 1 );
    csfilt_num2[0] = sub( MAX_16, varEnvShape );
    csfilt_num2[0] = sub( MAX_16, varEnvShape ); // Q15
    move16();
    neg_csfilt_den2[1] = varEnvShape;
    neg_csfilt_den2[1] = varEnvShape; // Q15
    move16();

    test();
@@ -3036,7 +3036,7 @@ void GenShapedSHBExcitation_ivas_fx(

    White_exc16k = exc16k;
    move16();
    Word16 Q_excTmp2 = add( getScaleFactor16( excTmp2, L_FRAME16k ), *Q_bwe_exc );
    Word16 Q_excTmp2 = sub( add( s_min( getScaleFactor16( excTmp2, L_FRAME16k ), norm_l( *mem_csfilt ) ), *Q_bwe_exc ), 1 );
    test();
    /* Track the low band envelope */
    IF( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT )
@@ -3079,7 +3079,7 @@ void GenShapedSHBExcitation_ivas_fx(
#endif
    {
        /* Track the low band envelope */
        L_tmp = *mem_csfilt;
        L_tmp = L_shl( *mem_csfilt, sub( Q_excTmp2, *Q_bwe_exc ) );
        move32();
        FOR( i = 0; i < L_FRAME16k; i++ )
        {
@@ -3089,7 +3089,7 @@ void GenShapedSHBExcitation_ivas_fx(
             *mem_csfilt: Q_excTmp2+16, excTmp2: Q_excTmp2, csfilt_num2[0] Q_excTmp2  */
            L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_excTmp2 + 16 */
        }
        *mem_csfilt = L_tmp;
        *mem_csfilt = L_shr( L_tmp, sub( Q_excTmp2, *Q_bwe_exc ) );
        move32();
    }
#if 1 // def ADD_IVAS_TBE_CODE
@@ -3141,20 +3141,15 @@ void GenShapedSHBExcitation_ivas_fx(
        /* create a random excitation - Reuse exc16k memory */
        White_exc16k = exc16k;
        move16();
        create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed );
        create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed );
        create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed );                        // Q5
        create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); // Q5

        L_tmp = L_deposit_l( 0 );
        tmp = add( *Q_bwe_exc, 1 );
        FOR( k = 0; k < L_FRAME16k; k++ )
        {
#ifdef BASOP_NOGLOB
            L_tmp4 = L_shl_sat( L_deposit_l( White_exc16k[k] ), tmp );
#else
            L_tmp4 = L_shl( L_deposit_l( White_exc16k[k] ), tmp );
#endif
            L_tmp4 = L_mult( shr( excNoisyEnv[k], sub( Q_excTmp2, *Q_bwe_exc ) ), White_exc16k[k] ); /* (Q_bwe_exc)  +5 +1*/
            White_exc16k_32[k] = L_tmp4;
            L_tmp4 = L_mult( shr( excNoisyEnv[k], sub( Q_excTmp2, *Q_bwe_exc ) ), White_exc16k[k] ); /* (Q_excTmp2)  +5 +1*/
            White_exc16k_32[k] = L_tmp4;                                                             /* (Q_excTmp2)  +5 +1*/
            move32();
            L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) );
        }
@@ -3175,10 +3170,10 @@ void GenShapedSHBExcitation_ivas_fx(
        FOR( k = 0; k < L_FRAME16k; k++ )
        {
            /* White_exc16k[k] *= excNoisyEnv[k]; */
            White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], tmp ) );
            White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], tmp ) ); // Q_excTmp2 + 5 + 1 - 15 ==> Q_excTmp2 - 9
            move16();
            chk2 = s_or( chk2, White_exc16k[k] );
            /* i: excNoisyEnv in (Q_bwe_exc)     */
            /* i: excNoisyEnv in (Q_excTmp2)     */
            /* i: White_exc16k  in Q6               */
            /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ)  */
            /* pow22 += White_exc16k[k] * White_exc16k[k]; */
@@ -3500,11 +3495,11 @@ void GenShapedSHBExcitation_ivas_fx(
    tmp = sub( Q_temp, 3 );
    FOR( k = 0; k < L_FRAME16k; k++ )
    {
        White_exc16k_FB[k] = round_fx( L_shl( White_exc16k_32[k], tmp ) ); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */
        White_exc16k_FB[k] = White_exc16k[k]; /* Q_bwe_exc-NOISE_QADJ */
    }
    prev_Q_bwe_exc_fb = *Q_bwe_exc_fb;
    move16();
    *Q_bwe_exc_fb = sub( add( *Q_bwe_exc, Q_temp ), 13 );
    *Q_bwe_exc_fb = sub( *Q_bwe_exc, NOISE_QADJ );
    move16();
    deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph );
    /* i/o: White_exc16k (Q_bwe_exc-NOISE_QADJ) */
+1 −36
Original line number Diff line number Diff line
@@ -415,8 +415,6 @@ ivas_error ivas_jbm_dec_tc_fx(
                move16();
                nchan_out = nchan_transport;
                move16();
                hSpar->hMdDec->Q_mixer_mat = 31;
                move16();
                ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx ), ( p_output_fx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame );

                IF( st_ivas->hSpar->hPCA != NULL )
@@ -532,8 +530,6 @@ ivas_error ivas_jbm_dec_tc_fx(
                    hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft;
                    move16();
                }
                st_ivas->hSpar->hMdDec->Q_mixer_mat = 30;
                move16();
                FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ )
                {
                    scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) );
@@ -633,8 +629,6 @@ ivas_error ivas_jbm_dec_tc_fx(
                    hCPE->hStereoDft->q_ap_fade_mem_fx = Q11;
                    test();
                }
                st_ivas->hSpar->hMdDec->Q_mixer_mat = 30;
                test();
                FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ )
                {
                    scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) );
@@ -690,9 +684,6 @@ ivas_error ivas_jbm_dec_tc_fx(
                    Scale_sig32( p_output_fx[ch], output_frame, Q_p_output );
                }

                hSpar->hMdDec->Q_mixer_mat = 31;
                move16();

                ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, p_output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, Q_p_output );
                FOR( Word16 c = 0; c < nchan_transport; c++ )
                {
@@ -964,8 +955,6 @@ ivas_error ivas_jbm_dec_tc_fx(
            move16();
            nchan_out = nchan_transport;
            move16();
            hSpar->hMdDec->Q_mixer_mat = 31;
            move16();
            ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx + sba_ch_idx ), ( p_output_fx + sba_ch_idx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame );

            IF( st_ivas->hSpar->hPCA != NULL )
@@ -1019,8 +1008,6 @@ ivas_error ivas_jbm_dec_tc_fx(
                    hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft;
                    move16();
                }
                st_ivas->hSpar->hMdDec->Q_mixer_mat = Q30;
                move32();

                IF( hSCE != NULL )
                {
@@ -1076,8 +1063,7 @@ ivas_error ivas_jbm_dec_tc_fx(
                    hCPE->hStereoDft->q_ap_fade_mem_fx = Q11;
                    move16();
                }
                st_ivas->hSpar->hMdDec->Q_mixer_mat = 30;
                move16();

                FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ )
                {
                    scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) );
@@ -1549,8 +1535,6 @@ ivas_error ivas_jbm_dec_tc_fx(
                }
                IF( st_ivas->hSpar != NULL )
                {
                    st_ivas->hSpar->hMdDec->Q_mixer_mat = 31;
                    move16();
                    FOR( Word16 ii = 0; ii < CPE_CHANNELS; ii++ )
                    {
                        scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) );
@@ -2314,11 +2298,6 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx(
        st_ivas->hTcBuffer->q_tc_fx = 11;
        move16();
    }
    if ( st_ivas->hSpar )
    {
        st_ivas->hSpar->hMdDec->Q_mixer_mat = 31;
        move16();
    }
    Word16 n, n_render_timeslots;

    push_wmops( "ivas_jbm_dec_feed_tc_to_rendererer" );
@@ -2996,11 +2975,6 @@ ivas_error ivas_jbm_dec_render_fx(
        }
        ELSE
        {
            SPAR_DEC_HANDLE hSpar;
            hSpar = st_ivas->hSpar;
            hSpar->hMdDec->Q_mixer_mat = 30;
            move16();

            IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK )
            {
                return error;
@@ -3087,11 +3061,6 @@ ivas_error ivas_jbm_dec_render_fx(
            }
            ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) /*EXT output = individual objects + HOA3*/
            {
                SPAR_DEC_HANDLE hSpar;
                hSpar = st_ivas->hSpar;
                hSpar->hMdDec->Q_mixer_mat = 30;
                move16();

                IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960 ) ) != IVAS_ERR_OK )
                {
                    return error;
@@ -3104,10 +3073,6 @@ ivas_error ivas_jbm_dec_render_fx(
            }
            ELSE
            {
                SPAR_DEC_HANDLE hSpar;
                hSpar = st_ivas->hSpar;
                hSpar->hMdDec->Q_mixer_mat = 30;

                IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK )
                {
                    return error;
+2 −0
Original line number Diff line number Diff line
@@ -404,6 +404,8 @@ ivas_error ivas_spar_dec_open_fx(
            }
        }
    }
    hSpar->hMdDec->Q_mixer_mat = Q31;
    move16();
    hSpar->i_subframe = 0;
    move16();
    hSpar->AGC_flag = 0;
+8 −3
Original line number Diff line number Diff line
@@ -2486,7 +2486,8 @@ static void ivas_get_spar_matrices_fx(
                    ivas_mat_col_rearrange_fx( tmp_C1_re_fx, order, i_ts, hMdDec->mixer_mat_fx, b, numch_out );
                }
            }

            hMdDec->Q_mixer_mat = Q30;
            move16();
            IF( dmx_ch > 0 )
            {
                Word32 tmpC_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
@@ -2723,6 +2724,8 @@ void ivas_spar_dec_gen_umx_mat_fx(
            }
        }
    }
    hMdDec->Q_mixer_mat = Q30;
    move16();
    ivas_spar_dec_compute_ramp_down_post_matrix_fx( hMdDec, num_bands_out, bfi, num_md_sub_frames );
    return;
}
@@ -4195,6 +4198,8 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx(
            }
            Q_post_matrix = sub( add( Q_gain, norm_nff ), 15 );
            /* apply the post matrix */
            hMdDec->Q_mixer_mat = sub( add( Q_post_matrix, hMdDec->Q_mixer_mat ), 31 );
            move16();
            FOR( Word16 i_ts = 0; i_ts < num_md_sub_frames; i_ts++ )
            {
                FOR( i = 0; i < num_out_ch; i++ )
@@ -4203,13 +4208,13 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx(
                    {
                        FOR( b = 0; b < num_bands_out; b++ )
                        {
                            hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = Mult_32_32( hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] );
                            hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl( Mult_32_32( hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] ), sub( Q30, hMdDec->Q_mixer_mat ) ); // Q30
                            move32();
                        }
                    }
                }
            }
            hMdDec->Q_mixer_mat = sub( add( Q_post_matrix, hMdDec->Q_mixer_mat ), 31 );
            hMdDec->Q_mixer_mat = Q30;
            move16();
        }
    }
+34 −31
Original line number Diff line number Diff line
@@ -683,7 +683,7 @@ static void stereo_dft_generate_comfort_noise_fx(
    Decoder_State *st,                            /* i/o: Core coder decoder state                       */
    Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers                                    */
    Decoder_State *st1,                           /* i/o: Core coder decoder state secondary channel     */
    const Word16 targetGain,                      /* i  : ICA target gain                            */
    const Word16 targetGain,                      /* i  : ICA target gain                            Q13 */
    const Word16 chan,                            /* i  : channel number                                 */
    const Word16 output_frame,                    /* i  : output frame size                              */
    Word16 q_dft                                  /* i  : Q of DFT                                       */
@@ -710,10 +710,10 @@ static void stereo_dft_generate_comfort_noise_fx(
    Word16 b, q_cngNoiseLevel_upd, q_cngNoiseLevel;
    Word32 *pSideGain;
    Word16 gamma;
    Word16 c;
    Word16 c, c_e;
    Word16 scaleMS;
    Word16 scaleAvg;
    Word16 LR_ratio;
    Word16 scaleAvg, scaleAvg_e;
    Word16 LR_ratio; /* Q15 */
    Word32 factor;
    Word16 alpha;
    Word32 ftmp;
@@ -807,6 +807,8 @@ static void stereo_dft_generate_comfort_noise_fx(
        {
            scaleAvg = 0;
            move16();
            scaleAvg_e = 15;
            move16();
            FOR( b = 0; b < hStereoDft->nbands; b++ )
            {
                IF( LT_16( hStereoCng->cm_fx[b], 0x7333 ) )
@@ -827,36 +829,37 @@ static void stereo_dft_generate_comfort_noise_fx(
                    move16();
                }

                LR_ratio = extract_h( tdm_ratio_tabl_fx[hStereoCng->last_tdm_idx] );
                LR_ratio = extract_h( tdm_ratio_tabl_fx[hStereoCng->last_tdm_idx] ); /* Q15 */
                c = BASOP_Util_Divide3232_Scale(
                    L_add( L_mult( add( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ),
                                   add( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ) ),
                           L_shr( L_mult( gamma, gamma ), 4 ) ),
                    L_add( Mpy_32_32( sub( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ),
                    L_add( L_mult( sub( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ),
                                   sub( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ) ),
                           L_shr( L_mult( gamma, gamma ), 4 ) ),
                    &q_div );
                q_sqrt = q_div;
                    &c_e );
                q_sqrt = c_e;
                move16();
                sqrt_res = Sqrt16( mult( c, hStereoCng->cm_fx[b] ), &q_sqrt );
                // Add 1 to q_sqrt to account for multiplication with 2.0 in float computation.
                q_sqrt = add( q_sqrt, 1 );
                tmp32_1 = L_add( L_add( L_shl( 1, sub( Q15, q_div ) ), c ), L_shr( L_deposit_l( sqrt_res ), sub( q_div, q_sqrt ) ) );
                q_sqrt = q_div;
                tmp32_1 = L_add( L_add( L_shl( 1, sub( Q15, c_e ) ), c ), L_shl( L_deposit_l( sqrt_res ), sub( add( q_sqrt, 1 ), c_e ) ) ); /* Q(15 - c_e) */ /* +1 to account for multiplication with 2 */
                move16();
                // scaleMS = (1 + c + 2 * sqrtf(c * hStereoCng->cm[b])) / (4 * (c * LR_ratio * LR_ratio + (1 - LR_ratio) * (1 - LR_ratio) * targetGain * targetGain + 2 * LR_ratio * (1 - LR_ratio) * targetGain * sqrtf(c * hStereoCng->cm[b])));
                sqrt_res = Sqrt16( mult( c, hStereoCng->cm_fx[b] ), &q_sqrt );
                tmp32_2 = L_shl( L_add( L_shl( L_deposit_l( mult( c, mult( LR_ratio, LR_ratio ) ) ), q_div ),
                                        L_add( mult( mult( sub( MAX_16, LR_ratio ), sub( MAX_16, LR_ratio ) ), mult( targetGain, targetGain ) ),
                                               L_shl( L_deposit_l( mult( mult( LR_ratio, sub( MAX_16, LR_ratio ) ), mult( targetGain, sqrt_res ) ) ), add( 1, q_sqrt ) ) ) ), // add(1, q_sqrt) to account for multiplication with 2 and also to maintain uniform q.
                                 2 );
                scaleMS = BASOP_Util_Divide3232_Scale( tmp32_1, tmp32_2, &q_div );
                q_sqrt = q_div;
                tmp32_2 = L_deposit_l( mult( c, mult( LR_ratio, LR_ratio ) ) ); /* Q(15 - c_e) */
                /* (1 - LR_ratio) * (1 - LR_ratio) * targetGain * targetGain */
                tmp32_2 = L_add( tmp32_2, L_shl( mult( mult( sub( MAX_16, LR_ratio ), sub( MAX_16, LR_ratio ) ), mult( targetGain, targetGain ) ), sub( Q4, c_e ) ) ); /* Q(15 - c_e) */
                /* 2 * LR_ratio * (1 - LR_ratio) * targetGain * sqrtf(c * hStereoCng->cm[b]) */
                tmp32_2 = L_add( tmp32_2, L_shl( L_deposit_l( mult( mult( LR_ratio, sub( MAX_16, LR_ratio ) ), mult( targetGain, sqrt_res ) ) ), sub( add( q_sqrt, 3 ), c_e ) ) ); /* Q(15 - c_e) */ /* +1 to account for multiplication with 2 */
                tmp32_2 = L_shl( tmp32_2, 2 );
                scaleMS = BASOP_Util_Divide3232_Scale( tmp32_1, tmp32_2, &c_e );
                q_sqrt = c_e;
                move16();
                scaleMS = Sqrt16( scaleMS, &q_sqrt );
                scaleAvg = add( scaleAvg, shr( scaleMS, sub( Q15, q_sqrt ) ) );
                scaleAvg_e = BASOP_Util_Add_MantExp( scaleAvg, scaleAvg_e, scaleMS, q_sqrt, &scaleAvg );
            }
            scaleAvg = BASOP_Util_Divide1616_Scale( scaleAvg, hStereoDft->nbands, &q_div );
            hStereoDft->scale_fx = shl_sat( scaleAvg, q_div );
            scaleAvg = BASOP_Util_Divide1616_Scale( scaleAvg, hStereoDft->nbands, &c_e );
            c_e = sub( add( c_e, scaleAvg_e ), 15 );
            hStereoDft->scale_fx = shl_sat( scaleAvg, c_e );
            move16();
        }
    }