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 1758254 : void processResidualCoding_fl(LC3_FLOAT x[], LC3_INT xq[], LC3_FLOAT gain, LC3_INT L_spec, LC3_INT targetBits, LC3_INT nBits, uint8_t* resBits, LC3_INT* numResBits, LC3_INT hrmode 15 : #ifdef ENABLE_12p5_DMS_MODE 16 : , LC3PLUS_FrameDuration frame_dms 17 : #endif 18 : ) 19 : { 20 1758254 : LC3_INT n = 0, m = 0, k = 0; 21 1758254 : LC3_INT iter=0; 22 : LC3_FLOAT offset[3]; 23 1758254 : LC3_INT iter_max = 1; 24 : LC3_INT nz_idx[MAX_LEN]; 25 1758254 : LC3_INT N_nz = 0, idx = 0; 26 : 27 : 28 1758254 : memset(resBits, 0, MAX_RESBITS_LEN); 29 : 30 1758254 : m = targetBits - nBits + 4; 31 1758254 : if (hrmode) 32 : { 33 0 : m += 10; 34 : } 35 : 36 1758254 : assert(m <= MAX_RESBITS); 37 : 38 1758254 : offset[2] = .5; 39 1758254 : if (hrmode) 40 : { 41 0 : iter_max = EXT_RES_ITER_MAX; 42 : } 43 : #ifdef ENABLE_12p5_DMS_MODE 44 1758254 : else if (frame_dms == LC3PLUS_FRAME_DURATION_1p25MS) 45 : { 46 0 : iter_max = 3; 47 0 : offset[2] = .375; 48 : } 49 : #endif 50 : 51 : /* init offset */ 52 1758254 : offset[0] = offset[2] / 2.; 53 1758254 : offset[1] = (1.-offset[2]) / 2.; 54 : 55 369661774 : for (k = 0; k < L_spec; k ++) 56 : { 57 367903520 : if (xq[k]) 58 : { 59 302857238 : nz_idx[N_nz ++] = k; 60 : } 61 : } 62 3516508 : while (iter < iter_max && n < m) 63 : { 64 1758254 : k = 0; 65 35832017 : while (k < N_nz && n < m) 66 : { 67 34073763 : idx = nz_idx[k]; 68 : 69 34073763 : if (x[idx] >= (LC3_FLOAT)xq[idx] * gain) 70 : { 71 17038897 : resBits[n >> 3] |= 1 << (n & 7); 72 17038897 : x[idx] -= gain * offset[x[idx] > 0]; 73 : } 74 : else 75 : { 76 17034866 : resBits[n >> 3] &= ~(1 << (n & 7)); 77 17034866 : x[idx] += gain * offset[x[idx] < 0]; 78 : } 79 : 80 34073763 : n++; 81 : 82 34073763 : k++; 83 : } 84 1758254 : iter ++; 85 1758254 : offset[0] *= .5; 86 1758254 : offset[1] *= .5; 87 : } 88 : 89 1758254 : *numResBits = n; 90 1758254 : }