Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : #include <stdint.h>
6 : #include "options.h"
7 : //#include "prot_fx.h"
8 : #include "cnst.h" /* Common constants */
9 : #include "rom_com.h" /* Common constants */
10 : #include "prot_fx.h" /* Function prototypes */
11 : #include "prot_fx_enc.h" /* Function prototypes */
12 : #include "basop_util.h" /* Function prototypes */
13 : #include "prot_fx_enc.h" /* Function prototypes */
14 :
15 : /*-------------------------------------------------------------------*
16 : * enc_acelp_tcx_main_fx()
17 : *
18 : * encoder function for coding ACELP/TCX
19 : *--------------------------------------------------------------------*/
20 1266 : void enc_acelp_tcx_main_fx(
21 : const Word16 new_samples[], /* i : new samples Q15*/
22 : Encoder_State *st, /* i/o: encoder state structure */
23 : Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/
24 : const Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/
25 : const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame Q15*/
26 : Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q_new*/
27 : Word16 *voice_factors, /* o : voicing factors Q15*/
28 : Word16 pitch_buf[], /* o : floating pitch for each subframe Q6*/
29 : Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/
30 : Word16 *Q_new,
31 : Word16 *shift )
32 : {
33 : Word16 old_bwe_exc[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */
34 : Word16 *ptr_bwe_exc;
35 1266 : TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD;
36 :
37 1266 : ptr_bwe_exc = old_bwe_exc + PIT16k_MAX * 2;
38 :
39 1266 : IF( EQ_16( st->last_core, ACELP_CORE ) )
40 : {
41 613 : set16_fx( old_bwe_exc + PIT16k_MAX * 2, 0, ( ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 );
42 613 : Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); /*Q_exc*/
43 : }
44 : ELSE
45 : {
46 653 : set16_fx( old_bwe_exc, 0, ( ( L_FRAME16k + 1 ) + L_SUBFR16k + PIT16k_MAX ) * 2 );
47 : }
48 :
49 1266 : if ( st->hPlcExt )
50 : { /* PLC: [Guided ACELP PLC] */
51 1266 : gPLC_encInfo_fx( st->hPlcExt, st->total_brate, st->bwidth, st->clas, st->coder_type );
52 : }
53 1266 : IF( s_and( st->core_brate != FRAME_NO_DATA, st->core_brate != SID_2k40 ) )
54 : {
55 :
56 : /* Run Core Coder */
57 1266 : IF( st->tcxonly == 0 )
58 : {
59 1266 : core_encode_openloop_fx( st, st->coder_type, Aw, lsp_new, lsp_mid, pitch_buf, voice_factors, ptr_bwe_exc,
60 1266 : vad_hover_flag, st->vad_flag, *Q_new, *shift );
61 : }
62 : ELSE
63 : {
64 0 : core_encode_twodiv_fx( new_samples, st, st->coder_type, Aw, vad_hover_flag, Q_new, shift );
65 : }
66 : /*-----------------------------------------------------------------*
67 : * Apply non linearity to the SHB excitation
68 : *-----------------------------------------------------------------*/
69 :
70 :
71 1266 : test();
72 1266 : IF( EQ_16( st->core, ACELP_CORE ) && st->igf != 0 )
73 : {
74 604 : non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, *Q_new, st->coder_type, voice_factors, st->L_frame );
75 :
76 : /* update the old BWE exe memory */
77 604 : Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); /*Q_exc*/
78 : }
79 : ELSE
80 : {
81 662 : set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET );
82 662 : set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
83 662 : hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
84 : }
85 : }
86 : ELSE
87 : {
88 : /* Run SID Coder */
89 0 : IF( st->core_brate == SID_2k40 )
90 : {
91 0 : FdCng_encodeSID_fx( st->hFdCngEnc, st, st->preemph_fac );
92 : }
93 :
94 : /* Generate Comfort Noise */
95 0 : generate_comfort_noise_enc_fx( st, *Q_new, 1 );
96 :
97 : /* Update Core Encoder */
98 0 : core_encode_update_cng_fx( st, st->hFdCngEnc->hFdCngCom->timeDomainBuffer, st->hFdCngEnc->hFdCngCom->A_cng, Aw, *Q_new, *shift );
99 : }
100 :
101 : /* coreSwitching update of MODE1 parameters in the last frame */
102 1266 : st->last_coder_type = st->coder_type;
103 1266 : move16();
104 :
105 :
106 1266 : return;
107 : }
|