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 0 : 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 0 : LC3_INT n = 0, m = 0, k = 0; 21 0 : LC3_INT iter=0; 22 : LC3_FLOAT offset[3]; 23 0 : LC3_INT iter_max = 1; 24 : LC3_INT nz_idx[MAX_LEN]; 25 0 : LC3_INT N_nz = 0, idx = 0; 26 : 27 : 28 0 : memset(resBits, 0, MAX_RESBITS_LEN); 29 : 30 0 : m = targetBits - nBits + 4; 31 0 : if (hrmode) 32 : { 33 0 : m += 10; 34 : } 35 : 36 0 : assert(m <= MAX_RESBITS); 37 : 38 0 : offset[2] = .5; 39 0 : if (hrmode) 40 : { 41 0 : iter_max = EXT_RES_ITER_MAX; 42 : } 43 : #ifdef ENABLE_12p5_DMS_MODE 44 0 : 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 0 : offset[0] = offset[2] / 2.; 53 0 : offset[1] = (1.-offset[2]) / 2.; 54 : 55 0 : for (k = 0; k < L_spec; k ++) 56 : { 57 0 : if (xq[k]) 58 : { 59 0 : nz_idx[N_nz ++] = k; 60 : } 61 : } 62 0 : while (iter < iter_max && n < m) 63 : { 64 0 : k = 0; 65 0 : while (k < N_nz && n < m) 66 : { 67 0 : idx = nz_idx[k]; 68 : 69 0 : if (x[idx] >= (LC3_FLOAT)xq[idx] * gain) 70 : { 71 0 : resBits[n >> 3] |= 1 << (n & 7); 72 0 : x[idx] -= gain * offset[x[idx] > 0]; 73 : } 74 : else 75 : { 76 0 : resBits[n >> 3] &= ~(1 << (n & 7)); 77 0 : x[idx] += gain * offset[x[idx] < 0]; 78 : } 79 : 80 0 : n++; 81 : 82 0 : k++; 83 : } 84 0 : iter ++; 85 0 : offset[0] *= .5; 86 0 : offset[1] *= .5; 87 : } 88 : 89 0 : *numResBits = n; 90 0 : }