Commit 7fb489c7 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

[fix] bug where gains were never computed

parent 136c886a
Loading
Loading
Loading
Loading
Loading
+38 −17
Original line number Diff line number Diff line
@@ -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,
#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;
}