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 processAdjustGlobalGain_fl(LC3_INT* gg_idx, LC3_INT gg_idx_min, LC3_INT gg_idx_off, LC3_FLOAT* gain, LC3_INT target, LC3_INT nBits, LC3_INT* gainChange, LC3_INT fs_idx 15 : , LC3_INT16 hrmode, LC3_INT16 frame_dms 16 : ) 17 : { 18 : LC3_FLOAT delta; 19 : LC3_INT delta2; 20 : LC3_INT gg_idx_inc; 21 : LC3_FLOAT factor; 22 : 23 0 : if (frame_dms == 25) 24 : { 25 0 : if (target < 520) 26 : { 27 0 : factor = 3; 28 : } else { 29 0 : factor = 4; 30 : } 31 0 : } else if (frame_dms == 50) 32 : { 33 0 : factor = 2; 34 : } 35 0 : else if (frame_dms == 75) 36 : { 37 0 : factor = 1.2; 38 : } 39 : else 40 : { 41 0 : factor = 1; 42 : } 43 : 44 0 : if (nBits < gg_p1[fs_idx]) { 45 0 : delta = (nBits + 48.0) / 16.0; 46 0 : } else if (nBits < gg_p2[fs_idx]) { 47 0 : delta = (nBits + gg_d[fs_idx]) * gg_c[fs_idx]; 48 0 : } else if (nBits < gg_p3[fs_idx]) { 49 0 : delta = nBits / 48.0; 50 : } else { 51 0 : delta = gg_p3[fs_idx] / 48.0; 52 : } 53 : 54 0 : delta = round(delta); 55 0 : delta2 = delta + 2; 56 : 57 0 : *gainChange = 0; 58 : 59 0 : if (*gg_idx == 255 && nBits > target) { 60 0 : *gainChange = 1; 61 : } 62 : 63 0 : if ((*gg_idx < 255 && nBits > target) || (*gg_idx > 0 && nBits < target - delta2)) { 64 0 : if (hrmode) 65 : { 66 0 : if (nBits > target) { 67 0 : gg_idx_inc = (int) (factor * (((nBits - target)/ delta) + 1)); 68 0 : gg_idx_inc = MIN(gg_idx_inc, 10 * factor); 69 : 70 0 : *gg_idx += gg_idx_inc; 71 : } 72 : 73 0 : *gg_idx = MIN(*gg_idx, 255); 74 : } 75 : else 76 : { 77 0 : if (nBits < target - delta2) { 78 0 : *gg_idx = *gg_idx - 1; 79 0 : } else if (*gg_idx == 254 || nBits < target + delta) { 80 0 : *gg_idx = *gg_idx + 1; 81 : } else { 82 0 : *gg_idx = *gg_idx + 2; 83 : } 84 : } 85 : 86 0 : *gg_idx = MAX(*gg_idx, gg_idx_min - gg_idx_off); 87 0 : *gain = LC3_POW(10, (LC3_FLOAT)(*gg_idx + gg_idx_off) / 28); 88 0 : *gainChange = 1; 89 : } 90 0 : }