Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 : #include "prot.h"
43 : #include "rom_com.h"
44 : #include "wmc_auto.h"
45 :
46 : /*-------------------------------------------------------------------*
47 : * enc_acelp_tcx_main()
48 : *
49 : * encoder function for coding ACELP/TCX
50 : *--------------------------------------------------------------------*/
51 :
52 1250 : void enc_acelp_tcx_main(
53 : Encoder_State *st, /* i/o: encoder state structure */
54 : const float new_samples[], /* i : new samples */
55 : float Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/
56 : const float lsp_new[M], /* i : LSPs at the end of the frame */
57 : const float lsp_mid[M], /* i : LSPs at the middle of the frame */
58 : float bwe_exc_extended[], /* i/o: bandwidth extended excitation */
59 : float *voice_factors, /* o : voicing factors */
60 : float pitch_buf[], /* o : floating pitch for each subframe */
61 : const int16_t vad_hover_flag /* i : VAD hangover flag */
62 : )
63 : {
64 : float old_bwe_exc[( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2]; /* excitation buffer */
65 : float *ptr_bwe_exc; /* pointer to BWE excitation signal in the current frame */
66 :
67 1250 : push_wmops( "enc_acelp_tcx_main" );
68 :
69 1250 : ptr_bwe_exc = old_bwe_exc + PIT16k_MAX * 2;
70 :
71 1250 : if ( st->last_core == ACELP_CORE )
72 : {
73 612 : set_f( old_bwe_exc + PIT16k_MAX * 2, 0.f, ( ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 );
74 612 : mvr2r( st->hBWE_TD->old_bwe_exc, old_bwe_exc, PIT16k_MAX * 2 );
75 : }
76 : else
77 : {
78 638 : set_f( old_bwe_exc, 0.f, ( ( L_FRAME16k + 1 ) + L_SUBFR16k + PIT16k_MAX ) * 2 );
79 : }
80 :
81 : /* Guided ACELP PLC */
82 1250 : if ( st->hPlcExt )
83 : {
84 1250 : gPLC_encInfo( st->hPlcExt, st->total_brate, st->bwidth, st->clas, st->coder_type );
85 : }
86 :
87 1250 : if ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 )
88 : {
89 : /* Run Core Coder */
90 1250 : if ( st->tcxonly == 0 )
91 : {
92 1250 : core_encode_openloop( st, Aw, lsp_new, lsp_mid, pitch_buf, voice_factors, ptr_bwe_exc, vad_hover_flag );
93 : }
94 : else
95 : {
96 0 : core_encode_twodiv( st, new_samples, Aw, vad_hover_flag );
97 : }
98 :
99 : /* Apply non linearity to the SHB excitation */
100 1250 : if ( st->core == ACELP_CORE && st->igf )
101 : {
102 604 : non_linearity( ptr_bwe_exc, bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale, st->coder_type, voice_factors, st->L_frame );
103 :
104 : /* update the old_BWE_exc memory */
105 604 : mvr2r( &old_bwe_exc[L_FRAME32k], st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 );
106 : }
107 : else
108 : {
109 646 : set_f( st->hBWE_TD->old_bwe_exc_extended, 0, NL_BUFF_OFFSET );
110 646 : set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); /* reset old non_linear exc during igf frames */
111 646 : st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f;
112 : }
113 : }
114 : else
115 : {
116 : /* Run SID Coder */
117 0 : if ( st->core_brate == SID_2k40 )
118 : {
119 0 : FdCng_encodeSID( st );
120 : }
121 :
122 : /* Generate Comfort Noise */
123 0 : generate_comfort_noise_enc( st );
124 :
125 : /* Update Core Encoder */
126 0 : core_encode_update_cng( st, st->hFdCngEnc->hFdCngCom->timeDomainBuffer, st->hFdCngEnc->hFdCngCom->A_cng, Aw );
127 : }
128 :
129 : /* coreSwitching update of Mode 1 parameters in the last frame */
130 1250 : st->last_coder_type = st->coder_type;
131 :
132 1250 : pop_wmops();
133 1250 : return;
134 : }
|