Unverified Commit 00bd7ed6 authored by norvell's avatar norvell
Browse files

Range check refactoring

parent aecf0f5e
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -615,6 +615,14 @@ int main(
            goto cleanup;
        }

#ifdef FIX_2500_ISM4_BIN_REVERB_DISTORTION
        if ( RenderConfigReader_checkValues( renderConfigReader ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nInvalid render configuration parameters\n\n" );
            goto cleanup;
        }
#endif

        aeCount = RenderConfigReader_getAcousticEnvironmentCount( renderConfigReader );
        if ( aeCount > 0 )
        {
@@ -696,11 +704,13 @@ int main(
        {
            if ( ( error = IVAS_DEC_GetAcousticEnvironment( hIvasDec, aeID, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK )
            {
#ifndef FIX_2500_ISM4_BIN_REVERB_DISTORTION
                if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "Invalid reverberation configuration parameters\n\n" );
                    goto cleanup;
                }
#endif
            }
            else
            {
@@ -2340,6 +2350,14 @@ static ivas_error decodeG192(
            fprintf( stderr, "Failed to read renderer configuration from file %s\n\n", arg.renderConfigFilename );
            goto cleanup;
        }

#ifdef FIX_2500_ISM4_BIN_REVERB_DISTORTION
        if ( RenderConfigReader_checkValues( renderConfigReader ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nInvalid render configuration parameters\n\n" );
            goto cleanup;
        }
#endif
    }

    for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i )
@@ -2541,11 +2559,13 @@ static ivas_error decodeG192(
                        arg.aeSequence.frameCounter = 0;
                        if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, arg.aeSequence.pID[arg.aeSequence.selected], &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK )
                        {
#ifndef FIX_2500_ISM4_BIN_REVERB_DISTORTION
                            if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK )
                            {
                                fprintf( stderr, "Invalid acoustic environment configuratoin parameters\n\n" );
                                goto cleanup;
                            }
#endif
                        }
                        else
                        {
+12 −0
Original line number Diff line number Diff line
@@ -1126,6 +1126,14 @@ int main(
            goto cleanup;
        }

#ifdef FIX_2500_ISM4_BIN_REVERB_DISTORTION
        if ( RenderConfigReader_checkValues( renderConfigReader ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nInvalid render configuration parameters\n\n" );
            goto cleanup;
        }
#endif

        if ( ( error = RenderConfigReader_getDirectivity( renderConfigReader, args.directivityPatternId, renderConfig.directivity ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Failed to get directivity patterns for one or more of IDs: %d %d %d %d\n\n", args.directivityPatternId[0], args.directivityPatternId[1], args.directivityPatternId[2], args.directivityPatternId[3] );
@@ -1143,11 +1151,13 @@ int main(
            aeID = args.aeSequence.count > 0 ? args.aeSequence.pID[0] : IVAS_DEFAULT_AEID;
            if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, aeID, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK )
            {
#ifndef FIX_2500_ISM4_BIN_REVERB_DISTORTION
                if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nInvalid room acoustics configuration parameters\n\n" );
                    goto cleanup;
                }
#endif
            }
            else
            {
@@ -1562,11 +1572,13 @@ int main(
                args.aeSequence.frameCounter = 0;
                if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, args.aeSequence.pID[args.aeSequence.selected], &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK )
                {
#ifndef FIX_2500_ISM4_BIN_REVERB_DISTORTION
                    if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "\nInvalid acoustic environment configuration parameters\n\n" );
                        goto cleanup;
                    }
#endif
                }
                else
                {
+1 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@

#define USE_RTPDUMP                                     /* FhG: RTPDUMP format (rtptools standard) instead of custom format */
#define FIX_1540_EXPOSE_PT_IN_RTP_HEADER_API            /* Expose Payload Type setting in RTP Header */
#define FIX_2500_ISM4_BIN_REVERB_DISTORTION             /* FhG: Basop issue #2500: Move RenderConfigReader_checkValues() to operate on RenderConfigReader float values before fixed-point conversion. */
#define FIX_BASOP_2023_TDREND_DISTATT_PRECISION         /* Eri: Basop issue 2023: Distance attenuation scaling, synch with BASOP updates and adding clamping of distance att input and listener position  */
#define FIX_1574_EFAP_CODE_LINT                         /* FhG: issue 1574: Code quality fixes in ivas_efap.c */
#define FIX_FLOAT_1569_REND_RENDER_CONFIG_CHECKS        /* Nokia: float issue 1569: fix render config checks in renderer */
+151 −0
Original line number Diff line number Diff line
@@ -1230,6 +1230,156 @@ static int32_t errorHandler(
 * Verifies if the configuration parameters lie within acceptable limits
 *------------------------------------------------------------------------------------------*/

#ifdef FIX_2500_ISM4_BIN_REVERB_DISTORTION
ivas_error RenderConfigReader_checkValues(
    RenderConfigReader *pRenderConfigReader /* i/o : RenderConfigReader handle              */
)
{
    int16_t band_idx, tab_value_err_count;
    int16_t wall_idx;
    uint32_t n, i;

    tab_value_err_count = 0;

    /* Verify all acoustic environments */
    for ( n = 0; n < pRenderConfigReader->nAE; n++ )
    {
        AcousticEnv *pAE = &pRenderConfigReader->pAE[n];
        int16_t nBands = (int16_t) pAE->pFG->nrBands;

        /* Verify the number of frequency bands in the config input data */
        if ( ( nBands > N_BANDS_MAX ) || ( nBands < N_BANDS_MIN ) )
        {
            return IVAS_ERR_WRONG_PARAMS;
        }

        /* Verify input pre-delay value */
        if ( ( pAE->preDelay > INPUTPREDELAY_MAX ) || ( pAE->preDelay < INPUTPREDELAY_MIN ) )
        {
            return IVAS_ERR_WRONG_PARAMS;
        }

        /* Verify data per band in the acoustic properties table */
        for ( band_idx = 0; band_idx < nBands; band_idx++ )
        {
            /* Verify if the frequencies are in the ascending order (required for interpolation) */
            if ( band_idx != 0 )
            {
                if ( pAE->pFG->pFc[band_idx] <= pAE->pFG->pFc[band_idx - 1] )
                {
                    tab_value_err_count++;
                }
            }

            /* Check the input frequencies */
            if ( ( pAE->pFG->pFc[band_idx] > FC_INPUT_MAX ) || ( pAE->pFG->pFc[band_idx] < FC_INPUT_MIN ) )
            {
                tab_value_err_count++;
            }

            /* Check the input RT60 values */
            if ( ( pAE->pRT60[band_idx] > ACOUSTIC_RT60_MAX ) || ( pAE->pRT60[band_idx] < ACOUSTIC_RT60_MIN ) )
            {
                tab_value_err_count++;
            }

            /* Check the input DSR values */
            if ( ( pAE->pDSR[band_idx] > ACOUSTIC_DSR_MAX ) || ( pAE->pDSR[band_idx] < ACOUSTIC_DSR_MIN ) )
            {
                tab_value_err_count++;
            }

            /* Replace zero DSR values with very small positive values, to avoid issues with coloration filter design */
            if ( pAE->pDSR[band_idx] <= 0.0f )
            {
                pAE->pDSR[band_idx] = ACOUSTIC_DSR_EPSILON;
            }
        }

        if ( tab_value_err_count != 0 )
        {
            return IVAS_ERR_WRONG_PARAMS;
        }

        /* Early reflections parameter clamping */
        if ( pAE->pEarlyReflections != NULL && pAE->pEarlyReflections->use_er == 1 )
        {
            /* Room dimensions */
            if ( pAE->pEarlyReflections->dimensions.x < ER_MIN_ROOM_DIMENSION )
            {
                pAE->pEarlyReflections->dimensions.x = ER_MIN_ROOM_DIMENSION;
            }
            if ( pAE->pEarlyReflections->dimensions.x > ER_MAX_ROOM_DIMENSION )
            {
                pAE->pEarlyReflections->dimensions.x = ER_MAX_ROOM_DIMENSION;
            }
            if ( pAE->pEarlyReflections->dimensions.y < ER_MIN_ROOM_DIMENSION )
            {
                pAE->pEarlyReflections->dimensions.y = ER_MIN_ROOM_DIMENSION;
            }
            if ( pAE->pEarlyReflections->dimensions.y > ER_MAX_ROOM_DIMENSION )
            {
                pAE->pEarlyReflections->dimensions.y = ER_MAX_ROOM_DIMENSION;
            }
            if ( pAE->pEarlyReflections->dimensions.z < ER_MIN_ROOM_DIMENSION )
            {
                pAE->pEarlyReflections->dimensions.z = ER_MIN_ROOM_DIMENSION;
            }
            if ( pAE->pEarlyReflections->dimensions.z > ER_MAX_ROOM_DIMENSION )
            {
                pAE->pEarlyReflections->dimensions.z = ER_MAX_ROOM_DIMENSION;
            }

            /* Abs Coeff */
            for ( wall_idx = 0; wall_idx < IVAS_ROOM_ABS_COEFF; wall_idx++ )
            {
                if ( pAE->pEarlyReflections->pAbsCoeff[wall_idx] < ER_MIN_ABS_COEFF )
                {
                    pAE->pEarlyReflections->pAbsCoeff[wall_idx] = ER_MIN_ABS_COEFF;
                }
                if ( pAE->pEarlyReflections->pAbsCoeff[wall_idx] > ER_MAX_ABS_COEFF )
                {
                    pAE->pEarlyReflections->pAbsCoeff[wall_idx] = ER_MAX_ABS_COEFF;
                }
            }
        }
    }

    /* Apply default distance attenuation if not specified in config */
    if ( pRenderConfigReader->distAtt[0] == -1 )
    {
        pRenderConfigReader->distAtt[0] = 15.75f;
        pRenderConfigReader->distAtt[1] = 1.0f;
        pRenderConfigReader->distAtt[2] = 1.0f;
    }

    /* Verify range of distance attenuation parameters */
#ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION
    /* refDist:       0.0 <= distAtt[1] <= 6.3         */
    /* maxDist:       distAtt[1] <= distAtt[0] <= 63.0 */
    /* rollOffFactor: 0 <= distAtt[2] <= 4.0           */
    pRenderConfigReader->distAtt[1] = min( max( 0, pRenderConfigReader->distAtt[1] ), DIST_ATT_MAX_REFDIST );
    pRenderConfigReader->distAtt[0] = min( max( pRenderConfigReader->distAtt[1], pRenderConfigReader->distAtt[0] ), DIST_ATT_MAX_MAXDIST );
    pRenderConfigReader->distAtt[2] = min( max( 0.0f, pRenderConfigReader->distAtt[2] ), DIST_ATT_MAX_ROLLOFF );
#else
    /* 0.1 <= distAtt[0] <= distAtt[1] */
    /* 0.0 <= distAtt[2] <= 10.0       */
    pRenderConfigReader->distAtt[0] = max( 0.1f, pRenderConfigReader->distAtt[0] );
    pRenderConfigReader->distAtt[1] = max( pRenderConfigReader->distAtt[0], pRenderConfigReader->distAtt[1] );
    pRenderConfigReader->distAtt[2] = max( 0.0f, min( 10.0f, pRenderConfigReader->distAtt[2] ) );
#endif

    /* Verify range of directivity patterns */
    for ( i = 0; i < pRenderConfigReader->nDP; i++ )
    {
        pRenderConfigReader->pDP[i].pDirectivity[0] = max( 0.0f, min( 360.0f, pRenderConfigReader->pDP[i].pDirectivity[0] ) );
        pRenderConfigReader->pDP[i].pDirectivity[1] = max( 0.0f, min( 360.0f, pRenderConfigReader->pDP[i].pDirectivity[1] ) );
        pRenderConfigReader->pDP[i].pDirectivity[2] = max( 0.0f, min( 1.0f, pRenderConfigReader->pDP[i].pDirectivity[2] ) );
    }

    return IVAS_ERR_OK;
}
#else  /* !FIX_2500_ISM4_BIN_REVERB_DISTORTION */
ivas_error RenderConfigReader_checkValues(
    IVAS_RENDER_CONFIG_HANDLE hRenderConfig /* o  : Renderer configuration handle          */
)
@@ -1364,6 +1514,7 @@ ivas_error RenderConfigReader_checkValues(

    return IVAS_ERR_OK;
}
#endif /* FIX_2500_ISM4_BIN_REVERB_DISTORTION */


/*------------------------------------------------------------------------------------------*
+6 −0
Original line number Diff line number Diff line
@@ -79,9 +79,15 @@ ivas_error RenderConfigReader_getDistanceAttenuation(
    float *distAtt                           /* o  : Distance attenuation                   */
);
/* Verifies configuration parameters                                                        */
#ifdef FIX_2500_ISM4_BIN_REVERB_DISTORTION
ivas_error RenderConfigReader_checkValues(
    RenderConfigReader *pRenderConfigReader /* i/o : RenderConfigReader handle               */
);
#else
ivas_error RenderConfigReader_checkValues(
    IVAS_RENDER_CONFIG_HANDLE hRenderConfig /* o  : Renderer configuration handle           */
);
#endif

/* Reads a configuration                                                                    */
ivas_error RenderConfigReader_read(