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