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 // Maximum absolute value of word16 vector. 32 WebRtc_Word16 WebRtcSpl_MaxAbsValueW16(G_CONST WebRtc_Word16 *vector, WebRtc_Word16 length) 33 { 34 WebRtc_Word32 tempMax = 0; 35 WebRtc_Word32 absVal; 36 WebRtc_Word16 totMax; 37 int i; 38 G_CONST WebRtc_Word16 *tmpvector = vector; 39 40 #ifdef _ARM_OPT_ 41 #pragma message("NOTE: _ARM_OPT_ optimizations are used") 42 43 WebRtc_Word16 len4 = (length >> 2) << 2; 44 45 for (i = 0; i < len4; i = i + 4) 46 { 47 absVal = WEBRTC_SPL_ABS_W32((*tmpvector)); 48 if (absVal > tempMax) 49 { 50 tempMax = absVal; 51 } 52 tmpvector++; 53 absVal = WEBRTC_SPL_ABS_W32((*tmpvector)); 54 if (absVal > tempMax) 55 { 56 tempMax = absVal; 57 } 58 tmpvector++; 59 absVal = WEBRTC_SPL_ABS_W32((*tmpvector)); 60 if (absVal > tempMax) 61 { 62 tempMax = absVal; 63 } 64 tmpvector++; 65 absVal = WEBRTC_SPL_ABS_W32((*tmpvector)); 66 if (absVal > tempMax) 67 { 68 tempMax = absVal; 69 } 70 tmpvector++; 71 } 72 73 for (i = len4; i < len; i++) 74 { 75 absVal = WEBRTC_SPL_ABS_W32((*tmpvector)); 76 if (absVal > tempMax) 77 { 78 tempMax = absVal; 79 } 80 tmpvector++; 81 } 82 #else 83 for (i = 0; i < length; i++) 84 { 85 absVal = WEBRTC_SPL_ABS_W32((*tmpvector)); 86 if (absVal > tempMax) 87 { 88 tempMax = absVal; 89 } 90 tmpvector++; 91 } 92 totMax = (WebRtc_Word16)WEBRTC_SPL_MIN(tempMax, WEBRTC_SPL_WORD16_MAX); 93 return totMax; 94 #endif 95 } 96 97 // Index of maximum absolute value in a word16 vector. 98 WebRtc_Word16 WebRtcSpl_MaxAbsIndexW16(G_CONST WebRtc_Word16* vector, WebRtc_Word16 length) 99 { 100 WebRtc_Word16 tempMax; 101 WebRtc_Word16 absTemp; 102 WebRtc_Word16 tempMaxIndex = 0; 103 WebRtc_Word16 i = 0; 104 G_CONST WebRtc_Word16 *tmpvector = vector; 105 106 tempMax = WEBRTC_SPL_ABS_W16(*tmpvector); 107 tmpvector++; 108 for (i = 1; i < length; i++) 109 { 110 absTemp = WEBRTC_SPL_ABS_W16(*tmpvector); 111 tmpvector++; 112 if (absTemp > tempMax) 113 { 114 tempMax = absTemp; 115 tempMaxIndex = i; 116 } 117 } 118 return tempMaxIndex; 119 } 120 121 // Maximum absolute value of word32 vector. 122 WebRtc_Word32 WebRtcSpl_MaxAbsValueW32(G_CONST WebRtc_Word32 *vector, WebRtc_Word16 length) 123 { 124 WebRtc_UWord32 tempMax = 0; 125 WebRtc_UWord32 absVal; 126 WebRtc_Word32 retval; 127 int i; 128 G_CONST WebRtc_Word32 *tmpvector = vector; 129 130 for (i = 0; i < length; i++) 131 { 132 absVal = WEBRTC_SPL_ABS_W32((*tmpvector)); 133 if (absVal > tempMax) 134 { 135 tempMax = absVal; 136 } 137 tmpvector++; 138 } 139 retval = (WebRtc_Word32)(WEBRTC_SPL_MIN(tempMax, WEBRTC_SPL_WORD32_MAX)); 140 return retval; 141 } 142 143 // Maximum value of word16 vector. 144 #ifndef XSCALE_OPT 145 WebRtc_Word16 WebRtcSpl_MaxValueW16(G_CONST WebRtc_Word16* vector, WebRtc_Word16 length) 146 { 147 WebRtc_Word16 tempMax; 148 WebRtc_Word16 i; 149 G_CONST WebRtc_Word16 *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_MaxValueW16 is excluded from this build") 161 #endif 162 163 // Index of maximum value in a word16 vector. 164 WebRtc_Word16 WebRtcSpl_MaxIndexW16(G_CONST WebRtc_Word16 *vector, WebRtc_Word16 length) 165 { 166 WebRtc_Word16 tempMax; 167 WebRtc_Word16 tempMaxIndex = 0; 168 WebRtc_Word16 i = 0; 169 G_CONST WebRtc_Word16 *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 // Maximum value of word32 vector. 184 #ifndef XSCALE_OPT 185 WebRtc_Word32 WebRtcSpl_MaxValueW32(G_CONST WebRtc_Word32* vector, WebRtc_Word16 length) 186 { 187 WebRtc_Word32 tempMax; 188 WebRtc_Word16 i; 189 G_CONST WebRtc_Word32 *tmpvector = vector; 190 191 tempMax = *tmpvector++; 192 for (i = 1; i < length; i++) 193 { 194 if (*tmpvector++ > tempMax) 195 tempMax = vector[i]; 196 } 197 return tempMax; 198 } 199 #else 200 #pragma message(">> WebRtcSpl_MaxValueW32 is excluded from this build") 201 #endif 202 203 // Index of maximum value in a word32 vector. 204 WebRtc_Word16 WebRtcSpl_MaxIndexW32(G_CONST WebRtc_Word32* vector, WebRtc_Word16 length) 205 { 206 WebRtc_Word32 tempMax; 207 WebRtc_Word16 tempMaxIndex = 0; 208 WebRtc_Word16 i = 0; 209 G_CONST WebRtc_Word32 *tmpvector = vector; 210 211 tempMax = *tmpvector++; 212 for (i = 1; i < length; i++) 213 { 214 if (*tmpvector++ > tempMax) 215 { 216 tempMax = vector[i]; 217 tempMaxIndex = i; 218 } 219 } 220 return tempMaxIndex; 221 } 222 223 // Minimum value of word16 vector. 224 WebRtc_Word16 WebRtcSpl_MinValueW16(G_CONST WebRtc_Word16 *vector, WebRtc_Word16 length) 225 { 226 WebRtc_Word16 tempMin; 227 WebRtc_Word16 i; 228 G_CONST WebRtc_Word16 *tmpvector = vector; 229 230 // Find the minimum value 231 tempMin = *tmpvector++; 232 for (i = 1; i < length; i++) 233 { 234 if (*tmpvector++ < tempMin) 235 tempMin = (vector[i]); 236 } 237 return tempMin; 238 } 239 240 // Index of minimum value in a word16 vector. 241 #ifndef XSCALE_OPT 242 WebRtc_Word16 WebRtcSpl_MinIndexW16(G_CONST WebRtc_Word16* vector, WebRtc_Word16 length) 243 { 244 WebRtc_Word16 tempMin; 245 WebRtc_Word16 tempMinIndex = 0; 246 WebRtc_Word16 i = 0; 247 G_CONST WebRtc_Word16* tmpvector = vector; 248 249 // Find index of smallest value 250 tempMin = *tmpvector++; 251 for (i = 1; i < length; i++) 252 { 253 if (*tmpvector++ < tempMin) 254 { 255 tempMin = vector[i]; 256 tempMinIndex = i; 257 } 258 } 259 return tempMinIndex; 260 } 261 #else 262 #pragma message(">> WebRtcSpl_MinIndexW16 is excluded from this build") 263 #endif 264 265 // Minimum value of word32 vector. 266 WebRtc_Word32 WebRtcSpl_MinValueW32(G_CONST WebRtc_Word32 *vector, WebRtc_Word16 length) 267 { 268 WebRtc_Word32 tempMin; 269 WebRtc_Word16 i; 270 G_CONST WebRtc_Word32 *tmpvector = vector; 271 272 // Find the minimum value 273 tempMin = *tmpvector++; 274 for (i = 1; i < length; i++) 275 { 276 if (*tmpvector++ < tempMin) 277 tempMin = (vector[i]); 278 } 279 return tempMin; 280 } 281 282 // Index of minimum value in a word32 vector. 283 #ifndef XSCALE_OPT 284 WebRtc_Word16 WebRtcSpl_MinIndexW32(G_CONST WebRtc_Word32* vector, WebRtc_Word16 length) 285 { 286 WebRtc_Word32 tempMin; 287 WebRtc_Word16 tempMinIndex = 0; 288 WebRtc_Word16 i = 0; 289 G_CONST WebRtc_Word32 *tmpvector = vector; 290 291 // Find index of smallest value 292 tempMin = *tmpvector++; 293 for (i = 1; i < length; i++) 294 { 295 if (*tmpvector++ < tempMin) 296 { 297 tempMin = vector[i]; 298 tempMinIndex = i; 299 } 300 } 301 return tempMinIndex; 302 } 303 #else 304 #pragma message(">> WebRtcSpl_MinIndexW32 is excluded from this build") 305 #endif 306