Skip to content
......@@ -50,9 +50,7 @@
*-------------------------------------------------------------------------*/
static void apply_dmx_weights( CPE_DEC_HANDLE hCPE, float *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] );
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
static void run_min_stats( Decoder_State **sts, float *x[CPE_CHANNELS][NB_DIV] );
#endif
/*-------------------------------------------------------------------*
* convert_coeffs_to_higher_res()
......@@ -218,11 +216,6 @@ void stereo_mdct_core_dec(
initMdctStereoDecData( hCPE->hStereoMdct, sts[0]->igf, sts[0]->hIGFDec->igfData.igfInfo.grid, hCPE->element_brate, sts[0]->bwidth );
hCPE->hStereoMdct->isSBAStereoMode = ( ( st_ivas->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) );
/*to prevent unitialized values during condition checks for stereo IGF*/
if ( hCPE->hStereoMdct->isSBAStereoMode )
{
set_s( hCPE->hStereoMdct->IGFStereoMode, -1, 2 );
}
if ( !bfi )
{
......@@ -299,7 +292,7 @@ void stereo_mdct_core_dec(
assert( ( sts[0]->core == sts[1]->core ) || ( hCPE->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO ) );
/* stereo IGF decoding */
decoder_tcx_IGF_stereo( sts, hCPE->hStereoMdct, ms_mask, x, L_frame[0], left_rect[0], k, bfi );
decoder_tcx_IGF_stereo( sts, hCPE->hStereoMdct, ms_mask, x, L_frame[0], left_rect[0], k, bfi, 0 /* MCT_flag */ );
}
else
{
......@@ -329,37 +322,9 @@ void stereo_mdct_core_dec(
sns_interpolate_scalefactors( &sns_int_scf[0], &Aq[ch][k * M], DEC );
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( st->hTonalMDCTConc != NULL && ( ( k + 1 ) == nSubframes[ch] ) )
#else
if ( st->hTonalMDCTConc != NULL )
#endif
{
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
int16_t infoIGFStartLine;
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[ch], L_frame[ch] );
}
else
{
infoIGFStartLine = L_frameTCX[ch];
}
}
else
{
infoIGFStartLine = min( st->hIGFDec->infoIGFStartLine, L_frameTCX[ch] );
}
TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], infoIGFStartLine );
#else
TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0] );
#endif
TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) );
}
}
......@@ -375,8 +340,7 @@ void stereo_mdct_core_dec(
#ifdef DEBUGGING
assert( ( sts[0]->core == sts[1]->core ) || ( ( hCPE->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO ) && ( hCPE->hStereoMdct->mdct_stereo_mode[1] == SMDCT_DUAL_MONO ) ) );
#endif
stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], x[0], x[1], &hCPE->hStereoMdct->mdct_stereo_mode[0],
sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], 0, sts[0]->last_core, sts[1]->last_core, 0 );
stereo_decoder_tcx( hCPE->hStereoMdct, ms_mask, x_0[1], x[0], x[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0 );
}
ivas_mdct_core_tns_ns( hCPE, 0, fUseTns, tnsData, x, Aq, 0 );
......@@ -386,9 +350,7 @@ void stereo_mdct_core_dec(
ivas_ls_setup_conversion_process_mdct_param_mc( st_ivas, x );
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
run_min_stats( sts, x );
#endif
if ( hCPE->nchan_out == 1 && ( !bfi || ( bfi && sts[0]->core != ACELP_CORE && sts[1]->core != ACELP_CORE ) ) )
{
......@@ -607,7 +569,6 @@ static void apply_dmx_weights(
return;
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
/*-------------------------------------------------------------------*
* run_min_stats()
*
......@@ -687,4 +648,3 @@ static void run_min_stats(
st->VAD = save_VAD[ch];
}
}
#endif
......@@ -214,7 +214,8 @@ void stereo_decoder_tcx(
const int16_t core_l, /* i : core for left channel (TCX20/TCX10) */
const int16_t core_r, /* i : core for right channel (TCX20/TCX10) */
const int16_t igf, /* i : flag for IGF activity */
const int16_t L_frame, /* i : TCX frame length */
const int16_t L_frameTCX_l, /* i : TCX frame length of left channel */
const int16_t L_frameTCX_r, /* i : TCX frame length of right channel */
const int16_t mct_on, /* i : flag mct block (1) or stereo (0) */
const int16_t last_core_l, /* i : last core for left channel */
const int16_t last_core_r, /* i : last core for right channel */
......@@ -328,11 +329,11 @@ void stereo_decoder_tcx(
if ( ( nrgRatio > 1.0f ) && ( k < ( ( core_r == TCX_20_CORE ) ? 1 : NB_DIV ) ) )
{
v_multc( spec_r[k], nrgRatio, spec_r[k], L_frame / ( ( core_r == TCX_20_CORE ) ? 1 : NB_DIV ) );
v_multc( spec_r[k], nrgRatio, spec_r[k], L_frameTCX_r );
}
else if ( ( nrgRatio < 1.0f ) && ( k < ( ( core_l == TCX_20_CORE ) ? 1 : NB_DIV ) ) )
{
v_multc( spec_l[k], 1.0f / nrgRatio, spec_l[k], L_frame / ( ( core_l == TCX_20_CORE ) ? 1 : NB_DIV ) );
v_multc( spec_l[k], 1.0f / nrgRatio, spec_l[k], L_frameTCX_l );
}
}
} /* for k */
......@@ -559,13 +560,13 @@ void updateBuffersForDmxMdctStereo(
sts[1] = hCPE->hCoreCoder[1];
/* synch buffers for inactive frames, but not for transition frames */
if ( hCPE->last_element_brate <= IVAS_SID_4k4 )
if ( hCPE->last_element_brate <= IVAS_SID_5k2 )
{
mvr2r( output[0], output[1], output_frame );
mvr2r( synth[0], synth[1], output_frame );
}
if ( hCPE->element_brate == IVAS_SID_4k4 && hCPE->last_element_brate > IVAS_SID_4k4 )
if ( hCPE->element_brate == IVAS_SID_5k2 && hCPE->last_element_brate > IVAS_SID_5k2 )
{
/* in the first SID frame after an active frame, create mid noise shape here, in SID frames that follow inactive frames, it is done directly in the SID decoding since the mid shape is being used in CNG then */
for ( int16_t p = 0; p < sts[0]->hFdCngDec->hFdCngCom->npart; p++ )
......@@ -575,7 +576,7 @@ void updateBuffersForDmxMdctStereo(
}
/* for transition of active->inactive frame, apply passive downmix on buffers */
if ( hCPE->last_element_brate <= IVAS_SID_4k4 )
if ( hCPE->last_element_brate <= IVAS_SID_5k2 )
{
delta = 1;
if ( output_frame == L_FRAME16k )
......@@ -641,13 +642,13 @@ void applyDmxMdctStereo(
fade = 1.f;
dmx_len = output_frame;
if ( hCPE->last_element_brate <= IVAS_SID_4k4 )
if ( hCPE->last_element_brate <= IVAS_SID_5k2 )
{
crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS );
step /= crossfade_len;
}
/* for first inactive CNG frame after active decoding we have to do a fade-OUT FROM the passive DMX */
else if ( hCPE->element_brate <= IVAS_SID_4k4 && hCPE->last_element_brate > IVAS_SID_4k4 )
else if ( hCPE->element_brate <= IVAS_SID_5k2 && hCPE->last_element_brate > IVAS_SID_5k2 )
{
crossfade_len = output_frame / 4;
step /= -crossfade_len;
......
......@@ -424,9 +424,7 @@ ivas_error stereo_memory_dec(
if ( hCPE->last_element_mode == IVAS_CPE_MDCT )
{
cpy_tcx_ltp_data( hCPE->hCoreCoder[1]->hTcxLtpDec, hCPE->hStereoDft->hTcxLtpDec, output_Fs );
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
deleteFdCngDec( &hCPE->hCoreCoder[1]->hFdCngDec );
#endif
}
/* memory update - needed in TD stereo, TCX/HQ frame -> DFT stereo, ACELP frame switching */
......@@ -489,12 +487,10 @@ ivas_error stereo_memory_dec(
/* deallocated TCX/IGF structures for second channel */
deallocate_CoreCoder_TCX( hCPE->hCoreCoder[1] );
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( hCPE->last_element_mode == IVAS_CPE_MDCT )
{
deleteFdCngDec( &hCPE->hCoreCoder[1]->hFdCngDec );
}
#endif
/* allocate TD stereo data structure */
if ( hCPE->hStereoTD != NULL )
......@@ -675,10 +671,6 @@ ivas_error stereo_memory_dec(
/* deallocate core-decoder substructures */
deallocate_CoreCoder( st );
#ifndef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
/* deallocate FD_CNG substructure */
deleteFdCngDec( &st->hFdCngDec );
#endif
st->first_CNG = 0;
}
......@@ -702,7 +694,6 @@ ivas_error stereo_memory_dec(
}
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
/* allocate Fd-Cng structure for second channel */
if ( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK )
{
......@@ -711,7 +702,6 @@ ivas_error stereo_memory_dec(
/* Init FD-CNG */
initFdCngDec( st );
#endif
if ( hCPE->last_element_mode == IVAS_CPE_DFT )
{
......@@ -832,7 +822,7 @@ ivas_error stereo_memory_dec(
if ( ivas_format == STEREO_FORMAT && hCPE->element_mode == IVAS_CPE_MDCT )
{
if ( hCPE->element_brate <= MAX_MDCT_ITD_BRATE && ivas_total_brate > IVAS_SID_4k4 )
if ( hCPE->element_brate <= MAX_MDCT_ITD_BRATE && ivas_total_brate > IVAS_SID_5k2 )
{
if ( hCPE->hStereoMdct->use_itd == 0 )
{
......@@ -852,13 +842,13 @@ ivas_error stereo_memory_dec(
else
{
/* de-allocate TCA data structure */
if ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate > IVAS_SID_4k4 && hCPE->hStereoTCA != NULL )
if ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate > IVAS_SID_5k2 && hCPE->hStereoTCA != NULL )
{
count_free( hCPE->hStereoTCA );
hCPE->hStereoTCA = NULL;
hCPE->hStereoMdct->use_itd = 0;
}
else if ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate <= IVAS_SID_4k4 )
else if ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate <= IVAS_SID_5k2 )
{
hCPE->hStereoMdct->itd = 0.0f;
}
......@@ -1011,7 +1001,7 @@ void synchro_synthesis(
if ( use_cldfb_for_last_dft )
{
if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_TD && ( ivas_total_brate > IVAS_SID_4k4 || hCPE->nchan_out == 2 ) )
if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_TD && ( ivas_total_brate > IVAS_SID_5k2 || hCPE->nchan_out == 2 ) )
{
stereo_tca_scale_R_channel( hCPE, output[0], output_frame );
}
......@@ -1349,7 +1339,7 @@ void stereo_switching_dec(
mvr2r( hCPE->input_mem[n], hCPE->output_mem[n], dft32ms_ovl );
}
if ( ivas_total_brate > IVAS_SID_4k4 || n == 0 || hCPE->last_element_mode != IVAS_CPE_TD || hCPE->nchan_out == 1 )
if ( ivas_total_brate > IVAS_SID_5k2 || n == 0 || hCPE->last_element_mode != IVAS_CPE_TD || hCPE->nchan_out == 1 )
{
for ( i = 0; i < dft32ms_ovl; i++ )
{
......@@ -1423,7 +1413,7 @@ void stereo_switching_dec(
/* no secondary channel in the previous frame -> memory resets */
if ( hCPE->element_mode > IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_DFT )
{
if ( hCPE->last_element_brate <= IVAS_SID_4k4 && hCPE->nchan_out == 2 )
if ( hCPE->last_element_brate <= IVAS_SID_5k2 && hCPE->nchan_out == 2 )
{
/* reset CLDFB memories */
cldfb_reset_memory( sts[0]->cldfbAna );
......@@ -1494,6 +1484,8 @@ void stereo_switching_dec(
sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length;
sts[1]->pit_res_max = sts[0]->pit_res_max;
sts[1]->pit_res_max_past = sts[0]->pit_res_max_past;
sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX;
sts[1]->hTcxDec->conceal_eof_gain = sts[0]->hTcxDec->conceal_eof_gain;
}
}
else if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_MDCT )
......
......@@ -51,7 +51,8 @@
* Local prototypes
*-------------------------------------------------------------*/
static void dec_prm_tcx( Decoder_State *st, int16_t param[], int16_t param_lpc[], int16_t *total_nbbits, int16_t *bitsRead );
static void dec_prm_tcx( Decoder_State *st, int16_t param[], int16_t param_lpc[], int16_t *total_nbbits, const int16_t last_element_mode, int16_t *bitsRead );
static void stereo_tcx_dec_mode_switch_reconf( Decoder_State *st, const int16_t MCT_flag, const int16_t last_element_mode );
/*-------------------------------------------------------------*
......@@ -62,11 +63,10 @@ static void dec_prm_tcx( Decoder_State *st, int16_t param[], int16_t param_lpc[]
void stereo_tcx_init_dec(
Decoder_State *st, /* i/o: decoder state structure */
const int16_t is_mct, /* i : MCT mode flag */
const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/
const int16_t last_element_mode /* i : element mode of previous frame */
)
{
int16_t frame_size_index;
TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
......@@ -103,7 +103,7 @@ void stereo_tcx_init_dec(
if ( st->element_mode == IVAS_SCE )
{
st->tcxonly = getTcxonly( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, is_mct );
st->tcxonly = getTcxonly( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, MCT_flag );
/* LPC quantization */
if ( st->sr_core <= INT_FS_16k && st->tcxonly == 0 )
......@@ -125,36 +125,13 @@ void stereo_tcx_init_dec(
}
}
if ( ( st->bits_frame_nominal != st->last_bits_frame_nominal ) || ( st->bwidth != st->last_bwidth ) || ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) || ( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ) )
if ( ( st->bits_frame_nominal != st->last_bits_frame_nominal ) ||
( st->bwidth != st->last_bwidth ) ||
( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) ||
( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ) )
{
/*re-initialization*/
st->rate_switching_init = 1;
/* Identify frame type - TCX Reconfiguration */
for ( frame_size_index = 0; frame_size_index < FRAME_SIZE_NB; frame_size_index++ )
{
if ( frame_size_index < FRAME_SIZE_NB - 1 )
{
if ( ( FrameSizeConfig[frame_size_index].frame_bits <= st->bits_frame_nominal ) && ( FrameSizeConfig[frame_size_index + 1].frame_bits > st->bits_frame_nominal ) )
{
break;
}
}
else
{
if ( FrameSizeConfig[frame_size_index].frame_bits <= st->bits_frame_nominal )
{
break;
}
}
}
/* Reconfigure Core */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
mode_switch_decoder_LPD( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, is_mct, last_element_mode );
#else
mode_switch_decoder_LPD( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, is_mct );
#endif
stereo_tcx_dec_mode_switch_reconf( st, MCT_flag, last_element_mode );
}
return;
......@@ -288,7 +265,7 @@ void stereo_tcx_core_dec(
tcx_current_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode;
#endif
dec_prm_tcx( st, param, param_lpc, &total_nbbits, &bitsRead );
dec_prm_tcx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead );
#ifdef FIX_IVAS_337 /*IVAS-337 consider BER */
if ( !st->rate_switching_init && st->BER_detect )
......@@ -457,11 +434,7 @@ void stereo_tcx_core_dec(
}
/* 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, hTcxDec->L_frameTCX );
st->con_tcx = 1;
set_f( &st->mem_pitch_gain[2], st->lp_gainp, st->nb_subfr );
......@@ -589,11 +562,7 @@ void stereo_tcx_core_dec(
TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB, hTcxDec->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 )
{
......@@ -750,11 +719,7 @@ void stereo_tcx_core_dec(
if ( st->element_mode != IVAS_CPE_TD )
{
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
ApplyFdCng( signal_out, NULL, NULL, NULL, st, st->bfi, 0 );
#else
ApplyFdCng( signal_out, NULL, NULL, st, st->bfi, 0 );
#endif
}
/* Generate additional comfort noise to mask potential coding artefacts */
......@@ -779,11 +744,7 @@ void stereo_tcx_core_dec(
if ( st->element_mode == IVAS_CPE_TD && st->idchan == 0 )
{
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
ApplyFdCng( signal_out, NULL, NULL, NULL, st, st->bfi, 0 );
#else
ApplyFdCng( signal_out, NULL, NULL, st, st->bfi, 0 );
#endif
}
}
......@@ -818,9 +779,9 @@ void stereo_tcx_core_dec(
/*-----------------------------------------------------------------*
* Function dec_prm_tcx() *
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
* decode TCX parameters
* Function dec_prm_tcx()
*
* Decode TCX parameters
*-----------------------------------------------------------------*/
static void dec_prm_tcx(
......@@ -828,6 +789,7 @@ static void dec_prm_tcx(
int16_t param[], /* o : decoded parameters */
int16_t param_lpc[], /* o : LPC parameters */
int16_t *total_nbbits, /* i/o: number of bits / decoded bits */
const int16_t last_element_mode, /* i : last element mode */
int16_t *bitsRead /* o : number of read bits */
)
{
......@@ -867,11 +829,7 @@ static void dec_prm_tcx(
*--------------------------------------------------------------------------------*/
/* 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
/* last_core for error concealment */
if ( !st->use_partial_copy && st->element_mode != IVAS_CPE_MDCT )
......@@ -885,6 +843,12 @@ static void dec_prm_tcx(
st->prev_bfi = 1;
}
/* possible need for reconfiguration can only be decided correctly once last_core_from_bs has been decoded */
if ( ( st->last_core != st->last_core_from_bs ) && ( st->last_core_from_bs != TCX_20_CORE && st->last_core_from_bs != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core_from_bs == ACELP_CORE && st->last_con_tcx == 1 ) ) )
{
stereo_tcx_dec_mode_switch_reconf( st, 0, last_element_mode );
}
st->last_core = st->last_core_from_bs;
/*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/
......@@ -947,3 +911,44 @@ static void dec_prm_tcx(
return;
}
/*-----------------------------------------------------------------*
* Function stereo_tcx_dec_mode_switch_reconf()
*
* Reconfigure stereo TCX parameters
*-----------------------------------------------------------------*/
static void stereo_tcx_dec_mode_switch_reconf(
Decoder_State *st, /* i/o: decoder state structure */
const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/
const int16_t last_element_mode /* i : element mode of previous frame */
)
{
int16_t frame_size_index;
st->rate_switching_init = 1;
/* Identify frame type - TCX Reconfiguration */
for ( frame_size_index = 0; frame_size_index < FRAME_SIZE_NB; frame_size_index++ )
{
if ( frame_size_index < FRAME_SIZE_NB - 1 )
{
if ( ( FrameSizeConfig[frame_size_index].frame_bits <= st->bits_frame_nominal ) && ( FrameSizeConfig[frame_size_index + 1].frame_bits > st->bits_frame_nominal ) )
{
break;
}
}
else
{
if ( FrameSizeConfig[frame_size_index].frame_bits <= st->bits_frame_nominal )
{
break;
}
}
}
/* Reconfigure Core */
mode_switch_decoder_LPD( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, MCT_flag, last_element_mode );
return;
}
......@@ -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>
......@@ -436,7 +436,7 @@ void vbap_determine_gains(
gain_ene += gain_triplet[ch] * gain_triplet[ch];
}
norm_value = 1.0f / sqrtf( gain_ene );
norm_value = inv_sqrt( gain_ene );
for ( ch = 0; ch < 3; ch++ )
{
......
......@@ -250,39 +250,14 @@ void IVAS_DEC_Close(
if ( ( *phIvasDec )->hVoIP )
{
IVAS_DEC_Close_VoIP( ( *phIvasDec )->hVoIP );
count_free( ( *phIvasDec )->hVoIP );
( *phIvasDec )->hVoIP = NULL;
}
if ( ( *phIvasDec )->isInitialized )
{
if ( ( *phIvasDec )->st_ivas )
{
ivas_destroy_dec( ( *phIvasDec )->st_ivas );
}
}
else
{
if ( ( *phIvasDec )->st_ivas->hDecoderConfig != NULL )
{
count_free( ( *phIvasDec )->st_ivas->hDecoderConfig );
( *phIvasDec )->st_ivas->hDecoderConfig = NULL;
}
#ifndef FIX_I98_HANDLES_TO_NULL
if ( ( *phIvasDec )->st_ivas->hHeadTrackData != NULL )
{
count_free( ( *phIvasDec )->st_ivas->hHeadTrackData );
( *phIvasDec )->st_ivas->hHeadTrackData = NULL;
}
ivas_render_config_close( &( ( *phIvasDec )->st_ivas->hRenderConfig ) );
ivas_HRTF_binary_close( &( *phIvasDec )->st_ivas->hHrtfTD );
#endif
count_free( ( *phIvasDec )->st_ivas );
}
( *phIvasDec )->st_ivas = NULL;
}
count_free( *phIvasDec );
*phIvasDec = NULL;
......@@ -1156,7 +1131,7 @@ static bool isSidFrame(
{
return true; /* EVS SID */
}
else if ( size == IVAS_SID_4k4 / FRAMES_PER_SEC )
else if ( size == IVAS_SID_5k2 / FRAMES_PER_SEC )
{
return true; /* IVAS SID */
}
......@@ -1489,6 +1464,8 @@ static void IVAS_DEC_Close_VoIP(
pcmdsp_fifo_destroy( &hVoIP->hFifoAfterTimeScaler );
count_free( hVoIP );
return;
}
......@@ -1789,7 +1766,11 @@ static ivas_error printConfigInfo_dec(
}
else if ( st_ivas->ivas_format == SBA_FORMAT )
{
#ifdef PRINT_SBA_ORDER
fprintf( stdout, "Input configuration: Scene Based Audio, Ambisonic order %i%s, %d transport channel(s)\n", st_ivas->sba_order, st_ivas->sba_planar ? " (Planar)" : "", st_ivas->nchan_transport );
#else
fprintf( stdout, "Input configuration: SBA - %d transport channel(s) %s\n", st_ivas->nchan_transport, st_ivas->sba_planar ? "(Planar)" : "" );
#endif
}
else if ( st_ivas->ivas_format == MASA_FORMAT )
{
......
......@@ -204,16 +204,15 @@ typedef struct
Float32 *secondLastPcmOut;
float *secondLastPowerSpectrum;
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
float scaleFactorsBackground[FDNS_NPTS];
float scf_fadeout;
PsychoacousticParameters *psychParams;
/* could be stored only once, since the same for all channels (always at 16Khz fs) */
PsychoacousticParameters psychParamsTCX20;
PsychoacousticParameters psychParamsTCX10;
float last_block_nrg;
float curr_noise_nrg;
#endif
float faded_signal_nrg;
float nFramesLost;
......
......@@ -834,6 +834,7 @@ void swb_tbe_dec(
{
scale = (float) ( hBWE_TD->prev1_shb_ener_sf / sqrt( ( hBWE_TD->prev2_shb_ener_sf * hBWE_TD->prev3_shb_ener_sf ) + 0.0001 ) );
scale = hBWE_TD->prev_res_shb_gshape * min( scale, 1.0f );
if ( hBWE_TD->prev2_shb_ener_sf > 2.0f * hBWE_TD->prev1_shb_ener_sf || hBWE_TD->prev3_shb_ener_sf > 2.0f * hBWE_TD->prev2_shb_ener_sf )
{
shb_ener_sf = 0.5f * scale * hBWE_TD->prev1_shb_ener_sf;
......
......@@ -93,15 +93,15 @@ ivas_error TonalMDCTConceal_Init(
hTonalMDCTConc->nSamplesCore = nSamplesCore;
hTonalMDCTConc->nScaleFactors = nScaleFactors;
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
set_zero( hTonalMDCTConc->scaleFactorsBackground, FDNS_NPTS );
hTonalMDCTConc->scf_fadeout = 1.0f;
PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k, 64, 1, 1, &hTonalMDCTConc->psychParamsTCX20 );
PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k / 2, 64, 0, 1, &hTonalMDCTConc->psychParamsTCX10 );
hTonalMDCTConc->psychParams = NULL;
hTonalMDCTConc->last_block_nrg = 0.0f;
hTonalMDCTConc->curr_noise_nrg = 0.0f;
#endif
hTonalMDCTConc->faded_signal_nrg = 0.0f;
/* Offset the pointer to the end of buffer, so that pTCI is not destroyed when
new time samples are stored in lastPcmOut */
......@@ -122,12 +122,8 @@ void TonalMDCTConceal_SaveFreqSignal(
const float *mdctSpectrum,
const uint16_t nNewSamples,
const uint16_t nNewSamplesCore,
const float *scaleFactors
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
,
const int16_t infoIGFStartLine
#endif
)
const float *scaleFactors,
const int16_t infoIGFStartLine )
{
float *temp;
int16_t nOldSamples;
......@@ -168,7 +164,6 @@ void TonalMDCTConceal_SaveFreqSignal(
if ( ( nNewSamples > 0 ) && ( nNewSamples <= 2 * L_FRAME_MAX ) )
{
/* Store new data */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
int16_t i;
hTonalMDCTConc->last_block_nrg = 0.0f;
......@@ -181,9 +176,6 @@ void TonalMDCTConceal_SaveFreqSignal(
{
hTonalMDCTConc->lastBlockData.spectralData[i] = mdctSpectrum[i];
}
#else
mvr2r( mdctSpectrum, hTonalMDCTConc->lastBlockData.spectralData, nNewSamples );
#endif
mvr2r( scaleFactors, hTonalMDCTConc->lastBlockData.scaleFactors, hTonalMDCTConc->nScaleFactors );
}
......@@ -500,15 +492,15 @@ void TonalMDCTConceal_InsertNoise(
int16_t *pSeed,
const float tiltCompFactor,
const float crossfadeGain,
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
const float concealment_noise[L_FRAME48k],
#endif
const float cngLevelBackgroundTrace_bfi,
const int16_t crossOverFreq )
{
int16_t i, l;
float x, y;
Word16 rnd;
float g, nrgNoiseInLastFrame, nrgWhiteNoise, tiltFactor, tilt;
float last_block_nrg_correct;
wmops_sub_start( "InsertNoise" );
......@@ -522,21 +514,20 @@ void TonalMDCTConceal_InsertNoise(
rnd = *pSeed;
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
/* based on what is done in tcx_noise_filling() */
/* always initialize these to avoid compiler warnings */
tiltFactor = (float) pow( max( 0.375f, tiltCompFactor ), 1.0f / hTonalMDCTConc->lastBlockData.nSamples );
tilt = 1.0f;
nrgNoiseInLastFrame = 0.0f;
nrgWhiteNoise = 0.0f;
#endif
hTonalMDCTConc->faded_signal_nrg = 0.0f;
last_block_nrg_correct = 0.0f;
if ( !hTonalMDCTConc->lastBlockData.blockIsValid )
{
/* may just become active if the very first frame is lost */
set_f( mdctSpectrum, 0.0f, hTonalMDCTConc->nSamples );
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
else if ( concealment_noise != NULL )
{
if ( !tonalConcealmentActive )
......@@ -564,7 +555,7 @@ void TonalMDCTConceal_InsertNoise(
/* actual fadeout is done in this case */
else
{
g *= (float) sqrt( hTonalMDCTConc->last_block_nrg / hTonalMDCTConc->curr_noise_nrg );
g *= (float) sqrt( cngLevelBackgroundTrace_bfi / hTonalMDCTConc->curr_noise_nrg );
for ( i = 0; i < crossOverFreq; i++ )
{
......@@ -579,6 +570,8 @@ void TonalMDCTConceal_InsertNoise(
{
mdctSpectrum[i] = g * y - crossfadeGain * x;
}
hTonalMDCTConc->faded_signal_nrg += mdctSpectrum[i] * mdctSpectrum[i];
}
for ( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ )
{
......@@ -599,6 +592,11 @@ void TonalMDCTConceal_InsertNoise(
for ( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ )
{
mdctSpectrum[l] = 0;
if ( l < crossOverFreq )
{
last_block_nrg_correct += hTonalMDCTConc->lastBlockData.spectralData[l] * hTonalMDCTConc->lastBlockData.spectralData[l];
hTonalMDCTConc->curr_noise_nrg -= concealment_noise[l] * concealment_noise[l];
}
}
}
......@@ -651,7 +649,7 @@ void TonalMDCTConceal_InsertNoise(
/* actual fadeout is done in this case */
else
{
g *= (float) sqrt( hTonalMDCTConc->last_block_nrg / hTonalMDCTConc->curr_noise_nrg );
g *= (float) sqrt( cngLevelBackgroundTrace_bfi / hTonalMDCTConc->curr_noise_nrg );
for ( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ )
{
......@@ -666,6 +664,7 @@ void TonalMDCTConceal_InsertNoise(
{
mdctSpectrum[l] = g * y - crossfadeGain * x;
}
hTonalMDCTConc->faded_signal_nrg += mdctSpectrum[l] * mdctSpectrum[l];
}
for ( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ )
{
......@@ -682,6 +681,7 @@ void TonalMDCTConceal_InsertNoise(
{
mdctSpectrum[l] = g * y - crossfadeGain * x;
}
hTonalMDCTConc->faded_signal_nrg += mdctSpectrum[l] * mdctSpectrum[l];
}
}
......@@ -698,6 +698,7 @@ void TonalMDCTConceal_InsertNoise(
{
mdctSpectrum[l] = g * y - crossfadeGain * x;
}
hTonalMDCTConc->faded_signal_nrg += mdctSpectrum[l] * mdctSpectrum[l];
}
for ( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ )
......@@ -706,16 +707,17 @@ void TonalMDCTConceal_InsertNoise(
}
}
}
if ( hTonalMDCTConc->faded_signal_nrg > 0.0f && hTonalMDCTConc->curr_noise_nrg > MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG )
{
float nrg_corr_factor;
nrg_corr_factor = sqrtf( ( hTonalMDCTConc->last_block_nrg - last_block_nrg_correct ) / hTonalMDCTConc->faded_signal_nrg );
v_multc( mdctSpectrum, nrg_corr_factor, mdctSpectrum, crossOverFreq );
}
}
#endif
else
{
#ifndef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
/* based on what is done in tcx_noise_filling() */
tiltFactor = (float) pow( max( 0.375f, tiltCompFactor ), 1.0f / hTonalMDCTConc->lastBlockData.nSamples );
tilt = 1.0f;
nrgNoiseInLastFrame = nrgWhiteNoise = 0.0f;
#endif
if ( !tonalConcealmentActive )
{
for ( i = 0; i < crossOverFreq; i++ )
......@@ -962,7 +964,6 @@ void TonalMDCTConceal_SaveTimeSignal(
return;
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
void TonalMdctConceal_create_concealment_noise(
float concealment_noise[L_FRAME48k],
CPE_DEC_HANDLE hCPE,
......@@ -971,7 +972,7 @@ void TonalMdctConceal_create_concealment_noise(
const int16_t idchan,
const int16_t subframe_idx,
const int16_t core,
const int16_t crossfade_gain,
const float crossfade_gain,
const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode )
{
STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct;
......@@ -1049,7 +1050,6 @@ void TonalMdctConceal_create_concealment_noise(
c_inv = sqrtf( 1 - hStereoMdct->lastCoh );
/* pre-compute the noise shape for later weighting of the noise spectra */
/* TODO: optimize by intertwining with later loop */
cngNoiseLevelPtr = &hFdCngCom->cngNoiseLevel[0];
inc = ( st->core > TCX_20_CORE ) ? 2 : 1;
start_idx = hFdCngCom->startBand / inc;
......@@ -1072,7 +1072,7 @@ void TonalMdctConceal_create_concealment_noise(
}
/* fill the noise vector */
hTonalMDCTConc->curr_noise_nrg = 0.001f;
hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG;
if ( noise_gen_mode == EQUAL_CORES || ( ( noise_gen_mode == TCX20_IN_0_TCX10_IN_1 && idchan == 0 ) || ( noise_gen_mode == TCX10_IN_0_TCX20_IN_1 && idchan == 1 ) ) )
{
/* current channel is TCX20 -> generate noise for "full-length" spectrum */
......@@ -1100,6 +1100,14 @@ void TonalMdctConceal_create_concealment_noise(
}
}
if ( st->tonal_mdct_plc_active )
{
for ( i = crossOverFreq; i < max( crossOverFreq, hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ); ++i )
{
concealment_noise[i] *= 0.0f;
}
}
/* restore common seed
- after finishing the first channel
- after a first subframe if the current channel is TCX10 */
......@@ -1108,8 +1116,65 @@ void TonalMdctConceal_create_concealment_noise(
*rnd_c = save_rnd_c;
}
st->seed_tcx_plc = *rnd;
wmops_sub_end();
return;
}
#endif
void TonalMdctConceal_whiten_noise_shape(
Decoder_State *st,
const int16_t L_frame,
const TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE whitening_mode )
{
int16_t inc, start_idx, stop_idx;
float *noiseLevelPtr, *scfs_bg, *scfs_for_shaping;
HANDLE_FD_CNG_COM hFdCngCom;
float whitenend_noise_shape[L_FRAME16k];
float scfs_int[FDNS_NPTS];
const PsychoacousticParameters *psychParams;
wmops_sub_start( "apply_sns_on_noise_shape" );
scfs_bg = &st->hTonalMDCTConc->scaleFactorsBackground[0];
psychParams = st->hTonalMDCTConc->psychParams;
hFdCngCom = st->hFdCngDec->hFdCngCom;
inc = ( ( whitening_mode == ON_FIRST_LOST_FRAME ? st->core : st->last_core ) > TCX_20_CORE ) ? 2 : 1;
start_idx = hFdCngCom->startBand / inc;
stop_idx = L_frame / inc;
noiseLevelPtr = hFdCngCom->cngNoiseLevel;
set_zero( whitenend_noise_shape, start_idx );
for ( int16_t j = start_idx; j < stop_idx; j++, noiseLevelPtr += inc )
{
whitenend_noise_shape[j] = *noiseLevelPtr;
}
if ( whitening_mode == ON_FIRST_LOST_FRAME )
{
float scf[SNS_NPTS];
sns_compute_scf( whitenend_noise_shape, psychParams, L_frame, scf );
sns_interpolate_scalefactors( scfs_int, scf, ENC );
sns_interpolate_scalefactors( scfs_bg, scf, DEC );
scfs_for_shaping = &scfs_int[0];
}
else /* whitening_mode == ON_FIRST_GOOD_FRAME */
{
scfs_for_shaping = &scfs_bg[0];
}
if ( sum_f( scfs_for_shaping, FDNS_NPTS ) > 0.0f )
{
sns_shape_spectrum( whitenend_noise_shape, psychParams, scfs_for_shaping, L_frame );
mvr2r( whitenend_noise_shape + start_idx, hFdCngCom->cngNoiseLevel, stop_idx - start_idx );
}
else
{
set_zero( hFdCngCom->cngNoiseLevel, stop_idx - start_idx );
}
wmops_sub_end();
}
......@@ -480,6 +480,13 @@ ivas_error acelp_core_enc(
residu( Aq, M, hLPDmem->old_exc, old_exc, st->L_frame );
}
if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO )
{
/* Prepare ACB memory of old_bwe_exc */
lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
}
/*---------------------------------------------------------------*
* Calculation of LP residual (filtering through A[z] filter)
*---------------------------------------------------------------*/
......
......@@ -151,8 +151,7 @@ void acelp_core_switch_enc(
* Excitation encoding
*----------------------------------------------------------------*/
config_acelp1( ENC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, -1, -1, &j, &i, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/
);
config_acelp1( ENC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, -1, -1, &j, &i, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ );
encod_gen_voic_core_switch( st, st->last_L_frame, inp, Aq, A, T_op, st->voicing, exc, cbrate );
......
......@@ -494,7 +494,6 @@ void bw_detect(
st->input_bwidth = st->max_bwidth;
}
if ( st->element_mode == EVS_MONO )
{
set_bw( -1, -1, st, st->codec_mode );
......
......@@ -943,7 +943,7 @@ void EstimateStereoTCXNoiseLevel(
const int16_t ignore_chan[], /* i : flag indicating whether the channel should be ignored */
float fac_ns[][NB_DIV], /* o : noise filling level */
int16_t param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */
const int16_t is_mct /* i : is mct flag */
const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
)
{
int16_t ch, n;
......@@ -964,7 +964,7 @@ void EstimateStereoTCXNoiseLevel(
{
continue;
}
total_brate = ( st->element_mode == IVAS_CPE_MDCT && !is_mct ) ? st->element_brate : st->total_brate;
total_brate = ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag ) ? st->element_brate : st->total_brate;
for ( n = 0; n < nSubframes; n++ )
{
......
......@@ -49,7 +49,7 @@
* Local function prototypes
*-----------------------------------------------------------------------*/
static void init_tcx( Encoder_State *st, const int16_t L_frame_old, const int32_t total_brate, const int32_t last_total_brate, const int16_t is_mct );
static void init_tcx( Encoder_State *st, const int16_t L_frame_old, const int32_t total_brate, const int32_t last_total_brate, const int16_t MCT_flag );
static void init_sig_buffers( Encoder_State *st, const int16_t L_frame_old, const int16_t L_subfr, const int32_t total_brate, const int32_t last_total_brate );
static void init_core_sig_ana( Encoder_State *st );
static void init_acelp( Encoder_State *st, const int16_t L_frame_old, const int32_t total_brate, const int32_t last_total_brate );
......@@ -62,16 +62,17 @@ static void init_modes( Encoder_State *st, const int32_t last_total_brate );
*-----------------------------------------------------------------------*/
void init_coder_ace_plus(
Encoder_State *st,
const int32_t last_total_brate,
const int16_t is_mct )
Encoder_State *st, /* i : Encoder state */
const int32_t last_total_brate, /* i : last total bitrate */
const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
)
{
TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
int16_t L_frame_old; /*keep old frame size for switching */
int16_t L_subfr;
/* Bitrate */
st->tcxonly = getTcxonly( st->element_mode, st->total_brate, is_mct );
st->tcxonly = getTcxonly( st->element_mode, st->total_brate, MCT_flag );
/* Core Sampling Rate */
st->sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode );
......@@ -167,7 +168,7 @@ void init_coder_ace_plus(
/* Initialize TCX */
if ( hTcxEnc != NULL )
{
init_tcx( st, L_frame_old, st->total_brate, last_total_brate, is_mct );
init_tcx( st, L_frame_old, st->total_brate, last_total_brate, MCT_flag );
}
/* Initialize Signal Buffers */
......@@ -252,7 +253,7 @@ static void init_tcx(
const int16_t L_frame_old,
const int32_t total_brate,
const int32_t last_total_brate,
const int16_t is_mct )
const int16_t MCT_flag )
{
TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
......@@ -260,7 +261,7 @@ static void init_tcx(
hTcxEnc->spectrum[0] = hTcxEnc->spectrum_long;
hTcxEnc->spectrum[1] = hTcxEnc->spectrum_long + N_TCX10_MAX;
init_tcx_cfg( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, st->L_frame, st->bwidth, hTcxEnc->L_frameTCX, st->fscale, st->encoderLookahead_enc, st->encoderLookahead_FB, st->preemph_fac, st->tcxonly, st->rf_mode, st->igf, st->hIGFEnc != NULL ? st->hIGFEnc->infoStopFrequency : 0, st->element_mode, st->ini_frame, is_mct, st->mct_chan_mode );
init_tcx_cfg( st->hTcxCfg, total_brate, st->sr_core, st->input_Fs, st->L_frame, st->bwidth, hTcxEnc->L_frameTCX, st->fscale, st->encoderLookahead_enc, st->encoderLookahead_FB, st->preemph_fac, st->tcxonly, st->rf_mode, st->igf, st->hIGFEnc != NULL ? st->hIGFEnc->infoStopFrequency : 0, st->element_mode, st->ini_frame, MCT_flag, st->mct_chan_mode );
/* Init TCX target bits correction factor */
hTcxEnc->tcx_target_bits_fac = 1.0f;
......
......@@ -50,9 +50,10 @@
*-------------------------------------------------------------------*/
void core_coder_mode_switch(
Encoder_State *st,
const int32_t last_total_brate,
const int16_t is_mct )
Encoder_State *st, /* i/o: encoder state structure */
const int32_t last_total_brate, /* i : last bitrate */
const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0)*/
)
{
TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
int16_t i, fscale, switchWB;
......@@ -78,7 +79,7 @@ void core_coder_mode_switch(
switchWB = 1; /*force init when coming from MODE1*/
}
tcxonly_tmp = getTcxonly( st->element_mode, st->total_brate, is_mct );
tcxonly_tmp = getTcxonly( st->element_mode, st->total_brate, MCT_flag );
if ( tcxonly_tmp != st->tcxonly )
{
......@@ -90,7 +91,7 @@ void core_coder_mode_switch(
st->sr_core = sr_core;
st->L_frame = (int16_t) ( sr_core / FRAMES_PER_SEC );
st->tcxonly = getTcxonly( st->element_mode, st->total_brate, is_mct );
st->tcxonly = getTcxonly( st->element_mode, st->total_brate, MCT_flag );
st->bits_frame_nominal = (int16_t) ( (float) st->L_frame / (float) st->fscale * (float) FSCALE_DENOM / 128.0f * (float) st->total_brate / 100.0f + 0.49f );
......@@ -115,7 +116,7 @@ void core_coder_mode_switch(
if ( st->hTcxCfg->fIsTNSAllowed )
{
InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, is_mct );
InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag );
SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, st->element_mode == IVAS_CPE_MDCT );
}
......@@ -151,7 +152,7 @@ void core_coder_mode_switch(
else
{
st->igf = getIgfPresent( st->element_mode, st->total_brate, st->bwidth, st->rf_mode, st->mct_chan_mode );
init_coder_ace_plus( st, last_total_brate, is_mct );
init_coder_ace_plus( st, last_total_brate, MCT_flag );
}
if ( st->igf && st->hBWE_TD != NULL )
......
......@@ -55,9 +55,7 @@
void writeTCXMode(
Encoder_State *st, /* i/o: encoder state structure */
BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
const int16_t is_mct,
#endif
const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
int16_t *nbits_start /* o : nbits start */
)
{
......@@ -88,12 +86,10 @@ void writeTCXMode(
push_next_indice( hBstr, index, 2 );
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
if ( st->element_mode == IVAS_CPE_MDCT && !is_mct )
if ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag )
{
push_next_indice( hBstr, st->vad_flag, 1 );
}
#endif
}
else
{
......@@ -792,11 +788,7 @@ void enc_prm(
/* EVS header */
/* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
writeTCXMode( st, st->hBstr, 0, /* <- is_mct */ &nbits_start );
#else
writeTCXMode( st, st->hBstr, &nbits_start );
#endif
writeTCXMode( st, st->hBstr, 0 /* MCT_flag */, &nbits_start );
/* write last_core for error concealment */
if ( !( core == ACELP_CORE && st->hTcxCfg->lfacNext <= 0 ) )
......
......@@ -909,6 +909,10 @@ void stereoFdCngCoherence(
sts[0]->core_brate = SID_2k40;
sts[1]->core_brate = SID_2k40;
}
/* synchronize SID counters */
sts[0]->hDtxEnc->cnt_SID = min( sts[0]->hDtxEnc->cnt_SID, sts[1]->hDtxEnc->cnt_SID );
sts[1]->hDtxEnc->cnt_SID = sts[0]->hDtxEnc->cnt_SID;
}
pt_fftL = fft_buff[0];
......@@ -1009,11 +1013,7 @@ void FdCngEncodeMDCTStereoSID(
convertToMS( N, ms_ptr[0], ms_ptr[1], 0.5f );
}
side_energy = 0.0f;
for ( p = 0; p < N; p++ )
{
side_energy += ms_ptr[1][p] * ms_ptr[1][p];
}
side_energy = sum2_f( ms_ptr[1], N );
/* do not transmit side shape if initial noise shapes are very similar */
if ( side_energy <= 0.1f )
......@@ -1135,6 +1135,9 @@ void FdCngEncodeMDCTStereoSID(
push_indice( sts[ch]->hBstr, IND_ENERGY, gain_idx[ch], 7 );
}
/* pad with zeros to reach common SID frame size */
push_indice( sts[1]->hBstr, IND_ENERGY, 0, ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC );
return;
}
......@@ -1188,18 +1191,11 @@ void FdCngEncodeDiracMDCTStereoSID(
/* M/S transform on log envelopes */
convertToMS( NPART, ms_ptr[0], ms_ptr[1], 0.5f );
E[0] = 0.0f;
for ( p = 0; p < NPART; p++ )
{
E[0] += ms_ptr[0][p];
}
E[0] = sum_f( ms_ptr[0], NPART );
/* Quantize M noise shape */
/* Normalize MSVW input */
gain[0] = 0.f;
for ( p = N_GAIN_MIN; p < N_GAIN_MAX; p++ )
{
gain[0] += ms_ptr[0][p];
}
gain[0] = sum_f( ms_ptr[0] + N_GAIN_MIN, N_GAIN_MAX - N_GAIN_MIN );
gain[0] /= (float) ( N_GAIN_MAX - N_GAIN_MIN );
for ( p = 0; p < N[0]; p++ )
......@@ -1215,11 +1211,7 @@ void FdCngEncodeDiracMDCTStereoSID(
set_zero( ms_ptr[1], NPART );
/* compute M gain */
gain[0] = 0.f;
for ( p = 0; p < NPART; p++ )
{
gain[0] += ms_ptr[0][p];
}
gain[0] = sum_f( ms_ptr[0], NPART );
gain[0] = ( E[0] - gain[0] ) / (float) N[0];
apply_scale( &gain[0], sts[0]->hFdCngEnc->hFdCngCom->CngBandwidth, sts[0]->hDtxEnc->last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO );
......
......@@ -82,7 +82,6 @@ void frame_spec_dif_cor_rate(
/* 1073741.824 = 0.001 * 32768 * 32768 */
spec_low_dif_cor_rate = (float) ( m / sqrt( ( dx * dy + 1073741.824f ) ) );
spec_dif_cor_rate = spec_low_dif_cor_rate;
f_tonality_rate[0] = spec_dif_cor_rate;
f_tonality_rate[1] = f_tonality_rate[1] * 0.96f + spec_dif_cor_rate * 0.04f;
......
......@@ -1852,7 +1852,7 @@ void IGFEncApplyStereo(
const IGF_ENC_INSTANCE_HANDLE hIGFEnc[CPE_CHANNELS], /* i : instance handle of IGF Encoder */
const int16_t igfGridIdx, /* i : IGF grid index */
Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */
float pPowerSpectrum[CPE_CHANNELS][N_MAX], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */
float *pPowerSpectrum[CPE_CHANNELS], /* i/o: MDCT^2 + MDST^2 spectrum, or estimate */
float *pPowerSpectrumMsInv[CPE_CHANNELS][2], /* i/o: inverse power spectrum */
float *inv_spectrum[CPE_CHANNELS][2], /* i : inverse spectrum */
const int16_t frameno, /* i : flag indicating index of current subfr. */
......
......@@ -792,8 +792,13 @@ ivas_error init_encoder(
}
initFdCngEnc( st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale );
/* initialization for IVAS modes happens in first frame pre-processing */
if ( st->element_mode == EVS_MONO )
{
configureFdCngEnc( st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate );
}
}
else
{
st->hFdCngEnc = NULL;
......