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