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