Commit cf544e9b authored by Tapani Pihlajakuja's avatar Tapani Pihlajakuja
Browse files

Merge remote-tracking branch 'origin/main' into 1859_fix_ivas_get_nchan_buffers_dec_duplication

parents bb1d6971 5f80c06d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -212,6 +212,7 @@
    <ClCompile Include="..\lib_com\ivas_mdct_imdct_fx.c" />
    <ClCompile Include="..\lib_com\ivas_mdft_imdft_fx.c" />
    <ClCompile Include="..\lib_com\ivas_omasa_com_fx.c" />
    <ClCompile Include="..\lib_com\ivas_osba_com_fx.c" />
    <ClCompile Include="..\lib_com\ivas_pca_tools_fx.c" />
    <ClCompile Include="..\lib_com\ivas_qmetadata_com_fx.c" />
    <ClCompile Include="..\lib_com\ivas_qspherical_com_fx.c" />
+1 −0
Original line number Diff line number Diff line
@@ -512,6 +512,7 @@
      <Filter>common_ivas_c</Filter>
    </ClCompile>
    <ClCompile Include="..\lib_com\ivas_rotation_com.c">
    <ClCompile Include="..\lib_com\ivas_osba_com_fx.c">
      <Filter>common_ivas_c</Filter>
    </ClCompile>
  </ItemGroup>
+13 −1
Original line number Diff line number Diff line
@@ -488,18 +488,30 @@ int main(
            goto cleanup;
        }

#ifdef CONF_DISTATT
        if ( ( error = RenderConfigReader_getDirectivity( renderConfigReader, arg.directivityPatternId, renderConfig.directivity_fx ) ) != IVAS_ERR_OK )
#else
        if ( ( error = RenderConfigReader_getDirectivity( renderConfigReader, arg.directivityPatternId, renderConfig.directivity ) ) != IVAS_ERR_OK )
#endif
        {
            fprintf( stderr, "Failed to get directivity patterns for one or more of IDs: %d %d %d %d\n\n", arg.directivityPatternId[0], arg.directivityPatternId[1], arg.directivityPatternId[2], arg.directivityPatternId[3] );
            goto cleanup;
        }
#ifndef CONF_DISTATT
        FOR( Word16 i = 0; i < 4; i++ )
        {
            renderConfig.directivity_fx[i * 3] = (Word16) ( renderConfig.directivity[i * 3] * ( 1u << 6 ) );
            renderConfig.directivity_fx[i * 3 + 1] = (Word16) ( renderConfig.directivity[i * 3 + 1] * ( 1u << 6 ) );
            renderConfig.directivity_fx[i * 3 + 2] = (Word16) ( renderConfig.directivity[i * 3 + 2] * ( ( 1u << 15 ) - 1 ) );
        }

#endif
#ifdef CONF_DISTATT
        if ( ( error = RenderConfigReader_getDistanceAttenuation( renderConfigReader, renderConfig.distAtt_fx ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "Failed to get Distance Attenuation \n\n" );
            goto cleanup;
        }
#endif
        if ( ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ||
               arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
        {
+20 −29
Original line number Diff line number Diff line
@@ -893,7 +893,11 @@ ivas_error check_ind_list_limits(
        }
        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 );
#ifdef DEBUGGING
            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", frame, 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 );
#else
            return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Buffer of indices corrupted! 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 );
#endif
        }
    }

@@ -2799,7 +2803,11 @@ ivas_error push_indice(
    /* check the limits of the list of indices */
    IF( NE_32( ( 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" );
#ifdef DEBUGGING
        return IVAS_ERROR( error, "Error occured in push_indice() while re-allocating the list of indices (frame %d) !\n", frame );
#else
        return IVAS_ERROR( error, "Error occured in push_indice() while re-allocating the list of indices!\n" );
#endif
    }

    /* find the location in the list of indices based on ID */
@@ -2957,7 +2965,11 @@ ivas_error push_next_bits(
        /* check the limits of the list of indices */
        IF( NE_32( ( error = check_ind_list_limits( hBstr ) ), IVAS_ERR_OK ) )
        {
            return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices (frame %d) !\n" );
#ifdef DEBUGGING
            return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices (frame %d) !\n", frame );
#else
            return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices!\n" );
#endif
        }
        ptr = &hBstr->ind_list[hBstr->nb_ind_tot];

@@ -2981,7 +2993,11 @@ ivas_error push_next_bits(
        /* check the limits of the list of indices */
        IF( NE_32( ( error = check_ind_list_limits( hBstr ) ), IVAS_ERR_OK ) )
        {
            return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices (frame %d) !\n" );
#ifdef DEBUGGING
            return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices (frame %d) !\n", frame );
#else
            return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices!\n" );
#endif
        }
        ptr = &hBstr->ind_list[hBstr->nb_ind_tot];

@@ -3127,31 +3143,6 @@ UWord16 get_next_indice(
    return value;
}

/*-------------------------------------------------------------------*
 * get_next_indice_1()
 *
 * Get the next 1-bit indice from the buffer
 *-------------------------------------------------------------------*/

/*! r: value of the indice */
UWord16 get_next_indice_1(
    Decoder_State *st /* i/o: decoder state structure   */
)
{
    Word32 nbits_total;
    nbits_total = st->total_brate / FRAMES_PER_SEC;
    /* detect corrupted bitstream */
    if ( ( st->next_bit_pos + 1 > nbits_total && st->codec_mode == MODE1 ) ||
         ( ( st->next_bit_pos + 1 > nbits_total + ( 2 * 8 ) ) && st->codec_mode == MODE2 ) /* add two zero bytes for arithmetic coder flush */
    )
    {
        st->BER_detect = 1;
        return ( 0 );
    }

    return st->bit_stream[st->next_bit_pos++];
}

/*-------------------------------------------------------------------*
 * get_next_indice_tmp()
 *
+0 −209
Original line number Diff line number Diff line
@@ -327,42 +327,6 @@ void get_next_indice_tmp_fx(
    move16();
}

/*-------------------------------------------------------------------*
 * get_indice_fx( )
 *
 * Get indice at specific position in the buffer
 *-------------------------------------------------------------------*/

UWord16 get_indice_fx(                       /* o  : value of the indice */
                       Decoder_State *st_fx, /* i/o: decoder state structure */
                       Word16 pos,           /* i  : absolute position in the bitstream (update after the read) */
                       Word16 nb_bits        /* i  : number of bits that were used to quantize the indice */
)
{
    UWord16 value;
    Word16 i;

    assert( nb_bits <= 16 );

    /* detect corrupted bitstream */
    IF( GT_16( add( pos, nb_bits ), st_fx->total_num_bits ) )
    {
        st_fx->BER_detect = 1;
        move16();
        return ( 0 );
    }

    value = 0;
    move16();
    FOR( i = 0; i < nb_bits; i++ )
    {
        value = lshl( value, 1 );
        value = add( value, st_fx->bit_stream[pos + i] );
    }

    return value;
}

/*-------------------------------------------------------------------*
 * get_indice_1_fx( )
 *
@@ -413,179 +377,6 @@ void reset_indices_enc_fx(
    return;
}

/*-------------------------------------------------------------------*
 * reset_indices_dec_fx()
 *
 * Reset the buffer of decoder indices
 *-------------------------------------------------------------------*/

void reset_indices_dec_fx(
    Decoder_State *st_fx )
{
    st_fx->next_bit_pos = 0;
    move16();

    return;
}


/*-------------------------------------------------------------------*
 * write_indices_fx()
 *
 * Write the buffer of indices to a file
 *-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*
 * write_indices_buf_fx()
 *
 * Write the buffer of indices to a file
 *-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*
 * indices_to_serial()
 *
 * pack indices into serialized payload format
 *-------------------------------------------------------------------*/

void indices_to_serial(
    const Encoder_State *st_fx, /* i: encoder state structure */
    BSTR_ENC_HANDLE hBstr,      /* i/o: encoder state structure */
    UWord8 *pFrame,             /* o: byte array with bit packet and byte aligned coded speech data */
    Word16 *pFrame_size         /* o: size of the binary encoded access unit [bits] */
)
{
    Word16 i, k, j;
    Word16 cmi = 0, core_mode = 0;
    Word32 mask;
    Word16 amrwb_bits[( ACELP_23k85 / 50 )];
    UWord8 omask = 0x80;
    UWord8 *pt_pFrame = pFrame;
    Word16 isAmrWb = 0;
    move16();
    move16();
    move16();
    move16();

    IF( st_fx->Opt_AMR_WB )
    {
        cmi = rate2EVSmode( st_fx->total_brate, &isAmrWb );
        core_mode = rate2EVSmode( L_mult0( hBstr->nb_bits_tot, 50 ), &isAmrWb );

        j = 0;
        move16();
        FOR( i = 0; i < MAX_NUM_INDICES; i++ )
        {
            IF( NE_16( hBstr->ind_list[i].nb_bits, -1 ) )
            {
                /* mask from MSB to LSB */
                mask = L_shl( 1, sub( hBstr->ind_list[i].nb_bits, 1 ) );

                /* temporarily save bit */
                FOR( k = 0; k < hBstr->ind_list[i].nb_bits; k++ )
                {
                    amrwb_bits[j++] = L_and( hBstr->ind_list[i].value, mask ) > 0;
                    move16();
                    mask = L_shr( mask, 1 );
                }
            }
        }
    }

    *pFrame_size = hBstr->nb_bits_tot;
    move16();

    /*----------------------------------------------------------------*
     * Bitstream packing (conversion of individual indices into a serial stream)
     *----------------------------------------------------------------*/
    j = 0;
    move16();
    FOR( i = 0; i < MAX_NUM_INDICES; i++ )
    {
        IF( NE_16( hBstr->ind_list[i].nb_bits, -1 ) )
        {
            /* mask from MSB to LSB */
            mask = L_shl( 1, sub( hBstr->ind_list[i].nb_bits, 1 ) );

            /* write bit by bit */
            FOR( k = 0; k < hBstr->ind_list[i].nb_bits; k++ )
            {
                IF( st_fx->Opt_AMR_WB )
                {
                    pack_bit( amrwb_bits[sort_ptr[core_mode][j++]], &pt_pFrame, &omask );
                }
                ELSE
                {
                    pack_bit( hBstr->ind_list[i].value & mask, &pt_pFrame, &omask );
                    j = add( j, 1 );
                }
                mask = L_shr( mask, 1 );
            }
        }
    }

    test();
    IF( st_fx->Opt_AMR_WB && EQ_16( core_mode, AMRWB_IO_SID ) ) /* SID UPD frame always written now  .... */
    {
        /* insert STI bit and CMI */
        pack_bit( 1, &pt_pFrame, &omask );
        FOR( mask = 0x08; mask > 0; mask >>= 1 )
        {
            pack_bit( cmi & mask, &pt_pFrame, &omask );
        }
    }
}


/*-------------------------------------------------------------------*
 * indices_to_serial_generic()
 *
 * pack indices into serialized payload format
 *-------------------------------------------------------------------*/

void indices_to_serial_generic(
    const Indice *ind_list,   /* i: indices list */
    const Word16 num_indices, /* i: number of indices to write */
    UWord8 *pFrame,           /* o: byte array with bit packet and byte aligned coded speech data */
    Word16 *pFrame_size       /* i/o: number of bits in the binary encoded access unit [bits] */
)
{
    Word16 i, k, j;
    Word32 mask;
    UWord8 omask;
    UWord8 *pt_pFrame = pFrame;
    Word16 nb_bits_tot;

    nb_bits_tot = 0;
    move16();
    omask = (UWord8) shr( 0x80, s_and( *pFrame_size, 0x7 ) );
    move16();
    pt_pFrame += shr( *pFrame_size, 3 );

    /*----------------------------------------------------------------*
     * Bitstream packing (conversion of individual indices into a serial stream)
     *----------------------------------------------------------------*/
    j = 0;
    move16();
    FOR( i = 0; i < num_indices; i++ ){
        IF( NE_16( ind_list[i].nb_bits, -1 ) ){
            /* mask from MSB to LSB */
            mask = L_shl( 1, sub( ind_list[i].nb_bits, 1 ) );

    /* write bit by bit */
    FOR( k = 0; k < ind_list[i].nb_bits; k++ )
    {
        pack_bit( ind_list[i].value & mask, &pt_pFrame, &omask );
        j = add( j, 1 );
        mask = L_shr( mask, 1 );
    }
    nb_bits_tot = add( nb_bits_tot, ind_list[i].nb_bits );
}
}

*pFrame_size = add( *pFrame_size, nb_bits_tot );
move16();

return;
}


static void dec_prm_core( Decoder_State *st )
{
Loading