Commit 7976c073 authored by bayers's avatar bayers
Browse files

fix for #864, fix JBM for 5ms, address comments, simplify flushing for JBM

parent e80cfb8a
Loading
Loading
Loading
Loading
+12 −145
Original line number Diff line number Diff line
@@ -3360,10 +3360,10 @@ static ivas_error decodeVoIP(
#ifdef NONBE_FIX_864_JBM_RENDER_FRAMESIZE
        if ( vec_pos_update == 0 )
        {
#endif
            systemTime_ms += vec_pos_len * systemTimeInc_ms;
#ifdef NONBE_FIX_864_JBM_RENDER_FRAMESIZE
        }
#else
        systemTime_ms += systemTimeInc_ms;
#endif

#ifdef WMOPS
@@ -3376,9 +3376,6 @@ static ivas_error decodeVoIP(
#ifdef NONBE_FIX_864_JBM_RENDER_FRAMESIZE
    int16_t nSamplesFlushed = 0;

    do
    {

    /* decode and get samples */
#ifdef SPLIT_REND_WITH_HEAD_ROT
    if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK )
@@ -3390,6 +3387,8 @@ static ivas_error decodeVoIP(
        goto cleanup;
    }

    if ( nSamplesFlushed )
    {
        /* Write current frame */
        if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, nSamplesFlushed * nOutChannels ) ) != IVAS_ERR_OK )
        {
@@ -3442,139 +3441,7 @@ static ivas_error decodeVoIP(
                }
            }
        }

        vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len;
        frame++;
        if ( !arg.quietModeEnabled )
        {
            fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame );
#ifdef DEBUGGING
            if ( IVAS_DEC_GetBerDetectFlag( hIvasDec ) )
            {
                fprintf( stdout, "\n   Decoding error: BER detected in frame %d !!!!!\n", frame - 1 );
            }
#endif
        }

        /* reference vector */
        if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 )
        {
            IVAS_VECTOR3 listenerPosition, referencePosition;
            if ( ( error = Vector3PairFileReader_read( referenceVectorReader, &listenerPosition, &referencePosition ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nError %s while reading listener and reference positions from %s\n", IVAS_DEC_GetErrorMessage( error ), Vector3PairFileReader_getFilePath( referenceVectorReader ) );
                goto cleanup;
            }

            if ( ( error = IVAS_DEC_FeedRefVectorData( hIvasDec, listenerPosition, referencePosition ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_DEC_FeedRefVectorData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                goto cleanup;
            }
        }

        /* Reference rotation */
        if ( arg.enableReferenceRotation && vec_pos_update == 0 )
        {
            IVAS_QUATERNION quaternion;
            if ( ( error = HeadRotationFileReading( refRotReader, &quaternion, NULL ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nError %s while reading reference rotation from %s\n", IVAS_DEC_GetErrorMessage( error ), RotationFileReader_getFilePath( refRotReader ) );
                goto cleanup;
            }

            if ( ( error = IVAS_DEC_FeedRefRotData( hIvasDec, quaternion ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_DEC_FeedRefRotData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                goto cleanup;
            }
        }
        int16_t num_subframes;
        if ( ( error = IVAS_DEC_GetNumOrientationSubframes( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nIVAS_DEC_GetNumOrientationSubframes failed: \n" );
            goto cleanup;
        }

        /* Head-tracking input simulation */
        /* Head-tracking input simulation */
        if ( arg.enableHeadRotation )
        {
            IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];

#ifdef SPLIT_REND_WITH_HEAD_ROT
            if ( headRotReader == NULL )
            {
                for ( i = 0; i < num_subframes; i++ )
                {
                    Quaternions[i].w = -3.0f;
                    Quaternions[i].x = 0.0f;
                    Quaternions[i].y = 0.0f;
                    Quaternions[i].z = 0.0f;
                    Pos[i].x = 0.0f;
                    Pos[i].y = 0.0f;
                    Pos[i].z = 0.0f;
                }
            }
            else
            {
#endif
                for ( i = 0; i < num_subframes; i++ )
                {
                    if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "\nError %s while reading head orientation from %s\n", IVAS_DEC_GetErrorMessage( error ),
                                 RotationFileReader_getFilePath( headRotReader ) );
                        goto cleanup;
                    }
                }
#ifdef SPLIT_REND_WITH_HEAD_ROT
            }
#endif

            for ( i = 0; i < num_subframes; i++ )
            {
                if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i
#ifdef SPLIT_REND_WITH_HEAD_ROT
                                                           ,
                                                           DEFAULT_AXIS
#endif
                                                           ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }
            }
        }

        if ( arg.enableExternalOrientation )
        {
            IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            int8_t enableHeadRotation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            int8_t enableExternalOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            int8_t enableRotationInterpolation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];
            int16_t numFramesToTargetOrientation[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES];

            for ( i = 0; i < num_subframes; i++ )
            {

                if ( ( error = ExternalOrientationFileReading( externalOrientationFileReader, &Quaternions[i], &enableHeadRotation[i], &enableExternalOrientation[i], &enableRotationInterpolation[i], &numFramesToTargetOrientation[i] ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError %s while reading external orientation from %s\n", IVAS_DEC_GetErrorMessage( error ),
                             RotationFileReader_getFilePath( externalOrientationFileReader ) );
                    goto cleanup;
                }
            }
            for ( i = 0; i < num_subframes; i++ )
            {
                if ( ( error = IVAS_DEC_FeedExternalOrientationData( hIvasDec, Quaternions[i], enableHeadRotation[i], enableExternalOrientation[i], enableRotationInterpolation[i], numFramesToTargetOrientation[i], i ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nIVAS_DEC_FeedExternalOrientationData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }
            }
    }
    } while ( nSamplesFlushed > 0 );
#endif

    /*------------------------------------------------------------------------------------------*