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