Git init
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_wb / dec / src / median5.cpp
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
20
21     3GPP TS 26.173
22     ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23     Available from http://www.3gpp.org
24
25 (C) 2007, 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 ****************************************************************************************/
29 /*
30 ------------------------------------------------------------------------------
31
32
33
34  Filename: median5.cpp
35
36 ------------------------------------------------------------------------------
37  INPUT AND OUTPUT DEFINITIONS
38
39    INPUT
40        X[-2:2]   16-bit integers.
41
42    RETURN VALUE
43        The median of {X[-2], X[-1],..., X[2]}.
44
45 ------------------------------------------------------------------------------
46  FUNCTION DESCRIPTION
47
48       Returns the median of the set {X[-2], X[-1],..., X[2]},
49       whose elements are 16-bit integers.
50
51 ------------------------------------------------------------------------------
52  REQUIREMENTS
53
54
55 ------------------------------------------------------------------------------
56  REFERENCES
57
58 ------------------------------------------------------------------------------
59  PSEUDO-CODE
60
61 ------------------------------------------------------------------------------
62 */
63
64
65 /*----------------------------------------------------------------------------
66 ; INCLUDES
67 ----------------------------------------------------------------------------*/
68
69 #include "pv_amr_wb_type_defs.h"
70 #include "pvamrwbdecoder_basic_op.h"
71 #include "pvamrwbdecoder_acelp.h"
72 #include "pvamrwb_math_op.h"
73
74 /*----------------------------------------------------------------------------
75 ; MACROS
76 ; Define module specific macros here
77 ----------------------------------------------------------------------------*/
78
79
80 /*----------------------------------------------------------------------------
81 ; DEFINES
82 ; Include all pre-processor statements here. Include conditional
83 ; compile variables also.
84 ----------------------------------------------------------------------------*/
85
86 /*----------------------------------------------------------------------------
87 ; LOCAL FUNCTION DEFINITIONS
88 ; Function Prototype declaration
89 ----------------------------------------------------------------------------*/
90
91 /*----------------------------------------------------------------------------
92 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
93 ; Variable declaration - defined here and used outside this module
94 ----------------------------------------------------------------------------*/
95
96 /*----------------------------------------------------------------------------
97 ; EXTERNAL FUNCTION REFERENCES
98 ; Declare functions defined elsewhere and referenced in this module
99 ----------------------------------------------------------------------------*/
100
101 /*----------------------------------------------------------------------------
102 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
103 ; Declare variables used in this module but defined elsewhere
104 ----------------------------------------------------------------------------*/
105
106 /*----------------------------------------------------------------------------
107 ; FUNCTION CODE
108 ----------------------------------------------------------------------------*/
109
110 int16 median5(int16 x[])
111 {
112     int16 x1, x2, x3, x4, x5;
113     int16 tmp;
114
115     x1 = x[-2];
116     x2 = x[-1];
117     x3 = x[0];
118     x4 = x[1];
119     x5 = x[2];
120
121
122
123     if (x2 < x1)
124     {
125         tmp = x1;
126         x1 = x2;
127         x2 = tmp;
128     }
129     if (x3 < x1)
130     {
131         tmp = x1;
132         x1 = x3;
133         x3 = tmp;
134     }
135     if (x4 < x1)
136     {
137         tmp = x1;
138         x1 = x4;
139         x4 = tmp;
140     }
141     if (x5 < x1)
142     {
143         x5 = x1;
144     }
145     if (x3 < x2)
146     {
147         tmp = x2;
148         x2 = x3;
149         x3 = tmp;
150     }
151     if (x4 < x2)
152     {
153         tmp = x2;
154         x2 = x4;
155         x4 = tmp;
156     }
157     if (x5 < x2)
158     {
159         x5 = x2;
160     }
161     if (x4 < x3)
162     {
163         x3 = x4;
164     }
165     if (x5 < x3)
166     {
167         x3 = x5;
168     }
169     return (x3);
170 }
171
172