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

renderer functions converted to fixed

[x] Renderer related functions converted to fixed.
[x] Functions in files ivas_crend.c, ivas_reverb.c, reverb_fft_filter,
reverb_iir_filter and sub-functions converted to fixed point.
parent 61fb7109
Loading
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -609,6 +609,9 @@ int main(
    int16_t *inpInt16Buffer;
    float *inFloatBuffer;
    int16_t *outInt16Buffer;
#ifdef IVAS_FLOAT_FIXED
    Word32 *outInt32Buffer;
#endif
    float *outFloatBuffer;
    IVAS_REND_AudioBuffer inBuffer;
    IVAS_REND_AudioBuffer outBuffer;
@@ -1100,6 +1103,9 @@ int main(

    inFloatBuffer = malloc( inBufferSize * sizeof( float ) );
    outInt16Buffer = malloc( outBufferSize * sizeof( int16_t ) );
#ifdef IVAS_FLOAT_FIXED
    outInt32Buffer = malloc( outBufferSize * sizeof( Word32 ) );
#endif
    outFloatBuffer = malloc( outBufferSize * sizeof( float ) );

    inBuffer.config.numSamplesPerChannel = (int16_t) frameSize_smpls;
@@ -1109,7 +1115,9 @@ int main(
    outBuffer.config.numSamplesPerChannel = (int16_t) frameSize_smpls;
    outBuffer.config.numChannels = (int16_t) numOutChannels;
    outBuffer.data = outFloatBuffer;

#ifdef IVAS_FLOAT_FIXED
    outBuffer.data_fx = outInt32Buffer;
#endif
#ifdef WMOPS
    reset_stack();
    reset_wmops();
+3 −1
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@
#include "stl.h"

/* clang-format off */
#ifdef IVAS_FLOAT_FIXED
#define MATRIX_CONSTANT (759250113) 
#endif


/*----------------------------------------------------------------------------------*
@@ -116,7 +119,6 @@
#define ONE_IN_Q30                      1073741824
#define ONE_IN_Q31                      0x7fffffff


/*----------------------------------------------------------------------------------*
 * General constants
 *----------------------------------------------------------------------------------*/
+283 −275
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@
 * Local constants
 *-----------------------------------------------------------------*/


#define Mpy_32_xx Mpy_32_16_1

#define FFTC( x ) WORD322WORD16( (Word32) x )
@@ -94,6 +93,9 @@
#define FFT_C165 ( FFTC( 0x30fbc54d ) ) /* FL2WORD32( 3.826834323650898e-1)  COS_3PI_DIV8 */
#define FFT_C166 ( FFTC( 0xcf043ab3 ) ) /* FL2WORD32(-3.826834323650898e-1) -COS_3PI_DIV8 */

#define SCALEFACTOR16 ( 0 )
#define SCALEFACTOR20 ( 0 )
#if 0
#define SCALEFACTORN2   ( 3 )
#define SCALEFACTOR2    ( 2 )
#define SCALEFACTOR3    ( 3 )
@@ -129,7 +131,7 @@
#define SCALEFACTOR480  ( 11 )
#define SCALEFACTOR600  ( 10 )


#endif
/*-----------------------------------------------------------------*
 * Local function prototypes
 *-----------------------------------------------------------------*/
@@ -153,12 +155,12 @@ static void fft8_5( Word32 *x, Word32 *y, const Word16 *Idx );
static void fft5_8( Word16 n1, Word32 *zRe, Word32 *zIm, const Word16 *Idx );
static void fft4_5( Word32 *x, Word32 *y, const Word16 *Idx );
static void fft5_4( Word16 n1, Word32 *zRe, Word32 *zIm, const Word16 *Idx );

void DoRTFTn_fx_ivas(
    Word32 *x,      /* i/o: real part of input and output data       */
    Word32 *y,      /* i/o: imaginary part of input and output data  */
    const Word16 n /* i  : size of the FFT n=(2^k) up to 1024       */
);

/*-----------------------------------------------------------------*
 * fft15_shift2()
 * 15-point FFT with 2-point circular shift
@@ -1668,11 +1670,13 @@ static void cftfsub(
    Word32 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;

    l = 2;

    IF ( GT_16(n, 8) )
    {
        cft1st( n, a, w );

        l = 8;

        WHILE ( LT_16(shl(l, 2 ), n) )
        {
            cftmdl( n, l, a, w );
@@ -2107,7 +2111,6 @@ static void rftbsub(
    Word16 j, k, kk, ks, m;
    Word16 wkr, wki;
    Word32 xr, xi, yr, yi;

    a[1] = L_negate(a[1]);
    m = shr(n, 1);
    ks = 2 * nc / m;
@@ -2192,7 +2195,6 @@ void edct2_fx_ivas(
    {
        nc = n;
    }

    IF ( LT_16(isgn, 0) )
    {
        xr = a[n - 1];
@@ -3231,6 +3233,7 @@ static void cooleyTukeyFFT(
        default:
        {
            factor = findFactor( length );

            IF ( GT_16(factor, 0) && GT_16( length / factor, 1 ) )
            {
                n1 = factor;
@@ -3338,6 +3341,7 @@ static void pfaDFT(
                tmp[cnt++] = x[2 * idx + 1];

                idx += incr;

                IF ( GT_16(idx, length) )
                {
                    idx -= length;
@@ -3373,6 +3377,7 @@ static void pfaDFT(
                tmp[2 * idx] = x[cnt++];
                tmp[2 * idx + 1] = x[cnt++];
                idx += n2;

                IF ( GT_16(idx, length) )
                {
                    idx -= length;
@@ -4867,6 +4872,7 @@ static void fft_lenN(
            }
            BREAK;
    }

    SWITCH( dim2 )
    {

@@ -5117,6 +5123,7 @@ static void fft_lenN(
                    y[j] = xx[0 + j * dim1];
                };
            }

            fft_len16( &y[0] );
            FOR ( j = 0; j < dim2; j++ )
            {
@@ -5771,5 +5778,6 @@ void BASOP_cfft_fx(

    return;
}

#undef WMC_TOOL_SKIP
#endif
+3 −0
Original line number Diff line number Diff line
@@ -46,6 +46,9 @@
#define PI_OVER_2                               ( EVS_PI / 2.0f )
#define PI_OVER_180                             ( EVS_PI / 180.0f )
#define _180_OVER_PI                            ( 180.0f / EVS_PI )
#ifdef IVAS_FLOAT_FIXED
#define _180_OVER_PI_Q25                         1922527233
#endif

#define SQRT2                                   1.414213562373095f
#define SQRT2_FIXED                             1518500250 // Q30
+267 −8
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
   the United Nations Convention on Contracts on the International Sales of Goods.

*******************************************************************************************************/
#include <stdio.h>

#include <stdint.h>
#include "options.h"
@@ -37,7 +38,16 @@
#include "ivas_rom_com.h"
#include <assert.h>
#include "wmc_auto.h"

#ifdef IVAS_FLOAT_FIXED
#include <stdint.h>
#include <math.h>
#include "prot_fx1.h"
#include "prot_fx2.h"
#include "debug.h"
#define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) )
#define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) )
#define SHC( x )                  ( (Word16) x )
#endif

/*-----------------------------------------------------------------------------------------*
 * Local constants
@@ -50,7 +60,95 @@
#define IVAS_ONE_BY_160 0.00625f
#define IVAS_ONE_BY_80  0.0125f

#ifdef IVAS_FLOAT_FIXED
#define IVAS_ONE_BY_960_Q37 143165577
#define IVAS_ONE_BY_640_Q37 214748365
#define IVAS_ONE_BY_320_Q37 429496730
#define IVAS_ONE_BY_240_Q37 572662306
#define IVAS_ONE_BY_160_Q37 858993459
#define IVAS_ONE_BY_80_Q37  1717986918
/*-----------------------------------------------------------------------------------------*
 * Function ivas_get_mdft_twid_factors()
 *
 * get twiddle tables for MDFT
 *-----------------------------------------------------------------------------------------*/

static void ivas_get_mdft_twid_factors_fx(
    const Word16 length,
    const Word32 **ppTwid )
{
    switch ( length )
    {
        case L_FRAME48k:
            *ppTwid = &ivas_mdft_coeff_cos_twid_960_fx[0];
            break;
        case L_FRAME32k:
            *ppTwid = &ivas_mdft_coeff_cos_twid_640_fx[0];

            break;
        case L_FRAME16k:
            *ppTwid = &ivas_mdft_coeff_cos_twid_320_fx[0];
            break;
        case IVAS_240_PT_LEN:
            *ppTwid = &ivas_mdft_coeff_cos_twid_240_fx[0];
            break;
        case IVAS_160_PT_LEN:
            *ppTwid = &ivas_mdft_coeff_cos_twid_160_fx[0];
            break;
        case IVAS_120_PT_LEN:
            *ppTwid = &ivas_mdft_coeff_cos_twid_120_fx[0];
            break;
        case IVAS_80_PT_LEN:
            *ppTwid = &ivas_mdft_coeff_cos_twid_80_fx[0];
            break;
        case IVAS_40_PT_LEN:
            *ppTwid = &ivas_mdft_coeff_cos_twid_40_fx[0];
            break;

        default:
            assert( !"Not supported FFT length!" );
            break;
    }

    return;
}
/*-----------------------------------------------------------------------------------------*
 * Function ivas_get_imdft_twid_factors()
 *
 * get twiddle tables for IMDFT
 *-----------------------------------------------------------------------------------------*/

static void ivas_get_imdft_twid_factors_fx(
    const Word16 length,
    const Word32 **ppTwid )
{
    switch ( length )
    {
        case L_FRAME48k:
            *ppTwid = ivas_mdft_coeff_cos_twid_960_fx;
            break;
        case L_FRAME32k:
            *ppTwid = ivas_mdft_coeff_cos_twid_640_fx;
            break;
        case L_FRAME16k:
            *ppTwid = ivas_mdft_coeff_cos_twid_320_fx;
            break;
        case 240:
            *ppTwid = ivas_mdft_coeff_cos_twid_240_fx;
            break;
        case 160:
            *ppTwid = ivas_mdft_coeff_cos_twid_160_fx;
            break;
        case 80:
            *ppTwid = ivas_mdft_coeff_cos_twid_80_fx;
            break;
        default:
            assert( !"Not supported FFT length!" );
    }

    return;
}
#endif
/*-----------------------------------------------------------------------------------------*
 * Function ivas_get_mdft_twid_factors()
 *
@@ -96,8 +194,6 @@ static void ivas_get_mdft_twid_factors(

    return;
}


/*-----------------------------------------------------------------------------------------*
 * Function ivas_get_imdft_twid_factors()
 *
@@ -134,8 +230,6 @@ static void ivas_get_imdft_twid_factors(

    return;
}


static void get_one_by_length(
    float *one_by_length,
    const int16_t length )
@@ -171,8 +265,175 @@ static void get_one_by_length(

    return;
}
#ifdef IVAS_FLOAT_FIXED

static void get_one_by_length_fx(
    Word32 *one_by_length,
    const Word16 length )
{
    if ( length == L_FRAME48k )
    {
        *one_by_length = IVAS_ONE_BY_960_Q37;
    }
    else if ( length == L_FRAME32k )
    {
        *one_by_length = IVAS_ONE_BY_640_Q37;
    }
    else if ( length == L_FRAME16k )
    {
        *one_by_length = IVAS_ONE_BY_320_Q37;
    }
    else if ( length == IVAS_240_PT_LEN )
    {
        *one_by_length = IVAS_ONE_BY_240_Q37;
    }
    else if ( length == IVAS_160_PT_LEN )
    {
        *one_by_length = IVAS_ONE_BY_160_Q37;
    }
    else if ( length == IVAS_80_PT_LEN )
    {
        *one_by_length = IVAS_ONE_BY_80_Q37;
    }
    else
    {
        assert( !"Not supported FFT length!" );
    }

    return;
}

/*-----------------------------------------------------------------------------------------*
 * Function ivas_ifft_cplx1()
 *
 * Complex IFFT implementation using fft()
 *-----------------------------------------------------------------------------------------*/

static void ivas_ifft_cplx1_fx(
    Word32 *re,
    Word32 *im,
    const Word16 length )
{
    Word16 i;
    Word32 one_by_length, tmp;
    get_one_by_length_fx( &one_by_length, length );

    /* re-arrange inputs to use fft as ifft */
    re[0] = Mpy_32_32( re[0], one_by_length );
    im[0] = Mpy_32_32( im[0], one_by_length );

    for ( i = 1; i <= length >> 1; i++ )
    {
        tmp = Mpy_32_32( re[length - i], one_by_length ); /*stl_arr_index*/
        re[length - i] = Mpy_32_32( re[i], one_by_length ); /*stl_arr_index*/
        re[i] = tmp;

        tmp = Mpy_32_32( im[length - i], one_by_length ); /*stl_arr_index*/
        im[length - i] = Mpy_32_32( im[i], one_by_length ); /*stl_arr_index*/
        im[i] = tmp;
    }
    
    fft_fx( re, im, length, 1 );

    return;
}
#endif
#ifdef IVAS_FLOAT_FIXED

/*-----------------------------------------------------------------------------------------*
* Function ivas_mdft()

* MDFT implementation
*-----------------------------------------------------------------------------------------*/

void ivas_mdft_fx(
    const Word32 *pIn,           /* i  : input time-domain signal    */
    Word32 *pOut_re,             /* o  : Real part of MDFT signal    */
    Word32 *pOut_im,            /* o  : Imag. part of MDFT signal   */
    const Word16 input_length, /* i  : signal length               */
    const Word16 mdft_length   /* i  : MDFT length                 */
)
{
    Word32 re[L_FRAME48k];
    Word32 im[L_FRAME48k];
    Word16 j, len_by_2;
    const Word32 *pTwid;
    len_by_2 = mdft_length >> 1;

    ivas_get_mdft_twid_factors_fx( mdft_length, &pTwid );
    if ( mdft_length == input_length )
    {
        for ( j = 0; j < mdft_length; j++ )
        {
            re[j] = Mpy_32_32(pIn[j] , pTwid[j]);
            im[j] = Mpy_32_32 (- pIn[j] , pTwid[mdft_length - j]);
        }
    }
    else
    {
        for ( j = 0; j < mdft_length; j++ )
        {
            re[j] = Msub_32_32(Mpy_32_32(pIn[j] , pTwid[j]) , pIn[j + mdft_length] , pTwid[mdft_length - j]);
            im[j] = Msub_32_32(Mpy_32_32(-pIn[j] , pTwid[mdft_length - j]) , pIn[j + mdft_length] , pTwid[j]);
        }
    }
  
    fft_fx( re, im, mdft_length, 1 );
    for ( j = 0; j < len_by_2; j++ )
    {
        pOut_re[2 * j] = re[j];
        pOut_re[2 * j + 1] = re[mdft_length - j - 1];

        pOut_im[2 * j] = im[j];
        pOut_im[2 * j + 1] = -im[mdft_length - j - 1];
    }
    return;
}


/*-----------------------------------------------------------------------------------------*
 * Function ivas_imdft()
 *
 * iMDFT implementation
 * out buffer needs to have 2*length worth memory
 *-----------------------------------------------------------------------------------------*/

void ivas_imdft_fx(
    const Word32 *pRe,    /* i  : Real part of MDFT signal    */
    const Word32 *pIm,   /* i  : Imag. part of MDFT signal   */
    Word32 *pOut,        /* o  : output time-domain signal   */
    const Word16 length /* i  : signal length               */
)
{
    Word32 *re_tmp = pOut;
    Word32 *im_tmp = pOut + length;
    Word32 tmp;
    Word32 j;
    Word32 len_by_2 = length >> 1;
    const Word32 *pTwid;

    ivas_get_imdft_twid_factors_fx( length, &pTwid );

    for ( j = 0; j < len_by_2; j++ )
    {
        re_tmp[j] = pRe[2 * j];
        re_tmp[j + len_by_2] = pRe[length - 2 * j - 1];

        im_tmp[j] = pIm[2 * j];
        im_tmp[j + len_by_2] = -pIm[length - 2 * j - 1];
    }

    ivas_ifft_cplx1_fx( re_tmp, im_tmp, length );
    
    for ( j = 0; j < length; j++ )
    {
        tmp = Msub_32_32(Mpy_32_32(re_tmp[j] >> 6 , pTwid[j]) , im_tmp[j] >> 6, pTwid[length - j]);
        im_tmp[j] = -( Madd_32_32( Mpy_32_32(re_tmp[j] >> 6, pTwid[length - j]) , im_tmp[j] >> 6, pTwid[j] ));
        re_tmp[j] = tmp;
    }
    return;
}
#endif
/*-----------------------------------------------------------------------------------------*
 * Function ivas_ifft_cplx1()
 *
@@ -208,8 +469,6 @@ static void ivas_ifft_cplx1(

    return;
}


/*-----------------------------------------------------------------------------------------*
* Function ivas_mdft()

Loading