Line data Source code
1 : /****************************************************************************** 2 : * ETSI TS 103 634 V1.5.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 1779817 : void processSnsComputeScf_fl(LC3_FLOAT* x, LC3_INT xLen, LC3_FLOAT* gains, LC3_INT smooth, LC3_FLOAT sns_damping, LC3_FLOAT attdec_damping_factor, LC3_INT fs_idx) 15 : { 16 : LC3_INT bands_number, d, i, j, n, n2, n4, mapping[64]; 17 : LC3_FLOAT x_tmp1[MAX_LEN], sum, mean, nf, gains_smooth[M], ratio; 18 : LC3_FLOAT sum_gains_smooth; 19 : const LC3_FLOAT* sns_preemph; 20 : 21 1779817 : sum_gains_smooth = 0; sum = 0; 22 1779817 : sns_preemph = sns_preemph_all[fs_idx]; 23 : 24 1779817 : bands_number = xLen; 25 1779817 : assert(bands_number <= 64); 26 : 27 : /* 5 ms */ 28 1779817 : if (bands_number < 64) { 29 1697653 : d = 64 - bands_number; 30 : 31 1697653 : if (d < xLen) 32 : { 33 1697653 : j = 0; 34 16976706 : for (i = 0; i < 2 * d; i = i + 2) { 35 15279053 : x_tmp1[i] = x[j]; 36 15279053 : x_tmp1[i + 1] = x[j]; 37 15279053 : j++; 38 : } 39 : 40 1697653 : move_float(&x_tmp1[2 * d], &x[d], 64 - 2 * d); 41 : } 42 0 : else if (bands_number < 32) 43 : { 44 0 : ratio = LC3_FABS((LC3_FLOAT) (1.0 - 32.0 / (LC3_FLOAT) xLen)); 45 0 : n4 = round(ratio * xLen); 46 0 : n2 = xLen - n4; 47 : 48 0 : j = 0; 49 0 : for(i = 1; i <= n4; i++) 50 : { 51 0 : mapping[j] = i; 52 0 : mapping[j + 1] = i; 53 0 : mapping[j + 2] = i; 54 0 : mapping[j + 3] = i; 55 0 : j += 4; 56 : } 57 : 58 0 : for (i = n4 + 1; i <= n4 + n2; i++) 59 : { 60 0 : mapping[j] = i; 61 0 : mapping[j + 1] = i; 62 0 : j += 2; 63 : } 64 : 65 : 66 0 : for (i = 0; i < 64; i++) 67 : { 68 0 : x_tmp1[i] = x[mapping[i] - 1]; 69 : } 70 : } else { 71 0 : assert(0 && "Unsupported number of bands!"); 72 : } 73 : 74 1697653 : move_float(x, x_tmp1, 64); 75 : 76 1697653 : bands_number = 64; 77 1697653 : xLen = bands_number; 78 : } 79 : 80 : 81 : /* Smoothing */ 82 : 83 1779817 : x_tmp1[0] = x[0]; 84 1779817 : move_float(&x_tmp1[1], &x[0], 63); 85 : 86 113908288 : for (i = 0; i < 63; i++) { 87 112128471 : x[i] = 0.5 * x[i] + 0.25 * (x_tmp1[i] + x[i + 1]); 88 : } 89 : 90 1779817 : x[63] = 0.5 * x[63] + 0.25 * (x_tmp1[63] + x[63]); 91 : 92 : /* Pre-emphasis */ 93 115688105 : for (i = 0; i < 64; i++) { 94 113908288 : x[i] = x[i] * sns_preemph[i]; 95 : } 96 : 97 : /* Noise floor at -40dB */ 98 115688105 : for (i = 0; i < 64; i++) { 99 113908288 : sum += x[i]; 100 : } 101 : 102 1779817 : mean = sum * 0.015625; /* 1/64 */ 103 : 104 1779817 : nf = mean * 1.00e-04; 105 1779817 : nf = MAX(nf, 2.328306436538696e-10); 106 : 107 115688105 : for (i = 0; i < 64; i++) { 108 113908288 : if (x[i] < nf) { 109 11824577 : x[i] = nf; 110 : } 111 : } 112 : 113 : /* Log-domain */ 114 115688105 : for (i = 0; i < 64; i++) { 115 113908288 : x[i] = LC3_LOGTWO(x[i]) * 0.5; 116 : } 117 : 118 : /* Downsampling */ 119 30256889 : for (n = 0; n < 16; n++) { 120 28477072 : if (n == 0) { 121 1779817 : x_tmp1[0] = x[0]; 122 : 123 1779817 : move_float(&x_tmp1[1], &x[0], 5); 124 : 125 26697255 : } else if (n == 15) { 126 1779817 : move_float(x_tmp1, &x[59], 5); 127 : 128 1779817 : x_tmp1[5] = x[63]; 129 : 130 : } else { 131 24917438 : move_float(x_tmp1, &x[n * 4 - 1], ((n * 4 + 5 - 1) - (n * 4 - 1) + 1)); 132 : } 133 : 134 28477072 : sum = 0; 135 199339504 : for (i = 0; i < 6; i++) { 136 170862432 : sum += x_tmp1[i] * sns_W[i]; 137 : } 138 : 139 28477072 : gains_smooth[n] = sum; 140 28477072 : sum_gains_smooth += sum; 141 : } 142 : 143 : 144 : /* Remove mean and scaling */ 145 1779817 : mean = sum_gains_smooth / 16.0; 146 : 147 30256889 : for (i = 0; i < 16; i++) { 148 28477072 : gains[i] = sns_damping * (gains_smooth[i] - mean); 149 : } 150 : 151 : /* Smoothing */ 152 1779817 : if (smooth) { 153 6254 : gains_smooth[0] = (gains[0] + gains[1] + gains[2]) / 3.0; 154 6254 : gains_smooth[1] = (gains[0] + gains[1] + gains[2] + gains[3]) / 4.0; 155 : 156 81302 : for (i = 2; i < 14; i++) { 157 75048 : gains_smooth[i] = (gains[i - 2] + gains[i - 1] + gains[i] + gains[i + 1] + gains[i + 2]) / 5.0; 158 : } 159 : 160 6254 : gains_smooth[M - 2] = (gains[M - 4] + gains[M - 3] + gains[M - 2] + gains[M - 1]) / 4.0; 161 6254 : gains_smooth[M - 1] = (gains[M - 3] + gains[M - 2] + gains[M - 1]) / 3.0; 162 : 163 6254 : sum = 0; 164 106318 : for (i = 0; i < M; i++) { 165 100064 : sum += gains_smooth[i]; 166 : } 167 : 168 6254 : mean = sum / (LC3_FLOAT)M; 169 : 170 106318 : for (i = 0; i < M; i++) { 171 100064 : gains[i] = attdec_damping_factor * (gains_smooth[i] - mean); 172 : } 173 : } 174 1779817 : }