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 <math.h>
43 : #include "cnst.h"
44 : #include "rom_com.h"
45 : #include "prot.h"
46 : #include "wmc_auto.h"
47 :
48 : /*-------------------------------------------------------------------*
49 : * Local constants
50 : *-------------------------------------------------------------------*/
51 :
52 : #define ALPHA0 0.5f
53 : #define BETA0 ( 1.0f - ALPHA0 )
54 :
55 : /*-------------------------------------------------------------------*
56 : * inact_switch_ematch()
57 : *
58 : * Apply energy matching when swithcing to INACTIVE frame coded by the GSC technology
59 : *-------------------------------------------------------------------*/
60 :
61 472044 : void inact_switch_ematch(
62 : float exc2[], /* i/o: CELP/GSC excitation buffer */
63 : float dct_exc_tmp[], /* i : GSC excitation in DCT domain */
64 : float lt_ener_per_band[], /* i/o: Long term energy per band */
65 : const int16_t coder_type, /* i : Coder type */
66 : const int16_t inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */
67 : const int16_t L_frame, /* i : Frame length */
68 : const int16_t bfi, /* i : frame lost indicator */
69 : const int16_t last_core, /* i : Last core used */
70 : const int16_t last_codec_mode, /* i : Last codec mode */
71 : const int16_t tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/
72 : const int16_t element_mode /* i : element mode */
73 : )
74 : {
75 : float Ener_per_bd[MBANDS_GN16k];
76 : float ftmp;
77 : float *pt_exc;
78 : int16_t j, i;
79 :
80 :
81 : /*--------------------------------------------------------------------------
82 : * average energy per band
83 : *--------------------------------------------------------------------------*/
84 :
85 472044 : if ( ( coder_type == AUDIO || ( coder_type == UNVOICED && tdm_low_rate_mode == 1 ) ) && bfi == 0 )
86 : {
87 32937 : Ener_per_band_comp( dct_exc_tmp, Ener_per_bd, MBANDS_GN, 1, L_frame );
88 :
89 : /* reset long-term energy per band */
90 559929 : for ( i = 0; i < MBANDS_GN; i++ )
91 : {
92 526992 : lt_ener_per_band[i] = Ener_per_bd[i];
93 : }
94 : }
95 439107 : else if ( coder_type == VOICED || coder_type == GENERIC || coder_type == TRANSITION || last_core != ACELP_CORE || last_codec_mode != MODE1 || ( element_mode > EVS_MONO && coder_type == UNVOICED ) )
96 : {
97 : /* Find spectrum and energy per band for GC and VC frames */
98 397173 : edct( exc2, dct_exc_tmp, L_frame, element_mode );
99 :
100 397173 : Ener_per_band_comp( dct_exc_tmp, Ener_per_bd, MBANDS_GN, 1, L_frame );
101 :
102 : /* reset long-term energy per band */
103 6751941 : for ( i = 0; i < MBANDS_GN; i++ )
104 : {
105 6354768 : lt_ener_per_band[i] = Ener_per_bd[i];
106 : }
107 : }
108 41934 : else if ( coder_type == INACTIVE && inactive_coder_type_flag )
109 : {
110 : /* Find spectrum and energy per band for inactive frames */
111 33846 : edct( exc2, dct_exc_tmp, L_frame, element_mode );
112 :
113 33846 : Ener_per_band_comp( dct_exc_tmp, Ener_per_bd, MBANDS_GN, 1, L_frame );
114 :
115 : /* More agressive smoothing in the first 50 frames */
116 33846 : pt_exc = dct_exc_tmp;
117 575382 : for ( i = 0; i < MBANDS_GN; i++ )
118 : {
119 : /* Compute smoothing gain to apply with gain limitation */
120 541536 : lt_ener_per_band[i] = ALPHA0 * lt_ener_per_band[i] + BETA0 * Ener_per_bd[i];
121 :
122 541536 : ftmp = lt_ener_per_band[i] - Ener_per_bd[i];
123 541536 : ftmp = (float) pow( 10, ftmp );
124 :
125 541536 : if ( i < 2 )
126 : {
127 609228 : for ( j = 0; j < 8; j++ )
128 : {
129 541536 : *pt_exc *= ftmp;
130 541536 : pt_exc++;
131 : }
132 : }
133 : else
134 : {
135 8055348 : for ( j = 0; j < 16; j++ )
136 : {
137 7581504 : *pt_exc *= ftmp;
138 7581504 : pt_exc++;
139 : }
140 : }
141 : }
142 :
143 : /* Going back to time */
144 33846 : edct( dct_exc_tmp, exc2, L_frame, element_mode );
145 : }
146 :
147 472044 : return;
148 : }
|