Commit 48023415 authored by TYAGIRIS's avatar TYAGIRIS
Browse files

imdft precision fix

parent 1b7034bd
Loading
Loading
Loading
Loading
+74 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@
#include "ivas_prot_fx.h"
#include "prot_fx.h"
#include "ivas_rom_com_fx.h"
#ifdef DEBUG_SPAR_FX_CODE
#include "debug.h"
#endif


/*------------------------------------------------------------------------------------------*
@@ -555,6 +558,7 @@ void ivas_fb_mixer_pcm_ingest_fx(
        // mvr2r(&hFbMixer->ppFilterbank_prior_input[i][fb_cfg->prior_input_length - frame_len], ppOut_pcm[i], frame_len);
        Copy32( &hFbMixer->ppFilterbank_prior_input_fx[i][fb_cfg->prior_input_length - frame_len], ppOut_pcm[i], frame_len );

        // seems redundant if q factor of in PCM is always q_data_fix
        IF( LT_16( q_temp, hFbMixer->q_ppFilterbank_prior_input_fx[i] ) )
        {
            FOR( Word16 x = 0; x < frame_len; x++ )
@@ -729,6 +733,7 @@ void ivas_fb_mixer_cross_fading_fx(
        move16();
        move16();


        FOR( k = 0; k < fade_start_offset; k++ )
        {
            ppOut_pcm_fx[ch][k] = pMdft_out_old_fx[k + cf_offset]; // Qx
@@ -805,6 +810,9 @@ void ivas_fb_mixer_process_fx(
    move16();
    Word32 Out_fr_re_fx[L_FRAME48k], Out_fr_im_fx[L_FRAME48k];
    Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2];
#ifdef NONBE_FB_MIXER_CF_FIX
    Word16 norms[2];
#endif

    pOut_fr_re_fx = Out_fr_re_fx;
    pOut_fr_im_fx = Out_fr_im_fx;
@@ -852,6 +860,7 @@ void ivas_fb_mixer_process_fx(
                            move32();
                            filterbank_mixer_bins_im_fx[k] = L_add_sat( filterbank_mixer_bins_im_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_im_fx, mixer_const_fx ), total_guard ) ); // Q30 + hFbMixer->q_prior_mixer_fx - 31 - total_guard
                            move32();

                            /*filterbank_mixer_bins_im_fx q 30 */
                            /*mixer_const_fx q  q_ppOut_pcm_fx */
                            pFilterbank_bin_to_band_re_fx++;
@@ -893,11 +902,76 @@ void ivas_fb_mixer_process_fx(
                    move16();
                }
            }
#ifdef DEBUG_SPAR_FX_CODE
            {
                char file_name[100] = { 0 };
                float outre[960], outim[960];

                sprintf( file_name, "./res/fbmixer_re_im.pcm" );

                dbgread( outre, sizeof( float ), frame_len, file_name );
                dbgread( outim, sizeof( float ), frame_len, file_name );
                FOR( k = 0; k < frame_len; k++ )
                {
                    pOut_fr_re_fx[k] = (Word32) ( ( outre[k] * L_shl( 32768, ( q_pOut_fr_fx ) ) / 32768.0f ) );
                    pOut_fr_im_fx[k] = (Word32) ( ( outim[k] * L_shl( 32768, ( q_pOut_fr_fx ) ) / 32768.0f ) );
                }
            }
#endif

#ifdef NONBE_FB_MIXER_CF_FIX
            norms[hist] = ivas_imdft_fx( pOut_fr_re_fx, pOut_fr_im_fx, pMdft_out_fx[hist], frame_len ); // q_pOut_fr_fx + norms[hist]
            move16();
#else
            ivas_imdft_fx( pOut_fr_re_fx, pOut_fr_im_fx, pMdft_out_fx[hist], frame_len );
#endif
        }
#ifdef NONBE_FB_MIXER_CF_FIX
        Word16 minNorm = s_min( norms[0], norms[1] );
        move16();
        IF( NE_16( minNorm, norms[0] ) )
        {
            scale_sig32( pMdft_out_fx[0], 2 * frame_len, sub( minNorm, norms[0] ) );
        }
        IF( NE_16( minNorm, norms[1] ) )
        {
            scale_sig32( pMdft_out_fx[1], 2 * frame_len, sub( minNorm, norms[1] ) );
        }
        // q_pOut_fr_fx + minNorm
        q_pOut_fr_fx = add( q_pOut_fr_fx, minNorm );
        move16();
#endif

#if 0 // def DEBUG_SPAR_FX_CODE
        FOR( hist = 0; hist < 2; hist++ )
        {
            char file_name[100] = { 0 };
            float mdftoutt[2][2 * 960];
            sprintf( file_name, "./res/fbmixer_mdftout.pcm" );

            dbgread( mdftoutt[hist], sizeof( float ), 2 * frame_len, file_name );
            FOR( k = 0; k < 2 * frame_len; k++ )
            {
                pMdft_out_fx[hist][k] = (Word32) ( ( mdftoutt[hist][k] * L_shl( 32768, ( q_pOut_fr_fx ) ) / 32768.0f ) );
            }
        }
#endif

        ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len );
        q_ppOut_pcm_fx[ch] = q_pOut_fr_fx;
#if 0 // def DEBUG_SPAR_FX_CODE
        {
            char file_name[100] = { 0 };
            float mdftoutt[960];
            sprintf( file_name, "./res/fbmixer_crossfaded.pcm" );

            dbgread( mdftoutt, sizeof( float ), frame_len, file_name );
            FOR( k = 0; k < frame_len; k++ )
            {
                ppOut_pcm_fx[ch][k] = (Word32) ( ( mdftoutt[k] * L_shl( 32768, ( q_pOut_fr_fx ) ) / 32768.0f ) );
            }
        }
#endif
        move16();
    }

+93 −13
Original line number Diff line number Diff line
@@ -48,13 +48,21 @@
/*-----------------------------------------------------------------------------------------*
 * Local constants
 *-----------------------------------------------------------------------------------------*/

#ifdef NONBE_FB_MIXER_CF_FIX
#define IVAS_ONE_BY_960_Q31 2236962
#define IVAS_ONE_BY_640_Q31 3355443
#define IVAS_ONE_BY_320_Q31 6710886
#define IVAS_ONE_BY_240_Q31 8947849
#define IVAS_ONE_BY_160_Q31 13421773
#define IVAS_ONE_BY_80_Q31  26843546
#else
#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
#endif
/*-----------------------------------------------------------------------------------------*
 * Function ivas_get_mdft_twid_factors()
 *
@@ -141,6 +149,42 @@ static void get_one_by_length_fx(
    Word32 *one_by_length, // Q37
    const Word16 length )
{
#ifdef NONBE_FB_MIXER_CF_FIX
    IF( EQ_16( length, L_FRAME48k ) )
    {
        *one_by_length = IVAS_ONE_BY_960_Q31; // Q31
        move32();
    }
    ELSE IF( EQ_16( length, L_FRAME32k ) )
    {
        *one_by_length = IVAS_ONE_BY_640_Q31; // Q31
        move32();
    }
    ELSE IF( EQ_16( length, L_FRAME16k ) )
    {
        *one_by_length = IVAS_ONE_BY_320_Q31; // Q31
        move32();
    }
    ELSE IF( EQ_16( length, IVAS_240_PT_LEN ) )
    {
        *one_by_length = IVAS_ONE_BY_240_Q31; // Q31
        move32();
    }
    ELSE IF( EQ_16( length, IVAS_160_PT_LEN ) )
    {
        *one_by_length = IVAS_ONE_BY_160_Q31; // Q31
        move32();
    }
    ELSE IF( EQ_16( length, IVAS_80_PT_LEN ) )
    {
        *one_by_length = IVAS_ONE_BY_80_Q31; // Q31
        move32();
    }
    ELSE
    {
        assert( !"Not supported FFT length!" );
    }
#else
    IF( EQ_16( length, L_FRAME48k ) )
    {
        *one_by_length = IVAS_ONE_BY_960_Q37; // Q37
@@ -175,6 +219,7 @@ static void get_one_by_length_fx(
    {
        assert( !"Not supported FFT length!" );
    }
#endif

    return;
}
@@ -192,31 +237,32 @@ static void ivas_ifft_cplx1_fx(
{
    Word16 i;
    Word32 one_by_length, tmp;
    get_one_by_length_fx( &one_by_length, length ); // Q37
    get_one_by_length_fx( &one_by_length, length ); // Q31

    /* re-arrange inputs to use fft as ifft */
    re[0] = Mpy_32_32( re[0], one_by_length ); // ( Qin + Q37 ) - Q31 -> Qin + 6
    re[0] = Mpy_32_32( re[0], one_by_length ); // ( Qin + Q31 ) - Q31 -> Qin
    move32();
    im[0] = Mpy_32_32( im[0], one_by_length ); // ( Qin + Q37 ) - Q31 -> Qin + 6
    im[0] = Mpy_32_32( im[0], one_by_length ); // ( Qin + Q31 ) - Q31 -> Qin
    move32();

    FOR( i = 1; i <= length >> 1; i++ )
    {
        tmp = Mpy_32_32( re[length - i], one_by_length );   /*stl_arr_index       Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */
        re[length - i] = Mpy_32_32( re[i], one_by_length ); /*stl_arr_index       Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */
        tmp = Mpy_32_32( re[length - i], one_by_length );   /*stl_arr_index       Q: ( Qin + Q31 ) - Q31 -> Qin */
        re[length - i] = Mpy_32_32( re[i], one_by_length ); /*stl_arr_index       Q: ( Qin + Q31 ) - Q31 -> Qin */
        move32();
        re[i] = tmp;
        move32();

        tmp = Mpy_32_32( im[length - i], one_by_length );   /*stl_arr_index        Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */
        im[length - i] = Mpy_32_32( im[i], one_by_length ); /*stl_arr_index        Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */
        tmp = Mpy_32_32( im[length - i], one_by_length );   /*stl_arr_index        Q: ( Qin + Q31 ) - Q31 -> Qin */
        im[length - i] = Mpy_32_32( im[i], one_by_length ); /*stl_arr_index        Q: ( Qin + Q31 ) - Q31 -> Qin */
        move32();
        im[i] = tmp; // Q: ( Qin + Q37 ) - Q31 -> Qin + 6
        im[i] = tmp; // Q: ( Qin + Q31 ) - Q31 -> Qin
        move32();
    }

    fft_fx( re, im, length, 1 );


    return;
}

@@ -279,19 +325,34 @@ void ivas_mdft_fx(
}


#ifdef NONBE_FB_MIXER_CF_FIX
/*-----------------------------------------------------------------------------------------*
 * Function ivas_imdft()
 *
 * iMDFT implementation
 * out buffer needs to have 2*length worth memory
 * out: Norm shift
 *-----------------------------------------------------------------------------------------*/
Word16 ivas_imdft_fx(
    const Word32 *pRe,  /* i  : Real part of MDFT signal      Qin          */
    const Word32 *pIm,  /* i  : Imag. part of MDFT signal     Qin          */
    Word32 *pOut,       /* o  : output time-domain signal     Qin        */
    const Word16 length /* i  : signal length                              */
)
#else
/*-----------------------------------------------------------------------------------------*
 * 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      Qin          */
    const Word32 *pIm,  /* i  : Imag. part of MDFT signal     Qin          */
    Word32 *pOut,       /* o  : output time-domain signal     Qin        */
    const Word16 length /* i  : signal length                              */
)
#endif
{
    Word32 *re_tmp = pOut;
    Word32 *im_tmp = pOut + length;
@@ -299,6 +360,9 @@ void ivas_imdft_fx(
    Word16 j;
    Word16 len_by_2;
    const Word32 *pTwid; // Q31
#ifdef NONBE_FB_MIXER_CF_FIX
    Word16 norm;
#endif
    len_by_2 = shr( length, 1 );

    ivas_get_imdft_twid_factors_fx( length, &pTwid );
@@ -316,17 +380,33 @@ void ivas_imdft_fx(
        move32();
    }

#ifdef NONBE_FB_MIXER_CF_FIX
    norm = s_min( L_norm_arr( re_tmp, length ), L_norm_arr( im_tmp, length ) );
    move16();
    scale_sig32( re_tmp, length, norm );
    scale_sig32( im_tmp, length, norm );
#endif

    ivas_ifft_cplx1_fx( re_tmp, im_tmp, length );
    // re_tmp: Qin + 6
    // im_tmp: Qin + 6
    // re_tmp: Qin
    // im_tmp: Qin

    FOR( j = 0; j < length; j++ )
    {
#ifdef NONBE_FB_MIXER_CF_FIX
        tmp = Msub_32_32( Mpy_32_32( re_tmp[j], pTwid[j] ), im_tmp[j], pTwid[length - j] );                   // ( ( Qin ) + Q31 ) - Q31 -> Qin
        im_tmp[j] = L_negate( Madd_32_32( Mpy_32_32( re_tmp[j], pTwid[length - j] ), im_tmp[j], pTwid[j] ) ); // ( ( Qin ) + Q31 ) - Q31 -> Qin
#else
        tmp = Msub_32_32( Mpy_32_32( L_shr( re_tmp[j], Q6 ), pTwid[j] ), L_shr( im_tmp[j], Q6 ), pTwid[length - j] );                   // ( ( Qin + Q6 - Q6 ) + Q31 ) - Q31 -> Qin
        im_tmp[j] = L_negate( Madd_32_32( Mpy_32_32( L_shr( re_tmp[j], Q6 ), pTwid[length - j] ), L_shr( im_tmp[j], Q6 ), pTwid[j] ) ); // ( ( Qin + Q6 - Q6 ) + Q31 ) - Q31 -> Qin
#endif
        move32();
        re_tmp[j] = tmp; // ( ( Qin + Q6 - Q6 ) + Q31 ) - Q31 -> Qin
        re_tmp[j] = tmp; // ( ( Qin ) + Q31 ) - Q31 -> Qin
        move32();
    }
#ifdef NONBE_FB_MIXER_CF_FIX
    return norm;
#else
    return;
#endif
}
+9 −0
Original line number Diff line number Diff line
@@ -4026,12 +4026,21 @@ void ivas_mdft_fx(
    const Word16 mdft_length /* i  : MDFT length                                  */
);

#ifdef NONBE_FB_MIXER_CF_FIX
Word16 ivas_imdft_fx(
    const Word32 *pRe,  /* i  : Real part of MDFT signal            Qin              */
    const Word32 *pIm,  /* i  : Imag. part of MDFT signal           Qin              */
    Word32 *pOut,       /* o  : output time-domain signal           Qin              */
    const Word16 length /* i  : signal length                                          */
);
#else
void ivas_imdft_fx(
    const Word32 *pRe,  /* i  : Real part of MDFT signal            Qin              */
    const Word32 *pIm,  /* i  : Imag. part of MDFT signal           Qin              */
    Word32 *pOut,       /* o  : output time-domain signal           Qin              */
    const Word16 length /* i  : signal length                                          */
);
#endif

void TonalMdctConceal_create_concealment_noise_ivas_fx(
    Word32 concealment_noise[L_FRAME48k],
+1 −1
Original line number Diff line number Diff line
@@ -4508,7 +4508,7 @@ void ivas_get_spar_md_from_dirac_enc_fx(
                {
                    for ( j = 0; j < num_ch; j++ )
                    {
                        for ( k = start_band; k < end_band; k++ )
                        for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ )
                        {
                            dbgread( &mixer_mat[i][j][k + i_ts * IVAS_MAX_NUM_BANDS], sizeof( float ), 1, file_name );
                            mixer_mat_fx[i][j][k + ( i_ts * IVAS_MAX_NUM_BANDS )] = (Word32) roundf( mixer_mat[i][j][k + i_ts * IVAS_MAX_NUM_BANDS] * ( 1 << *q_mixer_mat_fx ) );
+3 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@
#define DEBUG_FORCE_MDCT_STEREO_MODE      /* Force stereo mode decision for MDCT stereo: -stereo 3 1 forces L/R coding and -stereo 3 2 forces full M/S coding */
/*#define DBG_WAV_WRITER*/                    /* Enable dbgwrite_wav() function for generating ".wav" files */
#define DEBUG_BYPASS_CORE_CODER
#define DEBUG_SPAR_FX_CODE
//#define DEBUG_SPAR_FX_CODE
#endif

#define SUPPORT_JBM_TRACEFILE                   /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */
@@ -86,4 +86,6 @@
#define NONBE_1233_HQ_CLASSIFIER_DIV_BY_ZERO            /* Eri: issue 1233: Address possible division by zero in hf_spectrum_sparseness() */
//#define NONBE_FIX_SBA_TRANS_DET_PRECISION               /*Work in progress*/
//#define NONBE_FIX_SBA_FFT_PRECISION                     /*Work in progress*/
//#define NONBE_FIX_PRIOR_MIXER_Q
#define NONBE_FB_MIXER_CF_FIX
#endif
Loading