diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 584013e2b786b3e904d095a54db824ce3a20fa9f..3d8a69a3e7361fb3a6daa6057a1a5e9cb7afbe6b 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -39,6 +39,7 @@ #include "options.h" #include "cnst.h" #include "prot.h" +#include "prot_fx.h" #include "stat_enc.h" #include "stat_dec.h" #include "rom_com.h" @@ -49,6 +50,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx_enc.h" #endif @@ -422,277 +424,6 @@ ivas_error ind_list_realloc( *-----------------------------------------------------------------------*/ /*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -) -{ - if ( ivas_format == STEREO_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 450; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 950; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1350; - } - else - { - return 1650; - } - } - else if ( ivas_format == ISM_FORMAT || ivas_format == MONO_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 250; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 350; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 450; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 550; - } - else if ( ivas_total_brate <= IVAS_64k ) - { - return 620; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 670; - } - else if ( ivas_total_brate <= IVAS_96k ) - { - return 780; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 880; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 950; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1100; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1300; - } - else - { - return 1650; - } - } - else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 250; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 350; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 1020; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 1160; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 1220; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1300; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1720; - } - else - { - return 2000; - } - } - else if ( ivas_format == MASA_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 950; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1150; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1450; - } - else - { - return 1650; - } - } - else if ( ivas_format == MASA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 1150; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 1250; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1400; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1650; - } - else - { - return 1850; - } - } - else if ( ivas_format == MC_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 250; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 350; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_64k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 1150; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 1420; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 2120; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 2250; - } - else - { - return 2450; - } - } - - return 2450; -} - Word16 get_ivas_max_num_indices_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -908,273 +639,93 @@ Word16 get_ivas_max_num_indices_fx( } ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) { - return 1650; - } - ELSE - { - return 1850; - } - } - ELSE IF( EQ_16( ivas_format, MC_FORMAT ) ) - { - IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) - { - return 250; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) - { - return 350; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) - { - return 400; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) - { - return 650; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_64k ) ) - { - return 750; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) - { - return 850; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) - { - return 1150; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) - { - return 1420; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) - { - return 2120; - } - ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) - { - return 2250; - } - ELSE - { - return 2450; - } - } - - return 2450; -} -/*-----------------------------------------------------------------------* - * get_BWE_max_num_indices() - * - * Get the maximum number of indices in the BWE - *-----------------------------------------------------------------------*/ - -/*! r: maximum number of indices */ -int16_t get_BWE_max_num_indices( - const int32_t extl_brate /* i : extensiona layer bitrate */ -) -{ - /* set the maximum number of indices in the BWE */ - if ( extl_brate < SWB_BWE_16k ) - { - return 30; - } - else - { - return 150; - } -} - - -/*-----------------------------------------------------------------------* - * get_ivas_max_num_indices_metadata() - * - * Set the maximum allowed number of metadata indices in the list - *-----------------------------------------------------------------------*/ - -/*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices_metadata( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -) -{ - /* set the maximum required number of metadata indices */ - if ( ivas_format == MONO_FORMAT ) - { - return 0; - } - else if ( ivas_format == STEREO_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 60; - } - else - { - return 80; - } - } - else if ( ivas_format == ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 20; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 65; - } - else - { - return 80; - } - } - else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 100; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 200; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 500; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1050; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 2000; - } - else - { - return 2500; - } - } - else if ( ivas_format == MASA_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 80; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 125; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 205; - } - else if ( ivas_total_brate <= IVAS_96k ) - { - return 240; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 305; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 425; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 630; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1000; - } - else - { - return 1750; - } - } - else if ( ivas_format == MASA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 80; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 125 + 100; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 205 + 100; + return 1650; } - else if ( ivas_total_brate <= IVAS_96k ) + ELSE { - return 240 + 150; + return 1850; } - else if ( ivas_total_brate <= IVAS_128k ) + } + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) ) + { + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) { - return 305 + 30; + return 250; } - else if ( ivas_total_brate <= IVAS_160k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) { - return 425 + 30; + return 350; } - else if ( ivas_total_brate <= IVAS_192k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) { - return 630 + 30; + return 400; } - else if ( ivas_total_brate <= IVAS_256k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) { - return 850 + 30; + return 650; } - else if ( ivas_total_brate <= IVAS_384k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_64k ) ) { - return 1000 + 30; + return 750; } - else + ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) { - return 1750 + 30; + return 850; } - } - else if ( ivas_format == MC_FORMAT ) - { - if ( ivas_total_brate <= IVAS_13k2 ) + ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) { - return 80; + return 1150; } - else if ( ivas_total_brate <= IVAS_24k4 ) + ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) { - return 100; + return 1420; } - else if ( ivas_total_brate <= IVAS_64k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) { - return 210; + return 2120; } - else if ( ivas_total_brate <= IVAS_96k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) { - return 220; + return 2250; } - else + ELSE { - return 300; + return 2450; } } - return 50; + return 2450; +} +/*-----------------------------------------------------------------------* + * get_BWE_max_num_indices() + * + * Get the maximum number of indices in the BWE + *-----------------------------------------------------------------------*/ + +/*! r: maximum number of indices */ +int16_t get_BWE_max_num_indices( + const int32_t extl_brate /* i : extensiona layer bitrate */ +) +{ + /* set the maximum number of indices in the BWE */ + if ( extl_brate < SWB_BWE_16k ) + { + return 30; + } + else + { + return 150; + } } + +/*-----------------------------------------------------------------------* + * get_ivas_max_num_indices_metadata() + * + * Set the maximum allowed number of metadata indices in the list + *-----------------------------------------------------------------------*/ + +/*! r: maximum number of indices */ Word16 get_ivas_max_num_indices_metadata_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -2244,7 +1795,52 @@ void reset_indices_dec( * * writing forward or backward to a serial stream *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 write_indices_to_stream_fx( + Indice *ind_list, + UWord16 **pt_stream, + const Word16 inc, + const Word16 num_indices ) +{ + Word16 i, k; + Word16 value, nb_bits; + UWord16 mask; + + FOR( i = 0; i < num_indices; i++ ) + { + value = ind_list[i].value; + nb_bits = ind_list[i].nb_bits; + move16(); + move16(); + + IF( nb_bits > 0 ) + { + /* mask from MSB to LSB */ + mask = (UWord16) L_shl( 1, sub( nb_bits, 1 ) ); + + /* write bit by bit */ + FOR( k = 0; k < nb_bits; k++ ) + { + IF( L_and( value, mask ) ) + { + **pt_stream = 1; + move16(); + *pt_stream += inc; + } + ELSE + { + **pt_stream = 0; + move16(); + *pt_stream += inc; + } + mask = (UWord16) L_shr( mask, 1 ); + } + } + } + return 0; +} +#else static int16_t write_indices_to_stream( Indice *ind_list, uint16_t **pt_stream, @@ -2285,13 +1881,158 @@ static int16_t write_indices_to_stream( } return 0; } +#endif /*-------------------------------------------------------------------* * write_indices_element() * * Bitstream writing function of one element (one SCE or one CPE) *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static ivas_error write_indices_element_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + UWord16 **pt_stream, /* i : pointer to bitstream buffer */ + const Word16 is_SCE, /* i : flag to distingusih SCE and CPE */ + const Word16 element_id /* i : id of the SCE or CPE */ +) +{ + Word16 ch; + Encoder_State **sts = NULL; + UWord16 *pt_stream_loc; + UWord16 *pt_stream_backup; + UWord16 *pt_stream_end; + Word16 nb_bits_tot_metadata; + Word16 nb_ind_tot_metadata; + + Indice *ind_list_metadata; + Word16 n, n_channels; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + ind_list_metadata = NULL; + nb_ind_tot_metadata = 0; + move16(); + + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + sts = st_ivas->hSCE[0]->hCoreCoder; + nb_bits_tot_metadata = 0; + move16(); + } + ELSE + { + nb_bits_tot_metadata = 0; + move16(); + test(); + test(); + IF( is_SCE && st_ivas->hSCE[element_id] != NULL ) + { + sts = st_ivas->hSCE[element_id]->hCoreCoder; + + IF( st_ivas->hSCE[element_id]->hMetaData != NULL ) + { + nb_bits_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_bits_tot; + ind_list_metadata = st_ivas->hSCE[element_id]->hMetaData->ind_list; + nb_ind_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot; + move16(); + move16(); + } + } + ELSE IF( !is_SCE && st_ivas->hCPE[element_id] != NULL ) + { + sts = st_ivas->hCPE[element_id]->hCoreCoder; + + IF( st_ivas->hCPE[element_id]->hMetaData != NULL ) + { + nb_bits_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_bits_tot; + ind_list_metadata = st_ivas->hCPE[element_id]->hMetaData->ind_list; + nb_ind_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot; + move16(); + move16(); + } + } + } + + n_channels = 1; + move16(); + if ( GT_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) + { + n_channels = CPE_CHANNELS; + move16(); + } + + /*----------------------------------------------------------------* + * Bitstream packing (conversion of individual indices into a serial stream) + *----------------------------------------------------------------*/ + + pt_stream_loc = *pt_stream; + pt_stream_end = pt_stream_loc; + + FOR( n = 0; n < n_channels; n++ ) + { + /* write the metadata buffer */ + test(); + IF( n == 0 && nb_bits_tot_metadata != 0 ) + { + pt_stream_backup = pt_stream_loc; + + FOR( ch = 0; ch < n_channels; ch++ ) + { + pt_stream_loc += sts[ch]->hBstr->nb_bits_tot; + } + pt_stream_loc += nb_bits_tot_metadata - 1; + pt_stream_end = pt_stream_loc + 1; + + write_indices_to_stream_fx( ind_list_metadata, &pt_stream_loc, -1, + nb_ind_tot_metadata ); + + /* restore previous pointer position */ + pt_stream_loc = pt_stream_backup; + } + write_indices_to_stream_fx( sts[n]->hBstr->ind_list, &pt_stream_loc, 1, + sts[n]->hBstr->nb_ind_tot ); + + if ( pt_stream_loc > pt_stream_end ) + { + pt_stream_end = pt_stream_loc; + } + } + + /*----------------------------------------------------------------* + * Clearing of indices + * Reset index pointers + *----------------------------------------------------------------*/ + + IF( is_SCE ) /* EVS and SCE */ + { + IF( st_ivas->hSCE[element_id]->hMetaData != NULL ) + { + reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot ); + } + + reset_indices_enc( sts[0]->hBstr, sts[0]->hBstr->nb_ind_tot ); + } + ELSE + { + IF( st_ivas->hCPE[element_id]->hMetaData != NULL ) + { + reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot ); + } + + FOR( n = 0; n < n_channels; n++ ) + { + reset_indices_enc( sts[n]->hBstr, sts[n]->hBstr->nb_ind_tot ); + } + } + /* update pointer */ + *pt_stream = pt_stream_end; + + return error; +} +#else static ivas_error write_indices_element( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ uint16_t **pt_stream, /* i : pointer to bitstream buffer */ @@ -2422,6 +2163,7 @@ static ivas_error write_indices_element( return error; } +#endif /*-------------------------------------------------------------------* * write_indices_ivas() @@ -2429,7 +2171,48 @@ static ivas_error write_indices_element( * Write the buffer of indices to a serial bitstream buffer, * each bit represented as a uint16_t of value 0 or 1 *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error write_indices_ivas_fx( + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + UWord16 *bit_stream, /* i/o: output bitstream */ + UWord16 *num_bits /* i : number of indices written to output */ +) +{ + Word16 i, n; + UWord16 *pt_stream; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + pt_stream = bit_stream; + FOR( i = 0; i < MAX_BITS_PER_FRAME; ++i ) + { + bit_stream[i] = 0; + move16(); + } + + + /*-----------------------------------------------------------------* + * Encode Payload + *-----------------------------------------------------------------*/ + + FOR( n = 0; n < st_ivas->nSCE; n++ ) + { + write_indices_element_fx( st_ivas, &pt_stream, 1, n ); + } + + FOR( n = 0; n < st_ivas->nCPE; n++ ) + { + write_indices_element_fx( st_ivas, &pt_stream, 0, n ); + } + + *num_bits = (UWord16) ( pt_stream - bit_stream ); + move16(); + return error; +} +#else ivas_error write_indices_ivas( Encoder_Struct *st_ivas, /* i/o: encoder state structure */ uint16_t *bit_stream, /* i/o: output bitstream */ @@ -2467,6 +2250,7 @@ ivas_error write_indices_ivas( return error; } +#endif #ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 7d7fa3fdda6d1c595bc8159c722672abb6019d59..753bc19cf8ccd5f516c52c0d68399edba62d703c 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -1088,7 +1088,7 @@ static void decoder_selectCodec( } -void dec_prm_core( Decoder_State *st ) +static void dec_prm_core( Decoder_State *st ) { Word16 n, frame_size_index, num_bits; UWord16 lsb; @@ -1178,7 +1178,7 @@ void dec_prm_core( Decoder_State *st ) * Set st->core, and st->bwidth if signalled together with the core. *-----------------------------------------------------------------*/ -void decision_matrix_core_dec( +static void decision_matrix_core_dec( Decoder_State *st /* i/o: decoder state structure */ ) { diff --git a/lib_com/gs_preech.c b/lib_com/gs_preech.c index 3d1b6f550b4c27e96e631d327597185cc9b97539..1fc23300e5901bb638620273ab41bd6432267568 100644 --- a/lib_com/gs_preech.c +++ b/lib_com/gs_preech.c @@ -144,10 +144,10 @@ void pre_echo_att( void pre_echo_att_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ) { Word32 etmp_fx; @@ -168,18 +168,18 @@ void pre_echo_att_fx( * The inverse weighting aims to favor the first maxima in case of * gradual onset *-------------------------------------------------------------------------*/ - att_len = ATT_LENGHT; + att_len = ATT_LENGHT; /* Q0 */ move16(); if ( EQ_16( L_frame, L_FRAME16k ) ) { - att_len = ATT_LENGHT16k; + att_len = ATT_LENGHT16k; /* Q0 */ move16(); } FOR( i = 0; i < att_len; i++ ) { - L_tmp = sum2_fx( &exc_fx[shl( i, 2 )], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ - tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ + L_tmp = sum2_fx( &exc_fx[i * 4], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ + tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ finc_fx[i] = L_tmp; move32(); /*2*Q_new+1 */ } @@ -231,10 +231,10 @@ void pre_echo_att_fx( L_tmp = L_shr( L_tmp, exp ); /* add exponent */ L_tmp = Isqrt( L_tmp ); - ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); + ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Q13 */ /* Pre-echo atttenuation should never increase the energy */ - ratio_fx = s_min( ratio_fx, 8192 ); + ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */ FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ ) { /*exc_fx[i] *= ratio_fx;*/ @@ -242,7 +242,7 @@ void pre_echo_att_fx( move16(); } } - *Last_frame_ener_fx = etmp1_fx; + *Last_frame_ener_fx = etmp1_fx; /*2*Q_new+1*/ move32(); } ELSE @@ -270,10 +270,10 @@ void pre_echo_att_fx( void pre_echo_att_ivas_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ) { Word32 etmp_fx; @@ -294,18 +294,18 @@ void pre_echo_att_ivas_fx( * The inverse weighting aims to favor the first maxima in case of * gradual onset *-------------------------------------------------------------------------*/ - att_len = ATT_LENGHT; + att_len = ATT_LENGHT; /* Q0 */ move16(); if ( EQ_16( L_frame, L_FRAME16k ) ) { - att_len = ATT_LENGHT16k; + att_len = ATT_LENGHT16k; /* Q0 */ move16(); } FOR( i = 0; i < att_len; i++ ) { - L_tmp = sum2_fx( &exc_fx[shl( i, 2 )], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ - tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ + L_tmp = sum2_fx( &exc_fx[i * 4], ATT_SEG_LEN ); /*2*Q_new+1, //ATT_SEG_LEN=(L_FRAME/ATT_LENGHT)=4(=shl(x,2))*/ + tmp = div_s( sub( att_len, i ), att_len ); /*Q15 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*2*Q_new+1 */ finc_fx[i] = L_tmp; move32(); /*2*Q_new+1 */ } @@ -360,7 +360,7 @@ void pre_echo_att_ivas_fx( ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Pre-echo atttenuation should never increase the energy */ - ratio_fx = s_min( ratio_fx, 8192 ); + ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */ FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ ) { /*exc_fx[i] *= ratio_fx;*/ @@ -368,7 +368,7 @@ void pre_echo_att_ivas_fx( move16(); } } - *Last_frame_ener_fx = etmp1_fx; + *Last_frame_ener_fx = etmp1_fx; /* 2 * Q_new + 1 */ move32(); } ELSE @@ -383,7 +383,7 @@ void pre_echo_att_ivas_fx( if ( EQ_16( L_frame, L_FRAME16k ) ) { - etmp_fx = Mpy_32_16_1( etmp_fx, 26214 ); + etmp_fx = Mpy_32_16_1( etmp_fx, 26214 /* 0.8 in Q15 */ ); /*2*Q_new+1*/ } *Last_frame_ener_fx = etmp_fx; move32(); /*2*Q_new+1*/ diff --git a/lib_com/guided_plc_util_fx.c b/lib_com/guided_plc_util_fx.c index b7eba5d7e7c5a634b57ce9b310d08ac7d6e03640..f556fff05d5669da9d9f2d68e5ea3c6d74c5350e 100644 --- a/lib_com/guided_plc_util_fx.c +++ b/lib_com/guided_plc_util_fx.c @@ -22,11 +22,12 @@ static void reorder_lsfs( Word16 *lsf, const Word16 min_dist, const Word16 n, co * *-------------------------------------------------------------------*/ void getLookAheadResSig( - Word16 *speechLookAhead, - Word16 *A_3Q12, - Word16 *res, - const Word16 L_frame, - const Word16 numSubFrame ) + Word16 *speechLookAhead, /* Qx */ + Word16 *A_3Q12, /* 3Q12 */ + Word16 *res, /* Qx */ + const Word16 L_frame, /* Q0 */ + const Word16 numSubFrame /* Q0 */ +) { Word16 *p_A; Word16 i_subfr; @@ -40,12 +41,12 @@ void getLookAheadResSig( move16(); /* 0.75 * L_SUBFR(64) */ } - p_A = A_3Q12; + p_A = A_3Q12; /* Q12 */ FOR( i_subfr = 0; i_subfr < numSubFrame * L_SUBFR; i_subfr += L_SUBFR ) { /* calculate residual signal */ Residu3_fx( p_A, &speechLookAhead[i_subfr], &res[i_subfr], - subfr_len[shr( i_subfr, 6 )], 0 ); + subfr_len[i_subfr / 64], 0 ); /* pointer initialization */ p_A += ( M + 1 ); @@ -62,21 +63,22 @@ void getLookAheadResSig( void updateLSFForConcealment( PLC_ENC_EVS_HANDLE decState, - Word16 *lsf_14Q1 ) + Word16 *lsf_14Q1 /* 14Q1 */ +) { Word16 i; Word32 L_tmp = 0; - const Word16 divide_by_3_Q15 = 10923; + const Word16 divide_by_3_Q15 = 10923; /* 1/3 in Q15 */ FOR( i = 0; i < M; i++ ) { - L_tmp = L_mult( divide_by_3_Q15, decState->lsfoldbfi1_14Q1[i] ); - L_tmp = L_mac( L_tmp, divide_by_3_Q15, decState->lsfoldbfi0_14Q1[i] ); - decState->lsf_adaptive_mean_14Q1[i] = mac_r( L_tmp, divide_by_3_Q15, lsf_14Q1[i] ); + L_tmp = L_mult( divide_by_3_Q15, decState->lsfoldbfi1_14Q1[i] ); /* Q17 */ + L_tmp = L_mac( L_tmp, divide_by_3_Q15, decState->lsfoldbfi0_14Q1[i] ); /* Q17 */ + decState->lsf_adaptive_mean_14Q1[i] = mac_r( L_tmp, divide_by_3_Q15, lsf_14Q1[i] ); /* 14Q1 */ move16(); - decState->lsfoldbfi1_14Q1[i] = decState->lsfoldbfi0_14Q1[i]; + decState->lsfoldbfi1_14Q1[i] = decState->lsfoldbfi0_14Q1[i]; /* 14Q1 */ move16(); - decState->lsfoldbfi0_14Q1[i] = lsf_14Q1[i]; + decState->lsfoldbfi0_14Q1[i] = lsf_14Q1[i]; /* 14Q1 */ move16(); } @@ -90,10 +92,11 @@ void updateLSFForConcealment( void getConcealedLP( PLC_ENC_EVS_HANDLE memDecState, - Word16 *AqCon, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ) + Word16 *AqCon, /* 14Q1 */ + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +) { Word16 *lsf; Word16 lsp[( NB_DIV + 1 ) * M]; @@ -106,7 +109,7 @@ void getConcealedLP( 1, memDecState->mem_MA_14Q1, memDecState->mem_AR, &( memDecState->stab_fac_Q15 ), memDecState->lsf_adaptive_mean_14Q1, 1, NULL, 0, NULL, NULL, lsfBase, 0 ); - Copy( memDecState->lspold_Q15, lsp, M ); + Copy( memDecState->lspold_Q15, lsp, M ); /* Q15 */ int_fs = INT_FS_FX; move32(); @@ -128,9 +131,10 @@ void getConcealedLP( *-------------------------------------------------------------------*/ void getConcealedLSF( PLC_ENC_EVS_HANDLE memDecState, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ) + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +) { Word16 *lsf = memDecState->lsf_con; @@ -149,11 +153,12 @@ void getConcealedLSF( *-------------------------------------------------------------------*/ void RecLpcSpecPowDiffuseLc( - Word16 *lspq, - Word16 *lsp_old, - Word16 *lsfq, + Word16 *lspq, /* Q15 */ + Word16 *lsp_old, /* Q15 */ + Word16 *lsfq, /* Q2.56 */ Decoder_State *st, - const Word16 reset_q ) + const Word16 reset_q /* Q0 */ +) { const Word16 *means; Word16 lsf_old[M]; @@ -163,7 +168,7 @@ void RecLpcSpecPowDiffuseLc( st->narrowBand, st->sr_core ); - Copy( st->lsf_old_fx, lsf_old, M ); + Copy( st->lsf_old_fx, lsf_old, M ); /* Q2.56 */ modify_lsf( lsf_old, M, st->sr_core, reset_q ); @@ -173,7 +178,7 @@ void RecLpcSpecPowDiffuseLc( { FOR( i = 0; i < M; i++ ) { - lsfq[i] = add( st->mem_MA_fx[i], means[i] ); + lsfq[i] = add( st->mem_MA_fx[i], means[i] ); /* Q2.56 */ move16(); } sort_fx( lsfq, 0, sub( M, 1 ) ); @@ -195,10 +200,11 @@ void RecLpcSpecPowDiffuseLc( * *-------------------------------------------------------------------*/ void modify_lsf( - Word16 *lsf, - const Word16 n, - const Word32 sr_core, - const Word16 reset_q ) + Word16 *lsf, /* Q14 */ + const Word16 n, /* Q0 */ + const Word32 sr_core, /* Q0 */ + const Word16 reset_q /* Q0 */ +) { Word16 i, k, th_x1p28_Q14; Word16 gap, gap_sum; @@ -231,25 +237,25 @@ void modify_lsf( } } - gap = mult_r( lsf[i - 1], InvIntTable[i] ); + gap = mult_r( lsf[i - 1], InvIntTable[i] ); /* Q14 */ move16(); gap_sum = gap; - i = sub( i, 1 ); + i--; FOR( k = 0; k < i; k++ ) { move16(); - lsf[k] = gap_sum; + lsf[k] = gap_sum; /* Q14 */ gap_sum = add( gap_sum, gap ); } } static void reorder_lsfs( - Word16 *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5)*/ - const Word16 min_dist0, /* i : minimum required distance */ - const Word16 n, /* i : LPC order */ - const Word32 sr_core /* i : input sampling frequency */ + Word16 *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5) 1.28 Q1*/ + const Word16 min_dist0, /* i : minimum required distance 1.28 Q1*/ + const Word16 n, /* i : LPC order Q0*/ + const Word32 sr_core /* i : input sampling frequency Q0*/ ) { Word16 i; @@ -277,17 +283,17 @@ static void reorder_lsfs( *-----------------------------------------------------------------*/ IF( EQ_32( sr_core, INT_FS_16k ) ) { - th1 = 3200; + th1 = 3200; /*1000.0 * 1.25 * 1.28 Q1*/ move16(); - th2 = 6080; + th2 = 6080; /*1900.0 * 1.25 * 1.28 Q1*/ move16(); min_dist = add( min_dist0, shr( min_dist0, 2 ) ); } ELSE { - th1 = 2560; + th1 = 2560; /* 1000.0 * 1.28 Q1 */ move16(); - th2 = 4864; + th2 = 4864; /* 1900.0 * 1.28 Q1 */ move16(); min_dist = min_dist0; move16(); @@ -322,7 +328,7 @@ static void reorder_lsfs( move16(); } - lsf_min = add( lsf[i], curr_min_dist ); + lsf_min = add( lsf[i], curr_min_dist ); /* 1.28 Q1 */ } /*------------------------------------------------------------------------------------------* @@ -333,7 +339,7 @@ static void reorder_lsfs( IF( GT_16( lsf[n - 1], lsf_max ) ) /* If danger of unstable filter in case of resonance in HF */ { - FOR( i = sub( n, 1 ); i >= 0; i-- ) /* Reverify the minimum ISF gap in the reverse direction */ + FOR( i = n - 1; i >= 0; i-- ) /* Reverify the minimum ISF gap in the reverse direction */ { IF( LE_16( lsf[i], th2 ) ) { @@ -354,7 +360,7 @@ static void reorder_lsfs( lsf[i] = lsf_max; move16(); } - lsf_max = sub( lsf[i], curr_min_dist ); + lsf_max = sub( lsf[i], curr_min_dist ); /* 1.28 Q1 */ } } diff --git a/lib_com/hq2_bit_alloc_fx.c b/lib_com/hq2_bit_alloc_fx.c index 486de81de13abff40fb0e1fd33da87d016e59e0c..395854d5f678aa22df3ce3c5e1113ab17fa6bbda 100644 --- a/lib_com/hq2_bit_alloc_fx.c +++ b/lib_com/hq2_bit_alloc_fx.c @@ -92,14 +92,14 @@ void Bits2indvsb_fx( Word32 L_temp1; Word32 L_temp2; - band_num_fx = sub( end_band, start_band ); - L_y_ptr = L_be + start_band; - L_R_ptr = L_Rsubband + start_band; - p2aflags_fx_ptr = p2aflags_fx + start_band; + band_num_fx = sub( end_band, start_band ); /* Q0 */ + L_y_ptr = L_be + start_band; /* Qbe */ + L_R_ptr = L_Rsubband + start_band; /* QRk */ + p2aflags_fx_ptr = p2aflags_fx + start_band; /* Q0 */ FOR( i = 0; i < band_num_fx; i++ ) { - y_index_fx[i] = extract_h( L_shr( L_y_ptr[i], sub( SWB_BWE_LR_Qbe, 16 ) ) ); + y_index_fx[i] = extract_h( L_shr( L_y_ptr[i], sub( SWB_BWE_LR_Qbe, 16 ) ) ); /* Q16 */ move16(); index_fx[i] = i; move16(); @@ -125,9 +125,9 @@ void Bits2indvsb_fx( } ELSE { - L_R_temp[j] = C1_QRk; - move32(); /* filled not zero value */ - be_cnt_fx = add( be_cnt_fx, 1 ); + L_R_temp[j] = C1_QRk; /* QRk */ + move32(); /* filled not zero value */ + be_cnt_fx = add( be_cnt_fx, 1 ); /* Q0 */ } } @@ -187,7 +187,7 @@ void Bits2indvsb_fx( exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( Rcnt_fx ); Ravg_fx = div_s( shl( be_sum_fx, exp_normn ), shl( Rcnt_fx, exp_normd ) ); - Ravg_fx = shr( Ravg_fx, 2 ); /* safe shift */ + Ravg_fx = shr( Ravg_fx, 2 ); /* safe shift exp_normn - exp_normd + 13*/ QRavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); if ( be_sum_fx <= 0 ) @@ -207,7 +207,7 @@ void Bits2indvsb_fx( exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( be_sum_fx ); Bits_avg_fx = div_s( shl( Bits, exp_normn ), shl( be_sum_fx, exp_normd ) ); - Bits_avg_fx = shr( Bits_avg_fx, 2 ); /* safe_shift */ + Bits_avg_fx = shr( Bits_avg_fx, 2 ); /* safe_shift exp_normn - exp_normd + 13*/ QBavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); } FOR( k = 0; k <= i; k++ ) @@ -244,7 +244,7 @@ void Bits2indvsb_fx( { j = index_fx[k]; move16(); - L_R_ptr[j] = L_R_temp[k]; + L_R_ptr[j] = L_R_temp[k]; /* SWB_BWE_LR_QRk */ move32(); } @@ -262,7 +262,7 @@ void hq2_bit_alloc_har_fx( Word16 B_fx, /* i : Q0 number of available bits */ const Word16 N_fx, /* i : Q0 number of sub-vectors */ Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : highfreq bands */ + Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ const Word32 L_core_brate, /* i : Q0 core bit rate */ Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ const Word16 band_width_fx[] /* i : Q0 table of band_width */ @@ -280,7 +280,7 @@ void hq2_bit_alloc_har_fx( Word16 G1_BE_DIFF_POS_fx; /* Q0 */ Word32 L_G1_BE_DIFF_VAL; /* Qbe Word32 */ Word16 final_gr_fact_pos_fx, gmax_range_fx[2], temp_fx; - Word16 bits_fact_fx, bits_fact1_fx; /* Q? */ + Word16 bits_fact_fx, bits_fact1_fx; Word16 grp_rngmax_fx[2] = { 0 }; Word16 index_fx[NB_SWB_SUBBANDS_HAR], y_index_fx[NB_SWB_SUBBANDS_HAR], esthf_bits_fx, grp_bit_avg_fx, harmonic_band_fx; Word32 L_norm_sum_avg; @@ -336,9 +336,9 @@ void hq2_bit_alloc_har_fx( } final_gr_fact_pos_fx = 2; move16(); - bits_fact_fx = C1_Qbf; + bits_fact_fx = C1_Qbf; /* Qbf */ move16(); - bits_fact1_fx = C1_Qbf; + bits_fact1_fx = C1_Qbf; /* Qbf */ move16(); gmax_range_fx[0] = G1_RANGE; @@ -378,27 +378,27 @@ void hq2_bit_alloc_har_fx( { FOR( temp_fx = 2; temp_fx <= k_fx; ) { - IF( LT_32( L_temp_band_energy[sub( add( gmax_range_fx[i], temp_fx ), 1 )], L_temp_band_energy[add( gmax_range_fx[i], temp_fx )] ) ) + IF( LT_32( L_temp_band_energy[( gmax_range_fx[i] + temp_fx ) - 1], L_temp_band_energy[gmax_range_fx[i] + temp_fx] ) ) { BREAK; } - ELSE IF( GE_32( L_temp_band_energy[sub( add( gmax_range_fx[i], temp_fx ), 1 )], L_temp_band_energy[add( gmax_range_fx[i], temp_fx )] ) ) + ELSE IF( GE_32( L_temp_band_energy[( gmax_range_fx[i] + temp_fx ) - 1], L_temp_band_energy[( gmax_range_fx[i] + temp_fx )] ) ) { - temp_fx = add( temp_fx, 1 ); + temp_fx++; IF( GT_16( temp_fx, k_fx ) ) { - temp_fx = sub( temp_fx, 1 ); + temp_fx--; /* Q0 */ BREAK; } } } - gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); + gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); /* Q0 */ move16(); } ELSE { - gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); + gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); /* Q0 */ move16(); } } @@ -407,12 +407,12 @@ void hq2_bit_alloc_har_fx( move16(); FOR( i = 1; i < GRP_SB - 1; i++ ) { - grp_bound_fx[i] = gmax_range_fx[i - 1]; + grp_bound_fx[i] = gmax_range_fx[i - 1]; /* Q0 */ move16(); } - grp_bound_fx[i] = harmonic_band_fx; + grp_bound_fx[i] = harmonic_band_fx; /* Q0 */ move16(); - grp_bound_fx[add( i, 1 )] = N_fx; + grp_bound_fx[i + 1] = N_fx; /* Q0 */ move16(); @@ -423,7 +423,7 @@ void hq2_bit_alloc_har_fx( { IF( L_temp_band_energy[j] > 0x0L ) { - L_Ravg_sub[i] = L_add( L_Ravg_sub[i], L_temp_band_energy[j] ); + L_Ravg_sub[i] = L_add( L_Ravg_sub[i], L_temp_band_energy[j] ); /* Qbe */ move32(); } } @@ -433,7 +433,7 @@ void hq2_bit_alloc_har_fx( move32(); FOR( j = 1; j < harmonic_band_fx; j++ ) { - L_temp_band_energydiff[j] = L_abs( L_sub( L_temp_band_energy[j], L_temp_band_energy[j - 1] ) ); + L_temp_band_energydiff[j] = L_abs( L_sub( L_temp_band_energy[j], L_temp_band_energy[j - 1] ) ); /* Qbe */ move32(); } @@ -447,7 +447,7 @@ void hq2_bit_alloc_har_fx( { G1_BE_DIFF_POS_fx = j; move16(); - L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j]; + L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j]; /* Qbe */ move32(); } } @@ -506,47 +506,47 @@ void hq2_bit_alloc_har_fx( } } - j = sub( N_fx, harmonic_band_fx ); + j = sub( N_fx, harmonic_band_fx ); /* Q0 */ FOR( i = 0; i < j; i++ ) { - y_index_fx[i] = extract_h( L_shl( L_temp_band_energy[harmonic_band_fx + i], sub( 16, SWB_BWE_LR_Qbe ) ) ); + y_index_fx[i] = extract_h( L_shl( L_temp_band_energy[harmonic_band_fx + i], sub( 16, SWB_BWE_LR_Qbe ) ) ); /* Q0 */ move16(); - index_fx[i] = add( harmonic_band_fx, i ); + index_fx[i] = add( harmonic_band_fx, i ); /* Q0 */ move16(); } reordvct_fx( y_index_fx, sub( N_fx, harmonic_band_fx ), index_fx ); /* Log2 */ - L_temp = L_deposit_l( band_width_fx[index_fx[0]] ); + L_temp = L_deposit_l( band_width_fx[index_fx[0]] ); /* Q0 */ exp = norm_l( L_temp ); frac = Log2_norm_lc( L_shl( L_temp, exp ) ); exp = sub( 30, exp ); - L_temp = L_Comp( exp, frac ); + L_temp = L_Comp( exp, frac ); /* Q16 */ /* ceil */ if ( L_and( 0x0000ffff, L_temp ) > 0 ) { - L_temp = L_add( L_temp, 0x00010000 ); + L_temp = L_add( L_temp, 0x00010000 ); /* Q16 */ } esthf_bits_fx = extract_h( L_temp ); - L_grp_thr[0] = L_THR1; + L_grp_thr[0] = L_THR1; /* SWB_BWE_LR_QRk */ move32(); - L_grp_thr[1] = L_THR2; + L_grp_thr[1] = L_THR2; /* SWB_BWE_LR_QRk */ move32(); - L_grp_thr[2] = L_THR3; + L_grp_thr[2] = L_THR3; /* SWB_BWE_LR_QRk */ move32(); - L_grp_thr[3] = L_shl( L_deposit_l( esthf_bits_fx ), SWB_BWE_LR_QRk ); + L_grp_thr[3] = L_shl( L_deposit_l( esthf_bits_fx ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ move16(); L_norm_sum = L_deposit_l( 1 ); FOR( i = 0; i < 3; i++ ) { - L_norm_sum = L_add( L_norm_sum, L_Ravg_sub[i] ); + L_norm_sum = L_add( L_norm_sum, L_Ravg_sub[i] ); /* Qbe */ } /*reserve bits for HF coding */ - L_temp = L_add( L_norm_sum, L_Ravg_sub[GRP_SB - 1] ); + L_temp = L_add( L_norm_sum, L_Ravg_sub[GRP_SB - 1] ); /* Qbe */ exp_normn = norm_l( L_temp ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( N_fx ); @@ -558,7 +558,7 @@ void hq2_bit_alloc_har_fx( norm_sum_fx = extract_h( L_shl( L_norm_sum, exp_norm ) ); /* SWB_BWE_LR_Qbe+exp_norm-16 */ Qns = sub( add( SWB_BWE_LR_Qbe, exp_norm ), 16 ); - Inv_norm_sum_fx = div_s( 0x4000 /* Q15 */, norm_sum_fx ); + Inv_norm_sum_fx = div_s( 0x4000 /* 0.5 in Q15 */, norm_sum_fx ); QIns = sub( 31, exp_norm ); /* 14 - (14+exp_norm-16) + 15 */ grp_bit_avg_fx = div_s_ss( B_fx, GRP_SB ); /* Q0 */ @@ -567,8 +567,8 @@ void hq2_bit_alloc_har_fx( Inv_p2a_bands_fx = div_s( 0x3fff, shl( p2a_bands_fx, exp_normd ) ); /* 14-exp_normd+15 */ QIpb = sub( 29, exp_normd ); - L_temp = L_shl( Mult_32_16( L_Ravg_sub[GRP_SB - 1], Inv_p2a_bands_fx ), sub( SWB_BWE_LR_Qbe, sub( QIpb, 1 ) ) ); - L_norm_diff = L_sub( L_temp, L_norm_sum_avg ); /* Qbe */ + L_temp = L_shl( Mult_32_16( L_Ravg_sub[GRP_SB - 1], Inv_p2a_bands_fx ), sub( SWB_BWE_LR_Qbe, sub( QIpb, 1 ) ) ); /* Qbe */ + L_norm_diff = L_sub( L_temp, L_norm_sum_avg ); /* Qbe */ L_temp = Mult_32_16( L_Ravg_sub[GRP_SB - 1], sub( GRP_SB, 1 ) ); /* Qbe+0+1 */ L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Qbe+1+QIpb+1 */ @@ -604,11 +604,11 @@ void hq2_bit_alloc_har_fx( L_temp2 = Mult_32_16( L_norm_diff, bits_allocweigh_fx ); /* Qbe+Q15-15 */ L_temp = L_shr( L_temp, add( QIpb, 1 ) ); - L_temp = L_add( L_shl( L_temp, SWB_BWE_LR_Qbe ), L_temp2 ); + L_temp = L_add( L_shl( L_temp, SWB_BWE_LR_Qbe ), L_temp2 ); /* Qbe+Q15-15 */ - Bits_grp_fx[GRP_SB - 1] = extract_h( L_shl( L_temp, sub( 16, SWB_BWE_LR_Qbe ) ) ); + Bits_grp_fx[GRP_SB - 1] = extract_h( L_shl( L_temp, sub( 16, SWB_BWE_LR_Qbe ) ) ); /* Q0 */ move16(); - Bits_grp_fx[GRP_SB - 1] = s_min( Bits_grp_fx[GRP_SB - 1], 10 ); + Bits_grp_fx[GRP_SB - 1] = s_min( Bits_grp_fx[GRP_SB - 1], 10 ); /* Q0 */ move16(); if ( LT_16( Bits_grp_fx[GRP_SB - 1], esthf_bits_fx ) ) @@ -616,7 +616,7 @@ void hq2_bit_alloc_har_fx( Bits_grp_fx[GRP_SB - 1] = 0; move16(); } - B_fx = sub( B_fx, Bits_grp_fx[GRP_SB - 1] ); + B_fx = sub( B_fx, Bits_grp_fx[GRP_SB - 1] ); /* Q0 */ } exp_shift = sub( add( SWB_BWE_LR_Qbe, QIns ), 47 ); /* (SWB_BWE_LR_Qbe+14+1+QIns-15-16) */ @@ -627,37 +627,37 @@ void hq2_bit_alloc_har_fx( IF( EQ_16( final_gr_fact_pos_fx, 1 ) ) { L_temp = Mult_32_16( L_Ravg_sub[1], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) ); - L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); - Bits_grp_fx[1] = extract_h( L_shr( L_temp, exp_shift ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[1] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); L_temp = Mult_32_16( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) ); - L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); - Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); - Bits_grp_fx[0] = sub( sub( B_fx, Bits_grp_fx[1] ), Bits_grp_fx[2] ); + Bits_grp_fx[0] = sub( sub( B_fx, Bits_grp_fx[1] ), Bits_grp_fx[2] ); /* Q0 */ move16(); } ELSE { L_temp = Mult_32_16( L_Ravg_sub[0], extract_h( L_mult( bits_fact_fx, B_norm_fx ) ) ); - L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); - Bits_grp_fx[0] = extract_h( L_shr( L_temp, exp_shift ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[0] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); L_temp = Mult_32_16( L_Ravg_sub[2], extract_h( L_mult( bits_fact1_fx, B_norm_fx ) ) ); - L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); - Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); - Bits_grp_fx[1] = sub( sub( B_fx, Bits_grp_fx[0] ), Bits_grp_fx[2] ); + Bits_grp_fx[1] = sub( sub( B_fx, Bits_grp_fx[0] ), Bits_grp_fx[2] ); /* Q0 */ move16(); } IF( LT_16( Bits_grp_fx[2], THR2 ) ) { - Bits_grp_fx[1] = add( Bits_grp_fx[1], Bits_grp_fx[2] ); + Bits_grp_fx[1] = add( Bits_grp_fx[1], Bits_grp_fx[2] ); /* Q0 */ move16(); Bits_grp_fx[2] = 0; move16(); @@ -690,16 +690,16 @@ void hq2_bit_alloc_har_fx( Word32 hq2_bit_alloc_fx( const Word32 L_band_energy[], /* i : band energy of each subband */ - const Word16 bands, /* i : total number of subbands in a frame */ - Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ - Word16 *bit_budget_fx, /* i/o: bit bugdet */ - Word16 *p2a_flags, /* i : HF tonal indicator */ - const Word16 weight_fx, /* i : weight */ - const Word16 band_width[], /* i : Sub band bandwidth */ - const Word16 num_bits, /* i : available bits */ - const Word16 hqswb_clas, /* i : HQ2 class information */ - const Word16 bwidth, /* i : input bandwidth */ - const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ + const Word16 bands, /* i : total number of subbands in a frame Q0*/ + Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. QRk*/ + Word16 *bit_budget_fx, /* i/o: bit bugdet Q0*/ + Word16 *p2a_flags, /* i : HF tonal indicator Q0*/ + const Word16 weight_fx, /* i : weight Q13*/ + const Word16 band_width[], /* i : Sub band bandwidth Q0*/ + const Word16 num_bits, /* i : available bits Q0*/ + const Word16 hqswb_clas, /* i : HQ2 class information Q0*/ + const Word16 bwidth, /* i : input bandwidth Q0*/ + const Word16 is_transient /* i : indicator HQ_TRANSIENT or not Q0*/ ) { Word16 j, k; @@ -728,9 +728,9 @@ Word32 hq2_bit_alloc_fx( Word32 L_THR1, L_THR2, L_THR3; - L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk ); - L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); - L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk ); + L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ + L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ + L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ /* Init Rk to non-zero values for bands to be allocated bits */ IF( LE_16( num_bits, HQ_16k40_BIT ) ) @@ -763,7 +763,7 @@ Word32 hq2_bit_alloc_fx( /*mvs2r( p2a_flags, Rk, bands ); */ FOR( k = 0; k < bands; k++ ) { - L_Rk[k] = L_shl( L_deposit_l( p2a_flags[k] ), SWB_BWE_LR_QRk ); + L_Rk[k] = L_shl( L_deposit_l( p2a_flags[k] ), SWB_BWE_LR_QRk ); /* QRk */ move32(); } } @@ -807,11 +807,11 @@ Word32 hq2_bit_alloc_fx( Qdiv = sub( sub( add( SWB_BWE_LR_QRk, exp_normd ), exp_normn ), 1 ); - L_Ravg = L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ); + L_Ravg = L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ); /* QRk */ exp_normd = norm_s( *bit_budget_fx ); exp_normd = sub( exp_normd, 1 ); - bit_budget_norm_fx = shl( *bit_budget_fx, exp_normd ); + bit_budget_norm_fx = shl( *bit_budget_fx, exp_normd ); /* exp_normd */ div_fx = 0; move16(); @@ -830,7 +830,7 @@ Word32 hq2_bit_alloc_fx( L_tmp = Mult_32_16( L_sub( L_shl( L_band_energy[k], sub( SWB_BWE_LR_QRk, SWB_BWE_LR_Qbe ) ), L_Ravg ), weight_fx ); /* SWB_BWE_LR_QRk + Q13 - 15 */ L_tmp = L_shl( L_tmp, 2 ); /* -> SWB_BWE_LR_QRk */ - L_Rk[k] = L_add( L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ), L_tmp ); + L_Rk[k] = L_add( L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ), L_tmp ); /* SWB_BWE_LR_QRk */ move32(); } } @@ -860,9 +860,9 @@ Word32 hq2_bit_alloc_fx( L_Rcalc = L_deposit_l( 0 ); /* find worst under-allocation */ - FOR( k = sub( bands, 1 ); k >= 0; k-- ) + FOR( k = bands - 1; k >= 0; k-- ) { - tmp_fx = s_min( band_width[k], s_max( 12, shr( band_width[k], 2 ) ) ); + tmp_fx = s_min( band_width[k], s_max( 12, shr( band_width[k], 2 ) ) ); /* Q0 */ L_dummy = L_sub( L_shl( L_deposit_l( tmp_fx ), SWB_BWE_LR_QRk ), L_Rk[k] ); /*SWB_BWE_LR_QRk */ test(); test(); @@ -927,14 +927,14 @@ Word32 hq2_bit_alloc_fx( test(); IF( EQ_16( hqswb_clas, HQ_NORMAL ) && LT_16( num_bits, HQ_16k40_BIT ) ) { - bit_budget_temp_fx = *bit_budget_fx; + bit_budget_temp_fx = *bit_budget_fx; /* Q0 */ move16(); FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) { test(); - IF( EQ_16( p2a_flags[add( sub( bands, NB_SWB_SUBBANDS ), k )], 1 ) && L_Rk[add( sub( bands, NB_SWB_SUBBANDS ), k )] == 0 ) + IF( EQ_16( p2a_flags[( bands - NB_SWB_SUBBANDS ) + k], 1 ) && L_Rk[( bands - NB_SWB_SUBBANDS ) + k] == 0 ) { - p2a_flags[add( sub( bands, NB_SWB_SUBBANDS ), k )] = 0; + p2a_flags[( bands - NB_SWB_SUBBANDS ) + k] = 0; move16(); bit_budget_temp_fx = sub( bit_budget_temp_fx, bits_lagIndices_modeNormal[k] ); } diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 2b696a4b1252b0ee4d649e8066ade64d494f88f1..f07dcd4be547e26ecc44000ac8381d260e1ca9d4 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -1029,8 +1029,8 @@ void computeDirectionVectors_fixed( e_x = sub( i_e, norm_x ); e_y = sub( i_e, norm_y ); e_z = sub( i_e, norm_z ); - temp1 = BASOP_Util_Add_Mant32Exp( Mult_32_32( scaled_x, scaled_x ), 2 * e_x, Mult_32_32( scaled_y, scaled_y ), 2 * e_y, &exp1 ); - intensityNorm = BASOP_Util_Add_Mant32Exp( temp1, exp1, Mult_32_32( scaled_z, scaled_z ), 2 * e_z, &intensityNorm_e ); + temp1 = BASOP_Util_Add_Mant32Exp( Mult_32_32( scaled_x, scaled_x ), shl( e_x, 1 ), Mult_32_32( scaled_y, scaled_y ), shl( e_y, 1 ), &exp1 ); + intensityNorm = BASOP_Util_Add_Mant32Exp( temp1, exp1, Mult_32_32( scaled_z, scaled_z ), shl( e_z, 1 ), &intensityNorm_e ); IF( LE_32( intensityNorm, EPSILON_FX ) ) { @@ -1048,12 +1048,12 @@ void computeDirectionVectors_fixed( } ELSE { - intensityNorm = ISqrt32( intensityNorm, &intensityNorm_e ); /*Q31-intensityNorm_e*/ - *( direction_vector_x++ ) = L_shl( Mult_32_32( scaled_x, intensityNorm ), e_x + intensityNorm_e - 1 ); /*Q30*/ + intensityNorm = ISqrt32( intensityNorm, &intensityNorm_e ); /*Q31-intensityNorm_e*/ + *( direction_vector_x++ ) = L_shl( Mult_32_32( scaled_x, intensityNorm ), sub( add( e_x, intensityNorm_e ), 1 ) ); /*Q30*/ intensity_real_x++; - *( direction_vector_y++ ) = L_shl( Mult_32_32( scaled_y, intensityNorm ), e_y + intensityNorm_e - 1 ); /*Q30*/ + *( direction_vector_y++ ) = L_shl( Mult_32_32( scaled_y, intensityNorm ), sub( add( e_y, intensityNorm_e ), 1 ) ); /*Q30*/ intensity_real_y++; - *( direction_vector_z++ ) = L_shl( Mult_32_32( scaled_z, intensityNorm ), e_z + intensityNorm_e - 1 ); /*Q30*/ + *( direction_vector_z++ ) = L_shl( Mult_32_32( scaled_z, intensityNorm ), sub( add( e_z, intensityNorm_e ), 1 ) ); /*Q30*/ intensity_real_z++; move32(); diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 5da92e9876c433ea565984dd0ce0f5e5e9d10d80..86e9e9e4753f3c78f62e324260427b8350e93541 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -343,13 +343,18 @@ ivas_error ivas_FB_mixer_open( { if ( fb_cfg->num_out_chans == 0 ) { +#ifndef IVAS_FLOAT_FIXED hFbMixer->ppFilterbank_inFR_re[i] = NULL; hFbMixer->ppFilterbank_inFR_im[i] = NULL; +#else + hFbMixer->ppFilterbank_inFR_re_fx[i] = NULL; + hFbMixer->ppFilterbank_inFR_im_fx[i] = NULL; +#endif } else { j = fb_cfg->remix_order[i]; - +#ifndef IVAS_FLOAT_FIXED if ( ( hFbMixer->ppFilterbank_inFR_re[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); @@ -359,8 +364,7 @@ ivas_error ivas_FB_mixer_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } - -#ifdef IVAS_FLOAT_FIXED +#else if ( ( hFbMixer->ppFilterbank_inFR_re_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); @@ -412,21 +416,6 @@ ivas_error ivas_FB_mixer_open( if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) { - float *pTemp_mem; - if ( ( pTemp_mem = (float *) malloc( sizeof( float ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); - } - for ( i = 0; i < fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < fb_cfg->num_in_chans; j++ ) - { - hFbMixer->prior_mixer[i][j] = pTemp_mem; - pTemp_mem += IVAS_MAX_NUM_BANDS; - set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); - } - } - Word32 *pTemp_mem_fx; if ( ( pTemp_mem_fx = (Word32 *) malloc( sizeof( Word32 ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) { @@ -441,6 +430,8 @@ ivas_error ivas_FB_mixer_open( set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); } } + hFbMixer->q_prior_mixer_fx = Q31; + move16(); } if ( !spar_reconfig_flag ) @@ -600,6 +591,7 @@ ivas_error ivas_FB_mixer_open_fx( ELSE { j = fb_cfg->remix_order[i]; + move16(); IF( ( hFbMixer->ppFilterbank_inFR_re_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) { @@ -611,27 +603,6 @@ ivas_error ivas_FB_mixer_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } } -#if 1 // TODO: To be removed later - if ( fb_cfg->num_out_chans == 0 ) - { - hFbMixer->ppFilterbank_inFR_re[i] = NULL; - hFbMixer->ppFilterbank_inFR_im[i] = NULL; - } - else - { - j = fb_cfg->remix_order[i]; - - if ( ( hFbMixer->ppFilterbank_inFR_re[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - - if ( ( hFbMixer->ppFilterbank_inFR_im[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - } -#endif } IF( EQ_16( fb_cfg->active_w_mixing, -1 ) ) @@ -677,22 +648,8 @@ ivas_error ivas_FB_mixer_open_fx( set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); } } -#if 1 // TODO: To be removed later - float *pTemp_mem; - if ( ( pTemp_mem = (float *) malloc( sizeof( float ) * fb_cfg->num_out_chans * max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ) * IVAS_MAX_NUM_BANDS ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); - } - for ( i = 0; i < fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < fb_cfg->num_in_chans; j++ ) - { - hFbMixer->prior_mixer[i][j] = pTemp_mem; - pTemp_mem += IVAS_MAX_NUM_BANDS; - set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); - } - } -#endif + hFbMixer->q_prior_mixer_fx = Q31; + move16(); } IF( !spar_reconfig_flag ) @@ -816,13 +773,13 @@ void ivas_FB_mixer_close( if ( fb_cfg->num_out_chans > 0 ) { j = fb_cfg->remix_order[i]; - +#ifndef IVAS_FLOAT_FIXED free( hFbMixer->ppFilterbank_inFR_re[j] ); hFbMixer->ppFilterbank_inFR_re[j] = NULL; free( hFbMixer->ppFilterbank_inFR_im[j] ); hFbMixer->ppFilterbank_inFR_im[j] = NULL; -#ifdef IVAS_FLOAT_FIXED +#else free( hFbMixer->ppFilterbank_inFR_re_fx[j] ); hFbMixer->ppFilterbank_inFR_re_fx[j] = NULL; @@ -853,12 +810,6 @@ void ivas_FB_mixer_close( hFbMixer->ppFilterbank_prior_input_fx[i] = NULL; } #endif - if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) - { - free( hFbMixer->prior_mixer[0][0] ); - hFbMixer->prior_mixer[0][0] = NULL; - } - if ( !spar_reconfig_flag ) { if ( fb_cfg->num_out_chans > 0 ) @@ -1056,7 +1007,7 @@ void ivas_FB_mixer_close_fx( * * PCM ingest block *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_fb_mixer_pcm_ingest( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float *pcm_in[], /* i : input audio channels */ @@ -1090,7 +1041,7 @@ void ivas_fb_mixer_pcm_ingest( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_fb_mixer_pcm_ingest_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 *pcm_in[], /* i : input audio channels Qq_data_fix[] */ @@ -1167,7 +1118,7 @@ void ivas_fb_mixer_pcm_ingest_fx( * * *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_fb_mixer_update_prior_input( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float *pcm_in[], /* i : input audio channels */ @@ -1185,8 +1136,7 @@ void ivas_fb_mixer_update_prior_input( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_fb_mixer_update_prior_input_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 *pcm_in_fx[], /* i : input audio channels */ @@ -1266,7 +1216,7 @@ void ivas_fb_mixer_get_windowed_fr_fx( return; } -#endif +#else void ivas_fb_mixer_get_windowed_fr( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ @@ -1311,7 +1261,7 @@ void ivas_fb_mixer_get_windowed_fr( return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_fb_mixer_cross_fading() diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b63a975d3ba359b7cd823d92288c735e995d05e3..6dc3b8f552d224148ae362539e28d7c688f8938a 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -829,8 +829,8 @@ void smooth_dft2td_transition( /*! r: flag indicating a valid bitrate */ -int16_t is_IVAS_bitrate( - const int32_t ivas_total_brate /* i : IVAS total bitrate */ +Word16 is_IVAS_bitrate_fx( + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ); int16_t is_DTXrate( @@ -4648,22 +4648,6 @@ void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ ); -#ifndef IVAS_FLOAT_FIXED -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 */ - 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_vad, - const int16_t nchan_inp, - const int16_t sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const int16_t dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const int16_t dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -); -#endif - void ivas_compute_spar_params( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], @@ -4887,6 +4871,16 @@ void ivas_cov_smooth_process( #endif /* Transient detector module */ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_transient_det_open_fx( + ivas_trans_det_state_t **hTranDet, /* i/o: Transient detector handle */ + const Word32 sampling_rate /* i : sampling rate */ +); + +void ivas_transient_det_close_fx( + ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ +); +#else ivas_error ivas_transient_det_open( ivas_trans_det_state_t **hTranDet, /* i/o: Transient detector handle */ const int32_t sampling_rate /* i : sampling rate */ @@ -4895,6 +4889,7 @@ ivas_error ivas_transient_det_open( void ivas_transient_det_close( ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ ); +#endif void ivas_transient_det_process( ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle */ @@ -5704,6 +5699,15 @@ void ivas_mcmasa_param_est_enc( const int16_t nchan_inp /* i : Number of input channels */ ); +#endif + +#ifdef IVAS_FLOAT_FIXED +void ivas_mcmasa_dmx_modify_fx( + const Word16 n_samples, /* i : input frame length in samples */ + Word32 dmx_fx[][L_FRAME48k + NS2SA(48000, IVAS_FB_ENC_DELAY_NS)], /* i/o: downmix signal to be transformed into another format Qx*/ + const Word16 n_chnls_dmx_old, /* i : number of downmix channels in the old format Q0*/ + const Word16 n_chnls_dmx_new /* i : number of downmix channels in the target format Q0*/ +); #endif void ivas_mcmasa_dmx_modify( const int16_t n_samples, /* i : input frame length in samples */ @@ -6232,15 +6236,6 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); -#ifndef IVAS_FLOAT_FIXED -void ivas_fb_mixer_process( - IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - float ***mixer_mat, /* i : mixer matrix */ - float **ppOut_pcm, /* o : output audio channels */ - const int16_t frame_len, /* i : frame length in samples */ - int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ -); -#endif void ivas_fb_mixer_get_in_out_mapping( const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index fea7eca613a147712a07330c417fd72c84da99de..7c0458fa2b03309a402496267a0b41ddfc92e3e6 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3224,10 +3224,10 @@ void computeDirectionVectors_fixed( UWord8 ivas_masa_surrcoh_signicant_fx( - Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ - Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ - const Word16 nSubFrames, /* i : Number of sub frames */ - const Word16 nBands /* i : Number of frequency bands */ + Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence Q31 */ + Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio Q31 */ + const Word16 nSubFrames, /* i : Number of sub frames */ + const Word16 nBands /* i : Number of frequency bands */ ); /*----------------------------------------------------------------------------------* @@ -3406,9 +3406,9 @@ void ivas_param_mc_enc_fx( const Word16 input_frame /* i : input frame length */ ); void ivas_merge_masa_transports_fx( - Word32 data_in_f1_fx[][L_FRAME48k], - Word32 *data_in_f2_fx[], - Word32 *data_out_f_fx[], + Word32 data_in_f1_fx[][L_FRAME48k], // Qx + Word32 *data_in_f2_fx[], // Qx + Word32 *data_out_f_fx[], // Qx const Word16 input_frame, const Word16 num_transport_channels ); @@ -5348,11 +5348,12 @@ ivas_error ivas_spar_md_enc_process_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const Word16 dtx_vad, const Word16 nchan_inp, - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -); + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word32 *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ + Word16 *q_prior_mixer, /* i/o : q for prior mixer_matrix */ + const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ + const Word16 dirac_mono_flag, /* i : flag to indicate mono only mode in SBA */ + const Word16 nchan_out ); Word16 ivas_get_spar_dec_md_num_subframes( const Word16 sba_order, /* i : Ambisonic (SBA) order */ diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 88821d0b32a954663ac7554d7fc1492b6cf9f220..25815afe3970ad3ebdf958cf504588b93defdf0f 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -69,24 +69,6 @@ static void ivas_qmetadata_free_memory( IVAS_QMETADATA_HANDLE hQMetaData ); * Allocate Q Metadata handle *-----------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_qmetadata_open( - IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ -) -{ - /* allocate MetaData handle */ - IF( ( *hQMetaData = (IVAS_QMETADATA_HANDLE) malloc( sizeof( IVAS_QMETADATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" ); - } - - ( *hQMetaData )->q_direction = NULL; - ( *hQMetaData )->surcoh_band_data = NULL; - ( *hQMetaData )->bandMap = NULL; - - return IVAS_ERR_OK; -} -#else ivas_error ivas_qmetadata_open( IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ ) @@ -103,8 +85,6 @@ ivas_error ivas_qmetadata_open( return IVAS_ERR_OK; } -#endif - /*-----------------------------------------------------------------------* * ivas_qmetadata_allocate_memory() diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 74d3c01d30653d130a3350415687ea4ea46b42af..bae0da15f6bd1407280c85cb58bf989d67271cd2 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1129,9 +1129,8 @@ static void ivas_get_pred_coeffs_enc_fx( num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); // Q=31-num_f_e - sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha64_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 - val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 - move16(); + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha64_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 + val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); // q=31-val_e sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ) /* reducing the Q by 2 instead of multiplication by 4*/, &val_e ); // q=31-val_e // val_e = norm_l( sqrt_val ); @@ -1193,6 +1192,11 @@ static void ivas_get_pred_coeffs_enc_fx( move32(); dm_v_re_q[i][b] = sub( add( add( dm_v_re_q[i][b], DM_F_q[b] ), tmp_shift ), 32 ); move16(); + if ( ppDM_Fv_re[i][b] == 0 ) + { + dm_v_re_q[i][b] = Q31; + move16(); + } *q_pred_coeffs = s_min( *q_pred_coeffs, q_ppPred_coeffs_re[i][b] ); move16(); @@ -3892,7 +3896,7 @@ void ivas_compute_spar_params_enc_fx( { pWscale[b] = 1; move32(); - q_Wscale[b] = 15; + q_Wscale[b] = Q31; move16(); } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index fc0f2159db636fff432f712c615547f9a9e460b0..d6dd690fbca436e822398090c17810976f5791bc 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -853,11 +853,11 @@ typedef struct ivas_fb_mixer_state_structure int16_t num_diff_bands; ivas_filterbank_t *pFb; - +#ifndef IVAS_FLOAT_FIXED float *ppFilterbank_inFR_re[IVAS_MAX_FB_MIXER_IN_CH]; float *ppFilterbank_inFR_im[IVAS_MAX_FB_MIXER_IN_CH]; +#endif float *ppFilterbank_prior_input[IVAS_MAX_FB_MIXER_IN_CH]; - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; #ifdef IVAS_FLOAT_FIXED Word32 *ppFilterbank_inFR_re_fx[IVAS_MAX_FB_MIXER_IN_CH]; diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 20cce673c507c610971d524c534ab5b2474c9ed7..88a0200ebff48a4e26ad166aa48f2b86ec419cbc 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -3197,27 +3197,6 @@ void v_sort_ind_fixed( *-------------------------------------------------------------------*/ /*! r: flag indicating a valid bitrate */ -int16_t is_IVAS_bitrate( - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -) -{ - int16_t j; - - j = SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES; /* skip NO_DATA and SID bitrates */ - while ( j < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[j] ) - { - j++; - } - - if ( j >= SIZE_IVAS_BRATE_TBL ) - { - return 0; - } - - return 1; -} - -#ifdef IVAS_FLOAT_FIXED Word16 is_IVAS_bitrate_fx( const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) @@ -3241,7 +3220,6 @@ Word16 is_IVAS_bitrate_fx( return 1; } -#endif /*-------------------------------------------------------------------* * is_DTXrate() diff --git a/lib_com/ivas_transient_det.c b/lib_com/ivas_transient_det.c index 65bb7f72b4b2fef8f0d78d1947372705b0fa3862..019874fc9e30b3ca7c6a38b036aff8861036b2ee 100644 --- a/lib_com/ivas_transient_det.c +++ b/lib_com/ivas_transient_det.c @@ -350,7 +350,26 @@ static void ivas_transient_det_init( * * Allocate and initialize SPAR TD handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_transient_det_open_fx( + ivas_trans_det_state_t **hTranDet_in, /* i/o: Transient detector handle */ + const Word32 sampling_rate /* i : sampling rate */ +) +{ + ivas_trans_det_state_t *hTranDet; + + IF( ( hTranDet = (ivas_trans_det_state_t *) malloc( sizeof( ivas_trans_det_state_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR TD\n" ); + } + ivas_transient_det_init( hTranDet, sampling_rate ); + + *hTranDet_in = hTranDet; + + return IVAS_ERR_OK; +} +#else ivas_error ivas_transient_det_open( ivas_trans_det_state_t **hTranDet_in, /* i/o: Transient detector handle */ const Word32 sampling_rate /* i : sampling rate */ @@ -358,7 +377,7 @@ ivas_error ivas_transient_det_open( { ivas_trans_det_state_t *hTranDet; - IF( ( hTranDet = (ivas_trans_det_state_t *) malloc( sizeof( ivas_trans_det_state_t ) ) ) == NULL ) + if ( ( hTranDet = (ivas_trans_det_state_t *) malloc( sizeof( ivas_trans_det_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR TD\n" ); } @@ -369,6 +388,7 @@ ivas_error ivas_transient_det_open( return IVAS_ERR_OK; } +#endif /*------------------------------------------------------------------------- @@ -376,7 +396,23 @@ ivas_error ivas_transient_det_open( * * Deallocate and initialize Transient detector handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_transient_det_close_fx( + ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ +) +{ + test(); + IF( hTranDet == NULL || *hTranDet == NULL ) + { + return; + } + + free( *hTranDet ); + *hTranDet = NULL; + return; +} +#else void ivas_transient_det_close( ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ ) @@ -392,6 +428,7 @@ void ivas_transient_det_close( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* diff --git a/lib_com/prot.h b/lib_com/prot.h index 1f54c2b1b832446380a163598dfa86e4535c2863..d15bb767d443973c12a4ee00e5226134b10b5476 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -522,11 +522,6 @@ ivas_error push_next_bits( #endif // IVAS_FLOAT_FIXED /*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -); - Word16 get_ivas_max_num_indices_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -538,11 +533,6 @@ int16_t get_BWE_max_num_indices( ); /*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices_metadata( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -); - Word16 get_ivas_max_num_indices_metadata_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -9940,11 +9930,6 @@ int16_t is_EVS_bitrate( int16_t *Opt_AMR_WB /* i : AMR-WB IO flag */ ); -/*! r: codec mode */ -int16_t get_codec_mode( - const int32_t total_brate /* i : total bitrate */ -); - int16_t getTcxonly_ivas( const int16_t element_mode, /* i : IVAS element mode */ const int32_t total_brate, /* i : total bitrate */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index de27c37c24f68fa2ab76438d6c16f3848d21ffe3..3239613af43d19cdbcf2674002d70f588d4d8764 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1262,13 +1262,6 @@ void indices_to_serial_generic( Word16 *pFrame_size /* i/o: number of bits in the binary encoded access unit [bits] */ ); -void dec_prm_core( - Decoder_State *st ); - -void decision_matrix_core_dec( - Decoder_State *st /* i/o: decoder state structure */ -); - Word16 BRATE2IDX_fx( Word32 brate ); Word16 BRATE2IDX16k_fx( Word32 brate ); @@ -1743,20 +1736,20 @@ void Comp_and_apply_gain_ivas_fx( void pre_echo_att_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ); void pre_echo_att_ivas_fx( Word32 *Last_frame_ener_fx, /* i/o: Energy of the last frame 2*Q_new+1*/ Word16 *exc_fx, /* i/o: Excitation of the current frame Q_new*/ - const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) */ + const Word16 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ); // wtda_fx.c void tcx_get_windows_mode1( @@ -2163,21 +2156,21 @@ hq2_bit_alloc_fx.c /========================================================================================================*/ void Bits2indvsb_fx( - const Word32 *L_be, /* i : Q14 Band Energy of sub-band */ + const Word32 *L_be, /* i : Qbe Band Energy of sub-band */ const Word16 start_band, /* i : Q0 start band indices */ const Word16 end_band, /* i : Q0 end band indices */ const Word16 Bits, /* i : Q0 Total number of bits allocated to a group */ - const Word32 L_Bits_needed, /* i : Q0 smallest bit number for allocation in group */ - Word32 *L_Rsubband, /* o : Q18 bit allocation of sub-band */ + const Word32 L_Bits_needed, /* i : QRk smallest bit number for allocation in group */ + Word32 *L_Rsubband, /* o : QRk bit allocation of sub-band */ Word16 *p2aflags_fx /* i/o: Q0 peaky/noise subband flag */ ); void hq2_bit_alloc_har_fx( - const Word32 *L_y, /* i : Q14 band energy of sub-vectors */ + const Word32 *L_y, /* i : Qbe band energy of sub-vectors */ Word16 B_fx, /* i : Q0 number of available bits */ const Word16 N_fx, /* i : Q0 number of sub-vectors */ - Word32 *L_Rsubband, /* o : Q18 sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ + Word32 *L_Rsubband, /* o : QRk sub-band bit-allocation vector */ + Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ const Word32 L_core_brate, /* i : Q0 core bit rate */ Word16 p2a_flags_fx[], /* i/o: Q0 p2a_flags */ const Word16 band_width_fx[] /* i : Q0 table of band_width */ @@ -2185,16 +2178,16 @@ void hq2_bit_alloc_har_fx( Word32 hq2_bit_alloc_fx( const Word32 L_band_energy[], /* i : band energy of each subband */ - const Word16 bands, /* i : total number of subbands in a frame */ - Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. */ - Word16 *bit_budget_fx, /* i/o: bit bugdet */ - Word16 *p2a_flags, /* i : HF tonal indicator */ - const Word16 weight_fx, /* i : weight */ - const Word16 band_width[], /* i : Sub band bandwidth */ - const Word16 num_bits, /* i : available bits */ - const Word16 hqswb_clas, /* i : HQ2 class information */ - const Word16 bwidth, /* i : i bandwidth */ - const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ + const Word16 bands, /* i : total number of subbands in a frame Q0*/ + Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. QRk*/ + Word16 *bit_budget_fx, /* i/o: bit bugdet Q0*/ + Word16 *p2a_flags, /* i : HF tonal indicator Q0*/ + const Word16 weight_fx, /* i : weight Q13*/ + const Word16 band_width[], /* i : Sub band bandwidth Q0*/ + const Word16 num_bits, /* i : available bits Q0*/ + const Word16 hqswb_clas, /* i : HQ2 class information Q0*/ + const Word16 bwidth, /* i : input bandwidth Q0*/ + const Word16 is_transient /* i : indicator HQ_TRANSIENT or not Q0*/ ); void reordvct_fx( @@ -3919,6 +3912,7 @@ int16_t get_cng_mode( ); // core_com_config.c +/*! r: codec mode */ Word16 get_codec_mode( const Word32 total_brate /* i : total bitrate */ ); @@ -9192,38 +9186,44 @@ void dlpc_bfi( // guided_plc_util_fx.c void getLookAheadResSig( - Word16 *speechLookAhead, - Word16 *A_3Q12, - Word16 *res, - const Word16 L_frame, - const Word16 numSubFrame ); + Word16 *speechLookAhead, /* Qx */ + Word16 *A_3Q12, /* 3Q12 */ + Word16 *res, /* Qx */ + const Word16 L_frame, /* Q0 */ + const Word16 numSubFrame /* Q0 */ +); void updateLSFForConcealment( PLC_ENC_EVS_HANDLE decState, - Word16 *lsf_14Q1 ); + Word16 *lsf_14Q1 /* 14Q1 */ +); void getConcealedLP( PLC_ENC_EVS_HANDLE memDecState, - Word16 *AqCon, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ); + Word16 *AqCon, /* 14Q1 */ + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +); void getConcealedLSF( PLC_ENC_EVS_HANDLE memDecState, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ); + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +); void RecLpcSpecPowDiffuseLc( - Word16 *lspq, - Word16 *lsp_old, - Word16 *lsfq, + Word16 *lspq, /* Q15 */ + Word16 *lsp_old, /* Q15 */ + Word16 *lsfq, /* Q2.56 */ Decoder_State *st, - const Word16 reset_q ); + const Word16 reset_q /* Q0 */ +); void modify_lsf( - Word16 *lsf, - const Word16 n, - const Word32 sr_core, - const Word16 reset_q ); + Word16 *lsf, /* Q14 */ + const Word16 n, /* Q0 */ + const Word32 sr_core, /* Q0 */ + const Word16 reset_q /* Q0 */ +); // er_dec_tcx_fx.c void con_tcx_fx( diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 9fb4736f18ba015607c1dfbdf89f572f8a940b5d..c36c6eabd7e89d7dca577740b5e8f8e497a545c0 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -39,6 +39,7 @@ #include "ivas_prot.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#include "math.h" /*-------------------------------------------------------------------* * ivas_corecoder_enc_reconfig() * @@ -504,7 +505,12 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { Word16 n, sce_id, cpe_id; Word16 len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing; - float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; + + Word32 input_buff_fx[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; + FOR( int i = 0; i < MCT_MAX_BLOCKS; i++ ) + { + set32_fx( input_buff_fx[i], 0, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) ); + } BSTR_ENC_HANDLE hBstr; Word16 i, nb_bits; Indice temp_ind_list[MAX_NUM_IND_TEMP_LIST]; @@ -531,7 +537,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( nchan_transport_real = st_ivas->nchan_transport; move16(); - if ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { nchan_transport_real = add( nchan_transport_real, st_ivas->hEncoderConfig->nchan_ism ); } @@ -571,7 +577,6 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, tmp ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - // 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() */ move32(); } } @@ -621,9 +626,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( nb_bits = 0; move16(); - test(); WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { + test(); IF( hBstr->ind_list[i].nb_bits > 0 ) { temp_ind_list[i].id = hBstr->ind_list[i].id; @@ -653,28 +658,95 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 q_com_sce = 0; + Word16 q_com_cpe = 0; + + Word16 gb = find_guarded_bits_fx( len_inp_memory ); + IF( nSCE_old > 0 ) + { + float max_val = 0.0f; + for ( int k = 0; k < nSCE_old; k++ ) + { + for ( i = 0; i < len_inp_memory; i++ ) + { + max_val = max( max_val, (float) fabs( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff[i] ) ); + } + } + q_com_sce = L_get_q1( max_val ) - gb; + } + + IF( nCPE_old > 0 ) + { + float max_val = 0.0f; + FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + for ( i = 0; i < len_inp_memory; i++ ) + { + max_val = max( max_val, (float) fabs( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff[i] ) ); + } + } + } + q_com_cpe = L_get_q1( max_val ) - gb; + } + + Word16 q_com = min( q_com_sce, q_com_cpe ); + IF( nSCE_old > 0 ) + { + for ( int k = 0; k < nSCE_old; k++ ) + { + st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = q_com; + } + for ( int k = 0; k < nSCE_old; k++ ) + { + floatToFixed_arrL( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32, len_inp_memory ); + } + } + + IF( nCPE_old > 0 ) + { + + FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = q_com; + } + } + FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + floatToFixed_arrL( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32, len_inp_memory ); + } + } + } +#endif test(); test(); IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_16( last_mc_mode, MC_MODE_MCMASA ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { /* within McMASA we can modify the transport signals when switching */ /* copy earlier dmx buffers */ + IF( nSCE_old > 0 ) { - set_zero( input_buff[0], len_inp_memory ); - mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory ); + set32_fx( input_buff_fx[0], 0, len_inp_memory ); + Copy32( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[0], len_inp_memory ); } FOR( n = 0; n < CPE_CHANNELS; n++ ) { - set_zero( input_buff[n + 1], len_inp_memory ); + set32_fx( input_buff_fx[n + 1], 0, len_inp_memory ); IF( nCPE_old > 0 ) { - mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory ); + Copy32( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[n + 1], len_inp_memory ); } } - ivas_mcmasa_dmx_modify( len_inp_memory, input_buff, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); + ivas_mcmasa_dmx_modify_fx( len_inp_memory, input_buff_fx, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); n_CoreCoder_existing = 0; move16(); @@ -690,9 +762,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* save input audio buffers */ IF( GT_16( n_CoreCoder_existing, sce_id ) ) { - mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory ); + Copy32( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[sce_id], len_inp_memory ); } - destroy_sce_enc( st_ivas->hSCE[sce_id], ( EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) && !st_ivas->hEncoderConfig->stereo_dmx_evs ) ); st_ivas->hSCE[sce_id] = NULL; } @@ -704,14 +775,12 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { IF( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) { - mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); + Copy32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); } } - destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); st_ivas->hCPE[cpe_id] = NULL; } - test(); IF( LE_16( st_ivas->nCPE, 1 ) && st_ivas->hMCT != NULL ) { @@ -752,9 +821,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( test(); IF( GT_16( n_CoreCoder_existing, sce_id ) && NE_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { - mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, len_inp_memory ); } - test(); /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ IF( sce_id > 0 || EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) @@ -785,7 +853,14 @@ ivas_error ivas_corecoder_enc_reconfig_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { copy_encoder_config_fx( 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( GT_16( st_ivas->nCPE, 1 ) ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate; + } + ELSE + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, 1 ); // CPE_CHANNELS + } move32(); test(); @@ -818,9 +893,10 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* propagate input audio buffers */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { + IF( GT_16( n_CoreCoder_existing, add( i_mult( cpe_id, CPE_CHANNELS ), n ) ) ) { - mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, len_inp_memory ); } } @@ -829,7 +905,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ test(); test(); - IF( add( i_mult( cpe_id, CPE_CHANNELS ), n ) > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ) + IF( add( i_mult( cpe_id, CPE_CHANNELS ), n ) > 0 || ( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->nSCE > 0 ) ) { reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot ); } @@ -850,9 +926,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); IF( st_ivas->nSCE > 0 ) { - test(); WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { + test(); IF( temp_ind_list[i].nb_bits > 0 ) { st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; @@ -876,6 +952,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { + test(); IF( temp_ind_list[i].nb_bits > 0 ) { st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; @@ -895,26 +972,42 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } - + test(); IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { /* restore modified transport signal */ IF( st_ivas->nSCE ) { - mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, len_inp_memory ); } IF( st_ivas->nCPE ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - mvr2r( input_buff[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, len_inp_memory ); } } } test(); test(); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( st_ivas->nSCE ) + { + fixedToFloat_arrL( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, q_com, len_inp_memory ); + } + + IF( st_ivas->nCPE ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + fixedToFloat_arrL( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, q_com, len_inp_memory ); + } + } +#endif + IF( GT_16( st_ivas->nCPE, 1 ) && LE_16( nCPE_old, 1 ) ) { IF( EQ_16( nCPE_old, 1 ) ) @@ -986,17 +1079,11 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; move32(); st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[0]->element_brate, 42949673 ) ) /* 1/50 in Q31*/; // ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); -#ifndef IVAS_FLOAT_FIXED - st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - L_mult0( 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 ); -#else + st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent_fx( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, L_mult0( 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 ); -#endif move16(); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 1a5a95af5e8def36494041f7ca87921bb0a67150..bb6a9dc8408de3ca68b96c9a8c25a638b02a23bc 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -773,8 +773,8 @@ ivas_error ivas_enc( /*----------------------------------------------------------------* * Encoding *----------------------------------------------------------------*/ - - if ( ivas_format == STEREO_FORMAT ) + test(); + IF( EQ_32( ivas_format, STEREO_FORMAT ) ) { st_ivas->hCPE[0]->element_brate = ivas_total_brate; if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) @@ -782,7 +782,7 @@ ivas_error ivas_enc( return error; } } - else if ( ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { /* select ISM format mode; reconfigure the ISM format encoder */ if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) @@ -968,9 +968,7 @@ ivas_error ivas_enc( v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } -#endif -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) { floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); @@ -985,65 +983,53 @@ ivas_error ivas_enc( fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } #endif -#else - /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif // IVAS_FLOAT_FIXED set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); idx_separated_object = 0; + move16(); data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; data_separated_object_fx = data_fx[hEncoderConfig->nchan_ism + CPE_CHANNELS]; /* put audio object data in SCE's */ - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - /* Estimate MASA parameters for the objects */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; - int16_t j; - int16_t nchan_transport = st_ivas->nchan_transport; - int16_t nchan_ism = hEncoderConfig->nchan_ism; - int16_t norm_data_in = MAX16B; - for ( j = 0; j < nchan_ism + nchan_transport; j++ ) + /* Scaling data_fx */ { - for ( int k = 0; k < input_frame; k++ ) + Word16 norm_data_in = MAX16B; + FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) { - data_fx[j][k] = float_to_fix( data_f[j][k], st_ivas->q_data_fx ); + norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[i], input_frame ) ); } - norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[j], input_frame ) ); - } - norm_data_in -= 6; /*guard bit is 3->to handle overflow in cldfbAnalysis*/ - for ( j = 0; j < nchan_ism + nchan_transport; j++ ) - { - Scale_sig32( data_fx[j], input_frame, norm_data_in ); + norm_data_in = sub( norm_data_in, 6 ); /*guard bit is 3->to handle overflow in cldfbAnalysis*/ + FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) + { + scale_sig32( data_fx[i], input_frame, norm_data_in ); + } + st_ivas->q_data_fx = add( st_ivas->q_data_fx, norm_data_in ); + move16(); } - st_ivas->q_data_fx = st_ivas->q_data_fx + norm_data_in; - for ( i = 0; i < nchan_ism; i++ ) +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; + for ( i = 0; i < hEncoderConfig->nchan_ism; i++ ) { floatToFixed_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } #endif + + /* Estimate MASA parameters for the objects */ ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_ism; i++ ) + for ( i = 0; i < hEncoderConfig->nchan_ism; i++ ) { fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - for ( i = 0; i < nchan_ism + nchan_transport; i++ ) + for ( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) { fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); } @@ -1053,39 +1039,37 @@ ivas_error ivas_enc( /* Encode ISMs transport channels */ n = 0; - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + move16(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ + IF( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ { return error; } } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { -#ifdef IVAS_FLOAT_FIXED flag_omasa_ener_brate = ivas_omasa_ener_brate_fx( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); -#else - flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); -#endif // IVAS_FLOAT_FIXED /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } n = st_ivas->hEncoderConfig->nchan_ism; + move16(); } hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - if ( st_ivas->nSCE > 0 ) + IF( st_ivas->nSCE > 0 ) { /* update pointer to the buffer of indices (ISM indices were alredy written) */ hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; @@ -1108,14 +1092,14 @@ ivas_error ivas_enc( ); /* Encode MASA transport channels */ - if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { - int16_t planar_sba_orig; + Word16 planar_sba_orig; planar_sba_orig = hEncoderConfig->sba_planar; #ifdef IVAS_FLOAT_FIXED /* Analyze objects and determine needed audio signals */ @@ -1200,10 +1184,10 @@ ivas_error ivas_enc( } } } - else if ( EQ_32( ivas_format, MC_FORMAT ) ) + ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ - if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1239,14 +1223,14 @@ ivas_error ivas_enc( fixedToFloat_arrL( data_fx[LFE_CHANNEL], data_f[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); #endif - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { /* encode MC ParamUpmix parameters and write bitstream */ #ifdef IVAS_FLOAT_FIXED @@ -1292,7 +1276,7 @@ ivas_error ivas_enc( return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { /* encode Parametric MC parameters and write bitstream */ #ifdef IVAS_FLOAT_FIXED @@ -1334,72 +1318,65 @@ ivas_error ivas_enc( } } } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { if ( st_ivas->hMcMasa->separateChannelEnabled ) { hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */ } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_data = Q8; - for ( i = 0; i < nchan_inp; i++ ) + + FOR( i = 0; i < nchan_inp; i++ ) { - floatToFixed_arrL32( data_f[i], data_fx[i], q_data, input_frame ); + scale_sig32( data_fx[i], input_frame, Q8 - Q11 ); // Q11 -> Q8 } -#endif - ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, q_data ); + st_ivas->q_data_fx = Q8; + move16(); + + ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, st_ivas->q_data_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < nchan_inp; i++ ) { - fixedToFloat_arrL( data_fx[i], data_f[i], q_data, input_frame ); + fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); } - Word32 ii, jj; - Word16 nBands = st_ivas->hMcMasa->nbands; - Word16 nBlocks = MAX_PARAM_SPATIAL_SUBFRAMES; - FOR( ii = 0; ii < nBands; ii++ ) +#endif + /* Scaling down the Q-factor of energy_ratio_fx from Q31 to Q30 */ + FOR( i = 0; i < st_ivas->hMcMasa->nbands; i++ ) { - FOR( jj = 0; jj < nBlocks; jj++ ) - { - st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj] = L_shr( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], 1 ); // Q31 -> Q30 - } + scale_sig32( st_ivas->hQMetaData->q_direction[0].band_data[i].energy_ratio_fx, MAX_PARAM_SPATIAL_SUBFRAMES, -1 ); // Q31 -> Q30 } -#endif -#else - ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); -#endif + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->hMcMasa->separateChannelEnabled ) + IF( st_ivas->hMcMasa->separateChannelEnabled ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else + ELSE { - if ( st_ivas->nSCE == 1 ) + IF( EQ_16( st_ivas->nSCE, 1 ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 3114ae478b1ae28ca579e6152491e8ef55098e3d..e0fd588022d89bfc41c396f7ad419ae166654b2b 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -567,7 +567,11 @@ void ivas_initialize_handles_enc( st_ivas->hCPE[i] = NULL; } +#ifdef IVAS_FLOAT_FIXED + st_ivas->mem_hp20_in_fx = NULL; +#else st_ivas->mem_hp20_in = NULL; +#endif /* ISM metadata handles */ FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) @@ -711,7 +715,7 @@ ivas_error ivas_init_encoder( *-----------------------------------------------------------------*/ /* set the maximum allowed number of indices in the list */ - st_ivas->ivas_max_num_indices = get_ivas_max_num_indices( ivas_format, ivas_total_brate ); + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( ivas_format, ivas_total_brate ); /* allocate buffer of indices */ if ( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) @@ -726,7 +730,7 @@ ivas_error ivas_init_encoder( } /* set the maximum allowed number of metadata indices in the list */ - st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); /* allocate buffer of metadata indices */ if ( st_ivas->ivas_max_num_indices_metadata > 0 ) @@ -765,7 +769,7 @@ ivas_error ivas_init_encoder( test(); IF( NE_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ) { - IF( NE_32( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -817,7 +821,7 @@ ivas_error ivas_init_encoder( for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - if ( ( error = create_sce_enc( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) + if ( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) { return error; } @@ -1260,6 +1264,7 @@ ivas_error ivas_init_encoder( n = getNumChanAnalysis_fx( st_ivas ); #endif +#ifndef IVAS_FLOAT_FIXED if ( n > 0 ) { if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) @@ -1281,7 +1286,7 @@ ivas_error ivas_init_encoder( set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); } -#ifdef IVAS_FLOAT_FIXED +#else IF( n > 0 ) { IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) @@ -1321,41 +1326,52 @@ ivas_error ivas_init_encoder_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); hEncoderConfig = st_ivas->hEncoderConfig; ivas_format = hEncoderConfig->ivas_format; + move32(); input_Fs = hEncoderConfig->input_Fs; + move32(); ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + move32(); IF( NE_16( ivas_format, MONO_FORMAT ) ) { /* In IVAS, ensure that minimum coded bandwidth is WB */ hEncoderConfig->max_bwidth = extract_l( L_max( hEncoderConfig->max_bwidth, WB ) ); + move16(); } st_ivas->ism_mode = ISM_MODE_NONE; + move32(); st_ivas->mc_mode = MC_MODE_NONE; + move32(); st_ivas->nchan_transport = -1; + move16(); /*-----------------------------------------------------------------* * Allocate floating-point input audio buffers *-----------------------------------------------------------------*/ nchan_inp_buff = hEncoderConfig->nchan_inp; + move16(); IF( EQ_16( ivas_format, MONO_FORMAT ) ) { nchan_inp_buff = 0; + move16(); } ELSE IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { IF( EQ_16( sub( hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) /* mono is duplicated in monoMASA */ { - nchan_inp_buff++; + nchan_inp_buff = add( nchan_inp_buff, 1 ); } - nchan_inp_buff++; /* for *data_separated_object */ + nchan_inp_buff = add( nchan_inp_buff, 1 ); /* for *data_separated_object */ } #if 1 /* To be removed */ FOR( n = 0; n < nchan_inp_buff; n++ ) @@ -1391,6 +1407,7 @@ ivas_error ivas_init_encoder_fx( /* set the maximum allowed number of indices in the list */ st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( ivas_format, ivas_total_brate ); + move16(); /* allocate buffer of indices */ IF( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) @@ -1402,11 +1419,12 @@ ivas_error ivas_init_encoder_fx( FOR( i = 0; i < st_ivas->ivas_max_num_indices; i++ ) { st_ivas->ind_list[i].nb_bits = -1; + move16(); } /* set the maximum allowed number of metadata indices in the list */ st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); - + move16(); /* allocate buffer of metadata indices */ IF( st_ivas->ivas_max_num_indices_metadata > 0 ) { @@ -1419,6 +1437,7 @@ ivas_error ivas_init_encoder_fx( FOR( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ ) { st_ivas->ind_list_metadata[i].nb_bits = -1; + move16(); } } ELSE @@ -1429,7 +1448,7 @@ ivas_error ivas_init_encoder_fx( /*-----------------------------------------------------------------* * Allocate and initialize SCE/CPE and other handles *-----------------------------------------------------------------*/ - + test(); IF( EQ_16( ivas_format, MONO_FORMAT ) ) { st_ivas->nSCE = 1; /* in mono, there is always only one SCE */ @@ -1469,35 +1488,40 @@ ivas_error ivas_init_encoder_fx( ELSE IF( ivas_format == STEREO_FORMAT ) { st_ivas->nSCE = 0; + move16(); st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */ + move16(); st_ivas->nchan_transport = CPE_CHANNELS; + move16(); cpe_id = 0; + move16(); - IF( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); + move32(); - IF( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ), IVAS_ERR_OK ) ) { return error; } } - IF( st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - IF( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_ism_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1505,48 +1529,39 @@ ivas_error ivas_init_encoder_fx( IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) { - IF( ( error = ivas_ism_dtx_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_dtx_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - ELSE IF( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) ) { - IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ivas_format == SBA_FORMAT ) + IF( EQ_32( ivas_format, SBA_FORMAT ) ) { -#ifndef IVAS_FLOAT_FIXED - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#else st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#endif + move16(); - IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - IF( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } ELSE { st_ivas->nchan_transport = hEncoderConfig->nchan_inp; + move16(); - IF( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1554,20 +1569,25 @@ ivas_error ivas_init_encoder_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } - + test(); IF( EQ_16( ivas_format, SBA_FORMAT ) && st_ivas->hEncoderConfig->Opt_DTX_ON ) { st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1; + move16(); } } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -1577,297 +1597,283 @@ ivas_error ivas_init_encoder_fx( IF( hEncoderConfig->Opt_DTX_ON ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; + move16(); } } } - if ( st_ivas->nCPE > 1 ) + IF( st_ivas->nCPE > 1 ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - else if ( ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - int32_t ism_total_brate; - int16_t k; + Word32 ism_total_brate; + Word16 k; -#ifndef IVAS_FLOAT_FIXED - st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism ); -#else st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); move32(); -#endif st_ivas->nchan_transport = 2; + move16(); - if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } k = 0; - while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) + move16(); + test(); + WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) { - k++; + k = add( k, 1 ); } ism_total_brate = 0; - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + move32(); + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; - if ( ( error = create_sce_enc_fx( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ) != IVAS_ERR_OK ) + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - if ( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) + IF( GE_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } - else + ELSE { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + move16(); } - if ( ( error = create_cpe_enc( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, 0, L_sub( ivas_total_brate, ism_total_brate ) ) ), IVAS_ERR_OK ) ) { return error; } } - else if ( ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { st_ivas->ism_mode = ISM_MODE_NONE; + move32(); - if ( ivas_total_brate >= IVAS_256k ) + IF( GE_32( ivas_total_brate, IVAS_256k ) ) { st_ivas->ism_mode = ISM_SBA_MODE_DISC; + move32(); } - if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } /* allocate and initialize SBA handles */ - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } -#ifndef IVAS_FLOAT_FIXED - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#else st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#endif - if ( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - if ( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) { /* allocate and initialize SBA core-coders */ - if ( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { - if ( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } } - for ( cpe_id = 0; 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 ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - else + ELSE { /* allocate and initialize MCT core coder */ - st_ivas->nCPE += ( st_ivas->hEncoderConfig->nchan_ism + 1 ) >> 1; + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->hEncoderConfig->nchan_ism, 1 ), 1 ) ); - for ( cpe_id = 0; 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 ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_osba_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - if ( ( error = ivas_osba_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_osba_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } -#endif } - else if ( ivas_format == MC_FORMAT ) + ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { -#ifndef IVAS_FLOAT_FIXED - st_ivas->mc_mode = ivas_mc_mode_select( hEncoderConfig->mc_input_setup, ivas_total_brate ); -#else st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); -#endif + move32(); - if ( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) { return error; } - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( NE_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = hEncoderConfig->nchan_inp / CPE_CHANNELS; + move16(); + st_ivas->nCPE = idiv1616( hEncoderConfig->nchan_inp, CPE_CHANNELS ); + move16(); - for ( cpe_id = 0; 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 / ( hEncoderConfig->nchan_inp - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, sub( hEncoderConfig->nchan_inp, 1 ), &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } -#ifndef IVAS_FLOAT_FIXED - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); -#else st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); -#endif + move16(); } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; + move16(); + st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS >> 1; + move16(); st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + move16(); - if ( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - for ( cpe_id = 0; 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->nCPE ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nCPE, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_param_mc_enc_open( st_ivas ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - for ( cpe_id = 0; 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->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - int32_t brate_sce, brate_cpe; + Word32 brate_sce, brate_cpe; -#ifndef IVAS_FLOAT_FIXED - ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); -#else ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); -#endif - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1878,31 +1884,27 @@ ivas_error ivas_init_encoder_fx( return error; } #else - if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } #endif - -#ifndef IVAS_FLOAT_FIXED - ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); -#else ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); -#endif - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - if ( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_sce ) ), IVAS_ERR_OK ) ) { return error; } } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); - if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, brate_cpe ) ), IVAS_ERR_OK ) ) { return error; } @@ -1916,30 +1918,6 @@ ivas_error ivas_init_encoder_fx( /* set number of input channels used for analysis/coding */ n = getNumChanAnalysis_fx( st_ivas ); -#if 1 // To be removed - if ( n > 0 ) - { - if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - } - else - { - st_ivas->mem_hp20_in = NULL; - } - - for ( i = 0; i < n; i++ ) - { - if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); - } -#endif - /*Fixed point init*/ IF( n > 0 ) { IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) @@ -2156,7 +2134,7 @@ void ivas_destroy_enc( } /* HP20 filter handles */ - if ( st_ivas->mem_hp20_in != NULL ) + if ( st_ivas->mem_hp20_in_fx != NULL ) { n = getNumChanAnalysis_fx( st_ivas ); @@ -2168,6 +2146,7 @@ void ivas_destroy_enc( free( st_ivas->mem_hp20_in_fx ); st_ivas->mem_hp20_in_fx = NULL; } +#ifndef IVAS_FLOAT_FIXED if ( st_ivas->mem_hp20_in != NULL ) { n = getNumChanAnalysis_fx( st_ivas ); @@ -2180,6 +2159,7 @@ void ivas_destroy_enc( free( st_ivas->mem_hp20_in ); st_ivas->mem_hp20_in = NULL; } +#endif /* ISM metadata handles */ ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); diff --git a/lib_enc/ivas_ism_dtx_enc.c b/lib_enc/ivas_ism_dtx_enc.c index c1947034d2e220fcda293509076dc37eb67af061..5b90cb9f84926993ac6982ea403b223b81b0717b 100644 --- a/lib_enc/ivas_ism_dtx_enc.c +++ b/lib_enc/ivas_ism_dtx_enc.c @@ -69,26 +69,30 @@ ivas_error ivas_ism_dtx_open( { ivas_error error; ISM_DTX_HANDLE hISMDTX; - int16_t i; + Word16 i; error = IVAS_ERR_OK; + move32(); /* Assign memory to DirAC handle */ - if ( ( hISMDTX = (ISM_DTX_HANDLE) malloc( sizeof( ISM_DTX_DATA ) ) ) == NULL ) + IF( ( hISMDTX = (ISM_DTX_HANDLE) malloc( sizeof( ISM_DTX_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM DTX Handle \n" ) ); } hISMDTX->dtx_flag = 0; + move16(); hISMDTX->sce_id_dtx = 0; + move16(); hISMDTX->cnt_SID_ISM = -1; + move16(); - for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { - set_f( hISMDTX->long_term_energy_stereo_dmx_enc[i], 0.0f, PARAM_ISM_HYS_BUF_SIZE ); + set32_fx( hISMDTX->long_term_energy_stereo_dmx_enc_fx[i], 0, PARAM_ISM_HYS_BUF_SIZE ); } - set_f( hISMDTX->coh, 0.0f, MAX_NUM_OBJECTS ); + set16_fx( hISMDTX->coh_fx, 0, MAX_NUM_OBJECTS ); st_ivas->hISMDTX = hISMDTX; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 982b355503449e91162491a6dde37d1701ee910a..64f64b721158678695df1473687a49e284fd5821 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -1518,7 +1518,7 @@ ivas_error ivas_ism_metadata_enc( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_ism_metadata_enc_create( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t n_ISms, /* i : number of objects */ + const Word16 n_ISms, /* i : number of objects */ Word32 element_brate_tmp[] /* o : element bitrate per object */ ) { @@ -1527,27 +1527,25 @@ ivas_error ivas_ism_metadata_enc_create( nchan_transport = st_ivas->nchan_transport; move16(); - IF( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { nchan_transport = MAX_PARAM_ISM_WAVE; -#ifndef IVAS_FLOAT_FIXED - ivas_set_omasa_TC( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); -#else + move16(); ivas_set_omasa_TC_fx( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); -#endif } - ELSE IF( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) { nchan_transport = n_ISms; + move16(); } ELSE { - IF( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) { nchan_transport = st_ivas->nchan_transport; move16(); - IF( nchan_transport == 1 ) + IF( EQ_16( nchan_transport, 1 ) ) { st_ivas->nSCE = 1; move16(); @@ -1562,7 +1560,7 @@ ivas_error ivas_ism_metadata_enc_create( move16(); } } - ELSE IF( st_ivas->ism_mode == ISM_MODE_PARAM ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { nchan_transport = 2; move16(); @@ -1623,37 +1621,39 @@ ivas_error ivas_ism_metadata_enc_create( st_ivas->hIsmMetaData[ch]->q_elevation_old_fx = 0; move16(); -#ifdef IVAS_FLOAT_FIXED ivas_ism_reset_metadata_enc( st_ivas->hIsmMetaData[ch] ); -#else - ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); -#endif - st_ivas->hIsmMetaData[ch]->last_azimuth_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->last_elevation_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->ism_md_fec_cnt_enc = 0; + move16(); st_ivas->hIsmMetaData[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; + move16(); st_ivas->hIsmMetaData[ch]->last_true_radius_fx = ONE_IN_Q9; + move16(); } IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { test(); - IF( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ), IVAS_ERR_OK ) ) { return error; } } ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1661,7 +1661,7 @@ ivas_error ivas_ism_metadata_enc_create( } ELSE { - IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 9b975d9355c38188811b0db9f1d8cf88181bb43c..63354efd434b21594f9f7ae121ce1a3aa4642428 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -2254,10 +2254,10 @@ ivas_error ivas_masa_enc_config( * Determine if surrounding coherence is significant in this frame and should be encoded *-----------------------------------------------------------------------*/ UWord8 ivas_masa_surrcoh_signicant_fx( - Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ - Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ - const Word16 nSubFrames, /* i : Number of sub frames */ - const Word16 nBands /* i : Number of frequency bands */ /* i : dynamic (min q for surroundingCoherence and diffuse_to_total_ratio) */ + Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence Q31 */ + Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio Q31 */ + const Word16 nSubFrames, /* i : Number of sub frames */ + const Word16 nBands /* i : Number of frequency bands */ ) { Word32 significanceMeasure1, significanceMeasure2, significanceMeasure; @@ -2287,17 +2287,17 @@ UWord8 ivas_masa_surrcoh_signicant_fx( FOR( band = 0; band < nBands; band++ ) { - surrCohToTotal = Mpy_32_32( diffuse_to_total_ratio[sf][band], surroundingCoherence[sf][band] ); // 2Q -> Q + surrCohToTotal = Mpy_32_32( diffuse_to_total_ratio[sf][band], surroundingCoherence[sf][band] ); // Q31 surrCohToTotalSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalSum, surrCohToTotalSum_e, surrCohToTotal, 0, &surrCohToTotalSum_e ); - surrCohToTotalTimesDiffSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalTimesDiffSum, surrCohToTotalTimesDiffSum_e, Mpy_32_32( (Word32) diffuse_to_total_ratio[sf][band], surrCohToTotal ), 0, &surrCohToTotalTimesDiffSum_e ); // Q2 -> Q - diffSum = BASOP_Util_Add_Mant32Exp( diffSum, diffSum_e, diffuse_to_total_ratio[sf][band], 0, &diffSum_e ); // Q + surrCohToTotalTimesDiffSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalTimesDiffSum, surrCohToTotalTimesDiffSum_e, Mpy_32_32( (Word32) diffuse_to_total_ratio[sf][band], surrCohToTotal ), 0, &surrCohToTotalTimesDiffSum_e ); + diffSum = BASOP_Util_Add_Mant32Exp( diffSum, diffSum_e, diffuse_to_total_ratio[sf][band], 0, &diffSum_e ); } Word16 significanceMeasure1_e, significanceMeasure2_e; Word16 significanceMeasure_e; - significanceMeasure1 = L_deposit_h( BASOP_Util_Divide3216_Scale( surrCohToTotalSum, nBands, &significanceMeasure1_e ) ); // e1 exponent + significanceMeasure1 = L_deposit_h( BASOP_Util_Divide3216_Scale( surrCohToTotalSum, nBands, &significanceMeasure1_e ) ); significanceMeasure1_e = add( significanceMeasure1_e, sub( surrCohToTotalSum_e, 15 ) ); - significanceMeasure2 = L_deposit_h( BASOP_Util_Divide3232_Scale( Mpy_32_32( surrCohSignificanceCoef, surrCohToTotalTimesDiffSum ), L_add( diffSum, EPSILON_FX ), &significanceMeasure2_e ) ); // e2 exponent + significanceMeasure2 = L_deposit_h( BASOP_Util_Divide3232_Scale( Mpy_32_32( surrCohSignificanceCoef, surrCohToTotalTimesDiffSum ), L_add( diffSum, EPSILON_FX ), &significanceMeasure2_e ) ); significanceMeasure2_e = add( significanceMeasure2_e, sub( surrCohToTotalTimesDiffSum_e, diffSum_e ) ); IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure1, significanceMeasure1_e, significanceMeasure2, significanceMeasure2_e ) > 0 ) @@ -2314,7 +2314,7 @@ UWord8 ivas_masa_surrcoh_signicant_fx( significanceMeasure_e = significanceMeasure2_e; move16(); } - IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure, significanceMeasure_e, threshold, 0 ) > 0 ) // Q31 Comparision + IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure, significanceMeasure_e, threshold, 0 ) > 0 ) { return 1; } @@ -8903,9 +8903,9 @@ static void ivas_encode_masaism_metadata_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_merge_masa_transports_fx( - Word32 data_in_f1_fx[][L_FRAME48k], - Word32 *data_in_f2_fx[], - Word32 *data_out_f_fx[], + Word32 data_in_f1_fx[][L_FRAME48k], // Qx + Word32 *data_in_f2_fx[], // Qx + Word32 *data_out_f_fx[], // Qx const Word16 input_frame, const Word16 num_transport_channels ) { diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index 7e4902855613a5683f132c32d5b963c7f8276011..d26e6bee40127102afecb37e862fbbe9491d3f69 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -258,7 +258,7 @@ ivas_error ivas_mc_paramupmix_enc_open( /* Transient Detector handle */ FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) { - IF( ( error = ivas_transient_det_open( &( hMCParamUpmix->hTranDet[i] ), input_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_transient_det_open_fx( &( hMCParamUpmix->hTranDet[i] ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -600,7 +600,7 @@ void ivas_mc_paramupmix_enc_close( FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) { - ivas_transient_det_close( &( *hMCParamUpmix )->hTranDet[i] ); + ivas_transient_det_close_fx( &( *hMCParamUpmix )->hTranDet[i] ); } IF( ( *hMCParamUpmix )->hFbMixer != NULL ) diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 57de41384b2714a085012d682b01a8903b4a39a3..c38bd5ec63845d339ebc2484fd2753b96d1de8f0 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -190,7 +190,6 @@ ivas_error ivas_mcmasa_enc_open_fx( Word16 maxBin, input_frame; Word16 nchan_inp; Word32 input_Fs; - Word32 dirac_slot_ns; IVAS_FB_CFG *fb_cfg, *fb_cfgLfe; ivas_error error; @@ -370,8 +369,7 @@ ivas_error ivas_mcmasa_enc_open_fx( } - dirac_slot_ns = DIRAC_SLOT_ENC_NS; - move32(); + /*dirac_slot_ns = DIRAC_SLOT_ENC_NS;*/ /* intensity 3-dim */ FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -406,7 +404,7 @@ ivas_error ivas_mcmasa_enc_open_fx( } } - hMcMasa->no_col_avg_diff = (Word8) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); + hMcMasa->no_col_avg_diff = (Word8) ( DIRAC_NO_COL_AVG_DIFF_NS / DIRAC_SLOT_ENC_NS ); /* dirac_slot_ns = DIRAC_SLOT_ENC_NS */ move16(); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -445,41 +443,41 @@ ivas_error ivas_mcmasa_enc_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } - set_zero_fx( hMcMasa->buffer_energy_fx, hMcMasa->nbands * hMcMasa->no_col_avg_diff ); + set_zero_fx( hMcMasa->buffer_energy_fx, imult1616( hMcMasa->nbands, hMcMasa->no_col_avg_diff ) ); set16_fx( hMcMasa->buffer_intensity_real_vert_q, 31, DIRAC_NO_COL_AVG_DIFF ); set16_fx( hMcMasa->buffer_energy_q, 31, DIRAC_NO_COL_AVG_DIFF ); - IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1 ) + IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_5_1 ) ) { - Copy32( ls_azimuth_CICP6_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP6_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP6_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP6_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 5; move16(); hMcMasa->isHorizontalSetup = 1; move16(); } - ELSE IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_7_1 ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_7_1 ) ) { - Copy32( ls_azimuth_CICP12_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP12_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP12_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP12_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 7; move16(); hMcMasa->isHorizontalSetup = 1; move16(); } - ELSE IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_2 ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_5_1_2 ) ) { - Copy32( ls_azimuth_CICP14_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP14_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP14_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP14_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 5; move16(); hMcMasa->isHorizontalSetup = 0; move16(); } - ELSE IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_4 ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_5_1_4 ) ) { - Copy32( ls_azimuth_CICP16_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP16_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP16_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP16_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 5; move16(); hMcMasa->isHorizontalSetup = 0; @@ -487,8 +485,8 @@ ivas_error ivas_mcmasa_enc_open_fx( } ELSE { - Copy32( ls_azimuth_CICP19_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP19_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP19_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP19_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 7; move16(); hMcMasa->isHorizontalSetup = 0; @@ -506,23 +504,23 @@ ivas_error ivas_mcmasa_enc_open_fx( computeEvenLayout_fx( ls_azimuth, ls_azimuth_even, hMcMasa->numHorizontalChannels ); IF( !hMcMasa->isHorizontalSetup ) { - computeEvenLayout_fx( &ls_azimuth[hMcMasa->numHorizontalChannels], &ls_azimuth_even[hMcMasa->numHorizontalChannels], numAnalysisChannels - hMcMasa->numHorizontalChannels ); + computeEvenLayout_fx( &ls_azimuth[hMcMasa->numHorizontalChannels], &ls_azimuth_even[hMcMasa->numHorizontalChannels], sub( numAnalysisChannels, hMcMasa->numHorizontalChannels ) ); } FOR( i = 0; i < numAnalysisChannels; i++ ) { hMcMasa->chnlToFoaMtx_fx[0][i] = ONE_IN_Q31; move32(); - hMcMasa->chnlToFoaMtx_fx[1][i] = L_mult( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 /*32767/360*/ ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); + hMcMasa->chnlToFoaMtx_fx[1][i] = L_mult( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 /*32767/360*/ ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); // Q31 move32(); - hMcMasa->chnlToFoaMtx_fx[2][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ), 16 ); + hMcMasa->chnlToFoaMtx_fx[2][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ), 16 ); // Q31 move32(); - hMcMasa->chnlToFoaMtx_fx[3][i] = L_mult( getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); + hMcMasa->chnlToFoaMtx_fx[3][i] = L_mult( getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); // Q31 move32(); hMcMasa->chnlToFoaEvenMtx_fx[0][i] = ONE_IN_Q31; move32(); - hMcMasa->chnlToFoaEvenMtx_fx[1][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_even[i], 91 ), 7 ) ) ), 16 ); + hMcMasa->chnlToFoaEvenMtx_fx[1][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_even[i], 91 ), 7 ) ) ), 16 ); // Q31 move32(); hMcMasa->chnlToFoaEvenMtx_fx[2][i] = 0; move32(); @@ -1215,11 +1213,11 @@ void ivas_mcmasa_enc_fx( MCMASA_ENC_HANDLE hMcMasa, /* i/o: Encoder McMASA handle */ IVAS_QMETADATA_HANDLE hQMeta, /* o : Qmetadata handle */ MASA_ENCODER_HANDLE hMasa, /* i/o: Encoder MASA handle */ - Word32 *data_fx[], /* i : Input frame of audio */ + Word32 *data_fx[], /* i : Input frame of audio Q(q_inp) */ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_transport, /* i : Number of transport channels */ const Word16 nchan_inp, /* i : Number of input channels */ - const Word16 q_inp /* i : Input data q-format */ + const Word16 q_inp /* i : Input data q-format */ ) { Word16 i, j, k; @@ -1270,6 +1268,8 @@ void ivas_mcmasa_enc_fx( { hMasa->data.lfeToTotalEnergyRatio_fx[i] = BASOP_Util_Divide3232_Scale( hMcMasa->lfeLfEne[i], L_add( EPSILON_FX, hMcMasa->totalLfEne[i] ), &hMasa->data.lfeToTotalEnergyRatio_e[i] ); hMasa->data.lfeToTotalEnergyRatio_e[i] = add( sub( hMcMasa->lfeLfEne_e[i], hMcMasa->totalLfEne_e[i] ), hMasa->data.lfeToTotalEnergyRatio_e[i] ); + move32(); + move16(); } /* Set analyzed values to the MASA struct */ @@ -1299,8 +1299,10 @@ void ivas_mcmasa_enc_fx( IF( hQMeta->surcoh_band_data != NULL ) { - hQMeta->q_direction[0].coherence_band_data[i].spread_coherence[j] = (uint8_t) round_fx( Mpy_32_32( spreadCoherence_fx[j][i], L_shl( UINT8_MAX, Q16 ) ) ); - hQMeta->surcoh_band_data[i].surround_coherence[j] = (uint8_t) round_fx( Mpy_32_32( surroundingCoherence_fx[k][i], L_shl( UINT8_MAX, Q16 ) ) ); + hQMeta->q_direction[0].coherence_band_data[i].spread_coherence[j] = (UWord8) round_fx( Mpy_32_32( spreadCoherence_fx[j][i], L_shl( UINT8_MAX, Q16 ) ) ); // Q0 + hQMeta->surcoh_band_data[i].surround_coherence[j] = (UWord8) round_fx( Mpy_32_32( surroundingCoherence_fx[k][i], L_shl( UINT8_MAX, Q16 ) ) ); // Q0 + move16(); + move16(); } } } @@ -1333,7 +1335,7 @@ void ivas_mcmasa_enc_fx( } /* Downmix */ - ivas_mcmasa_dmx_fx( hMcMasa, data_fx, 31 - q_inp, input_frame, nchan_transport, nchan_inp ); + ivas_mcmasa_dmx_fx( hMcMasa, data_fx, sub( 31, q_inp ), input_frame, nchan_transport, nchan_inp ); IF( hMcMasa->separateChannelEnabled ) { @@ -1344,11 +1346,13 @@ void ivas_mcmasa_enc_fx( /* Update mcMASA-relevant coding parameters */ /* These are reset to default values as they may be modified during later processing. */ hMasa->config.joinedSubframes = FALSE; + move16(); hQMeta->q_direction[0].cfg.nbands = hMcMasa->nbands; move16(); hQMeta->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; move16(); hQMeta->all_coherence_zero = 1; + move16(); /* Check spread coherence */ i = 0; @@ -1356,11 +1360,13 @@ void ivas_mcmasa_enc_fx( test(); WHILE( LT_16( i, nBlocks ) && hQMeta->all_coherence_zero ) { + test(); j = 0; move16(); test(); WHILE( LT_16( j, nBands ) && hQMeta->all_coherence_zero ) { + test(); IF( GT_32( spreadCoherence_fx[i][j], MASA_COHERENCE_THRESHOLD_FX ) ) { hQMeta->all_coherence_zero = 0; @@ -1393,7 +1399,7 @@ void ivas_mcmasa_enc_fx( { FOR( j = 0; j < nBands; j++ ) { - diffuse_to_total_ratio_fx[i][j] = L_max( 0, L_sub( ONE_IN_Q31, energyRatio_fx[i][j] ) ); + diffuse_to_total_ratio_fx[i][j] = L_max( 0, L_sub( ONE_IN_Q31, energyRatio_fx[i][j] ) ); // Q31 move32(); } } @@ -1588,17 +1594,17 @@ void ivas_mcmasa_enc( #ifdef IVAS_FLOAT_FIXED void ivas_mcmasa_param_est_enc_fx( - MCMASA_ENC_HANDLE hMcMasa, /* i : McMASA encoder structure */ - MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder structure */ - Word32 *data_f[], /* i : Audio frame in MC-format */ - Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated elevation */ - Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated azimuth */ - Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated direct-to-total ratio */ - Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated spread coherence */ - Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated surround coherence */ - const Word16 input_frame, /* i : Input frame size */ - const Word16 nchan_inp, /* i : Number of input channels */ - const Word16 q_inp /* i : Number of input channels */ + MCMASA_ENC_HANDLE hMcMasa, /* i : McMASA encoder structure */ + MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder structure */ + Word32 *data_f[], /* i : Audio frame in MC-format */ + Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated elevation Q22 */ + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated azimuth Q22 */ + Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated direct-to-total ratio Q31 */ + Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated spread coherence Q31 */ + Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated surround coherence Q31 */ + const Word16 input_frame, /* i : Input frame size */ + const Word16 nchan_inp, /* i : Number of input channels */ + const Word16 q_inp /* i : Q factor of the data_f */ ) { Word32 reference_power_fx[MDFT_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; @@ -1902,6 +1908,7 @@ void ivas_mcmasa_param_est_enc_fx( num_freq_bands, intensity_even_real_fx ); Word16 ref_e = 0; + move16(); computeReferencePower_enc_fx( hMcMasa->band_grouping, FoaEven_RealBuffer_fx, FoaEven_ImagBuffer_fx, @@ -1913,7 +1920,7 @@ void ivas_mcmasa_param_est_enc_fx( FOA_CHANNELS, inp_q, &ref_e ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ - hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ) + 1; /* averaging_length = 32 */ + hMcMasa->index_buffer_intensity = add( ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ move16(); index = hMcMasa->index_buffer_intensity; move16(); @@ -1959,8 +1966,9 @@ void ivas_mcmasa_param_est_enc_fx( ELSE { diffuseness_m_fx[block_m_idx][band_m_idx] = diffuseness_vector_fx[band_m_idx]; - diffuseness_e[block_m_idx][band_m_idx] = Q31; + diffuseness_e[block_m_idx][band_m_idx] = 0; // Q31 move32(); + move16(); } } } @@ -2075,7 +2083,7 @@ void ivas_mcmasa_param_est_enc_fx( /* Compute spread coherence */ IF( LT_32( elevation_m_values_fx[block_m_idx][band_m_idx], NEAR_HORIZONTAL_PLANE_ELEVATION_FX ) ) /* Computed only near horizontal plane */ { - minAngleDist_fx = 754974720; /*Q22*/ + minAngleDist_fx = 754974720; /*180.0f Q.22*/ move32(); i1 = 0; move16(); @@ -2086,7 +2094,7 @@ void ivas_mcmasa_param_est_enc_fx( angleDist_fx = L_abs( L_sub( currentAzi_fx, hMcMasa->ls_azimuth_fx[i] ) ); IF( GT_32( angleDist_fx, 754974720 /*180.0f Q.22*/ ) ) { - angleDist_fx = L_abs( L_sub( angleDist_fx, 1509949440 ) ); + angleDist_fx = L_abs( L_sub( angleDist_fx, 1509949440 /*360.0f Q.22*/ ) ); } IF( LT_32( angleDist_fx, minAngleDist_fx ) ) { @@ -2278,14 +2286,14 @@ void ivas_mcmasa_param_est_enc_fx( lsEnergySum_fx = L_add_sat( lsEnergySum_fx, EPSILON_FX ); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp1, lsEnergySum_fx, &lsEnergyRelation_e ); lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp1_e, lsEnergySum_e ) ); - lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); - stereoRatio_fx = L_sub( Mult_32_32( L_shl_sat( stereoCoh_fx, stereoCoh_e ), lsEnergyRelation_fx ), surrCoh_fx ); + lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); // Q31 + stereoRatio_fx = L_sub( Mult_32_32( L_shl_sat( stereoCoh_fx, stereoCoh_e ), lsEnergyRelation_fx ), surrCoh_fx ); // Q31 temp2 = L_sub( temp2, EPSILLON_FX ); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp2, lsEnergySum_fx, &lsEnergyRelation_e ); lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp2_e, lsEnergySum_e ) ); - lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); - cohPanRatio_fx = L_sub( Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ), surrCoh_fx ); + lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); // Q31 + cohPanRatio_fx = L_sub( Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ), surrCoh_fx ); // Q31 IF( GT_32( stereoRatio_fx, cohPanRatio_fx ) ) { cohRatio_fx = stereoRatio_fx; @@ -2338,9 +2346,9 @@ void ivas_mcmasa_param_est_enc_fx( } ELSE { - surroundingCoherence_fx[block_m_idx][band_m_idx] = surrCoh_fx; + surroundingCoherence_fx[block_m_idx][band_m_idx] = surrCoh_fx; // Q31 move32(); - coherentEnergyRatio_fx[block_m_idx][band_m_idx] = cohRatio_fx; + coherentEnergyRatio_fx[block_m_idx][band_m_idx] = cohRatio_fx; // Q31 move32(); } } @@ -2356,7 +2364,7 @@ void ivas_mcmasa_param_est_enc_fx( diffuseness_m_fx[0][band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[0][band_m_idx], renormalization_factor_diff_fx[band_m_idx], &diffuseness_m_e ); move32(); diffuseness_m_e = add( diffuseness_m_e, sub( diffuseness_e[0][band_m_idx], renormalization_factor_diff_e[band_m_idx] ) ); - diffuseness_m_fx[0][band_m_idx] = L_shl_sat( diffuseness_m_fx[0][band_m_idx], add( 16, diffuseness_m_e ) ); + diffuseness_m_fx[0][band_m_idx] = L_shl_sat( diffuseness_m_fx[0][band_m_idx], add( 16, diffuseness_m_e ) ); // Q(31 - diffuseness_m_e) -> Q31 move32(); } ELSE @@ -2372,12 +2380,12 @@ void ivas_mcmasa_param_est_enc_fx( surroundingCoherence_fx[0][band_m_idx] = BASOP_Util_Divide3232_Scale( surroundingCoherence_fx[0][band_m_idx], renormalization_factor_coh_fx[band_m_idx], &sc_e ); move32(); sc_e = add( sc_e, sub( surroundingCoherence_e[0][band_m_idx], renormalization_factor_coh_e[band_m_idx] ) ); - surroundingCoherence_fx[0][band_m_idx] = L_shl_sat( surroundingCoherence_fx[0][band_m_idx], add( 16, sc_e ) ); + surroundingCoherence_fx[0][band_m_idx] = L_shl_sat( surroundingCoherence_fx[0][band_m_idx], add( 16, sc_e ) ); // Q(31 - sc_e) -> Q31 move32(); coherentEnergyRatio_fx[0][band_m_idx] = BASOP_Util_Divide3232_Scale( coherentEnergyRatio_fx[0][band_m_idx], renormalization_factor_coh_fx[band_m_idx], &cer_e ); move32(); cer_e = add( cer_e, sub( coherentEnergyRatio_e[0][band_m_idx], renormalization_factor_coh_e[band_m_idx] ) ); - coherentEnergyRatio_fx[0][band_m_idx] = L_shl_sat( coherentEnergyRatio_fx[0][band_m_idx], add( 16, cer_e ) ); + coherentEnergyRatio_fx[0][band_m_idx] = L_shl_sat( coherentEnergyRatio_fx[0][band_m_idx], add( 16, cer_e ) ); // Q(31 - cer_e) -> Q31 move32(); } ELSE @@ -2406,7 +2414,7 @@ void ivas_mcmasa_param_est_enc_fx( { FOR( j = 0; j < hMcMasa->nbands; j++ ) { - energyRatio_fx[i][j] = L_sub( ONE_IN_Q31, diffuseness_m_fx[i][j] ); + energyRatio_fx[i][j] = L_sub( ONE_IN_Q31, diffuseness_m_fx[i][j] ); // Q31 move32(); IF( GT_32( energyRatio_fx[i][j], coherentEnergyRatio_fx[i][j] ) ) { @@ -2415,7 +2423,7 @@ void ivas_mcmasa_param_est_enc_fx( } ELSE { - energyRatio_fx[i][j] = coherentEnergyRatio_fx[i][j]; + energyRatio_fx[i][j] = coherentEnergyRatio_fx[i][j]; // Q31 move32(); } } @@ -2945,6 +2953,92 @@ void ivas_mcmasa_param_est_enc( * *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_mcmasa_dmx_modify_fx( + const Word16 n_samples, /* i : input frame length in samples */ + Word32 dmx_fx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format Qx*/ + const Word16 n_chnls_dmx_old, /* i : number of downmix channels in the old format Q0 */ + const Word16 n_chnls_dmx_new ) /* i : number of downmix channels in the target format Q0*/ +{ + /* assumed data ordering in **dmx: [sce][cpe_chnl0][cpe_chnl1], i.e., [c][l][r] */ + Word16 i; + + assert( ( n_chnls_dmx_old == 1 || n_chnls_dmx_old == 2 || n_chnls_dmx_old == 3 ) && "Input downmix may contain only 1-3 channels." ); + assert( ( n_chnls_dmx_new == 1 || n_chnls_dmx_new == 2 || n_chnls_dmx_new == 3 ) && "Output downmix may contain only 1-3 channels." ); + + IF( EQ_16( n_chnls_dmx_old, n_chnls_dmx_new ) ) + { + /* same dmx layout -> nothing to do */ + return; + } + + IF( EQ_16( n_chnls_dmx_old, 1 ) ) + { + /* split mono energy into identical channels */ + FOR( i = 0; i < n_samples; i++ ) + { + IF( EQ_16( n_chnls_dmx_new, 2 ) ) + { + dmx_fx[1][i] = Mpy_32_16_1( dmx_fx[0][i], INV_SQRT2_FX_Q15 ); // dmx_q + Q15 - 15 + dmx_fx[2][i] = dmx_fx[1][i]; + move32(); + move32(); + } + ELSE IF( EQ_16( n_chnls_dmx_new, 3 ) ) + { + dmx_fx[0][i] = Mpy_32_16_1( dmx_fx[0][i], INV_SQRT3_FX ); // dmx_q + Q15 - 15 + move32(); + } + } + } + ELSE IF( EQ_16( n_chnls_dmx_old, 2 ) ) + { + FOR( i = 0; i < n_samples; i++ ) + { + IF( EQ_16( n_chnls_dmx_new, 1 ) ) + { + /* sum l and r */ + dmx_fx[0][i] = L_add( dmx_fx[1][i], dmx_fx[2][i] ); + move32(); + } + ELSE IF( EQ_16( n_chnls_dmx_new, 3 ) ) + { + dmx_fx[0][i] = L_shr( L_add( dmx_fx[1][i], dmx_fx[2][i] ), 1 ); + dmx_fx[1][i] = L_sub( dmx_fx[1][i], dmx_fx[0][i] ); + dmx_fx[2][i] = L_sub( dmx_fx[2][i], dmx_fx[0][i] ); + move32(); + move32(); + move32(); + } + } + } + ELSE IF( EQ_16( n_chnls_dmx_old, 3 ) ) + { + FOR( i = 0; i < n_samples; i++ ) + { + IF( EQ_16( n_chnls_dmx_new, 1 ) ) + { + /* sum all channels */ + dmx_fx[0][i] = L_add( L_add( dmx_fx[0][i], dmx_fx[1][i] ), dmx_fx[2][i] ); + move32(); + } + ELSE IF( EQ_16( n_chnls_dmx_new, 2 ) ) + { + /* mix center into sides */ + dmx_fx[0][i] = Mpy_32_16_1( dmx_fx[0][i], INV_SQRT2_FX_Q15 ); + dmx_fx[1][i] = L_add( dmx_fx[1][i], dmx_fx[0][i] ); + dmx_fx[2][i] = L_add( dmx_fx[2][i], dmx_fx[0][i] ); + move32(); + move32(); + move32(); + } + } + } + + return; +} +#endif + void ivas_mcmasa_dmx_modify( const int16_t n_samples, /* i : input frame length in samples */ float dmx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format */ @@ -3127,16 +3221,16 @@ static void ivas_mcmasa_dmx_fx( } } - alpha_fx = 214748364; // Q31 + alpha_fx = 214748364; // 0.1 in Q31 move32(); L_tmp = Mpy_32_32( alpha_fx, multiChEne_fx ); - L_tmp1 = Mpy_32_32( 1932735284, hMcMasa->prevMultiChEne_fx ); + L_tmp1 = Mpy_32_32( 1932735284 /* 0.9f in Q31 */, hMcMasa->prevMultiChEne_fx ); hMcMasa->prevMultiChEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, multiChEne_e, L_tmp1, hMcMasa->prevMultiChEne_e, &hMcMasa->prevMultiChEne_e ); move32(); L_tmp = Mpy_32_32( alpha_fx, downmixEne_fx ); - L_tmp1 = Mpy_32_32( 1932735284, hMcMasa->prevDownmixEne_fx ); + L_tmp1 = Mpy_32_32( 1932735284 /* 0.9f in Q31 */, hMcMasa->prevDownmixEne_fx ); hMcMasa->prevDownmixEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, downmixEne_e, L_tmp1, hMcMasa->prevDownmixEne_e, &hMcMasa->prevDownmixEne_e ); move32(); @@ -3157,7 +3251,7 @@ static void ivas_mcmasa_dmx_fx( FOR( i = 0; i < input_frame; i++ ) { L_tmp = Mpy_32_32( L_deposit_h( hMcMasa->interpolator_fx[i] ), currEQ_fx ); - L_tmp1 = L_sub( 1073741824, L_lshr( L_deposit_h( hMcMasa->interpolator_fx[i] ), 1 ) ); + L_tmp1 = L_sub( 1073741824 /* 1 in Q30 */, L_lshr( L_deposit_h( hMcMasa->interpolator_fx[i] ), 1 ) ); L_tmp1 = Mpy_32_32( L_tmp1, prevEQ_fx ); instEQ_fx = BASOP_Util_Add_Mant32Exp( L_tmp, currEQ_e, L_tmp1, add( prevEQ_e, 1 ), &instEQ_e ); @@ -3282,8 +3376,8 @@ static void ivas_mcmasa_dmx( #ifdef IVAS_FLOAT_FIXED /* Compute covariance matrix, i.e., xT * conj(x), and accumulate to the output */ static void compute_cov_mtx_fx( - Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, real, s[ch][freq] */ - Word32 si[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, imag, s[ch][freq] */ + Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, real, s[ch][freq] (inp_exp) */ + Word32 si[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, imag, s[ch][freq] (inp_exp) */ const Word16 freq, /* i : Freq to process */ const Word16 N, /* i : Number of channels */ CovarianceMatrix *COVls, /* o : Output matrix, contains upper part of cov mtx */ @@ -3445,11 +3539,11 @@ static void computeIntensityVector_enc_fx( #endif #ifdef IVAS_FLOAT_FIXED static void computeVerticalDiffuseness_fx( - Word32 **buffer_intensity, /* i : Intensity vectors */ - const Word32 *buffer_energy, /* i : Energy */ - const int16_t averaging_length, /* i : Averaging length */ - const Word16 num_freq_bands, /* i : Number of frequency bands */ - Word32 *diffuseness, /* o : Estimated diffuseness */ + Word32 **buffer_intensity, /* i : Intensity vectors */ + const Word32 *buffer_energy, /* i : Energy */ + const Word16 averaging_length, /* i : Averaging length */ + const Word16 num_freq_bands, /* i : Number of frequency bands */ + Word32 *diffuseness, /* o : Estimated diffuseness Q31 */ Word16 *buffer_intensity_q, Word16 *buffer_energy_q ) { @@ -3518,7 +3612,7 @@ static void computeVerticalDiffuseness_fx( { tmp = L_shl( tmp, add( 16, tmp_e2 ) ); } - diffuseness[i] = tmp; + diffuseness[i] = tmp; // Q31 move32(); } @@ -3906,7 +4000,8 @@ static void computeLfeEnergy_fx( move32(); } - hMcMasa->ringBufferPointer--; + hMcMasa->ringBufferPointer = sub( hMcMasa->ringBufferPointer, 1 ); + move16(); IF( hMcMasa->ringBufferPointer < 0 ) { hMcMasa->ringBufferPointer = sub( hMcMasa->ringBufferSize, 1 ); @@ -3973,8 +4068,8 @@ static void computeLfeEnergy_fx( IF( hMcMasa->separateChannelEnabled ) { - Copy32( data_fx[lfeChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[0][0] ), ( hMcMasa->num_samples_delay_comp - hMcMasa->offset_comp ) ); - Copy32( data_fx[separateChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[1][0] ), ( hMcMasa->num_samples_delay_comp - hMcMasa->offset_comp ) ); + Copy32( data_fx[lfeChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[0][0] ), sub( hMcMasa->num_samples_delay_comp, hMcMasa->offset_comp ) ); + Copy32( data_fx[separateChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[1][0] ), sub( hMcMasa->num_samples_delay_comp, hMcMasa->offset_comp ) ); } return; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 0265b1339fa5dc24c096903e4a7ce672dc179d6d..48592f1b3c6d2bc86b1abdb31947e420e07afe72 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -75,9 +75,6 @@ static void ivas_omasa_energy_and_ratio_est_fx( OMASA_ENC_HANDLE hOMasa, OMASA_ENCODER_DATA_HANDLE hOmasaData, Word32 *data_fx[], -#if 0 - float *data_f[], -#endif const Word16 input_frame, const Word16 nchan_ism, const Word16 q_data ); @@ -873,7 +870,7 @@ void ivas_omasa_enc_fx( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ Word32 *data_in[], /* i/o: Input / transport audio signals */ - Word16 q_data, /* i:Q0 Stores the q for data_in_f */ + Word16 q_data, /* i : Q0 Stores the q for data_in */ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_transport, /* i : Number of transport channels */ const Word16 nchan_ism, /* i : Number of objects for parameter analysis */ @@ -939,7 +936,7 @@ void ivas_omasa_enc_fx( // alpha = 26214;/*0.8 Q15*/ FOR( i = 0; i < nchan_all_inp; i++ ) { - hOMasa->broadband_energy_sm_fx[i] = L_add( Mpy_32_16_1( broadband_energy_fx[i], 6554 ), Mpy_32_16_1( hOMasa->broadband_energy_sm_fx[i], 26214 ) ); + hOMasa->broadband_energy_sm_fx[i] = L_add( Mpy_32_16_1( broadband_energy_fx[i], 6554 /*0.2 Q15*/ ), Mpy_32_16_1( hOMasa->broadband_energy_sm_fx[i], 26214 /*0.8 Q15*/ ) ); move32(); } @@ -1405,6 +1402,7 @@ void ivas_set_ism_importance_interformat_fx( IF( active_flag == 0 ) { + test(); if ( GT_16( st->lp_noise_fx, 3840 /* 15 in Q8 */ ) || LT_16( sub( lp_noise_CPE_fx, st->lp_noise_fx ), 7680 /* 30 in Q8 */ ) ) { active_flag = 1; @@ -1425,6 +1423,8 @@ void ivas_set_ism_importance_interformat_fx( ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; st->low_rate_mode = 0; + move16(); + test(); IF( active_flag == 0 ) { ism_imp[ch] = ISM_INACTIVE_IMP; @@ -1533,12 +1533,8 @@ void ivas_set_surplus_brate_enc( test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { -#ifndef IVAS_FLOAT_FIXED - st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); -#else st_ivas->hCPE[0]->brate_surplus = L_sub( st_ivas->hSCE[0]->element_brate, ivas_interformat_brate_fx( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ) ); move32(); -#endif /* note: ISM st->total_brate is iset in ivas_sce_enc() */ } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) @@ -1777,7 +1773,7 @@ static void ivas_omasa_param_est_enc_fx( dir_v_e = MIN_16; num_freq_bins = hOMasa->cldfbAnaEnc[0]->no_channels; num_freq_bands = hOMasa->nbands; - l_ts = input_frame / CLDFB_NO_COL_MAX; /*division by power of 2 so basop not used*/ + l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); move16(); move16(); move16(); @@ -2011,8 +2007,8 @@ static void ivas_omasa_param_est_enc_fx( move16(); } move32(); - diffuseness_m_fx[band_m_idx] = L_shl( diffuseness_m_fx[band_m_idx], 15 + temp_e ); - energyRatio_fx[band_m_idx] = L_sub( ONE_IN_Q30, diffuseness_m_fx[band_m_idx] ); + diffuseness_m_fx[band_m_idx] = L_shl( diffuseness_m_fx[band_m_idx], add( 15, temp_e ) ); // Scaling to Q30 + energyRatio_fx[band_m_idx] = L_sub( ONE_IN_Q30, diffuseness_m_fx[band_m_idx] ); // Q30 move32(); move32(); } @@ -2672,9 +2668,7 @@ static void computeReferencePower_omasa_ivas_fx( /* abs()^2 */ FOR( j = brange[0]; j < brange[1]; j++ ) { - // reference_power[i] += ( Cldfb_RealBuffer[ch_idx][j] * Cldfb_RealBuffer[ch_idx][j] ) + ( Cldfb_ImagBuffer[ch_idx][j] * Cldfb_ImagBuffer[ch_idx][j] ); - // Q13 (Q6+Q6+1) - reference_power_tmp[i] = W_add( reference_power_tmp[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ); + reference_power_tmp[i] = W_add( reference_power_tmp[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ); // Q13 (Q6+Q6+1) move64(); } } diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index 4da8169fbc1b5e5f3a7d7281bc89397268c05cfc..ec1e0f9fac8db1795393f9811271d9632f98a359 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -345,66 +345,7 @@ ivas_error ivas_osba_enc_reconfig( n_old = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) ) ); n = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ) ); -#if 1 // To be removed - float **old_mem_hp20_in; - - if ( n > n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < n_old; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* create additional hp20 memories */ - for ( ; i < n; i++ ) - { - if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } - else if ( n < n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < n; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* remove superfluous hp20 memories */ - for ( ; i < n_old; i++ ) - { - free( old_mem_hp20_in[i] ); - old_mem_hp20_in[i] = NULL; - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } -#endif IF( GT_16( n, n_old ) ) { /* save old mem_hp_20 pointer */ diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 549b7ccdca1119b7af8282c7ae00822fd17177dc..501c6796a9caf88401a03898ce916e5f7c9ab8fa 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -140,66 +140,6 @@ ivas_error ivas_sba_enc_reconfigure( n_old = imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) ); n = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); -#if 1 // To be removed - float **old_mem_hp20_in; - - if ( n > n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < n_old; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* create additional hp20 memories */ - for ( ; i < n; i++ ) - { - if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } - else if ( n < n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < n; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* remove superfluous hp20 memories */ - for ( ; i < n_old; i++ ) - { - free( old_mem_hp20_in[i] ); - old_mem_hp20_in[i] = NULL; - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } -#endif IF( GT_16( n, n_old ) ) { /* save old mem_hp_20 pointer */ @@ -258,70 +198,77 @@ ivas_error ivas_sba_enc_reconfigure( } } -#ifdef IVAS_FLOAT_FIXED ivas_spar_config_fx( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); -#else - ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); -#endif hSpar = st_ivas->hSpar; - if ( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { hEncoderConfig->element_mode_init = IVAS_SCE; } - else + ELSE { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } + move16(); - if ( nchan_transport_old != st_ivas->nchan_transport || ( ivas_total_brate < IVAS_512k && hEncoderConfig->last_ivas_total_brate >= IVAS_512k ) || ( ivas_total_brate >= IVAS_512k && hEncoderConfig->last_ivas_total_brate < IVAS_512k ) ) + test(); + test(); + test(); + test(); + IF( NE_16( nchan_transport_old, st_ivas->nchan_transport ) || ( LT_32( ivas_total_brate, IVAS_512k ) && GE_32( hEncoderConfig->last_ivas_total_brate, IVAS_512k ) ) || ( GE_32( ivas_total_brate, IVAS_512k ) && LT_32( hEncoderConfig->last_ivas_total_brate, IVAS_512k ) ) ) { /* FB mixer handle */ - if ( hDirAC->hFbMixer != NULL ) + IF( hDirAC->hFbMixer != NULL ) { ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); hDirAC->hFbMixer = NULL; } spar_reconfig_flag = 1; + move16(); ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); - if ( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) { return error; } } st_ivas->hSpar->spar_reconfig_flag = spar_reconfig_flag; + move16(); - if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->hQMetaData->q_direction->cfg.nbands != nbands_old || st_ivas->hQMetaData->no_directions != ndir_old ) + test(); + IF( NE_16( st_ivas->hQMetaData->q_direction->cfg.nbands, nbands_old ) || NE_16( st_ivas->hQMetaData->no_directions, ndir_old ) ) { - int16_t dir, j, i; + Word16 dir, j, i; IVAS_QDIRECTION *q_direction = st_ivas->hQMetaData->q_direction; - for ( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ ) + FOR( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ ) { - for ( j = 0; j < q_direction[dir].cfg.nbands; j++ ) + FOR( j = 0; j < q_direction[dir].cfg.nbands; j++ ) { - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { q_direction[dir].band_data[j].energy_ratio_index[i] = 0; q_direction[dir].band_data[j].energy_ratio_index_mod[i] = 0; + move16(); + move16(); } } } } hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + move16(); /*-----------------------------------------------------------------* * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - if ( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index b6e5fbaf6798e7fb550a4341cb0fc6d11dc9a5b9..6637128dd65aa575e57a27c7b8e4d96d20a83e5f 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -428,7 +428,7 @@ ivas_error create_sce_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); } - copy_encoder_config( st_ivas, st, 1 ); + copy_encoder_config_fx( st_ivas, st, 1 ); if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { @@ -544,12 +544,13 @@ ivas_error create_evs_sce_enc( ivas_error error; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * Allocate SCE handle *-----------------------------------------------------------------*/ - if ( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL ) + IF( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) ); } @@ -559,21 +560,23 @@ ivas_error create_evs_sce_enc( *-----------------------------------------------------------------*/ hSCE->sce_id = sce_id; + move16(); hSCE->element_brate = element_brate; + move32(); hSCE->last_element_brate = hSCE->element_brate; - + move32(); /*-----------------------------------------------------------------* * Metadata: allocate and initialize *-----------------------------------------------------------------*/ - - if ( st_ivas->hEncoderConfig->ivas_format != MONO_FORMAT && sce_id == ( st_ivas->nSCE - 1 ) ) + test(); + IF( NE_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) && EQ_16( sce_id, sub( st_ivas->nSCE, 1 ) ) ) { - if ( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - else + ELSE { hSCE->hMetaData = NULL; } @@ -581,45 +584,72 @@ ivas_error create_evs_sce_enc( /*-----------------------------------------------------------------* * Core Coder, 1 instance: allocate and initialize *-----------------------------------------------------------------*/ - if ( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) + IF( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); } memset( st_fx, 0, sizeof( Encoder_State ) ); st_fx->input_Fs = 16000; + move32(); st_fx->total_brate = ACELP_12k65; - + move32(); st_fx->Opt_AMR_WB = 0; + move16(); st_fx->Opt_RF_ON = 0; + move16(); st_fx->rf_fec_offset = 0; + move16(); st_fx->rf_fec_indicator = 1; + move16(); st_fx->max_bwidth = SWB; + move16(); st_fx->interval_SID_fx = FIXED_SID_RATE; + move16(); st_fx->var_SID_rate_flag_fx = 1; + move16(); st_fx->Opt_HE_SAD_ON_fx = 0; + move16(); st_fx->Opt_SC_VBR = 0; + move16(); st_fx->last_Opt_SC_VBR = 0; + move16(); st_fx->bitstreamformat = G192; + move16(); // copy_encoder_config_fx( st_ivas, st_fx, 1 ); st_fx->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + move16(); st_fx->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON; + move16(); st_fx->var_SID_rate_flag_fx = st_ivas->hEncoderConfig->var_SID_rate_flag; + move16(); st_fx->interval_SID_fx = st_ivas->hEncoderConfig->interval_SID; + move16(); st_fx->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON; + move16(); st_fx->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator; + move16(); st_fx->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset; + move16(); // st_fx->bitstreamformat = st->bitstreamformat; st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); st_fx->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR; + move16(); st_fx->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR; + move16(); st_fx->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB; + move16(); st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs; + move32(); st_fx->codec_mode = st_ivas->codec_mode; + move16(); st_fx->last_codec_mode = st_ivas->last_codec_mode; + move16(); st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ); - if ( ( error = init_encoder_fx( st_fx ) ) != IVAS_ERR_OK ) + move16(); + IF( NE_32( ( error = init_encoder_fx( st_fx ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 2ad7393230d5b21f3ce4f62ea12279bc4bcd0e27..9ffd91825e77a8775d5e7196b7a280fd0531af39 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -104,11 +104,7 @@ ivas_error ivas_spar_enc_open( hSpar->spar_reconfig_flag = 0; input_Fs = hEncoderConfig->input_Fs; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); -#ifdef IVAS_FLOAT_FIXED nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order_internal, hEncoderConfig->ivas_total_brate ); -#else - nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal, hEncoderConfig->ivas_total_brate ); -#endif // IVAS_FLOAT_FIXED assert( nchan_inp <= hEncoderConfig->nchan_inp ); ivas_total_brate = hEncoderConfig->ivas_total_brate; @@ -130,9 +126,9 @@ ivas_error ivas_spar_enc_open( assert( 0 && "sba_order must be 1,2, or 3!" ); } - nchan_transport = ivas_get_sba_num_TCs( hEncoderConfig->ivas_total_brate, sba_order_internal ); + nchan_transport = ivas_get_sba_num_TCs_fx( hEncoderConfig->ivas_total_brate, sba_order_internal ); - table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); + table_idx = ivas_get_spar_table_idx_fx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); /* MD handle */ if ( ( error = ivas_spar_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) @@ -170,10 +166,17 @@ ivas_error ivas_spar_enc_open( if ( !spar_reconfig_flag ) { /* Transient Detector handle */ +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_transient_det_open_fx( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_transient_det_open( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } +#endif } /* initialization */ @@ -262,7 +265,7 @@ ivas_error ivas_spar_enc_open( hSpar->hCoreCoderVAD->total_brate = hEncoderConfig->ivas_total_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; - if ( ( error = init_encoder( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ) != IVAS_ERR_OK ) + if ( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -375,7 +378,7 @@ ivas_error ivas_spar_enc_open_fx( IF( !spar_reconfig_flag ) { /* Transient Detector handle */ - IF( ( error = ivas_transient_det_open( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_transient_det_open_fx( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -546,7 +549,11 @@ void ivas_spar_enc_close( if ( !spar_reconfig_flag ) { /* Trans Det handle */ +#ifdef IVAS_FLOAT_FIXED + ivas_transient_det_close_fx( &( *hSpar )->hTranDet ); +#else ivas_transient_det_close( &( *hSpar )->hTranDet ); +#endif free( ( *hSpar ) ); ( *hSpar ) = NULL; } @@ -661,10 +668,6 @@ static ivas_error ivas_spar_cov_md_process( Word16 i, j, i_ts, b, table_idx; Word16 active_w_vlbr; /* note: the actual dimensions of matrixes correspond to num_channels = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); */ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float cov_real_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - float cov_dtx_real_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; #ifdef IVAS_FLOAT_FIXED Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -716,29 +719,13 @@ static ivas_error ivas_spar_cov_md_process( num_bands = IVAS_MAX_NUM_BANDS; move16(); } - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, num_bands, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); + ivas_spar_set_bitrate_config_fx( &hSpar->hMdEnc->spar_md_cfg, table_idx, num_bands, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); } } /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ - - for ( i = 0; i < nchan_inp; i++ ) - { - for ( j = 0; j < nchan_inp; j++ ) - { - cov_real[i][j] = cov_real_buf[i][j]; - cov_dtx_real[i][j] = cov_dtx_real_buf[i][j]; - for ( b = hSpar->hFbMixer->pFb->filterbank_num_bands; b < IVAS_MAX_NUM_BANDS; b++ ) - { - cov_real[i][j][b] = 0.0f; - cov_dtx_real[i][j][b] = 0.0f; - } - } - } - -#ifdef IVAS_FLOAT_FIXED FOR( i = 0; i < nchan_inp; i++ ) { FOR( j = 0; j < nchan_inp; j++ ) @@ -757,14 +744,13 @@ static ivas_error ivas_spar_cov_md_process( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } - set_s( q_cov_real[i], Q31, nchan_inp ); + set16_fx( q_cov_real[i], Q31, nchan_inp ); IF( ( q_cov_dtx_real[i] = (Word16 *) malloc( sizeof( Word16 ) * nchan_inp ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } - set_s( q_cov_dtx_real[i], Q31, nchan_inp ); + set16_fx( q_cov_dtx_real[i], Q31, nchan_inp ); } -#endif ivas_enc_cov_handler_process_fx( hSpar->hCovEnc, ppIn_FR_real_fx, ppIn_FR_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det, hSpar->hMdEnc->HOA_md_ind, &hSpar->hMdEnc->spar_md.res_ind, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], dyn_active_w_flag, nchan_transport, 1 ); @@ -772,15 +758,6 @@ static ivas_error ivas_spar_cov_md_process( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS FOR( i = 0; i < nchan_inp; i++ ) { - FOR( j = 0; j < nchan_inp; j++ ) - { - Word16 k; - FOR( k = 0; k < hSpar->hFbMixer->pFb->filterbank_num_bands; k++ ) - { - cov_real[i][j][k] = me2f( cov_real_fx[i][j][k], sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][j][k] ) ); - cov_dtx_real[i][j][k] = me2f( cov_dtx_real_fx[i][j][k], sub( Q31, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band[i][j][k] ) ); - } - } free( q_cov_real[i] ); q_cov_real[i] = NULL; free( q_cov_dtx_real[i] ); @@ -821,7 +798,7 @@ static ivas_error ivas_spar_cov_md_process( IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { - IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer_fx, &hSpar->hFbMixer->q_prior_mixer_fx, *dyn_active_w_flag, hQMetaData->dirac_mono_flag, hSpar->hFbMixer->fb_cfg->num_out_chans ) ), IVAS_ERR_OK ) ) { return error; } @@ -892,35 +869,21 @@ static ivas_error ivas_spar_cov_md_process( move32(); } -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) + FOR( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); + move32(); hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); + move32(); } hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q22; + move16(); hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q22; + move16(); } - Word16 num_ch = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); - Word16 q_mixer_mat = 26; - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - q_mixer_mat = min( q_mixer_mat, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); - } - } - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - floatToFixed_arr32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], q_mixer_mat, IVAS_MAX_NUM_BANDS ); - } - } - hSpar->hMdEnc->q_mixer_mat_fx = q_mixer_mat; #endif IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { @@ -934,35 +897,26 @@ static ivas_error ivas_spar_cov_md_process( } ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, order, dtx_vad, Wscale_d_fx, hQMetaData->useLowerRes, active_w_vlbr, *dyn_active_w_flag ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) + FOR( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); + move32(); hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); + move32(); } hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q28; + move16(); hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q28; + move16(); } - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) - { - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - hSpar->hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hSpar->hMdEnc->mixer_mat_fx[i][j][b], hSpar->hMdEnc->q_mixer_mat_fx ); - } - } - } -#endif -#else - 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, hQMetaData->useLowerRes, active_w_vlbr, *dyn_active_w_flag ); #endif } IF( hSpar->hMdEnc->spar_hoa_md_flag ) { - error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); + error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer_fx, &hSpar->hFbMixer->q_prior_mixer_fx, *dyn_active_w_flag, hQMetaData->dirac_mono_flag, hSpar->hFbMixer->fb_cfg->num_out_chans ); } return error; @@ -1161,12 +1115,6 @@ static ivas_error ivas_spar_enc_process( hSpar->hFbMixer->q_ppFilterbank_inFR_re_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]] = q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]]; hSpar->hFbMixer->q_ppFilterbank_inFR_im_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]] = q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]]; - - me2f_buf( hSpar->hFbMixer->ppFilterbank_inFR_re_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], 31 - q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], - hSpar->hFbMixer->ppFilterbank_inFR_re[hSpar->hFbMixer->fb_cfg->remix_order[x]], input_frame ); - - me2f_buf( hSpar->hFbMixer->ppFilterbank_inFR_im_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], 31 - q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], - hSpar->hFbMixer->ppFilterbank_inFR_im[hSpar->hFbMixer->fb_cfg->remix_order[x]], input_frame ); } /* Need to remove fix to flt conversions */ #endif @@ -1383,45 +1331,6 @@ static ivas_error ivas_spar_enc_process( } #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 mixer_q = 31; - Word16 prior_mixer_q = 31; - Word32 num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - mixer_q = s_min( mixer_q, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); - } - } - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) - { - prior_mixer_q = s_min( prior_mixer_q, Q_factor_arrL( hSpar->hFbMixer->prior_mixer[i][j], IVAS_MAX_NUM_BANDS ) ); - } - } - - mixer_q = s_min( mixer_q, prior_mixer_q ); - // both should have a common q as there are values being copied inside function - // or need to do loop for updating values for unused values - - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - floatToFixed_arrL32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); - } - } - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) - { - floatToFixed_arrL32( hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->prior_mixer_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); - } - } - - hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; - hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; Word16 q_p_pcm_tmp_loc_fx[DIRAC_MAX_ANA_CHANS]; #endif @@ -1437,17 +1346,6 @@ static ivas_error ivas_spar_enc_process( p_pcm_tmp[ch][k] = (float) fixedToFloat( p_pcm_tmp_fx[ch][k], q_p_pcm_tmp_loc_fx[ch] ); } } - - // hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; - // hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; - // should be same - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) - { - fixedToFloat_arrL32( hSpar->hFbMixer->prior_mixer_fx[i][j], hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->q_prior_mixer_fx, IVAS_MAX_NUM_BANDS ); - } - } #endif if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index b2413c9285c758010c42b2ddf637426321a1fca7..1b07f61a6d343a04d2328f6e5325510048f0e781 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -174,24 +174,6 @@ ivas_error ivas_spar_md_enc_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - if ( ( hMdEnc->mixer_mat = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - for ( i = 0; i < num_channels; i++ ) - { - if ( ( hMdEnc->mixer_mat[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - for ( j = 0; j < num_channels; j++ ) - { - if ( ( hMdEnc->mixer_mat[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - } - } IF( ( hMdEnc->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); @@ -323,18 +305,6 @@ void ivas_spar_md_enc_close( free( hMdEnc->spar_md.band_coeffs ); hMdEnc->spar_md.band_coeffs = NULL; } - if ( hMdEnc->mixer_mat != NULL ) - { - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - free( hMdEnc->mixer_mat[i][j] ); - } - free( hMdEnc->mixer_mat[i] ); - } - free( hMdEnc->mixer_mat ); - } #ifdef IVAS_FLOAT_FIXED IF( hMdEnc->mixer_mat_fx != NULL ) { @@ -475,18 +445,6 @@ ivas_error ivas_spar_md_enc_init( hMdEnc->spar_md_cfg.prior_strat = START; hMdEnc->spar_md_cfg.prev_quant_idx = -1; - - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) - { - hMdEnc->mixer_mat[i][j][k] = 0; - } - } - } - #ifdef MSAN_FIX FOR( i = 0; i < num_channels; i++ ) { @@ -499,6 +457,8 @@ ivas_error ivas_spar_md_enc_init( } } } + hMdEnc->q_mixer_mat_fx = Q31; + move16(); #endif ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); @@ -581,19 +541,6 @@ ivas_error ivas_spar_md_enc_init_fx( } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < num_channels; i++ ) - { - FOR( j = 0; j < num_channels; j++ ) - { - FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) - { - hMdEnc->mixer_mat[i][j][k] = 0.0f; - move32(); - } - } - } -#endif hMdEnc->q_mixer_mat_fx = 0; move16(); ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); @@ -826,11 +773,12 @@ ivas_error ivas_spar_md_enc_process_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const Word16 dtx_vad, const Word16 nchan_inp, - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -) + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word32 *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ + Word16 *q_prior_mixer, /* i/o : q for prior mixer_matrix */ + const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ + const Word16 dirac_mono_flag, /* i : flag to indicate mono only mode in SBA */ + const Word16 nchan_out ) { Word32 pred_coeffs_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; @@ -1197,15 +1145,6 @@ ivas_error ivas_spar_md_enc_process_fx( { ivas_band_mixing_fx( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - fixedToFloat_arrL32( hMdEnc->mixer_mat_fx[i][j], hMdEnc->mixer_mat[i][j], hMdEnc->q_mixer_mat_fx, IVAS_MAX_NUM_BANDS ); - } - } -#endif IF( dtx_vad == 0 ) { @@ -1285,8 +1224,38 @@ ivas_error ivas_spar_md_enc_process_fx( } } } - - + IF( GT_16( hMdEnc->q_mixer_mat_fx, *q_prior_mixer ) ) + { + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + hMdEnc->mixer_mat_fx[i][j][b] = L_shr( hMdEnc->mixer_mat_fx[i][j][b], sub( hMdEnc->q_mixer_mat_fx, *q_prior_mixer ) ); + move32(); + } + } + } + hMdEnc->q_mixer_mat_fx = *q_prior_mixer; + move16(); + } + ELSE + { + FOR( i = 0; i < nchan_out; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + prior_mixer[i][j][b] = L_shr( prior_mixer[i][j][b], sub( *q_prior_mixer, hMdEnc->q_mixer_mat_fx ) ); + move32(); + } + } + } + *q_prior_mixer = hMdEnc->q_mixer_mat_fx; + move16(); + } /* Reuse mixer matrix values for unsent bands */ test(); IF( ( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) ) && GT_16( code_strat, 3 ) ) @@ -1302,9 +1271,10 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( j = 0; j < 4; j++ ) { - // TODO once fb-mixer changes are final - hMdEnc->mixer_mat[i][j][b] = prior_mixer[i][j][b]; - hMdEnc->mixer_mat[i][j][b + 1] = prior_mixer[i][j][b + 1]; + hMdEnc->mixer_mat_fx[i][j][b] = prior_mixer[i][j][b]; + move32(); + hMdEnc->mixer_mat_fx[i][j][b + 1] = prior_mixer[i][j][b + 1]; + move32(); } } } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 0286115d79d379c1cc60ceb02d65c708658254c3..eae4255072df2702f022b00915f0e471eba7026b 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1059,7 +1059,6 @@ typedef struct ivas_spar_md_enc_state_t Word16 num_umx_ch; Word16 num_decorr; - float ***mixer_mat; ivas_spar_md_com_cfg spar_md_cfg; ivas_arith_coeffs_t arith_coeffs; ivas_huff_coeffs_t huff_coeffs; @@ -1822,9 +1821,10 @@ typedef struct Word16 sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ Word16 codec_mode; /* Mode1 or Mode2 of core codec */ Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ - float **mem_hp20_in; /* input signals HP filter memories */ #ifdef IVAS_FLOAT_FIXED Word32 **mem_hp20_in_fx; /* input signals HP filter memories */ +#else + float **mem_hp20_in; /* input signals HP filter memories */ #endif /* core-encoder modules */ diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index b2dd2863fdb5c0ce8e2e81f658c9193c185f1e5a..2ba28fcf617aaa368459bc7cb2df765cd840c739 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -1738,7 +1738,14 @@ Word16 ivas_acelp_tcx20_switching_fx( basop_weight_a( A_q_tcx_fx, Ap_fx, 30147 /*0.92 in Q15*/ ); basop_lpc2mdct( Ap_fx, M, gainlpc_fx, gainlpc_e, gainlpc_noinv, gainlpc_noinv_e ); - + Word16 com_gainlpc_e = 0; + move16(); + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + com_gainlpc_e = s_max( com_gainlpc_e, gainlpc_e[i] ); + } + Copy_Scale_sig32( x_fx, x_fx, L_frame, -com_gainlpc_e ); + e_x = add( e_x, com_gainlpc_e ); mdct_shaping( x_fx, L_frame, gainlpc_fx, gainlpc_e ); FOR( i = 0; i < L_frame_4; i++ ) @@ -1748,20 +1755,20 @@ Word16 ivas_acelp_tcx20_switching_fx( move16(); tmp16 = norm_l( x_fx[0] ); - if ( x_fx[0] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[0] != 0 ) + s = s_min( s, tmp16 ); tmp16 = norm_l( x_fx[1] ); - if ( x_fx[1] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[1] != 0 ) + s = s_min( s, tmp16 ); tmp16 = norm_l( x_fx[2] ); - if ( x_fx[2] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[2] != 0 ) + s = s_min( s, tmp16 ); tmp16 = norm_l( x_fx[3] ); - if ( x_fx[3] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[3] != 0 ) + s = s_min( s, tmp16 ); s = sub( s, 2 ); /* 2 bits headroom */ @@ -1803,28 +1810,28 @@ Word16 ivas_acelp_tcx20_switching_fx( { tmp32 = L_sub( en[i], offset ); - if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } tmp32 = L_sub( en[i + 1], offset ); - if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } tmp32 = L_sub( en[i + 2], offset ); - if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } tmp32 = L_sub( en[i + 3], offset ); - if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ + IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 3.f * log2(10)/10 */ { ener = L_add( ener, tmp32 ); } @@ -1837,7 +1844,7 @@ Word16 ivas_acelp_tcx20_switching_fx( } } - if ( LE_32( offset, 0xAA153 ) ) /* 0xAA153 -> 32.f * log2(10)/10 */ + IF( LE_32( offset, 0xAA153 ) ) /* 0xAA153 -> 32.f * log2(10)/10 */ { offset = L_add( 0xFFD57AB5, 0 ); /* 0xFFD57AB5 -> -128.f * log2(10)/10; */ } @@ -1875,6 +1882,7 @@ Word16 ivas_acelp_tcx20_switching_fx( Word32 nrg_s, nrg_n; Word16 temp_e, e_num, e_den, temp_ene_e; temp_ene_e = ener_e; + move16(); tmp32 = Sqrt32( ener, &temp_ene_e ); /*Approximate SNR of TCX*/ set32_fx( x_fx, tmp32, L_frame ); /* ener_e */ @@ -2037,6 +2045,7 @@ Word16 ivas_acelp_tcx20_switching_fx( tmp32 = Mpy_32_16_1( temp_energy, tmp16 ); /*ener_e*/ tmp32 = L_shr( Mpy_32_16_1( tmp32, 0x6054 /* 0x6054 -> 10/log2(10) (2Q13) */ ), sub( 13, ener_e ) ); /* Q16*/ snr_acelp = tmp32; + move32(); /*--------------------------------------------------------------* * Switching Decision diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index ac29e728e8206ac76028074bb7ece3b7688e0ea1..ce072891d4b853256a7a845aaca9ef9c6a084b5b 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -71,16 +71,14 @@ static ivas_error setBandwidth_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BAND static ivas_error setChannelAwareConfig_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); static ivas_error sanitizeBandwidth_fx( const IVAS_ENC_HANDLE hIvasEnc ); static ivas_error sanitizeBitrateISM_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, const bool extMetadataApi ); +static Word16 getInputBufferSize_fx( const Encoder_Struct *st_ivas ); +#else +static int16_t getInputBufferSize( const Encoder_Struct *st_ivas ); #endif // IVAS_FLOAT_FIXED static ivas_error configureEncoder( IVAS_ENC_HANDLE hIvasEnc, const int32_t inputFs, const int32_t initBitrate, const IVAS_ENC_BANDWIDTH initBandwidth, const IVAS_ENC_DTX_CONFIG dtxConfig, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); -static ivas_error setBandwidth( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BANDWIDTH maxBandwidth ); static ivas_error setBitrate( IVAS_ENC_HANDLE hIvasEnc, const int32_t totalBitrate ); -static ivas_error setChannelAwareConfig( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); -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 ivas_error sanitizeBandwidth( const IVAS_ENC_HANDLE hIvasEnc ); -static ivas_error sanitizeBitrateISM( const ENCODER_CONFIG_HANDLE hEncoderConfig, const bool extMetadataApi ); 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 ); @@ -650,11 +648,11 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics_fx( ivas_error IVAS_ENC_ConfigureForSBAObjects( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const int32_t inputFs, /* i : input sampling frequency */ - const int32_t bitrate, /* i : requested bitrate of the ouput bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ - const uint16_t numObjects, /* i : number of objects to be encoded */ + const UWord16 numObjects, /* i : number of objects to be encoded */ 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_PCA_ON /* i : PCA option flag */ @@ -663,35 +661,38 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( Encoder_Struct *st_ivas; ivas_error error; - if ( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( NE_16( ( error = doCommonConfigureChecks( hIvasEnc ) ), IVAS_ERR_OK ) ) { return error; } - if ( numObjects > MAX_NUM_OBJECTS ) + IF( GT_32( numObjects, MAX_NUM_OBJECTS ) ) { return IVAS_ERR_TOO_MANY_INPUTS; } st_ivas = hIvasEnc->st_ivas; st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ + move16(); st_ivas->hEncoderConfig->sba_planar = isPlanar; + move16(); st_ivas->hEncoderConfig->sba_order = order; + move16(); /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ /*Input file will always contain all channels for a given order irrespective of planar flag*/ -#ifndef IVAS_FLOAT_FIXED - st_ivas->hEncoderConfig->nchan_inp = ivas_sba_get_nchan( st_ivas->hEncoderConfig->sba_order, 0 ) + numObjects; -#else - st_ivas->hEncoderConfig->nchan_inp = add( ivas_sba_get_nchan_fx( st_ivas->hEncoderConfig->sba_order, 0 ), (Word16) numObjects ); -#endif - - st_ivas->hEncoderConfig->Opt_PCA_ON = (int16_t) Opt_PCA_ON; + st_ivas->hEncoderConfig->nchan_inp = add( ivas_sba_get_nchan_fx( st_ivas->hEncoderConfig->sba_order, 0 ), numObjects ); + move16(); + st_ivas->hEncoderConfig->Opt_PCA_ON = extract_l( Opt_PCA_ON ); + move16(); /* Currently this is true but it is already shown in descriptive metadata that there can be inequality for this. */ - st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp - numObjects; + st_ivas->nchan_transport = sub( st_ivas->hEncoderConfig->nchan_inp, numObjects ); + move16(); st_ivas->hEncoderConfig->ivas_format = SBA_ISM_FORMAT; + move16(); st_ivas->hEncoderConfig->nchan_ism = numObjects; + move16(); return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); } @@ -919,7 +920,7 @@ static ivas_error configureEncoder( * Bandwidth limitation *-----------------------------------------------------------------*/ - if ( ( error = setBandwidth( hIvasEnc, initBandwidth ) ) != IVAS_ERR_OK ) + if ( ( error = setBandwidth_fx( hIvasEnc, initBandwidth ) ) != IVAS_ERR_OK ) { return error; } @@ -978,7 +979,7 @@ static ivas_error configureEncoder( /* check if the entered bitrate is supported */ if ( hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) /* IVAS */ { - if ( !is_IVAS_bitrate( hEncoderConfig->ivas_total_brate ) ) + if ( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) { if ( hEncoderConfig->Opt_SC_VBR ) { @@ -1017,7 +1018,7 @@ static ivas_error configureEncoder( } else if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { - if ( ( error = sanitizeBitrateISM( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) { return error; } @@ -1099,7 +1100,7 @@ static ivas_error configureEncoder( * Channel-aware mode *-----------------------------------------------------------------*/ - if ( ( error = setChannelAwareConfig( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) + if ( ( error = setChannelAwareConfig_fx( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -1153,7 +1154,7 @@ static ivas_error configureEncoder( return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." ); } - if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBandwidth_fx( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -1545,13 +1546,21 @@ ivas_error IVAS_ENC_GetDelay( * * *---------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED +static Word16 getInputBufferSize_fx( + const Encoder_Struct *st_ivas /* i : IVAS encoder handle */ +) +{ + return extract_l( Mpy_32_32( imult3216( st_ivas->hEncoderConfig->input_Fs, st_ivas->hEncoderConfig->nchan_inp ), ONE_BY_FRAMES_PER_SEC_Q31 ) ); +} +#else static int16_t getInputBufferSize( const Encoder_Struct *st_ivas /* i : IVAS encoder handle */ ) { return (int16_t) ( st_ivas->hEncoderConfig->input_Fs * st_ivas->hEncoderConfig->nchan_inp / FRAMES_PER_SEC ); } +#endif /*---------------------------------------------------------------------* * IVAS_ENC_GetNumInChannels() @@ -1584,7 +1593,28 @@ ivas_error IVAS_ENC_GetNumInChannels( * * *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_GetInputBufferSize( + const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + Word16 *inputBufferSize /* o : total number of samples expected in the input buffer for current encoder configuration */ +) +{ + IF( !hIvasEnc->isConfigured ) + { + return IVAS_ERR_NOT_CONFIGURED; + } + IF( inputBufferSize == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + *inputBufferSize = getInputBufferSize_fx( hIvasEnc->st_ivas ); + move16(); + + return IVAS_ERR_OK; +} +#else ivas_error IVAS_ENC_GetInputBufferSize( const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ int16_t *inputBufferSize /* o : total number of samples expected in the input buffer for current encoder configuration */ @@ -1604,6 +1634,7 @@ ivas_error IVAS_ENC_GetInputBufferSize( return IVAS_ERR_OK; } +#endif /*---------------------------------------------------------------------* @@ -1611,7 +1642,269 @@ ivas_error IVAS_ENC_GetInputBufferSize( * * Main function to encode one frame to a serial bitstream *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_EncodeFrameToSerial( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + Word16 *inputBuffer, /* i : PCM input, Q0 */ + Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() */ + UWord16 *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME */ + UWord16 *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value */ +) +{ + Encoder_Struct *st_ivas; + ENCODER_CONFIG_HANDLE hEncoderConfig; + Word16 i; + Word16 n, ch; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + IF( !hIvasEnc->isConfigured ) + { + return IVAS_ERR_NOT_CONFIGURED; + } + + st_ivas = hIvasEnc->st_ivas; + hEncoderConfig = st_ivas->hEncoderConfig; + ENC_CORE_HANDLE hCoreCoder = hIvasEnc->hCoreCoder; + + IF( NE_16( inputBufferSize, getInputBufferSize_fx( st_ivas ) ) ) + { + return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE; + } + + IF( NE_32( ( error = sanitizeBandwidth_fx( hIvasEnc ) ), IVAS_ERR_OK ) ) + { + return error; + } + + IF( EQ_32( hEncoderConfig->ivas_format, ISM_FORMAT ) ) + { + FOR( i = 0; i < hEncoderConfig->nchan_inp; ++i ) + { + IF( !hIvasEnc->ismMetadataProvided[i] ) + { + ivas_ism_reset_metadata_API( hIvasEnc->st_ivas->hIsmMetaData[i] ); + } + } + resetIsmMetadataProvidedFlags( hIvasEnc ); + } + + test(); + test(); + test(); + test(); + IF( ( hEncoderConfig->Opt_RF_ON && ( NE_32( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) || EQ_32( hEncoderConfig->input_Fs, 8000 ) || hEncoderConfig->max_bwidth == NB ) ) || hEncoderConfig->rf_fec_offset == 0 ) + { + test(); + IF( EQ_32( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) && EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + st_ivas->codec_mode = MODE1; + move16(); + + reset_rf_indices_fx( hCoreCoder ); + } + hEncoderConfig->Opt_RF_ON = 0; + move16(); + hEncoderConfig->rf_fec_offset = 0; + move16(); + hIvasEnc->switchingActive = true; + move16(); + } + + test(); + test(); + test(); + test(); + IF( hIvasEnc->Opt_RF_ON_loc && hIvasEnc->rf_fec_offset_loc != 0 && L_sub( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) == 0 && L_sub( hEncoderConfig->input_Fs, 8000 ) != 0 && hEncoderConfig->max_bwidth != NB ) + { + st_ivas->codec_mode = MODE2; + move16(); + test(); + IF( hEncoderConfig->Opt_RF_ON == 0 && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + reset_rf_indices_fx( hCoreCoder ); + } + hEncoderConfig->Opt_RF_ON = 1; + hEncoderConfig->rf_fec_offset = hIvasEnc->rf_fec_offset_loc; + hIvasEnc->switchingActive = true; + move16(); + move16(); + move16(); + } + + /* in case of 8kHz sampling rate or when in "max_band NB" mode, limit the total bitrate to 24.40 kbps */ + test(); + test(); + IF( ( EQ_32( hEncoderConfig->input_Fs, 8000 ) || ( hEncoderConfig->max_bwidth == NB ) ) && GT_32( hEncoderConfig->ivas_total_brate, ACELP_24k40 ) ) + { + hEncoderConfig->ivas_total_brate = ACELP_24k40; + st_ivas->codec_mode = MODE2; + hIvasEnc->switchingActive = true; + move32(); + move16(); + move16(); + } + + /*-----------------------------------------------------------------* + * Re-allocate and re-initialize buffer of indices if IVAS total bitrate has changed + *-----------------------------------------------------------------*/ + + IF( NE_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) ) + { + /* de-allocate old buffer of indices */ + free( st_ivas->ind_list ); + + /* set the maximum allowed number of indices in the list */ + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + move16(); + + /* allocate new buffer of indices */ + IF( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) ); + } + + /* reset the list of indices */ + FOR( i = 0; i < st_ivas->ivas_max_num_indices; i++ ) + { + st_ivas->ind_list[i].nb_bits = -1; + move16(); + } + + /* de-allocate old buffer of metadata indices */ + IF( st_ivas->ind_list_metadata != NULL ) + { + free( st_ivas->ind_list_metadata ); + } + + /* set the maximum allowed number of metadata indices in the list */ + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + move16(); + + IF( st_ivas->ivas_max_num_indices_metadata > 0 ) + { + /* allocate new buffer of metadata indices */ + IF( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) ); + } + + /* reset the list of metadata indices */ + FOR( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ ) + { + st_ivas->ind_list_metadata[i].nb_bits = -1; + move16(); + } + } + ELSE + { + st_ivas->ind_list_metadata = NULL; + } + + /* set pointers to the new buffers of indices in each element */ + FOR( n = 0; n < st_ivas->nSCE; n++ ) + { + test(); + IF( !( hIvasEnc->hCoreCoder == NULL && EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) ) ) + { + if ( ( hEncoderConfig->element_mode_init != EVS_MONO ) ) + { + st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ind_list = st_ivas->ind_list; + } + st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + } + + IF( st_ivas->hSCE[n]->hMetaData != NULL ) + { + st_ivas->hSCE[n]->hMetaData->ind_list = st_ivas->ind_list_metadata; + st_ivas->hSCE[n]->hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata; + } + } + + FOR( n = 0; n < st_ivas->nCPE; n++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr->ind_list = st_ivas->ind_list; + st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + } + IF( st_ivas->hCPE[n]->hMetaData != NULL ) + { + st_ivas->hCPE[n]->hMetaData->ind_list = st_ivas->ind_list_metadata; + st_ivas->hCPE[n]->hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata; + } + } + } + + test(); + IF( hIvasEnc->switchingActive && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + copy_encoder_config_fx( st_ivas, hCoreCoder, 0 ); + hEncoderConfig->last_ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); + } + + /* run the main encoding routine */ + IF( EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) ) /* EVS mono */ + { + hCoreCoder->total_brate = hEncoderConfig->ivas_total_brate; /* needed in case of bitrate switching */ + move32(); + + IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) + { + inputBufferSize = shr( inputBufferSize, 1 ); + stereo_dmx_evs_enc_fx( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize, hEncoderConfig->is_binaural ); + } + + IF( hEncoderConfig->Opt_AMR_WB ) + { + amr_wb_enc_fx( hCoreCoder, inputBuffer, inputBufferSize ); + } + ELSE + { + hCoreCoder->input_frame_fx = inputBufferSize; + move32(); + IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, hCoreCoder->mem_hp20_in_fx, inputBufferSize ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + } + ELSE /* IVAS */ + { + IF( NE_32( ( error = ivas_enc( st_ivas, inputBuffer, inputBufferSize ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + /* write indices into bitstream buffer */ + IF( EQ_16( hEncoderConfig->element_mode_init, EVS_MONO ) ) + { + test(); + IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && ( hCoreCoder->element_mode == EVS_MONO ) ) + { + /* write indices into bitstream file */ + UWord8 pFrame[( MAX_BITS_PER_FRAME + 7 ) >> 3]; + Word16 pFrame_size = 0; + move16(); + write_indices_buf_fx( hCoreCoder, hCoreCoder->hBstr, outputBitStream, pFrame, pFrame_size, numOutBits ); + } + } + ELSE + { + write_indices_ivas_fx( st_ivas, outputBitStream, numOutBits ); + } + /* Reset switching flag before next call - can be set to "true" by some setters */ + hIvasEnc->switchingActive = false; + move16(); + + return error; +} +#else ivas_error IVAS_ENC_EncodeFrameToSerial( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ int16_t *inputBuffer, /* i : PCM input */ @@ -1642,7 +1935,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE; } - if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBandwidth_fx( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -1716,7 +2009,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( free( st_ivas->ind_list ); /* set the maximum allowed number of indices in the list */ - st_ivas->ivas_max_num_indices = get_ivas_max_num_indices( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); /* allocate new buffer of indices */ if ( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) @@ -1737,7 +2030,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( } /* set the maximum allowed number of metadata indices in the list */ - st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); if ( st_ivas->ivas_max_num_indices_metadata > 0 ) { @@ -1885,6 +2178,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( return error; } +#endif #ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* @@ -1935,7 +2229,7 @@ ivas_error IVAS_ENC_SetBandwidth( } /* Use internal function to set bandiwdth */ - return setBandwidth( hIvasEnc, maxBandwidth ); + return setBandwidth_fx( hIvasEnc, maxBandwidth ); } @@ -1984,7 +2278,7 @@ ivas_error IVAS_ENC_SetChannelAwareConfig( } /* Use internal function to set CA config */ - return setChannelAwareConfig( hIvasEnc, rfConfig ); + return setChannelAwareConfig_fx( hIvasEnc, rfConfig ); } @@ -2034,8 +2328,11 @@ IVAS_ENC_CHANNEL_AWARE_CONFIG IVAS_ENC_GetDefaultChannelAwareConfig( void ) { IVAS_ENC_CHANNEL_AWARE_CONFIG defaultCaConfig; defaultCaConfig.channelAwareModeEnabled = 0; + move16(); defaultCaConfig.fec_indicator = IVAS_ENC_FEC_HI; + move16(); defaultCaConfig.fec_offset = 0; + move16(); return defaultCaConfig; } @@ -2308,7 +2605,7 @@ static ivas_error setBitrate( /* check if the entered bitrate is supported */ if ( hEncoderConfig->element_mode_init > EVS_MONO ) { - if ( !is_IVAS_bitrate( hEncoderConfig->ivas_total_brate ) ) + if ( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS: %d", hEncoderConfig->ivas_total_brate ); } @@ -2329,7 +2626,7 @@ static ivas_error setBitrate( if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { - if ( ( error = sanitizeBitrateISM( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) { return error; } @@ -2359,64 +2656,6 @@ static ivas_error setBitrate( * *---------------------------------------------------------------------*/ -static ivas_error setChannelAwareConfig( - IVAS_ENC_HANDLE hIvasEnc, - const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ) -{ - int16_t newFecIndicator; - ivas_error error; - Encoder_Struct *st_ivas; - ENCODER_CONFIG_HANDLE hEncoderConfig; - - st_ivas = hIvasEnc->st_ivas; - hEncoderConfig = st_ivas->hEncoderConfig; - - /* channel-aware mode is supported only at 13.20 kbps and with WB or SWB bandwidth */ - if ( ( caConfig.channelAwareModeEnabled && st_ivas->hEncoderConfig->ivas_total_brate != ACELP_13k20 ) || ( hEncoderConfig->Opt_RF_ON && hEncoderConfig->input_Fs == 8000 ) ) - { - hEncoderConfig->Opt_RF_ON = 0; - hEncoderConfig->rf_fec_offset = 0; - return IVAS_ERR_OK; - } - - if ( caConfig.channelAwareModeEnabled ) - { - hEncoderConfig->Opt_RF_ON = 1; - - /* Convert FEC indicator from API type */ - if ( ( error = fecIndicatorApiToInternal( caConfig.fec_indicator, &newFecIndicator ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* Set new values only if they differ from current values */ - if ( ( newFecIndicator != hEncoderConfig->rf_fec_indicator || caConfig.fec_offset != hEncoderConfig->rf_fec_offset ) ) - { - hEncoderConfig->rf_fec_indicator = newFecIndicator; - - /* Check if new FEC offset has a valid value */ - if ( caConfig.fec_offset == 0 || caConfig.fec_offset == 2 || caConfig.fec_offset == 3 || caConfig.fec_offset == 5 || caConfig.fec_offset == 7 ) - { - hEncoderConfig->rf_fec_offset = caConfig.fec_offset; - } - else - { - return IVAS_ERR_INVALID_FEC_OFFSET; - } - - hIvasEnc->switchingActive = true; - } - - /* Save a copy of FEC offset value - needed during encoding */ - hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; - } - else - { - hEncoderConfig->Opt_RF_ON = 0; - } - - return IVAS_ERR_OK; -} #ifdef IVAS_FLOAT_FIXED static ivas_error setChannelAwareConfig_fx( IVAS_ENC_HANDLE hIvasEnc, @@ -2531,94 +2770,6 @@ static ivas_error doCommonSetterChecks( * *---------------------------------------------------------------------*/ -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 && max_bwidth_tmp > NB ) - { - max_bwidth_tmp = NB; - } - else if ( hEncoderConfig->input_Fs == 16000 && max_bwidth_tmp > WB ) - { - max_bwidth_tmp = WB; - } - else if ( hEncoderConfig->input_Fs == 32000 && max_bwidth_tmp > SWB ) - { - max_bwidth_tmp = SWB; - } - - /* 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_format != ISM_FORMAT && hEncoderConfig->ivas_total_brate < MIN_BRATE_FB_STEREO ) || - ( hEncoderConfig->ivas_format == ISM_FORMAT && hEncoderConfig->ivas_total_brate / hEncoderConfig->nchan_ism < MIN_BRATE_FB_ISM ) ) ) - { - max_bwidth_tmp = SWB; - } - } - - if ( hEncoderConfig->max_bwidth != max_bwidth_tmp ) - { - hEncoderConfig->max_bwidth = max_bwidth_tmp; - hIvasEnc->switchingActive = true; - } - - return IVAS_ERR_OK; -} #ifdef IVAS_FLOAT_FIXED static ivas_error sanitizeBandwidth_fx( const IVAS_ENC_HANDLE hIvasEnc ) @@ -2710,56 +2861,11 @@ static ivas_error sanitizeBandwidth_fx( } #endif /*---------------------------------------------------------------------* - * sanitizeBitrateISM() + * sanitizeBitrateISM_fx() * * *---------------------------------------------------------------------*/ -static ivas_error sanitizeBitrateISM( - const ENCODER_CONFIG_HANDLE hEncoderConfig, - const bool extMetadataApi ) -{ - if ( hEncoderConfig->ivas_total_brate > IVAS_128k && hEncoderConfig->nchan_inp == 1 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 1 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - - if ( hEncoderConfig->ivas_total_brate > IVAS_256k && hEncoderConfig->nchan_inp == 2 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); - } - - if ( hEncoderConfig->ivas_total_brate > IVAS_384k && hEncoderConfig->nchan_inp == 3 ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 3 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 ); - } - - if ( extMetadataApi ) - { - hEncoderConfig->ism_extended_metadata_flag = ( hEncoderConfig->ivas_total_brate >= ISM_EXTENDED_METADATA_BRATE ); - } - else - { - hEncoderConfig->ism_extended_metadata_flag = 0; - } - - return IVAS_ERR_OK; -} #ifdef IVAS_FLOAT_FIXED static ivas_error sanitizeBitrateISM_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, @@ -2808,44 +2914,11 @@ static ivas_error sanitizeBitrateISM_fx( } #endif /*---------------------------------------------------------------------* - * setBandwidth() + * setBandwidth_fx() * * *---------------------------------------------------------------------*/ -static ivas_error setBandwidth( - IVAS_ENC_HANDLE hIvasEnc, - const IVAS_ENC_BANDWIDTH maxBandwidth ) -{ - ivas_error error; - int16_t newBandwidth; - ENCODER_CONFIG_HANDLE hEncoderConfig; - - hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; - - /* Convert bandwidth from API type */ - if ( ( error = bandwidthApiToInternal( maxBandwidth, &newBandwidth ) ) != IVAS_ERR_OK ) - { - 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 ) - { - newBandwidth = WB; - } - - if ( hEncoderConfig->max_bwidth != newBandwidth ) - { - hEncoderConfig->max_bwidth = newBandwidth; - hIvasEnc->switchingActive = true; - } - - return IVAS_ERR_OK; -} -#ifdef IVAS_FLOAT_FIXED static ivas_error setBandwidth_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BANDWIDTH maxBandwidth ) @@ -2878,7 +2951,6 @@ static ivas_error setBandwidth_fx( return IVAS_ERR_OK; } -#endif /*---------------------------------------------------------------------* * resetIsmMetadataProvidedFlags() diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index c50055f33110dd7c3d9b399f9f121183ac1a7ec5..67e747393764a90b97209adc897f0c732e57e391 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -257,6 +257,16 @@ ivas_error IVAS_ENC_FeedMasaMetadata( IVAS_MASA_METADATA_HANDLE hMasaMetadata /* i : MASA metadata for current frame */ ); +#ifdef IVAS_FLOAT_FIXED +/*! r: error code */ +ivas_error IVAS_ENC_EncodeFrameToSerial( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + Word16 *inputBuffer, /* i : PCM input, Q0 */ + Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() */ + UWord16 *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME */ + UWord16 *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value */ +); +#else /*! r: error code */ ivas_error IVAS_ENC_EncodeFrameToSerial( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ @@ -265,6 +275,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( uint16_t *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME */ uint16_t *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value */ ); +#endif /*! r: error code */ ivas_error IVAS_ENC_EncodeFrameToCompact( diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d113f7c4cffbf83766908b152e48c563b6ef902c..d41b70076418205e1d8865425d1079f0ec3df673 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4393,4 +4393,9 @@ void SynthesisSTFT_enc_ivas_fx( const Word16 nchan_out /* i : number of output channels */ ); +ivas_error write_indices_ivas_fx( + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + UWord16 *bit_stream, /* i/o: output bitstream */ + UWord16 *num_bits /* i : number of indices written to output */ +); #endif diff --git a/lib_rend/ivas_td_decorr.c b/lib_rend/ivas_td_decorr.c index ab172f9729371564a81af392c00f3bdeefef3ca7..8e1f4d0436605d60c37917b2818a1c326c3e22f0 100644 --- a/lib_rend/ivas_td_decorr.c +++ b/lib_rend/ivas_td_decorr.c @@ -391,7 +391,7 @@ ivas_error ivas_td_decorr_dec_open_fx( IF( ducking_flag ) { - IF( NE_32( ( error = ivas_transient_det_open( &hTdDecorr_loc->pTrans_det, output_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_transient_det_open_fx( &hTdDecorr_loc->pTrans_det, output_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -508,7 +508,7 @@ void ivas_td_decorr_dec_close( IF( ( *hTdDecorr )->pTrans_det != NULL ) { - ivas_transient_det_close( &( *hTdDecorr )->pTrans_det ); + ivas_transient_det_close_fx( &( *hTdDecorr )->pTrans_det ); } free( ( *hTdDecorr ) );