Skip to content
......@@ -791,7 +791,7 @@ void acelp_fast_fx(
FOR( i = 0; i < L_subfr; i++ )
{
y_tmp[i] = add( y_tmp[i], *p_hn++ ); // q_H
y_tmp[i] = add_sat( y_tmp[i], *p_hn++ ); // q_H
move16();
}
......
......@@ -6,9 +6,8 @@
//#include "prot_fx.h"
//#include "basop_mpy.h"
#include "options.h"
#include "cnst.h" /* Common constants */
#include "cnst.h"
#include "stl.h"
#include "count.h"
#include "basop_util.h"
#include "rom_com_fx.h"
#include "ivas_cnst.h"
......
......@@ -48,200 +48,6 @@
* - reconfig core coder when switching to another frame type *
*-----------------------------------------------------------------*/
void core_coder_reconfig(
Encoder_State *st,
const int32_t last_total_brate )
{
TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
int16_t bwidth, i, index;
/*Configuration of ACELP*/
BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) );
/*Configuration of partial copy*/
if ( st->Opt_RF_ON )
{
st->hRF->acelp_cfg_rf.mode_index = 1;
st->hRF->acelp_cfg_rf.midLpc = 0;
st->hRF->acelp_cfg_rf.midLpc_enable = 0;
st->hRF->acelp_cfg_rf.pre_emphasis = 0;
st->hRF->acelp_cfg_rf.formant_enh = 1;
st->hRF->acelp_cfg_rf.formant_tilt = 1;
st->hRF->acelp_cfg_rf.voice_tilt = 1;
st->hRF->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1;
st->hRF->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2;
}
if ( st->element_mode == IVAS_CPE_MDCT )
{
st->nb_bits_header_tcx = 2; /* signal class */
}
else if ( st->tcxonly )
{
st->nb_bits_header_tcx = 1 + 1; /*TCX20/TCX10 + last_core*/
st->nb_bits_header_tcx += 2; /* Siganl class*/
}
else
{
st->nb_bits_header_ace = 1 + 2 + 1; /*TCX/ACELP+coder_type + last_core*/
st->nb_bits_header_tcx = st->nb_bits_header_ace;
if ( st->hTcxCfg != NULL )
{
if ( st->hTcxCfg->lfacNext <= 0 )
{
st->nb_bits_header_ace--; /*No last_core*/
}
}
}
/*Switch off TCX or ACELP?*/
if ( st->sr_core == INT_FS_12k8 )
{
st->acelpEnabled = ( st->restrictedMode & 1 ) == 1;
st->tcx20Enabled = ( st->restrictedMode & 2 ) == 2;
}
st->prevEnergyHF_fx = st->currEnergyHF_fx = 1073725440l /*65535.0f Q14*/; /* prevent block switch */
st->currEnergyHF_e_fx = 17;
move32();
move32();
move16();
/* TCX-LTP */
if ( st->hTcxEnc != NULL )
{
st->hTcxEnc->tcxltp = getTcxLtp( st->sr_core );
}
/*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/
st->acelp_autocorr = 1;
if ( st->total_brate <= ACELP_9k60 && st->sr_core == INT_FS_12k8 )
{
st->acelp_autocorr = 0;
}
/*Get audio bandwidth info*/
if ( st->narrowBand )
{
bwidth = NB;
}
else if ( st->sr_core <= INT_FS_16k )
{
bwidth = WB;
}
else
{
bwidth = SWB;
}
/*Scale TCX for non-active frames to adjust loudness with ACELP*/
if ( st->hTcxCfg != NULL )
{
st->hTcxCfg->na_scale = 32767;
if ( bwidth < SWB && !( st->tcxonly ) )
{
for ( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ )
{
if ( ( bwidth == scaleTcxTable[i].bwmode ) &&
( st->total_brate >= scaleTcxTable[i].bitrateFrom ) &&
( st->total_brate < scaleTcxTable[i].bitrateTo ) )
{
if ( st->rf_mode )
{
i--;
}
st->hTcxCfg->na_scale = scaleTcxTable[i].scale;
break;
}
}
}
}
if ( st->element_mode > IVAS_SCE )
{
st->enableTcxLpc = ( st->lpcQuantization == 1 ) && ( st->total_brate <= LOWRATE_TCXLPC_MAX_BR_CPE || st->rf_mode );
}
else
{
st->enableTcxLpc = ( st->lpcQuantization == 1 ) && ( st->total_brate <= LOWRATE_TCXLPC_MAX_BR || st->rf_mode );
}
if ( st->ini_frame == 0 || st->last_codec_mode == MODE1 )
{
st->envWeighted = 0;
}
if ( st->bwidth == SWB && ( st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO )
{
if ( st->tec_tfa == 0 )
{
set16_fx( st->hTECEnc->loBuffer, 0, MAX_TEC_SMOOTHING_DEG );
}
st->tec_tfa = 1;
}
else
{
st->tec_tfa = 0;
}
st->enablePlcWaveadjust = 0;
if ( st->total_brate >= HQ_48k )
{
st->enablePlcWaveadjust = 1;
}
st->glr = 0;
if ( ( st->total_brate == ACELP_9k60 || st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO )
{
st->glr = 1;
}
if ( st->glr )
{
st->nb_bits_header_ace += G_LPC_RECOVERY_BITS;
}
if ( hTcxEnc != NULL )
{
if ( st->bwidth == NB || st->bwidth == WB )
{
index = min( N_TCX_STARTLINE_NOISE_WB - 1, (uint16_t) max( 0, ( st->rf_mode == 0 ) ? st->frame_size_index : st->frame_size_index - 1 ) );
hTcxEnc->nmStartLine = startLineWB[index];
}
else /* (st->bwidth == SWB || st->bwidth == FB) */
{
index = min( N_TCX_STARTLINE_NOISE_SWB - 1, (uint16_t) max( 3, ( st->rf_mode == 0 ) ? st->frame_size_index : st->frame_size_index - 1 ) - 3 );
if ( st->total_brate >= IVAS_96k && st->total_brate <= IVAS_192k && st->element_mode > IVAS_SCE )
{
index--;
}
hTcxEnc->nmStartLine = startLineSWB[index];
if ( st->total_brate == IVAS_48k && st->element_mode == IVAS_CPE_MDCT && hTcxEnc->nmStartLine * 5 < st->L_frame * 4 )
{
hTcxEnc->nmStartLine = ( hTcxEnc->nmStartLine * 5 ) >> 2; /* low-rate stereo is more efficient than dual-mono due to stereo processing */
}
}
}
if ( hTcxEnc != NULL )
{
if ( st->total_brate < ACELP_24k40 && ( ( st->total_brate > last_total_brate ) || ( st->last_codec_mode == MODE1 ) ) )
{
/* low-freq memQuantZeros must be reset partially if bitrate increased */
set_c( hTcxEnc->memQuantZeros, 0, hTcxEnc->nmStartLine );
}
else
{
if ( st->total_brate >= ACELP_24k40 && st->total_brate <= ACELP_32k && last_total_brate >= ACELP_13k20 && last_total_brate < ACELP_24k40 )
{
set_c( hTcxEnc->memQuantZeros, 0, st->L_frame );
}
}
}
return;
}
void core_coder_reconfig_ivas_fx(
Encoder_State *st )
{
......@@ -270,6 +76,7 @@ void core_coder_reconfig_ivas_fx(
move16();
move16();
move16();
move16();
}
IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
......@@ -305,8 +112,8 @@ void core_coder_reconfig_ivas_fx(
/*Switch off TCX or ACELP?*/
IF( EQ_32( st->sr_core, INT_FS_12k8 ) )
{
st->acelpEnabled = (Word16) EQ_16( ( s_and( st->restrictedMode, 1 ) ), 1 );
st->tcx20Enabled = (Word16) EQ_16( ( s_and( st->restrictedMode, 2 ) ), 2 );
st->acelpEnabled = extract_l( EQ_16( ( s_and( st->restrictedMode, 1 ) ), 1 ) );
st->tcx20Enabled = extract_l( EQ_16( ( s_and( st->restrictedMode, 2 ) ), 2 ) );
move16();
move16();
}
......@@ -455,7 +262,7 @@ void core_coder_reconfig_ivas_fx(
test();
test();
test();
if ( ( EQ_32( st->total_brate, ACELP_9k60 ) || EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) )
if ( ( EQ_32( st->total_brate, ACELP_9k60 ) || EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( st->element_mode == EVS_MONO ) )
{
move16();
st->glr = 1;
......@@ -502,7 +309,7 @@ void core_coder_reconfig_ivas_fx(
move16();
test();
test();
if ( EQ_32( st->total_brate, IVAS_48k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LT_16( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), shl( st->L_frame, 2 ) ) )
IF( EQ_32( st->total_brate, IVAS_48k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LT_16( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), shl( st->L_frame, 2 ) ) )
{
hTcxEnc->nmStartLine = shr( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), 2 ); /* low-rate stereo is more efficient than dual-mono due to stereo processing */
move16();
......
......@@ -31,7 +31,7 @@ void core_coder_reconfig_fx(
BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) );
/*Configuration of partial copy*/
if ( st->Opt_RF_ON )
IF( st->Opt_RF_ON )
{
st->hRF->acelp_cfg_rf.mode_index = 1;
st->hRF->acelp_cfg_rf.midLpc = 0;
......@@ -58,6 +58,7 @@ void core_coder_reconfig_fx(
IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
{
st->nb_bits_header_tcx = 2; /* signal class */
move16();
}
ELSE IF( st->tcxonly == 0 )
{
......@@ -71,6 +72,7 @@ void core_coder_reconfig_fx(
{
/*st->nb_bits_header_ace--;*/ /*No Last_mode*/
st->nb_bits_header_ace = sub( st->nb_bits_header_ace, 1 );
move16();
}
}
}
......@@ -78,6 +80,7 @@ void core_coder_reconfig_fx(
if ( st->tcxonly )
{
st->nb_bits_header_tcx = add( st->nb_bits_header_tcx, 2 );
move16();
}
......@@ -109,11 +112,11 @@ void core_coder_reconfig_fx(
st->currEnergyHF_e_fx = 17;
/*Sanity check : don't need to be instrumented*/
if ( st->tcxonly == 0 )
IF( st->tcxonly == 0 )
{
assert( st->acelpEnabled || st->tcx20Enabled || st->frame_size_index == 0 );
}
else
ELSE
{
assert( st->tcx10Enabled || st->tcx20Enabled || st->frame_size_index == 0 );
}
......@@ -122,6 +125,7 @@ void core_coder_reconfig_fx(
IF( st->hTcxEnc != NULL )
{
hTcxEnc->tcxltp = getTcxLtp( st->sr_core );
move16();
}
/*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/
......@@ -157,6 +161,7 @@ void core_coder_reconfig_fx(
IF( st->hTcxCfg != NULL )
{
st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
move16();
test();
IF( LT_16( bwidth, 2 ) && ( st->tcxonly == 0 ) )
......@@ -174,7 +179,7 @@ void core_coder_reconfig_fx(
{
if ( st->rf_mode )
{
i--;
i = sub( i, 1 );
}
move16();
st->hTcxCfg->na_scale = scaleTcxTable[i].scale;
......@@ -242,11 +247,11 @@ void core_coder_reconfig_fx(
move16();
st->glr = 0;
test();
test();
test();
test();
if ( ( EQ_32( st->total_brate, ACELP_9k60 ) || EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) )
if ( ( EQ_32( st->total_brate, ACELP_9k60 ) || EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( st->element_mode == EVS_MONO ) )
{
move16();
st->glr = 1;
......@@ -256,13 +261,14 @@ void core_coder_reconfig_fx(
{
st->nb_bits_header_ace = add( st->nb_bits_header_ace, G_LPC_RECOVERY_BITS );
move16();
}
IF( hTcxEnc != NULL )
{
test();
IF( EQ_16( st->bwidth, NB ) || EQ_16( st->bwidth, WB ) )
{
test();
IF( st->rf_mode == 0 )
{
index = s_min( N_TCX_STARTLINE_NOISE_WB - 1, s_max( 3, st->frame_size_index ) );
......@@ -292,9 +298,12 @@ void core_coder_reconfig_fx(
}
hTcxEnc->nmStartLine = startLineSWB[index];
move16();
test();
test();
if ( EQ_32( st->total_brate, IVAS_48k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LT_16( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), shl( st->L_frame, 2 ) ) )
{
hTcxEnc->nmStartLine = shr( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), 2 ); /* low-rate stereo is more efficient than dual-mono due to stereo processing */
move16();
}
}
}
......
......@@ -68,7 +68,7 @@ void core_coder_mode_switch_ivas_fx(
move16();
IF( EQ_16( st->last_core, AMR_WB_CORE ) )
if ( EQ_16( st->last_core, AMR_WB_CORE ) )
{
bSwitchFromAmrwbIO = 1;
move16();
......@@ -99,7 +99,7 @@ void core_coder_mode_switch_ivas_fx(
st->sr_core = sr_core;
move16();
Word16 tmp = BASOP_Util_Divide3232_Scale( sr_core, FRAMES_PER_SEC, &exp_res );
st->L_frame = shr( tmp, 15 - exp_res );
st->L_frame = shr( tmp, sub( 15, exp_res ) ); // Q0
move16();
st->tcxonly = getTcxonly_fx( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format );
......@@ -119,7 +119,7 @@ void core_coder_mode_switch_ivas_fx(
Word32 tmp4 = L_mult0( tmp1, tmp2 ); // exp_tmp1 + exp_tmp2
Word32 tmp5 = L_shl( Mpy_32_16_1( tmp4, tmp3 ), 1 ); // exp_tmp1 + exp_tmp2 + exp_tmp3
st->bits_frame_nominal = (Word16) L_shr( tmp5, sub( 31, ( add( add( exp_tmp1, exp_tmp2 ), exp_tmp3 ) ) ) );
st->bits_frame_nominal = extract_l( L_shr( tmp5, sub( 31, ( add( add( exp_tmp1, exp_tmp2 ), exp_tmp3 ) ) ) ) );
move16();
st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode );
move16();
......@@ -133,12 +133,30 @@ void core_coder_mode_switch_ivas_fx(
st->hTcxCfg->bandwidth = getTcxBandwidth( st->bwidth );
move16();
st->hTcxCfg->tcxRateLoopOpt = ( st->tcxonly ) ? 2 : 0;
st->hTcxCfg->tcxRateLoopOpt = ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ? 3 : st->hTcxCfg->tcxRateLoopOpt;
if ( st->tcxonly )
{
st->hTcxCfg->tcxRateLoopOpt = 2;
move16();
}
else
{
st->hTcxCfg->tcxRateLoopOpt = 0;
move16();
}
if ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
{
st->hTcxCfg->tcxRateLoopOpt = 3;
move16();
}
st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, st->total_brate, st->rf_mode );
st->hTcxCfg->resq = getResq( st->total_brate );
hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->total_brate, st->rf_mode, st->element_mode );
st->hTcxCfg->tcxRateLoopOpt = ( st->hTcxCfg->resq && !st->tcxonly ) ? 1 : st->hTcxCfg->tcxRateLoopOpt;
test();
if ( st->hTcxCfg->resq && !st->tcxonly )
{
st->hTcxCfg->tcxRateLoopOpt = 1;
move16();
}
st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st->total_brate, st->igf, st->element_mode );
move16();
move16();
......@@ -174,7 +192,7 @@ void core_coder_mode_switch_ivas_fx(
FOR( i = 0; i < FRAME_SIZE_NB; i++ )
{
IF( FrameSizeConfig[i].frame_bits == st->bits_frame_nominal )
IF( EQ_32( FrameSizeConfig[i].frame_bits, st->bits_frame_nominal ) )
{
st->frame_size_index = i;
st->bits_frame = FrameSizeConfig[i].frame_bits;
......@@ -182,7 +200,7 @@ void core_coder_mode_switch_ivas_fx(
move16();
move16();
move16();
break;
BREAK;
}
}
......@@ -210,7 +228,7 @@ void core_coder_mode_switch_ivas_fx(
st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift );
move16();
init_coder_ace_plus_ivas_fx( st, last_total_brate, MCT_flag );
IF( st->hLPDmem != NULL )
if ( st->hLPDmem != NULL )
{
st->hLPDmem->q_lpd_old_exc = st->prev_Q_new;
move16();
......@@ -268,7 +286,7 @@ void core_coder_mode_switch_ivas_fx(
test();
test();
IF( ( GT_32( last_total_brate, HQ_32k ) || EQ_16( st->last_codec_mode, MODE1 ) ) && EQ_16( st->element_mode, EVS_MONO ) )
if ( ( GT_32( last_total_brate, HQ_32k ) || EQ_16( st->last_codec_mode, MODE1 ) ) && ( st->element_mode == EVS_MONO ) )
{
st->glr_reset = 1;
move16();
......
......@@ -29,8 +29,7 @@ void core_coder_mode_switch_fx(
TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD;
TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
move16();
move16();
move16();
move16();
......@@ -43,7 +42,7 @@ void core_coder_mode_switch_fx(
}
sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format );
move16();
move32();
fscale = sr2fscale( sr_core );
move16();
......@@ -59,7 +58,6 @@ void core_coder_mode_switch_fx(
tcxonly_tmp = getTcxonly( st->total_brate );
#endif
test();
if ( NE_16( tcxonly_tmp, st->tcxonly ) )
{
move16();
......@@ -85,9 +83,9 @@ void core_coder_mode_switch_fx(
/* st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1( L_shl(st->bitrate,8), mult_r(div_s(st->fscale, shl(st->L_frame,4)), FL2WORD16(FSCALE_DENOM/12800.f))), 6)); */
tmp32 = L_shl( st->total_brate, 1 ); /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */
st->bits_frame_nominal = extract_l( L_shr( Mpy_32_16_1( tmp32, 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */
move16();
st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode );
move16();
/* switch IGF configuration */
IF( st->igf )
{
......@@ -111,7 +109,7 @@ void core_coder_mode_switch_fx(
st->hTcxCfg->resq = getResq( st->total_brate );
move16();
hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->total_brate, st->rf_mode, st->element_mode );
move16();
test();
if ( st->hTcxCfg->resq != 0 && st->tcxonly == 0 )
{
......@@ -119,6 +117,7 @@ void core_coder_mode_switch_fx(
move16();
}
st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st->total_brate, st->igf, st->element_mode );
move16();
IF( st->hTcxCfg->fIsTNSAllowed != 0 )
{
InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag );
......@@ -126,7 +125,6 @@ void core_coder_mode_switch_fx(
SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, EQ_16( st->element_mode, IVAS_CPE_MDCT ) );
#endif
}
move16();
st->narrowBand = 0;
move16();
......@@ -166,12 +164,13 @@ void core_coder_mode_switch_fx(
}
st->restrictedMode = getRestrictedMode( st->element_mode, st->total_brate, 0 );
move16();
core_coder_reconfig_fx( st, last_total_bitrate );
}
ELSE
{
st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode );
move16();
init_coder_ace_plus_fx( st, last_total_bitrate, shift, MCT_flag );
}
......@@ -218,7 +217,7 @@ void core_coder_mode_switch_fx(
}
test();
IF( ( GT_32( last_total_bitrate, HQ_32k ) || EQ_32( st->last_codec_mode, MODE1 ) ) && EQ_16( st->element_mode, EVS_MONO ) )
IF( ( GT_32( last_total_bitrate, HQ_32k ) || EQ_32( st->last_codec_mode, MODE1 ) ) && ( st->element_mode == EVS_MONO ) )
{
move16();
st->glr_reset = 1;
......
......@@ -72,17 +72,18 @@ void core_encode_update_ivas_fx(
test();
test();
test();
IF( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) )
IF( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || ( st->core_brate == FRAME_NO_DATA ) )
{
Word16 max_e = s_max( st->hTcxEnc->exp_buf_speech_ltp, hTcxEnc->exp_buf_speech_ltp );
Scale_sig( hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, -( max_e - st->hTcxEnc->exp_buf_speech_ltp ) );
Copy_Scale_sig( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame, -( max_e - st->exp_buf_speech_enc ) );
Scale_sig( hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, negate( sub( max_e, st->hTcxEnc->exp_buf_speech_ltp ) ) ); // Q(31-max_e)
Copy_Scale_sig( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame, negate( sub( max_e, st->exp_buf_speech_enc ) ) ); // Q(31-max_e)
st->hTcxEnc->exp_buf_speech_ltp = max_e;
move16();
}
}
n = add( st->encoderPastSamples_enc, st->encoderLookahead_enc );
Copy( st->buf_synth + st->L_frame, st->buf_synth, st->L_frame + L_SUBFR );
Copy( st->buf_synth + st->L_frame, st->buf_synth, add( st->L_frame, L_SUBFR ) );
IF( hTcxEnc != NULL )
{
Copy( hTcxEnc->buf_speech_ltp + st->L_frame, hTcxEnc->buf_speech_ltp, n );
......@@ -105,7 +106,8 @@ void core_encode_update_ivas_fx(
test();
test();
test();
IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && ( EQ_16( st->codec_mode, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) ) )
test();
IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && ( EQ_16( st->codec_mode, MODE2 ) || ( st->element_mode > EVS_MONO ) ) ) )
{
/* reset LP memories */
set16_fx( st->mem_MA_fx, 0, M );
......
......@@ -38,7 +38,7 @@ void core_encode_update_fx( Encoder_State *st )
IF( hTcxEnc != NULL )
{
IF( EQ_16( st->core, ACELP_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core, AMR_WB_CORE ) )
IF( ( st->core == ACELP_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core, AMR_WB_CORE ) )
{
Copy( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame );
}
......@@ -146,7 +146,7 @@ void core_encode_update_cng_fx(
IF( EQ_32( st->core_brate, SID_2k40 ) )
{
/*IVAS_CODE CNG_att is missing */
enr = cng_energy_fx( st->element_mode, st->bwidth, hDtxEnc->CNG_mode, /*st->hTdCngEnc->CNG_att*/ 0, hLPDmem->old_exc + s_max( L_EXC_MEM - st->L_frame, 0 ), st->L_frame, Q_new );
enr = cng_energy_fx( st->element_mode, st->bwidth, hDtxEnc->CNG_mode, /*st->hTdCngEnc->CNG_att*/ 0, hLPDmem->old_exc + s_max( sub( L_EXC_MEM, st->L_frame ), 0 ), st->L_frame, Q_new );
/* calculate the energy quantization index */
enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */
......@@ -157,24 +157,24 @@ void core_encode_update_cng_fx(
enr_index = s_max( enr_index, 0 );
hTdCngEnc->old_enr_index = enr_index;
move16();
}
/* Update weighted synthesis memory */
move16();
p_A = Aw;
FOR( i = 0; i < st->L_frame; i += L_SUBFR )
{
Residu3_fx( p_A, &synth[i], &wsyn[i], L_SUBFR, 0 );
p_A += ( M + 1 );
}
move16();
tmp = sub( st->wspeech_enc[-1], shl( hLPDmem->mem_w0, shift ) );
E_UTIL_deemph2( -shift, wsyn, st->preemph_fac, st->L_frame, &tmp );
E_UTIL_deemph2( negate( shift ), wsyn, st->preemph_fac, st->L_frame, &tmp );
hLPDmem->mem_w0 = sub( st->wspeech_enc[st->L_frame - 1], tmp );
hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift );
move16();
move16();
/* Update LPC-related memories */
Copy( lsp, st->lsp_old_fx, M );
......@@ -193,7 +193,9 @@ void core_encode_update_cng_fx(
hLPDmem->dm_fx.prev_state = 0;
hLPDmem->tilt_code = TILT_CODE;
hLPDmem->gc_threshold = L_deposit_l( 0 );
move16();
move16();
move16();
/* Update ace/tcx mode */
move16();
st->core = ACELP_CORE;
......
......@@ -48,9 +48,9 @@
void core_switching_pre_enc_ivas_fx(
Encoder_State *st_fx, /* i/o: encoder state structure */
const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz */
const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz q_old_inp_12k8 */
const Word16 q_old_inp_12k8, /* i : Q old input signal @12.8kHz */
const Word16 *old_inp_16k, /* i : old input signal @16kHz */
const Word16 *old_inp_16k, /* i : old input signal @16kHz q_old_inp_16k */
const Word16 q_old_inp_16k, /* i : Q old input signal @16kHz */
const Word16 active_cnt, /* i : active frame counter */
const Word16 last_element_mode /* i : last_element_mode */
......@@ -70,7 +70,7 @@ void core_switching_pre_enc_ivas_fx(
test();
test();
test();
IF( EQ_16( st_fx->last_codec_mode, MODE2 ) || ( ( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) && GT_16( st_fx->element_mode, EVS_MONO ) ) ) )
IF( EQ_16( st_fx->last_codec_mode, MODE2 ) || ( ( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) && ( st_fx->element_mode > EVS_MONO ) ) ) )
{
IF( hLPDmem != NULL )
{
......@@ -87,11 +87,12 @@ void core_switching_pre_enc_ivas_fx(
IF( hBWE_TD != NULL )
{
IF( NE_16( st_fx->last_core, ACELP_CORE ) )
IF( st_fx->last_core != ACELP_CORE )
{
/* reset BWE memories */
set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 );
move32();
}
set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
......@@ -99,7 +100,7 @@ void core_switching_pre_enc_ivas_fx(
test();
IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) )
{
if ( EQ_16( st_fx->element_mode, EVS_MONO ) )
if ( st_fx->element_mode == EVS_MONO )
{
st_fx->last_core = HQ_CORE;
move16();
......@@ -122,8 +123,9 @@ void core_switching_pre_enc_ivas_fx(
hHQ_core->prev_stab_hfe2 = 0;
move16();
}
test();
/*ALDO overlap windowed past: also used in MODE2 but for other MDCT-LB*/
IF( EQ_16( st_fx->element_mode, EVS_MONO ) && hTcxEnc != NULL )
IF( ( st_fx->element_mode == EVS_MONO ) && hTcxEnc != NULL )
{
set16_fx( hTcxEnc->old_out_fx, 0, L_FRAME32k );
}
......@@ -135,6 +137,7 @@ void core_switching_pre_enc_ivas_fx(
Copy( st_fx->lsp_old_fx, st_fx->lsp_old16k_fx, M );
st_fx->rate_switching_reset_16kHz = lsp_convert_poly_fx( st_fx->lsp_old16k_fx, st_fx->L_frame, 0 );
move16();
}
st_fx->use_acelp_preq = 0;
......@@ -144,7 +147,7 @@ void core_switching_pre_enc_ivas_fx(
test();
test();
test();
IF( EQ_16( st_fx->last_core, -1 ) && ( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) ) )
if ( EQ_16( st_fx->last_core, -1 ) && ( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) ) )
{
/* very first frame is HQ_CORE */
st_fx->last_core = HQ_CORE;
......@@ -153,7 +156,7 @@ void core_switching_pre_enc_ivas_fx(
test();
test();
IF( EQ_16( st_fx->core, HQ_CORE ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) /* HQ init */
IF( EQ_16( st_fx->core, HQ_CORE ) && ( ( st_fx->last_core == ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) /* HQ init */
{
set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX );
......@@ -171,7 +174,7 @@ void core_switching_pre_enc_ivas_fx(
hHQ_core->prev_stab_hfe2 = 0;
move16();
if ( hTcxEnc != NULL )
IF( hTcxEnc != NULL )
{
set16_fx( hTcxEnc->old_out_fx, 0, L_FRAME32k );
}
......@@ -181,7 +184,7 @@ void core_switching_pre_enc_ivas_fx(
within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */
test();
test();
IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) ) )
IF( ( st_fx->core == ACELP_CORE ) && ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) ) )
{
IF( hSC_VBR != NULL )
{
......@@ -197,7 +200,7 @@ void core_switching_pre_enc_ivas_fx(
test();
test();
test();
IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || LE_32( st_fx->last_total_brate, PPP_NELP_2k80 ) ) )
IF( ( st_fx->core == ACELP_CORE ) && ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || LE_32( st_fx->last_total_brate, PPP_NELP_2k80 ) ) )
{
st_fx->act_count = 3;
move16();
......@@ -207,7 +210,12 @@ void core_switching_pre_enc_ivas_fx(
test();
test();
IF( ( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) ) ||
test();
test();
test();
test();
test();
IF( ( ( ( st_fx->core == ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) ) ||
( ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( active_cnt, 1 ) ) )
{
IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
......@@ -222,6 +230,7 @@ void core_switching_pre_enc_ivas_fx(
}
st_fx->mem_deemph_fx = 0;
move16();
/* Reset ACELP parameters */
IF( hLPDmem != NULL )
{
......@@ -255,7 +264,6 @@ void core_switching_pre_enc_ivas_fx(
move16();
tmp16 = add( NB_SUBFR, 1 );
move16();
if ( EQ_16( st_fx->L_frame, L_FRAME ) )
{
......@@ -268,7 +276,7 @@ void core_switching_pre_enc_ivas_fx(
/* Reset old ACELP buffers */
test();
IF( EQ_16( st_fx->element_mode, EVS_MONO ) && hLPDmem != NULL )
IF( ( st_fx->element_mode == EVS_MONO ) && hLPDmem != NULL )
{
set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM );
}
......@@ -278,6 +286,7 @@ void core_switching_pre_enc_ivas_fx(
/* reset BWE memories */
hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
move32();
}
IF( hBWE_FD != NULL )
{
......@@ -287,7 +296,7 @@ void core_switching_pre_enc_ivas_fx(
test();
test();
test();
IF( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) )
IF( ( ( st_fx->core == ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) )
{
/* Reset the ACELP core in case of TCX->ACELP core switching */
st_fx->Nb_ACELP_frames = 0;
......@@ -305,7 +314,8 @@ void core_switching_pre_enc_ivas_fx(
set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 );
hLPDmem->dm_fx.prev_state = 0;
move16();
hLPDmem->dm_fx.prev_gain_code = L_deposit_l( 0 );
hLPDmem->dm_fx.prev_gain_code = 0;
move32();
}
st_fx->last_coder_type = GENERIC;
......@@ -320,7 +330,7 @@ void core_switching_pre_enc_ivas_fx(
{
set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
move16();
move32();
}
/* reset BWE memories */
......@@ -361,7 +371,7 @@ void core_switching_pre_enc_ivas_fx(
{
Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS );
Sample_Delay_LP = NS2SA( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS );
IF( GT_16( st_fx->element_mode, EVS_MONO ) )
IF( ( st_fx->element_mode > EVS_MONO ) )
{
IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) )
{
......@@ -371,11 +381,11 @@ void core_switching_pre_enc_ivas_fx(
}
IF( GT_16( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) )
{
Copy_Scale_sig( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_12k8 ) );
Copy_Scale_sig( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_12k8 ) ); // prev_Q_input_lp
}
ELSE
{
Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) );
Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) ); // q_old_inp_12k8
hBWE_FD->prev_Q_input_lp = q_old_inp_12k8;
move16();
Copy( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP );
......@@ -395,19 +405,19 @@ void core_switching_pre_enc_ivas_fx(
}
IF( GT_16( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) )
{
Copy_Scale_sig( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_16k ) );
Copy_Scale_sig( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_16k ) ); // prev_Q_input_lp
}
ELSE
{
Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) );
Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) ); // q_old_inp_16k
hBWE_FD->prev_Q_input_lp = q_old_inp_16k;
move16();
Copy( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP );
}
}
tmp = sub( L_LOOK_16k + L_SUBFR16k, Sample_Delay_HP );
Copy( &hBWE_TD->old_speech_shb_fx[tmp], hBWE_FD->new_input_hp_fx, Sample_Delay_HP );
add( 0, 0 );
IF( NE_16( st_fx->last_extl, WB_BWE ) )
{
......@@ -416,7 +426,8 @@ void core_switching_pre_enc_ivas_fx(
hBWE_FD->modeCount = 0;
move16();
}
hBWE_FD->EnergyLF_fx = L_deposit_l( 0 );
hBWE_FD->EnergyLF_fx = 0;
move32();
hBWE_FD->prev_L_swb_norm1 = 8;
move16(); /*8.0 in Q0 */
st_fx->EnergyLT_fx_exp = 30;
......@@ -425,19 +436,21 @@ void core_switching_pre_enc_ivas_fx(
/*---------------------------------------------------------------------*
* band-width switching from WB -> SWB/FB
*---------------------------------------------------------------------*/
IF( GT_16( st_fx->element_mode, EVS_MONO ) )
IF( st_fx->element_mode > EVS_MONO )
{
IF( st_fx->bwidth_sw_cnt == 0 )
{
test();
IF( GE_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) )
{
st_fx->bwidth_sw_cnt = add( st_fx->bwidth_sw_cnt, 1 );
move16();
}
}
ELSE
{
st_fx->bwidth_sw_cnt = add( st_fx->bwidth_sw_cnt, 1 );
move16();
IF( EQ_16( st_fx->bwidth_sw_cnt, BWS_TRAN_PERIOD ) )
{
st_fx->bwidth_sw_cnt = 0;
......@@ -532,7 +545,7 @@ void core_switching_post_enc_ivas_fx(
test();
test();
test();
test();
IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) &&
( EQ_16( st->last_core, HQ_CORE ) || NE_16( st->L_frame, st->last_L_frame ) || ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) ) )
{
......@@ -573,11 +586,11 @@ void core_switching_post_enc_ivas_fx(
/* Fade towards init value for non HQ_CORE */
IF( st->hHQ_core != NULL )
{
st->hHQ_core->crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_lp_fx ), Mpy_32_32( L_sub( 2147483647, HQ_CREST_FAC_SM_FX ), HQ_CREST_THRESHOLD_FX ) ); /*Q28*/
st->hHQ_core->crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_lp_fx ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), HQ_CREST_THRESHOLD_FX ) ); /*Q28*/
move32();
st->hHQ_core->crest_lp_q = Q28;
move16();
st->hHQ_core->crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_mod_lp_fx ), Mpy_32_32( L_sub( 2147483647, HQ_CREST_FAC_SM_FX ), HQ_CREST_MOD_THRESHOLD_FX ) ); /*Q29*/
st->hHQ_core->crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_mod_lp_fx ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), HQ_CREST_MOD_THRESHOLD_FX ) ); /*Q29*/
move32();
st->hHQ_core->crest_mod_lp_q = Q29;
move16();
......
......@@ -764,7 +764,9 @@ void core_signal_analysis_high_bitrate_ivas_fx(
Q_exp = sub( *Q_new, st->prev_Q_new );
move16();
Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( *Q_new, st->Q_old ) ); // *Q_new
Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( *Q_new, sub( Q15, st->exp_old_inp_16k ) ) ); // *Q_new
st->exp_old_inp_16k = sub( Q15, *Q_new );
move16();
IF( Q_exp != 0 )
{
Scale_sig( st->buf_speech_enc_pe, st->encoderPastSamples_enc + st->encoderLookahead_enc, Q_exp ); // *Q_new
......
......@@ -32,11 +32,12 @@
#include <stdint.h>
#include <math.h>
#include <assert.h>
#include "options.h"
#include "ivas_prot.h"
#include "prot.h"
#include <math.h>
#include <assert.h>
#include "rom_com.h"
#include "wmc_auto.h"
#include "prot_fx.h"
#include "ivas_prot_fx.h"
......
......@@ -60,7 +60,8 @@ ivas_error ivas_core_enc(
const Word16 n_CoreChannels, /* i : number of core channels to be coded */
Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal */
Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal */
Word32 ener_fx[], /* i : residual energy from Levinson-Durbin Q6 */
Word16 Q_new[],
Word32 ener_fx[], /* i : residual energy from Levinson-Durbin epsP_fx_q */
Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */
Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes */
Word32 epsP_fx[][M + 1], /* i : LP prediction errors epsP_fx_q */
......@@ -90,7 +91,6 @@ ivas_error ivas_core_enc(
Encoder_State **sts, *st;
STEREO_ICBWE_ENC_HANDLE hStereoICBWE;
STEREO_TD_ENC_DATA_HANDLE hStereoTD;
Word16 Q_new[CPE_CHANNELS] = { 0 };
move16();
move16();
Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */
......@@ -834,7 +834,7 @@ ivas_error ivas_core_enc(
IF( !MCT_flag ) /* for MCT do this later, otherwise there can be a problem because TCX quant happens later and might get the wrong last_core on a bit rate switch */
{
updt_enc_common_ivas_fx( st );
updt_enc_common_ivas_fx( st, Q_new[n] );
}
IF( st->hBWE_FD != NULL )
......
......@@ -56,10 +56,10 @@ ivas_error pre_proc_ivas(
const Word32 element_brate, /* i : element bitrate */
const Word32 last_element_brate, /* i : last element bitrate */
const Word16 input_frame, /* i : frame length */
Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */
Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz */
Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal Q_new-1 */
Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz Q_new-1 */
Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame*/
Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q6 */
Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q */
Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */
Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes */
Word32 epsP_fx[M + 1], /* i : LP prediction errors epsP_fx_q */
......@@ -533,24 +533,29 @@ ivas_error pre_proc_ivas(
inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look;
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
Word16 Q_old_inp_16k = -1;
move16();
Word16 Q_r[2] = { 0 };
move16();
move16();
inp_16k_fx = old_inp_16k_fx + L_INP_MEM - L_look;
Word16 shift = getScaleFactor16( st->old_inp_12k8_fx, 240 );
Scale_sig( st->old_inp_12k8_fx, 240, shift );
Word16 shift = getScaleFactor16( st->old_inp_12k8_fx, L_INP_MEM );
Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift );
st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift );
move16();
Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( Q_old_inp_16k, sub( Q15, Q_old_inp_16k ) ) );
Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( Q_old_inp_16k, sub( Q15, st->exp_old_inp_16k ) ) );
st->exp_old_inp_16k = sub( Q15, Q_old_inp_16k );
if ( st->hBWE_FD != NULL )
move16();
IF( st->hBWE_FD != NULL )
{
Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) );
st->Q_old_wtda = -1; // This reset needs to be looked into
move16();
}
#endif
st->mem_preemph_enc = shl( st->mem_preemph_enc, sub( Q_old_inp_16k, sub( Q15, st->exp_mem_preemph_enc ) ) );
move16();
st->exp_mem_preemph_enc = sub( Q15, Q_old_inp_16k );
......@@ -566,20 +571,22 @@ ivas_error pre_proc_ivas(
Scale_sig( st->buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_wspeech_enc ) ) );
st->exp_buf_wspeech_enc = sub( Q15, Q_old_inp_16k );
move16();
Word16 Q_old_inp_128k = *Q_new;
move16();
IF( !flag_16k_smc )
{
error = ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, ener_fx,
A_fx, Aw_fx,
epsP_fx,
lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new );
lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new, 0 );
IF( NE_32( error, IVAS_ERR_OK ) )
{
return error;
}
*epsP_fx_q = add( Q_r[0], 1 );
move16();
}
test();
Scale_sig( old_inp_12k8_fx, L_INP_12k8, *Q_new ); // Q_new-1
IF( !( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) )
{
/* update signal buffers */
......@@ -626,6 +633,8 @@ ivas_error pre_proc_ivas(
IF( EQ_16( st->L_frame, L_FRAME ) )
{
*inp_fx = inp_12k8_fx;
*Q_new = Q_old_inp_128k;
move16();
}
ELSE
{
......@@ -682,7 +691,8 @@ ivas_error ivas_compute_core_buffers_fx(
Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */
Word16 Q_old_inp_16k,
Word16 Q_r[2],
Word16 *Q_new )
Word16 *Q_new,
Word16 downscale_buf_speech_enc_pe )
{
Word16 *inp_16k_fx, *new_inp_16k_fx;
Word16 delay, element_mode;
......@@ -909,8 +919,7 @@ ivas_error ivas_compute_core_buffers_fx(
test();
test();
IF( Q_new )
{
*Q_new = 0;
move16();
set32_fx( sig_out, 0, 960 );
......@@ -1070,97 +1079,6 @@ ivas_error ivas_compute_core_buffers_fx(
st->mem_preemph16k_DFT_fx = st->mem_preemph16k_fx;
move16();
}
}
ELSE
{
test();
test();
IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) )
{
IF( EQ_16( element_mode, IVAS_CPE_DFT ) )
{
Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw_fx, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching */
st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx;
move16();
st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1];
move16();
IF( EQ_16( st->L_frame, L_FRAME16k ) )
{
Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k );
}
PREEMPH_FX( new_inp_16k_fx - STEREO_DFT_OVL_16k, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) );
tmp_fx = st->mem_preemph16k_fx;
move16();
PREEMPH_FX( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx );
}
ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
{
IF( EQ_16( last_element_mode, IVAS_CPE_DFT ) )
{
st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx;
move16();
Copy( st->inp_16k_mem_stereo_sw_fx, new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k );
PREEMPH_FX( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx );
}
st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1];
move16();
/* preemphasise past segment of input signal when switching from MDCT stereo */
IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) )
{
Word16 length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS );
move16();
PREEMPH_FX( new_inp_16k_fx - add( lMemRecalc_16k, length_16k ), PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx );
}
IF( EQ_16( st->L_frame, L_FRAME16k ) )
{
Copy( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc + sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), add( lMemRecalc_16k, L_FRAME16k + L_FILT16k ) );
}
PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) );
tmp_fx = st->mem_preemph16k_fx;
move16();
PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, PREEMPH_FAC_16k, add( lMemRecalc_16k, L_FILT16k ), &tmp_fx );
}
ELSE IF( EQ_16( element_mode, IVAS_SCE ) )
{
PREEMPH_FX( new_inp_16k_fx, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) );
tmp_fx = st->mem_preemph16k_fx;
move16();
PREEMPH_FX( new_inp_16k_fx + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx );
}
}
ELSE IF( GT_32( input_Fs, 8000 ) ) /* keep memory up-to-date in case of bitrate switching */
{
IF( EQ_16( element_mode, IVAS_CPE_DFT ) )
{
st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - STEREO_DFT_OVL_16k - 1];
move16();
}
ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) )
{
st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - lMemRecalc_16k - 1];
move16();
}
ELSE IF( EQ_16( element_mode, IVAS_CPE_MDCT ) )
{
st->mem_preemph16k_fx = 0;
move16();
}
ELSE /* SCE */
{
st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - 1];
move16();
}
st->mem_preemph16k_DFT_fx = st->mem_preemph16k_fx;
move16();
}
}
/*-----------------------------------------------------------------*
* LP analysis at 16kHz if ACELP@16k core was selected
......@@ -1171,18 +1089,28 @@ ivas_error ivas_compute_core_buffers_fx(
IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) )
{
/* update signal buffers */
Word16 shift;
IF( downscale_buf_speech_enc_pe )
{
shift = negate( *Q_new );
}
ELSE
{
shift = 0;
}
move16();
IF( EQ_16( element_mode, IVAS_CPE_DFT ) )
{
Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc_pe + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k );
Copy_Scale_sig( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc_pe + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k, shift ); // Q-1
}
ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) )
{
Copy( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc_pe + L_FRAME16k - lMemRecalc_16k - L_FILT16k, L_FRAME16k + lMemRecalc_16k + L_FILT16k );
Copy_Scale_sig( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc_pe + L_FRAME16k - lMemRecalc_16k - L_FILT16k, L_FRAME16k + lMemRecalc_16k + L_FILT16k, shift ); // Q-1
}
ELSE
{
Copy( new_inp_resamp16k_fx, st->buf_speech_enc + L_FRAME16k, L_FRAME16k );
Copy( new_inp_16k_fx, st->buf_speech_enc_pe + L_FRAME16k, L_FRAME16k );
Copy_Scale_sig( new_inp_16k_fx, st->buf_speech_enc_pe + L_FRAME16k, L_FRAME16k, shift ); // Q-1
}
/*--------------------------------------------------------------*
......@@ -1195,7 +1123,14 @@ ivas_error ivas_compute_core_buffers_fx(
Copy( st->lsp_old1_fx, st->lspold_enc_fx, M );
}
analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, Q_new ? *Q_new : 0, Q_r );
IF( Q_new )
{
analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, sub( *Q_new, 1 ), Q_r );
}
ELSE
{
analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, -1, Q_r );
}
/*--------------------------------------------------------------*
* Compute Weighted Input
......@@ -1215,15 +1150,24 @@ ivas_error ivas_compute_core_buffers_fx(
IF( ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) || EQ_16( element_mode, IVAS_CPE_MDCT ) )
{
set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM );
st->exp_old_inp_16k = 0;
move16();
}
ELSE IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) )
{
Copy( &old_inp_16k_fx[L_frame_tmp], st->old_inp_16k_fx, L_INP_MEM );
IF( Q_new )
{
st->exp_old_inp_16k = sub( Q16, *Q_new ); //(*Q_new - 1)
move16();
}
}
ELSE IF( GT_32( input_Fs, 8000 ) )
{
lerp( st->old_inp_12k8_fx + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k_fx, L_INP_MEM, L_INP_MEM * 4 / 5 );
Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( -1 /* Q st->old_inp_16k_fx = -1 */, sub( 15, st->exp_old_inp_12k8 ) ) );
Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( -1 /* Q st->old_inp_16k_fx = -1 */, sub( 15, st->exp_old_inp_16k ) ) );
st->exp_old_inp_16k = Q16; // Q-1
move16();
}
IF( inp16k_out_fx != NULL )
......
......@@ -43,6 +43,10 @@
#include "ivas_prot_fx.h"
#include "wmc_auto.h"
#include <math.h>
#ifdef DEBUGGING
#include "debug.h"
#include "string.h"
#endif
#include "prot_fx_enc.h"
#include "ivas_prot_fx.h"
......@@ -74,7 +78,6 @@ static Word16 get_zero_flag( Word32 arr[], Word16 len )
IF( arr[j] != 0 )
{
return 1;
BREAK;
}
}
return 0;
......@@ -87,9 +90,9 @@ ivas_error pre_proc_front_ivas_fx(
const Word16 nb_bits_metadata, /* i : number of metadata bits */
const Word16 input_frame, /* i : frame length */
const Word16 n, /* i : channel number */
Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */
Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q-1 */
Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r */
Word16 old_inp_12k8_fx[], /* o : buffer of old input signal Q_new-1 */
Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1 */
Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q */
Word16 *relE_fx, /* o : frame relative energy Q8 */
Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12 */
Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12 */
......@@ -131,7 +134,12 @@ ivas_error pre_proc_front_ivas_fx(
const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/
const IVAS_FORMAT ivas_format, /* i : IVAS format */
const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
const Word32 ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */
const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX */
Word16 *Q_new
#ifdef DEBUG_MODE_INFO
,
const Word16 ch_idx
#endif
)
{
Encoder_State *st;
......@@ -240,10 +248,15 @@ ivas_error pre_proc_front_ivas_fx(
Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
Word16 res_cod_SNR_M_fx_e[STEREO_DFT_BAND_MAX];
Word16 band_energies_fx_exp, Qfact_PS, q_lf_E_fx;
#ifdef DEBUG_MODE_INFO
Word32 *in_buff_temp;
Word16 in_q_temp;
#endif
mem_decim_dummy_fx = (Word16 *) malloc( 90 * sizeof( Word16 * ) );
temp1F_icatdmResampBuf_fx = (Word16 *) malloc( 45 * sizeof( Word16 * ) );
set16_fx( fft_buff_fx, 0, 512 );
IF( hSCE != NULL )
{
Copy_Scale_sig_16_32( hSCE->hCoreCoder[n]->input_fx, hSCE->hCoreCoder[n]->input32_fx, input_frame, sub( Q11, hSCE->hCoreCoder[n]->q_inp ) );
......@@ -256,6 +269,11 @@ ivas_error pre_proc_front_ivas_fx(
Scale_sig( hSCE->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( -1, hSCE->hCoreCoder[n]->q_old_inp ) );
hSCE->hCoreCoder[n]->q_old_inp = -1;
move16();
#ifdef DEBUG_MODE_INFO
in_buff_temp = hSCE->hCoreCoder[n]->input32_fx;
in_q_temp = hSCE->hCoreCoder[n]->q_inp32;
#endif
}
ELSE
{
......@@ -269,7 +287,23 @@ ivas_error pre_proc_front_ivas_fx(
Scale_sig( hCPE->hCoreCoder[n]->old_input_signal_fx, input_frame, sub( -1, hCPE->hCoreCoder[n]->q_old_inp ) );
hCPE->hCoreCoder[n]->q_old_inp = -1;
move16();
#ifdef DEBUG_MODE_INFO
in_buff_temp = hCPE->hCoreCoder[n]->input32_fx;
in_q_temp = hCPE->hCoreCoder[n]->q_inp32;
#endif
}
#ifdef DEBUG_MODE_INFO
{
int16_t tmpF[L_FRAME48k];
for ( int16_t isample = 0; isample < input_frame; isample++ )
{
tmpF[isample] = (int16_t) ( (float) in_buff_temp[isample - NS2SA( st->input_Fs, ACELP_LOOK_NS )] / ( (float) ( 1 << in_q_temp ) ) );
}
dbgwrite( &tmpF, sizeof( int16_t ), input_frame, 1, strcat( fname( debug_dir, "ivas_input_dmx", 0, ch_idx + 1, ENC ), ".pcm" ) );
}
#endif
#ifdef MSAN_FIX
FOR( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ )
{
......@@ -574,12 +608,7 @@ ivas_error pre_proc_front_ivas_fx(
* Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1
*-----------------------------------------------------------------*/
Word16 Q_new = 1;
move16();
IF( Q_new )
{
Q_new = 0;
*Q_new = 0;
move16();
set32_fx( sig_out, 0, 960 );
......@@ -690,13 +719,13 @@ ivas_error pre_proc_front_ivas_fx(
shift = s_max( shift, 0 );
shift = s_min( shift, Q_MAX );
minimum_fx( st->Q_max, L_Q_MEM, &Q_min );
Q_new = s_min( shift, Q_min );
*Q_new = s_min( shift, Q_min );
move16();
IF( inp_max == 0 )
{
IF( NE_16( st->last_coder_type, UNVOICED ) )
{
Q_new = s_min( Q_new, 1 );
*Q_new = s_min( *Q_new, 1 );
move16();
}
}
......@@ -709,16 +738,13 @@ ivas_error pre_proc_front_ivas_fx(
st->Q_max[i] = shift;
move16();
Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, Q_new );
Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, *Q_new );
Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), Q_new );
Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), *Q_new );
*Q_new = add( *Q_new, Q_to_be_looked_into );
move16();
Q_new = add( Q_new, Q_to_be_looked_into );
}
ELSE
{
// See if needed
}
cldfbScale.hb_scale = cldfbScale.lb_scale;
move16();
......@@ -738,17 +764,29 @@ ivas_error pre_proc_front_ivas_fx(
Word16 Scale_fac[2] = { 0 };
move16();
move16();
Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) );
st->q_Bin_E = add( Q_new, Q_SCALE - 2 );
Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( *Q_new, Q_SCALE - 2 ), st->q_Bin_E ) );
st->q_Bin_E = add( *Q_new, Q_SCALE - 2 );
move16();
Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 );
ivas_analy_sp_fx_front( element_mode, hCPE, input_Fs, inp_12k8_fx /*old_inp_12k8_e*/, Q_new, fr_bands_fx, lf_E_fx, &Etot_fx, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, PS_fx, lgBin_E_fx, band_energies_fx, fft_buff_fx /*, Q_inp_dmx*/ );
st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 );
Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( *Q_new, QSCALE - 2 ) ) ), 1 ), 1 );
ivas_analy_sp_fx_front( element_mode, hCPE, input_Fs, inp_12k8_fx /*old_inp_12k8_e*/, *Q_new, fr_bands_fx, lf_E_fx, &Etot_fx, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, PS_fx, lgBin_E_fx, band_energies_fx, fft_buff_fx /*, Q_inp_dmx*/ );
st->q_Bin_E_old = add( *Q_new, Q_SCALE - 2 );
move16();
fr_bands_fx_q = add( Q_new, QSCALE );
band_energies_fx_exp = sub( 31, add( Q_new, QSCALE ) );
Qfact_PS = add( Q_new, QSCALE - 2 );
q_lf_E_fx = add( Q_new, QSCALE - 2 );
fr_bands_fx_q = add( *Q_new, QSCALE - 2 );
band_energies_fx_exp = sub( 31, add( *Q_new, QSCALE - 2 ) );
Word16 tmp_norm = L_norm_arr( fr_bands_fx, 2 * NB_BANDS );
IF( GE_16( tmp_norm, 2 ) )
{
scale_sig32( fr_bands_fx, 2 * NB_BANDS, 2 );
fr_bands_fx_q = add( fr_bands_fx_q, 2 );
}
tmp_norm = L_norm_arr( band_energies_fx, 2 * NB_BANDS );
IF( GE_16( tmp_norm, 2 ) )
{
scale_sig32( band_energies_fx, 2 * NB_BANDS, 2 );
band_energies_fx_exp = sub( band_energies_fx_exp, 2 );
}
Qfact_PS = add( *Q_new, QSCALE - 2 );
q_lf_E_fx = add( *Q_new, QSCALE - 2 );
IF( lgBin_E_fx != NULL )
{
Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) );
......@@ -758,7 +796,7 @@ ivas_error pre_proc_front_ivas_fx(
Word16 i_sbfr;
FOR( i_sbfr = 0; i_sbfr < 2; i_sbfr++ )
{
fft_q[i_sbfr] = add( Q_new, Scale_fac[i_sbfr] );
fft_q[i_sbfr] = add( *Q_new, Scale_fac[i_sbfr] );
move16();
min_q = s_min( min_q, fft_q[i_sbfr] );
}
......@@ -773,11 +811,11 @@ ivas_error pre_proc_front_ivas_fx(
move16();
move16();
Scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( add( Q_new, QSCALE ), st->hNoiseEst->q_bckr ) );
st->hNoiseEst->q_bckr = add( Q_new, QSCALE );
Scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( add( *Q_new, QSCALE ), st->hNoiseEst->q_bckr ) );
st->hNoiseEst->q_bckr = add( *Q_new, QSCALE );
move16();
Scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, sub( add( Q_new, QSCALE ), st->hNoiseEst->q_enrO ) );
st->hNoiseEst->q_enrO = add( Q_new, QSCALE );
Scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, sub( add( *Q_new, QSCALE ), st->hNoiseEst->q_enrO ) );
st->hNoiseEst->q_enrO = add( *Q_new, QSCALE );
move16();
IF( hStereoClassif != NULL )
......@@ -818,7 +856,7 @@ ivas_error pre_proc_front_ivas_fx(
move16();
}
st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), Q_new, NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float
st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), *Q_new, NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float
move16();
test();
......@@ -904,10 +942,10 @@ ivas_error pre_proc_front_ivas_fx(
* Correlation correction as a function of total noise level
*----------------------------------------------------------------*/
Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 );
Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( *Q_new, QSCALE ) ) ), 1 ), 1 );
noise_est_down_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_fx, &st->hNoiseEst->Etot_v_h2_fx, Q_new, Le_min_scaled );
st->hNoiseEst->q_bckr = add( Q_new, QSCALE );
noise_est_down_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_fx, &st->hNoiseEst->Etot_v_h2_fx, *Q_new, Le_min_scaled );
st->hNoiseEst->q_bckr = add( *Q_new, QSCALE );
move16();
test();
......@@ -935,7 +973,7 @@ ivas_error pre_proc_front_ivas_fx(
move16();
move16();
}
q_tmpN = q_tmpE = add( Q_new, QSCALE );
q_tmpN = q_tmpE = add( *Q_new, QSCALE );
move16();
*relE_fx = sub( Etot_fx, st->lp_speech_fx );
move16();
......@@ -1050,7 +1088,7 @@ ivas_error pre_proc_front_ivas_fx(
st->cng_type = LP_CNG;
move16();
}
dtx_ivas_fx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, Q_new );
dtx_ivas_fx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, *Q_new );
test();
test();
......@@ -1141,7 +1179,7 @@ ivas_error pre_proc_front_ivas_fx(
Word16 Q_new_loc;
Word16 Q_r[2];
set16_fx( Q_r, 0, 2 );
Q_new_loc = Q_new;
Q_new_loc = *Q_new;
move16();
alw_pitch_lag_12k8[0] = st->old_pitch_la;
......@@ -1190,7 +1228,7 @@ ivas_error pre_proc_front_ivas_fx(
*----------------------------------------------------------------*/
Word32 speech_buff[L_FRAME + M];
Copy_Scale_sig_16_32( inp_12k8_fx - M, speech_buff, L_FRAME + M, Q12 );
hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), add( Q_new, 12 ) );
hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), add( *Q_new, 12 ) );
move16();
}
......@@ -1201,14 +1239,14 @@ ivas_error pre_proc_front_ivas_fx(
* 1/4 pitch precision improvement
*----------------------------------------------------------------*/
st->mem_wsp_fx = shl( st->mem_wsp_fx, sub( Q_new, st->mem_wsp_q ) );
st->mem_wsp_q = Q_new;
st->mem_wsp_fx = shl( st->mem_wsp_fx, sub( *Q_new, st->mem_wsp_q ) );
st->mem_wsp_q = *Q_new;
move16();
move16();
ivas_find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 );
Word16 Q_wsp = Q_new;
Word16 Q_wsp = *Q_new;
move16();
IF( st->vad_flag == 0 )
{
......@@ -1308,7 +1346,7 @@ ivas_error pre_proc_front_ivas_fx(
q_fr_bands = s_min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q );
}
}
Word16 q_inp_12k8 = Q_new; // inp_12k8_fx
Word16 q_inp_12k8 = *Q_new; // inp_12k8_fx
move16();
scale_sig32( lf_E_fx, 2 * VOIC_BINS, sub( sub( q_fr_bands, 2 ), q_lf_E_fx ) );
......@@ -1508,10 +1546,6 @@ ivas_error pre_proc_front_ivas_fx(
* TC frame selection
*-----------------------------------------------------------------*/
Word16 oi12k8_fx[L_INP_12k8];
Copy_Scale_sig( old_inp_12k8_fx, oi12k8_fx, L_INP_12k8, negate( Q_new ) ); // Q0
Word16 *ni12k8_fx = oi12k8_fx + L_INP_MEM;
inp_12k8_fx = ni12k8_fx - L_look;
st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas );
select_TC_fx( MODE1, st->tc_cnt, &st->coder_type, st->localVAD );
......@@ -1669,8 +1703,9 @@ ivas_error pre_proc_front_ivas_fx(
Word16 Q_old_inp_16k = -1;
move16();
Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( Q_old_inp_16k, sub( Q15, Q_old_inp_16k ) ) );
Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( Q_old_inp_16k, sub( Q15, st->exp_old_inp_16k ) ) );
st->exp_old_inp_16k = sub( Q15, Q_old_inp_16k );
move16();
IF( st->hBWE_FD != NULL )
{
......@@ -1691,11 +1726,14 @@ ivas_error pre_proc_front_ivas_fx(
Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc ) ) );
st->exp_buf_speech_enc = sub( Q15, Q_old_inp_16k );
move16();
Word16 Q_old_inp_12k8 = *Q_new;
move16();
/* Compute core-coder buffers at internal sampling rate */
error = ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener_fx,
A_fx, Aw_fx,
epsP_fx,
lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, NULL );
lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new, 1 );
IF( error != IVAS_ERR_OK )
{
return error;
......@@ -1703,17 +1741,26 @@ ivas_error pre_proc_front_ivas_fx(
*epsP_fx_q = add( Q_r[0], 1 );
move16();
Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q15, st->exp_buf_speech_enc ) );
st->mem_wsp_enc = shr_r( st->mem_wsp_enc, *Q_new ); // Q_new - 1 -> Q-1
move16();
*Q_new = add( *Q_new, Q_to_be_looked_into ); // actual Q_new
move16();
Scale_sig( old_inp_12k8_fx, L_INP_12k8, sub( *Q_new, Q_old_inp_12k8 ) );
Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( 0, sub( Q15, st->exp_buf_speech_enc ) ) );
st->exp_buf_speech_enc = Q15;
move16();
smc_dec = ivas_acelp_tcx20_switching_fx( st, st->speech_enc, 0, st->wspeech_enc, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc );
}
ELSE
{
Scale_sig( old_wsp_fx, L_WSP, sub( Q_new, *q_old_wsp ) );
*q_old_wsp = Q_new;
Scale_sig( old_wsp_fx, L_WSP, sub( *Q_new, *q_old_wsp ) );
*q_old_wsp = *Q_new;
move16();
Q_wsp = Q_new;
Q_wsp = *Q_new;
move16();
smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc );
smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, *Q_new, wsp_fx, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc );
}
}
/* Switch to ACELP for non-harmonic transient signals */
......@@ -1741,11 +1788,11 @@ ivas_error pre_proc_front_ivas_fx(
}
}
Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) );
st->q_Bin_E = add( Q_new, Q_SCALE - 2 );
Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( *Q_new, Q_SCALE - 2 ), st->q_Bin_E ) );
st->q_Bin_E = add( *Q_new, Q_SCALE - 2 );
move16();
/* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */
ivas_smc_mode_selection_fx( st, element_brate, smc_dec, *relE_fx, Etot_fx, attack_flag, inp_12k8_fx, Q_new, S_map_fx, flag_spitch );
ivas_smc_mode_selection_fx( st, element_brate, smc_dec, *relE_fx, Etot_fx, attack_flag, inp_12k8_fx, *Q_new, S_map_fx, flag_spitch );
}
/*----------------------------------------------------------------*
......@@ -1765,10 +1812,13 @@ ivas_error pre_proc_front_ivas_fx(
*-----------------------------------------------------------------*/
shift = getScaleFactor16( &old_inp_12k8_fx[L_FRAME], L_INP_MEM );
Copy_Scale_sig( &old_inp_12k8_fx[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM, shift );
st->exp_old_inp_12k8 = sub( Q15, add( Q_new, shift ) );
st->exp_old_inp_12k8 = sub( Q15, add( *Q_new, shift ) );
move16();
Scale_sig( old_inp_12k8_fx, L_INP_12k8, negate( add( Q_new, 1 ) ) );
// Scale_sig( old_inp_12k8_fx, L_INP_12k8, negate( add( *Q_new, 1 ) ) );
*Q_new = sub( *Q_new, Q_to_be_looked_into ); // ivas_core_enc will assume inp signal (12k8 and 16k) in Q_new - 1
move16();
free( mem_decim_dummy_fx );
free( temp1F_icatdmResampBuf_fx );
......
......@@ -67,7 +67,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
BSTR_ENC_HANDLE hBstr;
Word16 i, nb_bits;
Indice temp_ind_list[MAX_NUM_IND_TEMP_LIST];
Word16 nb_bits_tot, input_frame;
Word16 nb_bits_tot, input_frame, q_input_buff[MCT_MAX_BLOCKS];
Word16 nchan_transport_real, nchan_transport_old_real;
ENCODER_CONFIG_HANDLE hEncoderConfig;
ivas_error error;
......@@ -80,6 +80,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
error = IVAS_ERR_OK;
move32();
set16_fx( q_input_buff, Q31, MCT_MAX_BLOCKS );
input_frame = idiv1616U( extract_l( L_shr( hEncoderConfig->input_Fs, 1 ) ), FRAMES_PER_SEC / 2 );
len_inp_memory = input_frame;
move16();
......@@ -302,6 +303,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
{
set32_fx( input_buff_fx[0], 0, len_inp_memory );
Copy32( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[0], len_inp_memory );
q_input_buff[0] = st_ivas->hSCE[0]->hCoreCoder[0]->q_inp32;
move16();
}
FOR( n = 0; n < CPE_CHANNELS; n++ )
......@@ -310,6 +313,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
IF( nCPE_old > 0 )
{
Copy32( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[n + 1], len_inp_memory );
q_input_buff[n + 1] = st_ivas->hCPE[0]->hCoreCoder[n]->q_inp32;
move16();
}
}
......@@ -330,6 +335,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
IF( GT_16( n_CoreCoder_existing, sce_id ) )
{
Copy32( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[sce_id], len_inp_memory );
q_input_buff[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]->q_inp32;
move16();
}
destroy_sce_enc( st_ivas->hSCE[sce_id], ( EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) && !st_ivas->hEncoderConfig->stereo_dmx_evs ) );
st_ivas->hSCE[sce_id] = NULL;
......@@ -343,6 +350,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
IF( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
{
Copy32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory );
q_input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n] = st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32;
move16();
}
}
destroy_cpe_enc( st_ivas->hCPE[cpe_id] );
......@@ -390,6 +399,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
IF( GT_16( n_CoreCoder_existing, sce_id ) && NE_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) )
{
Copy32( input_buff_fx[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, len_inp_memory );
st_ivas->hSCE[sce_id]->hCoreCoder[0]->q_inp32 = q_input_buff[sce_id];
move16();
}
test();
/* only reset indices if it is not the first index list, this already contains the IVAS format bits */
......@@ -465,6 +476,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
IF( GT_16( n_CoreCoder_existing, add( i_mult( cpe_id, CPE_CHANNELS ), n ) ) )
{
Copy32( input_buff_fx[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, len_inp_memory );
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = q_input_buff[n];
move16();
}
}
......@@ -548,6 +561,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
IF( st_ivas->nSCE )
{
Copy32( input_buff_fx[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, len_inp_memory );
st_ivas->hSCE[0]->hCoreCoder[0]->q_inp32 = q_input_buff[0];
move16();
}
IF( st_ivas->nCPE )
......@@ -555,6 +570,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx(
FOR( n = 0; n < CPE_CHANNELS; n++ )
{
Copy32( input_buff_fx[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, len_inp_memory );
st_ivas->hCPE[0]->hCoreCoder[n]->q_inp32 = q_input_buff[n + 1];
move16();
}
}
}
......
......@@ -67,16 +67,17 @@ ivas_error ivas_cpe_enc_fx(
Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */
Word16 q_data_fx, /* i : Q-factor of input signal for both channels */
const Word16 input_frame, /* i : input frame length per channel */
const Word16 nb_bits_metadata /* i : number of metadata bits */
)
const Word16 nb_bits_metadata, /* i : number of metadata bits */
Word16 Q_new_out[] )
{
CPE_ENC_HANDLE hCPE;
Encoder_State **sts;
Word16 n, n_CoreChannels;
Word32 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 Q16 */
Word16 old_inp_12k8_16fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 Q-1 */
Word16 old_inp_12k8_16fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 Q_new-1 */
Word32 old_inp_16k_fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz Q16 */
Word16 old_inp_16k_16fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz Q-1 */
Word16 old_inp_16k_16fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz Q_new-1 */
Word16 Q_new[CPE_CHANNELS] = { 0 };
Word16 fft_buff_fx[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */
Word16 fft_buff_fx_q[CPE_CHANNELS]; /* FFT buffer */
Word16 fft_buff_fx_final_q = MAX_16;
......@@ -123,6 +124,8 @@ ivas_error ivas_cpe_enc_fx(
Word16 last_bits_frame_nominal; /* last_bits_frame_nominal for M or PCh channel */
Word16 old_wsp_fx[CPE_CHANNELS][L_WSP];
Word16 e_old_wsp[CPE_CHANNELS], q_old_wsp;
move16(); // Q_new
move16(); // Q_new
error = IVAS_ERR_OK;
move32();
......@@ -803,7 +806,12 @@ ivas_error ivas_cpe_enc_fx(
&ener_fx[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n],
realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp_fx[n], &q_old_wsp, pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n],
fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, add( Q_buffer[n], QSCALE ), Etot_LR_fx, lf_E_fx, add( Q_buffer[n], QSCALE - 2 ), localVAD_HE_SAD,
band_energies_LR_fx, sub( add( Q_buffer[n], QSCALE ), band_ener_guardbits ), 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate );
band_energies_LR_fx, sub( add( Q_buffer[n], QSCALE ), band_ener_guardbits ), 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate, &Q_new[n]
#ifdef DEBUG_MODE_INFO
,
( st_ivas->nSCE + ( cpe_id * CPE_CHANNELS ) + n )
#endif
);
e_old_wsp[n] = sub( Q15, q_old_wsp );
move16();
if ( error != IVAS_ERR_OK )
......@@ -1059,7 +1067,7 @@ ivas_error ivas_cpe_enc_fx(
e_old_wsp[n] = 16;
move16();
}
IF( NE_32( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8_16fx, old_inp_16k_16fx, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ), IVAS_ERR_OK ) )
IF( NE_32( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8_16fx, old_inp_16k_16fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ), IVAS_ERR_OK ) )
{
return error;
}
......@@ -1112,6 +1120,12 @@ ivas_error ivas_cpe_enc_fx(
sts[n]->hTranDet->transientDetector.prev_bIsAttackPresent = sts[n]->hTranDet->transientDetector.bIsAttackPresent;
}
IF( Q_new_out )
{
Copy( Q_new, Q_new_out, CPE_CHANNELS );
}
#ifdef DEBUG_MODE_INFO
{
float tmpF = ivas_total_brate / 1000.0f;
......@@ -1391,6 +1405,20 @@ ivas_error create_cpe_enc_fx(
#ifdef DEBUGGING
hCPE->hStereoMdct->mdct_stereo_mode_cmdl = st_ivas->hEncoderConfig->mdct_stereo_mode_cmdl;
#ifdef DEBUG_FORCE_MDCT_STEREO_MODE
/*set all other members to defined states */
hCPE->hStereoMdct->fDualMono = 0;
hCPE->hStereoMdct->fMSstereo = 0;
if ( hCPE->hStereoMdct->mdct_stereo_mode_cmdl == SMDCT_FORCE_LR )
{
hCPE->hStereoMdct->fDualMono = 1;
}
else if ( hCPE->hStereoMdct->mdct_stereo_mode_cmdl == SMDCT_FORCE_MS )
{
hCPE->hStereoMdct->fMSstereo = 1;
}
#endif
#endif
initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1 );
......
......@@ -179,7 +179,7 @@ ivas_error ivas_enc_fx(
{
st_ivas->hCPE[0]->element_brate = ivas_total_brate;
move32();
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, 0 /* no metadata */ ) ), IVAS_ERR_OK ) )
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, 0 /* no metadata */, NULL ) ), IVAS_ERR_OK ) )
{
return error;
}
......@@ -285,7 +285,7 @@ ivas_error ivas_enc_fx(
}
ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */
{
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ), IVAS_ERR_OK ) )
{
return error;
}
......@@ -342,7 +342,7 @@ ivas_error ivas_enc_fx(
{
norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[i], input_frame ) );
}
norm_data_in = sub( norm_data_in, 6 ); /*guard bit is 3->to handle overflow in cldfbAnalysis*/
norm_data_in = sub( norm_data_in, 7 ); /*guard bit is 4->to handle overflow in cldfbAnalysis*/
FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ )
{
scale_sig32( data_fx[i], input_frame, norm_data_in );
......@@ -414,7 +414,7 @@ ivas_error ivas_enc_fx(
);
/* Encode MASA transport channels */
IF( ( ivas_cpe_enc_fx( st_ivas, 0, data_fx[n], data_fx[n + 1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
IF( ( ivas_cpe_enc_fx( st_ivas, 0, data_fx[n], data_fx[n + 1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ) != IVAS_ERR_OK )
{
return error;
}
......@@ -498,7 +498,7 @@ ivas_error ivas_enc_fx(
}
ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */
{
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ), IVAS_ERR_OK ) )
{
return error;
}
......@@ -583,7 +583,7 @@ ivas_error ivas_enc_fx(
IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */
{
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ), IVAS_ERR_OK ) )
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ), IVAS_ERR_OK ) )
{
return error;
}
......@@ -641,7 +641,7 @@ ivas_error ivas_enc_fx(
st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot;
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ), IVAS_ERR_OK ) )
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ), IVAS_ERR_OK ) )
{
return error;
}
......@@ -657,7 +657,7 @@ ivas_error ivas_enc_fx(
}
ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */
{
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ), IVAS_ERR_OK ) )
IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ), IVAS_ERR_OK ) )
{
return error;
}
......
......@@ -280,7 +280,7 @@ Word16 getNumChanAnalysis_fx(
void copy_encoder_config(
Encoder_Struct *st_ivas, /* i : IVAS encoder structure */
Encoder_State *st, /* o : encoder state structure */
const int16_t flag_all /* i : flag 1==update all, 0=partial update*/
const Word16 flag_all /* i : flag 1==update all, 0=partial update*/
)
{
if ( flag_all )
......@@ -453,12 +453,12 @@ ivas_error ivas_init_encoder(
Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
)
{
int16_t i, n;
int16_t nchan_inp_buff;
int16_t sce_id, cpe_id;
Word16 i, n;
Word16 nchan_inp_buff;
Word16 sce_id, cpe_id;
IVAS_FORMAT ivas_format;
int32_t input_Fs, ivas_total_brate;
int32_t element_brate_tmp[MAX_NUM_OBJECTS];
Word32 input_Fs, ivas_total_brate;
Word32 element_brate_tmp[MAX_NUM_OBJECTS];
ENCODER_CONFIG_HANDLE hEncoderConfig;
ivas_error error;
......@@ -640,11 +640,7 @@ ivas_error ivas_init_encoder(
}
else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT )
{
#ifndef IVAS_FLOAT_FIXED
if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
#else
IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
#endif
{
return error;
}
......@@ -712,8 +708,8 @@ ivas_error ivas_init_encoder(
}
else if ( ivas_format == MASA_ISM_FORMAT )
{
int32_t ism_total_brate;
int16_t k;
Word32 ism_total_brate;
Word16 k;
st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism );
move32();
......@@ -740,11 +736,7 @@ ivas_error ivas_init_encoder(
}
}
#ifndef IVAS_FLOAT_FIXED
if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
#else
IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
#endif
{
return error;
}
......@@ -790,11 +782,7 @@ ivas_error ivas_init_encoder(
}
/* allocate and initialize SBA handles */
#ifndef IVAS_FLOAT_FIXED
if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
#else
IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
#endif
{
return error;
}
......@@ -949,15 +937,11 @@ ivas_error ivas_init_encoder(
}
else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
{
int32_t brate_sce, brate_cpe;
Word32 brate_sce, brate_cpe;
ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate );
#ifndef IVAS_FLOAT_FIXED
if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
#else
IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
#endif
{
return error;
}
......@@ -1953,7 +1937,7 @@ void ivas_destroy_enc(
Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
)
{
int16_t i, n, nchan_inp;
Word16 i, n, nchan_inp;
nchan_inp = st_ivas->hEncoderConfig->nchan_inp;
/* SCE handles */
......
......@@ -509,7 +509,7 @@ void ivas_ism_coh_estim_dtx_enc_fx(
coh_e = 0;
}
/* ensure value of coherence is between [0,1] */
hISMDTX->coh_fx[sce_id] = check_bounds_s( hISMDTX->coh_fx[sce_id], 0, shl_sat( 1, 15 - coh_e ) );
hISMDTX->coh_fx[sce_id] = check_bounds_s_fx( hISMDTX->coh_fx[sce_id], 0, shl_sat( 1, 15 - coh_e ) );
hISMDTX->coh_fx[sce_id] = shl_sat( hISMDTX->coh_fx[sce_id], coh_e );
move16();
move16();
......
......@@ -62,8 +62,9 @@ ivas_error ivas_ism_enc_fx(
SCE_ENC_HANDLE hSCE;
Encoder_State *st;
Word16 sce_id;
Word16 old_inp_12k8_fx[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 Q-1 */
Word16 old_inp_16k_fx[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 12k8 Q-1 */
Word16 old_inp_12k8_fx[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 Q_new-1 */
Word16 old_inp_16k_fx[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 12k8 Q_new-1 */
Word16 Q_new[MAX_NUM_OBJECTS][1] = { 0 };
Word16 vad_flag[MAX_NUM_OBJECTS]; /* VAD flag */
Word32 ener_fx[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin Q6 */
Word16 relE_fx[MAX_NUM_OBJECTS][1];
......@@ -103,6 +104,10 @@ ivas_error ivas_ism_enc_fx(
Word16 i, nchan_transport_ism;
Word16 q_st_inp_16;
ivas_error error;
move16(); // Q_new
move16(); // Q_new
move16(); // Q_new
move16(); // Q_new
push_wmops( "ivas_ism_enc" );
......@@ -236,7 +241,12 @@ ivas_error ivas_ism_enc_fx(
error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_16k_fx[sce_id][0],
&ener_fx[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP_fx[sce_id][0], &epsP_fx_q[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0],
realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp_fx[sce_id][0], &q_old_wsp, pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0],
fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, 31, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate );
fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, 31, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0]
#ifdef DEBUG_MODE_INFO
,
st->id_element
#endif
);
e_old_wsp[sce_id][0] = sub( Q15, q_old_wsp );
move16();
IF( NE_32( error, IVAS_ERR_OK ) )
......@@ -430,7 +440,7 @@ ivas_error ivas_ism_enc_fx(
Scale_sig( old_wsp_fx[sce_id][0], L_WSP, sub( e_old_wsp[sce_id][0], Q16 ) );
e_old_wsp[sce_id][0] = 16;
move16();
IF( NE_32( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx[sce_id], old_inp_16k_fx[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp_fx[sce_id], e_old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ), IVAS_ERR_OK ) )
IF( NE_32( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx[sce_id], old_inp_16k_fx[sce_id], Q_new[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp_fx[sce_id], e_old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ), IVAS_ERR_OK ) )
{
return error;
}
......