LCOV - code coverage report
Current view: top level - lib_com - swb_bwe_com_hr.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 95 98 96.9 %
Date: 2025-05-23 08:37:30 Functions: 3 3 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 <math.h>
      43             : #include "prot.h"
      44             : #include "wmc_auto.h"
      45             : 
      46             : /*-------------------------------------------------------------------*
      47             :  * swb_hr_nonzero_subband_noise_fill()
      48             :  *
      49             :  * SWB BWE HR noise filling of zero subbands
      50             :  *-------------------------------------------------------------------*/
      51             : 
      52        2583 : static void swb_hr_nonzero_subband_noise_fill(
      53             :     const float tilt_wb,        /* i  : tilt of wideband signal      */
      54             :     float *t_audio,             /* i/o: mdct spectrum                */
      55             :     int16_t *bwe_highrate_seed, /* i/o: seed of random noise         */
      56             :     const int16_t N,            /* i  : length of subband            */
      57             :     const int16_t Nsv           /* i  : number of subband            */
      58             : )
      59             : {
      60             :     int16_t i, j;
      61             :     float *ptr;
      62             :     float min_bwe, max_bwe, tmpF;
      63             : 
      64        2583 :     if ( tilt_wb > 5.0f )
      65             :     {
      66        6645 :         for ( i = 0; i < Nsv; i++ )
      67             :         {
      68        6366 :             min_bwe = FLT_MAX;
      69        6366 :             max_bwe = FLT_MIN;
      70       57294 :             for ( j = 0; j < N; j++ )
      71             :             {
      72       50928 :                 tmpF = (float) fabs( t_audio[i * N + j] );
      73             : 
      74       50928 :                 if ( tmpF > 0 )
      75             :                 {
      76       34686 :                     min_bwe = min( tmpF, min_bwe );
      77       34686 :                     max_bwe = max( tmpF, max_bwe );
      78             :                 }
      79             :             }
      80             : 
      81        6366 :             if ( max_bwe == min_bwe && min_bwe > 1.0f )
      82             :             {
      83        2673 :                 min_bwe *= 0.5f;
      84             :             }
      85             : 
      86        6366 :             ptr = &t_audio[i * N];
      87       57294 :             for ( j = 0; j < N; j++ )
      88             :             {
      89       50928 :                 if ( *ptr == 0 )
      90             :                 {
      91       16242 :                     if ( own_random( bwe_highrate_seed ) > 0 )
      92             :                     {
      93        8127 :                         *ptr = 0.5f * min_bwe;
      94             :                     }
      95             :                     else
      96             :                     {
      97        8115 :                         *ptr = -0.5f * min_bwe;
      98             :                     }
      99             :                 }
     100       50928 :                 ptr++;
     101             :             }
     102             :         }
     103             :     }
     104             : 
     105        2583 :     return;
     106             : }
     107             : 
     108             : /*-------------------------------------------------------------------*
     109             :  * swb_hr_noise_fill()
     110             :  *
     111             :  * SWB BWE HR noise filling
     112             :  *-------------------------------------------------------------------*/
     113             : 
     114        2583 : void swb_hr_noise_fill(
     115             :     const int16_t is_transient, /* i  : transient flag          */
     116             :     const int16_t spect_start,  /* i  : spectrum start point    */
     117             :     const int16_t spect_end,    /* i  : spectrum end point      */
     118             :     const float tilt_wb,        /* i  : tilt of wideband signal */
     119             :     const float pitch,          /* i  : pitch value             */
     120             :     const int16_t nq[],         /* i  : AVQ nq index            */
     121             :     int16_t Nsv,                /* i  : number of subband       */
     122             :     int16_t *bwe_highrate_seed, /* i/o: seed of random noise    */
     123             :     float *t_audio              /* i/o: mdct spectrum           */
     124             : )
     125             : {
     126             :     int16_t i, j, k;
     127             :     float alpha, beta;
     128             :     int16_t pos_start, pos_end, incr;
     129             : 
     130        2583 :     if ( is_transient )
     131             :     {
     132        6912 :         for ( i = 0; i < Nsv; i++ )
     133             :         {
     134        6144 :             if ( nq[i] == 0 )
     135             :             {
     136       15336 :                 for ( j = 0; j < WIDTH_BAND; j++ )
     137             :                 {
     138       13632 :                     t_audio[i * WIDTH_BAND + j] = own_random( bwe_highrate_seed ) / 65536.0f;
     139             :                 }
     140             :             }
     141             :         }
     142             :     }
     143             :     else
     144             :     {
     145        1815 :         Nsv = ( spect_end - spect_start ) / WIDTH_BAND;
     146        1815 :         alpha = 0.25f;
     147        1815 :         if ( tilt_wb > 5.0f )
     148             :         {
     149         159 :             beta = 0.25f;
     150             :         }
     151             :         else
     152             :         {
     153        1656 :             if ( 100 > 0.25f * pitch )
     154             :             {
     155         747 :                 beta = 0.25f;
     156             :             }
     157             :             else
     158             :             {
     159         909 :                 beta = 100 / pitch;
     160             :             }
     161             :         }
     162             : 
     163        1815 :         i = 0;
     164        1815 :         if ( nq[i] == 0 )
     165             :         {
     166          12 :             i = 1;
     167          24 :             while ( i < Nsv && nq[i] == 0 )
     168             :             {
     169          12 :                 i++;
     170             :             }
     171             : 
     172          12 :             pos_start = i;
     173             : 
     174             : 
     175         147 :             while ( i < Nsv && nq[i] != 0 )
     176             :             {
     177         135 :                 i++;
     178             :             }
     179             : 
     180          12 :             pos_end = i - 1;
     181             : 
     182          12 :             if ( pos_end - pos_start > pos_start )
     183             :             {
     184           9 :                 pos_end = 2 * pos_start - 1;
     185             :             }
     186             : 
     187          12 :             incr = pos_end;
     188             : 
     189          36 :             for ( j = pos_start - 1; j >= 0; j-- )
     190             :             {
     191         216 :                 for ( k = 0; k < WIDTH_BAND; k++ )
     192             :                 {
     193         192 :                     t_audio[j * WIDTH_BAND + k] = alpha * t_audio[incr * WIDTH_BAND + k] + beta * own_random( bwe_highrate_seed ) / PCM16_TO_FLT_FAC;
     194             :                 }
     195             : 
     196          24 :                 incr = ( incr < pos_start ) ? pos_end : incr - 1;
     197             :             }
     198             :         }
     199             : 
     200       62460 :         while ( i < Nsv )
     201             :         {
     202       60645 :             if ( nq[i] == 0 )
     203             :             {
     204        2625 :                 pos_start = i;
     205        2625 :                 pos_end = i;
     206             : 
     207        6156 :                 for ( j = pos_start; j < Nsv; j++ )
     208             :                 {
     209        5778 :                     if ( nq[j] != 0 )
     210             :                     {
     211        2247 :                         i = j;
     212        2247 :                         pos_end = j;
     213        2247 :                         break;
     214             :                     }
     215             :                 }
     216             : 
     217        2625 :                 if ( pos_start == pos_end )
     218             :                 {
     219         378 :                     i = Nsv;
     220         378 :                     pos_end = Nsv;
     221             :                 }
     222             : 
     223        2625 :                 incr = ( pos_start - 1 );
     224             : 
     225        6156 :                 for ( j = pos_end - 1; j >= pos_start; j-- )
     226             :                 {
     227       31779 :                     for ( k = 0; k < WIDTH_BAND; k++ )
     228             :                     {
     229       28248 :                         t_audio[j * WIDTH_BAND + k] = alpha * t_audio[incr * WIDTH_BAND + k] + beta * own_random( bwe_highrate_seed ) / PCM16_TO_FLT_FAC;
     230             :                     }
     231        3531 :                     incr = ( incr == 0 ) ? ( pos_start - 1 ) : incr - 1;
     232             :                 }
     233             :             }
     234             :             else
     235             :             {
     236       58020 :                 i++;
     237             :             }
     238             :         }
     239             :     }
     240             : 
     241        2583 :     swb_hr_nonzero_subband_noise_fill( tilt_wb, t_audio, bwe_highrate_seed, WIDTH_BAND, Nsv );
     242             : 
     243        2583 :     return;
     244             : }
     245             : 
     246             : 
     247             : /*-------------------------------------------------------------------*
     248             :  * td_postprocess()
     249             :  *
     250             :  * post processing in time domain for td/fd switching
     251             :  *-------------------------------------------------------------------*/
     252             : 
     253             : /*! r: gain */
     254          30 : float td_postprocess(
     255             :     float hb_synth[],          /* i/o: high-band synthesis         */
     256             :     const int16_t input_frame, /* i  : frame length                */
     257             :     const int16_t last_extl    /* i  : last extension layer        */
     258             : )
     259             : {
     260             :     int16_t i;
     261             :     int16_t pos, ind1, ind2;
     262             :     float max_samp, gain, tmpF;
     263             :     float alpha, beta, step;
     264             : 
     265          30 :     max_samp = (float) fabs( hb_synth[0] );
     266          30 :     pos = 0;
     267       28800 :     for ( i = 1; i < input_frame; i++ )
     268             :     {
     269       28770 :         if ( fabs( hb_synth[i] ) > max_samp )
     270             :         {
     271         948 :             max_samp = (float) fabs( hb_synth[i] );
     272         948 :             pos = i;
     273             :         }
     274             :     }
     275             : 
     276          30 :     if ( pos < 160 )
     277             :     {
     278           0 :         gain = sum2_f( hb_synth + input_frame - 80, 80 ) + EPSILON;
     279             :     }
     280             :     else
     281             :     {
     282          30 :         gain = sum2_f( hb_synth, 80 ) + EPSILON;
     283             :     }
     284             : 
     285          30 :     gain = (float) sqrt( gain / 80 );
     286             : 
     287          30 :     ind1 = max( 0, pos - 40 );
     288          30 :     ind2 = min( input_frame, pos + 40 );
     289          30 :     tmpF = sum2_f( hb_synth + ind1, ind2 - ind1 ) + EPSILON;
     290          30 :     tmpF = (float) sqrt( tmpF / ( ind2 - ind1 ) );
     291             : 
     292          30 :     gain = min( 1.0f, gain / tmpF );
     293             : 
     294          30 :     if ( last_extl == SWB_BWE || last_extl == FB_BWE )
     295             :     {
     296           0 :         for ( i = ind1; i < input_frame; i++ )
     297             :         {
     298           0 :             hb_synth[i] *= gain;
     299             :         }
     300             :     }
     301             :     else
     302             :     {
     303        2430 :         for ( i = ind1; i < ind2; i++ )
     304             :         {
     305        2400 :             hb_synth[i] *= gain;
     306             :         }
     307             : 
     308          30 :         if ( ind2 != input_frame )
     309             :         {
     310          30 :             step = 0.0f;
     311          30 :             alpha = ( gain > 0.5f ) ? 1.0f : 0.5f;
     312          30 :             beta = ( alpha - gain ) / ( input_frame - ind2 );
     313             : 
     314        9138 :             for ( i = ind2; i < input_frame; i++ )
     315             :             {
     316        9108 :                 hb_synth[i] *= ( gain + step );
     317        9108 :                 step += beta;
     318             :             }
     319             :         }
     320             :     }
     321             : 
     322          30 :     return ( gain );
     323             : }

Generated by: LCOV version 1.14