From 084a523e0d364f104fd1970a4ebf774eb76b4ab2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 6 Apr 2025 10:38:22 +0200 Subject: [PATCH 01/11] correction and simplification of lib_dec.c; under LIB_DEC_REVISION --- apps/decoder.c | 4 ++ lib_com/options.h | 1 + lib_dec/lib_dec.c | 118 +++++++++++++++++++++++++++++++++++++++++----- lib_dec/lib_dec.h | 3 ++ 4 files changed, 113 insertions(+), 13 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index f35d12fd0d..993150cee7 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -259,7 +259,11 @@ int main( * Open decoder handle *------------------------------------------------------------------------------------------*/ +#ifdef LIB_DEC_REVISION + if ( ( error = IVAS_DEC_Open( &hIvasDec, arg.output_Fs, arg.decMode ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_Open( &hIvasDec, arg.decMode ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; diff --git a/lib_com/options.h b/lib_com/options.h index 92a2e7a0f8..e1cf3d987b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,6 +163,7 @@ #define FIX_1285_RENDER_CONFIG_PTR_COMPARE /* Philips: Warning about pointer comparison in the render config reader */ #define FIX_1298_MEMORY_OPT_IVAS_CORE_ENC /* VA: issue 1298: Memory saving in ivas_core_enc() */ #define SIMPLIFY_IVAS_CORE /* VA: simplify ivas core coder functions */ +#define LIB_DEC_REVISION /* VA: correction and simplification of lib_dec.c */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 52c50f0140..c9dbf21f20 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -55,7 +55,9 @@ struct IVAS_DEC_VOIP { +#ifndef LIB_DEC_REVISION uint16_t nSamplesFrame; /* Total number of samples in a frame (includes number of channels) */ +#endif JB4_HANDLE hJBM; uint16_t lastDecodedWasActive; JB4_DATAUNIT_HANDLE hCurrentDataUnit; /* Points to the currently processed data unit */ @@ -90,7 +92,9 @@ struct IVAS_DEC bool hasBeenFedFrame; bool updateOrientation; uint16_t nSamplesAvailableNext; +#ifndef LIB_DEC_REVISION int16_t nSamplesRendered; +#endif int16_t nTransportChannelsOld; int16_t amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ int16_t sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ @@ -119,8 +123,10 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uin static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels ); static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, float *pcmBuf, int16_t *nOutSamples ); static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const int16_t nSamplesForRendering, int16_t *nSamplesResidual, float *pcmBuf ); +#ifndef LIB_DEC_REVISION static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const uint16_t nSamplesForRendering, uint16_t *nSamplesRendered, uint16_t *nSamplesAvailableNext, const IVAS_DEC_PCM_TYPE pcmType, void *pcmBuf ); static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( IVAS_DEC_HANDLE hIvasDec, int16_t *nSamplesBuffered ); +#endif static PCM_RESOLUTION pcm_type_API_to_internal( const IVAS_DEC_PCM_TYPE pcmType ); static void *pcm_buffer_offset( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, const int32_t offset ); static ivas_error set_pcm_buffer_to_zero( void *buffer, const IVAS_DEC_PCM_TYPE pcmType, const int16_t nZeroSamples ); @@ -141,7 +147,10 @@ static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const int16_t nS /* may return an error but may still have allocated memory - thus run Close also in case of error to release memory */ ivas_error IVAS_DEC_Open( IVAS_DEC_HANDLE *phIvasDec, /* i/o: pointer to an IVAS decoder handle to be opened */ - const IVAS_DEC_MODE mode /* i : compatibility mode (EVS or IVAS) */ +#ifdef LIB_DEC_REVISION + const int32_t output_Fs, /* i : output sampling frequency */ +#endif + const IVAS_DEC_MODE mode /* i : compatibility mode (EVS or IVAS) */ ) { IVAS_DEC_HANDLE hIvasDec; @@ -171,8 +180,12 @@ ivas_error IVAS_DEC_Open( hIvasDec->needNewFrame = false; hIvasDec->nTransportChannelsOld = 0; hIvasDec->nSamplesAvailableNext = 0; +#ifdef LIB_DEC_REVISION + hIvasDec->nSamplesFrame = (uint16_t) ( output_Fs / FRAMES_PER_SEC ); +#else hIvasDec->nSamplesRendered = 0; hIvasDec->nSamplesFrame = 0; +#endif hIvasDec->hasBeenFedFrame = false; hIvasDec->hasBeenFedFirstGoodFrame = false; hIvasDec->hasDecodedFirstGoodFrame = false; @@ -522,6 +535,7 @@ ivas_error IVAS_DEC_Configure( hIvasDec->st_ivas->ivas_format = MONO_FORMAT; } +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesFrame = (uint16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); hIvasDec->nSamplesAvailableNext = 0; hIvasDec->nSamplesRendered = 0; @@ -540,7 +554,7 @@ ivas_error IVAS_DEC_Configure( hIvasDec->pcmType = IVAS_DEC_PCM_INT16; set_s( (int16_t *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); } - +#endif return IVAS_ERR_OK; } @@ -770,7 +784,9 @@ ivas_error IVAS_DEC_EnableVoIP( hIvasDec->hVoIP->lastDecodedWasActive = 0; hIvasDec->hVoIP->hCurrentDataUnit = NULL; +#ifndef LIB_DEC_REVISION hIvasDec->hVoIP->nSamplesFrame = (uint16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); +#endif hIvasDec->hVoIP->nSamplesRendered20ms = 0; #define WMC_TOOL_SKIP @@ -896,7 +912,9 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->needNewFrame = false; hIvasDec->hasBeenFedFrame = true; +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesRendered = 0; +#endif hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; return IVAS_ERR_OK; @@ -1658,9 +1676,12 @@ ivas_error IVAS_DEC_GetSamplesRenderer( ) { ivas_error error; +#ifndef LIB_DEC_REVISION int16_t nSamplesToRender; +#endif uint16_t nSamplesRendered, nSamplesRendered_loop; uint8_t nOutChannels; + Decoder_Struct *st_ivas; nSamplesRendered = 0; nOutChannels = 0; @@ -1677,13 +1698,15 @@ ivas_error IVAS_DEC_GetSamplesRenderer( return IVAS_ERR_UNKNOWN; } + st_ivas = hIvasDec->st_ivas; + if ( hIvasDec->updateOrientation ) { /*----------------------------------------------------------------* * Combine orientations *----------------------------------------------------------------*/ - if ( ( error = combine_external_and_head_orientations_dec( hIvasDec->st_ivas->hHeadTrackData, hIvasDec->st_ivas->hExtOrientationData, hIvasDec->st_ivas->hCombinedOrientationData ) ) != IVAS_ERR_OK ) + if ( ( error = combine_external_and_head_orientations_dec( st_ivas->hHeadTrackData, st_ivas->hExtOrientationData, st_ivas->hCombinedOrientationData ) ) != IVAS_ERR_OK ) { return error; } @@ -1692,9 +1715,9 @@ ivas_error IVAS_DEC_GetSamplesRenderer( * Binaural split rendering setup *----------------------------------------------------------------*/ - if ( hIvasDec->st_ivas->hCombinedOrientationData != NULL && ( hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + if ( st_ivas->hCombinedOrientationData != NULL && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { - isar_set_split_rend_ht_setup( &hIvasDec->st_ivas->hSplitBinRend->splitrend, hIvasDec->st_ivas->hCombinedOrientationData->Quaternions, hIvasDec->st_ivas->hCombinedOrientationData->Rmat ); + isar_set_split_rend_ht_setup( &st_ivas->hSplitBinRend->splitrend, st_ivas->hCombinedOrientationData->Quaternions, st_ivas->hCombinedOrientationData->Rmat ); } hIvasDec->updateOrientation = false; @@ -1710,38 +1733,59 @@ ivas_error IVAS_DEC_GetSamplesRenderer( } /* check if we are still at the beginning with bad frames, put out zeroes, keep track of subframes */ - if ( !hIvasDec->isInitialized && hIvasDec->st_ivas->bfi ) + if ( !hIvasDec->isInitialized && st_ivas->bfi ) { hIvasDec->hasBeenFedFrame = false; - set_s( pcmBuf, 0, hIvasDec->st_ivas->hDecoderConfig->nchan_out * nSamplesAsked ); + set_s( pcmBuf, 0, st_ivas->hDecoderConfig->nchan_out * nSamplesAsked ); +#ifdef LIB_DEC_REVISION + nSamplesRendered = nSamplesAsked; +#else hIvasDec->nSamplesRendered += nSamplesAsked; *nOutSamples = nSamplesAsked; +#endif hIvasDec->nSamplesAvailableNext -= nSamplesAsked; +#ifndef LIB_DEC_REVISION if ( hIvasDec->nSamplesAvailableNext == 0 ) { hIvasDec->needNewFrame = true; *needNewFrame = true; } +#endif } else { - nOutChannels = (uint8_t) hIvasDec->st_ivas->hDecoderConfig->nchan_out; + nOutChannels = (uint8_t) st_ivas->hDecoderConfig->nchan_out; hIvasDec->hasBeenFedFrame = false; + /* check for possible flushed samples from a rate switch */ if ( hIvasDec->nSamplesFlushed > 0 ) { +#ifndef LIB_DEC_REVISION void *pPcmBuffer; +#endif #ifdef DEBUGGING assert( hIvasDec->pcmType == pcmType ); #endif +#ifdef LIB_DEC_REVISION + /* note: offset (rendered samples) is always 0 */ +#else pPcmBuffer = pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ); +#endif if ( pcmType == IVAS_DEC_PCM_INT16 ) { +#ifdef LIB_DEC_REVISION + mvs2s( (int16_t *) hIvasDec->flushbuffer, pcmBuf, hIvasDec->nSamplesFlushed * nOutChannels ); +#else mvs2s( (int16_t *) hIvasDec->flushbuffer, pPcmBuffer, hIvasDec->nSamplesFlushed * nOutChannels ); +#endif } else if ( pcmType == IVAS_DEC_PCM_FLOAT ) { +#ifdef LIB_DEC_REVISION + mvr2r( (float *) hIvasDec->flushbuffer, pcmBuf, hIvasDec->nSamplesFlushed * nOutChannels ); +#else mvr2r( (float *) hIvasDec->flushbuffer, pPcmBuffer, hIvasDec->nSamplesFlushed * nOutChannels ); +#endif } #ifdef DEBUGGING else @@ -1749,18 +1793,27 @@ ivas_error IVAS_DEC_GetSamplesRenderer( assert( 0 && "wrong PCM type for the flush buffer!" ); } #endif +#ifdef LIB_DEC_REVISION + nSamplesRendered = hIvasDec->nSamplesFlushed; +#else nSamplesRendered += hIvasDec->nSamplesFlushed; +#endif hIvasDec->nSamplesFlushed = 0; } /* render IVAS frames directly to the output buffer */ +#ifdef LIB_DEC_REVISION + if ( ( error = ivas_jbm_dec_render( st_ivas, nSamplesAsked - nSamplesRendered, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcm_type_API_to_internal( pcmType ), pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) +#else nSamplesToRender = nSamplesAsked - nSamplesRendered; if ( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) +#endif { return error; } nSamplesRendered += nSamplesRendered_loop; +#ifndef LIB_DEC_REVISION nSamplesToRender -= nSamplesRendered_loop; if ( hIvasDec->nSamplesAvailableNext == 0 ) { @@ -1773,11 +1826,26 @@ ivas_error IVAS_DEC_GetSamplesRenderer( } #ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST *nOutSamples = nSamplesRendered; +#endif #endif } +#ifdef LIB_DEC_REVISION + if ( hIvasDec->nSamplesAvailableNext == 0 ) + { + *needNewFrame = true; + hIvasDec->needNewFrame = true; + } + else + { + *needNewFrame = false; + } + + *nOutSamples = nSamplesRendered; +#else #ifndef NONBE_1293_CRASH_FIRST_FRAME_LOST *nOutSamples = nSamplesRendered; +#endif #endif return IVAS_ERR_OK; @@ -2146,7 +2214,7 @@ static ivas_error IVAS_DEC_RendererFeedTcSamples( return IVAS_ERR_OK; } - +#ifndef LIB_DEC_REVISION /*---------------------------------------------------------------------* * IVAS_DEC_GetRenderedSamples( ) * @@ -2205,7 +2273,7 @@ static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( return IVAS_ERR_OK; } - +#endif /*---------------------------------------------------------------------* * IVAS_DEC_GetNumObjects( ) @@ -3561,17 +3629,25 @@ ivas_error IVAS_DEC_VoIP_GetSamples( nSamplesBuffered = 0; if ( hIvasDec->hasBeenFedFirstGoodFrame ) { +#ifdef LIB_DEC_REVISION + /* check if the TC buffer already exists, otherweise nothing is buffered anyway */ + if ( st_ivas->hTcBuffer != NULL ) + { + nSamplesBuffered = st_ivas->hTcBuffer->n_samples_buffered - st_ivas->hTcBuffer->n_samples_rendered; + nSamplesBuffered += hVoIP->nSamplesRendered20ms; + } +#else if ( ( error = IVAS_DEC_GetBufferedNumberOfSamples( hIvasDec, &nSamplesBuffered ) ) != IVAS_ERR_OK ) { return error; } +#endif } extBufferedSamples = nSamplesBuffered; extBufferedTime_ms = extBufferedSamples * 1000 / hDecoderConfig->output_Fs; dataUnit = NULL; - /* pop one access unit from the jitter buffer */ result = JB4_PopDataUnit( hVoIP->hJBM, systemTimestamp_ms, extBufferedTime_ms, &dataUnit, &scale, &maxScaling ); if ( result != 0 ) @@ -3671,7 +3747,9 @@ ivas_error IVAS_DEC_VoIP_GetSamples( if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesRendered = 0; +#endif } } @@ -3683,8 +3761,9 @@ ivas_error IVAS_DEC_VoIP_GetSamples( int16_t nSamplesToZero = min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext ); set_pcm_buffer_to_zero( pcm_buffer_offset( pcmBuf, pcmType, ( *nSamplesRendered ) * nOutChannels ), pcmType, nSamplesToZero * nOutChannels ); *nSamplesRendered += nSamplesToZero; - +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesRendered += nSamplesToZero; +#endif hIvasDec->nSamplesAvailableNext -= nSamplesToZero; update_voip_rendered20ms( hIvasDec, nSamplesToZero ); } @@ -3741,7 +3820,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( /*---------------------------------------------------------------------* * update_voip_rendered20ms( ) * - * Function to flush remaining audio in VoIP + * Return number of samples that have been rendered since the last 20ms render border *---------------------------------------------------------------------*/ static void update_voip_rendered20ms( @@ -3753,12 +3832,20 @@ static void update_voip_rendered20ms( nSamplesRenderedTotal = hIvasDec->hVoIP->nSamplesRendered20ms + nSamplesRendered; /* we have crossed a 20ms border, reset the time scaling done flag */ +#ifdef LIB_DEC_REVISION + if ( nSamplesRenderedTotal >= hIvasDec->nSamplesFrame ) +#else if ( nSamplesRenderedTotal >= hIvasDec->hVoIP->nSamplesFrame ) +#endif { hIvasDec->timeScalingDone = 0; } +#ifdef LIB_DEC_REVISION + hIvasDec->hVoIP->nSamplesRendered20ms = nSamplesRenderedTotal % hIvasDec->nSamplesFrame; +#else hIvasDec->hVoIP->nSamplesRendered20ms = nSamplesRenderedTotal % hIvasDec->hVoIP->nSamplesFrame; +#endif return; } @@ -3795,12 +3882,17 @@ ivas_error IVAS_DEC_Flush( error = IVAS_ERR_OK; if ( nSamplesToRender > 0 && hIvasDec->st_ivas->ivas_format != MONO_FORMAT ) { +#ifdef LIB_DEC_REVISION + error = ivas_jbm_dec_render( hIvasDec->st_ivas, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmType, pcmBuf ); +#else error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmType, pcmBuf ); +#endif } else { *nSamplesFlushed = 0; } + return error; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index bfe6dd6e0b..de74494d03 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -114,6 +114,9 @@ typedef ivas_error ( *JbmTraceFileWriterFn )( const void *data, void *writer ); /*! r: error code */ ivas_error IVAS_DEC_Open( IVAS_DEC_HANDLE *phIvasDec, /* i/o: pointer to an IVAS decoder handle to be opened */ +#ifdef LIB_DEC_REVISION + const int32_t output_Fs, /* i : output sampling frequency */ +#endif IVAS_DEC_MODE mode /* i : compatibility mode (EVS or IVAS) */ ); -- GitLab From 437b101841ef793ebdb1519c676aa5b631755d3b Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 6 Apr 2025 10:44:47 +0200 Subject: [PATCH 02/11] fix --- lib_dec/lib_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index c9dbf21f20..f81dfe8785 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -3883,7 +3883,7 @@ ivas_error IVAS_DEC_Flush( if ( nSamplesToRender > 0 && hIvasDec->st_ivas->ivas_format != MONO_FORMAT ) { #ifdef LIB_DEC_REVISION - error = ivas_jbm_dec_render( hIvasDec->st_ivas, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmType, pcmBuf ); + error = ivas_jbm_dec_render( hIvasDec->st_ivas, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcm_type_API_to_internal( pcmType ), pcmBuf ); #else error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmType, pcmBuf ); #endif -- GitLab From 4ff7c9c28671e52320245013d66ce92fd39e29bd Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 6 Apr 2025 15:20:19 +0200 Subject: [PATCH 03/11] more updates --- apps/decoder.c | 12 ++- lib_com/options.h | 4 +- lib_dec/lib_dec.c | 235 +++++++++++++++++++++++++++++++++++++++------- lib_dec/lib_dec.h | 3 + 4 files changed, 215 insertions(+), 39 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 993150cee7..1d5e4f9419 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -449,8 +449,14 @@ int main( asked_frame_size = arg.renderFramesize; uint16_t aeID = arg.aeSequence.count > 0 ? arg.aeSequence.pID[0] : 65535; +#ifdef LIB_DEC_REVISION + if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.voipMode, arg.tsmEnabled, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, + arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.non_diegetic_pan_enabled, + arg.non_diegetic_pan_gain, arg.dpidEnabled, aeID, arg.objEditEnabled, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.tsmEnabled, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.non_diegetic_pan_enabled, arg.non_diegetic_pan_gain, arg.dpidEnabled, aeID, arg.objEditEnabled, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -1055,18 +1061,18 @@ static bool parseCmdlIVAS_dec( if ( strcmp( argv_to_upper, "-VOIP" ) == 0 ) { - arg->voipMode = 1; + arg->voipMode = true; i++; } else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=0" ) == 0 ) { - arg->voipMode = 1; + arg->voipMode = true; arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP; i++; } else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=1" ) == 0 ) { - arg->voipMode = 1; + arg->voipMode = true; arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF; i++; } diff --git a/lib_com/options.h b/lib_com/options.h index e1cf3d987b..0eee0b8b5a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -48,7 +48,7 @@ /* ################### Start DEBUGGING switches ########################### */ #ifndef RELEASE -/*#define DEBUGGING*/ /* Activate debugging part of the code */ +#define DEBUGGING /* Activate debugging part of the code */ #endif /*#define WMOPS*/ /* Activate complexity and memory counters */ /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ @@ -132,7 +132,7 @@ /*#define DEBUG_BINAURAL_FILTER_DESIGN*/ /* debugging of Crend binaural filter design */ /*#define DEBUG_AGC_ENCODER_CMD_OPTION*/ /* Ability to force enable or disable AGC behaviour in DIRAC/SPAR via command line option */ /*#define DEBUG_JBM_CMD_OPTION*/ /* ability for telling the decoder the frontend fetch size and to not delay compensate for bad frames at the beginning */ -/*#define VARIABLE_SPEED_DECODING*/ /* variable speed decoding employing the JBM functioniality; move to DEBUGGING after build for disabled is fixed */ +#define VARIABLE_SPEED_DECODING /* variable speed decoding employing the JBM functioniality; move to DEBUGGING after build for disabled is fixed */ /*#define DISABLE_LIMITER*/ /* disable the limiter */ /*Split Rendering Debug switches*/ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index f81dfe8785..fe761cc023 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -116,14 +116,21 @@ static void IVAS_DEC_Close_VoIP( IVAS_DEC_VOIP *hVoIP ); #ifdef SUPPORT_JBM_TRACEFILE static void store_JbmData( IVAS_DEC_VOIP *hVoIP, JB4_DATAUNIT_HANDLE dataUnit, const uint32_t systemTimestamp_ms, const uint16_t extBufferedSamples, const int32_t output_Fs ); #endif +#ifdef LIB_DEC_REVISION +static ivas_error evs_dec_main( Decoder_Struct *st_ivas, float *floatBuf, int16_t *pcmBuf ); +#else static ivas_error evs_dec_main( Decoder_Struct *st_ivas, const int16_t nOutSamples, float *floatBuf, int16_t *pcmBuf ); +#endif static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, int16_t *bitstream_format_internal, int16_t *sdp_hf_only, const bool is_voip_enabled ); static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig ); +#ifdef LIB_DEC_REVISION +static ivas_error ivas_dec_setup_all( IVAS_DEC_HANDLE hIvasDec, uint8_t *nTransportChannels, const int16_t isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits ); +static ivas_error apa_setup( IVAS_DEC_HANDLE hIvasDec, const bool isInitialized_voip, const uint16_t nTransportChannels ); +#else static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uint16_t nTransportChannels, const uint16_t l_ts ); static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels ); static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, float *pcmBuf, int16_t *nOutSamples ); static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const int16_t nSamplesForRendering, int16_t *nSamplesResidual, float *pcmBuf ); -#ifndef LIB_DEC_REVISION static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const uint16_t nSamplesForRendering, uint16_t *nSamplesRendered, uint16_t *nSamplesAvailableNext, const IVAS_DEC_PCM_TYPE pcmType, void *pcmBuf ); static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( IVAS_DEC_HANDLE hIvasDec, int16_t *nSamplesBuffered ); #endif @@ -426,9 +433,12 @@ static IVAS_DEC_BS_FORMAT mapIvasFormat( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_Configure( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const uint32_t sampleRate, /* i : output sampling frequency */ - const AUDIO_CONFIG outputConfig, /* i : output configuration */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const uint32_t sampleRate, /* i : output sampling frequency */ + const AUDIO_CONFIG outputConfig, /* i : output configuration */ +#ifdef LIB_DEC_REVISION + const bool voipMode, /* i : enable VoIP mode with JBM */ +#endif const bool tsmEnabled, /* i : enable TSM */ const IVAS_RENDER_FRAMESIZE renderFramesize, /* i : rendering frame size */ const bool customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ @@ -542,9 +552,14 @@ ivas_error IVAS_DEC_Configure( hIvasDec->tsm_scale = 100; hIvasDec->tsm_max_scaling = 0; hIvasDec->tsm_quality = 1.0f; - - /* init flush buffer if necessary (only needed for binaural)*/ +#endif +#ifdef LIB_DEC_REVISION + /* Create flush buffer - needed for binaural outputs with TSM or in VoIP mode */ + if ( ( tsmEnabled || voipMode ) && ( outputConfig == IVAS_AUDIO_CONFIG_BINAURAL || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) +#else + /* Init flush buffer if necessary (only needed for binaural)*/ if ( tsmEnabled && ( outputConfig == IVAS_AUDIO_CONFIG_BINAURAL || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) +#endif { hIvasDec->flushbuffer = (void *) malloc( CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( int16_t ) ); if ( hIvasDec->flushbuffer == NULL ) @@ -554,7 +569,7 @@ ivas_error IVAS_DEC_Configure( hIvasDec->pcmType = IVAS_DEC_PCM_INT16; set_s( (int16_t *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); } -#endif + return IVAS_ERR_OK; } @@ -816,6 +831,7 @@ ivas_error IVAS_DEC_EnableVoIP( } #endif +#ifndef LIB_DEC_REVISION /* init flush buffer if necessary (only needed for binaural)*/ if ( hIvasDec->flushbuffer == NULL && ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { @@ -823,7 +839,7 @@ ivas_error IVAS_DEC_EnableVoIP( hIvasDec->pcmType = IVAS_DEC_PCM_INT16; set_s( (int16_t *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); } - +#endif return IVAS_ERR_OK; } @@ -1096,7 +1112,7 @@ ivas_error IVAS_DEC_ReadFormat( /*---------------------------------------------------------------------* * IVAS_DEC_GetSamplesDecoder( ) * - * Main function to decode transport channels, do TSM and feed to renderer. + * Main function to run setup, decode transport channels, do TSM and feed to renderer. *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetSamplesDecoder( @@ -1106,6 +1122,13 @@ ivas_error IVAS_DEC_GetSamplesDecoder( ) { ivas_error error; + Decoder_Struct *st_ivas; +#ifdef LIB_DEC_REVISION + uint16_t nTimeScalerOutSamples; + uint8_t nTransportChannels; + int16_t nResidualSamples, nSamplesTcsScaled; + bool isInitialized_voip; +#endif if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { @@ -1119,17 +1142,27 @@ ivas_error IVAS_DEC_GetSamplesDecoder( } #endif - /* 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->isInitialized || hIvasDec->hasBeenFedFrame ) + st_ivas = hIvasDec->st_ivas; +#ifdef LIB_DEC_REVISION + isInitialized_voip = hIvasDec->isInitialized; +#endif + + if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) /* wait for the first good frame */ { +#ifdef LIB_DEC_REVISION + /* Setup all decoder parts (IVAS decoder, ISAR) */ + if ( ( error = ivas_dec_setup_all( hIvasDec, &nTransportChannels, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK ) + { + return error; + } +#else uint16_t l_ts, nTimeScalerOutSamples; uint8_t nTransportChannels; 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 ) + if ( ( error = isar_set_split_rend_setup( st_ivas->hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK ) { return error; } @@ -1140,23 +1173,58 @@ ivas_error IVAS_DEC_GetSamplesDecoder( return error; } - if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && nTransportChannels != hIvasDec->nTransportChannelsOld ) + if ( st_ivas->hDecoderConfig->Opt_tsm && nTransportChannels != hIvasDec->nTransportChannelsOld ) { if ( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ) != IVAS_ERR_OK ) { return error; } } +#endif /* IVAS TC decoder */ +#ifdef LIB_DEC_REVISION + if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) + { + if ( ( error = evs_dec_main( st_ivas, hIvasDec->apaExecBuffer, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( hIvasDec->mode == IVAS_DEC_MODE_IVAS ) + { + if ( ( error = ivas_jbm_dec_tc( st_ivas, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK ) + { + return error; + } + + hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */ + } + + if ( hIvasDec->hasBeenFedFirstGoodFrame ) + { + hIvasDec->hasDecodedFirstGoodFrame = true; + } +#else if ( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK ) { return error; } +#endif /* JBM */ - if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) + if ( st_ivas->hDecoderConfig->Opt_tsm ) { +#ifdef LIB_DEC_REVISION + if ( nTransportChannels != hIvasDec->nTransportChannelsOld ) + { + if ( ( error = apa_setup( hIvasDec, isInitialized_voip, nTransportChannels ) ) != IVAS_ERR_OK ) + { + return error; + } + } + +#endif if ( apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 ) { return IVAS_ERR_UNKNOWN; @@ -1177,12 +1245,16 @@ ivas_error IVAS_DEC_GetSamplesDecoder( } /* Feed decoded transport channels samples to the renderer */ +#ifdef LIB_DEC_REVISION + ivas_jbm_dec_feed_tc_to_renderer( st_ivas, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ); +#else if ( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK ) { return error; } +#endif - if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) + if ( 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 ) @@ -1195,15 +1267,16 @@ ivas_error IVAS_DEC_GetSamplesDecoder( hIvasDec->hasBeenPreparedRendering = false; - if ( hIvasDec->st_ivas->hIsmMetaData[0] ) + /* set edited metadata */ + if ( 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 ) + if ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) { - 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 ) + if ( st_ivas->ism_mode == ISM_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { int16_t obj; - ISM_METADATA_HANDLE *hIsmMetaData = hIvasDec->st_ivas->hIsmMetaData; - for ( obj = 0; obj < hIvasDec->st_ivas->nchan_ism; obj++ ) + ISM_METADATA_HANDLE *hIsmMetaData = st_ivas->hIsmMetaData; + for ( obj = 0; obj < st_ivas->nchan_ism; obj++ ) { hIsmMetaData[obj]->edited_azimuth = hIsmMetaData[obj]->azimuth; hIsmMetaData[obj]->edited_elevation = hIsmMetaData[obj]->elevation; @@ -1213,21 +1286,21 @@ ivas_error IVAS_DEC_GetSamplesDecoder( hIsmMetaData[obj]->edited_gain = 1.0f; } - if ( hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { - hIvasDec->st_ivas->hSbaIsmData->gain_bed = 1.0f; + st_ivas->hSbaIsmData->gain_bed = 1.0f; } } } } - if ( hIvasDec->st_ivas->hParamIsmDec != NULL ) + if ( st_ivas->hParamIsmDec != NULL ) { - if ( hIvasDec->st_ivas->ism_mode == ISM_MODE_PARAM ) + if ( 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++ ) + PARAM_ISM_DEC_HANDLE hParamIsmDec = st_ivas->hParamIsmDec; + for ( obj = 0; obj < st_ivas->nchan_ism; obj++ ) { hParamIsmDec->edited_azimuth_values[obj] = hParamIsmDec->azimuth_values[obj]; hParamIsmDec->edited_elevation_values[obj] = hParamIsmDec->elevation_values[obj]; @@ -1339,7 +1412,7 @@ ivas_error IVAS_DEC_GetEditableParameters( hIvasEditableParameters->ism_metadata[obj].radius = st_ivas->hIsmMetaData[obj]->radius; /* reset the otherwise unused "gain" field for the object */ - hIvasDec->st_ivas->hIsmMetaData[obj]->edited_gain = 1.0f; + st_ivas->hIsmMetaData[obj]->edited_gain = 1.0f; hIvasEditableParameters->ism_metadata[obj].gain = st_ivas->hIsmMetaData[obj]->edited_gain; hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = st_ivas->hIsmMetaData[obj]->non_diegetic_flag; } @@ -1366,7 +1439,7 @@ ivas_error IVAS_DEC_GetEditableParameters( hIvasEditableParameters->ism_metadata[obj].radius = st_ivas->hIsmMetaData[obj]->radius; /* reset the otherwise unused "gain" field for the object */ - hIvasDec->st_ivas->hIsmMetaData[obj]->edited_gain = 1.0f; + st_ivas->hIsmMetaData[obj]->edited_gain = 1.0f; hIvasEditableParameters->ism_metadata[obj].gain = st_ivas->hIsmMetaData[obj]->edited_gain; hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = st_ivas->hIsmMetaData[obj]->non_diegetic_flag; } @@ -1915,8 +1988,8 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( } if ( st_ivas->hDecoderConfig->render_framesize != IVAS_RENDER_FRAMESIZE_20MS && - ( hIvasDec->st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE || - hIvasDec->st_ivas->hRenderConfig->split_rend_config.dof == 0 ) ) + ( st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE || + st_ivas->hRenderConfig->split_rend_config.dof == 0 ) ) { numSamplesPerChannelToDecode = (int16_t) ( output_Fs / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ); numSamplesPerChannelToDecode *= (int16_t) st_ivas->hDecoderConfig->render_framesize; @@ -2059,6 +2132,23 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( } +#ifdef LIB_DEC_REVISION +/*---------------------------------------------------------------------* + * ivas_dec_setup_all() + * + * Set-up all decoder parts: IVAS decoder, ISAR + *---------------------------------------------------------------------*/ + +static ivas_error ivas_dec_setup_all( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ +#ifndef LIB_DEC_REVISION + uint16_t *nTcBufferGranularity, /* o : granularity of the TC Buffer */ +#endif + uint8_t *nTransportChannels, /* o : number of decoded transport PCM channels */ + const int16_t isSplitRend, /* i : split rendering enabled flag */ + ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ +) +#else /*---------------------------------------------------------------------* * IVAS_DEC_Setup( ) * @@ -2070,6 +2160,7 @@ static ivas_error IVAS_DEC_Setup( uint16_t *nTcBufferGranularity, /* o : granularity of the TC Buffer */ uint8_t *nTransportChannels /* o : number of decoded transport PCM channels */ ) +#endif { ivas_error error; @@ -2090,6 +2181,16 @@ static ivas_error IVAS_DEC_Setup( st_ivas = hIvasDec->st_ivas; +#ifdef LIB_DEC_REVISION + /* Setup IVAS split rendering */ + if ( isSplitRend ) + { + if ( ( error = isar_set_split_rend_setup( st_ivas->hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif /*----------------------------------------------------------------* * IVAS decoder setup * - read IVAS format signaling @@ -2107,14 +2208,40 @@ static ivas_error IVAS_DEC_Setup( } *nTransportChannels = (uint8_t) st_ivas->hTcBuffer->nchan_transport_jbm; +#ifndef LIB_DEC_REVISION *nTcBufferGranularity = (uint16_t) st_ivas->hTcBuffer->n_samples_granularity; +#endif + +#ifdef LIB_DEC_REVISION + /* allocate/reallocte APA buffer */ + // ToDo: this memory should be harmonized with st_ivas->p_output_f[] and st_ivas->hTcBuffer->tc_buffer[] - see issue #104 + // ToDo: this part is also related to cleaning of NONBE_UNIFIED_DECODING_PATHS leftovers (see MR !1246) + if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && *nTransportChannels != hIvasDec->nTransportChannelsOld ) + { + if ( hIvasDec->apaExecBuffer != NULL ) + { + free( hIvasDec->apaExecBuffer ); + } + + if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * APA_BUF_PER_CHANNEL * *nTransportChannels ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); + } + set_zero( hIvasDec->apaExecBuffer, APA_BUF_PER_CHANNEL * *nTransportChannels ); + } +#endif /*-----------------------------------------------------------------* * ISAR: * - initialize ISAR handle at the first frame * - reconfigure the ISAR handle in case of bitrate switching (renderer might change) *-----------------------------------------------------------------*/ + +#ifdef LIB_DEC_REVISION + if ( st_ivas->ini_frame == 0 && isSplitRend ) +#else if ( st_ivas->ini_frame == 0 && ( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) ) ) +#endif { if ( ( error = ivas_dec_init_split_rend( st_ivas ) ) != IVAS_ERR_OK ) { @@ -2134,7 +2261,7 @@ static ivas_error IVAS_DEC_Setup( return IVAS_ERR_OK; } - +#ifndef LIB_DEC_REVISION /*---------------------------------------------------------------------* * IVAS_DEC_GetTcSamples( ) * @@ -2214,7 +2341,7 @@ static ivas_error IVAS_DEC_RendererFeedTcSamples( return IVAS_ERR_OK; } -#ifndef LIB_DEC_REVISION + /*---------------------------------------------------------------------* * IVAS_DEC_GetRenderedSamples( ) * @@ -3779,7 +3906,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { uint16_t nSamplesFlushed_ref = hIvasDec->nSamplesFlushed; - if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, NULL ) ) != IVAS_ERR_OK ) { return error; } @@ -4341,7 +4468,9 @@ void IVAS_DEC_PrintDisclaimer( void ) static ivas_error evs_dec_main( Decoder_Struct *st_ivas, +#ifndef LIB_DEC_REVISION const int16_t nOutSamples, +#endif float *floatBuf, int16_t *pcmBuf ) { @@ -4349,6 +4478,9 @@ static ivas_error evs_dec_main( float mixer_left, mixer_rigth; float *p_output[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN]; int16_t ch; +#ifdef LIB_DEC_REVISION + int16_t nOutSamples; +#endif ivas_error error; hCoreCoder = st_ivas->hSCE[0]->hCoreCoder; @@ -4405,6 +4537,10 @@ static ivas_error evs_dec_main( } st_ivas->BER_detect = hCoreCoder[0]->BER_detect; +#ifdef LIB_DEC_REVISION + + nOutSamples = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); +#endif if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ) { @@ -4637,6 +4773,18 @@ static ivas_error input_format_API_to_internal( } +#ifdef LIB_DEC_REVISION +/*---------------------------------------------------------------------* + * apa_setup() + * + * Setup APA decoder + *---------------------------------------------------------------------*/ + +static ivas_error apa_setup( + IVAS_DEC_HANDLE hIvasDec, + const bool isInitialized_voip, + const uint16_t nTransportChannels ) +#else /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_reconfigure() * @@ -4647,22 +4795,35 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uint16_t nTransportChannels, const uint16_t l_ts ) +#endif { +#ifdef LIB_DEC_REVISION + uint16_t l_ts; + + l_ts = (uint16_t) hIvasDec->st_ivas->hTcBuffer->n_samples_granularity; + + if ( isInitialized_voip == false ) +#else int16_t apa_buffer_size; apa_buffer_size = hIvasDec->nSamplesFrame; if ( hIvasDec->apaExecBuffer == NULL ) +#endif { DECODER_CONFIG_HANDLE hDecoderConfig; +#ifndef LIB_DEC_REVISION if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { +#endif uint16_t wss, css; float startQuality; startQuality = hIvasDec->tsm_quality; +#ifndef LIB_DEC_REVISION apa_buffer_size = APA_BUF_PER_CHANNEL; +#endif /* get current renderer type*/ hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig; @@ -4708,6 +4869,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( return IVAS_ERR_INIT_ERROR; } } +#ifndef LIB_DEC_REVISION if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL ) { @@ -4716,15 +4878,19 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels ); } +#endif } else { +#ifndef LIB_DEC_REVISION if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { +#endif if ( apa_reconfigure( hIvasDec->hTimeScaler, nTransportChannels, l_ts ) != 0 ) { return IVAS_ERR_INIT_ERROR; } +#ifndef LIB_DEC_REVISION apa_buffer_size = APA_BUF_PER_CHANNEL; free( hIvasDec->apaExecBuffer ); if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL ) @@ -4734,6 +4900,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels ); } /* realloc apa_exe_buffer */ +#endif } hIvasDec->nTransportChannelsOld = nTransportChannels; diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index de74494d03..5f3e65f1d6 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -125,6 +125,9 @@ ivas_error IVAS_DEC_Configure( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const uint32_t sampleRate, /* i : output sampling frequency */ const IVAS_AUDIO_CONFIG outputConfig, /* i : audio configuration */ +#ifdef LIB_DEC_REVISION + const bool voipMode, /* i : enable VoIP mode with JBM */ +#endif const bool tsmEnabled, /* i : enable TSM */ const IVAS_RENDER_FRAMESIZE renderFramesize,/* i : rendering frame size */ const bool customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ -- GitLab From ff871758d2e0435078c75e210e45ffb94958da5e Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 6 Apr 2025 15:48:10 +0200 Subject: [PATCH 04/11] comments; fix EVS VoIP --- apps/decoder.c | 4 ++++ lib_com/options.h | 2 +- lib_dec/lib_dec.c | 47 ++++++++++++++++++++++------------------------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 1d5e4f9419..84dffb01a6 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1222,6 +1222,10 @@ static bool parseCmdlIVAS_dec( { if ( !is_digits_only( argv[i] ) ) { +#ifdef LIB_DEC_REVISION + fprintf( stderr, "Error: Render frame size not specified!\n\n" ); + usage_dec(); +#endif return false; } diff --git a/lib_com/options.h b/lib_com/options.h index 0eee0b8b5a..d16b82ce80 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,7 +163,7 @@ #define FIX_1285_RENDER_CONFIG_PTR_COMPARE /* Philips: Warning about pointer comparison in the render config reader */ #define FIX_1298_MEMORY_OPT_IVAS_CORE_ENC /* VA: issue 1298: Memory saving in ivas_core_enc() */ #define SIMPLIFY_IVAS_CORE /* VA: simplify ivas core coder functions */ -#define LIB_DEC_REVISION /* VA: correction and simplification of lib_dec.c */ +#define LIB_DEC_REVISION /* VA: cleaning and simplification of lib_dec.c */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index fe761cc023..2ba695e46c 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1144,7 +1144,7 @@ ivas_error IVAS_DEC_GetSamplesDecoder( st_ivas = hIvasDec->st_ivas; #ifdef LIB_DEC_REVISION - isInitialized_voip = hIvasDec->isInitialized; + isInitialized_voip = hIvasDec->apaExecBuffer != NULL; #endif if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) /* wait for the first good frame */ @@ -2140,10 +2140,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( *---------------------------------------------------------------------*/ static ivas_error ivas_dec_setup_all( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ -#ifndef LIB_DEC_REVISION - uint16_t *nTcBufferGranularity, /* o : granularity of the TC Buffer */ -#endif + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ uint8_t *nTransportChannels, /* o : number of decoded transport PCM channels */ const int16_t isSplitRend, /* i : split rendering enabled flag */ ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ @@ -2212,25 +2209,6 @@ static ivas_error IVAS_DEC_Setup( *nTcBufferGranularity = (uint16_t) st_ivas->hTcBuffer->n_samples_granularity; #endif -#ifdef LIB_DEC_REVISION - /* allocate/reallocte APA buffer */ - // ToDo: this memory should be harmonized with st_ivas->p_output_f[] and st_ivas->hTcBuffer->tc_buffer[] - see issue #104 - // ToDo: this part is also related to cleaning of NONBE_UNIFIED_DECODING_PATHS leftovers (see MR !1246) - if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && *nTransportChannels != hIvasDec->nTransportChannelsOld ) - { - if ( hIvasDec->apaExecBuffer != NULL ) - { - free( hIvasDec->apaExecBuffer ); - } - - if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * APA_BUF_PER_CHANNEL * *nTransportChannels ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); - } - set_zero( hIvasDec->apaExecBuffer, APA_BUF_PER_CHANNEL * *nTransportChannels ); - } -#endif - /*-----------------------------------------------------------------* * ISAR: * - initialize ISAR handle at the first frame @@ -2258,6 +2236,25 @@ static ivas_error IVAS_DEC_Setup( } } +#ifdef LIB_DEC_REVISION + /* allocate/reallocate APA buffer */ + // ToDo: this memory should be harmonized with st_ivas->p_output_f[] and st_ivas->hTcBuffer->tc_buffer[] - see issue #916 + // ToDo: this part is also related to cleaning of NONBE_UNIFIED_DECODING_PATHS leftovers (see MR !1246) + if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && *nTransportChannels != hIvasDec->nTransportChannelsOld ) + { + if ( hIvasDec->apaExecBuffer != NULL ) + { + free( hIvasDec->apaExecBuffer ); + } + + if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * APA_BUF_PER_CHANNEL * *nTransportChannels ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); + } + set_zero( hIvasDec->apaExecBuffer, APA_BUF_PER_CHANNEL * *nTransportChannels ); + } + +#endif return IVAS_ERR_OK; } @@ -4812,8 +4809,8 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( #endif { DECODER_CONFIG_HANDLE hDecoderConfig; - #ifndef LIB_DEC_REVISION + if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { #endif -- GitLab From 8807eab6f873dcb5119e44031923c4a26bc419bf Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 6 Apr 2025 16:41:10 +0200 Subject: [PATCH 05/11] disable DEBUGGING --- lib_com/options.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index d16b82ce80..bf154bfdd1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -48,7 +48,7 @@ /* ################### Start DEBUGGING switches ########################### */ #ifndef RELEASE -#define DEBUGGING /* Activate debugging part of the code */ +/*#define DEBUGGING*/ /* Activate debugging part of the code */ #endif /*#define WMOPS*/ /* Activate complexity and memory counters */ /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ @@ -132,7 +132,7 @@ /*#define DEBUG_BINAURAL_FILTER_DESIGN*/ /* debugging of Crend binaural filter design */ /*#define DEBUG_AGC_ENCODER_CMD_OPTION*/ /* Ability to force enable or disable AGC behaviour in DIRAC/SPAR via command line option */ /*#define DEBUG_JBM_CMD_OPTION*/ /* ability for telling the decoder the frontend fetch size and to not delay compensate for bad frames at the beginning */ -#define VARIABLE_SPEED_DECODING /* variable speed decoding employing the JBM functioniality; move to DEBUGGING after build for disabled is fixed */ +/*#define VARIABLE_SPEED_DECODING*/ /* variable speed decoding employing the JBM functioniality; move to DEBUGGING after build for disabled is fixed */ /*#define DISABLE_LIMITER*/ /* disable the limiter */ /*Split Rendering Debug switches*/ -- GitLab From 9cb5d2cee13668bd8596e085e77568cbf47379cb Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 7 Apr 2025 11:27:53 +0200 Subject: [PATCH 06/11] replace IVAS_DEC_GetPcmFrameSize() by IVAS_DEC_GetOutputBufferSize(); revision of function description; formatting --- apps/decoder.c | 35 +++++++- lib_dec/lib_dec.c | 208 ++++++++++++++++++++++++++++------------------ lib_dec/lib_dec.h | 3 +- 3 files changed, 163 insertions(+), 83 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 84dffb01a6..5607d6a4ea 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -760,6 +760,13 @@ int main( } pcmBuf = malloc( pcmBufSize * sizeof( int16_t ) ); +#ifdef LIB_DEC_REVISION + if ( pcmBuf == NULL ) + { + fprintf( stdout, "Error: Unable to allocate memory for output buffer.\n" ); + goto cleanup; + } +#endif /*-----------------------------------------------------------------* * Decoding @@ -1807,14 +1814,16 @@ static ivas_error initOnFirstGoodFrame( return error; } +#ifndef LIB_DEC_REVISION int32_t pcmFrameSize; if ( ( error = IVAS_DEC_GetPcmFrameSize( hIvasDec, &pcmFrameSize ) ) != IVAS_ERR_OK ) + { fprintf( stderr, "\nError in IVAS_DEC_GetPcmFrameSize, error code: %d\n", error ); return error; } - +#endif if ( isSplitRend ) { /* Open split rendering metadata writer */ @@ -1872,7 +1881,23 @@ static ivas_error initOnFirstGoodFrame( } } +#ifdef LIB_DEC_REVISION + int16_t pcmFrameSize; + if ( ( error = IVAS_DEC_GetOutputBufferSize( hIvasDec, &pcmFrameSize ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetOutputBufferSize, error code: %d\n", error ); + return error; + } + +#endif int16_t *zeroBuf = malloc( pcmFrameSize * sizeof( int16_t ) ); +#ifdef LIB_DEC_REVISION + if ( zeroBuf == NULL ) + { + fprintf( stdout, "Error: Unable to allocate memory for output buffer.\n" ); + return IVAS_ERR_FAILED_ALLOC; + } +#endif memset( zeroBuf, 0, pcmFrameSize * sizeof( int16_t ) ); for ( int16_t i = 0; i < numInitialBadFrames; ++i ) @@ -3400,7 +3425,12 @@ static ivas_error decodeVoIP( { if ( ( error = IVAS_DEC_HasDecodedFirstGoodFrame( hIvasDec, &decodedGoodFrame ) ) != IVAS_ERR_OK ) { +#ifdef LIB_DEC_REVISION + fprintf( stderr, "Error in IVAS_DEC_HasDecodedFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); +#else fprintf( stderr, "Error in IVAS_DEC_HasDecodedFirstGoodFrame, code: %d\n", error ); + +#endif goto cleanup; } @@ -3412,6 +3442,9 @@ static ivas_error decodeVoIP( if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, NULL, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) { +#ifdef LIB_DEC_REVISION + fprintf( stderr, "Error in initOnFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); +#endif goto cleanup; } } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 2ba695e46c..6f7b69651c 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -112,7 +112,11 @@ struct IVAS_DEC * Local function declarations *---------------------------------------------------------------------*/ +#ifdef LIB_DEC_REVISION +static void ivas_destroy_handle_VoIP( IVAS_DEC_VOIP *hVoIP ); +#else static void IVAS_DEC_Close_VoIP( IVAS_DEC_VOIP *hVoIP ); +#endif #ifdef SUPPORT_JBM_TRACEFILE static void store_JbmData( IVAS_DEC_VOIP *hVoIP, JB4_DATAUNIT_HANDLE dataUnit, const uint32_t systemTimestamp_ms, const uint16_t extBufferedSamples, const int32_t output_Fs ); #endif @@ -145,6 +149,7 @@ static void ivas_destroy_handle_isar( ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplit static int16_t get_render_frame_size_ms( IVAS_RENDER_FRAMESIZE render_framesize ); static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const int16_t nSamplesRendered ); + /*---------------------------------------------------------------------* * IVAS_DEC_Open() * @@ -176,6 +181,7 @@ ivas_error IVAS_DEC_Open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" ); } + hIvasDec = *phIvasDec; hIvasDec->hVoIP = NULL; hIvasDec->apaExecBuffer = NULL; @@ -308,6 +314,7 @@ static ivas_error isar_set_split_rend_setup( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * init_decoder_config() * @@ -342,7 +349,7 @@ static void init_decoder_config( /*---------------------------------------------------------------------* * IVAS_DEC_Close( ) * - * + * Deallocate IVAS decoder memory handles *---------------------------------------------------------------------*/ void IVAS_DEC_Close( @@ -357,7 +364,11 @@ void IVAS_DEC_Close( if ( ( *phIvasDec )->hVoIP ) { +#ifdef LIB_DEC_REVISION + ivas_destroy_handle_VoIP( ( *phIvasDec )->hVoIP ); +#else IVAS_DEC_Close_VoIP( ( *phIvasDec )->hVoIP ); +#endif ( *phIvasDec )->hVoIP = NULL; } @@ -429,7 +440,7 @@ static IVAS_DEC_BS_FORMAT mapIvasFormat( * IVAS_DEC_Configure( ) * * Decoder configuration - * legacy code behavior: if no output format set, then it's EVS mono + * legacy behavior: if no output format set, then it's EVS mono *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_Configure( @@ -516,6 +527,7 @@ ivas_error IVAS_DEC_Configure( { return IVAS_ERR_WRONG_PARAMS; } + if ( outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) { hDecoderConfig->render_framesize = IVAS_RENDER_FRAMESIZE_20MS; @@ -577,7 +589,7 @@ ivas_error IVAS_DEC_Configure( /*---------------------------------------------------------------------* * IVAS_DEC_EnableSplitRendering( ) * - * Intitialize Split rendering + * Update IVAS decoder config. if Split rendering is enabled *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_EnableSplitRendering( @@ -603,7 +615,7 @@ ivas_error IVAS_DEC_EnableSplitRendering( /*---------------------------------------------------------------------* * get_render_framesize_ms( ) * - * Get the 5ms flag + * Get render framesize in ms *---------------------------------------------------------------------*/ static int16_t get_render_frame_size_ms( @@ -616,7 +628,7 @@ static int16_t get_render_frame_size_ms( /*---------------------------------------------------------------------* * IVAS_DEC_SetRenderFramesize( ) * - * Get the 5ms flag + * Set render framesize *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_SetRenderFramesize( @@ -635,6 +647,7 @@ ivas_error IVAS_DEC_SetRenderFramesize( { hIvasDec->st_ivas->hExtOrientationData->num_subframes = (int16_t) render_framesize; } + if ( hIvasDec->st_ivas->hCombinedOrientationData != NULL ) { hIvasDec->st_ivas->hCombinedOrientationData->num_subframes = (int16_t) render_framesize; @@ -647,7 +660,7 @@ ivas_error IVAS_DEC_SetRenderFramesize( /*---------------------------------------------------------------------* * IVAS_DEC_GetGetRenderFramesize( ) * - * Get the 5ms flag + * Get render framesize *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetRenderFramesize( @@ -665,6 +678,7 @@ ivas_error IVAS_DEC_GetRenderFramesize( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetGetRenderFramesizeSamples( ) * @@ -686,6 +700,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetGetRenderFramesizeMs( ) * @@ -707,6 +722,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeMs( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetGetReferencesUpdateFrequency( ) * @@ -728,10 +744,11 @@ ivas_error IVAS_DEC_GetReferencesUpdateFrequency( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetGetNumOrientationSubframes( ) * - * Get the number of subframes for head/ecernal orientation per render frame + * Get the number of subframes for head/external orientation per render frame *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetNumOrientationSubframes( @@ -910,6 +927,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( bfi = 2; } } + if ( ( error = read_indices( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ) ) != IVAS_ERR_OK ) { return error; @@ -1150,7 +1168,10 @@ ivas_error IVAS_DEC_GetSamplesDecoder( if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) /* wait for the first good frame */ { #ifdef LIB_DEC_REVISION - /* Setup all decoder parts (IVAS decoder, ISAR) */ + /*-----------------------------------------------------------------* + * Setup all decoder parts (IVAS decoder, ISAR) + *-----------------------------------------------------------------*/ + if ( ( error = ivas_dec_setup_all( hIvasDec, &nTransportChannels, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK ) { return error; @@ -1182,8 +1203,11 @@ ivas_error IVAS_DEC_GetSamplesDecoder( } #endif - /* IVAS TC decoder */ #ifdef LIB_DEC_REVISION + /*-----------------------------------------------------------------* + * IVAS decoder: decode transport channels and metadata + *-----------------------------------------------------------------*/ + if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) { if ( ( error = evs_dec_main( st_ivas, hIvasDec->apaExecBuffer, NULL ) ) != IVAS_ERR_OK ) @@ -1206,13 +1230,17 @@ ivas_error IVAS_DEC_GetSamplesDecoder( hIvasDec->hasDecodedFirstGoodFrame = true; } #else + /* IVAS TC decoder */ if ( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK ) { return error; } #endif - /* JBM */ + /*-----------------------------------------------------------------* + * JBM + *-----------------------------------------------------------------*/ + if ( st_ivas->hDecoderConfig->Opt_tsm ) { #ifdef LIB_DEC_REVISION @@ -1244,7 +1272,10 @@ ivas_error IVAS_DEC_GetSamplesDecoder( nSamplesTcsScaled = hIvasDec->nSamplesFrame; } - /* Feed decoded transport channels samples to the renderer */ + /*-----------------------------------------------------------------* + * Feed decoded transport channels samples to the renderer + *-----------------------------------------------------------------*/ + #ifdef LIB_DEC_REVISION ivas_jbm_dec_feed_tc_to_renderer( st_ivas, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ); #else @@ -1267,7 +1298,10 @@ ivas_error IVAS_DEC_GetSamplesDecoder( hIvasDec->hasBeenPreparedRendering = false; - /* set edited metadata */ + /*-----------------------------------------------------------------* + * Set editable metadata + *-----------------------------------------------------------------*/ + if ( st_ivas->hIsmMetaData[0] ) { if ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) @@ -1315,7 +1349,7 @@ ivas_error IVAS_DEC_GetSamplesDecoder( /*---------------------------------------------------------------------* * IVAS_DEC_GetEditableParameters( ) * - * + * Get editable metadata parameters *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetEditableParameters( @@ -1463,7 +1497,7 @@ ivas_error IVAS_DEC_GetEditableParameters( /*---------------------------------------------------------------------* * IVAS_DEC_SetEditableParameters( ) * - * Main function to decode to PCM data + * Set editable metadata parameters *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_SetEditableParameters( @@ -1928,7 +1962,7 @@ ivas_error IVAS_DEC_GetSamplesRenderer( /*---------------------------------------------------------------------* * IVAS_DEC_GetSplitBinauralBitstream( ) * - * + * Get split-rendering bitstream *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetSplitBinauralBitstream( @@ -2187,6 +2221,7 @@ static ivas_error IVAS_DEC_Setup( return error; } } + #endif /*----------------------------------------------------------------* * IVAS decoder setup @@ -2425,6 +2460,7 @@ ivas_error IVAS_DEC_GetNumObjects( is_masa_ism = 1; } } + if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == SBA_ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT || is_masa_ism ) { *numObjects = hIvasDec->st_ivas->nchan_ism; @@ -2476,7 +2512,7 @@ ivas_error IVAS_DEC_GetFormat( /*---------------------------------------------------------------------* * getInputBufferSize() * - * + * Get size of output buffer in samples *---------------------------------------------------------------------*/ static int16_t getOutputBufferSize( @@ -2511,7 +2547,7 @@ static int16_t getOutputBufferSize( /*---------------------------------------------------------------------* * IVAS_DEC_GetOutputBufferSize() * - * + * Returns size of output buffer in samples *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetOutputBufferSize( @@ -2573,10 +2609,10 @@ ivas_error IVAS_DEC_GetNumOutputChannels( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetObjectMetadata( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_ISM_METADATA *metadata, /* o : struct where metadata decoded in most recently decoded frame will be written */ - const uint16_t zero_flag, /* i : if this flag is enabled, this function outputs a zero-initialized metadata struct */ - const uint16_t objectIdx /* i : index of the queried object */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_ISM_METADATA *metadata, /* o : struct where metadata decoded in most recently decoded frame will be written */ + const uint16_t zero_flag, /* i : if this flag is enabled, this function outputs a zero-initialized metadata struct */ + const uint16_t objectIdx /* i : index of the queried object */ ) { Decoder_Struct *st_ivas; @@ -2597,6 +2633,7 @@ ivas_error IVAS_DEC_GetObjectMetadata( is_masa_ism = 1; } } + if ( st_ivas->ivas_format != ISM_FORMAT && st_ivas->ivas_format != MASA_ISM_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT && is_masa_ism == 0 ) { return IVAS_ERR_WRONG_MODE; @@ -2762,7 +2799,7 @@ ivas_error IVAS_DEC_FeedHeadTrackData( /*---------------------------------------------------------------------* * IVAS_DEC_FeedRefRotData( ) * - * Feed the decoder with the reference rotation + * Feed the decoder with the reference rotation data *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_FeedRefRotData( @@ -3004,6 +3041,7 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfStatisticsHandle( ) * @@ -3111,13 +3149,13 @@ ivas_error IVAS_DEC_HRTF_binary_close( { Decoder_Struct *st_ivas; - st_ivas = hIvasDec->st_ivas; - if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + st_ivas = hIvasDec->st_ivas; + if ( st_ivas->hDecoderConfig->Opt_HRTF_binary && st_ivas->ini_frame > 0 ) { if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && @@ -3205,7 +3243,7 @@ static ivas_error copyRendererConfigStruct( /*---------------------------------------------------------------------* * IVAS_DEC_GetRenderConfig( ) * - * + * Return renderer configuration parameters handle *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetRenderConfig( @@ -3225,12 +3263,12 @@ ivas_error IVAS_DEC_GetRenderConfig( /*---------------------------------------------------------------------* * IVAS_DEC_GetDefaultRenderConfig( ) * - * + * Return default renderer configuration parameters *---------------------------------------------------------------------*/ /*! r: error code*/ ivas_error IVAS_DEC_GetDefaultRenderConfig( - IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render config handle */ + IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render config handle */ ) { RENDER_CONFIG_DATA RCin; @@ -3249,7 +3287,7 @@ ivas_error IVAS_DEC_GetDefaultRenderConfig( /*---------------------------------------------------------------------* * IVAS_DEC_FeedRenderConfig( ) * - * + * Set renderer configuration (acoustic environment) parameters *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_FeedRenderConfig( @@ -3258,6 +3296,7 @@ ivas_error IVAS_DEC_FeedRenderConfig( ) { RENDER_CONFIG_HANDLE hRenderConfig; + Decoder_Struct *st_ivas; ivas_error error; if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL ) @@ -3266,6 +3305,8 @@ ivas_error IVAS_DEC_FeedRenderConfig( } hRenderConfig = hIvasDec->st_ivas->hRenderConfig; + st_ivas = hIvasDec->st_ivas; + #ifdef DEBUGGING hRenderConfig->renderer_type_override = IVAS_RENDER_TYPE_OVERRIDE_NONE; if ( renderConfig.renderer_type_override == IVAS_RENDER_TYPE_OVERRIDE_FASTCONV ) @@ -3299,53 +3340,42 @@ ivas_error IVAS_DEC_FeedRenderConfig( /* Re-initialize reverb instance if already available */ /* TD renderer Jot reverberator */ - if ( hIvasDec->st_ivas->hReverb != NULL ) + if ( st_ivas->hReverb != NULL ) { - if ( ( error = ivas_reverb_open( &hIvasDec->st_ivas->hReverb, hIvasDec->st_ivas->hHrtfStatistics, hRenderConfig, hIvasDec->st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_open( &st_ivas->hReverb, st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } } /* CREND Jot reverberator */ - if ( hIvasDec->st_ivas->hCrendWrapper != NULL && hIvasDec->st_ivas->hCrendWrapper->hCrend[0] != NULL && hIvasDec->st_ivas->hCrendWrapper->hCrend[0]->hReverb != NULL ) + if ( st_ivas->hCrendWrapper != NULL && st_ivas->hCrendWrapper->hCrend[0] != NULL && st_ivas->hCrendWrapper->hCrend[0]->hReverb != NULL ) { - if ( ( error = ivas_reverb_open( &hIvasDec->st_ivas->hCrendWrapper->hCrend[0]->hReverb, hIvasDec->st_ivas->hHrtfStatistics, hRenderConfig, hIvasDec->st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_open( &st_ivas->hCrendWrapper->hCrend[0]->hReverb, st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } } - /* FB reverberator */ - if ( hIvasDec->st_ivas->hDiracDecBin[0] != NULL && hIvasDec->st_ivas->hDiracDecBin[0]->hReverb != NULL ) + /* Parametric renderer reverberator */ + if ( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->hReverb != NULL ) { - ivas_binaural_reverb_close( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ) ); - if ( ( error = ivas_binaural_reverb_init( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ), - hIvasDec->st_ivas->hHrtfStatistics, - hIvasDec->st_ivas->hSpatParamRendCom->num_freq_bands, - CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, - &( hRenderConfig->roomAcoustics ), - hIvasDec->st_ivas->hDecoderConfig->output_Fs, - NULL, - NULL, - NULL ) ) != IVAS_ERR_OK ) + ivas_binaural_reverb_close( &( st_ivas->hDiracDecBin[0]->hReverb ) ); + + if ( ( error = ivas_binaural_reverb_init( &( st_ivas->hDiracDecBin[0]->hReverb ), st_ivas->hHrtfStatistics, st_ivas->hSpatParamRendCom->num_freq_bands, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, + &( hRenderConfig->roomAcoustics ), st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) { return error; } } - /* Fastconv CLDFB reverberator */ - if ( hIvasDec->st_ivas->hBinRenderer != NULL && hIvasDec->st_ivas->hBinRenderer->hReverb != NULL ) + + /* FastConv renderer reverberator */ + if ( st_ivas->hBinRenderer != NULL && st_ivas->hBinRenderer->hReverb != NULL ) { - ivas_binaural_reverb_close( &( hIvasDec->st_ivas->hBinRenderer->hReverb ) ); - if ( ( error = ivas_binaural_reverb_init( &( hIvasDec->st_ivas->hBinRenderer->hReverb ), - hIvasDec->st_ivas->hHrtfStatistics, - hIvasDec->st_ivas->hBinRenderer->conv_band, - hIvasDec->st_ivas->hBinRenderer->timeSlots, - &( hRenderConfig->roomAcoustics ), - hIvasDec->st_ivas->hDecoderConfig->output_Fs, - NULL, - NULL, - NULL ) ) != IVAS_ERR_OK ) + ivas_binaural_reverb_close( &( st_ivas->hBinRenderer->hReverb ) ); + + if ( ( error = ivas_binaural_reverb_init( &( st_ivas->hBinRenderer->hReverb ), st_ivas->hHrtfStatistics, st_ivas->hBinRenderer->conv_band, st_ivas->hBinRenderer->timeSlots, + &( hRenderConfig->roomAcoustics ), st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK ) { return error; } @@ -3362,9 +3392,9 @@ ivas_error IVAS_DEC_FeedRenderConfig( hRenderConfig->split_rend_config.poseCorrectionMode = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE; } - if ( is_split_rendering_enabled( hIvasDec->st_ivas->hDecoderConfig, hRenderConfig ) ) + if ( is_split_rendering_enabled( st_ivas->hDecoderConfig, hRenderConfig ) ) { - if ( ( error = isar_split_rend_validate_config( &hRenderConfig->split_rend_config, ( hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0 ) ) != IVAS_ERR_OK ) + if ( ( error = isar_split_rend_validate_config( &hRenderConfig->split_rend_config, ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -3377,7 +3407,7 @@ ivas_error IVAS_DEC_FeedRenderConfig( /*---------------------------------------------------------------------* * IVAS_DEC_GetDelay( ) * - * + * Return IVAS decoder delay in nanoseconds *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetDelay( @@ -3423,7 +3453,7 @@ ivas_error IVAS_DEC_GetDelay( /*---------------------------------------------------------------------* * IVAS_DEC_HasDecodedFirstGoodFrame( ) * - * + * Return flag indicating if the decoder has decoded a good frame *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( @@ -3441,7 +3471,7 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( return IVAS_ERR_OK; } - +#ifndef LIB_DEC_REVISION /*---------------------------------------------------------------------* * IVAS_DEC_GetPcmFrameSize( ) * @@ -3469,7 +3499,7 @@ ivas_error IVAS_DEC_GetPcmFrameSize( return IVAS_ERR_OK; } - +#endif /*---------------------------------------------------------------------* * isSidFrame( ) @@ -3496,6 +3526,13 @@ static bool isSidFrame( return false; } + +/*---------------------------------------------------------------------* + * bsCompactToSerial( ) + * + * Bitstream conversion to Byte format + *---------------------------------------------------------------------*/ + static void bsCompactToSerial( const uint8_t *compact, uint16_t *serial, @@ -3786,7 +3823,6 @@ ivas_error IVAS_DEC_VoIP_GetSamples( dbgwrite( &scale, sizeof( uint32_t ), 1, 1, "./res/JBM_scale.dat" ); dbgwrite( &maxScaling, sizeof( uint32_t ), 1, 1, "./res/JBM_maxScale.dat" ); #endif - /* avoid time scaling multiple times within one 20ms frame*/ if ( scale != 100U ) { @@ -3941,6 +3977,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * update_voip_rendered20ms( ) * @@ -3978,7 +4015,7 @@ static void update_voip_rendered20ms( /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_Flush( ) * - * Function to flush remaining audio in VoIP + * Function to flush remaining audio samples in VoIP *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_Flush( @@ -4028,8 +4065,9 @@ ivas_error IVAS_DEC_Flush( *---------------------------------------------------------------------*/ bool IVAS_DEC_VoIP_IsEmpty( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const int16_t nSamplesAsked ) + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t nSamplesAsked /* i : number of output samples asked */ +) { if ( hIvasDec == NULL || hIvasDec->hVoIP == NULL ) { @@ -4064,13 +4102,17 @@ ivas_error IVAS_DEC_VoIP_Get_CA_offset( /*---------------------------------------------------------------------* - * IVAS_DEC_Close_VoIP( ) - * + * ivas_destroy_handle_VoIP( ) * + * Deallocate VoIP handle *---------------------------------------------------------------------*/ +#ifdef LIB_DEC_REVISION +static void ivas_destroy_handle_VoIP( +#else static void IVAS_DEC_Close_VoIP( - IVAS_DEC_VOIP *hVoIP /* i/o: IVAS decoder handle */ +#endif + IVAS_DEC_VOIP *hVoIP /* i/o: VoIP decoder handle */ ) { JB4_Destroy( &hVoIP->hJBM ); @@ -4088,7 +4130,6 @@ static void IVAS_DEC_Close_VoIP( return; } - #ifdef SUPPORT_JBM_TRACEFILE /*---------------------------------------------------------------------* * store_JbmData() @@ -4151,10 +4192,8 @@ ivas_error IVAS_DEC_GetJbmData( return IVAS_ERR_OK; } - #endif - /*---------------------------------------------------------------------* * IVAS_DEC_GetErrorMessage( ) * @@ -4387,8 +4426,12 @@ ivas_error IVAS_DEC_PrintConfig( return IVAS_ERR_OK; } - #ifdef DEBUGGING +/*---------------------------------------------------------------------* + * IVAS_DEC_PrintConfigWithBitstream( ) + * + * + *---------------------------------------------------------------------*/ #define WMC_TOOL_SKIP void IVAS_DEC_PrintConfigWithBitstream( IVAS_DEC_HANDLE hIvasDec, @@ -4414,6 +4457,13 @@ void IVAS_DEC_PrintConfigWithBitstream( return; } + +/*---------------------------------------------------------------------* + * IVAS_DEC_PrintConfigWithVoipBitstream( ) + * + * + *---------------------------------------------------------------------*/ + void IVAS_DEC_PrintConfigWithVoipBitstream( IVAS_DEC_HANDLE hIvasDec, const bool quietModeEnabled, @@ -4442,7 +4492,6 @@ void IVAS_DEC_PrintConfigWithVoipBitstream( #undef WMC_TOOL_SKIP #endif - /*---------------------------------------------------------------------* * IVAS_DEC_PrintDisclaimer( ) * @@ -4575,7 +4624,6 @@ static ivas_error evs_dec_main( return IVAS_ERR_OK; } - #ifdef DEBUGGING /*---------------------------------------------------------------------* * IVAS_DEC_GetBer_detect_flag() @@ -4725,10 +4773,8 @@ ivas_error IVAS_DEC_GetSbaDebugParams( return IVAS_ERR_OK; } #endif /* DEBUG_SBA_AUDIO_DUMP */ - #endif /* DEBUGGING */ - /*---------------------------------------------------------------------* * input_format_API_to_internal() * @@ -5088,7 +5134,7 @@ PCM_RESOLUTION pcm_type_API_to_internal( /*-------------------------------------------------------------------* * ivas_create_handle_isar() * - * Initialize IVAS decoder split rend handle + * Initialize IVAS decoder split-rendering handle *-------------------------------------------------------------------*/ static ivas_error ivas_create_handle_isar( @@ -5302,7 +5348,7 @@ static ivas_error ivas_dec_reconfig_split_rend( /*-------------------------------------------------------------------* * ivas_dec_init_split_rend() * - * IVAS decoder split rend init + * IVAS decoder split rendering initialization *-------------------------------------------------------------------*/ static ivas_error ivas_dec_init_split_rend( @@ -5356,12 +5402,12 @@ static ivas_error ivas_dec_init_split_rend( /*---------------------------------------------------------------------* * IVAS_DEC_is_split_rendering_coded_out() * - * + * Return flag to indicate if split rendering is enabled *---------------------------------------------------------------------*/ /*! r: decoder error code */ ivas_error IVAS_DEC_is_split_rendering_coded_out( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ int16_t *isSplitCoded /* o : flag to indicate if split rendering is enabled */ ) { diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 5f3e65f1d6..2f873d1856 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -503,12 +503,13 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( bool *hasDecodedFirstGoodFrame /* o : flag indicating if the decoder has decoded a good frame since it was configured */ ); +#ifndef LIB_DEC_REVISION /*! r: error code */ ivas_error IVAS_DEC_GetPcmFrameSize( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ int32_t *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels */ ); - +#endif /*! r: true if decoder has no data in VoIP jitter buffer */ bool IVAS_DEC_VoIP_IsEmpty( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ -- GitLab From 1246130b58c1e9cdde29bdc242656ce156376705 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 7 Apr 2025 19:11:07 +0200 Subject: [PATCH 07/11] simplify APA buffer handling --- lib_com/ivas_prot.h | 4 +++ lib_dec/ivas_jbm_dec.c | 9 +++++ lib_dec/lib_dec.c | 81 ++++++++++++++++++++++-------------------- 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 4722f322d2..518712193f 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -806,8 +806,12 @@ void ivas_apply_non_diegetic_panning( *----------------------------------------------------------------------------------*/ ivas_error ivas_jbm_dec_tc( +#ifdef LIB_DEC_REVISION + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#else Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *data /* o : output synthesis signals */ +#endif ); ivas_error ivas_jbm_dec_render( diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 669fa5f43c..f4492948c3 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -66,8 +66,12 @@ static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const int16_t *--------------------------------------------------------------------------*/ ivas_error ivas_jbm_dec_tc( +#ifdef LIB_DEC_REVISION + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#else Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *data /* o : transport channel signals */ +#endif ) { int16_t n, output_frame, nchan_out; @@ -727,11 +731,16 @@ ivas_error ivas_jbm_dec_tc( * Write IVAS transport channels *----------------------------------------------------------------*/ +#ifdef LIB_DEC_REVISION + if ( st_ivas->hDecoderConfig->Opt_tsm == 0 ) +#else if ( st_ivas->hDecoderConfig->Opt_tsm == 1 ) { + ivas_syn_output_f( p_output, output_frame, st_ivas->hTcBuffer->nchan_transport_jbm, data ); } else +#endif { /* directly copy to tc buffers */ ivas_jbm_dec_copy_tc_no_tsm( st_ivas, p_output, output_frame ); diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 0d00257da6..ca8498f721 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -121,7 +121,7 @@ static void IVAS_DEC_Close_VoIP( IVAS_DEC_VOIP *hVoIP ); static void store_JbmData( IVAS_DEC_VOIP *hVoIP, JB4_DATAUNIT_HANDLE dataUnit, const uint32_t systemTimestamp_ms, const uint16_t extBufferedSamples, const int32_t output_Fs ); #endif #ifdef LIB_DEC_REVISION -static ivas_error evs_dec_main( Decoder_Struct *st_ivas, float *floatBuf, int16_t *pcmBuf ); +static ivas_error evs_dec_main( Decoder_Struct *st_ivas ); #else static ivas_error evs_dec_main( Decoder_Struct *st_ivas, const int16_t nOutSamples, float *floatBuf, int16_t *pcmBuf ); #endif @@ -1303,14 +1303,14 @@ ivas_error IVAS_DEC_GetSamplesDecoder( if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) { - if ( ( error = evs_dec_main( st_ivas, hIvasDec->apaExecBuffer, NULL ) ) != IVAS_ERR_OK ) + if ( ( error = evs_dec_main( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } else if ( hIvasDec->mode == IVAS_DEC_MODE_IVAS ) { - if ( ( error = ivas_jbm_dec_tc( st_ivas, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_jbm_dec_tc( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1351,6 +1351,10 @@ ivas_error IVAS_DEC_GetSamplesDecoder( return IVAS_ERR_UNKNOWN; } +#ifdef LIB_DEC_REVISION + ivas_syn_output_f( hIvasDec->st_ivas->p_output_f, hIvasDec->nSamplesFrame, nTransportChannels, hIvasDec->apaExecBuffer ); + +#endif if ( apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, hIvasDec->nSamplesFrame * nTransportChannels, (uint16_t) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; @@ -2364,25 +2368,6 @@ static ivas_error IVAS_DEC_Setup( } } -#ifdef LIB_DEC_REVISION - /* allocate/reallocate APA buffer */ - // ToDo: this memory should be harmonized with st_ivas->p_output_f[] and st_ivas->hTcBuffer->tc_buffer[] - see issue #916 - // ToDo: this part is also related to cleaning of NONBE_UNIFIED_DECODING_PATHS leftovers (see MR !1246) - if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && *nTransportChannels != hIvasDec->nTransportChannelsOld ) - { - if ( hIvasDec->apaExecBuffer != NULL ) - { - free( hIvasDec->apaExecBuffer ); - } - - if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * APA_BUF_PER_CHANNEL * *nTransportChannels ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); - } - set_zero( hIvasDec->apaExecBuffer, APA_BUF_PER_CHANNEL * *nTransportChannels ); - } - -#endif return IVAS_ERR_OK; } @@ -4610,24 +4595,32 @@ void IVAS_DEC_PrintDisclaimer( void ) *---------------------------------------------------------------------*/ static ivas_error evs_dec_main( +#ifdef LIB_DEC_REVISION + Decoder_Struct *st_ivas /* i : IVAS decoder structure */ +#else Decoder_Struct *st_ivas, -#ifndef LIB_DEC_REVISION const int16_t nOutSamples, -#endif float *floatBuf, - int16_t *pcmBuf ) + int16_t *pcmBuf +#endif + +) { DEC_CORE_HANDLE *hCoreCoder; float mixer_left, mixer_rigth; float *p_output[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN]; - int16_t ch; #ifdef LIB_DEC_REVISION - int16_t nOutSamples; + int16_t ch, nOutSamples; +#else + int16_t ch; #endif ivas_error error; hCoreCoder = st_ivas->hSCE[0]->hCoreCoder; hCoreCoder[0]->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; +#ifdef LIB_DEC_REVISION + nOutSamples = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); +#endif mdct_switching_dec( hCoreCoder[0] ); @@ -4680,10 +4673,6 @@ static ivas_error evs_dec_main( } st_ivas->BER_detect = hCoreCoder[0]->BER_detect; -#ifdef LIB_DEC_REVISION - - nOutSamples = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); -#endif if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ) { @@ -4693,6 +4682,23 @@ static ivas_error evs_dec_main( v_multc( p_output[0], mixer_left, p_output[0], nOutSamples ); } +#ifdef LIB_DEC_REVISION + if ( st_ivas->hDecoderConfig->Opt_tsm ) + { + /* BE workaround: in order to keep EVS bit-exact wrt. TS 26.443, convert 'float' output data to 'short' before the TSM */ + int16_t pcm_buf_local[L_FRAME48k]; + + for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) + { +#ifdef DEBUGGING + st_ivas->noClipping += +#endif + ivas_syn_output( &p_output[ch], nOutSamples, 1, pcm_buf_local ); + + mvs2r( pcm_buf_local, p_output[ch], nOutSamples ); + } + } +#else if ( !st_ivas->hDecoderConfig->Opt_tsm ) { ivas_jbm_dec_copy_tc_no_tsm( st_ivas, p_output, nOutSamples ); @@ -4717,6 +4723,7 @@ static ivas_error evs_dec_main( #endif ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); } +#endif return IVAS_ERR_OK; } @@ -4937,6 +4944,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( const uint16_t l_ts ) #endif { + int16_t apa_buffer_size; #ifdef LIB_DEC_REVISION uint16_t l_ts; @@ -4944,8 +4952,6 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( if ( isInitialized_voip == false ) #else - int16_t apa_buffer_size; - apa_buffer_size = hIvasDec->nSamplesFrame; if ( hIvasDec->apaExecBuffer == NULL ) @@ -4961,9 +4967,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( float startQuality; startQuality = hIvasDec->tsm_quality; -#ifndef LIB_DEC_REVISION apa_buffer_size = APA_BUF_PER_CHANNEL; -#endif /* get current renderer type*/ hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig; @@ -5009,14 +5013,13 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( return IVAS_ERR_INIT_ERROR; } } -#ifndef LIB_DEC_REVISION if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } - set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels ); +#ifndef LIB_DEC_REVISION } #endif } @@ -5030,7 +5033,8 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( { return IVAS_ERR_INIT_ERROR; } -#ifndef LIB_DEC_REVISION + + /* realloc apa_exe_buffer */ apa_buffer_size = APA_BUF_PER_CHANNEL; free( hIvasDec->apaExecBuffer ); if ( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL ) @@ -5038,6 +5042,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels ); +#ifndef LIB_DEC_REVISION } /* realloc apa_exe_buffer */ #endif -- GitLab From 88b8fc8f50230c39e448d2a25676240e7863e1e1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 7 Apr 2025 20:15:16 +0200 Subject: [PATCH 08/11] fix AMR-WB path --- lib_dec/lib_dec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index ca8498f721..05decb054e 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -4698,6 +4698,10 @@ static ivas_error evs_dec_main( mvs2r( pcm_buf_local, p_output[ch], nOutSamples ); } } + else // ToDo: the 'else' branch can be removed once UNIFIED_DECODING_PATHS_LEFTOVERS is merged + { + ivas_jbm_dec_copy_tc_no_tsm( st_ivas, p_output, nOutSamples ); + } #else if ( !st_ivas->hDecoderConfig->Opt_tsm ) { -- GitLab From 0c2086b55b5536742954d9e1eea3ea66b2a3ce13 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 7 Apr 2025 21:56:34 +0200 Subject: [PATCH 09/11] update --- apps/decoder.c | 13 ++++++++++++- lib_dec/lib_dec.c | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 5607d6a4ea..94760fe1c7 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1068,18 +1068,30 @@ static bool parseCmdlIVAS_dec( if ( strcmp( argv_to_upper, "-VOIP" ) == 0 ) { +#ifdef LIB_DEC_REVISION arg->voipMode = true; +#else + arg->voipMode = 1; +#endif i++; } else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=0" ) == 0 ) { +#ifdef LIB_DEC_REVISION arg->voipMode = true; +#else + arg->voipMode = 1; +#endif arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP; i++; } else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=1" ) == 0 ) { +#ifdef LIB_DEC_REVISION arg->voipMode = true; +#else + arg->voipMode = 1; +#endif arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF; i++; } @@ -1818,7 +1830,6 @@ static ivas_error initOnFirstGoodFrame( int32_t pcmFrameSize; if ( ( error = IVAS_DEC_GetPcmFrameSize( hIvasDec, &pcmFrameSize ) ) != IVAS_ERR_OK ) - { fprintf( stderr, "\nError in IVAS_DEC_GetPcmFrameSize, error code: %d\n", error ); return error; diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 05decb054e..898d7c6590 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -181,7 +181,6 @@ ivas_error IVAS_DEC_Open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" ); } - hIvasDec = *phIvasDec; hIvasDec->hVoIP = NULL; hIvasDec->apaExecBuffer = NULL; @@ -314,7 +313,6 @@ static ivas_error isar_set_split_rend_setup( return IVAS_ERR_OK; } - /*---------------------------------------------------------------------* * init_decoder_config() * @@ -527,7 +525,6 @@ ivas_error IVAS_DEC_Configure( { return IVAS_ERR_WRONG_PARAMS; } - if ( outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) { hDecoderConfig->render_framesize = IVAS_RENDER_FRAMESIZE_20MS; @@ -678,7 +675,6 @@ ivas_error IVAS_DEC_GetRenderFramesize( return IVAS_ERR_OK; } - /*---------------------------------------------------------------------* * IVAS_DEC_GetGetRenderFramesizeSamples( ) * @@ -700,7 +696,6 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( return IVAS_ERR_OK; } - /*---------------------------------------------------------------------* * IVAS_DEC_GetGetRenderFramesizeMs( ) * @@ -744,7 +739,6 @@ ivas_error IVAS_DEC_GetReferencesUpdateFrequency( return IVAS_ERR_OK; } - /*---------------------------------------------------------------------* * IVAS_DEC_GetGetNumOrientationSubframes( ) * @@ -927,7 +921,6 @@ ivas_error IVAS_DEC_FeedFrame_Serial( bfi = 2; } } - if ( ( error = read_indices( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ) ) != IVAS_ERR_OK ) { return error; @@ -2538,7 +2531,6 @@ ivas_error IVAS_DEC_GetNumObjects( is_masa_ism = 1; } } - if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == SBA_ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT || is_masa_ism ) { *numObjects = hIvasDec->st_ivas->nchan_ism; @@ -2711,7 +2703,6 @@ ivas_error IVAS_DEC_GetObjectMetadata( is_masa_ism = 1; } } - if ( st_ivas->ivas_format != ISM_FORMAT && st_ivas->ivas_format != MASA_ISM_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT && is_masa_ism == 0 ) { return IVAS_ERR_WRONG_MODE; @@ -3119,7 +3110,6 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( return IVAS_ERR_OK; } - /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfStatisticsHandle( ) * @@ -3891,6 +3881,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( extBufferedTime_ms = extBufferedSamples * 1000 / hDecoderConfig->output_Fs; dataUnit = NULL; + /* pop one access unit from the jitter buffer */ result = JB4_PopDataUnit( hVoIP->hJBM, systemTimestamp_ms, extBufferedTime_ms, &dataUnit, &scale, &maxScaling ); if ( result != 0 ) @@ -3905,6 +3896,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( dbgwrite( &scale, sizeof( uint32_t ), 1, 1, "./res/JBM_scale.dat" ); dbgwrite( &maxScaling, sizeof( uint32_t ), 1, 1, "./res/JBM_maxScale.dat" ); #endif + /* avoid time scaling multiple times within one 20ms frame*/ if ( scale != 100U ) { @@ -4212,6 +4204,7 @@ static void IVAS_DEC_Close_VoIP( return; } + #ifdef SUPPORT_JBM_TRACEFILE /*---------------------------------------------------------------------* * store_JbmData() @@ -4274,8 +4267,10 @@ ivas_error IVAS_DEC_GetJbmData( return IVAS_ERR_OK; } + #endif + /*---------------------------------------------------------------------* * IVAS_DEC_GetErrorMessage( ) * @@ -4508,6 +4503,7 @@ ivas_error IVAS_DEC_PrintConfig( return IVAS_ERR_OK; } + #ifdef DEBUGGING /*---------------------------------------------------------------------* * IVAS_DEC_PrintConfigWithBitstream( ) @@ -4574,6 +4570,7 @@ void IVAS_DEC_PrintConfigWithVoipBitstream( #undef WMC_TOOL_SKIP #endif + /*---------------------------------------------------------------------* * IVAS_DEC_PrintDisclaimer( ) * @@ -4603,7 +4600,6 @@ static ivas_error evs_dec_main( float *floatBuf, int16_t *pcmBuf #endif - ) { DEC_CORE_HANDLE *hCoreCoder; @@ -4732,6 +4728,7 @@ static ivas_error evs_dec_main( return IVAS_ERR_OK; } + #ifdef DEBUGGING /*---------------------------------------------------------------------* * IVAS_DEC_GetBer_detect_flag() @@ -4881,8 +4878,10 @@ ivas_error IVAS_DEC_GetSbaDebugParams( return IVAS_ERR_OK; } #endif /* DEBUG_SBA_AUDIO_DUMP */ + #endif /* DEBUGGING */ + /*---------------------------------------------------------------------* * input_format_API_to_internal() * @@ -5022,6 +5021,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } + set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels ); #ifndef LIB_DEC_REVISION } -- GitLab From 1adf8e1a6ba4f11e34023ddd6fede581e5a795ed Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 7 Apr 2025 22:26:01 +0200 Subject: [PATCH 10/11] removal of unnecessary temporary parameter --- lib_dec/lib_dec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 898d7c6590..587fa6ece7 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -4011,15 +4011,17 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { if ( hIvasDec->nSamplesAvailableNext == 0 || hIvasDec->nSamplesAvailableNext == hIvasDec->nSamplesFrame ) { +#ifndef LIB_DEC_REVISION uint16_t nSamplesFlushed_ref = hIvasDec->nSamplesFlushed; - +#endif if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, NULL ) ) != IVAS_ERR_OK ) { return error; } - +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesFlushed = nSamplesFlushed_ref; +#endif *bitstreamReadDone = false; *parametersAvailableForEditing = true; return IVAS_ERR_OK; -- GitLab From c20a7e415a76170a5b0c314b53661adb1276652c Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 10 Apr 2025 15:49:42 +0200 Subject: [PATCH 11/11] address comments --- apps/decoder.c | 21 +++++--- lib_dec/lib_dec.c | 119 ++++++++++++++++++++++++++++++++++++---------- lib_dec/lib_dec.h | 19 ++++---- 3 files changed, 121 insertions(+), 38 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 94760fe1c7..dbd92244de 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -259,11 +259,7 @@ int main( * Open decoder handle *------------------------------------------------------------------------------------------*/ -#ifdef LIB_DEC_REVISION - if ( ( error = IVAS_DEC_Open( &hIvasDec, arg.output_Fs, arg.decMode ) ) != IVAS_ERR_OK ) -#else if ( ( error = IVAS_DEC_Open( &hIvasDec, arg.decMode ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -450,7 +446,7 @@ int main( uint16_t aeID = arg.aeSequence.count > 0 ? arg.aeSequence.pID[0] : 65535; #ifdef LIB_DEC_REVISION - if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.voipMode, arg.tsmEnabled, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, + if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.non_diegetic_pan_enabled, arg.non_diegetic_pan_gain, arg.dpidEnabled, aeID, arg.objEditEnabled, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) #else @@ -1242,7 +1238,7 @@ static bool parseCmdlIVAS_dec( if ( !is_digits_only( argv[i] ) ) { #ifdef LIB_DEC_REVISION - fprintf( stderr, "Error: Render frame size not specified!\n\n" ); + fprintf( stderr, "Error: Render frame size is invalid or not specified!\n\n" ); usage_dec(); #endif return false; @@ -2122,6 +2118,19 @@ static ivas_error decodeG192( SplitFileReadWrite *splitRendWriter = NULL; int16_t isSplitRend, isSplitCoded; +#ifdef VARIABLE_SPEED_DECODING +#ifdef LIB_DEC_REVISION + if ( arg.tsmEnabled ) + { + if ( ( error = IVAS_DEC_EnableTsm( hIvasDec ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_EnableTsm, code: %d\n", error ); + return error; + } + } + +#endif +#endif if ( ( error = IVAS_DEC_is_split_rendering_enabled( hIvasDec, &isSplitRend ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_is_split_rendering_enabled, code: %d\n", error ); diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 587fa6ece7..42718c0244 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -81,8 +81,10 @@ struct IVAS_DEC bool isInitialized; int16_t bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ - bool Opt_VOIP; /* flag indicating VOIP mode with JBM */ - int16_t tsm_scale; /* scale for TSM operation */ +#ifdef DEBUGGING + bool Opt_VOIP; /* flag indicating VOIP mode with JBM */ +#endif + int16_t tsm_scale; /* scale for TSM operation */ int16_t tsm_max_scaling; int16_t timeScalingDone; /* have we done already one TSM in a 20ms frame? */ float tsm_quality; @@ -159,10 +161,7 @@ static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const int16_t nS /* may return an error but may still have allocated memory - thus run Close also in case of error to release memory */ ivas_error IVAS_DEC_Open( IVAS_DEC_HANDLE *phIvasDec, /* i/o: pointer to an IVAS decoder handle to be opened */ -#ifdef LIB_DEC_REVISION - const int32_t output_Fs, /* i : output sampling frequency */ -#endif - const IVAS_DEC_MODE mode /* i : compatibility mode (EVS or IVAS) */ + const IVAS_DEC_MODE mode /* i : compatibility mode (EVS or IVAS) */ ) { IVAS_DEC_HANDLE hIvasDec; @@ -192,12 +191,10 @@ ivas_error IVAS_DEC_Open( hIvasDec->needNewFrame = false; hIvasDec->nTransportChannelsOld = 0; hIvasDec->nSamplesAvailableNext = 0; -#ifdef LIB_DEC_REVISION - hIvasDec->nSamplesFrame = (uint16_t) ( output_Fs / FRAMES_PER_SEC ); -#else +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesRendered = 0; - hIvasDec->nSamplesFrame = 0; #endif + hIvasDec->nSamplesFrame = 0; hIvasDec->hasBeenFedFrame = false; hIvasDec->hasBeenFedFirstGoodFrame = false; hIvasDec->hasDecodedFirstGoodFrame = false; @@ -211,7 +208,9 @@ ivas_error IVAS_DEC_Open( hIvasDec->mode = mode; hIvasDec->bitstreamformat = G192; +#ifdef DEBUGGING hIvasDec->Opt_VOIP = 0; +#endif hIvasDec->amrwb_rfc4867_flag = -1; hIvasDec->prev_ft_speech = 1; /* RXDTX handler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ hIvasDec->CNG = 0; /* RXDTX handler CNG = 1, no CNG = 0*/ @@ -433,6 +432,32 @@ static IVAS_DEC_BS_FORMAT mapIvasFormat( return IVAS_DEC_BS_UNKOWN; } +#ifdef LIB_DEC_REVISION + +/*---------------------------------------------------------------------* + * create_flush_buffer() + * + * Create flush buffer - needed for binaural outputs with TSM or in VoIP mode + *---------------------------------------------------------------------*/ + +static ivas_error create_flush_buffer( + IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ +) +{ + hIvasDec->flushbuffer = (void *) malloc( CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( int16_t ) ); + if ( hIvasDec->flushbuffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate JBM flush buffer" ); + } + + hIvasDec->pcmType = IVAS_DEC_PCM_INT16; + set_s( (int16_t *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); + + return IVAS_ERR_OK; +} + +#endif + /*---------------------------------------------------------------------* * IVAS_DEC_Configure( ) @@ -445,10 +470,9 @@ ivas_error IVAS_DEC_Configure( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const uint32_t sampleRate, /* i : output sampling frequency */ const AUDIO_CONFIG outputConfig, /* i : output configuration */ -#ifdef LIB_DEC_REVISION - const bool voipMode, /* i : enable VoIP mode with JBM */ +#ifndef LIB_DEC_REVISION + const bool tsmEnabled, /* i : enable TSM */ #endif - const bool tsmEnabled, /* i : enable TSM */ const IVAS_RENDER_FRAMESIZE renderFramesize, /* i : rendering frame size */ const bool customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ const bool hrtfReaderEnabled, /* i : enable HRTF binary file input */ @@ -507,7 +531,9 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config ); } +#ifndef LIB_DEC_REVISION hDecoderConfig->Opt_tsm = (int16_t) tsmEnabled; +#endif hDecoderConfig->Opt_LsCustom = (int16_t) customLsOutputEnabled; hDecoderConfig->Opt_Headrotation = (int16_t) enableHeadRotation; hDecoderConfig->orientation_tracking = orientation_tracking; @@ -554,21 +580,16 @@ ivas_error IVAS_DEC_Configure( hIvasDec->st_ivas->ivas_format = MONO_FORMAT; } -#ifndef LIB_DEC_REVISION hIvasDec->nSamplesFrame = (uint16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesAvailableNext = 0; hIvasDec->nSamplesRendered = 0; hIvasDec->tsm_scale = 100; hIvasDec->tsm_max_scaling = 0; hIvasDec->tsm_quality = 1.0f; -#endif -#ifdef LIB_DEC_REVISION - /* Create flush buffer - needed for binaural outputs with TSM or in VoIP mode */ - if ( ( tsmEnabled || voipMode ) && ( outputConfig == IVAS_AUDIO_CONFIG_BINAURAL || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) -#else + /* Init flush buffer if necessary (only needed for binaural)*/ if ( tsmEnabled && ( outputConfig == IVAS_AUDIO_CONFIG_BINAURAL || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) -#endif { hIvasDec->flushbuffer = (void *) malloc( CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( int16_t ) ); if ( hIvasDec->flushbuffer == NULL ) @@ -578,6 +599,7 @@ ivas_error IVAS_DEC_Configure( hIvasDec->pcmType = IVAS_DEC_PCM_INT16; set_s( (int16_t *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); } +#endif return IVAS_ERR_OK; } @@ -785,8 +807,11 @@ ivas_error IVAS_DEC_EnableVoIP( hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig; +#ifdef DEBUGGING hIvasDec->Opt_VOIP = 1; +#endif hDecoderConfig->Opt_tsm = 1; + if ( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_EXTERNAL ) { hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config ); @@ -835,6 +860,7 @@ ivas_error IVAS_DEC_EnableVoIP( { return IVAS_ERR_FAILED_ALLOC; } + #ifdef NONBE_1122_KEEP_EVS_MODE_UNCHANGED if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) { @@ -842,8 +868,14 @@ ivas_error IVAS_DEC_EnableVoIP( } #endif -#ifndef LIB_DEC_REVISION - /* init flush buffer if necessary (only needed for binaural)*/ +#ifdef LIB_DEC_REVISION + /* init flush buffer (needed for binaural outputs) */ + if ( ( error = create_flush_buffer( hIvasDec ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in create_flush_buffer , code: %d\n", error ); + return error; + } +#else if ( hIvasDec->flushbuffer == NULL && ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { hIvasDec->flushbuffer = (void *) malloc( CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( int16_t ) ); @@ -851,6 +883,7 @@ ivas_error IVAS_DEC_EnableVoIP( set_s( (int16_t *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); } #endif + return IVAS_ERR_OK; } @@ -3759,6 +3792,43 @@ ivas_error IVAS_DEC_VoIP_SetScale( return IVAS_ERR_OK; } +#ifdef VARIABLE_SPEED_DECODING +#ifdef LIB_DEC_REVISION + +/*---------------------------------------------------------------------* + * IVAS_DEC_EnableTsm( ) + * + * Enable Time-Scale Modification (TSM) + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_EnableTsm( + IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ +) +{ + AUDIO_CONFIG output_config; + ivas_error error; + + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + hIvasDec->st_ivas->hDecoderConfig->Opt_tsm = 1; + + /* init flush buffer if necessary (only needed for binaural) */ + output_config = hIvasDec->st_ivas->hDecoderConfig->output_config; + if ( hIvasDec->flushbuffer == NULL && ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + if ( ( error = create_flush_buffer( hIvasDec ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + return IVAS_ERR_OK; +} + +#endif /*---------------------------------------------------------------------* * IVAS_DEC_TSM_SetQuality( ) @@ -3797,6 +3867,7 @@ ivas_error IVAS_DEC_TSM_SetQuality( return IVAS_ERR_OK; } +#endif /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_GetSamples( ) @@ -4057,7 +4128,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( /*---------------------------------------------------------------------* * update_voip_rendered20ms( ) * - * Return number of samples that have been rendered since the last 20ms render border + * Update the number of samples that have been rendered since the last 20ms render border *---------------------------------------------------------------------*/ static void update_voip_rendered20ms( @@ -4955,7 +5026,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( l_ts = (uint16_t) hIvasDec->st_ivas->hTcBuffer->n_samples_granularity; - if ( isInitialized_voip == false ) + if ( !isInitialized_voip ) #else apa_buffer_size = hIvasDec->nSamplesFrame; diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 2f873d1856..2a02fd46ec 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -114,9 +114,6 @@ typedef ivas_error ( *JbmTraceFileWriterFn )( const void *data, void *writer ); /*! r: error code */ ivas_error IVAS_DEC_Open( IVAS_DEC_HANDLE *phIvasDec, /* i/o: pointer to an IVAS decoder handle to be opened */ -#ifdef LIB_DEC_REVISION - const int32_t output_Fs, /* i : output sampling frequency */ -#endif IVAS_DEC_MODE mode /* i : compatibility mode (EVS or IVAS) */ ); @@ -125,10 +122,9 @@ ivas_error IVAS_DEC_Configure( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const uint32_t sampleRate, /* i : output sampling frequency */ const IVAS_AUDIO_CONFIG outputConfig, /* i : audio configuration */ -#ifdef LIB_DEC_REVISION - const bool voipMode, /* i : enable VoIP mode with JBM */ -#endif +#ifndef LIB_DEC_REVISION const bool tsmEnabled, /* i : enable TSM */ + #endif const IVAS_RENDER_FRAMESIZE renderFramesize,/* i : rendering frame size */ const bool customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ const bool hrtfReaderEnabled, /* i : enable HRTF binary file input */ @@ -301,12 +297,19 @@ ivas_error IVAS_DEC_VoIP_SetScale( const int16_t scale /* i : TSM scale to set */ ); +#ifdef VARIABLE_SPEED_DECODING +#ifdef LIB_DEC_REVISION +ivas_error IVAS_DEC_EnableTsm( + IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ +); +#endif + /*! r: error code */ ivas_error IVAS_DEC_TSM_SetQuality( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const float quality /* i : target TSM quality */ + const float quality /* i : target TSM quality */ ); - +#endif /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ -- GitLab