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 : #include <assert.h>
34 : #include <stdint.h>
35 : #include <math.h>
36 : #include "options.h"
37 : #include "ivas_cnst.h"
38 : #include "prot_fx.h"
39 : #include "ivas_stat_com.h"
40 : #include "ivas_rom_com.h"
41 : #include "wmc_auto.h"
42 : #include "ivas_rom_com_fx.h"
43 : #include "ivas_prot_fx.h"
44 :
45 :
46 : /*-------------------------------------------------------------------------
47 : * Local function prototypes
48 : *------------------------------------------------------------------------*/
49 :
50 :
51 : static void ivas_param_mc_set_coding_scheme_fx( const MC_LS_SETUP mc_ls_setup, const Word32 ivas_total_brate, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC );
52 :
53 : /*-------------------------------------------------------------------------
54 : * ivas_param_mc_get_configuration_index()
55 : *
56 : *
57 : *------------------------------------------------------------------------*/
58 :
59 11248 : UWord16 ivas_param_mc_get_configuration_index_fx(
60 : const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */
61 : const Word32 ivas_total_brate /* i : IVAS total bitrate */
62 : )
63 : {
64 : UWord16 cur_idx;
65 :
66 26884 : FOR( cur_idx = 0; cur_idx < PARAM_MC_NUM_CONFIGS; cur_idx++ )
67 : {
68 26884 : IF( EQ_16( (Word16) ivas_param_mc_conf[cur_idx].mc_ls_setup, (Word16) mc_ls_setup ) && EQ_32( ivas_param_mc_conf[cur_idx].ivas_total_brate, ivas_total_brate ) )
69 : {
70 11248 : return cur_idx;
71 : }
72 : }
73 0 : return PARAM_MC_NUM_CONFIGS;
74 : }
75 :
76 :
77 : /*-------------------------------------------------------------------------
78 : * ivas_param_mc_metadata_open()
79 : *
80 : * Parametric MC parameter coding state open function
81 : *------------------------------------------------------------------------*/
82 :
83 344 : void ivas_param_mc_metadata_open_fx(
84 : const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */
85 : const Word32 ivas_total_brate, /* i : IVAS total bitrate */
86 : HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */
87 : )
88 : {
89 : UWord16 config_index;
90 :
91 : /* get coding band mappings */
92 344 : set16_fx( hMetadataPMC->coding_band_mapping, 0, PARAM_MC_MAX_PARAMETER_BANDS );
93 :
94 : /* set coding scheme */
95 344 : ivas_param_mc_set_coding_scheme_fx( mc_ls_setup, ivas_total_brate, hMetadataPMC );
96 :
97 : /* get configuration index */
98 344 : config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_brate );
99 344 : IF( EQ_16( (Word16) config_index, PARAM_MC_NUM_CONFIGS ) )
100 : {
101 0 : assert( 0 && "ParamMC configuration index not found!" );
102 : }
103 :
104 : /* Band Grouping */
105 344 : IF( EQ_16( hMetadataPMC->num_parameter_bands, 20 ) )
106 : {
107 3 : Copy( param_mc_coding_band_mapping_20, hMetadataPMC->coding_band_mapping, 20 );
108 : }
109 341 : ELSE IF( EQ_16( hMetadataPMC->num_parameter_bands, 14 ) )
110 : {
111 169 : Copy( param_mc_coding_band_mapping_14, hMetadataPMC->coding_band_mapping, 14 );
112 : }
113 172 : ELSE IF( EQ_16( hMetadataPMC->num_parameter_bands, 10 ) )
114 : {
115 172 : Copy( param_mc_coding_band_mapping_10, hMetadataPMC->coding_band_mapping, 10 );
116 : }
117 : ELSE
118 : {
119 0 : assert( 0 && "nbands must be 20 or 14!" );
120 : }
121 344 : hMetadataPMC->icc_mapping_conf = ivas_param_mc_conf[config_index].icc_mapping_conf;
122 344 : hMetadataPMC->ild_mapping_conf = ivas_param_mc_conf[config_index].ild_mapping_conf;
123 344 : hMetadataPMC->ild_factors_fx = ivas_param_mc_conf[config_index].ild_factors_fx;
124 :
125 : /* init remaining flags and indices */
126 344 : hMetadataPMC->param_frame_idx = 0;
127 344 : move16();
128 344 : hMetadataPMC->bAttackPresent = 0;
129 344 : move16();
130 344 : hMetadataPMC->attackIndex = 0;
131 344 : move16();
132 344 : hMetadataPMC->lfe_on = 1;
133 344 : move16();
134 :
135 : /* set coded bwidth to FB at the beginning */
136 344 : hMetadataPMC->coded_bwidth = FB;
137 344 : move16();
138 344 : hMetadataPMC->last_coded_bwidth = FB;
139 344 : move16();
140 :
141 344 : ivas_param_mc_set_coded_bands_fx( hMetadataPMC );
142 :
143 344 : return;
144 : }
145 :
146 : /*-------------------------------------------------------------------------
147 : * ivas_param_mc_set_coded_bands()
148 : *
149 : * Parametric MC: set number of actually coded parameters bands based on the
150 : * coded band width
151 : *------------------------------------------------------------------------*/
152 :
153 430 : void ivas_param_mc_set_coded_bands_fx(
154 : HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */
155 : )
156 : {
157 : Word16 i;
158 :
159 : /* set number of coded bands*/
160 430 : SWITCH( hMetadataPMC->num_parameter_bands )
161 : {
162 3 : case 20:
163 3 : hMetadataPMC->nbands_coded = param_mc_bands_coded_20[hMetadataPMC->coded_bwidth];
164 3 : move16();
165 3 : BREAK;
166 211 : case 14:
167 211 : hMetadataPMC->nbands_coded = param_mc_bands_coded_14[hMetadataPMC->coded_bwidth];
168 211 : move16();
169 211 : BREAK;
170 216 : case 10:
171 216 : hMetadataPMC->nbands_coded = param_mc_bands_coded_10[hMetadataPMC->coded_bwidth];
172 216 : move16();
173 : }
174 :
175 : /* set number of bands per parameter frame set */
176 1290 : FOR( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ )
177 : {
178 860 : hMetadataPMC->nbands_in_param_frame[i] = 0;
179 860 : move16();
180 : }
181 :
182 5501 : FOR( i = 0; i < hMetadataPMC->nbands_coded; i++ )
183 : {
184 5071 : hMetadataPMC->nbands_in_param_frame[hMetadataPMC->coding_band_mapping[i]] = add( hMetadataPMC->nbands_in_param_frame[hMetadataPMC->coding_band_mapping[i]], 1 );
185 5071 : move16();
186 : }
187 :
188 430 : return;
189 : }
190 :
191 : /*-------------------------------------------------------------------------
192 : * ivas_param_mc_getNumTransportChannels()
193 : *
194 : *
195 : *------------------------------------------------------------------------*/
196 :
197 : /* r : number of IVAS transport channels */
198 10560 : Word16 ivas_param_mc_getNumTransportChannels_fx(
199 : const Word32 ivas_total_bitrate, /* i : IVAS total bitrate */
200 : const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */
201 : )
202 : {
203 : Word16 nchan_transport;
204 : Word16 config_index;
205 :
206 10560 : config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_bitrate );
207 :
208 10560 : nchan_transport = ivas_param_mc_conf[config_index].num_transport_chan;
209 10560 : move16();
210 :
211 10560 : return nchan_transport;
212 : }
213 :
214 : /*-------------------------------------------------------------------------
215 : * ivas_param_mc_get_num_param_bands()
216 : *
217 : *
218 : *------------------------------------------------------------------------*/
219 344 : static Word16 ivas_param_mc_get_num_param_bands_fx(
220 : const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */
221 : const Word32 ivas_total_brate /* i : IVAS total bitrate */
222 : )
223 : {
224 : Word16 num_parameter_bands;
225 :
226 344 : num_parameter_bands = 0;
227 344 : move16();
228 :
229 : /* parameter bands */
230 344 : SWITCH( mc_ls_setup )
231 : {
232 306 : case MC_LS_SETUP_5_1:
233 : SWITCH( ivas_total_brate )
234 : {
235 167 : case IVAS_48k:
236 167 : num_parameter_bands = 10;
237 167 : move16();
238 167 : BREAK;
239 139 : case IVAS_64k:
240 : case IVAS_80k:
241 139 : num_parameter_bands = 14;
242 139 : move16();
243 139 : BREAK;
244 0 : default:
245 0 : assert( 0 && "PARAM_MC: bitrate for CICP6 not supported!" );
246 : }
247 306 : BREAK;
248 :
249 13 : case MC_LS_SETUP_7_1:
250 : SWITCH( ivas_total_brate )
251 : {
252 3 : case IVAS_48k:
253 3 : num_parameter_bands = 10;
254 3 : move16();
255 3 : BREAK;
256 8 : case IVAS_64k:
257 : case IVAS_80k:
258 8 : num_parameter_bands = 14;
259 8 : move16();
260 8 : BREAK;
261 2 : case IVAS_96k:
262 2 : num_parameter_bands = 20;
263 2 : move16();
264 2 : BREAK;
265 : }
266 13 : BREAK;
267 11 : case MC_LS_SETUP_5_1_2:
268 : SWITCH( ivas_total_brate )
269 : {
270 2 : case IVAS_48k:
271 2 : num_parameter_bands = 10;
272 2 : move16();
273 2 : BREAK;
274 8 : case IVAS_64k:
275 : case IVAS_80k:
276 8 : num_parameter_bands = 14;
277 8 : move16();
278 8 : BREAK;
279 1 : case IVAS_96k:
280 1 : num_parameter_bands = 20;
281 1 : move16();
282 1 : BREAK;
283 : }
284 11 : BREAK;
285 0 : case MC_LS_SETUP_5_1_4:
286 : SWITCH( ivas_total_brate )
287 : {
288 0 : case IVAS_96k:
289 0 : num_parameter_bands = 14;
290 0 : move16();
291 0 : BREAK;
292 0 : case IVAS_128k:
293 0 : num_parameter_bands = 20;
294 0 : move16();
295 0 : BREAK;
296 : }
297 0 : BREAK;
298 14 : case MC_LS_SETUP_7_1_4:
299 : SWITCH( ivas_total_brate )
300 : {
301 14 : case IVAS_128k:
302 14 : num_parameter_bands = 14;
303 14 : move16();
304 14 : BREAK;
305 : }
306 14 : BREAK;
307 0 : default:
308 0 : assert( 0 && "PARAM_MC: channel configuration not supportet!" );
309 : }
310 :
311 344 : return num_parameter_bands;
312 : }
313 :
314 :
315 : /*-------------------------------------------------------------------------
316 : * Local functions
317 : *------------------------------------------------------------------------*/
318 :
319 : /*-------------------------------------------------------------------------
320 : * ivas_param_mc_set_coding_scheme()
321 : *
322 : * set Parametric MC parameter coding tables based on format and bitrate
323 : *------------------------------------------------------------------------*/
324 :
325 344 : static void ivas_param_mc_set_coding_scheme_fx(
326 : const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */
327 : const Word32 ivas_total_brate, /* i : IVAS total bitrate */
328 : HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: Parametric MC metadata handle */
329 : )
330 : {
331 : /* quantizer and coding tables */
332 344 : SWITCH( mc_ls_setup )
333 : {
334 306 : case MC_LS_SETUP_5_1:
335 : /* ICC */
336 306 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp6_48_16bits[0];
337 306 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp6_48_16bits[0];
338 306 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[0];
339 306 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[0];
340 306 : hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/
341 306 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
342 306 : move16();
343 306 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
344 306 : move16();
345 : /* ILD */
346 306 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp6_48_16bits[0];
347 306 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp6_48_16bits[0];
348 306 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[0];
349 306 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[0];
350 306 : hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/
351 306 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
352 306 : move16();
353 306 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
354 306 : move16();
355 306 : BREAK;
356 13 : case MC_LS_SETUP_7_1:
357 : /* ICC */
358 13 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp12_48_16bits[0];
359 13 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp12_48_16bits[0];
360 13 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[0];
361 13 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0];
362 13 : hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/
363 13 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
364 13 : move16();
365 13 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
366 13 : move16();
367 : /* ILD */
368 13 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp12_48_16bits[0];
369 13 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp12_48_16bits[0];
370 13 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[0];
371 13 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0];
372 13 : hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/
373 13 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
374 13 : move16();
375 13 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
376 13 : move16();
377 13 : BREAK;
378 11 : case MC_LS_SETUP_5_1_2:
379 : /* ICC */
380 11 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp14_48_16bits[0];
381 11 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp14_48_16bits[0];
382 11 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[0];
383 11 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0];
384 11 : hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/
385 11 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
386 11 : move16();
387 11 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
388 11 : move16();
389 : /* ILD */
390 11 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp14_48_16bits[0];
391 11 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp14_48_16bits[0];
392 11 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[0];
393 11 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0];
394 11 : hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/
395 11 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
396 11 : move16();
397 11 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
398 11 : move16();
399 11 : BREAK;
400 14 : case MC_LS_SETUP_5_1_4:
401 : case MC_LS_SETUP_7_1_4:
402 : /* ICC */
403 14 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_combined_48_16bits[0];
404 14 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_combined_48_16bits[0];
405 14 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[0];
406 14 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0];
407 14 : hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/
408 14 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
409 14 : move16();
410 14 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
411 14 : move16();
412 : /* ILD */
413 14 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_combined_48_16bits[0];
414 14 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_combined_48_16bits[0];
415 14 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[0];
416 14 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0];
417 14 : hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/
418 14 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
419 14 : move16();
420 14 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
421 14 : move16();
422 14 : BREAK;
423 0 : default:
424 0 : assert( 0 && "PARAM_MC: channel configuration not supported!" );
425 : }
426 :
427 344 : hMetadataPMC->num_parameter_bands = ivas_param_mc_get_num_param_bands_fx( mc_ls_setup, ivas_total_brate );
428 344 : move16();
429 :
430 344 : return;
431 : }
|