Commit d989eb80 authored by vaclav's avatar vaclav
Browse files

- Merge remote-tracking branch 'remotes/origin/main' into...

- Merge remote-tracking branch 'remotes/origin/main' into basop-2339-remove-duplicated-code-core-coder-dtx
parents 7df0a905 2997f3e6
Loading
Loading
Loading
Loading
Loading
+16 −79
Original line number Diff line number Diff line
@@ -142,11 +142,6 @@ typedef struct
    hrtfFileReader *hrtfReader;
    char *hrtfFileName;

#ifndef FIX_2249_MEMORY_LEAK_IN_SBA
    IVAS_DEC_HRTF_TD_HANDLE *hHrtfTD;

    IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics;
#endif

    IVAS_BIN_RENDERER_TYPE binaural_renderer;
    IVAS_BIN_RENDERER_TYPE binaural_renderer_old;
@@ -209,10 +204,6 @@ int main(
    reset_mem( USE_BYTES );
#endif

#ifndef FIX_2249_MEMORY_LEAK_IN_SBA
    hHrtfBinary.hHrtfTD = NULL;         /* just to avoid compilation warning */
    hHrtfBinary.hHrtfStatistics = NULL; /* just to avoid compilation warning */
#endif

    splitRendBits.bits_buf = splitRendBitsBuf;

@@ -741,21 +732,6 @@ cleanup:
        free( arg.aeSequence.pValidity );
    }

#ifndef FIX_2249_MEMORY_LEAK_IN_SBA
    if ( arg.hrtfReaderEnabled )
    {
        destroy_td_hrtf( hHrtfBinary.hHrtfTD );
        destroy_hrtf_statistics( hHrtfBinary.hHrtfStatistics );
    }
#ifdef FIX_1990_SANITIZER_IN_REVERB_LOAD
    // TODO:
    /* This free differs from float version.
       This is needed as HRTF statistics from ROM are currently converted from Word16 values to scaled Word32 values. */
    IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics = NULL;
    IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics );
    destroy_hrtf_statistics( hHrtfStatistics );
#endif
#endif
    IVAS_DEC_Close( &hIvasDec );
    CustomLsReader_close( &hLsCustomReader );
    hrtfFileReader_close( &hrtfReader );
@@ -3769,12 +3745,6 @@ static ivas_error load_hrtf_from_file(
        /*------------------------------------------------------------------------------------------*
         * Release HRTF binary data
         *------------------------------------------------------------------------------------------*/
#ifndef FIX_2249_MEMORY_LEAK_IN_SBA
        if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && binaural_renderer_sec != IVAS_BIN_RENDERER_TYPE_TDREND && hHrtfBinary->hHrtfTD != NULL )
        {
            destroy_td_hrtf( hHrtfBinary->hHrtfTD );
        }
#endif
        if ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtfBinary->binaural_renderer_old ) ) != IVAS_ERR_OK )
        {
            return error;
@@ -3797,22 +3767,14 @@ static ivas_error load_hrtf_from_file(
        if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_sec == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT )
        {

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
            IVAS_DEC_HRTF_TD_HANDLE *hHrtfTD = NULL;
            if ( ( error = IVAS_DEC_GetHrtfTDrendHandle( hIvasDec, &hHrtfTD ) ) != IVAS_ERR_OK )
#else
            if ( ( error = IVAS_DEC_GetHrtfTDrendHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK )
#endif
            {
                fprintf( stderr, "\nIVAS_DEC_GetHrtfTDrendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
                return error;
            }

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
            if ( ( error = load_TDrend_HRTF_binary( *hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK )
#else
            if ( ( error = load_TDrend_HRTF_binary( *hHrtfBinary->hHrtfTD, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK )
#endif
            {
                if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA )
                {
@@ -3821,11 +3783,7 @@ static ivas_error load_hrtf_from_file(
                }
                else
                {
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
                    destroy_td_hrtf( hHrtfTD );
#else
                    destroy_td_hrtf( hHrtfBinary->hHrtfTD );
#endif
                }
            }
        }
@@ -3898,32 +3856,17 @@ static ivas_error load_hrtf_from_file(
                }
            }
        }
#ifndef FIX_2249_MEMORY_LEAK_IN_SBA
    }
#endif

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
        if ( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
#else
        if ( hHrtfBinary->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
#endif
        {
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
            IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics = NULL;
            if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics ) ) != IVAS_ERR_OK )
#else
            if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK )
#endif
            {
                fprintf( stderr, "\nIVAS_DEC_GetHrtfStatisticsHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
                return error;
            }

#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
            if ( ( error = load_HrtfStatistics_from_binary( *hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK )
#else
            if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK )
#endif
            {
                if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA )
                {
@@ -3932,17 +3875,11 @@ static ivas_error load_hrtf_from_file(
                }
                else
                {
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
                    destroy_hrtf_statistics( hHrtfStatistics );
#else
                    destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics );
#endif
                }
            }
        }
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
    }
#endif

    return IVAS_ERR_OK;
}
+0 −8
Original line number Diff line number Diff line
@@ -1107,11 +1107,7 @@ int main(
            fprintf( stderr, "\nIVAS_REND_GetHrtfStatisticsHandle failed\n\n" );
            goto cleanup;
        }
#ifdef FIX_2249_MEMORY_LEAK_IN_SBA
        if ( ( error = load_HrtfStatistics_from_binary( *hHrtfStatistics, args.sampleRate, hrtfFileReader ) ) != IVAS_ERR_OK )
#else
        if ( ( error = load_reverb_binary( *hHrtfStatistics, args.sampleRate, hrtfFileReader ) ) != IVAS_ERR_OK )
#endif
        {
            if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA )
            {
@@ -2203,10 +2199,6 @@ cleanup:
    RotationFileReader_close( &externalOrientationFileReader );
    RotationFileReader_close( &referenceRotReader );
    Vector3PairFileReader_close( &referenceVectorReader );
#ifndef FIX_2249_MEMORY_LEAK_IN_SBA
    destroy_td_hrtf( hHrtfTD );
    destroy_hrtf_statistics( hHrtfStatistics );
#endif
    IVAS_REND_Close( &hIvasRend );
    IsmPositionProvider_close( positionProvider );
    RenderConfigReader_close( &renderConfigReader );
+0 −4
Original line number Diff line number Diff line
@@ -2734,11 +2734,7 @@ extern const Word16 Idx2Freq_Tbl[];
/* 'x' is converted to Q6, 'Freq_Tbl'/1000 in Q9 */
/* only works for 'fs' = [8000,12800,16000,25600,32000,48000] (unpredictable otherwise) */
/* 15625 is 1000000.0f/Q6 but we use the calculated value to avoid float point code */
#ifdef FIX_2286_GCC_WARNING_Idx2Freq_Tbl
#define NS2SA_FX2(fs,x)                         (chk_fs(fs) mult(Idx2Freq_Tbl[L_and(L_shr(fs,8),7)-2], (Word16)((x)/15625)))
#else
#define NS2SA_FX2(fs,x)                         (chk_fs(fs) mult((&Idx2Freq_Tbl[-2])[L_and(L_shr(fs,8),7)], (Word16)((x)/15625)))
#endif

#define L_FRAME_12k8                            256     /* Frame size at 12k8Hz: 20ms = 256 samples  */
#define L_FRAME_16k                             320     /* Frame size at 16kHz:  20ms = 320 samples  */
+0 −110
Original line number Diff line number Diff line
@@ -33,93 +33,9 @@
/* RETURN ARGUMENTS :                                                    */
/* _ (Word16) tolt_code :  tilt of the code           Q15                */
/*=======================================================================*/
#ifndef CLEANUP_ACELP_ENC
Word16 est_tilt_fx(                         /* o  : tilt of the code              Q15      */
                    const Word16 *exc,      /* i  : adaptive excitation vector      Qx  */
                    const Word16 gain_pit,  /* i  : adaptive gain                   Q14 */
                    const Word16 *code,     /* i  : algebraic excitation vector    Q9  */
                    const Word32 gain_code, /* i  : algebraic code gain             Q16 */
                    Word16 *voice_fac,      /* o  : voicing factor                  Q15 */
                    const Word16 Q_exc      /* i  : Scaling factor of excitation    Q0  */
)
{
    Word16 i, tmp, exp, ener1, exp1, ener2, exp2;
    Word32 L_tmp;
    Word16 tilt_code;

    ener1 = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp1 ) );
    exp1 = sub( exp1, add( Q_exc, Q_exc ) );
    L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */
    exp = norm_l( L_tmp );
    tmp = extract_h( L_shl( L_tmp, exp ) );
    ener1 = mult( ener1, tmp );
    exp1 = sub( sub( exp1, exp ), 10 ); /* 10 -> gain_pit Q14 to Q9   */

    ener2 = extract_h( Dot_product12( code, code, L_SUBFR, &exp2 ) );

    exp = norm_l( gain_code );
    tmp = extract_h( L_shl( gain_code, exp ) );
    tmp = mult( tmp, tmp ); /* energy of innovative code excitation */
    ener2 = mult( ener2, tmp );
    exp2 = sub( exp2, add( exp, exp ) );

    i = sub( exp1, exp2 );
    BASOP_SATURATE_WARNING_OFF_EVS
    ener1 = shr_sat( ener1, sub( 1, s_min( i, 0 ) ) );
    ener2 = shr_sat( ener2, add( s_max( 0, i ), 1 ) );
    BASOP_SATURATE_WARNING_ON_EVS
    tmp = sub( ener1, ener2 );
    ener1 = add( add( ener1, ener2 ), 1 );

    /* find voice factor (1=voiced, -1=unvoiced) */
    exp = div_s( abs_s( tmp ), ener1 );
    if ( tmp < 0 )
    {
        exp = negate( exp );
    }
    *voice_fac = exp;
    move16();

    /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */

    /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */
    tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */

    return tilt_code;
}

/*======================================================================*/
/* FUNCTION : est_tilt_ivas_fx()                                         */
/*-----------------------------------------------------------------------*/
/* PURPOSE :  Estimate spectral tilt based on the relative E of adaptive */
/* and innovative excitations                                            */
/*                                                                       */
/*-----------------------------------------------------------------------*/
/*  INPUT ARGUMENTS :                                                    */
/* _ (Word16 *) exc :  adaptive excitation vector      Q0                */
/* _ (Word16) gain_pit : adaptive gain                 Q14               */
/* _ (Word16 *) code : algebraic exctitation vector    Q12               */
/* _ (Word32) gain_code :  algebraic code gain         Q16               */
/* _ (Word16) Q_exc : Scaling factor of excitation     Q0                */
/*-----------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS :                                                    */
/* _ (Word16 *) voice_fac :   voicing factor          Q15                */
/*-----------------------------------------------------------------------*/
/* INPUT OUTPUT ARGUMENTS                                                */
/*-----------------------------------------------------------------------*/

/*-----------------------------------------------------------------------*/
/* RETURN ARGUMENTS :                                                    */
/* _ (Word16) tolt_code :  tilt of the code           Q15                */
/*=======================================================================*/
#endif

/* o  : tilt of the code Q15 */
#ifdef CLEANUP_ACELP_ENC
Word16 est_tilt_fx(
#else
Word16 est_tilt_ivas_fx(
#endif
    const Word16 *exc,      /* i  : adaptive excitation vector      Qx  */
    const Word16 gain_pit,  /* i  : adaptive gain                   Q14 */
    const Word16 *code,     /* i  : algebraic excitation vector     Q9  */
@@ -127,10 +43,6 @@ Word16 est_tilt_ivas_fx(
    Word16 *voice_fac,      /* o  : voicing factor                  Q15 */
    const Word16 Q_exc,     /* i  : Scaling factor of excitation    Q0  */
    const Word16 L_subfr    /* i  : Sub frame length                    */
#ifndef CLEANUP_ACELP_ENC
    ,
    const Word16 flag_tilt /* i  : flag for special tilt        */
#endif
)
{
    Word16 i, tmp, exp, ener1, exp1, ener2, exp2;
@@ -170,29 +82,7 @@ Word16 est_tilt_ivas_fx(
    *voice_fac = exp;
    move16();

#ifdef CLEANUP_ACELP_ENC
    tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */
#else
    IF( flag_tilt == 0 )
    {
        /* tilt of code for next subframe: 0.5=voiced, 0=unvoiced */

        /* tilt_code = (float)(0.25*(1.0 + *voice_fac)) */
    tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */
    }
    ELSE IF( EQ_16( flag_tilt, 1 ) )
    {
        /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/
        // tilt_code = (float)(0.25f + (*voice_fac + 1.0f) * 0.125f);
        tilt_code = mac_r( 12288L /*0.375.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4096 /*0.125.Q15*/ ); /*Q15 */
    }
    ELSE
    {
        /*Between 0.28 (=unvoiced) and 0.56 (=voiced)*/
        // tilt_code = (float)(0.28f + (*voice_fac + 1.0f) * 0.14f);
        tilt_code = mac_r( 13763L /*0.42.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4588 /*0.14.Q15*/ ); /*Q15 */
    }
#endif

    return tilt_code;
}
+196 −63

File changed.

Preview size limit exceeded, changes collapsed.

Loading