OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 /* | 11 /* |
12 * This file contains the implementation of functions | 12 * This file contains the implementation of functions |
13 * WebRtcSpl_MaxAbsValueW16C() | 13 * WebRtcSpl_MaxAbsValueW16C() |
14 * WebRtcSpl_MaxAbsValueW32C() | 14 * WebRtcSpl_MaxAbsValueW32C() |
15 * WebRtcSpl_MaxValueW16C() | 15 * WebRtcSpl_MaxValueW16C() |
16 * WebRtcSpl_MaxValueW32C() | 16 * WebRtcSpl_MaxValueW32C() |
17 * WebRtcSpl_MinValueW16C() | 17 * WebRtcSpl_MinValueW16C() |
18 * WebRtcSpl_MinValueW32C() | 18 * WebRtcSpl_MinValueW32C() |
19 * WebRtcSpl_MaxAbsIndexW16() | 19 * WebRtcSpl_MaxAbsIndexW16() |
20 * WebRtcSpl_MaxIndexW16() | 20 * WebRtcSpl_MaxIndexW16() |
21 * WebRtcSpl_MaxIndexW32() | 21 * WebRtcSpl_MaxIndexW32() |
22 * WebRtcSpl_MinIndexW16() | 22 * WebRtcSpl_MinIndexW16() |
23 * WebRtcSpl_MinIndexW32() | 23 * WebRtcSpl_MinIndexW32() |
24 * | 24 * |
25 */ | 25 */ |
26 | 26 |
27 #include <assert.h> | |
28 #include <stdlib.h> | 27 #include <stdlib.h> |
29 | 28 |
| 29 #include "webrtc/base/checks.h" |
30 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 30 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
31 | 31 |
32 // TODO(bjorn/kma): Consolidate function pairs (e.g. combine | 32 // TODO(bjorn/kma): Consolidate function pairs (e.g. combine |
33 // WebRtcSpl_MaxAbsValueW16C and WebRtcSpl_MaxAbsIndexW16 into a single one.) | 33 // WebRtcSpl_MaxAbsValueW16C and WebRtcSpl_MaxAbsIndexW16 into a single one.) |
34 // TODO(kma): Move the next six functions into min_max_operations_c.c. | 34 // TODO(kma): Move the next six functions into min_max_operations_c.c. |
35 | 35 |
36 // Maximum absolute value of word16 vector. C version for generic platforms. | 36 // Maximum absolute value of word16 vector. C version for generic platforms. |
37 int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) { | 37 int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) { |
38 size_t i = 0; | 38 size_t i = 0; |
39 int absolute = 0, maximum = 0; | 39 int absolute = 0, maximum = 0; |
40 | 40 |
41 assert(length > 0); | 41 RTC_DCHECK_GT(length, 0); |
42 | 42 |
43 for (i = 0; i < length; i++) { | 43 for (i = 0; i < length; i++) { |
44 absolute = abs((int)vector[i]); | 44 absolute = abs((int)vector[i]); |
45 | 45 |
46 if (absolute > maximum) { | 46 if (absolute > maximum) { |
47 maximum = absolute; | 47 maximum = absolute; |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 // Guard the case for abs(-32768). | 51 // Guard the case for abs(-32768). |
52 if (maximum > WEBRTC_SPL_WORD16_MAX) { | 52 if (maximum > WEBRTC_SPL_WORD16_MAX) { |
53 maximum = WEBRTC_SPL_WORD16_MAX; | 53 maximum = WEBRTC_SPL_WORD16_MAX; |
54 } | 54 } |
55 | 55 |
56 return (int16_t)maximum; | 56 return (int16_t)maximum; |
57 } | 57 } |
58 | 58 |
59 // Maximum absolute value of word32 vector. C version for generic platforms. | 59 // Maximum absolute value of word32 vector. C version for generic platforms. |
60 int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) { | 60 int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) { |
61 // Use uint32_t for the local variables, to accommodate the return value | 61 // Use uint32_t for the local variables, to accommodate the return value |
62 // of abs(0x80000000), which is 0x80000000. | 62 // of abs(0x80000000), which is 0x80000000. |
63 | 63 |
64 uint32_t absolute = 0, maximum = 0; | 64 uint32_t absolute = 0, maximum = 0; |
65 size_t i = 0; | 65 size_t i = 0; |
66 | 66 |
67 assert(length > 0); | 67 RTC_DCHECK_GT(length, 0); |
68 | 68 |
69 for (i = 0; i < length; i++) { | 69 for (i = 0; i < length; i++) { |
70 absolute = abs((int)vector[i]); | 70 absolute = abs((int)vector[i]); |
71 if (absolute > maximum) { | 71 if (absolute > maximum) { |
72 maximum = absolute; | 72 maximum = absolute; |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 maximum = WEBRTC_SPL_MIN(maximum, WEBRTC_SPL_WORD32_MAX); | 76 maximum = WEBRTC_SPL_MIN(maximum, WEBRTC_SPL_WORD32_MAX); |
77 | 77 |
78 return (int32_t)maximum; | 78 return (int32_t)maximum; |
79 } | 79 } |
80 | 80 |
81 // Maximum value of word16 vector. C version for generic platforms. | 81 // Maximum value of word16 vector. C version for generic platforms. |
82 int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) { | 82 int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) { |
83 int16_t maximum = WEBRTC_SPL_WORD16_MIN; | 83 int16_t maximum = WEBRTC_SPL_WORD16_MIN; |
84 size_t i = 0; | 84 size_t i = 0; |
85 | 85 |
86 assert(length > 0); | 86 RTC_DCHECK_GT(length, 0); |
87 | 87 |
88 for (i = 0; i < length; i++) { | 88 for (i = 0; i < length; i++) { |
89 if (vector[i] > maximum) | 89 if (vector[i] > maximum) |
90 maximum = vector[i]; | 90 maximum = vector[i]; |
91 } | 91 } |
92 return maximum; | 92 return maximum; |
93 } | 93 } |
94 | 94 |
95 // Maximum value of word32 vector. C version for generic platforms. | 95 // Maximum value of word32 vector. C version for generic platforms. |
96 int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) { | 96 int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) { |
97 int32_t maximum = WEBRTC_SPL_WORD32_MIN; | 97 int32_t maximum = WEBRTC_SPL_WORD32_MIN; |
98 size_t i = 0; | 98 size_t i = 0; |
99 | 99 |
100 assert(length > 0); | 100 RTC_DCHECK_GT(length, 0); |
101 | 101 |
102 for (i = 0; i < length; i++) { | 102 for (i = 0; i < length; i++) { |
103 if (vector[i] > maximum) | 103 if (vector[i] > maximum) |
104 maximum = vector[i]; | 104 maximum = vector[i]; |
105 } | 105 } |
106 return maximum; | 106 return maximum; |
107 } | 107 } |
108 | 108 |
109 // Minimum value of word16 vector. C version for generic platforms. | 109 // Minimum value of word16 vector. C version for generic platforms. |
110 int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) { | 110 int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) { |
111 int16_t minimum = WEBRTC_SPL_WORD16_MAX; | 111 int16_t minimum = WEBRTC_SPL_WORD16_MAX; |
112 size_t i = 0; | 112 size_t i = 0; |
113 | 113 |
114 assert(length > 0); | 114 RTC_DCHECK_GT(length, 0); |
115 | 115 |
116 for (i = 0; i < length; i++) { | 116 for (i = 0; i < length; i++) { |
117 if (vector[i] < minimum) | 117 if (vector[i] < minimum) |
118 minimum = vector[i]; | 118 minimum = vector[i]; |
119 } | 119 } |
120 return minimum; | 120 return minimum; |
121 } | 121 } |
122 | 122 |
123 // Minimum value of word32 vector. C version for generic platforms. | 123 // Minimum value of word32 vector. C version for generic platforms. |
124 int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) { | 124 int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) { |
125 int32_t minimum = WEBRTC_SPL_WORD32_MAX; | 125 int32_t minimum = WEBRTC_SPL_WORD32_MAX; |
126 size_t i = 0; | 126 size_t i = 0; |
127 | 127 |
128 assert(length > 0); | 128 RTC_DCHECK_GT(length, 0); |
129 | 129 |
130 for (i = 0; i < length; i++) { | 130 for (i = 0; i < length; i++) { |
131 if (vector[i] < minimum) | 131 if (vector[i] < minimum) |
132 minimum = vector[i]; | 132 minimum = vector[i]; |
133 } | 133 } |
134 return minimum; | 134 return minimum; |
135 } | 135 } |
136 | 136 |
137 // Index of maximum absolute value in a word16 vector. | 137 // Index of maximum absolute value in a word16 vector. |
138 size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) { | 138 size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) { |
139 // Use type int for local variables, to accomodate the value of abs(-32768). | 139 // Use type int for local variables, to accomodate the value of abs(-32768). |
140 | 140 |
141 size_t i = 0, index = 0; | 141 size_t i = 0, index = 0; |
142 int absolute = 0, maximum = 0; | 142 int absolute = 0, maximum = 0; |
143 | 143 |
144 assert(length > 0); | 144 RTC_DCHECK_GT(length, 0); |
145 | 145 |
146 for (i = 0; i < length; i++) { | 146 for (i = 0; i < length; i++) { |
147 absolute = abs((int)vector[i]); | 147 absolute = abs((int)vector[i]); |
148 | 148 |
149 if (absolute > maximum) { | 149 if (absolute > maximum) { |
150 maximum = absolute; | 150 maximum = absolute; |
151 index = i; | 151 index = i; |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 return index; | 155 return index; |
156 } | 156 } |
157 | 157 |
158 // Index of maximum value in a word16 vector. | 158 // Index of maximum value in a word16 vector. |
159 size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) { | 159 size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) { |
160 size_t i = 0, index = 0; | 160 size_t i = 0, index = 0; |
161 int16_t maximum = WEBRTC_SPL_WORD16_MIN; | 161 int16_t maximum = WEBRTC_SPL_WORD16_MIN; |
162 | 162 |
163 assert(length > 0); | 163 RTC_DCHECK_GT(length, 0); |
164 | 164 |
165 for (i = 0; i < length; i++) { | 165 for (i = 0; i < length; i++) { |
166 if (vector[i] > maximum) { | 166 if (vector[i] > maximum) { |
167 maximum = vector[i]; | 167 maximum = vector[i]; |
168 index = i; | 168 index = i; |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 return index; | 172 return index; |
173 } | 173 } |
174 | 174 |
175 // Index of maximum value in a word32 vector. | 175 // Index of maximum value in a word32 vector. |
176 size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) { | 176 size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) { |
177 size_t i = 0, index = 0; | 177 size_t i = 0, index = 0; |
178 int32_t maximum = WEBRTC_SPL_WORD32_MIN; | 178 int32_t maximum = WEBRTC_SPL_WORD32_MIN; |
179 | 179 |
180 assert(length > 0); | 180 RTC_DCHECK_GT(length, 0); |
181 | 181 |
182 for (i = 0; i < length; i++) { | 182 for (i = 0; i < length; i++) { |
183 if (vector[i] > maximum) { | 183 if (vector[i] > maximum) { |
184 maximum = vector[i]; | 184 maximum = vector[i]; |
185 index = i; | 185 index = i; |
186 } | 186 } |
187 } | 187 } |
188 | 188 |
189 return index; | 189 return index; |
190 } | 190 } |
191 | 191 |
192 // Index of minimum value in a word16 vector. | 192 // Index of minimum value in a word16 vector. |
193 size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) { | 193 size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) { |
194 size_t i = 0, index = 0; | 194 size_t i = 0, index = 0; |
195 int16_t minimum = WEBRTC_SPL_WORD16_MAX; | 195 int16_t minimum = WEBRTC_SPL_WORD16_MAX; |
196 | 196 |
197 assert(length > 0); | 197 RTC_DCHECK_GT(length, 0); |
198 | 198 |
199 for (i = 0; i < length; i++) { | 199 for (i = 0; i < length; i++) { |
200 if (vector[i] < minimum) { | 200 if (vector[i] < minimum) { |
201 minimum = vector[i]; | 201 minimum = vector[i]; |
202 index = i; | 202 index = i; |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
206 return index; | 206 return index; |
207 } | 207 } |
208 | 208 |
209 // Index of minimum value in a word32 vector. | 209 // Index of minimum value in a word32 vector. |
210 size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) { | 210 size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) { |
211 size_t i = 0, index = 0; | 211 size_t i = 0, index = 0; |
212 int32_t minimum = WEBRTC_SPL_WORD32_MAX; | 212 int32_t minimum = WEBRTC_SPL_WORD32_MAX; |
213 | 213 |
214 assert(length > 0); | 214 RTC_DCHECK_GT(length, 0); |
215 | 215 |
216 for (i = 0; i < length; i++) { | 216 for (i = 0; i < length; i++) { |
217 if (vector[i] < minimum) { | 217 if (vector[i] < minimum) { |
218 minimum = vector[i]; | 218 minimum = vector[i]; |
219 index = i; | 219 index = i; |
220 } | 220 } |
221 } | 221 } |
222 | 222 |
223 return index; | 223 return index; |
224 } | 224 } |
OLD | NEW |