LCOV - code coverage report
Current view: top level - lib_lc3plus - plc_damping_scrambling.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 867217ee32c8e8cd2cf5aae69e60c58e00160b49 Lines: 86 113 76.1 %
Date: 2025-12-13 06:47:12 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             : *                        ETSI TS 103 634 V1.6.1                               *
       3             : *              Low Complexity Communication Codec Plus (LC3plus)              *
       4             : *                                                                             *
       5             : * Copyright licence is solely granted through ETSI Intellectual Property      *
       6             : * Rights Policy, 3rd April 2019. No patent licence is granted by implication, *
       7             : * estoppel or otherwise.                                                      *
       8             : ******************************************************************************/
       9             : 
      10             : #include "options.h"
      11             : #include "wmc_auto.h"
      12             : #include "functions.h"
      13             : 
      14     1186529 : void processPlcDampingScramblingMain_fl(LC3_INT32 *ns_seed,
      15             :                                         LC3_INT32 *pc_seed, LC3_INT32 ns_nbLostCmpt_pc,
      16             :                                         LC3_INT32 ns_nbLostCmpt, LC3_FLOAT *stabFac, LC3_FLOAT *cum_fading_slow, LC3_FLOAT *cum_fading_fast,
      17             :                                         LC3_FLOAT *spec_prev, LC3_FLOAT *spec, LC3_INT32 spec_inv_idx, LC3_INT32 yLen, LC3_INT32 bfi,
      18             :                                         LC3PLUS_FrameDuration frame_dms, LC3_INT32 concealMethod, LC3_INT32 pitch_present_bfi1, LC3_INT32 pitch_present_bfi2,
      19             :                                         LC3_FLOAT *cum_fflcAtten
      20             :                                         , LC3_UINT8 plc_fadeout_type
      21             :                                         )
      22             : {
      23             : 
      24             :         LC3_INT32 processDampScramb;
      25             : 
      26     1186529 :     processDampScramb = 0;
      27             :     
      28             : 
      29     1186529 :     if ( bfi != 0 )
      30             :     {
      31        8287 :         if (concealMethod == 4 || bfi == 2)
      32             :         {
      33        1375 :             processDampScramb = 1;
      34             :         }
      35             :         
      36        8287 :         if (ns_nbLostCmpt == 1)
      37             :         {
      38        1245 :             *cum_fading_slow = 1;
      39        1245 :             *cum_fading_fast = 1;
      40        1245 :             *cum_fflcAtten   = 1;
      41             :         }     
      42             :         
      43        8287 :         if ( bfi == 1 )
      44             :         {
      45        8287 :             processPlcDampingScrambling_fl(spec, yLen, ns_nbLostCmpt, stabFac, processDampScramb, cum_fflcAtten,
      46             :                                            pitch_present_bfi1, frame_dms, cum_fading_slow, cum_fading_fast, ns_seed, 0
      47             :                                            , plc_fadeout_type
      48             :                                           );
      49             :         }
      50             :         else /* bfi == 2 */
      51             :         {
      52           0 :             processPlcDampingScrambling_fl(spec, yLen, ns_nbLostCmpt_pc, stabFac, processDampScramb, cum_fflcAtten,
      53             :                                            pitch_present_bfi2, frame_dms, cum_fading_slow, cum_fading_fast, pc_seed, spec_inv_idx
      54             :                                            , plc_fadeout_type
      55             :                                           );
      56           0 :             processPlcUpdateSpec_fl(spec_prev, spec, yLen);
      57             :         }
      58             :     }
      59     1186529 : }
      60             : 
      61        8287 : void processPlcDampingScrambling_fl(LC3_FLOAT *spec, LC3_INT32 yLen, LC3_INT32 nbLostCmpt, LC3_FLOAT *stabFac, LC3_INT32 processDampScramb,
      62             :                             LC3_FLOAT *cum_fflcAtten, LC3_INT32 pitch_present, LC3PLUS_FrameDuration frame_dms, LC3_FLOAT *cum_fading_slow,
      63             :                             LC3_FLOAT *cum_fading_fast, LC3_INT32 *seed, LC3_INT32 spec_inv_idx
      64             :                             , LC3_UINT8 plc_fadeout_type
      65             :                             )
      66             : {
      67             :     LC3_INT32 plc_start_inFrames, plc_end_inFrames, plc_duration_inFrames, x, b, i, ad_ThreshFac_start;
      68             :     LC3_FLOAT slow, fast, linFuncStartStop, randThreshold, ad_ThreshFac_end, ad_threshFac, frame_energy, mean_energy, energThreshold, fac, m, n, fflcAtten, cum_fading_slow_local, cum_fading_fast_local;
      69             :     
      70        8287 :     frame_energy = 0;
      71             : 
      72        8287 :     slow = 0.8 + 0.2 * (*stabFac);
      73        8287 :     fast = 0.3 + 0.2 * (*stabFac);
      74             : 
      75        8287 :     switch (frame_dms)
      76             :     {
      77             : #ifdef CR9_C_ADD_1p25MS
      78           0 :       case LC3PLUS_FRAME_DURATION_1p25MS:
      79           0 :           slow = LC3_SQRT(LC3_SQRT(LC3_SQRT(slow)));
      80           0 :           fast = LC3_SQRT(LC3_SQRT(LC3_SQRT(fast)));
      81           0 :           break;
      82             : #endif
      83          32 :       case LC3PLUS_FRAME_DURATION_2p5MS:
      84          32 :           slow = LC3_SQRT(LC3_SQRT(slow));
      85          32 :           fast = LC3_SQRT(LC3_SQRT(fast));
      86          32 :           break;
      87        8199 :       case LC3PLUS_FRAME_DURATION_5MS:
      88        8199 :           slow = LC3_SQRT(slow);
      89        8199 :           fast = LC3_SQRT(fast);
      90        8199 :           break;
      91           0 :       case LC3PLUS_FRAME_DURATION_7p5MS:
      92           0 :           slow = LC3_SQRT(LC3_SQRT(slow*slow*slow));
      93           0 :           fast = LC3_SQRT(LC3_SQRT(fast*fast*fast));
      94           0 :           break;
      95          56 :       case LC3PLUS_FRAME_DURATION_10MS:
      96          56 :           break;
      97           0 :         case LC3PLUS_FRAME_DURATION_UNDEFINED:
      98           0 :             assert(0);
      99             :     }
     100             : 
     101        8287 :     if (plc_fadeout_type == 0)
     102             :     {
     103        8215 :         *cum_fading_slow = *cum_fading_slow * slow;
     104        8215 :         *cum_fading_fast = *cum_fading_fast * fast;
     105             :     }
     106             :     
     107        8287 :         if (processDampScramb == 1)
     108             :         {
     109        1375 :                 if (plc_fadeout_type != 0)
     110             :                 {
     111           0 :                         if (nbLostCmpt < (4 * (100.0 / (LC3_FLOAT)(frame_dms*1.25*10)))) {
     112           0 :                                 cum_fading_slow_local = 1.0;
     113             :                         }
     114           0 :                         else if (nbLostCmpt < (8 * (100.0 / (LC3_FLOAT)(frame_dms*1.25*10)))) {
     115           0 :                                 cum_fading_slow_local = 0.9;
     116             :                         }
     117             :                         else {
     118           0 :                                 cum_fading_slow_local = 0.85;
     119             :                         }
     120             : 
     121           0 :                         *cum_fading_slow = *cum_fading_slow * cum_fading_slow_local;
     122           0 :                         cum_fading_slow_local = *cum_fading_slow;                
     123             :                 }
     124             :                 else {
     125        1375 :                         fflcAtten = 1;
     126        1375 :                         cum_fading_slow_local = *cum_fading_slow;
     127        1375 :                         cum_fading_fast_local = *cum_fading_fast;
     128             : 
     129        1375 :                         if (spec_inv_idx == 0)
     130             :                         {
     131        1375 :                                 if (nbLostCmpt * frame_dms * 1.25 * 10 > PLC_FADEOUT_IN_MS * 10)
     132             :                                 {
     133         176 :                                         fflcAtten = 0;
     134         176 :                                         *cum_fflcAtten = 0;
     135             :                                 }
     136        1199 :                                 else if (nbLostCmpt * frame_dms * 1.25 * 10 > 200)
     137             :                                 {
     138         400 :                                         switch (frame_dms)
     139             :                                         {
     140             : #ifdef CR9_C_ADD_1p25MS
     141           0 :                                         case  LC3PLUS_FRAME_DURATION_1p25MS: fflcAtten = PLC34_ATTEN_FAC_0125; break;
     142             : #endif
     143           0 :                                         case  LC3PLUS_FRAME_DURATION_2p5MS: fflcAtten = PLC34_ATTEN_FAC_025; break;
     144         400 :                                         case  LC3PLUS_FRAME_DURATION_5MS: fflcAtten = PLC34_ATTEN_FAC_050; break;
     145           0 :                     case  LC3PLUS_FRAME_DURATION_7p5MS: fflcAtten = PLC34_ATTEN_FAC_075; break;
     146           0 :                                         case LC3PLUS_FRAME_DURATION_10MS: fflcAtten = PLC34_ATTEN_FAC_100; break;
     147           0 :                     case LC3PLUS_FRAME_DURATION_UNDEFINED:
     148           0 :                         assert(0);
     149             :                                         }
     150             :                                 }
     151             : 
     152        1375 :                                 *cum_fflcAtten = *cum_fflcAtten * fflcAtten;
     153        1375 :                                 cum_fading_slow_local = *cum_fading_slow * *cum_fflcAtten;
     154        1375 :                                 cum_fading_fast_local = *cum_fading_fast * *cum_fflcAtten;
     155             :                         }
     156             : 
     157        1375 :                         if (pitch_present == 0)
     158             :                         {
     159        1375 :                                 plc_start_inFrames = 1;
     160             :                         }
     161             :                         else {
     162           0 :                                 plc_start_inFrames = floor(PLC4_TRANSIT_START_IN_MS / (frame_dms * 1.25));
     163             :                         }
     164             : 
     165        1375 :                         plc_end_inFrames = floor(PLC4_TRANSIT_END_IN_MS / (frame_dms * 1.25));
     166        1375 :                         plc_duration_inFrames = plc_end_inFrames - plc_start_inFrames;
     167             : 
     168        1375 :                         if (nbLostCmpt <= plc_start_inFrames)
     169             :                         {
     170         229 :                                 linFuncStartStop = 1;
     171             :                         }
     172        1146 :                         else if (nbLostCmpt >= plc_end_inFrames)
     173             :                         {
     174         204 :                                 linFuncStartStop = 0;
     175             :                         }
     176             :                         else {
     177         942 :                                 x = nbLostCmpt;
     178         942 :                                 m = -1.0 / plc_duration_inFrames;
     179         942 :                                 b = -plc_end_inFrames;
     180         942 :                                 linFuncStartStop = m * (x + b);
     181             :                         }
     182             : 
     183        1375 :                         randThreshold = -32768 * linFuncStartStop;
     184             :                 }
     185             :         
     186      281815 :         for (i = spec_inv_idx; i < yLen; i++)
     187             :         {
     188      280440 :             *seed = 16831 + *seed * 12821;
     189             : 
     190      280440 :             *seed = (LC3_INT16)(*seed);
     191             : 
     192      280440 :             if (*seed < 0)
     193             :             {
     194      138196 :                 if (plc_fadeout_type != 0 || pitch_present == 0 || *seed < randThreshold )
     195             :                 {
     196      138196 :                     spec[i] = -spec[i];
     197             :                 }
     198             :             }
     199             :         }
     200             : 
     201        1375 :         if (plc_fadeout_type == 0)
     202             :         {
     203        1375 :             ad_ThreshFac_start = 10;
     204        1375 :             ad_ThreshFac_end   = 1.2;
     205        1375 :             ad_threshFac       = (ad_ThreshFac_start - ad_ThreshFac_end) * linFuncStartStop + ad_ThreshFac_end;
     206             : 
     207        1375 :             if (spec_inv_idx < yLen)
     208             :             {
     209      281815 :                 for (i = spec_inv_idx; i < yLen; i++)
     210             :                 {
     211      280440 :                     frame_energy = frame_energy + (spec[i] * spec[i]);
     212             :                 }
     213             : 
     214        1375 :                 mean_energy = frame_energy * 1 / (yLen - spec_inv_idx);
     215             :             }
     216             :             else
     217             :             {
     218           0 :                 mean_energy = 0;
     219             :             }
     220             : 
     221        1375 :             energThreshold = LC3_SQRT(ad_threshFac * mean_energy);
     222        1375 :             fac = (cum_fading_slow_local - cum_fading_fast_local) * energThreshold;
     223             :         }
     224             : 
     225      281815 :         for (i = spec_inv_idx; i < yLen; i++)
     226             :         {
     227      280440 :             if (plc_fadeout_type != 0 || LC3_FABS(spec[i]) < energThreshold  )
     228             :             {
     229      247254 :                 m = cum_fading_slow_local;
     230      247254 :                 n = 0;
     231             :             }
     232             :             else
     233             :             {
     234       33186 :                 m = cum_fading_fast_local;
     235             : 
     236       33186 :                 if (spec[i] > 0)
     237             :                 {
     238        4376 :                     n = fac;
     239             :                 }
     240       28810 :                 else if (spec[i] == 0)
     241             :                 {
     242       24440 :                     n = 0;
     243             :                 }
     244             :                 else
     245             :                 {
     246        4370 :                     n = -fac;
     247             :                 }
     248             :             }
     249             : 
     250      280440 :             spec[i] = m * spec[i] + n;
     251             :         }
     252             :     }
     253        8287 : }
     254             : 

Generated by: LCOV version 1.14