idnits 2.17.1 draft-ietf-avt-ilbc-codec-05.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** It looks like you're using RFC 3978 boilerplate. You should update this to the boilerplate described in the IETF Trust License Policy document (see https://trustee.ietf.org/license-info), which is required now. -- Found old boilerplate from RFC 3979, Section 5, paragraph 1 on line 2216. -- Found old boilerplate from RFC 3979, Section 5, paragraph 2 on line 2223. -- Found old boilerplate from RFC 3979, Section 5, paragraph 3 on line 2229. ** Found boilerplate matching RFC 3978, Section 5.4, paragraph 1 (on line 9659), which is fine, but *also* found old RFC 2026, Section 10.4C, paragraph 1 text on line 9659. ** The document seems to lack an RFC 3978 Section 5.1 IPR Disclosure Acknowledgement -- however, there's a paragraph with a matching beginning. Boilerplate error? ** This document has an original RFC 3978 Section 5.4 Copyright Line, instead of the newer IETF Trust Copyright according to RFC 4748. ** The document seems to lack an RFC 3978 Section 5.4 Reference to BCP 78 -- however, there's a paragraph with a matching beginning. Boilerplate error? ** The document seems to lack an RFC 3978 Section 5.5 (updated by RFC 4748) Disclaimer -- however, there's a paragraph with a matching beginning. Boilerplate error? Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- ** The document seems to lack a 1id_guidelines paragraph about Internet-Drafts being working documents. ** The document seems to lack a 1id_guidelines paragraph about 6 months document validity. ** The document seems to lack a 1id_guidelines paragraph about the list of current Internet-Drafts. ** The document seems to lack a 1id_guidelines paragraph about the list of Shadow Directories. == The page length should not exceed 58 lines per page, but there was 1 longer page, the longest (page 1) being 10191 lines Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- == 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: ---------------------------------------------------------------------------- == The copyright year in the RFC 3978 Section 5.4 Copyright Line does not match the current year == Line 1173 has weird spacing: '... pi pp ...' == Line 1201 has weird spacing: '... pi pp ...' == Line 3330 has weird spacing: '...samples in th...' == Line 4087 has weird spacing: '...ern int dim_...' == Line 4088 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 9584, but not defined == Missing Reference: '64' is mentioned on line 4222, but not defined == Missing Reference: '8' is mentioned on line 4216, but not defined == Missing Reference: '6' is mentioned on line 6091, but not defined -- Looks like a reference, but probably isn't: '-st' on line 5807 -- Looks like a reference, but probably isn't: '-orderCoef' on line 6426 -- Looks like a reference, but probably isn't: '-1' on line 6426 -- Looks like a reference, but probably isn't: '-k' on line 6399 -- Looks like a reference, but probably isn't: 'SUBL-l-1' on line 6614 -- Looks like a reference, but probably isn't: 'SUBL' on line 7828 Summary: 10 errors (**), 0 flaws (~~), 13 warnings (==), 12 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 1 Internet Draft S. V. Andersen 2 Document: draft-ietf-avt-ilbc-codec-05.txt Aalborg University 3 Category: Experimental A. Duric 4 May 29th, 2004 Telio 5 Expires: November 29th, 2004 H. Astrom 6 R. Hagen 7 W. B. Kleijn 8 J. Linden 9 Global IP Sound 11 Internet Low Bit Rate Codec 13 Status of this Memo 15 This document specifies an Internet experimental standards track 16 protocol for the Internet community, and requests discussion and 17 suggestions for improvements. Please refer to the current edition of 18 the "Internet Official Protocol Standards" (STD 1) for the 19 standardization state and status of this protocol. Distribution of 20 this memo is unlimited. 22 By submitting this Internet-Draft, we certify that any applicable 23 patent or other IPR claims of which we am aware have been disclosed, 24 and any of which we become aware will be disclosed, in accordance 25 with RFC 3668. 27 Copyright Notice 29 Copyright (C) The Internet Society (2004). All Rights Reserved. 31 Abstract 33 This document specifies a speech codec suitable for robust voice 34 communication over IP. The codec is developed by Global IP Sound 35 (GIPS). It is designed for narrow band speech and results in a 36 payload bit rate of 13.33 kbit/s for 30 ms frames and 15.20 kbit/s 37 for 20 ms frames. The codec enables graceful speech quality 38 degradation in the case of lost frames, which occurs in connection 39 with lost or delayed IP packets. 41 Andersen et. al. 1 42 Internet Low Bit Rate Codec May 04 44 Table of Contents 46 Status of this Memo................................................1 47 Copyright Notice...................................................1 48 Abstract...........................................................1 49 Table of Contents..................................................2 50 1. INTRODUCTION....................................................5 51 2. OUTLINE OF THE CODEC............................................5 52 2.1 Encoder........................................................6 53 2.2 Decoder........................................................7 54 3. ENCODER PRINCIPLES..............................................8 55 3.1 Pre-processing.................................................9 56 3.2 LPC Analysis and Quantization..................................9 57 3.2.1 Computation of Autocorrelation Coefficients..................9 58 3.2.2 Computation of LPC Coefficients.............................11 59 3.2.3 Computation of LSF Coefficients from LPC Coefficients.......11 60 3.2.4 Quantization of LSF Coefficients............................11 61 3.2.5 Stability Check of LSF Coefficients.........................12 62 3.2.6 Interpolation of LSF Coefficients...........................12 63 3.2.7 LPC Analysis and Quantization for 20 ms frames..............13 64 3.3 Calculation of the Residual...................................14 65 3.4 Perceptual Weighting Filter...................................14 66 3.5 Start State Encoder...........................................15 67 3.5.1 Start State Estimation......................................15 68 3.5.2 All-Pass Filtering and Scale Quantization...................16 69 3.5.3 Scalar Quantization.........................................17 70 3.6 Encoding the remaining samples................................17 71 3.6.1 Codebook Memory.............................................19 72 3.6.2 Perceptual Weighting of Codebook Memory and Target..........20 73 3.6.3 Codebook Creation...........................................21 74 3.6.3.1 Creation of a Base Codebook...............................21 75 3.6.3.2 Codebook Expansion........................................22 76 3.6.3.3 Codebook Augmentation.....................................22 77 3.6.4 Codebook Search.............................................23 78 3.6.4.1 Codebook Search at Each Stage.............................24 79 3.6.4.2 Gain Quantization at Each Stage...........................24 80 3.6.4.3 Preparation of Target for Next Stage......................26 81 3.7 Gain Correction Encoding......................................26 82 3.8 Bitstream Definition..........................................27 83 4. DECODER PRINCIPLES.............................................30 84 4.1 LPC Filter Reconstruction.....................................30 85 4.2 Start State Reconstruction....................................31 86 4.3 Excitation Decoding Loop......................................31 87 4.4 Multistage Adaptive Codebook Decoding.........................32 88 4.4.1 Construction of the Decoded Excitation Signal...............32 89 4.5 Packet Loss Concealment.......................................33 90 4.5.1 Block Received Correctly and Previous Block also Received...33 92 Andersen et. al. Experimental - Expires November 29th, 2004 2 93 Internet Low Bit Rate Codec May 04 95 4.5.2 Block Not Received..........................................33 96 4.5.3 Block Received Correctly When Previous Block Not Received...34 97 4.6 Enhancement...................................................34 98 4.6.1 Estimating the pitch........................................36 99 4.6.2 Determination of the Pitch-Synchronous Sequences............36 100 4.6.3 Calculation of the smoothed excitation......................37 101 4.6.4 Enhancer criterion..........................................38 102 4.6.5 Enhancing the excitation....................................38 103 4.7 Synthesis Filtering...........................................39 104 4.8 Post Filtering................................................39 105 5. IANA CONSIDERATIONS............................................39 106 6. SECURITY CONSIDERATIONS........................................39 107 7. EVALUATION OF THE ILBC IMPLEMENTATIONS.........................39 108 8. REFERENCES.....................................................40 109 8.1 Normative.....................................................40 110 8.2 Informative...................................................40 111 9. ACKNOWLEDGEMENTS...............................................40 112 10. AUTHOR'S ADDRESSES............................................41 113 Full Copyright Statement..........................................42 114 Intellectual Property.............................................42 115 APPENDIX A REFERENCE IMPLEMENTATION...............................43 116 A.1 iLBC_test.c...................................................44 117 A.2 iLBC_encode.h.................................................49 118 A.3 iLBC_encode.c.................................................50 119 A.4 iLBC_decode.h.................................................59 120 A.5 iLBC_decode.c.................................................60 121 A.6 iLBC_define.h.................................................71 122 A.7 constants.h...................................................74 123 A.8 constants.c...................................................76 124 A.9 anaFilter.h...................................................89 125 A.10 anaFilter.c..................................................89 126 A.11 createCB.h...................................................90 127 A.12 createCB.c...................................................91 128 A.13 doCPLC.h.....................................................95 129 A.14 doCPLC.c.....................................................96 130 A.15 enhancer.h..................................................101 131 A.16 enhancer.c..................................................101 132 A.17 filter.h....................................................113 133 A.18 filter.c....................................................114 134 A.19 FrameClassify.h.............................................117 135 A.20 FrameClassify.c.............................................118 136 A.21 gainquant.h.................................................120 137 A.22 gainquant.c.................................................120 138 A.23 getCBvec.h..................................................122 139 A.24 getCBvec.c..................................................123 140 A.25 helpfun.h...................................................126 141 A.26 helpfun.c...................................................128 143 Andersen et. al. Experimental - Expires November 29th, 2004 3 144 Internet Low Bit Rate Codec May 04 146 A.27 hpInput.h...................................................133 147 A.28 hpInput.c...................................................134 148 A.29 hpOutput.h..................................................135 149 A.30 hpOutput.c..................................................135 150 A.31 iCBConstruct.h..............................................136 151 A.32 iCBConstruct.c..............................................137 152 A.33 iCBSearch.h.................................................139 153 A.34 iCBSearch.c.................................................140 154 A.35 LPCdecode.h.................................................148 155 A.36 LPCdecode.c.................................................149 156 A.37 LPCencode.h.................................................152 157 A.38 LPCencode.c.................................................152 158 A.39 lsf.h.......................................................156 159 A.40 lsf.c.......................................................157 160 A.41 packing.h...................................................162 161 A.42 packing.c...................................................163 162 A.43 StateConstructW.h...........................................166 163 A.44 StateConstructW.c...........................................166 164 A.45 StateSearchW.h..............................................168 165 A.46 StateSearchW.c..............................................169 166 A.47 syntFilter.h................................................172 167 A.48 syntFilter.c................................................173 169 Andersen et. al. Experimental - Expires November 29th, 2004 4 170 Internet Low Bit Rate Codec May 04 172 1. INTRODUCTION 174 This document contains the description of an algorithm for the 175 coding of speech signals sampled at 8 kHz. The algorithm, called 176 iLBC, uses a block-independent linear-predictive coding (LPC) 177 algorithm and has support for two basic frame lengths: 20 ms at 15.2 178 kbit/s and 30 ms at 13.33 kbit/s. When the codec operates at block 179 lengths of 20 ms, it produces 304 bits per block which SHOULD be 180 packetized as in [1]. Similarly, for block lengths of 30 ms it 181 produces 400 bits per block which SHOULD be packetized as in [1]. 182 The two modes for the different frame sizes operate in a very 183 similar way. When they differ it is explicitly stated in the text, 184 usually with the notation x/y, where x refers to the 20 ms mode and 185 y refers to the 30 ms mode. 187 The described algorithm results in a speech coding system with a 188 controlled response to packet losses similar to what is known from 189 pulse code modulation (PCM) with packet loss concealment (PLC), such 190 as the ITU-T G.711 standard [4] which operates at a fixed bit rate 191 of 64 kbit/s. At the same time, the described algorithm enables 192 fixed bit rate coding with a quality-versus-bit rate tradeoff close 193 to state-of-the-art. A suitable RTP payload format for the iLBC 194 codec is specified in [1]. 196 Some of the applications for which this coder is suitable are: real 197 time communications such as telephony and videoconferencing, 198 streaming audio, archival, and messaging. 200 Cable Television Laboratories (CableLabs(R)) intends to adapt iLBC 201 as a PacketCable(TM) audio codec standard for VoIP over Cable 202 applications [3]. 204 This document is organized as follows. In Section 2 a brief outline 205 of the codec is given. The specific encoder and decoder algorithms 206 are explained in Sections 3 and 4, respectively. A c-code reference 207 implementation is provided in Appendix A. 209 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 210 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in 211 this document are to be interpreted as described in RFC 2119 [2]. 213 2. OUTLINE OF THE CODEC 215 The codec consists of an encoder and a decoder described in Section 216 2.1 and 2.2, respectively. 218 The essence of the codec is LPC and block based coding of the LPC 219 residual signal. For each 160/240 (20ms/30 ms) sample block, the 220 following major steps are performed: A set of LPC filters are 221 computed and the speech signal is filtered through them to produce 222 the residual signal. The codec uses scalar quantization of the 223 dominant part, in terms of energy, of the residual signal for the 224 block. The dominant state is of length 57/58 (20 ms/30 ms) samples 226 Andersen et. al. Experimental - Expires November 29th, 2004 5 227 Internet Low Bit Rate Codec May 04 229 and forms a start state for dynamic codebooks constructed from the 230 already coded parts of the residual signal. These dynamic codebooks 231 are used to code the remaining parts of the residual signal. By this 232 method, coding independence between blocks is achieved, resulting in 233 elimination of propagation of perceptual degradations due to packet 234 loss. The method facilitates high-quality packet loss concealment 235 (PLC). 237 2.1 Encoder 239 The input to the encoder SHOULD be 16 bit uniform PCM sampled at 8 240 kHz. It SHOULD be partitioned into blocks of BLOCKL=160/240 samples 241 for the 20/30 ms frame size. Each block is divided into NSUB=4/6 242 consecutive sub-blocks of SUBL=40 samples each. For 30 ms frame 243 size, the encoder performs two LPC_FILTERORDER=10 linear-predictive 244 coding (LPC) analyses. The first analysis applies a smooth window 245 centered over the 2nd sub-block and extending to the middle of the 246 5th sub-block. The second LPC analysis applies a smooth asymmetric 247 window centered over the 5th sub-block and extending to the end of 248 the 6th sub-block. For 20 ms frame size one LPC_FILTERORDER=10 249 linear-predictive coding (LPC) analysis is performed with a smooth 250 window centered over the 3rd sub-frame. 252 For each of the LPC analyses, a set of line-spectral frequencies 253 (LSFs) are obtained, quantized and interpolated to obtain LSF 254 coefficients for each sub-block. Subsequently, the LPC residual is 255 computed using the quantized and interpolated LPC analysis filters. 257 The two consecutive sub-blocks of the residual exhibiting the 258 maximal weighted energy are identified. Within these 2 sub-blocks, 259 the start state (segment) is selected from two choices: the first 260 57/58 samples or the last 57/58 samples of the 2 consecutive sub- 261 blocks. The selected segment is the one of higher energy. The start 262 state is encoded with scalar quantization. 264 A dynamic codebook encoding procedure is used to encode 1) the 23/22 265 (20 ms/30 ms) remaining samples in the 2 sub-blocks containing the 266 start state; 2) encoding of the sub-blocks after the start state in 267 time; 3) encoding of the sub-blocks before the start state in time. 268 Thus, the encoding target can be either the 23/22 samples remaining 269 of the 2 sub-blocks containing the start state or a 40 sample sub- 270 block. This target can consist of samples that are indexed forwards 271 in time or backwards in time depending on the location of the start 272 state. 274 The coding is based on an adaptive codebook that is built from a 275 codebook memory which contains decoded LPC excitation samples from 276 the already encoded part of the block. These samples are indexed in 277 the same time direction as the target vector and ending at the 278 sample instant prior to the first sample instant represented in the 279 target vector. The codebook is used in CB_NSTAGES=3 stages in a 280 successive refinement approach and the resulting 3 code vector gains 281 are encoded with 5, 4, and 3 bit scalar quantization, respectively. 283 Andersen et. al. Experimental - Expires November 29th, 2004 6 284 Internet Low Bit Rate Codec May 04 286 The codebook search method employs noise shaping derived from the 287 LPC filters and the main decision criterion is minimizing the 288 squared error between the target vector and the code vectors. Each 289 code vector in this codebook comes from one of CB_EXPAND=2 codebook 290 sections. The first section is filled with delayed, already encoded 291 residual vectors. The code vectors of the second codebook section 292 are constructed by predefined linear combinations of vectors in the 293 first section of the codebook. 295 Since codebook encoding with squared-error matching is known to 296 produce a coded signal of less power than the scalar quantized start 297 state signal, a gain re-scaling method is implemented by a refined 298 search for a better set of codebook gains in terms of power matching 299 after encoding. This is done by searching for a higher value of the 300 gain factor for the first stage codebook since the subsequent stage 301 codebook gains are scaled by the first stage gain. 303 2.2 Decoder 305 For packet communications, typically a jitter buffer placed at the 306 receiving end decides whether the packet containing an encoded 307 signal block has been received or lost. This logic is not part of 308 the codec described here. For each received encoded signal block the 309 decoder performs a decoding. For each lost signal block the decoder 310 performs a PLC operation. 312 The decoding for each block starts by decoding and interpolating the 313 LPC coefficients. Subsequently the start state is decoded. 315 For codebook encoded segments, each segment is decoded by 316 constructing the 3 code vectors given by the received codebook 317 indices in the same way as the code vectors were constructed in the 318 encoder. The 3 gain factors are also decoded and the resulting 319 decoded signal is given by the sum of the 3 codebook vectors scaled 320 with respective gain. 322 An enhancement algorithm is applied on the reconstructed excitation 323 signal. This enhancement augments the periodicity of voiced speech 324 regions. The enhancement is optimized under the constraint that the 325 modification signal (defined as the difference between the enhanced 326 excitation and the excitation signal prior to enhancement) has a 327 short-time energy that does not exceed a preset fraction of the 328 short-time energy of the excitation signal prior to enhancement. 330 A packet loss concealment (PLC) operation is easily embedded in the 331 decoder. The PLC operation can, e.g., be based on repetition of LPC 332 filters and obtaining the LPC residual signal using a long term 333 prediction estimate from previous residual blocks. 335 Andersen et. al. Experimental - Expires November 29th, 2004 7 336 Internet Low Bit Rate Codec May 04 338 3. ENCODER PRINCIPLES 340 The following block diagram is an overview of all the components of 341 the iLBC encoding procedure. The description of the blocks contains 342 references to the section where that particular procedure is 343 described further. 345 +-----------+ +---------+ +---------+ 346 speech -> | 1. Pre P | -> | 2. LPC | -> | 3. Ana | -> 347 +-----------+ +---------+ +---------+ 349 +---------------+ +--------------+ 350 -> | 4. Start Sel | ->| 5. Scalar Qu | -> 351 +---------------+ +--------------+ 353 +--------------+ +---------------+ 354 -> |6. CB Search | -> | 7. Packetize | -> payload 355 | +--------------+ | +---------------+ 356 ----<---------<------ 357 sub-frame 0..2/4 (20 ms/30 ms) 359 Figure 3.1. Flow chart of the iLBC encoder 361 1. Pre process speech with a HP filter if needed (section 3.1) 362 2. Compute LPC parameters, quantize and interpolate (section 3.2) 363 3. Use analysis filters on speech to compute residual (section 3.3) 364 4. Select position of 57/58 sample start state (section 3.5) 365 5. Quantize the 57/58 sample start state with scalar quantization 366 (section 3.5) 367 6. Search the codebook for each sub-frame. Start with 23/22 sample 368 block, then encode sub-blocks forward in time and then encode sub- 369 blocks backward in time. For each block the steps in figure 3.4 are 370 performed (section 3.6) 371 7. Packetize the bits into the payload specified in table 3.2. 373 The input to the encoder SHOULD be 16 bit uniform PCM sampled at 8 374 kHz. Also it SHOULD be partitioned into blocks of BLOCKL=160/240 375 samples. Each block input to the encoder is divided into NSUB=4/6 376 consecutive sub-blocks of SUBL=40 samples each. 378 Andersen et. al. Experimental - Expires November 29th, 2004 8 379 Internet Low Bit Rate Codec May 04 381 0 39 79 119 159 382 +---------------------------------------+ 383 | 1 | 2 | 3 | 4 | 384 +---------------------------------------+ 385 20 ms frame 387 0 39 79 119 159 199 239 388 +-----------------------------------------------------------+ 389 | 1 | 2 | 3 | 4 | 5 | 6 | 390 +-----------------------------------------------------------+ 391 30 ms frame 393 Figure 3.2. One input block to the encoder for 20 ms (with 4 sub- 394 frames) and 30 ms (with 6 sub-frames). 396 3.1 Pre-processing 398 In some applications the recorded speech signal contains DC level 399 and/or 50/60 Hz noise. If these components have not been removed 400 prior to the encoder call, they should be removed by a high-pass 401 filter. A reference implementation of this, using a filter with cut 402 off frequency 90 Hz, can be found in Appendix A.28. 404 3.2 LPC Analysis and Quantization 406 The input to the LPC analysis module is a possibly high-pass 407 filtered speech buffer, speech_hp, that contains 240/300 408 (LPC_LOOKBACK + BLOCKL = 80/60 + 160/240 = 240/300) speech samples 409 , 410 where samples 0 through 79/59 are from the previous block and 411 samples 80/60 through 239/299 are from the current block. No look- 412 ahead into the next block is used. For the very first block 413 processed, the look back samples are assumed to be zeros. 415 For each input block, the LPC analysis calculates one/two set(s) of 416 LPC_FILTERORDER=10 LPC filter coefficients using the autocorrelation 418 method and the Levinson-Durbin recursion. These coefficients are 419 converted to the Line Spectrum Frequency representation. In the 20 420 ms case the set, lsf, represents the spectral characteristics as 421 measured at the center of the third sub-block. For 30 ms frames the 422 first set, lsf1, represents the spectral properties of the input 423 signal at the center of the second sub-block while the other set, 424 lsf2, represents the spectral characteristics as measured at the 425 center of the fifth sub-block. The details of the computation for 30 426 ms frames are described in 3.2.1 through 3.2.6. Section 3.2.7 427 explains how the LPC Analysis and Quantization differs for 20 ms 428 frames. 430 3.2.1 Computation of Autocorrelation Coefficients 432 The first step in the LPC analysis procedure is to calculate 433 autocorrelation coefficients using windowed speech samples. This 434 windowing is the only difference in the LPC analysis procedure for 435 the two sets of coefficients. For the first set, a 240 sample long 437 Andersen et. al. Experimental - Expires November 29th, 2004 9 438 Internet Low Bit Rate Codec May 04 440 standard symmetric Hanning window is applied to samples 0 through 441 239 of the input data. The first window, lpc_winTbl, is defined as: 443 lpc_winTbl[i]= 0.5 * (1.0 - cos((2*PI*(i+1))/(BLOCKL+1))); 444 i=0,...,119 445 lpc_winTbl[i] = winTbl[BLOCKL - i - 1]; i=120,...,239 447 The windowed speech speech_hp_win1 is then obtained by multiplying 448 the 240 first samples of the input speech buffer with the window 449 coefficients: 451 speech_hp_win1[i] = speech_hp[i] * lpc_winTbl[i]; 452 i=0,...,BLOCKL-1 454 From these 240 windowed speech samples, 11 (LPC_FILTERORDER + 1) 455 autocorrelation coefficients, acf1, are calculated: 457 acf1[lag] += speech_hp_win1[n] * speech_hp_win1[n + lag]; 458 lag=0,...,LPC_FILTERORDER; n=0,...,BLOCKL-lag-1 460 In order to make the analysis more robust against numerical 461 precision problems, a spectral smoothing procedure is applied by 462 windowing the autocorrelation coefficients before the LPC 463 coefficients are computed. Also, a white noise floor is added to the 464 autocorrelation function by multiplying coefficient zero by 1.0001 465 (40dB below the energy of the windowed speech signal). These two 466 steps are implemented by multiplying the autocorrelation 467 coefficients with the following window: 469 lpc_lagwinTbl[0] = 1.0001; 470 lpc_lagwinTbl[i] = exp(-0.5 * ((2 * PI * 60.0 * i) /FS)^2); 471 i=1,...,LPC_FILTERORDER 472 where FS=8000 is the sampling frequency 474 Then, the windowed acf function acf1_win is obtained by: 476 acf1_win[i] = acf1[i] * lpc_lagwinTbl[i]; 477 i=0,...,LPC_FILTERORDER 479 The second set of autocorrelation coefficients, acf2_win are 480 obtained in a similar manner. The window, lpc_asymwinTbl, is applied 481 to samples 60 through 299, i.e., the entire current block. The 482 window consists of two segments; the first (samples 0 to 219) being 483 half a Hanning window with length 440 and the second being a quarter 484 of a cycle of a cosine wave. By using this asymmetric window, an LPC 485 analysis centered in the fifth sub-block is obtained without the 486 need for any look-ahead, which would have added delay. The 487 asymmetric window is defined as: 489 lpc_asymwinTbl[i] = (sin(PI * (i + 1) / 441))^2; i=0,...,219 491 lpc_asymwinTbl[i] = cos((i - 220) * PI / 40); i=220,...,239 493 Andersen et. al. Experimental - Expires November 29th, 2004 10 494 Internet Low Bit Rate Codec May 04 496 and the windowed speech is computed by: 498 speech_hp_win2[i] = speech_hp[i + LPC_LOOKBACK] * 499 lpc_asymwinTbl[i]; i=0,....BLOCKL-1 501 The windowed autocorrelation coefficients are then obtained in 502 exactly the same way as for the first analysis instance. 504 The generation of the windows lpc_winTbl, lpc_asymwinTbl, and 505 lpc_lagwinTbl are typically done in advance and the arrays are 506 stored in ROM rather than repeating the calculation for every block. 508 3.2.2 Computation of LPC Coefficients 510 From the 2 x 11 smoothed autocorrelation coefficients, acf1_win and 511 acf2_win, the 2 x 11 LPC coefficients, lp1 and lp2, are calculated 512 in the same way for both analysis locations using the well known 513 Levinson-Durbin recursion. The first LPC coefficient is always 1.0, 514 resulting in 10 unique coefficients. 516 After determining the LPC coefficients, a bandwidth expansion 517 procedure is applied in order to smooth the spectral peaks in the 518 short-term spectrum. The bandwidth addition is obtained by the 519 following modification of the LPC coefficients: 521 lp1_bw[i] = lp1[i] * chirp^i; i=0,...,LPC_FILTERORDER 522 lp2_bw[i] = lp2[i] * chirp^i; i=0,...,LPC_FILTERORDER 524 where "chirp" is a real number between 0 and 1. It is RECOMMENDED to 525 use a value of 0.9. 527 3.2.3 Computation of LSF Coefficients from LPC Coefficients 529 Thusfar, two sets of LPC coefficients that represent the short-term 530 spectral characteristics of the speech signal for two different time 531 locations within the current block have been determined. These 532 coefficients SHOULD be quantized and interpolated. Before doing so, 533 it is advantageous to convert the LPC parameters into another type 534 of representation called Line Spectral Frequencies (LSF). The LSF 535 parameters are used because they are better suited for quantization 536 and interpolation than the regular LPC coefficients. Many 537 computationally efficient methods for calculating the LSFs from the 538 LPC coefficients have been proposed in the literature. The detailed 539 implementation of one applicable method can be found in Appendix 540 A.26. The two arrays of LSF coefficients obtained, lsf1 and lsf2, 541 are of dimension 10 (LPC_FILTERORDER). 543 3.2.4 Quantization of LSF Coefficients 545 Since the LPC filters defined by the two sets of LSFs are needed 546 also in the decoder, the LSF parameters need to be quantized and 547 transmitted as side information. The total number of bits required 548 to represent the quantization of the two LSF representations for one 549 block of speech is 40 with 20 bits used for each of lsf1 and lsf2. 551 Andersen et. al. Experimental - Expires November 29th, 2004 11 552 Internet Low Bit Rate Codec May 04 554 For computational and storage reasons, the LSF vectors are quantized 555 using 3-split vector quantization (VQ). That is, the LSF vectors are 556 split into three sub-vectors which are each quantized with a regular 557 VQ. The quantized versions of lsf1 and lsf2, qlsf1 and qlsf2, are 558 obtained by using the same memoryless split VQ. The length of each 559 of these two LSF vectors is 10 and they are split into 3 sub-vectors 560 containing 3, 3 and 4 values respectively. 562 For each of the sub-vectors, a separate codebook of quantized values 563 has been designed using a standard VQ training method for a large 564 database containing speech from a large number of speakers recorded 565 under various conditions. The size of each of the three codebooks 566 associated with the split definitions above is: 568 int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128}; 570 The actual values of the vector quantization codebook that must be 571 used can be found in the reference code of appendix A. Both sets of 572 LSF coefficients, lsf1 and lsf2, are quantized with a standard 573 memoryless split vector quantization (VQ) structure using the 574 squared error criterion in the LSF domain. The split VQ quantization 575 consists of the following steps: 577 1) Quantize the first 3 LSF coefficients (1 - 3) with a VQ codebook 578 of size 64. 579 2) Quantize the LSF coefficients 4, 5, and 6 with VQ a codebook of 580 size 128. 581 3) Quantize the last 4 LSF coefficients (7 - 10) with a VQ codebook 582 of size 128. 584 This procedure, repeated for lsf1 and lsf2, gives 6 quantization 585 indices and the quantized sets of LSF coefficients qlsf1 and qlsf2. 586 Each set of three indices is encoded with 6 + 7 + 7 = 20 bits. The 587 total number of bits used for LSF quantization in a block is thus 40 588 bits. 590 3.2.5 Stability Check of LSF Coefficients 592 The LSF representation of the LPC filter has the nice property that 593 the coefficients are ordered by increasing value, i.e., lsf(n-1) < 594 lsf(n), 0 < n < 10, if the corresponding synthesis filter is stable. 595 Since we are employing a split VQ scheme it is possible that at the 596 split boundaries the LSF coefficients are not ordered correctly and 597 hence the corresponding LP filter is unstable. To ensure that the 598 filter used is stable, a stability check is performed for the 599 quantized LSF vectors. If it turns out that the coefficients are not 600 ordered appropriately (with a safety margin of 50 Hz to ensure that 601 formant peaks are not too narrow) they will be moved apart. The 602 detailed method for this can be found in Appendix A.40. The same 603 procedure is performed in the decoder. This ensures that exactly the 604 same LSF representations are used in both encoder and decoder. 606 3.2.6 Interpolation of LSF Coefficients 608 Andersen et. al. Experimental - Expires November 29th, 2004 12 609 Internet Low Bit Rate Codec May 04 611 From the two sets of LSF coefficients that are computed for each 612 block of speech, different LSFs are obtained for each sub-block by 613 means of interpolation. This procedure is performed for the original 614 LSFs (lsf1 and lsf2), as well as the quantized versions qlsf1 and 615 qlsf2 since both versions are used in the encoder. Here follows a 616 brief summary of the interpolation scheme while the details are 617 found in the c-code of Appendix A. In the first sub-block, the 618 average of the second LSF vector from the previous block and the 619 first LSF vector in the current block is used. For sub-blocks two 620 through five the LSFs used are obtained by linear interpolation from 621 lsf1 (and qlsf1) to lsf2 (and qlsf2) with lsf1 used in sub-block two 622 and lsf2 in sub-block five. In the last sub-block, lsf2 is used. For 623 the very first block it is assumed that the last LSF vector of the 624 previous block is equal to a predefined vector, lsfmeanTbl, that was 625 obtained by calculating the mean LSF vector of the LSF design 626 database. 628 lsfmeanTbl[LPC_FILTERORDER] = {0.281738, 0.445801, 0.663330, 629 0.962524, 1.251831, 1.533081, 1.850586, 2.137817, 630 2.481445, 2.777344} 632 The interpolation method is standard linear interpolation in the LSF 633 domain. The interpolated LSF values are converted to LPC 634 coefficients for each sub-block. The unquantized and quantized LPC 635 coefficients form two sets of filters respectively. The unquantized 636 analysis filter for sub-block k: 638 ___ 639 \ 640 Ak(z)= 1 + > ak(i)*z^(-i) 641 /__ 642 i=1...LPC_FILTERORDER 644 And the quantized analysis filter for sub-block k: 645 ___ 646 \ 647 A~k(z)= 1 + > a~k(i)*z^(-i) 648 /__ 649 i=1...LPC_FILTERORDER 651 A reference implementation of the lsf encoding is given in Appendix 652 A.38. A reference implementation of the corresponding decoding can 653 be found in Appendix A.36. 655 3.2.7 LPC Analysis and Quantization for 20 ms frames 657 As stated before, the codec only calculates one set of LPC 658 parameters for the 20 ms frame size as opposed to two sets for 30 ms 659 frames. A single set of autocorrelation coefficients is calculated 660 on the LPC_LOOKBACK + BLOCKL = 80 + 160 = 240 samples. These sampl 661 es 662 are windowed with the asymmetric window lpc_asymwinTbl, centered 663 over the third sub-frame, to form speech_hp_win. Autocorrelation 664 coefficients, acf, are calculated on the 240 samples in 666 Andersen et. al. Experimental - Expires November 29th, 2004 13 667 Internet Low Bit Rate Codec May 04 669 speech_hp_win and then windowed exactly as in 3.2.1 (resulting in 670 acf_win). 672 This single set of windowed autocorrelation coefficients is used to 673 calculate LPC Coefficients, LSF Coefficients and quantized LSF 674 coefficients in exactly the same manner as in 3.2.3 to 3.2.4. As for 675 the 30 ms frame size, the 10 LSF coefficients are divided into three 676 sub-vectors of size 3, 3, 4 and quantized using the same scheme and 677 codebook as in 3.2.4 to finally get 3 quantization indices. The 678 quantized LSF coefficients are stabilized with the algorithm 679 described in 3.2.5. 681 From the set of LSF coefficients that was computed for this block 682 together with the LSF coefficients from the previous block, 683 different LSFs are obtained for each sub-block by means of 684 interpolation. The interpolation is done linearly in the LSF domain 685 over the 4 sub-blocks, so that the n-th sub-frame uses the weight 686 (4-n)/4 for the LSF from old frame and the weight n/4 of the LSF 687 from the current frame. For the very first block the mean LSF, 688 lsfmeanTbl, is used as the LSF from the previous block. Similar to 689 3.2.6, both unquantized, A(z), and quantized, A~(z), analysis 690 filters are calculated for each of the four sub-blocks. 692 3.3 Calculation of the Residual 694 The block of speech samples is filtered by the quantized and 695 interpolated LPC analysis filters to yield the residual signal. In 696 particular, the corresponding LPC analysis filter for each 40 sample 697 sub-block is used to filter the speech samples for the same sub- 698 block. The filter memory at the end of each sub-block is carried 699 over to the LPC filter of the next sub-block. The signal at the 700 output of each LP analysis filter constitutes the residual signal 701 for the corresponding sub-block. 703 A reference implementation of the LPC analysis filters is given in 704 Appendix A.10. 706 3.4 Perceptual Weighting Filter 708 In principle any good design of a perceptual weighting filter can be 709 applied in the encoder without compromising this codec definition. 710 It is however RECOMMENDED to use the perceptual weighting filter 711 specified below: 713 Weighting filter for sub-block k: 715 Wk(z)=1/Ak(z/LPC_CHIRP_WEIGHTDENUM), where 716 LPC_CHIRP_WEIGHTDENUM = 0.4222 718 This is a simple design with low complexity that is applied in the 719 LPC residual domain. Here Ak(z) is the filter obtained from 720 unquantized but interpolated LSF coefficients. 722 Andersen et. al. Experimental - Expires November 29th, 2004 14 723 Internet Low Bit Rate Codec May 04 725 3.5 Start State Encoder 727 The start state is quantized using a common 6-bit scalar quantizer 728 for the block and a 3-bit scalar quantizer operating on scaled 729 samples in the weighted speech domain. In the following we describe 730 the state encoding in greater detail. 732 3.5.1 Start State Estimation 734 The two sub-blocks containing the start state are determined by 735 finding the two consecutive sub-blocks in the block having the 736 highest power. Advantageously, down-weighting is used in the 737 beginning and end of the sub-frames. I.e., the following measure is 738 computed (NSUB=4/6 for 20/30 ms frame size): 740 nsub=1,...,NSUB-1 741 ssqn[nsub] = 0.0; 742 for (i=(nsub-1)*SUBL; i<(nsub-1)*SUBL+5; i++) 743 ssqn[nsub] += sampEn_win[i-(nsub-1)*SUBL]* 744 residual[i]*residual[i]; 745 for (i=(nsub-1)*SUBL+5; i<(nsub+1)*SUBL-5; i++) 746 ssqn[nsub] += residual[i]*residual[i]; 747 for (i=(nsub+1)*SUBL-5; i<(nsub+1)*SUBL; i++) 748 ssqn[nsub] += sampEn_win[(nsub+1)*SUBL-i-1]* 749 residual[i]*residual[i]; 751 where sampEn_win[5]={1/6, 2/6, 3/6, 4/6, 5/6}; MAY be used. The sub- 752 frame number corresponding to the maximum value of ssqEn_win[nsub- 753 1]*ssqn[nsub] is selected as the start state indicator. A weighting 754 of ssqEn_win[]={0.8,0.9,1.0,0.9,0.8} for 30 ms frames and 755 ssqEn_win[]={0.9,1.0,0.9} for 20 ms frames; MAY advantageously be 756 used to bias the start state towards the middle of the frame. 758 For 20 ms frames there are 3 possible positions of the two-sub-block 759 length maximum power segment, the start state position is encoded 760 using 2 bits. The start state position, start, MUST be encoded as: 762 start=1: start state in sub-frame 0 and 1 763 start=2: start state in sub-frame 1 and 2 764 start=3: start state in sub-frame 2 and 3 766 For 30 ms frames there are 5 possible positions of the two-sub-block 767 length maximum power segment, the start state position is encoded 768 using 3 bits. The start state position, start, MUST be encoded as: 770 start=1: start state in sub-frame 0 and 1 771 start=2: start state in sub-frame 1 and 2 772 start=3: start state in sub-frame 2 and 3 773 start=4: start state in sub-frame 3 and 4 774 start=5: start state in sub-frame 4 and 5 776 hence, in both cases, index 0 is not utilized. In order to shorten 777 the start state for bit rate efficiency, the start state is brought 778 down to STATE_SHORT_LEN=57 samples for 20 ms frames and 780 Andersen et. al. Experimental - Expires November 29th, 2004 15 781 Internet Low Bit Rate Codec May 04 783 STATE_SHORT_LEN=58 samples for 30 ms frames. The power of the first 784 23/22 and last 23/22 samples of the 2 sub-frame block identified 785 above is computed as the sum of the squared signal sample values and 786 the 23/22 sample segment with the lowest power is excluded from the 787 start state. One bit is transmitted to indicate which of the 2 788 possible 57/58 sample segments is used. The start state position 789 within the 2 sub-frames determined above, state_first, MUST be 790 encoded as: 792 state_first=1: start state is first STATE_SHORT_LEN samples 793 state_first=0: start state is last STATE_SHORT_LEN samples 795 3.5.2 All-Pass Filtering and Scale Quantization 797 The block of residual samples in the start state is first filtered 798 by an all-pass filter with the quantized LPC coefficients as 799 denominator and reversed quantized LPC coefficients as numerator. 800 The purpose of this phase-dispersion filter is to get a more even 801 distribution of the sample values in the residual signal. The 802 filtering is performed by circular convolution, where the initial 803 filter memory is set to zero. 805 res(0..(STATE_SHORT_LEN-1)) = uncoded start state residual 806 res((STATE_SHORT_LEN)..(2*STATE_SHORT_LEN-1)) = 0 808 Pk(z) = A~rk(z)/A~k(z), where 809 ___ 810 \ 811 A~rk(z)= z^(-LPC_FILTERORDER)+>a~k(i+1)*z^(i-(LPC_FILTERORDER-1)) 813 /__ 814 i=0...(LPC_FILTERORDER-1) 816 and A~k(z) is taken from the block where the start state begins 818 res -> Pk(z) -> filtered 820 ccres(k) = filtered(k) + filtered(k+STATE_SHORT_LEN), 821 k=0..(STATE_SHORT_LEN-1) 823 The all pass filtered block is searched for its largest magnitude 824 sample. The 10-logarithm of this magnitude is quantized with a 6-bit 825 quantizer, state_frgqTbl, by finding the nearest representation. 826 This results in an index, idxForMax, corresponding to a quantized 827 value, qmax. The all-pass filtered residual samples in the block are 828 then multiplied with a scaling factor scal=4.5/(10^qmax) to yield 829 normalized samples. 831 state_frgqTbl[64] = {1.000085, 1.071695, 1.140395, 1.206868, 832 1.277188, 1.351503, 1.429380, 1.500727, 1.569049, 833 1.639599, 1.707071, 1.781531, 1.840799, 1.901550, 834 1.956695, 2.006750, 2.055474, 2.102787, 2.142819, 835 2.183592, 2.217962, 2.257177, 2.295739, 2.332967, 836 2.369248, 2.402792, 2.435080, 2.468598, 2.503394, 837 2.539284, 2.572944, 2.605036, 2.636331, 2.668939, 839 Andersen et. al. Experimental - Expires November 29th, 2004 16 840 Internet Low Bit Rate Codec May 04 842 2.698780, 2.729101, 2.759786, 2.789834, 2.818679, 843 2.848074, 2.877470, 2.906899, 2.936655, 2.967804, 844 3.000115, 3.033367, 3.066355, 3.104231, 3.141499, 845 3.183012, 3.222952, 3.265433, 3.308441, 3.350823, 846 3.395275, 3.442793, 3.490801, 3.542514, 3.604064, 847 3.666050, 3.740994, 3.830749, 3.938770, 4.101764} 849 3.5.3 Scalar Quantization 851 The normalized samples are quantized in the perceptually weighted 852 speech domain by a sample-by-sample scalar DPCM quantization as 853 depicted in Figure 3.3. Each sample in the block is filtered by a 854 weighting filter Wk(z), specified in section 3.4, to form a weighted 855 speech sample x[n]. The target sample d[n] is formed by subtracting 856 a predicted sample y[n], where the prediction filter is given by 858 Pk(z) = 1 - 1 / Wk(z). 860 +-------+ x[n] + d[n] +-----------+ u[n] 861 residual -->| Wk(z) |-------->(+)---->| Quantizer |------> quantized 862 +-------+ - /|\ +-----------+ | residual 863 | \|/ 864 y[n] +--------------------->(+) 865 | | 866 | +------+ | 867 +--------| Pk(z)|<------+ 868 +------+ 870 Figure 3.3. Quantization of start state samples by DPCM in weighted 871 speech domain. 873 The coded state sample u[n] is obtained by quantizing d[n] with a 3- 874 bit quantizer with quantization table state_sq3Tbl. 876 state_sq3Tbl[8] = {-3.719849, -2.177490, -1.130005, -0.309692, 877 0.444214, 1.329712, 2.436279, 3.983887} 879 The quantized samples are transformed back to the residual domain by 880 1) scaling with 1/scal 2) time-reversing the scaled samples 3) 881 filtering the time-reversed samples by the same all-pass filter as 882 in section 3.5.2, using circular convolution 4) time-reversing the 883 filtered samples. (More detailed in section 4.2) 885 A reference implementation of the start state encoding can be found 886 in Appendix A.46. 888 3.6 Encoding the remaining samples 890 A dynamic codebook is used to encode 1) the 23/22 remaining samples 891 in the 2 sub-blocks containing the start state; 2) encoding of the 892 sub-blocks after the start state in time; 3) encoding of the sub- 893 blocks before the start state in time. Thus, the encoding target can 894 be either the 23/22 samples remaining of the 2 sub-blocks containing 895 the start state or a 40 sample sub-block. This target can consist of 897 Andersen et. al. Experimental - Expires November 29th, 2004 17 898 Internet Low Bit Rate Codec May 04 900 samples that are indexed forwards in time or backwards in time 901 depending on the location of the start state. The length of the 902 target is denoted by lTarget. 904 The coding is based on an adaptive codebook that is built from a 905 codebook memory which contains decoded LPC excitation samples from 906 the already encoded part of the block. These samples are indexed in 907 the same time direction as the target vector and ending at the 908 sample instant prior to the first sample instant represented in the 909 target vector. The codebook memory has length lMem which is equal to 910 CB_MEML=147 for the two/four 40 sample sub-blocks and 85 for the 911 23/22 sample sub-block. 913 The following figure shows an overview of the encoding procedure. 915 +------------+ +---------------+ +-------------+ 916 -> | 1. Decode | -> | 2. Mem setup | -> | 3. Perc. W. | -> 917 +------------+ +---------------+ +-------------+ 919 +------------+ +-----------------+ 920 -> | 4. Search | -> | 5. Upd. Target | ------------------> 921 | +------------+ +------------------ | 922 ----<-------------<-----------<---------- 923 stage=0..2 925 +----------------+ 926 -> | 6. Recalc G[0] | ---------------> gains and CB indices 927 +----------------+ 929 Figure 3.4. Flow chart of the codebook search in the iLBC encoder 931 1. Decode the part of the residual that has been encoded so far, 932 using the codebook without perceptual weighting 933 2. Set up the memory by taking data from the decoded residual. This 934 memory is used to construct codebooks from. For blocks preceding the 935 start state, both the decoded residual and the target are time 936 reversed (section 3.6.1) 937 3. Filter the memory + target with the perceptual weighting filter 938 (section 3.6.2) 939 4. Search for the best match between the target and the codebook 940 vector. Compute the optimal gain for this match and quantize that 941 gain (section 3.6.4) 942 5. Update the perceptually weighted target by subtracting the 943 contribution from the selected codebook vector from the perceptually 944 weighted memory (quantized gain times selected vector). Repeat 4. 945 and 5. for the 2 additional stages 946 6. Calculate the energy loss due to encoding of the residual. If 947 needed, compensate for this loss by an upscaling and requantization 948 of the gain for the first stage (section 3.7) 950 The following sections provide an in-depth description of the 951 different blocks of figure 3.4. 953 Andersen et. al. Experimental - Expires November 29th, 2004 18 954 Internet Low Bit Rate Codec May 04 956 3.6.1 Codebook Memory 958 The codebook memory is based on the already encoded sub-blocks so 959 the available data for encoding increases for each new sub-block 960 that has been encoded. Until enough sub-blocks have been encoded to 961 fill the codebook memory with data it is padded with zeros. The 962 following figure shows an example of the order in which the sub- 963 blocks are encoded for the 30 ms frame size if the start state is 964 located in the last 58 samples of sub-block 2 and 3. 966 +-----------------------------------------------------+ 967 | 5 | 1 |///|////////| 2 | 3 | 4 | 968 +-----------------------------------------------------+ 970 Figure 3.5. The order from 1 to 5 in which the sub-blocks are 971 encoded. The slashed area is the start state. 973 The first target sub-block to be encoded is number 1 and the 974 corresponding codebook memory is shown in the following figure. 975 Since the target vector is before the start state in time the 976 codebook memory and target vector are time reversed. By reversing 977 them in time, the search algorithm can be reused. Since only the 978 start state has been encoded so far the last samples of the codebook 979 memory are padded with zeros. 981 +------------------------- 982 |zeros|\\\\\\\\|\\\\| 1 | 983 +------------------------- 985 Figure 3.6. The codebook memory, length lMem=85 samples, and the 986 target vector 1, length 22 samples. 988 The next step is to encode sub-block 2 using the memory which now 989 has increased since sub-block 1 has been encoded. The following 990 figure shows the codebook memory for encoding of sub-block 2. 992 +----------------------------------- 993 | zeros | 1 |///|////////| 2 | 994 +----------------------------------- 996 Figure 3.7. The codebook memory, length lMem=147 samples, and the 997 target vector 2, length 40 samples. 999 The next step is to encode sub-block 3 using the memory which now 1000 has increased yet again since sub-blocks 1 and 2 have been encoded 1001 but it still has to be padded with a few zeros. The following figure 1002 shows the codebook memory for encoding of sub-block 3. 1004 +------------------------------------------ 1005 |zeros| 1 |///|////////| 2 | 3 | 1006 +------------------------------------------ 1008 Figure 3.8. The codebook memory, length lMem=147 samples, and the 1009 target vector 3, length 40 samples. 1011 Andersen et. al. Experimental - Expires November 29th, 2004 19 1012 Internet Low Bit Rate Codec May 04 1014 The next step is to encode sub-block 4 using the memory which now 1015 has increased yet again since sub-blocks 1, 2 and 3 have been 1016 encoded. This time the memory does not have to be padded with zeros. 1017 The following figure shows the codebook memory for encoding of sub- 1018 block 4. 1020 +------------------------------------------ 1021 |1|///|////////| 2 | 3 | 4 | 1022 +------------------------------------------ 1024 Figure 3.9. The codebook memory, length lMem=147 samples, and the 1025 target vector 4, length 40 samples. 1027 The final target sub-block to be encoded is number 5 and the 1028 corresponding codebook memory is shown in the following figure. 1029 Since the target vector is before the start state in time the 1030 codebook memory and target vector are time reversed. 1032 +------------------------------------------- 1033 | 3 | 2 |\\\\\\\\|\\\\| 1 | 5 | 1034 +------------------------------------------- 1036 Figure 3.10. The codebook memory, length lMem=147 samples, and the 1037 target vector 5, length 40 samples. 1039 For the case of 20 ms frames the encoding procedure looks almost 1040 exactly the same. The only difference is that the size of the start 1041 state is 57 samples and that there are only 3 sub-blocks to be 1042 encoded. The encoding order is the same as above starting with the 1043 23 sample target and then encoding the two remaining 40 sample sub- 1044 blocks, first going forward in time and then going backwards in time 1045 relative to the start state. 1047 3.6.2 Perceptual Weighting of Codebook Memory and Target 1049 To provide a perceptual weighting of the coding error, a 1050 concatenation of the codebook memory and the target to be coded is 1051 all pole filtered with the perceptual weighting filter specified in 1052 section 3.4. The filter state of the weighting filter is set to 1053 zero. 1055 in(0..(lMem-1)) = unweighted codebook memory 1056 in(lMem..(lMem+lTarget-1)) = unweighted target signal 1058 in -> Wk(z) -> filtered, 1059 where Wk(z) is taken from the sub-block of the target 1061 weighted codebook memory = filtered(0..(lMem-1)) 1062 weighted target signal = filtered(lMem..(lMem+lTarget-1)) 1064 The codebook search is done using the weighted codebook memory and 1065 the weighted target, while the decoding and the codebook memory 1066 update uses the unweighted codebook memory. 1068 Andersen et. al. Experimental - Expires November 29th, 2004 20 1069 Internet Low Bit Rate Codec May 04 1071 3.6.3 Codebook Creation 1073 The codebook for the search is created from the perceptually 1074 weighted codebook memory. It consists of two sections where the 1075 first is referred to as the base codebook and the second as the 1076 expanded codebook since it is created by linear combinations of the 1077 first. Each of these two sections also has a subsection referred to 1078 as the augmented codebook. The augmented codebook is only created 1079 and used for the coding of the 40 sample sub-blocks and not for the 1080 23/22 sample sub-block case. The codebook size used for the 1081 different sub-blocks and different stages are summarized in the 1082 table below. 1084 Stage 1085 1 2 & 3 1086 -------------------------------------------- 1087 22 128 (64+0)*2 128 (64+0)*2 1088 Sub- 1:st 40 256 (108+20)*2 128 (44+20)*2 1089 Blocks 2:nd 40 256 (108+20)*2 256 (108+20)*2 1090 3:rd 40 256 (108+20)*2 256 (108+20)*2 1091 4:th 40 256 (108+20)*2 256 (108+20)*2 1093 Table 3.1. Codebook sizes for the 30 ms mode 1095 The table 3.1 shows the codebook size for the different sub-blocks 1096 and stages for 30 ms frames. Inside the parenthesis it shows how the 1097 number of codebook vectors is distributed, within the two sections, 1098 between the base/expanded codebook and the augmented base/expanded 1099 codebook. It should be interpreted in the following way: 1100 (base/expanded cb + augmented base/expanded cb). The total number of 1101 codebook vectors for a specific sub-block and stage is given by the 1102 following formula: 1104 Tot. cb vectors = base cb + aug. base cb + exp. cb + aug. exp. cb 1106 The corresponding values to figure 3.1 for 20 ms frames are only 1107 slightly modified. The short sub-block is 23 instead of 22 samples 1108 and the 3:rd and 4:th sub-frame are not present. 1110 3.6.3.1 Creation of a Base Codebook 1112 The base codebook is given by the perceptually weighted codebook 1113 memory that is mentioned in section 3.5.3. The different codebook 1114 vectors are given by sliding a window of length 23/22 or 40, given 1115 by variable lTarget, over the lMem long perceptually weighted 1116 codebook memory. The indices are ordered so that the codebook vector 1117 containing sample(lMem-lTarget-n) to (lMem-n-1) of the codebook 1118 memory vector has index n, where n=0..lMem-lTarget. Thus the total 1119 number of base codebook vectors is lMem-lTarget+1 and the indices 1120 are ordered from sample delay lTarget (23/22 or 40) to lMem+1 (86 or 1121 148). 1123 Andersen et. al. Experimental - Expires November 29th, 2004 21 1124 Internet Low Bit Rate Codec May 04 1126 3.6.3.2 Codebook Expansion 1128 The base codebook is expanded by a factor of 2, creating an 1129 additional section in the codebook. This new section is obtained by 1130 filtering the base codebook, base_cb, with a FIR filter with filter 1131 length CB_FILTERLEN=8. The delay of four samples introduced by the 1132 FIR filter is compensated for in the construction of the expanded 1133 codebook. 1135 cbfiltersTbl[CB_FILTERLEN]={-0.033691, 0.083740, -0.144043, 1136 0.713379, 0.806152, -0.184326, 1137 0.108887, -0.034180}; 1139 ___ 1140 \ 1141 exp_cb(k)= + > cbfiltersTbl(i)*x(k-i+4) 1142 /__ 1143 i=0...(LPC_FILTERORDER-1) 1145 where x(j) = base_cb(j) for j=0..lMem-1 and 0 otherwise 1147 The individual codebook vectors of the new filtered codebook, 1148 exp_cb, and their indices are obtained in the same fashion as 1149 described above for the base codebook. 1151 3.6.3.3 Codebook Augmentation 1153 For the cases when encoding entire sub-blocks, i.e. cbveclen=40, the 1155 base and expanded codebooks are augmented to increase codebook 1156 richness. The codebooks are augmented by vectors produced by 1157 interpolation of segments. The base and expanded codebook, 1158 constructed above, consists of vectors corresponding to sample 1159 delays in the range from cbveclen to lMem. The codebook augmentation 1160 attempts to augment these codebooks with vectors corresponding to 1161 sample delays from 20 to 39. However, not all of these samples are 1162 present in the base codebook and expanded codebook respectively. 1163 Therefore, the augmentation vectors are constructed as linear 1164 combinations between samples corresponding to sample delays in the 1165 range 20 to 39. The general idea of this procedure is presented in 1166 the following figures and text. The procedure is performed for both 1167 the base codebook and the expanded codebook. 1169 - - ------------------------| 1170 codebook memory | 1171 - - ------------------------| 1172 |-5-|---15---|-5-| 1173 pi pp po 1175 | | Codebook vector 1176 |---15---|-5-|-----20-----| <- corresponding to 1177 i ii iii sample delay 20 1179 Figure 3.11. Generation of the first augmented codebook 1181 Andersen et. al. Experimental - Expires November 29th, 2004 22 1182 Internet Low Bit Rate Codec May 04 1184 The figure 3.11 shows the codebook memory with pointers pi, pp and 1185 po where pi points to sample 25, pp to sample 20 and po to sample 5. 1186 Below the codebook memory, the augmented codebook vector 1187 corresponding to sample delay 20 is drawn. Segment i consists of 15 1188 samples from pointer pp and forward in time. Segment ii consists of 1189 5 interpolated samples from pi and forward and from po and forward. 1190 The samples are linearly interpolated with weights [0.0, 0.2, 0.4, 1191 0.6, 0.8] for pi and weights [1.0, 0.8, 0.6, 0.4, 0.2] for po. 1192 Segment iii consists of 20 samples from pp and forward. The 1193 augmented codebook vector corresponding to sample delay 21 is 1194 produced by moving pointers pp and pi one sample backwards in time. 1195 That gives us the following figure. 1197 - - ------------------------| 1198 codebook memory | 1199 - - ------------------------| 1200 |-5-|---16---|-5-| 1201 pi pp po 1203 | | Codebook vector 1204 |---16---|-5-|-----19-----| <- corresponding to 1205 i ii iii sample delay 21 1207 Figure 3.12. Generation of the second augmented codebook 1209 The figure 3.12 shows the codebook memory with pointers pi, pp and 1210 po where pi points to sample 26, pp to sample 21 and po to sample 5. 1211 Below the codebook memory, the augmented codebook vector 1212 corresponding to sample delay 21 is drawn. Segment i does now 1213 consist of 16 samples from pp and forward. Segment ii consists of 5 1214 interpolated samples from pi and forward and po and forward and the 1215 interpolation weights are the same throughout the procedure. Segment 1216 iii consists of 19 samples from pp and forward. The same procedure 1217 of moving the two pointers is continued until the last augmented 1218 vector corresponding to sample delay 39 has been created. This gives 1219 a total of 20 new codebook vectors to each of the two sections. Thus 1220 the total number of codebook vectors for each of the two sections, 1221 when including the augmented codebook becomes lMem-SUBL+1+SUBL/2. 1222 This is provided that augmentation is evoked, i.e., that 1223 lTarget=SUBL. 1225 3.6.4 Codebook Search 1227 The codebook search uses the codebooks described in the sections 1228 above to find the best match of the perceptually weighted target, 1229 see section 3.6.2. The search method is a multi-stage gain-shape 1230 matching performed as follows. At each stage the best shape vector 1231 is identified, then the gain is calculated and quantized, and 1232 finally the target is updated in preparation for the next codebook 1233 search stage. The number of stages is CB_NSTAGES=3. 1235 If the target is the 23/22 sample vector the codebooks are indexed 1236 in the order: base codebook followed by the expanded codebook. If 1237 the target is 40 samples the order is: base codebook, augmented base 1239 Andersen et. al. Experimental - Expires November 29th, 2004 23 1240 Internet Low Bit Rate Codec May 04 1242 codebook, expanded codebook and finally augmented expanded codebook. 1243 The size of each codebook section and its corresponding augmented 1244 section is given by table 3.1 in section 3.6.3. 1246 For example when coding the second 40 sample sub-block indices 0-107 1247 correspond to the base codebook, 108-127 correspond to the augmented 1248 base codebook, 128-235 correspond to the expanded codebook and 1249 finally indices 236-255 correspond to the augmented expanded 1250 codebook. The indices are divided in the same fashion for all stages 1251 in the example. Only in the case of coding the first 40 sample sub- 1252 block is there a difference between stages (see Table 3.1). 1254 3.6.4.1 Codebook Search at Each Stage 1256 The codebooks are searched to find the best match to the target at 1257 each stage. When the best match is found the target is updated and 1258 the next-stage search is started. The three chosen codebook vectors 1259 and their corresponding gains constitute the encoded sub-block. The 1260 best match is decided by the following three criteria: 1262 1. Compute the measure 1264 (target*cbvec)^2 / ||cbvec||^2 1266 for all codebook vectors, cbvec, and choose the codebook vector 1267 maximizing the measure. The expression (target*cbvec) is the dot 1268 product between the target vector to be coded and the codebook 1269 vector for which we compute the measure. The norm, ||x||, is defined 1270 as the square root of (x*x). 1272 2. The absolute value of the gain, corresponding to the chosen 1273 codebook vector, cbvec, must be smaller than a fixed limit, 1274 CB_MAXGAIN=1.3: 1276 |gain| < CB_MAXGAIN 1278 where the gain is computed in the following way: 1280 gain = (target*cbvec) / ||cbvec||^2 1282 3. For the first stage the dot product of the chosen codebook vector 1283 and target must be positive: 1285 target*cbvec > 0 1287 In practice the above criteria are used in a sequential search 1288 through all codebook vectors. The best match is found by registering 1289 a new max measure and index whenever the previously registered max 1290 measure is surpassed and all other criteria are fulfilled. If none 1291 of the codebook vectors fulfill (2) and (3), the first codebook 1292 vector is selected. 1294 3.6.4.2 Gain Quantization at Each Stage 1296 Andersen et. al. Experimental - Expires November 29th, 2004 24 1297 Internet Low Bit Rate Codec May 04 1299 The gain follows as a result of the computation: 1301 gain = (target*cbvec) / ||cbvec||^2 1303 for the optimal codebook vector that was found by the procedure from 1304 section 3.6.4.1. 1306 The three stages quantize the gain using 5, 4 and 3 bits 1307 respectively. In the first stage, the gain is limited to positive 1308 values. This gain is quantized by finding the nearest value in the 1309 quantization table gain_sq5Tbl. 1311 gain_sq5Tbl[32]={0.037476, 0.075012, 0.112488, 0.150024, 0.187500, 1312 0.224976, 0.262512, 0.299988, 0.337524, 0.375000, 1313 0.412476, 0.450012, 0.487488, 0.525024, 0.562500, 1314 0.599976, 0.637512, 0.674988, 0.712524, 0.750000, 1315 0.787476, 0.825012, 0.862488, 0.900024, 0.937500, 1316 0.974976, 1.012512, 1.049988, 1.087524, 1.125000, 1317 1.162476, 1.200012} 1319 The gains of the subsequent two stages can be either positive or 1320 negative. The gains are quantized using a quantization table times a 1321 scale factor. The second stage uses the table gain_sq4Tbl and the 1322 third stage uses gain_sq3Tbl. The scale factor equates 0.1 or the 1323 absolute value of the quantized gain representation value obtained 1324 in the previous stage, whichever is the larger. Again, the resulting 1325 gain index is the index to the nearest value of the quantization 1326 table times the scale factor. 1328 Andersen et. al. Experimental - Expires November 29th, 2004 25 1329 Internet Low Bit Rate Codec May 04 1331 gainQ = scaleFact * gain_sqXTbl[index] 1333 gain_sq4Tbl[16]={-1.049988, -0.900024, -0.750000, -0.599976, 1334 -0.450012, -0.299988, -0.150024, 0.000000, 0.150024, 1335 0.299988, 0.450012, 0.599976, 0.750000, 0.900024, 1336 1.049988, 1.200012} 1338 gain_sq3Tbl[8]={-1.000000, -0.659973, -0.330017,0.000000, 1339 0.250000, 0.500000, 0.750000, 1.00000} 1341 3.6.4.3 Preparation of Target for Next Stage 1343 Before performing the search for the next stage the perceptually 1344 weighted target vector is updated by subtracting from it the 1345 selected codebook vector (from the perceptually weighted codebook) 1346 times the corresponding quantized gain. 1348 target[i] = target[i] - gainQ * selected_vec[i]; 1350 A reference implementation of the codebook encoding is found in 1351 Appendix A.34. 1353 3.7 Gain Correction Encoding 1355 The start state is quantized in a relatively model independent 1356 manner using 3 bits per sample. In contrast to this, the remaining 1357 parts of the block is encoded using an adaptive codebook. This 1358 codebook will produce high matching accuracy whenever there is a 1359 high correlation between the target and the best codebook vector. 1360 For unvoiced speech segments and background noises, this is not 1361 necessarily so, which, due to the nature of the squared error 1362 criterion, results in a coded signal with less power than the target 1363 signal. As the coded start state has good power matching to the 1364 target, the result is a power fluctuation within the encoded frame. 1365 Perceptually, the main problem with this is that the time envelope 1366 of the signal energy becomes unsteady. To overcome this problem, the 1367 gains for the codebooks are re-scaled after the codebook encoding by 1368 searching for a new gain factor for the first stage codebook that 1369 provides better power matching. 1371 First the energy for the target signal, tene, is computed along with 1372 the energy for the coded signal, cene, given by the addition of the 1373 3 gain scaled codebook vectors. Since the gains of the 2nd and 3rd 1374 stage scale with the gain of the first stage, by changing the first 1375 stage gain from gain[0] to gain_sq5Tbl[i], the energy of the coded 1376 signal changes from cene to 1378 cene*(gain_sq5Tbl[i]*gain_sq5Tbl[i])/(gain[0]*gain[0]) 1380 where gain[0] is the gain for the first stage found in the original 1381 codebook search. A refined search is performed by testing the gain 1382 indices i=0 to 31, and as long as the new codebook energy as given 1383 above is less than tene, the gain index for stage 1 is increased. A 1384 restriction is applied so that the new gain value for stage 1 cannot 1386 Andersen et. al. Experimental - Expires November 29th, 2004 26 1387 Internet Low Bit Rate Codec May 04 1389 be more than 2 times higher than the original value found in the 1390 codebook search. Note that by using this method the shape of the 1391 encoded vector is not changed, only the gain or amplitude. 1393 3.8 Bitstream Definition 1395 The total number of bits used to describe one frame of 20 ms speech 1396 is 304, which fits in 38 bytes and results in a bit rate of 15.20 1397 kbit/s. For the case with a frame length of 30 ms speech the total 1398 number of bits used is 400, which fits in 50 bytes and results in a 1399 bit rate of 13.33 kbit/s. In the bitstream definition the bits are 1400 distributed into three classes according to their bit error or loss 1401 sensitivity. The most sensitive bits (class 1) are placed first in 1402 the bitstream for each frame. The less sensitive bits (class 2) are 1403 placed after the class 1 bits. The least sensitive bits (class 3) 1404 are placed at the end of the bitstream for each frame. 1406 Looking at the 20/30 ms frame length cases for each class: The class 1407 1 bits occupy a total of 6/8 bytes (48/64 bits), the class 2 bits 1408 occupy 8/12 bytes (64/96 bits), and the class 3 bits occupy 24/30 1409 bytes (191/239 bits). This distribution of the bits enable the use 1410 of uneven level protection (ULP) as is exploited in the payload 1411 format definition for iLBC [1]. The detailed bit allocation is shown 1412 in the table below. When a quantization index is distributed between 1413 more classes the more significant bits belong to the lowest class. 1415 Andersen et. al. Experimental - Expires November 29th, 2004 27 1416 Internet Low Bit Rate Codec May 04 1418 Bitstream structure: 1420 ------------------------------------------------------------------+ 1421 Parameter | Bits Class <1,2,3> | 1422 | 20 ms frame | 30 ms frame | 1423 ----------------------------------+---------------+---------------+ 1424 Split 1 | 6 <6,0,0> | 6 <6,0,0> | 1425 LSF 1 Split 2 | 7 <7,0,0> | 7 <7,0,0> | 1426 LSF Split 3 | 7 <7,0,0> | 7 <7,0,0> | 1427 ------------------+---------------+---------------+ 1428 Split 1 | NA (Not Appl.)| 6 <6,0,0> | 1429 LSF 2 Split 2 | NA | 7 <7,0,0> | 1430 Split 3 | NA | 7 <7,0,0> | 1431 ------------------+---------------+---------------+ 1432 Sum | 20 <20,0,0> | 40 <40,0,0> | 1433 ----------------------------------+---------------+---------------+ 1434 Block Class. | 2 <2,0,0> | 3 <3,0,0> | 1435 ----------------------------------+---------------+---------------+ 1436 Position 22 sample segment | 1 <1,0,0> | 1 <1,0,0> | 1437 ----------------------------------+---------------+---------------+ 1438 Scale Factor State Coder | 6 <6,0,0> | 6 <6,0,0> | 1439 ----------------------------------+---------------+---------------+ 1440 Sample 0 | 3 <0,1,2> | 3 <0,1,2> | 1441 Quantized Sample 1 | 3 <0,1,2> | 3 <0,1,2> | 1442 Residual : | : : | : : | 1443 State : | : : | : : | 1444 Samples : | : : | : : | 1445 Sample 56 | 3 <0,1,2> | 3 <0,1,2> | 1446 Sample 57 | NA | 3 <0,1,2> | 1447 ------------------+---------------+---------------+ 1448 Sum | 171 <0,57,114>| 174 <0,58,116>| 1449 ----------------------------------+---------------+---------------+ 1450 Stage 1 | 7 <6,0,1> | 7 <4,2,1> | 1451 CB for 22/23 Stage 2 | 7 <0,0,7> | 7 <0,0,7> | 1452 sample block Stage 3 | 7 <0,0,7> | 7 <0,0,7> | 1453 ------------------+---------------+---------------+ 1454 Sum | 21 <6,0,15> | 21 <4,2,15> | 1455 ----------------------------------+---------------+---------------+ 1456 Stage 1 | 5 <2,0,3> | 5 <1,1,3> | 1457 Gain for 22/23 Stage 2 | 4 <1,1,2> | 4 <1,1,2> | 1458 sample block Stage 3 | 3 <0,0,3> | 3 <0,0,3> | 1459 ------------------+---------------+---------------+ 1460 Sum | 12 <3,1,8> | 12 <2,2,8> | 1462 Andersen et. al. Experimental - Expires November 29th, 2004 28 1463 Internet Low Bit Rate Codec May 04 1465 ----------------------------------+---------------+---------------+ 1466 Stage 1 | 8 <7,0,1> | 8 <6,1,1> | 1467 sub-block 1 Stage 2 | 7 <0,0,7> | 7 <0,0,7> | 1468 Stage 3 | 7 <0,0,7> | 7 <0,0,7> | 1469 ------------------+---------------+---------------+ 1470 Stage 1 | 8 <0,0,8> | 8 <0,7,1> | 1471 sub-block 2 Stage 2 | 8 <0,0,8> | 8 <0,0,8> | 1472 Indices Stage 3 | 8 <0,0,8> | 8 <0,0,8> | 1473 for CB ------------------+---------------+---------------+ 1474 sub-blocks Stage 1 | NA | 8 <0,7,1> | 1475 sub-block 3 Stage 2 | NA | 8 <0,0,8> | 1476 Stage 3 | NA | 8 <0,0,8> | 1477 ------------------+---------------+---------------+ 1478 Stage 1 | NA | 8 <0,7,1> | 1479 sub-block 4 Stage 2 | NA | 8 <0,0,8> | 1480 Stage 3 | NA | 8 <0,0,8> | 1481 ------------------+---------------+---------------+ 1482 Sum | 46 <7,0,39> | 94 <6,22,66> | 1483 ----------------------------------+---------------+---------------+ 1484 Stage 1 | 5 <1,2,2> | 5 <1,2,2> | 1485 sub-block 1 Stage 2 | 4 <1,1,2> | 4 <1,2,1> | 1486 Stage 3 | 3 <0,0,3> | 3 <0,0,3> | 1487 ------------------+---------------+---------------+ 1488 Stage 1 | 5 <1,1,3> | 5 <0,2,3> | 1489 sub-block 2 Stage 2 | 4 <0,2,2> | 4 <0,2,2> | 1490 Stage 3 | 3 <0,0,3> | 3 <0,0,3> | 1491 Gains for ------------------+---------------+---------------+ 1492 sub-blocks Stage 1 | NA | 5 <0,1,4> | 1493 sub-block 3 Stage 2 | NA | 4 <0,1,3> | 1494 Stage 3 | NA | 3 <0,0,3> | 1495 ------------------+---------------+---------------+ 1496 Stage 1 | NA | 5 <0,1,4> | 1497 sub-block 4 Stage 2 | NA | 4 <0,1,3> | 1498 Stage 3 | NA | 3 <0,0,3> | 1499 ------------------+---------------+---------------+ 1500 Sum | 24 <3,6,15> | 48 <2,12,34> | 1501 ----------------------------------+---------------+---------------+ 1502 Empty frame indicator | 1 <0,0,1> | 1 <0,0,1> | 1503 ------------------------------------------------------------------- 1504 SUM 304 <48,64,192> 400 <64,96,240> 1506 Table 3.2. The bitstream definition for iLBC for both the 20 ms 1507 frame size mode and the 30 ms frame size mode. 1509 When packetized into the payload the bits MUST be sorted as: All the 1510 class 1 bits in the order (from top to bottom) as they were 1511 specified in the table, all the class 2 bits (from top to bottom) 1512 and finally all the class 3 bits in the same sequential order. 1513 The last bit, the empty frame indicator, SHOULD be set to zero by 1514 the encoder. If this bit is set to one the decoder SHOULD treat the 1515 data as a lost frame. For example this bit can be set to 1 to 1516 indicate lost frame for file storage format as in [1]. 1518 Andersen et. al. Experimental - Expires November 29th, 2004 29 1519 Internet Low Bit Rate Codec May 04 1521 4. DECODER PRINCIPLES 1523 This section describes the principles of each component of the 1524 decoder algorithm. 1526 +-------------+ +--------+ +---------------+ 1527 payload -> | 1. Get para | -> | 2. LPC | -> | 3. Sc Dequant | -> 1528 +-------------+ +--------+ +---------------+ 1530 +-------------+ +------------------+ 1531 -> | 4 Mem setup | -> | 5. Construct res |-------> 1532 | +-------------+ +------------------- | 1533 ---------<-----------<-----------<------------ 1534 Sub-frame 0...2/4 (20 ms/30 ms) 1536 +----------------+ +----------+ 1537 -> | 6. Enhance res | -> | 7. Synth | ------------> 1538 +----------------+ +----------+ 1540 +-----------------+ 1541 -> | 8. Post Process | ----------------> decoded speech 1542 +-----------------+ 1544 Figure 4.1. Flow chart of the iLBC decoder. If a frame was lost 1545 steps 1 to 5 SHOULD be replaced by a PLC algorithm. 1547 1. Extract the parameters from the bitstream 1548 2. Decode the LPC and interpolate (section 4.1) 1549 3. Construct the 57/58 sample start state (section 4.2) 1550 4. Set up the memory using data from the decoded residual. This 1551 memory is used for codebook construction. For blocks preceding the 1552 start state, both the decoded residual and the target are time 1553 reversed. Sub-frames are decoded in the same order as they were 1554 encoded 1555 5. Construct the residuals of this sub-frame (gain[0]*cbvec[0] + 1556 gain[1]*cbvec[1] + gain[2]*cbvec[2]). Repeat 4 and 5 until the 1557 residual of all sub-blocks have been constructed 1558 6. Enhance the residual with the post filter (section 4.6) 1559 7. Synthesis of the residual (section 4.7) 1560 8. Post process with HP filter if desired (section 4.8) 1562 4.1 LPC Filter Reconstruction 1564 The decoding of the LP filter parameters is very straightforward. 1565 For a set of three/six indices the corresponding LSF vector(s) are 1566 found by simple table look up. For each of the LSF vectors the three 1567 split vectors are concatenated to obtain qlsf1 and qlsf2, 1568 respectively (in the 20 ms mode only one LSF vector, qlsf, is 1569 constructed). The next step is the stability check described in 1570 Section 3.2.5 followed by the interpolation scheme described in 1571 Section 3.2.6 (3.2.7 for 20 ms frames). The only difference is that 1572 only the quantized LSFs are known at the decoder and hence the 1573 unquantized LSFs are not processed. 1575 Andersen et. al. Experimental - Expires November 29th, 2004 30 1576 Internet Low Bit Rate Codec May 04 1578 A reference implementation of the LPC filter reconstruction is given 1579 in Appendix A.36. 1581 4.2 Start State Reconstruction 1583 The scalar encoded STATE_SHORT_LEN=58 (STATE_SHORT_LEN=57 in the 2 1584 0 1585 ms mode) state samples are reconstructed by 1) forming a set of 1586 samples (by table look-up) from the index stream idxVec[n] 2) 1587 multiplying the set with 1/scal=(10^qmax)/4.5 3) time reversing the 1588 57/58 samples 4) filtering the time reversed block with the 1589 dispersion (all-pass) filter used in the encoder (as described in 1590 section 3.5.2). This compensates for the phase distortion of the 1591 earlier filter operation. 5) Reversing the 57/58 samples from the 1592 previous step 1594 in(0..(STATE_SHORT_LEN-1)) = time reversed samples from table 1595 look-up, 1596 idxVecDec((STATE_SHORT_LEN-1)..0) 1598 in(STATE_SHORT_LEN..(2*STATE_SHORT_LEN-1)) = 0 1600 Pk(z) = A~rk(z)/A~k(z), where 1601 ___ 1602 \ 1603 A~rk(z)= z^(-LPC_FILTERORDER) + > a~ki*z^(i-(LPC_FILTERORDER-1)) 1604 /__ 1605 i=0...(LPC_FILTERORDER-1) 1607 and A~k(z) is taken from the block where the start state begins 1609 in -> Pk(z) -> filtered 1611 out(k) = filtered(STATE_SHORT_LEN-1-k) + 1612 filtered(2*STATE_SHORT_LEN-1-k), 1613 k=0..(STATE_SHORT_LEN-1) 1615 The remaining 23/22 samples in the state are reconstructed by the 1616 same adaptive codebook technique as described in section 4.3. The 1617 location bit determines whether these are the first or the last 1618 23/22 samples of the 80 sample state vector. If the remaining 23/22 1619 samples are the first samples of the state vector, then the scalar 1620 encoded STATE_SHORT_LEN state samples are time-reversed before 1621 initialization of the adaptive codebook memory vector. 1623 A reference implementation of the start state reconstruction is 1624 given in Appendix A.44. 1626 4.3 Excitation Decoding Loop 1628 The decoding of the LPC excitation vector proceeds in the same order 1629 in which the residual was encoded at the encoder. That is, after the 1630 decoding of the entire 80 sample state vector, the forward sub- 1631 blocks (corresponding to samples occurring after the state vector 1632 samples) are decoded, and then the backward sub-blocks 1634 Andersen et. al. Experimental - Expires November 29th, 2004 31 1635 Internet Low Bit Rate Codec May 04 1637 (corresponding to samples occurring before the state vector) are 1638 decoded, resulting in a fully decoded block of excitation signal 1639 samples. 1641 In particular, each sub-block is decoded using the multistage 1642 adaptive codebook decoding module which is described in section 4.4. 1643 This module relies upon an adaptive codebook memory that is 1644 constructed before each run of the adaptive codebook decoding. The 1645 construction of the adaptive codebook memory in the decoder is 1646 identical to the method outlined in section 3.6.3, except that it is 1647 done on the codebook memory without perceptual weighting. 1649 For the initial forward sub-block, the last STATE_LEN=80 samples of 1650 the length CB_LMEM=147 adaptive codebook memory are filled with the 1651 samples of the state vector. For subsequent forward sub-blocks, the 1652 first SUBL=40 samples of the adaptive codebook memory are discarded, 1654 the remaining samples are shifted by SUBL samples towards the 1655 beginning of the vector, while the newly decoded SUBL=40 samples are 1657 placed at the end of the adaptive codebook memory. For backward sub- 1658 blocks, the construction is similar except that every vector of 1659 samples involved is first time-reversed. 1661 A reference implementation of the excitation decoding loop is found 1662 in Appendix A.5. 1664 4.4 Multistage Adaptive Codebook Decoding 1666 The Multistage Adaptive Codebook Decoding module is used at both the 1667 sender (encoder) and the receiver (decoder) ends to produce a 1668 synthetic signal in the residual domain that is eventually used to 1669 produce synthetic speech. The module takes the index values used to 1670 construct vectors that are scaled and summed together to produce a 1671 synthetic signal that is the output of the module. 1673 4.4.1 Construction of the Decoded Excitation Signal 1675 The unpacked index values provided at the input to the module are 1676 references to extended codebooks, which are constructed as described 1677 in Section 3.6.3 with the only difference that it is based on the 1678 codebook memory without the perceptual weighting. The unpacked 3 1679 indices are used to look up 3 codebook vectors. The unpacked 3 gain 1680 indices are used to decode the corresponding 3 gains. In this 1681 decoding the successive rescaling as described in Section 3.6.4.2 is 1682 applied. 1684 A reference implementation of the adaptive codebook decoding is 1685 listed in Appendix A.32. 1687 Andersen et. al. Experimental - Expires November 29th, 2004 32 1688 Internet Low Bit Rate Codec May 04 1690 4.5 Packet Loss Concealment 1692 If packet loss occurs, the decoder receives a signal saying that 1693 information regarding a block is lost. For such blocks it is 1694 RECOMMENDED to use a Packet Loss Concealment (PLC) unit to create a 1695 decoded signal which masks the effect of that packet loss. In the 1696 following we will describe an example of a PLC unit that can be used 1697 with the iLBC codec. As the PLC unit is used only at the decoder, 1698 the PLC unit does not affect interoperability between 1699 implementations. Other PLC implementations MAY therefore be used. 1701 The example PLC described operates on the LP filters and the 1702 excitation signals and is based on the following principles: 1704 4.5.1 Block Received Correctly and Previous Block also Received 1706 If the block is received correctly, the PLC only records state 1707 information of the current block that can be used in case the next 1708 block is lost. The LP filter coefficients for each sub-block and the 1709 entire decoded excitation signal are all saved in the decoder state 1710 structure. All this information will be needed if the following 1711 block is lost. 1713 4.5.2 Block Not Received 1715 If the block is not received, the block substitution is based on 1716 doing a pitch synchronous repetition of the excitation signal which 1717 is filtered by the last LP filter of the previous block. The 1718 previous block's information is stored in the decoder state 1719 structure. 1721 A correlation analysis is performed on the previous block's 1722 excitation signal in order to detect the amount of pitch periodicity 1723 and a pitch value. The correlation measure is also used to decide on 1724 the voicing level (the degree to which the previous block's 1725 excitation was a voiced or roughly periodic signal). The excitation 1726 in the previous block is used to create an excitation for the block 1727 to be substituted such that the pitch of the previous block is 1728 maintained. Therefore, the new excitation is constructed in a pitch 1729 synchronous manner. In order to avoid a buzzy sounding substituted 1730 block, a random excitation is mixed with the new pitch periodic 1731 excitation and the relative use of the two components is computed 1732 from the correlation measure (voicing level). 1734 For the block to be substituted, the newly constructed excitation 1735 signal is then passed through the LP filter to produce the speech 1736 that will be substituted for the lost block. 1738 For several consecutive lost blocks, the packet loss concealment 1739 continues in a similar manner. The correlation measure of the last 1740 received block is still used along with the same pitch value. The LP 1741 filters of the last received block are also used again. The energy 1742 of the substituted excitation for consecutive lost blocks is 1744 Andersen et. al. Experimental - Expires November 29th, 2004 33 1745 Internet Low Bit Rate Codec May 04 1747 decreased, leading to a dampened excitation, and therefore dampened 1748 speech. 1750 4.5.3 Block Received Correctly When Previous Block Not Received 1752 For the case in which a block is received correctly when the 1753 previous block was not received, the correctly received block's 1754 directly decoded speech (based solely on the received block) is not 1755 used as the actual output. The reason for this is that the directly 1756 decoded speech does not necessarily smoothly merge into the 1757 synthetic speech generated for the previous lost block. If the two 1758 signals are not smoothly merged, an audible discontinuity is 1759 accidentally produced. Therefore, a correlation analysis between the 1760 two blocks of excitation signal (the excitation of the previous 1761 concealed block and the excitation of the current received block) is 1762 performed to find the best phase match. Then a simple overlap-add 1763 procedure is performed to smoothly merge the previous excitation 1764 into the current block's excitation. 1766 The exact implementation of the packet loss concealment does not 1767 influence interoperability of the codec. 1769 A reference implementation of the packet loss concealment is 1770 suggested in Appendix A.14. Exact compliance with this suggested 1771 algorithm is not needed for a reference implementation to be fully 1772 compatible with the overall codec specification. 1774 4.6 Enhancement 1776 The decoder contains an enhancement unit that operates on the 1777 reconstructed excitation signal. The enhancement unit increases the 1778 perceptual quality of the reconstructed signal by reducing the 1779 speech-correlated noise in the voiced speech segments. Compared to 1780 traditional postfilters, the enhancer has the advantage that it can 1781 only modify the excitation signal slightly. This means that there is 1782 no risk of over enhancement. The enhancer works very similar for 1783 both the 20 ms frame size mode and for the 30 ms frame size mode. 1785 For the mode with 20 ms frame size, the enhancer uses a memory of 1786 six 80 sample excitation blocks prior in time plus the two new 80 1787 sample excitation blocks. For each block of 160 new unenhanced 1788 excitation samples, 160 enhanced excitation samples are produced. 1789 The enhanced excitation is 40 sample delayed compared to the 1790 unenhanced excitation since the enhancer algorithm uses lookahead. 1792 For the mode with 30 ms frame size, the enhancer uses a memory of 1793 five 80 sample excitation blocks prior in time plus the three new 80 1794 sample excitation blocks. For each block of 240 new unenhanced 1795 excitation samples, 240 enhanced excitation samples are produced. 1796 The enhanced excitation is 80 sample delayed compared to the 1797 unenhanced excitation since the enhancer algorithm uses lookahead. 1799 OUTLINE of Enhancer 1801 Andersen et. al. Experimental - Expires November 29th, 2004 34 1802 Internet Low Bit Rate Codec May 04 1804 The speech enhancement unit operates on sub-blocks of 80 samples, 1805 which means that there are two/three 80 sample sub-blocks per frame. 1806 Each of these two/three sub-blocks is enhanced separately, but in an 1807 analogous manner. 1809 unenhanced residual 1810 | 1811 | +---------------+ +--------------+ 1812 +-> | 1. Pitch Est | -> | 2. Find PSSQ | --------> 1813 +---------------+ | +--------------+ 1814 +-----<-------<------<--+ 1815 +------------+ enh block 0..1/2 | 1816 -> | 3. Smooth | | 1817 +------------+ | 1818 \ | 1819 /\ | 1820 / \ Already | 1821 / 4. \----------->----------->-----------+ | 1822 \Crit/ Fulfilled | | 1823 \? / v | 1824 \/ | | 1825 \ +-----------------+ +---------+ | | 1826 Not +->| 5. Use Constr. | -> | 6. Mix | -----> 1827 Fulfilled +-----------------+ +---------+ 1829 ---------------> enhanced residual 1831 Figure 4.2. Flow chart of the enhancer 1833 1. Pitch estimation of each of the two/three new 80 sample blocks 1834 2. Find the pitch-period-synchronous sequence n (for block k) by a 1835 search around the estimated pitch value. Do this for 1836 n=1,2,3,-1,-2,-3 1837 3. Calculate the smoothed residual generated by the 6 pitch-period- 1838 synchronous sequences from prior step 1839 4. Check if the smoothed residual satisfies the criterion (section 1840 4.6.4) 1841 5. Use constraint to calculate mixing factor (section 4.6.5) 1842 6. Mix smoothed signal with unenhanced residual (pssq(n) n=0) 1844 The main idea of the enhancer is to find three 80 sample blocks 1845 before and three 80 sample blocks after the analyzed unenhanced sub- 1846 block and use these to improve the quality of the excitation in that 1847 sub-block. The six blocks are chosen so that they have the highest 1848 possible correlation with the unenhanced sub-block that is being 1849 enhanced. In other words the 6 blocks are pitch-period-synchronous 1850 sequences to the unenhanced sub-block. 1852 A linear combination of the six pitch-period-synchronous sequences 1853 is calculated that approximates the sub-block. If the squared error 1854 between the approximation and the unenhanced sub-block is small 1855 enough, the enhanced residual is set equal to this approximation. 1856 For the cases when the squared error criterion is not fulfilled, a 1858 Andersen et. al. Experimental - Expires November 29th, 2004 35 1859 Internet Low Bit Rate Codec May 04 1861 linear combination of the approximation and the unenhanced residual 1862 forms the enhanced residual. 1864 4.6.1 Estimating the pitch 1866 Pitch estimates are needed to determine the locations of the pitch- 1867 period-synchronous sequences in a complexity efficient way. For each 1868 of the new two/three sub-blocks a pitch estimate is calculated by 1869 finding the maximum correlation in the range from lag 20 to lag 120. 1871 These pitch estimates are used to narrow down the search for the 1872 best possible pitch-period-synchronous sequences. 1874 4.6.2 Determination of the Pitch-Synchronous Sequences 1876 Upon receiving the pitch estimates from the prior step, the enhancer 1877 analyzes and enhances one 80 sample sub-block at a time. The pitch- 1878 period-synchronous-sequences pssq(n) can be viewed as vectors of 1879 length 80 samples each shifted n*lag samples from the current sub- 1880 block. The six pitch-period-synchronous-sequences, pssq(-3) to 1881 pssq(-1) and pssq(1) to pssq(3), are found one at a time by the 1882 steps below: 1884 1) Calculate the estimate of the position of the pssq(n). For 1885 pssq(n) in front of pssq(0) (n > 0), the location of the pssq(n) 1886 is estimated by moving one pitch estimate forward in time from 1887 the exact location of pssq(n-1). Similarly for pssq(n) behind 1888 pssq(0) (n < 0) is estimated by moving one pitch estimate 1889 backward in time from the exact location of pssq(n+1). If the 1890 estimated pssq(n) vector location is totally within the enhancer 1891 memory (figure 4.3) step 2,3, and 4 are performed, otherwise the 1892 pssq(n) is set to zeros. 1894 2) Compute the correlation between the unenhanced excitation and 1895 vectors around the estimated location interval of pssq(n). The 1896 correlation is calculated in the interval estimated location +/- 1897 2 samples. This results in 5 correlation values. 1899 3) The 5 correlation values are upsampled by a factor 4, using sinc 1900 upsampling filters (four MA filters with coefficients upsFilter1 1901 .. upsFilter4). Within these the maximum value is found, which 1902 specifies the best pitch-period with a resolution of a quarter of 1903 a sample. 1905 upsFilter1[7]={0.000000 0.000000 0.000000 1.000000 1906 0.000000 0.000000 0.000000} 1907 upsFilter2[7]={0.015625 -0.076904 0.288330 0.862061 1908 -0.106445 0.018799 -0.015625} 1909 upsFilter3[7]={0.023682 -0.124268 0.601563 0.601563 1910 -0.124268 0.023682 -0.023682} 1911 upsFilter4[7]={0.018799 -0.106445 0.862061 0.288330 1912 -0.076904 0.015625 -0.018799} 1914 Andersen et. al. Experimental - Expires November 29th, 2004 36 1915 Internet Low Bit Rate Codec May 04 1917 4) Generate the pssq(n) vector by upsampling of the excitation 1918 memory and extracting the sequence that corresponds to the lag 1919 delay that was calculated in prior step. 1921 With the steps above all the pssq(n) can be found in an iterative 1922 manner, first moving backward in time from pssq(0) and then forward 1923 in time from pssq(0). 1925 0 159 319 479 639 1926 +---------------------------------------------------------------+ 1927 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 1928 +---------------------------------------------------------------+ 1929 |pssq 0 | 1930 |pssq -1| |pssq 1 | 1931 |pssq -2| |pssq 2 | 1932 |pssq -3| |pssq 3 | 1934 Figure 4.3. Enhancement for 20 ms frame size 1936 Figure 4.3. depicts pitch-period-synchronous sequences in the 1937 enhancement of the first 80 sample block in the 20 ms frame size 1938 mode. The unenhanced signal input is stored in the two last sub- 1939 blocks (1-2), and the six other sub-blocks contain unenhanced 1940 residual prior-in-time. We perform the enhancement algorithm on two 1941 blocks of 80 samples, where the first of the two blocks consist of 1942 the last 40 samples of sub-block 0 and the first 40 samples of sub- 1943 block 1. The second 80 sample block consists of the last 40 samples 1944 of sub-block 1 and the first 40 samples of sub-block 2. 1946 0 159 319 479 639 1947 +---------------------------------------------------------------+ 1948 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 | 1949 +---------------------------------------------------------------+ 1950 |pssq 0 | 1951 |pssq -1| |pssq 1 | 1952 |pssq -2| |pssq 2 | 1953 |pssq -3| |pssq 3 | 1955 Figure 4.4. Enhancement for 30 ms frame size 1957 Figure 4.4. depicts pitch-period-synchronous sequences in the 1958 enhancement of the first 80 sample block in the 30 ms frame size 1959 mode. The unenhanced signal input is stored in the three last sub- 1960 blocks (1-3). The five other sub-blocks contain unenhanced residual 1961 prior-in-time. The enhancement algorithm is performed on the three 1962 80 sample sub-blocks 0, 1 and 2. 1964 4.6.3 Calculation of the smoothed excitation 1966 A linear combination of the six pssq(n) (n!=0) form a smoothed 1967 approximation, z, of pssq(0). Most of the weight is put on the 1968 sequences that are close to pssq(0) since these are most likely to 1969 be most similar to pssq(0). The smoothed vector is also rescaled, so 1970 that the energy of z is the same as the energy of pssq(0). 1972 Andersen et. al. Experimental - Expires November 29th, 2004 37 1973 Internet Low Bit Rate Codec May 04 1975 ___ 1976 \ 1977 y = > pssq(i) * pssq_weight(i) 1978 /__ 1979 i=-3,-2,-1,1,2,3 1981 pssq_weight(i) = 0.5*(1-cos(2*pi*(i+4)/(2*3+2))) 1983 z = C * y, where C = ||pssq(0)||/||y|| 1985 4.6.4 Enhancer criterion 1987 The criterion of the enhancer is that the enhanced excitation is not 1988 allowed to differ much from the unenhanced excitation. This 1989 criterion is checked for each 80 sample sub-block. 1991 e < (b * ||pssq(0)||^2), where b=0.05 and (Constraint 1) 1993 e = (pssq(0)-z)*(pssq(0)-z), and "*" means the dot product 1995 4.6.5 Enhancing the excitation 1997 From the criterion in the previous section it is clear that the 1998 excitation is not allowed to change much. The purpose of this 1999 constraint is to prevent the creation of an enhanced signal that is 2000 significantly different from the original signal. This also means 2001 that the constraint limits the numerical size of the errors that the 2002 enhancement procedure can make. That is especially important in 2003 unvoiced segments and background noise segments where increased 2004 periodicity could lead to lower perceived quality. 2006 When the constraint in the prior section is not met, the enhanced 2007 residual is instead calculated through a constrained optimization 2008 using the Lagrange multiplier technique. The new constraint is that: 2010 e = (b * ||pssq(0)||^2) (Constraint 2) 2012 We distinguish two solution regions for the optimization: 1) the 2013 region where the first constraint is fulfilled and 2) the region 2014 where the first constraint is not fulfilled so the second constraint 2015 must be used. 2017 In the first case, where the second constraint is not needed, the 2018 optimized re-estimated vector is simply z, the energy scaled version 2019 of y. 2021 In the second case, where the second constraint is activated and 2022 becomes an equality constraint, we have that 2024 z= A*y + B*pssq(0) 2026 where 2028 Andersen et. al. Experimental - Expires November 29th, 2004 38 2029 Internet Low Bit Rate Codec May 04 2031 A = sqrt((b-b^2/4)*(w00*w00)/ (w11*w00 + w10*w10)) and 2033 w11 = pssq(0)*pssq(0) 2034 w00 = y*y 2035 w10 = y*pssq(0) (* symbolizes the dot product) 2037 and 2039 B = 1 - b/2 - A * w10/w00 2041 Appendix A.16 contains a listing of a reference implementation for 2042 the enhancement method. 2044 4.7 Synthesis Filtering 2046 Upon decoding or PLC of the LP excitation block, the decoded speech 2047 block is obtained by running the decoded LP synthesis filter, 2048 1/A~k(z), over the block. The synthesis filters have to be shifted 2049 to compensate for the delay in the enhancer. For 20 ms frame size 2050 mode they SHOULD be shifted one 40 sample sub-block and for 30 ms 2051 frame size mode they SHOULD be shifted two 40 sample sub-blocks. The 2052 LP coefficients SHOULD be changed at the first sample of every sub- 2053 block while keeping the filter state. For PLC blocks, one solution 2054 is to apply the last LP coefficients of the last decoded speech 2055 block for all sub-blocks. 2057 The reference implementation for the synthesis filtering can be 2058 found in Appendix A.48. 2060 4.8 Post Filtering 2062 If desired the decoded block can be filtered by a high-pass filter. 2063 This removes the low frequencies of the decoded signal. A reference 2064 implementation of this, with cut off at 65 Hz, is shown in Appendix 2065 A.30. 2067 5. IANA CONSIDERATIONS 2069 This algorithm for the coding of speech signals does not have any 2070 IANA considerations that need to be addressed. 2072 6. SECURITY CONSIDERATIONS 2074 This algorithm for the coding of speech signals is not subject of 2075 any known security consideration; however, its RTP payload format 2076 [1] is subject of several considerations which are addressed there. 2077 Confidentiality of the media streams is achieved by encryption, 2078 therefore external mechanisms, such as SRTP [5], MAY be used for 2079 that purpose. 2081 7. EVALUATION OF THE ILBC IMPLEMENTATIONS 2083 Andersen et. al. Experimental - Expires November 29th, 2004 39 2084 Internet Low Bit Rate Codec May 04 2086 It is possible and suggested to evaluate certain iLBC implementation 2087 by utilizing methodology and tools available at 2088 http://www.ilbcfreeware.org/evaluation.html 2090 8. REFERENCES 2092 8.1 Normative 2094 [1] A. Duric and S. V. Andersen, "RTP Payload Format for iLBC 2095 Speech", IETF Draft, May 2004 2097 [2] S. Bradner, "Key words for use in RFCs to Indicate requirement 2098 Levels", BCP 14, RFC 2119, March 1997. 2100 [3] PacketCable(TM) Audio/Video Codecs Specification, Cable 2101 Television Laboratories, Inc. 2103 8.2 Informative 2105 [4] ITU-T Recommendation G.711, available online from the ITU 2106 bookstore at http://www.itu.int. 2108 [5] Baugher, et al., "The Secure Real Time Transport Protocol", IETF 2109 RFC 3711, March 2004. 2111 9. ACKNOWLEDGEMENTS 2113 This extensive work, beside listed authors, has the following 2114 authors, which could not been listed among "official" authors (due 2115 to IESG confines in number of authors which can be listed): 2117 Manohar N Murthi (Dpt of El and Comp Eng, University of Miami), 2118 Fredrik Galschiodt, Julian Spittka and Jan Skoglund (Global IP 2119 Sound) 2121 The authors are deeply indebted to them all and thank them 2122 sincerely: 2124 Henry Sinnreich, Patrik Faltstrom and Alan Johnston 2126 for great support of the iLBC initiative and for valuable feedback 2127 and comments. 2129 Peter Vary, Frank Mertz and Christoph Erdmann (RWTH Aachen); 2130 Vladimir Cuperman (Niftybox LLC); Thomas Eriksson (Chalmers 2131 Univ of Tech) and Gernot Kubin (TU Graz) 2133 for thorough review of the iLBC draft and their valuable feedback 2134 and remarks. 2136 Andersen et. al. Experimental - Expires November 29th, 2004 40 2137 Internet Low Bit Rate Codec May 04 2139 10. AUTHOR'S ADDRESSES 2141 Soren Vang Andersen 2142 Department of Communication Technology 2143 Aalborg University 2144 Fredrik Bajers Vej 7A 2145 9200 Aalborg 2146 Denmark 2147 Phone: ++45 9 6358627 2148 Email: sva@kom.auc.dk 2150 Alan Duric 2151 Telio AS 2152 Stortingsgt. 8 2153 Oslo, N-0161 2154 Norway 2155 Phone: +47 21673555 2156 Email: alan.duric@telio.no 2158 Henrik Astrom 2159 Global IP Sound AB 2160 Rosenlundsgatan 54 2161 Stockholm, S-11863 2162 Sweden 2163 Phone: +46 8 54553040 2164 Email: henrik.astrom@globalipsound.com 2166 Roar Hagen 2167 Global IP Sound AB 2168 Rosenlundsgatan 54 2169 Stockholm, S-11863 2170 Sweden 2171 Phone: +46 8 54553040 2172 Email: roar.hagen@globalipsound.com 2174 W. Bastiaan Kleijn 2175 Global IP Sound AB 2176 Rosenlundsgatan 54 2177 Stockholm, S-11863 2178 Sweden 2179 Phone: +46 8 54553040 2180 Email: bastiaan.kleijn@globalipsound.com 2182 Jan Linden 2183 Global IP Sound Inc. 2184 900 Kearny Street, suite 500 2185 San Francisco, CA-94133 2186 USA 2187 Phone: +1 415 397 2555 2188 Email: jan.linden@globalipsound.com 2190 Andersen et. al. Experimental - Expires November 29th, 2004 41 2191 Internet Low Bit Rate Codec May 04 2193 Full Copyright Statement 2195 Copyright (C) The Internet Society (2004). This document is subject 2196 to the rights, licenses and restrictions contained in BCP 78 and 2197 except as set forth therein, the authors retain all their rights. 2199 This document and the information contained herein are provided on 2200 "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE 2201 REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE 2202 INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR 2203 IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF 2204 THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED 2205 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 2207 Intellectual Property 2209 The IETF takes no position regarding the validity or scope of any 2210 Intellectual Property Rights or other rights that might be claimed 2211 to pertain to the implementation or use of the technology described 2212 in this document or the extent to which any license under such 2213 rights might or might not be available; nor does it represent that 2214 it has made any independent effort to identify any such rights. 2215 Information on the procedures with respect to rights in RFC 2216 documents can be found in BCP 78 and BCP 79. 2218 Copies of IPR disclosures made to the IETF Secretariat and any 2219 assurances of licenses to be made available, or the result of an 2220 attempt made to obtain a general license or permission for the use 2221 of such proprietary rights by implementers or users of this 2222 specification can be obtained from the IETF on-line IPR repository 2223 at http://www.ietf.org/ipr. 2225 The IETF invites any interested party to bring to its attention any 2226 copyrights, patents or patent applications, or other proprietary 2227 rights that may cover technology that may be required to implement 2228 this standard. Please address the information to the IETF at ietf- 2229 ipr@ietf.org. 2231 Andersen et. al. Experimental - Expires November 29th, 2004 42 2232 Internet Low Bit Rate Codec May 04 2234 APPENDIX A REFERENCE IMPLEMENTATION 2236 This appendix contains the complete c-code for a reference 2237 implementation of encoder and decoder for the specified codec. 2239 The c-code consists of the following files with highest level 2240 functions: 2242 iLBC_test.c: main function for evaluation purpose 2243 iLBC_encode.h: encoder header 2244 iLBC_encode.c: encoder function 2245 iLBC_decode.h: decoder header 2246 iLBC_decode.c: decoder function 2248 the following files containing global defines and constants: 2250 iLBC_define.h: global defines 2251 constants.h: global constants header 2252 constants.c: global constants memory allocations 2254 and the following files containing subroutines: 2256 anaFilter.h: lpc analysis filter header 2257 anaFilter.c: lpc analysis filter function 2258 createCB.h: codebook construction header 2259 createCB.c: codebook construction function 2260 doCPLC.h: packet loss concealment header 2261 doCPLC.c: packet loss concealment function 2262 enhancer.h: signal enhancement header 2263 enhancer.c: signal enhancement function 2264 filter.h: general filter header 2265 filter.c: general filter functions 2266 FrameClassify.h: start state classification header 2267 FrameClassify.c: start state classification function 2268 gainquant.h: gain quantization header 2269 gainquant.c: gain quantization function 2270 getCBvec.h: codebook vector construction header 2271 getCBvec.c: codebook vector construction function 2272 helpfun.h: general purpose header 2273 helpfun.c: general purpose functions 2274 hpInput.h: input high pass filter header 2275 hpInput.c: input high pass filter function 2276 hpOutput.h: output high pass filter header 2277 hpOutput.c: output high pass filter function 2278 iCBConstruct.h: excitation decoding header 2279 iCBConstruct.c: excitation decoding function 2280 iCBSearch.h: excitation encoding header 2281 iCBSearch.c: excitation encoding function 2282 LPCdecode.h: lpc decoding header 2283 LPCdecode.c: lpc decoding function 2284 LPCencode.h: lpc encoding header 2285 LPCencode.c: lpc encoding function 2286 lsf.h: line spectral frequencies header 2287 lsf.c: line spectral frequencies functions 2289 Andersen et. al. Experimental - Expires November 29th, 2004 43 2290 Internet Low Bit Rate Codec May 04 2292 packing.h: bitstream packetization header 2293 packing.c: bitstream packetization functions 2294 StateConstructW.h: state decoding header 2295 StateConstructW.c: state decoding functions 2296 StateSearchW.h: state encoding header 2297 StateSearchW.c: state encoding function 2298 syntFilter.h: lpc synthesis filter header 2299 syntFilter.c: lpc synthesis filter function 2301 The implementation is portable and should work on many different 2302 platforms. However, it is not difficult to optimize the 2303 implementation on particular platforms, an exercise left to the 2304 reader. 2306 A.1 iLBC_test.c 2308 /****************************************************************** 2310 iLBC Speech Coder ANSI-C Source Code 2312 iLBC_test.c 2314 Copyright (C) The Internet Society (2004). 2315 All Rights Reserved. 2317 ******************************************************************/ 2319 #include 2320 #include 2321 #include 2322 #include 2323 #include "iLBC_define.h" 2324 #include "iLBC_encode.h" 2325 #include "iLBC_decode.h" 2327 /* Runtime statistics */ 2328 #include 2330 #define ILBCNOOFWORDS_MAX (NO_OF_BYTES_30MS/2) 2332 /*----------------------------------------------------------------* 2333 * Encoder interface function 2334 *---------------------------------------------------------------*/ 2336 short encode( /* (o) Number of bytes encoded */ 2337 iLBC_Enc_Inst_t *iLBCenc_inst, 2338 /* (i/o) Encoder instance */ 2339 short *encoded_data, /* (o) The encoded bytes */ 2340 short *data /* (i) The signal block to encode*/ 2341 ){ 2342 float block[BLOCKL_MAX]; 2343 int k; 2345 Andersen et. al. Experimental - Expires November 29th, 2004 44 2346 Internet Low Bit Rate Codec May 04 2348 /* convert signal to float */ 2350 for (k=0; kblockl; k++) 2351 block[k] = (float)data[k]; 2353 /* do the actual encoding */ 2355 iLBC_encode((unsigned char *)encoded_data, block, iLBCenc_inst); 2357 return (iLBCenc_inst->no_of_bytes); 2358 } 2360 /*----------------------------------------------------------------* 2361 * Decoder interface function 2362 *---------------------------------------------------------------*/ 2364 short decode( /* (o) Number of decoded samples */ 2365 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */ 2366 short *decoded_data, /* (o) Decoded signal block*/ 2367 short *encoded_data, /* (i) Encoded bytes */ 2368 short mode /* (i) 0=PL, 1=Normal */ 2369 ){ 2370 int k; 2371 float decblock[BLOCKL_MAX], dtmp; 2373 /* check if mode is valid */ 2375 if (mode<0 || mode>1) { 2376 printf("\nERROR - Wrong mode - 0, 1 allowed\n"); exit(3);} 2378 /* do actual decoding of block */ 2380 iLBC_decode(decblock, (unsigned char *)encoded_data, 2381 iLBCdec_inst, mode); 2383 /* convert to short */ 2385 for (k=0; kblockl; k++){ 2386 dtmp=decblock[k]; 2388 if (dtmpMAX_SAMPLE) 2391 dtmp=MAX_SAMPLE; 2392 decoded_data[k] = (short) dtmp; 2393 } 2395 return (iLBCdec_inst->blockl); 2396 } 2398 /*---------------------------------------------------------------* 2399 * Main program to test iLBC encoding and decoding 2400 * 2402 Andersen et. al. Experimental - Expires November 29th, 2004 45 2403 Internet Low Bit Rate Codec May 04 2405 * Usage: 2406 * exefile_name.exe 2407 * 2408 * : Input file, speech for encoder (16-bit pcm file) 2409 * : Bit stream output from the encoder 2410 * : Output file, decoded speech (16-bit pcm file) 2411 * : Bit error file, optional (16-bit) 2412 * 1 - Packet received correctly 2413 * 0 - Packet Lost 2414 * 2415 *--------------------------------------------------------------*/ 2417 int main(int argc, char* argv[]) 2418 { 2420 /* Runtime statistics */ 2422 float starttime; 2423 float runtime; 2424 float outtime; 2426 FILE *ifileid,*efileid,*ofileid, *cfileid; 2427 short data[BLOCKL_MAX]; 2428 short encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX]; 2429 int len; 2430 short pli, mode; 2431 int blockcount = 0; 2432 int packetlosscount = 0; 2434 /* Create structs */ 2435 iLBC_Enc_Inst_t Enc_Inst; 2436 iLBC_Dec_Inst_t Dec_Inst; 2438 /* get arguments and open files */ 2440 if ((argc!=5) && (argc!=6)) { 2441 fprintf(stderr, 2442 "\n*-----------------------------------------------*\n"); 2443 fprintf(stderr, 2444 " %s <20,30> input encoded decoded (channel)\n\n", 2445 argv[0]); 2446 fprintf(stderr, 2447 " mode : Frame size for the encoding/decoding\n"); 2448 fprintf(stderr, 2449 " 20 - 20 ms\n"); 2450 fprintf(stderr, 2451 " 30 - 30 ms\n"); 2452 fprintf(stderr, 2453 " input : Speech for encoder (16-bit pcm file)\n"); 2454 fprintf(stderr, 2455 " encoded : Encoded bit stream\n"); 2456 fprintf(stderr, 2457 " decoded : Decoded speech (16-bit pcm file)\n"); 2458 fprintf(stderr, 2460 Andersen et. al. Experimental - Expires November 29th, 2004 46 2461 Internet Low Bit Rate Codec May 04 2463 " channel : Packet loss pattern, optional (16-bit)\n"); 2464 fprintf(stderr, 2465 " 1 - Packet received correctly\n"); 2466 fprintf(stderr, 2467 " 0 - Packet Lost\n"); 2468 fprintf(stderr, 2469 "*-----------------------------------------------*\n\n"); 2470 exit(1); 2471 } 2472 mode=atoi(argv[1]); 2473 if (mode != 20 && mode != 30) { 2474 fprintf(stderr,"Wrong mode %s, must be 20, or 30\n", 2475 argv[1]); 2476 exit(2); 2477 } 2478 if ( (ifileid=fopen(argv[2],"rb")) == NULL) { 2479 fprintf(stderr,"Cannot open input file %s\n", argv[2]); 2480 exit(2);} 2481 if ( (efileid=fopen(argv[3],"wb")) == NULL) { 2482 fprintf(stderr, "Cannot open encoded file file %s\n", 2483 argv[3]); exit(1);} 2484 if ( (ofileid=fopen(argv[4],"wb")) == NULL) { 2485 fprintf(stderr, "Cannot open decoded file %s\n", 2486 argv[4]); exit(1);} 2487 if (argc==6) { 2488 if( (cfileid=fopen(argv[5],"rb")) == NULL) { 2489 fprintf(stderr, "Cannot open channel file %s\n", 2490 argv[5]); 2491 exit(1); 2492 } 2493 } else { 2494 cfileid=NULL; 2495 } 2497 /* print info */ 2499 fprintf(stderr, "\n"); 2500 fprintf(stderr, 2501 "*---------------------------------------------------*\n"); 2502 fprintf(stderr, 2503 "* *\n"); 2504 fprintf(stderr, 2505 "* iLBC test program *\n"); 2506 fprintf(stderr, 2507 "* *\n"); 2508 fprintf(stderr, 2509 "* *\n"); 2510 fprintf(stderr, 2511 "*---------------------------------------------------*\n"); 2512 fprintf(stderr,"\nMode : %2d ms\n", mode); 2513 fprintf(stderr,"Input file : %s\n", argv[2]); 2514 fprintf(stderr,"Encoded file : %s\n", argv[3]); 2515 fprintf(stderr,"Output file : %s\n", argv[4]); 2516 if (argc==6) { 2518 Andersen et. al. Experimental - Expires November 29th, 2004 47 2519 Internet Low Bit Rate Codec May 04 2521 fprintf(stderr,"Channel file : %s\n", argv[5]); 2522 } 2523 fprintf(stderr,"\n"); 2525 /* Initialization */ 2527 initEncode(&Enc_Inst, mode); 2528 initDecode(&Dec_Inst, mode, 1); 2530 /* Runtime statistics */ 2532 starttime=clock()/(float)CLOCKS_PER_SEC; 2534 /* loop over input blocks */ 2536 while (fread(data,sizeof(short),Enc_Inst.blockl,ifileid)== 2537 Enc_Inst.blockl) { 2539 blockcount++; 2541 /* encoding */ 2543 fprintf(stderr, "--- Encoding block %i --- ",blockcount); 2544 len=encode(&Enc_Inst, encoded_data, data); 2545 fprintf(stderr, "\r"); 2547 /* write byte file */ 2549 fwrite(encoded_data, sizeof(unsigned char), len, efileid); 2551 /* get channel data if provided */ 2552 if (argc==6) { 2553 if (fread(&pli, sizeof(short), 1, cfileid)) { 2554 if ((pli!=0)&&(pli!=1)) { 2555 fprintf(stderr, "Error in channel file\n"); 2556 exit(0); 2557 } 2558 if (pli==0) { 2559 /* Packet loss -> remove info from frame */ 2560 memset(encoded_data, 0, 2561 sizeof(short)*ILBCNOOFWORDS_MAX); 2562 packetlosscount++; 2563 } 2564 } else { 2565 fprintf(stderr, "Error. Channel file too short\n"); 2566 exit(0); 2567 } 2568 } else { 2569 pli=1; 2570 } 2572 /* decoding */ 2574 fprintf(stderr, "--- Decoding block %i --- ",blockcount); 2576 Andersen et. al. Experimental - Expires November 29th, 2004 48 2577 Internet Low Bit Rate Codec May 04 2579 len=decode(&Dec_Inst, decoded_data, encoded_data, pli); 2580 fprintf(stderr, "\r"); 2582 /* write output file */ 2584 fwrite(decoded_data,sizeof(short),len,ofileid); 2585 } 2587 /* Runtime statistics */ 2589 runtime = (float)(clock()/(float)CLOCKS_PER_SEC-starttime); 2590 outtime = (float)((float)blockcount*(float)mode/1000.0); 2591 printf("\n\nLength of speech file: %.1f s\n", outtime); 2592 printf("Packet loss : %.1f%%\n", 2593 100.0*(float)packetlosscount/(float)blockcount); 2594 printf("Time to run iLBC :"); 2595 printf(" %.1f s (%.1f %% of realtime)\n\n", runtime, 2596 (100*runtime/outtime)); 2598 /* close files */ 2600 fclose(ifileid); fclose(efileid); fclose(ofileid); 2601 if (argc==6) { 2602 fclose(cfileid); 2603 } 2604 return(0); 2605 } 2607 A.2 iLBC_encode.h 2609 /****************************************************************** 2611 iLBC Speech Coder ANSI-C Source Code 2613 iLBC_encode.h 2615 Copyright (C) The Internet Society (2004). 2616 All Rights Reserved. 2618 ******************************************************************/ 2620 #ifndef __iLBC_ILBCENCODE_H 2621 #define __iLBC_ILBCENCODE_H 2623 #include "iLBC_define.h" 2625 short initEncode( /* (o) Number of bytes 2626 encoded */ 2627 iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */ 2628 int mode /* (i) frame size mode */ 2629 ); 2631 void iLBC_encode( 2633 Andersen et. al. Experimental - Expires November 29th, 2004 49 2634 Internet Low Bit Rate Codec May 04 2636 unsigned char *bytes, /* (o) encoded data bits iLBC */ 2637 float *block, /* (o) speech vector to 2638 encode */ 2639 iLBC_Enc_Inst_t *iLBCenc_inst /* (i/o) the general encoder 2640 state */ 2641 ); 2643 #endif 2645 A.3 iLBC_encode.c 2647 /****************************************************************** 2649 iLBC Speech Coder ANSI-C Source Code 2651 iLBC_encode.c 2653 Copyright (C) The Internet Society (2004). 2654 All Rights Reserved. 2656 ******************************************************************/ 2658 #include 2659 #include 2660 #include 2662 #include "iLBC_define.h" 2663 #include "LPCencode.h" 2664 #include "FrameClassify.h" 2665 #include "StateSearchW.h" 2666 #include "StateConstructW.h" 2667 #include "helpfun.h" 2668 #include "constants.h" 2669 #include "packing.h" 2670 #include "iCBSearch.h" 2671 #include "iCBConstruct.h" 2672 #include "hpInput.h" 2673 #include "anaFilter.h" 2674 #include "syntFilter.h" 2676 /*----------------------------------------------------------------* 2677 * Initiation of encoder instance. 2678 *---------------------------------------------------------------*/ 2680 short initEncode( /* (o) Number of bytes 2681 encoded */ 2682 iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */ 2683 int mode /* (i) frame size mode */ 2684 ){ 2685 iLBCenc_inst->mode = mode; 2686 if (mode==30) { 2687 iLBCenc_inst->blockl = BLOCKL_30MS; 2688 iLBCenc_inst->nsub = NSUB_30MS; 2690 Andersen et. al. Experimental - Expires November 29th, 2004 50 2691 Internet Low Bit Rate Codec May 04 2693 iLBCenc_inst->nasub = NASUB_30MS; 2694 iLBCenc_inst->lpc_n = LPC_N_30MS; 2695 iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS; 2696 iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS; 2697 iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS; 2698 /* ULP init */ 2699 iLBCenc_inst->ULP_inst=&ULP_30msTbl; 2700 } 2701 else if (mode==20) { 2702 iLBCenc_inst->blockl = BLOCKL_20MS; 2703 iLBCenc_inst->nsub = NSUB_20MS; 2704 iLBCenc_inst->nasub = NASUB_20MS; 2705 iLBCenc_inst->lpc_n = LPC_N_20MS; 2706 iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS; 2707 iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS; 2708 iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS; 2709 /* ULP init */ 2710 iLBCenc_inst->ULP_inst=&ULP_20msTbl; 2711 } 2712 else { 2713 exit(2); 2714 } 2716 memset((*iLBCenc_inst).anaMem, 0, 2717 LPC_FILTERORDER*sizeof(float)); 2718 memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl, 2719 LPC_FILTERORDER*sizeof(float)); 2720 memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl, 2721 LPC_FILTERORDER*sizeof(float)); 2722 memset((*iLBCenc_inst).lpc_buffer, 0, 2723 (LPC_LOOKBACK+BLOCKL_MAX)*sizeof(float)); 2724 memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float)); 2726 return (iLBCenc_inst->no_of_bytes); 2727 } 2729 /*----------------------------------------------------------------* 2730 * main encoder function 2731 *---------------------------------------------------------------*/ 2733 void iLBC_encode( 2734 unsigned char *bytes, /* (o) encoded data bits iLBC */ 2735 float *block, /* (o) speech vector to 2736 encode */ 2737 iLBC_Enc_Inst_t *iLBCenc_inst /* (i/o) the general encoder 2738 state */ 2739 ){ 2741 float data[BLOCKL_MAX]; 2742 float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX]; 2744 int start, idxForMax, idxVec[STATE_LEN]; 2745 float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML]; 2746 int n, k, meml_gotten, Nfor, Nback, i, pos; 2748 Andersen et. al. Experimental - Expires November 29th, 2004 51 2749 Internet Low Bit Rate Codec May 04 2751 int gain_index[CB_NSTAGES*NASUB_MAX], 2752 extra_gain_index[CB_NSTAGES]; 2753 int cb_index[CB_NSTAGES*NASUB_MAX],extra_cb_index[CB_NSTAGES]; 2754 int lsf_i[LSF_NSPLIT*LPC_N_MAX]; 2755 unsigned char *pbytes; 2756 int diff, start_pos, state_first; 2757 float en1, en2; 2758 int index, ulp, firstpart; 2759 int subcount, subframe; 2760 float weightState[LPC_FILTERORDER]; 2761 float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; 2762 float weightdenum[NSUB_MAX*(LPC_FILTERORDER+1)]; 2763 float decresidual[BLOCKL_MAX]; 2765 /* high pass filtering of input signal if such is not done 2766 prior to calling this function */ 2768 hpInput(block, iLBCenc_inst->blockl, 2769 data, (*iLBCenc_inst).hpimem); 2771 /* otherwise simply copy */ 2773 /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float));*/ 2775 /* LPC of hp filtered input data */ 2777 LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst); 2779 /* inverse filter to get residual */ 2781 for (n=0; nnsub; n++) { 2782 anaFilter(&data[n*SUBL], &syntdenum[n*(LPC_FILTERORDER+1)], 2783 SUBL, &residual[n*SUBL], iLBCenc_inst->anaMem); 2784 } 2786 /* find state location */ 2788 start = FrameClassify(iLBCenc_inst, residual); 2790 /* check if state should be in first or last part of the 2791 two subframes */ 2793 diff = STATE_LEN - iLBCenc_inst->state_short_len; 2794 en1 = 0; 2795 index = (start-1)*SUBL; 2796 for (i = 0; i < iLBCenc_inst->state_short_len; i++) { 2797 en1 += residual[index+i]*residual[index+i]; 2798 } 2799 en2 = 0; 2800 index = (start-1)*SUBL+diff; 2801 for (i = 0; i < iLBCenc_inst->state_short_len; i++) { 2802 en2 += residual[index+i]*residual[index+i]; 2803 } 2805 Andersen et. al. Experimental - Expires November 29th, 2004 52 2806 Internet Low Bit Rate Codec May 04 2808 if (en1 > en2) { 2809 state_first = 1; 2810 start_pos = (start-1)*SUBL; 2811 } else { 2812 state_first = 0; 2813 start_pos = (start-1)*SUBL + diff; 2814 } 2816 /* scalar quantization of state */ 2818 StateSearchW(iLBCenc_inst, &residual[start_pos], 2819 &syntdenum[(start-1)*(LPC_FILTERORDER+1)], 2820 &weightdenum[(start-1)*(LPC_FILTERORDER+1)], &idxForMax, 2821 idxVec, iLBCenc_inst->state_short_len, state_first); 2823 StateConstructW(idxForMax, idxVec, 2824 &syntdenum[(start-1)*(LPC_FILTERORDER+1)], 2825 &decresidual[start_pos], iLBCenc_inst->state_short_len); 2827 /* predictive quantization in state */ 2829 if (state_first) { /* put adaptive part in the end */ 2831 /* setup memory */ 2833 memset(mem, 0, 2834 (CB_MEML-iLBCenc_inst->state_short_len)*sizeof(float)); 2835 memcpy(mem+CB_MEML-iLBCenc_inst->state_short_len, 2836 decresidual+start_pos, 2837 iLBCenc_inst->state_short_len*sizeof(float)); 2838 memset(weightState, 0, LPC_FILTERORDER*sizeof(float)); 2840 /* encode sub-frames */ 2842 iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index, 2843 &residual[start_pos+iLBCenc_inst->state_short_len], 2844 mem+CB_MEML-stMemLTbl, 2845 stMemLTbl, diff, CB_NSTAGES, 2846 &weightdenum[start*(LPC_FILTERORDER+1)], 2847 weightState, 0); 2849 /* construct decoded vector */ 2851 iCBConstruct( 2852 &decresidual[start_pos+iLBCenc_inst->state_short_len], 2853 extra_cb_index, extra_gain_index, 2854 mem+CB_MEML-stMemLTbl, 2855 stMemLTbl, diff, CB_NSTAGES); 2857 } 2858 else { /* put adaptive part in the beginning */ 2860 Andersen et. al. Experimental - Expires November 29th, 2004 53 2861 Internet Low Bit Rate Codec May 04 2863 /* create reversed vectors for prediction */ 2865 for (k=0; kstate_short_len)]; 2868 } 2870 /* setup memory */ 2872 meml_gotten = iLBCenc_inst->state_short_len; 2873 for (k=0; knsub-start-1; 2908 if ( Nfor > 0 ) { 2910 /* setup memory */ 2912 memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float)); 2913 memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, 2914 STATE_LEN*sizeof(float)); 2915 memset(weightState, 0, LPC_FILTERORDER*sizeof(float)); 2917 Andersen et. al. Experimental - Expires November 29th, 2004 54 2918 Internet Low Bit Rate Codec May 04 2920 /* loop over sub-frames to encode */ 2922 for (subframe=0; subframe 0 ) { 2961 /* create reverse order vectors */ 2963 for (n=0; nnsub+1-start); 2979 if ( meml_gotten > CB_MEML ) { 2980 meml_gotten=CB_MEML; 2981 } 2982 for (k=0; klpc_n; k++) { 3050 packsplit(&lsf_i[k], &firstpart, &lsf_i[k], 3051 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], 3052 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp]+ 3053 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+1]+ 3054 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+2]); 3055 dopack( &pbytes, firstpart, 3056 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos); 3057 } 3059 /* Start block info */ 3061 packsplit(&start, &firstpart, &start, 3062 iLBCenc_inst->ULP_inst->start_bits[ulp], 3063 iLBCenc_inst->ULP_inst->start_bits[ulp]+ 3064 iLBCenc_inst->ULP_inst->start_bits[ulp+1]+ 3065 iLBCenc_inst->ULP_inst->start_bits[ulp+2]); 3066 dopack( &pbytes, firstpart, 3067 iLBCenc_inst->ULP_inst->start_bits[ulp], &pos); 3069 packsplit(&state_first, &firstpart, &state_first, 3070 iLBCenc_inst->ULP_inst->startfirst_bits[ulp], 3071 iLBCenc_inst->ULP_inst->startfirst_bits[ulp]+ 3072 iLBCenc_inst->ULP_inst->startfirst_bits[ulp+1]+ 3073 iLBCenc_inst->ULP_inst->startfirst_bits[ulp+2]); 3074 dopack( &pbytes, firstpart, 3075 iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos); 3077 packsplit(&idxForMax, &firstpart, &idxForMax, 3078 iLBCenc_inst->ULP_inst->scale_bits[ulp], 3079 iLBCenc_inst->ULP_inst->scale_bits[ulp]+ 3080 iLBCenc_inst->ULP_inst->scale_bits[ulp+1]+ 3081 iLBCenc_inst->ULP_inst->scale_bits[ulp+2]); 3082 dopack( &pbytes, firstpart, 3083 iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos); 3085 Andersen et. al. Experimental - Expires November 29th, 2004 57 3086 Internet Low Bit Rate Codec May 04 3088 for (k=0; kstate_short_len; k++) { 3089 packsplit(idxVec+k, &firstpart, idxVec+k, 3090 iLBCenc_inst->ULP_inst->state_bits[ulp], 3091 iLBCenc_inst->ULP_inst->state_bits[ulp]+ 3092 iLBCenc_inst->ULP_inst->state_bits[ulp+1]+ 3093 iLBCenc_inst->ULP_inst->state_bits[ulp+2]); 3094 dopack( &pbytes, firstpart, 3095 iLBCenc_inst->ULP_inst->state_bits[ulp], &pos); 3096 } 3098 /* 23/22 (20ms/30ms) sample block */ 3100 for (k=0;kULP_inst->extra_cb_index[k][ulp], 3104 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp]+ 3105 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+1]+ 3106 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+2]); 3107 dopack( &pbytes, firstpart, 3108 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp], 3109 &pos); 3110 } 3112 for (k=0;kULP_inst->extra_cb_gain[k][ulp], 3116 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp]+ 3117 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+1]+ 3118 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+2]); 3119 dopack( &pbytes, firstpart, 3120 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp], 3121 &pos); 3122 } 3124 /* The two/four (20ms/30ms) 40 sample sub-blocks */ 3126 for (i=0; inasub; i++) { 3127 for (k=0; kULP_inst->cb_index[i][k][ulp], 3131 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp]+ 3132 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+1]+ 3133 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+2]); 3134 dopack( &pbytes, firstpart, 3135 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp], 3136 &pos); 3137 } 3138 } 3140 for (i=0; inasub; i++) { 3141 for (k=0; kULP_inst->cb_gain[i][k][ulp], 3149 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp]+ 3150 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+1]+ 3151 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+2]); 3152 dopack( &pbytes, firstpart, 3153 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp], 3154 &pos); 3155 } 3156 } 3157 } 3159 /* set the last bit to zero (otherwise the decoder 3160 will treat it as a lost frame) */ 3161 dopack( &pbytes, 0, 1, &pos); 3162 } 3164 A.4 iLBC_decode.h 3166 /****************************************************************** 3168 iLBC Speech Coder ANSI-C Source Code 3170 iLBC_decode.h 3172 Copyright (C) The Internet Society (2004). 3173 All Rights Reserved. 3175 ******************************************************************/ 3177 #ifndef __iLBC_ILBCDECODE_H 3178 #define __iLBC_ILBCDECODE_H 3180 #include "iLBC_define.h" 3182 short initDecode( /* (o) Number of decoded 3183 samples */ 3184 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */ 3185 int mode, /* (i) frame size mode */ 3186 int use_enhancer /* (i) 1 to use enhancer 3187 0 to run without 3188 enhancer */ 3189 ); 3191 void iLBC_decode( 3192 float *decblock, /* (o) decoded signal block */ 3193 unsigned char *bytes, /* (i) encoded signal bits */ 3194 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state 3195 structure */ 3196 int mode /* (i) 0: bad packet, PLC, 3197 1: normal */ 3198 ); 3200 Andersen et. al. Experimental - Expires November 29th, 2004 59 3201 Internet Low Bit Rate Codec May 04 3203 #endif 3205 A.5 iLBC_decode.c 3207 /****************************************************************** 3209 iLBC Speech Coder ANSI-C Source Code 3211 iLBC_decode.c 3213 Copyright (C) The Internet Society (2004). 3214 All Rights Reserved. 3216 ******************************************************************/ 3218 #include 3219 #include 3221 #include "iLBC_define.h" 3222 #include "StateConstructW.h" 3223 #include "LPCdecode.h" 3224 #include "iCBConstruct.h" 3225 #include "doCPLC.h" 3226 #include "helpfun.h" 3227 #include "constants.h" 3228 #include "packing.h" 3229 #include "string.h" 3230 #include "enhancer.h" 3231 #include "hpOutput.h" 3232 #include "syntFilter.h" 3234 /*----------------------------------------------------------------* 3235 * Initiation of decoder instance. 3236 *---------------------------------------------------------------*/ 3238 short initDecode( /* (o) Number of decoded 3239 samples */ 3240 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */ 3241 int mode, /* (i) frame size mode */ 3242 int use_enhancer /* (i) 1 to use enhancer 3243 0 to run without 3244 enhancer */ 3245 ){ 3246 int i; 3248 iLBCdec_inst->mode = mode; 3250 if (mode==30) { 3251 iLBCdec_inst->blockl = BLOCKL_30MS; 3252 iLBCdec_inst->nsub = NSUB_30MS; 3253 iLBCdec_inst->nasub = NASUB_30MS; 3254 iLBCdec_inst->lpc_n = LPC_N_30MS; 3256 Andersen et. al. Experimental - Expires November 29th, 2004 60 3257 Internet Low Bit Rate Codec May 04 3259 iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS; 3260 iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS; 3261 iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS; 3262 /* ULP init */ 3263 iLBCdec_inst->ULP_inst=&ULP_30msTbl; 3264 } 3265 else if (mode==20) { 3266 iLBCdec_inst->blockl = BLOCKL_20MS; 3267 iLBCdec_inst->nsub = NSUB_20MS; 3268 iLBCdec_inst->nasub = NASUB_20MS; 3269 iLBCdec_inst->lpc_n = LPC_N_20MS; 3270 iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS; 3271 iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS; 3272 iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS; 3273 /* ULP init */ 3274 iLBCdec_inst->ULP_inst=&ULP_20msTbl; 3275 } 3276 else { 3277 exit(2); 3278 } 3280 memset(iLBCdec_inst->syntMem, 0, 3281 LPC_FILTERORDER*sizeof(float)); 3282 memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl, 3283 LPC_FILTERORDER*sizeof(float)); 3285 memset(iLBCdec_inst->old_syntdenum, 0, 3286 ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float)); 3287 for (i=0; iold_syntdenum[i*(LPC_FILTERORDER+1)]=1.0; 3290 iLBCdec_inst->last_lag = 20; 3292 iLBCdec_inst->prevLag = 120; 3293 iLBCdec_inst->per = 0.0; 3294 iLBCdec_inst->consPLICount = 0; 3295 iLBCdec_inst->prevPLI = 0; 3296 iLBCdec_inst->prevLpc[0] = 1.0; 3297 memset(iLBCdec_inst->prevLpc+1,0, 3298 LPC_FILTERORDER*sizeof(float)); 3299 memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float)); 3300 iLBCdec_inst->seed=777; 3302 memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float)); 3304 iLBCdec_inst->use_enhancer = use_enhancer; 3305 memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float)); 3306 for (i=0;ienh_period[i]=(float)40.0; 3309 iLBCdec_inst->prev_enh_pl = 0; 3311 return (iLBCdec_inst->blockl); 3312 } 3314 Andersen et. al. Experimental - Expires November 29th, 2004 61 3315 Internet Low Bit Rate Codec May 04 3317 /*----------------------------------------------------------------* 3318 * frame residual decoder function (subrutine to iLBC_decode) 3319 *---------------------------------------------------------------*/ 3321 void Decode( 3322 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state 3323 structure */ 3324 float *decresidual, /* (o) decoded residual frame */ 3325 int start, /* (i) location of start 3326 state */ 3327 int idxForMax, /* (i) codebook index for the 3328 maximum value */ 3329 int *idxVec, /* (i) codebook indexes for the 3330 samples in the start 3331 state */ 3332 float *syntdenum, /* (i) the decoded synthesis 3333 filter coefficients */ 3334 int *cb_index, /* (i) the indexes for the 3335 adaptive codebook */ 3336 int *gain_index, /* (i) the indexes for the 3337 corresponding gains */ 3338 int *extra_cb_index, /* (i) the indexes for the 3339 adaptive codebook part 3340 of start state */ 3341 int *extra_gain_index, /* (i) the indexes for the 3342 corresponding gains */ 3343 int state_first /* (i) 1 if non adaptive part 3344 of start state comes 3345 first 0 if that part 3346 comes last */ 3347 ){ 3348 float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML]; 3349 int k, meml_gotten, Nfor, Nback, i; 3350 int diff, start_pos; 3351 int subcount, subframe; 3353 diff = STATE_LEN - iLBCdec_inst->state_short_len; 3355 if (state_first == 1) { 3356 start_pos = (start-1)*SUBL; 3357 } else { 3358 start_pos = (start-1)*SUBL + diff; 3359 } 3361 /* decode scalar part of start state */ 3363 StateConstructW(idxForMax, idxVec, 3364 &syntdenum[(start-1)*(LPC_FILTERORDER+1)], 3365 &decresidual[start_pos], iLBCdec_inst->state_short_len); 3367 if (state_first) { /* put adaptive part in the end */ 3369 Andersen et. al. Experimental - Expires November 29th, 2004 62 3370 Internet Low Bit Rate Codec May 04 3372 /* setup memory */ 3374 memset(mem, 0, 3375 (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float)); 3376 memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len, 3377 decresidual+start_pos, 3378 iLBCdec_inst->state_short_len*sizeof(float)); 3380 /* construct decoded vector */ 3382 iCBConstruct( 3383 &decresidual[start_pos+iLBCdec_inst->state_short_len], 3384 extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl, 3385 stMemLTbl, diff, CB_NSTAGES); 3387 } 3388 else {/* put adaptive part in the beginning */ 3390 /* create reversed vectors for prediction */ 3392 for (k=0; kstate_short_len)]; 3396 } 3398 /* setup memory */ 3400 meml_gotten = iLBCdec_inst->state_short_len; 3401 for (k=0; knsub-start-1; 3427 Andersen et. al. Experimental - Expires November 29th, 2004 63 3428 Internet Low Bit Rate Codec May 04 3430 if ( Nfor > 0 ){ 3432 /* setup memory */ 3434 memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float)); 3435 memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL, 3436 STATE_LEN*sizeof(float)); 3438 /* loop over sub-frames to encode */ 3440 for (subframe=0; subframe 0 ) { 3469 /* setup memory */ 3471 meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start); 3473 if ( meml_gotten > CB_MEML ) { 3474 meml_gotten=CB_MEML; 3475 } 3476 for (k=0; k0) { /* the data are good */ 3553 /* decode data */ 3555 pbytes=bytes; 3556 pos=0; 3558 /* Set everything to zero before decoding */ 3560 for (k=0; kstate_short_len; k++) { 3567 idxVec[k]=0; 3568 } 3569 for (k=0; knasub; i++) { 3576 for (k=0; knasub; i++) { 3581 for (k=0; klpc_n; k++){ 3592 unpack( &pbytes, &lastpart, 3593 iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos); 3594 packcombine(&lsf_i[k], lastpart, 3595 iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]); 3596 } 3598 Andersen et. al. Experimental - Expires November 29th, 2004 66 3599 Internet Low Bit Rate Codec May 04 3601 /* Start block info */ 3603 unpack( &pbytes, &lastpart, 3604 iLBCdec_inst->ULP_inst->start_bits[ulp], &pos); 3605 packcombine(&start, lastpart, 3606 iLBCdec_inst->ULP_inst->start_bits[ulp]); 3608 unpack( &pbytes, &lastpart, 3609 iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos); 3610 packcombine(&state_first, lastpart, 3611 iLBCdec_inst->ULP_inst->startfirst_bits[ulp]); 3613 unpack( &pbytes, &lastpart, 3614 iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos); 3615 packcombine(&idxForMax, lastpart, 3616 iLBCdec_inst->ULP_inst->scale_bits[ulp]); 3618 for (k=0; kstate_short_len; k++) { 3619 unpack( &pbytes, &lastpart, 3620 iLBCdec_inst->ULP_inst->state_bits[ulp], &pos); 3621 packcombine(idxVec+k, lastpart, 3622 iLBCdec_inst->ULP_inst->state_bits[ulp]); 3623 } 3625 /* 23/22 (20ms/30ms) sample block */ 3627 for (k=0; kULP_inst->extra_cb_index[k][ulp], 3630 &pos); 3631 packcombine(extra_cb_index+k, lastpart, 3632 iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]); 3633 } 3634 for (k=0; kULP_inst->extra_cb_gain[k][ulp], 3637 &pos); 3638 packcombine(extra_gain_index+k, lastpart, 3639 iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]); 3640 } 3642 /* The two/four (20ms/30ms) 40 sample sub-blocks */ 3644 for (i=0; inasub; i++) { 3645 for (k=0; kULP_inst->cb_index[i][k][ulp], 3648 &pos); 3649 packcombine(cb_index+i*CB_NSTAGES+k, lastpart, 3650 iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]); 3651 } 3652 } 3654 for (i=0; inasub; i++) { 3656 Andersen et. al. Experimental - Expires November 29th, 2004 67 3657 Internet Low Bit Rate Codec May 04 3659 for (k=0; kULP_inst->cb_gain[i][k][ulp], 3663 &pos); 3664 packcombine(gain_index+i*CB_NSTAGES+k, lastpart, 3665 iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]); 3666 } 3667 } 3668 } 3669 /* Extract last bit. If it is 1 this indicates an 3670 empty/lost frame */ 3671 unpack( &pbytes, &last_bit, 1, &pos); 3673 /* Check for bit errors or empty/lost frames */ 3674 if (start<1) 3675 mode = 0; 3676 if (iLBCdec_inst->mode==20 && start>3) 3677 mode = 0; 3678 if (iLBCdec_inst->mode==30 && start>5) 3679 mode = 0; 3680 if (last_bit==1) 3681 mode = 0; 3683 if (mode==1) { /* No bit errors was detected, 3684 continue decoding */ 3686 /* adjust index */ 3687 index_conv_dec(cb_index); 3689 /* decode the lsf */ 3691 SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n); 3692 check=LSF_check(lsfdeq, LPC_FILTERORDER, 3693 iLBCdec_inst->lpc_n); 3694 DecoderInterpolateLSF(syntdenum, weightdenum, 3695 lsfdeq, LPC_FILTERORDER, iLBCdec_inst); 3697 Decode(iLBCdec_inst, decresidual, start, idxForMax, 3698 idxVec, syntdenum, cb_index, gain_index, 3699 extra_cb_index, extra_gain_index, 3700 state_first); 3702 /* preparing the plc for a future loss! */ 3704 doThePLC(PLCresidual, PLClpc, 0, decresidual, 3705 syntdenum + 3706 (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1), 3707 (*iLBCdec_inst).last_lag, iLBCdec_inst); 3709 memcpy(decresidual, PLCresidual, 3710 iLBCdec_inst->blockl*sizeof(float)); 3711 } 3713 Andersen et. al. Experimental - Expires November 29th, 2004 68 3714 Internet Low Bit Rate Codec May 04 3716 } 3718 if (mode == 0) { 3719 /* the data is bad (either a PLC call 3720 * was made or a severe bit error was detected) 3721 */ 3723 /* packet loss conceal */ 3725 memset(zeros, 0, BLOCKL_MAX*sizeof(float)); 3727 one[0] = 1; 3728 memset(one+1, 0, LPC_FILTERORDER*sizeof(float)); 3730 start=0; 3732 doThePLC(PLCresidual, PLClpc, 1, zeros, one, 3733 (*iLBCdec_inst).last_lag, iLBCdec_inst); 3734 memcpy(decresidual, PLCresidual, 3735 iLBCdec_inst->blockl*sizeof(float)); 3737 order_plus_one = LPC_FILTERORDER + 1; 3738 for (i = 0; i < iLBCdec_inst->nsub; i++) { 3739 memcpy(syntdenum+(i*order_plus_one), PLClpc, 3740 order_plus_one*sizeof(float)); 3741 } 3742 } 3744 if (iLBCdec_inst->use_enhancer == 1) { 3746 /* post filtering */ 3748 iLBCdec_inst->last_lag = 3749 enhancerInterface(data, decresidual, iLBCdec_inst); 3751 /* synthesis filtering */ 3753 if (iLBCdec_inst->mode==20) { 3754 /* Enhancer has 40 samples delay */ 3755 i=0; 3756 syntFilter(data + i*SUBL, 3757 iLBCdec_inst->old_syntdenum + 3758 (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1), 3759 SUBL, iLBCdec_inst->syntMem); 3760 for (i=1; i < iLBCdec_inst->nsub; i++) { 3761 syntFilter(data + i*SUBL, 3762 syntdenum + (i-1)*(LPC_FILTERORDER+1), 3763 SUBL, iLBCdec_inst->syntMem); 3764 } 3765 } else if (iLBCdec_inst->mode==30) { 3766 /* Enhancer has 80 samples delay */ 3767 for (i=0; i < 2; i++) { 3768 syntFilter(data + i*SUBL, 3770 Andersen et. al. Experimental - Expires November 29th, 2004 69 3771 Internet Low Bit Rate Codec May 04 3773 iLBCdec_inst->old_syntdenum + 3774 (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1), 3775 SUBL, iLBCdec_inst->syntMem); 3776 } 3777 for (i=2; i < iLBCdec_inst->nsub; i++) { 3778 syntFilter(data + i*SUBL, 3779 syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL, 3780 iLBCdec_inst->syntMem); 3781 } 3782 } 3784 } else { 3786 /* Find last lag */ 3787 lag = 20; 3788 maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], 3789 &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL); 3791 for (ilag=21; ilag<120; ilag++) { 3792 cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL], 3793 &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag], 3794 ENH_BLOCKL); 3796 if (cc > maxcc) { 3797 maxcc = cc; 3798 lag = ilag; 3799 } 3800 } 3801 iLBCdec_inst->last_lag = lag; 3803 /* copy data and run synthesis filter */ 3805 memcpy(data, decresidual, 3806 iLBCdec_inst->blockl*sizeof(float)); 3807 for (i=0; i < iLBCdec_inst->nsub; i++) { 3808 syntFilter(data + i*SUBL, 3809 syntdenum + i*(LPC_FILTERORDER+1), SUBL, 3810 iLBCdec_inst->syntMem); 3811 } 3812 } 3814 /* high pass filtering on output if desired, otherwise 3815 copy to out */ 3817 hpOutput(data, iLBCdec_inst->blockl, 3818 decblock,iLBCdec_inst->hpomem); 3820 /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/ 3822 memcpy(iLBCdec_inst->old_syntdenum, syntdenum, 3824 iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float)); 3826 iLBCdec_inst->prev_enh_pl=0; 3828 Andersen et. al. Experimental - Expires November 29th, 2004 70 3829 Internet Low Bit Rate Codec May 04 3831 if (mode==0) { /* PLC was used */ 3832 iLBCdec_inst->prev_enh_pl=1; 3833 } 3834 } 3836 A.6 iLBC_define.h 3838 /****************************************************************** 3840 iLBC Speech Coder ANSI-C Source Code 3842 iLBC_define.h 3844 Copyright (C) The Internet Society (2004). 3845 All Rights Reserved. 3847 ******************************************************************/ 3848 #include 3850 #ifndef __iLBC_ILBCDEFINE_H 3851 #define __iLBC_ILBCDEFINE_H 3853 /* general codec settings */ 3855 #define FS (float)8000.0 3856 #define BLOCKL_20MS 160 3857 #define BLOCKL_30MS 240 3858 #define BLOCKL_MAX 240 3859 #define NSUB_20MS 4 3860 #define NSUB_30MS 6 3861 #define NSUB_MAX 6 3862 #define NASUB_20MS 2 3863 #define NASUB_30MS 4 3864 #define NASUB_MAX 4 3865 #define SUBL 40 3866 #define STATE_LEN 80 3867 #define STATE_SHORT_LEN_30MS 58 3868 #define STATE_SHORT_LEN_20MS 57 3870 /* LPC settings */ 3872 #define LPC_FILTERORDER 10 3873 #define LPC_CHIRP_SYNTDENUM (float)0.9025 3874 #define LPC_CHIRP_WEIGHTDENUM (float)0.4222 3875 #define LPC_LOOKBACK 60 3876 #define LPC_N_20MS 1 3877 #define LPC_N_30MS 2 3878 #define LPC_N_MAX 2 3879 #define LPC_ASYMDIFF 20 3880 #define LPC_BW (float)60.0 3881 #define LPC_WN (float)1.0001 3882 #define LSF_NSPLIT 3 3884 Andersen et. al. Experimental - Expires November 29th, 2004 71 3885 Internet Low Bit Rate Codec May 04 3887 #define LSF_NUMBER_OF_STEPS 4 3888 #define LPC_HALFORDER (LPC_FILTERORDER/2) 3890 /* cb settings */ 3892 #define CB_NSTAGES 3 3893 #define CB_EXPAND 2 3894 #define CB_MEML 147 3895 #define CB_FILTERLEN 2*4 3896 #define CB_HALFFILTERLEN 4 3897 #define CB_RESRANGE 34 3898 #define CB_MAXGAIN (float)1.3 3900 /* enhancer */ 3902 #define ENH_BLOCKL 80 /* block length */ 3903 #define ENH_BLOCKL_HALF (ENH_BLOCKL/2) 3904 #define ENH_HL 3 /* 2*ENH_HL+1 is number blocks 3905 in said second sequence */ 3906 #define ENH_SLOP 2 /* max difference estimated and 3907 correct pitch period */ 3908 #define ENH_PLOCSL 20 /* pitch-estimates and pitch- 3909 locations buffer length */ 3910 #define ENH_OVERHANG 2 3911 #define ENH_UPS0 4 /* upsampling rate */ 3912 #define ENH_FL0 3 /* 2*FLO+1 is the length of 3913 each filter */ 3914 #define ENH_VECTL (ENH_BLOCKL+2*ENH_FL0) 3915 #define ENH_CORRDIM (2*ENH_SLOP+1) 3916 #define ENH_NBLOCKS (BLOCKL_MAX/ENH_BLOCKL) 3917 #define ENH_NBLOCKS_EXTRA 5 3918 #define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS + 3919 ENH_NBLOCKS_EXTRA */ 3920 #define ENH_BUFL (ENH_NBLOCKS_TOT)*ENH_BLOCKL 3921 #define ENH_ALPHA0 (float)0.05 3923 /* Down sampling */ 3925 #define FILTERORDER_DS 7 3926 #define DELAY_DS 3 3927 #define FACTOR_DS 2 3929 /* bit stream defs */ 3931 #define NO_OF_BYTES_20MS 38 3932 #define NO_OF_BYTES_30MS 50 3933 #define NO_OF_WORDS_20MS 19 3934 #define NO_OF_WORDS_30MS 25 3935 #define STATE_BITS 3 3936 #define BYTE_LEN 8 3937 #define ULP_CLASSES 3 3939 /* help parameters */ 3941 Andersen et. al. Experimental - Expires November 29th, 2004 72 3942 Internet Low Bit Rate Codec May 04 3944 #define FLOAT_MAX (float)1.0e37 3945 #define EPS (float)2.220446049250313e-016 3946 #define PI (float)3.14159265358979323846 3947 #define MIN_SAMPLE -32768 3948 #define MAX_SAMPLE 32767 3949 #define TWO_PI (float)6.283185307 3950 #define PI2 (float)0.159154943 3952 /* type definition encoder instance */ 3953 typedef struct iLBC_ULP_Inst_t_ { 3954 int lsf_bits[6][ULP_CLASSES+2]; 3955 int start_bits[ULP_CLASSES+2]; 3956 int startfirst_bits[ULP_CLASSES+2]; 3957 int scale_bits[ULP_CLASSES+2]; 3958 int state_bits[ULP_CLASSES+2]; 3959 int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2]; 3960 int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2]; 3961 int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2]; 3962 int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2]; 3963 } iLBC_ULP_Inst_t; 3965 /* type definition encoder instance */ 3966 typedef struct iLBC_Enc_Inst_t_ { 3968 /* flag for frame size mode */ 3969 int mode; 3971 /* basic parameters for different frame sizes */ 3972 int blockl; 3973 int nsub; 3974 int nasub; 3975 int no_of_bytes, no_of_words; 3976 int lpc_n; 3977 int state_short_len; 3978 const iLBC_ULP_Inst_t *ULP_inst; 3980 /* analysis filter state */ 3981 float anaMem[LPC_FILTERORDER]; 3983 /* old lsf parameters for interpolation */ 3984 float lsfold[LPC_FILTERORDER]; 3985 float lsfdeqold[LPC_FILTERORDER]; 3987 /* signal buffer for LP analysis */ 3988 float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX]; 3990 /* state of input HP filter */ 3991 float hpimem[4]; 3993 } iLBC_Enc_Inst_t; 3995 /* type definition decoder instance */ 3996 typedef struct iLBC_Dec_Inst_t_ { 3998 Andersen et. al. Experimental - Expires November 29th, 2004 73 3999 Internet Low Bit Rate Codec May 04 4001 /* flag for frame size mode */ 4002 int mode; 4004 /* basic parameters for different frame sizes */ 4005 int blockl; 4006 int nsub; 4007 int nasub; 4008 int no_of_bytes, no_of_words; 4009 int lpc_n; 4010 int state_short_len; 4011 const iLBC_ULP_Inst_t *ULP_inst; 4013 /* synthesis filter state */ 4014 float syntMem[LPC_FILTERORDER]; 4016 /* old LSF for interpolation */ 4017 float lsfdeqold[LPC_FILTERORDER]; 4019 /* pitch lag estimated in enhancer and used in PLC */ 4020 int last_lag; 4022 /* PLC state information */ 4023 int prevLag, consPLICount, prevPLI, prev_enh_pl; 4024 float prevLpc[LPC_FILTERORDER+1]; 4025 float prevResidual[NSUB_MAX*SUBL]; 4026 float per; 4027 unsigned long seed; 4029 /* previous synthesis filter parameters */ 4030 float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX]; 4032 /* state of output HP filter */ 4033 float hpomem[4]; 4035 /* enhancer state information */ 4036 int use_enhancer; 4037 float enh_buf[ENH_BUFL]; 4038 float enh_period[ENH_NBLOCKS_TOT]; 4040 } iLBC_Dec_Inst_t; 4042 #endif 4044 A.7 constants.h 4046 /****************************************************************** 4048 iLBC Speech Coder ANSI-C Source Code 4050 constants.h 4052 Copyright (C) The Internet Society (2004). 4053 All Rights Reserved. 4055 Andersen et. al. Experimental - Expires November 29th, 2004 74 4056 Internet Low Bit Rate Codec May 04 4058 ******************************************************************/ 4060 #ifndef __iLBC_CONSTANTS_H 4061 #define __iLBC_CONSTANTS_H 4063 #include "iLBC_define.h" 4065 /* ULP bit allocation */ 4067 extern const iLBC_ULP_Inst_t ULP_20msTbl; 4068 extern const iLBC_ULP_Inst_t ULP_30msTbl; 4070 /* high pass filters */ 4072 extern float hpi_zero_coefsTbl[]; 4073 extern float hpi_pole_coefsTbl[]; 4074 extern float hpo_zero_coefsTbl[]; 4075 extern float hpo_pole_coefsTbl[]; 4077 /* low pass filters */ 4078 extern float lpFilt_coefsTbl[]; 4080 /* LPC analysis and quantization */ 4082 extern float lpc_winTbl[]; 4083 extern float lpc_asymwinTbl[]; 4084 extern float lpc_lagwinTbl[]; 4085 extern float lsfCbTbl[]; 4086 extern float lsfmeanTbl[]; 4087 extern int dim_lsfCbTbl[]; 4088 extern int size_lsfCbTbl[]; 4089 extern float lsf_weightTbl_30ms[]; 4090 extern float lsf_weightTbl_20ms[]; 4092 /* state quantization tables */ 4094 extern float state_sq3Tbl[]; 4095 extern float state_frgqTbl[]; 4097 /* gain quantization tables */ 4099 extern float gain_sq3Tbl[]; 4100 extern float gain_sq4Tbl[]; 4101 extern float gain_sq5Tbl[]; 4103 /* adaptive codebook definitions */ 4105 extern int search_rangeTbl[5][CB_NSTAGES]; 4106 extern int memLfTbl[]; 4107 extern int stMemLTbl; 4108 extern float cbfiltersTbl[CB_FILTERLEN]; 4110 Andersen et. al. Experimental - Expires November 29th, 2004 75 4111 Internet Low Bit Rate Codec May 04 4113 /* enhancer definitions */ 4115 extern float polyphaserTbl[]; 4116 extern float enh_plocsTbl[]; 4118 #endif 4120 A.8 constants.c 4122 /****************************************************************** 4124 iLBC Speech Coder ANSI-C Source Code 4126 constants.c 4128 Copyright (C) The Internet Society (2004). 4129 All Rights Reserved. 4131 ******************************************************************/ 4133 #include "iLBC_define.h" 4135 /* ULP bit allocation */ 4137 /* 20 ms frame */ 4139 const iLBC_ULP_Inst_t ULP_20msTbl = { 4140 /* LSF */ 4141 { {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, 4142 {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}, 4143 /* Start state location, gain and samples */ 4144 {2,0,0,0,0}, 4145 {1,0,0,0,0}, 4146 {6,0,0,0,0}, 4147 {0,1,2,0,0}, 4148 /* extra CB index and extra CB gain */ 4149 {{6,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 4150 {{2,0,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}}, 4151 /* CB index and CB gain */ 4152 { {{7,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 4153 {{0,0,8,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}, 4154 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}, 4155 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}}, 4156 { {{1,2,2,0,0}, {1,1,2,0,0}, {0,0,3,0,0}}, 4157 {{1,1,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}}, 4158 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}, 4159 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}} 4160 }; 4162 /* 30 ms frame */ 4164 const iLBC_ULP_Inst_t ULP_30msTbl = { 4165 /* LSF */ 4166 { {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}, 4168 Andersen et. al. Experimental - Expires November 29th, 2004 76 4169 Internet Low Bit Rate Codec May 04 4171 {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}}, 4172 /* Start state location, gain and samples */ 4173 {3,0,0,0,0}, 4174 {1,0,0,0,0}, 4175 {6,0,0,0,0}, 4176 {0,1,2,0,0}, 4177 /* extra CB index and extra CB gain */ 4178 {{4,2,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 4179 {{1,1,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}}, 4180 /* CB index and CB gain */ 4181 { {{6,1,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}}, 4182 {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}, 4183 {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}, 4184 {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}}, 4185 { {{1,2,2,0,0}, {1,2,1,0,0}, {0,0,3,0,0}}, 4186 {{0,2,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}}, 4187 {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}, 4188 {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}} 4189 }; 4191 /* HP Filters */ 4193 float hpi_zero_coefsTbl[3] = { 4194 (float)0.92727436, (float)-1.8544941, (float)0.92727436 4195 }; 4196 float hpi_pole_coefsTbl[3] = { 4197 (float)1.0, (float)-1.9059465, (float)0.9114024 4198 }; 4199 float hpo_zero_coefsTbl[3] = { 4200 (float)0.93980581, (float)-1.8795834, (float)0.93980581 4201 }; 4202 float hpo_pole_coefsTbl[3] = { 4203 (float)1.0, (float)-1.9330735, (float)0.93589199 4204 }; 4206 /* LP Filter */ 4208 float lpFilt_coefsTbl[FILTERORDER_DS]={ 4209 (float)-0.066650, (float)0.125000, (float)0.316650, 4210 (float)0.414063, (float)0.316650, 4211 (float)0.125000, (float)-0.066650 4212 }; 4214 /* State quantization tables */ 4216 float state_sq3Tbl[8] = { 4217 (float)-3.719849, (float)-2.177490, (float)-1.130005, 4218 (float)-0.309692, (float)0.444214, (float)1.329712, 4219 (float)2.436279, (float)3.983887 4220 }; 4222 float state_frgqTbl[64] = { 4223 (float)1.000085, (float)1.071695, (float)1.140395, 4224 (float)1.206868, (float)1.277188, (float)1.351503, 4226 Andersen et. al. Experimental - Expires November 29th, 2004 77 4227 Internet Low Bit Rate Codec May 04 4229 (float)1.429380, (float)1.500727, (float)1.569049, 4230 (float)1.639599, (float)1.707071, (float)1.781531, 4231 (float)1.840799, (float)1.901550, (float)1.956695, 4232 (float)2.006750, (float)2.055474, (float)2.102787, 4233 (float)2.142819, (float)2.183592, (float)2.217962, 4234 (float)2.257177, (float)2.295739, (float)2.332967, 4235 (float)2.369248, (float)2.402792, (float)2.435080, 4236 (float)2.468598, (float)2.503394, (float)2.539284, 4237 (float)2.572944, (float)2.605036, (float)2.636331, 4238 (float)2.668939, (float)2.698780, (float)2.729101, 4239 (float)2.759786, (float)2.789834, (float)2.818679, 4240 (float)2.848074, (float)2.877470, (float)2.906899, 4241 (float)2.936655, (float)2.967804, (float)3.000115, 4242 (float)3.033367, (float)3.066355, (float)3.104231, 4243 (float)3.141499, (float)3.183012, (float)3.222952, 4244 (float)3.265433, (float)3.308441, (float)3.350823, 4245 (float)3.395275, (float)3.442793, (float)3.490801, 4246 (float)3.542514, (float)3.604064, (float)3.666050, 4247 (float)3.740994, (float)3.830749, (float)3.938770, 4248 (float)4.101764 4249 }; 4251 /* CB tables */ 4253 int search_rangeTbl[5][CB_NSTAGES]={{58,58,58}, {108,44,44}, 4254 {108,108,108}, {108,108,108}, {108,108,108}}; 4255 int stMemLTbl=85; 4256 int memLfTbl[NASUB_MAX]={147,147,147,147}; 4258 /* expansion filter(s) */ 4260 float cbfiltersTbl[CB_FILTERLEN]={ 4261 (float)-0.034180, (float)0.108887, (float)-0.184326, 4262 (float)0.806152, (float)0.713379, (float)-0.144043, 4263 (float)0.083740, (float)-0.033691 4264 }; 4266 /* Gain Quantization */ 4268 float gain_sq3Tbl[8]={ 4269 (float)-1.000000, (float)-0.659973, (float)-0.330017, 4270 (float)0.000000, (float)0.250000, (float)0.500000, 4271 (float)0.750000, (float)1.00000}; 4273 float gain_sq4Tbl[16]={ 4274 (float)-1.049988, (float)-0.900024, (float)-0.750000, 4275 (float)-0.599976, (float)-0.450012, (float)-0.299988, 4276 (float)-0.150024, (float)0.000000, (float)0.150024, 4277 (float)0.299988, (float)0.450012, (float)0.599976, 4278 (float)0.750000, (float)0.900024, (float)1.049988, 4279 (float)1.200012}; 4281 float gain_sq5Tbl[32]={ 4282 (float)0.037476, (float)0.075012, (float)0.112488, 4284 Andersen et. al. Experimental - Expires November 29th, 2004 78 4285 Internet Low Bit Rate Codec May 04 4287 (float)0.150024, (float)0.187500, (float)0.224976, 4288 (float)0.262512, (float)0.299988, (float)0.337524, 4289 (float)0.375000, (float)0.412476, (float)0.450012, 4290 (float)0.487488, (float)0.525024, (float)0.562500, 4291 (float)0.599976, (float)0.637512, (float)0.674988, 4292 (float)0.712524, (float)0.750000, (float)0.787476, 4293 (float)0.825012, (float)0.862488, (float)0.900024, 4294 (float)0.937500, (float)0.974976, (float)1.012512, 4295 (float)1.049988, (float)1.087524, (float)1.125000, 4296 (float)1.162476, (float)1.200012}; 4298 /* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */ 4299 float polyphaserTbl[ENH_UPS0*(2*ENH_FL0+1)]={ 4300 (float)0.000000, (float)0.000000, (float)0.000000, 4301 (float)1.000000, 4302 (float)0.000000, (float)0.000000, (float)0.000000, 4303 (float)0.015625, (float)-0.076904, (float)0.288330, 4304 (float)0.862061, 4305 (float)-0.106445, (float)0.018799, (float)-0.015625, 4306 (float)0.023682, (float)-0.124268, (float)0.601563, 4307 (float)0.601563, 4308 (float)-0.124268, (float)0.023682, (float)-0.023682, 4309 (float)0.018799, (float)-0.106445, (float)0.862061, 4310 (float)0.288330, 4311 (float)-0.076904, (float)0.015625, (float)-0.018799}; 4313 float enh_plocsTbl[ENH_NBLOCKS_TOT] = {(float)40.0, (float)120.0, 4314 (float)200.0, (float)280.0, (float)360.0, 4315 (float)440.0, (float)520.0, (float)600.0}; 4317 /* LPC analysis and quantization */ 4319 int dim_lsfCbTbl[LSF_NSPLIT] = {3, 3, 4}; 4320 int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128}; 4322 float lsfmeanTbl[LPC_FILTERORDER] = { 4323 (float)0.281738, (float)0.445801, (float)0.663330, 4324 (float)0.962524, (float)1.251831, (float)1.533081, 4325 (float)1.850586, (float)2.137817, (float)2.481445, 4326 (float)2.777344}; 4328 float lsf_weightTbl_30ms[6] = {(float)(1.0/2.0), (float)1.0, 4329 (float)(2.0/3.0), 4330 (float)(1.0/3.0), (float)0.0, (float)0.0}; 4332 float lsf_weightTbl_20ms[4] = {(float)(3.0/4.0), (float)(2.0/4.0), 4333 (float)(1.0/4.0), (float)(0.0)}; 4335 /* Hanning LPC window */ 4336 float lpc_winTbl[BLOCKL_MAX]={ 4337 (float)0.000183, (float)0.000671, (float)0.001526, 4338 (float)0.002716, (float)0.004242, (float)0.006104, 4339 (float)0.008301, (float)0.010834, (float)0.013702, 4341 Andersen et. al. Experimental - Expires November 29th, 2004 79 4342 Internet Low Bit Rate Codec May 04 4344 (float)0.016907, (float)0.020416, (float)0.024261, 4345 (float)0.028442, (float)0.032928, (float)0.037750, 4346 (float)0.042877, (float)0.048309, (float)0.054047, 4347 (float)0.060089, (float)0.066437, (float)0.073090, 4348 (float)0.080017, (float)0.087219, (float)0.094727, 4349 (float)0.102509, (float)0.110535, (float)0.118835, 4350 (float)0.127411, (float)0.136230, (float)0.145294, 4351 (float)0.154602, (float)0.164154, (float)0.173920, 4352 (float)0.183899, (float)0.194122, (float)0.204529, 4353 (float)0.215149, (float)0.225952, (float)0.236938, 4354 (float)0.248108, (float)0.259460, (float)0.270966, 4355 (float)0.282654, (float)0.294464, (float)0.306396, 4356 (float)0.318481, (float)0.330688, (float)0.343018, 4357 (float)0.355438, (float)0.367981, (float)0.380585, 4358 (float)0.393280, (float)0.406067, (float)0.418884, 4359 (float)0.431763, (float)0.444702, (float)0.457672, 4360 (float)0.470673, (float)0.483704, (float)0.496735, 4361 (float)0.509766, (float)0.522797, (float)0.535828, 4362 (float)0.548798, (float)0.561768, (float)0.574677, 4363 (float)0.587524, (float)0.600342, (float)0.613068, 4364 (float)0.625732, (float)0.638306, (float)0.650787, 4365 (float)0.663147, (float)0.675415, (float)0.687561, 4366 (float)0.699585, (float)0.711487, (float)0.723206, 4367 (float)0.734802, (float)0.746216, (float)0.757477, 4368 (float)0.768585, (float)0.779480, (float)0.790192, 4369 (float)0.800720, (float)0.811005, (float)0.821106, 4370 (float)0.830994, (float)0.840668, (float)0.850067, 4371 (float)0.859253, (float)0.868225, (float)0.876892, 4372 (float)0.885345, (float)0.893524, (float)0.901428, 4373 (float)0.909058, (float)0.916412, (float)0.923492, 4374 (float)0.930267, (float)0.936768, (float)0.942963, 4375 (float)0.948853, (float)0.954437, (float)0.959717, 4376 (float)0.964691, (float)0.969360, (float)0.973694, 4377 (float)0.977692, (float)0.981384, (float)0.984741, 4378 (float)0.987762, (float)0.990479, (float)0.992828, 4379 (float)0.994873, (float)0.996552, (float)0.997925, 4380 (float)0.998932, (float)0.999603, (float)0.999969, 4381 (float)0.999969, (float)0.999603, (float)0.998932, 4382 (float)0.997925, (float)0.996552, (float)0.994873, 4383 (float)0.992828, (float)0.990479, (float)0.987762, 4384 (float)0.984741, (float)0.981384, (float)0.977692, 4385 (float)0.973694, (float)0.969360, (float)0.964691, 4386 (float)0.959717, (float)0.954437, (float)0.948853, 4387 (float)0.942963, (float)0.936768, (float)0.930267, 4388 (float)0.923492, (float)0.916412, (float)0.909058, 4389 (float)0.901428, (float)0.893524, (float)0.885345, 4390 (float)0.876892, (float)0.868225, (float)0.859253, 4391 (float)0.850067, (float)0.840668, (float)0.830994, 4392 (float)0.821106, (float)0.811005, (float)0.800720, 4393 (float)0.790192, (float)0.779480, (float)0.768585, 4394 (float)0.757477, (float)0.746216, (float)0.734802, 4395 (float)0.723206, (float)0.711487, (float)0.699585, 4396 (float)0.687561, (float)0.675415, (float)0.663147, 4397 (float)0.650787, (float)0.638306, (float)0.625732, 4399 Andersen et. al. Experimental - Expires November 29th, 2004 80 4400 Internet Low Bit Rate Codec May 04 4402 (float)0.613068, (float)0.600342, (float)0.587524, 4403 (float)0.574677, (float)0.561768, (float)0.548798, 4404 (float)0.535828, (float)0.522797, (float)0.509766, 4405 (float)0.496735, (float)0.483704, (float)0.470673, 4406 (float)0.457672, (float)0.444702, (float)0.431763, 4407 (float)0.418884, (float)0.406067, (float)0.393280, 4408 (float)0.380585, (float)0.367981, (float)0.355438, 4409 (float)0.343018, (float)0.330688, (float)0.318481, 4410 (float)0.306396, (float)0.294464, (float)0.282654, 4411 (float)0.270966, (float)0.259460, (float)0.248108, 4412 (float)0.236938, (float)0.225952, (float)0.215149, 4413 (float)0.204529, (float)0.194122, (float)0.183899, 4414 (float)0.173920, (float)0.164154, (float)0.154602, 4415 (float)0.145294, (float)0.136230, (float)0.127411, 4416 (float)0.118835, (float)0.110535, (float)0.102509, 4417 (float)0.094727, (float)0.087219, (float)0.080017, 4418 (float)0.073090, (float)0.066437, (float)0.060089, 4419 (float)0.054047, (float)0.048309, (float)0.042877, 4420 (float)0.037750, (float)0.032928, (float)0.028442, 4421 (float)0.024261, (float)0.020416, (float)0.016907, 4422 (float)0.013702, (float)0.010834, (float)0.008301, 4423 (float)0.006104, (float)0.004242, (float)0.002716, 4424 (float)0.001526, (float)0.000671, (float)0.000183 4425 }; 4427 /* Asymmetric LPC window */ 4428 float lpc_asymwinTbl[BLOCKL_MAX]={ 4429 (float)0.000061, (float)0.000214, (float)0.000458, 4430 (float)0.000824, (float)0.001282, (float)0.001831, 4431 (float)0.002472, (float)0.003235, (float)0.004120, 4432 (float)0.005066, (float)0.006134, (float)0.007294, 4433 (float)0.008545, (float)0.009918, (float)0.011383, 4434 (float)0.012939, (float)0.014587, (float)0.016357, 4435 (float)0.018219, (float)0.020172, (float)0.022217, 4436 (float)0.024353, (float)0.026611, (float)0.028961, 4437 (float)0.031372, (float)0.033905, (float)0.036530, 4438 (float)0.039276, (float)0.042084, (float)0.044983, 4439 (float)0.047974, (float)0.051086, (float)0.054260, 4440 (float)0.057526, (float)0.060883, (float)0.064331, 4441 (float)0.067871, (float)0.071503, (float)0.075226, 4442 (float)0.079010, (float)0.082916, (float)0.086884, 4443 (float)0.090942, (float)0.095062, (float)0.099304, 4444 (float)0.103607, (float)0.107971, (float)0.112427, 4445 (float)0.116974, (float)0.121582, (float)0.126282, 4446 (float)0.131073, (float)0.135895, (float)0.140839, 4447 (float)0.145813, (float)0.150879, (float)0.156006, 4448 (float)0.161224, (float)0.166504, (float)0.171844, 4449 (float)0.177246, (float)0.182709, (float)0.188263, 4450 (float)0.193848, (float)0.199524, (float)0.205231, 4451 (float)0.211029, (float)0.216858, (float)0.222778, 4452 (float)0.228729, (float)0.234741, (float)0.240814, 4453 (float)0.246918, (float)0.253082, (float)0.259308, 4454 (float)0.265564, (float)0.271881, (float)0.278259, 4455 (float)0.284668, (float)0.291107, (float)0.297607, 4457 Andersen et. al. Experimental - Expires November 29th, 2004 81 4458 Internet Low Bit Rate Codec May 04 4460 (float)0.304138, (float)0.310730, (float)0.317322, 4461 (float)0.323975, (float)0.330658, (float)0.337372, 4462 (float)0.344147, (float)0.350922, (float)0.357727, 4463 (float)0.364594, (float)0.371460, (float)0.378357, 4464 (float)0.385284, (float)0.392212, (float)0.399170, 4465 (float)0.406158, (float)0.413177, (float)0.420197, 4466 (float)0.427246, (float)0.434296, (float)0.441376, 4467 (float)0.448456, (float)0.455536, (float)0.462646, 4468 (float)0.469757, (float)0.476868, (float)0.483978, 4469 (float)0.491089, (float)0.498230, (float)0.505341, 4470 (float)0.512451, (float)0.519592, (float)0.526703, 4471 (float)0.533813, (float)0.540924, (float)0.548004, 4472 (float)0.555084, (float)0.562164, (float)0.569244, 4473 (float)0.576294, (float)0.583313, (float)0.590332, 4474 (float)0.597321, (float)0.604309, (float)0.611267, 4475 (float)0.618195, (float)0.625092, (float)0.631989, 4476 (float)0.638855, (float)0.645660, (float)0.652466, 4477 (float)0.659241, (float)0.665985, (float)0.672668, 4478 (float)0.679352, (float)0.685974, (float)0.692566, 4479 (float)0.699127, (float)0.705658, (float)0.712128, 4480 (float)0.718536, (float)0.724945, (float)0.731262, 4481 (float)0.737549, (float)0.743805, (float)0.750000, 4482 (float)0.756134, (float)0.762238, (float)0.768280, 4483 (float)0.774261, (float)0.780182, (float)0.786072, 4484 (float)0.791870, (float)0.797638, (float)0.803314, 4485 (float)0.808960, (float)0.814514, (float)0.820038, 4486 (float)0.825470, (float)0.830841, (float)0.836151, 4487 (float)0.841400, (float)0.846558, (float)0.851654, 4488 (float)0.856689, (float)0.861633, (float)0.866516, 4489 (float)0.871338, (float)0.876068, (float)0.880737, 4490 (float)0.885315, (float)0.889801, (float)0.894226, 4491 (float)0.898560, (float)0.902832, (float)0.907013, 4492 (float)0.911102, (float)0.915100, (float)0.919037, 4493 (float)0.922882, (float)0.926636, (float)0.930328, 4494 (float)0.933899, (float)0.937408, (float)0.940796, 4495 (float)0.944122, (float)0.947357, (float)0.950470, 4496 (float)0.953522, (float)0.956482, (float)0.959351, 4497 (float)0.962097, (float)0.964783, (float)0.967377, 4498 (float)0.969849, (float)0.972229, (float)0.974518, 4499 (float)0.976715, (float)0.978821, (float)0.980835, 4500 (float)0.982727, (float)0.984528, (float)0.986237, 4501 (float)0.987854, (float)0.989380, (float)0.990784, 4502 (float)0.992096, (float)0.993317, (float)0.994415, 4503 (float)0.995422, (float)0.996338, (float)0.997162, 4504 (float)0.997864, (float)0.998474, (float)0.998962, 4505 (float)0.999390, (float)0.999695, (float)0.999878, 4506 (float)0.999969, (float)0.999969, (float)0.996918, 4507 (float)0.987701, (float)0.972382, (float)0.951050, 4508 (float)0.923889, (float)0.891022, (float)0.852631, 4509 (float)0.809021, (float)0.760406, (float)0.707092, 4510 (float)0.649445, (float)0.587799, (float)0.522491, 4511 (float)0.453979, (float)0.382690, (float)0.309021, 4512 (float)0.233459, (float)0.156433, (float)0.078461 4513 }; 4515 Andersen et. al. Experimental - Expires November 29th, 2004 82 4516 Internet Low Bit Rate Codec May 04 4518 /* Lag window for LPC */ 4519 float lpc_lagwinTbl[LPC_FILTERORDER + 1]={ 4520 (float)1.000100, (float)0.998890, (float)0.995569, 4521 (float)0.990057, (float)0.982392, 4522 (float)0.972623, (float)0.960816, (float)0.947047, 4523 (float)0.931405, (float)0.913989, (float)0.894909}; 4525 /* LSF quantization*/ 4526 float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = { 4527 (float)0.155396, (float)0.273193, (float)0.451172, 4528 (float)0.390503, (float)0.648071, (float)1.002075, 4529 (float)0.440186, (float)0.692261, (float)0.955688, 4530 (float)0.343628, (float)0.642334, (float)1.071533, 4531 (float)0.318359, (float)0.491577, (float)0.670532, 4532 (float)0.193115, (float)0.375488, (float)0.725708, 4533 (float)0.364136, (float)0.510376, (float)0.658691, 4534 (float)0.297485, (float)0.527588, (float)0.842529, 4535 (float)0.227173, (float)0.365967, (float)0.563110, 4536 (float)0.244995, (float)0.396729, (float)0.636475, 4537 (float)0.169434, (float)0.300171, (float)0.520264, 4538 (float)0.312866, (float)0.464478, (float)0.643188, 4539 (float)0.248535, (float)0.429932, (float)0.626099, 4540 (float)0.236206, (float)0.491333, (float)0.817139, 4541 (float)0.334961, (float)0.625122, (float)0.895752, 4542 (float)0.343018, (float)0.518555, (float)0.698608, 4543 (float)0.372803, (float)0.659790, (float)0.945435, 4544 (float)0.176880, (float)0.316528, (float)0.581421, 4545 (float)0.416382, (float)0.625977, (float)0.805176, 4546 (float)0.303223, (float)0.568726, (float)0.915039, 4547 (float)0.203613, (float)0.351440, (float)0.588135, 4548 (float)0.221191, (float)0.375000, (float)0.614746, 4549 (float)0.199951, (float)0.323364, (float)0.476074, 4550 (float)0.300781, (float)0.433350, (float)0.566895, 4551 (float)0.226196, (float)0.354004, (float)0.507568, 4552 (float)0.300049, (float)0.508179, (float)0.711670, 4553 (float)0.312012, (float)0.492676, (float)0.763428, 4554 (float)0.329956, (float)0.541016, (float)0.795776, 4555 (float)0.373779, (float)0.604614, (float)0.928833, 4556 (float)0.210571, (float)0.452026, (float)0.755249, 4557 (float)0.271118, (float)0.473267, (float)0.662476, 4558 (float)0.285522, (float)0.436890, (float)0.634399, 4559 (float)0.246704, (float)0.565552, (float)0.859009, 4560 (float)0.270508, (float)0.406250, (float)0.553589, 4561 (float)0.361450, (float)0.578491, (float)0.813843, 4562 (float)0.342651, (float)0.482788, (float)0.622437, 4563 (float)0.340332, (float)0.549438, (float)0.743164, 4564 (float)0.200439, (float)0.336304, (float)0.540894, 4565 (float)0.407837, (float)0.644775, (float)0.895142, 4566 (float)0.294678, (float)0.454834, (float)0.699097, 4567 (float)0.193115, (float)0.344482, (float)0.643188, 4568 (float)0.275757, (float)0.420776, (float)0.598755, 4569 (float)0.380493, (float)0.608643, (float)0.861084, 4570 (float)0.222778, (float)0.426147, (float)0.676514, 4572 Andersen et. al. Experimental - Expires November 29th, 2004 83 4573 Internet Low Bit Rate Codec May 04 4575 (float)0.407471, (float)0.700195, (float)1.053101, 4576 (float)0.218384, (float)0.377197, (float)0.669922, 4577 (float)0.313232, (float)0.454102, (float)0.600952, 4578 (float)0.347412, (float)0.571533, (float)0.874146, 4579 (float)0.238037, (float)0.405396, (float)0.729492, 4580 (float)0.223877, (float)0.412964, (float)0.822021, 4581 (float)0.395264, (float)0.582153, (float)0.743896, 4582 (float)0.247925, (float)0.485596, (float)0.720581, 4583 (float)0.229126, (float)0.496582, (float)0.907715, 4584 (float)0.260132, (float)0.566895, (float)1.012695, 4585 (float)0.337402, (float)0.611572, (float)0.978149, 4586 (float)0.267822, (float)0.447632, (float)0.769287, 4587 (float)0.250610, (float)0.381714, (float)0.530029, 4588 (float)0.430054, (float)0.805054, (float)1.221924, 4589 (float)0.382568, (float)0.544067, (float)0.701660, 4590 (float)0.383545, (float)0.710327, (float)1.149170, 4591 (float)0.271362, (float)0.529053, (float)0.775513, 4592 (float)0.246826, (float)0.393555, (float)0.588623, 4593 (float)0.266846, (float)0.422119, (float)0.676758, 4594 (float)0.311523, (float)0.580688, (float)0.838623, 4595 (float)1.331177, (float)1.576782, (float)1.779541, 4596 (float)1.160034, (float)1.401978, (float)1.768188, 4597 (float)1.161865, (float)1.525146, (float)1.715332, 4598 (float)0.759521, (float)0.913940, (float)1.119873, 4599 (float)0.947144, (float)1.121338, (float)1.282471, 4600 (float)1.015015, (float)1.557007, (float)1.804932, 4601 (float)1.172974, (float)1.402100, (float)1.692627, 4602 (float)1.087524, (float)1.474243, (float)1.665405, 4603 (float)0.899536, (float)1.105225, (float)1.406250, 4604 (float)1.148438, (float)1.484741, (float)1.796265, 4605 (float)0.785645, (float)1.209839, (float)1.567749, 4606 (float)0.867798, (float)1.166504, (float)1.450684, 4607 (float)0.922485, (float)1.229858, (float)1.420898, 4608 (float)0.791260, (float)1.123291, (float)1.409546, 4609 (float)0.788940, (float)0.966064, (float)1.340332, 4610 (float)1.051147, (float)1.272827, (float)1.556641, 4611 (float)0.866821, (float)1.181152, (float)1.538818, 4612 (float)0.906738, (float)1.373535, (float)1.607910, 4613 (float)1.244751, (float)1.581421, (float)1.933838, 4614 (float)0.913940, (float)1.337280, (float)1.539673, 4615 (float)0.680542, (float)0.959229, (float)1.662720, 4616 (float)0.887207, (float)1.430542, (float)1.800781, 4617 (float)0.912598, (float)1.433594, (float)1.683960, 4618 (float)0.860474, (float)1.060303, (float)1.455322, 4619 (float)1.005127, (float)1.381104, (float)1.706909, 4620 (float)0.800781, (float)1.363892, (float)1.829102, 4621 (float)0.781860, (float)1.124390, (float)1.505981, 4622 (float)1.003662, (float)1.471436, (float)1.684692, 4623 (float)0.981323, (float)1.309570, (float)1.618042, 4624 (float)1.228760, (float)1.554321, (float)1.756470, 4625 (float)0.734375, (float)0.895752, (float)1.225586, 4626 (float)0.841797, (float)1.055664, (float)1.249268, 4627 (float)0.920166, (float)1.119385, (float)1.486206, 4628 (float)0.894409, (float)1.539063, (float)1.828979, 4630 Andersen et. al. Experimental - Expires November 29th, 2004 84 4631 Internet Low Bit Rate Codec May 04 4633 (float)1.283691, (float)1.543335, (float)1.858276, 4634 (float)0.676025, (float)0.933105, (float)1.490845, 4635 (float)0.821289, (float)1.491821, (float)1.739868, 4636 (float)0.923218, (float)1.144653, (float)1.580566, 4637 (float)1.057251, (float)1.345581, (float)1.635864, 4638 (float)0.888672, (float)1.074951, (float)1.353149, 4639 (float)0.942749, (float)1.195435, (float)1.505493, 4640 (float)1.492310, (float)1.788086, (float)2.039673, 4641 (float)1.070313, (float)1.634399, (float)1.860962, 4642 (float)1.253296, (float)1.488892, (float)1.686035, 4643 (float)0.647095, (float)0.864014, (float)1.401855, 4644 (float)0.866699, (float)1.254883, (float)1.453369, 4645 (float)1.063965, (float)1.532593, (float)1.731323, 4646 (float)1.167847, (float)1.521484, (float)1.884033, 4647 (float)0.956055, (float)1.502075, (float)1.745605, 4648 (float)0.928711, (float)1.288574, (float)1.479614, 4649 (float)1.088013, (float)1.380737, (float)1.570801, 4650 (float)0.905029, (float)1.186768, (float)1.371948, 4651 (float)1.057861, (float)1.421021, (float)1.617432, 4652 (float)1.108276, (float)1.312500, (float)1.501465, 4653 (float)0.979492, (float)1.416992, (float)1.624268, 4654 (float)1.276001, (float)1.661011, (float)2.007935, 4655 (float)0.993042, (float)1.168579, (float)1.331665, 4656 (float)0.778198, (float)0.944946, (float)1.235962, 4657 (float)1.223755, (float)1.491333, (float)1.815674, 4658 (float)0.852661, (float)1.350464, (float)1.722290, 4659 (float)1.134766, (float)1.593140, (float)1.787354, 4660 (float)1.051392, (float)1.339722, (float)1.531006, 4661 (float)0.803589, (float)1.271240, (float)1.652100, 4662 (float)0.755737, (float)1.143555, (float)1.639404, 4663 (float)0.700928, (float)0.837280, (float)1.130371, 4664 (float)0.942749, (float)1.197876, (float)1.669800, 4665 (float)0.993286, (float)1.378296, (float)1.566528, 4666 (float)0.801025, (float)1.095337, (float)1.298950, 4667 (float)0.739990, (float)1.032959, (float)1.383667, 4668 (float)0.845703, (float)1.072266, (float)1.543823, 4669 (float)0.915649, (float)1.072266, (float)1.224487, 4670 (float)1.021973, (float)1.226196, (float)1.481323, 4671 (float)0.999878, (float)1.204102, (float)1.555908, 4672 (float)0.722290, (float)0.913940, (float)1.340210, 4673 (float)0.673340, (float)0.835938, (float)1.259521, 4674 (float)0.832397, (float)1.208374, (float)1.394165, 4675 (float)0.962158, (float)1.576172, (float)1.912842, 4676 (float)1.166748, (float)1.370850, (float)1.556763, 4677 (float)0.946289, (float)1.138550, (float)1.400391, 4678 (float)1.035034, (float)1.218262, (float)1.386475, 4679 (float)1.393799, (float)1.717773, (float)2.000244, 4680 (float)0.972656, (float)1.260986, (float)1.760620, 4681 (float)1.028198, (float)1.288452, (float)1.484619, 4682 (float)0.773560, (float)1.258057, (float)1.756714, 4683 (float)1.080322, (float)1.328003, (float)1.742676, 4684 (float)0.823975, (float)1.450806, (float)1.917725, 4685 (float)0.859009, (float)1.016602, (float)1.191895, 4686 (float)0.843994, (float)1.131104, (float)1.645020, 4688 Andersen et. al. Experimental - Expires November 29th, 2004 85 4689 Internet Low Bit Rate Codec May 04 4691 (float)1.189697, (float)1.702759, (float)1.894409, 4692 (float)1.346680, (float)1.763184, (float)2.066040, 4693 (float)0.980469, (float)1.253784, (float)1.441650, 4694 (float)1.338135, (float)1.641968, (float)1.932739, 4695 (float)1.223267, (float)1.424194, (float)1.626465, 4696 (float)0.765747, (float)1.004150, (float)1.579102, 4697 (float)1.042847, (float)1.269165, (float)1.647461, 4698 (float)0.968750, (float)1.257568, (float)1.555786, 4699 (float)0.826294, (float)0.993408, (float)1.275146, 4700 (float)0.742310, (float)0.950439, (float)1.430542, 4701 (float)1.054321, (float)1.439819, (float)1.828003, 4702 (float)1.072998, (float)1.261719, (float)1.441895, 4703 (float)0.859375, (float)1.036377, (float)1.314819, 4704 (float)0.895752, (float)1.267212, (float)1.605591, 4705 (float)0.805420, (float)0.962891, (float)1.142334, 4706 (float)0.795654, (float)1.005493, (float)1.468506, 4707 (float)1.105347, (float)1.313843, (float)1.584839, 4708 (float)0.792236, (float)1.221802, (float)1.465698, 4709 (float)1.170532, (float)1.467651, (float)1.664063, 4710 (float)0.838257, (float)1.153198, (float)1.342163, 4711 (float)0.968018, (float)1.198242, (float)1.391235, 4712 (float)1.250122, (float)1.623535, (float)1.823608, 4713 (float)0.711670, (float)1.058350, (float)1.512085, 4714 (float)1.204834, (float)1.454468, (float)1.739136, 4715 (float)1.137451, (float)1.421753, (float)1.620117, 4716 (float)0.820435, (float)1.322754, (float)1.578247, 4717 (float)0.798706, (float)1.005005, (float)1.213867, 4718 (float)0.980713, (float)1.324951, (float)1.512939, 4719 (float)1.112305, (float)1.438843, (float)1.735596, 4720 (float)1.135498, (float)1.356689, (float)1.635742, 4721 (float)1.101318, (float)1.387451, (float)1.686523, 4722 (float)0.849854, (float)1.276978, (float)1.523438, 4723 (float)1.377930, (float)1.627563, (float)1.858154, 4724 (float)0.884888, (float)1.095459, (float)1.287476, 4725 (float)1.289795, (float)1.505859, (float)1.756592, 4726 (float)0.817505, (float)1.384155, (float)1.650513, 4727 (float)1.446655, (float)1.702148, (float)1.931885, 4728 (float)0.835815, (float)1.023071, (float)1.385376, 4729 (float)0.916626, (float)1.139038, (float)1.335327, 4730 (float)0.980103, (float)1.174072, (float)1.453735, 4731 (float)1.705688, (float)2.153809, (float)2.398315, (float)2.743408, 4732 (float)1.797119, (float)2.016846, (float)2.445679, (float)2.701904, 4733 (float)1.990356, (float)2.219116, (float)2.576416, (float)2.813477, 4734 (float)1.849365, (float)2.190918, (float)2.611572, (float)2.835083, 4735 (float)1.657959, (float)1.854370, (float)2.159058, (float)2.726196, 4736 (float)1.437744, (float)1.897705, (float)2.253174, (float)2.655396, 4737 (float)2.028687, (float)2.247314, (float)2.542358, (float)2.875854, 4738 (float)1.736938, (float)1.922119, (float)2.185913, (float)2.743408, 4739 (float)1.521606, (float)1.870972, (float)2.526855, (float)2.786987, 4740 (float)1.841431, (float)2.050659, (float)2.463623, (float)2.857666, 4741 (float)1.590088, (float)2.067261, (float)2.427979, (float)2.794434, 4742 (float)1.746826, (float)2.057373, (float)2.320190, (float)2.800781, 4743 (float)1.734619, (float)1.940552, (float)2.306030, (float)2.826416, 4744 (float)1.786255, (float)2.204468, (float)2.457520, (float)2.795288, 4746 Andersen et. al. Experimental - Expires November 29th, 2004 86 4747 Internet Low Bit Rate Codec May 04 4749 (float)1.861084, (float)2.170532, (float)2.414551, (float)2.763672, 4750 (float)2.001465, (float)2.307617, (float)2.552734, (float)2.811890, 4751 (float)1.784424, (float)2.124146, (float)2.381592, (float)2.645508, 4752 (float)1.888794, (float)2.135864, (float)2.418579, (float)2.861206, 4753 (float)2.301147, (float)2.531250, (float)2.724976, (float)2.913086, 4754 (float)1.837769, (float)2.051270, (float)2.261963, (float)2.553223, 4755 (float)2.012939, (float)2.221191, (float)2.440186, (float)2.678101, 4756 (float)1.429565, (float)1.858276, (float)2.582275, (float)2.845703, 4757 (float)1.622803, (float)1.897705, (float)2.367310, (float)2.621094, 4758 (float)1.581543, (float)1.960449, (float)2.515869, (float)2.736450, 4759 (float)1.419434, (float)1.933960, (float)2.394653, (float)2.746704, 4760 (float)1.721924, (float)2.059570, (float)2.421753, (float)2.769653, 4761 (float)1.911011, (float)2.220703, (float)2.461060, (float)2.740723, 4762 (float)1.581177, (float)1.860840, (float)2.516968, (float)2.874634, 4763 (float)1.870361, (float)2.098755, (float)2.432373, (float)2.656494, 4764 (float)2.059692, (float)2.279785, (float)2.495605, (float)2.729370, 4765 (float)1.815674, (float)2.181519, (float)2.451538, (float)2.680542, 4766 (float)1.407959, (float)1.768311, (float)2.343018, (float)2.668091, 4767 (float)2.168701, (float)2.394653, (float)2.604736, (float)2.829346, 4768 (float)1.636230, (float)1.865723, (float)2.329102, (float)2.824219, 4769 (float)1.878906, (float)2.139526, (float)2.376709, (float)2.679810, 4770 (float)1.765381, (float)1.971802, (float)2.195435, (float)2.586914, 4771 (float)2.164795, (float)2.410889, (float)2.673706, (float)2.903198, 4772 (float)2.071899, (float)2.331055, (float)2.645874, (float)2.907104, 4773 (float)2.026001, (float)2.311523, (float)2.594849, (float)2.863892, 4774 (float)1.948975, (float)2.180786, (float)2.514893, (float)2.797852, 4775 (float)1.881836, (float)2.130859, (float)2.478149, (float)2.804199, 4776 (float)2.238159, (float)2.452759, (float)2.652832, (float)2.868286, 4777 (float)1.897949, (float)2.101685, (float)2.524292, (float)2.880127, 4778 (float)1.856445, (float)2.074585, (float)2.541016, (float)2.791748, 4779 (float)1.695557, (float)2.199097, (float)2.506226, (float)2.742676, 4780 (float)1.612671, (float)1.877075, (float)2.435425, (float)2.732910, 4781 (float)1.568848, (float)1.786499, (float)2.194580, (float)2.768555, 4782 (float)1.953369, (float)2.164551, (float)2.486938, (float)2.874023, 4783 (float)1.388306, (float)1.725342, (float)2.384521, (float)2.771851, 4784 (float)2.115356, (float)2.337769, (float)2.592896, (float)2.864014, 4785 (float)1.905762, (float)2.111328, (float)2.363525, (float)2.789307, 4786 (float)1.882568, (float)2.332031, (float)2.598267, (float)2.827637, 4787 (float)1.683594, (float)2.088745, (float)2.361938, (float)2.608643, 4788 (float)1.874023, (float)2.182129, (float)2.536133, (float)2.766968, 4789 (float)1.861938, (float)2.070435, (float)2.309692, (float)2.700562, 4790 (float)1.722168, (float)2.107422, (float)2.477295, (float)2.837646, 4791 (float)1.926880, (float)2.184692, (float)2.442627, (float)2.663818, 4792 (float)2.123901, (float)2.337280, (float)2.553101, (float)2.777466, 4793 (float)1.588135, (float)1.911499, (float)2.212769, (float)2.543945, 4794 (float)2.053955, (float)2.370850, (float)2.712158, (float)2.939941, 4795 (float)2.210449, (float)2.519653, (float)2.770386, (float)2.958618, 4796 (float)2.199463, (float)2.474731, (float)2.718262, (float)2.919922, 4797 (float)1.960083, (float)2.175415, (float)2.608032, (float)2.888794, 4798 (float)1.953735, (float)2.185181, (float)2.428223, (float)2.809570, 4799 (float)1.615234, (float)2.036499, (float)2.576538, (float)2.834595, 4800 (float)1.621094, (float)2.028198, (float)2.431030, (float)2.664673, 4801 (float)1.824951, (float)2.267456, (float)2.514526, (float)2.747925, 4802 (float)1.994263, (float)2.229126, (float)2.475220, (float)2.833984, 4804 Andersen et. al. Experimental - Expires November 29th, 2004 87 4805 Internet Low Bit Rate Codec May 04 4807 (float)1.746338, (float)2.011353, (float)2.588257, (float)2.826904, 4808 (float)1.562866, (float)2.135986, (float)2.471680, (float)2.687256, 4809 (float)1.748901, (float)2.083496, (float)2.460938, (float)2.686279, 4810 (float)1.758057, (float)2.131470, (float)2.636597, (float)2.891602, 4811 (float)2.071289, (float)2.299072, (float)2.550781, (float)2.814331, 4812 (float)1.839600, (float)2.094360, (float)2.496460, (float)2.723999, 4813 (float)1.882202, (float)2.088257, (float)2.636841, (float)2.923096, 4814 (float)1.957886, (float)2.153198, (float)2.384399, (float)2.615234, 4815 (float)1.992920, (float)2.351196, (float)2.654419, (float)2.889771, 4816 (float)2.012817, (float)2.262451, (float)2.643799, (float)2.903076, 4817 (float)2.025635, (float)2.254761, (float)2.508423, (float)2.784058, 4818 (float)2.316040, (float)2.589355, (float)2.794189, (float)2.963623, 4819 (float)1.741211, (float)2.279541, (float)2.578491, (float)2.816284, 4820 (float)1.845337, (float)2.055786, (float)2.348511, (float)2.822021, 4821 (float)1.679932, (float)1.926514, (float)2.499756, (float)2.835693, 4822 (float)1.722534, (float)1.946899, (float)2.448486, (float)2.728760, 4823 (float)1.829834, (float)2.043213, (float)2.580444, (float)2.867676, 4824 (float)1.676636, (float)2.071655, (float)2.322510, (float)2.704834, 4825 (float)1.791504, (float)2.113525, (float)2.469727, (float)2.784058, 4826 (float)1.977051, (float)2.215088, (float)2.497437, (float)2.726929, 4827 (float)1.800171, (float)2.106689, (float)2.357788, (float)2.738892, 4828 (float)1.827759, (float)2.170166, (float)2.525879, (float)2.852417, 4829 (float)1.918335, (float)2.132813, (float)2.488403, (float)2.728149, 4830 (float)1.916748, (float)2.225098, (float)2.542603, (float)2.857666, 4831 (float)1.761230, (float)1.976074, (float)2.507446, (float)2.884521, 4832 (float)2.053711, (float)2.367432, (float)2.608032, (float)2.837646, 4833 (float)1.595337, (float)2.000977, (float)2.307129, (float)2.578247, 4834 (float)1.470581, (float)2.031250, (float)2.375854, (float)2.647583, 4835 (float)1.801392, (float)2.128052, (float)2.399780, (float)2.822876, 4836 (float)1.853638, (float)2.066650, (float)2.429199, (float)2.751465, 4837 (float)1.956299, (float)2.163696, (float)2.394775, (float)2.734253, 4838 (float)1.963623, (float)2.275757, (float)2.585327, (float)2.865234, 4839 (float)1.887451, (float)2.105469, (float)2.331787, (float)2.587402, 4840 (float)2.120117, (float)2.443359, (float)2.733887, (float)2.941406, 4841 (float)1.506348, (float)1.766968, (float)2.400513, (float)2.851807, 4842 (float)1.664551, (float)1.981079, (float)2.375732, (float)2.774414, 4843 (float)1.720703, (float)1.978882, (float)2.391479, (float)2.640991, 4844 (float)1.483398, (float)1.814819, (float)2.434448, (float)2.722290, 4845 (float)1.769043, (float)2.136597, (float)2.563721, (float)2.774414, 4846 (float)1.810791, (float)2.049316, (float)2.373901, (float)2.613647, 4847 (float)1.788330, (float)2.005981, (float)2.359131, (float)2.723145, 4848 (float)1.785156, (float)1.993164, (float)2.399780, (float)2.832520, 4849 (float)1.695313, (float)2.022949, (float)2.522583, (float)2.745117, 4850 (float)1.584106, (float)1.965576, (float)2.299927, (float)2.715576, 4851 (float)1.894897, (float)2.249878, (float)2.655884, (float)2.897705, 4852 (float)1.720581, (float)1.995728, (float)2.299438, (float)2.557007, 4853 (float)1.619385, (float)2.173950, (float)2.574219, (float)2.787964, 4854 (float)1.883179, (float)2.220459, (float)2.474365, (float)2.825073, 4855 (float)1.447632, (float)2.045044, (float)2.555542, (float)2.744873, 4856 (float)1.502686, (float)2.156616, (float)2.653320, (float)2.846558, 4857 (float)1.711548, (float)1.944092, (float)2.282959, (float)2.685791, 4858 (float)1.499756, (float)1.867554, (float)2.341064, (float)2.578857, 4859 (float)1.916870, (float)2.135132, (float)2.568237, (float)2.826050, 4860 (float)1.498047, (float)1.711182, (float)2.223267, (float)2.755127, 4862 Andersen et. al. Experimental - Expires November 29th, 2004 88 4863 Internet Low Bit Rate Codec May 04 4865 (float)1.808716, (float)1.997559, (float)2.256470, (float)2.758545, 4866 (float)2.088501, (float)2.402710, (float)2.667358, (float)2.890259, 4867 (float)1.545044, (float)1.819214, (float)2.324097, (float)2.692993, 4868 (float)1.796021, (float)2.012573, (float)2.505737, (float)2.784912, 4869 (float)1.786499, (float)2.041748, (float)2.290405, (float)2.650757, 4870 (float)1.938232, (float)2.264404, (float)2.529053, (float)2.796143 4871 }; 4873 A.9 anaFilter.h 4875 /****************************************************************** 4877 iLBC Speech Coder ANSI-C Source Code 4879 anaFilter.h 4881 Copyright (C) The Internet Society (2004). 4882 All Rights Reserved. 4884 ******************************************************************/ 4886 #ifndef __iLBC_ANAFILTER_H 4887 #define __iLBC_ANAFILTER_H 4889 void anaFilter( 4890 float *In, /* (i) Signal to be filtered */ 4891 float *a, /* (i) LP parameters */ 4892 int len,/* (i) Length of signal */ 4893 float *Out, /* (o) Filtered signal */ 4894 float *mem /* (i/o) Filter state */ 4895 ); 4897 #endif 4899 A.10 anaFilter.c 4901 /****************************************************************** 4903 iLBC Speech Coder ANSI-C Source Code 4905 anaFilter.c 4907 Copyright (C) The Internet Society (2004). 4908 All Rights Reserved. 4910 ******************************************************************/ 4912 #include 4913 #include "iLBC_define.h" 4915 /*----------------------------------------------------------------* 4916 * LP analysis filter. 4918 Andersen et. al. Experimental - Expires November 29th, 2004 89 4919 Internet Low Bit Rate Codec May 04 4921 *---------------------------------------------------------------*/ 4923 void anaFilter( 4924 float *In, /* (i) Signal to be filtered */ 4925 float *a, /* (i) LP parameters */ 4926 int len,/* (i) Length of signal */ 4927 float *Out, /* (o) Filtered signal */ 4928 float *mem /* (i/o) Filter state */ 4929 ){ 4930 int i, j; 4931 float *po, *pi, *pm, *pa; 4933 po = Out; 4935 /* Filter first part using memory from past */ 4937 for (i=0; i 5047 #include 5049 /*----------------------------------------------------------------* 5050 * Construct an additional codebook vector by filtering the 5051 * initial codebook buffer. This vector is then used to expand 5052 * the codebook with an additional section. 5053 *---------------------------------------------------------------*/ 5055 void filteredCBvecs( 5056 float *cbvectors, /* (o) Codebook vectors for the 5057 higher section */ 5058 float *mem, /* (i) Buffer to create codebook 5059 vector from */ 5060 int lMem /* (i) Length of buffer */ 5061 ){ 5062 int j, k; 5063 float *pp, *pp1; 5064 float tempbuff2[CB_MEML+CB_FILTERLEN]; 5065 float *pos; 5067 memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float)); 5068 memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float)); 5069 memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0, 5070 (CB_HALFFILTERLEN+1)*sizeof(float)); 5072 /* Create codebook vector for higher section by filtering */ 5074 /* do filtering */ 5075 pos=cbvectors; 5076 memset(pos, 0, lMem*sizeof(float)); 5077 for (k=0; k0.0) { 5174 invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS); 5175 } else { 5176 invenergy[tmpIndex] = (float) 0.0; 5177 } 5179 if (stage==0) { 5180 measure = (float)-10000000.0; 5182 if (crossDot > 0.0) { 5183 measure = crossDot*crossDot*invenergy[tmpIndex]; 5184 } 5185 } 5186 else { 5187 measure = crossDot*crossDot*invenergy[tmpIndex]; 5188 } 5190 /* check if measure is better */ 5191 ftmp = crossDot*invenergy[tmpIndex]; 5193 if ((measure>*max_measure) && (fabs(ftmp) 5293 #include 5294 #include 5296 #include "iLBC_define.h" 5298 /*----------------------------------------------------------------* 5299 * Compute cross correlation and pitch gain for pitch prediction 5300 * of last subframe at given lag. 5301 *---------------------------------------------------------------*/ 5303 void compCorr( 5304 float *cc, /* (o) cross correlation coefficient */ 5305 float *gc, /* (o) gain */ 5306 float *pm, 5307 float *buffer, /* (i) signal buffer */ 5308 int lag, /* (i) pitch lag */ 5309 int bLen, /* (i) length of buffer */ 5310 int sRange /* (i) correlation search length */ 5311 ){ 5313 Andersen et. al. Experimental - Expires November 29th, 2004 96 5314 Internet Low Bit Rate Codec May 04 5316 int i; 5317 float ftmp1, ftmp2, ftmp3; 5319 /* Guard against getting outside buffer */ 5320 if ((bLen-sRange-lag)<0) { 5321 sRange=bLen-lag; 5322 } 5324 ftmp1 = 0.0; 5325 ftmp2 = 0.0; 5326 ftmp3 = 0.0; 5327 for (i=0; i 0.0) { 5337 *cc = ftmp1*ftmp1/ftmp2; 5338 *gc = (float)fabs(ftmp1/ftmp2); 5339 *pm=(float)fabs(ftmp1)/ 5340 ((float)sqrt(ftmp2)*(float)sqrt(ftmp3)); 5341 } 5342 else { 5343 *cc = 0.0; 5344 *gc = 0.0; 5345 *pm=0.0; 5346 } 5347 } 5349 /*----------------------------------------------------------------* 5350 * Packet loss concealment routine. Conceals a residual signal 5351 * and LP parameters. If no packet loss, update state. 5352 *---------------------------------------------------------------*/ 5354 void doThePLC( 5355 float *PLCresidual, /* (o) concealed residual */ 5356 float *PLClpc, /* (o) concealed LP parameters */ 5357 int PLI, /* (i) packet loss indicator 5358 0 - no PL, 1 = PL */ 5359 float *decresidual, /* (i) decoded residual */ 5360 float *lpc, /* (i) decoded LPC (only used for no PL) */ 5361 int inlag, /* (i) pitch lag */ 5362 iLBC_Dec_Inst_t *iLBCdec_inst 5363 /* (i/o) decoder instance */ 5364 ){ 5365 int lag=20, randlag; 5366 float gain, maxcc; 5367 float use_gain; 5368 float gain_comp, maxcc_comp, per, max_per; 5369 int i, pick, use_lag; 5371 Andersen et. al. Experimental - Expires November 29th, 2004 97 5372 Internet Low Bit Rate Codec May 04 5374 float ftmp, randvec[BLOCKL_MAX], pitchfact, energy; 5376 /* Packet Loss */ 5378 if (PLI == 1) { 5380 iLBCdec_inst->consPLICount += 1; 5382 /* if previous frame not lost, 5383 determine pitch pred. gain */ 5385 if (iLBCdec_inst->prevPLI != 1) { 5387 /* Search around the previous lag to find the 5388 best pitch period */ 5390 lag=inlag-3; 5391 compCorr(&maxcc, &gain, &max_per, 5392 iLBCdec_inst->prevResidual, 5393 lag, iLBCdec_inst->blockl, 60); 5394 for (i=inlag-2;i<=inlag+3;i++) { 5395 compCorr(&maxcc_comp, &gain_comp, &per, 5396 iLBCdec_inst->prevResidual, 5397 i, iLBCdec_inst->blockl, 60); 5399 if (maxcc_comp>maxcc) { 5400 maxcc=maxcc_comp; 5401 gain=gain_comp; 5402 lag=i; 5403 max_per=per; 5404 } 5405 } 5407 } 5409 /* previous frame lost, use recorded lag and periodicity */ 5411 else { 5412 lag=iLBCdec_inst->prevLag; 5413 max_per=iLBCdec_inst->per; 5414 } 5416 /* downscaling */ 5418 use_gain=1.0; 5419 if (iLBCdec_inst->consPLICount*iLBCdec_inst->blockl>320) 5420 use_gain=(float)0.9; 5421 else if (iLBCdec_inst->consPLICount* 5422 iLBCdec_inst->blockl>2*320) 5423 use_gain=(float)0.7; 5424 else if (iLBCdec_inst->consPLICount* 5425 iLBCdec_inst->blockl>3*320) 5426 use_gain=(float)0.5; 5427 else if (iLBCdec_inst->consPLICount* 5429 Andersen et. al. Experimental - Expires November 29th, 2004 98 5430 Internet Low Bit Rate Codec May 04 5432 iLBCdec_inst->blockl>4*320) 5433 use_gain=(float)0.0; 5435 /* mix noise and pitch repeatition */ 5436 ftmp=(float)sqrt(max_per); 5437 if (ftmp>(float)0.7) 5438 pitchfact=(float)1.0; 5439 else if (ftmp>(float)0.4) 5440 pitchfact=(ftmp-(float)0.4)/((float)0.7-(float)0.4); 5441 else 5442 pitchfact=0.0; 5444 /* avoid repetition of same pitch cycle */ 5445 use_lag=lag; 5446 if (lag<80) { 5447 use_lag=2*lag; 5448 } 5450 /* compute concealed residual */ 5452 energy = 0.0; 5453 for (i=0; iblockl; i++) { 5455 /* noise component */ 5457 iLBCdec_inst->seed=(iLBCdec_inst->seed*69069L+1) & 5458 (0x80000000L-1); 5459 randlag = 50 + ((signed long) iLBCdec_inst->seed)%70; 5460 pick = i - randlag; 5462 if (pick < 0) { 5463 randvec[i] = 5464 iLBCdec_inst->prevResidual[ 5465 iLBCdec_inst->blockl+pick]; 5466 } else { 5467 randvec[i] = randvec[pick]; 5468 } 5470 /* pitch repeatition component */ 5471 pick = i - use_lag; 5473 if (pick < 0) { 5474 PLCresidual[i] = 5475 iLBCdec_inst->prevResidual[ 5476 iLBCdec_inst->blockl+pick]; 5477 } else { 5478 PLCresidual[i] = PLCresidual[pick]; 5479 } 5481 /* mix random and periodicity component */ 5483 if (i<80) 5484 PLCresidual[i] = use_gain*(pitchfact * 5486 Andersen et. al. Experimental - Expires November 29th, 2004 99 5487 Internet Low Bit Rate Codec May 04 5489 PLCresidual[i] + 5490 ((float)1.0 - pitchfact) * randvec[i]); 5491 else if (i<160) 5492 PLCresidual[i] = (float)0.95*use_gain*(pitchfact * 5493 PLCresidual[i] + 5494 ((float)1.0 - pitchfact) * randvec[i]); 5495 else 5496 PLCresidual[i] = (float)0.9*use_gain*(pitchfact * 5497 PLCresidual[i] + 5498 ((float)1.0 - pitchfact) * randvec[i]); 5500 energy += PLCresidual[i] * PLCresidual[i]; 5501 } 5503 /* less than 30 dB, use only noise */ 5505 if (sqrt(energy/(float)iLBCdec_inst->blockl) < 30.0) { 5506 gain=0.0; 5507 for (i=0; iblockl; i++) { 5508 PLCresidual[i] = randvec[i]; 5509 } 5510 } 5512 /* use old LPC */ 5514 memcpy(PLClpc,iLBCdec_inst->prevLpc, 5515 (LPC_FILTERORDER+1)*sizeof(float)); 5517 } 5519 /* no packet loss, copy input */ 5521 else { 5522 memcpy(PLCresidual, decresidual, 5523 iLBCdec_inst->blockl*sizeof(float)); 5524 memcpy(PLClpc, lpc, (LPC_FILTERORDER+1)*sizeof(float)); 5525 iLBCdec_inst->consPLICount = 0; 5526 } 5528 /* update state */ 5530 if (PLI) { 5531 iLBCdec_inst->prevLag = lag; 5532 iLBCdec_inst->per=max_per; 5533 } 5535 iLBCdec_inst->prevPLI = PLI; 5536 memcpy(iLBCdec_inst->prevLpc, PLClpc, 5537 (LPC_FILTERORDER+1)*sizeof(float)); 5538 memcpy(iLBCdec_inst->prevResidual, PLCresidual, 5539 iLBCdec_inst->blockl*sizeof(float)); 5540 } 5542 Andersen et. al. Experimental - Expires November 29th, 2004 100 5543 Internet Low Bit Rate Codec May 04 5545 A.15 enhancer.h 5547 /****************************************************************** 5549 iLBC Speech Coder ANSI-C Source Code 5551 enhancer.h 5553 Copyright (C) The Internet Society (2004). 5554 All Rights Reserved. 5556 ******************************************************************/ 5558 #ifndef __ENHANCER_H 5559 #define __ENHANCER_H 5561 #include "iLBC_define.h" 5563 float xCorrCoef( 5564 float *target, /* (i) first array */ 5565 float *regressor, /* (i) second array */ 5566 int subl /* (i) dimension arrays */ 5567 ); 5569 int enhancerInterface( 5570 float *out, /* (o) the enhanced recidual signal */ 5571 float *in, /* (i) the recidual signal to enhance */ 5572 iLBC_Dec_Inst_t *iLBCdec_inst 5573 /* (i/o) the decoder state structure */ 5574 ); 5576 #endif 5578 A.16 enhancer.c 5580 /****************************************************************** 5582 iLBC Speech Coder ANSI-C Source Code 5584 enhancer.c 5586 Copyright (C) The Internet Society (2004). 5587 All Rights Reserved. 5589 ******************************************************************/ 5591 #include 5592 #include 5593 #include "iLBC_define.h" 5594 #include "constants.h" 5595 #include "filter.h" 5597 /*----------------------------------------------------------------* 5599 Andersen et. al. Experimental - Expires November 29th, 2004 101 5600 Internet Low Bit Rate Codec May 04 5602 * Find index in array such that the array element with said 5603 * index is the element of said array closest to "value" 5604 * according to the squared-error criterion 5605 *---------------------------------------------------------------*/ 5607 void NearestNeighbor( 5608 int *index, /* (o) index of array element closest 5609 to value */ 5610 float *array, /* (i) data array */ 5611 float value,/* (i) value */ 5612 int arlength/* (i) dimension of data array */ 5613 ){ 5614 int i; 5615 float bestcrit,crit; 5617 crit=array[0]-value; 5618 bestcrit=crit*crit; 5619 *index=0; 5620 for (i=1; i dim1 ) { 5676 hfl2=(int) (dim1/2); 5677 for (j=0; j= idatal) { 5774 searchSegEndPos=idatal-ENH_BLOCKL-1; 5775 } 5776 corrdim=searchSegEndPos-searchSegStartPos+1; 5778 /* compute upsampled correlation (corr33) and find 5779 location of max */ 5781 mycorr1(corrVec,idata+searchSegStartPos, 5782 corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL); 5783 enh_upsample(corrVecUps,corrVec,corrdim,ENH_FL0); 5784 tloc=0; maxv=corrVecUps[0]; 5785 for (i=1; imaxv) { 5788 tloc=i; 5789 maxv=corrVecUps[i]; 5790 } 5791 } 5793 /* make vector can be upsampled without ever running outside 5794 bounds */ 5796 *updStartPos= (float)searchSegStartPos + 5797 (float)tloc/(float)ENH_UPS0+(float)1.0; 5798 tloc2=(int)(tloc/ENH_UPS0); 5800 if (tloc>tloc2*ENH_UPS0) { 5801 tloc2++; 5802 } 5803 st=searchSegStartPos+tloc2-ENH_FL0; 5805 if (st<0) { 5806 memset(vect,0,-st*sizeof(float)); 5807 memcpy(&vect[-st],idata, (ENH_VECTL+st)*sizeof(float)); 5808 } 5809 else { 5810 en=st+ENH_VECTL; 5812 if (en>idatal) { 5813 memcpy(vect, &idata[st], 5814 (ENH_VECTL-(en-idatal))*sizeof(float)); 5815 memset(&vect[ENH_VECTL-(en-idatal)], 0, 5816 (en-idatal)*sizeof(float)); 5817 } 5818 else { 5819 memcpy(vect, &idata[st], ENH_VECTL*sizeof(float)); 5820 } 5821 } 5822 fraction=tloc2*ENH_UPS0-tloc; 5824 /* compute the segment (this is actually a convolution) */ 5826 mycorr1(seg,vect,ENH_VECTL,polyphaserTbl+(2*ENH_FL0+1)*fraction, 5828 Andersen et. al. Experimental - Expires November 29th, 2004 105 5829 Internet Low Bit Rate Codec May 04 5831 2*ENH_FL0+1); 5832 } 5834 /*----------------------------------------------------------------* 5835 * find the smoothed output data 5836 *---------------------------------------------------------------*/ 5838 void smath( 5839 float *odata, /* (o) smoothed output */ 5840 float *sseq,/* (i) said second sequence of waveforms */ 5841 int hl, /* (i) 2*hl+1 is sseq dimension */ 5842 float alpha0/* (i) max smoothing energy fraction */ 5843 ){ 5844 int i,k; 5845 float w00,w10,w11,A,B,C,*psseq,err,errs; 5846 float surround[BLOCKL_MAX]; /* shape contributed by other than 5847 current */ 5848 float wt[2*ENH_HL+1]; /* waveform weighting to get 5849 surround shape */ 5850 float denom; 5852 /* create shape of contribution from all waveforms except the 5853 current one */ 5855 for (i=1; i<=2*hl+1; i++) { 5856 wt[i-1] = (float)0.5*(1 - (float)cos(2*PI*i/(2*hl+2))); 5857 } 5858 wt[hl]=0.0; /* for clarity, not used */ 5859 for (i=0; i alpha0 * w00) { 5906 if ( w00 < 1) { 5907 w00=1; 5908 } 5909 denom = (w11*w00-w10*w10)/(w00*w00); 5911 if (denom > 0.0001) { /* eliminates numerical problems 5912 for if smooth */ 5913 A = (float)sqrt( (alpha0- alpha0*alpha0/4)/denom); 5914 B = -alpha0/2 - A * w10/w00; 5915 B = B+1; 5916 } 5917 else { /* essentially no difference between cycles; 5918 smoothing not needed */ 5919 A= 0.0; 5920 B= 1.0; 5921 } 5923 /* create smoothed sequence */ 5925 psseq=sseq+hl*ENH_BLOCKL; 5926 for (i=0; i=0; q--) { 5971 blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]]; 5972 NearestNeighbor(lagBlock+q,plocs, 5973 blockStartPos[q]+ 5974 ENH_BLOCKL_HALF-period[lagBlock[q+1]], periodl); 5976 if (blockStartPos[q]-ENH_OVERHANG>=0) { 5977 refiner(sseq+q*ENH_BLOCKL, blockStartPos+q, idata, 5978 idatal, centerStartPos, blockStartPos[q], 5979 period[lagBlock[q+1]]); 5980 } else { 5981 psseq=sseq+q*ENH_BLOCKL; 5982 memset(psseq, 0, ENH_BLOCKL*sizeof(float)); 5983 } 5984 } 5986 /* future */ 5988 for (i=0; i 0.0) { 6067 return (float)(ftmp1*ftmp1/ftmp2); 6068 } 6069 else { 6070 return (float)0.0; 6071 } 6072 } 6074 /*----------------------------------------------------------------* 6075 * interface for enhancer 6076 *---------------------------------------------------------------*/ 6078 int enhancerInterface( 6079 float *out, /* (o) enhanced signal */ 6080 float *in, /* (i) unenhanced signal */ 6081 iLBC_Dec_Inst_t *iLBCdec_inst /* (i) buffers etc */ 6082 ){ 6083 float *enh_buf, *enh_period; 6084 int iblock, isample; 6085 int lag=0, ilag, i, ioffset; 6086 float cc, maxcc; 6087 float ftmp1, ftmp2; 6088 float *inPtr, *enh_bufPtr1, *enh_bufPtr2; 6089 float plc_pred[ENH_BLOCKL]; 6091 float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2]; 6092 int inLen=ENH_NBLOCKS*ENH_BLOCKL+120; 6093 int start, plc_blockl, inlag; 6095 enh_buf=iLBCdec_inst->enh_buf; 6096 enh_period=iLBCdec_inst->enh_period; 6098 memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl], 6099 (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float)); 6101 memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in, 6102 iLBCdec_inst->blockl*sizeof(float)); 6104 if (iLBCdec_inst->mode==30) 6105 plc_blockl=ENH_BLOCKL; 6106 else 6107 plc_blockl=40; 6109 /* when 20 ms frame, move processing one block */ 6110 ioffset=0; 6111 if (iLBCdec_inst->mode==20) ioffset=1; 6113 i=3-ioffset; 6114 memmove(enh_period, &enh_period[i], 6116 Andersen et. al. Experimental - Expires November 29th, 2004 110 6117 Internet Low Bit Rate Codec May 04 6119 (ENH_NBLOCKS_TOT-i)*sizeof(float)); 6121 /* Set state information to the 6 samples right before 6122 the samples to be downsampled. */ 6124 memcpy(lpState, 6125 enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126, 6126 6*sizeof(float)); 6128 /* Down sample a factor 2 to save computations */ 6130 DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120, 6131 lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL, 6132 lpState, downsampled); 6134 /* Estimate the pitch in the down sampled domain. */ 6135 for (iblock = 0; iblock maxcc) { 6147 maxcc = cc; 6148 lag = ilag; 6149 } 6150 } 6152 /* Store the estimated lag in the non-downsampled domain */ 6153 enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2; 6155 } 6157 /* PLC was performed on the previous packet */ 6158 if (iLBCdec_inst->prev_enh_pl==1) { 6160 inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset]; 6162 lag = inlag-1; 6163 maxcc = xCorrCoef(in, in+lag, plc_blockl); 6164 for (ilag=inlag; ilag<=inlag+1; ilag++) { 6165 cc = xCorrCoef(in, in+ilag, plc_blockl); 6167 if (cc > maxcc) { 6168 maxcc = cc; 6169 lag = ilag; 6170 } 6171 } 6173 Andersen et. al. Experimental - Expires November 29th, 2004 111 6174 Internet Low Bit Rate Codec May 04 6176 enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag; 6178 /* compute new concealed residual for the old lookahead, 6179 mix the forward PLC with a backward PLC from 6180 the new frame */ 6182 inPtr=&in[lag-1]; 6184 enh_bufPtr1=&plc_pred[plc_blockl-1]; 6186 if (lag>plc_blockl) { 6187 start=plc_blockl; 6188 } else { 6189 start=lag; 6190 } 6192 for (isample = start; isample>0; isample--) { 6193 *enh_bufPtr1-- = *inPtr--; 6194 } 6196 enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl]; 6197 for (isample = (plc_blockl-1-lag); isample>=0; isample--) 6198 { 6199 *enh_bufPtr1-- = *enh_bufPtr2--; 6200 } 6202 /* limit energy change */ 6203 ftmp2=0.0; 6204 ftmp1=0.0; 6205 for (i=0;iblockl-i]* 6207 enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]; 6208 ftmp1+=plc_pred[i]*plc_pred[i]; 6209 } 6210 ftmp1=(float)sqrt(ftmp1/(float)plc_blockl); 6211 ftmp2=(float)sqrt(ftmp2/(float)plc_blockl); 6212 if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) { 6213 for (i=0;iblockl]; 6224 for (i=0; imode==20) { 6238 /* Enhancer with 40 samples delay */ 6239 for (iblock = 0; iblock<2; iblock++) { 6240 enhancer(out+iblock*ENH_BLOCKL, enh_buf, 6241 ENH_BUFL, (5+iblock)*ENH_BLOCKL+40, 6242 ENH_ALPHA0, enh_period, enh_plocsTbl, 6243 ENH_NBLOCKS_TOT); 6244 } 6245 } else if (iLBCdec_inst->mode==30) { 6246 /* Enhancer with 80 samples delay */ 6247 for (iblock = 0; iblock<3; iblock++) { 6248 enhancer(out+iblock*ENH_BLOCKL, enh_buf, 6249 ENH_BUFL, (4+iblock)*ENH_BLOCKL, 6250 ENH_ALPHA0, enh_period, enh_plocsTbl, 6251 ENH_NBLOCKS_TOT); 6252 } 6253 } 6255 return (lag*2); 6256 } 6258 A.17 filter.h 6260 /****************************************************************** 6262 iLBC Speech Coder ANSI-C Source Code 6264 filter.h 6266 Copyright (C) The Internet Society (2004). 6267 All Rights Reserved. 6269 ******************************************************************/ 6271 #ifndef __iLBC_FILTER_H 6272 #define __iLBC_FILTER_H 6274 void AllPoleFilter( 6275 float *InOut, /* (i/o) on entrance InOut[-orderCoef] to 6276 InOut[-1] contain the state of the 6277 filter (delayed samples). InOut[0] to 6278 InOut[lengthInOut-1] contain the filter 6279 input, on en exit InOut[-orderCoef] to 6280 InOut[-1] is unchanged and InOut[0] to 6281 InOut[lengthInOut-1] contain filtered 6282 samples */ 6283 float *Coef,/* (i) filter coefficients, Coef[0] is assumed 6284 to be 1.0 */ 6285 int lengthInOut,/* (i) number of input/output samples */ 6286 int orderCoef /* (i) number of filter coefficients */ 6287 ); 6289 Andersen et. al. Experimental - Expires November 29th, 2004 113 6290 Internet Low Bit Rate Codec May 04 6292 void AllZeroFilter( 6293 float *In, /* (i) In[0] to In[lengthInOut-1] contain 6294 filter input samples */ 6295 float *Coef,/* (i) filter coefficients (Coef[0] is assumed 6296 to be 1.0) */ 6297 int lengthInOut,/* (i) number of input/output samples */ 6298 int orderCoef, /* (i) number of filter coefficients */ 6299 float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] 6300 contain the filter state, on exit Out[0] 6301 to Out[lengthInOut-1] contain filtered 6302 samples */ 6303 ); 6305 void ZeroPoleFilter( 6306 float *In, /* (i) In[0] to In[lengthInOut-1] contain filter 6307 input samples In[-orderCoef] to In[-1] 6308 contain state of all-zero section */ 6309 float *ZeroCoef,/* (i) filter coefficients for all-zero 6310 section (ZeroCoef[0] is assumed to 6311 be 1.0) */ 6312 float *PoleCoef,/* (i) filter coefficients for all-pole section 6313 (ZeroCoef[0] is assumed to be 1.0) */ 6314 int lengthInOut,/* (i) number of input/output samples */ 6315 int orderCoef, /* (i) number of filter coefficients */ 6316 float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1] 6317 contain state of all-pole section. On 6318 exit Out[0] to Out[lengthInOut-1] 6319 contain filtered samples */ 6320 ); 6322 void DownSample ( 6323 float *In, /* (i) input samples */ 6324 float *Coef, /* (i) filter coefficients */ 6325 int lengthIn, /* (i) number of input samples */ 6326 float *state, /* (i) filter state */ 6327 float *Out /* (o) downsampled output */ 6328 ); 6330 #endif 6332 A.18 filter.c 6334 /****************************************************************** 6336 iLBC Speech Coder ANSI-C Source Code 6338 filter.c 6340 Copyright (C) The Internet Society (2004). 6341 All Rights Reserved. 6343 ******************************************************************/ 6345 Andersen et. al. Experimental - Expires November 29th, 2004 114 6346 Internet Low Bit Rate Codec May 04 6348 #include "iLBC_define.h" 6350 /*----------------------------------------------------------------* 6351 * all-pole filter 6352 *---------------------------------------------------------------*/ 6354 void AllPoleFilter( 6355 float *InOut, /* (i/o) on entrance InOut[-orderCoef] to 6356 InOut[-1] contain the state of the 6357 filter (delayed samples). InOut[0] to 6358 InOut[lengthInOut-1] contain the filter 6359 input, on en exit InOut[-orderCoef] to 6360 InOut[-1] is unchanged and InOut[0] to 6361 InOut[lengthInOut-1] contain filtered 6362 samples */ 6363 float *Coef,/* (i) filter coefficients, Coef[0] is assumed 6364 to be 1.0 */ 6365 int lengthInOut,/* (i) number of input/output samples */ 6366 int orderCoef /* (i) number of filter coefficients */ 6367 ){ 6368 int n,k; 6370 for(n=0;nnsub-1; n++) { 6587 pp=residual+n*SUBL; 6588 for (l=0; l<5; l++) { 6589 fssqEn[n] += sampEn_win[l] * (*pp) * (*pp); 6590 bssqEn[n] += (*pp) * (*pp); 6591 pp++; 6592 } 6593 for (l=5; lnsub-1; 6608 pp=residual+n*SUBL; 6609 for (l=0; lmode==20) l=1; 6622 else l=0; 6624 max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l]; 6625 max_ssqEn_n=1; 6626 for (n=2; nnsub; n++) { 6628 l++; 6630 Andersen et. al. Experimental - Expires November 29th, 2004 119 6631 Internet Low Bit Rate Codec May 04 6633 if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) { 6634 max_ssqEn=(fssqEn[n-1]+bssqEn[n]) * 6635 ssqEn_win[l]; 6636 max_ssqEn_n=n; 6637 } 6638 } 6640 return max_ssqEn_n; 6641 } 6643 A.21 gainquant.h 6645 /****************************************************************** 6647 iLBC Speech Coder ANSI-C Source Code 6649 gainquant.h 6651 Copyright (C) The Internet Society (2004). 6652 All Rights Reserved. 6654 ******************************************************************/ 6656 #ifndef __iLBC_GAINQUANT_H 6657 #define __iLBC_GAINQUANT_H 6659 float gainquant(/* (o) quantized gain value */ 6660 float in, /* (i) gain value */ 6661 float maxIn,/* (i) maximum of gain value */ 6662 int cblen, /* (i) number of quantization indices */ 6663 int *index /* (o) quantization index */ 6664 ); 6666 float gaindequant( /* (o) quantized gain value */ 6667 int index, /* (i) quantization index */ 6668 float maxIn,/* (i) maximum of unquantized gain */ 6669 int cblen /* (i) number of quantization indices */ 6670 ); 6672 #endif 6674 A.22 gainquant.c 6676 /****************************************************************** 6678 iLBC Speech Coder ANSI-C Source Code 6680 gainquant.c 6682 Copyright (C) The Internet Society (2004). 6683 All Rights Reserved. 6685 Andersen et. al. Experimental - Expires November 29th, 2004 120 6686 Internet Low Bit Rate Codec May 04 6688 ******************************************************************/ 6690 #include 6691 #include 6692 #include "constants.h" 6693 #include "filter.h" 6695 /*----------------------------------------------------------------* 6696 * quantizer for the gain in the gain-shape coding of residual 6697 *---------------------------------------------------------------*/ 6699 float gainquant(/* (o) quantized gain value */ 6700 float in, /* (i) gain value */ 6701 float maxIn,/* (i) maximum of gain value */ 6702 int cblen, /* (i) number of quantization indices */ 6703 int *index /* (o) quantization index */ 6704 ){ 6705 int i, tindex; 6706 float minmeasure,measure, *cb, scale; 6708 /* ensure a lower bound on the scaling factor */ 6710 scale=maxIn; 6712 if (scale<0.1) { 6713 scale=(float)0.1; 6714 } 6716 /* select the quantization table */ 6718 if (cblen == 8) { 6719 cb = gain_sq3Tbl; 6720 } else if (cblen == 16) { 6721 cb = gain_sq4Tbl; 6722 } else { 6723 cb = gain_sq5Tbl; 6724 } 6726 /* select the best index in the quantization table */ 6728 minmeasure=10000000.0; 6729 tindex=0; 6730 for (i=0; i 6828 /*----------------------------------------------------------------* 6829 * Construct codebook vector for given index. 6830 *---------------------------------------------------------------*/ 6832 void getCBvec( 6833 float *cbvec, /* (o) Constructed codebook vector */ 6834 float *mem, /* (i) Codebook buffer */ 6835 int index, /* (i) Codebook index */ 6836 int lMem, /* (i) Length of codebook buffer */ 6837 int cbveclen/* (i) Codebook vector length */ 6838 ){ 6839 int j, k, n, memInd, sFilt; 6840 float tmpbuf[CB_MEML]; 6841 int base_size; 6842 int ilow, ihigh; 6843 float alfa, alfa1; 6845 /* Determine size of codebook sections */ 6847 base_size=lMem-cbveclen+1; 6849 if (cbveclen==SUBL) { 6850 base_size+=cbveclen/2; 6851 } 6853 /* No filter -> First codebook section */ 6855 Andersen et. al. Experimental - Expires November 29th, 2004 123 6856 Internet Low Bit Rate Codec May 04 6858 if (index 7112 #include "iLBC_define.h" 7113 #include "constants.h" 7115 /*----------------------------------------------------------------* 7116 * calculation of auto correlation 7117 *---------------------------------------------------------------*/ 7119 void autocorr( 7120 float *r, /* (o) autocorrelation vector */ 7121 const float *x, /* (i) data vector */ 7122 int N, /* (i) length of data vector */ 7123 int order /* largest lag for calculated 7124 autocorrelations */ 7125 ){ 7126 int lag, n; 7127 float sum; 7129 for (lag = 0; lag <= order; lag++) { 7130 sum = 0; 7131 for (n = 0; n < N - lag; n++) { 7132 sum += x[n] * x[n+lag]; 7133 } 7134 r[lag] = sum; 7135 } 7136 } 7138 Andersen et. al. Experimental - Expires November 29th, 2004 128 7139 Internet Low Bit Rate Codec May 04 7141 /*----------------------------------------------------------------* 7142 * window multiplication 7143 *---------------------------------------------------------------*/ 7145 void window( 7146 float *z, /* (o) the windowed data */ 7147 const float *x, /* (i) the original data vector */ 7148 const float *y, /* (i) the window */ 7149 int N /* (i) length of all vectors */ 7150 ){ 7151 int i; 7153 for (i = 0; i < N; i++) { 7154 z[i] = x[i] * y[i]; 7155 } 7156 } 7158 /*----------------------------------------------------------------* 7159 * levinson-durbin solution for lpc coefficients 7160 *---------------------------------------------------------------*/ 7162 void levdurb( 7163 float *a, /* (o) lpc coefficient vector starting 7164 with 1.0 */ 7165 float *k, /* (o) reflection coefficients */ 7166 float *r, /* (i) autocorrelation vector */ 7167 int order /* (i) order of lpc filter */ 7168 ){ 7169 float sum, alpha; 7170 int m, m_h, i; 7172 a[0] = 1.0; 7174 if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */ 7175 for (i = 0; i < order; i++) { 7176 k[i] = 0; 7177 a[i+1] = 0; 7178 } 7179 } else { 7180 a[1] = k[0] = -r[1]/r[0]; 7181 alpha = r[0] + r[1] * k[0]; 7182 for (m = 1; m < order; m++){ 7183 sum = r[m + 1]; 7184 for (i = 0; i < m; i++){ 7185 sum += a[i+1] * r[m - i]; 7186 } 7187 k[m] = -sum / alpha; 7188 alpha += k[m] * sum; 7189 m_h = (m + 1) >> 1; 7190 for (i = 0; i < m_h; i++){ 7191 sum = a[i+1] + k[m] * a[m - i]; 7192 a[m - i] += k[m] * a[i+1]; 7193 a[i+1] = sum; 7195 Andersen et. al. Experimental - Expires November 29th, 2004 129 7196 Internet Low Bit Rate Codec May 04 7198 } 7199 a[m+1] = k[m]; 7200 } 7201 } 7202 } 7204 /*----------------------------------------------------------------* 7205 * interpolation between vectors 7206 *---------------------------------------------------------------*/ 7208 void interpolate( 7209 float *out, /* (o) the interpolated vector */ 7210 float *in1, /* (i) the first vector for the 7211 interpolation */ 7212 float *in2, /* (i) the second vector for the 7213 interpolation */ 7214 float coef, /* (i) interpolation weights */ 7215 int length /* (i) length of all vectors */ 7216 ){ 7217 int i; 7218 float invcoef; 7220 invcoef = (float)1.0 - coef; 7221 for (i = 0; i < length; i++) { 7222 out[i] = coef * in1[i] + invcoef * in2[i]; 7223 } 7224 } 7226 /*----------------------------------------------------------------* 7227 * lpc bandwidth expansion 7228 *---------------------------------------------------------------*/ 7230 void bwexpand( 7231 float *out, /* (o) the bandwidth expanded lpc 7232 coefficients */ 7233 float *in, /* (i) the lpc coefficients before bandwidth 7234 expansion */ 7235 float coef, /* (i) the bandwidth expansion factor */ 7236 int length /* (i) the length of lpc coefficient vectors */ 7237 ){ 7238 int i; 7239 float chirp; 7241 chirp = coef; 7243 out[0] = in[0]; 7244 for (i = 1; i < length; i++) { 7245 out[i] = chirp * in[i]; 7246 chirp *= coef; 7247 } 7248 } 7250 /*----------------------------------------------------------------* 7251 * vector quantization 7253 Andersen et. al. Experimental - Expires November 29th, 2004 130 7254 Internet Low Bit Rate Codec May 04 7256 *---------------------------------------------------------------*/ 7258 void vq( 7259 float *Xq, /* (o) the quantized vector */ 7260 int *index, /* (o) the quantization index */ 7261 const float *CB,/* (i) the vector quantization codebook */ 7262 float *X, /* (i) the vector to quantize */ 7263 int n_cb, /* (i) the number of vectors in the codebook */ 7264 int dim /* (i) the dimension of all vectors */ 7265 ){ 7266 int i, j; 7267 int pos, minindex; 7268 float dist, tmp, mindist; 7270 pos = 0; 7271 mindist = FLOAT_MAX; 7272 minindex = 0; 7273 for (j = 0; j < n_cb; j++) { 7274 dist = X[0] - CB[pos]; 7275 dist *= dist; 7276 for (i = 1; i < dim; i++) { 7277 tmp = X[i] - CB[pos + i]; 7278 dist += tmp*tmp; 7279 } 7281 if (dist < mindist) { 7282 mindist = dist; 7283 minindex = j; 7284 } 7285 pos += dim; 7286 } 7287 for (i = 0; i < dim; i++) { 7288 Xq[i] = CB[minindex*dim + i]; 7289 } 7290 *index = minindex; 7291 } 7293 /*----------------------------------------------------------------* 7294 * split vector quantization 7295 *---------------------------------------------------------------*/ 7297 void SplitVQ( 7298 float *qX, /* (o) the quantized vector */ 7299 int *index, /* (o) a vector of indexes for all vector 7300 codebooks in the split */ 7301 float *X, /* (i) the vector to quantize */ 7302 const float *CB,/* (i) the quantizer codebook */ 7303 int nsplit, /* the number of vector splits */ 7304 const int *dim, /* the dimension of X and qX */ 7305 const int *cbsize /* the number of vectors in the codebook */ 7306 ){ 7307 int cb_pos, X_pos, i; 7309 cb_pos = 0; 7311 Andersen et. al. Experimental - Expires November 29th, 2004 131 7312 Internet Low Bit Rate Codec May 04 7314 X_pos= 0; 7315 for (i = 0; i < nsplit; i++) { 7316 vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos, 7317 cbsize[i], dim[i]); 7318 X_pos += dim[i]; 7319 cb_pos += dim[i] * cbsize[i]; 7320 } 7321 } 7323 /*----------------------------------------------------------------* 7324 * scalar quantization 7325 *---------------------------------------------------------------*/ 7327 void sort_sq( 7328 float *xq, /* (o) the quantized value */ 7329 int *index, /* (o) the quantization index */ 7330 float x, /* (i) the value to quantize */ 7331 const float *cb,/* (i) the quantization codebook */ 7332 int cb_size /* (i) the size of the quantization codebook */ 7333 ){ 7334 int i; 7336 if (x <= cb[0]) { 7337 *index = 0; 7338 *xq = cb[0]; 7339 } else { 7340 i = 0; 7341 while ((x > cb[i]) && i < cb_size - 1) { 7342 i++; 7343 } 7345 if (x > ((cb[i] + cb[i - 1])/2)) { 7346 *index = i; 7347 *xq = cb[i]; 7348 } else { 7349 *index = i - 1; 7350 *xq = cb[i - 1]; 7351 } 7352 } 7353 } 7355 /*----------------------------------------------------------------* 7356 * check for stability of lsf coefficients 7357 *---------------------------------------------------------------*/ 7359 int LSF_check( /* (o) 1 for stable lsf vectors and 0 for 7360 nonstable ones */ 7361 float *lsf, /* (i) a table of lsf vectors */ 7362 int dim, /* (i) the dimension of each lsf vector */ 7363 int NoAn /* (i) the number of lsf vectors in the 7364 table */ 7365 ){ 7366 int k,n,m, Nit=2, change=0,pos; 7367 float tmp; 7369 Andersen et. al. Experimental - Expires November 29th, 2004 132 7370 Internet Low Bit Rate Codec May 04 7372 static float eps=(float)0.039; /* 50 Hz */ 7373 static float eps2=(float)0.0195; 7374 static float maxlsf=(float)3.14; /* 4000 Hz */ 7375 static float minlsf=(float)0.01; /* 0 Hz */ 7377 /* LSF separation check*/ 7379 for (n=0; nmaxlsf) { 7403 lsf[pos]=maxlsf; 7404 change=1; 7405 } 7406 } 7407 } 7408 } 7410 return change; 7411 } 7413 A.27 hpInput.h 7415 /****************************************************************** 7417 iLBC Speech Coder ANSI-C Source Code 7419 hpInput.h 7421 Copyright (C) The Internet Society (2004). 7422 All Rights Reserved. 7424 ******************************************************************/ 7426 Andersen et. al. Experimental - Expires November 29th, 2004 133 7427 Internet Low Bit Rate Codec May 04 7429 #ifndef __iLBC_HPINPUT_H 7430 #define __iLBC_HPINPUT_H 7432 void hpInput( 7433 float *In, /* (i) vector to filter */ 7434 int len, /* (i) length of vector to filter */ 7435 float *Out, /* (o) the resulting filtered vector */ 7436 float *mem /* (i/o) the filter state */ 7437 ); 7439 #endif 7441 A.28 hpInput.c 7443 /****************************************************************** 7445 iLBC Speech Coder ANSI-C Source Code 7447 hpInput.c 7449 Copyright (C) The Internet Society (2004). 7450 All Rights Reserved. 7452 ******************************************************************/ 7454 #include "constants.h" 7456 /*----------------------------------------------------------------* 7457 * Input high-pass filter 7458 *---------------------------------------------------------------*/ 7460 void hpInput( 7461 float *In, /* (i) vector to filter */ 7462 int len, /* (i) length of vector to filter */ 7463 float *Out, /* (o) the resulting filtered vector */ 7464 float *mem /* (i/o) the filter state */ 7465 ){ 7466 int i; 7467 float *pi, *po; 7469 /* all-zero section*/ 7471 pi = &In[0]; 7472 po = &Out[0]; 7473 for (i=0; i 7641 #include "iLBC_define.h" 7642 #include "gainquant.h" 7643 #include "getCBvec.h" 7645 /*----------------------------------------------------------------* 7646 * Convert the codebook indexes to make the search easier 7647 *---------------------------------------------------------------*/ 7649 Andersen et. al. Experimental - Expires November 29th, 2004 137 7650 Internet Low Bit Rate Codec May 04 7652 void index_conv_enc( 7653 int *index /* (i/o) Codebook indexes */ 7654 ){ 7655 int k; 7657 for (k=1; k=108)&&(index[k]<172)) { 7660 index[k]-=64; 7661 } else if (index[k]>=236) { 7662 index[k]-=128; 7663 } else { 7664 /* ERROR */ 7665 } 7666 } 7667 } 7669 void index_conv_dec( 7670 int *index /* (i/o) Codebook indexes */ 7671 ){ 7672 int k; 7674 for (k=1; k=44)&&(index[k]<108)) { 7677 index[k]+=64; 7678 } else if ((index[k]>=108)&&(index[k]<128)) { 7679 index[k]+=128; 7680 } else { 7681 /* ERROR */ 7682 } 7683 } 7684 } 7686 /*----------------------------------------------------------------* 7687 * Construct decoded vector from codebook and gains. 7688 *---------------------------------------------------------------*/ 7690 void iCBConstruct( 7691 float *decvector, /* (o) Decoded vector */ 7692 int *index, /* (i) Codebook indices */ 7693 int *gain_index,/* (i) Gain quantization indices */ 7694 float *mem, /* (i) Buffer for codevector construction */ 7695 int lMem, /* (i) Length of buffer */ 7696 int veclen, /* (i) Length of vector */ 7697 int nStages /* (i) Number of codebook stages */ 7698 ){ 7699 int j,k; 7700 float gain[CB_NSTAGES]; 7701 float cbvec[SUBL]; 7703 /* gain de-quantization */ 7705 gain[0] = gaindequant(gain_index[0], 1.0, 32); 7707 Andersen et. al. Experimental - Expires November 29th, 2004 138 7708 Internet Low Bit Rate Codec May 04 7710 if (nStages > 1) { 7711 gain[1] = gaindequant(gain_index[1], 7712 (float)fabs(gain[0]), 16); 7713 } 7714 if (nStages > 2) { 7715 gain[2] = gaindequant(gain_index[2], 7716 (float)fabs(gain[1]), 8); 7717 } 7719 /* codebook vector construction and construction of 7720 total vector */ 7722 getCBvec(cbvec, mem, index[0], lMem, veclen); 7723 for (j=0;j 1) { 7727 for (k=1; k 7787 #include 7789 #include "iLBC_define.h" 7790 #include "gainquant.h" 7791 #include "createCB.h" 7792 #include "filter.h" 7793 #include "constants.h" 7795 /*----------------------------------------------------------------* 7796 * Search routine for codebook encoding and gain quantization. 7797 *---------------------------------------------------------------*/ 7799 void iCBSearch( 7800 iLBC_Enc_Inst_t *iLBCenc_inst, 7801 /* (i) the encoder state structure */ 7802 int *index, /* (o) Codebook indices */ 7803 int *gain_index,/* (o) Gain quantization indices */ 7804 float *intarget,/* (i) Target vector for encoding */ 7805 float *mem, /* (i) Buffer for codebook construction */ 7806 int lMem, /* (i) Length of buffer */ 7807 int lTarget, /* (i) Length of vector */ 7808 int nStages, /* (i) Number of codebook stages */ 7809 float *weightDenum, /* (i) weighting filter coefficients */ 7810 float *weightState, /* (i) weighting filter state */ 7811 int block /* (i) the sub-block number */ 7812 ){ 7813 int i, j, icount, stage, best_index, range, counter; 7814 float max_measure, gain, measure, crossDot, ftmp; 7815 float gains[CB_NSTAGES]; 7816 float target[SUBL]; 7817 int base_index, sInd, eInd, base_size; 7818 int sIndAug=0, eIndAug=0; 7819 float buf[CB_MEML+SUBL+2*LPC_FILTERORDER]; 7821 Andersen et. al. Experimental - Expires November 29th, 2004 140 7822 Internet Low Bit Rate Codec May 04 7824 float invenergy[CB_EXPAND*128], energy[CB_EXPAND*128]; 7825 float *pp, *ppi=0, *ppo=0, *ppe=0; 7826 float cbvectors[CB_MEML]; 7827 float tene, cene, cvec[SUBL]; 7828 float aug_vec[SUBL]; 7830 memset(cvec,0,SUBL*sizeof(float)); 7832 /* Determine size of codebook sections */ 7834 base_size=lMem-lTarget+1; 7836 if (lTarget==SUBL) { 7837 base_size=lMem-lTarget+1+lTarget/2; 7838 } 7840 /* setup buffer for weighting */ 7842 memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER); 7843 memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float)); 7844 memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float)); 7846 /* weighting */ 7848 AllPoleFilter(buf+LPC_FILTERORDER, weightDenum, 7849 lMem+lTarget, LPC_FILTERORDER); 7851 /* Construct the codebook and target needed */ 7853 memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float)); 7855 tene=0.0; 7856 for (i=0; i0.0) { 7905 invenergy[0] = (float) 1.0 / (*ppe + EPS); 7906 } else { 7907 invenergy[0] = (float) 0.0; 7908 } 7909 ppe++; 7911 measure=(float)-10000000.0; 7913 if (crossDot > 0.0) { 7914 measure = crossDot*crossDot*invenergy[0]; 7915 } 7916 } 7917 else { 7918 measure = crossDot*crossDot*invenergy[0]; 7919 } 7921 /* check if measure is better */ 7922 ftmp = crossDot*invenergy[0]; 7924 if ((measure>max_measure) && (fabs(ftmp)0.0) { 7954 invenergy[icount] = 7955 (float)1.0/(energy[icount]+EPS); 7956 } else { 7957 invenergy[icount] = (float) 0.0; 7958 } 7960 measure=(float)-10000000.0; 7962 if (crossDot > 0.0) { 7963 measure = crossDot*crossDot*invenergy[icount]; 7964 } 7965 } 7966 else { 7967 measure = crossDot*crossDot*invenergy[icount]; 7968 } 7970 /* check if measure is better */ 7971 ftmp = crossDot*invenergy[icount]; 7973 if ((measure>max_measure) && (fabs(ftmp) range) { 8033 sInd -= (eInd-range); 8034 eInd = range; 8035 } 8036 } else { /* base_index >= (base_size-20) */ 8038 if (sInd < (base_size-20)) { 8039 sIndAug = 20; 8040 sInd = 0; 8041 eInd = 0; 8042 eIndAug = 19 + CB_RESRANGE; 8044 if(eIndAug > 39) { 8045 eInd = eIndAug-39; 8046 eIndAug = 39; 8047 } 8048 } else { 8049 sIndAug = 20 + sInd - (base_size-20); 8050 eIndAug = 39; 8052 Andersen et. al. Experimental - Expires November 29th, 2004 144 8053 Internet Low Bit Rate Codec May 04 8055 sInd = 0; 8056 eInd = CB_RESRANGE - (eIndAug-sIndAug+1); 8057 } 8058 } 8060 } else { /* lTarget = 22 or 23 */ 8062 if (sInd < 0) { 8063 eInd -= sInd; 8064 sInd = 0; 8065 } 8067 if(eInd > range) { 8068 sInd -= (eInd - range); 8069 eInd = range; 8070 } 8071 } 8072 } 8074 /* search of higher codebook section */ 8076 /* index search range */ 8077 counter = sInd; 8078 sInd += base_size; 8079 eInd += base_size; 8081 if (stage==0) { 8082 ppe = energy+base_size; 8083 *ppe=0.0; 8085 pp=cbvectors+lMem-lTarget; 8086 for (j=0; j0.0) { 8119 invenergy[icount] =(float)1.0/(energy[icount]+EPS); 8120 } else { 8121 invenergy[icount] =(float)0.0; 8122 } 8124 if (stage==0) { 8126 measure=(float)-10000000.0; 8128 if (crossDot > 0.0) { 8129 measure = crossDot*crossDot* 8130 invenergy[icount]; 8131 } 8132 } 8133 else { 8134 measure = crossDot*crossDot*invenergy[icount]; 8135 } 8137 /* check if measure is better */ 8138 ftmp = crossDot*invenergy[icount]; 8140 if ((measure>max_measure) && (fabs(ftmp)CB_MAXGAIN) { 8173 gain = (float)CB_MAXGAIN; 8174 } 8175 gain = gainquant(gain, 1.0, 32, &gain_index[stage]); 8176 } 8177 else { 8178 if (stage==1) { 8179 gain = gainquant(gain, (float)fabs(gains[stage-1]), 8180 16, &gain_index[stage]); 8181 } else { 8182 gain = gainquant(gain, (float)fabs(gains[stage-1]), 8183 8, &gain_index[stage]); 8184 } 8185 } 8187 /* Extract the best (according to measure) 8188 codebook vector */ 8190 if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) { 8192 if (index[stage] 8323 #include 8325 #include "helpfun.h" 8326 #include "lsf.h" 8327 #include "iLBC_define.h" 8328 #include "constants.h" 8330 /*---------------------------------------------------------------* 8331 * interpolation of lsf coefficients for the decoder 8332 *--------------------------------------------------------------*/ 8334 void LSFinterpolate2a_dec( 8335 float *a, /* (o) lpc coefficients for a sub-frame */ 8336 float *lsf1, /* (i) first lsf coefficient vector */ 8338 Andersen et. al. Experimental - Expires November 29th, 2004 149 8339 Internet Low Bit Rate Codec May 04 8341 float *lsf2, /* (i) second lsf coefficient vector */ 8342 float coef, /* (i) interpolation weight */ 8343 int length /* (i) length of lsf vectors */ 8344 ){ 8345 float lsftmp[LPC_FILTERORDER]; 8347 interpolate(lsftmp, lsf1, lsf2, coef, length); 8348 lsf2a(a, lsftmp); 8349 } 8351 /*---------------------------------------------------------------* 8352 * obtain dequantized lsf coefficients from quantization index 8353 *--------------------------------------------------------------*/ 8355 void SimplelsfDEQ( 8356 float *lsfdeq, /* (o) dequantized lsf coefficients */ 8357 int *index, /* (i) quantization index */ 8358 int lpc_n /* (i) number of LPCs */ 8359 ){ 8360 int i, j, pos, cb_pos; 8362 /* decode first LSF */ 8364 pos = 0; 8365 cb_pos = 0; 8366 for (i = 0; i < LSF_NSPLIT; i++) { 8367 for (j = 0; j < dim_lsfCbTbl[i]; j++) { 8368 lsfdeq[pos + j] = lsfCbTbl[cb_pos + 8369 (long)(index[i])*dim_lsfCbTbl[i] + j]; 8370 } 8371 pos += dim_lsfCbTbl[i]; 8372 cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i]; 8373 } 8375 if (lpc_n>1) { 8377 /* decode last LSF */ 8379 pos = 0; 8380 cb_pos = 0; 8381 for (i = 0; i < LSF_NSPLIT; i++) { 8382 for (j = 0; j < dim_lsfCbTbl[i]; j++) { 8383 lsfdeq[LPC_FILTERORDER + pos + j] = 8384 lsfCbTbl[cb_pos + 8385 (long)(index[LSF_NSPLIT + i])* 8386 dim_lsfCbTbl[i] + j]; 8387 } 8388 pos += dim_lsfCbTbl[i]; 8389 cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i]; 8390 } 8391 } 8392 } 8394 /*----------------------------------------------------------------* 8396 Andersen et. al. Experimental - Expires November 29th, 2004 150 8397 Internet Low Bit Rate Codec May 04 8399 * obtain synthesis and weighting filters form lsf coefficients 8400 *---------------------------------------------------------------*/ 8402 void DecoderInterpolateLSF( 8403 float *syntdenum, /* (o) synthesis filter coefficients */ 8404 float *weightdenum, /* (o) weighting denumerator 8405 coefficients */ 8406 float *lsfdeq, /* (i) dequantized lsf coefficients */ 8407 int length, /* (i) length of lsf coefficient vector */ 8408 iLBC_Dec_Inst_t *iLBCdec_inst 8409 /* (i) the decoder state structure */ 8410 ){ 8411 int i, pos, lp_length; 8412 float lp[LPC_FILTERORDER + 1], *lsfdeq2; 8414 lsfdeq2 = lsfdeq + length; 8415 lp_length = length + 1; 8417 if (iLBCdec_inst->mode==30) { 8418 /* sub-frame 1: Interpolation between old and first */ 8420 LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq, 8421 lsf_weightTbl_30ms[0], length); 8422 memcpy(syntdenum,lp,lp_length*sizeof(float)); 8423 bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, 8424 lp_length); 8426 /* sub-frames 2 to 6: interpolation between first 8427 and last LSF */ 8429 pos = lp_length; 8430 for (i = 1; i < 6; i++) { 8431 LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2, 8432 lsf_weightTbl_30ms[i], length); 8433 memcpy(syntdenum + pos,lp,lp_length*sizeof(float)); 8434 bwexpand(weightdenum + pos, lp, 8435 LPC_CHIRP_WEIGHTDENUM, lp_length); 8436 pos += lp_length; 8437 } 8438 } 8439 else { 8440 pos = 0; 8441 for (i = 0; i < iLBCdec_inst->nsub; i++) { 8442 LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, 8443 lsfdeq, lsf_weightTbl_20ms[i], length); 8444 memcpy(syntdenum+pos,lp,lp_length*sizeof(float)); 8445 bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM, 8446 lp_length); 8447 pos += lp_length; 8448 } 8449 } 8451 /* update memory */ 8453 Andersen et. al. Experimental - Expires November 29th, 2004 151 8454 Internet Low Bit Rate Codec May 04 8456 if (iLBCdec_inst->mode==30) 8457 memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2, 8458 length*sizeof(float)); 8459 else 8460 memcpy(iLBCdec_inst->lsfdeqold, lsfdeq, 8461 length*sizeof(float)); 8463 } 8465 A.37 LPCencode.h 8467 /****************************************************************** 8469 iLBC Speech Coder ANSI-C Source Code 8471 LPCencode.h 8473 Copyright (C) The Internet Society (2004). 8474 All Rights Reserved. 8476 ******************************************************************/ 8478 #ifndef __iLBC_LPCENCOD_H 8479 #define __iLBC_LPCENCOD_H 8481 void LPCencode( 8482 float *syntdenum, /* (i/o) synthesis filter coefficients 8483 before/after encoding */ 8484 float *weightdenum, /* (i/o) weighting denumerator coefficients 8485 before/after encoding */ 8486 int *lsf_index, /* (o) lsf quantization index */ 8487 float *data, /* (i) lsf coefficients to quantize */ 8488 iLBC_Enc_Inst_t *iLBCenc_inst 8489 /* (i/o) the encoder state structure */ 8490 ); 8492 #endif 8494 A.38 LPCencode.c 8496 /****************************************************************** 8498 iLBC Speech Coder ANSI-C Source Code 8500 LPCencode.c 8502 Copyright (C) The Internet Society (2004). 8503 All Rights Reserved. 8505 ******************************************************************/ 8507 #include 8509 Andersen et. al. Experimental - Expires November 29th, 2004 152 8510 Internet Low Bit Rate Codec May 04 8512 #include "iLBC_define.h" 8513 #include "helpfun.h" 8514 #include "lsf.h" 8515 #include "constants.h" 8517 /*----------------------------------------------------------------* 8518 * lpc analysis (subrutine to LPCencode) 8519 *---------------------------------------------------------------*/ 8521 void SimpleAnalysis( 8522 float *lsf, /* (o) lsf coefficients */ 8523 float *data, /* (i) new data vector */ 8524 iLBC_Enc_Inst_t *iLBCenc_inst 8525 /* (i/o) the encoder state structure */ 8526 ){ 8527 int k, is; 8528 float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1]; 8529 float lp2[LPC_FILTERORDER + 1]; 8530 float r[LPC_FILTERORDER + 1]; 8532 is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl; 8533 memcpy(iLBCenc_inst->lpc_buffer+is,data, 8534 iLBCenc_inst->blockl*sizeof(float)); 8536 /* No lookahead, last window is asymmetric */ 8538 for (k = 0; k < iLBCenc_inst->lpc_n; k++) { 8540 is = LPC_LOOKBACK; 8542 if (k < (iLBCenc_inst->lpc_n - 1)) { 8543 window(temp, lpc_winTbl, 8544 iLBCenc_inst->lpc_buffer, BLOCKL_MAX); 8545 } else { 8546 window(temp, lpc_asymwinTbl, 8547 iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX); 8548 } 8550 autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER); 8551 window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1); 8553 levdurb(lp, temp, r, LPC_FILTERORDER); 8554 bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1); 8556 a2lsf(lsf + k*LPC_FILTERORDER, lp2); 8557 } 8558 is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl; 8559 memmove(iLBCenc_inst->lpc_buffer, 8560 iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is, 8561 is*sizeof(float)); 8562 } 8564 /*----------------------------------------------------------------* 8566 Andersen et. al. Experimental - Expires November 29th, 2004 153 8567 Internet Low Bit Rate Codec May 04 8569 * lsf interpolator and conversion from lsf to a coefficients 8570 * (subrutine to SimpleInterpolateLSF) 8571 *---------------------------------------------------------------*/ 8573 void LSFinterpolate2a_enc( 8574 float *a, /* (o) lpc coefficients */ 8575 float *lsf1,/* (i) first set of lsf coefficients */ 8576 float *lsf2,/* (i) second set of lsf coefficients */ 8577 float coef, /* (i) weighting coefficient to use between 8578 lsf1 and lsf2 */ 8579 long length /* (i) length of coefficient vectors */ 8580 ){ 8581 float lsftmp[LPC_FILTERORDER]; 8583 interpolate(lsftmp, lsf1, lsf2, coef, length); 8584 lsf2a(a, lsftmp); 8585 } 8587 /*----------------------------------------------------------------* 8588 * lsf interpolator (subrutine to LPCencode) 8589 *---------------------------------------------------------------*/ 8591 void SimpleInterpolateLSF( 8592 float *syntdenum, /* (o) the synthesis filter denominator 8593 resulting from the quantized 8594 interpolated lsf */ 8595 float *weightdenum, /* (o) the weighting filter denominator 8596 resulting from the unquantized 8597 interpolated lsf */ 8598 float *lsf, /* (i) the unquantized lsf coefficients */ 8599 float *lsfdeq, /* (i) the dequantized lsf coefficients */ 8600 float *lsfold, /* (i) the unquantized lsf coefficients of 8601 the previous signal frame */ 8602 float *lsfdeqold, /* (i) the dequantized lsf coefficients of 8603 the previous signal frame */ 8604 int length, /* (i) should equate LPC_FILTERORDER */ 8605 iLBC_Enc_Inst_t *iLBCenc_inst 8606 /* (i/o) the encoder state structure */ 8607 ){ 8608 int i, pos, lp_length; 8609 float lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2; 8611 lsf2 = lsf + length; 8612 lsfdeq2 = lsfdeq + length; 8613 lp_length = length + 1; 8615 if (iLBCenc_inst->mode==30) { 8616 /* sub-frame 1: Interpolation between old and first 8617 set of lsf coefficients */ 8619 LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, 8620 lsf_weightTbl_30ms[0], length); 8621 memcpy(syntdenum,lp,lp_length*sizeof(float)); 8622 LSFinterpolate2a_enc(lp, lsfold, lsf, 8624 Andersen et. al. Experimental - Expires November 29th, 2004 154 8625 Internet Low Bit Rate Codec May 04 8627 lsf_weightTbl_30ms[0], length); 8628 bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length); 8630 /* sub-frame 2 to 6: Interpolation between first 8631 and second set of lsf coefficients */ 8633 pos = lp_length; 8634 for (i = 1; i < iLBCenc_inst->nsub; i++) { 8635 LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2, 8636 lsf_weightTbl_30ms[i], length); 8637 memcpy(syntdenum + pos,lp,lp_length*sizeof(float)); 8639 LSFinterpolate2a_enc(lp, lsf, lsf2, 8640 lsf_weightTbl_30ms[i], length); 8641 bwexpand(weightdenum + pos, lp, 8642 LPC_CHIRP_WEIGHTDENUM, lp_length); 8643 pos += lp_length; 8644 } 8645 } 8646 else { 8647 pos = 0; 8648 for (i = 0; i < iLBCenc_inst->nsub; i++) { 8649 LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq, 8650 lsf_weightTbl_20ms[i], length); 8651 memcpy(syntdenum+pos,lp,lp_length*sizeof(float)); 8652 LSFinterpolate2a_enc(lp, lsfold, lsf, 8653 lsf_weightTbl_20ms[i], length); 8654 bwexpand(weightdenum+pos, lp, 8655 LPC_CHIRP_WEIGHTDENUM, lp_length); 8656 pos += lp_length; 8657 } 8658 } 8660 /* update memory */ 8662 if (iLBCenc_inst->mode==30) { 8663 memcpy(lsfold, lsf2, length*sizeof(float)); 8664 memcpy(lsfdeqold, lsfdeq2, length*sizeof(float)); 8665 } 8666 else { 8667 memcpy(lsfold, lsf, length*sizeof(float)); 8668 memcpy(lsfdeqold, lsfdeq, length*sizeof(float)); 8669 } 8670 } 8672 /*----------------------------------------------------------------* 8673 * lsf quantizer (subrutine to LPCencode) 8674 *---------------------------------------------------------------*/ 8676 void SimplelsfQ( 8677 float *lsfdeq, /* (o) dequantized lsf coefficients 8678 (dimension FILTERORDER) */ 8679 int *index, /* (o) quantization index */ 8680 float *lsf, /* (i) the lsf coefficient vector to be 8682 Andersen et. al. Experimental - Expires November 29th, 2004 155 8683 Internet Low Bit Rate Codec May 04 8685 quantized (dimension FILTERORDER ) */ 8686 int lpc_n /* (i) number of lsf sets to quantize */ 8687 ){ 8688 /* Quantize first LSF with memoryless split VQ */ 8689 SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT, 8690 dim_lsfCbTbl, size_lsfCbTbl); 8692 if (lpc_n==2) { 8693 /* Quantize second LSF with memoryless split VQ */ 8694 SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT, 8695 lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT, 8696 dim_lsfCbTbl, size_lsfCbTbl); 8697 } 8698 } 8700 /*----------------------------------------------------------------* 8701 * lpc encoder 8702 *---------------------------------------------------------------*/ 8704 void LPCencode( 8705 float *syntdenum, /* (i/o) synthesis filter coefficients 8706 before/after encoding */ 8707 float *weightdenum, /* (i/o) weighting denumerator 8708 coefficients before/after 8709 encoding */ 8710 int *lsf_index, /* (o) lsf quantization index */ 8711 float *data, /* (i) lsf coefficients to quantize */ 8712 iLBC_Enc_Inst_t *iLBCenc_inst 8713 /* (i/o) the encoder state structure */ 8714 ){ 8715 float lsf[LPC_FILTERORDER * LPC_N_MAX]; 8716 float lsfdeq[LPC_FILTERORDER * LPC_N_MAX]; 8717 int change=0; 8719 SimpleAnalysis(lsf, data, iLBCenc_inst); 8720 SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n); 8721 change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n); 8722 SimpleInterpolateLSF(syntdenum, weightdenum, 8723 lsf, lsfdeq, iLBCenc_inst->lsfold, 8724 iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst); 8725 } 8727 A.39 lsf.h 8729 /****************************************************************** 8731 iLBC Speech Coder ANSI-C Source Code 8733 lsf.h 8735 Copyright (C) The Internet Society (2004). 8736 All Rights Reserved. 8738 Andersen et. al. Experimental - Expires November 29th, 2004 156 8739 Internet Low Bit Rate Codec May 04 8741 ******************************************************************/ 8743 #ifndef __iLBC_LSF_H 8744 #define __iLBC_LSF_H 8746 void a2lsf( 8747 float *freq,/* (o) lsf coefficients */ 8748 float *a /* (i) lpc coefficients */ 8749 ); 8751 void lsf2a( 8752 float *a_coef, /* (o) lpc coefficients */ 8753 float *freq /* (i) lsf coefficients */ 8754 ); 8756 #endif 8758 A.40 lsf.c 8760 /****************************************************************** 8762 iLBC Speech Coder ANSI-C Source Code 8764 lsf.c 8766 Copyright (C) The Internet Society (2004). 8767 All Rights Reserved. 8769 ******************************************************************/ 8771 #include 8772 #include 8774 #include "iLBC_define.h" 8776 /*----------------------------------------------------------------* 8777 * conversion from lpc coefficients to lsf coefficients 8778 *---------------------------------------------------------------*/ 8780 void a2lsf( 8781 float *freq,/* (o) lsf coefficients */ 8782 float *a /* (i) lpc coefficients */ 8783 ){ 8784 float steps[LSF_NUMBER_OF_STEPS] = 8785 {(float)0.00635, (float)0.003175, (float)0.0015875, 8786 (float)0.00079375}; 8787 float step; 8788 int step_idx; 8789 int lsp_index; 8790 float p[LPC_HALFORDER]; 8791 float q[LPC_HALFORDER]; 8792 float p_pre[LPC_HALFORDER]; 8794 Andersen et. al. Experimental - Expires November 29th, 2004 157 8795 Internet Low Bit Rate Codec May 04 8797 float q_pre[LPC_HALFORDER]; 8798 float old_p, old_q, *old; 8799 float *pq_coef; 8800 float omega, old_omega; 8801 int i; 8802 float hlp, hlp1, hlp2, hlp3, hlp4, hlp5; 8804 for (i=0; i= 0.5)){ 8866 if (step_idx == (LSF_NUMBER_OF_STEPS - 1)){ 8868 if (fabs(hlp5) >= fabs(*old)) { 8869 freq[lsp_index] = omega - step; 8870 } else { 8871 freq[lsp_index] = omega; 8872 } 8874 if ((*old) >= 0.0){ 8875 *old = (float)-1.0 * FLOAT_MAX; 8876 } else { 8877 *old = FLOAT_MAX; 8878 } 8880 omega = old_omega; 8881 step_idx = 0; 8883 step_idx = LSF_NUMBER_OF_STEPS; 8884 } else { 8886 if (step_idx == 0) { 8887 old_omega = omega; 8888 } 8890 step_idx++; 8891 omega -= steps[step_idx]; 8893 /* Go back one grid step */ 8895 step = steps[step_idx]; 8896 } 8897 } else { 8899 /* increment omega until they are of different sign, 8900 and we know there is at least one root between omega 8901 and old_omega */ 8902 *old = hlp5; 8903 omega += step; 8904 } 8906 Andersen et. al. Experimental - Expires November 29th, 2004 159 8907 Internet Low Bit Rate Codec May 04 8909 } 8910 } 8912 for (i = 0; i= 0.5)){ 8946 if (freq[0] <= 0.0) { 8947 freq[0] = (float)0.022; 8948 } 8950 if (freq[LPC_FILTERORDER - 1] >= 0.5) { 8951 freq[LPC_FILTERORDER - 1] = (float)0.499; 8952 } 8954 hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) / 8955 (float) (LPC_FILTERORDER - 1); 8957 for (i=1; i 9107 #include 9109 #include "iLBC_define.h" 9110 #include "constants.h" 9111 #include "helpfun.h" 9112 #include "string.h" 9114 /*----------------------------------------------------------------* 9115 * splitting an integer into first most significant bits and 9116 * remaining least significant bits 9117 *---------------------------------------------------------------*/ 9119 void packsplit( 9120 int *index, /* (i) the value to split */ 9121 int *firstpart, /* (o) the value specified by most 9122 significant bits */ 9123 int *rest, /* (o) the value specified by least 9124 significant bits */ 9125 int bitno_firstpart, /* (i) number of bits in most 9126 significant part */ 9127 int bitno_total /* (i) number of bits in full range 9128 of value */ 9129 ){ 9130 int bitno_rest = bitno_total-bitno_firstpart; 9132 Andersen et. al. Experimental - Expires November 29th, 2004 163 9133 Internet Low Bit Rate Codec May 04 9135 *firstpart = *index>>(bitno_rest); 9136 *rest = *index-(*firstpart<<(bitno_rest)); 9137 } 9139 /*----------------------------------------------------------------* 9140 * combining a value corresponding to msb's with a value 9141 * corresponding to lsb's 9142 *---------------------------------------------------------------*/ 9144 void packcombine( 9145 int *index, /* (i/o) the msb value in the 9146 combined value out */ 9147 int rest, /* (i) the lsb value */ 9148 int bitno_rest /* (i) the number of bits in the 9149 lsb part */ 9150 ){ 9151 *index = *index<0) { 9181 /* Jump to the next byte if end of this byte is reached*/ 9183 if (*pos==8) { 9184 *pos=0; 9185 (*bitstream)++; 9186 **bitstream=0; 9187 } 9189 Andersen et. al. Experimental - Expires November 29th, 2004 164 9190 Internet Low Bit Rate Codec May 04 9192 posLeft=8-(*pos); 9194 /* Insert index into the bitstream */ 9196 if (bitno <= posLeft) { 9197 **bitstream |= (unsigned char)(index<<(posLeft-bitno)); 9198 *pos+=bitno; 9199 bitno=0; 9200 } else { 9201 **bitstream |= (unsigned char)(index>>(bitno-posLeft)); 9203 *pos=8; 9204 index-=((index>>(bitno-posLeft))<<(bitno-posLeft)); 9206 bitno-=posLeft; 9207 } 9208 } 9209 } 9211 /*----------------------------------------------------------------* 9212 * unpacking of bits from bitstream, i.e., vector of bytes 9213 *---------------------------------------------------------------*/ 9215 void unpack( 9216 unsigned char **bitstream, /* (i/o) on entrance pointer to 9217 place in bitstream to 9218 unpack new data from, on 9219 exit pointer to place in 9220 bitstream to unpack future 9221 data from */ 9222 int *index, /* (o) resulting value */ 9223 int bitno, /* (i) number of bits used to 9224 represent the value */ 9225 int *pos /* (i/o) read position in the 9226 current byte */ 9227 ){ 9228 int BitsLeft; 9230 *index=0; 9232 while (bitno>0) { 9234 /* move forward in bitstream when the end of the 9235 byte is reached */ 9237 if (*pos==8) { 9238 *pos=0; 9239 (*bitstream)++; 9240 } 9242 BitsLeft=8-(*pos); 9244 /* Extract bits to index */ 9246 Andersen et. al. Experimental - Expires November 29th, 2004 165 9247 Internet Low Bit Rate Codec May 04 9249 if (BitsLeft>=bitno) { 9250 *index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno)); 9252 *pos+=bitno; 9253 bitno=0; 9254 } else { 9256 if ((8-bitno)>0) { 9257 *index+=((((**bitstream)<<(*pos)) & 0xFF)>> 9258 (8-bitno)); 9259 *pos=8; 9260 } else { 9261 *index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<< 9262 (bitno-8)); 9263 *pos=8; 9264 } 9265 bitno-=BitsLeft; 9266 } 9267 } 9268 } 9270 A.43 StateConstructW.h 9272 /****************************************************************** 9274 iLBC Speech Coder ANSI-C Source Code 9276 StateConstructW.h 9278 Copyright (C) The Internet Society (2004). 9279 All Rights Reserved. 9281 ******************************************************************/ 9283 #ifndef __iLBC_STATECONSTRUCTW_H 9284 #define __iLBC_STATECONSTRUCTW_H 9286 void StateConstructW( 9287 int idxForMax, /* (i) 6-bit index for the quantization of 9288 max amplitude */ 9289 int *idxVec, /* (i) vector of quantization indexes */ 9290 float *syntDenum, /* (i) synthesis filter denumerator */ 9291 float *out, /* (o) the decoded state vector */ 9292 int len /* (i) length of a state vector */ 9293 ); 9295 #endif 9297 A.44 StateConstructW.c 9299 /****************************************************************** 9301 Andersen et. al. Experimental - Expires November 29th, 2004 166 9302 Internet Low Bit Rate Codec May 04 9304 iLBC Speech Coder ANSI-C Source Code 9306 StateConstructW.c 9308 Copyright (C) The Internet Society (2004). 9309 All Rights Reserved. 9311 ******************************************************************/ 9313 #include 9314 #include 9316 #include "iLBC_define.h" 9317 #include "constants.h" 9318 #include "filter.h" 9320 /*----------------------------------------------------------------* 9321 * decoding of the start state 9322 *---------------------------------------------------------------*/ 9324 void StateConstructW( 9325 int idxForMax, /* (i) 6-bit index for the quantization of 9326 max amplitude */ 9327 int *idxVec, /* (i) vector of quantization indexes */ 9328 float *syntDenum, /* (i) synthesis filter denumerator */ 9329 float *out, /* (o) the decoded state vector */ 9330 int len /* (i) length of a state vector */ 9331 ){ 9332 float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp, 9333 numerator[LPC_FILTERORDER+1]; 9334 float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout; 9335 int k,tmpi; 9337 /* decoding of the maximum value */ 9339 maxVal = state_frgqTbl[idxForMax]; 9340 maxVal = (float)pow(10,maxVal)/(float)4.5; 9342 /* initialization of buffers and coefficients */ 9344 memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float)); 9345 memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float)); 9346 for (k=0; k 9438 #include 9440 #include "iLBC_define.h" 9441 #include "constants.h" 9442 #include "filter.h" 9443 #include "helpfun.h" 9445 /*----------------------------------------------------------------* 9446 * predictive noise shaping encoding of scaled start state 9447 * (subrutine for StateSearchW) 9448 *---------------------------------------------------------------*/ 9450 void AbsQuantW( 9451 iLBC_Enc_Inst_t *iLBCenc_inst, 9452 /* (i) Encoder instance */ 9453 float *in, /* (i) vector to encode */ 9454 float *syntDenum, /* (i) denominator of synthesis filter */ 9455 float *weightDenum, /* (i) denominator of weighting filter */ 9456 int *out, /* (o) vector of quantizer indexes */ 9457 int len, /* (i) length of vector to encode and 9458 vector of quantizer indexes */ 9459 int state_first /* (i) position of start state in the 9460 80 vec */ 9461 ){ 9462 float *syntOut; 9463 float syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS]; 9464 float toQ, xq; 9465 int n; 9466 int index; 9468 /* initialization of buffer for filtering */ 9470 memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float)); 9472 Andersen et. al. Experimental - Expires November 29th, 2004 169 9473 Internet Low Bit Rate Codec May 04 9475 /* initialization of pointer for filtering */ 9477 syntOut = &syntOutBuf[LPC_FILTERORDER]; 9479 /* synthesis and weighting filters on input */ 9481 if (state_first) { 9482 AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER); 9483 } else { 9484 AllPoleFilter (in, weightDenum, 9485 iLBCenc_inst->state_short_len-SUBL, 9486 LPC_FILTERORDER); 9487 } 9489 /* encoding loop */ 9491 for (n=0; nstate_short_len-SUBL))) { 9505 syntDenum += (LPC_FILTERORDER+1); 9506 weightDenum += (LPC_FILTERORDER+1); 9508 /* synthesis and weighting filters on input */ 9509 AllPoleFilter (&in[n], weightDenum, len-n, 9510 LPC_FILTERORDER); 9512 } 9514 /* prediction of synthesized and weighted input */ 9516 syntOut[n] = 0.0; 9517 AllPoleFilter (&syntOut[n], weightDenum, 1, 9518 LPC_FILTERORDER); 9520 /* quantization */ 9522 toQ = in[n]-syntOut[n]; 9523 sort_sq(&xq, &index, toQ, state_sq3Tbl, 8); 9524 out[n]=index; 9525 syntOut[n] = state_sq3Tbl[out[n]]; 9527 /* update of the prediction filter */ 9529 Andersen et. al. Experimental - Expires November 29th, 2004 170 9530 Internet Low Bit Rate Codec May 04 9532 AllPoleFilter(&syntOut[n], weightDenum, 1, 9533 LPC_FILTERORDER); 9534 } 9535 } 9537 /*----------------------------------------------------------------* 9538 * encoding of start state 9539 *---------------------------------------------------------------*/ 9541 void StateSearchW( 9542 iLBC_Enc_Inst_t *iLBCenc_inst, 9543 /* (i) Encoder instance */ 9544 float *residual,/* (i) target residual vector */ 9545 float *syntDenum, /* (i) lpc synthesis filter */ 9546 float *weightDenum, /* (i) weighting filter denuminator */ 9547 int *idxForMax, /* (o) quantizer index for maximum 9548 amplitude */ 9549 int *idxVec, /* (o) vector of quantization indexes */ 9550 int len, /* (i) length of all vectors */ 9551 int state_first /* (i) position of start state in the 9552 80 vec */ 9553 ){ 9554 float dtmp, maxVal; 9555 float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS]; 9556 float *tmp, numerator[1+LPC_FILTERORDER]; 9557 float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout; 9558 int k; 9559 float qmax, scal; 9561 /* initialization of buffers and filter coefficients */ 9563 memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float)); 9564 memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float)); 9565 for (k=0; k maxVal*maxVal){ 9592 maxVal = fout[k]; 9593 } 9594 } 9595 maxVal=(float)fabs(maxVal); 9597 /* encoding of the maximum amplitude value */ 9599 if (maxVal < 10.0) { 9600 maxVal = 10.0; 9601 } 9602 maxVal = (float)log10(maxVal); 9603 sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64); 9605 /* decoding of the maximum amplitude representation value, 9606 and corresponding scaling of start state */ 9608 maxVal=state_frgqTbl[*idxForMax]; 9609 qmax = (float)pow(10,maxVal); 9610 scal = (float)(4.5)/qmax; 9611 for (k=0; k