wok-current diff asterisk/stuff/rfc3951.txt @ rev 23176
openvpn: add conf2opvn (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Mar 18 11:14:38 2020 +0100 (2020-03-18) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/asterisk/stuff/rfc3951.txt Wed Mar 18 11:14:38 2020 +0100 1.3 @@ -0,0 +1,10867 @@ 1.4 + 1.5 + 1.6 + 1.7 + 1.8 + 1.9 + 1.10 +Network Working Group S. Andersen 1.11 +Request for Comments: 3951 Aalborg University 1.12 +Category: Experimental A. Duric 1.13 + Telio 1.14 + H. Astrom 1.15 + R. Hagen 1.16 + W. Kleijn 1.17 + J. Linden 1.18 + Global IP Sound 1.19 + December 2004 1.20 + 1.21 + 1.22 + Internet Low Bit Rate Codec (iLBC) 1.23 + 1.24 +Status of this Memo 1.25 + 1.26 + This memo defines an Experimental Protocol for the Internet 1.27 + community. It does not specify an Internet standard of any kind. 1.28 + Discussion and suggestions for improvement are requested. 1.29 + Distribution of this memo is unlimited. 1.30 + 1.31 +Copyright Notice 1.32 + 1.33 + Copyright (C) The Internet Society (2004). 1.34 + 1.35 +Abstract 1.36 + 1.37 + This document specifies a speech codec suitable for robust voice 1.38 + communication over IP. The codec is developed by Global IP Sound 1.39 + (GIPS). It is designed for narrow band speech and results in a 1.40 + payload bit rate of 13.33 kbit/s for 30 ms frames and 15.20 kbit/s 1.41 + for 20 ms frames. The codec enables graceful speech quality 1.42 + degradation in the case of lost frames, which occurs in connection 1.43 + with lost or delayed IP packets. 1.44 + 1.45 + 1.46 + 1.47 + 1.48 + 1.49 + 1.50 + 1.51 + 1.52 + 1.53 + 1.54 + 1.55 + 1.56 + 1.57 + 1.58 + 1.59 + 1.60 + 1.61 +Andersen, et al. Experimental [Page 1] 1.62 + 1.63 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.64 + 1.65 + 1.66 +Table of Contents 1.67 + 1.68 + 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.69 + 2. Outline of the Codec . . . . . . . . . . . . . . . . . . . . . 5 1.70 + 2.1. Encoder. . . . . . . . . . . . . . . . . . . . . . . . . 5 1.71 + 2.2. Decoder. . . . . . . . . . . . . . . . . . . . . . . . . 7 1.72 + 3. Encoder Principles . . . . . . . . . . . . . . . . . . . . . . 7 1.73 + 3.1. Pre-processing . . . . . . . . . . . . . . . . . . . . . 9 1.74 + 3.2. LPC Analysis and Quantization. . . . . . . . . . . . . . 9 1.75 + 3.2.1. Computation of Autocorrelation Coefficients. . . 10 1.76 + 3.2.2. Computation of LPC Coefficients. . . . . . . . . 11 1.77 + 3.2.3. Computation of LSF Coefficients from LPC 1.78 + Coefficients . . . . . . . . . . . . . . . . . . 11 1.79 + 3.2.4. Quantization of LSF Coefficients . . . . . . . . 12 1.80 + 3.2.5. Stability Check of LSF Coefficients. . . . . . . 13 1.81 + 3.2.6. Interpolation of LSF Coefficients. . . . . . . . 13 1.82 + 3.2.7. LPC Analysis and Quantization for 20 ms Frames . 14 1.83 + 3.3. Calculation of the Residual. . . . . . . . . . . . . . . 15 1.84 + 3.4. Perceptual Weighting Filter. . . . . . . . . . . . . . . 15 1.85 + 3.5. Start State Encoder. . . . . . . . . . . . . . . . . . . 15 1.86 + 3.5.1. Start State Estimation . . . . . . . . . . . . . 16 1.87 + 3.5.2. All-Pass Filtering and Scale Quantization. . . . 17 1.88 + 3.5.3. Scalar Quantization. . . . . . . . . . . . . . . 18 1.89 + 3.6. Encoding the Remaining Samples . . . . . . . . . . . . . 19 1.90 + 3.6.1. Codebook Memory. . . . . . . . . . . . . . . . . 20 1.91 + 3.6.2. Perceptual Weighting of Codebook Memory 1.92 + and Target . . . . . . . . . . . . . . . . . . . 22 1.93 + 3.6.3. Codebook Creation. . . . . . . . . . . . . . . . 23 1.94 + 3.6.3.1. Creation of a Base Codebook . . . . . . 23 1.95 + 3.6.3.2. Codebook Expansion. . . . . . . . . . . 24 1.96 + 3.6.3.3. Codebook Augmentation . . . . . . . . . 24 1.97 + 3.6.4. Codebook Search. . . . . . . . . . . . . . . . . 26 1.98 + 3.6.4.1. Codebook Search at Each Stage . . . . . 26 1.99 + 3.6.4.2. Gain Quantization at Each Stage . . . . 27 1.100 + 3.6.4.3. Preparation of Target for Next Stage. . 28 1.101 + 3.7. Gain Correction Encoding . . . . . . . . . . . . . . . . 28 1.102 + 3.8. Bitstream Definition . . . . . . . . . . . . . . . . . . 29 1.103 + 4. Decoder Principles . . . . . . . . . . . . . . . . . . . . . . 32 1.104 + 4.1. LPC Filter Reconstruction. . . . . . . . . . . . . . . . 33 1.105 + 4.2. Start State Reconstruction . . . . . . . . . . . . . . . 33 1.106 + 4.3. Excitation Decoding Loop . . . . . . . . . . . . . . . . 34 1.107 + 4.4. Multistage Adaptive Codebook Decoding. . . . . . . . . . 35 1.108 + 4.4.1. Construction of the Decoded Excitation Signal. . 35 1.109 + 4.5. Packet Loss Concealment. . . . . . . . . . . . . . . . . 35 1.110 + 4.5.1. Block Received Correctly and Previous Block 1.111 + Also Received. . . . . . . . . . . . . . . . . . 35 1.112 + 4.5.2. Block Not Received . . . . . . . . . . . . . . . 36 1.113 + 1.114 + 1.115 + 1.116 + 1.117 +Andersen, et al. Experimental [Page 2] 1.118 + 1.119 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.120 + 1.121 + 1.122 + 4.5.3. Block Received Correctly When Previous Block 1.123 + Not Received . . . . . . . . . . . . . . . . . . 36 1.124 + 4.6. Enhancement. . . . . . . . . . . . . . . . . . . . . . . 37 1.125 + 4.6.1. Estimating the Pitch . . . . . . . . . . . . . . 39 1.126 + 4.6.2. Determination of the Pitch-Synchronous 1.127 + Sequences. . . . . . . . . . . . . . . . . . . . 39 1.128 + 4.6.3. Calculation of the Smoothed Excitation . . . . . 41 1.129 + 4.6.4. Enhancer Criterion . . . . . . . . . . . . . . . 41 1.130 + 4.6.5. Enhancing the Excitation . . . . . . . . . . . . 42 1.131 + 4.7. Synthesis Filtering. . . . . . . . . . . . . . . . . . . 43 1.132 + 4.8. Post Filtering . . . . . . . . . . . . . . . . . . . . . 43 1.133 + 5. Security Considerations. . . . . . . . . . . . . . . . . . . . 43 1.134 + 6. Evaluation of the iLBC Implementations . . . . . . . . . . . . 43 1.135 + 7. References . . . . . . . . . . . . . . . . . . . . . . . . . . 43 1.136 + 7.1. Normative References . . . . . . . . . . . . . . . . . . 43 1.137 + 7.2. Informative References . . . . . . . . . . . . . . . . . 44 1.138 + 8. ACKNOWLEDGEMENTS . . . . . . . . . . . . . . . . . . . . . . . 44 1.139 + APPENDIX A: Reference Implementation . . . . . . . . . . . . . . . 45 1.140 + A.1. iLBC_test.c. . . . . . . . . . . . . . . . . . . . . . . 46 1.141 + A.2 iLBC_encode.h. . . . . . . . . . . . . . . . . . . . . . 52 1.142 + A.3. iLBC_encode.c. . . . . . . . . . . . . . . . . . . . . . 53 1.143 + A.4. iLBC_decode.h. . . . . . . . . . . . . . . . . . . . . . 63 1.144 + A.5. iLBC_decode.c. . . . . . . . . . . . . . . . . . . . . . 64 1.145 + A.6. iLBC_define.h. . . . . . . . . . . . . . . . . . . . . . 76 1.146 + A.7. constants.h. . . . . . . . . . . . . . . . . . . . . . . 80 1.147 + A.8. constants.c. . . . . . . . . . . . . . . . . . . . . . . 82 1.148 + A.9. anaFilter.h. . . . . . . . . . . . . . . . . . . . . . . 96 1.149 + A.10. anaFilter.c. . . . . . . . . . . . . . . . . . . . . . . 97 1.150 + A.11. createCB.h . . . . . . . . . . . . . . . . . . . . . . . 98 1.151 + A.12. createCB.c . . . . . . . . . . . . . . . . . . . . . . . 99 1.152 + A.13. doCPLC.h . . . . . . . . . . . . . . . . . . . . . . . .104 1.153 + A.14. doCPLC.c . . . . . . . . . . . . . . . . . . . . . . . .104 1.154 + A.15. enhancer.h . . . . . . . . . . . . . . . . . . . . . . .109 1.155 + A.16. enhancer.c . . . . . . . . . . . . . . . . . . . . . . .110 1.156 + A.17. filter.h . . . . . . . . . . . . . . . . . . . . . . . .123 1.157 + A.18. filter.c . . . . . . . . . . . . . . . . . . . . . . . .125 1.158 + A.19. FrameClassify.h. . . . . . . . . . . . . . . . . . . . .128 1.159 + A.20. FrameClassify.c. . . . . . . . . . . . . . . . . . . . .129 1.160 + A.21. gainquant.h. . . . . . . . . . . . . . . . . . . . . . .131 1.161 + A.22. gainquant.c. . . . . . . . . . . . . . . . . . . . . . .131 1.162 + A.23. getCBvec.h . . . . . . . . . . . . . . . . . . . . . . .134 1.163 + A.24. getCBvec.c . . . . . . . . . . . . . . . . . . . . . . .134 1.164 + A.25. helpfun.h. . . . . . . . . . . . . . . . . . . . . . . .138 1.165 + A.26. helpfun.c. . . . . . . . . . . . . . . . . . . . . . . .140 1.166 + A.27. hpInput.h. . . . . . . . . . . . . . . . . . . . . . . .146 1.167 + A.28. hpInput.c. . . . . . . . . . . . . . . . . . . . . . . .146 1.168 + A.29. hpOutput.h . . . . . . . . . . . . . . . . . . . . . . .148 1.169 + A.30. hpOutput.c . . . . . . . . . . . . . . . . . . . . . . .148 1.170 + 1.171 + 1.172 + 1.173 +Andersen, et al. Experimental [Page 3] 1.174 + 1.175 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.176 + 1.177 + 1.178 + A.31. iCBConstruct.h . . . . . . . . . . . . . . . . . . . . .149 1.179 + A.32. iCBConstruct.c . . . . . . . . . . . . . . . . . . . . .150 1.180 + A.33. iCBSearch.h. . . . . . . . . . . . . . . . . . . . . . .152 1.181 + A.34. iCBSearch.c. . . . . . . . . . . . . . . . . . . . . . .153 1.182 + A.35. LPCdecode.h. . . . . . . . . . . . . . . . . . . . . . .163 1.183 + A.36. LPCdecode.c. . . . . . . . . . . . . . . . . . . . . . .164 1.184 + A.37. LPCencode.h. . . . . . . . . . . . . . . . . . . . . . .167 1.185 + A.38. LPCencode.c. . . . . . . . . . . . . . . . . . . . . . .167 1.186 + A.39. lsf.h. . . . . . . . . . . . . . . . . . . . . . . . . .172 1.187 + A.40. lsf.c. . . . . . . . . . . . . . . . . . . . . . . . . .172 1.188 + A.41. packing.h. . . . . . . . . . . . . . . . . . . . . . . .178 1.189 + A.42. packing.c. . . . . . . . . . . . . . . . . . . . . . . .179 1.190 + A.43. StateConstructW.h. . . . . . . . . . . . . . . . . . . .182 1.191 + A.44. StateConstructW.c. . . . . . . . . . . . . . . . . . . .183 1.192 + A.45. StateSearchW.h . . . . . . . . . . . . . . . . . . . . .185 1.193 + A.46. StateSearchW.c . . . . . . . . . . . . . . . . . . . . .186 1.194 + A.47. syntFilter.h . . . . . . . . . . . . . . . . . . . . . .190 1.195 + A.48. syntFilter.c . . . . . . . . . . . . . . . . . . . . . .190 1.196 + Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . .192 1.197 + Full Copyright Statement . . . . . . . . . . . . . . . . . . . . .194 1.198 + 1.199 +1. Introduction 1.200 + 1.201 + This document contains the description of an algorithm for the coding 1.202 + of speech signals sampled at 8 kHz. The algorithm, called iLBC, uses 1.203 + a block-independent linear-predictive coding (LPC) algorithm and has 1.204 + support for two basic frame lengths: 20 ms at 15.2 kbit/s and 30 ms 1.205 + at 13.33 kbit/s. When the codec operates at block lengths of 20 ms, 1.206 + it produces 304 bits per block, which SHOULD be packetized as in [1]. 1.207 + Similarly, for block lengths of 30 ms it produces 400 bits per block, 1.208 + which SHOULD be packetized as in [1]. The two modes for the 1.209 + different frame sizes operate in a very similar way. When they 1.210 + differ it is explicitly stated in the text, usually with the notation 1.211 + x/y, where x refers to the 20 ms mode and y refers to the 30 ms mode. 1.212 + 1.213 + The described algorithm results in a speech coding system with a 1.214 + controlled response to packet losses similar to what is known from 1.215 + pulse code modulation (PCM) with packet loss concealment (PLC), such 1.216 + as the ITU-T G.711 standard [4], which operates at a fixed bit rate 1.217 + of 64 kbit/s. At the same time, the described algorithm enables 1.218 + fixed bit rate coding with a quality-versus-bit rate tradeoff close 1.219 + to state-of-the-art. A suitable RTP payload format for the iLBC 1.220 + codec is specified in [1]. 1.221 + 1.222 + Some of the applications for which this coder is suitable are real 1.223 + time communications such as telephony and videoconferencing, 1.224 + streaming audio, archival, and messaging. 1.225 + 1.226 + 1.227 + 1.228 + 1.229 +Andersen, et al. Experimental [Page 4] 1.230 + 1.231 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.232 + 1.233 + 1.234 + Cable Television Laboratories (CableLabs(R)) has adopted iLBC as a 1.235 + mandatory PacketCable(TM) audio codec standard for VoIP over Cable 1.236 + applications [3]. 1.237 + 1.238 + This document is organized as follows. Section 2 gives a brief 1.239 + outline of the codec. The specific encoder and decoder algorithms 1.240 + are explained in sections 3 and 4, respectively. Appendix A provides 1.241 + a c-code reference implementation. 1.242 + 1.243 + The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 1.244 + "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 1.245 + document are to be interpreted as described in BCP 14, RFC 2119 [2]. 1.246 + 1.247 +2. Outline of the Codec 1.248 + 1.249 + The codec consists of an encoder and a decoder as described in 1.250 + sections 2.1 and 2.2, respectively. 1.251 + 1.252 + The essence of the codec is LPC and block-based coding of the LPC 1.253 + residual signal. For each 160/240 (20 ms/30 ms) sample block, the 1.254 + following major steps are performed: A set of LPC filters are 1.255 + computed, and the speech signal is filtered through them to produce 1.256 + the residual signal. The codec uses scalar quantization of the 1.257 + dominant part, in terms of energy, of the residual signal for the 1.258 + block. The dominant state is of length 57/58 (20 ms/30 ms) samples 1.259 + and forms a start state for dynamic codebooks constructed from the 1.260 + already coded parts of the residual signal. These dynamic codebooks 1.261 + are used to code the remaining parts of the residual signal. By this 1.262 + method, coding independence between blocks is achieved, resulting in 1.263 + elimination of propagation of perceptual degradations due to packet 1.264 + loss. The method facilitates high-quality packet loss concealment 1.265 + (PLC). 1.266 + 1.267 +2.1. Encoder 1.268 + 1.269 + The input to the encoder SHOULD be 16 bit uniform PCM sampled at 8 1.270 + kHz. It SHOULD be partitioned into blocks of BLOCKL=160/240 samples 1.271 + for the 20/30 ms frame size. Each block is divided into NSUB=4/6 1.272 + consecutive sub-blocks of SUBL=40 samples each. For 30 ms frame 1.273 + size, the encoder performs two LPC_FILTERORDER=10 linear-predictive 1.274 + coding (LPC) analyses. The first analysis applies a smooth window 1.275 + centered over the second sub-block and extending to the middle of the 1.276 + fifth sub-block. The second LPC analysis applies a smooth asymmetric 1.277 + window centered over the fifth sub-block and extending to the end of 1.278 + the sixth sub-block. For 20 ms frame size, one LPC_FILTERORDER=10 1.279 + linear-predictive coding (LPC) analysis is performed with a smooth 1.280 + window centered over the third sub-frame. 1.281 + 1.282 + 1.283 + 1.284 + 1.285 +Andersen, et al. Experimental [Page 5] 1.286 + 1.287 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.288 + 1.289 + 1.290 + For each of the LPC analyses, a set of line-spectral frequencies 1.291 + (LSFs) are obtained, quantized, and interpolated to obtain LSF 1.292 + coefficients for each sub-block. Subsequently, the LPC residual is 1.293 + computed by using the quantized and interpolated LPC analysis 1.294 + filters. 1.295 + 1.296 + The two consecutive sub-blocks of the residual exhibiting the maximal 1.297 + weighted energy are identified. Within these two sub-blocks, the 1.298 + start state (segment) is selected from two choices: the first 57/58 1.299 + samples or the last 57/58 samples of the two consecutive sub-blocks. 1.300 + The selected segment is the one of higher energy. The start state is 1.301 + encoded with scalar quantization. 1.302 + 1.303 + A dynamic codebook encoding procedure is used to encode 1) the 23/22 1.304 + (20 ms/30 ms) remaining samples in the two sub-blocks containing the 1.305 + start state; 2) the sub-blocks after the start state in time; and 3) 1.306 + the sub-blocks before the start state in time. Thus, the encoding 1.307 + target can be either the 23/22 samples remaining of the two sub- 1.308 + blocks containing the start state or a 40-sample sub-block. This 1.309 + target can consist of samples indexed forward in time or backward in 1.310 + time, depending on the location of the start state. 1.311 + 1.312 + The codebook coding is based on an adaptive codebook built from a 1.313 + codebook memory that contains decoded LPC excitation samples from the 1.314 + already encoded part of the block. These samples are indexed in the 1.315 + same time direction as the target vector, ending at the sample 1.316 + instant prior to the first sample instant represented in the target 1.317 + vector. The codebook is used in CB_NSTAGES=3 stages in a successive 1.318 + refinement approach, and the resulting three code vector gains are 1.319 + encoded with 5-, 4-, and 3-bit scalar quantization, respectively. 1.320 + 1.321 + The codebook search method employs noise shaping derived from the LPC 1.322 + filters, and the main decision criterion is to minimize the squared 1.323 + error between the target vector and the code vectors. Each code 1.324 + vector in this codebook comes from one of CB_EXPAND=2 codebook 1.325 + sections. The first section is filled with delayed, already encoded 1.326 + residual vectors. The code vectors of the second codebook section 1.327 + are constructed by predefined linear combinations of vectors in the 1.328 + first section of the codebook. 1.329 + 1.330 + As codebook encoding with squared-error matching is known to produce 1.331 + a coded signal of less power than does the scalar quantized start 1.332 + state signal, a gain re-scaling method is implemented by a refined 1.333 + search for a better set of codebook gains in terms of power matching 1.334 + after encoding. This is done by searching for a higher value of the 1.335 + gain factor for the first stage codebook, as the subsequent stage 1.336 + codebook gains are scaled by the first stage gain. 1.337 + 1.338 + 1.339 + 1.340 + 1.341 +Andersen, et al. Experimental [Page 6] 1.342 + 1.343 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.344 + 1.345 + 1.346 +2.2. Decoder 1.347 + 1.348 + Typically for packet communications, a jitter buffer placed at the 1.349 + receiving end decides whether the packet containing an encoded signal 1.350 + block has been received or lost. This logic is not part of the codec 1.351 + described here. For each encoded signal block received the decoder 1.352 + performs a decoding. For each lost signal block, the decoder 1.353 + performs a PLC operation. 1.354 + 1.355 + The decoding for each block starts by decoding and interpolating the 1.356 + LPC coefficients. Subsequently the start state is decoded. 1.357 + 1.358 + For codebook-encoded segments, each segment is decoded by 1.359 + constructing the three code vectors given by the received codebook 1.360 + indices in the same way that the code vectors were constructed in the 1.361 + encoder. The three gain factors are also decoded and the resulting 1.362 + decoded signal is given by the sum of the three codebook vectors 1.363 + scaled with respective gain. 1.364 + 1.365 + An enhancement algorithm is applied to the reconstructed excitation 1.366 + signal. This enhancement augments the periodicity of voiced speech 1.367 + regions. The enhancement is optimized under the constraint that the 1.368 + modification signal (defined as the difference between the enhanced 1.369 + excitation and the excitation signal prior to enhancement) has a 1.370 + short-time energy that does not exceed a preset fraction of the 1.371 + short-time energy of the excitation signal prior to enhancement. 1.372 + 1.373 + A packet loss concealment (PLC) operation is easily embedded in the 1.374 + decoder. The PLC operation can, e.g., be based on repeating LPC 1.375 + filters and obtaining the LPC residual signal by using a long-term 1.376 + prediction estimate from previous residual blocks. 1.377 + 1.378 +3. Encoder Principles 1.379 + 1.380 + The following block diagram is an overview of all the components of 1.381 + the iLBC encoding procedure. The description of the blocks contains 1.382 + references to the section where that particular procedure is further 1.383 + described. 1.384 + 1.385 + 1.386 + 1.387 + 1.388 + 1.389 + 1.390 + 1.391 + 1.392 + 1.393 + 1.394 + 1.395 + 1.396 + 1.397 +Andersen, et al. Experimental [Page 7] 1.398 + 1.399 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.400 + 1.401 + 1.402 + +-----------+ +---------+ +---------+ 1.403 + speech -> | 1. Pre P | -> | 2. LPC | -> | 3. Ana | -> 1.404 + +-----------+ +---------+ +---------+ 1.405 + 1.406 + +---------------+ +--------------+ 1.407 + -> | 4. Start Sel | ->| 5. Scalar Qu | -> 1.408 + +---------------+ +--------------+ 1.409 + 1.410 + +--------------+ +---------------+ 1.411 + -> |6. CB Search | -> | 7. Packetize | -> payload 1.412 + | +--------------+ | +---------------+ 1.413 + ----<---------<------ 1.414 + sub-frame 0..2/4 (20 ms/30 ms) 1.415 + 1.416 + Figure 3.1. Flow chart of the iLBC encoder 1.417 + 1.418 + 1. Pre-process speech with a HP filter, if needed (section 3.1). 1.419 + 1.420 + 2. Compute LPC parameters, quantize, and interpolate (section 3.2). 1.421 + 1.422 + 3. Use analysis filters on speech to compute residual (section 3.3). 1.423 + 1.424 + 4. Select position of 57/58-sample start state (section 3.5). 1.425 + 1.426 + 5. Quantize the 57/58-sample start state with scalar quantization 1.427 + (section 3.5). 1.428 + 1.429 + 6. Search the codebook for each sub-frame. Start with 23/22 sample 1.430 + block, then encode sub-blocks forward in time, and then encode 1.431 + sub-blocks backward in time. For each block, the steps in Figure 1.432 + 3.4 are performed (section 3.6). 1.433 + 1.434 + 7. Packetize the bits into the payload specified in Table 3.2. 1.435 + 1.436 + The input to the encoder SHOULD be 16-bit uniform PCM sampled at 8 1.437 + kHz. Also it SHOULD be partitioned into blocks of BLOCKL=160/240 1.438 + samples. Each block input to the encoder is divided into NSUB=4/6 1.439 + consecutive sub-blocks of SUBL=40 samples each. 1.440 + 1.441 + 1.442 + 1.443 + 1.444 + 1.445 + 1.446 + 1.447 + 1.448 + 1.449 + 1.450 + 1.451 + 1.452 + 1.453 +Andersen, et al. Experimental [Page 8] 1.454 + 1.455 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.456 + 1.457 + 1.458 + 0 39 79 119 159 1.459 + +---------------------------------------+ 1.460 + | 1 | 2 | 3 | 4 | 1.461 + +---------------------------------------+ 1.462 + 20 ms frame 1.463 + 1.464 + 0 39 79 119 159 199 239 1.465 + +-----------------------------------------------------------+ 1.466 + | 1 | 2 | 3 | 4 | 5 | 6 | 1.467 + +-----------------------------------------------------------+ 1.468 + 30 ms frame 1.469 + Figure 3.2. One input block to the encoder for 20 ms (with four sub- 1.470 + frames) and 30 ms (with six sub-frames). 1.471 + 1.472 +3.1. Pre-processing 1.473 + 1.474 + In some applications, the recorded speech signal contains DC level 1.475 + and/or 50/60 Hz noise. If these components have not been removed 1.476 + prior to the encoder call, they should be removed by a high-pass 1.477 + filter. A reference implementation of this, using a filter with a 1.478 + cutoff frequency of 90 Hz, can be found in Appendix A.28. 1.479 + 1.480 +3.2. LPC Analysis and Quantization 1.481 + 1.482 + The input to the LPC analysis module is a possibly high-pass filtered 1.483 + speech buffer, speech_hp, that contains 240/300 (LPC_LOOKBACK + 1.484 + BLOCKL = 80/60 + 160/240 = 240/300) speech samples, where samples 0 1.485 + through 79/59 are from the previous block and samples 80/60 through 1.486 + 239/299 are from the current block. No look-ahead into the next 1.487 + block is used. For the very first block processed, the look-back 1.488 + samples are assumed to be zeros. 1.489 + 1.490 + For each input block, the LPC analysis calculates one/two set(s) of 1.491 + LPC_FILTERORDER=10 LPC filter coefficients using the autocorrelation 1.492 + method and the Levinson-Durbin recursion. These coefficients are 1.493 + converted to the Line Spectrum Frequency representation. In the 20 1.494 + ms case, the single lsf set represents the spectral characteristics 1.495 + as measured at the center of the third sub-block. For 30 ms frames, 1.496 + the first set, lsf1, represents the spectral properties of the input 1.497 + signal at the center of the second sub-block, and the other set, 1.498 + lsf2, represents the spectral characteristics as measured at the 1.499 + center of the fifth sub-block. The details of the computation for 30 1.500 + ms frames are described in sections 3.2.1 through 3.2.6. Section 1.501 + 3.2.7 explains how the LPC Analysis and Quantization differs for 20 1.502 + ms frames. 1.503 + 1.504 + 1.505 + 1.506 + 1.507 + 1.508 + 1.509 +Andersen, et al. Experimental [Page 9] 1.510 + 1.511 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.512 + 1.513 + 1.514 +3.2.1. Computation of Autocorrelation Coefficients 1.515 + 1.516 + The first step in the LPC analysis procedure is to calculate 1.517 + autocorrelation coefficients by using windowed speech samples. This 1.518 + windowing is the only difference in the LPC analysis procedure for 1.519 + the two sets of coefficients. For the first set, a 240-sample-long 1.520 + standard symmetric Hanning window is applied to samples 0 through 239 1.521 + of the input data. The first window, lpc_winTbl, is defined as 1.522 + 1.523 + lpc_winTbl[i]= 0.5 * (1.0 - cos((2*PI*(i+1))/(BLOCKL+1))); 1.524 + i=0,...,119 1.525 + lpc_winTbl[i] = winTbl[BLOCKL - i - 1]; i=120,...,239 1.526 + 1.527 + The windowed speech speech_hp_win1 is then obtained by multiplying 1.528 + the first 240 samples of the input speech buffer with the window 1.529 + coefficients: 1.530 + 1.531 + speech_hp_win1[i] = speech_hp[i] * lpc_winTbl[i]; 1.532 + i=0,...,BLOCKL-1 1.533 + 1.534 + From these 240 windowed speech samples, 11 (LPC_FILTERORDER + 1) 1.535 + autocorrelation coefficients, acf1, are calculated: 1.536 + 1.537 + acf1[lag] += speech_hp_win1[n] * speech_hp_win1[n + lag]; 1.538 + lag=0,...,LPC_FILTERORDER; n=0,...,BLOCKL-lag-1 1.539 + 1.540 + In order to make the analysis more robust against numerical precision 1.541 + problems, a spectral smoothing procedure is applied by windowing the 1.542 + autocorrelation coefficients before the LPC coefficients are 1.543 + computed. Also, a white noise floor is added to the autocorrelation 1.544 + function by multiplying coefficient zero by 1.0001 (40dB below the 1.545 + energy of the windowed speech signal). These two steps are 1.546 + implemented by multiplying the autocorrelation coefficients with the 1.547 + following window: 1.548 + 1.549 + lpc_lagwinTbl[0] = 1.0001; 1.550 + lpc_lagwinTbl[i] = exp(-0.5 * ((2 * PI * 60.0 * i) /FS)^2); 1.551 + i=1,...,LPC_FILTERORDER 1.552 + where FS=8000 is the sampling frequency 1.553 + 1.554 + Then, the windowed acf function acf1_win is obtained by 1.555 + 1.556 + acf1_win[i] = acf1[i] * lpc_lagwinTbl[i]; 1.557 + i=0,...,LPC_FILTERORDER 1.558 + 1.559 + The second set of autocorrelation coefficients, acf2_win, are 1.560 + obtained in a similar manner. The window, lpc_asymwinTbl, is applied 1.561 + to samples 60 through 299, i.e., the entire current block. The 1.562 + 1.563 + 1.564 + 1.565 +Andersen, et al. Experimental [Page 10] 1.566 + 1.567 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.568 + 1.569 + 1.570 + window consists of two segments, the first (samples 0 to 219) being 1.571 + half a Hanning window with length 440 and the second a quarter of a 1.572 + cycle of a cosine wave. By using this asymmetric window, an LPC 1.573 + analysis centered in the fifth sub-block is obtained without the need 1.574 + for any look-ahead, which would add delay. The asymmetric window is 1.575 + defined as 1.576 + 1.577 + lpc_asymwinTbl[i] = (sin(PI * (i + 1) / 441))^2; i=0,...,219 1.578 + 1.579 + lpc_asymwinTbl[i] = cos((i - 220) * PI / 40); i=220,...,239 1.580 + 1.581 + and the windowed speech is computed by 1.582 + 1.583 + speech_hp_win2[i] = speech_hp[i + LPC_LOOKBACK] * 1.584 + lpc_asymwinTbl[i]; i=0,....BLOCKL-1 1.585 + 1.586 + The windowed autocorrelation coefficients are then obtained in 1.587 + exactly the same way as for the first analysis instance. 1.588 + 1.589 + The generation of the windows lpc_winTbl, lpc_asymwinTbl, and 1.590 + lpc_lagwinTbl are typically done in advance, and the arrays are 1.591 + stored in ROM rather than repeating the calculation for every block. 1.592 + 1.593 +3.2.2. Computation of LPC Coefficients 1.594 + 1.595 + From the 2 x 11 smoothed autocorrelation coefficients, acf1_win and 1.596 + acf2_win, the 2 x 11 LPC coefficients, lp1 and lp2, are calculated 1.597 + in the same way for both analysis locations by using the well known 1.598 + Levinson-Durbin recursion. The first LPC coefficient is always 1.0, 1.599 + resulting in ten unique coefficients. 1.600 + 1.601 + After determining the LPC coefficients, a bandwidth expansion 1.602 + procedure is applied to smooth the spectral peaks in the 1.603 + short-term spectrum. The bandwidth addition is obtained by the 1.604 + following modification of the LPC coefficients: 1.605 + 1.606 + lp1_bw[i] = lp1[i] * chirp^i; i=0,...,LPC_FILTERORDER 1.607 + lp2_bw[i] = lp2[i] * chirp^i; i=0,...,LPC_FILTERORDER 1.608 + 1.609 + where "chirp" is a real number between 0 and 1. It is RECOMMENDED to 1.610 + use a value of 0.9. 1.611 + 1.612 +3.2.3. Computation of LSF Coefficients from LPC Coefficients 1.613 + 1.614 + Thus far, two sets of LPC coefficients that represent the short-term 1.615 + spectral characteristics of the speech signal for two different time 1.616 + locations within the current block have been determined. These 1.617 + coefficients SHOULD be quantized and interpolated. Before this is 1.618 + 1.619 + 1.620 + 1.621 +Andersen, et al. Experimental [Page 11] 1.622 + 1.623 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.624 + 1.625 + 1.626 + done, it is advantageous to convert the LPC parameters into another 1.627 + type of representation called Line Spectral Frequencies (LSF). The 1.628 + LSF parameters are used because they are better suited for 1.629 + quantization and interpolation than the regular LPC coefficients. 1.630 + Many computationally efficient methods for calculating the LSFs from 1.631 + the LPC coefficients have been proposed in the literature. The 1.632 + detailed implementation of one applicable method can be found in 1.633 + Appendix A.26. The two arrays of LSF coefficients obtained, lsf1 and 1.634 + lsf2, are of dimension 10 (LPC_FILTERORDER). 1.635 + 1.636 +3.2.4. Quantization of LSF Coefficients 1.637 + 1.638 + Because the LPC filters defined by the two sets of LSFs are also 1.639 + needed in the decoder, the LSF parameters need to be quantized and 1.640 + transmitted as side information. The total number of bits required 1.641 + to represent the quantization of the two LSF representations for one 1.642 + block of speech is 40, with 20 bits used for each of lsf1 and lsf2. 1.643 + 1.644 + For computational and storage reasons, the LSF vectors are quantized 1.645 + using three-split vector quantization (VQ). That is, the LSF vectors 1.646 + are split into three sub-vectors that are each quantized with a 1.647 + regular VQ. The quantized versions of lsf1 and lsf2, qlsf1 and 1.648 + qlsf2, are obtained by using the same memoryless split VQ. The 1.649 + length of each of these two LSF vectors is 10, and they are split 1.650 + into three sub-vectors containing 3, 3, and 4 values, respectively. 1.651 + 1.652 + For each of the sub-vectors, a separate codebook of quantized values 1.653 + has been designed with a standard VQ training method for a large 1.654 + database containing speech from a large number of speakers recorded 1.655 + under various conditions. The size of each of the three codebooks 1.656 + associated with the split definitions above is 1.657 + 1.658 + int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128}; 1.659 + 1.660 + The actual values of the vector quantization codebook that must be 1.661 + used can be found in the reference code of Appendix A. Both sets of 1.662 + LSF coefficients, lsf1 and lsf2, are quantized with a standard 1.663 + memoryless split vector quantization (VQ) structure using the squared 1.664 + error criterion in the LSF domain. The split VQ quantization 1.665 + consists of the following steps: 1.666 + 1.667 + 1) Quantize the first three LSF coefficients (1 - 3) with a VQ 1.668 + codebook of size 64. 1.669 + 2) Quantize the next three LSF coefficients 4 - 6 with VQ a codebook 1.670 + of size 128. 1.671 + 3) Quantize the last four LSF coefficients (7 - 10) with a VQ 1.672 + codebook of size 128. 1.673 + 1.674 + 1.675 + 1.676 + 1.677 +Andersen, et al. Experimental [Page 12] 1.678 + 1.679 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.680 + 1.681 + 1.682 + This procedure, repeated for lsf1 and lsf2, gives six quantization 1.683 + indices and the quantized sets of LSF coefficients qlsf1 and qlsf2. 1.684 + Each set of three indices is encoded with 6 + 7 + 7 = 20 bits. The 1.685 + total number of bits used for LSF quantization in a block is thus 40 1.686 + bits. 1.687 + 1.688 +3.2.5. Stability Check of LSF Coefficients 1.689 + 1.690 + The LSF representation of the LPC filter has the convenient property 1.691 + that the coefficients are ordered by increasing value, i.e., lsf(n-1) 1.692 + < lsf(n), 0 < n < 10, if the corresponding synthesis filter is 1.693 + stable. As we are employing a split VQ scheme, it is possible that 1.694 + at the split boundaries the LSF coefficients are not ordered 1.695 + correctly and hence that the corresponding LP filter is unstable. To 1.696 + ensure that the filter used is stable, a stability check is performed 1.697 + for the quantized LSF vectors. If it turns out that the coefficients 1.698 + are not ordered appropriately (with a safety margin of 50 Hz to 1.699 + ensure that formant peaks are not too narrow), they will be moved 1.700 + apart. The detailed method for this can be found in Appendix A.40. 1.701 + The same procedure is performed in the decoder. This ensures that 1.702 + exactly the same LSF representations are used in both encoder and 1.703 + decoder. 1.704 + 1.705 +3.2.6. Interpolation of LSF Coefficients 1.706 + 1.707 + From the two sets of LSF coefficients that are computed for each 1.708 + block of speech, different LSFs are obtained for each sub-block by 1.709 + means of interpolation. This procedure is performed for the original 1.710 + LSFs (lsf1 and lsf2), as well as the quantized versions qlsf1 and 1.711 + qlsf2, as both versions are used in the encoder. Here follows a 1.712 + brief summary of the interpolation scheme; the details are found in 1.713 + the c-code of Appendix A. In the first sub-block, the average of the 1.714 + second LSF vector from the previous block and the first LSF vector in 1.715 + the current block is used. For sub-blocks two through five, the LSFs 1.716 + used are obtained by linear interpolation from lsf1 (and qlsf1) to 1.717 + lsf2 (and qlsf2), with lsf1 used in sub-block two and lsf2 in sub- 1.718 + block five. In the last sub-block, lsf2 is used. For the very first 1.719 + block it is assumed that the last LSF vector of the previous block is 1.720 + equal to a predefined vector, lsfmeanTbl, obtained by calculating the 1.721 + mean LSF vector of the LSF design database. 1.722 + 1.723 + lsfmeanTbl[LPC_FILTERORDER] = {0.281738, 0.445801, 0.663330, 1.724 + 0.962524, 1.251831, 1.533081, 1.850586, 2.137817, 1.725 + 2.481445, 2.777344} 1.726 + 1.727 + 1.728 + 1.729 + 1.730 + 1.731 + 1.732 + 1.733 +Andersen, et al. Experimental [Page 13] 1.734 + 1.735 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.736 + 1.737 + 1.738 + The interpolation method is standard linear interpolation in the LSF 1.739 + domain. The interpolated LSF values are converted to LPC 1.740 + coefficients for each sub-block. The unquantized and quantized LPC 1.741 + coefficients form two sets of filters respectively. The unquantized 1.742 + analysis filter for sub-block k is defined as follows 1.743 + 1.744 + ___ 1.745 + \ 1.746 + Ak(z)= 1 + > ak(i)*z^(-i) 1.747 + /__ 1.748 + i=1...LPC_FILTERORDER 1.749 + 1.750 + The quantized analysis filter for sub-block k is defined as follows 1.751 + ___ 1.752 + \ 1.753 + A~k(z)= 1 + > a~k(i)*z^(-i) 1.754 + /__ 1.755 + i=1...LPC_FILTERORDER 1.756 + 1.757 + A reference implementation of the lsf encoding is given in Appendix 1.758 + A.38. A reference implementation of the corresponding decoding can 1.759 + be found in Appendix A.36. 1.760 + 1.761 +3.2.7. LPC Analysis and Quantization for 20 ms Frames 1.762 + 1.763 + As previously stated, the codec only calculates one set of LPC 1.764 + parameters for the 20 ms frame size as opposed to two sets for 30 ms 1.765 + frames. A single set of autocorrelation coefficients is calculated 1.766 + on the LPC_LOOKBACK + BLOCKL = 80 + 160 = 240 samples. These samples 1.767 + are windowed with the asymmetric window lpc_asymwinTbl, centered over 1.768 + the third sub-frame, to form speech_hp_win. Autocorrelation 1.769 + coefficients, acf, are calculated on the 240 samples in speech_hp_win 1.770 + and then windowed exactly as in section 3.2.1 (resulting in 1.771 + acf_win). 1.772 + 1.773 + This single set of windowed autocorrelation coefficients is used to 1.774 + calculate LPC coefficients, LSF coefficients, and quantized LSF 1.775 + coefficients in exactly the same manner as in sections 3.2.3 through 1.776 + 3.2.4. As for the 30 ms frame size, the ten LSF coefficients are 1.777 + divided into three sub-vectors of size 3, 3, and 4 and quantized by 1.778 + using the same scheme and codebook as in section 3.2.4 to finally get 1.779 + 3 quantization indices. The quantized LSF coefficients are 1.780 + stabilized with the algorithm described in section 3.2.5. 1.781 + 1.782 + From the set of LSF coefficients computed for this block and those 1.783 + from the previous block, different LSFs are obtained for each sub- 1.784 + block by means of interpolation. The interpolation is done linearly 1.785 + in the LSF domain over the four sub-blocks, so that the n-th sub- 1.786 + 1.787 + 1.788 + 1.789 +Andersen, et al. Experimental [Page 14] 1.790 + 1.791 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.792 + 1.793 + 1.794 + frame uses the weight (4-n)/4 for the LSF from old frame and the 1.795 + weight n/4 of the LSF from the current frame. For the very first 1.796 + block the mean LSF, lsfmeanTbl, is used as the LSF from the previous 1.797 + block. Similarly as seen in section 3.2.6, both unquantized, A(z), 1.798 + and quantized, A~(z), analysis filters are calculated for each of the 1.799 + four sub-blocks. 1.800 + 1.801 +3.3. Calculation of the Residual 1.802 + 1.803 + The block of speech samples is filtered by the quantized and 1.804 + interpolated LPC analysis filters to yield the residual signal. In 1.805 + particular, the corresponding LPC analysis filter for each 40 sample 1.806 + sub-block is used to filter the speech samples for the same sub- 1.807 + block. The filter memory at the end of each sub-block is carried 1.808 + over to the LPC filter of the next sub-block. The signal at the 1.809 + output of each LP analysis filter constitutes the residual signal for 1.810 + the corresponding sub-block. 1.811 + 1.812 + A reference implementation of the LPC analysis filters is given in 1.813 + Appendix A.10. 1.814 + 1.815 +3.4. Perceptual Weighting Filter 1.816 + 1.817 + In principle any good design of a perceptual weighting filter can be 1.818 + applied in the encoder without compromising this codec definition. 1.819 + However, it is RECOMMENDED to use the perceptual weighting filter Wk 1.820 + for sub-block k specified below: 1.821 + 1.822 + Wk(z)=1/Ak(z/LPC_CHIRP_WEIGHTDENUM), where 1.823 + LPC_CHIRP_WEIGHTDENUM = 0.4222 1.824 + 1.825 + This is a simple design with low complexity that is applied in the 1.826 + LPC residual domain. Here Ak(z) is the filter obtained for sub-block 1.827 + k from unquantized but interpolated LSF coefficients. 1.828 + 1.829 +3.5. Start State Encoder 1.830 + 1.831 + The start state is quantized by using a common 6-bit scalar quantizer 1.832 + for the block and a 3-bit scalar quantizer operating on scaled 1.833 + samples in the weighted speech domain. In the following we describe 1.834 + the state encoding in greater detail. 1.835 + 1.836 + 1.837 + 1.838 + 1.839 + 1.840 + 1.841 + 1.842 + 1.843 + 1.844 + 1.845 +Andersen, et al. Experimental [Page 15] 1.846 + 1.847 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.848 + 1.849 + 1.850 +3.5.1. Start State Estimation 1.851 + 1.852 + The two sub-blocks containing the start state are determined by 1.853 + finding the two consecutive sub-blocks in the block having the 1.854 + highest power. Advantageously, down-weighting is used in the 1.855 + beginning and end of the sub-frames, i.e., the following measure is 1.856 + computed (NSUB=4/6 for 20/30 ms frame size): 1.857 + 1.858 + nsub=1,...,NSUB-1 1.859 + ssqn[nsub] = 0.0; 1.860 + for (i=(nsub-1)*SUBL; i<(nsub-1)*SUBL+5; i++) 1.861 + ssqn[nsub] += sampEn_win[i-(nsub-1)*SUBL]* 1.862 + residual[i]*residual[i]; 1.863 + for (i=(nsub-1)*SUBL+5; i<(nsub+1)*SUBL-5; i++) 1.864 + ssqn[nsub] += residual[i]*residual[i]; 1.865 + for (i=(nsub+1)*SUBL-5; i<(nsub+1)*SUBL; i++) 1.866 + ssqn[nsub] += sampEn_win[(nsub+1)*SUBL-i-1]* 1.867 + residual[i]*residual[i]; 1.868 + 1.869 + where sampEn_win[5]={1/6, 2/6, 3/6, 4/6, 5/6}; MAY be used. The 1.870 + sub-frame number corresponding to the maximum value of 1.871 + ssqEn_win[nsub-1]*ssqn[nsub] is selected as the start state 1.872 + indicator. A weighting of ssqEn_win[]={0.8,0.9,1.0,0.9,0.8} for 30 1.873 + ms frames and ssqEn_win[]={0.9,1.0,0.9} for 20 ms frames; MAY 1.874 + advantageously be used to bias the start state towards the middle of 1.875 + the frame. 1.876 + 1.877 + For 20 ms frames there are three possible positions for the two-sub- 1.878 + block length maximum power segment; the start state position is 1.879 + encoded with 2 bits. The start state position, start, MUST be 1.880 + encoded as 1.881 + 1.882 + start=1: start state in sub-frame 0 and 1 1.883 + start=2: start state in sub-frame 1 and 2 1.884 + start=3: start state in sub-frame 2 and 3 1.885 + 1.886 + For 30 ms frames there are five possible positions of the two-sub- 1.887 + block length maximum power segment, the start state position is 1.888 + encoded with 3 bits. The start state position, start, MUST be 1.889 + encoded as 1.890 + 1.891 + start=1: start state in sub-frame 0 and 1 1.892 + start=2: start state in sub-frame 1 and 2 1.893 + start=3: start state in sub-frame 2 and 3 1.894 + start=4: start state in sub-frame 3 and 4 1.895 + start=5: start state in sub-frame 4 and 5 1.896 + 1.897 + 1.898 + 1.899 + 1.900 + 1.901 +Andersen, et al. Experimental [Page 16] 1.902 + 1.903 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.904 + 1.905 + 1.906 + Hence, in both cases, index 0 is not used. In order to shorten the 1.907 + start state for bit rate efficiency, the start state is brought down 1.908 + to STATE_SHORT_LEN=57 samples for 20 ms frames and STATE_SHORT_LEN=58 1.909 + samples for 30 ms frames. The power of the first 23/22 and last 1.910 + 23/22 samples of the two sub-frame blocks identified above is 1.911 + computed as the sum of the squared signal sample values, and the 1.912 + 23/22-sample segment with the lowest power is excluded from the start 1.913 + state. One bit is transmitted to indicate which of the two possible 1.914 + 57/58 sample segments is used. The start state position within the 1.915 + two sub-frames determined above, state_first, MUST be encoded as 1.916 + 1.917 + state_first=1: start state is first STATE_SHORT_LEN samples 1.918 + state_first=0: start state is last STATE_SHORT_LEN samples 1.919 + 1.920 +3.5.2. All-Pass Filtering and Scale Quantization 1.921 + 1.922 + The block of residual samples in the start state is first filtered by 1.923 + an all-pass filter with the quantized LPC coefficients as denominator 1.924 + and reversed quantized LPC coefficients as numerator. The purpose of 1.925 + this phase-dispersion filter is to get a more even distribution of 1.926 + the sample values in the residual signal. The filtering is performed 1.927 + by circular convolution, where the initial filter memory is set to 1.928 + zero. 1.929 + 1.930 + res(0..(STATE_SHORT_LEN-1)) = uncoded start state residual 1.931 + res((STATE_SHORT_LEN)..(2*STATE_SHORT_LEN-1)) = 0 1.932 + 1.933 + Pk(z) = A~rk(z)/A~k(z), where 1.934 + ___ 1.935 + \ 1.936 + A~rk(z)= z^(-LPC_FILTERORDER)+>a~k(i+1)*z^(i-(LPC_FILTERORDER-1)) 1.937 + /__ 1.938 + i=0...(LPC_FILTERORDER-1) 1.939 + 1.940 + and A~k(z) is taken from the block where the start state begins 1.941 + 1.942 + res -> Pk(z) -> filtered 1.943 + 1.944 + ccres(k) = filtered(k) + filtered(k+STATE_SHORT_LEN), 1.945 + k=0..(STATE_SHORT_LEN-1) 1.946 + 1.947 + The all-pass filtered block is searched for its largest magnitude 1.948 + sample. The 10-logarithm of this magnitude is quantized with a 6-bit 1.949 + quantizer, state_frgqTbl, by finding the nearest representation. 1.950 + 1.951 + 1.952 + 1.953 + 1.954 + 1.955 + 1.956 + 1.957 +Andersen, et al. Experimental [Page 17] 1.958 + 1.959 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.960 + 1.961 + 1.962 + This results in an index, idxForMax, corresponding to a quantized 1.963 + value, qmax. The all-pass filtered residual samples in the block are 1.964 + then multiplied with a scaling factor scal=4.5/(10^qmax) to yield 1.965 + normalized samples. 1.966 + 1.967 + state_frgqTbl[64] = {1.000085, 1.071695, 1.140395, 1.206868, 1.968 + 1.277188, 1.351503, 1.429380, 1.500727, 1.569049, 1.969 + 1.639599, 1.707071, 1.781531, 1.840799, 1.901550, 1.970 + 1.956695, 2.006750, 2.055474, 2.102787, 2.142819, 1.971 + 2.183592, 2.217962, 2.257177, 2.295739, 2.332967, 1.972 + 2.369248, 2.402792, 2.435080, 2.468598, 2.503394, 1.973 + 2.539284, 2.572944, 2.605036, 2.636331, 2.668939, 1.974 + 2.698780, 2.729101, 2.759786, 2.789834, 2.818679, 1.975 + 2.848074, 2.877470, 2.906899, 2.936655, 2.967804, 1.976 + 3.000115, 3.033367, 3.066355, 3.104231, 3.141499, 1.977 + 3.183012, 3.222952, 3.265433, 3.308441, 3.350823, 1.978 + 3.395275, 3.442793, 3.490801, 3.542514, 3.604064, 1.979 + 3.666050, 3.740994, 3.830749, 3.938770, 4.101764} 1.980 + 1.981 +3.5.3. Scalar Quantization 1.982 + 1.983 + The normalized samples are quantized in the perceptually weighted 1.984 + speech domain by a sample-by-sample scalar DPCM quantization as 1.985 + depicted in Figure 3.3. Each sample in the block is filtered by a 1.986 + weighting filter Wk(z), specified in section 3.4, to form a weighted 1.987 + speech sample x[n]. The target sample d[n] is formed by subtracting 1.988 + a predicted sample y[n], where the prediction filter is given by 1.989 + 1.990 + Pk(z) = 1 - 1 / Wk(z). 1.991 + 1.992 + +-------+ x[n] + d[n] +-----------+ u[n] 1.993 + residual -->| Wk(z) |-------->(+)---->| Quantizer |------> quantized 1.994 + +-------+ - /|\ +-----------+ | residual 1.995 + | \|/ 1.996 + y[n] +--------------------->(+) 1.997 + | | 1.998 + | +------+ | 1.999 + +--------| Pk(z)|<------+ 1.1000 + +------+ 1.1001 + 1.1002 + Figure 3.3. Quantization of start state samples by DPCM in weighted 1.1003 + speech domain. 1.1004 + 1.1005 + The coded state sample u[n] is obtained by quantizing d[n] with a 3- 1.1006 + bit quantizer with quantization table state_sq3Tbl. 1.1007 + 1.1008 + state_sq3Tbl[8] = {-3.719849, -2.177490, -1.130005, -0.309692, 1.1009 + 0.444214, 1.329712, 2.436279, 3.983887} 1.1010 + 1.1011 + 1.1012 + 1.1013 +Andersen, et al. Experimental [Page 18] 1.1014 + 1.1015 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1016 + 1.1017 + 1.1018 + The quantized samples are transformed back to the residual domain by 1.1019 + 1) scaling with 1/scal; 2) time-reversing the scaled samples; 3) 1.1020 + filtering the time-reversed samples by the same all-pass filter, as 1.1021 + in section 3.5.2, by using circular convolution; and 4) time- 1.1022 + reversing the filtered samples. (More detail is in section 4.2.) 1.1023 + 1.1024 + A reference implementation of the start-state encoding can be found 1.1025 + in Appendix A.46. 1.1026 + 1.1027 +3.6. Encoding the Remaining Samples 1.1028 + 1.1029 + A dynamic codebook is used to encode 1) the 23/22 remaining samples 1.1030 + in the two sub-blocks containing the start state; 2) the sub-blocks 1.1031 + after the start state in time; and 3) the sub-blocks before the start 1.1032 + state in time. Thus, the encoding target can be either the 23/22 1.1033 + samples remaining of the 2 sub-blocks containing the start state, or 1.1034 + a 40-sample sub-block. This target can consist of samples that are 1.1035 + indexed forward in time or backward in time, depending on the 1.1036 + location of the start state. The length of the target is denoted by 1.1037 + lTarget. 1.1038 + 1.1039 + The coding is based on an adaptive codebook that is built from a 1.1040 + codebook memory that contains decoded LPC excitation samples from the 1.1041 + already encoded part of the block. These samples are indexed in the 1.1042 + same time direction as is the target vector and end at the sample 1.1043 + instant prior to the first sample instant represented in the target 1.1044 + vector. The codebook memory has length lMem, which is equal to 1.1045 + CB_MEML=147 for the two/four 40-sample sub-blocks and 85 for the 1.1046 + 23/22-sample sub-block. 1.1047 + 1.1048 + The following figure shows an overview of the encoding procedure. 1.1049 + 1.1050 + +------------+ +---------------+ +-------------+ 1.1051 + -> | 1. Decode | -> | 2. Mem setup | -> | 3. Perc. W. | -> 1.1052 + +------------+ +---------------+ +-------------+ 1.1053 + 1.1054 + +------------+ +-----------------+ 1.1055 + -> | 4. Search | -> | 5. Upd. Target | ------------------> 1.1056 + | +------------+ +------------------ | 1.1057 + ----<-------------<-----------<---------- 1.1058 + stage=0..2 1.1059 + 1.1060 + +----------------+ 1.1061 + -> | 6. Recalc G[0] | ---------------> gains and CB indices 1.1062 + +----------------+ 1.1063 + 1.1064 + Figure 3.4. Flow chart of the codebook search in the iLBC encoder. 1.1065 + 1.1066 + 1.1067 + 1.1068 + 1.1069 +Andersen, et al. Experimental [Page 19] 1.1070 + 1.1071 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1072 + 1.1073 + 1.1074 + 1. Decode the part of the residual that has been encoded so far, 1.1075 + using the codebook without perceptual weighting. 1.1076 + 1.1077 + 2. Set up the memory by taking data from the decoded residual. This 1.1078 + memory is used to construct codebooks. For blocks preceding the 1.1079 + start state, both the decoded residual and the target are time 1.1080 + reversed (section 3.6.1). 1.1081 + 3. Filter the memory + target with the perceptual weighting filter 1.1082 + (section 3.6.2). 1.1083 + 1.1084 + 4. Search for the best match between the target and the codebook 1.1085 + vector. Compute the optimal gain for this match and quantize that 1.1086 + gain (section 3.6.4). 1.1087 + 1.1088 + 5. Update the perceptually weighted target by subtracting the 1.1089 + contribution from the selected codebook vector from the 1.1090 + perceptually weighted memory (quantized gain times selected 1.1091 + vector). Repeat 4 and 5 for the two additional stages. 1.1092 + 1.1093 + 6. Calculate the energy loss due to encoding of the residual. If 1.1094 + needed, compensate for this loss by an upscaling and 1.1095 + requantization of the gain for the first stage (section 3.7). 1.1096 + 1.1097 + The following sections provide an in-depth description of the 1.1098 + different blocks of Figure 3.4. 1.1099 + 1.1100 +3.6.1. Codebook Memory 1.1101 + 1.1102 + The codebook memory is based on the already encoded sub-blocks, so 1.1103 + the available data for encoding increases for each new sub-block that 1.1104 + has been encoded. Until enough sub-blocks have been encoded to fill 1.1105 + the codebook memory with data, it is padded with zeros. The 1.1106 + following figure shows an example of the order in which the sub- 1.1107 + blocks are encoded for the 30 ms frame size if the start state is 1.1108 + located in the last 58 samples of sub-block 2 and 3. 1.1109 + 1.1110 + +-----------------------------------------------------+ 1.1111 + | 5 | 1 |///|////////| 2 | 3 | 4 | 1.1112 + +-----------------------------------------------------+ 1.1113 + 1.1114 + Figure 3.5. The order from 1 to 5 in which the sub-blocks are 1.1115 + encoded. The slashed area is the start state. 1.1116 + 1.1117 + 1.1118 + 1.1119 + 1.1120 + 1.1121 + 1.1122 + 1.1123 + 1.1124 + 1.1125 +Andersen, et al. Experimental [Page 20] 1.1126 + 1.1127 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1128 + 1.1129 + 1.1130 + The first target sub-block to be encoded is number 1, and the 1.1131 + corresponding codebook memory is shown in the following figure. As 1.1132 + the target vector comes before the start state in time, the codebook 1.1133 + memory and target vector are time reversed; thus, after the block has 1.1134 + been time reversed the search algorithm can be reused. As only the 1.1135 + start state has been encoded so far, the last samples of the codebook 1.1136 + memory are padded with zeros. 1.1137 + 1.1138 + +------------------------- 1.1139 + |zeros|\\\\\\\\|\\\\| 1 | 1.1140 + +------------------------- 1.1141 + 1.1142 + Figure 3.6. The codebook memory, length lMem=85 samples, and the 1.1143 + target vector 1, length 22 samples. 1.1144 + 1.1145 + The next step is to encode sub-block 2 by using the memory that now 1.1146 + has increased since sub-block 1 has been encoded. The following 1.1147 + figure shows the codebook memory for encoding of sub-block 2. 1.1148 + 1.1149 + +----------------------------------- 1.1150 + | zeros | 1 |///|////////| 2 | 1.1151 + +----------------------------------- 1.1152 + 1.1153 + Figure 3.7. The codebook memory, length lMem=147 samples, and the 1.1154 + target vector 2, length 40 samples. 1.1155 + 1.1156 + The next step is to encode sub-block 3 by using the memory which has 1.1157 + been increased yet again since sub-blocks 1 and 2 have been encoded, 1.1158 + but the sub-block still has to be padded with a few zeros. The 1.1159 + following figure shows the codebook memory for encoding of sub-block 1.1160 + 3. 1.1161 + 1.1162 + +------------------------------------------ 1.1163 + |zeros| 1 |///|////////| 2 | 3 | 1.1164 + +------------------------------------------ 1.1165 + 1.1166 + Figure 3.8. The codebook memory, length lMem=147 samples, and the 1.1167 + target vector 3, length 40 samples. 1.1168 + 1.1169 + The next step is to encode sub-block 4 by using the memory which now 1.1170 + has increased yet again since sub-blocks 1, 2, and 3 have been 1.1171 + encoded. This time, the memory does not have to be padded with 1.1172 + zeros. The following figure shows the codebook memory for encoding 1.1173 + of sub-block 4. 1.1174 + 1.1175 + 1.1176 + 1.1177 + 1.1178 + 1.1179 + 1.1180 + 1.1181 +Andersen, et al. Experimental [Page 21] 1.1182 + 1.1183 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1184 + 1.1185 + 1.1186 + +------------------------------------------ 1.1187 + |1|///|////////| 2 | 3 | 4 | 1.1188 + +------------------------------------------ 1.1189 + 1.1190 + Figure 3.9. The codebook memory, length lMem=147 samples, and the 1.1191 + target vector 4, length 40 samples. 1.1192 + 1.1193 + The final target sub-block to be encoded is number 5, and the 1.1194 + following figure shows the corresponding codebook memory. As the 1.1195 + target vector comes before the start state in time, the codebook 1.1196 + memory and target vector are time reversed. 1.1197 + 1.1198 + +------------------------------------------- 1.1199 + | 3 | 2 |\\\\\\\\|\\\\| 1 | 5 | 1.1200 + +------------------------------------------- 1.1201 + 1.1202 + Figure 3.10. The codebook memory, length lMem=147 samples, and the 1.1203 + target vector 5, length 40 samples. 1.1204 + 1.1205 + For the case of 20 ms frames, the encoding procedure looks almost 1.1206 + exactly the same. The only difference is that the size of the start 1.1207 + state is 57 samples and that there are only three sub-blocks to be 1.1208 + encoded. The encoding order is the same as above, starting with the 1.1209 + 23-sample target and then encoding the two remaining 40-sample sub- 1.1210 + blocks, first going forward in time and then going backward in time 1.1211 + relative to the start state. 1.1212 + 1.1213 +3.6.2. Perceptual Weighting of Codebook Memory and Target 1.1214 + 1.1215 + To provide a perceptual weighting of the coding error, a 1.1216 + concatenation of the codebook memory and the target to be coded is 1.1217 + all-pole filtered with the perceptual weighting filter specified in 1.1218 + section 3.4. The filter state of the weighting filter is set to 1.1219 + zero. 1.1220 + 1.1221 + in(0..(lMem-1)) = unweighted codebook memory 1.1222 + in(lMem..(lMem+lTarget-1)) = unweighted target signal 1.1223 + 1.1224 + 1.1225 + in -> Wk(z) -> filtered, 1.1226 + where Wk(z) is taken from the sub-block of the target 1.1227 + 1.1228 + weighted codebook memory = filtered(0..(lMem-1)) 1.1229 + weighted target signal = filtered(lMem..(lMem+lTarget-1)) 1.1230 + 1.1231 + The codebook search is done with the weighted codebook memory and the 1.1232 + weighted target, whereas the decoding and the codebook memory update 1.1233 + uses the unweighted codebook memory. 1.1234 + 1.1235 + 1.1236 + 1.1237 +Andersen, et al. Experimental [Page 22] 1.1238 + 1.1239 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1240 + 1.1241 + 1.1242 +3.6.3. Codebook Creation 1.1243 + 1.1244 + The codebook for the search is created from the perceptually weighted 1.1245 + codebook memory. It consists of two sections, where the first is 1.1246 + referred to as the base codebook and the second as the expanded 1.1247 + codebook, as it is created by linear combinations of the first. Each 1.1248 + of these two sections also has a subsection referred to as the 1.1249 + augmented codebook. The augmented codebook is only created and used 1.1250 + for the coding of the 40-sample sub-blocks and not for the 23/22- 1.1251 + sample sub-block case. The codebook size used for the different 1.1252 + sub-blocks and different stages are summarized in the table below. 1.1253 + 1.1254 + Stage 1.1255 + 1 2 & 3 1.1256 + -------------------------------------------- 1.1257 + 22 128 (64+0)*2 128 (64+0)*2 1.1258 + Sub- 1:st 40 256 (108+20)*2 128 (44+20)*2 1.1259 + Blocks 2:nd 40 256 (108+20)*2 256 (108+20)*2 1.1260 + 3:rd 40 256 (108+20)*2 256 (108+20)*2 1.1261 + 4:th 40 256 (108+20)*2 256 (108+20)*2 1.1262 + 1.1263 + Table 3.1. Codebook sizes for the 30 ms mode. 1.1264 + 1.1265 + Table 3.1 shows the codebook size for the different sub-blocks and 1.1266 + stages for 30 ms frames. Inside the parentheses it shows how the 1.1267 + number of codebook vectors is distributed, within the two sections, 1.1268 + between the base/expanded codebook and the augmented base/expanded 1.1269 + codebook. It should be interpreted in the following way: 1.1270 + (base/expanded cb + augmented base/expanded cb). The total number of 1.1271 + codebook vectors for a specific sub-block and stage is given by the 1.1272 + following formula: 1.1273 + 1.1274 + Tot. cb vectors = base cb + aug. base cb + exp. cb + aug. exp. cb 1.1275 + 1.1276 + The corresponding values to Figure 3.1 for 20 ms frames are only 1.1277 + slightly modified. The short sub-block is 23 instead of 22 samples, 1.1278 + and the 3:rd and 4:th sub-frame are not present. 1.1279 + 1.1280 +3.6.3.1. Creation of a Base Codebook 1.1281 + 1.1282 + The base codebook is given by the perceptually weighted codebook 1.1283 + memory that is mentioned in section 3.5.3. The different codebook 1.1284 + vectors are given by sliding a window of length 23/22 or 40, given by 1.1285 + variable lTarget, over the lMem-long perceptually weighted codebook 1.1286 + memory. The indices are ordered so that the codebook vector 1.1287 + containing sample (lMem-lTarget-n) to (lMem-n-1) of the codebook 1.1288 + 1.1289 + 1.1290 + 1.1291 + 1.1292 + 1.1293 +Andersen, et al. Experimental [Page 23] 1.1294 + 1.1295 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1296 + 1.1297 + 1.1298 + memory vector has index n, where n=0..lMem-lTarget. Thus the total 1.1299 + number of base codebook vectors is lMem-lTarget+1, and the indices 1.1300 + are ordered from sample delay lTarget (23/22 or 40) to lMem+1 (86 or 1.1301 + 148). 1.1302 + 1.1303 +3.6.3.2. Codebook Expansion 1.1304 + 1.1305 + The base codebook is expanded by a factor of 2, creating an 1.1306 + additional section in the codebook. This new section is obtained by 1.1307 + filtering the base codebook, base_cb, with a FIR filter with filter 1.1308 + length CB_FILTERLEN=8. The construction of the expanded codebook 1.1309 + compensates for the delay of four samples introduced by the FIR 1.1310 + filter. 1.1311 + 1.1312 + cbfiltersTbl[CB_FILTERLEN]={-0.033691, 0.083740, -0.144043, 1.1313 + 0.713379, 0.806152, -0.184326, 1.1314 + 0.108887, -0.034180}; 1.1315 + 1.1316 + ___ 1.1317 + \ 1.1318 + exp_cb(k)= + > cbfiltersTbl(i)*x(k-i+4) 1.1319 + /__ 1.1320 + i=0...(LPC_FILTERORDER-1) 1.1321 + 1.1322 + where x(j) = base_cb(j) for j=0..lMem-1 and 0 otherwise 1.1323 + 1.1324 + The individual codebook vectors of the new filtered codebook, exp_cb, 1.1325 + and their indices are obtained in the same fashion as described above 1.1326 + for the base codebook. 1.1327 + 1.1328 +3.6.3.3. Codebook Augmentation 1.1329 + 1.1330 + For cases where encoding entire sub-blocks, i.e., cbveclen=40, the 1.1331 + base and expanded codebooks are augmented to increase codebook 1.1332 + richness. The codebooks are augmented by vectors produced by 1.1333 + interpolation of segments. The base and expanded codebook, 1.1334 + constructed above, consists of vectors corresponding to sample delays 1.1335 + in the range from cbveclen to lMem. The codebook augmentation 1.1336 + attempts to augment these codebooks with vectors corresponding to 1.1337 + sample delays from 20 to 39. However, not all of these samples are 1.1338 + present in the base codebook and expanded codebook, respectively. 1.1339 + Therefore, the augmentation vectors are constructed as linear 1.1340 + combinations between samples corresponding to sample delays in the 1.1341 + range 20 to 39. The general idea of this procedure is presented in 1.1342 + the following figures and text. The procedure is performed for both 1.1343 + the base codebook and the expanded codebook. 1.1344 + 1.1345 + 1.1346 + 1.1347 + 1.1348 + 1.1349 +Andersen, et al. Experimental [Page 24] 1.1350 + 1.1351 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1352 + 1.1353 + 1.1354 + - - ------------------------| 1.1355 + codebook memory | 1.1356 + - - ------------------------| 1.1357 + |-5-|---15---|-5-| 1.1358 + pi pp po 1.1359 + 1.1360 + | | Codebook vector 1.1361 + |---15---|-5-|-----20-----| <- corresponding to 1.1362 + i ii iii sample delay 20 1.1363 + 1.1364 + Figure 3.11. Generation of the first augmented codebook. 1.1365 + 1.1366 + Figure 3.11 shows the codebook memory with pointers pi, pp, and po, 1.1367 + where pi points to sample 25, pp to sample 20, and po to sample 5. 1.1368 + Below the codebook memory, the augmented codebook vector 1.1369 + corresponding to sample delay 20 is drawn. Segment i consists of 1.1370 + fifteen samples from pointer pp and forward in time. Segment ii 1.1371 + consists of five interpolated samples from pi and forward and from po 1.1372 + and forward. The samples are linearly interpolated with weights 1.1373 + [0.0, 0.2, 0.4, 0.6, 0.8] for pi and weights [1.0, 0.8, 0.6, 0.4, 1.1374 + 0.2] for po. Segment iii consists of twenty samples from pp and 1.1375 + forward. The augmented codebook vector corresponding to sample delay 1.1376 + 21 is produced by moving pointers pp and pi one sample backward in 1.1377 + time. This gives us the following figure. 1.1378 + 1.1379 + - - ------------------------| 1.1380 + codebook memory | 1.1381 + - - ------------------------| 1.1382 + |-5-|---16---|-5-| 1.1383 + pi pp po 1.1384 + 1.1385 + | | Codebook vector 1.1386 + |---16---|-5-|-----19-----| <- corresponding to 1.1387 + i ii iii sample delay 21 1.1388 + 1.1389 + Figure 3.12. Generation of the second augmented codebook. 1.1390 + 1.1391 + Figure 3.12 shows the codebook memory with pointers pi, pp and po 1.1392 + where pi points to sample 26, pp to sample 21, and po to sample 5. 1.1393 + Below the codebook memory, the augmented codebook vector 1.1394 + corresponding to sample delay 21 is drawn. Segment i now consists of 1.1395 + sixteen samples from pp and forward. Segment ii consists of five 1.1396 + interpolated samples from pi and forward and from po and forward, and 1.1397 + the interpolation weights are the same throughout the procedure. 1.1398 + Segment iii consists of nineteen samples from pp and forward. The 1.1399 + same procedure of moving the two pointers is continued until the last 1.1400 + augmented vector corresponding to sample delay 39 has been created. 1.1401 + This gives a total of twenty new codebook vectors to each of the two 1.1402 + 1.1403 + 1.1404 + 1.1405 +Andersen, et al. Experimental [Page 25] 1.1406 + 1.1407 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1408 + 1.1409 + 1.1410 + sections. Thus the total number of codebook vectors for each of the 1.1411 + two sections, when including the augmented codebook, becomes lMem- 1.1412 + SUBL+1+SUBL/2. This is provided that augmentation is evoked, i.e., 1.1413 + that lTarget=SUBL. 1.1414 + 1.1415 +3.6.4. Codebook Search 1.1416 + 1.1417 + The codebook search uses the codebooks described in the sections 1.1418 + above to find the best match of the perceptually weighted target, see 1.1419 + section 3.6.2. The search method is a multi-stage gain-shape 1.1420 + matching performed as follows. At each stage the best shape vector 1.1421 + is identified, then the gain is calculated and quantized, and finally 1.1422 + the target is updated in preparation for the next codebook search 1.1423 + stage. The number of stages is CB_NSTAGES=3. 1.1424 + 1.1425 + If the target is the 23/22-sample vector the codebooks are indexed so 1.1426 + that the base codebook is followed by the expanded codebook. If the 1.1427 + target is 40 samples the order is as follows: base codebook, 1.1428 + augmented base codebook, expanded codebook, and augmented expanded 1.1429 + codebook. The size of each codebook section and its corresponding 1.1430 + augmented section is given by Table 3.1 in section 3.6.3. 1.1431 + 1.1432 + For example, when the second 40-sample sub-block is coded, indices 0 1.1433 + - 107 correspond to the base codebook, 108 - 127 correspond to the 1.1434 + augmented base codebook, 128 - 235 correspond to the expanded 1.1435 + codebook, and indices 236 - 255 correspond to the augmented expanded 1.1436 + codebook. The indices are divided in the same fashion for all stages 1.1437 + in the example. Only in the case of coding the first 40-sample sub- 1.1438 + block is there a difference between stages (see Table 3.1). 1.1439 + 1.1440 +3.6.4.1. Codebook Search at Each Stage 1.1441 + 1.1442 + The codebooks are searched to find the best match to the target at 1.1443 + each stage. When the best match is found, the target is updated and 1.1444 + the next-stage search is started. The three chosen codebook vectors 1.1445 + and their corresponding gains constitute the encoded sub-block. The 1.1446 + best match is decided by the following three criteria: 1.1447 + 1.1448 + 1. Compute the measure 1.1449 + 1.1450 + (target*cbvec)^2 / ||cbvec||^2 1.1451 + 1.1452 + for all codebook vectors, cbvec, and choose the codebook vector 1.1453 + maximizing the measure. The expression (target*cbvec) is the dot 1.1454 + product between the target vector to be coded and the codebook vector 1.1455 + for which we compute the measure. The norm, ||x||, is defined as the 1.1456 + square root of (x*x). 1.1457 + 1.1458 + 1.1459 + 1.1460 + 1.1461 +Andersen, et al. Experimental [Page 26] 1.1462 + 1.1463 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1464 + 1.1465 + 1.1466 + 2. The absolute value of the gain, corresponding to the chosen 1.1467 + codebook vector, cbvec, must be smaller than a fixed limit, 1.1468 + CB_MAXGAIN=1.3: 1.1469 + 1.1470 + |gain| < CB_MAXGAIN 1.1471 + 1.1472 + where the gain is computed in the following way: 1.1473 + 1.1474 + gain = (target*cbvec) / ||cbvec||^2 1.1475 + 1.1476 + 3. For the first stage, the dot product of the chosen codebook vector 1.1477 + and target must be positive: 1.1478 + 1.1479 + target*cbvec > 0 1.1480 + 1.1481 + In practice the above criteria are used in a sequential search 1.1482 + through all codebook vectors. The best match is found by registering 1.1483 + a new max measure and index whenever the previously registered max 1.1484 + measure is surpassed and all other criteria are fulfilled. If none 1.1485 + of the codebook vectors fulfill (2) and (3), the first codebook 1.1486 + vector is selected. 1.1487 + 1.1488 +3.6.4.2. Gain Quantization at Each Stage 1.1489 + 1.1490 + The gain follows as a result of the computation 1.1491 + 1.1492 + gain = (target*cbvec) / ||cbvec||^2 1.1493 + 1.1494 + for the optimal codebook vector found by the procedure in section 1.1495 + 3.6.4.1. 1.1496 + 1.1497 + The three stages quantize the gain, using 5, 4, and 3 bits, 1.1498 + respectively. In the first stage, the gain is limited to positive 1.1499 + values. This gain is quantized by finding the nearest value in the 1.1500 + quantization table gain_sq5Tbl. 1.1501 + 1.1502 + gain_sq5Tbl[32]={0.037476, 0.075012, 0.112488, 0.150024, 0.187500, 1.1503 + 0.224976, 0.262512, 0.299988, 0.337524, 0.375000, 1.1504 + 0.412476, 0.450012, 0.487488, 0.525024, 0.562500, 1.1505 + 0.599976, 0.637512, 0.674988, 0.712524, 0.750000, 1.1506 + 0.787476, 0.825012, 0.862488, 0.900024, 0.937500, 1.1507 + 0.974976, 1.012512, 1.049988, 1.087524, 1.125000, 1.1508 + 1.162476, 1.200012} 1.1509 + 1.1510 + The gains of the subsequent two stages can be either positive or 1.1511 + negative. The gains are quantized by using a quantization table 1.1512 + times a scale factor. The second stage uses the table gain_sq4Tbl, 1.1513 + and the third stage uses gain_sq3Tbl. The scale factor equates 0.1 1.1514 + 1.1515 + 1.1516 + 1.1517 +Andersen, et al. Experimental [Page 27] 1.1518 + 1.1519 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1520 + 1.1521 + 1.1522 + or the absolute value of the quantized gain representation value 1.1523 + obtained in the previous stage, whichever is larger. Again, the 1.1524 + resulting gain index is the index to the nearest value of the 1.1525 + quantization table times the scale factor. 1.1526 + 1.1527 + gainQ = scaleFact * gain_sqXTbl[index] 1.1528 + 1.1529 + gain_sq4Tbl[16]={-1.049988, -0.900024, -0.750000, -0.599976, 1.1530 + -0.450012, -0.299988, -0.150024, 0.000000, 0.150024, 1.1531 + 0.299988, 0.450012, 0.599976, 0.750000, 0.900024, 1.1532 + 1.049988, 1.200012} 1.1533 + 1.1534 + gain_sq3Tbl[8]={-1.000000, -0.659973, -0.330017,0.000000, 1.1535 + 0.250000, 0.500000, 0.750000, 1.00000} 1.1536 + 1.1537 +3.6.4.3. Preparation of Target for Next Stage 1.1538 + 1.1539 + Before performing the search for the next stage, the perceptually 1.1540 + weighted target vector is updated by subtracting from it the selected 1.1541 + codebook vector (from the perceptually weighted codebook) times the 1.1542 + corresponding quantized gain. 1.1543 + 1.1544 + target[i] = target[i] - gainQ * selected_vec[i]; 1.1545 + 1.1546 + A reference implementation of the codebook encoding is found in 1.1547 + Appendix A.34. 1.1548 + 1.1549 +3.7. Gain Correction Encoding 1.1550 + 1.1551 + The start state is quantized in a relatively model independent manner 1.1552 + using 3 bits per sample. In contrast, the remaining parts of the 1.1553 + block are encoded by using an adaptive codebook. This codebook will 1.1554 + produce high matching accuracy whenever there is a high correlation 1.1555 + between the target and the best codebook vector. For unvoiced speech 1.1556 + segments and background noises, this is not necessarily so, which, 1.1557 + due to the nature of the squared error criterion, results in a coded 1.1558 + signal with less power than the target signal. As the coded start 1.1559 + state has good power matching to the target, the result is a power 1.1560 + fluctuation within the encoded frame. Perceptually, the main problem 1.1561 + with this is that the time envelope of the signal energy becomes 1.1562 + unsteady. To overcome this problem, the gains for the codebooks are 1.1563 + re-scaled after the codebook encoding by searching for a new gain 1.1564 + factor for the first stage codebook that provides better power 1.1565 + matching. 1.1566 + 1.1567 + First, the energy for the target signal, tene, is computed along with 1.1568 + the energy for the coded signal, cene, given by the addition of the 1.1569 + three gain scaled codebook vectors. Because the gains of the second 1.1570 + 1.1571 + 1.1572 + 1.1573 +Andersen, et al. Experimental [Page 28] 1.1574 + 1.1575 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1576 + 1.1577 + 1.1578 + and third stage scale with the gain of the first stage, when the 1.1579 + first stage gain is changed from gain[0] to gain_sq5Tbl[i] the energy 1.1580 + of the coded signal changes from cene to 1.1581 + 1.1582 + cene*(gain_sq5Tbl[i]*gain_sq5Tbl[i])/(gain[0]*gain[0]) 1.1583 + 1.1584 + where gain[0] is the gain for the first stage found in the original 1.1585 + codebook search. A refined search is performed by testing the gain 1.1586 + indices i=0 to 31, and as long as the new codebook energy as given 1.1587 + above is less than tene, the gain index for stage 1 is increased. A 1.1588 + restriction is applied so that the new gain value for stage 1 cannot 1.1589 + be more than two times higher than the original value found in the 1.1590 + codebook search. Note that by using this method we do not change the 1.1591 + shape of the encoded vector, only the gain or amplitude. 1.1592 + 1.1593 +3.8. Bitstream Definition 1.1594 + 1.1595 + The total number of bits used to describe one frame of 20 ms speech 1.1596 + is 304, which fits in 38 bytes and results in a bit rate of 15.20 1.1597 + kbit/s. For the case of a frame length of 30 ms speech, the total 1.1598 + number of bits used is 400, which fits in 50 bytes and results in a 1.1599 + bit rate of 13.33 kbit/s. In the bitstream definition, the bits are 1.1600 + distributed into three classes according to their bit error or loss 1.1601 + sensitivity. The most sensitive bits (class 1) are placed first in 1.1602 + the bitstream for each frame. The less sensitive bits (class 2) are 1.1603 + placed after the class 1 bits. The least sensitive bits (class 3) 1.1604 + are placed at the end of the bitstream for each frame. 1.1605 + 1.1606 + In the 20/30 ms frame length cases for each class, the following hold 1.1607 + true: The class 1 bits occupy a total of 6/8 bytes (48/64 bits), the 1.1608 + class 2 bits occupy 8/12 bytes (64/96 bits), and the class 3 bits 1.1609 + occupy 24/30 bytes (191/239 bits). This distribution of the bits 1.1610 + enables the use of uneven level protection (ULP) as is exploited in 1.1611 + the payload format definition for iLBC [1]. The detailed bit 1.1612 + allocation is shown in the table below. When a quantization index is 1.1613 + distributed between more classes, the more significant bits belong to 1.1614 + the lowest class. 1.1615 + 1.1616 + 1.1617 + 1.1618 + 1.1619 + 1.1620 + 1.1621 + 1.1622 + 1.1623 + 1.1624 + 1.1625 + 1.1626 + 1.1627 + 1.1628 + 1.1629 +Andersen, et al. Experimental [Page 29] 1.1630 + 1.1631 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1632 + 1.1633 + 1.1634 + Bitstream structure: 1.1635 + 1.1636 + ------------------------------------------------------------------+ 1.1637 + Parameter | Bits Class <1,2,3> | 1.1638 + | 20 ms frame | 30 ms frame | 1.1639 + ----------------------------------+---------------+---------------+ 1.1640 + Split 1 | 6 <6,0,0> | 6 <6,0,0> | 1.1641 + LSF 1 Split 2 | 7 <7,0,0> | 7 <7,0,0> | 1.1642 + LSF Split 3 | 7 <7,0,0> | 7 <7,0,0> | 1.1643 + ------------------+---------------+---------------+ 1.1644 + Split 1 | NA (Not Appl.)| 6 <6,0,0> | 1.1645 + LSF 2 Split 2 | NA | 7 <7,0,0> | 1.1646 + Split 3 | NA | 7 <7,0,0> | 1.1647 + ------------------+---------------+---------------+ 1.1648 + Sum | 20 <20,0,0> | 40 <40,0,0> | 1.1649 + ----------------------------------+---------------+---------------+ 1.1650 + Block Class | 2 <2,0,0> | 3 <3,0,0> | 1.1651 + ----------------------------------+---------------+---------------+ 1.1652 + Position 22 sample segment | 1 <1,0,0> | 1 <1,0,0> | 1.1653 + ----------------------------------+---------------+---------------+ 1.1654 + Scale Factor State Coder | 6 <6,0,0> | 6 <6,0,0> | 1.1655 + ----------------------------------+---------------+---------------+ 1.1656 + Sample 0 | 3 <0,1,2> | 3 <0,1,2> | 1.1657 + Quantized Sample 1 | 3 <0,1,2> | 3 <0,1,2> | 1.1658 + Residual : | : : | : : | 1.1659 + State : | : : | : : | 1.1660 + Samples : | : : | : : | 1.1661 + Sample 56 | 3 <0,1,2> | 3 <0,1,2> | 1.1662 + Sample 57 | NA | 3 <0,1,2> | 1.1663 + ------------------+---------------+---------------+ 1.1664 + Sum | 171 <0,57,114>| 174 <0,58,116>| 1.1665 + ----------------------------------+---------------+---------------+ 1.1666 + Stage 1 | 7 <6,0,1> | 7 <4,2,1> | 1.1667 + CB for 22/23 Stage 2 | 7 <0,0,7> | 7 <0,0,7> | 1.1668 + sample block Stage 3 | 7 <0,0,7> | 7 <0,0,7> | 1.1669 + ------------------+---------------+---------------+ 1.1670 + Sum | 21 <6,0,15> | 21 <4,2,15> | 1.1671 + ----------------------------------+---------------+---------------+ 1.1672 + Stage 1 | 5 <2,0,3> | 5 <1,1,3> | 1.1673 + Gain for 22/23 Stage 2 | 4 <1,1,2> | 4 <1,1,2> | 1.1674 + sample block Stage 3 | 3 <0,0,3> | 3 <0,0,3> | 1.1675 + ------------------+---------------+---------------+ 1.1676 + Sum | 12 <3,1,8> | 12 <2,2,8> | 1.1677 + ----------------------------------+---------------+---------------+ 1.1678 + Stage 1 | 8 <7,0,1> | 8 <6,1,1> | 1.1679 + sub-block 1 Stage 2 | 7 <0,0,7> | 7 <0,0,7> | 1.1680 + Stage 3 | 7 <0,0,7> | 7 <0,0,7> | 1.1681 + ------------------+---------------+---------------+ 1.1682 + 1.1683 + 1.1684 + 1.1685 +Andersen, et al. Experimental [Page 30] 1.1686 + 1.1687 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1688 + 1.1689 + 1.1690 + Stage 1 | 8 <0,0,8> | 8 <0,7,1> | 1.1691 + sub-block 2 Stage 2 | 8 <0,0,8> | 8 <0,0,8> | 1.1692 + Indices Stage 3 | 8 <0,0,8> | 8 <0,0,8> | 1.1693 + for CB ------------------+---------------+---------------+ 1.1694 + sub-blocks Stage 1 | NA | 8 <0,7,1> | 1.1695 + sub-block 3 Stage 2 | NA | 8 <0,0,8> | 1.1696 + Stage 3 | NA | 8 <0,0,8> | 1.1697 + ------------------+---------------+---------------+ 1.1698 + Stage 1 | NA | 8 <0,7,1> | 1.1699 + sub-block 4 Stage 2 | NA | 8 <0,0,8> | 1.1700 + Stage 3 | NA | 8 <0,0,8> | 1.1701 + ------------------+---------------+---------------+ 1.1702 + Sum | 46 <7,0,39> | 94 <6,22,66> | 1.1703 + ----------------------------------+---------------+---------------+ 1.1704 + Stage 1 | 5 <1,2,2> | 5 <1,2,2> | 1.1705 + sub-block 1 Stage 2 | 4 <1,1,2> | 4 <1,2,1> | 1.1706 + Stage 3 | 3 <0,0,3> | 3 <0,0,3> | 1.1707 + ------------------+---------------+---------------+ 1.1708 + Stage 1 | 5 <1,1,3> | 5 <0,2,3> | 1.1709 + sub-block 2 Stage 2 | 4 <0,2,2> | 4 <0,2,2> | 1.1710 + Stage 3 | 3 <0,0,3> | 3 <0,0,3> | 1.1711 + Gains for ------------------+---------------+---------------+ 1.1712 + sub-blocks Stage 1 | NA | 5 <0,1,4> | 1.1713 + sub-block 3 Stage 2 | NA | 4 <0,1,3> | 1.1714 + Stage 3 | NA | 3 <0,0,3> | 1.1715 + ------------------+---------------+---------------+ 1.1716 + Stage 1 | NA | 5 <0,1,4> | 1.1717 + sub-block 4 Stage 2 | NA | 4 <0,1,3> | 1.1718 + Stage 3 | NA | 3 <0,0,3> | 1.1719 + ------------------+---------------+---------------+ 1.1720 + Sum | 24 <3,6,15> | 48 <2,12,34> | 1.1721 + ----------------------------------+---------------+---------------+ 1.1722 + Empty frame indicator | 1 <0,0,1> | 1 <0,0,1> | 1.1723 + ------------------------------------------------------------------- 1.1724 + SUM 304 <48,64,192> 400 <64,96,240> 1.1725 + 1.1726 + Table 3.2. The bitstream definition for iLBC for both the 20 ms 1.1727 + frame size mode and the 30 ms frame size mode. 1.1728 + 1.1729 + When packetized into the payload, the bits MUST be sorted as follows: 1.1730 + All the class 1 bits in the order (from top to bottom) as specified 1.1731 + in the table, all the class 2 bits (from top to bottom), and all the 1.1732 + class 3 bits in the same sequential order. The last bit, the empty 1.1733 + frame indicator, SHOULD be set to zero by the encoder. If this bit 1.1734 + is set to 1 the decoder SHOULD treat the data as a lost frame. For 1.1735 + example, this bit can be set to 1 to indicate lost frame for file 1.1736 + storage format, as in [1]. 1.1737 + 1.1738 + 1.1739 + 1.1740 + 1.1741 +Andersen, et al. Experimental [Page 31] 1.1742 + 1.1743 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1744 + 1.1745 + 1.1746 +4. Decoder Principles 1.1747 + 1.1748 + This section describes the principles of each component of the 1.1749 + decoder algorithm. 1.1750 + 1.1751 + +-------------+ +--------+ +---------------+ 1.1752 + payload -> | 1. Get para | -> | 2. LPC | -> | 3. Sc Dequant | -> 1.1753 + +-------------+ +--------+ +---------------+ 1.1754 + 1.1755 + +-------------+ +------------------+ 1.1756 + -> | 4. Mem setup| -> | 5. Construct res |-------> 1.1757 + | +-------------+ +------------------- | 1.1758 + ---------<-----------<-----------<------------ 1.1759 + Sub-frame 0...2/4 (20 ms/30 ms) 1.1760 + 1.1761 + +----------------+ +----------+ 1.1762 + -> | 6. Enhance res | -> | 7. Synth | ------------> 1.1763 + +----------------+ +----------+ 1.1764 + 1.1765 + +-----------------+ 1.1766 + -> | 8. Post Process | ----------------> decoded speech 1.1767 + +-----------------+ 1.1768 + 1.1769 + Figure 4.1. Flow chart of the iLBC decoder. If a frame was lost, 1.1770 + steps 1 to 5 SHOULD be replaced by a PLC algorithm. 1.1771 + 1.1772 + 1. Extract the parameters from the bitstream. 1.1773 + 1.1774 + 2. Decode the LPC and interpolate (section 4.1). 1.1775 + 1.1776 + 3. Construct the 57/58-sample start state (section 4.2). 1.1777 + 1.1778 + 4. Set up the memory by using data from the decoded residual. This 1.1779 + memory is used for codebook construction. For blocks preceding 1.1780 + the start state, both the decoded residual and the target are time 1.1781 + reversed. Sub-frames are decoded in the same order as they were 1.1782 + encoded. 1.1783 + 1.1784 + 5. Construct the residuals of this sub-frame (gain[0]*cbvec[0] + 1.1785 + gain[1]*cbvec[1] + gain[2]*cbvec[2]). Repeat 4 and 5 until the 1.1786 + residual of all sub-blocks has been constructed. 1.1787 + 1.1788 + 6. Enhance the residual with the post filter (section 4.6). 1.1789 + 1.1790 + 7. Synthesis of the residual (section 4.7). 1.1791 + 1.1792 + 8. Post process with HP filter, if desired (section 4.8). 1.1793 + 1.1794 + 1.1795 + 1.1796 + 1.1797 +Andersen, et al. Experimental [Page 32] 1.1798 + 1.1799 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1800 + 1.1801 + 1.1802 +4.1. LPC Filter Reconstruction 1.1803 + 1.1804 + The decoding of the LP filter parameters is very straightforward. 1.1805 + For a set of three/six indices, the corresponding LSF vector(s) are 1.1806 + found by simple table lookup. For each of the LSF vectors, the three 1.1807 + split vectors are concatenated to obtain qlsf1 and qlsf2, 1.1808 + respectively (in the 20 ms mode only one LSF vector, qlsf, is 1.1809 + constructed). The next step is the stability check described in 1.1810 + section 3.2.5 followed by the interpolation scheme described in 1.1811 + section 3.2.6 (3.2.7 for 20 ms frames). The only difference is that 1.1812 + only the quantized LSFs are known at the decoder, and hence the 1.1813 + unquantized LSFs are not processed. 1.1814 + 1.1815 + A reference implementation of the LPC filter reconstruction is given 1.1816 + in Appendix A.36. 1.1817 + 1.1818 +4.2. Start State Reconstruction 1.1819 + 1.1820 + The scalar encoded STATE_SHORT_LEN=58 (STATE_SHORT_LEN=57 in the 20 1.1821 + ms mode) state samples are reconstructed by 1) forming a set of 1.1822 + samples (by table lookup) from the index stream idxVec[n], 2) 1.1823 + multiplying the set with 1/scal=(10^qmax)/4.5, 3) time reversing the 1.1824 + 57/58 samples, 4) filtering the time reversed block with the 1.1825 + dispersion (all-pass) filter used in the encoder (as described in 1.1826 + section 3.5.2); this compensates for the phase distortion of the 1.1827 + earlier filter operation, and 5 reversing the 57/58 samples from the 1.1828 + previous step. 1.1829 + 1.1830 + in(0..(STATE_SHORT_LEN-1)) = time reversed samples from table 1.1831 + look-up, 1.1832 + idxVecDec((STATE_SHORT_LEN-1)..0) 1.1833 + 1.1834 + in(STATE_SHORT_LEN..(2*STATE_SHORT_LEN-1)) = 0 1.1835 + 1.1836 + Pk(z) = A~rk(z)/A~k(z), where 1.1837 + ___ 1.1838 + \ 1.1839 + A~rk(z)= z^(-LPC_FILTERORDER) + > a~ki*z^(i-(LPC_FILTERORDER-1)) 1.1840 + /__ 1.1841 + i=0...(LPC_FILTERORDER-1) 1.1842 + 1.1843 + and A~k(z) is taken from the block where the start state begins 1.1844 + 1.1845 + in -> Pk(z) -> filtered 1.1846 + 1.1847 + out(k) = filtered(STATE_SHORT_LEN-1-k) + 1.1848 + filtered(2*STATE_SHORT_LEN-1-k), 1.1849 + k=0..(STATE_SHORT_LEN-1) 1.1850 + 1.1851 + 1.1852 + 1.1853 +Andersen, et al. Experimental [Page 33] 1.1854 + 1.1855 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1856 + 1.1857 + 1.1858 + The remaining 23/22 samples in the state are reconstructed by the 1.1859 + same adaptive codebook technique described in section 4.3. The 1.1860 + location bit determines whether these are the first or the last 23/22 1.1861 + samples of the 80-sample state vector. If the remaining 23/22 1.1862 + samples are the first samples, then the scalar encoded 1.1863 + STATE_SHORT_LEN state samples are time-reversed before initialization 1.1864 + of the adaptive codebook memory vector. 1.1865 + 1.1866 + A reference implementation of the start state reconstruction is given 1.1867 + in Appendix A.44. 1.1868 + 1.1869 +4.3. Excitation Decoding Loop 1.1870 + 1.1871 + The decoding of the LPC excitation vector proceeds in the same order 1.1872 + in which the residual was encoded at the encoder. That is, after the 1.1873 + decoding of the entire 80-sample state vector, the forward sub-blocks 1.1874 + (corresponding to samples occurring after the state vector samples) 1.1875 + are decoded, and then the backward sub-blocks (corresponding to 1.1876 + samples occurring before the state vector) are decoded, resulting in 1.1877 + a fully decoded block of excitation signal samples. 1.1878 + 1.1879 + In particular, each sub-block is decoded by using the multistage 1.1880 + adaptive codebook decoding module described in section 4.4. This 1.1881 + module relies upon an adaptive codebook memory constructed before 1.1882 + each run of the adaptive codebook decoding. The construction of the 1.1883 + adaptive codebook memory in the decoder is identical to the method 1.1884 + outlined in section 3.6.3, except that it is done on the codebook 1.1885 + memory without perceptual weighting. 1.1886 + 1.1887 + For the initial forward sub-block, the last STATE_LEN=80 samples of 1.1888 + the length CB_LMEM=147 adaptive codebook memory are filled with the 1.1889 + samples of the state vector. For subsequent forward sub-blocks, the 1.1890 + first SUBL=40 samples of the adaptive codebook memory are discarded, 1.1891 + the remaining samples are shifted by SUBL samples toward the 1.1892 + beginning of the vector, and the newly decoded SUBL=40 samples are 1.1893 + placed at the end of the adaptive codebook memory. For backward 1.1894 + sub-blocks, the construction is similar, except that every vector of 1.1895 + samples involved is first time reversed. 1.1896 + 1.1897 + A reference implementation of the excitation decoding loop is found 1.1898 + in Appendix A.5. 1.1899 + 1.1900 + 1.1901 + 1.1902 + 1.1903 + 1.1904 + 1.1905 + 1.1906 + 1.1907 + 1.1908 + 1.1909 +Andersen, et al. Experimental [Page 34] 1.1910 + 1.1911 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1912 + 1.1913 + 1.1914 +4.4. Multistage Adaptive Codebook Decoding 1.1915 + 1.1916 + The Multistage Adaptive Codebook Decoding module is used at both the 1.1917 + sender (encoder) and the receiver (decoder) ends to produce a 1.1918 + synthetic signal in the residual domain that is eventually used to 1.1919 + produce synthetic speech. The module takes the index values used to 1.1920 + construct vectors that are scaled and summed together to produce a 1.1921 + synthetic signal that is the output of the module. 1.1922 + 1.1923 +4.4.1. Construction of the Decoded Excitation Signal 1.1924 + 1.1925 + The unpacked index values provided at the input to the module are 1.1926 + references to extended codebooks, which are constructed as described 1.1927 + in section 3.6.3, except that they are based on the codebook memory 1.1928 + without the perceptual weighting. The unpacked three indices are 1.1929 + used to look up three codebook vectors. The unpacked three gain 1.1930 + indices are used to decode the corresponding 3 gains. In this 1.1931 + decoding, the successive rescaling, as described in section 3.6.4.2, 1.1932 + is applied. 1.1933 + 1.1934 + A reference implementation of the adaptive codebook decoding is 1.1935 + listed in Appendix A.32. 1.1936 + 1.1937 +4.5. Packet Loss Concealment 1.1938 + 1.1939 + If packet loss occurs, the decoder receives a signal saying that 1.1940 + information regarding a block is lost. For such blocks it is 1.1941 + RECOMMENDED to use a Packet Loss Concealment (PLC) unit to create a 1.1942 + decoded signal that masks the effect of that packet loss. In the 1.1943 + following we will describe an example of a PLC unit that can be used 1.1944 + with the iLBC codec. As the PLC unit is used only at the decoder, 1.1945 + the PLC unit does not affect interoperability between 1.1946 + implementations. Other PLC implementations MAY therefore be used. 1.1947 + 1.1948 + The PLC described operates on the LP filters and the excitation 1.1949 + signals and is based on the following principles: 1.1950 + 1.1951 +4.5.1. Block Received Correctly and Previous Block Also Received 1.1952 + 1.1953 + If the block is received correctly, the PLC only records state 1.1954 + information of the current block that can be used in case the next 1.1955 + block is lost. The LP filter coefficients for each sub-block and the 1.1956 + entire decoded excitation signal are all saved in the decoder state 1.1957 + structure. All of this information will be needed if the following 1.1958 + block is lost. 1.1959 + 1.1960 + 1.1961 + 1.1962 + 1.1963 + 1.1964 + 1.1965 +Andersen, et al. Experimental [Page 35] 1.1966 + 1.1967 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.1968 + 1.1969 + 1.1970 +4.5.2. Block Not Received 1.1971 + 1.1972 + If the block is not received, the block substitution is based on a 1.1973 + pitch-synchronous repetition of the excitation signal, which is 1.1974 + filtered by the last LP filter of the previous block. The previous 1.1975 + block's information is stored in the decoder state structure. 1.1976 + 1.1977 + A correlation analysis is performed on the previous block's 1.1978 + excitation signal in order to detect the amount of pitch periodicity 1.1979 + and a pitch value. The correlation measure is also used to decide on 1.1980 + the voicing level (the degree to which the previous block's 1.1981 + excitation was a voiced or roughly periodic signal). The excitation 1.1982 + in the previous block is used to create an excitation for the block 1.1983 + to be substituted, such that the pitch of the previous block is 1.1984 + maintained. Therefore, the new excitation is constructed in a 1.1985 + pitch-synchronous manner. In order to avoid a buzzy-sounding 1.1986 + substituted block, a random excitation is mixed with the new pitch 1.1987 + periodic excitation, and the relative use of the two components is 1.1988 + computed from the correlation measure (voicing level). 1.1989 + 1.1990 + For the block to be substituted, the newly constructed excitation 1.1991 + signal is then passed through the LP filter to produce the speech 1.1992 + that will be substituted for the lost block. 1.1993 + 1.1994 + For several consecutive lost blocks, the packet loss concealment 1.1995 + continues in a similar manner. The correlation measure of the last 1.1996 + block received is still used along with the same pitch value. The LP 1.1997 + filters of the last block received are also used again. The energy 1.1998 + of the substituted excitation for consecutive lost blocks is 1.1999 + decreased, leading to a dampened excitation, and therefore to 1.2000 + dampened speech. 1.2001 + 1.2002 +4.5.3. Block Received Correctly When Previous Block Not Received 1.2003 + 1.2004 + For the case in which a block is received correctly when the previous 1.2005 + block was not, the correctly received block's directly decoded speech 1.2006 + (based solely on the received block) is not used as the actual 1.2007 + output. The reason for this is that the directly decoded speech does 1.2008 + not necessarily smoothly merge into the synthetic speech generated 1.2009 + for the previous lost block. If the two signals are not smoothly 1.2010 + merged, an audible discontinuity is accidentally produced. 1.2011 + Therefore, a correlation analysis between the two blocks of 1.2012 + excitation signal (the excitation of the previous concealed block and 1.2013 + that of the current received block) is performed to find the best 1.2014 + phase match. Then a simple overlap-add procedure is performed to 1.2015 + merge the previous excitation smoothly into the current block's 1.2016 + excitation. 1.2017 + 1.2018 + 1.2019 + 1.2020 + 1.2021 +Andersen, et al. Experimental [Page 36] 1.2022 + 1.2023 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2024 + 1.2025 + 1.2026 + The exact implementation of the packet loss concealment does not 1.2027 + influence interoperability of the codec. 1.2028 + 1.2029 + A reference implementation of the packet loss concealment is 1.2030 + suggested in Appendix A.14. Exact compliance with this suggested 1.2031 + algorithm is not needed for a reference implementation to be fully 1.2032 + compatible with the overall codec specification. 1.2033 + 1.2034 +4.6. Enhancement 1.2035 + 1.2036 + The decoder contains an enhancement unit that operates on the 1.2037 + reconstructed excitation signal. The enhancement unit increases the 1.2038 + perceptual quality of the reconstructed signal by reducing the 1.2039 + speech-correlated noise in the voiced speech segments. Compared to 1.2040 + traditional postfilters, the enhancer has an advantage in that it can 1.2041 + only modify the excitation signal slightly. This means that there is 1.2042 + no risk of over enhancement. The enhancer works very similarly for 1.2043 + both the 20 ms frame size mode and the 30 ms frame size mode. 1.2044 + 1.2045 + For the mode with 20 ms frame size, the enhancer uses a memory of six 1.2046 + 80-sample excitation blocks prior in time plus the two new 80-sample 1.2047 + excitation blocks. For each block of 160 new unenhanced excitation 1.2048 + samples, 160 enhanced excitation samples are produced. The enhanced 1.2049 + excitation is 40-sample delayed compared to the unenhanced 1.2050 + excitation, as the enhancer algorithm uses lookahead. 1.2051 + 1.2052 + For the mode with 30 ms frame size, the enhancer uses a memory of 1.2053 + five 80-sample excitation blocks prior in time plus the three new 1.2054 + 80-sample excitation blocks. For each block of 240 new unenhanced 1.2055 + excitation samples, 240 enhanced excitation samples are produced. 1.2056 + The enhanced excitation is 80-sample delayed compared to the 1.2057 + unenhanced excitation, as the enhancer algorithm uses lookahead. 1.2058 + 1.2059 + Outline of Enhancer 1.2060 + 1.2061 + The speech enhancement unit operates on sub-blocks of 80 samples, 1.2062 + which means that there are two/three 80 sample sub-blocks per frame. 1.2063 + Each of these two/three sub-blocks is enhanced separately, but in an 1.2064 + analogous manner. 1.2065 + 1.2066 + 1.2067 + 1.2068 + 1.2069 + 1.2070 + 1.2071 + 1.2072 + 1.2073 + 1.2074 + 1.2075 + 1.2076 + 1.2077 +Andersen, et al. Experimental [Page 37] 1.2078 + 1.2079 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2080 + 1.2081 + 1.2082 + unenhanced residual 1.2083 + | 1.2084 + | +---------------+ +--------------+ 1.2085 + +-> | 1. Pitch Est | -> | 2. Find PSSQ | --------> 1.2086 + +---------------+ | +--------------+ 1.2087 + +-----<-------<------<--+ 1.2088 + +------------+ enh block 0..1/2 | 1.2089 + -> | 3. Smooth | | 1.2090 + +------------+ | 1.2091 + \ | 1.2092 + /\ | 1.2093 + / \ Already | 1.2094 + / 4. \----------->----------->-----------+ | 1.2095 + \Crit/ Fulfilled | | 1.2096 + \? / v | 1.2097 + \/ | | 1.2098 + \ +-----------------+ +---------+ | | 1.2099 + Not +->| 5. Use Constr. | -> | 6. Mix | -----> 1.2100 + Fulfilled +-----------------+ +---------+ 1.2101 + 1.2102 + ---------------> enhanced residual 1.2103 + 1.2104 + Figure 4.2. Flow chart of the enhancer. 1.2105 + 1.2106 + 1. Pitch estimation of each of the two/three new 80-sample blocks. 1.2107 + 1.2108 + 2. Find the pitch-period-synchronous sequence n (for block k) by a 1.2109 + search around the estimated pitch value. Do this for n=1,2,3, 1.2110 + -1,-2,-3. 1.2111 + 1.2112 + 3. Calculate the smoothed residual generated by the six pitch- 1.2113 + period-synchronous sequences from prior step. 1.2114 + 1.2115 + 4. Check if the smoothed residual satisfies the criterion (section 1.2116 + 4.6.4). 1.2117 + 1.2118 + 5. Use constraint to calculate mixing factor (section 4.6.5). 1.2119 + 1.2120 + 6. Mix smoothed signal with unenhanced residual (pssq(n) n=0). 1.2121 + 1.2122 + The main idea of the enhancer is to find three 80 sample blocks 1.2123 + before and three 80-sample blocks after the analyzed unenhanced sub- 1.2124 + block and to use these to improve the quality of the excitation in 1.2125 + that sub-block. The six blocks are chosen so that they have the 1.2126 + highest possible correlation with the unenhanced sub-block that is 1.2127 + being enhanced. In other words, the six blocks are pitch-period- 1.2128 + synchronous sequences to the unenhanced sub-block. 1.2129 + 1.2130 + 1.2131 + 1.2132 + 1.2133 +Andersen, et al. Experimental [Page 38] 1.2134 + 1.2135 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2136 + 1.2137 + 1.2138 + A linear combination of the six pitch-period-synchronous sequences is 1.2139 + calculated that approximates the sub-block. If the squared error 1.2140 + between the approximation and the unenhanced sub-block is small 1.2141 + enough, the enhanced residual is set equal to this approximation. 1.2142 + For the cases when the squared error criterion is not fulfilled, a 1.2143 + linear combination of the approximation and the unenhanced residual 1.2144 + forms the enhanced residual. 1.2145 + 1.2146 +4.6.1. Estimating the Pitch 1.2147 + 1.2148 + Pitch estimates are needed to determine the locations of the pitch- 1.2149 + period-synchronous sequences in a complexity-efficient way. For each 1.2150 + of the new two/three sub-blocks, a pitch estimate is calculated by 1.2151 + finding the maximum correlation in the range from lag 20 to lag 120. 1.2152 + These pitch estimates are used to narrow down the search for the best 1.2153 + possible pitch-period-synchronous sequences. 1.2154 + 1.2155 +4.6.2. Determination of the Pitch-Synchronous Sequences 1.2156 + 1.2157 + Upon receiving the pitch estimates from the prior step, the enhancer 1.2158 + analyzes and enhances one 80-sample sub-block at a time. The pitch- 1.2159 + period-synchronous-sequences pssq(n) can be viewed as vectors of 1.2160 + length 80 samples each shifted n*lag samples from the current sub- 1.2161 + block. The six pitch-period-synchronous-sequences, pssq(-3) to 1.2162 + pssq(-1) and pssq(1) to pssq(3), are found one at a time by the steps 1.2163 + below: 1.2164 + 1.2165 + 1) Calculate the estimate of the position of the pssq(n). For 1.2166 + pssq(n) in front of pssq(0) (n > 0), the location of the pssq(n) 1.2167 + is estimated by moving one pitch estimate forward in time from the 1.2168 + exact location of pssq(n-1). Similarly, pssq(n) behind pssq(0) (n 1.2169 + < 0) is estimated by moving one pitch estimate backward in time 1.2170 + from the exact location of pssq(n+1). If the estimated pssq(n) 1.2171 + vector location is totally within the enhancer memory (Figure 1.2172 + 4.3), steps 2, 3, and 4 are performed, otherwise the pssq(n) is 1.2173 + set to zeros. 1.2174 + 1.2175 + 2) Compute the correlation between the unenhanced excitation and 1.2176 + vectors around the estimated location interval of pssq(n). The 1.2177 + correlation is calculated in the interval estimated location +/- 2 1.2178 + samples. This results in five correlation values. 1.2179 + 1.2180 + 3) The five correlation values are upsampled by a factor of 4, by 1.2181 + using four simple upsampling filters (MA filters with coefficients 1.2182 + upsFilter1.. upsFilter4). Within these the maximum value is 1.2183 + found, which specifies the best pitch-period with a resolution of 1.2184 + a quarter of a sample. 1.2185 + 1.2186 + 1.2187 + 1.2188 + 1.2189 +Andersen, et al. Experimental [Page 39] 1.2190 + 1.2191 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2192 + 1.2193 + 1.2194 + upsFilter1[7]={0.000000 0.000000 0.000000 1.000000 1.2195 + 0.000000 0.000000 0.000000} 1.2196 + upsFilter2[7]={0.015625 -0.076904 0.288330 0.862061 1.2197 + -0.106445 0.018799 -0.015625} 1.2198 + upsFilter3[7]={0.023682 -0.124268 0.601563 0.601563 1.2199 + -0.124268 0.023682 -0.023682} 1.2200 + upsFilter4[7]={0.018799 -0.106445 0.862061 0.288330 1.2201 + -0.076904 0.015625 -0.018799} 1.2202 + 1.2203 + 4) Generate the pssq(n) vector by upsampling of the excitation memory 1.2204 + and extracting the sequence that corresponds to the lag delay that 1.2205 + was calculated in prior step. 1.2206 + 1.2207 + With the steps above, all the pssq(n) can be found in an iterative 1.2208 + manner, first moving backward in time from pssq(0) and then forward 1.2209 + in time from pssq(0). 1.2210 + 1.2211 + 1.2212 + 0 159 319 479 639 1.2213 + +---------------------------------------------------------------+ 1.2214 + | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 1.2215 + +---------------------------------------------------------------+ 1.2216 + |pssq 0 | 1.2217 + |pssq -1| |pssq 1 | 1.2218 + |pssq -2| |pssq 2 | 1.2219 + |pssq -3| |pssq 3 | 1.2220 + 1.2221 + Figure 4.3. Enhancement for 20 ms frame size. 1.2222 + 1.2223 + Figure 4.3 depicts pitch-period-synchronous sequences in the 1.2224 + enhancement of the first 80 sample block in the 20 ms frame size 1.2225 + mode. The unenhanced signal input is stored in the last two sub- 1.2226 + blocks (1 - 2), and the six other sub-blocks contain unenhanced 1.2227 + residual prior-in-time. We perform the enhancement algorithm on two 1.2228 + blocks of 80 samples, where the first of the two blocks consists of 1.2229 + the last 40 samples of sub-block 0 and the first 40 samples of sub- 1.2230 + block 1. The second 80-sample block consists of the last 40 samples 1.2231 + of sub-block 1 and the first 40 samples of sub-block 2. 1.2232 + 1.2233 + 1.2234 + 1.2235 + 1.2236 + 1.2237 + 1.2238 + 1.2239 + 1.2240 + 1.2241 + 1.2242 + 1.2243 + 1.2244 + 1.2245 +Andersen, et al. Experimental [Page 40] 1.2246 + 1.2247 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2248 + 1.2249 + 1.2250 + 0 159 319 479 639 1.2251 + +---------------------------------------------------------------+ 1.2252 + | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 1.2253 + +---------------------------------------------------------------+ 1.2254 + |pssq 0 | 1.2255 + |pssq -1| |pssq 1 | 1.2256 + |pssq -2| |pssq 2 | 1.2257 + |pssq -3| |pssq 3 | 1.2258 + 1.2259 + Figure 4.4. Enhancement for 30 ms frame size. 1.2260 + 1.2261 + Figure 4.4 depicts pitch-period-synchronous sequences in the 1.2262 + enhancement of the first 80-sample block in the 30 ms frame size 1.2263 + mode. The unenhanced signal input is stored in the last three sub- 1.2264 + blocks (1 - 3). The five other sub-blocks contain unenhanced 1.2265 + residual prior-in-time. The enhancement algorithm is performed on 1.2266 + the three 80 sample sub-blocks 0, 1, and 2. 1.2267 + 1.2268 +4.6.3. Calculation of the Smoothed Excitation 1.2269 + 1.2270 + A linear combination of the six pssq(n) (n!=0) form a smoothed 1.2271 + approximation, z, of pssq(0). Most of the weight is put on the 1.2272 + sequences that are close to pssq(0), as these are likely to be most 1.2273 + similar to pssq(0). The smoothed vector is also rescaled so that the 1.2274 + energy of z is the same as the energy of pssq(0). 1.2275 + 1.2276 + ___ 1.2277 + \ 1.2278 + y = > pssq(i) * pssq_weight(i) 1.2279 + /__ 1.2280 + i=-3,-2,-1,1,2,3 1.2281 + 1.2282 + pssq_weight(i) = 0.5*(1-cos(2*pi*(i+4)/(2*3+2))) 1.2283 + 1.2284 + z = C * y, where C = ||pssq(0)||/||y|| 1.2285 + 1.2286 +4.6.4. Enhancer Criterion 1.2287 + 1.2288 + The criterion of the enhancer is that the enhanced excitation is not 1.2289 + allowed to differ much from the unenhanced excitation. This 1.2290 + criterion is checked for each 80-sample sub-block. 1.2291 + 1.2292 + e < (b * ||pssq(0)||^2), where b=0.05 and (Constraint 1) 1.2293 + 1.2294 + e = (pssq(0)-z)*(pssq(0)-z), and "*" means the dot product 1.2295 + 1.2296 + 1.2297 + 1.2298 + 1.2299 + 1.2300 + 1.2301 +Andersen, et al. Experimental [Page 41] 1.2302 + 1.2303 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2304 + 1.2305 + 1.2306 +4.6.5. Enhancing the excitation 1.2307 + 1.2308 + From the criterion in the previous section, it is clear that the 1.2309 + excitation is not allowed to change much. The purpose of this 1.2310 + constraint is to prevent the creation of an enhanced signal 1.2311 + significantly different from the original signal. This also means 1.2312 + that the constraint limits the numerical size of the errors that the 1.2313 + enhancement procedure can make. That is especially important in 1.2314 + unvoiced segments and background noise segments for which increased 1.2315 + periodicity could lead to lower perceived quality. 1.2316 + 1.2317 + When the constraint in the prior section is not met, the enhanced 1.2318 + residual is instead calculated through a constrained optimization by 1.2319 + using the Lagrange multiplier technique. The new constraint is that 1.2320 + 1.2321 + e = (b * ||pssq(0)||^2) (Constraint 2) 1.2322 + 1.2323 + We distinguish two solution regions for the optimization: 1) the 1.2324 + region where the first constraint is fulfilled and 2) the region 1.2325 + where the first constraint is not fulfilled and the second constraint 1.2326 + must be used. 1.2327 + 1.2328 + In the first case, where the second constraint is not needed, the 1.2329 + optimized re-estimated vector is simply z, the energy-scaled version 1.2330 + of y. 1.2331 + 1.2332 + In the second case, where the second constraint is activated and 1.2333 + becomes an equality constraint, we have 1.2334 + 1.2335 + z= A*y + B*pssq(0) 1.2336 + 1.2337 + where 1.2338 + 1.2339 + A = sqrt((b-b^2/4)*(w00*w00)/ (w11*w00 + w10*w10)) and 1.2340 + 1.2341 + w11 = pssq(0)*pssq(0) 1.2342 + w00 = y*y 1.2343 + w10 = y*pssq(0) (* symbolizes the dot product) 1.2344 + 1.2345 + and 1.2346 + 1.2347 + B = 1 - b/2 - A * w10/w00 1.2348 + 1.2349 + Appendix A.16 contains a listing of a reference implementation for 1.2350 + the enhancement method. 1.2351 + 1.2352 + 1.2353 + 1.2354 + 1.2355 + 1.2356 + 1.2357 +Andersen, et al. Experimental [Page 42] 1.2358 + 1.2359 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2360 + 1.2361 + 1.2362 +4.7. Synthesis Filtering 1.2363 + 1.2364 + Upon decoding or PLC of the LP excitation block, the decoded speech 1.2365 + block is obtained by running the decoded LP synthesis filter, 1.2366 + 1/A~k(z), over the block. The synthesis filters have to be shifted 1.2367 + to compensate for the delay in the enhancer. For 20 ms frame size 1.2368 + mode, they SHOULD be shifted one 40-sample sub-block, and for 30 ms 1.2369 + frame size mode, they SHOULD be shifted two 40-sample sub-blocks. 1.2370 + The LP coefficients SHOULD be changed at the first sample of every 1.2371 + sub-block while keeping the filter state. For PLC blocks, one 1.2372 + solution is to apply the last LP coefficients of the last decoded 1.2373 + speech block for all sub-blocks. 1.2374 + 1.2375 + The reference implementation for the synthesis filtering can be found 1.2376 + in Appendix A.48. 1.2377 + 1.2378 +4.8. Post Filtering 1.2379 + 1.2380 + If desired, the decoded block can be filtered by a high-pass filter. 1.2381 + This removes the low frequencies of the decoded signal. A reference 1.2382 + implementation of this, with cutoff at 65 Hz, is shown in Appendix 1.2383 + A.30. 1.2384 + 1.2385 +5. Security Considerations 1.2386 + 1.2387 + This algorithm for the coding of speech signals is not subject to any 1.2388 + known security consideration; however, its RTP payload format [1] is 1.2389 + subject to several considerations, which are addressed there. 1.2390 + Confidentiality of the media streams is achieved by encryption; 1.2391 + therefore external mechanisms, such as SRTP [5], MAY be used for that 1.2392 + purpose. 1.2393 + 1.2394 +6. Evaluation of the iLBC Implementations 1.2395 + 1.2396 + It is possible and suggested to evaluate certain iLBC implementation 1.2397 + by utilizing methodology and tools available at 1.2398 + http://www.ilbcfreeware.org/evaluation.html 1.2399 + 1.2400 +7. References 1.2401 + 1.2402 +7.1. Normative References 1.2403 + 1.2404 + [1] Duric, A. and S. Andersen, "Real-time Transport Protocol (RTP) 1.2405 + Payload Format for internet Low Bit Rate Codec (iLBC) Speech", 1.2406 + RFC 3952, December 2004. 1.2407 + 1.2408 + [2] Bradner, S., "Key words for use in RFCs to Indicate Requirement 1.2409 + Levels", BCP 14, RFC 2119, March 1997. 1.2410 + 1.2411 + 1.2412 + 1.2413 +Andersen, et al. Experimental [Page 43] 1.2414 + 1.2415 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2416 + 1.2417 + 1.2418 + [3] PacketCable(TM) Audio/Video Codecs Specification, Cable 1.2419 + Television Laboratories, Inc. 1.2420 + 1.2421 +7.2. Informative References 1.2422 + 1.2423 + [4] ITU-T Recommendation G.711, available online from the ITU 1.2424 + bookstore at http://www.itu.int. 1.2425 + 1.2426 + [5] Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norman, 1.2427 + "The Secure Real Time Transport Protocol (SRTP)", RFC 3711, March 1.2428 + 2004. 1.2429 + 1.2430 +8. Acknowledgements 1.2431 + 1.2432 + This extensive work, besides listed authors, has the following 1.2433 + authors, who could not have been listed among "official" authors (due 1.2434 + to IESG restrictions in the number of authors who can be listed): 1.2435 + 1.2436 + Manohar N. Murthi (Department of Electrical and Computer 1.2437 + Engineering, University of Miami), Fredrik Galschiodt, Julian 1.2438 + Spittka, and Jan Skoglund (Global IP Sound). 1.2439 + 1.2440 + The authors are deeply indebted to the following people and thank 1.2441 + them sincerely: 1.2442 + 1.2443 + Henry Sinnreich, Patrik Faltstrom, Alan Johnston, and Jean- 1.2444 + Francois Mule for great support of the iLBC initiative and for 1.2445 + valuable feedback and comments. 1.2446 + 1.2447 + Peter Vary, Frank Mertz, and Christoph Erdmann (RWTH Aachen); 1.2448 + Vladimir Cuperman (Niftybox LLC); Thomas Eriksson (Chalmers Univ 1.2449 + of Tech), and Gernot Kubin (TU Graz), for thorough review of the 1.2450 + iLBC document and their valuable feedback and remarks. 1.2451 + 1.2452 + 1.2453 + 1.2454 + 1.2455 + 1.2456 + 1.2457 + 1.2458 + 1.2459 + 1.2460 + 1.2461 + 1.2462 + 1.2463 + 1.2464 + 1.2465 + 1.2466 + 1.2467 + 1.2468 + 1.2469 +Andersen, et al. Experimental [Page 44] 1.2470 + 1.2471 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2472 + 1.2473 + 1.2474 +APPENDIX A. Reference Implementation 1.2475 + 1.2476 + This appendix contains the complete c-code for a reference 1.2477 + implementation of encoder and decoder for the specified codec. 1.2478 + 1.2479 + The c-code consists of the following files with highest-level 1.2480 + functions: 1.2481 + 1.2482 + iLBC_test.c: main function for evaluation purpose 1.2483 + iLBC_encode.h: encoder header 1.2484 + iLBC_encode.c: encoder function 1.2485 + iLBC_decode.h: decoder header 1.2486 + iLBC_decode.c: decoder function 1.2487 + 1.2488 + The following files contain global defines and constants: 1.2489 + 1.2490 + iLBC_define.h: global defines 1.2491 + constants.h: global constants header 1.2492 + constants.c: global constants memory allocations 1.2493 + 1.2494 + The following files contain subroutines: 1.2495 + 1.2496 + anaFilter.h: lpc analysis filter header 1.2497 + anaFilter.c: lpc analysis filter function 1.2498 + createCB.h: codebook construction header 1.2499 + createCB.c: codebook construction function 1.2500 + doCPLC.h: packet loss concealment header 1.2501 + doCPLC.c: packet loss concealment function 1.2502 + enhancer.h: signal enhancement header 1.2503 + enhancer.c: signal enhancement function 1.2504 + filter.h: general filter header 1.2505 + filter.c: general filter functions 1.2506 + FrameClassify.h: start state classification header 1.2507 + FrameClassify.c: start state classification function 1.2508 + gainquant.h: gain quantization header 1.2509 + gainquant.c: gain quantization function 1.2510 + getCBvec.h: codebook vector construction header 1.2511 + getCBvec.c: codebook vector construction function 1.2512 + helpfun.h: general purpose header 1.2513 + helpfun.c: general purpose functions 1.2514 + hpInput.h: input high pass filter header 1.2515 + hpInput.c: input high pass filter function 1.2516 + hpOutput.h: output high pass filter header 1.2517 + hpOutput.c: output high pass filter function 1.2518 + iCBConstruct.h: excitation decoding header 1.2519 + iCBConstruct.c: excitation decoding function 1.2520 + iCBSearch.h: excitation encoding header 1.2521 + iCBSearch.c: excitation encoding function 1.2522 + 1.2523 + 1.2524 + 1.2525 +Andersen, et al. Experimental [Page 45] 1.2526 + 1.2527 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2528 + 1.2529 + 1.2530 + LPCdecode.h: lpc decoding header 1.2531 + LPCdecode.c: lpc decoding function 1.2532 + LPCencode.h: lpc encoding header 1.2533 + LPCencode.c: lpc encoding function 1.2534 + lsf.h: line spectral frequencies header 1.2535 + lsf.c: line spectral frequencies functions 1.2536 + packing.h: bitstream packetization header 1.2537 + packing.c: bitstream packetization functions 1.2538 + StateConstructW.h: state decoding header 1.2539 + StateConstructW.c: state decoding functions 1.2540 + StateSearchW.h: state encoding header 1.2541 + StateSearchW.c: state encoding function 1.2542 + syntFilter.h: lpc synthesis filter header 1.2543 + syntFilter.c: lpc synthesis filter function 1.2544 + 1.2545 + The implementation is portable and should work on many different 1.2546 + platforms. However, it is not difficult to optimize the 1.2547 + implementation on particular platforms, an exercise left to the 1.2548 + reader. 1.2549 + 1.2550 +A.1. iLBC_test.c 1.2551 + 1.2552 + /****************************************************************** 1.2553 + 1.2554 + iLBC Speech Coder ANSI-C Source Code 1.2555 + 1.2556 + iLBC_test.c 1.2557 + 1.2558 + Copyright (C) The Internet Society (2004). 1.2559 + All Rights Reserved. 1.2560 + 1.2561 + ******************************************************************/ 1.2562 + 1.2563 + #include <math.h> 1.2564 + #include <stdlib.h> 1.2565 + #include <stdio.h> 1.2566 + #include <string.h> 1.2567 + #include "iLBC_define.h" 1.2568 + #include "iLBC_encode.h" 1.2569 + #include "iLBC_decode.h" 1.2570 + 1.2571 + /* Runtime statistics */ 1.2572 + #include <time.h> 1.2573 + 1.2574 + #define ILBCNOOFWORDS_MAX (NO_OF_BYTES_30MS/2) 1.2575 + 1.2576 + /*----------------------------------------------------------------* 1.2577 + * Encoder interface function 1.2578 + 1.2579 + 1.2580 + 1.2581 +Andersen, et al. Experimental [Page 46] 1.2582 + 1.2583 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2584 + 1.2585 + 1.2586 + *---------------------------------------------------------------*/ 1.2587 + 1.2588 + short encode( /* (o) Number of bytes encoded */ 1.2589 + iLBC_Enc_Inst_t *iLBCenc_inst, 1.2590 + /* (i/o) Encoder instance */ 1.2591 + short *encoded_data, /* (o) The encoded bytes */ 1.2592 + short *data /* (i) The signal block to encode*/ 1.2593 + ){ 1.2594 + float block[BLOCKL_MAX]; 1.2595 + int k; 1.2596 + 1.2597 + /* convert signal to float */ 1.2598 + 1.2599 + for (k=0; k<iLBCenc_inst->blockl; k++) 1.2600 + block[k] = (float)data[k]; 1.2601 + 1.2602 + /* do the actual encoding */ 1.2603 + 1.2604 + iLBC_encode((unsigned char *)encoded_data, block, iLBCenc_inst); 1.2605 + 1.2606 + 1.2607 + return (iLBCenc_inst->no_of_bytes); 1.2608 + } 1.2609 + 1.2610 + /*----------------------------------------------------------------* 1.2611 + * Decoder interface function 1.2612 + *---------------------------------------------------------------*/ 1.2613 + 1.2614 + short decode( /* (o) Number of decoded samples */ 1.2615 + iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */ 1.2616 + short *decoded_data, /* (o) Decoded signal block*/ 1.2617 + short *encoded_data, /* (i) Encoded bytes */ 1.2618 + short mode /* (i) 0=PL, 1=Normal */ 1.2619 + ){ 1.2620 + int k; 1.2621 + float decblock[BLOCKL_MAX], dtmp; 1.2622 + 1.2623 + /* check if mode is valid */ 1.2624 + 1.2625 + if (mode<0 || mode>1) { 1.2626 + printf("\nERROR - Wrong mode - 0, 1 allowed\n"); exit(3);} 1.2627 + 1.2628 + /* do actual decoding of block */ 1.2629 + 1.2630 + iLBC_decode(decblock, (unsigned char *)encoded_data, 1.2631 + iLBCdec_inst, mode); 1.2632 + 1.2633 + /* convert to short */ 1.2634 + 1.2635 + 1.2636 + 1.2637 +Andersen, et al. Experimental [Page 47] 1.2638 + 1.2639 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2640 + 1.2641 + 1.2642 + for (k=0; k<iLBCdec_inst->blockl; k++){ 1.2643 + dtmp=decblock[k]; 1.2644 + 1.2645 + if (dtmp<MIN_SAMPLE) 1.2646 + dtmp=MIN_SAMPLE; 1.2647 + else if (dtmp>MAX_SAMPLE) 1.2648 + dtmp=MAX_SAMPLE; 1.2649 + decoded_data[k] = (short) dtmp; 1.2650 + } 1.2651 + 1.2652 + return (iLBCdec_inst->blockl); 1.2653 + } 1.2654 + 1.2655 + /*---------------------------------------------------------------* 1.2656 + * Main program to test iLBC encoding and decoding 1.2657 + * 1.2658 + * Usage: 1.2659 + * exefile_name.exe <infile> <bytefile> <outfile> <channel> 1.2660 + * 1.2661 + * <infile> : Input file, speech for encoder (16-bit pcm file) 1.2662 + * <bytefile> : Bit stream output from the encoder 1.2663 + * <outfile> : Output file, decoded speech (16-bit pcm file) 1.2664 + * <channel> : Bit error file, optional (16-bit) 1.2665 + * 1 - Packet received correctly 1.2666 + * 0 - Packet Lost 1.2667 + * 1.2668 + *--------------------------------------------------------------*/ 1.2669 + 1.2670 + int main(int argc, char* argv[]) 1.2671 + { 1.2672 + 1.2673 + /* Runtime statistics */ 1.2674 + 1.2675 + float starttime; 1.2676 + float runtime; 1.2677 + float outtime; 1.2678 + 1.2679 + FILE *ifileid,*efileid,*ofileid, *cfileid; 1.2680 + short data[BLOCKL_MAX]; 1.2681 + short encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX]; 1.2682 + int len; 1.2683 + short pli, mode; 1.2684 + int blockcount = 0; 1.2685 + int packetlosscount = 0; 1.2686 + 1.2687 + /* Create structs */ 1.2688 + iLBC_Enc_Inst_t Enc_Inst; 1.2689 + iLBC_Dec_Inst_t Dec_Inst; 1.2690 + 1.2691 + 1.2692 + 1.2693 +Andersen, et al. Experimental [Page 48] 1.2694 + 1.2695 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2696 + 1.2697 + 1.2698 + /* get arguments and open files */ 1.2699 + 1.2700 + if ((argc!=5) && (argc!=6)) { 1.2701 + fprintf(stderr, 1.2702 + "\n*-----------------------------------------------*\n"); 1.2703 + fprintf(stderr, 1.2704 + " %s <20,30> input encoded decoded (channel)\n\n", 1.2705 + argv[0]); 1.2706 + fprintf(stderr, 1.2707 + " mode : Frame size for the encoding/decoding\n"); 1.2708 + fprintf(stderr, 1.2709 + " 20 - 20 ms\n"); 1.2710 + fprintf(stderr, 1.2711 + " 30 - 30 ms\n"); 1.2712 + fprintf(stderr, 1.2713 + " input : Speech for encoder (16-bit pcm file)\n"); 1.2714 + fprintf(stderr, 1.2715 + " encoded : Encoded bit stream\n"); 1.2716 + fprintf(stderr, 1.2717 + " decoded : Decoded speech (16-bit pcm file)\n"); 1.2718 + fprintf(stderr, 1.2719 + " channel : Packet loss pattern, optional (16-bit)\n"); 1.2720 + fprintf(stderr, 1.2721 + " 1 - Packet received correctly\n"); 1.2722 + fprintf(stderr, 1.2723 + " 0 - Packet Lost\n"); 1.2724 + fprintf(stderr, 1.2725 + "*-----------------------------------------------*\n\n"); 1.2726 + exit(1); 1.2727 + } 1.2728 + mode=atoi(argv[1]); 1.2729 + if (mode != 20 && mode != 30) { 1.2730 + fprintf(stderr,"Wrong mode %s, must be 20, or 30\n", 1.2731 + argv[1]); 1.2732 + exit(2); 1.2733 + } 1.2734 + if ( (ifileid=fopen(argv[2],"rb")) == NULL) { 1.2735 + fprintf(stderr,"Cannot open input file %s\n", argv[2]); 1.2736 + exit(2);} 1.2737 + if ( (efileid=fopen(argv[3],"wb")) == NULL) { 1.2738 + fprintf(stderr, "Cannot open encoded file %s\n", 1.2739 + argv[3]); exit(1);} 1.2740 + if ( (ofileid=fopen(argv[4],"wb")) == NULL) { 1.2741 + fprintf(stderr, "Cannot open decoded file %s\n", 1.2742 + argv[4]); exit(1);} 1.2743 + if (argc==6) { 1.2744 + if( (cfileid=fopen(argv[5],"rb")) == NULL) { 1.2745 + fprintf(stderr, "Cannot open channel file %s\n", 1.2746 + 1.2747 + 1.2748 + 1.2749 +Andersen, et al. Experimental [Page 49] 1.2750 + 1.2751 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2752 + 1.2753 + 1.2754 + argv[5]); 1.2755 + exit(1); 1.2756 + } 1.2757 + } else { 1.2758 + cfileid=NULL; 1.2759 + } 1.2760 + 1.2761 + /* print info */ 1.2762 + 1.2763 + fprintf(stderr, "\n"); 1.2764 + fprintf(stderr, 1.2765 + "*---------------------------------------------------*\n"); 1.2766 + fprintf(stderr, 1.2767 + "* *\n"); 1.2768 + fprintf(stderr, 1.2769 + "* iLBC test program *\n"); 1.2770 + fprintf(stderr, 1.2771 + "* *\n"); 1.2772 + fprintf(stderr, 1.2773 + "* *\n"); 1.2774 + fprintf(stderr, 1.2775 + "*---------------------------------------------------*\n"); 1.2776 + fprintf(stderr,"\nMode : %2d ms\n", mode); 1.2777 + fprintf(stderr,"Input file : %s\n", argv[2]); 1.2778 + fprintf(stderr,"Encoded file : %s\n", argv[3]); 1.2779 + fprintf(stderr,"Output file : %s\n", argv[4]); 1.2780 + if (argc==6) { 1.2781 + fprintf(stderr,"Channel file : %s\n", argv[5]); 1.2782 + } 1.2783 + fprintf(stderr,"\n"); 1.2784 + 1.2785 + /* Initialization */ 1.2786 + 1.2787 + initEncode(&Enc_Inst, mode); 1.2788 + initDecode(&Dec_Inst, mode, 1); 1.2789 + 1.2790 + /* Runtime statistics */ 1.2791 + 1.2792 + starttime=clock()/(float)CLOCKS_PER_SEC; 1.2793 + 1.2794 + /* loop over input blocks */ 1.2795 + 1.2796 + while (fread(data,sizeof(short),Enc_Inst.blockl,ifileid)== 1.2797 + Enc_Inst.blockl) { 1.2798 + 1.2799 + blockcount++; 1.2800 + 1.2801 + /* encoding */ 1.2802 + 1.2803 + 1.2804 + 1.2805 +Andersen, et al. Experimental [Page 50] 1.2806 + 1.2807 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2808 + 1.2809 + 1.2810 + fprintf(stderr, "--- Encoding block %i --- ",blockcount); 1.2811 + len=encode(&Enc_Inst, encoded_data, data); 1.2812 + fprintf(stderr, "\r"); 1.2813 + 1.2814 + /* write byte file */ 1.2815 + 1.2816 + fwrite(encoded_data, sizeof(unsigned char), len, efileid); 1.2817 + 1.2818 + /* get channel data if provided */ 1.2819 + if (argc==6) { 1.2820 + if (fread(&pli, sizeof(short), 1, cfileid)) { 1.2821 + if ((pli!=0)&&(pli!=1)) { 1.2822 + fprintf(stderr, "Error in channel file\n"); 1.2823 + exit(0); 1.2824 + } 1.2825 + if (pli==0) { 1.2826 + /* Packet loss -> remove info from frame */ 1.2827 + memset(encoded_data, 0, 1.2828 + sizeof(short)*ILBCNOOFWORDS_MAX); 1.2829 + packetlosscount++; 1.2830 + } 1.2831 + } else { 1.2832 + fprintf(stderr, "Error. Channel file too short\n"); 1.2833 + exit(0); 1.2834 + } 1.2835 + } else { 1.2836 + pli=1; 1.2837 + } 1.2838 + 1.2839 + /* decoding */ 1.2840 + 1.2841 + fprintf(stderr, "--- Decoding block %i --- ",blockcount); 1.2842 + 1.2843 + len=decode(&Dec_Inst, decoded_data, encoded_data, pli); 1.2844 + fprintf(stderr, "\r"); 1.2845 + 1.2846 + /* write output file */ 1.2847 + 1.2848 + fwrite(decoded_data,sizeof(short),len,ofileid); 1.2849 + } 1.2850 + 1.2851 + /* Runtime statistics */ 1.2852 + 1.2853 + runtime = (float)(clock()/(float)CLOCKS_PER_SEC-starttime); 1.2854 + outtime = (float)((float)blockcount*(float)mode/1000.0); 1.2855 + printf("\n\nLength of speech file: %.1f s\n", outtime); 1.2856 + printf("Packet loss : %.1f%%\n", 1.2857 + 100.0*(float)packetlosscount/(float)blockcount); 1.2858 + 1.2859 + 1.2860 + 1.2861 +Andersen, et al. Experimental [Page 51] 1.2862 + 1.2863 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2864 + 1.2865 + 1.2866 + printf("Time to run iLBC :"); 1.2867 + printf(" %.1f s (%.1f %% of realtime)\n\n", runtime, 1.2868 + (100*runtime/outtime)); 1.2869 + 1.2870 + /* close files */ 1.2871 + 1.2872 + fclose(ifileid); fclose(efileid); fclose(ofileid); 1.2873 + if (argc==6) { 1.2874 + fclose(cfileid); 1.2875 + } 1.2876 + return(0); 1.2877 + } 1.2878 + 1.2879 +A.2. iLBC_encode.h 1.2880 + 1.2881 + /****************************************************************** 1.2882 + 1.2883 + iLBC Speech Coder ANSI-C Source Code 1.2884 + 1.2885 + iLBC_encode.h 1.2886 + 1.2887 + Copyright (C) The Internet Society (2004). 1.2888 + All Rights Reserved. 1.2889 + 1.2890 + ******************************************************************/ 1.2891 + 1.2892 + #ifndef __iLBC_ILBCENCODE_H 1.2893 + #define __iLBC_ILBCENCODE_H 1.2894 + 1.2895 + #include "iLBC_define.h" 1.2896 + 1.2897 + short initEncode( /* (o) Number of bytes 1.2898 + encoded */ 1.2899 + iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */ 1.2900 + int mode /* (i) frame size mode */ 1.2901 + ); 1.2902 + 1.2903 + void iLBC_encode( 1.2904 + 1.2905 + unsigned char *bytes, /* (o) encoded data bits iLBC */ 1.2906 + float *block, /* (o) speech vector to 1.2907 + encode */ 1.2908 + iLBC_Enc_Inst_t *iLBCenc_inst /* (i/o) the general encoder 1.2909 + state */ 1.2910 + ); 1.2911 + 1.2912 + #endif 1.2913 + 1.2914 + 1.2915 + 1.2916 + 1.2917 +Andersen, et al. Experimental [Page 52] 1.2918 + 1.2919 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2920 + 1.2921 + 1.2922 +A.3. iLBC_encode.c 1.2923 + 1.2924 + /****************************************************************** 1.2925 + 1.2926 + iLBC Speech Coder ANSI-C Source Code 1.2927 + 1.2928 + iLBC_encode.c 1.2929 + 1.2930 + Copyright (C) The Internet Society (2004). 1.2931 + All Rights Reserved. 1.2932 + 1.2933 + ******************************************************************/ 1.2934 + 1.2935 + #include <math.h> 1.2936 + #include <stdlib.h> 1.2937 + #include <string.h> 1.2938 + 1.2939 + #include "iLBC_define.h" 1.2940 + #include "LPCencode.h" 1.2941 + #include "FrameClassify.h" 1.2942 + #include "StateSearchW.h" 1.2943 + #include "StateConstructW.h" 1.2944 + #include "helpfun.h" 1.2945 + #include "constants.h" 1.2946 + #include "packing.h" 1.2947 + #include "iCBSearch.h" 1.2948 + #include "iCBConstruct.h" 1.2949 + #include "hpInput.h" 1.2950 + #include "anaFilter.h" 1.2951 + #include "syntFilter.h" 1.2952 + 1.2953 + /*----------------------------------------------------------------* 1.2954 + * Initiation of encoder instance. 1.2955 + *---------------------------------------------------------------*/ 1.2956 + 1.2957 + short initEncode( /* (o) Number of bytes 1.2958 + encoded */ 1.2959 + iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */ 1.2960 + int mode /* (i) frame size mode */ 1.2961 + ){ 1.2962 + iLBCenc_inst->mode = mode; 1.2963 + if (mode==30) { 1.2964 + iLBCenc_inst->blockl = BLOCKL_30MS; 1.2965 + iLBCenc_inst->nsub = NSUB_30MS; 1.2966 + iLBCenc_inst->nasub = NASUB_30MS; 1.2967 + iLBCenc_inst->lpc_n = LPC_N_30MS; 1.2968 + iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS; 1.2969 + iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS; 1.2970 + 1.2971 + 1.2972 + 1.2973 +Andersen, et al. Experimental [Page 53] 1.2974 + 1.2975 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.2976 + 1.2977 + 1.2978 + iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS; 1.2979 + /* ULP init */ 1.2980 + iLBCenc_inst->ULP_inst=&ULP_30msTbl; 1.2981 + } 1.2982 + else if (mode==20) { 1.2983 + iLBCenc_inst->blockl = BLOCKL_20MS; 1.2984 + iLBCenc_inst->nsub = NSUB_20MS; 1.2985 + iLBCenc_inst->nasub = NASUB_20MS; 1.2986 + iLBCenc_inst->lpc_n = LPC_N_20MS; 1.2987 + iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS; 1.2988 + iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS; 1.2989 + iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS; 1.2990 + /* ULP init */ 1.2991 + iLBCenc_inst->ULP_inst=&ULP_20msTbl; 1.2992 + } 1.2993 + else { 1.2994 + exit(2); 1.2995 + } 1.2996 + 1.2997 + memset((*iLBCenc_inst).anaMem, 0, 1.2998 + LPC_FILTERORDER*sizeof(float)); 1.2999 + memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl, 1.3000 + LPC_FILTERORDER*sizeof(float)); 1.3001 + memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl, 1.3002 + LPC_FILTERORDER*sizeof(float)); 1.3003 + memset((*iLBCenc_inst).lpc_buffer, 0, 1.3004 + (LPC_LOOKBACK+BLOCKL_MAX)*sizeof(float)); 1.3005 + memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float)); 1.3006 + 1.3007 + return (iLBCenc_inst->no_of_bytes); 1.3008 + } 1.3009 + 1.3010 + /*----------------------------------------------------------------* 1.3011 + * main encoder function 1.3012 + *---------------------------------------------------------------*/ 1.3013 + 1.3014 + void iLBC_encode( 1.3015 + unsigned char *bytes, /* (o) encoded data bits iLBC */ 1.3016 + float *block, /* (o) speech vector to 1.3017 + encode */ 1.3018 + iLBC_Enc_Inst_t *iLBCenc_inst /* (i/o) the general encoder 1.3019 + state */ 1.3020 + ){ 1.3021 + 1.3022 + float data[BLOCKL_MAX]; 1.3023 + float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX]; 1.3024 + 1.3025 + int start, idxForMax, idxVec[STATE_LEN]; 1.3026 + 1.3027 + 1.3028 + 1.3029 +Andersen, et al. Experimental [Page 54] 1.3030 + 1.3031 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3032 + 1.3033 + 1.3034 + float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML]; 1.3035 + int n, k, meml_gotten, Nfor, Nback, i, pos; 1.3036 + int gain_index[CB_NSTAGES*NASUB_MAX], 1.3037 + extra_gain_index[CB_NSTAGES]; 1.3038 + int cb_index[CB_NSTAGES*NASUB_MAX],extra_cb_index[CB_NSTAGES]; 1.3039 + int lsf_i[LSF_NSPLIT*LPC_N_MAX]; 1.3040 + unsigned char *pbytes; 1.3041 + int diff, start_pos, state_first; 1.3042 + float en1, en2; 1.3043 + int index, ulp, firstpart; 1.3044 + int subcount, subframe; 1.3045 + float weightState[LPC_FILTERORDER]; 1.3046 + float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; 1.3047 + float weightdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; 1.3048 + float decresidual[BLOCKL_MAX]; 1.3049 + 1.3050 + /* high pass filtering of input signal if such is not done 1.3051 + prior to calling this function */ 1.3052 + 1.3053 + hpInput(block, iLBCenc_inst->blockl, 1.3054 + data, (*iLBCenc_inst).hpimem); 1.3055 + 1.3056 + /* otherwise simply copy */ 1.3057 + 1.3058 + /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float));*/ 1.3059 + 1.3060 + /* LPC of hp filtered input data */ 1.3061 + 1.3062 + LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst); 1.3063 + 1.3064 + 1.3065 + /* inverse filter to get residual */ 1.3066 + 1.3067 + for (n=0; n<iLBCenc_inst->nsub; n++) { 1.3068 + anaFilter(&data[n*SUBL], &syntdenum[n*(LPC_FILTERORDER+1)], 1.3069 + SUBL, &residual[n*SUBL], iLBCenc_inst->anaMem); 1.3070 + } 1.3071 + 1.3072 + /* find state location */ 1.3073 + 1.3074 + start = FrameClassify(iLBCenc_inst, residual); 1.3075 + 1.3076 + /* check if state should be in first or last part of the 1.3077 + two subframes */ 1.3078 + 1.3079 + diff = STATE_LEN - iLBCenc_inst->state_short_len; 1.3080 + en1 = 0; 1.3081 + index = (start-1)*SUBL; 1.3082 + 1.3083 + 1.3084 + 1.3085 +Andersen, et al. Experimental [Page 55] 1.3086 + 1.3087 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3088 + 1.3089 + 1.3090 + for (i = 0; i < iLBCenc_inst->state_short_len; i++) { 1.3091 + en1 += residual[index+i]*residual[index+i]; 1.3092 + } 1.3093 + en2 = 0; 1.3094 + index = (start-1)*SUBL+diff; 1.3095 + for (i = 0; i < iLBCenc_inst->state_short_len; i++) { 1.3096 + en2 += residual[index+i]*residual[index+i]; 1.3097 + } 1.3098 + 1.3099 + 1.3100 + if (en1 > en2) { 1.3101 + state_first = 1; 1.3102 + start_pos = (start-1)*SUBL; 1.3103 + } else { 1.3104 + state_first = 0; 1.3105 + start_pos = (start-1)*SUBL + diff; 1.3106 + } 1.3107 + 1.3108 + /* scalar quantization of state */ 1.3109 + 1.3110 + StateSearchW(iLBCenc_inst, &residual[start_pos], 1.3111 + &syntdenum[(start-1)*(LPC_FILTERORDER+1)], 1.3112 + &weightdenum[(start-1)*(LPC_FILTERORDER+1)], &idxForMax, 1.3113 + idxVec, iLBCenc_inst->state_short_len, state_first); 1.3114 + 1.3115 + StateConstructW(idxForMax, idxVec, 1.3116 + &syntdenum[(start-1)*(LPC_FILTERORDER+1)], 1.3117 + &decresidual[start_pos], iLBCenc_inst->state_short_len); 1.3118 + 1.3119 + /* predictive quantization in state */ 1.3120 + 1.3121 + if (state_first) { /* put adaptive part in the end */ 1.3122 + 1.3123 + /* setup memory */ 1.3124 + 1.3125 + memset(mem, 0, 1.3126 + (CB_MEML-iLBCenc_inst->state_short_len)*sizeof(float)); 1.3127 + memcpy(mem+CB_MEML-iLBCenc_inst->state_short_len, 1.3128 + decresidual+start_pos, 1.3129 + iLBCenc_inst->state_short_len*sizeof(float)); 1.3130 + memset(weightState, 0, LPC_FILTERORDER*sizeof(float)); 1.3131 + 1.3132 + /* encode sub-frames */ 1.3133 + 1.3134 + iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, 1.3135 + &residual[start_pos+iLBCenc_inst->state_short_len], 1.3136 + mem+CB_MEML-stMemLTbl, 1.3137 + stMemLTbl, diff, CB_NSTAGES, 1.3138 + 1.3139 + 1.3140 + 1.3141 +Andersen, et al. Experimental [Page 56] 1.3142 + 1.3143 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3144 + 1.3145 + 1.3146 + &weightdenum[start*(LPC_FILTERORDER+1)], 1.3147 + weightState, 0); 1.3148 + 1.3149 + /* construct decoded vector */ 1.3150 + 1.3151 + iCBConstruct( 1.3152 + &decresidual[start_pos+iLBCenc_inst->state_short_len], 1.3153 + extra_cb_index, extra_gain_index, 1.3154 + mem+CB_MEML-stMemLTbl, 1.3155 + stMemLTbl, diff, CB_NSTAGES); 1.3156 + 1.3157 + } 1.3158 + else { /* put adaptive part in the beginning */ 1.3159 + 1.3160 + /* create reversed vectors for prediction */ 1.3161 + 1.3162 + for (k=0; k<diff; k++) { 1.3163 + reverseResidual[k] = residual[(start+1)*SUBL-1 1.3164 + -(k+iLBCenc_inst->state_short_len)]; 1.3165 + } 1.3166 + 1.3167 + /* setup memory */ 1.3168 + 1.3169 + meml_gotten = iLBCenc_inst->state_short_len; 1.3170 + for (k=0; k<meml_gotten; k++) { 1.3171 + mem[CB_MEML-1-k] = decresidual[start_pos + k]; 1.3172 + } 1.3173 + memset(mem, 0, (CB_MEML-k)*sizeof(float)); 1.3174 + memset(weightState, 0, LPC_FILTERORDER*sizeof(float)); 1.3175 + 1.3176 + /* encode sub-frames */ 1.3177 + 1.3178 + iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, 1.3179 + reverseResidual, mem+CB_MEML-stMemLTbl, stMemLTbl, 1.3180 + diff, CB_NSTAGES, 1.3181 + &weightdenum[(start-1)*(LPC_FILTERORDER+1)], 1.3182 + weightState, 0); 1.3183 + 1.3184 + /* construct decoded vector */ 1.3185 + 1.3186 + iCBConstruct(reverseDecresidual, extra_cb_index, 1.3187 + extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl, 1.3188 + diff, CB_NSTAGES); 1.3189 + 1.3190 + /* get decoded residual from reversed vector */ 1.3191 + 1.3192 + for (k=0; k<diff; k++) { 1.3193 + decresidual[start_pos-1-k] = reverseDecresidual[k]; 1.3194 + 1.3195 + 1.3196 + 1.3197 +Andersen, et al. Experimental [Page 57] 1.3198 + 1.3199 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3200 + 1.3201 + 1.3202 + } 1.3203 + } 1.3204 + 1.3205 + /* counter for predicted sub-frames */ 1.3206 + 1.3207 + subcount=0; 1.3208 + 1.3209 + /* forward prediction of sub-frames */ 1.3210 + 1.3211 + Nfor = iLBCenc_inst->nsub-start-1; 1.3212 + 1.3213 + 1.3214 + if ( Nfor > 0 ) { 1.3215 + 1.3216 + /* setup memory */ 1.3217 + 1.3218 + memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float)); 1.3219 + memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, 1.3220 + STATE_LEN*sizeof(float)); 1.3221 + memset(weightState, 0, LPC_FILTERORDER*sizeof(float)); 1.3222 + 1.3223 + /* loop over sub-frames to encode */ 1.3224 + 1.3225 + for (subframe=0; subframe<Nfor; subframe++) { 1.3226 + 1.3227 + /* encode sub-frame */ 1.3228 + 1.3229 + iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, 1.3230 + gain_index+subcount*CB_NSTAGES, 1.3231 + &residual[(start+1+subframe)*SUBL], 1.3232 + mem+CB_MEML-memLfTbl[subcount], 1.3233 + memLfTbl[subcount], SUBL, CB_NSTAGES, 1.3234 + &weightdenum[(start+1+subframe)* 1.3235 + (LPC_FILTERORDER+1)], 1.3236 + weightState, subcount+1); 1.3237 + 1.3238 + /* construct decoded vector */ 1.3239 + 1.3240 + iCBConstruct(&decresidual[(start+1+subframe)*SUBL], 1.3241 + cb_index+subcount*CB_NSTAGES, 1.3242 + gain_index+subcount*CB_NSTAGES, 1.3243 + mem+CB_MEML-memLfTbl[subcount], 1.3244 + memLfTbl[subcount], SUBL, CB_NSTAGES); 1.3245 + 1.3246 + /* update memory */ 1.3247 + 1.3248 + memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float)); 1.3249 + memcpy(mem+CB_MEML-SUBL, 1.3250 + 1.3251 + 1.3252 + 1.3253 +Andersen, et al. Experimental [Page 58] 1.3254 + 1.3255 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3256 + 1.3257 + 1.3258 + &decresidual[(start+1+subframe)*SUBL], 1.3259 + SUBL*sizeof(float)); 1.3260 + memset(weightState, 0, LPC_FILTERORDER*sizeof(float)); 1.3261 + 1.3262 + subcount++; 1.3263 + } 1.3264 + } 1.3265 + 1.3266 + 1.3267 + /* backward prediction of sub-frames */ 1.3268 + 1.3269 + Nback = start-1; 1.3270 + 1.3271 + 1.3272 + if ( Nback > 0 ) { 1.3273 + 1.3274 + /* create reverse order vectors */ 1.3275 + 1.3276 + for (n=0; n<Nback; n++) { 1.3277 + for (k=0; k<SUBL; k++) { 1.3278 + reverseResidual[n*SUBL+k] = 1.3279 + residual[(start-1)*SUBL-1-n*SUBL-k]; 1.3280 + reverseDecresidual[n*SUBL+k] = 1.3281 + decresidual[(start-1)*SUBL-1-n*SUBL-k]; 1.3282 + } 1.3283 + } 1.3284 + 1.3285 + /* setup memory */ 1.3286 + 1.3287 + meml_gotten = SUBL*(iLBCenc_inst->nsub+1-start); 1.3288 + 1.3289 + 1.3290 + if ( meml_gotten > CB_MEML ) { 1.3291 + meml_gotten=CB_MEML; 1.3292 + } 1.3293 + for (k=0; k<meml_gotten; k++) { 1.3294 + mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k]; 1.3295 + } 1.3296 + memset(mem, 0, (CB_MEML-k)*sizeof(float)); 1.3297 + memset(weightState, 0, LPC_FILTERORDER*sizeof(float)); 1.3298 + 1.3299 + /* loop over sub-frames to encode */ 1.3300 + 1.3301 + for (subframe=0; subframe<Nback; subframe++) { 1.3302 + 1.3303 + /* encode sub-frame */ 1.3304 + 1.3305 + iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES, 1.3306 + 1.3307 + 1.3308 + 1.3309 +Andersen, et al. Experimental [Page 59] 1.3310 + 1.3311 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3312 + 1.3313 + 1.3314 + gain_index+subcount*CB_NSTAGES, 1.3315 + &reverseResidual[subframe*SUBL], 1.3316 + mem+CB_MEML-memLfTbl[subcount], 1.3317 + memLfTbl[subcount], SUBL, CB_NSTAGES, 1.3318 + &weightdenum[(start-2-subframe)* 1.3319 + (LPC_FILTERORDER+1)], 1.3320 + weightState, subcount+1); 1.3321 + 1.3322 + /* construct decoded vector */ 1.3323 + 1.3324 + iCBConstruct(&reverseDecresidual[subframe*SUBL], 1.3325 + cb_index+subcount*CB_NSTAGES, 1.3326 + gain_index+subcount*CB_NSTAGES, 1.3327 + mem+CB_MEML-memLfTbl[subcount], 1.3328 + memLfTbl[subcount], SUBL, CB_NSTAGES); 1.3329 + 1.3330 + /* update memory */ 1.3331 + 1.3332 + memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float)); 1.3333 + memcpy(mem+CB_MEML-SUBL, 1.3334 + &reverseDecresidual[subframe*SUBL], 1.3335 + SUBL*sizeof(float)); 1.3336 + memset(weightState, 0, LPC_FILTERORDER*sizeof(float)); 1.3337 + 1.3338 + subcount++; 1.3339 + 1.3340 + } 1.3341 + 1.3342 + /* get decoded residual from reversed vector */ 1.3343 + 1.3344 + for (i=0; i<SUBL*Nback; i++) { 1.3345 + decresidual[SUBL*Nback - i - 1] = 1.3346 + reverseDecresidual[i]; 1.3347 + } 1.3348 + } 1.3349 + /* end encoding part */ 1.3350 + 1.3351 + /* adjust index */ 1.3352 + index_conv_enc(cb_index); 1.3353 + 1.3354 + /* pack bytes */ 1.3355 + 1.3356 + pbytes=bytes; 1.3357 + pos=0; 1.3358 + 1.3359 + /* loop over the 3 ULP classes */ 1.3360 + 1.3361 + for (ulp=0; ulp<3; ulp++) { 1.3362 + 1.3363 + 1.3364 + 1.3365 +Andersen, et al. Experimental [Page 60] 1.3366 + 1.3367 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3368 + 1.3369 + 1.3370 + 1.3371 + /* LSF */ 1.3372 + for (k=0; k<LSF_NSPLIT*iLBCenc_inst->lpc_n; k++) { 1.3373 + packsplit(&lsf_i[k], &firstpart, &lsf_i[k], 1.3374 + iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], 1.3375 + iLBCenc_inst->ULP_inst->lsf_bits[k][ulp]+ 1.3376 + iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+1]+ 1.3377 + iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+2]); 1.3378 + dopack( &pbytes, firstpart, 1.3379 + iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos); 1.3380 + } 1.3381 + 1.3382 + /* Start block info */ 1.3383 + 1.3384 + packsplit(&start, &firstpart, &start, 1.3385 + iLBCenc_inst->ULP_inst->start_bits[ulp], 1.3386 + iLBCenc_inst->ULP_inst->start_bits[ulp]+ 1.3387 + iLBCenc_inst->ULP_inst->start_bits[ulp+1]+ 1.3388 + iLBCenc_inst->ULP_inst->start_bits[ulp+2]); 1.3389 + dopack( &pbytes, firstpart, 1.3390 + iLBCenc_inst->ULP_inst->start_bits[ulp], &pos); 1.3391 + 1.3392 + packsplit(&state_first, &firstpart, &state_first, 1.3393 + iLBCenc_inst->ULP_inst->startfirst_bits[ulp], 1.3394 + iLBCenc_inst->ULP_inst->startfirst_bits[ulp]+ 1.3395 + iLBCenc_inst->ULP_inst->startfirst_bits[ulp+1]+ 1.3396 + iLBCenc_inst->ULP_inst->startfirst_bits[ulp+2]); 1.3397 + dopack( &pbytes, firstpart, 1.3398 + iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos); 1.3399 + 1.3400 + packsplit(&idxForMax, &firstpart, &idxForMax, 1.3401 + iLBCenc_inst->ULP_inst->scale_bits[ulp], 1.3402 + iLBCenc_inst->ULP_inst->scale_bits[ulp]+ 1.3403 + iLBCenc_inst->ULP_inst->scale_bits[ulp+1]+ 1.3404 + iLBCenc_inst->ULP_inst->scale_bits[ulp+2]); 1.3405 + dopack( &pbytes, firstpart, 1.3406 + iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos); 1.3407 + 1.3408 + for (k=0; k<iLBCenc_inst->state_short_len; k++) { 1.3409 + packsplit(idxVec+k, &firstpart, idxVec+k, 1.3410 + iLBCenc_inst->ULP_inst->state_bits[ulp], 1.3411 + iLBCenc_inst->ULP_inst->state_bits[ulp]+ 1.3412 + iLBCenc_inst->ULP_inst->state_bits[ulp+1]+ 1.3413 + iLBCenc_inst->ULP_inst->state_bits[ulp+2]); 1.3414 + dopack( &pbytes, firstpart, 1.3415 + iLBCenc_inst->ULP_inst->state_bits[ulp], &pos); 1.3416 + } 1.3417 + 1.3418 + 1.3419 + 1.3420 + 1.3421 +Andersen, et al. Experimental [Page 61] 1.3422 + 1.3423 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3424 + 1.3425 + 1.3426 + /* 23/22 (20ms/30ms) sample block */ 1.3427 + 1.3428 + for (k=0;k<CB_NSTAGES;k++) { 1.3429 + packsplit(extra_cb_index+k, &firstpart, 1.3430 + extra_cb_index+k, 1.3431 + iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], 1.3432 + iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp]+ 1.3433 + iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+1]+ 1.3434 + iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+2]); 1.3435 + dopack( &pbytes, firstpart, 1.3436 + iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], 1.3437 + &pos); 1.3438 + } 1.3439 + 1.3440 + for (k=0;k<CB_NSTAGES;k++) { 1.3441 + packsplit(extra_gain_index+k, &firstpart, 1.3442 + extra_gain_index+k, 1.3443 + iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], 1.3444 + iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp]+ 1.3445 + iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+1]+ 1.3446 + iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+2]); 1.3447 + dopack( &pbytes, firstpart, 1.3448 + iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], 1.3449 + &pos); 1.3450 + } 1.3451 + 1.3452 + /* The two/four (20ms/30ms) 40 sample sub-blocks */ 1.3453 + 1.3454 + for (i=0; i<iLBCenc_inst->nasub; i++) { 1.3455 + for (k=0; k<CB_NSTAGES; k++) { 1.3456 + packsplit(cb_index+i*CB_NSTAGES+k, &firstpart, 1.3457 + cb_index+i*CB_NSTAGES+k, 1.3458 + iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], 1.3459 + iLBCenc_inst->ULP_inst->cb_index[i][k][ulp]+ 1.3460 + iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+1]+ 1.3461 + iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+2]); 1.3462 + dopack( &pbytes, firstpart, 1.3463 + iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], 1.3464 + &pos); 1.3465 + } 1.3466 + } 1.3467 + 1.3468 + for (i=0; i<iLBCenc_inst->nasub; i++) { 1.3469 + for (k=0; k<CB_NSTAGES; k++) { 1.3470 + packsplit(gain_index+i*CB_NSTAGES+k, &firstpart, 1.3471 + gain_index+i*CB_NSTAGES+k, 1.3472 + iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], 1.3473 + iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp]+ 1.3474 + 1.3475 + 1.3476 + 1.3477 +Andersen, et al. Experimental [Page 62] 1.3478 + 1.3479 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3480 + 1.3481 + 1.3482 + iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+1]+ 1.3483 + iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+2]); 1.3484 + dopack( &pbytes, firstpart, 1.3485 + iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], 1.3486 + &pos); 1.3487 + } 1.3488 + } 1.3489 + } 1.3490 + 1.3491 + /* set the last bit to zero (otherwise the decoder 1.3492 + will treat it as a lost frame) */ 1.3493 + dopack( &pbytes, 0, 1, &pos); 1.3494 + } 1.3495 + 1.3496 +A.4. iLBC_decode.h 1.3497 + 1.3498 + /****************************************************************** 1.3499 + 1.3500 + iLBC Speech Coder ANSI-C Source Code 1.3501 + 1.3502 + iLBC_decode.h 1.3503 + 1.3504 + Copyright (C) The Internet Society (2004). 1.3505 + All Rights Reserved. 1.3506 + 1.3507 + ******************************************************************/ 1.3508 + 1.3509 + #ifndef __iLBC_ILBCDECODE_H 1.3510 + #define __iLBC_ILBCDECODE_H 1.3511 + 1.3512 + #include "iLBC_define.h" 1.3513 + 1.3514 + short initDecode( /* (o) Number of decoded 1.3515 + samples */ 1.3516 + iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */ 1.3517 + int mode, /* (i) frame size mode */ 1.3518 + int use_enhancer /* (i) 1 to use enhancer 1.3519 + 0 to run without 1.3520 + enhancer */ 1.3521 + ); 1.3522 + 1.3523 + void iLBC_decode( 1.3524 + float *decblock, /* (o) decoded signal block */ 1.3525 + unsigned char *bytes, /* (i) encoded signal bits */ 1.3526 + iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state 1.3527 + structure */ 1.3528 + int mode /* (i) 0: bad packet, PLC, 1.3529 + 1: normal */ 1.3530 + 1.3531 + 1.3532 + 1.3533 +Andersen, et al. Experimental [Page 63] 1.3534 + 1.3535 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3536 + 1.3537 + 1.3538 + ); 1.3539 + 1.3540 + #endif 1.3541 + 1.3542 +A.5. iLBC_decode.c 1.3543 + 1.3544 + /****************************************************************** 1.3545 + 1.3546 + iLBC Speech Coder ANSI-C Source Code 1.3547 + 1.3548 + iLBC_decode.c 1.3549 + 1.3550 + Copyright (C) The Internet Society (2004). 1.3551 + All Rights Reserved. 1.3552 + 1.3553 + ******************************************************************/ 1.3554 + 1.3555 + #include <math.h> 1.3556 + #include <stdlib.h> 1.3557 + 1.3558 + #include "iLBC_define.h" 1.3559 + #include "StateConstructW.h" 1.3560 + #include "LPCdecode.h" 1.3561 + #include "iCBConstruct.h" 1.3562 + #include "doCPLC.h" 1.3563 + #include "helpfun.h" 1.3564 + #include "constants.h" 1.3565 + #include "packing.h" 1.3566 + #include "string.h" 1.3567 + #include "enhancer.h" 1.3568 + #include "hpOutput.h" 1.3569 + #include "syntFilter.h" 1.3570 + 1.3571 + /*----------------------------------------------------------------* 1.3572 + * Initiation of decoder instance. 1.3573 + *---------------------------------------------------------------*/ 1.3574 + 1.3575 + short initDecode( /* (o) Number of decoded 1.3576 + samples */ 1.3577 + iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */ 1.3578 + int mode, /* (i) frame size mode */ 1.3579 + int use_enhancer /* (i) 1 to use enhancer 1.3580 + 0 to run without 1.3581 + enhancer */ 1.3582 + ){ 1.3583 + int i; 1.3584 + 1.3585 + iLBCdec_inst->mode = mode; 1.3586 + 1.3587 + 1.3588 + 1.3589 +Andersen, et al. Experimental [Page 64] 1.3590 + 1.3591 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3592 + 1.3593 + 1.3594 + if (mode==30) { 1.3595 + iLBCdec_inst->blockl = BLOCKL_30MS; 1.3596 + iLBCdec_inst->nsub = NSUB_30MS; 1.3597 + iLBCdec_inst->nasub = NASUB_30MS; 1.3598 + iLBCdec_inst->lpc_n = LPC_N_30MS; 1.3599 + iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS; 1.3600 + iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS; 1.3601 + iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS; 1.3602 + /* ULP init */ 1.3603 + iLBCdec_inst->ULP_inst=&ULP_30msTbl; 1.3604 + } 1.3605 + else if (mode==20) { 1.3606 + iLBCdec_inst->blockl = BLOCKL_20MS; 1.3607 + iLBCdec_inst->nsub = NSUB_20MS; 1.3608 + iLBCdec_inst->nasub = NASUB_20MS; 1.3609 + iLBCdec_inst->lpc_n = LPC_N_20MS; 1.3610 + iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS; 1.3611 + iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS; 1.3612 + iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS; 1.3613 + /* ULP init */ 1.3614 + iLBCdec_inst->ULP_inst=&ULP_20msTbl; 1.3615 + } 1.3616 + else { 1.3617 + exit(2); 1.3618 + } 1.3619 + 1.3620 + memset(iLBCdec_inst->syntMem, 0, 1.3621 + LPC_FILTERORDER*sizeof(float)); 1.3622 + memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl, 1.3623 + LPC_FILTERORDER*sizeof(float)); 1.3624 + 1.3625 + memset(iLBCdec_inst->old_syntdenum, 0, 1.3626 + ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float)); 1.3627 + for (i=0; i<NSUB_MAX; i++) 1.3628 + iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)]=1.0; 1.3629 + 1.3630 + iLBCdec_inst->last_lag = 20; 1.3631 + 1.3632 + iLBCdec_inst->prevLag = 120; 1.3633 + iLBCdec_inst->per = 0.0; 1.3634 + iLBCdec_inst->consPLICount = 0; 1.3635 + iLBCdec_inst->prevPLI = 0; 1.3636 + iLBCdec_inst->prevLpc[0] = 1.0; 1.3637 + memset(iLBCdec_inst->prevLpc+1,0, 1.3638 + LPC_FILTERORDER*sizeof(float)); 1.3639 + memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float)); 1.3640 + iLBCdec_inst->seed=777; 1.3641 + 1.3642 + 1.3643 + 1.3644 + 1.3645 +Andersen, et al. Experimental [Page 65] 1.3646 + 1.3647 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3648 + 1.3649 + 1.3650 + memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float)); 1.3651 + 1.3652 + iLBCdec_inst->use_enhancer = use_enhancer; 1.3653 + memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float)); 1.3654 + for (i=0;i<ENH_NBLOCKS_TOT;i++) 1.3655 + iLBCdec_inst->enh_period[i]=(float)40.0; 1.3656 + 1.3657 + iLBCdec_inst->prev_enh_pl = 0; 1.3658 + 1.3659 + return (iLBCdec_inst->blockl); 1.3660 + } 1.3661 + 1.3662 + /*----------------------------------------------------------------* 1.3663 + * frame residual decoder function (subrutine to iLBC_decode) 1.3664 + *---------------------------------------------------------------*/ 1.3665 + 1.3666 + void Decode( 1.3667 + iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state 1.3668 + structure */ 1.3669 + float *decresidual, /* (o) decoded residual frame */ 1.3670 + int start, /* (i) location of start 1.3671 + state */ 1.3672 + int idxForMax, /* (i) codebook index for the 1.3673 + maximum value */ 1.3674 + int *idxVec, /* (i) codebook indexes for the 1.3675 + samples in the start 1.3676 + state */ 1.3677 + float *syntdenum, /* (i) the decoded synthesis 1.3678 + filter coefficients */ 1.3679 + int *cb_index, /* (i) the indexes for the 1.3680 + adaptive codebook */ 1.3681 + int *gain_index, /* (i) the indexes for the 1.3682 + corresponding gains */ 1.3683 + int *extra_cb_index, /* (i) the indexes for the 1.3684 + adaptive codebook part 1.3685 + of start state */ 1.3686 + int *extra_gain_index, /* (i) the indexes for the 1.3687 + corresponding gains */ 1.3688 + int state_first /* (i) 1 if non adaptive part 1.3689 + of start state comes 1.3690 + first 0 if that part 1.3691 + comes last */ 1.3692 + ){ 1.3693 + float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML]; 1.3694 + int k, meml_gotten, Nfor, Nback, i; 1.3695 + int diff, start_pos; 1.3696 + int subcount, subframe; 1.3697 + 1.3698 + 1.3699 + 1.3700 + 1.3701 +Andersen, et al. Experimental [Page 66] 1.3702 + 1.3703 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3704 + 1.3705 + 1.3706 + diff = STATE_LEN - iLBCdec_inst->state_short_len; 1.3707 + 1.3708 + if (state_first == 1) { 1.3709 + start_pos = (start-1)*SUBL; 1.3710 + } else { 1.3711 + start_pos = (start-1)*SUBL + diff; 1.3712 + } 1.3713 + 1.3714 + /* decode scalar part of start state */ 1.3715 + 1.3716 + StateConstructW(idxForMax, idxVec, 1.3717 + &syntdenum[(start-1)*(LPC_FILTERORDER+1)], 1.3718 + &decresidual[start_pos], iLBCdec_inst->state_short_len); 1.3719 + 1.3720 + 1.3721 + if (state_first) { /* put adaptive part in the end */ 1.3722 + 1.3723 + /* setup memory */ 1.3724 + 1.3725 + memset(mem, 0, 1.3726 + (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float)); 1.3727 + memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len, 1.3728 + decresidual+start_pos, 1.3729 + iLBCdec_inst->state_short_len*sizeof(float)); 1.3730 + 1.3731 + /* construct decoded vector */ 1.3732 + 1.3733 + iCBConstruct( 1.3734 + &decresidual[start_pos+iLBCdec_inst->state_short_len], 1.3735 + extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl, 1.3736 + stMemLTbl, diff, CB_NSTAGES); 1.3737 + 1.3738 + } 1.3739 + else {/* put adaptive part in the beginning */ 1.3740 + 1.3741 + /* create reversed vectors for prediction */ 1.3742 + 1.3743 + for (k=0; k<diff; k++) { 1.3744 + reverseDecresidual[k] = 1.3745 + decresidual[(start+1)*SUBL-1- 1.3746 + (k+iLBCdec_inst->state_short_len)]; 1.3747 + } 1.3748 + 1.3749 + /* setup memory */ 1.3750 + 1.3751 + meml_gotten = iLBCdec_inst->state_short_len; 1.3752 + for (k=0; k<meml_gotten; k++){ 1.3753 + mem[CB_MEML-1-k] = decresidual[start_pos + k]; 1.3754 + 1.3755 + 1.3756 + 1.3757 +Andersen, et al. Experimental [Page 67] 1.3758 + 1.3759 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3760 + 1.3761 + 1.3762 + } 1.3763 + memset(mem, 0, (CB_MEML-k)*sizeof(float)); 1.3764 + 1.3765 + /* construct decoded vector */ 1.3766 + 1.3767 + iCBConstruct(reverseDecresidual, extra_cb_index, 1.3768 + extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl, 1.3769 + diff, CB_NSTAGES); 1.3770 + 1.3771 + /* get decoded residual from reversed vector */ 1.3772 + 1.3773 + for (k=0; k<diff; k++) { 1.3774 + decresidual[start_pos-1-k] = reverseDecresidual[k]; 1.3775 + } 1.3776 + } 1.3777 + 1.3778 + /* counter for predicted sub-frames */ 1.3779 + 1.3780 + subcount=0; 1.3781 + 1.3782 + /* forward prediction of sub-frames */ 1.3783 + 1.3784 + Nfor = iLBCdec_inst->nsub-start-1; 1.3785 + 1.3786 + if ( Nfor > 0 ){ 1.3787 + 1.3788 + /* setup memory */ 1.3789 + 1.3790 + memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float)); 1.3791 + memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, 1.3792 + STATE_LEN*sizeof(float)); 1.3793 + 1.3794 + /* loop over sub-frames to encode */ 1.3795 + 1.3796 + for (subframe=0; subframe<Nfor; subframe++) { 1.3797 + 1.3798 + /* construct decoded vector */ 1.3799 + 1.3800 + iCBConstruct(&decresidual[(start+1+subframe)*SUBL], 1.3801 + cb_index+subcount*CB_NSTAGES, 1.3802 + gain_index+subcount*CB_NSTAGES, 1.3803 + mem+CB_MEML-memLfTbl[subcount], 1.3804 + memLfTbl[subcount], SUBL, CB_NSTAGES); 1.3805 + 1.3806 + /* update memory */ 1.3807 + 1.3808 + memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float)); 1.3809 + memcpy(mem+CB_MEML-SUBL, 1.3810 + 1.3811 + 1.3812 + 1.3813 +Andersen, et al. Experimental [Page 68] 1.3814 + 1.3815 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3816 + 1.3817 + 1.3818 + &decresidual[(start+1+subframe)*SUBL], 1.3819 + SUBL*sizeof(float)); 1.3820 + 1.3821 + subcount++; 1.3822 + 1.3823 + } 1.3824 + 1.3825 + } 1.3826 + 1.3827 + /* backward prediction of sub-frames */ 1.3828 + 1.3829 + Nback = start-1; 1.3830 + 1.3831 + if ( Nback > 0 ) { 1.3832 + 1.3833 + /* setup memory */ 1.3834 + 1.3835 + meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start); 1.3836 + 1.3837 + if ( meml_gotten > CB_MEML ) { 1.3838 + meml_gotten=CB_MEML; 1.3839 + } 1.3840 + for (k=0; k<meml_gotten; k++) { 1.3841 + mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k]; 1.3842 + } 1.3843 + memset(mem, 0, (CB_MEML-k)*sizeof(float)); 1.3844 + 1.3845 + /* loop over subframes to decode */ 1.3846 + 1.3847 + for (subframe=0; subframe<Nback; subframe++) { 1.3848 + 1.3849 + /* construct decoded vector */ 1.3850 + 1.3851 + iCBConstruct(&reverseDecresidual[subframe*SUBL], 1.3852 + cb_index+subcount*CB_NSTAGES, 1.3853 + gain_index+subcount*CB_NSTAGES, 1.3854 + mem+CB_MEML-memLfTbl[subcount], memLfTbl[subcount], 1.3855 + SUBL, CB_NSTAGES); 1.3856 + 1.3857 + /* update memory */ 1.3858 + 1.3859 + memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float)); 1.3860 + memcpy(mem+CB_MEML-SUBL, 1.3861 + &reverseDecresidual[subframe*SUBL], 1.3862 + SUBL*sizeof(float)); 1.3863 + 1.3864 + subcount++; 1.3865 + } 1.3866 + 1.3867 + 1.3868 + 1.3869 +Andersen, et al. Experimental [Page 69] 1.3870 + 1.3871 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3872 + 1.3873 + 1.3874 + /* get decoded residual from reversed vector */ 1.3875 + 1.3876 + for (i=0; i<SUBL*Nback; i++) 1.3877 + decresidual[SUBL*Nback - i - 1] = 1.3878 + reverseDecresidual[i]; 1.3879 + } 1.3880 + } 1.3881 + 1.3882 + /*----------------------------------------------------------------* 1.3883 + * main decoder function 1.3884 + *---------------------------------------------------------------*/ 1.3885 + 1.3886 + void iLBC_decode( 1.3887 + float *decblock, /* (o) decoded signal block */ 1.3888 + unsigned char *bytes, /* (i) encoded signal bits */ 1.3889 + iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state 1.3890 + structure */ 1.3891 + int mode /* (i) 0: bad packet, PLC, 1.3892 + 1: normal */ 1.3893 + ){ 1.3894 + float data[BLOCKL_MAX]; 1.3895 + float lsfdeq[LPC_FILTERORDER*LPC_N_MAX]; 1.3896 + float PLCresidual[BLOCKL_MAX], PLClpc[LPC_FILTERORDER + 1]; 1.3897 + float zeros[BLOCKL_MAX], one[LPC_FILTERORDER + 1]; 1.3898 + int k, i, start, idxForMax, pos, lastpart, ulp; 1.3899 + int lag, ilag; 1.3900 + float cc, maxcc; 1.3901 + int idxVec[STATE_LEN]; 1.3902 + int check; 1.3903 + int gain_index[NASUB_MAX*CB_NSTAGES], 1.3904 + extra_gain_index[CB_NSTAGES]; 1.3905 + int cb_index[CB_NSTAGES*NASUB_MAX], extra_cb_index[CB_NSTAGES]; 1.3906 + int lsf_i[LSF_NSPLIT*LPC_N_MAX]; 1.3907 + int state_first; 1.3908 + int last_bit; 1.3909 + unsigned char *pbytes; 1.3910 + float weightdenum[(LPC_FILTERORDER + 1)*NSUB_MAX]; 1.3911 + int order_plus_one; 1.3912 + float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; 1.3913 + float decresidual[BLOCKL_MAX]; 1.3914 + 1.3915 + if (mode>0) { /* the data are good */ 1.3916 + 1.3917 + /* decode data */ 1.3918 + 1.3919 + pbytes=bytes; 1.3920 + pos=0; 1.3921 + 1.3922 + 1.3923 + 1.3924 + 1.3925 +Andersen, et al. Experimental [Page 70] 1.3926 + 1.3927 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3928 + 1.3929 + 1.3930 + /* Set everything to zero before decoding */ 1.3931 + 1.3932 + for (k=0; k<LSF_NSPLIT*LPC_N_MAX; k++) { 1.3933 + lsf_i[k]=0; 1.3934 + } 1.3935 + start=0; 1.3936 + state_first=0; 1.3937 + idxForMax=0; 1.3938 + for (k=0; k<iLBCdec_inst->state_short_len; k++) { 1.3939 + idxVec[k]=0; 1.3940 + } 1.3941 + for (k=0; k<CB_NSTAGES; k++) { 1.3942 + extra_cb_index[k]=0; 1.3943 + } 1.3944 + for (k=0; k<CB_NSTAGES; k++) { 1.3945 + extra_gain_index[k]=0; 1.3946 + } 1.3947 + for (i=0; i<iLBCdec_inst->nasub; i++) { 1.3948 + for (k=0; k<CB_NSTAGES; k++) { 1.3949 + cb_index[i*CB_NSTAGES+k]=0; 1.3950 + } 1.3951 + } 1.3952 + for (i=0; i<iLBCdec_inst->nasub; i++) { 1.3953 + for (k=0; k<CB_NSTAGES; k++) { 1.3954 + gain_index[i*CB_NSTAGES+k]=0; 1.3955 + } 1.3956 + } 1.3957 + 1.3958 + /* loop over ULP classes */ 1.3959 + 1.3960 + for (ulp=0; ulp<3; ulp++) { 1.3961 + 1.3962 + /* LSF */ 1.3963 + for (k=0; k<LSF_NSPLIT*iLBCdec_inst->lpc_n; k++){ 1.3964 + unpack( &pbytes, &lastpart, 1.3965 + iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos); 1.3966 + packcombine(&lsf_i[k], lastpart, 1.3967 + iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]); 1.3968 + } 1.3969 + 1.3970 + /* Start block info */ 1.3971 + 1.3972 + unpack( &pbytes, &lastpart, 1.3973 + iLBCdec_inst->ULP_inst->start_bits[ulp], &pos); 1.3974 + packcombine(&start, lastpart, 1.3975 + iLBCdec_inst->ULP_inst->start_bits[ulp]); 1.3976 + 1.3977 + unpack( &pbytes, &lastpart, 1.3978 + 1.3979 + 1.3980 + 1.3981 +Andersen, et al. Experimental [Page 71] 1.3982 + 1.3983 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.3984 + 1.3985 + 1.3986 + iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos); 1.3987 + packcombine(&state_first, lastpart, 1.3988 + iLBCdec_inst->ULP_inst->startfirst_bits[ulp]); 1.3989 + 1.3990 + unpack( &pbytes, &lastpart, 1.3991 + iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos); 1.3992 + packcombine(&idxForMax, lastpart, 1.3993 + iLBCdec_inst->ULP_inst->scale_bits[ulp]); 1.3994 + 1.3995 + for (k=0; k<iLBCdec_inst->state_short_len; k++) { 1.3996 + unpack( &pbytes, &lastpart, 1.3997 + iLBCdec_inst->ULP_inst->state_bits[ulp], &pos); 1.3998 + packcombine(idxVec+k, lastpart, 1.3999 + iLBCdec_inst->ULP_inst->state_bits[ulp]); 1.4000 + } 1.4001 + 1.4002 + /* 23/22 (20ms/30ms) sample block */ 1.4003 + 1.4004 + for (k=0; k<CB_NSTAGES; k++) { 1.4005 + unpack( &pbytes, &lastpart, 1.4006 + iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp], 1.4007 + &pos); 1.4008 + packcombine(extra_cb_index+k, lastpart, 1.4009 + iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]); 1.4010 + } 1.4011 + for (k=0; k<CB_NSTAGES; k++) { 1.4012 + unpack( &pbytes, &lastpart, 1.4013 + iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp], 1.4014 + &pos); 1.4015 + packcombine(extra_gain_index+k, lastpart, 1.4016 + iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]); 1.4017 + } 1.4018 + 1.4019 + /* The two/four (20ms/30ms) 40 sample sub-blocks */ 1.4020 + 1.4021 + for (i=0; i<iLBCdec_inst->nasub; i++) { 1.4022 + for (k=0; k<CB_NSTAGES; k++) { 1.4023 + unpack( &pbytes, &lastpart, 1.4024 + iLBCdec_inst->ULP_inst->cb_index[i][k][ulp], 1.4025 + &pos); 1.4026 + packcombine(cb_index+i*CB_NSTAGES+k, lastpart, 1.4027 + iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]); 1.4028 + } 1.4029 + } 1.4030 + 1.4031 + for (i=0; i<iLBCdec_inst->nasub; i++) { 1.4032 + for (k=0; k<CB_NSTAGES; k++) { 1.4033 + unpack( &pbytes, &lastpart, 1.4034 + 1.4035 + 1.4036 + 1.4037 +Andersen, et al. Experimental [Page 72] 1.4038 + 1.4039 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4040 + 1.4041 + 1.4042 + iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp], 1.4043 + &pos); 1.4044 + packcombine(gain_index+i*CB_NSTAGES+k, lastpart, 1.4045 + iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]); 1.4046 + } 1.4047 + } 1.4048 + } 1.4049 + /* Extract last bit. If it is 1 this indicates an 1.4050 + empty/lost frame */ 1.4051 + unpack( &pbytes, &last_bit, 1, &pos); 1.4052 + 1.4053 + /* Check for bit errors or empty/lost frames */ 1.4054 + if (start<1) 1.4055 + mode = 0; 1.4056 + if (iLBCdec_inst->mode==20 && start>3) 1.4057 + mode = 0; 1.4058 + if (iLBCdec_inst->mode==30 && start>5) 1.4059 + mode = 0; 1.4060 + if (last_bit==1) 1.4061 + mode = 0; 1.4062 + 1.4063 + if (mode==1) { /* No bit errors was detected, 1.4064 + continue decoding */ 1.4065 + 1.4066 + /* adjust index */ 1.4067 + index_conv_dec(cb_index); 1.4068 + 1.4069 + /* decode the lsf */ 1.4070 + 1.4071 + SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n); 1.4072 + check=LSF_check(lsfdeq, LPC_FILTERORDER, 1.4073 + iLBCdec_inst->lpc_n); 1.4074 + DecoderInterpolateLSF(syntdenum, weightdenum, 1.4075 + lsfdeq, LPC_FILTERORDER, iLBCdec_inst); 1.4076 + 1.4077 + Decode(iLBCdec_inst, decresidual, start, idxForMax, 1.4078 + idxVec, syntdenum, cb_index, gain_index, 1.4079 + extra_cb_index, extra_gain_index, 1.4080 + state_first); 1.4081 + 1.4082 + /* preparing the plc for a future loss! */ 1.4083 + 1.4084 + doThePLC(PLCresidual, PLClpc, 0, decresidual, 1.4085 + syntdenum + 1.4086 + (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1), 1.4087 + (*iLBCdec_inst).last_lag, iLBCdec_inst); 1.4088 + 1.4089 + 1.4090 + 1.4091 + 1.4092 + 1.4093 +Andersen, et al. Experimental [Page 73] 1.4094 + 1.4095 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4096 + 1.4097 + 1.4098 + memcpy(decresidual, PLCresidual, 1.4099 + iLBCdec_inst->blockl*sizeof(float)); 1.4100 + } 1.4101 + 1.4102 + } 1.4103 + 1.4104 + if (mode == 0) { 1.4105 + /* the data is bad (either a PLC call 1.4106 + * was made or a severe bit error was detected) 1.4107 + */ 1.4108 + 1.4109 + /* packet loss conceal */ 1.4110 + 1.4111 + memset(zeros, 0, BLOCKL_MAX*sizeof(float)); 1.4112 + 1.4113 + one[0] = 1; 1.4114 + memset(one+1, 0, LPC_FILTERORDER*sizeof(float)); 1.4115 + 1.4116 + start=0; 1.4117 + 1.4118 + doThePLC(PLCresidual, PLClpc, 1, zeros, one, 1.4119 + (*iLBCdec_inst).last_lag, iLBCdec_inst); 1.4120 + memcpy(decresidual, PLCresidual, 1.4121 + iLBCdec_inst->blockl*sizeof(float)); 1.4122 + 1.4123 + order_plus_one = LPC_FILTERORDER + 1; 1.4124 + for (i = 0; i < iLBCdec_inst->nsub; i++) { 1.4125 + memcpy(syntdenum+(i*order_plus_one), PLClpc, 1.4126 + order_plus_one*sizeof(float)); 1.4127 + } 1.4128 + } 1.4129 + 1.4130 + if (iLBCdec_inst->use_enhancer == 1) { 1.4131 + 1.4132 + /* post filtering */ 1.4133 + 1.4134 + iLBCdec_inst->last_lag = 1.4135 + enhancerInterface(data, decresidual, iLBCdec_inst); 1.4136 + 1.4137 + /* synthesis filtering */ 1.4138 + 1.4139 + if (iLBCdec_inst->mode==20) { 1.4140 + /* Enhancer has 40 samples delay */ 1.4141 + i=0; 1.4142 + syntFilter(data + i*SUBL, 1.4143 + iLBCdec_inst->old_syntdenum + 1.4144 + (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1), 1.4145 + SUBL, iLBCdec_inst->syntMem); 1.4146 + 1.4147 + 1.4148 + 1.4149 +Andersen, et al. Experimental [Page 74] 1.4150 + 1.4151 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4152 + 1.4153 + 1.4154 + for (i=1; i < iLBCdec_inst->nsub; i++) { 1.4155 + syntFilter(data + i*SUBL, 1.4156 + syntdenum + (i-1)*(LPC_FILTERORDER+1), 1.4157 + SUBL, iLBCdec_inst->syntMem); 1.4158 + } 1.4159 + } else if (iLBCdec_inst->mode==30) { 1.4160 + /* Enhancer has 80 samples delay */ 1.4161 + for (i=0; i < 2; i++) { 1.4162 + syntFilter(data + i*SUBL, 1.4163 + iLBCdec_inst->old_syntdenum + 1.4164 + (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1), 1.4165 + SUBL, iLBCdec_inst->syntMem); 1.4166 + } 1.4167 + for (i=2; i < iLBCdec_inst->nsub; i++) { 1.4168 + syntFilter(data + i*SUBL, 1.4169 + syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL, 1.4170 + iLBCdec_inst->syntMem); 1.4171 + } 1.4172 + } 1.4173 + 1.4174 + } else { 1.4175 + 1.4176 + /* Find last lag */ 1.4177 + lag = 20; 1.4178 + maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], 1.4179 + &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL); 1.4180 + 1.4181 + for (ilag=21; ilag<120; ilag++) { 1.4182 + cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], 1.4183 + &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag], 1.4184 + ENH_BLOCKL); 1.4185 + 1.4186 + if (cc > maxcc) { 1.4187 + maxcc = cc; 1.4188 + lag = ilag; 1.4189 + } 1.4190 + } 1.4191 + iLBCdec_inst->last_lag = lag; 1.4192 + 1.4193 + /* copy data and run synthesis filter */ 1.4194 + 1.4195 + memcpy(data, decresidual, 1.4196 + iLBCdec_inst->blockl*sizeof(float)); 1.4197 + for (i=0; i < iLBCdec_inst->nsub; i++) { 1.4198 + syntFilter(data + i*SUBL, 1.4199 + syntdenum + i*(LPC_FILTERORDER+1), SUBL, 1.4200 + iLBCdec_inst->syntMem); 1.4201 + } 1.4202 + 1.4203 + 1.4204 + 1.4205 +Andersen, et al. Experimental [Page 75] 1.4206 + 1.4207 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4208 + 1.4209 + 1.4210 + } 1.4211 + 1.4212 + /* high pass filtering on output if desired, otherwise 1.4213 + copy to out */ 1.4214 + 1.4215 + hpOutput(data, iLBCdec_inst->blockl, 1.4216 + decblock,iLBCdec_inst->hpomem); 1.4217 + 1.4218 + /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/ 1.4219 + 1.4220 + memcpy(iLBCdec_inst->old_syntdenum, syntdenum, 1.4221 + 1.4222 + iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float)); 1.4223 + 1.4224 + iLBCdec_inst->prev_enh_pl=0; 1.4225 + 1.4226 + if (mode==0) { /* PLC was used */ 1.4227 + iLBCdec_inst->prev_enh_pl=1; 1.4228 + } 1.4229 + } 1.4230 + 1.4231 +A.6. iLBC_define.h 1.4232 + 1.4233 + /****************************************************************** 1.4234 + 1.4235 + iLBC Speech Coder ANSI-C Source Code 1.4236 + 1.4237 + iLBC_define.h 1.4238 + 1.4239 + Copyright (C) The Internet Society (2004). 1.4240 + All Rights Reserved. 1.4241 + 1.4242 + ******************************************************************/ 1.4243 + #include <string.h> 1.4244 + 1.4245 + #ifndef __iLBC_ILBCDEFINE_H 1.4246 + #define __iLBC_ILBCDEFINE_H 1.4247 + 1.4248 + /* general codec settings */ 1.4249 + 1.4250 + #define FS (float)8000.0 1.4251 + #define BLOCKL_20MS 160 1.4252 + #define BLOCKL_30MS 240 1.4253 + #define BLOCKL_MAX 240 1.4254 + #define NSUB_20MS 4 1.4255 + #define NSUB_30MS 6 1.4256 + #define NSUB_MAX 6 1.4257 + #define NASUB_20MS 2 1.4258 + 1.4259 + 1.4260 + 1.4261 +Andersen, et al. Experimental [Page 76] 1.4262 + 1.4263 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4264 + 1.4265 + 1.4266 + #define NASUB_30MS 4 1.4267 + #define NASUB_MAX 4 1.4268 + #define SUBL 40 1.4269 + #define STATE_LEN 80 1.4270 + #define STATE_SHORT_LEN_30MS 58 1.4271 + #define STATE_SHORT_LEN_20MS 57 1.4272 + 1.4273 + /* LPC settings */ 1.4274 + 1.4275 + #define LPC_FILTERORDER 10 1.4276 + #define LPC_CHIRP_SYNTDENUM (float)0.9025 1.4277 + #define LPC_CHIRP_WEIGHTDENUM (float)0.4222 1.4278 + #define LPC_LOOKBACK 60 1.4279 + #define LPC_N_20MS 1 1.4280 + #define LPC_N_30MS 2 1.4281 + #define LPC_N_MAX 2 1.4282 + #define LPC_ASYMDIFF 20 1.4283 + #define LPC_BW (float)60.0 1.4284 + #define LPC_WN (float)1.0001 1.4285 + #define LSF_NSPLIT 3 1.4286 + #define LSF_NUMBER_OF_STEPS 4 1.4287 + #define LPC_HALFORDER (LPC_FILTERORDER/2) 1.4288 + 1.4289 + /* cb settings */ 1.4290 + 1.4291 + #define CB_NSTAGES 3 1.4292 + #define CB_EXPAND 2 1.4293 + #define CB_MEML 147 1.4294 + #define CB_FILTERLEN 2*4 1.4295 + #define CB_HALFFILTERLEN 4 1.4296 + #define CB_RESRANGE 34 1.4297 + #define CB_MAXGAIN (float)1.3 1.4298 + 1.4299 + /* enhancer */ 1.4300 + 1.4301 + #define ENH_BLOCKL 80 /* block length */ 1.4302 + #define ENH_BLOCKL_HALF (ENH_BLOCKL/2) 1.4303 + #define ENH_HL 3 /* 2*ENH_HL+1 is number blocks 1.4304 + in said second sequence */ 1.4305 + #define ENH_SLOP 2 /* max difference estimated and 1.4306 + correct pitch period */ 1.4307 + #define ENH_PLOCSL 20 /* pitch-estimates and pitch- 1.4308 + locations buffer length */ 1.4309 + #define ENH_OVERHANG 2 1.4310 + #define ENH_UPS0 4 /* upsampling rate */ 1.4311 + #define ENH_FL0 3 /* 2*FLO+1 is the length of 1.4312 + each filter */ 1.4313 + #define ENH_VECTL (ENH_BLOCKL+2*ENH_FL0) 1.4314 + 1.4315 + 1.4316 + 1.4317 +Andersen, et al. Experimental [Page 77] 1.4318 + 1.4319 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4320 + 1.4321 + 1.4322 + #define ENH_CORRDIM (2*ENH_SLOP+1) 1.4323 + #define ENH_NBLOCKS (BLOCKL_MAX/ENH_BLOCKL) 1.4324 + #define ENH_NBLOCKS_EXTRA 5 1.4325 + #define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS + 1.4326 + ENH_NBLOCKS_EXTRA */ 1.4327 + #define ENH_BUFL (ENH_NBLOCKS_TOT)*ENH_BLOCKL 1.4328 + #define ENH_ALPHA0 (float)0.05 1.4329 + 1.4330 + /* Down sampling */ 1.4331 + 1.4332 + #define FILTERORDER_DS 7 1.4333 + #define DELAY_DS 3 1.4334 + #define FACTOR_DS 2 1.4335 + 1.4336 + /* bit stream defs */ 1.4337 + 1.4338 + #define NO_OF_BYTES_20MS 38 1.4339 + #define NO_OF_BYTES_30MS 50 1.4340 + #define NO_OF_WORDS_20MS 19 1.4341 + #define NO_OF_WORDS_30MS 25 1.4342 + #define STATE_BITS 3 1.4343 + #define BYTE_LEN 8 1.4344 + #define ULP_CLASSES 3 1.4345 + 1.4346 + /* help parameters */ 1.4347 + 1.4348 + #define FLOAT_MAX (float)1.0e37 1.4349 + #define EPS (float)2.220446049250313e-016 1.4350 + #define PI (float)3.14159265358979323846 1.4351 + #define MIN_SAMPLE -32768 1.4352 + #define MAX_SAMPLE 32767 1.4353 + #define TWO_PI (float)6.283185307 1.4354 + #define PI2 (float)0.159154943 1.4355 + 1.4356 + /* type definition encoder instance */ 1.4357 + typedef struct iLBC_ULP_Inst_t_ { 1.4358 + int lsf_bits[6][ULP_CLASSES+2]; 1.4359 + int start_bits[ULP_CLASSES+2]; 1.4360 + int startfirst_bits[ULP_CLASSES+2]; 1.4361 + int scale_bits[ULP_CLASSES+2]; 1.4362 + int state_bits[ULP_CLASSES+2]; 1.4363 + int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2]; 1.4364 + int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2]; 1.4365 + int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2]; 1.4366 + int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2]; 1.4367 + } iLBC_ULP_Inst_t; 1.4368 + 1.4369 + /* type definition encoder instance */ 1.4370 + 1.4371 + 1.4372 + 1.4373 +Andersen, et al. Experimental [Page 78] 1.4374 + 1.4375 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4376 + 1.4377 + 1.4378 + typedef struct iLBC_Enc_Inst_t_ { 1.4379 + 1.4380 + /* flag for frame size mode */ 1.4381 + int mode; 1.4382 + 1.4383 + /* basic parameters for different frame sizes */ 1.4384 + int blockl; 1.4385 + int nsub; 1.4386 + int nasub; 1.4387 + int no_of_bytes, no_of_words; 1.4388 + int lpc_n; 1.4389 + int state_short_len; 1.4390 + const iLBC_ULP_Inst_t *ULP_inst; 1.4391 + 1.4392 + /* analysis filter state */ 1.4393 + float anaMem[LPC_FILTERORDER]; 1.4394 + 1.4395 + /* old lsf parameters for interpolation */ 1.4396 + float lsfold[LPC_FILTERORDER]; 1.4397 + float lsfdeqold[LPC_FILTERORDER]; 1.4398 + 1.4399 + /* signal buffer for LP analysis */ 1.4400 + float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX]; 1.4401 + 1.4402 + /* state of input HP filter */ 1.4403 + float hpimem[4]; 1.4404 + 1.4405 + } iLBC_Enc_Inst_t; 1.4406 + 1.4407 + /* type definition decoder instance */ 1.4408 + typedef struct iLBC_Dec_Inst_t_ { 1.4409 + 1.4410 + /* flag for frame size mode */ 1.4411 + int mode; 1.4412 + 1.4413 + /* basic parameters for different frame sizes */ 1.4414 + int blockl; 1.4415 + int nsub; 1.4416 + int nasub; 1.4417 + int no_of_bytes, no_of_words; 1.4418 + int lpc_n; 1.4419 + int state_short_len; 1.4420 + const iLBC_ULP_Inst_t *ULP_inst; 1.4421 + 1.4422 + /* synthesis filter state */ 1.4423 + float syntMem[LPC_FILTERORDER]; 1.4424 + 1.4425 + /* old LSF for interpolation */ 1.4426 + 1.4427 + 1.4428 + 1.4429 +Andersen, et al. Experimental [Page 79] 1.4430 + 1.4431 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4432 + 1.4433 + 1.4434 + float lsfdeqold[LPC_FILTERORDER]; 1.4435 + 1.4436 + /* pitch lag estimated in enhancer and used in PLC */ 1.4437 + int last_lag; 1.4438 + 1.4439 + /* PLC state information */ 1.4440 + int prevLag, consPLICount, prevPLI, prev_enh_pl; 1.4441 + float prevLpc[LPC_FILTERORDER+1]; 1.4442 + float prevResidual[NSUB_MAX*SUBL]; 1.4443 + float per; 1.4444 + unsigned long seed; 1.4445 + 1.4446 + /* previous synthesis filter parameters */ 1.4447 + float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX]; 1.4448 + 1.4449 + /* state of output HP filter */ 1.4450 + float hpomem[4]; 1.4451 + 1.4452 + /* enhancer state information */ 1.4453 + int use_enhancer; 1.4454 + float enh_buf[ENH_BUFL]; 1.4455 + float enh_period[ENH_NBLOCKS_TOT]; 1.4456 + 1.4457 + } iLBC_Dec_Inst_t; 1.4458 + 1.4459 + #endif 1.4460 + 1.4461 +A.7. constants.h 1.4462 + 1.4463 + /****************************************************************** 1.4464 + 1.4465 + iLBC Speech Coder ANSI-C Source Code 1.4466 + 1.4467 + constants.h 1.4468 + 1.4469 + Copyright (C) The Internet Society (2004). 1.4470 + All Rights Reserved. 1.4471 + 1.4472 + ******************************************************************/ 1.4473 + 1.4474 + #ifndef __iLBC_CONSTANTS_H 1.4475 + #define __iLBC_CONSTANTS_H 1.4476 + 1.4477 + #include "iLBC_define.h" 1.4478 + 1.4479 + 1.4480 + /* ULP bit allocation */ 1.4481 + 1.4482 + 1.4483 + 1.4484 + 1.4485 +Andersen, et al. Experimental [Page 80] 1.4486 + 1.4487 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4488 + 1.4489 + 1.4490 + extern const iLBC_ULP_Inst_t ULP_20msTbl; 1.4491 + extern const iLBC_ULP_Inst_t ULP_30msTbl; 1.4492 + 1.4493 + /* high pass filters */ 1.4494 + 1.4495 + extern float hpi_zero_coefsTbl[]; 1.4496 + extern float hpi_pole_coefsTbl[]; 1.4497 + extern float hpo_zero_coefsTbl[]; 1.4498 + extern float hpo_pole_coefsTbl[]; 1.4499 + 1.4500 + /* low pass filters */ 1.4501 + extern float lpFilt_coefsTbl[]; 1.4502 + 1.4503 + /* LPC analysis and quantization */ 1.4504 + 1.4505 + extern float lpc_winTbl[]; 1.4506 + extern float lpc_asymwinTbl[]; 1.4507 + extern float lpc_lagwinTbl[]; 1.4508 + extern float lsfCbTbl[]; 1.4509 + extern float lsfmeanTbl[]; 1.4510 + extern int dim_lsfCbTbl[]; 1.4511 + extern int size_lsfCbTbl[]; 1.4512 + extern float lsf_weightTbl_30ms[]; 1.4513 + extern float lsf_weightTbl_20ms[]; 1.4514 + 1.4515 + /* state quantization tables */ 1.4516 + 1.4517 + extern float state_sq3Tbl[]; 1.4518 + extern float state_frgqTbl[]; 1.4519 + 1.4520 + /* gain quantization tables */ 1.4521 + 1.4522 + extern float gain_sq3Tbl[]; 1.4523 + extern float gain_sq4Tbl[]; 1.4524 + extern float gain_sq5Tbl[]; 1.4525 + 1.4526 + /* adaptive codebook definitions */ 1.4527 + 1.4528 + extern int search_rangeTbl[5][CB_NSTAGES]; 1.4529 + extern int memLfTbl[]; 1.4530 + extern int stMemLTbl; 1.4531 + extern float cbfiltersTbl[CB_FILTERLEN]; 1.4532 + 1.4533 + /* enhancer definitions */ 1.4534 + 1.4535 + extern float polyphaserTbl[]; 1.4536 + extern float enh_plocsTbl[]; 1.4537 + 1.4538 + 1.4539 + 1.4540 + 1.4541 +Andersen, et al. Experimental [Page 81] 1.4542 + 1.4543 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4544 + 1.4545 + 1.4546 + #endif 1.4547 + 1.4548 +A.8. constants.c 1.4549 + 1.4550 + /****************************************************************** 1.4551 + 1.4552 + iLBC Speech Coder ANSI-C Source Code 1.4553 + 1.4554 + constants.c 1.4555 + 1.4556 + Copyright (C) The Internet Society (2004). 1.4557 + All Rights Reserved. 1.4558 + 1.4559 + ******************************************************************/ 1.4560 + 1.4561 + #include "iLBC_define.h" 1.4562 + 1.4563 + /* ULP bit allocation */ 1.4564 + 1.4565 + /* 20 ms frame */ 1.4566 + 1.4567 + const iLBC_ULP_Inst_t ULP_20msTbl = { 1.4568 + /* LSF */ 1.4569 + { {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, 1.4570 + {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}, 1.4571 + /* Start state location, gain and samples */ 1.4572 + {2,0,0,0,0}, 1.4573 + {1,0,0,0,0}, 1.4574 + {6,0,0,0,0}, 1.4575 + {0,1,2,0,0}, 1.4576 + /* extra CB index and extra CB gain */ 1.4577 + {{6,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 1.4578 + {{2,0,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}}, 1.4579 + /* CB index and CB gain */ 1.4580 + { {{7,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 1.4581 + {{0,0,8,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}, 1.4582 + {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}, 1.4583 + {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}}, 1.4584 + { {{1,2,2,0,0}, {1,1,2,0,0}, {0,0,3,0,0}}, 1.4585 + {{1,1,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}}, 1.4586 + {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}, 1.4587 + {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}} 1.4588 + }; 1.4589 + 1.4590 + /* 30 ms frame */ 1.4591 + 1.4592 + const iLBC_ULP_Inst_t ULP_30msTbl = { 1.4593 + /* LSF */ 1.4594 + 1.4595 + 1.4596 + 1.4597 +Andersen, et al. Experimental [Page 82] 1.4598 + 1.4599 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4600 + 1.4601 + 1.4602 + { {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, 1.4603 + {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}}, 1.4604 + /* Start state location, gain and samples */ 1.4605 + {3,0,0,0,0}, 1.4606 + {1,0,0,0,0}, 1.4607 + {6,0,0,0,0}, 1.4608 + {0,1,2,0,0}, 1.4609 + /* extra CB index and extra CB gain */ 1.4610 + {{4,2,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 1.4611 + {{1,1,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}}, 1.4612 + /* CB index and CB gain */ 1.4613 + { {{6,1,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 1.4614 + {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}, 1.4615 + {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}, 1.4616 + {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}}, 1.4617 + { {{1,2,2,0,0}, {1,2,1,0,0}, {0,0,3,0,0}}, 1.4618 + {{0,2,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}}, 1.4619 + {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}, 1.4620 + {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}} 1.4621 + }; 1.4622 + 1.4623 + /* HP Filters */ 1.4624 + 1.4625 + float hpi_zero_coefsTbl[3] = { 1.4626 + (float)0.92727436, (float)-1.8544941, (float)0.92727436 1.4627 + }; 1.4628 + float hpi_pole_coefsTbl[3] = { 1.4629 + (float)1.0, (float)-1.9059465, (float)0.9114024 1.4630 + }; 1.4631 + float hpo_zero_coefsTbl[3] = { 1.4632 + (float)0.93980581, (float)-1.8795834, (float)0.93980581 1.4633 + }; 1.4634 + float hpo_pole_coefsTbl[3] = { 1.4635 + (float)1.0, (float)-1.9330735, (float)0.93589199 1.4636 + }; 1.4637 + 1.4638 + /* LP Filter */ 1.4639 + 1.4640 + float lpFilt_coefsTbl[FILTERORDER_DS]={ 1.4641 + (float)-0.066650, (float)0.125000, (float)0.316650, 1.4642 + (float)0.414063, (float)0.316650, 1.4643 + (float)0.125000, (float)-0.066650 1.4644 + }; 1.4645 + 1.4646 + /* State quantization tables */ 1.4647 + 1.4648 + float state_sq3Tbl[8] = { 1.4649 + (float)-3.719849, (float)-2.177490, (float)-1.130005, 1.4650 + 1.4651 + 1.4652 + 1.4653 +Andersen, et al. Experimental [Page 83] 1.4654 + 1.4655 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4656 + 1.4657 + 1.4658 + (float)-0.309692, (float)0.444214, (float)1.329712, 1.4659 + (float)2.436279, (float)3.983887 1.4660 + }; 1.4661 + 1.4662 + float state_frgqTbl[64] = { 1.4663 + (float)1.000085, (float)1.071695, (float)1.140395, 1.4664 + (float)1.206868, (float)1.277188, (float)1.351503, 1.4665 + (float)1.429380, (float)1.500727, (float)1.569049, 1.4666 + (float)1.639599, (float)1.707071, (float)1.781531, 1.4667 + (float)1.840799, (float)1.901550, (float)1.956695, 1.4668 + (float)2.006750, (float)2.055474, (float)2.102787, 1.4669 + (float)2.142819, (float)2.183592, (float)2.217962, 1.4670 + (float)2.257177, (float)2.295739, (float)2.332967, 1.4671 + (float)2.369248, (float)2.402792, (float)2.435080, 1.4672 + (float)2.468598, (float)2.503394, (float)2.539284, 1.4673 + (float)2.572944, (float)2.605036, (float)2.636331, 1.4674 + (float)2.668939, (float)2.698780, (float)2.729101, 1.4675 + (float)2.759786, (float)2.789834, (float)2.818679, 1.4676 + (float)2.848074, (float)2.877470, (float)2.906899, 1.4677 + (float)2.936655, (float)2.967804, (float)3.000115, 1.4678 + (float)3.033367, (float)3.066355, (float)3.104231, 1.4679 + (float)3.141499, (float)3.183012, (float)3.222952, 1.4680 + (float)3.265433, (float)3.308441, (float)3.350823, 1.4681 + (float)3.395275, (float)3.442793, (float)3.490801, 1.4682 + (float)3.542514, (float)3.604064, (float)3.666050, 1.4683 + (float)3.740994, (float)3.830749, (float)3.938770, 1.4684 + (float)4.101764 1.4685 + }; 1.4686 + 1.4687 + /* CB tables */ 1.4688 + 1.4689 + int search_rangeTbl[5][CB_NSTAGES]={{58,58,58}, {108,44,44}, 1.4690 + {108,108,108}, {108,108,108}, {108,108,108}}; 1.4691 + int stMemLTbl=85; 1.4692 + int memLfTbl[NASUB_MAX]={147,147,147,147}; 1.4693 + 1.4694 + /* expansion filter(s) */ 1.4695 + 1.4696 + float cbfiltersTbl[CB_FILTERLEN]={ 1.4697 + (float)-0.034180, (float)0.108887, (float)-0.184326, 1.4698 + (float)0.806152, (float)0.713379, (float)-0.144043, 1.4699 + (float)0.083740, (float)-0.033691 1.4700 + }; 1.4701 + 1.4702 + /* Gain Quantization */ 1.4703 + 1.4704 + float gain_sq3Tbl[8]={ 1.4705 + (float)-1.000000, (float)-0.659973, (float)-0.330017, 1.4706 + 1.4707 + 1.4708 + 1.4709 +Andersen, et al. Experimental [Page 84] 1.4710 + 1.4711 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4712 + 1.4713 + 1.4714 + (float)0.000000, (float)0.250000, (float)0.500000, 1.4715 + (float)0.750000, (float)1.00000}; 1.4716 + 1.4717 + float gain_sq4Tbl[16]={ 1.4718 + (float)-1.049988, (float)-0.900024, (float)-0.750000, 1.4719 + (float)-0.599976, (float)-0.450012, (float)-0.299988, 1.4720 + (float)-0.150024, (float)0.000000, (float)0.150024, 1.4721 + (float)0.299988, (float)0.450012, (float)0.599976, 1.4722 + (float)0.750000, (float)0.900024, (float)1.049988, 1.4723 + (float)1.200012}; 1.4724 + 1.4725 + float gain_sq5Tbl[32]={ 1.4726 + (float)0.037476, (float)0.075012, (float)0.112488, 1.4727 + (float)0.150024, (float)0.187500, (float)0.224976, 1.4728 + (float)0.262512, (float)0.299988, (float)0.337524, 1.4729 + (float)0.375000, (float)0.412476, (float)0.450012, 1.4730 + (float)0.487488, (float)0.525024, (float)0.562500, 1.4731 + (float)0.599976, (float)0.637512, (float)0.674988, 1.4732 + (float)0.712524, (float)0.750000, (float)0.787476, 1.4733 + (float)0.825012, (float)0.862488, (float)0.900024, 1.4734 + (float)0.937500, (float)0.974976, (float)1.012512, 1.4735 + (float)1.049988, (float)1.087524, (float)1.125000, 1.4736 + (float)1.162476, (float)1.200012}; 1.4737 + 1.4738 + /* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */ 1.4739 + float polyphaserTbl[ENH_UPS0*(2*ENH_FL0+1)]={ 1.4740 + (float)0.000000, (float)0.000000, (float)0.000000, 1.4741 + (float)1.000000, 1.4742 + (float)0.000000, (float)0.000000, (float)0.000000, 1.4743 + (float)0.015625, (float)-0.076904, (float)0.288330, 1.4744 + (float)0.862061, 1.4745 + (float)-0.106445, (float)0.018799, (float)-0.015625, 1.4746 + (float)0.023682, (float)-0.124268, (float)0.601563, 1.4747 + (float)0.601563, 1.4748 + (float)-0.124268, (float)0.023682, (float)-0.023682, 1.4749 + (float)0.018799, (float)-0.106445, (float)0.862061, 1.4750 + (float)0.288330, 1.4751 + (float)-0.076904, (float)0.015625, (float)-0.018799}; 1.4752 + 1.4753 + float enh_plocsTbl[ENH_NBLOCKS_TOT] = {(float)40.0, (float)120.0, 1.4754 + (float)200.0, (float)280.0, (float)360.0, 1.4755 + (float)440.0, (float)520.0, (float)600.0}; 1.4756 + 1.4757 + /* LPC analysis and quantization */ 1.4758 + 1.4759 + int dim_lsfCbTbl[LSF_NSPLIT] = {3, 3, 4}; 1.4760 + int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128}; 1.4761 + 1.4762 + 1.4763 + 1.4764 + 1.4765 +Andersen, et al. Experimental [Page 85] 1.4766 + 1.4767 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4768 + 1.4769 + 1.4770 + float lsfmeanTbl[LPC_FILTERORDER] = { 1.4771 + (float)0.281738, (float)0.445801, (float)0.663330, 1.4772 + (float)0.962524, (float)1.251831, (float)1.533081, 1.4773 + (float)1.850586, (float)2.137817, (float)2.481445, 1.4774 + (float)2.777344}; 1.4775 + 1.4776 + float lsf_weightTbl_30ms[6] = {(float)(1.0/2.0), (float)1.0, 1.4777 + (float)(2.0/3.0), 1.4778 + (float)(1.0/3.0), (float)0.0, (float)0.0}; 1.4779 + 1.4780 + float lsf_weightTbl_20ms[4] = {(float)(3.0/4.0), (float)(2.0/4.0), 1.4781 + (float)(1.0/4.0), (float)(0.0)}; 1.4782 + 1.4783 + /* Hanning LPC window */ 1.4784 + float lpc_winTbl[BLOCKL_MAX]={ 1.4785 + (float)0.000183, (float)0.000671, (float)0.001526, 1.4786 + (float)0.002716, (float)0.004242, (float)0.006104, 1.4787 + (float)0.008301, (float)0.010834, (float)0.013702, 1.4788 + (float)0.016907, (float)0.020416, (float)0.024261, 1.4789 + (float)0.028442, (float)0.032928, (float)0.037750, 1.4790 + (float)0.042877, (float)0.048309, (float)0.054047, 1.4791 + (float)0.060089, (float)0.066437, (float)0.073090, 1.4792 + (float)0.080017, (float)0.087219, (float)0.094727, 1.4793 + (float)0.102509, (float)0.110535, (float)0.118835, 1.4794 + (float)0.127411, (float)0.136230, (float)0.145294, 1.4795 + (float)0.154602, (float)0.164154, (float)0.173920, 1.4796 + (float)0.183899, (float)0.194122, (float)0.204529, 1.4797 + (float)0.215149, (float)0.225952, (float)0.236938, 1.4798 + (float)0.248108, (float)0.259460, (float)0.270966, 1.4799 + (float)0.282654, (float)0.294464, (float)0.306396, 1.4800 + (float)0.318481, (float)0.330688, (float)0.343018, 1.4801 + (float)0.355438, (float)0.367981, (float)0.380585, 1.4802 + (float)0.393280, (float)0.406067, (float)0.418884, 1.4803 + (float)0.431763, (float)0.444702, (float)0.457672, 1.4804 + (float)0.470673, (float)0.483704, (float)0.496735, 1.4805 + (float)0.509766, (float)0.522797, (float)0.535828, 1.4806 + (float)0.548798, (float)0.561768, (float)0.574677, 1.4807 + (float)0.587524, (float)0.600342, (float)0.613068, 1.4808 + (float)0.625732, (float)0.638306, (float)0.650787, 1.4809 + (float)0.663147, (float)0.675415, (float)0.687561, 1.4810 + (float)0.699585, (float)0.711487, (float)0.723206, 1.4811 + (float)0.734802, (float)0.746216, (float)0.757477, 1.4812 + (float)0.768585, (float)0.779480, (float)0.790192, 1.4813 + (float)0.800720, (float)0.811005, (float)0.821106, 1.4814 + (float)0.830994, (float)0.840668, (float)0.850067, 1.4815 + (float)0.859253, (float)0.868225, (float)0.876892, 1.4816 + (float)0.885345, (float)0.893524, (float)0.901428, 1.4817 + (float)0.909058, (float)0.916412, (float)0.923492, 1.4818 + 1.4819 + 1.4820 + 1.4821 +Andersen, et al. Experimental [Page 86] 1.4822 + 1.4823 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4824 + 1.4825 + 1.4826 + (float)0.930267, (float)0.936768, (float)0.942963, 1.4827 + (float)0.948853, (float)0.954437, (float)0.959717, 1.4828 + (float)0.964691, (float)0.969360, (float)0.973694, 1.4829 + (float)0.977692, (float)0.981384, (float)0.984741, 1.4830 + (float)0.987762, (float)0.990479, (float)0.992828, 1.4831 + (float)0.994873, (float)0.996552, (float)0.997925, 1.4832 + (float)0.998932, (float)0.999603, (float)0.999969, 1.4833 + (float)0.999969, (float)0.999603, (float)0.998932, 1.4834 + (float)0.997925, (float)0.996552, (float)0.994873, 1.4835 + (float)0.992828, (float)0.990479, (float)0.987762, 1.4836 + (float)0.984741, (float)0.981384, (float)0.977692, 1.4837 + (float)0.973694, (float)0.969360, (float)0.964691, 1.4838 + (float)0.959717, (float)0.954437, (float)0.948853, 1.4839 + (float)0.942963, (float)0.936768, (float)0.930267, 1.4840 + (float)0.923492, (float)0.916412, (float)0.909058, 1.4841 + (float)0.901428, (float)0.893524, (float)0.885345, 1.4842 + (float)0.876892, (float)0.868225, (float)0.859253, 1.4843 + (float)0.850067, (float)0.840668, (float)0.830994, 1.4844 + (float)0.821106, (float)0.811005, (float)0.800720, 1.4845 + (float)0.790192, (float)0.779480, (float)0.768585, 1.4846 + (float)0.757477, (float)0.746216, (float)0.734802, 1.4847 + (float)0.723206, (float)0.711487, (float)0.699585, 1.4848 + (float)0.687561, (float)0.675415, (float)0.663147, 1.4849 + (float)0.650787, (float)0.638306, (float)0.625732, 1.4850 + (float)0.613068, (float)0.600342, (float)0.587524, 1.4851 + (float)0.574677, (float)0.561768, (float)0.548798, 1.4852 + (float)0.535828, (float)0.522797, (float)0.509766, 1.4853 + (float)0.496735, (float)0.483704, (float)0.470673, 1.4854 + (float)0.457672, (float)0.444702, (float)0.431763, 1.4855 + (float)0.418884, (float)0.406067, (float)0.393280, 1.4856 + (float)0.380585, (float)0.367981, (float)0.355438, 1.4857 + (float)0.343018, (float)0.330688, (float)0.318481, 1.4858 + (float)0.306396, (float)0.294464, (float)0.282654, 1.4859 + (float)0.270966, (float)0.259460, (float)0.248108, 1.4860 + (float)0.236938, (float)0.225952, (float)0.215149, 1.4861 + (float)0.204529, (float)0.194122, (float)0.183899, 1.4862 + (float)0.173920, (float)0.164154, (float)0.154602, 1.4863 + (float)0.145294, (float)0.136230, (float)0.127411, 1.4864 + (float)0.118835, (float)0.110535, (float)0.102509, 1.4865 + (float)0.094727, (float)0.087219, (float)0.080017, 1.4866 + (float)0.073090, (float)0.066437, (float)0.060089, 1.4867 + (float)0.054047, (float)0.048309, (float)0.042877, 1.4868 + (float)0.037750, (float)0.032928, (float)0.028442, 1.4869 + (float)0.024261, (float)0.020416, (float)0.016907, 1.4870 + (float)0.013702, (float)0.010834, (float)0.008301, 1.4871 + (float)0.006104, (float)0.004242, (float)0.002716, 1.4872 + (float)0.001526, (float)0.000671, (float)0.000183 1.4873 + }; 1.4874 + 1.4875 + 1.4876 + 1.4877 +Andersen, et al. Experimental [Page 87] 1.4878 + 1.4879 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4880 + 1.4881 + 1.4882 + /* Asymmetric LPC window */ 1.4883 + float lpc_asymwinTbl[BLOCKL_MAX]={ 1.4884 + (float)0.000061, (float)0.000214, (float)0.000458, 1.4885 + (float)0.000824, (float)0.001282, (float)0.001831, 1.4886 + (float)0.002472, (float)0.003235, (float)0.004120, 1.4887 + (float)0.005066, (float)0.006134, (float)0.007294, 1.4888 + (float)0.008545, (float)0.009918, (float)0.011383, 1.4889 + (float)0.012939, (float)0.014587, (float)0.016357, 1.4890 + (float)0.018219, (float)0.020172, (float)0.022217, 1.4891 + (float)0.024353, (float)0.026611, (float)0.028961, 1.4892 + (float)0.031372, (float)0.033905, (float)0.036530, 1.4893 + (float)0.039276, (float)0.042084, (float)0.044983, 1.4894 + (float)0.047974, (float)0.051086, (float)0.054260, 1.4895 + (float)0.057526, (float)0.060883, (float)0.064331, 1.4896 + (float)0.067871, (float)0.071503, (float)0.075226, 1.4897 + (float)0.079010, (float)0.082916, (float)0.086884, 1.4898 + (float)0.090942, (float)0.095062, (float)0.099304, 1.4899 + (float)0.103607, (float)0.107971, (float)0.112427, 1.4900 + (float)0.116974, (float)0.121582, (float)0.126282, 1.4901 + (float)0.131073, (float)0.135895, (float)0.140839, 1.4902 + (float)0.145813, (float)0.150879, (float)0.156006, 1.4903 + (float)0.161224, (float)0.166504, (float)0.171844, 1.4904 + (float)0.177246, (float)0.182709, (float)0.188263, 1.4905 + (float)0.193848, (float)0.199524, (float)0.205231, 1.4906 + (float)0.211029, (float)0.216858, (float)0.222778, 1.4907 + (float)0.228729, (float)0.234741, (float)0.240814, 1.4908 + (float)0.246918, (float)0.253082, (float)0.259308, 1.4909 + (float)0.265564, (float)0.271881, (float)0.278259, 1.4910 + (float)0.284668, (float)0.291107, (float)0.297607, 1.4911 + (float)0.304138, (float)0.310730, (float)0.317322, 1.4912 + (float)0.323975, (float)0.330658, (float)0.337372, 1.4913 + (float)0.344147, (float)0.350922, (float)0.357727, 1.4914 + (float)0.364594, (float)0.371460, (float)0.378357, 1.4915 + (float)0.385284, (float)0.392212, (float)0.399170, 1.4916 + (float)0.406158, (float)0.413177, (float)0.420197, 1.4917 + (float)0.427246, (float)0.434296, (float)0.441376, 1.4918 + (float)0.448456, (float)0.455536, (float)0.462646, 1.4919 + (float)0.469757, (float)0.476868, (float)0.483978, 1.4920 + (float)0.491089, (float)0.498230, (float)0.505341, 1.4921 + (float)0.512451, (float)0.519592, (float)0.526703, 1.4922 + (float)0.533813, (float)0.540924, (float)0.548004, 1.4923 + (float)0.555084, (float)0.562164, (float)0.569244, 1.4924 + (float)0.576294, (float)0.583313, (float)0.590332, 1.4925 + (float)0.597321, (float)0.604309, (float)0.611267, 1.4926 + (float)0.618195, (float)0.625092, (float)0.631989, 1.4927 + (float)0.638855, (float)0.645660, (float)0.652466, 1.4928 + (float)0.659241, (float)0.665985, (float)0.672668, 1.4929 + (float)0.679352, (float)0.685974, (float)0.692566, 1.4930 + 1.4931 + 1.4932 + 1.4933 +Andersen, et al. Experimental [Page 88] 1.4934 + 1.4935 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4936 + 1.4937 + 1.4938 + (float)0.699127, (float)0.705658, (float)0.712128, 1.4939 + (float)0.718536, (float)0.724945, (float)0.731262, 1.4940 + (float)0.737549, (float)0.743805, (float)0.750000, 1.4941 + (float)0.756134, (float)0.762238, (float)0.768280, 1.4942 + (float)0.774261, (float)0.780182, (float)0.786072, 1.4943 + (float)0.791870, (float)0.797638, (float)0.803314, 1.4944 + (float)0.808960, (float)0.814514, (float)0.820038, 1.4945 + (float)0.825470, (float)0.830841, (float)0.836151, 1.4946 + (float)0.841400, (float)0.846558, (float)0.851654, 1.4947 + (float)0.856689, (float)0.861633, (float)0.866516, 1.4948 + (float)0.871338, (float)0.876068, (float)0.880737, 1.4949 + (float)0.885315, (float)0.889801, (float)0.894226, 1.4950 + (float)0.898560, (float)0.902832, (float)0.907013, 1.4951 + (float)0.911102, (float)0.915100, (float)0.919037, 1.4952 + (float)0.922882, (float)0.926636, (float)0.930328, 1.4953 + (float)0.933899, (float)0.937408, (float)0.940796, 1.4954 + (float)0.944122, (float)0.947357, (float)0.950470, 1.4955 + (float)0.953522, (float)0.956482, (float)0.959351, 1.4956 + (float)0.962097, (float)0.964783, (float)0.967377, 1.4957 + (float)0.969849, (float)0.972229, (float)0.974518, 1.4958 + (float)0.976715, (float)0.978821, (float)0.980835, 1.4959 + (float)0.982727, (float)0.984528, (float)0.986237, 1.4960 + (float)0.987854, (float)0.989380, (float)0.990784, 1.4961 + (float)0.992096, (float)0.993317, (float)0.994415, 1.4962 + (float)0.995422, (float)0.996338, (float)0.997162, 1.4963 + (float)0.997864, (float)0.998474, (float)0.998962, 1.4964 + (float)0.999390, (float)0.999695, (float)0.999878, 1.4965 + (float)0.999969, (float)0.999969, (float)0.996918, 1.4966 + (float)0.987701, (float)0.972382, (float)0.951050, 1.4967 + (float)0.923889, (float)0.891022, (float)0.852631, 1.4968 + (float)0.809021, (float)0.760406, (float)0.707092, 1.4969 + (float)0.649445, (float)0.587799, (float)0.522491, 1.4970 + (float)0.453979, (float)0.382690, (float)0.309021, 1.4971 + (float)0.233459, (float)0.156433, (float)0.078461 1.4972 + }; 1.4973 + 1.4974 + /* Lag window for LPC */ 1.4975 + float lpc_lagwinTbl[LPC_FILTERORDER + 1]={ 1.4976 + (float)1.000100, (float)0.998890, (float)0.995569, 1.4977 + (float)0.990057, (float)0.982392, 1.4978 + (float)0.972623, (float)0.960816, (float)0.947047, 1.4979 + (float)0.931405, (float)0.913989, (float)0.894909}; 1.4980 + 1.4981 + /* LSF quantization*/ 1.4982 + float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = { 1.4983 + (float)0.155396, (float)0.273193, (float)0.451172, 1.4984 + (float)0.390503, (float)0.648071, (float)1.002075, 1.4985 + (float)0.440186, (float)0.692261, (float)0.955688, 1.4986 + 1.4987 + 1.4988 + 1.4989 +Andersen, et al. Experimental [Page 89] 1.4990 + 1.4991 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.4992 + 1.4993 + 1.4994 + (float)0.343628, (float)0.642334, (float)1.071533, 1.4995 + (float)0.318359, (float)0.491577, (float)0.670532, 1.4996 + (float)0.193115, (float)0.375488, (float)0.725708, 1.4997 + (float)0.364136, (float)0.510376, (float)0.658691, 1.4998 + (float)0.297485, (float)0.527588, (float)0.842529, 1.4999 + (float)0.227173, (float)0.365967, (float)0.563110, 1.5000 + (float)0.244995, (float)0.396729, (float)0.636475, 1.5001 + (float)0.169434, (float)0.300171, (float)0.520264, 1.5002 + (float)0.312866, (float)0.464478, (float)0.643188, 1.5003 + (float)0.248535, (float)0.429932, (float)0.626099, 1.5004 + (float)0.236206, (float)0.491333, (float)0.817139, 1.5005 + (float)0.334961, (float)0.625122, (float)0.895752, 1.5006 + (float)0.343018, (float)0.518555, (float)0.698608, 1.5007 + (float)0.372803, (float)0.659790, (float)0.945435, 1.5008 + (float)0.176880, (float)0.316528, (float)0.581421, 1.5009 + (float)0.416382, (float)0.625977, (float)0.805176, 1.5010 + (float)0.303223, (float)0.568726, (float)0.915039, 1.5011 + (float)0.203613, (float)0.351440, (float)0.588135, 1.5012 + (float)0.221191, (float)0.375000, (float)0.614746, 1.5013 + (float)0.199951, (float)0.323364, (float)0.476074, 1.5014 + (float)0.300781, (float)0.433350, (float)0.566895, 1.5015 + (float)0.226196, (float)0.354004, (float)0.507568, 1.5016 + (float)0.300049, (float)0.508179, (float)0.711670, 1.5017 + (float)0.312012, (float)0.492676, (float)0.763428, 1.5018 + (float)0.329956, (float)0.541016, (float)0.795776, 1.5019 + (float)0.373779, (float)0.604614, (float)0.928833, 1.5020 + (float)0.210571, (float)0.452026, (float)0.755249, 1.5021 + (float)0.271118, (float)0.473267, (float)0.662476, 1.5022 + (float)0.285522, (float)0.436890, (float)0.634399, 1.5023 + (float)0.246704, (float)0.565552, (float)0.859009, 1.5024 + (float)0.270508, (float)0.406250, (float)0.553589, 1.5025 + (float)0.361450, (float)0.578491, (float)0.813843, 1.5026 + (float)0.342651, (float)0.482788, (float)0.622437, 1.5027 + (float)0.340332, (float)0.549438, (float)0.743164, 1.5028 + (float)0.200439, (float)0.336304, (float)0.540894, 1.5029 + (float)0.407837, (float)0.644775, (float)0.895142, 1.5030 + (float)0.294678, (float)0.454834, (float)0.699097, 1.5031 + (float)0.193115, (float)0.344482, (float)0.643188, 1.5032 + (float)0.275757, (float)0.420776, (float)0.598755, 1.5033 + (float)0.380493, (float)0.608643, (float)0.861084, 1.5034 + (float)0.222778, (float)0.426147, (float)0.676514, 1.5035 + (float)0.407471, (float)0.700195, (float)1.053101, 1.5036 + (float)0.218384, (float)0.377197, (float)0.669922, 1.5037 + (float)0.313232, (float)0.454102, (float)0.600952, 1.5038 + (float)0.347412, (float)0.571533, (float)0.874146, 1.5039 + (float)0.238037, (float)0.405396, (float)0.729492, 1.5040 + (float)0.223877, (float)0.412964, (float)0.822021, 1.5041 + (float)0.395264, (float)0.582153, (float)0.743896, 1.5042 + 1.5043 + 1.5044 + 1.5045 +Andersen, et al. Experimental [Page 90] 1.5046 + 1.5047 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5048 + 1.5049 + 1.5050 + (float)0.247925, (float)0.485596, (float)0.720581, 1.5051 + (float)0.229126, (float)0.496582, (float)0.907715, 1.5052 + (float)0.260132, (float)0.566895, (float)1.012695, 1.5053 + (float)0.337402, (float)0.611572, (float)0.978149, 1.5054 + (float)0.267822, (float)0.447632, (float)0.769287, 1.5055 + (float)0.250610, (float)0.381714, (float)0.530029, 1.5056 + (float)0.430054, (float)0.805054, (float)1.221924, 1.5057 + (float)0.382568, (float)0.544067, (float)0.701660, 1.5058 + (float)0.383545, (float)0.710327, (float)1.149170, 1.5059 + (float)0.271362, (float)0.529053, (float)0.775513, 1.5060 + (float)0.246826, (float)0.393555, (float)0.588623, 1.5061 + (float)0.266846, (float)0.422119, (float)0.676758, 1.5062 + (float)0.311523, (float)0.580688, (float)0.838623, 1.5063 + (float)1.331177, (float)1.576782, (float)1.779541, 1.5064 + (float)1.160034, (float)1.401978, (float)1.768188, 1.5065 + (float)1.161865, (float)1.525146, (float)1.715332, 1.5066 + (float)0.759521, (float)0.913940, (float)1.119873, 1.5067 + (float)0.947144, (float)1.121338, (float)1.282471, 1.5068 + (float)1.015015, (float)1.557007, (float)1.804932, 1.5069 + (float)1.172974, (float)1.402100, (float)1.692627, 1.5070 + (float)1.087524, (float)1.474243, (float)1.665405, 1.5071 + (float)0.899536, (float)1.105225, (float)1.406250, 1.5072 + (float)1.148438, (float)1.484741, (float)1.796265, 1.5073 + (float)0.785645, (float)1.209839, (float)1.567749, 1.5074 + (float)0.867798, (float)1.166504, (float)1.450684, 1.5075 + (float)0.922485, (float)1.229858, (float)1.420898, 1.5076 + (float)0.791260, (float)1.123291, (float)1.409546, 1.5077 + (float)0.788940, (float)0.966064, (float)1.340332, 1.5078 + (float)1.051147, (float)1.272827, (float)1.556641, 1.5079 + (float)0.866821, (float)1.181152, (float)1.538818, 1.5080 + (float)0.906738, (float)1.373535, (float)1.607910, 1.5081 + (float)1.244751, (float)1.581421, (float)1.933838, 1.5082 + (float)0.913940, (float)1.337280, (float)1.539673, 1.5083 + (float)0.680542, (float)0.959229, (float)1.662720, 1.5084 + (float)0.887207, (float)1.430542, (float)1.800781, 1.5085 + (float)0.912598, (float)1.433594, (float)1.683960, 1.5086 + (float)0.860474, (float)1.060303, (float)1.455322, 1.5087 + (float)1.005127, (float)1.381104, (float)1.706909, 1.5088 + (float)0.800781, (float)1.363892, (float)1.829102, 1.5089 + (float)0.781860, (float)1.124390, (float)1.505981, 1.5090 + (float)1.003662, (float)1.471436, (float)1.684692, 1.5091 + (float)0.981323, (float)1.309570, (float)1.618042, 1.5092 + (float)1.228760, (float)1.554321, (float)1.756470, 1.5093 + (float)0.734375, (float)0.895752, (float)1.225586, 1.5094 + (float)0.841797, (float)1.055664, (float)1.249268, 1.5095 + (float)0.920166, (float)1.119385, (float)1.486206, 1.5096 + (float)0.894409, (float)1.539063, (float)1.828979, 1.5097 + (float)1.283691, (float)1.543335, (float)1.858276, 1.5098 + 1.5099 + 1.5100 + 1.5101 +Andersen, et al. Experimental [Page 91] 1.5102 + 1.5103 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5104 + 1.5105 + 1.5106 + (float)0.676025, (float)0.933105, (float)1.490845, 1.5107 + (float)0.821289, (float)1.491821, (float)1.739868, 1.5108 + (float)0.923218, (float)1.144653, (float)1.580566, 1.5109 + (float)1.057251, (float)1.345581, (float)1.635864, 1.5110 + (float)0.888672, (float)1.074951, (float)1.353149, 1.5111 + (float)0.942749, (float)1.195435, (float)1.505493, 1.5112 + (float)1.492310, (float)1.788086, (float)2.039673, 1.5113 + (float)1.070313, (float)1.634399, (float)1.860962, 1.5114 + (float)1.253296, (float)1.488892, (float)1.686035, 1.5115 + (float)0.647095, (float)0.864014, (float)1.401855, 1.5116 + (float)0.866699, (float)1.254883, (float)1.453369, 1.5117 + (float)1.063965, (float)1.532593, (float)1.731323, 1.5118 + (float)1.167847, (float)1.521484, (float)1.884033, 1.5119 + (float)0.956055, (float)1.502075, (float)1.745605, 1.5120 + (float)0.928711, (float)1.288574, (float)1.479614, 1.5121 + (float)1.088013, (float)1.380737, (float)1.570801, 1.5122 + (float)0.905029, (float)1.186768, (float)1.371948, 1.5123 + (float)1.057861, (float)1.421021, (float)1.617432, 1.5124 + (float)1.108276, (float)1.312500, (float)1.501465, 1.5125 + (float)0.979492, (float)1.416992, (float)1.624268, 1.5126 + (float)1.276001, (float)1.661011, (float)2.007935, 1.5127 + (float)0.993042, (float)1.168579, (float)1.331665, 1.5128 + (float)0.778198, (float)0.944946, (float)1.235962, 1.5129 + (float)1.223755, (float)1.491333, (float)1.815674, 1.5130 + (float)0.852661, (float)1.350464, (float)1.722290, 1.5131 + (float)1.134766, (float)1.593140, (float)1.787354, 1.5132 + (float)1.051392, (float)1.339722, (float)1.531006, 1.5133 + (float)0.803589, (float)1.271240, (float)1.652100, 1.5134 + (float)0.755737, (float)1.143555, (float)1.639404, 1.5135 + (float)0.700928, (float)0.837280, (float)1.130371, 1.5136 + (float)0.942749, (float)1.197876, (float)1.669800, 1.5137 + (float)0.993286, (float)1.378296, (float)1.566528, 1.5138 + (float)0.801025, (float)1.095337, (float)1.298950, 1.5139 + (float)0.739990, (float)1.032959, (float)1.383667, 1.5140 + (float)0.845703, (float)1.072266, (float)1.543823, 1.5141 + (float)0.915649, (float)1.072266, (float)1.224487, 1.5142 + (float)1.021973, (float)1.226196, (float)1.481323, 1.5143 + (float)0.999878, (float)1.204102, (float)1.555908, 1.5144 + (float)0.722290, (float)0.913940, (float)1.340210, 1.5145 + (float)0.673340, (float)0.835938, (float)1.259521, 1.5146 + (float)0.832397, (float)1.208374, (float)1.394165, 1.5147 + (float)0.962158, (float)1.576172, (float)1.912842, 1.5148 + (float)1.166748, (float)1.370850, (float)1.556763, 1.5149 + (float)0.946289, (float)1.138550, (float)1.400391, 1.5150 + (float)1.035034, (float)1.218262, (float)1.386475, 1.5151 + (float)1.393799, (float)1.717773, (float)2.000244, 1.5152 + (float)0.972656, (float)1.260986, (float)1.760620, 1.5153 + (float)1.028198, (float)1.288452, (float)1.484619, 1.5154 + 1.5155 + 1.5156 + 1.5157 +Andersen, et al. Experimental [Page 92] 1.5158 + 1.5159 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5160 + 1.5161 + 1.5162 + (float)0.773560, (float)1.258057, (float)1.756714, 1.5163 + (float)1.080322, (float)1.328003, (float)1.742676, 1.5164 + (float)0.823975, (float)1.450806, (float)1.917725, 1.5165 + (float)0.859009, (float)1.016602, (float)1.191895, 1.5166 + (float)0.843994, (float)1.131104, (float)1.645020, 1.5167 + (float)1.189697, (float)1.702759, (float)1.894409, 1.5168 + (float)1.346680, (float)1.763184, (float)2.066040, 1.5169 + (float)0.980469, (float)1.253784, (float)1.441650, 1.5170 + (float)1.338135, (float)1.641968, (float)1.932739, 1.5171 + (float)1.223267, (float)1.424194, (float)1.626465, 1.5172 + (float)0.765747, (float)1.004150, (float)1.579102, 1.5173 + (float)1.042847, (float)1.269165, (float)1.647461, 1.5174 + (float)0.968750, (float)1.257568, (float)1.555786, 1.5175 + (float)0.826294, (float)0.993408, (float)1.275146, 1.5176 + (float)0.742310, (float)0.950439, (float)1.430542, 1.5177 + (float)1.054321, (float)1.439819, (float)1.828003, 1.5178 + (float)1.072998, (float)1.261719, (float)1.441895, 1.5179 + (float)0.859375, (float)1.036377, (float)1.314819, 1.5180 + (float)0.895752, (float)1.267212, (float)1.605591, 1.5181 + (float)0.805420, (float)0.962891, (float)1.142334, 1.5182 + (float)0.795654, (float)1.005493, (float)1.468506, 1.5183 + (float)1.105347, (float)1.313843, (float)1.584839, 1.5184 + (float)0.792236, (float)1.221802, (float)1.465698, 1.5185 + (float)1.170532, (float)1.467651, (float)1.664063, 1.5186 + (float)0.838257, (float)1.153198, (float)1.342163, 1.5187 + (float)0.968018, (float)1.198242, (float)1.391235, 1.5188 + (float)1.250122, (float)1.623535, (float)1.823608, 1.5189 + (float)0.711670, (float)1.058350, (float)1.512085, 1.5190 + (float)1.204834, (float)1.454468, (float)1.739136, 1.5191 + (float)1.137451, (float)1.421753, (float)1.620117, 1.5192 + (float)0.820435, (float)1.322754, (float)1.578247, 1.5193 + (float)0.798706, (float)1.005005, (float)1.213867, 1.5194 + (float)0.980713, (float)1.324951, (float)1.512939, 1.5195 + (float)1.112305, (float)1.438843, (float)1.735596, 1.5196 + (float)1.135498, (float)1.356689, (float)1.635742, 1.5197 + (float)1.101318, (float)1.387451, (float)1.686523, 1.5198 + (float)0.849854, (float)1.276978, (float)1.523438, 1.5199 + (float)1.377930, (float)1.627563, (float)1.858154, 1.5200 + (float)0.884888, (float)1.095459, (float)1.287476, 1.5201 + (float)1.289795, (float)1.505859, (float)1.756592, 1.5202 + (float)0.817505, (float)1.384155, (float)1.650513, 1.5203 + (float)1.446655, (float)1.702148, (float)1.931885, 1.5204 + (float)0.835815, (float)1.023071, (float)1.385376, 1.5205 + (float)0.916626, (float)1.139038, (float)1.335327, 1.5206 + (float)0.980103, (float)1.174072, (float)1.453735, 1.5207 + (float)1.705688, (float)2.153809, (float)2.398315, (float)2.743408, 1.5208 + (float)1.797119, (float)2.016846, (float)2.445679, (float)2.701904, 1.5209 + (float)1.990356, (float)2.219116, (float)2.576416, (float)2.813477, 1.5210 + 1.5211 + 1.5212 + 1.5213 +Andersen, et al. Experimental [Page 93] 1.5214 + 1.5215 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5216 + 1.5217 + 1.5218 + (float)1.849365, (float)2.190918, (float)2.611572, (float)2.835083, 1.5219 + (float)1.657959, (float)1.854370, (float)2.159058, (float)2.726196, 1.5220 + (float)1.437744, (float)1.897705, (float)2.253174, (float)2.655396, 1.5221 + (float)2.028687, (float)2.247314, (float)2.542358, (float)2.875854, 1.5222 + (float)1.736938, (float)1.922119, (float)2.185913, (float)2.743408, 1.5223 + (float)1.521606, (float)1.870972, (float)2.526855, (float)2.786987, 1.5224 + (float)1.841431, (float)2.050659, (float)2.463623, (float)2.857666, 1.5225 + (float)1.590088, (float)2.067261, (float)2.427979, (float)2.794434, 1.5226 + (float)1.746826, (float)2.057373, (float)2.320190, (float)2.800781, 1.5227 + (float)1.734619, (float)1.940552, (float)2.306030, (float)2.826416, 1.5228 + (float)1.786255, (float)2.204468, (float)2.457520, (float)2.795288, 1.5229 + (float)1.861084, (float)2.170532, (float)2.414551, (float)2.763672, 1.5230 + (float)2.001465, (float)2.307617, (float)2.552734, (float)2.811890, 1.5231 + (float)1.784424, (float)2.124146, (float)2.381592, (float)2.645508, 1.5232 + (float)1.888794, (float)2.135864, (float)2.418579, (float)2.861206, 1.5233 + (float)2.301147, (float)2.531250, (float)2.724976, (float)2.913086, 1.5234 + (float)1.837769, (float)2.051270, (float)2.261963, (float)2.553223, 1.5235 + (float)2.012939, (float)2.221191, (float)2.440186, (float)2.678101, 1.5236 + (float)1.429565, (float)1.858276, (float)2.582275, (float)2.845703, 1.5237 + (float)1.622803, (float)1.897705, (float)2.367310, (float)2.621094, 1.5238 + (float)1.581543, (float)1.960449, (float)2.515869, (float)2.736450, 1.5239 + (float)1.419434, (float)1.933960, (float)2.394653, (float)2.746704, 1.5240 + (float)1.721924, (float)2.059570, (float)2.421753, (float)2.769653, 1.5241 + (float)1.911011, (float)2.220703, (float)2.461060, (float)2.740723, 1.5242 + (float)1.581177, (float)1.860840, (float)2.516968, (float)2.874634, 1.5243 + (float)1.870361, (float)2.098755, (float)2.432373, (float)2.656494, 1.5244 + (float)2.059692, (float)2.279785, (float)2.495605, (float)2.729370, 1.5245 + (float)1.815674, (float)2.181519, (float)2.451538, (float)2.680542, 1.5246 + (float)1.407959, (float)1.768311, (float)2.343018, (float)2.668091, 1.5247 + (float)2.168701, (float)2.394653, (float)2.604736, (float)2.829346, 1.5248 + (float)1.636230, (float)1.865723, (float)2.329102, (float)2.824219, 1.5249 + (float)1.878906, (float)2.139526, (float)2.376709, (float)2.679810, 1.5250 + (float)1.765381, (float)1.971802, (float)2.195435, (float)2.586914, 1.5251 + (float)2.164795, (float)2.410889, (float)2.673706, (float)2.903198, 1.5252 + (float)2.071899, (float)2.331055, (float)2.645874, (float)2.907104, 1.5253 + (float)2.026001, (float)2.311523, (float)2.594849, (float)2.863892, 1.5254 + (float)1.948975, (float)2.180786, (float)2.514893, (float)2.797852, 1.5255 + (float)1.881836, (float)2.130859, (float)2.478149, (float)2.804199, 1.5256 + (float)2.238159, (float)2.452759, (float)2.652832, (float)2.868286, 1.5257 + (float)1.897949, (float)2.101685, (float)2.524292, (float)2.880127, 1.5258 + (float)1.856445, (float)2.074585, (float)2.541016, (float)2.791748, 1.5259 + (float)1.695557, (float)2.199097, (float)2.506226, (float)2.742676, 1.5260 + (float)1.612671, (float)1.877075, (float)2.435425, (float)2.732910, 1.5261 + (float)1.568848, (float)1.786499, (float)2.194580, (float)2.768555, 1.5262 + (float)1.953369, (float)2.164551, (float)2.486938, (float)2.874023, 1.5263 + (float)1.388306, (float)1.725342, (float)2.384521, (float)2.771851, 1.5264 + (float)2.115356, (float)2.337769, (float)2.592896, (float)2.864014, 1.5265 + (float)1.905762, (float)2.111328, (float)2.363525, (float)2.789307, 1.5266 + 1.5267 + 1.5268 + 1.5269 +Andersen, et al. Experimental [Page 94] 1.5270 + 1.5271 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5272 + 1.5273 + 1.5274 + (float)1.882568, (float)2.332031, (float)2.598267, (float)2.827637, 1.5275 + (float)1.683594, (float)2.088745, (float)2.361938, (float)2.608643, 1.5276 + (float)1.874023, (float)2.182129, (float)2.536133, (float)2.766968, 1.5277 + (float)1.861938, (float)2.070435, (float)2.309692, (float)2.700562, 1.5278 + (float)1.722168, (float)2.107422, (float)2.477295, (float)2.837646, 1.5279 + (float)1.926880, (float)2.184692, (float)2.442627, (float)2.663818, 1.5280 + (float)2.123901, (float)2.337280, (float)2.553101, (float)2.777466, 1.5281 + (float)1.588135, (float)1.911499, (float)2.212769, (float)2.543945, 1.5282 + (float)2.053955, (float)2.370850, (float)2.712158, (float)2.939941, 1.5283 + (float)2.210449, (float)2.519653, (float)2.770386, (float)2.958618, 1.5284 + (float)2.199463, (float)2.474731, (float)2.718262, (float)2.919922, 1.5285 + (float)1.960083, (float)2.175415, (float)2.608032, (float)2.888794, 1.5286 + (float)1.953735, (float)2.185181, (float)2.428223, (float)2.809570, 1.5287 + (float)1.615234, (float)2.036499, (float)2.576538, (float)2.834595, 1.5288 + (float)1.621094, (float)2.028198, (float)2.431030, (float)2.664673, 1.5289 + (float)1.824951, (float)2.267456, (float)2.514526, (float)2.747925, 1.5290 + (float)1.994263, (float)2.229126, (float)2.475220, (float)2.833984, 1.5291 + (float)1.746338, (float)2.011353, (float)2.588257, (float)2.826904, 1.5292 + (float)1.562866, (float)2.135986, (float)2.471680, (float)2.687256, 1.5293 + (float)1.748901, (float)2.083496, (float)2.460938, (float)2.686279, 1.5294 + (float)1.758057, (float)2.131470, (float)2.636597, (float)2.891602, 1.5295 + (float)2.071289, (float)2.299072, (float)2.550781, (float)2.814331, 1.5296 + (float)1.839600, (float)2.094360, (float)2.496460, (float)2.723999, 1.5297 + (float)1.882202, (float)2.088257, (float)2.636841, (float)2.923096, 1.5298 + (float)1.957886, (float)2.153198, (float)2.384399, (float)2.615234, 1.5299 + (float)1.992920, (float)2.351196, (float)2.654419, (float)2.889771, 1.5300 + (float)2.012817, (float)2.262451, (float)2.643799, (float)2.903076, 1.5301 + (float)2.025635, (float)2.254761, (float)2.508423, (float)2.784058, 1.5302 + (float)2.316040, (float)2.589355, (float)2.794189, (float)2.963623, 1.5303 + (float)1.741211, (float)2.279541, (float)2.578491, (float)2.816284, 1.5304 + (float)1.845337, (float)2.055786, (float)2.348511, (float)2.822021, 1.5305 + (float)1.679932, (float)1.926514, (float)2.499756, (float)2.835693, 1.5306 + (float)1.722534, (float)1.946899, (float)2.448486, (float)2.728760, 1.5307 + (float)1.829834, (float)2.043213, (float)2.580444, (float)2.867676, 1.5308 + (float)1.676636, (float)2.071655, (float)2.322510, (float)2.704834, 1.5309 + (float)1.791504, (float)2.113525, (float)2.469727, (float)2.784058, 1.5310 + (float)1.977051, (float)2.215088, (float)2.497437, (float)2.726929, 1.5311 + (float)1.800171, (float)2.106689, (float)2.357788, (float)2.738892, 1.5312 + (float)1.827759, (float)2.170166, (float)2.525879, (float)2.852417, 1.5313 + (float)1.918335, (float)2.132813, (float)2.488403, (float)2.728149, 1.5314 + (float)1.916748, (float)2.225098, (float)2.542603, (float)2.857666, 1.5315 + (float)1.761230, (float)1.976074, (float)2.507446, (float)2.884521, 1.5316 + (float)2.053711, (float)2.367432, (float)2.608032, (float)2.837646, 1.5317 + (float)1.595337, (float)2.000977, (float)2.307129, (float)2.578247, 1.5318 + (float)1.470581, (float)2.031250, (float)2.375854, (float)2.647583, 1.5319 + (float)1.801392, (float)2.128052, (float)2.399780, (float)2.822876, 1.5320 + (float)1.853638, (float)2.066650, (float)2.429199, (float)2.751465, 1.5321 + (float)1.956299, (float)2.163696, (float)2.394775, (float)2.734253, 1.5322 + 1.5323 + 1.5324 + 1.5325 +Andersen, et al. Experimental [Page 95] 1.5326 + 1.5327 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5328 + 1.5329 + 1.5330 + (float)1.963623, (float)2.275757, (float)2.585327, (float)2.865234, 1.5331 + (float)1.887451, (float)2.105469, (float)2.331787, (float)2.587402, 1.5332 + (float)2.120117, (float)2.443359, (float)2.733887, (float)2.941406, 1.5333 + (float)1.506348, (float)1.766968, (float)2.400513, (float)2.851807, 1.5334 + (float)1.664551, (float)1.981079, (float)2.375732, (float)2.774414, 1.5335 + (float)1.720703, (float)1.978882, (float)2.391479, (float)2.640991, 1.5336 + (float)1.483398, (float)1.814819, (float)2.434448, (float)2.722290, 1.5337 + (float)1.769043, (float)2.136597, (float)2.563721, (float)2.774414, 1.5338 + (float)1.810791, (float)2.049316, (float)2.373901, (float)2.613647, 1.5339 + (float)1.788330, (float)2.005981, (float)2.359131, (float)2.723145, 1.5340 + (float)1.785156, (float)1.993164, (float)2.399780, (float)2.832520, 1.5341 + (float)1.695313, (float)2.022949, (float)2.522583, (float)2.745117, 1.5342 + (float)1.584106, (float)1.965576, (float)2.299927, (float)2.715576, 1.5343 + (float)1.894897, (float)2.249878, (float)2.655884, (float)2.897705, 1.5344 + (float)1.720581, (float)1.995728, (float)2.299438, (float)2.557007, 1.5345 + (float)1.619385, (float)2.173950, (float)2.574219, (float)2.787964, 1.5346 + (float)1.883179, (float)2.220459, (float)2.474365, (float)2.825073, 1.5347 + (float)1.447632, (float)2.045044, (float)2.555542, (float)2.744873, 1.5348 + (float)1.502686, (float)2.156616, (float)2.653320, (float)2.846558, 1.5349 + (float)1.711548, (float)1.944092, (float)2.282959, (float)2.685791, 1.5350 + (float)1.499756, (float)1.867554, (float)2.341064, (float)2.578857, 1.5351 + (float)1.916870, (float)2.135132, (float)2.568237, (float)2.826050, 1.5352 + (float)1.498047, (float)1.711182, (float)2.223267, (float)2.755127, 1.5353 + (float)1.808716, (float)1.997559, (float)2.256470, (float)2.758545, 1.5354 + (float)2.088501, (float)2.402710, (float)2.667358, (float)2.890259, 1.5355 + (float)1.545044, (float)1.819214, (float)2.324097, (float)2.692993, 1.5356 + (float)1.796021, (float)2.012573, (float)2.505737, (float)2.784912, 1.5357 + (float)1.786499, (float)2.041748, (float)2.290405, (float)2.650757, 1.5358 + (float)1.938232, (float)2.264404, (float)2.529053, (float)2.796143 1.5359 + }; 1.5360 + 1.5361 +A.9. anaFilter.h 1.5362 + 1.5363 + /****************************************************************** 1.5364 + 1.5365 + iLBC Speech Coder ANSI-C Source Code 1.5366 + 1.5367 + anaFilter.h 1.5368 + 1.5369 + Copyright (C) The Internet Society (2004). 1.5370 + All Rights Reserved. 1.5371 + 1.5372 + ******************************************************************/ 1.5373 + 1.5374 + #ifndef __iLBC_ANAFILTER_H 1.5375 + #define __iLBC_ANAFILTER_H 1.5376 + 1.5377 + void anaFilter( 1.5378 + 1.5379 + 1.5380 + 1.5381 +Andersen, et al. Experimental [Page 96] 1.5382 + 1.5383 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5384 + 1.5385 + 1.5386 + float *In, /* (i) Signal to be filtered */ 1.5387 + float *a, /* (i) LP parameters */ 1.5388 + int len,/* (i) Length of signal */ 1.5389 + float *Out, /* (o) Filtered signal */ 1.5390 + float *mem /* (i/o) Filter state */ 1.5391 + ); 1.5392 + 1.5393 + #endif 1.5394 + 1.5395 +A.10. anaFilter.c 1.5396 + 1.5397 + /****************************************************************** 1.5398 + 1.5399 + iLBC Speech Coder ANSI-C Source Code 1.5400 + 1.5401 + anaFilter.c 1.5402 + 1.5403 + Copyright (C) The Internet Society (2004). 1.5404 + All Rights Reserved. 1.5405 + 1.5406 + ******************************************************************/ 1.5407 + 1.5408 + #include <string.h> 1.5409 + #include "iLBC_define.h" 1.5410 + 1.5411 + /*----------------------------------------------------------------* 1.5412 + * LP analysis filter. 1.5413 + *---------------------------------------------------------------*/ 1.5414 + 1.5415 + void anaFilter( 1.5416 + float *In, /* (i) Signal to be filtered */ 1.5417 + float *a, /* (i) LP parameters */ 1.5418 + int len,/* (i) Length of signal */ 1.5419 + float *Out, /* (o) Filtered signal */ 1.5420 + float *mem /* (i/o) Filter state */ 1.5421 + ){ 1.5422 + int i, j; 1.5423 + float *po, *pi, *pm, *pa; 1.5424 + 1.5425 + po = Out; 1.5426 + 1.5427 + /* Filter first part using memory from past */ 1.5428 + 1.5429 + for (i=0; i<LPC_FILTERORDER; i++) { 1.5430 + pi = &In[i]; 1.5431 + pm = &mem[LPC_FILTERORDER-1]; 1.5432 + pa = a; 1.5433 + *po=0.0; 1.5434 + 1.5435 + 1.5436 + 1.5437 +Andersen, et al. Experimental [Page 97] 1.5438 + 1.5439 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5440 + 1.5441 + 1.5442 + for (j=0; j<=i; j++) { 1.5443 + *po+=(*pa++)*(*pi--); 1.5444 + } 1.5445 + for (j=i+1; j<LPC_FILTERORDER+1; j++) { 1.5446 + 1.5447 + *po+=(*pa++)*(*pm--); 1.5448 + } 1.5449 + po++; 1.5450 + } 1.5451 + 1.5452 + /* Filter last part where the state is entirely 1.5453 + in the input vector */ 1.5454 + 1.5455 + for (i=LPC_FILTERORDER; i<len; i++) { 1.5456 + pi = &In[i]; 1.5457 + pa = a; 1.5458 + *po=0.0; 1.5459 + for (j=0; j<LPC_FILTERORDER+1; j++) { 1.5460 + *po+=(*pa++)*(*pi--); 1.5461 + } 1.5462 + po++; 1.5463 + } 1.5464 + 1.5465 + /* Update state vector */ 1.5466 + 1.5467 + memcpy(mem, &In[len-LPC_FILTERORDER], 1.5468 + LPC_FILTERORDER*sizeof(float)); 1.5469 + } 1.5470 + 1.5471 +A.11. createCB.h 1.5472 + 1.5473 + /****************************************************************** 1.5474 + 1.5475 + iLBC Speech Coder ANSI-C Source Code 1.5476 + 1.5477 + createCB.h 1.5478 + 1.5479 + Copyright (C) The Internet Society (2004). 1.5480 + All Rights Reserved. 1.5481 + 1.5482 + ******************************************************************/ 1.5483 + 1.5484 + #ifndef __iLBC_CREATECB_H 1.5485 + #define __iLBC_CREATECB_H 1.5486 + 1.5487 + void filteredCBvecs( 1.5488 + float *cbvectors, /* (o) Codebook vector for the 1.5489 + higher section */ 1.5490 + 1.5491 + 1.5492 + 1.5493 +Andersen, et al. Experimental [Page 98] 1.5494 + 1.5495 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5496 + 1.5497 + 1.5498 + float *mem, /* (i) Buffer to create codebook 1.5499 + vectors from */ 1.5500 + int lMem /* (i) Length of buffer */ 1.5501 + ); 1.5502 + 1.5503 + void searchAugmentedCB( 1.5504 + int low, /* (i) Start index for the search */ 1.5505 + int high, /* (i) End index for the search */ 1.5506 + int stage, /* (i) Current stage */ 1.5507 + int startIndex, /* (i) CB index for the first 1.5508 + augmented vector */ 1.5509 + float *target, /* (i) Target vector for encoding */ 1.5510 + float *buffer, /* (i) Pointer to the end of the 1.5511 + buffer for augmented codebook 1.5512 + construction */ 1.5513 + float *max_measure, /* (i/o) Currently maximum measure */ 1.5514 + int *best_index,/* (o) Currently the best index */ 1.5515 + float *gain, /* (o) Currently the best gain */ 1.5516 + float *energy, /* (o) Energy of augmented 1.5517 + codebook vectors */ 1.5518 + float *invenergy/* (o) Inv energy of aug codebook 1.5519 + vectors */ 1.5520 + ); 1.5521 + 1.5522 + void createAugmentedVec( 1.5523 + int index, /* (i) Index for the aug vector 1.5524 + to be created */ 1.5525 + float *buffer, /* (i) Pointer to the end of the 1.5526 + buffer for augmented codebook 1.5527 + construction */ 1.5528 + float *cbVec /* (o) The construced codebook vector */ 1.5529 + ); 1.5530 + 1.5531 + #endif 1.5532 + 1.5533 +A.12. createCB.c 1.5534 + 1.5535 + 1.5536 + /****************************************************************** 1.5537 + 1.5538 + iLBC Speech Coder ANSI-C Source Code 1.5539 + 1.5540 + createCB.c 1.5541 + 1.5542 + Copyright (C) The Internet Society (2004). 1.5543 + All Rights Reserved. 1.5544 + 1.5545 + ******************************************************************/ 1.5546 + 1.5547 + 1.5548 + 1.5549 +Andersen, et al. Experimental [Page 99] 1.5550 + 1.5551 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5552 + 1.5553 + 1.5554 + #include "iLBC_define.h" 1.5555 + #include "constants.h" 1.5556 + #include <string.h> 1.5557 + #include <math.h> 1.5558 + 1.5559 + /*----------------------------------------------------------------* 1.5560 + * Construct an additional codebook vector by filtering the 1.5561 + * initial codebook buffer. This vector is then used to expand 1.5562 + * the codebook with an additional section. 1.5563 + *---------------------------------------------------------------*/ 1.5564 + 1.5565 + void filteredCBvecs( 1.5566 + float *cbvectors, /* (o) Codebook vectors for the 1.5567 + higher section */ 1.5568 + float *mem, /* (i) Buffer to create codebook 1.5569 + vector from */ 1.5570 + int lMem /* (i) Length of buffer */ 1.5571 + ){ 1.5572 + int j, k; 1.5573 + float *pp, *pp1; 1.5574 + float tempbuff2[CB_MEML+CB_FILTERLEN]; 1.5575 + float *pos; 1.5576 + 1.5577 + memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float)); 1.5578 + memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float)); 1.5579 + memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0, 1.5580 + (CB_HALFFILTERLEN+1)*sizeof(float)); 1.5581 + 1.5582 + /* Create codebook vector for higher section by filtering */ 1.5583 + 1.5584 + /* do filtering */ 1.5585 + pos=cbvectors; 1.5586 + memset(pos, 0, lMem*sizeof(float)); 1.5587 + for (k=0; k<lMem; k++) { 1.5588 + pp=&tempbuff2[k]; 1.5589 + pp1=&cbfiltersTbl[CB_FILTERLEN-1]; 1.5590 + for (j=0;j<CB_FILTERLEN;j++) { 1.5591 + (*pos)+=(*pp++)*(*pp1--); 1.5592 + } 1.5593 + pos++; 1.5594 + } 1.5595 + } 1.5596 + 1.5597 + /*----------------------------------------------------------------* 1.5598 + * Search the augmented part of the codebook to find the best 1.5599 + * measure. 1.5600 + *----------------------------------------------------------------*/ 1.5601 + 1.5602 + 1.5603 + 1.5604 + 1.5605 +Andersen, et al. Experimental [Page 100] 1.5606 + 1.5607 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5608 + 1.5609 + 1.5610 + void searchAugmentedCB( 1.5611 + int low, /* (i) Start index for the search */ 1.5612 + int high, /* (i) End index for the search */ 1.5613 + int stage, /* (i) Current stage */ 1.5614 + int startIndex, /* (i) Codebook index for the first 1.5615 + aug vector */ 1.5616 + float *target, /* (i) Target vector for encoding */ 1.5617 + float *buffer, /* (i) Pointer to the end of the buffer for 1.5618 + augmented codebook construction */ 1.5619 + float *max_measure, /* (i/o) Currently maximum measure */ 1.5620 + int *best_index,/* (o) Currently the best index */ 1.5621 + float *gain, /* (o) Currently the best gain */ 1.5622 + float *energy, /* (o) Energy of augmented codebook 1.5623 + vectors */ 1.5624 + float *invenergy/* (o) Inv energy of augmented codebook 1.5625 + vectors */ 1.5626 + ) { 1.5627 + int icount, ilow, j, tmpIndex; 1.5628 + float *pp, *ppo, *ppi, *ppe, crossDot, alfa; 1.5629 + float weighted, measure, nrjRecursive; 1.5630 + float ftmp; 1.5631 + 1.5632 + /* Compute the energy for the first (low-5) 1.5633 + noninterpolated samples */ 1.5634 + nrjRecursive = (float) 0.0; 1.5635 + pp = buffer - low + 1; 1.5636 + for (j=0; j<(low-5); j++) { 1.5637 + nrjRecursive += ( (*pp)*(*pp) ); 1.5638 + pp++; 1.5639 + } 1.5640 + ppe = buffer - low; 1.5641 + 1.5642 + 1.5643 + for (icount=low; icount<=high; icount++) { 1.5644 + 1.5645 + /* Index of the codebook vector used for retrieving 1.5646 + energy values */ 1.5647 + tmpIndex = startIndex+icount-20; 1.5648 + 1.5649 + ilow = icount-4; 1.5650 + 1.5651 + /* Update the energy recursively to save complexity */ 1.5652 + nrjRecursive = nrjRecursive + (*ppe)*(*ppe); 1.5653 + ppe--; 1.5654 + energy[tmpIndex] = nrjRecursive; 1.5655 + 1.5656 + /* Compute cross dot product for the first (low-5) 1.5657 + samples */ 1.5658 + 1.5659 + 1.5660 + 1.5661 +Andersen, et al. Experimental [Page 101] 1.5662 + 1.5663 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5664 + 1.5665 + 1.5666 + crossDot = (float) 0.0; 1.5667 + pp = buffer-icount; 1.5668 + for (j=0; j<ilow; j++) { 1.5669 + crossDot += target[j]*(*pp++); 1.5670 + } 1.5671 + 1.5672 + /* interpolation */ 1.5673 + alfa = (float) 0.2; 1.5674 + ppo = buffer-4; 1.5675 + ppi = buffer-icount-4; 1.5676 + for (j=ilow; j<icount; j++) { 1.5677 + weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi); 1.5678 + ppo++; 1.5679 + ppi++; 1.5680 + energy[tmpIndex] += weighted*weighted; 1.5681 + crossDot += target[j]*weighted; 1.5682 + alfa += (float)0.2; 1.5683 + } 1.5684 + 1.5685 + /* Compute energy and cross dot product for the 1.5686 + remaining samples */ 1.5687 + pp = buffer - icount; 1.5688 + for (j=icount; j<SUBL; j++) { 1.5689 + energy[tmpIndex] += (*pp)*(*pp); 1.5690 + crossDot += target[j]*(*pp++); 1.5691 + } 1.5692 + 1.5693 + if (energy[tmpIndex]>0.0) { 1.5694 + invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS); 1.5695 + } else { 1.5696 + invenergy[tmpIndex] = (float) 0.0; 1.5697 + } 1.5698 + 1.5699 + if (stage==0) { 1.5700 + measure = (float)-10000000.0; 1.5701 + 1.5702 + if (crossDot > 0.0) { 1.5703 + measure = crossDot*crossDot*invenergy[tmpIndex]; 1.5704 + } 1.5705 + } 1.5706 + else { 1.5707 + measure = crossDot*crossDot*invenergy[tmpIndex]; 1.5708 + } 1.5709 + 1.5710 + /* check if measure is better */ 1.5711 + ftmp = crossDot*invenergy[tmpIndex]; 1.5712 + 1.5713 + if ((measure>*max_measure) && (fabs(ftmp)<CB_MAXGAIN)) { 1.5714 + 1.5715 + 1.5716 + 1.5717 +Andersen, et al. Experimental [Page 102] 1.5718 + 1.5719 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5720 + 1.5721 + 1.5722 + *best_index = tmpIndex; 1.5723 + *max_measure = measure; 1.5724 + *gain = ftmp; 1.5725 + } 1.5726 + } 1.5727 + } 1.5728 + 1.5729 + 1.5730 + /*----------------------------------------------------------------* 1.5731 + * Recreate a specific codebook vector from the augmented part. 1.5732 + * 1.5733 + *----------------------------------------------------------------*/ 1.5734 + 1.5735 + void createAugmentedVec( 1.5736 + int index, /* (i) Index for the augmented vector 1.5737 + to be created */ 1.5738 + float *buffer, /* (i) Pointer to the end of the buffer for 1.5739 + augmented codebook construction */ 1.5740 + float *cbVec/* (o) The construced codebook vector */ 1.5741 + ) { 1.5742 + int ilow, j; 1.5743 + float *pp, *ppo, *ppi, alfa, alfa1, weighted; 1.5744 + 1.5745 + ilow = index-5; 1.5746 + 1.5747 + /* copy the first noninterpolated part */ 1.5748 + 1.5749 + pp = buffer-index; 1.5750 + memcpy(cbVec,pp,sizeof(float)*index); 1.5751 + 1.5752 + /* interpolation */ 1.5753 + 1.5754 + alfa1 = (float)0.2; 1.5755 + alfa = 0.0; 1.5756 + ppo = buffer-5; 1.5757 + ppi = buffer-index-5; 1.5758 + for (j=ilow; j<index; j++) { 1.5759 + weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi); 1.5760 + ppo++; 1.5761 + ppi++; 1.5762 + cbVec[j] = weighted; 1.5763 + alfa += alfa1; 1.5764 + } 1.5765 + 1.5766 + /* copy the second noninterpolated part */ 1.5767 + 1.5768 + pp = buffer - index; 1.5769 + memcpy(cbVec+index,pp,sizeof(float)*(SUBL-index)); 1.5770 + 1.5771 + 1.5772 + 1.5773 +Andersen, et al. Experimental [Page 103] 1.5774 + 1.5775 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5776 + 1.5777 + 1.5778 + } 1.5779 + 1.5780 +A.13. doCPLC.h 1.5781 + 1.5782 + /****************************************************************** 1.5783 + 1.5784 + iLBC Speech Coder ANSI-C Source Code 1.5785 + 1.5786 + doCPLC.h 1.5787 + 1.5788 + Copyright (C) The Internet Society (2004). 1.5789 + All Rights Reserved. 1.5790 + 1.5791 + ******************************************************************/ 1.5792 + 1.5793 + #ifndef __iLBC_DOLPC_H 1.5794 + #define __iLBC_DOLPC_H 1.5795 + 1.5796 + void doThePLC( 1.5797 + float *PLCresidual, /* (o) concealed residual */ 1.5798 + float *PLClpc, /* (o) concealed LP parameters */ 1.5799 + int PLI, /* (i) packet loss indicator 1.5800 + 0 - no PL, 1 = PL */ 1.5801 + float *decresidual, /* (i) decoded residual */ 1.5802 + float *lpc, /* (i) decoded LPC (only used for no PL) */ 1.5803 + int inlag, /* (i) pitch lag */ 1.5804 + iLBC_Dec_Inst_t *iLBCdec_inst 1.5805 + /* (i/o) decoder instance */ 1.5806 + ); 1.5807 + 1.5808 + #endif 1.5809 + 1.5810 +A.14. doCPLC.c 1.5811 + 1.5812 + /****************************************************************** 1.5813 + 1.5814 + iLBC Speech Coder ANSI-C Source Code 1.5815 + 1.5816 + doCPLC.c 1.5817 + 1.5818 + Copyright (C) The Internet Society (2004). 1.5819 + All Rights Reserved. 1.5820 + 1.5821 + ******************************************************************/ 1.5822 + 1.5823 + #include <math.h> 1.5824 + #include <string.h> 1.5825 + #include <stdio.h> 1.5826 + 1.5827 + 1.5828 + 1.5829 +Andersen, et al. Experimental [Page 104] 1.5830 + 1.5831 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5832 + 1.5833 + 1.5834 + #include "iLBC_define.h" 1.5835 + 1.5836 + /*----------------------------------------------------------------* 1.5837 + * Compute cross correlation and pitch gain for pitch prediction 1.5838 + * of last subframe at given lag. 1.5839 + *---------------------------------------------------------------*/ 1.5840 + 1.5841 + void compCorr( 1.5842 + float *cc, /* (o) cross correlation coefficient */ 1.5843 + float *gc, /* (o) gain */ 1.5844 + float *pm, 1.5845 + float *buffer, /* (i) signal buffer */ 1.5846 + int lag, /* (i) pitch lag */ 1.5847 + int bLen, /* (i) length of buffer */ 1.5848 + int sRange /* (i) correlation search length */ 1.5849 + ){ 1.5850 + int i; 1.5851 + float ftmp1, ftmp2, ftmp3; 1.5852 + 1.5853 + /* Guard against getting outside buffer */ 1.5854 + if ((bLen-sRange-lag)<0) { 1.5855 + sRange=bLen-lag; 1.5856 + } 1.5857 + 1.5858 + ftmp1 = 0.0; 1.5859 + ftmp2 = 0.0; 1.5860 + ftmp3 = 0.0; 1.5861 + for (i=0; i<sRange; i++) { 1.5862 + ftmp1 += buffer[bLen-sRange+i] * 1.5863 + buffer[bLen-sRange+i-lag]; 1.5864 + ftmp2 += buffer[bLen-sRange+i-lag] * 1.5865 + buffer[bLen-sRange+i-lag]; 1.5866 + ftmp3 += buffer[bLen-sRange+i] * 1.5867 + buffer[bLen-sRange+i]; 1.5868 + } 1.5869 + 1.5870 + if (ftmp2 > 0.0) { 1.5871 + *cc = ftmp1*ftmp1/ftmp2; 1.5872 + *gc = (float)fabs(ftmp1/ftmp2); 1.5873 + *pm=(float)fabs(ftmp1)/ 1.5874 + ((float)sqrt(ftmp2)*(float)sqrt(ftmp3)); 1.5875 + } 1.5876 + else { 1.5877 + *cc = 0.0; 1.5878 + *gc = 0.0; 1.5879 + *pm=0.0; 1.5880 + } 1.5881 + } 1.5882 + 1.5883 + 1.5884 + 1.5885 +Andersen, et al. Experimental [Page 105] 1.5886 + 1.5887 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5888 + 1.5889 + 1.5890 + /*----------------------------------------------------------------* 1.5891 + * Packet loss concealment routine. Conceals a residual signal 1.5892 + * and LP parameters. If no packet loss, update state. 1.5893 + *---------------------------------------------------------------*/ 1.5894 + 1.5895 + void doThePLC( 1.5896 + float *PLCresidual, /* (o) concealed residual */ 1.5897 + float *PLClpc, /* (o) concealed LP parameters */ 1.5898 + int PLI, /* (i) packet loss indicator 1.5899 + 0 - no PL, 1 = PL */ 1.5900 + float *decresidual, /* (i) decoded residual */ 1.5901 + float *lpc, /* (i) decoded LPC (only used for no PL) */ 1.5902 + int inlag, /* (i) pitch lag */ 1.5903 + iLBC_Dec_Inst_t *iLBCdec_inst 1.5904 + /* (i/o) decoder instance */ 1.5905 + ){ 1.5906 + int lag=20, randlag; 1.5907 + float gain, maxcc; 1.5908 + float use_gain; 1.5909 + float gain_comp, maxcc_comp, per, max_per; 1.5910 + int i, pick, use_lag; 1.5911 + float ftmp, randvec[BLOCKL_MAX], pitchfact, energy; 1.5912 + 1.5913 + /* Packet Loss */ 1.5914 + 1.5915 + if (PLI == 1) { 1.5916 + 1.5917 + iLBCdec_inst->consPLICount += 1; 1.5918 + 1.5919 + /* if previous frame not lost, 1.5920 + determine pitch pred. gain */ 1.5921 + 1.5922 + if (iLBCdec_inst->prevPLI != 1) { 1.5923 + 1.5924 + /* Search around the previous lag to find the 1.5925 + best pitch period */ 1.5926 + 1.5927 + lag=inlag-3; 1.5928 + compCorr(&maxcc, &gain, &max_per, 1.5929 + iLBCdec_inst->prevResidual, 1.5930 + lag, iLBCdec_inst->blockl, 60); 1.5931 + for (i=inlag-2;i<=inlag+3;i++) { 1.5932 + compCorr(&maxcc_comp, &gain_comp, &per, 1.5933 + iLBCdec_inst->prevResidual, 1.5934 + i, iLBCdec_inst->blockl, 60); 1.5935 + 1.5936 + if (maxcc_comp>maxcc) { 1.5937 + maxcc=maxcc_comp; 1.5938 + 1.5939 + 1.5940 + 1.5941 +Andersen, et al. Experimental [Page 106] 1.5942 + 1.5943 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.5944 + 1.5945 + 1.5946 + gain=gain_comp; 1.5947 + lag=i; 1.5948 + max_per=per; 1.5949 + } 1.5950 + } 1.5951 + 1.5952 + } 1.5953 + 1.5954 + /* previous frame lost, use recorded lag and periodicity */ 1.5955 + 1.5956 + else { 1.5957 + lag=iLBCdec_inst->prevLag; 1.5958 + max_per=iLBCdec_inst->per; 1.5959 + } 1.5960 + 1.5961 + /* downscaling */ 1.5962 + 1.5963 + use_gain=1.0; 1.5964 + if (iLBCdec_inst->consPLICount*iLBCdec_inst->blockl>320) 1.5965 + use_gain=(float)0.9; 1.5966 + else if (iLBCdec_inst->consPLICount* 1.5967 + iLBCdec_inst->blockl>2*320) 1.5968 + use_gain=(float)0.7; 1.5969 + else if (iLBCdec_inst->consPLICount* 1.5970 + iLBCdec_inst->blockl>3*320) 1.5971 + use_gain=(float)0.5; 1.5972 + else if (iLBCdec_inst->consPLICount* 1.5973 + iLBCdec_inst->blockl>4*320) 1.5974 + use_gain=(float)0.0; 1.5975 + 1.5976 + /* mix noise and pitch repeatition */ 1.5977 + ftmp=(float)sqrt(max_per); 1.5978 + if (ftmp>(float)0.7) 1.5979 + pitchfact=(float)1.0; 1.5980 + else if (ftmp>(float)0.4) 1.5981 + pitchfact=(ftmp-(float)0.4)/((float)0.7-(float)0.4); 1.5982 + else 1.5983 + pitchfact=0.0; 1.5984 + 1.5985 + 1.5986 + /* avoid repetition of same pitch cycle */ 1.5987 + use_lag=lag; 1.5988 + if (lag<80) { 1.5989 + use_lag=2*lag; 1.5990 + } 1.5991 + 1.5992 + /* compute concealed residual */ 1.5993 + 1.5994 + 1.5995 + 1.5996 + 1.5997 +Andersen, et al. Experimental [Page 107] 1.5998 + 1.5999 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6000 + 1.6001 + 1.6002 + energy = 0.0; 1.6003 + for (i=0; i<iLBCdec_inst->blockl; i++) { 1.6004 + 1.6005 + /* noise component */ 1.6006 + 1.6007 + iLBCdec_inst->seed=(iLBCdec_inst->seed*69069L+1) & 1.6008 + (0x80000000L-1); 1.6009 + randlag = 50 + ((signed long) iLBCdec_inst->seed)%70; 1.6010 + pick = i - randlag; 1.6011 + 1.6012 + if (pick < 0) { 1.6013 + randvec[i] = 1.6014 + iLBCdec_inst->prevResidual[ 1.6015 + iLBCdec_inst->blockl+pick]; 1.6016 + } else { 1.6017 + randvec[i] = randvec[pick]; 1.6018 + } 1.6019 + 1.6020 + /* pitch repeatition component */ 1.6021 + pick = i - use_lag; 1.6022 + 1.6023 + if (pick < 0) { 1.6024 + PLCresidual[i] = 1.6025 + iLBCdec_inst->prevResidual[ 1.6026 + iLBCdec_inst->blockl+pick]; 1.6027 + } else { 1.6028 + PLCresidual[i] = PLCresidual[pick]; 1.6029 + } 1.6030 + 1.6031 + /* mix random and periodicity component */ 1.6032 + 1.6033 + if (i<80) 1.6034 + PLCresidual[i] = use_gain*(pitchfact * 1.6035 + PLCresidual[i] + 1.6036 + ((float)1.0 - pitchfact) * randvec[i]); 1.6037 + else if (i<160) 1.6038 + PLCresidual[i] = (float)0.95*use_gain*(pitchfact * 1.6039 + PLCresidual[i] + 1.6040 + ((float)1.0 - pitchfact) * randvec[i]); 1.6041 + else 1.6042 + PLCresidual[i] = (float)0.9*use_gain*(pitchfact * 1.6043 + PLCresidual[i] + 1.6044 + ((float)1.0 - pitchfact) * randvec[i]); 1.6045 + 1.6046 + energy += PLCresidual[i] * PLCresidual[i]; 1.6047 + } 1.6048 + 1.6049 + /* less than 30 dB, use only noise */ 1.6050 + 1.6051 + 1.6052 + 1.6053 +Andersen, et al. Experimental [Page 108] 1.6054 + 1.6055 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6056 + 1.6057 + 1.6058 + 1.6059 + if (sqrt(energy/(float)iLBCdec_inst->blockl) < 30.0) { 1.6060 + gain=0.0; 1.6061 + for (i=0; i<iLBCdec_inst->blockl; i++) { 1.6062 + PLCresidual[i] = randvec[i]; 1.6063 + } 1.6064 + } 1.6065 + 1.6066 + /* use old LPC */ 1.6067 + 1.6068 + memcpy(PLClpc,iLBCdec_inst->prevLpc, 1.6069 + (LPC_FILTERORDER+1)*sizeof(float)); 1.6070 + 1.6071 + } 1.6072 + 1.6073 + /* no packet loss, copy input */ 1.6074 + 1.6075 + else { 1.6076 + memcpy(PLCresidual, decresidual, 1.6077 + iLBCdec_inst->blockl*sizeof(float)); 1.6078 + memcpy(PLClpc, lpc, (LPC_FILTERORDER+1)*sizeof(float)); 1.6079 + iLBCdec_inst->consPLICount = 0; 1.6080 + } 1.6081 + 1.6082 + /* update state */ 1.6083 + 1.6084 + if (PLI) { 1.6085 + iLBCdec_inst->prevLag = lag; 1.6086 + iLBCdec_inst->per=max_per; 1.6087 + } 1.6088 + 1.6089 + iLBCdec_inst->prevPLI = PLI; 1.6090 + memcpy(iLBCdec_inst->prevLpc, PLClpc, 1.6091 + (LPC_FILTERORDER+1)*sizeof(float)); 1.6092 + memcpy(iLBCdec_inst->prevResidual, PLCresidual, 1.6093 + iLBCdec_inst->blockl*sizeof(float)); 1.6094 + } 1.6095 + 1.6096 +A.15. enhancer.h 1.6097 + 1.6098 + /****************************************************************** 1.6099 + 1.6100 + iLBC Speech Coder ANSI-C Source Code 1.6101 + 1.6102 + enhancer.h 1.6103 + 1.6104 + Copyright (C) The Internet Society (2004). 1.6105 + All Rights Reserved. 1.6106 + 1.6107 + 1.6108 + 1.6109 +Andersen, et al. Experimental [Page 109] 1.6110 + 1.6111 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6112 + 1.6113 + 1.6114 + ******************************************************************/ 1.6115 + 1.6116 + #ifndef __ENHANCER_H 1.6117 + #define __ENHANCER_H 1.6118 + 1.6119 + #include "iLBC_define.h" 1.6120 + 1.6121 + float xCorrCoef( 1.6122 + float *target, /* (i) first array */ 1.6123 + float *regressor, /* (i) second array */ 1.6124 + int subl /* (i) dimension arrays */ 1.6125 + ); 1.6126 + 1.6127 + int enhancerInterface( 1.6128 + float *out, /* (o) the enhanced recidual signal */ 1.6129 + float *in, /* (i) the recidual signal to enhance */ 1.6130 + iLBC_Dec_Inst_t *iLBCdec_inst 1.6131 + /* (i/o) the decoder state structure */ 1.6132 + ); 1.6133 + 1.6134 + #endif 1.6135 + 1.6136 +A.16. enhancer.c 1.6137 + 1.6138 + /****************************************************************** 1.6139 + 1.6140 + iLBC Speech Coder ANSI-C Source Code 1.6141 + 1.6142 + enhancer.c 1.6143 + 1.6144 + Copyright (C) The Internet Society (2004). 1.6145 + All Rights Reserved. 1.6146 + 1.6147 + ******************************************************************/ 1.6148 + 1.6149 + #include <math.h> 1.6150 + #include <string.h> 1.6151 + #include "iLBC_define.h" 1.6152 + #include "constants.h" 1.6153 + #include "filter.h" 1.6154 + 1.6155 + /*----------------------------------------------------------------* 1.6156 + * Find index in array such that the array element with said 1.6157 + * index is the element of said array closest to "value" 1.6158 + * according to the squared-error criterion 1.6159 + *---------------------------------------------------------------*/ 1.6160 + 1.6161 + void NearestNeighbor( 1.6162 + 1.6163 + 1.6164 + 1.6165 +Andersen, et al. Experimental [Page 110] 1.6166 + 1.6167 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6168 + 1.6169 + 1.6170 + int *index, /* (o) index of array element closest 1.6171 + to value */ 1.6172 + float *array, /* (i) data array */ 1.6173 + float value,/* (i) value */ 1.6174 + int arlength/* (i) dimension of data array */ 1.6175 + ){ 1.6176 + int i; 1.6177 + float bestcrit,crit; 1.6178 + 1.6179 + crit=array[0]-value; 1.6180 + bestcrit=crit*crit; 1.6181 + *index=0; 1.6182 + for (i=1; i<arlength; i++) { 1.6183 + crit=array[i]-value; 1.6184 + crit=crit*crit; 1.6185 + 1.6186 + if (crit<bestcrit) { 1.6187 + bestcrit=crit; 1.6188 + *index=i; 1.6189 + } 1.6190 + } 1.6191 + } 1.6192 + 1.6193 + /*----------------------------------------------------------------* 1.6194 + * compute cross correlation between sequences 1.6195 + *---------------------------------------------------------------*/ 1.6196 + 1.6197 + void mycorr1( 1.6198 + float* corr, /* (o) correlation of seq1 and seq2 */ 1.6199 + float* seq1, /* (i) first sequence */ 1.6200 + int dim1, /* (i) dimension first seq1 */ 1.6201 + const float *seq2, /* (i) second sequence */ 1.6202 + int dim2 /* (i) dimension seq2 */ 1.6203 + ){ 1.6204 + int i,j; 1.6205 + 1.6206 + for (i=0; i<=dim1-dim2; i++) { 1.6207 + corr[i]=0.0; 1.6208 + for (j=0; j<dim2; j++) { 1.6209 + corr[i] += seq1[i+j] * seq2[j]; 1.6210 + } 1.6211 + } 1.6212 + } 1.6213 + 1.6214 + /*----------------------------------------------------------------* 1.6215 + * upsample finite array assuming zeros outside bounds 1.6216 + *---------------------------------------------------------------*/ 1.6217 + 1.6218 + 1.6219 + 1.6220 + 1.6221 +Andersen, et al. Experimental [Page 111] 1.6222 + 1.6223 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6224 + 1.6225 + 1.6226 + void enh_upsample( 1.6227 + float* useq1, /* (o) upsampled output sequence */ 1.6228 + float* seq1,/* (i) unupsampled sequence */ 1.6229 + int dim1, /* (i) dimension seq1 */ 1.6230 + int hfl /* (i) polyphase filter length=2*hfl+1 */ 1.6231 + ){ 1.6232 + float *pu,*ps; 1.6233 + int i,j,k,q,filterlength,hfl2; 1.6234 + const float *polyp[ENH_UPS0]; /* pointers to 1.6235 + polyphase columns */ 1.6236 + const float *pp; 1.6237 + 1.6238 + /* define pointers for filter */ 1.6239 + 1.6240 + filterlength=2*hfl+1; 1.6241 + 1.6242 + if ( filterlength > dim1 ) { 1.6243 + hfl2=(int) (dim1/2); 1.6244 + for (j=0; j<ENH_UPS0; j++) { 1.6245 + polyp[j]=polyphaserTbl+j*filterlength+hfl-hfl2; 1.6246 + } 1.6247 + hfl=hfl2; 1.6248 + filterlength=2*hfl+1; 1.6249 + } 1.6250 + else { 1.6251 + for (j=0; j<ENH_UPS0; j++) { 1.6252 + polyp[j]=polyphaserTbl+j*filterlength; 1.6253 + } 1.6254 + } 1.6255 + 1.6256 + /* filtering: filter overhangs left side of sequence */ 1.6257 + 1.6258 + pu=useq1; 1.6259 + for (i=hfl; i<filterlength; i++) { 1.6260 + for (j=0; j<ENH_UPS0; j++) { 1.6261 + *pu=0.0; 1.6262 + pp = polyp[j]; 1.6263 + ps = seq1+i; 1.6264 + for (k=0; k<=i; k++) { 1.6265 + *pu += *ps-- * *pp++; 1.6266 + } 1.6267 + pu++; 1.6268 + } 1.6269 + } 1.6270 + 1.6271 + /* filtering: simple convolution=inner products */ 1.6272 + 1.6273 + for (i=filterlength; i<dim1; i++) { 1.6274 + 1.6275 + 1.6276 + 1.6277 +Andersen, et al. Experimental [Page 112] 1.6278 + 1.6279 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6280 + 1.6281 + 1.6282 + for (j=0;j<ENH_UPS0; j++){ 1.6283 + *pu=0.0; 1.6284 + pp = polyp[j]; 1.6285 + ps = seq1+i; 1.6286 + for (k=0; k<filterlength; k++) { 1.6287 + *pu += *ps-- * *pp++; 1.6288 + } 1.6289 + pu++; 1.6290 + } 1.6291 + } 1.6292 + 1.6293 + /* filtering: filter overhangs right side of sequence */ 1.6294 + 1.6295 + for (q=1; q<=hfl; q++) { 1.6296 + for (j=0; j<ENH_UPS0; j++) { 1.6297 + *pu=0.0; 1.6298 + pp = polyp[j]+q; 1.6299 + ps = seq1+dim1-1; 1.6300 + for (k=0; k<filterlength-q; k++) { 1.6301 + *pu += *ps-- * *pp++; 1.6302 + } 1.6303 + pu++; 1.6304 + } 1.6305 + } 1.6306 + } 1.6307 + 1.6308 + 1.6309 + /*----------------------------------------------------------------* 1.6310 + * find segment starting near idata+estSegPos that has highest 1.6311 + * correlation with idata+centerStartPos through 1.6312 + * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a 1.6313 + * resolution of ENH_UPSO times the original of the original 1.6314 + * sampling rate 1.6315 + *---------------------------------------------------------------*/ 1.6316 + 1.6317 + void refiner( 1.6318 + float *seg, /* (o) segment array */ 1.6319 + float *updStartPos, /* (o) updated start point */ 1.6320 + float* idata, /* (i) original data buffer */ 1.6321 + int idatal, /* (i) dimension of idata */ 1.6322 + int centerStartPos, /* (i) beginning center segment */ 1.6323 + float estSegPos,/* (i) estimated beginning other segment */ 1.6324 + float period /* (i) estimated pitch period */ 1.6325 + ){ 1.6326 + int estSegPosRounded,searchSegStartPos,searchSegEndPos,corrdim; 1.6327 + int tloc,tloc2,i,st,en,fraction; 1.6328 + float vect[ENH_VECTL],corrVec[ENH_CORRDIM],maxv; 1.6329 + float corrVecUps[ENH_CORRDIM*ENH_UPS0]; 1.6330 + 1.6331 + 1.6332 + 1.6333 +Andersen, et al. Experimental [Page 113] 1.6334 + 1.6335 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6336 + 1.6337 + 1.6338 + /* defining array bounds */ 1.6339 + 1.6340 + estSegPosRounded=(int)(estSegPos - 0.5); 1.6341 + 1.6342 + searchSegStartPos=estSegPosRounded-ENH_SLOP; 1.6343 + 1.6344 + if (searchSegStartPos<0) { 1.6345 + searchSegStartPos=0; 1.6346 + } 1.6347 + searchSegEndPos=estSegPosRounded+ENH_SLOP; 1.6348 + 1.6349 + if (searchSegEndPos+ENH_BLOCKL >= idatal) { 1.6350 + searchSegEndPos=idatal-ENH_BLOCKL-1; 1.6351 + } 1.6352 + corrdim=searchSegEndPos-searchSegStartPos+1; 1.6353 + 1.6354 + /* compute upsampled correlation (corr33) and find 1.6355 + location of max */ 1.6356 + 1.6357 + mycorr1(corrVec,idata+searchSegStartPos, 1.6358 + corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL); 1.6359 + enh_upsample(corrVecUps,corrVec,corrdim,ENH_FL0); 1.6360 + tloc=0; maxv=corrVecUps[0]; 1.6361 + for (i=1; i<ENH_UPS0*corrdim; i++) { 1.6362 + 1.6363 + if (corrVecUps[i]>maxv) { 1.6364 + tloc=i; 1.6365 + maxv=corrVecUps[i]; 1.6366 + } 1.6367 + } 1.6368 + 1.6369 + /* make vector can be upsampled without ever running outside 1.6370 + bounds */ 1.6371 + 1.6372 + *updStartPos= (float)searchSegStartPos + 1.6373 + (float)tloc/(float)ENH_UPS0+(float)1.0; 1.6374 + tloc2=(int)(tloc/ENH_UPS0); 1.6375 + 1.6376 + if (tloc>tloc2*ENH_UPS0) { 1.6377 + tloc2++; 1.6378 + } 1.6379 + st=searchSegStartPos+tloc2-ENH_FL0; 1.6380 + 1.6381 + if (st<0) { 1.6382 + memset(vect,0,-st*sizeof(float)); 1.6383 + memcpy(&vect[-st],idata, (ENH_VECTL+st)*sizeof(float)); 1.6384 + } 1.6385 + else { 1.6386 + 1.6387 + 1.6388 + 1.6389 +Andersen, et al. Experimental [Page 114] 1.6390 + 1.6391 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6392 + 1.6393 + 1.6394 + en=st+ENH_VECTL; 1.6395 + 1.6396 + if (en>idatal) { 1.6397 + memcpy(vect, &idata[st], 1.6398 + (ENH_VECTL-(en-idatal))*sizeof(float)); 1.6399 + memset(&vect[ENH_VECTL-(en-idatal)], 0, 1.6400 + (en-idatal)*sizeof(float)); 1.6401 + } 1.6402 + else { 1.6403 + memcpy(vect, &idata[st], ENH_VECTL*sizeof(float)); 1.6404 + } 1.6405 + } 1.6406 + fraction=tloc2*ENH_UPS0-tloc; 1.6407 + 1.6408 + /* compute the segment (this is actually a convolution) */ 1.6409 + 1.6410 + mycorr1(seg,vect,ENH_VECTL,polyphaserTbl+(2*ENH_FL0+1)*fraction, 1.6411 + 2*ENH_FL0+1); 1.6412 + } 1.6413 + 1.6414 + /*----------------------------------------------------------------* 1.6415 + * find the smoothed output data 1.6416 + *---------------------------------------------------------------*/ 1.6417 + 1.6418 + void smath( 1.6419 + float *odata, /* (o) smoothed output */ 1.6420 + float *sseq,/* (i) said second sequence of waveforms */ 1.6421 + int hl, /* (i) 2*hl+1 is sseq dimension */ 1.6422 + float alpha0/* (i) max smoothing energy fraction */ 1.6423 + ){ 1.6424 + int i,k; 1.6425 + float w00,w10,w11,A,B,C,*psseq,err,errs; 1.6426 + float surround[BLOCKL_MAX]; /* shape contributed by other than 1.6427 + current */ 1.6428 + float wt[2*ENH_HL+1]; /* waveform weighting to get 1.6429 + surround shape */ 1.6430 + float denom; 1.6431 + 1.6432 + /* create shape of contribution from all waveforms except the 1.6433 + current one */ 1.6434 + 1.6435 + for (i=1; i<=2*hl+1; i++) { 1.6436 + wt[i-1] = (float)0.5*(1 - (float)cos(2*PI*i/(2*hl+2))); 1.6437 + } 1.6438 + wt[hl]=0.0; /* for clarity, not used */ 1.6439 + for (i=0; i<ENH_BLOCKL; i++) { 1.6440 + surround[i]=sseq[i]*wt[0]; 1.6441 + } 1.6442 + 1.6443 + 1.6444 + 1.6445 +Andersen, et al. Experimental [Page 115] 1.6446 + 1.6447 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6448 + 1.6449 + 1.6450 + for (k=1; k<hl; k++) { 1.6451 + psseq=sseq+k*ENH_BLOCKL; 1.6452 + for(i=0;i<ENH_BLOCKL; i++) { 1.6453 + surround[i]+=psseq[i]*wt[k]; 1.6454 + } 1.6455 + } 1.6456 + for (k=hl+1; k<=2*hl; k++) { 1.6457 + psseq=sseq+k*ENH_BLOCKL; 1.6458 + for(i=0;i<ENH_BLOCKL; i++) { 1.6459 + surround[i]+=psseq[i]*wt[k]; 1.6460 + } 1.6461 + } 1.6462 + 1.6463 + /* compute some inner products */ 1.6464 + 1.6465 + w00 = w10 = w11 = 0.0; 1.6466 + psseq=sseq+hl*ENH_BLOCKL; /* current block */ 1.6467 + for (i=0; i<ENH_BLOCKL;i++) { 1.6468 + w00+=psseq[i]*psseq[i]; 1.6469 + w11+=surround[i]*surround[i]; 1.6470 + w10+=surround[i]*psseq[i]; 1.6471 + } 1.6472 + 1.6473 + if (fabs(w11) < 1.0) { 1.6474 + w11=1.0; 1.6475 + } 1.6476 + C = (float)sqrt( w00/w11); 1.6477 + 1.6478 + /* first try enhancement without power-constraint */ 1.6479 + 1.6480 + errs=0.0; 1.6481 + psseq=sseq+hl*ENH_BLOCKL; 1.6482 + for (i=0; i<ENH_BLOCKL; i++) { 1.6483 + odata[i]=C*surround[i]; 1.6484 + err=psseq[i]-odata[i]; 1.6485 + errs+=err*err; 1.6486 + } 1.6487 + 1.6488 + /* if constraint violated by first try, add constraint */ 1.6489 + 1.6490 + if (errs > alpha0 * w00) { 1.6491 + if ( w00 < 1) { 1.6492 + w00=1; 1.6493 + } 1.6494 + denom = (w11*w00-w10*w10)/(w00*w00); 1.6495 + 1.6496 + if (denom > 0.0001) { /* eliminates numerical problems 1.6497 + for if smooth */ 1.6498 + 1.6499 + 1.6500 + 1.6501 +Andersen, et al. Experimental [Page 116] 1.6502 + 1.6503 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6504 + 1.6505 + 1.6506 + A = (float)sqrt( (alpha0- alpha0*alpha0/4)/denom); 1.6507 + B = -alpha0/2 - A * w10/w00; 1.6508 + B = B+1; 1.6509 + } 1.6510 + else { /* essentially no difference between cycles; 1.6511 + smoothing not needed */ 1.6512 + A= 0.0; 1.6513 + B= 1.0; 1.6514 + } 1.6515 + 1.6516 + /* create smoothed sequence */ 1.6517 + 1.6518 + psseq=sseq+hl*ENH_BLOCKL; 1.6519 + for (i=0; i<ENH_BLOCKL; i++) { 1.6520 + odata[i]=A*surround[i]+B*psseq[i]; 1.6521 + } 1.6522 + } 1.6523 + } 1.6524 + 1.6525 + /*----------------------------------------------------------------* 1.6526 + * get the pitch-synchronous sample sequence 1.6527 + *---------------------------------------------------------------*/ 1.6528 + 1.6529 + void getsseq( 1.6530 + float *sseq, /* (o) the pitch-synchronous sequence */ 1.6531 + float *idata, /* (i) original data */ 1.6532 + int idatal, /* (i) dimension of data */ 1.6533 + int centerStartPos, /* (i) where current block starts */ 1.6534 + float *period, /* (i) rough-pitch-period array */ 1.6535 + float *plocs, /* (i) where periods of period array 1.6536 + are taken */ 1.6537 + int periodl, /* (i) dimension period array */ 1.6538 + int hl /* (i) 2*hl+1 is the number of sequences */ 1.6539 + ){ 1.6540 + int i,centerEndPos,q; 1.6541 + float blockStartPos[2*ENH_HL+1]; 1.6542 + int lagBlock[2*ENH_HL+1]; 1.6543 + float plocs2[ENH_PLOCSL]; 1.6544 + float *psseq; 1.6545 + 1.6546 + centerEndPos=centerStartPos+ENH_BLOCKL-1; 1.6547 + 1.6548 + /* present */ 1.6549 + 1.6550 + NearestNeighbor(lagBlock+hl,plocs, 1.6551 + (float)0.5*(centerStartPos+centerEndPos),periodl); 1.6552 + 1.6553 + blockStartPos[hl]=(float)centerStartPos; 1.6554 + 1.6555 + 1.6556 + 1.6557 +Andersen, et al. Experimental [Page 117] 1.6558 + 1.6559 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6560 + 1.6561 + 1.6562 + psseq=sseq+ENH_BLOCKL*hl; 1.6563 + memcpy(psseq, idata+centerStartPos, ENH_BLOCKL*sizeof(float)); 1.6564 + 1.6565 + /* past */ 1.6566 + 1.6567 + for (q=hl-1; q>=0; q--) { 1.6568 + blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]]; 1.6569 + NearestNeighbor(lagBlock+q,plocs, 1.6570 + blockStartPos[q]+ 1.6571 + ENH_BLOCKL_HALF-period[lagBlock[q+1]], periodl); 1.6572 + 1.6573 + 1.6574 + if (blockStartPos[q]-ENH_OVERHANG>=0) { 1.6575 + refiner(sseq+q*ENH_BLOCKL, blockStartPos+q, idata, 1.6576 + idatal, centerStartPos, blockStartPos[q], 1.6577 + period[lagBlock[q+1]]); 1.6578 + } else { 1.6579 + psseq=sseq+q*ENH_BLOCKL; 1.6580 + memset(psseq, 0, ENH_BLOCKL*sizeof(float)); 1.6581 + } 1.6582 + } 1.6583 + 1.6584 + /* future */ 1.6585 + 1.6586 + for (i=0; i<periodl; i++) { 1.6587 + plocs2[i]=plocs[i]-period[i]; 1.6588 + } 1.6589 + for (q=hl+1; q<=2*hl; q++) { 1.6590 + NearestNeighbor(lagBlock+q,plocs2, 1.6591 + blockStartPos[q-1]+ENH_BLOCKL_HALF,periodl); 1.6592 + 1.6593 + blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]]; 1.6594 + if (blockStartPos[q]+ENH_BLOCKL+ENH_OVERHANG<idatal) { 1.6595 + refiner(sseq+ENH_BLOCKL*q, blockStartPos+q, idata, 1.6596 + idatal, centerStartPos, blockStartPos[q], 1.6597 + period[lagBlock[q]]); 1.6598 + } 1.6599 + else { 1.6600 + psseq=sseq+q*ENH_BLOCKL; 1.6601 + memset(psseq, 0, ENH_BLOCKL*sizeof(float)); 1.6602 + } 1.6603 + } 1.6604 + } 1.6605 + 1.6606 + /*----------------------------------------------------------------* 1.6607 + * perform enhancement on idata+centerStartPos through 1.6608 + * idata+centerStartPos+ENH_BLOCKL-1 1.6609 + *---------------------------------------------------------------*/ 1.6610 + 1.6611 + 1.6612 + 1.6613 +Andersen, et al. Experimental [Page 118] 1.6614 + 1.6615 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6616 + 1.6617 + 1.6618 + void enhancer( 1.6619 + float *odata, /* (o) smoothed block, dimension blockl */ 1.6620 + float *idata, /* (i) data buffer used for enhancing */ 1.6621 + int idatal, /* (i) dimension idata */ 1.6622 + int centerStartPos, /* (i) first sample current block 1.6623 + within idata */ 1.6624 + float alpha0, /* (i) max correction-energy-fraction 1.6625 + (in [0,1]) */ 1.6626 + float *period, /* (i) pitch period array */ 1.6627 + float *plocs, /* (i) locations where period array 1.6628 + values valid */ 1.6629 + int periodl /* (i) dimension of period and plocs */ 1.6630 + ){ 1.6631 + float sseq[(2*ENH_HL+1)*ENH_BLOCKL]; 1.6632 + 1.6633 + /* get said second sequence of segments */ 1.6634 + 1.6635 + getsseq(sseq,idata,idatal,centerStartPos,period, 1.6636 + plocs,periodl,ENH_HL); 1.6637 + 1.6638 + /* compute the smoothed output from said second sequence */ 1.6639 + 1.6640 + smath(odata,sseq,ENH_HL,alpha0); 1.6641 + 1.6642 + } 1.6643 + 1.6644 + /*----------------------------------------------------------------* 1.6645 + * cross correlation 1.6646 + *---------------------------------------------------------------*/ 1.6647 + 1.6648 + float xCorrCoef( 1.6649 + float *target, /* (i) first array */ 1.6650 + float *regressor, /* (i) second array */ 1.6651 + int subl /* (i) dimension arrays */ 1.6652 + ){ 1.6653 + int i; 1.6654 + float ftmp1, ftmp2; 1.6655 + 1.6656 + ftmp1 = 0.0; 1.6657 + ftmp2 = 0.0; 1.6658 + for (i=0; i<subl; i++) { 1.6659 + ftmp1 += target[i]*regressor[i]; 1.6660 + ftmp2 += regressor[i]*regressor[i]; 1.6661 + } 1.6662 + 1.6663 + if (ftmp1 > 0.0) { 1.6664 + return (float)(ftmp1*ftmp1/ftmp2); 1.6665 + } 1.6666 + 1.6667 + 1.6668 + 1.6669 +Andersen, et al. Experimental [Page 119] 1.6670 + 1.6671 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6672 + 1.6673 + 1.6674 + else { 1.6675 + return (float)0.0; 1.6676 + } 1.6677 + } 1.6678 + 1.6679 + /*----------------------------------------------------------------* 1.6680 + * interface for enhancer 1.6681 + *---------------------------------------------------------------*/ 1.6682 + 1.6683 + int enhancerInterface( 1.6684 + float *out, /* (o) enhanced signal */ 1.6685 + float *in, /* (i) unenhanced signal */ 1.6686 + iLBC_Dec_Inst_t *iLBCdec_inst /* (i) buffers etc */ 1.6687 + ){ 1.6688 + float *enh_buf, *enh_period; 1.6689 + int iblock, isample; 1.6690 + int lag=0, ilag, i, ioffset; 1.6691 + float cc, maxcc; 1.6692 + float ftmp1, ftmp2; 1.6693 + float *inPtr, *enh_bufPtr1, *enh_bufPtr2; 1.6694 + float plc_pred[ENH_BLOCKL]; 1.6695 + 1.6696 + float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2]; 1.6697 + int inLen=ENH_NBLOCKS*ENH_BLOCKL+120; 1.6698 + int start, plc_blockl, inlag; 1.6699 + 1.6700 + enh_buf=iLBCdec_inst->enh_buf; 1.6701 + enh_period=iLBCdec_inst->enh_period; 1.6702 + 1.6703 + memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl], 1.6704 + (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float)); 1.6705 + 1.6706 + memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in, 1.6707 + iLBCdec_inst->blockl*sizeof(float)); 1.6708 + 1.6709 + if (iLBCdec_inst->mode==30) 1.6710 + plc_blockl=ENH_BLOCKL; 1.6711 + else 1.6712 + plc_blockl=40; 1.6713 + 1.6714 + /* when 20 ms frame, move processing one block */ 1.6715 + ioffset=0; 1.6716 + if (iLBCdec_inst->mode==20) ioffset=1; 1.6717 + 1.6718 + i=3-ioffset; 1.6719 + memmove(enh_period, &enh_period[i], 1.6720 + (ENH_NBLOCKS_TOT-i)*sizeof(float)); 1.6721 + 1.6722 + 1.6723 + 1.6724 + 1.6725 +Andersen, et al. Experimental [Page 120] 1.6726 + 1.6727 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6728 + 1.6729 + 1.6730 + /* Set state information to the 6 samples right before 1.6731 + the samples to be downsampled. */ 1.6732 + 1.6733 + memcpy(lpState, 1.6734 + enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126, 1.6735 + 6*sizeof(float)); 1.6736 + 1.6737 + /* Down sample a factor 2 to save computations */ 1.6738 + 1.6739 + DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120, 1.6740 + lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL, 1.6741 + lpState, downsampled); 1.6742 + 1.6743 + /* Estimate the pitch in the down sampled domain. */ 1.6744 + for (iblock = 0; iblock<ENH_NBLOCKS-ioffset; iblock++) { 1.6745 + 1.6746 + lag = 10; 1.6747 + maxcc = xCorrCoef(downsampled+60+iblock* 1.6748 + ENH_BLOCKL_HALF, downsampled+60+iblock* 1.6749 + ENH_BLOCKL_HALF-lag, ENH_BLOCKL_HALF); 1.6750 + for (ilag=11; ilag<60; ilag++) { 1.6751 + cc = xCorrCoef(downsampled+60+iblock* 1.6752 + ENH_BLOCKL_HALF, downsampled+60+iblock* 1.6753 + ENH_BLOCKL_HALF-ilag, ENH_BLOCKL_HALF); 1.6754 + 1.6755 + if (cc > maxcc) { 1.6756 + maxcc = cc; 1.6757 + lag = ilag; 1.6758 + } 1.6759 + } 1.6760 + 1.6761 + /* Store the estimated lag in the non-downsampled domain */ 1.6762 + enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2; 1.6763 + 1.6764 + 1.6765 + } 1.6766 + 1.6767 + 1.6768 + /* PLC was performed on the previous packet */ 1.6769 + if (iLBCdec_inst->prev_enh_pl==1) { 1.6770 + 1.6771 + inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset]; 1.6772 + 1.6773 + lag = inlag-1; 1.6774 + maxcc = xCorrCoef(in, in+lag, plc_blockl); 1.6775 + for (ilag=inlag; ilag<=inlag+1; ilag++) { 1.6776 + cc = xCorrCoef(in, in+ilag, plc_blockl); 1.6777 + 1.6778 + 1.6779 + 1.6780 + 1.6781 +Andersen, et al. Experimental [Page 121] 1.6782 + 1.6783 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6784 + 1.6785 + 1.6786 + if (cc > maxcc) { 1.6787 + maxcc = cc; 1.6788 + lag = ilag; 1.6789 + } 1.6790 + } 1.6791 + 1.6792 + enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag; 1.6793 + 1.6794 + /* compute new concealed residual for the old lookahead, 1.6795 + mix the forward PLC with a backward PLC from 1.6796 + the new frame */ 1.6797 + 1.6798 + inPtr=&in[lag-1]; 1.6799 + 1.6800 + enh_bufPtr1=&plc_pred[plc_blockl-1]; 1.6801 + 1.6802 + if (lag>plc_blockl) { 1.6803 + start=plc_blockl; 1.6804 + } else { 1.6805 + start=lag; 1.6806 + } 1.6807 + 1.6808 + for (isample = start; isample>0; isample--) { 1.6809 + *enh_bufPtr1-- = *inPtr--; 1.6810 + } 1.6811 + 1.6812 + enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl]; 1.6813 + for (isample = (plc_blockl-1-lag); isample>=0; isample--) { 1.6814 + *enh_bufPtr1-- = *enh_bufPtr2--; 1.6815 + } 1.6816 + 1.6817 + /* limit energy change */ 1.6818 + ftmp2=0.0; 1.6819 + ftmp1=0.0; 1.6820 + for (i=0;i<plc_blockl;i++) { 1.6821 + ftmp2+=enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]* 1.6822 + enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]; 1.6823 + ftmp1+=plc_pred[i]*plc_pred[i]; 1.6824 + } 1.6825 + ftmp1=(float)sqrt(ftmp1/(float)plc_blockl); 1.6826 + ftmp2=(float)sqrt(ftmp2/(float)plc_blockl); 1.6827 + if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) { 1.6828 + for (i=0;i<plc_blockl-10;i++) { 1.6829 + plc_pred[i]*=(float)2.0*ftmp2/ftmp1; 1.6830 + } 1.6831 + for (i=plc_blockl-10;i<plc_blockl;i++) { 1.6832 + plc_pred[i]*=(float)(i-plc_blockl+10)* 1.6833 + ((float)1.0-(float)2.0*ftmp2/ftmp1)/(float)(10)+ 1.6834 + 1.6835 + 1.6836 + 1.6837 +Andersen, et al. Experimental [Page 122] 1.6838 + 1.6839 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6840 + 1.6841 + 1.6842 + (float)2.0*ftmp2/ftmp1; 1.6843 + } 1.6844 + } 1.6845 + 1.6846 + enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl]; 1.6847 + for (i=0; i<plc_blockl; i++) { 1.6848 + ftmp1 = (float) (i+1) / (float) (plc_blockl+1); 1.6849 + *enh_bufPtr1 *= ftmp1; 1.6850 + *enh_bufPtr1 += ((float)1.0-ftmp1)* 1.6851 + plc_pred[plc_blockl-1-i]; 1.6852 + enh_bufPtr1--; 1.6853 + } 1.6854 + } 1.6855 + 1.6856 + if (iLBCdec_inst->mode==20) { 1.6857 + /* Enhancer with 40 samples delay */ 1.6858 + for (iblock = 0; iblock<2; iblock++) { 1.6859 + enhancer(out+iblock*ENH_BLOCKL, enh_buf, 1.6860 + ENH_BUFL, (5+iblock)*ENH_BLOCKL+40, 1.6861 + ENH_ALPHA0, enh_period, enh_plocsTbl, 1.6862 + ENH_NBLOCKS_TOT); 1.6863 + } 1.6864 + } else if (iLBCdec_inst->mode==30) { 1.6865 + /* Enhancer with 80 samples delay */ 1.6866 + for (iblock = 0; iblock<3; iblock++) { 1.6867 + enhancer(out+iblock*ENH_BLOCKL, enh_buf, 1.6868 + ENH_BUFL, (4+iblock)*ENH_BLOCKL, 1.6869 + ENH_ALPHA0, enh_period, enh_plocsTbl, 1.6870 + ENH_NBLOCKS_TOT); 1.6871 + } 1.6872 + } 1.6873 + 1.6874 + return (lag*2); 1.6875 + } 1.6876 + 1.6877 +A.17. filter.h 1.6878 + 1.6879 + /****************************************************************** 1.6880 + 1.6881 + iLBC Speech Coder ANSI-C Source Code 1.6882 + 1.6883 + filter.h 1.6884 + 1.6885 + Copyright (C) The Internet Society (2004). 1.6886 + All Rights Reserved. 1.6887 + 1.6888 + ******************************************************************/ 1.6889 + 1.6890 + 1.6891 + 1.6892 + 1.6893 +Andersen, et al. Experimental [Page 123] 1.6894 + 1.6895 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6896 + 1.6897 + 1.6898 + #ifndef __iLBC_FILTER_H 1.6899 + #define __iLBC_FILTER_H 1.6900 + 1.6901 + void AllPoleFilter( 1.6902 + float *InOut, /* (i/o) on entrance InOut[-orderCoef] to 1.6903 + InOut[-1] contain the state of the 1.6904 + filter (delayed samples). InOut[0] to 1.6905 + InOut[lengthInOut-1] contain the filter 1.6906 + input, on en exit InOut[-orderCoef] to 1.6907 + InOut[-1] is unchanged and InOut[0] to 1.6908 + InOut[lengthInOut-1] contain filtered 1.6909 + samples */ 1.6910 + float *Coef,/* (i) filter coefficients, Coef[0] is assumed 1.6911 + to be 1.0 */ 1.6912 + int lengthInOut,/* (i) number of input/output samples */ 1.6913 + int orderCoef /* (i) number of filter coefficients */ 1.6914 + ); 1.6915 + 1.6916 + void AllZeroFilter( 1.6917 + float *In, /* (i) In[0] to In[lengthInOut-1] contain 1.6918 + filter input samples */ 1.6919 + float *Coef,/* (i) filter coefficients (Coef[0] is assumed 1.6920 + to be 1.0) */ 1.6921 + int lengthInOut,/* (i) number of input/output samples */ 1.6922 + int orderCoef, /* (i) number of filter coefficients */ 1.6923 + float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] 1.6924 + contain the filter state, on exit Out[0] 1.6925 + to Out[lengthInOut-1] contain filtered 1.6926 + samples */ 1.6927 + ); 1.6928 + 1.6929 + void ZeroPoleFilter( 1.6930 + float *In, /* (i) In[0] to In[lengthInOut-1] contain filter 1.6931 + input samples In[-orderCoef] to In[-1] 1.6932 + contain state of all-zero section */ 1.6933 + float *ZeroCoef,/* (i) filter coefficients for all-zero 1.6934 + section (ZeroCoef[0] is assumed to 1.6935 + be 1.0) */ 1.6936 + float *PoleCoef,/* (i) filter coefficients for all-pole section 1.6937 + (ZeroCoef[0] is assumed to be 1.0) */ 1.6938 + int lengthInOut,/* (i) number of input/output samples */ 1.6939 + int orderCoef, /* (i) number of filter coefficients */ 1.6940 + float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] 1.6941 + contain state of all-pole section. On 1.6942 + exit Out[0] to Out[lengthInOut-1] 1.6943 + contain filtered samples */ 1.6944 + ); 1.6945 + 1.6946 + 1.6947 + 1.6948 + 1.6949 +Andersen, et al. Experimental [Page 124] 1.6950 + 1.6951 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.6952 + 1.6953 + 1.6954 + void DownSample ( 1.6955 + float *In, /* (i) input samples */ 1.6956 + float *Coef, /* (i) filter coefficients */ 1.6957 + int lengthIn, /* (i) number of input samples */ 1.6958 + float *state, /* (i) filter state */ 1.6959 + float *Out /* (o) downsampled output */ 1.6960 + ); 1.6961 + 1.6962 + #endif 1.6963 + 1.6964 +A.18. filter.c 1.6965 + 1.6966 + /****************************************************************** 1.6967 + 1.6968 + iLBC Speech Coder ANSI-C Source Code 1.6969 + 1.6970 + filter.c 1.6971 + 1.6972 + Copyright (C) The Internet Society (2004). 1.6973 + All Rights Reserved. 1.6974 + 1.6975 + ******************************************************************/ 1.6976 + 1.6977 + #include "iLBC_define.h" 1.6978 + 1.6979 + /*----------------------------------------------------------------* 1.6980 + * all-pole filter 1.6981 + *---------------------------------------------------------------*/ 1.6982 + 1.6983 + void AllPoleFilter( 1.6984 + float *InOut, /* (i/o) on entrance InOut[-orderCoef] to 1.6985 + InOut[-1] contain the state of the 1.6986 + filter (delayed samples). InOut[0] to 1.6987 + InOut[lengthInOut-1] contain the filter 1.6988 + input, on en exit InOut[-orderCoef] to 1.6989 + InOut[-1] is unchanged and InOut[0] to 1.6990 + InOut[lengthInOut-1] contain filtered 1.6991 + samples */ 1.6992 + float *Coef,/* (i) filter coefficients, Coef[0] is assumed 1.6993 + to be 1.0 */ 1.6994 + int lengthInOut,/* (i) number of input/output samples */ 1.6995 + int orderCoef /* (i) number of filter coefficients */ 1.6996 + ){ 1.6997 + int n,k; 1.6998 + 1.6999 + for(n=0;n<lengthInOut;n++){ 1.7000 + for(k=1;k<=orderCoef;k++){ 1.7001 + *InOut -= Coef[k]*InOut[-k]; 1.7002 + 1.7003 + 1.7004 + 1.7005 +Andersen, et al. Experimental [Page 125] 1.7006 + 1.7007 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7008 + 1.7009 + 1.7010 + } 1.7011 + InOut++; 1.7012 + } 1.7013 + } 1.7014 + 1.7015 + /*----------------------------------------------------------------* 1.7016 + * all-zero filter 1.7017 + *---------------------------------------------------------------*/ 1.7018 + 1.7019 + void AllZeroFilter( 1.7020 + float *In, /* (i) In[0] to In[lengthInOut-1] contain 1.7021 + filter input samples */ 1.7022 + float *Coef,/* (i) filter coefficients (Coef[0] is assumed 1.7023 + to be 1.0) */ 1.7024 + int lengthInOut,/* (i) number of input/output samples */ 1.7025 + int orderCoef, /* (i) number of filter coefficients */ 1.7026 + float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] 1.7027 + contain the filter state, on exit Out[0] 1.7028 + to Out[lengthInOut-1] contain filtered 1.7029 + samples */ 1.7030 + ){ 1.7031 + int n,k; 1.7032 + 1.7033 + for(n=0;n<lengthInOut;n++){ 1.7034 + *Out = Coef[0]*In[0]; 1.7035 + for(k=1;k<=orderCoef;k++){ 1.7036 + *Out += Coef[k]*In[-k]; 1.7037 + } 1.7038 + Out++; 1.7039 + In++; 1.7040 + } 1.7041 + } 1.7042 + 1.7043 + /*----------------------------------------------------------------* 1.7044 + * pole-zero filter 1.7045 + *---------------------------------------------------------------*/ 1.7046 + 1.7047 + void ZeroPoleFilter( 1.7048 + float *In, /* (i) In[0] to In[lengthInOut-1] contain 1.7049 + filter input samples In[-orderCoef] to 1.7050 + In[-1] contain state of all-zero 1.7051 + section */ 1.7052 + float *ZeroCoef,/* (i) filter coefficients for all-zero 1.7053 + section (ZeroCoef[0] is assumed to 1.7054 + be 1.0) */ 1.7055 + float *PoleCoef,/* (i) filter coefficients for all-pole section 1.7056 + (ZeroCoef[0] is assumed to be 1.0) */ 1.7057 + int lengthInOut,/* (i) number of input/output samples */ 1.7058 + 1.7059 + 1.7060 + 1.7061 +Andersen, et al. Experimental [Page 126] 1.7062 + 1.7063 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7064 + 1.7065 + 1.7066 + int orderCoef, /* (i) number of filter coefficients */ 1.7067 + float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] 1.7068 + contain state of all-pole section. On 1.7069 + exit Out[0] to Out[lengthInOut-1] 1.7070 + contain filtered samples */ 1.7071 + ){ 1.7072 + AllZeroFilter(In,ZeroCoef,lengthInOut,orderCoef,Out); 1.7073 + AllPoleFilter(Out,PoleCoef,lengthInOut,orderCoef); 1.7074 + } 1.7075 + 1.7076 + /*----------------------------------------------------------------* 1.7077 + * downsample (LP filter and decimation) 1.7078 + *---------------------------------------------------------------*/ 1.7079 + 1.7080 + void DownSample ( 1.7081 + float *In, /* (i) input samples */ 1.7082 + float *Coef, /* (i) filter coefficients */ 1.7083 + int lengthIn, /* (i) number of input samples */ 1.7084 + float *state, /* (i) filter state */ 1.7085 + float *Out /* (o) downsampled output */ 1.7086 + ){ 1.7087 + float o; 1.7088 + float *Out_ptr = Out; 1.7089 + float *Coef_ptr, *In_ptr; 1.7090 + float *state_ptr; 1.7091 + int i, j, stop; 1.7092 + 1.7093 + /* LP filter and decimate at the same time */ 1.7094 + 1.7095 + for (i = DELAY_DS; i < lengthIn; i+=FACTOR_DS) 1.7096 + { 1.7097 + Coef_ptr = &Coef[0]; 1.7098 + In_ptr = &In[i]; 1.7099 + state_ptr = &state[FILTERORDER_DS-2]; 1.7100 + 1.7101 + o = (float)0.0; 1.7102 + 1.7103 + stop = (i < FILTERORDER_DS) ? i + 1 : FILTERORDER_DS; 1.7104 + 1.7105 + for (j = 0; j < stop; j++) 1.7106 + { 1.7107 + o += *Coef_ptr++ * (*In_ptr--); 1.7108 + } 1.7109 + for (j = i + 1; j < FILTERORDER_DS; j++) 1.7110 + { 1.7111 + o += *Coef_ptr++ * (*state_ptr--); 1.7112 + } 1.7113 + 1.7114 + 1.7115 + 1.7116 + 1.7117 +Andersen, et al. Experimental [Page 127] 1.7118 + 1.7119 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7120 + 1.7121 + 1.7122 + *Out_ptr++ = o; 1.7123 + } 1.7124 + 1.7125 + /* Get the last part (use zeros as input for the future) */ 1.7126 + 1.7127 + for (i=(lengthIn+FACTOR_DS); i<(lengthIn+DELAY_DS); 1.7128 + i+=FACTOR_DS) { 1.7129 + 1.7130 + o=(float)0.0; 1.7131 + 1.7132 + if (i<lengthIn) { 1.7133 + Coef_ptr = &Coef[0]; 1.7134 + In_ptr = &In[i]; 1.7135 + for (j=0; j<FILTERORDER_DS; j++) { 1.7136 + o += *Coef_ptr++ * (*Out_ptr--); 1.7137 + } 1.7138 + } else { 1.7139 + Coef_ptr = &Coef[i-lengthIn]; 1.7140 + In_ptr = &In[lengthIn-1]; 1.7141 + for (j=0; j<FILTERORDER_DS-(i-lengthIn); j++) { 1.7142 + o += *Coef_ptr++ * (*In_ptr--); 1.7143 + } 1.7144 + } 1.7145 + *Out_ptr++ = o; 1.7146 + } 1.7147 + } 1.7148 + 1.7149 +A.19. FrameClassify.h 1.7150 + 1.7151 + /****************************************************************** 1.7152 + 1.7153 + iLBC Speech Coder ANSI-C Source Code 1.7154 + 1.7155 + FrameClassify.h 1.7156 + 1.7157 + Copyright (C) The Internet Society (2004). 1.7158 + All Rights Reserved. 1.7159 + 1.7160 + ******************************************************************/ 1.7161 + 1.7162 + #ifndef __iLBC_FRAMECLASSIFY_H 1.7163 + #define __iLBC_FRAMECLASSIFY_H 1.7164 + 1.7165 + int FrameClassify( /* index to the max-energy sub-frame */ 1.7166 + iLBC_Enc_Inst_t *iLBCenc_inst, 1.7167 + /* (i/o) the encoder state structure */ 1.7168 + float *residual /* (i) lpc residual signal */ 1.7169 + ); 1.7170 + 1.7171 + 1.7172 + 1.7173 +Andersen, et al. Experimental [Page 128] 1.7174 + 1.7175 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7176 + 1.7177 + 1.7178 + #endif 1.7179 + 1.7180 +A.20. FrameClassify.c 1.7181 + 1.7182 + /****************************************************************** 1.7183 + 1.7184 + iLBC Speech Coder ANSI-C Source Code 1.7185 + 1.7186 + FrameClassify.c 1.7187 + 1.7188 + Copyright (C) The Internet Society (2004). 1.7189 + All Rights Reserved. 1.7190 + 1.7191 + ******************************************************************/ 1.7192 + 1.7193 + #include "iLBC_define.h" 1.7194 + 1.7195 + /*---------------------------------------------------------------* 1.7196 + * Classification of subframes to localize start state 1.7197 + *--------------------------------------------------------------*/ 1.7198 + 1.7199 + int FrameClassify( /* index to the max-energy sub-frame */ 1.7200 + iLBC_Enc_Inst_t *iLBCenc_inst, 1.7201 + /* (i/o) the encoder state structure */ 1.7202 + float *residual /* (i) lpc residual signal */ 1.7203 + ) { 1.7204 + float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp; 1.7205 + int n, l, max_ssqEn_n; 1.7206 + const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9, 1.7207 + (float)1.0,(float)0.9,(float)0.8}; 1.7208 + const float sampEn_win[5]={(float)1.0/(float)6.0, 1.7209 + (float)2.0/(float)6.0, (float)3.0/(float)6.0, 1.7210 + (float)4.0/(float)6.0, (float)5.0/(float)6.0}; 1.7211 + 1.7212 + /* init the front and back energies to zero */ 1.7213 + 1.7214 + memset(fssqEn, 0, NSUB_MAX*sizeof(float)); 1.7215 + memset(bssqEn, 0, NSUB_MAX*sizeof(float)); 1.7216 + 1.7217 + /* Calculate front of first seqence */ 1.7218 + 1.7219 + n=0; 1.7220 + pp=residual; 1.7221 + for (l=0; l<5; l++) { 1.7222 + fssqEn[n] += sampEn_win[l] * (*pp) * (*pp); 1.7223 + pp++; 1.7224 + } 1.7225 + for (l=5; l<SUBL; l++) { 1.7226 + 1.7227 + 1.7228 + 1.7229 +Andersen, et al. Experimental [Page 129] 1.7230 + 1.7231 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7232 + 1.7233 + 1.7234 + fssqEn[n] += (*pp) * (*pp); 1.7235 + pp++; 1.7236 + } 1.7237 + 1.7238 + /* Calculate front and back of all middle sequences */ 1.7239 + 1.7240 + for (n=1; n<iLBCenc_inst->nsub-1; n++) { 1.7241 + pp=residual+n*SUBL; 1.7242 + for (l=0; l<5; l++) { 1.7243 + fssqEn[n] += sampEn_win[l] * (*pp) * (*pp); 1.7244 + bssqEn[n] += (*pp) * (*pp); 1.7245 + pp++; 1.7246 + } 1.7247 + for (l=5; l<SUBL-5; l++) { 1.7248 + fssqEn[n] += (*pp) * (*pp); 1.7249 + bssqEn[n] += (*pp) * (*pp); 1.7250 + pp++; 1.7251 + } 1.7252 + for (l=SUBL-5; l<SUBL; l++) { 1.7253 + fssqEn[n] += (*pp) * (*pp); 1.7254 + bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp); 1.7255 + pp++; 1.7256 + } 1.7257 + } 1.7258 + 1.7259 + /* Calculate back of last seqence */ 1.7260 + 1.7261 + n=iLBCenc_inst->nsub-1; 1.7262 + pp=residual+n*SUBL; 1.7263 + for (l=0; l<SUBL-5; l++) { 1.7264 + bssqEn[n] += (*pp) * (*pp); 1.7265 + pp++; 1.7266 + } 1.7267 + for (l=SUBL-5; l<SUBL; l++) { 1.7268 + bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp); 1.7269 + pp++; 1.7270 + } 1.7271 + 1.7272 + /* find the index to the weighted 80 sample with 1.7273 + most energy */ 1.7274 + 1.7275 + if (iLBCenc_inst->mode==20) l=1; 1.7276 + else l=0; 1.7277 + 1.7278 + max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l]; 1.7279 + max_ssqEn_n=1; 1.7280 + for (n=2; n<iLBCenc_inst->nsub; n++) { 1.7281 + 1.7282 + 1.7283 + 1.7284 + 1.7285 +Andersen, et al. Experimental [Page 130] 1.7286 + 1.7287 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7288 + 1.7289 + 1.7290 + l++; 1.7291 + if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) { 1.7292 + max_ssqEn=(fssqEn[n-1]+bssqEn[n]) * 1.7293 + ssqEn_win[l]; 1.7294 + max_ssqEn_n=n; 1.7295 + } 1.7296 + } 1.7297 + 1.7298 + return max_ssqEn_n; 1.7299 + } 1.7300 + 1.7301 +A.21. gainquant.h 1.7302 + 1.7303 + /****************************************************************** 1.7304 + 1.7305 + iLBC Speech Coder ANSI-C Source Code 1.7306 + 1.7307 + gainquant.h 1.7308 + 1.7309 + Copyright (C) The Internet Society (2004). 1.7310 + All Rights Reserved. 1.7311 + 1.7312 + ******************************************************************/ 1.7313 + 1.7314 + #ifndef __iLBC_GAINQUANT_H 1.7315 + #define __iLBC_GAINQUANT_H 1.7316 + 1.7317 + float gainquant(/* (o) quantized gain value */ 1.7318 + float in, /* (i) gain value */ 1.7319 + float maxIn,/* (i) maximum of gain value */ 1.7320 + int cblen, /* (i) number of quantization indices */ 1.7321 + int *index /* (o) quantization index */ 1.7322 + ); 1.7323 + 1.7324 + float gaindequant( /* (o) quantized gain value */ 1.7325 + int index, /* (i) quantization index */ 1.7326 + float maxIn,/* (i) maximum of unquantized gain */ 1.7327 + int cblen /* (i) number of quantization indices */ 1.7328 + ); 1.7329 + 1.7330 + #endif 1.7331 + 1.7332 +A.22. gainquant.c 1.7333 + 1.7334 + /****************************************************************** 1.7335 + 1.7336 + iLBC Speech Coder ANSI-C Source Code 1.7337 + 1.7338 + 1.7339 + 1.7340 + 1.7341 +Andersen, et al. Experimental [Page 131] 1.7342 + 1.7343 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7344 + 1.7345 + 1.7346 + gainquant.c 1.7347 + 1.7348 + Copyright (C) The Internet Society (2004). 1.7349 + All Rights Reserved. 1.7350 + 1.7351 + ******************************************************************/ 1.7352 + 1.7353 + #include <string.h> 1.7354 + #include <math.h> 1.7355 + #include "constants.h" 1.7356 + #include "filter.h" 1.7357 + 1.7358 + /*----------------------------------------------------------------* 1.7359 + * quantizer for the gain in the gain-shape coding of residual 1.7360 + *---------------------------------------------------------------*/ 1.7361 + 1.7362 + float gainquant(/* (o) quantized gain value */ 1.7363 + float in, /* (i) gain value */ 1.7364 + float maxIn,/* (i) maximum of gain value */ 1.7365 + int cblen, /* (i) number of quantization indices */ 1.7366 + int *index /* (o) quantization index */ 1.7367 + ){ 1.7368 + int i, tindex; 1.7369 + float minmeasure,measure, *cb, scale; 1.7370 + 1.7371 + /* ensure a lower bound on the scaling factor */ 1.7372 + 1.7373 + scale=maxIn; 1.7374 + 1.7375 + if (scale<0.1) { 1.7376 + scale=(float)0.1; 1.7377 + } 1.7378 + 1.7379 + /* select the quantization table */ 1.7380 + 1.7381 + if (cblen == 8) { 1.7382 + cb = gain_sq3Tbl; 1.7383 + } else if (cblen == 16) { 1.7384 + cb = gain_sq4Tbl; 1.7385 + } else { 1.7386 + cb = gain_sq5Tbl; 1.7387 + } 1.7388 + 1.7389 + /* select the best index in the quantization table */ 1.7390 + 1.7391 + minmeasure=10000000.0; 1.7392 + tindex=0; 1.7393 + for (i=0; i<cblen; i++) { 1.7394 + 1.7395 + 1.7396 + 1.7397 +Andersen, et al. Experimental [Page 132] 1.7398 + 1.7399 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7400 + 1.7401 + 1.7402 + measure=(in-scale*cb[i])*(in-scale*cb[i]); 1.7403 + 1.7404 + if (measure<minmeasure) { 1.7405 + tindex=i; 1.7406 + minmeasure=measure; 1.7407 + } 1.7408 + } 1.7409 + *index=tindex; 1.7410 + 1.7411 + /* return the quantized value */ 1.7412 + 1.7413 + return scale*cb[tindex]; 1.7414 + } 1.7415 + 1.7416 + /*----------------------------------------------------------------* 1.7417 + * decoder for quantized gains in the gain-shape coding of 1.7418 + * residual 1.7419 + *---------------------------------------------------------------*/ 1.7420 + 1.7421 + float gaindequant( /* (o) quantized gain value */ 1.7422 + int index, /* (i) quantization index */ 1.7423 + float maxIn,/* (i) maximum of unquantized gain */ 1.7424 + int cblen /* (i) number of quantization indices */ 1.7425 + ){ 1.7426 + float scale; 1.7427 + 1.7428 + /* obtain correct scale factor */ 1.7429 + 1.7430 + scale=(float)fabs(maxIn); 1.7431 + 1.7432 + if (scale<0.1) { 1.7433 + scale=(float)0.1; 1.7434 + } 1.7435 + 1.7436 + /* select the quantization table and return the decoded value */ 1.7437 + 1.7438 + if (cblen==8) { 1.7439 + return scale*gain_sq3Tbl[index]; 1.7440 + } else if (cblen==16) { 1.7441 + return scale*gain_sq4Tbl[index]; 1.7442 + } 1.7443 + else if (cblen==32) { 1.7444 + return scale*gain_sq5Tbl[index]; 1.7445 + } 1.7446 + 1.7447 + return 0.0; 1.7448 + } 1.7449 + 1.7450 + 1.7451 + 1.7452 + 1.7453 +Andersen, et al. Experimental [Page 133] 1.7454 + 1.7455 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7456 + 1.7457 + 1.7458 +A.23. getCBvec.h 1.7459 + 1.7460 + /****************************************************************** 1.7461 + 1.7462 + iLBC Speech Coder ANSI-C Source Code 1.7463 + 1.7464 + getCBvec.h 1.7465 + 1.7466 + Copyright (C) The Internet Society (2004). 1.7467 + All Rights Reserved. 1.7468 + 1.7469 + ******************************************************************/ 1.7470 + 1.7471 + #ifndef __iLBC_GETCBVEC_H 1.7472 + #define __iLBC_GETCBVEC_H 1.7473 + 1.7474 + void getCBvec( 1.7475 + float *cbvec, /* (o) Constructed codebook vector */ 1.7476 + float *mem, /* (i) Codebook buffer */ 1.7477 + int index, /* (i) Codebook index */ 1.7478 + int lMem, /* (i) Length of codebook buffer */ 1.7479 + int cbveclen/* (i) Codebook vector length */ 1.7480 + ); 1.7481 + 1.7482 + #endif 1.7483 + 1.7484 +A.24. getCBvec.c 1.7485 + 1.7486 + /****************************************************************** 1.7487 + 1.7488 + iLBC Speech Coder ANSI-C Source Code 1.7489 + 1.7490 + getCBvec.c 1.7491 + 1.7492 + Copyright (C) The Internet Society (2004). 1.7493 + All Rights Reserved. 1.7494 + 1.7495 + ******************************************************************/ 1.7496 + 1.7497 + #include "iLBC_define.h" 1.7498 + #include "constants.h" 1.7499 + #include <string.h> 1.7500 + 1.7501 + /*----------------------------------------------------------------* 1.7502 + * Construct codebook vector for given index. 1.7503 + *---------------------------------------------------------------*/ 1.7504 + 1.7505 + void getCBvec( 1.7506 + 1.7507 + 1.7508 + 1.7509 +Andersen, et al. Experimental [Page 134] 1.7510 + 1.7511 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7512 + 1.7513 + 1.7514 + float *cbvec, /* (o) Constructed codebook vector */ 1.7515 + float *mem, /* (i) Codebook buffer */ 1.7516 + int index, /* (i) Codebook index */ 1.7517 + int lMem, /* (i) Length of codebook buffer */ 1.7518 + int cbveclen/* (i) Codebook vector length */ 1.7519 + ){ 1.7520 + int j, k, n, memInd, sFilt; 1.7521 + float tmpbuf[CB_MEML]; 1.7522 + int base_size; 1.7523 + int ilow, ihigh; 1.7524 + float alfa, alfa1; 1.7525 + 1.7526 + /* Determine size of codebook sections */ 1.7527 + 1.7528 + base_size=lMem-cbveclen+1; 1.7529 + 1.7530 + if (cbveclen==SUBL) { 1.7531 + base_size+=cbveclen/2; 1.7532 + } 1.7533 + 1.7534 + /* No filter -> First codebook section */ 1.7535 + 1.7536 + if (index<lMem-cbveclen+1) { 1.7537 + 1.7538 + /* first non-interpolated vectors */ 1.7539 + 1.7540 + k=index+cbveclen; 1.7541 + /* get vector */ 1.7542 + memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float)); 1.7543 + 1.7544 + } else if (index < base_size) { 1.7545 + 1.7546 + k=2*(index-(lMem-cbveclen+1))+cbveclen; 1.7547 + 1.7548 + ihigh=k/2; 1.7549 + ilow=ihigh-5; 1.7550 + 1.7551 + /* Copy first noninterpolated part */ 1.7552 + 1.7553 + memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float)); 1.7554 + 1.7555 + /* interpolation */ 1.7556 + 1.7557 + alfa1=(float)0.2; 1.7558 + alfa=0.0; 1.7559 + for (j=ilow; j<ihigh; j++) { 1.7560 + cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+ 1.7561 + alfa*mem[lMem-k+j]; 1.7562 + 1.7563 + 1.7564 + 1.7565 +Andersen, et al. Experimental [Page 135] 1.7566 + 1.7567 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7568 + 1.7569 + 1.7570 + alfa+=alfa1; 1.7571 + } 1.7572 + 1.7573 + /* Copy second noninterpolated part */ 1.7574 + 1.7575 + memcpy(cbvec+ihigh, mem+lMem-k+ihigh, 1.7576 + (cbveclen-ihigh)*sizeof(float)); 1.7577 + 1.7578 + } 1.7579 + 1.7580 + /* Higher codebook section based on filtering */ 1.7581 + 1.7582 + else { 1.7583 + 1.7584 + /* first non-interpolated vectors */ 1.7585 + 1.7586 + if (index-base_size<lMem-cbveclen+1) { 1.7587 + float tempbuff2[CB_MEML+CB_FILTERLEN+1]; 1.7588 + float *pos; 1.7589 + float *pp, *pp1; 1.7590 + 1.7591 + memset(tempbuff2, 0, 1.7592 + CB_HALFFILTERLEN*sizeof(float)); 1.7593 + memcpy(&tempbuff2[CB_HALFFILTERLEN], mem, 1.7594 + lMem*sizeof(float)); 1.7595 + memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0, 1.7596 + (CB_HALFFILTERLEN+1)*sizeof(float)); 1.7597 + 1.7598 + k=index-base_size+cbveclen; 1.7599 + sFilt=lMem-k; 1.7600 + memInd=sFilt+1-CB_HALFFILTERLEN; 1.7601 + 1.7602 + /* do filtering */ 1.7603 + pos=cbvec; 1.7604 + memset(pos, 0, cbveclen*sizeof(float)); 1.7605 + for (n=0; n<cbveclen; n++) { 1.7606 + pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN]; 1.7607 + pp1=&cbfiltersTbl[CB_FILTERLEN-1]; 1.7608 + for (j=0; j<CB_FILTERLEN; j++) { 1.7609 + (*pos)+=(*pp++)*(*pp1--); 1.7610 + } 1.7611 + pos++; 1.7612 + } 1.7613 + } 1.7614 + 1.7615 + /* interpolated vectors */ 1.7616 + 1.7617 + else { 1.7618 + 1.7619 + 1.7620 + 1.7621 +Andersen, et al. Experimental [Page 136] 1.7622 + 1.7623 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7624 + 1.7625 + 1.7626 + float tempbuff2[CB_MEML+CB_FILTERLEN+1]; 1.7627 + 1.7628 + float *pos; 1.7629 + float *pp, *pp1; 1.7630 + int i; 1.7631 + 1.7632 + memset(tempbuff2, 0, 1.7633 + CB_HALFFILTERLEN*sizeof(float)); 1.7634 + memcpy(&tempbuff2[CB_HALFFILTERLEN], mem, 1.7635 + lMem*sizeof(float)); 1.7636 + memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0, 1.7637 + (CB_HALFFILTERLEN+1)*sizeof(float)); 1.7638 + 1.7639 + k=2*(index-base_size- 1.7640 + (lMem-cbveclen+1))+cbveclen; 1.7641 + sFilt=lMem-k; 1.7642 + memInd=sFilt+1-CB_HALFFILTERLEN; 1.7643 + 1.7644 + /* do filtering */ 1.7645 + pos=&tmpbuf[sFilt]; 1.7646 + memset(pos, 0, k*sizeof(float)); 1.7647 + for (i=0; i<k; i++) { 1.7648 + pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN]; 1.7649 + pp1=&cbfiltersTbl[CB_FILTERLEN-1]; 1.7650 + for (j=0; j<CB_FILTERLEN; j++) { 1.7651 + (*pos)+=(*pp++)*(*pp1--); 1.7652 + } 1.7653 + pos++; 1.7654 + } 1.7655 + 1.7656 + ihigh=k/2; 1.7657 + ilow=ihigh-5; 1.7658 + 1.7659 + /* Copy first noninterpolated part */ 1.7660 + 1.7661 + memcpy(cbvec, tmpbuf+lMem-k/2, 1.7662 + ilow*sizeof(float)); 1.7663 + 1.7664 + /* interpolation */ 1.7665 + 1.7666 + alfa1=(float)0.2; 1.7667 + alfa=0.0; 1.7668 + for (j=ilow; j<ihigh; j++) { 1.7669 + cbvec[j]=((float)1.0-alfa)* 1.7670 + tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j]; 1.7671 + alfa+=alfa1; 1.7672 + } 1.7673 + 1.7674 + 1.7675 + 1.7676 + 1.7677 +Andersen, et al. Experimental [Page 137] 1.7678 + 1.7679 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7680 + 1.7681 + 1.7682 + /* Copy second noninterpolated part */ 1.7683 + 1.7684 + memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh, 1.7685 + (cbveclen-ihigh)*sizeof(float)); 1.7686 + } 1.7687 + } 1.7688 + } 1.7689 + 1.7690 +A.25. helpfun.h 1.7691 + 1.7692 + /****************************************************************** 1.7693 + 1.7694 + iLBC Speech Coder ANSI-C Source Code 1.7695 + 1.7696 + helpfun.h 1.7697 + 1.7698 + Copyright (C) The Internet Society (2004). 1.7699 + All Rights Reserved. 1.7700 + 1.7701 + ******************************************************************/ 1.7702 + 1.7703 + #ifndef __iLBC_HELPFUN_H 1.7704 + #define __iLBC_HELPFUN_H 1.7705 + 1.7706 + void autocorr( 1.7707 + float *r, /* (o) autocorrelation vector */ 1.7708 + const float *x, /* (i) data vector */ 1.7709 + int N, /* (i) length of data vector */ 1.7710 + int order /* largest lag for calculated 1.7711 + autocorrelations */ 1.7712 + ); 1.7713 + 1.7714 + void window( 1.7715 + float *z, /* (o) the windowed data */ 1.7716 + const float *x, /* (i) the original data vector */ 1.7717 + const float *y, /* (i) the window */ 1.7718 + int N /* (i) length of all vectors */ 1.7719 + ); 1.7720 + 1.7721 + void levdurb( 1.7722 + float *a, /* (o) lpc coefficient vector starting 1.7723 + with 1.0 */ 1.7724 + float *k, /* (o) reflection coefficients */ 1.7725 + float *r, /* (i) autocorrelation vector */ 1.7726 + int order /* (i) order of lpc filter */ 1.7727 + ); 1.7728 + 1.7729 + void interpolate( 1.7730 + 1.7731 + 1.7732 + 1.7733 +Andersen, et al. Experimental [Page 138] 1.7734 + 1.7735 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7736 + 1.7737 + 1.7738 + float *out, /* (o) the interpolated vector */ 1.7739 + float *in1, /* (i) the first vector for the 1.7740 + interpolation */ 1.7741 + float *in2, /* (i) the second vector for the 1.7742 + interpolation */ 1.7743 + float coef, /* (i) interpolation weights */ 1.7744 + int length /* (i) length of all vectors */ 1.7745 + ); 1.7746 + 1.7747 + void bwexpand( 1.7748 + float *out, /* (o) the bandwidth expanded lpc 1.7749 + coefficients */ 1.7750 + float *in, /* (i) the lpc coefficients before bandwidth 1.7751 + expansion */ 1.7752 + float coef, /* (i) the bandwidth expansion factor */ 1.7753 + int length /* (i) the length of lpc coefficient vectors */ 1.7754 + ); 1.7755 + 1.7756 + void vq( 1.7757 + float *Xq, /* (o) the quantized vector */ 1.7758 + int *index, /* (o) the quantization index */ 1.7759 + const float *CB,/* (i) the vector quantization codebook */ 1.7760 + float *X, /* (i) the vector to quantize */ 1.7761 + int n_cb, /* (i) the number of vectors in the codebook */ 1.7762 + int dim /* (i) the dimension of all vectors */ 1.7763 + ); 1.7764 + 1.7765 + void SplitVQ( 1.7766 + float *qX, /* (o) the quantized vector */ 1.7767 + int *index, /* (o) a vector of indexes for all vector 1.7768 + codebooks in the split */ 1.7769 + float *X, /* (i) the vector to quantize */ 1.7770 + const float *CB,/* (i) the quantizer codebook */ 1.7771 + int nsplit, /* the number of vector splits */ 1.7772 + const int *dim, /* the dimension of X and qX */ 1.7773 + const int *cbsize /* the number of vectors in the codebook */ 1.7774 + ); 1.7775 + 1.7776 + 1.7777 + void sort_sq( 1.7778 + float *xq, /* (o) the quantized value */ 1.7779 + int *index, /* (o) the quantization index */ 1.7780 + float x, /* (i) the value to quantize */ 1.7781 + const float *cb,/* (i) the quantization codebook */ 1.7782 + int cb_size /* (i) the size of the quantization codebook */ 1.7783 + ); 1.7784 + 1.7785 + int LSF_check( /* (o) 1 for stable lsf vectors and 0 for 1.7786 + 1.7787 + 1.7788 + 1.7789 +Andersen, et al. Experimental [Page 139] 1.7790 + 1.7791 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7792 + 1.7793 + 1.7794 + nonstable ones */ 1.7795 + float *lsf, /* (i) a table of lsf vectors */ 1.7796 + int dim, /* (i) the dimension of each lsf vector */ 1.7797 + int NoAn /* (i) the number of lsf vectors in the 1.7798 + table */ 1.7799 + ); 1.7800 + 1.7801 + #endif 1.7802 + 1.7803 +A.26. helpfun.c 1.7804 + 1.7805 + /****************************************************************** 1.7806 + 1.7807 + iLBC Speech Coder ANSI-C Source Code 1.7808 + 1.7809 + helpfun.c 1.7810 + 1.7811 + Copyright (C) The Internet Society (2004). 1.7812 + All Rights Reserved. 1.7813 + 1.7814 + ******************************************************************/ 1.7815 + 1.7816 + #include <math.h> 1.7817 + 1.7818 + #include "iLBC_define.h" 1.7819 + #include "constants.h" 1.7820 + 1.7821 + /*----------------------------------------------------------------* 1.7822 + * calculation of auto correlation 1.7823 + *---------------------------------------------------------------*/ 1.7824 + 1.7825 + void autocorr( 1.7826 + float *r, /* (o) autocorrelation vector */ 1.7827 + const float *x, /* (i) data vector */ 1.7828 + int N, /* (i) length of data vector */ 1.7829 + int order /* largest lag for calculated 1.7830 + autocorrelations */ 1.7831 + ){ 1.7832 + int lag, n; 1.7833 + float sum; 1.7834 + 1.7835 + for (lag = 0; lag <= order; lag++) { 1.7836 + sum = 0; 1.7837 + for (n = 0; n < N - lag; n++) { 1.7838 + sum += x[n] * x[n+lag]; 1.7839 + } 1.7840 + r[lag] = sum; 1.7841 + } 1.7842 + 1.7843 + 1.7844 + 1.7845 +Andersen, et al. Experimental [Page 140] 1.7846 + 1.7847 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7848 + 1.7849 + 1.7850 + } 1.7851 + 1.7852 + /*----------------------------------------------------------------* 1.7853 + * window multiplication 1.7854 + *---------------------------------------------------------------*/ 1.7855 + 1.7856 + void window( 1.7857 + float *z, /* (o) the windowed data */ 1.7858 + const float *x, /* (i) the original data vector */ 1.7859 + const float *y, /* (i) the window */ 1.7860 + int N /* (i) length of all vectors */ 1.7861 + ){ 1.7862 + int i; 1.7863 + 1.7864 + for (i = 0; i < N; i++) { 1.7865 + z[i] = x[i] * y[i]; 1.7866 + } 1.7867 + } 1.7868 + 1.7869 + /*----------------------------------------------------------------* 1.7870 + * levinson-durbin solution for lpc coefficients 1.7871 + *---------------------------------------------------------------*/ 1.7872 + 1.7873 + void levdurb( 1.7874 + float *a, /* (o) lpc coefficient vector starting 1.7875 + with 1.0 */ 1.7876 + float *k, /* (o) reflection coefficients */ 1.7877 + float *r, /* (i) autocorrelation vector */ 1.7878 + int order /* (i) order of lpc filter */ 1.7879 + ){ 1.7880 + float sum, alpha; 1.7881 + int m, m_h, i; 1.7882 + 1.7883 + a[0] = 1.0; 1.7884 + 1.7885 + if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */ 1.7886 + for (i = 0; i < order; i++) { 1.7887 + k[i] = 0; 1.7888 + a[i+1] = 0; 1.7889 + } 1.7890 + } else { 1.7891 + a[1] = k[0] = -r[1]/r[0]; 1.7892 + alpha = r[0] + r[1] * k[0]; 1.7893 + for (m = 1; m < order; m++){ 1.7894 + sum = r[m + 1]; 1.7895 + for (i = 0; i < m; i++){ 1.7896 + sum += a[i+1] * r[m - i]; 1.7897 + } 1.7898 + 1.7899 + 1.7900 + 1.7901 +Andersen, et al. Experimental [Page 141] 1.7902 + 1.7903 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7904 + 1.7905 + 1.7906 + k[m] = -sum / alpha; 1.7907 + alpha += k[m] * sum; 1.7908 + m_h = (m + 1) >> 1; 1.7909 + for (i = 0; i < m_h; i++){ 1.7910 + sum = a[i+1] + k[m] * a[m - i]; 1.7911 + a[m - i] += k[m] * a[i+1]; 1.7912 + a[i+1] = sum; 1.7913 + } 1.7914 + a[m+1] = k[m]; 1.7915 + } 1.7916 + } 1.7917 + } 1.7918 + 1.7919 + /*----------------------------------------------------------------* 1.7920 + * interpolation between vectors 1.7921 + *---------------------------------------------------------------*/ 1.7922 + 1.7923 + void interpolate( 1.7924 + float *out, /* (o) the interpolated vector */ 1.7925 + float *in1, /* (i) the first vector for the 1.7926 + interpolation */ 1.7927 + float *in2, /* (i) the second vector for the 1.7928 + interpolation */ 1.7929 + float coef, /* (i) interpolation weights */ 1.7930 + int length /* (i) length of all vectors */ 1.7931 + ){ 1.7932 + int i; 1.7933 + float invcoef; 1.7934 + 1.7935 + invcoef = (float)1.0 - coef; 1.7936 + for (i = 0; i < length; i++) { 1.7937 + out[i] = coef * in1[i] + invcoef * in2[i]; 1.7938 + } 1.7939 + } 1.7940 + 1.7941 + /*----------------------------------------------------------------* 1.7942 + * lpc bandwidth expansion 1.7943 + *---------------------------------------------------------------*/ 1.7944 + 1.7945 + void bwexpand( 1.7946 + float *out, /* (o) the bandwidth expanded lpc 1.7947 + coefficients */ 1.7948 + float *in, /* (i) the lpc coefficients before bandwidth 1.7949 + expansion */ 1.7950 + float coef, /* (i) the bandwidth expansion factor */ 1.7951 + int length /* (i) the length of lpc coefficient vectors */ 1.7952 + ){ 1.7953 + int i; 1.7954 + 1.7955 + 1.7956 + 1.7957 +Andersen, et al. Experimental [Page 142] 1.7958 + 1.7959 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.7960 + 1.7961 + 1.7962 + float chirp; 1.7963 + 1.7964 + chirp = coef; 1.7965 + 1.7966 + out[0] = in[0]; 1.7967 + for (i = 1; i < length; i++) { 1.7968 + out[i] = chirp * in[i]; 1.7969 + chirp *= coef; 1.7970 + } 1.7971 + } 1.7972 + 1.7973 + /*----------------------------------------------------------------* 1.7974 + * vector quantization 1.7975 + *---------------------------------------------------------------*/ 1.7976 + 1.7977 + void vq( 1.7978 + float *Xq, /* (o) the quantized vector */ 1.7979 + int *index, /* (o) the quantization index */ 1.7980 + const float *CB,/* (i) the vector quantization codebook */ 1.7981 + float *X, /* (i) the vector to quantize */ 1.7982 + int n_cb, /* (i) the number of vectors in the codebook */ 1.7983 + int dim /* (i) the dimension of all vectors */ 1.7984 + ){ 1.7985 + int i, j; 1.7986 + int pos, minindex; 1.7987 + float dist, tmp, mindist; 1.7988 + 1.7989 + pos = 0; 1.7990 + mindist = FLOAT_MAX; 1.7991 + minindex = 0; 1.7992 + for (j = 0; j < n_cb; j++) { 1.7993 + dist = X[0] - CB[pos]; 1.7994 + dist *= dist; 1.7995 + for (i = 1; i < dim; i++) { 1.7996 + tmp = X[i] - CB[pos + i]; 1.7997 + dist += tmp*tmp; 1.7998 + } 1.7999 + 1.8000 + if (dist < mindist) { 1.8001 + mindist = dist; 1.8002 + minindex = j; 1.8003 + } 1.8004 + pos += dim; 1.8005 + } 1.8006 + for (i = 0; i < dim; i++) { 1.8007 + Xq[i] = CB[minindex*dim + i]; 1.8008 + } 1.8009 + *index = minindex; 1.8010 + 1.8011 + 1.8012 + 1.8013 +Andersen, et al. Experimental [Page 143] 1.8014 + 1.8015 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8016 + 1.8017 + 1.8018 + } 1.8019 + 1.8020 + /*----------------------------------------------------------------* 1.8021 + * split vector quantization 1.8022 + *---------------------------------------------------------------*/ 1.8023 + 1.8024 + void SplitVQ( 1.8025 + float *qX, /* (o) the quantized vector */ 1.8026 + int *index, /* (o) a vector of indexes for all vector 1.8027 + codebooks in the split */ 1.8028 + float *X, /* (i) the vector to quantize */ 1.8029 + const float *CB,/* (i) the quantizer codebook */ 1.8030 + int nsplit, /* the number of vector splits */ 1.8031 + const int *dim, /* the dimension of X and qX */ 1.8032 + const int *cbsize /* the number of vectors in the codebook */ 1.8033 + ){ 1.8034 + int cb_pos, X_pos, i; 1.8035 + 1.8036 + cb_pos = 0; 1.8037 + X_pos= 0; 1.8038 + for (i = 0; i < nsplit; i++) { 1.8039 + vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos, 1.8040 + cbsize[i], dim[i]); 1.8041 + X_pos += dim[i]; 1.8042 + cb_pos += dim[i] * cbsize[i]; 1.8043 + } 1.8044 + } 1.8045 + 1.8046 + /*----------------------------------------------------------------* 1.8047 + * scalar quantization 1.8048 + *---------------------------------------------------------------*/ 1.8049 + 1.8050 + void sort_sq( 1.8051 + float *xq, /* (o) the quantized value */ 1.8052 + int *index, /* (o) the quantization index */ 1.8053 + float x, /* (i) the value to quantize */ 1.8054 + const float *cb,/* (i) the quantization codebook */ 1.8055 + int cb_size /* (i) the size of the quantization codebook */ 1.8056 + ){ 1.8057 + int i; 1.8058 + 1.8059 + if (x <= cb[0]) { 1.8060 + *index = 0; 1.8061 + *xq = cb[0]; 1.8062 + } else { 1.8063 + i = 0; 1.8064 + while ((x > cb[i]) && i < cb_size - 1) { 1.8065 + i++; 1.8066 + 1.8067 + 1.8068 + 1.8069 +Andersen, et al. Experimental [Page 144] 1.8070 + 1.8071 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8072 + 1.8073 + 1.8074 + } 1.8075 + 1.8076 + if (x > ((cb[i] + cb[i - 1])/2)) { 1.8077 + *index = i; 1.8078 + *xq = cb[i]; 1.8079 + } else { 1.8080 + *index = i - 1; 1.8081 + *xq = cb[i - 1]; 1.8082 + } 1.8083 + } 1.8084 + } 1.8085 + 1.8086 + /*----------------------------------------------------------------* 1.8087 + * check for stability of lsf coefficients 1.8088 + *---------------------------------------------------------------*/ 1.8089 + 1.8090 + int LSF_check( /* (o) 1 for stable lsf vectors and 0 for 1.8091 + nonstable ones */ 1.8092 + float *lsf, /* (i) a table of lsf vectors */ 1.8093 + int dim, /* (i) the dimension of each lsf vector */ 1.8094 + int NoAn /* (i) the number of lsf vectors in the 1.8095 + table */ 1.8096 + ){ 1.8097 + int k,n,m, Nit=2, change=0,pos; 1.8098 + float tmp; 1.8099 + static float eps=(float)0.039; /* 50 Hz */ 1.8100 + static float eps2=(float)0.0195; 1.8101 + static float maxlsf=(float)3.14; /* 4000 Hz */ 1.8102 + static float minlsf=(float)0.01; /* 0 Hz */ 1.8103 + 1.8104 + /* LSF separation check*/ 1.8105 + 1.8106 + for (n=0; n<Nit; n++) { /* Run through a couple of times */ 1.8107 + for (m=0; m<NoAn; m++) { /* Number of analyses per frame */ 1.8108 + for (k=0; k<(dim-1); k++) { 1.8109 + pos=m*dim+k; 1.8110 + 1.8111 + if ((lsf[pos+1]-lsf[pos])<eps) { 1.8112 + 1.8113 + if (lsf[pos+1]<lsf[pos]) { 1.8114 + tmp=lsf[pos+1]; 1.8115 + lsf[pos+1]= lsf[pos]+eps2; 1.8116 + lsf[pos]= lsf[pos+1]-eps2; 1.8117 + } else { 1.8118 + lsf[pos]-=eps2; 1.8119 + lsf[pos+1]+=eps2; 1.8120 + } 1.8121 + change=1; 1.8122 + 1.8123 + 1.8124 + 1.8125 +Andersen, et al. Experimental [Page 145] 1.8126 + 1.8127 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8128 + 1.8129 + 1.8130 + } 1.8131 + 1.8132 + if (lsf[pos]<minlsf) { 1.8133 + lsf[pos]=minlsf; 1.8134 + change=1; 1.8135 + } 1.8136 + 1.8137 + if (lsf[pos]>maxlsf) { 1.8138 + lsf[pos]=maxlsf; 1.8139 + change=1; 1.8140 + } 1.8141 + } 1.8142 + } 1.8143 + } 1.8144 + 1.8145 + return change; 1.8146 + } 1.8147 + 1.8148 +A.27. hpInput.h 1.8149 + 1.8150 + /****************************************************************** 1.8151 + 1.8152 + iLBC Speech Coder ANSI-C Source Code 1.8153 + 1.8154 + hpInput.h 1.8155 + 1.8156 + Copyright (C) The Internet Society (2004). 1.8157 + All Rights Reserved. 1.8158 + 1.8159 + ******************************************************************/ 1.8160 + 1.8161 + #ifndef __iLBC_HPINPUT_H 1.8162 + #define __iLBC_HPINPUT_H 1.8163 + 1.8164 + void hpInput( 1.8165 + float *In, /* (i) vector to filter */ 1.8166 + int len, /* (i) length of vector to filter */ 1.8167 + float *Out, /* (o) the resulting filtered vector */ 1.8168 + float *mem /* (i/o) the filter state */ 1.8169 + ); 1.8170 + 1.8171 + #endif 1.8172 + 1.8173 +A.28. hpInput.c 1.8174 + 1.8175 + /****************************************************************** 1.8176 + 1.8177 + iLBC Speech Coder ANSI-C Source Code 1.8178 + 1.8179 + 1.8180 + 1.8181 +Andersen, et al. Experimental [Page 146] 1.8182 + 1.8183 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8184 + 1.8185 + 1.8186 + hpInput.c 1.8187 + 1.8188 + Copyright (C) The Internet Society (2004). 1.8189 + All Rights Reserved. 1.8190 + 1.8191 + ******************************************************************/ 1.8192 + 1.8193 + #include "constants.h" 1.8194 + 1.8195 + /*----------------------------------------------------------------* 1.8196 + * Input high-pass filter 1.8197 + *---------------------------------------------------------------*/ 1.8198 + 1.8199 + void hpInput( 1.8200 + float *In, /* (i) vector to filter */ 1.8201 + int len, /* (i) length of vector to filter */ 1.8202 + float *Out, /* (o) the resulting filtered vector */ 1.8203 + float *mem /* (i/o) the filter state */ 1.8204 + ){ 1.8205 + int i; 1.8206 + float *pi, *po; 1.8207 + 1.8208 + /* all-zero section*/ 1.8209 + 1.8210 + pi = &In[0]; 1.8211 + po = &Out[0]; 1.8212 + for (i=0; i<len; i++) { 1.8213 + *po = hpi_zero_coefsTbl[0] * (*pi); 1.8214 + *po += hpi_zero_coefsTbl[1] * mem[0]; 1.8215 + *po += hpi_zero_coefsTbl[2] * mem[1]; 1.8216 + 1.8217 + mem[1] = mem[0]; 1.8218 + mem[0] = *pi; 1.8219 + po++; 1.8220 + pi++; 1.8221 + 1.8222 + } 1.8223 + 1.8224 + /* all-pole section*/ 1.8225 + 1.8226 + po = &Out[0]; 1.8227 + for (i=0; i<len; i++) { 1.8228 + *po -= hpi_pole_coefsTbl[1] * mem[2]; 1.8229 + *po -= hpi_pole_coefsTbl[2] * mem[3]; 1.8230 + 1.8231 + mem[3] = mem[2]; 1.8232 + mem[2] = *po; 1.8233 + po++; 1.8234 + 1.8235 + 1.8236 + 1.8237 +Andersen, et al. Experimental [Page 147] 1.8238 + 1.8239 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8240 + 1.8241 + 1.8242 + } 1.8243 + } 1.8244 + 1.8245 +A.29. hpOutput.h 1.8246 + 1.8247 + /****************************************************************** 1.8248 + 1.8249 + iLBC Speech Coder ANSI-C Source Code 1.8250 + 1.8251 + hpOutput.h 1.8252 + 1.8253 + Copyright (C) The Internet Society (2004). 1.8254 + All Rights Reserved. 1.8255 + 1.8256 + ******************************************************************/ 1.8257 + 1.8258 + #ifndef __iLBC_HPOUTPUT_H 1.8259 + #define __iLBC_HPOUTPUT_H 1.8260 + 1.8261 + void hpOutput( 1.8262 + float *In, /* (i) vector to filter */ 1.8263 + int len,/* (i) length of vector to filter */ 1.8264 + float *Out, /* (o) the resulting filtered vector */ 1.8265 + float *mem /* (i/o) the filter state */ 1.8266 + ); 1.8267 + 1.8268 + #endif 1.8269 + 1.8270 +A.30. hpOutput.c 1.8271 + 1.8272 + /****************************************************************** 1.8273 + 1.8274 + iLBC Speech Coder ANSI-C Source Code 1.8275 + 1.8276 + hpOutput.c 1.8277 + 1.8278 + Copyright (C) The Internet Society (2004). 1.8279 + All Rights Reserved. 1.8280 + 1.8281 + ******************************************************************/ 1.8282 + 1.8283 + #include "constants.h" 1.8284 + 1.8285 + /*----------------------------------------------------------------* 1.8286 + * Output high-pass filter 1.8287 + *---------------------------------------------------------------*/ 1.8288 + 1.8289 + void hpOutput( 1.8290 + 1.8291 + 1.8292 + 1.8293 +Andersen, et al. Experimental [Page 148] 1.8294 + 1.8295 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8296 + 1.8297 + 1.8298 + float *In, /* (i) vector to filter */ 1.8299 + int len,/* (i) length of vector to filter */ 1.8300 + float *Out, /* (o) the resulting filtered vector */ 1.8301 + float *mem /* (i/o) the filter state */ 1.8302 + ){ 1.8303 + int i; 1.8304 + float *pi, *po; 1.8305 + 1.8306 + /* all-zero section*/ 1.8307 + 1.8308 + pi = &In[0]; 1.8309 + po = &Out[0]; 1.8310 + for (i=0; i<len; i++) { 1.8311 + *po = hpo_zero_coefsTbl[0] * (*pi); 1.8312 + *po += hpo_zero_coefsTbl[1] * mem[0]; 1.8313 + *po += hpo_zero_coefsTbl[2] * mem[1]; 1.8314 + 1.8315 + mem[1] = mem[0]; 1.8316 + mem[0] = *pi; 1.8317 + po++; 1.8318 + pi++; 1.8319 + 1.8320 + } 1.8321 + 1.8322 + /* all-pole section*/ 1.8323 + 1.8324 + po = &Out[0]; 1.8325 + for (i=0; i<len; i++) { 1.8326 + *po -= hpo_pole_coefsTbl[1] * mem[2]; 1.8327 + *po -= hpo_pole_coefsTbl[2] * mem[3]; 1.8328 + 1.8329 + mem[3] = mem[2]; 1.8330 + mem[2] = *po; 1.8331 + po++; 1.8332 + } 1.8333 + } 1.8334 + 1.8335 +A.31. iCBConstruct.h 1.8336 + 1.8337 + /****************************************************************** 1.8338 + 1.8339 + iLBC Speech Coder ANSI-C Source Code 1.8340 + 1.8341 + iCBConstruct.h 1.8342 + 1.8343 + Copyright (C) The Internet Society (2004). 1.8344 + All Rights Reserved. 1.8345 + 1.8346 + 1.8347 + 1.8348 + 1.8349 +Andersen, et al. Experimental [Page 149] 1.8350 + 1.8351 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8352 + 1.8353 + 1.8354 + ******************************************************************/ 1.8355 + 1.8356 + #ifndef __iLBC_ICBCONSTRUCT_H 1.8357 + #define __iLBC_ICBCONSTRUCT_H 1.8358 + 1.8359 + void index_conv_enc( 1.8360 + int *index /* (i/o) Codebook indexes */ 1.8361 + ); 1.8362 + 1.8363 + void index_conv_dec( 1.8364 + int *index /* (i/o) Codebook indexes */ 1.8365 + ); 1.8366 + 1.8367 + void iCBConstruct( 1.8368 + float *decvector, /* (o) Decoded vector */ 1.8369 + int *index, /* (i) Codebook indices */ 1.8370 + int *gain_index,/* (i) Gain quantization indices */ 1.8371 + float *mem, /* (i) Buffer for codevector construction */ 1.8372 + int lMem, /* (i) Length of buffer */ 1.8373 + int veclen, /* (i) Length of vector */ 1.8374 + int nStages /* (i) Number of codebook stages */ 1.8375 + ); 1.8376 + 1.8377 + #endif 1.8378 + 1.8379 +A.32. iCBConstruct.c 1.8380 + 1.8381 + /****************************************************************** 1.8382 + 1.8383 + iLBC Speech Coder ANSI-C Source Code 1.8384 + 1.8385 + iCBConstruct.c 1.8386 + 1.8387 + Copyright (C) The Internet Society (2004). 1.8388 + All Rights Reserved. 1.8389 + 1.8390 + ******************************************************************/ 1.8391 + 1.8392 + #include <math.h> 1.8393 + 1.8394 + #include "iLBC_define.h" 1.8395 + #include "gainquant.h" 1.8396 + #include "getCBvec.h" 1.8397 + 1.8398 + /*----------------------------------------------------------------* 1.8399 + * Convert the codebook indexes to make the search easier 1.8400 + *---------------------------------------------------------------*/ 1.8401 + 1.8402 + 1.8403 + 1.8404 + 1.8405 +Andersen, et al. Experimental [Page 150] 1.8406 + 1.8407 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8408 + 1.8409 + 1.8410 + void index_conv_enc( 1.8411 + int *index /* (i/o) Codebook indexes */ 1.8412 + ){ 1.8413 + int k; 1.8414 + 1.8415 + for (k=1; k<CB_NSTAGES; k++) { 1.8416 + 1.8417 + if ((index[k]>=108)&&(index[k]<172)) { 1.8418 + index[k]-=64; 1.8419 + } else if (index[k]>=236) { 1.8420 + index[k]-=128; 1.8421 + } else { 1.8422 + /* ERROR */ 1.8423 + } 1.8424 + } 1.8425 + } 1.8426 + 1.8427 + void index_conv_dec( 1.8428 + int *index /* (i/o) Codebook indexes */ 1.8429 + ){ 1.8430 + int k; 1.8431 + 1.8432 + for (k=1; k<CB_NSTAGES; k++) { 1.8433 + 1.8434 + if ((index[k]>=44)&&(index[k]<108)) { 1.8435 + index[k]+=64; 1.8436 + } else if ((index[k]>=108)&&(index[k]<128)) { 1.8437 + index[k]+=128; 1.8438 + } else { 1.8439 + /* ERROR */ 1.8440 + } 1.8441 + } 1.8442 + } 1.8443 + 1.8444 + /*----------------------------------------------------------------* 1.8445 + * Construct decoded vector from codebook and gains. 1.8446 + *---------------------------------------------------------------*/ 1.8447 + 1.8448 + void iCBConstruct( 1.8449 + float *decvector, /* (o) Decoded vector */ 1.8450 + int *index, /* (i) Codebook indices */ 1.8451 + int *gain_index,/* (i) Gain quantization indices */ 1.8452 + float *mem, /* (i) Buffer for codevector construction */ 1.8453 + int lMem, /* (i) Length of buffer */ 1.8454 + int veclen, /* (i) Length of vector */ 1.8455 + int nStages /* (i) Number of codebook stages */ 1.8456 + ){ 1.8457 + int j,k; 1.8458 + 1.8459 + 1.8460 + 1.8461 +Andersen, et al. Experimental [Page 151] 1.8462 + 1.8463 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8464 + 1.8465 + 1.8466 + float gain[CB_NSTAGES]; 1.8467 + float cbvec[SUBL]; 1.8468 + 1.8469 + /* gain de-quantization */ 1.8470 + 1.8471 + gain[0] = gaindequant(gain_index[0], 1.0, 32); 1.8472 + if (nStages > 1) { 1.8473 + gain[1] = gaindequant(gain_index[1], 1.8474 + (float)fabs(gain[0]), 16); 1.8475 + } 1.8476 + if (nStages > 2) { 1.8477 + gain[2] = gaindequant(gain_index[2], 1.8478 + (float)fabs(gain[1]), 8); 1.8479 + } 1.8480 + 1.8481 + /* codebook vector construction and construction of 1.8482 + total vector */ 1.8483 + 1.8484 + getCBvec(cbvec, mem, index[0], lMem, veclen); 1.8485 + for (j=0;j<veclen;j++){ 1.8486 + decvector[j] = gain[0]*cbvec[j]; 1.8487 + } 1.8488 + if (nStages > 1) { 1.8489 + for (k=1; k<nStages; k++) { 1.8490 + getCBvec(cbvec, mem, index[k], lMem, veclen); 1.8491 + for (j=0;j<veclen;j++) { 1.8492 + decvector[j] += gain[k]*cbvec[j]; 1.8493 + } 1.8494 + } 1.8495 + } 1.8496 + } 1.8497 + 1.8498 +A.33. iCBSearch.h 1.8499 + 1.8500 + /****************************************************************** 1.8501 + 1.8502 + iLBC Speech Coder ANSI-C Source Code 1.8503 + 1.8504 + iCBSearch.h 1.8505 + 1.8506 + Copyright (C) The Internet Society (2004). 1.8507 + All Rights Reserved. 1.8508 + 1.8509 + ******************************************************************/ 1.8510 + 1.8511 + #ifndef __iLBC_ICBSEARCH_H 1.8512 + #define __iLBC_ICBSEARCH_H 1.8513 + 1.8514 + 1.8515 + 1.8516 + 1.8517 +Andersen, et al. Experimental [Page 152] 1.8518 + 1.8519 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8520 + 1.8521 + 1.8522 + void iCBSearch( 1.8523 + iLBC_Enc_Inst_t *iLBCenc_inst, 1.8524 + /* (i) the encoder state structure */ 1.8525 + int *index, /* (o) Codebook indices */ 1.8526 + int *gain_index,/* (o) Gain quantization indices */ 1.8527 + float *intarget,/* (i) Target vector for encoding */ 1.8528 + float *mem, /* (i) Buffer for codebook construction */ 1.8529 + int lMem, /* (i) Length of buffer */ 1.8530 + int lTarget, /* (i) Length of vector */ 1.8531 + int nStages, /* (i) Number of codebook stages */ 1.8532 + float *weightDenum, /* (i) weighting filter coefficients */ 1.8533 + float *weightState, /* (i) weighting filter state */ 1.8534 + int block /* (i) the sub-block number */ 1.8535 + ); 1.8536 + 1.8537 + #endif 1.8538 + 1.8539 +A.34. iCBSearch.c 1.8540 + 1.8541 + /****************************************************************** 1.8542 + 1.8543 + iLBC Speech Coder ANSI-C Source Code 1.8544 + 1.8545 + iCBSearch.c 1.8546 + 1.8547 + Copyright (C) The Internet Society (2004). 1.8548 + All Rights Reserved. 1.8549 + 1.8550 + ******************************************************************/ 1.8551 + 1.8552 + #include <math.h> 1.8553 + #include <string.h> 1.8554 + 1.8555 + #include "iLBC_define.h" 1.8556 + #include "gainquant.h" 1.8557 + #include "createCB.h" 1.8558 + #include "filter.h" 1.8559 + #include "constants.h" 1.8560 + 1.8561 + /*----------------------------------------------------------------* 1.8562 + * Search routine for codebook encoding and gain quantization. 1.8563 + *---------------------------------------------------------------*/ 1.8564 + 1.8565 + void iCBSearch( 1.8566 + iLBC_Enc_Inst_t *iLBCenc_inst, 1.8567 + /* (i) the encoder state structure */ 1.8568 + int *index, /* (o) Codebook indices */ 1.8569 + int *gain_index,/* (o) Gain quantization indices */ 1.8570 + 1.8571 + 1.8572 + 1.8573 +Andersen, et al. Experimental [Page 153] 1.8574 + 1.8575 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8576 + 1.8577 + 1.8578 + float *intarget,/* (i) Target vector for encoding */ 1.8579 + float *mem, /* (i) Buffer for codebook construction */ 1.8580 + int lMem, /* (i) Length of buffer */ 1.8581 + int lTarget, /* (i) Length of vector */ 1.8582 + int nStages, /* (i) Number of codebook stages */ 1.8583 + float *weightDenum, /* (i) weighting filter coefficients */ 1.8584 + float *weightState, /* (i) weighting filter state */ 1.8585 + int block /* (i) the sub-block number */ 1.8586 + ){ 1.8587 + int i, j, icount, stage, best_index, range, counter; 1.8588 + float max_measure, gain, measure, crossDot, ftmp; 1.8589 + float gains[CB_NSTAGES]; 1.8590 + float target[SUBL]; 1.8591 + int base_index, sInd, eInd, base_size; 1.8592 + int sIndAug=0, eIndAug=0; 1.8593 + float buf[CB_MEML+SUBL+2*LPC_FILTERORDER]; 1.8594 + float invenergy[CB_EXPAND*128], energy[CB_EXPAND*128]; 1.8595 + float *pp, *ppi=0, *ppo=0, *ppe=0; 1.8596 + float cbvectors[CB_MEML]; 1.8597 + float tene, cene, cvec[SUBL]; 1.8598 + float aug_vec[SUBL]; 1.8599 + 1.8600 + memset(cvec,0,SUBL*sizeof(float)); 1.8601 + 1.8602 + /* Determine size of codebook sections */ 1.8603 + 1.8604 + base_size=lMem-lTarget+1; 1.8605 + 1.8606 + if (lTarget==SUBL) { 1.8607 + base_size=lMem-lTarget+1+lTarget/2; 1.8608 + } 1.8609 + 1.8610 + /* setup buffer for weighting */ 1.8611 + 1.8612 + memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER); 1.8613 + memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float)); 1.8614 + memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float)); 1.8615 + 1.8616 + /* weighting */ 1.8617 + 1.8618 + AllPoleFilter(buf+LPC_FILTERORDER, weightDenum, 1.8619 + lMem+lTarget, LPC_FILTERORDER); 1.8620 + 1.8621 + /* Construct the codebook and target needed */ 1.8622 + 1.8623 + memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float)); 1.8624 + 1.8625 + tene=0.0; 1.8626 + 1.8627 + 1.8628 + 1.8629 +Andersen, et al. Experimental [Page 154] 1.8630 + 1.8631 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8632 + 1.8633 + 1.8634 + for (i=0; i<lTarget; i++) { 1.8635 + tene+=target[i]*target[i]; 1.8636 + } 1.8637 + 1.8638 + /* Prepare search over one more codebook section. This section 1.8639 + is created by filtering the original buffer with a filter. */ 1.8640 + 1.8641 + filteredCBvecs(cbvectors, buf+LPC_FILTERORDER, lMem); 1.8642 + 1.8643 + /* The Main Loop over stages */ 1.8644 + 1.8645 + for (stage=0; stage<nStages; stage++) { 1.8646 + 1.8647 + range = search_rangeTbl[block][stage]; 1.8648 + 1.8649 + /* initialize search measure */ 1.8650 + 1.8651 + max_measure = (float)-10000000.0; 1.8652 + gain = (float)0.0; 1.8653 + best_index = 0; 1.8654 + 1.8655 + /* Compute cross dot product between the target 1.8656 + and the CB memory */ 1.8657 + 1.8658 + crossDot=0.0; 1.8659 + pp=buf+LPC_FILTERORDER+lMem-lTarget; 1.8660 + for (j=0; j<lTarget; j++) { 1.8661 + crossDot += target[j]*(*pp++); 1.8662 + } 1.8663 + 1.8664 + if (stage==0) { 1.8665 + 1.8666 + /* Calculate energy in the first block of 1.8667 + 'lTarget' samples. */ 1.8668 + ppe = energy; 1.8669 + ppi = buf+LPC_FILTERORDER+lMem-lTarget-1; 1.8670 + ppo = buf+LPC_FILTERORDER+lMem-1; 1.8671 + 1.8672 + *ppe=0.0; 1.8673 + pp=buf+LPC_FILTERORDER+lMem-lTarget; 1.8674 + for (j=0; j<lTarget; j++) { 1.8675 + *ppe+=(*pp)*(*pp++); 1.8676 + } 1.8677 + 1.8678 + if (*ppe>0.0) { 1.8679 + invenergy[0] = (float) 1.0 / (*ppe + EPS); 1.8680 + } else { 1.8681 + invenergy[0] = (float) 0.0; 1.8682 + 1.8683 + 1.8684 + 1.8685 +Andersen, et al. Experimental [Page 155] 1.8686 + 1.8687 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8688 + 1.8689 + 1.8690 + } 1.8691 + ppe++; 1.8692 + 1.8693 + measure=(float)-10000000.0; 1.8694 + 1.8695 + if (crossDot > 0.0) { 1.8696 + measure = crossDot*crossDot*invenergy[0]; 1.8697 + } 1.8698 + } 1.8699 + else { 1.8700 + measure = crossDot*crossDot*invenergy[0]; 1.8701 + } 1.8702 + 1.8703 + /* check if measure is better */ 1.8704 + ftmp = crossDot*invenergy[0]; 1.8705 + 1.8706 + if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) { 1.8707 + best_index = 0; 1.8708 + max_measure = measure; 1.8709 + gain = ftmp; 1.8710 + } 1.8711 + 1.8712 + /* loop over the main first codebook section, 1.8713 + full search */ 1.8714 + 1.8715 + for (icount=1; icount<range; icount++) { 1.8716 + 1.8717 + /* calculate measure */ 1.8718 + 1.8719 + crossDot=0.0; 1.8720 + pp = buf+LPC_FILTERORDER+lMem-lTarget-icount; 1.8721 + 1.8722 + for (j=0; j<lTarget; j++) { 1.8723 + crossDot += target[j]*(*pp++); 1.8724 + } 1.8725 + 1.8726 + if (stage==0) { 1.8727 + *ppe++ = energy[icount-1] + (*ppi)*(*ppi) - 1.8728 + (*ppo)*(*ppo); 1.8729 + ppo--; 1.8730 + ppi--; 1.8731 + 1.8732 + if (energy[icount]>0.0) { 1.8733 + invenergy[icount] = 1.8734 + (float)1.0/(energy[icount]+EPS); 1.8735 + } else { 1.8736 + invenergy[icount] = (float) 0.0; 1.8737 + } 1.8738 + 1.8739 + 1.8740 + 1.8741 +Andersen, et al. Experimental [Page 156] 1.8742 + 1.8743 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8744 + 1.8745 + 1.8746 + measure=(float)-10000000.0; 1.8747 + 1.8748 + if (crossDot > 0.0) { 1.8749 + measure = crossDot*crossDot*invenergy[icount]; 1.8750 + } 1.8751 + } 1.8752 + else { 1.8753 + measure = crossDot*crossDot*invenergy[icount]; 1.8754 + } 1.8755 + 1.8756 + /* check if measure is better */ 1.8757 + ftmp = crossDot*invenergy[icount]; 1.8758 + 1.8759 + if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) { 1.8760 + best_index = icount; 1.8761 + max_measure = measure; 1.8762 + gain = ftmp; 1.8763 + } 1.8764 + } 1.8765 + 1.8766 + /* Loop over augmented part in the first codebook 1.8767 + * section, full search. 1.8768 + * The vectors are interpolated. 1.8769 + */ 1.8770 + 1.8771 + if (lTarget==SUBL) { 1.8772 + 1.8773 + /* Search for best possible cb vector and 1.8774 + compute the CB-vectors' energy. */ 1.8775 + searchAugmentedCB(20, 39, stage, base_size-lTarget/2, 1.8776 + target, buf+LPC_FILTERORDER+lMem, 1.8777 + &max_measure, &best_index, &gain, energy, 1.8778 + invenergy); 1.8779 + } 1.8780 + 1.8781 + /* set search range for following codebook sections */ 1.8782 + 1.8783 + base_index=best_index; 1.8784 + 1.8785 + /* unrestricted search */ 1.8786 + 1.8787 + if (CB_RESRANGE == -1) { 1.8788 + sInd=0; 1.8789 + eInd=range-1; 1.8790 + sIndAug=20; 1.8791 + eIndAug=39; 1.8792 + } 1.8793 + 1.8794 + 1.8795 + 1.8796 + 1.8797 +Andersen, et al. Experimental [Page 157] 1.8798 + 1.8799 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8800 + 1.8801 + 1.8802 + /* restricted search around best index from first 1.8803 + codebook section */ 1.8804 + 1.8805 + else { 1.8806 + /* Initialize search indices */ 1.8807 + sIndAug=0; 1.8808 + eIndAug=0; 1.8809 + sInd=base_index-CB_RESRANGE/2; 1.8810 + eInd=sInd+CB_RESRANGE; 1.8811 + 1.8812 + if (lTarget==SUBL) { 1.8813 + 1.8814 + if (sInd<0) { 1.8815 + 1.8816 + sIndAug = 40 + sInd; 1.8817 + eIndAug = 39; 1.8818 + sInd=0; 1.8819 + 1.8820 + } else if ( base_index < (base_size-20) ) { 1.8821 + 1.8822 + if (eInd > range) { 1.8823 + sInd -= (eInd-range); 1.8824 + eInd = range; 1.8825 + } 1.8826 + } else { /* base_index >= (base_size-20) */ 1.8827 + 1.8828 + if (sInd < (base_size-20)) { 1.8829 + sIndAug = 20; 1.8830 + sInd = 0; 1.8831 + eInd = 0; 1.8832 + eIndAug = 19 + CB_RESRANGE; 1.8833 + 1.8834 + if(eIndAug > 39) { 1.8835 + eInd = eIndAug-39; 1.8836 + eIndAug = 39; 1.8837 + } 1.8838 + } else { 1.8839 + sIndAug = 20 + sInd - (base_size-20); 1.8840 + eIndAug = 39; 1.8841 + sInd = 0; 1.8842 + eInd = CB_RESRANGE - (eIndAug-sIndAug+1); 1.8843 + } 1.8844 + } 1.8845 + 1.8846 + } else { /* lTarget = 22 or 23 */ 1.8847 + 1.8848 + if (sInd < 0) { 1.8849 + eInd -= sInd; 1.8850 + 1.8851 + 1.8852 + 1.8853 +Andersen, et al. Experimental [Page 158] 1.8854 + 1.8855 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8856 + 1.8857 + 1.8858 + sInd = 0; 1.8859 + } 1.8860 + 1.8861 + if(eInd > range) { 1.8862 + sInd -= (eInd - range); 1.8863 + eInd = range; 1.8864 + } 1.8865 + } 1.8866 + } 1.8867 + 1.8868 + /* search of higher codebook section */ 1.8869 + 1.8870 + /* index search range */ 1.8871 + counter = sInd; 1.8872 + sInd += base_size; 1.8873 + eInd += base_size; 1.8874 + 1.8875 + 1.8876 + if (stage==0) { 1.8877 + ppe = energy+base_size; 1.8878 + *ppe=0.0; 1.8879 + 1.8880 + pp=cbvectors+lMem-lTarget; 1.8881 + for (j=0; j<lTarget; j++) { 1.8882 + *ppe+=(*pp)*(*pp++); 1.8883 + } 1.8884 + 1.8885 + ppi = cbvectors + lMem - 1 - lTarget; 1.8886 + ppo = cbvectors + lMem - 1; 1.8887 + 1.8888 + for (j=0; j<(range-1); j++) { 1.8889 + *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo); 1.8890 + ppo--; 1.8891 + ppi--; 1.8892 + ppe++; 1.8893 + } 1.8894 + } 1.8895 + 1.8896 + /* loop over search range */ 1.8897 + 1.8898 + for (icount=sInd; icount<eInd; icount++) { 1.8899 + 1.8900 + /* calculate measure */ 1.8901 + 1.8902 + crossDot=0.0; 1.8903 + pp=cbvectors + lMem - (counter++) - lTarget; 1.8904 + 1.8905 + for (j=0;j<lTarget;j++) { 1.8906 + 1.8907 + 1.8908 + 1.8909 +Andersen, et al. Experimental [Page 159] 1.8910 + 1.8911 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8912 + 1.8913 + 1.8914 + crossDot += target[j]*(*pp++); 1.8915 + } 1.8916 + 1.8917 + if (energy[icount]>0.0) { 1.8918 + invenergy[icount] =(float)1.0/(energy[icount]+EPS); 1.8919 + } else { 1.8920 + invenergy[icount] =(float)0.0; 1.8921 + } 1.8922 + 1.8923 + if (stage==0) { 1.8924 + 1.8925 + measure=(float)-10000000.0; 1.8926 + 1.8927 + if (crossDot > 0.0) { 1.8928 + measure = crossDot*crossDot* 1.8929 + invenergy[icount]; 1.8930 + } 1.8931 + } 1.8932 + else { 1.8933 + measure = crossDot*crossDot*invenergy[icount]; 1.8934 + } 1.8935 + 1.8936 + /* check if measure is better */ 1.8937 + ftmp = crossDot*invenergy[icount]; 1.8938 + 1.8939 + if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) { 1.8940 + best_index = icount; 1.8941 + max_measure = measure; 1.8942 + gain = ftmp; 1.8943 + } 1.8944 + } 1.8945 + 1.8946 + /* Search the augmented CB inside the limited range. */ 1.8947 + 1.8948 + if ((lTarget==SUBL)&&(sIndAug!=0)) { 1.8949 + searchAugmentedCB(sIndAug, eIndAug, stage, 1.8950 + 2*base_size-20, target, cbvectors+lMem, 1.8951 + &max_measure, &best_index, &gain, energy, 1.8952 + invenergy); 1.8953 + } 1.8954 + 1.8955 + /* record best index */ 1.8956 + 1.8957 + index[stage] = best_index; 1.8958 + 1.8959 + /* gain quantization */ 1.8960 + 1.8961 + if (stage==0){ 1.8962 + 1.8963 + 1.8964 + 1.8965 +Andersen, et al. Experimental [Page 160] 1.8966 + 1.8967 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.8968 + 1.8969 + 1.8970 + 1.8971 + if (gain<0.0){ 1.8972 + gain = 0.0; 1.8973 + } 1.8974 + 1.8975 + if (gain>CB_MAXGAIN) { 1.8976 + gain = (float)CB_MAXGAIN; 1.8977 + } 1.8978 + gain = gainquant(gain, 1.0, 32, &gain_index[stage]); 1.8979 + } 1.8980 + else { 1.8981 + if (stage==1) { 1.8982 + gain = gainquant(gain, (float)fabs(gains[stage-1]), 1.8983 + 16, &gain_index[stage]); 1.8984 + } else { 1.8985 + gain = gainquant(gain, (float)fabs(gains[stage-1]), 1.8986 + 8, &gain_index[stage]); 1.8987 + } 1.8988 + } 1.8989 + 1.8990 + /* Extract the best (according to measure) 1.8991 + codebook vector */ 1.8992 + 1.8993 + if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) { 1.8994 + 1.8995 + if (index[stage]<base_size) { 1.8996 + pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage]; 1.8997 + } else { 1.8998 + pp=cbvectors+lMem-lTarget- 1.8999 + index[stage]+base_size; 1.9000 + } 1.9001 + } else { 1.9002 + 1.9003 + if (index[stage]<base_size) { 1.9004 + if (index[stage]<(base_size-20)) { 1.9005 + pp=buf+LPC_FILTERORDER+lMem- 1.9006 + lTarget-index[stage]; 1.9007 + } else { 1.9008 + createAugmentedVec(index[stage]-base_size+40, 1.9009 + buf+LPC_FILTERORDER+lMem,aug_vec); 1.9010 + pp=aug_vec; 1.9011 + } 1.9012 + } else { 1.9013 + int filterno, position; 1.9014 + 1.9015 + filterno=index[stage]/base_size; 1.9016 + position=index[stage]-filterno*base_size; 1.9017 + 1.9018 + 1.9019 + 1.9020 + 1.9021 +Andersen, et al. Experimental [Page 161] 1.9022 + 1.9023 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9024 + 1.9025 + 1.9026 + 1.9027 + if (position<(base_size-20)) { 1.9028 + pp=cbvectors+filterno*lMem-lTarget- 1.9029 + index[stage]+filterno*base_size; 1.9030 + } else { 1.9031 + createAugmentedVec( 1.9032 + index[stage]-(filterno+1)*base_size+40, 1.9033 + cbvectors+filterno*lMem,aug_vec); 1.9034 + pp=aug_vec; 1.9035 + } 1.9036 + } 1.9037 + } 1.9038 + 1.9039 + /* Subtract the best codebook vector, according 1.9040 + to measure, from the target vector */ 1.9041 + 1.9042 + for (j=0;j<lTarget;j++) { 1.9043 + cvec[j] += gain*(*pp); 1.9044 + target[j] -= gain*(*pp++); 1.9045 + } 1.9046 + 1.9047 + /* record quantized gain */ 1.9048 + 1.9049 + gains[stage]=gain; 1.9050 + 1.9051 + }/* end of Main Loop. for (stage=0;... */ 1.9052 + 1.9053 + /* Gain adjustment for energy matching */ 1.9054 + cene=0.0; 1.9055 + for (i=0; i<lTarget; i++) { 1.9056 + cene+=cvec[i]*cvec[i]; 1.9057 + } 1.9058 + j=gain_index[0]; 1.9059 + 1.9060 + for (i=gain_index[0]; i<32; i++) { 1.9061 + ftmp=cene*gain_sq5Tbl[i]*gain_sq5Tbl[i]; 1.9062 + 1.9063 + if ((ftmp<(tene*gains[0]*gains[0])) && 1.9064 + (gain_sq5Tbl[j]<(2.0*gains[0]))) { 1.9065 + j=i; 1.9066 + } 1.9067 + } 1.9068 + gain_index[0]=j; 1.9069 + } 1.9070 + 1.9071 + 1.9072 + 1.9073 + 1.9074 + 1.9075 + 1.9076 + 1.9077 +Andersen, et al. Experimental [Page 162] 1.9078 + 1.9079 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9080 + 1.9081 + 1.9082 +A.35. LPCdecode.h 1.9083 + 1.9084 + /****************************************************************** 1.9085 + 1.9086 + iLBC Speech Coder ANSI-C Source Code 1.9087 + 1.9088 + LPC_decode.h 1.9089 + 1.9090 + Copyright (C) The Internet Society (2004). 1.9091 + All Rights Reserved. 1.9092 + 1.9093 + ******************************************************************/ 1.9094 + 1.9095 + #ifndef __iLBC_LPC_DECODE_H 1.9096 + #define __iLBC_LPC_DECODE_H 1.9097 + 1.9098 + void LSFinterpolate2a_dec( 1.9099 + float *a, /* (o) lpc coefficients for a sub-frame */ 1.9100 + float *lsf1, /* (i) first lsf coefficient vector */ 1.9101 + float *lsf2, /* (i) second lsf coefficient vector */ 1.9102 + float coef, /* (i) interpolation weight */ 1.9103 + int length /* (i) length of lsf vectors */ 1.9104 + ); 1.9105 + 1.9106 + void SimplelsfDEQ( 1.9107 + float *lsfdeq, /* (o) dequantized lsf coefficients */ 1.9108 + int *index, /* (i) quantization index */ 1.9109 + int lpc_n /* (i) number of LPCs */ 1.9110 + ); 1.9111 + 1.9112 + void DecoderInterpolateLSF( 1.9113 + float *syntdenum, /* (o) synthesis filter coefficients */ 1.9114 + float *weightdenum, /* (o) weighting denumerator 1.9115 + coefficients */ 1.9116 + float *lsfdeq, /* (i) dequantized lsf coefficients */ 1.9117 + int length, /* (i) length of lsf coefficient vector */ 1.9118 + iLBC_Dec_Inst_t *iLBCdec_inst 1.9119 + /* (i) the decoder state structure */ 1.9120 + ); 1.9121 + 1.9122 + #endif 1.9123 + 1.9124 + 1.9125 + 1.9126 + 1.9127 + 1.9128 + 1.9129 + 1.9130 + 1.9131 + 1.9132 + 1.9133 +Andersen, et al. Experimental [Page 163] 1.9134 + 1.9135 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9136 + 1.9137 + 1.9138 +A.36. LPCdecode.c 1.9139 + 1.9140 + /****************************************************************** 1.9141 + 1.9142 + iLBC Speech Coder ANSI-C Source Code 1.9143 + 1.9144 + LPC_decode.c 1.9145 + 1.9146 + Copyright (C) The Internet Society (2004). 1.9147 + All Rights Reserved. 1.9148 + 1.9149 + ******************************************************************/ 1.9150 + 1.9151 + #include <math.h> 1.9152 + #include <string.h> 1.9153 + 1.9154 + #include "helpfun.h" 1.9155 + #include "lsf.h" 1.9156 + #include "iLBC_define.h" 1.9157 + #include "constants.h" 1.9158 + 1.9159 + /*---------------------------------------------------------------* 1.9160 + * interpolation of lsf coefficients for the decoder 1.9161 + *--------------------------------------------------------------*/ 1.9162 + 1.9163 + void LSFinterpolate2a_dec( 1.9164 + float *a, /* (o) lpc coefficients for a sub-frame */ 1.9165 + float *lsf1, /* (i) first lsf coefficient vector */ 1.9166 + float *lsf2, /* (i) second lsf coefficient vector */ 1.9167 + float coef, /* (i) interpolation weight */ 1.9168 + int length /* (i) length of lsf vectors */ 1.9169 + ){ 1.9170 + float lsftmp[LPC_FILTERORDER]; 1.9171 + 1.9172 + interpolate(lsftmp, lsf1, lsf2, coef, length); 1.9173 + lsf2a(a, lsftmp); 1.9174 + } 1.9175 + 1.9176 + /*---------------------------------------------------------------* 1.9177 + * obtain dequantized lsf coefficients from quantization index 1.9178 + *--------------------------------------------------------------*/ 1.9179 + 1.9180 + void SimplelsfDEQ( 1.9181 + float *lsfdeq, /* (o) dequantized lsf coefficients */ 1.9182 + int *index, /* (i) quantization index */ 1.9183 + int lpc_n /* (i) number of LPCs */ 1.9184 + ){ 1.9185 + int i, j, pos, cb_pos; 1.9186 + 1.9187 + 1.9188 + 1.9189 +Andersen, et al. Experimental [Page 164] 1.9190 + 1.9191 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9192 + 1.9193 + 1.9194 + /* decode first LSF */ 1.9195 + 1.9196 + pos = 0; 1.9197 + cb_pos = 0; 1.9198 + for (i = 0; i < LSF_NSPLIT; i++) { 1.9199 + for (j = 0; j < dim_lsfCbTbl[i]; j++) { 1.9200 + lsfdeq[pos + j] = lsfCbTbl[cb_pos + 1.9201 + (long)(index[i])*dim_lsfCbTbl[i] + j]; 1.9202 + } 1.9203 + pos += dim_lsfCbTbl[i]; 1.9204 + cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i]; 1.9205 + } 1.9206 + 1.9207 + if (lpc_n>1) { 1.9208 + 1.9209 + /* decode last LSF */ 1.9210 + 1.9211 + pos = 0; 1.9212 + cb_pos = 0; 1.9213 + for (i = 0; i < LSF_NSPLIT; i++) { 1.9214 + for (j = 0; j < dim_lsfCbTbl[i]; j++) { 1.9215 + lsfdeq[LPC_FILTERORDER + pos + j] = 1.9216 + lsfCbTbl[cb_pos + 1.9217 + (long)(index[LSF_NSPLIT + i])* 1.9218 + dim_lsfCbTbl[i] + j]; 1.9219 + } 1.9220 + pos += dim_lsfCbTbl[i]; 1.9221 + cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i]; 1.9222 + } 1.9223 + } 1.9224 + } 1.9225 + 1.9226 + /*----------------------------------------------------------------* 1.9227 + * obtain synthesis and weighting filters form lsf coefficients 1.9228 + *---------------------------------------------------------------*/ 1.9229 + 1.9230 + void DecoderInterpolateLSF( 1.9231 + float *syntdenum, /* (o) synthesis filter coefficients */ 1.9232 + float *weightdenum, /* (o) weighting denumerator 1.9233 + coefficients */ 1.9234 + float *lsfdeq, /* (i) dequantized lsf coefficients */ 1.9235 + int length, /* (i) length of lsf coefficient vector */ 1.9236 + iLBC_Dec_Inst_t *iLBCdec_inst 1.9237 + /* (i) the decoder state structure */ 1.9238 + ){ 1.9239 + int i, pos, lp_length; 1.9240 + float lp[LPC_FILTERORDER + 1], *lsfdeq2; 1.9241 + 1.9242 + 1.9243 + 1.9244 + 1.9245 +Andersen, et al. Experimental [Page 165] 1.9246 + 1.9247 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9248 + 1.9249 + 1.9250 + lsfdeq2 = lsfdeq + length; 1.9251 + lp_length = length + 1; 1.9252 + 1.9253 + if (iLBCdec_inst->mode==30) { 1.9254 + /* sub-frame 1: Interpolation between old and first */ 1.9255 + 1.9256 + LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, 1.9257 + lsf_weightTbl_30ms[0], length); 1.9258 + memcpy(syntdenum,lp,lp_length*sizeof(float)); 1.9259 + bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, 1.9260 + lp_length); 1.9261 + 1.9262 + /* sub-frames 2 to 6: interpolation between first 1.9263 + and last LSF */ 1.9264 + 1.9265 + pos = lp_length; 1.9266 + for (i = 1; i < 6; i++) { 1.9267 + LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2, 1.9268 + lsf_weightTbl_30ms[i], length); 1.9269 + memcpy(syntdenum + pos,lp,lp_length*sizeof(float)); 1.9270 + bwexpand(weightdenum + pos, lp, 1.9271 + LPC_CHIRP_WEIGHTDENUM, lp_length); 1.9272 + pos += lp_length; 1.9273 + } 1.9274 + } 1.9275 + else { 1.9276 + pos = 0; 1.9277 + for (i = 0; i < iLBCdec_inst->nsub; i++) { 1.9278 + LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, 1.9279 + lsfdeq, lsf_weightTbl_20ms[i], length); 1.9280 + memcpy(syntdenum+pos,lp,lp_length*sizeof(float)); 1.9281 + bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM, 1.9282 + lp_length); 1.9283 + pos += lp_length; 1.9284 + } 1.9285 + } 1.9286 + 1.9287 + /* update memory */ 1.9288 + 1.9289 + if (iLBCdec_inst->mode==30) 1.9290 + memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2, 1.9291 + length*sizeof(float)); 1.9292 + else 1.9293 + memcpy(iLBCdec_inst->lsfdeqold, lsfdeq, 1.9294 + length*sizeof(float)); 1.9295 + 1.9296 + } 1.9297 + 1.9298 + 1.9299 + 1.9300 + 1.9301 +Andersen, et al. Experimental [Page 166] 1.9302 + 1.9303 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9304 + 1.9305 + 1.9306 +A.37. LPCencode.h 1.9307 + 1.9308 + /****************************************************************** 1.9309 + 1.9310 + iLBC Speech Coder ANSI-C Source Code 1.9311 + 1.9312 + LPCencode.h 1.9313 + 1.9314 + Copyright (C) The Internet Society (2004). 1.9315 + All Rights Reserved. 1.9316 + 1.9317 + ******************************************************************/ 1.9318 + 1.9319 + #ifndef __iLBC_LPCENCOD_H 1.9320 + #define __iLBC_LPCENCOD_H 1.9321 + 1.9322 + void LPCencode( 1.9323 + float *syntdenum, /* (i/o) synthesis filter coefficients 1.9324 + before/after encoding */ 1.9325 + float *weightdenum, /* (i/o) weighting denumerator coefficients 1.9326 + before/after encoding */ 1.9327 + int *lsf_index, /* (o) lsf quantization index */ 1.9328 + float *data, /* (i) lsf coefficients to quantize */ 1.9329 + iLBC_Enc_Inst_t *iLBCenc_inst 1.9330 + /* (i/o) the encoder state structure */ 1.9331 + ); 1.9332 + 1.9333 + #endif 1.9334 + 1.9335 +A.38. LPCencode.c 1.9336 + 1.9337 + /****************************************************************** 1.9338 + 1.9339 + iLBC Speech Coder ANSI-C Source Code 1.9340 + 1.9341 + LPCencode.c 1.9342 + 1.9343 + Copyright (C) The Internet Society (2004). 1.9344 + All Rights Reserved. 1.9345 + 1.9346 + ******************************************************************/ 1.9347 + 1.9348 + #include <string.h> 1.9349 + 1.9350 + #include "iLBC_define.h" 1.9351 + #include "helpfun.h" 1.9352 + #include "lsf.h" 1.9353 + #include "constants.h" 1.9354 + 1.9355 + 1.9356 + 1.9357 +Andersen, et al. Experimental [Page 167] 1.9358 + 1.9359 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9360 + 1.9361 + 1.9362 + /*----------------------------------------------------------------* 1.9363 + * lpc analysis (subrutine to LPCencode) 1.9364 + *---------------------------------------------------------------*/ 1.9365 + 1.9366 + void SimpleAnalysis( 1.9367 + float *lsf, /* (o) lsf coefficients */ 1.9368 + float *data, /* (i) new data vector */ 1.9369 + iLBC_Enc_Inst_t *iLBCenc_inst 1.9370 + /* (i/o) the encoder state structure */ 1.9371 + ){ 1.9372 + int k, is; 1.9373 + float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1]; 1.9374 + float lp2[LPC_FILTERORDER + 1]; 1.9375 + float r[LPC_FILTERORDER + 1]; 1.9376 + 1.9377 + is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl; 1.9378 + memcpy(iLBCenc_inst->lpc_buffer+is,data, 1.9379 + iLBCenc_inst->blockl*sizeof(float)); 1.9380 + 1.9381 + /* No lookahead, last window is asymmetric */ 1.9382 + 1.9383 + for (k = 0; k < iLBCenc_inst->lpc_n; k++) { 1.9384 + 1.9385 + is = LPC_LOOKBACK; 1.9386 + 1.9387 + if (k < (iLBCenc_inst->lpc_n - 1)) { 1.9388 + window(temp, lpc_winTbl, 1.9389 + iLBCenc_inst->lpc_buffer, BLOCKL_MAX); 1.9390 + } else { 1.9391 + window(temp, lpc_asymwinTbl, 1.9392 + iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX); 1.9393 + } 1.9394 + 1.9395 + autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER); 1.9396 + window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1); 1.9397 + 1.9398 + levdurb(lp, temp, r, LPC_FILTERORDER); 1.9399 + bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1); 1.9400 + 1.9401 + a2lsf(lsf + k*LPC_FILTERORDER, lp2); 1.9402 + } 1.9403 + is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl; 1.9404 + memmove(iLBCenc_inst->lpc_buffer, 1.9405 + iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is, 1.9406 + is*sizeof(float)); 1.9407 + } 1.9408 + 1.9409 + /*----------------------------------------------------------------* 1.9410 + 1.9411 + 1.9412 + 1.9413 +Andersen, et al. Experimental [Page 168] 1.9414 + 1.9415 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9416 + 1.9417 + 1.9418 + * lsf interpolator and conversion from lsf to a coefficients 1.9419 + * (subrutine to SimpleInterpolateLSF) 1.9420 + *---------------------------------------------------------------*/ 1.9421 + 1.9422 + void LSFinterpolate2a_enc( 1.9423 + float *a, /* (o) lpc coefficients */ 1.9424 + float *lsf1,/* (i) first set of lsf coefficients */ 1.9425 + float *lsf2,/* (i) second set of lsf coefficients */ 1.9426 + float coef, /* (i) weighting coefficient to use between 1.9427 + lsf1 and lsf2 */ 1.9428 + long length /* (i) length of coefficient vectors */ 1.9429 + ){ 1.9430 + float lsftmp[LPC_FILTERORDER]; 1.9431 + 1.9432 + interpolate(lsftmp, lsf1, lsf2, coef, length); 1.9433 + lsf2a(a, lsftmp); 1.9434 + } 1.9435 + 1.9436 + /*----------------------------------------------------------------* 1.9437 + * lsf interpolator (subrutine to LPCencode) 1.9438 + *---------------------------------------------------------------*/ 1.9439 + 1.9440 + void SimpleInterpolateLSF( 1.9441 + float *syntdenum, /* (o) the synthesis filter denominator 1.9442 + resulting from the quantized 1.9443 + interpolated lsf */ 1.9444 + float *weightdenum, /* (o) the weighting filter denominator 1.9445 + resulting from the unquantized 1.9446 + interpolated lsf */ 1.9447 + float *lsf, /* (i) the unquantized lsf coefficients */ 1.9448 + float *lsfdeq, /* (i) the dequantized lsf coefficients */ 1.9449 + float *lsfold, /* (i) the unquantized lsf coefficients of 1.9450 + the previous signal frame */ 1.9451 + float *lsfdeqold, /* (i) the dequantized lsf coefficients of 1.9452 + the previous signal frame */ 1.9453 + int length, /* (i) should equate LPC_FILTERORDER */ 1.9454 + iLBC_Enc_Inst_t *iLBCenc_inst 1.9455 + /* (i/o) the encoder state structure */ 1.9456 + ){ 1.9457 + int i, pos, lp_length; 1.9458 + float lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2; 1.9459 + 1.9460 + lsf2 = lsf + length; 1.9461 + lsfdeq2 = lsfdeq + length; 1.9462 + lp_length = length + 1; 1.9463 + 1.9464 + if (iLBCenc_inst->mode==30) { 1.9465 + /* sub-frame 1: Interpolation between old and first 1.9466 + 1.9467 + 1.9468 + 1.9469 +Andersen, et al. Experimental [Page 169] 1.9470 + 1.9471 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9472 + 1.9473 + 1.9474 + set of lsf coefficients */ 1.9475 + 1.9476 + LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, 1.9477 + lsf_weightTbl_30ms[0], length); 1.9478 + memcpy(syntdenum,lp,lp_length*sizeof(float)); 1.9479 + LSFinterpolate2a_enc(lp, lsfold, lsf, 1.9480 + lsf_weightTbl_30ms[0], length); 1.9481 + bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); 1.9482 + 1.9483 + /* sub-frame 2 to 6: Interpolation between first 1.9484 + and second set of lsf coefficients */ 1.9485 + 1.9486 + pos = lp_length; 1.9487 + for (i = 1; i < iLBCenc_inst->nsub; i++) { 1.9488 + LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2, 1.9489 + lsf_weightTbl_30ms[i], length); 1.9490 + memcpy(syntdenum + pos,lp,lp_length*sizeof(float)); 1.9491 + 1.9492 + LSFinterpolate2a_enc(lp, lsf, lsf2, 1.9493 + lsf_weightTbl_30ms[i], length); 1.9494 + bwexpand(weightdenum + pos, lp, 1.9495 + LPC_CHIRP_WEIGHTDENUM, lp_length); 1.9496 + pos += lp_length; 1.9497 + } 1.9498 + } 1.9499 + else { 1.9500 + pos = 0; 1.9501 + for (i = 0; i < iLBCenc_inst->nsub; i++) { 1.9502 + LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, 1.9503 + lsf_weightTbl_20ms[i], length); 1.9504 + memcpy(syntdenum+pos,lp,lp_length*sizeof(float)); 1.9505 + LSFinterpolate2a_enc(lp, lsfold, lsf, 1.9506 + lsf_weightTbl_20ms[i], length); 1.9507 + bwexpand(weightdenum+pos, lp, 1.9508 + LPC_CHIRP_WEIGHTDENUM, lp_length); 1.9509 + pos += lp_length; 1.9510 + } 1.9511 + } 1.9512 + 1.9513 + /* update memory */ 1.9514 + 1.9515 + if (iLBCenc_inst->mode==30) { 1.9516 + memcpy(lsfold, lsf2, length*sizeof(float)); 1.9517 + memcpy(lsfdeqold, lsfdeq2, length*sizeof(float)); 1.9518 + } 1.9519 + else { 1.9520 + memcpy(lsfold, lsf, length*sizeof(float)); 1.9521 + memcpy(lsfdeqold, lsfdeq, length*sizeof(float)); 1.9522 + 1.9523 + 1.9524 + 1.9525 +Andersen, et al. Experimental [Page 170] 1.9526 + 1.9527 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9528 + 1.9529 + 1.9530 + } 1.9531 + } 1.9532 + 1.9533 + /*----------------------------------------------------------------* 1.9534 + * lsf quantizer (subrutine to LPCencode) 1.9535 + *---------------------------------------------------------------*/ 1.9536 + 1.9537 + void SimplelsfQ( 1.9538 + float *lsfdeq, /* (o) dequantized lsf coefficients 1.9539 + (dimension FILTERORDER) */ 1.9540 + int *index, /* (o) quantization index */ 1.9541 + float *lsf, /* (i) the lsf coefficient vector to be 1.9542 + quantized (dimension FILTERORDER ) */ 1.9543 + int lpc_n /* (i) number of lsf sets to quantize */ 1.9544 + ){ 1.9545 + /* Quantize first LSF with memoryless split VQ */ 1.9546 + SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT, 1.9547 + dim_lsfCbTbl, size_lsfCbTbl); 1.9548 + 1.9549 + if (lpc_n==2) { 1.9550 + /* Quantize second LSF with memoryless split VQ */ 1.9551 + SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT, 1.9552 + lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT, 1.9553 + dim_lsfCbTbl, size_lsfCbTbl); 1.9554 + } 1.9555 + } 1.9556 + 1.9557 + /*----------------------------------------------------------------* 1.9558 + * lpc encoder 1.9559 + *---------------------------------------------------------------*/ 1.9560 + 1.9561 + void LPCencode( 1.9562 + float *syntdenum, /* (i/o) synthesis filter coefficients 1.9563 + before/after encoding */ 1.9564 + float *weightdenum, /* (i/o) weighting denumerator 1.9565 + coefficients before/after 1.9566 + encoding */ 1.9567 + int *lsf_index, /* (o) lsf quantization index */ 1.9568 + float *data, /* (i) lsf coefficients to quantize */ 1.9569 + iLBC_Enc_Inst_t *iLBCenc_inst 1.9570 + /* (i/o) the encoder state structure */ 1.9571 + ){ 1.9572 + float lsf[LPC_FILTERORDER * LPC_N_MAX]; 1.9573 + float lsfdeq[LPC_FILTERORDER * LPC_N_MAX]; 1.9574 + int change=0; 1.9575 + 1.9576 + SimpleAnalysis(lsf, data, iLBCenc_inst); 1.9577 + SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n); 1.9578 + 1.9579 + 1.9580 + 1.9581 +Andersen, et al. Experimental [Page 171] 1.9582 + 1.9583 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9584 + 1.9585 + 1.9586 + change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n); 1.9587 + SimpleInterpolateLSF(syntdenum, weightdenum, 1.9588 + lsf, lsfdeq, iLBCenc_inst->lsfold, 1.9589 + iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst); 1.9590 + } 1.9591 + 1.9592 +A.39. lsf.h 1.9593 + 1.9594 + /****************************************************************** 1.9595 + 1.9596 + iLBC Speech Coder ANSI-C Source Code 1.9597 + 1.9598 + lsf.h 1.9599 + 1.9600 + Copyright (C) The Internet Society (2004). 1.9601 + All Rights Reserved. 1.9602 + 1.9603 + ******************************************************************/ 1.9604 + 1.9605 + #ifndef __iLBC_LSF_H 1.9606 + #define __iLBC_LSF_H 1.9607 + 1.9608 + void a2lsf( 1.9609 + float *freq,/* (o) lsf coefficients */ 1.9610 + float *a /* (i) lpc coefficients */ 1.9611 + ); 1.9612 + 1.9613 + void lsf2a( 1.9614 + float *a_coef, /* (o) lpc coefficients */ 1.9615 + float *freq /* (i) lsf coefficients */ 1.9616 + ); 1.9617 + 1.9618 + #endif 1.9619 + 1.9620 +A.40. lsf.c 1.9621 + 1.9622 + /****************************************************************** 1.9623 + 1.9624 + iLBC Speech Coder ANSI-C Source Code 1.9625 + 1.9626 + lsf.c 1.9627 + 1.9628 + Copyright (C) The Internet Society (2004). 1.9629 + All Rights Reserved. 1.9630 + 1.9631 + ******************************************************************/ 1.9632 + 1.9633 + #include <string.h> 1.9634 + 1.9635 + 1.9636 + 1.9637 +Andersen, et al. Experimental [Page 172] 1.9638 + 1.9639 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9640 + 1.9641 + 1.9642 + #include <math.h> 1.9643 + 1.9644 + #include "iLBC_define.h" 1.9645 + 1.9646 + /*----------------------------------------------------------------* 1.9647 + * conversion from lpc coefficients to lsf coefficients 1.9648 + *---------------------------------------------------------------*/ 1.9649 + 1.9650 + void a2lsf( 1.9651 + float *freq,/* (o) lsf coefficients */ 1.9652 + float *a /* (i) lpc coefficients */ 1.9653 + ){ 1.9654 + float steps[LSF_NUMBER_OF_STEPS] = 1.9655 + {(float)0.00635, (float)0.003175, (float)0.0015875, 1.9656 + (float)0.00079375}; 1.9657 + float step; 1.9658 + int step_idx; 1.9659 + int lsp_index; 1.9660 + float p[LPC_HALFORDER]; 1.9661 + float q[LPC_HALFORDER]; 1.9662 + float p_pre[LPC_HALFORDER]; 1.9663 + float q_pre[LPC_HALFORDER]; 1.9664 + float old_p, old_q, *old; 1.9665 + float *pq_coef; 1.9666 + float omega, old_omega; 1.9667 + int i; 1.9668 + float hlp, hlp1, hlp2, hlp3, hlp4, hlp5; 1.9669 + 1.9670 + for (i=0; i<LPC_HALFORDER; i++) { 1.9671 + p[i] = (float)-1.0 * (a[i + 1] + a[LPC_FILTERORDER - i]); 1.9672 + q[i] = a[LPC_FILTERORDER - i] - a[i + 1]; 1.9673 + } 1.9674 + 1.9675 + p_pre[0] = (float)-1.0 - p[0]; 1.9676 + p_pre[1] = - p_pre[0] - p[1]; 1.9677 + p_pre[2] = - p_pre[1] - p[2]; 1.9678 + p_pre[3] = - p_pre[2] - p[3]; 1.9679 + p_pre[4] = - p_pre[3] - p[4]; 1.9680 + p_pre[4] = p_pre[4] / 2; 1.9681 + 1.9682 + q_pre[0] = (float)1.0 - q[0]; 1.9683 + q_pre[1] = q_pre[0] - q[1]; 1.9684 + q_pre[2] = q_pre[1] - q[2]; 1.9685 + q_pre[3] = q_pre[2] - q[3]; 1.9686 + q_pre[4] = q_pre[3] - q[4]; 1.9687 + q_pre[4] = q_pre[4] / 2; 1.9688 + 1.9689 + omega = 0.0; 1.9690 + 1.9691 + 1.9692 + 1.9693 +Andersen, et al. Experimental [Page 173] 1.9694 + 1.9695 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9696 + 1.9697 + 1.9698 + old_omega = 0.0; 1.9699 + 1.9700 + old_p = FLOAT_MAX; 1.9701 + old_q = FLOAT_MAX; 1.9702 + 1.9703 + /* Here we loop through lsp_index to find all the 1.9704 + LPC_FILTERORDER roots for omega. */ 1.9705 + 1.9706 + for (lsp_index = 0; lsp_index<LPC_FILTERORDER; lsp_index++) { 1.9707 + 1.9708 + /* Depending on lsp_index being even or odd, we 1.9709 + alternatively solve the roots for the two LSP equations. */ 1.9710 + 1.9711 + 1.9712 + if ((lsp_index & 0x1) == 0) { 1.9713 + pq_coef = p_pre; 1.9714 + old = &old_p; 1.9715 + } else { 1.9716 + pq_coef = q_pre; 1.9717 + old = &old_q; 1.9718 + } 1.9719 + 1.9720 + /* Start with low resolution grid */ 1.9721 + 1.9722 + for (step_idx = 0, step = steps[step_idx]; 1.9723 + step_idx < LSF_NUMBER_OF_STEPS;){ 1.9724 + 1.9725 + /* cos(10piw) + pq(0)cos(8piw) + pq(1)cos(6piw) + 1.9726 + pq(2)cos(4piw) + pq(3)cod(2piw) + pq(4) */ 1.9727 + 1.9728 + hlp = (float)cos(omega * TWO_PI); 1.9729 + hlp1 = (float)2.0 * hlp + pq_coef[0]; 1.9730 + hlp2 = (float)2.0 * hlp * hlp1 - (float)1.0 + 1.9731 + pq_coef[1]; 1.9732 + hlp3 = (float)2.0 * hlp * hlp2 - hlp1 + pq_coef[2]; 1.9733 + hlp4 = (float)2.0 * hlp * hlp3 - hlp2 + pq_coef[3]; 1.9734 + hlp5 = hlp * hlp4 - hlp3 + pq_coef[4]; 1.9735 + 1.9736 + 1.9737 + if (((hlp5 * (*old)) <= 0.0) || (omega >= 0.5)){ 1.9738 + 1.9739 + if (step_idx == (LSF_NUMBER_OF_STEPS - 1)){ 1.9740 + 1.9741 + if (fabs(hlp5) >= fabs(*old)) { 1.9742 + freq[lsp_index] = omega - step; 1.9743 + } else { 1.9744 + freq[lsp_index] = omega; 1.9745 + } 1.9746 + 1.9747 + 1.9748 + 1.9749 +Andersen, et al. Experimental [Page 174] 1.9750 + 1.9751 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9752 + 1.9753 + 1.9754 + 1.9755 + 1.9756 + if ((*old) >= 0.0){ 1.9757 + *old = (float)-1.0 * FLOAT_MAX; 1.9758 + } else { 1.9759 + *old = FLOAT_MAX; 1.9760 + } 1.9761 + 1.9762 + omega = old_omega; 1.9763 + step_idx = 0; 1.9764 + 1.9765 + step_idx = LSF_NUMBER_OF_STEPS; 1.9766 + } else { 1.9767 + 1.9768 + if (step_idx == 0) { 1.9769 + old_omega = omega; 1.9770 + } 1.9771 + 1.9772 + step_idx++; 1.9773 + omega -= steps[step_idx]; 1.9774 + 1.9775 + /* Go back one grid step */ 1.9776 + 1.9777 + step = steps[step_idx]; 1.9778 + } 1.9779 + } else { 1.9780 + 1.9781 + /* increment omega until they are of different sign, 1.9782 + and we know there is at least one root between omega 1.9783 + and old_omega */ 1.9784 + *old = hlp5; 1.9785 + omega += step; 1.9786 + } 1.9787 + } 1.9788 + } 1.9789 + 1.9790 + for (i = 0; i<LPC_FILTERORDER; i++) { 1.9791 + freq[i] = freq[i] * TWO_PI; 1.9792 + } 1.9793 + } 1.9794 + 1.9795 + /*----------------------------------------------------------------* 1.9796 + * conversion from lsf coefficients to lpc coefficients 1.9797 + *---------------------------------------------------------------*/ 1.9798 + 1.9799 + void lsf2a( 1.9800 + float *a_coef, /* (o) lpc coefficients */ 1.9801 + float *freq /* (i) lsf coefficients */ 1.9802 + 1.9803 + 1.9804 + 1.9805 +Andersen, et al. Experimental [Page 175] 1.9806 + 1.9807 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9808 + 1.9809 + 1.9810 + ){ 1.9811 + int i, j; 1.9812 + float hlp; 1.9813 + float p[LPC_HALFORDER], q[LPC_HALFORDER]; 1.9814 + float a[LPC_HALFORDER + 1], a1[LPC_HALFORDER], 1.9815 + a2[LPC_HALFORDER]; 1.9816 + float b[LPC_HALFORDER + 1], b1[LPC_HALFORDER], 1.9817 + b2[LPC_HALFORDER]; 1.9818 + 1.9819 + for (i=0; i<LPC_FILTERORDER; i++) { 1.9820 + freq[i] = freq[i] * PI2; 1.9821 + } 1.9822 + 1.9823 + /* Check input for ill-conditioned cases. This part is not 1.9824 + found in the TIA standard. It involves the following 2 IF 1.9825 + blocks. If "freq" is judged ill-conditioned, then we first 1.9826 + modify freq[0] and freq[LPC_HALFORDER-1] (normally 1.9827 + LPC_HALFORDER = 10 for LPC applications), then we adjust 1.9828 + the other "freq" values slightly */ 1.9829 + 1.9830 + 1.9831 + if ((freq[0] <= 0.0) || (freq[LPC_FILTERORDER - 1] >= 0.5)){ 1.9832 + 1.9833 + 1.9834 + if (freq[0] <= 0.0) { 1.9835 + freq[0] = (float)0.022; 1.9836 + } 1.9837 + 1.9838 + 1.9839 + if (freq[LPC_FILTERORDER - 1] >= 0.5) { 1.9840 + freq[LPC_FILTERORDER - 1] = (float)0.499; 1.9841 + } 1.9842 + 1.9843 + hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) / 1.9844 + (float) (LPC_FILTERORDER - 1); 1.9845 + 1.9846 + for (i=1; i<LPC_FILTERORDER; i++) { 1.9847 + freq[i] = freq[i - 1] + hlp; 1.9848 + } 1.9849 + } 1.9850 + 1.9851 + memset(a1, 0, LPC_HALFORDER*sizeof(float)); 1.9852 + memset(a2, 0, LPC_HALFORDER*sizeof(float)); 1.9853 + memset(b1, 0, LPC_HALFORDER*sizeof(float)); 1.9854 + memset(b2, 0, LPC_HALFORDER*sizeof(float)); 1.9855 + memset(a, 0, (LPC_HALFORDER+1)*sizeof(float)); 1.9856 + memset(b, 0, (LPC_HALFORDER+1)*sizeof(float)); 1.9857 + 1.9858 + 1.9859 + 1.9860 + 1.9861 +Andersen, et al. Experimental [Page 176] 1.9862 + 1.9863 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9864 + 1.9865 + 1.9866 + /* p[i] and q[i] compute cos(2*pi*omega_{2j}) and 1.9867 + cos(2*pi*omega_{2j-1} in eqs. 4.2.2.2-1 and 4.2.2.2-2. 1.9868 + Note that for this code p[i] specifies the coefficients 1.9869 + used in .Q_A(z) while q[i] specifies the coefficients used 1.9870 + in .P_A(z) */ 1.9871 + 1.9872 + for (i=0; i<LPC_HALFORDER; i++) { 1.9873 + p[i] = (float)cos(TWO_PI * freq[2 * i]); 1.9874 + q[i] = (float)cos(TWO_PI * freq[2 * i + 1]); 1.9875 + } 1.9876 + 1.9877 + a[0] = 0.25; 1.9878 + b[0] = 0.25; 1.9879 + 1.9880 + for (i= 0; i<LPC_HALFORDER; i++) { 1.9881 + a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i]; 1.9882 + b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i]; 1.9883 + a2[i] = a1[i]; 1.9884 + a1[i] = a[i]; 1.9885 + b2[i] = b1[i]; 1.9886 + b1[i] = b[i]; 1.9887 + } 1.9888 + 1.9889 + for (j=0; j<LPC_FILTERORDER; j++) { 1.9890 + 1.9891 + if (j == 0) { 1.9892 + a[0] = 0.25; 1.9893 + b[0] = -0.25; 1.9894 + } else { 1.9895 + a[0] = b[0] = 0.0; 1.9896 + } 1.9897 + 1.9898 + for (i=0; i<LPC_HALFORDER; i++) { 1.9899 + a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i]; 1.9900 + b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i]; 1.9901 + a2[i] = a1[i]; 1.9902 + a1[i] = a[i]; 1.9903 + b2[i] = b1[i]; 1.9904 + b1[i] = b[i]; 1.9905 + } 1.9906 + 1.9907 + a_coef[j + 1] = 2 * (a[LPC_HALFORDER] + b[LPC_HALFORDER]); 1.9908 + } 1.9909 + 1.9910 + a_coef[0] = 1.0; 1.9911 + } 1.9912 + 1.9913 + 1.9914 + 1.9915 + 1.9916 + 1.9917 +Andersen, et al. Experimental [Page 177] 1.9918 + 1.9919 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9920 + 1.9921 + 1.9922 +A.41. packing.h 1.9923 + 1.9924 + /****************************************************************** 1.9925 + 1.9926 + iLBC Speech Coder ANSI-C Source Code 1.9927 + 1.9928 + packing.h 1.9929 + 1.9930 + Copyright (C) The Internet Society (2004). 1.9931 + All Rights Reserved. 1.9932 + 1.9933 + ******************************************************************/ 1.9934 + 1.9935 + #ifndef __PACKING_H 1.9936 + #define __PACKING_H 1.9937 + 1.9938 + void packsplit( 1.9939 + int *index, /* (i) the value to split */ 1.9940 + int *firstpart, /* (o) the value specified by most 1.9941 + significant bits */ 1.9942 + int *rest, /* (o) the value specified by least 1.9943 + significant bits */ 1.9944 + int bitno_firstpart, /* (i) number of bits in most 1.9945 + significant part */ 1.9946 + int bitno_total /* (i) number of bits in full range 1.9947 + of value */ 1.9948 + ); 1.9949 + 1.9950 + void packcombine( 1.9951 + int *index, /* (i/o) the msb value in the 1.9952 + combined value out */ 1.9953 + int rest, /* (i) the lsb value */ 1.9954 + int bitno_rest /* (i) the number of bits in the 1.9955 + lsb part */ 1.9956 + ); 1.9957 + 1.9958 + void dopack( 1.9959 + unsigned char **bitstream, /* (i/o) on entrance pointer to 1.9960 + place in bitstream to pack 1.9961 + new data, on exit pointer 1.9962 + to place in bitstream to 1.9963 + pack future data */ 1.9964 + int index, /* (i) the value to pack */ 1.9965 + int bitno, /* (i) the number of bits that the 1.9966 + value will fit within */ 1.9967 + int *pos /* (i/o) write position in the 1.9968 + current byte */ 1.9969 + ); 1.9970 + 1.9971 + 1.9972 + 1.9973 +Andersen, et al. Experimental [Page 178] 1.9974 + 1.9975 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.9976 + 1.9977 + 1.9978 + void unpack( 1.9979 + unsigned char **bitstream, /* (i/o) on entrance pointer to 1.9980 + place in bitstream to 1.9981 + unpack new data from, on 1.9982 + exit pointer to place in 1.9983 + bitstream to unpack future 1.9984 + data from */ 1.9985 + int *index, /* (o) resulting value */ 1.9986 + int bitno, /* (i) number of bits used to 1.9987 + represent the value */ 1.9988 + int *pos /* (i/o) read position in the 1.9989 + current byte */ 1.9990 + ); 1.9991 + 1.9992 + #endif 1.9993 + 1.9994 +A.42. packing.c 1.9995 + 1.9996 + /****************************************************************** 1.9997 + 1.9998 + iLBC Speech Coder ANSI-C Source Code 1.9999 + 1.10000 + packing.c 1.10001 + 1.10002 + Copyright (C) The Internet Society (2004). 1.10003 + All Rights Reserved. 1.10004 + 1.10005 + ******************************************************************/ 1.10006 + 1.10007 + #include <math.h> 1.10008 + #include <stdlib.h> 1.10009 + 1.10010 + #include "iLBC_define.h" 1.10011 + #include "constants.h" 1.10012 + #include "helpfun.h" 1.10013 + #include "string.h" 1.10014 + 1.10015 + /*----------------------------------------------------------------* 1.10016 + * splitting an integer into first most significant bits and 1.10017 + * remaining least significant bits 1.10018 + *---------------------------------------------------------------*/ 1.10019 + 1.10020 + void packsplit( 1.10021 + int *index, /* (i) the value to split */ 1.10022 + int *firstpart, /* (o) the value specified by most 1.10023 + significant bits */ 1.10024 + int *rest, /* (o) the value specified by least 1.10025 + significant bits */ 1.10026 + 1.10027 + 1.10028 + 1.10029 +Andersen, et al. Experimental [Page 179] 1.10030 + 1.10031 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10032 + 1.10033 + 1.10034 + int bitno_firstpart, /* (i) number of bits in most 1.10035 + significant part */ 1.10036 + int bitno_total /* (i) number of bits in full range 1.10037 + of value */ 1.10038 + ){ 1.10039 + int bitno_rest = bitno_total-bitno_firstpart; 1.10040 + 1.10041 + *firstpart = *index>>(bitno_rest); 1.10042 + *rest = *index-(*firstpart<<(bitno_rest)); 1.10043 + } 1.10044 + 1.10045 + /*----------------------------------------------------------------* 1.10046 + * combining a value corresponding to msb's with a value 1.10047 + * corresponding to lsb's 1.10048 + *---------------------------------------------------------------*/ 1.10049 + 1.10050 + void packcombine( 1.10051 + int *index, /* (i/o) the msb value in the 1.10052 + combined value out */ 1.10053 + int rest, /* (i) the lsb value */ 1.10054 + int bitno_rest /* (i) the number of bits in the 1.10055 + lsb part */ 1.10056 + ){ 1.10057 + *index = *index<<bitno_rest; 1.10058 + *index += rest; 1.10059 + } 1.10060 + 1.10061 + /*----------------------------------------------------------------* 1.10062 + * packing of bits into bitstream, i.e., vector of bytes 1.10063 + *---------------------------------------------------------------*/ 1.10064 + 1.10065 + void dopack( 1.10066 + unsigned char **bitstream, /* (i/o) on entrance pointer to 1.10067 + place in bitstream to pack 1.10068 + new data, on exit pointer 1.10069 + to place in bitstream to 1.10070 + pack future data */ 1.10071 + int index, /* (i) the value to pack */ 1.10072 + int bitno, /* (i) the number of bits that the 1.10073 + value will fit within */ 1.10074 + int *pos /* (i/o) write position in the 1.10075 + current byte */ 1.10076 + ){ 1.10077 + int posLeft; 1.10078 + 1.10079 + /* Clear the bits before starting in a new byte */ 1.10080 + 1.10081 + if ((*pos)==0) { 1.10082 + 1.10083 + 1.10084 + 1.10085 +Andersen, et al. Experimental [Page 180] 1.10086 + 1.10087 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10088 + 1.10089 + 1.10090 + **bitstream=0; 1.10091 + } 1.10092 + 1.10093 + while (bitno>0) { 1.10094 + 1.10095 + /* Jump to the next byte if end of this byte is reached*/ 1.10096 + 1.10097 + if (*pos==8) { 1.10098 + *pos=0; 1.10099 + (*bitstream)++; 1.10100 + **bitstream=0; 1.10101 + } 1.10102 + 1.10103 + posLeft=8-(*pos); 1.10104 + 1.10105 + /* Insert index into the bitstream */ 1.10106 + 1.10107 + if (bitno <= posLeft) { 1.10108 + **bitstream |= (unsigned char)(index<<(posLeft-bitno)); 1.10109 + *pos+=bitno; 1.10110 + bitno=0; 1.10111 + } else { 1.10112 + **bitstream |= (unsigned char)(index>>(bitno-posLeft)); 1.10113 + 1.10114 + *pos=8; 1.10115 + index-=((index>>(bitno-posLeft))<<(bitno-posLeft)); 1.10116 + 1.10117 + bitno-=posLeft; 1.10118 + } 1.10119 + } 1.10120 + } 1.10121 + 1.10122 + /*----------------------------------------------------------------* 1.10123 + * unpacking of bits from bitstream, i.e., vector of bytes 1.10124 + *---------------------------------------------------------------*/ 1.10125 + 1.10126 + void unpack( 1.10127 + unsigned char **bitstream, /* (i/o) on entrance pointer to 1.10128 + place in bitstream to 1.10129 + unpack new data from, on 1.10130 + exit pointer to place in 1.10131 + bitstream to unpack future 1.10132 + data from */ 1.10133 + int *index, /* (o) resulting value */ 1.10134 + int bitno, /* (i) number of bits used to 1.10135 + represent the value */ 1.10136 + int *pos /* (i/o) read position in the 1.10137 + current byte */ 1.10138 + 1.10139 + 1.10140 + 1.10141 +Andersen, et al. Experimental [Page 181] 1.10142 + 1.10143 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10144 + 1.10145 + 1.10146 + ){ 1.10147 + int BitsLeft; 1.10148 + 1.10149 + *index=0; 1.10150 + 1.10151 + while (bitno>0) { 1.10152 + 1.10153 + /* move forward in bitstream when the end of the 1.10154 + byte is reached */ 1.10155 + 1.10156 + if (*pos==8) { 1.10157 + *pos=0; 1.10158 + (*bitstream)++; 1.10159 + } 1.10160 + 1.10161 + BitsLeft=8-(*pos); 1.10162 + 1.10163 + /* Extract bits to index */ 1.10164 + 1.10165 + if (BitsLeft>=bitno) { 1.10166 + *index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno)); 1.10167 + 1.10168 + *pos+=bitno; 1.10169 + bitno=0; 1.10170 + } else { 1.10171 + 1.10172 + if ((8-bitno)>0) { 1.10173 + *index+=((((**bitstream)<<(*pos)) & 0xFF)>> 1.10174 + (8-bitno)); 1.10175 + *pos=8; 1.10176 + } else { 1.10177 + *index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<< 1.10178 + (bitno-8)); 1.10179 + *pos=8; 1.10180 + } 1.10181 + bitno-=BitsLeft; 1.10182 + } 1.10183 + } 1.10184 + } 1.10185 + 1.10186 +A.43. StateConstructW.h 1.10187 + 1.10188 + /****************************************************************** 1.10189 + 1.10190 + iLBC Speech Coder ANSI-C Source Code 1.10191 + 1.10192 + StateConstructW.h 1.10193 + 1.10194 + 1.10195 + 1.10196 + 1.10197 +Andersen, et al. Experimental [Page 182] 1.10198 + 1.10199 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10200 + 1.10201 + 1.10202 + Copyright (C) The Internet Society (2004). 1.10203 + All Rights Reserved. 1.10204 + 1.10205 + ******************************************************************/ 1.10206 + 1.10207 + #ifndef __iLBC_STATECONSTRUCTW_H 1.10208 + #define __iLBC_STATECONSTRUCTW_H 1.10209 + 1.10210 + void StateConstructW( 1.10211 + int idxForMax, /* (i) 6-bit index for the quantization of 1.10212 + max amplitude */ 1.10213 + int *idxVec, /* (i) vector of quantization indexes */ 1.10214 + float *syntDenum, /* (i) synthesis filter denumerator */ 1.10215 + float *out, /* (o) the decoded state vector */ 1.10216 + int len /* (i) length of a state vector */ 1.10217 + ); 1.10218 + 1.10219 + #endif 1.10220 + 1.10221 +A.44. StateConstructW.c 1.10222 + 1.10223 + /****************************************************************** 1.10224 + 1.10225 + iLBC Speech Coder ANSI-C Source Code 1.10226 + 1.10227 + StateConstructW.c 1.10228 + 1.10229 + Copyright (C) The Internet Society (2004). 1.10230 + All Rights Reserved. 1.10231 + 1.10232 + ******************************************************************/ 1.10233 + 1.10234 + #include <math.h> 1.10235 + #include <string.h> 1.10236 + 1.10237 + #include "iLBC_define.h" 1.10238 + #include "constants.h" 1.10239 + #include "filter.h" 1.10240 + 1.10241 + /*----------------------------------------------------------------* 1.10242 + * decoding of the start state 1.10243 + *---------------------------------------------------------------*/ 1.10244 + 1.10245 + void StateConstructW( 1.10246 + int idxForMax, /* (i) 6-bit index for the quantization of 1.10247 + max amplitude */ 1.10248 + int *idxVec, /* (i) vector of quantization indexes */ 1.10249 + float *syntDenum, /* (i) synthesis filter denumerator */ 1.10250 + 1.10251 + 1.10252 + 1.10253 +Andersen, et al. Experimental [Page 183] 1.10254 + 1.10255 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10256 + 1.10257 + 1.10258 + float *out, /* (o) the decoded state vector */ 1.10259 + int len /* (i) length of a state vector */ 1.10260 + ){ 1.10261 + float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp, 1.10262 + numerator[LPC_FILTERORDER+1]; 1.10263 + float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout; 1.10264 + int k,tmpi; 1.10265 + 1.10266 + /* decoding of the maximum value */ 1.10267 + 1.10268 + maxVal = state_frgqTbl[idxForMax]; 1.10269 + maxVal = (float)pow(10,maxVal)/(float)4.5; 1.10270 + 1.10271 + /* initialization of buffers and coefficients */ 1.10272 + 1.10273 + memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float)); 1.10274 + memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float)); 1.10275 + for (k=0; k<LPC_FILTERORDER; k++) { 1.10276 + numerator[k]=syntDenum[LPC_FILTERORDER-k]; 1.10277 + } 1.10278 + numerator[LPC_FILTERORDER]=syntDenum[0]; 1.10279 + tmp = &tmpbuf[LPC_FILTERORDER]; 1.10280 + fout = &foutbuf[LPC_FILTERORDER]; 1.10281 + 1.10282 + /* decoding of the sample values */ 1.10283 + 1.10284 + for (k=0; k<len; k++) { 1.10285 + tmpi = len-1-k; 1.10286 + /* maxVal = 1/scal */ 1.10287 + tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]]; 1.10288 + } 1.10289 + 1.10290 + /* circular convolution with all-pass filter */ 1.10291 + 1.10292 + memset(tmp+len, 0, len*sizeof(float)); 1.10293 + ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, 1.10294 + LPC_FILTERORDER, fout); 1.10295 + for (k=0;k<len;k++) { 1.10296 + out[k] = fout[len-1-k]+fout[2*len-1-k]; 1.10297 + } 1.10298 + } 1.10299 + 1.10300 + 1.10301 + 1.10302 + 1.10303 + 1.10304 + 1.10305 + 1.10306 + 1.10307 + 1.10308 + 1.10309 +Andersen, et al. Experimental [Page 184] 1.10310 + 1.10311 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10312 + 1.10313 + 1.10314 +A.45. StateSearchW.h 1.10315 + 1.10316 + /****************************************************************** 1.10317 + 1.10318 + iLBC Speech Coder ANSI-C Source Code 1.10319 + 1.10320 + StateSearchW.h 1.10321 + 1.10322 + Copyright (C) The Internet Society (2004). 1.10323 + All Rights Reserved. 1.10324 + 1.10325 + ******************************************************************/ 1.10326 + 1.10327 + #ifndef __iLBC_STATESEARCHW_H 1.10328 + #define __iLBC_STATESEARCHW_H 1.10329 + 1.10330 + void AbsQuantW( 1.10331 + iLBC_Enc_Inst_t *iLBCenc_inst, 1.10332 + /* (i) Encoder instance */ 1.10333 + float *in, /* (i) vector to encode */ 1.10334 + float *syntDenum, /* (i) denominator of synthesis filter */ 1.10335 + float *weightDenum, /* (i) denominator of weighting filter */ 1.10336 + int *out, /* (o) vector of quantizer indexes */ 1.10337 + int len, /* (i) length of vector to encode and 1.10338 + vector of quantizer indexes */ 1.10339 + int state_first /* (i) position of start state in the 1.10340 + 80 vec */ 1.10341 + ); 1.10342 + 1.10343 + void StateSearchW( 1.10344 + iLBC_Enc_Inst_t *iLBCenc_inst, 1.10345 + /* (i) Encoder instance */ 1.10346 + float *residual,/* (i) target residual vector */ 1.10347 + float *syntDenum, /* (i) lpc synthesis filter */ 1.10348 + float *weightDenum, /* (i) weighting filter denuminator */ 1.10349 + int *idxForMax, /* (o) quantizer index for maximum 1.10350 + amplitude */ 1.10351 + int *idxVec, /* (o) vector of quantization indexes */ 1.10352 + int len, /* (i) length of all vectors */ 1.10353 + int state_first /* (i) position of start state in the 1.10354 + 80 vec */ 1.10355 + ); 1.10356 + 1.10357 + 1.10358 + #endif 1.10359 + 1.10360 + 1.10361 + 1.10362 + 1.10363 + 1.10364 + 1.10365 +Andersen, et al. Experimental [Page 185] 1.10366 + 1.10367 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10368 + 1.10369 + 1.10370 +A.46. StateSearchW.c 1.10371 + 1.10372 + /****************************************************************** 1.10373 + 1.10374 + iLBC Speech Coder ANSI-C Source Code 1.10375 + 1.10376 + StateSearchW.c 1.10377 + 1.10378 + Copyright (C) The Internet Society (2004). 1.10379 + All Rights Reserved. 1.10380 + 1.10381 + ******************************************************************/ 1.10382 + 1.10383 + #include <math.h> 1.10384 + #include <string.h> 1.10385 + 1.10386 + #include "iLBC_define.h" 1.10387 + #include "constants.h" 1.10388 + #include "filter.h" 1.10389 + #include "helpfun.h" 1.10390 + 1.10391 + /*----------------------------------------------------------------* 1.10392 + * predictive noise shaping encoding of scaled start state 1.10393 + * (subrutine for StateSearchW) 1.10394 + *---------------------------------------------------------------*/ 1.10395 + 1.10396 + void AbsQuantW( 1.10397 + iLBC_Enc_Inst_t *iLBCenc_inst, 1.10398 + /* (i) Encoder instance */ 1.10399 + float *in, /* (i) vector to encode */ 1.10400 + float *syntDenum, /* (i) denominator of synthesis filter */ 1.10401 + float *weightDenum, /* (i) denominator of weighting filter */ 1.10402 + int *out, /* (o) vector of quantizer indexes */ 1.10403 + int len, /* (i) length of vector to encode and 1.10404 + vector of quantizer indexes */ 1.10405 + int state_first /* (i) position of start state in the 1.10406 + 80 vec */ 1.10407 + ){ 1.10408 + float *syntOut; 1.10409 + float syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS]; 1.10410 + float toQ, xq; 1.10411 + int n; 1.10412 + int index; 1.10413 + 1.10414 + /* initialization of buffer for filtering */ 1.10415 + 1.10416 + memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float)); 1.10417 + 1.10418 + 1.10419 + 1.10420 + 1.10421 +Andersen, et al. Experimental [Page 186] 1.10422 + 1.10423 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10424 + 1.10425 + 1.10426 + /* initialization of pointer for filtering */ 1.10427 + 1.10428 + syntOut = &syntOutBuf[LPC_FILTERORDER]; 1.10429 + 1.10430 + /* synthesis and weighting filters on input */ 1.10431 + 1.10432 + if (state_first) { 1.10433 + AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER); 1.10434 + } else { 1.10435 + AllPoleFilter (in, weightDenum, 1.10436 + iLBCenc_inst->state_short_len-SUBL, 1.10437 + LPC_FILTERORDER); 1.10438 + } 1.10439 + 1.10440 + /* encoding loop */ 1.10441 + 1.10442 + for (n=0; n<len; n++) { 1.10443 + 1.10444 + /* time update of filter coefficients */ 1.10445 + 1.10446 + if ((state_first)&&(n==SUBL)){ 1.10447 + syntDenum += (LPC_FILTERORDER+1); 1.10448 + weightDenum += (LPC_FILTERORDER+1); 1.10449 + 1.10450 + /* synthesis and weighting filters on input */ 1.10451 + AllPoleFilter (&in[n], weightDenum, len-n, 1.10452 + LPC_FILTERORDER); 1.10453 + 1.10454 + } else if ((state_first==0)&& 1.10455 + (n==(iLBCenc_inst->state_short_len-SUBL))) { 1.10456 + syntDenum += (LPC_FILTERORDER+1); 1.10457 + weightDenum += (LPC_FILTERORDER+1); 1.10458 + 1.10459 + /* synthesis and weighting filters on input */ 1.10460 + AllPoleFilter (&in[n], weightDenum, len-n, 1.10461 + LPC_FILTERORDER); 1.10462 + 1.10463 + } 1.10464 + 1.10465 + /* prediction of synthesized and weighted input */ 1.10466 + 1.10467 + syntOut[n] = 0.0; 1.10468 + AllPoleFilter (&syntOut[n], weightDenum, 1, 1.10469 + LPC_FILTERORDER); 1.10470 + 1.10471 + /* quantization */ 1.10472 + 1.10473 + toQ = in[n]-syntOut[n]; 1.10474 + 1.10475 + 1.10476 + 1.10477 +Andersen, et al. Experimental [Page 187] 1.10478 + 1.10479 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10480 + 1.10481 + 1.10482 + sort_sq(&xq, &index, toQ, state_sq3Tbl, 8); 1.10483 + out[n]=index; 1.10484 + syntOut[n] = state_sq3Tbl[out[n]]; 1.10485 + 1.10486 + /* update of the prediction filter */ 1.10487 + 1.10488 + AllPoleFilter(&syntOut[n], weightDenum, 1, 1.10489 + LPC_FILTERORDER); 1.10490 + } 1.10491 + } 1.10492 + 1.10493 + /*----------------------------------------------------------------* 1.10494 + * encoding of start state 1.10495 + *---------------------------------------------------------------*/ 1.10496 + 1.10497 + void StateSearchW( 1.10498 + iLBC_Enc_Inst_t *iLBCenc_inst, 1.10499 + /* (i) Encoder instance */ 1.10500 + float *residual,/* (i) target residual vector */ 1.10501 + float *syntDenum, /* (i) lpc synthesis filter */ 1.10502 + float *weightDenum, /* (i) weighting filter denuminator */ 1.10503 + int *idxForMax, /* (o) quantizer index for maximum 1.10504 + amplitude */ 1.10505 + int *idxVec, /* (o) vector of quantization indexes */ 1.10506 + int len, /* (i) length of all vectors */ 1.10507 + int state_first /* (i) position of start state in the 1.10508 + 80 vec */ 1.10509 + ){ 1.10510 + float dtmp, maxVal; 1.10511 + float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS]; 1.10512 + float *tmp, numerator[1+LPC_FILTERORDER]; 1.10513 + float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout; 1.10514 + int k; 1.10515 + float qmax, scal; 1.10516 + 1.10517 + /* initialization of buffers and filter coefficients */ 1.10518 + 1.10519 + memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float)); 1.10520 + memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float)); 1.10521 + for (k=0; k<LPC_FILTERORDER; k++) { 1.10522 + numerator[k]=syntDenum[LPC_FILTERORDER-k]; 1.10523 + } 1.10524 + numerator[LPC_FILTERORDER]=syntDenum[0]; 1.10525 + tmp = &tmpbuf[LPC_FILTERORDER]; 1.10526 + fout = &foutbuf[LPC_FILTERORDER]; 1.10527 + 1.10528 + /* circular convolution with the all-pass filter */ 1.10529 + 1.10530 + 1.10531 + 1.10532 + 1.10533 +Andersen, et al. Experimental [Page 188] 1.10534 + 1.10535 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10536 + 1.10537 + 1.10538 + memcpy(tmp, residual, len*sizeof(float)); 1.10539 + memset(tmp+len, 0, len*sizeof(float)); 1.10540 + ZeroPoleFilter(tmp, numerator, syntDenum, 2*len, 1.10541 + LPC_FILTERORDER, fout); 1.10542 + for (k=0; k<len; k++) { 1.10543 + fout[k] += fout[k+len]; 1.10544 + } 1.10545 + 1.10546 + /* identification of the maximum amplitude value */ 1.10547 + 1.10548 + maxVal = fout[0]; 1.10549 + for (k=1; k<len; k++) { 1.10550 + 1.10551 + if (fout[k]*fout[k] > maxVal*maxVal){ 1.10552 + maxVal = fout[k]; 1.10553 + } 1.10554 + } 1.10555 + maxVal=(float)fabs(maxVal); 1.10556 + 1.10557 + /* encoding of the maximum amplitude value */ 1.10558 + 1.10559 + if (maxVal < 10.0) { 1.10560 + maxVal = 10.0; 1.10561 + } 1.10562 + maxVal = (float)log10(maxVal); 1.10563 + sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64); 1.10564 + 1.10565 + /* decoding of the maximum amplitude representation value, 1.10566 + and corresponding scaling of start state */ 1.10567 + 1.10568 + maxVal=state_frgqTbl[*idxForMax]; 1.10569 + qmax = (float)pow(10,maxVal); 1.10570 + scal = (float)(4.5)/qmax; 1.10571 + for (k=0; k<len; k++){ 1.10572 + fout[k] *= scal; 1.10573 + } 1.10574 + 1.10575 + /* predictive noise shaping encoding of scaled start state */ 1.10576 + 1.10577 + AbsQuantW(iLBCenc_inst, fout,syntDenum, 1.10578 + weightDenum,idxVec, len, state_first); 1.10579 + } 1.10580 + 1.10581 + 1.10582 + 1.10583 + 1.10584 + 1.10585 + 1.10586 + 1.10587 + 1.10588 + 1.10589 +Andersen, et al. Experimental [Page 189] 1.10590 + 1.10591 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10592 + 1.10593 + 1.10594 +A.47. syntFilter.h 1.10595 + 1.10596 + /****************************************************************** 1.10597 + 1.10598 + iLBC Speech Coder ANSI-C Source Code 1.10599 + 1.10600 + syntFilter.h 1.10601 + 1.10602 + Copyright (C) The Internet Society (2004). 1.10603 + All Rights Reserved. 1.10604 + 1.10605 + ******************************************************************/ 1.10606 + 1.10607 + #ifndef __iLBC_SYNTFILTER_H 1.10608 + #define __iLBC_SYNTFILTER_H 1.10609 + 1.10610 + void syntFilter( 1.10611 + float *Out, /* (i/o) Signal to be filtered */ 1.10612 + float *a, /* (i) LP parameters */ 1.10613 + int len, /* (i) Length of signal */ 1.10614 + float *mem /* (i/o) Filter state */ 1.10615 + ); 1.10616 + 1.10617 + #endif 1.10618 + 1.10619 +A.48. syntFilter.c 1.10620 + 1.10621 + /****************************************************************** 1.10622 + 1.10623 + iLBC Speech Coder ANSI-C Source Code 1.10624 + 1.10625 + syntFilter.c 1.10626 + 1.10627 + Copyright (C) The Internet Society (2004). 1.10628 + All Rights Reserved. 1.10629 + 1.10630 + ******************************************************************/ 1.10631 + 1.10632 + #include "iLBC_define.h" 1.10633 + 1.10634 + /*----------------------------------------------------------------* 1.10635 + * LP synthesis filter. 1.10636 + *---------------------------------------------------------------*/ 1.10637 + 1.10638 + void syntFilter( 1.10639 + float *Out, /* (i/o) Signal to be filtered */ 1.10640 + float *a, /* (i) LP parameters */ 1.10641 + int len, /* (i) Length of signal */ 1.10642 + 1.10643 + 1.10644 + 1.10645 +Andersen, et al. Experimental [Page 190] 1.10646 + 1.10647 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10648 + 1.10649 + 1.10650 + float *mem /* (i/o) Filter state */ 1.10651 + ){ 1.10652 + int i, j; 1.10653 + float *po, *pi, *pa, *pm; 1.10654 + 1.10655 + po=Out; 1.10656 + 1.10657 + /* Filter first part using memory from past */ 1.10658 + 1.10659 + for (i=0; i<LPC_FILTERORDER; i++) { 1.10660 + pi=&Out[i-1]; 1.10661 + pa=&a[1]; 1.10662 + pm=&mem[LPC_FILTERORDER-1]; 1.10663 + for (j=1; j<=i; j++) { 1.10664 + *po-=(*pa++)*(*pi--); 1.10665 + } 1.10666 + for (j=i+1; j<LPC_FILTERORDER+1; j++) { 1.10667 + *po-=(*pa++)*(*pm--); 1.10668 + } 1.10669 + po++; 1.10670 + } 1.10671 + 1.10672 + /* Filter last part where the state is entirely in 1.10673 + the output vector */ 1.10674 + 1.10675 + for (i=LPC_FILTERORDER; i<len; i++) { 1.10676 + pi=&Out[i-1]; 1.10677 + pa=&a[1]; 1.10678 + for (j=1; j<LPC_FILTERORDER+1; j++) { 1.10679 + *po-=(*pa++)*(*pi--); 1.10680 + } 1.10681 + po++; 1.10682 + } 1.10683 + 1.10684 + /* Update state vector */ 1.10685 + 1.10686 + memcpy(mem, &Out[len-LPC_FILTERORDER], 1.10687 + LPC_FILTERORDER*sizeof(float)); 1.10688 + } 1.10689 + 1.10690 + 1.10691 + 1.10692 + 1.10693 + 1.10694 + 1.10695 + 1.10696 + 1.10697 + 1.10698 + 1.10699 + 1.10700 + 1.10701 +Andersen, et al. Experimental [Page 191] 1.10702 + 1.10703 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10704 + 1.10705 + 1.10706 +Authors' Addresses 1.10707 + 1.10708 + Soren Vang Andersen 1.10709 + Department of Communication Technology 1.10710 + Aalborg University 1.10711 + Fredrik Bajers Vej 7A 1.10712 + 9200 Aalborg 1.10713 + Denmark 1.10714 + 1.10715 + Phone: ++45 9 6358627 1.10716 + EMail: sva@kom.auc.dk 1.10717 + 1.10718 + 1.10719 + Alan Duric 1.10720 + Telio AS 1.10721 + Stoperigt. 2 1.10722 + Oslo, N-0250 1.10723 + Norway 1.10724 + 1.10725 + Phone: +47 21673555 1.10726 + EMail: alan.duric@telio.no 1.10727 + 1.10728 + 1.10729 + Henrik Astrom 1.10730 + Global IP Sound AB 1.10731 + Olandsgatan 42 1.10732 + Stockholm, S-11663 1.10733 + Sweden 1.10734 + 1.10735 + Phone: +46 8 54553040 1.10736 + EMail: henrik.astrom@globalipsound.com 1.10737 + 1.10738 + 1.10739 + Roar Hagen 1.10740 + Global IP Sound AB 1.10741 + Olandsgatan 42 1.10742 + Stockholm, S-11663 1.10743 + Sweden 1.10744 + 1.10745 + Phone: +46 8 54553040 1.10746 + EMail: roar.hagen@globalipsound.com 1.10747 + 1.10748 + 1.10749 + 1.10750 + 1.10751 + 1.10752 + 1.10753 + 1.10754 + 1.10755 + 1.10756 + 1.10757 +Andersen, et al. Experimental [Page 192] 1.10758 + 1.10759 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10760 + 1.10761 + 1.10762 + W. Bastiaan Kleijn 1.10763 + Global IP Sound AB 1.10764 + Olandsgatan 42 1.10765 + Stockholm, S-11663 1.10766 + Sweden 1.10767 + 1.10768 + Phone: +46 8 54553040 1.10769 + EMail: bastiaan.kleijn@globalipsound.com 1.10770 + 1.10771 + 1.10772 + Jan Linden 1.10773 + Global IP Sound Inc. 1.10774 + 900 Kearny Street, suite 500 1.10775 + San Francisco, CA-94133 1.10776 + USA 1.10777 + 1.10778 + Phone: +1 415 397 2555 1.10779 + EMail: jan.linden@globalipsound.com 1.10780 + 1.10781 + 1.10782 + 1.10783 + 1.10784 + 1.10785 + 1.10786 + 1.10787 + 1.10788 + 1.10789 + 1.10790 + 1.10791 + 1.10792 + 1.10793 + 1.10794 + 1.10795 + 1.10796 + 1.10797 + 1.10798 + 1.10799 + 1.10800 + 1.10801 + 1.10802 + 1.10803 + 1.10804 + 1.10805 + 1.10806 + 1.10807 + 1.10808 + 1.10809 + 1.10810 + 1.10811 + 1.10812 + 1.10813 +Andersen, et al. Experimental [Page 193] 1.10814 + 1.10815 +RFC 3951 Internet Low Bit Rate Codec December 2004 1.10816 + 1.10817 + 1.10818 +Full Copyright Statement 1.10819 + 1.10820 + Copyright (C) The Internet Society (2004). 1.10821 + 1.10822 + This document is subject to the rights, licenses and restrictions 1.10823 + contained in BCP 78, and except as set forth therein, the authors 1.10824 + retain all their rights. 1.10825 + 1.10826 + This document and the information contained herein are provided on an 1.10827 + "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS 1.10828 + OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET 1.10829 + ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, 1.10830 + INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE 1.10831 + INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED 1.10832 + WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 1.10833 + 1.10834 +Intellectual Property 1.10835 + 1.10836 + The IETF takes no position regarding the validity or scope of any 1.10837 + Intellectual Property Rights or other rights that might be claimed to 1.10838 + pertain to the implementation or use of the technology described in 1.10839 + this document or the extent to which any license under such rights 1.10840 + might or might not be available; nor does it represent that it has 1.10841 + made any independent effort to identify any such rights. Information 1.10842 + on the IETF's procedures with respect to rights in IETF Documents can 1.10843 + be found in BCP 78 and BCP 79. 1.10844 + 1.10845 + Copies of IPR disclosures made to the IETF Secretariat and any 1.10846 + assurances of licenses to be made available, or the result of an 1.10847 + attempt made to obtain a general license or permission for the use of 1.10848 + such proprietary rights by implementers or users of this 1.10849 + specification can be obtained from the IETF on-line IPR repository at 1.10850 + http://www.ietf.org/ipr. 1.10851 + 1.10852 + The IETF invites any interested party to bring to its attention any 1.10853 + copyrights, patents or patent applications, or other proprietary 1.10854 + rights that may cover technology that may be required to implement 1.10855 + this standard. Please address the information to the IETF at ietf- 1.10856 + ipr@ietf.org. 1.10857 + 1.10858 + 1.10859 +Acknowledgement 1.10860 + 1.10861 + Funding for the RFC Editor function is currently provided by the 1.10862 + Internet Society. 1.10863 + 1.10864 + 1.10865 + 1.10866 + 1.10867 + 1.10868 + 1.10869 +Andersen, et al. Experimental [Page 194] 1.10870 +