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