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 processNearNyquistdetector_fl(LC3_INT16* near_nyquist_flag, const LC3_INT fs_idx, const LC3_INT near_nyquist_index, 15 : const LC3_INT bands_number, const LC3_FLOAT* ener , const LC3_INT16 frame_dms, const LC3_INT16 hrmode) 16 : { 17 0 : *near_nyquist_flag = 0; 18 0 : if (hrmode == 0){ 19 0 : if (fs_idx < 4) 20 : { 21 0 : LC3_INT i = 0; 22 0 : LC3_FLOAT ener_low = FLT_EPSILON, ener_high = 0; 23 : 24 0 : for (i=0; i<near_nyquist_index; i++) 25 : { 26 0 : ener_low += ener[i]; 27 : } 28 : 29 0 : for (i=near_nyquist_index; i<bands_number; i++) 30 : { 31 0 : ener_high += ener[i]; 32 : } 33 : 34 0 : if (ener_high > NN_thresh * ener_low){ 35 0 : *near_nyquist_flag = 1; 36 : } 37 : } 38 : } 39 : else // hrmode == 1 40 : { 41 : // inverse spectral flatness = mean(energy) ./ 2^(mean(log2(energy))); 42 0 : LC3_INT32 td_thresh, i = 0; 43 0 : LC3_FLOAT mean_ener = 0, mean_ener_log2 = 0, inv_flatness = 0; 44 : 45 0 : switch (frame_dms) 46 : { 47 0 : case 25: 48 0 : td_thresh = TD_HR_thresh_2_5ms; 49 0 : break; 50 0 : case 50: 51 0 : td_thresh = TD_HR_thresh_5ms; 52 0 : break; 53 0 : case 75: 54 0 : td_thresh = TD_HR_thresh_7_5ms; 55 0 : break; 56 0 : default: /* 100 */ 57 0 : td_thresh = TD_HR_thresh_10ms; 58 0 : break; 59 : } 60 : 61 : // calculate arithmetic mean 62 0 : for (i = 0; i < bands_number; i++) 63 : { 64 0 : mean_ener += ener[i]; 65 : } 66 0 : mean_ener = mean_ener / bands_number; 67 : 68 : // calculate geometric mean 69 0 : for (i = 0; i < bands_number; i++) 70 : { 71 0 : if (ener[i] != 0) { 72 0 : mean_ener_log2 += LC3_LOGTWO(ener[i]); 73 : } 74 : } 75 0 : mean_ener_log2 = mean_ener_log2 / bands_number; 76 : 77 0 : inv_flatness = mean_ener / LC3_POW(2,mean_ener_log2); 78 : 79 0 : if (inv_flatness > td_thresh) { 80 0 : *near_nyquist_flag = 1; 81 : } 82 : } 83 0 : }