comparison libtwamr/gmed_n.c @ 308:8dfb7cbe6b59

libtwamr: integrated up to bgnscd.c
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 16 Apr 2024 17:57:21 +0000
parents
children
comparison
equal deleted inserted replaced
307:6b33f3ba4289 308:8dfb7cbe6b59
1 /*
2 ********************************************************************************
3 *
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
5 * R99 Version 3.3.0
6 * REL-4 Version 4.1.0
7 *
8 ********************************************************************************
9 *
10 * File : gmed_n.c
11 * Purpose : calculates N-point median.
12 *
13 ********************************************************************************
14 */
15 /*
16 ********************************************************************************
17 * MODULE INCLUDE FILE AND VERSION ID
18 ********************************************************************************
19 */
20 #include "namespace.h"
21 #include "gmed_n.h"
22
23 /*
24 ********************************************************************************
25 * INCLUDE FILES
26 ********************************************************************************
27 */
28 #include "typedef.h"
29 #include "basic_op.h"
30 #include "no_count.h"
31
32 /*
33 ********************************************************************************
34 * LOCAL VARIABLES AND TABLES
35 ********************************************************************************
36 */
37
38 #define NMAX 9 /* largest N used in median calculation */
39
40 /*
41 ********************************************************************************
42 * PUBLIC PROGRAM CODE
43 ********************************************************************************
44 */
45 /*************************************************************************
46 *
47 * FUNCTION: gmed_n
48 *
49 * PURPOSE: calculates N-point median.
50 *
51 * DESCRIPTION:
52 *
53 *************************************************************************/
54
55 Word16 gmed_n ( /* o : index of the median value (0...N-1) */
56 Word16 ind[], /* i : Past gain values */
57 Word16 n /* i : The number of gains; this routine */
58 /* is only valid for a odd number of gains */
59 /* (n <= NMAX) */
60 )
61 {
62 Word16 i, j, ix = 0;
63 Word16 max;
64 Word16 medianIndex;
65 Word16 tmp[NMAX];
66 Word16 tmp2[NMAX];
67
68 for (i = 0; i < n; i++)
69 {
70 tmp2[i] = ind[i]; move16 ();
71 }
72
73 for (i = 0; i < n; i++)
74 {
75 max = -32767; move16 ();
76 for (j = 0; j < n; j++)
77 {
78 test ();
79 if (sub (tmp2[j], max) >= 0)
80 {
81 max = tmp2[j]; move16 ();
82 ix = j; move16 ();
83 }
84 }
85 tmp2[ix] = -32768; move16 ();
86 tmp[i] = ix; move16 ();
87 }
88
89 medianIndex=tmp[ shr(n,1) ]; move16 (); /* account for complex addressing */
90 return (ind[medianIndex]);
91 }