Chromium Code Reviews| Index: webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c |
| diff --git a/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c b/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c |
| index b6cc2406831952e7395b1cdb8d102318a2963da9..f1294d8d80e243c99e680cc3d71fe65bf5209fc6 100644 |
| --- a/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c |
| +++ b/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c |
| @@ -18,29 +18,16 @@ |
| #include "defines.h" |
| -/*----------------------------------------------------------------* |
| - * Find index in array such that the array element with said |
| - * index is the element of said array closest to "value" |
| - * according to the squared-error criterion |
| - *---------------------------------------------------------------*/ |
| - |
| -void WebRtcIlbcfix_NearestNeighbor( |
| - int16_t *index, /* (o) index of array element closest to value */ |
| - int16_t *array, /* (i) data array (Q2) */ |
| - int16_t value, /* (i) value (Q2) */ |
| - size_t arlength /* (i) dimension of data array (==8) */ |
| - ){ |
| - size_t i; |
| - int16_t diff; |
| - /* Stack based */ |
| - int32_t crit[8]; |
| - |
| - /* Calculate square distance */ |
| - for(i=0;i<arlength;i++){ |
| - diff=array[i]-value; |
| - crit[i] = diff * diff; |
| +void WebRtcIlbcfix_NearestNeighbor(size_t* index, |
| + const size_t* array, |
| + size_t value, |
| + size_t arlength) { |
| + size_t min_diff = static_cast<size_t>(-1); |
|
Peter Kasting
2015/08/27 00:39:03
I changed this implementation for a couple of reas
|
| + for (size_t i = 0; i < arlength; i++) { |
| + size_t diff = (array[i] < value) ? (value - array[i]) : (array[i] - value); |
|
hlundin-webrtc
2015/08/28 06:48:18
Nit: const size_t diff
|
| + if (diff < min_diff) { |
| + *index = i; |
| + min_diff = diff; |
| + } |
| } |
| - |
| - /* Find the minimum square distance */ |
| - *index=WebRtcSpl_MinIndexW32(crit, arlength); |
| } |