Commit 2ac14933 authored by vaclav's avatar vaclav
Browse files

HARMONIZE_DCT

parent 78c80a0c
Loading
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -758,9 +758,51 @@ Word16 getScaleFactor32( /* o: measured headroom in range [

    i = s_and( s_min( i_max, i_min ), 0x1F );

    return i;
}

#ifdef OPTIMIZE_FFT_STACK
/* o: measured headroom in range [0..31], 0 if all x[i] == 0 */
Word16 getScaleFactor32_cmplx( 
    cmplx *x,     /* i: array containing 32-bit data */
    const Word16 len_x  /* i: length of the array to scan  */
)
{
    Word16 i, i_min, i_max;
    Word32 x_min, x_max;

    x_max = 0;
    move32();
    x_min = 0;
    move32();
    FOR( i = 0; i < len_x; i++ )
    {
        if ( x[i].re >= 0 )
            x_max = L_max( x_max, x[i].re );
        if ( x[i].re < 0 )
            x_min = L_min( x_min, x[i].re );
        if ( x[i].im >= 0 )
            x_max = L_max( x_max, x[i].im );
        if ( x[i].im < 0 )
            x_min = L_min( x_min, x[i].im );
    }

    i_max = 0x20;
    move16();
    i_min = 0x20;
    move16();

    if ( x_max != 0 )
        i_max = norm_l( x_max );

    if ( x_min != 0 )
        i_min = norm_l( x_min );

    i = s_and( s_min( i_max, i_min ), 0x1F );

    return i;
}
#endif

Word16 getScaleFactor32_copy(                      /* o: measured headroom in range [0..31], 0 if all x[i] == 0 */
                              const Word32 *x,     /* i: array containing 32-bit data */
+8 −0
Original line number Diff line number Diff line
@@ -235,6 +235,14 @@ Word16 getScaleFactor32(
    const Word32 *x,      /* i  : array containing 32-bit data */
    const Word16 len_x ); /* i  : length of the array to scan  */

#ifdef OPTIMIZE_FFT_STACK
/* o: measured headroom in range [0..31], 0 if all x[i] == 0 */
Word16 getScaleFactor32_cmplx(
    cmplx *x,    /* i: array containing 32-bit data */
    const Word16 len_x  /* i: length of the array to scan  */
);
#endif

Word16 getScaleFactor32_copy(                       /* o: measured headroom in range [0..31], 0 if all x[i] == 0 */
                              const Word32 *x,      /* i: array containing 32-bit data */
                              const Word32 len_x ); /* i: length of the array to scan  */
+160 −22
Original line number Diff line number Diff line
@@ -207,14 +207,23 @@ void edct_fx(
    const Word32 *x, /* i  : input signal        Qq         */
    Word32 *y,       /* o  : output transform    Qq         */
    Word16 length,   /* i  : length                         Q0*/
#ifdef HARMONIZE_DCT
    Word16 *q,                /* i  : Q value of input signal        */
    const Word16 element_mode /* i  : element mode                   */
#else
    Word16 *q /* i  : Q value of input signal        */
#endif
)
{
    Word16 i;
    Word32 re;
    Word32 im;
    const Word16 *edct_table; /*Q16 */
#ifdef OPTIMIZE_FFT_STACK
    cmplx spec[L_FRAME_PLUS / 2];
#else
    Word32 complex_buf[2 * ( L_FRAME48k / 2 + 240 )];
#endif
    Word32 L_tmp;
    Word16 tmp;
    Word16 len1;
@@ -225,36 +234,93 @@ void edct_fx(
    FOR( i = 0; i < len1; i++ )
    {
        L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); /*Q(q+1) */
#ifdef OPTIMIZE_FFT_STACK
        spec[i].re = Madd_32_16( L_tmp, x[( length - ( 1 + ( i * 2 ) ) )], edct_table[( len1 - ( 1 + i ) )] ); /*Q(q+1) */
#else
        complex_buf[2 * i] = Madd_32_16( L_tmp, x[( length - ( 1 + ( i * 2 ) ) )], edct_table[( len1 - ( 1 + i ) )] ); /*Q(q+1) */
#endif
        move32();

        L_tmp = Mult_32_16( x[( length - ( 1 + ( i * 2 ) ) )], edct_table[i] ); /*Q(q+1) */

#ifdef OPTIMIZE_FFT_STACK
        spec[i].im = Msub_32_16( L_tmp, x[( i * 2 )], edct_table[( len1 - ( 1 + i ) )] ); /*Q(q+1) */
#else
        complex_buf[( ( i * 2 ) + 1 )] = Msub_32_16( L_tmp, x[( i * 2 )], edct_table[( len1 - ( 1 + i ) )] );          /*Q(q+1) */
#endif
        move32();
    }

#ifdef HARMONIZE_DCT
    IF( element_mode == EVS_MONO )
    {
#endif
        *q = sub( 15, *q );
        move16();
#ifdef OPTIMIZE_FFT_STACK
        BASOP_cfft( spec, len1, q, y );
#else
    BASOP_cfft( (cmplx *) complex_buf, len1, q, y );
#endif

        tmp = div_s( 1, length );                                                     /*Q15 */
        tmp = round_fx( L_shl( L_mult( tmp, 19302 /*0.75f * EVS_PI in Q13*/ ), 2 ) ); /*Q15 */
#ifdef HARMONIZE_DCT
    }
    ELSE
    {
        *q = sub( 31, *q );
        move16();
        tmp = sub( getScaleFactor32_cmplx( spec, len1 ), find_guarded_bits_fx( len1 ) );
        scale_sig32_cmplx( spec, len1, tmp );

        fft_cmplx_fx( spec, len1 );
        *q = sub( *q, tmp );
        move16();

        tmp = div_s( 4, length );                                         /*Q17 */
        tmp = round_fx( L_mult( tmp, 19302 /*0.75f * EVS_PI in Q13*/ ) ); /*Q15 */
    }
#endif

    FOR( i = 0; i < len1; i++ )
    {
#ifdef OPTIMIZE_FFT_STACK
        re = Msub_32_16( spec[i].re, spec[i].im, tmp ); /*Q(q+1) */
        im = Madd_32_16( spec[i].im, spec[i].re, tmp ); /*Q(q+1) */
#else
        re = Msub_32_16( complex_buf[2 * i], complex_buf[( ( i * 2 ) + 1 )], tmp ); /*Q(q+1) */
        im = Madd_32_16( complex_buf[( ( i * 2 ) + 1 )], complex_buf[2 * i], tmp ); /*Q(q+1) */
#endif
        y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[( len1 - ( 1 + i ) )] ) ); /*Q(q+2)*/
        move32();
        y[( length - ( 1 + ( i * 2 ) ) )] = L_sub( Mult_32_16( re, edct_table[( len1 - ( 1 + i ) )] ), Mult_32_16( im, edct_table[i] ) ); /*Q(q+2)*/
        move32();
    } /*Q(q-2) */

#ifdef HARMONIZE_DCTaa
    IF( element_mode == EVS_MONO )
    {
        *q = sub( 15 + 2, *q );
    }
    ELSE
    {
        *q = sub( 31 + 2, *q );
    }
#else
    *q = sub( 15 + 2, *q );
#ifdef HARMONIZE_DCT
    IF( element_mode != EVS_MONO )
    {
        *q = add( *q, Q16 );
    }
#endif
#endif
    move16();

    return;
}

#ifndef HARMONIZE_DCT
void edct_ivas_fx(
    const Word32 *x, /* i  : input signal        Qq         */
    Word32 *y,       /* o  : output transform    Qq         */
@@ -314,8 +380,11 @@ void edct_ivas_fx(

    *q = sub( 31 + 2, *q );
    move16();

    return;
}
#endif

/*-------------------------------------------------------------------------*
 * FUNCTION : edst_fx()
 *
@@ -340,7 +409,11 @@ void edst_fx(
    Word32 re;
    Word32 im;
    const Word16 *edct_table; /*Q16 */
#ifdef OPTIMIZE_FFT_STACK
    cmplx complex_buf[L_FRAME_PLUS / 2];
#else
    Word32 complex_buf[2 * ( L_FRAME48k / 2 + 240 )];
#endif
    Word32 L_tmp;
    Word16 tmp;
    Word16 len1;
@@ -351,24 +424,41 @@ void edst_fx(
    FOR( i = 0; i < len1; i++ )
    {
        L_tmp = Mult_32_16( x[( length - ( 1 + ( i * 2 ) ) )], edct_table[i] ); /*Qq+1*/
#ifdef OPTIMIZE_FFT_STACK
        complex_buf[i].re = Madd_32_16( L_tmp, x[2 * i], edct_table[( len1 - ( 1 + i ) )] ); /*Qq+1*/
#else
        complex_buf[2 * i] = Madd_32_16( L_tmp, x[2 * i], edct_table[( len1 - ( 1 + i ) )] );                                      /*Qq+1*/
#endif
        move32();

        L_tmp = Mult_32_16( x[2 * i], edct_table[i] ); /*Qq+1*/
#ifdef OPTIMIZE_FFT_STACK
        complex_buf[i].im = Msub_32_16( L_tmp, x[( length - ( 1 + ( i * 2 ) ) )], edct_table[( len1 - ( 1 + i ) )] ); /*Qq+1*/
#else
        complex_buf[( ( i * 2 ) + 1 )] = Msub_32_16( L_tmp, x[( length - ( 1 + ( i * 2 ) ) )], edct_table[( len1 - ( 1 + i ) )] ); /*Qq+1*/
#endif
        move32();
    }

    *q = sub( 15, *q );
    move16();
#ifdef OPTIMIZE_FFT_STACK
    BASOP_cfft( complex_buf, len1, q, y );
#else
    BASOP_cfft( (cmplx *) complex_buf, len1, q, y );
#endif

    tmp = div_s( 1, length );                                                     /*Q15 */
    tmp = round_fx( L_shl( L_mult( tmp, 19302 /*0.75f * EVS_PI in Q13*/ ), 2 ) ); /*Q15 */
    FOR( i = 0; i < len1; i++ )
    {
#ifdef OPTIMIZE_FFT_STACK
        re = Msub_32_16( complex_buf[i].re, complex_buf[i].im, tmp ); /*Qq+1*/
        im = Madd_32_16( complex_buf[i].im, complex_buf[i].re, tmp ); /*Qq+1*/
#else
        re = Msub_32_16( complex_buf[2 * i], complex_buf[( ( i * 2 ) + 1 )], tmp ); /*Qq+1*/
        im = Madd_32_16( complex_buf[( ( i * 2 ) + 1 )], complex_buf[2 * i], tmp ); /*Qq+1*/
#endif
        y[2 * i] = L_add( Mult_32_16( re, edct_table[i] ), Mult_32_16( im, edct_table[( len1 - ( 1 + i ) )] ) ); /*Qq+2*/
        move32();
        y[( length - ( 1 + ( i * 2 ) ) )] = L_sub( Mult_32_16( im, edct_table[i] ), Mult_32_16( re, edct_table[( len1 - ( 1 + i ) )] ) ); /*Qq+2*/
@@ -380,6 +470,8 @@ void edst_fx(

    return;
}


/*========================================================================*/
/* FUNCTION : edct_fx()                                                   */
/*------------------------------------------------------------------------*/
@@ -404,26 +496,35 @@ void edct_16fx(
    const Word16 *x, /* i  : input signal        Qx  */
    Word16 *y,       /* o  : output transform    Qx  */
    Word16 length,   /* i  : length  */
    Word16 bh,       /* bit-headroom */
    Word16 bh        /* bit-headroom */
#ifndef HARMONIZE_DCT
    ,
    const Word16 element_mode

#endif
)
{
    Word16 i;
    Word16 re[L_FRAME48k / 2];
    Word16 im[L_FRAME48k / 2];
    const Word16 *edct_table = NULL;
#ifndef OPTIMIZE_FFT_STACK
    Word16 re2[L_FRAME48k / 2];
    Word16 im2[L_FRAME48k / 2];

#endif
    Word32 L_tmp, Lacc, Lmax;
#ifdef OPTIMIZE_FFT_STACK
    Word16 tmp, tmp_re, fact;
#else
    Word16 tmp, fact;
#endif
    Word16 Q_edct;
    Word16 Len2, i2;
    const Word16 *px, *pt;
    Word16 *py;
#ifndef HARMONIZE_DCT
    (void) element_mode;
    /*COMPLETE: some eDCT sub function are missing */
#endif

    IF( EQ_16( length, L_FRAME32k ) )
    {
@@ -479,26 +580,46 @@ void edct_16fx(

        L_tmp = L_mult( x[i2], edct_table[i] ); /*Q(Qx+16) */
        Lacc = L_mac_sat( L_tmp, *px, *pt );    /*Q(Qx+16) */
#ifdef OPTIMIZE_FFT_STACK
        re[i] = round_fx_sat( L_shl_sat( Lacc, Q_edct ) ); /* Q(Qx+Q_edct) */
#else
        re2[i] = round_fx_sat( L_shl_sat( Lacc, Q_edct ) ); /* Q(Qx+Q_edct) */
#endif
        move16();
        L_tmp = L_mult( *px, edct_table[i] );  /*Q(Qx+16) */
        Lacc = L_msu_sat( L_tmp, x[i2], *pt ); /*Q(Qx+16) */
#ifdef OPTIMIZE_FFT_STACK
        im[i] = round_fx_sat( L_shl_sat( Lacc, Q_edct ) ); /* Q(Qx+Q_edct) */
#else
        im2[i] = round_fx_sat( L_shl_sat( Lacc, Q_edct ) ); /* Q(Qx+Q_edct) */
#endif
        move16();
        px -= 2;
        pt--;
    }
    IF( EQ_16( length, L_FRAME32k ) )
    {
#ifdef OPTIMIZE_FFT_STACK
        DoRTFT320_16fx( re, im );
#else
        DoRTFT320_16fx( re2, im2 );
#endif
    }
    ELSE IF( EQ_16( length, L_FRAME ) )
    {
#ifdef OPTIMIZE_FFT_STACK
        DoRTFT128_16fx( re, im );
#else
        DoRTFT128_16fx( re2, im2 );
#endif
    }
    ELSE IF( EQ_16( length, L_FRAME16k ) )
    {
#ifdef OPTIMIZE_FFT_STACK
        DoRTFT160_16fx( re, im );
#else
        DoRTFT160_16fx( re2, im2 );
#endif
    }
    ELSE
    {
@@ -508,6 +629,18 @@ void edct_16fx(
    fact = round_fx( L_shl( L_tmp, 2 ) ); /*Q15 */
    FOR( i = 0; i < shr( length, 1 ); i++ )
    {
#ifdef OPTIMIZE_FFT_STACK
        tmp = mult_r( im[i], fact );    /*Q(Qx+Q_edct) */
        tmp_re = sub_sat( re[i], tmp ); /*Q(Qx+Q_edct) */
        move16();

        tmp = mult_r( re[i], fact );   /*Q(Qx+Q_edct) */
        im[i] = add_sat( im[i], tmp ); /*Q(Qx+Q_edct) */
        move16();

        re[i] = tmp_re;
        move16();
#else
        tmp = mult_r( im2[i], fact );   /*Q(Qx+Q_edct) */
        re[i] = sub_sat( re2[i], tmp ); /*Q(Qx+Q_edct) */
        move16();
@@ -515,6 +648,7 @@ void edct_16fx(
        tmp = mult_r( re2[i], fact );   /*Q(Qx+Q_edct) */
        im[i] = add_sat( im2[i], tmp ); /*Q(Qx+Q_edct) */
        move16();
#endif
    }

    /* Post-rotate and obtain the output data */
@@ -567,7 +701,11 @@ void iedct_short_fx(
    seg_len_div4 = shr( segment_length, 2 ); /*Q0*/
    seg_len_3mul_div4 = add( seg_len_div2, seg_len_div4 );

#ifdef HARMONIZE_DCT
    edct_fx( in, alias, seg_len_div2, Q, EVS_MONO );
#else
    edct_fx( in, alias, seg_len_div2, Q );
#endif
    FOR( i = 0; i < seg_len_div2; i++ )
    {
        IF( alias[i] != 0 )
+12 −1
Original line number Diff line number Diff line
@@ -109,11 +109,13 @@ 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 );

#ifndef HARMONIZE_DCT
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       */
);
#endif
/*-----------------------------------------------------------------*
 * fft15_shift2()
 * 15-point FFT with 2-point circular shift
@@ -2630,6 +2632,7 @@ static void dctsub(
    return;
}

#ifndef HARMONIZE_DCT
/*-----------------------------------------------------------------*
 * edct2_fx_ivas()
 *
@@ -2790,7 +2793,7 @@ void DoRTFTn_fx_ivas(

    return;
}

#endif
#ifndef HQ_ALIGN_DUPLICATED_CODE
void fft3_fx_ivas(
    const Word32 X[], // Qx
@@ -4274,7 +4277,11 @@ void DoFFT_fx(
            DoRTFT320_fx( re2, im2 );
            BREAK;
        case 256:
#ifdef HARMONIZE_DCT
            DoRTFTn_fx( re2, im2, NULL, 256 );
#else
            DoRTFTn_fx_ivas( re2, im2, 256 );
#endif
            BREAK;
        case 240:
            DoRTFT240( re2, im2 );
@@ -4298,7 +4305,11 @@ void DoFFT_fx(
            DoRTFT80_fx( re2, im2 );
            BREAK;
        case 64:
#ifdef HARMONIZE_DCT
            DoRTFTn_fx( re2, im2, NULL, 64 );
#else
            DoRTFTn_fx_ivas( re2, im2, 64 );
#endif
            BREAK;
        case 40:
            DoRTFT40_fx( re2, im2 );
+12 −0
Original line number Diff line number Diff line
@@ -89,7 +89,11 @@ void Inac_switch_ematch_fx(
    ELSE IF( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || ( last_core != ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) || ( ( element_mode > EVS_MONO ) && EQ_16( coder_type, UNVOICED ) ) )
    {
        /* Find spectrum and energy per band for GC and VC frames */
#ifdef HARMONIZE_DCT
        edct_16fx( exc2, dct_exc_tmp, L_frame, 5 );
#else
        edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode );
#endif

        Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );

@@ -103,7 +107,11 @@ void Inac_switch_ematch_fx(
    ELSE IF( ( coder_type == INACTIVE ) && inactive_coder_type_flag )
    {
        /* Find spectrum and energy per band for inactive frames */
#ifdef HARMONIZE_DCT
        edct_16fx( exc2, dct_exc_tmp, L_frame, 5 );
#else
        edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode );
#endif

        Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );

@@ -188,7 +196,11 @@ void Inac_switch_ematch_fx(
            Scale_sig( dct_exc_tmp, 240, 1 ); // Q_exc
            Scale_sig( exc2, 240, 1 );        // Q_exc
        }
#ifdef HARMONIZE_DCT
        edct_16fx( dct_exc_tmp, exc2, L_frame, 5 );
#else
        edct_16fx( dct_exc_tmp, exc2, L_frame, 5, element_mode );
#endif
    }

    return;
Loading