diff --git a/apps/decoder.c b/apps/decoder.c index 968fcb2533aaa24198a3847b658cc237f2fa82a9..52a617990802948ddd777e87314e4cb7f628b888 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -429,7 +429,6 @@ int main( } } - /*------------------------------------------------------------------------------------------* * Configure the decoder *------------------------------------------------------------------------------------------*/ @@ -437,8 +436,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.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.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.delayCompensationEnabled ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -1049,18 +1054,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++; } @@ -1210,6 +1227,10 @@ static bool parseCmdlIVAS_dec( { if ( !is_digits_only( argv[i] ) ) { +#ifdef LIB_DEC_REVISION + fprintf( stderr, "Error: Render frame size is invalid or not specified!\n\n" ); + usage_dec(); +#endif return false; } @@ -1845,6 +1866,7 @@ static ivas_error initOnFirstGoodFrame( return error; } +#ifndef LIB_DEC_REVISION int32_t pcmFrameSize; if ( ( error = IVAS_DEC_GetPcmFrameSize( hIvasDec, &pcmFrameSize ) ) != IVAS_ERR_OK ) @@ -1852,7 +1874,7 @@ static ivas_error initOnFirstGoodFrame( fprintf( stderr, "\nError in IVAS_DEC_GetPcmFrameSize, error code: %d\n", error ); return error; } - +#endif if ( isSplitRend ) { /* Open split rendering metadata writer */ @@ -1910,7 +1932,24 @@ 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 ) @@ -2137,6 +2176,19 @@ static ivas_error decodeG192( #endif #endif +#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 ); @@ -2561,7 +2613,11 @@ static ivas_error decodeG192( } else { +#ifdef LIB_DEC_REVISION + if ( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3459,7 +3515,11 @@ 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; } @@ -3471,6 +3531,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_com/ivas_prot.h b/lib_com/ivas_prot.h index 271720f50cc72214f9095a6a307456918beaf014..b901e87a25109a68dd2f278cc2fee2e161570a17 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -817,8 +817,11 @@ 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 c640d2b9332933b49de95ecbc30f986bbe2a361d..c1da3e1165568c29e387114850e8ed96000e50f8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -195,6 +195,7 @@ #define FIX_1384_MSAN_ivas_spar_dec_open /* VA: issue 1386: fix use-of-uninitialized value in ivas_spar_dec_open() */ #define FIX_1388_MSAN_ivas_init_decoder /* VA: issue 1388: fix use-of-uninitialized value in ivas_init_decoder() */ #define FIX_1288_SPLIT_REND_XSAN /* Dlb: Fix asan, msan and usan issues in split rendering mode*/ +#define LIB_DEC_REVISION /* VA: cleaning and simplification of lib_dec.c */ // object-editing feature porting #define OBJ_EDITING_API /* object editing changes related to the API */ diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index b50829f879077329035e0af906a6bf28302b4221..1802de0856bfbd3e564145f7de46a2da917344b5 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -66,8 +66,11 @@ 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; @@ -727,11 +730,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 8f7c9525201518ecf2726c488046176565c05bbb..2f77238005f3e5ecf86a79c6cb15a5e72595fc32 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -57,7 +57,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 */ @@ -81,8 +83,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; @@ -92,7 +96,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 */ @@ -114,19 +120,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 ); 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 ); @@ -177,7 +196,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; @@ -200,7 +221,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*/ @@ -340,7 +363,7 @@ static void init_decoder_config( /*---------------------------------------------------------------------* * IVAS_DEC_Close( ) * - * + * Deallocate IVAS decoder memory handles *---------------------------------------------------------------------*/ void IVAS_DEC_Close( @@ -355,7 +378,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; } @@ -422,19 +449,46 @@ 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( - 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 */ @@ -492,7 +546,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; @@ -539,6 +595,7 @@ 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; @@ -553,6 +610,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 #endif return IVAS_ERR_OK; @@ -758,7 +816,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 ) { @@ -783,7 +843,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 @@ -814,6 +876,14 @@ ivas_error IVAS_DEC_EnableVoIP( } #endif +#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 #ifdef OBJ_EDITING_API /* 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 ) ) @@ -822,6 +892,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 #endif return IVAS_ERR_OK; @@ -927,7 +998,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; @@ -1186,6 +1259,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 ) { @@ -1199,10 +1279,23 @@ 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->apaExecBuffer != NULL; +#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; @@ -1227,21 +1320,68 @@ ivas_error IVAS_DEC_GetSamplesDecoder( 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; + } + + hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */ + } + + if ( hIvasDec->hasBeenFedFirstGoodFrame ) + { + 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 ( hIvasDec->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; } +#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; @@ -1256,11 +1396,18 @@ 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 if ( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { @@ -1272,8 +1419,13 @@ ivas_error IVAS_DEC_GetSamplesDecoder( } hIvasDec->hasBeenFedFrame = false; } + hIvasDec->hasBeenPreparedRendering = false; + /*-----------------------------------------------------------------* + * Set editable metadata + *-----------------------------------------------------------------*/ + if ( hIvasDec->st_ivas->hIsmMetaData[0] ) { if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT || hIvasDec->st_ivas->ivas_format == SBA_ISM_FORMAT ) @@ -1716,14 +1868,18 @@ ivas_error IVAS_DEC_PrepareRenderer( } #endif + /*---------------------------------------------------------------------* - * IVAS_DEC_GetSamples( ) + * IVAS_DEC_GetSamplesRenderer( ) * - * Main function to decode to PCM data + * Main function to render the decoded data to output data *---------------------------------------------------------------------*/ - +#ifdef LIB_DEC_REVISION +ivas_error IVAS_DEC_GetSamplesRenderer( +#else ivas_error IVAS_DEC_GetSamples( +#endif IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ @@ -1734,7 +1890,9 @@ ivas_error IVAS_DEC_GetSamples( { ivas_error error; #ifdef OBJ_EDITING_API +#ifndef LIB_DEC_REVISION int16_t nSamplesToRender; +#endif uint16_t nSamplesRendered, nSamplesRendered_loop; uint8_t nOutChannels; #else @@ -1742,6 +1900,7 @@ ivas_error IVAS_DEC_GetSamples( uint16_t nSamplesRendered, nSamplesRendered_loop, l_ts, nTimeScalerOutSamples; uint8_t nTransportChannels, nOutChannels; #endif + Decoder_Struct *st_ivas; nSamplesRendered = 0; nOutChannels = 0; @@ -1764,6 +1923,8 @@ ivas_error IVAS_DEC_GetSamples( } #endif + st_ivas = hIvasDec->st_ivas; + if ( hIvasDec->updateOrientation ) { /*----------------------------------------------------------------* @@ -1829,8 +1990,10 @@ ivas_error IVAS_DEC_GetSamples( } } #endif +#ifndef LIB_DEC_REVISION { - /* check if we need to run the setup function, tc decoding and feeding the renderer */ +/* check if we need to run the setup function, tc decoding and feeding the renderer */ +#endif #ifndef OBJ_EDITING_API if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { @@ -1896,38 +2059,61 @@ ivas_error IVAS_DEC_GetSamples( hIvasDec->hasBeenFedFrame = false; } #else - nOutChannels = (uint8_t) hIvasDec->st_ivas->hDecoderConfig->nchan_out; - hIvasDec->hasBeenFedFrame = false; - /* check for possible flushed samples from a rate switch */ - if ( hIvasDec->nSamplesFlushed > 0 ) - { - void *pPcmBuffer; -#ifdef DEBUGGING - assert( hIvasDec->pcmType == pcmType ); + nOutChannels = (uint8_t) hIvasDec->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 - pPcmBuffer = pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ); - if ( pcmType == IVAS_DEC_PCM_INT16 ) - { - mvs2s( (int16_t *) hIvasDec->flushbuffer, pPcmBuffer, hIvasDec->nSamplesFlushed * nOutChannels ); - } - else if ( pcmType == IVAS_DEC_PCM_FLOAT ) - { - mvr2r( (float *) hIvasDec->flushbuffer, pPcmBuffer, hIvasDec->nSamplesFlushed * nOutChannels ); - } #ifdef DEBUGGING - else - { - assert( 0 && "wrong PCM type for the flush buffer!" ); - } + 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 - nSamplesRendered += hIvasDec->nSamplesFlushed; - hIvasDec->nSamplesFlushed = 0; } + 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 + { + 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; + } #endif /* 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 ) +#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; } @@ -1945,7 +2131,9 @@ ivas_error IVAS_DEC_GetSamples( *needNewFrame = false; } #endif +#ifndef LIB_DEC_REVISION } +#endif } #ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST @@ -2063,7 +2251,11 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( } /* Decode and render */ +#ifdef LIB_DEC_REVISION + if ( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, numSamplesPerChannelToDecode, IVAS_DEC_PCM_FLOAT, pcmBuf, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_GetSamples( hIvasDec, numSamplesPerChannelToDecode, IVAS_DEC_PCM_FLOAT, pcmBuf, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2180,6 +2372,20 @@ 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 */ + 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( ) * @@ -2191,6 +2397,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; @@ -2211,6 +2418,17 @@ 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 @@ -2228,7 +2446,9 @@ 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 /*-----------------------------------------------------------------* * ISAR: @@ -2236,7 +2456,11 @@ static ivas_error IVAS_DEC_Setup( * - 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 ) { @@ -2256,7 +2480,7 @@ static ivas_error IVAS_DEC_Setup( return IVAS_ERR_OK; } - +#ifndef LIB_DEC_REVISION /*---------------------------------------------------------------------* * IVAS_DEC_GetTcSamples( ) * @@ -2430,7 +2654,7 @@ static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( return IVAS_ERR_OK; } - +#endif /*---------------------------------------------------------------------* * IVAS_DEC_GetNumObjects( ) @@ -2449,6 +2673,7 @@ ivas_error IVAS_DEC_GetNumObjects( { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + if ( hIvasDec->st_ivas->hMasa != NULL ) { if ( hIvasDec->st_ivas->hMasa->config.input_ivas_format == MASA_ISM_FORMAT ) @@ -2456,6 +2681,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; @@ -2627,6 +2853,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; @@ -2638,6 +2865,7 @@ ivas_error IVAS_DEC_GetObjectMetadata( } hIsmMeta = st_ivas->hIsmMetaData[objectIdx]; + if ( hIsmMeta == NULL || zero_flag || ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) { metadata->azimuth = 0.f; @@ -3462,7 +3690,7 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( return IVAS_ERR_OK; } - +#ifndef LIB_DEC_REVISION /*---------------------------------------------------------------------* * IVAS_DEC_GetPcmFrameSize( ) * @@ -3490,7 +3718,7 @@ ivas_error IVAS_DEC_GetPcmFrameSize( return IVAS_ERR_OK; } - +#endif /*---------------------------------------------------------------------* * isSidFrame( ) @@ -3523,7 +3751,7 @@ static void bsCompactToSerial( uint16_t *serial, const uint16_t num_bits ) { -/* Bitstream conversion is not counted towards complexity and memory usage */ + /* Bitstream conversion is not counted towards complexity and memory usage */ #define WMC_TOOL_SKIP uint32_t i; uint8_t byte = 0; @@ -3671,6 +3899,44 @@ 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( ) * @@ -3707,6 +3973,7 @@ ivas_error IVAS_DEC_TSM_SetQuality( return IVAS_ERR_OK; } +#endif /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_GetSamples( ) @@ -3776,10 +4043,19 @@ 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; @@ -3886,7 +4162,9 @@ ivas_error IVAS_DEC_VoIP_GetSamples( if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesRendered = 0; +#endif } #ifdef OBJ_EDITING_API @@ -3907,7 +4185,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 ); } @@ -3920,16 +4200,21 @@ 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, 0 ) ) != IVAS_ERR_OK ) { return error; } - +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesFlushed = nSamplesFlushed_ref; - +#endif *bitstreamReadDone = false; +#ifdef LIB_DEC_REVISION + *parametersAvailableForEditing = true; + return IVAS_ERR_OK; +#endif } } @@ -3948,7 +4233,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples( #endif /* render IVAS frames directly to the output buffer */ +#ifdef LIB_DEC_REVISION + if ( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, *nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, *nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -3976,12 +4265,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; } @@ -4019,7 +4316,11 @@ 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, pcm_type_API_to_internal( pcmType ), pcmBuf ); +#else error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmType, pcmBuf ); +#endif } else { @@ -4078,7 +4379,11 @@ ivas_error IVAS_DEC_VoIP_Get_CA_offset( * *---------------------------------------------------------------------*/ +#ifdef LIB_DEC_REVISION +static void ivas_destroy_handle_VoIP( +#else static void IVAS_DEC_Close_VoIP( +#endif IVAS_DEC_VOIP *hVoIP /* i/o: IVAS decoder handle */ ) { @@ -4467,19 +4772,31 @@ 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, const int16_t nOutSamples, 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]; +#ifdef LIB_DEC_REVISION + 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] ); @@ -4541,6 +4858,27 @@ 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 // 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 ) { ivas_jbm_dec_copy_tc_no_tsm( st_ivas, p_output, nOutSamples ); @@ -4564,6 +4902,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; } @@ -4762,7 +5101,18 @@ static ivas_error input_format_API_to_internal( return IVAS_ERR_OK; } +#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() * @@ -4773,17 +5123,27 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uint16_t nTransportChannels, const uint16_t l_ts ) +#endif { int16_t apa_buffer_size; +#ifdef LIB_DEC_REVISION + uint16_t l_ts; + + l_ts = (uint16_t) hIvasDec->st_ivas->hTcBuffer->n_samples_granularity; + if ( !isInitialized_voip ) +#else 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; @@ -4841,12 +5201,16 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( } set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels ); +#ifndef LIB_DEC_REVISION } +#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; @@ -4858,8 +5222,10 @@ 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 } hIvasDec->nTransportChannelsOld = nTransportChannels; diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index b11f08323617deb46380be2394288ab8307c7a9d..da34c2f45b2e3b9f021f88665565083bf1fbe992 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -121,7 +121,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 */ @@ -165,7 +167,11 @@ ivas_error IVAS_DEC_GetSamplesDecoder( ); /*! r: decoder error code */ +#ifdef LIB_DEC_REVISION +ivas_error IVAS_DEC_GetSamplesRenderer( +#else ivas_error IVAS_DEC_GetSamples( +#endif IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ @@ -292,9 +298,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 */ @@ -495,12 +509,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 */