LCOV - code coverage report
Current view: top level - lib_lc3plus - attack_detector.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 0 44 0.0 %
Date: 2025-05-23 08:37:30 Functions: 0 1 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 attack_detector_fl(LC3_FLOAT* in, LC3_INT frame_size, LC3_INT fs, LC3_INT* lastAttackPosition, LC3_FLOAT* accNrg, LC3_INT* attackFlag,
      15             :                         LC3_FLOAT* attdec_filter_mem, LC3_INT attackHandlingOn, LC3_INT attdec_nblocks, LC3_INT attdec_hangover_threshold)
      16             : {
      17             :     LC3_FLOAT f_sig[160], block_nrg[4], sum, tmpEne, *ptr, tmp[162];
      18             :     LC3_INT   i, j, attackPosition;
      19             :     LC3_FLOAT mval;
      20             :     LC3_INT frame_size_16k;
      21             : 
      22           0 :     if (attackHandlingOn) {
      23             : 
      24           0 :         mval = 0; j = 0;
      25           0 :         frame_size_16k = attdec_nblocks * 40;
      26           0 :         ptr = &tmp[2];
      27             :         
      28             :         /* Decimate 48 and 32 kHz signals to 16 kHz */
      29           0 :         if (fs == 48000) {
      30           0 :             j = 0;
      31           0 :             for (i = 0; i < frame_size;) {
      32           0 :                 ptr[j] = (in[i] + in[i + 1] + in[i + 2]);
      33           0 :                 i      = i + 3;
      34           0 :                 j++;
      35             :             }
      36           0 :         } else if (fs == 32000) {
      37           0 :             j = 0;
      38           0 :             for (i = 0; i < frame_size;) {
      39           0 :                 ptr[j] = (in[i] + in[i + 1]);
      40           0 :                 i      = i + 2;
      41           0 :                 j++;
      42             :             }
      43             :         }
      44             : 
      45             :         /* Filter */
      46           0 :         ptr[-2] = (LC3_FLOAT)attdec_filter_mem[0];
      47           0 :         ptr[-1] = (LC3_FLOAT)attdec_filter_mem[1];
      48             : 
      49           0 :         attdec_filter_mem[0] = ptr[frame_size_16k - 2];
      50           0 :         attdec_filter_mem[1] = ptr[frame_size_16k - 1];
      51             : 
      52           0 :         for (i = 159; i >= 0; i--) {
      53           0 :             tmpEne = 0;
      54             : 
      55           0 :             tmpEne += ptr[i] * 0.375;
      56           0 :             tmpEne += ptr[i - 1] * (-0.5);
      57           0 :             tmpEne += ptr[i - 2] * (0.125);
      58             : 
      59           0 :             f_sig[i] = tmpEne;
      60             :         }
      61             : 
      62           0 :         for (i = 0; i < attdec_nblocks; i++) {
      63           0 :             sum = 0;
      64           0 :             for (j = 0; j < 40; j++) {
      65           0 :                 sum += f_sig[j + i * 40] * f_sig[j + i * 40];
      66             :             }
      67             : 
      68           0 :             block_nrg[i] = sum;
      69             :         }
      70             : 
      71           0 :         *attackFlag    = 0;
      72           0 :         attackPosition = -1;
      73             : 
      74           0 :         for (i = 0; i < attdec_nblocks; i++) {
      75           0 :             tmpEne = block_nrg[i] / 8.5;
      76             : 
      77           0 :             if (tmpEne > MAX(*accNrg, mval)) {
      78           0 :                 *attackFlag    = 1;
      79           0 :                 attackPosition = i + 1;
      80             :             }
      81             : 
      82           0 :             *accNrg = MAX(block_nrg[i], 0.25 * (*accNrg));
      83             :         }
      84             : 
      85           0 :         if (*lastAttackPosition > attdec_hangover_threshold) {
      86           0 :             *attackFlag = 1;
      87             :         }
      88             : 
      89           0 :         *lastAttackPosition = attackPosition;
      90             :     }
      91           0 : }

Generated by: LCOV version 1.14