• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 /*
12  * This file contains the implementation of functions
13  * WebRtcSpl_MaxAbsValueW16()
14  * WebRtcSpl_MaxAbsIndexW16()
15  * WebRtcSpl_MaxAbsValueW32()
16  * WebRtcSpl_MaxValueW16()
17  * WebRtcSpl_MaxIndexW16()
18  * WebRtcSpl_MaxValueW32()
19  * WebRtcSpl_MaxIndexW32()
20  * WebRtcSpl_MinValueW16()
21  * WebRtcSpl_MinIndexW16()
22  * WebRtcSpl_MinValueW32()
23  * WebRtcSpl_MinIndexW32()
24  *
25  * The description header can be found in signal_processing_library.h.
26  *
27  */
28 
29 #include "signal_processing_library.h"
30 
31 #if !(defined(WEBRTC_ANDROID) && defined(WEBRTC_ARCH_ARM_NEON))
32 
33 // Maximum absolute value of word16 vector.
WebRtcSpl_MaxAbsValueW16(const WebRtc_Word16 * vector,WebRtc_Word16 length)34 WebRtc_Word16 WebRtcSpl_MaxAbsValueW16(const WebRtc_Word16 *vector, WebRtc_Word16 length)
35 {
36     WebRtc_Word32 tempMax = 0;
37     WebRtc_Word32 absVal;
38     WebRtc_Word16 totMax;
39     int i;
40     G_CONST WebRtc_Word16 *tmpvector = vector;
41 
42     for (i = 0; i < length; i++)
43     {
44         absVal = WEBRTC_SPL_ABS_W32((*tmpvector));
45         if (absVal > tempMax)
46         {
47             tempMax = absVal;
48         }
49         tmpvector++;
50     }
51     totMax = (WebRtc_Word16)WEBRTC_SPL_MIN(tempMax, WEBRTC_SPL_WORD16_MAX);
52     return totMax;
53 }
54 
55 #endif
56 
57 // Index of maximum absolute value in a  word16 vector.
WebRtcSpl_MaxAbsIndexW16(G_CONST WebRtc_Word16 * vector,WebRtc_Word16 length)58 WebRtc_Word16 WebRtcSpl_MaxAbsIndexW16(G_CONST WebRtc_Word16* vector, WebRtc_Word16 length)
59 {
60     WebRtc_Word16 tempMax;
61     WebRtc_Word16 absTemp;
62     WebRtc_Word16 tempMaxIndex = 0;
63     WebRtc_Word16 i = 0;
64     G_CONST WebRtc_Word16 *tmpvector = vector;
65 
66     tempMax = WEBRTC_SPL_ABS_W16(*tmpvector);
67     tmpvector++;
68     for (i = 1; i < length; i++)
69     {
70         absTemp = WEBRTC_SPL_ABS_W16(*tmpvector);
71         tmpvector++;
72         if (absTemp > tempMax)
73         {
74             tempMax = absTemp;
75             tempMaxIndex = i;
76         }
77     }
78     return tempMaxIndex;
79 }
80 
81 // Maximum absolute value of word32 vector.
WebRtcSpl_MaxAbsValueW32(G_CONST WebRtc_Word32 * vector,WebRtc_Word16 length)82 WebRtc_Word32 WebRtcSpl_MaxAbsValueW32(G_CONST WebRtc_Word32 *vector, WebRtc_Word16 length)
83 {
84     WebRtc_UWord32 tempMax = 0;
85     WebRtc_UWord32 absVal;
86     WebRtc_Word32 retval;
87     int i;
88     G_CONST WebRtc_Word32 *tmpvector = vector;
89 
90     for (i = 0; i < length; i++)
91     {
92         absVal = WEBRTC_SPL_ABS_W32((*tmpvector));
93         if (absVal > tempMax)
94         {
95             tempMax = absVal;
96         }
97         tmpvector++;
98     }
99     retval = (WebRtc_Word32)(WEBRTC_SPL_MIN(tempMax, WEBRTC_SPL_WORD32_MAX));
100     return retval;
101 }
102 
103 // Maximum value of word16 vector.
104 #ifndef XSCALE_OPT
WebRtcSpl_MaxValueW16(G_CONST WebRtc_Word16 * vector,WebRtc_Word16 length)105 WebRtc_Word16 WebRtcSpl_MaxValueW16(G_CONST WebRtc_Word16* vector, WebRtc_Word16 length)
106 {
107     WebRtc_Word16 tempMax;
108     WebRtc_Word16 i;
109     G_CONST WebRtc_Word16 *tmpvector = vector;
110 
111     tempMax = *tmpvector++;
112     for (i = 1; i < length; i++)
113     {
114         if (*tmpvector++ > tempMax)
115             tempMax = vector[i];
116     }
117     return tempMax;
118 }
119 #else
120 #pragma message(">> WebRtcSpl_MaxValueW16 is excluded from this build")
121 #endif
122 
123 // Index of maximum value in a word16 vector.
WebRtcSpl_MaxIndexW16(G_CONST WebRtc_Word16 * vector,WebRtc_Word16 length)124 WebRtc_Word16 WebRtcSpl_MaxIndexW16(G_CONST WebRtc_Word16 *vector, WebRtc_Word16 length)
125 {
126     WebRtc_Word16 tempMax;
127     WebRtc_Word16 tempMaxIndex = 0;
128     WebRtc_Word16 i = 0;
129     G_CONST WebRtc_Word16 *tmpvector = vector;
130 
131     tempMax = *tmpvector++;
132     for (i = 1; i < length; i++)
133     {
134         if (*tmpvector++ > tempMax)
135         {
136             tempMax = vector[i];
137             tempMaxIndex = i;
138         }
139     }
140     return tempMaxIndex;
141 }
142 
143 // Maximum value of word32 vector.
144 #ifndef XSCALE_OPT
WebRtcSpl_MaxValueW32(G_CONST WebRtc_Word32 * vector,WebRtc_Word16 length)145 WebRtc_Word32 WebRtcSpl_MaxValueW32(G_CONST WebRtc_Word32* vector, WebRtc_Word16 length)
146 {
147     WebRtc_Word32 tempMax;
148     WebRtc_Word16 i;
149     G_CONST WebRtc_Word32 *tmpvector = vector;
150 
151     tempMax = *tmpvector++;
152     for (i = 1; i < length; i++)
153     {
154         if (*tmpvector++ > tempMax)
155             tempMax = vector[i];
156     }
157     return tempMax;
158 }
159 #else
160 #pragma message(">> WebRtcSpl_MaxValueW32 is excluded from this build")
161 #endif
162 
163 // Index of maximum value in a word32 vector.
WebRtcSpl_MaxIndexW32(G_CONST WebRtc_Word32 * vector,WebRtc_Word16 length)164 WebRtc_Word16 WebRtcSpl_MaxIndexW32(G_CONST WebRtc_Word32* vector, WebRtc_Word16 length)
165 {
166     WebRtc_Word32 tempMax;
167     WebRtc_Word16 tempMaxIndex = 0;
168     WebRtc_Word16 i = 0;
169     G_CONST WebRtc_Word32 *tmpvector = vector;
170 
171     tempMax = *tmpvector++;
172     for (i = 1; i < length; i++)
173     {
174         if (*tmpvector++ > tempMax)
175         {
176             tempMax = vector[i];
177             tempMaxIndex = i;
178         }
179     }
180     return tempMaxIndex;
181 }
182 
183 // Minimum value of word16 vector.
WebRtcSpl_MinValueW16(G_CONST WebRtc_Word16 * vector,WebRtc_Word16 length)184 WebRtc_Word16 WebRtcSpl_MinValueW16(G_CONST WebRtc_Word16 *vector, WebRtc_Word16 length)
185 {
186     WebRtc_Word16 tempMin;
187     WebRtc_Word16 i;
188     G_CONST WebRtc_Word16 *tmpvector = vector;
189 
190     // Find the minimum value
191     tempMin = *tmpvector++;
192     for (i = 1; i < length; i++)
193     {
194         if (*tmpvector++ < tempMin)
195             tempMin = (vector[i]);
196     }
197     return tempMin;
198 }
199 
200 // Index of minimum value in a word16 vector.
201 #ifndef XSCALE_OPT
WebRtcSpl_MinIndexW16(G_CONST WebRtc_Word16 * vector,WebRtc_Word16 length)202 WebRtc_Word16 WebRtcSpl_MinIndexW16(G_CONST WebRtc_Word16* vector, WebRtc_Word16 length)
203 {
204     WebRtc_Word16 tempMin;
205     WebRtc_Word16 tempMinIndex = 0;
206     WebRtc_Word16 i = 0;
207     G_CONST WebRtc_Word16* tmpvector = vector;
208 
209     // Find index of smallest value
210     tempMin = *tmpvector++;
211     for (i = 1; i < length; i++)
212     {
213         if (*tmpvector++ < tempMin)
214         {
215             tempMin = vector[i];
216             tempMinIndex = i;
217         }
218     }
219     return tempMinIndex;
220 }
221 #else
222 #pragma message(">> WebRtcSpl_MinIndexW16 is excluded from this build")
223 #endif
224 
225 // Minimum value of word32 vector.
WebRtcSpl_MinValueW32(G_CONST WebRtc_Word32 * vector,WebRtc_Word16 length)226 WebRtc_Word32 WebRtcSpl_MinValueW32(G_CONST WebRtc_Word32 *vector, WebRtc_Word16 length)
227 {
228     WebRtc_Word32 tempMin;
229     WebRtc_Word16 i;
230     G_CONST WebRtc_Word32 *tmpvector = vector;
231 
232     // Find the minimum value
233     tempMin = *tmpvector++;
234     for (i = 1; i < length; i++)
235     {
236         if (*tmpvector++ < tempMin)
237             tempMin = (vector[i]);
238     }
239     return tempMin;
240 }
241 
242 // Index of minimum value in a word32 vector.
243 #ifndef XSCALE_OPT
WebRtcSpl_MinIndexW32(G_CONST WebRtc_Word32 * vector,WebRtc_Word16 length)244 WebRtc_Word16 WebRtcSpl_MinIndexW32(G_CONST WebRtc_Word32* vector, WebRtc_Word16 length)
245 {
246     WebRtc_Word32 tempMin;
247     WebRtc_Word16 tempMinIndex = 0;
248     WebRtc_Word16 i = 0;
249     G_CONST WebRtc_Word32 *tmpvector = vector;
250 
251     // Find index of smallest value
252     tempMin = *tmpvector++;
253     for (i = 1; i < length; i++)
254     {
255         if (*tmpvector++ < tempMin)
256         {
257             tempMin = vector[i];
258             tempMinIndex = i;
259         }
260     }
261     return tempMinIndex;
262 }
263 #else
264 #pragma message(">> WebRtcSpl_MinIndexW32 is excluded from this build")
265 #endif
266