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