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 @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 0 103 0.0 %
Date: 2025-05-23 08:37:30 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             : *                        ETSI TS 103 634 V1.5.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           0 : 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             :                                         LC3_INT32 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           0 :     processDampScramb = 0;
      27             :     
      28             : 
      29           0 :     if ( bfi != 0 )
      30             :     {
      31           0 :         if (concealMethod == 4 || bfi == 2)
      32             :         {
      33           0 :             processDampScramb = 1;
      34             :         }
      35             :         
      36           0 :         if (ns_nbLostCmpt == 1)
      37             :         {
      38           0 :             *cum_fading_slow = 1;
      39           0 :             *cum_fading_fast = 1;
      40           0 :             *cum_fflcAtten   = 1;
      41             :         }     
      42             :         
      43           0 :         if ( bfi == 1 )
      44             :         {
      45           0 :             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           0 : }
      60             : 
      61           0 : 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, LC3_INT32 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           0 :     frame_energy = 0;
      71             : 
      72           0 :     slow = 0.8 + 0.2 * (*stabFac);
      73           0 :     fast = 0.3 + 0.2 * (*stabFac);
      74             : 
      75           0 :     switch (frame_dms)
      76             :     {
      77           0 :     case 25:
      78           0 :         slow = LC3_SQRT(LC3_SQRT(slow));
      79           0 :         fast = LC3_SQRT(LC3_SQRT(fast));
      80           0 :         break;
      81           0 :     case 50:
      82           0 :         slow = LC3_SQRT(slow);
      83           0 :         fast = LC3_SQRT(fast);
      84           0 :         break;
      85           0 :     case 75:
      86           0 :         slow = LC3_SQRT(LC3_SQRT(slow*slow*slow));
      87           0 :         fast = LC3_SQRT(LC3_SQRT(fast*fast*fast));
      88           0 :         break;
      89             :     }
      90             : 
      91           0 :     if (plc_fadeout_type == 0)
      92             :     {
      93           0 :         *cum_fading_slow = *cum_fading_slow * slow;
      94           0 :         *cum_fading_fast = *cum_fading_fast * fast;
      95             :     }
      96             :     
      97           0 :         if (processDampScramb == 1)
      98             :         {
      99           0 :                 if (plc_fadeout_type != 0)
     100             :                 {
     101           0 :                         if (nbLostCmpt < (4 * (100.0 / (LC3_FLOAT)frame_dms))) {
     102           0 :                                 cum_fading_slow_local = 1.0;
     103             :                         }
     104           0 :                         else if (nbLostCmpt < (8 * (100.0 / (LC3_FLOAT)frame_dms))) {
     105           0 :                                 cum_fading_slow_local = 0.9;
     106             :                         }
     107             :                         else {
     108           0 :                                 cum_fading_slow_local = 0.85;
     109             :                         }
     110             : 
     111           0 :                         *cum_fading_slow = *cum_fading_slow * cum_fading_slow_local;
     112           0 :                         cum_fading_slow_local = *cum_fading_slow;                
     113             :                 }
     114             :                 else {
     115           0 :                         fflcAtten = 1;
     116           0 :                         cum_fading_slow_local = *cum_fading_slow;
     117           0 :                         cum_fading_fast_local = *cum_fading_fast;
     118             : 
     119           0 :                         if (spec_inv_idx == 0)
     120             :                         {
     121           0 :                                 if (nbLostCmpt * frame_dms > PLC_FADEOUT_IN_MS * 10)
     122             :                                 {
     123           0 :                                         fflcAtten = 0;
     124           0 :                                         *cum_fflcAtten = 0;
     125             :                                 }
     126           0 :                                 else if (nbLostCmpt * frame_dms > 200)
     127             :                                 {
     128           0 :                                         switch (frame_dms)
     129             :                                         {
     130           0 :                                         case  25: fflcAtten = PLC34_ATTEN_FAC_025; break;
     131           0 :                                         case  50: fflcAtten = PLC34_ATTEN_FAC_050; break;
     132           0 :                     case  75: fflcAtten = PLC34_ATTEN_FAC_075; break;
     133           0 :                                         case 100: fflcAtten = PLC34_ATTEN_FAC_100; break;
     134             :                                         }
     135           0 :                                 }
     136             : 
     137             : 
     138           0 :                                 *cum_fflcAtten = *cum_fflcAtten * fflcAtten;
     139           0 :                                 cum_fading_slow_local = *cum_fading_slow * *cum_fflcAtten;
     140           0 :                                 cum_fading_fast_local = *cum_fading_fast * *cum_fflcAtten;
     141             :                         }
     142             : 
     143           0 :                         if (pitch_present == 0)
     144             :                         {
     145           0 :                                 plc_start_inFrames = 1;
     146             :                         }
     147             :                         else {
     148           0 :                                 plc_start_inFrames = floor(PLC4_TRANSIT_START_IN_MS / (frame_dms / 10.0));
     149             :                         }
     150             : 
     151           0 :                         plc_end_inFrames = floor(PLC4_TRANSIT_END_IN_MS / (frame_dms / 10.0));
     152           0 :                         plc_duration_inFrames = plc_end_inFrames - plc_start_inFrames;
     153             : 
     154           0 :                         if (nbLostCmpt <= plc_start_inFrames)
     155             :                         {
     156           0 :                                 linFuncStartStop = 1;
     157             :                         }
     158           0 :                         else if (nbLostCmpt >= plc_end_inFrames)
     159             :                         {
     160           0 :                                 linFuncStartStop = 0;
     161             :                         }
     162             :                         else {
     163           0 :                                 x = nbLostCmpt;
     164           0 :                                 m = -1.0 / plc_duration_inFrames;
     165           0 :                                 b = -plc_end_inFrames;
     166           0 :                                 linFuncStartStop = m * (x + b);
     167             :                         }
     168             : 
     169           0 :                         randThreshold = -32768 * linFuncStartStop;
     170             :                 }
     171             :         
     172           0 :         for (i = spec_inv_idx; i < yLen; i++)
     173             :         {
     174           0 :             *seed = 16831 + *seed * 12821;
     175             : 
     176           0 :             *seed = (LC3_INT16)(*seed);
     177             : 
     178           0 :             if (*seed < 0)
     179             :             {
     180           0 :                 if (plc_fadeout_type != 0 || pitch_present == 0 || *seed < randThreshold )
     181             :                 {
     182           0 :                     spec[i] = -spec[i];
     183             :                 }
     184             :             }
     185             :         }
     186             : 
     187           0 :         if (plc_fadeout_type == 0)
     188             :         {
     189           0 :             ad_ThreshFac_start = 10;
     190           0 :             ad_ThreshFac_end   = 1.2;
     191           0 :             ad_threshFac       = (ad_ThreshFac_start - ad_ThreshFac_end) * linFuncStartStop + ad_ThreshFac_end;
     192             : 
     193           0 :             if (spec_inv_idx < yLen)
     194             :             {
     195           0 :                 for (i = spec_inv_idx; i < yLen; i++)
     196             :                 {
     197           0 :                     frame_energy = frame_energy + (spec[i] * spec[i]);
     198             :                 }
     199             : 
     200           0 :                 mean_energy = frame_energy * 1 / (yLen - spec_inv_idx);
     201             :             }
     202             :             else
     203             :             {
     204           0 :                 mean_energy = 0;
     205             :             }
     206             : 
     207           0 :             energThreshold = LC3_SQRT(ad_threshFac * mean_energy);
     208           0 :             fac = (cum_fading_slow_local - cum_fading_fast_local) * energThreshold;
     209             :         }
     210             : 
     211           0 :         for (i = spec_inv_idx; i < yLen; i++)
     212             :         {
     213           0 :             if (plc_fadeout_type != 0 || LC3_FABS(spec[i]) < energThreshold  )
     214             :             {
     215           0 :                 m = cum_fading_slow_local;
     216           0 :                 n = 0;
     217             :             }
     218             :             else
     219             :             {
     220           0 :                 m = cum_fading_fast_local;
     221             : 
     222           0 :                 if (spec[i] > 0)
     223             :                 {
     224           0 :                     n = fac;
     225             :                 }
     226           0 :                 else if (spec[i] == 0)
     227             :                 {
     228           0 :                     n = 0;
     229             :                 }
     230             :                 else
     231             :                 {
     232           0 :                     n = -fac;
     233             :                 }
     234             :             }
     235             : 
     236           0 :             spec[i] = m * spec[i] + n;
     237             :         }
     238             :     }
     239           0 : }
     240             : 

Generated by: LCOV version 1.14