niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 06c2aa9 | 2018-02-01 15:11:41 +0100 | [diff] [blame] | 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" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
| 23 | |
| 24 | /*----------------------------------------------------------------* |
| 25 | * predictive noise shaping encoding of scaled start state |
| 26 | * (subrutine for WebRtcIlbcfix_StateSearch) |
| 27 | *---------------------------------------------------------------*/ |
| 28 | |
| 29 | void WebRtcIlbcfix_AbsQuant( |
pbos@webrtc.org | eb54446 | 2014-12-17 15:23:29 +0000 | [diff] [blame] | 30 | IlbcEncoder *iLBCenc_inst, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | /* (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.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 35 | int16_t *in, /* (i) vector to encode */ |
| 36 | int16_t *weightDenum /* (i) denominator of synthesis filter */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | ) { |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 38 | int16_t *syntOut; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 39 | size_t quantLen[2]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
| 41 | /* Stack based */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 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]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | } |