diff --git a/apps/decoder.c b/apps/decoder.c index 0bb428c4974c3501e2636f36efd5062e2f38f2e3..824b3487de0f50d53a6aca2da132aada23013bbb 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -405,12 +405,18 @@ 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_fx, 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_fx, arg.dpidEnabled, aeID, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } + if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg.renderFramesize ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -896,18 +902,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++; } @@ -988,6 +1006,11 @@ 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; } @@ -1588,6 +1611,7 @@ static ivas_error initOnFirstGoodFrame( return error; } +#ifndef LIB_DEC_REVISION int32_t pcmFrameSize; if ( ( error = IVAS_DEC_GetPcmFrameSize( hIvasDec, &pcmFrameSize ) ) != IVAS_ERR_OK ) @@ -1595,7 +1619,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 */ @@ -1653,7 +1677,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 ) @@ -1870,6 +1910,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 ); @@ -2224,7 +2277,11 @@ static ivas_error decodeG192( } else { +#ifdef LIB_DEC_REVISION + if ( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, ( 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; @@ -2264,6 +2321,9 @@ static ivas_error decodeG192( { if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, 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; } } @@ -3014,7 +3074,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; } diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index bc88119669d5f0d05641cfc55864d737d173dd5c..5775170bb37aba1093acc431fa40a9db3e361032 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -4216,12 +4216,15 @@ Word16 rand_triangular_signed_fx( Word64 var_32_fx( const Word32 *x, /* i : input vector */ const Word16 len, /* i : length of inputvector */ - Word16 q /* q : q-factor for the array */ + Word16 q /* q : q-factor for the array */ ); ivas_error ivas_jbm_dec_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef LIB_DEC_REVISION + , Word32 *data_fx +#endif ); ivas_error ivas_jbm_dec_flush_renderer_fx( diff --git a/lib_com/options.h b/lib_com/options.h index a43f4053df65dd7d350fa0f34d88c6200da80c0b..5536d712a8c7d75e039041b41602a7366a4f80a7 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -117,6 +117,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_INTERFACE /* Interface for object editing */ diff --git a/lib_dec/ivas_jbm_dec_fx.c b/lib_dec/ivas_jbm_dec_fx.c index 086102fdc1c39fd6e40fa65cb26bac98acc95afd..3112ad77a766aaa99263fecedb0de27da26eba1e 100644 --- a/lib_dec/ivas_jbm_dec_fx.c +++ b/lib_dec/ivas_jbm_dec_fx.c @@ -80,8 +80,11 @@ static Word16 ceil_fx16( *--------------------------------------------------------------------------*/ ivas_error ivas_jbm_dec_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *data_fx /*Q11*/ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef LIB_DEC_REVISION + , + Word32 *data_fx /*Q11*/ +#endif ) { Word16 ch, n, output_frame, nchan_out, i, ii; @@ -1482,11 +1485,15 @@ ivas_error ivas_jbm_dec_tc_fx( * Write IVAS transport channels *----------------------------------------------------------------*/ +#ifdef LIB_DEC_REVISION + IF( st_ivas->hDecoderConfig->Opt_tsm == 0 ) +#else IF( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) ) { ivas_syn_output_f_fx( p_output_fx, output_frame, st_ivas->hTcBuffer->nchan_transport_jbm, data_fx ); } ELSE +#endif { /* directly copy to tc buffers */ /*note : the q of cldfb buffers (imag/real) are needed to be Q_p_output - 5 here 6 is taken for that*/ diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index b7fc02d968c7d4614cd5fbe08f6bb011152f15db..7957d191693a2b13dfe087c72137a8fa0100f9f8 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -111,7 +111,9 @@ ivas_error IVAS_DEC_Configure( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const UWord32 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 */ @@ -155,7 +157,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 Word16 nSamplesAsked, /* i : number of samples wanted by the caller */ Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ @@ -281,11 +287,19 @@ ivas_error IVAS_DEC_VoIP_SetScale( const Word16 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 + ivas_error IVAS_DEC_TSM_SetQuality( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 quality /* i : target TSM quality Q14 */ ); +#endif /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ @@ -454,12 +468,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 */ Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels Q0 */ ); - +#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 */ diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 3d1c4366e6439df51cb2da4d3dad983927fae641..b6d608a251ac69b6749bb8506955214d628bdb2f 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -57,7 +57,9 @@ struct IVAS_DEC_VOIP { +#ifndef LIB_DEC_REVISION UWord16 nSamplesFrame; /* Total number of samples in a frame (includes number of channels) */ +#endif JB4_HANDLE hJBM; UWord16 lastDecodedWasActive; JB4_DATAUNIT_HANDLE hCurrentDataUnit; /* Points to the currently processed data unit */ @@ -81,8 +83,10 @@ struct IVAS_DEC bool isInitialized; Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ - bool Opt_VOIP; /* flag indicating VOIP mode with JBM */ - Word16 tsm_scale; /* scale for TSM operation */ +#ifdef DEBUGGING + bool Opt_VOIP; /* flag indicating VOIP mode with JBM */ +#endif + Word16 tsm_scale; /* scale for TSM operation */ Word16 tsm_max_scaling; Word16 timeScalingDone; /* have we done already one TSM in a 20ms frame? */ Word16 tsm_quality; /*Q14*/ @@ -92,7 +96,9 @@ struct IVAS_DEC bool hasBeenFedFrame; bool updateOrientation; UWord16 nSamplesAvailableNext; +#ifndef LIB_DEC_REVISION Word16 nSamplesRendered; +#endif Word16 nTransportChannelsOld; Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ @@ -113,19 +119,32 @@ struct IVAS_DEC * Local function declarations *---------------------------------------------------------------------*/ +#ifdef LIB_DEC_REVISION +static void ivas_destroy_handle_VoIP_fx( 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 UWord32 systemTimestamp_ms, const UWord16 extBufferedSamples, const Word32 output_Fs ); #endif +#ifdef LIB_DEC_REVISION +static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas ); +#else static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas, const Word16 nOutSamples, Word32 *floatBuf, Word16 *pcmBuf ); +#endif static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, Word16 *bitstream_format_internal, Word16 *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, UWord8 *nTransportChannels, const Word16 isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits ); +static ivas_error apa_setup( IVAS_DEC_HANDLE hIvasDec, const bool isInitialized_voip, const UWord16 nTransportChannels ); +#else static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const UWord16 nTransportChannels, const UWord16 l_ts ); static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, UWord16 *nTcBufferGranularity, UWord8 *nTransportChannels ); static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, Word32 *pcmBuf_fx, Word16 *nOutSamples ); static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, Word32 *pcmBuf ); static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const UWord16 nSamplesForRendering, UWord16 *nSamplesRendered, UWord16 *nSamplesAvailableNext, Word16 *pcmBuf ); static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( IVAS_DEC_HANDLE hIvasDec, Word16 *nSamplesBuffered ); +#endif static Word16 get_render_frame_size_ms( IVAS_RENDER_FRAMESIZE render_framesize ); static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesRendered ); static ivas_error isar_set_split_rend_setup( ISAR_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, const ISAR_SPLIT_REND_CONFIG_DATA *hSplitBinConfig, const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, ISAR_SPLIT_REND_BITS_DATA *splitRendBits ); @@ -175,7 +194,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; @@ -211,15 +232,17 @@ ivas_error IVAS_DEC_Open( move16(); hIvasDec->bitstreamformat = G192; + move16(); +#ifdef DEBUGGING hIvasDec->Opt_VOIP = 0; + move16(); +#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*/ move16(); move16(); move16(); - move16(); - move16(); /*-----------------------------------------------------------------* * Initialize IVAS-codec decoder state @@ -393,7 +416,7 @@ static void init_decoder_config( /*---------------------------------------------------------------------* * IVAS_DEC_Close( ) * - * + * Deallocate IVAS decoder memory handles *---------------------------------------------------------------------*/ void IVAS_DEC_Close( @@ -409,7 +432,11 @@ void IVAS_DEC_Close( IF( ( *phIvasDec )->hVoIP ) { +#ifdef LIB_DEC_REVISION + ivas_destroy_handle_VoIP_fx( ( *phIvasDec )->hVoIP ); +#else IVAS_DEC_Close_VoIP( ( *phIvasDec )->hVoIP ); +#endif ( *phIvasDec )->hVoIP = NULL; } @@ -476,19 +503,45 @@ 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_fx( + IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ +) +{ + hIvasDec->flushbuffer = (Word16 *) malloc( CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word16 ) ); + if ( hIvasDec->flushbuffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate JBM flush buffer" ); + } + + set16_fx( 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 UWord32 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 UWord32 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 */ @@ -558,7 +611,9 @@ ivas_error IVAS_DEC_Configure( move16(); } +#ifndef LIB_DEC_REVISION hDecoderConfig->Opt_tsm = (Word16) tsmEnabled; +#endif hDecoderConfig->Opt_LsCustom = (Word16) customLsOutputEnabled; hDecoderConfig->Opt_Headrotation = (Word16) enableHeadRotation; hDecoderConfig->orientation_tracking = orientation_tracking; @@ -569,6 +624,7 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_delay_comp = (Word16) delayCompensationEnabled; hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation; hDecoderConfig->Opt_dpid_on = (Word16) dpidEnabled; + IF( NE_32( (Word32) acousticEnvironmentId, 65535 ) ) { hDecoderConfig->Opt_aeid_on = TRUE; @@ -626,6 +682,7 @@ ivas_error IVAS_DEC_Configure( } hIvasDec->nSamplesFrame = (UWord16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ); +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesAvailableNext = 0; hIvasDec->nSamplesRendered = 0; hIvasDec->tsm_scale = 100; @@ -649,6 +706,7 @@ ivas_error IVAS_DEC_Configure( hIvasDec->flushbuffer = (void *) malloc( CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word16 ) ); set16_fx( (Word16 *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); } +#endif #endif return IVAS_ERR_OK; @@ -658,7 +716,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( @@ -688,7 +746,7 @@ ivas_error IVAS_DEC_EnableSplitRendering( /*---------------------------------------------------------------------* * get_render_framesize_ms( ) * - * Get the 5ms flag + * Get render framesize in ms *---------------------------------------------------------------------*/ static Word16 get_render_frame_size_ms( @@ -714,7 +772,7 @@ static Word16 get_render_frame_size_ms( /*---------------------------------------------------------------------* * IVAS_DEC_SetRenderFramesize( ) * - * Get the 5ms flag + * Set render framesize *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_SetRenderFramesize( @@ -744,10 +802,11 @@ ivas_error IVAS_DEC_SetRenderFramesize( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetGetRenderFramesize( ) * - * Get the 5ms flag + * Get render framesize *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetRenderFramesize( @@ -876,7 +935,7 @@ ivas_error IVAS_DEC_GetReferencesUpdateFrequency( /*---------------------------------------------------------------------* * 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( @@ -923,10 +982,13 @@ ivas_error IVAS_DEC_EnableVoIP( hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig; +#ifdef DEBUGGING hIvasDec->Opt_VOIP = 1; +#endif hDecoderConfig->Opt_tsm = 1; move16(); move16(); + IF( NE_16( (Word16) hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config ); @@ -946,8 +1008,10 @@ ivas_error IVAS_DEC_EnableVoIP( hIvasDec->hVoIP->lastDecodedWasActive = 0; move16(); hIvasDec->hVoIP->hCurrentDataUnit = NULL; +#ifndef LIB_DEC_REVISION hIvasDec->hVoIP->nSamplesFrame = (UWord16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ); move16(); +#endif hIvasDec->hVoIP->nSamplesRendered20ms = 0; move16(); @@ -979,12 +1043,21 @@ ivas_error IVAS_DEC_EnableVoIP( } #endif +#ifdef LIB_DEC_REVISION + /* init flush buffer (needed for binaural outputs) */ + IF( ( error = create_flush_buffer_fx( hIvasDec ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in create_flush_buffer , code: %d\n", error ); + return error; + } +#else #ifdef OBJ_EDITING_API IF( hIvasDec->flushbuffer == NULL && ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) { hIvasDec->flushbuffer = (void *) malloc( CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word16 ) ); set16_fx( (Word16 *) hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); } +#endif #endif return IVAS_ERR_OK; @@ -1118,9 +1191,13 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->needNewFrame = false; hIvasDec->hasBeenFedFrame = true; +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesRendered = 0; +#endif hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; +#ifndef LIB_DEC_REVISION move16(); +#endif move16(); move16(); move16(); @@ -1130,13 +1207,16 @@ ivas_error IVAS_DEC_FeedFrame_Serial( /*---------------------------------------------------------------------* - * 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 Word16 nSamplesAsked, /* i : number of samples wanted by the caller */ Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ @@ -1146,7 +1226,9 @@ ivas_error IVAS_DEC_GetSamples( { ivas_error error; #ifdef OBJ_EDITING_API +#ifndef LIB_DEC_REVISION Word16 nSamplesToRender; +#endif UWord16 nSamplesRendered, nSamplesRendered_loop; UWord16 nOutChannels; #else @@ -1154,6 +1236,7 @@ ivas_error IVAS_DEC_GetSamples( UWord16 nSamplesRendered, nSamplesRendered_loop, l_ts, nTimeScalerOutSamples; UWord8 nTransportChannels, nOutChannels; #endif + Decoder_Struct *st_ivas; nSamplesRendered = 0; nOutChannels = 0; @@ -1164,7 +1247,6 @@ ivas_error IVAS_DEC_GetSamples( move16(); move16(); #endif - move16(); move16(); move16(); @@ -1183,13 +1265,15 @@ ivas_error IVAS_DEC_GetSamples( } #endif + st_ivas = hIvasDec->st_ivas; + IF( hIvasDec->updateOrientation ) { /*----------------------------------------------------------------* * Combine orientations *----------------------------------------------------------------*/ - IF( NE_32( ( error = combine_external_and_head_orientations_dec( hIvasDec->st_ivas->hHeadTrackData, hIvasDec->st_ivas->hExtOrientationData, hIvasDec->st_ivas->hCombinedOrientationData ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = combine_external_and_head_orientations_dec( st_ivas->hHeadTrackData, st_ivas->hExtOrientationData, st_ivas->hCombinedOrientationData ) ), IVAS_ERR_OK ) ) { return error; } @@ -1198,11 +1282,11 @@ ivas_error IVAS_DEC_GetSamples( * Binaural split rendering setup *----------------------------------------------------------------*/ - IF( EQ_32( hIvasDec->st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( hIvasDec->st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { - IF( hIvasDec->st_ivas->hCombinedOrientationData != NULL ) + IF( st_ivas->hCombinedOrientationData != NULL ) { - isar_set_split_rend_ht_setup_fx( &hIvasDec->st_ivas->hSplitBinRend->splitrend, hIvasDec->st_ivas->hCombinedOrientationData->Quaternions, hIvasDec->st_ivas->hCombinedOrientationData->Rmat_fx ); + isar_set_split_rend_ht_setup_fx( &st_ivas->hSplitBinRend->splitrend, st_ivas->hCombinedOrientationData->Quaternions, st_ivas->hCombinedOrientationData->Rmat_fx ); } } @@ -1225,11 +1309,11 @@ ivas_error IVAS_DEC_GetSamples( test(); /* 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; move16(); - set16_fx( pcmBuf, 0, imult1616( hIvasDec->st_ivas->hDecoderConfig->nchan_out, nSamplesAsked ) ); + set16_fx( pcmBuf, 0, imult1616( st_ivas->hDecoderConfig->nchan_out, nSamplesAsked ) ); #ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST nSamplesRendered = nSamplesAsked; move16(); @@ -1261,11 +1345,13 @@ ivas_error IVAS_DEC_GetSamples( /* setup */ IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels ) ), IVAS_ERR_OK ) ) { - return error; + // return error; } } #endif +#ifndef LIB_DEC_REVISION { +#endif #ifndef OBJ_EDITING_API /* check if we need to run the setup function, tc decoding and feeding the renderer */ test(); @@ -1357,24 +1443,33 @@ ivas_error IVAS_DEC_GetSamples( move16(); } #else - nOutChannels = (UWord8) hIvasDec->st_ivas->hDecoderConfig->nchan_out; - hIvasDec->hasBeenFedFrame = false; - /* check for possible flushed samples from a rate switch */ - IF( GE_16( hIvasDec->nSamplesFlushed, 0 ) ) - { - /* note: offset (rendered samples) is always 0 */ - Copy( hIvasDec->flushbuffer, pcmBuf, imult1616( hIvasDec->nSamplesFlushed, nOutChannels ) ); + nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out; + hIvasDec->hasBeenFedFrame = false; - nSamplesRendered = add( nSamplesRendered, hIvasDec->nSamplesFlushed ); - hIvasDec->nSamplesFlushed = 0; - move16(); - move16(); - } + /* check for possible flushed samples from a rate switch */ + IF( GE_16( hIvasDec->nSamplesFlushed, 0 ) ) + { + /* note: offset (rendered samples) is always 0 */ + Copy( hIvasDec->flushbuffer, pcmBuf, imult1616( hIvasDec->nSamplesFlushed, nOutChannels ) ); + +#ifdef LIB_DEC_REVISION + nSamplesRendered = hIvasDec->nSamplesFlushed; +#else + nSamplesRendered = add( nSamplesRendered, hIvasDec->nSamplesFlushed ); +#endif + hIvasDec->nSamplesFlushed = 0; + move16(); + move16(); + } #endif /* render IVAS frames directly to the output buffer */ - nSamplesToRender = sub( nSamplesAsked, nSamplesRendered ); - IF( NE_32( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) ) +#ifdef LIB_DEC_REVISION + IF( ( error = ivas_jbm_dec_render_fx( st_ivas, sub( nSamplesAsked, nSamplesRendered ), &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ) != IVAS_ERR_OK ) +#else + nSamplesToRender = sub( nSamplesAsked, nSamplesRendered ); + IF( NE_32( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -1395,7 +1490,9 @@ ivas_error IVAS_DEC_GetSamples( move16(); } #endif +#ifndef LIB_DEC_REVISION } +#endif } #ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST @@ -1423,7 +1520,7 @@ ivas_error IVAS_DEC_GetSamples( /*---------------------------------------------------------------------* * IVAS_DEC_GetSplitBinauralBitstream( ) * - * + * Get split-rendering bitstream *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetSplitBinauralBitstream( @@ -1509,8 +1606,8 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( #endif IF( NE_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) && - ( EQ_32( hIvasDec->st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE ) || - EQ_16( hIvasDec->st_ivas->hRenderConfig->split_rend_config.dof, 0 ) ) ) + ( EQ_32( st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE ) || + EQ_16( st_ivas->hRenderConfig->split_rend_config.dof, 0 ) ) ) { numSamplesPerChannelToDecode = (Word16) ( output_Fs / FRAMES_PER_SEC ); // TODO remove division numSamplesPerChannelToDecode = (Word16) ( numSamplesPerChannelToDecode / MAX_PARAM_SPATIAL_SUBFRAMES ); // TODO remove division @@ -1544,7 +1641,11 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( } /* Decode and render */ +#ifdef LIB_DEC_REVISION + IF( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, numSamplesPerChannelToDecode, pcmBuf_out, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) +#else IF( ( error = IVAS_DEC_GetSamples( hIvasDec, numSamplesPerChannelToDecode, pcmBuf_out, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1703,6 +1804,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 */ + UWord8 *nTransportChannels, /* o : number of decoded transport PCM channels */ + const Word16 isSplitRend, /* i : split rendering enabled flag */ + ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ +) +#else /*---------------------------------------------------------------------* * IVAS_DEC_Setup( ) * @@ -1714,6 +1829,7 @@ static ivas_error IVAS_DEC_Setup( UWord16 *nTcBufferGranularity, /* o : granularity of the TC Buffer */ UWord8 *nTransportChannels /* o : number of decoded transport PCM channels */ ) +#endif { ivas_error error; @@ -1735,6 +1851,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 @@ -1743,20 +1870,20 @@ static ivas_error IVAS_DEC_Setup( * - reconfigure the decoder when the number of TC or IVAS total bitrate change *----------------------------------------------------------------*/ - IF( st_ivas->bfi == 0 ) + IF( EQ_16( st_ivas->bfi, 0 ) ) { + error = IVAS_ERR_OK; // this is just to help the clang-formatting keep alignments IF( ( error = ivas_dec_setup( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#ifdef DEBUGGING - int16_t a = 0; // this is just to help the clang-formatting keep alignments correct -#endif } *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_jbm; +#ifndef LIB_DEC_REVISION *nTcBufferGranularity = (UWord16) st_ivas->hTcBuffer->n_samples_granularity; move16(); +#endif move16(); /*-----------------------------------------------------------------* @@ -1766,7 +1893,11 @@ static ivas_error IVAS_DEC_Setup( *-----------------------------------------------------------------*/ test(); +#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 ) { @@ -1787,7 +1918,7 @@ static ivas_error IVAS_DEC_Setup( return IVAS_ERR_OK; } - +#ifndef LIB_DEC_REVISION /*---------------------------------------------------------------------* * IVAS_DEC_GetTcSamples( ) * @@ -1816,7 +1947,12 @@ static ivas_error IVAS_DEC_GetTcSamples( IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { +#ifdef LIB_DEC_REVISION + pcmBuf_fx[0] = 0; // TODO !!! + IF( NE_32( ( error = evs_dec_main_fx( st_ivas ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = evs_dec_main_fx( st_ivas, *nOutSamples, pcmBuf_fx, NULL ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -1869,7 +2005,11 @@ static ivas_error IVAS_DEC_GetTcSamples( } /* Function call: ivas_jbm_dec_tc function */ +#ifdef LIB_DEC_REVISION + IF( NE_32( ( error = ivas_jbm_dec_tc_fx( st_ivas ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_jbm_dec_tc_fx( st_ivas, pcmBuf_fx ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -2002,7 +2142,6 @@ static ivas_error IVAS_DEC_GetRenderedSamples( return error; } - /*---------------------------------------------------------------------* * IVAS_DEC_GetBufferedNumberOfSamples( ) * @@ -2033,7 +2172,7 @@ static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( return IVAS_ERR_OK; } - +#endif /*---------------------------------------------------------------------* * IVAS_DEC_GetNumObjects( ) @@ -2128,7 +2267,7 @@ ivas_error IVAS_DEC_GetFormat( /*---------------------------------------------------------------------* * getInputBufferSize() * - * + * Get size of output buffer in samples *---------------------------------------------------------------------*/ static Word16 getOutputBufferSize( @@ -2163,7 +2302,7 @@ static Word16 getOutputBufferSize( /*---------------------------------------------------------------------* * IVAS_DEC_GetOutputBufferSize() * - * + * Returns size of output buffer in samples *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetOutputBufferSize( @@ -2228,6 +2367,7 @@ ivas_error IVAS_DEC_GetNumOutputChannels( * * Get metadata of one object decoded in the most recent frame *---------------------------------------------------------------------*/ + 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 */ @@ -2250,7 +2390,7 @@ ivas_error IVAS_DEC_GetObjectMetadata( st_ivas = hIvasDec->st_ivas; - IF( hIvasDec->st_ivas->hMasa != NULL ) + IF( st_ivas->hMasa != NULL ) { IF( EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) ) { @@ -2353,9 +2493,11 @@ ivas_error IVAS_DEC_GetObjectMetadata( move32(); move16(); move16(); + return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetMasaMetadata( ) * @@ -2479,7 +2621,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( @@ -2546,10 +2688,10 @@ ivas_error IVAS_DEC_FeedRefVectorData( hIvasDec->updateOrientation = true; move16(); - ivas_error error_fx = ivas_orient_trk_SetReferenceVector_fx( pOtr, listenerPos, refPos ); - return error_fx; + return ivas_orient_trk_SetReferenceVector_fx( pOtr, listenerPos, refPos ); } + /*---------------------------------------------------------------------* * IVAS_DEC_FeedExternalOrientationData( ) * @@ -2893,20 +3035,20 @@ ivas_error IVAS_DEC_HRTF_binary_close( IF( st_ivas->hDecoderConfig->Opt_HRTF_binary && st_ivas->ini_frame > 0 ) { test(); - IF( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + IF( !( EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_TDREND ) || EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) ) { ivas_HRTF_binary_close_fx( &st_ivas->hHrtfTD ); } test(); - IF( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + IF( !( EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_CREND ) || EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) ) { /* CRend binaural renderer handle */ ivas_HRTF_CRend_binary_close_fx( &st_ivas->hHrtfCrend ); } test(); - IF( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + IF( !( EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_FASTCONV ) || EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) ) { /* Fastconv HRTF memories */ ivas_binaural_hrtf_close_fx( &st_ivas->hHrtfFastConv ); @@ -2916,9 +3058,8 @@ ivas_error IVAS_DEC_HRTF_binary_close( } test(); - IF( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_PARAMBIN || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + IF( !( EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_PARAMBIN ) || EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) ) { - /* Parametric binauralizer HRTF filters */ ivas_HRTF_parambin_binary_close_fx( &st_ivas->hHrtfParambin ); } @@ -2972,7 +3113,7 @@ static ivas_error copyRendererConfigStruct( /*---------------------------------------------------------------------* * IVAS_DEC_GetRenderConfig( ) * - * + * Return renderer configuration parameters handle *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_GetRenderConfig( @@ -2992,6 +3133,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 */ @@ -3013,7 +3160,7 @@ ivas_error IVAS_DEC_GetDefaultRenderConfig( /*---------------------------------------------------------------------* * IVAS_DEC_FeedRenderConfig( ) * - * + * Set renderer configuration (acoustic environment) parameters *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_FeedRenderConfig( @@ -3022,6 +3169,7 @@ ivas_error IVAS_DEC_FeedRenderConfig( ) { RENDER_CONFIG_HANDLE hRenderConfig; + Decoder_Struct *st_ivas; ivas_error error; test(); @@ -3032,6 +3180,8 @@ ivas_error IVAS_DEC_FeedRenderConfig( } hRenderConfig = hIvasDec->st_ivas->hRenderConfig; + st_ivas = hIvasDec->st_ivas; + hRenderConfig->roomAcoustics.nBands = renderConfig.roomAcoustics.nBands; hRenderConfig->roomAcoustics.acousticPreDelay_fx = renderConfig.roomAcoustics.acousticPreDelay_fx; hRenderConfig->roomAcoustics.inputPreDelay_fx = renderConfig.roomAcoustics.inputPreDelay_fx; @@ -3061,9 +3211,9 @@ 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_fx( &hIvasDec->st_ivas->hReverb, hIvasDec->st_ivas->hHrtfStatistics, hRenderConfig, hIvasDec->st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -3072,19 +3222,19 @@ ivas_error IVAS_DEC_FeedRenderConfig( /* CREND Jot reverberator */ test(); test(); - 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_fx( &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_fx( &st_ivas->hCrendWrapper->hCrend[0]->hReverb, hIvasDec->st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } } - test(); /* FB reverberator */ - IF( hIvasDec->st_ivas->hDiracDecBin[0] != NULL && hIvasDec->st_ivas->hDiracDecBin[0]->hReverb != NULL ) + test(); + IF( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->hReverb != NULL ) { - ivas_binaural_reverb_close_fx( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ) ); + ivas_binaural_reverb_close_fx( &( st_ivas->hDiracDecBin[0]->hReverb ) ); IF( ( error = ivas_binaural_reverb_init_fx( &( 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 ) { @@ -3094,9 +3244,9 @@ ivas_error IVAS_DEC_FeedRenderConfig( test(); /* Fastconv CLDFB reverberator */ - IF( hIvasDec->st_ivas->hBinRenderer != NULL && hIvasDec->st_ivas->hBinRenderer->hReverb != NULL ) + IF( st_ivas->hBinRenderer != NULL && st_ivas->hBinRenderer->hReverb != NULL ) { - ivas_binaural_reverb_close_fx( &( hIvasDec->st_ivas->hBinRenderer->hReverb ) ); + ivas_binaural_reverb_close_fx( &( st_ivas->hBinRenderer->hReverb ) ); IF( ( error = ivas_binaural_reverb_init_fx( &( 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 ) { @@ -3115,7 +3265,7 @@ 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 ) { @@ -3202,7 +3352,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( @@ -3223,6 +3373,7 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( return IVAS_ERR_OK; } +#ifndef LIB_DEC_REVISION /*---------------------------------------------------------------------* * IVAS_DEC_GetPcmFrameSize( ) @@ -3255,6 +3406,8 @@ ivas_error IVAS_DEC_GetPcmFrameSize( return IVAS_ERR_OK; } +#endif + /*---------------------------------------------------------------------* * isSidFrame( ) @@ -3281,6 +3434,13 @@ static bool isSidFrame( return false; } + +/*---------------------------------------------------------------------* + * bsCompactToSerial( ) + * + * Bitstream conversion to Byte format + *---------------------------------------------------------------------*/ + static void bsCompactToSerial( const UWord8 *compact, UWord16 *serial, @@ -3468,6 +3628,51 @@ 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; + + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + hIvasDec->st_ivas->hDecoderConfig->Opt_tsm = 1; + move16(); + + /* Init flush buffer if necessary (only needed for binaural) */ + output_config = hIvasDec->st_ivas->hDecoderConfig->output_config; + + test(); + test(); + test(); + test(); + test(); + IF( hIvasDec->flushbuffer == NULL && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_32( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( 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( ) @@ -3508,6 +3713,7 @@ ivas_error IVAS_DEC_TSM_SetQuality( return IVAS_ERR_OK; } +#endif /*---------------------------------------------------------------------* * renderer_type_to_mode() @@ -3807,6 +4013,13 @@ ivas_error IVAS_DEC_GetSamplesDecoder( ) { ivas_error error; + Decoder_Struct *st_ivas; +#ifdef LIB_DEC_REVISION + UWord16 nTimeScalerOutSamples; + UWord8 nTransportChannels; + Word16 nResidualSamples, nSamplesTcsScaled; + bool isInitialized_voip; +#endif IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { @@ -3821,11 +4034,25 @@ 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. */ + st_ivas = hIvasDec->st_ivas; + +#ifdef LIB_DEC_REVISION + isInitialized_voip = hIvasDec->apaExecBuffer_fx != NULL; +#endif + test(); - IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) + 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 UWord16 l_ts, nTimeScalerOutSamples; UWord8 nTransportChannels; Word16 nResidualSamples, nSamplesTcsScaled, nOutSamplesElse; @@ -3850,21 +4077,70 @@ ivas_error IVAS_DEC_GetSamplesDecoder( return error; } } +#endif + +#ifdef LIB_DEC_REVISION + /*-----------------------------------------------------------------* + * IVAS decoder: decode transport channels and metadata + *-----------------------------------------------------------------*/ + IF( EQ_32( hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) + { + IF( ( error = evs_dec_main_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( EQ_32( hIvasDec->mode, IVAS_DEC_MODE_IVAS ) ) + { + IF( ( error = ivas_jbm_dec_tc_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */ + move16(); + } + + if ( hIvasDec->hasBeenFedFirstGoodFrame ) + { + hIvasDec->hasDecodedFirstGoodFrame = true; + move16(); + } +#else /* IVAS TC decoder */ IF( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ) != IVAS_ERR_OK ) { return error; } +#endif - /* JBM */ - IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) + /*-----------------------------------------------------------------* + * JBM + *-----------------------------------------------------------------*/ + + IF( st_ivas->hDecoderConfig->Opt_tsm ) { +#ifdef LIB_DEC_REVISION + IF( NE_16( nTransportChannels, hIvasDec->nTransportChannelsOld ) ) + { + IF( ( error = apa_setup( hIvasDec, isInitialized_voip, nTransportChannels ) ) != IVAS_ERR_OK ) + { + return error; + } + } + +#endif IF( apa_set_scale_fx( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 ) { return IVAS_ERR_UNKNOWN; } +#ifdef LIB_DEC_REVISION + ivas_syn_output_f_fx( st_ivas->p_output_fx, hIvasDec->nSamplesFrame, nTransportChannels, hIvasDec->apaExecBuffer_fx ); + +#endif + // tmp apaExecBuffer IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { @@ -3902,13 +4178,20 @@ 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_fx( st_ivas, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer_fx ); +#else IF( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer_fx ) ) != 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 ) @@ -3923,49 +4206,62 @@ ivas_error IVAS_DEC_GetSamplesDecoder( hIvasDec->hasBeenPreparedRendering = false; move16(); - IF( hIvasDec->st_ivas->hIsmMetaData[0] ) + /*-----------------------------------------------------------------* + * Set editable 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 ) + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { #ifdef OMASA_OBJECT_EDITING test(); test(); test(); - IF( EQ_32( hIvasDec->st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_32( hIvasDec->st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( hIvasDec->st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( hIvasDec->st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) #else - IF( hIvasDec->st_ivas->ism_mode == ISM_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( st_ivas->ism_mode == ISM_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_SBA_MODE_DISC ) #endif { Word16 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_fx = hIsmMetaData[obj]->azimuth_fx; + move32(); hIsmMetaData[obj]->edited_elevation_fx = hIsmMetaData[obj]->elevation_fx; + move32(); hIsmMetaData[obj]->edited_yaw_fx = hIsmMetaData[obj]->yaw_fx; + move32(); hIsmMetaData[obj]->edited_pitch_fx = hIsmMetaData[obj]->pitch_fx; + move32(); hIsmMetaData[obj]->edited_radius_fx = hIsmMetaData[obj]->radius_fx; - hIsmMetaData[obj]->edited_gain_fx = ONE_IN_Q29; // TODO: Check Q value + move32(); } - IF( hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + if ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - hIvasDec->st_ivas->hSbaIsmData->gain_bed_fx = ONE_IN_Q29; // TODO: Check Q value + st_ivas->hSbaIsmData->gain_bed_fx = ONE_IN_Q29; // TODO: Check Q value + move32(); } } } } - IF( hIvasDec->st_ivas->hParamIsmDec != NULL ) + IF( st_ivas->hParamIsmDec != NULL ) { - IF( hIvasDec->st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { Word16 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_fx[obj] = hParamIsmDec->azimuth_values_fx[obj]; hParamIsmDec->edited_elevation_values_fx[obj] = hParamIsmDec->elevation_values_fx[obj]; + move32(); + move32(); } } } @@ -4026,6 +4322,7 @@ ivas_error IVAS_DEC_GetEditableParameters( hIvasEditableParameters->num_obj = st_ivas->nchan_ism; move16(); + test(); test(); test(); IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) @@ -4083,50 +4380,65 @@ ivas_error IVAS_DEC_GetEditableParameters( } } #ifdef OMASA_OBJECT_EDITING - ELSE IF( hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT && ( hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { /* object editing possible only in two highest OMASA modes */ - IF( hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { FOR( obj = 0; obj < hIvasEditableParameters->num_obj; obj++ ) { - hIvasEditableParameters->ism_metadata[obj].azimuth_fx = hIvasDec->st_ivas->hIsmMetaData[obj]->azimuth_fx; - hIvasEditableParameters->ism_metadata[obj].elevation_fx = hIvasDec->st_ivas->hIsmMetaData[obj]->elevation_fx; - hIvasEditableParameters->ism_metadata[obj].yaw_fx = hIvasDec->st_ivas->hIsmMetaData[obj]->yaw_fx; - hIvasEditableParameters->ism_metadata[obj].pitch_fx = hIvasDec->st_ivas->hIsmMetaData[obj]->pitch_fx; - hIvasEditableParameters->ism_metadata[obj].radius_fx = hIvasDec->st_ivas->hIsmMetaData[obj]->radius_fx; + hIvasEditableParameters->ism_metadata[obj].azimuth_fx = st_ivas->hIsmMetaData[obj]->azimuth_fx; + move32(); + hIvasEditableParameters->ism_metadata[obj].elevation_fx = st_ivas->hIsmMetaData[obj]->elevation_fx; + move32(); + hIvasEditableParameters->ism_metadata[obj].yaw_fx = st_ivas->hIsmMetaData[obj]->yaw_fx; + move32(); + hIvasEditableParameters->ism_metadata[obj].pitch_fx = st_ivas->hIsmMetaData[obj]->pitch_fx; + move32(); + hIvasEditableParameters->ism_metadata[obj].radius_fx = st_ivas->hIsmMetaData[obj]->radius_fx; + move32(); /* reset the otherwise unused "gain" field for the object */ - hIvasDec->st_ivas->hIsmMetaData[obj]->edited_gain_fx = ONE_IN_Q29; - hIvasEditableParameters->ism_metadata[obj].gain_fx = hIvasDec->st_ivas->hIsmMetaData[obj]->edited_gain_fx; - hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = hIvasDec->st_ivas->hIsmMetaData[obj]->non_diegetic_flag; + st_ivas->hIsmMetaData[obj]->edited_gain_fx = ONE_IN_Q29; + move32(); + hIvasEditableParameters->ism_metadata[obj].gain_fx = st_ivas->hIsmMetaData[obj]->edited_gain_fx; + move32(); + hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = st_ivas->hIsmMetaData[obj]->non_diegetic_flag; + move16(); } } ELSE { /* Handle MONO output */ - IF( hIvasDec->st_ivas->renderer_type != RENDERER_MONO_DOWNMIX ) + IF( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) { - dirac_read_idx = hIvasDec->st_ivas->hSpatParamRendCom->render_to_md_map[hIvasDec->st_ivas->hSpatParamRendCom->subframes_rendered]; + dirac_read_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->subframes_rendered]; } ELSE { dirac_read_idx = 0; } + move16(); FOR( obj = 0; obj < hIvasEditableParameters->num_obj; obj++ ) { - hIvasEditableParameters->ism_metadata[obj].azimuth_fx = L_shl( L_deposit_l( hIvasDec->st_ivas->hMasaIsmData->azimuth_ism_fx[obj][dirac_read_idx] ), Q22 ); - hIvasEditableParameters->ism_metadata[obj].elevation_fx = L_shl( L_deposit_l( hIvasDec->st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ), Q22 ); + hIvasEditableParameters->ism_metadata[obj].azimuth_fx = L_shl( L_deposit_l( st_ivas->hMasaIsmData->azimuth_ism_fx[obj][dirac_read_idx] ), Q22 ); + hIvasEditableParameters->ism_metadata[obj].elevation_fx = L_shl( L_deposit_l( st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ), Q22 ); - hIvasEditableParameters->ism_metadata[obj].yaw_fx = hIvasDec->st_ivas->hIsmMetaData[obj]->yaw_fx; - hIvasEditableParameters->ism_metadata[obj].pitch_fx = hIvasDec->st_ivas->hIsmMetaData[obj]->pitch_fx; - hIvasEditableParameters->ism_metadata[obj].radius_fx = hIvasDec->st_ivas->hIsmMetaData[obj]->radius_fx; + hIvasEditableParameters->ism_metadata[obj].yaw_fx = st_ivas->hIsmMetaData[obj]->yaw_fx; + hIvasEditableParameters->ism_metadata[obj].pitch_fx = st_ivas->hIsmMetaData[obj]->pitch_fx; + hIvasEditableParameters->ism_metadata[obj].radius_fx = st_ivas->hIsmMetaData[obj]->radius_fx; + move32(); + move32(); + move32(); /* reset the otherwise unused "gain" field for the object */ - hIvasDec->st_ivas->hIsmMetaData[obj]->edited_gain_fx = ONE_IN_Q29; - hIvasEditableParameters->ism_metadata[obj].gain_fx = hIvasDec->st_ivas->hIsmMetaData[obj]->edited_gain_fx; - hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = hIvasDec->st_ivas->hIsmMetaData[obj]->non_diegetic_flag; + st_ivas->hIsmMetaData[obj]->edited_gain_fx = ONE_IN_Q29; + hIvasEditableParameters->ism_metadata[obj].gain_fx = st_ivas->hIsmMetaData[obj]->edited_gain_fx; + hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = st_ivas->hIsmMetaData[obj]->non_diegetic_flag; + move32(); + move32(); + move16(); } } } @@ -4187,6 +4499,8 @@ ivas_error IVAS_DEC_SetEditableParameters( assert( hIvasEditableParameters.num_obj == st_ivas->nchan_ism ); #endif + test(); + test(); test(); IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { @@ -4196,20 +4510,25 @@ ivas_error IVAS_DEC_SetEditableParameters( FOR( obj = 0; obj < hIvasEditableParameters.num_obj; obj++ ) { st_ivas->hIsmMetaData[obj]->edited_azimuth_fx = hIvasEditableParameters.ism_metadata[obj].azimuth_fx; + move32(); st_ivas->hIsmMetaData[obj]->edited_elevation_fx = hIvasEditableParameters.ism_metadata[obj].elevation_fx; + move32(); st_ivas->hIsmMetaData[obj]->edited_radius_fx = hIvasEditableParameters.ism_metadata[obj].radius_fx; - + move32(); st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx; - + move32(); st_ivas->hIsmMetaData[obj]->edited_yaw_fx = hIvasEditableParameters.ism_metadata[obj].yaw_fx; + move32(); st_ivas->hIsmMetaData[obj]->edited_pitch_fx = hIvasEditableParameters.ism_metadata[obj].pitch_fx; - + move32(); st_ivas->hIsmMetaData[obj]->non_diegetic_flag = hIvasEditableParameters.ism_metadata[obj].non_diegetic_flag; + move16(); } IF( EQ_32( ism_mode, ISM_SBA_MODE_DISC ) ) { st_ivas->hSbaIsmData->gain_bed_fx = hIvasEditableParameters.gain_bed_fx; + move32(); } } ELSE IF( EQ_32( ism_mode, ISM_MODE_PARAM ) ) @@ -4217,35 +4536,42 @@ ivas_error IVAS_DEC_SetEditableParameters( FOR( obj = 0; obj < hIvasEditableParameters.num_obj; obj++ ) { #ifdef OBJ_EDITING_PARAMISM_BIN - hIvasDec->st_ivas->hParamIsmDec->edited_azimuth_values_fx[obj] = hIvasEditableParameters.ism_metadata[obj].azimuth_fx; - hIvasDec->st_ivas->hParamIsmDec->edited_elevation_values_fx[obj] = hIvasEditableParameters.ism_metadata[obj].elevation_fx; - hIvasDec->st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 -> Q12 + st_ivas->hParamIsmDec->edited_azimuth_values_fx[obj] = hIvasEditableParameters.ism_metadata[obj].azimuth_fx; + move32(); + st_ivas->hParamIsmDec->edited_elevation_values_fx[obj] = hIvasEditableParameters.ism_metadata[obj].elevation_fx; + move32(); + st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 -> Q12 + move32(); /* Detect direction editing in Param-ISM mode */ - IF( GT_32( L_abs( L_sub( hIvasDec->st_ivas->hParamIsmDec->azimuth_values_fx[obj], hIvasEditableParameters.ism_metadata[obj].azimuth_fx ) ), OMASA_AZI_EDIT_THR_FX ) || - GT_32( L_abs( L_sub( hIvasDec->st_ivas->hParamIsmDec->elevation_values_fx[obj], hIvasEditableParameters.ism_metadata[obj].elevation_fx ) ), OMASA_ELE_EDIT_THR_FX ) ) + IF( GT_32( L_abs( L_sub( st_ivas->hParamIsmDec->azimuth_values_fx[obj], hIvasEditableParameters.ism_metadata[obj].azimuth_fx ) ), OMASA_AZI_EDIT_THR_FX ) || + GT_32( L_abs( L_sub( st_ivas->hParamIsmDec->elevation_values_fx[obj], hIvasEditableParameters.ism_metadata[obj].elevation_fx ) ), OMASA_ELE_EDIT_THR_FX ) ) { - hIvasDec->st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 1; + st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 1; } ELSE { - hIvasDec->st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 0; + st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 0; } + move16(); /* Detect gain editing in Param-ISM mode */ IF( GT_16( abs_s( sub( ONE_IN_Q12, shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ) ) ), OMASA_GAIN_EDIT_THR_FX ) ) // TODO: check Q values { - hIvasDec->st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 1; + st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 1; } ELSE { - hIvasDec->st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 0; + st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 0; } + move16(); #endif } + #ifdef OBJ_EDITING_PARAMISM_BIN /* MASA is not present with the ISM format */ - hIvasDec->st_ivas->hMasaIsmData->masa_gain_is_edited = 0; + st_ivas->hMasaIsmData->masa_gain_is_edited = 0; + move16(); #endif } ELSE @@ -4254,14 +4580,14 @@ ivas_error IVAS_DEC_SetEditableParameters( } } #ifdef OMASA_OBJECT_EDITING - ELSE IF( EQ_16( hIvasDec->st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( hIvasDec->st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( hIvasDec->st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) + ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { Word32 id_th; Word32 threshold_azi, threshold_ele; FOR( obj = 0; obj < hIvasEditableParameters.num_obj; obj++ ) { - IF( hIvasDec->st_ivas->hMasaIsmData != NULL ) + IF( st_ivas->hMasaIsmData != NULL ) { /* copy relevant fields also to OMASA structs, but only if the value has been changed. original values are in st_ivas->hIsmMetaData */ /* first, need to convert float values to ints used internally */ @@ -4278,12 +4604,12 @@ ivas_error IVAS_DEC_SetEditableParameters( new_ele = negate( new_ele ); } - IF( EQ_16( hIvasDec->st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { /* Handle MONO output */ - IF( NE_16( hIvasDec->st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) + IF( NE_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) { - dirac_read_idx = hIvasDec->st_ivas->hSpatParamRendCom->render_to_md_map[hIvasDec->st_ivas->hSpatParamRendCom->subframes_rendered]; + dirac_read_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->subframes_rendered]; } ELSE { @@ -4295,78 +4621,94 @@ ivas_error IVAS_DEC_SetEditableParameters( * which in turn depends from the object priority and importance: * importance -> priority -> number of bits -> elevation resolution -> elevation ring index -> azimuth resolution. * leading to elevation_resolution -> elevation threshold and azimuth resolution -> azimuth threshold */ - id_th = extract_l( L_shr( L_add( Mpy_32_16_1( delta_theta_masa_inv_fx[hIvasDec->st_ivas->hMasaIsmData->bits_ism[obj] - 3], abs_s( hIvasDec->st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ) ), 32768 ), 16 ) ); // + 0.5f in Q16 - threshold_azi = Mpy_32_32( 1509949440, no_phi_masa_inv_fx[hIvasDec->st_ivas->hMasaIsmData->bits_ism[obj] - 1][id_th] ); // Q = 22; - threshold_ele = delta_theta_masa_fx[hIvasDec->st_ivas->hMasaIsmData->bits_ism[obj] - 3]; + id_th = extract_l( L_shr( L_add( Mpy_32_16_1( delta_theta_masa_inv_fx[st_ivas->hMasaIsmData->bits_ism[obj] - 3], abs_s( st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ) ), 32768 ), 16 ) ); // + 0.5f in Q16 + threshold_azi = Mpy_32_32( 1509949440, no_phi_masa_inv_fx[st_ivas->hMasaIsmData->bits_ism[obj] - 1][id_th] ); // Q = 22; + threshold_ele = delta_theta_masa_fx[st_ivas->hMasaIsmData->bits_ism[obj] - 3]; test(); - IF( ( GT_32( L_shl( abs_s( sub( new_azi, hIvasDec->st_ivas->hMasaIsmData->azimuth_ism_fx[obj][dirac_read_idx] ) ), 22 ), threshold_azi ) ) || - ( GT_32( L_shl( abs_s( sub( new_ele, hIvasDec->st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ) ), 22 ), threshold_ele ) ) ) + IF( ( GT_32( L_shl( abs_s( sub( new_azi, st_ivas->hMasaIsmData->azimuth_ism_fx[obj][dirac_read_idx] ) ), 22 ), threshold_azi ) ) || + ( GT_32( L_shl( abs_s( sub( new_ele, st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ) ), 22 ), threshold_ele ) ) ) { /* at least one of the threshold is exceeded, so use new direction value and set editing detection flag */ - hIvasDec->st_ivas->hMasaIsmData->azimuth_ism_edited_fx[obj] = new_azi; - hIvasDec->st_ivas->hMasaIsmData->elevation_ism_edited_fx[obj] = new_ele; + st_ivas->hMasaIsmData->azimuth_ism_edited_fx[obj] = new_azi; + move32(); + st_ivas->hMasaIsmData->elevation_ism_edited_fx[obj] = new_ele; + move32(); - hIvasDec->st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 1; + st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 1; } ELSE { - hIvasDec->st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 0; + st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 0; } + move16(); } ELSE { /* detect editing in ISM_MASA_MODE_DISC. optionally, add quantization-resolution -based thresholds */ test(); - IF( L_abs( L_sub( hIvasDec->st_ivas->hIsmMetaData[obj]->azimuth_fx, hIvasEditableParameters.ism_metadata[obj].azimuth_fx ) ) > OMASA_AZI_EDIT_THR_FX || - L_abs( L_sub( hIvasDec->st_ivas->hIsmMetaData[obj]->elevation_fx, hIvasEditableParameters.ism_metadata[obj].elevation_fx ) ) > OMASA_ELE_EDIT_THR_FX ) + IF( L_abs( L_sub( st_ivas->hIsmMetaData[obj]->azimuth_fx, hIvasEditableParameters.ism_metadata[obj].azimuth_fx ) ) > OMASA_AZI_EDIT_THR_FX || + L_abs( L_sub( st_ivas->hIsmMetaData[obj]->elevation_fx, hIvasEditableParameters.ism_metadata[obj].elevation_fx ) ) > OMASA_ELE_EDIT_THR_FX ) { - hIvasDec->st_ivas->hMasaIsmData->azimuth_ism_edited_fx[obj] = new_azi; - hIvasDec->st_ivas->hMasaIsmData->elevation_ism_edited_fx[obj] = new_ele; + st_ivas->hMasaIsmData->azimuth_ism_edited_fx[obj] = new_azi; + move32(); + st_ivas->hMasaIsmData->elevation_ism_edited_fx[obj] = new_ele; + move32(); - hIvasDec->st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 1; + st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 1; } ELSE { - hIvasDec->st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 0; + st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 0; } + move16(); } /* compare pre-edit gain and the edited one to detect editing */ - IF( GT_16( abs_s( sub( shr( extract_h( hIvasDec->st_ivas->hIsmMetaData[obj]->edited_gain_fx ), Q1 ), shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ) ) ), OMASA_GAIN_EDIT_THR_FX ) ) // TODO: check incoming Q value + IF( GT_16( abs_s( sub( shr( extract_h( st_ivas->hIsmMetaData[obj]->edited_gain_fx ), Q1 ), shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ) ) ), OMASA_GAIN_EDIT_THR_FX ) ) // TODO: check incoming Q value { - hIvasDec->st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 1; - hIvasDec->st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 --> Q12 + st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 1; + st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 --> Q12 + move16(); } ELSE { - hIvasDec->st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 0u; + st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 0u; } + move32(); } /* Copy edited values to hIsmMetaData struct */ - IF( hIvasDec->st_ivas->hIsmMetaData[obj] != NULL ) + IF( st_ivas->hIsmMetaData[obj] != NULL ) { - hIvasDec->st_ivas->hIsmMetaData[obj]->azimuth_fx = hIvasEditableParameters.ism_metadata[obj].azimuth_fx; - hIvasDec->st_ivas->hIsmMetaData[obj]->elevation_fx = hIvasEditableParameters.ism_metadata[obj].elevation_fx; - hIvasDec->st_ivas->hIsmMetaData[obj]->yaw_fx = hIvasEditableParameters.ism_metadata[obj].yaw_fx; - hIvasDec->st_ivas->hIsmMetaData[obj]->pitch_fx = hIvasEditableParameters.ism_metadata[obj].pitch_fx; - hIvasDec->st_ivas->hIsmMetaData[obj]->radius_fx = hIvasEditableParameters.ism_metadata[obj].radius_fx; - hIvasDec->st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx; // TODO: check incoming Q value - hIvasDec->st_ivas->hIsmMetaData[obj]->non_diegetic_flag = hIvasEditableParameters.ism_metadata[obj].non_diegetic_flag; + st_ivas->hIsmMetaData[obj]->azimuth_fx = hIvasEditableParameters.ism_metadata[obj].azimuth_fx; + move32(); + st_ivas->hIsmMetaData[obj]->elevation_fx = hIvasEditableParameters.ism_metadata[obj].elevation_fx; + move32(); + st_ivas->hIsmMetaData[obj]->yaw_fx = hIvasEditableParameters.ism_metadata[obj].yaw_fx; + move32(); + st_ivas->hIsmMetaData[obj]->pitch_fx = hIvasEditableParameters.ism_metadata[obj].pitch_fx; + move32(); + st_ivas->hIsmMetaData[obj]->radius_fx = hIvasEditableParameters.ism_metadata[obj].radius_fx; + move32(); + st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx; // TODO: check incoming Q value + move32(); + st_ivas->hIsmMetaData[obj]->non_diegetic_flag = hIvasEditableParameters.ism_metadata[obj].non_diegetic_flag; + move16(); } } IF( GT_16( abs_s( sub( shr( extract_h( hIvasEditableParameters.gain_bed_fx ), Q1 ), ONE_IN_Q12 ) ), OMASA_GAIN_EDIT_THR_FX ) ) // TODO: check Q value { - hIvasDec->st_ivas->hMasaIsmData->gain_masa_edited_fx = shr( extract_h( hIvasEditableParameters.gain_bed_fx ), Q1 ); // TODO: check type + st_ivas->hMasaIsmData->gain_masa_edited_fx = shr( extract_h( hIvasEditableParameters.gain_bed_fx ), Q1 ); // TODO: check type move32(); - hIvasDec->st_ivas->hMasaIsmData->masa_gain_is_edited = 1; + st_ivas->hMasaIsmData->masa_gain_is_edited = 1; } ELSE { - hIvasDec->st_ivas->hMasaIsmData->masa_gain_is_edited = 0; + st_ivas->hMasaIsmData->masa_gain_is_edited = 0; } + move16(); } #endif @@ -4383,7 +4725,8 @@ ivas_error IVAS_DEC_SetEditableParameters( ivas_error IVAS_DEC_PrepareRenderer( IVAS_DEC_HANDLE hIvasDec ) { - IF( hIvasDec == NULL ) + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } @@ -4397,6 +4740,7 @@ ivas_error IVAS_DEC_PrepareRenderer( } hIvasDec->hasBeenPreparedRendering = true; + move16(); return IVAS_ERR_OK; } @@ -4475,6 +4819,19 @@ ivas_error IVAS_DEC_VoIP_GetSamples( Word16 nSamplesBuffered; nSamplesBuffered = 0; move16(); + +#ifdef LIB_DEC_REVISION + IF( hIvasDec->hasBeenFedFirstGoodFrame ) + { + /* check if the TC buffer already exists, otherweise nothing is buffered anyway */ + + IF( st_ivas->hTcBuffer != NULL ) + { + nSamplesBuffered = sub( st_ivas->hTcBuffer->n_samples_buffered, st_ivas->hTcBuffer->n_samples_rendered ); + nSamplesBuffered = add( nSamplesBuffered, hVoIP->nSamplesRendered20ms ); + } + } +#else IF( hIvasDec->hasBeenFedFirstGoodFrame ) { IF( NE_32( ( error = IVAS_DEC_GetBufferedNumberOfSamples( hIvasDec, &nSamplesBuffered ) ), IVAS_ERR_OK ) ) @@ -4482,6 +4839,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( return error; } } +#endif extBufferedSamples = nSamplesBuffered; move16(); @@ -4605,8 +4963,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( IF( !hIvasDec->hasBeenFedFirstGoodFrame ) { hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; +#ifndef LIB_DEC_REVISION hIvasDec->nSamplesRendered = 0; move16(); +#endif move16(); } @@ -4629,7 +4989,13 @@ ivas_error IVAS_DEC_VoIP_GetSamples( Word16 nSamplesToZero = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext ); set16_fx( pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), 0, imult1616( nSamplesToZero, nOutChannels ) ); *nSamplesRendered = add( *nSamplesRendered, nSamplesToZero ); +#ifndef LIB_DEC_REVISION +#ifndef OBJ_EDITING_API + nSamplesRendered = add( nSamplesRendered, nSamplesToZero ); +#else hIvasDec->nSamplesRendered = add( hIvasDec->nSamplesRendered, nSamplesToZero ); +#endif +#endif hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesToZero ); move16(); move16(); @@ -4646,16 +5012,18 @@ ivas_error IVAS_DEC_VoIP_GetSamples( test(); IF( hIvasDec->nSamplesAvailableNext == 0 || EQ_16( 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; move16(); - +#endif *bitstreamReadDone = false; move16(); } @@ -4676,7 +5044,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples( #endif /* render IVAS frames directly to the output buffer */ +#ifdef LIB_DEC_REVISION + IF( NE_32( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -4693,7 +5065,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( /*---------------------------------------------------------------------* * update_voip_rendered20ms( ) * - * Function to flush remaining audio in VoIP + * pdate the number of samples that have been rendered since the last 20ms render border *---------------------------------------------------------------------*/ static void update_voip_rendered20ms( @@ -4705,7 +5077,11 @@ static void update_voip_rendered20ms( nSamplesRenderedTotal = add( hIvasDec->hVoIP->nSamplesRendered20ms, nSamplesRendered ); /* we have crossed a 20ms border, reset the time scaling done flag */ +#ifdef LIB_DEC_REVISION + IF( GE_16( nSamplesRenderedTotal, hIvasDec->nSamplesFrame ) ) +#else IF( GE_16( nSamplesRenderedTotal, hIvasDec->hVoIP->nSamplesFrame ) ) +#endif { hIvasDec->timeScalingDone = 0; move16(); @@ -4714,9 +5090,17 @@ static void update_voip_rendered20ms( /* float code was: hIvasDec->hVoIP->nSamplesRendered20ms = nSamplesRenderedTotal % hIvasDec->hVoIP->nSamplesFrame; */ hIvasDec->hVoIP->nSamplesRendered20ms = nSamplesRenderedTotal; move16(); +#ifdef LIB_DEC_REVISION + WHILE( GE_16( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->nSamplesFrame ) ) +#else WHILE( GE_16( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->hVoIP->nSamplesFrame ) ) +#endif { +#ifdef LIB_DEC_REVISION + hIvasDec->hVoIP->nSamplesRendered20ms = sub( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->nSamplesFrame ); +#else hIvasDec->hVoIP->nSamplesRendered20ms = sub( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->hVoIP->nSamplesFrame ); +#endif } return; @@ -4726,7 +5110,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( @@ -4760,7 +5144,11 @@ ivas_error IVAS_DEC_Flush( test(); IF( GT_16( nSamplesToRender, 0 ) && NE_16( (Word16) hIvasDec->st_ivas->ivas_format, (Word16) MONO_FORMAT ) ) { +#ifdef LIB_DEC_REVISION + error = ivas_jbm_dec_render_fx( hIvasDec->st_ivas, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf ); +#else error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf ); +#endif } ELSE { @@ -4821,12 +5209,16 @@ 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_fx( +#else static void IVAS_DEC_Close_VoIP( +#endif IVAS_DEC_VOIP *hVoIP /* i/o: IVAS decoder handle */ ) { @@ -5179,16 +5571,23 @@ void IVAS_DEC_PrintDisclaimer( void ) *---------------------------------------------------------------------*/ static ivas_error evs_dec_main_fx( - Decoder_Struct *st_ivas, + Decoder_Struct *st_ivas +#ifndef LIB_DEC_REVISION + , const Word16 nOutSamples, Word32 *Buf_fx, // Q11 Word16 *pcmBuf // Q0 +#endif ) { DEC_CORE_HANDLE *hCoreCoder; Word16 mixer_left_fx, mixer_right_fx; Word32 *p_output_fx[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN]; +#ifdef LIB_DEC_REVISION + Word16 ch, i, nOutSamples; +#else Word16 ch, n, i; +#endif Word16 output_16[L_FRAME48k]; ivas_error error; @@ -5197,6 +5596,10 @@ static ivas_error evs_dec_main_fx( move32(); hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); // Q0 move16(); +#ifdef LIB_DEC_REVISION + nOutSamples = hCoreCoder[0]->output_frame_fx; + move16(); +#endif mdct_switching_dec_fx( hCoreCoder[0] ); @@ -5264,6 +5667,24 @@ static ivas_error evs_dec_main_fx( v_multc_fx_16( p_output_fx[0], mixer_left_fx, p_output_fx[0], nOutSamples ); /* Q11 */ } +#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 */ + Word32 pcm_buf_local[L_FRAME48k]; + + FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) + { + ivas_syn_output_f_fx( &p_output_fx[ch], nOutSamples, 1, pcm_buf_local ); + + Copy32( pcm_buf_local, p_output_fx[ch], nOutSamples ); + } + } + ELSE // ToDo: the 'else' branch can be removed once UNIFIED_DECODING_PATHS_LEFTOVERS is merged + { + ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, nOutSamples ); + } +#else IF( !st_ivas->hDecoderConfig->Opt_tsm ) { ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, nOutSamples ); @@ -5291,6 +5712,7 @@ static ivas_error evs_dec_main_fx( } } } +#endif return IVAS_ERR_OK; } @@ -5345,6 +5767,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 UWord16 nTransportChannels ) +#else /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_reconfigure() * @@ -5355,18 +5789,29 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const UWord16 nTransportChannels, const UWord16 l_ts ) +#endif { Word16 apa_buffer_size; +#ifdef LIB_DEC_REVISION + UWord16 l_ts; + + l_ts = (UWord16) hIvasDec->st_ivas->hTcBuffer->n_samples_granularity; + move16(); + IF( !isInitialized_voip ) +#else apa_buffer_size = hIvasDec->nSamplesFrame; move16(); IF( hIvasDec->apaExecBuffer_fx == NULL ) +#endif { DECODER_CONFIG_HANDLE hDecoderConfig; +#ifndef LIB_DEC_REVISION IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { +#endif UWord16 wss, css; Word32 startQuality; @@ -5431,32 +5876,35 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( } set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ); +#ifndef LIB_DEC_REVISION } +#endif } - ELSE - { - IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) - { - IF( apa_reconfigure( hIvasDec->hTimeScaler, nTransportChannels, l_ts ) != 0 ) - { + 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; - } - apa_buffer_size = APA_BUF_PER_CHANNEL; - move16(); - free( hIvasDec->apaExecBuffer_fx ); - IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); - } - set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ); - } - /* realloc apa_exe_buffer */ - } +} +apa_buffer_size = APA_BUF_PER_CHANNEL; +move16(); +free( hIvasDec->apaExecBuffer_fx ); +IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) +{ + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); +} +set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ); +#ifndef LIB_DEC_REVISION +} +/* realloc apa_exe_buffer */ +#endif +} - hIvasDec->nTransportChannelsOld = nTransportChannels; - move16(); +hIvasDec->nTransportChannelsOld = nTransportChannels; +move16(); - return IVAS_ERR_OK; +return IVAS_ERR_OK; } @@ -5553,7 +6001,7 @@ ivas_error IVAS_DEC_GetCldfbSamples( /*-------------------------------------------------------------------* * ivas_create_handle_isar() * - * Initialize IVAS decoder split rend handle + * Initialize IVAS decoder split-rendering handle *-------------------------------------------------------------------*/ static ivas_error ivas_create_handle_isar( @@ -5852,7 +6300,7 @@ static ivas_error ivas_dec_init_split_rend( /*---------------------------------------------------------------------* * IVAS_DEC_is_split_rendering_coded_out() * - * + * Return flag to indicate if split rendering is enabled *---------------------------------------------------------------------*/ Word16 IVAS_DEC_is_split_rendering_coded_out(