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.452 Aug 12, 2021. Version 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 288838491 : Word16 own_random(
51 : Word16 *seed /* i/o: random seed */
52 : )
53 : {
54 288838491 : *seed = (Word16) ( *seed * 31821L + 13849L );
55 :
56 288838491 : 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 362530 : 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 362530 : tmp = 0;
101 8545704 : for ( i = 0; i < lvec; i++ )
102 : {
103 8183174 : tmp += vec[i];
104 : }
105 :
106 362530 : return tmp;
107 : }
108 :
109 : /*! r: sum of all vector elements */
110 6696 : 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 6696 : tmpL = 0;
119 6696 : move32();
120 80352 : FOR( i = 0; i < lvec; i++ )
121 : {
122 73656 : tmpL = L_add( tmpL, vec[i] );
123 : }
124 :
125 6696 : return tmpL;
126 : }
127 :
128 : /*----------------------------------------------------------------------
129 : * sum2_f()
130 : *
131 : *---------------------------------------------------------------------*/
132 :
133 : /*! r: sum of all squared vector elements */
134 840 : 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 840 : tmp = 0;
143 840 : move32();
144 14280 : FOR( i = 0; i < lvec; i++ )
145 : {
146 13440 : tmp = L_add( tmp, L_mult0( vec[i], vec[i] ) );
147 : }
148 :
149 840 : return tmp;
150 : }
151 148 : 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 148 : tmp = 0;
160 96148 : FOR( i = 0; i < lvec; i++ )
161 : {
162 96000 : tmp = L_add( tmp, L_shr( L_mult0( vec[i], vec[i] ), gb ) );
163 : }
164 :
165 148 : return tmp;
166 : }
167 :
168 35497 : 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 35497 : L_tmp = 0;
179 35497 : move32();
180 35497 : var_a = 0;
181 35497 : move32();
182 6535941 : FOR( i = 0; i < lvec; i++ )
183 : {
184 6500444 : var_a = L_mult0( vec[i], vec[i] ); /* 2 * Q(15 - exp) */
185 6500444 : L_tmp = L_add( L_tmp, L_shr( var_a, gb ) ); /* 2 * Q(15 - exp) - gb */
186 : }
187 :
188 35497 : s = norm_l( L_tmp );
189 35497 : L_tmp = L_shl( L_tmp, s ); /* 2 * Q(15 - exp) - gb + s */
190 :
191 35497 : *exp = add( sub( add( shl( *exp, 1 ), gb ), s ), 1 );
192 35497 : move16();
193 :
194 35497 : return L_tmp;
195 : }
196 :
197 8416921 : 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 8416921 : W_tmp = 0;
208 8416921 : Word64 var_a = 0;
209 8416921 : move64();
210 8416921 : move64();
211 :
212 8416921 : norm = L_norm_arr( vec, lvec );
213 :
214 8416921 : gb = sub( gb, norm );
215 :
216 1756382531 : FOR( i = 0; i < lvec; i++ )
217 : {
218 1747965610 : var_a = W_mult0_32_32( vec[i], vec[i] ); // 2x
219 1747965610 : W_tmp = W_add( W_tmp, W_shr( var_a, gb ) ); // 2x-gb
220 : }
221 :
222 8416921 : s = W_norm( W_tmp );
223 8416921 : W_tmp = W_shl( W_tmp, s ); // 2x - gb + s
224 :
225 : //*exp = 31 - (2*(31 - *exp) - gb + s) + 32;
226 8416921 : *exp = add( sub( add( shl( *exp, 1 ), gb ), s ), 1 );
227 8416921 : move16();
228 :
229 8416921 : return W_extract_h( W_tmp );
230 : }
231 :
232 8372179 : 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 8372179 : tmp = 0;
242 8372179 : Word32 var_a = 0;
243 8372179 : move32();
244 8372179 : move32();
245 85238386 : FOR( i = 0; i < lvec; i++ )
246 : {
247 76866207 : var_a = Mpy_32_32( vec[i], vec[i] ); // 2x-31
248 76866207 : tmp = L_add( tmp, L_shr( var_a, gb ) ); // 2x-31-gb
249 : }
250 :
251 8372179 : return tmp;
252 : }
253 :
254 1948200 : 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 1948200 : tmp = 0;
263 1948200 : Word32 var_a = 0;
264 1948200 : Word16 exp = 0, exp_tmp;
265 1948200 : move32();
266 1948200 : move32();
267 1948200 : move16();
268 146452536 : FOR( i = 0; i < lvec; i++ )
269 : {
270 144504336 : exp_tmp = norm_l( vec[i] );
271 144504336 : var_a = L_shl( vec[i], exp_tmp );
272 144504336 : var_a = Mpy_32_32( var_a, var_a );
273 144504336 : exp_tmp = shl( sub( *e, exp_tmp ), 1 );
274 144504336 : tmp = BASOP_Util_Add_Mant32Exp( tmp, exp, var_a, exp_tmp, &exp );
275 : }
276 1948200 : *e = exp;
277 1948200 : move16();
278 :
279 1948200 : 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 118716 : 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 914352 : for ( i = 0; i < N; i++ )
300 : {
301 795636 : y[i] = a;
302 : }
303 :
304 118716 : return;
305 : }
306 :
307 :
308 2572622 : 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 30091618 : for ( i = 0; i < N; i++ )
317 : {
318 27518996 : y[i] = a;
319 : }
320 :
321 2572622 : 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 1151051 : 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 1151051 : if ( n <= 0 )
413 : {
414 : /* cannot transfer vectors with size 0 */
415 0 : return;
416 : }
417 :
418 1151051 : 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 8057060 : for ( i = n - 1; i >= 0; i-- )
428 : {
429 6906009 : y[i] = x[i];
430 : }
431 : }
432 :
433 1151051 : 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 636515 : 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 636515 : ind = 0;
479 636515 : move16();
480 636515 : tmp = vec[0];
481 636515 : move16();
482 :
483 6461937 : FOR( i = 1; i < lvec; i++ )
484 : {
485 5825422 : IF( GT_16( vec[i], tmp ) )
486 : {
487 210266 : ind = i;
488 210266 : move16();
489 210266 : tmp = vec[i];
490 210266 : move16();
491 : }
492 : }
493 :
494 636515 : if ( max != NULL )
495 : {
496 630603 : *max = tmp;
497 630603 : move16();
498 : }
499 :
500 636515 : return ind;
501 : }
502 :
503 : /*! r: index of the maximum value in the input vector */
504 253427 : 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 253427 : ind = 0;
514 253427 : tmp = vec[0];
515 253427 : move16();
516 253427 : move32();
517 68249602 : FOR( i = 1; i < lvec; i++ )
518 : {
519 67996175 : IF( GT_32( vec[i], tmp ) )
520 : {
521 1336462 : ind = i;
522 1336462 : tmp = vec[i];
523 1336462 : move16();
524 1336462 : move32();
525 : }
526 : }
527 :
528 253427 : if ( max_val != NULL )
529 : {
530 253427 : *max_val = tmp;
531 253427 : move32();
532 : }
533 :
534 253427 : return ind;
535 : }
536 :
537 : /*! r: index of the maximum value in the input vector */
538 1613930 : 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 1613930 : ind = 0;
548 1613930 : move16();
549 1613930 : tmp = L_abs( vec[0] );
550 :
551 59486794 : FOR( j = 1; j < lvec; j++ )
552 : {
553 57872864 : IF( GT_32( L_abs( vec[j] ), tmp ) )
554 : {
555 5482586 : ind = j;
556 5482586 : move16();
557 5482586 : tmp = L_abs( vec[j] );
558 : }
559 : }
560 :
561 1613930 : IF( max_val != NULL )
562 : {
563 1613930 : *max_val = tmp;
564 1613930 : move32();
565 : }
566 :
567 1613930 : 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 89064292 : 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 89064292 : ind = 0;
586 89064292 : move16();
587 :
588 422673011 : FOR( i = 1; i < lvec; i++ )
589 : {
590 333608719 : if ( LT_16( vec[i], vec[ind] ) )
591 : {
592 31071932 : ind = i;
593 31071932 : move16();
594 : }
595 : }
596 :
597 89064292 : if ( min_val != NULL )
598 : {
599 89064292 : *min_val = vec[ind];
600 89064292 : move16();
601 : }
602 :
603 89064292 : 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 156512 : 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 156512 : ind = 0;
622 156512 : move16();
623 :
624 1981207 : FOR( i = 1; i < lvec; i++ )
625 : {
626 1824695 : if ( LT_32( vec[i], vec[ind] ) )
627 : {
628 383916 : ind = i;
629 383916 : move16();
630 : }
631 : }
632 :
633 156512 : if ( min_val != NULL )
634 : {
635 156512 : *min_val = vec[ind];
636 156512 : move32();
637 : }
638 :
639 156512 : 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 14354364 : 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 14354364 : suma = Mpy_32_32( x[0], y[0] );
659 :
660 37884512 : FOR( i = 1; i < n; i++ )
661 : {
662 23530148 : suma = L_add( suma, Mpy_32_32( x[i], y[i] ) );
663 : }
664 :
665 14354364 : return suma;
666 : }
667 :
668 : /*To calculate dot product of two 32 bit arrays in case of overflow*/
669 2956718 : 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 2956718 : suma = W_shr( W_mult_32_32( x[0], y[0] ), log_len );
681 :
682 153085784 : FOR( i = 1; i < n; i++ )
683 : {
684 150129066 : suma = W_add( suma, W_shr( W_mult_32_32( x[i], y[i] ), log_len ) );
685 : }
686 2956718 : *res_q = add( sub( *res_q, log_len ), 1 );
687 2956718 : move16();
688 2956718 : test();
689 2956718 : test();
690 35670625 : FOR( ; ( suma > MAX_32 ) || ( suma < MIN_32 ) || ( *res_q > 31 ); )
691 : {
692 32713907 : suma = W_shr( suma, 1 );
693 32713907 : *res_q = sub( *res_q, 1 );
694 32713907 : move16();
695 : }
696 2956718 : return W_extract_l( suma );
697 : }
698 :
699 1497166 : 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 1497166 : suma = W_shr( W_mult_32_32( x[0], y[0] ), log_len );
711 :
712 1289141760 : FOR( i = 1; i < n; i++ )
713 : {
714 1287644594 : suma = W_add( suma, W_shr( W_mult_32_32( x[i], y[i] ), log_len ) );
715 : }
716 1497166 : *res_q = add( *res_q, add( sub( *res_q, log_len ), 1 ) );
717 1497166 : move16();
718 1497166 : test();
719 1497166 : test();
720 31086783 : FOR( ; ( suma > MAX_32 ) || ( suma < MIN_32 ) || ( *res_q > 31 ); )
721 : {
722 29589617 : suma = W_shr( suma, 1 );
723 29589617 : *res_q = sub( *res_q, 1 );
724 29589617 : move16();
725 : }
726 1497166 : 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 6927235 : 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 27708940 : FOR( i = 0; i < N; i++ )
771 : {
772 20781705 : y[i] = L_sub( L_shr( x1[i], hdrm ), L_shr( x2[i], hdrm ) );
773 20781705 : move32();
774 : }
775 :
776 6927235 : return;
777 : }
778 :
779 541191039 : 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 2607587036 : FOR( i = 0; i < N; i++ )
789 : {
790 2066395997 : y[i] = L_sub( x1[i], x2[i] );
791 2066395997 : move32();
792 : }
793 :
794 541191039 : return;
795 : }
796 :
797 : /*-------------------------------------------------------------------*
798 : * v_multc_fixed()
799 : *
800 : * Multiplication of vector by constant
801 : *-------------------------------------------------------------------*/
802 :
803 51641194 : 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 6603386600 : FOR( i = 0; i < N; i++ )
813 : {
814 6551745406 : y[i] = Mpy_32_32( c, x[i] );
815 6551745406 : move32();
816 : }
817 :
818 51641194 : return;
819 : }
820 :
821 1830670 : 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 198772858 : FOR( i = 0; i < N; i++ )
831 : {
832 196942188 : y[i] = Mpy_32_16_1( x[i], c );
833 196942188 : move32();
834 : }
835 :
836 1830670 : return;
837 : }
838 :
839 10516 : 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 5033124 : FOR( i = 0; i < N; i++ )
849 : {
850 5022608 : y[i] = mult_r( x[i], c );
851 5022608 : move16();
852 : }
853 :
854 10516 : 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 : }
|