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 1777035 : void processPlcUpdate_fl(PlcAdvSetup *PlcAdvSetup, LC3_INT32 frame_length, LC3_FLOAT *syntM, LC3_FLOAT *scf_q, 15 : LC3_INT32 *nbLostCmpt, LC3_FLOAT *cum_alpha, LC3_INT32 bfi, LC3_INT32 *prevBfi, LC3_INT32 *prevprevBfi) 16 : { 17 : LC3_FLOAT tmp[MAX_LEN_PCM_PLC]; 18 : 19 1777035 : move_float(tmp, &PlcAdvSetup->pcmbufHist[frame_length], PlcAdvSetup->max_len_pcm_plc - frame_length); 20 1777035 : move_float(&PlcAdvSetup->pcmbufHist[0], tmp, PlcAdvSetup->max_len_pcm_plc - frame_length); 21 1777035 : move_float(&PlcAdvSetup->pcmbufHist[PlcAdvSetup->max_len_pcm_plc - frame_length], syntM, frame_length); 22 : 23 1777035 : if (bfi != 1) 24 : { 25 1768748 : *nbLostCmpt = 0; 26 1768748 : *cum_alpha = 1; 27 : 28 1768748 : if (PlcAdvSetup) 29 : { 30 1768748 : move_float(PlcAdvSetup->scf_q_old_old, PlcAdvSetup->scf_q_old, M); 31 1768748 : move_float(PlcAdvSetup->scf_q_old, scf_q, M); 32 : /* PLC fullband transient detector setting for non-bfi frames */ 33 1768748 : PlcAdvSetup->PlcPhEcuSetup.PhECU_short_flag_prev = 0; /* fullband transient not active */ 34 : } 35 : } 36 : 37 1777035 : *prevprevBfi = *prevBfi; 38 1777035 : *prevBfi = bfi; 39 1777035 : } 40 : 41 82164 : void plc_phEcu_processPLCspec2shape(LC3_INT16 prev_bfi, LC3_INT16 bfi, LC3_FLOAT q_d[], LC3_INT32 yLen, 42 : LC3_FLOAT *stPhECU_oold_grp_shape, LC3_FLOAT *stPhECU_old_grp_shape) 43 : { 44 : LC3_INT32 i, j, N_grp; 45 : LC3_INT32 local_prev_bfi; 46 : LC3_INT32 fs_idx; 47 82164 : LC3_FLOAT E_tot = 0.0; 48 : LC3_INT32 l_grp; 49 : LC3_FLOAT *pX; 50 : 51 82164 : if (bfi != 1) /* compute only for bfi== 0 or 2 */ 52 : { 53 82108 : fs_idx = (LC3_INT32)floor(yLen / 100); 54 82108 : assert(fs_idx < 5); 55 82108 : N_grp = xavg_N_grp[fs_idx]; 56 : 57 82108 : local_prev_bfi = prev_bfi; 58 82108 : if (local_prev_bfi == 2) { 59 0 : local_prev_bfi = 0; 60 : } 61 : 62 : 63 : /* Copy old to oold grp shape */ 64 821080 : for (i = 0; i < MAX_LGW; i++) 65 : { 66 738972 : stPhECU_oold_grp_shape[i] = stPhECU_old_grp_shape[i]; 67 : } 68 : 69 : /* Accumulate DC-coupled bins to total */ 70 82108 : E_tot = 0; 71 82108 : pX = q_d; /* ptr setup */ 72 410540 : for (i = 0; i < mdct_grp_bins[0]; i++) 73 : { 74 328432 : E_tot += sqrf( *pX ); 75 328432 : pX++; 76 : } 77 : 78 : /* Accumulate middle grps and add to total */ 79 656848 : for (i = 0; i < (N_grp - 1); i++) 80 : { 81 574740 : l_grp = mdct_grp_bins[i + 1] - mdct_grp_bins[i]; ; 82 574740 : stPhECU_old_grp_shape[i] = 0.0; 83 26848020 : for (j = 0; j < l_grp; j++) { 84 26273280 : stPhECU_old_grp_shape[i] += sqrf( *pX ); 85 26273280 : pX++; 86 : } 87 574740 : E_tot += stPhECU_old_grp_shape[i]; 88 : } 89 : 90 : /* Accumulate last subbband and add to total */ 91 82108 : stPhECU_old_grp_shape[(N_grp - 1)] = 0.0; 92 82108 : l_grp = mdct_grp_bins[N_grp] - mdct_grp_bins[N_grp - 1] - mdct_grp_bins[0]; 93 82108 : assert( (mdct_grp_bins[N_grp] - mdct_grp_bins[0]) <= yLen); 94 6322316 : for (j = 0; j < l_grp; j++) 95 : { 96 6240208 : stPhECU_old_grp_shape[(N_grp - 1)] += sqrf( *pX ); 97 6240208 : pX++; 98 : } 99 82108 : E_tot += stPhECU_old_grp_shape[(N_grp - 1)]; 100 : 101 : 102 : /* Normalize shape */ 103 738956 : for (i = 0; i < (N_grp); i++) { 104 656848 : if (E_tot > 0.0) { 105 655872 : stPhECU_old_grp_shape[i] /= E_tot; 106 : } 107 : else 108 : { 109 976 : stPhECU_old_grp_shape[i] = 0.0; 110 : } 111 : } 112 82108 : if (local_prev_bfi == 1) { 113 210 : for (i = 0; i < MAX_LGW; i++) { 114 189 : stPhECU_oold_grp_shape[i] = stPhECU_old_grp_shape[i]; 115 : } 116 : } 117 : }/*bfi*/ 118 82164 : return; 119 : } 120 : 121 1768748 : void processPlcUpdateSpec_fl(LC3_FLOAT *q_d_prev, LC3_FLOAT *q_d_fl_c, LC3_INT32 yLen) 122 : { 123 1768748 : move_float(q_d_prev, q_d_fl_c, yLen); 124 1768748 : } 125 :