Commit bb427c09 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

BASOP and instrumentation updates for decoder and renderer files

[x] BASOP added for lib_rend and lib_dec files
[x] Unnecessary code duplication cleared as mentioned in issue 805
parent b375b255
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -524,7 +524,7 @@ void hp400_12k8_fx(
    Word16 mem[]     /* i/o: filter memory [6]                      */
);

#ifdef IVAS_FLOAT_FIXED
#if 0
void hp400_12k8_ivas_fx(
    Word16 signal[], /* i/o: input signal / output is divided by 16 */
    const Word16 lg, /* i  : lenght of signal                       */
+0 −190
Original line number Diff line number Diff line
@@ -56,9 +56,6 @@
static void create_random_vector( float output[], const int16_t length, int16_t seed[] );
static void flip_spectrum( const float input[], float output[], const int16_t length );
static void Hilbert_transform( float tmp_R[], float tmp_I[], float *tmpi_R, float *tmpi_I, const int16_t length, const int16_t HB_stage_id );
#ifdef IVAS_FLOAT_FIXED
static void Hilbert_transform_fx_32( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id );
#endif
static void Estimate_mix_factors( const float *shb_res, const float *exc16kWhtnd, const float *White_exc16k, const float pow1, const float pow22, float *vf_modified, int16_t *vf_ind );

/*-------------------------------------------------------------------*
@@ -241,133 +238,6 @@ void flip_and_downmix_generic(

    return;
}
#ifdef IVAS_FLOAT_FIXED
void flip_and_downmix_generic_fx_32(
    Word32 input[],                      /* i : input spectrum Qx*/
    Word32 output[],                     /* o : output spectrum Qx*/
    const Word16 length,                 /* i : length of spectra */
    Word32 mem1_ext[HILBERT_ORDER1],     /* i/o: memory Qx*/
    Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/
    Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/
    Word16 *phase_state                  /* i/o: Phase state in case frequency isn't multiple of 50 Hz */
)
{
    Word16 i, j;
    Word32 tmp[L_FRAME32k + HILBERT_ORDER1];
    Word32 tmpi_R[L_FRAME32k];
    Word32 tmpi_I[L_FRAME32k];
    Word32 tmpi2_R[L_FRAME32k + HILBERT_ORDER2];
    Word32 tmpi2_I[L_FRAME32k + HILBERT_ORDER2];
    Word32 tmp_R[L_FRAME32k + HILBERT_ORDER2];
    Word32 tmp_I[L_FRAME32k + HILBERT_ORDER2];

    /*Word16 s_tmp[L_FRAME32k];*/
    /*Word16 factor;*/
    Word16 period;
    Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580,
                                        -26319, -17530, -6393, 6393, 17530, 26319,
                                        31580, 32609, 29268, 22005, 11793 }; /* Q15 */
    Word16 local_cos_table17[17] = { 32767, 30571, 24279, 14732, 3212, -8739,
                                     -19519, -27683, -32137, -32137, -27683,
                                     -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */
    Word16 *local_negsin_table, *local_cos_table;
    Word32 L_tmp;

    /* 1850 Hz downmix */
    period = 17;
    move16();
    local_negsin_table = local_negsin_table17;
    local_cos_table = local_cos_table17;


    FOR( i = 0; i < length; i = i + 2 )
    {
        input[i] = L_negate( input[i] );
        move16();
    }

    Copy32( input, tmp + HILBERT_ORDER1, length );
    Copy32( mem1_ext, tmp, HILBERT_ORDER1 );

    /* Hilber transform stage - 0 - single precision */
    Hilbert_transform_fx_32( tmp,    /* i: Real component of HB */
                             tmp,    /* i: Imag component of HB */
                             tmpi_R, /* o: Real component of HB */
                             tmpi_I, /* o: Imag. component of HB */
                             length, /* i: length of the spectra */
                             0 );    /* i: HB transform stage */


    Copy32( mem2_ext, tmpi2_R, HILBERT_ORDER2 );
    Copy32( mem3_ext, tmpi2_I, HILBERT_ORDER2 );

    /* Hilber transform stage - 1 */
    Hilbert_transform_fx_32( tmpi_R,  /* i: Real component of HB */
                             tmpi_I,  /* i: Imag component of HB */
                             tmpi2_R, /* o: Real component of HB */
                             tmpi2_I, /* o: Imag. component of HB */
                             length,  /* i: length of the spectra */
                             1 );     /* i: HB transform stage */
    Copy32( tmp + length, mem1_ext, HILBERT_ORDER1 );
    Copy32( mem2_ext + HILBERT_ORDER2, tmp_R, HILBERT_ORDER2 );
    Copy32( mem3_ext + HILBERT_ORDER2, tmp_I, HILBERT_ORDER2 );

    /* Hilber transform stage - 2 */
    Hilbert_transform_fx_32( tmpi2_R, /* i: Real component of HB */
                             tmpi2_I, /* i: Imag component of HB */
                             tmpi_R,  /* o: Real component of HB */
                             tmpi_I,  /* o: Imag. component of HB */
                             length,  /* i: length of the spectra */
                             2 );     /* i: HB transform stage */

    Copy32( tmpi2_R + length, mem2_ext, HILBERT_ORDER2 );
    Copy32( tmpi2_I + length, mem3_ext, HILBERT_ORDER2 );

    /* Hilber transform stage - 3 */
    Hilbert_transform_fx_32( tmpi_R, /* i: Real component of HB */
                             tmpi_I, /* i: Imag component of HB */
                             tmp_R,  /* o: Real component of HB */
                             tmp_I,  /* o: Imag. component of HB */
                             length, /* i: length of the spectra */
                             3 );    /* i: HB transform stage */

    Copy32( tmp_R + length, mem2_ext + HILBERT_ORDER2, HILBERT_ORDER2 );
    Copy32( tmp_I + length, mem3_ext + HILBERT_ORDER2, HILBERT_ORDER2 );

    if ( *phase_state >= period )
    {
        *phase_state = 0;
        move16();
    }

    i = 0;
    move16();
    j = *phase_state;
    move16();

    WHILE( i < length )
    {
        WHILE( ( j < period ) && ( i < length ) )
        {
            L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] );           /*//Qx+16 */
            L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */
            output[i] = L_tmp;                                                /*Qx */
            i++;
            j++;
        }

        if ( j >= period )
        {
            j = 0;
            move16();
        }
    }

    *phase_state = j;
    move16();
    return;
}
#endif

/*----------------------------------------------
 * Hilbert_transform()
@@ -411,66 +281,6 @@ static void Hilbert_transform(
    return;
}

#ifdef IVAS_FLOAT_FIXED
static void Hilbert_transform_fx_32(
    Word32 tmp_R[],          /* i: Real component of HB */
    Word32 tmp_I[],          /* i: Real component of HB */
    Word32 tmpi_R[],         /* o: Real component of HB */
    Word32 tmpi_I[],         /* o: Imag. component of HB */
    const Word16 length,     /* i: input length */
    const Word16 HB_stage_id /* i: HB transform stage */
)
{
    Word16 i, hb_filter_stage, offset;
    Word32 L_tmp;

    hb_filter_stage = 2 * HB_stage_id;
    offset = 0;
    move16();
    if ( HB_stage_id == 0 )
    {
        offset = 1;
        move16();
    }

    test();
    test();
    IF( HB_stage_id == 0 || HB_stage_id == 2 )
    {
        FOR( i = 0; i < length; i++ )
        {
            L_tmp = Mult_32_16( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] );        /*Qx+15 */
            L_tmp = Madd_32_16( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx+15 */
            L_tmp = Madd_32_16( L_tmp, tmp_R[i], Hilbert_coeffs_fx[hb_filter_stage][4 + offset] );     /*Qx+15 */
            tmpi_R[i] = L_shl( L_tmp, 1 );
            move32(); /*Qx+16 */

            L_tmp = Mult_32_16( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][0] );        /*Qx+15 */
            L_tmp = Madd_32_16( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][2] ); /*Qx+15 */
            L_tmp = Madd_32_16( L_tmp, tmp_I[i + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][4] );     /*Qx+15 */
            tmpi_I[i] = L_shl( L_tmp, 1 );
            move32(); /*Qx+16 */
        }
    }
    ELSE IF( HB_stage_id == 1 || HB_stage_id == 3 )
    {
        FOR( i = 0; i < length; i++ )
        {

            L_tmp = Mult_32_16( tmpi_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2] );    /*Qx+15 */
            L_tmp = Madd_32_16( L_tmp, tmpi_R[i], Hilbert_coeffs_fx[hb_filter_stage][4] ); /*Qx+15 */
            tmpi_R[i + 4] = L_sub( tmp_R[i], L_shl( L_tmp, 1 ) );
            move32(); /*Qx+16 */

            L_tmp = Mult_32_16( tmpi_I[i + 2], Hilbert_coeffs_fx[hb_filter_stage + 1][2] );    /*Qx+15 */
            L_tmp = Madd_32_16( L_tmp, tmpi_I[i], Hilbert_coeffs_fx[hb_filter_stage + 1][4] ); /*Qx+15 */
            tmpi_I[i + 4] = L_sub( tmp_I[i], L_shl( L_tmp, 1 ) );
            move32(); /*Qx+16 */
        }
    }
}
#endif

/*-------------------------------------------------------------------*
 * flip_spectrum()
 *
+125 −1
Original line number Diff line number Diff line
@@ -483,6 +483,131 @@ void flip_and_downmix_generic_fx(
    return;
}

void flip_and_downmix_generic_fx_32(
    Word32 input[],                      /* i : input spectrum Qx*/
    Word32 output[],                     /* o : output spectrum Qx*/
    const Word16 length,                 /* i : length of spectra */
    Word32 mem1_ext[HILBERT_ORDER1],     /* i/o: memory Qx*/
    Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/
    Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/
    Word16 *phase_state                  /* i/o: Phase state in case frequency isn't multiple of 50 Hz */
)
{
    Word16 i, j;
    Word32 tmp[L_FRAME32k + HILBERT_ORDER1];
    Word32 tmpi_R[L_FRAME32k];
    Word32 tmpi_I[L_FRAME32k];
    Word32 tmpi2_R[L_FRAME32k + HILBERT_ORDER2];
    Word32 tmpi2_I[L_FRAME32k + HILBERT_ORDER2];
    Word32 tmp_R[L_FRAME32k + HILBERT_ORDER2];
    Word32 tmp_I[L_FRAME32k + HILBERT_ORDER2];

    /*Word16 s_tmp[L_FRAME32k];*/
    /*Word16 factor;*/
    Word16 period;
    Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580,
                                        -26319, -17530, -6393, 6393, 17530, 26319,
                                        31580, 32609, 29268, 22005, 11793 }; /* Q15 */
    Word16 local_cos_table17[17] = { 32767, 30571, 24279, 14732, 3212, -8739,
                                     -19519, -27683, -32137, -32137, -27683,
                                     -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */
    Word16 *local_negsin_table, *local_cos_table;
    Word32 L_tmp;

    /* 1850 Hz downmix */
    period = 17;
    move16();
    local_negsin_table = local_negsin_table17;
    local_cos_table = local_cos_table17;


    FOR( i = 0; i < length; i = i + 2 )
    {
        input[i] = L_negate( input[i] );
        move16();
    }

    Copy32( input, tmp + HILBERT_ORDER1, length );
    Copy32( mem1_ext, tmp, HILBERT_ORDER1 );

    /* Hilber transform stage - 0 - single precision */
    Hilbert_transform_fx( tmp,    /* i: Real component of HB */
                          tmp,    /* i: Imag component of HB */
                          tmpi_R, /* o: Real component of HB */
                          tmpi_I, /* o: Imag. component of HB */
                          length, /* i: length of the spectra */
                          0 );    /* i: HB transform stage */


    Copy32( mem2_ext, tmpi2_R, HILBERT_ORDER2 );
    Copy32( mem3_ext, tmpi2_I, HILBERT_ORDER2 );

    /* Hilber transform stage - 1 */
    Hilbert_transform_fx( tmpi_R,  /* i: Real component of HB */
                          tmpi_I,  /* i: Imag component of HB */
                          tmpi2_R, /* o: Real component of HB */
                          tmpi2_I, /* o: Imag. component of HB */
                          length,  /* i: length of the spectra */
                          1 );     /* i: HB transform stage */
    Copy32( tmp + length, mem1_ext, HILBERT_ORDER1 );
    Copy32( mem2_ext + HILBERT_ORDER2, tmp_R, HILBERT_ORDER2 );
    Copy32( mem3_ext + HILBERT_ORDER2, tmp_I, HILBERT_ORDER2 );

    /* Hilber transform stage - 2 */
    Hilbert_transform_fx( tmpi2_R, /* i: Real component of HB */
                          tmpi2_I, /* i: Imag component of HB */
                          tmpi_R,  /* o: Real component of HB */
                          tmpi_I,  /* o: Imag. component of HB */
                          length,  /* i: length of the spectra */
                          2 );     /* i: HB transform stage */

    Copy32( tmpi2_R + length, mem2_ext, HILBERT_ORDER2 );
    Copy32( tmpi2_I + length, mem3_ext, HILBERT_ORDER2 );

    /* Hilber transform stage - 3 */
    Hilbert_transform_fx( tmpi_R, /* i: Real component of HB */
                          tmpi_I, /* i: Imag component of HB */
                          tmp_R,  /* o: Real component of HB */
                          tmp_I,  /* o: Imag. component of HB */
                          length, /* i: length of the spectra */
                          3 );    /* i: HB transform stage */

    Copy32( tmp_R + length, mem2_ext + HILBERT_ORDER2, HILBERT_ORDER2 );
    Copy32( tmp_I + length, mem3_ext + HILBERT_ORDER2, HILBERT_ORDER2 );

    if ( *phase_state >= period )
    {
        *phase_state = 0;
        move16();
    }

    i = 0;
    move16();
    j = *phase_state;
    move16();

    WHILE( i < length )
    {
        WHILE( ( j < period ) && ( i < length ) )
        {
            L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] );           /*//Qx+16 */
            L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */
            output[i] = L_tmp;                                                /*Qx */
            i++;
            j++;
        }

        if ( j >= period )
        {
            j = 0;
            move16();
        }
    }

    *phase_state = j;
    move16();
    return;
}

/*----------------------------------------------
 * Hilbert transform - Double precision
@@ -779,7 +904,6 @@ static void filt_mu_fx(
            Overflow = 0;
        }
#endif

#else
        sig_out[n] = shl( mult_r( ga, temp ), 1 );
#endif
+1 −1
Original line number Diff line number Diff line
@@ -3545,7 +3545,7 @@ void hp400_12k8_fx(
    return;
}

#ifdef IVAS_FLOAT_FIXED
#if 0
void hp400_12k8_ivas_fx(
    Word16 signal[], /* i/o: input signal / output is divided by 16 */
    const Word16 lg, /* i  : lenght of signal                       */
+27 −16
Original line number Diff line number Diff line
@@ -1551,68 +1551,79 @@ void save_synthesis_hq_fec_fx(
    {
        case EVS_MONO:
            post_hq_delay = NS2SA( st->output_Fs, POST_HQ_DELAY_NS );
            move16();
            BREAK;
        case IVAS_SCE:
            post_hq_delay = NS2SA( st->output_Fs, DELAY_CLDFB_NS );
            move16();
            BREAK;
        case IVAS_CPE_DFT:
            IF( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF )
            IF( EQ_16(hCPE->nchan_out , 1) && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF )
            {
                post_hq_delay = NS2SA( st->output_Fs, DELAY_CLDFB_NS );
                move16();
            }
            ELSE
            {
                post_hq_delay = 0;
                move16();
            }
            BREAK;
        default:
            post_hq_delay = 0;
            move16();
            BREAK;
    }

    test();
    test();
    test();
    test();
    test();
    IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) )
    {
        Copy( st->hTcxDec->synth_history_fx + output_frame, st->hTcxDec->synth_history_fx, output_frame - post_hq_delay + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) );
        FOR( int i = 0; i < output_frame; i++ )
        Copy( st->hTcxDec->synth_history_fx + output_frame, st->hTcxDec->synth_history_fx, add(sub(output_frame , post_hq_delay) , NS2SA( st->output_Fs, PH_ECU_MEM_NS )) );
        FOR( Word16 i = 0; i < output_frame; i++ )
        {
            st->hTcxDec->old_synthFB_fx[i + output_frame - post_hq_delay] = extract_h( output_fx[i] );
            st->hTcxDec->old_synthFB_fx[sub(add(i , output_frame) , post_hq_delay)] = extract_h( output_fx[i] );
            move16();
        }

        IF( EQ_16( st->element_mode, EVS_MONO ) )
        IF( st->element_mode == EVS_MONO )
        {
            /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill
               this buffer are not available for all cases, the impact on the output is limited */

            set16_fx( st->hTcxDec->old_synthFB_fx + 2 * output_frame - post_hq_delay, 0, post_hq_delay );
            set16_fx( st->hTcxDec->old_synthFB_fx + sub(shl(output_frame, 1) , post_hq_delay), 0, post_hq_delay );
            IF( GE_16( output_frame, L_FRAME16k ) )
            {
                Copy( st->prev_synth_buffer_fx, st->hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) );
                Copy( st->prev_synth_buffer_fx, st->hTcxDec->old_synthFB_fx + sub(shl(output_frame, 1) , NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS )), NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) );
            }
            ELSE
            {
                Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
                Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl(output_frame, 1), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
            }

            IF( NE_16( st->core, ACELP_CORE ) )
            IF( st->core != ACELP_CORE )
            {
                IF( GE_16( output_frame, L_FRAME16k ) )
                {
                    Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) );
                    Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
                    Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub(shl(output_frame, 1) , NS2SA( st->output_Fs, DELAY_CLDFB_NS )), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) );
                    Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl(output_frame, 1), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
                }
                ELSE
                {
                    Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) );
                    Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
                    Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub(shl(output_frame, 1) , NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS )), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) );
                    Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + sub(shl(output_frame, 1) , NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS )), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
                }
            }
        }
        ELSE
        {
            IF( NE_16( st->core, ACELP_CORE ) )
            IF( st->core != ACELP_CORE )
            {
                Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + 2 * output_frame - post_hq_delay, post_hq_delay );
                Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
                Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub(shl(output_frame, 1) , post_hq_delay), post_hq_delay );
                Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl(output_frame, 1), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) );
            }
        }
    }
Loading