blob: 308902f574a46360835788535ae2ce6ddf58be74 [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
Mirko Bonadei06c2aa92018-02-01 15:11:41 +010019#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"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
23
24/*----------------------------------------------------------------*
25 * predictive noise shaping encoding of scaled start state
26 * (subrutine for WebRtcIlbcfix_StateSearch)
27 *---------------------------------------------------------------*/
28
29void WebRtcIlbcfix_AbsQuant(
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000030 IlbcEncoder *iLBCenc_inst,
niklase@google.com470e71d2011-07-07 08:21:25 +000031 /* (i) Encoder instance */
32 iLBC_bits *iLBC_encbits, /* (i/o) Encoded bits (outputs idxForMax
33 and idxVec, uses state_first as
34 input) */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000035 int16_t *in, /* (i) vector to encode */
36 int16_t *weightDenum /* (i) denominator of synthesis filter */
niklase@google.com470e71d2011-07-07 08:21:25 +000037 ) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +000038 int16_t *syntOut;
Peter Kastingdce40cf2015-08-24 14:52:23 -070039 size_t quantLen[2];
niklase@google.com470e71d2011-07-07 08:21:25 +000040
41 /* Stack based */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000042 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];
niklase@google.com470e71d2011-07-07 08:21:25 +000045
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}