Commit b24d9d29 authored by vaclav's avatar vaclav
Browse files

add FIX_HRTF_LOAD_JBM

parent 89678ef5
Loading
Loading
Loading
Loading
+54 −1
Original line number Diff line number Diff line
@@ -193,7 +193,11 @@ static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS
#else
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
#endif
#ifdef FIX_HRTF_LOAD_JBM
static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec );
#else
static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec );
#endif
#ifdef FIX_HRTF_LOAD
static ivas_error IVAS_DEC_LoadHrtfFromFile( IVAS_DEC_HRTF_WRAPPER *hHrtf, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs );
#endif
@@ -774,7 +778,7 @@ int main(
#ifdef FIX_HRTF_LOAD
        hHrtf.hrtfReader = hrtfReader;
        hHrtf.hrtfFileName = arg.hrtfFileName;

#ifndef FIX_HRTF_LOAD_JBM
        if ( arg.voipMode )
        {
            hHrtf.binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT;
@@ -785,6 +789,7 @@ int main(
                goto cleanup;
            }
        }
#endif
#else
        if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ) ) != IVAS_ERR_OK )
        {
@@ -904,7 +909,11 @@ int main(

    if ( arg.voipMode )
    {
#ifdef FIX_HRTF_LOAD_JBM
        error = decodeVoIP( arg, hBsReader, &hHrtf, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec );
#else
        error = decodeVoIP( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec );
#endif
    }
    else
    {
@@ -2534,10 +2543,12 @@ static ivas_error decodeG192(
#endif
                /* Feed into decoder */
                if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, bit_stream, num_bits, bfi
#ifndef FIX_HRTF_LOAD_JBM
#ifdef OBJ_EDITING_API
                                                          ,
                                                          isSplitRend,
                                                          splitRendBits
#endif
#endif
                                                          ) ) != IVAS_ERR_OK )
                {
@@ -2554,6 +2565,7 @@ static ivas_error decodeG192(
                }

                /* Placeholder for memory reallocation */
                /* ... */

                /* Load HRTF binary file data */
                if ( arg.hrtfReaderEnabled )
@@ -3138,6 +3150,9 @@ static ivas_error writeJbmTraceFileFrameWrapper( const void *data, void *writer
static ivas_error decodeVoIP(
    DecArguments arg,
    BS_READER_HANDLE hBsReader,
#ifdef FIX_HRTF_LOAD_JBM
    IVAS_DEC_HRTF_WRAPPER *hHrtf,
#endif
    RotFileReader *headRotReader,
    RotFileReader *externalOrientationFileReader,
    RotFileReader *refRotReader,
@@ -3188,6 +3203,10 @@ static ivas_error decodeVoIP(
    int16_t vec_pos_update, vec_pos_len;
    int16_t nOutSamples = 0;

#ifdef FIX_HRTF_LOAD_JBM
    bool bitstreamReadDone = false;
#endif

#ifdef OBJ_EDITING_API
    bool parameterAvailableForEditing = false;
    uint16_t nSamplesRendered = 0;
@@ -3481,6 +3500,10 @@ static ivas_error decodeVoIP(

#ifdef SUPPORT_JBM_TRACEFILE
            if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter
#ifdef FIX_HRTF_LOAD_JBM
                                                     ,
                                                     &bitstreamReadDone
#endif
#ifdef OBJ_EDITING_API
                                                     ,
                                                     &nSamplesRendered, &parameterAvailableForEditing
@@ -3488,6 +3511,10 @@ static ivas_error decodeVoIP(
                                                     ) ) != IVAS_ERR_OK )
#else
        if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, &nSamplesRendered, &parameterAvailableForEditing
#ifdef FIX_HRTF_LOAD_JBM
                                                 ,
                                                 &bitstreamReadDone
#endif
#ifdef OBJ_EDITING_API
                                                                                                                                                   & nSamplesRendered,
                                                 &parameterAvailableForEditing
@@ -3498,6 +3525,32 @@ static ivas_error decodeVoIP(
                fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                goto cleanup;
            }
#ifdef FIX_HRTF_LOAD_JBM

            if ( bitstreamReadDone == true )
            {
                /* Read main parameters from the bitstream to set-up the decoder */
                hHrtf->binaural_renderer_old = hHrtf->binaural_renderer;
                if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->room_reverb_flag, &hHrtf->intern_audio_config ) ) != IVAS_ERR_OK )
                {
                    return error;
                }

                /* Placeholder for memory reallocation */
                /* ... */

                /* Load HRTF binary file data */
                if ( arg.hrtfReaderEnabled )
                {
                    if ( ( error = IVAS_DEC_LoadHrtfFromFile( hHrtf, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
                        goto cleanup;
                    }
                }
            }

#endif
#ifdef OBJ_EDITING_API
            if ( parameterAvailableForEditing == true )
            {
+1 −0
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@
#define FIX_VOIP_FUNCTIONS                              /* VA: fix data type mismatch in IVAS_DEC_VoIP_SetScale() + add sanity checks to API functions */

#define FIX_HRTF_LOAD   /* VA: fix memory issue when HRTFs are loaded from a binary file */
#define FIX_HRTF_LOAD_JBM

/* #################### End BE switches ################################## */

+42 −1
Original line number Diff line number Diff line
@@ -838,11 +838,13 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
    uint16_t *serial,         /* i  : buffer containing serial input bitstream. Each bit should be stored as a single uint16_t value  */
    const uint16_t num_bits,  /* i  : number of bits in input bitstream     */
    int16_t bfi               /* i  : bad frame indicator flag              */
#ifndef FIX_HRTF_LOAD_JBM
#ifdef OBJ_EDITING_API
    ,
    int16_t isSplitRend,
    ISAR_SPLIT_REND_BITS_DATA *splitRendBits
#endif
#endif
)
{
    ivas_error error;
@@ -920,6 +922,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
    hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame;

#ifdef OBJ_EDITING_API
#ifndef FIX_HRTF_LOAD_JBM
#ifdef FIX_HRTF_LOAD // VE: TODO - JBM decoder path to be addressed
    if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
    {
@@ -928,6 +931,8 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
            return error;
        }
    }
#endif
#endif
#else
    /* Decode TCs, do TSM and feed to renderer.
           If TSM is generally enabled, we have to wait for the first good frame.
@@ -1049,7 +1054,6 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
            }
        }
    }
#endif
#endif

    return IVAS_ERR_OK;
@@ -1178,7 +1182,11 @@ ivas_error IVAS_DEC_GetSamplesDecoder(

    /* If TSM is generally enabled, we have to wait for the first good frame.
       Otherwise, we directly decode the first frame in any case. */
#ifdef FIX_HRTF_LOAD_JBM
    if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame )
#else
    if ( ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && hIvasDec->hasBeenFedFirstGoodFrame ) || !hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
#endif
    {
        uint16_t l_ts, nTimeScalerOutSamples;
        uint8_t nTransportChannels, nOutChannels;
@@ -3646,6 +3654,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
    JbmTraceFileWriterFn jbmWriterFn,
    void *jbmWriter
#endif
#ifdef FIX_HRTF_LOAD_JBM
    ,
    bool *bitstreamReadDone
#endif
#ifdef OBJ_EDITING_API
    ,
    uint16_t *nSamplesRendered,
@@ -3769,24 +3781,32 @@ ivas_error IVAS_DEC_VoIP_GetSamples(


                if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0
#ifndef FIX_HRTF_LOAD_JBM
#if defined( OBJ_EDITING_API )
                                                          ,
                                                          0,
                                                          0
#endif
#endif
                                                          ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
#ifdef FIX_HRTF_LOAD_JBM

                *bitstreamReadDone = true;
#endif
            }
            else if ( hIvasDec->hasDecodedFirstGoodFrame )
            {
                /* Decoder has been initialized with first good frame - do PLC */
                if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1
#ifndef FIX_HRTF_LOAD_JBM
#if defined( OBJ_EDITING_API )
                                                          ,
                                                          0,
                                                          0
#endif
#endif
                                                          ) ) != IVAS_ERR_OK )
                {
@@ -3822,6 +3842,14 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
                JB4_FreeDataUnit( hVoIP->hJBM, dataUnit );
            }

#ifdef FIX_HRTF_LOAD_JBM
            if ( hIvasDec->hasBeenFedFirstGoodFrame && *bitstreamReadDone == true )
            {
                /* new bitstream was feeded, return for reconfiguration */
                return IVAS_ERR_OK;
            }

#endif
            if ( !hIvasDec->hasBeenFedFirstGoodFrame )
            {
                hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame;
@@ -3859,6 +3887,19 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
        {
            int16_t nSamplesToRender, nSamplesRendered_loop;
            bool tmp;

#ifdef FIX_HRTF_LOAD_JBM
            if ( hIvasDec->nSamplesAvailableNext == 0 || hIvasDec->nSamplesAvailableNext == hIvasDec->nSamplesFrame )
            {
                if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, 0 ) ) != IVAS_ERR_OK )
                {
                    return error;
                }

                *bitstreamReadDone = false;
            }
#endif

#ifdef OBJ_EDITING_API
            nSamplesToRender = nSamplesPerChannel - *nSamplesRendered;
#else
+6 −0
Original line number Diff line number Diff line
@@ -150,11 +150,13 @@ ivas_error IVAS_DEC_FeedFrame_Serial(
    uint16_t *serial,                           /* i  : buffer containing serial input bitstream. Each bit should be stored as a single uint16_t value  */
    const uint16_t num_bits,                    /* i  : number of bits in input bitstream                                       */
    int16_t bfi                                 /* i  : bad frame indicator flag                                                */
#ifndef FIX_HRTF_LOAD_JBM
#if defined( OBJ_EDITING_API )
    ,
    int16_t isSplitRend,
    ISAR_SPLIT_REND_BITS_DATA *splitRendBits
#endif
#endif
);

#ifdef FIX_HRTF_LOAD
@@ -319,6 +321,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
    , JbmTraceFileWriterFn jbmWriterFn,
    void* jbmWriter
#endif
#ifdef FIX_HRTF_LOAD_JBM
    ,
    bool *bitstreamReadDone
#endif
#ifdef OBJ_EDITING_API
	,
	uint16_t *nSamplesRendered,