blob: 77da78ba7fa0af17f4972ed789a7d833904af565 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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
Timothy Gu31117832020-12-18 22:25:57 -080019#include "modules/audio_coding/codecs/ilbc/abs_quant.h"
20
Mirko Bonadei06c2aa92018-02-01 15:11:41 +010021#include "modules/audio_coding/codecs/ilbc/abs_quant_loop.h"
Timothy Gu31117832020-12-18 22:25:57 -080022#include "modules/audio_coding/codecs/ilbc/constants.h"
23#include "modules/audio_coding/codecs/ilbc/defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25
26/*----------------------------------------------------------------*
27 * predictive noise shaping encoding of scaled start state
28 * (subrutine for WebRtcIlbcfix_StateSearch)
29 *---------------------------------------------------------------*/
30
31void WebRtcIlbcfix_AbsQuant(
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000032 IlbcEncoder *iLBCenc_inst,
niklase@google.com470e71d2011-07-07 08:21:25 +000033 /* (i) Encoder instance */
34 iLBC_bits *iLBC_encbits, /* (i/o) Encoded bits (outputs idxForMax
35 and idxVec, uses state_first as
36 input) */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000037 int16_t *in, /* (i) vector to encode */
38 int16_t *weightDenum /* (i) denominator of synthesis filter */
niklase@google.com470e71d2011-07-07 08:21:25 +000039 ) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +000040 int16_t *syntOut;
Peter Kastingdce40cf2015-08-24 14:52:23 -070041 size_t quantLen[2];
niklase@google.com470e71d2011-07-07 08:21:25 +000042
43 /* Stack based */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000044 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];
niklase@google.com470e71d2011-07-07 08:21:25 +000047
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}