Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: webrtc/common_audio/signal_processing/min_max_operations.c

Issue 1305983003: Convert some more things to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Support Android's C89 mode Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
29
27 #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"
28 31
29 #include <stdlib.h>
30
31 // TODO(bjorn/kma): Consolidate function pairs (e.g. combine 32 // TODO(bjorn/kma): Consolidate function pairs (e.g. combine
32 // WebRtcSpl_MaxAbsValueW16C and WebRtcSpl_MaxAbsIndexW16 into a single one.) 33 // WebRtcSpl_MaxAbsValueW16C and WebRtcSpl_MaxAbsIndexW16 into a single one.)
33 // 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.
34 35
35 // Maximum absolute value of word16 vector. C version for generic platforms. 36 // Maximum absolute value of word16 vector. C version for generic platforms.
36 int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) { 37 int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) {
37 size_t i = 0; 38 size_t i = 0;
38 int absolute = 0, maximum = 0; 39 int absolute = 0, maximum = 0;
39 40
40 if (vector == NULL || length == 0) { 41 assert(length > 0);
41 return -1;
42 }
43 42
44 for (i = 0; i < length; i++) { 43 for (i = 0; i < length; i++) {
45 absolute = abs((int)vector[i]); 44 absolute = abs((int)vector[i]);
46 45
47 if (absolute > maximum) { 46 if (absolute > maximum) {
48 maximum = absolute; 47 maximum = absolute;
49 } 48 }
50 } 49 }
51 50
52 // Guard the case for abs(-32768). 51 // Guard the case for abs(-32768).
53 if (maximum > WEBRTC_SPL_WORD16_MAX) { 52 if (maximum > WEBRTC_SPL_WORD16_MAX) {
54 maximum = WEBRTC_SPL_WORD16_MAX; 53 maximum = WEBRTC_SPL_WORD16_MAX;
55 } 54 }
56 55
57 return (int16_t)maximum; 56 return (int16_t)maximum;
58 } 57 }
59 58
60 // Maximum absolute value of word32 vector. C version for generic platforms. 59 // Maximum absolute value of word32 vector. C version for generic platforms.
61 int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) { 60 int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) {
62 // 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
63 // of abs(0x80000000), which is 0x80000000. 62 // of abs(0x80000000), which is 0x80000000.
64 63
65 uint32_t absolute = 0, maximum = 0; 64 uint32_t absolute = 0, maximum = 0;
66 size_t i = 0; 65 size_t i = 0;
67 66
68 if (vector == NULL || length == 0) { 67 assert(length > 0);
69 return -1;
70 }
71 68
72 for (i = 0; i < length; i++) { 69 for (i = 0; i < length; i++) {
73 absolute = abs((int)vector[i]); 70 absolute = abs((int)vector[i]);
74 if (absolute > maximum) { 71 if (absolute > maximum) {
75 maximum = absolute; 72 maximum = absolute;
76 } 73 }
77 } 74 }
78 75
79 maximum = WEBRTC_SPL_MIN(maximum, WEBRTC_SPL_WORD32_MAX); 76 maximum = WEBRTC_SPL_MIN(maximum, WEBRTC_SPL_WORD32_MAX);
80 77
81 return (int32_t)maximum; 78 return (int32_t)maximum;
82 } 79 }
83 80
84 // Maximum value of word16 vector. C version for generic platforms. 81 // Maximum value of word16 vector. C version for generic platforms.
85 int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) { 82 int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) {
86 int16_t maximum = WEBRTC_SPL_WORD16_MIN; 83 int16_t maximum = WEBRTC_SPL_WORD16_MIN;
87 size_t i = 0; 84 size_t i = 0;
88 85
89 if (vector == NULL || length == 0) { 86 assert(length > 0);
90 return maximum;
91 }
92 87
93 for (i = 0; i < length; i++) { 88 for (i = 0; i < length; i++) {
94 if (vector[i] > maximum) 89 if (vector[i] > maximum)
95 maximum = vector[i]; 90 maximum = vector[i];
96 } 91 }
97 return maximum; 92 return maximum;
98 } 93 }
99 94
100 // Maximum value of word32 vector. C version for generic platforms. 95 // Maximum value of word32 vector. C version for generic platforms.
101 int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) { 96 int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) {
102 int32_t maximum = WEBRTC_SPL_WORD32_MIN; 97 int32_t maximum = WEBRTC_SPL_WORD32_MIN;
103 size_t i = 0; 98 size_t i = 0;
104 99
105 if (vector == NULL || length == 0) { 100 assert(length > 0);
106 return maximum;
107 }
108 101
109 for (i = 0; i < length; i++) { 102 for (i = 0; i < length; i++) {
110 if (vector[i] > maximum) 103 if (vector[i] > maximum)
111 maximum = vector[i]; 104 maximum = vector[i];
112 } 105 }
113 return maximum; 106 return maximum;
114 } 107 }
115 108
116 // Minimum value of word16 vector. C version for generic platforms. 109 // Minimum value of word16 vector. C version for generic platforms.
117 int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) { 110 int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) {
118 int16_t minimum = WEBRTC_SPL_WORD16_MAX; 111 int16_t minimum = WEBRTC_SPL_WORD16_MAX;
119 size_t i = 0; 112 size_t i = 0;
120 113
121 if (vector == NULL || length == 0) { 114 assert(length > 0);
122 return minimum;
123 }
124 115
125 for (i = 0; i < length; i++) { 116 for (i = 0; i < length; i++) {
126 if (vector[i] < minimum) 117 if (vector[i] < minimum)
127 minimum = vector[i]; 118 minimum = vector[i];
128 } 119 }
129 return minimum; 120 return minimum;
130 } 121 }
131 122
132 // Minimum value of word32 vector. C version for generic platforms. 123 // Minimum value of word32 vector. C version for generic platforms.
133 int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) { 124 int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) {
134 int32_t minimum = WEBRTC_SPL_WORD32_MAX; 125 int32_t minimum = WEBRTC_SPL_WORD32_MAX;
135 size_t i = 0; 126 size_t i = 0;
136 127
137 if (vector == NULL || length == 0) { 128 assert(length > 0);
138 return minimum;
139 }
140 129
141 for (i = 0; i < length; i++) { 130 for (i = 0; i < length; i++) {
142 if (vector[i] < minimum) 131 if (vector[i] < minimum)
143 minimum = vector[i]; 132 minimum = vector[i];
144 } 133 }
145 return minimum; 134 return minimum;
146 } 135 }
147 136
148 // Index of maximum absolute value in a word16 vector. 137 // Index of maximum absolute value in a word16 vector.
149 int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) { 138 size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) {
150 // 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).
151 140
152 size_t i = 0, index = 0; 141 size_t i = 0, index = 0;
153 int absolute = 0, maximum = 0; 142 int absolute = 0, maximum = 0;
154 143
155 if (vector == NULL || length == 0) { 144 assert(length > 0);
156 return -1;
157 }
158 145
159 for (i = 0; i < length; i++) { 146 for (i = 0; i < length; i++) {
160 absolute = abs((int)vector[i]); 147 absolute = abs((int)vector[i]);
161 148
162 if (absolute > maximum) { 149 if (absolute > maximum) {
163 maximum = absolute; 150 maximum = absolute;
164 index = i; 151 index = i;
165 } 152 }
166 } 153 }
167 154
168 return (int)index; 155 return index;
169 } 156 }
170 157
171 // Index of maximum value in a word16 vector. 158 // Index of maximum value in a word16 vector.
172 int WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) { 159 size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) {
173 size_t i = 0, index = 0; 160 size_t i = 0, index = 0;
174 int16_t maximum = WEBRTC_SPL_WORD16_MIN; 161 int16_t maximum = WEBRTC_SPL_WORD16_MIN;
175 162
176 if (vector == NULL || length == 0) { 163 assert(length > 0);
177 return -1;
178 }
179 164
180 for (i = 0; i < length; i++) { 165 for (i = 0; i < length; i++) {
181 if (vector[i] > maximum) { 166 if (vector[i] > maximum) {
182 maximum = vector[i]; 167 maximum = vector[i];
183 index = i; 168 index = i;
184 } 169 }
185 } 170 }
186 171
187 return (int)index; 172 return index;
188 } 173 }
189 174
190 // Index of maximum value in a word32 vector. 175 // Index of maximum value in a word32 vector.
191 int WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) { 176 size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) {
192 size_t i = 0, index = 0; 177 size_t i = 0, index = 0;
193 int32_t maximum = WEBRTC_SPL_WORD32_MIN; 178 int32_t maximum = WEBRTC_SPL_WORD32_MIN;
194 179
195 if (vector == NULL || length == 0) { 180 assert(length > 0);
196 return -1;
197 }
198 181
199 for (i = 0; i < length; i++) { 182 for (i = 0; i < length; i++) {
200 if (vector[i] > maximum) { 183 if (vector[i] > maximum) {
201 maximum = vector[i]; 184 maximum = vector[i];
202 index = i; 185 index = i;
203 } 186 }
204 } 187 }
205 188
206 return (int)index; 189 return index;
207 } 190 }
208 191
209 // Index of minimum value in a word16 vector. 192 // Index of minimum value in a word16 vector.
210 int WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) { 193 size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) {
211 size_t i = 0, index = 0; 194 size_t i = 0, index = 0;
212 int16_t minimum = WEBRTC_SPL_WORD16_MAX; 195 int16_t minimum = WEBRTC_SPL_WORD16_MAX;
213 196
214 if (vector == NULL || length == 0) { 197 assert(length > 0);
215 return -1;
216 }
217 198
218 for (i = 0; i < length; i++) { 199 for (i = 0; i < length; i++) {
219 if (vector[i] < minimum) { 200 if (vector[i] < minimum) {
220 minimum = vector[i]; 201 minimum = vector[i];
221 index = i; 202 index = i;
222 } 203 }
223 } 204 }
224 205
225 return (int)index; 206 return index;
226 } 207 }
227 208
228 // Index of minimum value in a word32 vector. 209 // Index of minimum value in a word32 vector.
229 int WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) { 210 size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) {
230 size_t i = 0, index = 0; 211 size_t i = 0, index = 0;
231 int32_t minimum = WEBRTC_SPL_WORD32_MAX; 212 int32_t minimum = WEBRTC_SPL_WORD32_MAX;
232 213
233 if (vector == NULL || length == 0) { 214 assert(length > 0);
234 return -1;
235 }
236 215
237 for (i = 0; i < length; i++) { 216 for (i = 0; i < length; i++) {
238 if (vector[i] < minimum) { 217 if (vector[i] < minimum) {
239 minimum = vector[i]; 218 minimum = vector[i];
240 index = i; 219 index = i;
241 } 220 }
242 } 221 }
243 222
244 return (int)index; 223 return index;
245 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698