From c2efd75f8c54c84eedeb666c273d47335a54d238 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 25 Aug 2025 17:17:20 +0200 Subject: [PATCH 1/3] port MR, part 1 --- lib_com/ivas_prot.h | 4 +- lib_com/options.h | 1 + lib_dec/ivas_jbm_dec.c | 10 +- lib_dec/lib_dec.c | 300 ++++++++++++++++++++++++++++++----------- lib_dec/lib_dec.h | 17 ++- 5 files changed, 246 insertions(+), 86 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b46381291..fcac615f8 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -822,8 +822,10 @@ void ivas_apply_non_diegetic_panning( *----------------------------------------------------------------------------------*/ ivas_error ivas_jbm_dec_tc( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef LIB_DEC_REVISION float *data /* o : output synthesis signals */ +#endif ); ivas_error ivas_jbm_dec_render( diff --git a/lib_com/options.h b/lib_com/options.h index 3b6c3bade..599e698bc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -221,6 +221,7 @@ #define FIX_1369_HQ_LR_OVERFLOW /* FhG: fix BASOP overflow in hq_lr_enc(), brings floating-point code inline with FX */ #define NONBE_1118_EVS_LR_HQ_BITERROR /* VA: issue 1118: fix EVS decoder crash in LR-HQ in case of bit errors */ #define FIX_1139_REV_COLORATION_SHORT_T60 /* Nokia,FhG: Fix issue 1139, prevent sound coloration artefacts at very low reverberation times */ +#define LIB_DEC_REVISION /* VA: cleaning and simplification of lib_dec.c */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index dacbbf159..c9fdee2c7 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -66,8 +66,10 @@ static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const int16_t *--------------------------------------------------------------------------*/ ivas_error ivas_jbm_dec_tc( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *data /* o : transport channel signals */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef LIB_DEC_REVISION + float *data /* o : transport channel signals */ +#endif ) { int16_t n, output_frame, nchan_out; @@ -746,11 +748,15 @@ 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 868fc4e06..cba9ae505 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -78,8 +78,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; @@ -89,7 +91,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 */ @@ -102,19 +106,32 @@ 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 +#ifdef LIB_DEC_REVISION +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 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, uint8_t *nOutChannels, uint16_t *nSamplesRendered, const IVAS_DEC_PCM_TYPE pcmType, void *data ); 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 ); 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 ); @@ -165,7 +182,9 @@ ivas_error IVAS_DEC_Open( hIvasDec->needNewFrame = false; hIvasDec->nTransportChannelsOld = 0; hIvasDec->nSamplesAvailableNext = 0; +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesRendered = 0; +#endif hIvasDec->nSamplesFrame = 0; hIvasDec->hasBeenFedFrame = false; hIvasDec->hasBeenFedFirstGoodFrame = false; @@ -176,7 +195,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*/ @@ -315,7 +336,7 @@ static void init_decoder_config( /*---------------------------------------------------------------------* * IVAS_DEC_Close( ) * - * + * Deallocate IVAS decoder memory handles *---------------------------------------------------------------------*/ void IVAS_DEC_Close( @@ -330,7 +351,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; } @@ -391,20 +416,47 @@ 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( ) * * 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( #ifdef FIX_745_FIX_DATA_TYPE_CONVERSION - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const uint32_t sampleRate, /* i : output sampling frequency */ - const IVAS_AUDIO_CONFIG outputConfig, /* i : output configuration */ - const bool tsmEnabled, /* i : enable time scale modification */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const uint32_t sampleRate, /* i : output sampling frequency */ + const IVAS_AUDIO_CONFIG outputConfig, /* i : output configuration */ +#ifndef LIB_DEC_REVISION + const bool tsmEnabled, /* i : enable time scale modification */ +#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 */ @@ -486,7 +538,9 @@ ivas_error IVAS_DEC_Configure( } #ifdef FIX_745_FIX_DATA_TYPE_CONVERSION +#ifndef LIB_DEC_REVISION hDecoderConfig->Opt_tsm = (int16_t) tsmEnabled; +#endif hDecoderConfig->Opt_LsCustom = (int16_t) customLsOutputEnabled; hDecoderConfig->Opt_Headrotation = (int16_t) enableHeadRotation; #else @@ -558,11 +612,13 @@ ivas_error IVAS_DEC_Configure( } 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 return IVAS_ERR_OK; } @@ -767,7 +823,9 @@ 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 ) { @@ -792,7 +850,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 @@ -905,7 +965,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; @@ -929,6 +991,13 @@ ivas_error IVAS_DEC_GetSamples( ) { 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 int16_t nOutSamplesElse, nSamplesToRender; uint16_t nSamplesRendered, nSamplesRendered_loop, l_ts, nTimeScalerOutSamples; uint8_t nTransportChannels, nOutChannels; @@ -992,107 +1061,178 @@ ivas_error IVAS_DEC_GetSamples( } else { - /* check if we need to run the setup function */ - if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) - { - /* setup */ + st_ivas = hIvasDec->st_ivas; - if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) +#ifdef LIB_DEC_REVISION + isInitialized_voip = hIvasDec->apaExecBuffer != NULL; +#endif - { - return error; - } +#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 + if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) /* wait for the first good frame */ { - /* check if we need to run the setup function, tc decoding and feeding the renderer */ + /* check if we need to run the setup function */ if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { - int16_t nResidualSamples, nSamplesTcsScaled; - nSamplesRendered += nSamplesRendered_loop; + /* setup */ - if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && nTransportChannels != hIvasDec->nTransportChannelsOld ) - { - if ( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ) != IVAS_ERR_OK ) - { - return error; - } - } + if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) - /* IVAS decoder */ - if ( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK ) { return error; } - - /* JBM */ - if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) + } + { + /* check if we need to run the setup function, tc decoding and feeding the renderer */ + if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { - if ( apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 ) + int16_t nResidualSamples, nSamplesTcsScaled; + nSamplesRendered += nSamplesRendered_loop; + + if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && nTransportChannels != hIvasDec->nTransportChannelsOld ) { - return IVAS_ERR_UNKNOWN; + if ( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ) != IVAS_ERR_OK ) + { + return error; + } } +#endif + +#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 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( hIvasDec->mode == IVAS_DEC_MODE_IVAS ) + { + if ( ( error = ivas_jbm_dec_tc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, hIvasDec->nSamplesFrame * nTransportChannels, (uint16_t) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) + hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */ + } + + if ( hIvasDec->hasBeenFedFirstGoodFrame ) + { + hIvasDec->hasDecodedFirstGoodFrame = true; + } +#else + /* IVAS decoder */ + if ( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK ) { - return IVAS_ERR_UNKNOWN; + return error; } +#endif - assert( nTimeScalerOutSamples <= APA_BUF ); - nSamplesTcsScaled = nTimeScalerOutSamples / nTransportChannels; - hIvasDec->timeScalingDone = 1; - } - else - { - nSamplesTcsScaled = hIvasDec->nSamplesFrame; - } + /*-----------------------------------------------------------------* + * JBM + *-----------------------------------------------------------------*/ -#ifdef DEBUG_MODE_JBM - dbgwrite( &nTimeScalerOutSamples, sizeof( uint16_t ), 1, 1, "./res/JBM_nTimeScaleOutSamples.dat" ); -#endif - /* Feed decoded transport channels samples to the renderer */ - if ( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK ) + 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; } - -#ifdef DEBUG_MODE_JBM - dbgwrite( &nResidualSamples, sizeof( int16_t ), 1, 1, "./res/JBM_nResidualSamples.dat" ); -#endif - if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) - { - /* feed residual samples to TSM for the next call */ - if ( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (uint16_t) nResidualSamples ) != 0 ) - { - return IVAS_ERR_UNKNOWN; - } - } - hIvasDec->hasBeenFedFrame = false; } - /* render IVAS frames directly to the output buffer */ - 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 + if ( apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 ) { - return error; + return IVAS_ERR_UNKNOWN; } - nSamplesRendered += nSamplesRendered_loop; - nSamplesToRender -= nSamplesRendered_loop; - if ( hIvasDec->nSamplesAvailableNext == 0 ) +#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 ) { - *needNewFrame = true; - hIvasDec->needNewFrame = true; + return IVAS_ERR_UNKNOWN; } - else + + assert( nTimeScalerOutSamples <= APA_BUF ); + nSamplesTcsScaled = nTimeScalerOutSamples / nTransportChannels; + hIvasDec->timeScalingDone = 1; + } + else + { + nSamplesTcsScaled = hIvasDec->nSamplesFrame; + } + +#ifdef DEBUG_MODE_JBM + dbgwrite( &nTimeScalerOutSamples, sizeof( uint16_t ), 1, 1, "./res/JBM_nTimeScaleOutSamples.dat" ); +#endif + /*-----------------------------------------------------------------* + * 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 + +#ifdef DEBUG_MODE_JBM + dbgwrite( &nResidualSamples, sizeof( int16_t ), 1, 1, "./res/JBM_nResidualSamples.dat" ); +#endif + 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 ) { - *needNewFrame = false; + return IVAS_ERR_UNKNOWN; } } + hIvasDec->hasBeenFedFrame = false; } - *nOutSamples = nSamplesRendered; + /* render IVAS frames directly to the output buffer */ + 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 ) + { + return error; + } - return IVAS_ERR_OK; + nSamplesRendered += nSamplesRendered_loop; + nSamplesToRender -= nSamplesRendered_loop; + if ( hIvasDec->nSamplesAvailableNext == 0 ) + { + *needNewFrame = true; + hIvasDec->needNewFrame = true; + } + else + { + *needNewFrame = false; + } +} +} + +*nOutSamples = nSamplesRendered; + +return IVAS_ERR_OK; } @@ -1547,7 +1687,7 @@ ivas_error IVAS_DEC_GetNumObjects( } 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 ) #else - if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == SBA_ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT ) + if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == SBA_ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT ) #endif { *numObjects = hIvasDec->st_ivas->nchan_ism; @@ -1730,7 +1870,7 @@ ivas_error IVAS_DEC_GetObjectMetadata( } 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 ) #else - if ( st_ivas->ivas_format != ISM_FORMAT && st_ivas->ivas_format != MASA_ISM_FORMAT && 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 ) #endif { return IVAS_ERR_WRONG_MODE; @@ -1745,7 +1885,7 @@ ivas_error IVAS_DEC_GetObjectMetadata( #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT if ( hIsmMeta == NULL || zero_flag || ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) #else - if ( hIsmMeta == NULL || zero_flag ) + if ( hIsmMeta == NULL || zero_flag ) #endif { metadata->azimuth = 0.f; @@ -2386,7 +2526,7 @@ ivas_error IVAS_DEC_GetDelay( #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT nSamples[1] = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbSynDec[0], hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ); #else - nSamples[1] = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], hDecoderConfig->output_config ) ); + nSamples[1] = NS2SA( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], hDecoderConfig->output_config ) ); #endif nSamples[2] = (int16_t) roundf( (float) st_ivas->binaural_latency_ns * hDecoderConfig->output_Fs / 1000000000.f ); nSamples[0] = nSamples[1] + nSamples[2]; @@ -3296,7 +3436,7 @@ static ivas_error printConfigInfo_dec( #ifdef FIX_VOIP_FUNCTIONS ivas_error IVAS_DEC_PrintConfig( #else -void IVAS_DEC_PrintConfig( + void IVAS_DEC_PrintConfig( #endif const IVAS_DEC_HANDLE hIvasDec, const bool quietModeEnabled, @@ -3314,7 +3454,7 @@ void IVAS_DEC_PrintConfig( #ifdef FIX_VOIP_FUNCTIONS return IVAS_ERR_OK; #else - return; + return; #endif } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 31d40bd78..2d637329a 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -122,7 +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 : output configuration */ +#ifndef LIB_DEC_REVISION const bool tsmEnabled, /* i : enable time scale modification */ +#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 */ @@ -282,9 +284,17 @@ 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 +#endif ivas_error IVAS_DEC_TSM_SetQuality( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const float quality /* i : target TSM quality */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const float quality /* i : target TSM quality */ ); /*! r: error code */ @@ -470,12 +480,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 53056dd81327579cb7d6c10d119033c1d4bc5128 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 16 Oct 2025 15:46:44 +0200 Subject: [PATCH 2/3] fix merging --- lib_dec/lib_dec.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index d16b14387..8bce7e08f 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2470,11 +2470,7 @@ ivas_error IVAS_DEC_GetNumObjects( } } -#ifndef LIB_DEC_REVISION 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 ) -#else - if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == SBA_ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT ) -#endif { *numObjects = hIvasDec->st_ivas->nchan_ism; } -- GitLab From a17e302eeb20acddca2b6bf9e339c65a3bc8eef6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 16 Oct 2025 18:33:44 +0200 Subject: [PATCH 3/3] addition --- lib_dec/lib_dec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 8bce7e08f..7859e4fb0 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -54,7 +54,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 */ -- GitLab