wok-6.x annotate asterisk/stuff/rfc3951.txt @ rev 12828

zlib: first x86_64 package :-)
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 22 14:21:52 2012 +0200 (2012-05-22)
parents
children
rev   line source
pascal@12756 1
pascal@12756 2
pascal@12756 3
pascal@12756 4
pascal@12756 5
pascal@12756 6
pascal@12756 7 Network Working Group S. Andersen
pascal@12756 8 Request for Comments: 3951 Aalborg University
pascal@12756 9 Category: Experimental A. Duric
pascal@12756 10 Telio
pascal@12756 11 H. Astrom
pascal@12756 12 R. Hagen
pascal@12756 13 W. Kleijn
pascal@12756 14 J. Linden
pascal@12756 15 Global IP Sound
pascal@12756 16 December 2004
pascal@12756 17
pascal@12756 18
pascal@12756 19 Internet Low Bit Rate Codec (iLBC)
pascal@12756 20
pascal@12756 21 Status of this Memo
pascal@12756 22
pascal@12756 23 This memo defines an Experimental Protocol for the Internet
pascal@12756 24 community. It does not specify an Internet standard of any kind.
pascal@12756 25 Discussion and suggestions for improvement are requested.
pascal@12756 26 Distribution of this memo is unlimited.
pascal@12756 27
pascal@12756 28 Copyright Notice
pascal@12756 29
pascal@12756 30 Copyright (C) The Internet Society (2004).
pascal@12756 31
pascal@12756 32 Abstract
pascal@12756 33
pascal@12756 34 This document specifies a speech codec suitable for robust voice
pascal@12756 35 communication over IP. The codec is developed by Global IP Sound
pascal@12756 36 (GIPS). It is designed for narrow band speech and results in a
pascal@12756 37 payload bit rate of 13.33 kbit/s for 30 ms frames and 15.20 kbit/s
pascal@12756 38 for 20 ms frames. The codec enables graceful speech quality
pascal@12756 39 degradation in the case of lost frames, which occurs in connection
pascal@12756 40 with lost or delayed IP packets.
pascal@12756 41
pascal@12756 42
pascal@12756 43
pascal@12756 44
pascal@12756 45
pascal@12756 46
pascal@12756 47
pascal@12756 48
pascal@12756 49
pascal@12756 50
pascal@12756 51
pascal@12756 52
pascal@12756 53
pascal@12756 54
pascal@12756 55
pascal@12756 56
pascal@12756 57
pascal@12756 58 Andersen, et al. Experimental [Page 1]
pascal@12756 59
pascal@12756 60 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 61
pascal@12756 62
pascal@12756 63 Table of Contents
pascal@12756 64
pascal@12756 65 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4
pascal@12756 66 2. Outline of the Codec . . . . . . . . . . . . . . . . . . . . . 5
pascal@12756 67 2.1. Encoder. . . . . . . . . . . . . . . . . . . . . . . . . 5
pascal@12756 68 2.2. Decoder. . . . . . . . . . . . . . . . . . . . . . . . . 7
pascal@12756 69 3. Encoder Principles . . . . . . . . . . . . . . . . . . . . . . 7
pascal@12756 70 3.1. Pre-processing . . . . . . . . . . . . . . . . . . . . . 9
pascal@12756 71 3.2. LPC Analysis and Quantization. . . . . . . . . . . . . . 9
pascal@12756 72 3.2.1. Computation of Autocorrelation Coefficients. . . 10
pascal@12756 73 3.2.2. Computation of LPC Coefficients. . . . . . . . . 11
pascal@12756 74 3.2.3. Computation of LSF Coefficients from LPC
pascal@12756 75 Coefficients . . . . . . . . . . . . . . . . . . 11
pascal@12756 76 3.2.4. Quantization of LSF Coefficients . . . . . . . . 12
pascal@12756 77 3.2.5. Stability Check of LSF Coefficients. . . . . . . 13
pascal@12756 78 3.2.6. Interpolation of LSF Coefficients. . . . . . . . 13
pascal@12756 79 3.2.7. LPC Analysis and Quantization for 20 ms Frames . 14
pascal@12756 80 3.3. Calculation of the Residual. . . . . . . . . . . . . . . 15
pascal@12756 81 3.4. Perceptual Weighting Filter. . . . . . . . . . . . . . . 15
pascal@12756 82 3.5. Start State Encoder. . . . . . . . . . . . . . . . . . . 15
pascal@12756 83 3.5.1. Start State Estimation . . . . . . . . . . . . . 16
pascal@12756 84 3.5.2. All-Pass Filtering and Scale Quantization. . . . 17
pascal@12756 85 3.5.3. Scalar Quantization. . . . . . . . . . . . . . . 18
pascal@12756 86 3.6. Encoding the Remaining Samples . . . . . . . . . . . . . 19
pascal@12756 87 3.6.1. Codebook Memory. . . . . . . . . . . . . . . . . 20
pascal@12756 88 3.6.2. Perceptual Weighting of Codebook Memory
pascal@12756 89 and Target . . . . . . . . . . . . . . . . . . . 22
pascal@12756 90 3.6.3. Codebook Creation. . . . . . . . . . . . . . . . 23
pascal@12756 91 3.6.3.1. Creation of a Base Codebook . . . . . . 23
pascal@12756 92 3.6.3.2. Codebook Expansion. . . . . . . . . . . 24
pascal@12756 93 3.6.3.3. Codebook Augmentation . . . . . . . . . 24
pascal@12756 94 3.6.4. Codebook Search. . . . . . . . . . . . . . . . . 26
pascal@12756 95 3.6.4.1. Codebook Search at Each Stage . . . . . 26
pascal@12756 96 3.6.4.2. Gain Quantization at Each Stage . . . . 27
pascal@12756 97 3.6.4.3. Preparation of Target for Next Stage. . 28
pascal@12756 98 3.7. Gain Correction Encoding . . . . . . . . . . . . . . . . 28
pascal@12756 99 3.8. Bitstream Definition . . . . . . . . . . . . . . . . . . 29
pascal@12756 100 4. Decoder Principles . . . . . . . . . . . . . . . . . . . . . . 32
pascal@12756 101 4.1. LPC Filter Reconstruction. . . . . . . . . . . . . . . . 33
pascal@12756 102 4.2. Start State Reconstruction . . . . . . . . . . . . . . . 33
pascal@12756 103 4.3. Excitation Decoding Loop . . . . . . . . . . . . . . . . 34
pascal@12756 104 4.4. Multistage Adaptive Codebook Decoding. . . . . . . . . . 35
pascal@12756 105 4.4.1. Construction of the Decoded Excitation Signal. . 35
pascal@12756 106 4.5. Packet Loss Concealment. . . . . . . . . . . . . . . . . 35
pascal@12756 107 4.5.1. Block Received Correctly and Previous Block
pascal@12756 108 Also Received. . . . . . . . . . . . . . . . . . 35
pascal@12756 109 4.5.2. Block Not Received . . . . . . . . . . . . . . . 36
pascal@12756 110
pascal@12756 111
pascal@12756 112
pascal@12756 113
pascal@12756 114 Andersen, et al. Experimental [Page 2]
pascal@12756 115
pascal@12756 116 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 117
pascal@12756 118
pascal@12756 119 4.5.3. Block Received Correctly When Previous Block
pascal@12756 120 Not Received . . . . . . . . . . . . . . . . . . 36
pascal@12756 121 4.6. Enhancement. . . . . . . . . . . . . . . . . . . . . . . 37
pascal@12756 122 4.6.1. Estimating the Pitch . . . . . . . . . . . . . . 39
pascal@12756 123 4.6.2. Determination of the Pitch-Synchronous
pascal@12756 124 Sequences. . . . . . . . . . . . . . . . . . . . 39
pascal@12756 125 4.6.3. Calculation of the Smoothed Excitation . . . . . 41
pascal@12756 126 4.6.4. Enhancer Criterion . . . . . . . . . . . . . . . 41
pascal@12756 127 4.6.5. Enhancing the Excitation . . . . . . . . . . . . 42
pascal@12756 128 4.7. Synthesis Filtering. . . . . . . . . . . . . . . . . . . 43
pascal@12756 129 4.8. Post Filtering . . . . . . . . . . . . . . . . . . . . . 43
pascal@12756 130 5. Security Considerations. . . . . . . . . . . . . . . . . . . . 43
pascal@12756 131 6. Evaluation of the iLBC Implementations . . . . . . . . . . . . 43
pascal@12756 132 7. References . . . . . . . . . . . . . . . . . . . . . . . . . . 43
pascal@12756 133 7.1. Normative References . . . . . . . . . . . . . . . . . . 43
pascal@12756 134 7.2. Informative References . . . . . . . . . . . . . . . . . 44
pascal@12756 135 8. ACKNOWLEDGEMENTS . . . . . . . . . . . . . . . . . . . . . . . 44
pascal@12756 136 APPENDIX A: Reference Implementation . . . . . . . . . . . . . . . 45
pascal@12756 137 A.1. iLBC_test.c. . . . . . . . . . . . . . . . . . . . . . . 46
pascal@12756 138 A.2 iLBC_encode.h. . . . . . . . . . . . . . . . . . . . . . 52
pascal@12756 139 A.3. iLBC_encode.c. . . . . . . . . . . . . . . . . . . . . . 53
pascal@12756 140 A.4. iLBC_decode.h. . . . . . . . . . . . . . . . . . . . . . 63
pascal@12756 141 A.5. iLBC_decode.c. . . . . . . . . . . . . . . . . . . . . . 64
pascal@12756 142 A.6. iLBC_define.h. . . . . . . . . . . . . . . . . . . . . . 76
pascal@12756 143 A.7. constants.h. . . . . . . . . . . . . . . . . . . . . . . 80
pascal@12756 144 A.8. constants.c. . . . . . . . . . . . . . . . . . . . . . . 82
pascal@12756 145 A.9. anaFilter.h. . . . . . . . . . . . . . . . . . . . . . . 96
pascal@12756 146 A.10. anaFilter.c. . . . . . . . . . . . . . . . . . . . . . . 97
pascal@12756 147 A.11. createCB.h . . . . . . . . . . . . . . . . . . . . . . . 98
pascal@12756 148 A.12. createCB.c . . . . . . . . . . . . . . . . . . . . . . . 99
pascal@12756 149 A.13. doCPLC.h . . . . . . . . . . . . . . . . . . . . . . . .104
pascal@12756 150 A.14. doCPLC.c . . . . . . . . . . . . . . . . . . . . . . . .104
pascal@12756 151 A.15. enhancer.h . . . . . . . . . . . . . . . . . . . . . . .109
pascal@12756 152 A.16. enhancer.c . . . . . . . . . . . . . . . . . . . . . . .110
pascal@12756 153 A.17. filter.h . . . . . . . . . . . . . . . . . . . . . . . .123
pascal@12756 154 A.18. filter.c . . . . . . . . . . . . . . . . . . . . . . . .125
pascal@12756 155 A.19. FrameClassify.h. . . . . . . . . . . . . . . . . . . . .128
pascal@12756 156 A.20. FrameClassify.c. . . . . . . . . . . . . . . . . . . . .129
pascal@12756 157 A.21. gainquant.h. . . . . . . . . . . . . . . . . . . . . . .131
pascal@12756 158 A.22. gainquant.c. . . . . . . . . . . . . . . . . . . . . . .131
pascal@12756 159 A.23. getCBvec.h . . . . . . . . . . . . . . . . . . . . . . .134
pascal@12756 160 A.24. getCBvec.c . . . . . . . . . . . . . . . . . . . . . . .134
pascal@12756 161 A.25. helpfun.h. . . . . . . . . . . . . . . . . . . . . . . .138
pascal@12756 162 A.26. helpfun.c. . . . . . . . . . . . . . . . . . . . . . . .140
pascal@12756 163 A.27. hpInput.h. . . . . . . . . . . . . . . . . . . . . . . .146
pascal@12756 164 A.28. hpInput.c. . . . . . . . . . . . . . . . . . . . . . . .146
pascal@12756 165 A.29. hpOutput.h . . . . . . . . . . . . . . . . . . . . . . .148
pascal@12756 166 A.30. hpOutput.c . . . . . . . . . . . . . . . . . . . . . . .148
pascal@12756 167
pascal@12756 168
pascal@12756 169
pascal@12756 170 Andersen, et al. Experimental [Page 3]
pascal@12756 171
pascal@12756 172 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 173
pascal@12756 174
pascal@12756 175 A.31. iCBConstruct.h . . . . . . . . . . . . . . . . . . . . .149
pascal@12756 176 A.32. iCBConstruct.c . . . . . . . . . . . . . . . . . . . . .150
pascal@12756 177 A.33. iCBSearch.h. . . . . . . . . . . . . . . . . . . . . . .152
pascal@12756 178 A.34. iCBSearch.c. . . . . . . . . . . . . . . . . . . . . . .153
pascal@12756 179 A.35. LPCdecode.h. . . . . . . . . . . . . . . . . . . . . . .163
pascal@12756 180 A.36. LPCdecode.c. . . . . . . . . . . . . . . . . . . . . . .164
pascal@12756 181 A.37. LPCencode.h. . . . . . . . . . . . . . . . . . . . . . .167
pascal@12756 182 A.38. LPCencode.c. . . . . . . . . . . . . . . . . . . . . . .167
pascal@12756 183 A.39. lsf.h. . . . . . . . . . . . . . . . . . . . . . . . . .172
pascal@12756 184 A.40. lsf.c. . . . . . . . . . . . . . . . . . . . . . . . . .172
pascal@12756 185 A.41. packing.h. . . . . . . . . . . . . . . . . . . . . . . .178
pascal@12756 186 A.42. packing.c. . . . . . . . . . . . . . . . . . . . . . . .179
pascal@12756 187 A.43. StateConstructW.h. . . . . . . . . . . . . . . . . . . .182
pascal@12756 188 A.44. StateConstructW.c. . . . . . . . . . . . . . . . . . . .183
pascal@12756 189 A.45. StateSearchW.h . . . . . . . . . . . . . . . . . . . . .185
pascal@12756 190 A.46. StateSearchW.c . . . . . . . . . . . . . . . . . . . . .186
pascal@12756 191 A.47. syntFilter.h . . . . . . . . . . . . . . . . . . . . . .190
pascal@12756 192 A.48. syntFilter.c . . . . . . . . . . . . . . . . . . . . . .190
pascal@12756 193 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . .192
pascal@12756 194 Full Copyright Statement . . . . . . . . . . . . . . . . . . . . .194
pascal@12756 195
pascal@12756 196 1. Introduction
pascal@12756 197
pascal@12756 198 This document contains the description of an algorithm for the coding
pascal@12756 199 of speech signals sampled at 8 kHz. The algorithm, called iLBC, uses
pascal@12756 200 a block-independent linear-predictive coding (LPC) algorithm and has
pascal@12756 201 support for two basic frame lengths: 20 ms at 15.2 kbit/s and 30 ms
pascal@12756 202 at 13.33 kbit/s. When the codec operates at block lengths of 20 ms,
pascal@12756 203 it produces 304 bits per block, which SHOULD be packetized as in [1].
pascal@12756 204 Similarly, for block lengths of 30 ms it produces 400 bits per block,
pascal@12756 205 which SHOULD be packetized as in [1]. The two modes for the
pascal@12756 206 different frame sizes operate in a very similar way. When they
pascal@12756 207 differ it is explicitly stated in the text, usually with the notation
pascal@12756 208 x/y, where x refers to the 20 ms mode and y refers to the 30 ms mode.
pascal@12756 209
pascal@12756 210 The described algorithm results in a speech coding system with a
pascal@12756 211 controlled response to packet losses similar to what is known from
pascal@12756 212 pulse code modulation (PCM) with packet loss concealment (PLC), such
pascal@12756 213 as the ITU-T G.711 standard [4], which operates at a fixed bit rate
pascal@12756 214 of 64 kbit/s. At the same time, the described algorithm enables
pascal@12756 215 fixed bit rate coding with a quality-versus-bit rate tradeoff close
pascal@12756 216 to state-of-the-art. A suitable RTP payload format for the iLBC
pascal@12756 217 codec is specified in [1].
pascal@12756 218
pascal@12756 219 Some of the applications for which this coder is suitable are real
pascal@12756 220 time communications such as telephony and videoconferencing,
pascal@12756 221 streaming audio, archival, and messaging.
pascal@12756 222
pascal@12756 223
pascal@12756 224
pascal@12756 225
pascal@12756 226 Andersen, et al. Experimental [Page 4]
pascal@12756 227
pascal@12756 228 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 229
pascal@12756 230
pascal@12756 231 Cable Television Laboratories (CableLabs(R)) has adopted iLBC as a
pascal@12756 232 mandatory PacketCable(TM) audio codec standard for VoIP over Cable
pascal@12756 233 applications [3].
pascal@12756 234
pascal@12756 235 This document is organized as follows. Section 2 gives a brief
pascal@12756 236 outline of the codec. The specific encoder and decoder algorithms
pascal@12756 237 are explained in sections 3 and 4, respectively. Appendix A provides
pascal@12756 238 a c-code reference implementation.
pascal@12756 239
pascal@12756 240 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
pascal@12756 241 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
pascal@12756 242 document are to be interpreted as described in BCP 14, RFC 2119 [2].
pascal@12756 243
pascal@12756 244 2. Outline of the Codec
pascal@12756 245
pascal@12756 246 The codec consists of an encoder and a decoder as described in
pascal@12756 247 sections 2.1 and 2.2, respectively.
pascal@12756 248
pascal@12756 249 The essence of the codec is LPC and block-based coding of the LPC
pascal@12756 250 residual signal. For each 160/240 (20 ms/30 ms) sample block, the
pascal@12756 251 following major steps are performed: A set of LPC filters are
pascal@12756 252 computed, and the speech signal is filtered through them to produce
pascal@12756 253 the residual signal. The codec uses scalar quantization of the
pascal@12756 254 dominant part, in terms of energy, of the residual signal for the
pascal@12756 255 block. The dominant state is of length 57/58 (20 ms/30 ms) samples
pascal@12756 256 and forms a start state for dynamic codebooks constructed from the
pascal@12756 257 already coded parts of the residual signal. These dynamic codebooks
pascal@12756 258 are used to code the remaining parts of the residual signal. By this
pascal@12756 259 method, coding independence between blocks is achieved, resulting in
pascal@12756 260 elimination of propagation of perceptual degradations due to packet
pascal@12756 261 loss. The method facilitates high-quality packet loss concealment
pascal@12756 262 (PLC).
pascal@12756 263
pascal@12756 264 2.1. Encoder
pascal@12756 265
pascal@12756 266 The input to the encoder SHOULD be 16 bit uniform PCM sampled at 8
pascal@12756 267 kHz. It SHOULD be partitioned into blocks of BLOCKL=160/240 samples
pascal@12756 268 for the 20/30 ms frame size. Each block is divided into NSUB=4/6
pascal@12756 269 consecutive sub-blocks of SUBL=40 samples each. For 30 ms frame
pascal@12756 270 size, the encoder performs two LPC_FILTERORDER=10 linear-predictive
pascal@12756 271 coding (LPC) analyses. The first analysis applies a smooth window
pascal@12756 272 centered over the second sub-block and extending to the middle of the
pascal@12756 273 fifth sub-block. The second LPC analysis applies a smooth asymmetric
pascal@12756 274 window centered over the fifth sub-block and extending to the end of
pascal@12756 275 the sixth sub-block. For 20 ms frame size, one LPC_FILTERORDER=10
pascal@12756 276 linear-predictive coding (LPC) analysis is performed with a smooth
pascal@12756 277 window centered over the third sub-frame.
pascal@12756 278
pascal@12756 279
pascal@12756 280
pascal@12756 281
pascal@12756 282 Andersen, et al. Experimental [Page 5]
pascal@12756 283
pascal@12756 284 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 285
pascal@12756 286
pascal@12756 287 For each of the LPC analyses, a set of line-spectral frequencies
pascal@12756 288 (LSFs) are obtained, quantized, and interpolated to obtain LSF
pascal@12756 289 coefficients for each sub-block. Subsequently, the LPC residual is
pascal@12756 290 computed by using the quantized and interpolated LPC analysis
pascal@12756 291 filters.
pascal@12756 292
pascal@12756 293 The two consecutive sub-blocks of the residual exhibiting the maximal
pascal@12756 294 weighted energy are identified. Within these two sub-blocks, the
pascal@12756 295 start state (segment) is selected from two choices: the first 57/58
pascal@12756 296 samples or the last 57/58 samples of the two consecutive sub-blocks.
pascal@12756 297 The selected segment is the one of higher energy. The start state is
pascal@12756 298 encoded with scalar quantization.
pascal@12756 299
pascal@12756 300 A dynamic codebook encoding procedure is used to encode 1) the 23/22
pascal@12756 301 (20 ms/30 ms) remaining samples in the two sub-blocks containing the
pascal@12756 302 start state; 2) the sub-blocks after the start state in time; and 3)
pascal@12756 303 the sub-blocks before the start state in time. Thus, the encoding
pascal@12756 304 target can be either the 23/22 samples remaining of the two sub-
pascal@12756 305 blocks containing the start state or a 40-sample sub-block. This
pascal@12756 306 target can consist of samples indexed forward in time or backward in
pascal@12756 307 time, depending on the location of the start state.
pascal@12756 308
pascal@12756 309 The codebook coding is based on an adaptive codebook built from a
pascal@12756 310 codebook memory that contains decoded LPC excitation samples from the
pascal@12756 311 already encoded part of the block. These samples are indexed in the
pascal@12756 312 same time direction as the target vector, ending at the sample
pascal@12756 313 instant prior to the first sample instant represented in the target
pascal@12756 314 vector. The codebook is used in CB_NSTAGES=3 stages in a successive
pascal@12756 315 refinement approach, and the resulting three code vector gains are
pascal@12756 316 encoded with 5-, 4-, and 3-bit scalar quantization, respectively.
pascal@12756 317
pascal@12756 318 The codebook search method employs noise shaping derived from the LPC
pascal@12756 319 filters, and the main decision criterion is to minimize the squared
pascal@12756 320 error between the target vector and the code vectors. Each code
pascal@12756 321 vector in this codebook comes from one of CB_EXPAND=2 codebook
pascal@12756 322 sections. The first section is filled with delayed, already encoded
pascal@12756 323 residual vectors. The code vectors of the second codebook section
pascal@12756 324 are constructed by predefined linear combinations of vectors in the
pascal@12756 325 first section of the codebook.
pascal@12756 326
pascal@12756 327 As codebook encoding with squared-error matching is known to produce
pascal@12756 328 a coded signal of less power than does the scalar quantized start
pascal@12756 329 state signal, a gain re-scaling method is implemented by a refined
pascal@12756 330 search for a better set of codebook gains in terms of power matching
pascal@12756 331 after encoding. This is done by searching for a higher value of the
pascal@12756 332 gain factor for the first stage codebook, as the subsequent stage
pascal@12756 333 codebook gains are scaled by the first stage gain.
pascal@12756 334
pascal@12756 335
pascal@12756 336
pascal@12756 337
pascal@12756 338 Andersen, et al. Experimental [Page 6]
pascal@12756 339
pascal@12756 340 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 341
pascal@12756 342
pascal@12756 343 2.2. Decoder
pascal@12756 344
pascal@12756 345 Typically for packet communications, a jitter buffer placed at the
pascal@12756 346 receiving end decides whether the packet containing an encoded signal
pascal@12756 347 block has been received or lost. This logic is not part of the codec
pascal@12756 348 described here. For each encoded signal block received the decoder
pascal@12756 349 performs a decoding. For each lost signal block, the decoder
pascal@12756 350 performs a PLC operation.
pascal@12756 351
pascal@12756 352 The decoding for each block starts by decoding and interpolating the
pascal@12756 353 LPC coefficients. Subsequently the start state is decoded.
pascal@12756 354
pascal@12756 355 For codebook-encoded segments, each segment is decoded by
pascal@12756 356 constructing the three code vectors given by the received codebook
pascal@12756 357 indices in the same way that the code vectors were constructed in the
pascal@12756 358 encoder. The three gain factors are also decoded and the resulting
pascal@12756 359 decoded signal is given by the sum of the three codebook vectors
pascal@12756 360 scaled with respective gain.
pascal@12756 361
pascal@12756 362 An enhancement algorithm is applied to the reconstructed excitation
pascal@12756 363 signal. This enhancement augments the periodicity of voiced speech
pascal@12756 364 regions. The enhancement is optimized under the constraint that the
pascal@12756 365 modification signal (defined as the difference between the enhanced
pascal@12756 366 excitation and the excitation signal prior to enhancement) has a
pascal@12756 367 short-time energy that does not exceed a preset fraction of the
pascal@12756 368 short-time energy of the excitation signal prior to enhancement.
pascal@12756 369
pascal@12756 370 A packet loss concealment (PLC) operation is easily embedded in the
pascal@12756 371 decoder. The PLC operation can, e.g., be based on repeating LPC
pascal@12756 372 filters and obtaining the LPC residual signal by using a long-term
pascal@12756 373 prediction estimate from previous residual blocks.
pascal@12756 374
pascal@12756 375 3. Encoder Principles
pascal@12756 376
pascal@12756 377 The following block diagram is an overview of all the components of
pascal@12756 378 the iLBC encoding procedure. The description of the blocks contains
pascal@12756 379 references to the section where that particular procedure is further
pascal@12756 380 described.
pascal@12756 381
pascal@12756 382
pascal@12756 383
pascal@12756 384
pascal@12756 385
pascal@12756 386
pascal@12756 387
pascal@12756 388
pascal@12756 389
pascal@12756 390
pascal@12756 391
pascal@12756 392
pascal@12756 393
pascal@12756 394 Andersen, et al. Experimental [Page 7]
pascal@12756 395
pascal@12756 396 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 397
pascal@12756 398
pascal@12756 399 +-----------+ +---------+ +---------+
pascal@12756 400 speech -> | 1. Pre P | -> | 2. LPC | -> | 3. Ana | ->
pascal@12756 401 +-----------+ +---------+ +---------+
pascal@12756 402
pascal@12756 403 +---------------+ +--------------+
pascal@12756 404 -> | 4. Start Sel | ->| 5. Scalar Qu | ->
pascal@12756 405 +---------------+ +--------------+
pascal@12756 406
pascal@12756 407 +--------------+ +---------------+
pascal@12756 408 -> |6. CB Search | -> | 7. Packetize | -> payload
pascal@12756 409 | +--------------+ | +---------------+
pascal@12756 410 ----<---------<------
pascal@12756 411 sub-frame 0..2/4 (20 ms/30 ms)
pascal@12756 412
pascal@12756 413 Figure 3.1. Flow chart of the iLBC encoder
pascal@12756 414
pascal@12756 415 1. Pre-process speech with a HP filter, if needed (section 3.1).
pascal@12756 416
pascal@12756 417 2. Compute LPC parameters, quantize, and interpolate (section 3.2).
pascal@12756 418
pascal@12756 419 3. Use analysis filters on speech to compute residual (section 3.3).
pascal@12756 420
pascal@12756 421 4. Select position of 57/58-sample start state (section 3.5).
pascal@12756 422
pascal@12756 423 5. Quantize the 57/58-sample start state with scalar quantization
pascal@12756 424 (section 3.5).
pascal@12756 425
pascal@12756 426 6. Search the codebook for each sub-frame. Start with 23/22 sample
pascal@12756 427 block, then encode sub-blocks forward in time, and then encode
pascal@12756 428 sub-blocks backward in time. For each block, the steps in Figure
pascal@12756 429 3.4 are performed (section 3.6).
pascal@12756 430
pascal@12756 431 7. Packetize the bits into the payload specified in Table 3.2.
pascal@12756 432
pascal@12756 433 The input to the encoder SHOULD be 16-bit uniform PCM sampled at 8
pascal@12756 434 kHz. Also it SHOULD be partitioned into blocks of BLOCKL=160/240
pascal@12756 435 samples. Each block input to the encoder is divided into NSUB=4/6
pascal@12756 436 consecutive sub-blocks of SUBL=40 samples each.
pascal@12756 437
pascal@12756 438
pascal@12756 439
pascal@12756 440
pascal@12756 441
pascal@12756 442
pascal@12756 443
pascal@12756 444
pascal@12756 445
pascal@12756 446
pascal@12756 447
pascal@12756 448
pascal@12756 449
pascal@12756 450 Andersen, et al. Experimental [Page 8]
pascal@12756 451
pascal@12756 452 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 453
pascal@12756 454
pascal@12756 455 0 39 79 119 159
pascal@12756 456 +---------------------------------------+
pascal@12756 457 | 1 | 2 | 3 | 4 |
pascal@12756 458 +---------------------------------------+
pascal@12756 459 20 ms frame
pascal@12756 460
pascal@12756 461 0 39 79 119 159 199 239
pascal@12756 462 +-----------------------------------------------------------+
pascal@12756 463 | 1 | 2 | 3 | 4 | 5 | 6 |
pascal@12756 464 +-----------------------------------------------------------+
pascal@12756 465 30 ms frame
pascal@12756 466 Figure 3.2. One input block to the encoder for 20 ms (with four sub-
pascal@12756 467 frames) and 30 ms (with six sub-frames).
pascal@12756 468
pascal@12756 469 3.1. Pre-processing
pascal@12756 470
pascal@12756 471 In some applications, the recorded speech signal contains DC level
pascal@12756 472 and/or 50/60 Hz noise. If these components have not been removed
pascal@12756 473 prior to the encoder call, they should be removed by a high-pass
pascal@12756 474 filter. A reference implementation of this, using a filter with a
pascal@12756 475 cutoff frequency of 90 Hz, can be found in Appendix A.28.
pascal@12756 476
pascal@12756 477 3.2. LPC Analysis and Quantization
pascal@12756 478
pascal@12756 479 The input to the LPC analysis module is a possibly high-pass filtered
pascal@12756 480 speech buffer, speech_hp, that contains 240/300 (LPC_LOOKBACK +
pascal@12756 481 BLOCKL = 80/60 + 160/240 = 240/300) speech samples, where samples 0
pascal@12756 482 through 79/59 are from the previous block and samples 80/60 through
pascal@12756 483 239/299 are from the current block. No look-ahead into the next
pascal@12756 484 block is used. For the very first block processed, the look-back
pascal@12756 485 samples are assumed to be zeros.
pascal@12756 486
pascal@12756 487 For each input block, the LPC analysis calculates one/two set(s) of
pascal@12756 488 LPC_FILTERORDER=10 LPC filter coefficients using the autocorrelation
pascal@12756 489 method and the Levinson-Durbin recursion. These coefficients are
pascal@12756 490 converted to the Line Spectrum Frequency representation. In the 20
pascal@12756 491 ms case, the single lsf set represents the spectral characteristics
pascal@12756 492 as measured at the center of the third sub-block. For 30 ms frames,
pascal@12756 493 the first set, lsf1, represents the spectral properties of the input
pascal@12756 494 signal at the center of the second sub-block, and the other set,
pascal@12756 495 lsf2, represents the spectral characteristics as measured at the
pascal@12756 496 center of the fifth sub-block. The details of the computation for 30
pascal@12756 497 ms frames are described in sections 3.2.1 through 3.2.6. Section
pascal@12756 498 3.2.7 explains how the LPC Analysis and Quantization differs for 20
pascal@12756 499 ms frames.
pascal@12756 500
pascal@12756 501
pascal@12756 502
pascal@12756 503
pascal@12756 504
pascal@12756 505
pascal@12756 506 Andersen, et al. Experimental [Page 9]
pascal@12756 507
pascal@12756 508 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 509
pascal@12756 510
pascal@12756 511 3.2.1. Computation of Autocorrelation Coefficients
pascal@12756 512
pascal@12756 513 The first step in the LPC analysis procedure is to calculate
pascal@12756 514 autocorrelation coefficients by using windowed speech samples. This
pascal@12756 515 windowing is the only difference in the LPC analysis procedure for
pascal@12756 516 the two sets of coefficients. For the first set, a 240-sample-long
pascal@12756 517 standard symmetric Hanning window is applied to samples 0 through 239
pascal@12756 518 of the input data. The first window, lpc_winTbl, is defined as
pascal@12756 519
pascal@12756 520 lpc_winTbl[i]= 0.5 * (1.0 - cos((2*PI*(i+1))/(BLOCKL+1)));
pascal@12756 521 i=0,...,119
pascal@12756 522 lpc_winTbl[i] = winTbl[BLOCKL - i - 1]; i=120,...,239
pascal@12756 523
pascal@12756 524 The windowed speech speech_hp_win1 is then obtained by multiplying
pascal@12756 525 the first 240 samples of the input speech buffer with the window
pascal@12756 526 coefficients:
pascal@12756 527
pascal@12756 528 speech_hp_win1[i] = speech_hp[i] * lpc_winTbl[i];
pascal@12756 529 i=0,...,BLOCKL-1
pascal@12756 530
pascal@12756 531 From these 240 windowed speech samples, 11 (LPC_FILTERORDER + 1)
pascal@12756 532 autocorrelation coefficients, acf1, are calculated:
pascal@12756 533
pascal@12756 534 acf1[lag] += speech_hp_win1[n] * speech_hp_win1[n + lag];
pascal@12756 535 lag=0,...,LPC_FILTERORDER; n=0,...,BLOCKL-lag-1
pascal@12756 536
pascal@12756 537 In order to make the analysis more robust against numerical precision
pascal@12756 538 problems, a spectral smoothing procedure is applied by windowing the
pascal@12756 539 autocorrelation coefficients before the LPC coefficients are
pascal@12756 540 computed. Also, a white noise floor is added to the autocorrelation
pascal@12756 541 function by multiplying coefficient zero by 1.0001 (40dB below the
pascal@12756 542 energy of the windowed speech signal). These two steps are
pascal@12756 543 implemented by multiplying the autocorrelation coefficients with the
pascal@12756 544 following window:
pascal@12756 545
pascal@12756 546 lpc_lagwinTbl[0] = 1.0001;
pascal@12756 547 lpc_lagwinTbl[i] = exp(-0.5 * ((2 * PI * 60.0 * i) /FS)^2);
pascal@12756 548 i=1,...,LPC_FILTERORDER
pascal@12756 549 where FS=8000 is the sampling frequency
pascal@12756 550
pascal@12756 551 Then, the windowed acf function acf1_win is obtained by
pascal@12756 552
pascal@12756 553 acf1_win[i] = acf1[i] * lpc_lagwinTbl[i];
pascal@12756 554 i=0,...,LPC_FILTERORDER
pascal@12756 555
pascal@12756 556 The second set of autocorrelation coefficients, acf2_win, are
pascal@12756 557 obtained in a similar manner. The window, lpc_asymwinTbl, is applied
pascal@12756 558 to samples 60 through 299, i.e., the entire current block. The
pascal@12756 559
pascal@12756 560
pascal@12756 561
pascal@12756 562 Andersen, et al. Experimental [Page 10]
pascal@12756 563
pascal@12756 564 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 565
pascal@12756 566
pascal@12756 567 window consists of two segments, the first (samples 0 to 219) being
pascal@12756 568 half a Hanning window with length 440 and the second a quarter of a
pascal@12756 569 cycle of a cosine wave. By using this asymmetric window, an LPC
pascal@12756 570 analysis centered in the fifth sub-block is obtained without the need
pascal@12756 571 for any look-ahead, which would add delay. The asymmetric window is
pascal@12756 572 defined as
pascal@12756 573
pascal@12756 574 lpc_asymwinTbl[i] = (sin(PI * (i + 1) / 441))^2; i=0,...,219
pascal@12756 575
pascal@12756 576 lpc_asymwinTbl[i] = cos((i - 220) * PI / 40); i=220,...,239
pascal@12756 577
pascal@12756 578 and the windowed speech is computed by
pascal@12756 579
pascal@12756 580 speech_hp_win2[i] = speech_hp[i + LPC_LOOKBACK] *
pascal@12756 581 lpc_asymwinTbl[i]; i=0,....BLOCKL-1
pascal@12756 582
pascal@12756 583 The windowed autocorrelation coefficients are then obtained in
pascal@12756 584 exactly the same way as for the first analysis instance.
pascal@12756 585
pascal@12756 586 The generation of the windows lpc_winTbl, lpc_asymwinTbl, and
pascal@12756 587 lpc_lagwinTbl are typically done in advance, and the arrays are
pascal@12756 588 stored in ROM rather than repeating the calculation for every block.
pascal@12756 589
pascal@12756 590 3.2.2. Computation of LPC Coefficients
pascal@12756 591
pascal@12756 592 From the 2 x 11 smoothed autocorrelation coefficients, acf1_win and
pascal@12756 593 acf2_win, the 2 x 11 LPC coefficients, lp1 and lp2, are calculated
pascal@12756 594 in the same way for both analysis locations by using the well known
pascal@12756 595 Levinson-Durbin recursion. The first LPC coefficient is always 1.0,
pascal@12756 596 resulting in ten unique coefficients.
pascal@12756 597
pascal@12756 598 After determining the LPC coefficients, a bandwidth expansion
pascal@12756 599 procedure is applied to smooth the spectral peaks in the
pascal@12756 600 short-term spectrum. The bandwidth addition is obtained by the
pascal@12756 601 following modification of the LPC coefficients:
pascal@12756 602
pascal@12756 603 lp1_bw[i] = lp1[i] * chirp^i; i=0,...,LPC_FILTERORDER
pascal@12756 604 lp2_bw[i] = lp2[i] * chirp^i; i=0,...,LPC_FILTERORDER
pascal@12756 605
pascal@12756 606 where "chirp" is a real number between 0 and 1. It is RECOMMENDED to
pascal@12756 607 use a value of 0.9.
pascal@12756 608
pascal@12756 609 3.2.3. Computation of LSF Coefficients from LPC Coefficients
pascal@12756 610
pascal@12756 611 Thus far, two sets of LPC coefficients that represent the short-term
pascal@12756 612 spectral characteristics of the speech signal for two different time
pascal@12756 613 locations within the current block have been determined. These
pascal@12756 614 coefficients SHOULD be quantized and interpolated. Before this is
pascal@12756 615
pascal@12756 616
pascal@12756 617
pascal@12756 618 Andersen, et al. Experimental [Page 11]
pascal@12756 619
pascal@12756 620 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 621
pascal@12756 622
pascal@12756 623 done, it is advantageous to convert the LPC parameters into another
pascal@12756 624 type of representation called Line Spectral Frequencies (LSF). The
pascal@12756 625 LSF parameters are used because they are better suited for
pascal@12756 626 quantization and interpolation than the regular LPC coefficients.
pascal@12756 627 Many computationally efficient methods for calculating the LSFs from
pascal@12756 628 the LPC coefficients have been proposed in the literature. The
pascal@12756 629 detailed implementation of one applicable method can be found in
pascal@12756 630 Appendix A.26. The two arrays of LSF coefficients obtained, lsf1 and
pascal@12756 631 lsf2, are of dimension 10 (LPC_FILTERORDER).
pascal@12756 632
pascal@12756 633 3.2.4. Quantization of LSF Coefficients
pascal@12756 634
pascal@12756 635 Because the LPC filters defined by the two sets of LSFs are also
pascal@12756 636 needed in the decoder, the LSF parameters need to be quantized and
pascal@12756 637 transmitted as side information. The total number of bits required
pascal@12756 638 to represent the quantization of the two LSF representations for one
pascal@12756 639 block of speech is 40, with 20 bits used for each of lsf1 and lsf2.
pascal@12756 640
pascal@12756 641 For computational and storage reasons, the LSF vectors are quantized
pascal@12756 642 using three-split vector quantization (VQ). That is, the LSF vectors
pascal@12756 643 are split into three sub-vectors that are each quantized with a
pascal@12756 644 regular VQ. The quantized versions of lsf1 and lsf2, qlsf1 and
pascal@12756 645 qlsf2, are obtained by using the same memoryless split VQ. The
pascal@12756 646 length of each of these two LSF vectors is 10, and they are split
pascal@12756 647 into three sub-vectors containing 3, 3, and 4 values, respectively.
pascal@12756 648
pascal@12756 649 For each of the sub-vectors, a separate codebook of quantized values
pascal@12756 650 has been designed with a standard VQ training method for a large
pascal@12756 651 database containing speech from a large number of speakers recorded
pascal@12756 652 under various conditions. The size of each of the three codebooks
pascal@12756 653 associated with the split definitions above is
pascal@12756 654
pascal@12756 655 int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128};
pascal@12756 656
pascal@12756 657 The actual values of the vector quantization codebook that must be
pascal@12756 658 used can be found in the reference code of Appendix A. Both sets of
pascal@12756 659 LSF coefficients, lsf1 and lsf2, are quantized with a standard
pascal@12756 660 memoryless split vector quantization (VQ) structure using the squared
pascal@12756 661 error criterion in the LSF domain. The split VQ quantization
pascal@12756 662 consists of the following steps:
pascal@12756 663
pascal@12756 664 1) Quantize the first three LSF coefficients (1 - 3) with a VQ
pascal@12756 665 codebook of size 64.
pascal@12756 666 2) Quantize the next three LSF coefficients 4 - 6 with VQ a codebook
pascal@12756 667 of size 128.
pascal@12756 668 3) Quantize the last four LSF coefficients (7 - 10) with a VQ
pascal@12756 669 codebook of size 128.
pascal@12756 670
pascal@12756 671
pascal@12756 672
pascal@12756 673
pascal@12756 674 Andersen, et al. Experimental [Page 12]
pascal@12756 675
pascal@12756 676 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 677
pascal@12756 678
pascal@12756 679 This procedure, repeated for lsf1 and lsf2, gives six quantization
pascal@12756 680 indices and the quantized sets of LSF coefficients qlsf1 and qlsf2.
pascal@12756 681 Each set of three indices is encoded with 6 + 7 + 7 = 20 bits. The
pascal@12756 682 total number of bits used for LSF quantization in a block is thus 40
pascal@12756 683 bits.
pascal@12756 684
pascal@12756 685 3.2.5. Stability Check of LSF Coefficients
pascal@12756 686
pascal@12756 687 The LSF representation of the LPC filter has the convenient property
pascal@12756 688 that the coefficients are ordered by increasing value, i.e., lsf(n-1)
pascal@12756 689 < lsf(n), 0 < n < 10, if the corresponding synthesis filter is
pascal@12756 690 stable. As we are employing a split VQ scheme, it is possible that
pascal@12756 691 at the split boundaries the LSF coefficients are not ordered
pascal@12756 692 correctly and hence that the corresponding LP filter is unstable. To
pascal@12756 693 ensure that the filter used is stable, a stability check is performed
pascal@12756 694 for the quantized LSF vectors. If it turns out that the coefficients
pascal@12756 695 are not ordered appropriately (with a safety margin of 50 Hz to
pascal@12756 696 ensure that formant peaks are not too narrow), they will be moved
pascal@12756 697 apart. The detailed method for this can be found in Appendix A.40.
pascal@12756 698 The same procedure is performed in the decoder. This ensures that
pascal@12756 699 exactly the same LSF representations are used in both encoder and
pascal@12756 700 decoder.
pascal@12756 701
pascal@12756 702 3.2.6. Interpolation of LSF Coefficients
pascal@12756 703
pascal@12756 704 From the two sets of LSF coefficients that are computed for each
pascal@12756 705 block of speech, different LSFs are obtained for each sub-block by
pascal@12756 706 means of interpolation. This procedure is performed for the original
pascal@12756 707 LSFs (lsf1 and lsf2), as well as the quantized versions qlsf1 and
pascal@12756 708 qlsf2, as both versions are used in the encoder. Here follows a
pascal@12756 709 brief summary of the interpolation scheme; the details are found in
pascal@12756 710 the c-code of Appendix A. In the first sub-block, the average of the
pascal@12756 711 second LSF vector from the previous block and the first LSF vector in
pascal@12756 712 the current block is used. For sub-blocks two through five, the LSFs
pascal@12756 713 used are obtained by linear interpolation from lsf1 (and qlsf1) to
pascal@12756 714 lsf2 (and qlsf2), with lsf1 used in sub-block two and lsf2 in sub-
pascal@12756 715 block five. In the last sub-block, lsf2 is used. For the very first
pascal@12756 716 block it is assumed that the last LSF vector of the previous block is
pascal@12756 717 equal to a predefined vector, lsfmeanTbl, obtained by calculating the
pascal@12756 718 mean LSF vector of the LSF design database.
pascal@12756 719
pascal@12756 720 lsfmeanTbl[LPC_FILTERORDER] = {0.281738, 0.445801, 0.663330,
pascal@12756 721 0.962524, 1.251831, 1.533081, 1.850586, 2.137817,
pascal@12756 722 2.481445, 2.777344}
pascal@12756 723
pascal@12756 724
pascal@12756 725
pascal@12756 726
pascal@12756 727
pascal@12756 728
pascal@12756 729
pascal@12756 730 Andersen, et al. Experimental [Page 13]
pascal@12756 731
pascal@12756 732 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 733
pascal@12756 734
pascal@12756 735 The interpolation method is standard linear interpolation in the LSF
pascal@12756 736 domain. The interpolated LSF values are converted to LPC
pascal@12756 737 coefficients for each sub-block. The unquantized and quantized LPC
pascal@12756 738 coefficients form two sets of filters respectively. The unquantized
pascal@12756 739 analysis filter for sub-block k is defined as follows
pascal@12756 740
pascal@12756 741 ___
pascal@12756 742 \
pascal@12756 743 Ak(z)= 1 + > ak(i)*z^(-i)
pascal@12756 744 /__
pascal@12756 745 i=1...LPC_FILTERORDER
pascal@12756 746
pascal@12756 747 The quantized analysis filter for sub-block k is defined as follows
pascal@12756 748 ___
pascal@12756 749 \
pascal@12756 750 A~k(z)= 1 + > a~k(i)*z^(-i)
pascal@12756 751 /__
pascal@12756 752 i=1...LPC_FILTERORDER
pascal@12756 753
pascal@12756 754 A reference implementation of the lsf encoding is given in Appendix
pascal@12756 755 A.38. A reference implementation of the corresponding decoding can
pascal@12756 756 be found in Appendix A.36.
pascal@12756 757
pascal@12756 758 3.2.7. LPC Analysis and Quantization for 20 ms Frames
pascal@12756 759
pascal@12756 760 As previously stated, the codec only calculates one set of LPC
pascal@12756 761 parameters for the 20 ms frame size as opposed to two sets for 30 ms
pascal@12756 762 frames. A single set of autocorrelation coefficients is calculated
pascal@12756 763 on the LPC_LOOKBACK + BLOCKL = 80 + 160 = 240 samples. These samples
pascal@12756 764 are windowed with the asymmetric window lpc_asymwinTbl, centered over
pascal@12756 765 the third sub-frame, to form speech_hp_win. Autocorrelation
pascal@12756 766 coefficients, acf, are calculated on the 240 samples in speech_hp_win
pascal@12756 767 and then windowed exactly as in section 3.2.1 (resulting in
pascal@12756 768 acf_win).
pascal@12756 769
pascal@12756 770 This single set of windowed autocorrelation coefficients is used to
pascal@12756 771 calculate LPC coefficients, LSF coefficients, and quantized LSF
pascal@12756 772 coefficients in exactly the same manner as in sections 3.2.3 through
pascal@12756 773 3.2.4. As for the 30 ms frame size, the ten LSF coefficients are
pascal@12756 774 divided into three sub-vectors of size 3, 3, and 4 and quantized by
pascal@12756 775 using the same scheme and codebook as in section 3.2.4 to finally get
pascal@12756 776 3 quantization indices. The quantized LSF coefficients are
pascal@12756 777 stabilized with the algorithm described in section 3.2.5.
pascal@12756 778
pascal@12756 779 From the set of LSF coefficients computed for this block and those
pascal@12756 780 from the previous block, different LSFs are obtained for each sub-
pascal@12756 781 block by means of interpolation. The interpolation is done linearly
pascal@12756 782 in the LSF domain over the four sub-blocks, so that the n-th sub-
pascal@12756 783
pascal@12756 784
pascal@12756 785
pascal@12756 786 Andersen, et al. Experimental [Page 14]
pascal@12756 787
pascal@12756 788 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 789
pascal@12756 790
pascal@12756 791 frame uses the weight (4-n)/4 for the LSF from old frame and the
pascal@12756 792 weight n/4 of the LSF from the current frame. For the very first
pascal@12756 793 block the mean LSF, lsfmeanTbl, is used as the LSF from the previous
pascal@12756 794 block. Similarly as seen in section 3.2.6, both unquantized, A(z),
pascal@12756 795 and quantized, A~(z), analysis filters are calculated for each of the
pascal@12756 796 four sub-blocks.
pascal@12756 797
pascal@12756 798 3.3. Calculation of the Residual
pascal@12756 799
pascal@12756 800 The block of speech samples is filtered by the quantized and
pascal@12756 801 interpolated LPC analysis filters to yield the residual signal. In
pascal@12756 802 particular, the corresponding LPC analysis filter for each 40 sample
pascal@12756 803 sub-block is used to filter the speech samples for the same sub-
pascal@12756 804 block. The filter memory at the end of each sub-block is carried
pascal@12756 805 over to the LPC filter of the next sub-block. The signal at the
pascal@12756 806 output of each LP analysis filter constitutes the residual signal for
pascal@12756 807 the corresponding sub-block.
pascal@12756 808
pascal@12756 809 A reference implementation of the LPC analysis filters is given in
pascal@12756 810 Appendix A.10.
pascal@12756 811
pascal@12756 812 3.4. Perceptual Weighting Filter
pascal@12756 813
pascal@12756 814 In principle any good design of a perceptual weighting filter can be
pascal@12756 815 applied in the encoder without compromising this codec definition.
pascal@12756 816 However, it is RECOMMENDED to use the perceptual weighting filter Wk
pascal@12756 817 for sub-block k specified below:
pascal@12756 818
pascal@12756 819 Wk(z)=1/Ak(z/LPC_CHIRP_WEIGHTDENUM), where
pascal@12756 820 LPC_CHIRP_WEIGHTDENUM = 0.4222
pascal@12756 821
pascal@12756 822 This is a simple design with low complexity that is applied in the
pascal@12756 823 LPC residual domain. Here Ak(z) is the filter obtained for sub-block
pascal@12756 824 k from unquantized but interpolated LSF coefficients.
pascal@12756 825
pascal@12756 826 3.5. Start State Encoder
pascal@12756 827
pascal@12756 828 The start state is quantized by using a common 6-bit scalar quantizer
pascal@12756 829 for the block and a 3-bit scalar quantizer operating on scaled
pascal@12756 830 samples in the weighted speech domain. In the following we describe
pascal@12756 831 the state encoding in greater detail.
pascal@12756 832
pascal@12756 833
pascal@12756 834
pascal@12756 835
pascal@12756 836
pascal@12756 837
pascal@12756 838
pascal@12756 839
pascal@12756 840
pascal@12756 841
pascal@12756 842 Andersen, et al. Experimental [Page 15]
pascal@12756 843
pascal@12756 844 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 845
pascal@12756 846
pascal@12756 847 3.5.1. Start State Estimation
pascal@12756 848
pascal@12756 849 The two sub-blocks containing the start state are determined by
pascal@12756 850 finding the two consecutive sub-blocks in the block having the
pascal@12756 851 highest power. Advantageously, down-weighting is used in the
pascal@12756 852 beginning and end of the sub-frames, i.e., the following measure is
pascal@12756 853 computed (NSUB=4/6 for 20/30 ms frame size):
pascal@12756 854
pascal@12756 855 nsub=1,...,NSUB-1
pascal@12756 856 ssqn[nsub] = 0.0;
pascal@12756 857 for (i=(nsub-1)*SUBL; i<(nsub-1)*SUBL+5; i++)
pascal@12756 858 ssqn[nsub] += sampEn_win[i-(nsub-1)*SUBL]*
pascal@12756 859 residual[i]*residual[i];
pascal@12756 860 for (i=(nsub-1)*SUBL+5; i<(nsub+1)*SUBL-5; i++)
pascal@12756 861 ssqn[nsub] += residual[i]*residual[i];
pascal@12756 862 for (i=(nsub+1)*SUBL-5; i<(nsub+1)*SUBL; i++)
pascal@12756 863 ssqn[nsub] += sampEn_win[(nsub+1)*SUBL-i-1]*
pascal@12756 864 residual[i]*residual[i];
pascal@12756 865
pascal@12756 866 where sampEn_win[5]={1/6, 2/6, 3/6, 4/6, 5/6}; MAY be used. The
pascal@12756 867 sub-frame number corresponding to the maximum value of
pascal@12756 868 ssqEn_win[nsub-1]*ssqn[nsub] is selected as the start state
pascal@12756 869 indicator. A weighting of ssqEn_win[]={0.8,0.9,1.0,0.9,0.8} for 30
pascal@12756 870 ms frames and ssqEn_win[]={0.9,1.0,0.9} for 20 ms frames; MAY
pascal@12756 871 advantageously be used to bias the start state towards the middle of
pascal@12756 872 the frame.
pascal@12756 873
pascal@12756 874 For 20 ms frames there are three possible positions for the two-sub-
pascal@12756 875 block length maximum power segment; the start state position is
pascal@12756 876 encoded with 2 bits. The start state position, start, MUST be
pascal@12756 877 encoded as
pascal@12756 878
pascal@12756 879 start=1: start state in sub-frame 0 and 1
pascal@12756 880 start=2: start state in sub-frame 1 and 2
pascal@12756 881 start=3: start state in sub-frame 2 and 3
pascal@12756 882
pascal@12756 883 For 30 ms frames there are five possible positions of the two-sub-
pascal@12756 884 block length maximum power segment, the start state position is
pascal@12756 885 encoded with 3 bits. The start state position, start, MUST be
pascal@12756 886 encoded as
pascal@12756 887
pascal@12756 888 start=1: start state in sub-frame 0 and 1
pascal@12756 889 start=2: start state in sub-frame 1 and 2
pascal@12756 890 start=3: start state in sub-frame 2 and 3
pascal@12756 891 start=4: start state in sub-frame 3 and 4
pascal@12756 892 start=5: start state in sub-frame 4 and 5
pascal@12756 893
pascal@12756 894
pascal@12756 895
pascal@12756 896
pascal@12756 897
pascal@12756 898 Andersen, et al. Experimental [Page 16]
pascal@12756 899
pascal@12756 900 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 901
pascal@12756 902
pascal@12756 903 Hence, in both cases, index 0 is not used. In order to shorten the
pascal@12756 904 start state for bit rate efficiency, the start state is brought down
pascal@12756 905 to STATE_SHORT_LEN=57 samples for 20 ms frames and STATE_SHORT_LEN=58
pascal@12756 906 samples for 30 ms frames. The power of the first 23/22 and last
pascal@12756 907 23/22 samples of the two sub-frame blocks identified above is
pascal@12756 908 computed as the sum of the squared signal sample values, and the
pascal@12756 909 23/22-sample segment with the lowest power is excluded from the start
pascal@12756 910 state. One bit is transmitted to indicate which of the two possible
pascal@12756 911 57/58 sample segments is used. The start state position within the
pascal@12756 912 two sub-frames determined above, state_first, MUST be encoded as
pascal@12756 913
pascal@12756 914 state_first=1: start state is first STATE_SHORT_LEN samples
pascal@12756 915 state_first=0: start state is last STATE_SHORT_LEN samples
pascal@12756 916
pascal@12756 917 3.5.2. All-Pass Filtering and Scale Quantization
pascal@12756 918
pascal@12756 919 The block of residual samples in the start state is first filtered by
pascal@12756 920 an all-pass filter with the quantized LPC coefficients as denominator
pascal@12756 921 and reversed quantized LPC coefficients as numerator. The purpose of
pascal@12756 922 this phase-dispersion filter is to get a more even distribution of
pascal@12756 923 the sample values in the residual signal. The filtering is performed
pascal@12756 924 by circular convolution, where the initial filter memory is set to
pascal@12756 925 zero.
pascal@12756 926
pascal@12756 927 res(0..(STATE_SHORT_LEN-1)) = uncoded start state residual
pascal@12756 928 res((STATE_SHORT_LEN)..(2*STATE_SHORT_LEN-1)) = 0
pascal@12756 929
pascal@12756 930 Pk(z) = A~rk(z)/A~k(z), where
pascal@12756 931 ___
pascal@12756 932 \
pascal@12756 933 A~rk(z)= z^(-LPC_FILTERORDER)+>a~k(i+1)*z^(i-(LPC_FILTERORDER-1))
pascal@12756 934 /__
pascal@12756 935 i=0...(LPC_FILTERORDER-1)
pascal@12756 936
pascal@12756 937 and A~k(z) is taken from the block where the start state begins
pascal@12756 938
pascal@12756 939 res -> Pk(z) -> filtered
pascal@12756 940
pascal@12756 941 ccres(k) = filtered(k) + filtered(k+STATE_SHORT_LEN),
pascal@12756 942 k=0..(STATE_SHORT_LEN-1)
pascal@12756 943
pascal@12756 944 The all-pass filtered block is searched for its largest magnitude
pascal@12756 945 sample. The 10-logarithm of this magnitude is quantized with a 6-bit
pascal@12756 946 quantizer, state_frgqTbl, by finding the nearest representation.
pascal@12756 947
pascal@12756 948
pascal@12756 949
pascal@12756 950
pascal@12756 951
pascal@12756 952
pascal@12756 953
pascal@12756 954 Andersen, et al. Experimental [Page 17]
pascal@12756 955
pascal@12756 956 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 957
pascal@12756 958
pascal@12756 959 This results in an index, idxForMax, corresponding to a quantized
pascal@12756 960 value, qmax. The all-pass filtered residual samples in the block are
pascal@12756 961 then multiplied with a scaling factor scal=4.5/(10^qmax) to yield
pascal@12756 962 normalized samples.
pascal@12756 963
pascal@12756 964 state_frgqTbl[64] = {1.000085, 1.071695, 1.140395, 1.206868,
pascal@12756 965 1.277188, 1.351503, 1.429380, 1.500727, 1.569049,
pascal@12756 966 1.639599, 1.707071, 1.781531, 1.840799, 1.901550,
pascal@12756 967 1.956695, 2.006750, 2.055474, 2.102787, 2.142819,
pascal@12756 968 2.183592, 2.217962, 2.257177, 2.295739, 2.332967,
pascal@12756 969 2.369248, 2.402792, 2.435080, 2.468598, 2.503394,
pascal@12756 970 2.539284, 2.572944, 2.605036, 2.636331, 2.668939,
pascal@12756 971 2.698780, 2.729101, 2.759786, 2.789834, 2.818679,
pascal@12756 972 2.848074, 2.877470, 2.906899, 2.936655, 2.967804,
pascal@12756 973 3.000115, 3.033367, 3.066355, 3.104231, 3.141499,
pascal@12756 974 3.183012, 3.222952, 3.265433, 3.308441, 3.350823,
pascal@12756 975 3.395275, 3.442793, 3.490801, 3.542514, 3.604064,
pascal@12756 976 3.666050, 3.740994, 3.830749, 3.938770, 4.101764}
pascal@12756 977
pascal@12756 978 3.5.3. Scalar Quantization
pascal@12756 979
pascal@12756 980 The normalized samples are quantized in the perceptually weighted
pascal@12756 981 speech domain by a sample-by-sample scalar DPCM quantization as
pascal@12756 982 depicted in Figure 3.3. Each sample in the block is filtered by a
pascal@12756 983 weighting filter Wk(z), specified in section 3.4, to form a weighted
pascal@12756 984 speech sample x[n]. The target sample d[n] is formed by subtracting
pascal@12756 985 a predicted sample y[n], where the prediction filter is given by
pascal@12756 986
pascal@12756 987 Pk(z) = 1 - 1 / Wk(z).
pascal@12756 988
pascal@12756 989 +-------+ x[n] + d[n] +-----------+ u[n]
pascal@12756 990 residual -->| Wk(z) |-------->(+)---->| Quantizer |------> quantized
pascal@12756 991 +-------+ - /|\ +-----------+ | residual
pascal@12756 992 | \|/
pascal@12756 993 y[n] +--------------------->(+)
pascal@12756 994 | |
pascal@12756 995 | +------+ |
pascal@12756 996 +--------| Pk(z)|<------+
pascal@12756 997 +------+
pascal@12756 998
pascal@12756 999 Figure 3.3. Quantization of start state samples by DPCM in weighted
pascal@12756 1000 speech domain.
pascal@12756 1001
pascal@12756 1002 The coded state sample u[n] is obtained by quantizing d[n] with a 3-
pascal@12756 1003 bit quantizer with quantization table state_sq3Tbl.
pascal@12756 1004
pascal@12756 1005 state_sq3Tbl[8] = {-3.719849, -2.177490, -1.130005, -0.309692,
pascal@12756 1006 0.444214, 1.329712, 2.436279, 3.983887}
pascal@12756 1007
pascal@12756 1008
pascal@12756 1009
pascal@12756 1010 Andersen, et al. Experimental [Page 18]
pascal@12756 1011
pascal@12756 1012 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1013
pascal@12756 1014
pascal@12756 1015 The quantized samples are transformed back to the residual domain by
pascal@12756 1016 1) scaling with 1/scal; 2) time-reversing the scaled samples; 3)
pascal@12756 1017 filtering the time-reversed samples by the same all-pass filter, as
pascal@12756 1018 in section 3.5.2, by using circular convolution; and 4) time-
pascal@12756 1019 reversing the filtered samples. (More detail is in section 4.2.)
pascal@12756 1020
pascal@12756 1021 A reference implementation of the start-state encoding can be found
pascal@12756 1022 in Appendix A.46.
pascal@12756 1023
pascal@12756 1024 3.6. Encoding the Remaining Samples
pascal@12756 1025
pascal@12756 1026 A dynamic codebook is used to encode 1) the 23/22 remaining samples
pascal@12756 1027 in the two sub-blocks containing the start state; 2) the sub-blocks
pascal@12756 1028 after the start state in time; and 3) the sub-blocks before the start
pascal@12756 1029 state in time. Thus, the encoding target can be either the 23/22
pascal@12756 1030 samples remaining of the 2 sub-blocks containing the start state, or
pascal@12756 1031 a 40-sample sub-block. This target can consist of samples that are
pascal@12756 1032 indexed forward in time or backward in time, depending on the
pascal@12756 1033 location of the start state. The length of the target is denoted by
pascal@12756 1034 lTarget.
pascal@12756 1035
pascal@12756 1036 The coding is based on an adaptive codebook that is built from a
pascal@12756 1037 codebook memory that contains decoded LPC excitation samples from the
pascal@12756 1038 already encoded part of the block. These samples are indexed in the
pascal@12756 1039 same time direction as is the target vector and end at the sample
pascal@12756 1040 instant prior to the first sample instant represented in the target
pascal@12756 1041 vector. The codebook memory has length lMem, which is equal to
pascal@12756 1042 CB_MEML=147 for the two/four 40-sample sub-blocks and 85 for the
pascal@12756 1043 23/22-sample sub-block.
pascal@12756 1044
pascal@12756 1045 The following figure shows an overview of the encoding procedure.
pascal@12756 1046
pascal@12756 1047 +------------+ +---------------+ +-------------+
pascal@12756 1048 -> | 1. Decode | -> | 2. Mem setup | -> | 3. Perc. W. | ->
pascal@12756 1049 +------------+ +---------------+ +-------------+
pascal@12756 1050
pascal@12756 1051 +------------+ +-----------------+
pascal@12756 1052 -> | 4. Search | -> | 5. Upd. Target | ------------------>
pascal@12756 1053 | +------------+ +------------------ |
pascal@12756 1054 ----<-------------<-----------<----------
pascal@12756 1055 stage=0..2
pascal@12756 1056
pascal@12756 1057 +----------------+
pascal@12756 1058 -> | 6. Recalc G[0] | ---------------> gains and CB indices
pascal@12756 1059 +----------------+
pascal@12756 1060
pascal@12756 1061 Figure 3.4. Flow chart of the codebook search in the iLBC encoder.
pascal@12756 1062
pascal@12756 1063
pascal@12756 1064
pascal@12756 1065
pascal@12756 1066 Andersen, et al. Experimental [Page 19]
pascal@12756 1067
pascal@12756 1068 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1069
pascal@12756 1070
pascal@12756 1071 1. Decode the part of the residual that has been encoded so far,
pascal@12756 1072 using the codebook without perceptual weighting.
pascal@12756 1073
pascal@12756 1074 2. Set up the memory by taking data from the decoded residual. This
pascal@12756 1075 memory is used to construct codebooks. For blocks preceding the
pascal@12756 1076 start state, both the decoded residual and the target are time
pascal@12756 1077 reversed (section 3.6.1).
pascal@12756 1078 3. Filter the memory + target with the perceptual weighting filter
pascal@12756 1079 (section 3.6.2).
pascal@12756 1080
pascal@12756 1081 4. Search for the best match between the target and the codebook
pascal@12756 1082 vector. Compute the optimal gain for this match and quantize that
pascal@12756 1083 gain (section 3.6.4).
pascal@12756 1084
pascal@12756 1085 5. Update the perceptually weighted target by subtracting the
pascal@12756 1086 contribution from the selected codebook vector from the
pascal@12756 1087 perceptually weighted memory (quantized gain times selected
pascal@12756 1088 vector). Repeat 4 and 5 for the two additional stages.
pascal@12756 1089
pascal@12756 1090 6. Calculate the energy loss due to encoding of the residual. If
pascal@12756 1091 needed, compensate for this loss by an upscaling and
pascal@12756 1092 requantization of the gain for the first stage (section 3.7).
pascal@12756 1093
pascal@12756 1094 The following sections provide an in-depth description of the
pascal@12756 1095 different blocks of Figure 3.4.
pascal@12756 1096
pascal@12756 1097 3.6.1. Codebook Memory
pascal@12756 1098
pascal@12756 1099 The codebook memory is based on the already encoded sub-blocks, so
pascal@12756 1100 the available data for encoding increases for each new sub-block that
pascal@12756 1101 has been encoded. Until enough sub-blocks have been encoded to fill
pascal@12756 1102 the codebook memory with data, it is padded with zeros. The
pascal@12756 1103 following figure shows an example of the order in which the sub-
pascal@12756 1104 blocks are encoded for the 30 ms frame size if the start state is
pascal@12756 1105 located in the last 58 samples of sub-block 2 and 3.
pascal@12756 1106
pascal@12756 1107 +-----------------------------------------------------+
pascal@12756 1108 | 5 | 1 |///|////////| 2 | 3 | 4 |
pascal@12756 1109 +-----------------------------------------------------+
pascal@12756 1110
pascal@12756 1111 Figure 3.5. The order from 1 to 5 in which the sub-blocks are
pascal@12756 1112 encoded. The slashed area is the start state.
pascal@12756 1113
pascal@12756 1114
pascal@12756 1115
pascal@12756 1116
pascal@12756 1117
pascal@12756 1118
pascal@12756 1119
pascal@12756 1120
pascal@12756 1121
pascal@12756 1122 Andersen, et al. Experimental [Page 20]
pascal@12756 1123
pascal@12756 1124 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1125
pascal@12756 1126
pascal@12756 1127 The first target sub-block to be encoded is number 1, and the
pascal@12756 1128 corresponding codebook memory is shown in the following figure. As
pascal@12756 1129 the target vector comes before the start state in time, the codebook
pascal@12756 1130 memory and target vector are time reversed; thus, after the block has
pascal@12756 1131 been time reversed the search algorithm can be reused. As only the
pascal@12756 1132 start state has been encoded so far, the last samples of the codebook
pascal@12756 1133 memory are padded with zeros.
pascal@12756 1134
pascal@12756 1135 +-------------------------
pascal@12756 1136 |zeros|\\\\\\\\|\\\\| 1 |
pascal@12756 1137 +-------------------------
pascal@12756 1138
pascal@12756 1139 Figure 3.6. The codebook memory, length lMem=85 samples, and the
pascal@12756 1140 target vector 1, length 22 samples.
pascal@12756 1141
pascal@12756 1142 The next step is to encode sub-block 2 by using the memory that now
pascal@12756 1143 has increased since sub-block 1 has been encoded. The following
pascal@12756 1144 figure shows the codebook memory for encoding of sub-block 2.
pascal@12756 1145
pascal@12756 1146 +-----------------------------------
pascal@12756 1147 | zeros | 1 |///|////////| 2 |
pascal@12756 1148 +-----------------------------------
pascal@12756 1149
pascal@12756 1150 Figure 3.7. The codebook memory, length lMem=147 samples, and the
pascal@12756 1151 target vector 2, length 40 samples.
pascal@12756 1152
pascal@12756 1153 The next step is to encode sub-block 3 by using the memory which has
pascal@12756 1154 been increased yet again since sub-blocks 1 and 2 have been encoded,
pascal@12756 1155 but the sub-block still has to be padded with a few zeros. The
pascal@12756 1156 following figure shows the codebook memory for encoding of sub-block
pascal@12756 1157 3.
pascal@12756 1158
pascal@12756 1159 +------------------------------------------
pascal@12756 1160 |zeros| 1 |///|////////| 2 | 3 |
pascal@12756 1161 +------------------------------------------
pascal@12756 1162
pascal@12756 1163 Figure 3.8. The codebook memory, length lMem=147 samples, and the
pascal@12756 1164 target vector 3, length 40 samples.
pascal@12756 1165
pascal@12756 1166 The next step is to encode sub-block 4 by using the memory which now
pascal@12756 1167 has increased yet again since sub-blocks 1, 2, and 3 have been
pascal@12756 1168 encoded. This time, the memory does not have to be padded with
pascal@12756 1169 zeros. The following figure shows the codebook memory for encoding
pascal@12756 1170 of sub-block 4.
pascal@12756 1171
pascal@12756 1172
pascal@12756 1173
pascal@12756 1174
pascal@12756 1175
pascal@12756 1176
pascal@12756 1177
pascal@12756 1178 Andersen, et al. Experimental [Page 21]
pascal@12756 1179
pascal@12756 1180 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1181
pascal@12756 1182
pascal@12756 1183 +------------------------------------------
pascal@12756 1184 |1|///|////////| 2 | 3 | 4 |
pascal@12756 1185 +------------------------------------------
pascal@12756 1186
pascal@12756 1187 Figure 3.9. The codebook memory, length lMem=147 samples, and the
pascal@12756 1188 target vector 4, length 40 samples.
pascal@12756 1189
pascal@12756 1190 The final target sub-block to be encoded is number 5, and the
pascal@12756 1191 following figure shows the corresponding codebook memory. As the
pascal@12756 1192 target vector comes before the start state in time, the codebook
pascal@12756 1193 memory and target vector are time reversed.
pascal@12756 1194
pascal@12756 1195 +-------------------------------------------
pascal@12756 1196 | 3 | 2 |\\\\\\\\|\\\\| 1 | 5 |
pascal@12756 1197 +-------------------------------------------
pascal@12756 1198
pascal@12756 1199 Figure 3.10. The codebook memory, length lMem=147 samples, and the
pascal@12756 1200 target vector 5, length 40 samples.
pascal@12756 1201
pascal@12756 1202 For the case of 20 ms frames, the encoding procedure looks almost
pascal@12756 1203 exactly the same. The only difference is that the size of the start
pascal@12756 1204 state is 57 samples and that there are only three sub-blocks to be
pascal@12756 1205 encoded. The encoding order is the same as above, starting with the
pascal@12756 1206 23-sample target and then encoding the two remaining 40-sample sub-
pascal@12756 1207 blocks, first going forward in time and then going backward in time
pascal@12756 1208 relative to the start state.
pascal@12756 1209
pascal@12756 1210 3.6.2. Perceptual Weighting of Codebook Memory and Target
pascal@12756 1211
pascal@12756 1212 To provide a perceptual weighting of the coding error, a
pascal@12756 1213 concatenation of the codebook memory and the target to be coded is
pascal@12756 1214 all-pole filtered with the perceptual weighting filter specified in
pascal@12756 1215 section 3.4. The filter state of the weighting filter is set to
pascal@12756 1216 zero.
pascal@12756 1217
pascal@12756 1218 in(0..(lMem-1)) = unweighted codebook memory
pascal@12756 1219 in(lMem..(lMem+lTarget-1)) = unweighted target signal
pascal@12756 1220
pascal@12756 1221
pascal@12756 1222 in -> Wk(z) -> filtered,
pascal@12756 1223 where Wk(z) is taken from the sub-block of the target
pascal@12756 1224
pascal@12756 1225 weighted codebook memory = filtered(0..(lMem-1))
pascal@12756 1226 weighted target signal = filtered(lMem..(lMem+lTarget-1))
pascal@12756 1227
pascal@12756 1228 The codebook search is done with the weighted codebook memory and the
pascal@12756 1229 weighted target, whereas the decoding and the codebook memory update
pascal@12756 1230 uses the unweighted codebook memory.
pascal@12756 1231
pascal@12756 1232
pascal@12756 1233
pascal@12756 1234 Andersen, et al. Experimental [Page 22]
pascal@12756 1235
pascal@12756 1236 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1237
pascal@12756 1238
pascal@12756 1239 3.6.3. Codebook Creation
pascal@12756 1240
pascal@12756 1241 The codebook for the search is created from the perceptually weighted
pascal@12756 1242 codebook memory. It consists of two sections, where the first is
pascal@12756 1243 referred to as the base codebook and the second as the expanded
pascal@12756 1244 codebook, as it is created by linear combinations of the first. Each
pascal@12756 1245 of these two sections also has a subsection referred to as the
pascal@12756 1246 augmented codebook. The augmented codebook is only created and used
pascal@12756 1247 for the coding of the 40-sample sub-blocks and not for the 23/22-
pascal@12756 1248 sample sub-block case. The codebook size used for the different
pascal@12756 1249 sub-blocks and different stages are summarized in the table below.
pascal@12756 1250
pascal@12756 1251 Stage
pascal@12756 1252 1 2 & 3
pascal@12756 1253 --------------------------------------------
pascal@12756 1254 22 128 (64+0)*2 128 (64+0)*2
pascal@12756 1255 Sub- 1:st 40 256 (108+20)*2 128 (44+20)*2
pascal@12756 1256 Blocks 2:nd 40 256 (108+20)*2 256 (108+20)*2
pascal@12756 1257 3:rd 40 256 (108+20)*2 256 (108+20)*2
pascal@12756 1258 4:th 40 256 (108+20)*2 256 (108+20)*2
pascal@12756 1259
pascal@12756 1260 Table 3.1. Codebook sizes for the 30 ms mode.
pascal@12756 1261
pascal@12756 1262 Table 3.1 shows the codebook size for the different sub-blocks and
pascal@12756 1263 stages for 30 ms frames. Inside the parentheses it shows how the
pascal@12756 1264 number of codebook vectors is distributed, within the two sections,
pascal@12756 1265 between the base/expanded codebook and the augmented base/expanded
pascal@12756 1266 codebook. It should be interpreted in the following way:
pascal@12756 1267 (base/expanded cb + augmented base/expanded cb). The total number of
pascal@12756 1268 codebook vectors for a specific sub-block and stage is given by the
pascal@12756 1269 following formula:
pascal@12756 1270
pascal@12756 1271 Tot. cb vectors = base cb + aug. base cb + exp. cb + aug. exp. cb
pascal@12756 1272
pascal@12756 1273 The corresponding values to Figure 3.1 for 20 ms frames are only
pascal@12756 1274 slightly modified. The short sub-block is 23 instead of 22 samples,
pascal@12756 1275 and the 3:rd and 4:th sub-frame are not present.
pascal@12756 1276
pascal@12756 1277 3.6.3.1. Creation of a Base Codebook
pascal@12756 1278
pascal@12756 1279 The base codebook is given by the perceptually weighted codebook
pascal@12756 1280 memory that is mentioned in section 3.5.3. The different codebook
pascal@12756 1281 vectors are given by sliding a window of length 23/22 or 40, given by
pascal@12756 1282 variable lTarget, over the lMem-long perceptually weighted codebook
pascal@12756 1283 memory. The indices are ordered so that the codebook vector
pascal@12756 1284 containing sample (lMem-lTarget-n) to (lMem-n-1) of the codebook
pascal@12756 1285
pascal@12756 1286
pascal@12756 1287
pascal@12756 1288
pascal@12756 1289
pascal@12756 1290 Andersen, et al. Experimental [Page 23]
pascal@12756 1291
pascal@12756 1292 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1293
pascal@12756 1294
pascal@12756 1295 memory vector has index n, where n=0..lMem-lTarget. Thus the total
pascal@12756 1296 number of base codebook vectors is lMem-lTarget+1, and the indices
pascal@12756 1297 are ordered from sample delay lTarget (23/22 or 40) to lMem+1 (86 or
pascal@12756 1298 148).
pascal@12756 1299
pascal@12756 1300 3.6.3.2. Codebook Expansion
pascal@12756 1301
pascal@12756 1302 The base codebook is expanded by a factor of 2, creating an
pascal@12756 1303 additional section in the codebook. This new section is obtained by
pascal@12756 1304 filtering the base codebook, base_cb, with a FIR filter with filter
pascal@12756 1305 length CB_FILTERLEN=8. The construction of the expanded codebook
pascal@12756 1306 compensates for the delay of four samples introduced by the FIR
pascal@12756 1307 filter.
pascal@12756 1308
pascal@12756 1309 cbfiltersTbl[CB_FILTERLEN]={-0.033691, 0.083740, -0.144043,
pascal@12756 1310 0.713379, 0.806152, -0.184326,
pascal@12756 1311 0.108887, -0.034180};
pascal@12756 1312
pascal@12756 1313 ___
pascal@12756 1314 \
pascal@12756 1315 exp_cb(k)= + > cbfiltersTbl(i)*x(k-i+4)
pascal@12756 1316 /__
pascal@12756 1317 i=0...(LPC_FILTERORDER-1)
pascal@12756 1318
pascal@12756 1319 where x(j) = base_cb(j) for j=0..lMem-1 and 0 otherwise
pascal@12756 1320
pascal@12756 1321 The individual codebook vectors of the new filtered codebook, exp_cb,
pascal@12756 1322 and their indices are obtained in the same fashion as described above
pascal@12756 1323 for the base codebook.
pascal@12756 1324
pascal@12756 1325 3.6.3.3. Codebook Augmentation
pascal@12756 1326
pascal@12756 1327 For cases where encoding entire sub-blocks, i.e., cbveclen=40, the
pascal@12756 1328 base and expanded codebooks are augmented to increase codebook
pascal@12756 1329 richness. The codebooks are augmented by vectors produced by
pascal@12756 1330 interpolation of segments. The base and expanded codebook,
pascal@12756 1331 constructed above, consists of vectors corresponding to sample delays
pascal@12756 1332 in the range from cbveclen to lMem. The codebook augmentation
pascal@12756 1333 attempts to augment these codebooks with vectors corresponding to
pascal@12756 1334 sample delays from 20 to 39. However, not all of these samples are
pascal@12756 1335 present in the base codebook and expanded codebook, respectively.
pascal@12756 1336 Therefore, the augmentation vectors are constructed as linear
pascal@12756 1337 combinations between samples corresponding to sample delays in the
pascal@12756 1338 range 20 to 39. The general idea of this procedure is presented in
pascal@12756 1339 the following figures and text. The procedure is performed for both
pascal@12756 1340 the base codebook and the expanded codebook.
pascal@12756 1341
pascal@12756 1342
pascal@12756 1343
pascal@12756 1344
pascal@12756 1345
pascal@12756 1346 Andersen, et al. Experimental [Page 24]
pascal@12756 1347
pascal@12756 1348 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1349
pascal@12756 1350
pascal@12756 1351 - - ------------------------|
pascal@12756 1352 codebook memory |
pascal@12756 1353 - - ------------------------|
pascal@12756 1354 |-5-|---15---|-5-|
pascal@12756 1355 pi pp po
pascal@12756 1356
pascal@12756 1357 | | Codebook vector
pascal@12756 1358 |---15---|-5-|-----20-----| <- corresponding to
pascal@12756 1359 i ii iii sample delay 20
pascal@12756 1360
pascal@12756 1361 Figure 3.11. Generation of the first augmented codebook.
pascal@12756 1362
pascal@12756 1363 Figure 3.11 shows the codebook memory with pointers pi, pp, and po,
pascal@12756 1364 where pi points to sample 25, pp to sample 20, and po to sample 5.
pascal@12756 1365 Below the codebook memory, the augmented codebook vector
pascal@12756 1366 corresponding to sample delay 20 is drawn. Segment i consists of
pascal@12756 1367 fifteen samples from pointer pp and forward in time. Segment ii
pascal@12756 1368 consists of five interpolated samples from pi and forward and from po
pascal@12756 1369 and forward. The samples are linearly interpolated with weights
pascal@12756 1370 [0.0, 0.2, 0.4, 0.6, 0.8] for pi and weights [1.0, 0.8, 0.6, 0.4,
pascal@12756 1371 0.2] for po. Segment iii consists of twenty samples from pp and
pascal@12756 1372 forward. The augmented codebook vector corresponding to sample delay
pascal@12756 1373 21 is produced by moving pointers pp and pi one sample backward in
pascal@12756 1374 time. This gives us the following figure.
pascal@12756 1375
pascal@12756 1376 - - ------------------------|
pascal@12756 1377 codebook memory |
pascal@12756 1378 - - ------------------------|
pascal@12756 1379 |-5-|---16---|-5-|
pascal@12756 1380 pi pp po
pascal@12756 1381
pascal@12756 1382 | | Codebook vector
pascal@12756 1383 |---16---|-5-|-----19-----| <- corresponding to
pascal@12756 1384 i ii iii sample delay 21
pascal@12756 1385
pascal@12756 1386 Figure 3.12. Generation of the second augmented codebook.
pascal@12756 1387
pascal@12756 1388 Figure 3.12 shows the codebook memory with pointers pi, pp and po
pascal@12756 1389 where pi points to sample 26, pp to sample 21, and po to sample 5.
pascal@12756 1390 Below the codebook memory, the augmented codebook vector
pascal@12756 1391 corresponding to sample delay 21 is drawn. Segment i now consists of
pascal@12756 1392 sixteen samples from pp and forward. Segment ii consists of five
pascal@12756 1393 interpolated samples from pi and forward and from po and forward, and
pascal@12756 1394 the interpolation weights are the same throughout the procedure.
pascal@12756 1395 Segment iii consists of nineteen samples from pp and forward. The
pascal@12756 1396 same procedure of moving the two pointers is continued until the last
pascal@12756 1397 augmented vector corresponding to sample delay 39 has been created.
pascal@12756 1398 This gives a total of twenty new codebook vectors to each of the two
pascal@12756 1399
pascal@12756 1400
pascal@12756 1401
pascal@12756 1402 Andersen, et al. Experimental [Page 25]
pascal@12756 1403
pascal@12756 1404 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1405
pascal@12756 1406
pascal@12756 1407 sections. Thus the total number of codebook vectors for each of the
pascal@12756 1408 two sections, when including the augmented codebook, becomes lMem-
pascal@12756 1409 SUBL+1+SUBL/2. This is provided that augmentation is evoked, i.e.,
pascal@12756 1410 that lTarget=SUBL.
pascal@12756 1411
pascal@12756 1412 3.6.4. Codebook Search
pascal@12756 1413
pascal@12756 1414 The codebook search uses the codebooks described in the sections
pascal@12756 1415 above to find the best match of the perceptually weighted target, see
pascal@12756 1416 section 3.6.2. The search method is a multi-stage gain-shape
pascal@12756 1417 matching performed as follows. At each stage the best shape vector
pascal@12756 1418 is identified, then the gain is calculated and quantized, and finally
pascal@12756 1419 the target is updated in preparation for the next codebook search
pascal@12756 1420 stage. The number of stages is CB_NSTAGES=3.
pascal@12756 1421
pascal@12756 1422 If the target is the 23/22-sample vector the codebooks are indexed so
pascal@12756 1423 that the base codebook is followed by the expanded codebook. If the
pascal@12756 1424 target is 40 samples the order is as follows: base codebook,
pascal@12756 1425 augmented base codebook, expanded codebook, and augmented expanded
pascal@12756 1426 codebook. The size of each codebook section and its corresponding
pascal@12756 1427 augmented section is given by Table 3.1 in section 3.6.3.
pascal@12756 1428
pascal@12756 1429 For example, when the second 40-sample sub-block is coded, indices 0
pascal@12756 1430 - 107 correspond to the base codebook, 108 - 127 correspond to the
pascal@12756 1431 augmented base codebook, 128 - 235 correspond to the expanded
pascal@12756 1432 codebook, and indices 236 - 255 correspond to the augmented expanded
pascal@12756 1433 codebook. The indices are divided in the same fashion for all stages
pascal@12756 1434 in the example. Only in the case of coding the first 40-sample sub-
pascal@12756 1435 block is there a difference between stages (see Table 3.1).
pascal@12756 1436
pascal@12756 1437 3.6.4.1. Codebook Search at Each Stage
pascal@12756 1438
pascal@12756 1439 The codebooks are searched to find the best match to the target at
pascal@12756 1440 each stage. When the best match is found, the target is updated and
pascal@12756 1441 the next-stage search is started. The three chosen codebook vectors
pascal@12756 1442 and their corresponding gains constitute the encoded sub-block. The
pascal@12756 1443 best match is decided by the following three criteria:
pascal@12756 1444
pascal@12756 1445 1. Compute the measure
pascal@12756 1446
pascal@12756 1447 (target*cbvec)^2 / ||cbvec||^2
pascal@12756 1448
pascal@12756 1449 for all codebook vectors, cbvec, and choose the codebook vector
pascal@12756 1450 maximizing the measure. The expression (target*cbvec) is the dot
pascal@12756 1451 product between the target vector to be coded and the codebook vector
pascal@12756 1452 for which we compute the measure. The norm, ||x||, is defined as the
pascal@12756 1453 square root of (x*x).
pascal@12756 1454
pascal@12756 1455
pascal@12756 1456
pascal@12756 1457
pascal@12756 1458 Andersen, et al. Experimental [Page 26]
pascal@12756 1459
pascal@12756 1460 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1461
pascal@12756 1462
pascal@12756 1463 2. The absolute value of the gain, corresponding to the chosen
pascal@12756 1464 codebook vector, cbvec, must be smaller than a fixed limit,
pascal@12756 1465 CB_MAXGAIN=1.3:
pascal@12756 1466
pascal@12756 1467 |gain| < CB_MAXGAIN
pascal@12756 1468
pascal@12756 1469 where the gain is computed in the following way:
pascal@12756 1470
pascal@12756 1471 gain = (target*cbvec) / ||cbvec||^2
pascal@12756 1472
pascal@12756 1473 3. For the first stage, the dot product of the chosen codebook vector
pascal@12756 1474 and target must be positive:
pascal@12756 1475
pascal@12756 1476 target*cbvec > 0
pascal@12756 1477
pascal@12756 1478 In practice the above criteria are used in a sequential search
pascal@12756 1479 through all codebook vectors. The best match is found by registering
pascal@12756 1480 a new max measure and index whenever the previously registered max
pascal@12756 1481 measure is surpassed and all other criteria are fulfilled. If none
pascal@12756 1482 of the codebook vectors fulfill (2) and (3), the first codebook
pascal@12756 1483 vector is selected.
pascal@12756 1484
pascal@12756 1485 3.6.4.2. Gain Quantization at Each Stage
pascal@12756 1486
pascal@12756 1487 The gain follows as a result of the computation
pascal@12756 1488
pascal@12756 1489 gain = (target*cbvec) / ||cbvec||^2
pascal@12756 1490
pascal@12756 1491 for the optimal codebook vector found by the procedure in section
pascal@12756 1492 3.6.4.1.
pascal@12756 1493
pascal@12756 1494 The three stages quantize the gain, using 5, 4, and 3 bits,
pascal@12756 1495 respectively. In the first stage, the gain is limited to positive
pascal@12756 1496 values. This gain is quantized by finding the nearest value in the
pascal@12756 1497 quantization table gain_sq5Tbl.
pascal@12756 1498
pascal@12756 1499 gain_sq5Tbl[32]={0.037476, 0.075012, 0.112488, 0.150024, 0.187500,
pascal@12756 1500 0.224976, 0.262512, 0.299988, 0.337524, 0.375000,
pascal@12756 1501 0.412476, 0.450012, 0.487488, 0.525024, 0.562500,
pascal@12756 1502 0.599976, 0.637512, 0.674988, 0.712524, 0.750000,
pascal@12756 1503 0.787476, 0.825012, 0.862488, 0.900024, 0.937500,
pascal@12756 1504 0.974976, 1.012512, 1.049988, 1.087524, 1.125000,
pascal@12756 1505 1.162476, 1.200012}
pascal@12756 1506
pascal@12756 1507 The gains of the subsequent two stages can be either positive or
pascal@12756 1508 negative. The gains are quantized by using a quantization table
pascal@12756 1509 times a scale factor. The second stage uses the table gain_sq4Tbl,
pascal@12756 1510 and the third stage uses gain_sq3Tbl. The scale factor equates 0.1
pascal@12756 1511
pascal@12756 1512
pascal@12756 1513
pascal@12756 1514 Andersen, et al. Experimental [Page 27]
pascal@12756 1515
pascal@12756 1516 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1517
pascal@12756 1518
pascal@12756 1519 or the absolute value of the quantized gain representation value
pascal@12756 1520 obtained in the previous stage, whichever is larger. Again, the
pascal@12756 1521 resulting gain index is the index to the nearest value of the
pascal@12756 1522 quantization table times the scale factor.
pascal@12756 1523
pascal@12756 1524 gainQ = scaleFact * gain_sqXTbl[index]
pascal@12756 1525
pascal@12756 1526 gain_sq4Tbl[16]={-1.049988, -0.900024, -0.750000, -0.599976,
pascal@12756 1527 -0.450012, -0.299988, -0.150024, 0.000000, 0.150024,
pascal@12756 1528 0.299988, 0.450012, 0.599976, 0.750000, 0.900024,
pascal@12756 1529 1.049988, 1.200012}
pascal@12756 1530
pascal@12756 1531 gain_sq3Tbl[8]={-1.000000, -0.659973, -0.330017,0.000000,
pascal@12756 1532 0.250000, 0.500000, 0.750000, 1.00000}
pascal@12756 1533
pascal@12756 1534 3.6.4.3. Preparation of Target for Next Stage
pascal@12756 1535
pascal@12756 1536 Before performing the search for the next stage, the perceptually
pascal@12756 1537 weighted target vector is updated by subtracting from it the selected
pascal@12756 1538 codebook vector (from the perceptually weighted codebook) times the
pascal@12756 1539 corresponding quantized gain.
pascal@12756 1540
pascal@12756 1541 target[i] = target[i] - gainQ * selected_vec[i];
pascal@12756 1542
pascal@12756 1543 A reference implementation of the codebook encoding is found in
pascal@12756 1544 Appendix A.34.
pascal@12756 1545
pascal@12756 1546 3.7. Gain Correction Encoding
pascal@12756 1547
pascal@12756 1548 The start state is quantized in a relatively model independent manner
pascal@12756 1549 using 3 bits per sample. In contrast, the remaining parts of the
pascal@12756 1550 block are encoded by using an adaptive codebook. This codebook will
pascal@12756 1551 produce high matching accuracy whenever there is a high correlation
pascal@12756 1552 between the target and the best codebook vector. For unvoiced speech
pascal@12756 1553 segments and background noises, this is not necessarily so, which,
pascal@12756 1554 due to the nature of the squared error criterion, results in a coded
pascal@12756 1555 signal with less power than the target signal. As the coded start
pascal@12756 1556 state has good power matching to the target, the result is a power
pascal@12756 1557 fluctuation within the encoded frame. Perceptually, the main problem
pascal@12756 1558 with this is that the time envelope of the signal energy becomes
pascal@12756 1559 unsteady. To overcome this problem, the gains for the codebooks are
pascal@12756 1560 re-scaled after the codebook encoding by searching for a new gain
pascal@12756 1561 factor for the first stage codebook that provides better power
pascal@12756 1562 matching.
pascal@12756 1563
pascal@12756 1564 First, the energy for the target signal, tene, is computed along with
pascal@12756 1565 the energy for the coded signal, cene, given by the addition of the
pascal@12756 1566 three gain scaled codebook vectors. Because the gains of the second
pascal@12756 1567
pascal@12756 1568
pascal@12756 1569
pascal@12756 1570 Andersen, et al. Experimental [Page 28]
pascal@12756 1571
pascal@12756 1572 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1573
pascal@12756 1574
pascal@12756 1575 and third stage scale with the gain of the first stage, when the
pascal@12756 1576 first stage gain is changed from gain[0] to gain_sq5Tbl[i] the energy
pascal@12756 1577 of the coded signal changes from cene to
pascal@12756 1578
pascal@12756 1579 cene*(gain_sq5Tbl[i]*gain_sq5Tbl[i])/(gain[0]*gain[0])
pascal@12756 1580
pascal@12756 1581 where gain[0] is the gain for the first stage found in the original
pascal@12756 1582 codebook search. A refined search is performed by testing the gain
pascal@12756 1583 indices i=0 to 31, and as long as the new codebook energy as given
pascal@12756 1584 above is less than tene, the gain index for stage 1 is increased. A
pascal@12756 1585 restriction is applied so that the new gain value for stage 1 cannot
pascal@12756 1586 be more than two times higher than the original value found in the
pascal@12756 1587 codebook search. Note that by using this method we do not change the
pascal@12756 1588 shape of the encoded vector, only the gain or amplitude.
pascal@12756 1589
pascal@12756 1590 3.8. Bitstream Definition
pascal@12756 1591
pascal@12756 1592 The total number of bits used to describe one frame of 20 ms speech
pascal@12756 1593 is 304, which fits in 38 bytes and results in a bit rate of 15.20
pascal@12756 1594 kbit/s. For the case of a frame length of 30 ms speech, the total
pascal@12756 1595 number of bits used is 400, which fits in 50 bytes and results in a
pascal@12756 1596 bit rate of 13.33 kbit/s. In the bitstream definition, the bits are
pascal@12756 1597 distributed into three classes according to their bit error or loss
pascal@12756 1598 sensitivity. The most sensitive bits (class 1) are placed first in
pascal@12756 1599 the bitstream for each frame. The less sensitive bits (class 2) are
pascal@12756 1600 placed after the class 1 bits. The least sensitive bits (class 3)
pascal@12756 1601 are placed at the end of the bitstream for each frame.
pascal@12756 1602
pascal@12756 1603 In the 20/30 ms frame length cases for each class, the following hold
pascal@12756 1604 true: The class 1 bits occupy a total of 6/8 bytes (48/64 bits), the
pascal@12756 1605 class 2 bits occupy 8/12 bytes (64/96 bits), and the class 3 bits
pascal@12756 1606 occupy 24/30 bytes (191/239 bits). This distribution of the bits
pascal@12756 1607 enables the use of uneven level protection (ULP) as is exploited in
pascal@12756 1608 the payload format definition for iLBC [1]. The detailed bit
pascal@12756 1609 allocation is shown in the table below. When a quantization index is
pascal@12756 1610 distributed between more classes, the more significant bits belong to
pascal@12756 1611 the lowest class.
pascal@12756 1612
pascal@12756 1613
pascal@12756 1614
pascal@12756 1615
pascal@12756 1616
pascal@12756 1617
pascal@12756 1618
pascal@12756 1619
pascal@12756 1620
pascal@12756 1621
pascal@12756 1622
pascal@12756 1623
pascal@12756 1624
pascal@12756 1625
pascal@12756 1626 Andersen, et al. Experimental [Page 29]
pascal@12756 1627
pascal@12756 1628 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1629
pascal@12756 1630
pascal@12756 1631 Bitstream structure:
pascal@12756 1632
pascal@12756 1633 ------------------------------------------------------------------+
pascal@12756 1634 Parameter | Bits Class <1,2,3> |
pascal@12756 1635 | 20 ms frame | 30 ms frame |
pascal@12756 1636 ----------------------------------+---------------+---------------+
pascal@12756 1637 Split 1 | 6 <6,0,0> | 6 <6,0,0> |
pascal@12756 1638 LSF 1 Split 2 | 7 <7,0,0> | 7 <7,0,0> |
pascal@12756 1639 LSF Split 3 | 7 <7,0,0> | 7 <7,0,0> |
pascal@12756 1640 ------------------+---------------+---------------+
pascal@12756 1641 Split 1 | NA (Not Appl.)| 6 <6,0,0> |
pascal@12756 1642 LSF 2 Split 2 | NA | 7 <7,0,0> |
pascal@12756 1643 Split 3 | NA | 7 <7,0,0> |
pascal@12756 1644 ------------------+---------------+---------------+
pascal@12756 1645 Sum | 20 <20,0,0> | 40 <40,0,0> |
pascal@12756 1646 ----------------------------------+---------------+---------------+
pascal@12756 1647 Block Class | 2 <2,0,0> | 3 <3,0,0> |
pascal@12756 1648 ----------------------------------+---------------+---------------+
pascal@12756 1649 Position 22 sample segment | 1 <1,0,0> | 1 <1,0,0> |
pascal@12756 1650 ----------------------------------+---------------+---------------+
pascal@12756 1651 Scale Factor State Coder | 6 <6,0,0> | 6 <6,0,0> |
pascal@12756 1652 ----------------------------------+---------------+---------------+
pascal@12756 1653 Sample 0 | 3 <0,1,2> | 3 <0,1,2> |
pascal@12756 1654 Quantized Sample 1 | 3 <0,1,2> | 3 <0,1,2> |
pascal@12756 1655 Residual : | : : | : : |
pascal@12756 1656 State : | : : | : : |
pascal@12756 1657 Samples : | : : | : : |
pascal@12756 1658 Sample 56 | 3 <0,1,2> | 3 <0,1,2> |
pascal@12756 1659 Sample 57 | NA | 3 <0,1,2> |
pascal@12756 1660 ------------------+---------------+---------------+
pascal@12756 1661 Sum | 171 <0,57,114>| 174 <0,58,116>|
pascal@12756 1662 ----------------------------------+---------------+---------------+
pascal@12756 1663 Stage 1 | 7 <6,0,1> | 7 <4,2,1> |
pascal@12756 1664 CB for 22/23 Stage 2 | 7 <0,0,7> | 7 <0,0,7> |
pascal@12756 1665 sample block Stage 3 | 7 <0,0,7> | 7 <0,0,7> |
pascal@12756 1666 ------------------+---------------+---------------+
pascal@12756 1667 Sum | 21 <6,0,15> | 21 <4,2,15> |
pascal@12756 1668 ----------------------------------+---------------+---------------+
pascal@12756 1669 Stage 1 | 5 <2,0,3> | 5 <1,1,3> |
pascal@12756 1670 Gain for 22/23 Stage 2 | 4 <1,1,2> | 4 <1,1,2> |
pascal@12756 1671 sample block Stage 3 | 3 <0,0,3> | 3 <0,0,3> |
pascal@12756 1672 ------------------+---------------+---------------+
pascal@12756 1673 Sum | 12 <3,1,8> | 12 <2,2,8> |
pascal@12756 1674 ----------------------------------+---------------+---------------+
pascal@12756 1675 Stage 1 | 8 <7,0,1> | 8 <6,1,1> |
pascal@12756 1676 sub-block 1 Stage 2 | 7 <0,0,7> | 7 <0,0,7> |
pascal@12756 1677 Stage 3 | 7 <0,0,7> | 7 <0,0,7> |
pascal@12756 1678 ------------------+---------------+---------------+
pascal@12756 1679
pascal@12756 1680
pascal@12756 1681
pascal@12756 1682 Andersen, et al. Experimental [Page 30]
pascal@12756 1683
pascal@12756 1684 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1685
pascal@12756 1686
pascal@12756 1687 Stage 1 | 8 <0,0,8> | 8 <0,7,1> |
pascal@12756 1688 sub-block 2 Stage 2 | 8 <0,0,8> | 8 <0,0,8> |
pascal@12756 1689 Indices Stage 3 | 8 <0,0,8> | 8 <0,0,8> |
pascal@12756 1690 for CB ------------------+---------------+---------------+
pascal@12756 1691 sub-blocks Stage 1 | NA | 8 <0,7,1> |
pascal@12756 1692 sub-block 3 Stage 2 | NA | 8 <0,0,8> |
pascal@12756 1693 Stage 3 | NA | 8 <0,0,8> |
pascal@12756 1694 ------------------+---------------+---------------+
pascal@12756 1695 Stage 1 | NA | 8 <0,7,1> |
pascal@12756 1696 sub-block 4 Stage 2 | NA | 8 <0,0,8> |
pascal@12756 1697 Stage 3 | NA | 8 <0,0,8> |
pascal@12756 1698 ------------------+---------------+---------------+
pascal@12756 1699 Sum | 46 <7,0,39> | 94 <6,22,66> |
pascal@12756 1700 ----------------------------------+---------------+---------------+
pascal@12756 1701 Stage 1 | 5 <1,2,2> | 5 <1,2,2> |
pascal@12756 1702 sub-block 1 Stage 2 | 4 <1,1,2> | 4 <1,2,1> |
pascal@12756 1703 Stage 3 | 3 <0,0,3> | 3 <0,0,3> |
pascal@12756 1704 ------------------+---------------+---------------+
pascal@12756 1705 Stage 1 | 5 <1,1,3> | 5 <0,2,3> |
pascal@12756 1706 sub-block 2 Stage 2 | 4 <0,2,2> | 4 <0,2,2> |
pascal@12756 1707 Stage 3 | 3 <0,0,3> | 3 <0,0,3> |
pascal@12756 1708 Gains for ------------------+---------------+---------------+
pascal@12756 1709 sub-blocks Stage 1 | NA | 5 <0,1,4> |
pascal@12756 1710 sub-block 3 Stage 2 | NA | 4 <0,1,3> |
pascal@12756 1711 Stage 3 | NA | 3 <0,0,3> |
pascal@12756 1712 ------------------+---------------+---------------+
pascal@12756 1713 Stage 1 | NA | 5 <0,1,4> |
pascal@12756 1714 sub-block 4 Stage 2 | NA | 4 <0,1,3> |
pascal@12756 1715 Stage 3 | NA | 3 <0,0,3> |
pascal@12756 1716 ------------------+---------------+---------------+
pascal@12756 1717 Sum | 24 <3,6,15> | 48 <2,12,34> |
pascal@12756 1718 ----------------------------------+---------------+---------------+
pascal@12756 1719 Empty frame indicator | 1 <0,0,1> | 1 <0,0,1> |
pascal@12756 1720 -------------------------------------------------------------------
pascal@12756 1721 SUM 304 <48,64,192> 400 <64,96,240>
pascal@12756 1722
pascal@12756 1723 Table 3.2. The bitstream definition for iLBC for both the 20 ms
pascal@12756 1724 frame size mode and the 30 ms frame size mode.
pascal@12756 1725
pascal@12756 1726 When packetized into the payload, the bits MUST be sorted as follows:
pascal@12756 1727 All the class 1 bits in the order (from top to bottom) as specified
pascal@12756 1728 in the table, all the class 2 bits (from top to bottom), and all the
pascal@12756 1729 class 3 bits in the same sequential order. The last bit, the empty
pascal@12756 1730 frame indicator, SHOULD be set to zero by the encoder. If this bit
pascal@12756 1731 is set to 1 the decoder SHOULD treat the data as a lost frame. For
pascal@12756 1732 example, this bit can be set to 1 to indicate lost frame for file
pascal@12756 1733 storage format, as in [1].
pascal@12756 1734
pascal@12756 1735
pascal@12756 1736
pascal@12756 1737
pascal@12756 1738 Andersen, et al. Experimental [Page 31]
pascal@12756 1739
pascal@12756 1740 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1741
pascal@12756 1742
pascal@12756 1743 4. Decoder Principles
pascal@12756 1744
pascal@12756 1745 This section describes the principles of each component of the
pascal@12756 1746 decoder algorithm.
pascal@12756 1747
pascal@12756 1748 +-------------+ +--------+ +---------------+
pascal@12756 1749 payload -> | 1. Get para | -> | 2. LPC | -> | 3. Sc Dequant | ->
pascal@12756 1750 +-------------+ +--------+ +---------------+
pascal@12756 1751
pascal@12756 1752 +-------------+ +------------------+
pascal@12756 1753 -> | 4. Mem setup| -> | 5. Construct res |------->
pascal@12756 1754 | +-------------+ +------------------- |
pascal@12756 1755 ---------<-----------<-----------<------------
pascal@12756 1756 Sub-frame 0...2/4 (20 ms/30 ms)
pascal@12756 1757
pascal@12756 1758 +----------------+ +----------+
pascal@12756 1759 -> | 6. Enhance res | -> | 7. Synth | ------------>
pascal@12756 1760 +----------------+ +----------+
pascal@12756 1761
pascal@12756 1762 +-----------------+
pascal@12756 1763 -> | 8. Post Process | ----------------> decoded speech
pascal@12756 1764 +-----------------+
pascal@12756 1765
pascal@12756 1766 Figure 4.1. Flow chart of the iLBC decoder. If a frame was lost,
pascal@12756 1767 steps 1 to 5 SHOULD be replaced by a PLC algorithm.
pascal@12756 1768
pascal@12756 1769 1. Extract the parameters from the bitstream.
pascal@12756 1770
pascal@12756 1771 2. Decode the LPC and interpolate (section 4.1).
pascal@12756 1772
pascal@12756 1773 3. Construct the 57/58-sample start state (section 4.2).
pascal@12756 1774
pascal@12756 1775 4. Set up the memory by using data from the decoded residual. This
pascal@12756 1776 memory is used for codebook construction. For blocks preceding
pascal@12756 1777 the start state, both the decoded residual and the target are time
pascal@12756 1778 reversed. Sub-frames are decoded in the same order as they were
pascal@12756 1779 encoded.
pascal@12756 1780
pascal@12756 1781 5. Construct the residuals of this sub-frame (gain[0]*cbvec[0] +
pascal@12756 1782 gain[1]*cbvec[1] + gain[2]*cbvec[2]). Repeat 4 and 5 until the
pascal@12756 1783 residual of all sub-blocks has been constructed.
pascal@12756 1784
pascal@12756 1785 6. Enhance the residual with the post filter (section 4.6).
pascal@12756 1786
pascal@12756 1787 7. Synthesis of the residual (section 4.7).
pascal@12756 1788
pascal@12756 1789 8. Post process with HP filter, if desired (section 4.8).
pascal@12756 1790
pascal@12756 1791
pascal@12756 1792
pascal@12756 1793
pascal@12756 1794 Andersen, et al. Experimental [Page 32]
pascal@12756 1795
pascal@12756 1796 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1797
pascal@12756 1798
pascal@12756 1799 4.1. LPC Filter Reconstruction
pascal@12756 1800
pascal@12756 1801 The decoding of the LP filter parameters is very straightforward.
pascal@12756 1802 For a set of three/six indices, the corresponding LSF vector(s) are
pascal@12756 1803 found by simple table lookup. For each of the LSF vectors, the three
pascal@12756 1804 split vectors are concatenated to obtain qlsf1 and qlsf2,
pascal@12756 1805 respectively (in the 20 ms mode only one LSF vector, qlsf, is
pascal@12756 1806 constructed). The next step is the stability check described in
pascal@12756 1807 section 3.2.5 followed by the interpolation scheme described in
pascal@12756 1808 section 3.2.6 (3.2.7 for 20 ms frames). The only difference is that
pascal@12756 1809 only the quantized LSFs are known at the decoder, and hence the
pascal@12756 1810 unquantized LSFs are not processed.
pascal@12756 1811
pascal@12756 1812 A reference implementation of the LPC filter reconstruction is given
pascal@12756 1813 in Appendix A.36.
pascal@12756 1814
pascal@12756 1815 4.2. Start State Reconstruction
pascal@12756 1816
pascal@12756 1817 The scalar encoded STATE_SHORT_LEN=58 (STATE_SHORT_LEN=57 in the 20
pascal@12756 1818 ms mode) state samples are reconstructed by 1) forming a set of
pascal@12756 1819 samples (by table lookup) from the index stream idxVec[n], 2)
pascal@12756 1820 multiplying the set with 1/scal=(10^qmax)/4.5, 3) time reversing the
pascal@12756 1821 57/58 samples, 4) filtering the time reversed block with the
pascal@12756 1822 dispersion (all-pass) filter used in the encoder (as described in
pascal@12756 1823 section 3.5.2); this compensates for the phase distortion of the
pascal@12756 1824 earlier filter operation, and 5 reversing the 57/58 samples from the
pascal@12756 1825 previous step.
pascal@12756 1826
pascal@12756 1827 in(0..(STATE_SHORT_LEN-1)) = time reversed samples from table
pascal@12756 1828 look-up,
pascal@12756 1829 idxVecDec((STATE_SHORT_LEN-1)..0)
pascal@12756 1830
pascal@12756 1831 in(STATE_SHORT_LEN..(2*STATE_SHORT_LEN-1)) = 0
pascal@12756 1832
pascal@12756 1833 Pk(z) = A~rk(z)/A~k(z), where
pascal@12756 1834 ___
pascal@12756 1835 \
pascal@12756 1836 A~rk(z)= z^(-LPC_FILTERORDER) + > a~ki*z^(i-(LPC_FILTERORDER-1))
pascal@12756 1837 /__
pascal@12756 1838 i=0...(LPC_FILTERORDER-1)
pascal@12756 1839
pascal@12756 1840 and A~k(z) is taken from the block where the start state begins
pascal@12756 1841
pascal@12756 1842 in -> Pk(z) -> filtered
pascal@12756 1843
pascal@12756 1844 out(k) = filtered(STATE_SHORT_LEN-1-k) +
pascal@12756 1845 filtered(2*STATE_SHORT_LEN-1-k),
pascal@12756 1846 k=0..(STATE_SHORT_LEN-1)
pascal@12756 1847
pascal@12756 1848
pascal@12756 1849
pascal@12756 1850 Andersen, et al. Experimental [Page 33]
pascal@12756 1851
pascal@12756 1852 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1853
pascal@12756 1854
pascal@12756 1855 The remaining 23/22 samples in the state are reconstructed by the
pascal@12756 1856 same adaptive codebook technique described in section 4.3. The
pascal@12756 1857 location bit determines whether these are the first or the last 23/22
pascal@12756 1858 samples of the 80-sample state vector. If the remaining 23/22
pascal@12756 1859 samples are the first samples, then the scalar encoded
pascal@12756 1860 STATE_SHORT_LEN state samples are time-reversed before initialization
pascal@12756 1861 of the adaptive codebook memory vector.
pascal@12756 1862
pascal@12756 1863 A reference implementation of the start state reconstruction is given
pascal@12756 1864 in Appendix A.44.
pascal@12756 1865
pascal@12756 1866 4.3. Excitation Decoding Loop
pascal@12756 1867
pascal@12756 1868 The decoding of the LPC excitation vector proceeds in the same order
pascal@12756 1869 in which the residual was encoded at the encoder. That is, after the
pascal@12756 1870 decoding of the entire 80-sample state vector, the forward sub-blocks
pascal@12756 1871 (corresponding to samples occurring after the state vector samples)
pascal@12756 1872 are decoded, and then the backward sub-blocks (corresponding to
pascal@12756 1873 samples occurring before the state vector) are decoded, resulting in
pascal@12756 1874 a fully decoded block of excitation signal samples.
pascal@12756 1875
pascal@12756 1876 In particular, each sub-block is decoded by using the multistage
pascal@12756 1877 adaptive codebook decoding module described in section 4.4. This
pascal@12756 1878 module relies upon an adaptive codebook memory constructed before
pascal@12756 1879 each run of the adaptive codebook decoding. The construction of the
pascal@12756 1880 adaptive codebook memory in the decoder is identical to the method
pascal@12756 1881 outlined in section 3.6.3, except that it is done on the codebook
pascal@12756 1882 memory without perceptual weighting.
pascal@12756 1883
pascal@12756 1884 For the initial forward sub-block, the last STATE_LEN=80 samples of
pascal@12756 1885 the length CB_LMEM=147 adaptive codebook memory are filled with the
pascal@12756 1886 samples of the state vector. For subsequent forward sub-blocks, the
pascal@12756 1887 first SUBL=40 samples of the adaptive codebook memory are discarded,
pascal@12756 1888 the remaining samples are shifted by SUBL samples toward the
pascal@12756 1889 beginning of the vector, and the newly decoded SUBL=40 samples are
pascal@12756 1890 placed at the end of the adaptive codebook memory. For backward
pascal@12756 1891 sub-blocks, the construction is similar, except that every vector of
pascal@12756 1892 samples involved is first time reversed.
pascal@12756 1893
pascal@12756 1894 A reference implementation of the excitation decoding loop is found
pascal@12756 1895 in Appendix A.5.
pascal@12756 1896
pascal@12756 1897
pascal@12756 1898
pascal@12756 1899
pascal@12756 1900
pascal@12756 1901
pascal@12756 1902
pascal@12756 1903
pascal@12756 1904
pascal@12756 1905
pascal@12756 1906 Andersen, et al. Experimental [Page 34]
pascal@12756 1907
pascal@12756 1908 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1909
pascal@12756 1910
pascal@12756 1911 4.4. Multistage Adaptive Codebook Decoding
pascal@12756 1912
pascal@12756 1913 The Multistage Adaptive Codebook Decoding module is used at both the
pascal@12756 1914 sender (encoder) and the receiver (decoder) ends to produce a
pascal@12756 1915 synthetic signal in the residual domain that is eventually used to
pascal@12756 1916 produce synthetic speech. The module takes the index values used to
pascal@12756 1917 construct vectors that are scaled and summed together to produce a
pascal@12756 1918 synthetic signal that is the output of the module.
pascal@12756 1919
pascal@12756 1920 4.4.1. Construction of the Decoded Excitation Signal
pascal@12756 1921
pascal@12756 1922 The unpacked index values provided at the input to the module are
pascal@12756 1923 references to extended codebooks, which are constructed as described
pascal@12756 1924 in section 3.6.3, except that they are based on the codebook memory
pascal@12756 1925 without the perceptual weighting. The unpacked three indices are
pascal@12756 1926 used to look up three codebook vectors. The unpacked three gain
pascal@12756 1927 indices are used to decode the corresponding 3 gains. In this
pascal@12756 1928 decoding, the successive rescaling, as described in section 3.6.4.2,
pascal@12756 1929 is applied.
pascal@12756 1930
pascal@12756 1931 A reference implementation of the adaptive codebook decoding is
pascal@12756 1932 listed in Appendix A.32.
pascal@12756 1933
pascal@12756 1934 4.5. Packet Loss Concealment
pascal@12756 1935
pascal@12756 1936 If packet loss occurs, the decoder receives a signal saying that
pascal@12756 1937 information regarding a block is lost. For such blocks it is
pascal@12756 1938 RECOMMENDED to use a Packet Loss Concealment (PLC) unit to create a
pascal@12756 1939 decoded signal that masks the effect of that packet loss. In the
pascal@12756 1940 following we will describe an example of a PLC unit that can be used
pascal@12756 1941 with the iLBC codec. As the PLC unit is used only at the decoder,
pascal@12756 1942 the PLC unit does not affect interoperability between
pascal@12756 1943 implementations. Other PLC implementations MAY therefore be used.
pascal@12756 1944
pascal@12756 1945 The PLC described operates on the LP filters and the excitation
pascal@12756 1946 signals and is based on the following principles:
pascal@12756 1947
pascal@12756 1948 4.5.1. Block Received Correctly and Previous Block Also Received
pascal@12756 1949
pascal@12756 1950 If the block is received correctly, the PLC only records state
pascal@12756 1951 information of the current block that can be used in case the next
pascal@12756 1952 block is lost. The LP filter coefficients for each sub-block and the
pascal@12756 1953 entire decoded excitation signal are all saved in the decoder state
pascal@12756 1954 structure. All of this information will be needed if the following
pascal@12756 1955 block is lost.
pascal@12756 1956
pascal@12756 1957
pascal@12756 1958
pascal@12756 1959
pascal@12756 1960
pascal@12756 1961
pascal@12756 1962 Andersen, et al. Experimental [Page 35]
pascal@12756 1963
pascal@12756 1964 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 1965
pascal@12756 1966
pascal@12756 1967 4.5.2. Block Not Received
pascal@12756 1968
pascal@12756 1969 If the block is not received, the block substitution is based on a
pascal@12756 1970 pitch-synchronous repetition of the excitation signal, which is
pascal@12756 1971 filtered by the last LP filter of the previous block. The previous
pascal@12756 1972 block's information is stored in the decoder state structure.
pascal@12756 1973
pascal@12756 1974 A correlation analysis is performed on the previous block's
pascal@12756 1975 excitation signal in order to detect the amount of pitch periodicity
pascal@12756 1976 and a pitch value. The correlation measure is also used to decide on
pascal@12756 1977 the voicing level (the degree to which the previous block's
pascal@12756 1978 excitation was a voiced or roughly periodic signal). The excitation
pascal@12756 1979 in the previous block is used to create an excitation for the block
pascal@12756 1980 to be substituted, such that the pitch of the previous block is
pascal@12756 1981 maintained. Therefore, the new excitation is constructed in a
pascal@12756 1982 pitch-synchronous manner. In order to avoid a buzzy-sounding
pascal@12756 1983 substituted block, a random excitation is mixed with the new pitch
pascal@12756 1984 periodic excitation, and the relative use of the two components is
pascal@12756 1985 computed from the correlation measure (voicing level).
pascal@12756 1986
pascal@12756 1987 For the block to be substituted, the newly constructed excitation
pascal@12756 1988 signal is then passed through the LP filter to produce the speech
pascal@12756 1989 that will be substituted for the lost block.
pascal@12756 1990
pascal@12756 1991 For several consecutive lost blocks, the packet loss concealment
pascal@12756 1992 continues in a similar manner. The correlation measure of the last
pascal@12756 1993 block received is still used along with the same pitch value. The LP
pascal@12756 1994 filters of the last block received are also used again. The energy
pascal@12756 1995 of the substituted excitation for consecutive lost blocks is
pascal@12756 1996 decreased, leading to a dampened excitation, and therefore to
pascal@12756 1997 dampened speech.
pascal@12756 1998
pascal@12756 1999 4.5.3. Block Received Correctly When Previous Block Not Received
pascal@12756 2000
pascal@12756 2001 For the case in which a block is received correctly when the previous
pascal@12756 2002 block was not, the correctly received block's directly decoded speech
pascal@12756 2003 (based solely on the received block) is not used as the actual
pascal@12756 2004 output. The reason for this is that the directly decoded speech does
pascal@12756 2005 not necessarily smoothly merge into the synthetic speech generated
pascal@12756 2006 for the previous lost block. If the two signals are not smoothly
pascal@12756 2007 merged, an audible discontinuity is accidentally produced.
pascal@12756 2008 Therefore, a correlation analysis between the two blocks of
pascal@12756 2009 excitation signal (the excitation of the previous concealed block and
pascal@12756 2010 that of the current received block) is performed to find the best
pascal@12756 2011 phase match. Then a simple overlap-add procedure is performed to
pascal@12756 2012 merge the previous excitation smoothly into the current block's
pascal@12756 2013 excitation.
pascal@12756 2014
pascal@12756 2015
pascal@12756 2016
pascal@12756 2017
pascal@12756 2018 Andersen, et al. Experimental [Page 36]
pascal@12756 2019
pascal@12756 2020 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2021
pascal@12756 2022
pascal@12756 2023 The exact implementation of the packet loss concealment does not
pascal@12756 2024 influence interoperability of the codec.
pascal@12756 2025
pascal@12756 2026 A reference implementation of the packet loss concealment is
pascal@12756 2027 suggested in Appendix A.14. Exact compliance with this suggested
pascal@12756 2028 algorithm is not needed for a reference implementation to be fully
pascal@12756 2029 compatible with the overall codec specification.
pascal@12756 2030
pascal@12756 2031 4.6. Enhancement
pascal@12756 2032
pascal@12756 2033 The decoder contains an enhancement unit that operates on the
pascal@12756 2034 reconstructed excitation signal. The enhancement unit increases the
pascal@12756 2035 perceptual quality of the reconstructed signal by reducing the
pascal@12756 2036 speech-correlated noise in the voiced speech segments. Compared to
pascal@12756 2037 traditional postfilters, the enhancer has an advantage in that it can
pascal@12756 2038 only modify the excitation signal slightly. This means that there is
pascal@12756 2039 no risk of over enhancement. The enhancer works very similarly for
pascal@12756 2040 both the 20 ms frame size mode and the 30 ms frame size mode.
pascal@12756 2041
pascal@12756 2042 For the mode with 20 ms frame size, the enhancer uses a memory of six
pascal@12756 2043 80-sample excitation blocks prior in time plus the two new 80-sample
pascal@12756 2044 excitation blocks. For each block of 160 new unenhanced excitation
pascal@12756 2045 samples, 160 enhanced excitation samples are produced. The enhanced
pascal@12756 2046 excitation is 40-sample delayed compared to the unenhanced
pascal@12756 2047 excitation, as the enhancer algorithm uses lookahead.
pascal@12756 2048
pascal@12756 2049 For the mode with 30 ms frame size, the enhancer uses a memory of
pascal@12756 2050 five 80-sample excitation blocks prior in time plus the three new
pascal@12756 2051 80-sample excitation blocks. For each block of 240 new unenhanced
pascal@12756 2052 excitation samples, 240 enhanced excitation samples are produced.
pascal@12756 2053 The enhanced excitation is 80-sample delayed compared to the
pascal@12756 2054 unenhanced excitation, as the enhancer algorithm uses lookahead.
pascal@12756 2055
pascal@12756 2056 Outline of Enhancer
pascal@12756 2057
pascal@12756 2058 The speech enhancement unit operates on sub-blocks of 80 samples,
pascal@12756 2059 which means that there are two/three 80 sample sub-blocks per frame.
pascal@12756 2060 Each of these two/three sub-blocks is enhanced separately, but in an
pascal@12756 2061 analogous manner.
pascal@12756 2062
pascal@12756 2063
pascal@12756 2064
pascal@12756 2065
pascal@12756 2066
pascal@12756 2067
pascal@12756 2068
pascal@12756 2069
pascal@12756 2070
pascal@12756 2071
pascal@12756 2072
pascal@12756 2073
pascal@12756 2074 Andersen, et al. Experimental [Page 37]
pascal@12756 2075
pascal@12756 2076 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2077
pascal@12756 2078
pascal@12756 2079 unenhanced residual
pascal@12756 2080 |
pascal@12756 2081 | +---------------+ +--------------+
pascal@12756 2082 +-> | 1. Pitch Est | -> | 2. Find PSSQ | -------->
pascal@12756 2083 +---------------+ | +--------------+
pascal@12756 2084 +-----<-------<------<--+
pascal@12756 2085 +------------+ enh block 0..1/2 |
pascal@12756 2086 -> | 3. Smooth | |
pascal@12756 2087 +------------+ |
pascal@12756 2088 \ |
pascal@12756 2089 /\ |
pascal@12756 2090 / \ Already |
pascal@12756 2091 / 4. \----------->----------->-----------+ |
pascal@12756 2092 \Crit/ Fulfilled | |
pascal@12756 2093 \? / v |
pascal@12756 2094 \/ | |
pascal@12756 2095 \ +-----------------+ +---------+ | |
pascal@12756 2096 Not +->| 5. Use Constr. | -> | 6. Mix | ----->
pascal@12756 2097 Fulfilled +-----------------+ +---------+
pascal@12756 2098
pascal@12756 2099 ---------------> enhanced residual
pascal@12756 2100
pascal@12756 2101 Figure 4.2. Flow chart of the enhancer.
pascal@12756 2102
pascal@12756 2103 1. Pitch estimation of each of the two/three new 80-sample blocks.
pascal@12756 2104
pascal@12756 2105 2. Find the pitch-period-synchronous sequence n (for block k) by a
pascal@12756 2106 search around the estimated pitch value. Do this for n=1,2,3,
pascal@12756 2107 -1,-2,-3.
pascal@12756 2108
pascal@12756 2109 3. Calculate the smoothed residual generated by the six pitch-
pascal@12756 2110 period-synchronous sequences from prior step.
pascal@12756 2111
pascal@12756 2112 4. Check if the smoothed residual satisfies the criterion (section
pascal@12756 2113 4.6.4).
pascal@12756 2114
pascal@12756 2115 5. Use constraint to calculate mixing factor (section 4.6.5).
pascal@12756 2116
pascal@12756 2117 6. Mix smoothed signal with unenhanced residual (pssq(n) n=0).
pascal@12756 2118
pascal@12756 2119 The main idea of the enhancer is to find three 80 sample blocks
pascal@12756 2120 before and three 80-sample blocks after the analyzed unenhanced sub-
pascal@12756 2121 block and to use these to improve the quality of the excitation in
pascal@12756 2122 that sub-block. The six blocks are chosen so that they have the
pascal@12756 2123 highest possible correlation with the unenhanced sub-block that is
pascal@12756 2124 being enhanced. In other words, the six blocks are pitch-period-
pascal@12756 2125 synchronous sequences to the unenhanced sub-block.
pascal@12756 2126
pascal@12756 2127
pascal@12756 2128
pascal@12756 2129
pascal@12756 2130 Andersen, et al. Experimental [Page 38]
pascal@12756 2131
pascal@12756 2132 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2133
pascal@12756 2134
pascal@12756 2135 A linear combination of the six pitch-period-synchronous sequences is
pascal@12756 2136 calculated that approximates the sub-block. If the squared error
pascal@12756 2137 between the approximation and the unenhanced sub-block is small
pascal@12756 2138 enough, the enhanced residual is set equal to this approximation.
pascal@12756 2139 For the cases when the squared error criterion is not fulfilled, a
pascal@12756 2140 linear combination of the approximation and the unenhanced residual
pascal@12756 2141 forms the enhanced residual.
pascal@12756 2142
pascal@12756 2143 4.6.1. Estimating the Pitch
pascal@12756 2144
pascal@12756 2145 Pitch estimates are needed to determine the locations of the pitch-
pascal@12756 2146 period-synchronous sequences in a complexity-efficient way. For each
pascal@12756 2147 of the new two/three sub-blocks, a pitch estimate is calculated by
pascal@12756 2148 finding the maximum correlation in the range from lag 20 to lag 120.
pascal@12756 2149 These pitch estimates are used to narrow down the search for the best
pascal@12756 2150 possible pitch-period-synchronous sequences.
pascal@12756 2151
pascal@12756 2152 4.6.2. Determination of the Pitch-Synchronous Sequences
pascal@12756 2153
pascal@12756 2154 Upon receiving the pitch estimates from the prior step, the enhancer
pascal@12756 2155 analyzes and enhances one 80-sample sub-block at a time. The pitch-
pascal@12756 2156 period-synchronous-sequences pssq(n) can be viewed as vectors of
pascal@12756 2157 length 80 samples each shifted n*lag samples from the current sub-
pascal@12756 2158 block. The six pitch-period-synchronous-sequences, pssq(-3) to
pascal@12756 2159 pssq(-1) and pssq(1) to pssq(3), are found one at a time by the steps
pascal@12756 2160 below:
pascal@12756 2161
pascal@12756 2162 1) Calculate the estimate of the position of the pssq(n). For
pascal@12756 2163 pssq(n) in front of pssq(0) (n > 0), the location of the pssq(n)
pascal@12756 2164 is estimated by moving one pitch estimate forward in time from the
pascal@12756 2165 exact location of pssq(n-1). Similarly, pssq(n) behind pssq(0) (n
pascal@12756 2166 < 0) is estimated by moving one pitch estimate backward in time
pascal@12756 2167 from the exact location of pssq(n+1). If the estimated pssq(n)
pascal@12756 2168 vector location is totally within the enhancer memory (Figure
pascal@12756 2169 4.3), steps 2, 3, and 4 are performed, otherwise the pssq(n) is
pascal@12756 2170 set to zeros.
pascal@12756 2171
pascal@12756 2172 2) Compute the correlation between the unenhanced excitation and
pascal@12756 2173 vectors around the estimated location interval of pssq(n). The
pascal@12756 2174 correlation is calculated in the interval estimated location +/- 2
pascal@12756 2175 samples. This results in five correlation values.
pascal@12756 2176
pascal@12756 2177 3) The five correlation values are upsampled by a factor of 4, by
pascal@12756 2178 using four simple upsampling filters (MA filters with coefficients
pascal@12756 2179 upsFilter1.. upsFilter4). Within these the maximum value is
pascal@12756 2180 found, which specifies the best pitch-period with a resolution of
pascal@12756 2181 a quarter of a sample.
pascal@12756 2182
pascal@12756 2183
pascal@12756 2184
pascal@12756 2185
pascal@12756 2186 Andersen, et al. Experimental [Page 39]
pascal@12756 2187
pascal@12756 2188 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2189
pascal@12756 2190
pascal@12756 2191 upsFilter1[7]={0.000000 0.000000 0.000000 1.000000
pascal@12756 2192 0.000000 0.000000 0.000000}
pascal@12756 2193 upsFilter2[7]={0.015625 -0.076904 0.288330 0.862061
pascal@12756 2194 -0.106445 0.018799 -0.015625}
pascal@12756 2195 upsFilter3[7]={0.023682 -0.124268 0.601563 0.601563
pascal@12756 2196 -0.124268 0.023682 -0.023682}
pascal@12756 2197 upsFilter4[7]={0.018799 -0.106445 0.862061 0.288330
pascal@12756 2198 -0.076904 0.015625 -0.018799}
pascal@12756 2199
pascal@12756 2200 4) Generate the pssq(n) vector by upsampling of the excitation memory
pascal@12756 2201 and extracting the sequence that corresponds to the lag delay that
pascal@12756 2202 was calculated in prior step.
pascal@12756 2203
pascal@12756 2204 With the steps above, all the pssq(n) can be found in an iterative
pascal@12756 2205 manner, first moving backward in time from pssq(0) and then forward
pascal@12756 2206 in time from pssq(0).
pascal@12756 2207
pascal@12756 2208
pascal@12756 2209 0 159 319 479 639
pascal@12756 2210 +---------------------------------------------------------------+
pascal@12756 2211 | -5 | -4 | -3 | -2 | -1 | 0 | 1 | 2 |
pascal@12756 2212 +---------------------------------------------------------------+
pascal@12756 2213 |pssq 0 |
pascal@12756 2214 |pssq -1| |pssq 1 |
pascal@12756 2215 |pssq -2| |pssq 2 |
pascal@12756 2216 |pssq -3| |pssq 3 |
pascal@12756 2217
pascal@12756 2218 Figure 4.3. Enhancement for 20 ms frame size.
pascal@12756 2219
pascal@12756 2220 Figure 4.3 depicts pitch-period-synchronous sequences in the
pascal@12756 2221 enhancement of the first 80 sample block in the 20 ms frame size
pascal@12756 2222 mode. The unenhanced signal input is stored in the last two sub-
pascal@12756 2223 blocks (1 - 2), and the six other sub-blocks contain unenhanced
pascal@12756 2224 residual prior-in-time. We perform the enhancement algorithm on two
pascal@12756 2225 blocks of 80 samples, where the first of the two blocks consists of
pascal@12756 2226 the last 40 samples of sub-block 0 and the first 40 samples of sub-
pascal@12756 2227 block 1. The second 80-sample block consists of the last 40 samples
pascal@12756 2228 of sub-block 1 and the first 40 samples of sub-block 2.
pascal@12756 2229
pascal@12756 2230
pascal@12756 2231
pascal@12756 2232
pascal@12756 2233
pascal@12756 2234
pascal@12756 2235
pascal@12756 2236
pascal@12756 2237
pascal@12756 2238
pascal@12756 2239
pascal@12756 2240
pascal@12756 2241
pascal@12756 2242 Andersen, et al. Experimental [Page 40]
pascal@12756 2243
pascal@12756 2244 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2245
pascal@12756 2246
pascal@12756 2247 0 159 319 479 639
pascal@12756 2248 +---------------------------------------------------------------+
pascal@12756 2249 | -4 | -3 | -2 | -1 | 0 | 1 | 2 | 3 |
pascal@12756 2250 +---------------------------------------------------------------+
pascal@12756 2251 |pssq 0 |
pascal@12756 2252 |pssq -1| |pssq 1 |
pascal@12756 2253 |pssq -2| |pssq 2 |
pascal@12756 2254 |pssq -3| |pssq 3 |
pascal@12756 2255
pascal@12756 2256 Figure 4.4. Enhancement for 30 ms frame size.
pascal@12756 2257
pascal@12756 2258 Figure 4.4 depicts pitch-period-synchronous sequences in the
pascal@12756 2259 enhancement of the first 80-sample block in the 30 ms frame size
pascal@12756 2260 mode. The unenhanced signal input is stored in the last three sub-
pascal@12756 2261 blocks (1 - 3). The five other sub-blocks contain unenhanced
pascal@12756 2262 residual prior-in-time. The enhancement algorithm is performed on
pascal@12756 2263 the three 80 sample sub-blocks 0, 1, and 2.
pascal@12756 2264
pascal@12756 2265 4.6.3. Calculation of the Smoothed Excitation
pascal@12756 2266
pascal@12756 2267 A linear combination of the six pssq(n) (n!=0) form a smoothed
pascal@12756 2268 approximation, z, of pssq(0). Most of the weight is put on the
pascal@12756 2269 sequences that are close to pssq(0), as these are likely to be most
pascal@12756 2270 similar to pssq(0). The smoothed vector is also rescaled so that the
pascal@12756 2271 energy of z is the same as the energy of pssq(0).
pascal@12756 2272
pascal@12756 2273 ___
pascal@12756 2274 \
pascal@12756 2275 y = > pssq(i) * pssq_weight(i)
pascal@12756 2276 /__
pascal@12756 2277 i=-3,-2,-1,1,2,3
pascal@12756 2278
pascal@12756 2279 pssq_weight(i) = 0.5*(1-cos(2*pi*(i+4)/(2*3+2)))
pascal@12756 2280
pascal@12756 2281 z = C * y, where C = ||pssq(0)||/||y||
pascal@12756 2282
pascal@12756 2283 4.6.4. Enhancer Criterion
pascal@12756 2284
pascal@12756 2285 The criterion of the enhancer is that the enhanced excitation is not
pascal@12756 2286 allowed to differ much from the unenhanced excitation. This
pascal@12756 2287 criterion is checked for each 80-sample sub-block.
pascal@12756 2288
pascal@12756 2289 e < (b * ||pssq(0)||^2), where b=0.05 and (Constraint 1)
pascal@12756 2290
pascal@12756 2291 e = (pssq(0)-z)*(pssq(0)-z), and "*" means the dot product
pascal@12756 2292
pascal@12756 2293
pascal@12756 2294
pascal@12756 2295
pascal@12756 2296
pascal@12756 2297
pascal@12756 2298 Andersen, et al. Experimental [Page 41]
pascal@12756 2299
pascal@12756 2300 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2301
pascal@12756 2302
pascal@12756 2303 4.6.5. Enhancing the excitation
pascal@12756 2304
pascal@12756 2305 From the criterion in the previous section, it is clear that the
pascal@12756 2306 excitation is not allowed to change much. The purpose of this
pascal@12756 2307 constraint is to prevent the creation of an enhanced signal
pascal@12756 2308 significantly different from the original signal. This also means
pascal@12756 2309 that the constraint limits the numerical size of the errors that the
pascal@12756 2310 enhancement procedure can make. That is especially important in
pascal@12756 2311 unvoiced segments and background noise segments for which increased
pascal@12756 2312 periodicity could lead to lower perceived quality.
pascal@12756 2313
pascal@12756 2314 When the constraint in the prior section is not met, the enhanced
pascal@12756 2315 residual is instead calculated through a constrained optimization by
pascal@12756 2316 using the Lagrange multiplier technique. The new constraint is that
pascal@12756 2317
pascal@12756 2318 e = (b * ||pssq(0)||^2) (Constraint 2)
pascal@12756 2319
pascal@12756 2320 We distinguish two solution regions for the optimization: 1) the
pascal@12756 2321 region where the first constraint is fulfilled and 2) the region
pascal@12756 2322 where the first constraint is not fulfilled and the second constraint
pascal@12756 2323 must be used.
pascal@12756 2324
pascal@12756 2325 In the first case, where the second constraint is not needed, the
pascal@12756 2326 optimized re-estimated vector is simply z, the energy-scaled version
pascal@12756 2327 of y.
pascal@12756 2328
pascal@12756 2329 In the second case, where the second constraint is activated and
pascal@12756 2330 becomes an equality constraint, we have
pascal@12756 2331
pascal@12756 2332 z= A*y + B*pssq(0)
pascal@12756 2333
pascal@12756 2334 where
pascal@12756 2335
pascal@12756 2336 A = sqrt((b-b^2/4)*(w00*w00)/ (w11*w00 + w10*w10)) and
pascal@12756 2337
pascal@12756 2338 w11 = pssq(0)*pssq(0)
pascal@12756 2339 w00 = y*y
pascal@12756 2340 w10 = y*pssq(0) (* symbolizes the dot product)
pascal@12756 2341
pascal@12756 2342 and
pascal@12756 2343
pascal@12756 2344 B = 1 - b/2 - A * w10/w00
pascal@12756 2345
pascal@12756 2346 Appendix A.16 contains a listing of a reference implementation for
pascal@12756 2347 the enhancement method.
pascal@12756 2348
pascal@12756 2349
pascal@12756 2350
pascal@12756 2351
pascal@12756 2352
pascal@12756 2353
pascal@12756 2354 Andersen, et al. Experimental [Page 42]
pascal@12756 2355
pascal@12756 2356 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2357
pascal@12756 2358
pascal@12756 2359 4.7. Synthesis Filtering
pascal@12756 2360
pascal@12756 2361 Upon decoding or PLC of the LP excitation block, the decoded speech
pascal@12756 2362 block is obtained by running the decoded LP synthesis filter,
pascal@12756 2363 1/A~k(z), over the block. The synthesis filters have to be shifted
pascal@12756 2364 to compensate for the delay in the enhancer. For 20 ms frame size
pascal@12756 2365 mode, they SHOULD be shifted one 40-sample sub-block, and for 30 ms
pascal@12756 2366 frame size mode, they SHOULD be shifted two 40-sample sub-blocks.
pascal@12756 2367 The LP coefficients SHOULD be changed at the first sample of every
pascal@12756 2368 sub-block while keeping the filter state. For PLC blocks, one
pascal@12756 2369 solution is to apply the last LP coefficients of the last decoded
pascal@12756 2370 speech block for all sub-blocks.
pascal@12756 2371
pascal@12756 2372 The reference implementation for the synthesis filtering can be found
pascal@12756 2373 in Appendix A.48.
pascal@12756 2374
pascal@12756 2375 4.8. Post Filtering
pascal@12756 2376
pascal@12756 2377 If desired, the decoded block can be filtered by a high-pass filter.
pascal@12756 2378 This removes the low frequencies of the decoded signal. A reference
pascal@12756 2379 implementation of this, with cutoff at 65 Hz, is shown in Appendix
pascal@12756 2380 A.30.
pascal@12756 2381
pascal@12756 2382 5. Security Considerations
pascal@12756 2383
pascal@12756 2384 This algorithm for the coding of speech signals is not subject to any
pascal@12756 2385 known security consideration; however, its RTP payload format [1] is
pascal@12756 2386 subject to several considerations, which are addressed there.
pascal@12756 2387 Confidentiality of the media streams is achieved by encryption;
pascal@12756 2388 therefore external mechanisms, such as SRTP [5], MAY be used for that
pascal@12756 2389 purpose.
pascal@12756 2390
pascal@12756 2391 6. Evaluation of the iLBC Implementations
pascal@12756 2392
pascal@12756 2393 It is possible and suggested to evaluate certain iLBC implementation
pascal@12756 2394 by utilizing methodology and tools available at
pascal@12756 2395 http://www.ilbcfreeware.org/evaluation.html
pascal@12756 2396
pascal@12756 2397 7. References
pascal@12756 2398
pascal@12756 2399 7.1. Normative References
pascal@12756 2400
pascal@12756 2401 [1] Duric, A. and S. Andersen, "Real-time Transport Protocol (RTP)
pascal@12756 2402 Payload Format for internet Low Bit Rate Codec (iLBC) Speech",
pascal@12756 2403 RFC 3952, December 2004.
pascal@12756 2404
pascal@12756 2405 [2] Bradner, S., "Key words for use in RFCs to Indicate Requirement
pascal@12756 2406 Levels", BCP 14, RFC 2119, March 1997.
pascal@12756 2407
pascal@12756 2408
pascal@12756 2409
pascal@12756 2410 Andersen, et al. Experimental [Page 43]
pascal@12756 2411
pascal@12756 2412 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2413
pascal@12756 2414
pascal@12756 2415 [3] PacketCable(TM) Audio/Video Codecs Specification, Cable
pascal@12756 2416 Television Laboratories, Inc.
pascal@12756 2417
pascal@12756 2418 7.2. Informative References
pascal@12756 2419
pascal@12756 2420 [4] ITU-T Recommendation G.711, available online from the ITU
pascal@12756 2421 bookstore at http://www.itu.int.
pascal@12756 2422
pascal@12756 2423 [5] Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norman,
pascal@12756 2424 "The Secure Real Time Transport Protocol (SRTP)", RFC 3711, March
pascal@12756 2425 2004.
pascal@12756 2426
pascal@12756 2427 8. Acknowledgements
pascal@12756 2428
pascal@12756 2429 This extensive work, besides listed authors, has the following
pascal@12756 2430 authors, who could not have been listed among "official" authors (due
pascal@12756 2431 to IESG restrictions in the number of authors who can be listed):
pascal@12756 2432
pascal@12756 2433 Manohar N. Murthi (Department of Electrical and Computer
pascal@12756 2434 Engineering, University of Miami), Fredrik Galschiodt, Julian
pascal@12756 2435 Spittka, and Jan Skoglund (Global IP Sound).
pascal@12756 2436
pascal@12756 2437 The authors are deeply indebted to the following people and thank
pascal@12756 2438 them sincerely:
pascal@12756 2439
pascal@12756 2440 Henry Sinnreich, Patrik Faltstrom, Alan Johnston, and Jean-
pascal@12756 2441 Francois Mule for great support of the iLBC initiative and for
pascal@12756 2442 valuable feedback and comments.
pascal@12756 2443
pascal@12756 2444 Peter Vary, Frank Mertz, and Christoph Erdmann (RWTH Aachen);
pascal@12756 2445 Vladimir Cuperman (Niftybox LLC); Thomas Eriksson (Chalmers Univ
pascal@12756 2446 of Tech), and Gernot Kubin (TU Graz), for thorough review of the
pascal@12756 2447 iLBC document and their valuable feedback and remarks.
pascal@12756 2448
pascal@12756 2449
pascal@12756 2450
pascal@12756 2451
pascal@12756 2452
pascal@12756 2453
pascal@12756 2454
pascal@12756 2455
pascal@12756 2456
pascal@12756 2457
pascal@12756 2458
pascal@12756 2459
pascal@12756 2460
pascal@12756 2461
pascal@12756 2462
pascal@12756 2463
pascal@12756 2464
pascal@12756 2465
pascal@12756 2466 Andersen, et al. Experimental [Page 44]
pascal@12756 2467
pascal@12756 2468 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2469
pascal@12756 2470
pascal@12756 2471 APPENDIX A. Reference Implementation
pascal@12756 2472
pascal@12756 2473 This appendix contains the complete c-code for a reference
pascal@12756 2474 implementation of encoder and decoder for the specified codec.
pascal@12756 2475
pascal@12756 2476 The c-code consists of the following files with highest-level
pascal@12756 2477 functions:
pascal@12756 2478
pascal@12756 2479 iLBC_test.c: main function for evaluation purpose
pascal@12756 2480 iLBC_encode.h: encoder header
pascal@12756 2481 iLBC_encode.c: encoder function
pascal@12756 2482 iLBC_decode.h: decoder header
pascal@12756 2483 iLBC_decode.c: decoder function
pascal@12756 2484
pascal@12756 2485 The following files contain global defines and constants:
pascal@12756 2486
pascal@12756 2487 iLBC_define.h: global defines
pascal@12756 2488 constants.h: global constants header
pascal@12756 2489 constants.c: global constants memory allocations
pascal@12756 2490
pascal@12756 2491 The following files contain subroutines:
pascal@12756 2492
pascal@12756 2493 anaFilter.h: lpc analysis filter header
pascal@12756 2494 anaFilter.c: lpc analysis filter function
pascal@12756 2495 createCB.h: codebook construction header
pascal@12756 2496 createCB.c: codebook construction function
pascal@12756 2497 doCPLC.h: packet loss concealment header
pascal@12756 2498 doCPLC.c: packet loss concealment function
pascal@12756 2499 enhancer.h: signal enhancement header
pascal@12756 2500 enhancer.c: signal enhancement function
pascal@12756 2501 filter.h: general filter header
pascal@12756 2502 filter.c: general filter functions
pascal@12756 2503 FrameClassify.h: start state classification header
pascal@12756 2504 FrameClassify.c: start state classification function
pascal@12756 2505 gainquant.h: gain quantization header
pascal@12756 2506 gainquant.c: gain quantization function
pascal@12756 2507 getCBvec.h: codebook vector construction header
pascal@12756 2508 getCBvec.c: codebook vector construction function
pascal@12756 2509 helpfun.h: general purpose header
pascal@12756 2510 helpfun.c: general purpose functions
pascal@12756 2511 hpInput.h: input high pass filter header
pascal@12756 2512 hpInput.c: input high pass filter function
pascal@12756 2513 hpOutput.h: output high pass filter header
pascal@12756 2514 hpOutput.c: output high pass filter function
pascal@12756 2515 iCBConstruct.h: excitation decoding header
pascal@12756 2516 iCBConstruct.c: excitation decoding function
pascal@12756 2517 iCBSearch.h: excitation encoding header
pascal@12756 2518 iCBSearch.c: excitation encoding function
pascal@12756 2519
pascal@12756 2520
pascal@12756 2521
pascal@12756 2522 Andersen, et al. Experimental [Page 45]
pascal@12756 2523
pascal@12756 2524 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2525
pascal@12756 2526
pascal@12756 2527 LPCdecode.h: lpc decoding header
pascal@12756 2528 LPCdecode.c: lpc decoding function
pascal@12756 2529 LPCencode.h: lpc encoding header
pascal@12756 2530 LPCencode.c: lpc encoding function
pascal@12756 2531 lsf.h: line spectral frequencies header
pascal@12756 2532 lsf.c: line spectral frequencies functions
pascal@12756 2533 packing.h: bitstream packetization header
pascal@12756 2534 packing.c: bitstream packetization functions
pascal@12756 2535 StateConstructW.h: state decoding header
pascal@12756 2536 StateConstructW.c: state decoding functions
pascal@12756 2537 StateSearchW.h: state encoding header
pascal@12756 2538 StateSearchW.c: state encoding function
pascal@12756 2539 syntFilter.h: lpc synthesis filter header
pascal@12756 2540 syntFilter.c: lpc synthesis filter function
pascal@12756 2541
pascal@12756 2542 The implementation is portable and should work on many different
pascal@12756 2543 platforms. However, it is not difficult to optimize the
pascal@12756 2544 implementation on particular platforms, an exercise left to the
pascal@12756 2545 reader.
pascal@12756 2546
pascal@12756 2547 A.1. iLBC_test.c
pascal@12756 2548
pascal@12756 2549 /******************************************************************
pascal@12756 2550
pascal@12756 2551 iLBC Speech Coder ANSI-C Source Code
pascal@12756 2552
pascal@12756 2553 iLBC_test.c
pascal@12756 2554
pascal@12756 2555 Copyright (C) The Internet Society (2004).
pascal@12756 2556 All Rights Reserved.
pascal@12756 2557
pascal@12756 2558 ******************************************************************/
pascal@12756 2559
pascal@12756 2560 #include <math.h>
pascal@12756 2561 #include <stdlib.h>
pascal@12756 2562 #include <stdio.h>
pascal@12756 2563 #include <string.h>
pascal@12756 2564 #include "iLBC_define.h"
pascal@12756 2565 #include "iLBC_encode.h"
pascal@12756 2566 #include "iLBC_decode.h"
pascal@12756 2567
pascal@12756 2568 /* Runtime statistics */
pascal@12756 2569 #include <time.h>
pascal@12756 2570
pascal@12756 2571 #define ILBCNOOFWORDS_MAX (NO_OF_BYTES_30MS/2)
pascal@12756 2572
pascal@12756 2573 /*----------------------------------------------------------------*
pascal@12756 2574 * Encoder interface function
pascal@12756 2575
pascal@12756 2576
pascal@12756 2577
pascal@12756 2578 Andersen, et al. Experimental [Page 46]
pascal@12756 2579
pascal@12756 2580 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2581
pascal@12756 2582
pascal@12756 2583 *---------------------------------------------------------------*/
pascal@12756 2584
pascal@12756 2585 short encode( /* (o) Number of bytes encoded */
pascal@12756 2586 iLBC_Enc_Inst_t *iLBCenc_inst,
pascal@12756 2587 /* (i/o) Encoder instance */
pascal@12756 2588 short *encoded_data, /* (o) The encoded bytes */
pascal@12756 2589 short *data /* (i) The signal block to encode*/
pascal@12756 2590 ){
pascal@12756 2591 float block[BLOCKL_MAX];
pascal@12756 2592 int k;
pascal@12756 2593
pascal@12756 2594 /* convert signal to float */
pascal@12756 2595
pascal@12756 2596 for (k=0; k<iLBCenc_inst->blockl; k++)
pascal@12756 2597 block[k] = (float)data[k];
pascal@12756 2598
pascal@12756 2599 /* do the actual encoding */
pascal@12756 2600
pascal@12756 2601 iLBC_encode((unsigned char *)encoded_data, block, iLBCenc_inst);
pascal@12756 2602
pascal@12756 2603
pascal@12756 2604 return (iLBCenc_inst->no_of_bytes);
pascal@12756 2605 }
pascal@12756 2606
pascal@12756 2607 /*----------------------------------------------------------------*
pascal@12756 2608 * Decoder interface function
pascal@12756 2609 *---------------------------------------------------------------*/
pascal@12756 2610
pascal@12756 2611 short decode( /* (o) Number of decoded samples */
pascal@12756 2612 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */
pascal@12756 2613 short *decoded_data, /* (o) Decoded signal block*/
pascal@12756 2614 short *encoded_data, /* (i) Encoded bytes */
pascal@12756 2615 short mode /* (i) 0=PL, 1=Normal */
pascal@12756 2616 ){
pascal@12756 2617 int k;
pascal@12756 2618 float decblock[BLOCKL_MAX], dtmp;
pascal@12756 2619
pascal@12756 2620 /* check if mode is valid */
pascal@12756 2621
pascal@12756 2622 if (mode<0 || mode>1) {
pascal@12756 2623 printf("\nERROR - Wrong mode - 0, 1 allowed\n"); exit(3);}
pascal@12756 2624
pascal@12756 2625 /* do actual decoding of block */
pascal@12756 2626
pascal@12756 2627 iLBC_decode(decblock, (unsigned char *)encoded_data,
pascal@12756 2628 iLBCdec_inst, mode);
pascal@12756 2629
pascal@12756 2630 /* convert to short */
pascal@12756 2631
pascal@12756 2632
pascal@12756 2633
pascal@12756 2634 Andersen, et al. Experimental [Page 47]
pascal@12756 2635
pascal@12756 2636 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2637
pascal@12756 2638
pascal@12756 2639 for (k=0; k<iLBCdec_inst->blockl; k++){
pascal@12756 2640 dtmp=decblock[k];
pascal@12756 2641
pascal@12756 2642 if (dtmp<MIN_SAMPLE)
pascal@12756 2643 dtmp=MIN_SAMPLE;
pascal@12756 2644 else if (dtmp>MAX_SAMPLE)
pascal@12756 2645 dtmp=MAX_SAMPLE;
pascal@12756 2646 decoded_data[k] = (short) dtmp;
pascal@12756 2647 }
pascal@12756 2648
pascal@12756 2649 return (iLBCdec_inst->blockl);
pascal@12756 2650 }
pascal@12756 2651
pascal@12756 2652 /*---------------------------------------------------------------*
pascal@12756 2653 * Main program to test iLBC encoding and decoding
pascal@12756 2654 *
pascal@12756 2655 * Usage:
pascal@12756 2656 * exefile_name.exe <infile> <bytefile> <outfile> <channel>
pascal@12756 2657 *
pascal@12756 2658 * <infile> : Input file, speech for encoder (16-bit pcm file)
pascal@12756 2659 * <bytefile> : Bit stream output from the encoder
pascal@12756 2660 * <outfile> : Output file, decoded speech (16-bit pcm file)
pascal@12756 2661 * <channel> : Bit error file, optional (16-bit)
pascal@12756 2662 * 1 - Packet received correctly
pascal@12756 2663 * 0 - Packet Lost
pascal@12756 2664 *
pascal@12756 2665 *--------------------------------------------------------------*/
pascal@12756 2666
pascal@12756 2667 int main(int argc, char* argv[])
pascal@12756 2668 {
pascal@12756 2669
pascal@12756 2670 /* Runtime statistics */
pascal@12756 2671
pascal@12756 2672 float starttime;
pascal@12756 2673 float runtime;
pascal@12756 2674 float outtime;
pascal@12756 2675
pascal@12756 2676 FILE *ifileid,*efileid,*ofileid, *cfileid;
pascal@12756 2677 short data[BLOCKL_MAX];
pascal@12756 2678 short encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX];
pascal@12756 2679 int len;
pascal@12756 2680 short pli, mode;
pascal@12756 2681 int blockcount = 0;
pascal@12756 2682 int packetlosscount = 0;
pascal@12756 2683
pascal@12756 2684 /* Create structs */
pascal@12756 2685 iLBC_Enc_Inst_t Enc_Inst;
pascal@12756 2686 iLBC_Dec_Inst_t Dec_Inst;
pascal@12756 2687
pascal@12756 2688
pascal@12756 2689
pascal@12756 2690 Andersen, et al. Experimental [Page 48]
pascal@12756 2691
pascal@12756 2692 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2693
pascal@12756 2694
pascal@12756 2695 /* get arguments and open files */
pascal@12756 2696
pascal@12756 2697 if ((argc!=5) && (argc!=6)) {
pascal@12756 2698 fprintf(stderr,
pascal@12756 2699 "\n*-----------------------------------------------*\n");
pascal@12756 2700 fprintf(stderr,
pascal@12756 2701 " %s <20,30> input encoded decoded (channel)\n\n",
pascal@12756 2702 argv[0]);
pascal@12756 2703 fprintf(stderr,
pascal@12756 2704 " mode : Frame size for the encoding/decoding\n");
pascal@12756 2705 fprintf(stderr,
pascal@12756 2706 " 20 - 20 ms\n");
pascal@12756 2707 fprintf(stderr,
pascal@12756 2708 " 30 - 30 ms\n");
pascal@12756 2709 fprintf(stderr,
pascal@12756 2710 " input : Speech for encoder (16-bit pcm file)\n");
pascal@12756 2711 fprintf(stderr,
pascal@12756 2712 " encoded : Encoded bit stream\n");
pascal@12756 2713 fprintf(stderr,
pascal@12756 2714 " decoded : Decoded speech (16-bit pcm file)\n");
pascal@12756 2715 fprintf(stderr,
pascal@12756 2716 " channel : Packet loss pattern, optional (16-bit)\n");
pascal@12756 2717 fprintf(stderr,
pascal@12756 2718 " 1 - Packet received correctly\n");
pascal@12756 2719 fprintf(stderr,
pascal@12756 2720 " 0 - Packet Lost\n");
pascal@12756 2721 fprintf(stderr,
pascal@12756 2722 "*-----------------------------------------------*\n\n");
pascal@12756 2723 exit(1);
pascal@12756 2724 }
pascal@12756 2725 mode=atoi(argv[1]);
pascal@12756 2726 if (mode != 20 && mode != 30) {
pascal@12756 2727 fprintf(stderr,"Wrong mode %s, must be 20, or 30\n",
pascal@12756 2728 argv[1]);
pascal@12756 2729 exit(2);
pascal@12756 2730 }
pascal@12756 2731 if ( (ifileid=fopen(argv[2],"rb")) == NULL) {
pascal@12756 2732 fprintf(stderr,"Cannot open input file %s\n", argv[2]);
pascal@12756 2733 exit(2);}
pascal@12756 2734 if ( (efileid=fopen(argv[3],"wb")) == NULL) {
pascal@12756 2735 fprintf(stderr, "Cannot open encoded file %s\n",
pascal@12756 2736 argv[3]); exit(1);}
pascal@12756 2737 if ( (ofileid=fopen(argv[4],"wb")) == NULL) {
pascal@12756 2738 fprintf(stderr, "Cannot open decoded file %s\n",
pascal@12756 2739 argv[4]); exit(1);}
pascal@12756 2740 if (argc==6) {
pascal@12756 2741 if( (cfileid=fopen(argv[5],"rb")) == NULL) {
pascal@12756 2742 fprintf(stderr, "Cannot open channel file %s\n",
pascal@12756 2743
pascal@12756 2744
pascal@12756 2745
pascal@12756 2746 Andersen, et al. Experimental [Page 49]
pascal@12756 2747
pascal@12756 2748 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2749
pascal@12756 2750
pascal@12756 2751 argv[5]);
pascal@12756 2752 exit(1);
pascal@12756 2753 }
pascal@12756 2754 } else {
pascal@12756 2755 cfileid=NULL;
pascal@12756 2756 }
pascal@12756 2757
pascal@12756 2758 /* print info */
pascal@12756 2759
pascal@12756 2760 fprintf(stderr, "\n");
pascal@12756 2761 fprintf(stderr,
pascal@12756 2762 "*---------------------------------------------------*\n");
pascal@12756 2763 fprintf(stderr,
pascal@12756 2764 "* *\n");
pascal@12756 2765 fprintf(stderr,
pascal@12756 2766 "* iLBC test program *\n");
pascal@12756 2767 fprintf(stderr,
pascal@12756 2768 "* *\n");
pascal@12756 2769 fprintf(stderr,
pascal@12756 2770 "* *\n");
pascal@12756 2771 fprintf(stderr,
pascal@12756 2772 "*---------------------------------------------------*\n");
pascal@12756 2773 fprintf(stderr,"\nMode : %2d ms\n", mode);
pascal@12756 2774 fprintf(stderr,"Input file : %s\n", argv[2]);
pascal@12756 2775 fprintf(stderr,"Encoded file : %s\n", argv[3]);
pascal@12756 2776 fprintf(stderr,"Output file : %s\n", argv[4]);
pascal@12756 2777 if (argc==6) {
pascal@12756 2778 fprintf(stderr,"Channel file : %s\n", argv[5]);
pascal@12756 2779 }
pascal@12756 2780 fprintf(stderr,"\n");
pascal@12756 2781
pascal@12756 2782 /* Initialization */
pascal@12756 2783
pascal@12756 2784 initEncode(&Enc_Inst, mode);
pascal@12756 2785 initDecode(&Dec_Inst, mode, 1);
pascal@12756 2786
pascal@12756 2787 /* Runtime statistics */
pascal@12756 2788
pascal@12756 2789 starttime=clock()/(float)CLOCKS_PER_SEC;
pascal@12756 2790
pascal@12756 2791 /* loop over input blocks */
pascal@12756 2792
pascal@12756 2793 while (fread(data,sizeof(short),Enc_Inst.blockl,ifileid)==
pascal@12756 2794 Enc_Inst.blockl) {
pascal@12756 2795
pascal@12756 2796 blockcount++;
pascal@12756 2797
pascal@12756 2798 /* encoding */
pascal@12756 2799
pascal@12756 2800
pascal@12756 2801
pascal@12756 2802 Andersen, et al. Experimental [Page 50]
pascal@12756 2803
pascal@12756 2804 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2805
pascal@12756 2806
pascal@12756 2807 fprintf(stderr, "--- Encoding block %i --- ",blockcount);
pascal@12756 2808 len=encode(&Enc_Inst, encoded_data, data);
pascal@12756 2809 fprintf(stderr, "\r");
pascal@12756 2810
pascal@12756 2811 /* write byte file */
pascal@12756 2812
pascal@12756 2813 fwrite(encoded_data, sizeof(unsigned char), len, efileid);
pascal@12756 2814
pascal@12756 2815 /* get channel data if provided */
pascal@12756 2816 if (argc==6) {
pascal@12756 2817 if (fread(&pli, sizeof(short), 1, cfileid)) {
pascal@12756 2818 if ((pli!=0)&&(pli!=1)) {
pascal@12756 2819 fprintf(stderr, "Error in channel file\n");
pascal@12756 2820 exit(0);
pascal@12756 2821 }
pascal@12756 2822 if (pli==0) {
pascal@12756 2823 /* Packet loss -> remove info from frame */
pascal@12756 2824 memset(encoded_data, 0,
pascal@12756 2825 sizeof(short)*ILBCNOOFWORDS_MAX);
pascal@12756 2826 packetlosscount++;
pascal@12756 2827 }
pascal@12756 2828 } else {
pascal@12756 2829 fprintf(stderr, "Error. Channel file too short\n");
pascal@12756 2830 exit(0);
pascal@12756 2831 }
pascal@12756 2832 } else {
pascal@12756 2833 pli=1;
pascal@12756 2834 }
pascal@12756 2835
pascal@12756 2836 /* decoding */
pascal@12756 2837
pascal@12756 2838 fprintf(stderr, "--- Decoding block %i --- ",blockcount);
pascal@12756 2839
pascal@12756 2840 len=decode(&Dec_Inst, decoded_data, encoded_data, pli);
pascal@12756 2841 fprintf(stderr, "\r");
pascal@12756 2842
pascal@12756 2843 /* write output file */
pascal@12756 2844
pascal@12756 2845 fwrite(decoded_data,sizeof(short),len,ofileid);
pascal@12756 2846 }
pascal@12756 2847
pascal@12756 2848 /* Runtime statistics */
pascal@12756 2849
pascal@12756 2850 runtime = (float)(clock()/(float)CLOCKS_PER_SEC-starttime);
pascal@12756 2851 outtime = (float)((float)blockcount*(float)mode/1000.0);
pascal@12756 2852 printf("\n\nLength of speech file: %.1f s\n", outtime);
pascal@12756 2853 printf("Packet loss : %.1f%%\n",
pascal@12756 2854 100.0*(float)packetlosscount/(float)blockcount);
pascal@12756 2855
pascal@12756 2856
pascal@12756 2857
pascal@12756 2858 Andersen, et al. Experimental [Page 51]
pascal@12756 2859
pascal@12756 2860 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2861
pascal@12756 2862
pascal@12756 2863 printf("Time to run iLBC :");
pascal@12756 2864 printf(" %.1f s (%.1f %% of realtime)\n\n", runtime,
pascal@12756 2865 (100*runtime/outtime));
pascal@12756 2866
pascal@12756 2867 /* close files */
pascal@12756 2868
pascal@12756 2869 fclose(ifileid); fclose(efileid); fclose(ofileid);
pascal@12756 2870 if (argc==6) {
pascal@12756 2871 fclose(cfileid);
pascal@12756 2872 }
pascal@12756 2873 return(0);
pascal@12756 2874 }
pascal@12756 2875
pascal@12756 2876 A.2. iLBC_encode.h
pascal@12756 2877
pascal@12756 2878 /******************************************************************
pascal@12756 2879
pascal@12756 2880 iLBC Speech Coder ANSI-C Source Code
pascal@12756 2881
pascal@12756 2882 iLBC_encode.h
pascal@12756 2883
pascal@12756 2884 Copyright (C) The Internet Society (2004).
pascal@12756 2885 All Rights Reserved.
pascal@12756 2886
pascal@12756 2887 ******************************************************************/
pascal@12756 2888
pascal@12756 2889 #ifndef __iLBC_ILBCENCODE_H
pascal@12756 2890 #define __iLBC_ILBCENCODE_H
pascal@12756 2891
pascal@12756 2892 #include "iLBC_define.h"
pascal@12756 2893
pascal@12756 2894 short initEncode( /* (o) Number of bytes
pascal@12756 2895 encoded */
pascal@12756 2896 iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */
pascal@12756 2897 int mode /* (i) frame size mode */
pascal@12756 2898 );
pascal@12756 2899
pascal@12756 2900 void iLBC_encode(
pascal@12756 2901
pascal@12756 2902 unsigned char *bytes, /* (o) encoded data bits iLBC */
pascal@12756 2903 float *block, /* (o) speech vector to
pascal@12756 2904 encode */
pascal@12756 2905 iLBC_Enc_Inst_t *iLBCenc_inst /* (i/o) the general encoder
pascal@12756 2906 state */
pascal@12756 2907 );
pascal@12756 2908
pascal@12756 2909 #endif
pascal@12756 2910
pascal@12756 2911
pascal@12756 2912
pascal@12756 2913
pascal@12756 2914 Andersen, et al. Experimental [Page 52]
pascal@12756 2915
pascal@12756 2916 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2917
pascal@12756 2918
pascal@12756 2919 A.3. iLBC_encode.c
pascal@12756 2920
pascal@12756 2921 /******************************************************************
pascal@12756 2922
pascal@12756 2923 iLBC Speech Coder ANSI-C Source Code
pascal@12756 2924
pascal@12756 2925 iLBC_encode.c
pascal@12756 2926
pascal@12756 2927 Copyright (C) The Internet Society (2004).
pascal@12756 2928 All Rights Reserved.
pascal@12756 2929
pascal@12756 2930 ******************************************************************/
pascal@12756 2931
pascal@12756 2932 #include <math.h>
pascal@12756 2933 #include <stdlib.h>
pascal@12756 2934 #include <string.h>
pascal@12756 2935
pascal@12756 2936 #include "iLBC_define.h"
pascal@12756 2937 #include "LPCencode.h"
pascal@12756 2938 #include "FrameClassify.h"
pascal@12756 2939 #include "StateSearchW.h"
pascal@12756 2940 #include "StateConstructW.h"
pascal@12756 2941 #include "helpfun.h"
pascal@12756 2942 #include "constants.h"
pascal@12756 2943 #include "packing.h"
pascal@12756 2944 #include "iCBSearch.h"
pascal@12756 2945 #include "iCBConstruct.h"
pascal@12756 2946 #include "hpInput.h"
pascal@12756 2947 #include "anaFilter.h"
pascal@12756 2948 #include "syntFilter.h"
pascal@12756 2949
pascal@12756 2950 /*----------------------------------------------------------------*
pascal@12756 2951 * Initiation of encoder instance.
pascal@12756 2952 *---------------------------------------------------------------*/
pascal@12756 2953
pascal@12756 2954 short initEncode( /* (o) Number of bytes
pascal@12756 2955 encoded */
pascal@12756 2956 iLBC_Enc_Inst_t *iLBCenc_inst, /* (i/o) Encoder instance */
pascal@12756 2957 int mode /* (i) frame size mode */
pascal@12756 2958 ){
pascal@12756 2959 iLBCenc_inst->mode = mode;
pascal@12756 2960 if (mode==30) {
pascal@12756 2961 iLBCenc_inst->blockl = BLOCKL_30MS;
pascal@12756 2962 iLBCenc_inst->nsub = NSUB_30MS;
pascal@12756 2963 iLBCenc_inst->nasub = NASUB_30MS;
pascal@12756 2964 iLBCenc_inst->lpc_n = LPC_N_30MS;
pascal@12756 2965 iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS;
pascal@12756 2966 iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS;
pascal@12756 2967
pascal@12756 2968
pascal@12756 2969
pascal@12756 2970 Andersen, et al. Experimental [Page 53]
pascal@12756 2971
pascal@12756 2972 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 2973
pascal@12756 2974
pascal@12756 2975 iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS;
pascal@12756 2976 /* ULP init */
pascal@12756 2977 iLBCenc_inst->ULP_inst=&ULP_30msTbl;
pascal@12756 2978 }
pascal@12756 2979 else if (mode==20) {
pascal@12756 2980 iLBCenc_inst->blockl = BLOCKL_20MS;
pascal@12756 2981 iLBCenc_inst->nsub = NSUB_20MS;
pascal@12756 2982 iLBCenc_inst->nasub = NASUB_20MS;
pascal@12756 2983 iLBCenc_inst->lpc_n = LPC_N_20MS;
pascal@12756 2984 iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS;
pascal@12756 2985 iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS;
pascal@12756 2986 iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS;
pascal@12756 2987 /* ULP init */
pascal@12756 2988 iLBCenc_inst->ULP_inst=&ULP_20msTbl;
pascal@12756 2989 }
pascal@12756 2990 else {
pascal@12756 2991 exit(2);
pascal@12756 2992 }
pascal@12756 2993
pascal@12756 2994 memset((*iLBCenc_inst).anaMem, 0,
pascal@12756 2995 LPC_FILTERORDER*sizeof(float));
pascal@12756 2996 memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl,
pascal@12756 2997 LPC_FILTERORDER*sizeof(float));
pascal@12756 2998 memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl,
pascal@12756 2999 LPC_FILTERORDER*sizeof(float));
pascal@12756 3000 memset((*iLBCenc_inst).lpc_buffer, 0,
pascal@12756 3001 (LPC_LOOKBACK+BLOCKL_MAX)*sizeof(float));
pascal@12756 3002 memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float));
pascal@12756 3003
pascal@12756 3004 return (iLBCenc_inst->no_of_bytes);
pascal@12756 3005 }
pascal@12756 3006
pascal@12756 3007 /*----------------------------------------------------------------*
pascal@12756 3008 * main encoder function
pascal@12756 3009 *---------------------------------------------------------------*/
pascal@12756 3010
pascal@12756 3011 void iLBC_encode(
pascal@12756 3012 unsigned char *bytes, /* (o) encoded data bits iLBC */
pascal@12756 3013 float *block, /* (o) speech vector to
pascal@12756 3014 encode */
pascal@12756 3015 iLBC_Enc_Inst_t *iLBCenc_inst /* (i/o) the general encoder
pascal@12756 3016 state */
pascal@12756 3017 ){
pascal@12756 3018
pascal@12756 3019 float data[BLOCKL_MAX];
pascal@12756 3020 float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX];
pascal@12756 3021
pascal@12756 3022 int start, idxForMax, idxVec[STATE_LEN];
pascal@12756 3023
pascal@12756 3024
pascal@12756 3025
pascal@12756 3026 Andersen, et al. Experimental [Page 54]
pascal@12756 3027
pascal@12756 3028 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3029
pascal@12756 3030
pascal@12756 3031 float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];
pascal@12756 3032 int n, k, meml_gotten, Nfor, Nback, i, pos;
pascal@12756 3033 int gain_index[CB_NSTAGES*NASUB_MAX],
pascal@12756 3034 extra_gain_index[CB_NSTAGES];
pascal@12756 3035 int cb_index[CB_NSTAGES*NASUB_MAX],extra_cb_index[CB_NSTAGES];
pascal@12756 3036 int lsf_i[LSF_NSPLIT*LPC_N_MAX];
pascal@12756 3037 unsigned char *pbytes;
pascal@12756 3038 int diff, start_pos, state_first;
pascal@12756 3039 float en1, en2;
pascal@12756 3040 int index, ulp, firstpart;
pascal@12756 3041 int subcount, subframe;
pascal@12756 3042 float weightState[LPC_FILTERORDER];
pascal@12756 3043 float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)];
pascal@12756 3044 float weightdenum[NSUB_MAX*(LPC_FILTERORDER+1)];
pascal@12756 3045 float decresidual[BLOCKL_MAX];
pascal@12756 3046
pascal@12756 3047 /* high pass filtering of input signal if such is not done
pascal@12756 3048 prior to calling this function */
pascal@12756 3049
pascal@12756 3050 hpInput(block, iLBCenc_inst->blockl,
pascal@12756 3051 data, (*iLBCenc_inst).hpimem);
pascal@12756 3052
pascal@12756 3053 /* otherwise simply copy */
pascal@12756 3054
pascal@12756 3055 /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float));*/
pascal@12756 3056
pascal@12756 3057 /* LPC of hp filtered input data */
pascal@12756 3058
pascal@12756 3059 LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst);
pascal@12756 3060
pascal@12756 3061
pascal@12756 3062 /* inverse filter to get residual */
pascal@12756 3063
pascal@12756 3064 for (n=0; n<iLBCenc_inst->nsub; n++) {
pascal@12756 3065 anaFilter(&data[n*SUBL], &syntdenum[n*(LPC_FILTERORDER+1)],
pascal@12756 3066 SUBL, &residual[n*SUBL], iLBCenc_inst->anaMem);
pascal@12756 3067 }
pascal@12756 3068
pascal@12756 3069 /* find state location */
pascal@12756 3070
pascal@12756 3071 start = FrameClassify(iLBCenc_inst, residual);
pascal@12756 3072
pascal@12756 3073 /* check if state should be in first or last part of the
pascal@12756 3074 two subframes */
pascal@12756 3075
pascal@12756 3076 diff = STATE_LEN - iLBCenc_inst->state_short_len;
pascal@12756 3077 en1 = 0;
pascal@12756 3078 index = (start-1)*SUBL;
pascal@12756 3079
pascal@12756 3080
pascal@12756 3081
pascal@12756 3082 Andersen, et al. Experimental [Page 55]
pascal@12756 3083
pascal@12756 3084 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3085
pascal@12756 3086
pascal@12756 3087 for (i = 0; i < iLBCenc_inst->state_short_len; i++) {
pascal@12756 3088 en1 += residual[index+i]*residual[index+i];
pascal@12756 3089 }
pascal@12756 3090 en2 = 0;
pascal@12756 3091 index = (start-1)*SUBL+diff;
pascal@12756 3092 for (i = 0; i < iLBCenc_inst->state_short_len; i++) {
pascal@12756 3093 en2 += residual[index+i]*residual[index+i];
pascal@12756 3094 }
pascal@12756 3095
pascal@12756 3096
pascal@12756 3097 if (en1 > en2) {
pascal@12756 3098 state_first = 1;
pascal@12756 3099 start_pos = (start-1)*SUBL;
pascal@12756 3100 } else {
pascal@12756 3101 state_first = 0;
pascal@12756 3102 start_pos = (start-1)*SUBL + diff;
pascal@12756 3103 }
pascal@12756 3104
pascal@12756 3105 /* scalar quantization of state */
pascal@12756 3106
pascal@12756 3107 StateSearchW(iLBCenc_inst, &residual[start_pos],
pascal@12756 3108 &syntdenum[(start-1)*(LPC_FILTERORDER+1)],
pascal@12756 3109 &weightdenum[(start-1)*(LPC_FILTERORDER+1)], &idxForMax,
pascal@12756 3110 idxVec, iLBCenc_inst->state_short_len, state_first);
pascal@12756 3111
pascal@12756 3112 StateConstructW(idxForMax, idxVec,
pascal@12756 3113 &syntdenum[(start-1)*(LPC_FILTERORDER+1)],
pascal@12756 3114 &decresidual[start_pos], iLBCenc_inst->state_short_len);
pascal@12756 3115
pascal@12756 3116 /* predictive quantization in state */
pascal@12756 3117
pascal@12756 3118 if (state_first) { /* put adaptive part in the end */
pascal@12756 3119
pascal@12756 3120 /* setup memory */
pascal@12756 3121
pascal@12756 3122 memset(mem, 0,
pascal@12756 3123 (CB_MEML-iLBCenc_inst->state_short_len)*sizeof(float));
pascal@12756 3124 memcpy(mem+CB_MEML-iLBCenc_inst->state_short_len,
pascal@12756 3125 decresidual+start_pos,
pascal@12756 3126 iLBCenc_inst->state_short_len*sizeof(float));
pascal@12756 3127 memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 3128
pascal@12756 3129 /* encode sub-frames */
pascal@12756 3130
pascal@12756 3131 iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index,
pascal@12756 3132 &residual[start_pos+iLBCenc_inst->state_short_len],
pascal@12756 3133 mem+CB_MEML-stMemLTbl,
pascal@12756 3134 stMemLTbl, diff, CB_NSTAGES,
pascal@12756 3135
pascal@12756 3136
pascal@12756 3137
pascal@12756 3138 Andersen, et al. Experimental [Page 56]
pascal@12756 3139
pascal@12756 3140 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3141
pascal@12756 3142
pascal@12756 3143 &weightdenum[start*(LPC_FILTERORDER+1)],
pascal@12756 3144 weightState, 0);
pascal@12756 3145
pascal@12756 3146 /* construct decoded vector */
pascal@12756 3147
pascal@12756 3148 iCBConstruct(
pascal@12756 3149 &decresidual[start_pos+iLBCenc_inst->state_short_len],
pascal@12756 3150 extra_cb_index, extra_gain_index,
pascal@12756 3151 mem+CB_MEML-stMemLTbl,
pascal@12756 3152 stMemLTbl, diff, CB_NSTAGES);
pascal@12756 3153
pascal@12756 3154 }
pascal@12756 3155 else { /* put adaptive part in the beginning */
pascal@12756 3156
pascal@12756 3157 /* create reversed vectors for prediction */
pascal@12756 3158
pascal@12756 3159 for (k=0; k<diff; k++) {
pascal@12756 3160 reverseResidual[k] = residual[(start+1)*SUBL-1
pascal@12756 3161 -(k+iLBCenc_inst->state_short_len)];
pascal@12756 3162 }
pascal@12756 3163
pascal@12756 3164 /* setup memory */
pascal@12756 3165
pascal@12756 3166 meml_gotten = iLBCenc_inst->state_short_len;
pascal@12756 3167 for (k=0; k<meml_gotten; k++) {
pascal@12756 3168 mem[CB_MEML-1-k] = decresidual[start_pos + k];
pascal@12756 3169 }
pascal@12756 3170 memset(mem, 0, (CB_MEML-k)*sizeof(float));
pascal@12756 3171 memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 3172
pascal@12756 3173 /* encode sub-frames */
pascal@12756 3174
pascal@12756 3175 iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index,
pascal@12756 3176 reverseResidual, mem+CB_MEML-stMemLTbl, stMemLTbl,
pascal@12756 3177 diff, CB_NSTAGES,
pascal@12756 3178 &weightdenum[(start-1)*(LPC_FILTERORDER+1)],
pascal@12756 3179 weightState, 0);
pascal@12756 3180
pascal@12756 3181 /* construct decoded vector */
pascal@12756 3182
pascal@12756 3183 iCBConstruct(reverseDecresidual, extra_cb_index,
pascal@12756 3184 extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl,
pascal@12756 3185 diff, CB_NSTAGES);
pascal@12756 3186
pascal@12756 3187 /* get decoded residual from reversed vector */
pascal@12756 3188
pascal@12756 3189 for (k=0; k<diff; k++) {
pascal@12756 3190 decresidual[start_pos-1-k] = reverseDecresidual[k];
pascal@12756 3191
pascal@12756 3192
pascal@12756 3193
pascal@12756 3194 Andersen, et al. Experimental [Page 57]
pascal@12756 3195
pascal@12756 3196 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3197
pascal@12756 3198
pascal@12756 3199 }
pascal@12756 3200 }
pascal@12756 3201
pascal@12756 3202 /* counter for predicted sub-frames */
pascal@12756 3203
pascal@12756 3204 subcount=0;
pascal@12756 3205
pascal@12756 3206 /* forward prediction of sub-frames */
pascal@12756 3207
pascal@12756 3208 Nfor = iLBCenc_inst->nsub-start-1;
pascal@12756 3209
pascal@12756 3210
pascal@12756 3211 if ( Nfor > 0 ) {
pascal@12756 3212
pascal@12756 3213 /* setup memory */
pascal@12756 3214
pascal@12756 3215 memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));
pascal@12756 3216 memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL,
pascal@12756 3217 STATE_LEN*sizeof(float));
pascal@12756 3218 memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 3219
pascal@12756 3220 /* loop over sub-frames to encode */
pascal@12756 3221
pascal@12756 3222 for (subframe=0; subframe<Nfor; subframe++) {
pascal@12756 3223
pascal@12756 3224 /* encode sub-frame */
pascal@12756 3225
pascal@12756 3226 iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES,
pascal@12756 3227 gain_index+subcount*CB_NSTAGES,
pascal@12756 3228 &residual[(start+1+subframe)*SUBL],
pascal@12756 3229 mem+CB_MEML-memLfTbl[subcount],
pascal@12756 3230 memLfTbl[subcount], SUBL, CB_NSTAGES,
pascal@12756 3231 &weightdenum[(start+1+subframe)*
pascal@12756 3232 (LPC_FILTERORDER+1)],
pascal@12756 3233 weightState, subcount+1);
pascal@12756 3234
pascal@12756 3235 /* construct decoded vector */
pascal@12756 3236
pascal@12756 3237 iCBConstruct(&decresidual[(start+1+subframe)*SUBL],
pascal@12756 3238 cb_index+subcount*CB_NSTAGES,
pascal@12756 3239 gain_index+subcount*CB_NSTAGES,
pascal@12756 3240 mem+CB_MEML-memLfTbl[subcount],
pascal@12756 3241 memLfTbl[subcount], SUBL, CB_NSTAGES);
pascal@12756 3242
pascal@12756 3243 /* update memory */
pascal@12756 3244
pascal@12756 3245 memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
pascal@12756 3246 memcpy(mem+CB_MEML-SUBL,
pascal@12756 3247
pascal@12756 3248
pascal@12756 3249
pascal@12756 3250 Andersen, et al. Experimental [Page 58]
pascal@12756 3251
pascal@12756 3252 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3253
pascal@12756 3254
pascal@12756 3255 &decresidual[(start+1+subframe)*SUBL],
pascal@12756 3256 SUBL*sizeof(float));
pascal@12756 3257 memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 3258
pascal@12756 3259 subcount++;
pascal@12756 3260 }
pascal@12756 3261 }
pascal@12756 3262
pascal@12756 3263
pascal@12756 3264 /* backward prediction of sub-frames */
pascal@12756 3265
pascal@12756 3266 Nback = start-1;
pascal@12756 3267
pascal@12756 3268
pascal@12756 3269 if ( Nback > 0 ) {
pascal@12756 3270
pascal@12756 3271 /* create reverse order vectors */
pascal@12756 3272
pascal@12756 3273 for (n=0; n<Nback; n++) {
pascal@12756 3274 for (k=0; k<SUBL; k++) {
pascal@12756 3275 reverseResidual[n*SUBL+k] =
pascal@12756 3276 residual[(start-1)*SUBL-1-n*SUBL-k];
pascal@12756 3277 reverseDecresidual[n*SUBL+k] =
pascal@12756 3278 decresidual[(start-1)*SUBL-1-n*SUBL-k];
pascal@12756 3279 }
pascal@12756 3280 }
pascal@12756 3281
pascal@12756 3282 /* setup memory */
pascal@12756 3283
pascal@12756 3284 meml_gotten = SUBL*(iLBCenc_inst->nsub+1-start);
pascal@12756 3285
pascal@12756 3286
pascal@12756 3287 if ( meml_gotten > CB_MEML ) {
pascal@12756 3288 meml_gotten=CB_MEML;
pascal@12756 3289 }
pascal@12756 3290 for (k=0; k<meml_gotten; k++) {
pascal@12756 3291 mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];
pascal@12756 3292 }
pascal@12756 3293 memset(mem, 0, (CB_MEML-k)*sizeof(float));
pascal@12756 3294 memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 3295
pascal@12756 3296 /* loop over sub-frames to encode */
pascal@12756 3297
pascal@12756 3298 for (subframe=0; subframe<Nback; subframe++) {
pascal@12756 3299
pascal@12756 3300 /* encode sub-frame */
pascal@12756 3301
pascal@12756 3302 iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES,
pascal@12756 3303
pascal@12756 3304
pascal@12756 3305
pascal@12756 3306 Andersen, et al. Experimental [Page 59]
pascal@12756 3307
pascal@12756 3308 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3309
pascal@12756 3310
pascal@12756 3311 gain_index+subcount*CB_NSTAGES,
pascal@12756 3312 &reverseResidual[subframe*SUBL],
pascal@12756 3313 mem+CB_MEML-memLfTbl[subcount],
pascal@12756 3314 memLfTbl[subcount], SUBL, CB_NSTAGES,
pascal@12756 3315 &weightdenum[(start-2-subframe)*
pascal@12756 3316 (LPC_FILTERORDER+1)],
pascal@12756 3317 weightState, subcount+1);
pascal@12756 3318
pascal@12756 3319 /* construct decoded vector */
pascal@12756 3320
pascal@12756 3321 iCBConstruct(&reverseDecresidual[subframe*SUBL],
pascal@12756 3322 cb_index+subcount*CB_NSTAGES,
pascal@12756 3323 gain_index+subcount*CB_NSTAGES,
pascal@12756 3324 mem+CB_MEML-memLfTbl[subcount],
pascal@12756 3325 memLfTbl[subcount], SUBL, CB_NSTAGES);
pascal@12756 3326
pascal@12756 3327 /* update memory */
pascal@12756 3328
pascal@12756 3329 memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
pascal@12756 3330 memcpy(mem+CB_MEML-SUBL,
pascal@12756 3331 &reverseDecresidual[subframe*SUBL],
pascal@12756 3332 SUBL*sizeof(float));
pascal@12756 3333 memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 3334
pascal@12756 3335 subcount++;
pascal@12756 3336
pascal@12756 3337 }
pascal@12756 3338
pascal@12756 3339 /* get decoded residual from reversed vector */
pascal@12756 3340
pascal@12756 3341 for (i=0; i<SUBL*Nback; i++) {
pascal@12756 3342 decresidual[SUBL*Nback - i - 1] =
pascal@12756 3343 reverseDecresidual[i];
pascal@12756 3344 }
pascal@12756 3345 }
pascal@12756 3346 /* end encoding part */
pascal@12756 3347
pascal@12756 3348 /* adjust index */
pascal@12756 3349 index_conv_enc(cb_index);
pascal@12756 3350
pascal@12756 3351 /* pack bytes */
pascal@12756 3352
pascal@12756 3353 pbytes=bytes;
pascal@12756 3354 pos=0;
pascal@12756 3355
pascal@12756 3356 /* loop over the 3 ULP classes */
pascal@12756 3357
pascal@12756 3358 for (ulp=0; ulp<3; ulp++) {
pascal@12756 3359
pascal@12756 3360
pascal@12756 3361
pascal@12756 3362 Andersen, et al. Experimental [Page 60]
pascal@12756 3363
pascal@12756 3364 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3365
pascal@12756 3366
pascal@12756 3367
pascal@12756 3368 /* LSF */
pascal@12756 3369 for (k=0; k<LSF_NSPLIT*iLBCenc_inst->lpc_n; k++) {
pascal@12756 3370 packsplit(&lsf_i[k], &firstpart, &lsf_i[k],
pascal@12756 3371 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp],
pascal@12756 3372 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp]+
pascal@12756 3373 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+1]+
pascal@12756 3374 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+2]);
pascal@12756 3375 dopack( &pbytes, firstpart,
pascal@12756 3376 iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos);
pascal@12756 3377 }
pascal@12756 3378
pascal@12756 3379 /* Start block info */
pascal@12756 3380
pascal@12756 3381 packsplit(&start, &firstpart, &start,
pascal@12756 3382 iLBCenc_inst->ULP_inst->start_bits[ulp],
pascal@12756 3383 iLBCenc_inst->ULP_inst->start_bits[ulp]+
pascal@12756 3384 iLBCenc_inst->ULP_inst->start_bits[ulp+1]+
pascal@12756 3385 iLBCenc_inst->ULP_inst->start_bits[ulp+2]);
pascal@12756 3386 dopack( &pbytes, firstpart,
pascal@12756 3387 iLBCenc_inst->ULP_inst->start_bits[ulp], &pos);
pascal@12756 3388
pascal@12756 3389 packsplit(&state_first, &firstpart, &state_first,
pascal@12756 3390 iLBCenc_inst->ULP_inst->startfirst_bits[ulp],
pascal@12756 3391 iLBCenc_inst->ULP_inst->startfirst_bits[ulp]+
pascal@12756 3392 iLBCenc_inst->ULP_inst->startfirst_bits[ulp+1]+
pascal@12756 3393 iLBCenc_inst->ULP_inst->startfirst_bits[ulp+2]);
pascal@12756 3394 dopack( &pbytes, firstpart,
pascal@12756 3395 iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos);
pascal@12756 3396
pascal@12756 3397 packsplit(&idxForMax, &firstpart, &idxForMax,
pascal@12756 3398 iLBCenc_inst->ULP_inst->scale_bits[ulp],
pascal@12756 3399 iLBCenc_inst->ULP_inst->scale_bits[ulp]+
pascal@12756 3400 iLBCenc_inst->ULP_inst->scale_bits[ulp+1]+
pascal@12756 3401 iLBCenc_inst->ULP_inst->scale_bits[ulp+2]);
pascal@12756 3402 dopack( &pbytes, firstpart,
pascal@12756 3403 iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos);
pascal@12756 3404
pascal@12756 3405 for (k=0; k<iLBCenc_inst->state_short_len; k++) {
pascal@12756 3406 packsplit(idxVec+k, &firstpart, idxVec+k,
pascal@12756 3407 iLBCenc_inst->ULP_inst->state_bits[ulp],
pascal@12756 3408 iLBCenc_inst->ULP_inst->state_bits[ulp]+
pascal@12756 3409 iLBCenc_inst->ULP_inst->state_bits[ulp+1]+
pascal@12756 3410 iLBCenc_inst->ULP_inst->state_bits[ulp+2]);
pascal@12756 3411 dopack( &pbytes, firstpart,
pascal@12756 3412 iLBCenc_inst->ULP_inst->state_bits[ulp], &pos);
pascal@12756 3413 }
pascal@12756 3414
pascal@12756 3415
pascal@12756 3416
pascal@12756 3417
pascal@12756 3418 Andersen, et al. Experimental [Page 61]
pascal@12756 3419
pascal@12756 3420 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3421
pascal@12756 3422
pascal@12756 3423 /* 23/22 (20ms/30ms) sample block */
pascal@12756 3424
pascal@12756 3425 for (k=0;k<CB_NSTAGES;k++) {
pascal@12756 3426 packsplit(extra_cb_index+k, &firstpart,
pascal@12756 3427 extra_cb_index+k,
pascal@12756 3428 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp],
pascal@12756 3429 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp]+
pascal@12756 3430 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+1]+
pascal@12756 3431 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+2]);
pascal@12756 3432 dopack( &pbytes, firstpart,
pascal@12756 3433 iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp],
pascal@12756 3434 &pos);
pascal@12756 3435 }
pascal@12756 3436
pascal@12756 3437 for (k=0;k<CB_NSTAGES;k++) {
pascal@12756 3438 packsplit(extra_gain_index+k, &firstpart,
pascal@12756 3439 extra_gain_index+k,
pascal@12756 3440 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp],
pascal@12756 3441 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp]+
pascal@12756 3442 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+1]+
pascal@12756 3443 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+2]);
pascal@12756 3444 dopack( &pbytes, firstpart,
pascal@12756 3445 iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp],
pascal@12756 3446 &pos);
pascal@12756 3447 }
pascal@12756 3448
pascal@12756 3449 /* The two/four (20ms/30ms) 40 sample sub-blocks */
pascal@12756 3450
pascal@12756 3451 for (i=0; i<iLBCenc_inst->nasub; i++) {
pascal@12756 3452 for (k=0; k<CB_NSTAGES; k++) {
pascal@12756 3453 packsplit(cb_index+i*CB_NSTAGES+k, &firstpart,
pascal@12756 3454 cb_index+i*CB_NSTAGES+k,
pascal@12756 3455 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp],
pascal@12756 3456 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp]+
pascal@12756 3457 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+1]+
pascal@12756 3458 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+2]);
pascal@12756 3459 dopack( &pbytes, firstpart,
pascal@12756 3460 iLBCenc_inst->ULP_inst->cb_index[i][k][ulp],
pascal@12756 3461 &pos);
pascal@12756 3462 }
pascal@12756 3463 }
pascal@12756 3464
pascal@12756 3465 for (i=0; i<iLBCenc_inst->nasub; i++) {
pascal@12756 3466 for (k=0; k<CB_NSTAGES; k++) {
pascal@12756 3467 packsplit(gain_index+i*CB_NSTAGES+k, &firstpart,
pascal@12756 3468 gain_index+i*CB_NSTAGES+k,
pascal@12756 3469 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp],
pascal@12756 3470 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp]+
pascal@12756 3471
pascal@12756 3472
pascal@12756 3473
pascal@12756 3474 Andersen, et al. Experimental [Page 62]
pascal@12756 3475
pascal@12756 3476 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3477
pascal@12756 3478
pascal@12756 3479 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+1]+
pascal@12756 3480 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+2]);
pascal@12756 3481 dopack( &pbytes, firstpart,
pascal@12756 3482 iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp],
pascal@12756 3483 &pos);
pascal@12756 3484 }
pascal@12756 3485 }
pascal@12756 3486 }
pascal@12756 3487
pascal@12756 3488 /* set the last bit to zero (otherwise the decoder
pascal@12756 3489 will treat it as a lost frame) */
pascal@12756 3490 dopack( &pbytes, 0, 1, &pos);
pascal@12756 3491 }
pascal@12756 3492
pascal@12756 3493 A.4. iLBC_decode.h
pascal@12756 3494
pascal@12756 3495 /******************************************************************
pascal@12756 3496
pascal@12756 3497 iLBC Speech Coder ANSI-C Source Code
pascal@12756 3498
pascal@12756 3499 iLBC_decode.h
pascal@12756 3500
pascal@12756 3501 Copyright (C) The Internet Society (2004).
pascal@12756 3502 All Rights Reserved.
pascal@12756 3503
pascal@12756 3504 ******************************************************************/
pascal@12756 3505
pascal@12756 3506 #ifndef __iLBC_ILBCDECODE_H
pascal@12756 3507 #define __iLBC_ILBCDECODE_H
pascal@12756 3508
pascal@12756 3509 #include "iLBC_define.h"
pascal@12756 3510
pascal@12756 3511 short initDecode( /* (o) Number of decoded
pascal@12756 3512 samples */
pascal@12756 3513 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */
pascal@12756 3514 int mode, /* (i) frame size mode */
pascal@12756 3515 int use_enhancer /* (i) 1 to use enhancer
pascal@12756 3516 0 to run without
pascal@12756 3517 enhancer */
pascal@12756 3518 );
pascal@12756 3519
pascal@12756 3520 void iLBC_decode(
pascal@12756 3521 float *decblock, /* (o) decoded signal block */
pascal@12756 3522 unsigned char *bytes, /* (i) encoded signal bits */
pascal@12756 3523 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state
pascal@12756 3524 structure */
pascal@12756 3525 int mode /* (i) 0: bad packet, PLC,
pascal@12756 3526 1: normal */
pascal@12756 3527
pascal@12756 3528
pascal@12756 3529
pascal@12756 3530 Andersen, et al. Experimental [Page 63]
pascal@12756 3531
pascal@12756 3532 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3533
pascal@12756 3534
pascal@12756 3535 );
pascal@12756 3536
pascal@12756 3537 #endif
pascal@12756 3538
pascal@12756 3539 A.5. iLBC_decode.c
pascal@12756 3540
pascal@12756 3541 /******************************************************************
pascal@12756 3542
pascal@12756 3543 iLBC Speech Coder ANSI-C Source Code
pascal@12756 3544
pascal@12756 3545 iLBC_decode.c
pascal@12756 3546
pascal@12756 3547 Copyright (C) The Internet Society (2004).
pascal@12756 3548 All Rights Reserved.
pascal@12756 3549
pascal@12756 3550 ******************************************************************/
pascal@12756 3551
pascal@12756 3552 #include <math.h>
pascal@12756 3553 #include <stdlib.h>
pascal@12756 3554
pascal@12756 3555 #include "iLBC_define.h"
pascal@12756 3556 #include "StateConstructW.h"
pascal@12756 3557 #include "LPCdecode.h"
pascal@12756 3558 #include "iCBConstruct.h"
pascal@12756 3559 #include "doCPLC.h"
pascal@12756 3560 #include "helpfun.h"
pascal@12756 3561 #include "constants.h"
pascal@12756 3562 #include "packing.h"
pascal@12756 3563 #include "string.h"
pascal@12756 3564 #include "enhancer.h"
pascal@12756 3565 #include "hpOutput.h"
pascal@12756 3566 #include "syntFilter.h"
pascal@12756 3567
pascal@12756 3568 /*----------------------------------------------------------------*
pascal@12756 3569 * Initiation of decoder instance.
pascal@12756 3570 *---------------------------------------------------------------*/
pascal@12756 3571
pascal@12756 3572 short initDecode( /* (o) Number of decoded
pascal@12756 3573 samples */
pascal@12756 3574 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) Decoder instance */
pascal@12756 3575 int mode, /* (i) frame size mode */
pascal@12756 3576 int use_enhancer /* (i) 1 to use enhancer
pascal@12756 3577 0 to run without
pascal@12756 3578 enhancer */
pascal@12756 3579 ){
pascal@12756 3580 int i;
pascal@12756 3581
pascal@12756 3582 iLBCdec_inst->mode = mode;
pascal@12756 3583
pascal@12756 3584
pascal@12756 3585
pascal@12756 3586 Andersen, et al. Experimental [Page 64]
pascal@12756 3587
pascal@12756 3588 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3589
pascal@12756 3590
pascal@12756 3591 if (mode==30) {
pascal@12756 3592 iLBCdec_inst->blockl = BLOCKL_30MS;
pascal@12756 3593 iLBCdec_inst->nsub = NSUB_30MS;
pascal@12756 3594 iLBCdec_inst->nasub = NASUB_30MS;
pascal@12756 3595 iLBCdec_inst->lpc_n = LPC_N_30MS;
pascal@12756 3596 iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS;
pascal@12756 3597 iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS;
pascal@12756 3598 iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS;
pascal@12756 3599 /* ULP init */
pascal@12756 3600 iLBCdec_inst->ULP_inst=&ULP_30msTbl;
pascal@12756 3601 }
pascal@12756 3602 else if (mode==20) {
pascal@12756 3603 iLBCdec_inst->blockl = BLOCKL_20MS;
pascal@12756 3604 iLBCdec_inst->nsub = NSUB_20MS;
pascal@12756 3605 iLBCdec_inst->nasub = NASUB_20MS;
pascal@12756 3606 iLBCdec_inst->lpc_n = LPC_N_20MS;
pascal@12756 3607 iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS;
pascal@12756 3608 iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS;
pascal@12756 3609 iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS;
pascal@12756 3610 /* ULP init */
pascal@12756 3611 iLBCdec_inst->ULP_inst=&ULP_20msTbl;
pascal@12756 3612 }
pascal@12756 3613 else {
pascal@12756 3614 exit(2);
pascal@12756 3615 }
pascal@12756 3616
pascal@12756 3617 memset(iLBCdec_inst->syntMem, 0,
pascal@12756 3618 LPC_FILTERORDER*sizeof(float));
pascal@12756 3619 memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl,
pascal@12756 3620 LPC_FILTERORDER*sizeof(float));
pascal@12756 3621
pascal@12756 3622 memset(iLBCdec_inst->old_syntdenum, 0,
pascal@12756 3623 ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float));
pascal@12756 3624 for (i=0; i<NSUB_MAX; i++)
pascal@12756 3625 iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)]=1.0;
pascal@12756 3626
pascal@12756 3627 iLBCdec_inst->last_lag = 20;
pascal@12756 3628
pascal@12756 3629 iLBCdec_inst->prevLag = 120;
pascal@12756 3630 iLBCdec_inst->per = 0.0;
pascal@12756 3631 iLBCdec_inst->consPLICount = 0;
pascal@12756 3632 iLBCdec_inst->prevPLI = 0;
pascal@12756 3633 iLBCdec_inst->prevLpc[0] = 1.0;
pascal@12756 3634 memset(iLBCdec_inst->prevLpc+1,0,
pascal@12756 3635 LPC_FILTERORDER*sizeof(float));
pascal@12756 3636 memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float));
pascal@12756 3637 iLBCdec_inst->seed=777;
pascal@12756 3638
pascal@12756 3639
pascal@12756 3640
pascal@12756 3641
pascal@12756 3642 Andersen, et al. Experimental [Page 65]
pascal@12756 3643
pascal@12756 3644 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3645
pascal@12756 3646
pascal@12756 3647 memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float));
pascal@12756 3648
pascal@12756 3649 iLBCdec_inst->use_enhancer = use_enhancer;
pascal@12756 3650 memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float));
pascal@12756 3651 for (i=0;i<ENH_NBLOCKS_TOT;i++)
pascal@12756 3652 iLBCdec_inst->enh_period[i]=(float)40.0;
pascal@12756 3653
pascal@12756 3654 iLBCdec_inst->prev_enh_pl = 0;
pascal@12756 3655
pascal@12756 3656 return (iLBCdec_inst->blockl);
pascal@12756 3657 }
pascal@12756 3658
pascal@12756 3659 /*----------------------------------------------------------------*
pascal@12756 3660 * frame residual decoder function (subrutine to iLBC_decode)
pascal@12756 3661 *---------------------------------------------------------------*/
pascal@12756 3662
pascal@12756 3663 void Decode(
pascal@12756 3664 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state
pascal@12756 3665 structure */
pascal@12756 3666 float *decresidual, /* (o) decoded residual frame */
pascal@12756 3667 int start, /* (i) location of start
pascal@12756 3668 state */
pascal@12756 3669 int idxForMax, /* (i) codebook index for the
pascal@12756 3670 maximum value */
pascal@12756 3671 int *idxVec, /* (i) codebook indexes for the
pascal@12756 3672 samples in the start
pascal@12756 3673 state */
pascal@12756 3674 float *syntdenum, /* (i) the decoded synthesis
pascal@12756 3675 filter coefficients */
pascal@12756 3676 int *cb_index, /* (i) the indexes for the
pascal@12756 3677 adaptive codebook */
pascal@12756 3678 int *gain_index, /* (i) the indexes for the
pascal@12756 3679 corresponding gains */
pascal@12756 3680 int *extra_cb_index, /* (i) the indexes for the
pascal@12756 3681 adaptive codebook part
pascal@12756 3682 of start state */
pascal@12756 3683 int *extra_gain_index, /* (i) the indexes for the
pascal@12756 3684 corresponding gains */
pascal@12756 3685 int state_first /* (i) 1 if non adaptive part
pascal@12756 3686 of start state comes
pascal@12756 3687 first 0 if that part
pascal@12756 3688 comes last */
pascal@12756 3689 ){
pascal@12756 3690 float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];
pascal@12756 3691 int k, meml_gotten, Nfor, Nback, i;
pascal@12756 3692 int diff, start_pos;
pascal@12756 3693 int subcount, subframe;
pascal@12756 3694
pascal@12756 3695
pascal@12756 3696
pascal@12756 3697
pascal@12756 3698 Andersen, et al. Experimental [Page 66]
pascal@12756 3699
pascal@12756 3700 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3701
pascal@12756 3702
pascal@12756 3703 diff = STATE_LEN - iLBCdec_inst->state_short_len;
pascal@12756 3704
pascal@12756 3705 if (state_first == 1) {
pascal@12756 3706 start_pos = (start-1)*SUBL;
pascal@12756 3707 } else {
pascal@12756 3708 start_pos = (start-1)*SUBL + diff;
pascal@12756 3709 }
pascal@12756 3710
pascal@12756 3711 /* decode scalar part of start state */
pascal@12756 3712
pascal@12756 3713 StateConstructW(idxForMax, idxVec,
pascal@12756 3714 &syntdenum[(start-1)*(LPC_FILTERORDER+1)],
pascal@12756 3715 &decresidual[start_pos], iLBCdec_inst->state_short_len);
pascal@12756 3716
pascal@12756 3717
pascal@12756 3718 if (state_first) { /* put adaptive part in the end */
pascal@12756 3719
pascal@12756 3720 /* setup memory */
pascal@12756 3721
pascal@12756 3722 memset(mem, 0,
pascal@12756 3723 (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float));
pascal@12756 3724 memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len,
pascal@12756 3725 decresidual+start_pos,
pascal@12756 3726 iLBCdec_inst->state_short_len*sizeof(float));
pascal@12756 3727
pascal@12756 3728 /* construct decoded vector */
pascal@12756 3729
pascal@12756 3730 iCBConstruct(
pascal@12756 3731 &decresidual[start_pos+iLBCdec_inst->state_short_len],
pascal@12756 3732 extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl,
pascal@12756 3733 stMemLTbl, diff, CB_NSTAGES);
pascal@12756 3734
pascal@12756 3735 }
pascal@12756 3736 else {/* put adaptive part in the beginning */
pascal@12756 3737
pascal@12756 3738 /* create reversed vectors for prediction */
pascal@12756 3739
pascal@12756 3740 for (k=0; k<diff; k++) {
pascal@12756 3741 reverseDecresidual[k] =
pascal@12756 3742 decresidual[(start+1)*SUBL-1-
pascal@12756 3743 (k+iLBCdec_inst->state_short_len)];
pascal@12756 3744 }
pascal@12756 3745
pascal@12756 3746 /* setup memory */
pascal@12756 3747
pascal@12756 3748 meml_gotten = iLBCdec_inst->state_short_len;
pascal@12756 3749 for (k=0; k<meml_gotten; k++){
pascal@12756 3750 mem[CB_MEML-1-k] = decresidual[start_pos + k];
pascal@12756 3751
pascal@12756 3752
pascal@12756 3753
pascal@12756 3754 Andersen, et al. Experimental [Page 67]
pascal@12756 3755
pascal@12756 3756 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3757
pascal@12756 3758
pascal@12756 3759 }
pascal@12756 3760 memset(mem, 0, (CB_MEML-k)*sizeof(float));
pascal@12756 3761
pascal@12756 3762 /* construct decoded vector */
pascal@12756 3763
pascal@12756 3764 iCBConstruct(reverseDecresidual, extra_cb_index,
pascal@12756 3765 extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl,
pascal@12756 3766 diff, CB_NSTAGES);
pascal@12756 3767
pascal@12756 3768 /* get decoded residual from reversed vector */
pascal@12756 3769
pascal@12756 3770 for (k=0; k<diff; k++) {
pascal@12756 3771 decresidual[start_pos-1-k] = reverseDecresidual[k];
pascal@12756 3772 }
pascal@12756 3773 }
pascal@12756 3774
pascal@12756 3775 /* counter for predicted sub-frames */
pascal@12756 3776
pascal@12756 3777 subcount=0;
pascal@12756 3778
pascal@12756 3779 /* forward prediction of sub-frames */
pascal@12756 3780
pascal@12756 3781 Nfor = iLBCdec_inst->nsub-start-1;
pascal@12756 3782
pascal@12756 3783 if ( Nfor > 0 ){
pascal@12756 3784
pascal@12756 3785 /* setup memory */
pascal@12756 3786
pascal@12756 3787 memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));
pascal@12756 3788 memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL,
pascal@12756 3789 STATE_LEN*sizeof(float));
pascal@12756 3790
pascal@12756 3791 /* loop over sub-frames to encode */
pascal@12756 3792
pascal@12756 3793 for (subframe=0; subframe<Nfor; subframe++) {
pascal@12756 3794
pascal@12756 3795 /* construct decoded vector */
pascal@12756 3796
pascal@12756 3797 iCBConstruct(&decresidual[(start+1+subframe)*SUBL],
pascal@12756 3798 cb_index+subcount*CB_NSTAGES,
pascal@12756 3799 gain_index+subcount*CB_NSTAGES,
pascal@12756 3800 mem+CB_MEML-memLfTbl[subcount],
pascal@12756 3801 memLfTbl[subcount], SUBL, CB_NSTAGES);
pascal@12756 3802
pascal@12756 3803 /* update memory */
pascal@12756 3804
pascal@12756 3805 memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
pascal@12756 3806 memcpy(mem+CB_MEML-SUBL,
pascal@12756 3807
pascal@12756 3808
pascal@12756 3809
pascal@12756 3810 Andersen, et al. Experimental [Page 68]
pascal@12756 3811
pascal@12756 3812 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3813
pascal@12756 3814
pascal@12756 3815 &decresidual[(start+1+subframe)*SUBL],
pascal@12756 3816 SUBL*sizeof(float));
pascal@12756 3817
pascal@12756 3818 subcount++;
pascal@12756 3819
pascal@12756 3820 }
pascal@12756 3821
pascal@12756 3822 }
pascal@12756 3823
pascal@12756 3824 /* backward prediction of sub-frames */
pascal@12756 3825
pascal@12756 3826 Nback = start-1;
pascal@12756 3827
pascal@12756 3828 if ( Nback > 0 ) {
pascal@12756 3829
pascal@12756 3830 /* setup memory */
pascal@12756 3831
pascal@12756 3832 meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start);
pascal@12756 3833
pascal@12756 3834 if ( meml_gotten > CB_MEML ) {
pascal@12756 3835 meml_gotten=CB_MEML;
pascal@12756 3836 }
pascal@12756 3837 for (k=0; k<meml_gotten; k++) {
pascal@12756 3838 mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];
pascal@12756 3839 }
pascal@12756 3840 memset(mem, 0, (CB_MEML-k)*sizeof(float));
pascal@12756 3841
pascal@12756 3842 /* loop over subframes to decode */
pascal@12756 3843
pascal@12756 3844 for (subframe=0; subframe<Nback; subframe++) {
pascal@12756 3845
pascal@12756 3846 /* construct decoded vector */
pascal@12756 3847
pascal@12756 3848 iCBConstruct(&reverseDecresidual[subframe*SUBL],
pascal@12756 3849 cb_index+subcount*CB_NSTAGES,
pascal@12756 3850 gain_index+subcount*CB_NSTAGES,
pascal@12756 3851 mem+CB_MEML-memLfTbl[subcount], memLfTbl[subcount],
pascal@12756 3852 SUBL, CB_NSTAGES);
pascal@12756 3853
pascal@12756 3854 /* update memory */
pascal@12756 3855
pascal@12756 3856 memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
pascal@12756 3857 memcpy(mem+CB_MEML-SUBL,
pascal@12756 3858 &reverseDecresidual[subframe*SUBL],
pascal@12756 3859 SUBL*sizeof(float));
pascal@12756 3860
pascal@12756 3861 subcount++;
pascal@12756 3862 }
pascal@12756 3863
pascal@12756 3864
pascal@12756 3865
pascal@12756 3866 Andersen, et al. Experimental [Page 69]
pascal@12756 3867
pascal@12756 3868 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3869
pascal@12756 3870
pascal@12756 3871 /* get decoded residual from reversed vector */
pascal@12756 3872
pascal@12756 3873 for (i=0; i<SUBL*Nback; i++)
pascal@12756 3874 decresidual[SUBL*Nback - i - 1] =
pascal@12756 3875 reverseDecresidual[i];
pascal@12756 3876 }
pascal@12756 3877 }
pascal@12756 3878
pascal@12756 3879 /*----------------------------------------------------------------*
pascal@12756 3880 * main decoder function
pascal@12756 3881 *---------------------------------------------------------------*/
pascal@12756 3882
pascal@12756 3883 void iLBC_decode(
pascal@12756 3884 float *decblock, /* (o) decoded signal block */
pascal@12756 3885 unsigned char *bytes, /* (i) encoded signal bits */
pascal@12756 3886 iLBC_Dec_Inst_t *iLBCdec_inst, /* (i/o) the decoder state
pascal@12756 3887 structure */
pascal@12756 3888 int mode /* (i) 0: bad packet, PLC,
pascal@12756 3889 1: normal */
pascal@12756 3890 ){
pascal@12756 3891 float data[BLOCKL_MAX];
pascal@12756 3892 float lsfdeq[LPC_FILTERORDER*LPC_N_MAX];
pascal@12756 3893 float PLCresidual[BLOCKL_MAX], PLClpc[LPC_FILTERORDER + 1];
pascal@12756 3894 float zeros[BLOCKL_MAX], one[LPC_FILTERORDER + 1];
pascal@12756 3895 int k, i, start, idxForMax, pos, lastpart, ulp;
pascal@12756 3896 int lag, ilag;
pascal@12756 3897 float cc, maxcc;
pascal@12756 3898 int idxVec[STATE_LEN];
pascal@12756 3899 int check;
pascal@12756 3900 int gain_index[NASUB_MAX*CB_NSTAGES],
pascal@12756 3901 extra_gain_index[CB_NSTAGES];
pascal@12756 3902 int cb_index[CB_NSTAGES*NASUB_MAX], extra_cb_index[CB_NSTAGES];
pascal@12756 3903 int lsf_i[LSF_NSPLIT*LPC_N_MAX];
pascal@12756 3904 int state_first;
pascal@12756 3905 int last_bit;
pascal@12756 3906 unsigned char *pbytes;
pascal@12756 3907 float weightdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];
pascal@12756 3908 int order_plus_one;
pascal@12756 3909 float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)];
pascal@12756 3910 float decresidual[BLOCKL_MAX];
pascal@12756 3911
pascal@12756 3912 if (mode>0) { /* the data are good */
pascal@12756 3913
pascal@12756 3914 /* decode data */
pascal@12756 3915
pascal@12756 3916 pbytes=bytes;
pascal@12756 3917 pos=0;
pascal@12756 3918
pascal@12756 3919
pascal@12756 3920
pascal@12756 3921
pascal@12756 3922 Andersen, et al. Experimental [Page 70]
pascal@12756 3923
pascal@12756 3924 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3925
pascal@12756 3926
pascal@12756 3927 /* Set everything to zero before decoding */
pascal@12756 3928
pascal@12756 3929 for (k=0; k<LSF_NSPLIT*LPC_N_MAX; k++) {
pascal@12756 3930 lsf_i[k]=0;
pascal@12756 3931 }
pascal@12756 3932 start=0;
pascal@12756 3933 state_first=0;
pascal@12756 3934 idxForMax=0;
pascal@12756 3935 for (k=0; k<iLBCdec_inst->state_short_len; k++) {
pascal@12756 3936 idxVec[k]=0;
pascal@12756 3937 }
pascal@12756 3938 for (k=0; k<CB_NSTAGES; k++) {
pascal@12756 3939 extra_cb_index[k]=0;
pascal@12756 3940 }
pascal@12756 3941 for (k=0; k<CB_NSTAGES; k++) {
pascal@12756 3942 extra_gain_index[k]=0;
pascal@12756 3943 }
pascal@12756 3944 for (i=0; i<iLBCdec_inst->nasub; i++) {
pascal@12756 3945 for (k=0; k<CB_NSTAGES; k++) {
pascal@12756 3946 cb_index[i*CB_NSTAGES+k]=0;
pascal@12756 3947 }
pascal@12756 3948 }
pascal@12756 3949 for (i=0; i<iLBCdec_inst->nasub; i++) {
pascal@12756 3950 for (k=0; k<CB_NSTAGES; k++) {
pascal@12756 3951 gain_index[i*CB_NSTAGES+k]=0;
pascal@12756 3952 }
pascal@12756 3953 }
pascal@12756 3954
pascal@12756 3955 /* loop over ULP classes */
pascal@12756 3956
pascal@12756 3957 for (ulp=0; ulp<3; ulp++) {
pascal@12756 3958
pascal@12756 3959 /* LSF */
pascal@12756 3960 for (k=0; k<LSF_NSPLIT*iLBCdec_inst->lpc_n; k++){
pascal@12756 3961 unpack( &pbytes, &lastpart,
pascal@12756 3962 iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos);
pascal@12756 3963 packcombine(&lsf_i[k], lastpart,
pascal@12756 3964 iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]);
pascal@12756 3965 }
pascal@12756 3966
pascal@12756 3967 /* Start block info */
pascal@12756 3968
pascal@12756 3969 unpack( &pbytes, &lastpart,
pascal@12756 3970 iLBCdec_inst->ULP_inst->start_bits[ulp], &pos);
pascal@12756 3971 packcombine(&start, lastpart,
pascal@12756 3972 iLBCdec_inst->ULP_inst->start_bits[ulp]);
pascal@12756 3973
pascal@12756 3974 unpack( &pbytes, &lastpart,
pascal@12756 3975
pascal@12756 3976
pascal@12756 3977
pascal@12756 3978 Andersen, et al. Experimental [Page 71]
pascal@12756 3979
pascal@12756 3980 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 3981
pascal@12756 3982
pascal@12756 3983 iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos);
pascal@12756 3984 packcombine(&state_first, lastpart,
pascal@12756 3985 iLBCdec_inst->ULP_inst->startfirst_bits[ulp]);
pascal@12756 3986
pascal@12756 3987 unpack( &pbytes, &lastpart,
pascal@12756 3988 iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos);
pascal@12756 3989 packcombine(&idxForMax, lastpart,
pascal@12756 3990 iLBCdec_inst->ULP_inst->scale_bits[ulp]);
pascal@12756 3991
pascal@12756 3992 for (k=0; k<iLBCdec_inst->state_short_len; k++) {
pascal@12756 3993 unpack( &pbytes, &lastpart,
pascal@12756 3994 iLBCdec_inst->ULP_inst->state_bits[ulp], &pos);
pascal@12756 3995 packcombine(idxVec+k, lastpart,
pascal@12756 3996 iLBCdec_inst->ULP_inst->state_bits[ulp]);
pascal@12756 3997 }
pascal@12756 3998
pascal@12756 3999 /* 23/22 (20ms/30ms) sample block */
pascal@12756 4000
pascal@12756 4001 for (k=0; k<CB_NSTAGES; k++) {
pascal@12756 4002 unpack( &pbytes, &lastpart,
pascal@12756 4003 iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp],
pascal@12756 4004 &pos);
pascal@12756 4005 packcombine(extra_cb_index+k, lastpart,
pascal@12756 4006 iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]);
pascal@12756 4007 }
pascal@12756 4008 for (k=0; k<CB_NSTAGES; k++) {
pascal@12756 4009 unpack( &pbytes, &lastpart,
pascal@12756 4010 iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp],
pascal@12756 4011 &pos);
pascal@12756 4012 packcombine(extra_gain_index+k, lastpart,
pascal@12756 4013 iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]);
pascal@12756 4014 }
pascal@12756 4015
pascal@12756 4016 /* The two/four (20ms/30ms) 40 sample sub-blocks */
pascal@12756 4017
pascal@12756 4018 for (i=0; i<iLBCdec_inst->nasub; i++) {
pascal@12756 4019 for (k=0; k<CB_NSTAGES; k++) {
pascal@12756 4020 unpack( &pbytes, &lastpart,
pascal@12756 4021 iLBCdec_inst->ULP_inst->cb_index[i][k][ulp],
pascal@12756 4022 &pos);
pascal@12756 4023 packcombine(cb_index+i*CB_NSTAGES+k, lastpart,
pascal@12756 4024 iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]);
pascal@12756 4025 }
pascal@12756 4026 }
pascal@12756 4027
pascal@12756 4028 for (i=0; i<iLBCdec_inst->nasub; i++) {
pascal@12756 4029 for (k=0; k<CB_NSTAGES; k++) {
pascal@12756 4030 unpack( &pbytes, &lastpart,
pascal@12756 4031
pascal@12756 4032
pascal@12756 4033
pascal@12756 4034 Andersen, et al. Experimental [Page 72]
pascal@12756 4035
pascal@12756 4036 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4037
pascal@12756 4038
pascal@12756 4039 iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp],
pascal@12756 4040 &pos);
pascal@12756 4041 packcombine(gain_index+i*CB_NSTAGES+k, lastpart,
pascal@12756 4042 iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]);
pascal@12756 4043 }
pascal@12756 4044 }
pascal@12756 4045 }
pascal@12756 4046 /* Extract last bit. If it is 1 this indicates an
pascal@12756 4047 empty/lost frame */
pascal@12756 4048 unpack( &pbytes, &last_bit, 1, &pos);
pascal@12756 4049
pascal@12756 4050 /* Check for bit errors or empty/lost frames */
pascal@12756 4051 if (start<1)
pascal@12756 4052 mode = 0;
pascal@12756 4053 if (iLBCdec_inst->mode==20 && start>3)
pascal@12756 4054 mode = 0;
pascal@12756 4055 if (iLBCdec_inst->mode==30 && start>5)
pascal@12756 4056 mode = 0;
pascal@12756 4057 if (last_bit==1)
pascal@12756 4058 mode = 0;
pascal@12756 4059
pascal@12756 4060 if (mode==1) { /* No bit errors was detected,
pascal@12756 4061 continue decoding */
pascal@12756 4062
pascal@12756 4063 /* adjust index */
pascal@12756 4064 index_conv_dec(cb_index);
pascal@12756 4065
pascal@12756 4066 /* decode the lsf */
pascal@12756 4067
pascal@12756 4068 SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n);
pascal@12756 4069 check=LSF_check(lsfdeq, LPC_FILTERORDER,
pascal@12756 4070 iLBCdec_inst->lpc_n);
pascal@12756 4071 DecoderInterpolateLSF(syntdenum, weightdenum,
pascal@12756 4072 lsfdeq, LPC_FILTERORDER, iLBCdec_inst);
pascal@12756 4073
pascal@12756 4074 Decode(iLBCdec_inst, decresidual, start, idxForMax,
pascal@12756 4075 idxVec, syntdenum, cb_index, gain_index,
pascal@12756 4076 extra_cb_index, extra_gain_index,
pascal@12756 4077 state_first);
pascal@12756 4078
pascal@12756 4079 /* preparing the plc for a future loss! */
pascal@12756 4080
pascal@12756 4081 doThePLC(PLCresidual, PLClpc, 0, decresidual,
pascal@12756 4082 syntdenum +
pascal@12756 4083 (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1),
pascal@12756 4084 (*iLBCdec_inst).last_lag, iLBCdec_inst);
pascal@12756 4085
pascal@12756 4086
pascal@12756 4087
pascal@12756 4088
pascal@12756 4089
pascal@12756 4090 Andersen, et al. Experimental [Page 73]
pascal@12756 4091
pascal@12756 4092 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4093
pascal@12756 4094
pascal@12756 4095 memcpy(decresidual, PLCresidual,
pascal@12756 4096 iLBCdec_inst->blockl*sizeof(float));
pascal@12756 4097 }
pascal@12756 4098
pascal@12756 4099 }
pascal@12756 4100
pascal@12756 4101 if (mode == 0) {
pascal@12756 4102 /* the data is bad (either a PLC call
pascal@12756 4103 * was made or a severe bit error was detected)
pascal@12756 4104 */
pascal@12756 4105
pascal@12756 4106 /* packet loss conceal */
pascal@12756 4107
pascal@12756 4108 memset(zeros, 0, BLOCKL_MAX*sizeof(float));
pascal@12756 4109
pascal@12756 4110 one[0] = 1;
pascal@12756 4111 memset(one+1, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 4112
pascal@12756 4113 start=0;
pascal@12756 4114
pascal@12756 4115 doThePLC(PLCresidual, PLClpc, 1, zeros, one,
pascal@12756 4116 (*iLBCdec_inst).last_lag, iLBCdec_inst);
pascal@12756 4117 memcpy(decresidual, PLCresidual,
pascal@12756 4118 iLBCdec_inst->blockl*sizeof(float));
pascal@12756 4119
pascal@12756 4120 order_plus_one = LPC_FILTERORDER + 1;
pascal@12756 4121 for (i = 0; i < iLBCdec_inst->nsub; i++) {
pascal@12756 4122 memcpy(syntdenum+(i*order_plus_one), PLClpc,
pascal@12756 4123 order_plus_one*sizeof(float));
pascal@12756 4124 }
pascal@12756 4125 }
pascal@12756 4126
pascal@12756 4127 if (iLBCdec_inst->use_enhancer == 1) {
pascal@12756 4128
pascal@12756 4129 /* post filtering */
pascal@12756 4130
pascal@12756 4131 iLBCdec_inst->last_lag =
pascal@12756 4132 enhancerInterface(data, decresidual, iLBCdec_inst);
pascal@12756 4133
pascal@12756 4134 /* synthesis filtering */
pascal@12756 4135
pascal@12756 4136 if (iLBCdec_inst->mode==20) {
pascal@12756 4137 /* Enhancer has 40 samples delay */
pascal@12756 4138 i=0;
pascal@12756 4139 syntFilter(data + i*SUBL,
pascal@12756 4140 iLBCdec_inst->old_syntdenum +
pascal@12756 4141 (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1),
pascal@12756 4142 SUBL, iLBCdec_inst->syntMem);
pascal@12756 4143
pascal@12756 4144
pascal@12756 4145
pascal@12756 4146 Andersen, et al. Experimental [Page 74]
pascal@12756 4147
pascal@12756 4148 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4149
pascal@12756 4150
pascal@12756 4151 for (i=1; i < iLBCdec_inst->nsub; i++) {
pascal@12756 4152 syntFilter(data + i*SUBL,
pascal@12756 4153 syntdenum + (i-1)*(LPC_FILTERORDER+1),
pascal@12756 4154 SUBL, iLBCdec_inst->syntMem);
pascal@12756 4155 }
pascal@12756 4156 } else if (iLBCdec_inst->mode==30) {
pascal@12756 4157 /* Enhancer has 80 samples delay */
pascal@12756 4158 for (i=0; i < 2; i++) {
pascal@12756 4159 syntFilter(data + i*SUBL,
pascal@12756 4160 iLBCdec_inst->old_syntdenum +
pascal@12756 4161 (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1),
pascal@12756 4162 SUBL, iLBCdec_inst->syntMem);
pascal@12756 4163 }
pascal@12756 4164 for (i=2; i < iLBCdec_inst->nsub; i++) {
pascal@12756 4165 syntFilter(data + i*SUBL,
pascal@12756 4166 syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL,
pascal@12756 4167 iLBCdec_inst->syntMem);
pascal@12756 4168 }
pascal@12756 4169 }
pascal@12756 4170
pascal@12756 4171 } else {
pascal@12756 4172
pascal@12756 4173 /* Find last lag */
pascal@12756 4174 lag = 20;
pascal@12756 4175 maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL],
pascal@12756 4176 &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL);
pascal@12756 4177
pascal@12756 4178 for (ilag=21; ilag<120; ilag++) {
pascal@12756 4179 cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL],
pascal@12756 4180 &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag],
pascal@12756 4181 ENH_BLOCKL);
pascal@12756 4182
pascal@12756 4183 if (cc > maxcc) {
pascal@12756 4184 maxcc = cc;
pascal@12756 4185 lag = ilag;
pascal@12756 4186 }
pascal@12756 4187 }
pascal@12756 4188 iLBCdec_inst->last_lag = lag;
pascal@12756 4189
pascal@12756 4190 /* copy data and run synthesis filter */
pascal@12756 4191
pascal@12756 4192 memcpy(data, decresidual,
pascal@12756 4193 iLBCdec_inst->blockl*sizeof(float));
pascal@12756 4194 for (i=0; i < iLBCdec_inst->nsub; i++) {
pascal@12756 4195 syntFilter(data + i*SUBL,
pascal@12756 4196 syntdenum + i*(LPC_FILTERORDER+1), SUBL,
pascal@12756 4197 iLBCdec_inst->syntMem);
pascal@12756 4198 }
pascal@12756 4199
pascal@12756 4200
pascal@12756 4201
pascal@12756 4202 Andersen, et al. Experimental [Page 75]
pascal@12756 4203
pascal@12756 4204 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4205
pascal@12756 4206
pascal@12756 4207 }
pascal@12756 4208
pascal@12756 4209 /* high pass filtering on output if desired, otherwise
pascal@12756 4210 copy to out */
pascal@12756 4211
pascal@12756 4212 hpOutput(data, iLBCdec_inst->blockl,
pascal@12756 4213 decblock,iLBCdec_inst->hpomem);
pascal@12756 4214
pascal@12756 4215 /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/
pascal@12756 4216
pascal@12756 4217 memcpy(iLBCdec_inst->old_syntdenum, syntdenum,
pascal@12756 4218
pascal@12756 4219 iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float));
pascal@12756 4220
pascal@12756 4221 iLBCdec_inst->prev_enh_pl=0;
pascal@12756 4222
pascal@12756 4223 if (mode==0) { /* PLC was used */
pascal@12756 4224 iLBCdec_inst->prev_enh_pl=1;
pascal@12756 4225 }
pascal@12756 4226 }
pascal@12756 4227
pascal@12756 4228 A.6. iLBC_define.h
pascal@12756 4229
pascal@12756 4230 /******************************************************************
pascal@12756 4231
pascal@12756 4232 iLBC Speech Coder ANSI-C Source Code
pascal@12756 4233
pascal@12756 4234 iLBC_define.h
pascal@12756 4235
pascal@12756 4236 Copyright (C) The Internet Society (2004).
pascal@12756 4237 All Rights Reserved.
pascal@12756 4238
pascal@12756 4239 ******************************************************************/
pascal@12756 4240 #include <string.h>
pascal@12756 4241
pascal@12756 4242 #ifndef __iLBC_ILBCDEFINE_H
pascal@12756 4243 #define __iLBC_ILBCDEFINE_H
pascal@12756 4244
pascal@12756 4245 /* general codec settings */
pascal@12756 4246
pascal@12756 4247 #define FS (float)8000.0
pascal@12756 4248 #define BLOCKL_20MS 160
pascal@12756 4249 #define BLOCKL_30MS 240
pascal@12756 4250 #define BLOCKL_MAX 240
pascal@12756 4251 #define NSUB_20MS 4
pascal@12756 4252 #define NSUB_30MS 6
pascal@12756 4253 #define NSUB_MAX 6
pascal@12756 4254 #define NASUB_20MS 2
pascal@12756 4255
pascal@12756 4256
pascal@12756 4257
pascal@12756 4258 Andersen, et al. Experimental [Page 76]
pascal@12756 4259
pascal@12756 4260 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4261
pascal@12756 4262
pascal@12756 4263 #define NASUB_30MS 4
pascal@12756 4264 #define NASUB_MAX 4
pascal@12756 4265 #define SUBL 40
pascal@12756 4266 #define STATE_LEN 80
pascal@12756 4267 #define STATE_SHORT_LEN_30MS 58
pascal@12756 4268 #define STATE_SHORT_LEN_20MS 57
pascal@12756 4269
pascal@12756 4270 /* LPC settings */
pascal@12756 4271
pascal@12756 4272 #define LPC_FILTERORDER 10
pascal@12756 4273 #define LPC_CHIRP_SYNTDENUM (float)0.9025
pascal@12756 4274 #define LPC_CHIRP_WEIGHTDENUM (float)0.4222
pascal@12756 4275 #define LPC_LOOKBACK 60
pascal@12756 4276 #define LPC_N_20MS 1
pascal@12756 4277 #define LPC_N_30MS 2
pascal@12756 4278 #define LPC_N_MAX 2
pascal@12756 4279 #define LPC_ASYMDIFF 20
pascal@12756 4280 #define LPC_BW (float)60.0
pascal@12756 4281 #define LPC_WN (float)1.0001
pascal@12756 4282 #define LSF_NSPLIT 3
pascal@12756 4283 #define LSF_NUMBER_OF_STEPS 4
pascal@12756 4284 #define LPC_HALFORDER (LPC_FILTERORDER/2)
pascal@12756 4285
pascal@12756 4286 /* cb settings */
pascal@12756 4287
pascal@12756 4288 #define CB_NSTAGES 3
pascal@12756 4289 #define CB_EXPAND 2
pascal@12756 4290 #define CB_MEML 147
pascal@12756 4291 #define CB_FILTERLEN 2*4
pascal@12756 4292 #define CB_HALFFILTERLEN 4
pascal@12756 4293 #define CB_RESRANGE 34
pascal@12756 4294 #define CB_MAXGAIN (float)1.3
pascal@12756 4295
pascal@12756 4296 /* enhancer */
pascal@12756 4297
pascal@12756 4298 #define ENH_BLOCKL 80 /* block length */
pascal@12756 4299 #define ENH_BLOCKL_HALF (ENH_BLOCKL/2)
pascal@12756 4300 #define ENH_HL 3 /* 2*ENH_HL+1 is number blocks
pascal@12756 4301 in said second sequence */
pascal@12756 4302 #define ENH_SLOP 2 /* max difference estimated and
pascal@12756 4303 correct pitch period */
pascal@12756 4304 #define ENH_PLOCSL 20 /* pitch-estimates and pitch-
pascal@12756 4305 locations buffer length */
pascal@12756 4306 #define ENH_OVERHANG 2
pascal@12756 4307 #define ENH_UPS0 4 /* upsampling rate */
pascal@12756 4308 #define ENH_FL0 3 /* 2*FLO+1 is the length of
pascal@12756 4309 each filter */
pascal@12756 4310 #define ENH_VECTL (ENH_BLOCKL+2*ENH_FL0)
pascal@12756 4311
pascal@12756 4312
pascal@12756 4313
pascal@12756 4314 Andersen, et al. Experimental [Page 77]
pascal@12756 4315
pascal@12756 4316 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4317
pascal@12756 4318
pascal@12756 4319 #define ENH_CORRDIM (2*ENH_SLOP+1)
pascal@12756 4320 #define ENH_NBLOCKS (BLOCKL_MAX/ENH_BLOCKL)
pascal@12756 4321 #define ENH_NBLOCKS_EXTRA 5
pascal@12756 4322 #define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS +
pascal@12756 4323 ENH_NBLOCKS_EXTRA */
pascal@12756 4324 #define ENH_BUFL (ENH_NBLOCKS_TOT)*ENH_BLOCKL
pascal@12756 4325 #define ENH_ALPHA0 (float)0.05
pascal@12756 4326
pascal@12756 4327 /* Down sampling */
pascal@12756 4328
pascal@12756 4329 #define FILTERORDER_DS 7
pascal@12756 4330 #define DELAY_DS 3
pascal@12756 4331 #define FACTOR_DS 2
pascal@12756 4332
pascal@12756 4333 /* bit stream defs */
pascal@12756 4334
pascal@12756 4335 #define NO_OF_BYTES_20MS 38
pascal@12756 4336 #define NO_OF_BYTES_30MS 50
pascal@12756 4337 #define NO_OF_WORDS_20MS 19
pascal@12756 4338 #define NO_OF_WORDS_30MS 25
pascal@12756 4339 #define STATE_BITS 3
pascal@12756 4340 #define BYTE_LEN 8
pascal@12756 4341 #define ULP_CLASSES 3
pascal@12756 4342
pascal@12756 4343 /* help parameters */
pascal@12756 4344
pascal@12756 4345 #define FLOAT_MAX (float)1.0e37
pascal@12756 4346 #define EPS (float)2.220446049250313e-016
pascal@12756 4347 #define PI (float)3.14159265358979323846
pascal@12756 4348 #define MIN_SAMPLE -32768
pascal@12756 4349 #define MAX_SAMPLE 32767
pascal@12756 4350 #define TWO_PI (float)6.283185307
pascal@12756 4351 #define PI2 (float)0.159154943
pascal@12756 4352
pascal@12756 4353 /* type definition encoder instance */
pascal@12756 4354 typedef struct iLBC_ULP_Inst_t_ {
pascal@12756 4355 int lsf_bits[6][ULP_CLASSES+2];
pascal@12756 4356 int start_bits[ULP_CLASSES+2];
pascal@12756 4357 int startfirst_bits[ULP_CLASSES+2];
pascal@12756 4358 int scale_bits[ULP_CLASSES+2];
pascal@12756 4359 int state_bits[ULP_CLASSES+2];
pascal@12756 4360 int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2];
pascal@12756 4361 int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2];
pascal@12756 4362 int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];
pascal@12756 4363 int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];
pascal@12756 4364 } iLBC_ULP_Inst_t;
pascal@12756 4365
pascal@12756 4366 /* type definition encoder instance */
pascal@12756 4367
pascal@12756 4368
pascal@12756 4369
pascal@12756 4370 Andersen, et al. Experimental [Page 78]
pascal@12756 4371
pascal@12756 4372 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4373
pascal@12756 4374
pascal@12756 4375 typedef struct iLBC_Enc_Inst_t_ {
pascal@12756 4376
pascal@12756 4377 /* flag for frame size mode */
pascal@12756 4378 int mode;
pascal@12756 4379
pascal@12756 4380 /* basic parameters for different frame sizes */
pascal@12756 4381 int blockl;
pascal@12756 4382 int nsub;
pascal@12756 4383 int nasub;
pascal@12756 4384 int no_of_bytes, no_of_words;
pascal@12756 4385 int lpc_n;
pascal@12756 4386 int state_short_len;
pascal@12756 4387 const iLBC_ULP_Inst_t *ULP_inst;
pascal@12756 4388
pascal@12756 4389 /* analysis filter state */
pascal@12756 4390 float anaMem[LPC_FILTERORDER];
pascal@12756 4391
pascal@12756 4392 /* old lsf parameters for interpolation */
pascal@12756 4393 float lsfold[LPC_FILTERORDER];
pascal@12756 4394 float lsfdeqold[LPC_FILTERORDER];
pascal@12756 4395
pascal@12756 4396 /* signal buffer for LP analysis */
pascal@12756 4397 float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];
pascal@12756 4398
pascal@12756 4399 /* state of input HP filter */
pascal@12756 4400 float hpimem[4];
pascal@12756 4401
pascal@12756 4402 } iLBC_Enc_Inst_t;
pascal@12756 4403
pascal@12756 4404 /* type definition decoder instance */
pascal@12756 4405 typedef struct iLBC_Dec_Inst_t_ {
pascal@12756 4406
pascal@12756 4407 /* flag for frame size mode */
pascal@12756 4408 int mode;
pascal@12756 4409
pascal@12756 4410 /* basic parameters for different frame sizes */
pascal@12756 4411 int blockl;
pascal@12756 4412 int nsub;
pascal@12756 4413 int nasub;
pascal@12756 4414 int no_of_bytes, no_of_words;
pascal@12756 4415 int lpc_n;
pascal@12756 4416 int state_short_len;
pascal@12756 4417 const iLBC_ULP_Inst_t *ULP_inst;
pascal@12756 4418
pascal@12756 4419 /* synthesis filter state */
pascal@12756 4420 float syntMem[LPC_FILTERORDER];
pascal@12756 4421
pascal@12756 4422 /* old LSF for interpolation */
pascal@12756 4423
pascal@12756 4424
pascal@12756 4425
pascal@12756 4426 Andersen, et al. Experimental [Page 79]
pascal@12756 4427
pascal@12756 4428 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4429
pascal@12756 4430
pascal@12756 4431 float lsfdeqold[LPC_FILTERORDER];
pascal@12756 4432
pascal@12756 4433 /* pitch lag estimated in enhancer and used in PLC */
pascal@12756 4434 int last_lag;
pascal@12756 4435
pascal@12756 4436 /* PLC state information */
pascal@12756 4437 int prevLag, consPLICount, prevPLI, prev_enh_pl;
pascal@12756 4438 float prevLpc[LPC_FILTERORDER+1];
pascal@12756 4439 float prevResidual[NSUB_MAX*SUBL];
pascal@12756 4440 float per;
pascal@12756 4441 unsigned long seed;
pascal@12756 4442
pascal@12756 4443 /* previous synthesis filter parameters */
pascal@12756 4444 float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];
pascal@12756 4445
pascal@12756 4446 /* state of output HP filter */
pascal@12756 4447 float hpomem[4];
pascal@12756 4448
pascal@12756 4449 /* enhancer state information */
pascal@12756 4450 int use_enhancer;
pascal@12756 4451 float enh_buf[ENH_BUFL];
pascal@12756 4452 float enh_period[ENH_NBLOCKS_TOT];
pascal@12756 4453
pascal@12756 4454 } iLBC_Dec_Inst_t;
pascal@12756 4455
pascal@12756 4456 #endif
pascal@12756 4457
pascal@12756 4458 A.7. constants.h
pascal@12756 4459
pascal@12756 4460 /******************************************************************
pascal@12756 4461
pascal@12756 4462 iLBC Speech Coder ANSI-C Source Code
pascal@12756 4463
pascal@12756 4464 constants.h
pascal@12756 4465
pascal@12756 4466 Copyright (C) The Internet Society (2004).
pascal@12756 4467 All Rights Reserved.
pascal@12756 4468
pascal@12756 4469 ******************************************************************/
pascal@12756 4470
pascal@12756 4471 #ifndef __iLBC_CONSTANTS_H
pascal@12756 4472 #define __iLBC_CONSTANTS_H
pascal@12756 4473
pascal@12756 4474 #include "iLBC_define.h"
pascal@12756 4475
pascal@12756 4476
pascal@12756 4477 /* ULP bit allocation */
pascal@12756 4478
pascal@12756 4479
pascal@12756 4480
pascal@12756 4481
pascal@12756 4482 Andersen, et al. Experimental [Page 80]
pascal@12756 4483
pascal@12756 4484 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4485
pascal@12756 4486
pascal@12756 4487 extern const iLBC_ULP_Inst_t ULP_20msTbl;
pascal@12756 4488 extern const iLBC_ULP_Inst_t ULP_30msTbl;
pascal@12756 4489
pascal@12756 4490 /* high pass filters */
pascal@12756 4491
pascal@12756 4492 extern float hpi_zero_coefsTbl[];
pascal@12756 4493 extern float hpi_pole_coefsTbl[];
pascal@12756 4494 extern float hpo_zero_coefsTbl[];
pascal@12756 4495 extern float hpo_pole_coefsTbl[];
pascal@12756 4496
pascal@12756 4497 /* low pass filters */
pascal@12756 4498 extern float lpFilt_coefsTbl[];
pascal@12756 4499
pascal@12756 4500 /* LPC analysis and quantization */
pascal@12756 4501
pascal@12756 4502 extern float lpc_winTbl[];
pascal@12756 4503 extern float lpc_asymwinTbl[];
pascal@12756 4504 extern float lpc_lagwinTbl[];
pascal@12756 4505 extern float lsfCbTbl[];
pascal@12756 4506 extern float lsfmeanTbl[];
pascal@12756 4507 extern int dim_lsfCbTbl[];
pascal@12756 4508 extern int size_lsfCbTbl[];
pascal@12756 4509 extern float lsf_weightTbl_30ms[];
pascal@12756 4510 extern float lsf_weightTbl_20ms[];
pascal@12756 4511
pascal@12756 4512 /* state quantization tables */
pascal@12756 4513
pascal@12756 4514 extern float state_sq3Tbl[];
pascal@12756 4515 extern float state_frgqTbl[];
pascal@12756 4516
pascal@12756 4517 /* gain quantization tables */
pascal@12756 4518
pascal@12756 4519 extern float gain_sq3Tbl[];
pascal@12756 4520 extern float gain_sq4Tbl[];
pascal@12756 4521 extern float gain_sq5Tbl[];
pascal@12756 4522
pascal@12756 4523 /* adaptive codebook definitions */
pascal@12756 4524
pascal@12756 4525 extern int search_rangeTbl[5][CB_NSTAGES];
pascal@12756 4526 extern int memLfTbl[];
pascal@12756 4527 extern int stMemLTbl;
pascal@12756 4528 extern float cbfiltersTbl[CB_FILTERLEN];
pascal@12756 4529
pascal@12756 4530 /* enhancer definitions */
pascal@12756 4531
pascal@12756 4532 extern float polyphaserTbl[];
pascal@12756 4533 extern float enh_plocsTbl[];
pascal@12756 4534
pascal@12756 4535
pascal@12756 4536
pascal@12756 4537
pascal@12756 4538 Andersen, et al. Experimental [Page 81]
pascal@12756 4539
pascal@12756 4540 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4541
pascal@12756 4542
pascal@12756 4543 #endif
pascal@12756 4544
pascal@12756 4545 A.8. constants.c
pascal@12756 4546
pascal@12756 4547 /******************************************************************
pascal@12756 4548
pascal@12756 4549 iLBC Speech Coder ANSI-C Source Code
pascal@12756 4550
pascal@12756 4551 constants.c
pascal@12756 4552
pascal@12756 4553 Copyright (C) The Internet Society (2004).
pascal@12756 4554 All Rights Reserved.
pascal@12756 4555
pascal@12756 4556 ******************************************************************/
pascal@12756 4557
pascal@12756 4558 #include "iLBC_define.h"
pascal@12756 4559
pascal@12756 4560 /* ULP bit allocation */
pascal@12756 4561
pascal@12756 4562 /* 20 ms frame */
pascal@12756 4563
pascal@12756 4564 const iLBC_ULP_Inst_t ULP_20msTbl = {
pascal@12756 4565 /* LSF */
pascal@12756 4566 { {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0},
pascal@12756 4567 {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},
pascal@12756 4568 /* Start state location, gain and samples */
pascal@12756 4569 {2,0,0,0,0},
pascal@12756 4570 {1,0,0,0,0},
pascal@12756 4571 {6,0,0,0,0},
pascal@12756 4572 {0,1,2,0,0},
pascal@12756 4573 /* extra CB index and extra CB gain */
pascal@12756 4574 {{6,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
pascal@12756 4575 {{2,0,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},
pascal@12756 4576 /* CB index and CB gain */
pascal@12756 4577 { {{7,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
pascal@12756 4578 {{0,0,8,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},
pascal@12756 4579 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},
pascal@12756 4580 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}},
pascal@12756 4581 { {{1,2,2,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},
pascal@12756 4582 {{1,1,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},
pascal@12756 4583 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},
pascal@12756 4584 {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}}
pascal@12756 4585 };
pascal@12756 4586
pascal@12756 4587 /* 30 ms frame */
pascal@12756 4588
pascal@12756 4589 const iLBC_ULP_Inst_t ULP_30msTbl = {
pascal@12756 4590 /* LSF */
pascal@12756 4591
pascal@12756 4592
pascal@12756 4593
pascal@12756 4594 Andersen, et al. Experimental [Page 82]
pascal@12756 4595
pascal@12756 4596 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4597
pascal@12756 4598
pascal@12756 4599 { {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0},
pascal@12756 4600 {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}},
pascal@12756 4601 /* Start state location, gain and samples */
pascal@12756 4602 {3,0,0,0,0},
pascal@12756 4603 {1,0,0,0,0},
pascal@12756 4604 {6,0,0,0,0},
pascal@12756 4605 {0,1,2,0,0},
pascal@12756 4606 /* extra CB index and extra CB gain */
pascal@12756 4607 {{4,2,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
pascal@12756 4608 {{1,1,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},
pascal@12756 4609 /* CB index and CB gain */
pascal@12756 4610 { {{6,1,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
pascal@12756 4611 {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},
pascal@12756 4612 {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},
pascal@12756 4613 {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}},
pascal@12756 4614 { {{1,2,2,0,0}, {1,2,1,0,0}, {0,0,3,0,0}},
pascal@12756 4615 {{0,2,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},
pascal@12756 4616 {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}},
pascal@12756 4617 {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}}
pascal@12756 4618 };
pascal@12756 4619
pascal@12756 4620 /* HP Filters */
pascal@12756 4621
pascal@12756 4622 float hpi_zero_coefsTbl[3] = {
pascal@12756 4623 (float)0.92727436, (float)-1.8544941, (float)0.92727436
pascal@12756 4624 };
pascal@12756 4625 float hpi_pole_coefsTbl[3] = {
pascal@12756 4626 (float)1.0, (float)-1.9059465, (float)0.9114024
pascal@12756 4627 };
pascal@12756 4628 float hpo_zero_coefsTbl[3] = {
pascal@12756 4629 (float)0.93980581, (float)-1.8795834, (float)0.93980581
pascal@12756 4630 };
pascal@12756 4631 float hpo_pole_coefsTbl[3] = {
pascal@12756 4632 (float)1.0, (float)-1.9330735, (float)0.93589199
pascal@12756 4633 };
pascal@12756 4634
pascal@12756 4635 /* LP Filter */
pascal@12756 4636
pascal@12756 4637 float lpFilt_coefsTbl[FILTERORDER_DS]={
pascal@12756 4638 (float)-0.066650, (float)0.125000, (float)0.316650,
pascal@12756 4639 (float)0.414063, (float)0.316650,
pascal@12756 4640 (float)0.125000, (float)-0.066650
pascal@12756 4641 };
pascal@12756 4642
pascal@12756 4643 /* State quantization tables */
pascal@12756 4644
pascal@12756 4645 float state_sq3Tbl[8] = {
pascal@12756 4646 (float)-3.719849, (float)-2.177490, (float)-1.130005,
pascal@12756 4647
pascal@12756 4648
pascal@12756 4649
pascal@12756 4650 Andersen, et al. Experimental [Page 83]
pascal@12756 4651
pascal@12756 4652 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4653
pascal@12756 4654
pascal@12756 4655 (float)-0.309692, (float)0.444214, (float)1.329712,
pascal@12756 4656 (float)2.436279, (float)3.983887
pascal@12756 4657 };
pascal@12756 4658
pascal@12756 4659 float state_frgqTbl[64] = {
pascal@12756 4660 (float)1.000085, (float)1.071695, (float)1.140395,
pascal@12756 4661 (float)1.206868, (float)1.277188, (float)1.351503,
pascal@12756 4662 (float)1.429380, (float)1.500727, (float)1.569049,
pascal@12756 4663 (float)1.639599, (float)1.707071, (float)1.781531,
pascal@12756 4664 (float)1.840799, (float)1.901550, (float)1.956695,
pascal@12756 4665 (float)2.006750, (float)2.055474, (float)2.102787,
pascal@12756 4666 (float)2.142819, (float)2.183592, (float)2.217962,
pascal@12756 4667 (float)2.257177, (float)2.295739, (float)2.332967,
pascal@12756 4668 (float)2.369248, (float)2.402792, (float)2.435080,
pascal@12756 4669 (float)2.468598, (float)2.503394, (float)2.539284,
pascal@12756 4670 (float)2.572944, (float)2.605036, (float)2.636331,
pascal@12756 4671 (float)2.668939, (float)2.698780, (float)2.729101,
pascal@12756 4672 (float)2.759786, (float)2.789834, (float)2.818679,
pascal@12756 4673 (float)2.848074, (float)2.877470, (float)2.906899,
pascal@12756 4674 (float)2.936655, (float)2.967804, (float)3.000115,
pascal@12756 4675 (float)3.033367, (float)3.066355, (float)3.104231,
pascal@12756 4676 (float)3.141499, (float)3.183012, (float)3.222952,
pascal@12756 4677 (float)3.265433, (float)3.308441, (float)3.350823,
pascal@12756 4678 (float)3.395275, (float)3.442793, (float)3.490801,
pascal@12756 4679 (float)3.542514, (float)3.604064, (float)3.666050,
pascal@12756 4680 (float)3.740994, (float)3.830749, (float)3.938770,
pascal@12756 4681 (float)4.101764
pascal@12756 4682 };
pascal@12756 4683
pascal@12756 4684 /* CB tables */
pascal@12756 4685
pascal@12756 4686 int search_rangeTbl[5][CB_NSTAGES]={{58,58,58}, {108,44,44},
pascal@12756 4687 {108,108,108}, {108,108,108}, {108,108,108}};
pascal@12756 4688 int stMemLTbl=85;
pascal@12756 4689 int memLfTbl[NASUB_MAX]={147,147,147,147};
pascal@12756 4690
pascal@12756 4691 /* expansion filter(s) */
pascal@12756 4692
pascal@12756 4693 float cbfiltersTbl[CB_FILTERLEN]={
pascal@12756 4694 (float)-0.034180, (float)0.108887, (float)-0.184326,
pascal@12756 4695 (float)0.806152, (float)0.713379, (float)-0.144043,
pascal@12756 4696 (float)0.083740, (float)-0.033691
pascal@12756 4697 };
pascal@12756 4698
pascal@12756 4699 /* Gain Quantization */
pascal@12756 4700
pascal@12756 4701 float gain_sq3Tbl[8]={
pascal@12756 4702 (float)-1.000000, (float)-0.659973, (float)-0.330017,
pascal@12756 4703
pascal@12756 4704
pascal@12756 4705
pascal@12756 4706 Andersen, et al. Experimental [Page 84]
pascal@12756 4707
pascal@12756 4708 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4709
pascal@12756 4710
pascal@12756 4711 (float)0.000000, (float)0.250000, (float)0.500000,
pascal@12756 4712 (float)0.750000, (float)1.00000};
pascal@12756 4713
pascal@12756 4714 float gain_sq4Tbl[16]={
pascal@12756 4715 (float)-1.049988, (float)-0.900024, (float)-0.750000,
pascal@12756 4716 (float)-0.599976, (float)-0.450012, (float)-0.299988,
pascal@12756 4717 (float)-0.150024, (float)0.000000, (float)0.150024,
pascal@12756 4718 (float)0.299988, (float)0.450012, (float)0.599976,
pascal@12756 4719 (float)0.750000, (float)0.900024, (float)1.049988,
pascal@12756 4720 (float)1.200012};
pascal@12756 4721
pascal@12756 4722 float gain_sq5Tbl[32]={
pascal@12756 4723 (float)0.037476, (float)0.075012, (float)0.112488,
pascal@12756 4724 (float)0.150024, (float)0.187500, (float)0.224976,
pascal@12756 4725 (float)0.262512, (float)0.299988, (float)0.337524,
pascal@12756 4726 (float)0.375000, (float)0.412476, (float)0.450012,
pascal@12756 4727 (float)0.487488, (float)0.525024, (float)0.562500,
pascal@12756 4728 (float)0.599976, (float)0.637512, (float)0.674988,
pascal@12756 4729 (float)0.712524, (float)0.750000, (float)0.787476,
pascal@12756 4730 (float)0.825012, (float)0.862488, (float)0.900024,
pascal@12756 4731 (float)0.937500, (float)0.974976, (float)1.012512,
pascal@12756 4732 (float)1.049988, (float)1.087524, (float)1.125000,
pascal@12756 4733 (float)1.162476, (float)1.200012};
pascal@12756 4734
pascal@12756 4735 /* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */
pascal@12756 4736 float polyphaserTbl[ENH_UPS0*(2*ENH_FL0+1)]={
pascal@12756 4737 (float)0.000000, (float)0.000000, (float)0.000000,
pascal@12756 4738 (float)1.000000,
pascal@12756 4739 (float)0.000000, (float)0.000000, (float)0.000000,
pascal@12756 4740 (float)0.015625, (float)-0.076904, (float)0.288330,
pascal@12756 4741 (float)0.862061,
pascal@12756 4742 (float)-0.106445, (float)0.018799, (float)-0.015625,
pascal@12756 4743 (float)0.023682, (float)-0.124268, (float)0.601563,
pascal@12756 4744 (float)0.601563,
pascal@12756 4745 (float)-0.124268, (float)0.023682, (float)-0.023682,
pascal@12756 4746 (float)0.018799, (float)-0.106445, (float)0.862061,
pascal@12756 4747 (float)0.288330,
pascal@12756 4748 (float)-0.076904, (float)0.015625, (float)-0.018799};
pascal@12756 4749
pascal@12756 4750 float enh_plocsTbl[ENH_NBLOCKS_TOT] = {(float)40.0, (float)120.0,
pascal@12756 4751 (float)200.0, (float)280.0, (float)360.0,
pascal@12756 4752 (float)440.0, (float)520.0, (float)600.0};
pascal@12756 4753
pascal@12756 4754 /* LPC analysis and quantization */
pascal@12756 4755
pascal@12756 4756 int dim_lsfCbTbl[LSF_NSPLIT] = {3, 3, 4};
pascal@12756 4757 int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128};
pascal@12756 4758
pascal@12756 4759
pascal@12756 4760
pascal@12756 4761
pascal@12756 4762 Andersen, et al. Experimental [Page 85]
pascal@12756 4763
pascal@12756 4764 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4765
pascal@12756 4766
pascal@12756 4767 float lsfmeanTbl[LPC_FILTERORDER] = {
pascal@12756 4768 (float)0.281738, (float)0.445801, (float)0.663330,
pascal@12756 4769 (float)0.962524, (float)1.251831, (float)1.533081,
pascal@12756 4770 (float)1.850586, (float)2.137817, (float)2.481445,
pascal@12756 4771 (float)2.777344};
pascal@12756 4772
pascal@12756 4773 float lsf_weightTbl_30ms[6] = {(float)(1.0/2.0), (float)1.0,
pascal@12756 4774 (float)(2.0/3.0),
pascal@12756 4775 (float)(1.0/3.0), (float)0.0, (float)0.0};
pascal@12756 4776
pascal@12756 4777 float lsf_weightTbl_20ms[4] = {(float)(3.0/4.0), (float)(2.0/4.0),
pascal@12756 4778 (float)(1.0/4.0), (float)(0.0)};
pascal@12756 4779
pascal@12756 4780 /* Hanning LPC window */
pascal@12756 4781 float lpc_winTbl[BLOCKL_MAX]={
pascal@12756 4782 (float)0.000183, (float)0.000671, (float)0.001526,
pascal@12756 4783 (float)0.002716, (float)0.004242, (float)0.006104,
pascal@12756 4784 (float)0.008301, (float)0.010834, (float)0.013702,
pascal@12756 4785 (float)0.016907, (float)0.020416, (float)0.024261,
pascal@12756 4786 (float)0.028442, (float)0.032928, (float)0.037750,
pascal@12756 4787 (float)0.042877, (float)0.048309, (float)0.054047,
pascal@12756 4788 (float)0.060089, (float)0.066437, (float)0.073090,
pascal@12756 4789 (float)0.080017, (float)0.087219, (float)0.094727,
pascal@12756 4790 (float)0.102509, (float)0.110535, (float)0.118835,
pascal@12756 4791 (float)0.127411, (float)0.136230, (float)0.145294,
pascal@12756 4792 (float)0.154602, (float)0.164154, (float)0.173920,
pascal@12756 4793 (float)0.183899, (float)0.194122, (float)0.204529,
pascal@12756 4794 (float)0.215149, (float)0.225952, (float)0.236938,
pascal@12756 4795 (float)0.248108, (float)0.259460, (float)0.270966,
pascal@12756 4796 (float)0.282654, (float)0.294464, (float)0.306396,
pascal@12756 4797 (float)0.318481, (float)0.330688, (float)0.343018,
pascal@12756 4798 (float)0.355438, (float)0.367981, (float)0.380585,
pascal@12756 4799 (float)0.393280, (float)0.406067, (float)0.418884,
pascal@12756 4800 (float)0.431763, (float)0.444702, (float)0.457672,
pascal@12756 4801 (float)0.470673, (float)0.483704, (float)0.496735,
pascal@12756 4802 (float)0.509766, (float)0.522797, (float)0.535828,
pascal@12756 4803 (float)0.548798, (float)0.561768, (float)0.574677,
pascal@12756 4804 (float)0.587524, (float)0.600342, (float)0.613068,
pascal@12756 4805 (float)0.625732, (float)0.638306, (float)0.650787,
pascal@12756 4806 (float)0.663147, (float)0.675415, (float)0.687561,
pascal@12756 4807 (float)0.699585, (float)0.711487, (float)0.723206,
pascal@12756 4808 (float)0.734802, (float)0.746216, (float)0.757477,
pascal@12756 4809 (float)0.768585, (float)0.779480, (float)0.790192,
pascal@12756 4810 (float)0.800720, (float)0.811005, (float)0.821106,
pascal@12756 4811 (float)0.830994, (float)0.840668, (float)0.850067,
pascal@12756 4812 (float)0.859253, (float)0.868225, (float)0.876892,
pascal@12756 4813 (float)0.885345, (float)0.893524, (float)0.901428,
pascal@12756 4814 (float)0.909058, (float)0.916412, (float)0.923492,
pascal@12756 4815
pascal@12756 4816
pascal@12756 4817
pascal@12756 4818 Andersen, et al. Experimental [Page 86]
pascal@12756 4819
pascal@12756 4820 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4821
pascal@12756 4822
pascal@12756 4823 (float)0.930267, (float)0.936768, (float)0.942963,
pascal@12756 4824 (float)0.948853, (float)0.954437, (float)0.959717,
pascal@12756 4825 (float)0.964691, (float)0.969360, (float)0.973694,
pascal@12756 4826 (float)0.977692, (float)0.981384, (float)0.984741,
pascal@12756 4827 (float)0.987762, (float)0.990479, (float)0.992828,
pascal@12756 4828 (float)0.994873, (float)0.996552, (float)0.997925,
pascal@12756 4829 (float)0.998932, (float)0.999603, (float)0.999969,
pascal@12756 4830 (float)0.999969, (float)0.999603, (float)0.998932,
pascal@12756 4831 (float)0.997925, (float)0.996552, (float)0.994873,
pascal@12756 4832 (float)0.992828, (float)0.990479, (float)0.987762,
pascal@12756 4833 (float)0.984741, (float)0.981384, (float)0.977692,
pascal@12756 4834 (float)0.973694, (float)0.969360, (float)0.964691,
pascal@12756 4835 (float)0.959717, (float)0.954437, (float)0.948853,
pascal@12756 4836 (float)0.942963, (float)0.936768, (float)0.930267,
pascal@12756 4837 (float)0.923492, (float)0.916412, (float)0.909058,
pascal@12756 4838 (float)0.901428, (float)0.893524, (float)0.885345,
pascal@12756 4839 (float)0.876892, (float)0.868225, (float)0.859253,
pascal@12756 4840 (float)0.850067, (float)0.840668, (float)0.830994,
pascal@12756 4841 (float)0.821106, (float)0.811005, (float)0.800720,
pascal@12756 4842 (float)0.790192, (float)0.779480, (float)0.768585,
pascal@12756 4843 (float)0.757477, (float)0.746216, (float)0.734802,
pascal@12756 4844 (float)0.723206, (float)0.711487, (float)0.699585,
pascal@12756 4845 (float)0.687561, (float)0.675415, (float)0.663147,
pascal@12756 4846 (float)0.650787, (float)0.638306, (float)0.625732,
pascal@12756 4847 (float)0.613068, (float)0.600342, (float)0.587524,
pascal@12756 4848 (float)0.574677, (float)0.561768, (float)0.548798,
pascal@12756 4849 (float)0.535828, (float)0.522797, (float)0.509766,
pascal@12756 4850 (float)0.496735, (float)0.483704, (float)0.470673,
pascal@12756 4851 (float)0.457672, (float)0.444702, (float)0.431763,
pascal@12756 4852 (float)0.418884, (float)0.406067, (float)0.393280,
pascal@12756 4853 (float)0.380585, (float)0.367981, (float)0.355438,
pascal@12756 4854 (float)0.343018, (float)0.330688, (float)0.318481,
pascal@12756 4855 (float)0.306396, (float)0.294464, (float)0.282654,
pascal@12756 4856 (float)0.270966, (float)0.259460, (float)0.248108,
pascal@12756 4857 (float)0.236938, (float)0.225952, (float)0.215149,
pascal@12756 4858 (float)0.204529, (float)0.194122, (float)0.183899,
pascal@12756 4859 (float)0.173920, (float)0.164154, (float)0.154602,
pascal@12756 4860 (float)0.145294, (float)0.136230, (float)0.127411,
pascal@12756 4861 (float)0.118835, (float)0.110535, (float)0.102509,
pascal@12756 4862 (float)0.094727, (float)0.087219, (float)0.080017,
pascal@12756 4863 (float)0.073090, (float)0.066437, (float)0.060089,
pascal@12756 4864 (float)0.054047, (float)0.048309, (float)0.042877,
pascal@12756 4865 (float)0.037750, (float)0.032928, (float)0.028442,
pascal@12756 4866 (float)0.024261, (float)0.020416, (float)0.016907,
pascal@12756 4867 (float)0.013702, (float)0.010834, (float)0.008301,
pascal@12756 4868 (float)0.006104, (float)0.004242, (float)0.002716,
pascal@12756 4869 (float)0.001526, (float)0.000671, (float)0.000183
pascal@12756 4870 };
pascal@12756 4871
pascal@12756 4872
pascal@12756 4873
pascal@12756 4874 Andersen, et al. Experimental [Page 87]
pascal@12756 4875
pascal@12756 4876 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4877
pascal@12756 4878
pascal@12756 4879 /* Asymmetric LPC window */
pascal@12756 4880 float lpc_asymwinTbl[BLOCKL_MAX]={
pascal@12756 4881 (float)0.000061, (float)0.000214, (float)0.000458,
pascal@12756 4882 (float)0.000824, (float)0.001282, (float)0.001831,
pascal@12756 4883 (float)0.002472, (float)0.003235, (float)0.004120,
pascal@12756 4884 (float)0.005066, (float)0.006134, (float)0.007294,
pascal@12756 4885 (float)0.008545, (float)0.009918, (float)0.011383,
pascal@12756 4886 (float)0.012939, (float)0.014587, (float)0.016357,
pascal@12756 4887 (float)0.018219, (float)0.020172, (float)0.022217,
pascal@12756 4888 (float)0.024353, (float)0.026611, (float)0.028961,
pascal@12756 4889 (float)0.031372, (float)0.033905, (float)0.036530,
pascal@12756 4890 (float)0.039276, (float)0.042084, (float)0.044983,
pascal@12756 4891 (float)0.047974, (float)0.051086, (float)0.054260,
pascal@12756 4892 (float)0.057526, (float)0.060883, (float)0.064331,
pascal@12756 4893 (float)0.067871, (float)0.071503, (float)0.075226,
pascal@12756 4894 (float)0.079010, (float)0.082916, (float)0.086884,
pascal@12756 4895 (float)0.090942, (float)0.095062, (float)0.099304,
pascal@12756 4896 (float)0.103607, (float)0.107971, (float)0.112427,
pascal@12756 4897 (float)0.116974, (float)0.121582, (float)0.126282,
pascal@12756 4898 (float)0.131073, (float)0.135895, (float)0.140839,
pascal@12756 4899 (float)0.145813, (float)0.150879, (float)0.156006,
pascal@12756 4900 (float)0.161224, (float)0.166504, (float)0.171844,
pascal@12756 4901 (float)0.177246, (float)0.182709, (float)0.188263,
pascal@12756 4902 (float)0.193848, (float)0.199524, (float)0.205231,
pascal@12756 4903 (float)0.211029, (float)0.216858, (float)0.222778,
pascal@12756 4904 (float)0.228729, (float)0.234741, (float)0.240814,
pascal@12756 4905 (float)0.246918, (float)0.253082, (float)0.259308,
pascal@12756 4906 (float)0.265564, (float)0.271881, (float)0.278259,
pascal@12756 4907 (float)0.284668, (float)0.291107, (float)0.297607,
pascal@12756 4908 (float)0.304138, (float)0.310730, (float)0.317322,
pascal@12756 4909 (float)0.323975, (float)0.330658, (float)0.337372,
pascal@12756 4910 (float)0.344147, (float)0.350922, (float)0.357727,
pascal@12756 4911 (float)0.364594, (float)0.371460, (float)0.378357,
pascal@12756 4912 (float)0.385284, (float)0.392212, (float)0.399170,
pascal@12756 4913 (float)0.406158, (float)0.413177, (float)0.420197,
pascal@12756 4914 (float)0.427246, (float)0.434296, (float)0.441376,
pascal@12756 4915 (float)0.448456, (float)0.455536, (float)0.462646,
pascal@12756 4916 (float)0.469757, (float)0.476868, (float)0.483978,
pascal@12756 4917 (float)0.491089, (float)0.498230, (float)0.505341,
pascal@12756 4918 (float)0.512451, (float)0.519592, (float)0.526703,
pascal@12756 4919 (float)0.533813, (float)0.540924, (float)0.548004,
pascal@12756 4920 (float)0.555084, (float)0.562164, (float)0.569244,
pascal@12756 4921 (float)0.576294, (float)0.583313, (float)0.590332,
pascal@12756 4922 (float)0.597321, (float)0.604309, (float)0.611267,
pascal@12756 4923 (float)0.618195, (float)0.625092, (float)0.631989,
pascal@12756 4924 (float)0.638855, (float)0.645660, (float)0.652466,
pascal@12756 4925 (float)0.659241, (float)0.665985, (float)0.672668,
pascal@12756 4926 (float)0.679352, (float)0.685974, (float)0.692566,
pascal@12756 4927
pascal@12756 4928
pascal@12756 4929
pascal@12756 4930 Andersen, et al. Experimental [Page 88]
pascal@12756 4931
pascal@12756 4932 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4933
pascal@12756 4934
pascal@12756 4935 (float)0.699127, (float)0.705658, (float)0.712128,
pascal@12756 4936 (float)0.718536, (float)0.724945, (float)0.731262,
pascal@12756 4937 (float)0.737549, (float)0.743805, (float)0.750000,
pascal@12756 4938 (float)0.756134, (float)0.762238, (float)0.768280,
pascal@12756 4939 (float)0.774261, (float)0.780182, (float)0.786072,
pascal@12756 4940 (float)0.791870, (float)0.797638, (float)0.803314,
pascal@12756 4941 (float)0.808960, (float)0.814514, (float)0.820038,
pascal@12756 4942 (float)0.825470, (float)0.830841, (float)0.836151,
pascal@12756 4943 (float)0.841400, (float)0.846558, (float)0.851654,
pascal@12756 4944 (float)0.856689, (float)0.861633, (float)0.866516,
pascal@12756 4945 (float)0.871338, (float)0.876068, (float)0.880737,
pascal@12756 4946 (float)0.885315, (float)0.889801, (float)0.894226,
pascal@12756 4947 (float)0.898560, (float)0.902832, (float)0.907013,
pascal@12756 4948 (float)0.911102, (float)0.915100, (float)0.919037,
pascal@12756 4949 (float)0.922882, (float)0.926636, (float)0.930328,
pascal@12756 4950 (float)0.933899, (float)0.937408, (float)0.940796,
pascal@12756 4951 (float)0.944122, (float)0.947357, (float)0.950470,
pascal@12756 4952 (float)0.953522, (float)0.956482, (float)0.959351,
pascal@12756 4953 (float)0.962097, (float)0.964783, (float)0.967377,
pascal@12756 4954 (float)0.969849, (float)0.972229, (float)0.974518,
pascal@12756 4955 (float)0.976715, (float)0.978821, (float)0.980835,
pascal@12756 4956 (float)0.982727, (float)0.984528, (float)0.986237,
pascal@12756 4957 (float)0.987854, (float)0.989380, (float)0.990784,
pascal@12756 4958 (float)0.992096, (float)0.993317, (float)0.994415,
pascal@12756 4959 (float)0.995422, (float)0.996338, (float)0.997162,
pascal@12756 4960 (float)0.997864, (float)0.998474, (float)0.998962,
pascal@12756 4961 (float)0.999390, (float)0.999695, (float)0.999878,
pascal@12756 4962 (float)0.999969, (float)0.999969, (float)0.996918,
pascal@12756 4963 (float)0.987701, (float)0.972382, (float)0.951050,
pascal@12756 4964 (float)0.923889, (float)0.891022, (float)0.852631,
pascal@12756 4965 (float)0.809021, (float)0.760406, (float)0.707092,
pascal@12756 4966 (float)0.649445, (float)0.587799, (float)0.522491,
pascal@12756 4967 (float)0.453979, (float)0.382690, (float)0.309021,
pascal@12756 4968 (float)0.233459, (float)0.156433, (float)0.078461
pascal@12756 4969 };
pascal@12756 4970
pascal@12756 4971 /* Lag window for LPC */
pascal@12756 4972 float lpc_lagwinTbl[LPC_FILTERORDER + 1]={
pascal@12756 4973 (float)1.000100, (float)0.998890, (float)0.995569,
pascal@12756 4974 (float)0.990057, (float)0.982392,
pascal@12756 4975 (float)0.972623, (float)0.960816, (float)0.947047,
pascal@12756 4976 (float)0.931405, (float)0.913989, (float)0.894909};
pascal@12756 4977
pascal@12756 4978 /* LSF quantization*/
pascal@12756 4979 float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = {
pascal@12756 4980 (float)0.155396, (float)0.273193, (float)0.451172,
pascal@12756 4981 (float)0.390503, (float)0.648071, (float)1.002075,
pascal@12756 4982 (float)0.440186, (float)0.692261, (float)0.955688,
pascal@12756 4983
pascal@12756 4984
pascal@12756 4985
pascal@12756 4986 Andersen, et al. Experimental [Page 89]
pascal@12756 4987
pascal@12756 4988 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 4989
pascal@12756 4990
pascal@12756 4991 (float)0.343628, (float)0.642334, (float)1.071533,
pascal@12756 4992 (float)0.318359, (float)0.491577, (float)0.670532,
pascal@12756 4993 (float)0.193115, (float)0.375488, (float)0.725708,
pascal@12756 4994 (float)0.364136, (float)0.510376, (float)0.658691,
pascal@12756 4995 (float)0.297485, (float)0.527588, (float)0.842529,
pascal@12756 4996 (float)0.227173, (float)0.365967, (float)0.563110,
pascal@12756 4997 (float)0.244995, (float)0.396729, (float)0.636475,
pascal@12756 4998 (float)0.169434, (float)0.300171, (float)0.520264,
pascal@12756 4999 (float)0.312866, (float)0.464478, (float)0.643188,
pascal@12756 5000 (float)0.248535, (float)0.429932, (float)0.626099,
pascal@12756 5001 (float)0.236206, (float)0.491333, (float)0.817139,
pascal@12756 5002 (float)0.334961, (float)0.625122, (float)0.895752,
pascal@12756 5003 (float)0.343018, (float)0.518555, (float)0.698608,
pascal@12756 5004 (float)0.372803, (float)0.659790, (float)0.945435,
pascal@12756 5005 (float)0.176880, (float)0.316528, (float)0.581421,
pascal@12756 5006 (float)0.416382, (float)0.625977, (float)0.805176,
pascal@12756 5007 (float)0.303223, (float)0.568726, (float)0.915039,
pascal@12756 5008 (float)0.203613, (float)0.351440, (float)0.588135,
pascal@12756 5009 (float)0.221191, (float)0.375000, (float)0.614746,
pascal@12756 5010 (float)0.199951, (float)0.323364, (float)0.476074,
pascal@12756 5011 (float)0.300781, (float)0.433350, (float)0.566895,
pascal@12756 5012 (float)0.226196, (float)0.354004, (float)0.507568,
pascal@12756 5013 (float)0.300049, (float)0.508179, (float)0.711670,
pascal@12756 5014 (float)0.312012, (float)0.492676, (float)0.763428,
pascal@12756 5015 (float)0.329956, (float)0.541016, (float)0.795776,
pascal@12756 5016 (float)0.373779, (float)0.604614, (float)0.928833,
pascal@12756 5017 (float)0.210571, (float)0.452026, (float)0.755249,
pascal@12756 5018 (float)0.271118, (float)0.473267, (float)0.662476,
pascal@12756 5019 (float)0.285522, (float)0.436890, (float)0.634399,
pascal@12756 5020 (float)0.246704, (float)0.565552, (float)0.859009,
pascal@12756 5021 (float)0.270508, (float)0.406250, (float)0.553589,
pascal@12756 5022 (float)0.361450, (float)0.578491, (float)0.813843,
pascal@12756 5023 (float)0.342651, (float)0.482788, (float)0.622437,
pascal@12756 5024 (float)0.340332, (float)0.549438, (float)0.743164,
pascal@12756 5025 (float)0.200439, (float)0.336304, (float)0.540894,
pascal@12756 5026 (float)0.407837, (float)0.644775, (float)0.895142,
pascal@12756 5027 (float)0.294678, (float)0.454834, (float)0.699097,
pascal@12756 5028 (float)0.193115, (float)0.344482, (float)0.643188,
pascal@12756 5029 (float)0.275757, (float)0.420776, (float)0.598755,
pascal@12756 5030 (float)0.380493, (float)0.608643, (float)0.861084,
pascal@12756 5031 (float)0.222778, (float)0.426147, (float)0.676514,
pascal@12756 5032 (float)0.407471, (float)0.700195, (float)1.053101,
pascal@12756 5033 (float)0.218384, (float)0.377197, (float)0.669922,
pascal@12756 5034 (float)0.313232, (float)0.454102, (float)0.600952,
pascal@12756 5035 (float)0.347412, (float)0.571533, (float)0.874146,
pascal@12756 5036 (float)0.238037, (float)0.405396, (float)0.729492,
pascal@12756 5037 (float)0.223877, (float)0.412964, (float)0.822021,
pascal@12756 5038 (float)0.395264, (float)0.582153, (float)0.743896,
pascal@12756 5039
pascal@12756 5040
pascal@12756 5041
pascal@12756 5042 Andersen, et al. Experimental [Page 90]
pascal@12756 5043
pascal@12756 5044 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5045
pascal@12756 5046
pascal@12756 5047 (float)0.247925, (float)0.485596, (float)0.720581,
pascal@12756 5048 (float)0.229126, (float)0.496582, (float)0.907715,
pascal@12756 5049 (float)0.260132, (float)0.566895, (float)1.012695,
pascal@12756 5050 (float)0.337402, (float)0.611572, (float)0.978149,
pascal@12756 5051 (float)0.267822, (float)0.447632, (float)0.769287,
pascal@12756 5052 (float)0.250610, (float)0.381714, (float)0.530029,
pascal@12756 5053 (float)0.430054, (float)0.805054, (float)1.221924,
pascal@12756 5054 (float)0.382568, (float)0.544067, (float)0.701660,
pascal@12756 5055 (float)0.383545, (float)0.710327, (float)1.149170,
pascal@12756 5056 (float)0.271362, (float)0.529053, (float)0.775513,
pascal@12756 5057 (float)0.246826, (float)0.393555, (float)0.588623,
pascal@12756 5058 (float)0.266846, (float)0.422119, (float)0.676758,
pascal@12756 5059 (float)0.311523, (float)0.580688, (float)0.838623,
pascal@12756 5060 (float)1.331177, (float)1.576782, (float)1.779541,
pascal@12756 5061 (float)1.160034, (float)1.401978, (float)1.768188,
pascal@12756 5062 (float)1.161865, (float)1.525146, (float)1.715332,
pascal@12756 5063 (float)0.759521, (float)0.913940, (float)1.119873,
pascal@12756 5064 (float)0.947144, (float)1.121338, (float)1.282471,
pascal@12756 5065 (float)1.015015, (float)1.557007, (float)1.804932,
pascal@12756 5066 (float)1.172974, (float)1.402100, (float)1.692627,
pascal@12756 5067 (float)1.087524, (float)1.474243, (float)1.665405,
pascal@12756 5068 (float)0.899536, (float)1.105225, (float)1.406250,
pascal@12756 5069 (float)1.148438, (float)1.484741, (float)1.796265,
pascal@12756 5070 (float)0.785645, (float)1.209839, (float)1.567749,
pascal@12756 5071 (float)0.867798, (float)1.166504, (float)1.450684,
pascal@12756 5072 (float)0.922485, (float)1.229858, (float)1.420898,
pascal@12756 5073 (float)0.791260, (float)1.123291, (float)1.409546,
pascal@12756 5074 (float)0.788940, (float)0.966064, (float)1.340332,
pascal@12756 5075 (float)1.051147, (float)1.272827, (float)1.556641,
pascal@12756 5076 (float)0.866821, (float)1.181152, (float)1.538818,
pascal@12756 5077 (float)0.906738, (float)1.373535, (float)1.607910,
pascal@12756 5078 (float)1.244751, (float)1.581421, (float)1.933838,
pascal@12756 5079 (float)0.913940, (float)1.337280, (float)1.539673,
pascal@12756 5080 (float)0.680542, (float)0.959229, (float)1.662720,
pascal@12756 5081 (float)0.887207, (float)1.430542, (float)1.800781,
pascal@12756 5082 (float)0.912598, (float)1.433594, (float)1.683960,
pascal@12756 5083 (float)0.860474, (float)1.060303, (float)1.455322,
pascal@12756 5084 (float)1.005127, (float)1.381104, (float)1.706909,
pascal@12756 5085 (float)0.800781, (float)1.363892, (float)1.829102,
pascal@12756 5086 (float)0.781860, (float)1.124390, (float)1.505981,
pascal@12756 5087 (float)1.003662, (float)1.471436, (float)1.684692,
pascal@12756 5088 (float)0.981323, (float)1.309570, (float)1.618042,
pascal@12756 5089 (float)1.228760, (float)1.554321, (float)1.756470,
pascal@12756 5090 (float)0.734375, (float)0.895752, (float)1.225586,
pascal@12756 5091 (float)0.841797, (float)1.055664, (float)1.249268,
pascal@12756 5092 (float)0.920166, (float)1.119385, (float)1.486206,
pascal@12756 5093 (float)0.894409, (float)1.539063, (float)1.828979,
pascal@12756 5094 (float)1.283691, (float)1.543335, (float)1.858276,
pascal@12756 5095
pascal@12756 5096
pascal@12756 5097
pascal@12756 5098 Andersen, et al. Experimental [Page 91]
pascal@12756 5099
pascal@12756 5100 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5101
pascal@12756 5102
pascal@12756 5103 (float)0.676025, (float)0.933105, (float)1.490845,
pascal@12756 5104 (float)0.821289, (float)1.491821, (float)1.739868,
pascal@12756 5105 (float)0.923218, (float)1.144653, (float)1.580566,
pascal@12756 5106 (float)1.057251, (float)1.345581, (float)1.635864,
pascal@12756 5107 (float)0.888672, (float)1.074951, (float)1.353149,
pascal@12756 5108 (float)0.942749, (float)1.195435, (float)1.505493,
pascal@12756 5109 (float)1.492310, (float)1.788086, (float)2.039673,
pascal@12756 5110 (float)1.070313, (float)1.634399, (float)1.860962,
pascal@12756 5111 (float)1.253296, (float)1.488892, (float)1.686035,
pascal@12756 5112 (float)0.647095, (float)0.864014, (float)1.401855,
pascal@12756 5113 (float)0.866699, (float)1.254883, (float)1.453369,
pascal@12756 5114 (float)1.063965, (float)1.532593, (float)1.731323,
pascal@12756 5115 (float)1.167847, (float)1.521484, (float)1.884033,
pascal@12756 5116 (float)0.956055, (float)1.502075, (float)1.745605,
pascal@12756 5117 (float)0.928711, (float)1.288574, (float)1.479614,
pascal@12756 5118 (float)1.088013, (float)1.380737, (float)1.570801,
pascal@12756 5119 (float)0.905029, (float)1.186768, (float)1.371948,
pascal@12756 5120 (float)1.057861, (float)1.421021, (float)1.617432,
pascal@12756 5121 (float)1.108276, (float)1.312500, (float)1.501465,
pascal@12756 5122 (float)0.979492, (float)1.416992, (float)1.624268,
pascal@12756 5123 (float)1.276001, (float)1.661011, (float)2.007935,
pascal@12756 5124 (float)0.993042, (float)1.168579, (float)1.331665,
pascal@12756 5125 (float)0.778198, (float)0.944946, (float)1.235962,
pascal@12756 5126 (float)1.223755, (float)1.491333, (float)1.815674,
pascal@12756 5127 (float)0.852661, (float)1.350464, (float)1.722290,
pascal@12756 5128 (float)1.134766, (float)1.593140, (float)1.787354,
pascal@12756 5129 (float)1.051392, (float)1.339722, (float)1.531006,
pascal@12756 5130 (float)0.803589, (float)1.271240, (float)1.652100,
pascal@12756 5131 (float)0.755737, (float)1.143555, (float)1.639404,
pascal@12756 5132 (float)0.700928, (float)0.837280, (float)1.130371,
pascal@12756 5133 (float)0.942749, (float)1.197876, (float)1.669800,
pascal@12756 5134 (float)0.993286, (float)1.378296, (float)1.566528,
pascal@12756 5135 (float)0.801025, (float)1.095337, (float)1.298950,
pascal@12756 5136 (float)0.739990, (float)1.032959, (float)1.383667,
pascal@12756 5137 (float)0.845703, (float)1.072266, (float)1.543823,
pascal@12756 5138 (float)0.915649, (float)1.072266, (float)1.224487,
pascal@12756 5139 (float)1.021973, (float)1.226196, (float)1.481323,
pascal@12756 5140 (float)0.999878, (float)1.204102, (float)1.555908,
pascal@12756 5141 (float)0.722290, (float)0.913940, (float)1.340210,
pascal@12756 5142 (float)0.673340, (float)0.835938, (float)1.259521,
pascal@12756 5143 (float)0.832397, (float)1.208374, (float)1.394165,
pascal@12756 5144 (float)0.962158, (float)1.576172, (float)1.912842,
pascal@12756 5145 (float)1.166748, (float)1.370850, (float)1.556763,
pascal@12756 5146 (float)0.946289, (float)1.138550, (float)1.400391,
pascal@12756 5147 (float)1.035034, (float)1.218262, (float)1.386475,
pascal@12756 5148 (float)1.393799, (float)1.717773, (float)2.000244,
pascal@12756 5149 (float)0.972656, (float)1.260986, (float)1.760620,
pascal@12756 5150 (float)1.028198, (float)1.288452, (float)1.484619,
pascal@12756 5151
pascal@12756 5152
pascal@12756 5153
pascal@12756 5154 Andersen, et al. Experimental [Page 92]
pascal@12756 5155
pascal@12756 5156 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5157
pascal@12756 5158
pascal@12756 5159 (float)0.773560, (float)1.258057, (float)1.756714,
pascal@12756 5160 (float)1.080322, (float)1.328003, (float)1.742676,
pascal@12756 5161 (float)0.823975, (float)1.450806, (float)1.917725,
pascal@12756 5162 (float)0.859009, (float)1.016602, (float)1.191895,
pascal@12756 5163 (float)0.843994, (float)1.131104, (float)1.645020,
pascal@12756 5164 (float)1.189697, (float)1.702759, (float)1.894409,
pascal@12756 5165 (float)1.346680, (float)1.763184, (float)2.066040,
pascal@12756 5166 (float)0.980469, (float)1.253784, (float)1.441650,
pascal@12756 5167 (float)1.338135, (float)1.641968, (float)1.932739,
pascal@12756 5168 (float)1.223267, (float)1.424194, (float)1.626465,
pascal@12756 5169 (float)0.765747, (float)1.004150, (float)1.579102,
pascal@12756 5170 (float)1.042847, (float)1.269165, (float)1.647461,
pascal@12756 5171 (float)0.968750, (float)1.257568, (float)1.555786,
pascal@12756 5172 (float)0.826294, (float)0.993408, (float)1.275146,
pascal@12756 5173 (float)0.742310, (float)0.950439, (float)1.430542,
pascal@12756 5174 (float)1.054321, (float)1.439819, (float)1.828003,
pascal@12756 5175 (float)1.072998, (float)1.261719, (float)1.441895,
pascal@12756 5176 (float)0.859375, (float)1.036377, (float)1.314819,
pascal@12756 5177 (float)0.895752, (float)1.267212, (float)1.605591,
pascal@12756 5178 (float)0.805420, (float)0.962891, (float)1.142334,
pascal@12756 5179 (float)0.795654, (float)1.005493, (float)1.468506,
pascal@12756 5180 (float)1.105347, (float)1.313843, (float)1.584839,
pascal@12756 5181 (float)0.792236, (float)1.221802, (float)1.465698,
pascal@12756 5182 (float)1.170532, (float)1.467651, (float)1.664063,
pascal@12756 5183 (float)0.838257, (float)1.153198, (float)1.342163,
pascal@12756 5184 (float)0.968018, (float)1.198242, (float)1.391235,
pascal@12756 5185 (float)1.250122, (float)1.623535, (float)1.823608,
pascal@12756 5186 (float)0.711670, (float)1.058350, (float)1.512085,
pascal@12756 5187 (float)1.204834, (float)1.454468, (float)1.739136,
pascal@12756 5188 (float)1.137451, (float)1.421753, (float)1.620117,
pascal@12756 5189 (float)0.820435, (float)1.322754, (float)1.578247,
pascal@12756 5190 (float)0.798706, (float)1.005005, (float)1.213867,
pascal@12756 5191 (float)0.980713, (float)1.324951, (float)1.512939,
pascal@12756 5192 (float)1.112305, (float)1.438843, (float)1.735596,
pascal@12756 5193 (float)1.135498, (float)1.356689, (float)1.635742,
pascal@12756 5194 (float)1.101318, (float)1.387451, (float)1.686523,
pascal@12756 5195 (float)0.849854, (float)1.276978, (float)1.523438,
pascal@12756 5196 (float)1.377930, (float)1.627563, (float)1.858154,
pascal@12756 5197 (float)0.884888, (float)1.095459, (float)1.287476,
pascal@12756 5198 (float)1.289795, (float)1.505859, (float)1.756592,
pascal@12756 5199 (float)0.817505, (float)1.384155, (float)1.650513,
pascal@12756 5200 (float)1.446655, (float)1.702148, (float)1.931885,
pascal@12756 5201 (float)0.835815, (float)1.023071, (float)1.385376,
pascal@12756 5202 (float)0.916626, (float)1.139038, (float)1.335327,
pascal@12756 5203 (float)0.980103, (float)1.174072, (float)1.453735,
pascal@12756 5204 (float)1.705688, (float)2.153809, (float)2.398315, (float)2.743408,
pascal@12756 5205 (float)1.797119, (float)2.016846, (float)2.445679, (float)2.701904,
pascal@12756 5206 (float)1.990356, (float)2.219116, (float)2.576416, (float)2.813477,
pascal@12756 5207
pascal@12756 5208
pascal@12756 5209
pascal@12756 5210 Andersen, et al. Experimental [Page 93]
pascal@12756 5211
pascal@12756 5212 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5213
pascal@12756 5214
pascal@12756 5215 (float)1.849365, (float)2.190918, (float)2.611572, (float)2.835083,
pascal@12756 5216 (float)1.657959, (float)1.854370, (float)2.159058, (float)2.726196,
pascal@12756 5217 (float)1.437744, (float)1.897705, (float)2.253174, (float)2.655396,
pascal@12756 5218 (float)2.028687, (float)2.247314, (float)2.542358, (float)2.875854,
pascal@12756 5219 (float)1.736938, (float)1.922119, (float)2.185913, (float)2.743408,
pascal@12756 5220 (float)1.521606, (float)1.870972, (float)2.526855, (float)2.786987,
pascal@12756 5221 (float)1.841431, (float)2.050659, (float)2.463623, (float)2.857666,
pascal@12756 5222 (float)1.590088, (float)2.067261, (float)2.427979, (float)2.794434,
pascal@12756 5223 (float)1.746826, (float)2.057373, (float)2.320190, (float)2.800781,
pascal@12756 5224 (float)1.734619, (float)1.940552, (float)2.306030, (float)2.826416,
pascal@12756 5225 (float)1.786255, (float)2.204468, (float)2.457520, (float)2.795288,
pascal@12756 5226 (float)1.861084, (float)2.170532, (float)2.414551, (float)2.763672,
pascal@12756 5227 (float)2.001465, (float)2.307617, (float)2.552734, (float)2.811890,
pascal@12756 5228 (float)1.784424, (float)2.124146, (float)2.381592, (float)2.645508,
pascal@12756 5229 (float)1.888794, (float)2.135864, (float)2.418579, (float)2.861206,
pascal@12756 5230 (float)2.301147, (float)2.531250, (float)2.724976, (float)2.913086,
pascal@12756 5231 (float)1.837769, (float)2.051270, (float)2.261963, (float)2.553223,
pascal@12756 5232 (float)2.012939, (float)2.221191, (float)2.440186, (float)2.678101,
pascal@12756 5233 (float)1.429565, (float)1.858276, (float)2.582275, (float)2.845703,
pascal@12756 5234 (float)1.622803, (float)1.897705, (float)2.367310, (float)2.621094,
pascal@12756 5235 (float)1.581543, (float)1.960449, (float)2.515869, (float)2.736450,
pascal@12756 5236 (float)1.419434, (float)1.933960, (float)2.394653, (float)2.746704,
pascal@12756 5237 (float)1.721924, (float)2.059570, (float)2.421753, (float)2.769653,
pascal@12756 5238 (float)1.911011, (float)2.220703, (float)2.461060, (float)2.740723,
pascal@12756 5239 (float)1.581177, (float)1.860840, (float)2.516968, (float)2.874634,
pascal@12756 5240 (float)1.870361, (float)2.098755, (float)2.432373, (float)2.656494,
pascal@12756 5241 (float)2.059692, (float)2.279785, (float)2.495605, (float)2.729370,
pascal@12756 5242 (float)1.815674, (float)2.181519, (float)2.451538, (float)2.680542,
pascal@12756 5243 (float)1.407959, (float)1.768311, (float)2.343018, (float)2.668091,
pascal@12756 5244 (float)2.168701, (float)2.394653, (float)2.604736, (float)2.829346,
pascal@12756 5245 (float)1.636230, (float)1.865723, (float)2.329102, (float)2.824219,
pascal@12756 5246 (float)1.878906, (float)2.139526, (float)2.376709, (float)2.679810,
pascal@12756 5247 (float)1.765381, (float)1.971802, (float)2.195435, (float)2.586914,
pascal@12756 5248 (float)2.164795, (float)2.410889, (float)2.673706, (float)2.903198,
pascal@12756 5249 (float)2.071899, (float)2.331055, (float)2.645874, (float)2.907104,
pascal@12756 5250 (float)2.026001, (float)2.311523, (float)2.594849, (float)2.863892,
pascal@12756 5251 (float)1.948975, (float)2.180786, (float)2.514893, (float)2.797852,
pascal@12756 5252 (float)1.881836, (float)2.130859, (float)2.478149, (float)2.804199,
pascal@12756 5253 (float)2.238159, (float)2.452759, (float)2.652832, (float)2.868286,
pascal@12756 5254 (float)1.897949, (float)2.101685, (float)2.524292, (float)2.880127,
pascal@12756 5255 (float)1.856445, (float)2.074585, (float)2.541016, (float)2.791748,
pascal@12756 5256 (float)1.695557, (float)2.199097, (float)2.506226, (float)2.742676,
pascal@12756 5257 (float)1.612671, (float)1.877075, (float)2.435425, (float)2.732910,
pascal@12756 5258 (float)1.568848, (float)1.786499, (float)2.194580, (float)2.768555,
pascal@12756 5259 (float)1.953369, (float)2.164551, (float)2.486938, (float)2.874023,
pascal@12756 5260 (float)1.388306, (float)1.725342, (float)2.384521, (float)2.771851,
pascal@12756 5261 (float)2.115356, (float)2.337769, (float)2.592896, (float)2.864014,
pascal@12756 5262 (float)1.905762, (float)2.111328, (float)2.363525, (float)2.789307,
pascal@12756 5263
pascal@12756 5264
pascal@12756 5265
pascal@12756 5266 Andersen, et al. Experimental [Page 94]
pascal@12756 5267
pascal@12756 5268 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5269
pascal@12756 5270
pascal@12756 5271 (float)1.882568, (float)2.332031, (float)2.598267, (float)2.827637,
pascal@12756 5272 (float)1.683594, (float)2.088745, (float)2.361938, (float)2.608643,
pascal@12756 5273 (float)1.874023, (float)2.182129, (float)2.536133, (float)2.766968,
pascal@12756 5274 (float)1.861938, (float)2.070435, (float)2.309692, (float)2.700562,
pascal@12756 5275 (float)1.722168, (float)2.107422, (float)2.477295, (float)2.837646,
pascal@12756 5276 (float)1.926880, (float)2.184692, (float)2.442627, (float)2.663818,
pascal@12756 5277 (float)2.123901, (float)2.337280, (float)2.553101, (float)2.777466,
pascal@12756 5278 (float)1.588135, (float)1.911499, (float)2.212769, (float)2.543945,
pascal@12756 5279 (float)2.053955, (float)2.370850, (float)2.712158, (float)2.939941,
pascal@12756 5280 (float)2.210449, (float)2.519653, (float)2.770386, (float)2.958618,
pascal@12756 5281 (float)2.199463, (float)2.474731, (float)2.718262, (float)2.919922,
pascal@12756 5282 (float)1.960083, (float)2.175415, (float)2.608032, (float)2.888794,
pascal@12756 5283 (float)1.953735, (float)2.185181, (float)2.428223, (float)2.809570,
pascal@12756 5284 (float)1.615234, (float)2.036499, (float)2.576538, (float)2.834595,
pascal@12756 5285 (float)1.621094, (float)2.028198, (float)2.431030, (float)2.664673,
pascal@12756 5286 (float)1.824951, (float)2.267456, (float)2.514526, (float)2.747925,
pascal@12756 5287 (float)1.994263, (float)2.229126, (float)2.475220, (float)2.833984,
pascal@12756 5288 (float)1.746338, (float)2.011353, (float)2.588257, (float)2.826904,
pascal@12756 5289 (float)1.562866, (float)2.135986, (float)2.471680, (float)2.687256,
pascal@12756 5290 (float)1.748901, (float)2.083496, (float)2.460938, (float)2.686279,
pascal@12756 5291 (float)1.758057, (float)2.131470, (float)2.636597, (float)2.891602,
pascal@12756 5292 (float)2.071289, (float)2.299072, (float)2.550781, (float)2.814331,
pascal@12756 5293 (float)1.839600, (float)2.094360, (float)2.496460, (float)2.723999,
pascal@12756 5294 (float)1.882202, (float)2.088257, (float)2.636841, (float)2.923096,
pascal@12756 5295 (float)1.957886, (float)2.153198, (float)2.384399, (float)2.615234,
pascal@12756 5296 (float)1.992920, (float)2.351196, (float)2.654419, (float)2.889771,
pascal@12756 5297 (float)2.012817, (float)2.262451, (float)2.643799, (float)2.903076,
pascal@12756 5298 (float)2.025635, (float)2.254761, (float)2.508423, (float)2.784058,
pascal@12756 5299 (float)2.316040, (float)2.589355, (float)2.794189, (float)2.963623,
pascal@12756 5300 (float)1.741211, (float)2.279541, (float)2.578491, (float)2.816284,
pascal@12756 5301 (float)1.845337, (float)2.055786, (float)2.348511, (float)2.822021,
pascal@12756 5302 (float)1.679932, (float)1.926514, (float)2.499756, (float)2.835693,
pascal@12756 5303 (float)1.722534, (float)1.946899, (float)2.448486, (float)2.728760,
pascal@12756 5304 (float)1.829834, (float)2.043213, (float)2.580444, (float)2.867676,
pascal@12756 5305 (float)1.676636, (float)2.071655, (float)2.322510, (float)2.704834,
pascal@12756 5306 (float)1.791504, (float)2.113525, (float)2.469727, (float)2.784058,
pascal@12756 5307 (float)1.977051, (float)2.215088, (float)2.497437, (float)2.726929,
pascal@12756 5308 (float)1.800171, (float)2.106689, (float)2.357788, (float)2.738892,
pascal@12756 5309 (float)1.827759, (float)2.170166, (float)2.525879, (float)2.852417,
pascal@12756 5310 (float)1.918335, (float)2.132813, (float)2.488403, (float)2.728149,
pascal@12756 5311 (float)1.916748, (float)2.225098, (float)2.542603, (float)2.857666,
pascal@12756 5312 (float)1.761230, (float)1.976074, (float)2.507446, (float)2.884521,
pascal@12756 5313 (float)2.053711, (float)2.367432, (float)2.608032, (float)2.837646,
pascal@12756 5314 (float)1.595337, (float)2.000977, (float)2.307129, (float)2.578247,
pascal@12756 5315 (float)1.470581, (float)2.031250, (float)2.375854, (float)2.647583,
pascal@12756 5316 (float)1.801392, (float)2.128052, (float)2.399780, (float)2.822876,
pascal@12756 5317 (float)1.853638, (float)2.066650, (float)2.429199, (float)2.751465,
pascal@12756 5318 (float)1.956299, (float)2.163696, (float)2.394775, (float)2.734253,
pascal@12756 5319
pascal@12756 5320
pascal@12756 5321
pascal@12756 5322 Andersen, et al. Experimental [Page 95]
pascal@12756 5323
pascal@12756 5324 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5325
pascal@12756 5326
pascal@12756 5327 (float)1.963623, (float)2.275757, (float)2.585327, (float)2.865234,
pascal@12756 5328 (float)1.887451, (float)2.105469, (float)2.331787, (float)2.587402,
pascal@12756 5329 (float)2.120117, (float)2.443359, (float)2.733887, (float)2.941406,
pascal@12756 5330 (float)1.506348, (float)1.766968, (float)2.400513, (float)2.851807,
pascal@12756 5331 (float)1.664551, (float)1.981079, (float)2.375732, (float)2.774414,
pascal@12756 5332 (float)1.720703, (float)1.978882, (float)2.391479, (float)2.640991,
pascal@12756 5333 (float)1.483398, (float)1.814819, (float)2.434448, (float)2.722290,
pascal@12756 5334 (float)1.769043, (float)2.136597, (float)2.563721, (float)2.774414,
pascal@12756 5335 (float)1.810791, (float)2.049316, (float)2.373901, (float)2.613647,
pascal@12756 5336 (float)1.788330, (float)2.005981, (float)2.359131, (float)2.723145,
pascal@12756 5337 (float)1.785156, (float)1.993164, (float)2.399780, (float)2.832520,
pascal@12756 5338 (float)1.695313, (float)2.022949, (float)2.522583, (float)2.745117,
pascal@12756 5339 (float)1.584106, (float)1.965576, (float)2.299927, (float)2.715576,
pascal@12756 5340 (float)1.894897, (float)2.249878, (float)2.655884, (float)2.897705,
pascal@12756 5341 (float)1.720581, (float)1.995728, (float)2.299438, (float)2.557007,
pascal@12756 5342 (float)1.619385, (float)2.173950, (float)2.574219, (float)2.787964,
pascal@12756 5343 (float)1.883179, (float)2.220459, (float)2.474365, (float)2.825073,
pascal@12756 5344 (float)1.447632, (float)2.045044, (float)2.555542, (float)2.744873,
pascal@12756 5345 (float)1.502686, (float)2.156616, (float)2.653320, (float)2.846558,
pascal@12756 5346 (float)1.711548, (float)1.944092, (float)2.282959, (float)2.685791,
pascal@12756 5347 (float)1.499756, (float)1.867554, (float)2.341064, (float)2.578857,
pascal@12756 5348 (float)1.916870, (float)2.135132, (float)2.568237, (float)2.826050,
pascal@12756 5349 (float)1.498047, (float)1.711182, (float)2.223267, (float)2.755127,
pascal@12756 5350 (float)1.808716, (float)1.997559, (float)2.256470, (float)2.758545,
pascal@12756 5351 (float)2.088501, (float)2.402710, (float)2.667358, (float)2.890259,
pascal@12756 5352 (float)1.545044, (float)1.819214, (float)2.324097, (float)2.692993,
pascal@12756 5353 (float)1.796021, (float)2.012573, (float)2.505737, (float)2.784912,
pascal@12756 5354 (float)1.786499, (float)2.041748, (float)2.290405, (float)2.650757,
pascal@12756 5355 (float)1.938232, (float)2.264404, (float)2.529053, (float)2.796143
pascal@12756 5356 };
pascal@12756 5357
pascal@12756 5358 A.9. anaFilter.h
pascal@12756 5359
pascal@12756 5360 /******************************************************************
pascal@12756 5361
pascal@12756 5362 iLBC Speech Coder ANSI-C Source Code
pascal@12756 5363
pascal@12756 5364 anaFilter.h
pascal@12756 5365
pascal@12756 5366 Copyright (C) The Internet Society (2004).
pascal@12756 5367 All Rights Reserved.
pascal@12756 5368
pascal@12756 5369 ******************************************************************/
pascal@12756 5370
pascal@12756 5371 #ifndef __iLBC_ANAFILTER_H
pascal@12756 5372 #define __iLBC_ANAFILTER_H
pascal@12756 5373
pascal@12756 5374 void anaFilter(
pascal@12756 5375
pascal@12756 5376
pascal@12756 5377
pascal@12756 5378 Andersen, et al. Experimental [Page 96]
pascal@12756 5379
pascal@12756 5380 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5381
pascal@12756 5382
pascal@12756 5383 float *In, /* (i) Signal to be filtered */
pascal@12756 5384 float *a, /* (i) LP parameters */
pascal@12756 5385 int len,/* (i) Length of signal */
pascal@12756 5386 float *Out, /* (o) Filtered signal */
pascal@12756 5387 float *mem /* (i/o) Filter state */
pascal@12756 5388 );
pascal@12756 5389
pascal@12756 5390 #endif
pascal@12756 5391
pascal@12756 5392 A.10. anaFilter.c
pascal@12756 5393
pascal@12756 5394 /******************************************************************
pascal@12756 5395
pascal@12756 5396 iLBC Speech Coder ANSI-C Source Code
pascal@12756 5397
pascal@12756 5398 anaFilter.c
pascal@12756 5399
pascal@12756 5400 Copyright (C) The Internet Society (2004).
pascal@12756 5401 All Rights Reserved.
pascal@12756 5402
pascal@12756 5403 ******************************************************************/
pascal@12756 5404
pascal@12756 5405 #include <string.h>
pascal@12756 5406 #include "iLBC_define.h"
pascal@12756 5407
pascal@12756 5408 /*----------------------------------------------------------------*
pascal@12756 5409 * LP analysis filter.
pascal@12756 5410 *---------------------------------------------------------------*/
pascal@12756 5411
pascal@12756 5412 void anaFilter(
pascal@12756 5413 float *In, /* (i) Signal to be filtered */
pascal@12756 5414 float *a, /* (i) LP parameters */
pascal@12756 5415 int len,/* (i) Length of signal */
pascal@12756 5416 float *Out, /* (o) Filtered signal */
pascal@12756 5417 float *mem /* (i/o) Filter state */
pascal@12756 5418 ){
pascal@12756 5419 int i, j;
pascal@12756 5420 float *po, *pi, *pm, *pa;
pascal@12756 5421
pascal@12756 5422 po = Out;
pascal@12756 5423
pascal@12756 5424 /* Filter first part using memory from past */
pascal@12756 5425
pascal@12756 5426 for (i=0; i<LPC_FILTERORDER; i++) {
pascal@12756 5427 pi = &In[i];
pascal@12756 5428 pm = &mem[LPC_FILTERORDER-1];
pascal@12756 5429 pa = a;
pascal@12756 5430 *po=0.0;
pascal@12756 5431
pascal@12756 5432
pascal@12756 5433
pascal@12756 5434 Andersen, et al. Experimental [Page 97]
pascal@12756 5435
pascal@12756 5436 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5437
pascal@12756 5438
pascal@12756 5439 for (j=0; j<=i; j++) {
pascal@12756 5440 *po+=(*pa++)*(*pi--);
pascal@12756 5441 }
pascal@12756 5442 for (j=i+1; j<LPC_FILTERORDER+1; j++) {
pascal@12756 5443
pascal@12756 5444 *po+=(*pa++)*(*pm--);
pascal@12756 5445 }
pascal@12756 5446 po++;
pascal@12756 5447 }
pascal@12756 5448
pascal@12756 5449 /* Filter last part where the state is entirely
pascal@12756 5450 in the input vector */
pascal@12756 5451
pascal@12756 5452 for (i=LPC_FILTERORDER; i<len; i++) {
pascal@12756 5453 pi = &In[i];
pascal@12756 5454 pa = a;
pascal@12756 5455 *po=0.0;
pascal@12756 5456 for (j=0; j<LPC_FILTERORDER+1; j++) {
pascal@12756 5457 *po+=(*pa++)*(*pi--);
pascal@12756 5458 }
pascal@12756 5459 po++;
pascal@12756 5460 }
pascal@12756 5461
pascal@12756 5462 /* Update state vector */
pascal@12756 5463
pascal@12756 5464 memcpy(mem, &In[len-LPC_FILTERORDER],
pascal@12756 5465 LPC_FILTERORDER*sizeof(float));
pascal@12756 5466 }
pascal@12756 5467
pascal@12756 5468 A.11. createCB.h
pascal@12756 5469
pascal@12756 5470 /******************************************************************
pascal@12756 5471
pascal@12756 5472 iLBC Speech Coder ANSI-C Source Code
pascal@12756 5473
pascal@12756 5474 createCB.h
pascal@12756 5475
pascal@12756 5476 Copyright (C) The Internet Society (2004).
pascal@12756 5477 All Rights Reserved.
pascal@12756 5478
pascal@12756 5479 ******************************************************************/
pascal@12756 5480
pascal@12756 5481 #ifndef __iLBC_CREATECB_H
pascal@12756 5482 #define __iLBC_CREATECB_H
pascal@12756 5483
pascal@12756 5484 void filteredCBvecs(
pascal@12756 5485 float *cbvectors, /* (o) Codebook vector for the
pascal@12756 5486 higher section */
pascal@12756 5487
pascal@12756 5488
pascal@12756 5489
pascal@12756 5490 Andersen, et al. Experimental [Page 98]
pascal@12756 5491
pascal@12756 5492 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5493
pascal@12756 5494
pascal@12756 5495 float *mem, /* (i) Buffer to create codebook
pascal@12756 5496 vectors from */
pascal@12756 5497 int lMem /* (i) Length of buffer */
pascal@12756 5498 );
pascal@12756 5499
pascal@12756 5500 void searchAugmentedCB(
pascal@12756 5501 int low, /* (i) Start index for the search */
pascal@12756 5502 int high, /* (i) End index for the search */
pascal@12756 5503 int stage, /* (i) Current stage */
pascal@12756 5504 int startIndex, /* (i) CB index for the first
pascal@12756 5505 augmented vector */
pascal@12756 5506 float *target, /* (i) Target vector for encoding */
pascal@12756 5507 float *buffer, /* (i) Pointer to the end of the
pascal@12756 5508 buffer for augmented codebook
pascal@12756 5509 construction */
pascal@12756 5510 float *max_measure, /* (i/o) Currently maximum measure */
pascal@12756 5511 int *best_index,/* (o) Currently the best index */
pascal@12756 5512 float *gain, /* (o) Currently the best gain */
pascal@12756 5513 float *energy, /* (o) Energy of augmented
pascal@12756 5514 codebook vectors */
pascal@12756 5515 float *invenergy/* (o) Inv energy of aug codebook
pascal@12756 5516 vectors */
pascal@12756 5517 );
pascal@12756 5518
pascal@12756 5519 void createAugmentedVec(
pascal@12756 5520 int index, /* (i) Index for the aug vector
pascal@12756 5521 to be created */
pascal@12756 5522 float *buffer, /* (i) Pointer to the end of the
pascal@12756 5523 buffer for augmented codebook
pascal@12756 5524 construction */
pascal@12756 5525 float *cbVec /* (o) The construced codebook vector */
pascal@12756 5526 );
pascal@12756 5527
pascal@12756 5528 #endif
pascal@12756 5529
pascal@12756 5530 A.12. createCB.c
pascal@12756 5531
pascal@12756 5532
pascal@12756 5533 /******************************************************************
pascal@12756 5534
pascal@12756 5535 iLBC Speech Coder ANSI-C Source Code
pascal@12756 5536
pascal@12756 5537 createCB.c
pascal@12756 5538
pascal@12756 5539 Copyright (C) The Internet Society (2004).
pascal@12756 5540 All Rights Reserved.
pascal@12756 5541
pascal@12756 5542 ******************************************************************/
pascal@12756 5543
pascal@12756 5544
pascal@12756 5545
pascal@12756 5546 Andersen, et al. Experimental [Page 99]
pascal@12756 5547
pascal@12756 5548 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5549
pascal@12756 5550
pascal@12756 5551 #include "iLBC_define.h"
pascal@12756 5552 #include "constants.h"
pascal@12756 5553 #include <string.h>
pascal@12756 5554 #include <math.h>
pascal@12756 5555
pascal@12756 5556 /*----------------------------------------------------------------*
pascal@12756 5557 * Construct an additional codebook vector by filtering the
pascal@12756 5558 * initial codebook buffer. This vector is then used to expand
pascal@12756 5559 * the codebook with an additional section.
pascal@12756 5560 *---------------------------------------------------------------*/
pascal@12756 5561
pascal@12756 5562 void filteredCBvecs(
pascal@12756 5563 float *cbvectors, /* (o) Codebook vectors for the
pascal@12756 5564 higher section */
pascal@12756 5565 float *mem, /* (i) Buffer to create codebook
pascal@12756 5566 vector from */
pascal@12756 5567 int lMem /* (i) Length of buffer */
pascal@12756 5568 ){
pascal@12756 5569 int j, k;
pascal@12756 5570 float *pp, *pp1;
pascal@12756 5571 float tempbuff2[CB_MEML+CB_FILTERLEN];
pascal@12756 5572 float *pos;
pascal@12756 5573
pascal@12756 5574 memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float));
pascal@12756 5575 memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float));
pascal@12756 5576 memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0,
pascal@12756 5577 (CB_HALFFILTERLEN+1)*sizeof(float));
pascal@12756 5578
pascal@12756 5579 /* Create codebook vector for higher section by filtering */
pascal@12756 5580
pascal@12756 5581 /* do filtering */
pascal@12756 5582 pos=cbvectors;
pascal@12756 5583 memset(pos, 0, lMem*sizeof(float));
pascal@12756 5584 for (k=0; k<lMem; k++) {
pascal@12756 5585 pp=&tempbuff2[k];
pascal@12756 5586 pp1=&cbfiltersTbl[CB_FILTERLEN-1];
pascal@12756 5587 for (j=0;j<CB_FILTERLEN;j++) {
pascal@12756 5588 (*pos)+=(*pp++)*(*pp1--);
pascal@12756 5589 }
pascal@12756 5590 pos++;
pascal@12756 5591 }
pascal@12756 5592 }
pascal@12756 5593
pascal@12756 5594 /*----------------------------------------------------------------*
pascal@12756 5595 * Search the augmented part of the codebook to find the best
pascal@12756 5596 * measure.
pascal@12756 5597 *----------------------------------------------------------------*/
pascal@12756 5598
pascal@12756 5599
pascal@12756 5600
pascal@12756 5601
pascal@12756 5602 Andersen, et al. Experimental [Page 100]
pascal@12756 5603
pascal@12756 5604 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5605
pascal@12756 5606
pascal@12756 5607 void searchAugmentedCB(
pascal@12756 5608 int low, /* (i) Start index for the search */
pascal@12756 5609 int high, /* (i) End index for the search */
pascal@12756 5610 int stage, /* (i) Current stage */
pascal@12756 5611 int startIndex, /* (i) Codebook index for the first
pascal@12756 5612 aug vector */
pascal@12756 5613 float *target, /* (i) Target vector for encoding */
pascal@12756 5614 float *buffer, /* (i) Pointer to the end of the buffer for
pascal@12756 5615 augmented codebook construction */
pascal@12756 5616 float *max_measure, /* (i/o) Currently maximum measure */
pascal@12756 5617 int *best_index,/* (o) Currently the best index */
pascal@12756 5618 float *gain, /* (o) Currently the best gain */
pascal@12756 5619 float *energy, /* (o) Energy of augmented codebook
pascal@12756 5620 vectors */
pascal@12756 5621 float *invenergy/* (o) Inv energy of augmented codebook
pascal@12756 5622 vectors */
pascal@12756 5623 ) {
pascal@12756 5624 int icount, ilow, j, tmpIndex;
pascal@12756 5625 float *pp, *ppo, *ppi, *ppe, crossDot, alfa;
pascal@12756 5626 float weighted, measure, nrjRecursive;
pascal@12756 5627 float ftmp;
pascal@12756 5628
pascal@12756 5629 /* Compute the energy for the first (low-5)
pascal@12756 5630 noninterpolated samples */
pascal@12756 5631 nrjRecursive = (float) 0.0;
pascal@12756 5632 pp = buffer - low + 1;
pascal@12756 5633 for (j=0; j<(low-5); j++) {
pascal@12756 5634 nrjRecursive += ( (*pp)*(*pp) );
pascal@12756 5635 pp++;
pascal@12756 5636 }
pascal@12756 5637 ppe = buffer - low;
pascal@12756 5638
pascal@12756 5639
pascal@12756 5640 for (icount=low; icount<=high; icount++) {
pascal@12756 5641
pascal@12756 5642 /* Index of the codebook vector used for retrieving
pascal@12756 5643 energy values */
pascal@12756 5644 tmpIndex = startIndex+icount-20;
pascal@12756 5645
pascal@12756 5646 ilow = icount-4;
pascal@12756 5647
pascal@12756 5648 /* Update the energy recursively to save complexity */
pascal@12756 5649 nrjRecursive = nrjRecursive + (*ppe)*(*ppe);
pascal@12756 5650 ppe--;
pascal@12756 5651 energy[tmpIndex] = nrjRecursive;
pascal@12756 5652
pascal@12756 5653 /* Compute cross dot product for the first (low-5)
pascal@12756 5654 samples */
pascal@12756 5655
pascal@12756 5656
pascal@12756 5657
pascal@12756 5658 Andersen, et al. Experimental [Page 101]
pascal@12756 5659
pascal@12756 5660 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5661
pascal@12756 5662
pascal@12756 5663 crossDot = (float) 0.0;
pascal@12756 5664 pp = buffer-icount;
pascal@12756 5665 for (j=0; j<ilow; j++) {
pascal@12756 5666 crossDot += target[j]*(*pp++);
pascal@12756 5667 }
pascal@12756 5668
pascal@12756 5669 /* interpolation */
pascal@12756 5670 alfa = (float) 0.2;
pascal@12756 5671 ppo = buffer-4;
pascal@12756 5672 ppi = buffer-icount-4;
pascal@12756 5673 for (j=ilow; j<icount; j++) {
pascal@12756 5674 weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);
pascal@12756 5675 ppo++;
pascal@12756 5676 ppi++;
pascal@12756 5677 energy[tmpIndex] += weighted*weighted;
pascal@12756 5678 crossDot += target[j]*weighted;
pascal@12756 5679 alfa += (float)0.2;
pascal@12756 5680 }
pascal@12756 5681
pascal@12756 5682 /* Compute energy and cross dot product for the
pascal@12756 5683 remaining samples */
pascal@12756 5684 pp = buffer - icount;
pascal@12756 5685 for (j=icount; j<SUBL; j++) {
pascal@12756 5686 energy[tmpIndex] += (*pp)*(*pp);
pascal@12756 5687 crossDot += target[j]*(*pp++);
pascal@12756 5688 }
pascal@12756 5689
pascal@12756 5690 if (energy[tmpIndex]>0.0) {
pascal@12756 5691 invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS);
pascal@12756 5692 } else {
pascal@12756 5693 invenergy[tmpIndex] = (float) 0.0;
pascal@12756 5694 }
pascal@12756 5695
pascal@12756 5696 if (stage==0) {
pascal@12756 5697 measure = (float)-10000000.0;
pascal@12756 5698
pascal@12756 5699 if (crossDot > 0.0) {
pascal@12756 5700 measure = crossDot*crossDot*invenergy[tmpIndex];
pascal@12756 5701 }
pascal@12756 5702 }
pascal@12756 5703 else {
pascal@12756 5704 measure = crossDot*crossDot*invenergy[tmpIndex];
pascal@12756 5705 }
pascal@12756 5706
pascal@12756 5707 /* check if measure is better */
pascal@12756 5708 ftmp = crossDot*invenergy[tmpIndex];
pascal@12756 5709
pascal@12756 5710 if ((measure>*max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
pascal@12756 5711
pascal@12756 5712
pascal@12756 5713
pascal@12756 5714 Andersen, et al. Experimental [Page 102]
pascal@12756 5715
pascal@12756 5716 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5717
pascal@12756 5718
pascal@12756 5719 *best_index = tmpIndex;
pascal@12756 5720 *max_measure = measure;
pascal@12756 5721 *gain = ftmp;
pascal@12756 5722 }
pascal@12756 5723 }
pascal@12756 5724 }
pascal@12756 5725
pascal@12756 5726
pascal@12756 5727 /*----------------------------------------------------------------*
pascal@12756 5728 * Recreate a specific codebook vector from the augmented part.
pascal@12756 5729 *
pascal@12756 5730 *----------------------------------------------------------------*/
pascal@12756 5731
pascal@12756 5732 void createAugmentedVec(
pascal@12756 5733 int index, /* (i) Index for the augmented vector
pascal@12756 5734 to be created */
pascal@12756 5735 float *buffer, /* (i) Pointer to the end of the buffer for
pascal@12756 5736 augmented codebook construction */
pascal@12756 5737 float *cbVec/* (o) The construced codebook vector */
pascal@12756 5738 ) {
pascal@12756 5739 int ilow, j;
pascal@12756 5740 float *pp, *ppo, *ppi, alfa, alfa1, weighted;
pascal@12756 5741
pascal@12756 5742 ilow = index-5;
pascal@12756 5743
pascal@12756 5744 /* copy the first noninterpolated part */
pascal@12756 5745
pascal@12756 5746 pp = buffer-index;
pascal@12756 5747 memcpy(cbVec,pp,sizeof(float)*index);
pascal@12756 5748
pascal@12756 5749 /* interpolation */
pascal@12756 5750
pascal@12756 5751 alfa1 = (float)0.2;
pascal@12756 5752 alfa = 0.0;
pascal@12756 5753 ppo = buffer-5;
pascal@12756 5754 ppi = buffer-index-5;
pascal@12756 5755 for (j=ilow; j<index; j++) {
pascal@12756 5756 weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);
pascal@12756 5757 ppo++;
pascal@12756 5758 ppi++;
pascal@12756 5759 cbVec[j] = weighted;
pascal@12756 5760 alfa += alfa1;
pascal@12756 5761 }
pascal@12756 5762
pascal@12756 5763 /* copy the second noninterpolated part */
pascal@12756 5764
pascal@12756 5765 pp = buffer - index;
pascal@12756 5766 memcpy(cbVec+index,pp,sizeof(float)*(SUBL-index));
pascal@12756 5767
pascal@12756 5768
pascal@12756 5769
pascal@12756 5770 Andersen, et al. Experimental [Page 103]
pascal@12756 5771
pascal@12756 5772 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5773
pascal@12756 5774
pascal@12756 5775 }
pascal@12756 5776
pascal@12756 5777 A.13. doCPLC.h
pascal@12756 5778
pascal@12756 5779 /******************************************************************
pascal@12756 5780
pascal@12756 5781 iLBC Speech Coder ANSI-C Source Code
pascal@12756 5782
pascal@12756 5783 doCPLC.h
pascal@12756 5784
pascal@12756 5785 Copyright (C) The Internet Society (2004).
pascal@12756 5786 All Rights Reserved.
pascal@12756 5787
pascal@12756 5788 ******************************************************************/
pascal@12756 5789
pascal@12756 5790 #ifndef __iLBC_DOLPC_H
pascal@12756 5791 #define __iLBC_DOLPC_H
pascal@12756 5792
pascal@12756 5793 void doThePLC(
pascal@12756 5794 float *PLCresidual, /* (o) concealed residual */
pascal@12756 5795 float *PLClpc, /* (o) concealed LP parameters */
pascal@12756 5796 int PLI, /* (i) packet loss indicator
pascal@12756 5797 0 - no PL, 1 = PL */
pascal@12756 5798 float *decresidual, /* (i) decoded residual */
pascal@12756 5799 float *lpc, /* (i) decoded LPC (only used for no PL) */
pascal@12756 5800 int inlag, /* (i) pitch lag */
pascal@12756 5801 iLBC_Dec_Inst_t *iLBCdec_inst
pascal@12756 5802 /* (i/o) decoder instance */
pascal@12756 5803 );
pascal@12756 5804
pascal@12756 5805 #endif
pascal@12756 5806
pascal@12756 5807 A.14. doCPLC.c
pascal@12756 5808
pascal@12756 5809 /******************************************************************
pascal@12756 5810
pascal@12756 5811 iLBC Speech Coder ANSI-C Source Code
pascal@12756 5812
pascal@12756 5813 doCPLC.c
pascal@12756 5814
pascal@12756 5815 Copyright (C) The Internet Society (2004).
pascal@12756 5816 All Rights Reserved.
pascal@12756 5817
pascal@12756 5818 ******************************************************************/
pascal@12756 5819
pascal@12756 5820 #include <math.h>
pascal@12756 5821 #include <string.h>
pascal@12756 5822 #include <stdio.h>
pascal@12756 5823
pascal@12756 5824
pascal@12756 5825
pascal@12756 5826 Andersen, et al. Experimental [Page 104]
pascal@12756 5827
pascal@12756 5828 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5829
pascal@12756 5830
pascal@12756 5831 #include "iLBC_define.h"
pascal@12756 5832
pascal@12756 5833 /*----------------------------------------------------------------*
pascal@12756 5834 * Compute cross correlation and pitch gain for pitch prediction
pascal@12756 5835 * of last subframe at given lag.
pascal@12756 5836 *---------------------------------------------------------------*/
pascal@12756 5837
pascal@12756 5838 void compCorr(
pascal@12756 5839 float *cc, /* (o) cross correlation coefficient */
pascal@12756 5840 float *gc, /* (o) gain */
pascal@12756 5841 float *pm,
pascal@12756 5842 float *buffer, /* (i) signal buffer */
pascal@12756 5843 int lag, /* (i) pitch lag */
pascal@12756 5844 int bLen, /* (i) length of buffer */
pascal@12756 5845 int sRange /* (i) correlation search length */
pascal@12756 5846 ){
pascal@12756 5847 int i;
pascal@12756 5848 float ftmp1, ftmp2, ftmp3;
pascal@12756 5849
pascal@12756 5850 /* Guard against getting outside buffer */
pascal@12756 5851 if ((bLen-sRange-lag)<0) {
pascal@12756 5852 sRange=bLen-lag;
pascal@12756 5853 }
pascal@12756 5854
pascal@12756 5855 ftmp1 = 0.0;
pascal@12756 5856 ftmp2 = 0.0;
pascal@12756 5857 ftmp3 = 0.0;
pascal@12756 5858 for (i=0; i<sRange; i++) {
pascal@12756 5859 ftmp1 += buffer[bLen-sRange+i] *
pascal@12756 5860 buffer[bLen-sRange+i-lag];
pascal@12756 5861 ftmp2 += buffer[bLen-sRange+i-lag] *
pascal@12756 5862 buffer[bLen-sRange+i-lag];
pascal@12756 5863 ftmp3 += buffer[bLen-sRange+i] *
pascal@12756 5864 buffer[bLen-sRange+i];
pascal@12756 5865 }
pascal@12756 5866
pascal@12756 5867 if (ftmp2 > 0.0) {
pascal@12756 5868 *cc = ftmp1*ftmp1/ftmp2;
pascal@12756 5869 *gc = (float)fabs(ftmp1/ftmp2);
pascal@12756 5870 *pm=(float)fabs(ftmp1)/
pascal@12756 5871 ((float)sqrt(ftmp2)*(float)sqrt(ftmp3));
pascal@12756 5872 }
pascal@12756 5873 else {
pascal@12756 5874 *cc = 0.0;
pascal@12756 5875 *gc = 0.0;
pascal@12756 5876 *pm=0.0;
pascal@12756 5877 }
pascal@12756 5878 }
pascal@12756 5879
pascal@12756 5880
pascal@12756 5881
pascal@12756 5882 Andersen, et al. Experimental [Page 105]
pascal@12756 5883
pascal@12756 5884 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5885
pascal@12756 5886
pascal@12756 5887 /*----------------------------------------------------------------*
pascal@12756 5888 * Packet loss concealment routine. Conceals a residual signal
pascal@12756 5889 * and LP parameters. If no packet loss, update state.
pascal@12756 5890 *---------------------------------------------------------------*/
pascal@12756 5891
pascal@12756 5892 void doThePLC(
pascal@12756 5893 float *PLCresidual, /* (o) concealed residual */
pascal@12756 5894 float *PLClpc, /* (o) concealed LP parameters */
pascal@12756 5895 int PLI, /* (i) packet loss indicator
pascal@12756 5896 0 - no PL, 1 = PL */
pascal@12756 5897 float *decresidual, /* (i) decoded residual */
pascal@12756 5898 float *lpc, /* (i) decoded LPC (only used for no PL) */
pascal@12756 5899 int inlag, /* (i) pitch lag */
pascal@12756 5900 iLBC_Dec_Inst_t *iLBCdec_inst
pascal@12756 5901 /* (i/o) decoder instance */
pascal@12756 5902 ){
pascal@12756 5903 int lag=20, randlag;
pascal@12756 5904 float gain, maxcc;
pascal@12756 5905 float use_gain;
pascal@12756 5906 float gain_comp, maxcc_comp, per, max_per;
pascal@12756 5907 int i, pick, use_lag;
pascal@12756 5908 float ftmp, randvec[BLOCKL_MAX], pitchfact, energy;
pascal@12756 5909
pascal@12756 5910 /* Packet Loss */
pascal@12756 5911
pascal@12756 5912 if (PLI == 1) {
pascal@12756 5913
pascal@12756 5914 iLBCdec_inst->consPLICount += 1;
pascal@12756 5915
pascal@12756 5916 /* if previous frame not lost,
pascal@12756 5917 determine pitch pred. gain */
pascal@12756 5918
pascal@12756 5919 if (iLBCdec_inst->prevPLI != 1) {
pascal@12756 5920
pascal@12756 5921 /* Search around the previous lag to find the
pascal@12756 5922 best pitch period */
pascal@12756 5923
pascal@12756 5924 lag=inlag-3;
pascal@12756 5925 compCorr(&maxcc, &gain, &max_per,
pascal@12756 5926 iLBCdec_inst->prevResidual,
pascal@12756 5927 lag, iLBCdec_inst->blockl, 60);
pascal@12756 5928 for (i=inlag-2;i<=inlag+3;i++) {
pascal@12756 5929 compCorr(&maxcc_comp, &gain_comp, &per,
pascal@12756 5930 iLBCdec_inst->prevResidual,
pascal@12756 5931 i, iLBCdec_inst->blockl, 60);
pascal@12756 5932
pascal@12756 5933 if (maxcc_comp>maxcc) {
pascal@12756 5934 maxcc=maxcc_comp;
pascal@12756 5935
pascal@12756 5936
pascal@12756 5937
pascal@12756 5938 Andersen, et al. Experimental [Page 106]
pascal@12756 5939
pascal@12756 5940 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5941
pascal@12756 5942
pascal@12756 5943 gain=gain_comp;
pascal@12756 5944 lag=i;
pascal@12756 5945 max_per=per;
pascal@12756 5946 }
pascal@12756 5947 }
pascal@12756 5948
pascal@12756 5949 }
pascal@12756 5950
pascal@12756 5951 /* previous frame lost, use recorded lag and periodicity */
pascal@12756 5952
pascal@12756 5953 else {
pascal@12756 5954 lag=iLBCdec_inst->prevLag;
pascal@12756 5955 max_per=iLBCdec_inst->per;
pascal@12756 5956 }
pascal@12756 5957
pascal@12756 5958 /* downscaling */
pascal@12756 5959
pascal@12756 5960 use_gain=1.0;
pascal@12756 5961 if (iLBCdec_inst->consPLICount*iLBCdec_inst->blockl>320)
pascal@12756 5962 use_gain=(float)0.9;
pascal@12756 5963 else if (iLBCdec_inst->consPLICount*
pascal@12756 5964 iLBCdec_inst->blockl>2*320)
pascal@12756 5965 use_gain=(float)0.7;
pascal@12756 5966 else if (iLBCdec_inst->consPLICount*
pascal@12756 5967 iLBCdec_inst->blockl>3*320)
pascal@12756 5968 use_gain=(float)0.5;
pascal@12756 5969 else if (iLBCdec_inst->consPLICount*
pascal@12756 5970 iLBCdec_inst->blockl>4*320)
pascal@12756 5971 use_gain=(float)0.0;
pascal@12756 5972
pascal@12756 5973 /* mix noise and pitch repeatition */
pascal@12756 5974 ftmp=(float)sqrt(max_per);
pascal@12756 5975 if (ftmp>(float)0.7)
pascal@12756 5976 pitchfact=(float)1.0;
pascal@12756 5977 else if (ftmp>(float)0.4)
pascal@12756 5978 pitchfact=(ftmp-(float)0.4)/((float)0.7-(float)0.4);
pascal@12756 5979 else
pascal@12756 5980 pitchfact=0.0;
pascal@12756 5981
pascal@12756 5982
pascal@12756 5983 /* avoid repetition of same pitch cycle */
pascal@12756 5984 use_lag=lag;
pascal@12756 5985 if (lag<80) {
pascal@12756 5986 use_lag=2*lag;
pascal@12756 5987 }
pascal@12756 5988
pascal@12756 5989 /* compute concealed residual */
pascal@12756 5990
pascal@12756 5991
pascal@12756 5992
pascal@12756 5993
pascal@12756 5994 Andersen, et al. Experimental [Page 107]
pascal@12756 5995
pascal@12756 5996 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 5997
pascal@12756 5998
pascal@12756 5999 energy = 0.0;
pascal@12756 6000 for (i=0; i<iLBCdec_inst->blockl; i++) {
pascal@12756 6001
pascal@12756 6002 /* noise component */
pascal@12756 6003
pascal@12756 6004 iLBCdec_inst->seed=(iLBCdec_inst->seed*69069L+1) &
pascal@12756 6005 (0x80000000L-1);
pascal@12756 6006 randlag = 50 + ((signed long) iLBCdec_inst->seed)%70;
pascal@12756 6007 pick = i - randlag;
pascal@12756 6008
pascal@12756 6009 if (pick < 0) {
pascal@12756 6010 randvec[i] =
pascal@12756 6011 iLBCdec_inst->prevResidual[
pascal@12756 6012 iLBCdec_inst->blockl+pick];
pascal@12756 6013 } else {
pascal@12756 6014 randvec[i] = randvec[pick];
pascal@12756 6015 }
pascal@12756 6016
pascal@12756 6017 /* pitch repeatition component */
pascal@12756 6018 pick = i - use_lag;
pascal@12756 6019
pascal@12756 6020 if (pick < 0) {
pascal@12756 6021 PLCresidual[i] =
pascal@12756 6022 iLBCdec_inst->prevResidual[
pascal@12756 6023 iLBCdec_inst->blockl+pick];
pascal@12756 6024 } else {
pascal@12756 6025 PLCresidual[i] = PLCresidual[pick];
pascal@12756 6026 }
pascal@12756 6027
pascal@12756 6028 /* mix random and periodicity component */
pascal@12756 6029
pascal@12756 6030 if (i<80)
pascal@12756 6031 PLCresidual[i] = use_gain*(pitchfact *
pascal@12756 6032 PLCresidual[i] +
pascal@12756 6033 ((float)1.0 - pitchfact) * randvec[i]);
pascal@12756 6034 else if (i<160)
pascal@12756 6035 PLCresidual[i] = (float)0.95*use_gain*(pitchfact *
pascal@12756 6036 PLCresidual[i] +
pascal@12756 6037 ((float)1.0 - pitchfact) * randvec[i]);
pascal@12756 6038 else
pascal@12756 6039 PLCresidual[i] = (float)0.9*use_gain*(pitchfact *
pascal@12756 6040 PLCresidual[i] +
pascal@12756 6041 ((float)1.0 - pitchfact) * randvec[i]);
pascal@12756 6042
pascal@12756 6043 energy += PLCresidual[i] * PLCresidual[i];
pascal@12756 6044 }
pascal@12756 6045
pascal@12756 6046 /* less than 30 dB, use only noise */
pascal@12756 6047
pascal@12756 6048
pascal@12756 6049
pascal@12756 6050 Andersen, et al. Experimental [Page 108]
pascal@12756 6051
pascal@12756 6052 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6053
pascal@12756 6054
pascal@12756 6055
pascal@12756 6056 if (sqrt(energy/(float)iLBCdec_inst->blockl) < 30.0) {
pascal@12756 6057 gain=0.0;
pascal@12756 6058 for (i=0; i<iLBCdec_inst->blockl; i++) {
pascal@12756 6059 PLCresidual[i] = randvec[i];
pascal@12756 6060 }
pascal@12756 6061 }
pascal@12756 6062
pascal@12756 6063 /* use old LPC */
pascal@12756 6064
pascal@12756 6065 memcpy(PLClpc,iLBCdec_inst->prevLpc,
pascal@12756 6066 (LPC_FILTERORDER+1)*sizeof(float));
pascal@12756 6067
pascal@12756 6068 }
pascal@12756 6069
pascal@12756 6070 /* no packet loss, copy input */
pascal@12756 6071
pascal@12756 6072 else {
pascal@12756 6073 memcpy(PLCresidual, decresidual,
pascal@12756 6074 iLBCdec_inst->blockl*sizeof(float));
pascal@12756 6075 memcpy(PLClpc, lpc, (LPC_FILTERORDER+1)*sizeof(float));
pascal@12756 6076 iLBCdec_inst->consPLICount = 0;
pascal@12756 6077 }
pascal@12756 6078
pascal@12756 6079 /* update state */
pascal@12756 6080
pascal@12756 6081 if (PLI) {
pascal@12756 6082 iLBCdec_inst->prevLag = lag;
pascal@12756 6083 iLBCdec_inst->per=max_per;
pascal@12756 6084 }
pascal@12756 6085
pascal@12756 6086 iLBCdec_inst->prevPLI = PLI;
pascal@12756 6087 memcpy(iLBCdec_inst->prevLpc, PLClpc,
pascal@12756 6088 (LPC_FILTERORDER+1)*sizeof(float));
pascal@12756 6089 memcpy(iLBCdec_inst->prevResidual, PLCresidual,
pascal@12756 6090 iLBCdec_inst->blockl*sizeof(float));
pascal@12756 6091 }
pascal@12756 6092
pascal@12756 6093 A.15. enhancer.h
pascal@12756 6094
pascal@12756 6095 /******************************************************************
pascal@12756 6096
pascal@12756 6097 iLBC Speech Coder ANSI-C Source Code
pascal@12756 6098
pascal@12756 6099 enhancer.h
pascal@12756 6100
pascal@12756 6101 Copyright (C) The Internet Society (2004).
pascal@12756 6102 All Rights Reserved.
pascal@12756 6103
pascal@12756 6104
pascal@12756 6105
pascal@12756 6106 Andersen, et al. Experimental [Page 109]
pascal@12756 6107
pascal@12756 6108 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6109
pascal@12756 6110
pascal@12756 6111 ******************************************************************/
pascal@12756 6112
pascal@12756 6113 #ifndef __ENHANCER_H
pascal@12756 6114 #define __ENHANCER_H
pascal@12756 6115
pascal@12756 6116 #include "iLBC_define.h"
pascal@12756 6117
pascal@12756 6118 float xCorrCoef(
pascal@12756 6119 float *target, /* (i) first array */
pascal@12756 6120 float *regressor, /* (i) second array */
pascal@12756 6121 int subl /* (i) dimension arrays */
pascal@12756 6122 );
pascal@12756 6123
pascal@12756 6124 int enhancerInterface(
pascal@12756 6125 float *out, /* (o) the enhanced recidual signal */
pascal@12756 6126 float *in, /* (i) the recidual signal to enhance */
pascal@12756 6127 iLBC_Dec_Inst_t *iLBCdec_inst
pascal@12756 6128 /* (i/o) the decoder state structure */
pascal@12756 6129 );
pascal@12756 6130
pascal@12756 6131 #endif
pascal@12756 6132
pascal@12756 6133 A.16. enhancer.c
pascal@12756 6134
pascal@12756 6135 /******************************************************************
pascal@12756 6136
pascal@12756 6137 iLBC Speech Coder ANSI-C Source Code
pascal@12756 6138
pascal@12756 6139 enhancer.c
pascal@12756 6140
pascal@12756 6141 Copyright (C) The Internet Society (2004).
pascal@12756 6142 All Rights Reserved.
pascal@12756 6143
pascal@12756 6144 ******************************************************************/
pascal@12756 6145
pascal@12756 6146 #include <math.h>
pascal@12756 6147 #include <string.h>
pascal@12756 6148 #include "iLBC_define.h"
pascal@12756 6149 #include "constants.h"
pascal@12756 6150 #include "filter.h"
pascal@12756 6151
pascal@12756 6152 /*----------------------------------------------------------------*
pascal@12756 6153 * Find index in array such that the array element with said
pascal@12756 6154 * index is the element of said array closest to "value"
pascal@12756 6155 * according to the squared-error criterion
pascal@12756 6156 *---------------------------------------------------------------*/
pascal@12756 6157
pascal@12756 6158 void NearestNeighbor(
pascal@12756 6159
pascal@12756 6160
pascal@12756 6161
pascal@12756 6162 Andersen, et al. Experimental [Page 110]
pascal@12756 6163
pascal@12756 6164 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6165
pascal@12756 6166
pascal@12756 6167 int *index, /* (o) index of array element closest
pascal@12756 6168 to value */
pascal@12756 6169 float *array, /* (i) data array */
pascal@12756 6170 float value,/* (i) value */
pascal@12756 6171 int arlength/* (i) dimension of data array */
pascal@12756 6172 ){
pascal@12756 6173 int i;
pascal@12756 6174 float bestcrit,crit;
pascal@12756 6175
pascal@12756 6176 crit=array[0]-value;
pascal@12756 6177 bestcrit=crit*crit;
pascal@12756 6178 *index=0;
pascal@12756 6179 for (i=1; i<arlength; i++) {
pascal@12756 6180 crit=array[i]-value;
pascal@12756 6181 crit=crit*crit;
pascal@12756 6182
pascal@12756 6183 if (crit<bestcrit) {
pascal@12756 6184 bestcrit=crit;
pascal@12756 6185 *index=i;
pascal@12756 6186 }
pascal@12756 6187 }
pascal@12756 6188 }
pascal@12756 6189
pascal@12756 6190 /*----------------------------------------------------------------*
pascal@12756 6191 * compute cross correlation between sequences
pascal@12756 6192 *---------------------------------------------------------------*/
pascal@12756 6193
pascal@12756 6194 void mycorr1(
pascal@12756 6195 float* corr, /* (o) correlation of seq1 and seq2 */
pascal@12756 6196 float* seq1, /* (i) first sequence */
pascal@12756 6197 int dim1, /* (i) dimension first seq1 */
pascal@12756 6198 const float *seq2, /* (i) second sequence */
pascal@12756 6199 int dim2 /* (i) dimension seq2 */
pascal@12756 6200 ){
pascal@12756 6201 int i,j;
pascal@12756 6202
pascal@12756 6203 for (i=0; i<=dim1-dim2; i++) {
pascal@12756 6204 corr[i]=0.0;
pascal@12756 6205 for (j=0; j<dim2; j++) {
pascal@12756 6206 corr[i] += seq1[i+j] * seq2[j];
pascal@12756 6207 }
pascal@12756 6208 }
pascal@12756 6209 }
pascal@12756 6210
pascal@12756 6211 /*----------------------------------------------------------------*
pascal@12756 6212 * upsample finite array assuming zeros outside bounds
pascal@12756 6213 *---------------------------------------------------------------*/
pascal@12756 6214
pascal@12756 6215
pascal@12756 6216
pascal@12756 6217
pascal@12756 6218 Andersen, et al. Experimental [Page 111]
pascal@12756 6219
pascal@12756 6220 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6221
pascal@12756 6222
pascal@12756 6223 void enh_upsample(
pascal@12756 6224 float* useq1, /* (o) upsampled output sequence */
pascal@12756 6225 float* seq1,/* (i) unupsampled sequence */
pascal@12756 6226 int dim1, /* (i) dimension seq1 */
pascal@12756 6227 int hfl /* (i) polyphase filter length=2*hfl+1 */
pascal@12756 6228 ){
pascal@12756 6229 float *pu,*ps;
pascal@12756 6230 int i,j,k,q,filterlength,hfl2;
pascal@12756 6231 const float *polyp[ENH_UPS0]; /* pointers to
pascal@12756 6232 polyphase columns */
pascal@12756 6233 const float *pp;
pascal@12756 6234
pascal@12756 6235 /* define pointers for filter */
pascal@12756 6236
pascal@12756 6237 filterlength=2*hfl+1;
pascal@12756 6238
pascal@12756 6239 if ( filterlength > dim1 ) {
pascal@12756 6240 hfl2=(int) (dim1/2);
pascal@12756 6241 for (j=0; j<ENH_UPS0; j++) {
pascal@12756 6242 polyp[j]=polyphaserTbl+j*filterlength+hfl-hfl2;
pascal@12756 6243 }
pascal@12756 6244 hfl=hfl2;
pascal@12756 6245 filterlength=2*hfl+1;
pascal@12756 6246 }
pascal@12756 6247 else {
pascal@12756 6248 for (j=0; j<ENH_UPS0; j++) {
pascal@12756 6249 polyp[j]=polyphaserTbl+j*filterlength;
pascal@12756 6250 }
pascal@12756 6251 }
pascal@12756 6252
pascal@12756 6253 /* filtering: filter overhangs left side of sequence */
pascal@12756 6254
pascal@12756 6255 pu=useq1;
pascal@12756 6256 for (i=hfl; i<filterlength; i++) {
pascal@12756 6257 for (j=0; j<ENH_UPS0; j++) {
pascal@12756 6258 *pu=0.0;
pascal@12756 6259 pp = polyp[j];
pascal@12756 6260 ps = seq1+i;
pascal@12756 6261 for (k=0; k<=i; k++) {
pascal@12756 6262 *pu += *ps-- * *pp++;
pascal@12756 6263 }
pascal@12756 6264 pu++;
pascal@12756 6265 }
pascal@12756 6266 }
pascal@12756 6267
pascal@12756 6268 /* filtering: simple convolution=inner products */
pascal@12756 6269
pascal@12756 6270 for (i=filterlength; i<dim1; i++) {
pascal@12756 6271
pascal@12756 6272
pascal@12756 6273
pascal@12756 6274 Andersen, et al. Experimental [Page 112]
pascal@12756 6275
pascal@12756 6276 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6277
pascal@12756 6278
pascal@12756 6279 for (j=0;j<ENH_UPS0; j++){
pascal@12756 6280 *pu=0.0;
pascal@12756 6281 pp = polyp[j];
pascal@12756 6282 ps = seq1+i;
pascal@12756 6283 for (k=0; k<filterlength; k++) {
pascal@12756 6284 *pu += *ps-- * *pp++;
pascal@12756 6285 }
pascal@12756 6286 pu++;
pascal@12756 6287 }
pascal@12756 6288 }
pascal@12756 6289
pascal@12756 6290 /* filtering: filter overhangs right side of sequence */
pascal@12756 6291
pascal@12756 6292 for (q=1; q<=hfl; q++) {
pascal@12756 6293 for (j=0; j<ENH_UPS0; j++) {
pascal@12756 6294 *pu=0.0;
pascal@12756 6295 pp = polyp[j]+q;
pascal@12756 6296 ps = seq1+dim1-1;
pascal@12756 6297 for (k=0; k<filterlength-q; k++) {
pascal@12756 6298 *pu += *ps-- * *pp++;
pascal@12756 6299 }
pascal@12756 6300 pu++;
pascal@12756 6301 }
pascal@12756 6302 }
pascal@12756 6303 }
pascal@12756 6304
pascal@12756 6305
pascal@12756 6306 /*----------------------------------------------------------------*
pascal@12756 6307 * find segment starting near idata+estSegPos that has highest
pascal@12756 6308 * correlation with idata+centerStartPos through
pascal@12756 6309 * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a
pascal@12756 6310 * resolution of ENH_UPSO times the original of the original
pascal@12756 6311 * sampling rate
pascal@12756 6312 *---------------------------------------------------------------*/
pascal@12756 6313
pascal@12756 6314 void refiner(
pascal@12756 6315 float *seg, /* (o) segment array */
pascal@12756 6316 float *updStartPos, /* (o) updated start point */
pascal@12756 6317 float* idata, /* (i) original data buffer */
pascal@12756 6318 int idatal, /* (i) dimension of idata */
pascal@12756 6319 int centerStartPos, /* (i) beginning center segment */
pascal@12756 6320 float estSegPos,/* (i) estimated beginning other segment */
pascal@12756 6321 float period /* (i) estimated pitch period */
pascal@12756 6322 ){
pascal@12756 6323 int estSegPosRounded,searchSegStartPos,searchSegEndPos,corrdim;
pascal@12756 6324 int tloc,tloc2,i,st,en,fraction;
pascal@12756 6325 float vect[ENH_VECTL],corrVec[ENH_CORRDIM],maxv;
pascal@12756 6326 float corrVecUps[ENH_CORRDIM*ENH_UPS0];
pascal@12756 6327
pascal@12756 6328
pascal@12756 6329
pascal@12756 6330 Andersen, et al. Experimental [Page 113]
pascal@12756 6331
pascal@12756 6332 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6333
pascal@12756 6334
pascal@12756 6335 /* defining array bounds */
pascal@12756 6336
pascal@12756 6337 estSegPosRounded=(int)(estSegPos - 0.5);
pascal@12756 6338
pascal@12756 6339 searchSegStartPos=estSegPosRounded-ENH_SLOP;
pascal@12756 6340
pascal@12756 6341 if (searchSegStartPos<0) {
pascal@12756 6342 searchSegStartPos=0;
pascal@12756 6343 }
pascal@12756 6344 searchSegEndPos=estSegPosRounded+ENH_SLOP;
pascal@12756 6345
pascal@12756 6346 if (searchSegEndPos+ENH_BLOCKL >= idatal) {
pascal@12756 6347 searchSegEndPos=idatal-ENH_BLOCKL-1;
pascal@12756 6348 }
pascal@12756 6349 corrdim=searchSegEndPos-searchSegStartPos+1;
pascal@12756 6350
pascal@12756 6351 /* compute upsampled correlation (corr33) and find
pascal@12756 6352 location of max */
pascal@12756 6353
pascal@12756 6354 mycorr1(corrVec,idata+searchSegStartPos,
pascal@12756 6355 corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL);
pascal@12756 6356 enh_upsample(corrVecUps,corrVec,corrdim,ENH_FL0);
pascal@12756 6357 tloc=0; maxv=corrVecUps[0];
pascal@12756 6358 for (i=1; i<ENH_UPS0*corrdim; i++) {
pascal@12756 6359
pascal@12756 6360 if (corrVecUps[i]>maxv) {
pascal@12756 6361 tloc=i;
pascal@12756 6362 maxv=corrVecUps[i];
pascal@12756 6363 }
pascal@12756 6364 }
pascal@12756 6365
pascal@12756 6366 /* make vector can be upsampled without ever running outside
pascal@12756 6367 bounds */
pascal@12756 6368
pascal@12756 6369 *updStartPos= (float)searchSegStartPos +
pascal@12756 6370 (float)tloc/(float)ENH_UPS0+(float)1.0;
pascal@12756 6371 tloc2=(int)(tloc/ENH_UPS0);
pascal@12756 6372
pascal@12756 6373 if (tloc>tloc2*ENH_UPS0) {
pascal@12756 6374 tloc2++;
pascal@12756 6375 }
pascal@12756 6376 st=searchSegStartPos+tloc2-ENH_FL0;
pascal@12756 6377
pascal@12756 6378 if (st<0) {
pascal@12756 6379 memset(vect,0,-st*sizeof(float));
pascal@12756 6380 memcpy(&vect[-st],idata, (ENH_VECTL+st)*sizeof(float));
pascal@12756 6381 }
pascal@12756 6382 else {
pascal@12756 6383
pascal@12756 6384
pascal@12756 6385
pascal@12756 6386 Andersen, et al. Experimental [Page 114]
pascal@12756 6387
pascal@12756 6388 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6389
pascal@12756 6390
pascal@12756 6391 en=st+ENH_VECTL;
pascal@12756 6392
pascal@12756 6393 if (en>idatal) {
pascal@12756 6394 memcpy(vect, &idata[st],
pascal@12756 6395 (ENH_VECTL-(en-idatal))*sizeof(float));
pascal@12756 6396 memset(&vect[ENH_VECTL-(en-idatal)], 0,
pascal@12756 6397 (en-idatal)*sizeof(float));
pascal@12756 6398 }
pascal@12756 6399 else {
pascal@12756 6400 memcpy(vect, &idata[st], ENH_VECTL*sizeof(float));
pascal@12756 6401 }
pascal@12756 6402 }
pascal@12756 6403 fraction=tloc2*ENH_UPS0-tloc;
pascal@12756 6404
pascal@12756 6405 /* compute the segment (this is actually a convolution) */
pascal@12756 6406
pascal@12756 6407 mycorr1(seg,vect,ENH_VECTL,polyphaserTbl+(2*ENH_FL0+1)*fraction,
pascal@12756 6408 2*ENH_FL0+1);
pascal@12756 6409 }
pascal@12756 6410
pascal@12756 6411 /*----------------------------------------------------------------*
pascal@12756 6412 * find the smoothed output data
pascal@12756 6413 *---------------------------------------------------------------*/
pascal@12756 6414
pascal@12756 6415 void smath(
pascal@12756 6416 float *odata, /* (o) smoothed output */
pascal@12756 6417 float *sseq,/* (i) said second sequence of waveforms */
pascal@12756 6418 int hl, /* (i) 2*hl+1 is sseq dimension */
pascal@12756 6419 float alpha0/* (i) max smoothing energy fraction */
pascal@12756 6420 ){
pascal@12756 6421 int i,k;
pascal@12756 6422 float w00,w10,w11,A,B,C,*psseq,err,errs;
pascal@12756 6423 float surround[BLOCKL_MAX]; /* shape contributed by other than
pascal@12756 6424 current */
pascal@12756 6425 float wt[2*ENH_HL+1]; /* waveform weighting to get
pascal@12756 6426 surround shape */
pascal@12756 6427 float denom;
pascal@12756 6428
pascal@12756 6429 /* create shape of contribution from all waveforms except the
pascal@12756 6430 current one */
pascal@12756 6431
pascal@12756 6432 for (i=1; i<=2*hl+1; i++) {
pascal@12756 6433 wt[i-1] = (float)0.5*(1 - (float)cos(2*PI*i/(2*hl+2)));
pascal@12756 6434 }
pascal@12756 6435 wt[hl]=0.0; /* for clarity, not used */
pascal@12756 6436 for (i=0; i<ENH_BLOCKL; i++) {
pascal@12756 6437 surround[i]=sseq[i]*wt[0];
pascal@12756 6438 }
pascal@12756 6439
pascal@12756 6440
pascal@12756 6441
pascal@12756 6442 Andersen, et al. Experimental [Page 115]
pascal@12756 6443
pascal@12756 6444 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6445
pascal@12756 6446
pascal@12756 6447 for (k=1; k<hl; k++) {
pascal@12756 6448 psseq=sseq+k*ENH_BLOCKL;
pascal@12756 6449 for(i=0;i<ENH_BLOCKL; i++) {
pascal@12756 6450 surround[i]+=psseq[i]*wt[k];
pascal@12756 6451 }
pascal@12756 6452 }
pascal@12756 6453 for (k=hl+1; k<=2*hl; k++) {
pascal@12756 6454 psseq=sseq+k*ENH_BLOCKL;
pascal@12756 6455 for(i=0;i<ENH_BLOCKL; i++) {
pascal@12756 6456 surround[i]+=psseq[i]*wt[k];
pascal@12756 6457 }
pascal@12756 6458 }
pascal@12756 6459
pascal@12756 6460 /* compute some inner products */
pascal@12756 6461
pascal@12756 6462 w00 = w10 = w11 = 0.0;
pascal@12756 6463 psseq=sseq+hl*ENH_BLOCKL; /* current block */
pascal@12756 6464 for (i=0; i<ENH_BLOCKL;i++) {
pascal@12756 6465 w00+=psseq[i]*psseq[i];
pascal@12756 6466 w11+=surround[i]*surround[i];
pascal@12756 6467 w10+=surround[i]*psseq[i];
pascal@12756 6468 }
pascal@12756 6469
pascal@12756 6470 if (fabs(w11) < 1.0) {
pascal@12756 6471 w11=1.0;
pascal@12756 6472 }
pascal@12756 6473 C = (float)sqrt( w00/w11);
pascal@12756 6474
pascal@12756 6475 /* first try enhancement without power-constraint */
pascal@12756 6476
pascal@12756 6477 errs=0.0;
pascal@12756 6478 psseq=sseq+hl*ENH_BLOCKL;
pascal@12756 6479 for (i=0; i<ENH_BLOCKL; i++) {
pascal@12756 6480 odata[i]=C*surround[i];
pascal@12756 6481 err=psseq[i]-odata[i];
pascal@12756 6482 errs+=err*err;
pascal@12756 6483 }
pascal@12756 6484
pascal@12756 6485 /* if constraint violated by first try, add constraint */
pascal@12756 6486
pascal@12756 6487 if (errs > alpha0 * w00) {
pascal@12756 6488 if ( w00 < 1) {
pascal@12756 6489 w00=1;
pascal@12756 6490 }
pascal@12756 6491 denom = (w11*w00-w10*w10)/(w00*w00);
pascal@12756 6492
pascal@12756 6493 if (denom > 0.0001) { /* eliminates numerical problems
pascal@12756 6494 for if smooth */
pascal@12756 6495
pascal@12756 6496
pascal@12756 6497
pascal@12756 6498 Andersen, et al. Experimental [Page 116]
pascal@12756 6499
pascal@12756 6500 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6501
pascal@12756 6502
pascal@12756 6503 A = (float)sqrt( (alpha0- alpha0*alpha0/4)/denom);
pascal@12756 6504 B = -alpha0/2 - A * w10/w00;
pascal@12756 6505 B = B+1;
pascal@12756 6506 }
pascal@12756 6507 else { /* essentially no difference between cycles;
pascal@12756 6508 smoothing not needed */
pascal@12756 6509 A= 0.0;
pascal@12756 6510 B= 1.0;
pascal@12756 6511 }
pascal@12756 6512
pascal@12756 6513 /* create smoothed sequence */
pascal@12756 6514
pascal@12756 6515 psseq=sseq+hl*ENH_BLOCKL;
pascal@12756 6516 for (i=0; i<ENH_BLOCKL; i++) {
pascal@12756 6517 odata[i]=A*surround[i]+B*psseq[i];
pascal@12756 6518 }
pascal@12756 6519 }
pascal@12756 6520 }
pascal@12756 6521
pascal@12756 6522 /*----------------------------------------------------------------*
pascal@12756 6523 * get the pitch-synchronous sample sequence
pascal@12756 6524 *---------------------------------------------------------------*/
pascal@12756 6525
pascal@12756 6526 void getsseq(
pascal@12756 6527 float *sseq, /* (o) the pitch-synchronous sequence */
pascal@12756 6528 float *idata, /* (i) original data */
pascal@12756 6529 int idatal, /* (i) dimension of data */
pascal@12756 6530 int centerStartPos, /* (i) where current block starts */
pascal@12756 6531 float *period, /* (i) rough-pitch-period array */
pascal@12756 6532 float *plocs, /* (i) where periods of period array
pascal@12756 6533 are taken */
pascal@12756 6534 int periodl, /* (i) dimension period array */
pascal@12756 6535 int hl /* (i) 2*hl+1 is the number of sequences */
pascal@12756 6536 ){
pascal@12756 6537 int i,centerEndPos,q;
pascal@12756 6538 float blockStartPos[2*ENH_HL+1];
pascal@12756 6539 int lagBlock[2*ENH_HL+1];
pascal@12756 6540 float plocs2[ENH_PLOCSL];
pascal@12756 6541 float *psseq;
pascal@12756 6542
pascal@12756 6543 centerEndPos=centerStartPos+ENH_BLOCKL-1;
pascal@12756 6544
pascal@12756 6545 /* present */
pascal@12756 6546
pascal@12756 6547 NearestNeighbor(lagBlock+hl,plocs,
pascal@12756 6548 (float)0.5*(centerStartPos+centerEndPos),periodl);
pascal@12756 6549
pascal@12756 6550 blockStartPos[hl]=(float)centerStartPos;
pascal@12756 6551
pascal@12756 6552
pascal@12756 6553
pascal@12756 6554 Andersen, et al. Experimental [Page 117]
pascal@12756 6555
pascal@12756 6556 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6557
pascal@12756 6558
pascal@12756 6559 psseq=sseq+ENH_BLOCKL*hl;
pascal@12756 6560 memcpy(psseq, idata+centerStartPos, ENH_BLOCKL*sizeof(float));
pascal@12756 6561
pascal@12756 6562 /* past */
pascal@12756 6563
pascal@12756 6564 for (q=hl-1; q>=0; q--) {
pascal@12756 6565 blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]];
pascal@12756 6566 NearestNeighbor(lagBlock+q,plocs,
pascal@12756 6567 blockStartPos[q]+
pascal@12756 6568 ENH_BLOCKL_HALF-period[lagBlock[q+1]], periodl);
pascal@12756 6569
pascal@12756 6570
pascal@12756 6571 if (blockStartPos[q]-ENH_OVERHANG>=0) {
pascal@12756 6572 refiner(sseq+q*ENH_BLOCKL, blockStartPos+q, idata,
pascal@12756 6573 idatal, centerStartPos, blockStartPos[q],
pascal@12756 6574 period[lagBlock[q+1]]);
pascal@12756 6575 } else {
pascal@12756 6576 psseq=sseq+q*ENH_BLOCKL;
pascal@12756 6577 memset(psseq, 0, ENH_BLOCKL*sizeof(float));
pascal@12756 6578 }
pascal@12756 6579 }
pascal@12756 6580
pascal@12756 6581 /* future */
pascal@12756 6582
pascal@12756 6583 for (i=0; i<periodl; i++) {
pascal@12756 6584 plocs2[i]=plocs[i]-period[i];
pascal@12756 6585 }
pascal@12756 6586 for (q=hl+1; q<=2*hl; q++) {
pascal@12756 6587 NearestNeighbor(lagBlock+q,plocs2,
pascal@12756 6588 blockStartPos[q-1]+ENH_BLOCKL_HALF,periodl);
pascal@12756 6589
pascal@12756 6590 blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]];
pascal@12756 6591 if (blockStartPos[q]+ENH_BLOCKL+ENH_OVERHANG<idatal) {
pascal@12756 6592 refiner(sseq+ENH_BLOCKL*q, blockStartPos+q, idata,
pascal@12756 6593 idatal, centerStartPos, blockStartPos[q],
pascal@12756 6594 period[lagBlock[q]]);
pascal@12756 6595 }
pascal@12756 6596 else {
pascal@12756 6597 psseq=sseq+q*ENH_BLOCKL;
pascal@12756 6598 memset(psseq, 0, ENH_BLOCKL*sizeof(float));
pascal@12756 6599 }
pascal@12756 6600 }
pascal@12756 6601 }
pascal@12756 6602
pascal@12756 6603 /*----------------------------------------------------------------*
pascal@12756 6604 * perform enhancement on idata+centerStartPos through
pascal@12756 6605 * idata+centerStartPos+ENH_BLOCKL-1
pascal@12756 6606 *---------------------------------------------------------------*/
pascal@12756 6607
pascal@12756 6608
pascal@12756 6609
pascal@12756 6610 Andersen, et al. Experimental [Page 118]
pascal@12756 6611
pascal@12756 6612 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6613
pascal@12756 6614
pascal@12756 6615 void enhancer(
pascal@12756 6616 float *odata, /* (o) smoothed block, dimension blockl */
pascal@12756 6617 float *idata, /* (i) data buffer used for enhancing */
pascal@12756 6618 int idatal, /* (i) dimension idata */
pascal@12756 6619 int centerStartPos, /* (i) first sample current block
pascal@12756 6620 within idata */
pascal@12756 6621 float alpha0, /* (i) max correction-energy-fraction
pascal@12756 6622 (in [0,1]) */
pascal@12756 6623 float *period, /* (i) pitch period array */
pascal@12756 6624 float *plocs, /* (i) locations where period array
pascal@12756 6625 values valid */
pascal@12756 6626 int periodl /* (i) dimension of period and plocs */
pascal@12756 6627 ){
pascal@12756 6628 float sseq[(2*ENH_HL+1)*ENH_BLOCKL];
pascal@12756 6629
pascal@12756 6630 /* get said second sequence of segments */
pascal@12756 6631
pascal@12756 6632 getsseq(sseq,idata,idatal,centerStartPos,period,
pascal@12756 6633 plocs,periodl,ENH_HL);
pascal@12756 6634
pascal@12756 6635 /* compute the smoothed output from said second sequence */
pascal@12756 6636
pascal@12756 6637 smath(odata,sseq,ENH_HL,alpha0);
pascal@12756 6638
pascal@12756 6639 }
pascal@12756 6640
pascal@12756 6641 /*----------------------------------------------------------------*
pascal@12756 6642 * cross correlation
pascal@12756 6643 *---------------------------------------------------------------*/
pascal@12756 6644
pascal@12756 6645 float xCorrCoef(
pascal@12756 6646 float *target, /* (i) first array */
pascal@12756 6647 float *regressor, /* (i) second array */
pascal@12756 6648 int subl /* (i) dimension arrays */
pascal@12756 6649 ){
pascal@12756 6650 int i;
pascal@12756 6651 float ftmp1, ftmp2;
pascal@12756 6652
pascal@12756 6653 ftmp1 = 0.0;
pascal@12756 6654 ftmp2 = 0.0;
pascal@12756 6655 for (i=0; i<subl; i++) {
pascal@12756 6656 ftmp1 += target[i]*regressor[i];
pascal@12756 6657 ftmp2 += regressor[i]*regressor[i];
pascal@12756 6658 }
pascal@12756 6659
pascal@12756 6660 if (ftmp1 > 0.0) {
pascal@12756 6661 return (float)(ftmp1*ftmp1/ftmp2);
pascal@12756 6662 }
pascal@12756 6663
pascal@12756 6664
pascal@12756 6665
pascal@12756 6666 Andersen, et al. Experimental [Page 119]
pascal@12756 6667
pascal@12756 6668 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6669
pascal@12756 6670
pascal@12756 6671 else {
pascal@12756 6672 return (float)0.0;
pascal@12756 6673 }
pascal@12756 6674 }
pascal@12756 6675
pascal@12756 6676 /*----------------------------------------------------------------*
pascal@12756 6677 * interface for enhancer
pascal@12756 6678 *---------------------------------------------------------------*/
pascal@12756 6679
pascal@12756 6680 int enhancerInterface(
pascal@12756 6681 float *out, /* (o) enhanced signal */
pascal@12756 6682 float *in, /* (i) unenhanced signal */
pascal@12756 6683 iLBC_Dec_Inst_t *iLBCdec_inst /* (i) buffers etc */
pascal@12756 6684 ){
pascal@12756 6685 float *enh_buf, *enh_period;
pascal@12756 6686 int iblock, isample;
pascal@12756 6687 int lag=0, ilag, i, ioffset;
pascal@12756 6688 float cc, maxcc;
pascal@12756 6689 float ftmp1, ftmp2;
pascal@12756 6690 float *inPtr, *enh_bufPtr1, *enh_bufPtr2;
pascal@12756 6691 float plc_pred[ENH_BLOCKL];
pascal@12756 6692
pascal@12756 6693 float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2];
pascal@12756 6694 int inLen=ENH_NBLOCKS*ENH_BLOCKL+120;
pascal@12756 6695 int start, plc_blockl, inlag;
pascal@12756 6696
pascal@12756 6697 enh_buf=iLBCdec_inst->enh_buf;
pascal@12756 6698 enh_period=iLBCdec_inst->enh_period;
pascal@12756 6699
pascal@12756 6700 memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl],
pascal@12756 6701 (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float));
pascal@12756 6702
pascal@12756 6703 memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in,
pascal@12756 6704 iLBCdec_inst->blockl*sizeof(float));
pascal@12756 6705
pascal@12756 6706 if (iLBCdec_inst->mode==30)
pascal@12756 6707 plc_blockl=ENH_BLOCKL;
pascal@12756 6708 else
pascal@12756 6709 plc_blockl=40;
pascal@12756 6710
pascal@12756 6711 /* when 20 ms frame, move processing one block */
pascal@12756 6712 ioffset=0;
pascal@12756 6713 if (iLBCdec_inst->mode==20) ioffset=1;
pascal@12756 6714
pascal@12756 6715 i=3-ioffset;
pascal@12756 6716 memmove(enh_period, &enh_period[i],
pascal@12756 6717 (ENH_NBLOCKS_TOT-i)*sizeof(float));
pascal@12756 6718
pascal@12756 6719
pascal@12756 6720
pascal@12756 6721
pascal@12756 6722 Andersen, et al. Experimental [Page 120]
pascal@12756 6723
pascal@12756 6724 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6725
pascal@12756 6726
pascal@12756 6727 /* Set state information to the 6 samples right before
pascal@12756 6728 the samples to be downsampled. */
pascal@12756 6729
pascal@12756 6730 memcpy(lpState,
pascal@12756 6731 enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126,
pascal@12756 6732 6*sizeof(float));
pascal@12756 6733
pascal@12756 6734 /* Down sample a factor 2 to save computations */
pascal@12756 6735
pascal@12756 6736 DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120,
pascal@12756 6737 lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL,
pascal@12756 6738 lpState, downsampled);
pascal@12756 6739
pascal@12756 6740 /* Estimate the pitch in the down sampled domain. */
pascal@12756 6741 for (iblock = 0; iblock<ENH_NBLOCKS-ioffset; iblock++) {
pascal@12756 6742
pascal@12756 6743 lag = 10;
pascal@12756 6744 maxcc = xCorrCoef(downsampled+60+iblock*
pascal@12756 6745 ENH_BLOCKL_HALF, downsampled+60+iblock*
pascal@12756 6746 ENH_BLOCKL_HALF-lag, ENH_BLOCKL_HALF);
pascal@12756 6747 for (ilag=11; ilag<60; ilag++) {
pascal@12756 6748 cc = xCorrCoef(downsampled+60+iblock*
pascal@12756 6749 ENH_BLOCKL_HALF, downsampled+60+iblock*
pascal@12756 6750 ENH_BLOCKL_HALF-ilag, ENH_BLOCKL_HALF);
pascal@12756 6751
pascal@12756 6752 if (cc > maxcc) {
pascal@12756 6753 maxcc = cc;
pascal@12756 6754 lag = ilag;
pascal@12756 6755 }
pascal@12756 6756 }
pascal@12756 6757
pascal@12756 6758 /* Store the estimated lag in the non-downsampled domain */
pascal@12756 6759 enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2;
pascal@12756 6760
pascal@12756 6761
pascal@12756 6762 }
pascal@12756 6763
pascal@12756 6764
pascal@12756 6765 /* PLC was performed on the previous packet */
pascal@12756 6766 if (iLBCdec_inst->prev_enh_pl==1) {
pascal@12756 6767
pascal@12756 6768 inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset];
pascal@12756 6769
pascal@12756 6770 lag = inlag-1;
pascal@12756 6771 maxcc = xCorrCoef(in, in+lag, plc_blockl);
pascal@12756 6772 for (ilag=inlag; ilag<=inlag+1; ilag++) {
pascal@12756 6773 cc = xCorrCoef(in, in+ilag, plc_blockl);
pascal@12756 6774
pascal@12756 6775
pascal@12756 6776
pascal@12756 6777
pascal@12756 6778 Andersen, et al. Experimental [Page 121]
pascal@12756 6779
pascal@12756 6780 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6781
pascal@12756 6782
pascal@12756 6783 if (cc > maxcc) {
pascal@12756 6784 maxcc = cc;
pascal@12756 6785 lag = ilag;
pascal@12756 6786 }
pascal@12756 6787 }
pascal@12756 6788
pascal@12756 6789 enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag;
pascal@12756 6790
pascal@12756 6791 /* compute new concealed residual for the old lookahead,
pascal@12756 6792 mix the forward PLC with a backward PLC from
pascal@12756 6793 the new frame */
pascal@12756 6794
pascal@12756 6795 inPtr=&in[lag-1];
pascal@12756 6796
pascal@12756 6797 enh_bufPtr1=&plc_pred[plc_blockl-1];
pascal@12756 6798
pascal@12756 6799 if (lag>plc_blockl) {
pascal@12756 6800 start=plc_blockl;
pascal@12756 6801 } else {
pascal@12756 6802 start=lag;
pascal@12756 6803 }
pascal@12756 6804
pascal@12756 6805 for (isample = start; isample>0; isample--) {
pascal@12756 6806 *enh_bufPtr1-- = *inPtr--;
pascal@12756 6807 }
pascal@12756 6808
pascal@12756 6809 enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
pascal@12756 6810 for (isample = (plc_blockl-1-lag); isample>=0; isample--) {
pascal@12756 6811 *enh_bufPtr1-- = *enh_bufPtr2--;
pascal@12756 6812 }
pascal@12756 6813
pascal@12756 6814 /* limit energy change */
pascal@12756 6815 ftmp2=0.0;
pascal@12756 6816 ftmp1=0.0;
pascal@12756 6817 for (i=0;i<plc_blockl;i++) {
pascal@12756 6818 ftmp2+=enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]*
pascal@12756 6819 enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i];
pascal@12756 6820 ftmp1+=plc_pred[i]*plc_pred[i];
pascal@12756 6821 }
pascal@12756 6822 ftmp1=(float)sqrt(ftmp1/(float)plc_blockl);
pascal@12756 6823 ftmp2=(float)sqrt(ftmp2/(float)plc_blockl);
pascal@12756 6824 if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) {
pascal@12756 6825 for (i=0;i<plc_blockl-10;i++) {
pascal@12756 6826 plc_pred[i]*=(float)2.0*ftmp2/ftmp1;
pascal@12756 6827 }
pascal@12756 6828 for (i=plc_blockl-10;i<plc_blockl;i++) {
pascal@12756 6829 plc_pred[i]*=(float)(i-plc_blockl+10)*
pascal@12756 6830 ((float)1.0-(float)2.0*ftmp2/ftmp1)/(float)(10)+
pascal@12756 6831
pascal@12756 6832
pascal@12756 6833
pascal@12756 6834 Andersen, et al. Experimental [Page 122]
pascal@12756 6835
pascal@12756 6836 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6837
pascal@12756 6838
pascal@12756 6839 (float)2.0*ftmp2/ftmp1;
pascal@12756 6840 }
pascal@12756 6841 }
pascal@12756 6842
pascal@12756 6843 enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
pascal@12756 6844 for (i=0; i<plc_blockl; i++) {
pascal@12756 6845 ftmp1 = (float) (i+1) / (float) (plc_blockl+1);
pascal@12756 6846 *enh_bufPtr1 *= ftmp1;
pascal@12756 6847 *enh_bufPtr1 += ((float)1.0-ftmp1)*
pascal@12756 6848 plc_pred[plc_blockl-1-i];
pascal@12756 6849 enh_bufPtr1--;
pascal@12756 6850 }
pascal@12756 6851 }
pascal@12756 6852
pascal@12756 6853 if (iLBCdec_inst->mode==20) {
pascal@12756 6854 /* Enhancer with 40 samples delay */
pascal@12756 6855 for (iblock = 0; iblock<2; iblock++) {
pascal@12756 6856 enhancer(out+iblock*ENH_BLOCKL, enh_buf,
pascal@12756 6857 ENH_BUFL, (5+iblock)*ENH_BLOCKL+40,
pascal@12756 6858 ENH_ALPHA0, enh_period, enh_plocsTbl,
pascal@12756 6859 ENH_NBLOCKS_TOT);
pascal@12756 6860 }
pascal@12756 6861 } else if (iLBCdec_inst->mode==30) {
pascal@12756 6862 /* Enhancer with 80 samples delay */
pascal@12756 6863 for (iblock = 0; iblock<3; iblock++) {
pascal@12756 6864 enhancer(out+iblock*ENH_BLOCKL, enh_buf,
pascal@12756 6865 ENH_BUFL, (4+iblock)*ENH_BLOCKL,
pascal@12756 6866 ENH_ALPHA0, enh_period, enh_plocsTbl,
pascal@12756 6867 ENH_NBLOCKS_TOT);
pascal@12756 6868 }
pascal@12756 6869 }
pascal@12756 6870
pascal@12756 6871 return (lag*2);
pascal@12756 6872 }
pascal@12756 6873
pascal@12756 6874 A.17. filter.h
pascal@12756 6875
pascal@12756 6876 /******************************************************************
pascal@12756 6877
pascal@12756 6878 iLBC Speech Coder ANSI-C Source Code
pascal@12756 6879
pascal@12756 6880 filter.h
pascal@12756 6881
pascal@12756 6882 Copyright (C) The Internet Society (2004).
pascal@12756 6883 All Rights Reserved.
pascal@12756 6884
pascal@12756 6885 ******************************************************************/
pascal@12756 6886
pascal@12756 6887
pascal@12756 6888
pascal@12756 6889
pascal@12756 6890 Andersen, et al. Experimental [Page 123]
pascal@12756 6891
pascal@12756 6892 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6893
pascal@12756 6894
pascal@12756 6895 #ifndef __iLBC_FILTER_H
pascal@12756 6896 #define __iLBC_FILTER_H
pascal@12756 6897
pascal@12756 6898 void AllPoleFilter(
pascal@12756 6899 float *InOut, /* (i/o) on entrance InOut[-orderCoef] to
pascal@12756 6900 InOut[-1] contain the state of the
pascal@12756 6901 filter (delayed samples). InOut[0] to
pascal@12756 6902 InOut[lengthInOut-1] contain the filter
pascal@12756 6903 input, on en exit InOut[-orderCoef] to
pascal@12756 6904 InOut[-1] is unchanged and InOut[0] to
pascal@12756 6905 InOut[lengthInOut-1] contain filtered
pascal@12756 6906 samples */
pascal@12756 6907 float *Coef,/* (i) filter coefficients, Coef[0] is assumed
pascal@12756 6908 to be 1.0 */
pascal@12756 6909 int lengthInOut,/* (i) number of input/output samples */
pascal@12756 6910 int orderCoef /* (i) number of filter coefficients */
pascal@12756 6911 );
pascal@12756 6912
pascal@12756 6913 void AllZeroFilter(
pascal@12756 6914 float *In, /* (i) In[0] to In[lengthInOut-1] contain
pascal@12756 6915 filter input samples */
pascal@12756 6916 float *Coef,/* (i) filter coefficients (Coef[0] is assumed
pascal@12756 6917 to be 1.0) */
pascal@12756 6918 int lengthInOut,/* (i) number of input/output samples */
pascal@12756 6919 int orderCoef, /* (i) number of filter coefficients */
pascal@12756 6920 float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1]
pascal@12756 6921 contain the filter state, on exit Out[0]
pascal@12756 6922 to Out[lengthInOut-1] contain filtered
pascal@12756 6923 samples */
pascal@12756 6924 );
pascal@12756 6925
pascal@12756 6926 void ZeroPoleFilter(
pascal@12756 6927 float *In, /* (i) In[0] to In[lengthInOut-1] contain filter
pascal@12756 6928 input samples In[-orderCoef] to In[-1]
pascal@12756 6929 contain state of all-zero section */
pascal@12756 6930 float *ZeroCoef,/* (i) filter coefficients for all-zero
pascal@12756 6931 section (ZeroCoef[0] is assumed to
pascal@12756 6932 be 1.0) */
pascal@12756 6933 float *PoleCoef,/* (i) filter coefficients for all-pole section
pascal@12756 6934 (ZeroCoef[0] is assumed to be 1.0) */
pascal@12756 6935 int lengthInOut,/* (i) number of input/output samples */
pascal@12756 6936 int orderCoef, /* (i) number of filter coefficients */
pascal@12756 6937 float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1]
pascal@12756 6938 contain state of all-pole section. On
pascal@12756 6939 exit Out[0] to Out[lengthInOut-1]
pascal@12756 6940 contain filtered samples */
pascal@12756 6941 );
pascal@12756 6942
pascal@12756 6943
pascal@12756 6944
pascal@12756 6945
pascal@12756 6946 Andersen, et al. Experimental [Page 124]
pascal@12756 6947
pascal@12756 6948 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 6949
pascal@12756 6950
pascal@12756 6951 void DownSample (
pascal@12756 6952 float *In, /* (i) input samples */
pascal@12756 6953 float *Coef, /* (i) filter coefficients */
pascal@12756 6954 int lengthIn, /* (i) number of input samples */
pascal@12756 6955 float *state, /* (i) filter state */
pascal@12756 6956 float *Out /* (o) downsampled output */
pascal@12756 6957 );
pascal@12756 6958
pascal@12756 6959 #endif
pascal@12756 6960
pascal@12756 6961 A.18. filter.c
pascal@12756 6962
pascal@12756 6963 /******************************************************************
pascal@12756 6964
pascal@12756 6965 iLBC Speech Coder ANSI-C Source Code
pascal@12756 6966
pascal@12756 6967 filter.c
pascal@12756 6968
pascal@12756 6969 Copyright (C) The Internet Society (2004).
pascal@12756 6970 All Rights Reserved.
pascal@12756 6971
pascal@12756 6972 ******************************************************************/
pascal@12756 6973
pascal@12756 6974 #include "iLBC_define.h"
pascal@12756 6975
pascal@12756 6976 /*----------------------------------------------------------------*
pascal@12756 6977 * all-pole filter
pascal@12756 6978 *---------------------------------------------------------------*/
pascal@12756 6979
pascal@12756 6980 void AllPoleFilter(
pascal@12756 6981 float *InOut, /* (i/o) on entrance InOut[-orderCoef] to
pascal@12756 6982 InOut[-1] contain the state of the
pascal@12756 6983 filter (delayed samples). InOut[0] to
pascal@12756 6984 InOut[lengthInOut-1] contain the filter
pascal@12756 6985 input, on en exit InOut[-orderCoef] to
pascal@12756 6986 InOut[-1] is unchanged and InOut[0] to
pascal@12756 6987 InOut[lengthInOut-1] contain filtered
pascal@12756 6988 samples */
pascal@12756 6989 float *Coef,/* (i) filter coefficients, Coef[0] is assumed
pascal@12756 6990 to be 1.0 */
pascal@12756 6991 int lengthInOut,/* (i) number of input/output samples */
pascal@12756 6992 int orderCoef /* (i) number of filter coefficients */
pascal@12756 6993 ){
pascal@12756 6994 int n,k;
pascal@12756 6995
pascal@12756 6996 for(n=0;n<lengthInOut;n++){
pascal@12756 6997 for(k=1;k<=orderCoef;k++){
pascal@12756 6998 *InOut -= Coef[k]*InOut[-k];
pascal@12756 6999
pascal@12756 7000
pascal@12756 7001
pascal@12756 7002 Andersen, et al. Experimental [Page 125]
pascal@12756 7003
pascal@12756 7004 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7005
pascal@12756 7006
pascal@12756 7007 }
pascal@12756 7008 InOut++;
pascal@12756 7009 }
pascal@12756 7010 }
pascal@12756 7011
pascal@12756 7012 /*----------------------------------------------------------------*
pascal@12756 7013 * all-zero filter
pascal@12756 7014 *---------------------------------------------------------------*/
pascal@12756 7015
pascal@12756 7016 void AllZeroFilter(
pascal@12756 7017 float *In, /* (i) In[0] to In[lengthInOut-1] contain
pascal@12756 7018 filter input samples */
pascal@12756 7019 float *Coef,/* (i) filter coefficients (Coef[0] is assumed
pascal@12756 7020 to be 1.0) */
pascal@12756 7021 int lengthInOut,/* (i) number of input/output samples */
pascal@12756 7022 int orderCoef, /* (i) number of filter coefficients */
pascal@12756 7023 float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1]
pascal@12756 7024 contain the filter state, on exit Out[0]
pascal@12756 7025 to Out[lengthInOut-1] contain filtered
pascal@12756 7026 samples */
pascal@12756 7027 ){
pascal@12756 7028 int n,k;
pascal@12756 7029
pascal@12756 7030 for(n=0;n<lengthInOut;n++){
pascal@12756 7031 *Out = Coef[0]*In[0];
pascal@12756 7032 for(k=1;k<=orderCoef;k++){
pascal@12756 7033 *Out += Coef[k]*In[-k];
pascal@12756 7034 }
pascal@12756 7035 Out++;
pascal@12756 7036 In++;
pascal@12756 7037 }
pascal@12756 7038 }
pascal@12756 7039
pascal@12756 7040 /*----------------------------------------------------------------*
pascal@12756 7041 * pole-zero filter
pascal@12756 7042 *---------------------------------------------------------------*/
pascal@12756 7043
pascal@12756 7044 void ZeroPoleFilter(
pascal@12756 7045 float *In, /* (i) In[0] to In[lengthInOut-1] contain
pascal@12756 7046 filter input samples In[-orderCoef] to
pascal@12756 7047 In[-1] contain state of all-zero
pascal@12756 7048 section */
pascal@12756 7049 float *ZeroCoef,/* (i) filter coefficients for all-zero
pascal@12756 7050 section (ZeroCoef[0] is assumed to
pascal@12756 7051 be 1.0) */
pascal@12756 7052 float *PoleCoef,/* (i) filter coefficients for all-pole section
pascal@12756 7053 (ZeroCoef[0] is assumed to be 1.0) */
pascal@12756 7054 int lengthInOut,/* (i) number of input/output samples */
pascal@12756 7055
pascal@12756 7056
pascal@12756 7057
pascal@12756 7058 Andersen, et al. Experimental [Page 126]
pascal@12756 7059
pascal@12756 7060 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7061
pascal@12756 7062
pascal@12756 7063 int orderCoef, /* (i) number of filter coefficients */
pascal@12756 7064 float *Out /* (i/o) on entrance Out[-orderCoef] to Out[-1]
pascal@12756 7065 contain state of all-pole section. On
pascal@12756 7066 exit Out[0] to Out[lengthInOut-1]
pascal@12756 7067 contain filtered samples */
pascal@12756 7068 ){
pascal@12756 7069 AllZeroFilter(In,ZeroCoef,lengthInOut,orderCoef,Out);
pascal@12756 7070 AllPoleFilter(Out,PoleCoef,lengthInOut,orderCoef);
pascal@12756 7071 }
pascal@12756 7072
pascal@12756 7073 /*----------------------------------------------------------------*
pascal@12756 7074 * downsample (LP filter and decimation)
pascal@12756 7075 *---------------------------------------------------------------*/
pascal@12756 7076
pascal@12756 7077 void DownSample (
pascal@12756 7078 float *In, /* (i) input samples */
pascal@12756 7079 float *Coef, /* (i) filter coefficients */
pascal@12756 7080 int lengthIn, /* (i) number of input samples */
pascal@12756 7081 float *state, /* (i) filter state */
pascal@12756 7082 float *Out /* (o) downsampled output */
pascal@12756 7083 ){
pascal@12756 7084 float o;
pascal@12756 7085 float *Out_ptr = Out;
pascal@12756 7086 float *Coef_ptr, *In_ptr;
pascal@12756 7087 float *state_ptr;
pascal@12756 7088 int i, j, stop;
pascal@12756 7089
pascal@12756 7090 /* LP filter and decimate at the same time */
pascal@12756 7091
pascal@12756 7092 for (i = DELAY_DS; i < lengthIn; i+=FACTOR_DS)
pascal@12756 7093 {
pascal@12756 7094 Coef_ptr = &Coef[0];
pascal@12756 7095 In_ptr = &In[i];
pascal@12756 7096 state_ptr = &state[FILTERORDER_DS-2];
pascal@12756 7097
pascal@12756 7098 o = (float)0.0;
pascal@12756 7099
pascal@12756 7100 stop = (i < FILTERORDER_DS) ? i + 1 : FILTERORDER_DS;
pascal@12756 7101
pascal@12756 7102 for (j = 0; j < stop; j++)
pascal@12756 7103 {
pascal@12756 7104 o += *Coef_ptr++ * (*In_ptr--);
pascal@12756 7105 }
pascal@12756 7106 for (j = i + 1; j < FILTERORDER_DS; j++)
pascal@12756 7107 {
pascal@12756 7108 o += *Coef_ptr++ * (*state_ptr--);
pascal@12756 7109 }
pascal@12756 7110
pascal@12756 7111
pascal@12756 7112
pascal@12756 7113
pascal@12756 7114 Andersen, et al. Experimental [Page 127]
pascal@12756 7115
pascal@12756 7116 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7117
pascal@12756 7118
pascal@12756 7119 *Out_ptr++ = o;
pascal@12756 7120 }
pascal@12756 7121
pascal@12756 7122 /* Get the last part (use zeros as input for the future) */
pascal@12756 7123
pascal@12756 7124 for (i=(lengthIn+FACTOR_DS); i<(lengthIn+DELAY_DS);
pascal@12756 7125 i+=FACTOR_DS) {
pascal@12756 7126
pascal@12756 7127 o=(float)0.0;
pascal@12756 7128
pascal@12756 7129 if (i<lengthIn) {
pascal@12756 7130 Coef_ptr = &Coef[0];
pascal@12756 7131 In_ptr = &In[i];
pascal@12756 7132 for (j=0; j<FILTERORDER_DS; j++) {
pascal@12756 7133 o += *Coef_ptr++ * (*Out_ptr--);
pascal@12756 7134 }
pascal@12756 7135 } else {
pascal@12756 7136 Coef_ptr = &Coef[i-lengthIn];
pascal@12756 7137 In_ptr = &In[lengthIn-1];
pascal@12756 7138 for (j=0; j<FILTERORDER_DS-(i-lengthIn); j++) {
pascal@12756 7139 o += *Coef_ptr++ * (*In_ptr--);
pascal@12756 7140 }
pascal@12756 7141 }
pascal@12756 7142 *Out_ptr++ = o;
pascal@12756 7143 }
pascal@12756 7144 }
pascal@12756 7145
pascal@12756 7146 A.19. FrameClassify.h
pascal@12756 7147
pascal@12756 7148 /******************************************************************
pascal@12756 7149
pascal@12756 7150 iLBC Speech Coder ANSI-C Source Code
pascal@12756 7151
pascal@12756 7152 FrameClassify.h
pascal@12756 7153
pascal@12756 7154 Copyright (C) The Internet Society (2004).
pascal@12756 7155 All Rights Reserved.
pascal@12756 7156
pascal@12756 7157 ******************************************************************/
pascal@12756 7158
pascal@12756 7159 #ifndef __iLBC_FRAMECLASSIFY_H
pascal@12756 7160 #define __iLBC_FRAMECLASSIFY_H
pascal@12756 7161
pascal@12756 7162 int FrameClassify( /* index to the max-energy sub-frame */
pascal@12756 7163 iLBC_Enc_Inst_t *iLBCenc_inst,
pascal@12756 7164 /* (i/o) the encoder state structure */
pascal@12756 7165 float *residual /* (i) lpc residual signal */
pascal@12756 7166 );
pascal@12756 7167
pascal@12756 7168
pascal@12756 7169
pascal@12756 7170 Andersen, et al. Experimental [Page 128]
pascal@12756 7171
pascal@12756 7172 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7173
pascal@12756 7174
pascal@12756 7175 #endif
pascal@12756 7176
pascal@12756 7177 A.20. FrameClassify.c
pascal@12756 7178
pascal@12756 7179 /******************************************************************
pascal@12756 7180
pascal@12756 7181 iLBC Speech Coder ANSI-C Source Code
pascal@12756 7182
pascal@12756 7183 FrameClassify.c
pascal@12756 7184
pascal@12756 7185 Copyright (C) The Internet Society (2004).
pascal@12756 7186 All Rights Reserved.
pascal@12756 7187
pascal@12756 7188 ******************************************************************/
pascal@12756 7189
pascal@12756 7190 #include "iLBC_define.h"
pascal@12756 7191
pascal@12756 7192 /*---------------------------------------------------------------*
pascal@12756 7193 * Classification of subframes to localize start state
pascal@12756 7194 *--------------------------------------------------------------*/
pascal@12756 7195
pascal@12756 7196 int FrameClassify( /* index to the max-energy sub-frame */
pascal@12756 7197 iLBC_Enc_Inst_t *iLBCenc_inst,
pascal@12756 7198 /* (i/o) the encoder state structure */
pascal@12756 7199 float *residual /* (i) lpc residual signal */
pascal@12756 7200 ) {
pascal@12756 7201 float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp;
pascal@12756 7202 int n, l, max_ssqEn_n;
pascal@12756 7203 const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9,
pascal@12756 7204 (float)1.0,(float)0.9,(float)0.8};
pascal@12756 7205 const float sampEn_win[5]={(float)1.0/(float)6.0,
pascal@12756 7206 (float)2.0/(float)6.0, (float)3.0/(float)6.0,
pascal@12756 7207 (float)4.0/(float)6.0, (float)5.0/(float)6.0};
pascal@12756 7208
pascal@12756 7209 /* init the front and back energies to zero */
pascal@12756 7210
pascal@12756 7211 memset(fssqEn, 0, NSUB_MAX*sizeof(float));
pascal@12756 7212 memset(bssqEn, 0, NSUB_MAX*sizeof(float));
pascal@12756 7213
pascal@12756 7214 /* Calculate front of first seqence */
pascal@12756 7215
pascal@12756 7216 n=0;
pascal@12756 7217 pp=residual;
pascal@12756 7218 for (l=0; l<5; l++) {
pascal@12756 7219 fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
pascal@12756 7220 pp++;
pascal@12756 7221 }
pascal@12756 7222 for (l=5; l<SUBL; l++) {
pascal@12756 7223
pascal@12756 7224
pascal@12756 7225
pascal@12756 7226 Andersen, et al. Experimental [Page 129]
pascal@12756 7227
pascal@12756 7228 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7229
pascal@12756 7230
pascal@12756 7231 fssqEn[n] += (*pp) * (*pp);
pascal@12756 7232 pp++;
pascal@12756 7233 }
pascal@12756 7234
pascal@12756 7235 /* Calculate front and back of all middle sequences */
pascal@12756 7236
pascal@12756 7237 for (n=1; n<iLBCenc_inst->nsub-1; n++) {
pascal@12756 7238 pp=residual+n*SUBL;
pascal@12756 7239 for (l=0; l<5; l++) {
pascal@12756 7240 fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
pascal@12756 7241 bssqEn[n] += (*pp) * (*pp);
pascal@12756 7242 pp++;
pascal@12756 7243 }
pascal@12756 7244 for (l=5; l<SUBL-5; l++) {
pascal@12756 7245 fssqEn[n] += (*pp) * (*pp);
pascal@12756 7246 bssqEn[n] += (*pp) * (*pp);
pascal@12756 7247 pp++;
pascal@12756 7248 }
pascal@12756 7249 for (l=SUBL-5; l<SUBL; l++) {
pascal@12756 7250 fssqEn[n] += (*pp) * (*pp);
pascal@12756 7251 bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
pascal@12756 7252 pp++;
pascal@12756 7253 }
pascal@12756 7254 }
pascal@12756 7255
pascal@12756 7256 /* Calculate back of last seqence */
pascal@12756 7257
pascal@12756 7258 n=iLBCenc_inst->nsub-1;
pascal@12756 7259 pp=residual+n*SUBL;
pascal@12756 7260 for (l=0; l<SUBL-5; l++) {
pascal@12756 7261 bssqEn[n] += (*pp) * (*pp);
pascal@12756 7262 pp++;
pascal@12756 7263 }
pascal@12756 7264 for (l=SUBL-5; l<SUBL; l++) {
pascal@12756 7265 bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
pascal@12756 7266 pp++;
pascal@12756 7267 }
pascal@12756 7268
pascal@12756 7269 /* find the index to the weighted 80 sample with
pascal@12756 7270 most energy */
pascal@12756 7271
pascal@12756 7272 if (iLBCenc_inst->mode==20) l=1;
pascal@12756 7273 else l=0;
pascal@12756 7274
pascal@12756 7275 max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l];
pascal@12756 7276 max_ssqEn_n=1;
pascal@12756 7277 for (n=2; n<iLBCenc_inst->nsub; n++) {
pascal@12756 7278
pascal@12756 7279
pascal@12756 7280
pascal@12756 7281
pascal@12756 7282 Andersen, et al. Experimental [Page 130]
pascal@12756 7283
pascal@12756 7284 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7285
pascal@12756 7286
pascal@12756 7287 l++;
pascal@12756 7288 if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) {
pascal@12756 7289 max_ssqEn=(fssqEn[n-1]+bssqEn[n]) *
pascal@12756 7290 ssqEn_win[l];
pascal@12756 7291 max_ssqEn_n=n;
pascal@12756 7292 }
pascal@12756 7293 }
pascal@12756 7294
pascal@12756 7295 return max_ssqEn_n;
pascal@12756 7296 }
pascal@12756 7297
pascal@12756 7298 A.21. gainquant.h
pascal@12756 7299
pascal@12756 7300 /******************************************************************
pascal@12756 7301
pascal@12756 7302 iLBC Speech Coder ANSI-C Source Code
pascal@12756 7303
pascal@12756 7304 gainquant.h
pascal@12756 7305
pascal@12756 7306 Copyright (C) The Internet Society (2004).
pascal@12756 7307 All Rights Reserved.
pascal@12756 7308
pascal@12756 7309 ******************************************************************/
pascal@12756 7310
pascal@12756 7311 #ifndef __iLBC_GAINQUANT_H
pascal@12756 7312 #define __iLBC_GAINQUANT_H
pascal@12756 7313
pascal@12756 7314 float gainquant(/* (o) quantized gain value */
pascal@12756 7315 float in, /* (i) gain value */
pascal@12756 7316 float maxIn,/* (i) maximum of gain value */
pascal@12756 7317 int cblen, /* (i) number of quantization indices */
pascal@12756 7318 int *index /* (o) quantization index */
pascal@12756 7319 );
pascal@12756 7320
pascal@12756 7321 float gaindequant( /* (o) quantized gain value */
pascal@12756 7322 int index, /* (i) quantization index */
pascal@12756 7323 float maxIn,/* (i) maximum of unquantized gain */
pascal@12756 7324 int cblen /* (i) number of quantization indices */
pascal@12756 7325 );
pascal@12756 7326
pascal@12756 7327 #endif
pascal@12756 7328
pascal@12756 7329 A.22. gainquant.c
pascal@12756 7330
pascal@12756 7331 /******************************************************************
pascal@12756 7332
pascal@12756 7333 iLBC Speech Coder ANSI-C Source Code
pascal@12756 7334
pascal@12756 7335
pascal@12756 7336
pascal@12756 7337
pascal@12756 7338 Andersen, et al. Experimental [Page 131]
pascal@12756 7339
pascal@12756 7340 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7341
pascal@12756 7342
pascal@12756 7343 gainquant.c
pascal@12756 7344
pascal@12756 7345 Copyright (C) The Internet Society (2004).
pascal@12756 7346 All Rights Reserved.
pascal@12756 7347
pascal@12756 7348 ******************************************************************/
pascal@12756 7349
pascal@12756 7350 #include <string.h>
pascal@12756 7351 #include <math.h>
pascal@12756 7352 #include "constants.h"
pascal@12756 7353 #include "filter.h"
pascal@12756 7354
pascal@12756 7355 /*----------------------------------------------------------------*
pascal@12756 7356 * quantizer for the gain in the gain-shape coding of residual
pascal@12756 7357 *---------------------------------------------------------------*/
pascal@12756 7358
pascal@12756 7359 float gainquant(/* (o) quantized gain value */
pascal@12756 7360 float in, /* (i) gain value */
pascal@12756 7361 float maxIn,/* (i) maximum of gain value */
pascal@12756 7362 int cblen, /* (i) number of quantization indices */
pascal@12756 7363 int *index /* (o) quantization index */
pascal@12756 7364 ){
pascal@12756 7365 int i, tindex;
pascal@12756 7366 float minmeasure,measure, *cb, scale;
pascal@12756 7367
pascal@12756 7368 /* ensure a lower bound on the scaling factor */
pascal@12756 7369
pascal@12756 7370 scale=maxIn;
pascal@12756 7371
pascal@12756 7372 if (scale<0.1) {
pascal@12756 7373 scale=(float)0.1;
pascal@12756 7374 }
pascal@12756 7375
pascal@12756 7376 /* select the quantization table */
pascal@12756 7377
pascal@12756 7378 if (cblen == 8) {
pascal@12756 7379 cb = gain_sq3Tbl;
pascal@12756 7380 } else if (cblen == 16) {
pascal@12756 7381 cb = gain_sq4Tbl;
pascal@12756 7382 } else {
pascal@12756 7383 cb = gain_sq5Tbl;
pascal@12756 7384 }
pascal@12756 7385
pascal@12756 7386 /* select the best index in the quantization table */
pascal@12756 7387
pascal@12756 7388 minmeasure=10000000.0;
pascal@12756 7389 tindex=0;
pascal@12756 7390 for (i=0; i<cblen; i++) {
pascal@12756 7391
pascal@12756 7392
pascal@12756 7393
pascal@12756 7394 Andersen, et al. Experimental [Page 132]
pascal@12756 7395
pascal@12756 7396 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7397
pascal@12756 7398
pascal@12756 7399 measure=(in-scale*cb[i])*(in-scale*cb[i]);
pascal@12756 7400
pascal@12756 7401 if (measure<minmeasure) {
pascal@12756 7402 tindex=i;
pascal@12756 7403 minmeasure=measure;
pascal@12756 7404 }
pascal@12756 7405 }
pascal@12756 7406 *index=tindex;
pascal@12756 7407
pascal@12756 7408 /* return the quantized value */
pascal@12756 7409
pascal@12756 7410 return scale*cb[tindex];
pascal@12756 7411 }
pascal@12756 7412
pascal@12756 7413 /*----------------------------------------------------------------*
pascal@12756 7414 * decoder for quantized gains in the gain-shape coding of
pascal@12756 7415 * residual
pascal@12756 7416 *---------------------------------------------------------------*/
pascal@12756 7417
pascal@12756 7418 float gaindequant( /* (o) quantized gain value */
pascal@12756 7419 int index, /* (i) quantization index */
pascal@12756 7420 float maxIn,/* (i) maximum of unquantized gain */
pascal@12756 7421 int cblen /* (i) number of quantization indices */
pascal@12756 7422 ){
pascal@12756 7423 float scale;
pascal@12756 7424
pascal@12756 7425 /* obtain correct scale factor */
pascal@12756 7426
pascal@12756 7427 scale=(float)fabs(maxIn);
pascal@12756 7428
pascal@12756 7429 if (scale<0.1) {
pascal@12756 7430 scale=(float)0.1;
pascal@12756 7431 }
pascal@12756 7432
pascal@12756 7433 /* select the quantization table and return the decoded value */
pascal@12756 7434
pascal@12756 7435 if (cblen==8) {
pascal@12756 7436 return scale*gain_sq3Tbl[index];
pascal@12756 7437 } else if (cblen==16) {
pascal@12756 7438 return scale*gain_sq4Tbl[index];
pascal@12756 7439 }
pascal@12756 7440 else if (cblen==32) {
pascal@12756 7441 return scale*gain_sq5Tbl[index];
pascal@12756 7442 }
pascal@12756 7443
pascal@12756 7444 return 0.0;
pascal@12756 7445 }
pascal@12756 7446
pascal@12756 7447
pascal@12756 7448
pascal@12756 7449
pascal@12756 7450 Andersen, et al. Experimental [Page 133]
pascal@12756 7451
pascal@12756 7452 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7453
pascal@12756 7454
pascal@12756 7455 A.23. getCBvec.h
pascal@12756 7456
pascal@12756 7457 /******************************************************************
pascal@12756 7458
pascal@12756 7459 iLBC Speech Coder ANSI-C Source Code
pascal@12756 7460
pascal@12756 7461 getCBvec.h
pascal@12756 7462
pascal@12756 7463 Copyright (C) The Internet Society (2004).
pascal@12756 7464 All Rights Reserved.
pascal@12756 7465
pascal@12756 7466 ******************************************************************/
pascal@12756 7467
pascal@12756 7468 #ifndef __iLBC_GETCBVEC_H
pascal@12756 7469 #define __iLBC_GETCBVEC_H
pascal@12756 7470
pascal@12756 7471 void getCBvec(
pascal@12756 7472 float *cbvec, /* (o) Constructed codebook vector */
pascal@12756 7473 float *mem, /* (i) Codebook buffer */
pascal@12756 7474 int index, /* (i) Codebook index */
pascal@12756 7475 int lMem, /* (i) Length of codebook buffer */
pascal@12756 7476 int cbveclen/* (i) Codebook vector length */
pascal@12756 7477 );
pascal@12756 7478
pascal@12756 7479 #endif
pascal@12756 7480
pascal@12756 7481 A.24. getCBvec.c
pascal@12756 7482
pascal@12756 7483 /******************************************************************
pascal@12756 7484
pascal@12756 7485 iLBC Speech Coder ANSI-C Source Code
pascal@12756 7486
pascal@12756 7487 getCBvec.c
pascal@12756 7488
pascal@12756 7489 Copyright (C) The Internet Society (2004).
pascal@12756 7490 All Rights Reserved.
pascal@12756 7491
pascal@12756 7492 ******************************************************************/
pascal@12756 7493
pascal@12756 7494 #include "iLBC_define.h"
pascal@12756 7495 #include "constants.h"
pascal@12756 7496 #include <string.h>
pascal@12756 7497
pascal@12756 7498 /*----------------------------------------------------------------*
pascal@12756 7499 * Construct codebook vector for given index.
pascal@12756 7500 *---------------------------------------------------------------*/
pascal@12756 7501
pascal@12756 7502 void getCBvec(
pascal@12756 7503
pascal@12756 7504
pascal@12756 7505
pascal@12756 7506 Andersen, et al. Experimental [Page 134]
pascal@12756 7507
pascal@12756 7508 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7509
pascal@12756 7510
pascal@12756 7511 float *cbvec, /* (o) Constructed codebook vector */
pascal@12756 7512 float *mem, /* (i) Codebook buffer */
pascal@12756 7513 int index, /* (i) Codebook index */
pascal@12756 7514 int lMem, /* (i) Length of codebook buffer */
pascal@12756 7515 int cbveclen/* (i) Codebook vector length */
pascal@12756 7516 ){
pascal@12756 7517 int j, k, n, memInd, sFilt;
pascal@12756 7518 float tmpbuf[CB_MEML];
pascal@12756 7519 int base_size;
pascal@12756 7520 int ilow, ihigh;
pascal@12756 7521 float alfa, alfa1;
pascal@12756 7522
pascal@12756 7523 /* Determine size of codebook sections */
pascal@12756 7524
pascal@12756 7525 base_size=lMem-cbveclen+1;
pascal@12756 7526
pascal@12756 7527 if (cbveclen==SUBL) {
pascal@12756 7528 base_size+=cbveclen/2;
pascal@12756 7529 }
pascal@12756 7530
pascal@12756 7531 /* No filter -> First codebook section */
pascal@12756 7532
pascal@12756 7533 if (index<lMem-cbveclen+1) {
pascal@12756 7534
pascal@12756 7535 /* first non-interpolated vectors */
pascal@12756 7536
pascal@12756 7537 k=index+cbveclen;
pascal@12756 7538 /* get vector */
pascal@12756 7539 memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float));
pascal@12756 7540
pascal@12756 7541 } else if (index < base_size) {
pascal@12756 7542
pascal@12756 7543 k=2*(index-(lMem-cbveclen+1))+cbveclen;
pascal@12756 7544
pascal@12756 7545 ihigh=k/2;
pascal@12756 7546 ilow=ihigh-5;
pascal@12756 7547
pascal@12756 7548 /* Copy first noninterpolated part */
pascal@12756 7549
pascal@12756 7550 memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float));
pascal@12756 7551
pascal@12756 7552 /* interpolation */
pascal@12756 7553
pascal@12756 7554 alfa1=(float)0.2;
pascal@12756 7555 alfa=0.0;
pascal@12756 7556 for (j=ilow; j<ihigh; j++) {
pascal@12756 7557 cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+
pascal@12756 7558 alfa*mem[lMem-k+j];
pascal@12756 7559
pascal@12756 7560
pascal@12756 7561
pascal@12756 7562 Andersen, et al. Experimental [Page 135]
pascal@12756 7563
pascal@12756 7564 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7565
pascal@12756 7566
pascal@12756 7567 alfa+=alfa1;
pascal@12756 7568 }
pascal@12756 7569
pascal@12756 7570 /* Copy second noninterpolated part */
pascal@12756 7571
pascal@12756 7572 memcpy(cbvec+ihigh, mem+lMem-k+ihigh,
pascal@12756 7573 (cbveclen-ihigh)*sizeof(float));
pascal@12756 7574
pascal@12756 7575 }
pascal@12756 7576
pascal@12756 7577 /* Higher codebook section based on filtering */
pascal@12756 7578
pascal@12756 7579 else {
pascal@12756 7580
pascal@12756 7581 /* first non-interpolated vectors */
pascal@12756 7582
pascal@12756 7583 if (index-base_size<lMem-cbveclen+1) {
pascal@12756 7584 float tempbuff2[CB_MEML+CB_FILTERLEN+1];
pascal@12756 7585 float *pos;
pascal@12756 7586 float *pp, *pp1;
pascal@12756 7587
pascal@12756 7588 memset(tempbuff2, 0,
pascal@12756 7589 CB_HALFFILTERLEN*sizeof(float));
pascal@12756 7590 memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,
pascal@12756 7591 lMem*sizeof(float));
pascal@12756 7592 memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,
pascal@12756 7593 (CB_HALFFILTERLEN+1)*sizeof(float));
pascal@12756 7594
pascal@12756 7595 k=index-base_size+cbveclen;
pascal@12756 7596 sFilt=lMem-k;
pascal@12756 7597 memInd=sFilt+1-CB_HALFFILTERLEN;
pascal@12756 7598
pascal@12756 7599 /* do filtering */
pascal@12756 7600 pos=cbvec;
pascal@12756 7601 memset(pos, 0, cbveclen*sizeof(float));
pascal@12756 7602 for (n=0; n<cbveclen; n++) {
pascal@12756 7603 pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN];
pascal@12756 7604 pp1=&cbfiltersTbl[CB_FILTERLEN-1];
pascal@12756 7605 for (j=0; j<CB_FILTERLEN; j++) {
pascal@12756 7606 (*pos)+=(*pp++)*(*pp1--);
pascal@12756 7607 }
pascal@12756 7608 pos++;
pascal@12756 7609 }
pascal@12756 7610 }
pascal@12756 7611
pascal@12756 7612 /* interpolated vectors */
pascal@12756 7613
pascal@12756 7614 else {
pascal@12756 7615
pascal@12756 7616
pascal@12756 7617
pascal@12756 7618 Andersen, et al. Experimental [Page 136]
pascal@12756 7619
pascal@12756 7620 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7621
pascal@12756 7622
pascal@12756 7623 float tempbuff2[CB_MEML+CB_FILTERLEN+1];
pascal@12756 7624
pascal@12756 7625 float *pos;
pascal@12756 7626 float *pp, *pp1;
pascal@12756 7627 int i;
pascal@12756 7628
pascal@12756 7629 memset(tempbuff2, 0,
pascal@12756 7630 CB_HALFFILTERLEN*sizeof(float));
pascal@12756 7631 memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,
pascal@12756 7632 lMem*sizeof(float));
pascal@12756 7633 memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,
pascal@12756 7634 (CB_HALFFILTERLEN+1)*sizeof(float));
pascal@12756 7635
pascal@12756 7636 k=2*(index-base_size-
pascal@12756 7637 (lMem-cbveclen+1))+cbveclen;
pascal@12756 7638 sFilt=lMem-k;
pascal@12756 7639 memInd=sFilt+1-CB_HALFFILTERLEN;
pascal@12756 7640
pascal@12756 7641 /* do filtering */
pascal@12756 7642 pos=&tmpbuf[sFilt];
pascal@12756 7643 memset(pos, 0, k*sizeof(float));
pascal@12756 7644 for (i=0; i<k; i++) {
pascal@12756 7645 pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN];
pascal@12756 7646 pp1=&cbfiltersTbl[CB_FILTERLEN-1];
pascal@12756 7647 for (j=0; j<CB_FILTERLEN; j++) {
pascal@12756 7648 (*pos)+=(*pp++)*(*pp1--);
pascal@12756 7649 }
pascal@12756 7650 pos++;
pascal@12756 7651 }
pascal@12756 7652
pascal@12756 7653 ihigh=k/2;
pascal@12756 7654 ilow=ihigh-5;
pascal@12756 7655
pascal@12756 7656 /* Copy first noninterpolated part */
pascal@12756 7657
pascal@12756 7658 memcpy(cbvec, tmpbuf+lMem-k/2,
pascal@12756 7659 ilow*sizeof(float));
pascal@12756 7660
pascal@12756 7661 /* interpolation */
pascal@12756 7662
pascal@12756 7663 alfa1=(float)0.2;
pascal@12756 7664 alfa=0.0;
pascal@12756 7665 for (j=ilow; j<ihigh; j++) {
pascal@12756 7666 cbvec[j]=((float)1.0-alfa)*
pascal@12756 7667 tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j];
pascal@12756 7668 alfa+=alfa1;
pascal@12756 7669 }
pascal@12756 7670
pascal@12756 7671
pascal@12756 7672
pascal@12756 7673
pascal@12756 7674 Andersen, et al. Experimental [Page 137]
pascal@12756 7675
pascal@12756 7676 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7677
pascal@12756 7678
pascal@12756 7679 /* Copy second noninterpolated part */
pascal@12756 7680
pascal@12756 7681 memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh,
pascal@12756 7682 (cbveclen-ihigh)*sizeof(float));
pascal@12756 7683 }
pascal@12756 7684 }
pascal@12756 7685 }
pascal@12756 7686
pascal@12756 7687 A.25. helpfun.h
pascal@12756 7688
pascal@12756 7689 /******************************************************************
pascal@12756 7690
pascal@12756 7691 iLBC Speech Coder ANSI-C Source Code
pascal@12756 7692
pascal@12756 7693 helpfun.h
pascal@12756 7694
pascal@12756 7695 Copyright (C) The Internet Society (2004).
pascal@12756 7696 All Rights Reserved.
pascal@12756 7697
pascal@12756 7698 ******************************************************************/
pascal@12756 7699
pascal@12756 7700 #ifndef __iLBC_HELPFUN_H
pascal@12756 7701 #define __iLBC_HELPFUN_H
pascal@12756 7702
pascal@12756 7703 void autocorr(
pascal@12756 7704 float *r, /* (o) autocorrelation vector */
pascal@12756 7705 const float *x, /* (i) data vector */
pascal@12756 7706 int N, /* (i) length of data vector */
pascal@12756 7707 int order /* largest lag for calculated
pascal@12756 7708 autocorrelations */
pascal@12756 7709 );
pascal@12756 7710
pascal@12756 7711 void window(
pascal@12756 7712 float *z, /* (o) the windowed data */
pascal@12756 7713 const float *x, /* (i) the original data vector */
pascal@12756 7714 const float *y, /* (i) the window */
pascal@12756 7715 int N /* (i) length of all vectors */
pascal@12756 7716 );
pascal@12756 7717
pascal@12756 7718 void levdurb(
pascal@12756 7719 float *a, /* (o) lpc coefficient vector starting
pascal@12756 7720 with 1.0 */
pascal@12756 7721 float *k, /* (o) reflection coefficients */
pascal@12756 7722 float *r, /* (i) autocorrelation vector */
pascal@12756 7723 int order /* (i) order of lpc filter */
pascal@12756 7724 );
pascal@12756 7725
pascal@12756 7726 void interpolate(
pascal@12756 7727
pascal@12756 7728
pascal@12756 7729
pascal@12756 7730 Andersen, et al. Experimental [Page 138]
pascal@12756 7731
pascal@12756 7732 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7733
pascal@12756 7734
pascal@12756 7735 float *out, /* (o) the interpolated vector */
pascal@12756 7736 float *in1, /* (i) the first vector for the
pascal@12756 7737 interpolation */
pascal@12756 7738 float *in2, /* (i) the second vector for the
pascal@12756 7739 interpolation */
pascal@12756 7740 float coef, /* (i) interpolation weights */
pascal@12756 7741 int length /* (i) length of all vectors */
pascal@12756 7742 );
pascal@12756 7743
pascal@12756 7744 void bwexpand(
pascal@12756 7745 float *out, /* (o) the bandwidth expanded lpc
pascal@12756 7746 coefficients */
pascal@12756 7747 float *in, /* (i) the lpc coefficients before bandwidth
pascal@12756 7748 expansion */
pascal@12756 7749 float coef, /* (i) the bandwidth expansion factor */
pascal@12756 7750 int length /* (i) the length of lpc coefficient vectors */
pascal@12756 7751 );
pascal@12756 7752
pascal@12756 7753 void vq(
pascal@12756 7754 float *Xq, /* (o) the quantized vector */
pascal@12756 7755 int *index, /* (o) the quantization index */
pascal@12756 7756 const float *CB,/* (i) the vector quantization codebook */
pascal@12756 7757 float *X, /* (i) the vector to quantize */
pascal@12756 7758 int n_cb, /* (i) the number of vectors in the codebook */
pascal@12756 7759 int dim /* (i) the dimension of all vectors */
pascal@12756 7760 );
pascal@12756 7761
pascal@12756 7762 void SplitVQ(
pascal@12756 7763 float *qX, /* (o) the quantized vector */
pascal@12756 7764 int *index, /* (o) a vector of indexes for all vector
pascal@12756 7765 codebooks in the split */
pascal@12756 7766 float *X, /* (i) the vector to quantize */
pascal@12756 7767 const float *CB,/* (i) the quantizer codebook */
pascal@12756 7768 int nsplit, /* the number of vector splits */
pascal@12756 7769 const int *dim, /* the dimension of X and qX */
pascal@12756 7770 const int *cbsize /* the number of vectors in the codebook */
pascal@12756 7771 );
pascal@12756 7772
pascal@12756 7773
pascal@12756 7774 void sort_sq(
pascal@12756 7775 float *xq, /* (o) the quantized value */
pascal@12756 7776 int *index, /* (o) the quantization index */
pascal@12756 7777 float x, /* (i) the value to quantize */
pascal@12756 7778 const float *cb,/* (i) the quantization codebook */
pascal@12756 7779 int cb_size /* (i) the size of the quantization codebook */
pascal@12756 7780 );
pascal@12756 7781
pascal@12756 7782 int LSF_check( /* (o) 1 for stable lsf vectors and 0 for
pascal@12756 7783
pascal@12756 7784
pascal@12756 7785
pascal@12756 7786 Andersen, et al. Experimental [Page 139]
pascal@12756 7787
pascal@12756 7788 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7789
pascal@12756 7790
pascal@12756 7791 nonstable ones */
pascal@12756 7792 float *lsf, /* (i) a table of lsf vectors */
pascal@12756 7793 int dim, /* (i) the dimension of each lsf vector */
pascal@12756 7794 int NoAn /* (i) the number of lsf vectors in the
pascal@12756 7795 table */
pascal@12756 7796 );
pascal@12756 7797
pascal@12756 7798 #endif
pascal@12756 7799
pascal@12756 7800 A.26. helpfun.c
pascal@12756 7801
pascal@12756 7802 /******************************************************************
pascal@12756 7803
pascal@12756 7804 iLBC Speech Coder ANSI-C Source Code
pascal@12756 7805
pascal@12756 7806 helpfun.c
pascal@12756 7807
pascal@12756 7808 Copyright (C) The Internet Society (2004).
pascal@12756 7809 All Rights Reserved.
pascal@12756 7810
pascal@12756 7811 ******************************************************************/
pascal@12756 7812
pascal@12756 7813 #include <math.h>
pascal@12756 7814
pascal@12756 7815 #include "iLBC_define.h"
pascal@12756 7816 #include "constants.h"
pascal@12756 7817
pascal@12756 7818 /*----------------------------------------------------------------*
pascal@12756 7819 * calculation of auto correlation
pascal@12756 7820 *---------------------------------------------------------------*/
pascal@12756 7821
pascal@12756 7822 void autocorr(
pascal@12756 7823 float *r, /* (o) autocorrelation vector */
pascal@12756 7824 const float *x, /* (i) data vector */
pascal@12756 7825 int N, /* (i) length of data vector */
pascal@12756 7826 int order /* largest lag for calculated
pascal@12756 7827 autocorrelations */
pascal@12756 7828 ){
pascal@12756 7829 int lag, n;
pascal@12756 7830 float sum;
pascal@12756 7831
pascal@12756 7832 for (lag = 0; lag <= order; lag++) {
pascal@12756 7833 sum = 0;
pascal@12756 7834 for (n = 0; n < N - lag; n++) {
pascal@12756 7835 sum += x[n] * x[n+lag];
pascal@12756 7836 }
pascal@12756 7837 r[lag] = sum;
pascal@12756 7838 }
pascal@12756 7839
pascal@12756 7840
pascal@12756 7841
pascal@12756 7842 Andersen, et al. Experimental [Page 140]
pascal@12756 7843
pascal@12756 7844 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7845
pascal@12756 7846
pascal@12756 7847 }
pascal@12756 7848
pascal@12756 7849 /*----------------------------------------------------------------*
pascal@12756 7850 * window multiplication
pascal@12756 7851 *---------------------------------------------------------------*/
pascal@12756 7852
pascal@12756 7853 void window(
pascal@12756 7854 float *z, /* (o) the windowed data */
pascal@12756 7855 const float *x, /* (i) the original data vector */
pascal@12756 7856 const float *y, /* (i) the window */
pascal@12756 7857 int N /* (i) length of all vectors */
pascal@12756 7858 ){
pascal@12756 7859 int i;
pascal@12756 7860
pascal@12756 7861 for (i = 0; i < N; i++) {
pascal@12756 7862 z[i] = x[i] * y[i];
pascal@12756 7863 }
pascal@12756 7864 }
pascal@12756 7865
pascal@12756 7866 /*----------------------------------------------------------------*
pascal@12756 7867 * levinson-durbin solution for lpc coefficients
pascal@12756 7868 *---------------------------------------------------------------*/
pascal@12756 7869
pascal@12756 7870 void levdurb(
pascal@12756 7871 float *a, /* (o) lpc coefficient vector starting
pascal@12756 7872 with 1.0 */
pascal@12756 7873 float *k, /* (o) reflection coefficients */
pascal@12756 7874 float *r, /* (i) autocorrelation vector */
pascal@12756 7875 int order /* (i) order of lpc filter */
pascal@12756 7876 ){
pascal@12756 7877 float sum, alpha;
pascal@12756 7878 int m, m_h, i;
pascal@12756 7879
pascal@12756 7880 a[0] = 1.0;
pascal@12756 7881
pascal@12756 7882 if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */
pascal@12756 7883 for (i = 0; i < order; i++) {
pascal@12756 7884 k[i] = 0;
pascal@12756 7885 a[i+1] = 0;
pascal@12756 7886 }
pascal@12756 7887 } else {
pascal@12756 7888 a[1] = k[0] = -r[1]/r[0];
pascal@12756 7889 alpha = r[0] + r[1] * k[0];
pascal@12756 7890 for (m = 1; m < order; m++){
pascal@12756 7891 sum = r[m + 1];
pascal@12756 7892 for (i = 0; i < m; i++){
pascal@12756 7893 sum += a[i+1] * r[m - i];
pascal@12756 7894 }
pascal@12756 7895
pascal@12756 7896
pascal@12756 7897
pascal@12756 7898 Andersen, et al. Experimental [Page 141]
pascal@12756 7899
pascal@12756 7900 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7901
pascal@12756 7902
pascal@12756 7903 k[m] = -sum / alpha;
pascal@12756 7904 alpha += k[m] * sum;
pascal@12756 7905 m_h = (m + 1) >> 1;
pascal@12756 7906 for (i = 0; i < m_h; i++){
pascal@12756 7907 sum = a[i+1] + k[m] * a[m - i];
pascal@12756 7908 a[m - i] += k[m] * a[i+1];
pascal@12756 7909 a[i+1] = sum;
pascal@12756 7910 }
pascal@12756 7911 a[m+1] = k[m];
pascal@12756 7912 }
pascal@12756 7913 }
pascal@12756 7914 }
pascal@12756 7915
pascal@12756 7916 /*----------------------------------------------------------------*
pascal@12756 7917 * interpolation between vectors
pascal@12756 7918 *---------------------------------------------------------------*/
pascal@12756 7919
pascal@12756 7920 void interpolate(
pascal@12756 7921 float *out, /* (o) the interpolated vector */
pascal@12756 7922 float *in1, /* (i) the first vector for the
pascal@12756 7923 interpolation */
pascal@12756 7924 float *in2, /* (i) the second vector for the
pascal@12756 7925 interpolation */
pascal@12756 7926 float coef, /* (i) interpolation weights */
pascal@12756 7927 int length /* (i) length of all vectors */
pascal@12756 7928 ){
pascal@12756 7929 int i;
pascal@12756 7930 float invcoef;
pascal@12756 7931
pascal@12756 7932 invcoef = (float)1.0 - coef;
pascal@12756 7933 for (i = 0; i < length; i++) {
pascal@12756 7934 out[i] = coef * in1[i] + invcoef * in2[i];
pascal@12756 7935 }
pascal@12756 7936 }
pascal@12756 7937
pascal@12756 7938 /*----------------------------------------------------------------*
pascal@12756 7939 * lpc bandwidth expansion
pascal@12756 7940 *---------------------------------------------------------------*/
pascal@12756 7941
pascal@12756 7942 void bwexpand(
pascal@12756 7943 float *out, /* (o) the bandwidth expanded lpc
pascal@12756 7944 coefficients */
pascal@12756 7945 float *in, /* (i) the lpc coefficients before bandwidth
pascal@12756 7946 expansion */
pascal@12756 7947 float coef, /* (i) the bandwidth expansion factor */
pascal@12756 7948 int length /* (i) the length of lpc coefficient vectors */
pascal@12756 7949 ){
pascal@12756 7950 int i;
pascal@12756 7951
pascal@12756 7952
pascal@12756 7953
pascal@12756 7954 Andersen, et al. Experimental [Page 142]
pascal@12756 7955
pascal@12756 7956 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 7957
pascal@12756 7958
pascal@12756 7959 float chirp;
pascal@12756 7960
pascal@12756 7961 chirp = coef;
pascal@12756 7962
pascal@12756 7963 out[0] = in[0];
pascal@12756 7964 for (i = 1; i < length; i++) {
pascal@12756 7965 out[i] = chirp * in[i];
pascal@12756 7966 chirp *= coef;
pascal@12756 7967 }
pascal@12756 7968 }
pascal@12756 7969
pascal@12756 7970 /*----------------------------------------------------------------*
pascal@12756 7971 * vector quantization
pascal@12756 7972 *---------------------------------------------------------------*/
pascal@12756 7973
pascal@12756 7974 void vq(
pascal@12756 7975 float *Xq, /* (o) the quantized vector */
pascal@12756 7976 int *index, /* (o) the quantization index */
pascal@12756 7977 const float *CB,/* (i) the vector quantization codebook */
pascal@12756 7978 float *X, /* (i) the vector to quantize */
pascal@12756 7979 int n_cb, /* (i) the number of vectors in the codebook */
pascal@12756 7980 int dim /* (i) the dimension of all vectors */
pascal@12756 7981 ){
pascal@12756 7982 int i, j;
pascal@12756 7983 int pos, minindex;
pascal@12756 7984 float dist, tmp, mindist;
pascal@12756 7985
pascal@12756 7986 pos = 0;
pascal@12756 7987 mindist = FLOAT_MAX;
pascal@12756 7988 minindex = 0;
pascal@12756 7989 for (j = 0; j < n_cb; j++) {
pascal@12756 7990 dist = X[0] - CB[pos];
pascal@12756 7991 dist *= dist;
pascal@12756 7992 for (i = 1; i < dim; i++) {
pascal@12756 7993 tmp = X[i] - CB[pos + i];
pascal@12756 7994 dist += tmp*tmp;
pascal@12756 7995 }
pascal@12756 7996
pascal@12756 7997 if (dist < mindist) {
pascal@12756 7998 mindist = dist;
pascal@12756 7999 minindex = j;
pascal@12756 8000 }
pascal@12756 8001 pos += dim;
pascal@12756 8002 }
pascal@12756 8003 for (i = 0; i < dim; i++) {
pascal@12756 8004 Xq[i] = CB[minindex*dim + i];
pascal@12756 8005 }
pascal@12756 8006 *index = minindex;
pascal@12756 8007
pascal@12756 8008
pascal@12756 8009
pascal@12756 8010 Andersen, et al. Experimental [Page 143]
pascal@12756 8011
pascal@12756 8012 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8013
pascal@12756 8014
pascal@12756 8015 }
pascal@12756 8016
pascal@12756 8017 /*----------------------------------------------------------------*
pascal@12756 8018 * split vector quantization
pascal@12756 8019 *---------------------------------------------------------------*/
pascal@12756 8020
pascal@12756 8021 void SplitVQ(
pascal@12756 8022 float *qX, /* (o) the quantized vector */
pascal@12756 8023 int *index, /* (o) a vector of indexes for all vector
pascal@12756 8024 codebooks in the split */
pascal@12756 8025 float *X, /* (i) the vector to quantize */
pascal@12756 8026 const float *CB,/* (i) the quantizer codebook */
pascal@12756 8027 int nsplit, /* the number of vector splits */
pascal@12756 8028 const int *dim, /* the dimension of X and qX */
pascal@12756 8029 const int *cbsize /* the number of vectors in the codebook */
pascal@12756 8030 ){
pascal@12756 8031 int cb_pos, X_pos, i;
pascal@12756 8032
pascal@12756 8033 cb_pos = 0;
pascal@12756 8034 X_pos= 0;
pascal@12756 8035 for (i = 0; i < nsplit; i++) {
pascal@12756 8036 vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos,
pascal@12756 8037 cbsize[i], dim[i]);
pascal@12756 8038 X_pos += dim[i];
pascal@12756 8039 cb_pos += dim[i] * cbsize[i];
pascal@12756 8040 }
pascal@12756 8041 }
pascal@12756 8042
pascal@12756 8043 /*----------------------------------------------------------------*
pascal@12756 8044 * scalar quantization
pascal@12756 8045 *---------------------------------------------------------------*/
pascal@12756 8046
pascal@12756 8047 void sort_sq(
pascal@12756 8048 float *xq, /* (o) the quantized value */
pascal@12756 8049 int *index, /* (o) the quantization index */
pascal@12756 8050 float x, /* (i) the value to quantize */
pascal@12756 8051 const float *cb,/* (i) the quantization codebook */
pascal@12756 8052 int cb_size /* (i) the size of the quantization codebook */
pascal@12756 8053 ){
pascal@12756 8054 int i;
pascal@12756 8055
pascal@12756 8056 if (x <= cb[0]) {
pascal@12756 8057 *index = 0;
pascal@12756 8058 *xq = cb[0];
pascal@12756 8059 } else {
pascal@12756 8060 i = 0;
pascal@12756 8061 while ((x > cb[i]) && i < cb_size - 1) {
pascal@12756 8062 i++;
pascal@12756 8063
pascal@12756 8064
pascal@12756 8065
pascal@12756 8066 Andersen, et al. Experimental [Page 144]
pascal@12756 8067
pascal@12756 8068 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8069
pascal@12756 8070
pascal@12756 8071 }
pascal@12756 8072
pascal@12756 8073 if (x > ((cb[i] + cb[i - 1])/2)) {
pascal@12756 8074 *index = i;
pascal@12756 8075 *xq = cb[i];
pascal@12756 8076 } else {
pascal@12756 8077 *index = i - 1;
pascal@12756 8078 *xq = cb[i - 1];
pascal@12756 8079 }
pascal@12756 8080 }
pascal@12756 8081 }
pascal@12756 8082
pascal@12756 8083 /*----------------------------------------------------------------*
pascal@12756 8084 * check for stability of lsf coefficients
pascal@12756 8085 *---------------------------------------------------------------*/
pascal@12756 8086
pascal@12756 8087 int LSF_check( /* (o) 1 for stable lsf vectors and 0 for
pascal@12756 8088 nonstable ones */
pascal@12756 8089 float *lsf, /* (i) a table of lsf vectors */
pascal@12756 8090 int dim, /* (i) the dimension of each lsf vector */
pascal@12756 8091 int NoAn /* (i) the number of lsf vectors in the
pascal@12756 8092 table */
pascal@12756 8093 ){
pascal@12756 8094 int k,n,m, Nit=2, change=0,pos;
pascal@12756 8095 float tmp;
pascal@12756 8096 static float eps=(float)0.039; /* 50 Hz */
pascal@12756 8097 static float eps2=(float)0.0195;
pascal@12756 8098 static float maxlsf=(float)3.14; /* 4000 Hz */
pascal@12756 8099 static float minlsf=(float)0.01; /* 0 Hz */
pascal@12756 8100
pascal@12756 8101 /* LSF separation check*/
pascal@12756 8102
pascal@12756 8103 for (n=0; n<Nit; n++) { /* Run through a couple of times */
pascal@12756 8104 for (m=0; m<NoAn; m++) { /* Number of analyses per frame */
pascal@12756 8105 for (k=0; k<(dim-1); k++) {
pascal@12756 8106 pos=m*dim+k;
pascal@12756 8107
pascal@12756 8108 if ((lsf[pos+1]-lsf[pos])<eps) {
pascal@12756 8109
pascal@12756 8110 if (lsf[pos+1]<lsf[pos]) {
pascal@12756 8111 tmp=lsf[pos+1];
pascal@12756 8112 lsf[pos+1]= lsf[pos]+eps2;
pascal@12756 8113 lsf[pos]= lsf[pos+1]-eps2;
pascal@12756 8114 } else {
pascal@12756 8115 lsf[pos]-=eps2;
pascal@12756 8116 lsf[pos+1]+=eps2;
pascal@12756 8117 }
pascal@12756 8118 change=1;
pascal@12756 8119
pascal@12756 8120
pascal@12756 8121
pascal@12756 8122 Andersen, et al. Experimental [Page 145]
pascal@12756 8123
pascal@12756 8124 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8125
pascal@12756 8126
pascal@12756 8127 }
pascal@12756 8128
pascal@12756 8129 if (lsf[pos]<minlsf) {
pascal@12756 8130 lsf[pos]=minlsf;
pascal@12756 8131 change=1;
pascal@12756 8132 }
pascal@12756 8133
pascal@12756 8134 if (lsf[pos]>maxlsf) {
pascal@12756 8135 lsf[pos]=maxlsf;
pascal@12756 8136 change=1;
pascal@12756 8137 }
pascal@12756 8138 }
pascal@12756 8139 }
pascal@12756 8140 }
pascal@12756 8141
pascal@12756 8142 return change;
pascal@12756 8143 }
pascal@12756 8144
pascal@12756 8145 A.27. hpInput.h
pascal@12756 8146
pascal@12756 8147 /******************************************************************
pascal@12756 8148
pascal@12756 8149 iLBC Speech Coder ANSI-C Source Code
pascal@12756 8150
pascal@12756 8151 hpInput.h
pascal@12756 8152
pascal@12756 8153 Copyright (C) The Internet Society (2004).
pascal@12756 8154 All Rights Reserved.
pascal@12756 8155
pascal@12756 8156 ******************************************************************/
pascal@12756 8157
pascal@12756 8158 #ifndef __iLBC_HPINPUT_H
pascal@12756 8159 #define __iLBC_HPINPUT_H
pascal@12756 8160
pascal@12756 8161 void hpInput(
pascal@12756 8162 float *In, /* (i) vector to filter */
pascal@12756 8163 int len, /* (i) length of vector to filter */
pascal@12756 8164 float *Out, /* (o) the resulting filtered vector */
pascal@12756 8165 float *mem /* (i/o) the filter state */
pascal@12756 8166 );
pascal@12756 8167
pascal@12756 8168 #endif
pascal@12756 8169
pascal@12756 8170 A.28. hpInput.c
pascal@12756 8171
pascal@12756 8172 /******************************************************************
pascal@12756 8173
pascal@12756 8174 iLBC Speech Coder ANSI-C Source Code
pascal@12756 8175
pascal@12756 8176
pascal@12756 8177
pascal@12756 8178 Andersen, et al. Experimental [Page 146]
pascal@12756 8179
pascal@12756 8180 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8181
pascal@12756 8182
pascal@12756 8183 hpInput.c
pascal@12756 8184
pascal@12756 8185 Copyright (C) The Internet Society (2004).
pascal@12756 8186 All Rights Reserved.
pascal@12756 8187
pascal@12756 8188 ******************************************************************/
pascal@12756 8189
pascal@12756 8190 #include "constants.h"
pascal@12756 8191
pascal@12756 8192 /*----------------------------------------------------------------*
pascal@12756 8193 * Input high-pass filter
pascal@12756 8194 *---------------------------------------------------------------*/
pascal@12756 8195
pascal@12756 8196 void hpInput(
pascal@12756 8197 float *In, /* (i) vector to filter */
pascal@12756 8198 int len, /* (i) length of vector to filter */
pascal@12756 8199 float *Out, /* (o) the resulting filtered vector */
pascal@12756 8200 float *mem /* (i/o) the filter state */
pascal@12756 8201 ){
pascal@12756 8202 int i;
pascal@12756 8203 float *pi, *po;
pascal@12756 8204
pascal@12756 8205 /* all-zero section*/
pascal@12756 8206
pascal@12756 8207 pi = &In[0];
pascal@12756 8208 po = &Out[0];
pascal@12756 8209 for (i=0; i<len; i++) {
pascal@12756 8210 *po = hpi_zero_coefsTbl[0] * (*pi);
pascal@12756 8211 *po += hpi_zero_coefsTbl[1] * mem[0];
pascal@12756 8212 *po += hpi_zero_coefsTbl[2] * mem[1];
pascal@12756 8213
pascal@12756 8214 mem[1] = mem[0];
pascal@12756 8215 mem[0] = *pi;
pascal@12756 8216 po++;
pascal@12756 8217 pi++;
pascal@12756 8218
pascal@12756 8219 }
pascal@12756 8220
pascal@12756 8221 /* all-pole section*/
pascal@12756 8222
pascal@12756 8223 po = &Out[0];
pascal@12756 8224 for (i=0; i<len; i++) {
pascal@12756 8225 *po -= hpi_pole_coefsTbl[1] * mem[2];
pascal@12756 8226 *po -= hpi_pole_coefsTbl[2] * mem[3];
pascal@12756 8227
pascal@12756 8228 mem[3] = mem[2];
pascal@12756 8229 mem[2] = *po;
pascal@12756 8230 po++;
pascal@12756 8231
pascal@12756 8232
pascal@12756 8233
pascal@12756 8234 Andersen, et al. Experimental [Page 147]
pascal@12756 8235
pascal@12756 8236 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8237
pascal@12756 8238
pascal@12756 8239 }
pascal@12756 8240 }
pascal@12756 8241
pascal@12756 8242 A.29. hpOutput.h
pascal@12756 8243
pascal@12756 8244 /******************************************************************
pascal@12756 8245
pascal@12756 8246 iLBC Speech Coder ANSI-C Source Code
pascal@12756 8247
pascal@12756 8248 hpOutput.h
pascal@12756 8249
pascal@12756 8250 Copyright (C) The Internet Society (2004).
pascal@12756 8251 All Rights Reserved.
pascal@12756 8252
pascal@12756 8253 ******************************************************************/
pascal@12756 8254
pascal@12756 8255 #ifndef __iLBC_HPOUTPUT_H
pascal@12756 8256 #define __iLBC_HPOUTPUT_H
pascal@12756 8257
pascal@12756 8258 void hpOutput(
pascal@12756 8259 float *In, /* (i) vector to filter */
pascal@12756 8260 int len,/* (i) length of vector to filter */
pascal@12756 8261 float *Out, /* (o) the resulting filtered vector */
pascal@12756 8262 float *mem /* (i/o) the filter state */
pascal@12756 8263 );
pascal@12756 8264
pascal@12756 8265 #endif
pascal@12756 8266
pascal@12756 8267 A.30. hpOutput.c
pascal@12756 8268
pascal@12756 8269 /******************************************************************
pascal@12756 8270
pascal@12756 8271 iLBC Speech Coder ANSI-C Source Code
pascal@12756 8272
pascal@12756 8273 hpOutput.c
pascal@12756 8274
pascal@12756 8275 Copyright (C) The Internet Society (2004).
pascal@12756 8276 All Rights Reserved.
pascal@12756 8277
pascal@12756 8278 ******************************************************************/
pascal@12756 8279
pascal@12756 8280 #include "constants.h"
pascal@12756 8281
pascal@12756 8282 /*----------------------------------------------------------------*
pascal@12756 8283 * Output high-pass filter
pascal@12756 8284 *---------------------------------------------------------------*/
pascal@12756 8285
pascal@12756 8286 void hpOutput(
pascal@12756 8287
pascal@12756 8288
pascal@12756 8289
pascal@12756 8290 Andersen, et al. Experimental [Page 148]
pascal@12756 8291
pascal@12756 8292 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8293
pascal@12756 8294
pascal@12756 8295 float *In, /* (i) vector to filter */
pascal@12756 8296 int len,/* (i) length of vector to filter */
pascal@12756 8297 float *Out, /* (o) the resulting filtered vector */
pascal@12756 8298 float *mem /* (i/o) the filter state */
pascal@12756 8299 ){
pascal@12756 8300 int i;
pascal@12756 8301 float *pi, *po;
pascal@12756 8302
pascal@12756 8303 /* all-zero section*/
pascal@12756 8304
pascal@12756 8305 pi = &In[0];
pascal@12756 8306 po = &Out[0];
pascal@12756 8307 for (i=0; i<len; i++) {
pascal@12756 8308 *po = hpo_zero_coefsTbl[0] * (*pi);
pascal@12756 8309 *po += hpo_zero_coefsTbl[1] * mem[0];
pascal@12756 8310 *po += hpo_zero_coefsTbl[2] * mem[1];
pascal@12756 8311
pascal@12756 8312 mem[1] = mem[0];
pascal@12756 8313 mem[0] = *pi;
pascal@12756 8314 po++;
pascal@12756 8315 pi++;
pascal@12756 8316
pascal@12756 8317 }
pascal@12756 8318
pascal@12756 8319 /* all-pole section*/
pascal@12756 8320
pascal@12756 8321 po = &Out[0];
pascal@12756 8322 for (i=0; i<len; i++) {
pascal@12756 8323 *po -= hpo_pole_coefsTbl[1] * mem[2];
pascal@12756 8324 *po -= hpo_pole_coefsTbl[2] * mem[3];
pascal@12756 8325
pascal@12756 8326 mem[3] = mem[2];
pascal@12756 8327 mem[2] = *po;
pascal@12756 8328 po++;
pascal@12756 8329 }
pascal@12756 8330 }
pascal@12756 8331
pascal@12756 8332 A.31. iCBConstruct.h
pascal@12756 8333
pascal@12756 8334 /******************************************************************
pascal@12756 8335
pascal@12756 8336 iLBC Speech Coder ANSI-C Source Code
pascal@12756 8337
pascal@12756 8338 iCBConstruct.h
pascal@12756 8339
pascal@12756 8340 Copyright (C) The Internet Society (2004).
pascal@12756 8341 All Rights Reserved.
pascal@12756 8342
pascal@12756 8343
pascal@12756 8344
pascal@12756 8345
pascal@12756 8346 Andersen, et al. Experimental [Page 149]
pascal@12756 8347
pascal@12756 8348 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8349
pascal@12756 8350
pascal@12756 8351 ******************************************************************/
pascal@12756 8352
pascal@12756 8353 #ifndef __iLBC_ICBCONSTRUCT_H
pascal@12756 8354 #define __iLBC_ICBCONSTRUCT_H
pascal@12756 8355
pascal@12756 8356 void index_conv_enc(
pascal@12756 8357 int *index /* (i/o) Codebook indexes */
pascal@12756 8358 );
pascal@12756 8359
pascal@12756 8360 void index_conv_dec(
pascal@12756 8361 int *index /* (i/o) Codebook indexes */
pascal@12756 8362 );
pascal@12756 8363
pascal@12756 8364 void iCBConstruct(
pascal@12756 8365 float *decvector, /* (o) Decoded vector */
pascal@12756 8366 int *index, /* (i) Codebook indices */
pascal@12756 8367 int *gain_index,/* (i) Gain quantization indices */
pascal@12756 8368 float *mem, /* (i) Buffer for codevector construction */
pascal@12756 8369 int lMem, /* (i) Length of buffer */
pascal@12756 8370 int veclen, /* (i) Length of vector */
pascal@12756 8371 int nStages /* (i) Number of codebook stages */
pascal@12756 8372 );
pascal@12756 8373
pascal@12756 8374 #endif
pascal@12756 8375
pascal@12756 8376 A.32. iCBConstruct.c
pascal@12756 8377
pascal@12756 8378 /******************************************************************
pascal@12756 8379
pascal@12756 8380 iLBC Speech Coder ANSI-C Source Code
pascal@12756 8381
pascal@12756 8382 iCBConstruct.c
pascal@12756 8383
pascal@12756 8384 Copyright (C) The Internet Society (2004).
pascal@12756 8385 All Rights Reserved.
pascal@12756 8386
pascal@12756 8387 ******************************************************************/
pascal@12756 8388
pascal@12756 8389 #include <math.h>
pascal@12756 8390
pascal@12756 8391 #include "iLBC_define.h"
pascal@12756 8392 #include "gainquant.h"
pascal@12756 8393 #include "getCBvec.h"
pascal@12756 8394
pascal@12756 8395 /*----------------------------------------------------------------*
pascal@12756 8396 * Convert the codebook indexes to make the search easier
pascal@12756 8397 *---------------------------------------------------------------*/
pascal@12756 8398
pascal@12756 8399
pascal@12756 8400
pascal@12756 8401
pascal@12756 8402 Andersen, et al. Experimental [Page 150]
pascal@12756 8403
pascal@12756 8404 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8405
pascal@12756 8406
pascal@12756 8407 void index_conv_enc(
pascal@12756 8408 int *index /* (i/o) Codebook indexes */
pascal@12756 8409 ){
pascal@12756 8410 int k;
pascal@12756 8411
pascal@12756 8412 for (k=1; k<CB_NSTAGES; k++) {
pascal@12756 8413
pascal@12756 8414 if ((index[k]>=108)&&(index[k]<172)) {
pascal@12756 8415 index[k]-=64;
pascal@12756 8416 } else if (index[k]>=236) {
pascal@12756 8417 index[k]-=128;
pascal@12756 8418 } else {
pascal@12756 8419 /* ERROR */
pascal@12756 8420 }
pascal@12756 8421 }
pascal@12756 8422 }
pascal@12756 8423
pascal@12756 8424 void index_conv_dec(
pascal@12756 8425 int *index /* (i/o) Codebook indexes */
pascal@12756 8426 ){
pascal@12756 8427 int k;
pascal@12756 8428
pascal@12756 8429 for (k=1; k<CB_NSTAGES; k++) {
pascal@12756 8430
pascal@12756 8431 if ((index[k]>=44)&&(index[k]<108)) {
pascal@12756 8432 index[k]+=64;
pascal@12756 8433 } else if ((index[k]>=108)&&(index[k]<128)) {
pascal@12756 8434 index[k]+=128;
pascal@12756 8435 } else {
pascal@12756 8436 /* ERROR */
pascal@12756 8437 }
pascal@12756 8438 }
pascal@12756 8439 }
pascal@12756 8440
pascal@12756 8441 /*----------------------------------------------------------------*
pascal@12756 8442 * Construct decoded vector from codebook and gains.
pascal@12756 8443 *---------------------------------------------------------------*/
pascal@12756 8444
pascal@12756 8445 void iCBConstruct(
pascal@12756 8446 float *decvector, /* (o) Decoded vector */
pascal@12756 8447 int *index, /* (i) Codebook indices */
pascal@12756 8448 int *gain_index,/* (i) Gain quantization indices */
pascal@12756 8449 float *mem, /* (i) Buffer for codevector construction */
pascal@12756 8450 int lMem, /* (i) Length of buffer */
pascal@12756 8451 int veclen, /* (i) Length of vector */
pascal@12756 8452 int nStages /* (i) Number of codebook stages */
pascal@12756 8453 ){
pascal@12756 8454 int j,k;
pascal@12756 8455
pascal@12756 8456
pascal@12756 8457
pascal@12756 8458 Andersen, et al. Experimental [Page 151]
pascal@12756 8459
pascal@12756 8460 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8461
pascal@12756 8462
pascal@12756 8463 float gain[CB_NSTAGES];
pascal@12756 8464 float cbvec[SUBL];
pascal@12756 8465
pascal@12756 8466 /* gain de-quantization */
pascal@12756 8467
pascal@12756 8468 gain[0] = gaindequant(gain_index[0], 1.0, 32);
pascal@12756 8469 if (nStages > 1) {
pascal@12756 8470 gain[1] = gaindequant(gain_index[1],
pascal@12756 8471 (float)fabs(gain[0]), 16);
pascal@12756 8472 }
pascal@12756 8473 if (nStages > 2) {
pascal@12756 8474 gain[2] = gaindequant(gain_index[2],
pascal@12756 8475 (float)fabs(gain[1]), 8);
pascal@12756 8476 }
pascal@12756 8477
pascal@12756 8478 /* codebook vector construction and construction of
pascal@12756 8479 total vector */
pascal@12756 8480
pascal@12756 8481 getCBvec(cbvec, mem, index[0], lMem, veclen);
pascal@12756 8482 for (j=0;j<veclen;j++){
pascal@12756 8483 decvector[j] = gain[0]*cbvec[j];
pascal@12756 8484 }
pascal@12756 8485 if (nStages > 1) {
pascal@12756 8486 for (k=1; k<nStages; k++) {
pascal@12756 8487 getCBvec(cbvec, mem, index[k], lMem, veclen);
pascal@12756 8488 for (j=0;j<veclen;j++) {
pascal@12756 8489 decvector[j] += gain[k]*cbvec[j];
pascal@12756 8490 }
pascal@12756 8491 }
pascal@12756 8492 }
pascal@12756 8493 }
pascal@12756 8494
pascal@12756 8495 A.33. iCBSearch.h
pascal@12756 8496
pascal@12756 8497 /******************************************************************
pascal@12756 8498
pascal@12756 8499 iLBC Speech Coder ANSI-C Source Code
pascal@12756 8500
pascal@12756 8501 iCBSearch.h
pascal@12756 8502
pascal@12756 8503 Copyright (C) The Internet Society (2004).
pascal@12756 8504 All Rights Reserved.
pascal@12756 8505
pascal@12756 8506 ******************************************************************/
pascal@12756 8507
pascal@12756 8508 #ifndef __iLBC_ICBSEARCH_H
pascal@12756 8509 #define __iLBC_ICBSEARCH_H
pascal@12756 8510
pascal@12756 8511
pascal@12756 8512
pascal@12756 8513
pascal@12756 8514 Andersen, et al. Experimental [Page 152]
pascal@12756 8515
pascal@12756 8516 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8517
pascal@12756 8518
pascal@12756 8519 void iCBSearch(
pascal@12756 8520 iLBC_Enc_Inst_t *iLBCenc_inst,
pascal@12756 8521 /* (i) the encoder state structure */
pascal@12756 8522 int *index, /* (o) Codebook indices */
pascal@12756 8523 int *gain_index,/* (o) Gain quantization indices */
pascal@12756 8524 float *intarget,/* (i) Target vector for encoding */
pascal@12756 8525 float *mem, /* (i) Buffer for codebook construction */
pascal@12756 8526 int lMem, /* (i) Length of buffer */
pascal@12756 8527 int lTarget, /* (i) Length of vector */
pascal@12756 8528 int nStages, /* (i) Number of codebook stages */
pascal@12756 8529 float *weightDenum, /* (i) weighting filter coefficients */
pascal@12756 8530 float *weightState, /* (i) weighting filter state */
pascal@12756 8531 int block /* (i) the sub-block number */
pascal@12756 8532 );
pascal@12756 8533
pascal@12756 8534 #endif
pascal@12756 8535
pascal@12756 8536 A.34. iCBSearch.c
pascal@12756 8537
pascal@12756 8538 /******************************************************************
pascal@12756 8539
pascal@12756 8540 iLBC Speech Coder ANSI-C Source Code
pascal@12756 8541
pascal@12756 8542 iCBSearch.c
pascal@12756 8543
pascal@12756 8544 Copyright (C) The Internet Society (2004).
pascal@12756 8545 All Rights Reserved.
pascal@12756 8546
pascal@12756 8547 ******************************************************************/
pascal@12756 8548
pascal@12756 8549 #include <math.h>
pascal@12756 8550 #include <string.h>
pascal@12756 8551
pascal@12756 8552 #include "iLBC_define.h"
pascal@12756 8553 #include "gainquant.h"
pascal@12756 8554 #include "createCB.h"
pascal@12756 8555 #include "filter.h"
pascal@12756 8556 #include "constants.h"
pascal@12756 8557
pascal@12756 8558 /*----------------------------------------------------------------*
pascal@12756 8559 * Search routine for codebook encoding and gain quantization.
pascal@12756 8560 *---------------------------------------------------------------*/
pascal@12756 8561
pascal@12756 8562 void iCBSearch(
pascal@12756 8563 iLBC_Enc_Inst_t *iLBCenc_inst,
pascal@12756 8564 /* (i) the encoder state structure */
pascal@12756 8565 int *index, /* (o) Codebook indices */
pascal@12756 8566 int *gain_index,/* (o) Gain quantization indices */
pascal@12756 8567
pascal@12756 8568
pascal@12756 8569
pascal@12756 8570 Andersen, et al. Experimental [Page 153]
pascal@12756 8571
pascal@12756 8572 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8573
pascal@12756 8574
pascal@12756 8575 float *intarget,/* (i) Target vector for encoding */
pascal@12756 8576 float *mem, /* (i) Buffer for codebook construction */
pascal@12756 8577 int lMem, /* (i) Length of buffer */
pascal@12756 8578 int lTarget, /* (i) Length of vector */
pascal@12756 8579 int nStages, /* (i) Number of codebook stages */
pascal@12756 8580 float *weightDenum, /* (i) weighting filter coefficients */
pascal@12756 8581 float *weightState, /* (i) weighting filter state */
pascal@12756 8582 int block /* (i) the sub-block number */
pascal@12756 8583 ){
pascal@12756 8584 int i, j, icount, stage, best_index, range, counter;
pascal@12756 8585 float max_measure, gain, measure, crossDot, ftmp;
pascal@12756 8586 float gains[CB_NSTAGES];
pascal@12756 8587 float target[SUBL];
pascal@12756 8588 int base_index, sInd, eInd, base_size;
pascal@12756 8589 int sIndAug=0, eIndAug=0;
pascal@12756 8590 float buf[CB_MEML+SUBL+2*LPC_FILTERORDER];
pascal@12756 8591 float invenergy[CB_EXPAND*128], energy[CB_EXPAND*128];
pascal@12756 8592 float *pp, *ppi=0, *ppo=0, *ppe=0;
pascal@12756 8593 float cbvectors[CB_MEML];
pascal@12756 8594 float tene, cene, cvec[SUBL];
pascal@12756 8595 float aug_vec[SUBL];
pascal@12756 8596
pascal@12756 8597 memset(cvec,0,SUBL*sizeof(float));
pascal@12756 8598
pascal@12756 8599 /* Determine size of codebook sections */
pascal@12756 8600
pascal@12756 8601 base_size=lMem-lTarget+1;
pascal@12756 8602
pascal@12756 8603 if (lTarget==SUBL) {
pascal@12756 8604 base_size=lMem-lTarget+1+lTarget/2;
pascal@12756 8605 }
pascal@12756 8606
pascal@12756 8607 /* setup buffer for weighting */
pascal@12756 8608
pascal@12756 8609 memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER);
pascal@12756 8610 memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float));
pascal@12756 8611 memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float));
pascal@12756 8612
pascal@12756 8613 /* weighting */
pascal@12756 8614
pascal@12756 8615 AllPoleFilter(buf+LPC_FILTERORDER, weightDenum,
pascal@12756 8616 lMem+lTarget, LPC_FILTERORDER);
pascal@12756 8617
pascal@12756 8618 /* Construct the codebook and target needed */
pascal@12756 8619
pascal@12756 8620 memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float));
pascal@12756 8621
pascal@12756 8622 tene=0.0;
pascal@12756 8623
pascal@12756 8624
pascal@12756 8625
pascal@12756 8626 Andersen, et al. Experimental [Page 154]
pascal@12756 8627
pascal@12756 8628 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8629
pascal@12756 8630
pascal@12756 8631 for (i=0; i<lTarget; i++) {
pascal@12756 8632 tene+=target[i]*target[i];
pascal@12756 8633 }
pascal@12756 8634
pascal@12756 8635 /* Prepare search over one more codebook section. This section
pascal@12756 8636 is created by filtering the original buffer with a filter. */
pascal@12756 8637
pascal@12756 8638 filteredCBvecs(cbvectors, buf+LPC_FILTERORDER, lMem);
pascal@12756 8639
pascal@12756 8640 /* The Main Loop over stages */
pascal@12756 8641
pascal@12756 8642 for (stage=0; stage<nStages; stage++) {
pascal@12756 8643
pascal@12756 8644 range = search_rangeTbl[block][stage];
pascal@12756 8645
pascal@12756 8646 /* initialize search measure */
pascal@12756 8647
pascal@12756 8648 max_measure = (float)-10000000.0;
pascal@12756 8649 gain = (float)0.0;
pascal@12756 8650 best_index = 0;
pascal@12756 8651
pascal@12756 8652 /* Compute cross dot product between the target
pascal@12756 8653 and the CB memory */
pascal@12756 8654
pascal@12756 8655 crossDot=0.0;
pascal@12756 8656 pp=buf+LPC_FILTERORDER+lMem-lTarget;
pascal@12756 8657 for (j=0; j<lTarget; j++) {
pascal@12756 8658 crossDot += target[j]*(*pp++);
pascal@12756 8659 }
pascal@12756 8660
pascal@12756 8661 if (stage==0) {
pascal@12756 8662
pascal@12756 8663 /* Calculate energy in the first block of
pascal@12756 8664 'lTarget' samples. */
pascal@12756 8665 ppe = energy;
pascal@12756 8666 ppi = buf+LPC_FILTERORDER+lMem-lTarget-1;
pascal@12756 8667 ppo = buf+LPC_FILTERORDER+lMem-1;
pascal@12756 8668
pascal@12756 8669 *ppe=0.0;
pascal@12756 8670 pp=buf+LPC_FILTERORDER+lMem-lTarget;
pascal@12756 8671 for (j=0; j<lTarget; j++) {
pascal@12756 8672 *ppe+=(*pp)*(*pp++);
pascal@12756 8673 }
pascal@12756 8674
pascal@12756 8675 if (*ppe>0.0) {
pascal@12756 8676 invenergy[0] = (float) 1.0 / (*ppe + EPS);
pascal@12756 8677 } else {
pascal@12756 8678 invenergy[0] = (float) 0.0;
pascal@12756 8679
pascal@12756 8680
pascal@12756 8681
pascal@12756 8682 Andersen, et al. Experimental [Page 155]
pascal@12756 8683
pascal@12756 8684 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8685
pascal@12756 8686
pascal@12756 8687 }
pascal@12756 8688 ppe++;
pascal@12756 8689
pascal@12756 8690 measure=(float)-10000000.0;
pascal@12756 8691
pascal@12756 8692 if (crossDot > 0.0) {
pascal@12756 8693 measure = crossDot*crossDot*invenergy[0];
pascal@12756 8694 }
pascal@12756 8695 }
pascal@12756 8696 else {
pascal@12756 8697 measure = crossDot*crossDot*invenergy[0];
pascal@12756 8698 }
pascal@12756 8699
pascal@12756 8700 /* check if measure is better */
pascal@12756 8701 ftmp = crossDot*invenergy[0];
pascal@12756 8702
pascal@12756 8703 if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
pascal@12756 8704 best_index = 0;
pascal@12756 8705 max_measure = measure;
pascal@12756 8706 gain = ftmp;
pascal@12756 8707 }
pascal@12756 8708
pascal@12756 8709 /* loop over the main first codebook section,
pascal@12756 8710 full search */
pascal@12756 8711
pascal@12756 8712 for (icount=1; icount<range; icount++) {
pascal@12756 8713
pascal@12756 8714 /* calculate measure */
pascal@12756 8715
pascal@12756 8716 crossDot=0.0;
pascal@12756 8717 pp = buf+LPC_FILTERORDER+lMem-lTarget-icount;
pascal@12756 8718
pascal@12756 8719 for (j=0; j<lTarget; j++) {
pascal@12756 8720 crossDot += target[j]*(*pp++);
pascal@12756 8721 }
pascal@12756 8722
pascal@12756 8723 if (stage==0) {
pascal@12756 8724 *ppe++ = energy[icount-1] + (*ppi)*(*ppi) -
pascal@12756 8725 (*ppo)*(*ppo);
pascal@12756 8726 ppo--;
pascal@12756 8727 ppi--;
pascal@12756 8728
pascal@12756 8729 if (energy[icount]>0.0) {
pascal@12756 8730 invenergy[icount] =
pascal@12756 8731 (float)1.0/(energy[icount]+EPS);
pascal@12756 8732 } else {
pascal@12756 8733 invenergy[icount] = (float) 0.0;
pascal@12756 8734 }
pascal@12756 8735
pascal@12756 8736
pascal@12756 8737
pascal@12756 8738 Andersen, et al. Experimental [Page 156]
pascal@12756 8739
pascal@12756 8740 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8741
pascal@12756 8742
pascal@12756 8743 measure=(float)-10000000.0;
pascal@12756 8744
pascal@12756 8745 if (crossDot > 0.0) {
pascal@12756 8746 measure = crossDot*crossDot*invenergy[icount];
pascal@12756 8747 }
pascal@12756 8748 }
pascal@12756 8749 else {
pascal@12756 8750 measure = crossDot*crossDot*invenergy[icount];
pascal@12756 8751 }
pascal@12756 8752
pascal@12756 8753 /* check if measure is better */
pascal@12756 8754 ftmp = crossDot*invenergy[icount];
pascal@12756 8755
pascal@12756 8756 if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
pascal@12756 8757 best_index = icount;
pascal@12756 8758 max_measure = measure;
pascal@12756 8759 gain = ftmp;
pascal@12756 8760 }
pascal@12756 8761 }
pascal@12756 8762
pascal@12756 8763 /* Loop over augmented part in the first codebook
pascal@12756 8764 * section, full search.
pascal@12756 8765 * The vectors are interpolated.
pascal@12756 8766 */
pascal@12756 8767
pascal@12756 8768 if (lTarget==SUBL) {
pascal@12756 8769
pascal@12756 8770 /* Search for best possible cb vector and
pascal@12756 8771 compute the CB-vectors' energy. */
pascal@12756 8772 searchAugmentedCB(20, 39, stage, base_size-lTarget/2,
pascal@12756 8773 target, buf+LPC_FILTERORDER+lMem,
pascal@12756 8774 &max_measure, &best_index, &gain, energy,
pascal@12756 8775 invenergy);
pascal@12756 8776 }
pascal@12756 8777
pascal@12756 8778 /* set search range for following codebook sections */
pascal@12756 8779
pascal@12756 8780 base_index=best_index;
pascal@12756 8781
pascal@12756 8782 /* unrestricted search */
pascal@12756 8783
pascal@12756 8784 if (CB_RESRANGE == -1) {
pascal@12756 8785 sInd=0;
pascal@12756 8786 eInd=range-1;
pascal@12756 8787 sIndAug=20;
pascal@12756 8788 eIndAug=39;
pascal@12756 8789 }
pascal@12756 8790
pascal@12756 8791
pascal@12756 8792
pascal@12756 8793
pascal@12756 8794 Andersen, et al. Experimental [Page 157]
pascal@12756 8795
pascal@12756 8796 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8797
pascal@12756 8798
pascal@12756 8799 /* restricted search around best index from first
pascal@12756 8800 codebook section */
pascal@12756 8801
pascal@12756 8802 else {
pascal@12756 8803 /* Initialize search indices */
pascal@12756 8804 sIndAug=0;
pascal@12756 8805 eIndAug=0;
pascal@12756 8806 sInd=base_index-CB_RESRANGE/2;
pascal@12756 8807 eInd=sInd+CB_RESRANGE;
pascal@12756 8808
pascal@12756 8809 if (lTarget==SUBL) {
pascal@12756 8810
pascal@12756 8811 if (sInd<0) {
pascal@12756 8812
pascal@12756 8813 sIndAug = 40 + sInd;
pascal@12756 8814 eIndAug = 39;
pascal@12756 8815 sInd=0;
pascal@12756 8816
pascal@12756 8817 } else if ( base_index < (base_size-20) ) {
pascal@12756 8818
pascal@12756 8819 if (eInd > range) {
pascal@12756 8820 sInd -= (eInd-range);
pascal@12756 8821 eInd = range;
pascal@12756 8822 }
pascal@12756 8823 } else { /* base_index >= (base_size-20) */
pascal@12756 8824
pascal@12756 8825 if (sInd < (base_size-20)) {
pascal@12756 8826 sIndAug = 20;
pascal@12756 8827 sInd = 0;
pascal@12756 8828 eInd = 0;
pascal@12756 8829 eIndAug = 19 + CB_RESRANGE;
pascal@12756 8830
pascal@12756 8831 if(eIndAug > 39) {
pascal@12756 8832 eInd = eIndAug-39;
pascal@12756 8833 eIndAug = 39;
pascal@12756 8834 }
pascal@12756 8835 } else {
pascal@12756 8836 sIndAug = 20 + sInd - (base_size-20);
pascal@12756 8837 eIndAug = 39;
pascal@12756 8838 sInd = 0;
pascal@12756 8839 eInd = CB_RESRANGE - (eIndAug-sIndAug+1);
pascal@12756 8840 }
pascal@12756 8841 }
pascal@12756 8842
pascal@12756 8843 } else { /* lTarget = 22 or 23 */
pascal@12756 8844
pascal@12756 8845 if (sInd < 0) {
pascal@12756 8846 eInd -= sInd;
pascal@12756 8847
pascal@12756 8848
pascal@12756 8849
pascal@12756 8850 Andersen, et al. Experimental [Page 158]
pascal@12756 8851
pascal@12756 8852 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8853
pascal@12756 8854
pascal@12756 8855 sInd = 0;
pascal@12756 8856 }
pascal@12756 8857
pascal@12756 8858 if(eInd > range) {
pascal@12756 8859 sInd -= (eInd - range);
pascal@12756 8860 eInd = range;
pascal@12756 8861 }
pascal@12756 8862 }
pascal@12756 8863 }
pascal@12756 8864
pascal@12756 8865 /* search of higher codebook section */
pascal@12756 8866
pascal@12756 8867 /* index search range */
pascal@12756 8868 counter = sInd;
pascal@12756 8869 sInd += base_size;
pascal@12756 8870 eInd += base_size;
pascal@12756 8871
pascal@12756 8872
pascal@12756 8873 if (stage==0) {
pascal@12756 8874 ppe = energy+base_size;
pascal@12756 8875 *ppe=0.0;
pascal@12756 8876
pascal@12756 8877 pp=cbvectors+lMem-lTarget;
pascal@12756 8878 for (j=0; j<lTarget; j++) {
pascal@12756 8879 *ppe+=(*pp)*(*pp++);
pascal@12756 8880 }
pascal@12756 8881
pascal@12756 8882 ppi = cbvectors + lMem - 1 - lTarget;
pascal@12756 8883 ppo = cbvectors + lMem - 1;
pascal@12756 8884
pascal@12756 8885 for (j=0; j<(range-1); j++) {
pascal@12756 8886 *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo);
pascal@12756 8887 ppo--;
pascal@12756 8888 ppi--;
pascal@12756 8889 ppe++;
pascal@12756 8890 }
pascal@12756 8891 }
pascal@12756 8892
pascal@12756 8893 /* loop over search range */
pascal@12756 8894
pascal@12756 8895 for (icount=sInd; icount<eInd; icount++) {
pascal@12756 8896
pascal@12756 8897 /* calculate measure */
pascal@12756 8898
pascal@12756 8899 crossDot=0.0;
pascal@12756 8900 pp=cbvectors + lMem - (counter++) - lTarget;
pascal@12756 8901
pascal@12756 8902 for (j=0;j<lTarget;j++) {
pascal@12756 8903
pascal@12756 8904
pascal@12756 8905
pascal@12756 8906 Andersen, et al. Experimental [Page 159]
pascal@12756 8907
pascal@12756 8908 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8909
pascal@12756 8910
pascal@12756 8911 crossDot += target[j]*(*pp++);
pascal@12756 8912 }
pascal@12756 8913
pascal@12756 8914 if (energy[icount]>0.0) {
pascal@12756 8915 invenergy[icount] =(float)1.0/(energy[icount]+EPS);
pascal@12756 8916 } else {
pascal@12756 8917 invenergy[icount] =(float)0.0;
pascal@12756 8918 }
pascal@12756 8919
pascal@12756 8920 if (stage==0) {
pascal@12756 8921
pascal@12756 8922 measure=(float)-10000000.0;
pascal@12756 8923
pascal@12756 8924 if (crossDot > 0.0) {
pascal@12756 8925 measure = crossDot*crossDot*
pascal@12756 8926 invenergy[icount];
pascal@12756 8927 }
pascal@12756 8928 }
pascal@12756 8929 else {
pascal@12756 8930 measure = crossDot*crossDot*invenergy[icount];
pascal@12756 8931 }
pascal@12756 8932
pascal@12756 8933 /* check if measure is better */
pascal@12756 8934 ftmp = crossDot*invenergy[icount];
pascal@12756 8935
pascal@12756 8936 if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
pascal@12756 8937 best_index = icount;
pascal@12756 8938 max_measure = measure;
pascal@12756 8939 gain = ftmp;
pascal@12756 8940 }
pascal@12756 8941 }
pascal@12756 8942
pascal@12756 8943 /* Search the augmented CB inside the limited range. */
pascal@12756 8944
pascal@12756 8945 if ((lTarget==SUBL)&&(sIndAug!=0)) {
pascal@12756 8946 searchAugmentedCB(sIndAug, eIndAug, stage,
pascal@12756 8947 2*base_size-20, target, cbvectors+lMem,
pascal@12756 8948 &max_measure, &best_index, &gain, energy,
pascal@12756 8949 invenergy);
pascal@12756 8950 }
pascal@12756 8951
pascal@12756 8952 /* record best index */
pascal@12756 8953
pascal@12756 8954 index[stage] = best_index;
pascal@12756 8955
pascal@12756 8956 /* gain quantization */
pascal@12756 8957
pascal@12756 8958 if (stage==0){
pascal@12756 8959
pascal@12756 8960
pascal@12756 8961
pascal@12756 8962 Andersen, et al. Experimental [Page 160]
pascal@12756 8963
pascal@12756 8964 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 8965
pascal@12756 8966
pascal@12756 8967
pascal@12756 8968 if (gain<0.0){
pascal@12756 8969 gain = 0.0;
pascal@12756 8970 }
pascal@12756 8971
pascal@12756 8972 if (gain>CB_MAXGAIN) {
pascal@12756 8973 gain = (float)CB_MAXGAIN;
pascal@12756 8974 }
pascal@12756 8975 gain = gainquant(gain, 1.0, 32, &gain_index[stage]);
pascal@12756 8976 }
pascal@12756 8977 else {
pascal@12756 8978 if (stage==1) {
pascal@12756 8979 gain = gainquant(gain, (float)fabs(gains[stage-1]),
pascal@12756 8980 16, &gain_index[stage]);
pascal@12756 8981 } else {
pascal@12756 8982 gain = gainquant(gain, (float)fabs(gains[stage-1]),
pascal@12756 8983 8, &gain_index[stage]);
pascal@12756 8984 }
pascal@12756 8985 }
pascal@12756 8986
pascal@12756 8987 /* Extract the best (according to measure)
pascal@12756 8988 codebook vector */
pascal@12756 8989
pascal@12756 8990 if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) {
pascal@12756 8991
pascal@12756 8992 if (index[stage]<base_size) {
pascal@12756 8993 pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage];
pascal@12756 8994 } else {
pascal@12756 8995 pp=cbvectors+lMem-lTarget-
pascal@12756 8996 index[stage]+base_size;
pascal@12756 8997 }
pascal@12756 8998 } else {
pascal@12756 8999
pascal@12756 9000 if (index[stage]<base_size) {
pascal@12756 9001 if (index[stage]<(base_size-20)) {
pascal@12756 9002 pp=buf+LPC_FILTERORDER+lMem-
pascal@12756 9003 lTarget-index[stage];
pascal@12756 9004 } else {
pascal@12756 9005 createAugmentedVec(index[stage]-base_size+40,
pascal@12756 9006 buf+LPC_FILTERORDER+lMem,aug_vec);
pascal@12756 9007 pp=aug_vec;
pascal@12756 9008 }
pascal@12756 9009 } else {
pascal@12756 9010 int filterno, position;
pascal@12756 9011
pascal@12756 9012 filterno=index[stage]/base_size;
pascal@12756 9013 position=index[stage]-filterno*base_size;
pascal@12756 9014
pascal@12756 9015
pascal@12756 9016
pascal@12756 9017
pascal@12756 9018 Andersen, et al. Experimental [Page 161]
pascal@12756 9019
pascal@12756 9020 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9021
pascal@12756 9022
pascal@12756 9023
pascal@12756 9024 if (position<(base_size-20)) {
pascal@12756 9025 pp=cbvectors+filterno*lMem-lTarget-
pascal@12756 9026 index[stage]+filterno*base_size;
pascal@12756 9027 } else {
pascal@12756 9028 createAugmentedVec(
pascal@12756 9029 index[stage]-(filterno+1)*base_size+40,
pascal@12756 9030 cbvectors+filterno*lMem,aug_vec);
pascal@12756 9031 pp=aug_vec;
pascal@12756 9032 }
pascal@12756 9033 }
pascal@12756 9034 }
pascal@12756 9035
pascal@12756 9036 /* Subtract the best codebook vector, according
pascal@12756 9037 to measure, from the target vector */
pascal@12756 9038
pascal@12756 9039 for (j=0;j<lTarget;j++) {
pascal@12756 9040 cvec[j] += gain*(*pp);
pascal@12756 9041 target[j] -= gain*(*pp++);
pascal@12756 9042 }
pascal@12756 9043
pascal@12756 9044 /* record quantized gain */
pascal@12756 9045
pascal@12756 9046 gains[stage]=gain;
pascal@12756 9047
pascal@12756 9048 }/* end of Main Loop. for (stage=0;... */
pascal@12756 9049
pascal@12756 9050 /* Gain adjustment for energy matching */
pascal@12756 9051 cene=0.0;
pascal@12756 9052 for (i=0; i<lTarget; i++) {
pascal@12756 9053 cene+=cvec[i]*cvec[i];
pascal@12756 9054 }
pascal@12756 9055 j=gain_index[0];
pascal@12756 9056
pascal@12756 9057 for (i=gain_index[0]; i<32; i++) {
pascal@12756 9058 ftmp=cene*gain_sq5Tbl[i]*gain_sq5Tbl[i];
pascal@12756 9059
pascal@12756 9060 if ((ftmp<(tene*gains[0]*gains[0])) &&
pascal@12756 9061 (gain_sq5Tbl[j]<(2.0*gains[0]))) {
pascal@12756 9062 j=i;
pascal@12756 9063 }
pascal@12756 9064 }
pascal@12756 9065 gain_index[0]=j;
pascal@12756 9066 }
pascal@12756 9067
pascal@12756 9068
pascal@12756 9069
pascal@12756 9070
pascal@12756 9071
pascal@12756 9072
pascal@12756 9073
pascal@12756 9074 Andersen, et al. Experimental [Page 162]
pascal@12756 9075
pascal@12756 9076 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9077
pascal@12756 9078
pascal@12756 9079 A.35. LPCdecode.h
pascal@12756 9080
pascal@12756 9081 /******************************************************************
pascal@12756 9082
pascal@12756 9083 iLBC Speech Coder ANSI-C Source Code
pascal@12756 9084
pascal@12756 9085 LPC_decode.h
pascal@12756 9086
pascal@12756 9087 Copyright (C) The Internet Society (2004).
pascal@12756 9088 All Rights Reserved.
pascal@12756 9089
pascal@12756 9090 ******************************************************************/
pascal@12756 9091
pascal@12756 9092 #ifndef __iLBC_LPC_DECODE_H
pascal@12756 9093 #define __iLBC_LPC_DECODE_H
pascal@12756 9094
pascal@12756 9095 void LSFinterpolate2a_dec(
pascal@12756 9096 float *a, /* (o) lpc coefficients for a sub-frame */
pascal@12756 9097 float *lsf1, /* (i) first lsf coefficient vector */
pascal@12756 9098 float *lsf2, /* (i) second lsf coefficient vector */
pascal@12756 9099 float coef, /* (i) interpolation weight */
pascal@12756 9100 int length /* (i) length of lsf vectors */
pascal@12756 9101 );
pascal@12756 9102
pascal@12756 9103 void SimplelsfDEQ(
pascal@12756 9104 float *lsfdeq, /* (o) dequantized lsf coefficients */
pascal@12756 9105 int *index, /* (i) quantization index */
pascal@12756 9106 int lpc_n /* (i) number of LPCs */
pascal@12756 9107 );
pascal@12756 9108
pascal@12756 9109 void DecoderInterpolateLSF(
pascal@12756 9110 float *syntdenum, /* (o) synthesis filter coefficients */
pascal@12756 9111 float *weightdenum, /* (o) weighting denumerator
pascal@12756 9112 coefficients */
pascal@12756 9113 float *lsfdeq, /* (i) dequantized lsf coefficients */
pascal@12756 9114 int length, /* (i) length of lsf coefficient vector */
pascal@12756 9115 iLBC_Dec_Inst_t *iLBCdec_inst
pascal@12756 9116 /* (i) the decoder state structure */
pascal@12756 9117 );
pascal@12756 9118
pascal@12756 9119 #endif
pascal@12756 9120
pascal@12756 9121
pascal@12756 9122
pascal@12756 9123
pascal@12756 9124
pascal@12756 9125
pascal@12756 9126
pascal@12756 9127
pascal@12756 9128
pascal@12756 9129
pascal@12756 9130 Andersen, et al. Experimental [Page 163]
pascal@12756 9131
pascal@12756 9132 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9133
pascal@12756 9134
pascal@12756 9135 A.36. LPCdecode.c
pascal@12756 9136
pascal@12756 9137 /******************************************************************
pascal@12756 9138
pascal@12756 9139 iLBC Speech Coder ANSI-C Source Code
pascal@12756 9140
pascal@12756 9141 LPC_decode.c
pascal@12756 9142
pascal@12756 9143 Copyright (C) The Internet Society (2004).
pascal@12756 9144 All Rights Reserved.
pascal@12756 9145
pascal@12756 9146 ******************************************************************/
pascal@12756 9147
pascal@12756 9148 #include <math.h>
pascal@12756 9149 #include <string.h>
pascal@12756 9150
pascal@12756 9151 #include "helpfun.h"
pascal@12756 9152 #include "lsf.h"
pascal@12756 9153 #include "iLBC_define.h"
pascal@12756 9154 #include "constants.h"
pascal@12756 9155
pascal@12756 9156 /*---------------------------------------------------------------*
pascal@12756 9157 * interpolation of lsf coefficients for the decoder
pascal@12756 9158 *--------------------------------------------------------------*/
pascal@12756 9159
pascal@12756 9160 void LSFinterpolate2a_dec(
pascal@12756 9161 float *a, /* (o) lpc coefficients for a sub-frame */
pascal@12756 9162 float *lsf1, /* (i) first lsf coefficient vector */
pascal@12756 9163 float *lsf2, /* (i) second lsf coefficient vector */
pascal@12756 9164 float coef, /* (i) interpolation weight */
pascal@12756 9165 int length /* (i) length of lsf vectors */
pascal@12756 9166 ){
pascal@12756 9167 float lsftmp[LPC_FILTERORDER];
pascal@12756 9168
pascal@12756 9169 interpolate(lsftmp, lsf1, lsf2, coef, length);
pascal@12756 9170 lsf2a(a, lsftmp);
pascal@12756 9171 }
pascal@12756 9172
pascal@12756 9173 /*---------------------------------------------------------------*
pascal@12756 9174 * obtain dequantized lsf coefficients from quantization index
pascal@12756 9175 *--------------------------------------------------------------*/
pascal@12756 9176
pascal@12756 9177 void SimplelsfDEQ(
pascal@12756 9178 float *lsfdeq, /* (o) dequantized lsf coefficients */
pascal@12756 9179 int *index, /* (i) quantization index */
pascal@12756 9180 int lpc_n /* (i) number of LPCs */
pascal@12756 9181 ){
pascal@12756 9182 int i, j, pos, cb_pos;
pascal@12756 9183
pascal@12756 9184
pascal@12756 9185
pascal@12756 9186 Andersen, et al. Experimental [Page 164]
pascal@12756 9187
pascal@12756 9188 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9189
pascal@12756 9190
pascal@12756 9191 /* decode first LSF */
pascal@12756 9192
pascal@12756 9193 pos = 0;
pascal@12756 9194 cb_pos = 0;
pascal@12756 9195 for (i = 0; i < LSF_NSPLIT; i++) {
pascal@12756 9196 for (j = 0; j < dim_lsfCbTbl[i]; j++) {
pascal@12756 9197 lsfdeq[pos + j] = lsfCbTbl[cb_pos +
pascal@12756 9198 (long)(index[i])*dim_lsfCbTbl[i] + j];
pascal@12756 9199 }
pascal@12756 9200 pos += dim_lsfCbTbl[i];
pascal@12756 9201 cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
pascal@12756 9202 }
pascal@12756 9203
pascal@12756 9204 if (lpc_n>1) {
pascal@12756 9205
pascal@12756 9206 /* decode last LSF */
pascal@12756 9207
pascal@12756 9208 pos = 0;
pascal@12756 9209 cb_pos = 0;
pascal@12756 9210 for (i = 0; i < LSF_NSPLIT; i++) {
pascal@12756 9211 for (j = 0; j < dim_lsfCbTbl[i]; j++) {
pascal@12756 9212 lsfdeq[LPC_FILTERORDER + pos + j] =
pascal@12756 9213 lsfCbTbl[cb_pos +
pascal@12756 9214 (long)(index[LSF_NSPLIT + i])*
pascal@12756 9215 dim_lsfCbTbl[i] + j];
pascal@12756 9216 }
pascal@12756 9217 pos += dim_lsfCbTbl[i];
pascal@12756 9218 cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
pascal@12756 9219 }
pascal@12756 9220 }
pascal@12756 9221 }
pascal@12756 9222
pascal@12756 9223 /*----------------------------------------------------------------*
pascal@12756 9224 * obtain synthesis and weighting filters form lsf coefficients
pascal@12756 9225 *---------------------------------------------------------------*/
pascal@12756 9226
pascal@12756 9227 void DecoderInterpolateLSF(
pascal@12756 9228 float *syntdenum, /* (o) synthesis filter coefficients */
pascal@12756 9229 float *weightdenum, /* (o) weighting denumerator
pascal@12756 9230 coefficients */
pascal@12756 9231 float *lsfdeq, /* (i) dequantized lsf coefficients */
pascal@12756 9232 int length, /* (i) length of lsf coefficient vector */
pascal@12756 9233 iLBC_Dec_Inst_t *iLBCdec_inst
pascal@12756 9234 /* (i) the decoder state structure */
pascal@12756 9235 ){
pascal@12756 9236 int i, pos, lp_length;
pascal@12756 9237 float lp[LPC_FILTERORDER + 1], *lsfdeq2;
pascal@12756 9238
pascal@12756 9239
pascal@12756 9240
pascal@12756 9241
pascal@12756 9242 Andersen, et al. Experimental [Page 165]
pascal@12756 9243
pascal@12756 9244 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9245
pascal@12756 9246
pascal@12756 9247 lsfdeq2 = lsfdeq + length;
pascal@12756 9248 lp_length = length + 1;
pascal@12756 9249
pascal@12756 9250 if (iLBCdec_inst->mode==30) {
pascal@12756 9251 /* sub-frame 1: Interpolation between old and first */
pascal@12756 9252
pascal@12756 9253 LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq,
pascal@12756 9254 lsf_weightTbl_30ms[0], length);
pascal@12756 9255 memcpy(syntdenum,lp,lp_length*sizeof(float));
pascal@12756 9256 bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM,
pascal@12756 9257 lp_length);
pascal@12756 9258
pascal@12756 9259 /* sub-frames 2 to 6: interpolation between first
pascal@12756 9260 and last LSF */
pascal@12756 9261
pascal@12756 9262 pos = lp_length;
pascal@12756 9263 for (i = 1; i < 6; i++) {
pascal@12756 9264 LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2,
pascal@12756 9265 lsf_weightTbl_30ms[i], length);
pascal@12756 9266 memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
pascal@12756 9267 bwexpand(weightdenum + pos, lp,
pascal@12756 9268 LPC_CHIRP_WEIGHTDENUM, lp_length);
pascal@12756 9269 pos += lp_length;
pascal@12756 9270 }
pascal@12756 9271 }
pascal@12756 9272 else {
pascal@12756 9273 pos = 0;
pascal@12756 9274 for (i = 0; i < iLBCdec_inst->nsub; i++) {
pascal@12756 9275 LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold,
pascal@12756 9276 lsfdeq, lsf_weightTbl_20ms[i], length);
pascal@12756 9277 memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
pascal@12756 9278 bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM,
pascal@12756 9279 lp_length);
pascal@12756 9280 pos += lp_length;
pascal@12756 9281 }
pascal@12756 9282 }
pascal@12756 9283
pascal@12756 9284 /* update memory */
pascal@12756 9285
pascal@12756 9286 if (iLBCdec_inst->mode==30)
pascal@12756 9287 memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2,
pascal@12756 9288 length*sizeof(float));
pascal@12756 9289 else
pascal@12756 9290 memcpy(iLBCdec_inst->lsfdeqold, lsfdeq,
pascal@12756 9291 length*sizeof(float));
pascal@12756 9292
pascal@12756 9293 }
pascal@12756 9294
pascal@12756 9295
pascal@12756 9296
pascal@12756 9297
pascal@12756 9298 Andersen, et al. Experimental [Page 166]
pascal@12756 9299
pascal@12756 9300 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9301
pascal@12756 9302
pascal@12756 9303 A.37. LPCencode.h
pascal@12756 9304
pascal@12756 9305 /******************************************************************
pascal@12756 9306
pascal@12756 9307 iLBC Speech Coder ANSI-C Source Code
pascal@12756 9308
pascal@12756 9309 LPCencode.h
pascal@12756 9310
pascal@12756 9311 Copyright (C) The Internet Society (2004).
pascal@12756 9312 All Rights Reserved.
pascal@12756 9313
pascal@12756 9314 ******************************************************************/
pascal@12756 9315
pascal@12756 9316 #ifndef __iLBC_LPCENCOD_H
pascal@12756 9317 #define __iLBC_LPCENCOD_H
pascal@12756 9318
pascal@12756 9319 void LPCencode(
pascal@12756 9320 float *syntdenum, /* (i/o) synthesis filter coefficients
pascal@12756 9321 before/after encoding */
pascal@12756 9322 float *weightdenum, /* (i/o) weighting denumerator coefficients
pascal@12756 9323 before/after encoding */
pascal@12756 9324 int *lsf_index, /* (o) lsf quantization index */
pascal@12756 9325 float *data, /* (i) lsf coefficients to quantize */
pascal@12756 9326 iLBC_Enc_Inst_t *iLBCenc_inst
pascal@12756 9327 /* (i/o) the encoder state structure */
pascal@12756 9328 );
pascal@12756 9329
pascal@12756 9330 #endif
pascal@12756 9331
pascal@12756 9332 A.38. LPCencode.c
pascal@12756 9333
pascal@12756 9334 /******************************************************************
pascal@12756 9335
pascal@12756 9336 iLBC Speech Coder ANSI-C Source Code
pascal@12756 9337
pascal@12756 9338 LPCencode.c
pascal@12756 9339
pascal@12756 9340 Copyright (C) The Internet Society (2004).
pascal@12756 9341 All Rights Reserved.
pascal@12756 9342
pascal@12756 9343 ******************************************************************/
pascal@12756 9344
pascal@12756 9345 #include <string.h>
pascal@12756 9346
pascal@12756 9347 #include "iLBC_define.h"
pascal@12756 9348 #include "helpfun.h"
pascal@12756 9349 #include "lsf.h"
pascal@12756 9350 #include "constants.h"
pascal@12756 9351
pascal@12756 9352
pascal@12756 9353
pascal@12756 9354 Andersen, et al. Experimental [Page 167]
pascal@12756 9355
pascal@12756 9356 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9357
pascal@12756 9358
pascal@12756 9359 /*----------------------------------------------------------------*
pascal@12756 9360 * lpc analysis (subrutine to LPCencode)
pascal@12756 9361 *---------------------------------------------------------------*/
pascal@12756 9362
pascal@12756 9363 void SimpleAnalysis(
pascal@12756 9364 float *lsf, /* (o) lsf coefficients */
pascal@12756 9365 float *data, /* (i) new data vector */
pascal@12756 9366 iLBC_Enc_Inst_t *iLBCenc_inst
pascal@12756 9367 /* (i/o) the encoder state structure */
pascal@12756 9368 ){
pascal@12756 9369 int k, is;
pascal@12756 9370 float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1];
pascal@12756 9371 float lp2[LPC_FILTERORDER + 1];
pascal@12756 9372 float r[LPC_FILTERORDER + 1];
pascal@12756 9373
pascal@12756 9374 is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;
pascal@12756 9375 memcpy(iLBCenc_inst->lpc_buffer+is,data,
pascal@12756 9376 iLBCenc_inst->blockl*sizeof(float));
pascal@12756 9377
pascal@12756 9378 /* No lookahead, last window is asymmetric */
pascal@12756 9379
pascal@12756 9380 for (k = 0; k < iLBCenc_inst->lpc_n; k++) {
pascal@12756 9381
pascal@12756 9382 is = LPC_LOOKBACK;
pascal@12756 9383
pascal@12756 9384 if (k < (iLBCenc_inst->lpc_n - 1)) {
pascal@12756 9385 window(temp, lpc_winTbl,
pascal@12756 9386 iLBCenc_inst->lpc_buffer, BLOCKL_MAX);
pascal@12756 9387 } else {
pascal@12756 9388 window(temp, lpc_asymwinTbl,
pascal@12756 9389 iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX);
pascal@12756 9390 }
pascal@12756 9391
pascal@12756 9392 autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER);
pascal@12756 9393 window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1);
pascal@12756 9394
pascal@12756 9395 levdurb(lp, temp, r, LPC_FILTERORDER);
pascal@12756 9396 bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1);
pascal@12756 9397
pascal@12756 9398 a2lsf(lsf + k*LPC_FILTERORDER, lp2);
pascal@12756 9399 }
pascal@12756 9400 is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;
pascal@12756 9401 memmove(iLBCenc_inst->lpc_buffer,
pascal@12756 9402 iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is,
pascal@12756 9403 is*sizeof(float));
pascal@12756 9404 }
pascal@12756 9405
pascal@12756 9406 /*----------------------------------------------------------------*
pascal@12756 9407
pascal@12756 9408
pascal@12756 9409
pascal@12756 9410 Andersen, et al. Experimental [Page 168]
pascal@12756 9411
pascal@12756 9412 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9413
pascal@12756 9414
pascal@12756 9415 * lsf interpolator and conversion from lsf to a coefficients
pascal@12756 9416 * (subrutine to SimpleInterpolateLSF)
pascal@12756 9417 *---------------------------------------------------------------*/
pascal@12756 9418
pascal@12756 9419 void LSFinterpolate2a_enc(
pascal@12756 9420 float *a, /* (o) lpc coefficients */
pascal@12756 9421 float *lsf1,/* (i) first set of lsf coefficients */
pascal@12756 9422 float *lsf2,/* (i) second set of lsf coefficients */
pascal@12756 9423 float coef, /* (i) weighting coefficient to use between
pascal@12756 9424 lsf1 and lsf2 */
pascal@12756 9425 long length /* (i) length of coefficient vectors */
pascal@12756 9426 ){
pascal@12756 9427 float lsftmp[LPC_FILTERORDER];
pascal@12756 9428
pascal@12756 9429 interpolate(lsftmp, lsf1, lsf2, coef, length);
pascal@12756 9430 lsf2a(a, lsftmp);
pascal@12756 9431 }
pascal@12756 9432
pascal@12756 9433 /*----------------------------------------------------------------*
pascal@12756 9434 * lsf interpolator (subrutine to LPCencode)
pascal@12756 9435 *---------------------------------------------------------------*/
pascal@12756 9436
pascal@12756 9437 void SimpleInterpolateLSF(
pascal@12756 9438 float *syntdenum, /* (o) the synthesis filter denominator
pascal@12756 9439 resulting from the quantized
pascal@12756 9440 interpolated lsf */
pascal@12756 9441 float *weightdenum, /* (o) the weighting filter denominator
pascal@12756 9442 resulting from the unquantized
pascal@12756 9443 interpolated lsf */
pascal@12756 9444 float *lsf, /* (i) the unquantized lsf coefficients */
pascal@12756 9445 float *lsfdeq, /* (i) the dequantized lsf coefficients */
pascal@12756 9446 float *lsfold, /* (i) the unquantized lsf coefficients of
pascal@12756 9447 the previous signal frame */
pascal@12756 9448 float *lsfdeqold, /* (i) the dequantized lsf coefficients of
pascal@12756 9449 the previous signal frame */
pascal@12756 9450 int length, /* (i) should equate LPC_FILTERORDER */
pascal@12756 9451 iLBC_Enc_Inst_t *iLBCenc_inst
pascal@12756 9452 /* (i/o) the encoder state structure */
pascal@12756 9453 ){
pascal@12756 9454 int i, pos, lp_length;
pascal@12756 9455 float lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2;
pascal@12756 9456
pascal@12756 9457 lsf2 = lsf + length;
pascal@12756 9458 lsfdeq2 = lsfdeq + length;
pascal@12756 9459 lp_length = length + 1;
pascal@12756 9460
pascal@12756 9461 if (iLBCenc_inst->mode==30) {
pascal@12756 9462 /* sub-frame 1: Interpolation between old and first
pascal@12756 9463
pascal@12756 9464
pascal@12756 9465
pascal@12756 9466 Andersen, et al. Experimental [Page 169]
pascal@12756 9467
pascal@12756 9468 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9469
pascal@12756 9470
pascal@12756 9471 set of lsf coefficients */
pascal@12756 9472
pascal@12756 9473 LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq,
pascal@12756 9474 lsf_weightTbl_30ms[0], length);
pascal@12756 9475 memcpy(syntdenum,lp,lp_length*sizeof(float));
pascal@12756 9476 LSFinterpolate2a_enc(lp, lsfold, lsf,
pascal@12756 9477 lsf_weightTbl_30ms[0], length);
pascal@12756 9478 bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);
pascal@12756 9479
pascal@12756 9480 /* sub-frame 2 to 6: Interpolation between first
pascal@12756 9481 and second set of lsf coefficients */
pascal@12756 9482
pascal@12756 9483 pos = lp_length;
pascal@12756 9484 for (i = 1; i < iLBCenc_inst->nsub; i++) {
pascal@12756 9485 LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2,
pascal@12756 9486 lsf_weightTbl_30ms[i], length);
pascal@12756 9487 memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
pascal@12756 9488
pascal@12756 9489 LSFinterpolate2a_enc(lp, lsf, lsf2,
pascal@12756 9490 lsf_weightTbl_30ms[i], length);
pascal@12756 9491 bwexpand(weightdenum + pos, lp,
pascal@12756 9492 LPC_CHIRP_WEIGHTDENUM, lp_length);
pascal@12756 9493 pos += lp_length;
pascal@12756 9494 }
pascal@12756 9495 }
pascal@12756 9496 else {
pascal@12756 9497 pos = 0;
pascal@12756 9498 for (i = 0; i < iLBCenc_inst->nsub; i++) {
pascal@12756 9499 LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq,
pascal@12756 9500 lsf_weightTbl_20ms[i], length);
pascal@12756 9501 memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
pascal@12756 9502 LSFinterpolate2a_enc(lp, lsfold, lsf,
pascal@12756 9503 lsf_weightTbl_20ms[i], length);
pascal@12756 9504 bwexpand(weightdenum+pos, lp,
pascal@12756 9505 LPC_CHIRP_WEIGHTDENUM, lp_length);
pascal@12756 9506 pos += lp_length;
pascal@12756 9507 }
pascal@12756 9508 }
pascal@12756 9509
pascal@12756 9510 /* update memory */
pascal@12756 9511
pascal@12756 9512 if (iLBCenc_inst->mode==30) {
pascal@12756 9513 memcpy(lsfold, lsf2, length*sizeof(float));
pascal@12756 9514 memcpy(lsfdeqold, lsfdeq2, length*sizeof(float));
pascal@12756 9515 }
pascal@12756 9516 else {
pascal@12756 9517 memcpy(lsfold, lsf, length*sizeof(float));
pascal@12756 9518 memcpy(lsfdeqold, lsfdeq, length*sizeof(float));
pascal@12756 9519
pascal@12756 9520
pascal@12756 9521
pascal@12756 9522 Andersen, et al. Experimental [Page 170]
pascal@12756 9523
pascal@12756 9524 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9525
pascal@12756 9526
pascal@12756 9527 }
pascal@12756 9528 }
pascal@12756 9529
pascal@12756 9530 /*----------------------------------------------------------------*
pascal@12756 9531 * lsf quantizer (subrutine to LPCencode)
pascal@12756 9532 *---------------------------------------------------------------*/
pascal@12756 9533
pascal@12756 9534 void SimplelsfQ(
pascal@12756 9535 float *lsfdeq, /* (o) dequantized lsf coefficients
pascal@12756 9536 (dimension FILTERORDER) */
pascal@12756 9537 int *index, /* (o) quantization index */
pascal@12756 9538 float *lsf, /* (i) the lsf coefficient vector to be
pascal@12756 9539 quantized (dimension FILTERORDER ) */
pascal@12756 9540 int lpc_n /* (i) number of lsf sets to quantize */
pascal@12756 9541 ){
pascal@12756 9542 /* Quantize first LSF with memoryless split VQ */
pascal@12756 9543 SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT,
pascal@12756 9544 dim_lsfCbTbl, size_lsfCbTbl);
pascal@12756 9545
pascal@12756 9546 if (lpc_n==2) {
pascal@12756 9547 /* Quantize second LSF with memoryless split VQ */
pascal@12756 9548 SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT,
pascal@12756 9549 lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT,
pascal@12756 9550 dim_lsfCbTbl, size_lsfCbTbl);
pascal@12756 9551 }
pascal@12756 9552 }
pascal@12756 9553
pascal@12756 9554 /*----------------------------------------------------------------*
pascal@12756 9555 * lpc encoder
pascal@12756 9556 *---------------------------------------------------------------*/
pascal@12756 9557
pascal@12756 9558 void LPCencode(
pascal@12756 9559 float *syntdenum, /* (i/o) synthesis filter coefficients
pascal@12756 9560 before/after encoding */
pascal@12756 9561 float *weightdenum, /* (i/o) weighting denumerator
pascal@12756 9562 coefficients before/after
pascal@12756 9563 encoding */
pascal@12756 9564 int *lsf_index, /* (o) lsf quantization index */
pascal@12756 9565 float *data, /* (i) lsf coefficients to quantize */
pascal@12756 9566 iLBC_Enc_Inst_t *iLBCenc_inst
pascal@12756 9567 /* (i/o) the encoder state structure */
pascal@12756 9568 ){
pascal@12756 9569 float lsf[LPC_FILTERORDER * LPC_N_MAX];
pascal@12756 9570 float lsfdeq[LPC_FILTERORDER * LPC_N_MAX];
pascal@12756 9571 int change=0;
pascal@12756 9572
pascal@12756 9573 SimpleAnalysis(lsf, data, iLBCenc_inst);
pascal@12756 9574 SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n);
pascal@12756 9575
pascal@12756 9576
pascal@12756 9577
pascal@12756 9578 Andersen, et al. Experimental [Page 171]
pascal@12756 9579
pascal@12756 9580 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9581
pascal@12756 9582
pascal@12756 9583 change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n);
pascal@12756 9584 SimpleInterpolateLSF(syntdenum, weightdenum,
pascal@12756 9585 lsf, lsfdeq, iLBCenc_inst->lsfold,
pascal@12756 9586 iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst);
pascal@12756 9587 }
pascal@12756 9588
pascal@12756 9589 A.39. lsf.h
pascal@12756 9590
pascal@12756 9591 /******************************************************************
pascal@12756 9592
pascal@12756 9593 iLBC Speech Coder ANSI-C Source Code
pascal@12756 9594
pascal@12756 9595 lsf.h
pascal@12756 9596
pascal@12756 9597 Copyright (C) The Internet Society (2004).
pascal@12756 9598 All Rights Reserved.
pascal@12756 9599
pascal@12756 9600 ******************************************************************/
pascal@12756 9601
pascal@12756 9602 #ifndef __iLBC_LSF_H
pascal@12756 9603 #define __iLBC_LSF_H
pascal@12756 9604
pascal@12756 9605 void a2lsf(
pascal@12756 9606 float *freq,/* (o) lsf coefficients */
pascal@12756 9607 float *a /* (i) lpc coefficients */
pascal@12756 9608 );
pascal@12756 9609
pascal@12756 9610 void lsf2a(
pascal@12756 9611 float *a_coef, /* (o) lpc coefficients */
pascal@12756 9612 float *freq /* (i) lsf coefficients */
pascal@12756 9613 );
pascal@12756 9614
pascal@12756 9615 #endif
pascal@12756 9616
pascal@12756 9617 A.40. lsf.c
pascal@12756 9618
pascal@12756 9619 /******************************************************************
pascal@12756 9620
pascal@12756 9621 iLBC Speech Coder ANSI-C Source Code
pascal@12756 9622
pascal@12756 9623 lsf.c
pascal@12756 9624
pascal@12756 9625 Copyright (C) The Internet Society (2004).
pascal@12756 9626 All Rights Reserved.
pascal@12756 9627
pascal@12756 9628 ******************************************************************/
pascal@12756 9629
pascal@12756 9630 #include <string.h>
pascal@12756 9631
pascal@12756 9632
pascal@12756 9633
pascal@12756 9634 Andersen, et al. Experimental [Page 172]
pascal@12756 9635
pascal@12756 9636 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9637
pascal@12756 9638
pascal@12756 9639 #include <math.h>
pascal@12756 9640
pascal@12756 9641 #include "iLBC_define.h"
pascal@12756 9642
pascal@12756 9643 /*----------------------------------------------------------------*
pascal@12756 9644 * conversion from lpc coefficients to lsf coefficients
pascal@12756 9645 *---------------------------------------------------------------*/
pascal@12756 9646
pascal@12756 9647 void a2lsf(
pascal@12756 9648 float *freq,/* (o) lsf coefficients */
pascal@12756 9649 float *a /* (i) lpc coefficients */
pascal@12756 9650 ){
pascal@12756 9651 float steps[LSF_NUMBER_OF_STEPS] =
pascal@12756 9652 {(float)0.00635, (float)0.003175, (float)0.0015875,
pascal@12756 9653 (float)0.00079375};
pascal@12756 9654 float step;
pascal@12756 9655 int step_idx;
pascal@12756 9656 int lsp_index;
pascal@12756 9657 float p[LPC_HALFORDER];
pascal@12756 9658 float q[LPC_HALFORDER];
pascal@12756 9659 float p_pre[LPC_HALFORDER];
pascal@12756 9660 float q_pre[LPC_HALFORDER];
pascal@12756 9661 float old_p, old_q, *old;
pascal@12756 9662 float *pq_coef;
pascal@12756 9663 float omega, old_omega;
pascal@12756 9664 int i;
pascal@12756 9665 float hlp, hlp1, hlp2, hlp3, hlp4, hlp5;
pascal@12756 9666
pascal@12756 9667 for (i=0; i<LPC_HALFORDER; i++) {
pascal@12756 9668 p[i] = (float)-1.0 * (a[i + 1] + a[LPC_FILTERORDER - i]);
pascal@12756 9669 q[i] = a[LPC_FILTERORDER - i] - a[i + 1];
pascal@12756 9670 }
pascal@12756 9671
pascal@12756 9672 p_pre[0] = (float)-1.0 - p[0];
pascal@12756 9673 p_pre[1] = - p_pre[0] - p[1];
pascal@12756 9674 p_pre[2] = - p_pre[1] - p[2];
pascal@12756 9675 p_pre[3] = - p_pre[2] - p[3];
pascal@12756 9676 p_pre[4] = - p_pre[3] - p[4];
pascal@12756 9677 p_pre[4] = p_pre[4] / 2;
pascal@12756 9678
pascal@12756 9679 q_pre[0] = (float)1.0 - q[0];
pascal@12756 9680 q_pre[1] = q_pre[0] - q[1];
pascal@12756 9681 q_pre[2] = q_pre[1] - q[2];
pascal@12756 9682 q_pre[3] = q_pre[2] - q[3];
pascal@12756 9683 q_pre[4] = q_pre[3] - q[4];
pascal@12756 9684 q_pre[4] = q_pre[4] / 2;
pascal@12756 9685
pascal@12756 9686 omega = 0.0;
pascal@12756 9687
pascal@12756 9688
pascal@12756 9689
pascal@12756 9690 Andersen, et al. Experimental [Page 173]
pascal@12756 9691
pascal@12756 9692 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9693
pascal@12756 9694
pascal@12756 9695 old_omega = 0.0;
pascal@12756 9696
pascal@12756 9697 old_p = FLOAT_MAX;
pascal@12756 9698 old_q = FLOAT_MAX;
pascal@12756 9699
pascal@12756 9700 /* Here we loop through lsp_index to find all the
pascal@12756 9701 LPC_FILTERORDER roots for omega. */
pascal@12756 9702
pascal@12756 9703 for (lsp_index = 0; lsp_index<LPC_FILTERORDER; lsp_index++) {
pascal@12756 9704
pascal@12756 9705 /* Depending on lsp_index being even or odd, we
pascal@12756 9706 alternatively solve the roots for the two LSP equations. */
pascal@12756 9707
pascal@12756 9708
pascal@12756 9709 if ((lsp_index & 0x1) == 0) {
pascal@12756 9710 pq_coef = p_pre;
pascal@12756 9711 old = &old_p;
pascal@12756 9712 } else {
pascal@12756 9713 pq_coef = q_pre;
pascal@12756 9714 old = &old_q;
pascal@12756 9715 }
pascal@12756 9716
pascal@12756 9717 /* Start with low resolution grid */
pascal@12756 9718
pascal@12756 9719 for (step_idx = 0, step = steps[step_idx];
pascal@12756 9720 step_idx < LSF_NUMBER_OF_STEPS;){
pascal@12756 9721
pascal@12756 9722 /* cos(10piw) + pq(0)cos(8piw) + pq(1)cos(6piw) +
pascal@12756 9723 pq(2)cos(4piw) + pq(3)cod(2piw) + pq(4) */
pascal@12756 9724
pascal@12756 9725 hlp = (float)cos(omega * TWO_PI);
pascal@12756 9726 hlp1 = (float)2.0 * hlp + pq_coef[0];
pascal@12756 9727 hlp2 = (float)2.0 * hlp * hlp1 - (float)1.0 +
pascal@12756 9728 pq_coef[1];
pascal@12756 9729 hlp3 = (float)2.0 * hlp * hlp2 - hlp1 + pq_coef[2];
pascal@12756 9730 hlp4 = (float)2.0 * hlp * hlp3 - hlp2 + pq_coef[3];
pascal@12756 9731 hlp5 = hlp * hlp4 - hlp3 + pq_coef[4];
pascal@12756 9732
pascal@12756 9733
pascal@12756 9734 if (((hlp5 * (*old)) <= 0.0) || (omega >= 0.5)){
pascal@12756 9735
pascal@12756 9736 if (step_idx == (LSF_NUMBER_OF_STEPS - 1)){
pascal@12756 9737
pascal@12756 9738 if (fabs(hlp5) >= fabs(*old)) {
pascal@12756 9739 freq[lsp_index] = omega - step;
pascal@12756 9740 } else {
pascal@12756 9741 freq[lsp_index] = omega;
pascal@12756 9742 }
pascal@12756 9743
pascal@12756 9744
pascal@12756 9745
pascal@12756 9746 Andersen, et al. Experimental [Page 174]
pascal@12756 9747
pascal@12756 9748 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9749
pascal@12756 9750
pascal@12756 9751
pascal@12756 9752
pascal@12756 9753 if ((*old) >= 0.0){
pascal@12756 9754 *old = (float)-1.0 * FLOAT_MAX;
pascal@12756 9755 } else {
pascal@12756 9756 *old = FLOAT_MAX;
pascal@12756 9757 }
pascal@12756 9758
pascal@12756 9759 omega = old_omega;
pascal@12756 9760 step_idx = 0;
pascal@12756 9761
pascal@12756 9762 step_idx = LSF_NUMBER_OF_STEPS;
pascal@12756 9763 } else {
pascal@12756 9764
pascal@12756 9765 if (step_idx == 0) {
pascal@12756 9766 old_omega = omega;
pascal@12756 9767 }
pascal@12756 9768
pascal@12756 9769 step_idx++;
pascal@12756 9770 omega -= steps[step_idx];
pascal@12756 9771
pascal@12756 9772 /* Go back one grid step */
pascal@12756 9773
pascal@12756 9774 step = steps[step_idx];
pascal@12756 9775 }
pascal@12756 9776 } else {
pascal@12756 9777
pascal@12756 9778 /* increment omega until they are of different sign,
pascal@12756 9779 and we know there is at least one root between omega
pascal@12756 9780 and old_omega */
pascal@12756 9781 *old = hlp5;
pascal@12756 9782 omega += step;
pascal@12756 9783 }
pascal@12756 9784 }
pascal@12756 9785 }
pascal@12756 9786
pascal@12756 9787 for (i = 0; i<LPC_FILTERORDER; i++) {
pascal@12756 9788 freq[i] = freq[i] * TWO_PI;
pascal@12756 9789 }
pascal@12756 9790 }
pascal@12756 9791
pascal@12756 9792 /*----------------------------------------------------------------*
pascal@12756 9793 * conversion from lsf coefficients to lpc coefficients
pascal@12756 9794 *---------------------------------------------------------------*/
pascal@12756 9795
pascal@12756 9796 void lsf2a(
pascal@12756 9797 float *a_coef, /* (o) lpc coefficients */
pascal@12756 9798 float *freq /* (i) lsf coefficients */
pascal@12756 9799
pascal@12756 9800
pascal@12756 9801
pascal@12756 9802 Andersen, et al. Experimental [Page 175]
pascal@12756 9803
pascal@12756 9804 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9805
pascal@12756 9806
pascal@12756 9807 ){
pascal@12756 9808 int i, j;
pascal@12756 9809 float hlp;
pascal@12756 9810 float p[LPC_HALFORDER], q[LPC_HALFORDER];
pascal@12756 9811 float a[LPC_HALFORDER + 1], a1[LPC_HALFORDER],
pascal@12756 9812 a2[LPC_HALFORDER];
pascal@12756 9813 float b[LPC_HALFORDER + 1], b1[LPC_HALFORDER],
pascal@12756 9814 b2[LPC_HALFORDER];
pascal@12756 9815
pascal@12756 9816 for (i=0; i<LPC_FILTERORDER; i++) {
pascal@12756 9817 freq[i] = freq[i] * PI2;
pascal@12756 9818 }
pascal@12756 9819
pascal@12756 9820 /* Check input for ill-conditioned cases. This part is not
pascal@12756 9821 found in the TIA standard. It involves the following 2 IF
pascal@12756 9822 blocks. If "freq" is judged ill-conditioned, then we first
pascal@12756 9823 modify freq[0] and freq[LPC_HALFORDER-1] (normally
pascal@12756 9824 LPC_HALFORDER = 10 for LPC applications), then we adjust
pascal@12756 9825 the other "freq" values slightly */
pascal@12756 9826
pascal@12756 9827
pascal@12756 9828 if ((freq[0] <= 0.0) || (freq[LPC_FILTERORDER - 1] >= 0.5)){
pascal@12756 9829
pascal@12756 9830
pascal@12756 9831 if (freq[0] <= 0.0) {
pascal@12756 9832 freq[0] = (float)0.022;
pascal@12756 9833 }
pascal@12756 9834
pascal@12756 9835
pascal@12756 9836 if (freq[LPC_FILTERORDER - 1] >= 0.5) {
pascal@12756 9837 freq[LPC_FILTERORDER - 1] = (float)0.499;
pascal@12756 9838 }
pascal@12756 9839
pascal@12756 9840 hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) /
pascal@12756 9841 (float) (LPC_FILTERORDER - 1);
pascal@12756 9842
pascal@12756 9843 for (i=1; i<LPC_FILTERORDER; i++) {
pascal@12756 9844 freq[i] = freq[i - 1] + hlp;
pascal@12756 9845 }
pascal@12756 9846 }
pascal@12756 9847
pascal@12756 9848 memset(a1, 0, LPC_HALFORDER*sizeof(float));
pascal@12756 9849 memset(a2, 0, LPC_HALFORDER*sizeof(float));
pascal@12756 9850 memset(b1, 0, LPC_HALFORDER*sizeof(float));
pascal@12756 9851 memset(b2, 0, LPC_HALFORDER*sizeof(float));
pascal@12756 9852 memset(a, 0, (LPC_HALFORDER+1)*sizeof(float));
pascal@12756 9853 memset(b, 0, (LPC_HALFORDER+1)*sizeof(float));
pascal@12756 9854
pascal@12756 9855
pascal@12756 9856
pascal@12756 9857
pascal@12756 9858 Andersen, et al. Experimental [Page 176]
pascal@12756 9859
pascal@12756 9860 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9861
pascal@12756 9862
pascal@12756 9863 /* p[i] and q[i] compute cos(2*pi*omega_{2j}) and
pascal@12756 9864 cos(2*pi*omega_{2j-1} in eqs. 4.2.2.2-1 and 4.2.2.2-2.
pascal@12756 9865 Note that for this code p[i] specifies the coefficients
pascal@12756 9866 used in .Q_A(z) while q[i] specifies the coefficients used
pascal@12756 9867 in .P_A(z) */
pascal@12756 9868
pascal@12756 9869 for (i=0; i<LPC_HALFORDER; i++) {
pascal@12756 9870 p[i] = (float)cos(TWO_PI * freq[2 * i]);
pascal@12756 9871 q[i] = (float)cos(TWO_PI * freq[2 * i + 1]);
pascal@12756 9872 }
pascal@12756 9873
pascal@12756 9874 a[0] = 0.25;
pascal@12756 9875 b[0] = 0.25;
pascal@12756 9876
pascal@12756 9877 for (i= 0; i<LPC_HALFORDER; i++) {
pascal@12756 9878 a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];
pascal@12756 9879 b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];
pascal@12756 9880 a2[i] = a1[i];
pascal@12756 9881 a1[i] = a[i];
pascal@12756 9882 b2[i] = b1[i];
pascal@12756 9883 b1[i] = b[i];
pascal@12756 9884 }
pascal@12756 9885
pascal@12756 9886 for (j=0; j<LPC_FILTERORDER; j++) {
pascal@12756 9887
pascal@12756 9888 if (j == 0) {
pascal@12756 9889 a[0] = 0.25;
pascal@12756 9890 b[0] = -0.25;
pascal@12756 9891 } else {
pascal@12756 9892 a[0] = b[0] = 0.0;
pascal@12756 9893 }
pascal@12756 9894
pascal@12756 9895 for (i=0; i<LPC_HALFORDER; i++) {
pascal@12756 9896 a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];
pascal@12756 9897 b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];
pascal@12756 9898 a2[i] = a1[i];
pascal@12756 9899 a1[i] = a[i];
pascal@12756 9900 b2[i] = b1[i];
pascal@12756 9901 b1[i] = b[i];
pascal@12756 9902 }
pascal@12756 9903
pascal@12756 9904 a_coef[j + 1] = 2 * (a[LPC_HALFORDER] + b[LPC_HALFORDER]);
pascal@12756 9905 }
pascal@12756 9906
pascal@12756 9907 a_coef[0] = 1.0;
pascal@12756 9908 }
pascal@12756 9909
pascal@12756 9910
pascal@12756 9911
pascal@12756 9912
pascal@12756 9913
pascal@12756 9914 Andersen, et al. Experimental [Page 177]
pascal@12756 9915
pascal@12756 9916 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9917
pascal@12756 9918
pascal@12756 9919 A.41. packing.h
pascal@12756 9920
pascal@12756 9921 /******************************************************************
pascal@12756 9922
pascal@12756 9923 iLBC Speech Coder ANSI-C Source Code
pascal@12756 9924
pascal@12756 9925 packing.h
pascal@12756 9926
pascal@12756 9927 Copyright (C) The Internet Society (2004).
pascal@12756 9928 All Rights Reserved.
pascal@12756 9929
pascal@12756 9930 ******************************************************************/
pascal@12756 9931
pascal@12756 9932 #ifndef __PACKING_H
pascal@12756 9933 #define __PACKING_H
pascal@12756 9934
pascal@12756 9935 void packsplit(
pascal@12756 9936 int *index, /* (i) the value to split */
pascal@12756 9937 int *firstpart, /* (o) the value specified by most
pascal@12756 9938 significant bits */
pascal@12756 9939 int *rest, /* (o) the value specified by least
pascal@12756 9940 significant bits */
pascal@12756 9941 int bitno_firstpart, /* (i) number of bits in most
pascal@12756 9942 significant part */
pascal@12756 9943 int bitno_total /* (i) number of bits in full range
pascal@12756 9944 of value */
pascal@12756 9945 );
pascal@12756 9946
pascal@12756 9947 void packcombine(
pascal@12756 9948 int *index, /* (i/o) the msb value in the
pascal@12756 9949 combined value out */
pascal@12756 9950 int rest, /* (i) the lsb value */
pascal@12756 9951 int bitno_rest /* (i) the number of bits in the
pascal@12756 9952 lsb part */
pascal@12756 9953 );
pascal@12756 9954
pascal@12756 9955 void dopack(
pascal@12756 9956 unsigned char **bitstream, /* (i/o) on entrance pointer to
pascal@12756 9957 place in bitstream to pack
pascal@12756 9958 new data, on exit pointer
pascal@12756 9959 to place in bitstream to
pascal@12756 9960 pack future data */
pascal@12756 9961 int index, /* (i) the value to pack */
pascal@12756 9962 int bitno, /* (i) the number of bits that the
pascal@12756 9963 value will fit within */
pascal@12756 9964 int *pos /* (i/o) write position in the
pascal@12756 9965 current byte */
pascal@12756 9966 );
pascal@12756 9967
pascal@12756 9968
pascal@12756 9969
pascal@12756 9970 Andersen, et al. Experimental [Page 178]
pascal@12756 9971
pascal@12756 9972 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 9973
pascal@12756 9974
pascal@12756 9975 void unpack(
pascal@12756 9976 unsigned char **bitstream, /* (i/o) on entrance pointer to
pascal@12756 9977 place in bitstream to
pascal@12756 9978 unpack new data from, on
pascal@12756 9979 exit pointer to place in
pascal@12756 9980 bitstream to unpack future
pascal@12756 9981 data from */
pascal@12756 9982 int *index, /* (o) resulting value */
pascal@12756 9983 int bitno, /* (i) number of bits used to
pascal@12756 9984 represent the value */
pascal@12756 9985 int *pos /* (i/o) read position in the
pascal@12756 9986 current byte */
pascal@12756 9987 );
pascal@12756 9988
pascal@12756 9989 #endif
pascal@12756 9990
pascal@12756 9991 A.42. packing.c
pascal@12756 9992
pascal@12756 9993 /******************************************************************
pascal@12756 9994
pascal@12756 9995 iLBC Speech Coder ANSI-C Source Code
pascal@12756 9996
pascal@12756 9997 packing.c
pascal@12756 9998
pascal@12756 9999 Copyright (C) The Internet Society (2004).
pascal@12756 10000 All Rights Reserved.
pascal@12756 10001
pascal@12756 10002 ******************************************************************/
pascal@12756 10003
pascal@12756 10004 #include <math.h>
pascal@12756 10005 #include <stdlib.h>
pascal@12756 10006
pascal@12756 10007 #include "iLBC_define.h"
pascal@12756 10008 #include "constants.h"
pascal@12756 10009 #include "helpfun.h"
pascal@12756 10010 #include "string.h"
pascal@12756 10011
pascal@12756 10012 /*----------------------------------------------------------------*
pascal@12756 10013 * splitting an integer into first most significant bits and
pascal@12756 10014 * remaining least significant bits
pascal@12756 10015 *---------------------------------------------------------------*/
pascal@12756 10016
pascal@12756 10017 void packsplit(
pascal@12756 10018 int *index, /* (i) the value to split */
pascal@12756 10019 int *firstpart, /* (o) the value specified by most
pascal@12756 10020 significant bits */
pascal@12756 10021 int *rest, /* (o) the value specified by least
pascal@12756 10022 significant bits */
pascal@12756 10023
pascal@12756 10024
pascal@12756 10025
pascal@12756 10026 Andersen, et al. Experimental [Page 179]
pascal@12756 10027
pascal@12756 10028 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10029
pascal@12756 10030
pascal@12756 10031 int bitno_firstpart, /* (i) number of bits in most
pascal@12756 10032 significant part */
pascal@12756 10033 int bitno_total /* (i) number of bits in full range
pascal@12756 10034 of value */
pascal@12756 10035 ){
pascal@12756 10036 int bitno_rest = bitno_total-bitno_firstpart;
pascal@12756 10037
pascal@12756 10038 *firstpart = *index>>(bitno_rest);
pascal@12756 10039 *rest = *index-(*firstpart<<(bitno_rest));
pascal@12756 10040 }
pascal@12756 10041
pascal@12756 10042 /*----------------------------------------------------------------*
pascal@12756 10043 * combining a value corresponding to msb's with a value
pascal@12756 10044 * corresponding to lsb's
pascal@12756 10045 *---------------------------------------------------------------*/
pascal@12756 10046
pascal@12756 10047 void packcombine(
pascal@12756 10048 int *index, /* (i/o) the msb value in the
pascal@12756 10049 combined value out */
pascal@12756 10050 int rest, /* (i) the lsb value */
pascal@12756 10051 int bitno_rest /* (i) the number of bits in the
pascal@12756 10052 lsb part */
pascal@12756 10053 ){
pascal@12756 10054 *index = *index<<bitno_rest;
pascal@12756 10055 *index += rest;
pascal@12756 10056 }
pascal@12756 10057
pascal@12756 10058 /*----------------------------------------------------------------*
pascal@12756 10059 * packing of bits into bitstream, i.e., vector of bytes
pascal@12756 10060 *---------------------------------------------------------------*/
pascal@12756 10061
pascal@12756 10062 void dopack(
pascal@12756 10063 unsigned char **bitstream, /* (i/o) on entrance pointer to
pascal@12756 10064 place in bitstream to pack
pascal@12756 10065 new data, on exit pointer
pascal@12756 10066 to place in bitstream to
pascal@12756 10067 pack future data */
pascal@12756 10068 int index, /* (i) the value to pack */
pascal@12756 10069 int bitno, /* (i) the number of bits that the
pascal@12756 10070 value will fit within */
pascal@12756 10071 int *pos /* (i/o) write position in the
pascal@12756 10072 current byte */
pascal@12756 10073 ){
pascal@12756 10074 int posLeft;
pascal@12756 10075
pascal@12756 10076 /* Clear the bits before starting in a new byte */
pascal@12756 10077
pascal@12756 10078 if ((*pos)==0) {
pascal@12756 10079
pascal@12756 10080
pascal@12756 10081
pascal@12756 10082 Andersen, et al. Experimental [Page 180]
pascal@12756 10083
pascal@12756 10084 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10085
pascal@12756 10086
pascal@12756 10087 **bitstream=0;
pascal@12756 10088 }
pascal@12756 10089
pascal@12756 10090 while (bitno>0) {
pascal@12756 10091
pascal@12756 10092 /* Jump to the next byte if end of this byte is reached*/
pascal@12756 10093
pascal@12756 10094 if (*pos==8) {
pascal@12756 10095 *pos=0;
pascal@12756 10096 (*bitstream)++;
pascal@12756 10097 **bitstream=0;
pascal@12756 10098 }
pascal@12756 10099
pascal@12756 10100 posLeft=8-(*pos);
pascal@12756 10101
pascal@12756 10102 /* Insert index into the bitstream */
pascal@12756 10103
pascal@12756 10104 if (bitno <= posLeft) {
pascal@12756 10105 **bitstream |= (unsigned char)(index<<(posLeft-bitno));
pascal@12756 10106 *pos+=bitno;
pascal@12756 10107 bitno=0;
pascal@12756 10108 } else {
pascal@12756 10109 **bitstream |= (unsigned char)(index>>(bitno-posLeft));
pascal@12756 10110
pascal@12756 10111 *pos=8;
pascal@12756 10112 index-=((index>>(bitno-posLeft))<<(bitno-posLeft));
pascal@12756 10113
pascal@12756 10114 bitno-=posLeft;
pascal@12756 10115 }
pascal@12756 10116 }
pascal@12756 10117 }
pascal@12756 10118
pascal@12756 10119 /*----------------------------------------------------------------*
pascal@12756 10120 * unpacking of bits from bitstream, i.e., vector of bytes
pascal@12756 10121 *---------------------------------------------------------------*/
pascal@12756 10122
pascal@12756 10123 void unpack(
pascal@12756 10124 unsigned char **bitstream, /* (i/o) on entrance pointer to
pascal@12756 10125 place in bitstream to
pascal@12756 10126 unpack new data from, on
pascal@12756 10127 exit pointer to place in
pascal@12756 10128 bitstream to unpack future
pascal@12756 10129 data from */
pascal@12756 10130 int *index, /* (o) resulting value */
pascal@12756 10131 int bitno, /* (i) number of bits used to
pascal@12756 10132 represent the value */
pascal@12756 10133 int *pos /* (i/o) read position in the
pascal@12756 10134 current byte */
pascal@12756 10135
pascal@12756 10136
pascal@12756 10137
pascal@12756 10138 Andersen, et al. Experimental [Page 181]
pascal@12756 10139
pascal@12756 10140 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10141
pascal@12756 10142
pascal@12756 10143 ){
pascal@12756 10144 int BitsLeft;
pascal@12756 10145
pascal@12756 10146 *index=0;
pascal@12756 10147
pascal@12756 10148 while (bitno>0) {
pascal@12756 10149
pascal@12756 10150 /* move forward in bitstream when the end of the
pascal@12756 10151 byte is reached */
pascal@12756 10152
pascal@12756 10153 if (*pos==8) {
pascal@12756 10154 *pos=0;
pascal@12756 10155 (*bitstream)++;
pascal@12756 10156 }
pascal@12756 10157
pascal@12756 10158 BitsLeft=8-(*pos);
pascal@12756 10159
pascal@12756 10160 /* Extract bits to index */
pascal@12756 10161
pascal@12756 10162 if (BitsLeft>=bitno) {
pascal@12756 10163 *index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno));
pascal@12756 10164
pascal@12756 10165 *pos+=bitno;
pascal@12756 10166 bitno=0;
pascal@12756 10167 } else {
pascal@12756 10168
pascal@12756 10169 if ((8-bitno)>0) {
pascal@12756 10170 *index+=((((**bitstream)<<(*pos)) & 0xFF)>>
pascal@12756 10171 (8-bitno));
pascal@12756 10172 *pos=8;
pascal@12756 10173 } else {
pascal@12756 10174 *index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<<
pascal@12756 10175 (bitno-8));
pascal@12756 10176 *pos=8;
pascal@12756 10177 }
pascal@12756 10178 bitno-=BitsLeft;
pascal@12756 10179 }
pascal@12756 10180 }
pascal@12756 10181 }
pascal@12756 10182
pascal@12756 10183 A.43. StateConstructW.h
pascal@12756 10184
pascal@12756 10185 /******************************************************************
pascal@12756 10186
pascal@12756 10187 iLBC Speech Coder ANSI-C Source Code
pascal@12756 10188
pascal@12756 10189 StateConstructW.h
pascal@12756 10190
pascal@12756 10191
pascal@12756 10192
pascal@12756 10193
pascal@12756 10194 Andersen, et al. Experimental [Page 182]
pascal@12756 10195
pascal@12756 10196 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10197
pascal@12756 10198
pascal@12756 10199 Copyright (C) The Internet Society (2004).
pascal@12756 10200 All Rights Reserved.
pascal@12756 10201
pascal@12756 10202 ******************************************************************/
pascal@12756 10203
pascal@12756 10204 #ifndef __iLBC_STATECONSTRUCTW_H
pascal@12756 10205 #define __iLBC_STATECONSTRUCTW_H
pascal@12756 10206
pascal@12756 10207 void StateConstructW(
pascal@12756 10208 int idxForMax, /* (i) 6-bit index for the quantization of
pascal@12756 10209 max amplitude */
pascal@12756 10210 int *idxVec, /* (i) vector of quantization indexes */
pascal@12756 10211 float *syntDenum, /* (i) synthesis filter denumerator */
pascal@12756 10212 float *out, /* (o) the decoded state vector */
pascal@12756 10213 int len /* (i) length of a state vector */
pascal@12756 10214 );
pascal@12756 10215
pascal@12756 10216 #endif
pascal@12756 10217
pascal@12756 10218 A.44. StateConstructW.c
pascal@12756 10219
pascal@12756 10220 /******************************************************************
pascal@12756 10221
pascal@12756 10222 iLBC Speech Coder ANSI-C Source Code
pascal@12756 10223
pascal@12756 10224 StateConstructW.c
pascal@12756 10225
pascal@12756 10226 Copyright (C) The Internet Society (2004).
pascal@12756 10227 All Rights Reserved.
pascal@12756 10228
pascal@12756 10229 ******************************************************************/
pascal@12756 10230
pascal@12756 10231 #include <math.h>
pascal@12756 10232 #include <string.h>
pascal@12756 10233
pascal@12756 10234 #include "iLBC_define.h"
pascal@12756 10235 #include "constants.h"
pascal@12756 10236 #include "filter.h"
pascal@12756 10237
pascal@12756 10238 /*----------------------------------------------------------------*
pascal@12756 10239 * decoding of the start state
pascal@12756 10240 *---------------------------------------------------------------*/
pascal@12756 10241
pascal@12756 10242 void StateConstructW(
pascal@12756 10243 int idxForMax, /* (i) 6-bit index for the quantization of
pascal@12756 10244 max amplitude */
pascal@12756 10245 int *idxVec, /* (i) vector of quantization indexes */
pascal@12756 10246 float *syntDenum, /* (i) synthesis filter denumerator */
pascal@12756 10247
pascal@12756 10248
pascal@12756 10249
pascal@12756 10250 Andersen, et al. Experimental [Page 183]
pascal@12756 10251
pascal@12756 10252 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10253
pascal@12756 10254
pascal@12756 10255 float *out, /* (o) the decoded state vector */
pascal@12756 10256 int len /* (i) length of a state vector */
pascal@12756 10257 ){
pascal@12756 10258 float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp,
pascal@12756 10259 numerator[LPC_FILTERORDER+1];
pascal@12756 10260 float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout;
pascal@12756 10261 int k,tmpi;
pascal@12756 10262
pascal@12756 10263 /* decoding of the maximum value */
pascal@12756 10264
pascal@12756 10265 maxVal = state_frgqTbl[idxForMax];
pascal@12756 10266 maxVal = (float)pow(10,maxVal)/(float)4.5;
pascal@12756 10267
pascal@12756 10268 /* initialization of buffers and coefficients */
pascal@12756 10269
pascal@12756 10270 memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 10271 memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 10272 for (k=0; k<LPC_FILTERORDER; k++) {
pascal@12756 10273 numerator[k]=syntDenum[LPC_FILTERORDER-k];
pascal@12756 10274 }
pascal@12756 10275 numerator[LPC_FILTERORDER]=syntDenum[0];
pascal@12756 10276 tmp = &tmpbuf[LPC_FILTERORDER];
pascal@12756 10277 fout = &foutbuf[LPC_FILTERORDER];
pascal@12756 10278
pascal@12756 10279 /* decoding of the sample values */
pascal@12756 10280
pascal@12756 10281 for (k=0; k<len; k++) {
pascal@12756 10282 tmpi = len-1-k;
pascal@12756 10283 /* maxVal = 1/scal */
pascal@12756 10284 tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]];
pascal@12756 10285 }
pascal@12756 10286
pascal@12756 10287 /* circular convolution with all-pass filter */
pascal@12756 10288
pascal@12756 10289 memset(tmp+len, 0, len*sizeof(float));
pascal@12756 10290 ZeroPoleFilter(tmp, numerator, syntDenum, 2*len,
pascal@12756 10291 LPC_FILTERORDER, fout);
pascal@12756 10292 for (k=0;k<len;k++) {
pascal@12756 10293 out[k] = fout[len-1-k]+fout[2*len-1-k];
pascal@12756 10294 }
pascal@12756 10295 }
pascal@12756 10296
pascal@12756 10297
pascal@12756 10298
pascal@12756 10299
pascal@12756 10300
pascal@12756 10301
pascal@12756 10302
pascal@12756 10303
pascal@12756 10304
pascal@12756 10305
pascal@12756 10306 Andersen, et al. Experimental [Page 184]
pascal@12756 10307
pascal@12756 10308 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10309
pascal@12756 10310
pascal@12756 10311 A.45. StateSearchW.h
pascal@12756 10312
pascal@12756 10313 /******************************************************************
pascal@12756 10314
pascal@12756 10315 iLBC Speech Coder ANSI-C Source Code
pascal@12756 10316
pascal@12756 10317 StateSearchW.h
pascal@12756 10318
pascal@12756 10319 Copyright (C) The Internet Society (2004).
pascal@12756 10320 All Rights Reserved.
pascal@12756 10321
pascal@12756 10322 ******************************************************************/
pascal@12756 10323
pascal@12756 10324 #ifndef __iLBC_STATESEARCHW_H
pascal@12756 10325 #define __iLBC_STATESEARCHW_H
pascal@12756 10326
pascal@12756 10327 void AbsQuantW(
pascal@12756 10328 iLBC_Enc_Inst_t *iLBCenc_inst,
pascal@12756 10329 /* (i) Encoder instance */
pascal@12756 10330 float *in, /* (i) vector to encode */
pascal@12756 10331 float *syntDenum, /* (i) denominator of synthesis filter */
pascal@12756 10332 float *weightDenum, /* (i) denominator of weighting filter */
pascal@12756 10333 int *out, /* (o) vector of quantizer indexes */
pascal@12756 10334 int len, /* (i) length of vector to encode and
pascal@12756 10335 vector of quantizer indexes */
pascal@12756 10336 int state_first /* (i) position of start state in the
pascal@12756 10337 80 vec */
pascal@12756 10338 );
pascal@12756 10339
pascal@12756 10340 void StateSearchW(
pascal@12756 10341 iLBC_Enc_Inst_t *iLBCenc_inst,
pascal@12756 10342 /* (i) Encoder instance */
pascal@12756 10343 float *residual,/* (i) target residual vector */
pascal@12756 10344 float *syntDenum, /* (i) lpc synthesis filter */
pascal@12756 10345 float *weightDenum, /* (i) weighting filter denuminator */
pascal@12756 10346 int *idxForMax, /* (o) quantizer index for maximum
pascal@12756 10347 amplitude */
pascal@12756 10348 int *idxVec, /* (o) vector of quantization indexes */
pascal@12756 10349 int len, /* (i) length of all vectors */
pascal@12756 10350 int state_first /* (i) position of start state in the
pascal@12756 10351 80 vec */
pascal@12756 10352 );
pascal@12756 10353
pascal@12756 10354
pascal@12756 10355 #endif
pascal@12756 10356
pascal@12756 10357
pascal@12756 10358
pascal@12756 10359
pascal@12756 10360
pascal@12756 10361
pascal@12756 10362 Andersen, et al. Experimental [Page 185]
pascal@12756 10363
pascal@12756 10364 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10365
pascal@12756 10366
pascal@12756 10367 A.46. StateSearchW.c
pascal@12756 10368
pascal@12756 10369 /******************************************************************
pascal@12756 10370
pascal@12756 10371 iLBC Speech Coder ANSI-C Source Code
pascal@12756 10372
pascal@12756 10373 StateSearchW.c
pascal@12756 10374
pascal@12756 10375 Copyright (C) The Internet Society (2004).
pascal@12756 10376 All Rights Reserved.
pascal@12756 10377
pascal@12756 10378 ******************************************************************/
pascal@12756 10379
pascal@12756 10380 #include <math.h>
pascal@12756 10381 #include <string.h>
pascal@12756 10382
pascal@12756 10383 #include "iLBC_define.h"
pascal@12756 10384 #include "constants.h"
pascal@12756 10385 #include "filter.h"
pascal@12756 10386 #include "helpfun.h"
pascal@12756 10387
pascal@12756 10388 /*----------------------------------------------------------------*
pascal@12756 10389 * predictive noise shaping encoding of scaled start state
pascal@12756 10390 * (subrutine for StateSearchW)
pascal@12756 10391 *---------------------------------------------------------------*/
pascal@12756 10392
pascal@12756 10393 void AbsQuantW(
pascal@12756 10394 iLBC_Enc_Inst_t *iLBCenc_inst,
pascal@12756 10395 /* (i) Encoder instance */
pascal@12756 10396 float *in, /* (i) vector to encode */
pascal@12756 10397 float *syntDenum, /* (i) denominator of synthesis filter */
pascal@12756 10398 float *weightDenum, /* (i) denominator of weighting filter */
pascal@12756 10399 int *out, /* (o) vector of quantizer indexes */
pascal@12756 10400 int len, /* (i) length of vector to encode and
pascal@12756 10401 vector of quantizer indexes */
pascal@12756 10402 int state_first /* (i) position of start state in the
pascal@12756 10403 80 vec */
pascal@12756 10404 ){
pascal@12756 10405 float *syntOut;
pascal@12756 10406 float syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS];
pascal@12756 10407 float toQ, xq;
pascal@12756 10408 int n;
pascal@12756 10409 int index;
pascal@12756 10410
pascal@12756 10411 /* initialization of buffer for filtering */
pascal@12756 10412
pascal@12756 10413 memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 10414
pascal@12756 10415
pascal@12756 10416
pascal@12756 10417
pascal@12756 10418 Andersen, et al. Experimental [Page 186]
pascal@12756 10419
pascal@12756 10420 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10421
pascal@12756 10422
pascal@12756 10423 /* initialization of pointer for filtering */
pascal@12756 10424
pascal@12756 10425 syntOut = &syntOutBuf[LPC_FILTERORDER];
pascal@12756 10426
pascal@12756 10427 /* synthesis and weighting filters on input */
pascal@12756 10428
pascal@12756 10429 if (state_first) {
pascal@12756 10430 AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER);
pascal@12756 10431 } else {
pascal@12756 10432 AllPoleFilter (in, weightDenum,
pascal@12756 10433 iLBCenc_inst->state_short_len-SUBL,
pascal@12756 10434 LPC_FILTERORDER);
pascal@12756 10435 }
pascal@12756 10436
pascal@12756 10437 /* encoding loop */
pascal@12756 10438
pascal@12756 10439 for (n=0; n<len; n++) {
pascal@12756 10440
pascal@12756 10441 /* time update of filter coefficients */
pascal@12756 10442
pascal@12756 10443 if ((state_first)&&(n==SUBL)){
pascal@12756 10444 syntDenum += (LPC_FILTERORDER+1);
pascal@12756 10445 weightDenum += (LPC_FILTERORDER+1);
pascal@12756 10446
pascal@12756 10447 /* synthesis and weighting filters on input */
pascal@12756 10448 AllPoleFilter (&in[n], weightDenum, len-n,
pascal@12756 10449 LPC_FILTERORDER);
pascal@12756 10450
pascal@12756 10451 } else if ((state_first==0)&&
pascal@12756 10452 (n==(iLBCenc_inst->state_short_len-SUBL))) {
pascal@12756 10453 syntDenum += (LPC_FILTERORDER+1);
pascal@12756 10454 weightDenum += (LPC_FILTERORDER+1);
pascal@12756 10455
pascal@12756 10456 /* synthesis and weighting filters on input */
pascal@12756 10457 AllPoleFilter (&in[n], weightDenum, len-n,
pascal@12756 10458 LPC_FILTERORDER);
pascal@12756 10459
pascal@12756 10460 }
pascal@12756 10461
pascal@12756 10462 /* prediction of synthesized and weighted input */
pascal@12756 10463
pascal@12756 10464 syntOut[n] = 0.0;
pascal@12756 10465 AllPoleFilter (&syntOut[n], weightDenum, 1,
pascal@12756 10466 LPC_FILTERORDER);
pascal@12756 10467
pascal@12756 10468 /* quantization */
pascal@12756 10469
pascal@12756 10470 toQ = in[n]-syntOut[n];
pascal@12756 10471
pascal@12756 10472
pascal@12756 10473
pascal@12756 10474 Andersen, et al. Experimental [Page 187]
pascal@12756 10475
pascal@12756 10476 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10477
pascal@12756 10478
pascal@12756 10479 sort_sq(&xq, &index, toQ, state_sq3Tbl, 8);
pascal@12756 10480 out[n]=index;
pascal@12756 10481 syntOut[n] = state_sq3Tbl[out[n]];
pascal@12756 10482
pascal@12756 10483 /* update of the prediction filter */
pascal@12756 10484
pascal@12756 10485 AllPoleFilter(&syntOut[n], weightDenum, 1,
pascal@12756 10486 LPC_FILTERORDER);
pascal@12756 10487 }
pascal@12756 10488 }
pascal@12756 10489
pascal@12756 10490 /*----------------------------------------------------------------*
pascal@12756 10491 * encoding of start state
pascal@12756 10492 *---------------------------------------------------------------*/
pascal@12756 10493
pascal@12756 10494 void StateSearchW(
pascal@12756 10495 iLBC_Enc_Inst_t *iLBCenc_inst,
pascal@12756 10496 /* (i) Encoder instance */
pascal@12756 10497 float *residual,/* (i) target residual vector */
pascal@12756 10498 float *syntDenum, /* (i) lpc synthesis filter */
pascal@12756 10499 float *weightDenum, /* (i) weighting filter denuminator */
pascal@12756 10500 int *idxForMax, /* (o) quantizer index for maximum
pascal@12756 10501 amplitude */
pascal@12756 10502 int *idxVec, /* (o) vector of quantization indexes */
pascal@12756 10503 int len, /* (i) length of all vectors */
pascal@12756 10504 int state_first /* (i) position of start state in the
pascal@12756 10505 80 vec */
pascal@12756 10506 ){
pascal@12756 10507 float dtmp, maxVal;
pascal@12756 10508 float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS];
pascal@12756 10509 float *tmp, numerator[1+LPC_FILTERORDER];
pascal@12756 10510 float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout;
pascal@12756 10511 int k;
pascal@12756 10512 float qmax, scal;
pascal@12756 10513
pascal@12756 10514 /* initialization of buffers and filter coefficients */
pascal@12756 10515
pascal@12756 10516 memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 10517 memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));
pascal@12756 10518 for (k=0; k<LPC_FILTERORDER; k++) {
pascal@12756 10519 numerator[k]=syntDenum[LPC_FILTERORDER-k];
pascal@12756 10520 }
pascal@12756 10521 numerator[LPC_FILTERORDER]=syntDenum[0];
pascal@12756 10522 tmp = &tmpbuf[LPC_FILTERORDER];
pascal@12756 10523 fout = &foutbuf[LPC_FILTERORDER];
pascal@12756 10524
pascal@12756 10525 /* circular convolution with the all-pass filter */
pascal@12756 10526
pascal@12756 10527
pascal@12756 10528
pascal@12756 10529
pascal@12756 10530 Andersen, et al. Experimental [Page 188]
pascal@12756 10531
pascal@12756 10532 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10533
pascal@12756 10534
pascal@12756 10535 memcpy(tmp, residual, len*sizeof(float));
pascal@12756 10536 memset(tmp+len, 0, len*sizeof(float));
pascal@12756 10537 ZeroPoleFilter(tmp, numerator, syntDenum, 2*len,
pascal@12756 10538 LPC_FILTERORDER, fout);
pascal@12756 10539 for (k=0; k<len; k++) {
pascal@12756 10540 fout[k] += fout[k+len];
pascal@12756 10541 }
pascal@12756 10542
pascal@12756 10543 /* identification of the maximum amplitude value */
pascal@12756 10544
pascal@12756 10545 maxVal = fout[0];
pascal@12756 10546 for (k=1; k<len; k++) {
pascal@12756 10547
pascal@12756 10548 if (fout[k]*fout[k] > maxVal*maxVal){
pascal@12756 10549 maxVal = fout[k];
pascal@12756 10550 }
pascal@12756 10551 }
pascal@12756 10552 maxVal=(float)fabs(maxVal);
pascal@12756 10553
pascal@12756 10554 /* encoding of the maximum amplitude value */
pascal@12756 10555
pascal@12756 10556 if (maxVal < 10.0) {
pascal@12756 10557 maxVal = 10.0;
pascal@12756 10558 }
pascal@12756 10559 maxVal = (float)log10(maxVal);
pascal@12756 10560 sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64);
pascal@12756 10561
pascal@12756 10562 /* decoding of the maximum amplitude representation value,
pascal@12756 10563 and corresponding scaling of start state */
pascal@12756 10564
pascal@12756 10565 maxVal=state_frgqTbl[*idxForMax];
pascal@12756 10566 qmax = (float)pow(10,maxVal);
pascal@12756 10567 scal = (float)(4.5)/qmax;
pascal@12756 10568 for (k=0; k<len; k++){
pascal@12756 10569 fout[k] *= scal;
pascal@12756 10570 }
pascal@12756 10571
pascal@12756 10572 /* predictive noise shaping encoding of scaled start state */
pascal@12756 10573
pascal@12756 10574 AbsQuantW(iLBCenc_inst, fout,syntDenum,
pascal@12756 10575 weightDenum,idxVec, len, state_first);
pascal@12756 10576 }
pascal@12756 10577
pascal@12756 10578
pascal@12756 10579
pascal@12756 10580
pascal@12756 10581
pascal@12756 10582
pascal@12756 10583
pascal@12756 10584
pascal@12756 10585
pascal@12756 10586 Andersen, et al. Experimental [Page 189]
pascal@12756 10587
pascal@12756 10588 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10589
pascal@12756 10590
pascal@12756 10591 A.47. syntFilter.h
pascal@12756 10592
pascal@12756 10593 /******************************************************************
pascal@12756 10594
pascal@12756 10595 iLBC Speech Coder ANSI-C Source Code
pascal@12756 10596
pascal@12756 10597 syntFilter.h
pascal@12756 10598
pascal@12756 10599 Copyright (C) The Internet Society (2004).
pascal@12756 10600 All Rights Reserved.
pascal@12756 10601
pascal@12756 10602 ******************************************************************/
pascal@12756 10603
pascal@12756 10604 #ifndef __iLBC_SYNTFILTER_H
pascal@12756 10605 #define __iLBC_SYNTFILTER_H
pascal@12756 10606
pascal@12756 10607 void syntFilter(
pascal@12756 10608 float *Out, /* (i/o) Signal to be filtered */
pascal@12756 10609 float *a, /* (i) LP parameters */
pascal@12756 10610 int len, /* (i) Length of signal */
pascal@12756 10611 float *mem /* (i/o) Filter state */
pascal@12756 10612 );
pascal@12756 10613
pascal@12756 10614 #endif
pascal@12756 10615
pascal@12756 10616 A.48. syntFilter.c
pascal@12756 10617
pascal@12756 10618 /******************************************************************
pascal@12756 10619
pascal@12756 10620 iLBC Speech Coder ANSI-C Source Code
pascal@12756 10621
pascal@12756 10622 syntFilter.c
pascal@12756 10623
pascal@12756 10624 Copyright (C) The Internet Society (2004).
pascal@12756 10625 All Rights Reserved.
pascal@12756 10626
pascal@12756 10627 ******************************************************************/
pascal@12756 10628
pascal@12756 10629 #include "iLBC_define.h"
pascal@12756 10630
pascal@12756 10631 /*----------------------------------------------------------------*
pascal@12756 10632 * LP synthesis filter.
pascal@12756 10633 *---------------------------------------------------------------*/
pascal@12756 10634
pascal@12756 10635 void syntFilter(
pascal@12756 10636 float *Out, /* (i/o) Signal to be filtered */
pascal@12756 10637 float *a, /* (i) LP parameters */
pascal@12756 10638 int len, /* (i) Length of signal */
pascal@12756 10639
pascal@12756 10640
pascal@12756 10641
pascal@12756 10642 Andersen, et al. Experimental [Page 190]
pascal@12756 10643
pascal@12756 10644 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10645
pascal@12756 10646
pascal@12756 10647 float *mem /* (i/o) Filter state */
pascal@12756 10648 ){
pascal@12756 10649 int i, j;
pascal@12756 10650 float *po, *pi, *pa, *pm;
pascal@12756 10651
pascal@12756 10652 po=Out;
pascal@12756 10653
pascal@12756 10654 /* Filter first part using memory from past */
pascal@12756 10655
pascal@12756 10656 for (i=0; i<LPC_FILTERORDER; i++) {
pascal@12756 10657 pi=&Out[i-1];
pascal@12756 10658 pa=&a[1];
pascal@12756 10659 pm=&mem[LPC_FILTERORDER-1];
pascal@12756 10660 for (j=1; j<=i; j++) {
pascal@12756 10661 *po-=(*pa++)*(*pi--);
pascal@12756 10662 }
pascal@12756 10663 for (j=i+1; j<LPC_FILTERORDER+1; j++) {
pascal@12756 10664 *po-=(*pa++)*(*pm--);
pascal@12756 10665 }
pascal@12756 10666 po++;
pascal@12756 10667 }
pascal@12756 10668
pascal@12756 10669 /* Filter last part where the state is entirely in
pascal@12756 10670 the output vector */
pascal@12756 10671
pascal@12756 10672 for (i=LPC_FILTERORDER; i<len; i++) {
pascal@12756 10673 pi=&Out[i-1];
pascal@12756 10674 pa=&a[1];
pascal@12756 10675 for (j=1; j<LPC_FILTERORDER+1; j++) {
pascal@12756 10676 *po-=(*pa++)*(*pi--);
pascal@12756 10677 }
pascal@12756 10678 po++;
pascal@12756 10679 }
pascal@12756 10680
pascal@12756 10681 /* Update state vector */
pascal@12756 10682
pascal@12756 10683 memcpy(mem, &Out[len-LPC_FILTERORDER],
pascal@12756 10684 LPC_FILTERORDER*sizeof(float));
pascal@12756 10685 }
pascal@12756 10686
pascal@12756 10687
pascal@12756 10688
pascal@12756 10689
pascal@12756 10690
pascal@12756 10691
pascal@12756 10692
pascal@12756 10693
pascal@12756 10694
pascal@12756 10695
pascal@12756 10696
pascal@12756 10697
pascal@12756 10698 Andersen, et al. Experimental [Page 191]
pascal@12756 10699
pascal@12756 10700 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10701
pascal@12756 10702
pascal@12756 10703 Authors' Addresses
pascal@12756 10704
pascal@12756 10705 Soren Vang Andersen
pascal@12756 10706 Department of Communication Technology
pascal@12756 10707 Aalborg University
pascal@12756 10708 Fredrik Bajers Vej 7A
pascal@12756 10709 9200 Aalborg
pascal@12756 10710 Denmark
pascal@12756 10711
pascal@12756 10712 Phone: ++45 9 6358627
pascal@12756 10713 EMail: sva@kom.auc.dk
pascal@12756 10714
pascal@12756 10715
pascal@12756 10716 Alan Duric
pascal@12756 10717 Telio AS
pascal@12756 10718 Stoperigt. 2
pascal@12756 10719 Oslo, N-0250
pascal@12756 10720 Norway
pascal@12756 10721
pascal@12756 10722 Phone: +47 21673555
pascal@12756 10723 EMail: alan.duric@telio.no
pascal@12756 10724
pascal@12756 10725
pascal@12756 10726 Henrik Astrom
pascal@12756 10727 Global IP Sound AB
pascal@12756 10728 Olandsgatan 42
pascal@12756 10729 Stockholm, S-11663
pascal@12756 10730 Sweden
pascal@12756 10731
pascal@12756 10732 Phone: +46 8 54553040
pascal@12756 10733 EMail: henrik.astrom@globalipsound.com
pascal@12756 10734
pascal@12756 10735
pascal@12756 10736 Roar Hagen
pascal@12756 10737 Global IP Sound AB
pascal@12756 10738 Olandsgatan 42
pascal@12756 10739 Stockholm, S-11663
pascal@12756 10740 Sweden
pascal@12756 10741
pascal@12756 10742 Phone: +46 8 54553040
pascal@12756 10743 EMail: roar.hagen@globalipsound.com
pascal@12756 10744
pascal@12756 10745
pascal@12756 10746
pascal@12756 10747
pascal@12756 10748
pascal@12756 10749
pascal@12756 10750
pascal@12756 10751
pascal@12756 10752
pascal@12756 10753
pascal@12756 10754 Andersen, et al. Experimental [Page 192]
pascal@12756 10755
pascal@12756 10756 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10757
pascal@12756 10758
pascal@12756 10759 W. Bastiaan Kleijn
pascal@12756 10760 Global IP Sound AB
pascal@12756 10761 Olandsgatan 42
pascal@12756 10762 Stockholm, S-11663
pascal@12756 10763 Sweden
pascal@12756 10764
pascal@12756 10765 Phone: +46 8 54553040
pascal@12756 10766 EMail: bastiaan.kleijn@globalipsound.com
pascal@12756 10767
pascal@12756 10768
pascal@12756 10769 Jan Linden
pascal@12756 10770 Global IP Sound Inc.
pascal@12756 10771 900 Kearny Street, suite 500
pascal@12756 10772 San Francisco, CA-94133
pascal@12756 10773 USA
pascal@12756 10774
pascal@12756 10775 Phone: +1 415 397 2555
pascal@12756 10776 EMail: jan.linden@globalipsound.com
pascal@12756 10777
pascal@12756 10778
pascal@12756 10779
pascal@12756 10780
pascal@12756 10781
pascal@12756 10782
pascal@12756 10783
pascal@12756 10784
pascal@12756 10785
pascal@12756 10786
pascal@12756 10787
pascal@12756 10788
pascal@12756 10789
pascal@12756 10790
pascal@12756 10791
pascal@12756 10792
pascal@12756 10793
pascal@12756 10794
pascal@12756 10795
pascal@12756 10796
pascal@12756 10797
pascal@12756 10798
pascal@12756 10799
pascal@12756 10800
pascal@12756 10801
pascal@12756 10802
pascal@12756 10803
pascal@12756 10804
pascal@12756 10805
pascal@12756 10806
pascal@12756 10807
pascal@12756 10808
pascal@12756 10809
pascal@12756 10810 Andersen, et al. Experimental [Page 193]
pascal@12756 10811
pascal@12756 10812 RFC 3951 Internet Low Bit Rate Codec December 2004
pascal@12756 10813
pascal@12756 10814
pascal@12756 10815 Full Copyright Statement
pascal@12756 10816
pascal@12756 10817 Copyright (C) The Internet Society (2004).
pascal@12756 10818
pascal@12756 10819 This document is subject to the rights, licenses and restrictions
pascal@12756 10820 contained in BCP 78, and except as set forth therein, the authors
pascal@12756 10821 retain all their rights.
pascal@12756 10822
pascal@12756 10823 This document and the information contained herein are provided on an
pascal@12756 10824 "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
pascal@12756 10825 OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET
pascal@12756 10826 ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED,
pascal@12756 10827 INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
pascal@12756 10828 INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
pascal@12756 10829 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
pascal@12756 10830
pascal@12756 10831 Intellectual Property
pascal@12756 10832
pascal@12756 10833 The IETF takes no position regarding the validity or scope of any
pascal@12756 10834 Intellectual Property Rights or other rights that might be claimed to
pascal@12756 10835 pertain to the implementation or use of the technology described in
pascal@12756 10836 this document or the extent to which any license under such rights
pascal@12756 10837 might or might not be available; nor does it represent that it has
pascal@12756 10838 made any independent effort to identify any such rights. Information
pascal@12756 10839 on the IETF's procedures with respect to rights in IETF Documents can
pascal@12756 10840 be found in BCP 78 and BCP 79.
pascal@12756 10841
pascal@12756 10842 Copies of IPR disclosures made to the IETF Secretariat and any
pascal@12756 10843 assurances of licenses to be made available, or the result of an
pascal@12756 10844 attempt made to obtain a general license or permission for the use of
pascal@12756 10845 such proprietary rights by implementers or users of this
pascal@12756 10846 specification can be obtained from the IETF on-line IPR repository at
pascal@12756 10847 http://www.ietf.org/ipr.
pascal@12756 10848
pascal@12756 10849 The IETF invites any interested party to bring to its attention any
pascal@12756 10850 copyrights, patents or patent applications, or other proprietary
pascal@12756 10851 rights that may cover technology that may be required to implement
pascal@12756 10852 this standard. Please address the information to the IETF at ietf-
pascal@12756 10853 ipr@ietf.org.
pascal@12756 10854
pascal@12756 10855
pascal@12756 10856 Acknowledgement
pascal@12756 10857
pascal@12756 10858 Funding for the RFC Editor function is currently provided by the
pascal@12756 10859 Internet Society.
pascal@12756 10860
pascal@12756 10861
pascal@12756 10862
pascal@12756 10863
pascal@12756 10864
pascal@12756 10865
pascal@12756 10866 Andersen, et al. Experimental [Page 194]
pascal@12756 10867