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_StateConstruct.c |
| 16 | |
| 17 | ******************************************************************/ |
| 18 | |
Timothy Gu | 3111783 | 2020-12-18 22:25:57 -0800 | [diff] [blame] | 19 | #include "modules/audio_coding/codecs/ilbc/state_construct.h" |
| 20 | |
Mirko Bonadei | 06c2aa9 | 2018-02-01 15:11:41 +0100 | [diff] [blame] | 21 | #include "modules/audio_coding/codecs/ilbc/constants.h" |
Timothy Gu | 3111783 | 2020-12-18 22:25:57 -0800 | [diff] [blame] | 22 | #include "modules/audio_coding/codecs/ilbc/defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | /*----------------------------------------------------------------* |
| 25 | * decoding of the start state |
| 26 | *---------------------------------------------------------------*/ |
| 27 | |
| 28 | void WebRtcIlbcfix_StateConstruct( |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 29 | size_t idxForMax, /* (i) 6-bit index for the quantization of |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | max amplitude */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 31 | int16_t *idxVec, /* (i) vector of quantization indexes */ |
| 32 | int16_t *syntDenum, /* (i) synthesis filter denumerator */ |
| 33 | int16_t *Out_fix, /* (o) the decoded state vector */ |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 34 | size_t len /* (i) length of a state vector */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | ) { |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 36 | size_t k; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 37 | int16_t maxVal; |
| 38 | int16_t *tmp1, *tmp2, *tmp3; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | /* Stack based */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 40 | int16_t numerator[1+LPC_FILTERORDER]; |
| 41 | int16_t sampleValVec[2*STATE_SHORT_LEN_30MS+LPC_FILTERORDER]; |
| 42 | int16_t sampleMaVec[2*STATE_SHORT_LEN_30MS+LPC_FILTERORDER]; |
| 43 | int16_t *sampleVal = &sampleValVec[LPC_FILTERORDER]; |
| 44 | int16_t *sampleMa = &sampleMaVec[LPC_FILTERORDER]; |
| 45 | int16_t *sampleAr = &sampleValVec[LPC_FILTERORDER]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
| 47 | /* initialization of coefficients */ |
| 48 | |
| 49 | for (k=0; k<LPC_FILTERORDER+1; k++){ |
| 50 | numerator[k] = syntDenum[LPC_FILTERORDER-k]; |
| 51 | } |
| 52 | |
| 53 | /* decoding of the maximum value */ |
| 54 | |
| 55 | maxVal = WebRtcIlbcfix_kFrgQuantMod[idxForMax]; |
| 56 | |
| 57 | /* decoding of the sample values */ |
| 58 | tmp1 = sampleVal; |
| 59 | tmp2 = &idxVec[len-1]; |
| 60 | |
| 61 | if (idxForMax<37) { |
| 62 | for(k=0; k<len; k++){ |
| 63 | /*the shifting is due to the Q13 in sq4_fixQ13[i], also the adding of 2097152 (= 0.5 << 22) |
| 64 | maxVal is in Q8 and result is in Q(-1) */ |
bjornv@webrtc.org | ba97ea6 | 2015-02-13 09:51:40 +0000 | [diff] [blame] | 65 | *tmp1 = (int16_t)((maxVal * WebRtcIlbcfix_kStateSq3[*tmp2] + 2097152) >> |
| 66 | 22); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | tmp1++; |
| 68 | tmp2--; |
| 69 | } |
| 70 | } else if (idxForMax<59) { |
| 71 | for(k=0; k<len; k++){ |
| 72 | /*the shifting is due to the Q13 in sq4_fixQ13[i], also the adding of 262144 (= 0.5 << 19) |
| 73 | maxVal is in Q5 and result is in Q(-1) */ |
bjornv@webrtc.org | ba97ea6 | 2015-02-13 09:51:40 +0000 | [diff] [blame] | 74 | *tmp1 = (int16_t)((maxVal * WebRtcIlbcfix_kStateSq3[*tmp2] + 262144) >> |
| 75 | 19); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | tmp1++; |
| 77 | tmp2--; |
| 78 | } |
| 79 | } else { |
| 80 | for(k=0; k<len; k++){ |
| 81 | /*the shifting is due to the Q13 in sq4_fixQ13[i], also the adding of 65536 (= 0.5 << 17) |
| 82 | maxVal is in Q3 and result is in Q(-1) */ |
bjornv@webrtc.org | ba97ea6 | 2015-02-13 09:51:40 +0000 | [diff] [blame] | 83 | *tmp1 = (int16_t)((maxVal * WebRtcIlbcfix_kStateSq3[*tmp2] + 65536) >> |
| 84 | 17); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | tmp1++; |
| 86 | tmp2--; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /* Set the rest of the data to zero */ |
| 91 | WebRtcSpl_MemSetW16(&sampleVal[len], 0, len); |
| 92 | |
| 93 | /* circular convolution with all-pass filter */ |
| 94 | |
| 95 | /* Set the state to zero */ |
| 96 | WebRtcSpl_MemSetW16(sampleValVec, 0, (LPC_FILTERORDER)); |
| 97 | |
| 98 | /* Run MA filter + AR filter */ |
| 99 | WebRtcSpl_FilterMAFastQ12( |
| 100 | sampleVal, sampleMa, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 101 | numerator, LPC_FILTERORDER+1, len + LPC_FILTERORDER); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | WebRtcSpl_MemSetW16(&sampleMa[len + LPC_FILTERORDER], 0, (len - LPC_FILTERORDER)); |
| 103 | WebRtcSpl_FilterARFastQ12( |
| 104 | sampleMa, sampleAr, |
Peter Kasting | b7e5054 | 2015-06-11 12:55:50 -0700 | [diff] [blame] | 105 | syntDenum, LPC_FILTERORDER+1, 2 * len); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
| 107 | tmp1 = &sampleAr[len-1]; |
| 108 | tmp2 = &sampleAr[2*len-1]; |
| 109 | tmp3 = Out_fix; |
| 110 | for(k=0;k<len;k++){ |
| 111 | (*tmp3) = (*tmp1) + (*tmp2); |
| 112 | tmp1--; |
| 113 | tmp2--; |
| 114 | tmp3++; |
| 115 | } |
| 116 | } |