diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 47c30f497f880bc601564fef35972664bfc5b90b..988d514895f959c72f4935087dcf9a7e57168a2c 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -159,6 +159,138 @@ Word16 rate2EVSmode_float( * Re-allocate the list of indices *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ind_list_realloc( + INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */ + const Word16 max_num_indices, /* i : new maximum number of allowed indices in the list */ + Encoder_Struct *st_ivas /* i : IVAS encoder structure */ +) +{ + Word16 i, n, ch, n_channels, ind_list_pos, is_metadata, ivas_max_num_indices; + INDICE_HANDLE new_ind_list; + BSTR_ENC_HANDLE hBstr; + + IF( st_ivas == NULL ) + { + return IVAS_ERR_OK; + } + + /* get the pointer to the beginning of the old buffer of indices (either metadata or core coders) */ + IF( old_ind_list == st_ivas->ind_list_metadata ) + { + is_metadata = 1; + ivas_max_num_indices = st_ivas->ivas_max_num_indices_metadata; + } + ELSE + { + is_metadata = 0; + ivas_max_num_indices = st_ivas->ivas_max_num_indices; + } + move16(); + move16(); + + /* allocate new buffer of indices */ + IF( ( new_ind_list = (INDICE_HANDLE) malloc( max_num_indices * sizeof( Indice ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) ); + } + + /* move indices from the old list to the new list */ + FOR( i = 0; i < s_min( max_num_indices, ivas_max_num_indices ); i++ ) + { + IF( GT_16( old_ind_list[i].nb_bits, -1 ) ) + { + new_ind_list[i].id = old_ind_list[i].id; + new_ind_list[i].value = old_ind_list[i].value; + move16(); + move16(); + } + new_ind_list[i].nb_bits = old_ind_list[i].nb_bits; + move16(); + } + + /* reset nb_bits of all other indices to -1 */ + FOR( ; i < max_num_indices; i++ ) + { + new_ind_list[i].nb_bits = -1; + move16(); + } + + /* update parameters in all SCE elements */ + FOR( n = 0; n < st_ivas->nSCE; n++ ) + { + /* get the pointer to hBstr */ + IF( is_metadata ) + { + hBstr = st_ivas->hSCE[n]->hMetaData; + } + ELSE + { + hBstr = st_ivas->hSCE[n]->hCoreCoder[0]->hBstr; + } + + IF( hBstr != NULL ) + { + /* get the current position inside the old list */ + ind_list_pos = (Word16) ( hBstr->ind_list - old_ind_list ); + + /* set pointers in the new list */ + *( hBstr->ivas_ind_list_zero ) = new_ind_list; + hBstr->ind_list = &new_ind_list[ind_list_pos]; + + /* set the new maximum number of indices */ + *( hBstr->ivas_max_num_indices ) = max_num_indices; + move16(); + } + } + + /* update parameters in all CPE elements */ + FOR( n = 0; n < st_ivas->nCPE; n++ ) + { + /* get the pointer to hBstr */ + IF( is_metadata ) + { + n_channels = 1; + } + ELSE + { + n_channels = CPE_CHANNELS; + } + move16(); + + FOR( ch = 0; ch < n_channels; ch++ ) + { + IF( is_metadata ) + { + hBstr = st_ivas->hCPE[n]->hMetaData; + } + ELSE + { + hBstr = st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr; + } + + IF( hBstr != NULL ) + { + /* get the current position inside the old list */ + ind_list_pos = (Word16) ( hBstr->ind_list - old_ind_list ); + + /* set pointers in the new list */ + *( hBstr->ivas_ind_list_zero ) = new_ind_list; + hBstr->ind_list = &new_ind_list[ind_list_pos]; + + /* set the new maximum number of indices */ + *( hBstr->ivas_max_num_indices ) = max_num_indices; + move16(); + } + } + } + + /* free the old list */ + free( old_ind_list ); + + return IVAS_ERR_OK; +} +#else ivas_error ind_list_realloc( INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */ const int16_t max_num_indices, /* i : new maximum number of allowed indices in the list */ @@ -280,6 +412,7 @@ ivas_error ind_list_realloc( return IVAS_ERR_OK; } +#endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* @@ -1267,6 +1400,61 @@ void move_indices( * Check, if we will not overwrite an existing indice -> adjust the location *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error check_ind_list_limits( + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ +) +{ + Indice *ivas_ind_list_zero, *ivas_ind_list_last; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + ivas_ind_list_zero = *( hBstr->ivas_ind_list_zero ); + + /* check, if the maximum number of indices has been reached and re-allocate the buffer */ + /* the re-allocation can be avoided by increasing the limits in get_ivas_max_num_indices() or get_ivas_max_num_indices_metadata() */ + IF( GE_16( (Word16) ( &hBstr->ind_list[hBstr->nb_ind_tot] - ivas_ind_list_zero ), *( hBstr->ivas_max_num_indices ) ) ) + { + + /* reallocate the buffer of indices with increased limit */ + IF( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* check, if we will not overwrite an existing indice */ + IF( hBstr->ind_list[hBstr->nb_ind_tot].nb_bits > 0 ) + { + IF( hBstr->nb_ind_tot == 0 ) + { + /* move the pointer to the next available empty slot */ + ivas_ind_list_last = &ivas_ind_list_zero[*( hBstr->ivas_max_num_indices )]; + WHILE( hBstr->ind_list[0].nb_bits > 0 && hBstr->ind_list < ivas_ind_list_last ) + { + hBstr->ind_list++; + } + + IF( hBstr->ind_list >= ivas_ind_list_last ) + { + + /* no available empty slot -> need to re-allocate the buffer */ + IF( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Buffer of indices corrupted in frame %d! Attempt to overwrite indice ID = %d (value: %d, bits: %d)!\n", hBstr->ind_list[hBstr->nb_ind_tot].id, hBstr->ind_list[hBstr->nb_ind_tot].value, hBstr->ind_list[hBstr->nb_ind_tot].nb_bits ); + } + } + + return error; +} +#else ivas_error check_ind_list_limits( BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ) @@ -1319,6 +1507,7 @@ ivas_error check_ind_list_limits( return error; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -1327,6 +1516,65 @@ ivas_error check_ind_list_limits( * Push a new indice into the buffer *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error push_indice( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 id, /* i : ID of the indice */ + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ +) +{ + Word16 i; + Word16 j; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + /* check the limits of the list of indices */ + IF( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + { + return IVAS_ERROR( error, "Error occured in push_indice() while re-allocating the list of indices (frame %d) !\n" ); + } + + /* find the location in the list of indices based on ID */ + i = hBstr->nb_ind_tot; + move16(); + WHILE( i > 0 && LT_16( id, hBstr->ind_list[i - 1].id ) ) + { + i = sub( i, 1 ); + } + + /* shift indices, if the new ID is to be written somewhere inside the list */ + IF( i < hBstr->nb_ind_tot ) + { + FOR( j = hBstr->nb_ind_tot; j > i; j-- ) + { + hBstr->ind_list[j].id = hBstr->ind_list[j - 1].id; + hBstr->ind_list[j].nb_bits = hBstr->ind_list[j - 1].nb_bits; + hBstr->ind_list[j].value = hBstr->ind_list[j - 1].value; + move16(); + move16(); + move16(); + } + } + + + /* store the new indice in the list */ + hBstr->ind_list[i].id = id; + hBstr->ind_list[i].value = value; + hBstr->ind_list[i].nb_bits = nb_bits; + move16(); + move16(); + move16(); + + /* updates */ + hBstr->nb_ind_tot = add( hBstr->nb_ind_tot, 1 ); + hBstr->nb_bits_tot = add( hBstr->nb_bits_tot, nb_bits ); + + return error; +} +#else ivas_error push_indice( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ int16_t id, /* i : ID of the indice */ @@ -1377,6 +1625,7 @@ ivas_error push_indice( return error; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * push_next_indice() diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 2fca67ff96e8903562e2577c44308c18fe7eeabd..2bf4ecf9111b84b6a34397a7db6520bff12b26b7 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -280,23 +280,23 @@ void push_indice_fx( /* new indice - find an empty slot in the list */ i = id; move16(); - WHILE( NE_16( hBstr->ind_list_fx[i].nb_bits, -1 ) ) + WHILE( NE_16( hBstr->ind_list[i].nb_bits, -1 ) ) { i = add( i, 1 ); } } /* store the values in the list */ - hBstr->ind_list_fx[i].value = value; + hBstr->ind_list[i].value = value; move16(); - hBstr->ind_list_fx[i].nb_bits = nb_bits; + hBstr->ind_list[i].nb_bits = nb_bits; move16(); /* updates */ hBstr->next_ind_fx = add( i, 1 ); hBstr->last_ind_fx = id; move16(); - hBstr->nb_bits_tot_fx = add( hBstr->nb_bits_tot_fx, nb_bits ); + hBstr->nb_bits_tot = add( hBstr->nb_bits_tot, nb_bits ); return; } @@ -314,15 +314,15 @@ void push_next_indice_fx( { /* store the values in the list */ - hBstr->ind_list_fx[hBstr->next_ind_fx].value = value; + hBstr->ind_list[hBstr->next_ind_fx].value = value; move16(); - hBstr->ind_list_fx[hBstr->next_ind_fx].nb_bits = nb_bits; + hBstr->ind_list[hBstr->next_ind_fx].nb_bits = nb_bits; move16(); hBstr->next_ind_fx = add( hBstr->next_ind_fx, 1 ); /* update the total number of bits already written */ - hBstr->nb_bits_tot_fx = add( hBstr->nb_bits_tot_fx, nb_bits ); + hBstr->nb_bits_tot = add( hBstr->nb_bits_tot, nb_bits ); return; } @@ -343,7 +343,7 @@ void push_next_bits_fx( Word16 i, nb_bits_m15; Indice *ptr; - ptr = &hBstr->ind_list_fx[hBstr->next_ind_fx]; + ptr = &hBstr->ind_list[hBstr->next_ind_fx]; nb_bits_m15 = sub( nb_bits, 15 ); i = 0; move16(); @@ -374,8 +374,8 @@ void push_next_bits_fx( ++ptr; } } - hBstr->next_ind_fx = (Word16) ( ptr - hBstr->ind_list_fx ); - hBstr->nb_bits_tot_fx = add( hBstr->nb_bits_tot_fx, nb_bits ); + hBstr->next_ind_fx = (Word16) ( ptr - hBstr->ind_list ); + hBstr->nb_bits_tot = add( hBstr->nb_bits_tot, nb_bits ); } /*-------------------------------------------------------------------* @@ -532,7 +532,7 @@ void reset_indices_enc_fx( { Word16 i; - hBstr->nb_bits_tot_fx = 0; + hBstr->nb_bits_tot = 0; move16(); hBstr->next_ind_fx = 0; move16(); @@ -541,7 +541,7 @@ void reset_indices_enc_fx( FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - hBstr->ind_list_fx[i].nb_bits = -1; + hBstr->ind_list[i].nb_bits = -1; move16(); } @@ -596,7 +596,7 @@ void write_indices_fx( stream[i] = 0; } *pt_stream++ = (Word16) SYNC_GOOD_FRAME; - *pt_stream++ = hBstr->nb_bits_tot_fx; + *pt_stream++ = hBstr->nb_bits_tot; /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) @@ -605,15 +605,15 @@ void write_indices_fx( for ( i = 0; i < MAX_NUM_INDICES; i++ ) { - if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + if ( hBstr->ind_list[i].nb_bits != -1 ) { /* mask from MSB to LSB */ - mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + mask = 1 << ( hBstr->ind_list[i].nb_bits - 1 ); /* write bit by bit */ - for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + for ( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) { - if ( hBstr->ind_list_fx[i].value & mask ) + if ( hBstr->ind_list[i].value & mask ) { *pt_stream++ = G192_BIN1; } @@ -631,7 +631,7 @@ void write_indices_fx( { /* Create and write ToC header */ /* qbit always set to 1 on encoder side for AMRWBIO , no qbit in use for EVS, but set to 0(bad) */ - header = (UWord8) ( st_fx->Opt_AMR_WB << 5 | st_fx->Opt_AMR_WB << 4 | rate2EVSmode( hBstr->nb_bits_tot_fx * 50, &isAmrWb ) ); + header = (UWord8) ( st_fx->Opt_AMR_WB << 5 | st_fx->Opt_AMR_WB << 4 | rate2EVSmode( hBstr->nb_bits_tot * 50, &isAmrWb ) ); fwrite( &header, sizeof( UWord8 ), 1, file ); /* Write speech bits */ fwrite( pFrame, sizeof( UWord8 ), ( pFrame_size + 7 ) >> 3, file ); @@ -640,7 +640,7 @@ void write_indices_fx( /* Clearing of indices */ FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - hBstr->ind_list_fx[i].nb_bits = -1; + hBstr->ind_list[i].nb_bits = -1; move16(); } @@ -651,7 +651,7 @@ void write_indices_fx( fwrite( stream, sizeof( unsigned short ), 2 + stream[1], file ); } /* reset index pointers */ - hBstr->nb_bits_tot_fx = 0; + hBstr->nb_bits_tot = 0; hBstr->next_ind_fx = 0; hBstr->last_ind_fx = -1; @@ -690,7 +690,7 @@ void write_indices_buf_fx( } //*pt_stream++ = (Word16) SYNC_GOOD_FRAME; //*pt_stream++ = hBstr->nb_bits_tot_fx; - *num_bits = hBstr->nb_bits_tot_fx; + *num_bits = hBstr->nb_bits_tot; /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) @@ -698,15 +698,15 @@ void write_indices_buf_fx( *----------------------------------------------------------------*/ for ( i = 0; i < MAX_NUM_INDICES; i++ ) { - if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + if ( hBstr->ind_list[i].nb_bits != -1 ) { /* mask from MSB to LSB */ - mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + mask = 1 << ( hBstr->ind_list[i].nb_bits - 1 ); /* write bit by bit */ - for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + for ( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) { - if ( hBstr->ind_list_fx[i].value & mask ) + if ( hBstr->ind_list[i].value & mask ) { //*pt_stream++ = G192_BIN1; *pt_stream++ = 1; @@ -726,7 +726,7 @@ void write_indices_buf_fx( { /* Create and write ToC header */ /* qbit always set to 1 on encoder side for AMRWBIO , no qbit in use for EVS, but set to 0(bad) */ - header = (UWord8) ( st_fx->Opt_AMR_WB << 5 | st_fx->Opt_AMR_WB << 4 | rate2EVSmode( hBstr->nb_bits_tot_fx * 50, &isAmrWb ) ); + header = (UWord8) ( st_fx->Opt_AMR_WB << 5 | st_fx->Opt_AMR_WB << 4 | rate2EVSmode( hBstr->nb_bits_tot * 50, &isAmrWb ) ); // fwrite(&header, sizeof(UWord8), 1, file); memcpy( out_buf, &header, sizeof( UWord8 ) ); *num_bits += sizeof( UWord8 ); @@ -739,7 +739,7 @@ void write_indices_buf_fx( /* Clearing of indices */ FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - hBstr->ind_list_fx[i].nb_bits = -1; + hBstr->ind_list[i].nb_bits = -1; move16(); } @@ -755,7 +755,7 @@ void write_indices_buf_fx( //*num_bits += sizeof( unsigned short ) * ( 2 + stream[1] ); } /* reset index pointers */ - hBstr->nb_bits_tot_fx = 0; + hBstr->nb_bits_tot = 0; hBstr->next_ind_fx = 0; hBstr->last_ind_fx = -1; @@ -786,27 +786,27 @@ void indices_to_serial( if ( st_fx->Opt_AMR_WB ) { cmi = rate2EVSmode( st_fx->total_brate, &isAmrWb ); - core_mode = rate2EVSmode( hBstr->nb_bits_tot_fx * 50, &isAmrWb ); + core_mode = rate2EVSmode( hBstr->nb_bits_tot * 50, &isAmrWb ); j = 0; for ( i = 0; i < MAX_NUM_INDICES; i++ ) { - if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + if ( hBstr->ind_list[i].nb_bits != -1 ) { /* mask from MSB to LSB */ - mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + mask = 1 << ( hBstr->ind_list[i].nb_bits - 1 ); /* temporarily save bit */ - for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + for ( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) { - amrwb_bits[j++] = ( hBstr->ind_list_fx[i].value & mask ) > 0; + amrwb_bits[j++] = ( hBstr->ind_list[i].value & mask ) > 0; mask >>= 1; } } } } - *pFrame_size = hBstr->nb_bits_tot_fx; + *pFrame_size = hBstr->nb_bits_tot; /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) @@ -814,13 +814,13 @@ void indices_to_serial( j = 0; for ( i = 0; i < MAX_NUM_INDICES; i++ ) { - if ( hBstr->ind_list_fx[i].nb_bits != -1 ) + if ( hBstr->ind_list[i].nb_bits != -1 ) { /* mask from MSB to LSB */ - mask = 1 << ( hBstr->ind_list_fx[i].nb_bits - 1 ); + mask = 1 << ( hBstr->ind_list[i].nb_bits - 1 ); /* write bit by bit */ - for ( k = 0; k < hBstr->ind_list_fx[i].nb_bits; k++ ) + for ( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) { if ( st_fx->Opt_AMR_WB ) { @@ -828,7 +828,7 @@ void indices_to_serial( } else { - pack_bit( hBstr->ind_list_fx[i].value & mask, &pt_pFrame, &omask ); + pack_bit( hBstr->ind_list[i].value & mask, &pt_pFrame, &omask ); j++; } mask >>= 1; diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 6a4062a9878ca4d3d783114ff8b2d048a5810d5e..b319bf21cb8aef999c2c7a767d472b53adb9cf24 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -1716,7 +1716,7 @@ ivas_error openCldfb_ivas_fx( return IVAS_ERR_OK; } -ivas_error openCldfb_ivas_enc( +ivas_error openCldfb_ivas( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ const int32_t sampling_rate, /* i : sampling rate */ @@ -1734,25 +1734,17 @@ ivas_error openCldfb_ivas_enc( hs->type = type; hs->prototype = prototype; - configureCldfb_ivas_enc( hs, sampling_rate ); + configureCldfb_ivas( hs, sampling_rate ); hs->memory_flt = NULL; hs->memory_length = 0; if ( type == CLDFB_ANALYSIS ) { buf_len = hs->p_filter_length - hs->no_channels; -#ifdef IVAS_FLOAT_FIXED - hs->FilterStates = (Word16 *) malloc( ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); - hs->FilterStates_eg = 0; -#endif } else { buf_len = hs->p_filter_length; -#ifdef IVAS_FLOAT_FIXED - hs->FilterStates = (Word16 *) malloc( 2 * ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); - hs->FilterStates_eg = 0; -#endif } if ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) @@ -1768,8 +1760,7 @@ ivas_error openCldfb_ivas_enc( hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ set32_fx( hs->cldfb_state_fx, 0, buf_len ); - set16_fx( hs->FilterStates, 0, i_mult( 9 + 16, hs->no_channels ) ); - set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); + hs->Q_cldfb_state = Q11; #endif // IVAS_FLOAT_FIXED @@ -1777,6 +1768,7 @@ ivas_error openCldfb_ivas_enc( return IVAS_ERR_OK; } +#else ivas_error openCldfb_ivas( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ @@ -1812,25 +1804,15 @@ ivas_error openCldfb_ivas( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } - set_f( hs->cldfb_state, 0.0f, buf_len ); -#ifdef IVAS_FLOAT_FIXED - if ( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); - } - hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer - hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ - set32_fx( hs->cldfb_state_fx, 0, buf_len ); - hs->Q_cldfb_state = Q11; -#endif // IVAS_FLOAT_FIXED + set_f( hs->cldfb_state, 0.0f, buf_len ); *h_cldfb = hs; return IVAS_ERR_OK; } -#else -ivas_error openCldfb_ivas( +#endif +ivas_error openCldfb_ivas_enc( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ const int32_t sampling_rate, /* i : sampling rate */ @@ -1848,31 +1830,50 @@ ivas_error openCldfb_ivas( hs->type = type; hs->prototype = prototype; - configureCldfb_ivas( hs, sampling_rate ); + configureCldfb_ivas_enc( hs, sampling_rate ); hs->memory_flt = NULL; hs->memory_length = 0; if ( type == CLDFB_ANALYSIS ) { buf_len = hs->p_filter_length - hs->no_channels; +#ifdef IVAS_FLOAT_FIXED + hs->FilterStates = (Word16 *) malloc( ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); + hs->FilterStates_eg = 0; +#endif } else { buf_len = hs->p_filter_length; +#ifdef IVAS_FLOAT_FIXED + hs->FilterStates = (Word16 *) malloc( 2 * ( 9 + 16 ) * CLDFB_getNumChannels( sampling_rate ) * sizeof( Word16 ) ); + hs->FilterStates_eg = 0; +#endif } if ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } - set_f( hs->cldfb_state, 0.0f, buf_len ); +#ifdef IVAS_FLOAT_FIXED + if ( ( hs->cldfb_state_fx = (Word32 *) malloc( buf_len * sizeof( Word32 ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); + } + hs->cldfb_state_length = buf_len; // Temporarily added to store the length of buffer + hs->cldfb_size = buf_len; /*for having original size at intermediatery conversion, will be removed on removing conversion*/ + set32_fx( hs->cldfb_state_fx, 0, buf_len ); + set16_fx( hs->FilterStates, 0, i_mult( 9 + 16, hs->no_channels ) ); + set16_fx( hs->FilterStates_e, 0, sizeof( hs->FilterStates_e ) / sizeof( hs->FilterStates_e[0] ) ); +#endif // IVAS_FLOAT_FIXED + *h_cldfb = hs; return IVAS_ERR_OK; } -#endif + /*-------------------------------------------------------------------* * resampleCldfb_ivas() * diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index 7cf76a7cf329e7d33bb8cd300f9ee2061a12ec4c..5547bb30c28b3a02d3be8fd36b9701d4bde256d0 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -5,24 +5,23 @@ #include "options.h" #include "prot.h" #include "prot_fx2.h" + Word32 floatToFixed( float f, Word16 Q ) { + Word64 result_32; if ( f == 1.0f && Q == Q15 ) return MAX16B; if ( f == 1.0f && Q == Q31 ) return MAXVAL_WORD32; if ( Q < 0 ) - return (Word32) ( (float) ( f ) / (double) ( 1llu << ( -Q ) ) + ( f >= 0 ? 0.5 : -0.5 ) ); + result_32 = (Word64) ( (float) ( f ) / (double) ( 1llu << ( -Q ) ) + ( f >= 0 ? 0.5 : -0.5 ) ); else - { - Word64 result_32; result_32 = (Word64) ( f * (double) ( 1llu << Q ) + ( f >= 0 ? 0.5 : -0.5 ) ); - if ( result_32 > MAX_32 ) - return MAX_32; - if ( result_32 < MIN_32 ) - return MIN_32; - return (Word32) result_32; - } + if ( result_32 > MAX_32 ) + return MAX_32; + if ( result_32 < MIN_32 ) + return MIN_32; + return (Word32) result_32; } float fixedToFloat( Word32 i, Word16 Q ) diff --git a/lib_com/ivas_arith.c b/lib_com/ivas_arith.c index 852ddee0d678f21a979b1ebeef57daf75d1fce1b..47ac42fbda55cc46e4f0dbd0ab2cc8a06feb897c 100644 --- a/lib_com/ivas_arith.c +++ b/lib_com/ivas_arith.c @@ -35,6 +35,7 @@ #include "wmc_auto.h" #include "prot.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "stat_dec.h" /*-----------------------------------------------------------------------------------------* @@ -188,7 +189,7 @@ void ivas_ari_done_decoding_14bits_ext_1_lfe( * * Arith encoding of last table entry *-------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_ari_done_encoding_14bits( BSTR_ENC_HANDLE hBstr, Tastat *s ) @@ -224,14 +225,51 @@ void ivas_ari_done_encoding_14bits( return; } +#else +void ivas_ari_done_encoding_14bits_fx( + BSTR_ENC_HANDLE hBstr, + Tastat *s ) +{ + Word32 low; + Word32 bits_to_follow; + + /* not needed, s points to s->low */ + low = s->low; + move32(); + bits_to_follow = L_add( s->bits_to_follow, 1 ); + + IF( LT_32( low, ari_q1new ) ) + { + push_next_indice( hBstr, 0, 1 ); /*send a zero*/ + + FOR( ; bits_to_follow > 0; bits_to_follow-- ) + { + push_next_indice( hBstr, 1, 1 ); /*send a one*/ + } + } + ELSE + { + push_next_indice( hBstr, 1, 1 ); /*send a one*/ + FOR( ; bits_to_follow > 0; bits_to_follow-- ) + { + push_next_indice( hBstr, 0, 1 ); /*send a zero*/ + } + } + /*It is done so no need to save values-> no counting*/ + /*s->low = low; + s->bits_to_follow = bits_to_follow;*/ + + return; +} +#endif /*--------------------------------------------------------------- * Function ivas_ari_encode_14bits_ext() * * Arith encode function for extended proba tables *-------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_ari_encode_14bits_ext( BSTR_ENC_HANDLE hBstr, Tastat *s, @@ -300,3 +338,80 @@ void ivas_ari_encode_14bits_ext( return; } +#else +void ivas_ari_encode_14bits_ext_fx( + BSTR_ENC_HANDLE hBstr, + Tastat *s, + Word32 symbol, + const UWord16 *cum_freq ) +{ + Word32 low, high, range; + Word32 bits_to_follow; + + /*for all operation using bit_ptr=&ptr[bp] */ + /* for reading s->high,low,bits_to_follow sequentially */ + high = s->high; + low = s->low; + range = L_add( L_sub( high, low ), 1 ); + move32(); + move32(); + + high = L_sub( L_add( low, mul_sbc_14bits_ivas( range, cum_freq[symbol] ) ), 1 ); + low = L_add( low, mul_sbc_14bits_ivas( range, cum_freq[L_add( symbol, 1 )] ) ); + + bits_to_follow = s->bits_to_follow; + move32(); + + FOR( ;; ) + { + IF( LT_32( high, ari_q2new ) ) + { + push_next_indice( hBstr, 0, 1 ); /*send a zero*/ + FOR( ; bits_to_follow > 0; bits_to_follow-- ) + { + push_next_indice( hBstr, 1, 1 ); /*send a one*/ + } + } + ELSE + { + IF( GE_32( low, ari_q2new ) ) + { + push_next_indice( hBstr, 1, 1 ); /*send a one*/ + FOR( ; bits_to_follow > 0; bits_to_follow-- ) + { + push_next_indice( hBstr, 0, 1 ); /*send a zero*/ + } + low = L_sub( low, ari_q2new ); + high = L_sub( high, ari_q2new ); /* Subtract offset to top. */ + } + ELSE + { + /* Output an opposite bit */ + test(); + IF( GE_32( low, ari_q1new ) && LT_32( high, ari_q3new ) ) /* Output an opposite bit */ + { + /* later if in middle half. */ + bits_to_follow = L_add( bits_to_follow, 1 ); + low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/ + high = L_sub( high, ari_q1new ); + } + ELSE + { + BREAK; /* Otherwise exit loop. */ + } + } + } + low = L_add( low, low ); + high = L_add( L_add( high, high ), 1 ); /* Scale up code range. */ + } + + s->low = low; + s->high = high; + s->bits_to_follow = bits_to_follow; + move32(); + move32(); + move32(); + + return; +} +#endif diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 62183974c6d12e5030d84a3cafb91b7857be8f86..b56c3d35b18d9c7a64691bed6dff7d443194e563 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -586,8 +586,14 @@ typedef enum #define STEREO_DFT_FLAG_BITS 1 #define STEREO_DFT_SIDEGAIN_NBITS 5 #define STEREO_DFT_FEC_THRESHOLD 10 +#ifdef IVAS_FLOAT_FIXED +#define STEREO_DFT_FEC_THRESHOLD_PLUS_1_INV_Q31 ( 195225786 ) +#define STEREO_DFT_BITDIFF_LP_FAC_Q31 ( 128849019 ) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ +#define STEREO_DFT_BITDIFF_ABS_SELECT_Q31 ( 1717986918 ) /* Constant to set tendency for selecting absolute coding mode */ +#else #define STEREO_DFT_BITDIFF_LP_FAC (0.06f) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ #define STEREO_DFT_BITDIFF_ABS_SELECT (0.8f) /* Constant to set tendency for selecting absolute coding mode */ +#endif #define STEREO_DFT_BITDIFF_INIT (12.0f) /* Init value for low-pass bit difference */ #define STEREO_DFT_BITDIFF_INIT_FX (12288) /* Init value for low-pass bit difference in Q10*/ diff --git a/lib_com/ivas_filters.c b/lib_com/ivas_filters.c index 69a4e13c1aa953ecfa529ba3d6572fff6a33861f..2790cfb5cf36b553cab9b825045fce584abb78e0 100644 --- a/lib_com/ivas_filters.c +++ b/lib_com/ivas_filters.c @@ -43,8 +43,9 @@ /*------------------------------------------------------------------------------------------* * Local functions declaration *------------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_iir_2_filter( ivas_filters_process_state_t *filter_state, float *pIn_Out, const int16_t length, const int16_t stage ); -#ifdef IVAS_FLOAT_FIXED +#else static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Word32 *pIn_Out_fx, const Word16 length, const Word16 stage, Word16 q_fcator ); #endif /*-----------------------------------------------------------------------------------------* @@ -52,7 +53,7 @@ static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Wo * * Initialisation call for filtering a signal *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_filters_init( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ const float *filt_coeff, /* i : filter coefficients */ @@ -98,15 +99,17 @@ void ivas_filters_init( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_filters_init_fx( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ const Word32 *filt_coeff_fx, /* i : filter coefficients */ + const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ const Word16 order ) /* i : filter order */ { Word16 i; filter_state->order = order; - + move16(); + test(); IF( EQ_16( order, IVAS_FILTER_ORDER_2 ) || EQ_16( order, IVAS_FILTER_ORDER_1 ) ) { filter_state->filt_len = add( order, 1 ); @@ -114,12 +117,27 @@ void ivas_filters_init_fx( FOR( i = 0; i < IVAS_BIQUAD_FILT_LEN; i++ ) { filter_state->num_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i]; - filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[add( i, IVAS_BIQUAD_FILT_LEN )]; + filter_state->num_e[IVAS_FILTER_STAGE_0][i] = 1; + filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN]; + filter_state->den_e[IVAS_FILTER_STAGE_0][i] = 1; + move32(); + move32(); + move16(); + move16(); } filter_state->state_fx[0][0] = 0; + filter_state->state_e[0][0] = 0; filter_state->state_fx[0][1] = 0; + filter_state->state_e[0][1] = 0; filter_state->state_fx[0][2] = 0; + filter_state->state_e[0][2] = 0; + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); } ELSE { @@ -129,17 +147,47 @@ void ivas_filters_init_fx( { filter_state->num_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i]; - filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[add( i, IVAS_BIQUAD_FILT_LEN )]; - filter_state->num_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[add( i, i_mult( IVAS_BIQUAD_FILT_LEN, 2 ) )]; - filter_state->den_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[add( i, i_mult( IVAS_BIQUAD_FILT_LEN, 3 ) )]; + filter_state->num_e[IVAS_FILTER_STAGE_0][i] = filt_coeff_e[i]; + filter_state->den_fx[IVAS_FILTER_STAGE_0][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN]; + filter_state->den_e[IVAS_FILTER_STAGE_0][i] = filt_coeff_e[i + IVAS_BIQUAD_FILT_LEN]; + filter_state->num_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN * 2]; + filter_state->num_e[IVAS_FILTER_STAGE_1][i] = filt_coeff_e[i + IVAS_BIQUAD_FILT_LEN * 2]; + filter_state->den_fx[IVAS_FILTER_STAGE_1][i] = filt_coeff_fx[i + IVAS_BIQUAD_FILT_LEN * 3]; + filter_state->den_e[IVAS_FILTER_STAGE_1][i] = filt_coeff_e[i + IVAS_BIQUAD_FILT_LEN * 3]; + move32(); + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); + move16(); } filter_state->state_fx[0][0] = 0; + filter_state->state_e[0][0] = 0; filter_state->state_fx[0][1] = 0; + filter_state->state_e[0][1] = 0; filter_state->state_fx[0][2] = 0; + filter_state->state_e[0][2] = 0; filter_state->state_fx[1][0] = 0; + filter_state->state_e[1][0] = 0; filter_state->state_fx[1][1] = 0; + filter_state->state_e[1][1] = 0; filter_state->state_fx[1][2] = 0; + filter_state->state_e[1][2] = 0; + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); } return; @@ -152,6 +200,7 @@ void ivas_filters_init_fx( * * Process call for selecting the type filter *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_filter_process( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ float *pIn_Out, /* i/o: signal subject to filtering */ @@ -177,7 +226,7 @@ void ivas_filter_process( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_filter_process_fx( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ Word32 *pIn_Out_fx, /* i/o: signal subject to filtering */ @@ -210,6 +259,7 @@ void ivas_filter_process_fx( * * Process call for filtering a signal *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_iir_2_filter( ivas_filters_process_state_t *filter_state, float *pIn_Out, @@ -235,7 +285,7 @@ static void ivas_iir_2_filter( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Word32 *pIn_Out_fx, @@ -247,92 +297,44 @@ static void ivas_iir_2_filter_fx( Word32 *pIn_fx = pIn_Out_fx; Word32 *pOut_fx = pIn_Out_fx; + Word16 pOut_e; Word32 tmp_pIn_buf_i_fx; - Word32 L_tmp, L_tmp_1; - Word64 L_tmp_2; - Word16 L_tmp_q_factor, L_tmp_2_q_factor, L_tmp_3_q_factor, L_tmp_4_q_factor, L_tmp_5_q_factor, L_tmp_6_q_factor; - - Word16 q_factor_diff; - - Word16 q_factor_filter_num = 30; - Word16 q_factor_filter_den = 30; + Word32 L_tmp_prod, L_tmp; + Word16 L_prod_e, L_tmp_e; FOR( i = 0; i < length; i++ ) { tmp_pIn_buf_i_fx = pIn_fx[i]; + move32(); - /*L_tmp = Mpy_32_32(pIn_fx[i], filter_state->num_fx[stage][0]);*/ + L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ); + L_prod_e = sub( 31, sub( q_factor, filter_state->num_e[stage][0] ) ); // 31 - ( ( q_factor + ( 31 - filter_state->num_e[stage][0] ) ) - 31 ) - L_tmp_q_factor = sub( add( q_factor, q_factor_filter_num ), 31 ); + pOut_fx[i] = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][0], filter_state->state_e[stage][0], L_tmp_prod, L_prod_e, &pOut_e ); + move32(); - IF( GE_16( L_tmp_q_factor, q_factor ) ) - { - q_factor_diff = sub( L_tmp_q_factor, q_factor ); - pOut_fx[i] = L_add( ( filter_state->state_fx[stage][0] ), L_shr( Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ), q_factor_diff ) ); - L_tmp_2_q_factor = q_factor; - } - ELSE + FOR( j = 1; j < filter_state->filt_len; j++ ) { - q_factor_diff = sub( q_factor, L_tmp_q_factor ); - pOut_fx[i] = L_add( L_shr( filter_state->state_fx[stage][0], q_factor_diff ), ( Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ) ) ); - pOut_fx[i] = L_shl( pOut_fx[i], q_factor_diff ); - L_tmp_2_q_factor = q_factor; - } + L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ); + L_prod_e = sub( 31, sub( q_factor, filter_state->num_e[stage][j] ) ); // 31 - ( ( q_factor + ( 31 - filter_state->num_e[stage][j] ) ) - 31 ) + L_tmp = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][j], filter_state->state_e[stage][j], L_tmp_prod, L_prod_e, &L_tmp_e ); - FOR( j = 1; j < filter_state->filt_len; j++ ) + L_tmp_prod = Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ); + L_prod_e = add( pOut_e, filter_state->den_e[stage][j] ); // 31 - ( ( ( 31 - pOut_e ) + ( 31 - filter_state->den_e[stage][j] ) ) - 31 ); + + filter_state->state_fx[stage][j - 1] = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, L_negate( L_tmp_prod ), L_prod_e, &filter_state->state_e[stage][j - 1] ); + move32(); + } + + /* Scaling pOut_fx to Q11 */ + pOut_fx[i] = L_shr_sat( pOut_fx[i], sub( sub( 31, q_factor ), pOut_e ) ); + move32(); + IF( pOut_fx[i] < 0 ) { - /*L_tmp_1 = filter_state->num_fx[stage][j] * tmp_pIn_buf_i_fx;*/ - - L_tmp_3_q_factor = sub( add( q_factor_filter_num, q_factor ), 31 ); - - IF( GE_16( L_tmp_3_q_factor, q_factor ) ) - { - q_factor_diff = sub( L_tmp_3_q_factor, q_factor ); - L_tmp = L_add( ( filter_state->state_fx[stage][j] ), L_shr( Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ), q_factor_diff ) ); - L_tmp_4_q_factor = q_factor; - } - ELSE - { - q_factor_diff = sub( q_factor, L_tmp_3_q_factor ); - L_tmp = L_add( L_shr( filter_state->state_fx[stage][j], q_factor_diff ), ( Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ) ) ); - L_tmp_4_q_factor = L_tmp_3_q_factor; - } - - /*L_tmp_3 = filter_state->den_fx[stage][j] * pOut_fx[i];*/ - - L_tmp_5_q_factor = sub( add( q_factor_filter_den, L_tmp_2_q_factor ), 31 ); - - - IF( GE_16( L_tmp_5_q_factor, L_tmp_4_q_factor ) ) - { - q_factor_diff = sub( L_tmp_5_q_factor, L_tmp_4_q_factor ); - L_tmp_1 = L_sub( L_tmp, L_shr( Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ), q_factor_diff ) ); - L_tmp_6_q_factor = L_tmp_4_q_factor; - } - ELSE - { - q_factor_diff = sub( L_tmp_4_q_factor, L_tmp_5_q_factor ); - L_tmp_1 = L_sub( L_shr( L_tmp, q_factor_diff ), Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ) ); - L_tmp_6_q_factor = L_tmp_5_q_factor; - } - - IF( GE_16( L_tmp_6_q_factor, q_factor ) ) - { - q_factor_diff = sub( L_tmp_6_q_factor, q_factor ); - L_tmp_2 = W_shr( (Word64) L_tmp_1, q_factor_diff ); - } - ELSE - { - q_factor_diff = sub( q_factor, L_tmp_6_q_factor ); - L_tmp_2 = W_shl( (Word64) L_tmp_1, q_factor_diff ); - } - - - filter_state->state_fx[stage][j - 1] = W_extract_l( L_tmp_2 ); - - // filter_state->state[stage][j - 1] = WORD322FL_SCALE(filter_state->state_fx[stage][j - 1], sub(31, q_factor)); + pOut_fx[i] = L_add( pOut_fx[i], 1 ); + move32(); } } } diff --git a/lib_com/ivas_lfe_com.c b/lib_com/ivas_lfe_com.c index 99c7741c31556781b8601f8146ea743fa19d3342..0249e288e90557f7e2a7b88f045d4473501458e1 100644 --- a/lib_com/ivas_lfe_com.c +++ b/lib_com/ivas_lfe_com.c @@ -54,7 +54,7 @@ * * Selects LFE filter coeff based on config. *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_lfe_lpf_select_filt_coeff( const int32_t sampling_rate, /* i : sampling rate */ const int16_t order, /* i : filter order */ @@ -102,11 +102,12 @@ void ivas_lfe_lpf_select_filt_coeff( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_lfe_lpf_select_filt_coeff_fx( - const Word32 sampling_rate, /* i : sampling rate */ - const Word16 order, /* i : filter order */ - const Word32 **ppFilt_coeff_fx /* o : filter coefficients */ + const Word32 sampling_rate, /* i : sampling rate */ + const Word16 order, /* i : filter order */ + const Word32 **ppFilt_coeff_fx, /* o : filter coefficients */ + const Word16 **ppFilt_coeff_e /* o : exponents of filter coefficients */ ) { SWITCH( order ) @@ -132,12 +133,15 @@ void ivas_lfe_lpf_select_filt_coeff_fx( { case 16000: *ppFilt_coeff_fx = ivas_lpf_4_butter_16k_sos_fx; + *ppFilt_coeff_e = ivas_lpf_4_butter_16k_sos_e; BREAK; case 32000: *ppFilt_coeff_fx = ivas_lpf_4_butter_32k_sos_fx; + *ppFilt_coeff_e = ivas_lpf_4_butter_32k_sos_e; BREAK; case 48000: *ppFilt_coeff_fx = ivas_lpf_4_butter_48k_sos_fx; + *ppFilt_coeff_e = ivas_lpf_4_butter_48k_sos_e; BREAK; default: BREAK; @@ -185,15 +189,19 @@ void ivas_lfe_window_init_fx( /* 10ms stride, MDCT will be done in two iterations */ hLFEWindow->dct_len = shr( frame_len, 1 ); + move16(); /* 8ms of latency */ - hLFEWindow->fade_len = NS2SA( sampling_rate, IVAS_LFE_FADE_NS ); + hLFEWindow->fade_len = NS2SA_fx2( sampling_rate, IVAS_LFE_FADE_NS ); hLFEWindow->zero_pad_len = ( mult( IVAS_ZERO_PAD_LEN_MULT_FAC_fx, sub( hLFEWindow->dct_len, hLFEWindow->fade_len ) ) ); hLFEWindow->full_len = add( add( hLFEWindow->zero_pad_len, hLFEWindow->fade_len ), hLFEWindow->dct_len ); + move16(); + move16(); + move16(); return; } -#endif +#else void ivas_lfe_window_init( LFE_WINDOW_HANDLE hLFEWindow, /* i/o: LFE window handle */ const int32_t sampling_rate, /* i : sampling rate */ @@ -228,3 +236,4 @@ void ivas_lfe_window_init( return; } +#endif diff --git a/lib_com/ivas_mdct_imdct_fx.c b/lib_com/ivas_mdct_imdct_fx.c index 486f3a8dbfb5f9f3012f88ff5f9b0f4bb72b879b..e5bdfca190fca1aa1ea5232a1e65174d25641033 100644 --- a/lib_com/ivas_mdct_imdct_fx.c +++ b/lib_com/ivas_mdct_imdct_fx.c @@ -355,7 +355,6 @@ void ivas_imdct_fx( * * Sets/Maps the fft twiddle tables based on fft length *-----------------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED void ivas_get_twid_factors_fx1( const Word16 length, const Word16 **pTwid_re, @@ -388,7 +387,6 @@ void ivas_get_twid_factors_fx1( return; } -#endif /*-----------------------------------------------------------------------------------------* * Function ivas_get_mdct_scaling_gain_fx() diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index ffb1b601418b314277e327e86a2510b4813f98e0..65b5e6c503c0d7b700492a3d6fc422bee20684be 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1435,6 +1435,19 @@ void ivas_param_ism_params_to_masa_param_mapping( ivas_error ivas_ism_dtx_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_ism_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word16 vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + Word16 md_diff_flag[], /* o : metadata differential flag */ + Word16 *sid_flag /* o : indication of SID frame */ +); +#endif // IVAS_FLOAT_FIXED /*! r: indication of DTX frame */ int16_t ivas_ism_dtx_enc( @@ -1485,6 +1498,14 @@ void ivas_ism_metadata_sid_dec( ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ int16_t nb_bits_metadata[] /* o : number of metadata bits */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_ism_get_sce_id_dtx_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length per channel */ +); +#endif // IVAS_FLOAT_FIXED void ivas_ism_get_sce_id_dtx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ @@ -1497,6 +1518,14 @@ void ivas_param_ism_compute_noisy_speech_flag( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_ism_coh_estim_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length */ +); +#endif // IVAS_FLOAT_FIXED void ivas_ism_coh_estim_dtx_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ @@ -1891,6 +1920,16 @@ void filter_with_allpass( ); /*! r: used GR order */ +#ifdef IVAS_FLOAT_FIXED +Word16 write_bitstream_adapt_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : values to be written in bitstream */ + const Word16 len, /* i : values vector length */ + const Word16 GR_ord, /* i : GR order to be used */ + const Word16 no_GR_ord /* i : speech/music 0/1 */ +); +#else int16_t write_bitstream_adapt_GR( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t Indice, /* i : identifier for bitstream index */ @@ -1899,8 +1938,27 @@ int16_t write_bitstream_adapt_GR( const int16_t GR_ord, /* i : GR order to be used */ const int16_t sp_aud_decision /* i : speech/music 0/1 */ ); +#endif /*! r: used GR order */ +#ifdef IVAS_FLOAT_FIXED +Word16 adapt_GR_ief_fx( + const Word16 *in, /* i : vector to encode */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *map0, /* i : mapping array */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + Word16 *nbits_diff, /* o : number bits in diff encoding */ + const Word16 side_gain_counter, /* i : number of frames since last abs coding */ + Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ + Word16 *q_side_gain_bitdiff_lp, /* i/o: Q of LP-filtered bit difference between abs/diff */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +); +#else int16_t adapt_GR_ief( const int16_t *in, /* i : vector to encode */ int16_t *in_diff, /* o : encoded symbols in case of differential encoding */ @@ -1916,7 +1974,23 @@ int16_t adapt_GR_ief( float *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ const int16_t try_diff /* i : diff coding allowed 1/0 */ ); +#endif +#ifdef IVAS_FLOAT_FIXED +Word16 adapt_GR_rpg1_ief( + const Word16 *in, /* i : res pred gains input vector */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *maps, /* i : mapping array */ + Word16 *nbits_diff, /* o : estimated no of bits for differential encoding */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +); +#else /*! r: used GR order */ int16_t adapt_GR_rpg1_ief( const int16_t *in, /* i : res pred gains input vector */ @@ -1931,16 +2005,35 @@ int16_t adapt_GR_rpg1_ief( const int16_t no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ const int16_t try_diff /* i : diff coding allowed 1/0 */ ); +#endif /*! r: number of bits written */ +#ifdef IVAS_FLOAT_FIXED +Word16 write_GR1( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +); +#else int16_t write_GR1( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ const int16_t *in, /* i : input vector */ const int16_t len /* i : vector length */ ); +#endif /*! r: number of bits written */ +#ifdef IVAS_FLOAT_FIXED +Word16 write_bitstream_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : input vector */ + const Word16 len, /* i : input vector length */ + const Word16 GR_ord /* i : GR order */ +); +#else int16_t write_bitstream_GR( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ @@ -1948,6 +2041,7 @@ int16_t write_bitstream_GR( const int16_t len, /* i : input data length */ const int16_t GR_ord /* i : GR order to be used */ ); +#endif #ifndef IVAS_FLOAT_FIXED /*! r: number of bits read */ @@ -3649,12 +3743,21 @@ void stereo_mdct2dft_update_fx( Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 */ ); /*! r: number of bits written */ +#ifdef IVAS_FLOAT_FIXED +Word16 write_GR0( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +); +#else int16_t write_GR0( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ const int16_t *in, /* i : data to be encoded */ const int16_t len /* i : input data length */ ); +#endif #ifndef IVAS_FLOAT_FIXED /*! r: number of bits read */ @@ -7219,7 +7322,8 @@ void ivas_lfe_lpf_select_filt_coeff( void ivas_lfe_lpf_select_filt_coeff_fx( const Word32 sampling_rate, /* i : sampling rate */ const Word16 order, /* i : filter order */ - const Word32 **ppFilt_coeff_fx /* o : filter coefficients */ + const Word32 **ppFilt_coeff_fx, /* o : filter coefficients */ + const Word16 **ppFilt_coeff_e /* o : exponents of filter coefficients */ ); #endif @@ -7234,6 +7338,7 @@ void ivas_filters_init( void ivas_filters_init_fx( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ const Word32 *filt_coeff, /* i : filter coefficients */ + const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ const Word16 order /* i : filter order */ ); #endif diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 12a8e69c80ef5bdc2106cd3f1c0a8d6924644985..6be57ae485f94705241d6e37db15ec78a1b1af96 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2423,4 +2423,26 @@ void tdm_SCh_LSF_intra_pred_fx( const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ ); + +ivas_error ivas_create_lfe_lpf_enc_fx( + ivas_filters_process_state_t **hLfeLpf, /* o : LFE LPF handle */ + const Word32 input_Fs /* i : input sampling rate */ +); + +void ivas_lfe_lpf_enc_apply_fx( + ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle */ + Word32 data_lfe_ch[], /* i/o: LFE signal */ + const Word16 input_frame /* i : input frame length per channel */ +); + +// ivas_arith.c +void ivas_ari_done_encoding_14bits_fx( + BSTR_ENC_HANDLE hBstr, + Tastat *s ); + +void ivas_ari_encode_14bits_ext_fx( + BSTR_ENC_HANDLE hBstr, + Tastat *s, + Word32 symbol, + const UWord16 *cum_freq ); #endif diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 6dddb795f36a3dbf7f495ee7c42f97220c702cc0..42176bf82d51ad39af8b391fedd2a928f2b8ee28 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1664,33 +1664,46 @@ const Word32 ism_elevation_borders_fx[4] = { *----------------------------------------------------------------------------------*/ const Word32 ivas_lpf_4_butter_16k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2] = { - 0x1ab, 0x356, 0x1ab, 0x40000000, + // 0x1ab, 0x356, 0x1ab, 0x40000000, + 0x3558C94E, 0x3558C95D, 0x3558C94E, 0x40000000, 0x85ec0b80, 0x3a3cb940, 0x40000000, 0x7fffffff, 0x40000000, 0x40000000, 0x829d8180, 0x3d8c5e40 }; +const Word16 ivas_lpf_4_butter_16k_sos_e[IVAS_BIQUAD_FILT_LEN << 2] = { + -20, -19, -20, 1, 1, 1, 1, 1, 1, 1, 1, 1 +}; const Word32 ivas_lpf_4_butter_32k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2] = { - 0x1c, 0x37, 0x1c, 0x40000000, + // 0x1c, 0x37, 0x1c, 0x40000000, + 0x371ED5AA, 0x371ED5BA, 0x371ED5AA, 0x40000000, 0x82fd4b80, 0x3d0d2280, 0x40000000, 0x7fffffff, 0x40000000, 0x40000000, 0x81478600, 0x3ec30c00 }; +const Word16 ivas_lpf_4_butter_32k_sos_e[IVAS_BIQUAD_FILT_LEN << 2] = { + -24, -23, -24, 1, 1, 1, 1, 1, 1, 1, 1, 1 +}; const Word32 ivas_lpf_4_butter_48k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2] = { - 0x6, 0xb, 0x6, 0x40000000, - 0x81ffd700, 0x3e04d500, 0x40000000, 0x7fffff80, - 0x40000000, 0x40000000, 0x80d8b600, 0x3f2c0080 + // 6, 11, 6, 1073741824, /* Q30 */ + 1477520448, 1477520448, 1477520448, 1073741824, + -2113939767, 1040504054, 1073741824, 2147483480, + 1073741829, 1073741824, -2133281237, 1059848324 +}; +const Word16 ivas_lpf_4_butter_48k_sos_e[IVAS_BIQUAD_FILT_LEN << 2] = { + -27, -26, -27, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; -const Word32 ivas_lpf_2_butter_16k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { - 0xa4d0c, 0x149a17, 0xa4d0c, 0x40000000, 0x849e6300, 0x3b8ad140 +const Word32 ivas_lpf_2_butter_16k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { /* Q30 */ + 0xa4d0c, 0x149a17, 0xa4d0c, 0x40000000, 0x849e6300, 0x3b8ad140 }; -const Word32 ivas_lpf_2_butter_32k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { - 0x53e1a, 0x29f0d, 0x40000000, 0x824f6000, 0x3dbb1c80, 0x29f0d +const Word32 ivas_lpf_2_butter_32k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { /* Q30 */ + // 0x53e1a, 0x29f0d, 0x40000000, 0x824f6000, 0x3dbb1c80, 0x29f0d + 0x29F0D, 0x53E1A, 0x29F0D, 0x40000000, 0x824F5FC3, 0x3DBB1C71 }; -const Word32 ivas_lpf_2_butter_48k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { - 0x12c07, 0x2580d, 0x12c07, 0x40000000, 0x818a4580, 0x3e7a6a80 +const Word32 ivas_lpf_2_butter_48k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { /* Q30 */ + 0x12c07, 0x2580d, 0x12c07, 0x40000000, 0x818a4580, 0x3e7a6a80 }; const Word32 ivas_lfe_window_coeff_48k_fx[IVAS_LFE_FADE_LEN_48K] = { diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 049dd0aadf00cdc043345b456e2ad1ad1bbf27ca..29a5b21cf6cc9ae796e7b903a7c2bc083699e101 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -206,8 +206,11 @@ extern const Word32 ism_elevation_borders_fx[4]; *----------------------------------------------------------------------------------*/ extern const Word32 ivas_lpf_4_butter_16k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2]; +extern const Word16 ivas_lpf_4_butter_16k_sos_e[IVAS_BIQUAD_FILT_LEN << 2]; extern const Word32 ivas_lpf_4_butter_32k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2]; +extern const Word16 ivas_lpf_4_butter_32k_sos_e[IVAS_BIQUAD_FILT_LEN << 2]; extern const Word32 ivas_lpf_4_butter_48k_sos_fx[IVAS_BIQUAD_FILT_LEN << 2]; +extern const Word16 ivas_lpf_4_butter_48k_sos_e[IVAS_BIQUAD_FILT_LEN << 2]; extern const Word32 ivas_lpf_2_butter_16k_fx[IVAS_BIQUAD_FILT_LEN << 1]; extern const Word32 ivas_lpf_2_butter_32k_fx[IVAS_BIQUAD_FILT_LEN << 1]; extern const Word32 ivas_lpf_2_butter_48k_fx[IVAS_BIQUAD_FILT_LEN << 1]; diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 8a042ca26a85f3123da0b1c174caf14116ba744e..67b03df524540011e6ec3361cbd9e026bf972045 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -731,12 +731,14 @@ typedef struct ivas_filters_process_state_t Word32 num_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; Word32 den_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; Word32 state_fx[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; - Word32 state_fx_q_factor[IVAS_FILTER_MAX_STAGES]; -#endif + Word16 num_e[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; + Word16 den_e[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; + Word16 state_e[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; +#else float num[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; float den[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; float state[IVAS_FILTER_MAX_STAGES][IVAS_BIQUAD_FILT_LEN]; - +#endif } ivas_filters_process_state_t; diff --git a/lib_com/ivas_transient_det.c b/lib_com/ivas_transient_det.c index 54539e3838ee7f05bca45d0e718f490cf96f7674..a8841845aa60f53ac08e49290c8b5714604f36a6 100644 --- a/lib_com/ivas_transient_det.c +++ b/lib_com/ivas_transient_det.c @@ -134,6 +134,7 @@ static void ivas_transient_det_init( float filt_coeff_arr[3][IVAS_BIQUAD_FILT_LEN << 1]; #else Word32 filt_coeff_arr_fx[3][IVAS_BIQUAD_FILT_LEN << 1]; + const Word16 *filt_coeff_arr_e = NULL; #endif #ifdef IVAS_FLOAT_FIXED @@ -284,9 +285,9 @@ static void ivas_transient_det_init( ivas_filters_init( &hTranDet->env_fast, (const float *) filt_coeff_arr[1], IVAS_FILTER_ORDER_1 ); ivas_filters_init( &hTranDet->env_slow, (const float *) filt_coeff_arr[2], IVAS_FILTER_ORDER_1 ); #else - ivas_filters_init_fx( &hTranDet->env_hpf, (const Word32 *) filt_coeff_arr_fx[0], IVAS_FILTER_ORDER_1 ); - ivas_filters_init_fx( &hTranDet->env_fast, (const Word32 *) filt_coeff_arr_fx[1], IVAS_FILTER_ORDER_1 ); - ivas_filters_init_fx( &hTranDet->env_slow, (const Word32 *) filt_coeff_arr_fx[2], IVAS_FILTER_ORDER_1 ); + ivas_filters_init_fx( &hTranDet->env_hpf, (const Word32 *) filt_coeff_arr_fx[0], filt_coeff_arr_e, IVAS_FILTER_ORDER_1 ); + ivas_filters_init_fx( &hTranDet->env_fast, (const Word32 *) filt_coeff_arr_fx[1], filt_coeff_arr_e, IVAS_FILTER_ORDER_1 ); + ivas_filters_init_fx( &hTranDet->env_slow, (const Word32 *) filt_coeff_arr_fx[2], filt_coeff_arr_e, IVAS_FILTER_ORDER_1 ); #endif diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index e03108221b090e15b9904ac86c7860b1899c25d4..c90e50f849c723876ab64bfdad361d0a904c1122 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -9249,3 +9249,6 @@ void ivas_mdct_core_reconstruct_fx( const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ Word16 q_x, Word16 e_sig ); + +void ari_start_encoding_14bits_ivas_fx( + Tastat *s ); diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 1808c53844b969c79fed11080df6d0c4a0348b4d..52fc6e26c5664cc876eae827c3cf06ce65159c88 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -2853,7 +2853,7 @@ void stereo_dft_generate_res_pred_fx( dmx_nrg = L_add( dmx_nrg, Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[add( shl( i, 1 ), 1 )], pDFT_DMX[add( shl( i, 1 ), 1 )] ) ); } - hStereoDft->hb_nrg_fx[0] = dmx_nrg, L_shr( hStereoDft->NFFT, 1 ); + hStereoDft->hb_nrg_fx[0] = L_add( hStereoDft->hb_nrg_fx[0], div_l( dmx_nrg, shr( hStereoDft->NFFT, 2 ) ) ); move32(); *stop = bin0; move16(); diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 3d4eda605e42c66ec845bb9ec0e55bf527a00c4a..c7688e7df6da6e7a01e8d56a03ccf845179e77fa 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -396,7 +396,7 @@ ivas_error acelp_core_enc_fx( IF( !nelp_mode && !ppp_mode ) { config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, - st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, st_fx->coder_type, + st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, tc_subfr_fx, 0, &nb_bits, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } @@ -531,7 +531,7 @@ ivas_error acelp_core_enc_fx( tc_classif_enc_fx( Q_new, st_fx->L_frame, &tc_subfr_fx, &position, attack_flag, st_fx->pitch_fx[0], res_fx ); config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, - -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, st_fx->coder_type, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, + -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } @@ -599,7 +599,7 @@ ivas_error acelp_core_enc_fx( /* Configure ACELP bit allocation */ config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, - -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, st_fx->coder_type, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, + -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); /* redo LSF quantization */ diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index e71900fc295c6cf7cdaa7352fb630b6450788469..bda7304c8b3f6179d7f87163cb71950f273d7431 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -138,7 +138,7 @@ void acelp_core_switch_enc_fx( /*----------------------------------------------------------------* * Excitation encoding *----------------------------------------------------------------*/ - config_acelp1( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, + config_acelp1( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); encod_gen_voic_core_switch_fx( st_fx, st_fx->last_L_frame, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); @@ -160,11 +160,11 @@ void acelp_core_switch_enc_fx( #else FOR( i = 0; i < 20; i++ ) { - hBstr->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME + i].value = hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START + i].value; + hBstr->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME + i].value = hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].value; move16(); - hBstr->ind_list_fx[IND_CORE_SWITCHING_CELP_SUBFRAME + i].nb_bits = hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits; + hBstr->ind_list[IND_CORE_SWITCHING_CELP_SUBFRAME + i].nb_bits = hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits; move16(); - hBstr->ind_list_fx[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits = -1; + hBstr->ind_list[TAG_ACELP_SUBFR_LOOP_START + i].nb_bits = -1; move16(); } #endif diff --git a/lib_enc/ari_enc.c b/lib_enc/ari_enc.c index 2908310f8b3336ff601a1a745eae981624162d69..192479aa6f1f523178f6db9091535f3d9923f383 100644 --- a/lib_enc/ari_enc.c +++ b/lib_enc/ari_enc.c @@ -39,6 +39,7 @@ #include "options.h" #include "cnst.h" #include "prot.h" +#include "prot_fx2.h" #include "stat_com.h" #include "basop_util.h" #include "wmc_auto.h" @@ -81,7 +82,21 @@ void ari_start_encoding_14bits( return; } +#ifdef IVAS_FLOAT_FIXED +void ari_start_encoding_14bits_ivas_fx( + Tastat *s ) +{ + /* : addressing is made with walking pointer s */ + s->low = 0; + s->high = ari_q4new; + s->bits_to_follow = 0; + move32(); + move32(); + move32(); + return; +} +#endif /*--------------------------------------------------------------- * ari_done_encoding_14bits() diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index c037a4c34cd74db0dfdc5648d3921d79698b73a5..dc5ed20dfe2208845cd04197e8c7860a68e2cc3e 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -1319,8 +1319,8 @@ static void shb_CNG_encod_fx( push_indice_fx( hBstr, IND_SHB_CNG_GAIN, idx_ener_fx, 4 ); push_indice_fx( hBstr, IND_SID_BW, 1, 1 ); #ifndef IVAS_CODE - hBstr->nb_bits_tot_fx = sub( hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits ); - hBstr->ind_list_fx[IND_CNG_ENV1].nb_bits = -1; + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[IND_CNG_ENV1].nb_bits ); + hBstr->ind_list[IND_CNG_ENV1].nb_bits = -1; #else delete_indice( hBstr, IND_CNG_ENV1 ); #endif diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c index 93b4698fc45eab10263473af9848a73e42b6f1ed..b32c0f2ae8b4a2924674b8ebdf262ca172b0d21f 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -301,7 +301,7 @@ void enc_prm_fx( move16(); move16(); j = 0; - nbits_start = hBstr->nb_bits_tot_fx; + nbits_start = hBstr->nb_bits_tot; /*--------------------------------------------------------------------------------* @@ -514,7 +514,7 @@ void enc_prm_fx( st->glr_reset = 0; move16(); - nbits_header = sub( hBstr->nb_bits_tot_fx, nbits_start ); + nbits_header = sub( hBstr->nb_bits_tot, nbits_start ); /*--------------------------------------------------------------------------------* @@ -744,7 +744,7 @@ void enc_prm_fx( IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_NORM, 1 ); } } - total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); + total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); if ( EQ_16( st->rf_mode, 1 ) ) { total_nbbits = add( total_nbbits, st->rf_target_bits_write ); @@ -798,7 +798,7 @@ void enc_prm_fx( j = 0; move16(); - nbits_tcx = total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); + nbits_tcx = total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); test(); IF( st->enablePlcWaveadjust && k ) @@ -878,7 +878,7 @@ void enc_prm_fx( } j = add( j, NPRM_CTX_HM ); - total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); + total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); nbits_tcx = sub( shr( sub( add( sub( sub( sub( st->bits_frame_core, nbits_header ), nbits_lpc ), nbits_igf ), 1 ), k ), 1 ), sub( total_nbbits, nbits_tcx ) ); @@ -903,7 +903,7 @@ void enc_prm_fx( *--------------------------------------------------------------------------------*/ - total_nbbits = sub( hBstr->nb_bits_tot_fx, nbits_start ); + total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Check if total encoded bits does not exceed CBR target bits (->this must never happen) */ diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index 308f3ec4eedc354821a95790f03e29a1057e6d93..df76226531b1721abe6de633b41a5132fed6fc71 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -382,10 +382,10 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit FOR( i = TAG_ACELP_SUBFR_LOOP_START; i < TAG_ACELP_SUBFR_LOOP_END; i++ ) { #ifndef IVAS_CODE_BITSTREAM - IF( hBstr->ind_list_fx[i].nb_bits != -1 ) + IF( hBstr->ind_list[i].nb_bits != -1 ) { - hBstr->nb_bits_tot_fx = sub( hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[i].nb_bits ); - hBstr->ind_list_fx[i].nb_bits = -1; + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[i].nb_bits ); + hBstr->ind_list[i].nb_bits = -1; move16(); } #else @@ -394,10 +394,10 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit } #ifndef IVAS_CODE_BITSTREAM - IF( hBstr->ind_list_fx[IND_ES_PRED].nb_bits != -1 ) + IF( hBstr->ind_list[IND_ES_PRED].nb_bits != -1 ) { - hBstr->nb_bits_tot_fx = sub( hBstr->nb_bits_tot_fx, hBstr->ind_list_fx[IND_ES_PRED].nb_bits ); - hBstr->ind_list_fx[IND_ES_PRED].nb_bits = -1; + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[IND_ES_PRED].nb_bits ); + hBstr->ind_list[IND_ES_PRED].nb_bits = -1; move16(); } #else diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 53b52d3dc74b7021ad5530434875d8e0bb6fcf7a..7cc08c96b81c3eb51ae93b424b89ee6b5d486b7e 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -410,13 +410,13 @@ ivas_error evs_enc_fx( { /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) ) + get_tbe_bits(st->total_brate, st->bwidth, st->rf_mode )); */ tmp = add( get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_mode ), sub( st->rf_target_bits_write, st->rf_mode ) ); - padBits = sub( sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), hBstr->nb_bits_tot_fx ), tmp ); + padBits = sub( sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), hBstr->nb_bits_tot ), tmp ); } ELSE { /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) )); */ tmp = sub( st->rf_target_bits_write, st->rf_mode ); - padBits = sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), add( hBstr->nb_bits_tot_fx, tmp ) ); + padBits = sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), add( hBstr->nb_bits_tot, tmp ) ); } FOR( i = 0; i < padBits; i++ ) diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index a0396a97f31b3456cce21c521bf7b1f67653007b..615b09fd0450fb939026d76eebf80d0731312eb2 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -303,7 +303,7 @@ void encod_audio_fx( *--------------------------------------------------------------------------------------*/ /* Find the current total number of bits used */ - tmp_nb_bits_tot = hBstr->nb_bits_tot_fx; + tmp_nb_bits_tot = hBstr->nb_bits_tot; move16(); diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 700ac87264c8fafaa7a39f3f6d14c91a04baff6b..132df11bb27c4fcd750d0c7829d5afaaba678265 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -147,7 +147,7 @@ void hq_core_enc_fx( } #ifndef ADD_IVAS_HQ_CODE /* subtract signalling bits */ - num_bits = sub( num_bits, hBstr->nb_bits_tot_fx ); + num_bits = sub( num_bits, hBstr->nb_bits_tot ); #endif direct_transform_fx( wtda_audio, t_audio, is_transient, input_frame, &Q_audio, st_fx->element_mode ); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 02550d2bb17f111451d6e6fa0f7b58b54b140e1e..98d86d096d89ba02d1976af3ea30424251843ab2 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -331,6 +331,8 @@ ivas_error init_encoder( set16_fx( st->old_inp_12k8_fx, 0, L_INP_MEM ); set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM ); set16_fx( st->mem_decim_fx, 0, 2 * L_FILT_MAX ); + st->input_buff_fx = st->hSignalBuf->input_buff; + st->input_buff32_fx = st->hSignalBuf->input_buff32; #endif st->input_buff = st->hSignalBuf->input_buff_flt; set_zero( st->input_buff, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); @@ -342,10 +344,18 @@ ivas_error init_encoder( #endif if ( st->element_mode == EVS_MONO ) { +#ifdef IVAS_FLOAT_FIXED + st->input_fx = st->input_buff_fx + st->input_Fs / FRAMES_PER_SEC + NS2SA_fx2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); + st->input32_fx = st->input_buff32_fx + st->input_Fs / FRAMES_PER_SEC + NS2SA_fx2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); +#endif // IVAS_FLOAT_FIXED st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC + NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ); } else { +#ifdef IVAS_FLOAT_FIXED + st->input_fx = st->input_buff_fx + st->input_Fs / FRAMES_PER_SEC; + st->input32_fx = st->input_buff32_fx + st->input_Fs / FRAMES_PER_SEC; +#endif // IVAS_FLOAT_FIXED st->input = st->input_buff + st->input_Fs / FRAMES_PER_SEC; #ifdef IVAS_FLOAT_FIXED st->input_fx = st->input_buff_fx + st->input_Fs / FRAMES_PER_SEC; @@ -550,7 +560,11 @@ ivas_error init_encoder( if ( ( st->element_mode != IVAS_CPE_MDCT && idchan == 0 ) || ( st->element_mode == IVAS_CPE_MDCT && st->Opt_DTX_ON ) ) { +#ifdef IVAS_FLOAT_FIXED if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -653,8 +667,11 @@ ivas_error init_encoder( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - +#ifdef IVAS_FLOAT_FIXED if ( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 2607c50a5f276a00daed5fe99d1771a4a46fe128..d740915c18208488af5968b4fc41d21f5d62dc01 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -149,7 +149,7 @@ ivas_error init_encoder_fx( { st_fx->hBstr = NULL; } - st_fx->hBstr->nb_bits_tot_fx = 0; + st_fx->hBstr->nb_bits_tot = 0; move16(); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index cca282ff9828f97b2cd00ff493a1ff77aed8ceaf..cdcdadb8eb6c564aae446fb1fae213f91c6b0d30 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -991,7 +991,7 @@ ivas_error ivas_enc( } /* LFE low pass filter */ - ivas_lfe_lpf_enc_apply( st_ivas->hLfeLpf, data_f[LFE_CHANNEL], input_frame ); + ivas_lfe_lpf_enc_apply_fx( st_ivas->hLfeLpf, data_fx[LFE_CHANNEL], input_frame ); /* LFE channel encoder */ IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) @@ -1005,11 +1005,11 @@ ivas_error ivas_enc( st_ivas->hLFE->hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; } -#if 1 // To be removed - floatToFixed_arr32( data_f[LFE_CHANNEL], data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); -#endif ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); } +#if 1 // To be removed + 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 ) { @@ -1025,14 +1025,10 @@ ivas_error ivas_enc( st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; -#ifdef IVAS_FLOAT_FIXED - floatToFixed_arr32( data_f[LFE_CHANNEL], data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); - ivas_lfe_enc_fx( st_ivas->hLFE, data_fx[LFE_CHANNEL], st_ivas->q_data_fx, input_frame, st_ivas->hLFE->hBstr ); -#else - ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); -#endif // IVAS_FLOAT_FIXED - +#if 1 // To be removed + fixedToFloat_arrL( data_fx[LFE_CHANNEL], data_f[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); +#endif if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index 14ed149e12b1a901742b6478ae3b11898e2e3d45..dec1dfc265204bd823e25781dee0548513a3a351 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -246,15 +246,22 @@ static Word16 ivas_arith_encode_array( FOR( i = 0; i < in_len; i++ ) { ind = sub( pInput[i], pArith->vals[0] ); - +#ifdef IVAS_FLOAT_FIXED + ivas_ari_encode_14bits_ext_fx( hMetaData, &as, ind, (const UWord16 *) pCum_freq ); +#else ivas_ari_encode_14bits_ext( hMetaData, &as, ind, (const UWord16 *) pCum_freq ); +#endif IF( GT_16( hMetaData->nb_bits_tot, wc_strat_arith ) ) { return -1; } } +#ifdef IVAS_FLOAT_FIXED + ivas_ari_done_encoding_14bits_fx( hMetaData, &as ); +#else ivas_ari_done_encoding_14bits( hMetaData, &as ); +#endif IF( GT_16( hMetaData->nb_bits_tot, wc_strat_arith ) ) { return -1; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index dc7c49756add9ffa0b001ec3e0151b618b9c1cd2..5af37336dc9670a5b7484e8b7ecb95084ab6aee3 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -869,7 +869,11 @@ ivas_error ivas_init_encoder( st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); #endif +#ifndef IVAS_FLOAT_FIXED if ( ( error = ivas_create_lfe_lpf_enc( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1487,7 +1491,7 @@ ivas_error ivas_init_encoder_fx( st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); #endif - if ( ( error = ivas_create_lfe_lpf_enc( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_ism_dtx_enc.c b/lib_enc/ivas_ism_dtx_enc.c index db27d9085057f0a94cf45b6b8308291a6b627267..157b81378cbad736e2a2570c87dfe32851baec1b 100644 --- a/lib_enc/ivas_ism_dtx_enc.c +++ b/lib_enc/ivas_ism_dtx_enc.c @@ -37,11 +37,22 @@ #include "prot.h" #include "ivas_prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx2.h" +#include "prot_fx1.h" +#include "ivas_prot_fx.h" +#include "prot_fx_enc.h" +#define IVAS_FLOAT_FIXED_TO_BE_REMOVED +#endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +#define MD_MAX_DIFF_AZIMUTH_FX 41943040 +#define MD_MAX_DIFF_ELEVATION_FX 41943040 +#endif // IVAS_FLOAT_FIXED #define MD_MAX_DIFF_AZIMUTH 10 #define MD_MAX_DIFF_ELEVATION 10 @@ -93,6 +104,247 @@ ivas_error ivas_ism_dtx_open( *-------------------------------------------------------------------*/ /*! r: indication of DTX frame */ +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_ism_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word16 vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + Word16 md_diff_flag[], /* o : metadata differential flag */ + Word16 *sid_flag /* o : indication of SID frame */ +) +{ + Word16 ch, dtx_flag; + Word16 nBits, nBits_MD_max; + Word16 nBits_azimuth, nBits_elevation, nBits_coh, nBits_sce_id; + Word16 lp_noise_fx[MAX_NUM_OBJECTS], lp_noise_variation_fx, lp_noise_mean_fx; + Word16 lp_noise_max_fx; + Word32 tmp1_fx, tmp2_fx; + /* initialization */ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; + move16(); + } + + /*------------------------------------------------------------------* + * compute global ISM DTX flag + *-----------------------------------------------------------------*/ + + /* compute global ISM based on localVAD */ + dtx_flag = 1; + move16(); + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + dtx_flag = s_and( dtx_flag, !vad_flag[ch] ); + } + + /* compute global ISM based on long-term background noise */ + /* one of the channels is active -> no DTX */ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + lp_noise_fx[ch] = hSCE[ch]->hCoreCoder[0]->lp_noise_fx; /*Q8*/ + move16(); + } + + lp_noise_variation_fx = var_fx( lp_noise_fx, Q8, nchan_transport ); /*Q8*/ + lp_noise_mean_fx = mean_fx( lp_noise_fx, nchan_transport ); /*Q8*/ + + test(); + test(); + if ( GT_16( lp_noise_mean_fx, ( 50 << 8 ) ) || ( GT_16( lp_noise_mean_fx, ( 25 << 8 ) ) && GT_16( lp_noise_variation_fx, ( 32 << 8 ) ) ) ) + { + dtx_flag = 0; + move16(); + } + + + /* default DTX is applied at lower bitrates; otherwise DTX is applied only in silence */ + maximum_fx( lp_noise_fx, nchan_transport, &lp_noise_max_fx ); /*Q8*/ + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( !( ( EQ_16( nchan_ism, 1 ) && LE_32( ivas_total_brate, IVAS_24k4 ) ) || + ( EQ_16( nchan_ism, 2 ) && LE_32( ivas_total_brate, IVAS_48k ) ) || + ( EQ_16( nchan_ism, 3 ) && LE_32( ivas_total_brate, IVAS_80k ) ) || + ( EQ_16( nchan_ism, 4 ) && LE_32( ivas_total_brate, IVAS_96k ) ) || + LT_16( lp_noise_max_fx, ( 15 << 8 ) ) ) ) + { + dtx_flag = 0; + move16(); + } + + /*------------------------------------------------------------------* + * Reset the bitstream + *-----------------------------------------------------------------*/ + + IF( dtx_flag ) + { + /* reset the bitstream (IVAS format signaling was already written) */ + reset_indices_enc( hSCE[0]->hCoreCoder[0]->hBstr, hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot ); + } + + /*------------------------------------------------------------------* + * decide about SID metadata to be sent or not (per object) + * estimate the MD bit-budget consumption + *-----------------------------------------------------------------*/ + + IF( dtx_flag ) + { + ivas_get_ism_sid_quan_bitbudget_fx( nchan_ism, &nBits_azimuth, &nBits_elevation, &tmp1_fx, &tmp2_fx, &nBits_coh, &nBits_sce_id ); + + nBits = 0; + move16(); + FOR( ch = 0; ch < nchan_ism; ch++ ) + { + /* check difference between current and last metadata */ + md_diff_flag[ch] = 0; + move16(); + if ( GT_32( L_abs( L_sub( hIsmMeta[ch]->azimuth_fx, hIsmMeta[ch]->last_azimuth_fx ) ), MD_MAX_DIFF_AZIMUTH_FX ) ) + { + md_diff_flag[ch] = 1; + move16(); + } + + if ( GT_32( L_abs( L_sub( hIsmMeta[ch]->elevation_fx, hIsmMeta[ch]->last_elevation_fx ) ), MD_MAX_DIFF_ELEVATION_FX ) ) + { + md_diff_flag[ch] = 1; + move16(); + } + + /* estimate SID metadata bit-budget */ + nBits = add( nBits, 1 ); /* number of objects */ + nBits = add( nBits, 1 ); /* SID metadata flag */ + IF( EQ_16( md_diff_flag[ch], 1 ) ) + { + nBits = add( nBits, nBits_azimuth ); + nBits = add( nBits, nBits_elevation ); + } + } + + /* calculate maximum available MD bit-budget */ + nBits_MD_max = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; + move16(); + nBits_MD_max = sub( nBits_MD_max, SID_FORMAT_NBITS ); + + if ( GT_16( nchan_transport, 1 ) ) + { + nBits_MD_max = sub( nBits_MD_max, nBits_sce_id ); + } + + FOR( ch = 0; ch < nchan_transport - 1; ch++ ) + { + nBits_MD_max = sub( nBits_MD_max, nBits_coh ); /* coherence */ + } + + if ( GT_16( nchan_ism, 3 ) ) + { + nBits_MD_max = sub( nBits_MD_max, 1 ); /* ism_mode flag */ + } + + /* too many metadata bits -> switch to active coding */ + if ( GT_16( nBits, nBits_MD_max ) ) + { + dtx_flag = 0; + move16(); + } + } + + /*------------------------------------------------------------------* + * set core_brate for all channels + * get 'sid_flag' value + *-----------------------------------------------------------------*/ + + *sid_flag = 0; + move16(); + + IF( !dtx_flag ) + { + /* at least one of the channels is active -> no DTX */ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + hSCE[ch]->hCoreCoder[0]->core_brate = -1; + move32(); + set_bw_fx( IVAS_SCE, hSCE[ch]->element_brate, hSCE[ch]->hCoreCoder[0], MODE1 ); + } + + hISMDTX->cnt_SID_ISM = -1; + move16(); + + /* IVAS format signaling was erased in dtx() */ + IF( EQ_16( hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot, 0 ) ) + { + /* replicate ivas_write_format() */ + Word16 ind = 2; + nBits = IVAS_FORMAT_SIGNALING_NBITS; + move16(); + move16(); + IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) + { + ind = 4; + nBits = IVAS_FORMAT_SIGNALING_NBITS_EXTENDED; + move16(); + move16(); + } + + push_indice( hSCE[0]->hCoreCoder[0]->hBstr, IND_IVAS_FORMAT, ind, nBits ); + } + } + ELSE /* ism_dtx_flag == 1 */ + { + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + hSCE[ch]->hCoreCoder[0]->cng_type = FD_CNG; + move16(); + } + + /* * update the global SID counter */ + hISMDTX->cnt_SID_ISM = add( hISMDTX->cnt_SID_ISM, 1 ); + move16(); + IF( GE_16( hISMDTX->cnt_SID_ISM, hSCE[0]->hCoreCoder[0]->hDtxEnc->max_SID ) ) + { + /* adaptive SID update interval */ + hSCE[0]->hCoreCoder[0]->hDtxEnc->max_SID = hSCE[0]->hCoreCoder[0]->hDtxEnc->interval_SID; + hISMDTX->cnt_SID_ISM = 0; + move16(); + move16(); + } + + /* encode SID in one channel only */ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + hSCE[ch]->hCoreCoder[0]->core_brate = FRAME_NO_DATA; + move32(); + } + + IF( EQ_16( hISMDTX->cnt_SID_ISM, 0 ) ) + { + hSCE[hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate = SID_2k40; + *sid_flag = 1; + move32(); + move16(); + } + } + + test(); + IF( EQ_16( dtx_flag, 1 ) && EQ_16( *sid_flag, 0 ) ) + { + set16_fx( md_diff_flag, 0, nchan_transport ); + } + + return dtx_flag; +} +#endif // IVAS_FLOAT_FIXED + int16_t ivas_ism_dtx_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ @@ -301,6 +553,85 @@ int16_t ivas_ism_dtx_enc( * * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_ism_get_sce_id_dtx_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length per channel */ +) +{ + Word32 tmp_energy[MAX_NUM_OBJECTS]; + Word16 tmp_energy_e[MAX_NUM_OBJECTS]; + Word16 i, j; + Word16 long_term_energy_stereo_dmx_enc_e[MAX_NUM_OBJECTS]; + Word16 max_exp; + + set16_fx( long_term_energy_stereo_dmx_enc_e, hISMDTX->long_term_energy_stereo_dmx_enc_e, nchan_transport ); + IF( EQ_16( nchan_transport, 1 ) ) + { + hISMDTX->sce_id_dtx = 0; + move16(); + + return; + } + + /* Initialize*/ + set32_fx( tmp_energy, 0, MAX_NUM_OBJECTS ); + set16_fx( tmp_energy_e, 0, MAX_NUM_OBJECTS ); + + /* compute long term energy parameter */ + FOR( j = 0; j < nchan_transport; j++ ) + { + FOR( i = 0; i < ( PARAM_ISM_HYS_BUF_SIZE - 1 ); i++ ) + { + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i] = hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i + 1]; + move32(); + } + long_term_energy_stereo_dmx_enc_e[j] = 20; + move16(); + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1] = sum2_32_fx( hSCE[j]->hCoreCoder[0]->input32_fx, input_frame, &long_term_energy_stereo_dmx_enc_e[j] ); /*Resultant Q_lte=2*Q(input_fx)+1=2*-5+1=>-9*/ + move32(); + tmp_energy[j] = L_deposit_l( 0 ); + move32(); + FOR( i = 0; i < PARAM_ISM_HYS_BUF_SIZE - 1; i++ ) + { + tmp_energy[j] = BASOP_Util_Add_Mant32Exp( tmp_energy[j], tmp_energy_e[j], hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i], hISMDTX->long_term_energy_stereo_dmx_enc_e, &tmp_energy_e[j] ); /*Resultant Q(tmp_energy)=Q_lte*/ + move32(); + } + tmp_energy[j] = BASOP_Util_Add_Mant32Exp( tmp_energy[j], tmp_energy_e[j], hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1], long_term_energy_stereo_dmx_enc_e[j], &tmp_energy_e[j] ); /*Resultant Q(tmp_energy)=Q_lte*/ + move32(); + } + + maximum_fx( long_term_energy_stereo_dmx_enc_e, nchan_transport, &max_exp ); + max_exp = s_max( max_exp, hISMDTX->long_term_energy_stereo_dmx_enc_e ); + FOR( j = 0; j < nchan_transport; j++ ) + { + FOR( i = 0; i < PARAM_ISM_HYS_BUF_SIZE - 1; i++ ) + { + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i] = L_shr( hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][i], max_exp - hISMDTX->long_term_energy_stereo_dmx_enc_e ); + move32(); + } + hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1] = L_shr( hISMDTX->long_term_energy_stereo_dmx_enc_fx[j][PARAM_ISM_HYS_BUF_SIZE - 1], max_exp - long_term_energy_stereo_dmx_enc_e[j] ); + move32(); + } + hISMDTX->long_term_energy_stereo_dmx_enc_e = max_exp; + move16(); + /* determine the sce_id */ + hISMDTX->sce_id_dtx = 0; + move16(); + FOR( j = 1; j < nchan_transport; j++ ) + { + if ( BASOP_Util_Cmp_Mant32Exp( tmp_energy[j], tmp_energy_e[j], tmp_energy[hISMDTX->sce_id_dtx], tmp_energy_e[hISMDTX->sce_id_dtx] ) ) + { + hISMDTX->sce_id_dtx = j; + move16(); + } + } + + return; +} +#endif // IVAS_FLOAT_FIXED void ivas_ism_get_sce_id_dtx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ @@ -354,6 +685,93 @@ void ivas_ism_get_sce_id_dtx( * * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_ism_coh_estim_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length */ +) +{ + Encoder_State *st, *st_id0; + Word16 sce_id, i; + Word32 acorr_ene_fx[MAX_NUM_OBJECTS], xcorr_ene_fx; + Word16 acorr_ene_e[MAX_NUM_OBJECTS], xcorr_ene_e; + Word16 norm_inp; + Word16 tot_exp; + Word32 scaled_inp; + set16_fx( acorr_ene_e, 0, MAX_NUM_OBJECTS ); + + IF( EQ_16( nchan_transport, 1 ) ) + { + hISMDTX->coh_fx[0] = 0; + move16(); + return; + } + + /* Compute Coherence */ + acorr_ene_fx[hISMDTX->sce_id_dtx] = 0; + move32(); + st_id0 = hSCE[hISMDTX->sce_id_dtx]->hCoreCoder[0]; + + FOR( i = 0; i < input_frame; i++ ) + { + norm_inp = norm_l( st_id0->input32_fx[i] ); + scaled_inp = L_shl( st_id0->input32_fx[i], norm_inp ); + tot_exp = shl( sub( 20, norm_inp ), 1 ); + acorr_ene_fx[hISMDTX->sce_id_dtx] = BASOP_Util_Add_Mant32Exp( acorr_ene_fx[hISMDTX->sce_id_dtx], acorr_ene_e[hISMDTX->sce_id_dtx], Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &acorr_ene_e[hISMDTX->sce_id_dtx] ); + move32(); + } + + FOR( sce_id = 0; sce_id < nchan_transport; sce_id++ ) + { + IF( EQ_16( sce_id, hISMDTX->sce_id_dtx ) ) + { + hISMDTX->coh_fx[sce_id] = 32767; + move16(); + continue; + } + + st = hSCE[sce_id]->hCoreCoder[0]; + + acorr_ene_fx[sce_id] = 0; + xcorr_ene_fx = 0; + xcorr_ene_e = 0; + move32(); + move32(); + move16(); + + FOR( i = 0; i < input_frame; i++ ) + { + norm_inp = norm_l( st->input32_fx[i] ); + scaled_inp = L_shl( st->input32_fx[i], norm_inp ); + tot_exp = shl( sub( 20, norm_inp ), 1 ); + acorr_ene_fx[sce_id] = BASOP_Util_Add_Mant32Exp( acorr_ene_fx[sce_id], acorr_ene_e[sce_id], Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &acorr_ene_e[sce_id] ); + move32(); + xcorr_ene_fx = BASOP_Util_Add_Mant32Exp( xcorr_ene_fx, xcorr_ene_e, Mult_32_32( scaled_inp, scaled_inp ), tot_exp, &xcorr_ene_e ); + } + Word16 coh_e; + Word16 temp_e = acorr_ene_e[hISMDTX->sce_id_dtx] + acorr_ene_e[sce_id]; + Word32 temp = Sqrt32( L_add( Mult_32_32( acorr_ene_fx[hISMDTX->sce_id_dtx], acorr_ene_fx[sce_id] ), EPSILON_FX ), &temp_e ); /*fabsf( xcorr_ene ) / ( sqrtf( ( acorr_ene[hISMDTX->sce_id_dtx] * acorr_ene[sce_id] ) + EPSILON ) );*/ + hISMDTX->coh_fx[sce_id] = BASOP_Util_Divide3232_Scale( L_abs( xcorr_ene_fx ), temp, &coh_e ); + move16(); + coh_e = add( coh_e, sub( xcorr_ene_e, temp_e ) ); + IF( coh_e < 0 ) + { + hISMDTX->coh_fx[sce_id] = shl( hISMDTX->coh_fx[sce_id], coh_e ); + move16(); + coh_e = 0; + } + /* ensure value of coherence is between [0,1] */ + hISMDTX->coh_fx[sce_id] = check_bounds_s( hISMDTX->coh_fx[sce_id], 0, shl_sat( 1, 15 - coh_e ) ); + hISMDTX->coh_fx[sce_id] = shl_sat( hISMDTX->coh_fx[sce_id], coh_e ); + move16(); + move16(); + } + + return; +} +#endif // IVAS_FLOAT_FIXED void ivas_ism_coh_estim_dtx_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 96b1f24607ce1450b3b1cd4e395233ed7f331da7..7a819965b4d7a1df8bfec6e61cd6575645017240 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -39,6 +39,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx2.h" #endif @@ -200,6 +201,38 @@ ivas_error ivas_ism_enc( if ( st_ivas->hEncoderConfig->Opt_DTX_ON ) { /* compute the dominant sce_id using long term energy */ +#ifdef IVAS_FLOAT_FIXED +#if 1 /************************flt_to_fix****************************/ + for ( int j = 0; j < st_ivas->nchan_transport; j++ ) + { + floatToFixed_arrL( st_ivas->hSCE[j]->hCoreCoder[0]->input, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, Q11, input_frame ); /*Q0*/ + } + f2me_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); + for ( int ch = 0; ch < nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->last_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->last_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_elevation, Q22 ); + } + for ( int ch = 0; ch < st_ivas->nchan_transport; ch++ ) + { + st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); /*Q8*/ + } + floatToFixed_arr16( st_ivas->hISMDTX->coh, st_ivas->hISMDTX->coh_fx, Q15, st_ivas->nchan_transport ); +#endif /****************************ends here*********************************/ + ivas_ism_get_sce_id_dtx_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); + dtx_flag = ivas_ism_dtx_enc_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, vad_flag, st_ivas->hIsmMetaData, md_diff_flag, &sid_flag ); + IF( sid_flag ) + { + /* estimate coherence between objects */ + ivas_ism_coh_estim_dtx_enc_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); + } +#if 1 /************************fix_to_flt****************************/ + me2f_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); + fixedToFloat_arr( st_ivas->hISMDTX->coh_fx, st_ivas->hISMDTX->coh, Q15, st_ivas->nchan_transport ); +#endif /****************************ends here*********************************/ +#else ivas_ism_get_sce_id_dtx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); /* analysis and decision about DTX */ @@ -210,6 +243,7 @@ ivas_error ivas_ism_enc( /* estimate coherence between objects */ ivas_ism_coh_estim_dtx_enc( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); } +#endif // IVAS_FLOAT_FIXED } /*------------------------------------------------------------------* @@ -217,7 +251,7 @@ ivas_error ivas_ism_enc( * Metadata quantization and encoding *-----------------------------------------------------------------*/ - if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { ivas_param_ism_compute_noisy_speech_flag( st_ivas ); flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech; diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index 10efa2f167d92f76e028f28654293aab3a085d94..49507f07835a3347a6dc2fec5d83b58db5c82221 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -548,6 +548,65 @@ void ivas_param_ism_enc( * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_param_ism_compute_noisy_speech_flag( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 i; + + /* Move the Noisy speech buffer */ + FOR( i = 0; i < ( PARAM_ISM_HYS_BUF_SIZE - 1 ); i++ ) + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = st_ivas->hParamIsm->noisy_speech_buffer[i + 1]; + move16(); + } + + /* Set flag_noisy_speech to 0 for cases where object energies are not roughly equal */ + IF( !st_ivas->hParamIsm->flag_equal_energy ) + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 0; + st_ivas->hParamIsm->flag_noisy_speech = 0; + move16(); + move16(); + } + ELSE + { + /* For the current frame, make a decision based on some core-coder flags */ + test(); + IF( st_ivas->hSCE[0]->hCoreCoder[0]->flag_noisy_speech_snr && st_ivas->hSCE[1]->hCoreCoder[0]->flag_noisy_speech_snr ) + { + test(); + IF( st_ivas->hSCE[0]->hCoreCoder[0]->vad_flag || st_ivas->hSCE[1]->hCoreCoder[0]->vad_flag ) + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 0; + move16(); + } + ELSE + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 1; + move16(); + } + } + ELSE + { + st_ivas->hParamIsm->noisy_speech_buffer[i] = 0; + move16(); + } + + /* Do a decision based on hysteresis */ + st_ivas->hParamIsm->flag_noisy_speech = 1; + move16(); + FOR( i = 0; i < PARAM_ISM_HYS_BUF_SIZE; i++ ) + { + test(); + st_ivas->hParamIsm->flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech && st_ivas->hParamIsm->noisy_speech_buffer[i]; + } + } + + return; +} +#else void ivas_param_ism_compute_noisy_speech_flag( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -595,3 +654,4 @@ void ivas_param_ism_compute_noisy_speech_flag( return; } +#endif // IVAS_FLOAT_FIXED diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index 8d0f57495841a289cf8ae9015e10ae1fa718020d..6a011d23ce1281f6f4d50dfe1ffd99eae071ec5a 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -51,7 +51,7 @@ * * LFE Arithmetic coding block. Writes encoded data to bitstream. *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void ivas_lfe_arith_coding( LFE_ENC_HANDLE hLFE, BSTR_ENC_HANDLE hBstr, @@ -87,7 +87,48 @@ static void ivas_lfe_arith_coding( return; } +#else +static void ivas_lfe_arith_coding_fx( + LFE_ENC_HANDLE hLFE, + BSTR_ENC_HANDLE hBstr, + const Word16 quant_strategy, + Word16 *values ) +{ + Tastat as; + Word16 index, i; + Word16 max_value, offset; + UWord16 num_ele_per_grp; + Word16 num_groups; + index = 0; + num_ele_per_grp = IVAS_LFE_NUM_COEFFS_IN_SUBGRP << 1; + num_groups = shr( ivas_lfe_num_dct_pass_bins_tbl[quant_strategy], 1 ); + move16(); + move16(); + move16(); + + FOR( i = 0; i < num_groups; i++ ) + { + max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][i]; + move16(); + ari_start_encoding_14bits_ivas_fx( &as ); + offset = imult1616( 4, i ); + + FOR( index = 0; index < num_ele_per_grp; index++ ) + { + IF( values[index + offset] > max_value ) + { + values[add( index, offset )] = max_value; + move16(); + } + ivas_ari_encode_14bits_ext_fx( hBstr, &as, values[index + offset], hLFE->cum_freq_models[quant_strategy][i] ); + } + + ivas_ari_done_encoding_14bits_fx( hBstr, &as ); + } + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_lfe_enc_quant() @@ -537,7 +578,7 @@ static void ivas_lfe_enc_quant_fx( push_next_indice( hBstr, coding_strategy, 1 ); base2_num_bits_tot = sub( hBstr->nb_bits_tot, bits_written ); - ivas_lfe_arith_coding( hLFE, hBstr, quant_strategy, values ); + ivas_lfe_arith_coding_fx( hLFE, hBstr, quant_strategy, values ); FOR( i = 0; i < num_groups; i++ ) { @@ -1021,7 +1062,36 @@ void ivas_lfe_enc_close( * * Create, allocate and initialize IVAS encoder LFE low pass filter state handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_create_lfe_lpf_enc_fx( + ivas_filters_process_state_t **hLfeLpf, /* o : LFE LPF handle */ + const Word32 input_Fs /* i : input sampling rate */ +) +{ + const Word32 *filt_coeff; + const Word16 *filt_coeff_e = NULL; + IF( hLfeLpf == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Can not allocate memory for LFE LPF\n" ) ); + } + + /*-----------------------------------------------------------------* + * Allocate LFE LPF handle + *-----------------------------------------------------------------*/ + + IF( ( *hLfeLpf = (ivas_filters_process_state_t *) malloc( sizeof( ivas_filters_process_state_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE LPF\n" ) ); + } + + ivas_lfe_lpf_select_filt_coeff_fx( input_Fs, IVAS_FILTER_ORDER_4, &filt_coeff, &filt_coeff_e ); + + ivas_filters_init_fx( *hLfeLpf, filt_coeff, filt_coeff_e, IVAS_FILTER_ORDER_4 ); + + return IVAS_ERR_OK; +} +#else ivas_error ivas_create_lfe_lpf_enc( ivas_filters_process_state_t **hLfeLpf, /* o : LFE LPF handle */ const int32_t input_Fs /* i : input sampling rate */ @@ -1049,14 +1119,30 @@ ivas_error ivas_create_lfe_lpf_enc( return IVAS_ERR_OK; } - +#endif /*------------------------------------------------------------------------- * ivas_lfe_lpf_enc_close() * * Destroy IVAS cncoder LFE low pass filter state *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_lfe_lpf_enc_close( + ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */ +) +{ + test(); + IF( hLfeLpf == NULL || *hLfeLpf == NULL ) + { + return; + } + free( ( *hLfeLpf ) ); + ( *hLfeLpf ) = NULL; + + return; +} +#else void ivas_lfe_lpf_enc_close( ivas_filters_process_state_t **hLfeLpf /* i/o: LFE LPF handle */ ) @@ -1071,6 +1157,7 @@ void ivas_lfe_lpf_enc_close( return; } +#endif /*------------------------------------------------------------------------- @@ -1078,7 +1165,18 @@ void ivas_lfe_lpf_enc_close( * * Apply IVAS cncoder LFE low pass filter *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_lfe_lpf_enc_apply_fx( + ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle */ + Word32 data_lfe_ch[], /* i/o: LFE signal */ + const Word16 input_frame /* i : input frame length per channel */ +) +{ + ivas_filter_process_fx( hLfeLpf, data_lfe_ch, input_frame, (Word16) Q11 ); + return; +} +#else void ivas_lfe_lpf_enc_apply( ivas_filters_process_state_t *hLfeLpf, /* i/o: LFE LPF handle */ float data_lfe_ch[], /* i/o: LFE signal */ @@ -1089,3 +1187,4 @@ void ivas_lfe_lpf_enc_apply( return; } +#endif diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 27b8e492cac77b1edbe4be56458a7f430e13e33b..6ccf6af511bdcc4693b1ac919d84348d8c14741a 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -136,7 +136,11 @@ ivas_error ivas_masa_enc_open( for ( i = 0; i < hMasa->data.num_Cldfb_instances; i++ ) { +#ifdef IVAS_FLOAT_FIXED if ( ( error = openCldfb_ivas_enc( &( hMasa->data.cldfbAnaEnc[i] ), CLDFB_ANALYSIS, hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = openCldfb_ivas( &( hMasa->data.cldfbAnaEnc[i] ), CLDFB_ANALYSIS, hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 353be1fecb3272a3d7da1c54965184d43e132e69..9598804d9a1d4f60d460da16bc3eef60c9c18c58 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -90,7 +90,11 @@ ivas_error ivas_omasa_enc_open( hOMasa->num_Cldfb_instances = numAnalysisChannels; for ( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) { +#ifdef IVAS_FLOAT_FIXED if ( ( error = openCldfb_ivas_enc( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, st_ivas->hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = openCldfb_ivas( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, st_ivas->hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 396df4b64330f0d19196954c602af4f56158350e..c2b53d5f5fa912cafacb1d68cfa3eb3c443608b8 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -550,7 +550,7 @@ ivas_error create_evs_sce_enc( { return error; } - st_fx->hBstr->ind_list_fx = ind_list; + st_fx->hBstr->ind_list = ind_list; // st_fx->hBstr->ind_list_fx = st->hBstr->ind_list; reset_indices_enc_fx( st_fx->hBstr ); hSCE->hCoreCoder[0] = st_fx; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 37aebacef3f7052b9d872ce62fe23055f78d90a6..37e9288e1d5fe949484f987fe7c4dbbb03c84f84 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -212,8 +212,12 @@ typedef struct stereo_dft_enc_data_struct int16_t side_gain_index_ECprevious[STEREO_DFT_BAND_MAX]; int16_t side_gain_index_EC[STEREO_DFT_BAND_MAX]; int16_t side_gain_counter; - float side_gain_bitdiff_lp; +#ifdef IVAS_FLOAT_FIXED Word16 side_gain_bitdiff_lp_fx; + Word16 q_side_gain_bitdiff_lp; +#else + float side_gain_bitdiff_lp; +#endif /* Stereo CNG */ float sidSideGain[STEREO_DFT_ERB4_BANDS]; @@ -735,6 +739,11 @@ typedef struct ivas_stereo_classifier_data_structure typedef struct { +#ifdef IVAS_FLOAT_FIXED + Word32 long_term_energy_stereo_dmx_enc_fx[MAX_NUM_OBJECTS][PARAM_ISM_HYS_BUF_SIZE]; + Word16 long_term_energy_stereo_dmx_enc_e; + Word16 coh_fx[MAX_NUM_OBJECTS]; +#endif // IVAS_FLOAT_FIXED int16_t dtx_flag; int16_t sce_id_dtx; diff --git a/lib_enc/ivas_stereo_adapt_GR_enc.c b/lib_enc/ivas_stereo_adapt_GR_enc.c index 0b7aac44cfb75a6ca6753d6e4d73178bdd2cd2cc..f98b453a0e11bcf87a3800cbcac8fef655265d66 100644 --- a/lib_enc/ivas_stereo_adapt_GR_enc.c +++ b/lib_enc/ivas_stereo_adapt_GR_enc.c @@ -47,6 +47,48 @@ static int16_t adapt_GR_sg( const int16_t *in, const int16_t len, const int16_t no_symb, int16_t *nbits, int16_t *in_enc, const int16_t *map0, const int16_t no_GR_ord ); +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * calculate_diff() + * + * calculate difference wrt previous frame and maps it to positive integer + *---------------------------------------------------------------------*/ + +static void calculate_diff( + const Word16 *in, /* i : current frame values */ + const Word16 *prev, /* i : previous frmae values */ + Word16 *in_diff, /* o : difference values */ + const Word16 len /* i : vector length */ +) +{ + Word16 i, tmp; + + FOR( i = 0; i < len; i++ ) + { + tmp = sub( in[i], prev[i] ); + IF( tmp > 0 ) + { + in_diff[i] = sub( imult1616( 2, tmp ), 1 ); + move16(); + } + ELSE + { + IF( tmp < 0 ) + { + in_diff[i] = imult1616( -2, tmp ); + move16(); + } + ELSE + { + in_diff[i] = 0; + move16(); + } + } + } + + return; +} +#else /*---------------------------------------------------------------------* * calculate_diff() * @@ -84,8 +126,54 @@ static void calculate_diff( return; } +#endif + + +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * calculate_bit_diff() + * + * estimates the GR number of bits for encoding differential values + * selects between GR order 0 or 1 + *---------------------------------------------------------------------*/ + +/*! r: number of bits */ +static Word16 calculate_bit_diff( + Word16 *in_diff, /* i : values to be encoded */ + Word16 len, /* i : number of params */ + Word16 *flag_diff /* o : selected GR order */ +) +{ + Word16 i, nb, nb1; + + nb = 0; + move16(); + nb1 = 0; + move16(); + FOR( i = 0; i < len; i++ ) + { + nb = add( nb, in_diff[i] ); + nb1 = add( nb1, shr( in_diff[i], 1 ) ); + } + nb = add( nb, len ); + nb1 = add( nb1, imult1616( 2, len ) ); + IF( LT_16( nb1, nb ) ) + { + nb = add( nb1, 1 ); + *flag_diff = 1; /* GR order for differential coding */ + move16(); + } + ELSE + { + nb = add( nb, 1 ); + *flag_diff = 0; + move16(); + } + return nb; +} +#else /*---------------------------------------------------------------------* * calculate_bit_diff() * @@ -125,8 +213,76 @@ static int16_t calculate_bit_diff( return nb; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * adapt_GR_ief_fx() + * + * adaptive GR coding considering also the differential case + *---------------------------------------------------------------------*/ + +/*! r: used GR order */ +Word16 adapt_GR_ief_fx( + const Word16 *in, /* i : vector to encode */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *map0, /* i : mapping array */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + Word16 *nbits_diff, /* o : number bits in diff encoding */ + const Word16 side_gain_counter, /* i : number of frames since last abs coding */ + Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ + Word16 *q_side_gain_bitdiff_lp, /* i/o: Q of LP-filtered bit difference between abs/diff */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +) +{ + Word16 nb_diff, flag, flag_diff; + Word16 bitdiff; + Word32 L_tmp, L_tmp1; + Word16 exp_diff; + + flag = adapt_GR_sg( in, len, no_symb, nbits, in_enc, map0, no_GR_ord ); + + IF( try_diff ) /* inter-frame prediction allowed */ + { + calculate_diff( in, prev, in_diff, len ); + nb_diff = calculate_bit_diff( in_diff, len, &flag_diff ); + *nbits_diff = nb_diff; + move16(); + + bitdiff = sub( s_min( imult1616( 5, len ), *nbits ), add( nb_diff, 1 ) ); + L_tmp = Mpy_32_16_1( STEREO_DFT_BITDIFF_LP_FAC_Q31, bitdiff ); // (Q31, Q0) -> Q16 + L_tmp1 = Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_DFT_BITDIFF_LP_FAC_Q31 ), *side_gain_bitdiff_lp ); // (Q31, *q_side_gain_bitdiff_lp) -> *q_side_gain_bitdiff_lp + Q16 + *side_gain_bitdiff_lp = extract_h( BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q16, L_tmp1, sub( Q31, add( *q_side_gain_bitdiff_lp, Q16 ) ), &exp_diff ) ); + *q_side_gain_bitdiff_lp = sub( Q15, exp_diff ); + move16(); + + L_tmp = Mpy_32_16_1( STEREO_DFT_BITDIFF_ABS_SELECT_Q31, *side_gain_bitdiff_lp ); // (Q31, *q_side_gain_bitdiff_lp) -> *q_side_gain_bitdiff_lp + Q16 + L_tmp1 = Mpy_32_16_1( STEREO_DFT_FEC_THRESHOLD_PLUS_1_INV_Q31, side_gain_counter ); // (Q31, Q0) -> Q16 + L_tmp = Mpy_32_32( L_tmp, L_tmp1 ); // (*q_side_gain_bitdiff_lp + Q16, Q16) -> *q_side_gain_bitdiff_lp + Q1 + IF( GT_32( L_shl( L_deposit_l( bitdiff ), add( *q_side_gain_bitdiff_lp, Q1 ) ), L_tmp ) ) + { + flag = add( no_GR_ord, flag_diff ); + *nbits = add( nb_diff, 1 ); + move16(); + } + } + ELSE + { + *nbits_diff = 100; + move16(); + flag_diff = -1; + move16(); + } + + return flag; +} +#else /*---------------------------------------------------------------------* * adapt_GR_ief() * @@ -176,8 +332,90 @@ int16_t adapt_GR_ief( return flag; } +#endif + + +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * adapt_GR_rpg1_ief() + * + * use adaptive GR for RPG's considering also the differential case + *---------------------------------------------------------------------*/ + +/*! r: used GR order */ +Word16 adapt_GR_rpg1_ief( + const Word16 *in, /* i : res pred gains input vector */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *maps, /* i : mapping array */ + Word16 *nbits_diff, /* o : estimated no of bits for differential encoding */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +) +{ + const Word16 *map0; + Word16 s, i, GR_ord, flag_diff, nb_diff; + map0 = &maps[8 * NO_SYMB_GR_PRED_G]; + IF( in[0] == 0 ) + { + s = 0; + move16(); + FOR( i = 0; i < len; i++ ) + { + s = add( s, in[i] ); + } + + IF( s == 0 ) + { + /* encode only the first zero with GR1 */ + *nbits = add( shr( map0[0], 1 ), 2 ); + move16(); + in_enc[0] = map0[0]; + move16(); + } + ELSE + { + *nbits = 1000; /* large number such that the plain coding will be selected */ + move16(); + } + GR_ord = 1; + move16(); + } + ELSE + { + GR_ord = adapt_GR_sg( in, len, no_symb, nbits, in_enc, maps, no_GR_ord ); + } + + IF( try_diff ) + { + calculate_diff( in, prev, in_diff, len ); + nb_diff = calculate_bit_diff( in_diff, len, &flag_diff ); + *nbits_diff = nb_diff; + move16(); + + IF( LT_16( add( nb_diff, 1 ), *nbits ) ) /* there is one more bit to signal differential coding */ + { + GR_ord = add( no_GR_ord, flag_diff ); + + *nbits = add( nb_diff, 1 ); + move16(); + } + } + ELSE + { + *nbits_diff = 100; + move16(); + } + + return GR_ord; +} +#else /*---------------------------------------------------------------------* * adapt_GR_rpg1_ief() * @@ -249,8 +487,137 @@ int16_t adapt_GR_rpg1_ief( return GR_ord; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * adapt_GR_sg() + * + * adaptive GR coding + *---------------------------------------------------------------------*/ + +/*! r: GR order */ +static Word16 adapt_GR_sg( + const Word16 *in, /* i : data to be encoded */ + const Word16 len, /* i : number of params to be encoded */ + const Word16 no_symb, /* i : max number of symbols */ + Word16 *nbits, /* o : estimated number of bits */ + Word16 *in_enc, /* o : mapped symbols */ + const Word16 *map0, /* i : mapping */ + const Word16 no_GR_ord /* i : number of GR orders to be tested (2 or 3)*/ +) +{ + const Word16 *map; + Word16 nbits0, nbits1, nbits2, symb, map_symb, i, nb0, nb1, nb2; + + IF( EQ_16( no_symb, NO_SYMB_GR_SIDE_G ) ) + { + map = &map0[imult1616( 15, no_symb )]; + } + ELSE + { + map = &( map0[imult1616( 8, no_symb )] ); + } + + set_s( in_enc, 0, len ); + + nbits1 = 0; + move16(); + nbits0 = 0; + move16(); + nbits2 = 0; + move16(); + + FOR( i = 0; i < len; i++ ) + { + symb = in[i]; + move16(); + map_symb = map[symb]; + move16(); + + IF( i == 0 ) + { + /* GR order is 1 for first band*/ + nb0 = add( shr( map_symb, 1 ), 1 ); + nb2 = sub( nb0, 2 ); + } + ELSE + { + nb0 = map_symb; + move16(); + nb2 = shr( map_symb, 2 ); + } + nb1 = shr( map_symb, 1 ); + + in_enc[i] = map_symb; + move16(); + nbits0 = add( nbits0, nb0 ); + nbits1 = add( nbits1, nb1 ); + nbits2 = add( nbits2, nb2 ); + + /* update counts */ + map = &( map0[imult1616( symb, no_symb )] ); + } + + IF( EQ_16( no_GR_ord, 2 ) ) + { + nbits0 = add( nbits0, add( len, 1 ) ); + nbits1 = add( nbits1, add( imult1616( 2, len ), 1 ) ); + IF( LE_16( nbits0, nbits1 ) ) + { + *nbits = nbits0; + move16(); + return 0; + } + ELSE + { + *nbits = nbits1; + move16(); + return 1; + } + } + ELSE + { + IF( EQ_16( no_GR_ord, 3 ) ) + { + nbits0 = add( nbits0, add( len, 2 ) ); + nbits1 = add( nbits1, add( imult1616( 2, len ), 1 ) ); + nbits2 = add( nbits2, add( imult1616( 3, len ), 2 ) ); + + test(); + IF( LE_16( nbits1, nbits2 ) && LE_16( nbits1, nbits0 ) ) + { + *nbits = nbits1; + move16(); + return 1; + } + + test(); + IF( LE_16( nbits0, nbits2 ) && LE_16( nbits0, nbits1 ) ) + { + *nbits = nbits0; + move16(); + return 0; + } + + test(); + IF( LE_16( nbits2, nbits0 ) && LE_16( nbits2, nbits1 ) ) + { + *nbits = nbits2; + move16(); + return 2; + } + } + ELSE + { + IVAS_ERROR( IVAS_ERR_INTERNAL, "Wrong number of GR orders!" ); + } + } + + return -1; +} +#else /*---------------------------------------------------------------------* * adapt_GR_sg() * @@ -362,8 +729,50 @@ static int16_t adapt_GR_sg( return -1; } +#endif + + +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * write_GR0() + * + * write data with GR order 0 + *---------------------------------------------------------------------*/ + +/*! r: number of bits written */ +Word16 write_GR0( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +) +{ + Word16 nb, i, n, val; + nb = 0; + move16(); + + FOR( i = 0; i < len; i++ ) + { + n = add( in[i], 1 ); + IF( LT_16( n, 16 ) ) + { + val = sub( shl( 1, in[i] ), 1 ); + val = shl( val, 1 ); + push_indice( hBstr, ind, val, n ); + } + ELSE + { + push_indice( hBstr, ind, 16383, 14 ); + push_indice( hBstr, ind, sub( shl( 1, sub( n, 15 ) ), 1 ), sub( n, 15 ) ); + push_indice( hBstr, ind, 0, 1 ); + } + nb = add( nb, n ); + } + return nb; +} +#else /*---------------------------------------------------------------------* * write_GR0() * @@ -401,8 +810,53 @@ int16_t write_GR0( return nb; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * write_GR1() + * + * write data with GR order 1 + *---------------------------------------------------------------------*/ + +/*! r: number of bits written */ +Word16 write_GR1( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +) +{ + Word16 nb, i, n, val; + nb = 0; + move16(); + + FOR( i = 0; i < len; i++ ) + { + n = shr( in[i], 1 ); + IF( LT_16( n, 14 ) ) + { + val = sub( shl( 1, n ), 1 ); + val = add( shl( val, 2 ), s_and( in[i], 1 ) ); + push_indice( hBstr, ind, val, add( n, 2 ) ); + } + ELSE + { + push_indice( hBstr, ind, 16383, 14 ); + IF( GT_16( n, 14 ) ) + { + push_indice( hBstr, ind, sub( shl( 1, sub( n, 14 ) ), 1 ), sub( n, 14 ) ); /* 1 n times */ + } + push_indice( hBstr, ind, 0, 1 ); + push_indice( hBstr, ind, s_and( in[i], 1 ), 1 ); + } + nb = add( nb, add( n, 2 ) ); + } + + return nb; +} +#else /*---------------------------------------------------------------------* * write_GR1() * @@ -443,8 +897,56 @@ int16_t write_GR1( return nb; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * write_GR2() + * + * write data with GR order 2 + *---------------------------------------------------------------------*/ + +/*! r: number of bits written */ +static Word16 write_GR2( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +) +{ + Word16 nb, i, n; + nb = 0; + move16(); + + FOR( i = 0; i < len; i++ ) + { + n = shr( in[i], 2 ); + IF( LT_16( n, 14 ) ) + { + IF( n > 0 ) + { + push_indice( hBstr, ind, sub( shl( 1, n ), 1 ), n ); /* 1 n times */ + } + push_indice( hBstr, ind, 0, 1 ); + push_indice( hBstr, ind, s_and( in[i], 3 ), 2 ); + } + ELSE + { + push_indice( hBstr, ind, 16383, 14 ); + IF( GT_16( n, 14 ) ) + { + push_indice( hBstr, ind, sub( shl( 1, sub( n, 14 ) ), 1 ), sub( n, 14 ) ); /* 1 n times */ + } + push_indice( hBstr, ind, 0, 1 ); + push_indice( hBstr, ind, s_and( in[i], 3 ), 2 ); + } + nb = add( nb, add( n, 3 ) ); + } + + return nb; +} +#else /*---------------------------------------------------------------------* * write_GR2() * @@ -488,8 +990,44 @@ static int16_t write_GR2( return nb; } +#endif +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * write_bitstream_GR() + * + * generic GR encoder for GR order 0 or 1 + *---------------------------------------------------------------------*/ + +/*! r: number of bits written */ +Word16 write_bitstream_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : input vector */ + const Word16 len, /* i : input vector length */ + const Word16 GR_ord /* i : GR order */ +) +{ + Word16 nb; + nb = 0; + move16(); + + push_indice( hBstr, ind, GR_ord, 1 ); + nb = add( nb, 1 ); + + IF( GR_ord == 0 ) + { + nb = add( nb, write_GR0( hBstr, ind, in, len ) ); + } + ELSE + { + nb = add( nb, write_GR1( hBstr, ind, in, len ) ); + } + + return nb; +} +#else /*---------------------------------------------------------------------* * write_bitstream_GR() * @@ -521,8 +1059,72 @@ int16_t write_bitstream_GR( return nb; } +#endif + + +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * write_bitstream_adapt_GR() + * + * write encoded data using adaptive GR + *---------------------------------------------------------------------*/ + +/*! r: number of bits written */ +Word16 write_bitstream_adapt_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : values to be written in bitstream */ + const Word16 len, /* i : values vector length */ + const Word16 GR_ord, /* i : GR order to be used */ + const Word16 no_GR_ord /* i : speech/music 0/1 */ +) +{ + Word16 nb; + + nb = 0; + /* first component first */ + nb = add( nb, write_GR1( hBstr, ind, in, 1 ) ); + + /* write the GR order */ + IF( EQ_16( no_GR_ord, 2 ) ) + { + push_indice( hBstr, ind, GR_ord, 1 ); + nb = add( nb, 1 ); + } + ELSE + { + IF( EQ_16( GR_ord, 1 ) ) + { + push_indice( hBstr, ind, 0, 1 ); /* GR order = 1*/ + nb = add( nb, 1 ); + } + ELSE + { + push_indice( hBstr, ind, 1, 1 ); + push_indice( hBstr, ind, shr( GR_ord, 1 ), 1 ); /* '10' for GR ord = 0; '11' for GR ord 2 */ + nb = add( nb, 2 ); + } + } + IF( GR_ord == 0 ) + { + nb = add( nb, write_GR0( hBstr, ind, &in[1], sub( len, 1 ) ) ); + } + ELSE + { + IF( EQ_16( GR_ord, 1 ) ) + { + nb = add( nb, write_GR1( hBstr, ind, &in[1], sub( len, 1 ) ) ); + } + ELSE + { + nb = add( nb, write_GR2( hBstr, ind, &in[1], sub( len, 1 ) ) ); + } + } + return nb; +} +#else /*---------------------------------------------------------------------* * write_bitstream_adapt_GR() * @@ -585,3 +1187,4 @@ int16_t write_bitstream_adapt_GR( return nb; } +#endif diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 6959f9e5eff7f4f326982cc5bc7a77b06f8c5820..27552f50bd1b07c4184928f48eee545edccea11a 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -578,7 +578,12 @@ void stereo_dft_enc_reset( set_s( hStereoDft->side_gain_index_ECDiff, 0, STEREO_DFT_BAND_MAX ); set_s( hStereoDft->side_gain_index_ECprevious, 15, STEREO_DFT_BAND_MAX ); hStereoDft->side_gain_counter = 0; +#ifdef IVAS_FLOAT_FIXED + hStereoDft->side_gain_bitdiff_lp_fx = STEREO_DFT_BITDIFF_INIT_FX; + hStereoDft->q_side_gain_bitdiff_lp = Q10; +#else hStereoDft->side_gain_bitdiff_lp = STEREO_DFT_BITDIFF_INIT; +#endif set_zero( hStereoDft->gipd, STEREO_DFT_ENC_DFT_NB ); set_zero( hStereoDft->dot_prod_real_smooth, STEREO_DFT_BAND_MAX ); set_zero( hStereoDft->dot_prod_img_smooth, STEREO_DFT_BAND_MAX ); @@ -2966,9 +2971,15 @@ static void side_gain_mode_decision( try_diff = 0; } no_GR_ord = 3; +#ifdef IVAS_FLOAT_FIXED + hStereoDft->side_gain_flag_2 = adapt_GR_ief_fx( hStereoDft->side_gain_index_EC, hStereoDft->side_gain_index_ECDiff, hStereoDft->side_gain_index_ECprevious, + hStereoDft->nbands, NO_SYMB_GR_SIDE_G, &n_bits, encoded_ind_GR, dft_maps_sg, no_GR_ord, &nb_diff, + hStereoDft->side_gain_counter, &hStereoDft->side_gain_bitdiff_lp_fx, &hStereoDft->q_side_gain_bitdiff_lp, try_diff ); +#else hStereoDft->side_gain_flag_2 = adapt_GR_ief( hStereoDft->side_gain_index_EC, hStereoDft->side_gain_index_ECDiff, hStereoDft->side_gain_index_ECprevious, hStereoDft->nbands, NO_SYMB_GR_SIDE_G, &n_bits, encoded_ind_GR, dft_maps_sg, no_GR_ord, &nb_diff, hStereoDft->side_gain_counter, &hStereoDft->side_gain_bitdiff_lp, try_diff ); +#endif for ( i = 0; i < hStereoDft->nbands; i++ ) diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 1e97552e331a7e0f15ff65fdc8baae01744219ca..c7ead90bc90e969ff40c070f4d5746c51cd2743a 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -403,7 +403,11 @@ ivas_error stereo_memory_enc( /* allocate CLDFB for primary channel */ if ( st->cldfbAnaEnc == NULL ) { +#ifdef IVAS_FLOAT_FIXED if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -419,7 +423,11 @@ ivas_error stereo_memory_enc( if ( st->cldfbSynTd == NULL ) { +#ifdef IVAS_FLOAT_FIXED if ( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -553,7 +561,12 @@ ivas_error stereo_memory_enc( for ( i = 0; i < CPE_CHANNELS; i++ ) { st = hCPE->hCoreCoder[i]; +#ifdef IVAS_FLOAT_FIXED if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif + { return error; } diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 1c899987e9e31de1629bc5348217fbc0ca3183af..2dc3884cc5bf6bbfd977804318f8e6d7decaf91a 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -311,7 +311,11 @@ ivas_error stereo_set_tdm( /* allocate CLDFB ana for secondary channel */ if ( st->cldfbAnaEnc == NULL ) { +#ifdef IVAS_FLOAT_FIXED if ( ( error = openCldfb_ivas_enc( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = openCldfb_ivas( &st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -324,8 +328,11 @@ ivas_error stereo_set_tdm( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - +#ifdef IVAS_FLOAT_FIXED if ( ( error = openCldfb_ivas_enc( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = openCldfb_ivas( &st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 292956a0aab3b158469596d4014927b6c7f603e3..8d61700e4a80ce009da58045f4321c10c52fa26e 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1641,7 +1641,10 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( { if ( !( hIvasEnc->hCoreCoder == NULL && hEncoderConfig->ivas_format == MONO_FORMAT ) ) { - st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ind_list = st_ivas->ind_list; + 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; } @@ -2634,17 +2637,17 @@ static ivas_error sanitizeBitrateISM_fx( return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } - IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_16k4 ) && EQ_16( hEncoderConfig->nchan_inp, 2 ) ) + IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_16k4 ) && EQ_16( 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( GT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 3 ) ) + IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( 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( GT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 4 ) ) + IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( 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 ); } diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 451ac33eea46479d40769d110b6bb4fb1831f740..719b7f661e4dd1605cd973c12f5cd6d920c1e718 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -91,10 +91,10 @@ typedef struct bitstream_enc_data_structure Indice **ivas_ind_list_zero; /* beginning of the buffer of indices */ void *st_ivas; /* IVAS encoder structure */ - Word16 nb_bits_tot_fx; /* total number of bits already written */ - Indice *ind_list_fx; /* list of indices */ - Word16 next_ind_fx; /* pointer to the next empty slot in the list of indices */ - Word16 last_ind_fx; /* last written indice */ + // Word16 nb_bits_tot_fx; /* total number of bits already written */ + // Indice *ind_list_fx; /* list of indices */ + Word16 next_ind_fx; /* pointer to the next empty slot in the list of indices */ + Word16 last_ind_fx; /* last written indice */ } BSTR_ENC_DATA, *BSTR_ENC_HANDLE; @@ -117,6 +117,7 @@ typedef struct signal_buffers_enc_data_structure float buf_wspeech_enc_flt[L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320]; /* increased by 320 to avoid memory overlap in find_wsp() and also to accomodate for the wspeech_enc */ // Fixed Word16 input_buff[L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS )]; + Word32 input_buff32[L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS )]; Word32 Bin_E_old_fx[L_FFT / 2]; /* per bin energy of old 2nd frames */ Word16 mem_decim_fx[2 * L_FILT_MAX]; /* decimation filter memory */ @@ -1924,7 +1925,9 @@ typedef struct enc_core_structure float *old_input_signal; Word16 *input_buff_fx; + Word32 *input_buff32_fx; Word16 *input_fx; + Word32 *input32_fx; Word16 *old_input_signal_fx; Word16 Q_old_wtda; diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 5b461cd5690aa41307bc3e133c6816d618c2dc1b..bfcdd8fdf99e6f23cd9ea30e5db48e3f22a5e01f 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -1977,7 +1977,7 @@ void ProcessIGF_fx( bsBits = sub( hBstr->next_ind_fx, bsStart ); IF( !isTCX20 ) { - IGFEncConcatenateBitstream_fx( hInstance, bsBits, &hBstr->next_ind_fx, &hBstr->nb_bits_tot_fx, hBstr->ind_list_fx ); + IGFEncConcatenateBitstream_fx( hInstance, bsBits, &hBstr->next_ind_fx, &hBstr->nb_bits_tot, hBstr->ind_list ); } #else PMT( "New bit stream implementation to be checked" ) diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index bc81a23c6be616ff792b21f617cd1062cb233bee..4e6b1f512b6fed29429d35a3d6c07abf4ef259eb 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -210,7 +210,7 @@ void transition_enc_fx( { /* this is called only to compute unused bits */ config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, - L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, + L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } @@ -319,7 +319,7 @@ void transition_enc_fx( IF( LE_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) { config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, - st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot_fx, TRANSITION, *tc_subfr, 2, NULL, + st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, *tc_subfr, 2, NULL, unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } /*-----------------------------------------------------------------*