Commit fd7c5da5 authored by Manuel Jander's avatar Manuel Jander
Browse files

Fix scaling errors.

parent 1d5ecbb6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4061,7 +4061,7 @@ static void computeTargetPSDs_direct_fx(
    v_mult_fixed( direct_power_factor, reference_power, direct_power, num_freq_bands ); /* Q31 + Q(q_reference_power) - Q31 = Q(q_reference_power) */

#ifdef FIX_867_CLDFB_NRG_SCALE
    Word16 common1_q = s_min( *q_cy_auto_dir_smooth, s_min( q_reference_power[0], q_reference_power[0] ) );
    Word16 common1_q = s_min( *q_cy_auto_dir_smooth, s_min( q_reference_power[0], q_reference_power[1] ) );
    Word16 common2_q = s_min( *q_cy_cross_dir_smooth, s_min( q_reference_power[0], q_reference_power[1] ) );
#else
    Word16 common1_q = s_min( *q_cy_auto_dir_smooth, *q_reference_power );
+64 −1
Original line number Diff line number Diff line
@@ -2808,6 +2808,9 @@ void protoSignalComputation4_fx(
    Word32 sq_tmp_fx;
    Word32 *p_proto_buffer_fx;
    Word16 min_q_shift, q_shift;
#ifdef FIX_867_CLDFB_NRG_SCALE
    Word16 min_q_shift2, q_shift2;
#endif
    Word32 re, im;
    Word16 proto_power_smooth_fx_q, sq_tmp_q;

@@ -2815,6 +2818,12 @@ void protoSignalComputation4_fx(
    move16();
    q_shift = Q31;
    move16();
#ifdef FIX_867_CLDFB_NRG_SCALE
    min_q_shift2 = Q31;
    move16();
    q_shift2 = Q31;
    move16();
#endif
    sq_tmp_q = 0;
    move16();

@@ -2823,16 +2832,52 @@ void protoSignalComputation4_fx(
    /* calculate the shift possible for both RealBuffer_fx and ImagBuffer_fx buffers*/
    FOR( k = 0; k < s_max( 4, nchan_transport ); k++ )
    {
#ifdef FIX_867_CLDFB_NRG_SCALE
        q_shift = L_norm_arr( RealBuffer_fx[k][0], s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands) );
        min_q_shift = s_min( q_shift, min_q_shift );
        q_shift = L_norm_arr( ImagBuffer_fx[k][0], s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands)  );
        min_q_shift = s_min( q_shift, min_q_shift );
        q_shift2 = L_norm_arr( RealBuffer_fx[k][0] + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
        min_q_shift2 = s_min( q_shift2, min_q_shift2 );
        q_shift2 = L_norm_arr( ImagBuffer_fx[k][0] + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
        min_q_shift2 = s_min( q_shift2, min_q_shift2 );
#else
        q_shift = L_norm_arr( RealBuffer_fx[k][0], num_freq_bands );
        min_q_shift = s_min( q_shift, min_q_shift );
        q_shift = L_norm_arr( ImagBuffer_fx[k][0], num_freq_bands );
        min_q_shift = s_min( q_shift, min_q_shift );
#endif
    }
    q_shift = min_q_shift;
    min_q_shift = sub( min_q_shift, find_guarded_bits_fx( i_mult( 2, 4 ) ) );

#ifdef FIX_867_CLDFB_NRG_SCALE
    q_shift2 = min_q_shift2;
    min_q_shift2 = sub( min_q_shift2, find_guarded_bits_fx( i_mult( 2, 4 ) ) );
#endif
    FOR( k = 0; k < 4; k++ )
    {
#ifdef FIX_867_CLDFB_NRG_SCALE
        FOR( l = 0; l < s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ); l++ )
        {
            re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
            im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift

            sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31

            reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 /*0.5 in Q15*/ ); // 2*(q_cldfb+min_q_shift)-31
            move32();
        }
        FOR( l = CLDFB_NO_CHANNELS_HALF; l < num_freq_bands; l++ )
        {
            re = L_shl( RealBuffer_fx[k][0][l], min_q_shift2 ); // q_cldfb+min_q_shift
            im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift2 ); // q_cldfb+min_q_shift

            sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31

            reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 /*0.5 in Q15*/ ); // 2*(q_cldfb+min_q_shift)-31
            move32();
        }
#else
        FOR( l = 0; l < num_freq_bands; l++ )
        {
            re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
@@ -2843,12 +2888,24 @@ void protoSignalComputation4_fx(
            reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 /*0.5 in Q15*/ ); // 2*(q_cldfb+min_q_shift)-31
            move32();
        }
#endif
    }
#ifdef FIX_867_CLDFB_NRG_SCALE
    sq_tmp_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
    reference_power_q[0] = sq_tmp_q;
    move16();
    sq_tmp_q = sub( add( add( q_cldfb, min_q_shift2 ), add( q_cldfb, min_q_shift2 ) ), 31 );
    reference_power_q[1] = sq_tmp_q;
    move16();

    min_q_shift = sub( s_min( q_shift, q_shift2 ), find_guarded_bits_fx( 2 ) );
#else
    sq_tmp_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
    *reference_power_q = sub( add( sq_tmp_q, Q15 ), 15 );
    move16();

    min_q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) );
#endif

    /*For decorrelated diffuseness*/
    FOR( l = 0; l < num_outputs_diff; l++ )
@@ -2931,8 +2988,14 @@ void protoSignalComputation4_fx(

    *proto_direct_buffer_f_q = *proto_frame_f_q;
    move16();
#ifdef FIX_867_CLDFB_NRG_SCALE
    proto_power_smooth_q[0] = proto_power_smooth_fx_q;
    proto_power_smooth_q[1] = proto_power_smooth_fx_q;
    move16(); move16();
#else
    *proto_power_smooth_q = proto_power_smooth_fx_q;
    move16();
#endif

    return;
}
+4 −4
Original line number Diff line number Diff line
@@ -8460,11 +8460,11 @@ static void intermidiate_ext_dirac_render(
            move16();
            FOR( slot_idx = 0; slot_idx < hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len; slot_idx = add( slot_idx, hSpatParamRendCom->num_freq_bands ) )
            {
                tmp = s_min( tmp, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + slot_idx, CLDFB_NO_CHANNELS_HALF ) );
                tmp = s_min( tmp, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + slot_idx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF) ) );
            }
            FOR( slot_idx = 0; slot_idx < hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len; slot_idx = add( slot_idx, hSpatParamRendCom->num_freq_bands ) )
            {
                scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + slot_idx, CLDFB_NO_CHANNELS_HALF, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + tmp) */
                scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + slot_idx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF) , tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + tmp) */
            }
            hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], tmp );
            move16();
@@ -8472,11 +8472,11 @@ static void intermidiate_ext_dirac_render(
            move16();
            FOR( slot_idx = 0; slot_idx < hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len; slot_idx = add( slot_idx, hSpatParamRendCom->num_freq_bands ) )
            {
                tmp = s_min( tmp, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + slot_idx + CLDFB_NO_CHANNELS_HALF, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
                tmp = s_min( tmp, L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + slot_idx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) ) );
            }
            FOR( slot_idx = 0; slot_idx < hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len; slot_idx = add( slot_idx, hSpatParamRendCom->num_freq_bands ) )
            {
                scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + slot_idx + CLDFB_NO_CHANNELS_HALF, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + tmp) */
                scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + slot_idx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + tmp) */
            }
            hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], tmp );
            move16();