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 2051024 : void processResidualDecoding_fl(LC3_INT* bitsRead, LC3_FLOAT x[], LC3_INT L_spec, uint8_t prm[], LC3_INT resQBits, LC3_INT hrmode 15 : #ifdef ENABLE_12p5_DMS_MODE 16 : , LC3PLUS_FrameDuration frame_dms 17 : #endif 18 : ) 19 : { 20 2051024 : LC3_INT k = 0, n = 0; 21 2051024 : LC3_FLOAT offset1 = 0, offset2 = 0; 22 2051024 : LC3_FLOAT offset = 0; 23 : LC3_INT nz_idx[MAX_LEN]; 24 2051024 : LC3_INT N_nz = 0, idx = 0; 25 : 26 2051024 : LC3_INT iter = 0, iter_max = 1; 27 : 28 2051024 : if (hrmode) 29 : { 30 0 : iter_max = EXT_RES_ITER_MAX; 31 0 : offset = offset1 = offset2 = 0.25; 32 : } 33 : else 34 : { 35 2051024 : offset1 = 0.1875; 36 2051024 : offset2 = 0.3125; 37 : } 38 : 39 : #ifdef ENABLE_12p5_DMS_MODE 40 2051024 : if (frame_dms == LC3PLUS_FRAME_DURATION_1p25MS) 41 : { 42 0 : iter_max = 3; 43 : } 44 : #endif 45 : 46 : /* enumerat non-zero coefficients */ 47 430092944 : for (k = 0; k < L_spec; k ++) 48 : { 49 428041920 : if (x[k]) 50 : { 51 354666586 : nz_idx[N_nz ++] = k; 52 : } 53 : } 54 : 55 2051024 : if (hrmode) 56 : { 57 : 58 : /* apply residual corrections */ 59 0 : while (n < resQBits && iter < iter_max) 60 : { 61 0 : for (k = 0; k < N_nz; k ++) 62 : { 63 0 : idx = nz_idx[k]; 64 : 65 0 : if ((prm[n >> 3] & 1 << (n & 7)) == 0) 66 : { 67 0 : x[idx] -= offset; 68 : } 69 : else 70 : { 71 : 72 0 : x[idx] += offset; 73 : } 74 0 : if (++n >= resQBits) 75 : { 76 0 : break; 77 : } 78 : } 79 0 : offset *= 0.5; 80 0 : iter ++; 81 : } 82 : } 83 : else 84 : { 85 : UNUSED(offset); 86 : 87 4076306 : while (n < resQBits && iter < iter_max) { 88 33529188 : for (k = 0; k < N_nz; k ++) 89 : { 90 33529188 : idx = nz_idx[k]; 91 : 92 33529188 : if ((prm[n >> 3] & 1 << (n & 7)) == 0) 93 : { 94 16764085 : if (x[idx] > 0) { 95 6420750 : x[idx] -= offset1; 96 : } else { 97 10343335 : x[idx] -= offset2; 98 : } 99 : } else { 100 16765103 : if (x[idx] > 0) { 101 10344488 : x[idx] += offset2; 102 : } else { 103 6420615 : x[idx] += offset1; 104 : } 105 : } 106 33529188 : if (++n >= resQBits) 107 : { 108 2025282 : break; 109 : } 110 : } 111 2025282 : offset1 *= 0.5; 112 2025282 : offset2 *= 0.5; 113 2025282 : iter ++; 114 : } 115 : } 116 2051024 : *bitsRead = n; 117 2051024 : }