LCOV - code coverage report
Current view: top level - lib_com - limit_t0.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 68 69 98.6 %
Date: 2025-05-23 08:37:30 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <stdint.h>
      38             : #include "options.h"
      39             : #ifdef DEBUGGING
      40             : #include "debug.h"
      41             : #endif
      42             : #include "cnst.h"
      43             : #include "prot.h"
      44             : #include "wmc_auto.h"
      45             : 
      46             : /*-------------------------------------------------*
      47             :  * Local constants
      48             :  *-------------------------------------------------*/
      49             : 
      50             : #define LIMIT_PIT_REL_LOWER 2 /* delta interval to extend pitch coding in relative Q */
      51             : #define LIMIT_PIT_REL_UPPER 0
      52             : 
      53             : /*-------------------------------------------------*
      54             :  * limit_T0()
      55             :  *
      56             :  * Close-loop pitch lag search limitation
      57             :  *-------------------------------------------------*/
      58             : 
      59     2639600 : void limit_T0(
      60             :     const int16_t L_frame,    /* i  : length of the frame                                  */
      61             :     const int16_t delta,      /* i  : Half the close-loop searched interval                */
      62             :     const int16_t pit_flag,   /* i  : selecting absolute(0) or delta(1) pitch quantization */
      63             :     const int16_t limit_flag, /* i  : flag for Q limits (0=restrained, 1=extended)         */
      64             :     const int16_t T0,         /* i  : rough pitch estimate around which the search is done */
      65             :     const int16_t T0_frac,    /* i  : pitch estimate fractional part                       */
      66             :     int16_t *T0_min,          /* o  : lower pitch limit                                    */
      67             :     int16_t *T0_max           /* o  : higher pitch limit                                   */
      68             : )
      69             : {
      70             :     int16_t delta2, T1;
      71             :     int16_t pit_min, pit_max;
      72             : 
      73     2639600 :     if ( limit_flag == 0 ) /* restrained Q limits */
      74             :     {
      75             :         /* set limits */
      76      331692 :         if ( L_frame == L_FRAME )
      77             :         {
      78      313891 :             pit_max = PIT_MAX;
      79      313891 :             pit_min = PIT_MIN;
      80             :         }
      81             :         else /* L_frame == L_FRAME16k */
      82             :         {
      83       17801 :             pit_max = PIT16k_MAX;
      84       17801 :             pit_min = PIT16k_MIN;
      85             :         }
      86             : 
      87      331692 :         delta2 = 2 * delta - 1;
      88             : 
      89      331692 :         T1 = T0;
      90      331692 :         if ( T0_frac >= 2 )
      91             :         {
      92      122945 :             T1++;
      93             :         }
      94      331692 :         *T0_min = T1 - delta;
      95             : 
      96      331692 :         if ( *T0_min < pit_min )
      97             :         {
      98       18612 :             *T0_min = pit_min;
      99             :         }
     100      331692 :         *T0_max = *T0_min + delta2;
     101             : 
     102      331692 :         if ( *T0_max > pit_max )
     103             :         {
     104        3492 :             *T0_max = pit_max;
     105        3492 :             *T0_min = *T0_max - delta2;
     106             :         }
     107             :     }
     108             :     else /* extended Q limits */
     109             :     {
     110             : 
     111             :         /* set limits */
     112     2307908 :         if ( L_frame == L_FRAME )
     113             :         {
     114      814784 :             pit_max = PIT_MAX;
     115      814784 :             pit_min = PIT_MIN_EXTEND;
     116             : 
     117      814784 :             if ( limit_flag == 2 )
     118             :             {
     119      146928 :                 pit_min = PIT_MIN_DOUBLEEXTEND;
     120             :             }
     121             :         }
     122             :         else /* L_frame == L_FRAME16k */
     123             :         {
     124     1493124 :             pit_max = PIT16k_MAX;
     125     1493124 :             pit_min = PIT16k_MIN_EXTEND;
     126             :         }
     127             : 
     128     2307908 :         delta2 = 2 * delta - 1;
     129             : 
     130     2307908 :         T1 = T0;
     131     2307908 :         if ( T0_frac >= 2 )
     132             :         {
     133     1039504 :             T1++;
     134             :         }
     135     2307908 :         *T0_min = T1 - delta;
     136             : 
     137     2307908 :         if ( pit_flag == 0 )
     138             :         {
     139             :             /* subframes with absolute search: keep Q range */
     140      228647 :             if ( *T0_min < pit_min )
     141             :             {
     142        9458 :                 *T0_min = pit_min;
     143             :             }
     144      228647 :             *T0_max = *T0_min + delta2;
     145             : 
     146      228647 :             if ( *T0_max > pit_max )
     147             :             {
     148        2844 :                 *T0_max = pit_max;
     149        2844 :                 *T0_min = *T0_max - delta2;
     150             :             }
     151             :         }
     152             :         else
     153             :         {
     154             :             /* subframes with relative search: extend Q range */
     155     2079261 :             if ( *T0_min < pit_min - LIMIT_PIT_REL_LOWER )
     156             :             {
     157       55618 :                 *T0_min = pit_min - LIMIT_PIT_REL_LOWER;
     158             :             }
     159             : 
     160     2079261 :             if ( *T0_min < L_INTERPOL )
     161             :             {
     162         900 :                 *T0_min = L_INTERPOL;
     163             :             }
     164     2079261 :             *T0_max = *T0_min + delta2;
     165             : 
     166     2079261 :             if ( *T0_max > pit_max + LIMIT_PIT_REL_UPPER )
     167             :             {
     168       17516 :                 *T0_max = pit_max + LIMIT_PIT_REL_UPPER;
     169       17516 :                 *T0_min = *T0_max - delta2;
     170             :             }
     171             :         }
     172             :     }
     173             : 
     174     2639600 :     return;
     175             : }
     176             : 
     177             : 
     178             : /*-------------------------------------------------*
     179             :  * Routine limit_T0_voiced()
     180             :  *
     181             :  * Close-loop pitch lag search limitation
     182             :  *-------------------------------------------------*/
     183             : 
     184        8320 : void limit_T0_voiced(
     185             :     const int16_t nbits,
     186             :     const int16_t res,
     187             :     const int16_t T0,      /* i  : rough pitch estimate around which the search is done */
     188             :     const int16_t T0_frac, /* i  : pitch estimate fractional part                       */
     189             :     const int16_t T0_res,  /* i  : pitch resolution                                     */
     190             :     int16_t *T0_min,       /* o  : lower pitch limit                                    */
     191             :     int16_t *T0_min_frac,  /* o  : lower pitch limit                                    */
     192             :     int16_t *T0_max,       /* o  : higher pitch limit                                   */
     193             :     int16_t *T0_max_frac,  /* o  : higher pitch limit                                   */
     194             :     const int16_t pit_min, /* i  : Minimum pitch lag                                    */
     195             :     const int16_t pit_max  /* i  : Maximum pitch lag                                    */
     196             : )
     197             : {
     198             :     int16_t T1, temp1, temp2;
     199             : 
     200             :     /* Mid-point */
     201        8320 :     T1 = T0;
     202        8320 :     if ( ( T0_res > 1 ) && ( T0_frac >= ( T0_res >> 1 ) ) )
     203             :     {
     204           0 :         T1++;
     205             :     }
     206             : 
     207             :     /* Lower-bound */
     208        8320 :     temp1 = ( T1 * res ) - ( 1 << ( nbits - 1 ) );
     209        8320 :     temp2 = temp1 / res;
     210        8320 :     *T0_min = temp2;
     211        8320 :     *T0_min_frac = temp1 - temp2 * res;
     212        8320 :     if ( *T0_min < pit_min )
     213             :     {
     214        1152 :         *T0_min = pit_min;
     215        1152 :         *T0_min_frac = 0;
     216             :     }
     217             : 
     218             :     /* Higher-bound */
     219        8320 :     temp1 = ( *T0_min * res ) + *T0_min_frac + ( 1 << nbits ) - 1;
     220        8320 :     temp2 = temp1 / res;
     221        8320 :     *T0_max = temp2;
     222        8320 :     *T0_max_frac = temp1 - temp2 * res;
     223        8320 :     if ( *T0_max > pit_max )
     224             :     {
     225          64 :         *T0_max = pit_max;
     226          64 :         *T0_max_frac = res - 1;
     227          64 :         temp1 = ( *T0_max * res ) + *T0_max_frac - ( 1 << nbits ) + 1;
     228          64 :         temp2 = temp1 / res;
     229          64 :         *T0_min = temp2;
     230          64 :         *T0_min_frac = temp1 - temp2 * res;
     231             :     }
     232             : 
     233        8320 :     return;
     234             : }

Generated by: LCOV version 1.14