Commit 016abdd9 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Converted the function calculate_energy_buffer

parent ca76e1c9
Loading
Loading
Loading
Loading
Loading
+132 −2
Original line number Diff line number Diff line
@@ -54,7 +54,9 @@
 *--------------------------------------------------------------------*/

static void calculate_energy_buffer( CPE_ENC_HANDLE hCPE, float enerBuffer_dft[], const int16_t no_channels, const int32_t input_Fs );

#ifdef IVAS_FLOAT_FIXED
static void calculate_energy_buffer_fx( CPE_ENC_HANDLE hCPE, Word64 enerBuffer_dft_fx[], Word16 *enerBuffer_dft_q_fx, const Word16 no_channels, const Word32 input_Fs );
#endif

/*-------------------------------------------------------------------*
 * pre_proc_front_ivas()
@@ -836,6 +838,69 @@ ivas_error pre_proc_front_ivas(
}


#ifdef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
 * calculate_energy_buffer_fx()
 *
 * calculate DFT-based energies
 *--------------------------------------------------------------------*/

static void calculate_energy_buffer_fx(
    CPE_ENC_HANDLE hCPE,        /* i  : CPE encoder structure       */
    Word64 enerBuffer_dft_fx[], /* o  : energy buffer               */
    Word16 *enerBuffer_dft_q_fx,
    const Word16 no_channels, /* i  : no. of used CLDFB channels  */
    const Word32 input_Fs     /* i  : input sampling rate         */
)
{
    Word16 i, j;
    Word64 nrg_DMX_fx[CLDFB_NO_CHANNELS_MAX];
    Word64 *p_nrg_DMX_fx;
    Word32 *pDFT_DMX_fx;
    Word16 *pDFT_DMX_q_fx;
    Word32 chan_width_bins_fx;
    Word16 band_res_dft_fx, chan_width_f_fx, start, stop;

    Word32 temp_q1 = norm_l( input_Fs ) - 1;
    Word32 temp_q2 = norm_s( hCPE->hStereoDft->NFFT );

    band_res_dft_fx = div_l( L_shl( input_Fs, temp_q1 ), shl( hCPE->hStereoDft->NFFT, temp_q2 ) );
    chan_width_f_fx = div_l( 24000, CLDFB_NO_CHANNELS_MAX );
    chan_width_bins_fx = L_shl( (Word32) div_s( chan_width_f_fx, band_res_dft_fx ), ( sub( add( temp_q1, 1 ), temp_q2 ) ) ); // Q16

    pDFT_DMX_fx = hCPE->hStereoDft->DFT_fx[0];
    pDFT_DMX_q_fx = hCPE->hStereoDft->DFT_q_fx[0];
    start = 1;
    p_nrg_DMX_fx = nrg_DMX_fx;

    *p_nrg_DMX_fx = Mpy_32_32( pDFT_DMX_fx[0], pDFT_DMX_fx[0] );

    FOR( i = 0; i < no_channels; i++ )
    {
        stop = (Word16) ( L_add( Mpy_32_16_1( chan_width_bins_fx, add( i, 1 ) ), 1 ) >> 1 );
        FOR( j = start; j < stop; j++ )
        {
            *p_nrg_DMX_fx = W_add( *p_nrg_DMX_fx, Mpy_32_32( pDFT_DMX_fx[2 * j], pDFT_DMX_fx[2 * j] ) );
            *p_nrg_DMX_fx = W_add( *p_nrg_DMX_fx, Mpy_32_32( pDFT_DMX_fx[2 * j + 1], pDFT_DMX_fx[2 * j + 1] ) );
        }
        enerBuffer_dft_q_fx[i] = 2 * pDFT_DMX_q_fx[i] - 31;
        start = stop;
        p_nrg_DMX_fx++;
    }

    FOR( i = 0; i < no_channels; i++ ) /* Consider only used channels, dependent on Fs */
    {
        enerBuffer_dft_fx[i] = nrg_DMX_fx[i] / 3;
    }

    /* Set remaining entries of enerBuffer to zero */
    FOR( ; i < CLDFB_NO_CHANNELS_MAX; i++ )
    {
        enerBuffer_dft_fx[i] = 0;
    }
    return;
}
#endif
/*-------------------------------------------------------------------*
 * calculate_energy_buffer()
 *
@@ -849,6 +914,71 @@ static void calculate_energy_buffer(
    const int32_t input_Fs     /* i  : input sampling rate         */
)
{
#ifdef IVAS_FLOAT_FIXED
    float *pDFT_DMX; // to be removed
    Word16 i, j;
    Word64 enerBuffer_dft_fx[CLDFB_NO_CHANNELS_MAX]; // to be removed
    Word64 nrg_DMX_fx[CLDFB_NO_CHANNELS_MAX];
    Word64 *p_nrg_DMX_fx;
    Word32 *pDFT_DMX_fx;
    Word32 chan_width_bins_fx;
    Word16 band_res_dft_fx, chan_width_f_fx, start, stop;

    Word32 temp_q1 = norm_l( input_Fs ) - 1;
    Word32 temp_q2 = norm_s( hCPE->hStereoDft->NFFT );

    band_res_dft_fx = div_l( L_shl( input_Fs, temp_q1 ), shl( hCPE->hStereoDft->NFFT, temp_q2 ) );
    chan_width_f_fx = div_l( 24000, CLDFB_NO_CHANNELS_MAX );
    chan_width_bins_fx = L_shl( (Word32) div_s( chan_width_f_fx, band_res_dft_fx ), ( sub( add( temp_q1, 1 ), temp_q2 ) ) ); // Q16

    pDFT_DMX = hCPE->hStereoDft->DFT[0]; // to be removed
    start = 1;

    pDFT_DMX_fx = hCPE->hStereoDft->DFT_fx[0];
    p_nrg_DMX_fx = nrg_DMX_fx;

    pDFT_DMX_fx[0] = (Word32) ( pDFT_DMX[0] * ONE_IN_Q11 );

    FOR( i = 0; i < no_channels; i++ )
    {
        stop = (Word16) ( L_add( Mpy_32_16_1( chan_width_bins_fx, add( i, 1 ) ), 1 ) >> 1 );
        nrg_DMX_fx[i] = 0;
        FOR( j = start; j < stop; j++ )
        {
            pDFT_DMX_fx[2 * j] = (Word32) ( pDFT_DMX[2 * j] * ONE_IN_Q11 );
            pDFT_DMX_fx[2 * j + 1] = (Word32) ( pDFT_DMX[2 * j + 1] * ONE_IN_Q11 );
        }
        start = stop;
    }
    start = 1;

    *p_nrg_DMX_fx = Mpy_32_32( pDFT_DMX_fx[0], pDFT_DMX_fx[0] );

    FOR( i = 0; i < no_channels; i++ )
    {
        stop = (Word16) ( L_add( Mpy_32_16_1( chan_width_bins_fx, add( i, 1 ) ), 1 ) >> 1 );
        FOR( j = start; j < stop; j++ )
        {
            *p_nrg_DMX_fx = W_add( *p_nrg_DMX_fx, Mpy_32_32( pDFT_DMX_fx[2 * j], pDFT_DMX_fx[2 * j] ) );
            *p_nrg_DMX_fx = W_add( *p_nrg_DMX_fx, Mpy_32_32( pDFT_DMX_fx[2 * j + 1], pDFT_DMX_fx[2 * j + 1] ) );
            // Q(-9) = Q11 + Q11 - Q31
        }
        start = stop;
        p_nrg_DMX_fx++;
    }

    FOR( i = 0; i < no_channels; i++ ) /* Consider only used channels, dependent on Fs */
    {
        enerBuffer_dft_fx[i] = nrg_DMX_fx[i] / 3;
        enerBuffer_dft[i] = (float) enerBuffer_dft_fx[i] * ( 1 << 9 ); // Q(-9) adjustment, to be removed
    }

    /* Set remaining entries of enerBuffer to zero */
    FOR( ; i < CLDFB_NO_CHANNELS_MAX; i++ )
    {
        enerBuffer_dft[i] = 0.f;
    }
#else
    int16_t i, j;
    float *pDFT_DMX, *p_nrg_DMX;
    float nrg_DMX[CLDFB_NO_CHANNELS_MAX];
@@ -887,6 +1017,6 @@ static void calculate_energy_buffer(
    {
        enerBuffer_dft[i] = 0.f;
    }

#endif
    return;
}
+4 −0
Original line number Diff line number Diff line
@@ -127,6 +127,10 @@ typedef struct stereo_dft_enc_data_struct
    int16_t NFFT; /* Size of the FFT=frame size+overlap */

    /*FFT*/
#ifdef IVAS_FLOAT_FIXED
    Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_N_MAX_ENC];
    Word16 DFT_q_fx[CLDFB_NO_CHANNELS_MAX];
#endif
    float DFT[CPE_CHANNELS][STEREO_DFT_N_MAX_ENC];
    int16_t dft_ovl; /* Overlap size */
    int16_t dft_zp;  /* Zero padding */