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 <stdint.h>
34 : #include "options.h"
35 : #include "cnst.h"
36 : #include "ivas_cnst.h"
37 : #include "rom_com.h"
38 : #include "prot.h"
39 : #include "ivas_prot.h"
40 : #include "ivas_stat_com.h"
41 : #include "ivas_rom_com.h"
42 : #ifdef DEBUGGING
43 : #include "debug.h"
44 : #endif
45 : #include "wmc_auto.h"
46 :
47 :
48 : /*-----------------------------------------------------------------------*
49 : * Local constants
50 : *-----------------------------------------------------------------------*/
51 :
52 : #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC )
53 :
54 : #define BETA_ISM_LOW_IMP 0.6f
55 : #define BETA_ISM_MEDIUM_IMP 0.8f
56 :
57 : #define MAX_BRATE_TCX_32k 48000
58 :
59 :
60 : /*-------------------------------------------------------------------*
61 : * bitbudget_to_brate()
62 : *
63 : * Convert bit-budget to bitrate
64 : *-------------------------------------------------------------------*/
65 :
66 18980998 : void bitbudget_to_brate(
67 : const int16_t x[], /* i : bitbudgets */
68 : int32_t y[], /* o : bitrates */
69 : const int16_t N /* i : number of entries to be converted */
70 : )
71 : {
72 : int16_t i;
73 :
74 67061235 : for ( i = 0; i < N; i++ )
75 : {
76 48080237 : y[i] = FRAMES_PER_SEC * x[i];
77 : }
78 :
79 18980998 : return;
80 : }
81 :
82 :
83 : /*-------------------------------------------------------------------*
84 : * ivas_ism_config()
85 : *
86 : * Configure audio objects coding
87 : *-------------------------------------------------------------------*/
88 :
89 4934281 : ivas_error ivas_ism_config(
90 : const int32_t ism_total_brate, /* i : ISM total bitrate */
91 : const int16_t nchan_transport, /* i : number of transport channels */
92 : const int16_t nchan_ism, /* i : number of objects */
93 : ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
94 : const int16_t ism_extended_metadata_flag, /* i : extended metadata flag */
95 : const int16_t null_metadata_flag[MAX_NUM_OBJECTS], /* i : NULL MD flag */
96 : const int16_t ism_imp[], /* i : ISM importance flags */
97 : int32_t element_brate[], /* o : element bitrate per object */
98 : int32_t total_brate[], /* o : total bitrate per object */
99 : int16_t nb_bits_metadata[], /* i/o: number of metadata bits */
100 : const int16_t combined_format_flag /* i : flag indicating combined format */
101 : )
102 : {
103 : int16_t ch;
104 : int16_t bits_element[MAX_NUM_OBJECTS], bits_CoreCoder[MAX_NUM_OBJECTS];
105 : int16_t bits_ism, bits_side;
106 4934281 : int16_t limit_high = 0; /* just to avoid compilation warning */
107 : int16_t tmp;
108 : int16_t ism_metadata_flag_global;
109 : int16_t n_ISms;
110 : ivas_error error;
111 :
112 4934281 : error = IVAS_ERR_OK;
113 4934281 : if ( combined_format_flag )
114 : {
115 1057023 : n_ISms = nchan_ism;
116 : }
117 : else
118 : {
119 3877258 : n_ISms = nchan_transport;
120 : }
121 :
122 : /* initialization */
123 4934281 : ism_metadata_flag_global = 0;
124 4934281 : bits_side = 0;
125 4934281 : if ( hIsmMeta != NULL )
126 : {
127 16932142 : for ( ch = 0; ch < n_ISms; ch++ )
128 : {
129 12108413 : ism_metadata_flag_global |= ism_imp[ch];
130 : }
131 : }
132 :
133 : /* decision about bitrates per channel */
134 4934281 : if ( combined_format_flag )
135 : {
136 : /* combined format: decision about bitrates per channel - variable during the session (at one ivas_total_brate) */
137 1057023 : bits_ism = (int16_t) ( ism_total_brate / FRAMES_PER_SEC );
138 1057023 : set_s( bits_element, bits_ism / n_ISms, n_ISms );
139 1057023 : bits_element[n_ISms - 1] += bits_ism % n_ISms;
140 :
141 : /* ISM common signaling bits are counted in MASA MD bit-budget */
142 : }
143 : else
144 : {
145 : /* ISM format: decision about bitrates per channel - constant during the session (at one ivas_total_brate) */
146 3877258 : bits_ism = (int16_t) ( ism_total_brate / FRAMES_PER_SEC );
147 3877258 : set_s( bits_element, bits_ism / n_ISms, n_ISms );
148 3877258 : bits_element[n_ISms - 1] += bits_ism % n_ISms;
149 3877258 : bitbudget_to_brate( bits_element, element_brate, n_ISms );
150 :
151 : /* count ISm common signaling bits */
152 3877258 : if ( hIsmMeta != NULL )
153 : {
154 3793899 : nb_bits_metadata[0] += n_ISms * ISM_METADATA_FLAG_BITS + nchan_ism;
155 :
156 3793899 : if ( ism_total_brate >= ISM_EXTENDED_METADATA_BRATE )
157 : {
158 2268145 : nb_bits_metadata[0] += ISM_EXTENDED_METADATA_BITS;
159 :
160 2268145 : if ( ism_extended_metadata_flag )
161 : {
162 519538 : nb_bits_metadata[0] += ISM_METADATA_IS_NDP_BITS;
163 : }
164 : }
165 :
166 13808952 : for ( ch = 0; ch < n_ISms; ch++ )
167 : {
168 10015053 : if ( null_metadata_flag[ch] )
169 : {
170 194136 : nb_bits_metadata[0] += ISM_METADATA_MD_FLAG_BITS;
171 194136 : nb_bits_metadata[0] += ISM_METADATA_FLAG_BITS;
172 : }
173 : else
174 : {
175 9820917 : if ( ism_imp[ch] == ISM_NO_META )
176 : {
177 1502198 : nb_bits_metadata[0] += ISM_METADATA_MD_FLAG_BITS;
178 1502198 : nb_bits_metadata[0] += ISM_METADATA_INACTIVE_FLAG_BITS;
179 : }
180 : }
181 : }
182 : }
183 : }
184 :
185 : /* split metadata bitbudget equally between channels */
186 4934281 : if ( nb_bits_metadata != NULL )
187 : {
188 4823729 : bits_side = sum_s( nb_bits_metadata, n_ISms );
189 4823729 : set_s( nb_bits_metadata, bits_side / n_ISms, n_ISms );
190 4823729 : nb_bits_metadata[n_ISms - 1] += bits_side % n_ISms;
191 4823729 : v_sub_s( bits_element, nb_bits_metadata, bits_CoreCoder, n_ISms );
192 4823729 : bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms );
193 :
194 4823729 : mvs2s( nb_bits_metadata, nb_bits_metadata, n_ISms );
195 : }
196 :
197 : /* assign less CoreCoder bit-budget to inactive streams (at least one stream must be active) */
198 4934281 : if ( ism_metadata_flag_global )
199 : {
200 : int16_t diff, n_higher, flag_higher[MAX_NUM_OBJECTS];
201 :
202 4721670 : set_s( flag_higher, 1, MAX_NUM_OBJECTS );
203 :
204 4721670 : diff = 0;
205 16606962 : for ( ch = 0; ch < n_ISms; ch++ )
206 : {
207 11885292 : if ( ism_imp[ch] == ISM_NO_META )
208 : {
209 1448433 : diff += bits_CoreCoder[ch] - BITS_ISM_INACTIVE;
210 1448433 : bits_CoreCoder[ch] = BITS_ISM_INACTIVE;
211 1448433 : flag_higher[ch] = 0;
212 : }
213 : }
214 :
215 4721670 : n_higher = sum_s( flag_higher, n_ISms );
216 :
217 4721670 : if ( diff > 0 && n_higher > 0 )
218 : {
219 795029 : tmp = diff / n_higher;
220 3554839 : for ( ch = 0; ch < n_ISms; ch++ )
221 : {
222 2759810 : if ( flag_higher[ch] )
223 : {
224 1311377 : bits_CoreCoder[ch] += tmp;
225 : }
226 : }
227 :
228 795029 : tmp = diff % n_higher;
229 795029 : ch = 0;
230 1355015 : while ( flag_higher[ch] == 0 )
231 : {
232 559986 : ch++;
233 : }
234 795029 : bits_CoreCoder[ch] += tmp;
235 : }
236 :
237 4721670 : bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms );
238 :
239 4721670 : diff = 0;
240 16606962 : for ( ch = 0; ch < n_ISms; ch++ )
241 : {
242 : int16_t limit;
243 :
244 11885292 : limit = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC;
245 11885292 : if ( element_brate[ch] < MIN_BRATE_SWB_STEREO ) /* replicate function set_bw() -> check the coded audio band-width */
246 : {
247 1131736 : limit = MIN_BRATE_WB_BWE / FRAMES_PER_SEC;
248 : }
249 10753556 : else if ( element_brate[ch] >= SCE_CORE_16k_LOW_LIMIT ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */
250 : {
251 : /*limit = SCE_CORE_16k_LOW_LIMIT;*/
252 8485043 : limit = ( ACELP_16k_LOW_LIMIT + SWB_TBE_1k6 ) / FRAMES_PER_SEC;
253 : }
254 :
255 11885292 : if ( ism_imp[ch] == ISM_NO_META )
256 : {
257 1448433 : tmp = BITS_ISM_INACTIVE;
258 : }
259 10436859 : else if ( ism_imp[ch] == ISM_LOW_IMP )
260 : {
261 1744434 : tmp = (int16_t) ( BETA_ISM_LOW_IMP * bits_CoreCoder[ch] );
262 1744434 : tmp = max( limit, tmp );
263 : }
264 8692425 : else if ( ism_imp[ch] == ISM_MEDIUM_IMP )
265 : {
266 2842488 : tmp = (int16_t) ( BETA_ISM_MEDIUM_IMP * bits_CoreCoder[ch] );
267 2842488 : tmp = max( limit, tmp );
268 : }
269 : else /* ism_imp[ch] == ISM_HIGH_IMP */
270 : {
271 5849937 : tmp = bits_CoreCoder[ch];
272 : }
273 :
274 11885292 : diff += bits_CoreCoder[ch] - tmp;
275 11885292 : bits_CoreCoder[ch] = tmp;
276 : }
277 :
278 4721670 : if ( diff > 0 && n_higher > 0 )
279 : {
280 2925346 : tmp = diff / n_higher;
281 11017679 : for ( ch = 0; ch < n_ISms; ch++ )
282 : {
283 8092333 : if ( flag_higher[ch] )
284 : {
285 7229358 : bits_CoreCoder[ch] += tmp;
286 : }
287 : }
288 :
289 2925346 : tmp = diff % n_higher;
290 2925346 : ch = 0;
291 3219539 : while ( flag_higher[ch] == 0 )
292 : {
293 294193 : ch++;
294 : }
295 2925346 : bits_CoreCoder[ch] += tmp;
296 : }
297 :
298 : /* verify for the maximum bitrate @12.8kHz core */
299 4721670 : diff = 0;
300 16606962 : for ( ch = 0; ch < n_ISms; ch++ )
301 : {
302 11885292 : limit_high = IVAS_512k / FRAMES_PER_SEC;
303 11885292 : if ( element_brate[ch] < SCE_CORE_16k_LOW_LIMIT ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */
304 : {
305 3400249 : limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
306 : }
307 :
308 11885292 : tmp = (int16_t) min( bits_CoreCoder[ch], limit_high );
309 :
310 11885292 : diff += bits_CoreCoder[ch] - tmp;
311 11885292 : bits_CoreCoder[ch] = tmp;
312 : }
313 :
314 : /* limitation to avoid too high bitrate in one active TCX channel */
315 4721670 : if ( element_brate[0] >= SCE_CORE_16k_LOW_LIMIT && element_brate[0] <= IVAS_32k )
316 : {
317 1189169 : diff = 0;
318 1189169 : limit_high = MAX_BRATE_TCX_32k / FRAMES_PER_SEC;
319 :
320 4748846 : for ( ch = 0; ch < n_ISms; ch++ )
321 : {
322 3559677 : tmp = (int16_t) min( bits_CoreCoder[ch], limit_high );
323 :
324 3559677 : diff += bits_CoreCoder[ch] - tmp;
325 3559677 : bits_CoreCoder[ch] = tmp;
326 : }
327 : }
328 :
329 4721670 : if ( diff > 0 )
330 : {
331 418238 : ch = 0;
332 727697 : for ( ch = 0; ch < n_ISms; ch++ )
333 : {
334 727697 : if ( flag_higher[ch] == 0 )
335 : {
336 499940 : if ( diff > limit_high )
337 : {
338 81702 : diff += bits_CoreCoder[ch] - limit_high;
339 81702 : bits_CoreCoder[ch] = limit_high;
340 : }
341 : else
342 : {
343 418238 : bits_CoreCoder[ch] += diff;
344 : #ifdef DEBUGGING
345 : if ( bits_CoreCoder[ch] == SID_2k40 / FRAMES_PER_SEC )
346 : {
347 : printf( "\nWarning: ISM bitbudget equal to SID!\n" );
348 : }
349 : #endif
350 :
351 418238 : if ( combined_format_flag )
352 : {
353 2626 : diff = 0;
354 : }
355 418238 : break;
356 : }
357 : }
358 : }
359 : }
360 :
361 4721670 : if ( combined_format_flag )
362 : {
363 1016549 : if ( diff > 0 )
364 : {
365 0 : for ( ch = 0; ch < n_ISms; ch++ )
366 : {
367 0 : if ( ism_imp[ch] <= ISM_MEDIUM_IMP )
368 : {
369 0 : if ( diff > limit_high )
370 : {
371 0 : diff += bits_CoreCoder[ch] - limit_high;
372 0 : bits_CoreCoder[ch] = limit_high;
373 : }
374 : else
375 : {
376 0 : bits_CoreCoder[ch] += diff;
377 0 : break;
378 : }
379 : }
380 : }
381 : }
382 : }
383 :
384 4721670 : bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms );
385 : }
386 :
387 : #ifdef DEBUGGING
388 : if ( nb_bits_metadata != NULL )
389 : {
390 : int32_t tmpL;
391 : tmpL = sum_l( total_brate, n_ISms ) + bits_side * FRAMES_PER_SEC;
392 : if ( ism_total_brate != tmpL )
393 : {
394 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "\nError: Mismatch in ISM bit-budget distribution. Exiting!\n" );
395 : }
396 : }
397 : #endif
398 :
399 4934281 : return error;
400 : }
401 :
402 :
403 : /*-------------------------------------------------------------------*
404 : * ivas_ism_reset_metadata()
405 : *
406 : * Reset ISM metadata parameters
407 : *-------------------------------------------------------------------*/
408 :
409 658310 : void ivas_ism_reset_metadata(
410 : ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */
411 : )
412 : {
413 658310 : hIsmMeta->azimuth = 0.0f;
414 658310 : hIsmMeta->elevation = 0.0f;
415 658310 : hIsmMeta->yaw = 0.0f;
416 658310 : hIsmMeta->pitch = 0.0f;
417 658310 : hIsmMeta->radius = 1.0f;
418 658310 : hIsmMeta->ism_metadata_flag = 0;
419 658310 : hIsmMeta->non_diegetic_flag = 0;
420 :
421 658310 : hIsmMeta->edited_gain = 1.0f;
422 658310 : hIsmMeta->edited_azimuth = 0.0f;
423 658310 : hIsmMeta->edited_elevation = 0.0f;
424 658310 : hIsmMeta->edited_pitch = 0.0f;
425 658310 : hIsmMeta->edited_yaw = 0.0f;
426 658310 : hIsmMeta->edited_radius = 1.0f;
427 658310 : hIsmMeta->gain = 1.0f;
428 658310 : hIsmMeta->non_diegetic_flag = 0;
429 :
430 658310 : return;
431 : }
432 :
433 :
434 : /*-------------------------------------------------------------------*
435 : * ivas_ism_reset_metadata_API()
436 : *
437 : * Reset ISM metadata parameters
438 : *-------------------------------------------------------------------*/
439 :
440 61810 : void ivas_ism_reset_metadata_API(
441 : ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */
442 : )
443 : {
444 61810 : ivas_ism_reset_metadata( hIsmMeta );
445 :
446 61810 : return;
447 : }
448 :
449 :
450 : /*-------------------------------------------------------------------*
451 : * ism_quant_meta()
452 : *
453 : * three-level uniform scalar quantizer for ISM metadata
454 : *-------------------------------------------------------------------*/
455 :
456 : /*! r: index of the winning codeword */
457 7737119 : int16_t ism_quant_meta(
458 : const float val, /* i : scalar value to quantize */
459 : float *valQ, /* o : quantized value */
460 : const float borders[], /* i : level borders */
461 : const float q_step, /* i : quantization step */
462 : const float q_step_border, /* i : quantization step at the border */
463 : const int16_t cbsize /* i : codebook size */
464 : )
465 : {
466 : int16_t idx, idx_start;
467 : float qlow, step;
468 :
469 7737119 : if ( val <= borders[1] )
470 : {
471 612183 : qlow = borders[0];
472 612183 : idx_start = 0;
473 612183 : step = q_step_border;
474 : }
475 7124936 : else if ( val <= borders[2] )
476 : {
477 6419576 : qlow = borders[1];
478 6419576 : idx_start = (int16_t) ( ( borders[1] - borders[0] ) / q_step_border );
479 6419576 : step = q_step;
480 : }
481 : else
482 : {
483 705360 : qlow = borders[2];
484 705360 : idx_start = (int16_t) ( cbsize - 1 - ( borders[3] - borders[2] ) / q_step_border );
485 705360 : step = q_step_border;
486 : }
487 :
488 7737119 : idx = idx_start + (int16_t) max( 0.f, min( cbsize - 1, ( ( val - qlow ) / step + 0.5f ) ) );
489 7737119 : *valQ = ( idx - idx_start ) * step + qlow;
490 :
491 7737119 : return idx;
492 : }
493 :
494 :
495 : /*-------------------------------------------------------------------*
496 : * ism_dequant_meta()
497 : *
498 : * three-level uniform scalar dequantizer for ISM metadata
499 : *-------------------------------------------------------------------*/
500 :
501 : /*! r: dequantized value */
502 28527729 : float ism_dequant_meta(
503 : const int16_t idx, /* i : quantizer index */
504 : const float borders[], /* i : level borders */
505 : const float q_step, /* i : quantization step */
506 : const float q_step_border, /* i : quantization step at the border */
507 : const int16_t cbsize /* i : codebook size */
508 : )
509 : {
510 : int16_t idx_start;
511 : float qlow, step, valQ;
512 :
513 28527729 : if ( idx <= ( borders[1] - borders[0] ) / q_step_border )
514 : {
515 3164679 : qlow = borders[0];
516 3164679 : idx_start = 0;
517 3164679 : step = q_step_border;
518 : }
519 25363050 : else if ( idx <= cbsize - 1 - ( borders[3] - borders[2] ) / q_step_border )
520 : {
521 23236740 : qlow = borders[1];
522 23236740 : idx_start = (int16_t) ( ( borders[1] - borders[0] ) / q_step_border );
523 23236740 : step = q_step;
524 : }
525 : else
526 : {
527 2126310 : qlow = borders[2];
528 2126310 : idx_start = (int16_t) ( cbsize - 1 - ( borders[3] - borders[2] ) / q_step_border );
529 2126310 : step = q_step_border;
530 : }
531 :
532 28527729 : valQ = ( idx - idx_start ) * step + qlow;
533 :
534 28527729 : return valQ;
535 : }
536 :
537 :
538 : /*---------------------------------------------------------------
539 : * ivas_param_ism_config()
540 : *
541 : *
542 : * ---------------------------------------------------------------*/
543 :
544 11422 : void ivas_param_ism_config(
545 : PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */
546 : const int16_t nchan_obj /* i : number of ISM channels */
547 : )
548 : {
549 : int16_t i;
550 :
551 11422 : hParamIsm->nbands = MAX_PARAM_ISM_NBANDS;
552 :
553 137064 : for ( i = 0; i < hParamIsm->nbands; i++ )
554 : {
555 125642 : hParamIsm->nblocks[i] = MAX_PARAM_ISM_NBLOCKS;
556 : }
557 :
558 : /* for elevation zero compute the max azi quantization indices */
559 53935 : for ( i = 0; i < nchan_obj; i++ )
560 : {
561 42513 : hParamIsm->last_az_diff[i] = 0;
562 42513 : hParamIsm->last_az_sgn[i] = 1;
563 42513 : hParamIsm->last_el_diff[i] = 0;
564 42513 : hParamIsm->last_el_sgn[i] = 1;
565 : }
566 :
567 11422 : hParamIsm->last_dmx_gain = 1.0f;
568 11422 : set_f( hParamIsm->last_cardioid_left, 1.0f, MAX_NUM_OBJECTS );
569 :
570 11422 : return;
571 : }
572 :
573 :
574 : /*---------------------------------------------------------------
575 : * ivas_ism_mode_select()
576 : *
577 : * selects the ISM mode base on bitrate and number of objects
578 : * ---------------------------------------------------------------*/
579 :
580 : /*! r : ISM format mode */
581 9736787 : ISM_MODE ivas_ism_mode_select(
582 : const int16_t nchan_inp, /* i : number of input objects */
583 : const int32_t ivas_total_brate /* i : IVAS total bitrate */
584 : )
585 : {
586 9736787 : ISM_MODE ism_mode = ISM_MODE_NONE;
587 :
588 9736787 : if ( nchan_inp > 2 && ivas_total_brate <= ACELP_32k )
589 : {
590 1721927 : ism_mode = ISM_MODE_PARAM;
591 : }
592 : else
593 : {
594 8014860 : ism_mode = ISM_MODE_DISC;
595 : }
596 :
597 9736787 : return ism_mode;
598 : }
599 :
600 :
601 : /*---------------------------------------------------------------
602 : * ivas_ism_metadata_close()
603 : *
604 : * Deallocate ISM metadata handles
605 : * ---------------------------------------------------------------*/
606 :
607 104024 : void ivas_ism_metadata_close(
608 : ISM_METADATA_HANDLE hIsmMetaData[], /* i/o: object metadata handles */
609 : const int16_t first_idx /* i : index of first handle to deallocate */
610 : )
611 : {
612 : int16_t n;
613 :
614 104024 : if ( hIsmMetaData == NULL || *hIsmMetaData == NULL )
615 : {
616 55145 : return;
617 : }
618 :
619 244395 : for ( n = first_idx; n < MAX_NUM_OBJECTS; n++ )
620 : {
621 195516 : if ( hIsmMetaData[n] != NULL )
622 : {
623 128581 : free( hIsmMetaData[n] );
624 128581 : hIsmMetaData[n] = NULL;
625 : }
626 : }
627 :
628 48879 : return;
629 : }
630 :
631 :
632 : /*-------------------------------------------------------------------*
633 : * update_last_metadata()
634 : *
635 : * Store last metadata values
636 : *-------------------------------------------------------------------*/
637 :
638 6692189 : void update_last_metadata(
639 : const int16_t nchan_ism, /* i : number of objects */
640 : ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */
641 : const int16_t updt_flag[] /* i : last metadata update flag */
642 : )
643 : {
644 : int16_t ch;
645 :
646 25101769 : for ( ch = 0; ch < nchan_ism; ch++ )
647 : {
648 18409580 : if ( updt_flag[ch] == 1 )
649 : {
650 18379279 : hIsmMeta[ch]->last_azimuth = hIsmMeta[ch]->azimuth;
651 18379279 : hIsmMeta[ch]->last_elevation = hIsmMeta[ch]->elevation;
652 : }
653 : }
654 :
655 6692189 : return;
656 : }
657 :
658 :
659 : /*----------------------------------------------------------------*
660 : * ivas_get_ism_sid_quan_bitbudget()
661 : *
662 : * Set quantization bits based on the number of coded objects
663 : *----------------------------------------------------------------*/
664 :
665 29700 : void ivas_get_ism_sid_quan_bitbudget(
666 : const int16_t nchan_ism, /* i : number of objects */
667 : int16_t *nBits_azimuth, /* o : number of Q bits for azimuth */
668 : int16_t *nBits_elevation, /* o : number of Q bits for elevation */
669 : float *q_step, /* o : quantization step */
670 : float *q_step_border, /* o : quantization step at the border */
671 : int16_t *nBits_coh, /* o : number of Q bits for coherence */
672 : int16_t *nBits_sce_id /* o : number of Q bits for sce_id_dtx */
673 : )
674 : {
675 29700 : *nBits_azimuth = ISM_DTX_AZI_BITS_HIGH;
676 29700 : *nBits_elevation = ISM_DTX_ELE_BITS_HIGH;
677 29700 : *q_step = ISM_Q_STEP_HIGH;
678 29700 : *q_step_border = ISM_Q_STEP_BORDER_HIGH;
679 29700 : *nBits_coh = ISM_DTX_COH_SCA_BITS;
680 29700 : *nBits_sce_id = 1;
681 :
682 29700 : if ( nchan_ism >= 3 )
683 : {
684 13467 : *nBits_azimuth = ISM_DTX_AZI_BITS_LOW;
685 13467 : *nBits_elevation = ISM_DTX_ELE_BITS_LOW;
686 13467 : *q_step = ISM_Q_STEP_LOW;
687 13467 : *q_step_border = ISM_Q_STEP_BORDER_LOW;
688 13467 : *nBits_sce_id = 2;
689 : }
690 :
691 29700 : return;
692 : }
|