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 10612 : 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 24840 : FOR( cur_idx = 0; cur_idx < PARAM_MC_NUM_CONFIGS; cur_idx++ )
67 : {
68 24840 : 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 10612 : 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 615 : 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 615 : set16_fx( hMetadataPMC->coding_band_mapping, 0, PARAM_MC_MAX_PARAMETER_BANDS );
93 :
94 : /* set coding scheme */
95 615 : ivas_param_mc_set_coding_scheme_fx( mc_ls_setup, ivas_total_brate, hMetadataPMC );
96 :
97 : /* get configuration index */
98 615 : config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_brate );
99 615 : 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 615 : 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 612 : ELSE IF( EQ_16( hMetadataPMC->num_parameter_bands, 14 ) )
110 : {
111 283 : Copy( param_mc_coding_band_mapping_14, hMetadataPMC->coding_band_mapping, 14 );
112 : }
113 329 : ELSE IF( EQ_16( hMetadataPMC->num_parameter_bands, 10 ) )
114 : {
115 329 : 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 615 : hMetadataPMC->icc_mapping_conf = ivas_param_mc_conf[config_index].icc_mapping_conf;
122 615 : hMetadataPMC->ild_mapping_conf = ivas_param_mc_conf[config_index].ild_mapping_conf;
123 615 : hMetadataPMC->ild_factors_fx = ivas_param_mc_conf[config_index].ild_factors_fx;
124 :
125 : /* init remaining flags and indices */
126 615 : hMetadataPMC->param_frame_idx = 0;
127 615 : move16();
128 615 : hMetadataPMC->bAttackPresent = 0;
129 615 : move16();
130 615 : hMetadataPMC->attackIndex = 0;
131 615 : move16();
132 615 : hMetadataPMC->lfe_on = 1;
133 615 : move16();
134 :
135 : /* set coded bwidth to FB at the beginning */
136 615 : hMetadataPMC->coded_bwidth = FB;
137 615 : move16();
138 615 : hMetadataPMC->last_coded_bwidth = FB;
139 615 : move16();
140 :
141 615 : ivas_param_mc_set_coded_bands_fx( hMetadataPMC );
142 :
143 615 : 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 1001 : 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 1001 : SWITCH( hMetadataPMC->num_parameter_bands )
161 : {
162 6 : case 20:
163 6 : hMetadataPMC->nbands_coded = param_mc_bands_coded_20[hMetadataPMC->coded_bwidth];
164 6 : move16();
165 6 : BREAK;
166 460 : case 14:
167 460 : hMetadataPMC->nbands_coded = param_mc_bands_coded_14[hMetadataPMC->coded_bwidth];
168 460 : move16();
169 460 : BREAK;
170 535 : case 10:
171 535 : hMetadataPMC->nbands_coded = param_mc_bands_coded_10[hMetadataPMC->coded_bwidth];
172 535 : move16();
173 : }
174 :
175 : /* set number of bands per parameter frame set */
176 3003 : FOR( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ )
177 : {
178 2002 : hMetadataPMC->nbands_in_param_frame[i] = 0;
179 2002 : move16();
180 : }
181 :
182 12775 : FOR( i = 0; i < hMetadataPMC->nbands_coded; i++ )
183 : {
184 11774 : hMetadataPMC->nbands_in_param_frame[hMetadataPMC->coding_band_mapping[i]] = add( hMetadataPMC->nbands_in_param_frame[hMetadataPMC->coding_band_mapping[i]], 1 );
185 11774 : move16();
186 : }
187 :
188 1001 : return;
189 : }
190 :
191 : /*-------------------------------------------------------------------------
192 : * ivas_param_mc_getNumTransportChannels()
193 : *
194 : *
195 : *------------------------------------------------------------------------*/
196 :
197 : /* r : number of IVAS transport channels */
198 9382 : 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 9382 : config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_bitrate );
207 :
208 9382 : nchan_transport = ivas_param_mc_conf[config_index].num_transport_chan;
209 9382 : move16();
210 :
211 9382 : return nchan_transport;
212 : }
213 :
214 : /*-------------------------------------------------------------------------
215 : * ivas_param_mc_get_num_param_bands()
216 : *
217 : *
218 : *------------------------------------------------------------------------*/
219 615 : 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 615 : num_parameter_bands = 0;
227 615 : move16();
228 :
229 : /* parameter bands */
230 615 : SWITCH( mc_ls_setup )
231 : {
232 559 : case MC_LS_SETUP_5_1:
233 : SWITCH( ivas_total_brate )
234 : {
235 322 : case IVAS_48k:
236 322 : num_parameter_bands = 10;
237 322 : move16();
238 322 : BREAK;
239 237 : case IVAS_64k:
240 : case IVAS_80k:
241 237 : num_parameter_bands = 14;
242 237 : move16();
243 237 : BREAK;
244 0 : default:
245 0 : assert( 0 && "PARAM_MC: bitrate for CICP6 not supported!" );
246 : }
247 559 : BREAK;
248 :
249 16 : case MC_LS_SETUP_7_1:
250 : SWITCH( ivas_total_brate )
251 : {
252 4 : case IVAS_48k:
253 4 : num_parameter_bands = 10;
254 4 : move16();
255 4 : BREAK;
256 10 : case IVAS_64k:
257 : case IVAS_80k:
258 10 : num_parameter_bands = 14;
259 10 : move16();
260 10 : BREAK;
261 2 : case IVAS_96k:
262 2 : num_parameter_bands = 20;
263 2 : move16();
264 2 : BREAK;
265 : }
266 16 : BREAK;
267 16 : case MC_LS_SETUP_5_1_2:
268 : SWITCH( ivas_total_brate )
269 : {
270 3 : case IVAS_48k:
271 3 : num_parameter_bands = 10;
272 3 : move16();
273 3 : BREAK;
274 12 : case IVAS_64k:
275 : case IVAS_80k:
276 12 : num_parameter_bands = 14;
277 12 : move16();
278 12 : BREAK;
279 1 : case IVAS_96k:
280 1 : num_parameter_bands = 20;
281 1 : move16();
282 1 : BREAK;
283 : }
284 16 : 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 24 : case MC_LS_SETUP_7_1_4:
299 : SWITCH( ivas_total_brate )
300 : {
301 24 : case IVAS_128k:
302 24 : num_parameter_bands = 14;
303 24 : move16();
304 24 : BREAK;
305 : }
306 24 : BREAK;
307 0 : default:
308 0 : assert( 0 && "PARAM_MC: channel configuration not supportet!" );
309 : }
310 :
311 615 : 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 615 : 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 615 : SWITCH( mc_ls_setup )
333 : {
334 559 : case MC_LS_SETUP_5_1:
335 : /* ICC */
336 559 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp6_48_16bits[0];
337 559 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp6_48_16bits[0];
338 559 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[0];
339 559 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[0];
340 559 : hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/
341 559 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
342 559 : move16();
343 559 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
344 559 : move16();
345 : /* ILD */
346 559 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp6_48_16bits[0];
347 559 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp6_48_16bits[0];
348 559 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[0];
349 559 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[0];
350 559 : hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/
351 559 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
352 559 : move16();
353 559 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
354 559 : move16();
355 559 : BREAK;
356 16 : case MC_LS_SETUP_7_1:
357 : /* ICC */
358 16 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp12_48_16bits[0];
359 16 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp12_48_16bits[0];
360 16 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[0];
361 16 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0];
362 16 : hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/
363 16 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
364 16 : move16();
365 16 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
366 16 : move16();
367 : /* ILD */
368 16 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp12_48_16bits[0];
369 16 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp12_48_16bits[0];
370 16 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[0];
371 16 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0];
372 16 : hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/
373 16 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
374 16 : move16();
375 16 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
376 16 : move16();
377 16 : BREAK;
378 16 : case MC_LS_SETUP_5_1_2:
379 : /* ICC */
380 16 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp14_48_16bits[0];
381 16 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp14_48_16bits[0];
382 16 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[0];
383 16 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0];
384 16 : hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/
385 16 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
386 16 : move16();
387 16 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
388 16 : move16();
389 : /* ILD */
390 16 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp14_48_16bits[0];
391 16 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp14_48_16bits[0];
392 16 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[0];
393 16 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0];
394 16 : hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/
395 16 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
396 16 : move16();
397 16 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
398 16 : move16();
399 16 : BREAK;
400 24 : case MC_LS_SETUP_5_1_4:
401 : case MC_LS_SETUP_7_1_4:
402 : /* ICC */
403 24 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_combined_48_16bits[0];
404 24 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_combined_48_16bits[0];
405 24 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[0];
406 24 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0];
407 24 : hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/
408 24 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
409 24 : move16();
410 24 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
411 24 : move16();
412 : /* ILD */
413 24 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_combined_48_16bits[0];
414 24 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_combined_48_16bits[0];
415 24 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[0];
416 24 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0];
417 24 : hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/
418 24 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
419 24 : move16();
420 24 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
421 24 : move16();
422 24 : BREAK;
423 0 : default:
424 0 : assert( 0 && "PARAM_MC: channel configuration not supported!" );
425 : }
426 :
427 615 : hMetadataPMC->num_parameter_bands = ivas_param_mc_get_num_param_bands_fx( mc_ls_setup, ivas_total_brate );
428 615 : move16();
429 :
430 615 : return;
431 : }
|