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