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 "functions.h"
11 : #include <stdio.h> // ToDo: probably to be removed
12 :
13 0 : static void Enc_LC3PLUS_Channel(LC3PLUS_Enc *encoder, int channel, int bits_per_sample, Word32 *s_in, UWord8 *bytes,
14 : Word8 *scratchBuffer, int bfi_ext)
15 : {
16 : #ifdef ENABLE_HR_MODE
17 : Dyn_Mem_Deluxe_In(Word16 d_fx_exp;
18 : Word16 gain_e, gain, quantizedGain, quantizedGainMin;
19 : Word16 ener_fx_exp;
20 : Word16 pitch, normcorr;
21 : Word16 ltpf_bits;
22 : Word16 tns_numfilters;
23 : Word16 lsbMode, lastnz, BW_cutoff_idx;
24 : Word16 gainChange, fac_ns_idx;
25 : Word16 nBits, numResBits;
26 : Word16 bp_side, mask_side;
27 : Word16 s_12k8_len;
28 : Word16 b_left;
29 : Word32 * L_scf_idx;
30 : Word32 * d_fx, *ener_fx;
31 : Word16 * s_12k8, *int_scf_fx_exp, tns_order[TNS_NUMFILTERS_MAX], *indexes;
32 : Word32 * q_d_fx24;
33 : Word16 * scf;
34 : Word16 * codingdata;
35 : Word32 * scf_q, *int_scf_fx;
36 : Word32 * s_in_scaled;
37 : Word16 * s_in_scaled_lp;
38 : UWord8 * resBits;
39 : Word16 ltpf_idx[3];
40 : EncSetup * h_EncSetup;
41 : Word8 * currentScratch;
42 : Word16 hrmode;
43 : );
44 : #else
45 : Dyn_Mem_Deluxe_In(Word16 d_fx_exp; Word16 gain_e, gain, quantizedGain, quantizedGainMin; Word16 ener_fx_exp;
46 : Word16 pitch, normcorr; Word16 ltpf_bits; Word16 tns_numfilters;
47 : Word16 lsbMode, lastnz, BW_cutoff_idx; Word16 gainChange, fac_ns_idx; Word16 nBits, numResBits;
48 : Word16 bp_side, mask_side; Word16 s_12k8_len; Word16 b_left;
49 :
50 : Word32 * L_scf_idx; Word32 * d_fx, *ener_fx;
51 : Word16 * s_12k8, *int_scf_fx_exp, *q_d_fx16, *int_scf_fx, tns_order[TNS_NUMFILTERS_MAX], *indexes;
52 : Word16 * scf, *scf_q; Word16 * codingdata; Word16 * s_in_scaled; UWord8 * resBits;
53 : Word8 * currentScratch; Word16 ltpf_idx[3]; EncSetup * h_EncSetup;);
54 : #endif /* ENABLE_HR_MODE */
55 :
56 0 : h_EncSetup = encoder->channel_setup[channel];
57 :
58 : #ifdef ENABLE_HR_MODE
59 0 : hrmode = encoder->hrmode;
60 : #endif
61 :
62 : #ifdef WMOPS
63 : push_wmops("Encoder");
64 : #endif
65 :
66 : /* BUFFER INITIALISATION. Some buffers may overlap since they are not used in the whole encoding process */
67 0 : d_fx = scratchAlign(scratchBuffer, 0); /* Size = 4 * MAX_LEN bytes */
68 0 : L_scf_idx = scratchAlign(
69 : d_fx, sizeof(*d_fx) * s_max(80, encoder->frame_length)); /* Size = 4 * SCF_MAX_PARAM -> aligned to 32 bytes */
70 0 : indexes = scratchAlign(L_scf_idx,
71 : sizeof(*L_scf_idx) * SCF_MAX_PARAM); /* Size = 2 * TNS_NUMFILTERS_MAX * MAXLAG = 32 bytes */
72 :
73 : #ifdef ENABLE_HR_MODE
74 0 : q_d_fx24 = scratchAlign(indexes, sizeof(*indexes) * (TNS_NUMFILTERS_MAX * MAXLAG));
75 : #else
76 : q_d_fx16 = scratchAlign(indexes, sizeof(*indexes) * (TNS_NUMFILTERS_MAX * MAXLAG)); /* Size = 2 * MAX_LEN bytes */
77 : #endif /* ENABLE_HR_MODE */
78 :
79 : #ifdef ENABLE_HR_MODE
80 0 : codingdata =
81 0 : scratchAlign(q_d_fx24, sizeof(*q_d_fx24) * s_max(80, encoder->frame_length)); /* Size = 3 * MAX_LEN bytes */
82 : #else
83 : codingdata =
84 : scratchAlign(q_d_fx16, sizeof(*q_d_fx16) * s_max(80, encoder->frame_length)); /* Size = 3 * MAX_LEN bytes */
85 : #endif
86 :
87 : #ifdef ENABLE_HR_MODE
88 0 : ener_fx = scratchAlign(q_d_fx24, 0); /* Size = 4 * MAX_BANDS_NUMBER = 256 bytes */
89 0 : s_in_scaled = scratchAlign(q_d_fx24, 0); /* Size = 2 * MAX_LEN bytes */
90 : #else
91 : ener_fx = scratchAlign(q_d_fx16, 0); /* Size = 4 * MAX_BANDS_NUMBER = 256 bytes */
92 : s_in_scaled = scratchAlign(q_d_fx16, 0); /* Size = 2 * MAX_LEN bytes */
93 : #endif
94 :
95 : #ifdef ENABLE_HR_MODE
96 0 : s_in_scaled_lp = (Word16 *)s_in_scaled;
97 : #endif
98 :
99 : #ifdef ENABLE_HR_MODE
100 : /* allocate memory for residual bits */
101 0 : if (encoder->hrmode)
102 : {
103 0 : resBits = scratchAlign(codingdata, sizeof(*codingdata) * (3 * s_max(80, encoder->frame_length) / 2));
104 : }
105 : else
106 : #endif /* #ifdef ENABLE_HR_MODE */
107 : {
108 0 : resBits = scratchAlign(codingdata,
109 : sizeof(*codingdata) * (3 * s_max(80, encoder->frame_length) / 2)); /* Size = MAX_LEN bytes */
110 : }
111 :
112 : {
113 : #ifdef ENABLE_HR_MODE
114 0 : currentScratch =
115 0 : scratchAlign(resBits, sizeof(*resBits) * MAX_RESBITS_LEN); /* Size = 4 * MAX_LEN */
116 : #else
117 : currentScratch =
118 : scratchAlign(resBits, sizeof(*resBits) * s_max(80, encoder->frame_length)); /* Size = 4 * MAX_LEN */
119 : #endif /* #ifdef ENABLE_HR_MODE */
120 : }
121 :
122 0 : s_12k8 = scratchAlign(
123 : s_in_scaled,
124 : sizeof(*s_in_scaled) *
125 : s_max(80, encoder->frame_length)); /* Size = 2 * (LEN_12K8 + 1) = 258 bytes -> aligned to 288 bytes */
126 0 : scf_q = scratchAlign(ener_fx, sizeof(*ener_fx) * MAX_BANDS_NUMBER); /* Size = 2 * M */
127 0 : scf = scratchAlign(scf_q, sizeof(*scf_q) * M); /* Size = 2 * M */
128 0 : int_scf_fx = scratchAlign(scf, sizeof(*scf) * M); /* Size = 2 * MAX_BANDS_NUMBER = 128 bytes */
129 0 : int_scf_fx_exp =
130 0 : scratchAlign(int_scf_fx, sizeof(*int_scf_fx) * MAX_BANDS_NUMBER); /* Size = 2 * MAX_BANDS_NUMBER = 128 bytes */
131 :
132 : /* Scale 24-bit input data */
133 0 : IF (sub(bits_per_sample, 24) == 0)
134 : {
135 : #ifdef WMOPS
136 : push_wmops("Scale_signal24");
137 : #endif
138 0 : scale_signal24_fx(s_in, s_in_scaled, &h_EncSetup->x_exp, h_EncSetup->stEnc_mdct_mem,
139 0 : encoder->stEnc_mdct_mem_len, h_EncSetup->r12k8_mem_in, encoder->r12k8_mem_in_len,
140 0 : h_EncSetup->r12k8_mem_50, h_EncSetup->r12k8_mem_out, encoder->r12k8_mem_out_len,
141 0 : h_EncSetup->mdct_mem32, encoder->frame_length, h_EncSetup->resamp_mem32,
142 0 : h_EncSetup->olpa_mem_s12k8, &h_EncSetup->resamp_exp);
143 : #ifdef WMOPS
144 : pop_wmops();
145 : #endif
146 : }
147 : ELSE
148 : {
149 : #ifdef ENABLE_HR_MODE
150 0 : Word16 *ip_buf = (Word16*)s_in;
151 : Word32 i;
152 0 : FOR(i = 0; i < encoder->frame_length; i++)
153 : {
154 0 : s_in_scaled[i] = L_deposit_h(ip_buf[i]);
155 : }
156 0 : h_EncSetup->x_exp = 15; move16();
157 : #else
158 : memcpy(s_in_scaled, s_in, encoder->frame_length * sizeof(*s_in_scaled));
159 : #endif
160 : }
161 :
162 : #ifdef WMOPS
163 : push_wmops("Mdct");
164 : #endif
165 :
166 : /* currentScratch Size = 4 * MAX_LEN */
167 0 : processMdct_fx(s_in_scaled, h_EncSetup->x_exp, encoder->frame_length,
168 : #ifdef ENABLE_HR_MODE
169 : hrmode,
170 : #endif
171 0 : encoder->W_fx, encoder->W_size,
172 0 : h_EncSetup->stEnc_mdct_mem, encoder->stEnc_mdct_mem_len, d_fx, &d_fx_exp, currentScratch);
173 : #ifdef WMOPS
174 : pop_wmops();
175 : #endif
176 :
177 : /* begin s_12k8 */
178 : #ifdef WMOPS
179 : push_wmops("Resamp12k8");
180 : #endif
181 : /* currentScratch Size = 2.25 * MAX_LEN bytes */
182 : #ifdef ENABLE_HR_MODE
183 0 : downshift_w32_arr(s_in_scaled, s_in_scaled_lp, 16, encoder->frame_length); /* s_in_scaled is no longer required */
184 :
185 0 : process_resamp12k8_fx(s_in_scaled_lp, encoder->frame_length, h_EncSetup->r12k8_mem_in, encoder->r12k8_mem_in_len,
186 0 : h_EncSetup->r12k8_mem_50, h_EncSetup->r12k8_mem_out, encoder->r12k8_mem_out_len, s_12k8,
187 0 : &s_12k8_len, encoder->fs_idx, encoder->frame_dms, currentScratch
188 : , bits_per_sample
189 : );
190 : #else
191 : process_resamp12k8_fx(s_in_scaled, encoder->frame_length, h_EncSetup->r12k8_mem_in, encoder->r12k8_mem_in_len,
192 : h_EncSetup->r12k8_mem_50, h_EncSetup->r12k8_mem_out, encoder->r12k8_mem_out_len, s_12k8,
193 : &s_12k8_len, encoder->fs_idx, encoder->frame_dms, currentScratch
194 : , bits_per_sample
195 : );
196 : #endif /* ENABLE_HR_MODE */
197 : #ifdef WMOPS
198 : pop_wmops();
199 : #endif
200 :
201 : #ifdef WMOPS
202 : push_wmops("Olpa");
203 : #endif
204 : /* currentScratch Size = 392 bytes */
205 0 : process_olpa_fx(&h_EncSetup->olpa_mem_s6k4_exp, h_EncSetup->olpa_mem_s12k8, h_EncSetup->olpa_mem_s6k4, &pitch,
206 : s_12k8, s_12k8_len, &normcorr, &h_EncSetup->olpa_mem_pitch,
207 : &h_EncSetup->pitch_flag,
208 0 : h_EncSetup->resamp_exp, encoder->frame_dms, currentScratch);
209 : #ifdef WMOPS
210 : pop_wmops();
211 : #endif
212 :
213 : #ifdef WMOPS
214 : push_wmops("LtpfEnc");
215 : #endif
216 : /* currentScratch Size = 512 bytes */
217 0 : process_ltpf_coder_fx(<pf_bits, pitch, h_EncSetup->ltpf_enable, &h_EncSetup->ltpf_mem_in_exp,
218 0 : h_EncSetup->ltpf_mem_in, encoder->ltpf_mem_in_len, ltpf_idx, s_12k8, s_12k8_len,
219 : &h_EncSetup->ltpf_mem_normcorr, &h_EncSetup->ltpf_mem_mem_normcorr, normcorr,
220 0 : &h_EncSetup->ltpf_mem_ltpf_on, &h_EncSetup->ltpf_mem_pitch, h_EncSetup->resamp_exp,
221 0 : encoder->frame_dms, currentScratch,
222 0 : encoder->hrmode
223 : );
224 : #ifdef WMOPS
225 : pop_wmops();
226 : #endif
227 :
228 : /* end s_12k8 */
229 : #ifdef WMOPS
230 : push_wmops("AttackDetector");
231 : #endif
232 : /* currentScratch Size = ??? bytes */
233 : #ifdef ENABLE_HR_MODE
234 0 : attack_detector_fx(encoder, h_EncSetup, s_in_scaled_lp, sub(h_EncSetup->x_exp, 15), currentScratch);
235 : #else
236 : attack_detector_fx(encoder, h_EncSetup, s_in_scaled, sub(h_EncSetup->x_exp, 15), currentScratch);
237 : #endif
238 : #ifdef WMOPS
239 : pop_wmops();
240 : #endif
241 :
242 : /* begin ener_fx */
243 : #ifdef WMOPS
244 : push_wmops("PerBandEnergy");
245 : #endif
246 : /* currentScratch Size = 160 bytes */
247 0 : processPerBandEnergy_fx(ener_fx, &ener_fx_exp, d_fx, d_fx_exp, encoder->bands_offset, encoder->fs_idx,
248 0 : encoder->bands_number, 0, encoder->frame_dms, currentScratch
249 : #ifdef ENABLE_HR_MODE
250 0 : , encoder->hrmode
251 : #endif
252 : );
253 : #ifdef WMOPS
254 : pop_wmops();
255 : #endif
256 :
257 : #ifdef WMOPS
258 : push_wmops("Near Nyquist Detector");
259 : #endif
260 : /* Near Nyquist Detector */
261 0 : processNearNyquistdetector_fx(&encoder->near_nyquist_flag, encoder->fs_idx, encoder->near_nyquist_index,
262 0 : encoder->bands_number, ener_fx, ener_fx_exp
263 : #ifdef ENABLE_HR_MODE
264 0 : , encoder->frame_dms, encoder->hrmode );
265 : #else
266 : );
267 : #endif
268 : /* Disable LTPF if nyquist detector triggers */
269 0 : IF (encoder->near_nyquist_flag != 0 || sub(h_EncSetup->lfe, 1) == 0)
270 : {
271 0 : h_EncSetup->ltpf_mem_ltpf_on = 0; move16();
272 0 : ltpf_idx[1] = 0; move16();
273 : }
274 : #ifdef WMOPS
275 : pop_wmops();
276 : #endif
277 : #ifdef WMOPS
278 : push_wmops("BW Cutoff-Detection");
279 : #endif
280 0 : IF (h_EncSetup->lfe == 0)
281 : {
282 : #ifdef ENABLE_HR_MODE
283 : /* No BW Cutoff for 8 kHz and 96 kHz */
284 0 : IF (encoder->fs_idx > 0 && encoder->hrmode == 0 && encoder->bw_ctrl_active == 0)
285 : {
286 : #else /* ENABLE_HR_MODE */
287 : IF (encoder->fs_idx > 0 && encoder->bw_ctrl_active == 0)
288 : {
289 : #endif /* ENABLE_HR_MODE */
290 0 : processDetectCutoffWarped_fx(&BW_cutoff_idx, ener_fx, ener_fx_exp, encoder->fs_idx, encoder->frame_dms);
291 : }
292 : ELSE
293 : {
294 0 : BW_cutoff_idx = encoder->fs_idx;
295 0 : move16();
296 : }
297 : }
298 : ELSE
299 : {
300 0 : BW_cutoff_idx = 0;
301 : }
302 : #ifdef WMOPS
303 : pop_wmops();
304 : #endif
305 :
306 : #ifdef WMOPS
307 : push_wmops("SnsCompScf");
308 : #endif
309 :
310 :
311 : /* currentScratch Size = 512 bytes */
312 0 : processSnsComputeScf_fx(ener_fx, ener_fx_exp, encoder->fs_idx, encoder->bands_number, scf,
313 0 : h_EncSetup->attdec_detected, encoder->attdec_damping, currentScratch, encoder->sns_damping
314 : );
315 : #ifdef WMOPS
316 : pop_wmops();
317 : #endif
318 :
319 : #ifdef WMOPS
320 : push_wmops("SnsQuantScfEnc");
321 : #endif
322 : /* currentScratch Size = 500 bytes */
323 :
324 0 : processSnsQuantizeScfEncoder_fx(scf, L_scf_idx, scf_q, currentScratch);
325 : #ifdef WMOPS
326 : pop_wmops();
327 : #endif
328 :
329 : #ifdef WMOPS
330 : push_wmops("SnsInterpScfEnc");
331 : #endif
332 : /* currentScratch Size = 128 bytes */
333 0 : processSnsInterpolateScf_fx(scf_q, int_scf_fx, int_scf_fx_exp, 1, encoder->bands_number, currentScratch);
334 : #ifdef WMOPS
335 : pop_wmops();
336 : #endif
337 :
338 : #ifdef WMOPS
339 : push_wmops("Mdct shaping_enc");
340 : #endif
341 0 : processMdctShaping_fx(d_fx, int_scf_fx, int_scf_fx_exp, encoder->bands_offset, encoder->bands_number);
342 :
343 : #ifdef WMOPS
344 : pop_wmops();
345 : #endif
346 : /* end int_scf_fx_exp */
347 : #ifdef WMOPS
348 : push_wmops("BandwidthControl_enc");
349 : #endif
350 0 : if (encoder->bandwidth < L_shr_pos(encoder->fs, 1))
351 : {
352 0 : process_cutoff_bandwidth(d_fx, encoder->yLen, encoder->bw_ctrl_cutoff_bin);
353 0 : BW_cutoff_idx = s_min(BW_cutoff_idx, encoder->bw_index);
354 : }
355 : #ifdef WMOPS
356 : pop_wmops();
357 : #endif
358 : #ifdef WMOPS
359 : push_wmops("Tns_enc");
360 : #endif
361 : /* currentScratch Size = 2 * MAX_LEN + 220 */
362 :
363 0 : IF (h_EncSetup->lfe == 0)
364 : {
365 0 : processTnsCoder_fx(&(h_EncSetup->tns_bits), indexes, d_fx, BW_cutoff_idx, tns_order, &tns_numfilters,
366 0 : h_EncSetup->enable_lpc_weighting, encoder->nSubdivisions, encoder->frame_dms,
367 0 : encoder->frame_length, currentScratch
368 : #ifdef ENABLE_HR_MODE
369 0 : , encoder->hrmode
370 : #endif
371 0 : , encoder->near_nyquist_flag
372 : );
373 : }
374 : ELSE
375 : {
376 0 : tns_numfilters = 1;
377 0 : move16();
378 0 : tns_order[0] = 0;
379 0 : move16();
380 0 : h_EncSetup->tns_bits = tns_numfilters;
381 0 : move16();
382 : }
383 : #ifdef WMOPS
384 : pop_wmops();
385 : #endif
386 :
387 : #ifdef WMOPS
388 : push_wmops("Est. Global Gain");
389 : #endif
390 : /* currentScratch Size = 4 * MAX_LEN bytes */
391 0 : h_EncSetup->targetBitsQuant = sub(h_EncSetup->targetBitsInit, add(h_EncSetup->tns_bits, ltpf_bits));
392 :
393 0 : test();
394 0 : IF (h_EncSetup->targetBitsQuant < 0 && sub(ltpf_bits, 1) > 0)
395 : {
396 : /* Disable LTPF */
397 0 : h_EncSetup->ltpf_mem_ltpf_on = 0; move16();
398 0 : ltpf_idx[1] = 0; move16();
399 0 : ltpf_bits = 1; move16();
400 0 : h_EncSetup->targetBitsQuant = sub(h_EncSetup->targetBitsInit, add(h_EncSetup->tns_bits, ltpf_bits));
401 : }
402 :
403 : #ifdef ENABLE_HR_MODE
404 : Word32 gain32;
405 : #endif
406 :
407 0 : processEstimateGlobalGain_fx(d_fx, d_fx_exp, encoder->yLen, h_EncSetup->targetBitsQuant,
408 : #ifdef ENABLE_HR_MODE
409 : &gain32,
410 : #else
411 : &gain,
412 : #endif
413 : &gain_e,
414 0 : &quantizedGain, &quantizedGainMin, h_EncSetup->quantizedGainOff,
415 0 : &h_EncSetup->targetBitsOff, &h_EncSetup->mem_targetBits, h_EncSetup->mem_specBits,
416 : currentScratch
417 : #ifdef ENABLE_HR_MODE
418 0 : , encoder->hrmode, h_EncSetup->regBits, encoder->frame_dms
419 : #endif
420 : );
421 : #ifdef WMOPS
422 : pop_wmops();
423 : #endif
424 : /* begin q_d_fx16 */
425 :
426 : #ifdef WMOPS
427 : push_wmops("Quant. 1");
428 : #endif
429 : #ifdef ENABLE_HR_MODE
430 0 : processQuantizeSpec_fx(d_fx, d_fx_exp, gain32, gain_e, q_d_fx24, encoder->yLen, h_EncSetup->targetBitsQuant,
431 0 : h_EncSetup->targetBitsAri, &h_EncSetup->mem_specBits, &nBits, encoder->fs_idx, &lastnz,
432 0 : codingdata, &lsbMode, -1, encoder->hrmode);
433 :
434 : #else
435 : processQuantizeSpec_fx(d_fx, d_fx_exp, gain, gain_e, q_d_fx16, encoder->yLen, h_EncSetup->targetBitsQuant,
436 : h_EncSetup->targetBitsAri, &h_EncSetup->mem_specBits, &nBits, encoder->fs_idx, &lastnz,
437 : codingdata, &lsbMode, -1);
438 : #endif /* ENABLE_HR_MODE */
439 : #ifdef WMOPS
440 : pop_wmops();
441 : #endif
442 :
443 : #ifdef WMOPS
444 : push_wmops("Adj. Global Gain");
445 : #endif
446 : #ifdef ENABLE_HR_MODE
447 : //gain32 = L_shl_pos((Word32)gain, 16);
448 0 : processAdjustGlobalGain_fx(&quantizedGain, quantizedGainMin, h_EncSetup->quantizedGainOff, &gain32, &gain_e,
449 0 : h_EncSetup->targetBitsQuant, h_EncSetup->mem_specBits, &gainChange, encoder->fs_idx
450 0 : , encoder->hrmode, encoder->frame_dms
451 : );
452 0 : gain = round_fx(gain32);
453 : #else
454 : processAdjustGlobalGain_fx(&quantizedGain, quantizedGainMin, h_EncSetup->quantizedGainOff, &gain, &gain_e,
455 : h_EncSetup->targetBitsQuant, h_EncSetup->mem_specBits, &gainChange, encoder->fs_idx);
456 : #endif /* ENABLE_HR_MODE */
457 : #ifdef WMOPS
458 : pop_wmops();
459 : #endif
460 :
461 : #ifdef WMOPS
462 : push_wmops("Quant. 2");
463 : #endif
464 0 : IF (sub(gainChange, 1) == 0)
465 : {
466 : #ifdef ENABLE_HR_MODE
467 0 : processQuantizeSpec_fx(d_fx, d_fx_exp, gain32, gain_e, q_d_fx24, encoder->yLen, h_EncSetup->targetBitsQuant,
468 0 : h_EncSetup->targetBitsAri, NULL, &nBits, encoder->fs_idx, &lastnz, codingdata, &lsbMode,
469 0 : 0, encoder->hrmode);
470 : #else
471 : processQuantizeSpec_fx(d_fx, d_fx_exp, gain, gain_e, q_d_fx16, encoder->yLen, h_EncSetup->targetBitsQuant,
472 : h_EncSetup->targetBitsAri, NULL, &nBits, encoder->fs_idx, &lastnz, codingdata, &lsbMode,
473 : 0);
474 : #endif /* ENABLE_HR_MODE */
475 : }
476 : #ifdef WMOPS
477 : pop_wmops();
478 : #endif
479 :
480 : #ifdef WMOPS
481 : push_wmops("Res. Cod.");
482 : #endif
483 0 : IF (lsbMode == 0)
484 : {
485 0 : processResidualCoding_fx(d_fx_exp, d_fx,
486 : #ifdef ENABLE_HR_MODE
487 : q_d_fx24,
488 : #else
489 : q_d_fx16,
490 : #endif
491 : #ifdef ENABLE_HR_MODE
492 : gain32,
493 : #else
494 : gain,
495 : #endif
496 0 : gain_e, encoder->yLen, h_EncSetup->targetBitsQuant, nBits, resBits, &numResBits
497 : #ifdef ENABLE_HR_MODE
498 0 : , encoder->hrmode
499 : #endif
500 : );
501 : }
502 : ELSE
503 : {
504 0 : numResBits = 0;
505 0 : move16();
506 : }
507 : #ifdef WMOPS
508 : pop_wmops();
509 : #endif
510 :
511 : #ifdef WMOPS
512 : push_wmops("Noise fac");
513 : #endif
514 : /* currentScratch Size = 2 * MAX_LEN bytes */
515 0 : IF (h_EncSetup->lfe == 0)
516 : {
517 0 : processNoiseFactor_fx(&fac_ns_idx, d_fx_exp, d_fx,
518 : #ifdef ENABLE_HR_MODE
519 : q_d_fx24,
520 : #else
521 : q_d_fx16,
522 : #endif
523 0 : gain, gain_e, BW_cutoff_idx, encoder->frame_dms, h_EncSetup->targetBytes, currentScratch
524 : #ifdef ENABLE_HR_MODE
525 0 : , encoder->hrmode
526 : #endif
527 : );
528 : }
529 : ELSE
530 : {
531 0 : fac_ns_idx = 7;
532 0 : move16();
533 : }
534 : #ifdef WMOPS
535 : pop_wmops();
536 : #endif
537 :
538 : #ifdef WMOPS
539 : push_wmops("Entropy cod");
540 : #endif
541 0 : processEncoderEntropy(bytes, &bp_side, &mask_side, h_EncSetup->targetBitsAri, h_EncSetup->targetBytes,
542 0 : encoder->yLen, encoder->BW_cutoff_bits, tns_numfilters, lsbMode, lastnz, tns_order,
543 0 : fac_ns_idx, quantizedGain, BW_cutoff_idx, ltpf_idx, L_scf_idx, bfi_ext, encoder->fs_idx);
544 : #ifdef WMOPS
545 : pop_wmops();
546 : #endif
547 :
548 : #ifdef WMOPS
549 : push_wmops("Ari cod");
550 : #endif
551 0 : processAriEncoder_fx(bytes, bp_side, mask_side, h_EncSetup->targetBitsAri,
552 : #ifdef ENABLE_HR_MODE
553 : q_d_fx24,
554 : #else
555 : q_d_fx16,
556 : #endif
557 : tns_order, tns_numfilters, indexes, lastnz, codingdata, resBits, numResBits, lsbMode,
558 0 : h_EncSetup->enable_lpc_weighting, currentScratch);
559 : #ifdef WMOPS
560 : pop_wmops();
561 : #endif
562 :
563 : #ifdef WMOPS
564 : push_wmops("Reorder Bitstream Enc");
565 : #endif
566 0 : test();
567 0 : IF (encoder->combined_channel_coding == 0 && h_EncSetup->n_pc > 0)
568 : {
569 : #ifdef WMOPS
570 : push_wmops("Reorder Ari dec");
571 : #endif
572 :
573 : #ifdef ENABLE_HR_MODE
574 0 : Word32 *xbuf = (Word32 *) scratchAlign(scratchBuffer, 0);
575 :
576 0 : processAriDecoder_fx(bytes, &bp_side, &mask_side, h_EncSetup->total_bits, encoder->yLen, encoder->fs_idx,
577 0 : h_EncSetup->enable_lpc_weighting, tns_numfilters, lsbMode, lastnz, &gain, tns_order,
578 0 : fac_ns_idx, quantizedGain, encoder->frame_dms, h_EncSetup->n_pc, 0,
579 0 : shr_pos(h_EncSetup->total_bits, 3), 1, &gain, &b_left, &gain,
580 : xbuf,
581 : &gain, resBits, indexes, &gain,
582 : currentScratch
583 0 : , encoder->hrmode
584 : );
585 : #else
586 :
587 : processAriDecoder_fx(bytes, &bp_side, &mask_side, h_EncSetup->total_bits, encoder->yLen, encoder->fs_idx,
588 : h_EncSetup->enable_lpc_weighting, tns_numfilters, lsbMode, lastnz, &gain, tns_order,
589 : fac_ns_idx, quantizedGain, encoder->frame_dms, h_EncSetup->n_pc, 0,
590 : shr_pos(h_EncSetup->total_bits, 3), 1, &gain, &b_left, &gain,
591 : codingdata,
592 : &gain, resBits, indexes, &gain,
593 : currentScratch
594 : );
595 : #endif
596 :
597 : #ifdef WMOPS
598 : pop_wmops(); /* Ari dec */
599 : #endif
600 0 : processReorderBitstream_fx(bytes, h_EncSetup->n_pccw, h_EncSetup->n_pc, b_left, currentScratch);
601 : }
602 : #ifdef WMOPS
603 : pop_wmops();
604 : #endif
605 :
606 : /* end q_d_fx16 */
607 : #ifdef WMOPS
608 : pop_wmops();
609 : #endif
610 :
611 : Dyn_Mem_Deluxe_Out();
612 0 : }
613 :
614 0 : int Enc_LC3PLUS(LC3PLUS_Enc *encoder, void **input, int bits_per_sample, UWord8 *output, void *scratch, Word16 bfi_ext)
615 : {
616 0 : int ch = 0, output_size = 0;
617 0 : int input_size = 0;
618 0 : int totalBytes = (Word32)encoder->bitrate * encoder->frame_length / (8 * encoder->fs_in);
619 : int output_size2;
620 :
621 0 : UWord8 *lc3buf = output;
622 :
623 0 : for (ch = 0; ch < encoder->channels; ch++)
624 : {
625 0 : Enc_LC3PLUS_Channel(encoder, ch, bits_per_sample, input[ch], lc3buf, scratch, bfi_ext);
626 0 : if (encoder->epmode && encoder->combined_channel_coding == 0)
627 : {
628 0 : output_size2 = totalBytes / encoder->channels + (ch < (totalBytes % encoder->channels));
629 : #ifdef WMOPS
630 : push_wmops("fec_enc");
631 : #endif
632 :
633 0 : fec_encoder(encoder->epmode, encoder->epmr, lc3buf, encoder->channel_setup[ch]->targetBytes, output_size2,
634 0 : encoder->channel_setup[ch]->n_pccw, scratch);
635 :
636 : #ifdef WMOPS
637 : pop_wmops();
638 : #endif
639 :
640 0 : lc3buf += output_size2;
641 0 : output_size += output_size2;
642 : }
643 : else
644 : {
645 0 : lc3buf += encoder->channel_setup[ch]->targetBytes;
646 0 : output_size += encoder->channel_setup[ch]->targetBytes;
647 : }
648 : }
649 :
650 0 : if (encoder->epmode > 0 && encoder->combined_channel_coding)
651 : {
652 0 : input_size = output_size;
653 0 : output_size = (Word32)encoder->bitrate * encoder->frame_length / (8 * encoder->fs_in);
654 : #ifdef WMOPS
655 : push_wmops("fec_enc");
656 : #endif
657 :
658 0 : fec_encoder(encoder->epmode, encoder->epmr, output, input_size, output_size, encoder->channel_setup[0]->n_pccw,
659 : scratch);
660 :
661 : #ifdef WMOPS
662 : pop_wmops();
663 : #endif
664 : }
665 :
666 0 : return output_size;
667 : }
668 :
|