Commit 0d31e99b authored by Jan Kiene's avatar Jan Kiene
Browse files

Merge branch 'main' into ci/encoder-stats-test-ltv

parents c272f7d6 31b60873
Loading
Loading
Loading
Loading
Loading
+118 −78
Original line number Diff line number Diff line
@@ -1318,33 +1318,6 @@ UWord16 get_indice_st(
}
#define WMC_TOOL_SKIP

/*-------------------------------------------------------------------*
 * reset_indices_enc()
 *
 * Reset the buffer of encoder indices
 *-------------------------------------------------------------------*/

void reset_indices_enc(
    BSTR_ENC_HANDLE hBstr,       /* i/o: encoder bitstream handle    */
    const Word16 max_num_indices /* i  : max number of indices       */
)
{
    Word16 i;

    hBstr->nb_bits_tot = 0;
    move16();
    hBstr->nb_ind_tot = 0;
    move16();

    FOR( i = 0; i < max_num_indices; i++ )
    {
        hBstr->ind_list[i].nb_bits = -1;
        move16();
    }

    return;
}

/*-------------------------------------------------------------------*
 * reset_indices_dec()
 *
@@ -1533,21 +1506,21 @@ static ivas_error write_indices_element_fx(
    {
        IF( st_ivas->hSCE[element_id]->hMetaData != NULL )
        {
            reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot );
            reset_indices_enc_fx( st_ivas->hSCE[element_id]->hMetaData, st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot );
        }

        reset_indices_enc( sts[0]->hBstr, sts[0]->hBstr->nb_ind_tot );
        reset_indices_enc_fx( sts[0]->hBstr, sts[0]->hBstr->nb_ind_tot );
    }
    ELSE
    {
        IF( st_ivas->hCPE[element_id]->hMetaData != NULL )
        {
            reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot );
            reset_indices_enc_fx( st_ivas->hCPE[element_id]->hMetaData, st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot );
        }

        FOR( n = 0; n < n_channels; n++ )
        {
            reset_indices_enc( sts[n]->hBstr, sts[n]->hBstr->nb_ind_tot );
            reset_indices_enc_fx( sts[n]->hBstr, sts[n]->hBstr->nb_ind_tot );
        }
    }

@@ -2059,67 +2032,84 @@ void ivas_set_bitstream_pointers(
 *-------------------------------------------------------------------*/

/*! r: 1 = reading OK, 0 = problem */
ivas_error read_indices(
ivas_error read_indices_fx(
    Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure         */
    uint16_t bit_stream[],   /* i  : bitstream buffer               */
    UWord16 bit_stream[],    /* i  : bitstream buffer               */
    UWord16 num_bits,        /* i  : number of bits in bitstream    */
    int16_t *prev_ft_speech,
    int16_t *CNG,
    int16_t bfi /* i  : bad frame indicator            */
    Word16 *prev_ft_speech,
    Word16 *CNG,
    Word16 bfi /* i  : bad frame indicator            */
)
{
    int16_t k;
    Word16 k;
    Decoder_State **sts;
    int32_t total_brate = 0;
    int16_t curr_ft_good_sp, curr_ft_bad_sp;
    int16_t g192_sid_first, sid_upd_bad, sid_update;
    int16_t speech_bad, speech_lost;
    int16_t n;
    Word32 total_brate = 0;
    move32();
    Word16 curr_ft_good_sp, curr_ft_bad_sp;
    Word16 g192_sid_first, sid_upd_bad, sid_update;
    Word16 speech_bad, speech_lost;
    Word16 n;
    ivas_error error;

    error = IVAS_ERR_OK;
    move32();

    st_ivas->BER_detect = 0;
    move16();
    st_ivas->num_bits = num_bits;
    move16();
    sts = reset_elements( st_ivas );

    st_ivas->bfi = bfi;
    move16();

    /* convert the frame length to total bitrate */
    total_brate = (int32_t) ( num_bits * FRAMES_PER_SEC );
    total_brate = imult3216( num_bits, FRAMES_PER_SEC );
    move32();

    /*  verify that a  valid  num bits value  is present in the G.192 file */
    /*  only AMRWB, EVS or IVAS bitrates or 0(NO DATA) are  allowed  in G.192 file frame reading  */
    if ( st_ivas->ivas_format != MONO_FORMAT )
    IF( NE_32( st_ivas->ivas_format, MONO_FORMAT ) )
    {
        k = 0;
        while ( k < SIZE_IVAS_BRATE_TBL && total_brate != ivas_brate_tbl[k] )
        move16();

        test();
        WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( total_brate, ivas_brate_tbl[k] ) )
        {
            k++;
            k = add( k, 1 );
        }

        if ( st_ivas->ivas_format == ISM_FORMAT && ( k < SIZE_IVAS_BRATE_TBL || total_brate <= SID_2k40 ) )
        test();
        test();
        test();
        test();
        IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) && ( LT_16( k, SIZE_IVAS_BRATE_TBL ) || LE_32( total_brate, SID_2k40 ) ) )
        {
            st_ivas->element_mode_init = IVAS_SCE;
            move16();
        }
        else if ( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) && ( total_brate <= SID_2k40 ) )
        ELSE IF( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) && LE_32( total_brate, SID_2k40 ) )
        {
            st_ivas->element_mode_init = IVAS_SCE;
            move16();
        }
        else if ( k == SIZE_IVAS_BRATE_TBL )
        ELSE IF( EQ_16( k, SIZE_IVAS_BRATE_TBL ) )
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error, illegal bitrate (%d) in the  G.192 frame ! Exiting ! \n", total_brate );
        }
        else
        ELSE
        {
            st_ivas->element_mode_init = -1;
            move16();
        }
    }
    else /* AMRWB or EVS */
    ELSE /* AMRWB or EVS */
    {
        st_ivas->element_mode_init = EVS_MONO;
        move16();

        if ( rate2EVSmode_float( total_brate, NULL ) < 0 ) /* negative value means that a valid rate was not found */
        IF( rate2EVSmode_float( total_brate, NULL ) < 0 ) /* negative value means that a valid rate was not found */
        {
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error, illegal bitrate (%d) in  the  G.192 frame ! Exiting ! \n", total_brate );
        }
@@ -2129,47 +2119,58 @@ ivas_error read_indices(
    /* handle SID_FIRST, SID_BAD, SPEECH_LOST,  NO_DATA as properly  as possible for the ITU-T  G.192 format  */
    /* (total_brate, bfi , st_CNG)   =  rx_handler(received frame type, [previous frame type],  past CNG state, past core) */
    curr_ft_good_sp = 0;
    move16();
    curr_ft_bad_sp = 0;
    move16();

    if ( is_DTXrate( total_brate ) == 0 )
    IF( is_DTXrate( total_brate ) == 0 )
    {
        if ( st_ivas->bfi == 0 )
        IF( st_ivas->bfi == 0 )
        {
            curr_ft_good_sp = 1;
            move16();
        }
        else
        ELSE
        {
            curr_ft_bad_sp = 1;
            move16();
        }
    }

    sid_update = 0;
    move16();
    sid_upd_bad = 0;
    if ( is_SIDrate( total_brate ) == 1 )
    move16();
    IF( EQ_16( is_SIDrate( total_brate ), 1 ) )
    {
        if ( st_ivas->bfi == 0 )
        IF( st_ivas->bfi == 0 )
        {
            sid_update = 1;
            move16();
        }
        else
        ELSE
        {
            sid_upd_bad = 1; /* this frame type may happen in ETSI/3GPP CS cases, a corrupt SID frames  */
            move16();
        }
    }

    /* all zero indices/bits iSP AMRWB SID_update results in a valid LP filter with extremely high LP-filter-gain  */
    /* all zero indices/bits  may be a result of CS bit errors  and/or  erroneously injected by gateways or by a bad dejitter handlers */
    if ( total_brate == SID_1k75 && sid_update == 1 )
    test();
    IF( EQ_32( total_brate, SID_1k75 ) && EQ_16( sid_update, 1 ) )
    {
        /* valid sid_update received, check for very risky but formally valid content  */
        int16_t sum = 0;
        for ( k = 0; k < num_bits; ++k )
        Word16 sum = 0;
        move16();
        FOR( k = 0; k < num_bits; ++k )
        {
            sum += ( bit_stream[k] == 1 ); /*   check of 35 zeroes   */
            sum = add( sum, extract_l( EQ_32( bit_stream[k], 1 ) ) ); /*   check of 35 zeroes   */
        }
        if ( sum == 0 )
        {                    /* all zeros  */
            sid_upd_bad = 1; /* initial signal as corrupt (BER likely)  */
            move16();
        }
    }

@@ -2180,14 +2181,22 @@ ivas_error read_indices(

                      Here we inhibit use of the SID-length info, even though it is available in the G.192 file format after STL/EID-XOR .
                   */
    if ( sid_upd_bad )
    IF( sid_upd_bad )
    {
        sid_upd_bad = 0;
        move16();
        total_brate = FRAME_NO_DATA; /* treat SID_BAD  as a  stolen signaling frame --> SPEECH LOST */
        move32();
    }

    g192_sid_first = 0;
    if ( st_ivas->ivas_format == MONO_FORMAT && sts[0]->core == AMR_WB_CORE && *prev_ft_speech && total_brate == FRAME_NO_DATA && st_ivas->bfi == 0 )
    move16();

    test();
    test();
    test();
    test();
    if ( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) && EQ_16( sts[0]->core, AMR_WB_CORE ) && *prev_ft_speech && total_brate == FRAME_NO_DATA && st_ivas->bfi == 0 )
    {
        g192_sid_first = 1; /*  SID_FIRST detected for previous AMRWB/AMRWBIO  active frames only  */
                            /* It is not possible to perfectly simulate rate switching conditions EVS->AMRWBIO  where:
@@ -2195,104 +2204,135 @@ ivas_error read_indices(
                                           and  a  good length 0  "SID_FIRST"(NO_DATA)   frame is sent in AMRWBIO,
                                           due to the one frame state memory in the AMRWB legacy  G.192 SID_FIRST encoding
                                         */
        move16();
    }

    speech_bad = 0;
    move16();

    test();
    if ( st_ivas->bfi != 0 && ( is_DTXrate( total_brate ) == 0 ) )
    {
        speech_bad = 1; /* initial ft assumption, CNG_state decides what to do */
        move16();
    }

    speech_lost = 0;
    move16();

    test();
    if ( total_brate == FRAME_NO_DATA && st_ivas->bfi != 0 ) /*  unsent  NO_DATA or stolen NO_DATA/signaling  frame  */
    {
        speech_lost = 1; /* initial ft assumption, CNG_state decides what to do */
        move16();
    }

    /* Do not allow decoder to enter CNG-synthesis for  any instantly  received  GOOD+LENGTH==0  frame
                   as this frame was never transmitted, one  can not know it is good and has a a length of zero ) */
    if ( *CNG != 0 )
    IF( *CNG != 0 )
    {
        /* We were in CNG synthesis  */
        if ( curr_ft_good_sp != 0 )
        {
            /* only a good speech frame makes you leave CNG synthesis */
            *CNG = 0;
            move16();
        }
    }
    else
    ELSE
    {
        /* We were in SPEECH synthesis  */
        /* only a received/detected SID frame can make the decoder enter into CNG synthsis  */
        test();
        test();
        if ( g192_sid_first || sid_update || sid_upd_bad )
        {
            *CNG = 1;
            move16();
        }
    }

    /* set bfi, total_brate pair  for proper decoding  */
    /*  handle the  G.192   _simulated_ untransmitted NO_DATA frame,  setting  for decoder  SPEECH synthesis  */
    test();
    test();
    if ( *CNG == 0 && total_brate == FRAME_NO_DATA && st_ivas->bfi == 0 )
    {
        st_ivas->bfi = 1; /*  SPEECH PLC code will now become active as in a real system */
                          /* total_brate= 0  */
        move16();
    }

    /* handle bad/lost speech frame(and CS bad SID frame) in the decoders CNG synthesis settings pair (total_brate, bfi) */
    if ( (
             bfi != FRAMEMODE_FUTURE &&
    test();
    test();
    test();
    test();
    IF( (
            NE_16( bfi, FRAMEMODE_FUTURE ) &&
            ( *CNG != 0 ) && ( ( speech_bad != 0 ) || ( speech_lost != 0 ) ) ) || /* SP_BAD or SPEECH_LOST)   --> stay in CNG */
        ( sid_upd_bad != 0 ) )                                                    /* SID_UPD_BAD              --> start CNG */
    {
        st_ivas->bfi = 0; /* bfi=0 needed to activate CNG code */
        move16();
        total_brate = FRAME_NO_DATA;
        move32();
    }

    /* update for next frame's G.192 file format's  odd SID_FIRST detection (primarily for AMRWBIO)  */
    test();
    *prev_ft_speech = ( ( curr_ft_good_sp != 0 ) || ( curr_ft_bad_sp != 0 ) );
    move16();

    /*   st->total brate= total_brate;   updated in a good frame below */

    for ( k = 0; k < st_ivas->nCPE; k++ )
    FOR( k = 0; k < st_ivas->nCPE; k++ )
    {
        sts = st_ivas->hCPE[k]->hCoreCoder;
        for ( n = 0; n < CPE_CHANNELS; n++ )
        FOR( n = 0; n < CPE_CHANNELS; n++ )
        {
            sts[n]->bfi = st_ivas->bfi;
            move16();
        }
    }

    for ( k = 0; k < st_ivas->nSCE; k++ )
    FOR( k = 0; k < st_ivas->nSCE; k++ )
    {
        sts = st_ivas->hSCE[k]->hCoreCoder;
        sts[0]->bfi = st_ivas->bfi;
        move16();
    }

    if ( st_ivas->bfi == 0 )
    IF( st_ivas->bfi == 0 )
    {
        /* select Mode 1 or Mode 2 */
        if ( st_ivas->ivas_format == MONO_FORMAT ) /* EVS mono */
        IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) /* EVS mono */
        {
            decoder_selectCodec( sts[0], total_brate, bit_stream[0] );
            st_ivas->hDecoderConfig->Opt_AMR_WB = sts[0]->Opt_AMR_WB;
            move16();
        }
        else /* IVAS */
        ELSE /* IVAS */
        {
            st_ivas->codec_mode = MODE1;
            move16();
            st_ivas->hDecoderConfig->Opt_AMR_WB = 0;
            move16();
        }
    }

    /* GOOD frame */
    if ( st_ivas->bfi == 0 || st_ivas->bfi == FRAMEMODE_FUTURE )
    test();
    if ( st_ivas->bfi == 0 || EQ_16( st_ivas->bfi, FRAMEMODE_FUTURE ) )
    {
        /* GOOD frame - convert ITU-T G.192 words to short values */
        st_ivas->hDecoderConfig->ivas_total_brate = total_brate;
        move32();
    }

    st_ivas->bit_stream = bit_stream;

    if ( st_ivas->ivas_format == MONO_FORMAT )
    IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) )
    {
        ivas_set_bitstream_pointers( st_ivas );
    }
+3 −354

File changed.

Preview size limit exceeded, changes collapsed.

+7 −17
Original line number Diff line number Diff line
@@ -1323,7 +1323,8 @@ UWord16 get_indice_1_fx( /* o : value of the indice */
);
void reset_indices_enc_fx(
    BSTR_ENC_HANDLE hBstr /* i/o: encoder state structure */
    BSTR_ENC_HANDLE hBstr,       /* i/o: encoder state structure */
    const Word16 max_num_indices /* i  : max number of indices       */
);
void reset_indices_dec_fx(
@@ -1367,12 +1368,6 @@ Word16 BRATE2IDX16k_fx( Word32 brate );
Word32 BIT_ALLOC_IDX_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc );
Word32 BIT_ALLOC_IDX_16KHZ_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc );
Word16 read_indices_fx(                       /* o  : 1 = OK, 0 = something wrong            */
                        Decoder_State *st_fx, /* i/o: decoder state structure */
                        FILE *file,           /* i  : bitstream file                         */
                        Word16 rew_flag       /* i  : rewind flag (rewind file after reading) */
);
Word16 read_indices_mime(                    /* o  : 1 = reading OK, 0 = problem            */
                          Decoder_State *st, /* i/o: decoder state structure                */
                          FILE *file,        /* i  : bitstream file                         */
@@ -11544,11 +11539,6 @@ uint16_t get_indice(
    int16_t nb_bits    /* i  : number of bits that were used to quantize the indice */
);
void reset_indices_enc(
    BSTR_ENC_HANDLE hBstr,        /* i/o: encoder bitstream handle               */
    const int16_t max_num_indices /* i  : max number of indices                  */
);
void reset_indices_dec(
    Decoder_State *st /* i/o: decoder state structure                */
);
@@ -11560,13 +11550,13 @@ Word16 rate2EVSmode_float(
/*! r: 1 = OK, 0 = something wrong */
ivas_error read_indices(
ivas_error read_indices_fx(
    Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure                 */
    uint16_t bit_stream[],   /* i  : bitstream buffer                       */
    UWord16 bit_stream[],    /* i  : bitstream buffer                       */
    UWord16 num_bits,        /* i  : number of bits in bitstream            */
    int16_t *prev_ft_speech,
    int16_t *CNG,
    int16_t bfi /* i  : bad frame indicator                    */
    Word16 *prev_ft_speech,
    Word16 *CNG,
    Word16 bfi /* i  : bad frame indicator                    */
);
+1 −1
Original line number Diff line number Diff line
@@ -923,7 +923,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
        }
    }

    IF( NE_32( ( error = read_indices( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ) ), IVAS_ERR_OK ) )
    IF( NE_32( ( error = read_indices_fx( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ) ), IVAS_ERR_OK ) )
    {
        return error;
    }
+0 −13
Original line number Diff line number Diff line
@@ -160,18 +160,6 @@ void acelp_core_switch_enc_fx(
    /*----------------------------------------------------------------*
     * bit-stream: modify the layer of sub frame CELP
     *----------------------------------------------------------------*/
#ifdef IVAS_CODE_BITSTREAM
    i = find_indice( hBstr, TAG_ACELP_SUBFR_LOOP_START, &value, &nb_bits );
#ifdef DEBUGGING
    assert( i >= 0 && "Internal error in ACELP core switching - unable to find ACELP subframe indices!" );
#endif
    while ( hBstr->ind_list[i].id == TAG_ACELP_SUBFR_LOOP_START )
    {
        push_indice( hBstr, IND_CORE_SWITCHING_CELP_SUBFRAME, hBstr->ind_list[i].value, hBstr->ind_list[i].nb_bits );
        i++;
    }
    delete_indice( hBstr, TAG_ACELP_SUBFR_LOOP_START );
#else
    FOR( i = 0; i < 20; i++ )
    {
        hBstr->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME + i].value = hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].value; /* Q0 */
@@ -181,7 +169,6 @@ void acelp_core_switch_enc_fx(
        hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits = -1; /* Q0 */
        move16();
    }
#endif
    /*----------------------------------------------------------------*
     * BWE encoding
     *----------------------------------------------------------------*/
Loading