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

Merge branch 'generate_stereo_masking_noise_fxd' into 'main'

generate_stereo_masking_noise() and sub-funcs converted to fixed point.

See merge request !121
parents 71da9eaa 202f6713
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1666,6 +1666,7 @@ enum
#define FD_CNG_JOINT_stages_25bits          4

#define OUTMAX_INV                          0.000030517578125f            /* 1/2^15 */
#define OUTMAX_INV_FX                       65536                         /* 1/2^15 (Q31) */
#define OUTMAX_SQ                           1073741824.f                  /* 2^30 */
#define OUTMAX_SQ_INV                       0.00000000093132257461547852f /* 1/2^30 */

+130 −2
Original line number Diff line number Diff line
@@ -39,10 +39,14 @@
#include "options.h"
#include <math.h>
#include "prot.h"
#include "prot_fx2.h"
#include "rom_com.h"
#include "wmc_auto.h"


#ifdef IVAS_FLOAT_FIXED
#define FFT_SCALING_512    1073741824 //Q22
#define FFT_SCALING_640    1342177280 //Q22
#endif
/*-------------------------------------------------------------------
 * Local function prototypes
 *-------------------------------------------------------------------*/
@@ -103,6 +107,10 @@ void initFdCngCom_flt(
    set_f( hFdCngCom->sidNoiseEst_flt, 0.0f, NPART );
    set_f( hFdCngCom->A_cng_flt, 0.0f, M + 1 );
    hFdCngCom->A_cng_flt[0] = 1.f;
#ifdef IVAS_FLOAT_FIXED
    set_s( hFdCngCom->A_cng, 0, M + 1 );
    hFdCngCom->A_cng[0] = MAX_16;
#endif

    /* Set some counters and flags */
    hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */
@@ -110,6 +118,9 @@ void initFdCngCom_flt(
    hFdCngCom->frame_type_previous = ACTIVE_FRAME;
    hFdCngCom->flag_noisy_speech = 0;
    hFdCngCom->likelihood_noisy_speech_flt = 0.f;
#ifdef IVAS_FLOAT_FIXED
    hFdCngCom->likelihood_noisy_speech_32fx = 0;
#endif
    hFdCngCom->numCoreBands = 0;
    hFdCngCom->stopBand = 0;
    hFdCngCom->startBand = 0;
@@ -937,6 +948,115 @@ void SynthesisSTFT_flt(
    return;
}

#ifdef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------
 * SynthesisSTFT_fx()
 *
 * STFT synthesis filterbank
 *-------------------------------------------------------------------*/

void SynthesisSTFT_fx(
    Word32 *fftBuffer, /* i  : FFT bins */
    Word16 Q_in,
    Word32 *timeDomainOutput,
    Word32 *olapBuffer,
    const Word16 *olapWin,
    const int16_t tcx_transition,
    HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
    const int16_t element_mode,  /* i  : element mode */
    const int16_t nchan_out      /* i  : number of output channels */
)
{
    int16_t i;
    Word32 buf_fx[M + 1 + 320], tmp_fx;

    /* Perform IFFT */
    RFFTN_fx( fftBuffer, hFdCngCom->fftSineTab_fx, hFdCngCom->fftlen, 1 );

    /* Handle overlap in P/S domain for stereo */
    IF( ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) && nchan_out == 2 )
    {
        mvl2l( olapBuffer + 3 * hFdCngCom->frameSize / 4 - ( M + 1 ), buf_fx, hFdCngCom->frameSize + M + 1 );
        set_l( olapBuffer, 0, hFdCngCom->fftlen );
    }
    ELSE
    {
        mvl2l( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize );
        set_l( olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize ); /*olapBuffer, fftBuffer, olapWin*/
    }

    IF( tcx_transition )
    {
        FOR( i = 0; i < 5 * hFdCngCom->frameSize / 4; i++ )
        {
            olapBuffer[i] = fftBuffer[i];
        }
    }
    ELSE
    {
        FOR( i = hFdCngCom->frameSize / 4; i < 3 * hFdCngCom->frameSize / 4; i++ )
        {
            olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[i - hFdCngCom->frameSize / 4] ) );
        }
        FOR( ; i < 5 * hFdCngCom->frameSize / 4; i++ )
        {
            olapBuffer[i] = fftBuffer[i];
        }
    }
    FOR( ; i < 7 * hFdCngCom->frameSize / 4; i++ )
    {
        olapBuffer[i] = Mpy_32_16_1( fftBuffer[i], olapWin[i - 3 * hFdCngCom->frameSize / 4] );
    }

    FOR( ; i < hFdCngCom->fftlen; i++ )
    {
        olapBuffer[i] = 0;
    }

    Word32 fftScale = 0;
    SWITCH( hFdCngCom->fftlen )
    {
        case 640:
            fftScale = FFT_SCALING_640;
            break;
        case 512:
            fftScale = FFT_SCALING_512;
            break;
        default:
            assert( !"Not supported FFT length!" );
    }
    /* Get time-domain signal */
    // v_multc(olapBuffer + hFdCngCom->frameSize / 4, (float)(hFdCngCom->fftlen / 2), timeDomainOutput, hFdCngCom->frameSize);
    v_multc_fixed( olapBuffer + hFdCngCom->frameSize / 4, fftScale, timeDomainOutput, hFdCngCom->frameSize ); // Q_in - 9
    /* Get excitation */
    IF( ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) && nchan_out == 2 )
    {
        FOR( i = 0; i < hFdCngCom->frameSize / 2; i++ )
        {
            buf_fx[i + ( M + 1 )] = L_add( buf_fx[i + ( M + 1 )], olapBuffer[i + hFdCngCom->frameSize / 4] );
        }
        // v_multc(buf, (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize);
        v_multc_fixed( buf_fx, fftScale, buf_fx, M + 1 + hFdCngCom->frameSize );
    }
    ELSE
    {
        // v_multc(olapBuffer + hFdCngCom->frameSize / 4 - (M + 1), (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize);
        v_multc_fixed( olapBuffer + ( hFdCngCom->frameSize / 4 ) - ( M + 1 ), fftScale, buf_fx, M + 1 + hFdCngCom->frameSize );
    }

    tmp_fx = buf_fx[0];
    // preemph(buf + 1, PREEMPH_FAC_FLT, M + hFdCngCom->frameSize, &tmp);
    preemph_ivas_fx( buf_fx + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp_fx );
    // residu(hFdCngCom->A_cng_flt, M, buf + 1 + M, hFdCngCom->exc_cng_flt, hFdCngCom->frameSize);
    residu_ivas_fx( hFdCngCom->A_cng, Q13, M, buf_fx + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize );
    for ( i = 0; i < hFdCngCom->frameSize; i++ )
    {
        hFdCngCom->exc_cng_flt[i] = fix_to_float( hFdCngCom->exc_cng_32fx[i], Q_in - 9 );
    }

    return;
}
#endif

/*-------------------------------------------------------------------
 * SynthesisSTFT_dirac_flt()
@@ -1112,6 +1232,9 @@ void lpc_from_spectrum_flt(
    int16_t fftlen = hFdCngCom->fftlen;
    const float *fftSineTab = hFdCngCom->fftSineTab_flt;
    float *A = hFdCngCom->A_cng_flt;
#ifdef IVAS_FLOAT_FIXED
    Word16 *A_fx = hFdCngCom->A_cng;
#endif

    /* Power Spectrum */
    ptr = fftBuffer;
@@ -1165,7 +1288,12 @@ void lpc_from_spectrum_flt(

    /* LPC */
    lev_dur( A, r, M, NULL );

#ifdef IVAS_FLOAT_FIXED
    for ( i = 0; i < M + 1; i++ )
    {
        A_fx[i] = float_to_fix16( A[i], Q13 );
    }
#endif
    return;
}

+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@
#define _180_OVER_PI_Q25                         1922527233
#define PI_OVER_4_Q29                            421657440
#define PI_OVER_Q29                              1686629760
#define Q31_0_99                                 2126008811
#define Q31_0_01                                 21474836
#endif

#define SQRT2                                   1.414213562373095f
+29 −0
Original line number Diff line number Diff line
@@ -66,3 +66,32 @@ void preemph(

    return;
}


/*-------------------------------------------------------------*
 * preemph_ivas_fx()
 *
 * Preemphasis: filtering through 1 - mu z^-1
 *-------------------------------------------------------------*/

void preemph_ivas_fx(
    Word32 *signal,  /* i/o: signal             */
    const Word16 mu, /* i  : preemphasis factor */
    const Word16 L,  /* i  : vector size        */
    Word32 *mem      /* i/o: memory (x[-1])     */
)
{
    Word16 i;
    Word32 temp;

    temp = signal[L - 1];
    FOR( i = L - 1; i > 0; i-- )
    {
        signal[i] = L_sub( signal[i], Mpy_32_16_1( signal[i - 1], mu ) );
    }

    signal[0] = L_sub( signal[0], Mpy_32_16_1( *mem, mu ) );
    *mem = temp;

    return;
}
 No newline at end of file
+56 −1
Original line number Diff line number Diff line
@@ -813,7 +813,12 @@ void preemph(
    const int16_t L, /* i  : vector size        */
    float *mem       /* i/o: memory (x[-1])     */
);

void preemph_ivas_fx(
    Word32 *signal,  /* i/o: signal             */
    const Word16 mu, /* i  : preemphasis factor */
    const Word16 L,  /* i  : vector size        */
    Word32 *mem      /* i/o: memory (x[-1])     */
);
void cb_shape(
    const int16_t preemphFlag,     /* i  : flag for pre-emphasis                       */
    const int16_t pitchFlag,       /* i  : flag for pitch sharpening                   */
@@ -1102,6 +1107,15 @@ void residu(
    const int16_t l  /* i  : size of filtering                           */
);

void residu_ivas_fx(
    const Word16 *a, /* i  : LP filter coefficients           */
    const Word16 a_exp,
    const Word16 m,  /* i  : order of LP filter               */
    const Word32 *x, /* i  : input signal (usually speech)    */
    Word32 *y,       /* o  : output signal (usually residual) */
    const Word16 l   /* i  : size of filtering                */
);

void calc_residu(
    const float *speech,  /* i  : weighted speech signal                      */
    float *res,           /* o  : residual signal                             */
@@ -8635,6 +8649,21 @@ void generate_masking_noise_flt(
    const int16_t nchan_out           /* i  : number of output channels */
);

#ifdef IVAS_FLOAT_FIXED
void generate_masking_noise_ivas_fx(
    Word32 *timeDomainBuffer,         /* i/o: time-domain signal */
    Word16 *exp_out,                  /* o  : time-domain signal exp */
    HANDLE_FD_CNG_COM hFdCngCom,      /* i/o: FD_CNG structure containing all buffers and variables */
    const int16_t length,             /* i  : frame size                                       */
    const int16_t core,               /* i  : core                                             */
    const int16_t return_noise,       /* i  : noise is returned instead of added */
    const int16_t secondary,          /* i  : flag to indicate secondary noise generation */
    const int16_t element_mode,       /* i  : element mode */
    STEREO_CNG_DEC_HANDLE hStereoCng, /* i  : stereo CNG handle */
    const int16_t nchan_out           /* i  : number of output channels */
);
#endif

void generate_masking_noise_update_seed_flt(
    HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables   */
);
@@ -8674,6 +8703,18 @@ void generate_stereo_masking_noise(
    const int16_t nchan_out              /* i  : number of output channels       */
);

#ifdef IVAS_FLOAT_FIXED
void generate_stereo_masking_noise_fx(
    float *syn,                          /* i/o: time-domain signal              */
    Decoder_State *st,                   /* i/o: decoder state structure         */
    STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i  : TD stereo structure             */
    const int16_t flag_sec_CNA,          /* i  : CNA flag for secondary channel  */
    const int16_t fadeOut,               /* i  : only fade out of previous state */
    STEREO_CNG_DEC_HANDLE hStereoCng,    /* i  : stereo CNG handle               */
    const int16_t nchan_out              /* i  : number of output channels       */
);
#endif

void apply_scale_flt(
    float *scale,                  /* i  : scale factor                                            */
    const int16_t bwidth,          /* i  : audio bandwidth                                         */
@@ -8728,6 +8769,20 @@ void SynthesisSTFT_flt(
    const int16_t nchan_out     /* i  : number of output channels */
);

#ifdef IVAS_FLOAT_FIXED
void SynthesisSTFT_fx(
    Word32 *fftBuffer, /* i  : FFT bins */
    Word16 Q_in,
    Word32 *timeDomainOutput,
    Word32 *olapBuffer,
    const Word16 *olapWin,
    const int16_t tcx_transition,
    HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
    const int16_t element_mode,  /* i  : element mode */
    const int16_t nchan_out      /* i  : number of output channels */
);
#endif

float rand_gauss_flt(
    float *x,
    int16_t *seed );
Loading