Commit 68382e39 authored by Fabian Bauer's avatar Fabian Bauer
Browse files

cleanup tonal conceal init reharmonization and change GT_16 to NE_16 in ivas detection

parent 0acd088c
Loading
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -97,11 +97,6 @@
#define HARMONIZE_2598_tcx_arith_encode_envelope        /* FhG: harmonize tcx_arith_encode_envelope between EVS and IVAS versions */
#define FIX_ISSUE_2594_FALSE_COMMENT                    /* FhG: basop issue 2594: fixing false comments about Q value*/
#define HARMONIZE_2583_open_decoder_LPD             /* FhG: harmonize open_decoder_LPD between EVS and IVAS versions */
//#define HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit /*devlop: get EVS/IVAS init for tonal concealment back*/
//#define HARMONIZE_2583_open_decoder_LPD_TonalConceal_reharmonize_stage1 /*devlop: reharmonize tonalconcealmen-init*/
//#define HARMONIZE_2583_open_decoder_LPD_TonalConceal_reharmonize_stage2 /*devlop: reharmonize tonalconcealmen-init*/
//#define HARMONIZE_2583_open_decoder_LPD_TonalConceal_reharmonize_stage3 /*devlop: reharmonize tonalconcealmen-init*/
//#define HARMONIZE_2583_open_decoder_LPD_TonalConceal_reharmonize_stage4 /*devlop: reharmonize tonalconcealmen-init*/

/* #################### End BE switches ################################## */

+0 −13
Original line number Diff line number Diff line
@@ -5544,22 +5544,9 @@ void RefineTonalComponents_fx(
    const Word16 element_mode,
    const PsychoacousticParameters *psychParamsCurrent );

#ifdef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit
ivas_error TonalMDCTConceal_Init_fx(
    TonalMDCTConcealPtr self,
    const Word16 nSamples,
    const Word16 nSamplesCore,
    const Word16 nScaleFactors,
    TCX_CONFIG_HANDLE hTcxCfg /* TCX config */
);
#endif

#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit
ivas_error TonalMDCTConceal_Init_fx(
    Word16 element_mode,
#else
ivas_error TonalMDCTConceal_Init_ivas_fx(
#endif
    TonalMDCTConcealPtr hTonalMDCTConc,
    const UWord16 nSamples,
    const UWord16 nSamplesCore,
+0 −1
Original line number Diff line number Diff line
@@ -1898,7 +1898,6 @@ ivas_error acelp_core_dec_fx(
            IF( st->p_bpf_noise_buf_32 )
            {
                Copy_Scale_sig_16_32_DEPREC( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1
                assert( st->L_frame <= L_FRAME16k );
                Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame );
                Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11
            }
+0 −21
Original line number Diff line number Diff line
@@ -908,11 +908,7 @@ void open_decoder_LPD_fx(
        st->hTonalMDCTConc->lastBlockData.nSamples = 0;
        move16();

#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit
        TonalMDCTConceal_Init_fx( EVS_MONO, st->hTonalMDCTConc, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
#else
        TonalMDCTConceal_Init_fx( st->hTonalMDCTConc, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
#endif
    }
    st->last_tns_active = 0;
    move16();
@@ -2334,24 +2330,7 @@ void open_decoder_LPD_ivas_fx(
        move16();
        st->hTonalMDCTConc->lastBlockData.nSamples = 0;
        move16();
#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit
        TonalMDCTConceal_Init_fx( st->element_mode, st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
#else

#ifdef HARMONIZE_2583_open_decoder_LPD
        IF( EQ_16( st->element_mode, EVS_MONO ) )
        {
            TonalMDCTConceal_Init_fx( st->hTonalMDCTConc, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
        }
        ELSE
        {
#endif

            TonalMDCTConceal_Init_ivas_fx( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
#ifdef HARMONIZE_2583_open_decoder_LPD
        }
#endif
#endif /*#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit*/
    }

    st->last_tns_active = 0;
+52 −235
Original line number Diff line number Diff line
@@ -30,230 +30,57 @@ static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, Word
/*-------------- public functions -------------------- */
/*******************************************************/

#ifdef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit
ivas_error TonalMDCTConceal_Init_fx(
    TonalMDCTConcealPtr hTonalMDCTConc,
    const Word16 nSamples,
    const Word16 nSamplesCore,
    const Word16 nScaleFactors,
    TCX_CONFIG_HANDLE hTcxCfg /* TCX config */
)
{
    test();
    IF( GT_16( nSamples, L_FRAME_MAX ) || GT_16( nScaleFactors, FDNS_NPTS ) )
    {
        assert( nSamples <= L_FRAME_MAX );
        assert( nScaleFactors <= FDNS_NPTS );
        return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "TonalMDCT FEC: Number of samples larger than max. block size\n" ) );
    }
    assert( ( hTonalMDCTConc->nScaleFactors == nScaleFactors ) || ( hTonalMDCTConc->nSamples != nSamples ) ); /* If nSamples doesn't change then also nScaleFactors must stay the same */

    hTonalMDCTConc->tcx_cfg = hTcxCfg;

    hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0];
    move16();
    hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[1];
    move16();
    hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData;
    move16();

    hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0];
    move16();
    hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[1];
    move16();
    hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0];
    move16();
    hTonalMDCTConc->secondLastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[1];
    move16();

    hTonalMDCTConc->lastBlockData.blockIsValid = 0;
    move16();
    hTonalMDCTConc->secondLastBlockData.blockIsValid = 0;
    move16();
    hTonalMDCTConc->nSamples = 0;
    move16();
    hTonalMDCTConc->nScaleFactors = 0;
    move16();

    hTonalMDCTConc->lastBlockData.blockIsConcealed = 0;
    move16();
    hTonalMDCTConc->secondLastBlockData.blockIsConcealed = 0;
    move16();

    hTonalMDCTConc->pTCI = (TonalComponentsInfo *) hTonalMDCTConc->timeDataBuffer;
    move16();

    hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 );

    IF( NE_16( hTonalMDCTConc->nSamples, nSamples ) )
    {
        hTonalMDCTConc->secondLastBlockData.blockIsValid = 0;
        move16();
        hTonalMDCTConc->lastBlockData.blockIsValid = 0;
        move16();
    }

    hTonalMDCTConc->nSamples = nSamples;
    move16();
    hTonalMDCTConc->nSamplesCore = nSamplesCore;
    move16();

    hTonalMDCTConc->nScaleFactors = nScaleFactors;
    move16();
    /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when
       new time samples are stored in lastPcmOut */
    move16();
    move16();
    /* just the second half of the second last pcm output is needed */
    hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, 3 * ( s_min( L_FRAME_MAX, nSamples ) ) / 2 )];
    hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )];

    /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */
    assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) );

    return IVAS_ERR_OK;
}
#endif


#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit
ivas_error TonalMDCTConceal_Init_fx(
    Word16 element_mode,
#else
ivas_error TonalMDCTConceal_Init_ivas_fx(
#endif /*HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit*/
    TonalMDCTConcealPtr hTonalMDCTConc,
    const UWord16 nSamples,
    const UWord16 nSamplesCore,
    const UWord16 nScaleFactors,
    TCX_CONFIG_HANDLE hTcxCfg )
{

#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit
    IF( EQ_16( element_mode, EVS_MONO ) )
    {
        /*EVS*/

        /*Common Part 1*/
    test();
    IF( GT_16( nSamples, L_FRAME_MAX ) || GT_16( nScaleFactors, FDNS_NPTS ) )
    {
            assert( nSamples <= L_FRAME_MAX );
            assert( nScaleFactors <= FDNS_NPTS );
        assert( LE_16( nSamples, L_FRAME_MAX ) );
        assert( LE_16( nScaleFactors, FDNS_NPTS ) );
        return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "TonalMDCT FEC: Number of samples larger than max. block size\n" ) );
    }
        assert( ( hTonalMDCTConc->nScaleFactors == nScaleFactors ) || ( hTonalMDCTConc->nSamples != nSamples ) ); /* If nSamples doesn't change then also nScaleFactors must stay the same */
    assert( EQ_16( hTonalMDCTConc->nScaleFactors, nScaleFactors ) || NE_16( hTonalMDCTConc->nSamples, nSamples ) ); /* If nSamples doesn't change then also nScaleFactors must stay the same */

    hTonalMDCTConc->tcx_cfg = hTcxCfg;

    hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0];
    IF( NE_16( element_mode, EVS_MONO ) )
    {
        set16_fx( hTonalMDCTConc->lastBlockData.spectralData, 0, L_FRAME_MAX );
        move16();

        /*Start EVS-only*/
        hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[1];
        set16_fx( hTonalMDCTConc->secondLastBlockData.spectralData, 0, L_FRAME_MAX );
        move16();
        hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData;
        move16();

        hTonalMDCTConc->secondLastPowerSpectrum_exp = hTonalMDCTConc->secondLastBlockData.spectralData_exp;
        move16();
        hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0];
        set16_fx( hTonalMDCTConc->lastBlockData.scaleFactors, 0, FDNS_NPTS );
        move16();
        hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[1];
        set16_fx( hTonalMDCTConc->secondLastBlockData.scaleFactors, 0, FDNS_NPTS );
        move16();
        /*Stop EVS-only*/

        /*Common Part 2*/
        hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0];
        move16();
        hTonalMDCTConc->secondLastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[1];
        move16();

        hTonalMDCTConc->lastBlockData.blockIsValid = 0;
        move16();
        hTonalMDCTConc->secondLastBlockData.blockIsValid = 0;
        move16();
        hTonalMDCTConc->nSamples = 0;
        move16();
        hTonalMDCTConc->nScaleFactors = 0;
        move16();

        hTonalMDCTConc->lastBlockData.blockIsConcealed = 0;
        move16();
        hTonalMDCTConc->secondLastBlockData.blockIsConcealed = 0;
        move16();

        hTonalMDCTConc->pTCI = (TonalComponentsInfo *) hTonalMDCTConc->timeDataBuffer;
        move16();

        hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 );

        IF( NE_16( hTonalMDCTConc->nSamples, nSamples ) )
        {
            hTonalMDCTConc->secondLastBlockData.blockIsValid = 0;
            move16();
            hTonalMDCTConc->lastBlockData.blockIsValid = 0;
            move16();
        }

        hTonalMDCTConc->nSamples = nSamples;
        move16();
        hTonalMDCTConc->nSamplesCore = nSamplesCore;
        move16();

        hTonalMDCTConc->nScaleFactors = nScaleFactors;
        move16();

        /*Common Part 3*/
        /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when
           new time samples are stored in lastPcmOut */
        move16();
        move16();
        /* just the second half of the second last pcm output is needed */

        /*Common Part 4*/
        hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * ( s_min( L_FRAME_MAX, nSamples ) ) / 2 )];
        hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - s_min( L_FRAME_MAX, nSamples )];
        /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */
        assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) );
    }
#endif /*#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit*/

#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit
    IF( NE_16( element_mode, EVS_MONO ) )
    {
#endif /*#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit*/


        /*Common Part 1*/
        test();
        IF( GT_16( nSamples, L_FRAME_MAX ) || GT_16( nScaleFactors, FDNS_NPTS ) )
    ELSE
    {
            assert( LE_16( nSamples, L_FRAME_MAX ) );
            assert( LE_16( nScaleFactors, FDNS_NPTS ) );
            return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "TonalMDCT FEC: Number of samples larger than max. block size\n" ) );
        }
        assert( EQ_16( hTonalMDCTConc->nScaleFactors, nScaleFactors ) || NE_16( hTonalMDCTConc->nSamples, nSamples ) ); /* If nSamples doesn't change then also nScaleFactors must stay the same */

        hTonalMDCTConc->tcx_cfg = hTcxCfg;
        hTonalMDCTConc->lastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[0];
        /*Start IVAS-only*/
        set16_fx( hTonalMDCTConc->lastBlockData.spectralData, 0, L_FRAME_MAX );
        move16();
        hTonalMDCTConc->secondLastBlockData.spectralData = hTonalMDCTConc->spectralDataBuffers[1];
        set16_fx( hTonalMDCTConc->secondLastBlockData.spectralData, 0, L_FRAME_MAX );
        move16();
        hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData;
        move16();
        hTonalMDCTConc->secondLastPowerSpectrum_exp = hTonalMDCTConc->secondLastBlockData.spectralData_exp;
        move16();

        hTonalMDCTConc->lastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[0];
        set16_fx( hTonalMDCTConc->lastBlockData.scaleFactors, 0, FDNS_NPTS );
        move16();
        hTonalMDCTConc->secondLastBlockData.scaleFactors = hTonalMDCTConc->scaleFactorsBuffers[1];
        set16_fx( hTonalMDCTConc->secondLastBlockData.scaleFactors, 0, FDNS_NPTS );
        move16();
        /*Stop IVAS-only*/

        /*Common Part 2*/
    }
    hTonalMDCTConc->lastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[0];
    move16();
    hTonalMDCTConc->secondLastBlockData.scaleFactors_exp = hTonalMDCTConc->scaleFactorsBuffers_exp[1];
@@ -290,14 +117,13 @@ ivas_error TonalMDCTConceal_Init_ivas_fx(
    move16();
    hTonalMDCTConc->nScaleFactors = nScaleFactors;
    move16();

        /*start IVAS-only*/
    IF( NE_16( element_mode, EVS_MONO ) )
    {
        set32_fx( hTonalMDCTConc->scaleFactorsBackground_fx, 0, FDNS_NPTS );
        hTonalMDCTConc->scf_fadeout = 16384 /*1.000000 Q14*/;
        PsychoacousticParameters_Init_fx( INT_FS_16k, L_FRAME16k, 64, 1, 1, &hTonalMDCTConc->psychParamsTCX20 );
        PsychoacousticParameters_Init_fx( INT_FS_16k, L_FRAME16k / 2, 64, 0, 1, &hTonalMDCTConc->psychParamsTCX10 );
        hTonalMDCTConc->psychParams = NULL;

        hTonalMDCTConc->last_block_nrg = 0;
        move16();
        hTonalMDCTConc->last_block_nrg_exp = 0;
@@ -310,32 +136,23 @@ ivas_error TonalMDCTConceal_Init_ivas_fx(
        move16();
        hTonalMDCTConc->faded_signal_nrg_exp = 0;
        move16();
        /*stop IVAS-only*/


        /*Common Part 3*/
    }
    /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when
       new time samples are stored in lastPcmOut */
    move16();
    move16();
    /* just the second half of the second last pcm output is needed */


        /*start IVAS-only*/
    IF( NE_16( element_mode, EVS_MONO ) )
    {
        set16_fx( hTonalMDCTConc->timeDataBuffer, 0, ( 3 * L_FRAME_MAX ) / 2 );
        /*stop IVAS-only*/
    }

        /*Common Part 4*/
        hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * ( s_min( L_FRAME_MAX, nSamples ) ) / 2 )];
    hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * s_min( L_FRAME_MAX, nSamples ) / 2 )];
    hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - s_min( L_FRAME_MAX, nSamples )];
    /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */
    assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) );

#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit
    }
#endif /*#ifndef HARMONIZE_2583_open_decoder_LPD_TonalConcealseparateinit*/


    return IVAS_ERR_OK;
}