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

Few functions in ivas_stereo_icbwe converted to fixed

Converted the stereo_icBWE module except for icBWE_dec function.
parent 518d9f24
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ Word32 floatToFixed(const float f, Word16 Q)
	if (Q < 0)
		return (Word32)((float)(f) / (float)(((unsigned)1) << (-Q)) + (f >= 0 ? 0.5 : -0.5));
	else
		return (Word32)(f * (float)(((unsigned)1) << Q) + (f >= 0 ? 0.5 : -0.5));
		return (Word32)(f * (float)((unsigned int)1 << Q) + (f >= 0 ? 0.5 : -0.5));
}

float fixedToFloat(const Word32 i, Word16 Q)
@@ -20,7 +20,7 @@ float fixedToFloat(const Word32 i, Word16 Q)
	if (Q < 0)
		return (i * (float)(((unsigned)1) << (-Q)));
	else
		return (float)(i) / (float)(((unsigned)1) << Q);
		return (float)(i) / (float)((unsigned int)1 << Q);
}
void floatToFixed_arrL(const float *f, Word32 *i, Word16 Q, Word16 l)
{
+1 −0
Original line number Diff line number Diff line
@@ -801,6 +801,7 @@ enum fea_names
#define STEREO_L_TCA_OVLP_NS                    5000000L                    /* overlap length of the ICA gain scaling */


#define STEREO_DMX_GAIN_Q13                     29066                       /* calculated this -->"powf( 10, ( ( 1 << STEREO_BITS_TCA_GD ) - 1 ) * STEREO_TCA_GDSTEP + STEREO_TCA_GDMIN )"*/
/*----------------------------------------------------------------------------------*
 * TD Stereo Constants
 *----------------------------------------------------------------------------------*/
+101 −0
Original line number Diff line number Diff line
@@ -989,4 +989,105 @@ Word16 matrix_product_diag_fx(
    const Word16 transpY, /* i  : flag indicating the transposition of the right hand matrix prior to the multiplication */
    Word32 *Z,            /* o  : resulting matrix after the matrix multiplication                                       */
    Word16 *Z_e );


// ivas_stereo_mdct_core_dec_fx.c
void stereo_mdct_core_dec_fx(
    Decoder_Struct *st_ivas,                     /* i/o: IVAS decoder structure                  */
    CPE_DEC_HANDLE hCPE,                         /* i/o: CPE decoder structure                   */
    float *signal_out[CPE_CHANNELS],             /* o  : synthesis @internal_FS                  */
    float signal_outFB[CPE_CHANNELS][L_FRAME48k] /* o  : synthesis @output_FS                    */
);

// ivas_stereo_mdct_stereo_com.c
void splitAvailableBits_fx(
    const Word16 total_bits,      /* i  : total available bits for TCX coding   */
    const Word16 split_ratio,     /* i  : split ratio                           */
    const Word16 isSBAStereoMode, /* i  : signal core coding for SBA            */
    Word16 *bits_ch0,             /* o  : bits for channel 0                    */
    Word16 *bits_ch1              /* o  : bits for channel 1                    */
);

void stereo_tcx_init_dec_fx(
    Decoder_State *st,             /* i/o: decoder state structure             */
    const Word16 MCT_flag,         /* i  : hMCT handle allocated (1) or not (0)*/
    const Word16 last_element_mode /* i  : element mode of previous frame      */
);

void initMdctStereoDecData_fx(
    STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */
    const Word16 igf,                  /* i  : flag indicating IGF activity     */
    const H_IGF_GRID igfGrid,          /* i  : IGF grid configuration           */
    const Word32 element_brate,        /* i  : element bitrate                  */
    const Word16 bwidth                /* i  : audio bandwidth                  */
);

void stereo_mdct_init_bands_fx(
    const Word16 L_frame,       /* i  : frame length                                       */
    const Word16 tmp_tcx_mode,  /* i  : tcx mode (TCX10, TCX 20), -1 if transition frame   */
    const Word32 element_brate, /* i  : element bitrate                                    */
    const Word16 igf,           /* i  : flag indicating if IGF is used                     */
    const H_IGF_GRID hIgfGrid,  /* i  : IGF grid setup                                     */
    Word16 *sfbOffset,          /* o  : sfb offset table                                   */
    Word16 *sfbCnt              /* o  : number of sfbs                                     */
);

void stereo_mdct_init_igf_start_band_fx(
    STEREO_MDCT_BAND_PARAMETERS *stbParams, /* i/o: stereo frequency band parameters    */
    const Word16 transFac,                  /* i  : transform factor                    */
    const Word16 bwidth,                    /* i  : audio bandwidth                     */
    const Word32 element_brate              /* i  : element bitrate                     */
);

void ivas_mdct_dec_side_bits_frame_channel_fx(
    CPE_DEC_HANDLE hCPE,                               /* i/o: CPE decoder structure               */
    Word16 param_lpc[CPE_CHANNELS][NPRM_LPC_NEW],      /* o  : lpc_parameters                      */
    Word16 p_param[CPE_CHANNELS][NB_DIV],              /* o  : pointer to param buffer             */
    Decoder_State *st0,                                /* i  : pointer to bitstream handle         */
    Word16 nTnsBitsTCX10[CPE_CHANNELS][NB_DIV],        /* o  : number of bits for TNS              */
    Word16 param[CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV], /* i/o: parameters buffer                   */
    const Word16 MCT_flag,                             /* i  : hMCT handle allocated (1) or not (0)*/
    const Word16 odd_channel_cpe                       /* i  : flag cpe with odd nb of tc channels */
);

void mdct_read_IGF_bits_fx(
    Decoder_State *st, /* i/o: Decoder state handle                        */
    Decoder_State *st0 /* i  : pointer to handle where bitstream is read   */
);

void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in:     | instance handle of IGF Deccoder                      */
                             Decoder_State *st,                       /**< in:     | decoder state                                        */
                             const Word16 igfGridIdx,                 /**< in: Q0  | in case of CELP->TCX switching, use 1.25 framelength */
                             const Word16 isIndepFrame                /**< in: Q0  | if 1: arith dec force reset, if 0: no reset          */
);

void stereo_tca_init_dec_fx(
   STEREO_TCA_DEC_HANDLE hStereoTCA                            /* i/o: Stereo TCA handle for Fixed  */
);

void stereo_icBWE_init_dec_fx(
  STEREO_ICBWE_DEC_HANDLE hStereoICBWE                        /* i/o: Stereo inter-channel BWE handle                 */
);

void stereo_icBWE_decproc_fx(
  CPE_DEC_HANDLE hCPE,                      /* i/o: CPE decoder structure       */
  Word32 *output[CPE_CHANNELS],              /* i/o: output synthesis            */
  Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i  : HB synthesis                */
  const int16_t last_core,                  /* i  : last core, primary channel  */
  const int16_t last_bwidth,                /* i  : last bandwidth              */
  const int16_t output_frame                /* i  : frame length                */
);

void add_HB_to_mono_dmx_fx(
  CPE_DEC_HANDLE hCPE,        /* i/o: CPE decoder structure       */
  Word32 output[L_FRAME48k],   /* i/o: output synthesis            */
  Word32 outputHB[L_FRAME48k], /* i  : HB synthesis                */
  const int16_t last_core,    /* i  : last core, primary channel  */
  const int16_t output_frame  /* i  : frame length                */
);

void stereo_dft_dmx_out_reset_fx(
  STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx                    /* i/o: DFT stereo DMX decoder                  */
);

#endif
+119 −118
Original line number Diff line number Diff line
@@ -916,59 +916,6 @@ Word16 matrix_diag_product_fx(
}
#endif

/*---------------------------------------------------------------------*
 * diag_matrix_product()
 *
 * compute the matrix product of a diagonal matrix X with a full matrix Y (Z=diag(Y)*X)
 *---------------------------------------------------------------------*/

/*! r: success or failure */
int16_t diag_matrix_product(
    const float *Y,         /* i  : left hand diagonal matrix as vector containing the diagonal elements                   */
    const int16_t entriesY, /* i  : length of the diagonal of the left hand matrix                                         */
    const float *X,         /* i  : right hand matrix                                                                      */
    const int16_t rowsX,    /* i  : number of rows of the right hand matrix                                                */
    const int16_t colsX,    /* i  : number of columns of the right hand matrix                                             */
    const int16_t transpX,  /* i  : flag indicating the transposition of the right hand matrix prior to the multiplication */
    float *Z                /* o  : resulting matrix after the matrix multiplication                                       */
)
{
    int16_t i, j;
    float *Zp = Z;

    /* Processing */
    if ( transpX == 1 ) /* We use X transpose */
    {
        if ( colsX != entriesY )
        {
            return EXIT_FAILURE;
        }
        for ( i = 0; i < rowsX; ++i )
        {
            for ( j = 0; j < entriesY; ++j )
            {
                *( Zp++ ) = X[i + j * rowsX] * Y[j];
            }
        }
    }
    else /* Regular case */
    {
        if ( rowsX != entriesY )
        {
            return EXIT_FAILURE;
        }
        for ( i = 0; i < colsX; ++i )
        {
            for ( j = 0; j < entriesY; ++j )
            {
                *( Zp++ ) = *( X++ ) * Y[j];
            }
        }
    }

    return EXIT_SUCCESS;
}

#ifdef IVAS_FLOAT_FIXED
Word16 diag_matrix_product_fx(
    const Word32 *Y, /* i  : left hand diagonal matrix as vector containing the diagonal elements                   */
@@ -1026,95 +973,52 @@ Word16 diag_matrix_product_fx(


/*---------------------------------------------------------------------*
 * matrix_product_diag()
 * diag_matrix_product()
 *
 * compute only the main diagonal of X*Y (Z=diag(X*Y))
 * compute the matrix product of a diagonal matrix X with a full matrix Y (Z=diag(Y)*X)
 *---------------------------------------------------------------------*/

/*! r: success or failure */
int16_t matrix_product_diag(
    const float *X,        /* i  : left hand matrix                                                                       */
    const int16_t rowsX,   /* i  : number of rows of the left hand matrix                                                 */
    const int16_t colsX,   /* i  : number of columns of the left hand matrix                                              */
    const int16_t transpX, /* i  : flag indicating the transposition of the left hand matrix prior to the multiplication  */
    const float *Y,        /* i  : right hand matrix                                                                      */
    const int16_t rowsY,   /* i  : number of rows of the right hand matrix                                                */
    const int16_t colsY,   /* i  : number of columns of the right hand matrix                                             */
    const int16_t transpY, /* i  : flag indicating the transposition of the right hand matrix prior to the multiplication */
int16_t diag_matrix_product(
    const float *Y,         /* i  : left hand diagonal matrix as vector containing the diagonal elements                   */
    const int16_t entriesY, /* i  : length of the diagonal of the left hand matrix                                         */
    const float *X,         /* i  : right hand matrix                                                                      */
    const int16_t rowsX,    /* i  : number of rows of the right hand matrix                                                */
    const int16_t colsX,    /* i  : number of columns of the right hand matrix                                             */
    const int16_t transpX,  /* i  : flag indicating the transposition of the right hand matrix prior to the multiplication */
    float *Z                /* o  : resulting matrix after the matrix multiplication                                       */
)
{
    int16_t j, k;
    int16_t i, j;
    float *Zp = Z;

    /* Processing */
    if ( transpX == 1 && transpY == 0 ) /* We use X transpose */
    {
        if ( rowsX != rowsY )
        {
            return EXIT_FAILURE;
        }

        for ( j = 0; j < colsY; ++j )
        {
            ( *Zp ) = 0.0f;
            for ( k = 0; k < rowsX; ++k )
            {
                ( *Zp ) += X[k + j * rowsX] * Y[k + j * rowsY];
            }
            Zp++;
        }
    }
    else if ( transpX == 0 && transpY == 1 ) /* We use Y transpose */
    {
        if ( colsX != colsY )
        {
            return EXIT_FAILURE;
        }
        for ( j = 0; j < rowsY; ++j )
        {
            ( *Zp ) = 0.0f;
            for ( k = 0; k < colsX; ++k )
            {
                ( *Zp ) += X[j + k * rowsX] * Y[j + k * rowsY];
            }
            Zp++;
        }
    }
    else if ( transpX == 1 && transpY == 1 ) /* We use both transpose */
    if ( transpX == 1 ) /* We use X transpose */
    {
        if ( rowsX != colsY )
        if ( colsX != entriesY )
        {
            return EXIT_FAILURE;
        }

        for ( j = 0; j < rowsY; ++j )
        for ( i = 0; i < rowsX; ++i )
        {

            ( *Zp ) = 0.0f;
            for ( k = 0; k < colsX; ++k )
            for ( j = 0; j < entriesY; ++j )
            {
                ( *Zp ) += X[k + j * rowsX] * Y[j + k * rowsY];
                *( Zp++ ) = X[i + j * rowsX] * Y[j];
            }

            Zp++;
        }
    }
    else /* Regular case */
    {
        if ( colsX != rowsY )
        if ( rowsX != entriesY )
        {
            return EXIT_FAILURE;
        }

        for ( j = 0; j < colsY; ++j )
        for ( i = 0; i < colsX; ++i )
        {
            ( *Zp ) = 0.0f;
            for ( k = 0; k < colsX; ++k )
            for ( j = 0; j < entriesY; ++j )
            {
                ( *Zp ) += X[j + k * rowsX] * Y[k + j * rowsY];
                *( Zp++ ) = *( X++ ) * Y[j];
            }
            Zp++;
        }
    }

@@ -1220,12 +1124,101 @@ Word16 matrix_product_diag_fx(
#endif

/*---------------------------------------------------------------------*
 * cmplx_matrix_square()
 * matrix_product_diag()
 *
 * compute the square of a complex matrix (Z=X*X)
 * compute only the main diagonal of X*Y (Z=diag(X*Y))
 *---------------------------------------------------------------------*/

/*! r: success or failure */
int16_t matrix_product_diag(
    const float *X,        /* i  : left hand matrix                                                                       */
    const int16_t rowsX,   /* i  : number of rows of the left hand matrix                                                 */
    const int16_t colsX,   /* i  : number of columns of the left hand matrix                                              */
    const int16_t transpX, /* i  : flag indicating the transposition of the left hand matrix prior to the multiplication  */
    const float *Y,        /* i  : right hand matrix                                                                      */
    const int16_t rowsY,   /* i  : number of rows of the right hand matrix                                                */
    const int16_t colsY,   /* i  : number of columns of the right hand matrix                                             */
    const int16_t transpY, /* i  : flag indicating the transposition of the right hand matrix prior to the multiplication */
    float *Z               /* o  : resulting matrix after the matrix multiplication                                       */
)
{
    int16_t j, k;
    float *Zp = Z;

    /* Processing */
    if ( transpX == 1 && transpY == 0 ) /* We use X transpose */
    {
        if ( rowsX != rowsY )
        {
            return EXIT_FAILURE;
        }

        for ( j = 0; j < colsY; ++j )
        {
            ( *Zp ) = 0.0f;
            for ( k = 0; k < rowsX; ++k )
            {
                ( *Zp ) += X[k + j * rowsX] * Y[k + j * rowsY];
            }
            Zp++;
        }
    }
    else if ( transpX == 0 && transpY == 1 ) /* We use Y transpose */
    {
        if ( colsX != colsY )
        {
            return EXIT_FAILURE;
        }
        for ( j = 0; j < rowsY; ++j )
        {
            ( *Zp ) = 0.0f;
            for ( k = 0; k < colsX; ++k )
            {
                ( *Zp ) += X[j + k * rowsX] * Y[j + k * rowsY];
            }
            Zp++;
        }
    }
    else if ( transpX == 1 && transpY == 1 ) /* We use both transpose */
    {
        if ( rowsX != colsY )
        {
            return EXIT_FAILURE;
        }

        for ( j = 0; j < rowsY; ++j )
        {

            ( *Zp ) = 0.0f;
            for ( k = 0; k < colsX; ++k )
            {
                ( *Zp ) += X[k + j * rowsX] * Y[j + k * rowsY];
            }

            Zp++;
        }
    }
    else /* Regular case */
    {
        if ( colsX != rowsY )
        {
            return EXIT_FAILURE;
        }

        for ( j = 0; j < colsY; ++j )
        {
            ( *Zp ) = 0.0f;
            for ( k = 0; k < colsX; ++k )
            {
                ( *Zp ) += X[j + k * rowsX] * Y[k + j * rowsY];
            }
            Zp++;
        }
    }

    return EXIT_SUCCESS;
}

#ifdef IVAS_FLOAT_FIXED
void cmplx_matrix_square_fx(
    const Word32 *realX, /* i  : real part of the matrix                                                     */
@@ -1291,6 +1284,14 @@ void cmplx_matrix_square_fx(
}
#endif


/*---------------------------------------------------------------------*
 * cmplx_matrix_square()
 *
 * compute the square of a complex matrix (Z=X*X)
 *---------------------------------------------------------------------*/

/*! r: success or failure */
void cmplx_matrix_square(
    const float *realX,  /* i  : real part of the matrix                                                     */
    const float *imagX,  /* i  : imaginary part of the matrix                                                */
+51 −4
Original line number Diff line number Diff line
@@ -558,7 +558,40 @@ ivas_error ivas_cpe_dec_fx(
     * IC-BWE: output LB and HB mix in ACELP mode
     *----------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
    Word32 *output_fx[CPE_CHANNELS];
    Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k];
    Word16 q_output_HB = 11;
    FOR(Word16 j = 0; j < CPE_CHANNELS; j++)
    {
      output_fx[j] = (Word32 *)malloc(output_frame * sizeof(Word32));
      floatToFixed_arrL(output_flt[j], output_fx[j], *q_output, output_frame);
      floatToFixed_arrL(outputHB[j], outputHB_fx[j], *q_output, output_frame);
    }

    IF (hCPE->hStereoDft != NULL)
    {
      Word16 q_td_gain = Q_factor_arr(hCPE->hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX);
      floatToFixed_arrL(hCPE->hStereoDft->td_gain, hCPE->hStereoDft->td_gain_fx, q_td_gain, STEREO_DFT_CORE_HIST_MAX);   // Checking this.
    }

    stereo_icBWE_decproc_fx(hCPE, output_fx, outputHB_fx, last_core, last_bwidth, output_frame);

    IF (hCPE->hStereoDft != NULL)
    {
      Word16 q_td_gain = Q_factor_arr(hCPE->hStereoDft->td_gain, STEREO_DFT_CORE_HIST_MAX);
      fixedToFloat_arrL(hCPE->hStereoDft->td_gain_fx, hCPE->hStereoDft->td_gain, q_td_gain, STEREO_DFT_CORE_HIST_MAX);   // Checking this.
    }

    FOR(Word16 j = 0; j < CPE_CHANNELS; j++)
    {
      fixedToFloat_arrL(output_fx[j], output_flt[j], q_output_HB, output_frame);
      fixedToFloat_arrL(outputHB_fx[j], outputHB[j], q_output_HB, output_frame);
      free(output_fx[j]);
    }
#else
    stereo_icBWE_decproc(hCPE, output_flt, outputHB, last_core, last_bwidth, output_frame);
#endif

    smooth_dft2td_transition( hCPE, output_flt, output_frame );

@@ -872,7 +905,11 @@ ivas_error create_cpe_dec(
            return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) );
        }

#ifdef IVAS_FLOAT_FIXED
        stereo_dft_dmx_out_reset_fx(hCPE->hStereoDftDmx);
#else
        stereo_dft_dmx_out_reset( hCPE->hStereoDftDmx );
#endif
    }

    /*-----------------------------------------------------------------*
@@ -886,7 +923,11 @@ ivas_error create_cpe_dec(
            return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) );
        }

#ifdef IVAS_FLOAT_FIXED
        stereo_tca_init_dec_fx(hCPE->hStereoTCA);
#else
        stereo_tca_init_dec(hCPE->hStereoTCA);
#endif
    }

    /*-----------------------------------------------------------------*
@@ -900,7 +941,13 @@ ivas_error create_cpe_dec(
            return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE\n" ) );
        }

        //stereo_icBWE_init_dec( hCPE->hStereoICBWE );
#ifdef IVAS_FLOAT_FIXED
        stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE);
#else
        stereo_icBWE_init_dec(hCPE->hStereoICBWE);
#endif

    }

    /*-----------------------------------------------------------------*
Loading