Commit 4a1bf2cf authored by Dominik Weckbecker's avatar Dominik Weckbecker 💬
Browse files

fix problems with division in running average

parent ce42f33e
Loading
Loading
Loading
Loading
Loading
+54 −29
Original line number Diff line number Diff line
@@ -2122,40 +2122,65 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx(
    p_power_smooth = h_dirac_output_synthesis_state->proto_power_smooth_fx;
    set16_fx( exp_arr, 0, i_mult( num_protos_dir, num_freq_bands ) );

	FOR(k = 0; k < 1; k++)
	{
		FOR(l = 0; l < num_freq_bands; l++)
		{
			static FILE *f = 0;
			if (f == 0)
				f = fopen("p_power_smooth0", "w");

			Word32 m = h_dirac_output_synthesis_state->proto_power_smooth_fx[k*num_protos_dir + l];
			Word16 e = h_dirac_output_synthesis_state->proto_power_smooth_q;
			float f1_m = (float)m;
			float f1_e = powf(2, e);
			float f1 = f1_m / f1_e;
			fprintf(f, "%d %d %d %f\n", l, m, e, f1);
		}
	}

    FOR( k = 0; k < num_protos_dir; k++ )
    {
        FOR( l = 0; l < num_freq_bands; l++ )
        {
            g1 = alpha[l]; // Q31
            move32();
            g2 = L_sub( ONE_IN_Q31, g1 );                                                          // Q31
            *p_power_smooth_prev = L_add( EPSILON_FX, Mpy_32_32( g2, ( *p_power_smooth_prev ) ) ); //(Q31, q_proto_power_smooth) -> q_proto_power_smooth
            move32();
            *( p_power_smooth_prev ) = L_add( *( p_power_smooth_prev ), Mpy_32_32( g1, ( *p_power_smooth ) ) ); //(Q31, q_proto_power_smooth) -> q_proto_power_smooth
			Word16 exp_tmp_1; // exp for p_power_smooth_prev

            g2 = L_sub( ONE_IN_Q31, alpha[l] ); // Q31
            
			L_tmp =  Madd_32_32( Mpy_32_32( g2, *p_power_smooth_prev), alpha[l], *p_power_smooth ); //(Q31, q_proto_power_smooth) -> q_proto_power_smooth

			L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, 
				      sub(31, h_dirac_output_synthesis_state->proto_power_smooth_q),
				      EPSILON_FX_M, EPSILON_FX_E, &exp_tmp_1 
			);

			*(p_power_smooth_prev++) = L_tmp;
			move32();
#ifndef FIX_867_2
            IF( EQ_32( *( p_power_smooth_prev ), EPSILON_FX ) )
            {
                p_power_smooth_prev++;
                L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, EPSILON_FX, &exp ); /*Q=31-(exp-(31-q_proto_power_smooth))*/
                exp_arr[k * num_freq_bands + l] = exp;

            L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, L_tmp, &exp ); /*Q=31-(exp-exp_tmp_1)*/
            exp_arr[k * num_freq_bands + l] = sub(exp,exp_tmp_1);
            move16();

                *( p_power_smooth++ ) = L_tmp; /*Q=31-(exp-(31-q_proto_power_smooth))*/
            *( p_power_smooth++ ) = L_tmp; /*Q=31-(exp-exp_tmp_1))*/
            move32();
        }
            ELSE
    }

	FOR(k = 0; k < 1; k++)
	{
#endif
                L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, *( p_power_smooth_prev++ ), &exp ); /*Q=31-(exp-(31-q_proto_power_smooth))*/
                exp_arr[k * num_freq_bands + l] = exp;
                move16();
		FOR(l = 0; l < num_freq_bands; l++)
		{
			static FILE *f = 0;
			if (f == 0)
				f = fopen("p_power_smooth1", "w");

                *( p_power_smooth++ ) = L_tmp; /*Q=31-(exp-(31-q_proto_power_smooth))*/
                move32();
#ifndef FIX_867_2
            }
#endif
			Word32 m = h_dirac_output_synthesis_state->proto_power_smooth_fx[k*num_protos_dir + l];
			q_tmp = sub(31, exp_arr[k * num_freq_bands + l]);
			Word16 e = q_tmp;
			float f1_m = (float)m;
			float f1_e = powf(2, e);
			float f1 = f1_m / f1_e;
			fprintf(f, "%d %d %d %f\n", l, m, e, f1);
		}
	}

@@ -2187,7 +2212,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx(
            *p_power_smooth = L_shr( *p_power_smooth, sub( min_exp, exp_arr[k * num_freq_bands + l] ) ); /*(31-(exp-(31-q_proto_power_smooth)))->(31-(min_exp-(31-q_proto_power_smooth)))*/
            move32();
            p_power_smooth++;
            q_tmp = add( sub( Q31, min_exp ), sub( Q31, h_dirac_output_synthesis_state->proto_power_smooth_q ) );
            q_tmp = sub(31, exp_arr[k * num_freq_bands + l]);
        }
    }