Commit 8a17c01d authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'stereo_encoder_fxd_changes' into 'main'

Stereo path encoder functions converted to fixed

See merge request !467
parents ce6f3b7c 761d4bae
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -3329,7 +3329,32 @@ void dequantize_sns(
    float snsQ_out[CPE_CHANNELS][NB_DIV][M],
    Decoder_State **sts
);
#ifdef IVAS_FLOAT_FIXED
void sns_avq_cod_fx(
    const Word32 *sns_fx, /* i  : Input sns vectors               */
    Word16 exp_sns,
    const Word32 *snsmid_fx, /* i  : Input mid-sns vectors           */
    Word16 exp_snsmid,
    Word32 *sns_q_fx,    /* o  : Quantized LFS vectors           Q16 */
    Word32 *snsmid_q_fx, /* o  : Quantized mid-LFS vectors       Q16 */
    Word16 *index,       /* o  : Quantization indices            */
    const Word16 core,   /* i  : core                            */
    const Word16 L_frame,
    const Word16 low_brate_mode /* i  : flag low bit operating mode     */
);

void sns_avq_cod_stereo_fx(
    const Word32 *snsl_fx, /* i  : Input sns vector (left channel)         */
    Word16 exp_snl,
    const Word32 *snsr_fx, /* i  : Input sns vector (right channel)        */
    Word16 exp_snr,
    const Word16 L_frame,
    Word32 *snsl_q_fx,   /* o  : Quantized sns vector (left channel)     Q16 */
    Word32 *snsr_q_fx,   /* o  : Quantized sns vector (right channel)    Q16 */
    Word16 *indexl, /* o  : Quantization indices (left channel)     */
    Word16 *indexr  /* o  : Quantization indices (right channel)    */
);
#else
void sns_avq_cod(
    const float *sns,                                           /* i  : Input sns vectors                       */
    const float *snsmid,                                        /* i  : Input mid-sns vectors                   */
@@ -3340,7 +3365,6 @@ void sns_avq_cod(
    const int16_t L_frame,
    const int16_t low_brate_mode                                /* i  : flag low bit operating mode             */
);

void sns_avq_cod_stereo(
    const float *snsl,                                          /* i  : Input sns vector (left channel)         */
    const float *snsr,                                          /* i  : Input sns vector (right channel)        */
@@ -3350,6 +3374,7 @@ void sns_avq_cod_stereo(
    int16_t *indexl,                                            /* o  : Quantization indices (left channel)     */
    int16_t *indexr                                             /* o  : Quantization indices (right channel)    */
);
#endif

void sns_avq_dec(
    int16_t *index,                                             /* i  : Quantization indices                    */
+9 −0
Original line number Diff line number Diff line
@@ -1288,6 +1288,7 @@ const Word16 pow_10_icbwe_gsMappingDFT_tbl_fx[128] = {
 * TD Stereo ROM tables
 *----------------------------------------------------------------------------------*/

// Q31
const UWord32 tdm_ratio_tabl_fx[TDM_NQ + 1] = {
    0, 0, 23407572, 52613348, 92771296,
    143881408, 205084688, 275736896, 355193792, 442596384, 536870912,
@@ -1297,6 +1298,14 @@ const UWord32 tdm_ratio_tabl_fx[TDM_NQ + 1] = {
    2147483647, 2147483647, 2147483647
};

// Q24
const Word32 tdm_ratio_tabl_fx_Q24[TDM_NQ + 1] = {
    0, 0, 182871, 411041, 724775, 1124073, 1602224, 2154194,
    2774951, 3457784, 4194304, 4976122, 5796528, 6643777, 7511159, 8388608,
    9266056, 10133438, 10980688, 11801094, 12582912, 13319432, 14002264, 14623021,
    15174992, 15653143, 16052440, 16366174, 16594344, 16777216, 16777216, 16777216
};

const UWord32 tdm_den_ratio_tabl_fx[TDM_NQ + 1] = {
    1073741824, 1073741824, 1097471488, 1127536256, 1170593280,
    1227179520, 1297939072, 1383409024, 1483374336, 1596009856, 1717986944,
+1 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ extern const Word16 pow_10_icbwe_gsMappingDFT_tbl_fx[];
 *----------------------------------------------------------------------------------*/

extern const UWord32 tdm_ratio_tabl_fx[TDM_NQ + 1];
extern const Word32 tdm_ratio_tabl_fx_Q24[TDM_NQ + 1];
extern const UWord32 tdm_den_ratio_tabl_fx[];

/* LSFs Intra-frame prediction tables */
+178 −0
Original line number Diff line number Diff line
@@ -49,6 +49,159 @@
 * write TCX mode
 *--------------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
void writeTCXMode(
    Encoder_State *st,     /* i/o: encoder state structure              */
    BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle                     */
    const Word16 MCT_flag, /* i  : hMCT handle allocated (1) or not (0) */
    Word16 *nbits_start    /* o  : nbits start                          */
)
{
    UWord16 index;
    Word16 idx, start_idx;
    Word16 nBits;

    IF( st->tcxonly )
    {
        push_next_indice( hBstr, (UWord16) EQ_16( st->core, TCX_10_CORE ), 1 );

        test();
        IF( EQ_16( st->clas, UNVOICED_CLAS ) )
        {
            index = 0;
            move16();
        }
        ELSE IF( EQ_16( st->clas, VOICED_TRANSITION ) || EQ_16( st->clas, UNVOICED_TRANSITION ) )
        {
            index = 1;
            move16();
        }
        ELSE IF( EQ_16( st->clas, VOICED_CLAS ) )
        {
            index = 2;
            move16();
        }
        ELSE
        {
            index = 3;
            move16();
        }

        push_next_indice( hBstr, index, 2 );

        test();
        IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag )
        {
            push_next_indice( hBstr, st->vad_flag, 1 );
        }
    }
    ELSE
    {
        IF( EQ_16( st->core, ACELP_CORE ) )
        {
            /* write the RF signaling information */
            IF( EQ_16( st->rf_mode, 1 ) )
            {
                /* find the section in the ACELP signaling table corresponding to bitrate */
                idx = 0;
                move16();
                WHILE( NE_32( acelp_sig_tbl[idx], st->total_brate ) ) /* total bitrate is kept at 13.2kbps */
                {
                    idx = add( idx, 1 );
                }

                /* retrieve the number of bits for signaling */
                idx = add( idx, 1 );
                nBits = extract_l( acelp_sig_tbl[idx] );

                /* retrieve the signaling index */
                idx = add( idx, 1 );
                start_idx = idx;
                move16();
                WHILE( NE_32( acelp_sig_tbl[idx], SIG2IND( st->coder_type, st->bwidth, st->sharpFlag, st->rf_mode ) ) )
                {
                    idx = add( idx, 1 );
                }
                push_next_indice( hBstr, sub( idx, start_idx ), nBits );
                push_next_indice( hBstr, 0, 1 ); /* Indicate to the decoder that the core is ACELP*/
                *nbits_start = 3;
                move16();
            }
            ELSE
            {
                push_next_indice( hBstr, st->coder_type, 3 );
            }
        }
        ELSE
        {
            IF( EQ_16( st->mdct_sw, MODE1 ) )
            {
                /* 2 bits instead of 3 as TCX is already signaled */
                push_next_indice( hBstr, st->hTcxCfg->coder_type, 2 );
            }
            ELSE
            {
                IF( EQ_16( st->mdct_sw_enable, MODE2 ) )
                {
                    push_next_indice( hBstr, 1, 1 ); /* TCX */
                    push_next_indice( hBstr, 0, 1 ); /* not HQ_CORE */
                    push_next_indice( hBstr, st->hTcxCfg->coder_type, 2 );
                }
                ELSE
                {
                    /*write the RF signaling information*/
                    IF( EQ_16( st->rf_mode, 1 ) )
                    {
                        /* find the section in the ACELP signaling table corresponding to bitrate */
                        idx = 0;
                        move16();
                        WHILE( NE_32( acelp_sig_tbl[idx], st->total_brate ) )
                        {
                            idx = add( idx, 1 );
                        }

                        /* retrieve the number of bits for signaling */
                        idx = add( idx, 1 );
                        nBits = extract_l( acelp_sig_tbl[idx] );

                        test();
                        test();
                        IF( EQ_16( st->hTcxCfg->coder_type, VOICED ) || EQ_16( st->hTcxCfg->coder_type, GENERIC ) || EQ_16( st->hTcxCfg->coder_type, TRANSITION ) )
                        {
                            st->sharpFlag = 1;
                            move16();
                        }
                        ELSE
                        {
                            st->sharpFlag = 0;
                            move16();
                        }

                        /* retrieve the signaling index */
                        idx = add( idx, 1 );
                        start_idx = idx;
                        move16();
                        WHILE( NE_32( acelp_sig_tbl[idx], SIG2IND( st->hTcxCfg->coder_type, st->bwidth, st->sharpFlag, st->rf_mode ) ) )
                        {
                            idx = add( idx, 1 );
                        }
                        push_next_indice( hBstr, sub( idx, start_idx ), nBits );
                        push_next_indice( hBstr, 1, 1 ); /* Indicate to the decoder that the core is TCX*/
                        *nbits_start = 3;
                        move16();
                    }
                    ELSE
                    {
                        push_next_indice( hBstr, add( ACELP_MODE_MAX, st->hTcxCfg->coder_type ), 3 );
                    }
                }
            }
        }
    }

    return;
}
#else
void writeTCXMode(
    Encoder_State *st,      /* i/o: encoder state structure              */
    BSTR_ENC_HANDLE hBstr,  /* i/o: bitstream handle                     */
@@ -180,6 +333,7 @@ void writeTCXMode(

    return;
}
#endif


/*-------------------------------------------------------------------*
@@ -188,6 +342,29 @@ void writeTCXMode(
 * write TCX transform type
 *-------------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
void writeTCXWindowing(
    BSTR_ENC_HANDLE hBstr,    /* i/o: bitstream handle        */
    const Word16 overlap_mode /* i  : overlap mode            */
)
{

    IF( EQ_16( overlap_mode, MIN_OVERLAP ) )
    {
        push_next_indice( hBstr, 2, 2 );
    }
    ELSE IF( EQ_16( overlap_mode, HALF_OVERLAP ) )
    {
        push_next_indice( hBstr, 3, 2 );
    }
    ELSE
    {
        push_next_indice( hBstr, 0, 1 );
    }

    return;
}
#else
void writeTCXWindowing(
    BSTR_ENC_HANDLE hBstr,     /* i/o: bitstream handle        */
    const int16_t overlap_mode /* i  : overlap mode            */
@@ -209,6 +386,7 @@ void writeTCXWindowing(

    return;
}
#endif


/*-------------------------------------------------------------------*
+52 −1
Original line number Diff line number Diff line
@@ -41,6 +41,11 @@
#include "rom_com.h"
#include "ivas_rom_com.h"
#include "wmc_auto.h"
#ifdef IVAS_FLOAT_FIXED
#include "prot_fx_enc.h"
#include "prot_fx.h"
#endif


/*--------------------------------------------------------------*
 * Local constants
@@ -582,6 +587,10 @@ void ivas_mdct_core_whitening_enc(
    Encoder_State *st, **sts;
    float scf[CPE_CHANNELS][NB_DIV][M];
    float scf_q[CPE_CHANNELS][NB_DIV][M];
#ifdef IVAS_FLOAT_FIXED
    Word32 scf_fx[CPE_CHANNELS][NB_DIV][M];
    Word32 scf_q_fx[CPE_CHANNELS][NB_DIV][M];
#endif
    float chE[2], chE_tot;
    int8_t sns_low_br_mode;
    int16_t nbits_start_sns;
@@ -599,7 +608,11 @@ void ivas_mdct_core_whitening_enc(

    for ( ch = 0; ch < CPE_CHANNELS; ch++ )
    {
#ifdef IVAS_FLOAT_FIXED
        stereo_tcx_init_enc_fx( sts[ch] );
#else
        stereo_tcx_init_enc( sts[ch] );
#endif

        set_s( tnsSize[ch], 0, 2 );
        set_s( tnsBits[ch], 0, 2 );
@@ -898,7 +911,20 @@ void ivas_mdct_core_whitening_enc(
        if ( sts[0]->hTcxEnc->tcxMode == TCX_20 && sts[1]->hTcxEnc->tcxMode == TCX_20 &&
             sts[0]->mct_chan_mode == MCT_CHAN_MODE_REGULAR && sts[1]->mct_chan_mode == MCT_CHAN_MODE_REGULAR )
        {
#ifdef IVAS_FLOAT_FIXED
            /*=================flt-2-fix==============*/
            Word16 exp_snl = 0, exp_snr = 0;
            f2me_buf( scf[0][0], scf_fx[0][0], &exp_snl, M );
            f2me_buf( scf[1][0], scf_fx[1][0], &exp_snr, M );
            /*=================flt-2-fix==============*/
            sns_avq_cod_stereo_fx( scf_fx[0][0], exp_snl, scf_fx[1][0], exp_snr, sts[0]->L_frame, scf_q_fx[0][0], scf_q_fx[1][0], param_lpc[0], param_lpc[1] );
            /*===============fix-2-flt==========================*/
            fixedToFloat_arrL( scf_q_fx[0][0], scf_q[0][0], Q16, M );
            fixedToFloat_arrL( scf_q_fx[1][0], scf_q[1][0], Q16, M );
            /*===============fix-2-flt==========================*/
#else
            sns_avq_cod_stereo( scf[0][0], scf[1][0], sts[0]->L_frame, scf_q[0][0], scf_q[1][0], param_lpc[0], param_lpc[1] );
#endif
        }
        else
        {
@@ -910,7 +936,31 @@ void ivas_mdct_core_whitening_enc(
                    continue;
                }
                st = sts[ch];

#ifdef IVAS_FLOAT_FIXED
                Word16 exp_scf_1 = 0, exp_scf_0 = 0;
                IF( st->hTcxEnc->tcxMode == TCX_20 )
                {
                    /*===============flt-2-fix==========================*/
                    f2me_buf( scf[ch][0], scf_fx[ch][0], &exp_scf_0, M );
                    /*===============flt-2-fix==========================*/
                    sns_avq_cod_fx( scf_fx[ch][0], exp_scf_0, NULL, 0, scf_q_fx[ch][0], NULL, &param_lpc[ch][1], st->hTcxEnc->tcxMode, st->L_frame, sns_low_br_mode );
                    /*===============fix-2-flt==========================*/
                    fixedToFloat_arrL( scf_q_fx[ch][0], scf_q[ch][0], Q16, M );
                    /*===============fix-2-flt==========================*/
                }
                ELSE
                {
                    /*===============flt-2-fix==========================*/
                    f2me_buf( scf[ch][1], scf_fx[ch][1], &exp_scf_1, M );
                    f2me_buf( scf[ch][0], scf_fx[ch][0], &exp_scf_0, M );
                    /*===============flt-2-fix==========================*/
                    sns_avq_cod_fx( scf_fx[ch][1], exp_scf_1, scf_fx[ch][0], exp_scf_0, scf_q_fx[ch][1], scf_q_fx[ch][0], &param_lpc[ch][1], st->hTcxEnc->tcxMode, st->L_frame, sns_low_br_mode );
                    /*===============fix-2-flt==========================*/
                    fixedToFloat_arrL( scf_q_fx[ch][0], scf_q[ch][0], Q16, M );
                    fixedToFloat_arrL( scf_q_fx[ch][1], scf_q[ch][1], Q16, M );
                    /*===============fix-2-flt==========================*/
                }
#else
                if ( st->hTcxEnc->tcxMode == TCX_20 )
                {
                    sns_avq_cod( scf[ch][0], NULL, scf_q[ch][0], NULL, &param_lpc[ch][1], st->hTcxEnc->tcxMode, st->L_frame, sns_low_br_mode );
@@ -919,6 +969,7 @@ void ivas_mdct_core_whitening_enc(
                {
                    sns_avq_cod( scf[ch][1], scf[ch][0], scf_q[ch][1], scf_q[ch][0], &param_lpc[ch][1], st->hTcxEnc->tcxMode, st->L_frame, sns_low_br_mode );
                }
#endif
            }
        }
    }
Loading