Skip to content
......@@ -63,9 +63,7 @@ static void enc_prm_pre_mdct(
int16_t param[], /* i : parameters */
const int16_t *no_param_tns, /* i : number of TNS parameters per subframe */
int16_t p_param[2], /* o : pointer to parameters for next round of bs writing */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
const int16_t is_mct,
#endif
const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */
BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */
)
{
......@@ -80,11 +78,7 @@ static void enc_prm_pre_mdct(
* Header
*--------------------------------------------------------------------------------*/
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
writeTCXMode( st, hBstr, is_mct, &nbits_start );
#else
writeTCXMode( st, hBstr, &nbits_start );
#endif
writeTCXMode( st, hBstr, MCT_flag, &nbits_start );
/* write last_core for core switching and error concealment */
push_next_indice( hBstr, st->last_core != ACELP_CORE, 1 );
......@@ -1065,11 +1059,7 @@ void ivas_mdct_core_whitening_enc(
continue;
}
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
enc_prm_pre_mdct( st, param_core[ch], ( ( ( ch > 0 ) && ( sts[0]->hTcxEnc->fUseTns[0] + sts[0]->hTcxEnc->fUseTns[1] > 0 ) && !mct_on ) ? tnsSize[ch] : NULL ), p_param[ch], mct_on, hBstr );
#else
enc_prm_pre_mdct( st, param_core[ch], ( ( ( ch > 0 ) && ( sts[0]->hTcxEnc->fUseTns[0] + sts[0]->hTcxEnc->fUseTns[1] > 0 ) && !mct_on ) ? tnsSize[ch] : NULL ), p_param[ch], hBstr );
#endif
if ( ch > 0 && sts[0]->hTcxEnc->fUseTns[0] + sts[0]->hTcxEnc->fUseTns[1] > 0 && !mct_on )
{
......@@ -1166,7 +1156,7 @@ void ivas_mdct_quant_coder(
int16_t tnsBits[CPE_CHANNELS][NB_DIV], /* i : bits needed for TNS parameters */
int16_t tnsSize[CPE_CHANNELS][NB_DIV], /* i : size of TNS */
int16_t p_param[CPE_CHANNELS][NB_DIV], /* i : pointer to parameter array */
const int16_t is_mct /* i : is mct flag */
const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
)
{
Encoder_State *st, **sts;
......@@ -1262,7 +1252,7 @@ void ivas_mdct_quant_coder(
}
}
EstimateStereoTCXNoiseLevel( sts, quantized_spectrum, gain_tcx, L_frame, noiseFillingBorder, hm_active, ignore_chan, fac_ns, param_core, is_mct );
EstimateStereoTCXNoiseLevel( sts, quantized_spectrum, gain_tcx, L_frame, noiseFillingBorder, hm_active, ignore_chan, fac_ns, param_core, MCT_flag );
for ( ch = 0; ch < CPE_CHANNELS; ch++ )
{
......
......@@ -684,17 +684,20 @@ void ivas_qmetadata_enc_sid_encode(
{
if ( sba_mode == SBA_MODE_SPAR )
{
metadata_sid_bits = (int16_t) ( IVAS_SID_5k - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 1; /* -1 for inactive mode header bit*/
/* TODO: still use old sid frame size to keep bitexactness */
metadata_sid_bits = (int16_t) ( 5000 /*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 1; /* -1 for inactive mode header bit*/
}
else
{
/* keep 13.2 and 16.4 SID bitrate as 4.4 kbps for now*/
metadata_sid_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS;
/* TODO: still use old sid frame size to keep bitexactness */
metadata_sid_bits = ( 4400 /*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS;
}
}
else
{
metadata_sid_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS;
/* TODO: still use old sid frame size to keep bitexactness */
metadata_sid_bits = ( 4400 /*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS;
}
#ifdef DEBUG_MODE_QMETADATA
......@@ -873,6 +876,20 @@ void ivas_qmetadata_enc_sid_encode(
}
#endif
/* TODO: temporary to keep BE */
if ( ivas_format == SBA_FORMAT )
{
if ( sba_mode != SBA_MODE_SPAR )
{
/* keep 13.2 and 16.4 SID bitrate as 4.4 kbps for now*/
metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - 1; /* -1 for spar/dirac indicator*/
}
}
else
{
metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS;
}
/* fill bits*/
assert( ( hMetaData->nb_bits_tot - bit_pos_start ) <= metadata_sid_bits && "Too many written bits!" );
while ( ( hMetaData->nb_bits_tot - bit_pos_start ) < metadata_sid_bits )
......@@ -896,11 +913,11 @@ void reset_metadata_spatial(
int32_t *total_brate, /* o : total bitrate */
const int32_t core_brate, /* i : core bitrate */
const int16_t nb_bits_metadata, /* i : number of meatdata bits */
const SBA_MODE sba_mode, /* i : SBA mode */
const int16_t element_mode /* i : element mode */
const SBA_MODE sba_mode /* i : SBA mode */
)
{
int16_t i, next_ind_sid, last_ind_sid;
int16_t metadata_sid_bits;
if ( core_brate == SID_2k40 || core_brate == FRAME_NO_DATA )
{
......@@ -909,13 +926,11 @@ void reset_metadata_spatial(
if ( sba_mode == SBA_MODE_SPAR )
{
assert( hMetaData->ind_list[0].nb_bits == 1 );
if ( element_mode > IVAS_SCE )
{
hMetaData->ind_list[0].value = 1;
}
else
metadata_sid_bits = (int16_t) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS;
while ( hMetaData->nb_bits_tot < metadata_sid_bits )
{
hMetaData->ind_list[0].value = 0;
push_next_indice( hMetaData, 0, 1 ); /*fill bit*/
}
}
else
......@@ -946,7 +961,7 @@ void reset_metadata_spatial(
hMetaData->ind_list[i].nb_bits = -1;
}
hMetaData->last_ind = hMetaData->next_ind;
assert( ( hMetaData->nb_bits_tot == ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) && "Problem of SID metadata in SCE" );
assert( ( hMetaData->nb_bits_tot == ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) && "Problem of SID metadata in SCE" );
}
}
else
......
......@@ -45,11 +45,6 @@
#endif
#include "wmops.h"
/*-----------------------------------------------------------------------*
* Local function prototypes
*-----------------------------------------------------------------------*/
static void ivas_sba_dmx_enc( float sba_data[][L_FRAME48k], const int16_t nchan_transport, const int16_t input_frame );
/*-------------------------------------------------------------------*
* ivas_sba_getTCs()
......@@ -65,9 +60,8 @@ void ivas_sba_getTCs(
{
ivas_sba_zero_vert_comp( sba_data, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar, input_frame );
if ( st_ivas->sba_mode == SBA_MODE_SPAR )
{
st_ivas->nchan_transport = ivas_get_spar_num_TCs( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
st_ivas->nchan_transport = ivas_get_sba_num_TCs( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->sba_analysis_order );
if ( st_ivas->nchan_transport >= 3 )
{
/*convert WYZX downmix to WYXZ*/
......@@ -80,12 +74,6 @@ void ivas_sba_getTCs(
sba_data[3][i] = temp;
}
}
}
else
{
st_ivas->nchan_transport = ivas_dirac_getNumTransportChannels( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar );
ivas_sba_dmx_enc( sba_data, st_ivas->nchan_transport, input_frame );
}
#ifdef DEBUG_MODE_DIRAC
for ( int16_t n = 0; n < st_ivas->nchan_transport; n++ )
......@@ -105,119 +93,17 @@ void ivas_sba_getTCs(
return;
}
#ifdef SBA_BR_SWITCHING
/*-------------------------------------------------------------------*
* ivas_sba_dmx_enc()
*
* ivas_sba_enc_reinit()
*
* Reinitialise IVAS SBA encoder
*-------------------------------------------------------------------*/
static void ivas_sba_dmx_enc(
float sba_data[][L_FRAME48k], /* i : SBA signals */
const int16_t nchan_transport, /* i : number of transport channels */
const int16_t input_frame /* i : frame length */
)
{
int16_t i;
float dmx_l, dmx_r;
float a, b;
float tmp_f[DIRAC_MAX_TRANS_CHANS];
if ( nchan_transport >= 7 )
{
for ( i = 0; i < input_frame; i++ )
{
tmp_f[0] = 0.282095f * sba_data[0][i] + 0.000000f * sba_data[1][i] + 0.420663f * sba_data[3][i] + 0.000000f * sba_data[4][i] + 0.334240f * sba_data[8][i] + 0.000000f * sba_data[9][i] + 0.179369f * sba_data[15][i];
tmp_f[1] = 0.282095f * sba_data[0][i] + 0.328887f * sba_data[1][i] + 0.262279f * sba_data[3][i] + 0.325860f * sba_data[4][i] + -0.074375f * sba_data[8][i] + 0.077825f * sba_data[9][i] + -0.161606f * sba_data[15][i];
tmp_f[2] = 0.282095f * sba_data[0][i] + 0.410116f * sba_data[1][i] + -0.093606f * sba_data[3][i] + -0.145021f * sba_data[4][i] + -0.301140f * sba_data[8][i] + -0.140237f * sba_data[9][i] + 0.111835f * sba_data[15][i];
tmp_f[3] = 0.282095f * sba_data[0][i] + 0.182519f * sba_data[1][i] + -0.379004f * sba_data[3][i] + -0.261320f * sba_data[4][i] + 0.208395f * sba_data[8][i] + 0.174872f * sba_data[9][i] + -0.039913f * sba_data[15][i];
tmp_f[4] = 0.282095f * sba_data[0][i] + -0.182519f * sba_data[1][i] + -0.379004f * sba_data[3][i] + 0.261320f * sba_data[4][i] + 0.208395f * sba_data[8][i] + -0.174872f * sba_data[9][i] + -0.039913f * sba_data[15][i];
tmp_f[5] = 0.282095f * sba_data[0][i] + -0.410116f * sba_data[1][i] + -0.093606f * sba_data[3][i] + 0.145021f * sba_data[4][i] + -0.301140f * sba_data[8][i] + 0.140237f * sba_data[9][i] + 0.111835f * sba_data[15][i];
tmp_f[6] = 0.282095f * sba_data[0][i] + -0.328887f * sba_data[1][i] + 0.262279f * sba_data[3][i] + -0.325860f * sba_data[4][i] + -0.074375f * sba_data[8][i] + -0.077825f * sba_data[9][i] + -0.161606f * sba_data[15][i];
sba_data[7][i] = sba_data[2][i]; /* will be dropped for planarSBA */
sba_data[0][i] = tmp_f[0];
sba_data[1][i] = tmp_f[1];
sba_data[2][i] = tmp_f[2];
sba_data[3][i] = tmp_f[3];
sba_data[4][i] = tmp_f[4];
sba_data[5][i] = tmp_f[5];
sba_data[6][i] = tmp_f[6];
}
return;
}
else if ( nchan_transport >= 5 )
{
for ( i = 0; i < input_frame; i++ )
{
tmp_f[0] = 0.282095f * sba_data[0][i] + 0.000000f * sba_data[1][i] + 0.378166f * sba_data[3][i] + 0.000000f * sba_data[4][i] + 0.217722f * sba_data[8][i];
tmp_f[1] = 0.282095f * sba_data[0][i] + 0.359658f * sba_data[1][i] + 0.116860f * sba_data[3][i] + 0.127974f * sba_data[4][i] + -0.176140f * sba_data[8][i];
tmp_f[2] = 0.282095f * sba_data[0][i] + 0.222281f * sba_data[1][i] + -0.305943f * sba_data[3][i] + -0.207066f * sba_data[4][i] + 0.067280f * sba_data[8][i];
tmp_f[3] = 0.282095f * sba_data[0][i] + -0.222281f * sba_data[1][i] + -0.305943f * sba_data[3][i] + 0.207066f * sba_data[4][i] + 0.067280f * sba_data[8][i];
tmp_f[4] = 0.282095f * sba_data[0][i] + -0.359658f * sba_data[1][i] + 0.116860f * sba_data[3][i] + -0.127974f * sba_data[4][i] + -0.176140f * sba_data[8][i];
sba_data[5][i] = sba_data[2][i]; /* will be dropped for planarSBA */
sba_data[0][i] = tmp_f[0];
sba_data[1][i] = tmp_f[1];
sba_data[2][i] = tmp_f[2];
sba_data[3][i] = tmp_f[3];
sba_data[4][i] = tmp_f[4];
}
return;
}
else if ( nchan_transport >= 3 )
{
for ( i = 0; i < input_frame; i++ )
{
dmx_l = 0.5f * sba_data[1][i];
dmx_r = 0.5f * sba_data[2][i];
a = 0.5f * sba_data[0][i];
b = 0.25f * sba_data[3][i];
sba_data[0][i] = a + b;
sba_data[1][i] = sba_data[0][i] - dmx_l;
sba_data[0][i] += dmx_l;
sba_data[2][i] = a - b;
sba_data[3][i] = sba_data[2][i] - dmx_r; /* will be dropped for planarSBA & irrelevant*/
sba_data[2][i] += dmx_r; /* irrelevant for planarSBA*/
}
return;
}
else if ( nchan_transport == 2 )
{
for ( i = 0; i < input_frame; i++ )
{
dmx_l = 0.5f * ( sba_data[0][i] + sba_data[1][i] ); /* cardioid_left = W + Y */
sba_data[1][i] = 0.5f * ( sba_data[0][i] - sba_data[1][i] ); /* cardioid_right = W - Y */
sba_data[0][i] = dmx_l;
}
return;
}
else if ( nchan_transport == 1 )
{
/* do nothing; simply use omni */
return;
}
return;
}
/*-------------------------------------------------------------------*
* ivas_sba_enc_reconfigure()
*
* Reconfigure IVAS SBA encoder
*-------------------------------------------------------------------*/
ivas_error ivas_sba_enc_reconfigure(
ivas_error ivas_sba_enc_reinit(
Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
)
{
int16_t ntransport;
int16_t ntransport_old;
int16_t nSCE_old;
int16_t nCPE_old;
int16_t sce_id;
......@@ -225,62 +111,23 @@ ivas_error ivas_sba_enc_reconfigure(
int16_t n;
Indice *ind_list_metadata;
int32_t ivas_total_brate;
int16_t i, nchan_inp;
ivas_error error;
ENCODER_CONFIG_HANDLE hEncoderConfig;
Indice *ind_list;
BSTR_ENC_HANDLE hBstr;
BSTR_ENC_HANDLE hMetaData;
hEncoderConfig = st_ivas->hEncoderConfig;
ivas_total_brate = hEncoderConfig->ivas_total_brate;
error = IVAS_ERR_OK;
nchan_inp = st_ivas->hEncoderConfig->nchan_inp;
ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate;
if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate )
{
ntransport = st_ivas->nchan_transport;
ntransport_old = st_ivas->nchan_transport;
nCPE_old = st_ivas->nCPE;
nSCE_old = st_ivas->nSCE;
ind_list_metadata = NULL;
st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order );
ivas_dirac_enc_reconfigure( st_ivas );
ntransport = st_ivas->nchan_transport;
if ( ntransport == ntransport_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
{
Indice *ind_list;
int16_t nb_bits_tot;
int16_t next_ind;
int16_t last_ind;
BSTR_ENC_HANDLE hBstr;
BSTR_ENC_HANDLE hMetaData;
ind_list = NULL;
hBstr = NULL;
......@@ -297,58 +144,96 @@ ivas_error ivas_sba_enc_reconfigure(
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;
/* destroy superfluous core coder elements */
for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
/*------------------------------------------------------------------------------------------*
* Closing Encoder handles before Reinitialisation
*------------------------------------------------------------------------------------------*/
/* Q Metadata handle */
ivas_qmetadata_close( &( st_ivas->hQMetaData ) );
/* DirAC handle */
if ( st_ivas->hDirAC != NULL )
{
destroy_sce_enc( st_ivas->hSCE[sce_id] );
st_ivas->hSCE[sce_id] = NULL;
ivas_dirac_enc_close( st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs );
st_ivas->hDirAC = NULL;
}
for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
/* SPAR handle */
if ( st_ivas->hSpar != NULL )
{
destroy_cpe_enc( st_ivas->hCPE[cpe_id] );
st_ivas->hCPE[cpe_id] = NULL;
ivas_spar_enc_close( st_ivas->hSpar, st_ivas->hEncoderConfig->input_Fs, nchan_inp );
st_ivas->hSpar = NULL;
}
/* SCE handles */
for ( i = 0; i < MAX_SCE; i++ )
{
if ( st_ivas->hSCE[i] != NULL )
{
destroy_sce_enc( st_ivas->hSCE[i] );
st_ivas->hSCE[i] = NULL;
}
}
if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
/* CPE handles */
for ( i = 0; i < MAX_CPE; i++ )
{
if ( st_ivas->hCPE[i] != NULL )
{
destroy_cpe_enc( st_ivas->hCPE[i] );
st_ivas->hCPE[i] = NULL;
}
}
/* MCT handle */
if ( st_ivas->hMCT != NULL )
{
ivas_mct_enc_close( st_ivas->hMCT );
st_ivas->hMCT = NULL;
}
if ( st_ivas->mem_hp20_in != NULL )
{
n = getNumChanAnalysis( st_ivas );
for ( i = 0; i < n; i++ )
{
count_free( st_ivas->mem_hp20_in[i] );
st_ivas->mem_hp20_in[i] = NULL;
}
count_free( st_ivas->mem_hp20_in );
st_ivas->mem_hp20_in = 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 )
/*------------------------------------------------------------------------------------------*
* Reopening Encoder handles for Reinitialisation
*------------------------------------------------------------------------------------------*/
if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
{
count_free( st_ivas->hCPE[0]->hStereoMdct );
st_ivas->hCPE[0]->hStereoMdct = NULL;
return error;
}
/* create missing core coder elements and set element bitrates for alrady existing ones */
if ( st_ivas->nSCE > 0 )
st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate );
st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order );
if ( st_ivas->sba_mode == SBA_MODE_SPAR )
{
int16_t nSCE_existing;
nSCE_existing = min( nSCE_old, st_ivas->nSCE );
for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
if ( ( error = ivas_spar_enc_open( st_ivas ) ) != IVAS_ERR_OK )
{
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() */
return error;
}
}
for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ )
if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK )
{
return error;
}
for ( sce_id = 0; 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 )
{
......@@ -357,41 +242,18 @@ ivas_error ivas_sba_enc_reconfigure(
/* 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 )
{
int16_t nCPE_existing;
nCPE_existing = min( nCPE_old, st_ivas->nCPE );
for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->hEncoderConfig->Opt_DTX_ON )
{
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() */
st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1;
}
}
for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ )
for ( cpe_id = 0; 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 )
{
......@@ -402,125 +264,91 @@ ivas_error ivas_sba_enc_reconfigure(
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 ( st_ivas->hEncoderConfig->Opt_DTX_ON )
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 )
/* Metadata only initialized for the last CPE index */
if ( cpe_id == st_ivas->nCPE - 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 );
}
st_ivas->hCPE[cpe_id]->hMetaData->ind_list = ind_list_metadata + sce_id * MAX_BITS_METADATA;
reset_indices_enc( st_ivas->hCPE[cpe_id]->hMetaData, MAX_BITS_METADATA );
}
}
if ( st_ivas->nCPE > 1 )
{
if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
{
return error;
}
}
else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
n = getNumChanAnalysis( st_ivas );
if ( n > 0 )
{
if ( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nCPE != nCPE_old ) ) != IVAS_ERR_OK )
if ( ( st_ivas->mem_hp20_in = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL )
{
return error;
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
}
}
/* 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 )
else
{
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) );
}
st_ivas->mem_hp20_in = NULL;
}
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++ )
for ( i = 0; i < n; i++ )
{
if ( st_ivas->hCPE[cpe_id]->hMetaData != NULL )
if ( ( st_ivas->mem_hp20_in[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL )
{
count_free( st_ivas->hCPE[cpe_id]->hMetaData );
st_ivas->hCPE[cpe_id]->hMetaData = NULL;
return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
}
set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM );
}
return error;
}
#endif
/* 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++ )
/*-------------------------------------------------------------------*
* ivas_sba_enc_reconfigure()
*
* Reconfigure IVAS SBA encoder
*-------------------------------------------------------------------*/
ivas_error ivas_sba_enc_reconfigure(
Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
)
{
st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
int16_t nSCE_old, nCPE_old, nchan_transport_old;
int32_t ivas_total_brate;
ivas_error error;
error = IVAS_ERR_OK;
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 );
ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate;
if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf )
if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate )
{
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;
}
nchan_transport_old = st_ivas->nchan_transport;
nCPE_old = st_ivas->nCPE;
nSCE_old = st_ivas->nSCE;
initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, st_ivas->hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, st_ivas->hEncoderConfig->max_bwidth, 0, NULL, 1 );
st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) );
}
}
st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order );
ivas_dirac_enc_reconfigure( st_ivas );
/*-----------------------------------------------------------------*
* Allocate, initalize, and configure SCE/CPE/MCT handles
*-----------------------------------------------------------------*/
ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old );
}
return error;
......
......@@ -165,11 +165,17 @@ ivas_error ivas_sce_enc(
/* set "total_brate" */
st->total_brate = hSCE->element_brate - nb_bits_metadata * FRAMES_PER_SEC;
/* set flag for sampling rate of OL S/M classifier */
flag_16k_smc = 0;
if ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) && hSCE->element_brate == hSCE->last_element_brate )
{
flag_16k_smc = 1;
}
#ifdef DEBUG_MODE_INFO
dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX" );
dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" );
dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) );
#endif
/* set flag for sampling rate of OL S/M classifier */
flag_16k_smc = ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) );
/*----------------------------------------------------------------*
* Front Pre-processing
......@@ -199,14 +205,13 @@ ivas_error ivas_sce_enc(
* Reset metadata
*----------------------------------------------------------------*/
reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode,
IVAS_SCE );
reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode );
/*----------------------------------------------------------------*
* Write IVAS format signaling in SID frames
*----------------------------------------------------------------*/
if ( st->core_brate == SID_2k40 && ( ivas_format != SBA_FORMAT || st_ivas->sba_mode != SBA_MODE_SPAR ) )
if ( st->core_brate == SID_2k40 )
{
ivas_write_format_sid( ivas_format, IVAS_SCE, st->hBstr );
}
......@@ -232,13 +237,11 @@ ivas_error ivas_sce_enc(
* Encoder
*----------------------------------------------------------------*/
if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, 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, 0,
flag_16k_smc ) ) != IVAS_ERR_OK )
if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, 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, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK )
{
return error;
}
/*----------------------------------------------------------------*
* Common updates
*----------------------------------------------------------------*/
......@@ -246,6 +249,15 @@ ivas_error ivas_sce_enc(
/* update input samples buffer */
mvr2r( st->input, st->old_input_signal, input_frame );
hSCE->last_element_brate = hSCE->element_brate;
#ifdef DEBUG_MODE_INFO
{
float tmpF = hSCE->element_brate / 1000.0f;
dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, sce_id, ENC ) );
}
#endif
wmops_sub_end();
return error;
......@@ -285,6 +297,7 @@ ivas_error create_sce_enc(
hSCE->sce_id = sce_id;
hSCE->element_brate = element_brate;
hSCE->last_element_brate = hSCE->element_brate;
/*-----------------------------------------------------------------*
* Metadata: allocate and initialize
......
......@@ -43,176 +43,6 @@
#endif
#include "wmops.h"
#ifndef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
#define SNS_NPTS 16 /* Number of downsampled SNS parameters */
/*-------------------------------------------------------------------
* sns_compute_scf()
*
*
*-------------------------------------------------------------------*/
void sns_compute_scf(
float spectrum[],
const PsychoacousticParameters *pPsychParams,
const int16_t L_frame,
float *scf )
{
int16_t i, n, k;
float x[FDNS_NPTS], xs[FDNS_NPTS], sum, mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS];
float tilt;
const uint8_t nBands = pPsychParams->nBands;
const uint8_t *bandLengths = pPsychParams->bandLengths;
int8_t bw = 0;
const float w_0 = 1.0f / 12.0f;
const float w_1 = 2.0f / 12.0f;
const float w_2 = 0.25f; /* 3.0f / 12.0f */
const float w_3 = w_2;
const float w_4 = w_1;
const float w_5 = w_0;
const float scale_log = INV_LOG_2 * 0.5f;
assert( nBands == 64 );
set_f( x, 0.0f, FDNS_NPTS );
if ( bandLengths == NULL )
{
bw = (int8_t) ( L_frame / nBands );
/* Energy per band */
k = 0;
for ( i = 0; i < nBands; ++i )
{
x[i] = 0.0f;
for ( n = 0; n < bw; ++n, ++k )
{
x[i] += spectrum[k];
}
x[i] /= bw;
}
}
else
{
/* Energy per band */
k = 0;
for ( i = 0; i < nBands; ++i )
{
x[i] = 0.0f;
for ( n = 0; n < bandLengths[i]; ++n, ++k )
{
x[i] += spectrum[k];
}
x[i] /= bandLengths[i];
}
}
/* Smoothing */
xs[0] = 0.75f * x[0] + 0.25f * x[1];
for ( i = 1; i < FDNS_NPTS - 1; i++ )
{
xs[i] = 0.5f * x[i] + 0.25f * x[i - 1] + 0.25f * x[i + 1];
}
xs[FDNS_NPTS - 1] = 0.75f * x[FDNS_NPTS - 1] + 0.25f * x[FDNS_NPTS - 2];
/* Pre-emphasis */
if ( L_frame == L_FRAME16k )
{
tilt = 18.f;
}
else if ( L_frame == L_SPEC16k_EXT )
{
tilt = 20.f;
}
else if ( L_frame == L_FRAME25_6k )
{
tilt = 22.f;
}
else if ( L_frame == L_FRAME32k )
{
tilt = 26.f;
}
else if ( L_frame == L_SPEC32k_EXT )
{
tilt = 30.f;
}
else
{
tilt = 0.f;
assert( 0 && "illegal frame length in sns_compute_scf" );
}
for ( i = 0; i < FDNS_NPTS; i++ )
{
xs[i] = xs[i] * powf( 10.0f, (float) i * (float) tilt / ( (float) FDNS_NPTS - 1.0f ) / 10.0f );
}
/* Noise floor at -40dB */
sum = sum_f( xs, FDNS_NPTS );
mean = sum / FDNS_NPTS;
nf = mean * powf( 10.0f, -4.0f );
nf = max( nf, powf( 2.0f, -32.0f ) );
for ( i = 0; i < FDNS_NPTS; i++ )
{
if ( xs[i] < nf )
{
xs[i] = nf;
}
}
/* Log-domain */
for ( i = 0; i < FDNS_NPTS; i++ )
{
xl[i] = logf( xs[i] ) * scale_log;
}
/* Downsampling */
xl4[0] = w_0 * xl[0] +
w_1 * xl[0] +
w_2 * xl[1] +
w_3 * xl[2] +
w_4 * xl[3] +
w_5 * xl[4];
for ( n = 1; n < SNS_NPTS - 1; n++ )
{
int16_t n4 = 4 * n;
xl4[n] = w_0 * xl[n4 - 1] +
w_1 * xl[n4] +
w_2 * xl[n4 + 1] +
w_3 * xl[n4 + 2] +
w_4 * xl[n4 + 3] +
w_5 * xl[n4 + 4];
}
xl4[SNS_NPTS - 1] = w_0 * xl[FDNS_NPTS - 5] +
w_1 * xl[FDNS_NPTS - 4] +
w_2 * xl[FDNS_NPTS - 3] +
w_3 * xl[FDNS_NPTS - 2] +
w_4 * xl[FDNS_NPTS - 1] +
w_5 * xl[FDNS_NPTS - 1];
/* Remove mean and scaling */
sum = sum_f( xl4, SNS_NPTS );
mean = sum / SNS_NPTS;
for ( i = 0; i < SNS_NPTS; i++ )
{
scf[i] = 0.85f * ( xl4[i] - mean );
}
return;
}
#endif
/*-------------------------------------------------------------------
* sns_1st_cod()
......
......@@ -83,7 +83,8 @@ ivas_error ivas_spar_enc_open(
nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal );
assert( nchan_inp <= hEncoderConfig->nchan_inp );
ivas_total_brate = hEncoderConfig->ivas_total_brate;
nchan_transport = ivas_get_spar_num_TCs( hEncoderConfig->ivas_total_brate, sba_order_internal );
nchan_transport = ivas_get_sba_num_TCs( hEncoderConfig->ivas_total_brate, sba_order_internal );
// bw = ivas_get_bw_idx_from_sample_rate(pCfg->input_Fs);
table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL );
......@@ -119,11 +120,20 @@ ivas_error ivas_spar_enc_open(
}
/* AGC handle */
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
hSpar->AGC_Enable = ivas_agc_enc_get_flag( hEncoderConfig->Opt_AGC_ON, nchan_transport );
#else
hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport );
#endif
hSpar->hAgcEnc = NULL;
if ( hSpar->AGC_Enable )
{
if ( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK )
{
return error;
}
}
/* PCA handle */
hSpar->hPCA = NULL;
if ( hEncoderConfig->Opt_PCA_ON )
......@@ -147,11 +157,11 @@ ivas_error ivas_spar_enc_open(
if ( st_ivas->nchan_transport == 1 )
{
st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE;
hEncoderConfig->element_mode_init = IVAS_SCE;
}
else
{
st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
}
/*-----------------------------------------------------------------*
......@@ -233,7 +243,6 @@ void ivas_spar_enc_close(
hSpar->hFrontVad = NULL;
}
num_chans = hSpar->hFbMixer->fb_cfg->num_in_chans;
assert( num_chans <= nchan_inp );
......@@ -282,28 +291,17 @@ ivas_error ivas_spar_enc(
)
{
ENCODER_CONFIG_HANDLE hEncoderConfig;
#ifndef SPAR_SCALING_HARMONIZATION
int16_t ch;
#endif
ivas_error error;
error = IVAS_ERR_OK;
hEncoderConfig = st_ivas->hEncoderConfig;
/* front VAD */
if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], st_ivas->hEncoderConfig, input_frame ) ) != IVAS_ERR_OK )
if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], hEncoderConfig, input_frame ) ) != IVAS_ERR_OK )
{
return error;
}
#ifndef SPAR_SCALING_HARMONIZATION
/* normalize input channels */
for ( ch = 0; ch < hEncoderConfig->nchan_inp; ch++ )
{
v_multc( data_f[ch], MDFT_NORM_SCALING, data_f[ch], input_frame );
}
#endif
if ( hEncoderConfig->sba_planar )
{
ivas_sba_zero_vert_comp( data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_planar, input_frame );
......@@ -321,8 +319,8 @@ ivas_error ivas_spar_enc(
*nb_bits_metadata = hMetaData->nb_bits_tot;
/* temp hack to not force IVAS front pre-proc decision for higher bitrates */
if ( hEncoderConfig->ivas_total_brate > IVAS_64k || hEncoderConfig->Opt_DTX_ON == 0 )
/* Force IVAS front pre-proc decision for higher bitrates */
if ( hEncoderConfig->ivas_total_brate > SBA_DTX_BITRATE_THRESHOLD || hEncoderConfig->Opt_DTX_ON == 0 )
{
st_ivas->hSpar->front_vad_flag = 0;
}
......@@ -330,68 +328,6 @@ ivas_error ivas_spar_enc(
return error;
}
/*-----------------------------------------------------------------------------------------*
* Function ivas_spar_enc_get_windowed_fr()
*
* Get windowed FRs
*-----------------------------------------------------------------------------------------*/
static void ivas_spar_enc_get_windowed_fr(
IVAS_FB_MIXER_HANDLE hFbMixer,
float *pIn_blocks[IVAS_SPAR_MAX_CH],
ivas_enc_cov_handler_in_buf_t *pCov_in_buf,
const int16_t input_frame,
const int16_t nchan_inp,
const int16_t num_past_samples )
{
int16_t i, j, rev_offset;
for ( i = 0; i < nchan_inp; i++ )
{
const int16_t stride = hFbMixer->pFb->fb_bin_to_band.short_stride;
float tmp_buf[MDFT_FB_BANDS_240 * 2];
int16_t win_len = (int16_t) hFbMixer->ana_window_offset;
float *mdft_in_ptr = tmp_buf + stride - win_len;
float tmp_in_block[L_FRAME48k + MDFT_FB_BANDS_240];
float *data_ptr = tmp_in_block;
float *fr_re_ptr = pCov_in_buf->ppIn_FR_real[i];
float *fr_im_ptr = pCov_in_buf->ppIn_FR_imag[i];
set_f( tmp_buf, 0, MDFT_FB_BANDS_240 * 2 );
/* copy input data, because pIn_blocks and fr_re_ptr + fr_im_ptr use the same memory */
mvr2r( &pIn_blocks[i][input_frame - num_past_samples], tmp_in_block, input_frame + win_len );
for ( int16_t blk = 0; blk < input_frame / stride; blk++ )
{
for ( j = 0; j < win_len; j++ )
{
mdft_in_ptr[j] = data_ptr[j] * hFbMixer->pAna_window[j];
}
for ( j = win_len; j < stride; j++ )
{
mdft_in_ptr[j] = data_ptr[j];
}
rev_offset = win_len - 1;
for ( j = stride; j < stride + win_len; j++ )
{
mdft_in_ptr[j] = data_ptr[j] * hFbMixer->pAna_window[rev_offset--];
}
ivas_mdft( tmp_buf, fr_re_ptr, fr_im_ptr, stride << 1, stride );
data_ptr += stride;
fr_re_ptr += stride;
fr_im_ptr += stride;
}
}
return;
}
/*-----------------------------------------------------------------------------------------*
* Function ivas_spar_enc_process()
......@@ -409,14 +345,11 @@ static ivas_error ivas_spar_enc_process(
{
float pcm_tmp[IVAS_SPAR_MAX_CH][L_FRAME48k * 2];
float *p_pcm_tmp[IVAS_SPAR_MAX_CH];
int16_t i, j, k, b, i_ts, input_frame, num_bands_bw;
int16_t dtx_vad, dtx_cov_flag, dtx_silence_mode;
int16_t i, j, b, i_ts, input_frame, transient_det, dtx_vad;
int32_t ivas_total_brate, input_Fs;
ivas_enc_cov_handler_in_buf_t cov_in_buf;
float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
ivas_spar_md_enc_in_buf_t md_in_buf;
int16_t nchan_inp, nchan_transport, bwidth, sba_order;
int16_t nchan_inp, nchan_transport, sba_order;
int16_t table_idx;
int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH];
ivas_error error;
......@@ -451,13 +384,11 @@ static ivas_error ivas_spar_enc_process(
mvr2r( data_f[HOA_keep_ind[i]], data_f[i], input_frame );
}
table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL );
/*-----------------------------------------------------------------------------------------*
* Transient detector
*-----------------------------------------------------------------------------------------*/
cov_in_buf.transient_det = ivas_transient_det_process( hSpar->hTranDet, data_f[0], input_frame );
transient_det = ivas_transient_det_process( hSpar->hTranDet, data_f[0], input_frame );
/* store previous input samples for W in local buffer */
assert( num_del_samples <= IVAS_FB_1MS_48K_SAMP );
......@@ -478,15 +409,9 @@ static ivas_error ivas_spar_enc_process(
/* prepare Parameter MDFT analysis */
for ( i = 0; i < nchan_inp; i++ )
{
cov_in_buf.ppIn_FR_real[i] = p_pcm_tmp[i];
cov_in_buf.ppIn_FR_imag[i] = p_pcm_tmp[i] + input_frame;
}
for ( i = 0; i < nchan_inp; i++ )
{
ppIn_FR_real[i] = p_pcm_tmp[i];
ppIn_FR_imag[i] = p_pcm_tmp[i] + input_frame;
p_pcm_tmp[i] = &data_f[i][0];
ppIn_FR_real[i] = cov_in_buf.ppIn_FR_real[i];
ppIn_FR_imag[i] = cov_in_buf.ppIn_FR_imag[i];
}
l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES;
......@@ -507,19 +432,18 @@ static ivas_error ivas_spar_enc_process(
/* turn pointers back to the local buffer, needed for the following processing */
for ( i = 0; i < nchan_inp; i++ )
{
ppIn_FR_real[i] = pcm_tmp[i];
ppIn_FR_imag[i] = pcm_tmp[i] + input_frame;
p_pcm_tmp[i] = pcm_tmp[i];
}
cov_in_buf.num_ch = nchan_inp;
dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1;
/*-----------------------------------------------------------------------------------------*
* DirAC encoding
*-----------------------------------------------------------------------------------------*/
ivas_dirac_param_est_enc( st_ivas->hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes,
data_f, cov_in_buf.ppIn_FR_real, cov_in_buf.ppIn_FR_imag, input_frame );
ivas_dirac_param_est_enc( st_ivas->hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, st_ivas->sba_mode );
if ( hQMetaData->q_direction->cfg.nbands > 0 )
{
......@@ -582,7 +506,6 @@ static ivas_error ivas_spar_enc_process(
if ( dtx_vad == 0 )
{
for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
{
hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0];
......@@ -604,24 +527,10 @@ static ivas_error ivas_spar_enc_process(
}
}
/*-----------------------------------------------------------------------------------------*
* Pre-proc flags
*-----------------------------------------------------------------------------------------*/
/* use just VAD function to get VAD flags */
dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1;
dtx_cov_flag = ( dtx_vad == 1 ) ? 0 : 1;
dtx_silence_mode = 0; // VE2DB: this variable is always 0 - please review or remove it
bwidth = ivas_get_bw_idx_from_sample_rate( input_Fs );
bwidth = min( bwidth, hEncoderConfig->max_bwidth );
/*-----------------------------------------------------------------------------------------*
* Covariance process
*-----------------------------------------------------------------------------------------*/
cov_in_buf.num_ch = nchan_inp;
for ( i = 0; i < nchan_inp; i++ )
{
for ( j = 0; j < nchan_inp; j++ )
......@@ -631,59 +540,31 @@ static ivas_error ivas_spar_enc_process(
}
}
cov_in_buf.dtx_cov_flag = dtx_cov_flag;
ivas_enc_cov_handler_process( hSpar->hCovEnc, &cov_in_buf, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands );
ivas_enc_cov_handler_process( hSpar->hCovEnc, ppIn_FR_real, ppIn_FR_imag, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det );
/*-----------------------------------------------------------------------------------------*
* Set SPAR bitrates
*-----------------------------------------------------------------------------------------*/
table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL );
if ( hSpar->hMdEnc->table_idx != table_idx )
{
hSpar->hMdEnc->table_idx = table_idx;
ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, SPAR_DIRAC_SPLIT_START_BAND );
ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND );
}
nchan_transport = hSpar->hMdEnc->spar_md_cfg.nchan_transport;
nchan_transport = st_ivas->nchan_transport;
/*-----------------------------------------------------------------------------------------*
* MetaData encoder
*-----------------------------------------------------------------------------------------*/
num_bands_bw = ivas_get_num_bands_from_bw_idx( bwidth );
if ( dtx_vad == 0 )
{
for ( i = 0; i < nchan_inp; i++ )
{
for ( j = 0; j < nchan_inp; j++ )
{
md_in_buf.cov_real[i][j] = cov_dtx_real[i][j];
for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ )
if ( hSpar->hMdEnc->spar_hoa_md_flag == 0 )
{
md_in_buf.cov_real[i][j][k] = 0;
ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order );
}
}
}
}
else
{
for ( i = 0; i < nchan_inp; i++ )
{
for ( j = 0; j < nchan_inp; j++ )
{
md_in_buf.cov_real[i][j] = cov_real[i][j];
for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ )
{
md_in_buf.cov_real[i][j][k] = 0;
}
}
}
}
md_in_buf.num_bands = ivas_get_num_bands_from_bw_idx( SPAR_CONFIG_BW );
md_in_buf.num_bands = min( md_in_buf.num_bands, SPAR_DIRAC_SPLIT_START_BAND );
md_in_buf.dtx_vad = dtx_vad;
ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, &md_in_buf, hMetaData, dtx_silence_mode, sba_order );
if ( st_ivas->sba_mode == SBA_MODE_SPAR ) // VE2DB: this looks obsolete
{
float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES];
float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES];
......@@ -706,13 +587,9 @@ static ivas_error ivas_spar_enc_process(
diffuseness[b] = 1.0f - hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0];
}
if ( ( d_start_band >= 6 ) && ( dtx_vad == 1 ) )
{
for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ )
if ( d_start_band >= 6 && dtx_vad == 1 )
{
hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re[i] =
hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re[i];
}
mvr2r( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re, IVAS_SPAR_MAX_CH - 1 );
}
for ( b = d_start_band; b < d_end_band; b++ )
......@@ -720,17 +597,20 @@ static ivas_error ivas_spar_enc_process(
Wscale_d[b] = 1.0f;
for ( i = 1; i < nchan_inp; i++ )
{
Wscale_d[b] += md_in_buf.cov_real[i][i][b] / max( EPSILON, md_in_buf.cov_real[0][0][b] );
Wscale_d[b] += cov_real[i][i][b] / max( EPSILON, cov_real[0][0][b] );
}
Wscale_d[b] = Wscale_d[b] / ( 1.0f + (float) sba_order ); /*DirAC normalized signal variance sums to 1 + order*/
Wscale_d[b] = sqrtf( Wscale_d[b] );
Wscale_d[b] = min( 2.0f, max( Wscale_d[b], 1.0f ) );
}
ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, hSpar->hMdEnc->mixer_mat, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg,
d_start_band, d_end_band, sba_order, dtx_vad, Wscale_d );
ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, hSpar->hMdEnc->mixer_mat, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? 1 : sba_order, dtx_vad, Wscale_d );
}
if ( hSpar->hMdEnc->spar_hoa_md_flag )
{
ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order );
}
/*-----------------------------------------------------------------------------------------*
* FB mixer
......@@ -740,6 +620,7 @@ static ivas_error ivas_spar_enc_process(
#ifdef DEBUG_SBA_MD_DUMP
{
int16_t k;
static FILE *f_mat = 0;
if ( f_mat == 0 )
......@@ -793,23 +674,11 @@ static ivas_error ivas_spar_enc_process(
if ( hSpar->hPCA != NULL )
{
#ifdef SPAR_SCALING_HARMONIZATION
for ( int16_t out_ch = 0; out_ch < FOA_CHANNELS; out_ch++ )
{
v_multc( p_pcm_tmp[out_ch], MDFT_NORM_SCALING, p_pcm_tmp[out_ch], input_frame );
}
#endif
ivas_pca_enc( hEncoderConfig, hSpar->hPCA, hMetaData, p_pcm_tmp, input_frame, FOA_CHANNELS );
#ifdef SPAR_SCALING_HARMONIZATION
for ( int16_t out_ch = 0; out_ch < FOA_CHANNELS; out_ch++ )
{
v_multc( p_pcm_tmp[out_ch], PCM16_TO_FLT_FAC, p_pcm_tmp[out_ch], input_frame );
}
#endif
}
else
{
if ( ivas_total_brate == PCA_BRATE && sba_order == 1 )
if ( ivas_total_brate == PCA_BRATE && sba_order == SBA_FOA_ORDER )
{
/* write PCA bypass bit */
push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 );
......@@ -840,12 +709,16 @@ static ivas_error ivas_spar_enc_process(
if ( dtx_vad == 1 )
{
if ( hEncoderConfig->Opt_AGC_ON > 0 )
if ( hSpar->AGC_Enable != 0 )
{
ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig );
}
else
{
/* IVAS_fmToDo: This AGC on/off bit should be removed when the command line option to force enable/disable AGC is
* removed.
* On the decoder side, ivas_agc_enc_get_flag could be used instead to determine if AGC is on or not. The
* ivas_agc_enc_get_flag function should be moved to ivas_agc_com.c and renamed when this occurs. */
push_next_indice( hMetaData, 0, 1 );
}
}
......@@ -896,20 +769,13 @@ static ivas_error ivas_spar_enc_process(
order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order];
for ( i = 0; i < input_frame; i++ )
{
for ( j = 0; j < nchan_transport; j++ )
{
#ifndef SPAR_SCALING_HARMONIZATION
data_f[order[j]][i] = p_pcm_tmp[j][i] * PCM16_TO_FLT_FAC;
#else
data_f[order[j]][i] = p_pcm_tmp[j][i];
#endif
mvr2r( p_pcm_tmp[j], data_f[order[j]], input_frame );
}
for ( ; j < IVAS_SPAR_MAX_DMX_CHS; j++ )
{
data_f[order[j]][i] = 0;
}
set_f( data_f[order[j]], 0.0f, input_frame );
}
wmops_sub_end();
......
......@@ -82,13 +82,13 @@ static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[
static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, const int16_t bands_bw, const int16_t strat, const int16_t dtx_vad, const int16_t qsi );
static void ivas_write_parameter_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP );
static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t strat, const int16_t qsi, const int16_t planarCP );
static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, const ENCODER_CONFIG_HANDLE hEncoderConfig, const int16_t sba_order );
static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, float **ppValues, const int16_t ndm, int16_t **ppIndex, const int16_t dim1, float **ppQuant );
static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, const int16_t ndm, int16_t *pIndex, const int16_t dim1, float *pQuant );
static void ivas_quant_p_per_band_dtx( float **ppP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float **ppP_out, const int16_t num_ch );
static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t num_ch );
static void ivas_write_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, int16_t *num_dmx, int16_t *num_dec, const int16_t num_bands );
......@@ -122,7 +122,7 @@ ivas_error ivas_spar_md_enc_open(
return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" );
}
num_channels = 2 * sba_order + 2;
num_channels = ivas_sba_get_nchan_metadata( sba_order );
if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL )
{
......@@ -318,12 +318,12 @@ static ivas_error ivas_spar_md_enc_init(
float PR_minmax[2];
int16_t num_channels, i, j, k;
hMdEnc->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate );
num_channels = ivas_sba_get_nchan_metadata( sba_order );
table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL );
hMdEnc->spar_md_cfg.gen_bs = 1;
ivas_spar_set_bitrate_config( &hMdEnc->spar_md_cfg, table_idx, SPAR_DIRAC_SPLIT_START_BAND );
ivas_spar_set_bitrate_config( &hMdEnc->spar_md_cfg, table_idx, ( hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND );
/* get FB coefficients */
for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ )
......@@ -332,19 +332,6 @@ static ivas_error ivas_spar_md_enc_init(
}
ivas_spar_set_enc_config( hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, num_channels );
/*
if(hMdEnc->spar_md_cfg.quant_strat[0].C.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].C.q_levels[1] == 0
|| hMdEnc->spar_md_cfg.quant_strat[0].PR.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].PR.q_levels[1] == 0
|| hMdEnc->spar_md_cfg.quant_strat[0].P_c.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].P_c.q_levels[1] == 0
|| hMdEnc->spar_md_cfg.quant_strat[0].P_r.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].P_r.q_levels[1] == 0)
{
hMdEnc->spar_md_cfg.gen_bs = 0;
}
else if(0 != hMdEnc->spar_md_cfg.gen_bs)
{
hMdEnc->spar_md_cfg.quant_strat_bits = ivas_get_bits_to_encode(MAX_QUANT_STRATS);
}
*/
if ( hMdEnc->spar_md_cfg.nchan_transport != 2 && ( ( hMdEnc->spar_md_cfg.remix_unmix_order == 1 ) || ( hMdEnc->spar_md_cfg.remix_unmix_order == 2 ) ) )
{
......@@ -555,19 +542,20 @@ static void write_metadata_buffer(
ivas_error ivas_spar_md_enc_process(
ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */
const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */
ivas_spar_md_enc_in_buf_t *pIn_buf,
float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */
const int16_t dtx_silence_mode,
const int16_t dtx_vad,
const int16_t nchan_inp,
const int16_t sba_order /* i : Ambisonic (SBA) order */
)
{
float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS];
float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS];
float pred_coeffs_re_local[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS];
int16_t i, b, qsi, ndm, ndec, num_ch, num_quant_strats;
int16_t j, planarCP;
int16_t num_bands = pIn_buf->num_bands;
int16_t dtx_vad = pIn_buf->dtx_vad;
int16_t k, bwidth, num_bands, num_bands_full, num_bands_bw;
int16_t active_w, nchan_transport, dmx_switch, strat;
int16_t nB, bands_bw, packed_ok = 0;
ivas_strats_t cs[MAX_CODING_STRATS];
......@@ -582,7 +570,40 @@ ivas_error ivas_spar_md_enc_process(
active_w = hMdEnc->spar_md_cfg.active_w;
nchan_transport = hMdEnc->spar_md_cfg.nchan_transport;
if ( hEncoderConfig->ivas_total_brate == BRATE_SPAR_Q_STRAT && sba_order == 1 )
bwidth = ivas_get_bw_idx_from_sample_rate( hEncoderConfig->input_Fs );
bwidth = min( bwidth, hEncoderConfig->max_bwidth );
num_bands = ivas_get_num_bands_from_bw_idx( SPAR_CONFIG_BW );
if ( hMdEnc->spar_hoa_md_flag == 0 )
{
num_bands = min( num_bands, SPAR_DIRAC_SPLIT_START_BAND );
}
num_bands_full = num_bands;
num_bands_bw = ivas_get_num_bands_from_bw_idx( bwidth );
if ( dtx_vad == 0 )
{
for ( i = 0; i < nchan_inp; i++ )
{
for ( j = 0; j < nchan_inp; j++ )
{
cov_real[i][j] = cov_dtx_real[i][j];
}
}
}
for ( i = 0; i < nchan_inp; i++ )
{
for ( j = 0; j < nchan_inp; j++ )
{
for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ )
{
cov_real[i][j][k] = 0;
}
}
}
if ( hEncoderConfig->ivas_total_brate == BRATE_SPAR_Q_STRAT && sba_order == SBA_FOA_ORDER )
{
/* make sure that qsi is always 0 (temporary bits are '00') */
num_quant_strats = 1;
......@@ -595,11 +616,6 @@ ivas_error ivas_spar_md_enc_process(
next_ind_start = hMetaData->next_ind;
last_ind_start = hMetaData->last_ind;
if ( hEncoderConfig->Opt_DTX_ON == 0 )
{
dtx_vad = 1;
}
dmx_switch = 0;
if ( dtx_vad == 0 )
......@@ -607,7 +623,7 @@ ivas_error ivas_spar_md_enc_process(
nB = SPAR_DTX_BANDS;
bands_bw = num_bands / nB;
ivas_band_mixer( pIn_buf->cov_real, num_ch, &num_bands, bands_bw );
ivas_band_mixer( cov_real, num_ch, &num_bands, bands_bw );
}
else
{
......@@ -615,7 +631,18 @@ ivas_error ivas_spar_md_enc_process(
bands_bw = 1;
}
ivas_compute_spar_params( pIn_buf->cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch,
if ( hMdEnc->spar_hoa_md_flag )
{
for ( b = SPAR_DIRAC_SPLIT_START_BAND; b < num_bands; b++ )
{
for ( i = 0; i < FOA_CHANNELS - 1; i++ )
{
pred_coeffs_re_local[i][b] = hMdEnc->spar_md.band_coeffs[b].pred_re[i];
}
}
}
ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch,
bands_bw, active_w, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0 );
for ( i = 0; i < num_ch; i++ )
......@@ -663,7 +690,7 @@ ivas_error ivas_spar_md_enc_process(
if ( ndm != num_ch )
{
ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat_local, num_ch, ndm, b, dtx_vad, 1, planarCP );
ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat_local, num_ch, ndm, b, dtx_vad, 1, planarCP );
}
}
}
......@@ -721,39 +748,17 @@ ivas_error ivas_spar_md_enc_process(
}
else
{
float **ppPred_re, **ppPred_quant, *pPred_re, *pPred_quant;
int16_t **ppPred_idx, *pPred_re_idx;
if ( ndm != num_ch )
{
float *P_re[IVAS_SPAR_MAX_CH - 1], *P_re_quant[IVAS_SPAR_MAX_CH - 1];
float **ppP_re = (float **) &P_re[0];
float **ppP_re_quant = (float **) &P_re_quant[0];
int16_t *ppP_idx = &hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[0];
for ( i = 0; i < ndec; i++ )
{
ppP_re[i] = hMdEnc->spar_md.band_coeffs[b].P_re;
ppP_re_quant[i] = hMdEnc->spar_md.band_coeffs[b].P_quant_re;
ivas_quant_p_per_band_dtx( hMdEnc->spar_md.band_coeffs[b].P_re, ndec, ndm, &hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[0], hMdEnc->spar_md.band_coeffs[b].P_quant_re, num_ch );
}
ivas_quant_p_per_band_dtx( ppP_re, ndec, ndm, ppP_idx, ppP_re_quant, num_ch );
}
ppPred_idx = (int16_t **) &pPred_re_idx;
ppPred_re = (float **) &pPred_re;
ppPred_quant = (float **) &pPred_quant;
ppPred_re[0] = hMdEnc->spar_md.band_coeffs[b].pred_re;
ppPred_idx[0] = hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re;
ppPred_quant[0] = hMdEnc->spar_md.band_coeffs[b].pred_quant_re;
for ( i = 0; i < num_ch - 1; i++ )
{
hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0;
}
ivas_spar_quant_pred_coeffs_dtx( &hMdEnc->spar_md, ppPred_re, ndm, ppPred_idx, num_ch - 1, ppPred_quant );
ivas_spar_quant_pred_coeffs_dtx( &hMdEnc->spar_md, hMdEnc->spar_md.band_coeffs[b].pred_re, ndm, hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re, num_ch - 1, hMdEnc->spar_md.band_coeffs[b].pred_quant_re );
}
}
......@@ -765,6 +770,20 @@ ivas_error ivas_spar_md_enc_process(
}
}
if ( hMdEnc->spar_hoa_md_flag )
{
for ( b = SPAR_DIRAC_SPLIT_START_BAND; b < num_bands; b++ )
{
for ( i = 0; i < FOA_CHANNELS - 1; i++ )
{
/* Use the prediction coeffs computed based on DirAC MD to generate mixer matrix */
pred_coeffs_re[i][b] = pred_coeffs_re_local[i][b];
hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0;
hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] = 0;
}
}
}
ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, hMdEnc->mixer_mat, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg );
for ( b = 0; b < num_bands; b++ )
......@@ -779,7 +798,7 @@ ivas_error ivas_spar_md_enc_process(
if ( ( ndm != num_ch ) && ( ndm != 1 ) )
{
ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, planarCP );
ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, planarCP );
#ifdef SPAR_HOA_DBG
/*fprintf(stderr, "\n\n C coefficients: band %d\n", b);
......@@ -840,12 +859,7 @@ ivas_error ivas_spar_md_enc_process(
/* band mixing */
if ( bands_bw > 1 )
{
ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, pIn_buf->num_bands );
}
if ( hMdEnc->spar_md_cfg.gen_bs == 0 )
{
break;
ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full );
}
if ( dtx_vad == 0 )
......@@ -863,13 +877,14 @@ ivas_error ivas_spar_md_enc_process(
{
reset_indices_enc( &hMetaData_tmp, MAX_BITS_METADATA );
ivas_write_parameter_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, dtx_silence_mode, strat, qsi, planarCP );
ivas_write_spar_md_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi, planarCP );
if ( hMetaData->nb_bits_tot == bit_pos_start || hMetaData_tmp.nb_bits_tot < ( hMetaData->nb_bits_tot - bit_pos_start ) )
{
write_metadata_buffer( &hMetaData_tmp, hMetaData, bit_pos_start, next_ind_start, last_ind_start );
code_strat = strat;
}
if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == 1 ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.tgt_bits_per_blk )
if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.tgt_bits_per_blk )
{
packed_ok = 1;
break;
......@@ -882,7 +897,7 @@ ivas_error ivas_spar_md_enc_process(
break;
}
if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == 1 ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.max_bits_per_blk )
if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.max_bits_per_blk )
{
break;
}
......@@ -982,6 +997,8 @@ ivas_error ivas_spar_md_enc_process(
byte_size = sizeof( float );
for ( b = 0; b < nB; b++ )
{
ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw];
sprintf( f_name, "spar_band_pred_coeffs.bin" );
( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false;
num_elements = num_ch - 1;
......@@ -1058,17 +1075,14 @@ ivas_error ivas_spar_md_enc_process(
}
#endif
#ifdef DEBUG_SPAR_MD_TARGET_TUNING
int16_t md_bits = hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == 1 ) ) ? 1 : 0 );
int16_t md_bits = hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 );
FILE *fp = fopen( "spar_md_bitrate.txt", "a" );
fprintf( fp, "%d\t %d \t %d\n", md_bits, qsi, code_strat );
fclose( fp );
#endif
if ( hMdEnc->spar_md_cfg.gen_bs == 1 )
{
ivas_store_prior_coeffs( hMdEnc, num_bands, bands_bw, code_strat, dtx_vad, qsi );
}
hMdEnc->spar_md.dtx_vad = dtx_vad;
hMdEnc->spar_md.num_bands = num_bands;
......@@ -1084,7 +1098,7 @@ ivas_error ivas_spar_md_enc_process(
*-----------------------------------------------------------------------------------------*/
static void ivas_band_mixer(
float *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
const int16_t num_ch,
int16_t *num_bands,
int16_t red_band_fact )
......@@ -1105,18 +1119,18 @@ static void ivas_band_mixer(
avg_cov = 0.0f;
for ( b = 0; b < red_band_fact; b++ )
{
avg_cov += cov_re[i][j][red_band_fact * k + b];
avg_cov += cov_real[i][j][red_band_fact * k + b];
}
cov_re[i][j][k] = avg_cov;
cov_real[i][j][k] = avg_cov;
}
avg_cov = 0.0f;
for ( b = 0; b < red_band_fact + rem_band; b++ )
{
avg_cov += cov_re[i][j][red_band_fact * ( *num_bands - 1 ) + b];
avg_cov += cov_real[i][j][red_band_fact * ( *num_bands - 1 ) + b];
}
cov_re[i][j][*num_bands - 1] = avg_cov;
cov_real[i][j][*num_bands - 1] = avg_cov;
}
}
......@@ -1125,18 +1139,17 @@ static void ivas_band_mixer(
/*-----------------------------------------------------------------------------------------*
* Function ivas_write_parameter_bitstream()
* Function ivas_write_spar_md_bitstream()
*
* Write MD parameters into bitstream
*-----------------------------------------------------------------------------------------*/
static void ivas_write_parameter_bitstream(
static void ivas_write_spar_md_bitstream(
ivas_spar_md_enc_state_t *hMdEnc,
const int16_t nB,
const int16_t bands_bw,
BSTR_ENC_HANDLE hMetaData,
const int32_t ivas_total_brate,
const int16_t dtx_silence_mode,
const int16_t strat,
const int16_t qsi,
const int16_t planarCP )
......@@ -1150,7 +1163,7 @@ static void ivas_write_parameter_bitstream(
}
/* write quant strat */
if ( dtx_silence_mode == 0 && ivas_total_brate >= BRATE_SPAR_Q_STRAT )
if ( ivas_total_brate >= BRATE_SPAR_Q_STRAT )
{
push_next_indice( hMetaData, qsi >> 1, hMdEnc->spar_md_cfg.quant_strat_bits - 1 );
}
......@@ -1245,6 +1258,7 @@ static void ivas_get_huffman_coded_bs(
const int16_t planarCP )
{
int16_t i, j;
int16_t pred_coeff_dim, pred_offset;
for ( i = 0; i < nB; i++ )
{
......@@ -1252,9 +1266,19 @@ static void ivas_get_huffman_coded_bs(
int16_t ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i];
int16_t ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[i];
pred_coeff_dim = ndm + ndec - 1;
pred_offset = 0;
if ( hMdEnc->spar_hoa_md_flag )
{
if ( i >= SPAR_DIRAC_SPLIT_START_BAND )
{
pred_offset = FOA_CHANNELS - 1;
}
}
if ( planarCP )
{
for ( j = 0; j < ndm + ndec - 1; j++ )
for ( j = pred_offset; j < pred_coeff_dim; j++ )
{
ivas_huffman_encode( &hMdEnc->huff_coeffs.pred_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j], &code, &len );
push_next_indice( hMetaData, code, len );
......@@ -1280,7 +1304,7 @@ static void ivas_get_huffman_coded_bs(
}
else
{
for ( j = 0; j < ndm + ndec - 1; j++ )
for ( j = pred_offset; j < pred_coeff_dim; j++ )
{
ivas_huffman_encode( &hMdEnc->huff_coeffs.pred_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j], &code, &len );
push_next_indice( hMetaData, code, len );
......@@ -1319,7 +1343,7 @@ static void ivas_get_arith_coded_bs(
const int16_t qsi,
const int16_t planarCP )
{
int16_t i, any_diff;
int16_t i, j, any_diff;
ivas_cell_dim_t pred_cell_dims[IVAS_MAX_NUM_BANDS];
ivas_cell_dim_t drct_cell_dims[IVAS_MAX_NUM_BANDS];
ivas_cell_dim_t decd_cell_dims[IVAS_MAX_NUM_BANDS];
......@@ -1333,6 +1357,13 @@ static void ivas_get_arith_coded_bs(
ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i];
ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[bands_bw * i];
pred_cell_dims[i].dim1 = ndm + ndec - 1;
if ( hMdEnc->spar_hoa_md_flag )
{
if ( i >= SPAR_DIRAC_SPLIT_START_BAND )
{
pred_cell_dims[i].dim1 -= ( FOA_CHANNELS - 1 );
}
}
pred_cell_dims[i].dim2 = 1;
drct_cell_dims[i].dim1 = ndec;
drct_cell_dims[i].dim2 = ndm - 1;
......@@ -1351,17 +1382,55 @@ static void ivas_get_arith_coded_bs(
break;
}
}
if ( hMdEnc->spar_hoa_md_flag )
{
for ( i = 0; i < nB; i++ )
{
if ( i >= SPAR_DIRAC_SPLIT_START_BAND )
{
for ( j = 0; j < pred_cell_dims[i].dim1; j++ )
{
hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j] =
hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j + ( FOA_CHANNELS - 1 )];
if ( any_diff == 1 )
{
hMdEnc->spar_md_prior.band_coeffs_idx_mapped[i].pred_index_re[j] =
hMdEnc->spar_md_prior.band_coeffs_idx_mapped[i].pred_index_re[j + ( FOA_CHANNELS - 1 )];
}
}
}
}
}
ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, pred_cell_dims, PRED_COEFF, planarCP );
if ( any_diff == 1 )
{
ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB,
symbol_arr_old_re, pred_cell_dims, PRED_COEFF, planarCP );
ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, pred_cell_dims, PRED_COEFF, planarCP );
}
ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.pred_arith_re[qsi], &hMdEnc->arith_coeffs.pred_arith_re_diff[qsi], pDo_diff, nB,
symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff );
if ( hMdEnc->spar_hoa_md_flag )
{
for ( i = 0; i < nB; i++ )
{
if ( i >= SPAR_DIRAC_SPLIT_START_BAND )
{
for ( j = pred_cell_dims[i].dim1 - 1; j >= 0; j-- )
{
hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j + ( FOA_CHANNELS - 1 )] =
hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j];
}
for ( j = 0; j < FOA_CHANNELS - 1; j++ )
{
hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j] = 0;
}
}
}
}
#ifdef SPAR_HOA_DBG
/*fprintf(stderr, "\n\n band_indexes:\n");
for (int16_t j = 1; j < drct_cell_dims[0].dim1 * drct_cell_dims[0].dim2; j++)
......@@ -1390,8 +1459,7 @@ static void ivas_get_arith_coded_bs(
if ( any_diff == 1 )
{
ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB,
symbol_arr_old_re, decd_cell_dims, DECD_COEFF, planarCP );
ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, decd_cell_dims, DECD_COEFF, planarCP );
}
if ( planarCP )
......@@ -1405,13 +1473,11 @@ static void ivas_get_arith_coded_bs(
ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.decd_arith_re[qsi], &hMdEnc->arith_coeffs.decd_arith_re_diff[qsi], pDo_diff, nB,
symbol_arr_re, symbol_arr_old_re, decd_cell_dims, hMetaData, any_diff );
ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, decx_cell_dims, DECX_COEFF, planarCP );
if ( any_diff == 1 )
{
ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB,
symbol_arr_old_re, decx_cell_dims, DECX_COEFF, planarCP );
ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, nB, symbol_arr_old_re, decx_cell_dims, DECX_COEFF, planarCP );
}
return;
......@@ -1525,35 +1591,23 @@ static void ivas_store_prior_coeffs(
static void ivas_spar_quant_pred_coeffs_dtx(
ivas_spar_md_t *pSpar_md,
float **ppValues,
const float *pValues,
const int16_t ndm,
int16_t **ppIndex,
int16_t *pIndex,
const int16_t dim1,
float **ppQuant )
float *pQuant )
{
int16_t i;
int16_t q_lvl;
float *pVal, val, **ppVal;
int16_t *pIdx, idx, **ppIdx;
float pr_min_max[2];
ppVal = (float **) &pVal;
ppIdx = (int16_t **) &pIdx;
ppVal[0] = (float *) &val;
ppIdx[0] = (int16_t *) &idx;
pr_min_max[0] = pSpar_md->min_max[0];
pr_min_max[1] = pSpar_md->min_max[1];
for ( i = 0; i < dim1; i++ )
{
q_lvl = dtx_pr_real_q_levels[ndm - 1][i];
ppVal[0][0] = ppValues[0][i];
ivas_quantise_real_values( ppVal, q_lvl, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 );
ppIndex[0][i] = ppIdx[0][0];
ppQuant[0][i] = ppVal[0][0];
ivas_quantise_real_values( &pValues[i], q_lvl, pr_min_max[0], pr_min_max[1], &pIndex[i], &pQuant[i], 1 );
}
return;
......@@ -1567,30 +1621,23 @@ static void ivas_spar_quant_pred_coeffs_dtx(
*-----------------------------------------------------------------------------------------*/
static void ivas_quant_p_per_band_dtx(
float **ppP_mat,
float *pP_mat,
const int16_t num_dec,
const int16_t num_dmx,
int16_t *ppIdx_pd,
float **ppP_out,
float *pP_out,
const int16_t num_ch )
{
int16_t i;
float **ppPd, *pPd, pd;
int16_t **ppIdx, *pIdx, idx;
int16_t dim = num_ch - num_dmx;
ppPd = (float **) &pPd;
ppIdx = (int16_t **) &pIdx;
ppPd[0] = (float *) &pd;
ppIdx[0] = (int16_t *) &idx;
if ( num_dec == num_ch - 1 )
{
for ( i = 0; i < dim; i++ )
{
if ( ppP_mat[i][i] < pr_boost_range[1] && ppP_mat[i][i] > pr_boost_range[0] )
if ( pP_mat[i] < pr_boost_range[1] && pP_mat[i] > pr_boost_range[0] )
{
ppP_mat[i][i] = pr_boost_range[1];
pP_mat[i] = pr_boost_range[1];
}
}
}
......@@ -1602,18 +1649,12 @@ static void ivas_quant_p_per_band_dtx(
for ( i = 0; i < dim; i++ )
{
ppPd[0][0] = ppP_mat[i][i];
ivas_quantise_real_values( ppPd, dtx_pd_real_q_levels[num_ch - num_dec - 1][i], dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], ppIdx, ppPd, 1, 1 );
ppP_out[i][i] = ppPd[0][0];
ppIdx_pd[i] = ppIdx[0][0];
ivas_quantise_real_values( &pP_mat[i], dtx_pd_real_q_levels[num_ch - num_dec - 1][i], dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &ppIdx_pd[i], &pP_out[i], 1 );
}
return;
}
/*-----------------------------------------------------------------------------------------*
* Function ivas_write_parameter_bitstream_dtx()
*
......@@ -1628,18 +1669,11 @@ static void ivas_write_parameter_bitstream_dtx(
const int16_t num_bands )
{
int16_t i, j;
float **ppVal, *pVal, val;
int16_t **ppIdx, *pIdx, idx;
float val;
int16_t idx;
float pr_min_max[2];
int16_t zero_pad_bits, sid_bits_len;
sid_bits_len = hMetaData->nb_bits_tot;
ppVal = (float **) &pVal;
ppIdx = (int16_t **) &pIdx;
ppVal[0] = (float *) &val;
ppIdx[0] = (int16_t *) &idx;
pr_min_max[0] = pSpar_md->min_max[0];
pr_min_max[1] = pSpar_md->min_max[1];
......@@ -1677,17 +1711,15 @@ static void ivas_write_parameter_bitstream_dtx(
pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1];
pd = pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1];
}
val = dtx_pd_real_min_max[0];
ivas_quantise_real_values( &val, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &idx, &val, 1 );
ppVal[0][0] = dtx_pd_real_min_max[0];
ivas_quantise_real_values( ppVal, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], ppIdx, ppVal, 1, 1 );
pd -= ppIdx[0][0];
pd -= idx;
ppVal[0][0] = pr_min_max[0];
ivas_quantise_real_values( ppVal, pr_q_lvls, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 );
pr -= ppIdx[0][0];
val = pr_min_max[0];
ivas_quantise_real_values( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 );
pr -= idx;
pr_pd_bits = ivas_get_bits_to_encode( pd_q_lvls * pr_q_lvls );
value = (uint16_t) ( pr * pd_q_lvls + pd );
......@@ -1698,23 +1730,22 @@ static void ivas_write_parameter_bitstream_dtx(
{
int16_t pr_q_lvls1, pr_q_lvls2;
int16_t pr_idx1, pr_idx2, pr_pr_bits;
pr_q_lvls1 = dtx_pr_real_q_levels[ndm - 1][pr_idx_1 - 1];
pr_q_lvls2 = dtx_pr_real_q_levels[ndm - 1][pr_idx_2 - 1];
ppVal[0][0] = pr_min_max[0];
ivas_quantise_real_values( ppVal, pr_q_lvls1, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 );
val = pr_min_max[0];
ivas_quantise_real_values( &val, pr_q_lvls1, pr_min_max[0], pr_min_max[1], &idx, &val, 1 );
pr_idx1 = pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_1 - 1];
pr_idx1 -= ppIdx[0][0];
pr_idx1 -= idx;
ppVal[0][0] = pr_min_max[0];
ivas_quantise_real_values( ppVal, pr_q_lvls2, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 );
val = pr_min_max[0];
ivas_quantise_real_values( &val, pr_q_lvls2, pr_min_max[0], pr_min_max[1], &idx, &val, 1 );
pr_idx2 = pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_2 - 1];
pr_idx2 -= ppIdx[0][0];
pr_idx2 -= idx;
value = (uint16_t) ( pr_idx2 * pr_q_lvls1 + pr_idx1 );
pr_pr_bits = ivas_get_bits_to_encode( pr_q_lvls1 * pr_q_lvls2 );
......@@ -1751,17 +1782,7 @@ static void ivas_quant_pred_coeffs_per_band(
ivas_quant_strat_t *pQs,
const int16_t num_ch )
{
float *pQuant_re, *pCoeff_re;
int16_t *pIdx_re;
float **ppPred_coeffs_re = (float **) &pCoeff_re;
float **ppPred_quant_re = (float **) &pQuant_re;
int16_t **ppPred_idx_re = (int16_t **) &pIdx_re;
ppPred_idx_re[0] = &pBand_coeffs_idx->pred_index_re[0];
ppPred_coeffs_re[0] = &pband_coeffs->pred_re[0];
ppPred_quant_re[0] = &pband_coeffs->pred_quant_re[0];
ivas_quantise_real_values( ppPred_coeffs_re, pQs->PR.q_levels[0], pQs->PR.min, pQs->PR.max, ppPred_idx_re, ppPred_quant_re, 1, ( num_ch - 1 ) );
ivas_quantise_real_values( pband_coeffs->pred_re, pQs->PR.q_levels[0], pQs->PR.min, pQs->PR.max, pBand_coeffs_idx->pred_index_re, pband_coeffs->pred_quant_re, ( num_ch - 1 ) );
return;
}
......@@ -1783,17 +1804,6 @@ static void ivas_quant_c_per_band(
int16_t i;
int16_t j, k;
float C_re[IVAS_SPAR_MAX_C_COEFF];
float *pC_re[IVAS_SPAR_MAX_C_COEFF];
int16_t *pIdx_re[IVAS_SPAR_MAX_C_COEFF];
float **ppC_re = (float **) &pC_re[0];
int16_t **ppIdx_re = (int16_t **) &pIdx_re[0];
for ( i = 0; i < ndec * ( ndm - 1 ); i++ )
{
ppC_re[i] = &C_re[i];
ppIdx_re[i] = &pBand_coeffs_idx->drct_index_re[i];
}
k = 0;
for ( i = 0; i < ndec; i++ )
{
......@@ -1803,7 +1813,6 @@ static void ivas_quant_c_per_band(
k++;
}
}
#ifdef SPAR_HOA_DBG
/*for (i = 0; i < ndec; i++)
{
......@@ -1813,9 +1822,7 @@ static void ivas_quant_c_per_band(
}
}*/
#endif
ivas_quantise_real_values( ppC_re, pQs->C.q_levels[0], pQs->C.min, pQs->C.max, ppIdx_re, ppC_re, ndec * ( ndm - 1 ), 1 );
ivas_quantise_real_values( C_re, pQs->C.q_levels[0], pQs->C.min, pQs->C.max, pBand_coeffs_idx->drct_index_re, C_re, ndec * ( ndm - 1 ) );
k = 0;
for ( i = 0; i < ndec; i++ )
{
......@@ -1854,25 +1861,6 @@ static void ivas_quant_p_per_band(
ivas_quant_strat_t *pQs,
const int16_t num_ch )
{
float P_re_diag[IVAS_SPAR_MAX_CH - 1];
int16_t i;
int16_t dim = num_ch - 1;
float *pP_diag[IVAS_SPAR_MAX_CH - 1];
int16_t *pDecd_idx[IVAS_SPAR_MAX_CH - 1];
float **ppP_diag = (float **) &pP_diag[0];
int16_t **ppDecd_idx = (int16_t **) &pDecd_idx[0];
for ( i = 0; i < dim; i++ )
{
ppP_diag[i] = &P_re_diag[i];
ppDecd_idx[i] = &pBand_coeffs_idx->decd_index_re[i];
}
for ( i = 0; i < dim; i++ )
{
P_re_diag[i] = pband_coeffs->P_re[i];
}
#ifdef SPAR_HOA_DBG
/*fprintf(stderr, "\n\n P_d:\n");
for (i = 0; i < dim; i++)
......@@ -1881,13 +1869,7 @@ static void ivas_quant_p_per_band(
}
fprintf(stderr, "\n\n");*/
#endif
ivas_quantise_real_values( ppP_diag, pQs->P_r.q_levels[0], pQs->P_r.min, pQs->P_r.max, ppDecd_idx, ppP_diag, num_ch - 1, 1 );
for ( i = 0; i < dim; i++ )
{
pband_coeffs->P_quant_re[i] = P_re_diag[i];
}
ivas_quantise_real_values( pband_coeffs->P_re, pQs->P_r.q_levels[0], pQs->P_r.min, pQs->P_r.max, pBand_coeffs_idx->decd_index_re, pband_coeffs->P_quant_re, num_ch - 1 );
return;
}
......@@ -41,7 +41,6 @@
#include "ivas_cnst.h"
#include "ivas_stat_com.h"
/*----------------------------------------------------------------------------------*
* DFT Stereo encoder structures
*----------------------------------------------------------------------------------*/
......@@ -278,6 +277,7 @@ typedef struct stereo_dft_enc_data_struct
int16_t flip_sign;
#ifdef DEBUG_MODE_DFT
int16_t verbose;
int16_t res_cod_bits;
#endif
} STEREO_DFT_ENC_DATA, *STEREO_DFT_ENC_DATA_HANDLE;
......@@ -571,7 +571,7 @@ typedef struct ivas_dirac_enc_data_structure
PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM handle */
IVAS_FB_MIXER_HANDLE hFbMixer;
float *sba_synchro_buffer[IVAS_MAX_NUM_CH]; // VE: all 16 buffers not needed ?
float *sba_synchro_buffer[DIRAC_MAX_ANA_CHANS];
int16_t num_samples_synchro_delay;
/* DirAC parameter estimation */
......@@ -628,15 +628,6 @@ typedef struct ivas_enc_cov_handler_state_t
} ivas_enc_cov_handler_state_t;
typedef struct ivas_enc_cov_handler_in_buf_t
{
float *ppIn_FR_real[IVAS_SPAR_MAX_CH];
float *ppIn_FR_imag[IVAS_SPAR_MAX_CH];
int16_t num_ch;
int16_t transient_det;
int16_t dtx_cov_flag;
} ivas_enc_cov_handler_in_buf_t;
/* SPAR MD structures */
typedef struct ivas_spar_md_enc_state_t
......@@ -654,17 +645,9 @@ typedef struct ivas_spar_md_enc_state_t
ivas_arith_coeffs_t arith_coeffs;
ivas_huff_coeffs_t huff_coeffs;
int16_t table_idx;
int16_t spar_hoa_md_flag;
} ivas_spar_md_enc_state_t;
typedef struct ivas_spar_md_enc_in_buf_t
{
float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
int16_t num_bands;
int16_t dtx_vad;
} ivas_spar_md_enc_in_buf_t;
/* PCA structure */
typedef struct
{
......@@ -688,6 +671,7 @@ typedef struct ivas_spar_enc_lib_t
ivas_agc_enc_state_t *hAgcEnc;
int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS];
int16_t enc_param_start_band;
int16_t AGC_Enable;
PCA_ENC_STATE *hPCA;
int32_t core_nominal_brate; /* Nominal bitrate for core coding */
FRONT_VAD_ENC_HANDLE hFrontVad; /* front-VAD handle */
......@@ -841,6 +825,7 @@ typedef struct sce_enc_data_structure
{
int16_t sce_id; /* SCE # identifier */
int32_t element_brate; /* SCE element total bitrate in bps */
int32_t last_element_brate; /* last SCE element bitrate in bps */
BSTR_ENC_HANDLE hMetaData; /* Metadata bitstream handle */
......@@ -1014,7 +999,6 @@ typedef struct encoder_config_structure
int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */
/* temp. development parameters */
int16_t Opt_AGC_ON; /* flag indicating AGC operation in SBA */
int16_t Opt_PCA_ON; /* flag indicating PCA operation in SBA */
#ifdef DEBUGGING
......@@ -1022,6 +1006,9 @@ typedef struct encoder_config_structure
int16_t stereo_mode_cmdl; /* stereo mode forced from the command-line */
int16_t force; /* parameter to force specific "core" of the Core-Coder*/
int16_t mdct_stereo_mode_cmdl; /* mdct stereo mode forced from command-line, employed only when DEBUG_FORCE_MDCT_STEREO_MODE is activated */
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
int16_t Opt_AGC_ON; /* flag indicating AGC operation in SBA */
#endif
#endif
......
......@@ -148,7 +148,8 @@ void stereo_dft_enc_sid_coh(
int16_t alpha_level;
int16_t n;
nr_of_sid_stereo_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS;
/* TODO: still use old number of bits to keep bitexactness in output */
nr_of_sid_stereo_bits = ( 4400 /*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS;
zeropad = 0;
/* Encode coherence vector. Find best fixed predictor by minimizing prediction error on input vector.
......@@ -303,6 +304,8 @@ void stereo_dft_enc_sid_coh(
( *nb_bits )++;
}
push_next_indice( hBstr, zeropad, ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC );
return;
}
......
......@@ -1643,9 +1643,11 @@ void stereo_dft_enc_process(
sum_nrg_R2 += pDFT_R[2 * j] * pDFT_R[2 * j] + pDFT_R[2 * j + 1] * pDFT_R[2 * j + 1];
dot_prod_real2 += pDFT_L[2 * j] * pDFT_R[2 * j] + pDFT_L[2 * j + 1] * pDFT_R[2 * j + 1];
}
sum_nrg_Mid = max( 0.f, sum_nrg_L2 + sum_nrg_R2 + 2.f * dot_prod_real2 );
wL = 0.5f * max( sqrtf( sum_nrg_L2 ) + sqrtf( sum_nrg_R2 ) - sqrtf( sum_nrg_Mid ), 0 ) / sqrtf( sum_nrg_L2 + EPSILON );
wL = 0.5f * max( sqrtf( sum_nrg_L2 ) + sqrtf( sum_nrg_R2 ) - sqrtf( sum_nrg_Mid ), 0 ) * inv_sqrt( sum_nrg_L2 + EPSILON );
wS = 1;
if ( hStereoDft->res_cod_sw_flag )
{
wL *= ( 1 - hStereoDft->switch_fade_factor );
......@@ -2317,7 +2319,7 @@ void stereo_dft_enc_write_BS(
{
stereo_dft_enc_sid_calc_coh( hStereoDft, hCPE->hStereoCng->coh_crossfade, &hCPE->hStereoCng->td_active, &hCPE->hStereoCng->first_SID, cohBand );
if ( *nb_bits <= ( ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_ITD_MODE_NBITS - STEREO_DFT_SID_ITD_NBITS - 1 ) )
if ( *nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_ITD_MODE_NBITS - STEREO_DFT_SID_ITD_NBITS - 1 ) )
{
if ( hStereoDft->hItd->itd[k_offset] != 0 )
{
......@@ -2393,7 +2395,7 @@ void stereo_dft_enc_write_BS(
nb += STEREO_DFT_GIPD_NBITS;
}
}
else if ( *nb_bits <= ( ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS ) )
else if ( *nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS ) )
{
push_indice( hBstr, IND_STEREO_DFT_NO_IPD_FLAG, hStereoDft->no_ipd_flag, STEREO_DFT_FLAG_BITS );
nb += STEREO_DFT_FLAG_BITS; /*IPD mode flag: 1bit*/
......
......@@ -345,7 +345,7 @@ static void utilCrossCorr(
temp = sum2_f( tempBuf1, len );
temp *= sum2_f( tempBuf2, len );
scale = ( temp == 0 ) ? 1.0f : 1.0f / sqrtf( temp );
scale = ( temp == 0 ) ? 1.0f : inv_sqrt( temp );
/* starting point of lag search range should be less than the ending point */
assert( lagSearchRange[0] <= lagSearchRange[1] );
......
......@@ -129,6 +129,7 @@ void stereo_mdct_core_enc(
float *p_orig_spectrum_long[CPE_CHANNELS], orig_spectrum_long[CPE_CHANNELS][N_MAX]; /* MDCT output (L/R). */
float *orig_spectrum[CPE_CHANNELS][2]; /* Pointers to MDCT output for a short block (L/R) */
float powerSpec[CPE_CHANNELS][N_MAX];
float *p_powerSpec[CPE_CHANNELS];
float powerSpecMsInv_long[CPE_CHANNELS][N_MAX]; /* MS inv power spectrum, also inverse MDST spectrum */
float *powerSpecMsInv[CPE_CHANNELS][2];
float quantized_spectrum_long[CPE_CHANNELS][N_MAX]; /* quantized MDCT spectrum, inv ms mask mdst spectrum, scratch for MS spectra in the MS decision */
......@@ -351,7 +352,9 @@ void stereo_mdct_core_enc(
hStereoMdct->mdct_stereo_mode[n] == SMDCT_BW_MS ) &&
!hStereoMdct->isSBAStereoMode )
{
ProcessStereoIGF( hStereoMdct, sts, ms_mask, orig_spectrum, powerSpec, powerSpecMsInv, inv_spectrum, n, hCPE->hCoreCoder[0]->sp_aud_decision0, hCPE->hCoreCoder[0]->element_brate, 0 );
p_powerSpec[0] = powerSpec[0];
p_powerSpec[1] = powerSpec[1];
ProcessStereoIGF( hStereoMdct, sts, ms_mask, orig_spectrum, p_powerSpec, powerSpecMsInv, inv_spectrum, n, hCPE->hCoreCoder[0]->sp_aud_decision0, hCPE->hCoreCoder[0]->element_brate, 0 );
}
else
{
......
......@@ -268,11 +268,7 @@ void stereo_tcx_core_enc(
*--------------------------------------------------------------------------------*/
/* TCX20/TCX10 and coder type */
#ifdef FIX_IVAS_185_MDCT_ST_PLC_FADEOUT
writeTCXMode( st, hBstr, 0, /* <- is_mct */ &nbits_start );
#else
writeTCXMode( st, hBstr, &nbits_start );
#endif
writeTCXMode( st, hBstr, 0, /* MCT_flag */ &nbits_start );
/* write last_core for error concealment */
push_next_indice( hBstr, ( st->last_core != ACELP_CORE || st->core == TCX_10_CORE ), 1 );
......@@ -684,7 +680,7 @@ int16_t ivas_acelp_tcx20_switching(
for ( i = 0; i < L_frame; i++ )
{
x[i] *= (float) L_frame / sqrtf( 2 * NORM_MDCT_FACTOR );
x[i] *= (float) L_frame * inv_sqrt( 2 * NORM_MDCT_FACTOR );
y[i] = x[i];
}
......
......@@ -63,6 +63,7 @@ struct IVAS_ENC
int16_t rf_fec_offset_loc;
bool ismMetadataProvided[MAX_NUM_OBJECTS];
bool maxBandwidthUser; /* Was a specific max bandwith selected by the user? */
IVAS_ENC_BANDWIDTH newBandwidthApi; /* maximum encoded bandwidth, as set on API level */
};
/*---------------------------------------------------------------------*
......@@ -76,10 +77,14 @@ static ivas_error setChannelAwareConfig( IVAS_ENC_HANDLE hIvasEnc, const IVAS_EN
static int16_t getInputBufferSize( const Encoder_Struct *st_ivas );
static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc );
static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc );
static void updateBandwidthFromFs( const ENCODER_CONFIG_HANDLE hEncoderConfig );
static ivas_error sanitizeBandwidth( const IVAS_ENC_HANDLE hIvasEnc );
static ivas_error sanitizeBitrateISM( const ENCODER_CONFIG_HANDLE hEncoderConfig );
static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig );
static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc );
static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, int16_t *internalMaxBandwidth );
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
static ivas_error agcAPIToInternal( const IVAS_ENC_AGC agcOption, int16_t *internalAGCOption );
#endif
static ivas_error fecIndicatorApiToInternal( const IVAS_ENC_FEC_INDICATOR fecIndicator, int16_t *fecIndicatorInternal );
#ifdef DEBUGGING
static ivas_error forcedModeApiToInternal( IVAS_ENC_FORCED_MODE forcedMode, int16_t *forcedModeInternal );
......@@ -171,14 +176,8 @@ ivas_error IVAS_ENC_Open(
/* initialize encoder Config. handle */
init_encoder_config( st_ivas->hEncoderConfig );
#ifdef FIX_I98_HANDLES_TO_NULL
/* initialize pointers to handles to NULL */
ivas_initialize_handles_enc( st_ivas );
#else
st_ivas->hEncoderConfig->ivas_total_brate = ACELP_12k65;
st_ivas->hEncoderConfig->Opt_SC_VBR = 0;
st_ivas->hEncoderConfig->last_Opt_SC_VBR = 0;
#endif
/* set high-level parameters */
st_ivas->mc_mode = MC_MODE_NONE;
......@@ -379,7 +378,11 @@ ivas_error IVAS_ENC_ConfigureForObjects(
if ( numObjects > MAX_NUM_OBJECTS )
{
#ifdef EXT_RENDERER
return IVAS_ERR_TOO_MANY_INPUTS;
#else
return IVAS_ERR_TOO_MANY_OBJECT_INPUTS;
#endif
}
st_ivas = hIvasEnc->st_ivas;
......@@ -453,7 +456,9 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics(
const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */
const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */
const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */
const bool Opt_AGC_ON, /* i : AGC on/off flag */
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
const IVAS_ENC_AGC Opt_AGC_ON, /* i : AGC on/off/undefined flag */
#endif
const bool Opt_PCA_ON /* i : PCA option flag */
#ifdef DEBUG_SBA_AUDIO_DUMP
,
......@@ -475,9 +480,17 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics(
hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */
hEncoderConfig->sba_planar = isPlanar;
hEncoderConfig->sba_order = order;
/* Input in ACN/SN3D in all cases (3D and planar): get number of channels */
hEncoderConfig->nchan_inp = ivas_sba_get_nchan( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/
hEncoderConfig->Opt_AGC_ON = (int16_t) Opt_AGC_ON;
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
if ( ( error = agcAPIToInternal( Opt_AGC_ON, &( hEncoderConfig->Opt_AGC_ON ) ) ) != IVAS_ERR_OK )
{
return error;
}
#endif
hEncoderConfig->Opt_PCA_ON = (int16_t) Opt_PCA_ON;
hIvasEnc->maxBandwidthUser = max_bwidth_user;
......@@ -766,21 +779,9 @@ static ivas_error configureEncoder(
}
else if ( hEncoderConfig->ivas_format == ISM_FORMAT )
{
if ( hEncoderConfig->ivas_total_brate > IVAS_256k )
{
return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
}
if ( hEncoderConfig->ivas_total_brate < IVAS_16k4 && hEncoderConfig->nchan_inp == 2 )
{
return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
}
if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 3 )
{
return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
}
if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 4 )
if ( ( error = sanitizeBitrateISM( hEncoderConfig ) ) != IVAS_ERR_OK )
{
return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
return error;
}
}
else if ( hEncoderConfig->ivas_format == SBA_FORMAT )
......@@ -830,8 +831,6 @@ static ivas_error configureEncoder(
hEncoderConfig->input_Fs = inputFs;
updateBandwidthFromFs( hEncoderConfig );
/*-----------------------------------------------------------------*
* Channel-aware mode
*-----------------------------------------------------------------*/
......@@ -896,16 +895,23 @@ static ivas_error configureEncoder(
return IVAS_ERROR( IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode." );
}
if ( hEncoderConfig->Opt_AGC_ON && !( hEncoderConfig->ivas_format == SBA_FORMAT && ivas_sba_mode_select( hEncoderConfig->ivas_total_brate ) == SBA_MODE_SPAR ) )
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
if ( hEncoderConfig->Opt_AGC_ON == SBA_AGC_FORCE_ENABLE && !( hEncoderConfig->ivas_format == SBA_FORMAT && ivas_sba_mode_select( hEncoderConfig->ivas_total_brate ) == SBA_MODE_SPAR ) )
{
return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "AGC supported in SBA format at bitrates >= 24.4 kbps only." );
}
#endif
if ( hEncoderConfig->Opt_PCA_ON && !( hEncoderConfig->ivas_format == SBA_FORMAT && hEncoderConfig->ivas_total_brate == PCA_BRATE && hEncoderConfig->sba_order == 1 ) )
if ( hEncoderConfig->Opt_PCA_ON && !( hEncoderConfig->ivas_format == SBA_FORMAT && hEncoderConfig->ivas_total_brate == PCA_BRATE && hEncoderConfig->sba_order == SBA_FOA_ORDER ) )
{
return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." );
}
if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK )
{
return error;
}
/*-----------------------------------------------------------------*
* Finalize initialization
*-----------------------------------------------------------------*/
......@@ -1050,6 +1056,11 @@ ivas_error IVAS_ENC_EncodeFrameToSerial(
return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE;
}
if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK )
{
return error;
}
if ( hEncoderConfig->ivas_format == ISM_FORMAT )
{
for ( i = 0; i < hEncoderConfig->nchan_inp; ++i )
......@@ -1370,7 +1381,11 @@ const char *IVAS_ENC_GetErrorMessage(
return "invalid bitrate";
case IVAS_ERR_INVALID_MASA_CONFIG:
return "invalid MASA config";
#ifdef EXT_RENDERER
case IVAS_ERR_TOO_MANY_INPUTS:
#else
case IVAS_ERR_TOO_MANY_OBJECT_INPUTS:
#endif
return "too many object inputs provided";
case IVAS_ERR_INDEX_OUT_OF_BOUNDS:
return "index out of bounds";
......@@ -1422,7 +1437,8 @@ static ivas_error printConfigInfo_enc(
{
Encoder_Struct *st_ivas;
ENCODER_CONFIG_HANDLE hEncoderConfig;
char max_bwidth_string[4];
int16_t newBandwidthApi;
ivas_error error;
st_ivas = hIvasEnc->st_ivas;
hEncoderConfig = st_ivas->hEncoderConfig;
......@@ -1504,15 +1520,33 @@ static ivas_error printConfigInfo_enc(
}
else if ( hEncoderConfig->ivas_format == SBA_FORMAT )
{
#ifdef PRINT_SBA_ORDER
fprintf( stdout, "IVAS format: Scene Based Audio, Ambisonic order %i %s ", hEncoderConfig->sba_order, hEncoderConfig->sba_planar ? "(Planar)" : "" );
#else
fprintf( stdout, "IVAS format: Scene Based Analysis %s ", hEncoderConfig->sba_planar ? "(Planar)" : "" );
#endif
if ( hEncoderConfig->Opt_PCA_ON )
{
fprintf( stdout, "- PCA configured with signal adaptive decision " );
}
if ( hEncoderConfig->Opt_AGC_ON )
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
switch ( hEncoderConfig->Opt_AGC_ON )
{
fprintf( stdout, "- AGC ON " );
case SBA_AGC_FORCE_ENABLE:
fprintf( stdout, "- AGC FORCED ON " );
break;
case SBA_AGC_FORCE_DISABLE:
fprintf( stdout, "- AGC FORCED OFF " );
break;
case SBA_AGC_DEFAULT:
fprintf( stdout, "- AGC default mode " );
break;
default:
fprintf( stdout, "- AGC unknown " );
break;
}
#endif
fprintf( stdout, "\n" );
}
else if ( hEncoderConfig->ivas_format == MASA_FORMAT )
......@@ -1563,20 +1597,9 @@ static ivas_error printConfigInfo_enc(
* Print potential limitation of audio bandwidth
*-----------------------------------------------------------------*/
switch ( hEncoderConfig->max_bwidth )
if ( ( error = bandwidthApiToInternal( hIvasEnc->newBandwidthApi, &newBandwidthApi ) ) != IVAS_ERR_OK )
{
case NB:
strncpy( max_bwidth_string, "NB\0", sizeof( max_bwidth_string ) );
break;
case WB:
strncpy( max_bwidth_string, "WB\0", sizeof( max_bwidth_string ) );
break;
case SWB:
strncpy( max_bwidth_string, "SWB\0", sizeof( max_bwidth_string ) );
break;
case FB:
strncpy( max_bwidth_string, "FB\0", sizeof( max_bwidth_string ) );
break;
return error;
}
if ( st_ivas->hEncoderConfig->Opt_SC_VBR && !hEncoderConfig->Opt_DTX_ON )
......@@ -1584,17 +1607,14 @@ static ivas_error printConfigInfo_enc(
return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "\nError: SC-VBR 5900 bps not supported without DTX\n\n" );
}
if ( hIvasEnc->maxBandwidthUser )
{
fprintf( stdout, "\nBandwidth limited to %s.\n", max_bwidth_string );
}
if ( hEncoderConfig->ivas_format == MONO_FORMAT )
{
if ( hEncoderConfig->max_bwidth == FB && hEncoderConfig->ivas_total_brate < ACELP_16k40 )
if ( newBandwidthApi != hEncoderConfig->max_bwidth )
{
if ( newBandwidthApi == FB )
{
fprintf( stdout, "\nFB coding not supported below %.2f kbps. ", ACELP_16k40 / 1000.f );
if ( hEncoderConfig->ivas_total_brate < ACELP_9k60 )
if ( hEncoderConfig->max_bwidth == WB )
{
fprintf( stdout, "Switching to WB.\n" );
}
......@@ -1603,14 +1623,14 @@ static ivas_error printConfigInfo_enc(
fprintf( stdout, "Switching to SWB.\n" );
}
}
if ( hEncoderConfig->max_bwidth == SWB && hEncoderConfig->ivas_total_brate < ACELP_9k60 )
else if ( newBandwidthApi == SWB )
{
fprintf( stdout, "\nSWB coding not supported below %.2f kbps. Switching to WB.", ACELP_9k60 / 1000.f );
fprintf( stdout, "\nSWB coding not supported below %.2f kbps. Switching to WB.\n", ACELP_9k60 / 1000.f );
}
}
/* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */
if ( ( hEncoderConfig->max_bwidth == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 )
if ( ( newBandwidthApi == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 )
{
fprintf( stdout, "\nError: Unsupported mode NB %d bps, NB mode supports rates 5900-24400 bps\n\n", hEncoderConfig->ivas_total_brate );
return IVAS_ERR_INVALID_BITRATE;
......@@ -1618,7 +1638,7 @@ static ivas_error printConfigInfo_enc(
}
else
{
if ( hEncoderConfig->max_bwidth == FB && hEncoderConfig->ivas_total_brate < MIN_BRATE_FB_STEREO )
if ( newBandwidthApi != hEncoderConfig->max_bwidth )
{
fprintf( stdout, "\nFB coding not supported below %.2f kbps. Switching to SWB.\n", MIN_BRATE_FB_STEREO / 1000.f );
}
......@@ -1652,6 +1672,7 @@ static ivas_error setBitrate(
{
Encoder_Struct *st_ivas;
ENCODER_CONFIG_HANDLE hEncoderConfig;
ivas_error error;
st_ivas = hIvasEnc->st_ivas;
hEncoderConfig = st_ivas->hEncoderConfig;
......@@ -1698,6 +1719,14 @@ static ivas_error setBitrate(
}
}
if ( hEncoderConfig->ivas_format == ISM_FORMAT )
{
if ( ( error = sanitizeBitrateISM( hEncoderConfig ) ) != IVAS_ERR_OK )
{
return error;
}
}
st_ivas->codec_mode = MODE1;
if ( hEncoderConfig->element_mode_init == EVS_MONO )
......@@ -1830,29 +1859,130 @@ static ivas_error doCommonSetterChecks(
/*---------------------------------------------------------------------*
* updateBandwidthFromFs()
* sanitizeBandwidth()
*
*
*---------------------------------------------------------------------*/
static void updateBandwidthFromFs(
const ENCODER_CONFIG_HANDLE hEncoderConfig )
static ivas_error sanitizeBandwidth(
const IVAS_ENC_HANDLE hIvasEnc )
{
ENCODER_CONFIG_HANDLE hEncoderConfig;
int16_t max_bwidth_tmp;
hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig;
max_bwidth_tmp = hIvasEnc->newBandwidthApi;
/* Prevent st_ivas->max_bwidth from being higher than Fs/2 */
if ( hEncoderConfig->input_Fs == 8000 && hEncoderConfig->max_bwidth > NB )
if ( hEncoderConfig->input_Fs == 8000 && max_bwidth_tmp > NB )
{
hEncoderConfig->max_bwidth = NB;
max_bwidth_tmp = NB;
}
else if ( hEncoderConfig->input_Fs == 16000 && hEncoderConfig->max_bwidth > WB )
else if ( hEncoderConfig->input_Fs == 16000 && max_bwidth_tmp > WB )
{
hEncoderConfig->max_bwidth = WB;
max_bwidth_tmp = WB;
}
else if ( hEncoderConfig->input_Fs == 32000 && hEncoderConfig->max_bwidth > SWB )
else if ( hEncoderConfig->input_Fs == 32000 && max_bwidth_tmp > SWB )
{
hEncoderConfig->max_bwidth = SWB;
max_bwidth_tmp = SWB;
}
return;
/* NB coding not supported in IVAS. Switching to WB. */
if ( max_bwidth_tmp == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT )
{
if ( hEncoderConfig->input_Fs >= 16000 )
{
max_bwidth_tmp = WB;
}
else
{
return IVAS_ERR_INVALID_BITRATE;
}
}
if ( hEncoderConfig->ivas_format == MONO_FORMAT )
{
#if 0 // IVAS_fmToDo: temporary disabled to keep EVS bit-exactness -> to be verified
if ( max_bwidth_tmp == FB && hEncoderConfig->ivas_total_brate < ACELP_16k40 )
{
if ( hEncoderConfig->ivas_total_brate < ACELP_9k60 )
{
max_bwidth_tmp = WB;
}
else
{
max_bwidth_tmp = SWB;
}
}
if ( max_bwidth_tmp == SWB && hEncoderConfig->ivas_total_brate < ACELP_9k60 )
{
max_bwidth_tmp = WB;
}
/* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */
if ( ( max_bwidth_tmp == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 )
{
if ( hEncoderConfig->input_Fs >= 16000 )
{
max_bwidth_tmp = WB;
}
else
{
return IVAS_ERR_INVALID_BITRATE;
}
}
#endif
}
else
{
if ( max_bwidth_tmp == FB && hEncoderConfig->ivas_total_brate < MIN_BRATE_FB_STEREO )
{
max_bwidth_tmp = SWB;
}
}
if ( hEncoderConfig->max_bwidth != max_bwidth_tmp )
{
hEncoderConfig->max_bwidth = max_bwidth_tmp;
hIvasEnc->switchingActive = true;
}
return IVAS_ERR_OK;
}
/*---------------------------------------------------------------------*
* sanitizeBitrateISM()
*
*
*---------------------------------------------------------------------*/
static ivas_error sanitizeBitrateISM(
const ENCODER_CONFIG_HANDLE hEncoderConfig )
{
if ( hEncoderConfig->ivas_total_brate > IVAS_256k )
{
return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
}
if ( hEncoderConfig->ivas_total_brate < IVAS_16k4 && hEncoderConfig->nchan_inp == 2 )
{
return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
}
if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 3 )
{
return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
}
if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 4 )
{
return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
}
return IVAS_ERR_OK;
}
......@@ -1878,6 +2008,8 @@ static ivas_error setBandwidth(
return error;
}
hIvasEnc->newBandwidthApi = newBandwidth;
/* NB coding not supported in IVAS. Switching to WB. */
if ( newBandwidth == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT )
{
......@@ -1890,13 +2022,6 @@ static ivas_error setBandwidth(
hIvasEnc->switchingActive = true;
}
/* Limit bandwidth to half of sampling rate - only possible if
* sampling rate has already been set via configure function */
if ( hIvasEnc->isConfigured )
{
updateBandwidthFromFs( hIvasEnc->st_ivas->hEncoderConfig );
}
return IVAS_ERR_OK;
}
......@@ -1954,6 +2079,37 @@ static ivas_error bandwidthApiToInternal(
return IVAS_ERR_OK;
}
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
/*---------------------------------------------------------------------*
* agcAPIToInternal()
*
*
*---------------------------------------------------------------------*/
static ivas_error agcAPIToInternal(
const IVAS_ENC_AGC agcOption,
int16_t *internalAGCOption )
{
switch ( agcOption )
{
case IVAS_ENC_AGC_ENABLED:
*internalAGCOption = SBA_AGC_FORCE_ENABLE;
break;
case IVAS_ENC_AGC_DISABLED:
*internalAGCOption = SBA_AGC_FORCE_DISABLE;
break;
case IVAS_ENC_AGC_UNDEFINED:
*internalAGCOption = SBA_AGC_DEFAULT;
break;
default:
return IVAS_ERR_INVALID_AGC;
break;
}
return IVAS_ERR_OK;
}
#endif
/*---------------------------------------------------------------------*
* fecIndicatorApiToInternal()
......@@ -2064,18 +2220,14 @@ static void init_encoder_config(
ENCODER_CONFIG_HANDLE hEncoderConfig /* o : configuration structure */
)
{
#ifdef FIX_I98_HANDLES_TO_NULL
hEncoderConfig->ivas_total_brate = ACELP_12k65;
#endif
hEncoderConfig->max_bwidth = SWB;
hEncoderConfig->input_Fs = 16000;
hEncoderConfig->nchan_inp = 1;
hEncoderConfig->element_mode_init = EVS_MONO;
hEncoderConfig->ivas_format = UNDEFINED_FORMAT;
#ifdef FIX_I98_HANDLES_TO_NULL
hEncoderConfig->Opt_SC_VBR = 0;
hEncoderConfig->last_Opt_SC_VBR = 0;
#endif
hEncoderConfig->Opt_AMR_WB = 0;
hEncoderConfig->Opt_DTX_ON = 0;
hEncoderConfig->Opt_RF_ON = 0;
......@@ -2083,16 +2235,18 @@ static void init_encoder_config(
hEncoderConfig->rf_fec_indicator = 1;
hEncoderConfig->interval_SID = FIXED_SID_RATE;
hEncoderConfig->var_SID_rate_flag = 1;
hEncoderConfig->mc_input_setup = MC_LS_SETUP_INVALID;
hEncoderConfig->stereo_dmx_evs = 0;
hEncoderConfig->sba_order = 0;
hEncoderConfig->sba_planar = 0;
#ifdef DEBUGGING
hEncoderConfig->stereo_mode_cmdl = 0;
hEncoderConfig->force = -1;
hEncoderConfig->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION;
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
hEncoderConfig->Opt_AGC_ON = SBA_AGC_DEFAULT;
#endif
#endif
hEncoderConfig->mc_input_setup = MC_LS_SETUP_INVALID;
hEncoderConfig->stereo_dmx_evs = 0;
hEncoderConfig->sba_order = 0;
hEncoderConfig->sba_planar = 0;
hEncoderConfig->Opt_AGC_ON = 0;
hEncoderConfig->Opt_PCA_ON = 0;
return;
......
......@@ -71,19 +71,6 @@ typedef struct _IVAS_ENC_DTX_CONFIG
int16_t SID_interval;
} IVAS_ENC_DTX_CONFIG;
#ifdef DEBUGGING
typedef enum _IVAS_ENC_STEREO_MODE
{
IVAS_ENC_STEREO_MODE_UNIFIED,
IVAS_ENC_STEREO_MODE_DFT,
IVAS_ENC_STEREO_MODE_TD,
IVAS_ENC_STEREO_MODE_MDCT_DECISION,
IVAS_ENC_STEREO_MODE_MDCT_FORCE_LR,
IVAS_ENC_STEREO_MODE_MDCT_FORCE_MS,
IVAS_ENC_STEREO_MODE_UNDEFINED = 0xffff
} IVAS_ENC_STEREO_MODE;
#endif /* DEBUGGING */
typedef enum _IVAS_ENC_SBA_ORDER
{
IVAS_ENC_SBA_FOA = 1,
......@@ -110,6 +97,17 @@ typedef enum _IVAS_ENC_MASA_VARIANT
} IVAS_ENC_MASA_VARIANT;
#ifdef DEBUGGING
typedef enum _IVAS_ENC_STEREO_MODE
{
IVAS_ENC_STEREO_MODE_UNIFIED,
IVAS_ENC_STEREO_MODE_DFT,
IVAS_ENC_STEREO_MODE_TD,
IVAS_ENC_STEREO_MODE_MDCT_DECISION,
IVAS_ENC_STEREO_MODE_MDCT_FORCE_LR,
IVAS_ENC_STEREO_MODE_MDCT_FORCE_MS,
IVAS_ENC_STEREO_MODE_UNDEFINED = 0xffff
} IVAS_ENC_STEREO_MODE;
typedef enum _IVAS_ENC_FORCED_MODE
{
IVAS_ENC_FORCE_SPEECH,
......@@ -121,8 +119,16 @@ typedef enum _IVAS_ENC_FORCED_MODE
IVAS_ENC_FORCE_UNFORCED,
IVAS_ENC_FORCE_UNDEFINED = 0xffff
} IVAS_ENC_FORCED_MODE;
#endif
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
typedef enum _IVAS_ENC_AGC
{
IVAS_ENC_AGC_DISABLED = 0,
IVAS_ENC_AGC_ENABLED,
IVAS_ENC_AGC_UNDEFINED = 0xffff
} IVAS_ENC_AGC;
#endif
#endif
/*---------------------------------------------------------------------*
* Encoder structures
......@@ -189,7 +195,9 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics(
const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */
const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */
const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */
const bool Opt_AGC_ON, /* i : AGC on/off flag */
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
const IVAS_ENC_AGC Opt_AGC_ON, /* i : AGC on/off/undefined flag */
#endif
const bool Opt_PCA_ON /* i : PCA option flag */
#ifdef DEBUG_SBA_AUDIO_DUMP
,
......
......@@ -55,8 +55,7 @@
* Local constants
*-----------------------------------------------------------------*/
#define MSVQ_MAXCNT 3000 /* was 300 */
#define LOWEMPH_LSFI 1.0f /* bigger value means more weight for lower frequencies */
#define MSVQ_MAXCNT 3000
/*---------------------------------------------------------------------*
......@@ -1020,7 +1019,7 @@ void first_VQstages(
dist[0] = dist_buf;
dist[1] = dist_buf + maxC;
set_s( idx_buf, 0, ( const int16_t )( 2 * stagesVQ * maxC ) );
set_s( idx_buf, 0, 2 * stagesVQ * maxC );
set_s( parents, 0, maxC );
/* Set up inital distance vector */
......
......@@ -622,7 +622,6 @@ void norm_corr(
for ( t = t_min; t <= t_max; t++ )
{
/* Compute correlation between xn[] and excf[] */
ps = 0.0f;
for ( j = 0; j < L_subfr; ++j )
{
......@@ -630,7 +629,6 @@ void norm_corr(
}
/* Compute 1/sqrt(energie of excf[]) */
alp = 0.01f;
for ( j = 0; j < L_subfr; ++j )
{
......
......@@ -101,7 +101,6 @@ void lpc_quantization(
}
/****** Low-rate LPC quantizer *******/
else if ( st->lpcQuantization == 1 )
{
......
......@@ -55,10 +55,11 @@
---------------------------------------------------------------------------*/
void SetModeIndex(
Encoder_State *st,
const int32_t last_total_brate,
const int16_t last_element_mode,
const int16_t is_mct )
Encoder_State *st, /* i : Encoder state */
const int32_t last_total_brate, /* i : last total bitrate */
const int16_t last_element_mode, /* i : last IVAS element mode */
const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */
)
{
int16_t ini_frame_loc = st->ini_frame;
......@@ -75,10 +76,9 @@ void SetModeIndex(
( st->rf_mode_last != st->rf_mode ) ||
( st->element_mode > EVS_MONO && st->ini_frame == 0 ) )
{
core_coder_mode_switch( st, last_total_brate, is_mct );
core_coder_mode_switch( st, last_total_brate, MCT_flag );
}
st->ini_frame = ini_frame_loc;
return;
......
......@@ -1361,7 +1361,9 @@ static int16_t SWB_BWE_encoding(
st->hBWE_FD->EnergyLF = energy;
}
calc_tilt_bwe( insig, &tilt, L_FRAME32k );
if ( IsTransient == 1 && ( tilt > 8.0 || st->clas > 1 ) )
{
IsTransient = 0;
......