idnits 2.17.1 draft-ietf-avt-ilbc-codec-01.txt: -(3): Line appears to be too long, but this could be caused by non-ascii characters in UTF-8 encoding -(5): Line appears to be too long, but this could be caused by non-ascii characters in UTF-8 encoding -(654): Line appears to be too long, but this could be caused by non-ascii characters in UTF-8 encoding -(1926): Line appears to be too long, but this could be caused by non-ascii characters in UTF-8 encoding Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Looks like you're using RFC 2026 boilerplate. This must be updated to follow RFC 3978/3979, as updated by RFC 4748. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- == There are 14 instances of lines with non-ascii characters in the document. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** The document seems to lack separate sections for Informative/Normative References. All references will be assumed normative when checking for downward references. == There are 7 instances of lines with non-RFC6890-compliant IPv4 addresses in the document. If these are example addresses, they should be changed. Miscellaneous warnings: ---------------------------------------------------------------------------- == Line 1099 has weird spacing: '... pi pp ...' == Line 1123 has weird spacing: '... pi pp ...' == Line 3109 has weird spacing: '...samples in th...' == Line 3843 has weird spacing: '...ern int dim_...' == Line 3844 has weird spacing: '...ern int size...' == (12 more instances...) -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- Couldn't find a document date in the document -- date freshness check skipped. -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Experimental ---------------------------------------------------------------------------- == Missing Reference: '0' is mentioned on line 9144, but not defined == Missing Reference: '64' is mentioned on line 3976, but not defined == Missing Reference: '8' is mentioned on line 3970, but not defined == Missing Reference: '4' is mentioned on line 8443, but not defined == Missing Reference: '5' is mentioned on line 4003, but not defined == Missing Reference: '6' is mentioned on line 5774, but not defined -- Looks like a reference, but probably isn't: '-st' on line 5501 -- Looks like a reference, but probably isn't: '-orderCoef' on line 6088 -- Looks like a reference, but probably isn't: '-1' on line 6088 -- Looks like a reference, but probably isn't: '-k' on line 6064 -- Looks like a reference, but probably isn't: 'SUBL-l-1' on line 6273 -- Looks like a reference, but probably isn't: 'SUBL' on line 7444 -- No information found for draft-avt-rtp-ilbc - is the name correct? Summary: 3 errors (**), 0 flaws (~~), 14 warnings (==), 10 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Internet Draft S. V. Andersen 3 Document: draft-ietf-avt-ilbc-codec-01.txt H. �str�m 4 Category: Experimental A. Duric 5 March 3rd, 2003 F. Galschi�dt 6 Expires: September 3rd, 2003 R. Hagen 7 W. B. Kleijn 8 J. Linden 9 M. N. Murthi 10 J. Skoglund 11 J. Spittka 13 Global IP Sound 15 Internet Low Bit Rate Codec 17 Status of this Memo 19 This document is an Internet-Draft and is in full conformance 20 with all provisions of Section 10 of RFC2026. 22 Internet-Drafts are working documents of the Internet Engineering 23 Task Force (IETF), its areas, and its working groups. Note that 24 other groups may also distribute working documents as Internet- 25 Drafts. 27 Internet-Drafts are draft documents valid for a maximum of six 28 months and may be updated, replaced, or obsoleted by other documents 29 at any time. It is inappropriate to use Internet-Drafts as 30 reference material or to cite them other than as "work in progress." 32 The list of current Internet-Drafts can be accessed at 33 http://www.ietf.org/ietf/1id-abstracts.txt 34 The list of Internet-Draft Shadow Directories can be accessed at 35 http://www.ietf.org/shadow.html. 37 Abstract 39 This document specifies a speech codec suitable for robust voice 40 communication over IP. The codec is developed by Global IP Sound 41 (GIPS). It is designed for narrow band speech and results in a payload 42 bit rate of 13.33 kbit/s for 30 ms frames and 15.20 kbit/s for 20 ms 43 frames. The codec enables graceful speech quality degradation in the 44 case of lost frames, which occurs in connection with lost or delayed IP 45 packets. 47 Andersen et. al. 1 48 Table of Contents 50 Status of this Memo................................................1 51 Abstract...........................................................1 52 Table of Contents..................................................2 53 1. INTRODUCTION....................................................5 54 2. OUTLINE OF THE CODEC............................................5 55 2.1 Encoder........................................................6 56 2.2 Decoder........................................................7 57 3. ENCODER PRINCIPLES..............................................8 58 3.2 LPC Analysis and Quantization..................................9 59 3.2.1 Computation of Autocorrelation Coefficients..................9 60 3.2.2 Computation of LPC Coefficients.............................11 61 3.2.3 Computation of LSF Coefficients from LPC Coefficients.......11 62 3.2.4 Quantization of LSF Coefficients............................11 63 3.2.5 Stability Check of LSF Coefficients.........................12 64 3.2.6 Interpolation of LSF Coefficients...........................13 65 3.2.7 LPC Analysis and Quantization for 20 ms frames..............13 66 3.3 Calculation of the Residual...................................14 67 3.4 Perceptual Weighting Filter...................................14 68 3.5 Start State Encoder...........................................15 69 3.5.1 Start State Estimation......................................15 70 3.5.2 All-Pass Filtering and Scale Quantization...................16 71 3.5.3 Scalar Quantization.........................................17 72 3.6 Encoding the remaining samples................................17 73 3.6.1 Codebook Memory.............................................18 74 3.6.2 Perceptual Weighting of Codebook Memory and Target..........20 75 3.6.3 Codebook Creation...........................................20 76 3.6.3.1 Creation of a Base Codebook...............................21 77 3.6.3.2 Codebook Expansion........................................21 78 3.6.3.3 Codebook Augmentation.....................................22 79 3.6.4 Codebook Search.............................................23 80 3.6.4.1 The Codebook Search at Each Stage.........................24 81 3.6.3.2 The Gain Quantization at Each Stage.......................24 82 3.6.3.3 Preparation of Target for Next Stage......................25 83 3.7 Gain Correction Encoding......................................25 84 3.8 Bitstream Definition..........................................26 85 4. DECODER PRINCIPLES.............................................29 86 4.1 LPC Filter Reconstruction.....................................29 87 4.2 Start State Reconstruction....................................30 88 4.3 Excitation Decoding Loop......................................30 89 4.4 Multistage Adaptive Codebook Decoding.........................31 90 4.4.1 Construction of the Decoded Excitation Signal...............31 91 4.5 Packet Loss Concealment.......................................32 92 4.5.1 Block Received Correctly and Previous Block also Received...32 93 4.5.2 Block Not Received..........................................32 95 Andersen et. al. Experimental - Expires September 3rd, 2003 2 96 4.5.3 Block Received Correctly When Previous Block Not Received...33 97 4.6 Enhancement...................................................33 98 4.6.1 Estimating the pitch........................................35 99 4.6.2 Determination of the Pitch-Synchronous Sequences............35 100 4.6.3 Calculation of the smoothed excitation......................37 101 4.6.4 Enhancer criterion..........................................37 102 4.6.5 Enhancing the excitation....................................37 103 4.7 Synthesis Filtering...........................................38 104 4.8 Post Filtering................................................38 105 5. SECURITY CONSIDERATIONS........................................38 106 6. REFERENCES.....................................................39 107 7. ACKNOWLEDGEMENTS...............................................39 108 8. AUTHOR'S ADDRESSES.............................................40 109 APPENDIX A REFERENCE IMPLEMENTATION...............................42 110 A.1 iLBC_test.c...................................................43 111 A.2 iLBC_encode.h.................................................48 112 A.3 iLBC_encode.c.................................................49 113 A.4 iLBC_decode.h.................................................58 114 A.5 iLBC_decode.c.................................................59 115 A.6 iLBC_define.h.................................................70 116 A.7 constants.h...................................................74 117 A.8 constants.c...................................................75 118 A.9 anaFilter.h...................................................88 119 A.10 anaFilter.c..................................................89 120 A.11 createCB.h...................................................90 121 A.12 createCB.c...................................................91 122 A.13 doCPLC.h.....................................................95 123 A.14 doCPLC.c.....................................................96 124 A.15 enhancer.h..................................................100 125 A.16 enhancer.c..................................................101 126 A.17 filter.h....................................................113 127 A.18 filter.c....................................................114 128 A.19 FrameClassify.h.............................................117 129 A.20 FrameClassify.c.............................................118 130 A.21 gainquant.h.................................................120 131 A.22 gainquant.c.................................................120 132 A.23 getCBvec.h..................................................122 133 A.24 getCBvec.c..................................................123 134 A.25 helpfun.h...................................................126 135 A.26 helpfun.c...................................................128 136 A.27 hpInput.h...................................................134 137 A.28 hpInput.c...................................................134 138 A.29 hpOutput.h..................................................135 139 A.30 hpOutput.c..................................................136 140 A.31 iCBConstruct.h..............................................137 141 A.32 iCBConstruct.c..............................................137 143 Andersen et. al. Experimental - Expires September 3rd, 2003 3 144 A.33 iCBSearch.h.................................................139 145 A.34 iCBSearch.c.................................................140 146 A.35 LPCdecode.h.................................................149 147 A.36 LPCdecode.c.................................................150 148 A.37 LPCencode.h.................................................152 149 A.38 LPCencode.c.................................................153 150 A.39 lsf.h.......................................................157 151 A.40 lsf.c.......................................................158 152 A.41 packing.h...................................................163 153 A.42 packing.c...................................................164 154 A.43 StateConstructW.h...........................................167 155 A.44 StateConstructW.c...........................................168 156 A.45 StateSearchW.h..............................................169 157 A.46 StateSearchW.c..............................................170 158 A.47 syntFilter.h................................................173 159 A.48 syntFilter.c................................................174 161 Andersen et. al. Experimental - Expires September 3rd, 2003 4 162 1. INTRODUCTION 164 This document contains the description of an algorithm for the 165 coding of speech signals sampled at 8 kHz. The algorithm, called 166 iLBC, uses a block-independent linear-predictive coding (LPC) 167 algorithm and has support for two basic frame lengths � 20 ms at 168 15.2 kbit/s and 30 ms at 13.33 kbit/s. When the codec operates at 169 block lengths of 20 ms, it produces 303 bits per block which SHOULD 170 be packetized in 38 bytes. Similarly, for block lengths of 30 ms it 171 produces 399 bits per block which SHOULD be packetized in 50 bytes. 172 The two modes for the different frame sizes operate in a very 173 similar way. When they differ it is explicitly said in the text, 174 usually with the notation x/y, where x refers to the 20 ms mode and 175 y refers to the 30 ms mode. 177 The described algorithm results in a speech coding system with a 178 controlled response to packet losses similar to what is known from 179 pulse code modulation (PCM) with packet loss concealment (PLC), such 180 as the ITU-T G.711 standard [3] which operates at a fixed bit rate 181 of 64 kbit/s. At the same time, the described algorithm enables 182 fixed bit rate coding with a quality-versus-bit rate tradeoff close 183 to state-of-the-art. A suitable RTP payload format for this codec is 184 specified in [1]. 186 Some of the applications for which this coder is suitable are: real 187 time communications such as telephony and videoconferencing, 188 streaming audio, archival, and messaging. 190 This document is organized as follows. In Section 2 a brief outline 191 of the codec is given. The specific encoder and decoder algorithms 192 are explained in Sections 3 and 4, respectively. A c-code reference 193 implementation is provided in Appendix A. 195 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 196 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in 197 this document are to be interpreted as described in RFC 2119 [2]. 199 2. OUTLINE OF THE CODEC 201 The codec consists of an encoder and a decoder described in Section 202 2.1 and 2.2, respectively. 204 The essence of the codec is LPC and block based coding of the LPC 205 residual signal. For each 160/240 (20ms/30ms) sample block, the 206 following major steps are done: A set of LPC filters are computed 207 and the speech signal is filtered through them to produce the 208 residual signal. The codec uses scalar quantization of the dominant 209 part, in terms of energy, of the residual signal for the block. The 210 dominant state is of length 57/58 (20ms/30ms) samples and forms a 211 start state for dynamic codebooks constructed from the already coded 212 parts of the residual signal. These dynamic codebooks are used to 213 code the remaining parts of the residual signal. By this method, 215 Andersen et. al. Experimental - Expires September 3rd, 2003 5 216 coding independence between blocks is achieved, resulting in 217 elimination of propagation of perceptual degradations due to packet 218 loss. The method facilitates high-quality packet loss concealment 219 (PLC). 221 2.1 Encoder 223 The input to the encoder should be 16 bit uniform PCM sampled at 8 224 kHz. It should be partitioned into blocks of BLOCKL=160/240 samples 225 for the 20/30 ms frame size. Each block is divided into NSUB=4/6 226 consecutive sub-blocks of SUBL=40 samples each. For 30 ms frame 227 size, the encoder performs two LPC_FILTERORDER=10 linear-predictive 228 coding (LPC) analyses. The first analysis applies a smooth window 229 centered over the 2nd sub-block and extending to the middle of the 230 5'th sub-block. The second LPC analysis applies a smooth window 231 centered over the 5'th sub-block and extending to the end of the 232 6'th sub-block. For 20 ms frame size one LPC_FILTERORDER=10 linear- 233 predictive coding (LPC) analysis is performed with a smooth window 234 centered over the 3'rd and 4'th subframe. 236 For each of the LPC analysis, a set of line-spectral 237 frequencies(LSF)'s are obtained, quantized and interpolated to 238 obtain LSF coefficients for each sub-block. Subsequently, the LPC 239 residual is computed using the quantized and interpolated LPC 240 analysis filters. 242 The two consecutive sub-blocks of residual exhibiting the maximal 243 weigthed energy are identified. Within these 2 sub-blocks, the start 244 state (segment) is selected from two choices: the first 57/58 245 samples or the last 57/58 samples of the 2 consecutive sub-blocks. 246 The selected segment is the one of higher energy. The start state is 247 encoded with scalar quantization. 249 A dynamic codebook encoding procedure is used to encode 1) the 23/22 250 (20ms/30ms) remaining samples in the 2 sub-blocks containing the 251 start state; 2) encoding of the sub-blocks after the start state in 252 time; 3) encoding of the sub-blocks before the start state in time. 253 Thus, the encoding target can be either the 23/22 samples remaining 254 of the 2 sub-blocks containing the start state or a 40 sample sub- 255 block. This target can consist of samples that are indexed forwards 256 in time or backwards in time depending on the location of the start 257 state. 259 The coding is based on an adaptive codebook that is built from a 260 codebook memory which contains decoded LPC excitation samples from 261 the already encoded part of the block. These samples are indexed in 262 the same time direction as the target vector and ending at the 263 sample instant prior to the first sample instant represented in the 264 target vector. The codebook is used in CB_NSTAGES=3 stages in a 265 successive refinement approach and the resulting 3 code vector gains 266 are encoded with 5, 4, and 3 bit scalar quantization, respectively. 268 Andersen et. al. Experimental - Expires September 3rd, 2003 6 269 The codebook search method employs noise shaping derived from the 270 LPC filters and the main descision criteria is minimizing the 271 squared error between the target vector and the code vectors. Each 272 code vector in this codebook comes from one of CB_EXPAND=2 codebook 273 sections. The first section is filled with delayed, already encoded 274 residual vectors. The code vectors of the second codebook section 275 are constructed by predefined linear combinations of vectors in the 276 first section of the codebook. 278 Since codebook encoding with squared-error matching is known to 279 produce a coded signal of less power than the scalar quantized 280 start state signal, a gain re-scaling method is implemented by a 281 refined search for a better set of codebook gains in terms of power 282 matching after encoding. This is done by searching for a higher 283 value of the gain factor for the first stage codebook since the 284 subsequent stage codebook gains are scaled by the first stage gain. 286 2.2 Decoder 288 For packet communications, typically a jitter buffer placed at the 289 receiving end decides whether the packet containing an encoded 290 signal block has been received or lost. This logic is not part of 291 the codec described here. For each received encoded signal block the 292 decoder performs a decoding. For each lost signal block the decoder 293 performs a PLC operation. 295 The decoding for each block starts by decoding and interpolating the 296 LPC coefficients. Subsequently the start state is decoded. 298 For codebook encoded segments, each segment is decoded by 299 constructing the 3 code vectors given by the received codebook 300 indices in the same way as the code vectors were constructed in the 301 encoder. The 3 gain factors are also decoded and the resulting 302 decoded signal is given by the sum of the 3 codebook vectors scaled 303 with respective gain. 305 An enhancement algorithm is applied on the reconstructed excitation 306 signal. This enhancement augments the periodicity of voiced speech 307 regions. The enhancement is optimized under the constraint that the 308 modification signal (defined as the difference between the enhanced 309 excitation and the excitation signal prior to enhancement) has a 310 short-time energy that does not exceed a preset fraction of the 311 short-time energy of the excitation signal prior to enhancement. 313 A packet loss concealment (PLC) operation is easily embedded in the 314 decoder. The PLC operation can, e.g., be based on repetition of LPC 315 filters and obtaining the LPC residual signal using a long term 316 prediction estimate from previous residual blocks. 318 Andersen et. al. Experimental - Expires September 3rd, 2003 7 319 3. ENCODER PRINCIPLES 321 The following block diagram is an overview of all the components of 322 the iLBC encoding procedure. The description of the blocks contains 323 references to the section where that particular procedure is 324 described further. 326 +-----------+ +---------+ +---------+ 327 speech -> | 1. Pre P | -> | 2. LPC | -> | 3. Ana | -> 328 +-----------+ +---------+ +---------+ 330 +---------------+ +--------------+ 331 -> | 4. Start Sel | ->| 5. Scalar Qu | -> 332 +---------------+ +--------------+ 334 +--------------+ +---------------+ 335 -> |6. CB Search | -> | 7. Packetize | -> payload 336 | +--------------+ | +---------------+ 337 ----<---------<------ 338 sub frame 0..2/4 (20ms/30ms) 340 Figure 3.1. Flow chart of the iLBC encoder 342 1. Pre process speech with a HP filter if needed (section 3.1) 343 2. Compute LPC parameters, quantize and interpolate (section 3.2) 344 3. Use analysis filters on speech to compute residual (section 3.3) 345 4. Select position of 57/58 sample start state (section 3.5) 346 5. Quantize the 57/58 sample start state with scalar quantization 347 (section 3.5) 348 6. Search the codebook for each subframe. Start with 23/22 sample 349 block, then encode sub blocks forward in time and then encode sub 350 blocks backward in time. For each block the steps in figure 3.3 are 351 performed (section 3.6) 352 7. Packetize the bits into the payload specified in table 3.2. 354 The input to the encoder should be 16 bit uniform PCM sampled at 8 355 kHz. Also it should be partitioned into blocks of BLOCKL=160/240 356 samples. Each block input to the encoder is divided into NSUB=4/6 357 consecutive sub-blocks of SUBL=40 samples each. 359 Andersen et. al. Experimental - Expires September 3rd, 2003 8 360 0 39 79 119 159 361 +---------------------------------------+ 362 | 1 | 2 | 3 | 4 | 363 +---------------------------------------+ 364 20 ms frame 366 0 39 79 119 159 199 239 367 +-----------------------------------------------------------+ 368 | 1 | 2 | 3 | 4 | 5 | 6 | 369 +-----------------------------------------------------------+ 370 30 ms frame 372 Figure 3.2. One input block to the encoder for 20 ms (with 4 373 subframes) and 30 ms (with 6 subframes). 375 3.1 Pre-processing 377 In some applications the recorded speech signal contains DC level 378 and/or 50/60 Hz noise. If these components have not been removed 379 prior to the encoder call, they should be removed by a high-pass 380 filter. A reference implementation of this, using a filter with cut 381 off frequency 90 Hz, can be found in Appendix A.28. 383 3.2 LPC Analysis and Quantization 385 The input to the LPC analysis module is a possibly high-pass 386 filtered speech buffer, speech_hp, that contains 220/300 387 (LPC_LOOKBACK + BLOCKL = 60 + 160/240 = 220/300) speech samples, 388 where samples 0 through 59 are from the previous block and samples 389 60 through 219/299 are from the current block. No look-ahead into 390 the next block is used. For the very first block processed, the look 391 back samples are assumed to be zeros. 393 For each input block, the LPC analysis calculates one/two set(s) of 394 LPC_FILTERORDER=10 LPC filter coefficients using the autocorrelation 395 method and the Levinson-Durbin recursion. These coefficients are 396 converted to the Line Spectrum Frequency representation. In the 20 397 ms case the set, lsf, represents the spectral characteristics as 398 measured at the center of the third subblock. For 30 ms frames the 399 first set, lsf1, represents the spectral properties of the input 400 signal at the center of the second subblock while the other set, 401 lsf2, represents the spectral characteristics as measured at the 402 center of the fifth subblock. The details of the computation for 30 403 ms frames are described in 3.2.1 through 3.2.6. Section 3.2.7 404 explains how the LPC Analysis and Quantization differs for 20 ms 405 frames. 407 3.2.1 Computation of Autocorrelation Coefficients 409 The first step in the LPC analysis procedure is to calculate 410 autocorrelation coefficients using windowed speech samples. This 411 windowing is the only difference in the LPC analysis procedure for 412 the two sets of coefficients. For the first set, a 240 sample long 414 Andersen et. al. Experimental - Expires September 3rd, 2003 9 415 standard symmetric Hanning window is applied to samples 0 through 416 239 of the input data. The first window, lpc_winTbl, is defined as: 418 lpc_winTbl[i]= 0.5 * (1.0 - cos((2*PI*(i+1))/(BLOCKL+1))); 419 i=0,...,119 420 lpc_winTbl[i] = winTbl[BLOCKL - i - 1]; i=120,...,239 422 The windowed speech speech_hp_win1 is then obtained by multiplying 423 the 240 first samples of the input speech buffer with the window 424 coefficients: 426 speech_hp_win1[i] = speech_hp[i] * lpc_winTbl[i]; 427 i=0,...,BLOCKL-1 429 From these 240 windowed speech samples, 11 (LPC_FILTERORDER + 1) 430 autocorrelation coefficients, acf1, are calculated: 432 acf1[lag] += speech_hp_win1[n] * speech_hp_win1[n + lag]; 433 lag=0,...,LPC_FILTERORDER; n=0,...,BLOCKL-lag 435 In order to make the analysis more robust against numerical 436 precision problems, a spectral smoothing procedure is applied by 437 windowing the autocorrelation coefficients with a window before the 438 LPC coefficients are computed. Also, a white noise floor is added to 439 the autocorrelation function by multiplying coefficient zero by 440 1.0001 (40dB below the energy of the windowed speech signal). These 441 two steps are implemented by multiplying the autocorrelation 442 coefficients with the following window: 444 lpc_lagwinTbl[0] = 1.0001; 445 lpc_lagwinTbl[i] = exp(-0.5 * ((2 * PI * 60.0 * i) /FS)^2); 446 i=1,...,LPC_FILTERORDER 447 where FS=8000 is the sampling frequency 449 Then, the windowed acf function acf1_win is obtained by: 451 acf1_win[i] = acf1[i] * lpc_lagwinTbl[i]; 452 i=0,...,LPC_FILTERORDER 454 The second set of autocorrelation coefficients, acf2_win are 455 obtained in a similar manner. The window, lpc_asymwinTbl, is applied 456 to samples 60 through 299, i.e., the entire current block. The 457 window consists of two segments; The first (samples 0 to 219) being 458 half a Hanning window with length 440 and the second being a quarter 459 of a cycle of a cosine wave. By using this asymmetric window, an LPC 460 analysis centered in the fifth subblock is obtained without the need 461 for any look-ahead, which would have added delay. The asymmetric 462 window is defined as: 464 lpc_asymwinTbl[i] = (sin(PI * (i + 1) / 441))^2; i=0,...,219 465 lpc_asymwinTbl[i] = cos((i - 220) * PI / 10); i=220,...,239 467 Andersen et. al. Experimental - Expires September 3rd, 2003 10 468 and the windowed speech is computed by: 470 speech_hp_win2[i] = speech_hp[i + LPC_LOOKBACK] * 471 lpc_asymwinTbl[i]; i=0,....BLOCKL-1 473 The windowed autocorrelation coefficients are then obtained in 474 exactly the same way as for the first analysis instance. 476 The generation of the windows lpc_winTbl, lpc_asymwinTbl, and 477 lpc_lagwinTbl are typically done in advance and the arrays are 478 stored in ROM rather than repeating the calculation for every block. 480 3.2.2 Computation of LPC Coefficients 482 From the 11 smoothed autocorrelation coefficients, acf1_win and 483 acf2_win, the 2 x 11 LPC coefficients, lp1 and lp2, are calculated 484 in the same way for both analysis locations using the well known 485 Levinson-Durbin recursion. The first LPC coefficient is always 1.0, 486 resulting in 10 unique coefficients. 488 After determining the LPC coefficients, a bandwidth expansion 489 procedure is applied in order to smooth the spectral peaks in the 490 short-term spectrum. The bandwidth addition is obtained by the 491 following modification of the LPC coefficients: 493 lp1_bw[i] = lp1[i] * chirp^i; i=0,...,LPC_FILTERORDER 494 lp2_bw[i] = lp2[i] * chirp^i; i=0,...,LPC_FILTERORDER 496 where "chirp" is a real number between 0 and 1. It is RECOMMENDED to 497 use a value of 0.9. 499 3.2.3 Computation of LSF Coefficients from LPC Coefficients 501 Thusfar, two sets of LPC coefficients that represent the short-term 502 spectral characteristics of the speech signal for two different time 503 locations within the current block have been determined. These 504 coefficients should be quantized and interpolated. Before 505 doing so, it is advantageous to convert the LPC parameters into 506 another type of representation called Line Spectral Frequencies 507 (LSF). The LSF parameters are used because they are better suited 508 for quantization and interpolation than the regular LPC 509 coefficients. Many computationally efficient methods for calculating 510 the LSFs from the LPC coefficients have been proposed in the 511 literature. The detailed implementation of one applicable method can 512 be found in Appendix A.40. The two arrays of LSF coefficients 513 obtained, lsf1 and lsf2, are of dimension 10 (LPC_FILTERORDER). 515 3.2.4 Quantization of LSF Coefficients 517 Since the LPC filters defined by the two sets of LSFs are needed 518 also in the decoder, the LSF parameters needs to be quantized and 519 transmitted as side information. The total number of bits required 520 to represent the quantization of the two LSF representations for one 522 Andersen et. al. Experimental - Expires September 3rd, 2003 11 523 block of speech is 40 with 20 bits used for each of lsf1 and lsf2. 524 For computational and storage reasons, the LSF vectors are quantized 525 using 3-split vector quantization (VQ). That is, the LSF vectors are 526 split into three subvectors which are each quantized with a regular 527 VQ. The quantized versions of lsf1 and lsf2, qlsf1 and qlsf2, are 528 obtained by using the same memoryless split VQ. The length of each 529 of these two LSF vectors are 10 and they are split into 3 sub 530 vectors containing 3, 3 and 4 values respectively. 532 For each of the sub-vectors, a separate codebook of quantized values 533 has been designed using a standard VQ training method for a large 534 database containing speech from a large number of speakers recorded 535 under various conditions. The size of each of the three codebooks 536 associated with the split definitions above is: 538 int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128}; 540 The actual values of the vector quantization codebook that must be 541 used can be found in the reference code of appendix A. Both sets of 542 LSF coefficients, lsf1 and lsf2, are quantized with a standard 543 memoryless split vector quantization (VQ) structure using the 544 squared error criterion in the LSF domain. The split VQ quantization 545 consists of the following steps: 547 1) Quantize the first 3 LSF coefficients (1 - 3) with a VQ codebook 548 of size 64. 549 2) Quantize the LSF coefficients 4, 5, and 6 with VQ a codebook of 550 size 128. 551 3) Quantize the last 4 LSF coefficients (7 - 10) with a VQ codebook 552 of size 128. 554 This procedure, repeated for lsf1 and lsf2, gives 6 quantization 555 indices and the quantized sets of LSF coefficients qlsf1 and qlsf2. 556 Each set of three indices is encoded with 6 + 7 + 7 = 20 bits. The 557 total number of bits used for LSF quantization in a block is thus 40 558 bits. 560 3.2.5 Stability Check of LSF Coefficients 562 The LSF representation of the LPC filter has the nice property that 563 the coefficients are ordered by increasing value, i.e., lsf(n-1) < 564 lsf(n), 0 < n < 10, if the corresponding synthesis filter is stable. 565 Since we are employing a split VQ scheme it is possible that at the 566 split boundaries the LSF coefficients are not ordered correctly and 567 hence the corresponding LP filter is unstable. To ensure that the 568 filter used is stable, a stability check is performed for the 569 quantized LSF vectors. If it turns out that the coefficients are not 570 ordered appropriately (with a safety margin of 50 Hz to ensure that 571 formant peaks are not too narrow) they will be moved apart. The 572 detailed method for this can be found in Appendix A.40. The same 573 procedure is performed in the decoder. This ensures that exactly the 574 same LSF representations are used in both encoder and decoder. 576 Andersen et. al. Experimental - Expires September 3rd, 2003 12 577 3.2.6 Interpolation of LSF Coefficients 579 From the two sets of LSF coefficients that are computed for each 580 block of speech, different LSFs are obtained for each subblock by 581 means of interpolation. This procedure is performed for the original 582 LSFs, lsf1 and lsf2 as well as the quantized versions qlsf1 and 583 qlsf2 since both versions are used in the encoder. Here follows a 584 brief summary of the interpolation scheme while the details are 585 found in the c-code of Appendix A. In the first sub-block, the 586 average of the second LSF vector from the previous block and the 587 first LSF vector in the current block is used. For sub-blocks two 588 through five the LSFs used are obtained by linear interpolation from 589 lsf1 (and qlsf1) to lsf2 (and qlsf2) with lsf1 used in subblock two 590 and lsf2 in subblock five. In the last subblock, lsf2 is used. For 591 the very first block it is assumed that the last LSF vector of the 592 previous block is equal to a predefined vector, lsfmeanTbl, that was 593 obtained by calculating the mean LSF vector of the LSF design 594 database. 596 lsfmeanTbl[LPC_FILTERORDER] = {0.281738, 0.445801, 0.663330, 597 0.962524, 1.251831, 1.533081, 1.850586, 2.137817, 598 2.481445, 2.777344} 600 The interpolation method is standard linear interpolation in the LSF 601 domain. The interpolated LSF values are converted to LPC 602 coefficients for each sub-block. The unquantized and quantized LPC 603 coefficients forms two sets of filters respectively. The unquantized 604 analysis filter for subblock k: 606 ___ 607 \ 608 Ak(z)= 1 + > aki*z^(-i) 609 /__ 610 i=1...LPC_FILTERORDER 612 Quantized analysis filter for subblock k: 613 ___ 614 \ 615 �k(z)= 1 + > �ki*z^(-i) 616 /__ 617 i=1...LPC_FILTERORDER 619 A reference implementation of the lsf encoding is given in Appendix 620 A.38. A reference implementation of the corresponding decoding can 621 be found in Appendix A.36. 623 3.2.7 LPC Analysis and Quantization for 20 ms frames 625 As stated before, the codec only calculates one set of LPC for the 626 20 ms frame size as opposed to two sets for 30 ms frames. A single 627 set of autocorrelation coefficients is calculated on the 628 LPC_LOOKBACK + BLOCKL = 60 + 160 = 240 samples. These samples are 629 windowed with the asymmetric window lpc_asymwinTbl, centered over 631 Andersen et. al. Experimental - Expires September 3rd, 2003 13 632 the third subframe, to form speech_hp_win. Autocorrelation 633 coefficients, acf, are calculated on the 240 samples in 634 speech_hp_win and then windowed exactly as in 3.2.1 (resulting in 635 acf_win). 637 This single set of windowed autocorrelation coefficients is used to 638 calculate LPC Coefficients, LSF Coefficients and quantized LSF 639 coefficients in exactly the same manner as in 3.2.3 to 3.2.4. As for 640 the 30 ms frame size, the 10 lsf coefficients are divided into three 641 sub vectors of size 3, 3, 4 and quantized using the same scheme and 642 codebook as in 3.2.4 to finally get 3 quantization indices. The 643 quantized LSF coefficients are stabilized with the algorithm 644 described in 3.2.5. 646 From the set of LSF coefficients that was computed for this block 647 together with the LSF coefficients from the previous block, 648 different LSFs are obtained for each subblock by means of 649 interpolation. The interpolation is done linearly in the LSF domain 650 over the 4 sub blocks, so that the n'th subframe uses the weight (4- 651 n)/4 for the LSF from old frame and the weight n/4 of the LSF from 652 the current frame. For the very first block the mean LSF, 653 lsfmeanTbl, is used as the LSF from the previous block. Similar to 654 3.2.6, both unquantized, A(z), and quantized, �(z), analysis filters 655 are calculated for each of the four sub block. 657 3.3 Calculation of the Residual 659 The block of speech samples is filtered by the quantized and 660 interpolated LPC analysis filters to yield the residual signal. In 661 particular, the corresponding LPC analysis filter for each 40 sample 662 subblock is used to filter the speech samples for the same subblock. 663 The filter memory at the end of each subblock is carried over to the 664 LPC filter of the next subblock. The signal at the output of each 665 LP analysis filter constitutes the residual signal for the 666 corresponding subblock. 668 A reference implementation of the LPC analysis filters are found in 669 Appendix A.10. 671 3.4 Perceptual Weighting Filter 673 In principle any good design of perceptual weighting filter can be 674 applied in the encoder without compromising this codec definition. 675 It is however RECOMMENDED to use the perceptual weighting filter 676 specified below: 678 Weighting filter for subblock k: 680 Wk(z)=1/Ak(z/LPC_CHIRP_WEIGHTDENUM), where 681 LPC_CHIRP_WEIGHTDENUM = 0.4222 683 Andersen et. al. Experimental - Expires September 3rd, 2003 14 684 This is a simple design with low complexity that is applied in the 685 LPC residual domain. Here Ak(z) is the filter obtained from 686 unquantized but interpolated LSF coefficients. 688 3.5 Start State Encoder 690 The start state containing STATE_SHORT_LEN=57 for 20 ms frames and 691 STATE_SHORT_LEN=58 maximum energy residual samples is quantized 692 using a common 6-bit scale quantizer for the block and a 3-bit 693 scalar quantizer operating on the scaled samples in the weighted 694 speech domain. Now we describe the state encoding in greater detail. 696 3.5.1 Start State Estimation 698 The two sub-blocks containing the start state are determined by 699 finding the two consecutive sub-blocks in the block having the 700 highest power. Advantageously, down-weighting is used in the 701 beginning and end of the sub-frames. I.e., the following measure is 702 computed (NSUB=4/6 for 20/30 ms frame size): 704 nsub=1,...,NSUB-1 705 ssqn[nsub] = 0.0; 706 for (i=(nsub-1)*SUBL; i<(nsub-1)*SUBL+5; i++) 707 ssqn[nsub] += sampEn_win[i-(nsub-1)*SUBL]* 708 residual[i]*residual[i]; 709 for (i=(nsub-1)*SUBL+5; i �ki*z^(i-(LPC_FILTERORDER-1)) 774 /__ 775 i=0...(LPC_FILTERORDER-1) 777 and �k(z) is taken from the block where the start state begins 779 in -> Pk(z) -> filtered 781 out(k) = filtered(k) + filtered(k+STATE_SHORT_LEN), 782 k=0..(STATE_SHORT_LEN-1) 784 The all pass filtered block is searched for its largest magnitude 785 sample. The 10-logarithm of this magnitude is quantized with a 6-bit 786 quantizer, state_frgqTbl, by finding the nearest representation. 787 This results in an index, idxForMax, corresponding to a quantized 788 value, qmax. The all-pass filtered residual samples in the block are 789 then multiplied with a scaling factor scal=4.5/(10^qmax) to yield 790 normalized samples. 792 Andersen et. al. Experimental - Expires September 3rd, 2003 16 793 state_frgqTbl[64] = {1.000085, 1.071695, 1.140395, 1.206868, 794 1.277188, 1.351503, 1.429380, 1.500727, 1.569049, 795 1.639599, 1.707071, 1.781531, 1.840799, 1.901550, 796 1.956695, 2.006750, 2.055474, 2.102787, 2.142819, 797 2.183592, 2.217962, 2.257177, 2.295739, 2.332967, 798 2.369248, 2.402792, 2.435080, 2.468598, 2.503394, 799 2.539284, 2.572944, 2.605036, 2.636331, 2.668939, 800 2.698780, 2.729101, 2.759786, 2.789834, 2.818679, 801 2.848074, 2.877470, 2.906899, 2.936655, 2.967804, 802 3.000115, 3.033367, 3.066355, 3.104231, 3.141499, 803 3.183012, 3.222952, 3.265433, 3.308441, 3.350823, 804 3.395275, 3.442793, 3.490801, 3.542514, 3.604064, 805 3.666050, 3.740994, 3.830749, 3.938770, 4.101764} 807 3.5.3 Scalar Quantization 809 The normalized samples are quantized in the perceptually weighted 810 speech domain by a sample-by-sample scalar quantization. Each sample 811 in[n] in the block is filtered by a weighting filter to form a 812 weighted speech sample weightin[n]. The target sample target[n] is 813 formed by subtracting a zero-input response sample of the weighting 814 filter from weightin[n]. The coded state sample out[n] is obtained 815 by quantizing target[n] with a 3-bit quantizer with quantization 816 table state_sq3Tbl. 818 state_sq3Tbl[8] = {-3.719849, -2.177490, -1.130005, -0.309692, 819 0.444214, 1.329712, 2.436279, 3.983887} 821 The state of the weighting filter is then updated by filtering coded 822 sample out[n]. The quantized samples are transformed back to the 823 residual domain by 1) scaling with 1/scal 2) time-reversing the 824 scaled samples 3) filtering the time-reversed samples by the same 825 all-pass filter as in section 3.5.2, using circular convolution 4) 826 time-reversing the filtered samples. (More detailed in section 4.2) 828 A reference implementation of the start state encoding can be found 829 in Appendix A.46. 831 3.6 Encoding the remaining samples 833 A dynamic codebook is used to encode 1) the 23/22 remaining samples 834 in the 2 sub-blocks containing the start state; 2) encoding of the 835 sub-blocks after the start state in time; 3) encoding of the sub- 836 blocks before the start state in time. Thus, the encoding target can 837 be either the 23/22 samples remaining of the 2 sub-blocks containing 838 the start state or a 40 sample sub-block. This target can consist of 839 samples that are indexed forwards in time or backwards in time 840 depending on the location of the start state. The length of the 841 target is denoted by lTarget. 843 The coding is based on an adaptive codebook that is built from a 844 codebook memory which contains decoded LPC excitation samples from 845 the already encoded part of the block. These samples are indexed in 847 Andersen et. al. Experimental - Expires September 3rd, 2003 17 848 the same time direction as the target vector and ending at the 849 sample instant prior to the first sample instant represented in the 850 target vector. The codebook memory has length lMem which is equal to 851 CB_MEML=147 for the two/four 40 sample sub-blocks and 85 for the 852 23/22 sample sub-block. 854 The following figure shows an overview of the encoding procedure. 856 +------------+ +---------------+ +-------------+ 857 -> | 1. Decode | -> | 2. Mem setup | -> | 3. Perc. W. | -> 858 +------------+ +---------------+ +-------------+ 860 +------------+ +-----------------+ 861 -> | 4. Search | -> | 5. Upd. Target | ------------------> 862 | +------------+ +------------------ | 863 ----<-------------<-----------<---------- 864 stage=0..2 866 +----------------+ 867 -> | 6. Recalc G[0] | ---------------> gains and CB indices 868 +----------------+ 870 Figure 3.3. Flow chart of the codebook search in the iLBC encoder 872 1. Decode the part of the residual that has been encoded so far, 873 using the codebook without perceptual weighting 874 2. Set up the memory by taking data from the decoded residual. This 875 memory is used to construct codebooks from. For blocks preceeding 876 the start state, both the decoded residual and the target are time 877 reversed (section 3.6.1) 878 3. Filter the memory + target with the perceptual weighting filter 879 (section 3.6.2) 880 4. Search for the best match between the target and the codebook 881 vector. Compute the optimal gain for this match and quantize that 882 gain (section 3.6.4) 883 5. Update the perceptually weighted target by subtracting the 884 contribution from the selected codebook vector from the perceptually 885 weighted memory (quantized gain times selected vector). Repeat 4. 886 and 5. for the 2 additional stages 887 6. Calculate the energy loss due to encoding of the residual. If 888 needed, compensate for this loss by an upscaling and requantization 889 of the gain for the first stage (section 3.7) 891 The following sections provides an in-depth description of the 892 different blocks of figure 3.3. 894 3.6.1 Codebook Memory 896 The codebook memory is based on the already encoded sub-blocks so 897 the avaible data for encoding increases for each new sub-block that 898 has been encoded. Until enough sub-blocks has been encoded to fill 899 the codebook memory with data it is padded with zeros. The following 900 figure shows an example of the order in which the sub-blocks are 902 Andersen et. al. Experimental - Expires September 3rd, 2003 18 903 encoded for the 30 ms frame size if the start state is located in 904 the last 58 samples of sub-block 2 and 3. 906 +-----------------------------------------------------+ 907 | 5 | 1 |///|////////| 2 | 3 | 4 | 908 +-----------------------------------------------------+ 910 Figure 3.4. The order from 1 to 5 in which the sub-blocks are 911 encoded. The slashed area is the start state. 913 The first target sub-block to be encoded is number 1 and the 914 corresponding codebook memory is shown in the following figure. 915 Since the target vector is before the start state in time the 916 codebook memory and target vector are time reversed. By reversing 917 them in time the search algorithm can be reused. Since only the 918 start state has been encoded so far the last samples of the codebook 919 memory are padded with zeros. 921 +------------------------- 922 |zeros|\\\\\\\\|\\\\| 1 | 923 +------------------------- 925 Figure 3.5. The codebook memory, length lMem=85 samples, and the 926 target vector 1, length 22 samples. 928 The next step is to encode sub-block 2 using the memory which now 929 has increased since sub-block 1 has been encoded. The following 930 figure shows the codebook memory for encoding of sub-block 2. 932 +----------------------------------- 933 | zeros | 1 |///|////////| 2 | 934 +----------------------------------- 936 Figure 3.6. The codebook memory, length lMem=147 samples, and the 937 target vector 2, length 40 samples. 939 The next step is to encode sub-block 3 using the memory which now 940 has increased yet again since sub-block 1 and 2 has been encoded but 941 it still has to be padded with a few zeros. The following figure 942 shows the codebook memory for encoding of sub-block 3. 944 +------------------------------------------ 945 |zeros| 1 |///|////////| 2 | 3 | 946 +------------------------------------------ 948 Figure 3.7. The codebook memory, length lMem=147 samples, and the 949 target vector 3, length 40 samples. 951 The next step is to encode sub-block 4 using the memory which now 952 has increased yet again since sub-block 1, 2 and 3 has been encoded. 953 This time the memory does not have to be padded with zeros. The 954 following figure shows the codebook memory for encoding of sub-block 955 4. 957 Andersen et. al. Experimental - Expires September 3rd, 2003 19 958 +------------------------------------------ 959 |1|///|////////| 2 | 3 | 4 | 960 +------------------------------------------ 962 Figure 3.8. The codebook memory, length lMem=147 samples, and the 963 target vector 4, length 40 samples. 965 The final target sub-block to be encoded is number 5 and the 966 corresponding codebook memory is shown in the following figure. 967 Since the target vector is before the start state in time the 968 codebook memory and target vector are time reversed. 970 +------------------------------------------- 971 | 3 | 2 |\\\\\\\\|\\\\| 1 | 5 | 972 +------------------------------------------- 974 Figure 3.9. The codebook memory, length lMem=147 samples, and the 975 target vector 5, length 40 samples. 977 For the case of 20 ms frames the encoding procedure looks almost 978 exactly the same. The only difference is that the size of the start 979 state is 57 samples and that there is only 3 sub blocks to be 980 encoded. The encoding order is the same as above starting with the 981 23 sample target and then encoding the two remaining 40 sample sub 982 blocks, first going forward in time and then going backwards in time 983 relative to the start state. 985 3.6.2 Perceptual Weighting of Codebook Memory and Target 987 To provide a perceptual weighting of the coding error, a 988 concatenation of the codebook memory and the target to be coded is 989 all pole filtered with the perceptual weighting filter specified in 990 section 3.3. The filter state of the weighting filter is set to 991 zero. 993 in(0..(lMem-1)) = unweighted codebook memory 994 in(lMem..(lMem+lTarget-1)) = unweighted target signal 996 in -> Wk(z) -> filtered, 997 where Wk(z) is taken from the subblock of the target 999 weighted codebook memory = filtered(0..(lMem-1)) 1000 weighted target signal = filtered(lMem..(lMem+lTarget-1)) 1002 The codebook search is done using the weighted codebook memory and 1003 the weighted target, while the decoding and the codebook memory 1004 update uses the unweighted codebook memory. 1006 3.6.3 Codebook Creation 1008 The codebook for the search is created from the perceptually 1009 weighted codebook memory. It consists of two sections where the 1011 Andersen et. al. Experimental - Expires September 3rd, 2003 20 1012 first is referred to as the base codebook and the second as the 1013 expanded codebook since it is created by linear combinations of the 1014 first. Each of these two sections also have a subsection referred to 1015 as the augmented codebook. The augmented codebook is only created 1016 and used for the coding of the 40 sample sub-blocks and not for the 1017 23/22 sample sub-block case. The codebook size used for the 1018 different sub-blocks and different stages are summarized in the 1019 table below. Also the table shows, in parenthesis, how the number of 1020 codebook vectors are divided within the two sections between 1021 base/expanded codebook and augmented codebook. 1023 Stage 1024 1 2 & 3 1025 _ -------------------------------------------- 1026 22 128 (64+0)*2 128 (64+0)*2 1027 Sub- 1:st 40 256 (108+20)*2 128 (44+20)*2 1028 Blocks 2:nd 40 256 (108+20)*2 256 (108+20)*2 1029 3:rd 40 256 (108+20)*2 256 (108+20)*2 1030 4:th 40 256 (108+20)*2 256 (108+20)*2 1032 Table 3.1. The table shows the codebook size for the different sub- 1033 blocks and stages for 30 ms frames. Inside the parenthesis it shows 1034 how the number of codebook vectors are distributed, within the two 1035 sections, between the base/expanded codebook and the augmented 1036 base/expanded codebook. It should be interpreted in the following 1037 way: (base/expanded cb + augmented base/expanded cb). The total 1038 number of codebook vectors for a specific sub-block and stage is 1039 given by by the following formula: 1041 Tot. cb vectors = base cb + aug. base cb + exp. cb + aug. exp. Cb 1043 The corresponding values to figure 3.1 for 20 ms frames are only 1044 slightly modified. The short sub block is 23 instead of 22 samples 1045 and the 3:rd and 4:th sub frame are not present. 1047 3.6.3.1 Creation of a Base Codebook 1049 The base codebook is given by the perceptually weigthed codebook 1050 memory that is mentioned in section 3.5.3. The different codebook 1051 vectors are given by sliding a window of length 23/22 or 40, given 1052 by variable lTarget, over the lMem long perceptually weighted 1053 codebook memory. The indices are ordered so that the codebook vector 1054 containing sample(lMem-lTarget-n) to (lMem-n) of the codebook memory 1055 vector has index n. Thus the total number of base codebook vectors 1056 is lMem-lTarget+1 and the indices are ordered from sample delay 1057 lTarget (23/22 or 40) to lMem+1 (86 or 148). 1059 3.6.3.2 Codebook Expansion 1061 The base codebook is expanded a factor 2 by creating an additional 1062 section in the codebook. This new section is obtained by filtering 1063 the buffer buf above with a FIR filter with filter length 1064 CB_FILTERLEN=8. 1066 Andersen et. al. Experimental - Expires September 3rd, 2003 21 1067 cbfiltersTbl[CB_FILTERLEN]={-0.033691, 0.083740, -0.144043, 1068 0.713379, 0.806152, -0.184326, 1069 0.108887, -0.034180}; 1071 Before filtering, the codebook buffer is padded with three zeros in 1072 the beginning to compensate for the filter delay. Also the buffer is 1073 padded with four zeros in the end to achieve a filtered output of 1074 the same size as the input. The individual codebook vectors of the 1075 new filtered codebook and their indices are obtained in the same 1076 fashion as described above for the base codebook. 1078 3.6.3.3 Codebook Augmentation 1080 For the cases when encoding entire sub-blocks, i.e. cbveclen=40, the 1081 base and expanded codebooks are augmented to increase codebook 1082 richness. The codebooks are augmented by vectors produced by 1083 interpolation of segments. The base and expanded codebook, 1084 constructed above, consists of vectors corresponding to sample 1085 delays in the range from cbveclen to lMem. The codebook augmentation 1086 attempts to augment these codebooks with vectors corresponding to 1087 sample delays from 20 to 39. However, not all of these samples are 1088 present in the base codebook and expanded codebook rspectively. 1089 Therefore, the augmentation vectors are constructed as linear 1090 combinations between samples corresponding to sample delays in the 1091 range 20 to 39. The general idea of this procedure is presented in 1092 the following figures and text. The procedure is performed for both 1093 the base codebook and the expanded codebook. 1095 - - ------------------------| 1096 codebook memory | 1097 - - ------------------------| 1098 |-5-|---15---|-5-| 1099 pi pp po 1101 | | Codebook vector 1102 |---15---|-5-|-----20-----| <- corresponding to 1103 i ii iii sample delay 20 1105 Figure 1 The figure shows the codebook memory with pointers pi, pp 1106 and po where pi points to sample 25, pp to sample 20 and po to 1107 sample 5. Below the codebook memory, the augmented codebook vector 1108 corresponding to sample delay 20 is drawn. Segment i consists of 15 1109 samples from pointer pp and forward in time. Segment ii consists of 1110 5 interpolated samples from pi and forward and from po and forward. 1111 The samples are linearly interpolated with weights [0.0, 0.2, 0.4, 1112 0.6, 0.8] for pi and weights [1.0, 0.8, 0.6, 0.4, 0.2] for po. 1113 Segment iii consists of 20 samples from pp and forward. The 1114 augmented codebook vector corresponding to sample delay 21 is 1115 produced by moving pointers pp and pi one sample backwards in time. 1116 That gives us the following figure. 1118 Andersen et. al. Experimental - Expires September 3rd, 2003 22 1119 - - ------------------------| 1120 codebook memory | 1121 - - ------------------------| 1122 |-5-|---16---|-5-| 1123 pi pp po 1125 | | Codebook vector 1126 |---16---|-5-|-----19-----| <- corresponding to 1127 i ii iii sample delay 21 1129 Figure 3.10. The figure shows the codebook memory with pointers pi, 1130 pp and po where pi points to sample 26, pp to sample 21 and po to 1131 sample 5. Below the codebook memory, the augmented codebook vector 1132 corresponding to sample delay 21 is drawn. Segment i does now 1133 consist of 16 samples from pp and forward. Segment ii consists of 5 1134 interpolated samples from pi and forward and po and forward and the 1135 interpolation weights are the same throughout the procedure. Segment 1136 iii consists of 19 samples from pp and forward. The same procedure 1137 of moving the two pointers is continued until the last augmented 1138 vector corresponding to sample delay 39 has been created. This gives 1139 a total of 20 new codebook vectors to each of the two sections. Thus 1140 the total number of codebook vectors for each of the two sections, 1141 when including the augmented codebook becomes lMem-SUBL+1+SUBL/2. 1142 This is provided that augmentation is evoked, i.e., that 1143 lTarget=SUBL. 1145 3.6.4 Codebook Search 1147 The codebook search uses the codebooks described in the sections 1148 above to find the best match of the perceptually weighted target, 1149 see section 3.6.2. The search method is a multi-stage gain-shape 1150 matching performed as follows. At each stage the best shape vector 1151 is identified, then the gain is calculated and quantized, and 1152 finally the target is updated in preparation for the next codebook 1153 search stage. The number of stages is CB_NSTAGES=3. 1155 If the target is the 23/22 sample vector the codebooks are searched 1156 in the order: base codebook followed by the expanded codebook. If 1157 the target is 40 samples the order is: base codebook, augmented base 1158 codebook, expanded codebook and finally augmented expanded codebook. 1159 The size of each codebook section and its corresponding augmented 1160 section is given by table 1 in section 3.5.3. 1162 For example when coding the second 40 sample sub-block indices 0-107 1163 corresponds to the base codebook, 108-127 corresponds to the 1164 augmented base codebook, 128-235 corresponds to the expanded 1165 codebook and finally indices 236-255 corresponds to the augmented 1166 expanded codebook. The indices are divided in the same fashion for 1167 all stages in the example. Only in the case of coding the first 40 1168 sample sub-block is there a difference between stages. 1170 Andersen et. al. Experimental - Expires September 3rd, 2003 23 1171 3.6.4.1 The Codebook Search at Each Stage 1173 The codebooks are searched to find the best match to the target at 1174 each stage. When the best match is found the target is updated and 1175 the next-stage search is started. The three chosen codebook vectors 1176 and their corresponding gain constitutes the encoded sub-block. The 1177 best match is decided by the following three criterions: 1179 1. Compute the measure 1181 (target*cbvec)^2 / ||cbvec||^2 1183 for all codebook vectors, cbvec, and choose the codebook vector 1184 maximizing the measure. The expression (target*cbvec) is the dot 1185 product between the target vector to be coded and the codebook 1186 vector for which we compute the measure. 1188 2. The absolute value of the gain, gain, corresponding to the chosen 1189 codebook vector, cbvec, must be smaller than a fixed limit, 1190 CB_MAXGAIN=1.3: 1192 |gain| < CB_MAXGAIN 1194 where the gain is computed in the following way: 1196 gain = (target*cbvec) / ||cbvec||^2 1198 3. For the first stage the dot product of the chosen codebook vector 1199 and target must be positive: 1201 target*cbvec > 0 1203 In practice the above criterions are used in a sequential search 1204 through all codebook vectors. The best match is found by 1205 registrering a new max measure and index whenever the previously 1206 registered max measure is surpassed and all other criterions are 1207 fulfilled. 1209 3.6.3.2 The Gain Quantization at Each Stage 1211 The gain follows as a result of the computation: 1213 gain = (target*cbvec)^2 / ||cbvec||^2 1215 for the optimal codebook vector that was found by the procedure from 1216 section 3.6.3.1. 1218 The three stages quantize the gain using 5, 4 and 3 bits 1219 respectively. In the first stage, the gain is limited to positive 1220 values. This gain is quantized by finding the nearest value in the 1221 quantization table gain_sq5Tbl. 1223 Andersen et. al. Experimental - Expires September 3rd, 2003 24 1224 gain_sq5Tbl[32]={0.037476, 0.075012, 0.112488, 0.150024, 0.187500, 1225 0.224976, 0.262512, 0.299988, 0.337524, 0.375000, 1226 0.412476, 0.450012, 0.487488, 0.525024, 0.562500, 1227 0.599976, 0.637512, 0.674988, 0.712524, 0.750000, 1228 0.787476, 0.825012, 0.862488, 0.900024, 0.937500, 1229 0.974976, 1.012512, 1.049988, 1.087524, 1.125000, 1230 1.162476, 1.200012} 1232 The gains of the subsequent two stages can be either positive or 1233 negative. The gains are quantized using a quantization table times a 1234 scale factor. The second stage uses the table gain_sq4Tbl and the 1235 third stage use gain_sq3Tbl. The scale factor equates 0.1 or the 1236 absolute value of the quantized gain representation value obtained 1237 in the previous stage, whichever is the larger. Again, the resulting 1238 gain index is the index to the nearest value of the quantization 1239 table times the scale factor. 1241 gainQ = scaleFact * gain_sqXTbl[index] 1243 gain_sq4Tbl[16]={-1.049988, -0.900024, -0.750000, -0.599976, 1244 -0.450012, -0.299988, -0.150024, 0.000000, 0.150024, 1245 0.299988, 0.450012, 0.599976, 0.750000, 0.900024, 1246 1.049988, 1.200012} 1248 gain_sq3Tbl[8]={-1.000000, -0.659973, -0.330017,0.000000, 1249 0.250000, 0.500000, 0.750000, 1.00000} 1251 3.6.3.3 Preparation of Target for Next Stage 1253 Before performing the search for the next stage the target vector is 1254 updated by subtracting from it the selected codebook vector (from 1255 the perceptually weighted codebook) times the corresponding 1256 quantized gain. 1258 target[i] = target[i] - gainQ * selected_vec[i]; 1260 A reference implementation of the codebook encoding is found in 1261 Appendix A.34. 1263 3.7 Gain Correction Encoding 1265 The start state is quantized in a relatively model independent 1266 manner using 3 bits per sample. In contrast to this, the remaining 1267 parts of the block is encoded using an adaptive codebook. This 1268 codebook will produce high matching accuracy whenever there is a 1269 high correlation between the target and the best codebook vector. 1270 For unvoiced speech segments and background noises, this is not 1271 necessarily so, which, due to the nature of the squared error 1272 criterion, results in a coded signal with less power than the target 1273 signal. As the coded start state has good power mathing to the 1274 target, the result is power fluctuation within the encoded frame. 1275 Perceptually, the main problem with this is that the time envelope 1276 of the signal energy becomes unsteady. To overcome this problem, the 1278 Andersen et. al. Experimental - Expires September 3rd, 2003 25 1279 gains for the codebooks are re-scaled after the codebook encoding by 1280 searching for a new gain factor for the first stage codebook that 1281 provides better power matching. 1283 First the energy for the target signal, tene, is computed along with 1284 the energy for the coded signal, cene, given by the addition of the 1285 the 3 gain scaled codebook vectors. Since the gains of the 2nd and 1286 3rd stage scale with the gain of the first stage, by changing the 1287 first stage gain from gains[0] to gain_sq5Tbl[i], the energy of the 1288 coded signal changes from cene to 1290 cene*(gain_sq5Tbl[i]*gain_sq5Tbl[i])/(gain[0]*gains[0]) 1292 where gains[0] is the gain for the first stage found in the original 1293 codebook search. A refined search is performed by testing the gain 1294 indices i=0 to 31, and as long as the new codebook energy as given 1295 above is less than tene, the gain index for stage 1 is increased. A 1296 restriction is applied so that the new gain value for stage 1 cannot 1297 be more than 2 times higher than the original value found in the 1298 codebook search. Note that by using this method the shape of the 1299 encoded vector is not changed, only the gain or amplitude. 1301 3.8 Bitstream Definition 1303 The total number of bits used to describe one frame of 20 ms speech 1304 is 303, which fits in 38 bytes and results in a bit rate of 15.20 1305 kbit/s. For the case with a frame length of 30 ms speech the total 1306 number of bits used is 399, which fits in 50 bytes and results in a 1307 bit rate of 13.33 kbit/s. In the bitstream definition the bits are 1308 distributed into three classes according to their bit error or loss 1309 sensitivity. The most sensitive bits (class 1) is placed first in 1310 the bitstream for each frame. The less sensitive bits (class 2) is 1311 placed after the class 1 bits. The least sensitive bits (class 3) 1312 are placed at the end of the bitstream for each frame. 1314 Looking at the 20/30 ms frame length casees for each class: The 1315 class 1 bits occupy a total of 6/8 bytes (48/64 bits), the class 2 1316 bits occupy 8/12 bytes (64/96 bits), and the class 3 bits occupy 1317 24/30 bytes (191/239 bits). This distribution of the bits enable the 1318 use of uneven level protection (ULP) as is exploited in the payload 1319 format definition for iLBC [1]. The detailed bit allocation is shown 1320 in the table below. When a quantization index is distributed between 1321 more classes the more significant bits belong to the lowest class. 1323 Andersen et. al. Experimental - Expires September 3rd, 2003 26 1324 Bitstream structure: 1326 ------------------------------------------------------------------+ 1327 Parameter | Bits Class <1,2,3> | 1328 | 20 ms frame | 30 ms frame | 1329 ----------------------------------+---------------+---------------+ 1330 Split 1 | 6 <6,0,0> | 6 <6,0,0> | 1331 LSF 1 Split 2 | 7 <7,0,0> | 7 <7,0,0> | 1332 LSF Split 3 | 7 <7,0,0> | 7 <7,0,0> | 1333 ------------------+---------------+---------------+ 1334 Split 1 | NA (Not Appl.)| 6 <6,0,0> | 1335 LSF 2 Split 2 | NA | 7 <7,0,0> | 1336 Split 3 | NA | 7 <7,0,0> | 1337 ------------------+---------------+---------------+ 1338 Sum | 20 <20,0,0> | 40 <40,0,0> | 1339 ----------------------------------+---------------+---------------+ 1340 Block Class. | 2 <2,0,0> | 3 <3,0,0> | 1341 ----------------------------------+---------------+---------------+ 1342 Position 22 sample segment | 1 <1,0,0> | 1 <1,0,0> | 1343 ----------------------------------+---------------+---------------+ 1344 Scale Factor State Coder | 6 <6,0,0> | 6 <6,0,0> | 1345 ----------------------------------+---------------+---------------+ 1346 Sample 0 | 3 <0,1,2> | 3 <0,1,2> | 1347 Quantized Sample 1 | 3 <0,1,2> | 3 <0,1,2> | 1348 Residual : | : : | : : | 1349 State : | : : | : : | 1350 Samples : | : : | : : | 1351 Sample 56 | 3 <0,1,2> | 3 <0,1,2> | 1352 Sample 57 | NA | 3 <0,1,2> | 1353 ------------------+---------------+---------------+ 1354 Sum | 171 <0,57,114>| 174 <0,58,116>| 1355 ----------------------------------+---------------+---------------+ 1356 Stage 1 | 7 <6,0,1> | 7 <4,2,1> | 1357 CB for 22/23 Stage 2 | 7 <0,0,7> | 7 <0,0,7> | 1358 sample block Stage 3 | 7 <0,0,7> | 7 <0,0,7> | 1359 ------------------+---------------+---------------+ 1360 Sum | 21 <6,0,15> | 21 <4,2,15> | 1361 ----------------------------------+---------------+---------------+ 1362 Stage 1 | 5 <2,0,3> | 5 <1,1,3> | 1363 Gain for 22/23 Stage 2 | 4 <1,1,2> | 4 <1,1,2> | 1364 sample block Stage 3 | 3 <0,0,3> | 3 <0,0,3> | 1365 ------------------+---------------+---------------+ 1366 Sum | 12 <3,1,8> | 12 <2,2,8> | 1368 Andersen et. al. Experimental - Expires September 3rd, 2003 27 1369 ----------------------------------+---------------+---------------+ 1370 Stage 1 | 8 <7,0,1> | 8 <6,1,1> | 1371 sub-block 1 Stage 2 | 7 <0,0,7> | 7 <0,0,7> | 1372 Stage 3 | 7 <0,0,7> | 7 <0,0,7> | 1373 ------------------+---------------+---------------+ 1374 Stage 1 | 8 <0,0,8> | 8 <0,7,1> | 1375 sub-block 2 Stage 2 | 8 <0,0,8> | 8 <0,0,8> | 1376 Indices Stage 3 | 8 <0,0,8> | 8 <0,0,8> | 1377 for CB ------------------+---------------+---------------+ 1378 sub-blocks Stage 1 | NA | 8 <0,7,1> | 1379 sub-block 3 Stage 2 | NA | 8 <0,0,8> | 1380 Stage 3 | NA | 8 <0,0,8> | 1381 ------------------+---------------+---------------+ 1382 Stage 1 | NA | 8 <0,7,1> | 1383 sub-block 4 Stage 2 | NA | 8 <0,0,8> | 1384 Stage 3 | NA | 8 <0,0,8> | 1385 ------------------+---------------+---------------+ 1386 Sum | 46 <7,0,39> | 94 <6,22,66> | 1387 ----------------------------------+---------------+---------------+ 1388 Stage 1 | 5 <1,2,2> | 5 <1,2,2> | 1389 sub-block 1 Stage 2 | 4 <1,1,2> | 4 <1,2,1> | 1390 Stage 3 | 3 <0,0,3> | 3 <0,0,3> | 1391 ------------------+---------------+---------------+ 1392 Stage 1 | 5 <1,1,3> | 5 <0,2,3> | 1393 sub-block 2 Stage 2 | 4 <0,2,2> | 4 <0,2,2> | 1394 Stage 3 | 3 <0,0,3> | 3 <0,0,3> | 1395 Gains for ------------------+---------------+---------------+ 1396 sub-blocks Stage 1 | NA | 5 <0,1,4> | 1397 sub-block 3 Stage 2 | NA | 4 <0,1,3> | 1398 Stage 3 | NA | 3 <0,0,3> | 1399 ------------------+---------------+---------------+ 1400 Stage 1 | NA | 5 <0,1,4> | 1401 sub-block 4 Stage 2 | NA | 4 <0,1,3> | 1402 Stage 3 | NA | 3 <0,0,3> | 1403 ------------------+---------------+---------------+ 1404 Sum | 24 <3,6,15> | 48 <2,12,34> | 1405 ------------------------------------------------------------------- 1406 SUM 303 <48,64,191> 399 <64,96,239> 1408 Table 3.2. The bitstream definition for iLBC for both the 20 ms 1409 frame size mode and the 30 ms frame size mode. 1411 When packetized into the payload the bits MUST be sorted as: All the 1412 class 1 bits in the order (from top and down) as they were specified 1413 in the table, all the class 2 bits (from top and down) and finally 1414 all the class 3 bits in the same sequential order. The last unused 1415 bit of the payload SHOULD be set to zero. 1417 Andersen et. al. Experimental - Expires September 3rd, 2003 28 1418 4. DECODER PRINCIPLES 1420 This section describes the principles of each component of the 1421 decoder algorithm. 1423 +-------------+ +--------+ +---------------+ 1424 payload -> | 1. Get para | -> | 2. LPC | -> | 3. Sc Dequant | -> 1425 +-------------+ +--------+ +---------------+ 1427 +-------------+ +------------------+ 1428 -> | 4 Mem setup | -> | 5. Construct res |-------> 1429 | +-------------+ +------------------- | 1430 ---------<-----------<-----------<------------ 1431 Sub frame 0...2/4 (20ms/30ms) 1433 +----------------+ +----------+ 1434 -> | 6. Enhance res | -> | 7. Synth | ------------> 1435 +----------------+ +----------+ 1437 +-----------------+ 1438 -> | 8. Post Process | ----------------> decoded speech 1439 +-----------------+ 1441 Figure 4.1. Flow chart of the iLBC decoder. If a frame was lost 1442 steps 1 to 5 SHOULD be replaced by a PLC algorithm. 1444 1. Extract the parameters from the bitstream 1445 2. Decode the LPC and interpolate (section 4.1) 1446 3. Construct the 57/58 sample start state (section 4.2) 1447 4. Set up the memory using data from the decoded residual. This 1448 memory is used for codebook construction. For blocks preceeding the 1449 start state, both the decoded residual and the target are time 1450 reversed. Subframes are decoded in the same order as they were 1451 encoded 1452 5. Construct the residual of this subframe (gain[0]*cbvec[0] + 1453 gain[1]*cbvec[1] + gain[2]*cbvec[2]). Repeat 4.4 and 4.5 until the 1454 residual of all sub blocks have been constructed 1455 6. Enhance the residual with the post filter (section 4.6) 1456 7. Synthesis of the residual (section 4.7) 1457 8. Post process with HP filter if desired (section 4.8) 1459 4.1 LPC Filter Reconstruction 1461 The decoding of the LP filter parameters is very straightforward. 1462 For a set of three/six indices the corresponding LSF vector(s) are 1463 found by simple table look up. For each of the LSF vectors the three 1464 split vectors are concatenated to obtain qlsf1 and qlsf2, 1465 respectively (in the 20 ms mode only one LSF vector, qlsf, is 1466 constructed). The next step is the stability check described in 1467 Section 3.2.5 followed by the interpolation scheme described in 1468 Section 3.2.6 (3.2.7 for 20 ms frames). The only difference is that 1469 only the quantized LSFs are known at the decoder and hence the 1470 unquantized LSFs are not processed. 1472 Andersen et. al. Experimental - Expires September 3rd, 2003 29 1473 A reference implementation of the LPC filter reconstruction is given 1474 in Appendix A.36. 1476 4.2 Start State Reconstruction 1478 The scalar encoded STATE_SHORT_LEN=58 (STATE_SHORT_LEN=57 in the 20 1479 ms mode) state samples are reconstructed by 1) forming a set of 1480 samples (by table look-up) from the index stream idxVec[n] 2) 1481 multiplying the set with 1/scal=(10^qmax)/4.5 3) time reversing the 1482 57/58 samples 4) filtering the time inversed block with the 1483 dispersion (all-pass) filter used in the encoder (as described in 1484 section 3.5.2). This compensates for the phase distortion of the 1485 earlier filter operation. 5) Reversing the 57/58 samples from 1486 previous step 1488 in(0..(STATE_SHORT_LEN-1)) = time reversed samples from table 1489 look-up, 1490 idxVecDec((STATE_SHORT_LEN-1)..0) 1492 in(STATE_SHORT_LEN..(2*STATE_SHORT_LEN-1)) = 0 1494 Pk(z) = �rk(z)/�k(z), where 1495 ___ 1496 \ 1497 �rk(z)= z^(-LPC_FILTERORDER) + > �ki*z^(i-(LPC_FILTERORDER-1)) 1498 /__ 1499 i=0...(LPC_FILTERORDER-1) 1501 and �k(z) is taken from the block where the start state begins 1503 in -> Pk(z) -> filtered 1505 out(k) = filtered(STATE_SHORT_LEN-1-k) + 1506 filtered(2*STATE_SHORT_LEN-1-k), 1507 k=0..(STATE_SHORT_LEN-1) 1509 The remaining 23/22 samples in the state are reconstructed by 1510 the same adaptive codebook technique as described in section 4.3. 1511 The location bit determines whether these are the first or the last 1512 23/22 samples of the 80 sample state vector. If the remaining 23/22 1513 samples are the first samples of the state vector, then the scalar 1514 encoded STATE_SHORT_LEN state samples are time-reversed before 1515 initialization of the adaptive codebook memory vector. 1517 A reference implementation of the start state reconstruction is 1518 given in Appendix A.44. 1520 4.3 Excitation Decoding Loop 1522 The decoding of the LPC excitation vector proceeds in the same order 1523 in which the residual was encoded at the encoder. That is, after the 1524 decoding of the entire 80 sample state vector, the forward subblocks 1526 Andersen et. al. Experimental - Expires September 3rd, 2003 30 1527 (corresponding to samples occurring after the state vector samples) 1528 are decoded, and then the backward subblocks (corresponding to 1529 samples occurring before the state vector) are decoded, resulting in 1530 a fully decoded block of excitation signal samples. 1532 In particular, each subblock is decoded using the multistage 1533 adaptive codebook decoding module which is described in section 4.4. 1534 This module relies upon an adaptive codebook memory that is 1535 constructed before each run of the adaptive codebook decoding. The 1536 construction of the adaptive codebook memory in the decoder is 1537 identical to the method outlined in section 3.6.3, except that it is 1538 done on the codebook memory without perceptual weighting. 1540 For the initial forward subblock, the last STATE_LEN=80 samples of 1541 the length CB_LMEM=147 adaptive codebook memory are filled with the 1542 samples of the state vector. For subsequent forward subblocks, the 1543 first SUBL=40 samples of the adaptive codebook memory are discarded, 1544 the remaining samples are shifted by SUBL samples towards the 1545 beginning of the vector, while the newly decoded SUBL=40 samples are 1546 placed at the end of the adaptive codebook memory. For backward 1547 subblocks, the construction is similar except that every vector of 1548 samples involved is first time-reversed. 1550 A reference implementation of the excitation decoding loop is found 1551 in Appendix A.5. 1553 4.4 Multistage Adaptive Codebook Decoding 1555 The Multistage Adaptive Codebook Decoding module is used at both the 1556 sender (encoder) and the receiver (decoder) ends to produce a 1557 synthetic signal in the residual domain that is eventually used to 1558 produce synthetic speech. The module takes the index values used to 1559 construct vectors that are scaled and summed together to produce a 1560 synthetic signal that is the output of the module. 1562 4.4.1 Construction of the Decoded Excitation Signal 1564 The unpacked index values provided at the input to the module are 1565 references to extended codebooks, which are constructed as described 1566 in Section 3.6.3 with the only difference that it is based on the 1567 codebook memory without the perceptual weighting. The unpacked 3 1568 indices are used to look up 3 codebook vectors. The unpacked 3 gain 1569 indices are used to decode the corresponding 3 gains. In this 1570 decoding the successive rescaling as described in Section 3.6.3.2 is 1571 applied. 1573 A reference implementation of the adaptive codebook decoding is 1574 listed in Appendix A.32. 1576 Andersen et. al. Experimental - Expires September 3rd, 2003 31 1577 4.5 Packet Loss Concealment 1579 If packet loss occurs, the decoder receives a signal saying that 1580 information regarding a block is lost. For such blocks it is 1581 RECOMMENDED to use a Packet Loss Concealment (PLC) unit to create a 1582 decoded signal which mask the effect of that packet loss. In the 1583 following we will describe an example of a PLC unit that can be used 1584 with the iLBC codec. As the PLC unit is used only at the decoder, 1585 the PLC unit does not affect interoperability between 1586 implementations. Other PLC implementations MAY therefore be used. 1588 The example PLC described operates on the LP filters and the 1589 excitation signals and is based on the following principles: 1591 4.5.1 Block Received Correctly and Previous Block also Received 1593 If the block is received correctly, the PLC only records state 1594 information of the current block that can be used in case the next 1595 block is lost. The LP filter coefficients for each subblock and the 1596 entire decoded excitation signal are all saved in the decoder state 1597 structure. All this information will be needed if the following 1598 block is lost. 1600 4.5.2 Block Not Received 1602 If the block is not received, the block substitution is based on 1603 doing a pitch synchronous repetition of the excitation signal which 1604 is filtered by modified versions of the previous block's LP filters. 1605 The previous block's information is stored in the decoder state 1606 structure. 1608 First, the previous block's LP filters are bandwidth expanded (the 1609 effect of which is to pull the roots away from the unit circle to 1610 mute the resonance of the filters) to produce the LP filters that 1611 are used in the synthesis of the substituted block. 1613 A correlation analysis is performed on the previous block's 1614 excitation signal in order to detect the amount of pitch periodicity 1615 and a pitch value. The correlation measure is also used to decide on 1616 the voicing level (the degree to which the previous block's 1617 excitation was a voiced or roughly periodic signal). The excitation 1618 in the previous block is used to create an excitation for the block 1619 to be substituted such that the pitch of the previous block is 1620 maintained. Therefore, the new excitation is constructed in a pitch 1621 synchronous manner. In order to avoid a buzzy sounding substituted 1622 block, a random excitation is mixed with the new pitch periodic 1623 excitation and the relative use of the two components is computed 1624 from the correlation measure (voicing level). 1626 For the block to be substituted, the newly constructed excitation 1627 signal is then passed through the newly constructed LP filters to 1628 produce the speech that will be substituted for the lost block. 1630 Andersen et. al. Experimental - Expires September 3rd, 2003 32 1631 For several consecutive lost blocks, the packet loss concealment 1632 continues in a similar manner. The correlation measure of the last 1633 received block is still used along with the same pitch value. The LP 1634 filters of the last received block are also used again, but the 1635 bandwidth expansion is increased for consecutive lost blocks (as the 1636 length in time from the last received block increases). This 1637 increases the muting of the resonance of the spectral envelope. The 1638 energy of the substituted excitation for consecutive lost blocks is 1639 decreased, leading to a dampened excitation, and therefore dampened 1640 speech. 1642 4.5.3 Block Received Correctly When Previous Block Not Received 1644 For the case in which a block is received correctly when the 1645 previous block was not received, the correctly received block's 1646 directly decoded speech (based solely on the received block) is not 1647 used as the actual output. The reason for this is that the directly 1648 decoded speech does not necessarily smoothly merge into the 1649 synthetic speech generated for the previous lost block. If the two 1650 signals are not smoothly merged, an audible discontinuity is 1651 accidentally produced. Therefore, a correlation analysis between the 1652 two blocks of excitation signal (the excitation of the previous 1653 concealed block and the excitation of the current received block) is 1654 performed to find the best phase match. Then a simple overlap-add 1655 procedure is performed to smoothly merge the previous excitation 1656 into the current block's excitation. 1658 The exact implementation of the packet loss concealment does not 1659 influence interoperability of the codec. 1661 A reference implementation of the packet loss concealment is 1662 suggested in Appendix A.14. Exact compliance with this suggested 1663 algorithm is not needed for a reference implementation to be fully 1664 compatible with the overall codec specification. 1666 4.6 Enhancement 1668 The decoder contains an enhancement unit that operates on the 1669 reconstructed excitation signal. The enhancement unit increases the 1670 perceptual quality of the reconstructed signal by reducing the 1671 speech-correlated noise in the voiced speech segments. Compared to 1672 tratidional postfilters, the enhancer has the advantage that it can 1673 only modify the excitation signal slightly. This means that there is 1674 no risk of over enhancement. The enhancer works very similar for 1675 both the 20 ms frame size mode and for the 30 ms frame size mode. 1677 For the mode with 20 ms frame size, the enhancer uses a memory of 1678 six 80 sample excitation blocks prior in time plus the two new 80 1679 sample excitation blocks. For each block of 160 new unenhanced 1680 excitation samples, 160 enhanced excitation samples is produced. The 1681 enhanced excitation is 40 sample delayed compared to the unenhanced 1682 excitation since the enhancer algorithm uses lookahead. 1684 Andersen et. al. Experimental - Expires September 3rd, 2003 33 1685 For the mode with 30 ms frame size, the enhancer uses a memory of 1686 five 80 sample excitation blocks prior in time plus the three new 80 1687 sample excitation blocks. For each block of 240 new unenhanced 1688 excitation samples, 240 enhanced excitation samples is produced. The 1689 enhanced excitation is 80 sample delayed compared to the unenhanced 1690 excitation since the enhancer algorithm uses lookahead. 1692 OUTLINE of Enhancer 1694 The speech enhancement unit operates on sub blocks of 80 samples, 1695 which means that there are 2/3 80 sample sub blocks per frame. Each 1696 of these two/three sub blocks are enhanced separately, but in an 1697 analogous manner. 1699 unenhanced residual 1700 | 1701 | +---------------+ +--------------+ 1702 +-> | 1. Pitch Est | -> | 2. Find PSSQ | --------> 1703 +---------------+ | +--------------+ 1704 +-----<-------<------<--+ 1705 +------------+ enh block 0..1/2 | 1706 -> | 3. Smooth | | 1707 +------------+ | 1708 \ | 1709 /\ | 1710 / \ Already | 1711 / 4. \----------->----------->-----------+ | 1712 \Crit/ Fulfilled | | 1713 \? / v | 1714 \/ | | 1715 \ +-----------------+ +---------+ | | 1716 Not +->| 5. Use Constr. | -> | 6. Mix | -----> 1717 Fulfilled +-----------------+ +---------+ 1719 ---------------> enhanced residual 1721 Figure 4.2. Flow chart of the enhancer 1723 1. Pitch estimation of each of the two/three new 80 sample blocks 1724 2. Find the pitch-period-synchronous sequence n (for block k) by a 1725 search around the estimated pitch value. Do this for 1726 n=1,2,3,-1,-2,-3 1727 3. Calculate the smoothed residual generated by the 6 pitch-period- 1728 synchronous sequence from prior step 1729 4. Check if the smoothed residual satisfies the criterion (section 1730 4.6.4) 1731 5. Use constraint to calculate mixing factor (section 4.6.5) 1732 6. Mix smoothed signal with unenhanced residual (pssq(n) n=0) 1734 The main idea of the enhancer is to find three 80 sample blocks 1735 before and three 80 sample blocks after the analyzed unenhanced sub 1736 block and use these to improve the quality of the exitation in that 1737 sub block. The six blocks are chosen so that they have the highest 1739 Andersen et. al. Experimental - Expires September 3rd, 2003 34 1740 possible correlation with the unenhanced sub block that is beeing 1741 enhanced. In other words the 6 blocks are pitch-period-synchronous 1742 sequences to the unenhanced sub block. 1744 A linear combination of the six pitch-period-synchronous sequences 1745 is calculated that approximates the sub block. If the squared error 1746 between the approximation and the unenhanced sub block is small 1747 enough, the enhanced residual is set equal to this approximation. 1748 For the cases when the squared error criteria is not fulfilled, a 1749 linear combination of the approximation and the unenhanced residual 1750 forms the enhanced residual. 1752 4.6.1 Estimating the pitch 1754 In order to determine the locations of the pitch-period-synchronous 1755 sequences in a complexity efficient way, pitch estimates are needed. 1756 For each of the new 3 sub blocks a pitch estimate is calculated by 1757 finding the maximum correlation in the range from lag 20 to lag 120. 1759 These pitch estimates are used to narrow down the search for the 1760 best possible pitch-period-synchronous sequences. 1762 4.6.2 Determination of the Pitch-Synchronous Sequences 1764 Upon receiving the pitch estimates from the prior step, the enhancer 1765 analyzes and enhances one 80 sample sub block at a time. The pitch- 1766 period-synchronous-sequences pssq(n) can be viewed as vectors of 1767 length 80 samples each shifted n*lag samples from the current sub 1768 block. The six pitch-period-synchronous-sequences, pssq(-3) to 1769 pssq(-1) and pssq(1) to pssq(3), are found one at a time by the 1770 steps below: 1772 1) Calculate the estimate of the position of the pssq(n). For 1773 pssq(n) in front of pssq(0) (n > 0), the location of the pssq(n) 1774 is estimated by moving one pitch estimate forward in time from 1775 the exact location of pssq(n-1). Similarly for pssq(n) behind 1776 pssq(0) (n < 0) is estimated by moving one pitch estimate 1777 backward in time from the exact location of pssq(n+1). If the 1778 estimated pssq(n) vector location is totally within the enhancer 1779 memory (figure 4.3) step 2,3, and 4 are performed, otherwise the 1780 pssq(n) is set to zeros. 1782 2) Compute the correlation between the unenhanced excitation and 1783 vectors around the estimated location interval of pssq(n). The 1784 correlation is calculated in the interval estimated location +/- 1785 2 samples. This results in 5 correlation values. 1787 3) The 5 correlation values are upsampled by a factor 4, using sinc 1788 upsampling filters (four MA filters with coefficients upsFilter1 1789 .. upsFilter4). Within these the maximum value is found, which 1790 specifies the best pitch-period with a resolution of a quarter of 1791 a sample. 1793 Andersen et. al. Experimental - Expires September 3rd, 2003 35 1794 upsFilter1[7]={0.000000 0.000000 0.000000 1.000000 1795 0.000000 0.000000 0.000000} 1796 upsFilter2[7]={0.015625 -0.076904 0.288330 0.862061 1797 -0.106445 0.018799 -0.015625} 1798 upsFilter3[7]={0.023682 -0.124268 0.601563 0.601563 1799 -0.124268 0.023682 -0.023682} 1800 upsFilter4[7]={0.018799 -0.106445 0.862061 0.288330 1801 -0.076904 0.015625 -0.018799} 1803 4) Generate the pssq(n) vector by upsampling of the excitation 1804 memory and extracting the sequence that corresponds to the lag 1805 delay that was calculated in prior step. 1807 With the steps above all the pssq(n) can be found in an iterative 1808 manner, first moving backward in time from pssq(0) and then forward 1809 in time from pssq(0). 1811 0 159 319 479 639 1812 +---------------------------------------------------------------+ 1813 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 1814 +---------------------------------------------------------------+ 1815 |pssq 0 | 1816 |pssq -1| |pssq 1 | 1817 |pssq -2| |pssq 2 | 1818 |pssq -3| |pssq 3 | 1820 Figure 4.3. Pitch-period-synchronous sequences in the enhancement of 1821 the first 80 sample block in the 20 ms frame size mode. The 1822 unenhanced signal input is stored in the two last sub-blocks (1-2), 1823 and the six other sub-blocks contain unenhanced residual prior-in- 1824 time. We perform the enhancement algorithm on two blocks of 80 1825 samples, where the first of the two blocks consist of the last 40 1826 samples of sub-block 0 and the first 40 samples of sub-block 1. The 1827 second 80 sample block consist of the last 40 samples of sub-block 1 1828 and the first 40 samples of sub-block 2. 1830 0 159 319 479 639 1831 +---------------------------------------------------------------+ 1832 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 1833 +---------------------------------------------------------------+ 1834 |pssq 0 | 1835 |pssq -1| |pssq 1 | 1836 |pssq -2| |pssq 2 | 1837 |pssq -3| |pssq 3 | 1839 Figure 4.4. Pitch-period-synchronous sequences in the enhancement of 1840 the first 80 sample block in the 30 ms frame size mode. The 1841 unenhanced signal input is stored in the three last sub-blocks (1- 1842 3). The five other sub-blocks contain unenhanced residual prior-in- 1843 time. The enhancement algorithm is performed the three 80 sample 1844 sub-blocks 0, 1 and 2. 1846 Andersen et. al. Experimental - Expires September 3rd, 2003 36 1847 4.6.3 Calculation of the smoothed excitation 1849 A linear combination of the six pssq(n) (n!=0) form a smoothed 1850 approximation, z, of pssq(0). Most of the weight is put on the 1851 sequences that are close to pssq(0) since these are most likely to 1852 be most similar to pssq(0). The smoothed vector is also rescaled, so 1853 that the energy of z is the same as the energy of pssq(0). 1855 ___ 1856 \ 1857 y = > pssq(i) * pssq_weight(i) 1858 /__ 1859 i=-3,-2,-1,1,2,3 1861 pssq_weight(i) = 0.5*(1-cos(2*pi*(i+4)/(2*3+2))) 1863 z = C * y, where C = sqrt(||pssq(0)||/||y||) 1865 4.6.4 Enhancer criterion 1867 The criterion of the enhancer is that the enhanced excitation is not 1868 allowed to differ much from the unenhanced excitation. This 1869 criterion is checked for each 80 sample sub block. 1871 e < (b * ||pssq(0)||), where b=0.05 and (Constraint 1) 1873 e = (pssq(0)-z)*(pssq(0)-z), and "*" means the dot product 1875 4.6.5 Enhancing the excitation 1877 From the criterion in the previous section it is clear that the 1878 excitation is not allowed to change much. The purpose of this 1879 constraint is to prevent the creation of an enhanced signal that is 1880 significantly different from the original signal. This also means 1881 that the constraint limits the numerical size of the errors that the 1882 enhancement procedure can make. That is especially important in 1883 unvoiced segments and background noise segments where increased 1884 periodicity could lead to lower perceived quality. 1886 When the constraint in the prior section is not met, the enhanced 1887 residual is instead calculated through a constrained optimization 1888 using the Lagrange multiplier technique. The new constraint is that: 1890 e = (b * ||pssq(0)||) (Constraint 2) 1892 We distinguish two solution regions for the optimization: 1) the 1893 region where the first constraint is fulfilled and 2) the region 1894 where the first constraint is not fulfilled so the second constraint 1895 must be used. 1897 In the first case, where the second constraint is not needed, the 1898 optimized re-estimated vector is simply z, the energy scaled version 1899 of y. 1901 Andersen et. al. Experimental - Expires September 3rd, 2003 37 1902 In the second case, where the second constraint is activated and 1903 becomes an equality constraint, we have that 1905 z= A*y + B*pssq(0) 1907 where 1909 A = sqrt((b-b^2/4)*(w00*w00)/ (w11*w00 + w10*w10)) and 1911 w11 = pssq(0)*pssq(0) 1912 w00 = y*y 1913 w01 = y*pssq(0) (* symbolizes the dot product) 1915 and 1917 B = 1 - b/2 - A * w10/w00 1919 Appendix A.16 contains a listing of a reference implementation for 1920 the enhancement method. 1922 4.7 Synthesis Filtering 1924 Upon decoding or PLC of the LP excitation block, the decoded speech 1925 block is obtained by running the decoded LP synthesis filter, 1926 1/�k(z), over the block. The synthesis filters have to be shifted to 1927 compensate for the delay in the enhancer. For 20 ms frame size mode 1928 they SHOULD be shifted one 40 sample sub block and for 30 ms frame 1929 size mode they SHOULD be shifted two 40 sample sub blocks. The LP 1930 coefficients SHOULD be changed at the first sample of every sub 1931 block while keeping the filter state. For PLC blocks, one solution 1932 is to apply the last LP coefficients of the last decoded speech 1933 block for all sub blocks. 1935 The reference implementation for the synthesis filtering can be 1936 found in Appendix A.48. 1938 4.8 Post Filtering 1940 If desired the decoded block can be filtered by a high-pass filter. 1941 This removes the low frequencies of the decoded signal. A reference 1942 implementation of this, with cut off at 65 Hz, is shown in Appendix 1943 A.30. 1945 5. SECURITY CONSIDERATIONS 1947 This algorithm for the coding of speech signals is not subject of 1948 any known security consideration; however, its RTP payload format 1949 [1] is subject of several considerations which are addressed there. 1951 Andersen et. al. Experimental - Expires September 3rd, 2003 38 1952 6. REFERENCES 1954 [1] A. Duric and S. V. Andersen, "RTP Payload Format for iLBC 1955 Speech", draft-avt-rtp-ilbc-01.txt, March 2003. 1957 [2] S. Bradner, "Key words for use in RFCs to Indicate requirement 1958 Levels", BCP 14, RFC 2119, March 1997. 1960 [3] ITU-T Recommendation G.711, available online from the ITU 1961 bookstore at http://www.itu.int. 1963 7. ACKNOWLEDGEMENTS 1965 The authors wish to thank Henry Sinnreich and Patrik Faltstrom for 1966 great support of the iLBC initiative and for the valuable feedback 1967 and comments. 1969 Andersen et. al. Experimental - Expires September 3rd, 2003 39 1970 8. AUTHOR'S ADDRESSES 1972 Soren Andersen 1973 Department of Communication Technology 1974 Aalborg University 1975 Fredrik Bajers Vej 7A 1976 9200 Aalborg 1977 Denmark 1978 Phone: ++45 9 6358627 1979 Email: sva@kom.auc.dk 1981 Henrik �str�m 1982 Global IP Sound AB 1983 Rosenlundsgatan 54 1984 Stockholm, S-11863 1985 Sweden 1986 Phone: +46 8 54553040 1987 Email: henrik.astrom@globalipsound.com 1989 Alan Duric 1990 Global IP Sound AB 1991 Rosenlundsgatan 54 1992 Stockholm, S-11863 1993 Sweden 1994 Phone: +46 8 54553040 1995 Email: alan.duric@globalipsound.com 1997 Fredrik Galschi�dt 1998 Global IP Sound AB 1999 Rosenlundsgatan 54 2000 Stockholm, S-11863 2001 Sweden 2002 Phone: +46 8 54553040 2003 Email: fredrik.galschiodt@globalipsound.com 2005 Roar Hagen 2006 Global IP Sound AB 2007 Rosenlundsgatan 54 2008 Stockholm, S-11863 2009 Sweden 2010 Phone: +46 8 54553040 2011 Email: roar.hagen@globalipsound.com 2013 W. Bastiaan Kleijn 2014 Global IP Sound AB 2015 Rosenlundsgatan 54 2016 Stockholm, S-11863 2017 Sweden 2018 Phone: +46 8 54553040 2019 Email: bastiaan.kleijn@globalipsound.com 2021 Andersen et. al. Experimental - Expires September 3rd, 2003 40 2022 Jan Linden 2023 Global IP Sound Inc. 2024 900 Kearny Street, suite 500 2025 San Francisco, CA-94133 2026 USA 2027 Phone: +1 415 397 2555 2028 Email: jan.linden@globalipsound.com 2030 Manohar N. Murthi 2031 Department of Electrical and Computer Engineering 2032 University of Miami 2033 McArthur Engineering Building 406 2034 1251 Memorial Dr 2035 Coral Gables, FL 33146-0640 2036 USA 2037 Phone: +1 (305) 284-3342 2038 Email: mmurthi@miami.edu 2040 Jan Skoglund 2041 Global IP Sound Inc. 2042 900 Kearny Street, suite 500 2043 San Francisco, CA-94133 2044 USA 2045 Phone: +1 415 397 2555 2046 Email: jan.skoglund@globalipsound.com 2048 Julian Spittka 2049 Global IP Sound Inc. 2050 900 Kearny Street, suite 500 2051 San Francisco, CA-94133 2052 USA 2053 Phone: +1 415 397 2555 2054 Email: julian.spittka@globalipsound.com 2056 Andersen et. al. Experimental - Expires September 3rd, 2003 41 2057 APPENDIX A REFERENCE IMPLEMENTATION 2059 This appendix contains the complete c-code for a reference 2060 implementation of encoder and decoder for the specified codec. 2062 The c-code consists of the following files with highest level 2063 functions: 2065 iLBC_test.c: main function for evaluation purpose 2066 iLBC_encode.h: encoder header 2067 iLBC_encode.c: encoder function 2068 iLBC_decode.h: decoder header 2069 iLBC_decode.c: decoder function 2071 the following files containing global defines and constants: 2073 iLBC_define.h: global defines 2074 constants.h: global constants header 2075 constants.c: global constants memory allocations 2077 and the following files containing subroutines: 2079 anaFilter.h: lpc analysis filter header 2080 anaFilter.c: lpc analysis filter function 2081 createCB.h: codebook construction header 2082 createCB.c: codebook construction function 2083 doCPLC.h: packet loss concealment header 2084 doCPLC.c: packet loss concealment function 2085 enhancer.h: signal enhancement header 2086 enhancer.c: signal enhancement function 2087 filter.h: general filter header 2088 filter.c: general filter functions 2089 FrameClassify.h: start state classification header 2090 FrameClassify.c: start state classification function 2091 gainquant.h: gain quantization header 2092 gainquant.c: gain quantization function 2093 getCBvec.h: codebook vector construction header 2094 getCBvec.c: codebook vector construction function 2095 helpfun.h: general purpose header 2096 helpfun.c: general purpose functions 2097 hpInput.h: input high pass filter header 2098 hpInput.c: input high pass filter function 2099 hpOutput.h: output high pass filter header 2100 hpOutput.c: output high pass filter function 2101 iCBConstruct.h: excitation decoding header 2102 iCBConstruct.c: excitation decoding function 2103 iCBSearch.h: excitation encoding header 2104 iCBSearch.c: excitation encoding function 2105 LPCdecode.h: lpc decoding header 2106 LPCdecode.c: lpc decoding function 2107 LPCencode.h: lpc encoding header 2108 LPCencode.c: lpc encoding function 2109 lsf.h: line spectral frequencies header 2111 Andersen et. al. Experimental - Expires September 3rd, 2003 42 2112 lsf.c: line spectral frequencies functions 2113 packing.h: bitstream packetization header 2114 packing.c: bitstream packetization functions 2115 StateConstructW.h: state decoding header 2116 StateConstructW.c: state decoding functions 2117 StateSearchW.h: state encoding header 2118 StateSearchW.c: state encoding function 2119 syntFilter.h: lpc synthesis filter header 2120 syntFilter.c: lpc synthesis filter function 2122 The implementation is portable and should work on many different 2123 platforms. However, it is not difficult to optimize the 2124 implementation on particular platforms, an exercise left to the 2125 reader. 2127 A.1 iLBC_test.c 2129 /****************************************************************** 2131 iLBC Speech Coder ANSI-C Source Code 2133 iLBC_test.c 2135 Copyright (c) 2001, 2136 Global IP Sound AB. 2137 All rights reserved. 2139 ******************************************************************/ 2141 #include 2142 #include 2143 #include 2144 #include 2145 #include "iLBC_define.h" 2146 #include "iLBC_encode.h" 2147 #include "iLBC_decode.h" 2149 /* Runtime statistics */ 2150 #include 2152 #define ILBCNOOFWORDS_MAX (NO_OF_BYTES_30MS/2) 2154 /*----------------------------------------------------------------* 2155 * Encoder interface function 2156 *---------------------------------------------------------------*/ 2158 short encode( /* (o) Number of bytes encoded */ 2159 iLBC_Enc_Inst_t *iLBCenc_inst, 2160 /* (i/o) Encoder instance */ 2161 short *encoded_data, /* (o) The encoded bytes */ 2162 short *data /* (i) The signal block to encode */ 2163 ){ 2165 Andersen et. al. Experimental - Expires September 3rd, 2003 43 2166 float block[BLOCKL_MAX]; 2167 int k; 2169 /* convert signal to float */ 2171 for (k=0; kblockl; k++) block[k] = (float)data[k]; 2173 /* do the actual encoding */ 2175 iLBC_encode((unsigned char *)encoded_data, block, iLBCenc_inst); 2177 return (iLBCenc_inst->no_of_bytes); 2178 } 2180 /*----------------------------------------------------------------* 2181 * Decoder interface function 2182 *---------------------------------------------------------------*/ 2184 short decode( /* (o) Number of decoded samples */ 2185 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */ 2186 short *decoded_data, /* (o) Decoded signal block */ 2187 short *encoded_data, /* (i) Encoded bytes */ 2188 short mode /* (i) 0=PL, 1=Normal */ 2189 ){ 2190 int k; 2191 float decblock[BLOCKL_MAX], dtmp; 2193 /* check if mode is valid */ 2195 if (mode<0 || mode>1) { 2196 printf("\nERROR - Wrong mode - 0, 1 allowed\n"); exit(3);} 2198 /* do actual decoding of block */ 2200 iLBC_decode(decblock, (unsigned char *)encoded_data, 2201 iLBCdec_inst, mode); 2203 /* convert to short */ 2205 for (k=0; kblockl; k++){ 2206 dtmp=decblock[k]; 2207 if (dtmpMAX_SAMPLE) 2210 dtmp=MAX_SAMPLE; 2211 decoded_data[k] = (short) dtmp; 2212 } 2214 return (iLBCdec_inst->blockl); 2215 } 2217 /*------------------------------------------------------------------* 2219 Andersen et. al. Experimental - Expires September 3rd, 2003 44 2220 * Main program to test iLBC encoding and decoding 2221 * 2222 * Usage: 2223 * exefile_name.exe 2224 * 2225 * : Input file, speech for encoder (16-bit pcm file) 2226 * : Bit stream output from the encoder 2227 * : Output file, decoded speech (16-bit pcm file) 2228 * : Bit error file, optional (16-bit) 2229 * 1 - Packet received correctly 2230 * 0 - Packet Lost 2231 * 2232 *------------------------------------------------------------------ 2233 */ 2235 int main(int argc, char* argv[]) 2236 { 2238 /* Runtime statistics */ 2240 float starttime; 2241 float runtime; 2242 float outtime; 2244 FILE *ifileid,*efileid,*ofileid, *cfileid; 2245 short data[BLOCKL_MAX]; 2246 short encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX]; 2247 int len; 2248 short pli, mode; 2249 int blockcount = 0; 2250 int packetlosscount = 0; 2252 /* Create structs */ 2253 iLBC_Enc_Inst_t Enc_Inst; 2254 iLBC_Dec_Inst_t Dec_Inst; 2256 /* get arguments and open files */ 2258 if ((argc!=5) && (argc!=6)) { 2259 fprintf(stderr, 2260 "\n*-----------------------------------------------*\n"); 2261 fprintf(stderr, 2262 " %s <20,30> input encoded decoded (channel)\n\n",argv[0]); 2263 fprintf(stderr, 2264 " mode : Frame size for the encoding/decoding\n"); 2265 fprintf(stderr, 2266 " 20 - 20 ms\n"); 2267 fprintf(stderr, 2268 " 30 - 30 ms\n"); 2269 fprintf(stderr, 2270 " input : Speech for encoder (16-bit pcm file)\n"); 2271 fprintf(stderr, 2272 " encoded : Encoded bit stream\n"); 2274 Andersen et. al. Experimental - Expires September 3rd, 2003 45 2275 fprintf(stderr, 2276 " decoded : Decoded speech (16-bit pcm file)\n"); 2277 fprintf(stderr, 2278 " channel : Packet loss pattern, optional (16-bit)\n"); 2279 fprintf(stderr, 2280 " 1 - Packet received correctly\n"); 2281 fprintf(stderr, 2282 " 0 - Packet Lost\n"); 2283 fprintf(stderr, 2284 "*-----------------------------------------------*\n\n"); 2285 exit(1); 2286 } 2287 mode=atoi(argv[1]); 2288 if (mode != 20 && mode != 30) { 2289 fprintf(stderr,"Wrong mode %s, must be 20, or 30\n", 2290 argv[1]); 2291 exit(2); 2292 } 2293 if ( (ifileid=fopen(argv[2],"rb")) == NULL) { 2294 fprintf(stderr,"Cannot open input file %s\n", argv[2]); 2295 exit(2);} 2296 if ( (efileid=fopen(argv[3],"wb")) == NULL) { 2297 fprintf(stderr, "Cannot open encoded file file %s\n", 2298 argv[3]); exit(1);} 2299 if ( (ofileid=fopen(argv[4],"wb")) == NULL) { 2300 fprintf(stderr, "Cannot open decoded file %s\n", 2301 argv[4]); exit(1);} 2302 if (argc==6) { 2303 if( (cfileid=fopen(argv[5],"rb")) == NULL) { 2304 fprintf(stderr, "Cannot open channel file %s\n", 2305 argv[5]); 2306 exit(1); 2307 } 2308 } else { 2309 cfileid=NULL; 2310 } 2312 /* print info */ 2314 fprintf(stderr, "\n"); 2315 fprintf(stderr, 2316 "*---------------------------------------------------*\n"); 2317 fprintf(stderr, 2318 "* *\n"); 2319 fprintf(stderr, 2320 "* iLBC test program *\n"); 2321 fprintf(stderr, 2322 "* *\n"); 2323 fprintf(stderr, 2324 "* *\n"); 2325 fprintf(stderr, 2326 "*---------------------------------------------------*\n"); 2327 fprintf(stderr,"\nMode : %2d ms\n", mode); 2329 Andersen et. al. Experimental - Expires September 3rd, 2003 46 2330 fprintf(stderr,"Input file : %s\n", argv[2]); 2331 fprintf(stderr,"Encoded file : %s\n", argv[3]); 2332 fprintf(stderr,"Output file : %s\n", argv[4]); 2333 if (argc==6) { 2334 fprintf(stderr,"Channel file : %s\n", argv[5]); 2335 } 2336 fprintf(stderr,"\n"); 2338 /* Initialization */ 2340 initEncode(&Enc_Inst, mode); 2341 initDecode(&Dec_Inst, mode, 1); 2343 /* Runtime statistics */ 2345 starttime=clock()/(float)CLOCKS_PER_SEC; 2347 /* loop over input blocks */ 2349 while (fread(data,sizeof(short),Enc_Inst.blockl,ifileid)== 2350 Enc_Inst.blockl) { 2352 blockcount++; 2354 /* encoding */ 2356 fprintf(stderr, "--- Encoding block %i --- ",blockcount); 2357 len=encode(&Enc_Inst, encoded_data, data); 2358 fprintf(stderr, "\r"); 2360 /* write byte file */ 2362 fwrite(encoded_data, sizeof(unsigned char), len, efileid); 2364 /* get channel data if provided */ 2365 if (argc==6) { 2366 if (fread(&pli, sizeof(short), 1, cfileid)) { 2367 if ((pli!=0)&&(pli!=1)) { 2368 fprintf(stderr, "Error in channel file\n"); 2369 exit(0); 2370 } 2371 if (pli==0) { 2372 /* Packet loss -> remove info from frame */ 2373 memset(encoded_data, 0, 2374 sizeof(short)*ILBCNOOFWORDS_MAX); 2375 packetlosscount++; 2376 } 2377 } else { 2378 fprintf(stderr, "Error. Channel file too short\n"); 2379 exit(0); 2380 } 2381 } else { 2382 pli=1; 2384 Andersen et. al. Experimental - Expires September 3rd, 2003 47 2385 } 2387 /* decoding */ 2389 fprintf(stderr, "--- Decoding block %i --- ",blockcount); 2390 len=decode(&Dec_Inst, decoded_data, encoded_data, pli); 2391 fprintf(stderr, "\r"); 2393 /* write output file */ 2395 fwrite(decoded_data,sizeof(short),len,ofileid); 2396 } 2398 /* Runtime statistics */ 2400 runtime = (float)(clock()/(float)CLOCKS_PER_SEC-starttime); 2401 outtime = (float)((float)blockcount*(float)mode/1000.0); 2402 printf("\n\nLength of speech file: %.1f s\n", outtime); 2403 printf("Packet loss : %.1f%%\n", 2404 100.0*(float)packetlosscount/(float)blockcount); 2405 printf("Time to run iLBC :"); 2406 printf(" %.1f s (%.1f %% of realtime)\n\n", runtime, 2407 (100*runtime/outtime)); 2409 /* close files */ 2411 fclose(ifileid); fclose(efileid); fclose(ofileid); 2412 if (argc==5) { 2413 fclose(cfileid); 2414 } 2415 return(0); 2416 } 2418 A.2 iLBC_encode.h 2420 /****************************************************************** 2422 iLBC Speech Coder ANSI-C Source Code 2424 iLBC_encode.h 2426 Copyright (c) 2001, 2427 Global IP Sound AB. 2428 All rights reserved. 2430 ******************************************************************/ 2432 #ifndef __iLBC_ILBCENCODE_H 2433 #define __iLBC_ILBCENCODE_H 2435 #include "iLBC_define.h" 2437 Andersen et. al. Experimental - Expires September 3rd, 2003 48 2438 short initEncode( /* (o) Number of bytes encoded */ 2439 iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */ 2440 int mode /* (i) frame size mode */ 2441 ); 2443 void iLBC_encode( 2444 unsigned char *bytes, /* (o) encoded data bits iLBC */ 2445 float *block, /* (o) speech vector to encode */ 2446 iLBC_Enc_Inst_t *iLBCenc_inst /* (i/o) the general encoder 2447 state */ 2448 ); 2450 #endif 2452 A.3 iLBC_encode.c 2454 /****************************************************************** 2456 iLBC Speech Coder ANSI-C Source Code 2458 iLBC_encode.c 2460 Copyright (c) 2001, 2461 Global IP Sound AB. 2462 All rights reserved. 2464 ******************************************************************/ 2466 #include 2467 #include 2468 #include 2470 #include "iLBC_define.h" 2471 #include "LPCencode.h" 2472 #include "FrameClassify.h" 2473 #include "StateSearchW.h" 2474 #include "StateConstructW.h" 2475 #include "helpfun.h" 2476 #include "constants.h" 2477 #include "packing.h" 2478 #include "iCBSearch.h" 2479 #include "iCBConstruct.h" 2480 #include "hpInput.h" 2481 #include "anaFilter.h" 2482 #include "syntFilter.h" 2484 /*----------------------------------------------------------------* 2485 * Initiation of encoder instance. 2486 *---------------------------------------------------------------*/ 2488 short initEncode( /* (o) Number of bytes encoded */ 2489 iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */ 2491 Andersen et. al. Experimental - Expires September 3rd, 2003 49 2492 int mode /* (i) frame size mode */ 2493 ){ 2494 iLBCenc_inst->mode = mode; 2495 if (mode==30) { 2496 iLBCenc_inst->blockl = BLOCKL_30MS; 2497 iLBCenc_inst->nsub = NSUB_30MS; 2498 iLBCenc_inst->nasub = NASUB_30MS; 2499 iLBCenc_inst->lpc_n = LPC_N_30MS; 2500 iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS; 2501 iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS; 2502 iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS; 2503 /* ULP init */ 2504 iLBCenc_inst->ULP_inst=&ULP_30msTbl; 2505 } 2506 else if (mode==20) { 2507 iLBCenc_inst->blockl = BLOCKL_20MS; 2508 iLBCenc_inst->nsub = NSUB_20MS; 2509 iLBCenc_inst->nasub = NASUB_20MS; 2510 iLBCenc_inst->lpc_n = LPC_N_20MS; 2511 iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS; 2512 iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS; 2513 iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS; 2514 /* ULP init */ 2515 iLBCenc_inst->ULP_inst=&ULP_20msTbl; 2516 } 2517 else { 2518 exit(2); 2519 } 2521 memset((*iLBCenc_inst).anaMem, 0, 2522 LPC_FILTERORDER*sizeof(float)); 2523 memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl, 2524 LPC_FILTERORDER*sizeof(float)); 2525 memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl, 2526 LPC_FILTERORDER*sizeof(float)); 2527 memset((*iLBCenc_inst).lpc_buffer, 0, 2528 (LPC_LOOKBACK+BLOCKL_MAX)*sizeof(float)); 2529 memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float)); 2531 return (iLBCenc_inst->no_of_bytes); 2532 } 2534 /*----------------------------------------------------------------* 2535 * main encoder function 2536 *---------------------------------------------------------------*/ 2538 void iLBC_encode( 2539 unsigned char *bytes, /* (o) encoded data bits iLBC */ 2540 float *block, /* (o) speech vector to encode */ 2541 iLBC_Enc_Inst_t *iLBCenc_inst /* (i/o) the general encoder 2542 state */ 2543 ){ 2545 Andersen et. al. Experimental - Expires September 3rd, 2003 50 2546 float data[BLOCKL_MAX]; 2547 float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX]; 2549 int start, idxForMax, idxVec[STATE_LEN]; 2550 float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML]; 2551 int n, k, meml_gotten, Nfor, Nback, i, pos; 2552 int gain_index[CB_NSTAGES*NASUB_MAX], 2553 extra_gain_index[CB_NSTAGES]; 2554 int cb_index[CB_NSTAGES*NASUB_MAX],extra_cb_index[CB_NSTAGES]; 2555 int lsf_i[LSF_NSPLIT*LPC_N_MAX]; 2556 unsigned char *pbytes; 2557 int diff, start_pos, state_first; 2558 float en1, en2; 2559 int index, ulp, firstpart; 2560 int subcount, subframe; 2561 float weightState[LPC_FILTERORDER]; 2562 float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; 2563 float weightdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; 2564 float decresidual[BLOCKL_MAX]; 2566 /* high pass filtering of input signal if such is not done 2567 prior to calling this function */ 2569 hpInput(block, iLBCenc_inst->blockl, 2570 data, (*iLBCenc_inst).hpimem); 2572 /* otherwise simply copy */ 2574 /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float));*/ 2576 /* LPC of hp filtered input data */ 2578 LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst); 2580 /* inverse filter to get residual */ 2582 for (n=0; nnsub; n++) { 2583 anaFilter(&data[n*SUBL], &syntdenum[n*(LPC_FILTERORDER+1)], 2584 SUBL, &residual[n*SUBL], iLBCenc_inst->anaMem); 2585 } 2587 /* find state location */ 2589 start = FrameClassify(iLBCenc_inst, residual); 2591 /* check if state should be in first or last part of the 2592 two subframes */ 2594 diff = STATE_LEN - iLBCenc_inst->state_short_len; 2595 en1 = 0; 2596 index = (start-1)*SUBL; 2597 for (i = 0; i < iLBCenc_inst->state_short_len; i++) { 2599 Andersen et. al. Experimental - Expires September 3rd, 2003 51 2600 en1 += residual[index+i]*residual[index+i]; 2601 } 2602 en2 = 0; 2603 index = (start-1)*SUBL+diff; 2604 for (i = 0; i < iLBCenc_inst->state_short_len; i++) { 2605 en2 += residual[index+i]*residual[index+i]; 2606 } 2608 if (en1 > en2) { 2609 state_first = 1; 2610 start_pos = (start-1)*SUBL; 2611 } else { 2612 state_first = 0; 2613 start_pos = (start-1)*SUBL + diff; 2614 } 2616 /* scalar quantization of state */ 2618 StateSearchW(iLBCenc_inst, &residual[start_pos], 2619 &syntdenum[(start-1)*(LPC_FILTERORDER+1)], 2620 &weightdenum[(start-1)*(LPC_FILTERORDER+1)], &idxForMax, 2621 idxVec, iLBCenc_inst->state_short_len, state_first); 2623 StateConstructW(idxForMax, idxVec, 2624 &syntdenum[(start-1)*(LPC_FILTERORDER+1)], 2625 &decresidual[start_pos], iLBCenc_inst->state_short_len); 2627 /* predictive quantization in state */ 2629 if (state_first) { /* put adaptive part in the end */ 2631 /* setup memory */ 2633 memset(mem, 0, 2634 (CB_MEML-iLBCenc_inst->state_short_len)*sizeof(float)); 2635 memcpy(mem+CB_MEML-iLBCenc_inst->state_short_len, 2636 decresidual+start_pos, 2637 iLBCenc_inst->state_short_len*sizeof(float)); 2638 memset(weightState, 0, LPC_FILTERORDER*sizeof(float)); 2640 /* encode subframes */ 2642 iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, 2643 &residual[start_pos+iLBCenc_inst->state_short_len], 2644 mem+CB_MEML-stMemLTbl, 2645 stMemLTbl, diff, CB_NSTAGES, 2646 &weightdenum[start*(LPC_FILTERORDER+1)], weightState, 0); 2648 /* construct decoded vector */ 2650 iCBConstruct( 2651 &decresidual[start_pos+iLBCenc_inst->state_short_len], 2653 Andersen et. al. Experimental - Expires September 3rd, 2003 52 2654 extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl, 2655 stMemLTbl, diff, CB_NSTAGES); 2657 } 2658 else { /* put adaptive part in the beginning */ 2660 /* create reversed vectors for prediction */ 2662 for (k=0; kstate_short_len)]; 2665 } 2667 /* setup memory */ 2669 meml_gotten = iLBCenc_inst->state_short_len; 2670 for (k=0; knsub-start-1; 2704 if ( Nfor > 0 ) { 2706 Andersen et. al. Experimental - Expires September 3rd, 2003 53 2707 /* setup memory */ 2709 memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float)); 2710 memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, 2711 STATE_LEN*sizeof(float)); 2712 memset(weightState, 0, LPC_FILTERORDER*sizeof(float)); 2714 /* loop over subframes to encode */ 2716 for (subframe=0; subframe 0 ) { 2754 /* create reverse order vectors */ 2756 for (n=0; nnsub+1-start); 2771 if ( meml_gotten > CB_MEML ) { 2772 meml_gotten=CB_MEML; 2773 } 2774 for (k=0; klpc_n; k++) { 2838 packsplit(&lsf_i[k], &firstpart, &lsf_i[k], 2839 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], 2840 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp]+ 2841 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+1]+ 2842 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+2]); 2843 dopack( &pbytes, firstpart, 2844 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos); 2845 } 2847 /* Start block info */ 2849 packsplit(&start, &firstpart, &start, 2850 iLBCenc_inst->ULP_inst->start_bits[ulp], 2851 iLBCenc_inst->ULP_inst->start_bits[ulp]+ 2852 iLBCenc_inst->ULP_inst->start_bits[ulp+1]+ 2853 iLBCenc_inst->ULP_inst->start_bits[ulp+2]); 2854 dopack( &pbytes, firstpart, 2855 iLBCenc_inst->ULP_inst->start_bits[ulp], &pos); 2857 packsplit(&state_first, &firstpart, &state_first, 2858 iLBCenc_inst->ULP_inst->startfirst_bits[ulp], 2859 iLBCenc_inst->ULP_inst->startfirst_bits[ulp]+ 2860 iLBCenc_inst->ULP_inst->startfirst_bits[ulp+1]+ 2861 iLBCenc_inst->ULP_inst->startfirst_bits[ulp+2]); 2862 dopack( &pbytes, firstpart, 2863 iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos); 2865 packsplit(&idxForMax, &firstpart, &idxForMax, 2867 Andersen et. al. Experimental - Expires September 3rd, 2003 56 2868 iLBCenc_inst->ULP_inst->scale_bits[ulp], 2869 iLBCenc_inst->ULP_inst->scale_bits[ulp]+ 2870 iLBCenc_inst->ULP_inst->scale_bits[ulp+1]+ 2871 iLBCenc_inst->ULP_inst->scale_bits[ulp+2]); 2872 dopack( &pbytes, firstpart, 2873 iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos); 2875 for (k=0; kstate_short_len; k++) { 2876 packsplit(idxVec+k, &firstpart, idxVec+k, 2877 iLBCenc_inst->ULP_inst->state_bits[ulp], 2878 iLBCenc_inst->ULP_inst->state_bits[ulp]+ 2879 iLBCenc_inst->ULP_inst->state_bits[ulp+1]+ 2880 iLBCenc_inst->ULP_inst->state_bits[ulp+2]); 2881 dopack( &pbytes, firstpart, 2882 iLBCenc_inst->ULP_inst->state_bits[ulp], &pos); 2883 } 2885 /* 23/22 (20ms/30ms) sample block */ 2887 for (k=0;kULP_inst->extra_cb_index[k][ulp], 2891 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp]+ 2892 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+1]+ 2893 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+2]); 2894 dopack( &pbytes, firstpart, 2895 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], 2896 &pos); 2897 } 2899 for (k=0;kULP_inst->extra_cb_gain[k][ulp], 2903 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp]+ 2904 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+1]+ 2905 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+2]); 2906 dopack( &pbytes, firstpart, 2907 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], 2908 &pos); 2909 } 2911 /* The two/four (20ms/30ms) 40 sample sub blocks */ 2913 for (i=0; inasub; i++) { 2914 for (k=0; kULP_inst->cb_index[i][k][ulp], 2918 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp]+ 2919 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+1]+ 2920 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+2]); 2922 Andersen et. al. Experimental - Expires September 3rd, 2003 57 2923 dopack( &pbytes, firstpart, 2924 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], 2925 &pos); 2926 } 2927 } 2929 for (i=0; inasub; i++) { 2930 for (k=0; kULP_inst->cb_gain[i][k][ulp], 2934 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp]+ 2935 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+1]+ 2936 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+2]); 2937 dopack( &pbytes, firstpart, 2938 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], 2939 &pos); 2940 } 2941 } 2942 } 2944 /* set the last unused bit to zero */ 2945 dopack( &pbytes, 0, 1, &pos); 2946 } 2948 A.4 iLBC_decode.h 2950 /****************************************************************** 2952 iLBC Speech Coder ANSI-C Source Code 2954 iLBC_decode.h 2956 Copyright (c) 2001, 2957 Global IP Sound AB. 2958 All rights reserved. 2960 ******************************************************************/ 2962 #ifndef __iLBC_ILBCDECODE_H 2963 #define __iLBC_ILBCDECODE_H 2965 #include "iLBC_define.h" 2967 short initDecode( /* (o) Number of decoded 2968 samples */ 2969 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */ 2970 int mode, /* (i) frame size mode */ 2971 int use_enhancer /* (i) 1 to use enhancer 2972 0 to run without 2973 enhancer */ 2974 ); 2976 Andersen et. al. Experimental - Expires September 3rd, 2003 58 2977 void iLBC_decode( 2978 float *decblock, /* (o) decoded signal block */ 2979 unsigned char *bytes, /* (i) encoded signal bits */ 2980 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state 2981 structure */ 2982 int mode /* (i) 0: bad packet, PLC, 2983 1: normal */ 2984 ); 2986 #endif 2988 A.5 iLBC_decode.c 2990 /****************************************************************** 2992 iLBC Speech Coder ANSI-C Source Code 2994 iLBC_decode.c 2996 Copyright (c) 2001, 2997 Global IP Sound AB. 2998 All rights reserved. 3000 ******************************************************************/ 3002 #include 3003 #include 3005 #include "iLBC_define.h" 3006 #include "StateConstructW.h" 3007 #include "LPCdecode.h" 3008 #include "iCBConstruct.h" 3009 #include "doCPLC.h" 3010 #include "helpfun.h" 3011 #include "constants.h" 3012 #include "packing.h" 3013 #include "string.h" 3014 #include "enhancer.h" 3015 #include "hpOutput.h" 3016 #include "syntFilter.h" 3018 /*----------------------------------------------------------------* 3019 * Initiation of decoder instance. 3020 *---------------------------------------------------------------*/ 3022 short initDecode( /* (o) Number of decoded 3023 samples */ 3024 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */ 3025 int mode, /* (i) frame size mode */ 3026 int use_enhancer /* (i) 1 to use enhancer 3027 0 to run without 3029 Andersen et. al. Experimental - Expires September 3rd, 2003 59 3030 enhancer */ 3031 ){ 3032 int i; 3034 iLBCdec_inst->mode = mode; 3036 if (mode==30) { 3037 iLBCdec_inst->blockl = BLOCKL_30MS; 3038 iLBCdec_inst->nsub = NSUB_30MS; 3039 iLBCdec_inst->nasub = NASUB_30MS; 3040 iLBCdec_inst->lpc_n = LPC_N_30MS; 3041 iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS; 3042 iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS; 3043 iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS; 3044 /* ULP init */ 3045 iLBCdec_inst->ULP_inst=&ULP_30msTbl; 3046 } 3047 else if (mode==20) { 3048 iLBCdec_inst->blockl = BLOCKL_20MS; 3049 iLBCdec_inst->nsub = NSUB_20MS; 3050 iLBCdec_inst->nasub = NASUB_20MS; 3051 iLBCdec_inst->lpc_n = LPC_N_20MS; 3052 iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS; 3053 iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS; 3054 iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS; 3055 /* ULP init */ 3056 iLBCdec_inst->ULP_inst=&ULP_20msTbl; 3057 } 3058 else { 3059 exit(2); 3060 } 3062 memset(iLBCdec_inst->syntMem, 0, 3063 LPC_FILTERORDER*sizeof(float)); 3064 memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl, 3065 LPC_FILTERORDER*sizeof(float)); 3067 memset(iLBCdec_inst->old_syntdenum, 0, 3068 ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float)); 3069 for (i=0; iold_syntdenum[i*(LPC_FILTERORDER+1)]=1.0; 3072 iLBCdec_inst->last_lag = 20; 3074 iLBCdec_inst->prevLag = 120; 3075 iLBCdec_inst->per = 0.0; 3076 iLBCdec_inst->consPLICount = 0; 3077 iLBCdec_inst->prevPLI = 0; 3078 iLBCdec_inst->prevLpc[0] = 1.0; 3079 memset(iLBCdec_inst->prevLpc+1,0, 3080 LPC_FILTERORDER*sizeof(float)); 3081 memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float)); 3082 iLBCdec_inst->seed=777; 3084 Andersen et. al. Experimental - Expires September 3rd, 2003 60 3085 memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float)); 3087 iLBCdec_inst->use_enhancer = use_enhancer; 3088 memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float)); 3089 for (i=0;ienh_period[i]=(float)40.0; 3092 iLBCdec_inst->prev_enh_pl = 0; 3094 return (iLBCdec_inst->blockl); 3095 } 3097 /*----------------------------------------------------------------* 3098 * frame residual decoder function (subrutine to iLBC_decode) 3099 *---------------------------------------------------------------*/ 3101 void Decode( 3102 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state 3103 structure */ 3104 float *decresidual, /* (o) decoded residual frame */ 3105 int start, /* (i) location of start state */ 3106 int idxForMax, /* (i) codebook index for the 3107 maximum value */ 3108 int *idxVec, /* (i) codebook indexes for the 3109 samples in the start 3110 state */ 3111 float *syntdenum, /* (i) the decoded synthesis 3112 filter coefficients */ 3113 int *cb_index, /* (i) the indexes for the 3114 adaptive codebook */ 3115 int *gain_index, /* (i) the indexes for the 3116 corresponding gains */ 3117 int *extra_cb_index, /* (i) the indexes for the 3118 adaptive codebook part 3119 of start state */ 3120 int *extra_gain_index, /* (i) the indexes for the 3121 corresponding gains */ 3122 int state_first /* (i) 1 if non adaptive part 3123 of start state comes first 3124 0 if that part comes 3125 last */ 3126 ){ 3127 float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML]; 3128 int k, meml_gotten, Nfor, Nback, i; 3129 int diff, start_pos; 3130 int subcount, subframe; 3132 diff = STATE_LEN - iLBCdec_inst->state_short_len; 3134 if (state_first == 1) { 3135 start_pos = (start-1)*SUBL; 3136 } else { 3138 Andersen et. al. Experimental - Expires September 3rd, 2003 61 3139 start_pos = (start-1)*SUBL + diff; 3140 } 3142 /* decode scalar part of start state */ 3144 StateConstructW(idxForMax, idxVec, 3145 &syntdenum[(start-1)*(LPC_FILTERORDER+1)], 3146 &decresidual[start_pos], iLBCdec_inst->state_short_len); 3148 if (state_first) { /* put adaptive part in the end */ 3150 /* setup memory */ 3152 memset(mem, 0, 3153 (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float)); 3154 memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len, 3155 decresidual+start_pos, 3156 iLBCdec_inst->state_short_len*sizeof(float)); 3158 /* construct decoded vector */ 3160 iCBConstruct( 3161 &decresidual[start_pos+iLBCdec_inst->state_short_len], 3162 extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl, 3163 stMemLTbl, diff, CB_NSTAGES); 3165 } 3166 else {/* put adaptive part in the beginning */ 3168 /* create reversed vectors for prediction */ 3170 for (k=0; kstate_short_len)]; 3174 } 3176 /* setup memory */ 3178 meml_gotten = iLBCdec_inst->state_short_len; 3179 for (k=0; knsub-start-1; 3206 if ( Nfor > 0 ){ 3208 /* setup memory */ 3210 memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float)); 3211 memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, 3212 STATE_LEN*sizeof(float)); 3214 /* loop over subframes to encode */ 3216 for (subframe=0; subframe 0 ) { 3245 Andersen et. al. Experimental - Expires September 3rd, 2003 63 3246 /* setup memory */ 3248 meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start); 3250 if ( meml_gotten > CB_MEML ) { 3251 meml_gotten=CB_MEML; 3252 } 3253 for (k=0; k0) { /* the data are good */ 3324 /* decode data */ 3326 pbytes=bytes; 3327 pos=0; 3329 /* Set everything to zero before decoding */ 3331 for (k=0; kstate_short_len; k++) { 3338 idxVec[k]=0; 3339 } 3340 for (k=0; knasub; i++) { 3347 for (k=0; knasub; i++) { 3352 for (k=0; klpc_n; k++){ 3365 unpack( &pbytes, &lastpart, 3366 iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos); 3367 packcombine(&lsf_i[k], lastpart, 3368 iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]); 3369 } 3371 /* Start block info */ 3373 unpack( &pbytes, &lastpart, 3374 iLBCdec_inst->ULP_inst->start_bits[ulp], &pos); 3375 packcombine(&start, lastpart, 3376 iLBCdec_inst->ULP_inst->start_bits[ulp]); 3378 unpack( &pbytes, &lastpart, 3379 iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos); 3380 packcombine(&state_first, lastpart, 3381 iLBCdec_inst->ULP_inst->startfirst_bits[ulp]); 3383 unpack( &pbytes, &lastpart, 3384 iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos); 3385 packcombine(&idxForMax, lastpart, 3386 iLBCdec_inst->ULP_inst->scale_bits[ulp]); 3388 for (k=0; kstate_short_len; k++) { 3389 unpack( &pbytes, &lastpart, 3390 iLBCdec_inst->ULP_inst->state_bits[ulp], &pos); 3391 packcombine(idxVec+k, lastpart, 3392 iLBCdec_inst->ULP_inst->state_bits[ulp]); 3393 } 3395 /* 23/22 (20ms/30ms) sample block */ 3397 for (k=0; kULP_inst->extra_cb_index[k][ulp], 3400 &pos); 3401 packcombine(extra_cb_index+k, lastpart, 3402 iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]); 3403 } 3404 for (k=0; kULP_inst->extra_cb_gain[k][ulp], 3407 &pos); 3408 packcombine(extra_gain_index+k, lastpart, 3410 Andersen et. al. Experimental - Expires September 3rd, 2003 66 3411 iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]); 3412 } 3414 /* The two/four (20ms/30ms) 40 sample sub blocks */ 3416 for (i=0; inasub; i++) { 3417 for (k=0; kULP_inst->cb_index[i][k][ulp], 3420 &pos); 3421 packcombine(cb_index+i*CB_NSTAGES+k, lastpart, 3422 iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]); 3423 } 3424 } 3426 for (i=0; inasub; i++) { 3427 for (k=0; kULP_inst->cb_gain[i][k][ulp], 3430 &pos); 3431 packcombine(gain_index+i*CB_NSTAGES+k, lastpart, 3432 iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]); 3433 } 3434 } 3435 } 3437 /* Check for bit errors */ 3438 if (start<1) 3439 mode = 0; 3440 if (iLBCdec_inst->mode==20 && start>3) 3441 mode = 0; 3442 if (iLBCdec_inst->mode==30 && start>5) 3443 mode = 0; 3445 if (mode==1) { /* No bit errors was detected, 3446 continue decoding */ 3448 /* adjust index */ 3449 index_conv_dec(cb_index); 3451 /* decode the lsf */ 3453 SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n); 3454 check=LSF_check(lsfdeq, LPC_FILTERORDER, 3455 iLBCdec_inst->lpc_n); 3456 DecoderInterpolateLSF(syntdenum, weightdenum, 3457 lsfdeq, LPC_FILTERORDER, iLBCdec_inst); 3459 Decode(iLBCdec_inst, decresidual, start, idxForMax, 3460 idxVec, syntdenum, cb_index, gain_index, 3461 extra_cb_index, extra_gain_index, 3462 state_first); 3464 Andersen et. al. Experimental - Expires September 3rd, 2003 67 3465 /* preparing the plc for a future loss! */ 3467 doThePLC(PLCresidual, PLClpc, 0, decresidual, 3468 syntdenum + 3469 (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1), 3470 (*iLBCdec_inst).last_lag, iLBCdec_inst); 3472 memcpy(decresidual, PLCresidual, 3473 iLBCdec_inst->blockl*sizeof(float)); 3474 } 3476 } 3478 if (mode == 0) { 3479 /* the data is bad (either a PLC call 3480 * was made or a severe bit error was detected) 3481 */ 3483 /* packet loss conceal */ 3485 memset(zeros, 0, BLOCKL_MAX*sizeof(float)); 3487 one[0] = 1; 3488 memset(one+1, 0, LPC_FILTERORDER*sizeof(float)); 3490 start=0; 3492 doThePLC(PLCresidual, PLClpc, 1, zeros, one, 3493 (*iLBCdec_inst).last_lag, iLBCdec_inst); 3494 memcpy(decresidual, PLCresidual, 3495 iLBCdec_inst->blockl*sizeof(float)); 3497 order_plus_one = LPC_FILTERORDER + 1; 3498 for (i = 0; i < iLBCdec_inst->nsub; i++) { 3499 memcpy(syntdenum+(i*order_plus_one), PLClpc, 3500 order_plus_one*sizeof(float)); 3501 } 3502 } 3504 if (iLBCdec_inst->use_enhancer == 1) { 3506 /* post filtering */ 3508 iLBCdec_inst->last_lag = 3509 enhancerInterface(data, decresidual, iLBCdec_inst); 3511 /* synthesis filtering */ 3513 if (iLBCdec_inst->mode==20) { 3514 /* Enhancer has 40 samples delay */ 3515 i=0; 3516 syntFilter(data + i*SUBL, 3518 Andersen et. al. Experimental - Expires September 3rd, 2003 68 3519 iLBCdec_inst->old_syntdenum + 3520 (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1), SUBL, 3521 iLBCdec_inst->syntMem); 3522 for (i=1; i < iLBCdec_inst->nsub; i++) { 3523 syntFilter(data + i*SUBL, 3524 syntdenum + (i-1)*(LPC_FILTERORDER+1), SUBL, 3525 iLBCdec_inst->syntMem); 3526 } 3527 } else if (iLBCdec_inst->mode==30) { 3528 /* Enhancer has 80 samples delay */ 3529 for (i=0; i < 2; i++) { 3530 syntFilter(data + i*SUBL, 3531 iLBCdec_inst->old_syntdenum + 3532 (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1), 3533 SUBL, iLBCdec_inst->syntMem); 3534 } 3535 for (i=2; i < iLBCdec_inst->nsub; i++) { 3536 syntFilter(data + i*SUBL, 3537 syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL, 3538 iLBCdec_inst->syntMem); 3539 } 3540 } 3542 } else { 3544 /* Find last lag */ 3545 lag = 20; 3546 maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], 3547 &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL); 3549 for (ilag=21; ilag<120; ilag++) { 3550 cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], 3551 &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag], 3552 ENH_BLOCKL); 3554 if (cc > maxcc) { 3555 maxcc = cc; 3556 lag = ilag; 3557 } 3558 } 3559 iLBCdec_inst->last_lag = lag; 3561 /* copy data and run synthesis filter */ 3563 memcpy(data, decresidual, 3564 iLBCdec_inst->blockl*sizeof(float)); 3565 for (i=0; i < iLBCdec_inst->nsub; i++) { 3566 syntFilter(data + i*SUBL, 3567 syntdenum + i*(LPC_FILTERORDER+1), SUBL, 3568 iLBCdec_inst->syntMem); 3569 } 3570 } 3572 Andersen et. al. Experimental - Expires September 3rd, 2003 69 3573 /* high pass filtering on output if desired, otherwise 3574 copy to out */ 3576 hpOutput(data, iLBCdec_inst->blockl, 3577 decblock,iLBCdec_inst->hpomem); 3579 /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/ 3581 memcpy(iLBCdec_inst->old_syntdenum, syntdenum, 3582 iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float)); 3584 iLBCdec_inst->prev_enh_pl=0; 3586 if (mode==0) { /* PLC was used */ 3587 iLBCdec_inst->prev_enh_pl=1; 3588 } 3589 } 3591 A.6 iLBC_define.h 3593 /****************************************************************** 3595 iLBC Speech Coder ANSI-C Source Code 3597 iLBC_define.h 3599 Copyright (c) 2001, 3600 Global IP Sound AB. 3601 All rights reserved. 3603 ******************************************************************/ 3604 #include 3606 #ifndef __iLBC_ILBCDEFINE_H 3607 #define __iLBC_ILBCDEFINE_H 3609 /* general codec settings */ 3611 #define FS (float)8000.0 3612 #define BLOCKL_20MS 160 3613 #define BLOCKL_30MS 240 3614 #define BLOCKL_MAX 240 3615 #define NSUB_20MS 4 3616 #define NSUB_30MS 6 3617 #define NSUB_MAX 6 3618 #define NASUB_20MS 2 3619 #define NASUB_30MS 4 3620 #define NASUB_MAX 4 3621 #define SUBL 40 3622 #define STATE_LEN 80 3623 #define STATE_SHORT_LEN_30MS58 3624 #define STATE_SHORT_LEN_20MS57 3626 Andersen et. al. Experimental - Expires September 3rd, 2003 70 3627 /* LPC settings */ 3629 #define LPC_FILTERORDER 10 3630 #define LPC_CHIRP_SYNTDENUM (float)0.9025 3631 #define LPC_CHIRP_WEIGHTDENUM (float)0.4222 3632 #define LPC_LOOKBACK 60 3633 #define LPC_N_20MS 1 3634 #define LPC_N_30MS 2 3635 #define LPC_N_MAX 2 3636 #define LPC_ASYMDIFF 20 3637 #define LPC_BW (float)60.0 3638 #define LPC_WN (float)1.0001 3639 #define LSF_NSPLIT 3 3640 #define LSF_NUMBER_OF_STEPS 4 3641 #define LPC_HALFORDER (LPC_FILTERORDER/2) 3643 /* cb settings */ 3645 #define CB_NSTAGES 3 3646 #define CB_EXPAND 2 3647 #define CB_MEML 147 3648 #define CB_FILTERLEN 2*4 3649 #define CB_HALFFILTERLEN 4 3650 #define CB_RESRANGE 34 3651 #define CB_MAXGAIN (float)1.3 3653 /* enhancer */ 3655 #define ENH_BLOCKL 80 /* block length */ 3656 #define ENH_BLOCKL_HALF (ENH_BLOCKL/2) 3657 #define ENH_HL 3 /* 2*ENH_HL+1 is number blocks 3658 in said second sequence */ 3659 #define ENH_SLOP 2 /* max difference estimated and 3660 correct pitch period */ 3661 #define ENH_PLOCSL 20 /* pitch-estimates and pitch- 3662 locations buffer length */ 3663 #define ENH_OVERHANG 2 3664 #define ENH_UPS0 4 /* upsampling rate */ 3665 #define ENH_FL0 3 /* 2*FLO+1 is the length of 3666 each filter */ 3667 #define ENH_VECTL (ENH_BLOCKL+2*ENH_FL0) 3668 #define ENH_CORRDIM (2*ENH_SLOP+1) 3669 #define ENH_NBLOCKS (BLOCKL_MAX/ENH_BLOCKL) 3670 #define ENH_NBLOCKS_EXTRA 5 3671 #define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS + 3672 ENH_NBLOCKS_EXTRA */ 3673 #define ENH_BUFL (ENH_NBLOCKS_TOT)*ENH_BLOCKL 3674 #define ENH_ALPHA0 (float)0.05 3676 /* PLC */ 3678 Andersen et. al. Experimental - Expires September 3rd, 2003 71 3679 #define PLC_BWEXPAND (float)0.99 3681 /* Down sampling */ 3683 #define FILTERORDER_DS 7 3684 #define DELAY_DS 3 3685 #define FACTOR_DS 2 3687 /* bit stream defs */ 3689 #define NO_OF_BYTES_20MS 38 3690 #define NO_OF_BYTES_30MS 50 3691 #define NO_OF_WORDS_20MS 19 3692 #define NO_OF_WORDS_30MS 25 3693 #define STATE_BITS 3 3694 #define BYTE_LEN 8 3695 #define ULP_CLASSES 3 3697 /* help parameters */ 3699 #define FLOAT_MAX (float)1.0e37 3700 #define EPS (float)2.220446049250313e-016 3701 #define PI (float)3.14159265358979323846 3702 #define MIN_SAMPLE -32768 3703 #define MAX_SAMPLE 32767 3704 #define TWO_PI (float)6.283185307 3705 #define PI2 (float)0.159154943 3707 /* type definition encoder instance */ 3708 typedef struct iLBC_ULP_Inst_t_ { 3709 int lsf_bits[6][ULP_CLASSES+2]; 3710 int start_bits[ULP_CLASSES+2]; 3711 int startfirst_bits[ULP_CLASSES+2]; 3712 int scale_bits[ULP_CLASSES+2]; 3713 int state_bits[ULP_CLASSES+2]; 3714 int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2]; 3715 int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2]; 3716 int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2]; 3717 int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2]; 3718 } iLBC_ULP_Inst_t; 3720 /* type definition encoder instance */ 3721 typedef struct iLBC_Enc_Inst_t_ { 3723 /* flag for frame size mode */ 3724 int mode; 3726 /* basic parameters for different frame sizes */ 3727 int blockl; 3728 int nsub; 3729 int nasub; 3730 int no_of_bytes, no_of_words; 3731 int lpc_n; 3733 Andersen et. al. Experimental - Expires September 3rd, 2003 72 3734 int state_short_len; 3735 const iLBC_ULP_Inst_t *ULP_inst; 3737 /* analysis filter state */ 3738 float anaMem[LPC_FILTERORDER]; 3740 /* old lsf parameters for interpolation */ 3741 float lsfold[LPC_FILTERORDER]; 3742 float lsfdeqold[LPC_FILTERORDER]; 3744 /* signal buffer for LP analysis */ 3745 float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX]; 3747 /* state of input HP filter */ 3748 float hpimem[4]; 3750 } iLBC_Enc_Inst_t; 3752 /* type definition decoder instance */ 3753 typedef struct iLBC_Dec_Inst_t_ { 3755 /* flag for frame size mode */ 3756 int mode; 3758 /* basic parameters for different frame sizes */ 3759 int blockl; 3760 int nsub; 3761 int nasub; 3762 int no_of_bytes, no_of_words; 3763 int lpc_n; 3764 int state_short_len; 3765 const iLBC_ULP_Inst_t *ULP_inst; 3767 /* synthesis filter state */ 3768 float syntMem[LPC_FILTERORDER]; 3770 /* old LSF for interpolation */ 3771 float lsfdeqold[LPC_FILTERORDER]; 3773 /* pitch lag estimated in enhancer and used in PLC */ 3774 int last_lag; 3776 /* PLC state information */ 3777 int prevLag, consPLICount, prevPLI, prev_enh_pl; 3778 float prevLpc[LPC_FILTERORDER+1]; 3779 float prevResidual[NSUB_MAX*SUBL]; 3780 float per; 3781 unsigned long seed; 3783 /* previous synthesis filter parameters */ 3784 float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX]; 3786 /* state of output HP filter */ 3788 Andersen et. al. Experimental - Expires September 3rd, 2003 73 3789 float hpomem[4]; 3791 /* enhancer state information */ 3792 int use_enhancer; 3793 float enh_buf[ENH_BUFL]; 3794 float enh_period[ENH_NBLOCKS_TOT]; 3796 } iLBC_Dec_Inst_t; 3798 #endif 3800 A.7 constants.h 3802 /****************************************************************** 3804 iLBC Speech Coder ANSI-C Source Code 3806 constants.h 3808 Copyright (c) 2001, 3809 Global IP Sound AB. 3810 All rights reserved. 3812 ******************************************************************/ 3814 #ifndef __iLBC_CONSTANTS_H 3815 #define __iLBC_CONSTANTS_H 3817 #include "iLBC_define.h" 3819 /* ULP bit allocation */ 3821 extern const iLBC_ULP_Inst_t ULP_20msTbl; 3822 extern const iLBC_ULP_Inst_t ULP_30msTbl; 3824 /* high pass filters */ 3826 extern float hpi_zero_coefsTbl[]; 3827 extern float hpi_pole_coefsTbl[]; 3828 extern float hpo_zero_coefsTbl[]; 3829 extern float hpo_pole_coefsTbl[]; 3831 /* low pass filters */ 3832 extern float lpFilt_coefsTbl[]; 3834 /* LPC analysis and quantization */ 3836 extern float lpc_winTbl[]; 3837 extern float lpc_asymwinTbl[]; 3838 extern float lpc_lagwinTbl[]; 3839 extern float lsfCbTbl[]; 3841 Andersen et. al. Experimental - Expires September 3rd, 2003 74 3842 extern float lsfmeanTbl[]; 3843 extern int dim_lsfCbTbl[]; 3844 extern int size_lsfCbTbl[]; 3845 extern float lsf_weightTbl_30ms[]; 3846 extern float lsf_weightTbl_20ms[]; 3848 /* state quantization tables */ 3850 extern float state_sq3Tbl[]; 3851 extern float state_frgqTbl[]; 3853 /* gain quantization tables */ 3855 extern float gain_sq3Tbl[]; 3856 extern float gain_sq4Tbl[]; 3857 extern float gain_sq5Tbl[]; 3859 /* adaptive codebook definitions */ 3861 extern int search_rangeTbl[5][CB_NSTAGES]; 3862 extern int memLfTbl[]; 3863 extern int stMemLTbl; 3864 extern float cbfiltersTbl[CB_FILTERLEN]; 3866 /* enhancer definitions */ 3868 extern float polyphaserTbl[]; 3869 extern float enh_plocsTbl[]; 3871 #endif 3873 A.8 constants.c 3875 /****************************************************************** 3877 iLBC Speech Coder ANSI-C Source Code 3879 constants.c 3881 Copyright (c) 2001, 3882 Global IP Sound AB. 3883 All rights reserved. 3885 ******************************************************************/ 3887 #include "iLBC_define.h" 3889 /* ULP bit allocation */ 3891 /* 20 ms frame */ 3893 const iLBC_ULP_Inst_t ULP_20msTbl = { 3894 /* LSF */ 3896 Andersen et. al. Experimental - Expires September 3rd, 2003 75 3897 { {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, 3898 {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}, 3899 /* Start state location, gain and samples */ 3900 {2,0,0,0,0}, 3901 {1,0,0,0,0}, 3902 {6,0,0,0,0}, 3903 {0,1,2,0,0}, 3904 /* extra CB index and extra CB gain */ 3905 {{6,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 3906 {{2,0,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}}, 3907 /* CB index and CB gain */ 3908 { {{7,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 3909 {{0,0,8,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}, 3910 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}, 3911 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}}, 3912 { {{1,2,2,0,0}, {1,1,2,0,0}, {0,0,3,0,0}}, 3913 {{1,1,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}}, 3914 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}, 3915 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}} 3916 }; 3918 /* 30 ms frame */ 3920 const iLBC_ULP_Inst_t ULP_30msTbl = { 3921 /* LSF */ 3922 { {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, 3923 {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}}, 3924 /* Start state location, gain and samples */ 3925 {3,0,0,0,0}, 3926 {1,0,0,0,0}, 3927 {6,0,0,0,0}, 3928 {0,1,2,0,0}, 3929 /* extra CB index and extra CB gain */ 3930 {{4,2,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 3931 {{1,1,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}}, 3932 /* CB index and CB gain */ 3933 { {{6,1,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 3934 {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}, 3935 {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}, 3936 {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}}, 3937 { {{1,2,2,0,0}, {1,2,1,0,0}, {0,0,3,0,0}}, 3938 {{0,2,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}}, 3939 {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}, 3940 {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}} 3941 }; 3943 /* HP Filters */ 3945 float hpi_zero_coefsTbl[3] = { 3946 (float)0.92727436, (float)-1.8544941, (float)0.92727436 3947 }; 3948 float hpi_pole_coefsTbl[3] = { 3949 (float)1.0, (float)-1.9059465, (float)0.9114024 3951 Andersen et. al. Experimental - Expires September 3rd, 2003 76 3952 }; 3953 float hpo_zero_coefsTbl[3] = { 3954 (float)0.93980581, (float)-1.8795834, (float)0.93980581 3955 }; 3956 float hpo_pole_coefsTbl[3] = { 3957 (float)1.0, (float)-1.9330735, (float)0.93589199 3958 }; 3960 /* LP Filter */ 3962 float lpFilt_coefsTbl[FILTERORDER_DS]={ 3963 (float)-0.066650, (float)0.125000, (float)0.316650, 3964 (float)0.414063, (float)0.316650, 3965 (float)0.125000, (float)-0.066650 3966 }; 3968 /* State quantization tables */ 3970 float state_sq3Tbl[8] = { 3971 (float)-3.719849, (float)-2.177490, (float)-1.130005, 3972 (float)-0.309692, (float)0.444214, (float)1.329712, 3973 (float)2.436279, (float)3.983887 3974 }; 3976 float state_frgqTbl[64] = { 3977 (float)1.000085, (float)1.071695, (float)1.140395, 3978 (float)1.206868, (float)1.277188, (float)1.351503, 3979 (float)1.429380, (float)1.500727, (float)1.569049, 3980 (float)1.639599, (float)1.707071, (float)1.781531, 3981 (float)1.840799, (float)1.901550, (float)1.956695, 3982 (float)2.006750, (float)2.055474, (float)2.102787, 3983 (float)2.142819, (float)2.183592, (float)2.217962, 3984 (float)2.257177, (float)2.295739, (float)2.332967, 3985 (float)2.369248, (float)2.402792, (float)2.435080, 3986 (float)2.468598, (float)2.503394, (float)2.539284, 3987 (float)2.572944, (float)2.605036, (float)2.636331, 3988 (float)2.668939, (float)2.698780, (float)2.729101, 3989 (float)2.759786, (float)2.789834, (float)2.818679, 3990 (float)2.848074, (float)2.877470, (float)2.906899, 3991 (float)2.936655, (float)2.967804, (float)3.000115, 3992 (float)3.033367, (float)3.066355, (float)3.104231, 3993 (float)3.141499, (float)3.183012, (float)3.222952, 3994 (float)3.265433, (float)3.308441, (float)3.350823, 3995 (float)3.395275, (float)3.442793, (float)3.490801, 3996 (float)3.542514, (float)3.604064, (float)3.666050, 3997 (float)3.740994, (float)3.830749, (float)3.938770, 3998 (float)4.101764 3999 }; 4001 /* CB tables */ 4003 int search_rangeTbl[5][CB_NSTAGES]={{58,58,58}, {108,44,44}, 4004 {108,108,108}, {108,108,108}, {108,108,108}}; 4006 Andersen et. al. Experimental - Expires September 3rd, 2003 77 4007 int stMemLTbl=85; 4008 int memLfTbl[NASUB_MAX]={147,147,147,147}; 4010 /* expansion filter(s) */ 4012 float cbfiltersTbl[CB_FILTERLEN]={ 4013 (float)-0.033691, (float)0.083740, (float)-0.144043, 4014 (float)0.713379, (float)0.806152, (float)-0.184326, 4015 (float)0.108887, (float)-0.034180}; 4017 /* Gain Quantization */ 4019 float gain_sq3Tbl[8]={ 4020 (float)-1.000000, (float)-0.659973, (float)-0.330017, 4021 (float)0.000000, (float)0.250000, (float)0.500000, 4022 (float)0.750000, (float)1.00000}; 4024 float gain_sq4Tbl[16]={ 4025 (float)-1.049988, (float)-0.900024, (float)-0.750000, 4026 (float)-0.599976, (float)-0.450012, (float)-0.299988, 4027 (float)-0.150024, (float)0.000000, (float)0.150024, 4028 (float)0.299988, (float)0.450012, (float)0.599976, 4029 (float)0.750000, (float)0.900024, (float)1.049988, 4030 (float)1.200012}; 4032 float gain_sq5Tbl[32]={ 4033 (float)0.037476, (float)0.075012, (float)0.112488, 4034 (float)0.150024, (float)0.187500, (float)0.224976, 4035 (float)0.262512, (float)0.299988, (float)0.337524, 4036 (float)0.375000, (float)0.412476, (float)0.450012, 4037 (float)0.487488, (float)0.525024, (float)0.562500, 4038 (float)0.599976, (float)0.637512, (float)0.674988, 4039 (float)0.712524, (float)0.750000, (float)0.787476, 4040 (float)0.825012, (float)0.862488, (float)0.900024, 4041 (float)0.937500, (float)0.974976, (float)1.012512, 4042 (float)1.049988, (float)1.087524, (float)1.125000, 4043 (float)1.162476, (float)1.200012}; 4045 /* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */ 4046 float polyphaserTbl[ENH_UPS0*(2*ENH_FL0+1)]={ 4047 (float)0.000000, (float)0.000000, (float)0.000000, 4048 (float)1.000000, 4049 (float)0.000000, (float)0.000000, (float)0.000000, 4050 (float)0.015625, (float)-0.076904, (float)0.288330, 4051 (float)0.862061, 4052 (float)-0.106445, (float)0.018799, (float)-0.015625, 4053 (float)0.023682, (float)-0.124268, (float)0.601563, 4054 (float)0.601563, 4055 (float)-0.124268, (float)0.023682, (float)-0.023682, 4056 (float)0.018799, (float)-0.106445, (float)0.862061, 4057 (float)0.288330, 4058 (float)-0.076904, (float)0.015625, (float)-0.018799}; 4060 Andersen et. al. Experimental - Expires September 3rd, 2003 78 4061 float enh_plocsTbl[ENH_NBLOCKS_TOT] = {(float)40.0, (float)120.0, 4062 (float)200.0, (float)280.0, (float)360.0, 4063 (float)440.0, (float)520.0, (float)600.0}; 4065 /* LPC analysis and quantization */ 4067 int dim_lsfCbTbl[LSF_NSPLIT] = {3, 3, 4}; 4068 int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128}; 4070 float lsfmeanTbl[LPC_FILTERORDER] = { 4071 (float)0.281738, (float)0.445801, (float)0.663330, 4072 (float)0.962524, (float)1.251831, (float)1.533081, 4073 (float)1.850586, (float)2.137817, (float)2.481445, 4074 (float)2.777344}; 4076 float lsf_weightTbl_30ms[6] = {(float)(1.0/2.0), (float)1.0, 4077 (float)(2.0/3.0), 4078 (float)(1.0/3.0), (float)0.0, (float)0.0}; 4080 float lsf_weightTbl_20ms[4] = {(float)(3.0/4.0), (float)(2.0/4.0), 4081 (float)(1.0/4.0), (float)(0.0)}; 4083 /* Hanning LPC window */ 4084 float lpc_winTbl[BLOCKL_MAX]={ 4085 (float)0.000183, (float)0.000671, (float)0.001526, 4086 (float)0.002716, (float)0.004242, (float)0.006104, 4087 (float)0.008301, (float)0.010834, (float)0.013702, 4088 (float)0.016907, (float)0.020416, (float)0.024261, 4089 (float)0.028442, (float)0.032928, (float)0.037750, 4090 (float)0.042877, (float)0.048309, (float)0.054047, 4091 (float)0.060089, (float)0.066437, (float)0.073090, 4092 (float)0.080017, (float)0.087219, (float)0.094727, 4093 (float)0.102509, (float)0.110535, (float)0.118835, 4094 (float)0.127411, (float)0.136230, (float)0.145294, 4095 (float)0.154602, (float)0.164154, (float)0.173920, 4096 (float)0.183899, (float)0.194122, (float)0.204529, 4097 (float)0.215149, (float)0.225952, (float)0.236938, 4098 (float)0.248108, (float)0.259460, (float)0.270966, 4099 (float)0.282654, (float)0.294464, (float)0.306396, 4100 (float)0.318481, (float)0.330688, (float)0.343018, 4101 (float)0.355438, (float)0.367981, (float)0.380585, 4102 (float)0.393280, (float)0.406067, (float)0.418884, 4103 (float)0.431763, (float)0.444702, (float)0.457672, 4104 (float)0.470673, (float)0.483704, (float)0.496735, 4105 (float)0.509766, (float)0.522797, (float)0.535828, 4106 (float)0.548798, (float)0.561768, (float)0.574677, 4107 (float)0.587524, (float)0.600342, (float)0.613068, 4108 (float)0.625732, (float)0.638306, (float)0.650787, 4109 (float)0.663147, (float)0.675415, (float)0.687561, 4110 (float)0.699585, (float)0.711487, (float)0.723206, 4111 (float)0.734802, (float)0.746216, (float)0.757477, 4112 (float)0.768585, (float)0.779480, (float)0.790192, 4114 Andersen et. al. Experimental - Expires September 3rd, 2003 79 4115 (float)0.800720, (float)0.811005, (float)0.821106, 4116 (float)0.830994, (float)0.840668, (float)0.850067, 4117 (float)0.859253, (float)0.868225, (float)0.876892, 4118 (float)0.885345, (float)0.893524, (float)0.901428, 4119 (float)0.909058, (float)0.916412, (float)0.923492, 4120 (float)0.930267, (float)0.936768, (float)0.942963, 4121 (float)0.948853, (float)0.954437, (float)0.959717, 4122 (float)0.964691, (float)0.969360, (float)0.973694, 4123 (float)0.977692, (float)0.981384, (float)0.984741, 4124 (float)0.987762, (float)0.990479, (float)0.992828, 4125 (float)0.994873, (float)0.996552, (float)0.997925, 4126 (float)0.998932, (float)0.999603, (float)0.999969, 4127 (float)0.999969, (float)0.999603, (float)0.998932, 4128 (float)0.997925, (float)0.996552, (float)0.994873, 4129 (float)0.992828, (float)0.990479, (float)0.987762, 4130 (float)0.984741, (float)0.981384, (float)0.977692, 4131 (float)0.973694, (float)0.969360, (float)0.964691, 4132 (float)0.959717, (float)0.954437, (float)0.948853, 4133 (float)0.942963, (float)0.936768, (float)0.930267, 4134 (float)0.923492, (float)0.916412, (float)0.909058, 4135 (float)0.901428, (float)0.893524, (float)0.885345, 4136 (float)0.876892, (float)0.868225, (float)0.859253, 4137 (float)0.850067, (float)0.840668, (float)0.830994, 4138 (float)0.821106, (float)0.811005, (float)0.800720, 4139 (float)0.790192, (float)0.779480, (float)0.768585, 4140 (float)0.757477, (float)0.746216, (float)0.734802, 4141 (float)0.723206, (float)0.711487, (float)0.699585, 4142 (float)0.687561, (float)0.675415, (float)0.663147, 4143 (float)0.650787, (float)0.638306, (float)0.625732, 4144 (float)0.613068, (float)0.600342, (float)0.587524, 4145 (float)0.574677, (float)0.561768, (float)0.548798, 4146 (float)0.535828, (float)0.522797, (float)0.509766, 4147 (float)0.496735, (float)0.483704, (float)0.470673, 4148 (float)0.457672, (float)0.444702, (float)0.431763, 4149 (float)0.418884, (float)0.406067, (float)0.393280, 4150 (float)0.380585, (float)0.367981, (float)0.355438, 4151 (float)0.343018, (float)0.330688, (float)0.318481, 4152 (float)0.306396, (float)0.294464, (float)0.282654, 4153 (float)0.270966, (float)0.259460, (float)0.248108, 4154 (float)0.236938, (float)0.225952, (float)0.215149, 4155 (float)0.204529, (float)0.194122, (float)0.183899, 4156 (float)0.173920, (float)0.164154, (float)0.154602, 4157 (float)0.145294, (float)0.136230, (float)0.127411, 4158 (float)0.118835, (float)0.110535, (float)0.102509, 4159 (float)0.094727, (float)0.087219, (float)0.080017, 4160 (float)0.073090, (float)0.066437, (float)0.060089, 4161 (float)0.054047, (float)0.048309, (float)0.042877, 4162 (float)0.037750, (float)0.032928, (float)0.028442, 4163 (float)0.024261, (float)0.020416, (float)0.016907, 4164 (float)0.013702, (float)0.010834, (float)0.008301, 4165 (float)0.006104, (float)0.004242, (float)0.002716, 4166 (float)0.001526, (float)0.000671, (float)0.000183 4167 }; 4169 Andersen et. al. Experimental - Expires September 3rd, 2003 80 4170 /* Asymmetric LPC window */ 4171 float lpc_asymwinTbl[BLOCKL_MAX]={ 4172 (float)0.000061, (float)0.000214, (float)0.000458, 4173 (float)0.000824, (float)0.001282, (float)0.001831, 4174 (float)0.002472, (float)0.003235, (float)0.004120, 4175 (float)0.005066, (float)0.006134, (float)0.007294, 4176 (float)0.008545, (float)0.009918, (float)0.011383, 4177 (float)0.012939, (float)0.014587, (float)0.016357, 4178 (float)0.018219, (float)0.020172, (float)0.022217, 4179 (float)0.024353, (float)0.026611, (float)0.028961, 4180 (float)0.031372, (float)0.033905, (float)0.036530, 4181 (float)0.039276, (float)0.042084, (float)0.044983, 4182 (float)0.047974, (float)0.051086, (float)0.054260, 4183 (float)0.057526, (float)0.060883, (float)0.064331, 4184 (float)0.067871, (float)0.071503, (float)0.075226, 4185 (float)0.079010, (float)0.082916, (float)0.086884, 4186 (float)0.090942, (float)0.095062, (float)0.099304, 4187 (float)0.103607, (float)0.107971, (float)0.112427, 4188 (float)0.116974, (float)0.121582, (float)0.126282, 4189 (float)0.131073, (float)0.135895, (float)0.140839, 4190 (float)0.145813, (float)0.150879, (float)0.156006, 4191 (float)0.161224, (float)0.166504, (float)0.171844, 4192 (float)0.177246, (float)0.182709, (float)0.188263, 4193 (float)0.193848, (float)0.199524, (float)0.205231, 4194 (float)0.211029, (float)0.216858, (float)0.222778, 4195 (float)0.228729, (float)0.234741, (float)0.240814, 4196 (float)0.246918, (float)0.253082, (float)0.259308, 4197 (float)0.265564, (float)0.271881, (float)0.278259, 4198 (float)0.284668, (float)0.291107, (float)0.297607, 4199 (float)0.304138, (float)0.310730, (float)0.317322, 4200 (float)0.323975, (float)0.330658, (float)0.337372, 4201 (float)0.344147, (float)0.350922, (float)0.357727, 4202 (float)0.364594, (float)0.371460, (float)0.378357, 4203 (float)0.385284, (float)0.392212, (float)0.399170, 4204 (float)0.406158, (float)0.413177, (float)0.420197, 4205 (float)0.427246, (float)0.434296, (float)0.441376, 4206 (float)0.448456, (float)0.455536, (float)0.462646, 4207 (float)0.469757, (float)0.476868, (float)0.483978, 4208 (float)0.491089, (float)0.498230, (float)0.505341, 4209 (float)0.512451, (float)0.519592, (float)0.526703, 4210 (float)0.533813, (float)0.540924, (float)0.548004, 4211 (float)0.555084, (float)0.562164, (float)0.569244, 4212 (float)0.576294, (float)0.583313, (float)0.590332, 4213 (float)0.597321, (float)0.604309, (float)0.611267, 4214 (float)0.618195, (float)0.625092, (float)0.631989, 4215 (float)0.638855, (float)0.645660, (float)0.652466, 4216 (float)0.659241, (float)0.665985, (float)0.672668, 4217 (float)0.679352, (float)0.685974, (float)0.692566, 4218 (float)0.699127, (float)0.705658, (float)0.712128, 4219 (float)0.718536, (float)0.724945, (float)0.731262, 4220 (float)0.737549, (float)0.743805, (float)0.750000, 4221 (float)0.756134, (float)0.762238, (float)0.768280, 4223 Andersen et. al. Experimental - Expires September 3rd, 2003 81 4224 (float)0.774261, (float)0.780182, (float)0.786072, 4225 (float)0.791870, (float)0.797638, (float)0.803314, 4226 (float)0.808960, (float)0.814514, (float)0.820038, 4227 (float)0.825470, (float)0.830841, (float)0.836151, 4228 (float)0.841400, (float)0.846558, (float)0.851654, 4229 (float)0.856689, (float)0.861633, (float)0.866516, 4230 (float)0.871338, (float)0.876068, (float)0.880737, 4231 (float)0.885315, (float)0.889801, (float)0.894226, 4232 (float)0.898560, (float)0.902832, (float)0.907013, 4233 (float)0.911102, (float)0.915100, (float)0.919037, 4234 (float)0.922882, (float)0.926636, (float)0.930328, 4235 (float)0.933899, (float)0.937408, (float)0.940796, 4236 (float)0.944122, (float)0.947357, (float)0.950470, 4237 (float)0.953522, (float)0.956482, (float)0.959351, 4238 (float)0.962097, (float)0.964783, (float)0.967377, 4239 (float)0.969849, (float)0.972229, (float)0.974518, 4240 (float)0.976715, (float)0.978821, (float)0.980835, 4241 (float)0.982727, (float)0.984528, (float)0.986237, 4242 (float)0.987854, (float)0.989380, (float)0.990784, 4243 (float)0.992096, (float)0.993317, (float)0.994415, 4244 (float)0.995422, (float)0.996338, (float)0.997162, 4245 (float)0.997864, (float)0.998474, (float)0.998962, 4246 (float)0.999390, (float)0.999695, (float)0.999878, 4247 (float)0.999969, (float)0.999969, (float)0.996918, 4248 (float)0.987701, (float)0.972382, (float)0.951050, 4249 (float)0.923889, (float)0.891022, (float)0.852631, 4250 (float)0.809021, (float)0.760406, (float)0.707092, 4251 (float)0.649445, (float)0.587799, (float)0.522491, 4252 (float)0.453979, (float)0.382690, (float)0.309021, 4253 (float)0.233459, (float)0.156433, (float)0.078461 4254 }; 4256 /* Lag window for LPC */ 4257 float lpc_lagwinTbl[LPC_FILTERORDER + 1]={ 4258 (float)1.000100, (float)0.998890, (float)0.995569, 4259 (float)0.990057, (float)0.982392, 4260 (float)0.972623, (float)0.960816, (float)0.947047, 4261 (float)0.931405, (float)0.913989, (float)0.894909}; 4263 /* LSF quantization*/ 4264 float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = { 4265 (float)0.155396, (float)0.273193, (float)0.451172, 4266 (float)0.390503, (float)0.648071, (float)1.002075, 4267 (float)0.440186, (float)0.692261, (float)0.955688, 4268 (float)0.343628, (float)0.642334, (float)1.071533, 4269 (float)0.318359, (float)0.491577, (float)0.670532, 4270 (float)0.193115, (float)0.375488, (float)0.725708, 4271 (float)0.364136, (float)0.510376, (float)0.658691, 4272 (float)0.297485, (float)0.527588, (float)0.842529, 4273 (float)0.227173, (float)0.365967, (float)0.563110, 4274 (float)0.244995, (float)0.396729, (float)0.636475, 4275 (float)0.169434, (float)0.300171, (float)0.520264, 4276 (float)0.312866, (float)0.464478, (float)0.643188, 4278 Andersen et. al. Experimental - Expires September 3rd, 2003 82 4279 (float)0.248535, (float)0.429932, (float)0.626099, 4280 (float)0.236206, (float)0.491333, (float)0.817139, 4281 (float)0.334961, (float)0.625122, (float)0.895752, 4282 (float)0.343018, (float)0.518555, (float)0.698608, 4283 (float)0.372803, (float)0.659790, (float)0.945435, 4284 (float)0.176880, (float)0.316528, (float)0.581421, 4285 (float)0.416382, (float)0.625977, (float)0.805176, 4286 (float)0.303223, (float)0.568726, (float)0.915039, 4287 (float)0.203613, (float)0.351440, (float)0.588135, 4288 (float)0.221191, (float)0.375000, (float)0.614746, 4289 (float)0.199951, (float)0.323364, (float)0.476074, 4290 (float)0.300781, (float)0.433350, (float)0.566895, 4291 (float)0.226196, (float)0.354004, (float)0.507568, 4292 (float)0.300049, (float)0.508179, (float)0.711670, 4293 (float)0.312012, (float)0.492676, (float)0.763428, 4294 (float)0.329956, (float)0.541016, (float)0.795776, 4295 (float)0.373779, (float)0.604614, (float)0.928833, 4296 (float)0.210571, (float)0.452026, (float)0.755249, 4297 (float)0.271118, (float)0.473267, (float)0.662476, 4298 (float)0.285522, (float)0.436890, (float)0.634399, 4299 (float)0.246704, (float)0.565552, (float)0.859009, 4300 (float)0.270508, (float)0.406250, (float)0.553589, 4301 (float)0.361450, (float)0.578491, (float)0.813843, 4302 (float)0.342651, (float)0.482788, (float)0.622437, 4303 (float)0.340332, (float)0.549438, (float)0.743164, 4304 (float)0.200439, (float)0.336304, (float)0.540894, 4305 (float)0.407837, (float)0.644775, (float)0.895142, 4306 (float)0.294678, (float)0.454834, (float)0.699097, 4307 (float)0.193115, (float)0.344482, (float)0.643188, 4308 (float)0.275757, (float)0.420776, (float)0.598755, 4309 (float)0.380493, (float)0.608643, (float)0.861084, 4310 (float)0.222778, (float)0.426147, (float)0.676514, 4311 (float)0.407471, (float)0.700195, (float)1.053101, 4312 (float)0.218384, (float)0.377197, (float)0.669922, 4313 (float)0.313232, (float)0.454102, (float)0.600952, 4314 (float)0.347412, (float)0.571533, (float)0.874146, 4315 (float)0.238037, (float)0.405396, (float)0.729492, 4316 (float)0.223877, (float)0.412964, (float)0.822021, 4317 (float)0.395264, (float)0.582153, (float)0.743896, 4318 (float)0.247925, (float)0.485596, (float)0.720581, 4319 (float)0.229126, (float)0.496582, (float)0.907715, 4320 (float)0.260132, (float)0.566895, (float)1.012695, 4321 (float)0.337402, (float)0.611572, (float)0.978149, 4322 (float)0.267822, (float)0.447632, (float)0.769287, 4323 (float)0.250610, (float)0.381714, (float)0.530029, 4324 (float)0.430054, (float)0.805054, (float)1.221924, 4325 (float)0.382568, (float)0.544067, (float)0.701660, 4326 (float)0.383545, (float)0.710327, (float)1.149170, 4327 (float)0.271362, (float)0.529053, (float)0.775513, 4328 (float)0.246826, (float)0.393555, (float)0.588623, 4329 (float)0.266846, (float)0.422119, (float)0.676758, 4330 (float)0.311523, (float)0.580688, (float)0.838623, 4331 (float)1.331177, (float)1.576782, (float)1.779541, 4333 Andersen et. al. Experimental - Expires September 3rd, 2003 83 4334 (float)1.160034, (float)1.401978, (float)1.768188, 4335 (float)1.161865, (float)1.525146, (float)1.715332, 4336 (float)0.759521, (float)0.913940, (float)1.119873, 4337 (float)0.947144, (float)1.121338, (float)1.282471, 4338 (float)1.015015, (float)1.557007, (float)1.804932, 4339 (float)1.172974, (float)1.402100, (float)1.692627, 4340 (float)1.087524, (float)1.474243, (float)1.665405, 4341 (float)0.899536, (float)1.105225, (float)1.406250, 4342 (float)1.148438, (float)1.484741, (float)1.796265, 4343 (float)0.785645, (float)1.209839, (float)1.567749, 4344 (float)0.867798, (float)1.166504, (float)1.450684, 4345 (float)0.922485, (float)1.229858, (float)1.420898, 4346 (float)0.791260, (float)1.123291, (float)1.409546, 4347 (float)0.788940, (float)0.966064, (float)1.340332, 4348 (float)1.051147, (float)1.272827, (float)1.556641, 4349 (float)0.866821, (float)1.181152, (float)1.538818, 4350 (float)0.906738, (float)1.373535, (float)1.607910, 4351 (float)1.244751, (float)1.581421, (float)1.933838, 4352 (float)0.913940, (float)1.337280, (float)1.539673, 4353 (float)0.680542, (float)0.959229, (float)1.662720, 4354 (float)0.887207, (float)1.430542, (float)1.800781, 4355 (float)0.912598, (float)1.433594, (float)1.683960, 4356 (float)0.860474, (float)1.060303, (float)1.455322, 4357 (float)1.005127, (float)1.381104, (float)1.706909, 4358 (float)0.800781, (float)1.363892, (float)1.829102, 4359 (float)0.781860, (float)1.124390, (float)1.505981, 4360 (float)1.003662, (float)1.471436, (float)1.684692, 4361 (float)0.981323, (float)1.309570, (float)1.618042, 4362 (float)1.228760, (float)1.554321, (float)1.756470, 4363 (float)0.734375, (float)0.895752, (float)1.225586, 4364 (float)0.841797, (float)1.055664, (float)1.249268, 4365 (float)0.920166, (float)1.119385, (float)1.486206, 4366 (float)0.894409, (float)1.539063, (float)1.828979, 4367 (float)1.283691, (float)1.543335, (float)1.858276, 4368 (float)0.676025, (float)0.933105, (float)1.490845, 4369 (float)0.821289, (float)1.491821, (float)1.739868, 4370 (float)0.923218, (float)1.144653, (float)1.580566, 4371 (float)1.057251, (float)1.345581, (float)1.635864, 4372 (float)0.888672, (float)1.074951, (float)1.353149, 4373 (float)0.942749, (float)1.195435, (float)1.505493, 4374 (float)1.492310, (float)1.788086, (float)2.039673, 4375 (float)1.070313, (float)1.634399, (float)1.860962, 4376 (float)1.253296, (float)1.488892, (float)1.686035, 4377 (float)0.647095, (float)0.864014, (float)1.401855, 4378 (float)0.866699, (float)1.254883, (float)1.453369, 4379 (float)1.063965, (float)1.532593, (float)1.731323, 4380 (float)1.167847, (float)1.521484, (float)1.884033, 4381 (float)0.956055, (float)1.502075, (float)1.745605, 4382 (float)0.928711, (float)1.288574, (float)1.479614, 4383 (float)1.088013, (float)1.380737, (float)1.570801, 4384 (float)0.905029, (float)1.186768, (float)1.371948, 4385 (float)1.057861, (float)1.421021, (float)1.617432, 4386 (float)1.108276, (float)1.312500, (float)1.501465, 4388 Andersen et. al. Experimental - Expires September 3rd, 2003 84 4389 (float)0.979492, (float)1.416992, (float)1.624268, 4390 (float)1.276001, (float)1.661011, (float)2.007935, 4391 (float)0.993042, (float)1.168579, (float)1.331665, 4392 (float)0.778198, (float)0.944946, (float)1.235962, 4393 (float)1.223755, (float)1.491333, (float)1.815674, 4394 (float)0.852661, (float)1.350464, (float)1.722290, 4395 (float)1.134766, (float)1.593140, (float)1.787354, 4396 (float)1.051392, (float)1.339722, (float)1.531006, 4397 (float)0.803589, (float)1.271240, (float)1.652100, 4398 (float)0.755737, (float)1.143555, (float)1.639404, 4399 (float)0.700928, (float)0.837280, (float)1.130371, 4400 (float)0.942749, (float)1.197876, (float)1.669800, 4401 (float)0.993286, (float)1.378296, (float)1.566528, 4402 (float)0.801025, (float)1.095337, (float)1.298950, 4403 (float)0.739990, (float)1.032959, (float)1.383667, 4404 (float)0.845703, (float)1.072266, (float)1.543823, 4405 (float)0.915649, (float)1.072266, (float)1.224487, 4406 (float)1.021973, (float)1.226196, (float)1.481323, 4407 (float)0.999878, (float)1.204102, (float)1.555908, 4408 (float)0.722290, (float)0.913940, (float)1.340210, 4409 (float)0.673340, (float)0.835938, (float)1.259521, 4410 (float)0.832397, (float)1.208374, (float)1.394165, 4411 (float)0.962158, (float)1.576172, (float)1.912842, 4412 (float)1.166748, (float)1.370850, (float)1.556763, 4413 (float)0.946289, (float)1.138550, (float)1.400391, 4414 (float)1.035034, (float)1.218262, (float)1.386475, 4415 (float)1.393799, (float)1.717773, (float)2.000244, 4416 (float)0.972656, (float)1.260986, (float)1.760620, 4417 (float)1.028198, (float)1.288452, (float)1.484619, 4418 (float)0.773560, (float)1.258057, (float)1.756714, 4419 (float)1.080322, (float)1.328003, (float)1.742676, 4420 (float)0.823975, (float)1.450806, (float)1.917725, 4421 (float)0.859009, (float)1.016602, (float)1.191895, 4422 (float)0.843994, (float)1.131104, (float)1.645020, 4423 (float)1.189697, (float)1.702759, (float)1.894409, 4424 (float)1.346680, (float)1.763184, (float)2.066040, 4425 (float)0.980469, (float)1.253784, (float)1.441650, 4426 (float)1.338135, (float)1.641968, (float)1.932739, 4427 (float)1.223267, (float)1.424194, (float)1.626465, 4428 (float)0.765747, (float)1.004150, (float)1.579102, 4429 (float)1.042847, (float)1.269165, (float)1.647461, 4430 (float)0.968750, (float)1.257568, (float)1.555786, 4431 (float)0.826294, (float)0.993408, (float)1.275146, 4432 (float)0.742310, (float)0.950439, (float)1.430542, 4433 (float)1.054321, (float)1.439819, (float)1.828003, 4434 (float)1.072998, (float)1.261719, (float)1.441895, 4435 (float)0.859375, (float)1.036377, (float)1.314819, 4436 (float)0.895752, (float)1.267212, (float)1.605591, 4437 (float)0.805420, (float)0.962891, (float)1.142334, 4438 (float)0.795654, (float)1.005493, (float)1.468506, 4439 (float)1.105347, (float)1.313843, (float)1.584839, 4440 (float)0.792236, (float)1.221802, (float)1.465698, 4441 (float)1.170532, (float)1.467651, (float)1.664063, 4443 Andersen et. al. Experimental - Expires September 3rd, 2003 85 4444 (float)0.838257, (float)1.153198, (float)1.342163, 4445 (float)0.968018, (float)1.198242, (float)1.391235, 4446 (float)1.250122, (float)1.623535, (float)1.823608, 4447 (float)0.711670, (float)1.058350, (float)1.512085, 4448 (float)1.204834, (float)1.454468, (float)1.739136, 4449 (float)1.137451, (float)1.421753, (float)1.620117, 4450 (float)0.820435, (float)1.322754, (float)1.578247, 4451 (float)0.798706, (float)1.005005, (float)1.213867, 4452 (float)0.980713, (float)1.324951, (float)1.512939, 4453 (float)1.112305, (float)1.438843, (float)1.735596, 4454 (float)1.135498, (float)1.356689, (float)1.635742, 4455 (float)1.101318, (float)1.387451, (float)1.686523, 4456 (float)0.849854, (float)1.276978, (float)1.523438, 4457 (float)1.377930, (float)1.627563, (float)1.858154, 4458 (float)0.884888, (float)1.095459, (float)1.287476, 4459 (float)1.289795, (float)1.505859, (float)1.756592, 4460 (float)0.817505, (float)1.384155, (float)1.650513, 4461 (float)1.446655, (float)1.702148, (float)1.931885, 4462 (float)0.835815, (float)1.023071, (float)1.385376, 4463 (float)0.916626, (float)1.139038, (float)1.335327, 4464 (float)0.980103, (float)1.174072, (float)1.453735, 4465 (float)1.705688, (float)2.153809, (float)2.398315, (float)2.743408, 4466 (float)1.797119, (float)2.016846, (float)2.445679, (float)2.701904, 4467 (float)1.990356, (float)2.219116, (float)2.576416, (float)2.813477, 4468 (float)1.849365, (float)2.190918, (float)2.611572, (float)2.835083, 4469 (float)1.657959, (float)1.854370, (float)2.159058, (float)2.726196, 4470 (float)1.437744, (float)1.897705, (float)2.253174, (float)2.655396, 4471 (float)2.028687, (float)2.247314, (float)2.542358, (float)2.875854, 4472 (float)1.736938, (float)1.922119, (float)2.185913, (float)2.743408, 4473 (float)1.521606, (float)1.870972, (float)2.526855, (float)2.786987, 4474 (float)1.841431, (float)2.050659, (float)2.463623, (float)2.857666, 4475 (float)1.590088, (float)2.067261, (float)2.427979, (float)2.794434, 4476 (float)1.746826, (float)2.057373, (float)2.320190, (float)2.800781, 4477 (float)1.734619, (float)1.940552, (float)2.306030, (float)2.826416, 4478 (float)1.786255, (float)2.204468, (float)2.457520, (float)2.795288, 4479 (float)1.861084, (float)2.170532, (float)2.414551, (float)2.763672, 4480 (float)2.001465, (float)2.307617, (float)2.552734, (float)2.811890, 4481 (float)1.784424, (float)2.124146, (float)2.381592, (float)2.645508, 4482 (float)1.888794, (float)2.135864, (float)2.418579, (float)2.861206, 4483 (float)2.301147, (float)2.531250, (float)2.724976, (float)2.913086, 4484 (float)1.837769, (float)2.051270, (float)2.261963, (float)2.553223, 4485 (float)2.012939, (float)2.221191, (float)2.440186, (float)2.678101, 4486 (float)1.429565, (float)1.858276, (float)2.582275, (float)2.845703, 4487 (float)1.622803, (float)1.897705, (float)2.367310, (float)2.621094, 4488 (float)1.581543, (float)1.960449, (float)2.515869, (float)2.736450, 4489 (float)1.419434, (float)1.933960, (float)2.394653, (float)2.746704, 4490 (float)1.721924, (float)2.059570, (float)2.421753, (float)2.769653, 4491 (float)1.911011, (float)2.220703, (float)2.461060, (float)2.740723, 4492 (float)1.581177, (float)1.860840, (float)2.516968, (float)2.874634, 4493 (float)1.870361, (float)2.098755, (float)2.432373, (float)2.656494, 4494 (float)2.059692, (float)2.279785, (float)2.495605, (float)2.729370, 4495 (float)1.815674, (float)2.181519, (float)2.451538, (float)2.680542, 4496 (float)1.407959, (float)1.768311, (float)2.343018, (float)2.668091, 4498 Andersen et. al. Experimental - Expires September 3rd, 2003 86 4499 (float)2.168701, (float)2.394653, (float)2.604736, (float)2.829346, 4500 (float)1.636230, (float)1.865723, (float)2.329102, (float)2.824219, 4501 (float)1.878906, (float)2.139526, (float)2.376709, (float)2.679810, 4502 (float)1.765381, (float)1.971802, (float)2.195435, (float)2.586914, 4503 (float)2.164795, (float)2.410889, (float)2.673706, (float)2.903198, 4504 (float)2.071899, (float)2.331055, (float)2.645874, (float)2.907104, 4505 (float)2.026001, (float)2.311523, (float)2.594849, (float)2.863892, 4506 (float)1.948975, (float)2.180786, (float)2.514893, (float)2.797852, 4507 (float)1.881836, (float)2.130859, (float)2.478149, (float)2.804199, 4508 (float)2.238159, (float)2.452759, (float)2.652832, (float)2.868286, 4509 (float)1.897949, (float)2.101685, (float)2.524292, (float)2.880127, 4510 (float)1.856445, (float)2.074585, (float)2.541016, (float)2.791748, 4511 (float)1.695557, (float)2.199097, (float)2.506226, (float)2.742676, 4512 (float)1.612671, (float)1.877075, (float)2.435425, (float)2.732910, 4513 (float)1.568848, (float)1.786499, (float)2.194580, (float)2.768555, 4514 (float)1.953369, (float)2.164551, (float)2.486938, (float)2.874023, 4515 (float)1.388306, (float)1.725342, (float)2.384521, (float)2.771851, 4516 (float)2.115356, (float)2.337769, (float)2.592896, (float)2.864014, 4517 (float)1.905762, (float)2.111328, (float)2.363525, (float)2.789307, 4518 (float)1.882568, (float)2.332031, (float)2.598267, (float)2.827637, 4519 (float)1.683594, (float)2.088745, (float)2.361938, (float)2.608643, 4520 (float)1.874023, (float)2.182129, (float)2.536133, (float)2.766968, 4521 (float)1.861938, (float)2.070435, (float)2.309692, (float)2.700562, 4522 (float)1.722168, (float)2.107422, (float)2.477295, (float)2.837646, 4523 (float)1.926880, (float)2.184692, (float)2.442627, (float)2.663818, 4524 (float)2.123901, (float)2.337280, (float)2.553101, (float)2.777466, 4525 (float)1.588135, (float)1.911499, (float)2.212769, (float)2.543945, 4526 (float)2.053955, (float)2.370850, (float)2.712158, (float)2.939941, 4527 (float)2.210449, (float)2.519653, (float)2.770386, (float)2.958618, 4528 (float)2.199463, (float)2.474731, (float)2.718262, (float)2.919922, 4529 (float)1.960083, (float)2.175415, (float)2.608032, (float)2.888794, 4530 (float)1.953735, (float)2.185181, (float)2.428223, (float)2.809570, 4531 (float)1.615234, (float)2.036499, (float)2.576538, (float)2.834595, 4532 (float)1.621094, (float)2.028198, (float)2.431030, (float)2.664673, 4533 (float)1.824951, (float)2.267456, (float)2.514526, (float)2.747925, 4534 (float)1.994263, (float)2.229126, (float)2.475220, (float)2.833984, 4535 (float)1.746338, (float)2.011353, (float)2.588257, (float)2.826904, 4536 (float)1.562866, (float)2.135986, (float)2.471680, (float)2.687256, 4537 (float)1.748901, (float)2.083496, (float)2.460938, (float)2.686279, 4538 (float)1.758057, (float)2.131470, (float)2.636597, (float)2.891602, 4539 (float)2.071289, (float)2.299072, (float)2.550781, (float)2.814331, 4540 (float)1.839600, (float)2.094360, (float)2.496460, (float)2.723999, 4541 (float)1.882202, (float)2.088257, (float)2.636841, (float)2.923096, 4542 (float)1.957886, (float)2.153198, (float)2.384399, (float)2.615234, 4543 (float)1.992920, (float)2.351196, (float)2.654419, (float)2.889771, 4544 (float)2.012817, (float)2.262451, (float)2.643799, (float)2.903076, 4545 (float)2.025635, (float)2.254761, (float)2.508423, (float)2.784058, 4546 (float)2.316040, (float)2.589355, (float)2.794189, (float)2.963623, 4547 (float)1.741211, (float)2.279541, (float)2.578491, (float)2.816284, 4548 (float)1.845337, (float)2.055786, (float)2.348511, (float)2.822021, 4549 (float)1.679932, (float)1.926514, (float)2.499756, (float)2.835693, 4550 (float)1.722534, (float)1.946899, (float)2.448486, (float)2.728760, 4551 (float)1.829834, (float)2.043213, (float)2.580444, (float)2.867676, 4553 Andersen et. al. Experimental - Expires September 3rd, 2003 87 4554 (float)1.676636, (float)2.071655, (float)2.322510, (float)2.704834, 4555 (float)1.791504, (float)2.113525, (float)2.469727, (float)2.784058, 4556 (float)1.977051, (float)2.215088, (float)2.497437, (float)2.726929, 4557 (float)1.800171, (float)2.106689, (float)2.357788, (float)2.738892, 4558 (float)1.827759, (float)2.170166, (float)2.525879, (float)2.852417, 4559 (float)1.918335, (float)2.132813, (float)2.488403, (float)2.728149, 4560 (float)1.916748, (float)2.225098, (float)2.542603, (float)2.857666, 4561 (float)1.761230, (float)1.976074, (float)2.507446, (float)2.884521, 4562 (float)2.053711, (float)2.367432, (float)2.608032, (float)2.837646, 4563 (float)1.595337, (float)2.000977, (float)2.307129, (float)2.578247, 4564 (float)1.470581, (float)2.031250, (float)2.375854, (float)2.647583, 4565 (float)1.801392, (float)2.128052, (float)2.399780, (float)2.822876, 4566 (float)1.853638, (float)2.066650, (float)2.429199, (float)2.751465, 4567 (float)1.956299, (float)2.163696, (float)2.394775, (float)2.734253, 4568 (float)1.963623, (float)2.275757, (float)2.585327, (float)2.865234, 4569 (float)1.887451, (float)2.105469, (float)2.331787, (float)2.587402, 4570 (float)2.120117, (float)2.443359, (float)2.733887, (float)2.941406, 4571 (float)1.506348, (float)1.766968, (float)2.400513, (float)2.851807, 4572 (float)1.664551, (float)1.981079, (float)2.375732, (float)2.774414, 4573 (float)1.720703, (float)1.978882, (float)2.391479, (float)2.640991, 4574 (float)1.483398, (float)1.814819, (float)2.434448, (float)2.722290, 4575 (float)1.769043, (float)2.136597, (float)2.563721, (float)2.774414, 4576 (float)1.810791, (float)2.049316, (float)2.373901, (float)2.613647, 4577 (float)1.788330, (float)2.005981, (float)2.359131, (float)2.723145, 4578 (float)1.785156, (float)1.993164, (float)2.399780, (float)2.832520, 4579 (float)1.695313, (float)2.022949, (float)2.522583, (float)2.745117, 4580 (float)1.584106, (float)1.965576, (float)2.299927, (float)2.715576, 4581 (float)1.894897, (float)2.249878, (float)2.655884, (float)2.897705, 4582 (float)1.720581, (float)1.995728, (float)2.299438, (float)2.557007, 4583 (float)1.619385, (float)2.173950, (float)2.574219, (float)2.787964, 4584 (float)1.883179, (float)2.220459, (float)2.474365, (float)2.825073, 4585 (float)1.447632, (float)2.045044, (float)2.555542, (float)2.744873, 4586 (float)1.502686, (float)2.156616, (float)2.653320, (float)2.846558, 4587 (float)1.711548, (float)1.944092, (float)2.282959, (float)2.685791, 4588 (float)1.499756, (float)1.867554, (float)2.341064, (float)2.578857, 4589 (float)1.916870, (float)2.135132, (float)2.568237, (float)2.826050, 4590 (float)1.498047, (float)1.711182, (float)2.223267, (float)2.755127, 4591 (float)1.808716, (float)1.997559, (float)2.256470, (float)2.758545, 4592 (float)2.088501, (float)2.402710, (float)2.667358, (float)2.890259, 4593 (float)1.545044, (float)1.819214, (float)2.324097, (float)2.692993, 4594 (float)1.796021, (float)2.012573, (float)2.505737, (float)2.784912, 4595 (float)1.786499, (float)2.041748, (float)2.290405, (float)2.650757, 4596 (float)1.938232, (float)2.264404, (float)2.529053, (float)2.796143 4597 }; 4599 A.9 anaFilter.h 4601 /****************************************************************** 4603 iLBC Speech Coder ANSI-C Source Code 4605 anaFilter.h 4607 Andersen et. al. Experimental - Expires September 3rd, 2003 88 4608 Copyright (c) 2001, 4609 Global IP Sound AB. 4610 All rights reserved. 4612 ******************************************************************/ 4614 #ifndef __iLBC_ANAFILTER_H 4615 #define __iLBC_ANAFILTER_H 4617 void anaFilter( 4618 float *In, /* (i) Signal to be filtered */ 4619 float *a, /* (i) LP parameters */ 4620 int len,/* (i) Length of signal */ 4621 float *Out, /* (o) Filtered signal */ 4622 float *mem /* (i/o) Filter state */ 4623 ); 4625 #endif 4627 A.10 anaFilter.c 4629 /****************************************************************** 4631 iLBC Speech Coder ANSI-C Source Code 4633 anaFilter.c 4635 Copyright (c) 2001, 4636 Global IP Sound AB. 4637 All rights reserved. 4639 ******************************************************************/ 4641 #include 4642 #include "iLBC_define.h" 4644 /*----------------------------------------------------------------* 4645 * LP analysis filter. 4646 *---------------------------------------------------------------*/ 4648 void anaFilter( 4649 float *In, /* (i) Signal to be filtered */ 4650 float *a, /* (i) LP parameters */ 4651 int len,/* (i) Length of signal */ 4652 float *Out, /* (o) Filtered signal */ 4653 float *mem /* (i/o) Filter state */ 4654 ){ 4655 int i, j; 4656 float *po, *pi, *pm, *pa; 4658 po = Out; 4660 Andersen et. al. Experimental - Expires September 3rd, 2003 89 4661 /* Filter first part using memory from past */ 4663 for (i=0; i 4772 #include 4774 /*----------------------------------------------------------------* 4775 * Construct an additional codebook vector by filtering the 4776 * initial codebook buffer. This vector is then used to expand 4777 * the codebook with an additional section. 4778 *---------------------------------------------------------------*/ 4780 void filteredCBvecs( 4781 float *cbvectors, /* (o) Codebook vectors for the 4782 higher section */ 4783 float *mem, /* (i) Buffer to create codebook 4784 vector from */ 4785 int lMem /* (i) Length of buffer */ 4786 ){ 4787 int j, k; 4788 float *pp, *pp1; 4789 float tempbuff2[CB_MEML+CB_FILTERLEN]; 4790 float *pos; 4792 memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float)); 4793 memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float)); 4794 memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0, 4795 (CB_HALFFILTERLEN+1)*sizeof(float)); 4797 /* Create codebook vector for higher section by filtering */ 4799 /* do filtering */ 4800 pos=cbvectors; 4801 memset(pos, 0, lMem*sizeof(float)); 4802 for (k=0; k0.0) { 4895 invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS); 4896 } else { 4897 invenergy[tmpIndex] = (float) 0.0; 4898 } 4900 if (stage==0) { 4901 measure = (float)-10000000.0; 4903 if (crossDot > 0.0) { 4904 measure = crossDot*crossDot*invenergy[tmpIndex]; 4905 } 4906 } 4907 else { 4908 measure = crossDot*crossDot*invenergy[tmpIndex]; 4909 } 4911 /* check if measure is better */ 4912 ftmp = crossDot*invenergy[tmpIndex]; 4914 if ((measure>*max_measure) && (fabs(ftmp) 5013 #include 5015 #include "iLBC_define.h" 5017 /*----------------------------------------------------------------* 5018 * Compute cross correlation and pitch gain for pitch prediction 5019 * of last subframe at given lag. 5020 *---------------------------------------------------------------*/ 5022 void compCorr( 5023 float *cc, /* (o) cross correlation coefficient */ 5024 float *gc, /* (o) gain */ 5025 float *pm, 5026 float *buffer, /* (i) signal buffer */ 5027 int lag, /* (i) pitch lag */ 5028 int bLen, /* (i) length of buffer */ 5029 int sRange /* (i) correlation search length */ 5030 ){ 5031 int i; 5032 float ftmp1, ftmp2, ftmp3; 5034 ftmp1 = 0.0; 5036 Andersen et. al. Experimental - Expires September 3rd, 2003 96 5037 ftmp2 = 0.0; 5038 ftmp3 = 0.0; 5039 for (i=0; i 0.0) { 5049 *cc = ftmp1*ftmp1/ftmp2; 5050 *gc = (float)fabs(ftmp1/ftmp2); 5051 *pm=(float)fabs(ftmp1)/ 5052 ((float)sqrt(ftmp2)*(float)sqrt(ftmp3)); 5053 } 5054 else { 5055 *cc = 0.0; 5056 *gc = 0.0; 5057 *pm=0.0; 5058 } 5059 } 5061 /*----------------------------------------------------------------* 5062 * Packet loss concealment routine. Conceals a residual signal 5063 * and LP parameters. If no packet loss, update state. 5064 *---------------------------------------------------------------*/ 5066 void doThePLC( 5067 float *PLCresidual, /* (o) concealed residual */ 5068 float *PLClpc, /* (o) concealed LP parameters */ 5069 int PLI, /* (i) packet loss indicator 5070 0 - no PL, 1 = PL */ 5071 float *decresidual, /* (i) decoded residual */ 5072 float *lpc, /* (i) decoded LPC (only used for no PL) */ 5073 int inlag, /* (i) pitch lag */ 5074 iLBC_Dec_Inst_t *iLBCdec_inst 5075 /* (i/o) decoder instance */ 5076 ){ 5077 int lag=20, randlag; 5078 float gain, maxcc; 5079 float use_gain; 5080 float gain_comp, maxcc_comp, per, max_per; 5081 int i, pick; 5082 float ftmp, randvec[BLOCKL_MAX], pitchfact, energy; 5084 /* Packet Loss */ 5086 if (PLI == 1) { 5088 iLBCdec_inst->consPLICount += 1; 5090 Andersen et. al. Experimental - Expires September 3rd, 2003 97 5091 /* if previous frame not lost, 5092 determine pitch pred. gain */ 5094 if (iLBCdec_inst->prevPLI != 1) { 5096 /* Search around the previous lag to find the 5097 best pitch period */ 5099 lag=20; 5100 compCorr(&maxcc, &gain, &max_per, 5101 iLBCdec_inst->prevResidual, 5102 lag, iLBCdec_inst->blockl, 60); 5103 for (i=21;i<=120;i++) { 5104 compCorr(&maxcc_comp, &gain_comp, &per, 5105 iLBCdec_inst->prevResidual, 5106 i, iLBCdec_inst->blockl, 60); 5108 if (maxcc_comp>maxcc) { 5109 maxcc=maxcc_comp; 5110 gain=gain_comp; 5111 lag=i; 5112 max_per=per; 5113 } 5114 } 5116 } 5118 /* previous frame lost, use recorded lag and periodicity */ 5120 else { 5121 lag=iLBCdec_inst->prevLag; 5122 max_per=iLBCdec_inst->per; 5123 } 5125 /* downscaling */ 5127 use_gain=1.0; 5128 if (iLBCdec_inst->consPLICount* 5129 iLBCdec_inst->blockl>320) 5130 use_gain=(float)0.9; 5131 else if (iLBCdec_inst->consPLICount* 5132 iLBCdec_inst->blockl>2*320) 5133 use_gain=(float)0.7; 5134 else if (iLBCdec_inst->consPLICount* 5135 iLBCdec_inst->blockl>3*320) 5136 use_gain=(float)0.5; 5137 else if (iLBCdec_inst->consPLICount* 5138 iLBCdec_inst->blockl>4*320) 5139 use_gain=(float)0.0; 5141 /* mix noise and pitch repeatition */ 5142 ftmp=(float)sqrt(max_per); 5143 if (ftmp>(float)0.7) 5145 Andersen et. al. Experimental - Expires September 3rd, 2003 98 5146 pitchfact=(float)1.0; 5147 else if (ftmp>(float)0.4) 5148 pitchfact=(ftmp-(float)0.4)/((float)0.7-(float)0.4); 5149 else 5150 pitchfact=0.0; 5152 /* compute concealed residual */ 5154 energy = 0.0; 5155 for (i=0; iblockl; i++) { 5157 /* noise component */ 5159 iLBCdec_inst->seed=(iLBCdec_inst->seed*69069L+1) & 5160 (0x80000000L-1); 5161 randlag = 50 + ((signed long) iLBCdec_inst->seed)%70; 5162 pick = i - randlag; 5164 if (pick < 0) { 5165 randvec[i] = 5166 iLBCdec_inst->prevResidual[iLBCdec_inst->blockl+ 5167 pick]; 5168 } else { 5169 randvec[i] = randvec[pick]; 5170 } 5172 /* pitch repeatition component */ 5174 pick = i - lag; 5176 if (pick < 0) { 5177 PLCresidual[i] = 5178 iLBCdec_inst->prevResidual[iLBCdec_inst->blockl+ 5179 pick]; 5180 } else { 5181 PLCresidual[i] = PLCresidual[pick]; 5182 } 5184 /* mix random and periodicity component */ 5186 if (i<80) 5187 PLCresidual[i] = use_gain*(pitchfact*PLCresidual[i] + 5188 ((float)1.0 - pitchfact) * randvec[i]); 5189 else if (i<160) 5190 PLCresidual[i] = (float)0.95*use_gain* 5191 (pitchfact * PLCresidual[i] + 5192 ((float)1.0 - pitchfact) * randvec[i]); 5193 else 5194 PLCresidual[i] = (float)0.9*use_gain* 5195 (pitchfact * PLCresidual[i] + 5196 ((float)1.0 - pitchfact) * randvec[i]); 5198 energy += PLCresidual[i] * PLCresidual[i]; 5200 Andersen et. al. Experimental - Expires September 3rd, 2003 99 5201 } 5203 /* less than 30 dB, use only noise */ 5205 if (sqrt(energy/(float)iLBCdec_inst->blockl) < 30.0) { 5206 gain=0.0; 5207 for (i=0; iblockl; i++) { 5208 PLCresidual[i] = randvec[i]; 5209 } 5210 } 5212 /* conceal LPC by bandwidth expansion of old LPC */ 5214 ftmp=PLC_BWEXPAND; 5215 PLClpc[0]=(float)1.0; 5216 for (i=1; iprevLpc[i]; 5218 ftmp *= PLC_BWEXPAND; 5219 } 5221 } 5223 /* no packet loss, copy input */ 5225 else { 5226 memcpy(PLCresidual, decresidual, 5227 iLBCdec_inst->blockl*sizeof(float)); 5228 memcpy(PLClpc, lpc, (LPC_FILTERORDER+1)*sizeof(float)); 5229 iLBCdec_inst->consPLICount = 0; 5230 } 5232 /* update state */ 5234 if (PLI) { 5235 iLBCdec_inst->prevLag = lag; 5236 iLBCdec_inst->per=max_per; 5237 } 5239 iLBCdec_inst->prevPLI = PLI; 5240 memcpy(iLBCdec_inst->prevLpc, PLClpc, 5241 (LPC_FILTERORDER+1)*sizeof(float)); 5242 memcpy(iLBCdec_inst->prevResidual, PLCresidual, 5243 iLBCdec_inst->blockl*sizeof(float)); 5244 } 5246 A.15 enhancer.h 5248 /****************************************************************** 5250 iLBC Speech Coder ANSI-C Source Code 5252 enhancer.h 5254 Andersen et. al. Experimental - Expires September 3rd, 2003 100 5255 Copyright (c) 2001, 5256 Global IP Sound AB. 5257 All rights reserved. 5259 ******************************************************************/ 5261 #ifndef __ENHANCER_H 5262 #define __ENHANCER_H 5264 #include "iLBC_define.h" 5266 float xCorrCoef( 5267 float *target, /* (i) first array */ 5268 float *regressor, /* (i) second array */ 5269 int subl /* (i) dimension arrays */ 5270 ); 5272 int enhancerInterface( 5273 float *out, /* (o) the enhanced recidual signal */ 5274 float *in, /* (i) the recidual signal to enhance */ 5275 iLBC_Dec_Inst_t *iLBCdec_inst 5276 /* (i/o) the decoder state structure */ 5277 ); 5279 #endif 5281 A.16 enhancer.c 5283 /****************************************************************** 5285 iLBC Speech Coder ANSI-C Source Code 5287 enhancer.c 5289 Copyright (c) 2001, 5290 Global IP Sound AB. 5291 All rights reserved. 5293 ******************************************************************/ 5295 #include 5296 #include 5297 #include "iLBC_define.h" 5298 #include "constants.h" 5299 #include "filter.h" 5301 /*----------------------------------------------------------------* 5302 * Find index in array such that the array element with said 5303 * index is the element of said array closest to "value" 5304 * according to the squared-error criterion 5305 *---------------------------------------------------------------*/ 5307 Andersen et. al. Experimental - Expires September 3rd, 2003 101 5308 void NearestNeighbor( 5309 int *index, /* (o) index of array element closest to value */ 5310 float *array, /* (i) data array */ 5311 float value,/* (i) value */ 5312 int arlength/* (i) dimension of data array */ 5313 ){ 5314 int i; 5315 float bestcrit,crit; 5317 crit=array[0]-value; 5318 bestcrit=crit*crit; 5319 *index=0; 5320 for (i=1; i dim1 ) { 5374 hfl2=(int) (dim1/2); 5375 for (j=0; j= idatal) { 5466 searchSegEndPos=idatal-ENH_BLOCKL-1; 5467 } 5469 Andersen et. al. Experimental - Expires September 3rd, 2003 104 5470 corrdim=searchSegEndPos-searchSegStartPos+1; 5472 /* compute upsampled correlation (corr33) and find 5473 location of max */ 5475 mycorr1(corrVec,idata+searchSegStartPos, 5476 corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL); 5477 enh_upsample(corrVecUps,corrVec,corrdim,ENH_FL0); 5478 tloc=0; maxv=corrVecUps[0]; 5479 for (i=1; imaxv) { 5482 tloc=i; 5483 maxv=corrVecUps[i]; 5484 } 5485 } 5487 /* make vector can be upsampled without ever running outside 5488 bounds */ 5490 *updStartPos= (float)searchSegStartPos + 5491 (float)tloc/(float)ENH_UPS0+(float)1.0; 5492 tloc2=(int)(tloc/ENH_UPS0); 5494 if (tloc>tloc2*ENH_UPS0) { 5495 tloc2++; 5496 } 5497 st=searchSegStartPos+tloc2-ENH_FL0; 5499 if (st<0) { 5500 memset(vect,0,-st*sizeof(float)); 5501 memcpy(&vect[-st],idata, (ENH_VECTL+st)*sizeof(float)); 5502 } 5503 else { 5504 en=st+ENH_VECTL; 5506 if (en>idatal) { 5507 memcpy(vect, &idata[st], 5508 (ENH_VECTL-(en-idatal))*sizeof(float)); 5509 memset(&vect[ENH_VECTL-(en-idatal)], 0, 5510 (en-idatal)*sizeof(float)); 5511 } 5512 else { 5513 memcpy(vect, &idata[st], ENH_VECTL*sizeof(float)); 5514 } 5515 } 5516 fraction=tloc2*ENH_UPS0-tloc; 5518 /* compute the segment (this is actually a convolution) */ 5520 mycorr1(seg,vect,ENH_VECTL,polyphaserTbl+(2*ENH_FL0+1)*fraction, 5521 2*ENH_FL0+1); 5522 } 5524 Andersen et. al. Experimental - Expires September 3rd, 2003 105 5525 /*----------------------------------------------------------------* 5526 * find the smoothed output data 5527 *---------------------------------------------------------------*/ 5529 void smath( 5530 float *odata, /* (o) smoothed output */ 5531 float *sseq,/* (i) said second sequence of waveforms */ 5532 int hl, /* (i) 2*hl+1 is sseq dimension */ 5533 float alpha0/* (i) max smoothing energy fraction */ 5534 ){ 5535 int i,k; 5536 float w00,w10,w11,A,B,C,*psseq,err,errs; 5537 float surround[BLOCKL_MAX]; /* shape contributed by other than 5538 current */ 5539 float wt[2*ENH_HL+1]; /* waveform weighting to get 5540 surround shape */ 5541 float denom; 5543 /* create shape of contribution from all waveforms except the 5544 current one */ 5546 for (i=1; i<=2*hl+1; i++) { 5547 wt[i-1] = (float)0.5*(1 - (float)cos(2*PI*i/(2*hl+2))); 5548 } 5549 wt[hl]=0.0; /* for clarity, not used */ 5550 for (i=0; i alpha0 * w00) { 5596 if ( w00 < 1) { 5597 w00=1; 5598 } 5599 denom = (w11*w00-w10*w10)/(w00*w00); 5601 if (denom > 0.0001) { /* eliminates numerical problems 5602 for if smooth */ 5603 A = (float)sqrt( (alpha0- alpha0*alpha0/4)/denom); 5604 B = -alpha0/2 - A * w10/w00; 5605 B = B+1; 5606 } 5607 else { /* essentially no difference between cycles; 5608 smoothing not needed */ 5609 A= 0.0; 5610 B= 1.0; 5611 } 5613 /* create smoothed sequence */ 5615 psseq=sseq+hl*ENH_BLOCKL; 5616 for (i=0; i=0; q--) { 5659 blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]]; 5660 NearestNeighbor(lagBlock+q,plocs, 5661 blockStartPos[q]+ENH_BLOCKL_HALF-period[lagBlock[q+1]], 5662 periodl); 5664 if (blockStartPos[q]-ENH_OVERHANG>=0) { 5665 refiner(sseq+q*ENH_BLOCKL,blockStartPos+q,idata,idatal, 5666 centerStartPos,blockStartPos[q], 5667 period[lagBlock[q+1]]); 5668 } else { 5669 psseq=sseq+q*ENH_BLOCKL; 5670 memset(psseq, 0, ENH_BLOCKL*sizeof(float)); 5671 } 5672 } 5674 /* future */ 5676 for (i=0; i 0.0) { 5750 return (float)(ftmp1*ftmp1/ftmp2); 5751 } 5752 else { 5753 return (float)0.0; 5754 } 5755 } 5757 /*----------------------------------------------------------------* 5758 * interface for enhancer 5759 *---------------------------------------------------------------*/ 5761 int enhancerInterface( 5762 float *out, /* (o) enhanced signal */ 5763 float *in, /* (i) unenhanced signal */ 5764 iLBC_Dec_Inst_t *iLBCdec_inst /* (i) buffers etc */ 5765 ){ 5766 float *enh_buf, *enh_period; 5767 int iblock, isample; 5768 int lag, ilag, i; 5769 float cc, maxcc; 5770 float ftmp1, ftmp2; 5771 float *inPtr, *enh_bufPtr1, *enh_bufPtr2; 5772 float plc_pred[ENH_BLOCKL]; 5774 float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2]; 5775 int inLen=ENH_NBLOCKS*ENH_BLOCKL+120; 5776 int start, plc_blockl; 5778 enh_buf=iLBCdec_inst->enh_buf; 5779 enh_period=iLBCdec_inst->enh_period; 5781 memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl], 5782 (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float)); 5784 memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in, 5785 iLBCdec_inst->blockl*sizeof(float)); 5787 if (iLBCdec_inst->mode==30) 5788 plc_blockl=ENH_BLOCKL; 5789 else 5790 plc_blockl=40; 5792 /* PLC was performed on the previous packet */ 5793 if (iLBCdec_inst->prev_enh_pl==1) { 5795 Andersen et. al. Experimental - Expires September 3rd, 2003 110 5796 lag = 20; 5797 maxcc = xCorrCoef(in, in+lag, plc_blockl); 5798 for (ilag=21; ilag<120; ilag++) { 5799 cc = xCorrCoef(in, in+ilag, plc_blockl); 5801 if (cc > maxcc) { 5802 maxcc = cc; 5803 lag = ilag; 5804 } 5805 } 5807 /* compute new concealed residual for the old lookahead, 5808 mix the forward PLC with a backward PLC from 5809 the new frame */ 5811 inPtr=&in[lag-1]; 5813 enh_bufPtr1=&plc_pred[plc_blockl-1]; 5815 if (lag>plc_blockl) { 5816 start=plc_blockl; 5817 } else { 5818 start=lag; 5819 } 5821 for (isample = start; isample>0; isample--) { 5822 *enh_bufPtr1-- = *inPtr--; 5823 } 5825 enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl]; 5826 for (isample = (plc_blockl-1-lag); isample>=0; isample--) { 5827 *enh_bufPtr1-- = *enh_bufPtr2--; 5828 } 5830 /* limit energy change */ 5831 ftmp2=0.0; 5832 ftmp1=0.0; 5833 for (i=0;iblockl-i]* 5835 enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]; 5836 ftmp1+=plc_pred[i]*plc_pred[i]; 5837 } 5838 ftmp1=(float)sqrt(ftmp1/(float)plc_blockl); 5839 ftmp2=(float)sqrt(ftmp2/(float)plc_blockl); 5840 if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) { 5841 for (i=0;iblockl]; 5854 for (i=0; iblockl/ENH_BLOCKL; 5864 memmove(enh_period, &enh_period[i], 5865 (ENH_NBLOCKS_TOT-i)*sizeof(float)); 5867 /* Set state information to the 6 samples right before 5868 the samples to be downsampled. */ 5870 memcpy(lpState, enh_buf+ENH_NBLOCKS_EXTRA*ENH_BLOCKL-126, 5871 6*sizeof(float)); 5873 /* Down sample a factor 2 to save computations */ 5875 DownSample(enh_buf+ENH_NBLOCKS_EXTRA*ENH_BLOCKL-120, 5876 lpFilt_coefsTbl, inLen, 5877 lpState, downsampled); 5879 /* Estimate the pitch in the down sampled domain. */ 5880 for (iblock = 0; iblock maxcc) { 5892 maxcc = cc; 5893 lag = ilag; 5894 } 5895 } 5897 /* Store the estimated lag in the non-downsampled domain */ 5898 enh_period[iblock+ENH_NBLOCKS_EXTRA] = (float)lag*2; 5899 } 5901 if (iLBCdec_inst->mode==20) { 5902 /* Enhancer with 40 samples delay */ 5904 Andersen et. al. Experimental - Expires September 3rd, 2003 112 5905 for (iblock = 0; iblock<2; iblock++) { 5906 enhancer(out+iblock*ENH_BLOCKL, enh_buf, 5907 ENH_BUFL, (5+iblock)*ENH_BLOCKL+40, 5908 ENH_ALPHA0, enh_period, enh_plocsTbl, 5909 ENH_NBLOCKS_TOT); 5910 } 5911 } else if (iLBCdec_inst->mode==30) { 5912 /* Enhancer with 80 samples delay */ 5913 for (iblock = 0; iblock<3; iblock++) { 5914 enhancer(out+iblock*ENH_BLOCKL, enh_buf, 5915 ENH_BUFL, (4+iblock)*ENH_BLOCKL, 5916 ENH_ALPHA0, enh_period, enh_plocsTbl, 5917 ENH_NBLOCKS_TOT); 5918 } 5919 } 5921 return (lag*2); 5922 } 5924 A.17 filter.h 5926 /****************************************************************** 5928 iLBC Speech Coder ANSI-C Source Code 5930 filter.h 5932 Copyright (c) 2001, 5933 Global IP Sound AB. 5934 All rights reserved. 5936 ******************************************************************/ 5938 #ifndef __iLBC_FILTER_H 5939 #define __iLBC_FILTER_H 5941 void AllPoleFilter( 5942 float *InOut, /* (i/o) on entrance InOut[-orderCoef] to 5943 InOut[-1] contain the state of the filter 5944 (delayed samples). InOut[0] to 5945 InOut[lengthInOut-1] contain the filter 5946 input, on en exit InOut[-orderCoef] to 5947 InOut[-1] is unchanged and InOut[0] to 5948 InOut[lengthInOut-1] contain filtered 5949 samples */ 5950 float *Coef,/* (i) filter coefficients, Coef[0] is assumed to 5951 be 1.0 */ 5952 int lengthInOut,/* (i) number of input/output samples */ 5953 int orderCoef /* (i) number of filter coefficients */ 5954 ); 5956 void AllZeroFilter( 5958 Andersen et. al. Experimental - Expires September 3rd, 2003 113 5959 float *In, /* (i) In[0] to In[lengthInOut-1] contain filter 5960 input samples */ 5961 float *Coef,/* (i) filter coefficients (Coef[0] is assumed 5962 to be 1.0) */ 5963 int lengthInOut,/* (i) number of input/output samples */ 5964 int orderCoef, /* (i) number of filter coefficients */ 5965 float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] 5966 contain the filter state, on exit Out[0] 5967 to Out[lengthInOut-1] contain filtered 5968 samples */ 5969 ); 5971 void ZeroPoleFilter( 5972 float *In, /* (i) In[0] to In[lengthInOut-1] contain filter 5973 input samples In[-orderCoef] to In[-1] 5974 contain state of all-zero section */ 5975 float *ZeroCoef,/* (i) filter coefficients for all-zero 5976 section (ZeroCoef[0] is assumed to 5977 be 1.0) */ 5978 float *PoleCoef,/* (i) filter coefficients for all-pole section 5979 (ZeroCoef[0] is assumed to be 1.0) */ 5980 int lengthInOut,/* (i) number of input/output samples */ 5981 int orderCoef, /* (i) number of filter coefficients */ 5982 float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] 5983 contain state of all-pole section. On exit 5984 Out[0] to Out[lengthInOut-1] contain 5985 filtered samples */ 5986 ); 5988 void DownSample ( 5989 float *In, /* (i) input samples */ 5990 float *Coef, /* (i) filter coefficients */ 5991 int lengthIn, /* (i) number of input samples */ 5992 float *state, /* (i) filter state */ 5993 float *Out /* (o) downsampled output */ 5994 ); 5996 #endif 5998 A.18 filter.c 6000 /****************************************************************** 6002 iLBC Speech Coder ANSI-C Source Code 6004 filter.c 6006 Copyright (c) 2001, 6007 Global IP Sound AB. 6008 All rights reserved. 6010 ******************************************************************/ 6012 Andersen et. al. Experimental - Expires September 3rd, 2003 114 6013 #include "iLBC_define.h" 6015 /*----------------------------------------------------------------* 6016 * all-pole filter 6017 *---------------------------------------------------------------*/ 6019 void AllPoleFilter( 6020 float *InOut, /* (i/o) on entrance InOut[-orderCoef] to 6021 InOut[-1] contain the state of the filter 6022 (delayed samples). InOut[0] to 6023 InOut[lengthInOut-1] contain the filter 6024 input, on en exit InOut[-orderCoef] to 6025 InOut[-1] is unchanged and InOut[0] to 6026 InOut[lengthInOut-1] contain filtered 6027 samples */ 6028 float *Coef,/* (i) filter coefficients, Coef[0] is assumed to 6029 be 1.0 */ 6030 int lengthInOut,/* (i) number of input/output samples */ 6031 int orderCoef /* (i) number of filter coefficients */ 6032 ){ 6033 int n,k; 6035 for(n=0;nnsub-1; n++) { 6246 pp=residual+n*SUBL; 6247 for (l=0; l<5; l++) { 6248 fssqEn[n] += sampEn_win[l] * (*pp) * (*pp); 6249 bssqEn[n] += (*pp) * (*pp); 6250 pp++; 6251 } 6252 for (l=5; lnsub-1; 6267 pp=residual+n*SUBL; 6268 for (l=0; lmode==20) l=1; 6281 else l=0; 6283 Andersen et. al. Experimental - Expires September 3rd, 2003 119 6284 max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l]; 6285 max_ssqEn_n=1; 6286 for (n=2; nnsub; n++) { 6288 l++; 6289 if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) { 6290 max_ssqEn=(fssqEn[n-1]+bssqEn[n]) * 6291 ssqEn_win[l]; 6292 max_ssqEn_n=n; 6293 } 6294 } 6296 return max_ssqEn_n; 6297 } 6299 A.21 gainquant.h 6301 /****************************************************************** 6303 iLBC Speech Coder ANSI-C Source Code 6305 gainquant.h 6307 Copyright (c) 2001, 6308 Global IP Sound AB. 6309 All rights reserved. 6311 ******************************************************************/ 6313 #ifndef __iLBC_GAINQUANT_H 6314 #define __iLBC_GAINQUANT_H 6316 float gainquant(/* (o) quantized gain value */ 6317 float in, /* (i) gain value */ 6318 float maxIn,/* (i) maximum of gain value */ 6319 int cblen, /* (i) number of quantization indices */ 6320 int *index /* (o) quantization index */ 6321 ); 6323 float gaindequant( /* (o) quantized gain value */ 6324 int index, /* (i) quantization index */ 6325 float maxIn,/* (i) maximum of unquantized gain */ 6326 int cblen /* (i) number of quantization indices */ 6327 ); 6329 #endif 6331 A.22 gainquant.c 6333 /****************************************************************** 6335 Andersen et. al. Experimental - Expires September 3rd, 2003 120 6336 iLBC Speech Coder ANSI-C Source Code 6338 gainquant.c 6340 Copyright (c) 2001, 6341 Global IP Sound AB. 6342 All rights reserved. 6344 ******************************************************************/ 6346 #include 6347 #include 6348 #include "constants.h" 6349 #include "filter.h" 6351 /*----------------------------------------------------------------* 6352 * quantizer for the gain in the gain-shape coding of residual 6353 *---------------------------------------------------------------*/ 6355 float gainquant(/* (o) quantized gain value */ 6356 float in, /* (i) gain value */ 6357 float maxIn,/* (i) maximum of gain value */ 6358 int cblen, /* (i) number of quantization indices */ 6359 int *index /* (o) quantization index */ 6360 ){ 6361 int i, tindex; 6362 float minmeasure,measure, *cb, scale; 6364 /* ensure a lower bound on the scaling factor */ 6366 scale=maxIn; 6368 if (scale<0.1) { 6369 scale=(float)0.1; 6370 } 6372 /* select the quantization table */ 6374 if (cblen == 8) { 6375 cb = gain_sq3Tbl; 6376 } else if (cblen == 16) { 6377 cb = gain_sq4Tbl; 6378 } else { 6379 cb = gain_sq5Tbl; 6380 } 6382 /* select the best index in the quantization table */ 6384 minmeasure=10000000.0; 6385 tindex=0; 6386 for (i=0; i 6482 /*----------------------------------------------------------------* 6483 * Construct codebook vector for given index. 6484 *---------------------------------------------------------------*/ 6486 void getCBvec( 6487 float *cbvec, /* (o) Constructed codebook vector */ 6488 float *mem, /* (i) Codebook buffer */ 6489 int index, /* (i) Codebook index */ 6490 int lMem, /* (i) Length of codebook buffer */ 6491 int cbveclen/* (i) Codebook vector length */ 6492 ){ 6493 int j, k, n, memInd, sFilt; 6495 Andersen et. al. Experimental - Expires September 3rd, 2003 123 6496 float tmpbuf[CB_MEML]; 6497 int base_size; 6498 int ilow, ihigh; 6499 float alfa, alfa1; 6501 /* Determine size of codebook sections */ 6503 base_size=lMem-cbveclen+1; 6505 if (cbveclen==SUBL) { 6506 base_size+=cbveclen/2; 6507 } 6509 /* No filter -> First codebook section */ 6511 if (index 6751 #include "iLBC_define.h" 6752 #include "constants.h" 6754 /*----------------------------------------------------------------* 6755 * calculation of auto correlation 6756 *---------------------------------------------------------------*/ 6758 void autocorr( 6759 float *r, /* (o) autocorrelation vector */ 6760 const float *x, /* (i) data vector */ 6761 int N, /* (i) length of data vector */ 6762 int order /* largest lag for calculated autocorrelations */ 6763 ){ 6765 Andersen et. al. Experimental - Expires September 3rd, 2003 128 6766 int lag, n; 6767 float sum; 6769 for (lag = 0; lag <= order; lag++) { 6770 sum = 0; 6771 for (n = 0; n < N - lag; n++) { 6772 sum += x[n] * x[n+lag]; 6773 } 6774 r[lag] = sum; 6775 } 6776 } 6778 /*----------------------------------------------------------------* 6779 * window multiplication 6780 *---------------------------------------------------------------*/ 6782 void window( 6783 float *z, /* (o) the windowed data */ 6784 const float *x, /* (i) the original data vector */ 6785 const float *y, /* (i) the window */ 6786 int N /* (i) length of all vectors */ 6787 ){ 6788 int i; 6790 for (i = 0; i < N; i++) { 6791 z[i] = x[i] * y[i]; 6792 } 6793 } 6795 /*----------------------------------------------------------------* 6796 * levinson-durbin solution for lpc coefficients 6797 *---------------------------------------------------------------*/ 6799 void levdurb( 6800 float *a, /* (o) lpc coefficient vector starting with 1.0 6801 */ 6802 float *k, /* (o) reflection coefficients */ 6803 float *r, /* (i) autocorrelation vector */ 6804 int order /* (i) order of lpc filter */ 6805 ){ 6806 float sum, alpha; 6807 int m, m_h, i; 6809 a[0] = 1.0; 6811 if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */ 6812 for (i = 0; i < order; i++) { 6813 k[i] = 0; 6814 a[i+1] = 0; 6815 } 6816 } else { 6817 a[1] = k[0] = -r[1]/r[0]; 6818 alpha = r[0] + r[1] * k[0]; 6820 Andersen et. al. Experimental - Expires September 3rd, 2003 129 6821 for (m = 1; m < order; m++){ 6822 sum = r[m + 1]; 6823 for (i = 0; i < m; i++){ 6824 sum += a[i+1] * r[m - i]; 6825 } 6826 k[m] = -sum / alpha; 6827 alpha += k[m] * sum; 6828 m_h = (m + 1) >> 1; 6829 for (i = 0; i < m_h; i++){ 6830 sum = a[i+1] + k[m] * a[m - i]; 6831 a[m - i] += k[m] * a[i+1]; 6832 a[i+1] = sum; 6833 } 6834 a[m+1] = k[m]; 6835 } 6836 } 6837 } 6839 /*----------------------------------------------------------------* 6840 * interpolation between vectors 6841 *---------------------------------------------------------------*/ 6843 void interpolate( 6844 float *out, /* (o) the interpolated vector */ 6845 float *in1, /* (i) the first vector for the interpolation */ 6846 float *in2, /* (i) the second vector for the interpolation */ 6847 float coef, /* (i) interpolation weights */ 6848 int length /* (i) length of all vectors */ 6849 ){ 6850 int i; 6851 float invcoef; 6853 invcoef = (float)1.0 - coef; 6854 for (i = 0; i < length; i++) { 6855 out[i] = coef * in1[i] + invcoef * in2[i]; 6856 } 6857 } 6859 /*----------------------------------------------------------------* 6860 * lpc bandwidth expansion 6861 *---------------------------------------------------------------*/ 6863 void bwexpand( 6864 float *out, /* (o) the bandwidth expanded lpc coefficients */ 6865 float *in, /* (i) the lpc coefficients before bandwidth 6866 expansion */ 6867 float coef, /* (i) the bandwidth expansion factor */ 6868 int length /* (i) the length of lpc coefficient vectors */ 6869 ){ 6870 int i; 6871 float chirp; 6873 chirp = coef; 6875 Andersen et. al. Experimental - Expires September 3rd, 2003 130 6876 out[0] = in[0]; 6877 for (i = 1; i < length; i++) { 6878 out[i] = chirp * in[i]; 6879 chirp *= coef; 6880 } 6881 } 6883 /*----------------------------------------------------------------* 6884 * vector quantization 6885 *---------------------------------------------------------------*/ 6887 void vq( 6888 float *Xq, /* (o) the quantized vector */ 6889 int *index, /* (o) the quantization index */ 6890 const float *CB,/* (i) the vector quantization codebook */ 6891 float *X, /* (i) the vector to quantize */ 6892 int n_cb, /* (i) the number of vectors in the codebook */ 6893 int dim /* (i) the dimension of all vectors */ 6894 ){ 6895 int i, j; 6896 int pos, minindex; 6897 float dist, tmp, mindist; 6899 pos = 0; 6900 mindist = FLOAT_MAX; 6901 minindex = 0; 6902 for (j = 0; j < n_cb; j++) { 6903 dist = X[0] - CB[pos]; 6904 dist *= dist; 6905 for (i = 1; i < dim; i++) { 6906 tmp = X[i] - CB[pos + i]; 6907 dist += tmp*tmp; 6908 } 6910 if (dist < mindist) { 6911 mindist = dist; 6912 minindex = j; 6913 } 6914 pos += dim; 6915 } 6916 for (i = 0; i < dim; i++) { 6917 Xq[i] = CB[minindex*dim + i]; 6918 } 6919 *index = minindex; 6920 } 6922 /*----------------------------------------------------------------* 6923 * split vector quantization 6924 *---------------------------------------------------------------*/ 6926 void SplitVQ( 6927 float *qX, /* (o) the quantized vector */ 6929 Andersen et. al. Experimental - Expires September 3rd, 2003 131 6930 int *index, /* (o) a vector of indexes for all vector 6931 codebooks in the split */ 6932 float *X, /* (i) the vector to quantize */ 6933 const float *CB,/* (i) the quantizer codebook */ 6934 int nsplit, /* the number of vector splits */ 6935 const int *dim, /* the dimension of X and qX */ 6936 const int *cbsize /* the number of vectors in the codebook */ 6937 ){ 6938 int cb_pos, X_pos, i; 6940 cb_pos = 0; 6941 X_pos= 0; 6942 for (i = 0; i < nsplit; i++) { 6943 vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos, 6944 cbsize[i], dim[i]); 6945 X_pos += dim[i]; 6946 cb_pos += dim[i] * cbsize[i]; 6947 } 6948 } 6950 /*----------------------------------------------------------------* 6951 * scalar quantization 6952 *---------------------------------------------------------------*/ 6954 void sort_sq( 6955 float *xq, /* (o) the quantized value */ 6956 int *index, /* (o) the quantization index */ 6957 float x, /* (i) the value to quantize */ 6958 const float *cb,/* (i) the quantization codebook */ 6959 int cb_size /* (i) the size of the quantization codebook */ 6960 ){ 6961 int i; 6963 if (x <= cb[0]) { 6964 *index = 0; 6965 *xq = cb[0]; 6966 } else { 6967 i = 0; 6968 while ((x > cb[i]) && i < cb_size - 1) { 6969 i++; 6970 } 6972 if (x > ((cb[i] + cb[i - 1])/2)) { 6973 *index = i; 6974 *xq = cb[i]; 6975 } else { 6976 *index = i - 1; 6977 *xq = cb[i - 1]; 6978 } 6979 } 6980 } 6982 /*----------------------------------------------------------------* 6984 Andersen et. al. Experimental - Expires September 3rd, 2003 132 6985 * check for stability of lsf coefficients 6986 *---------------------------------------------------------------*/ 6988 int LSF_check( /* (o) 1 for stable lsf vectors and 0 for 6989 nonstable ones */ 6990 float *lsf, /* (i) a table of lsf vectors */ 6991 int dim, /* (i) the dimension of each lsf vector */ 6992 int NoAn /* (i) the number of lsf vectors in the table */ 6993 ){ 6994 int k,n,m, Nit=2, change=0,pos; 6995 float tmp; 6996 static float eps=(float)0.039; /* 50 Hz */ 6997 static float eps2=(float)0.0195; 6998 static float maxlsf=(float)3.14; /* 4000 Hz */ 6999 static float minlsf=(float)0.01; /* 0 Hz */ 7001 /* LSF separation check*/ 7003 for (n=0; nmaxlsf) { 7027 lsf[pos]=maxlsf; 7028 change=1; 7029 } 7030 } 7031 } 7032 } 7034 return change; 7035 } 7037 Andersen et. al. Experimental - Expires September 3rd, 2003 133 7038 A.27 hpInput.h 7040 /****************************************************************** 7042 iLBC Speech Coder ANSI-C Source Code 7044 hpInput.h 7046 Copyright (c) 2001, 7047 Global IP Sound AB. 7048 All rights reserved. 7050 ******************************************************************/ 7052 #ifndef __iLBC_HPINPUT_H 7053 #define __iLBC_HPINPUT_H 7055 void hpInput( 7056 float *In, /* (i) vector to filter */ 7057 int len, /* (i) length of vector to filter */ 7058 float *Out, /* (o) the resulting filtered vector */ 7059 float *mem /* (i/o) the filter state */ 7060 ); 7062 #endif 7064 A.28 hpInput.c 7066 /****************************************************************** 7068 iLBC Speech Coder ANSI-C Source Code 7070 hpInput.c 7072 Copyright (c) 2001, 7073 Global IP Sound AB. 7074 All rights reserved. 7076 ******************************************************************/ 7078 #include "constants.h" 7080 /*----------------------------------------------------------------* 7081 * Input high-pass filter 7082 *---------------------------------------------------------------*/ 7084 void hpInput( 7085 float *In, /* (i) vector to filter */ 7086 int len, /* (i) length of vector to filter */ 7087 float *Out, /* (o) the resulting filtered vector */ 7088 float *mem /* (i/o) the filter state */ 7089 ){ 7091 Andersen et. al. Experimental - Expires September 3rd, 2003 134 7092 int i; 7093 float *pi, *po; 7095 /* all-zero section*/ 7097 pi = &In[0]; 7098 po = &Out[0]; 7099 for (i=0; i 7265 #include "iLBC_define.h" 7266 #include "gainquant.h" 7267 #include "getCBvec.h" 7269 /*----------------------------------------------------------------* 7270 * Convert the codebook indexes to make the search easier 7271 *---------------------------------------------------------------*/ 7273 void index_conv_enc( 7274 int *index /* (i/o) Codebook indexes */ 7275 ){ 7276 int k; 7278 for (k=1; k=108)&&(index[k]<172)) { 7281 index[k]-=64; 7282 } else if (index[k]>=236) { 7283 index[k]-=128; 7284 } else { 7285 /* ERROR */ 7286 } 7287 } 7288 } 7290 void index_conv_dec( 7291 int *index /* (i/o) Codebook indexes */ 7292 ){ 7293 int k; 7295 for (k=1; k=44)&&(index[k]<108)) { 7298 index[k]+=64; 7299 } else if ((index[k]>=108)&&(index[k]<128)) { 7300 index[k]+=128; 7301 } else { 7302 /* ERROR */ 7303 } 7305 Andersen et. al. Experimental - Expires September 3rd, 2003 138 7306 } 7307 } 7309 /*----------------------------------------------------------------* 7310 * Construct decoded vector from codebook and gains. 7311 *---------------------------------------------------------------*/ 7313 void iCBConstruct( 7314 float *decvector, /* (o) Decoded vector */ 7315 int *index, /* (i) Codebook indices */ 7316 int *gain_index,/* (i) Gain quantization indices */ 7317 float *mem, /* (i) Buffer for codevector construction */ 7318 int lMem, /* (i) Length of buffer */ 7319 int veclen, /* (i) Length of vector */ 7320 int nStages /* (i) Number of codebook stages */ 7321 ){ 7322 int j,k; 7323 float gain[CB_NSTAGES]; 7324 float cbvec[SUBL]; 7326 /* gain de-quantization */ 7328 gain[0] = gaindequant(gain_index[0], 1.0, 32); 7329 if (nStages > 1) { 7330 gain[1] = gaindequant(gain_index[1], 7331 (float)fabs(gain[0]), 16); 7332 } 7333 if (nStages > 2) { 7334 gain[2] = gaindequant(gain_index[2], 7335 (float)fabs(gain[1]), 8); 7336 } 7338 /* codebook vector construction and construction of 7339 total vector */ 7341 getCBvec(cbvec, mem, index[0], lMem, veclen); 7342 for (j=0;j 1) { 7346 for (k=1; k 7405 #include 7407 #include "iLBC_define.h" 7408 #include "gainquant.h" 7409 #include "createCB.h" 7410 #include "filter.h" 7412 Andersen et. al. Experimental - Expires September 3rd, 2003 140 7413 #include "constants.h" 7415 /*----------------------------------------------------------------* 7416 * Search routine for codebook encoding and gain quantization. 7417 *---------------------------------------------------------------*/ 7419 void iCBSearch( 7420 iLBC_Enc_Inst_t *iLBCenc_inst, 7421 /* (i) the encoder state structure */ 7422 int *index, /* (o) Codebook indices */ 7423 int *gain_index,/* (o) Gain quantization indices */ 7424 float *intarget,/* (i) Target vector for encoding */ 7425 float *mem, /* (i) Buffer for codebook construction */ 7426 int lMem, /* (i) Length of buffer */ 7427 int lTarget, /* (i) Length of vector */ 7428 int nStages, /* (i) Number of codebook stages */ 7429 float *weightDenum, /* (i) weighting filter coefficients */ 7430 float *weightState, /* (i) weighting filter state */ 7431 int block /* (i) the subblock number */ 7432 ){ 7433 int i, j, icount, stage, best_index, range, counter; 7434 float max_measure, gain, measure, crossDot, ftmp; 7435 float gains[CB_NSTAGES]; 7436 float target[SUBL]; 7437 int base_index, sInd, eInd, base_size; 7438 int sIndAug=0, eIndAug=0; 7439 float buf[CB_MEML+SUBL+2*LPC_FILTERORDER]; 7440 float invenergy[CB_EXPAND*128], energy[CB_EXPAND*128]; 7441 float *pp, *ppi=0, *ppo=0, *ppe=0; 7442 float cbvectors[CB_MEML]; 7443 float tene, cene, cvec[SUBL]; 7444 float aug_vec[SUBL]; 7446 memset(cvec,0,SUBL*sizeof(float)); 7448 /* Determine size of codebook sections */ 7450 base_size=lMem-lTarget+1; 7452 if (lTarget==SUBL) { 7453 base_size=lMem-lTarget+1+lTarget/2; 7454 } 7456 /* setup buffer for weighting */ 7458 memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER); 7459 memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float)); 7460 memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float)); 7462 /* weighting */ 7464 AllPoleFilter(buf+LPC_FILTERORDER, weightDenum, 7465 lMem+lTarget, LPC_FILTERORDER); 7467 Andersen et. al. Experimental - Expires September 3rd, 2003 141 7468 /* Construct the codebook and target needed */ 7470 memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float)); 7472 tene=0.0; 7473 for (i=0; i0.0) { 7518 invenergy[0] = (float) 1.0 / (*ppe + EPS); 7519 } else { 7521 Andersen et. al. Experimental - Expires September 3rd, 2003 142 7522 invenergy[0] = (float) 0.0; 7523 } 7524 ppe++; 7526 measure=(float)-10000000.0; 7528 if (crossDot > 0.0) { 7529 measure = crossDot*crossDot*invenergy[0]; 7530 } 7531 } 7532 else { 7533 measure = crossDot*crossDot*invenergy[0]; 7534 } 7536 /* check if measure is better */ 7537 ftmp = crossDot*invenergy[0]; 7539 if ((measure>max_measure) && (fabs(ftmp)0.0) { 7566 invenergy[icount] = 7567 (float)1.0/(energy[icount]+EPS); 7568 } else { 7569 invenergy[icount] = (float) 0.0; 7570 } 7572 measure=(float)-10000000.0; 7574 if (crossDot > 0.0) { 7576 Andersen et. al. Experimental - Expires September 3rd, 2003 143 7577 measure = crossDot*crossDot*invenergy[icount]; 7578 } 7579 } 7580 else { 7581 measure = crossDot*crossDot*invenergy[icount]; 7582 } 7584 /* check if measure is better */ 7585 ftmp = crossDot*invenergy[icount]; 7587 if ((measure>max_measure) && (fabs(ftmp) range) { 7646 sInd -= (eInd-range); 7647 eInd = range; 7648 } 7649 } else { /* base_index >= (base_size-20) */ 7651 if (sInd < (base_size-20)) { 7652 sIndAug = 20; 7653 sInd = 0; 7654 eInd = 0; 7655 eIndAug = 19 + CB_RESRANGE; 7657 if(eIndAug > 39) { 7658 eInd = eIndAug-39; 7659 eIndAug = 39; 7660 } 7661 } else { 7662 sIndAug = 20 + sInd - (base_size-20); 7663 eIndAug = 39; 7664 sInd = 0; 7665 eInd = CB_RESRANGE - (eIndAug-sIndAug+1); 7666 } 7667 } 7669 } else { /* lTarget = 22 or 23 */ 7671 if (sInd < 0) { 7672 eInd -= sInd; 7673 sInd = 0; 7674 } 7676 if(eInd > range) { 7677 sInd -= (eInd - range); 7678 eInd = range; 7679 } 7680 } 7681 } 7683 /* search of higher codebook section */ 7685 Andersen et. al. Experimental - Expires September 3rd, 2003 145 7686 /* index search range */ 7687 counter = sInd; 7688 sInd += base_size; 7689 eInd += base_size; 7691 if (stage==0) { 7692 ppe = energy+base_size; 7693 *ppe=0.0; 7695 pp=cbvectors+lMem-lTarget; 7696 for (j=0; j0.0) { 7725 invenergy[icount] = (float) 1.0/(energy[icount]+EPS); 7726 } else { 7727 invenergy[icount] = (float) 0.0; 7728 } 7730 if (stage==0) { 7732 measure=(float)-10000000.0; 7734 if (crossDot > 0.0) { 7735 measure = crossDot*crossDot* 7736 invenergy[icount]; 7738 Andersen et. al. Experimental - Expires September 3rd, 2003 146 7739 } 7740 } 7741 else { 7742 measure = crossDot*crossDot*invenergy[icount]; 7743 } 7745 /* check if measure is better */ 7746 ftmp = crossDot*invenergy[icount]; 7748 if ((measure>max_measure) && (fabs(ftmp)CB_MAXGAIN) { 7778 gain = (float)CB_MAXGAIN; 7779 } 7780 gain = gainquant(gain, 1.0, 32, &gain_index[stage]); 7781 } 7782 else { 7783 if (stage==1) { 7784 gain = gainquant(gain, (float)fabs(gains[stage-1]), 7785 16, &gain_index[stage]); 7786 } else { 7787 gain = gainquant(gain, (float)fabs(gains[stage-1]), 7788 8, &gain_index[stage]); 7789 } 7790 } 7792 Andersen et. al. Experimental - Expires September 3rd, 2003 147 7793 /* Extract the best (according to measure) codebook vector */ 7795 if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) { 7797 if (index[stage] 7924 #include 7926 #include "helpfun.h" 7927 #include "lsf.h" 7928 #include "iLBC_define.h" 7929 #include "constants.h" 7931 /*----------------------------------------------------------------* 7932 * interpolation of lsf coefficients for the decoder 7933 *---------------------------------------------------------------*/ 7935 void LSFinterpolate2a_dec( 7936 float *a, /* (o) lpc coefficients for a sub frame */ 7937 float *lsf1, /* (i) first lsf coefficient vector */ 7938 float *lsf2, /* (i) second lsf coefficient vector */ 7939 float coef, /* (i) interpolation weight */ 7940 int length /* (i) length of lsf vectors */ 7941 ){ 7942 float lsftmp[LPC_FILTERORDER]; 7944 interpolate(lsftmp, lsf1, lsf2, coef, length); 7945 lsf2a(a, lsftmp); 7946 } 7948 /*----------------------------------------------------------------* 7949 * obtain dequantized lsf coefficients from quantization index 7950 *---------------------------------------------------------------*/ 7952 Andersen et. al. Experimental - Expires September 3rd, 2003 150 7953 void SimplelsfDEQ( 7954 float *lsfdeq, /* (o) dequantized lsf coefficients */ 7955 int *index, /* (i) quantization index */ 7956 int lpc_n /* (i) number of LPCs */ 7957 ){ 7958 int i, j, pos, cb_pos; 7960 /* decode first LSF */ 7962 pos = 0; 7963 cb_pos = 0; 7964 for (i = 0; i < LSF_NSPLIT; i++) { 7965 for (j = 0; j < dim_lsfCbTbl[i]; j++) { 7966 lsfdeq[pos + j] = lsfCbTbl[cb_pos + 7967 (long)(index[i])*dim_lsfCbTbl[i] + j]; 7968 } 7969 pos += dim_lsfCbTbl[i]; 7970 cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i]; 7971 } 7973 if (lpc_n>1) { 7975 /* decode last LSF */ 7977 pos = 0; 7978 cb_pos = 0; 7979 for (i = 0; i < LSF_NSPLIT; i++) { 7980 for (j = 0; j < dim_lsfCbTbl[i]; j++) { 7981 lsfdeq[LPC_FILTERORDER + pos + j] = 7982 lsfCbTbl[cb_pos + 7983 (long)(index[LSF_NSPLIT + i])* 7984 dim_lsfCbTbl[i] + j]; 7985 } 7986 pos += dim_lsfCbTbl[i]; 7987 cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i]; 7988 } 7989 } 7990 } 7992 /*----------------------------------------------------------------* 7993 * obtain synthesis and weighting filters form lsf coefficients 7994 *---------------------------------------------------------------*/ 7996 void DecoderInterpolateLSF( 7997 float *syntdenum, /* (o) synthesis filter coefficients */ 7998 float *weightdenum, /* (o) weighting denumerator 7999 coefficients */ 8000 float *lsfdeq, /* (i) dequantized lsf coefficients */ 8001 int length, /* (i) length of lsf coefficient vector */ 8002 iLBC_Dec_Inst_t *iLBCdec_inst 8003 /* (i) the decoder state structure */ 8004 ){ 8005 int i, pos, lp_length; 8007 Andersen et. al. Experimental - Expires September 3rd, 2003 151 8008 float lp[LPC_FILTERORDER + 1], *lsfdeq2; 8010 lsfdeq2 = lsfdeq + length; 8011 lp_length = length + 1; 8013 if (iLBCdec_inst->mode==30) { 8014 /* subframe 1: Interpolation between old and first */ 8016 LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, 8017 lsf_weightTbl_30ms[0], length); 8018 memcpy(syntdenum,lp,lp_length*sizeof(float)); 8019 bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); 8021 /* subframes 2 to 6: interpolation between first and last 8022 LSF */ 8024 pos = lp_length; 8025 for (i = 1; i < 6; i++) { 8026 LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2, 8027 lsf_weightTbl_30ms[i], length); 8028 memcpy(syntdenum + pos,lp,lp_length*sizeof(float)); 8029 bwexpand(weightdenum + pos, lp, 8030 LPC_CHIRP_WEIGHTDENUM, lp_length); 8031 pos += lp_length; 8032 } 8033 } 8034 else { 8035 pos = 0; 8036 for (i = 0; i < iLBCdec_inst->nsub; i++) { 8037 LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, 8038 lsf_weightTbl_20ms[i], length); 8039 memcpy(syntdenum+pos,lp,lp_length*sizeof(float)); 8040 bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM, 8041 lp_length); 8042 pos += lp_length; 8043 } 8044 } 8046 /* update memory */ 8048 if (iLBCdec_inst->mode==30) 8049 memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2, 8050 length*sizeof(float)); 8051 else 8052 memcpy(iLBCdec_inst->lsfdeqold, lsfdeq, 8053 length*sizeof(float)); 8055 } 8057 A.37 LPCencode.h 8059 /****************************************************************** 8061 Andersen et. al. Experimental - Expires September 3rd, 2003 152 8062 iLBC Speech Coder ANSI-C Source Code 8064 LPCencode.h 8066 Copyright (c) 2001, 8067 Global IP Sound AB. 8068 All rights reserved. 8070 ******************************************************************/ 8072 #ifndef __iLBC_LPCENCOD_H 8073 #define __iLBC_LPCENCOD_H 8075 void LPCencode( 8076 float *syntdenum, /* (i/o) synthesis filter coefficients 8077 before/after encoding */ 8078 float *weightdenum, /* (i/o) weighting denumerator coefficients 8079 before/after encoding */ 8080 int *lsf_index, /* (o) lsf quantization index */ 8081 float *data, /* (i) lsf coefficients to quantize */ 8082 iLBC_Enc_Inst_t *iLBCenc_inst 8083 /* (i/o) the encoder state structure */ 8084 ); 8086 #endif 8088 A.38 LPCencode.c 8090 /****************************************************************** 8092 iLBC Speech Coder ANSI-C Source Code 8094 LPCencode.c 8096 Copyright (c) 2001, 8097 Global IP Sound AB. 8098 All rights reserved. 8100 ******************************************************************/ 8102 #include 8104 #include "iLBC_define.h" 8105 #include "helpfun.h" 8106 #include "lsf.h" 8107 #include "constants.h" 8109 /*----------------------------------------------------------------* 8110 * lpc analysis (subrutine to LPCencode) 8111 *---------------------------------------------------------------*/ 8113 Andersen et. al. Experimental - Expires September 3rd, 2003 153 8114 void SimpleAnalysis( 8115 float *lsf, /* (o) lsf coefficients */ 8116 float *data, /* (i) new data vector */ 8117 iLBC_Enc_Inst_t *iLBCenc_inst 8118 /* (i/o) the encoder state structure */ 8119 ){ 8120 int k, is; 8121 float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1]; 8122 float lp2[LPC_FILTERORDER + 1]; 8123 float r[LPC_FILTERORDER + 1]; 8125 is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl; 8126 memcpy(iLBCenc_inst->lpc_buffer+is,data, 8127 iLBCenc_inst->blockl*sizeof(float)); 8129 /* No lookahead, last window is asymmetric */ 8131 for (k = 0; k < iLBCenc_inst->lpc_n; k++) { 8133 is = LPC_LOOKBACK; 8135 if (k < (iLBCenc_inst->lpc_n - 1)) { 8136 window(temp, lpc_winTbl, 8137 iLBCenc_inst->lpc_buffer, BLOCKL_MAX); 8138 } else { 8139 window(temp, lpc_asymwinTbl, 8140 iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX); 8141 } 8143 autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER); 8144 window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1); 8146 levdurb(lp, temp, r, LPC_FILTERORDER); 8147 bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1); 8149 a2lsf(lsf + k*LPC_FILTERORDER, lp2); 8150 } 8151 is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl; 8152 memcpy(iLBCenc_inst->lpc_buffer, 8153 iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is, 8154 is*sizeof(float)); 8155 } 8157 /*----------------------------------------------------------------* 8158 * lsf interpolator and conversion from lsf to a coefficients 8159 * (subrutine to SimpleInterpolateLSF) 8160 *---------------------------------------------------------------*/ 8162 void LSFinterpolate2a_enc( 8163 float *a, /* (o) lpc coefficients */ 8164 float *lsf1,/* (i) first set of lsf coefficients */ 8165 float *lsf2,/* (i) second set of lsf coefficients */ 8166 float coef, /* (i) weighting coefficient to use between lsf1 8168 Andersen et. al. Experimental - Expires September 3rd, 2003 154 8169 and lsf2 */ 8170 long length /* (i) length of coefficient vectors */ 8171 ){ 8172 float lsftmp[LPC_FILTERORDER]; 8174 interpolate(lsftmp, lsf1, lsf2, coef, length); 8175 lsf2a(a, lsftmp); 8176 } 8178 /*----------------------------------------------------------------* 8179 * lsf interpolator (subrutine to LPCencode) 8180 *---------------------------------------------------------------*/ 8182 void SimpleInterpolateLSF( 8183 float *syntdenum, /* (o) the synthesis filter denominator 8184 resulting from the quantized 8185 interpolated lsf */ 8186 float *weightdenum, /* (o) the weighting filter denominator 8187 resulting from the unquantized 8188 interpolated lsf */ 8189 float *lsf, /* (i) the unquantized lsf coefficients */ 8190 float *lsfdeq, /* (i) the dequantized lsf coefficients */ 8191 float *lsfold, /* (i) the unquantized lsf coefficients of 8192 the previous signal frame */ 8193 float *lsfdeqold, /* (i) the dequantized lsf coefficients of 8194 the previous signal frame */ 8195 int length, /* (i) should equate LPC_FILTERORDER */ 8196 iLBC_Enc_Inst_t *iLBCenc_inst 8197 /* (i/o) the encoder state structure */ 8198 ){ 8199 int i, pos, lp_length; 8200 float lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2; 8202 lsf2 = lsf + length; 8203 lsfdeq2 = lsfdeq + length; 8204 lp_length = length + 1; 8206 if (iLBCenc_inst->mode==30) { 8207 /* subframe 1: Interpolation between old and first set of 8208 lsf coefficients */ 8210 LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, 8211 lsf_weightTbl_30ms[0], length); 8212 memcpy(syntdenum,lp,lp_length*sizeof(float)); 8213 LSFinterpolate2a_enc(lp, lsfold, lsf, 8214 lsf_weightTbl_30ms[0], length); 8215 bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); 8217 /* subframe 2 to 6: Interpolation between first and second 8218 set of lsf coefficients */ 8220 pos = lp_length; 8221 for (i = 1; i < iLBCenc_inst->nsub; i++) { 8223 Andersen et. al. Experimental - Expires September 3rd, 2003 155 8224 LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2, 8225 lsf_weightTbl_30ms[i], length); 8226 memcpy(syntdenum + pos,lp,lp_length*sizeof(float)); 8228 LSFinterpolate2a_enc(lp, lsf, lsf2, 8229 lsf_weightTbl_30ms[i], length); 8230 bwexpand(weightdenum + pos, lp, 8231 LPC_CHIRP_WEIGHTDENUM, lp_length); 8232 pos += lp_length; 8233 } 8234 } 8235 else { 8236 pos = 0; 8237 for (i = 0; i < iLBCenc_inst->nsub; i++) { 8238 LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, 8239 lsf_weightTbl_20ms[i], length); 8240 memcpy(syntdenum+pos,lp,lp_length*sizeof(float)); 8241 LSFinterpolate2a_enc(lp, lsfold, lsf, 8242 lsf_weightTbl_20ms[i], length); 8243 bwexpand(weightdenum+pos, lp, 8244 LPC_CHIRP_WEIGHTDENUM, lp_length); 8245 pos += lp_length; 8246 } 8247 } 8249 /* update memory */ 8251 if (iLBCenc_inst->mode==30) { 8252 memcpy(lsfold, lsf2, length*sizeof(float)); 8253 memcpy(lsfdeqold, lsfdeq2, length*sizeof(float)); 8254 } 8255 else { 8256 memcpy(lsfold, lsf, length*sizeof(float)); 8257 memcpy(lsfdeqold, lsfdeq, length*sizeof(float)); 8258 } 8259 } 8261 /*----------------------------------------------------------------* 8262 * lsf quantizer (subrutine to LPCencode) 8263 *---------------------------------------------------------------*/ 8265 void SimplelsfQ( 8266 float *lsfdeq, /* (o) dequantized lsf coefficients 8267 (dimension FILTERORDER) */ 8268 int *index, /* (o) quantization index */ 8269 float *lsf, /* (i) the lsf coefficient vector to be 8270 quantized (dimension FILTERORDER ) */ 8271 int lpc_n /* (i) number of lsf sets to quantize */ 8272 ){ 8273 /* Quantize first LSF with memoryless split VQ */ 8274 SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT, 8275 dim_lsfCbTbl, size_lsfCbTbl); 8277 Andersen et. al. Experimental - Expires September 3rd, 2003 156 8278 if (lpc_n==2) { 8279 /* Quantize second LSF with memoryless split VQ */ 8280 SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT, 8281 lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT, 8282 dim_lsfCbTbl, size_lsfCbTbl); 8283 } 8284 } 8286 /*----------------------------------------------------------------* 8287 * lpc encoder 8288 *---------------------------------------------------------------*/ 8290 void LPCencode( 8291 float *syntdenum, /* (i/o) synthesis filter coefficients 8292 before/after encoding */ 8293 float *weightdenum, /* (i/o) weighting denumerator coefficients 8294 before/after encoding */ 8295 int *lsf_index, /* (o) lsf quantization index */ 8296 float *data, /* (i) lsf coefficients to quantize */ 8297 iLBC_Enc_Inst_t *iLBCenc_inst 8298 /* (i/o) the encoder state structure */ 8299 ){ 8300 float lsf[LPC_FILTERORDER * LPC_N_MAX]; 8301 float lsfdeq[LPC_FILTERORDER * LPC_N_MAX]; 8302 int change=0; 8304 SimpleAnalysis(lsf, data, iLBCenc_inst); 8305 SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n); 8306 change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n); 8307 SimpleInterpolateLSF(syntdenum, weightdenum, 8308 lsf, lsfdeq, iLBCenc_inst->lsfold, 8309 iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst); 8310 } 8312 A.39 lsf.h 8314 /****************************************************************** 8316 iLBC Speech Coder ANSI-C Source Code 8318 lsf.h 8320 Copyright (c) 2001, 8321 Global IP Sound AB. 8322 All rights reserved. 8324 ******************************************************************/ 8326 #ifndef __iLBC_LSF_H 8327 #define __iLBC_LSF_H 8329 Andersen et. al. Experimental - Expires September 3rd, 2003 157 8330 void a2lsf( 8331 float *freq,/* (o) lsf coefficients */ 8332 float *a /* (i) lpc coefficients */ 8333 ); 8335 void lsf2a( 8336 float *a_coef, /* (o) lpc coefficients */ 8337 float *freq /* (i) lsf coefficients */ 8338 ); 8340 #endif 8342 A.40 lsf.c 8344 /****************************************************************** 8346 iLBC Speech Coder ANSI-C Source Code 8348 lsf.c 8350 Copyright (c) 2001, 8351 Global IP Sound AB. 8352 All rights reserved. 8354 ******************************************************************/ 8356 #include 8357 #include 8359 #include "iLBC_define.h" 8361 /*----------------------------------------------------------------* 8362 * conversion from lpc coefficients to lsf coefficients 8363 *---------------------------------------------------------------*/ 8365 void a2lsf( 8366 float *freq,/* (o) lsf coefficients */ 8367 float *a /* (i) lpc coefficients */ 8368 ){ 8369 float steps[LSF_NUMBER_OF_STEPS] = 8370 {(float)0.00635, (float)0.003175, (float)0.0015875, 8371 (float)0.00079375}; 8372 float step; 8373 int step_idx; 8374 int lsp_index; 8375 float p[LPC_HALFORDER]; 8376 float q[LPC_HALFORDER]; 8377 float p_pre[LPC_HALFORDER]; 8378 float q_pre[LPC_HALFORDER]; 8379 float old_p, old_q, *old; 8380 float *pq_coef; 8381 float omega, old_omega; 8383 Andersen et. al. Experimental - Expires September 3rd, 2003 158 8384 int i; 8385 float hlp, hlp1, hlp2, hlp3, hlp4, hlp5; 8387 for (i=0; i= 0.5)){ 8447 if (step_idx == (LSF_NUMBER_OF_STEPS - 1)){ 8449 if (fabs(hlp5) >= fabs(*old)) { 8450 freq[lsp_index] = omega - step; 8451 } else { 8452 freq[lsp_index] = omega; 8453 } 8455 if ((*old) >= 0.0){ 8456 *old = (float)-1.0 * FLOAT_MAX; 8457 } else { 8458 *old = FLOAT_MAX; 8459 } 8461 omega = old_omega; 8462 step_idx = 0; 8464 step_idx = LSF_NUMBER_OF_STEPS; 8465 } else { 8467 if (step_idx == 0) { 8468 old_omega = omega; 8469 } 8471 step_idx++; 8472 omega -= steps[step_idx]; 8474 /* Go back one grid step */ 8476 step = steps[step_idx]; 8477 } 8478 } else { 8480 /* increment omega until they are of different sign, 8481 and we know there is at least one root between omega 8482 and old_omega */ 8483 *old = hlp5; 8484 omega += step; 8485 } 8486 } 8487 } 8489 Andersen et. al. Experimental - Expires September 3rd, 2003 160 8490 for (i = 0; i= 0.5)){ 8522 if (freq[0] <= 0.0) { 8523 freq[0] = (float)0.022; 8524 } 8526 if (freq[LPC_FILTERORDER - 1] >= 0.5) { 8527 freq[LPC_FILTERORDER - 1] = (float)0.499; 8528 } 8530 hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) / 8531 (float) (LPC_FILTERORDER - 1); 8533 for (i=1; i 8677 #include 8679 #include "iLBC_define.h" 8680 #include "constants.h" 8681 #include "helpfun.h" 8682 #include "string.h" 8684 /*----------------------------------------------------------------* 8685 * splitting an integer into first most significant bits and 8686 * remaining least significant bits 8687 *---------------------------------------------------------------*/ 8689 void packsplit( 8690 int *index, /* (i) the value to split */ 8691 int *firstpart, /* (o) the value specified by most 8692 significant bits */ 8693 int *rest, /* (o) the value specified by least 8694 significant bits */ 8695 int bitno_firstpart, /* (i) number of bits in most 8696 significant part */ 8697 int bitno_total /* (i) number of bits in full range 8698 of value */ 8699 ){ 8700 int bitno_rest = bitno_total-bitno_firstpart; 8702 Andersen et. al. Experimental - Expires September 3rd, 2003 164 8703 *firstpart = *index>>(bitno_rest); 8704 *rest = *index-(*firstpart<<(bitno_rest)); 8705 } 8707 /*----------------------------------------------------------------* 8708 * combining a value corresponding to msb's with a value 8709 * corresponding to lsb's 8710 *---------------------------------------------------------------*/ 8712 void packcombine( 8713 int *index, /* (i/o) the msb value in the 8714 combined value out */ 8715 int rest, /* (i) the lsb value */ 8716 int bitno_rest /* (i) the number of bits in the 8717 lsb part */ 8718 ){ 8719 *index = *index<0) { 8749 /* Jump to the next byte if end of this byte is reached*/ 8751 if (*pos==8) { 8752 *pos=0; 8753 (*bitstream)++; 8754 **bitstream=0; 8756 Andersen et. al. Experimental - Expires September 3rd, 2003 165 8757 } 8759 posLeft=8-(*pos); 8761 /* Insert index into the bitstream */ 8763 if (bitno <= posLeft) { 8764 **bitstream |= (unsigned char)(index<<(posLeft-bitno)); 8765 *pos+=bitno; 8766 bitno=0; 8767 } else { 8768 **bitstream |= (unsigned char)(index>>(bitno-posLeft)); 8770 *pos=8; 8771 index-=((index>>(bitno-posLeft))<<(bitno-posLeft)); 8773 bitno-=posLeft; 8774 } 8775 } 8776 } 8778 /*----------------------------------------------------------------* 8779 * unpacking of bits from bitstream, i.e., vector of bytes 8780 *---------------------------------------------------------------*/ 8782 void unpack( 8783 unsigned char **bitstream, /* (i/o) on entrance pointer to 8784 place in bitstream to 8785 unpack new data from, on 8786 exit pointer to place in 8787 bitstream to unpack future 8788 data from */ 8789 int *index, /* (o) resulting value */ 8790 int bitno, /* (i) number of bits used to 8791 represent the value */ 8792 int *pos /* (i/o) read position in the 8793 current byte */ 8794 ){ 8795 int BitsLeft; 8797 *index=0; 8799 while (bitno>0) { 8801 /* move forward in bitstream when the end of the 8802 byte is reached */ 8804 if (*pos==8) { 8805 *pos=0; 8806 (*bitstream)++; 8807 } 8809 BitsLeft=8-(*pos); 8811 Andersen et. al. Experimental - Expires September 3rd, 2003 166 8812 /* Extract bits to index */ 8814 if (BitsLeft>=bitno) { 8815 *index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno)); 8817 *pos+=bitno; 8818 bitno=0; 8819 } else { 8821 if ((8-bitno)>0) { 8822 *index+=((((**bitstream)<<(*pos)) & 0xFF)>> 8823 (8-bitno)); 8824 *pos=8; 8825 } else { 8826 *index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<< 8827 (bitno-8)); 8828 *pos=8; 8829 } 8830 bitno-=BitsLeft; 8831 } 8832 } 8833 } 8835 A.43 StateConstructW.h 8837 /****************************************************************** 8839 iLBC Speech Coder ANSI-C Source Code 8841 StateConstructW.h 8843 Copyright (c) 2001, 8844 Global IP Sound AB. 8845 All rights reserved. 8847 ******************************************************************/ 8849 #ifndef __iLBC_STATECONSTRUCTW_H 8850 #define __iLBC_STATECONSTRUCTW_H 8852 void StateConstructW( 8853 int idxForMax, /* (i) 6-bit index for the quantization of 8854 max amplitude */ 8855 int *idxVec, /* (i) vector of quantization indexes */ 8856 float *syntDenum, /* (i) synthesis filter denumerator */ 8857 float *out, /* (o) the decoded state vector */ 8858 int len /* (i) length of a state vector */ 8859 ); 8861 #endif 8863 Andersen et. al. Experimental - Expires September 3rd, 2003 167 8864 A.44 StateConstructW.c 8866 /****************************************************************** 8868 iLBC Speech Coder ANSI-C Source Code 8870 StateConstructW.c 8872 Copyright (c) 2001, 8873 Global IP Sound AB. 8874 All rights reserved. 8876 ******************************************************************/ 8878 #include 8879 #include 8881 #include "iLBC_define.h" 8882 #include "constants.h" 8883 #include "filter.h" 8885 /*----------------------------------------------------------------* 8886 * decoding of the start state 8887 *---------------------------------------------------------------*/ 8889 void StateConstructW( 8890 int idxForMax, /* (i) 6-bit index for the quantization of 8891 max amplitude */ 8892 int *idxVec, /* (i) vector of quantization indexes */ 8893 float *syntDenum, /* (i) synthesis filter denumerator */ 8894 float *out, /* (o) the decoded state vector */ 8895 int len /* (i) length of a state vector */ 8896 ){ 8897 float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp, 8898 numerator[LPC_FILTERORDER+1]; 8899 float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout; 8900 int k,tmpi; 8902 /* decoding of the maximum value */ 8904 maxVal = state_frgqTbl[idxForMax]; 8905 maxVal = (float)pow(10,maxVal)/(float)4.5; 8907 /* initialization of buffers and coefficients */ 8909 memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float)); 8910 memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float)); 8911 for (k=0; k 9001 #include 9003 #include "iLBC_define.h" 9004 #include "constants.h" 9005 #include "filter.h" 9006 #include "helpfun.h" 9008 /*----------------------------------------------------------------* 9009 * predictive noise shaping encoding of scaled start state 9010 * (subrutine for StateSearchW) 9011 *---------------------------------------------------------------*/ 9013 void AbsQuantW( 9014 iLBC_Enc_Inst_t *iLBCenc_inst, 9015 /* (i) Encoder instance */ 9016 float *in, /* (i) vector to encode */ 9017 float *syntDenum, /* (i) denominator of synthesis filter */ 9018 float *weightDenum, /* (i) denominator of weighting filter */ 9019 int *out, /* (o) vector of quantizer indexes */ 9020 int len, /* (i) length of vector to encode and 9021 vector of quantizer indexes */ 9022 int state_first /* (i) position of start state in the 9024 Andersen et. al. Experimental - Expires September 3rd, 2003 170 9025 80 vec */ 9026 ){ 9027 float *syntOut, syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS]; 9028 float toQ, xq; 9029 int n; 9030 int index; 9032 /* initialization of buffer for filtering */ 9034 memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float)); 9036 /* initialization of pointer for filtering */ 9038 syntOut = &syntOutBuf[LPC_FILTERORDER]; 9040 /* synthesis and weighting filters on input */ 9042 if (state_first) { 9043 AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER); 9044 } else { 9045 AllPoleFilter (in, weightDenum, 9046 iLBCenc_inst->state_short_len-SUBL, 9047 LPC_FILTERORDER); 9048 } 9050 /* encoding loop */ 9052 for (n=0; nstate_short_len-SUBL))) { 9066 syntDenum += (LPC_FILTERORDER+1); 9067 weightDenum += (LPC_FILTERORDER+1); 9069 /* synthesis and weighting filters on input */ 9070 AllPoleFilter (&in[n], weightDenum, len-n, 9071 LPC_FILTERORDER); 9073 } 9075 /* prediction of synthesized and weighted input */ 9077 syntOut[n] = 0.0; 9079 Andersen et. al. Experimental - Expires September 3rd, 2003 171 9080 AllPoleFilter (&syntOut[n], weightDenum, 1, LPC_FILTERORDER); 9082 /* quantization */ 9084 toQ = in[n]-syntOut[n]; 9085 sort_sq(&xq, &index, toQ, state_sq3Tbl, 8); 9086 out[n]=index; 9087 syntOut[n] = state_sq3Tbl[out[n]]; 9089 /* update of the prediction filter */ 9091 AllPoleFilter(&syntOut[n], weightDenum, 1, LPC_FILTERORDER); 9092 } 9093 } 9095 /*----------------------------------------------------------------* 9096 * encoding of start state 9097 *---------------------------------------------------------------*/ 9099 void StateSearchW( 9100 iLBC_Enc_Inst_t *iLBCenc_inst, 9101 /* (i) Encoder instance */ 9102 float *residual,/* (i) target residual vector */ 9103 float *syntDenum, /* (i) lpc synthesis filter */ 9104 float *weightDenum, /* (i) weighting filter denuminator */ 9105 int *idxForMax, /* (o) quantizer index for maximum 9106 amplitude */ 9107 int *idxVec, /* (o) vector of quantization indexes */ 9108 int len, /* (i) length of all vectors */ 9109 int state_first /* (i) position of start state in the 9110 80 vec */ 9111 ){ 9112 float dtmp, maxVal; 9113 float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS]; 9114 float *tmp, numerator[1+LPC_FILTERORDER]; 9115 float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout; 9116 int k; 9117 float qmax, scal; 9119 /* initialization of buffers and filter coefficients */ 9121 memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float)); 9122 memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float)); 9123 for (k=0; k maxVal*maxVal){ 9148 maxVal = fout[k]; 9149 } 9150 } 9151 maxVal=(float)fabs(maxVal); 9153 /* encoding of the maximum amplitude value */ 9155 if (maxVal < 10.0) { 9156 maxVal = 10.0; 9157 } 9158 maxVal = (float)log10(maxVal); 9159 sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64); 9161 /* decoding of the maximum amplitude representation value, 9162 and corresponding scaling of start state */ 9164 maxVal=state_frgqTbl[*idxForMax]; 9165 qmax = (float)pow(10,maxVal); 9166 scal = (float)(4.5)/qmax; 9167 for (k=0; k