Commit 4b98829e authored by vaclav's avatar vaclav
Browse files

Make clear separation between decoding and rendering: functions...

Make clear separation between decoding and rendering: functions IVAS_DEC_GetSamplesDecoder() and IVAS_DEC_GetSamplesRenderer() now replaced function IVAS_DEC_GetSamples()
parent 3e5f9c61
Loading
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -2451,10 +2451,11 @@ static ivas_error decodeG192(
                    }
                }
#endif
                /* Feed into decoder */
#ifdef OBJ_EDITING_API
                /* Feed into decoder and decode transport channels */
                if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, bit_stream, num_bits, bfi, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK )
#else
                /* Feed into decoder */
                if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, bit_stream, num_bits, bfi ) ) != IVAS_ERR_OK )
#endif
                {
@@ -2497,6 +2498,7 @@ static ivas_error decodeG192(
            }
#endif

            /* Render */
            if ( isSplitRend )
            {
                if ( ( error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), splitRendBits, &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK )
@@ -2510,14 +2512,24 @@ static ivas_error decodeG192(
            }
            else
            {
#ifdef OBJ_EDITING_API
                if ( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK )
                {
                    fprintf( stderr, "\nError in IVAS_DEC_GetSamplesRenderer(): %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }
#else
                    if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                        goto cleanup;
                    }
#endif

                nSamplesRendered += nSamplesRendered_loop;
                nSamplesToRender -= nSamplesRendered_loop;
            }

            if ( needNewFrame )
            {
                frame++;
+167 −120
Original line number Diff line number Diff line
@@ -926,128 +926,13 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
    hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame;

#ifdef OBJ_EDITING_API
    /* Decode TCs, do TSM and feed to renderer.
           If TSM is generally enabled, we have to wait for the first good frame.
           Otherwise, we directly decode the first frame in any case.
        */
    if ( ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && hIvasDec->hasBeenFedFirstGoodFrame ) || !hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
    {
        uint16_t l_ts, nTimeScalerOutSamples;
        uint8_t nTransportChannels, nOutChannels;
        int16_t nResidualSamples, nSamplesTcsScaled, nOutSamplesElse;

        if ( isSplitRend )
        {
            if ( ( error = isar_set_split_rend_setup( hIvasDec->st_ivas->hSplitBinRend, &hIvasDec->st_ivas->hRenderConfig->split_rend_config, hIvasDec->st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }

        if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &hIvasDec->nSamplesFlushed, hIvasDec->pcmType, hIvasDec->flushbuffer ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && nTransportChannels != hIvasDec->nTransportChannelsOld )
        {
            if ( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }

        /* IVAS TC decoder */
        if ( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        /* JBM */
        if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
        {
            if ( apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 )
            {
                return IVAS_ERR_UNKNOWN;
            }

            if ( apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, hIvasDec->nSamplesFrame * nTransportChannels, (uint16_t) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ) != 0 )
            {
                return IVAS_ERR_UNKNOWN;
            }

            assert( nTimeScalerOutSamples <= APA_BUF );
            nSamplesTcsScaled = nTimeScalerOutSamples / nTransportChannels;
            hIvasDec->timeScalingDone = 1;
        }
        else
        {
            nSamplesTcsScaled = hIvasDec->nSamplesFrame;
        }

        /* Feed decoded transport channels samples to the renderer */
        if ( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK )
    /* Decode TCs, do TSM and feed to renderer */;
    if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK )
    {
        return error;
    }

        if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
        {
            /* feed residual samples to TSM for the next call */
            if ( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (uint16_t) nResidualSamples ) != 0 )
            {
                return IVAS_ERR_UNKNOWN;
            }
        }
        hIvasDec->hasBeenFedFrame = false;
    }
    hIvasDec->hasBeenPreparedRendering = false;

    if ( hIvasDec->st_ivas->hIsmMetaData[0] )
    {
        if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT || hIvasDec->st_ivas->ivas_format == SBA_ISM_FORMAT )
        {
#ifdef OMASA_OBJECT_EDITING
            if ( hIvasDec->st_ivas->ism_mode == ISM_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC )
#else
            if ( hIvasDec->st_ivas->ism_mode == ISM_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC )
#endif
            {
                int16_t obj;
                ISM_METADATA_HANDLE *hIsmMetaData = hIvasDec->st_ivas->hIsmMetaData;
                for ( obj = 0; obj < hIvasDec->st_ivas->nchan_ism; obj++ )
                {
                    hIsmMetaData[obj]->edited_azimuth = hIsmMetaData[obj]->azimuth;
                    hIsmMetaData[obj]->edited_elevation = hIsmMetaData[obj]->elevation;
                    hIsmMetaData[obj]->edited_yaw = hIsmMetaData[obj]->yaw;
                    hIsmMetaData[obj]->edited_pitch = hIsmMetaData[obj]->pitch;
                    hIsmMetaData[obj]->edited_radius = hIsmMetaData[obj]->radius;
                    hIsmMetaData[obj]->edited_gain = 1.0f;
                }

                if ( hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC )
                {
                    hIvasDec->st_ivas->hSbaIsmData->gain_bed = 1.0f;
                }
            }
        }
    }

    if ( hIvasDec->st_ivas->hParamIsmDec != NULL )
    {
        if ( hIvasDec->st_ivas->ism_mode == ISM_MODE_PARAM )
        {
            int16_t obj = 0;
            PARAM_ISM_DEC_HANDLE hParamIsmDec = hIvasDec->st_ivas->hParamIsmDec;
            for ( obj = 0; obj < hIvasDec->st_ivas->nchan_ism; obj++ )
            {
                hParamIsmDec->edited_azimuth_values[obj] = hParamIsmDec->azimuth_values[obj];
                hParamIsmDec->edited_elevation_values[obj] = hParamIsmDec->elevation_values[obj];
            }
        }
    }
#endif

    return IVAS_ERR_OK;
}

@@ -1426,6 +1311,158 @@ ivas_error IVAS_DEC_PrepareRenderer(

#endif

#ifdef OBJ_EDITING_API

/*---------------------------------------------------------------------*
 * IVAS_DEC_GetSamplesDecoder( )
 *
 * Main function to decode transport channels, do TSM and feed to renderer.
 *---------------------------------------------------------------------*/

ivas_error IVAS_DEC_GetSamplesDecoder(
    IVAS_DEC_HANDLE hIvasDec,                /* i/o: IVAS decoder handle            */
    const int16_t isSplitRend,               /* i  : split rendering enabled flag   */
    ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o  : output split rendering bits    */
)
{
    ivas_error error;

    if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    /* If TSM is generally enabled, we have to wait for the first good frame.
       Otherwise, we directly decode the first frame in any case. */
    if ( ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && hIvasDec->hasBeenFedFirstGoodFrame ) || !hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
    {
        uint16_t l_ts, nTimeScalerOutSamples;
        uint8_t nTransportChannels, nOutChannels;
        int16_t nResidualSamples, nSamplesTcsScaled, nOutSamplesElse;

        if ( isSplitRend )
        {
            if ( ( error = isar_set_split_rend_setup( hIvasDec->st_ivas->hSplitBinRend, &hIvasDec->st_ivas->hRenderConfig->split_rend_config, hIvasDec->st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }

        if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &hIvasDec->nSamplesFlushed, hIvasDec->pcmType, hIvasDec->flushbuffer ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && nTransportChannels != hIvasDec->nTransportChannelsOld )
        {
            if ( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }

        /* IVAS TC decoder */
        if ( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        /* JBM */
        if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
        {
            if ( apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 )
            {
                return IVAS_ERR_UNKNOWN;
            }

            if ( apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, hIvasDec->nSamplesFrame * nTransportChannels, (uint16_t) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ) != 0 )
            {
                return IVAS_ERR_UNKNOWN;
            }

            assert( nTimeScalerOutSamples <= APA_BUF );
            nSamplesTcsScaled = nTimeScalerOutSamples / nTransportChannels;
            hIvasDec->timeScalingDone = 1;
        }
        else
        {
            nSamplesTcsScaled = hIvasDec->nSamplesFrame;
        }

        /* Feed decoded transport channels samples to the renderer */
        if ( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
        {
            /* feed residual samples to TSM for the next call */
            if ( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (uint16_t) nResidualSamples ) != 0 )
            {
                return IVAS_ERR_UNKNOWN;
            }
        }
        hIvasDec->hasBeenFedFrame = false;
    }
    hIvasDec->hasBeenPreparedRendering = false;

    if ( hIvasDec->st_ivas->hIsmMetaData[0] )
    {
        if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT || hIvasDec->st_ivas->ivas_format == SBA_ISM_FORMAT )
        {
#ifdef OMASA_OBJECT_EDITING
            if ( hIvasDec->st_ivas->ism_mode == ISM_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC )
#else
            if ( hIvasDec->st_ivas->ism_mode == ISM_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC )
#endif
            {
                int16_t obj;
                ISM_METADATA_HANDLE *hIsmMetaData = hIvasDec->st_ivas->hIsmMetaData;
                for ( obj = 0; obj < hIvasDec->st_ivas->nchan_ism; obj++ )
                {
                    hIsmMetaData[obj]->edited_azimuth = hIsmMetaData[obj]->azimuth;
                    hIsmMetaData[obj]->edited_elevation = hIsmMetaData[obj]->elevation;
                    hIsmMetaData[obj]->edited_yaw = hIsmMetaData[obj]->yaw;
                    hIsmMetaData[obj]->edited_pitch = hIsmMetaData[obj]->pitch;
                    hIsmMetaData[obj]->edited_radius = hIsmMetaData[obj]->radius;
                    hIsmMetaData[obj]->edited_gain = 1.0f;
                }

                if ( hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC )
                {
                    hIvasDec->st_ivas->hSbaIsmData->gain_bed = 1.0f;
                }
            }
        }
    }

    if ( hIvasDec->st_ivas->hParamIsmDec != NULL )
    {
        if ( hIvasDec->st_ivas->ism_mode == ISM_MODE_PARAM )
        {
            int16_t obj = 0;
            PARAM_ISM_DEC_HANDLE hParamIsmDec = hIvasDec->st_ivas->hParamIsmDec;
            for ( obj = 0; obj < hIvasDec->st_ivas->nchan_ism; obj++ )
            {
                hParamIsmDec->edited_azimuth_values[obj] = hParamIsmDec->azimuth_values[obj];
                hParamIsmDec->edited_elevation_values[obj] = hParamIsmDec->elevation_values[obj];
            }
        }
    }

    return IVAS_ERR_OK;
}


/*---------------------------------------------------------------------*
 * IVAS_DEC_GetSamplesRenderer( )
 *
 * Main function to render the decoded data to output data
 *---------------------------------------------------------------------*/

ivas_error IVAS_DEC_GetSamplesRenderer(
#else
/*---------------------------------------------------------------------*
 * IVAS_DEC_GetSamples( )
 *
@@ -1434,6 +1471,7 @@ ivas_error IVAS_DEC_PrepareRenderer(


ivas_error IVAS_DEC_GetSamples(
#endif
    IVAS_DEC_HANDLE hIvasDec,        /* i/o: IVAS decoder handle                                                     */
    const int16_t nSamplesAsked,     /* i  : number of samples wanted by the caller                                  */
    const IVAS_DEC_PCM_TYPE pcmType, /* i  : type for the decoded PCM resolution                                     */
@@ -1753,11 +1791,19 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream(
        }
    }

#ifdef OBJ_EDITING_API
    /* render */
    if ( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, numSamplesPerChannelToDecode, IVAS_DEC_PCM_FLOAT, pcmBuf, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK )
    {
        return error;
    }
#else
    /* Decode and render */
    if ( ( error = IVAS_DEC_GetSamples( hIvasDec, numSamplesPerChannelToDecode, IVAS_DEC_PCM_FLOAT, pcmBuf, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK )
    {
        return error;
    }
#endif

    /* change buffer layout */
    for ( i = 0; i < numSamplesPerChannelToDecode; ++i )
@@ -3343,6 +3389,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
                bsCompactToSerial( dataUnit->data, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize );

#ifdef OBJ_EDITING_API
                /* Feed into decoder and decode transport channels */
                if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0, 0, 0 ) ) != IVAS_ERR_OK )
#else
                if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 ) ) != IVAS_ERR_OK )
@@ -3449,7 +3496,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples(

            /* render IVAS frames directly to the output buffer */
#ifdef OBJ_EDITING_API
            if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, *nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK )
            if ( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, *nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK )
#else
            if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK )
#endif
+13 −0
Original line number Diff line number Diff line
@@ -177,8 +177,21 @@ ivas_error IVAS_DEC_PrepareRenderer(
);
#endif

#ifdef OBJ_EDITING_API
/*! r: decoder error code */
ivas_error IVAS_DEC_GetSamplesDecoder(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
    const int16_t isSplitRend,                  /* i  : split rendering enabled flag                                            */
    ISAR_SPLIT_REND_BITS_DATA *splitRendBits    /* o  : output split rendering bits                                             */
);

#endif
/*! r: decoder error code */
#ifdef OBJ_EDITING_API
ivas_error IVAS_DEC_GetSamplesRenderer(
#else
ivas_error IVAS_DEC_GetSamples(
#endif
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
    const int16_t nSamplesAsked,                /* i  : number of samples wanted by the caller                                  */
    const IVAS_DEC_PCM_TYPE pcmType,            /* i  : type for the decoded PCM resolution                                     */