niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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_Vq4.c |
| 16 | |
| 17 | ******************************************************************/ |
| 18 | |
Mirko Bonadei | 06c2aa9 | 2018-02-01 15:11:41 +0100 | [diff] [blame] | 19 | #include "modules/audio_coding/codecs/ilbc/vq4.h" |
Timothy Gu | 3111783 | 2020-12-18 22:25:57 -0800 | [diff] [blame^] | 20 | |
Mirko Bonadei | 06c2aa9 | 2018-02-01 15:11:41 +0100 | [diff] [blame] | 21 | #include "modules/audio_coding/codecs/ilbc/constants.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | /*----------------------------------------------------------------* |
| 24 | * vector quantization |
| 25 | *---------------------------------------------------------------*/ |
| 26 | |
| 27 | void WebRtcIlbcfix_Vq4( |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 28 | int16_t *Xq, /* quantized vector (Q13) */ |
| 29 | int16_t *index, |
| 30 | int16_t *CB, /* codebook in Q13 */ |
| 31 | int16_t *X, /* vector to quantize (Q13) */ |
| 32 | int16_t n_cb |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | ){ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 34 | int16_t i, j; |
| 35 | int16_t pos, minindex=0; |
| 36 | int16_t tmp; |
| 37 | int32_t dist, mindist; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
| 39 | pos = 0; |
| 40 | mindist = WEBRTC_SPL_WORD32_MAX; /* start value */ |
| 41 | |
| 42 | /* Find the codebook with the lowest square distance */ |
| 43 | for (j = 0; j < n_cb; j++) { |
| 44 | tmp = X[0] - CB[pos]; |
bjornv@webrtc.org | ba97ea6 | 2015-02-13 09:51:40 +0000 | [diff] [blame] | 45 | dist = tmp * tmp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | for (i = 1; i < 4; i++) { |
| 47 | tmp = X[i] - CB[pos + i]; |
bjornv@webrtc.org | ba97ea6 | 2015-02-13 09:51:40 +0000 | [diff] [blame] | 48 | dist += tmp * tmp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | if (dist < mindist) { |
| 52 | mindist = dist; |
| 53 | minindex = j; |
| 54 | } |
| 55 | pos += 4; |
| 56 | } |
| 57 | |
| 58 | /* Store the quantized codebook and the index */ |
| 59 | for (i = 0; i < 4; i++) { |
| 60 | Xq[i] = CB[minindex*4 + i]; |
| 61 | } |
| 62 | *index = minindex; |
| 63 | } |