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

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

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

Powered by Google App Engine
This is Rietveld 408576698