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_AbsQuantLoop.c
16
17 ******************************************************************/
18
19 #include "modules/audio_coding/codecs/ilbc/abs_quant_loop.h"
20
21 #include "modules/audio_coding/codecs/ilbc/constants.h"
22 #include "modules/audio_coding/codecs/ilbc/defines.h"
23 #include "modules/audio_coding/codecs/ilbc/sort_sq.h"
24
WebRtcIlbcfix_AbsQuantLoop(int16_t * syntOutIN,int16_t * in_weightedIN,int16_t * weightDenumIN,size_t * quantLenIN,int16_t * idxVecIN)25 void WebRtcIlbcfix_AbsQuantLoop(int16_t *syntOutIN, int16_t *in_weightedIN,
26 int16_t *weightDenumIN, size_t *quantLenIN,
27 int16_t *idxVecIN ) {
28 size_t k1, k2;
29 int16_t index;
30 int32_t toQW32;
31 int32_t toQ32;
32 int16_t tmp16a;
33 int16_t xq;
34
35 int16_t *syntOut = syntOutIN;
36 int16_t *in_weighted = in_weightedIN;
37 int16_t *weightDenum = weightDenumIN;
38 size_t *quantLen = quantLenIN;
39 int16_t *idxVec = idxVecIN;
40
41 for(k1=0;k1<2;k1++) {
42 for(k2=0;k2<quantLen[k1];k2++){
43
44 /* Filter to get the predicted value */
45 WebRtcSpl_FilterARFastQ12(
46 syntOut, syntOut,
47 weightDenum, LPC_FILTERORDER+1, 1);
48
49 /* the quantizer */
50 toQW32 = (int32_t)(*in_weighted) - (int32_t)(*syntOut);
51
52 toQ32 = (((int32_t)toQW32)<<2);
53
54 if (toQ32 > 32767) {
55 toQ32 = (int32_t) 32767;
56 } else if (toQ32 < -32768) {
57 toQ32 = (int32_t) -32768;
58 }
59
60 /* Quantize the state */
61 if (toQW32<(-7577)) {
62 /* To prevent negative overflow */
63 index=0;
64 } else if (toQW32>8151) {
65 /* To prevent positive overflow */
66 index=7;
67 } else {
68 /* Find the best quantization index
69 (state_sq3Tbl is in Q13 and toQ is in Q11)
70 */
71 WebRtcIlbcfix_SortSq(&xq, &index,
72 (int16_t)toQ32,
73 WebRtcIlbcfix_kStateSq3, 8);
74 }
75
76 /* Store selected index */
77 (*idxVec++) = index;
78
79 /* Compute decoded sample and update of the prediction filter */
80 tmp16a = ((WebRtcIlbcfix_kStateSq3[index] + 2 ) >> 2);
81
82 *syntOut = (int16_t) (tmp16a + (int32_t)(*in_weighted) - toQW32);
83
84 syntOut++; in_weighted++;
85 }
86 /* Update perceptual weighting filter at subframe border */
87 weightDenum += 11;
88 }
89 }
90