Commit f1932c51 authored by Devansh Kandpal's avatar Devansh Kandpal
Browse files

mid stage changes

parent 2bf3969b
Loading
Loading
Loading
Loading
+62 −29
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ ivas_error ivas_reverb_prepare_cldfb_params(

    Word32 delay_diff_fx, ln_1e6_inverted_fx, L_tmp;
    const Word32 dmx_gain_2_fx = 1852986624; // Q16
    Word16 exp_argument_fx, exp_argument_e, tmp, tmp_flag;
    Word32 exp_argument_fx, exp_argument_e, tmp, tmp_flag;
    Word16 pow_exp;

    Word32 avg_pwr_left_fx[CLDFB_NO_CHANNELS_MAX];
@@ -110,47 +110,80 @@ ivas_error ivas_reverb_prepare_cldfb_params(
    ivas_reverb_interpolate_acoustic_data_fx( pInput_params->nBands, pInput_params->pFc_input_fx, pInput_params->pAcoustic_rt60_fx, pInput_params->pAcoustic_dsr_fx,
                                              CLDFB_NO_CHANNELS_MAX, output_fc_fx, output_t60_fx, output_ene_fx );

    //output_t60_fx is in Q26
    //output_ene_fx is in Q30

    /* adjust DSR for the delay difference */

    delay_diff_fx = L_sub( pInput_params->inputPreDelay_fx, pInput_params->acousticPreDelay_fx );
    delay_diff_fx = L_sub( pInput_params->inputPreDelay_fx, pInput_params->acousticPreDelay_fx ); //Q27

    ln_1e6_inverted_fx = 155440049; // Q31 /* 1.0f / logf( 1e06f ) */

    for ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
    {
        L_tmp = Mpy_32_32( output_t60_fx[idx], ln_1e6_inverted_fx );    // Q26
        exp_argument_fx = BASOP_Util_Divide3232_Scale( delay_diff_fx, L_tmp, &exp_argument_e );
        exp_argument_e = add( exp_argument_e, sub( 4, L_tmp ) ); // Q27 -> e4 (from other function). However, t60 is in Q26. This should be handled appropriately
        L_tmp = Mpy_32_32( output_t60_fx[idx], ln_1e6_inverted_fx );// exp = pRt60_e[bin_idx] + 0
        exp_argument_fx = BASOP_Util_Divide3232_Scale( delay_diff_fx, L_tmp, &exp_argument_e ); //exp_argument_fx in Q14
        //exp_argument_fx = L_shl_sat( exp_argument_fx, exp_argument_e ); //exp_argument_fx converted to Q16
        /* Test Segment Begin*/
        //exp_argument_fx = shl_sat( exp_argument_fx, exp_argument_e ); // Q22
        /* Test Segment End*/

        //exp_argument_e = add( exp_argument_e, sub( 4, pRt60_e[idx] ) ); // Q27 -> e4 -> This step must be adjusted accordingly as per the above two steps

        /* Limit exponent to approx +/-100 dB in case of incoherent value of delay_diff, to prevent overflow */
        // 23 in Q26
        tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( exp_argument_fx ), exp_argument_e, 1543503872, 5 );
        IF( tmp_flag > 0 )
        {
            exp_argument_fx = 23552;
            move16();
            exp_argument_e = 5;
            move16();
        }

        tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( exp_argument_fx ), exp_argument_e, 0, 31 );
        IF( tmp_flag < 0 )
        // Replace by 23 in Q14, only for _fx. 23 in Q14 = 376832
        // Pseudocode
        // IF (GT_32(exp_argument_fx, 376832 ))
        /*{
            assign Q14 equivalent of Left_Shift(23552,5) to exp_argument_fx 
          }
          IF (LT_32(exp_argument_fx, 0))
          {
            tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( negate( exp_argument_fx ) ), exp_argument_e, 1543503872, 5 );
            IF( tmp_flag < 0 )
            {
                exp_argument_fx = -23552;
                move16();
                exp_argument_e = 5;
                move16();
                If(LT_32(negate(exp_argument_fx), 376832))
                {
                    assign Q14 equivalent of Left_Shift(-23552,5) to exp_argument_fx
                }
            }
          }
        */


        // TODO: Convert the capping to the limits
        //tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( exp_argument_fx ), exp_argument_e, 1543503872, 5 );
        //IF( tmp_flag > 0 )
        //{
        //    exp_argument_fx = 23552;
        //    move16();
        //    exp_argument_e = 5; //exponent is 5 because 5 is the offset from Q31 to Q26
        //    move16(); // Same value in Q14 = 184??
        //}

        //tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( exp_argument_fx ), exp_argument_e, 0, 31 );
        //IF( tmp_flag < 0 )
        //{
        //    tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( negate( exp_argument_fx ) ), exp_argument_e, 1543503872, 5 );
        //    IF( tmp_flag < 0 )
        //    {
        //        exp_argument_fx = -23552;
        //        move16();
        //        exp_argument_e = 5;
        //        move16();
        //    }
        //}

        Word16 tmp_exp;
        /* expf(exp_argument) -> pow(2, log2(e) * exp_argument) */
        tmp = mult( 23637, exp_argument_fx );
        tmp_exp = add( exp_argument_e, 1 ); // exp_argument_e + 1
        L_tmp = BASOP_util_Pow2( L_deposit_h( tmp ), tmp_exp, &pow_exp );
        tmp = mult( 23637, exp_argument_fx ); // Q13 : mult(Q14,Q14) results in Q13 // this step denotes x * 1/ln(2)
        //tmp_exp = add( exp_argument_e, 1 ); // exp_argument_e + 1
        //L_tmp = BASOP_util_Pow2( L_deposit_h( tmp ), tmp_exp, &pow_exp );
        L_tmp = BASOP_util_Pow2( tmp, 0, &pow_exp );
        /*  L_tmp = mantissa of the operation
            pow_exp = exponent of the operation
            operation returns 2 ^ ( tmp * 2^(tmp_exp))
        */
        L_tmp = Mpy_32_32( L_tmp, output_ene_fx[idx] );
//        tmp_exp = add( pow_exp, output_ene_e[idx] );

@@ -196,7 +229,7 @@ ivas_error ivas_reverb_prepare_cldfb_params(
        tmp_ene = ( L_add( avg_pwr_left_fx[idx], avg_pwr_right_fx[idx] ) ) >> 1; // Or Madd32_32()??

        // Step 3 : multiply temp variable by gain, with appropriate scaling for Q31 and Q16 multiplication
        tmp_ene = Mpy_32_32( tmp_ene, dmx_gain_2_fx ); // Mpy_32_32_ss multiplies two 32 bit numberrs in 64-bit with saturation or L_mult -> outputs word16
        tmp_ene = Mpy_32_32( tmp_ene, dmx_gain_2_fx ); // Mpy_32_32_ss multiplies two 32 bit numberrs in 64-bit with saturation or L_mult -> outputs word16 // Qfactor of tmp_ene?? dmx_gain_2_fx is in Q16
        // incomplete implentation

        // Step 4 : multiply step 3 result with output energy
@@ -278,7 +311,7 @@ static void ivas_reverb_set_energies(

#ifdef FIX_1741_REVERB_TIMES_Q_FORMAT
    ivas_reverb_interpolate_energies_fx( avg_pwr_len, input_fc_fx, avg_pwr_l, avg_pwr_r,
                                         CLDFB_NO_CHANNELS_MAX, output_fc_fx, avg_pwr_left_fx, avg_pwr_right_fx );
                                         CLDFB_NO_CHANNELS_MAX, output_fc_fx, avg_pwr_left_fx, avg_pwr_right_fx ); //Retains Q-Format
#else
    ivas_reverb_interpolate_acoustic_data_fx( FFT_SPECTRUM_SIZE, input_fc_fx, avg_pwr_l, avg_pwr_r,
                                              CLDFB_NO_CHANNELS_MAX, output_fc_fx, avg_pwr_left_fx, avg_pwr_right_fx, avg_pwr_left_e, avg_pwr_right_e );