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 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #include <math.h>
40 : #include "prot_fx.h"
41 : #include "wmc_auto.h"
42 :
43 : /*------------------------------------------------------------------*
44 : * own_random()
45 : *
46 : * Random generator
47 : *------------------------------------------------------------------*/
48 :
49 : /*! r: output random value */
50 293660515 : Word16 own_random(
51 : Word16 *seed /* i/o: random seed */
52 : )
53 : {
54 293660515 : *seed = (Word16) ( *seed * 31821L + 13849L );
55 :
56 293660515 : return ( *seed );
57 : }
58 :
59 : /*---------------------------------------------------------------------
60 : * norm_ul_float()
61 : *
62 : *---------------------------------------------------------------------*/
63 :
64 0 : Word16 norm_ul_float( UWord32 UL_var1 )
65 : {
66 : Word16 var_out;
67 :
68 0 : if ( UL_var1 == 0 )
69 : {
70 0 : var_out = 0;
71 : }
72 : else
73 : {
74 0 : for ( var_out = 0; UL_var1 < (UWord32) 0x80000000U; var_out++ )
75 : {
76 0 : UL_var1 <<= 1;
77 : }
78 : }
79 : BASOP_CHECK();
80 :
81 0 : return ( var_out );
82 : }
83 :
84 :
85 : /*---------------------------------------------------------------------
86 : * sum_s()
87 : * sum_l()
88 : * sum_f()
89 : *
90 : *---------------------------------------------------------------------*/
91 :
92 : /*! r: sum of all vector elements */
93 8526 : Word16 sum_s(
94 : const Word16 *vec, /* i : input vector */
95 : const Word16 lvec /* i : length of input vector */
96 : )
97 : {
98 : Word16 i;
99 : Word16 tmp;
100 :
101 8526 : tmp = 0;
102 212428 : for ( i = 0; i < lvec; i++ )
103 : {
104 203902 : tmp += vec[i];
105 : }
106 :
107 8526 : return tmp;
108 : }
109 :
110 : /*! r: sum of all vector elements */
111 0 : Word32 sum_l_fx(
112 : const Word32 *vec, /* i : input vector */
113 : const Word16 lvec /* i : length of input vector */
114 : )
115 : {
116 : Word16 i;
117 : Word32 tmpL;
118 :
119 0 : tmpL = 0;
120 0 : move32();
121 0 : FOR( i = 0; i < lvec; i++ )
122 : {
123 0 : tmpL = L_add( tmpL, vec[i] );
124 : }
125 :
126 0 : return tmpL;
127 : }
128 :
129 : /*----------------------------------------------------------------------
130 : * sum2_f()
131 : *
132 : *---------------------------------------------------------------------*/
133 :
134 : /*! r: sum of all squared vector elements */
135 828 : Word32 sum2_f_16_fx(
136 : const Word16 *vec, /* i : input vector */
137 : const Word16 lvec /* i : length of input vector */
138 : )
139 : {
140 : Word16 i;
141 : Word32 tmp;
142 :
143 828 : tmp = 0;
144 828 : move32();
145 14076 : FOR( i = 0; i < lvec; i++ )
146 : {
147 13248 : tmp = L_add( tmp, L_mult0( vec[i], vec[i] ) );
148 : }
149 :
150 828 : return tmp;
151 : }
152 0 : Word32 sum2_f_16_gb_fx(
153 : const Word16 *vec, /* i : input vector */
154 : const Word16 lvec, /* i : length of input vector */
155 : Word16 gb )
156 : {
157 : Word16 i;
158 : Word32 tmp;
159 :
160 0 : tmp = 0;
161 0 : FOR( i = 0; i < lvec; i++ )
162 : {
163 0 : tmp = L_add( tmp, L_shr( L_mult0( vec[i], vec[i] ), gb ) );
164 : }
165 :
166 0 : return tmp;
167 : }
168 :
169 0 : Word32 sum2_16_exp_fx(
170 : const Word16 *vec, /* i : input vector Q(15 - exp) */
171 : const Word16 lvec, /* i : length of input vector */
172 : Word16 *exp, /* i/o: exponent of vector */
173 : Word16 gb /* i : guard bits */
174 : )
175 : {
176 : Word16 i, s;
177 : Word32 L_tmp, var_a;
178 :
179 0 : L_tmp = 0;
180 0 : move32();
181 0 : var_a = 0;
182 0 : move32();
183 0 : FOR( i = 0; i < lvec; i++ )
184 : {
185 0 : var_a = L_mult0( vec[i], vec[i] ); /* 2 * Q(15 - exp) */
186 0 : L_tmp = L_add( L_tmp, L_shr( var_a, gb ) ); /* 2 * Q(15 - exp) - gb */
187 : }
188 :
189 0 : s = norm_l( L_tmp );
190 0 : L_tmp = L_shl( L_tmp, s ); /* 2 * Q(15 - exp) - gb + s */
191 :
192 0 : *exp = add( sub( add( shl( *exp, 1 ), gb ), s ), 1 );
193 0 : move16();
194 :
195 0 : return L_tmp;
196 : }
197 :
198 0 : Word32 sum2_32_exp_fx(
199 : const Word32 *vec, /* i : input vector, Qx */
200 : const Word16 lvec, /* i : length of input vector */
201 : Word16 *exp, /* i/o: exponent of vector */
202 : Word16 gb /* i : guard bits */
203 : )
204 : {
205 : Word16 i, s, norm;
206 : Word64 W_tmp;
207 :
208 0 : W_tmp = 0;
209 0 : Word64 var_a = 0;
210 0 : move64();
211 0 : move64();
212 :
213 0 : norm = L_norm_arr( vec, lvec );
214 :
215 0 : gb = sub( gb, norm );
216 :
217 0 : FOR( i = 0; i < lvec; i++ )
218 : {
219 0 : var_a = W_mult0_32_32( vec[i], vec[i] ); // 2x
220 0 : W_tmp = W_add( W_tmp, W_shr( var_a, gb ) ); // 2x-gb
221 : }
222 :
223 0 : s = W_norm( W_tmp );
224 0 : W_tmp = W_shl( W_tmp, s ); // 2x - gb + s
225 :
226 : //*exp = 31 - (2*(31 - *exp) - gb + s) + 32;
227 0 : *exp = add( sub( add( shl( *exp, 1 ), gb ), s ), 1 );
228 0 : move16();
229 :
230 0 : return W_extract_h( W_tmp );
231 : }
232 :
233 10274032 : Word32 sum2_f_32_fx( /* o : Q(2x - 31 - gb) */
234 : const Word32 *vec, /* i : input vector, Qx */
235 : const Word16 lvec, /* i : length of input vector */
236 : Word16 gb /* i : guard bits */
237 : )
238 : {
239 : Word16 i;
240 : Word32 tmp;
241 :
242 10274032 : tmp = 0;
243 10274032 : Word32 var_a = 0;
244 10274032 : move32();
245 10274032 : move32();
246 108108924 : FOR( i = 0; i < lvec; i++ )
247 : {
248 97834892 : var_a = Mpy_32_32( vec[i], vec[i] ); // 2x-31
249 97834892 : tmp = L_add( tmp, L_shr( var_a, gb ) ); // 2x-31-gb
250 : }
251 :
252 10274032 : return tmp;
253 : }
254 :
255 75796 : Word32 sum2_32_fx(
256 : const Word32 *vec, /* i : input vector */
257 : const Word16 lvec, /* i : length of input vector */
258 : Word16 *e )
259 : {
260 : Word16 i;
261 : Word32 tmp;
262 :
263 75796 : tmp = 0;
264 75796 : Word32 var_a = 0;
265 75796 : Word16 exp = 0, exp_tmp;
266 75796 : move32();
267 75796 : move32();
268 75796 : move16();
269 64720596 : FOR( i = 0; i < lvec; i++ )
270 : {
271 64644800 : exp_tmp = norm_l( vec[i] );
272 64644800 : var_a = L_shl( vec[i], exp_tmp );
273 64644800 : var_a = Mpy_32_32( var_a, var_a );
274 64644800 : exp_tmp = shl( sub( *e, exp_tmp ), 1 );
275 64644800 : tmp = BASOP_Util_Add_Mant32Exp( tmp, exp, var_a, exp_tmp, &exp );
276 : }
277 75796 : *e = exp;
278 75796 : move16();
279 :
280 75796 : return tmp;
281 : }
282 :
283 : /*-------------------------------------------------------------------*
284 : * set_c()
285 : * set_s()
286 : * set_l()
287 : * set_d()
288 : *
289 : * Set the vector elements to a value
290 : *-------------------------------------------------------------------*/
291 :
292 116820 : void set_c(
293 : Word8 y[], /* i/o: Vector to set */
294 : const Word8 a, /* i : Value to set the vector to */
295 : const Word32 N /* i : Length of the vector */
296 : )
297 : {
298 : Word16 i;
299 :
300 692449 : for ( i = 0; i < N; i++ )
301 : {
302 575629 : y[i] = a;
303 : }
304 :
305 116820 : return;
306 : }
307 :
308 :
309 428 : void set_s(
310 : Word16 y[], /* i/o: Vector to set */
311 : const Word16 a, /* i : Value to set the vector to */
312 : const Word16 N /* i : Length of the vector */
313 : )
314 : {
315 : Word16 i;
316 :
317 8220 : for ( i = 0; i < N; i++ )
318 : {
319 7792 : y[i] = a;
320 : }
321 :
322 428 : return;
323 : }
324 :
325 :
326 0 : void set_l(
327 : Word32 y[], /* i/o: Vector to set */
328 : const Word32 a, /* i : Value to set the vector to */
329 : const Word16 N /* i : Length of the vector */
330 : )
331 : {
332 : Word16 i;
333 :
334 0 : for ( i = 0; i < N; i++ )
335 : {
336 0 : y[i] = a;
337 : }
338 :
339 0 : return;
340 : }
341 :
342 : /*---------------------------------------------------------------------*
343 : * set_zero()
344 : *
345 : * Set a vector vec[] of dimension lvec to zero
346 : *---------------------------------------------------------------------*/
347 :
348 620 : void set_zero(
349 : float *vec, /* o : input vector */
350 : const Word16 lvec /* i : length of the vector */
351 : )
352 : {
353 : Word16 i;
354 :
355 10540 : for ( i = 0; i < lvec; i++ )
356 : {
357 9920 : *vec++ = 0.0f;
358 : }
359 :
360 620 : return;
361 : }
362 :
363 :
364 : /*---------------------------------------------------------------------*
365 : * mvr2r()
366 : * mvs2s()
367 : * mvr2d()
368 : * mvd2r()
369 : *
370 : * Transfer the contents of vector x[] to vector y[]
371 : *---------------------------------------------------------------------*/
372 :
373 322 : void mvr2r(
374 : const float x[], /* i : input vector */
375 : float y[], /* o : output vector */
376 : const Word16 n /* i : vector size */
377 : )
378 : {
379 : Word16 i;
380 :
381 322 : if ( n <= 0 )
382 : {
383 : /* cannot transfer vectors with size 0 */
384 0 : return;
385 : }
386 :
387 322 : if ( y < x )
388 : {
389 0 : for ( i = 0; i < n; i++ )
390 : {
391 0 : y[i] = x[i];
392 : }
393 : }
394 : else
395 : {
396 5318 : for ( i = n - 1; i >= 0; i-- )
397 : {
398 4996 : y[i] = x[i];
399 : }
400 : }
401 :
402 322 : return;
403 : }
404 :
405 0 : void mvs2s(
406 : const Word16 x[], /* i : input vector */
407 : Word16 y[], /* o : output vector */
408 : const Word16 n /* i : vector size */
409 : )
410 : {
411 : Word16 i;
412 :
413 0 : if ( n <= 0 )
414 : {
415 : /* cannot transfer vectors with size 0 */
416 0 : return;
417 : }
418 :
419 0 : if ( y < x )
420 : {
421 0 : for ( i = 0; i < n; i++ )
422 : {
423 0 : y[i] = x[i];
424 : }
425 : }
426 : else
427 : {
428 0 : for ( i = n - 1; i >= 0; i-- )
429 : {
430 0 : y[i] = x[i];
431 : }
432 : }
433 :
434 0 : return;
435 : }
436 :
437 0 : void mvl2l(
438 : const Word32 x[], /* i : input vector */
439 : Word32 y[], /* o : output vector */
440 : const Word16 n /* i : vector size */
441 : )
442 : {
443 : Word16 i;
444 :
445 0 : if ( n <= 0 )
446 : {
447 : /* no need to transfer vectors with size 0 */
448 0 : return;
449 : }
450 :
451 0 : if ( y < x )
452 : {
453 0 : for ( i = 0; i < n; i++ )
454 : {
455 0 : y[i] = x[i];
456 : }
457 : }
458 : else
459 : {
460 0 : for ( i = n - 1; i >= 0; i-- )
461 : {
462 0 : y[i] = x[i];
463 : }
464 : }
465 :
466 0 : return;
467 : }
468 :
469 : /*! r: index of the maximum value in the input vector */
470 10917 : Word16 maximum_s(
471 : const Word16 *vec, /* i : input vector */
472 : const Word16 lvec, /* i : length of input vector */
473 : Word16 *max /* o : maximum value in the input vector */
474 : )
475 : {
476 : Word16 i, ind;
477 : Word16 tmp;
478 :
479 10917 : ind = 0;
480 10917 : move16();
481 10917 : tmp = vec[0];
482 10917 : move16();
483 :
484 34057 : FOR( i = 1; i < lvec; i++ )
485 : {
486 23140 : IF( GT_16( vec[i], tmp ) )
487 : {
488 4070 : ind = i;
489 4070 : move16();
490 4070 : tmp = vec[i];
491 4070 : move16();
492 : }
493 : }
494 :
495 10917 : if ( max != NULL )
496 : {
497 4741 : *max = tmp;
498 4741 : move16();
499 : }
500 :
501 10917 : return ind;
502 : }
503 :
504 : /*! r: index of the maximum value in the input vector */
505 16650 : Word16 maximum_l(
506 : const Word32 *vec, /* i : input vector */
507 : const Word16 lvec, /* i : length of input vector */
508 : Word32 *max_val /* o : maximum value in the input vector */
509 : )
510 : {
511 : Word16 i, ind;
512 : Word32 tmp;
513 :
514 16650 : ind = 0;
515 16650 : tmp = vec[0];
516 16650 : move16();
517 16650 : move32();
518 64167 : FOR( i = 1; i < lvec; i++ )
519 : {
520 47517 : IF( GT_32( vec[i], tmp ) )
521 : {
522 11686 : ind = i;
523 11686 : tmp = vec[i];
524 11686 : move16();
525 11686 : move32();
526 : }
527 : }
528 :
529 16650 : if ( max_val != NULL )
530 : {
531 16650 : *max_val = tmp;
532 16650 : move32();
533 : }
534 :
535 16650 : return ind;
536 : }
537 :
538 : /*! r: index of the maximum value in the input vector */
539 0 : Word16 maximumAbs_l(
540 : const Word32 *vec, /* i : input vector */
541 : const Word16 lvec, /* i : length of input vector */
542 : Word32 *max_val /* o : maximum value in the input vector */
543 : )
544 : {
545 : Word16 j, ind;
546 : Word32 tmp;
547 :
548 0 : ind = 0;
549 0 : move16();
550 0 : tmp = L_abs( vec[0] );
551 :
552 0 : FOR( j = 1; j < lvec; j++ )
553 : {
554 0 : IF( GT_32( L_abs( vec[j] ), tmp ) )
555 : {
556 0 : ind = j;
557 0 : move16();
558 0 : tmp = L_abs( vec[j] );
559 : }
560 : }
561 :
562 0 : IF( max_val != NULL )
563 : {
564 0 : *max_val = tmp;
565 0 : move32();
566 : }
567 :
568 0 : return ind;
569 : }
570 :
571 : /*-------------------------------------------------------------------*
572 : * minimum_s()
573 : *
574 : * Finds minimum 16-bit signed integer value in the array and returns it.
575 : *-------------------------------------------------------------------*/
576 :
577 : /*! r: index of the minimum value in the input vector */
578 85136139 : Word16 minimum_s(
579 : const Word16 *vec, /* i : Input vector */
580 : const Word16 lvec, /* i : Vector length */
581 : Word16 *min_val /* o : minimum value in the input vector */
582 : )
583 : {
584 : Word16 i, ind;
585 :
586 85136139 : ind = 0;
587 85136139 : move16();
588 :
589 397285572 : FOR( i = 1; i < lvec; i++ )
590 : {
591 312149433 : if ( LT_16( vec[i], vec[ind] ) )
592 : {
593 30266551 : ind = i;
594 30266551 : move16();
595 : }
596 : }
597 :
598 85136139 : if ( min_val != NULL )
599 : {
600 85136139 : *min_val = vec[ind];
601 85136139 : move16();
602 : }
603 :
604 85136139 : return ind;
605 : }
606 :
607 : /*-------------------------------------------------------------------*
608 : * minimum_l()
609 : *
610 : * Finds minimum 16-bit signed integer value in the array and returns it.
611 : *-------------------------------------------------------------------*/
612 :
613 : /*! r: index of the minimum value in the input vector */
614 79062 : Word16 minimum_l(
615 : const Word32 *vec, /* i : Input vector */
616 : const Word16 lvec, /* i : Vector length */
617 : Word32 *min_val /* o : minimum value in the input vector */
618 : )
619 : {
620 : Word16 i, ind;
621 :
622 79062 : ind = 0;
623 79062 : move16();
624 :
625 1592738 : FOR( i = 1; i < lvec; i++ )
626 : {
627 1513676 : if ( LT_32( vec[i], vec[ind] ) )
628 : {
629 318348 : ind = i;
630 318348 : move16();
631 : }
632 : }
633 :
634 79062 : if ( min_val != NULL )
635 : {
636 79062 : *min_val = vec[ind];
637 79062 : move32();
638 : }
639 :
640 79062 : return ind;
641 : }
642 :
643 : /*---------------------------------------------------------------------*
644 : * dotp()
645 : *
646 : * Dot product of vector x[] and vector y[]
647 : *---------------------------------------------------------------------*/
648 :
649 : /*! r: dot product of x[] and y[] */
650 13399550 : Word32 dotp_fixed(
651 : const Word32 x[], /* i : vector x[] Qx */
652 : const Word32 y[], /* i : vector y[] Qy */
653 : const Word16 n /* i : vector length */
654 : )
655 : {
656 : Word16 i;
657 : Word32 suma;
658 :
659 13399550 : suma = Mpy_32_32( x[0], y[0] );
660 :
661 35342958 : FOR( i = 1; i < n; i++ )
662 : {
663 21943408 : suma = L_add( suma, Mpy_32_32( x[i], y[i] ) );
664 : }
665 :
666 13399550 : return suma;
667 : }
668 :
669 : /*To calculate dot product of two 32 bit arrays in case of overflow*/
670 3466 : Word32 dotp_fixed_o(
671 : const Word32 x[], /* i : vector x[] */
672 : const Word32 y[], /* i : vector y[] */
673 : const Word16 n, /* i : vector length */
674 : const Word16 log_len, /* i : max factor added to result q after dot product (equal to log2(n)) */
675 : Word16 *res_q /*stores resultant Q*/
676 : )
677 : {
678 : Word16 i;
679 : Word64 suma; /*resultant q= q(x)+q(y)-9-x such that q<=31*/
680 :
681 3466 : suma = W_shr( W_mult_32_32( x[0], y[0] ), log_len );
682 :
683 906860 : FOR( i = 1; i < n; i++ )
684 : {
685 903394 : suma = W_add( suma, W_shr( W_mult_32_32( x[i], y[i] ), log_len ) );
686 : }
687 3466 : *res_q = add( sub( *res_q, log_len ), 1 );
688 3466 : move16();
689 3466 : test();
690 3466 : test();
691 68481 : WHILE( GT_64( suma, MAX_32 ) || LT_64( suma, MIN_32 ) || GT_16( *res_q, 31 ) )
692 : {
693 65015 : suma = W_shr( suma, 1 );
694 65015 : *res_q = sub( *res_q, 1 );
695 65015 : move16();
696 : }
697 3466 : return W_extract_l( suma );
698 : }
699 :
700 0 : Word32 dotp_fixed_32(
701 : const Word32 x[], /* i : vector x[] */
702 : const Word32 y[], /* i : vector y[] */
703 : const Word16 n, /* i : vector length */
704 : const Word16 log_len, /* i : max factor added to result q after dot product (equal to log2(n)) */
705 : Word16 *res_q /*stores resultant Q*/
706 : )
707 : {
708 : Word16 i;
709 : Word64 suma; /*resultant q= q(x)+q(y)-9-x such that q<=31*/
710 :
711 0 : suma = W_shr( W_mult_32_32( x[0], y[0] ), log_len );
712 :
713 0 : FOR( i = 1; i < n; i++ )
714 : {
715 0 : suma = W_add( suma, W_shr( W_mult_32_32( x[i], y[i] ), log_len ) );
716 : }
717 0 : *res_q = add( *res_q, add( sub( *res_q, log_len ), 1 ) );
718 0 : move16();
719 0 : test();
720 0 : test();
721 0 : WHILE( GT_64( suma, MAX_32 ) || LT_64( suma, MIN_32 ) || GT_16( *res_q, 31 ) )
722 : {
723 0 : suma = W_shr( suma, 1 );
724 0 : *res_q = sub( *res_q, 1 );
725 0 : move16();
726 : }
727 0 : return W_extract_l( suma );
728 : }
729 :
730 : /*-------------------------------------------------------------------*
731 : * v_add_w64()
732 : *
733 : * Subtraction of two vectors sample by sample
734 : *-------------------------------------------------------------------*/
735 :
736 0 : void v_add_w64(
737 : const Word64 x1[], /* i : Input vector 1 */
738 : const Word64 x2[], /* i : Input vector 2 */
739 : Word64 y[], /* o : Output vector that contains vector 1 - vector 2 */
740 : const Word16 N, /* i : Vector length */
741 : const Word16 hdrm /* i : headroom for when subtraction result > 1 or < -1 */
742 : )
743 : {
744 : Word16 i;
745 :
746 0 : FOR( i = 0; i < N; i++ )
747 : {
748 0 : y[i] = W_add( W_shr( x1[i], hdrm ), W_shr( x2[i], hdrm ) );
749 0 : move64();
750 : }
751 :
752 0 : return;
753 : }
754 :
755 : /*-------------------------------------------------------------------*
756 : * v_sub_fixed()
757 : *
758 : * Subtraction of two vectors sample by sample
759 : *-------------------------------------------------------------------*/
760 :
761 6465955 : void v_sub_fixed(
762 : const Word32 x1[], /* i : Input vector 1 */
763 : const Word32 x2[], /* i : Input vector 2 */
764 : Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */
765 : const Word16 N, /* i : Vector length */
766 : const Word16 hdrm /* i : headroom for when subtraction result > 1 or < -1 */
767 : )
768 : {
769 : Word16 i;
770 :
771 25863820 : FOR( i = 0; i < N; i++ )
772 : {
773 19397865 : y[i] = L_sub( L_shr( x1[i], hdrm ), L_shr( x2[i], hdrm ) );
774 19397865 : move32();
775 : }
776 :
777 6465955 : return;
778 : }
779 :
780 202874392 : void v_sub_fixed_no_hdrm(
781 : const Word32 x1[], /* i : Input vector 1 */
782 : const Word32 x2[], /* i : Input vector 2 */
783 : Word32 y[], /* o : Output vector that contains vector 1 - vector 2 */
784 : const Word16 N /* i : Vector length */
785 : )
786 : {
787 : Word16 i;
788 :
789 907767542 : FOR( i = 0; i < N; i++ )
790 : {
791 704893150 : y[i] = L_sub( x1[i], x2[i] );
792 704893150 : move32();
793 : }
794 :
795 202874392 : return;
796 : }
797 :
798 : /*-------------------------------------------------------------------*
799 : * v_multc_fixed()
800 : *
801 : * Multiplication of vector by constant
802 : *-------------------------------------------------------------------*/
803 :
804 34310574 : void v_multc_fixed(
805 : const Word32 x[], /* i : Input vector */
806 : const Word32 c, /* i : Constant */
807 : Word32 y[], /* o : Output vector that contains c*x */
808 : const Word16 N /* i : Vector length */
809 : )
810 : {
811 : Word16 i;
812 :
813 3642750547 : FOR( i = 0; i < N; i++ )
814 : {
815 3608439973 : y[i] = Mpy_32_32( c, x[i] );
816 3608439973 : move32();
817 : }
818 :
819 34310574 : return;
820 : }
821 :
822 1733474 : void v_multc_fixed_16(
823 : const Word32 x[], /* i : Input vector */
824 : const Word16 c, /* i : Constant */
825 : Word32 y[], /* o : Output vector that contains c*x */
826 : const Word16 N /* i : Vector length */
827 : )
828 : {
829 : Word16 i;
830 :
831 150324960 : FOR( i = 0; i < N; i++ )
832 : {
833 148591486 : y[i] = Mpy_32_16_1( x[i], c );
834 148591486 : move32();
835 : }
836 :
837 1733474 : return;
838 : }
839 :
840 6984 : void v_multc_fixed_16_16(
841 : const Word16 x[], /* i : Input vector */
842 : const Word16 c, /* i : Constant */
843 : Word16 y[], /* o : Output vector that contains c*x */
844 : const Word16 N /* i : Vector length */
845 : )
846 : {
847 : Word16 i;
848 :
849 3982520 : FOR( i = 0; i < N; i++ )
850 : {
851 3975536 : y[i] = mult_r( x[i], c );
852 3975536 : move16();
853 : }
854 :
855 6984 : return;
856 : }
857 :
858 : /*-------------------------------------------------------------------*
859 : * usdequant()
860 : *
861 : * Uniform scalar de-quantizer routine
862 : *
863 : * Applies de-quantization based on scale and round operations.
864 : *-------------------------------------------------------------------*/
865 :
866 3 : float usdequant(
867 : const Word16 idx, /* i : quantizer index */
868 : const float qlow, /* i : lowest codebook entry (index 0) */
869 : const float delta /* i : quantization step */
870 : )
871 : {
872 : float g;
873 :
874 3 : g = idx * delta + qlow;
875 :
876 3 : return ( g );
877 : }
878 :
879 835 : void sort(
880 : UWord16 *x, /* i/o: Vector to be sorted */
881 : UWord16 len /* i/o: vector length */
882 : )
883 : {
884 : Word16 i;
885 : UWord16 j, tempr;
886 :
887 4821 : FOR( i = len - 2; i >= 0; i-- )
888 : {
889 3986 : tempr = x[i];
890 3986 : move16();
891 8619 : FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ )
892 : {
893 4633 : test();
894 4633 : x[j - 1] = x[j];
895 4633 : move16();
896 : }
897 3986 : x[j - 1] = tempr;
898 3986 : move16();
899 : }
900 :
901 835 : return;
902 : }
|