Skip to content
......@@ -478,11 +478,7 @@ void decoder_LPD(
if ( bfi && st->last_core != ACELP_CORE )
{
/* PLC: [TCX: TD PLC] */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
con_tcx( st, &synthFB[0], -1.f, NULL, 0, NULL );
#else
con_tcx( st, &synthFB[0], -1.f, NULL, 0 );
#endif
lerp( synthFB, synth, st->L_frame, st->hTcxDec->L_frameTCX );
st->con_tcx = 1;
set_f( &st->mem_pitch_gain[2], st->lp_gainp, st->nb_subfr );
......@@ -650,11 +646,7 @@ void decoder_LPD(
TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB, L_frameTCX );
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
decoder_tcx_post( st, synth, synthFB, Aq, bfi, 0 );
#else
decoder_tcx_post( st, synth, synthFB, Aq, bfi );
#endif
if ( st->core == TCX_20_CORE )
{
......
......@@ -198,11 +198,7 @@ static void decode_frame_type(
st->rate_switching_init = 1;
/* Reconf Core */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
mode_switch_decoder_LPD( st, st->bwidth, st->total_brate, st->last_total_brate, frame_size_index, 0, st->element_mode );
#else
mode_switch_decoder_LPD( st, st->bwidth, st->total_brate, st->last_total_brate, frame_size_index, 0 );
#endif
/* Reconf. CLDFB: check if the CLDFB works on the right sample rate */
if ( ( st->cldfbAna->no_channels * st->cldfbAna->no_col ) != st->L_frame )
......
......@@ -54,11 +54,8 @@
void getTCXMode(
Decoder_State *st, /* i/o: decoder memory state */
Decoder_State *st0 /* i : bitstream */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
,
const int16_t MCT_flag
#endif
Decoder_State *st0, /* i : bitstream */
const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
)
{
uint16_t ind;
......@@ -94,7 +91,6 @@ void getTCXMode(
}
st->coder_type = INACTIVE;
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag )
{
st->VAD = get_next_indice( st0, 1 );
......@@ -103,9 +99,6 @@ void getTCXMode(
{
st->VAD = 0;
}
#else
st->VAD = 0;
#endif
}
else
{
......@@ -214,7 +207,7 @@ void getTCXMode(
void getTCXWindowing(
const int16_t core, /* i : current core */
const int16_t last_core, /* i : last frame core */
const int16_t element_mode,
const int16_t element_mode, /* i : element mode */
TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */
Decoder_State *st0 /* i : bitstream */
)
......@@ -793,11 +786,7 @@ void dec_prm(
*--------------------------------------------------------------------------------*/
/* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
getTCXMode( st, st, 0 /* <- MCT_flag */ );
#else
getTCXMode( st, st );
#endif
core = st->core;
/* Decode last_core for error concealment */
......
......@@ -98,17 +98,9 @@ void decoder_tcx(
init_tcx_info( st, L_frame_glob, L_frameTCX_glob, frame_cnt, bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec );
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
decoder_tcx_invQ( st, prm, A, Aind, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &xn_buf[0], &fUseTns, &tnsData, &gain_tcx, &prm_sqQ, &nf_seed, bfi, 0, /* <- isMCT */ frame_cnt );
#else
decoder_tcx_invQ( st, prm, A, Aind, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &xn_buf[0], &fUseTns, &tnsData, &gain_tcx, &prm_sqQ, &nf_seed, bfi, frame_cnt );
#endif
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
decoder_tcx_noisefilling( st, NULL, A, L_frameTCX_glob, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, 0, frame_cnt );
#else
decoder_tcx_noisefilling( st, A, L_frameTCX_glob, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, frame_cnt );
#endif
decoder_tcx_noiseshaping_igf( st, L_spec, L_frame, L_frameTCX, left_rect, &x[0], &gainlpc2[0], &tmp_concealment_method, bfi );
......@@ -128,15 +120,12 @@ void decoder_tcx(
*-------------------------------------------------------------------*/
void decoder_tcx_post(
Decoder_State *st,
float *synth,
float *synthFB,
float *A,
const int16_t bfi
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
,
const int16_t isMCT
#endif
Decoder_State *st, /* i/o: decoder memory state */
float *synth, /* i/o: synthesis */
float *synthFB, /* i/o: FB synthesis */
float *A, /* i : A(z) filter coefficients */
const int16_t bfi, /* i : Bad frame indicator */
const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
)
{
int16_t i;
......@@ -163,7 +152,11 @@ void decoder_tcx_post(
if ( bfi && !st->use_partial_copy )
{
/* run lpc gain compensation not for waveform adjustment */
#ifdef FIX_124_DONT_ALLOC_PLCINFO_IN_IVAS
if ( !st->enablePlcWaveadjust || ( st->hPlcInfo != NULL && st->hPlcInfo->concealment_method == TCX_TONAL ) )
#else
if ( !st->enablePlcWaveadjust || st->hPlcInfo->concealment_method == TCX_TONAL )
#endif
{
float gainHelperFB = hTcxDec->gainHelper;
float stepCompensateFB = hTcxDec->stepCompensate * st->L_frame / hTcxDec->L_frameTCX;
......@@ -188,11 +181,7 @@ void decoder_tcx_post(
/* PLC: [TCX: Fade-out]
* PLC: update or retrieve the background level */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( bfi == 0 && st->tcxonly && ( st->element_mode != IVAS_CPE_MDCT || isMCT ) && st->clas_dec == UNVOICED_CLAS )
#else
if ( bfi == 0 && st->tcxonly && st->clas_dec == UNVOICED_CLAS )
#endif
if ( bfi == 0 && st->tcxonly && ( st->element_mode != IVAS_CPE_MDCT || MCT_flag ) && st->clas_dec == UNVOICED_CLAS )
{
minimumStatistics( hTcxDec->NoiseLevelMemory_bfi, &hTcxDec->NoiseLevelIndex_bfi, &hTcxDec->CurrLevelIndex_bfi, &hTcxDec->CngLevelBackgroundTrace_bfi, &hTcxDec->LastFrameLevel_bfi, level_syn, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE );
}
......@@ -206,6 +195,18 @@ void decoder_tcx_post(
if ( st->tcxonly )
{
gainCNG = hTcxDec->CngLevelBackgroundTrace_bfi / ( level_syn + 0.01f );
if ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag )
{
if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME + MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN )
{
gainCNG = 0.f;
}
else if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME )
{
gainCNG *= 1.f - (float) ( st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN;
}
}
}
else
{
......@@ -696,9 +697,6 @@ void decoder_tcx_invQ(
const int16_t **prm_sqQ1,
int16_t *nf_seed,
const int16_t bfi, /* i : Bad frame indicator */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
const int16_t isMCT,
#endif
const int16_t frame_cnt /* i : frame counter in the super frame */
)
{
......@@ -913,16 +911,7 @@ void decoder_tcx_invQ(
hTcxDec->damping = 1;
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
else if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME )
{
*gain_tcx = hTcxDec->old_gaintcx_bfi;
hTcxDec->damping = Damping_fact( st->coder_type, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &( st->lp_gainp ), st->last_core );
}
else if ( st->element_mode != IVAS_CPE_MDCT || !isMCT )
#else
else
#endif
{
*gain_tcx = hTcxDec->old_gaintcx_bfi;
hTcxDec->damping = Damping_fact( st->coder_type, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), st->last_core );
......@@ -1079,9 +1068,7 @@ void decoder_tcx_invQ(
void decoder_tcx_noisefilling(
Decoder_State *st, /* i/o: coder memory state */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
float concealment_noise[L_FRAME48k],
#endif
const float A[], /* i : coefficients NxAz[M+1] */
const int16_t L_frameTCX_glob,
const int16_t L_spec,
......@@ -1094,9 +1081,7 @@ void decoder_tcx_noisefilling(
const int16_t *prm_sqQ,
int16_t nf_seed,
const int16_t bfi, /* i : Bad frame indicator */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
const int16_t isMCT,
#endif
const int16_t MCT_flag,
const int16_t frame_cnt /* i : frame counter in the super frame*/
)
{
......@@ -1120,23 +1105,7 @@ void decoder_tcx_noisefilling(
*-----------------------------------------------------------------*/
/* Init lengths */
if ( st->igf == 0 )
{
if ( st->narrowBand == 0 )
{
/* minimum needed for output with sampling rates lower then the
nominal sampling rate */
infoIGFStartLine = min( L_frameTCX, L_frame );
}
else
{
infoIGFStartLine = L_frameTCX;
}
}
else
{
infoIGFStartLine = min( st->hIGFDec->infoIGFStartLine, L_frameTCX );
}
infoIGFStartLine = get_igf_startline( st, L_frame, L_frameTCX );
noiseFillingSize = L_spec;
if ( st->igf )
......@@ -1246,13 +1215,8 @@ void decoder_tcx_noisefilling(
if ( st->hTonalMDCTConc != NULL )
{
if ( !bfi && st->element_mode != IVAS_CPE_MDCT )
{
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x, L_frameTCX, L_frame, gainlpc2, infoIGFStartLine );
#else
TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x, L_frameTCX, L_frame, gainlpc2 );
#endif
}
else if ( bfi )
{
......@@ -1261,11 +1225,7 @@ void decoder_tcx_noisefilling(
{
/* set f to 1 to not fade out */
/* set f to 0 to immediately switch to white noise */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( st->tcxonly && st->element_mode != IVAS_CPE_MDCT )
#else
if ( st->tcxonly )
#endif
if ( st->tcxonly && ( st->element_mode != IVAS_CPE_MDCT || MCT_flag ) )
{
f = 1.0f;
}
......@@ -1304,18 +1264,14 @@ void decoder_tcx_noisefilling(
noiseTiltFactor = 1.0f;
tcxGetNoiseFillingTilt( A, L_frame, ( total_brate >= ACELP_13k20 && !st->rf_flag ), &noiseTiltFactor );
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( st->element_mode == IVAS_CPE_MDCT && !isMCT )
if ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag )
{
TonalMDCTConceal_InsertNoise( st->hTonalMDCTConc, x, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, concealment_noise, infoIGFStartLine );
TonalMDCTConceal_InsertNoise( st->hTonalMDCTConc, x, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, concealment_noise, hTcxDec->CngLevelBackgroundTrace_bfi, infoIGFStartLine );
}
else
{
TonalMDCTConceal_InsertNoise( st->hTonalMDCTConc, x, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, NULL, infoIGFStartLine );
TonalMDCTConceal_InsertNoise( st->hTonalMDCTConc, x, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, NULL, hTcxDec->CngLevelBackgroundTrace_bfi, infoIGFStartLine );
}
#else
TonalMDCTConceal_InsertNoise( st->hTonalMDCTConc, x, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, infoIGFStartLine );
#endif
}
}
}
......@@ -1393,11 +1349,7 @@ void decoder_tcx_noiseshaping_igf(
* Noise shaping in frequency domain (1/Wz) *
*-----------------------------------------------------------*/
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( st->igf && ( !bfi || ( st->element_mode == IVAS_CPE_MDCT && st->prev_bfi ) ) )
#else
if ( st->igf && !bfi )
#endif
{
if ( ( L_frame == st->L_frame >> 1 ) && ( st->tcxonly ) )
{
......@@ -1517,11 +1469,6 @@ void decoder_tcx_tns(
isTCX5 = 1;
tcx5SpectrumDeinterleaving( L >> 1, x );
if ( hTcxCfg->fIsTNSAllowed && fUseTns != 0 && bfi != 1 && tnsData->tnsOnWhitenedSpectra == whitenedDomain )
{
tcx5TnsGrouping( L >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x );
}
}
}
......@@ -1539,15 +1486,27 @@ void decoder_tcx_tns(
/* Apply TNS to get the reconstructed signal */
SetTnsConfig( hTcxCfg, L_frame_glob == st->L_frame, ( st->last_core == ACELP_CORE ) && ( frame_cnt == 0 ) );
if ( ( L_frame == st->L_frame >> 1 ) && st->tcxonly && isTCX5 )
{
tcx5TnsGrouping( L >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x );
}
ApplyTnsFilter( hTcxCfg->pCurrentTnsConfig, tnsData, x, 0 );
#ifdef DEBUG_PLOT
sendDebout( "tnsSpec2", L_frameTCX, 1, "aftTNS", MTV_FLOAT, x );
#endif
if ( ( L_frame == st->L_frame >> 1 ) && st->tcxonly && isTCX5 )
{
if ( st->element_mode == EVS_MONO || L_spec < L_frameTCX ) /* TBC: this is temporary to maintain EVS BE, this is a bug and should be fixed also for EVS (see issue 13) */
{
tcx5TnsUngrouping( L_frameTCX >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x, DEC );
}
else
{
tcx5TnsUngrouping( L >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x, DEC );
}
}
}
if ( whitenedDomain && isTCX5 )
......@@ -1943,7 +1902,8 @@ void decoder_tcx_IGF_stereo(
const int16_t L_frame, /* i : frame length */
const int16_t left_rect, /* i : left part is rectangular */
const int16_t k, /* i : Subframe index */
const int16_t bfi /* i : bad frame indicator */
const int16_t bfi, /* i : bad frame indicator */
const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
)
{
int16_t coreMsMask[N_MAX];
......@@ -1996,7 +1956,7 @@ void decoder_tcx_IGF_stereo(
igfGridIdx = ( sts[0]->last_core == ACELP_CORE || ( left_rect && bfi ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM;
}
IGFDecApplyStereo( sts[0]->hIGFDec, sts[1]->hIGFDec, x[0][k], x[1][k], igfGridIdx, coreMsMask, hStereoMdct->IGFStereoMode[k] == SMDCT_BW_MS, bfi );
IGFDecApplyStereo( sts[0]->hIGFDec, sts[1]->hIGFDec, x[0][k], x[1][k], igfGridIdx, coreMsMask, hStereoMdct->IGFStereoMode[k] == SMDCT_BW_MS, bfi, MCT_flag );
}
return;
......
......@@ -57,7 +57,6 @@ int16_t dlpc_avq(
int16_t *p_index, q_type;
/* Last LPC index */
if ( numlpc == 1 )
{
last = 0;
......
......@@ -71,6 +71,7 @@ void lpc_unquantize(
if ( st->lpcQuantization == 0 )
{
nb_indices = dlpc_avq( param_lpc, &lsf[M], st->numlpc, st->sr_core );
for ( k = 0; k < st->numlpc; k++ )
{
lsf2lsp( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core );
......
......@@ -34,6 +34,8 @@
EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
====================================================================================*/
#include "cnst.h"
#include "ivas_cnst.h"
#include <assert.h>
#include <stdint.h>
#include "options.h"
......@@ -56,11 +58,8 @@ void con_tcx(
float synth[], /* i/o: synth[] */
const float coh, /* i : coherence of stereo signal */
int16_t *noise_seed, /* i/o: noise seed for stereo */
const int16_t only_left /* i : TD-PLC only in left channel */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
,
const float *A_cng
#endif
const int16_t only_left, /* i : TD-PLC only in left channel */
const float A_cng[] /* i : CNG LP filter coefficients */
)
{
int16_t i, n, L_frame, L_subfr, fLowPassFilter, T0;
......@@ -279,19 +278,7 @@ void con_tcx(
st->bpf_gain_param = 0;
/* PLC: calculate damping factor */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
alpha = 1.0f;
if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME )
{
alpha = Damping_fact( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 );
}
else if ( st->element_mode != IVAS_CPE_MDCT )
{
alpha = Damping_fact( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 );
}
#else
alpha = Damping_fact( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 );
#endif
alpha = Damping_fact( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), ACELP_CORE );
if ( st->nbLostCmpt == 1 )
{
......@@ -350,19 +337,7 @@ void con_tcx(
set_f( pitch_buf, (float) L_SUBFR, st->nb_subfr );
/* PLC: calculate damping factor */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
alpha = 1.0f;
if ( st->element_mode == IVAS_CPE_MDCT && st->nbLostCmpt >= MDCT_ST_PLC_FADEOUT_START_FRAME )
{
alpha = Damping_fact( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_START_FRAME, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 );
}
else if ( st->element_mode != IVAS_CPE_MDCT )
{
alpha = Damping_fact( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 );
}
#else
alpha = Damping_fact( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), 0 );
#endif
alpha = Damping_fact( st->core_ext_mode, st->nbLostCmpt, st->last_good, st->stab_fac, &( st->lp_gainp ), ACELP_CORE );
}
/*-----------------------------------------------------------------*
......@@ -459,7 +434,6 @@ void con_tcx(
/* PLC: [TCX: Fade-out] retrieve background level */
tmp = 1.0f;
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( A_cng != NULL )
{
gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_cng, L_frame / 4, st->preemph_fac, 1 ) / 4.f;
......@@ -468,12 +442,21 @@ void con_tcx(
{
gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_local, L_frame / 4, st->preemph_fac, 1 );
}
#else
gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_local, L_frame / 4, st->preemph_fac, 1 );
#endif
if ( st->tcxonly )
{
gainCNG = hTcxDec->CngLevelBackgroundTrace_bfi / gainSynthDeemph;
if ( st->element_mode == IVAS_CPE_MDCT && A_cng != NULL )
{
if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME + MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN )
{
gainCNG = 0.f;
}
else if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME )
{
gainCNG *= 1.f - (float) ( st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN;
}
}
}
else
{
......@@ -569,26 +552,12 @@ void con_tcx(
mvr2r( buf, mem_syn, M );
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( A_cng != NULL )
{
if ( ( st->nbLostCmpt == 1 && st->idchan == 0 ) || ( st->nbLostCmpt == 2 && st->idchan == 1 ) )
if ( st->plcBackgroundNoiseUpdated && alpha != 1.0f )
{
float lsp_cng[M];
float lsp_local[M], lsp_fade[M], alpha_inv;
lpc_from_spectrum( st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->startBand, st->hFdCngDec->hFdCngCom->stopFFTbin, 0.f );
a2lsp_stab( st->hFdCngDec->hFdCngCom->A_cng, lsp_cng, st->lspold_cng );
mvr2r( lsp_cng, st->lspold_cng, M );
}
if ( alpha != 1.0f )
{
float lsp_local[M];
float lsp_fade[M];
float alpha_inv;
wmops_sub_start( "Fade LSPs" );
alpha_inv = 1.0f - alpha;
a2lsp_stab( A_local, lsp_local, lsp_local );
......@@ -599,10 +568,8 @@ void con_tcx(
}
lsp2a_stab( lsp_fade, A_local, M );
wmops_sub_end();
}
}
#endif
syn_filt( A_local, M, &exc[0], &syn[0], L_frame + ( L_frame / 2 ), mem_syn, 1 );
......
......@@ -676,11 +676,7 @@ ivas_error evs_dec(
st->lp_noise = st->hFdCngDec->lp_noise;
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
ApplyFdCng( output, NULL, realBuffer, imagBuffer, st, concealWholeFrame, 0 );
#else
ApplyFdCng( output, realBuffer, imagBuffer, st, concealWholeFrame, 0 );
#endif
/* Generate additional comfort noise to mask potential coding artefacts */
if ( st->m_frame_type == ACTIVE_FRAME && st->flag_cna )
......
......@@ -368,9 +368,7 @@ void deleteFdCngDec(
void ApplyFdCng(
float *timeDomainInput,
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
float *powerSpectrum,
#endif
float **realBuffer, /* i/o: Real part of the buffer */
float **imagBuffer, /* i/o: Imaginary part of the buffer */
Decoder_State *st,
......@@ -384,7 +382,6 @@ void ApplyFdCng(
int16_t j, k;
float factor;
float lsp_cng[M];
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
int16_t L_frame, last_L_frame;
int32_t sr_core;
......@@ -394,7 +391,6 @@ void ApplyFdCng(
L_frame = min( st->L_frame, L_FRAME16k );
last_L_frame = min( st->last_L_frame, L_FRAME16k );
sr_core = min( st->sr_core, INT_FS_16k );
#endif
if ( hFdCngCom->frame_type_previous == ACTIVE_FRAME )
{
......@@ -419,27 +415,17 @@ void ApplyFdCng(
/* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */
/* set noise estimation inactive when we have bit errors, as no update with noise generated by corrupt frame (biterror) should be performed. */
if ( concealWholeFrame == 0 &&
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
( timeDomainInput == NULL ||
( *timeDomainInput<FLT_MAX && * timeDomainInput>( -FLT_MAX ) &&
*( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX &&
*( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) &&
#else
*timeDomainInput<FLT_MAX && * timeDomainInput>( -FLT_MAX ) &&
*( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX &&
*( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) &&
#endif
( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode ) || !st->VAD ) &&
!( st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode ) && ( is_music == 0 ) ) ||
( st->element_mode == IVAS_CPE_TD ) ) &&
( !st->BER_detect ) )
{
/* Perform noise estimation at the decoder */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD );
#else
perform_noise_estimation_dec( timeDomainInput, hFdCngDec, st->element_mode, st->bwidth, st->L_frame, st->last_L_frame, st->last_core_brate, st->VAD );
#endif
if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT )
{
......@@ -471,7 +457,6 @@ void ApplyFdCng(
}
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL )
{
st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / NORM_MDCT_FACTOR );
......@@ -480,7 +465,6 @@ void ApplyFdCng(
{
st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame );
}
#endif
st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame );
}
else if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT )
......@@ -488,74 +472,37 @@ void ApplyFdCng(
if ( hFdCngCom->active_frame_counter > 0 )
{
/* Perform noise estimation in active frames in the decoder for downward updates */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD );
#else
perform_noise_estimation_dec( timeDomainInput, hFdCngDec, st->element_mode, st->bwidth, st->L_frame, st->last_L_frame, st->last_core_brate, st->VAD );
#endif
}
}
if ( ( concealWholeFrame == 1 ) && ( st->nbLostCmpt == 1 ) && sum_f( cngNoiseLevel + hFdCngCom->startBand, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) > 0.01f )
if ( ( concealWholeFrame == 1 ) && ( st->nbLostCmpt == 1 ) )
{
#ifndef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
/* update lsf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/
lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 );
#else
if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE )
{
float scf[SNS_NPTS];
float scf_int[FDNS_NPTS];
float whitenend_noise_shape[L_FRAME16k];
int16_t inc, start_idx, stop_idx;
float *noiseLevelPtr;
wmops_sub_start( "get scfs for bg" );
inc = ( st->core > TCX_20 ) ? 2 : 1;
start_idx = hFdCngCom->startBand / inc;
stop_idx = L_frame / inc;
noiseLevelPtr = cngNoiseLevel;
set_zero( whitenend_noise_shape, start_idx );
for ( j = start_idx; j < stop_idx; j++, noiseLevelPtr += inc )
/* always set psychParameters for MDCT-Stereo ... */
if ( st->element_mode == IVAS_CPE_MDCT && st->hTonalMDCTConc != NULL )
{
whitenend_noise_shape[j] = *noiseLevelPtr;
st->hTonalMDCTConc->psychParams = ( st->core == TCX_20_CORE ) ? &st->hTonalMDCTConc->psychParamsTCX20 : &st->hTonalMDCTConc->psychParamsTCX10;
}
if ( st->core == TCX_20_CORE )
/* ... but do actual computations only if sufficient energy in noise shape */
if ( sum_f( cngNoiseLevel + hFdCngCom->startBand, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) > 0.01f )
{
st->hTonalMDCTConc->psychParams = &st->hTonalMDCTConc->psychParamsTCX20;
}
else
if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE )
{
st->hTonalMDCTConc->psychParams = &st->hTonalMDCTConc->psychParamsTCX10;
TonalMdctConceal_whiten_noise_shape( st, L_frame, ON_FIRST_LOST_FRAME );
}
sns_compute_scf( whitenend_noise_shape, st->hTonalMDCTConc->psychParams, L_frame, scf );
sns_interpolate_scalefactors( scf_int, scf, ENC );
sns_interpolate_scalefactors( st->hTonalMDCTConc->scaleFactorsBackground, scf, DEC );
sns_shape_spectrum( whitenend_noise_shape, st->hTonalMDCTConc->psychParams, scf_int, L_frame );
mvr2r( whitenend_noise_shape + start_idx, cngNoiseLevel, stop_idx - start_idx );
wmops_sub_end();
}
else if ( st->element_mode != IVAS_CPE_MDCT )
else if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE )
{
lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f );
a2lsp_stab( hFdCngCom->A_cng, lsp_cng, st->lspold_cng );
mvr2r( lsp_cng, st->lspold_cng, M );
lsp2lsf( lsp_cng, st->lsf_cng, M, sr_core );
}
#endif
#ifndef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
a2lsp_stab( hFdCngCom->A_cng, lsp_cng, st->lspold_cng );
mvr2r( lsp_cng, st->lspold_cng, M );
lsp2lsf( lsp_cng, st->lsf_cng, M, st->sr_core );
#endif
st->plcBackgroundNoiseUpdated = 1;
}
}
break;
case SID_FRAME:
......@@ -567,11 +514,7 @@ void ApplyFdCng(
if ( st != NULL && st->cng_type == LP_CNG )
{
/* Perform noise estimation on inactive phase at the decoder */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD );
#else
perform_noise_estimation_dec( timeDomainInput, hFdCngDec, st->element_mode, st->bwidth, st->L_frame, st->last_L_frame, st->last_core_brate, st->VAD );
#endif
if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT )
{
......@@ -582,11 +525,7 @@ void ApplyFdCng(
/* This sets the new CNG levels until a SID update overwrites it */
mvr2r( hFdCngDec->bandNoiseShape, cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame );
#else
st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame );
#endif
break;
}
......@@ -668,10 +607,8 @@ void ApplyFdCng(
default:
break;
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
wmops_sub_end();
#endif
return;
}
......@@ -685,9 +622,7 @@ void ApplyFdCng(
void perform_noise_estimation_dec(
const float *timeDomainInput,
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
float *power_spectrum,
#endif
HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */
const int16_t element_mode, /* i : element mode */
const int16_t bwidth, /* i : audio bandwidth */
......@@ -720,16 +655,11 @@ void perform_noise_estimation_dec(
float temp, ftemp, delta;
float wght;
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( !( element_mode == IVAS_CPE_MDCT && power_spectrum != NULL ) )
{
/* Perform STFT analysis */
AnalysisSTFT( timeDomainInput, fftBuffer, hFdCngDec->hFdCngCom );
}
#else
/* Perform STFT analysis */
AnalysisSTFT( timeDomainInput, fftBuffer, hFdCngDec->hFdCngCom );
#endif
if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT )
{
......@@ -962,7 +892,6 @@ void perform_noise_estimation_dec(
}
else
{
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( element_mode == IVAS_CPE_MDCT && power_spectrum != NULL )
{
/* use power spectrum calculated in the MDCT-domain instead of calculating new power spectrum */
......@@ -995,32 +924,6 @@ void perform_noise_estimation_dec(
/* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/
v_multc( periodog, 4.f / (float) ( hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen ), periodog, stopFFTbin - startBand );
}
#else
/* Compute the squared magnitude in each FFT bin */
if ( startBand == 0 )
{
( *ptr_per ) = fftBuffer[0] * fftBuffer[0]; /* DC component */
ptr_per++;
ptr_r = fftBuffer + 2;
}
else
{
ptr_r = fftBuffer + 2 * startBand;
}
ptr_i = ptr_r + 1;
for ( ; ptr_per < periodog + stopFFTbin - startBand; ptr_per++ )
{
( *ptr_per ) = ( *ptr_r ) * ( *ptr_r ) + ( *ptr_i ) * ( *ptr_i );
ptr_r += 2;
ptr_i += 2;
}
/* Nyquist frequency is discarded */
/* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/
v_multc( periodog, 4.f / (float) ( hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen ), periodog, stopFFTbin - startBand );
#endif
/* Adjust to the desired frequency resolution by averaging over spectral partitions for SID transmission */
bandcombinepow( periodog, stopFFTbin - startBand, part, npart, psize_inv, msPeriodog );
......@@ -2181,6 +2084,8 @@ void FdCngDecodeMDCTStereoSID(
msvq_dec( cdk_37bits_ivas, NULL, NULL, stages, N, FD_CNG_maxN_37bits, indices, ms_ptr[ch], NULL );
}
dtx_read_padding_bits( sts[1], ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC );
if ( sts[0]->hFdCngDec->hFdCngCom->no_side_flag )
{
set_zero( ms_ptr[1], NPART );
......@@ -2204,7 +2109,7 @@ void FdCngDecodeMDCTStereoSID(
lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac );
}
if ( hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_4k4 )
if ( hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_5k2 )
{
/* create proper M noise shape in channel zero after gains have been applied */
for ( p = 0; p < N; p++ )
......
......@@ -679,7 +679,8 @@ static void IGF_appl(
float *pSpectralData, /* i/o: Q31 | MDCT spectrum */
const float *igf_spec, /* i : Q31 | prepared IGF spectrum */
float *virtualSpec, /* o : Q31 | virtual IGF spectrum, used for temp flattening */
int16_t *flag_sparse /* o : Q0 | temp flattening indicator */
int16_t *flag_sparse, /* o : Q0 | temp flattening indicator */
const int16_t bfi_apply_damping /* i : flag to indicate if damping for lost frames should be applied */
)
{
H_IGF_GRID hGrid;
......@@ -855,7 +856,7 @@ static void IGF_appl(
for ( sfb = start_sfb; sfb < stop_sfb; sfb++ )
{
if ( hPrivateData->frameLossCounter > 0 )
if ( bfi_apply_damping && hPrivateData->frameLossCounter > 0 )
{
gain[sfb] = min( gain[sfb], 12.f );
......@@ -1212,7 +1213,7 @@ void IGFDecApplyMono(
/* apply IGF in three steps: */
IGF_prep( hPrivateData, igfGridIdx, hIGFDec->infoTCXNoise, igf_spec, hPrivateData->pSpecFlat, element_mode );
IGF_calc( hPrivateData, igfGridIdx, spectrum, igf_spec );
IGF_appl( hPrivateData, igfGridIdx, spectrum, igf_spec, hIGFDec->virtualSpec, hIGFDec->flag_sparse );
IGF_appl( hPrivateData, igfGridIdx, spectrum, igf_spec, hIGFDec->virtualSpec, hIGFDec->flag_sparse, 1 );
}
/* reset TCX noise indicator vector */
......@@ -1238,8 +1239,8 @@ void IGFDecApplyStereo(
const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
const int16_t *coreMsMask,
const int16_t restrict_hopsize,
const int16_t bfi /* i : frame loss == 1, frame good == 0 */
)
const int16_t bfi, /* i : frame loss == 1, frame good == 0 */
const int16_t bfi_apply_damping )
{
IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, hPrivateDataR;
H_IGF_GRID hGrid;
......@@ -1335,8 +1336,8 @@ void IGFDecApplyStereo(
IGF_calc( hPrivateDataL, igfGridIdx, spectrumL, igf_specL );
IGF_calc( hPrivateDataR, igfGridIdx, spectrumR, igf_specR );
IGF_appl( hPrivateDataL, igfGridIdx, spectrumL, igf_specL, hIGFDecL->virtualSpec, hIGFDecL->flag_sparse );
IGF_appl( hPrivateDataR, igfGridIdx, spectrumR, igf_specR, hIGFDecR->virtualSpec, hIGFDecR->flag_sparse );
IGF_appl( hPrivateDataL, igfGridIdx, spectrumL, igf_specL, hIGFDecL->virtualSpec, hIGFDecL->flag_sparse, bfi_apply_damping );
IGF_appl( hPrivateDataR, igfGridIdx, spectrumR, igf_specR, hIGFDecR->virtualSpec, hIGFDecR->flag_sparse, bfi_apply_damping );
}
/* reset TCX noise indicator vector */
......@@ -1588,3 +1589,31 @@ void init_igf_dec(
return;
}
int16_t get_igf_startline(
Decoder_State *st,
int16_t L_frame,
int16_t L_frameTCX )
{
int16_t igf_startline;
if ( st->igf == 0 )
{
if ( st->narrowBand == 0 )
{
/* minimum needed for output with sampling rates lower then the
nominal sampling rate */
igf_startline = min( L_frameTCX, L_frame );
}
else
{
igf_startline = L_frameTCX;
}
}
else
{
igf_startline = min( st->hIGFDec->infoIGFStartLine, L_frameTCX );
}
return igf_startline;
}
......@@ -53,11 +53,8 @@
ivas_error init_decoder(
Decoder_State *st, /* o : Decoder static variables structure */
const int16_t idchan /* i : channel ID */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
,
const int16_t idchan, /* i : channel ID */
const MC_MODE mc_mode /* i : MC mode */
#endif
)
{
int16_t i;
......@@ -664,7 +661,11 @@ ivas_error init_decoder(
* Mode 2 initialization
*-----------------------------------------------------------------*/
#ifdef FIX_124_DONT_ALLOC_PLCINFO_IN_IVAS
if ( st->element_mode == EVS_MONO )
#else
if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT )
#endif
{
if ( ( st->hPlcInfo = (T_PLCInfo_HANDLE) count_malloc( sizeof( T_PLCInfo ) ) ) == NULL )
{
......@@ -688,14 +689,11 @@ ivas_error init_decoder(
st->hTECDec = NULL;
}
#ifndef FIX_124_DONT_ALLOC_PLCINFO_IN_IVAS // the initialziation is done in open_decoder_LPD()
st->enablePlcWaveadjust = 0;
#endif
/* Init Core Decoder */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
open_decoder_LPD( st, st->total_brate, st->last_total_brate, st->bwidth, 0, st->element_mode, 1 );
#else
open_decoder_LPD( st, st->total_brate, st->last_total_brate, st->bwidth, 0, 1 );
#endif
/* PLC mode initialization */
st->m_decodeMode = DEC_NO_FRAM_LOSS;
......@@ -714,11 +712,7 @@ ivas_error init_decoder(
* FD-CNG decoder
*-----------------------------------------------------------------*/
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( ( st->element_mode == IVAS_CPE_MDCT || idchan == 0 ) && mc_mode != MC_MODE_MCT )
#else
if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT )
#endif
{
/* Create FD_CNG instance */
if ( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK )
......
......@@ -98,7 +98,11 @@ ivas_error ivas_spar_agc_dec_open(
)
{
ivas_agc_dec_state_t *hAgc;
#ifdef FIX_AGC_WINFUNC_MEMORY
int16_t output_frame, delay;
#else
int16_t output_frame;
#endif
if ( ( hAgc = (ivas_agc_dec_state_t *) count_malloc( sizeof( ivas_agc_dec_state_t ) ) ) == NULL )
{
......@@ -106,8 +110,15 @@ ivas_error ivas_spar_agc_dec_open(
}
output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC );
#ifdef FIX_AGC_WINFUNC_MEMORY
delay = NS2SA( output_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) );
#endif
#ifdef FIX_AGC_WINFUNC_MEMORY
if ( ( hAgc->agc_com.winFunc = (float *) count_malloc( sizeof( float ) * ( output_frame - delay ) ) ) == NULL )
#else
if ( ( hAgc->agc_com.winFunc = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL )
#endif
{
return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AGC decoder" );
}
......@@ -122,7 +133,11 @@ ivas_error ivas_spar_agc_dec_open(
return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AGC decoder" );
}
#ifdef FIX_AGC_WINFUNC_MEMORY
ivas_agc_dec_init( hAgc, output_frame, delay );
#else
ivas_agc_dec_init( hAgc, output_frame, NS2SA( output_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ) );
#endif
*hAgcDec = hAgc;
......@@ -190,10 +205,12 @@ void ivas_agc_dec_process(
if ( ( pState->gain_state[i].gainExpVal > (int32_t) ( pState->agc_com.maxAttExp + 1 ) ) || ( pState->gain_state[i].gainExpVal < -1 ) )
{
assert( 0 );
/* Such conditions indicate packet loss, better reset and do nothing*/
pState->gain_data[i].absGainExp = pState->agc_com.absEmin;
pState->gain_state[i].gainExpVal = 0;
}
pState->gain_state[i].lastGain = powf( 2, (float) ( pState->gain_data[i].absGainExp - pState->agc_com.absEmin ) );
pState->gain_state[i].lastGain = powf( pState->agc_com.winFunc[offset - 1], ( -1.f * (float) ( pState->gain_data[i].absGainExp - pState->agc_com.absEmin ) ) );
gainLast = 1.f / pState->gain_state[i].lastGain;
if ( !pState->gain_data[i].gainException )
......@@ -227,7 +244,7 @@ void ivas_agc_dec_process(
}
else
{
float gainCurr = powf( 2, (float) pState->gain_state[i].gainExpVal );
float gainCurr = powf( pState->agc_com.winFunc[offset - 1], ( -1.f * (float) pState->gain_state[i].gainExpVal ) );
float gainTot = gainCurr * gainLast;
for ( idx = 0; idx < output_frame; idx++ )
......
......@@ -35,9 +35,7 @@
#ifdef DEBUGGING
#include "debug.h"
#endif
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
#include <assert.h>
#endif
#include <math.h>
#include "cnst.h"
#include "rom_com.h"
......@@ -183,20 +181,23 @@ ivas_error ivas_core_dec(
st->flagGuidedAcelp = 0;
}
#ifndef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
/* PLC: [TCX: Fade-out-recovery] - overlapping part needs to be attenuated for first good frame */
if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT )
{
if ( st->hPlcInfo != NULL )
#ifdef FIX_124_DONT_ALLOC_PLCINFO_IN_IVAS
#ifdef FIX_MCT_PLC_RECOVERY
if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL )
#else
if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL && hMCT == NULL )
#endif
{
v_multc( st->hHQ_core->old_out, st->hPlcInfo->recovery_gain, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX );
v_multc( st->hHQ_core->old_outLB, st->hPlcInfo->recovery_gain, st->hHQ_core->old_outLB, st->L_frame );
float gain;
if ( !st->hTcxCfg->last_aldo && st->hTcxDec != NULL )
gain = st->hTcxDec->conceal_eof_gain * st->last_concealed_gain_syn_deemph;
v_multc( st->hHQ_core->old_out, gain, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX );
v_multc( st->hHQ_core->old_outLB, gain, st->hHQ_core->old_outLB, st->L_frame );
if ( !st->hTcxCfg->last_aldo )
{
v_multc( st->hTcxDec->syn_OverlFB, st->hPlcInfo->recovery_gain, st->hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB );
v_multc( st->hTcxDec->syn_Overl, st->hPlcInfo->recovery_gain, st->hTcxDec->syn_Overl, st->hTcxCfg->tcx_mdct_window_length );
}
v_multc( st->hTcxDec->syn_OverlFB, gain, st->hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB );
v_multc( st->hTcxDec->syn_Overl, gain, st->hTcxDec->syn_Overl, st->hTcxCfg->tcx_mdct_window_length );
}
}
#else
......@@ -204,20 +205,12 @@ ivas_error ivas_core_dec(
if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) )
{
float gain;
if ( st->hPlcInfo != NULL )
{
gain = st->hPlcInfo->recovery_gain;
}
else if ( st->hTcxDec != NULL )
{
gain = st->hTcxDec->conceal_eof_gain;
}
else
{
gain = 0.f;
assert( !"This should never happen." );
}
gain = ( st->element_mode == IVAS_CPE_MDCT ) ? st->hTcxDec->conceal_eof_gain : ( st->hPlcInfo != NULL ) ? st->hPlcInfo->recovery_gain
: 0.0f;
if ( ( st->element_mode == IVAS_CPE_MDCT && hMCT == NULL ) || ( st->hPlcInfo != NULL ) )
{
v_multc( st->hHQ_core->old_out, gain, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX );
v_multc( st->hHQ_core->old_outLB, gain, st->hHQ_core->old_outLB, st->L_frame );
......@@ -227,6 +220,7 @@ ivas_error ivas_core_dec(
v_multc( st->hTcxDec->syn_Overl, gain, st->hTcxDec->syn_Overl, st->hTcxCfg->tcx_mdct_window_length );
}
}
}
#endif
set_f( voice_factors[n], 0.f, NB_SUBFR16k );
......@@ -428,6 +422,18 @@ ivas_error ivas_core_dec(
{
updateBuffersForDmxMdctStereo( hCPE, output_frame, output, synth );
}
if ( sts[0]->bfi == 0 && sts[0]->prev_bfi == 1 )
{
/* On first good frame after frameloss undo the whitening of the bg noise shape */
for ( n = 0; n < n_channels; ++n )
{
if ( sts[n]->last_core_bfi != ACELP_CORE )
{
TonalMdctConceal_whiten_noise_shape( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME );
}
}
}
}
/*---------------------------------------------------------------------*
......
/******************************************************************************************************
(C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository. All Rights Reserved.
This software is protected by copyright law and by international treaties.
The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository retain full ownership rights in their respective contributions in
the software. This notice grants no license of any kind, including but not limited to patent
license, nor is any license granted by implication, estoppel or otherwise.
Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
contributions.
This software is provided "AS IS", without any express or implied warranties. The software is in the
development stage. It is intended exclusively for experts who have experience with such software and
solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
and fitness for a particular purpose are hereby disclaimed and excluded.
Any dispute, controversy or claim arising under or in relation to providing this software shall be
submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
the United Nations Convention on Contracts on the International Sales of Goods.
*******************************************************************************************************/
#include "options.h"
#include "ivas_cnst.h"
#include "ivas_prot.h"
#include "ivas_rom_com.h"
#include "ivas_stat_enc.h"
#include "lib_dec.h"
#include "prot.h"
#include <assert.h>
#include <math.h>
#include <stdint.h>
#ifdef DEBUGGING
#include "debug.h"
#endif
#include "wmops.h"
/*-------------------------------------------------------------------*
* ivas_corecoder_dec_reconfig()
*
* Allocate, initalize, and configure SCE/CPE/MCT handles in case of bitrate switching
*-------------------------------------------------------------------*/
ivas_error ivas_corecoder_dec_reconfig(
Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
const int16_t nSCE_old, /* i : number of SCEs in previous frame */
const int16_t nCPE_old, /* i : number of CPEs in previous frame */
const int16_t nchan_transport_old, /* i : number of TCs in previous frame */
const int16_t sba_dirac_stereo_flag_old /* i : signal stereo output for SBA DirAC in previous frame */
)
{
int16_t n, sce_id, cpe_id, output_frame;
int16_t nSCE_existing, nCPE_existing;
int32_t ivas_total_brate;
DECODER_CONFIG_HANDLE hDecoderConfig;
ivas_error error;
/*-----------------------------------------------------------------*
* Initialization
*-----------------------------------------------------------------*/
hDecoderConfig = st_ivas->hDecoderConfig;
ivas_total_brate = hDecoderConfig->ivas_total_brate;
error = IVAS_ERR_OK;
output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC );
/*-----------------------------------------------------------------*
* Allocate, initalize, and configure SCE/CPE/MCT handles
*-----------------------------------------------------------------*/
/* remove dummy CPE element for DFT stereo-like upmix */
if ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag )
{
st_ivas->hCPE[0]->hCoreCoder[0] = NULL;
st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
destroy_cpe_dec( st_ivas->hCPE[0] );
st_ivas->hCPE[0] = NULL;
if ( st_ivas->hSCE[0] != NULL )
{
count_free( st_ivas->hSCE[0]->save_synth );
st_ivas->hSCE[0]->save_synth = NULL;
count_free( st_ivas->hSCE[0]->save_hb_synth );
st_ivas->hSCE[0]->save_hb_synth = NULL;
}
}
if ( st_ivas->nchan_transport == nchan_transport_old )
{
for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
{
st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
}
for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
{
st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;
/* prepare bitstream buffers */
for ( n = 0; n < CPE_CHANNELS; n++ )
{
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
}
}
if ( st_ivas->nCPE > 1 )
{
if ( ( error = mct_dec_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK )
{
return error;
}
}
}
else
{
nSCE_existing = min( nSCE_old, st_ivas->nSCE );
nCPE_existing = min( nCPE_old, st_ivas->nCPE );
// VE: TBV - try to reuse the CoreCoder
/* destroy superfluous core coder elements */
for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
{
destroy_sce_dec( st_ivas->hSCE[sce_id] );
st_ivas->hSCE[sce_id] = NULL;
}
for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
{
destroy_cpe_dec( st_ivas->hCPE[cpe_id] );
st_ivas->hCPE[cpe_id] = NULL;
}
if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
{
ivas_mct_dec_close( &st_ivas->hMCT );
}
/* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles from the first CPE*/
if ( st_ivas->nCPE > 1 && nCPE_old == 1 )
{
count_free( st_ivas->hCPE[0]->hStereoMdct );
st_ivas->hCPE[0]->hStereoMdct = NULL;
}
for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
{
st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
}
for ( ; sce_id < st_ivas->nSCE; sce_id++ )
{
if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK )
{
return error;
}
}
for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
{
st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;
/* prepare bitstream buffers */
for ( n = 0; n < CPE_CHANNELS; n++ )
{
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
}
}
for ( ; cpe_id < st_ivas->nCPE; cpe_id++ )
{
if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK )
{
return error;
}
}
if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
{
if ( nCPE_old == 1 )
{
/* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */
for ( n = 0; n < CPE_CHANNELS; n++ )
{
st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0;
}
}
if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK )
{
return error;
}
}
else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
{
if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK )
{
return error;
}
}
/* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */
if ( st_ivas->nCPE == 1 && nCPE_old > 1 )
{
if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
}
st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->use_itd = 0;
st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->reverse_dmx = 0;
st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio = 1.f;
for ( n = 0; n < CPE_CHANNELS; n++ )
{
/* reset mct_chan_mode */
st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
}
}
}
/* create dummy CPE element for DFT stereo-like upmix */
if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old )
{
if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK )
{
return error;
}
// VE: TBV - just reset for now
set_f( st_ivas->hCPE[0]->hStereoDft->buff_LBTCX_mem, 0, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) );
st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
if ( st_ivas->hSCE[0]->save_synth == NULL )
{
if ( ( st_ivas->hSCE[0]->save_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) );
}
set_zero( st_ivas->hSCE[0]->save_synth, output_frame );
}
if ( st_ivas->hSCE[0]->save_hb_synth == NULL )
{
if ( ( st_ivas->hSCE[0]->save_hb_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) );
}
set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame );
}
}
/*-----------------------------------------------------------------*
* Set CNA/CNG flags
*-----------------------------------------------------------------*/
/// VE: this could be merged with part of ivas_init_decoder()
if ( st_ivas->ivas_format == SBA_FORMAT )
{
if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 )
{
/* skip as done in init function */
}
else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) )
{
st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1;
st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1;
}
else if ( st_ivas->nchan_transport == 2 )
{
for ( n = 0; n < CPE_CHANNELS; n++ )
{
st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0;
st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1;
}
}
else
{
for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
{
for ( n = 0; n < CPE_CHANNELS; n++ )
{
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0;
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0;
}
}
}
}
/* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */
if ( hDecoderConfig->last_ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE >= 1 )
{
if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK )
{
return error;
}
}
return error;
}
/*-------------------------------------------------------------------*
* ivas_hp20_dec_reconfig()
*
* Allocate, initialize, and configure HP20 memory handles in case of bitrate switching
*-------------------------------------------------------------------*/
ivas_error ivas_hp20_dec_reconfig(
Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
const int16_t nchan_hp20_old /* i : number of HP20 filters in previous frame */
)
{
int16_t i, nchan_hp20;
float **old_mem_hp20_out;
ivas_error error;
error = IVAS_ERR_OK;
/*-----------------------------------------------------------------*
* HP20 memories
*-----------------------------------------------------------------*/
nchan_hp20 = getNumChanSynthesis( st_ivas );
if ( nchan_hp20 > nchan_hp20_old )
{
/* save old mem_hp_20 pointer */
old_mem_hp20_out = st_ivas->mem_hp20_out;
st_ivas->mem_hp20_out = NULL;
if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
}
for ( i = 0; i < nchan_hp20_old; i++ )
{
st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i];
old_mem_hp20_out[i] = NULL;
}
/* create additional hp20 memories */
for ( ; i < nchan_hp20; i++ )
{
if ( ( st_ivas->mem_hp20_out[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
}
set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM );
}
count_free( old_mem_hp20_out );
old_mem_hp20_out = NULL;
}
else if ( nchan_hp20 < nchan_hp20_old )
{
/* save old mem_hp_20 pointer */
old_mem_hp20_out = st_ivas->mem_hp20_out;
st_ivas->mem_hp20_out = NULL;
if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
}
for ( i = 0; i < nchan_hp20; i++ )
{
st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i];
old_mem_hp20_out[i] = NULL;
}
/* remove superfluous hp20 memories */
for ( ; i < nchan_hp20_old; i++ )
{
count_free( old_mem_hp20_out[i] );
old_mem_hp20_out[i] = NULL;
}
count_free( old_mem_hp20_out );
old_mem_hp20_out = NULL;
}
return error;
}
......@@ -160,14 +160,14 @@ ivas_error ivas_cpe_dec(
if ( hCPE->element_mode != IVAS_CPE_MDCT && ( hCPE->element_brate != hCPE->last_element_brate || hCPE->last_element_mode != hCPE->element_mode || sts[0]->ini_frame == 0 || ( ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) ) )
{
if ( st_ivas->hQMetaData != NULL && ivas_total_brate > IVAS_SID_4k4 )
if ( st_ivas->hQMetaData != NULL && ivas_total_brate > IVAS_SID_5k2 )
{
stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
}
else
{
/* Note: This only works for stereo operation. If DTX would be applied for multiple CPEs a different bitrate signaling is needed */
if ( ivas_total_brate <= IVAS_SID_4k4 )
if ( ivas_total_brate <= IVAS_SID_5k2 )
{
stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
}
......@@ -203,7 +203,7 @@ ivas_error ivas_cpe_dec(
/* Update DFT Stereo memories */
stereo_dft_dec_update( hCPE->hStereoDft, output_frame, 0 );
if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_4k4 )
if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_5k2 )
{
if ( ivas_total_brate == FRAME_NO_DATA )
{
......@@ -220,13 +220,13 @@ ivas_error ivas_cpe_dec(
nb_bits = (int16_t) ( ( hCPE->element_brate ) / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal );
sts[1]->bit_stream = sts[0]->bit_stream + ivas_total_brate / FRAMES_PER_SEC - 1 - nb_bits_metadata;
if ( ivas_total_brate == IVAS_SID_4k4 )
if ( ivas_total_brate == IVAS_SID_5k2 )
{
nb_bits -= SID_FORMAT_NBITS;
sts[1]->bit_stream -= SID_FORMAT_NBITS;
}
if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_4k4 )
if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2 )
{
sts[0]->total_brate = hCPE->element_brate; /* Only mono downmix was transmitted in this case */
}
......@@ -266,7 +266,7 @@ ivas_error ivas_cpe_dec(
/* this is just for initialization, the true values of "total_brate" and "bits_frame_channel" are set later */
for ( n = 0; n < n_channels; n++ )
{
if ( ivas_total_brate == IVAS_SID_4k4 || ivas_total_brate == IVAS_SID_5k )
if ( ivas_total_brate == IVAS_SID_5k2 )
{
sts[n]->total_brate = SID_2k40;
......@@ -283,7 +283,7 @@ ivas_error ivas_cpe_dec(
if ( !st_ivas->hMCT )
{
if ( st_ivas->ivas_format == SBA_FORMAT && ivas_total_brate == IVAS_SID_5k )
if ( st_ivas->ivas_format == SBA_FORMAT && ivas_total_brate == IVAS_SID_5k2 )
{
for ( n = 0; n < n_channels; n++ )
{
......@@ -496,7 +496,7 @@ ivas_error ivas_cpe_dec(
#ifdef DEBUG_MODE_INFO
{
float tmpF = ivas_total_brate / 1000.0f;
float tmpF = hCPE->element_brate / 1000.0f;
n = 1;
if ( st_ivas->ini_frame == 0 && frame > 0 )
......@@ -508,12 +508,15 @@ ivas_error ivas_cpe_dec(
for ( i = 0; i < n; i++ )
{
dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, cpe_id, DEC ) );
dbgwrite( &hCPE->element_mode, 2, 1, output_frame, fname( debug_dir, "element_mode", 0, cpe_id, DEC ) );
dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, cpe_id, DEC ) );
for ( int16_t j = 0; j < CPE_CHANNELS; j++ )
{
dbgwrite( output[j], sizeof( float ), output_frame, 1, fname( debug_dir, "output.cpe", j, cpe_id, DEC ) );
}
tmpF = 0;
dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.sce", 0, cpe_id, DEC ) );
dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, cpe_id, DEC ) );
}
}
#endif
......@@ -587,7 +590,7 @@ ivas_error create_cpe_dec(
hCPE->nchan_out = min( CPE_CHANNELS, st_ivas->hDecoderConfig->nchan_out );
}
if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_4k4 )
if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_5k2 )
{
hCPE->nchan_out = 1;
}
......@@ -686,11 +689,7 @@ ivas_error create_cpe_dec(
st->mct_chan_mode = MCT_CHAN_MODE_LFE;
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( ( error = init_decoder( st, n, st_ivas->mc_mode ) ) != IVAS_ERR_OK )
#else
if ( ( error = init_decoder( st, n ) ) != IVAS_ERR_OK )
#endif
{
return error;
}
......@@ -791,6 +790,10 @@ ivas_error create_cpe_dec(
set_s( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB );
set_s( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB );
hCPE->hStereoMdct->lastCoh = 1.f;
hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO;
hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO;
hCPE->hStereoMdct->IGFStereoMode[0] = -1;
hCPE->hStereoMdct->IGFStereoMode[1] = -1;
}
/*-----------------------------------------------------------------*
......@@ -923,7 +926,7 @@ static void read_stereo_mode_and_bwidth(
* BFI or NO_DATA frame: Use stereo parameters from last (active) frame
*-----------------------------------------------------------------*/
if ( st_ivas->bfi || st_ivas->hDecoderConfig->ivas_total_brate < IVAS_SID_4k4 )
if ( st_ivas->bfi || st_ivas->hDecoderConfig->ivas_total_brate < IVAS_SID_5k2 )
{
hCPE->element_mode = hCPE->last_element_mode;
......@@ -933,7 +936,7 @@ static void read_stereo_mode_and_bwidth(
* SID frame: get element mode from SID side info
*-----------------------------------------------------------------*/
else if ( st_ivas->hDecoderConfig->ivas_total_brate == IVAS_SID_4k4 || st_ivas->hDecoderConfig->ivas_total_brate == IVAS_SID_5k )
else if ( st_ivas->hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 )
{
switch ( st_ivas->sid_format )
{
......
......@@ -304,8 +304,7 @@ ivas_error ivas_dec(
nchan_remapped = CPE_CHANNELS;
ivas_sba_dirac_stereo_dec( st_ivas, output, output_frame );
}
else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE &&
( ivas_total_brate > IVAS_SID_4k4 || ( ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE > 0 && st_ivas->hCPE[0]->nchan_out == 1 ) ) )
else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ( ivas_total_brate > IVAS_SID_5k2 || ( ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE > 0 && st_ivas->hCPE[0]->nchan_out == 1 ) ) )
{
nchan_remapped = 1; /* Only one channel transported */
}
......@@ -359,11 +358,7 @@ ivas_error ivas_dec(
}
else /* SBA_MODE_SPAR */
{
ivas_sba_upmixer_renderer( st_ivas, output,
#ifndef SPAR_SCALING_HARMONIZATION
nchan_remapped,
#endif
output_frame ); /* Note: ivas_sba_linear_renderer() or ivas_dirac_dec() are called internally */
ivas_sba_upmixer_renderer( st_ivas, output, output_frame ); /* Note: ivas_sba_linear_renderer() or ivas_dirac_dec() are called internally */
}
}
else if ( st_ivas->ivas_format == MC_FORMAT )
......@@ -589,7 +584,7 @@ ivas_error ivas_dec(
st_ivas->ini_frame++;
}
if ( st_ivas->ini_active_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && ivas_total_brate > IVAS_SID_4k4 ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */
if ( st_ivas->ini_active_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && ivas_total_brate > IVAS_SID_5k2 ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */
{
st_ivas->ini_active_frame++;
}
......
......@@ -190,7 +190,7 @@ ivas_error ivas_dirac_dec_config(
}
nchan_transport = st_ivas->nchan_transport;
if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_4k4 )
if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2 )
{
nchan_transport = 1;
}
......@@ -198,7 +198,7 @@ ivas_error ivas_dirac_dec_config(
if ( flag_config == DIRAC_RECONFIGURE && st_ivas->ivas_format == SBA_FORMAT )
{
int16_t tmp1, tmp2, tmp3;
ivas_sba_config( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3, SBA_MODE_DIRAC );
ivas_sba_config( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 );
}
/*-----------------------------------------------------------------*
......@@ -234,13 +234,13 @@ ivas_error ivas_dirac_dec_config(
if ( hDirAC->hOutSetup.ambisonics_order == -1 )
{
hDirAC->hOutSetup.ambisonics_order = 3; /* Order 3 is used by default in DirAC for SHD processing */
hDirAC->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */
if ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_MONO || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_STEREO )
{
hDirAC->hOutSetup.ambisonics_order = 1;
hDirAC->hOutSetup.ambisonics_order = SBA_FOA_ORDER;
}
}
else if ( hDirAC->hOutSetup.ambisonics_order >= 1 )
else if ( hDirAC->hOutSetup.ambisonics_order >= SBA_FOA_ORDER )
{
mvr2r( ls_azimuth_4d4, ls_azimuth, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
mvr2r( ls_elevation_4d4, ls_elevation, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS );
......@@ -756,7 +756,6 @@ ivas_error ivas_dirac_dec_config(
mvs2s( DirAC_block_grouping, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 );
if ( flag_config == DIRAC_OPEN )
{
hDirAC->dirac_md_buffer_length = 0;
......@@ -1280,7 +1279,7 @@ void ivas_dirac_dec_read_BS(
int16_t next_bit_pos_orig;
*nb_bits = 0;
if ( !st->bfi && ivas_total_brate > IVAS_SID_4k4 )
if ( !st->bfi && ivas_total_brate > IVAS_SID_5k2 )
{
next_bit_pos_orig = st->next_bit_pos;
st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 );
......@@ -1289,14 +1288,7 @@ void ivas_dirac_dec_read_BS(
b = st->bit_stream[( st->next_bit_pos )--];
( *nb_bits )++;
if ( sba_mode == SBA_MODE_SPAR )
{
if ( ivas_total_brate == IVAS_SID_5k )
{
b = 1;
}
}
else
if ( sba_mode != SBA_MODE_SPAR )
{
assert( ( b == 0 ) || ( hQMetaData->q_direction[0].cfg.start_band > 0 ) );
}
......@@ -1384,12 +1376,17 @@ void ivas_dirac_dec_read_BS(
st->next_bit_pos = next_bit_pos_orig;
}
else if ( !st->bfi && ivas_total_brate == IVAS_SID_4k4 )
else if ( !st->bfi && ivas_total_brate == IVAS_SID_5k2 )
{
next_bit_pos_orig = st->next_bit_pos;
/* subtract mode signaling bits, since bitstream was moved after mode reading */
st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS );
/* 1 bit flag for SPAR/DirAC, already read in read format function */
b = st->bit_stream[( st->next_bit_pos )--];
( *nb_bits )++;
hQMetaData->sba_inactive_mode = 1;
orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands;
/* if we start with a SID frame, we need to init the azi/ele arrays.*/
if ( st->ini_frame == 0 )
......@@ -1404,8 +1401,33 @@ void ivas_dirac_dec_read_BS(
}
}
*nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT, SBA_MODE_DIRAC );
*nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT, sba_mode );
if ( sba_mode == SBA_MODE_SPAR )
{
for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
{
hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0];
hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0];
hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0];
}
for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
{
for ( j = orig_dirac_bands - 2; j >= 0; j-- )
{
hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0];
hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0];
hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0];
}
}
hQMetaData->q_direction->cfg.nbands = orig_dirac_bands;
}
else
{
*nb_bits += SID_FORMAT_NBITS;
}
st->next_bit_pos = next_bit_pos_orig;
}
......@@ -1451,7 +1473,7 @@ void ivas_qmetadata_to_dirac(
q_direction = &( hQMetaData->q_direction[0] );
hDirAC->numSimultaneousDirections = hQMetaData->no_directions;
if ( hMasa != NULL && ivas_total_brate > IVAS_SID_4k4 )
if ( hMasa != NULL && ivas_total_brate > IVAS_SID_5k2 )
{
band_mapping = hMasa->data.band_mapping;
......@@ -1527,7 +1549,7 @@ void ivas_qmetadata_to_dirac(
nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands];
band_grouping = hDirAC->band_grouping;
if ( ivas_total_brate <= IVAS_SID_4k4 && sba_mode != SBA_MODE_SPAR )
if ( ivas_total_brate <= IVAS_SID_5k2 && sba_mode != SBA_MODE_SPAR )
{
/* SID/zero-frame: 1 direction, 5 bands, nblocks re-generated out of SID decoder*/
start_band = 0;
......@@ -1623,7 +1645,7 @@ void ivas_qmetadata_to_dirac(
ele = min( 90, ele );
ele = max( -90, ele );
if ( ivas_total_brate > IVAS_SID_4k4 && q_direction->coherence_band_data != NULL )
if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL )
{
hDirAC->spreadCoherence[tmp_write_idx_band][b] = q_direction->coherence_band_data[qBand_idx].spread_coherence[block] / 255.0f;
}
......@@ -1632,7 +1654,7 @@ void ivas_qmetadata_to_dirac(
hDirAC->spreadCoherence[tmp_write_idx_band][b] = 0.0f;
}
if ( ivas_total_brate > IVAS_SID_4k4 && q_direction->coherence_band_data != NULL )
if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL )
{
hDirAC->surroundingCoherence[tmp_write_idx_band][b] = hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0] / 255.0f;
}
......@@ -1787,9 +1809,9 @@ void ivas_dirac_dec(
#ifdef DEBUG_MODE_DIRAC
{
int16_t n, tmp[DIRAC_MAX_TRANS_CHANS * L_FRAME48k];
int16_t n, tmp[IVAS_SPAR_MAX_CH * L_FRAME48k];
char file_name[50] = { 0 };
const int16_t output_frame = st_ivas->output_Fs / FRAMES_PER_SEC;
const int16_t output_frame = st_ivas->->hDecoderConfig->output_Fs / FRAMES_PER_SEC;
for ( n = 0; n < nchan_transport; n++ )
{
......@@ -2514,7 +2536,7 @@ static void initDiffuseResponses(
if ( output_config == AUDIO_CONFIG_MONO )
{
diffuse_response_function[0] = 1.0f;
diffuse_response_function[1] = 1.0f / sqrtf( 3.0f );
diffuse_response_function[1] = inv_sqrt( 3.0f );
}
else if ( !( output_config == AUDIO_CONFIG_FOA || output_config == AUDIO_CONFIG_HOA2 || output_config == AUDIO_CONFIG_HOA3 ) )
{
......@@ -2596,7 +2618,7 @@ static void initDiffuseResponses(
{
for ( k = 0; k < ( 2 * l + 1 ); k++ )
{
diffuse_response_function[idx++] = 1.0f / sqrtf( 2.0f * l + 1.0f );
diffuse_response_function[idx++] = inv_sqrt( 2.0f * l + 1.0f );
}
}
}
......
......@@ -29,7 +29,7 @@
the United Nations Convention on Contracts on the International Sales of Goods.
*******************************************************************************************************/
// VE2AT: move to lib_rend ?
#include <stdint.h>
#include "options.h"
#include <assert.h>
......@@ -37,7 +37,7 @@
#include "prot.h"
#include "ivas_prot.h"
#include "ivas_cnst.h"
#include "ivas_rom_binauralRenderer.h"
#include "ivas_rom_binauralRenderer.h" // VE2AT: what about to put these includes ust into ivas_rom_rend.c ?
#include "ivas_rom_dec.h"
#ifdef DEBUGGING
#include "debug.h"
......@@ -150,7 +150,7 @@ ivas_error ivas_dirac_dec_init_binaural_data(
hBinaural->useTdDecorr = 1;
}
}
if ( st_ivas->ivas_format == MASA_FORMAT )
else if ( st_ivas->ivas_format == MASA_FORMAT )
{
if ( ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_48k && st_ivas->nchan_transport == 1 ) || st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE )
{
......@@ -188,23 +188,21 @@ ivas_error ivas_dirac_dec_init_binaural_data(
else if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) /* Indication of binaural rendering with room effect */
{
mvr2r( parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins );
if ( hBinaural->useSubframeMode )
{
if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) ) != IVAS_ERR_OK )
if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK )
{
return error;
}
}
else
{
if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX ) ) != IVAS_ERR_OK )
if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK )
{
return error;
}
}
ivas_binaural_reverb_setReverbTimes( hBinaural->hReverb, output_Fs, parametricReverberationTimes, parametricReverberationEneCorrections );
hBinaural->hReverb->useBinauralCoherence = 1;
ivas_binaural_reverb_setPreDelay( hBinaural->hReverb, 10 );
}
else if ( renderer_type == RENDERER_STEREO_PARAMETRIC )
{
......@@ -246,6 +244,7 @@ ivas_error ivas_dirac_dec_init_binaural_data(
return IVAS_ERR_OK;
}
/*-------------------------------------------------------------------------
* ivas_dirac_dec_close_binaural_data()
*
......@@ -415,6 +414,7 @@ static void ivas_dirac_dec_binaural_internal(
Cldfb_ImagBuffer_in[0][slot][b] = INV_SQRT2 * ( Cldfb_ImagBuffer_in[0][slot][b] + Cldfb_ImagBuffer_in[2][slot][b] );
Cldfb_ImagBuffer_in[1][slot][b] = Cldfb_ImagBuffer_in[0][slot][b];
}
/* HB: Copy first channel to second channel and add HB-CNGs with different scalings*/
for ( ; b < nBins; b++ )
{
......@@ -431,8 +431,9 @@ static void ivas_dirac_dec_binaural_internal(
{
/* At mono input duplicate the channel to dual-mono, and apply gain
correction to ensure same overall level as in stereo mode */
v_multc( Cldfb_RealBuffer_in[0][slot], 1.0f / SQRT2, Cldfb_RealBuffer_in[0][slot], nBins );
v_multc( Cldfb_ImagBuffer_in[0][slot], 1.0f / SQRT2, Cldfb_ImagBuffer_in[0][slot], nBins );
v_multc( Cldfb_RealBuffer_in[0][slot], INV_SQRT_2, Cldfb_RealBuffer_in[0][slot], nBins );
v_multc( Cldfb_ImagBuffer_in[0][slot], INV_SQRT_2, Cldfb_ImagBuffer_in[0][slot], nBins );
mvr2r( Cldfb_RealBuffer_in[0][slot], Cldfb_RealBuffer_in[1][slot], nBins );
mvr2r( Cldfb_ImagBuffer_in[0][slot], Cldfb_ImagBuffer_in[1][slot], nBins );
}
......@@ -447,10 +448,11 @@ static void ivas_dirac_dec_binaural_internal(
Cldfb_RealBuffer_in[ch][slot],
Cldfb_ImagBuffer_in[ch][slot],
nBins, st_ivas->cldfbAnaDec[ch] );
if ( st_ivas->nchan_transport == 1 && st_ivas->ivas_format == SBA_FORMAT )
{
v_multc( Cldfb_RealBuffer_in[ch][slot], 1.0f / SQRT2, Cldfb_RealBuffer_in[ch][slot], nBins );
v_multc( Cldfb_ImagBuffer_in[ch][slot], 1.0f / SQRT2, Cldfb_ImagBuffer_in[ch][slot], nBins );
v_multc( Cldfb_RealBuffer_in[ch][slot], INV_SQRT_2, Cldfb_RealBuffer_in[ch][slot], nBins );
v_multc( Cldfb_ImagBuffer_in[ch][slot], INV_SQRT_2, Cldfb_ImagBuffer_in[ch][slot], nBins );
}
}
}
......@@ -762,7 +764,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric
{
/* 0.5f <= spreadCoh < 1.0f */
centerMul = 2.0f - ( 2.0f * spreadCoh );
sidesMul = 1.0f / sqrtf( centerMul + 2.0f );
sidesMul = inv_sqrt( centerMul + 2.0f );
centerMul *= sidesMul;
}
......
......@@ -2078,7 +2078,8 @@ static void spreadCoherencePanningVbap(
if ( hVBAPdata == NULL )
{
/* Distribute signal to all channels if VBAP is not properly initialized. */
set_f( direct_response, 1.0f / sqrtf( num_channels_dir ), num_channels_dir );
set_f( direct_response, inv_sqrt( num_channels_dir ), num_channels_dir );
return;
}
......
......@@ -69,7 +69,6 @@ ivas_error ivas_dec_setup(
Decoder_State *st;
int32_t ivas_total_brate;
ivas_error error;
error = IVAS_ERR_OK;
num_bits_read = 0;
......@@ -126,16 +125,30 @@ ivas_error ivas_dec_setup(
st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order );
num_bits_read += SBA_ORDER_BITS;
if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_4k4 )
if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 )
{
#ifdef SBA_BR_SWITCHING
if ( get_sba_reinit_flag( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) )
{
if ( ( error = ivas_sba_dec_reinit( st_ivas ) ) != IVAS_ERR_OK )
{
return error;
}
}
else
{
#endif
if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK )
{
return error;
}
#ifdef SBA_BR_SWITCHING
}
#endif
}
else
{
ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode );
ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init );
}
}
else if ( st_ivas->ivas_format == MASA_FORMAT )
......@@ -154,7 +167,7 @@ ivas_error ivas_dec_setup(
if ( st_ivas->ini_frame > 0 )
{
/* reconfigure in case a change of operation mode is detected */
if ( ( ivas_total_brate > IVAS_SID_4k4 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) )
if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) )
{
if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->nCPE == 1 )
{
......@@ -213,7 +226,7 @@ ivas_error ivas_dec_setup(
}
}
}
else if ( ivas_total_brate == IVAS_SID_4k4 || ivas_total_brate == IVAS_SID_5k )
else if ( ivas_total_brate == IVAS_SID_5k2 )
{
switch ( st_ivas->sid_format )
{
......@@ -349,7 +362,7 @@ static ivas_error ivas_read_format(
break;
}
}
else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_4k4 )
else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k2 )
{
/* read IVAS format in SID frame */
idx = 0;
......@@ -402,74 +415,29 @@ static ivas_error ivas_read_format(
return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Invalid value %c found in SID format field.", st_ivas->sid_format );
}
/* reset bitstream handle to avoid BER detection after reading the 2400 kbps for ch0 */
st_ivas->bit_stream += ( *num_bits_read );
( *num_bits_read ) = 0;
}
else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k )
{
#ifdef PARAM_ISM_DTX_CNG
/* read IVAS format in SID frame */
idx = 0;
for ( k = 0; k < SID_FORMAT_NBITS; k++ )
{
idx += st_ivas->bit_stream[k] << ( SID_FORMAT_NBITS - 1 - k );
}
( *num_bits_read ) += SID_FORMAT_NBITS;
st_ivas->sid_format = idx;
switch ( idx )
{
case SID_ISM:
st_ivas->ivas_format = ISM_FORMAT;
if ( st_ivas->ism_mode == ISM_MODE_DISC )
if ( st_ivas->ivas_format == SBA_FORMAT )
{
ivas_ism_dec_config( st_ivas, 1 ); /* currently DTX supported for 1 ISM when ISM Mode is DISC_ISM */
}
if ( st_ivas->ism_mode == ISM_MODE_PARAM )
{
ivas_ism_dec_config( st_ivas, st_ivas->nSCE ); /* for Param-ISM, we need to generate 2 TCs */
}
break;
default:
/* This should actually be impossible, since only 3 bits are read, so if this happens something is broken */
return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Invalid value %c found in SID format field.", st_ivas->sid_format );
}
/* reset bitstream handle to avoid BER detection after reading the 2400 kbps for ch0 */
st_ivas->bit_stream += ( *num_bits_read );
( *num_bits_read ) = 0;
#else
int16_t tc_mode_offset;
tc_mode_offset = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 );
idx = st_ivas->bit_stream[tc_mode_offset];
// TBD: needs more work for HOA
if ( st_ivas->sba_analysis_order == 0 )
{
st_ivas->sba_analysis_order = 1;
st_ivas->sba_analysis_order = SBA_FOA_ORDER;
}
if ( idx == 0 )
if ( idx == 1 )
{
st_ivas->sid_format = SID_SBA_1TC;
st_ivas->ivas_format = SBA_FORMAT;
st_ivas->sba_mode = SBA_MODE_SPAR;
st_ivas->element_mode_init = IVAS_SCE;
}
else
{
st_ivas->sid_format = SID_SBA_2TC;
st_ivas->ivas_format = SBA_FORMAT;
st_ivas->sba_mode = SBA_MODE_SPAR;
st_ivas->element_mode_init = IVAS_CPE_MDCT;
st_ivas->sba_mode = SBA_MODE_DIRAC;
}
#endif
}
/* reset bitstream handle to avoid BER detection after reading the 2400 kbps for ch0 */
st_ivas->bit_stream += ( *num_bits_read );
( *num_bits_read ) = 0;
}
else
{
......@@ -717,61 +685,6 @@ ivas_error ivas_init_decoder(
}
}
#ifndef FIX_I98_HANDLES_TO_NULL
#if 0
/*-----------------------------------------------------------------*
* Dummy pointers to decoder handles
*-----------------------------------------------------------------*/
for ( i = 0; i < MAX_SCE; i++ )
{
st_ivas->hSCE[i] = NULL;
}
for ( i = 0; i < MAX_CPE; i++ )
{
st_ivas->hCPE[i] = NULL;
}
/* ISm metadata handles */
for ( n = 0; n < MAX_NUM_OBJECTS; n++ )
{
st_ivas->hIsmMetaData[n] = NULL;
}
/* DirAC handle */
st_ivas->hDirAC = NULL;
st_ivas->sba_dirac_stereo_flag = 0;
/* SPAR handle */
st_ivas->hSpar = NULL;
/* MASA decoder structure */
st_ivas->hMasa = NULL;
/* Q metadata handle */
st_ivas->hQMetaData = NULL;
/* MCT handles */
st_ivas->hMCT = NULL;
st_ivas->hParamMC = NULL;
/* LFE handle */
st_ivas->hLFE = NULL;
/* renderers handles */
st_ivas->hBinRenderer = NULL; /* fastconf binaural renderer */
st_ivas->hDiracDecBin = NULL; /* parametric binaural renderer */
st_ivas->hLsSetUpConversion = NULL; /* MC converter */
st_ivas->hEFAPdata = NULL; /* EFAP handle */
st_ivas->hVBAPdata = NULL; /* VBAP handle */
st_ivas->hIsmRendererData = NULL; /* ISm renderer */
st_ivas->hBinRendererTd = NULL; /* TD ISm binaural renderer */
st_ivas->hMonoDmxRenderer = NULL; /* Mono downmix renderer */
st_ivas->hHrtf = NULL; /* Crend hrtf data */
st_ivas->hCrend = NULL; /* Crend renderer */
#endif
#endif
/*-----------------------------------------------------------------*
* Allocate and initalize SCE/CPE and other handles
*-----------------------------------------------------------------*/
......@@ -808,6 +721,7 @@ ivas_error ivas_init_decoder(
{
reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
}
/* init EFAP for custom LS output and set hTransSetup */
if ( output_config == AUDIO_CONFIG_LS_CUSTOM )
{
......@@ -861,12 +775,11 @@ ivas_error ivas_init_decoder(
}
else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
{
{
if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
{
return error;
}
}
if ( st_ivas->ivas_format == MASA_FORMAT )
{
......@@ -883,6 +796,7 @@ ivas_error ivas_init_decoder(
{
return error;
}
if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup )
{
if ( ( error = ivas_sba_get_hoa_dec_matrix( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK )
......@@ -891,18 +805,18 @@ ivas_error ivas_init_decoder(
}
}
if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar,
st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK )
if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK )
{
return error;
}
if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA )
if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO )
{
if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK )
{
return error;
}
for ( k = 0; k < DIRAC_MAX_NBANDS; k++ )
{
st_ivas->hSpar->dirac_to_spar_md_bands[k] = st_ivas->hDirAC->dirac_to_spar_md_bands[k];
......@@ -921,7 +835,7 @@ ivas_error ivas_init_decoder(
}
else
{
if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK )
if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK )
{
return error;
}
......@@ -967,6 +881,7 @@ ivas_error ivas_init_decoder(
{
return error;
}
reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
}
......@@ -977,7 +892,6 @@ ivas_error ivas_init_decoder(
return error;
}
for ( n = 0; n < CPE_CHANNELS; n++ )
{
reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
......@@ -993,6 +907,7 @@ ivas_error ivas_init_decoder(
}
st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
}
if ( st_ivas->nCPE > 1 )
......@@ -1048,7 +963,6 @@ ivas_error ivas_init_decoder(
return error;
}
for ( n = 0; n < CPE_CHANNELS; n++ )
{
reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
......@@ -1070,12 +984,12 @@ ivas_error ivas_init_decoder(
return error;
}
}
if ( ( error = ivas_param_mc_dec_open( st_ivas ) ) != IVAS_ERR_OK )
{
return error;
}
for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
{
if ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK )
......@@ -1083,7 +997,6 @@ ivas_error ivas_init_decoder(
return error;
}
for ( n = 0; n < CPE_CHANNELS; n++ )
{
reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
......@@ -1112,7 +1025,6 @@ ivas_error ivas_init_decoder(
return error;
}
st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && output_config == AUDIO_CONFIG_STEREO );
if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MCMASA_MONO_STEREO )
......@@ -1129,7 +1041,7 @@ ivas_error ivas_init_decoder(
if ( st_ivas->hVBAPdata == NULL )
{
/* Distribute signal to all channels if VBAP is not properly initialized. */
set_f( st_ivas->hLsSetupCustom->separate_ch_gains, 1 / sqrtf( st_ivas->hLsSetupCustom->num_spk ), st_ivas->hLsSetupCustom->num_spk );
set_f( st_ivas->hLsSetupCustom->separate_ch_gains, inv_sqrt( st_ivas->hLsSetupCustom->num_spk ), st_ivas->hLsSetupCustom->num_spk );
}
else
{
......@@ -1153,6 +1065,7 @@ ivas_error ivas_init_decoder(
return error;
}
}
reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
}
......@@ -1161,6 +1074,7 @@ ivas_error ivas_init_decoder(
if ( st_ivas->hOutSetup.separateChannelEnabled )
{
st_ivas->element_mode_init = IVAS_CPE_MDCT;
if ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate - st_ivas->hSCE[0]->element_brate ) ) != IVAS_ERR_OK )
{
return error;
......@@ -1169,11 +1083,13 @@ ivas_error ivas_init_decoder(
else
{
st_ivas->element_mode_init = IVAS_CPE_MDCT;
if ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK )
{
return error;
}
}
for ( n = 0; n < CPE_CHANNELS; n++ )
{
reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] );
......@@ -1189,6 +1105,7 @@ ivas_error ivas_init_decoder(
}
st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
}
/* set CNA/CNG flags */
......@@ -1261,6 +1178,7 @@ ivas_error ivas_init_decoder(
{
return error;
}
if ( st_ivas->hRenderConfig->roomAcoustics.late_reverb_on )
{
if ( ( st_ivas->hCrend = (CREND_HANDLE) count_malloc( sizeof( CREND_DATA ) ) ) == NULL )
......@@ -1550,12 +1468,7 @@ void ivas_initialize_handles_dec(
st_ivas->hCPE[i] = NULL;
}
#ifdef FIX_I98_HANDLES_TO_NULL
st_ivas->bit_stream = NULL;
#else
st_ivas->nSCE = 0;
st_ivas->nCPE = 0;
#endif
st_ivas->mem_hp20_out = NULL;
st_ivas->hLimiter = NULL;
......@@ -1566,9 +1479,6 @@ void ivas_initialize_handles_dec(
}
/* spatial coding handles */
#ifndef FIX_I98_HANDLES_TO_NULL
st_ivas->hIsmRendererData = NULL;
#endif
st_ivas->hDirAC = NULL;
st_ivas->hSpar = NULL;
st_ivas->hMasa = NULL;
......@@ -1861,7 +1771,6 @@ void ivas_init_dec_get_num_cldfb_instances(
{
*numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans;
if ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC )
{
*numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE;
......@@ -2067,17 +1976,9 @@ static ivas_error doSanityChecks_IVAS(
#endif
#ifdef DEBUGGING
#ifdef FIX_I98_HANDLES_TO_NULL
if ( ( st_ivas->hDecoderConfig->Opt_HRTF_binary || st_ivas->hDecoderConfig->force_rend == FORCE_TD_RENDERER ) && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || output_config != AUDIO_CONFIG_BINAURAL || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode != MC_MODE_MCT ) ) )
#else
if ( ( st_ivas->hHrtfTD != NULL || st_ivas->hDecoderConfig->force_rend == FORCE_TD_RENDERER ) && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || output_config != AUDIO_CONFIG_BINAURAL || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode != MC_MODE_MCT ) ) )
#endif
#else
#ifdef FIX_I98_HANDLES_TO_NULL
if ( st_ivas->hDecoderConfig->Opt_HRTF_binary && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || output_config != AUDIO_CONFIG_BINAURAL || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) ) )
#else
if ( st_ivas->hHrtfTD != NULL && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || output_config != AUDIO_CONFIG_BINAURAL || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) ) )
#endif
#endif
{
return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration: Time Domain object renderer not supported in this configuration" );
......