diff --git a/apps/decoder.c b/apps/decoder.c index dd9885e7cb26a23caae4e5c174cd961cda9d4468..71933ddeb92588a73b6a0d140f94211b06cc4a27 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -621,6 +621,14 @@ int main( goto cleanup; } +#ifdef FIX_2500_RENDCONF_REFACTOR + if ( RenderConfigReader_checkValues( renderConfigReader ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Invalid renderer configuration parameters\n\n" ); + goto cleanup; + } +#endif + aeCount = RenderConfigReader_getAcousticEnvironmentCount( renderConfigReader ); if ( aeCount > 0 ) { @@ -700,6 +708,13 @@ int main( if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { +#ifdef FIX_2500_RENDCONF_REFACTOR + if ( ( error = IVAS_DEC_GetAcousticEnvironment( hIvasDec, aeID, &renderConfig.roomAcoustics ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Failed to get acoustic environment with ID: %d\n\n", aeID ); + goto cleanup; + } +#else if ( ( error = IVAS_DEC_GetAcousticEnvironment( hIvasDec, aeID, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK ) { if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK ) @@ -713,6 +728,7 @@ int main( fprintf( stderr, "Failed to get acoustic environment with ID: %d\n\n", aeID ); goto cleanup; } +#endif } /* ISAR frame size is set from command line, not renderer config file. @@ -2350,6 +2366,14 @@ static ivas_error decodeG192( fprintf( stderr, "Failed to read renderer configuration from file %s\n\n", arg.renderConfigFilename ); goto cleanup; } + +#ifdef FIX_2500_RENDCONF_REFACTOR + if ( RenderConfigReader_checkValues( renderConfigReader ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Invalid renderer configuration parameters\n\n" ); + goto cleanup; + } +#endif } for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) @@ -2549,6 +2573,13 @@ static ivas_error decodeG192( arg.aeSequence.selected = 0; } arg.aeSequence.frameCounter = 0; +#ifdef FIX_2500_RENDCONF_REFACTOR + if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, arg.aeSequence.pID[arg.aeSequence.selected], &renderConfig.roomAcoustics ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Failed to get acoustic environment with ID %d\n\n", arg.aeSequence.pID[arg.aeSequence.selected] ); + goto cleanup; + } +#else if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, arg.aeSequence.pID[arg.aeSequence.selected], &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK ) { if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK ) @@ -2562,6 +2593,7 @@ static ivas_error decodeG192( fprintf( stderr, "Failed to get acoustic environment with ID %d\n\n", arg.aeSequence.pID[arg.aeSequence.selected] ); goto cleanup; } +#endif if ( ( error = IVAS_DEC_FeedRenderConfig( hIvasDec, renderConfig ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); diff --git a/apps/renderer.c b/apps/renderer.c index 33c73760c2a48f36d52a66efda596c93ec2b6dcf..de60458259c9bf8e4c6bb296f5bc6a56cd85f0be 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -1173,6 +1173,14 @@ int main( goto cleanup; } +#ifdef FIX_2500_RENDCONF_REFACTOR + if ( RenderConfigReader_checkValues( renderConfigReader ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Invalid renderer 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] ); @@ -1188,6 +1196,13 @@ int main( if ( args.outConfig.audioConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { aeID = args.aeSequence.count > 0 ? args.aeSequence.pID[0] : IVAS_DEFAULT_AEID; +#ifdef FIX_2500_RENDCONF_REFACTOR + if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, aeID, &renderConfig.roomAcoustics ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nFailed to get acoustic environment with ID: %d\n\n", aeID ); + goto cleanup; + } +#else if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, aeID, &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK ) { if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK ) @@ -1201,6 +1216,7 @@ int main( fprintf( stderr, "\nFailed to get acoustic environment with ID: %d\n\n", aeID ); goto cleanup; } +#endif } /* ISAR frame size is set from command line, not renderer config file. @@ -1607,6 +1623,13 @@ int main( args.aeSequence.selected = 0; } args.aeSequence.frameCounter = 0; +#ifdef FIX_2500_RENDCONF_REFACTOR + if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, args.aeSequence.pID[args.aeSequence.selected], &renderConfig.roomAcoustics ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nFailed to get acoustic environment with ID %d\n\n", args.aeSequence.pID[args.aeSequence.selected] ); + goto cleanup; + } +#else if ( ( error = RenderConfigReader_getAcousticEnvironment( renderConfigReader, args.aeSequence.pID[args.aeSequence.selected], &renderConfig.roomAcoustics ) ) == IVAS_ERR_OK ) { if ( RenderConfigReader_checkValues( &renderConfig ) != IVAS_ERR_OK ) @@ -1620,6 +1643,7 @@ int main( fprintf( stderr, "\nFailed to get acoustic environment with ID %d\n\n", args.aeSequence.pID[args.aeSequence.selected] ); goto cleanup; } +#endif if ( ( error = IVAS_REND_FeedRenderConfig( hIvasRend, renderConfig ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_REND_FeedRenderConfig failed: %s\n\n", ivas_error_to_string( error ) ); diff --git a/lib_com/options.h b/lib_com/options.h index d573f13932eb7745079bf1ecb0368e572c4e453f..ab964e0b239f9ada96a62962a2a9f53cdf65b8c6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -173,6 +173,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_RENDCONF_REFACTOR /* Eri: Basop issue #2500: Renderer configuration range check before conversion to fixed point. Harmonize between BASOP/float */ #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 */ diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index 3b61da871b70a029aeaba3ef8e84521b18029baa..2fef778ad26b58706e390cbaa708dc9ae299febe 100644 --- a/lib_util/render_config_reader.c +++ b/lib_util/render_config_reader.c @@ -72,9 +72,19 @@ #define IVAS_ER_LIST_ORIGIN_Y 0.0f #ifdef FIX_BASOP_2023_TDREND_DISTATT_PRECISION -#define DIST_ATT_MAX_MAXDIST 63.0f -#define DIST_ATT_MAX_REFDIST 6.3f -#define DIST_ATT_MAX_ROLLOFF 4.0f +#define DIST_ATT_MIN_MAXDIST 0.0f +#define DIST_ATT_MIN_REFDIST 0.0f +#define DIST_ATT_MIN_ROLLOFF 0.0f +#define DIST_ATT_MAX_MAXDIST 63.0f +#define DIST_ATT_MAX_REFDIST 6.3f +#define DIST_ATT_MAX_ROLLOFF 4.0f +#define DIST_ATT_DEFAULT_MAXDIST 15.75f +#define DIST_ATT_DEFAULT_REFDIST 1.0f +#define DIST_ATT_DEFAULT_ROLLOFF 1.0f +#define DIRECTIVITY_MIN_ANGLE 0.0f +#define DIRECTIVITY_MAX_ANGLE 360.0f +#define DIRECTIVITY_MIN_ATT_FAC 0.0f +#define DIRECTIVITY_MAX_ATT_FAC 1.0f #endif #ifndef TRUE @@ -1230,6 +1240,155 @@ static int32_t errorHandler( * Verifies if the configuration parameters lie within acceptable limits *------------------------------------------------------------------------------------------*/ +#ifdef FIX_2500_RENDCONF_REFACTOR +ivas_error RenderConfigReader_checkValues( + RenderConfigReader *pRenderConfigReader /* i/o: Renderer configuration reader */ +) +{ + int16_t tab_value_err_count; + int16_t wall_idx; + uint32_t i; + uint32_t nBands; + uint32_t band_idx; + uint32_t n; + AcousticEnv *pAE; + FrequencyGrid *pFG; + + tab_value_err_count = 0; + + /* Check range for all Acoustic Environment IDs */ + for ( n = 0; n < pRenderConfigReader->nAE; n++ ) + { + pAE = &pRenderConfigReader->pAE[n]; + pFG = pAE->pFG; + nBands = 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 ( pFG->pFc[band_idx] <= pFG->pFc[band_idx - 1] ) + { + tab_value_err_count++; + } + } + + /* Check the input frequencies */ + if ( ( pFG->pFc[band_idx] > FC_INPUT_MAX ) || ( 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; + } + + 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; + } + } + } + } + + /* Distance attenuation range check */ + if ( pRenderConfigReader->distAtt[0] == -1 ) + { + /* Default values */ + pRenderConfigReader->distAtt[0] = DIST_ATT_DEFAULT_MAXDIST; + pRenderConfigReader->distAtt[1] = DIST_ATT_DEFAULT_REFDIST; + pRenderConfigReader->distAtt[2] = DIST_ATT_DEFAULT_ROLLOFF; + } + else + { + /* Verify range of distance attenuation parameters: 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( DIST_ATT_MIN_REFDIST, 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( DIST_ATT_MIN_ROLLOFF, pRenderConfigReader->distAtt[2] ), DIST_ATT_MAX_ROLLOFF ); + } + + /* Verify range of directivity patterns */ + for ( i = 0; i < pRenderConfigReader->nDP; i++ ) + { + pRenderConfigReader->pDP[i].pDirectivity[0] = max( DIRECTIVITY_MIN_ANGLE, min( DIRECTIVITY_MAX_ANGLE, pRenderConfigReader->pDP[i].pDirectivity[0] ) ); + pRenderConfigReader->pDP[i].pDirectivity[1] = max( DIRECTIVITY_MIN_ANGLE, min( DIRECTIVITY_MAX_ANGLE, pRenderConfigReader->pDP[i].pDirectivity[1] ) ); + pRenderConfigReader->pDP[i].pDirectivity[2] = max( DIRECTIVITY_MIN_ATT_FAC, min( DIRECTIVITY_MAX_ATT_FAC, pRenderConfigReader->pDP[i].pDirectivity[2] ) ); + } + + return IVAS_ERR_OK; +} +#else ivas_error RenderConfigReader_checkValues( IVAS_RENDER_CONFIG_HANDLE hRenderConfig /* o : Renderer configuration handle */ ) @@ -1364,6 +1523,7 @@ ivas_error RenderConfigReader_checkValues( return IVAS_ERR_OK; } +#endif /*------------------------------------------------------------------------------------------* diff --git a/lib_util/render_config_reader.h b/lib_util/render_config_reader.h index 105d5d19413ab7f1be7d87103790d75440c20eed..a46ed261d6b48345e03bfc1dc5f9d433158739db 100644 --- a/lib_util/render_config_reader.h +++ b/lib_util/render_config_reader.h @@ -80,7 +80,11 @@ ivas_error RenderConfigReader_getDistanceAttenuation( ); /* Verifies configuration parameters */ ivas_error RenderConfigReader_checkValues( +#ifdef FIX_2500_RENDCONF_REFACTOR + RenderConfigReader *pRenderConfigReader /* i/o: Renderer configuration reader */ +#else IVAS_RENDER_CONFIG_HANDLE hRenderConfig /* o : Renderer configuration handle */ +#endif ); /* Reads a configuration */