OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 /****************************************************************** | 11 /****************************************************************** |
12 | 12 |
13 iLBC Speech Coder ANSI-C Source Code | 13 iLBC Speech Coder ANSI-C Source Code |
14 | 14 |
15 WebRtcIlbcfix_DecodeResidual.c | 15 WebRtcIlbcfix_DecodeResidual.c |
16 | 16 |
17 ******************************************************************/ | 17 ******************************************************************/ |
18 | 18 |
| 19 #include "decode_residual.h" |
| 20 |
19 #include <string.h> | 21 #include <string.h> |
20 | 22 |
21 #include "defines.h" | 23 #include "defines.h" |
22 #include "state_construct.h" | 24 #include "state_construct.h" |
23 #include "cb_construct.h" | 25 #include "cb_construct.h" |
24 #include "index_conv_dec.h" | 26 #include "index_conv_dec.h" |
25 #include "do_plc.h" | 27 #include "do_plc.h" |
26 #include "constants.h" | 28 #include "constants.h" |
27 #include "enhancer_interface.h" | 29 #include "enhancer_interface.h" |
28 #include "xcorr_coef.h" | 30 #include "xcorr_coef.h" |
29 #include "lsf_check.h" | 31 #include "lsf_check.h" |
30 | 32 |
31 /*----------------------------------------------------------------* | 33 /*----------------------------------------------------------------* |
32 * frame residual decoder function (subrutine to iLBC_decode) | 34 * frame residual decoder function (subrutine to iLBC_decode) |
33 *---------------------------------------------------------------*/ | 35 *---------------------------------------------------------------*/ |
34 | 36 |
35 void WebRtcIlbcfix_DecodeResidual( | 37 bool WebRtcIlbcfix_DecodeResidual( |
36 IlbcDecoder *iLBCdec_inst, | 38 IlbcDecoder *iLBCdec_inst, |
37 /* (i/o) the decoder state structure */ | 39 /* (i/o) the decoder state structure */ |
38 iLBC_bits *iLBC_encbits, /* (i/o) Encoded bits, which are used | 40 iLBC_bits *iLBC_encbits, /* (i/o) Encoded bits, which are used |
39 for the decoding */ | 41 for the decoding */ |
40 int16_t *decresidual, /* (o) decoded residual frame */ | 42 int16_t *decresidual, /* (o) decoded residual frame */ |
41 int16_t *syntdenum /* (i) the decoded synthesis filter | 43 int16_t *syntdenum /* (i) the decoded synthesis filter |
42 coefficients */ | 44 coefficients */ |
43 ) { | 45 ) { |
44 size_t meml_gotten, diff, start_pos; | 46 size_t meml_gotten, diff, start_pos; |
45 size_t subcount, subframe; | 47 size_t subcount, subframe; |
(...skipping 19 matching lines...) Expand all Loading... |
65 if (iLBC_encbits->state_first) { /* put adaptive part in the end */ | 67 if (iLBC_encbits->state_first) { /* put adaptive part in the end */ |
66 | 68 |
67 /* setup memory */ | 69 /* setup memory */ |
68 | 70 |
69 WebRtcSpl_MemSetW16(mem, 0, CB_MEML - iLBCdec_inst->state_short_len); | 71 WebRtcSpl_MemSetW16(mem, 0, CB_MEML - iLBCdec_inst->state_short_len); |
70 WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-iLBCdec_inst->state_short_len, decresidual
+start_pos, | 72 WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-iLBCdec_inst->state_short_len, decresidual
+start_pos, |
71 iLBCdec_inst->state_short_len); | 73 iLBCdec_inst->state_short_len); |
72 | 74 |
73 /* construct decoded vector */ | 75 /* construct decoded vector */ |
74 | 76 |
75 WebRtcIlbcfix_CbConstruct( | 77 if (!WebRtcIlbcfix_CbConstruct( |
76 &decresidual[start_pos+iLBCdec_inst->state_short_len], | 78 &decresidual[start_pos + iLBCdec_inst->state_short_len], |
77 iLBC_encbits->cb_index, iLBC_encbits->gain_index, | 79 iLBC_encbits->cb_index, iLBC_encbits->gain_index, |
78 mem+CB_MEML-ST_MEM_L_TBL, | 80 mem + CB_MEML - ST_MEM_L_TBL, ST_MEM_L_TBL, diff)) |
79 ST_MEM_L_TBL, diff); | 81 return false; // Error. |
80 | 82 |
81 } | 83 } |
82 else {/* put adaptive part in the beginning */ | 84 else {/* put adaptive part in the beginning */ |
83 | 85 |
84 /* setup memory */ | 86 /* setup memory */ |
85 | 87 |
86 meml_gotten = iLBCdec_inst->state_short_len; | 88 meml_gotten = iLBCdec_inst->state_short_len; |
87 WebRtcSpl_MemCpyReversedOrder(mem+CB_MEML-1, | 89 WebRtcSpl_MemCpyReversedOrder(mem+CB_MEML-1, |
88 decresidual+start_pos, meml_gotten); | 90 decresidual+start_pos, meml_gotten); |
89 WebRtcSpl_MemSetW16(mem, 0, CB_MEML - meml_gotten); | 91 WebRtcSpl_MemSetW16(mem, 0, CB_MEML - meml_gotten); |
90 | 92 |
91 /* construct decoded vector */ | 93 /* construct decoded vector */ |
92 | 94 |
93 WebRtcIlbcfix_CbConstruct( | 95 if (!WebRtcIlbcfix_CbConstruct(reverseDecresidual, iLBC_encbits->cb_index, |
94 reverseDecresidual, | 96 iLBC_encbits->gain_index, |
95 iLBC_encbits->cb_index, iLBC_encbits->gain_index, | 97 mem + CB_MEML - ST_MEM_L_TBL, ST_MEM_L_TBL, |
96 mem+CB_MEML-ST_MEM_L_TBL, | 98 diff)) |
97 ST_MEM_L_TBL, diff | 99 return false; // Error. |
98 ); | |
99 | 100 |
100 /* get decoded residual from reversed vector */ | 101 /* get decoded residual from reversed vector */ |
101 | 102 |
102 WebRtcSpl_MemCpyReversedOrder(&decresidual[start_pos-1], | 103 WebRtcSpl_MemCpyReversedOrder(&decresidual[start_pos-1], |
103 reverseDecresidual, diff); | 104 reverseDecresidual, diff); |
104 } | 105 } |
105 | 106 |
106 /* counter for predicted subframes */ | 107 /* counter for predicted subframes */ |
107 | 108 |
108 subcount=1; | 109 subcount=1; |
109 | 110 |
110 /* forward prediction of subframes */ | 111 /* forward prediction of subframes */ |
111 | 112 |
112 if (iLBCdec_inst->nsub > iLBC_encbits->startIdx + 1) { | 113 if (iLBCdec_inst->nsub > iLBC_encbits->startIdx + 1) { |
113 | 114 |
114 /* setup memory */ | 115 /* setup memory */ |
115 WebRtcSpl_MemSetW16(mem, 0, CB_MEML-STATE_LEN); | 116 WebRtcSpl_MemSetW16(mem, 0, CB_MEML-STATE_LEN); |
116 WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-STATE_LEN, | 117 WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-STATE_LEN, |
117 decresidual+(iLBC_encbits->startIdx-1)*SUBL, STATE_LEN
); | 118 decresidual+(iLBC_encbits->startIdx-1)*SUBL, STATE_LEN
); |
118 | 119 |
119 /* loop over subframes to encode */ | 120 /* loop over subframes to encode */ |
120 | 121 |
121 size_t Nfor = iLBCdec_inst->nsub - iLBC_encbits->startIdx - 1; | 122 size_t Nfor = iLBCdec_inst->nsub - iLBC_encbits->startIdx - 1; |
122 for (subframe=0; subframe<Nfor; subframe++) { | 123 for (subframe=0; subframe<Nfor; subframe++) { |
123 | 124 |
124 /* construct decoded vector */ | 125 /* construct decoded vector */ |
125 WebRtcIlbcfix_CbConstruct( | 126 if (!WebRtcIlbcfix_CbConstruct( |
126 &decresidual[(iLBC_encbits->startIdx+1+subframe)*SUBL], | 127 &decresidual[(iLBC_encbits->startIdx + 1 + subframe) * SUBL], |
127 iLBC_encbits->cb_index+subcount*CB_NSTAGES, | 128 iLBC_encbits->cb_index + subcount * CB_NSTAGES, |
128 iLBC_encbits->gain_index+subcount*CB_NSTAGES, | 129 iLBC_encbits->gain_index + subcount * CB_NSTAGES, mem, MEM_LF_TBL, |
129 mem, MEM_LF_TBL, SUBL | 130 SUBL)) |
130 ); | 131 return false; // Error; |
131 | 132 |
132 /* update memory */ | 133 /* update memory */ |
133 memmove(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(*mem)); | 134 memmove(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(*mem)); |
134 WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-SUBL, | 135 WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-SUBL, |
135 &decresidual[(iLBC_encbits->startIdx+1+subframe)*SUB
L], SUBL); | 136 &decresidual[(iLBC_encbits->startIdx+1+subframe)*SUB
L], SUBL); |
136 | 137 |
137 subcount++; | 138 subcount++; |
138 } | 139 } |
139 | 140 |
140 } | 141 } |
(...skipping 12 matching lines...) Expand all Loading... |
153 WebRtcSpl_MemCpyReversedOrder(mem+CB_MEML-1, | 154 WebRtcSpl_MemCpyReversedOrder(mem+CB_MEML-1, |
154 decresidual+(iLBC_encbits->startIdx-1)*SUBL, m
eml_gotten); | 155 decresidual+(iLBC_encbits->startIdx-1)*SUBL, m
eml_gotten); |
155 WebRtcSpl_MemSetW16(mem, 0, CB_MEML - meml_gotten); | 156 WebRtcSpl_MemSetW16(mem, 0, CB_MEML - meml_gotten); |
156 | 157 |
157 /* loop over subframes to decode */ | 158 /* loop over subframes to decode */ |
158 | 159 |
159 size_t Nback = iLBC_encbits->startIdx - 1; | 160 size_t Nback = iLBC_encbits->startIdx - 1; |
160 for (subframe=0; subframe<Nback; subframe++) { | 161 for (subframe=0; subframe<Nback; subframe++) { |
161 | 162 |
162 /* construct decoded vector */ | 163 /* construct decoded vector */ |
163 WebRtcIlbcfix_CbConstruct( | 164 if (!WebRtcIlbcfix_CbConstruct( |
164 &reverseDecresidual[subframe*SUBL], | 165 &reverseDecresidual[subframe * SUBL], |
165 iLBC_encbits->cb_index+subcount*CB_NSTAGES, | 166 iLBC_encbits->cb_index + subcount * CB_NSTAGES, |
166 iLBC_encbits->gain_index+subcount*CB_NSTAGES, | 167 iLBC_encbits->gain_index + subcount * CB_NSTAGES, mem, MEM_LF_TBL, |
167 mem, MEM_LF_TBL, SUBL | 168 SUBL)) |
168 ); | 169 return false; // Error. |
169 | 170 |
170 /* update memory */ | 171 /* update memory */ |
171 memmove(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(*mem)); | 172 memmove(mem, mem + SUBL, (CB_MEML - SUBL) * sizeof(*mem)); |
172 WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-SUBL, | 173 WEBRTC_SPL_MEMCPY_W16(mem+CB_MEML-SUBL, |
173 &reverseDecresidual[subframe*SUBL], SUBL); | 174 &reverseDecresidual[subframe*SUBL], SUBL); |
174 | 175 |
175 subcount++; | 176 subcount++; |
176 } | 177 } |
177 | 178 |
178 /* get decoded residual from reversed vector */ | 179 /* get decoded residual from reversed vector */ |
179 WebRtcSpl_MemCpyReversedOrder(decresidual+SUBL*Nback-1, | 180 WebRtcSpl_MemCpyReversedOrder(decresidual+SUBL*Nback-1, |
180 reverseDecresidual, SUBL*Nback); | 181 reverseDecresidual, SUBL*Nback); |
181 } | 182 } |
| 183 |
| 184 return true; // Success. |
182 } | 185 } |
OLD | NEW |