• 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_AbsQuant.c
16 
17 ******************************************************************/
18 
19 #include "modules/audio_coding/codecs/ilbc/defines.h"
20 #include "modules/audio_coding/codecs/ilbc/constants.h"
21 #include "modules/audio_coding/codecs/ilbc/abs_quant_loop.h"
22 
23 
24 /*----------------------------------------------------------------*
25  *  predictive noise shaping encoding of scaled start state
26  *  (subrutine for WebRtcIlbcfix_StateSearch)
27  *---------------------------------------------------------------*/
28 
WebRtcIlbcfix_AbsQuant(IlbcEncoder * iLBCenc_inst,iLBC_bits * iLBC_encbits,int16_t * in,int16_t * weightDenum)29 void WebRtcIlbcfix_AbsQuant(
30     IlbcEncoder *iLBCenc_inst,
31     /* (i) Encoder instance */
32     iLBC_bits *iLBC_encbits, /* (i/o) Encoded bits (outputs idxForMax
33                                    and idxVec, uses state_first as
34                                    input) */
35     int16_t *in,     /* (i) vector to encode */
36     int16_t *weightDenum   /* (i) denominator of synthesis filter */
37                             ) {
38   int16_t *syntOut;
39   size_t quantLen[2];
40 
41   /* Stack based */
42   int16_t syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS];
43   int16_t in_weightedVec[STATE_SHORT_LEN_30MS+LPC_FILTERORDER];
44   int16_t *in_weighted = &in_weightedVec[LPC_FILTERORDER];
45 
46   /* Initialize the buffers */
47   WebRtcSpl_MemSetW16(syntOutBuf, 0, LPC_FILTERORDER+STATE_SHORT_LEN_30MS);
48   syntOut = &syntOutBuf[LPC_FILTERORDER];
49   /* Start with zero state */
50   WebRtcSpl_MemSetW16(in_weightedVec, 0, LPC_FILTERORDER);
51 
52   /* Perform the quantization loop in two sections of length quantLen[i],
53      where the perceptual weighting filter is updated at the subframe
54      border */
55 
56   if (iLBC_encbits->state_first) {
57     quantLen[0]=SUBL;
58     quantLen[1]=iLBCenc_inst->state_short_len-SUBL;
59   } else {
60     quantLen[0]=iLBCenc_inst->state_short_len-SUBL;
61     quantLen[1]=SUBL;
62   }
63 
64   /* Calculate the weighted residual, switch perceptual weighting
65      filter at the subframe border */
66   WebRtcSpl_FilterARFastQ12(
67       in, in_weighted,
68       weightDenum, LPC_FILTERORDER+1, quantLen[0]);
69   WebRtcSpl_FilterARFastQ12(
70       &in[quantLen[0]], &in_weighted[quantLen[0]],
71       &weightDenum[LPC_FILTERORDER+1], LPC_FILTERORDER+1, quantLen[1]);
72 
73   WebRtcIlbcfix_AbsQuantLoop(
74       syntOut,
75       in_weighted,
76       weightDenum,
77       quantLen,
78       iLBC_encbits->idxVec);
79 
80 }
81