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 1189311 : 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 1189311 : if (attackHandlingOn) { 23 : 24 49968 : mval = 0; j = 0; 25 49968 : frame_size_16k = attdec_nblocks * 40; 26 49968 : ptr = &tmp[2]; 27 : 28 : /* Decimate 48 and 32 kHz signals to 16 kHz */ 29 49968 : if (fs == 48000) { 30 49964 : j = 0; 31 8044204 : for (i = 0; i < frame_size;) { 32 7994240 : ptr[j] = (in[i] + in[i + 1] + in[i + 2]); 33 7994240 : i = i + 3; 34 7994240 : 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 49968 : ptr[-2] = (LC3_FLOAT)attdec_filter_mem[0]; 47 49968 : ptr[-1] = (LC3_FLOAT)attdec_filter_mem[1]; 48 : 49 49968 : attdec_filter_mem[0] = ptr[frame_size_16k - 2]; 50 49968 : attdec_filter_mem[1] = ptr[frame_size_16k - 1]; 51 : 52 8044848 : for (i = 159; i >= 0; i--) { 53 7994880 : tmpEne = 0; 54 : 55 7994880 : tmpEne += ptr[i] * 0.375; 56 7994880 : tmpEne += ptr[i - 1] * (-0.5); 57 7994880 : tmpEne += ptr[i - 2] * (0.125); 58 : 59 7994880 : f_sig[i] = tmpEne; 60 : } 61 : 62 249840 : for (i = 0; i < attdec_nblocks; i++) { 63 199872 : sum = 0; 64 8194752 : for (j = 0; j < 40; j++) { 65 7994880 : sum += f_sig[j + i * 40] * f_sig[j + i * 40]; 66 : } 67 : 68 199872 : block_nrg[i] = sum; 69 : } 70 : 71 49968 : *attackFlag = 0; 72 49968 : attackPosition = -1; 73 : 74 249840 : for (i = 0; i < attdec_nblocks; i++) { 75 199872 : tmpEne = block_nrg[i] / 8.5; 76 : 77 199872 : if (tmpEne > MAX(*accNrg, mval)) { 78 3941 : *attackFlag = 1; 79 3941 : attackPosition = i + 1; 80 : } 81 : 82 199872 : *accNrg = MAX(block_nrg[i], 0.25 * (*accNrg)); 83 : } 84 : 85 49968 : if (*lastAttackPosition > attdec_hangover_threshold) { 86 1670 : *attackFlag = 1; 87 : } 88 : 89 49968 : *lastAttackPosition = attackPosition; 90 : } 91 1189311 : }