Commit 45f78445 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'enc_float_code_cleanup_mld_improvements' into 'main'

Encoder and common float code clean up, high mld fixes

See merge request !867
parents 6d6ab129 a97b0030
Loading
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -160,7 +160,6 @@
    <ClCompile Include="..\lib_com\env_adj.c" />
    <ClCompile Include="..\lib_com\env_stab.c" />
    <ClCompile Include="..\lib_com\env_stab_trans.c" />
    <ClCompile Include="..\lib_com\est_tilt.c" />
    <ClCompile Include="..\lib_com\est_tilt_fx.c" />
    <ClCompile Include="..\lib_com\fd_cng_com_fx.c" />
    <ClCompile Include="..\lib_com\fft.c" />
@@ -172,19 +171,16 @@
    <ClCompile Include="..\lib_com\fft_rel_fx.c" />
    <ClCompile Include="..\lib_com\fill_spectrum.c" />
    <ClCompile Include="..\lib_com\findpulse.c" />
    <ClCompile Include="..\lib_com\fine_gain_bits.c" />
    <ClCompile Include="..\lib_com\fine_gain_bits_fx.c" />
    <ClCompile Include="..\lib_com\float_to_fix_ops.c" />
    <ClCompile Include="..\lib_com\frame_ener_fx.c" />
    <ClCompile Include="..\lib_com\gain_inov_fx.c" />
    <ClCompile Include="..\lib_com\get_gain_fx.c" />
    <ClCompile Include="..\lib_com\gs_bitallocation.c" />
    <ClCompile Include="..\lib_com\gs_bitallocation_fx.c" />
    <ClCompile Include="..\lib_com\gs_bitallocation_ivas_fx.c" />
    <ClCompile Include="..\lib_com\gs_gains.c" />
    <ClCompile Include="..\lib_com\gs_gains_fx.c" />
    <ClCompile Include="..\lib_com\gs_inact_switching_fx.c" />
    <ClCompile Include="..\lib_com\gs_noisefill.c" />
    <ClCompile Include="..\lib_com\gs_noisefill_fx.c" />
    <ClCompile Include="..\lib_com\gs_preech_fx.c" />
    <ClCompile Include="..\lib_com\guided_plc_util_fx.c" />
@@ -278,7 +274,6 @@
    <ClCompile Include="..\lib_com\rom_basic_math.c" />
    <ClCompile Include="..\lib_com\rom_basop_util.c" />
    <ClCompile Include="..\lib_com\rom_com.c" />
    <ClCompile Include="..\lib_com\ivas_sns_com.c" />
    <ClCompile Include="..\lib_com\rom_com_fx.c" />
    <ClCompile Include="..\lib_com\scale_mem_fx.c" />
    <ClCompile Include="..\lib_com\stab_est_fx.c" />
+0 −7
Original line number Diff line number Diff line
@@ -10,9 +10,6 @@
    <ClCompile Include="..\lib_com\ivas_sba_config.c">
      <Filter>common_ivas_c</Filter>
    </ClCompile>
    <ClCompile Include="..\lib_com\ivas_sns_com.c">
      <Filter>common_ivas_c</Filter>
    </ClCompile>
    <ClCompile Include="..\lib_com\ivas_mc_com.c">
      <Filter>common_ivas_c</Filter>
    </ClCompile>
@@ -386,15 +383,11 @@
    <ClCompile Include="..\lib_com\enr_1_az.c" />
    <ClCompile Include="..\lib_com\env_adj.c" />
    <ClCompile Include="..\lib_com\env_stab.c" />
    <ClCompile Include="..\lib_com\est_tilt.c" />
    <ClCompile Include="..\lib_com\fft.c" />
    <ClCompile Include="..\lib_com\fft_rel.c" />
    <ClCompile Include="..\lib_com\fill_spectrum.c" />
    <ClCompile Include="..\lib_com\findpulse.c" />
    <ClCompile Include="..\lib_com\fine_gain_bits.c" />
    <ClCompile Include="..\lib_com\gs_bitallocation.c" />
    <ClCompile Include="..\lib_com\gs_gains.c" />
    <ClCompile Include="..\lib_com\gs_noisefill.c" />
    <ClCompile Include="..\lib_com\hq2_core_com.c" />
    <ClCompile Include="..\lib_com\hq_conf.c" />
    <ClCompile Include="..\lib_com\ifft_rel.c" />

lib_com/est_tilt.c

deleted100644 → 0
+0 −90
Original line number Diff line number Diff line
/******************************************************************************************************

   (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository. All Rights Reserved.

   This software is protected by copyright law and by international treaties.
   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository retain full ownership rights in their respective contributions in
   the software. This notice grants no license of any kind, including but not limited to patent
   license, nor is any license granted by implication, estoppel or otherwise.

   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
   contributions.

   This software is provided "AS IS", without any express or implied warranties. The software is in the
   development stage. It is intended exclusively for experts who have experience with such software and
   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
   and fitness for a particular purpose are hereby disclaimed and excluded.

   Any dispute, controversy or claim arising under or in relation to providing this software shall be
   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
   the United Nations Convention on Contracts on the International Sales of Goods.

*******************************************************************************************************/

/*====================================================================================
    EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
  ====================================================================================*/

#include <stdint.h>
#include "options.h"
#include "cnst.h"
#include "prot.h"
#include "wmc_auto.h"

/*-------------------------------------------------------------------*
 * est_tilt()
 *
 * Estimate spectral tilt based on the relative E of adaptive
 * and innovative excitations
 *-------------------------------------------------------------------*/

/*! r: tilt of the code */
float est_tilt(
    const float *adpt_exc,  /* i  : adaptive excitation vector   */
    const float gain_pit,   /* i  : adaptive gain                */
    const float *fixe_exc,  /* i  : algebraic exctitation vector */
    const float gain_code,  /* i  : algebraic code gain          */
    float *voice_fac,       /* o  : voicing factor               */
    const int16_t L_subfr,  /* i  : subframe size                */
    const int16_t flag_tilt /* i  : flag for special tilt        */
)
{
    float ener, tmp, tilt_code;

    ener = dotp( adpt_exc, adpt_exc, L_subfr );
    ener *= gain_pit * gain_pit; /* energy of pitch excitation */

    tmp = dotp( fixe_exc, fixe_exc, L_subfr );
    tmp *= gain_code * gain_code; /* energy of innovative code excitation */

    /* find voice factor (1=voiced, -1=unvoiced) */
    *voice_fac = (float) ( ( ener - tmp ) / ( ener + tmp + 0.01f ) );

    /* find tilt of code for next subframe */
    if ( flag_tilt == 0 )
    {
        /*Between 0 (=unvoiced) and 0.5 (=voiced)*/
        tilt_code = (float) ( 0.25f * ( 1.0f + *voice_fac ) );
    }
    else if ( flag_tilt == 1 )
    {
        /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/
        tilt_code = (float) ( 0.25f + ( *voice_fac + 1.0f ) * 0.125f );
    }
    else
    {
        /*Between 0.28 (=unvoiced) and 0.56 (=voiced)*/
        tilt_code = (float) ( 0.28f + ( *voice_fac + 1.0f ) * 0.14f );
    }

    return tilt_code;
}

lib_com/fine_gain_bits.c

deleted100644 → 0
+0 −130
Original line number Diff line number Diff line
/******************************************************************************************************

   (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository. All Rights Reserved.

   This software is protected by copyright law and by international treaties.
   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository retain full ownership rights in their respective contributions in
   the software. This notice grants no license of any kind, including but not limited to patent
   license, nor is any license granted by implication, estoppel or otherwise.

   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
   contributions.

   This software is provided "AS IS", without any express or implied warranties. The software is in the
   development stage. It is intended exclusively for experts who have experience with such software and
   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
   and fitness for a particular purpose are hereby disclaimed and excluded.

   Any dispute, controversy or claim arising under or in relation to providing this software shall be
   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
   the United Nations Convention on Contracts on the International Sales of Goods.

*******************************************************************************************************/

/*====================================================================================
    EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
  ====================================================================================*/

#include <stdint.h>
#include "options.h"
#include "rom_com.h"
#include "prot.h"
#include <assert.h>
#include "wmc_auto.h"

#ifndef IVAS_FLOAT_FIXED
/*--------------------------------------------------------------------------
 * subband_gain_bits()
 *
 * HQ core encoder
 *--------------------------------------------------------------------------*/

static void subband_gain_bits(
    const int16_t *Rk,     /* i  : bit allocation per band (Q3)*/
    const int16_t N,       /* i  : number of bands         */
    int16_t *bits,         /* o  : gain bits per band      */
    const int16_t *sfmsize /* i  : Size of bands           */
)
{
    int16_t i, b, tot;
    int16_t bps;

    tot = 0;

    for ( i = 0; i < N; i++ )
    {
        bps = ( Rk[i] * fg_inv_tbl_fx[sfmsize[i] >> 3] ) >> 18;
        if ( ( ( sfmsize[i] * ( bps + 1 ) ) << 3 ) - Rk[i] == 0 )
        { /* correct approx. division result, to obtain exact integer division output */
            bps++;
        }
        bps = min( 7, bps );

        b = fine_gain_bits[bps];
        bits[i] = b;
        tot += b;
    }

    if ( tot == 0 )
    {
        /* If no gain bits were assigned, use one bit anyway for potential PVQ overage */
        bits[0] = 1;
    }

    return;
}

/*--------------------------------------------------------------------------*
 * assign_gain_bits()
 *
 * Assign gain adjustment bits and update bit budget
 *--------------------------------------------------------------------------*/

/*! r: Number of assigned gain bits */
int16_t assign_gain_bits(
    const int16_t core,        /* i  : HQ core                                 */
    const int16_t BANDS,       /* i  : Number of bands                         */
    const int16_t *band_width, /* i  : Sub band bandwidth                      */
    int16_t *Rk,               /* i/o: Bit allocation/Adjusted bit alloc. (Q3) */
    int16_t *gain_bits_array,  /* o  : Assigned gain bits                      */
    int16_t *Rcalc             /* o  : Bit budget for shape quantizer (Q3)     */
)
{
    int16_t gain_bits_tot;
    int16_t i;

    /* Allocate gain bits for every subband used, based on bitrate and bandwidth */
    if ( core == HQ_CORE )
    {
        subband_gain_bits( Rk, BANDS, gain_bits_array, band_width );
    }
    else
    {
        set_s( gain_bits_array, 0, BANDS );
    }

    /* Re-adjust bit budget for gain quantization */
    gain_bits_tot = 0;
    *Rcalc = 0;
    for ( i = 0; i < BANDS; i++ )
    {
        if ( Rk[i] > 0 )
        {
            Rk[i] -= gain_bits_array[i] * 8;
            gain_bits_tot += gain_bits_array[i];
            *Rcalc += Rk[i];
        }
    }

    return gain_bits_tot;
}
#endif
+0 −85
Original line number Diff line number Diff line
@@ -47,47 +47,6 @@
 * Estimation of pitch-synchronous (voiced sounds) or half-frame energy
 *----------------------------------------------------------------------------------*/

#ifndef IVAS_FLOAT_FIXED
void fer_energy(
    const int16_t L_frame, /* i  : frame length                           */
    const int16_t clas,    /* i  : frame classification                   */
    const float *synth,    /* i  : synthesized speech at Fs = 12k8 Hz     */
    const float pitch,     /* i  : pitch period                           */
    float *enr,            /* o  : pitch-synchronous or half_frame energy */
    const int16_t offset   /* i  : speech pointer offset (0 or L_frame)   */
)
{
    int16_t len;
    const float *pt_synth;

    if ( clas == VOICED_CLAS || clas == ONSET || clas == SIN_ONSET ) /* Voiced or Onset current frame */
    {
        len = (int16_t) ( pitch + 0.5f ); /* pitch value */

        pt_synth = synth;
        if ( offset != 0 )
        {
            pt_synth = synth + L_frame - len;
        }

        emaximum( pt_synth, len, enr ); /* pitch synchronous E */
    }
    else
    {
        pt_synth = synth;
        if ( offset != 0 )
        {
            pt_synth = synth + L_frame / 2;
        }

        *enr = dotp( pt_synth, pt_synth, L_frame / 2 );
        *enr /= (float) ( L_frame / 2 );
    }
    return;
}
#endif

#ifdef IVAS_FLOAT_FIXED
void fer_energy_fx(
    const Word16 L_frame, /* i  : frame length                                      */
    const Word16 clas,    /* i  : frame classification                              */
@@ -143,50 +102,6 @@ void fer_energy_fx(
    }
    return;
}
#endif // IVAS_FLOAT_FIXED

#ifndef IVAS_FLOAT_FIXED
/*------------------------------------------------------------------------*
 * frame_energy()
 *
 * Compute pitch-synchronous energy at the frame end
 *------------------------------------------------------------------------*/

float frame_energy(
    const int16_t L_frame, /* i  : length of the frame                            */
    const float *pitch,    /* i  : pitch values for each subframe                 */
    const float *speech,   /* i  : pointer to speech signal for E computation     */
    const float lp_speech, /* i  : long-term active speech energy average         */
    float *frame_ener      /* o  : pitch-synchronous energy at frame end          */
)
{
    float enern;
    const float *pt1;
    int16_t len;
    float dotProd;

    len = (int16_t) ( 0.5f * ( pitch[2] + pitch[3] ) + 0.5f );
    if ( len < L_SUBFR )
    {
        len *= 2;
    }

    pt1 = speech + L_frame - len;

    dotProd = dotp( pt1, pt1, len );
    if ( 0 == dotProd )
    {
        *frame_ener = MIN_LOG_VAL_60dB;
    }
    else
    {
        *frame_ener = 10.0f * (float) log10( dotProd / (float) len );
    }
    enern = *frame_ener - lp_speech;

    return enern;
}
#endif

/*----------------------------------------------------------------------------------*
 * frame_ener()
Loading