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