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..2b58abc4f94c74cbf22ee9426918c6dee561828e 100644 |
--- a/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c |
+++ b/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c |
@@ -18,29 +18,18 @@ |
#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) */ |
- ){ |
+void WebRtcIlbcfix_NearestNeighbor(size_t* index, |
+ const size_t* array, |
+ size_t value, |
+ size_t arlength) { |
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; |
+ size_t min_diff = (size_t)-1; |
+ for (i = 0; i < arlength; i++) { |
+ const size_t diff = |
+ (array[i] < value) ? (value - array[i]) : (array[i] - value); |
+ if (diff < min_diff) { |
+ *index = i; |
+ min_diff = diff; |
+ } |
} |
- |
- /* Find the minimum square distance */ |
- *index=WebRtcSpl_MinIndexW32(crit, arlength); |
} |