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 1186529 : void processPlcDampingScramblingMain_fl(LC3_INT32 *ns_seed,
15 : LC3_INT32 *pc_seed, LC3_INT32 ns_nbLostCmpt_pc,
16 : LC3_INT32 ns_nbLostCmpt, LC3_FLOAT *stabFac, LC3_FLOAT *cum_fading_slow, LC3_FLOAT *cum_fading_fast,
17 : LC3_FLOAT *spec_prev, LC3_FLOAT *spec, LC3_INT32 spec_inv_idx, LC3_INT32 yLen, LC3_INT32 bfi,
18 : LC3_INT32 frame_dms, LC3_INT32 concealMethod, LC3_INT32 pitch_present_bfi1, LC3_INT32 pitch_present_bfi2,
19 : LC3_FLOAT *cum_fflcAtten
20 : , LC3_UINT8 plc_fadeout_type
21 : )
22 : {
23 :
24 : LC3_INT32 processDampScramb;
25 :
26 1186529 : processDampScramb = 0;
27 :
28 :
29 1186529 : if ( bfi != 0 )
30 : {
31 8287 : if (concealMethod == 4 || bfi == 2)
32 : {
33 1375 : processDampScramb = 1;
34 : }
35 :
36 8287 : if (ns_nbLostCmpt == 1)
37 : {
38 1245 : *cum_fading_slow = 1;
39 1245 : *cum_fading_fast = 1;
40 1245 : *cum_fflcAtten = 1;
41 : }
42 :
43 8287 : if ( bfi == 1 )
44 : {
45 8287 : processPlcDampingScrambling_fl(spec, yLen, ns_nbLostCmpt, stabFac, processDampScramb, cum_fflcAtten,
46 : pitch_present_bfi1, frame_dms, cum_fading_slow, cum_fading_fast, ns_seed, 0
47 : , plc_fadeout_type
48 : );
49 : }
50 : else /* bfi == 2 */
51 : {
52 0 : processPlcDampingScrambling_fl(spec, yLen, ns_nbLostCmpt_pc, stabFac, processDampScramb, cum_fflcAtten,
53 : pitch_present_bfi2, frame_dms, cum_fading_slow, cum_fading_fast, pc_seed, spec_inv_idx
54 : , plc_fadeout_type
55 : );
56 0 : processPlcUpdateSpec_fl(spec_prev, spec, yLen);
57 : }
58 : }
59 1186529 : }
60 :
61 8287 : void processPlcDampingScrambling_fl(LC3_FLOAT *spec, LC3_INT32 yLen, LC3_INT32 nbLostCmpt, LC3_FLOAT *stabFac, LC3_INT32 processDampScramb,
62 : LC3_FLOAT *cum_fflcAtten, LC3_INT32 pitch_present, LC3_INT32 frame_dms, LC3_FLOAT *cum_fading_slow,
63 : LC3_FLOAT *cum_fading_fast, LC3_INT32 *seed, LC3_INT32 spec_inv_idx
64 : , LC3_UINT8 plc_fadeout_type
65 : )
66 : {
67 : LC3_INT32 plc_start_inFrames, plc_end_inFrames, plc_duration_inFrames, x, b, i, ad_ThreshFac_start;
68 : LC3_FLOAT slow, fast, linFuncStartStop, randThreshold, ad_ThreshFac_end, ad_threshFac, frame_energy, mean_energy, energThreshold, fac, m, n, fflcAtten, cum_fading_slow_local, cum_fading_fast_local;
69 :
70 8287 : frame_energy = 0;
71 :
72 8287 : slow = 0.8 + 0.2 * (*stabFac);
73 8287 : fast = 0.3 + 0.2 * (*stabFac);
74 :
75 8287 : switch (frame_dms)
76 : {
77 32 : case 25:
78 32 : slow = LC3_SQRT(LC3_SQRT(slow));
79 32 : fast = LC3_SQRT(LC3_SQRT(fast));
80 32 : break;
81 8199 : case 50:
82 8199 : slow = LC3_SQRT(slow);
83 8199 : fast = LC3_SQRT(fast);
84 8199 : break;
85 0 : case 75:
86 0 : slow = LC3_SQRT(LC3_SQRT(slow*slow*slow));
87 0 : fast = LC3_SQRT(LC3_SQRT(fast*fast*fast));
88 0 : break;
89 : }
90 :
91 8287 : if (plc_fadeout_type == 0)
92 : {
93 8239 : *cum_fading_slow = *cum_fading_slow * slow;
94 8239 : *cum_fading_fast = *cum_fading_fast * fast;
95 : }
96 :
97 8287 : if (processDampScramb == 1)
98 : {
99 1375 : if (plc_fadeout_type != 0)
100 : {
101 0 : if (nbLostCmpt < (4 * (100.0 / (LC3_FLOAT)frame_dms))) {
102 0 : cum_fading_slow_local = 1.0;
103 : }
104 0 : else if (nbLostCmpt < (8 * (100.0 / (LC3_FLOAT)frame_dms))) {
105 0 : cum_fading_slow_local = 0.9;
106 : }
107 : else {
108 0 : cum_fading_slow_local = 0.85;
109 : }
110 :
111 0 : *cum_fading_slow = *cum_fading_slow * cum_fading_slow_local;
112 0 : cum_fading_slow_local = *cum_fading_slow;
113 : }
114 : else {
115 1375 : fflcAtten = 1;
116 1375 : cum_fading_slow_local = *cum_fading_slow;
117 1375 : cum_fading_fast_local = *cum_fading_fast;
118 :
119 1375 : if (spec_inv_idx == 0)
120 : {
121 1375 : if (nbLostCmpt * frame_dms > PLC_FADEOUT_IN_MS * 10)
122 : {
123 176 : fflcAtten = 0;
124 176 : *cum_fflcAtten = 0;
125 : }
126 1199 : else if (nbLostCmpt * frame_dms > 200)
127 : {
128 400 : switch (frame_dms)
129 : {
130 0 : case 25: fflcAtten = PLC34_ATTEN_FAC_025; break;
131 400 : case 50: fflcAtten = PLC34_ATTEN_FAC_050; break;
132 0 : case 75: fflcAtten = PLC34_ATTEN_FAC_075; break;
133 0 : case 100: fflcAtten = PLC34_ATTEN_FAC_100; break;
134 : }
135 799 : }
136 :
137 :
138 1375 : *cum_fflcAtten = *cum_fflcAtten * fflcAtten;
139 1375 : cum_fading_slow_local = *cum_fading_slow * *cum_fflcAtten;
140 1375 : cum_fading_fast_local = *cum_fading_fast * *cum_fflcAtten;
141 : }
142 :
143 1375 : if (pitch_present == 0)
144 : {
145 1375 : plc_start_inFrames = 1;
146 : }
147 : else {
148 0 : plc_start_inFrames = floor(PLC4_TRANSIT_START_IN_MS / (frame_dms / 10.0));
149 : }
150 :
151 1375 : plc_end_inFrames = floor(PLC4_TRANSIT_END_IN_MS / (frame_dms / 10.0));
152 1375 : plc_duration_inFrames = plc_end_inFrames - plc_start_inFrames;
153 :
154 1375 : if (nbLostCmpt <= plc_start_inFrames)
155 : {
156 229 : linFuncStartStop = 1;
157 : }
158 1146 : else if (nbLostCmpt >= plc_end_inFrames)
159 : {
160 204 : linFuncStartStop = 0;
161 : }
162 : else {
163 942 : x = nbLostCmpt;
164 942 : m = -1.0 / plc_duration_inFrames;
165 942 : b = -plc_end_inFrames;
166 942 : linFuncStartStop = m * (x + b);
167 : }
168 :
169 1375 : randThreshold = -32768 * linFuncStartStop;
170 : }
171 :
172 281815 : for (i = spec_inv_idx; i < yLen; i++)
173 : {
174 280440 : *seed = 16831 + *seed * 12821;
175 :
176 280440 : *seed = (LC3_INT16)(*seed);
177 :
178 280440 : if (*seed < 0)
179 : {
180 138196 : if (plc_fadeout_type != 0 || pitch_present == 0 || *seed < randThreshold )
181 : {
182 138196 : spec[i] = -spec[i];
183 : }
184 : }
185 : }
186 :
187 1375 : if (plc_fadeout_type == 0)
188 : {
189 1375 : ad_ThreshFac_start = 10;
190 1375 : ad_ThreshFac_end = 1.2;
191 1375 : ad_threshFac = (ad_ThreshFac_start - ad_ThreshFac_end) * linFuncStartStop + ad_ThreshFac_end;
192 :
193 1375 : if (spec_inv_idx < yLen)
194 : {
195 281815 : for (i = spec_inv_idx; i < yLen; i++)
196 : {
197 280440 : frame_energy = frame_energy + (spec[i] * spec[i]);
198 : }
199 :
200 1375 : mean_energy = frame_energy * 1 / (yLen - spec_inv_idx);
201 : }
202 : else
203 : {
204 0 : mean_energy = 0;
205 : }
206 :
207 1375 : energThreshold = LC3_SQRT(ad_threshFac * mean_energy);
208 1375 : fac = (cum_fading_slow_local - cum_fading_fast_local) * energThreshold;
209 : }
210 :
211 281815 : for (i = spec_inv_idx; i < yLen; i++)
212 : {
213 280440 : if (plc_fadeout_type != 0 || LC3_FABS(spec[i]) < energThreshold )
214 : {
215 247254 : m = cum_fading_slow_local;
216 247254 : n = 0;
217 : }
218 : else
219 : {
220 33186 : m = cum_fading_fast_local;
221 :
222 33186 : if (spec[i] > 0)
223 : {
224 4376 : n = fac;
225 : }
226 28810 : else if (spec[i] == 0)
227 : {
228 24440 : n = 0;
229 : }
230 : else
231 : {
232 4370 : n = -fac;
233 : }
234 : }
235 :
236 280440 : spec[i] = m * spec[i] + n;
237 : }
238 : }
239 8287 : }
240 :
|