1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
32 ------------------------------------------------------------------------------
35 /*----------------------------------------------------------------------------
37 ----------------------------------------------------------------------------*/
42 /*----------------------------------------------------------------------------
44 ; Define module specific macros here
45 ----------------------------------------------------------------------------*/
48 /*----------------------------------------------------------------------------
50 ; Include all pre-processor statements here. Include conditional
51 ; compile variables also.
52 ----------------------------------------------------------------------------*/
53 #define NMAX 9 /* largest N used in median calculation */
55 /*----------------------------------------------------------------------------
56 ; LOCAL FUNCTION DEFINITIONS
57 ; Function Prototype declaration
58 ----------------------------------------------------------------------------*/
61 /*----------------------------------------------------------------------------
62 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
63 ; Variable declaration - defined here and used outside this module
64 ----------------------------------------------------------------------------*/
68 ------------------------------------------------------------------------------
70 ------------------------------------------------------------------------------
71 INPUT AND OUTPUT DEFINITIONS
74 ind = input values (Word16)
75 n = number of inputs to find the median (Word16)
83 Global Variables Used:
86 Local Variables Needed:
89 ------------------------------------------------------------------------------
92 This function calculates N-point median of a data set. This routine is only
93 valid for a odd number of gains (n <= NMAX).
95 ------------------------------------------------------------------------------
100 ------------------------------------------------------------------------------
103 gmed_n.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
105 ------------------------------------------------------------------------------
108 Word16 gmed_n ( // o : The median value (0...N-1)
109 Word16 ind[], // i : Past gain values
110 Word16 n // i : The number of gains; this routine
111 // is only valid for a odd number of gains
121 for (i = 0; i < n; i++)
126 for (i = 0; i < n; i++)
129 for (j = 0; j < n; j++)
131 if (sub (tmp2[j], max) >= 0)
141 medianIndex=tmp[ shr(n,1) ]; // account for complex addressing
142 return (ind[medianIndex]);
145 ------------------------------------------------------------------------------
147 [State any special notes, constraints or cautions for users of this function]
149 ------------------------------------------------------------------------------
152 OSCL_EXPORT_REF Word16 gmed_n( /* o : the median value */
153 Word16 ind[], /* i : input values */
154 Word16 n /* i : number of inputs */
157 register Word16 i, j, ix = 0;
159 register Word16 medianIndex;
163 oscl_memmove(tmp2, ind, n*sizeof(*ind));
165 for (i = 0; i < n; i++)
168 for (j = 0; j < n; j++)
170 if (*(tmp2 + j) >= max)
176 *(tmp2 + ix) = -32768;
180 medianIndex = *(tmp + (n >> 1)); /* account for complex addressing */
182 return (*(ind + medianIndex));