• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 /******************************************************************
12 
13  iLBC Speech Coder ANSI-C Source Code
14 
15  WebRtcIlbcfix_NearestNeighbor.c
16 
17 ******************************************************************/
18 
19 #include "modules/audio_coding/codecs/ilbc/defines.h"
20 
WebRtcIlbcfix_NearestNeighbor(size_t * index,const size_t * array,size_t value,size_t arlength)21 void WebRtcIlbcfix_NearestNeighbor(size_t* index,
22                                    const size_t* array,
23                                    size_t value,
24                                    size_t arlength) {
25   size_t i;
26   size_t min_diff = (size_t)-1;
27   for (i = 0; i < arlength; i++) {
28     const size_t diff =
29         (array[i] < value) ? (value - array[i]) : (array[i] - value);
30     if (diff < min_diff) {
31       *index = i;
32       min_diff = diff;
33     }
34   }
35 }
36