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 1160445 : 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 1160445 : LC3_INT k = 0, n = 0; 21 1160445 : LC3_FLOAT offset1 = 0, offset2 = 0; 22 1160445 : LC3_FLOAT offset = 0; 23 : LC3_INT nz_idx[MAX_LEN]; 24 1160445 : LC3_INT N_nz = 0, idx = 0; 25 : 26 1160445 : LC3_INT iter = 0, iter_max = 1; 27 : 28 1160445 : if (hrmode) 29 : { 30 0 : iter_max = EXT_RES_ITER_MAX; 31 0 : offset = offset1 = offset2 = 0.25; 32 : } 33 : else 34 : { 35 1160445 : offset1 = 0.1875; 36 1160445 : offset2 = 0.3125; 37 : } 38 : 39 : #ifdef ENABLE_12p5_DMS_MODE 40 1160445 : if (frame_dms == LC3PLUS_FRAME_DURATION_1p25MS) 41 : { 42 0 : iter_max = 3; 43 : } 44 : #endif 45 : 46 : /* enumerat non-zero coefficients */ 47 243097765 : for (k = 0; k < L_spec; k ++) 48 : { 49 241937320 : if (x[k]) 50 : { 51 198455996 : nz_idx[N_nz ++] = k; 52 : } 53 : } 54 : 55 1160445 : 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 2302129 : while (n < resQBits && iter < iter_max) { 88 18919666 : for (k = 0; k < N_nz; k ++) 89 : { 90 18919666 : idx = nz_idx[k]; 91 : 92 18919666 : if ((prm[n >> 3] & 1 << (n & 7)) == 0) 93 : { 94 9459126 : if (x[idx] > 0) { 95 3660328 : x[idx] -= offset1; 96 : } else { 97 5798798 : x[idx] -= offset2; 98 : } 99 : } else { 100 9460540 : if (x[idx] > 0) { 101 5804631 : x[idx] += offset2; 102 : } else { 103 3655909 : x[idx] += offset1; 104 : } 105 : } 106 18919666 : if (++n >= resQBits) 107 : { 108 1141684 : break; 109 : } 110 : } 111 1141684 : offset1 *= 0.5; 112 1141684 : offset2 *= 0.5; 113 1141684 : iter ++; 114 : } 115 : } 116 1160445 : *bitsRead = n; 117 1160445 : }