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 1779817 : 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 1779817 : if (attackHandlingOn) { 23 : 24 82160 : mval = 0; j = 0; 25 82160 : frame_size_16k = attdec_nblocks * 40; 26 82160 : ptr = &tmp[2]; 27 : 28 : /* Decimate 48 and 32 kHz signals to 16 kHz */ 29 82160 : if (fs == 48000) { 30 82156 : j = 0; 31 13227116 : for (i = 0; i < frame_size;) { 32 13144960 : ptr[j] = (in[i] + in[i + 1] + in[i + 2]); 33 13144960 : i = i + 3; 34 13144960 : j++; 35 : } 36 4 : } else if (fs == 32000) { 37 4 : j = 0; 38 644 : for (i = 0; i < frame_size;) { 39 640 : ptr[j] = (in[i] + in[i + 1]); 40 640 : i = i + 2; 41 640 : j++; 42 : } 43 : } 44 : 45 : /* Filter */ 46 82160 : ptr[-2] = (LC3_FLOAT)attdec_filter_mem[0]; 47 82160 : ptr[-1] = (LC3_FLOAT)attdec_filter_mem[1]; 48 : 49 82160 : attdec_filter_mem[0] = ptr[frame_size_16k - 2]; 50 82160 : attdec_filter_mem[1] = ptr[frame_size_16k - 1]; 51 : 52 13227760 : for (i = 159; i >= 0; i--) { 53 13145600 : tmpEne = 0; 54 : 55 13145600 : tmpEne += ptr[i] * 0.375; 56 13145600 : tmpEne += ptr[i - 1] * (-0.5); 57 13145600 : tmpEne += ptr[i - 2] * (0.125); 58 : 59 13145600 : f_sig[i] = tmpEne; 60 : } 61 : 62 410800 : for (i = 0; i < attdec_nblocks; i++) { 63 328640 : sum = 0; 64 13474240 : for (j = 0; j < 40; j++) { 65 13145600 : sum += f_sig[j + i * 40] * f_sig[j + i * 40]; 66 : } 67 : 68 328640 : block_nrg[i] = sum; 69 : } 70 : 71 82160 : *attackFlag = 0; 72 82160 : attackPosition = -1; 73 : 74 410800 : for (i = 0; i < attdec_nblocks; i++) { 75 328640 : tmpEne = block_nrg[i] / 8.5; 76 : 77 328640 : if (tmpEne > MAX(*accNrg, mval)) { 78 4776 : *attackFlag = 1; 79 4776 : attackPosition = i + 1; 80 : } 81 : 82 328640 : *accNrg = MAX(block_nrg[i], 0.25 * (*accNrg)); 83 : } 84 : 85 82160 : if (*lastAttackPosition > attdec_hangover_threshold) { 86 2076 : *attackFlag = 1; 87 : } 88 : 89 82160 : *lastAttackPosition = attackPosition; 90 : } 91 1779817 : }