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 33128 : 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 33128 : bw_ext = 0;
74 33128 : *start_norm = 0;
75 :
76 33128 : if ( length == L_SPEC48k )
77 : {
78 24047 : if ( hqswb_clas == HQ_GEN_FB )
79 : {
80 9074 : *num_sfm = NB_SFM;
81 9074 : p_sfmsize = band_len_HQ;
82 9074 : p_sfm_start = band_start_HQ;
83 9074 : p_sfm_end = band_end_HQ;
84 :
85 9074 : 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 9074 : *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4;
94 9074 : *num_env_bands = SFM_N_STA_8k;
95 : }
96 :
97 9074 : *nb_sfm = *num_sfm;
98 : }
99 : else
100 : {
101 14973 : if ( hqswb_clas == HQ_HARMONIC )
102 : {
103 2705 : *num_sfm = SFM_N_HARM_FB;
104 2705 : *nb_sfm = SFM_N_HARM_FB;
105 2705 : *num_env_bands = SFM_N_HARM_FB;
106 :
107 2705 : p_sfmsize = band_len_harm;
108 2705 : p_sfm_start = band_start_harm;
109 2705 : p_sfm_end = band_end_harm;
110 : }
111 12268 : else if ( hqswb_clas == HQ_HVQ )
112 : {
113 4462 : if ( core_brate < HQ_BWE_CROSSOVER_BRATE )
114 : {
115 2291 : *num_sfm = SFM_N_HARM_FB;
116 2291 : *nb_sfm = HVQ_THRES_SFM_24k;
117 2291 : *num_env_bands = *num_sfm - *nb_sfm;
118 2291 : *start_norm = HVQ_THRES_SFM_24k;
119 : }
120 : else
121 : {
122 2171 : *num_sfm = SFM_N_HARM_FB;
123 2171 : *nb_sfm = HVQ_THRES_SFM_32k;
124 2171 : *num_env_bands = *num_sfm - *nb_sfm;
125 2171 : *start_norm = HVQ_THRES_SFM_32k;
126 : }
127 :
128 4462 : p_sfmsize = band_len_harm;
129 4462 : p_sfm_start = band_start_harm;
130 4462 : p_sfm_end = band_end_harm;
131 : }
132 : else
133 : {
134 7806 : *num_sfm = NB_SFM;
135 7806 : *nb_sfm = *num_sfm;
136 7806 : *num_env_bands = NB_SFM;
137 :
138 7806 : p_sfmsize = band_len_HQ;
139 7806 : p_sfm_start = band_start_HQ;
140 7806 : p_sfm_end = band_end_HQ;
141 : }
142 : }
143 : }
144 9081 : else if ( length == L_SPEC32k )
145 : {
146 6138 : if ( hqswb_clas == HQ_HARMONIC )
147 : {
148 453 : *num_sfm = SFM_N_HARM;
149 453 : *nb_sfm = SFM_N_HARM;
150 453 : *num_env_bands = SFM_N_HARM;
151 :
152 453 : p_sfmsize = band_len_harm;
153 453 : p_sfm_start = band_start_harm;
154 453 : p_sfm_end = band_end_harm;
155 : }
156 5685 : else if ( hqswb_clas == HQ_HVQ )
157 : {
158 732 : if ( core_brate < HQ_BWE_CROSSOVER_BRATE )
159 : {
160 708 : *num_sfm = SFM_N_HARM;
161 708 : *nb_sfm = HVQ_THRES_SFM_24k;
162 708 : *num_env_bands = *num_sfm - *nb_sfm;
163 708 : *start_norm = HVQ_THRES_SFM_24k;
164 : }
165 : else
166 : {
167 24 : *num_sfm = SFM_N_HARM;
168 24 : *nb_sfm = HVQ_THRES_SFM_32k;
169 24 : *num_env_bands = *num_sfm - *nb_sfm;
170 24 : *start_norm = HVQ_THRES_SFM_32k;
171 : }
172 :
173 732 : p_sfmsize = band_len_harm;
174 732 : p_sfm_start = band_start_harm;
175 732 : p_sfm_end = band_end_harm;
176 : }
177 4953 : else if ( hqswb_clas == HQ_GEN_SWB )
178 : {
179 2998 : *num_sfm = SFM_N_SWB;
180 2998 : p_sfmsize = band_len_HQ;
181 2998 : p_sfm_start = band_start_HQ;
182 2998 : p_sfm_end = band_end_HQ;
183 :
184 2998 : 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 2998 : *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4;
193 : /* setting start frequency of FD BWE */
194 2998 : *num_env_bands = SFM_N_STA_8k;
195 : }
196 2998 : *nb_sfm = *num_sfm;
197 : }
198 : else
199 : {
200 : /* HQ_NORMAL and HQ_TRANSIENT */
201 1955 : *num_sfm = SFM_N_SWB;
202 1955 : *nb_sfm = *num_sfm;
203 1955 : *num_env_bands = SFM_N_SWB;
204 :
205 1955 : p_sfmsize = band_len_HQ;
206 1955 : p_sfm_start = band_start_HQ;
207 1955 : p_sfm_end = band_end_HQ;
208 : }
209 : }
210 2943 : else if ( length == L_SPEC48k_EXT )
211 : {
212 402 : bw_ext = 1;
213 402 : p_sfmsize = band_len_HQ;
214 402 : p_sfm_start = band_start_HQ;
215 402 : p_sfm_end = band_end_HQ;
216 402 : *num_sfm = NB_SFM;
217 : }
218 2541 : else if ( length == L_SPEC16k_EXT )
219 : {
220 132 : bw_ext = 1;
221 132 : p_sfmsize = band_len_wb;
222 132 : p_sfm_start = band_start_wb;
223 132 : p_sfm_end = band_end_wb;
224 132 : *num_sfm = SFM_N_WB;
225 : }
226 : else
227 : {
228 2409 : *num_sfm = SFM_N_WB;
229 2409 : *nb_sfm = *num_sfm;
230 2409 : *num_env_bands = SFM_N_WB;
231 :
232 2409 : p_sfmsize = band_len_wb;
233 2409 : p_sfm_start = band_start_wb;
234 2409 : p_sfm_end = band_end_wb;
235 : }
236 :
237 33128 : if ( bw_ext )
238 : {
239 21654 : for ( i = 0; i < *num_sfm; i++ )
240 : {
241 21120 : sfmsize[i] = (int16_t) ( 1.25f * p_sfmsize[i] );
242 21120 : sfm_start[i] = (int16_t) ( 1.25f * p_sfm_start[i] );
243 21120 : sfm_end[i] = (int16_t) ( 1.25f * p_sfm_end[i] );
244 : }
245 534 : *nb_sfm = *num_sfm;
246 534 : *num_env_bands = *num_sfm;
247 : }
248 : else
249 : {
250 32594 : mvs2s( p_sfmsize, sfmsize, *num_sfm );
251 32594 : mvs2s( p_sfm_start, sfm_start, *num_sfm );
252 32594 : mvs2s( p_sfm_end, sfm_end, *num_sfm );
253 : }
254 :
255 33128 : *numnrmibits = ( *num_env_bands - 1 ) * NORMI_BITS;
256 :
257 33128 : return;
258 : }
|