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 "cnst.h"
43 : #include "rom_com.h"
44 : #include "prot.h"
45 : #include "wmc_auto.h"
46 :
47 : /*--------------------------------------------------------------------------*
48 : * hq_configure()
49 : *
50 : * Configuration routine for HQ mode
51 : *--------------------------------------------------------------------------*/
52 :
53 16917 : void hq_configure(
54 : const int16_t length, /* i : Frame length */
55 : const int16_t hqswb_clas, /* i : HQ SWB class */
56 : const int32_t core_brate, /* i : Codec bitrate */
57 : int16_t *num_sfm, /* o : Total number of subbands */
58 : int16_t *nb_sfm, /* o : Total number of coded bands */
59 : int16_t *start_norm, /* o : First norm to be SDE encoded */
60 : int16_t *num_env_bands, /* o : Number coded envelope bands */
61 : int16_t *numnrmibits, /* o : Number of bits in fall-back norm encoding */
62 : int16_t *hq_generic_offset, /* o : Freq offset for HQ GENERIC */
63 : int16_t *sfmsize, /* o : Subband bandwidths */
64 : int16_t *sfm_start, /* o : Subband start coefficients */
65 : int16_t *sfm_end /* o : Subband end coefficients */
66 : )
67 : {
68 : const int16_t *p_sfmsize;
69 : const int16_t *p_sfm_start;
70 : const int16_t *p_sfm_end;
71 : int16_t i, bw_ext;
72 :
73 16917 : bw_ext = 0;
74 16917 : *start_norm = 0;
75 :
76 16917 : if ( length == L_SPEC48k )
77 : {
78 13030 : if ( hqswb_clas == HQ_GEN_FB )
79 : {
80 5108 : *num_sfm = NB_SFM;
81 5108 : p_sfmsize = band_len_HQ;
82 5108 : p_sfm_start = band_start_HQ;
83 5108 : p_sfm_end = band_end_HQ;
84 :
85 5108 : if ( core_brate >= HQ_32k )
86 : {
87 0 : *hq_generic_offset = HQ_GENERIC_FOFFSET_32K;
88 : /* setting start frequency of FD BWE */
89 0 : *num_env_bands = SFM_N_STA_10k;
90 : }
91 : else
92 : {
93 5108 : *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4;
94 5108 : *num_env_bands = SFM_N_STA_8k;
95 : }
96 :
97 5108 : *nb_sfm = *num_sfm;
98 : }
99 : else
100 : {
101 7922 : if ( hqswb_clas == HQ_HARMONIC )
102 : {
103 1244 : *num_sfm = SFM_N_HARM_FB;
104 1244 : *nb_sfm = SFM_N_HARM_FB;
105 1244 : *num_env_bands = SFM_N_HARM_FB;
106 :
107 1244 : p_sfmsize = band_len_harm;
108 1244 : p_sfm_start = band_start_harm;
109 1244 : p_sfm_end = band_end_harm;
110 : }
111 6678 : else if ( hqswb_clas == HQ_HVQ )
112 : {
113 2088 : if ( core_brate < HQ_BWE_CROSSOVER_BRATE )
114 : {
115 1029 : *num_sfm = SFM_N_HARM_FB;
116 1029 : *nb_sfm = HVQ_THRES_SFM_24k;
117 1029 : *num_env_bands = *num_sfm - *nb_sfm;
118 1029 : *start_norm = HVQ_THRES_SFM_24k;
119 : }
120 : else
121 : {
122 1059 : *num_sfm = SFM_N_HARM_FB;
123 1059 : *nb_sfm = HVQ_THRES_SFM_32k;
124 1059 : *num_env_bands = *num_sfm - *nb_sfm;
125 1059 : *start_norm = HVQ_THRES_SFM_32k;
126 : }
127 :
128 2088 : p_sfmsize = band_len_harm;
129 2088 : p_sfm_start = band_start_harm;
130 2088 : p_sfm_end = band_end_harm;
131 : }
132 : else
133 : {
134 4590 : *num_sfm = NB_SFM;
135 4590 : *nb_sfm = *num_sfm;
136 4590 : *num_env_bands = NB_SFM;
137 :
138 4590 : p_sfmsize = band_len_HQ;
139 4590 : p_sfm_start = band_start_HQ;
140 4590 : p_sfm_end = band_end_HQ;
141 : }
142 : }
143 : }
144 3887 : else if ( length == L_SPEC32k )
145 : {
146 2531 : if ( hqswb_clas == HQ_HARMONIC )
147 : {
148 210 : *num_sfm = SFM_N_HARM;
149 210 : *nb_sfm = SFM_N_HARM;
150 210 : *num_env_bands = SFM_N_HARM;
151 :
152 210 : p_sfmsize = band_len_harm;
153 210 : p_sfm_start = band_start_harm;
154 210 : p_sfm_end = band_end_harm;
155 : }
156 2321 : else if ( hqswb_clas == HQ_HVQ )
157 : {
158 262 : if ( core_brate < HQ_BWE_CROSSOVER_BRATE )
159 : {
160 250 : *num_sfm = SFM_N_HARM;
161 250 : *nb_sfm = HVQ_THRES_SFM_24k;
162 250 : *num_env_bands = *num_sfm - *nb_sfm;
163 250 : *start_norm = HVQ_THRES_SFM_24k;
164 : }
165 : else
166 : {
167 12 : *num_sfm = SFM_N_HARM;
168 12 : *nb_sfm = HVQ_THRES_SFM_32k;
169 12 : *num_env_bands = *num_sfm - *nb_sfm;
170 12 : *start_norm = HVQ_THRES_SFM_32k;
171 : }
172 :
173 262 : p_sfmsize = band_len_harm;
174 262 : p_sfm_start = band_start_harm;
175 262 : p_sfm_end = band_end_harm;
176 : }
177 2059 : else if ( hqswb_clas == HQ_GEN_SWB )
178 : {
179 1138 : *num_sfm = SFM_N_SWB;
180 1138 : p_sfmsize = band_len_HQ;
181 1138 : p_sfm_start = band_start_HQ;
182 1138 : p_sfm_end = band_end_HQ;
183 :
184 1138 : if ( core_brate >= HQ_32k )
185 : {
186 0 : *hq_generic_offset = HQ_GENERIC_FOFFSET_32K;
187 : /* setting start frequency of FD BWE */
188 0 : *num_env_bands = SFM_N_STA_10k;
189 : }
190 : else
191 : {
192 1138 : *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4;
193 : /* setting start frequency of FD BWE */
194 1138 : *num_env_bands = SFM_N_STA_8k;
195 : }
196 1138 : *nb_sfm = *num_sfm;
197 : }
198 : else
199 : {
200 : /* HQ_NORMAL and HQ_TRANSIENT */
201 921 : *num_sfm = SFM_N_SWB;
202 921 : *nb_sfm = *num_sfm;
203 921 : *num_env_bands = SFM_N_SWB;
204 :
205 921 : p_sfmsize = band_len_HQ;
206 921 : p_sfm_start = band_start_HQ;
207 921 : p_sfm_end = band_end_HQ;
208 : }
209 : }
210 1356 : else if ( length == L_SPEC48k_EXT )
211 : {
212 186 : bw_ext = 1;
213 186 : p_sfmsize = band_len_HQ;
214 186 : p_sfm_start = band_start_HQ;
215 186 : p_sfm_end = band_end_HQ;
216 186 : *num_sfm = NB_SFM;
217 : }
218 1170 : else if ( length == L_SPEC16k_EXT )
219 : {
220 58 : bw_ext = 1;
221 58 : p_sfmsize = band_len_wb;
222 58 : p_sfm_start = band_start_wb;
223 58 : p_sfm_end = band_end_wb;
224 58 : *num_sfm = SFM_N_WB;
225 : }
226 : else
227 : {
228 1112 : *num_sfm = SFM_N_WB;
229 1112 : *nb_sfm = *num_sfm;
230 1112 : *num_env_bands = SFM_N_WB;
231 :
232 1112 : p_sfmsize = band_len_wb;
233 1112 : p_sfm_start = band_start_wb;
234 1112 : p_sfm_end = band_end_wb;
235 : }
236 :
237 16917 : if ( bw_ext )
238 : {
239 9936 : for ( i = 0; i < *num_sfm; i++ )
240 : {
241 9692 : sfmsize[i] = (int16_t) ( 1.25f * p_sfmsize[i] );
242 9692 : sfm_start[i] = (int16_t) ( 1.25f * p_sfm_start[i] );
243 9692 : sfm_end[i] = (int16_t) ( 1.25f * p_sfm_end[i] );
244 : }
245 244 : *nb_sfm = *num_sfm;
246 244 : *num_env_bands = *num_sfm;
247 : }
248 : else
249 : {
250 16673 : mvs2s( p_sfmsize, sfmsize, *num_sfm );
251 16673 : mvs2s( p_sfm_start, sfm_start, *num_sfm );
252 16673 : mvs2s( p_sfm_end, sfm_end, *num_sfm );
253 : }
254 :
255 16917 : *numnrmibits = ( *num_env_bands - 1 ) * NORMI_BITS;
256 :
257 16917 : return;
258 : }
|