Line data Source code
1 : /****************************************************************************** 2 : * ETSI TS 103 634 V1.6.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 processDetectCutoffWarped_fl(LC3_FLOAT* d2, LC3_INT fs_idx, LC3PLUS_FrameDuration frame_dms, LC3_INT* bw_idx) 15 : { 16 : const LC3_INT *warp_idx_start, *warp_idx_stop; 17 1189311 : LC3_INT counter, brickwall = 0, i, stop, dist; 18 : LC3_FLOAT d2_mean, d2_sum, e_diff, thr; 19 : const LC3_INT *bw_dist; 20 : 21 1189311 : warp_idx_start = BW_warp_idx_start_all[fs_idx - 1]; 22 1189311 : warp_idx_stop = BW_warp_idx_stop_all[fs_idx - 1]; 23 : 24 1189311 : switch (frame_dms) 25 : { 26 : #ifdef CR9_C_ADD_1p25MS 27 0 : case LC3PLUS_FRAME_DURATION_1p25MS: 28 0 : assert (0); 29 : break; 30 : #endif 31 16 : case LC3PLUS_FRAME_DURATION_2p5MS: 32 16 : warp_idx_start = BW_warp_idx_start_all_2_5ms[fs_idx - 1]; 33 16 : warp_idx_stop = BW_warp_idx_stop_all_2_5ms[fs_idx - 1]; 34 16 : bw_dist = brickwall_dist; 35 16 : break; 36 1139323 : case LC3PLUS_FRAME_DURATION_5MS: 37 1139323 : warp_idx_start = BW_warp_idx_start_all_5ms[fs_idx - 1]; 38 1139323 : warp_idx_stop = BW_warp_idx_stop_all_5ms[fs_idx - 1]; 39 1139323 : bw_dist = brickwall_dist; 40 1139323 : break; 41 0 : case LC3PLUS_FRAME_DURATION_7p5MS: 42 0 : warp_idx_start = BW_warp_idx_start_all_7_5ms[fs_idx - 1]; 43 0 : warp_idx_stop = BW_warp_idx_stop_all_7_5ms[fs_idx - 1]; 44 0 : bw_dist = brickwall_dist_7_5ms; 45 0 : break; 46 49972 : case LC3PLUS_FRAME_DURATION_10MS: 47 49972 : warp_idx_start = BW_warp_idx_start_all[fs_idx - 1]; 48 49972 : warp_idx_stop = BW_warp_idx_stop_all[fs_idx - 1]; 49 49972 : bw_dist = brickwall_dist; 50 49972 : break; 51 0 : case LC3PLUS_FRAME_DURATION_UNDEFINED: 52 0 : assert(0); 53 : } 54 : 55 1189311 : counter = fs_idx; 56 : 57 1189311 : d2_sum = sum_vec(&d2[warp_idx_start[counter - 1]], warp_idx_stop[counter - 1] - warp_idx_start[counter - 1] + 1); 58 : 59 1189311 : d2_mean = d2_sum / (warp_idx_stop[counter - 1] - warp_idx_start[counter - 1] + 1); 60 : 61 1505267 : while (d2_mean < threshold_quiet[counter - 1]) { 62 368402 : d2_sum = 0; 63 368402 : counter--; 64 368402 : if (counter == 0) { 65 52446 : break; 66 : } 67 : 68 : /* calculate mean energy per band */ 69 : d2_sum = 70 315956 : sum_vec(&d2[warp_idx_start[counter - 1]], warp_idx_stop[counter - 1] - warp_idx_start[counter - 1] + 1); 71 : 72 315956 : d2_mean = d2_sum / (warp_idx_stop[counter - 1] - warp_idx_start[counter - 1] + 1); 73 : } 74 : 75 1189311 : *bw_idx = counter; 76 : 77 : /* check if energy difference between bands is present */ 78 1189311 : if (*bw_idx < fs_idx) { 79 175038 : thr = (LC3_FLOAT)threshold_brickwall[counter]; 80 175038 : stop = warp_idx_start[counter]; 81 175038 : dist = bw_dist[counter]; 82 : 83 668913 : for (i = stop; i >= stop - dist; i--) { 84 537783 : e_diff = 10.0 * LC3_LOGTEN(d2[i - dist + 1] + FLT_EPSILON) - 10.0 * LC3_LOGTEN(d2[i + 1] + FLT_EPSILON); 85 : 86 537783 : if (e_diff > thr) { 87 43908 : brickwall = 1; 88 43908 : break; 89 : } 90 : } 91 : 92 175038 : if (brickwall == 0) { 93 131130 : *bw_idx = fs_idx; 94 : } 95 : } 96 1189311 : }