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 295030435 : Word16 own_random(
51 : Word16 *seed /* i/o: random seed */
52 : )
53 : {
54 295030435 : *seed = (Word16) ( *seed * 31821L + 13849L );
55 :
56 295030435 : 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 352689 : 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 352689 : tmp = 0;
102 8284074 : for ( i = 0; i < lvec; i++ )
103 : {
104 7931385 : tmp += vec[i];
105 : }
106 :
107 352689 : return tmp;
108 : }
109 :
110 : /*! r: sum of all vector elements */
111 6674 : 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 6674 : tmpL = 0;
120 6674 : move32();
121 80088 : FOR( i = 0; i < lvec; i++ )
122 : {
123 73414 : tmpL = L_add( tmpL, vec[i] );
124 : }
125 :
126 6674 : 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 148 : 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 148 : tmp = 0;
161 96148 : FOR( i = 0; i < lvec; i++ )
162 : {
163 96000 : tmp = L_add( tmp, L_shr( L_mult0( vec[i], vec[i] ), gb ) );
164 : }
165 :
166 148 : return tmp;
167 : }
168 :
169 35515 : 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 35515 : L_tmp = 0;
180 35515 : move32();
181 35515 : var_a = 0;
182 35515 : move32();
183 6540567 : FOR( i = 0; i < lvec; i++ )
184 : {
185 6505052 : var_a = L_mult0( vec[i], vec[i] ); /* 2 * Q(15 - exp) */
186 6505052 : L_tmp = L_add( L_tmp, L_shr( var_a, gb ) ); /* 2 * Q(15 - exp) - gb */
187 : }
188 :
189 35515 : s = norm_l( L_tmp );
190 35515 : L_tmp = L_shl( L_tmp, s ); /* 2 * Q(15 - exp) - gb + s */
191 :
192 35515 : *exp = add( sub( add( shl( *exp, 1 ), gb ), s ), 1 );
193 35515 : move16();
194 :
195 35515 : return L_tmp;
196 : }
197 :
198 8061240 : 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 8061240 : W_tmp = 0;
209 8061240 : Word64 var_a = 0;
210 8061240 : move64();
211 8061240 : move64();
212 :
213 8061240 : norm = L_norm_arr( vec, lvec );
214 :
215 8061240 : gb = sub( gb, norm );
216 :
217 1674656298 : FOR( i = 0; i < lvec; i++ )
218 : {
219 1666595058 : var_a = W_mult0_32_32( vec[i], vec[i] ); // 2x
220 1666595058 : W_tmp = W_add( W_tmp, W_shr( var_a, gb ) ); // 2x-gb
221 : }
222 :
223 8061240 : s = W_norm( W_tmp );
224 8061240 : W_tmp = W_shl( W_tmp, s ); // 2x - gb + s
225 :
226 : //*exp = 31 - (2*(31 - *exp) - gb + s) + 32;
227 8061240 : *exp = add( sub( add( shl( *exp, 1 ), gb ), s ), 1 );
228 8061240 : move16();
229 :
230 8061240 : return W_extract_h( W_tmp );
231 : }
232 :
233 10275147 : 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 10275147 : tmp = 0;
243 10275147 : Word32 var_a = 0;
244 10275147 : move32();
245 10275147 : move32();
246 108122312 : FOR( i = 0; i < lvec; i++ )
247 : {
248 97847165 : var_a = Mpy_32_32( vec[i], vec[i] ); // 2x-31
249 97847165 : tmp = L_add( tmp, L_shr( var_a, gb ) ); // 2x-31-gb
250 : }
251 :
252 10275147 : return tmp;
253 : }
254 :
255 1924145 : 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 1924145 : tmp = 0;
264 1924145 : Word32 var_a = 0;
265 1924145 : Word16 exp = 0, exp_tmp;
266 1924145 : move32();
267 1924145 : move32();
268 1924145 : move16();
269 144678913 : FOR( i = 0; i < lvec; i++ )
270 : {
271 142754768 : exp_tmp = norm_l( vec[i] );
272 142754768 : var_a = L_shl( vec[i], exp_tmp );
273 142754768 : var_a = Mpy_32_32( var_a, var_a );
274 142754768 : exp_tmp = shl( sub( *e, exp_tmp ), 1 );
275 142754768 : tmp = BASOP_Util_Add_Mant32Exp( tmp, exp, var_a, exp_tmp, &exp );
276 : }
277 1924145 : *e = exp;
278 1924145 : move16();
279 :
280 1924145 : 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 2516644 : 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 29659711 : for ( i = 0; i < N; i++ )
318 : {
319 27143067 : y[i] = a;
320 : }
321 :
322 2516644 : 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 1129261 : 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 1129261 : if ( n <= 0 )
414 : {
415 : /* cannot transfer vectors with size 0 */
416 0 : return;
417 : }
418 :
419 1129261 : 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 7904550 : for ( i = n - 1; i >= 0; i-- )
429 : {
430 6775289 : y[i] = x[i];
431 : }
432 : }
433 :
434 1129261 : 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 614773 : 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 614773 : ind = 0;
480 614773 : move16();
481 614773 : tmp = vec[0];
482 614773 : move16();
483 :
484 6359735 : FOR( i = 1; i < lvec; i++ )
485 : {
486 5744962 : IF( GT_16( vec[i], tmp ) )
487 : {
488 197234 : ind = i;
489 197234 : move16();
490 197234 : tmp = vec[i];
491 197234 : move16();
492 : }
493 : }
494 :
495 614773 : if ( max != NULL )
496 : {
497 608597 : *max = tmp;
498 608597 : move16();
499 : }
500 :
501 614773 : return ind;
502 : }
503 :
504 : /*! r: index of the maximum value in the input vector */
505 254119 : 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 254119 : ind = 0;
515 254119 : tmp = vec[0];
516 254119 : move16();
517 254119 : move32();
518 68244952 : FOR( i = 1; i < lvec; i++ )
519 : {
520 67990833 : IF( GT_32( vec[i], tmp ) )
521 : {
522 1336892 : ind = i;
523 1336892 : tmp = vec[i];
524 1336892 : move16();
525 1336892 : move32();
526 : }
527 : }
528 :
529 254119 : if ( max_val != NULL )
530 : {
531 254119 : *max_val = tmp;
532 254119 : move32();
533 : }
534 :
535 254119 : return ind;
536 : }
537 :
538 : /*! r: index of the maximum value in the input vector */
539 1613954 : 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 1613954 : ind = 0;
549 1613954 : move16();
550 1613954 : tmp = L_abs( vec[0] );
551 :
552 59487130 : FOR( j = 1; j < lvec; j++ )
553 : {
554 57873176 : IF( GT_32( L_abs( vec[j] ), tmp ) )
555 : {
556 5482957 : ind = j;
557 5482957 : move16();
558 5482957 : tmp = L_abs( vec[j] );
559 : }
560 : }
561 :
562 1613954 : IF( max_val != NULL )
563 : {
564 1613954 : *max_val = tmp;
565 1613954 : move32();
566 : }
567 :
568 1613954 : 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 85771134 : 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 85771134 : ind = 0;
587 85771134 : move16();
588 :
589 407223652 : FOR( i = 1; i < lvec; i++ )
590 : {
591 321452518 : if ( LT_16( vec[i], vec[ind] ) )
592 : {
593 30302048 : ind = i;
594 30302048 : move16();
595 : }
596 : }
597 :
598 85771134 : if ( min_val != NULL )
599 : {
600 85771134 : *min_val = vec[ind];
601 85771134 : move16();
602 : }
603 :
604 85771134 : 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 157222 : 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 157222 : ind = 0;
623 157222 : move16();
624 :
625 1983538 : FOR( i = 1; i < lvec; i++ )
626 : {
627 1826316 : if ( LT_32( vec[i], vec[ind] ) )
628 : {
629 385186 : ind = i;
630 385186 : move16();
631 : }
632 : }
633 :
634 157222 : if ( min_val != NULL )
635 : {
636 157222 : *min_val = vec[ind];
637 157222 : move32();
638 : }
639 :
640 157222 : 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 13582168 : 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 13582168 : suma = Mpy_32_32( x[0], y[0] );
660 :
661 35913562 : FOR( i = 1; i < n; i++ )
662 : {
663 22331394 : suma = L_add( suma, Mpy_32_32( x[i], y[i] ) );
664 : }
665 :
666 13582168 : return suma;
667 : }
668 :
669 : /*To calculate dot product of two 32 bit arrays in case of overflow*/
670 2888188 : 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 2888188 : suma = W_shr( W_mult_32_32( x[0], y[0] ), log_len );
682 :
683 149563004 : FOR( i = 1; i < n; i++ )
684 : {
685 146674816 : suma = W_add( suma, W_shr( W_mult_32_32( x[i], y[i] ), log_len ) );
686 : }
687 2888188 : *res_q = add( sub( *res_q, log_len ), 1 );
688 2888188 : move16();
689 2888188 : test();
690 2888188 : test();
691 35147699 : WHILE( GT_64( suma, MAX_32 ) || LT_64( suma, MIN_32 ) || GT_16( *res_q, 31 ) )
692 : {
693 32259511 : suma = W_shr( suma, 1 );
694 32259511 : *res_q = sub( *res_q, 1 );
695 32259511 : move16();
696 : }
697 2888188 : return W_extract_l( suma );
698 : }
699 :
700 1378507 : 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 1378507 : suma = W_shr( W_mult_32_32( x[0], y[0] ), log_len );
712 :
713 1191228160 : FOR( i = 1; i < n; i++ )
714 : {
715 1189849653 : suma = W_add( suma, W_shr( W_mult_32_32( x[i], y[i] ), log_len ) );
716 : }
717 1378507 : *res_q = add( *res_q, add( sub( *res_q, log_len ), 1 ) );
718 1378507 : move16();
719 1378507 : test();
720 1378507 : test();
721 28906245 : WHILE( GT_64( suma, MAX_32 ) || LT_64( suma, MIN_32 ) || GT_16( *res_q, 31 ) )
722 : {
723 27527738 : suma = W_shr( suma, 1 );
724 27527738 : *res_q = sub( *res_q, 1 );
725 27527738 : move16();
726 : }
727 1378507 : 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 204052445 : 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 926665459 : FOR( i = 0; i < N; i++ )
790 : {
791 722613014 : y[i] = L_sub( x1[i], x2[i] );
792 722613014 : move32();
793 : }
794 :
795 204052445 : return;
796 : }
797 :
798 : /*-------------------------------------------------------------------*
799 : * v_multc_fixed()
800 : *
801 : * Multiplication of vector by constant
802 : *-------------------------------------------------------------------*/
803 :
804 39650904 : 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 6262786788 : FOR( i = 0; i < N; i++ )
814 : {
815 6223135884 : y[i] = Mpy_32_32( c, x[i] );
816 6223135884 : move32();
817 : }
818 :
819 39650904 : return;
820 : }
821 :
822 1802727 : 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 198312555 : FOR( i = 0; i < N; i++ )
832 : {
833 196509828 : y[i] = Mpy_32_16_1( x[i], c );
834 196509828 : move32();
835 : }
836 :
837 1802727 : return;
838 : }
839 :
840 10413 : 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 4992669 : FOR( i = 0; i < N; i++ )
850 : {
851 4982256 : y[i] = mult_r( x[i], c );
852 4982256 : move16();
853 : }
854 :
855 10413 : 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 : }
|