Skip to content
...@@ -60,6 +60,35 @@ static int16_t ivas_agc_writeBits( FILE *stream, const int16_t n_channels, ivas_ ...@@ -60,6 +60,35 @@ static int16_t ivas_agc_writeBits( FILE *stream, const int16_t n_channels, ivas_
#endif #endif
/*-----------------------------------------------------------------------------------------*
* Function ivas_agc_enc_get_flag()
*
* This function determines if AGC is enabled or disabled.
*-----------------------------------------------------------------------------------------*/
/*! r: AGC enable flag */
int16_t ivas_agc_enc_get_flag(
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
int16_t agc_configuration, /* i : AGC configuration from command-line */
#endif
int16_t nchan_transport /* i : number of transport channels */
)
{
int16_t agc_flag;
/* AGC is enabled only if there is one transport channel. */
agc_flag = (int16_t) ( nchan_transport == 1 );
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
/* If agc_configuration is not undefined, then this value decides on the state of * enablement,
otherwise AGC is enabled only if there is one transport channel. */
agc_flag = ( agc_configuration != SBA_AGC_DEFAULT ) ? agc_configuration : agc_flag;
#endif
return agc_flag;
}
/*-----------------------------------------------------------------------------------------* /*-----------------------------------------------------------------------------------------*
* Function ivas_agc_enc_init() * Function ivas_agc_enc_init()
* *
...@@ -108,6 +137,7 @@ static void ivas_agc_enc_init( ...@@ -108,6 +137,7 @@ static void ivas_agc_enc_init(
return; return;
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* ivas_spar_agc_enc_open() * ivas_spar_agc_enc_open()
* *
...@@ -121,7 +151,11 @@ ivas_error ivas_spar_agc_enc_open( ...@@ -121,7 +151,11 @@ ivas_error ivas_spar_agc_enc_open(
) )
{ {
ivas_agc_enc_state_t *hAgc; ivas_agc_enc_state_t *hAgc;
#ifdef FIX_AGC_WINFUNC_MEMORY
int16_t input_frame, delay;
#else
int16_t input_frame; int16_t input_frame;
#endif
if ( ( hAgc = (ivas_agc_enc_state_t *) count_malloc( sizeof( ivas_agc_enc_state_t ) ) ) == NULL ) if ( ( hAgc = (ivas_agc_enc_state_t *) count_malloc( sizeof( ivas_agc_enc_state_t ) ) ) == NULL )
{ {
...@@ -129,8 +163,15 @@ ivas_error ivas_spar_agc_enc_open( ...@@ -129,8 +163,15 @@ ivas_error ivas_spar_agc_enc_open(
} }
input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC );
#ifdef FIX_AGC_WINFUNC_MEMORY
delay = NS2SA( input_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) );
#endif
#ifdef FIX_AGC_WINFUNC_MEMORY
if ( ( hAgc->agc_com.winFunc = (float *) count_malloc( sizeof( float ) * ( input_frame - delay ) ) ) == NULL )
#else
if ( ( hAgc->agc_com.winFunc = (float *) count_malloc( sizeof( float ) * input_frame ) ) == NULL ) if ( ( hAgc->agc_com.winFunc = (float *) count_malloc( sizeof( float ) * input_frame ) ) == NULL )
#endif
{ {
return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" );
} }
...@@ -145,13 +186,18 @@ ivas_error ivas_spar_agc_enc_open( ...@@ -145,13 +186,18 @@ ivas_error ivas_spar_agc_enc_open(
return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" );
} }
#ifdef FIX_AGC_WINFUNC_MEMORY
ivas_agc_enc_init( hAgc, input_frame, nchan_inp, delay );
#else
ivas_agc_enc_init( hAgc, input_frame, nchan_inp, NS2SA( input_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ) ); ivas_agc_enc_init( hAgc, input_frame, nchan_inp, NS2SA( input_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ) );
#endif
*hAgcEnc = hAgc; *hAgcEnc = hAgc;
return IVAS_ERR_OK; return IVAS_ERR_OK;
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* ivas_spar_agc_enc_close() * ivas_spar_agc_enc_close()
* *
...@@ -184,6 +230,7 @@ void ivas_spar_agc_enc_close( ...@@ -184,6 +230,7 @@ void ivas_spar_agc_enc_close(
return; return;
} }
/*-----------------------------------------------------------------------------------------* /*-----------------------------------------------------------------------------------------*
* Function ivas_agc_enc_process() * Function ivas_agc_enc_process()
* *
...@@ -215,7 +262,7 @@ void ivas_agc_enc_process( ...@@ -215,7 +262,7 @@ void ivas_agc_enc_process(
{ {
float sampleAbsVal; float sampleAbsVal;
int16_t isClipped = FALSE; int16_t isClipped = FALSE;
int16_t clippedIdx = offset - 1; int16_t clippedIdx = 0;
int16_t MaxAbsValIdx = 0; int16_t MaxAbsValIdx = 0;
float MaxAbsVal = pState->gain_state[i].MaxAbsVal_del; float MaxAbsVal = pState->gain_state[i].MaxAbsVal_del;
float predMaxAbsVal = fabsf( ppPcm_in[i][offset] ); float predMaxAbsVal = fabsf( ppPcm_in[i][offset] );
...@@ -242,25 +289,14 @@ void ivas_agc_enc_process( ...@@ -242,25 +289,14 @@ void ivas_agc_enc_process(
if ( !isClipped ) if ( !isClipped )
{ {
#ifdef SPAR_SCALING_HARMONIZATION
if ( ( ppPcm_out[i][j] > ( 1.f - pState->minDelta ) * PCM16_TO_FLT_FAC ) || ( ppPcm_out[i][j] < MIN16B_FLT ) ) if ( ( ppPcm_out[i][j] > ( 1.f - pState->minDelta ) * PCM16_TO_FLT_FAC ) || ( ppPcm_out[i][j] < MIN16B_FLT ) )
#else
if ( ( ppPcm_out[i][j] > ( 1.f - pState->minDelta ) ) || ( ppPcm_out[i][j] < -1.f ) )
#endif
{
if ( j < offset )
{ {
clippedIdx = j; clippedIdx = j;
}
isClipped = TRUE; isClipped = TRUE;
} }
} }
} }
if ( MaxAbsValIdx >= offset )
{
MaxAbsValIdx = offset - 1;
}
pState->gain_state[i].MaxAbsVal_del = predMaxAbsVal; pState->gain_state[i].MaxAbsVal_del = predMaxAbsVal;
isGainAdjusted = FALSE; isGainAdjusted = FALSE;
...@@ -282,11 +318,7 @@ void ivas_agc_enc_process( ...@@ -282,11 +318,7 @@ void ivas_agc_enc_process(
maxGain = max( smoothedMaxAbsVal, MaxAbsVal ) * pState->gain_state[i].lastGain * 2.f; maxGain = max( smoothedMaxAbsVal, MaxAbsVal ) * pState->gain_state[i].lastGain * 2.f;
#ifdef SPAR_SCALING_HARMONIZATION
if ( maxGain < ( 1.f - pState->minDelta ) * PCM16_TO_FLT_FAC ) if ( maxGain < ( 1.f - pState->minDelta ) * PCM16_TO_FLT_FAC )
#else
if ( maxGain < 1.f - pState->minDelta )
#endif
{ {
pState->gain_state[i].gainExpVal = -1; pState->gain_state[i].gainExpVal = -1;
} }
...@@ -311,21 +343,11 @@ void ivas_agc_enc_process( ...@@ -311,21 +343,11 @@ void ivas_agc_enc_process(
extendedExpVal = FALSE; extendedExpVal = FALSE;
if ( isClipped ) if ( isClipped )
{
actualMaxAbsVal = pState->gain_state[i].lastMaxAbs * pState->gain_state[i].lastGain;
if ( MaxAbsValIdx == 0 )
{
pState->gain_data[i].gainException = TRUE;
}
else
{ {
int16_t isCompensated = FALSE; int16_t isCompensated = FALSE;
actualMaxAbsVal = pState->gain_state[i].lastMaxAbs * pState->gain_state[i].lastGain;
pState->gain_data[i].gainException = FALSE; pState->gain_data[i].gainException = FALSE;
#ifdef SPAR_SCALING_HARMONIZATION pState->gain_state[i].gainExpVal = (int16_t) ceilf( -logf( actualMaxAbsVal * MDFT_NORM_SCALING ) / logf( pState->agc_com.winFunc[min( offset - 1, MaxAbsValIdx )] ) );
pState->gain_state[i].gainExpVal = (int16_t) ceilf( -logf( actualMaxAbsVal * MDFT_NORM_SCALING ) / logf( pState->agc_com.winFunc[MaxAbsValIdx] ) );
#else
pState->gain_state[i].gainExpVal = (int16_t) ceilf( -logf( actualMaxAbsVal ) / logf( pState->agc_com.winFunc[MaxAbsValIdx] ) );
#endif
while ( !isCompensated ) while ( !isCompensated )
{ {
...@@ -333,14 +355,18 @@ void ivas_agc_enc_process( ...@@ -333,14 +355,18 @@ void ivas_agc_enc_process(
isCompensated = TRUE; isCompensated = TRUE;
for ( idx = clippedIdx; idx <= MaxAbsValIdx; idx++ ) for ( idx = clippedIdx; idx <= MaxAbsValIdx; idx++ )
{
if ( idx >= offset )
{
idx = MaxAbsValIdx;
tmpSignal = ppPcm_out[i][idx] * powf( pState->agc_com.winFunc[offset - 1], (float) pState->gain_state[i].gainExpVal );
}
else
{ {
tmpSignal = ppPcm_out[i][idx] * powf( pState->agc_com.winFunc[idx], (float) pState->gain_state[i].gainExpVal ); tmpSignal = ppPcm_out[i][idx] * powf( pState->agc_com.winFunc[idx], (float) pState->gain_state[i].gainExpVal );
}
#ifdef SPAR_SCALING_HARMONIZATION
if ( ( tmpSignal > ( 1.f - pState->minDelta ) * PCM16_TO_FLT_FAC ) || ( tmpSignal < MIN16B_FLT ) ) if ( ( tmpSignal > ( 1.f - pState->minDelta ) * PCM16_TO_FLT_FAC ) || ( tmpSignal < MIN16B_FLT ) )
#else
if ( ( tmpSignal > ( 1.f - pState->minDelta ) ) || ( tmpSignal < -1.f ) )
#endif
{ {
isCompensated = FALSE; isCompensated = FALSE;
break; break;
...@@ -352,6 +378,12 @@ void ivas_agc_enc_process( ...@@ -352,6 +378,12 @@ void ivas_agc_enc_process(
pState->gain_state[i].gainExpVal++; pState->gain_state[i].gainExpVal++;
} }
if ( pState->gain_state[i].gainExpVal > currMaxAttExp )
{
pState->gain_state[i].gainExpVal = min( pState->gain_state[i].gainExpVal, currMaxAttExp );
break;
}
if ( pState->gain_state[i].gainExpVal > currMaxAttExp ) if ( pState->gain_state[i].gainExpVal > currMaxAttExp )
{ {
pState->gain_data[i].gainException = TRUE; pState->gain_data[i].gainException = TRUE;
...@@ -368,7 +400,6 @@ void ivas_agc_enc_process( ...@@ -368,7 +400,6 @@ void ivas_agc_enc_process(
} }
} }
} }
}
if ( !pState->gain_data[i].gainException ) if ( !pState->gain_data[i].gainException )
{ {
...@@ -390,14 +421,10 @@ void ivas_agc_enc_process( ...@@ -390,14 +421,10 @@ void ivas_agc_enc_process(
} }
else else
{ {
#ifdef SPAR_SCALING_HARMONIZATION
pState->gain_state[i].gainExpVal = (int16_t) ( -floorf( -logf( ( actualMaxAbsVal + pState->minDelta ) * MDFT_NORM_SCALING ) * INV_LOG_2 ) ); pState->gain_state[i].gainExpVal = (int16_t) ( -floorf( -logf( ( actualMaxAbsVal + pState->minDelta ) * MDFT_NORM_SCALING ) * INV_LOG_2 ) );
#else
pState->gain_state[i].gainExpVal = (int16_t) ( -floorf( -logf( actualMaxAbsVal + pState->minDelta ) * INV_LOG_2 ) );
#endif
pState->gain_state[i].gainExpVal = min( gainExpValMaxRange, pState->gain_state[i].gainExpVal ); pState->gain_state[i].gainExpVal = min( gainExpValMaxRange, pState->gain_state[i].gainExpVal );
gain = powf( 2.0f, -1.0f * pState->gain_state[i].gainExpVal ); gain = powf( pState->agc_com.winFunc[offset - 1], pState->gain_state[i].gainExpVal );
for ( idx = 0; idx < input_frame; idx++ ) for ( idx = 0; idx < input_frame; idx++ )
{ {
ppPcm_out[i][idx] *= gain; ppPcm_out[i][idx] *= gain;
...@@ -486,6 +513,7 @@ void ivas_agc_enc_process( ...@@ -486,6 +513,7 @@ void ivas_agc_enc_process(
{ {
push_next_indice( hMetaData, (uint16_t) pState->gain_data[i].absGainExpCurr, (int16_t) pState->agc_com.betaE ); push_next_indice( hMetaData, (uint16_t) pState->gain_data[i].absGainExpCurr, (int16_t) pState->agc_com.betaE );
push_next_indice( hMetaData, (uint16_t) pState->gain_data[i].gainException, 1 ); push_next_indice( hMetaData, (uint16_t) pState->gain_data[i].gainException, 1 );
assert( pState->gain_data[i].gainException == FALSE );
} }
} }
} }
......
...@@ -79,11 +79,12 @@ ivas_error ivas_core_enc( ...@@ -79,11 +79,12 @@ ivas_error ivas_core_enc(
float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */
float fft_buff[CPE_CHANNELS][2 * L_FFT], /* i : FFT buffer */ float fft_buff[CPE_CHANNELS][2 * L_FFT], /* i : FFT buffer */
const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */
const int16_t ivas_format, /* i : IVAS format */
const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */
) )
{ {
int16_t n, input_frame; int16_t n, input_frame;
int16_t cpe_id, is_MCT; int16_t cpe_id, MCT_flag;
Encoder_State **sts, *st; Encoder_State **sts, *st;
STEREO_ICBWE_ENC_HANDLE hStereoICBWE; STEREO_ICBWE_ENC_HANDLE hStereoICBWE;
STEREO_TD_ENC_DATA_HANDLE hStereoTD; STEREO_TD_ENC_DATA_HANDLE hStereoTD;
...@@ -101,7 +102,7 @@ ivas_error ivas_core_enc( ...@@ -101,7 +102,7 @@ ivas_error ivas_core_enc(
int16_t unbits[CPE_CHANNELS]; int16_t unbits[CPE_CHANNELS];
float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M];
int16_t last_element_mode, tdm_Pitch_reuse_flag; int16_t last_element_mode, tdm_Pitch_reuse_flag;
int32_t element_brate, input_Fs; int32_t element_brate, last_element_brate, input_Fs;
ivas_error error; ivas_error error;
wmops_sub_start( "ivas_core_enc" ); wmops_sub_start( "ivas_core_enc" );
...@@ -115,25 +116,27 @@ ivas_error ivas_core_enc( ...@@ -115,25 +116,27 @@ ivas_error ivas_core_enc(
if ( hSCE != NULL ) if ( hSCE != NULL )
{ {
cpe_id = -1; cpe_id = -1;
is_MCT = 0; MCT_flag = 0;
sts = hSCE->hCoreCoder; sts = hSCE->hCoreCoder;
hStereoTD = NULL; hStereoTD = NULL;
hStereoICBWE = NULL; hStereoICBWE = NULL;
element_brate = hSCE->element_brate; element_brate = hSCE->element_brate;
last_element_brate = hSCE->last_element_brate;
last_element_mode = IVAS_SCE; last_element_mode = IVAS_SCE;
tdm_Pitch_reuse_flag = -1; tdm_Pitch_reuse_flag = -1;
} }
else else
{ {
cpe_id = hCPE->cpe_id; cpe_id = hCPE->cpe_id;
is_MCT = 0; MCT_flag = 0;
if ( hMCT != NULL ) if ( hMCT != NULL )
{ {
is_MCT = 1; MCT_flag = 1;
} }
sts = hCPE->hCoreCoder; sts = hCPE->hCoreCoder;
hStereoICBWE = hCPE->hStereoICBWE; hStereoICBWE = hCPE->hStereoICBWE;
element_brate = hCPE->element_brate; element_brate = hCPE->element_brate;
last_element_brate = hCPE->last_element_brate;
last_element_mode = hCPE->last_element_mode; last_element_mode = hCPE->last_element_mode;
if ( hCPE->hStereoTD != NULL ) if ( hCPE->hStereoTD != NULL )
...@@ -174,7 +177,7 @@ ivas_error ivas_core_enc( ...@@ -174,7 +177,7 @@ ivas_error ivas_core_enc(
* Pre-processing, incl. Decision matrix * Pre-processing, incl. Decision matrix
*---------------------------------------------------------------------*/ *---------------------------------------------------------------------*/
if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], is_MCT, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], MCT_flag, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK )
{ {
return error; return error;
} }
...@@ -197,9 +200,9 @@ ivas_error ivas_core_enc( ...@@ -197,9 +200,9 @@ ivas_error ivas_core_enc(
* Write signaling info into the bitstream * Write signaling info into the bitstream
*---------------------------------------------------------------------*/ *---------------------------------------------------------------------*/
if ( !is_MCT || ( is_MCT && cpe_id == 0 ) ) if ( !MCT_flag || ( MCT_flag && cpe_id == 0 ) )
{ {
ivas_signaling_enc( st, is_MCT, element_brate, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag ); ivas_signaling_enc( st, MCT_flag, element_brate, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag );
} }
/*---------------------------------------------------------------------* /*---------------------------------------------------------------------*
...@@ -254,7 +257,7 @@ ivas_error ivas_core_enc( ...@@ -254,7 +257,7 @@ ivas_error ivas_core_enc(
{ {
if ( sts[0]->core_brate > SID_2k40 && sts[1]->core_brate > SID_2k40 ) if ( sts[0]->core_brate > SID_2k40 && sts[1]->core_brate > SID_2k40 )
{ {
if ( is_MCT ) if ( MCT_flag )
{ {
ivas_mdct_core_whitening_enc( hCPE, old_inp_16k, old_wsp, pitch_buf, hMCT->p_mdst_spectrum_long[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long[cpe_id], ivas_mdct_core_whitening_enc( hCPE, old_inp_16k, old_wsp, pitch_buf, hMCT->p_mdst_spectrum_long[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long[cpe_id],
hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, &hMCT->LFE_off, 1, hMCT->nchan_out_woLFE + hMCT->num_lfe ); hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, &hMCT->LFE_off, 1, hMCT->nchan_out_woLFE + hMCT->num_lfe );
......
...@@ -55,6 +55,7 @@ ivas_error pre_proc_ivas( ...@@ -55,6 +55,7 @@ ivas_error pre_proc_ivas(
Encoder_State *st, /* i/o: encoder state structure */ Encoder_State *st, /* i/o: encoder state structure */
const int16_t last_element_mode, /* i : last element mode */ const int16_t last_element_mode, /* i : last element mode */
const int32_t element_brate, /* i : element bitrate */ const int32_t element_brate, /* i : element bitrate */
const int32_t last_element_brate, /* i : last element bitrate */
const int16_t input_frame, /* i : frame length */ const int16_t input_frame, /* i : frame length */
float old_inp_12k8[], /* i/o: buffer of old input signal */ float old_inp_12k8[], /* i/o: buffer of old input signal */
float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */
...@@ -73,7 +74,7 @@ ivas_error pre_proc_ivas( ...@@ -73,7 +74,7 @@ ivas_error pre_proc_ivas(
const int16_t vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */ const int16_t vad_flag_dtx, /* i : HE-SAD flag with additional DTX HO */
const float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ const float enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */
const float fft_buff[2 * L_FFT], /* i : FFT buffer */ const float fft_buff[2 * L_FFT], /* i : FFT buffer */
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 vad_hover_flag, /* i : VAD hangover flag */ const int16_t vad_hover_flag, /* i : VAD hangover flag */
const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */
) )
...@@ -234,7 +235,7 @@ ivas_error pre_proc_ivas( ...@@ -234,7 +235,7 @@ ivas_error pre_proc_ivas(
/* Configure TCX with the same bitrate as given when (re-)initializing TCX */ /* Configure TCX with the same bitrate as given when (re-)initializing TCX */
total_brate_tmp = st->total_brate; total_brate_tmp = st->total_brate;
st->total_brate = st->bits_frame_nominal * FRAMES_PER_SEC; st->total_brate = st->bits_frame_nominal * FRAMES_PER_SEC;
SetModeIndex( st, st->last_bits_frame_nominal * FRAMES_PER_SEC, last_element_mode, is_mct ); SetModeIndex( st, st->last_bits_frame_nominal * FRAMES_PER_SEC, last_element_mode, MCT_flag );
st->sr_core = getCoreSamplerateMode2( element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode ); st->sr_core = getCoreSamplerateMode2( element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode );
st->total_brate = total_brate_tmp; st->total_brate = total_brate_tmp;
...@@ -275,6 +276,11 @@ ivas_error pre_proc_ivas( ...@@ -275,6 +276,11 @@ ivas_error pre_proc_ivas(
{ {
st->hTcxEnc->tfm_mem = 0.75f; st->hTcxEnc->tfm_mem = 0.75f;
} }
else if ( element_brate != last_element_brate )
{
SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag );
}
/*-----------------------------------------------------------------* /*-----------------------------------------------------------------*
* Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps)
......
...@@ -553,7 +553,7 @@ ivas_error pre_proc_front_ivas( ...@@ -553,7 +553,7 @@ ivas_error pre_proc_front_ivas(
* Adjust FD-CNG Noise Estimator * Adjust FD-CNG Noise Estimator
*----------------------------------------------------------------*/ *----------------------------------------------------------------*/
if ( st->hFdCngEnc != NULL && ( last_element_brate != element_brate || st->last_bwidth != st->bwidth ) ) if ( st->hFdCngEnc != NULL && ( st->ini_frame == 0 || last_element_brate != element_brate || st->last_bwidth != st->bwidth ) )
{ {
configureFdCngEnc( st->hFdCngEnc, max( st->input_bwidth, WB ), st->bits_frame_nominal * FRAMES_PER_SEC ); configureFdCngEnc( st->hFdCngEnc, max( st->input_bwidth, WB ), st->bits_frame_nominal * FRAMES_PER_SEC );
if ( hCPE != NULL ) if ( hCPE != NULL )
......
/******************************************************************************************************
(C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository. All Rights Reserved.
This software is protected by copyright law and by international treaties.
The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
contributors to this repository retain full ownership rights in their respective contributions in
the software. This notice grants no license of any kind, including but not limited to patent
license, nor is any license granted by implication, estoppel or otherwise.
Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
contributions.
This software is provided "AS IS", without any express or implied warranties. The software is in the
development stage. It is intended exclusively for experts who have experience with such software and
solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
and fitness for a particular purpose are hereby disclaimed and excluded.
Any dispute, controversy or claim arising under or in relation to providing this software shall be
submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
the United Nations Convention on Contracts on the International Sales of Goods.
*******************************************************************************************************/
#include <assert.h>
#include <stdint.h>
#include "options.h"
#include "ivas_cnst.h"
#include "prot.h"
#include "ivas_prot.h"
#include "ivas_stat_enc.h"
#ifdef DEBUGGING
#include "debug.h"
#endif
#include "wmops.h"
/*-------------------------------------------------------------------*
* ivas_corecoder_enc_reconfig()
*
* Allocate, initalize, and configure SCE/CPE/MCT handles in case of bitrate switching
*-------------------------------------------------------------------*/
ivas_error ivas_corecoder_enc_reconfig(
Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
const int16_t nSCE_old, /* i : number of SCEs in previous frame */
const int16_t nCPE_old, /* i : number of CPEs in previous frame */
const int16_t nchan_transport_old /* i : number of TCs in previous frame */
)
{
int16_t n, sce_id, cpe_id;
int16_t len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing;
float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )];
BSTR_ENC_HANDLE hBstr, hMetaData;
Indice *ind_list, *ind_list_metadata;
int16_t nb_bits_tot, next_ind, last_ind;
int32_t ivas_total_brate;
ENCODER_CONFIG_HANDLE hEncoderConfig;
ivas_error error;
/*-----------------------------------------------------------------*
* Initialization
*-----------------------------------------------------------------*/
hEncoderConfig = st_ivas->hEncoderConfig;
ivas_total_brate = hEncoderConfig->ivas_total_brate;
error = IVAS_ERR_OK;
len_inp_memory = (int16_t) ( hEncoderConfig->input_Fs / FRAMES_PER_SEC );
if ( hEncoderConfig->ivas_format == SBA_FORMAT )
{
len_inp_memory += NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS );
}
/*-----------------------------------------------------------------*
* Switching between SCE(s)/CPE(s)/MCT
*-----------------------------------------------------------------*/
if ( st_ivas->nchan_transport == nchan_transport_old )
{
for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
{
copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
}
for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
{
st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;
/* prepare bitstream buffers */
for ( n = 0; n < CPE_CHANNELS; n++ )
{
copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
}
}
if ( st_ivas->nCPE > 1 )
{
if ( ( error = mct_enc_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK )
{
return error;
}
}
}
else
{
ind_list = NULL;
hBstr = NULL;
hMetaData = NULL;
/* get the index list pointers */
if ( nSCE_old )
{
hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr;
hMetaData = st_ivas->hSCE[0]->hMetaData;
}
else if ( nCPE_old )
{
hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr;
hMetaData = st_ivas->hCPE[nCPE_old - 1]->hMetaData;
}
#ifdef DEBUGGING
else
{
assert( 0 && "At least one SCE or one CPE should have existed before!\n" );
}
#endif
/* save bitstream information */
ind_list = hBstr->ind_list;
nb_bits_tot = hBstr->nb_bits_tot;
next_ind = hBstr->next_ind;
last_ind = hBstr->last_ind;
ind_list_metadata = hMetaData->ind_list;
n_CoreCoder_existing = min( st_ivas->nchan_transport, nchan_transport_old );
/* destroy superfluous core-coder elements */
for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
{
/* save input audio buffers */
if ( n_CoreCoder_existing > sce_id )
{
mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory );
}
destroy_sce_enc( st_ivas->hSCE[sce_id] );
st_ivas->hSCE[sce_id] = NULL;
}
for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
{
/* save input audio buffers */
for ( n = 0; n < CPE_CHANNELS; n++ )
{
if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
{
mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory );
}
}
destroy_cpe_enc( st_ivas->hCPE[cpe_id] );
st_ivas->hCPE[cpe_id] = NULL;
}
if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
{
ivas_mct_enc_close( st_ivas->hMCT );
st_ivas->hMCT = NULL;
}
/* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */
if ( st_ivas->nCPE > 1 && nCPE_old == 1 )
{
count_free( st_ivas->hCPE[0]->hStereoMdct );
st_ivas->hCPE[0]->hStereoMdct = NULL;
}
/* create missing core coder elements and set element bitrates for alrady existing ones */
if ( st_ivas->nSCE > 0 )
{
nSCE_existing = min( nSCE_old, st_ivas->nSCE );
for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
{
copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
}
for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ )
{
if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK )
{
return error;
}
/* propagate input audio buffers */
if ( n_CoreCoder_existing > sce_id )
{
mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory );
}
/* prepare bitstream buffers */
st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES;
/* only reset indices if it is not the first index list, this already contains the IVAS format bits */
if ( sce_id > 0 )
{
reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES );
}
else
{
st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->last_ind = last_ind;
st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot;
st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->next_ind = next_ind;
}
st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata + sce_id * MAX_BITS_METADATA;
reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA );
}
}
if ( st_ivas->nCPE > 0 )
{
nCPE_existing = min( nCPE_old, st_ivas->nCPE );
for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
{
st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;
/* prepare bitstream buffers */
for ( n = 0; n < CPE_CHANNELS; n++ )
{
copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
}
}
for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ )
{
if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK )
{
return error;
}
/* propagate input audio buffers */
for ( n = 0; n < CPE_CHANNELS; n++ )
{
if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
{
mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, len_inp_memory );
}
}
/* prepare bitstream buffers */
for ( n = 0; n < CPE_CHANNELS; n++ )
{
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n ) * MAX_NUM_INDICES;
if ( cpe_id * CPE_CHANNELS + n > 0 )
{
reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES );
}
else
{
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->last_ind = last_ind;
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = nb_bits_tot;
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind;
}
if ( hEncoderConfig->Opt_DTX_ON )
{
st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1;
}
}
}
}
if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
{
if ( nCPE_old == 1 )
{
/* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */
for ( n = 0; n < CPE_CHANNELS; n++ )
{
st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode,
st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode );
if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf )
{
IGFEncSetMode( st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc,
st_ivas->hCPE[0]->element_brate,
st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
}
}
}
if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
{
return error;
}
}
else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
{
if ( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK )
{
return error;
}
}
/* metadata handling for CPEs */
if ( st_ivas->nCPE > 0 )
{
if ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL )
{
if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData = (BSTR_ENC_HANDLE) count_malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) );
}
}
st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->ind_list = ind_list_metadata;
reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, MAX_BITS_METADATA );
for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ )
{
if ( st_ivas->hCPE[cpe_id]->hMetaData != NULL )
{
count_free( st_ivas->hCPE[cpe_id]->hMetaData );
st_ivas->hCPE[cpe_id]->hMetaData = NULL;
}
}
}
/* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */
if ( st_ivas->nCPE == 1 && nCPE_old > 1 )
{
if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL )
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
}
/* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handle */
for ( n = 0; n < CPE_CHANNELS; n++ )
{
st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode,
st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode );
if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf )
{
IGFEncSetMode( st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc,
st_ivas->hCPE[0]->element_brate,
st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
}
/* reset mct_chan_mode */
st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
}
initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 );
st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) );
}
}
return error;
}
...@@ -115,7 +115,6 @@ ivas_error ivas_cpe_enc( ...@@ -115,7 +115,6 @@ ivas_error ivas_cpe_enc(
input_Fs = hEncoderConfig->input_Fs; input_Fs = hEncoderConfig->input_Fs;
ivas_total_brate = hEncoderConfig->ivas_total_brate; ivas_total_brate = hEncoderConfig->ivas_total_brate;
/*------------------------------------------------------------------* /*------------------------------------------------------------------*
* Initialization - general * Initialization - general
*-----------------------------------------------------------------*/ *-----------------------------------------------------------------*/
...@@ -343,20 +342,11 @@ ivas_error ivas_cpe_enc( ...@@ -343,20 +342,11 @@ ivas_error ivas_cpe_enc(
stereo_dft_enc_analyze( sts, CPE_CHANNELS, input_frame, hCPE->hStereoDft, NULL, hCPE->hStereoDft->DFT, hCPE->input_mem ); stereo_dft_enc_analyze( sts, CPE_CHANNELS, input_frame, hCPE->hStereoDft, NULL, hCPE->hStereoDft->DFT, hCPE->input_mem );
sts[0]->total_brate = ( sts[0]->bits_frame_nominal + 10 ) * FRAMES_PER_SEC; /* add small overhead; st[0]->total_brate used in coder_type_modif() */ sts[0]->total_brate = ( sts[0]->bits_frame_nominal + 10 ) * FRAMES_PER_SEC; /* add small overhead; st[0]->total_brate used in coder_type_modif() */
if ( ( sts[0]->last_bwidth < max_bwidth ) || ( sts[0]->last_core_brate <= SID_2k40 ) ) /* IVAS_fmToDo: TBV - BWD output is not known here yet !!! */
{
/* reconfigure in case of BW switching or if last frame was a SID/NO_DATA with coarse partitioning */
hCPE->hStereoDft->nbands = stereo_dft_band_config( hCPE->hStereoDft->band_limits, hCPE->hStereoDft->hConfig->band_res, hCPE->hStereoDft->NFFT, ENC );
}
/* Update DFT Stereo memories */
stereo_dft_enc_update( hCPE->hStereoDft, sts[0]->max_bwidth
#ifdef DEBUG_MODE_DFT #ifdef DEBUG_MODE_DFT
, hCPE->hStereoDft->res_cod_bits = (int16_t) ( ( hCPE->element_brate ) / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal );
(int16_t) ( ( hCPE->element_brate ) / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal )
#endif #endif
); /* Update DFT Stereo memories */
stereo_dft_enc_update( hCPE->hStereoDft, sts[0]->max_bwidth );
/* DFT stereo processing */ /* DFT stereo processing */
stereo_dft_enc_process( hCPE, input_frame ); stereo_dft_enc_process( hCPE, input_frame );
...@@ -423,9 +413,11 @@ ivas_error ivas_cpe_enc( ...@@ -423,9 +413,11 @@ ivas_error ivas_cpe_enc(
} }
#ifdef DEBUG_MODE_INFO #ifdef DEBUG_MODE_INFO
dbgwrite( sts[0]->input - NS2SA( sts[0]->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX" ); for ( n = 0; n < n_CoreChannels; n++ )
dbgwrite( sts[1]->input - NS2SA( sts[1]->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX.ch2" ); {
dbgwrite( &hCPE->element_mode, 2, 1, input_frame, "res/element_mode" ); dbgwrite( sts[0]->input - NS2SA( sts[0]->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, fname( debug_dir, "input_DMX", n, sts[n]->id_element, ENC ) );
}
dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, sts[0]->id_element, ENC ) );
#endif #endif
/*----------------------------------------------------------------* /*----------------------------------------------------------------*
...@@ -460,7 +452,7 @@ ivas_error ivas_cpe_enc( ...@@ -460,7 +452,7 @@ ivas_error ivas_cpe_enc(
{ {
if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD )
{ {
reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata, st_ivas->sba_mode, hCPE->element_mode ); reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata, st_ivas->sba_mode );
} }
} }
...@@ -472,7 +464,7 @@ ivas_error ivas_cpe_enc( ...@@ -472,7 +464,7 @@ ivas_error ivas_cpe_enc(
/* Reset metadata */ /* Reset metadata */
if ( sts[0]->cng_sba_flag || ( ivas_format == SBA_FORMAT && st_ivas->sba_mode == SBA_MODE_SPAR ) ) if ( sts[0]->cng_sba_flag || ( ivas_format == SBA_FORMAT && st_ivas->sba_mode == SBA_MODE_SPAR ) )
{ {
reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata, st_ivas->sba_mode, hCPE->element_mode ); reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata, st_ivas->sba_mode );
} }
} }
...@@ -541,7 +533,7 @@ ivas_error ivas_cpe_enc( ...@@ -541,7 +533,7 @@ ivas_error ivas_cpe_enc(
* Write IVAS format signaling in SID frames * Write IVAS format signaling in SID frames
*----------------------------------------------------------------*/ *----------------------------------------------------------------*/
if ( sts[0]->core_brate == SID_2k40 && ( ivas_format != SBA_FORMAT || st_ivas->sba_mode != SBA_MODE_SPAR ) ) if ( sts[0]->core_brate == SID_2k40 )
{ {
ivas_write_format_sid( ivas_format, hCPE->element_mode, sts[0]->hBstr ); ivas_write_format_sid( ivas_format, hCPE->element_mode, sts[0]->hBstr );
} }
...@@ -560,7 +552,7 @@ ivas_error ivas_cpe_enc( ...@@ -560,7 +552,7 @@ ivas_error ivas_cpe_enc(
/* Reconfigure DFT Stereo for inactive frames */ /* Reconfigure DFT Stereo for inactive frames */
if ( sts[0]->core_brate == SID_2k40 ) if ( sts[0]->core_brate == SID_2k40 )
{ {
stereo_dft_config( hCPE->hStereoDft->hConfig, IVAS_SID_4k4, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); stereo_dft_config( hCPE->hStereoDft->hConfig, IVAS_SID_5k2, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
} }
else else
{ {
...@@ -568,13 +560,11 @@ ivas_error ivas_cpe_enc( ...@@ -568,13 +560,11 @@ ivas_error ivas_cpe_enc(
} }
stereo_dft_cng_side_gain( hCPE->hStereoDft, hCPE->hStereoCng, sts[0]->core_brate, sts[0]->last_core_brate, sts[0]->bwidth ); stereo_dft_cng_side_gain( hCPE->hStereoDft, hCPE->hStereoCng, sts[0]->core_brate, sts[0]->last_core_brate, sts[0]->bwidth );
stereo_dft_enc_update( hCPE->hStereoDft, min( SWB, sts[0]->max_bwidth )
#ifdef DEBUG_MODE_DFT #ifdef DEBUG_MODE_DFT
, hCPE->hStereoDft->res_cod_bits = 0;
0
#endif #endif
);
stereo_dft_enc_update( hCPE->hStereoDft, min( SWB, sts[0]->max_bwidth ) );
} }
else else
{ {
...@@ -604,7 +594,7 @@ ivas_error ivas_cpe_enc( ...@@ -604,7 +594,7 @@ ivas_error ivas_cpe_enc(
if ( sts[0]->core_brate == FRAME_NO_DATA || sts[0]->core_brate == SID_2k40 ) if ( sts[0]->core_brate == FRAME_NO_DATA || sts[0]->core_brate == SID_2k40 )
{ {
assert( ( nb_bits <= ( ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) ) && "Stereo DFT CNG: bit budget is violated" ); assert( ( nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) ) && "Stereo DFT CNG: bit budget is violated" );
} }
else else
{ {
...@@ -622,7 +612,7 @@ ivas_error ivas_cpe_enc( ...@@ -622,7 +612,7 @@ ivas_error ivas_cpe_enc(
* Core Encoder * Core Encoder
*----------------------------------------------------------------*/ *----------------------------------------------------------------*/
if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, 0 ) ) != IVAS_ERR_OK ) if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK )
{ {
return error; return error;
} }
......
...@@ -375,7 +375,7 @@ void ivas_decision_matrix_enc( ...@@ -375,7 +375,7 @@ void ivas_decision_matrix_enc(
void ivas_signaling_enc( void ivas_signaling_enc(
Encoder_State *st, /* i/o: encoder state structure */ Encoder_State *st, /* i/o: encoder state structure */
const int16_t is_MCT, /* i : MCT enabled */ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
const int32_t element_brate, /* i : element bitrate */ const int32_t element_brate, /* i : element bitrate */
const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */
const int16_t tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo */ const int16_t tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo */
...@@ -405,7 +405,7 @@ void ivas_signaling_enc( ...@@ -405,7 +405,7 @@ void ivas_signaling_enc(
* Write element mode info * Write element mode info
*--------------------------------------------------------------------------*/ *--------------------------------------------------------------------------*/
if ( st->element_mode >= IVAS_CPE_DFT && element_brate < MIN_BRATE_MDCT_STEREO && !is_MCT ) /* note: in MCT, the MDCT stereo is used exclusively */ if ( st->element_mode >= IVAS_CPE_DFT && element_brate < MIN_BRATE_MDCT_STEREO && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */
{ {
ind = st->element_mode - IVAS_CPE_DFT; ind = st->element_mode - IVAS_CPE_DFT;
push_indice( hBstr, IND_SMODE, ind, NBITS_ELEMENT_MODE ); push_indice( hBstr, IND_SMODE, ind, NBITS_ELEMENT_MODE );
......
...@@ -122,19 +122,16 @@ ivas_error ivas_dirac_enc_open( ...@@ -122,19 +122,16 @@ ivas_error ivas_dirac_enc_open(
if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) if ( st_ivas->sba_mode == SBA_MODE_DIRAC )
{ {
hDirAC->num_samples_synchro_delay = NS2SA( input_Fs, IVAS_FB_ENC_DELAY_NS ); hDirAC->num_samples_synchro_delay = NS2SA( input_Fs, IVAS_FB_ENC_DELAY_NS );
for ( i = 0; i < st_ivas->hEncoderConfig->nchan_inp; i++ )
for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ )
{ {
hDirAC->sba_synchro_buffer[i] = (float *) count_malloc( hDirAC->num_samples_synchro_delay * sizeof( float ) ); hDirAC->sba_synchro_buffer[i] = (float *) count_malloc( hDirAC->num_samples_synchro_delay * sizeof( float ) );
set_zero( hDirAC->sba_synchro_buffer[i], hDirAC->num_samples_synchro_delay ); set_zero( hDirAC->sba_synchro_buffer[i], hDirAC->num_samples_synchro_delay );
} }
for ( ; i < IVAS_MAX_NUM_CH; i++ )
{
hDirAC->sba_synchro_buffer[i] = NULL;
}
} }
else else
{ {
for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ )
{ {
hDirAC->sba_synchro_buffer[i] = NULL; hDirAC->sba_synchro_buffer[i] = NULL;
} }
...@@ -242,7 +239,7 @@ void ivas_dirac_enc_close( ...@@ -242,7 +239,7 @@ void ivas_dirac_enc_close(
ivas_FB_mixer_close( &hDirAC->hFbMixer, input_Fs ); ivas_FB_mixer_close( &hDirAC->hFbMixer, input_Fs );
} }
for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ )
{ {
if ( hDirAC->sba_synchro_buffer[i] != NULL ) if ( hDirAC->sba_synchro_buffer[i] != NULL )
{ {
...@@ -309,7 +306,7 @@ void ivas_dirac_enc( ...@@ -309,7 +306,7 @@ void ivas_dirac_enc(
BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */
int16_t *nb_bits_metadata, /* o : number of metadata bits written */ int16_t *nb_bits_metadata, /* o : number of metadata bits written */
const int16_t Opt_DTX_ON, /* i : flag signaling DTX on */ const int16_t Opt_DTX_ON, /* i : flag signaling DTX on */
float data_f[][L_FRAME48k], /* i/o: input: ACN/SN3D, output: omni, stereo DMX or FOA*/ float data_f[][L_FRAME48k], /* i/o: SBA channels */
const int16_t input_frame, /* i : input frame length */ const int16_t input_frame, /* i : input frame length */
const int16_t sba_planar /* i : SBA planar flag */ const int16_t sba_planar /* i : SBA planar flag */
) )
...@@ -337,7 +334,8 @@ void ivas_dirac_enc( ...@@ -337,7 +334,8 @@ void ivas_dirac_enc(
set_zero( data_f[2], input_frame ); set_zero( data_f[2], input_frame );
} }
ivas_dirac_param_est_enc( hDirAC, &( hQMetaData->q_direction[0] ), hQMetaData->useLowerRes, data_f, NULL, NULL, input_frame ); ivas_dirac_param_est_enc( hDirAC, &( hQMetaData->q_direction[0] ), hQMetaData->useLowerRes, data_f, NULL, NULL, input_frame, SBA_MODE_DIRAC );
/* encode parameters */ /* encode parameters */
if ( sba_planar || hQMetaData->useLowerRes ) if ( sba_planar || hQMetaData->useLowerRes )
{ {
...@@ -412,9 +410,7 @@ void ivas_dirac_enc( ...@@ -412,9 +410,7 @@ void ivas_dirac_enc(
} }
/* encode SID parameters */ /* encode SID parameters */
ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT, SBA_MODE_DIRAC );
SBA_FORMAT,
SBA_MODE_DIRAC );
/* restore original metadata */ /* restore original metadata */
hDirAC->hConfig->nbands = nbands; hDirAC->hConfig->nbands = nbands;
...@@ -429,10 +425,11 @@ void ivas_dirac_enc( ...@@ -429,10 +425,11 @@ void ivas_dirac_enc(
} }
else else
{ {
/*indicate whether SPAR or DiRAC mode*/
push_next_indice( hMetaData, 0, 1 );
/* encode SID parameters */ /* encode SID parameters */
ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT, SBA_MODE_DIRAC );
SBA_FORMAT,
SBA_MODE_DIRAC );
} }
} }
} }
...@@ -442,22 +439,52 @@ void ivas_dirac_enc( ...@@ -442,22 +439,52 @@ void ivas_dirac_enc(
return; return;
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* computeReferencePower_enc() * ivas_dirac_enc_spar_delay_synchro()
*
* *
* Delay input channels to be synchronized between DirAC and SPAR
*-------------------------------------------------------------------------*/ *-------------------------------------------------------------------------*/
void ivas_dirac_enc_spar_delay_synchro( void ivas_dirac_enc_spar_delay_synchro(
Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
const int16_t input_frame, /* i : input frame length */ const int16_t input_frame, /* i : input frame length */
float data_f[][L_FRAME48k] /* i/o: input: ACN/SN3D, output: omni, stereo DMX or FOA*/ float data_f[][L_FRAME48k] /* i/o: SBA channels (ACN / SN3D) */
) )
{ {
int16_t ch_idx; int16_t ch_idx;
float tmp_buffer[L_FRAME48k]; float tmp_buffer[L_FRAME48k];
Encoder_State *sts[MCT_MAX_BLOCKS];
int16_t sce_id, cpe_id, i_chan;
/* check last sba_mode */
if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_SPAR )
{
/* initializations */
i_chan = 0;
for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
{
sts[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0];
i_chan++;
}
for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
{
for ( int16_t ch = 0; ch < CPE_CHANNELS; ch++ )
{
sts[i_chan] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch];
i_chan++;
}
}
/* populate old synchro buffers */
for ( ch_idx = 0; ch_idx < i_chan; ch_idx++ )
{
mvr2r( sts[ch_idx]->input, st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay );
}
}
for ( ch_idx = 0; ch_idx < st_ivas->hEncoderConfig->nchan_inp; ch_idx++ ) for ( ch_idx = 0; ch_idx < DIRAC_MAX_ANA_CHANS; ch_idx++ )
{ {
mvr2r( data_f[ch_idx], tmp_buffer, input_frame ); mvr2r( data_f[ch_idx], tmp_buffer, input_frame );
mvr2r( st_ivas->hDirAC->sba_synchro_buffer[ch_idx], data_f[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); mvr2r( st_ivas->hDirAC->sba_synchro_buffer[ch_idx], data_f[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay );
...@@ -468,6 +495,7 @@ void ivas_dirac_enc_spar_delay_synchro( ...@@ -468,6 +495,7 @@ void ivas_dirac_enc_spar_delay_synchro(
return; return;
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* computeReferencePower_enc() * computeReferencePower_enc()
* *
...@@ -480,19 +508,28 @@ void computeReferencePower_enc( ...@@ -480,19 +508,28 @@ void computeReferencePower_enc(
float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */ float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal */
float *reference_power, /* o : Estimated power */ float *reference_power, /* o : Estimated power */
const int16_t enc_param_start_band, /* i : first band to process */ const int16_t enc_param_start_band, /* i : first band to process */
const int16_t num_freq_bands /* i : Number of frequency bands */ const int16_t num_freq_bands, /* i : Number of frequency bands */
const SBA_MODE sba_mode /* i : SBA mode */
) )
{ {
int16_t brange[2]; int16_t brange[2];
int16_t ch_idx, i, j; int16_t ch_idx, i, j;
float reference_power_W[DIRAC_MAX_NBANDS];
for ( i = 0; i < num_freq_bands; i++ ) for ( i = 0; i < num_freq_bands; i++ )
{ {
brange[0] = band_grouping[i + enc_param_start_band]; brange[0] = band_grouping[i + enc_param_start_band];
brange[1] = band_grouping[i + enc_param_start_band + 1]; brange[1] = band_grouping[i + enc_param_start_band + 1];
reference_power[i] = 0; reference_power[i] = 0;
for ( ch_idx = 0; ch_idx < DIRAC_MAX_ANA_CHANS; ch_idx++ ) reference_power_W[i] = 0;
for ( j = brange[0]; j < brange[1]; j++ )
{
reference_power_W[i] += ( Cldfb_RealBuffer[0][j] * Cldfb_RealBuffer[0][j] ) + ( Cldfb_ImagBuffer[0][j] * Cldfb_ImagBuffer[0][j] );
}
reference_power[i] += reference_power_W[i];
for ( ch_idx = 1; ch_idx < DIRAC_MAX_ANA_CHANS; ch_idx++ )
{ {
/* abs()^2 */ /* abs()^2 */
for ( j = brange[0]; j < brange[1]; j++ ) for ( j = brange[0]; j < brange[1]; j++ )
...@@ -503,15 +540,24 @@ void computeReferencePower_enc( ...@@ -503,15 +540,24 @@ void computeReferencePower_enc(
} }
v_multc( reference_power, 0.5f, reference_power, num_freq_bands ); v_multc( reference_power, 0.5f, reference_power, num_freq_bands );
if ( sba_mode == SBA_MODE_SPAR )
{
for ( i = 0; i < num_freq_bands; i++ )
{
reference_power[i] = max( reference_power[i], reference_power_W[i] );
}
}
return; return;
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* ivas_dirac_param_est_enc() * ivas_dirac_param_est_enc()
* *
* *
*------------------------------------------------------------------------*/ *------------------------------------------------------------------------*/
void ivas_dirac_param_est_enc( void ivas_dirac_param_est_enc(
DIRAC_ENC_HANDLE hDirAC, DIRAC_ENC_HANDLE hDirAC,
IVAS_QDIRECTION *q_direction, IVAS_QDIRECTION *q_direction,
...@@ -519,7 +565,8 @@ void ivas_dirac_param_est_enc( ...@@ -519,7 +565,8 @@ void ivas_dirac_param_est_enc(
float data_f[][L_FRAME48k], float data_f[][L_FRAME48k],
float **pp_fr_real, float **pp_fr_real,
float **pp_fr_imag, float **pp_fr_imag,
const int16_t input_frame ) const int16_t input_frame,
const SBA_MODE sba_mode )
{ {
int16_t i, d, ts, index, l_ts, num_freq_bands; int16_t i, d, ts, index, l_ts, num_freq_bands;
int16_t band_m_idx, block_m_idx; int16_t band_m_idx, block_m_idx;
...@@ -617,7 +664,8 @@ void ivas_dirac_param_est_enc( ...@@ -617,7 +664,8 @@ void ivas_dirac_param_est_enc(
Cldfb_ImagBuffer, Cldfb_ImagBuffer,
reference_power[ts], reference_power[ts],
hDirAC->hConfig->enc_param_start_band, hDirAC->hConfig->enc_param_start_band,
num_freq_bands ); num_freq_bands,
sba_mode );
computeIntensityVector_enc( computeIntensityVector_enc(
hDirAC, hDirAC,
...@@ -842,6 +890,7 @@ static void computeIntensityVector_enc( ...@@ -842,6 +890,7 @@ static void computeIntensityVector_enc(
int16_t i, j; int16_t i, j;
float real, img; float real, img;
int16_t brange[2]; int16_t brange[2];
for ( i = 0; i < num_frequency_bands; i++ ) for ( i = 0; i < num_frequency_bands; i++ )
{ {
brange[0] = hDirAC->band_grouping[i + enc_param_start_band]; brange[0] = hDirAC->band_grouping[i + enc_param_start_band];
......
...@@ -65,7 +65,9 @@ ivas_error ivas_enc( ...@@ -65,7 +65,9 @@ ivas_error ivas_enc(
float data_f[MAX_INPUT_CHANNELS][L_FRAME48k]; /* IVAS_fmToDo: buffer can be allocated dynamically based on the number of analysed channels */ float data_f[MAX_INPUT_CHANNELS][L_FRAME48k]; /* IVAS_fmToDo: buffer can be allocated dynamically based on the number of analysed channels */
int32_t ivas_total_brate; int32_t ivas_total_brate;
ivas_error error; ivas_error error;
#ifdef SBA_BR_SWITCHING
int16_t sba_reinit_flag;
#endif
error = IVAS_ERR_OK; error = IVAS_ERR_OK;
wmops_sub_start( "ivas_enc" ); wmops_sub_start( "ivas_enc" );
...@@ -85,6 +87,20 @@ ivas_error ivas_enc( ...@@ -85,6 +87,20 @@ ivas_error ivas_enc(
n_samples_chan = n_samples / nchan_inp; n_samples_chan = n_samples / nchan_inp;
set_s( nb_bits_metadata, 0, MAX_SCE ); set_s( nb_bits_metadata, 0, MAX_SCE );
#ifdef SBA_BR_SWITCHING
sba_reinit_flag = 0;
if ( ivas_format == SBA_FORMAT )
{
sba_reinit_flag = get_sba_reinit_flag( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate );
if ( sba_reinit_flag )
{
if ( ( error = ivas_sba_enc_reinit( st_ivas ) ) != IVAS_ERR_OK )
{
return error;
}
}
}
#endif
/*----------------------------------------------------------------* /*----------------------------------------------------------------*
* convert 'short' input data to 'float' * convert 'short' input data to 'float'
...@@ -189,7 +205,11 @@ ivas_error ivas_enc( ...@@ -189,7 +205,11 @@ ivas_error ivas_enc(
/* SBA/MASA configuration */ /* SBA/MASA configuration */
if ( ivas_format == SBA_FORMAT ) if ( ivas_format == SBA_FORMAT )
{ {
#ifndef SBA_BR_SWITCHING
if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) if ( st_ivas->sba_mode == SBA_MODE_DIRAC )
#else
if ( ( st_ivas->sba_mode == SBA_MODE_DIRAC ) && ( !sba_reinit_flag ) )
#endif
{ {
if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK )
{ {
......
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
static void ivas_band_cov( float **ppIn_FR_real, float **ppIn_FR_imag, const int16_t num_chans, const int16_t num_bins, int16_t stride, float **pFb_bin_to_band, const int16_t *pFb_start_bin_per_band, const int16_t *pFb_active_bins_per_band, const int16_t start_band, const int16_t end_band, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ); static void ivas_band_cov( float **ppIn_FR_real, float **ppIn_FR_imag, const int16_t num_chans, const int16_t num_bins, int16_t stride, float **pFb_bin_to_band, const int16_t *pFb_start_bin_per_band, const int16_t *pFb_active_bins_per_band, const int16_t start_band, const int16_t end_band, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] );
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* ivas_spar_covar_enc_open() * ivas_spar_covar_enc_open()
* *
...@@ -142,20 +141,23 @@ void ivas_spar_covar_enc_close( ...@@ -142,20 +141,23 @@ void ivas_spar_covar_enc_close(
void ivas_enc_cov_handler_process( void ivas_enc_cov_handler_process(
ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */
ivas_enc_cov_handler_in_buf_t *pIn_buf, float **ppIn_FR_real,
float **ppIn_FR_imag,
float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
ivas_filterbank_t *pFb, /* i/o: FB handle */ ivas_filterbank_t *pFb, /* i/o: FB handle */
const int16_t start_band, const int16_t start_band,
const int16_t end_band ) const int16_t end_band,
const int16_t num_ch,
const int16_t dtx_vad,
const int16_t transient_det )
{ {
int16_t i, j; int16_t i, j;
ivas_cov_smooth_in_buf_t pCov_in_buf; int16_t dtx_cov_flag;
int16_t num_ch = pIn_buf->num_ch;
pCov_in_buf.num_ch = num_ch; dtx_cov_flag = ( dtx_vad == 1 ) ? 0 : 1;
ivas_band_cov( pIn_buf->ppIn_FR_real, pIn_buf->ppIn_FR_imag, pIn_buf->num_ch, hCovEnc->num_bins, ivas_band_cov( ppIn_FR_real, ppIn_FR_imag, num_ch, hCovEnc->num_bins,
pFb->fb_bin_to_band.short_stride, pFb->fb_bin_to_band.short_stride,
pFb->fb_bin_to_band.pp_short_stride_bin_to_band, pFb->fb_bin_to_band.pp_short_stride_bin_to_band,
pFb->fb_bin_to_band.p_short_stride_start_bin_per_band, pFb->fb_bin_to_band.p_short_stride_start_bin_per_band,
...@@ -190,28 +192,20 @@ void ivas_enc_cov_handler_process( ...@@ -190,28 +192,20 @@ void ivas_enc_cov_handler_process(
{ {
for ( j = 0; j < num_ch; j++ ) for ( j = 0; j < num_ch; j++ )
{ {
pCov_in_buf.cov_real[i][j] = cov_real[i][j];
mvr2r( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); mvr2r( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands );
} }
} }
pCov_in_buf.reset_cov = 0; ivas_cov_smooth_process( hCovEnc->pCov_state, cov_real, pFb, start_band, end_band, num_ch, transient_det );
if ( pIn_buf->transient_det == 1 )
{
pCov_in_buf.reset_cov = 1;
}
ivas_cov_smooth_process( hCovEnc->pCov_state, &pCov_in_buf, pFb, start_band, end_band );
if ( pIn_buf->dtx_cov_flag == 0 ) if ( dtx_cov_flag == 0 )
{ {
for ( i = 0; i < num_ch; i++ ) for ( i = 0; i < num_ch; i++ )
{ {
for ( j = 0; j < num_ch; j++ ) for ( j = 0; j < num_ch; j++ )
{ {
mvr2r( pCov_in_buf.cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands ); mvr2r( cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands );
mvr2r( pCov_in_buf.cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); mvr2r( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands );
} }
} }
...@@ -219,35 +213,16 @@ void ivas_enc_cov_handler_process( ...@@ -219,35 +213,16 @@ void ivas_enc_cov_handler_process(
} }
else else
{ {
if ( transient_det == 0 )
if ( pIn_buf->transient_det == 0 )
{
for ( i = 0; i < num_ch; i++ )
{
for ( j = 0; j < num_ch; j++ )
{ {
pCov_in_buf.cov_real[i][j] = cov_dtx_real[i][j]; ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det );
}
}
pCov_in_buf.reset_cov = 0;
ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, &pCov_in_buf, pFb, start_band, end_band );
hCovEnc->prior_dtx_present = 1; hCovEnc->prior_dtx_present = 1;
} }
else else
{ {
if ( hCovEnc->prior_dtx_present == 0 ) if ( hCovEnc->prior_dtx_present == 0 )
{ {
for ( i = 0; i < num_ch; i++ ) ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det );
{
for ( j = 0; j < num_ch; j++ )
{
pCov_in_buf.cov_real[i][j] = cov_dtx_real[i][j];
}
}
pCov_in_buf.reset_cov = 1;
ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, &pCov_in_buf, pFb, start_band, end_band );
hCovEnc->prior_dtx_present = 1; hCovEnc->prior_dtx_present = 1;
} }
else else
......
...@@ -316,11 +316,13 @@ void ivas_arith_encode_cmplx_cell_array( ...@@ -316,11 +316,13 @@ void ivas_arith_encode_cmplx_cell_array(
int16_t input[IVAS_MAX_INPUT_LEN]; int16_t input[IVAS_MAX_INPUT_LEN];
ivas_cell_dim_t cell_dim[IVAS_MAX_NUM_BANDS], cell_dim_diff[IVAS_MAX_NUM_BANDS]; ivas_cell_dim_t cell_dim[IVAS_MAX_NUM_BANDS], cell_dim_diff[IVAS_MAX_NUM_BANDS];
int16_t len, idx, i, j, idx1; int16_t len, idx, i, j, idx1;
int16_t total_len;
idx1 = 0; idx1 = 0;
if ( any_diff == 1 ) if ( any_diff == 1 )
{ {
idx = 0; idx = 0;
total_len = 0;
for ( i = 0; i < nB; i++ ) for ( i = 0; i < nB; i++ )
{ {
len = ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); len = ( pCell_dims[i].dim1 * pCell_dims[i].dim2 );
...@@ -328,8 +330,8 @@ void ivas_arith_encode_cmplx_cell_array( ...@@ -328,8 +330,8 @@ void ivas_arith_encode_cmplx_cell_array(
{ {
for ( j = 0; j < len; j++ ) for ( j = 0; j < len; j++ )
{ {
input_old[idx] = pSymbol_old_re[i * len + j]; input_old[idx] = pSymbol_old_re[total_len + j];
input_new[idx++] = pSymbol_re[i * len + j]; input_new[idx++] = pSymbol_re[total_len + j];
} }
cell_dim_diff[i].dim1 = pCell_dims[i].dim1; cell_dim_diff[i].dim1 = pCell_dims[i].dim1;
cell_dim_diff[i].dim2 = pCell_dims[i].dim2; cell_dim_diff[i].dim2 = pCell_dims[i].dim2;
...@@ -340,13 +342,14 @@ void ivas_arith_encode_cmplx_cell_array( ...@@ -340,13 +342,14 @@ void ivas_arith_encode_cmplx_cell_array(
{ {
for ( j = 0; j < len; j++ ) for ( j = 0; j < len; j++ )
{ {
input[idx1++] = pSymbol_re[i * len + j]; input[idx1++] = pSymbol_re[total_len + j];
} }
cell_dim_diff[i].dim1 = 0; cell_dim_diff[i].dim1 = 0;
cell_dim_diff[i].dim2 = 0; cell_dim_diff[i].dim2 = 0;
cell_dim[i].dim1 = pCell_dims[i].dim1; cell_dim[i].dim1 = pCell_dims[i].dim1;
cell_dim[i].dim2 = pCell_dims[i].dim2; cell_dim[i].dim2 = pCell_dims[i].dim2;
} }
total_len += len;
} }
#ifdef SPAR_HOA_DBG #ifdef SPAR_HOA_DBG
/*if ( 0 )*/ /*(pCell_dims[0].dim1 == 12)*/ /*if ( 0 )*/ /*(pCell_dims[0].dim1 == 12)*/
......
...@@ -57,7 +57,7 @@ ivas_error front_vad( ...@@ -57,7 +57,7 @@ ivas_error front_vad(
Encoder_State *st, /* i/o: encoder state structure */ Encoder_State *st, /* i/o: encoder state structure */
const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */
FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: FrontVad handles */ FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: FrontVad handles */
const int16_t hMCT_flag, /* i : hMCT handle allocated (1) or not (0) */ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
const int16_t input_frame, /* i : frame length */ const int16_t input_frame, /* i : frame length */
int16_t vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO */ int16_t vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO */
float fr_bands[][2 * NB_BANDS], /* i : energy in frequency bands */ float fr_bands[][2 * NB_BANDS], /* i : energy in frequency bands */
...@@ -116,7 +116,7 @@ ivas_error front_vad( ...@@ -116,7 +116,7 @@ ivas_error front_vad(
* Allocate/deallocate hFrontVad handles in case of element_mode change * Allocate/deallocate hFrontVad handles in case of element_mode change
*-----------------------------------------------------------------*/ *-----------------------------------------------------------------*/
if ( sts[0]->ini_frame > 0 && hMCT_flag == 0 && last_element_mode != element_mode ) if ( sts[0]->ini_frame > 0 && MCT_flag == 0 && last_element_mode != element_mode )
{ {
if ( element_mode == IVAS_CPE_MDCT ) if ( element_mode == IVAS_CPE_MDCT )
{ {
...@@ -396,7 +396,7 @@ ivas_error front_vad_spar( ...@@ -396,7 +396,7 @@ ivas_error front_vad_spar(
hFrontVad = hSpar->hFrontVad; hFrontVad = hSpar->hFrontVad;
st = hSpar->hCoreCoderVAD; st = hSpar->hCoreCoderVAD;
if ( hEncoderConfig->Opt_DTX_ON && hEncoderConfig->ivas_total_brate <= IVAS_80k ) if ( hEncoderConfig->Opt_DTX_ON && hEncoderConfig->ivas_total_brate <= SBA_DTX_BITRATE_THRESHOLD )
{ {
/*------------------------------------------------------------------* /*------------------------------------------------------------------*
* Initialization * Initialization
...@@ -422,7 +422,7 @@ ivas_error front_vad_spar( ...@@ -422,7 +422,7 @@ ivas_error front_vad_spar(
* Front-VAD * Front-VAD
*-----------------------------------------------------------------*/ *-----------------------------------------------------------------*/
if ( ( error = front_vad( NULL, st, hEncoderConfig, &hFrontVad, 0 /* hMCT_flag */, input_frame, vad_flag_dtx, fr_bands, Etot, lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies, &PS[0], &st->Bin_E[0] ) ) != IVAS_ERR_OK ) if ( ( error = front_vad( NULL, st, hEncoderConfig, &hFrontVad, 0 /* MCT_flag */, input_frame, vad_flag_dtx, fr_bands, Etot, lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies, &PS[0], &st->Bin_E[0] ) ) != IVAS_ERR_OK )
{ {
return error; return error;
} }
......
...@@ -190,6 +190,10 @@ int16_t getNumChanAnalysis( ...@@ -190,6 +190,10 @@ int16_t getNumChanAnalysis(
{ {
n = st_ivas->hEncoderConfig->nchan_inp; n = st_ivas->hEncoderConfig->nchan_inp;
} }
else if ( st_ivas->hEncoderConfig->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM )
{
n = st_ivas->hEncoderConfig->nchan_inp;
}
return n; return n;
} }
...@@ -233,11 +237,11 @@ void copy_encoder_config( ...@@ -233,11 +237,11 @@ void copy_encoder_config(
st->force = st_ivas->hEncoderConfig->force; st->force = st_ivas->hEncoderConfig->force;
#endif #endif
st->element_mode = st_ivas->hEncoderConfig->element_mode_init; st->element_mode = st_ivas->hEncoderConfig->element_mode_init;
return; return;
} }
#ifdef FIX_I98_HANDLES_TO_NULL
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* ivas_initialize_handles_enc() * ivas_initialize_handles_enc()
* *
...@@ -297,7 +301,6 @@ void ivas_initialize_handles_enc( ...@@ -297,7 +301,6 @@ void ivas_initialize_handles_enc(
return; return;
} }
#endif
/*-------------------------------------------------------------------* /*-------------------------------------------------------------------*
...@@ -338,58 +341,7 @@ ivas_error ivas_init_encoder( ...@@ -338,58 +341,7 @@ ivas_error ivas_init_encoder(
st_ivas->mc_mode = MC_MODE_NONE; st_ivas->mc_mode = MC_MODE_NONE;
st_ivas->sba_mode = SBA_MODE_NONE; st_ivas->sba_mode = SBA_MODE_NONE;
#ifdef FIX_I98_HANDLES_TO_NULL
st_ivas->nchan_transport = -1; st_ivas->nchan_transport = -1;
#else
/*-----------------------------------------------------------------*
* Dummy pointers to max. number of SCEs and CPEs
*-----------------------------------------------------------------*/
st_ivas->nchan_transport = -1;
for ( i = 0; i < MAX_SCE; i++ )
{
st_ivas->hSCE[i] = NULL;
}
for ( i = 0; i < MAX_CPE; i++ )
{
st_ivas->hCPE[i] = NULL;
}
/* ISm metadata handles */
for ( n = 0; n < MAX_NUM_OBJECTS; n++ )
{
st_ivas->hIsmMetaData[n] = NULL;
}
/* Q Metadata handle */
st_ivas->hQMetaData = NULL;
/* DirAC handle */
st_ivas->hDirAC = NULL;
/* SPAR handle */
st_ivas->hSpar = NULL;
/* MASA encoder handle */
st_ivas->hMasa = NULL;
/* MCT handle */
st_ivas->hMCT = NULL;
/* Parametric MC handle */
st_ivas->hParamMC = NULL;
/* Multi-channel MASA handle */
st_ivas->hMcMasa = NULL;
/* Stereo downmix for EVS encoder handle */
st_ivas->hStereoDmxEVS = NULL;
/* LFE handle */
st_ivas->hLFE = NULL;
#endif
/*-----------------------------------------------------------------* /*-----------------------------------------------------------------*
* Allocate and initialize SCE/CPE and other handles * Allocate and initialize SCE/CPE and other handles
...@@ -478,13 +430,11 @@ ivas_error ivas_init_encoder( ...@@ -478,13 +430,11 @@ ivas_error ivas_init_encoder(
} }
} }
else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT )
{
{ {
if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
{ {
return error; return error;
} }
}
if ( ivas_format == SBA_FORMAT ) if ( ivas_format == SBA_FORMAT )
{ {
...@@ -650,6 +600,7 @@ ivas_error ivas_init_encoder( ...@@ -650,6 +600,7 @@ ivas_error ivas_init_encoder(
else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
{ {
ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate );
if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
{ {
return error; return error;
...@@ -1053,4 +1004,3 @@ void ivas_destroy_enc( ...@@ -1053,4 +1004,3 @@ void ivas_destroy_enc(
return; return;
} }
...@@ -259,7 +259,7 @@ ivas_error ivas_ism_enc( ...@@ -259,7 +259,7 @@ ivas_error ivas_ism_enc(
} }
#else #else
/* write unused bits */ /* write unused bits */
nBits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; nBits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS;
while ( nBits > 0 ) while ( nBits > 0 )
{ {
i = min( nBits, 16 ); i = min( nBits, 16 );
...@@ -312,7 +312,7 @@ ivas_error ivas_ism_enc( ...@@ -312,7 +312,7 @@ ivas_error ivas_ism_enc(
{ {
if ( sce_id == st_ivas->hDirAC->hParamIsm->sce_id_dtx ) if ( sce_id == st_ivas->hDirAC->hParamIsm->sce_id_dtx )
{ {
if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, 0 ) ) != IVAS_ERR_OK ) if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK )
{ {
return error; return error;
} }
...@@ -334,13 +334,13 @@ ivas_error ivas_ism_enc( ...@@ -334,13 +334,13 @@ ivas_error ivas_ism_enc(
} }
else else
{ {
if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, 0 ) ) != IVAS_ERR_OK ) if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK )
{ {
return error; return error;
} }
} }
#else #else
if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, 0 ) ) != IVAS_ERR_OK ) if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK )
{ {
return error; return error;
} }
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#include "ivas_rom_com.h" #include "ivas_rom_com.h"
#include "wmops.h" #include "wmops.h"
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* Local function definitions * Local function definitions
*------------------------------------------------------------------------*/ *------------------------------------------------------------------------*/
...@@ -422,19 +421,53 @@ ivas_error ivas_ism_enc_config( ...@@ -422,19 +421,53 @@ ivas_error ivas_ism_enc_config(
{ {
ivas_error error; ivas_error error;
ISM_MODE last_ism_mode; ISM_MODE last_ism_mode;
int16_t nchan_transport_old;
error = IVAS_ERR_OK; error = IVAS_ERR_OK;
last_ism_mode = st_ivas->ism_mode; last_ism_mode = st_ivas->ism_mode;
/* select ISM format mode */ /* select ISM format mode */
st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate ); st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate );
/* ISM format switching */ /* ISM bit-rate switching */
if ( st_ivas->ism_mode != last_ism_mode ) if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hEncoderConfig->ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) )
{
int32_t element_brate_tmp[MAX_NUM_OBJECTS];
nchan_transport_old = st_ivas->nchan_transport;
/* Reset and Initialize */
if ( st_ivas->ism_mode == ISM_MODE_PARAM )
{ {
/*ivas_ism_dec_reconfigure( st_ivas );*/ st_ivas->nchan_transport = 2;
return IVAS_ERROR( IVAS_ERR_RECONFIGURE_NOT_SUPPORTED, "Error: ISM format switching not supported yet!!!\n\n" ); }
else
{
st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp;
}
st_ivas->nSCE = st_ivas->nchan_transport;
st_ivas->nCPE = 0;
ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, NULL, NULL, element_brate_tmp, NULL, NULL );
ivas_corecoder_enc_reconfig( st_ivas, nchan_transport_old, 0, nchan_transport_old );
if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC )
{
/* Allocate and Initialize the memory used by ParamISM when switch from Discrete ISM */
if ( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK )
{
return error;
}
}
if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM )
{
/* Deallocate the memory used by ParamISM when switch to Discrete ISM */
ivas_param_ism_enc_close( st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs );
st_ivas->hDirAC = NULL;
}
} }
return error; return error;
......
...@@ -350,9 +350,7 @@ void ivas_masa_encode( ...@@ -350,9 +350,7 @@ void ivas_masa_encode(
count_free( h_orig_metadata ); count_free( h_orig_metadata );
ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, masa_sid_descriptor, ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, masa_sid_descriptor, ivas_format, SBA_MODE_NONE );
ivas_format,
SBA_MODE_NONE );
/* restore old values */ /* restore old values */
hMasa->config.numCodingBands = numCodingBands; hMasa->config.numCodingBands = numCodingBands;
......
...@@ -890,9 +890,14 @@ void ivas_mcmasa_param_est_enc( ...@@ -890,9 +890,14 @@ void ivas_mcmasa_param_est_enc(
0, 0,
num_freq_bands, num_freq_bands,
intensity_even_real ); intensity_even_real );
computeReferencePower_enc( hMcMasa->band_grouping, FoaEven_RealBuffer, FoaEven_ImagBuffer, reference_power[ts],
computeReferencePower_enc( hMcMasa->band_grouping,
FoaEven_RealBuffer,
FoaEven_ImagBuffer,
reference_power[ts],
0, 0,
num_freq_bands ); num_freq_bands,
SBA_MODE_NONE );
/* Fill buffers of length "averaging_length" time slots for intensity and energy */ /* Fill buffers of length "averaging_length" time slots for intensity and energy */
hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ) + 1; /* averaging_length = 32 */ hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ) + 1; /* averaging_length = 32 */
......
...@@ -53,21 +53,21 @@ ...@@ -53,21 +53,21 @@
static void FindChannelRatio( static void FindChannelRatio(
MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */
Encoder_State **sts, /* i/o: encoder state structure */ Encoder_State **sts, /* i/o: encoder state structure */
int16_t chBitRatios[MCT_MAX_CHANNELS], int16_t chBitRatios[MCT_MAX_CHANNELS], /* o : bit-disctribution channel ratios */
const int16_t nchan /* i : number of channels */ const int16_t nChannels /* i : number of channels to be coded */
) )
{ {
float sum_nrg = 0; float sum_nrg, chRatio;
float chRatio;
int16_t i; int16_t i;
float nrg[MCT_MAX_CHANNELS] = { 0 }; float nrg[MCT_MAX_CHANNELS];
set_f( nrg, 0, MCT_MAX_CHANNELS ); set_f( nrg, 0, MCT_MAX_CHANNELS );
getChannelEnergies( sts, nrg, nchan ); getChannelEnergies( sts, nrg, nChannels );
/*calculate total energy without LFE*/ /*calculate total energy without LFE*/
for ( i = 0; i < nchan; i++ ) sum_nrg = 0;
for ( i = 0; i < nChannels; i++ )
{ {
if ( sts[i]->mct_chan_mode != MCT_CHAN_MODE_IGNORE && sts[i]->mct_chan_mode != MCT_CHAN_MODE_LFE ) if ( sts[i]->mct_chan_mode != MCT_CHAN_MODE_IGNORE && sts[i]->mct_chan_mode != MCT_CHAN_MODE_LFE )
{ {
...@@ -76,7 +76,7 @@ static void FindChannelRatio( ...@@ -76,7 +76,7 @@ static void FindChannelRatio(
} }
sum_nrg = 1.0f / max( sum_nrg, EPSILON ); sum_nrg = 1.0f / max( sum_nrg, EPSILON );
for ( i = 0; i < nchan; i++ ) for ( i = 0; i < nChannels; i++ )
{ {
if ( sts[i]->mct_chan_mode != MCT_CHAN_MODE_IGNORE && sts[i]->mct_chan_mode != MCT_CHAN_MODE_LFE ) if ( sts[i]->mct_chan_mode != MCT_CHAN_MODE_IGNORE && sts[i]->mct_chan_mode != MCT_CHAN_MODE_LFE )
{ {
...@@ -106,14 +106,20 @@ static void FindChannelRatio( ...@@ -106,14 +106,20 @@ static void FindChannelRatio(
} }
/*----------------------------------------------------------*
* AdjustChannelRatios()
*
* adjust ratio of channels for bit distribution
*----------------------------------------------------------*/
static void AdjustChannelRatios( static void AdjustChannelRatios(
int16_t chBitRatios[MCT_MAX_CHANNELS], int16_t chBitRatios[MCT_MAX_CHANNELS], /* o : bit-disctribution channel ratios */
const int16_t nchan /* i : number of channels */ const int16_t nChannels /* i/o: number of channels */
#ifdef FIX_I1_113 #ifdef FIX_I1_113
, ,
const int32_t ivas_total_brate, const int32_t ivas_total_brate, /* i : IVAS total bitrate */
const int16_t nAvailBits, const int16_t nAvailBits, /* i : number of available bits */
const int16_t sba_order const int16_t sba_order /* i : Ambisonic (SBA) order */
#endif #endif
) )
{ {
...@@ -130,14 +136,14 @@ static void AdjustChannelRatios( ...@@ -130,14 +136,14 @@ static void AdjustChannelRatios(
force_ch_bit_ratios[2] = 5; force_ch_bit_ratios[2] = 5;
force_ch_bit_ratios[3] = 3; force_ch_bit_ratios[3] = 3;
#else #else
ivas_spar_bitrate_dist( temp_brs, nAvailBits, , sba_order, 3 ); ivas_spar_bitrate_dist( temp_brs, nAvailBits, ivas_total_brate, sba_order, (int16_t) FB );
sum_ratio = 0.0f; sum_ratio = 0.0f;
for ( i = 0; i < nchan; i++ ) for ( i = 0; i < nChannels; i++ )
{ {
sum_ratio += (float) temp_brs[i]; sum_ratio += (float) temp_brs[i];
} }
for ( i = 0; i < nchan; i++ ) for ( i = 0; i < nChannels; i++ )
{ {
cur_ratio = temp_brs[i] / sum_ratio; cur_ratio = temp_brs[i] / sum_ratio;
force_ch_bit_ratios[i] = min( BITRATE_MCT_RATIO_RANGE - 1, max( 1, (uint16_t) ( BITRATE_MCT_RATIO_RANGE * cur_ratio + 0.5f ) ) ); force_ch_bit_ratios[i] = min( BITRATE_MCT_RATIO_RANGE - 1, max( 1, (uint16_t) ( BITRATE_MCT_RATIO_RANGE * cur_ratio + 0.5f ) ) );
...@@ -148,12 +154,12 @@ static void AdjustChannelRatios( ...@@ -148,12 +154,12 @@ static void AdjustChannelRatios(
ratio_diff = 0; ratio_diff = 0;
sum_ratio = 0.0f; sum_ratio = 0.0f;
sum_tar_ratio = 0.0f; sum_tar_ratio = 0.0f;
for ( i = 0; i < nchan; i++ ) for ( i = 0; i < nChannels; i++ )
{ {
sum_ratio += (float) chBitRatios[i]; sum_ratio += (float) chBitRatios[i];
sum_tar_ratio += (float) force_ch_bit_ratios[i]; sum_tar_ratio += (float) force_ch_bit_ratios[i];
} }
for ( i = 3; i < nchan; i++ ) for ( i = 3; i < nChannels; i++ )
{ {
cur_ratio = (float) chBitRatios[i] / sum_ratio; cur_ratio = (float) chBitRatios[i] / sum_ratio;
tar_ratio = (float) force_ch_bit_ratios[i] / sum_tar_ratio; tar_ratio = (float) force_ch_bit_ratios[i] / sum_tar_ratio;
...@@ -164,29 +170,30 @@ static void AdjustChannelRatios( ...@@ -164,29 +170,30 @@ static void AdjustChannelRatios(
assert( chBitRatios[i] < ( BITRATE_MCT_RATIO_RANGE - 1 ) ); assert( chBitRatios[i] < ( BITRATE_MCT_RATIO_RANGE - 1 ) );
ratio_diff += force_ch_bit_ratios[i] - chBitRatios[i]; ratio_diff += force_ch_bit_ratios[i] - chBitRatios[i];
} }
for ( i = 0; i < min( 3, nchan ); i++ )
for ( i = 0; i < min( 3, nChannels ); i++ )
{ {
assert( force_ch_bit_ratios[i] >= 0 ); assert( force_ch_bit_ratios[i] >= 0 );
chBitRatios[i] = min( BITRATE_MCT_RATIO_RANGE - 1, force_ch_bit_ratios[i] ); chBitRatios[i] = min( BITRATE_MCT_RATIO_RANGE - 1, force_ch_bit_ratios[i] );
} }
chBitRatios[1] += ratio_diff; chBitRatios[1] += ratio_diff;
#ifdef FIX_I1_113
/* make sure final ratios are within range*/ /* make sure final ratios are within range*/
sum_ratio = 0.0f; sum_ratio = 0.0f;
for ( i = 0; i < nchan; i++ ) for ( i = 0; i < nChannels; i++ )
{ {
sum_ratio += (float) chBitRatios[i]; sum_ratio += (float) chBitRatios[i];
} }
for ( i = 0; i < nchan; i++ ) for ( i = 0; i < nChannels; i++ )
{ {
cur_ratio = chBitRatios[i] / sum_ratio; cur_ratio = chBitRatios[i] / sum_ratio;
chBitRatios[i] = min( BITRATE_MCT_RATIO_RANGE - 1, max( 1, (uint16_t) ( BITRATE_MCT_RATIO_RANGE * cur_ratio + 0.5f ) ) ); chBitRatios[i] = min( BITRATE_MCT_RATIO_RANGE - 1, max( 1, (uint16_t) ( BITRATE_MCT_RATIO_RANGE * cur_ratio + 0.5f ) ) );
} }
#endif
return; return;
} }
/*-------------------------------------------------------------------* /*-------------------------------------------------------------------*
* ivas_mct_core_enc() * ivas_mct_core_enc()
* *
...@@ -207,7 +214,7 @@ void ivas_mct_core_enc( ...@@ -207,7 +214,7 @@ void ivas_mct_core_enc(
#endif #endif
) )
{ {
int16_t ch, nSubframes, L_subframeTCX; int16_t ch, ch_core, nSubframes, L_subframeTCX;
int16_t i, cpe_id, n, nAvailBits; int16_t i, cpe_id, n, nAvailBits;
int16_t nCPE; int16_t nCPE;
float *orig_spectrum[MCT_MAX_CHANNELS][2]; /* Pointers to MDCT output for a short block (L/R) */ float *orig_spectrum[MCT_MAX_CHANNELS][2]; /* Pointers to MDCT output for a short block (L/R) */
...@@ -284,7 +291,7 @@ void ivas_mct_core_enc( ...@@ -284,7 +291,7 @@ void ivas_mct_core_enc(
for ( ch = 0; ch < (int16_t) ( hMCT->nchan_out_woLFE * 0.5 ); ch++ ) for ( ch = 0; ch < (int16_t) ( hMCT->nchan_out_woLFE * 0.5 ); ch++ )
{ {
int16_t ch_core = ch * CPE_CHANNELS; ch_core = ch * CPE_CHANNELS;
if ( switch_bw ) if ( switch_bw )
{ {
......
...@@ -193,17 +193,12 @@ ivas_error create_mct_enc( ...@@ -193,17 +193,12 @@ ivas_error create_mct_enc(
hMCT->nchan_out_woLFE = st_ivas->hEncoderConfig->nchan_inp - 1; /* LFE channel is coded separately */ hMCT->nchan_out_woLFE = st_ivas->hEncoderConfig->nchan_inp - 1; /* LFE channel is coded separately */
hMCT->num_lfe = TRUE; hMCT->num_lfe = TRUE;
} }
else if ( ivas_format == SBA_FORMAT && st_ivas->hSpar ) else if ( ivas_format == SBA_FORMAT )
{ {
hMCT->nchan_out_woLFE = ivas_get_spar_num_TCs( ivas_total_brate, st_ivas->sba_analysis_order ); hMCT->nchan_out_woLFE = ivas_get_sba_num_TCs( ivas_total_brate, st_ivas->sba_analysis_order );
hMCT->num_lfe = FALSE; hMCT->num_lfe = FALSE;
} }
else if ( ivas_format == SBA_FORMAT && st_ivas->hDirAC )
{
hMCT->nchan_out_woLFE = ivas_dirac_getNumTransportChannels( ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar );
hMCT->num_lfe = FALSE;
}
else if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) else if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC )
{ {
hMCT->nchan_out_woLFE = ivas_param_mc_getNumTransportChannels( ivas_total_brate, st_ivas->hEncoderConfig->mc_input_setup ); hMCT->nchan_out_woLFE = ivas_param_mc_getNumTransportChannels( ivas_total_brate, st_ivas->hEncoderConfig->mc_input_setup );
...@@ -337,9 +332,9 @@ ivas_error mct_enc_reconfigure( ...@@ -337,9 +332,9 @@ ivas_error mct_enc_reconfigure(
hMCT->nchan_out_woLFE = st_ivas->hEncoderConfig->nchan_inp - 1; /* LFE channel is coded separately */ hMCT->nchan_out_woLFE = st_ivas->hEncoderConfig->nchan_inp - 1; /* LFE channel is coded separately */
hMCT->num_lfe = TRUE; hMCT->num_lfe = TRUE;
} }
else if ( ivas_format == SBA_FORMAT && st_ivas->hDirAC ) else if ( ivas_format == SBA_FORMAT && st_ivas->hDirAC ) // VE: this condition to be reviewed together with the following one
{ {
hMCT->nchan_out_woLFE = ivas_dirac_getNumTransportChannels( ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); hMCT->nchan_out_woLFE = ivas_get_sba_num_TCs( ivas_total_brate, st_ivas->sba_analysis_order );
hMCT->num_lfe = FALSE; hMCT->num_lfe = FALSE;
} }
else if ( ivas_format == SBA_FORMAT ) else if ( ivas_format == SBA_FORMAT )
......
...@@ -834,7 +834,7 @@ void mctStereoIGF_enc( ...@@ -834,7 +834,7 @@ void mctStereoIGF_enc(
float *p_powerSpecMsInv[CPE_CHANNELS][NB_DIV]; float *p_powerSpecMsInv[CPE_CHANNELS][NB_DIV];
float *p_inv_spectrum[CPE_CHANNELS][NB_DIV]; float *p_inv_spectrum[CPE_CHANNELS][NB_DIV];
float *p_orig_spectrum[CPE_CHANNELS][NB_DIV]; float *p_orig_spectrum[CPE_CHANNELS][NB_DIV];
float p_powerSpec[NB_DIV][N_MAX]; float *p_powerSpec[NB_DIV];
int16_t singleChEle[MCT_MAX_CHANNELS]; int16_t singleChEle[MCT_MAX_CHANNELS];
L_subframeTCX = 0; /* to avoid compilation warning */ L_subframeTCX = 0; /* to avoid compilation warning */
...@@ -855,10 +855,8 @@ void mctStereoIGF_enc( ...@@ -855,10 +855,8 @@ void mctStereoIGF_enc(
p_st[0] = sts[ch1]; p_st[0] = sts[ch1];
p_st[1] = sts[ch2]; p_st[1] = sts[ch2];
mvr2r( powerSpec[ch1], p_powerSpec[0], L_FRAME48k ); p_powerSpec[0] = powerSpec[ch1];
set_f( &p_powerSpec[0][L_FRAME48k], 0.f, N_MAX - L_FRAME48k ); p_powerSpec[1] = powerSpec[ch2];
mvr2r( powerSpec[ch2], p_powerSpec[1], L_FRAME48k );
set_f( &p_powerSpec[1][L_FRAME48k], 0.f, N_MAX - L_FRAME48k );
/* Band-wise M/S for MDST */ /* Band-wise M/S for MDST */
nSubframes = p_st[0]->hTcxEnc->tcxMode == TCX_20 ? 1 : NB_DIV; nSubframes = p_st[0]->hTcxEnc->tcxMode == TCX_20 ? 1 : NB_DIV;
......