From 136c886a69c3cdc32b09d9bbb158da6495343834 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Tue, 22 Aug 2023 14:07:52 +0200 Subject: [PATCH 1/4] avoid computing gains if ISM position didnt change for renderIsmTo{BinauralRoom,Mc,Sba} --- lib_com/options.h | 1 + lib_rend/lib_rend.c | 193 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 169 insertions(+), 25 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index be3261f808..634bc615a7 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -167,6 +167,7 @@ #define FIX_718_JBM_MD_UDPATE /* Fhg: fix issue #718, wrong setting of the update flag in the TD obj renderer in the JBM path */ #define FIX_719_CRASH_IN_CLEANUP /* VA: issue 719: fix Decoder crash after call to goto to cleanup */ +#define FIX_518_ISM_BRIR_EXTREND /* FhG: fix issue #518, cleanup ISM to BINAURAL_ROOM_IR rendering in the external renderer */ /* ################## End BE DEVELOPMENT switches ######################### */ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 96f2d4952a..f91280441e 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -144,6 +144,9 @@ typedef struct CREND_WRAPPER_HANDLE crendWrapper; REVERB_HANDLE hReverb; rotation_matrix rot_mat_prev; +#ifdef FIX_518_ISM_BRIR_EXTREND + pan_vector prev_pan_gains; +#endif #ifdef SPLIT_REND_WITH_HEAD_ROT TDREND_WRAPPER splitTdRendWrappers[MAX_HEAD_ROT_POSES - 1]; /* Additional TD Rend instances used for split rendering */ #endif @@ -1384,6 +1387,9 @@ static ivas_error setRendInputActiveIsm( inputIsm->hReverb = NULL; inputIsm->tdRendWrapper = defaultTdRendWrapper(); initRotMatrix( inputIsm->rot_mat_prev ); +#ifdef FIX_518_ISM_BRIR_EXTREND + set_zero( inputIsm->prev_pan_gains, MAX_OUTPUT_CHANNELS ); +#endif #ifdef SPLIT_REND_WITH_HEAD_ROT for ( i = 0; i < (int16_t) ( sizeof( inputIsm->splitTdRendWrappers ) / sizeof( *inputIsm->splitTdRendWrappers ) ); ++i ) @@ -6132,7 +6138,10 @@ static ivas_error renderIsmToBinauralRoom( input_ism *ismInput, IVAS_REND_AudioBuffer outAudio ) { - int16_t i; +#ifdef FIX_518_ISM_BRIR_EXTREND + int16_t position_changed; +#endif + int16_t i, j; int16_t azi_rot, ele_rot; int16_t subframe_idx; #ifndef API_5MS @@ -6143,12 +6152,16 @@ static ivas_error renderIsmToBinauralRoom( float tmpRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; ivas_error error; pan_vector currentPanGains; +#ifndef FIX_518_ISM_BRIR_EXTREND pan_vector previousPanGains; +#endif IVAS_REND_AudioBuffer tmpMcBuffer; +#ifdef FIX_518_ISM_BRIR_EXTREND + IVAS_REND_AudioObjectPosition rotatedPosPrev; +#endif IVAS_REND_AudioObjectPosition rotatedPos; const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData; int8_t combinedOrientationEnabled; - int16_t j; float *p_tmpRendBuffer[MAX_OUTPUT_CHANNELS]; for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) @@ -6158,6 +6171,10 @@ static ivas_error renderIsmToBinauralRoom( push_wmops( "renderIsmToBinauralRoom" ); +#ifdef FIX_518_ISM_BRIR_EXTREND + position_changed = FALSE; + rotatedPosPrev = defaultObjectPosition(); +#endif rotatedPos = defaultObjectPosition(); hCombinedOrientationData = ismInput->base.ctx.pCombinedOrientationData; @@ -6212,6 +6229,7 @@ static ivas_error renderIsmToBinauralRoom( #endif } +#ifndef FIX_518_ISM_BRIR_EXTREND /* TODO tmu : see issue #518 */ /* Possible optimization: less processing needed if position didn't change * needs a lot of cleanup, we could also add rot_gains_prev to ismInput and use that */ @@ -6230,27 +6248,52 @@ static ivas_error renderIsmToBinauralRoom( { return error; } +#else + /* get previous position */ + if ( combinedOrientationEnabled ) + { + rotateAziEle( ismInput->previousPos.azimuth, ismInput->previousPos.elevation, &azi_rot, &ele_rot, ismInput->rot_mat_prev, 0 ); + rotatedPosPrev.azimuth = (float) azi_rot; + rotatedPosPrev.elevation = (float) ele_rot; + } + else + { + rotatedPosPrev.azimuth = ismInput->previousPos.azimuth; + rotatedPosPrev.elevation = ismInput->previousPos.elevation; + } +#endif - /* current position gains */ + /* get current position */ if ( combinedOrientationEnabled ) { rotateAziEle( ismInput->currentPos.azimuth, ismInput->currentPos.elevation, &azi_rot, &ele_rot, Rmat, 0 ); rotatedPos.azimuth = (float) azi_rot; rotatedPos.elevation = (float) ele_rot; } - - if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, - ( combinedOrientationEnabled ) ? rotatedPos.azimuth : ismInput->currentPos.azimuth, - ( combinedOrientationEnabled ) ? rotatedPos.elevation : ismInput->currentPos.elevation, - currentPanGains ) ) != IVAS_ERR_OK ) +#ifdef FIX_518_ISM_BRIR_EXTREND + else { - return error; + rotatedPos.azimuth = ismInput->currentPos.azimuth; + rotatedPos.elevation = ismInput->currentPos.elevation; } - for ( i = 0; i < 3; i++ ) + /* compute gains only if position changed */ + if ( rotatedPos.azimuth != rotatedPosPrev.azimuth && + rotatedPos.elevation != rotatedPosPrev.elevation ) { - mvr2r( Rmat[i], ismInput->rot_mat_prev[i], 3 ); + position_changed = TRUE; +#endif + if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, + ( combinedOrientationEnabled ) ? rotatedPos.azimuth : ismInput->currentPos.azimuth, + ( combinedOrientationEnabled ) ? rotatedPos.elevation : ismInput->currentPos.elevation, + currentPanGains ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef FIX_518_ISM_BRIR_EXTREND } +#endif + /* intermediate rendering to 7_1_4 */ tmpMcBuffer = ismInput->base.inputBuffer; @@ -6264,10 +6307,31 @@ static ivas_error renderIsmToBinauralRoom( tmpMcBuffer.data = malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpMcBuffer.data, tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels ); - renderBufferChannelLerp( ismInput->base.inputBuffer, 0, currentPanGains, previousPanGains, tmpMcBuffer ); + renderBufferChannelLerp( ismInput->base.inputBuffer, 0, +#ifdef FIX_518_ISM_BRIR_EXTREND + position_changed ? currentPanGains : ismInput->prev_pan_gains, + position_changed ? ismInput->prev_pan_gains : NULL, +#else + currentPanGains, + previousPanGains, +#endif + tmpMcBuffer ); copyBufferTo2dArray( tmpMcBuffer, tmpRendBuffer ); + /* save gains for next frame */ + for ( i = 0; i < 3; i++ ) + { + mvr2r( Rmat[i], ismInput->rot_mat_prev[i], 3 ); + } +#ifdef FIX_518_ISM_BRIR_EXTREND + if ( position_changed ) + { + mvr2r( currentPanGains, ismInput->prev_pan_gains, MAX_OUTPUT_CHANNELS ); + } + +#endif + /* render 7_1_4 with BRIRs */ if ( ( error = ivas_rend_crendProcess( ismInput->crendWrapper, AUDIO_CONFIG_7_1_4, AUDIO_CONFIG_BINAURAL_ROOM_IR, NULL, NULL, NULL, NULL, p_tmpRendBuffer, *ismInput->base.ctx.pOutSampleRate #ifdef API_5MS @@ -6330,46 +6394,78 @@ static ivas_error renderIsmToBinauralReverb( static ivas_error renderIsmToMc( - const input_ism *ismInput, +#ifndef FIX_518_ISM_BRIR_EXTREND + const +#endif + input_ism *ismInput, const IVAS_REND_AudioBuffer outAudio ) { +#ifdef FIX_518_ISM_BRIR_EXTREND + int8_t position_changed; +#endif pan_vector currentPanGains; +#ifndef FIX_518_ISM_BRIR_EXTREND pan_vector previousPanGains; +#endif ivas_error error; push_wmops( "renderIsmToMc" ); +#ifdef FIX_518_ISM_BRIR_EXTREND + position_changed = FALSE; +#else /* TODO(sgi): Possible optimization: less processing needed if position didn't change */ +#endif if ( *ismInput->base.ctx.pOutConfig == AUDIO_CONFIG_STEREO ) { if ( ismInput->nonDiegeticPan ) { +#ifdef FIX_518_ISM_BRIR_EXTREND + ismInput->prev_pan_gains[0] = currentPanGains[0] = ( ismInput->nonDiegeticPanGain + 1.f ) * 0.5f; + ismInput->prev_pan_gains[1] = currentPanGains[1] = 1.f - currentPanGains[0]; +#else previousPanGains[0] = currentPanGains[0] = ( ismInput->nonDiegeticPanGain + 1.f ) * 0.5f; previousPanGains[1] = currentPanGains[1] = 1.f - currentPanGains[0]; error = IVAS_ERR_OK; +#endif } else { - set_zero( currentPanGains, 16 ); + set_zero( currentPanGains, MAX_OUTPUT_CHANNELS ); ivas_ism_get_stereo_gains( ismInput->currentPos.azimuth, ismInput->currentPos.elevation, ¤tPanGains[0], ¤tPanGains[1] ); - set_zero( previousPanGains, 16 ); +#ifdef FIX_518_ISM_BRIR_EXTREND + set_zero( ismInput->prev_pan_gains, MAX_OUTPUT_CHANNELS ); + + ivas_ism_get_stereo_gains( ismInput->previousPos.azimuth, ismInput->previousPos.elevation, &ismInput->prev_pan_gains[0], &ismInput->prev_pan_gains[1] ); +#else + set_zero( previousPanGains, MAX_OUTPUT_CHANNELS ); ivas_ism_get_stereo_gains( ismInput->previousPos.azimuth, ismInput->previousPos.elevation, &previousPanGains[0], &previousPanGains[1] ); +#endif } } else { - // TODO tmu review when #215 is resolved - if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, - (int16_t) floorf( ismInput->currentPos.azimuth + 0.5f ), - (int16_t) floorf( ismInput->currentPos.elevation + 0.5f ), - currentPanGains ) ) != IVAS_ERR_OK ) +#ifdef FIX_518_ISM_BRIR_EXTREND + /* compute gains only if position changed */ + if ( ismInput->currentPos.azimuth != ismInput->previousPos.azimuth && + ismInput->currentPos.elevation != ismInput->previousPos.elevation ) { - return error; + position_changed = TRUE; +#endif + // TODO tmu review when #215 is resolved + if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, + (int16_t) floorf( ismInput->currentPos.azimuth + 0.5f ), + (int16_t) floorf( ismInput->currentPos.elevation + 0.5f ), + currentPanGains ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef FIX_518_ISM_BRIR_EXTREND } - +#else // TODO tmu review when #215 is resolved if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, (int16_t) floorf( ismInput->previousPos.azimuth + 0.5f ), @@ -6378,11 +6474,27 @@ static ivas_error renderIsmToMc( { return error; } +#endif } /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ - renderBufferChannelLerp( ismInput->base.inputBuffer, 0, currentPanGains, previousPanGains, outAudio ); + renderBufferChannelLerp( ismInput->base.inputBuffer, 0, +#ifdef FIX_518_ISM_BRIR_EXTREND + position_changed ? currentPanGains : ismInput->prev_pan_gains, + position_changed ? ismInput->prev_pan_gains : NULL, +#else + currentPanGains, + previousPanGains, +#endif + outAudio ); + +#ifdef FIX_518_ISM_BRIR_EXTREND + if ( position_changed ) + { + mvr2r( currentPanGains, ismInput->prev_pan_gains, MAX_OUTPUT_CHANNELS ); + } +#endif pop_wmops(); @@ -6391,18 +6503,29 @@ static ivas_error renderIsmToMc( static ivas_error renderIsmToSba( - const input_ism *ismInput, +#ifndef FIX_518_ISM_BRIR_EXTREND + const +#endif + input_ism *ismInput, const AUDIO_CONFIG outConfig, const IVAS_REND_AudioBuffer outAudio ) { +#ifdef FIX_518_ISM_BRIR_EXTREND + int8_t position_changed; +#endif int16_t ambiOrderOut; int16_t numOutChannels; pan_vector currentPanGains; +#ifndef FIX_518_ISM_BRIR_EXTREND pan_vector previousPanGains; +#endif ivas_error error; error = IVAS_ERR_OK; push_wmops( "renderIsmToSba" ); +#ifdef FIX_518_ISM_BRIR_EXTREND + position_changed = FALSE; +#endif if ( ( error = getAudioConfigNumChannels( outConfig, &numOutChannels ) ) != IVAS_ERR_OK ) { @@ -6414,19 +6537,25 @@ static ivas_error renderIsmToSba( return error; } +#ifndef FIX_518_ISM_BRIR_EXTREND // TODO tmu review when #215 is resolved ivas_dirac_dec_get_response( (int16_t) floorf( ismInput->previousPos.azimuth + 0.5f ), (int16_t) floorf( ismInput->previousPos.elevation + 0.5f ), previousPanGains, ambiOrderOut ); +#endif if ( ( ismInput->currentPos.azimuth == ismInput->previousPos.azimuth ) && ( ismInput->currentPos.elevation == ismInput->previousPos.elevation ) ) { +#ifdef FIX_518_ISM_BRIR_EXTREND + position_changed = TRUE; +#else mvr2r( previousPanGains, currentPanGains, MAX_OUTPUT_CHANNELS ); } else { +#endif // TODO tmu review when #215 is resolved ivas_dirac_dec_get_response( (int16_t) floorf( ismInput->currentPos.azimuth + 0.5f ), (int16_t) floorf( ismInput->currentPos.elevation + 0.5f ), @@ -6436,8 +6565,22 @@ static ivas_error renderIsmToSba( /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ - renderBufferChannelLerp( ismInput->base.inputBuffer, 0, currentPanGains, previousPanGains, outAudio ); + renderBufferChannelLerp( ismInput->base.inputBuffer, 0, +#ifdef FIX_518_ISM_BRIR_EXTREND + position_changed ? currentPanGains : ismInput->prev_pan_gains, + position_changed ? ismInput->prev_pan_gains : NULL, +#else + currentPanGains, + previousPanGains, +#endif + outAudio ); +#ifdef FIX_518_ISM_BRIR_EXTREND + if ( position_changed ) + { + mvr2r( currentPanGains, ismInput->prev_pan_gains, MAX_OUTPUT_CHANNELS ); + } +#endif pop_wmops(); return error; -- GitLab From 7fb489c7a7e3feff0000e50579cc1d397d7e796b Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Tue, 22 Aug 2023 16:49:40 +0200 Subject: [PATCH 2/4] [fix] bug where gains were never computed --- lib_rend/lib_rend.c | 55 +++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index f91280441e..1c2cea92c8 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -146,6 +146,7 @@ typedef struct rotation_matrix rot_mat_prev; #ifdef FIX_518_ISM_BRIR_EXTREND pan_vector prev_pan_gains; + int8_t firstFrameRendered; #endif #ifdef SPLIT_REND_WITH_HEAD_ROT TDREND_WRAPPER splitTdRendWrappers[MAX_HEAD_ROT_POSES - 1]; /* Additional TD Rend instances used for split rendering */ @@ -1249,6 +1250,15 @@ static IVAS_REND_AudioObjectPosition defaultObjectPosition( return pos; } +#ifdef FIX_518_ISM_BRIR_EXTREND +static int8_t checkObjectPositionChanged( + IVAS_REND_AudioObjectPosition *currentPos, + IVAS_REND_AudioObjectPosition *previousPos ) +{ + return ( fabs( currentPos->azimuth - previousPos->azimuth ) < EPSILON && + fabs( currentPos->elevation - previousPos->elevation ) < EPSILON ); +} +#endif static rendering_context getRendCtx( IVAS_REND_HANDLE hIvasRend ) @@ -1381,6 +1391,10 @@ static ivas_error setRendInputActiveIsm( } initRendInputBase( &inputIsm->base, inConfig, id, rendCtx, inputIsm->bufferData, MAX_BUFFER_LENGTH ); +#ifdef FIX_518_ISM_BRIR_EXTREND + inputIsm->firstFrameRendered = FALSE; +#endif + inputIsm->currentPos = defaultObjectPosition(); inputIsm->previousPos = defaultObjectPosition(); inputIsm->crendWrapper = NULL; @@ -6172,7 +6186,6 @@ static ivas_error renderIsmToBinauralRoom( push_wmops( "renderIsmToBinauralRoom" ); #ifdef FIX_518_ISM_BRIR_EXTREND - position_changed = FALSE; rotatedPosPrev = defaultObjectPosition(); #endif rotatedPos = defaultObjectPosition(); @@ -6277,15 +6290,21 @@ static ivas_error renderIsmToBinauralRoom( rotatedPos.elevation = ismInput->currentPos.elevation; } + position_changed = !ismInput->firstFrameRendered && + checkObjectPositionChanged( &rotatedPos, &rotatedPosPrev ); + /* compute gains only if position changed */ - if ( rotatedPos.azimuth != rotatedPosPrev.azimuth && - rotatedPos.elevation != rotatedPosPrev.elevation ) + if ( position_changed ) { - position_changed = TRUE; #endif if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, - ( combinedOrientationEnabled ) ? rotatedPos.azimuth : ismInput->currentPos.azimuth, - ( combinedOrientationEnabled ) ? rotatedPos.elevation : ismInput->currentPos.elevation, +#ifdef FIX_518_ISM_BRIR_EXTREND + rotatedPos.azimuth, + rotatedPos.elevation, +#else + ( combinedOrientationEnabled ) ? rotatedPos.azimuth : ismInput->currentPos.azimuth, + ( combinedOrientationEnabled ) ? rotatedPos.elevation : ismInput->currentPos.elevation, +#endif currentPanGains ) ) != IVAS_ERR_OK ) { return error; @@ -6412,7 +6431,8 @@ static ivas_error renderIsmToMc( push_wmops( "renderIsmToMc" ); #ifdef FIX_518_ISM_BRIR_EXTREND - position_changed = FALSE; + position_changed = !ismInput->firstFrameRendered && + checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); #else /* TODO(sgi): Possible optimization: less processing needed if position didn't change */ #endif @@ -6450,10 +6470,8 @@ static ivas_error renderIsmToMc( { #ifdef FIX_518_ISM_BRIR_EXTREND /* compute gains only if position changed */ - if ( ismInput->currentPos.azimuth != ismInput->previousPos.azimuth && - ismInput->currentPos.elevation != ismInput->previousPos.elevation ) + if ( position_changed ) { - position_changed = TRUE; #endif // TODO tmu review when #215 is resolved if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, @@ -6523,9 +6541,6 @@ static ivas_error renderIsmToSba( error = IVAS_ERR_OK; push_wmops( "renderIsmToSba" ); -#ifdef FIX_518_ISM_BRIR_EXTREND - position_changed = FALSE; -#endif if ( ( error = getAudioConfigNumChannels( outConfig, &numOutChannels ) ) != IVAS_ERR_OK ) { @@ -6544,17 +6559,19 @@ static ivas_error renderIsmToSba( previousPanGains, ambiOrderOut ); -#endif if ( ( ismInput->currentPos.azimuth == ismInput->previousPos.azimuth ) && ( ismInput->currentPos.elevation == ismInput->previousPos.elevation ) ) { -#ifdef FIX_518_ISM_BRIR_EXTREND - position_changed = TRUE; -#else mvr2r( previousPanGains, currentPanGains, MAX_OUTPUT_CHANNELS ); } else { +#else + position_changed = !ismInput->firstFrameRendered && + checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); + + if ( position_changed ) + { #endif // TODO tmu review when #215 is resolved ivas_dirac_dec_get_response( (int16_t) floorf( ismInput->currentPos.azimuth + 0.5f ), @@ -6800,6 +6817,10 @@ static ivas_error renderInputIsm( return error; } +#ifdef FIX_518_ISM_BRIR_EXTREND + ismInput->firstFrameRendered = TRUE; +#endif + return error; } -- GitLab From 8757e52eb2ed7bd5ba6a20d0e6ce25714e7ba1bb Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 23 Aug 2023 10:36:55 +0200 Subject: [PATCH 3/4] [fix] incorrect condition for position change check --- lib_rend/lib_rend.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 1c2cea92c8..8b901890f6 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1255,8 +1255,8 @@ static int8_t checkObjectPositionChanged( IVAS_REND_AudioObjectPosition *currentPos, IVAS_REND_AudioObjectPosition *previousPos ) { - return ( fabs( currentPos->azimuth - previousPos->azimuth ) < EPSILON && - fabs( currentPos->elevation - previousPos->elevation ) < EPSILON ); + return !( fabs( currentPos->azimuth - previousPos->azimuth ) < EPSILON && + fabs( currentPos->elevation - previousPos->elevation ) < EPSILON ); } #endif @@ -6290,7 +6290,7 @@ static ivas_error renderIsmToBinauralRoom( rotatedPos.elevation = ismInput->currentPos.elevation; } - position_changed = !ismInput->firstFrameRendered && + position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged( &rotatedPos, &rotatedPosPrev ); /* compute gains only if position changed */ @@ -6431,7 +6431,7 @@ static ivas_error renderIsmToMc( push_wmops( "renderIsmToMc" ); #ifdef FIX_518_ISM_BRIR_EXTREND - position_changed = !ismInput->firstFrameRendered && + position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); #else /* TODO(sgi): Possible optimization: less processing needed if position didn't change */ @@ -6567,7 +6567,7 @@ static ivas_error renderIsmToSba( else { #else - position_changed = !ismInput->firstFrameRendered && + position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); if ( position_changed ) -- GitLab From d38e1e405eaf83d5983b4dd53e72ca13d95a3213 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 23 Aug 2023 12:35:21 +0200 Subject: [PATCH 4/4] [fix] preserve BE: previous gains needed to be set on first frame --- lib_rend/lib_rend.c | 68 +++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 8b901890f6..474e6c7f27 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -6293,6 +6293,15 @@ static ivas_error renderIsmToBinauralRoom( position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged( &rotatedPos, &rotatedPosPrev ); + /* set previous gains if this is the first frame */ + if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, + rotatedPosPrev.azimuth, + rotatedPosPrev.elevation, + ismInput->prev_pan_gains ) ) != IVAS_ERR_OK ) + { + return error; + } + /* compute gains only if position changed */ if ( position_changed ) { @@ -6483,14 +6492,25 @@ static ivas_error renderIsmToMc( } #ifdef FIX_518_ISM_BRIR_EXTREND } -#else - // TODO tmu review when #215 is resolved - if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, - (int16_t) floorf( ismInput->previousPos.azimuth + 0.5f ), - (int16_t) floorf( ismInput->previousPos.elevation + 0.5f ), - previousPanGains ) ) != IVAS_ERR_OK ) + + /* set previous gains if this is the first frame */ + if ( !ismInput->firstFrameRendered ) { - return error; +#endif + // TODO tmu review when #215 is resolved + if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, + (int16_t) floorf( ismInput->previousPos.azimuth + 0.5f ), + (int16_t) floorf( ismInput->previousPos.elevation + 0.5f ), +#ifdef FIX_518_ISM_BRIR_EXTREND + ismInput->prev_pan_gains +#else + previousPanGains +#endif + ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef FIX_518_ISM_BRIR_EXTREND } #endif } @@ -6552,12 +6572,30 @@ static ivas_error renderIsmToSba( return error; } -#ifndef FIX_518_ISM_BRIR_EXTREND - // TODO tmu review when #215 is resolved - ivas_dirac_dec_get_response( (int16_t) floorf( ismInput->previousPos.azimuth + 0.5f ), - (int16_t) floorf( ismInput->previousPos.elevation + 0.5f ), +#ifdef FIX_518_ISM_BRIR_EXTREND + position_changed = !ismInput->firstFrameRendered || + checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); + + /* set previous gains if this is the first frame */ + if ( !ismInput->firstFrameRendered ) + { +#endif + // TODO tmu review when #215 is resolved + ivas_dirac_dec_get_response( (int16_t) floorf( ismInput->previousPos.azimuth + 0.5f ), + (int16_t) floorf( ismInput->previousPos.elevation + 0.5f ), +#ifdef FIX_518_ISM_BRIR_EXTREND + ismInput->prev_pan_gains, +#else previousPanGains, - ambiOrderOut ); +#endif + ambiOrderOut ); +#ifdef FIX_518_ISM_BRIR_EXTREND + } + + /* compute gains only if position changed */ + if ( position_changed ) + { +#else if ( ( ismInput->currentPos.azimuth == ismInput->previousPos.azimuth ) && ( ismInput->currentPos.elevation == ismInput->previousPos.elevation ) ) @@ -6566,12 +6604,6 @@ static ivas_error renderIsmToSba( } else { -#else - position_changed = !ismInput->firstFrameRendered || - checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); - - if ( position_changed ) - { #endif // TODO tmu review when #215 is resolved ivas_dirac_dec_get_response( (int16_t) floorf( ismInput->currentPos.azimuth + 0.5f ), -- GitLab