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 1779817 : 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 1779817 : 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 1779817 : warp_idx_start = BW_warp_idx_start_all[fs_idx - 1]; 22 1779817 : warp_idx_stop = BW_warp_idx_stop_all[fs_idx - 1]; 23 : 24 1779817 : 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 1697637 : case LC3PLUS_FRAME_DURATION_5MS: 37 1697637 : warp_idx_start = BW_warp_idx_start_all_5ms[fs_idx - 1]; 38 1697637 : warp_idx_stop = BW_warp_idx_stop_all_5ms[fs_idx - 1]; 39 1697637 : bw_dist = brickwall_dist; 40 1697637 : 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 82164 : case LC3PLUS_FRAME_DURATION_10MS: 47 82164 : warp_idx_start = BW_warp_idx_start_all[fs_idx - 1]; 48 82164 : warp_idx_stop = BW_warp_idx_stop_all[fs_idx - 1]; 49 82164 : bw_dist = brickwall_dist; 50 82164 : break; 51 0 : case LC3PLUS_FRAME_DURATION_UNDEFINED: 52 0 : assert(0); 53 : } 54 : 55 1779817 : counter = fs_idx; 56 : 57 1779817 : d2_sum = sum_vec(&d2[warp_idx_start[counter - 1]], warp_idx_stop[counter - 1] - warp_idx_start[counter - 1] + 1); 58 : 59 1779817 : d2_mean = d2_sum / (warp_idx_stop[counter - 1] - warp_idx_start[counter - 1] + 1); 60 : 61 2239443 : while (d2_mean < threshold_quiet[counter - 1]) { 62 535327 : d2_sum = 0; 63 535327 : counter--; 64 535327 : if (counter == 0) { 65 75701 : break; 66 : } 67 : 68 : /* calculate mean energy per band */ 69 : d2_sum = 70 459626 : sum_vec(&d2[warp_idx_start[counter - 1]], warp_idx_stop[counter - 1] - warp_idx_start[counter - 1] + 1); 71 : 72 459626 : d2_mean = d2_sum / (warp_idx_stop[counter - 1] - warp_idx_start[counter - 1] + 1); 73 : } 74 : 75 1779817 : *bw_idx = counter; 76 : 77 : /* check if energy difference between bands is present */ 78 1779817 : if (*bw_idx < fs_idx) { 79 265281 : thr = (LC3_FLOAT)threshold_brickwall[counter]; 80 265281 : stop = warp_idx_start[counter]; 81 265281 : dist = bw_dist[counter]; 82 : 83 998863 : for (i = stop; i >= stop - dist; i--) { 84 794432 : e_diff = 10.0 * LC3_LOGTEN(d2[i - dist + 1] + FLT_EPSILON) - 10.0 * LC3_LOGTEN(d2[i + 1] + FLT_EPSILON); 85 : 86 794432 : if (e_diff > thr) { 87 60850 : brickwall = 1; 88 60850 : break; 89 : } 90 : } 91 : 92 265281 : if (brickwall == 0) { 93 204431 : *bw_idx = fs_idx; 94 : } 95 : } 96 1779817 : }