wok-6.x rev 12756

asterisk: update WGET_URL
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 12 10:02:55 2012 +0200 (2012-05-12)
parents b7606869e51e
children 78783f6b1f25
files asterisk/receipt asterisk/stuff/rfc3951.txt
line diff
     1.1 --- a/asterisk/receipt	Sat May 12 04:20:53 2012 +0200
     1.2 +++ b/asterisk/receipt	Sat May 12 10:02:55 2012 +0200
     1.3 @@ -7,12 +7,12 @@
     1.4  MAINTAINER="pascal.bellard@slitaz.org"
     1.5  TARBALL="$PACKAGE-$VERSION.tar.gz"
     1.6  WEB_SITE="http://www.asterisk.org/"
     1.7 -WGET_URL="http://downloads.asterisk.org/pub/telephony/asterisk/$TARBALL"
     1.8 +WGET_URL="http://downloads.asterisk.org/pub/telephony/asterisk/releases/$TARBALL"
     1.9  DEPENDS="openssl ncurses zlib libogg libvorbis curl newt libusb-compat alsa-lib \
    1.10  speex iksemel spandsp tiff radiusclient-ng nbs freetds libpostgresqlclient \
    1.11  libmysqlclient libunixODBC popt dahdi libpri lua libcap attr net-snmp \
    1.12  portaudio sqlite libkrb5 libcomerr3 libsdl-image"
    1.13 -BUILD_DEPENDS="gtk+-dev libxml2-dev postgresql-dev libsdl-dev \
    1.14 +BUILD_DEPENDS="gtk+-dev libxml2-dev postgresql-dev libsdl-dev ncurses-dev \
    1.15  gmime gmime-dev unixODBC-dev unixODBC openldap-dev openldap \
    1.16  dahdi-linux dahdi-tools"
    1.17  CONFIG_FILES="/etc/asterisk"
    1.18 @@ -34,7 +34,8 @@
    1.19  		's/define AST_PBX_MAX_STACK.*/define AST_PBX_MAX_STACK 1024/'
    1.20  	[ -s $SOURCES_REPOSITORY/rfc3951.txt ] ||
    1.21  		wget -P $SOURCES_REPOSITORY http://www.ietf.org/rfc/rfc3951.txt
    1.22 -	cp $SOURCES_REPOSITORY/rfc3951.txt codecs/ilbc
    1.23 +	cp $SOURCES_REPOSITORY/rfc3951.txt codecs/ilbc ||
    1.24 +	cp $stuff/rfc3951.txt
    1.25  	[ -f codecs/ilbc/iLBC_define.h ] || ( cd codecs/ilbc &&
    1.26  		awk -f $stuff/extract-cfile.awk rfc3951.txt > /dev/null )
    1.27  	busybox sed -i '/codec_ilbc/{ns/no/yes/}' menuselect-tree
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/asterisk/stuff/rfc3951.txt	Sat May 12 10:02:55 2012 +0200
     2.3 @@ -0,0 +1,10867 @@
     2.4 +
     2.5 +
     2.6 +
     2.7 +
     2.8 +
     2.9 +
    2.10 +Network Working Group                                        S. Andersen
    2.11 +Request for Comments: 3951                            Aalborg University
    2.12 +Category: Experimental                                          A. Duric
    2.13 +                                                                   Telio
    2.14 +                                                               H. Astrom
    2.15 +                                                                R. Hagen
    2.16 +                                                               W. Kleijn
    2.17 +                                                               J. Linden
    2.18 +                                                         Global IP Sound
    2.19 +                                                           December 2004
    2.20 +
    2.21 +
    2.22 +                   Internet Low Bit Rate Codec (iLBC)
    2.23 +
    2.24 +Status of this Memo
    2.25 +
    2.26 +   This memo defines an Experimental Protocol for the Internet
    2.27 +   community.  It does not specify an Internet standard of any kind.
    2.28 +   Discussion and suggestions for improvement are requested.
    2.29 +   Distribution of this memo is unlimited.
    2.30 +
    2.31 +Copyright Notice
    2.32 +
    2.33 +   Copyright (C) The Internet Society (2004).
    2.34 +
    2.35 +Abstract
    2.36 +
    2.37 +   This document specifies a speech codec suitable for robust voice
    2.38 +   communication over IP.  The codec is developed by Global IP Sound
    2.39 +   (GIPS).  It is designed for narrow band speech and results in a
    2.40 +   payload bit rate of 13.33 kbit/s for 30 ms frames and 15.20 kbit/s
    2.41 +   for 20 ms frames.  The codec enables graceful speech quality
    2.42 +   degradation in the case of lost frames, which occurs in connection
    2.43 +   with lost or delayed IP packets.
    2.44 +
    2.45 +
    2.46 +
    2.47 +
    2.48 +
    2.49 +
    2.50 +
    2.51 +
    2.52 +
    2.53 +
    2.54 +
    2.55 +
    2.56 +
    2.57 +
    2.58 +
    2.59 +
    2.60 +
    2.61 +Andersen, et al.              Experimental                      [Page 1]
    2.62 +
    2.63 +RFC 3951              Internet Low Bit Rate Codec          December 2004
    2.64 +
    2.65 +
    2.66 +Table of Contents
    2.67 +
    2.68 +   1.  Introduction . . . . . . . . . . . . . . . . . . . . . . . . .  4
    2.69 +   2.  Outline of the Codec . . . . . . . . . . . . . . . . . . . . .  5
    2.70 +       2.1.  Encoder. . . . . . . . . . . . . . . . . . . . . . . . .  5
    2.71 +       2.2.  Decoder. . . . . . . . . . . . . . . . . . . . . . . . .  7
    2.72 +   3.  Encoder Principles . . . . . . . . . . . . . . . . . . . . . .  7
    2.73 +       3.1.  Pre-processing . . . . . . . . . . . . . . . . . . . . .  9
    2.74 +       3.2.  LPC Analysis and Quantization. . . . . . . . . . . . . .  9
    2.75 +             3.2.1.  Computation of Autocorrelation Coefficients. . . 10
    2.76 +             3.2.2.  Computation of LPC Coefficients. . . . . . . . . 11
    2.77 +             3.2.3.  Computation of LSF Coefficients from LPC
    2.78 +                     Coefficients . . . . . . . . . . . . . . . . . . 11
    2.79 +             3.2.4.  Quantization of LSF Coefficients . . . . . . . . 12
    2.80 +             3.2.5.  Stability Check of LSF Coefficients. . . . . . . 13
    2.81 +             3.2.6.  Interpolation of LSF Coefficients. . . . . . . . 13
    2.82 +             3.2.7.  LPC Analysis and Quantization for 20 ms Frames . 14
    2.83 +       3.3.  Calculation of the Residual. . . . . . . . . . . . . . . 15
    2.84 +       3.4.  Perceptual Weighting Filter. . . . . . . . . . . . . . . 15
    2.85 +       3.5.  Start State Encoder. . . . . . . . . . . . . . . . . . . 15
    2.86 +             3.5.1.  Start State Estimation . . . . . . . . . . . . . 16
    2.87 +             3.5.2.  All-Pass Filtering and Scale Quantization. . . . 17
    2.88 +             3.5.3.  Scalar Quantization. . . . . . . . . . . . . . . 18
    2.89 +       3.6.  Encoding the Remaining Samples . . . . . . . . . . . . . 19
    2.90 +             3.6.1.  Codebook Memory. . . . . . . . . . . . . . . . . 20
    2.91 +             3.6.2.  Perceptual Weighting of Codebook Memory
    2.92 +                     and Target . . . . . . . . . . . . . . . . . . . 22
    2.93 +             3.6.3.  Codebook Creation. . . . . . . . . . . . . . . . 23
    2.94 +                     3.6.3.1. Creation of a Base Codebook . . . . . . 23
    2.95 +                     3.6.3.2. Codebook Expansion. . . . . . . . . . . 24
    2.96 +                     3.6.3.3. Codebook Augmentation . . . . . . . . . 24
    2.97 +             3.6.4.  Codebook Search. . . . . . . . . . . . . . . . . 26
    2.98 +                     3.6.4.1. Codebook Search at Each Stage . . . . . 26
    2.99 +                     3.6.4.2. Gain Quantization at Each Stage . . . . 27
   2.100 +                     3.6.4.3. Preparation of Target for Next Stage. . 28
   2.101 +       3.7.  Gain Correction Encoding . . . . . . . . . . . . . . . . 28
   2.102 +       3.8.  Bitstream Definition . . . . . . . . . . . . . . . . . . 29
   2.103 +   4.  Decoder Principles . . . . . . . . . . . . . . . . . . . . . . 32
   2.104 +       4.1.  LPC Filter Reconstruction. . . . . . . . . . . . . . . . 33
   2.105 +       4.2.  Start State Reconstruction . . . . . . . . . . . . . . . 33
   2.106 +       4.3.  Excitation Decoding Loop . . . . . . . . . . . . . . . . 34
   2.107 +       4.4.  Multistage Adaptive Codebook Decoding. . . . . . . . . . 35
   2.108 +             4.4.1.  Construction of the Decoded Excitation Signal. . 35
   2.109 +       4.5.  Packet Loss Concealment. . . . . . . . . . . . . . . . . 35
   2.110 +             4.5.1.  Block Received Correctly and Previous Block
   2.111 +                     Also Received. . . . . . . . . . . . . . . . . . 35
   2.112 +             4.5.2.  Block Not Received . . . . . . . . . . . . . . . 36
   2.113 +
   2.114 +
   2.115 +
   2.116 +
   2.117 +Andersen, et al.              Experimental                      [Page 2]
   2.118 +
   2.119 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.120 +
   2.121 +
   2.122 +             4.5.3.  Block Received Correctly When Previous Block
   2.123 +                     Not Received . . . . . . . . . . . . . . . . . . 36
   2.124 +       4.6.  Enhancement. . . . . . . . . . . . . . . . . . . . . . . 37
   2.125 +             4.6.1.  Estimating the Pitch . . . . . . . . . . . . . . 39
   2.126 +             4.6.2.  Determination of the Pitch-Synchronous
   2.127 +                     Sequences. . . . . . . . . . . . . . . . . . . . 39
   2.128 +             4.6.3.  Calculation of the Smoothed Excitation . . . . . 41
   2.129 +             4.6.4.  Enhancer Criterion . . . . . . . . . . . . . . . 41
   2.130 +             4.6.5.  Enhancing the Excitation . . . . . . . . . . . . 42
   2.131 +       4.7.  Synthesis Filtering. . . . . . . . . . . . . . . . . . . 43
   2.132 +       4.8.  Post Filtering . . . . . . . . . . . . . . . . . . . . . 43
   2.133 +   5.  Security Considerations. . . . . . . . . . . . . . . . . . . . 43
   2.134 +   6.  Evaluation of the iLBC Implementations . . . . . . . . . . . . 43
   2.135 +   7.  References . . . . . . . . . . . . . . . . . . . . . . . . . . 43
   2.136 +       7.1.  Normative References . . . . . . . . . . . . . . . . . . 43
   2.137 +       7.2.  Informative References . . . . . . . . . . . . . . . . . 44
   2.138 +   8.  ACKNOWLEDGEMENTS . . . . . . . . . . . . . . . . . . . . . . . 44
   2.139 +   APPENDIX A: Reference Implementation . . . . . . . . . . . . . . . 45
   2.140 +       A.1.  iLBC_test.c. . . . . . . . . . . . . . . . . . . . . . . 46
   2.141 +       A.2   iLBC_encode.h. . . . . . . . . . . . . . . . . . . . . . 52
   2.142 +       A.3.  iLBC_encode.c. . . . . . . . . . . . . . . . . . . . . . 53
   2.143 +       A.4.  iLBC_decode.h. . . . . . . . . . . . . . . . . . . . . . 63
   2.144 +       A.5.  iLBC_decode.c. . . . . . . . . . . . . . . . . . . . . . 64
   2.145 +       A.6.  iLBC_define.h. . . . . . . . . . . . . . . . . . . . . . 76
   2.146 +       A.7.  constants.h. . . . . . . . . . . . . . . . . . . . . . . 80
   2.147 +       A.8.  constants.c. . . . . . . . . . . . . . . . . . . . . . . 82
   2.148 +       A.9.  anaFilter.h. . . . . . . . . . . . . . . . . . . . . . . 96
   2.149 +       A.10. anaFilter.c. . . . . . . . . . . . . . . . . . . . . . . 97
   2.150 +       A.11. createCB.h . . . . . . . . . . . . . . . . . . . . . . . 98
   2.151 +       A.12. createCB.c . . . . . . . . . . . . . . . . . . . . . . . 99
   2.152 +       A.13. doCPLC.h . . . . . . . . . . . . . . . . . . . . . . . .104
   2.153 +       A.14. doCPLC.c . . . . . . . . . . . . . . . . . . . . . . . .104
   2.154 +       A.15. enhancer.h . . . . . . . . . . . . . . . . . . . . . . .109
   2.155 +       A.16. enhancer.c . . . . . . . . . . . . . . . . . . . . . . .110
   2.156 +       A.17. filter.h . . . . . . . . . . . . . . . . . . . . . . . .123
   2.157 +       A.18. filter.c . . . . . . . . . . . . . . . . . . . . . . . .125
   2.158 +       A.19. FrameClassify.h. . . . . . . . . . . . . . . . . . . . .128
   2.159 +       A.20. FrameClassify.c. . . . . . . . . . . . . . . . . . . . .129
   2.160 +       A.21. gainquant.h. . . . . . . . . . . . . . . . . . . . . . .131
   2.161 +       A.22. gainquant.c. . . . . . . . . . . . . . . . . . . . . . .131
   2.162 +       A.23. getCBvec.h . . . . . . . . . . . . . . . . . . . . . . .134
   2.163 +       A.24. getCBvec.c . . . . . . . . . . . . . . . . . . . . . . .134
   2.164 +       A.25. helpfun.h. . . . . . . . . . . . . . . . . . . . . . . .138
   2.165 +       A.26. helpfun.c. . . . . . . . . . . . . . . . . . . . . . . .140
   2.166 +       A.27. hpInput.h. . . . . . . . . . . . . . . . . . . . . . . .146
   2.167 +       A.28. hpInput.c. . . . . . . . . . . . . . . . . . . . . . . .146
   2.168 +       A.29. hpOutput.h . . . . . . . . . . . . . . . . . . . . . . .148
   2.169 +       A.30. hpOutput.c . . . . . . . . . . . . . . . . . . . . . . .148
   2.170 +
   2.171 +
   2.172 +
   2.173 +Andersen, et al.              Experimental                      [Page 3]
   2.174 +
   2.175 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.176 +
   2.177 +
   2.178 +       A.31. iCBConstruct.h . . . . . . . . . . . . . . . . . . . . .149
   2.179 +       A.32. iCBConstruct.c . . . . . . . . . . . . . . . . . . . . .150
   2.180 +       A.33. iCBSearch.h. . . . . . . . . . . . . . . . . . . . . . .152
   2.181 +       A.34. iCBSearch.c. . . . . . . . . . . . . . . . . . . . . . .153
   2.182 +       A.35. LPCdecode.h. . . . . . . . . . . . . . . . . . . . . . .163
   2.183 +       A.36. LPCdecode.c. . . . . . . . . . . . . . . . . . . . . . .164
   2.184 +       A.37. LPCencode.h. . . . . . . . . . . . . . . . . . . . . . .167
   2.185 +       A.38. LPCencode.c. . . . . . . . . . . . . . . . . . . . . . .167
   2.186 +       A.39. lsf.h. . . . . . . . . . . . . . . . . . . . . . . . . .172
   2.187 +       A.40. lsf.c. . . . . . . . . . . . . . . . . . . . . . . . . .172
   2.188 +       A.41. packing.h. . . . . . . . . . . . . . . . . . . . . . . .178
   2.189 +       A.42. packing.c. . . . . . . . . . . . . . . . . . . . . . . .179
   2.190 +       A.43. StateConstructW.h. . . . . . . . . . . . . . . . . . . .182
   2.191 +       A.44. StateConstructW.c. . . . . . . . . . . . . . . . . . . .183
   2.192 +       A.45. StateSearchW.h . . . . . . . . . . . . . . . . . . . . .185
   2.193 +       A.46. StateSearchW.c . . . . . . . . . . . . . . . . . . . . .186
   2.194 +       A.47. syntFilter.h . . . . . . . . . . . . . . . . . . . . . .190
   2.195 +       A.48. syntFilter.c . . . . . . . . . . . . . . . . . . . . . .190
   2.196 +   Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . .192
   2.197 +   Full Copyright Statement . . . . . . . . . . . . . . . . . . . . .194
   2.198 +
   2.199 +1.  Introduction
   2.200 +
   2.201 +   This document contains the description of an algorithm for the coding
   2.202 +   of speech signals sampled at 8 kHz.  The algorithm, called iLBC, uses
   2.203 +   a block-independent linear-predictive coding (LPC) algorithm and has
   2.204 +   support for two basic frame lengths: 20 ms at 15.2 kbit/s and 30 ms
   2.205 +   at 13.33 kbit/s.  When the codec operates at block lengths of 20 ms,
   2.206 +   it produces 304 bits per block, which SHOULD be packetized as in [1].
   2.207 +   Similarly, for block lengths of 30 ms it produces 400 bits per block,
   2.208 +   which SHOULD be packetized as in [1].  The two modes for the
   2.209 +   different frame sizes operate in a very similar way.  When they
   2.210 +   differ it is explicitly stated in the text, usually with the notation
   2.211 +   x/y, where x refers to the 20 ms mode and y refers to the 30 ms mode.
   2.212 +
   2.213 +   The described algorithm results in a speech coding system with a
   2.214 +   controlled response to packet losses similar to what is known from
   2.215 +   pulse code modulation (PCM) with packet loss concealment (PLC), such
   2.216 +   as the ITU-T G.711 standard [4], which operates at a fixed bit rate
   2.217 +   of 64 kbit/s.  At the same time, the described algorithm enables
   2.218 +   fixed bit rate coding with a quality-versus-bit rate tradeoff close
   2.219 +   to state-of-the-art.  A suitable RTP payload format for the iLBC
   2.220 +   codec is specified in [1].
   2.221 +
   2.222 +   Some of the applications for which this coder is suitable are real
   2.223 +   time communications such as telephony and videoconferencing,
   2.224 +   streaming audio, archival, and messaging.
   2.225 +
   2.226 +
   2.227 +
   2.228 +
   2.229 +Andersen, et al.              Experimental                      [Page 4]
   2.230 +
   2.231 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.232 +
   2.233 +
   2.234 +   Cable Television Laboratories (CableLabs(R)) has adopted iLBC as a
   2.235 +   mandatory PacketCable(TM) audio codec standard for VoIP over Cable
   2.236 +   applications [3].
   2.237 +
   2.238 +   This document is organized as follows.  Section 2 gives a brief
   2.239 +   outline of the codec.  The specific encoder and decoder algorithms
   2.240 +   are explained in sections 3 and 4, respectively.  Appendix A provides
   2.241 +   a c-code reference implementation.
   2.242 +
   2.243 +   The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
   2.244 +   "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
   2.245 +   document are to be interpreted as described in BCP 14, RFC 2119 [2].
   2.246 +
   2.247 +2.  Outline of the Codec
   2.248 +
   2.249 +   The codec consists of an encoder and a decoder as described in
   2.250 +   sections 2.1 and 2.2, respectively.
   2.251 +
   2.252 +   The essence of the codec is LPC and block-based coding of the LPC
   2.253 +   residual signal.  For each 160/240 (20 ms/30 ms) sample block, the
   2.254 +   following major steps are performed: A set of LPC filters are
   2.255 +   computed, and the speech signal is filtered through them to produce
   2.256 +   the residual signal.  The codec uses scalar quantization of the
   2.257 +   dominant part, in terms of energy, of the residual signal for the
   2.258 +   block.  The dominant state is of length 57/58 (20 ms/30 ms) samples
   2.259 +   and forms a start state for dynamic codebooks constructed from the
   2.260 +   already coded parts of the residual signal.  These dynamic codebooks
   2.261 +   are used to code the remaining parts of the residual signal.  By this
   2.262 +   method, coding independence between blocks is achieved, resulting in
   2.263 +   elimination of propagation of perceptual degradations due to packet
   2.264 +   loss.  The method facilitates high-quality packet loss concealment
   2.265 +   (PLC).
   2.266 +
   2.267 +2.1.  Encoder
   2.268 +
   2.269 +   The input to the encoder SHOULD be 16 bit uniform PCM sampled at 8
   2.270 +   kHz.  It SHOULD be partitioned into blocks of BLOCKL=160/240 samples
   2.271 +   for the 20/30 ms frame size.  Each block is divided into NSUB=4/6
   2.272 +   consecutive sub-blocks of SUBL=40 samples each.  For 30 ms frame
   2.273 +   size, the encoder performs two LPC_FILTERORDER=10 linear-predictive
   2.274 +   coding (LPC) analyses.  The first analysis applies a smooth window
   2.275 +   centered over the second sub-block and extending to the middle of the
   2.276 +   fifth sub-block.  The second LPC analysis applies a smooth asymmetric
   2.277 +   window centered over the fifth sub-block and extending to the end of
   2.278 +   the sixth sub-block.  For 20 ms frame size, one LPC_FILTERORDER=10
   2.279 +   linear-predictive coding (LPC) analysis is performed with a smooth
   2.280 +   window centered over the third sub-frame.
   2.281 +
   2.282 +
   2.283 +
   2.284 +
   2.285 +Andersen, et al.              Experimental                      [Page 5]
   2.286 +
   2.287 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.288 +
   2.289 +
   2.290 +   For each of the LPC analyses, a set of line-spectral frequencies
   2.291 +   (LSFs) are obtained, quantized, and interpolated to obtain LSF
   2.292 +   coefficients for each sub-block.  Subsequently, the LPC residual is
   2.293 +   computed by using the quantized and interpolated LPC analysis
   2.294 +   filters.
   2.295 +
   2.296 +   The two consecutive sub-blocks of the residual exhibiting the maximal
   2.297 +   weighted energy are identified.  Within these two sub-blocks, the
   2.298 +   start state (segment) is selected from two choices: the first 57/58
   2.299 +   samples or the last 57/58 samples of the two consecutive sub-blocks.
   2.300 +   The selected segment is the one of higher energy.  The start state is
   2.301 +   encoded with scalar quantization.
   2.302 +
   2.303 +   A dynamic codebook encoding procedure is used to encode 1) the 23/22
   2.304 +   (20 ms/30 ms) remaining samples in the two sub-blocks containing the
   2.305 +   start state; 2) the sub-blocks after the start state in time; and 3)
   2.306 +   the sub-blocks before the start state in time.  Thus, the encoding
   2.307 +   target can be either the 23/22 samples remaining of the two sub-
   2.308 +   blocks containing the start state or a 40-sample sub-block.  This
   2.309 +   target can consist of samples indexed forward in time or backward in
   2.310 +   time, depending on the location of the start state.
   2.311 +
   2.312 +   The codebook coding is based on an adaptive codebook built from a
   2.313 +   codebook memory that contains decoded LPC excitation samples from the
   2.314 +   already encoded part of the block.  These samples are indexed in the
   2.315 +   same time direction as the target vector, ending at the sample
   2.316 +   instant prior to the first sample instant represented in the target
   2.317 +   vector.  The codebook is used in CB_NSTAGES=3 stages in a successive
   2.318 +   refinement approach, and the resulting three code vector gains are
   2.319 +   encoded with 5-, 4-, and 3-bit scalar quantization, respectively.
   2.320 +
   2.321 +   The codebook search method employs noise shaping derived from the LPC
   2.322 +   filters, and the main decision criterion is to minimize the squared
   2.323 +   error between the target vector and the code vectors.  Each code
   2.324 +   vector in this codebook comes from one of CB_EXPAND=2 codebook
   2.325 +   sections.  The first section is filled with delayed, already encoded
   2.326 +   residual vectors.  The code vectors of the second codebook section
   2.327 +   are constructed by predefined linear combinations of vectors in the
   2.328 +   first section of the codebook.
   2.329 +
   2.330 +   As codebook encoding with squared-error matching is known to produce
   2.331 +   a coded signal of less power than does the scalar quantized start
   2.332 +   state signal, a gain re-scaling method is implemented by a refined
   2.333 +   search for a better set of codebook gains in terms of power matching
   2.334 +   after encoding.  This is done by searching for a higher value of the
   2.335 +   gain factor for the first stage codebook, as the subsequent stage
   2.336 +   codebook gains are scaled by the first stage gain.
   2.337 +
   2.338 +
   2.339 +
   2.340 +
   2.341 +Andersen, et al.              Experimental                      [Page 6]
   2.342 +
   2.343 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.344 +
   2.345 +
   2.346 +2.2.  Decoder
   2.347 +
   2.348 +   Typically for packet communications, a jitter buffer placed at the
   2.349 +   receiving end decides whether the packet containing an encoded signal
   2.350 +   block has been received or lost.  This logic is not part of the codec
   2.351 +   described here.  For each encoded signal block received the decoder
   2.352 +   performs a decoding.  For each lost signal block, the decoder
   2.353 +   performs a PLC operation.
   2.354 +
   2.355 +   The decoding for each block starts by decoding and interpolating the
   2.356 +   LPC coefficients.  Subsequently the start state is decoded.
   2.357 +
   2.358 +   For codebook-encoded segments, each segment is decoded by
   2.359 +   constructing the three code vectors given by the received codebook
   2.360 +   indices in the same way that the code vectors were constructed in the
   2.361 +   encoder.  The three gain factors are also decoded and the resulting
   2.362 +   decoded signal is given by the sum of the three codebook vectors
   2.363 +   scaled with respective gain.
   2.364 +
   2.365 +   An enhancement algorithm is applied to the reconstructed excitation
   2.366 +   signal.  This enhancement augments the periodicity of voiced speech
   2.367 +   regions.  The enhancement is optimized under the constraint that the
   2.368 +   modification signal (defined as the difference between the enhanced
   2.369 +   excitation and the excitation signal prior to enhancement) has a
   2.370 +   short-time energy that does not exceed a preset fraction of the
   2.371 +   short-time energy of the excitation signal prior to enhancement.
   2.372 +
   2.373 +   A packet loss concealment (PLC) operation is easily embedded in the
   2.374 +   decoder.  The PLC operation can, e.g., be based on repeating LPC
   2.375 +   filters and obtaining the LPC residual signal by using a long-term
   2.376 +   prediction estimate from previous residual blocks.
   2.377 +
   2.378 +3.  Encoder Principles
   2.379 +
   2.380 +   The following block diagram is an overview of all the components of
   2.381 +   the iLBC encoding procedure.  The description of the blocks contains
   2.382 +   references to the section where that particular procedure is further
   2.383 +   described.
   2.384 +
   2.385 +
   2.386 +
   2.387 +
   2.388 +
   2.389 +
   2.390 +
   2.391 +
   2.392 +
   2.393 +
   2.394 +
   2.395 +
   2.396 +
   2.397 +Andersen, et al.              Experimental                      [Page 7]
   2.398 +
   2.399 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.400 +
   2.401 +
   2.402 +             +-----------+    +---------+    +---------+
   2.403 +   speech -> | 1. Pre P  | -> | 2. LPC  | -> | 3. Ana  | ->
   2.404 +             +-----------+    +---------+    +---------+
   2.405 +
   2.406 +             +---------------+   +--------------+
   2.407 +          -> | 4. Start Sel  | ->| 5. Scalar Qu | ->
   2.408 +             +---------------+   +--------------+
   2.409 +
   2.410 +             +--------------+    +---------------+
   2.411 +          -> |6. CB Search  | -> | 7. Packetize  | -> payload
   2.412 +          |  +--------------+ |  +---------------+
   2.413 +          ----<---------<------
   2.414 +       sub-frame 0..2/4 (20 ms/30 ms)
   2.415 +
   2.416 +   Figure 3.1. Flow chart of the iLBC encoder
   2.417 +
   2.418 +   1. Pre-process speech with a HP filter, if needed (section 3.1).
   2.419 +
   2.420 +   2. Compute LPC parameters, quantize, and interpolate (section 3.2).
   2.421 +
   2.422 +   3. Use analysis filters on speech to compute residual (section 3.3).
   2.423 +
   2.424 +   4. Select position of 57/58-sample start state (section 3.5).
   2.425 +
   2.426 +   5. Quantize the 57/58-sample start state with scalar quantization
   2.427 +      (section 3.5).
   2.428 +
   2.429 +   6. Search the codebook for each sub-frame.  Start with 23/22 sample
   2.430 +      block, then encode sub-blocks forward in time, and then encode
   2.431 +      sub-blocks backward in time.  For each block, the steps in Figure
   2.432 +      3.4 are performed (section 3.6).
   2.433 +
   2.434 +   7. Packetize the bits into the payload specified in Table 3.2.
   2.435 +
   2.436 +   The input to the encoder SHOULD be 16-bit uniform PCM sampled at 8
   2.437 +   kHz.  Also it SHOULD be partitioned into blocks of BLOCKL=160/240
   2.438 +   samples.  Each block input to the encoder is divided into NSUB=4/6
   2.439 +   consecutive sub-blocks of SUBL=40 samples each.
   2.440 +
   2.441 +
   2.442 +
   2.443 +
   2.444 +
   2.445 +
   2.446 +
   2.447 +
   2.448 +
   2.449 +
   2.450 +
   2.451 +
   2.452 +
   2.453 +Andersen, et al.              Experimental                      [Page 8]
   2.454 +
   2.455 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.456 +
   2.457 +
   2.458 +             0        39        79       119       159
   2.459 +             +---------------------------------------+
   2.460 +             |    1    |    2    |    3    |    4    |
   2.461 +             +---------------------------------------+
   2.462 +                            20 ms frame
   2.463 +
   2.464 +   0        39        79       119       159       199       239
   2.465 +   +-----------------------------------------------------------+
   2.466 +   |    1    |    2    |    3    |    4    |    5    |    6    |
   2.467 +   +-----------------------------------------------------------+
   2.468 +                                  30 ms frame
   2.469 +   Figure 3.2. One input block to the encoder for 20 ms (with four sub-
   2.470 +   frames) and 30 ms (with six sub-frames).
   2.471 +
   2.472 +3.1.  Pre-processing
   2.473 +
   2.474 +   In some applications, the recorded speech signal contains DC level
   2.475 +   and/or 50/60 Hz noise.  If these components have not been removed
   2.476 +   prior to the encoder call, they should be removed by a high-pass
   2.477 +   filter.  A reference implementation of this, using a filter with a
   2.478 +   cutoff frequency of 90 Hz, can be found in Appendix A.28.
   2.479 +
   2.480 +3.2.  LPC Analysis and Quantization
   2.481 +
   2.482 +   The input to the LPC analysis module is a possibly high-pass filtered
   2.483 +   speech buffer, speech_hp, that contains 240/300 (LPC_LOOKBACK +
   2.484 +   BLOCKL = 80/60 + 160/240 = 240/300) speech samples, where samples 0
   2.485 +   through 79/59 are from the previous block and samples 80/60 through
   2.486 +   239/299 are from the current block.  No look-ahead into the next
   2.487 +   block is used.  For the very first block processed, the look-back
   2.488 +   samples are assumed to be zeros.
   2.489 +
   2.490 +   For each input block, the LPC analysis calculates one/two set(s) of
   2.491 +   LPC_FILTERORDER=10 LPC filter coefficients using the autocorrelation
   2.492 +   method and the Levinson-Durbin recursion.  These coefficients are
   2.493 +   converted to the Line Spectrum Frequency representation.  In the 20
   2.494 +   ms case, the single lsf set represents the spectral characteristics
   2.495 +   as measured at the center of the third sub-block.  For 30 ms frames,
   2.496 +   the first set, lsf1, represents the spectral properties of the input
   2.497 +   signal at the center of the second sub-block, and the other set,
   2.498 +   lsf2, represents the spectral characteristics as measured at the
   2.499 +   center of the fifth sub-block.  The details of the computation for 30
   2.500 +   ms frames are described in sections 3.2.1 through 3.2.6.  Section
   2.501 +   3.2.7 explains how the LPC Analysis and Quantization differs for 20
   2.502 +   ms frames.
   2.503 +
   2.504 +
   2.505 +
   2.506 +
   2.507 +
   2.508 +
   2.509 +Andersen, et al.              Experimental                      [Page 9]
   2.510 +
   2.511 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.512 +
   2.513 +
   2.514 +3.2.1.  Computation of Autocorrelation Coefficients
   2.515 +
   2.516 +   The first step in the LPC analysis procedure is to calculate
   2.517 +   autocorrelation coefficients by using windowed speech samples.  This
   2.518 +   windowing is the only difference in the LPC analysis procedure for
   2.519 +   the two sets of coefficients.  For the first set, a 240-sample-long
   2.520 +   standard symmetric Hanning window is applied to samples 0 through 239
   2.521 +   of the input data.  The first window, lpc_winTbl, is defined as
   2.522 +
   2.523 +      lpc_winTbl[i]= 0.5 * (1.0 - cos((2*PI*(i+1))/(BLOCKL+1)));
   2.524 +               i=0,...,119
   2.525 +      lpc_winTbl[i] = winTbl[BLOCKL - i - 1]; i=120,...,239
   2.526 +
   2.527 +   The windowed speech speech_hp_win1 is then obtained by multiplying
   2.528 +   the first 240 samples of the input speech buffer with the window
   2.529 +   coefficients:
   2.530 +
   2.531 +      speech_hp_win1[i] = speech_hp[i] * lpc_winTbl[i];
   2.532 +               i=0,...,BLOCKL-1
   2.533 +
   2.534 +   From these 240 windowed speech samples, 11 (LPC_FILTERORDER + 1)
   2.535 +   autocorrelation coefficients, acf1, are calculated:
   2.536 +
   2.537 +      acf1[lag] += speech_hp_win1[n] * speech_hp_win1[n + lag];
   2.538 +               lag=0,...,LPC_FILTERORDER; n=0,...,BLOCKL-lag-1
   2.539 +
   2.540 +   In order to make the analysis more robust against numerical precision
   2.541 +   problems, a spectral smoothing procedure is applied by windowing the
   2.542 +   autocorrelation coefficients before the LPC coefficients are
   2.543 +   computed.  Also, a white noise floor is added to the autocorrelation
   2.544 +   function by multiplying coefficient zero by 1.0001 (40dB below the
   2.545 +   energy of the windowed speech signal).  These two steps are
   2.546 +   implemented by multiplying the autocorrelation coefficients with the
   2.547 +   following window:
   2.548 +
   2.549 +      lpc_lagwinTbl[0] = 1.0001;
   2.550 +      lpc_lagwinTbl[i] = exp(-0.5 * ((2 * PI * 60.0 * i) /FS)^2);
   2.551 +               i=1,...,LPC_FILTERORDER
   2.552 +               where FS=8000 is the sampling frequency
   2.553 +
   2.554 +   Then, the windowed acf function acf1_win is obtained by
   2.555 +
   2.556 +      acf1_win[i] = acf1[i] * lpc_lagwinTbl[i];
   2.557 +               i=0,...,LPC_FILTERORDER
   2.558 +
   2.559 +   The second set of autocorrelation coefficients, acf2_win, are
   2.560 +   obtained in a similar manner.  The window, lpc_asymwinTbl, is applied
   2.561 +   to samples 60 through 299, i.e., the entire current block.  The
   2.562 +
   2.563 +
   2.564 +
   2.565 +Andersen, et al.              Experimental                     [Page 10]
   2.566 +
   2.567 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.568 +
   2.569 +
   2.570 +   window consists of two segments, the first (samples 0 to 219) being
   2.571 +   half a Hanning window with length 440 and the second a quarter of a
   2.572 +   cycle of a cosine wave.  By using this asymmetric window, an LPC
   2.573 +   analysis centered in the fifth sub-block is obtained without the need
   2.574 +   for any look-ahead, which would add delay.  The asymmetric window is
   2.575 +   defined as
   2.576 +
   2.577 +      lpc_asymwinTbl[i] = (sin(PI * (i + 1) / 441))^2; i=0,...,219
   2.578 +
   2.579 +      lpc_asymwinTbl[i] = cos((i - 220) * PI / 40); i=220,...,239
   2.580 +
   2.581 +   and the windowed speech is computed by
   2.582 +
   2.583 +      speech_hp_win2[i] = speech_hp[i + LPC_LOOKBACK] *
   2.584 +               lpc_asymwinTbl[i];  i=0,....BLOCKL-1
   2.585 +
   2.586 +   The windowed autocorrelation coefficients are then obtained in
   2.587 +   exactly the same way as for the first analysis instance.
   2.588 +
   2.589 +   The generation of the windows lpc_winTbl, lpc_asymwinTbl, and
   2.590 +   lpc_lagwinTbl are typically done in advance, and the arrays are
   2.591 +   stored in ROM rather than repeating the calculation for every block.
   2.592 +
   2.593 +3.2.2.  Computation of LPC Coefficients
   2.594 +
   2.595 +   From the 2 x 11 smoothed autocorrelation coefficients, acf1_win and
   2.596 +   acf2_win, the 2 x 11 LPC coefficients, lp1 and lp2, are calculated
   2.597 +   in the same way for both analysis locations by using the well known
   2.598 +   Levinson-Durbin recursion.  The first LPC coefficient is always 1.0,
   2.599 +   resulting in ten unique coefficients.
   2.600 +
   2.601 +   After determining the LPC coefficients, a bandwidth expansion
   2.602 +   procedure is applied to smooth the spectral peaks in the
   2.603 +   short-term spectrum.  The bandwidth addition is obtained by the
   2.604 +   following modification of the LPC coefficients:
   2.605 +
   2.606 +      lp1_bw[i] = lp1[i] * chirp^i; i=0,...,LPC_FILTERORDER
   2.607 +      lp2_bw[i] = lp2[i] * chirp^i; i=0,...,LPC_FILTERORDER
   2.608 +
   2.609 +   where "chirp" is a real number between 0 and 1.  It is RECOMMENDED to
   2.610 +   use a value of 0.9.
   2.611 +
   2.612 +3.2.3.  Computation of LSF Coefficients from LPC Coefficients
   2.613 +
   2.614 +   Thus far, two sets of LPC coefficients that represent the short-term
   2.615 +   spectral characteristics of the speech signal for two different time
   2.616 +   locations within the current block have been determined.  These
   2.617 +   coefficients SHOULD be quantized and interpolated.  Before this is
   2.618 +
   2.619 +
   2.620 +
   2.621 +Andersen, et al.              Experimental                     [Page 11]
   2.622 +
   2.623 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.624 +
   2.625 +
   2.626 +   done, it is advantageous to convert the LPC parameters into another
   2.627 +   type of representation called Line Spectral Frequencies (LSF).  The
   2.628 +   LSF parameters are used because they are better suited for
   2.629 +   quantization and interpolation than the regular LPC coefficients.
   2.630 +   Many computationally efficient methods for calculating the LSFs from
   2.631 +   the LPC coefficients have been proposed in the literature.  The
   2.632 +   detailed implementation of one applicable method can be found in
   2.633 +   Appendix A.26.  The two arrays of LSF coefficients obtained, lsf1 and
   2.634 +   lsf2, are of dimension 10 (LPC_FILTERORDER).
   2.635 +
   2.636 +3.2.4.  Quantization of LSF Coefficients
   2.637 +
   2.638 +   Because the LPC filters defined by the two sets of LSFs are also
   2.639 +   needed in the decoder, the LSF parameters need to be quantized and
   2.640 +   transmitted as side information.  The total number of bits required
   2.641 +   to represent the quantization of the two LSF representations for one
   2.642 +   block of speech is 40, with 20 bits used for each of lsf1 and lsf2.
   2.643 +
   2.644 +   For computational and storage reasons, the LSF vectors are quantized
   2.645 +   using three-split vector quantization (VQ).  That is, the LSF vectors
   2.646 +   are split into three sub-vectors that are each quantized with a
   2.647 +   regular VQ.  The quantized versions of lsf1 and lsf2, qlsf1 and
   2.648 +   qlsf2, are obtained by using the same memoryless split VQ.  The
   2.649 +   length of each of these two LSF vectors is 10, and they are split
   2.650 +   into three sub-vectors containing 3, 3, and 4 values, respectively.
   2.651 +
   2.652 +   For each of the sub-vectors, a separate codebook of quantized values
   2.653 +   has been designed with a standard VQ training method for a large
   2.654 +   database containing speech from a large number of speakers recorded
   2.655 +   under various conditions.  The size of each of the three codebooks
   2.656 +   associated with the split definitions above is
   2.657 +
   2.658 +      int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128};
   2.659 +
   2.660 +   The actual values of the vector quantization codebook that must be
   2.661 +   used can be found in the reference code of Appendix A.  Both sets of
   2.662 +   LSF coefficients, lsf1 and lsf2, are quantized with a standard
   2.663 +   memoryless split vector quantization (VQ) structure using the squared
   2.664 +   error criterion in the LSF domain.  The split VQ quantization
   2.665 +   consists of the following steps:
   2.666 +
   2.667 +   1) Quantize the first three LSF coefficients (1 - 3) with a VQ
   2.668 +      codebook of size 64.
   2.669 +   2) Quantize the next three LSF coefficients 4 - 6 with VQ a codebook
   2.670 +      of size 128.
   2.671 +   3) Quantize the last four LSF coefficients (7 - 10) with a VQ
   2.672 +      codebook of size 128.
   2.673 +
   2.674 +
   2.675 +
   2.676 +
   2.677 +Andersen, et al.              Experimental                     [Page 12]
   2.678 +
   2.679 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.680 +
   2.681 +
   2.682 +   This procedure, repeated for lsf1 and lsf2, gives six quantization
   2.683 +   indices and the quantized sets of LSF coefficients qlsf1 and qlsf2.
   2.684 +   Each set of three indices is encoded with 6 + 7 + 7 = 20 bits.  The
   2.685 +   total number of bits used for LSF quantization in a block is thus 40
   2.686 +   bits.
   2.687 +
   2.688 +3.2.5.  Stability Check of LSF Coefficients
   2.689 +
   2.690 +   The LSF representation of the LPC filter has the convenient property
   2.691 +   that the coefficients are ordered by increasing value, i.e., lsf(n-1)
   2.692 +   < lsf(n), 0 < n < 10, if the corresponding synthesis filter is
   2.693 +   stable.  As we are employing a split VQ scheme, it is possible that
   2.694 +   at the split boundaries the LSF coefficients are not ordered
   2.695 +   correctly and hence that the corresponding LP filter is unstable.  To
   2.696 +   ensure that the filter used is stable, a stability check is performed
   2.697 +   for the quantized LSF vectors.  If it turns out that the coefficients
   2.698 +   are not ordered appropriately (with a safety margin of 50 Hz to
   2.699 +   ensure that formant peaks are not too narrow), they will be moved
   2.700 +   apart.  The detailed method for this can be found in Appendix A.40.
   2.701 +   The same procedure is performed in the decoder.  This ensures that
   2.702 +   exactly the same LSF representations are used in both encoder and
   2.703 +   decoder.
   2.704 +
   2.705 +3.2.6.  Interpolation of LSF Coefficients
   2.706 +
   2.707 +   From the two sets of LSF coefficients that are computed for each
   2.708 +   block of speech, different LSFs are obtained for each sub-block by
   2.709 +   means of interpolation.  This procedure is performed for the original
   2.710 +   LSFs (lsf1 and lsf2), as well as the quantized versions qlsf1 and
   2.711 +   qlsf2, as both versions are used in the encoder.  Here follows a
   2.712 +   brief summary of the interpolation scheme; the details are found in
   2.713 +   the c-code of Appendix A.  In the first sub-block, the average of the
   2.714 +   second LSF vector from the previous block and the first LSF vector in
   2.715 +   the current block is used.  For sub-blocks two through five, the LSFs
   2.716 +   used are obtained by linear interpolation from lsf1 (and qlsf1) to
   2.717 +   lsf2 (and qlsf2), with lsf1 used in sub-block two and lsf2 in sub-
   2.718 +   block five.  In the last sub-block, lsf2 is used.  For the very first
   2.719 +   block it is assumed that the last LSF vector of the previous block is
   2.720 +   equal to a predefined vector, lsfmeanTbl, obtained by calculating the
   2.721 +   mean LSF vector of the LSF design database.
   2.722 +
   2.723 +   lsfmeanTbl[LPC_FILTERORDER] = {0.281738, 0.445801, 0.663330,
   2.724 +                  0.962524, 1.251831, 1.533081, 1.850586, 2.137817,
   2.725 +                  2.481445, 2.777344}
   2.726 +
   2.727 +
   2.728 +
   2.729 +
   2.730 +
   2.731 +
   2.732 +
   2.733 +Andersen, et al.              Experimental                     [Page 13]
   2.734 +
   2.735 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.736 +
   2.737 +
   2.738 +   The interpolation method is standard linear interpolation in the LSF
   2.739 +   domain.  The interpolated LSF values are converted to LPC
   2.740 +   coefficients for each sub-block.  The unquantized and quantized LPC
   2.741 +   coefficients form two sets of filters respectively.  The unquantized
   2.742 +   analysis filter for sub-block k is defined as follows
   2.743 +
   2.744 +                ___
   2.745 +                \
   2.746 +      Ak(z)= 1 + > ak(i)*z^(-i)
   2.747 +                /__
   2.748 +             i=1...LPC_FILTERORDER
   2.749 +
   2.750 +   The quantized analysis filter for sub-block k is defined as follows
   2.751 +                 ___
   2.752 +                 \
   2.753 +      A~k(z)= 1 + > a~k(i)*z^(-i)
   2.754 +                 /__
   2.755 +             i=1...LPC_FILTERORDER
   2.756 +
   2.757 +   A reference implementation of the lsf encoding is given in Appendix
   2.758 +   A.38.  A reference implementation of the corresponding decoding can
   2.759 +   be found in Appendix A.36.
   2.760 +
   2.761 +3.2.7.  LPC Analysis and Quantization for 20 ms Frames
   2.762 +
   2.763 +   As previously stated, the codec only calculates one set of LPC
   2.764 +   parameters for the 20 ms frame size as opposed to two sets for 30 ms
   2.765 +   frames.  A single set of autocorrelation coefficients is calculated
   2.766 +   on the LPC_LOOKBACK + BLOCKL = 80 + 160 = 240 samples.  These samples
   2.767 +   are windowed with the asymmetric window lpc_asymwinTbl, centered over
   2.768 +   the third sub-frame, to form speech_hp_win.  Autocorrelation
   2.769 +   coefficients, acf, are calculated on the 240 samples in speech_hp_win
   2.770 +   and then windowed exactly as in section 3.2.1 (resulting in
   2.771 +   acf_win).
   2.772 +
   2.773 +   This single set of windowed autocorrelation coefficients is used to
   2.774 +   calculate LPC coefficients, LSF coefficients, and quantized LSF
   2.775 +   coefficients in exactly the same manner as in sections 3.2.3 through
   2.776 +   3.2.4.  As for the 30 ms frame size, the ten LSF coefficients are
   2.777 +   divided into three sub-vectors of size 3, 3, and 4 and quantized by
   2.778 +   using the same scheme and codebook as in section 3.2.4 to finally get
   2.779 +   3 quantization indices.  The quantized LSF coefficients are
   2.780 +   stabilized with the algorithm described in section 3.2.5.
   2.781 +
   2.782 +   From the set of LSF coefficients computed for this block and those
   2.783 +   from the previous block, different LSFs are obtained for each sub-
   2.784 +   block by means of interpolation.  The interpolation is done linearly
   2.785 +   in the LSF domain over the four sub-blocks, so that the n-th sub-
   2.786 +
   2.787 +
   2.788 +
   2.789 +Andersen, et al.              Experimental                     [Page 14]
   2.790 +
   2.791 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.792 +
   2.793 +
   2.794 +   frame uses the weight (4-n)/4 for the LSF from old frame and the
   2.795 +   weight n/4 of the LSF from the current frame.  For the very first
   2.796 +   block the mean LSF, lsfmeanTbl, is used as the LSF from the previous
   2.797 +   block.  Similarly as seen in section 3.2.6, both unquantized, A(z),
   2.798 +   and quantized, A~(z), analysis filters are calculated for each of the
   2.799 +   four sub-blocks.
   2.800 +
   2.801 +3.3.  Calculation of the Residual
   2.802 +
   2.803 +   The block of speech samples is filtered by the quantized and
   2.804 +   interpolated LPC analysis filters to yield the residual signal.  In
   2.805 +   particular, the corresponding LPC analysis filter for each 40 sample
   2.806 +   sub-block is used to filter the speech samples for the same sub-
   2.807 +   block.  The filter memory at the end of each sub-block is carried
   2.808 +   over to the LPC filter of the next sub-block.  The signal at the
   2.809 +   output of each LP analysis filter constitutes the residual signal for
   2.810 +   the corresponding sub-block.
   2.811 +
   2.812 +   A reference implementation of the LPC analysis filters is given in
   2.813 +   Appendix A.10.
   2.814 +
   2.815 +3.4.  Perceptual Weighting Filter
   2.816 +
   2.817 +   In principle any good design of a perceptual weighting filter can be
   2.818 +   applied in the encoder without compromising this codec definition.
   2.819 +   However, it is RECOMMENDED to use the perceptual weighting filter Wk
   2.820 +   for sub-block k specified below:
   2.821 +
   2.822 +      Wk(z)=1/Ak(z/LPC_CHIRP_WEIGHTDENUM), where
   2.823 +                               LPC_CHIRP_WEIGHTDENUM = 0.4222
   2.824 +
   2.825 +   This is a simple design with low complexity that is applied in the
   2.826 +   LPC residual domain.  Here Ak(z) is the filter obtained for sub-block
   2.827 +   k from unquantized but interpolated LSF coefficients.
   2.828 +
   2.829 +3.5.  Start State Encoder
   2.830 +
   2.831 +   The start state is quantized by using a common 6-bit scalar quantizer
   2.832 +   for the block and a 3-bit scalar quantizer operating on scaled
   2.833 +   samples in the weighted speech domain.  In the following we describe
   2.834 +   the state encoding in greater detail.
   2.835 +
   2.836 +
   2.837 +
   2.838 +
   2.839 +
   2.840 +
   2.841 +
   2.842 +
   2.843 +
   2.844 +
   2.845 +Andersen, et al.              Experimental                     [Page 15]
   2.846 +
   2.847 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.848 +
   2.849 +
   2.850 +3.5.1.  Start State Estimation
   2.851 +
   2.852 +   The two sub-blocks containing the start state are determined by
   2.853 +   finding the two consecutive sub-blocks in the block having the
   2.854 +   highest power.  Advantageously, down-weighting is used in the
   2.855 +   beginning and end of the sub-frames, i.e., the following measure is
   2.856 +   computed (NSUB=4/6 for 20/30 ms frame size):
   2.857 +
   2.858 +      nsub=1,...,NSUB-1
   2.859 +      ssqn[nsub] = 0.0;
   2.860 +      for (i=(nsub-1)*SUBL; i<(nsub-1)*SUBL+5; i++)
   2.861 +               ssqn[nsub] += sampEn_win[i-(nsub-1)*SUBL]*
   2.862 +                                 residual[i]*residual[i];
   2.863 +      for (i=(nsub-1)*SUBL+5; i<(nsub+1)*SUBL-5; i++)
   2.864 +               ssqn[nsub] += residual[i]*residual[i];
   2.865 +      for (i=(nsub+1)*SUBL-5; i<(nsub+1)*SUBL; i++)
   2.866 +               ssqn[nsub] += sampEn_win[(nsub+1)*SUBL-i-1]*
   2.867 +                                 residual[i]*residual[i];
   2.868 +
   2.869 +   where sampEn_win[5]={1/6, 2/6, 3/6, 4/6, 5/6}; MAY be used.  The
   2.870 +   sub-frame number corresponding to the maximum value of
   2.871 +   ssqEn_win[nsub-1]*ssqn[nsub] is selected as the start state
   2.872 +   indicator.  A weighting of ssqEn_win[]={0.8,0.9,1.0,0.9,0.8} for 30
   2.873 +   ms frames and ssqEn_win[]={0.9,1.0,0.9} for 20 ms frames; MAY
   2.874 +   advantageously be used to bias the start state towards the middle of
   2.875 +   the frame.
   2.876 +
   2.877 +   For 20 ms frames there are three possible positions for the two-sub-
   2.878 +   block length maximum power segment; the start state position is
   2.879 +   encoded with 2 bits.  The start state position, start, MUST be
   2.880 +   encoded as
   2.881 +
   2.882 +      start=1: start state in sub-frame 0 and 1
   2.883 +      start=2: start state in sub-frame 1 and 2
   2.884 +      start=3: start state in sub-frame 2 and 3
   2.885 +
   2.886 +   For 30 ms frames there are five possible positions of the two-sub-
   2.887 +   block length maximum power segment, the start state position is
   2.888 +   encoded with 3 bits.  The start state position, start, MUST be
   2.889 +   encoded as
   2.890 +
   2.891 +      start=1: start state in sub-frame 0 and 1
   2.892 +      start=2: start state in sub-frame 1 and 2
   2.893 +      start=3: start state in sub-frame 2 and 3
   2.894 +      start=4: start state in sub-frame 3 and 4
   2.895 +      start=5: start state in sub-frame 4 and 5
   2.896 +
   2.897 +
   2.898 +
   2.899 +
   2.900 +
   2.901 +Andersen, et al.              Experimental                     [Page 16]
   2.902 +
   2.903 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.904 +
   2.905 +
   2.906 +   Hence, in both cases, index 0 is not used.  In order to shorten the
   2.907 +   start state for bit rate efficiency, the start state is brought down
   2.908 +   to STATE_SHORT_LEN=57 samples for 20 ms frames and STATE_SHORT_LEN=58
   2.909 +   samples for 30 ms frames.  The power of the first 23/22 and last
   2.910 +   23/22 samples of the two sub-frame blocks identified above is
   2.911 +   computed as the sum of the squared signal sample values, and the
   2.912 +   23/22-sample segment with the lowest power is excluded from the start
   2.913 +   state.  One bit is transmitted to indicate which of the two possible
   2.914 +   57/58 sample segments is used.  The start state position within the
   2.915 +   two sub-frames determined above, state_first, MUST be encoded as
   2.916 +
   2.917 +      state_first=1: start state is first STATE_SHORT_LEN samples
   2.918 +      state_first=0: start state is last STATE_SHORT_LEN samples
   2.919 +
   2.920 +3.5.2.  All-Pass Filtering and Scale Quantization
   2.921 +
   2.922 +   The block of residual samples in the start state is first filtered by
   2.923 +   an all-pass filter with the quantized LPC coefficients as denominator
   2.924 +   and reversed quantized LPC coefficients as numerator.  The purpose of
   2.925 +   this phase-dispersion filter is to get a more even distribution of
   2.926 +   the sample values in the residual signal.  The filtering is performed
   2.927 +   by circular convolution, where the initial filter memory is set to
   2.928 +   zero.
   2.929 +
   2.930 +      res(0..(STATE_SHORT_LEN-1))   = uncoded start state residual
   2.931 +      res((STATE_SHORT_LEN)..(2*STATE_SHORT_LEN-1)) = 0
   2.932 +
   2.933 +      Pk(z) = A~rk(z)/A~k(z), where
   2.934 +                                   ___
   2.935 +                                   \
   2.936 +      A~rk(z)= z^(-LPC_FILTERORDER)+>a~k(i+1)*z^(i-(LPC_FILTERORDER-1))
   2.937 +                                   /__
   2.938 +                               i=0...(LPC_FILTERORDER-1)
   2.939 +
   2.940 +      and A~k(z) is taken from the block where the start state begins
   2.941 +
   2.942 +      res -> Pk(z) -> filtered
   2.943 +
   2.944 +      ccres(k) = filtered(k) + filtered(k+STATE_SHORT_LEN),
   2.945 +                                        k=0..(STATE_SHORT_LEN-1)
   2.946 +
   2.947 +   The all-pass filtered block is searched for its largest magnitude
   2.948 +   sample.  The 10-logarithm of this magnitude is quantized with a 6-bit
   2.949 +   quantizer, state_frgqTbl, by finding the nearest representation.
   2.950 +
   2.951 +
   2.952 +
   2.953 +
   2.954 +
   2.955 +
   2.956 +
   2.957 +Andersen, et al.              Experimental                     [Page 17]
   2.958 +
   2.959 +RFC 3951              Internet Low Bit Rate Codec          December 2004
   2.960 +
   2.961 +
   2.962 +   This results in an index, idxForMax, corresponding to a quantized
   2.963 +   value, qmax.  The all-pass filtered residual samples in the block are
   2.964 +   then multiplied with a scaling factor scal=4.5/(10^qmax) to yield
   2.965 +   normalized samples.
   2.966 +
   2.967 +   state_frgqTbl[64] = {1.000085, 1.071695, 1.140395, 1.206868,
   2.968 +                  1.277188, 1.351503, 1.429380, 1.500727, 1.569049,
   2.969 +                  1.639599, 1.707071, 1.781531, 1.840799, 1.901550,
   2.970 +                  1.956695, 2.006750, 2.055474, 2.102787, 2.142819,
   2.971 +                  2.183592, 2.217962, 2.257177, 2.295739, 2.332967,
   2.972 +                  2.369248, 2.402792, 2.435080, 2.468598, 2.503394,
   2.973 +                  2.539284, 2.572944, 2.605036, 2.636331, 2.668939,
   2.974 +                  2.698780, 2.729101, 2.759786, 2.789834, 2.818679,
   2.975 +                  2.848074, 2.877470, 2.906899, 2.936655, 2.967804,
   2.976 +                  3.000115, 3.033367, 3.066355, 3.104231, 3.141499,
   2.977 +                  3.183012, 3.222952, 3.265433, 3.308441, 3.350823,
   2.978 +                  3.395275, 3.442793, 3.490801, 3.542514, 3.604064,
   2.979 +                  3.666050, 3.740994, 3.830749, 3.938770, 4.101764}
   2.980 +
   2.981 +3.5.3.  Scalar Quantization
   2.982 +
   2.983 +   The normalized samples are quantized in the perceptually weighted
   2.984 +   speech domain by a sample-by-sample scalar DPCM quantization as
   2.985 +   depicted in Figure 3.3.  Each sample in the block is filtered by a
   2.986 +   weighting filter Wk(z), specified in section 3.4, to form a weighted
   2.987 +   speech sample x[n].  The target sample d[n] is formed by subtracting
   2.988 +   a predicted sample y[n], where the prediction filter is given by
   2.989 +
   2.990 +           Pk(z) = 1 - 1 / Wk(z).
   2.991 +
   2.992 +               +-------+  x[n] +    d[n] +-----------+ u[n]
   2.993 +   residual -->| Wk(z) |-------->(+)---->| Quantizer |------> quantized
   2.994 +               +-------+       - /|\     +-----------+    |   residual
   2.995 +                                  |                      \|/
   2.996 +                             y[n] +--------------------->(+)
   2.997 +                                  |                       |
   2.998 +                                  |        +------+       |
   2.999 +                                  +--------| Pk(z)|<------+
  2.1000 +                                           +------+
  2.1001 +
  2.1002 +   Figure 3.3.  Quantization of start state samples by DPCM in weighted
  2.1003 +   speech domain.
  2.1004 +
  2.1005 +   The coded state sample u[n] is obtained by quantizing d[n] with a 3-
  2.1006 +   bit quantizer with quantization table state_sq3Tbl.
  2.1007 +
  2.1008 +   state_sq3Tbl[8] = {-3.719849, -2.177490, -1.130005, -0.309692,
  2.1009 +                  0.444214, 1.329712, 2.436279, 3.983887}
  2.1010 +
  2.1011 +
  2.1012 +
  2.1013 +Andersen, et al.              Experimental                     [Page 18]
  2.1014 +
  2.1015 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1016 +
  2.1017 +
  2.1018 +   The quantized samples are transformed back to the residual domain by
  2.1019 +   1) scaling with 1/scal; 2) time-reversing the scaled samples; 3)
  2.1020 +   filtering the time-reversed samples by the same all-pass filter, as
  2.1021 +   in section 3.5.2, by using circular convolution; and 4) time-
  2.1022 +   reversing the filtered samples.  (More detail is in section 4.2.)
  2.1023 +
  2.1024 +   A reference implementation of the start-state encoding can be found
  2.1025 +   in Appendix A.46.
  2.1026 +
  2.1027 +3.6.  Encoding the Remaining Samples
  2.1028 +
  2.1029 +   A dynamic codebook is used to encode 1) the 23/22 remaining samples
  2.1030 +   in the two sub-blocks containing the start state; 2) the sub-blocks
  2.1031 +   after the start state in time; and 3) the sub-blocks before the start
  2.1032 +   state in time.  Thus, the encoding target can be either the 23/22
  2.1033 +   samples remaining of the 2 sub-blocks containing the start state, or
  2.1034 +   a 40-sample sub-block.  This target can consist of samples that are
  2.1035 +   indexed forward in time or backward in time, depending on the
  2.1036 +   location of the start state.  The length of the target is denoted by
  2.1037 +   lTarget.
  2.1038 +
  2.1039 +   The coding is based on an adaptive codebook that is built from a
  2.1040 +   codebook memory that contains decoded LPC excitation samples from the
  2.1041 +   already encoded part of the block.  These samples are indexed in the
  2.1042 +   same time direction as is the target vector and end at the sample
  2.1043 +   instant prior to the first sample instant represented in the target
  2.1044 +   vector.  The codebook memory has length lMem, which is equal to
  2.1045 +   CB_MEML=147 for the two/four 40-sample sub-blocks and 85 for the
  2.1046 +   23/22-sample sub-block.
  2.1047 +
  2.1048 +   The following figure shows an overview of the encoding procedure.
  2.1049 +
  2.1050 +         +------------+    +---------------+    +-------------+
  2.1051 +      -> | 1. Decode  | -> | 2. Mem setup  | -> | 3. Perc. W. | ->
  2.1052 +         +------------+    +---------------+    +-------------+
  2.1053 +
  2.1054 +         +------------+    +-----------------+
  2.1055 +      -> | 4. Search  | -> | 5. Upd. Target  | ------------------>
  2.1056 +       | +------------+    +------------------ |
  2.1057 +       ----<-------------<-----------<----------
  2.1058 +                     stage=0..2
  2.1059 +
  2.1060 +         +----------------+
  2.1061 +      -> | 6. Recalc G[0] | ---------------> gains and CB indices
  2.1062 +         +----------------+
  2.1063 +
  2.1064 +   Figure 3.4.  Flow chart of the codebook search in the iLBC encoder.
  2.1065 +
  2.1066 +
  2.1067 +
  2.1068 +
  2.1069 +Andersen, et al.              Experimental                     [Page 19]
  2.1070 +
  2.1071 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1072 +
  2.1073 +
  2.1074 +   1. Decode the part of the residual that has been encoded so far,
  2.1075 +      using the codebook without perceptual weighting.
  2.1076 +
  2.1077 +   2. Set up the memory by taking data from the decoded residual.  This
  2.1078 +      memory is used to construct codebooks.  For blocks preceding the
  2.1079 +      start state, both the decoded residual and the target are time
  2.1080 +      reversed (section 3.6.1).
  2.1081 +   3. Filter the memory + target with the perceptual weighting filter
  2.1082 +      (section 3.6.2).
  2.1083 +
  2.1084 +   4. Search for the best match between the target and the codebook
  2.1085 +      vector.  Compute the optimal gain for this match and quantize that
  2.1086 +      gain (section 3.6.4).
  2.1087 +
  2.1088 +   5. Update the perceptually weighted target by subtracting the
  2.1089 +      contribution from the selected codebook vector from the
  2.1090 +      perceptually weighted memory (quantized gain times selected
  2.1091 +      vector).  Repeat 4 and 5 for the two additional stages.
  2.1092 +
  2.1093 +   6. Calculate the energy loss due to encoding of the residual.  If
  2.1094 +      needed, compensate for this loss by an upscaling and
  2.1095 +      requantization of the gain for the first stage (section 3.7).
  2.1096 +
  2.1097 +   The following sections provide an in-depth description of the
  2.1098 +   different blocks of Figure 3.4.
  2.1099 +
  2.1100 +3.6.1.  Codebook Memory
  2.1101 +
  2.1102 +   The codebook memory is based on the already encoded sub-blocks, so
  2.1103 +   the available data for encoding increases for each new sub-block that
  2.1104 +   has been encoded.  Until enough sub-blocks have been encoded to fill
  2.1105 +   the codebook memory with data, it is padded with zeros.  The
  2.1106 +   following figure shows an example of the order in which the sub-
  2.1107 +   blocks are encoded for the 30 ms frame size if the start state is
  2.1108 +   located in the last 58 samples of sub-block 2 and 3.
  2.1109 +
  2.1110 +   +-----------------------------------------------------+
  2.1111 +   |  5     | 1  |///|////////|    2   |    3   |    4   |
  2.1112 +   +-----------------------------------------------------+
  2.1113 +
  2.1114 +   Figure 3.5.  The order from 1 to 5 in which the sub-blocks are
  2.1115 +   encoded.  The slashed area is the start state.
  2.1116 +
  2.1117 +
  2.1118 +
  2.1119 +
  2.1120 +
  2.1121 +
  2.1122 +
  2.1123 +
  2.1124 +
  2.1125 +Andersen, et al.              Experimental                     [Page 20]
  2.1126 +
  2.1127 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1128 +
  2.1129 +
  2.1130 +   The first target sub-block to be encoded is number 1, and the
  2.1131 +   corresponding codebook memory is shown in the following figure.  As
  2.1132 +   the target vector comes before the start state in time, the codebook
  2.1133 +   memory and target vector are time reversed; thus, after the block has
  2.1134 +   been time reversed the search algorithm can be reused.  As only the
  2.1135 +   start state has been encoded so far, the last samples of the codebook
  2.1136 +   memory are padded with zeros.
  2.1137 +
  2.1138 +   +-------------------------
  2.1139 +   |zeros|\\\\\\\\|\\\\|  1 |
  2.1140 +   +-------------------------
  2.1141 +
  2.1142 +   Figure 3.6.  The codebook memory, length lMem=85 samples, and the
  2.1143 +   target vector 1, length 22 samples.
  2.1144 +
  2.1145 +   The next step is to encode sub-block 2 by using the memory that now
  2.1146 +   has increased since sub-block 1 has been encoded.  The following
  2.1147 +   figure shows the codebook memory for encoding of sub-block 2.
  2.1148 +
  2.1149 +   +-----------------------------------
  2.1150 +   | zeros | 1  |///|////////|    2   |
  2.1151 +   +-----------------------------------
  2.1152 +
  2.1153 +   Figure 3.7.  The codebook memory, length lMem=147 samples, and the
  2.1154 +   target vector 2, length 40 samples.
  2.1155 +
  2.1156 +   The next step is to encode sub-block 3 by using the memory which has
  2.1157 +   been increased yet again since sub-blocks 1 and 2 have been encoded,
  2.1158 +   but the sub-block still has to be padded with a few zeros.  The
  2.1159 +   following figure shows the codebook memory for encoding of sub-block
  2.1160 +   3.
  2.1161 +
  2.1162 +   +------------------------------------------
  2.1163 +   |zeros| 1  |///|////////|    2   |   3    |
  2.1164 +   +------------------------------------------
  2.1165 +
  2.1166 +   Figure 3.8.  The codebook memory, length lMem=147 samples, and the
  2.1167 +   target vector 3, length 40 samples.
  2.1168 +
  2.1169 +   The next step is to encode sub-block 4 by using the memory which now
  2.1170 +   has increased yet again since sub-blocks 1, 2, and 3 have been
  2.1171 +   encoded.  This time, the memory does not have to be padded with
  2.1172 +   zeros.  The following figure shows the codebook memory for encoding
  2.1173 +   of sub-block 4.
  2.1174 +
  2.1175 +
  2.1176 +
  2.1177 +
  2.1178 +
  2.1179 +
  2.1180 +
  2.1181 +Andersen, et al.              Experimental                     [Page 21]
  2.1182 +
  2.1183 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1184 +
  2.1185 +
  2.1186 +   +------------------------------------------
  2.1187 +   |1|///|////////|    2   |   3    |   4    |
  2.1188 +   +------------------------------------------
  2.1189 +
  2.1190 +   Figure 3.9.  The codebook memory, length lMem=147 samples, and the
  2.1191 +   target vector 4, length 40 samples.
  2.1192 +
  2.1193 +   The final target sub-block to be encoded is number 5, and the
  2.1194 +   following figure shows the corresponding codebook memory.  As the
  2.1195 +   target vector comes before the start state in time, the codebook
  2.1196 +   memory and target vector are time reversed.
  2.1197 +
  2.1198 +   +-------------------------------------------
  2.1199 +   |  3  |   2    |\\\\\\\\|\\\\|  1 |   5    |
  2.1200 +   +-------------------------------------------
  2.1201 +
  2.1202 +   Figure 3.10.  The codebook memory, length lMem=147 samples, and the
  2.1203 +   target vector 5, length 40 samples.
  2.1204 +
  2.1205 +   For the case of 20 ms frames, the encoding procedure looks almost
  2.1206 +   exactly the same.  The only difference is that the size of the start
  2.1207 +   state is 57 samples and that there are only three sub-blocks to be
  2.1208 +   encoded.  The encoding order is the same as above, starting with the
  2.1209 +   23-sample target and then encoding the two remaining 40-sample sub-
  2.1210 +   blocks, first going forward in time and then going backward in time
  2.1211 +   relative to the start state.
  2.1212 +
  2.1213 +3.6.2.  Perceptual Weighting of Codebook Memory and Target
  2.1214 +
  2.1215 +   To provide a perceptual weighting of the coding error, a
  2.1216 +   concatenation of the codebook memory and the target to be coded is
  2.1217 +   all-pole filtered with the perceptual weighting filter specified in
  2.1218 +   section 3.4.  The filter state of the weighting filter is set to
  2.1219 +   zero.
  2.1220 +
  2.1221 +      in(0..(lMem-1))            = unweighted codebook memory
  2.1222 +      in(lMem..(lMem+lTarget-1)) = unweighted target signal
  2.1223 +
  2.1224 +
  2.1225 +      in -> Wk(z) -> filtered,
  2.1226 +          where Wk(z) is taken from the sub-block of the target
  2.1227 +
  2.1228 +      weighted codebook memory = filtered(0..(lMem-1))
  2.1229 +      weighted target signal = filtered(lMem..(lMem+lTarget-1))
  2.1230 +
  2.1231 +   The codebook search is done with the weighted codebook memory and the
  2.1232 +   weighted target, whereas the decoding and the codebook memory update
  2.1233 +   uses the unweighted codebook memory.
  2.1234 +
  2.1235 +
  2.1236 +
  2.1237 +Andersen, et al.              Experimental                     [Page 22]
  2.1238 +
  2.1239 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1240 +
  2.1241 +
  2.1242 +3.6.3.  Codebook Creation
  2.1243 +
  2.1244 +   The codebook for the search is created from the perceptually weighted
  2.1245 +   codebook memory.  It consists of two sections, where the first is
  2.1246 +   referred to as the base codebook and the second as the expanded
  2.1247 +   codebook, as it is created by linear combinations of the first.  Each
  2.1248 +   of these two sections also has a subsection referred to as the
  2.1249 +   augmented codebook.  The augmented codebook is only created and used
  2.1250 +   for the coding of the 40-sample sub-blocks and not for the 23/22-
  2.1251 +   sample sub-block case.  The codebook size used for the different
  2.1252 +   sub-blocks and different stages are summarized in the table below.
  2.1253 +
  2.1254 +                              Stage
  2.1255 +                        1               2 & 3
  2.1256 +           --------------------------------------------
  2.1257 +                22     128  (64+0)*2     128 (64+0)*2
  2.1258 +   Sub-    1:st 40     256  (108+20)*2   128 (44+20)*2
  2.1259 +   Blocks  2:nd 40     256  (108+20)*2   256 (108+20)*2
  2.1260 +           3:rd 40     256  (108+20)*2   256 (108+20)*2
  2.1261 +           4:th 40     256  (108+20)*2   256 (108+20)*2
  2.1262 +
  2.1263 +   Table 3.1.  Codebook sizes for the 30 ms mode.
  2.1264 +
  2.1265 +   Table 3.1 shows the codebook size for the different sub-blocks and
  2.1266 +   stages for 30 ms frames.  Inside the parentheses it shows how the
  2.1267 +   number of codebook vectors is distributed, within the two sections,
  2.1268 +   between the base/expanded codebook and the augmented base/expanded
  2.1269 +   codebook.  It should be interpreted in the following way:
  2.1270 +   (base/expanded cb + augmented base/expanded cb).  The total number of
  2.1271 +   codebook vectors for a specific sub-block and stage is given by the
  2.1272 +   following formula:
  2.1273 +
  2.1274 +   Tot. cb vectors = base cb + aug. base cb + exp. cb + aug. exp. cb
  2.1275 +
  2.1276 +   The corresponding values to Figure 3.1 for 20 ms frames are only
  2.1277 +   slightly modified.  The short sub-block is 23 instead of 22 samples,
  2.1278 +   and the 3:rd and 4:th sub-frame are not present.
  2.1279 +
  2.1280 +3.6.3.1.  Creation of a Base Codebook
  2.1281 +
  2.1282 +   The base codebook is given by the perceptually weighted codebook
  2.1283 +   memory that is mentioned in section 3.5.3.  The different codebook
  2.1284 +   vectors are given by sliding a window of length 23/22 or 40, given by
  2.1285 +   variable lTarget, over the lMem-long perceptually weighted codebook
  2.1286 +   memory.  The indices are ordered so that the codebook vector
  2.1287 +   containing sample (lMem-lTarget-n) to (lMem-n-1) of the codebook
  2.1288 +
  2.1289 +
  2.1290 +
  2.1291 +
  2.1292 +
  2.1293 +Andersen, et al.              Experimental                     [Page 23]
  2.1294 +
  2.1295 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1296 +
  2.1297 +
  2.1298 +   memory vector has index n, where n=0..lMem-lTarget.  Thus the total
  2.1299 +   number of base codebook vectors is lMem-lTarget+1, and the indices
  2.1300 +   are ordered from sample delay lTarget (23/22 or 40) to lMem+1 (86 or
  2.1301 +   148).
  2.1302 +
  2.1303 +3.6.3.2.  Codebook Expansion
  2.1304 +
  2.1305 +   The base codebook is expanded by a factor of 2, creating an
  2.1306 +   additional section in the codebook.  This new section is obtained by
  2.1307 +   filtering the base codebook, base_cb, with a FIR filter with filter
  2.1308 +   length CB_FILTERLEN=8.  The construction of the expanded codebook
  2.1309 +   compensates for the delay of four samples introduced by the FIR
  2.1310 +   filter.
  2.1311 +
  2.1312 +   cbfiltersTbl[CB_FILTERLEN]={-0.033691, 0.083740, -0.144043,
  2.1313 +                  0.713379, 0.806152, -0.184326,
  2.1314 +                  0.108887, -0.034180};
  2.1315 +
  2.1316 +                   ___
  2.1317 +                   \
  2.1318 +      exp_cb(k)=  + > cbfiltersTbl(i)*x(k-i+4)
  2.1319 +                   /__
  2.1320 +             i=0...(LPC_FILTERORDER-1)
  2.1321 +
  2.1322 +      where x(j) = base_cb(j) for j=0..lMem-1 and 0 otherwise
  2.1323 +
  2.1324 +   The individual codebook vectors of the new filtered codebook, exp_cb,
  2.1325 +   and their indices are obtained in the same fashion as described above
  2.1326 +   for the base codebook.
  2.1327 +
  2.1328 +3.6.3.3.  Codebook Augmentation
  2.1329 +
  2.1330 +   For cases where encoding entire sub-blocks, i.e., cbveclen=40, the
  2.1331 +   base and expanded codebooks are augmented to increase codebook
  2.1332 +   richness.  The codebooks are augmented by vectors produced by
  2.1333 +   interpolation of segments.  The base and expanded codebook,
  2.1334 +   constructed above, consists of vectors corresponding to sample delays
  2.1335 +   in the range from cbveclen to lMem.  The codebook augmentation
  2.1336 +   attempts to augment these codebooks with vectors corresponding to
  2.1337 +   sample delays from 20 to 39.  However, not all of these samples are
  2.1338 +   present in the base codebook and expanded codebook, respectively.
  2.1339 +   Therefore, the augmentation vectors are constructed as linear
  2.1340 +   combinations between samples corresponding to sample delays in the
  2.1341 +   range 20 to 39.  The general idea of this procedure is presented in
  2.1342 +   the following figures and text.  The procedure is performed for both
  2.1343 +   the base codebook and the expanded codebook.
  2.1344 +
  2.1345 +
  2.1346 +
  2.1347 +
  2.1348 +
  2.1349 +Andersen, et al.              Experimental                     [Page 24]
  2.1350 +
  2.1351 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1352 +
  2.1353 +
  2.1354 +       - - ------------------------|
  2.1355 +    codebook memory                |
  2.1356 +       - - ------------------------|
  2.1357 +                  |-5-|---15---|-5-|
  2.1358 +                  pi  pp       po
  2.1359 +
  2.1360 +                      |        |                       Codebook vector
  2.1361 +                      |---15---|-5-|-----20-----|   <- corresponding to
  2.1362 +                          i     ii      iii            sample delay 20
  2.1363 +
  2.1364 +   Figure 3.11.  Generation of the first augmented codebook.
  2.1365 +
  2.1366 +   Figure 3.11 shows the codebook memory with pointers pi, pp, and po,
  2.1367 +   where pi points to sample 25, pp to sample 20, and po to sample 5.
  2.1368 +   Below the codebook memory, the augmented codebook vector
  2.1369 +   corresponding to sample delay 20 is drawn.  Segment i consists of
  2.1370 +   fifteen samples from pointer pp and forward in time.  Segment ii
  2.1371 +   consists of five interpolated samples from pi and forward and from po
  2.1372 +   and forward.  The samples are linearly interpolated with weights
  2.1373 +   [0.0, 0.2, 0.4, 0.6, 0.8] for pi and weights [1.0, 0.8, 0.6, 0.4,
  2.1374 +   0.2] for po.  Segment iii consists of twenty samples from pp and
  2.1375 +   forward.  The augmented codebook vector corresponding to sample delay
  2.1376 +   21 is produced by moving pointers pp and pi one sample backward in
  2.1377 +   time.  This gives us the following figure.
  2.1378 +
  2.1379 +       - - ------------------------|
  2.1380 +    codebook memory                |
  2.1381 +       - - ------------------------|
  2.1382 +                  |-5-|---16---|-5-|
  2.1383 +                  pi  pp       po
  2.1384 +
  2.1385 +                      |        |                       Codebook vector
  2.1386 +                      |---16---|-5-|-----19-----|   <- corresponding to
  2.1387 +                          i     ii      iii            sample delay 21
  2.1388 +
  2.1389 +   Figure 3.12.  Generation of the second augmented codebook.
  2.1390 +
  2.1391 +   Figure 3.12 shows the codebook memory with pointers pi, pp and po
  2.1392 +   where pi points to sample 26, pp to sample 21, and po to sample 5.
  2.1393 +   Below the codebook memory, the augmented codebook vector
  2.1394 +   corresponding to sample delay 21 is drawn.  Segment i now consists of
  2.1395 +   sixteen samples from pp and forward.  Segment ii consists of five
  2.1396 +   interpolated samples from pi and forward and from po and forward, and
  2.1397 +   the interpolation weights are the same throughout the procedure.
  2.1398 +   Segment iii consists of nineteen samples from pp and forward.  The
  2.1399 +   same procedure of moving the two pointers is continued until the last
  2.1400 +   augmented vector corresponding to sample delay 39 has been created.
  2.1401 +   This gives a total of twenty new codebook vectors to each of the two
  2.1402 +
  2.1403 +
  2.1404 +
  2.1405 +Andersen, et al.              Experimental                     [Page 25]
  2.1406 +
  2.1407 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1408 +
  2.1409 +
  2.1410 +   sections.  Thus the total number of codebook vectors for each of the
  2.1411 +   two sections, when including the augmented codebook, becomes lMem-
  2.1412 +   SUBL+1+SUBL/2.  This is provided that augmentation is evoked, i.e.,
  2.1413 +   that lTarget=SUBL.
  2.1414 +
  2.1415 +3.6.4.  Codebook Search
  2.1416 +
  2.1417 +   The codebook search uses the codebooks described in the sections
  2.1418 +   above to find the best match of the perceptually weighted target, see
  2.1419 +   section 3.6.2.  The search method is a multi-stage gain-shape
  2.1420 +   matching performed as follows.  At each stage the best shape vector
  2.1421 +   is identified, then the gain is calculated and quantized, and finally
  2.1422 +   the target is updated in preparation for the next codebook search
  2.1423 +   stage.  The number of stages is CB_NSTAGES=3.
  2.1424 +
  2.1425 +   If the target is the 23/22-sample vector the codebooks are indexed so
  2.1426 +   that the base codebook is followed by the expanded codebook.  If the
  2.1427 +   target is 40 samples the order is as follows: base codebook,
  2.1428 +   augmented base codebook, expanded codebook, and augmented expanded
  2.1429 +   codebook.  The size of each codebook section and its corresponding
  2.1430 +   augmented section is given by Table 3.1 in section 3.6.3.
  2.1431 +
  2.1432 +   For example, when the second 40-sample sub-block is coded, indices 0
  2.1433 +   - 107 correspond to the base codebook, 108 - 127 correspond to the
  2.1434 +   augmented base codebook, 128 - 235 correspond to the expanded
  2.1435 +   codebook, and indices 236 - 255 correspond to the augmented expanded
  2.1436 +   codebook.  The indices are divided in the same fashion for all stages
  2.1437 +   in the example.  Only in the case of coding the first 40-sample sub-
  2.1438 +   block is there a difference between stages (see Table 3.1).
  2.1439 +
  2.1440 +3.6.4.1.  Codebook Search at Each Stage
  2.1441 +
  2.1442 +   The codebooks are searched to find the best match to the target at
  2.1443 +   each stage.  When the best match is found, the target is updated and
  2.1444 +   the next-stage search is started.  The three chosen codebook vectors
  2.1445 +   and their corresponding gains constitute the encoded sub-block.  The
  2.1446 +   best match is decided by the following three criteria:
  2.1447 +
  2.1448 +   1. Compute the measure
  2.1449 +
  2.1450 +      (target*cbvec)^2 / ||cbvec||^2
  2.1451 +
  2.1452 +   for all codebook vectors, cbvec, and choose the codebook vector
  2.1453 +   maximizing the measure.  The expression (target*cbvec) is the dot
  2.1454 +   product between the target vector to be coded and the codebook vector
  2.1455 +   for which we compute the measure.  The norm, ||x||, is defined as the
  2.1456 +   square root of (x*x).
  2.1457 +
  2.1458 +
  2.1459 +
  2.1460 +
  2.1461 +Andersen, et al.              Experimental                     [Page 26]
  2.1462 +
  2.1463 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1464 +
  2.1465 +
  2.1466 +   2. The absolute value of the gain, corresponding to the chosen
  2.1467 +      codebook vector, cbvec, must be smaller than a fixed limit,
  2.1468 +      CB_MAXGAIN=1.3:
  2.1469 +
  2.1470 +            |gain| < CB_MAXGAIN
  2.1471 +
  2.1472 +      where the gain is computed in the following way:
  2.1473 +
  2.1474 +            gain = (target*cbvec) / ||cbvec||^2
  2.1475 +
  2.1476 +   3. For the first stage, the dot product of the chosen codebook vector
  2.1477 +      and target must be positive:
  2.1478 +
  2.1479 +      target*cbvec > 0
  2.1480 +
  2.1481 +   In practice the above criteria are used in a sequential search
  2.1482 +   through all codebook vectors.  The best match is found by registering
  2.1483 +   a new max measure and index whenever the previously registered max
  2.1484 +   measure is surpassed and all other criteria are fulfilled.  If none
  2.1485 +   of the codebook vectors fulfill (2) and (3), the first codebook
  2.1486 +   vector is selected.
  2.1487 +
  2.1488 +3.6.4.2.  Gain Quantization at Each Stage
  2.1489 +
  2.1490 +   The gain follows as a result of the computation
  2.1491 +
  2.1492 +      gain = (target*cbvec) / ||cbvec||^2
  2.1493 +
  2.1494 +   for the optimal codebook vector found by the procedure in section
  2.1495 +   3.6.4.1.
  2.1496 +
  2.1497 +   The three stages quantize the gain, using 5, 4, and 3 bits,
  2.1498 +   respectively.  In the first stage, the gain is limited to positive
  2.1499 +   values.  This gain is quantized by finding the nearest value in the
  2.1500 +   quantization table gain_sq5Tbl.
  2.1501 +
  2.1502 +   gain_sq5Tbl[32]={0.037476, 0.075012, 0.112488, 0.150024, 0.187500,
  2.1503 +                  0.224976, 0.262512, 0.299988, 0.337524, 0.375000,
  2.1504 +                  0.412476, 0.450012, 0.487488, 0.525024, 0.562500,
  2.1505 +                  0.599976, 0.637512, 0.674988, 0.712524, 0.750000,
  2.1506 +                  0.787476, 0.825012, 0.862488, 0.900024, 0.937500,
  2.1507 +                  0.974976, 1.012512, 1.049988, 1.087524, 1.125000,
  2.1508 +                  1.162476, 1.200012}
  2.1509 +
  2.1510 +   The gains of the subsequent two stages can be either positive or
  2.1511 +   negative.  The gains are quantized by using a quantization table
  2.1512 +   times a scale factor.  The second stage uses the table gain_sq4Tbl,
  2.1513 +   and the third stage uses gain_sq3Tbl.  The scale factor equates 0.1
  2.1514 +
  2.1515 +
  2.1516 +
  2.1517 +Andersen, et al.              Experimental                     [Page 27]
  2.1518 +
  2.1519 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1520 +
  2.1521 +
  2.1522 +   or the absolute value of the quantized gain representation value
  2.1523 +   obtained in the previous stage, whichever is larger.  Again, the
  2.1524 +   resulting gain index is the index to the nearest value of the
  2.1525 +   quantization table times the scale factor.
  2.1526 +
  2.1527 +        gainQ = scaleFact * gain_sqXTbl[index]
  2.1528 +
  2.1529 +   gain_sq4Tbl[16]={-1.049988, -0.900024, -0.750000, -0.599976,
  2.1530 +                  -0.450012, -0.299988, -0.150024, 0.000000, 0.150024,
  2.1531 +                  0.299988, 0.450012, 0.599976, 0.750000, 0.900024,
  2.1532 +                  1.049988, 1.200012}
  2.1533 +
  2.1534 +   gain_sq3Tbl[8]={-1.000000, -0.659973, -0.330017,0.000000,
  2.1535 +                  0.250000, 0.500000, 0.750000, 1.00000}
  2.1536 +
  2.1537 +3.6.4.3.  Preparation of Target for Next Stage
  2.1538 +
  2.1539 +   Before performing the search for the next stage, the perceptually
  2.1540 +   weighted target vector is updated by subtracting from it the selected
  2.1541 +   codebook vector (from the perceptually weighted codebook) times the
  2.1542 +   corresponding quantized gain.
  2.1543 +
  2.1544 +      target[i] = target[i] - gainQ * selected_vec[i];
  2.1545 +
  2.1546 +   A reference implementation of the codebook encoding is found in
  2.1547 +   Appendix A.34.
  2.1548 +
  2.1549 +3.7.  Gain Correction Encoding
  2.1550 +
  2.1551 +   The start state is quantized in a relatively model independent manner
  2.1552 +   using 3 bits per sample.  In contrast, the remaining parts of the
  2.1553 +   block are encoded by using an adaptive codebook.  This codebook will
  2.1554 +   produce high matching accuracy whenever there is a high correlation
  2.1555 +   between the target and the best codebook vector.  For unvoiced speech
  2.1556 +   segments and background noises, this is not necessarily so, which,
  2.1557 +   due to the nature of the squared error criterion, results in a coded
  2.1558 +   signal with less power than the target signal.  As the coded start
  2.1559 +   state has good power matching to the target, the result is a power
  2.1560 +   fluctuation within the encoded frame.  Perceptually, the main problem
  2.1561 +   with this is that the time envelope of the signal energy becomes
  2.1562 +   unsteady.  To overcome this problem, the gains for the codebooks are
  2.1563 +   re-scaled after the codebook encoding by searching for a new gain
  2.1564 +   factor for the first stage codebook that provides better power
  2.1565 +   matching.
  2.1566 +
  2.1567 +   First, the energy for the target signal, tene, is computed along with
  2.1568 +   the energy for the coded signal, cene, given by the addition of the
  2.1569 +   three gain scaled codebook vectors.  Because the gains of the second
  2.1570 +
  2.1571 +
  2.1572 +
  2.1573 +Andersen, et al.              Experimental                     [Page 28]
  2.1574 +
  2.1575 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1576 +
  2.1577 +
  2.1578 +   and third stage scale with the gain of the first stage, when the
  2.1579 +   first stage gain is changed from gain[0] to gain_sq5Tbl[i] the energy
  2.1580 +   of the coded signal changes from cene to
  2.1581 +
  2.1582 +      cene*(gain_sq5Tbl[i]*gain_sq5Tbl[i])/(gain[0]*gain[0])
  2.1583 +
  2.1584 +   where gain[0] is the gain for the first stage found in the original
  2.1585 +   codebook search.  A refined search is performed by testing the gain
  2.1586 +   indices i=0 to 31, and as long as the new codebook energy as given
  2.1587 +   above is less than tene, the gain index for stage 1 is increased.  A
  2.1588 +   restriction is applied so that the new gain value for stage 1 cannot
  2.1589 +   be more than two times higher than the original value found in the
  2.1590 +   codebook search.  Note that by using this method we do not change the
  2.1591 +   shape of the encoded vector, only the gain or amplitude.
  2.1592 +
  2.1593 +3.8.  Bitstream Definition
  2.1594 +
  2.1595 +   The total number of bits used to describe one frame of 20 ms speech
  2.1596 +   is 304, which fits in 38 bytes and results in a bit rate of 15.20
  2.1597 +   kbit/s.  For the case of a frame length of 30 ms speech, the total
  2.1598 +   number of bits used is 400, which fits in 50 bytes and results in a
  2.1599 +   bit rate of 13.33 kbit/s.  In the bitstream definition, the bits are
  2.1600 +   distributed into three classes according to their bit error or loss
  2.1601 +   sensitivity.  The most sensitive bits (class 1) are placed first in
  2.1602 +   the bitstream for each frame.  The less sensitive bits (class 2) are
  2.1603 +   placed after the class 1 bits.  The least sensitive bits (class 3)
  2.1604 +   are placed at the end of the bitstream for each frame.
  2.1605 +
  2.1606 +   In the 20/30 ms frame length cases for each class, the following hold
  2.1607 +   true: The class 1 bits occupy a total of 6/8 bytes (48/64 bits), the
  2.1608 +   class 2 bits occupy 8/12 bytes (64/96 bits), and the class 3 bits
  2.1609 +   occupy 24/30 bytes (191/239 bits).  This distribution of the bits
  2.1610 +   enables the use of uneven level protection (ULP) as is exploited in
  2.1611 +   the payload format definition for iLBC [1].  The detailed bit
  2.1612 +   allocation is shown in the table below.  When a quantization index is
  2.1613 +   distributed between more classes, the more significant bits belong to
  2.1614 +   the lowest class.
  2.1615 +
  2.1616 +
  2.1617 +
  2.1618 +
  2.1619 +
  2.1620 +
  2.1621 +
  2.1622 +
  2.1623 +
  2.1624 +
  2.1625 +
  2.1626 +
  2.1627 +
  2.1628 +
  2.1629 +Andersen, et al.              Experimental                     [Page 29]
  2.1630 +
  2.1631 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1632 +
  2.1633 +
  2.1634 +   Bitstream structure:
  2.1635 +
  2.1636 +   ------------------------------------------------------------------+
  2.1637 +   Parameter                         |       Bits Class <1,2,3>      |
  2.1638 +                                     |  20 ms frame  |  30 ms frame  |
  2.1639 +   ----------------------------------+---------------+---------------+
  2.1640 +                            Split 1  |   6 <6,0,0>   |   6 <6,0,0>   |
  2.1641 +                   LSF 1    Split 2  |   7 <7,0,0>   |   7 <7,0,0>   |
  2.1642 +   LSF                      Split 3  |   7 <7,0,0>   |   7 <7,0,0>   |
  2.1643 +                   ------------------+---------------+---------------+
  2.1644 +                            Split 1  | NA (Not Appl.)|   6 <6,0,0>   |
  2.1645 +                   LSF 2    Split 2  |      NA       |   7 <7,0,0>   |
  2.1646 +                            Split 3  |      NA       |   7 <7,0,0>   |
  2.1647 +                   ------------------+---------------+---------------+
  2.1648 +                   Sum               |  20 <20,0,0>  |  40 <40,0,0>  |
  2.1649 +   ----------------------------------+---------------+---------------+
  2.1650 +   Block Class                       |   2 <2,0,0>   |   3 <3,0,0>   |
  2.1651 +   ----------------------------------+---------------+---------------+
  2.1652 +   Position 22 sample segment        |   1 <1,0,0>   |   1 <1,0,0>   |
  2.1653 +   ----------------------------------+---------------+---------------+
  2.1654 +   Scale Factor State Coder          |   6 <6,0,0>   |   6 <6,0,0>   |
  2.1655 +   ----------------------------------+---------------+---------------+
  2.1656 +                   Sample 0          |   3 <0,1,2>   |   3 <0,1,2>   |
  2.1657 +   Quantized       Sample 1          |   3 <0,1,2>   |   3 <0,1,2>   |
  2.1658 +   Residual           :              |   :    :      |   :    :      |
  2.1659 +   State              :              |   :    :      |   :    :      |
  2.1660 +   Samples            :              |   :    :      |   :    :      |
  2.1661 +                   Sample 56         |   3 <0,1,2>   |   3 <0,1,2>   |
  2.1662 +                   Sample 57         |      NA       |   3 <0,1,2>   |
  2.1663 +                   ------------------+---------------+---------------+
  2.1664 +                   Sum               | 171 <0,57,114>| 174 <0,58,116>|
  2.1665 +   ----------------------------------+---------------+---------------+
  2.1666 +                            Stage 1  |   7 <6,0,1>   |   7 <4,2,1>   |
  2.1667 +   CB for 22/23             Stage 2  |   7 <0,0,7>   |   7 <0,0,7>   |
  2.1668 +   sample block             Stage 3  |   7 <0,0,7>   |   7 <0,0,7>   |
  2.1669 +                   ------------------+---------------+---------------+
  2.1670 +                   Sum               |  21 <6,0,15>  |  21 <4,2,15>  |
  2.1671 +   ----------------------------------+---------------+---------------+
  2.1672 +                            Stage 1  |   5 <2,0,3>   |   5 <1,1,3>   |
  2.1673 +   Gain for 22/23           Stage 2  |   4 <1,1,2>   |   4 <1,1,2>   |
  2.1674 +   sample block             Stage 3  |   3 <0,0,3>   |   3 <0,0,3>   |
  2.1675 +                   ------------------+---------------+---------------+
  2.1676 +                   Sum               |  12 <3,1,8>   |  12 <2,2,8>   |
  2.1677 +   ----------------------------------+---------------+---------------+
  2.1678 +                            Stage 1  |   8 <7,0,1>   |   8 <6,1,1>   |
  2.1679 +               sub-block 1  Stage 2  |   7 <0,0,7>   |   7 <0,0,7>   |
  2.1680 +                            Stage 3  |   7 <0,0,7>   |   7 <0,0,7>   |
  2.1681 +                   ------------------+---------------+---------------+
  2.1682 +
  2.1683 +
  2.1684 +
  2.1685 +Andersen, et al.              Experimental                     [Page 30]
  2.1686 +
  2.1687 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1688 +
  2.1689 +
  2.1690 +                            Stage 1  |   8 <0,0,8>   |   8 <0,7,1>   |
  2.1691 +               sub-block 2  Stage 2  |   8 <0,0,8>   |   8 <0,0,8>   |
  2.1692 +   Indices                  Stage 3  |   8 <0,0,8>   |   8 <0,0,8>   |
  2.1693 +   for CB          ------------------+---------------+---------------+
  2.1694 +   sub-blocks               Stage 1  |      NA       |   8 <0,7,1>   |
  2.1695 +               sub-block 3  Stage 2  |      NA       |   8 <0,0,8>   |
  2.1696 +                            Stage 3  |      NA       |   8 <0,0,8>   |
  2.1697 +                   ------------------+---------------+---------------+
  2.1698 +                            Stage 1  |      NA       |   8 <0,7,1>   |
  2.1699 +               sub-block 4  Stage 2  |      NA       |   8 <0,0,8>   |
  2.1700 +                            Stage 3  |      NA       |   8 <0,0,8>   |
  2.1701 +                   ------------------+---------------+---------------+
  2.1702 +                   Sum               |  46 <7,0,39>  |  94 <6,22,66> |
  2.1703 +   ----------------------------------+---------------+---------------+
  2.1704 +                            Stage 1  |   5 <1,2,2>   |   5 <1,2,2>   |
  2.1705 +               sub-block 1  Stage 2  |   4 <1,1,2>   |   4 <1,2,1>   |
  2.1706 +                            Stage 3  |   3 <0,0,3>   |   3 <0,0,3>   |
  2.1707 +                   ------------------+---------------+---------------+
  2.1708 +                            Stage 1  |   5 <1,1,3>   |   5 <0,2,3>   |
  2.1709 +               sub-block 2  Stage 2  |   4 <0,2,2>   |   4 <0,2,2>   |
  2.1710 +                            Stage 3  |   3 <0,0,3>   |   3 <0,0,3>   |
  2.1711 +   Gains for       ------------------+---------------+---------------+
  2.1712 +   sub-blocks               Stage 1  |      NA       |   5 <0,1,4>   |
  2.1713 +               sub-block 3  Stage 2  |      NA       |   4 <0,1,3>   |
  2.1714 +                            Stage 3  |      NA       |   3 <0,0,3>   |
  2.1715 +                   ------------------+---------------+---------------+
  2.1716 +                            Stage 1  |      NA       |   5 <0,1,4>   |
  2.1717 +               sub-block 4  Stage 2  |      NA       |   4 <0,1,3>   |
  2.1718 +                            Stage 3  |      NA       |   3 <0,0,3>   |
  2.1719 +                   ------------------+---------------+---------------+
  2.1720 +                   Sum               |  24 <3,6,15>  |  48 <2,12,34> |
  2.1721 +   ----------------------------------+---------------+---------------+
  2.1722 +   Empty frame indicator             |   1 <0,0,1>   |   1 <0,0,1>   |
  2.1723 +   -------------------------------------------------------------------
  2.1724 +   SUM                                 304 <48,64,192> 400 <64,96,240>
  2.1725 +
  2.1726 +   Table 3.2.  The bitstream definition for iLBC for both the 20 ms
  2.1727 +   frame size mode and the 30 ms frame size mode.
  2.1728 +
  2.1729 +   When packetized into the payload, the bits MUST be sorted as follows:
  2.1730 +   All the class 1 bits in the order (from top to bottom) as specified
  2.1731 +   in the table, all the class 2 bits (from top to bottom), and all the
  2.1732 +   class 3 bits in the same sequential order.  The last bit, the empty
  2.1733 +   frame indicator, SHOULD be set to zero by the encoder.  If this bit
  2.1734 +   is set to 1 the decoder SHOULD treat the data as a lost frame.  For
  2.1735 +   example, this bit can be set to 1 to indicate lost frame for file
  2.1736 +   storage format, as in [1].
  2.1737 +
  2.1738 +
  2.1739 +
  2.1740 +
  2.1741 +Andersen, et al.              Experimental                     [Page 31]
  2.1742 +
  2.1743 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1744 +
  2.1745 +
  2.1746 +4.  Decoder Principles
  2.1747 +
  2.1748 +   This section describes the principles of each component of the
  2.1749 +   decoder algorithm.
  2.1750 +
  2.1751 +              +-------------+    +--------+    +---------------+
  2.1752 +   payload -> | 1. Get para | -> | 2. LPC | -> | 3. Sc Dequant | ->
  2.1753 +              +-------------+    +--------+    +---------------+
  2.1754 +
  2.1755 +              +-------------+    +------------------+
  2.1756 +           -> | 4. Mem setup| -> | 5. Construct res |------->
  2.1757 +           |  +-------------+    +-------------------   |
  2.1758 +           ---------<-----------<-----------<------------
  2.1759 +                     Sub-frame 0...2/4 (20 ms/30 ms)
  2.1760 +
  2.1761 +              +----------------+    +----------+
  2.1762 +           -> | 6. Enhance res | -> | 7. Synth | ------------>
  2.1763 +              +----------------+    +----------+
  2.1764 +
  2.1765 +              +-----------------+
  2.1766 +           -> | 8. Post Process | ----------------> decoded speech
  2.1767 +              +-----------------+
  2.1768 +
  2.1769 +   Figure 4.1.  Flow chart of the iLBC decoder.  If a frame was lost,
  2.1770 +   steps 1 to 5 SHOULD be replaced by a PLC algorithm.
  2.1771 +
  2.1772 +   1. Extract the parameters from the bitstream.
  2.1773 +
  2.1774 +   2. Decode the LPC and interpolate (section 4.1).
  2.1775 +
  2.1776 +   3. Construct the 57/58-sample start state (section 4.2).
  2.1777 +
  2.1778 +   4. Set up the memory by using data from the decoded residual.  This
  2.1779 +      memory is used for codebook construction.  For blocks preceding
  2.1780 +      the start state, both the decoded residual and the target are time
  2.1781 +      reversed.  Sub-frames are decoded in the same order as they were
  2.1782 +      encoded.
  2.1783 +
  2.1784 +   5. Construct the residuals of this sub-frame (gain[0]*cbvec[0] +
  2.1785 +      gain[1]*cbvec[1] + gain[2]*cbvec[2]).  Repeat 4 and 5 until the
  2.1786 +      residual of all sub-blocks has been constructed.
  2.1787 +
  2.1788 +   6. Enhance the residual with the post filter (section 4.6).
  2.1789 +
  2.1790 +   7. Synthesis of the residual (section 4.7).
  2.1791 +
  2.1792 +   8. Post process with HP filter, if desired (section 4.8).
  2.1793 +
  2.1794 +
  2.1795 +
  2.1796 +
  2.1797 +Andersen, et al.              Experimental                     [Page 32]
  2.1798 +
  2.1799 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1800 +
  2.1801 +
  2.1802 +4.1.  LPC Filter Reconstruction
  2.1803 +
  2.1804 +   The decoding of the LP filter parameters is very straightforward.
  2.1805 +   For a set of three/six indices, the corresponding LSF vector(s) are
  2.1806 +   found by simple table lookup.  For each of the LSF vectors, the three
  2.1807 +   split vectors are concatenated to obtain qlsf1 and qlsf2,
  2.1808 +   respectively (in the 20 ms mode only one LSF vector, qlsf, is
  2.1809 +   constructed).  The next step is the stability check described in
  2.1810 +   section 3.2.5 followed by the interpolation scheme described in
  2.1811 +   section 3.2.6 (3.2.7 for 20 ms frames).  The only difference is that
  2.1812 +   only the quantized LSFs are known at the decoder, and hence the
  2.1813 +   unquantized LSFs are not processed.
  2.1814 +
  2.1815 +   A reference implementation of the LPC filter reconstruction is given
  2.1816 +   in Appendix A.36.
  2.1817 +
  2.1818 +4.2.  Start State Reconstruction
  2.1819 +
  2.1820 +   The scalar encoded STATE_SHORT_LEN=58 (STATE_SHORT_LEN=57 in the 20
  2.1821 +   ms mode) state samples are reconstructed by 1) forming a set of
  2.1822 +   samples (by table lookup) from the index stream idxVec[n], 2)
  2.1823 +   multiplying the set with 1/scal=(10^qmax)/4.5, 3) time reversing the
  2.1824 +   57/58 samples, 4) filtering the time reversed block with the
  2.1825 +   dispersion (all-pass) filter used in the encoder (as described in
  2.1826 +   section 3.5.2); this compensates for the phase distortion of the
  2.1827 +   earlier filter operation, and 5 reversing the 57/58 samples from the
  2.1828 +   previous step.
  2.1829 +
  2.1830 +   in(0..(STATE_SHORT_LEN-1)) = time reversed samples from table
  2.1831 +                                look-up,
  2.1832 +                                idxVecDec((STATE_SHORT_LEN-1)..0)
  2.1833 +
  2.1834 +   in(STATE_SHORT_LEN..(2*STATE_SHORT_LEN-1)) = 0
  2.1835 +
  2.1836 +   Pk(z) = A~rk(z)/A~k(z), where
  2.1837 +                                  ___
  2.1838 +                                  \
  2.1839 +   A~rk(z)= z^(-LPC_FILTERORDER) + > a~ki*z^(i-(LPC_FILTERORDER-1))
  2.1840 +                                  /__
  2.1841 +                              i=0...(LPC_FILTERORDER-1)
  2.1842 +
  2.1843 +   and A~k(z) is taken from the block where the start state begins
  2.1844 +
  2.1845 +   in -> Pk(z) -> filtered
  2.1846 +
  2.1847 +   out(k) = filtered(STATE_SHORT_LEN-1-k) +
  2.1848 +                           filtered(2*STATE_SHORT_LEN-1-k),
  2.1849 +                                         k=0..(STATE_SHORT_LEN-1)
  2.1850 +
  2.1851 +
  2.1852 +
  2.1853 +Andersen, et al.              Experimental                     [Page 33]
  2.1854 +
  2.1855 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1856 +
  2.1857 +
  2.1858 +   The remaining 23/22 samples in the state are reconstructed by the
  2.1859 +   same adaptive codebook technique described in section 4.3.  The
  2.1860 +   location bit determines whether these are the first or the last 23/22
  2.1861 +   samples of the 80-sample state vector.  If the remaining 23/22
  2.1862 +   samples are the first samples, then the scalar encoded
  2.1863 +   STATE_SHORT_LEN state samples are time-reversed before initialization
  2.1864 +   of the adaptive codebook memory vector.
  2.1865 +
  2.1866 +   A reference implementation of the start state reconstruction is given
  2.1867 +   in Appendix A.44.
  2.1868 +
  2.1869 +4.3.  Excitation Decoding Loop
  2.1870 +
  2.1871 +   The decoding of the LPC excitation vector proceeds in the same order
  2.1872 +   in which the residual was encoded at the encoder.  That is, after the
  2.1873 +   decoding of the entire 80-sample state vector, the forward sub-blocks
  2.1874 +   (corresponding to samples occurring after the state vector samples)
  2.1875 +   are decoded, and then the backward sub-blocks (corresponding to
  2.1876 +   samples occurring before the state vector) are decoded, resulting in
  2.1877 +   a fully decoded block of excitation signal samples.
  2.1878 +
  2.1879 +   In particular, each sub-block is decoded by using the multistage
  2.1880 +   adaptive codebook decoding module described in section 4.4.  This
  2.1881 +   module relies upon an adaptive codebook memory constructed before
  2.1882 +   each run of the adaptive codebook decoding.  The construction of the
  2.1883 +   adaptive codebook memory in the decoder is identical to the method
  2.1884 +   outlined in section 3.6.3, except that it is done on the codebook
  2.1885 +   memory without perceptual weighting.
  2.1886 +
  2.1887 +   For the initial forward sub-block, the last STATE_LEN=80 samples of
  2.1888 +   the length CB_LMEM=147 adaptive codebook memory are filled with the
  2.1889 +   samples of the state vector.  For subsequent forward sub-blocks, the
  2.1890 +   first SUBL=40 samples of the adaptive codebook memory are discarded,
  2.1891 +   the remaining samples are shifted by SUBL samples toward the
  2.1892 +   beginning of the vector, and the newly decoded SUBL=40 samples are
  2.1893 +   placed at the end of the adaptive codebook memory.  For backward
  2.1894 +   sub-blocks, the construction is similar, except that every vector of
  2.1895 +   samples involved is first time reversed.
  2.1896 +
  2.1897 +   A reference implementation of the excitation decoding loop is found
  2.1898 +   in Appendix A.5.
  2.1899 +
  2.1900 +
  2.1901 +
  2.1902 +
  2.1903 +
  2.1904 +
  2.1905 +
  2.1906 +
  2.1907 +
  2.1908 +
  2.1909 +Andersen, et al.              Experimental                     [Page 34]
  2.1910 +
  2.1911 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1912 +
  2.1913 +
  2.1914 +4.4.  Multistage Adaptive Codebook Decoding
  2.1915 +
  2.1916 +   The Multistage Adaptive Codebook Decoding module is used at both the
  2.1917 +   sender (encoder) and the receiver (decoder) ends to produce a
  2.1918 +   synthetic signal in the residual domain that is eventually used to
  2.1919 +   produce synthetic speech.  The module takes the index values used to
  2.1920 +   construct vectors that are scaled and summed together to produce a
  2.1921 +   synthetic signal that is the output of the module.
  2.1922 +
  2.1923 +4.4.1.  Construction of the Decoded Excitation Signal
  2.1924 +
  2.1925 +   The unpacked index values provided at the input to the module are
  2.1926 +   references to extended codebooks, which are constructed as described
  2.1927 +   in section 3.6.3, except that they are based on the codebook memory
  2.1928 +   without the perceptual weighting.  The unpacked three indices are
  2.1929 +   used to look up three codebook vectors.  The unpacked three gain
  2.1930 +   indices are used to decode the corresponding 3 gains.  In this
  2.1931 +   decoding, the successive rescaling, as described in section 3.6.4.2,
  2.1932 +   is applied.
  2.1933 +
  2.1934 +   A reference implementation of the adaptive codebook decoding is
  2.1935 +   listed in Appendix A.32.
  2.1936 +
  2.1937 +4.5.  Packet Loss Concealment
  2.1938 +
  2.1939 +   If packet loss occurs, the decoder receives a signal saying that
  2.1940 +   information regarding a block is lost.  For such blocks it is
  2.1941 +   RECOMMENDED to use a Packet Loss Concealment (PLC) unit to create a
  2.1942 +   decoded signal that masks the effect of that packet loss.  In the
  2.1943 +   following we will describe an example of a PLC unit that can be used
  2.1944 +   with the iLBC codec.  As the PLC unit is used only at the decoder,
  2.1945 +   the PLC unit does not affect interoperability between
  2.1946 +   implementations.  Other PLC implementations MAY therefore be used.
  2.1947 +
  2.1948 +   The PLC described operates on the LP filters and the excitation
  2.1949 +   signals and is based on the following principles:
  2.1950 +
  2.1951 +4.5.1.  Block Received Correctly and Previous Block Also Received
  2.1952 +
  2.1953 +   If the block is received correctly, the PLC only records state
  2.1954 +   information of the current block that can be used in case the next
  2.1955 +   block is lost.  The LP filter coefficients for each sub-block and the
  2.1956 +   entire decoded excitation signal are all saved in the decoder state
  2.1957 +   structure.  All of this information will be needed if the following
  2.1958 +   block is lost.
  2.1959 +
  2.1960 +
  2.1961 +
  2.1962 +
  2.1963 +
  2.1964 +
  2.1965 +Andersen, et al.              Experimental                     [Page 35]
  2.1966 +
  2.1967 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.1968 +
  2.1969 +
  2.1970 +4.5.2.  Block Not Received
  2.1971 +
  2.1972 +   If the block is not received, the block substitution is based on a
  2.1973 +   pitch-synchronous repetition of the excitation signal, which is
  2.1974 +   filtered by the last LP filter of the previous block.  The previous
  2.1975 +   block's information is stored in the decoder state structure.
  2.1976 +
  2.1977 +   A correlation analysis is performed on the previous block's
  2.1978 +   excitation signal in order to detect the amount of pitch periodicity
  2.1979 +   and a pitch value.  The correlation measure is also used to decide on
  2.1980 +   the voicing level (the degree to which the previous block's
  2.1981 +   excitation was a voiced or roughly periodic signal).  The excitation
  2.1982 +   in the previous block is used to create an excitation for the block
  2.1983 +   to be substituted, such that the pitch of the previous block is
  2.1984 +   maintained.  Therefore, the new excitation is constructed in a
  2.1985 +   pitch-synchronous manner.  In order to avoid a buzzy-sounding
  2.1986 +   substituted block, a random excitation is mixed with the new pitch
  2.1987 +   periodic excitation, and the relative use of the two components is
  2.1988 +   computed from the correlation measure (voicing level).
  2.1989 +
  2.1990 +   For the block to be substituted, the newly constructed excitation
  2.1991 +   signal is then passed through the LP filter to produce the speech
  2.1992 +   that will be substituted for the lost block.
  2.1993 +
  2.1994 +   For several consecutive lost blocks, the packet loss concealment
  2.1995 +   continues in a similar manner.  The correlation measure of the last
  2.1996 +   block received is still used along with the same pitch value.  The LP
  2.1997 +   filters of the last block received are also used again.  The energy
  2.1998 +   of the substituted excitation for consecutive lost blocks is
  2.1999 +   decreased, leading to a dampened excitation, and therefore to
  2.2000 +   dampened speech.
  2.2001 +
  2.2002 +4.5.3.  Block Received Correctly When Previous Block Not Received
  2.2003 +
  2.2004 +   For the case in which a block is received correctly when the previous
  2.2005 +   block was not, the correctly received block's directly decoded speech
  2.2006 +   (based solely on the received block) is not used as the actual
  2.2007 +   output.  The reason for this is that the directly decoded speech does
  2.2008 +   not necessarily smoothly merge into the synthetic speech generated
  2.2009 +   for the previous lost block.  If the two signals are not smoothly
  2.2010 +   merged, an audible discontinuity is accidentally produced.
  2.2011 +   Therefore, a correlation analysis between the two blocks of
  2.2012 +   excitation signal (the excitation of the previous concealed block and
  2.2013 +   that of the current received block) is performed to find the best
  2.2014 +   phase match.  Then a simple overlap-add procedure is performed to
  2.2015 +   merge the previous excitation smoothly into the current block's
  2.2016 +   excitation.
  2.2017 +
  2.2018 +
  2.2019 +
  2.2020 +
  2.2021 +Andersen, et al.              Experimental                     [Page 36]
  2.2022 +
  2.2023 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2024 +
  2.2025 +
  2.2026 +   The exact implementation of the packet loss concealment does not
  2.2027 +   influence interoperability of the codec.
  2.2028 +
  2.2029 +   A reference implementation of the packet loss concealment is
  2.2030 +   suggested in Appendix A.14.  Exact compliance with this suggested
  2.2031 +   algorithm is not needed for a reference implementation to be fully
  2.2032 +   compatible with the overall codec specification.
  2.2033 +
  2.2034 +4.6.  Enhancement
  2.2035 +
  2.2036 +   The decoder contains an enhancement unit that operates on the
  2.2037 +   reconstructed excitation signal.  The enhancement unit increases the
  2.2038 +   perceptual quality of the reconstructed signal by reducing the
  2.2039 +   speech-correlated noise in the voiced speech segments.  Compared to
  2.2040 +   traditional postfilters, the enhancer has an advantage in that it can
  2.2041 +   only modify the excitation signal slightly.  This means that there is
  2.2042 +   no risk of over enhancement.  The enhancer works very similarly for
  2.2043 +   both the 20 ms frame size mode and the 30 ms frame size mode.
  2.2044 +
  2.2045 +   For the mode with 20 ms frame size, the enhancer uses a memory of six
  2.2046 +   80-sample excitation blocks prior in time plus the two new 80-sample
  2.2047 +   excitation blocks.  For each block of 160 new unenhanced excitation
  2.2048 +   samples, 160 enhanced excitation samples are produced.  The enhanced
  2.2049 +   excitation is 40-sample delayed compared to the unenhanced
  2.2050 +   excitation, as the enhancer algorithm uses lookahead.
  2.2051 +
  2.2052 +   For the mode with 30 ms frame size, the enhancer uses a memory of
  2.2053 +   five 80-sample excitation blocks prior in time plus the three new
  2.2054 +   80-sample excitation blocks.  For each block of 240 new unenhanced
  2.2055 +   excitation samples, 240 enhanced excitation samples are produced.
  2.2056 +   The enhanced excitation is 80-sample delayed compared to the
  2.2057 +   unenhanced excitation, as the enhancer algorithm uses lookahead.
  2.2058 +
  2.2059 +   Outline of Enhancer
  2.2060 +
  2.2061 +   The speech enhancement unit operates on sub-blocks of 80 samples,
  2.2062 +   which means that there are two/three 80 sample sub-blocks per frame.
  2.2063 +   Each of these two/three sub-blocks is enhanced separately, but in an
  2.2064 +   analogous manner.
  2.2065 +
  2.2066 +
  2.2067 +
  2.2068 +
  2.2069 +
  2.2070 +
  2.2071 +
  2.2072 +
  2.2073 +
  2.2074 +
  2.2075 +
  2.2076 +
  2.2077 +Andersen, et al.              Experimental                     [Page 37]
  2.2078 +
  2.2079 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2080 +
  2.2081 +
  2.2082 +   unenhanced residual
  2.2083 +           |
  2.2084 +           |   +---------------+    +--------------+
  2.2085 +           +-> | 1. Pitch Est  | -> | 2. Find PSSQ | -------->
  2.2086 +               +---------------+  | +--------------+
  2.2087 +                                  +-----<-------<------<--+
  2.2088 +               +------------+         enh block 0..1/2    |
  2.2089 +            -> | 3. Smooth  |                             |
  2.2090 +               +------------+                             |
  2.2091 +                 \                                        |
  2.2092 +                 /\                                       |
  2.2093 +                /  \   Already                            |
  2.2094 +               / 4. \----------->----------->-----------+ |
  2.2095 +               \Crit/ Fulfilled                         | |
  2.2096 +                \? /                                    v |
  2.2097 +                 \/                                     | |
  2.2098 +                  \  +-----------------+    +---------+ | |
  2.2099 +              Not +->| 5. Use Constr.  | -> | 6. Mix  | ----->
  2.2100 +           Fulfilled +-----------------+    +---------+
  2.2101 +
  2.2102 +            ---------------> enhanced residual
  2.2103 +
  2.2104 +   Figure 4.2.  Flow chart of the enhancer.
  2.2105 +
  2.2106 +   1. Pitch estimation of each of the two/three new 80-sample blocks.
  2.2107 +
  2.2108 +   2. Find the pitch-period-synchronous sequence n (for block k) by a
  2.2109 +      search around the estimated pitch value.  Do this for n=1,2,3,
  2.2110 +      -1,-2,-3.
  2.2111 +
  2.2112 +   3. Calculate the smoothed residual generated by the six pitch-
  2.2113 +      period-synchronous sequences from prior step.
  2.2114 +
  2.2115 +   4. Check if the smoothed residual satisfies the criterion (section
  2.2116 +      4.6.4).
  2.2117 +
  2.2118 +   5. Use constraint to calculate mixing factor (section 4.6.5).
  2.2119 +
  2.2120 +   6. Mix smoothed signal with unenhanced residual (pssq(n) n=0).
  2.2121 +
  2.2122 +   The main idea of the enhancer is to find three 80 sample blocks
  2.2123 +   before and three 80-sample blocks after the analyzed unenhanced sub-
  2.2124 +   block and to use these to improve the quality of the excitation in
  2.2125 +   that sub-block.  The six blocks are chosen so that they have the
  2.2126 +   highest possible correlation with the unenhanced sub-block that is
  2.2127 +   being enhanced.  In other words, the six blocks are pitch-period-
  2.2128 +   synchronous sequences to the unenhanced sub-block.
  2.2129 +
  2.2130 +
  2.2131 +
  2.2132 +
  2.2133 +Andersen, et al.              Experimental                     [Page 38]
  2.2134 +
  2.2135 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2136 +
  2.2137 +
  2.2138 +   A linear combination of the six pitch-period-synchronous sequences is
  2.2139 +   calculated that approximates the sub-block.  If the squared error
  2.2140 +   between the approximation and the unenhanced sub-block is small
  2.2141 +   enough, the enhanced residual is set equal to this approximation.
  2.2142 +   For the cases when the squared error criterion is not fulfilled, a
  2.2143 +   linear combination of the approximation and the unenhanced residual
  2.2144 +   forms the enhanced residual.
  2.2145 +
  2.2146 +4.6.1.  Estimating the Pitch
  2.2147 +
  2.2148 +   Pitch estimates are needed to determine the locations of the pitch-
  2.2149 +   period-synchronous sequences in a complexity-efficient way.  For each
  2.2150 +   of the new two/three sub-blocks, a pitch estimate is calculated by
  2.2151 +   finding the maximum correlation in the range from lag 20 to lag 120.
  2.2152 +   These pitch estimates are used to narrow down the search for the best
  2.2153 +   possible pitch-period-synchronous sequences.
  2.2154 +
  2.2155 +4.6.2.  Determination of the Pitch-Synchronous Sequences
  2.2156 +
  2.2157 +   Upon receiving the pitch estimates from the prior step, the enhancer
  2.2158 +   analyzes and enhances one 80-sample sub-block at a time.  The pitch-
  2.2159 +   period-synchronous-sequences pssq(n) can be viewed as vectors of
  2.2160 +   length 80 samples each shifted n*lag samples from the current sub-
  2.2161 +   block.  The six pitch-period-synchronous-sequences, pssq(-3) to
  2.2162 +   pssq(-1) and pssq(1) to pssq(3), are found one at a time by the steps
  2.2163 +   below:
  2.2164 +
  2.2165 +   1) Calculate the estimate of the position of the pssq(n).  For
  2.2166 +      pssq(n) in front of pssq(0) (n > 0), the location of the pssq(n)
  2.2167 +      is estimated by moving one pitch estimate forward in time from the
  2.2168 +      exact location of pssq(n-1).  Similarly, pssq(n) behind pssq(0) (n
  2.2169 +      < 0) is estimated by moving one pitch estimate backward in time
  2.2170 +      from the exact location of pssq(n+1).  If the estimated pssq(n)
  2.2171 +      vector location is totally within the enhancer memory (Figure
  2.2172 +      4.3), steps 2, 3, and 4 are performed, otherwise the pssq(n) is
  2.2173 +      set to zeros.
  2.2174 +
  2.2175 +   2) Compute the correlation between the unenhanced excitation and
  2.2176 +      vectors around the estimated location interval of pssq(n).  The
  2.2177 +      correlation is calculated in the interval estimated location +/- 2
  2.2178 +      samples.  This results in five correlation values.
  2.2179 +
  2.2180 +   3) The five correlation values are upsampled by a factor of 4, by
  2.2181 +      using four simple upsampling filters (MA filters with coefficients
  2.2182 +      upsFilter1.. upsFilter4).  Within these the maximum value is
  2.2183 +      found, which specifies the best pitch-period with a resolution of
  2.2184 +      a quarter of a sample.
  2.2185 +
  2.2186 +
  2.2187 +
  2.2188 +
  2.2189 +Andersen, et al.              Experimental                     [Page 39]
  2.2190 +
  2.2191 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2192 +
  2.2193 +
  2.2194 +      upsFilter1[7]={0.000000 0.000000 0.000000 1.000000
  2.2195 +             0.000000 0.000000 0.000000}
  2.2196 +      upsFilter2[7]={0.015625 -0.076904 0.288330 0.862061
  2.2197 +            -0.106445 0.018799 -0.015625}
  2.2198 +      upsFilter3[7]={0.023682 -0.124268 0.601563 0.601563
  2.2199 +            -0.124268 0.023682 -0.023682}
  2.2200 +      upsFilter4[7]={0.018799 -0.106445 0.862061 0.288330
  2.2201 +            -0.076904 0.015625 -0.018799}
  2.2202 +
  2.2203 +   4) Generate the pssq(n) vector by upsampling of the excitation memory
  2.2204 +      and extracting the sequence that corresponds to the lag delay that
  2.2205 +      was calculated in prior step.
  2.2206 +
  2.2207 +   With the steps above, all the pssq(n) can be found in an iterative
  2.2208 +   manner, first moving backward in time from pssq(0) and then forward
  2.2209 +   in time from pssq(0).
  2.2210 +
  2.2211 +
  2.2212 +   0              159             319             479             639
  2.2213 +   +---------------------------------------------------------------+
  2.2214 +   |  -5   |  -4   |  -3   |  -2   |  -1   |   0   |   1   |   2   |
  2.2215 +   +---------------------------------------------------------------+
  2.2216 +                                               |pssq 0 |
  2.2217 +                                          |pssq -1| |pssq 1 |
  2.2218 +                                       |pssq -2|       |pssq 2 |
  2.2219 +                                    |pssq -3|             |pssq 3 |
  2.2220 +
  2.2221 +   Figure 4.3.  Enhancement for 20 ms frame size.
  2.2222 +
  2.2223 +   Figure 4.3 depicts pitch-period-synchronous sequences in the
  2.2224 +   enhancement of the first 80 sample block in the 20 ms frame size
  2.2225 +   mode.  The unenhanced signal input is stored in the last two sub-
  2.2226 +   blocks (1 - 2), and the six other sub-blocks contain unenhanced
  2.2227 +   residual prior-in-time.  We perform the enhancement algorithm on two
  2.2228 +   blocks of 80 samples, where the first of the two blocks consists of
  2.2229 +   the last 40 samples of sub-block 0 and the first 40 samples of sub-
  2.2230 +   block 1.  The second 80-sample block consists of the last 40 samples
  2.2231 +   of sub-block 1 and the first 40 samples of sub-block 2.
  2.2232 +
  2.2233 +
  2.2234 +
  2.2235 +
  2.2236 +
  2.2237 +
  2.2238 +
  2.2239 +
  2.2240 +
  2.2241 +
  2.2242 +
  2.2243 +
  2.2244 +
  2.2245 +Andersen, et al.              Experimental                     [Page 40]
  2.2246 +
  2.2247 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2248 +
  2.2249 +
  2.2250 +   0              159             319             479             639
  2.2251 +   +---------------------------------------------------------------+
  2.2252 +   |  -4   |  -3   |  -2   |  -1   |   0   |   1   |   2   |   3   |
  2.2253 +   +---------------------------------------------------------------+
  2.2254 +                                   |pssq 0 |
  2.2255 +                              |pssq -1| |pssq 1 |
  2.2256 +                           |pssq -2|       |pssq 2 |
  2.2257 +                        |pssq -3|             |pssq 3 |
  2.2258 +
  2.2259 +   Figure 4.4.  Enhancement for 30 ms frame size.
  2.2260 +
  2.2261 +   Figure 4.4 depicts pitch-period-synchronous sequences in the
  2.2262 +   enhancement of the first 80-sample block in the 30 ms frame size
  2.2263 +   mode.  The unenhanced signal input is stored in the last three sub-
  2.2264 +   blocks (1 - 3).  The five other sub-blocks contain unenhanced
  2.2265 +   residual prior-in-time.  The enhancement algorithm is performed on
  2.2266 +   the three 80 sample sub-blocks 0, 1, and 2.
  2.2267 +
  2.2268 +4.6.3.  Calculation of the Smoothed Excitation
  2.2269 +
  2.2270 +   A linear combination of the six pssq(n) (n!=0) form a smoothed
  2.2271 +   approximation, z, of pssq(0).  Most of the weight is put on the
  2.2272 +   sequences that are close to pssq(0), as these are likely to be most
  2.2273 +   similar to pssq(0).  The smoothed vector is also rescaled so that the
  2.2274 +   energy of z is the same as the energy of pssq(0).
  2.2275 +
  2.2276 +      ___
  2.2277 +      \
  2.2278 +   y = > pssq(i) * pssq_weight(i)
  2.2279 +      /__
  2.2280 +   i=-3,-2,-1,1,2,3
  2.2281 +
  2.2282 +   pssq_weight(i) = 0.5*(1-cos(2*pi*(i+4)/(2*3+2)))
  2.2283 +
  2.2284 +   z = C * y, where C = ||pssq(0)||/||y||
  2.2285 +
  2.2286 +4.6.4.  Enhancer Criterion
  2.2287 +
  2.2288 +   The criterion of the enhancer is that the enhanced excitation is not
  2.2289 +   allowed to differ much from the unenhanced excitation.  This
  2.2290 +   criterion is checked for each 80-sample sub-block.
  2.2291 +
  2.2292 +   e < (b * ||pssq(0)||^2), where b=0.05 and   (Constraint 1)
  2.2293 +
  2.2294 +   e = (pssq(0)-z)*(pssq(0)-z), and "*" means the dot product
  2.2295 +
  2.2296 +
  2.2297 +
  2.2298 +
  2.2299 +
  2.2300 +
  2.2301 +Andersen, et al.              Experimental                     [Page 41]
  2.2302 +
  2.2303 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2304 +
  2.2305 +
  2.2306 +4.6.5.  Enhancing the excitation
  2.2307 +
  2.2308 +   From the criterion in the previous section, it is clear that the
  2.2309 +   excitation is not allowed to change much.  The purpose of this
  2.2310 +   constraint is to prevent the creation of an enhanced signal
  2.2311 +   significantly different from the original signal.  This also means
  2.2312 +   that the constraint limits the numerical size of the errors that the
  2.2313 +   enhancement procedure can make.  That is especially important in
  2.2314 +   unvoiced segments and background noise segments for which increased
  2.2315 +   periodicity could lead to lower perceived quality.
  2.2316 +
  2.2317 +   When the constraint in the prior section is not met, the enhanced
  2.2318 +   residual is instead calculated through a constrained optimization by
  2.2319 +   using the Lagrange multiplier technique.  The new constraint is that
  2.2320 +
  2.2321 +      e = (b * ||pssq(0)||^2)                     (Constraint 2)
  2.2322 +
  2.2323 +   We distinguish two solution regions for the optimization: 1) the
  2.2324 +   region where the first constraint is fulfilled and 2) the region
  2.2325 +   where the first constraint is not fulfilled and the second constraint
  2.2326 +   must be used.
  2.2327 +
  2.2328 +   In the first case, where the second constraint is not needed, the
  2.2329 +   optimized re-estimated vector is simply z, the energy-scaled version
  2.2330 +   of y.
  2.2331 +
  2.2332 +   In the second case, where the second constraint is activated and
  2.2333 +   becomes an equality constraint, we have
  2.2334 +
  2.2335 +      z= A*y + B*pssq(0)
  2.2336 +
  2.2337 +   where
  2.2338 +
  2.2339 +      A = sqrt((b-b^2/4)*(w00*w00)/ (w11*w00 + w10*w10)) and
  2.2340 +
  2.2341 +      w11 = pssq(0)*pssq(0)
  2.2342 +      w00 = y*y
  2.2343 +      w10 = y*pssq(0)    (* symbolizes the dot product)
  2.2344 +
  2.2345 +   and
  2.2346 +
  2.2347 +      B = 1 - b/2 - A * w10/w00
  2.2348 +
  2.2349 +   Appendix A.16 contains a listing of a reference implementation for
  2.2350 +   the enhancement method.
  2.2351 +
  2.2352 +
  2.2353 +
  2.2354 +
  2.2355 +
  2.2356 +
  2.2357 +Andersen, et al.              Experimental                     [Page 42]
  2.2358 +
  2.2359 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2360 +
  2.2361 +
  2.2362 +4.7.  Synthesis Filtering
  2.2363 +
  2.2364 +   Upon decoding or PLC of the LP excitation block, the decoded speech
  2.2365 +   block is obtained by running the decoded LP synthesis filter,
  2.2366 +   1/A~k(z), over the block.  The synthesis filters have to be shifted
  2.2367 +   to compensate for the delay in the enhancer.  For 20 ms frame size
  2.2368 +   mode, they SHOULD be shifted one 40-sample sub-block, and for 30 ms
  2.2369 +   frame size mode, they SHOULD be shifted two 40-sample sub-blocks.
  2.2370 +   The LP coefficients SHOULD be changed at the first sample of every
  2.2371 +   sub-block while keeping the filter state.  For PLC blocks, one
  2.2372 +   solution is to apply the last LP coefficients of the last decoded
  2.2373 +   speech block for all sub-blocks.
  2.2374 +
  2.2375 +   The reference implementation for the synthesis filtering can be found
  2.2376 +   in Appendix A.48.
  2.2377 +
  2.2378 +4.8.  Post Filtering
  2.2379 +
  2.2380 +   If desired, the decoded block can be filtered by a high-pass filter.
  2.2381 +   This removes the low frequencies of the decoded signal.  A reference
  2.2382 +   implementation of this, with cutoff at 65 Hz, is shown in Appendix
  2.2383 +   A.30.
  2.2384 +
  2.2385 +5.  Security Considerations
  2.2386 +
  2.2387 +   This algorithm for the coding of speech signals is not subject to any
  2.2388 +   known security consideration; however, its RTP payload format [1] is
  2.2389 +   subject to several considerations, which are addressed there.
  2.2390 +   Confidentiality of the media streams is achieved by encryption;
  2.2391 +   therefore external mechanisms, such as SRTP [5], MAY be used for that
  2.2392 +   purpose.
  2.2393 +
  2.2394 +6.  Evaluation of the iLBC Implementations
  2.2395 +
  2.2396 +   It is possible and suggested to evaluate certain iLBC implementation
  2.2397 +   by utilizing methodology and tools available at
  2.2398 +   http://www.ilbcfreeware.org/evaluation.html
  2.2399 +
  2.2400 +7.  References
  2.2401 +
  2.2402 +7.1.  Normative References
  2.2403 +
  2.2404 +   [1] Duric, A. and S. Andersen, "Real-time Transport Protocol (RTP)
  2.2405 +       Payload Format for internet Low Bit Rate Codec (iLBC) Speech",
  2.2406 +       RFC 3952, December 2004.
  2.2407 +
  2.2408 +   [2] Bradner, S., "Key words for use in RFCs to Indicate Requirement
  2.2409 +       Levels", BCP 14, RFC 2119, March 1997.
  2.2410 +
  2.2411 +
  2.2412 +
  2.2413 +Andersen, et al.              Experimental                     [Page 43]
  2.2414 +
  2.2415 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2416 +
  2.2417 +
  2.2418 +   [3] PacketCable(TM) Audio/Video Codecs Specification, Cable
  2.2419 +       Television Laboratories, Inc.
  2.2420 +
  2.2421 +7.2.  Informative References
  2.2422 +
  2.2423 +   [4] ITU-T Recommendation G.711, available online from the ITU
  2.2424 +       bookstore at http://www.itu.int.
  2.2425 +
  2.2426 +   [5] Baugher, M., McGrew, D., Naslund, M., Carrara, E., and K. Norman,
  2.2427 +       "The Secure Real Time Transport Protocol (SRTP)", RFC 3711, March
  2.2428 +       2004.
  2.2429 +
  2.2430 +8.  Acknowledgements
  2.2431 +
  2.2432 +   This extensive work, besides listed authors, has the following
  2.2433 +   authors, who could not have been listed among "official" authors (due
  2.2434 +   to IESG restrictions in the number of authors who can be listed):
  2.2435 +
  2.2436 +      Manohar N. Murthi (Department of Electrical and Computer
  2.2437 +      Engineering, University of Miami), Fredrik Galschiodt, Julian
  2.2438 +      Spittka, and Jan Skoglund (Global IP Sound).
  2.2439 +
  2.2440 +   The authors are deeply indebted to the following people and thank
  2.2441 +   them sincerely:
  2.2442 +
  2.2443 +      Henry Sinnreich, Patrik Faltstrom, Alan Johnston, and Jean-
  2.2444 +      Francois Mule for great support of the iLBC initiative and for
  2.2445 +      valuable feedback and comments.
  2.2446 +
  2.2447 +      Peter Vary, Frank Mertz, and Christoph Erdmann (RWTH Aachen);
  2.2448 +      Vladimir Cuperman (Niftybox LLC); Thomas Eriksson (Chalmers Univ
  2.2449 +      of Tech), and Gernot Kubin (TU Graz), for thorough review of the
  2.2450 +      iLBC document and their valuable feedback and remarks.
  2.2451 +
  2.2452 +
  2.2453 +
  2.2454 +
  2.2455 +
  2.2456 +
  2.2457 +
  2.2458 +
  2.2459 +
  2.2460 +
  2.2461 +
  2.2462 +
  2.2463 +
  2.2464 +
  2.2465 +
  2.2466 +
  2.2467 +
  2.2468 +
  2.2469 +Andersen, et al.              Experimental                     [Page 44]
  2.2470 +
  2.2471 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2472 +
  2.2473 +
  2.2474 +APPENDIX A.  Reference Implementation
  2.2475 +
  2.2476 +   This appendix contains the complete c-code for a reference
  2.2477 +   implementation of encoder and decoder for the specified codec.
  2.2478 +
  2.2479 +   The c-code consists of the following files with highest-level
  2.2480 +   functions:
  2.2481 +
  2.2482 +         iLBC_test.c: main function for evaluation purpose
  2.2483 +         iLBC_encode.h: encoder header
  2.2484 +         iLBC_encode.c: encoder function
  2.2485 +         iLBC_decode.h: decoder header
  2.2486 +         iLBC_decode.c: decoder function
  2.2487 +
  2.2488 +   The following files contain global defines and constants:
  2.2489 +
  2.2490 +         iLBC_define.h: global defines
  2.2491 +         constants.h: global constants header
  2.2492 +         constants.c: global constants memory allocations
  2.2493 +
  2.2494 +   The following files contain subroutines:
  2.2495 +
  2.2496 +         anaFilter.h: lpc analysis filter header
  2.2497 +         anaFilter.c: lpc analysis filter function
  2.2498 +         createCB.h: codebook construction header
  2.2499 +         createCB.c: codebook construction function
  2.2500 +         doCPLC.h: packet loss concealment header
  2.2501 +         doCPLC.c: packet loss concealment function
  2.2502 +         enhancer.h: signal enhancement header
  2.2503 +         enhancer.c: signal enhancement function
  2.2504 +         filter.h: general filter header
  2.2505 +         filter.c: general filter functions
  2.2506 +         FrameClassify.h: start state classification header
  2.2507 +         FrameClassify.c: start state classification function
  2.2508 +         gainquant.h: gain quantization header
  2.2509 +         gainquant.c: gain quantization function
  2.2510 +         getCBvec.h: codebook vector construction header
  2.2511 +         getCBvec.c: codebook vector construction function
  2.2512 +         helpfun.h: general purpose header
  2.2513 +         helpfun.c: general purpose functions
  2.2514 +         hpInput.h: input high pass filter header
  2.2515 +         hpInput.c: input high pass filter function
  2.2516 +         hpOutput.h: output high pass filter header
  2.2517 +         hpOutput.c: output high pass filter function
  2.2518 +         iCBConstruct.h: excitation decoding header
  2.2519 +         iCBConstruct.c: excitation decoding function
  2.2520 +         iCBSearch.h: excitation encoding header
  2.2521 +         iCBSearch.c: excitation encoding function
  2.2522 +
  2.2523 +
  2.2524 +
  2.2525 +Andersen, et al.              Experimental                     [Page 45]
  2.2526 +
  2.2527 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2528 +
  2.2529 +
  2.2530 +         LPCdecode.h: lpc decoding header
  2.2531 +         LPCdecode.c: lpc decoding function
  2.2532 +         LPCencode.h: lpc encoding header
  2.2533 +         LPCencode.c: lpc encoding function
  2.2534 +         lsf.h: line spectral frequencies header
  2.2535 +         lsf.c: line spectral frequencies functions
  2.2536 +         packing.h: bitstream packetization header
  2.2537 +         packing.c: bitstream packetization functions
  2.2538 +         StateConstructW.h: state decoding header
  2.2539 +         StateConstructW.c: state decoding functions
  2.2540 +         StateSearchW.h: state encoding header
  2.2541 +         StateSearchW.c: state encoding function
  2.2542 +         syntFilter.h: lpc synthesis filter header
  2.2543 +         syntFilter.c: lpc synthesis filter function
  2.2544 +
  2.2545 +   The implementation is portable and should work on many different
  2.2546 +   platforms.  However, it is not difficult to optimize the
  2.2547 +   implementation on particular platforms, an exercise left to the
  2.2548 +   reader.
  2.2549 +
  2.2550 +A.1.  iLBC_test.c
  2.2551 +
  2.2552 +   /******************************************************************
  2.2553 +
  2.2554 +       iLBC Speech Coder ANSI-C Source Code
  2.2555 +
  2.2556 +       iLBC_test.c
  2.2557 +
  2.2558 +       Copyright (C) The Internet Society (2004).
  2.2559 +       All Rights Reserved.
  2.2560 +
  2.2561 +   ******************************************************************/
  2.2562 +
  2.2563 +   #include <math.h>
  2.2564 +   #include <stdlib.h>
  2.2565 +   #include <stdio.h>
  2.2566 +   #include <string.h>
  2.2567 +   #include "iLBC_define.h"
  2.2568 +   #include "iLBC_encode.h"
  2.2569 +   #include "iLBC_decode.h"
  2.2570 +
  2.2571 +   /* Runtime statistics */
  2.2572 +   #include <time.h>
  2.2573 +
  2.2574 +   #define ILBCNOOFWORDS_MAX   (NO_OF_BYTES_30MS/2)
  2.2575 +
  2.2576 +   /*----------------------------------------------------------------*
  2.2577 +    *  Encoder interface function
  2.2578 +
  2.2579 +
  2.2580 +
  2.2581 +Andersen, et al.              Experimental                     [Page 46]
  2.2582 +
  2.2583 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2584 +
  2.2585 +
  2.2586 +    *---------------------------------------------------------------*/
  2.2587 +
  2.2588 +   short encode(   /* (o) Number of bytes encoded */
  2.2589 +       iLBC_Enc_Inst_t *iLBCenc_inst,
  2.2590 +                                   /* (i/o) Encoder instance */
  2.2591 +       short *encoded_data,    /* (o) The encoded bytes */
  2.2592 +       short *data                 /* (i) The signal block to encode*/
  2.2593 +   ){
  2.2594 +       float block[BLOCKL_MAX];
  2.2595 +       int k;
  2.2596 +
  2.2597 +       /* convert signal to float */
  2.2598 +
  2.2599 +       for (k=0; k<iLBCenc_inst->blockl; k++)
  2.2600 +           block[k] = (float)data[k];
  2.2601 +
  2.2602 +       /* do the actual encoding */
  2.2603 +
  2.2604 +       iLBC_encode((unsigned char *)encoded_data, block, iLBCenc_inst);
  2.2605 +
  2.2606 +
  2.2607 +       return (iLBCenc_inst->no_of_bytes);
  2.2608 +   }
  2.2609 +
  2.2610 +   /*----------------------------------------------------------------*
  2.2611 +    *  Decoder interface function
  2.2612 +    *---------------------------------------------------------------*/
  2.2613 +
  2.2614 +   short decode(       /* (o) Number of decoded samples */
  2.2615 +       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */
  2.2616 +       short *decoded_data,        /* (o) Decoded signal block*/
  2.2617 +       short *encoded_data,        /* (i) Encoded bytes */
  2.2618 +       short mode                       /* (i) 0=PL, 1=Normal */
  2.2619 +   ){
  2.2620 +       int k;
  2.2621 +       float decblock[BLOCKL_MAX], dtmp;
  2.2622 +
  2.2623 +       /* check if mode is valid */
  2.2624 +
  2.2625 +       if (mode<0 || mode>1) {
  2.2626 +           printf("\nERROR - Wrong mode - 0, 1 allowed\n"); exit(3);}
  2.2627 +
  2.2628 +       /* do actual decoding of block */
  2.2629 +
  2.2630 +       iLBC_decode(decblock, (unsigned char *)encoded_data,
  2.2631 +           iLBCdec_inst, mode);
  2.2632 +
  2.2633 +       /* convert to short */
  2.2634 +
  2.2635 +
  2.2636 +
  2.2637 +Andersen, et al.              Experimental                     [Page 47]
  2.2638 +
  2.2639 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2640 +
  2.2641 +
  2.2642 +       for (k=0; k<iLBCdec_inst->blockl; k++){
  2.2643 +           dtmp=decblock[k];
  2.2644 +
  2.2645 +           if (dtmp<MIN_SAMPLE)
  2.2646 +               dtmp=MIN_SAMPLE;
  2.2647 +           else if (dtmp>MAX_SAMPLE)
  2.2648 +               dtmp=MAX_SAMPLE;
  2.2649 +           decoded_data[k] = (short) dtmp;
  2.2650 +       }
  2.2651 +
  2.2652 +       return (iLBCdec_inst->blockl);
  2.2653 +   }
  2.2654 +
  2.2655 +   /*---------------------------------------------------------------*
  2.2656 +    *  Main program to test iLBC encoding and decoding
  2.2657 +    *
  2.2658 +    *  Usage:
  2.2659 +    *    exefile_name.exe <infile> <bytefile> <outfile> <channel>
  2.2660 +    *
  2.2661 +    *    <infile>   : Input file, speech for encoder (16-bit pcm file)
  2.2662 +    *    <bytefile> : Bit stream output from the encoder
  2.2663 +    *    <outfile>  : Output file, decoded speech (16-bit pcm file)
  2.2664 +    *    <channel>  : Bit error file, optional (16-bit)
  2.2665 +    *                     1 - Packet received correctly
  2.2666 +    *                     0 - Packet Lost
  2.2667 +    *
  2.2668 +    *--------------------------------------------------------------*/
  2.2669 +
  2.2670 +   int main(int argc, char* argv[])
  2.2671 +   {
  2.2672 +
  2.2673 +       /* Runtime statistics */
  2.2674 +
  2.2675 +       float starttime;
  2.2676 +       float runtime;
  2.2677 +       float outtime;
  2.2678 +
  2.2679 +       FILE *ifileid,*efileid,*ofileid, *cfileid;
  2.2680 +       short data[BLOCKL_MAX];
  2.2681 +       short encoded_data[ILBCNOOFWORDS_MAX], decoded_data[BLOCKL_MAX];
  2.2682 +       int len;
  2.2683 +       short pli, mode;
  2.2684 +       int blockcount = 0;
  2.2685 +       int packetlosscount = 0;
  2.2686 +
  2.2687 +       /* Create structs */
  2.2688 +       iLBC_Enc_Inst_t Enc_Inst;
  2.2689 +       iLBC_Dec_Inst_t Dec_Inst;
  2.2690 +
  2.2691 +
  2.2692 +
  2.2693 +Andersen, et al.              Experimental                     [Page 48]
  2.2694 +
  2.2695 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2696 +
  2.2697 +
  2.2698 +       /* get arguments and open files */
  2.2699 +
  2.2700 +       if ((argc!=5) && (argc!=6)) {
  2.2701 +           fprintf(stderr,
  2.2702 +           "\n*-----------------------------------------------*\n");
  2.2703 +           fprintf(stderr,
  2.2704 +           "   %s <20,30> input encoded decoded (channel)\n\n",
  2.2705 +               argv[0]);
  2.2706 +           fprintf(stderr,
  2.2707 +           "   mode    : Frame size for the encoding/decoding\n");
  2.2708 +           fprintf(stderr,
  2.2709 +           "                 20 - 20 ms\n");
  2.2710 +           fprintf(stderr,
  2.2711 +           "                 30 - 30 ms\n");
  2.2712 +           fprintf(stderr,
  2.2713 +           "   input   : Speech for encoder (16-bit pcm file)\n");
  2.2714 +           fprintf(stderr,
  2.2715 +           "   encoded : Encoded bit stream\n");
  2.2716 +           fprintf(stderr,
  2.2717 +           "   decoded : Decoded speech (16-bit pcm file)\n");
  2.2718 +           fprintf(stderr,
  2.2719 +           "   channel : Packet loss pattern, optional (16-bit)\n");
  2.2720 +           fprintf(stderr,
  2.2721 +           "                  1 - Packet received correctly\n");
  2.2722 +           fprintf(stderr,
  2.2723 +           "                  0 - Packet Lost\n");
  2.2724 +           fprintf(stderr,
  2.2725 +           "*-----------------------------------------------*\n\n");
  2.2726 +           exit(1);
  2.2727 +       }
  2.2728 +       mode=atoi(argv[1]);
  2.2729 +       if (mode != 20 && mode != 30) {
  2.2730 +           fprintf(stderr,"Wrong mode %s, must be 20, or 30\n",
  2.2731 +               argv[1]);
  2.2732 +           exit(2);
  2.2733 +       }
  2.2734 +       if ( (ifileid=fopen(argv[2],"rb")) == NULL) {
  2.2735 +           fprintf(stderr,"Cannot open input file %s\n", argv[2]);
  2.2736 +           exit(2);}
  2.2737 +       if ( (efileid=fopen(argv[3],"wb")) == NULL) {
  2.2738 +           fprintf(stderr, "Cannot open encoded file %s\n",
  2.2739 +               argv[3]); exit(1);}
  2.2740 +       if ( (ofileid=fopen(argv[4],"wb")) == NULL) {
  2.2741 +           fprintf(stderr, "Cannot open decoded file %s\n",
  2.2742 +               argv[4]); exit(1);}
  2.2743 +       if (argc==6) {
  2.2744 +           if( (cfileid=fopen(argv[5],"rb")) == NULL) {
  2.2745 +               fprintf(stderr, "Cannot open channel file %s\n",
  2.2746 +
  2.2747 +
  2.2748 +
  2.2749 +Andersen, et al.              Experimental                     [Page 49]
  2.2750 +
  2.2751 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2752 +
  2.2753 +
  2.2754 +                   argv[5]);
  2.2755 +               exit(1);
  2.2756 +           }
  2.2757 +       } else {
  2.2758 +           cfileid=NULL;
  2.2759 +       }
  2.2760 +
  2.2761 +       /* print info */
  2.2762 +
  2.2763 +       fprintf(stderr, "\n");
  2.2764 +       fprintf(stderr,
  2.2765 +           "*---------------------------------------------------*\n");
  2.2766 +       fprintf(stderr,
  2.2767 +           "*                                                   *\n");
  2.2768 +       fprintf(stderr,
  2.2769 +           "*      iLBC test program                            *\n");
  2.2770 +       fprintf(stderr,
  2.2771 +           "*                                                   *\n");
  2.2772 +       fprintf(stderr,
  2.2773 +           "*                                                   *\n");
  2.2774 +       fprintf(stderr,
  2.2775 +           "*---------------------------------------------------*\n");
  2.2776 +       fprintf(stderr,"\nMode           : %2d ms\n", mode);
  2.2777 +       fprintf(stderr,"Input file     : %s\n", argv[2]);
  2.2778 +       fprintf(stderr,"Encoded file   : %s\n", argv[3]);
  2.2779 +       fprintf(stderr,"Output file    : %s\n", argv[4]);
  2.2780 +       if (argc==6) {
  2.2781 +           fprintf(stderr,"Channel file   : %s\n", argv[5]);
  2.2782 +       }
  2.2783 +       fprintf(stderr,"\n");
  2.2784 +
  2.2785 +       /* Initialization */
  2.2786 +
  2.2787 +       initEncode(&Enc_Inst, mode);
  2.2788 +       initDecode(&Dec_Inst, mode, 1);
  2.2789 +
  2.2790 +       /* Runtime statistics */
  2.2791 +
  2.2792 +       starttime=clock()/(float)CLOCKS_PER_SEC;
  2.2793 +
  2.2794 +       /* loop over input blocks */
  2.2795 +
  2.2796 +       while (fread(data,sizeof(short),Enc_Inst.blockl,ifileid)==
  2.2797 +               Enc_Inst.blockl) {
  2.2798 +
  2.2799 +           blockcount++;
  2.2800 +
  2.2801 +           /* encoding */
  2.2802 +
  2.2803 +
  2.2804 +
  2.2805 +Andersen, et al.              Experimental                     [Page 50]
  2.2806 +
  2.2807 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2808 +
  2.2809 +
  2.2810 +           fprintf(stderr, "--- Encoding block %i --- ",blockcount);
  2.2811 +           len=encode(&Enc_Inst, encoded_data, data);
  2.2812 +           fprintf(stderr, "\r");
  2.2813 +
  2.2814 +           /* write byte file */
  2.2815 +
  2.2816 +           fwrite(encoded_data, sizeof(unsigned char), len, efileid);
  2.2817 +
  2.2818 +           /* get channel data if provided */
  2.2819 +           if (argc==6) {
  2.2820 +               if (fread(&pli, sizeof(short), 1, cfileid)) {
  2.2821 +                   if ((pli!=0)&&(pli!=1)) {
  2.2822 +                       fprintf(stderr, "Error in channel file\n");
  2.2823 +                       exit(0);
  2.2824 +                   }
  2.2825 +                   if (pli==0) {
  2.2826 +                       /* Packet loss -> remove info from frame */
  2.2827 +                       memset(encoded_data, 0,
  2.2828 +                           sizeof(short)*ILBCNOOFWORDS_MAX);
  2.2829 +                       packetlosscount++;
  2.2830 +                   }
  2.2831 +               } else {
  2.2832 +                   fprintf(stderr, "Error. Channel file too short\n");
  2.2833 +                   exit(0);
  2.2834 +               }
  2.2835 +           } else {
  2.2836 +               pli=1;
  2.2837 +           }
  2.2838 +
  2.2839 +           /* decoding */
  2.2840 +
  2.2841 +           fprintf(stderr, "--- Decoding block %i --- ",blockcount);
  2.2842 +
  2.2843 +           len=decode(&Dec_Inst, decoded_data, encoded_data, pli);
  2.2844 +           fprintf(stderr, "\r");
  2.2845 +
  2.2846 +           /* write output file */
  2.2847 +
  2.2848 +           fwrite(decoded_data,sizeof(short),len,ofileid);
  2.2849 +       }
  2.2850 +
  2.2851 +       /* Runtime statistics */
  2.2852 +
  2.2853 +       runtime = (float)(clock()/(float)CLOCKS_PER_SEC-starttime);
  2.2854 +       outtime = (float)((float)blockcount*(float)mode/1000.0);
  2.2855 +       printf("\n\nLength of speech file: %.1f s\n", outtime);
  2.2856 +       printf("Packet loss          : %.1f%%\n",
  2.2857 +           100.0*(float)packetlosscount/(float)blockcount);
  2.2858 +
  2.2859 +
  2.2860 +
  2.2861 +Andersen, et al.              Experimental                     [Page 51]
  2.2862 +
  2.2863 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2864 +
  2.2865 +
  2.2866 +       printf("Time to run iLBC     :");
  2.2867 +       printf(" %.1f s (%.1f %% of realtime)\n\n", runtime,
  2.2868 +           (100*runtime/outtime));
  2.2869 +
  2.2870 +       /* close files */
  2.2871 +
  2.2872 +       fclose(ifileid);  fclose(efileid); fclose(ofileid);
  2.2873 +       if (argc==6) {
  2.2874 +           fclose(cfileid);
  2.2875 +       }
  2.2876 +       return(0);
  2.2877 +   }
  2.2878 +
  2.2879 +A.2.  iLBC_encode.h
  2.2880 +
  2.2881 +   /******************************************************************
  2.2882 +
  2.2883 +       iLBC Speech Coder ANSI-C Source Code
  2.2884 +
  2.2885 +       iLBC_encode.h
  2.2886 +
  2.2887 +       Copyright (C) The Internet Society (2004).
  2.2888 +       All Rights Reserved.
  2.2889 +
  2.2890 +   ******************************************************************/
  2.2891 +
  2.2892 +   #ifndef __iLBC_ILBCENCODE_H
  2.2893 +   #define __iLBC_ILBCENCODE_H
  2.2894 +
  2.2895 +   #include "iLBC_define.h"
  2.2896 +
  2.2897 +   short initEncode(                   /* (o) Number of bytes
  2.2898 +                                              encoded */
  2.2899 +       iLBC_Enc_Inst_t *iLBCenc_inst,  /* (i/o) Encoder instance */
  2.2900 +       int mode                    /* (i) frame size mode */
  2.2901 +   );
  2.2902 +
  2.2903 +   void iLBC_encode(
  2.2904 +
  2.2905 +       unsigned char *bytes,           /* (o) encoded data bits iLBC */
  2.2906 +       float *block,                   /* (o) speech vector to
  2.2907 +                                              encode */
  2.2908 +       iLBC_Enc_Inst_t *iLBCenc_inst   /* (i/o) the general encoder
  2.2909 +                                              state */
  2.2910 +   );
  2.2911 +
  2.2912 +   #endif
  2.2913 +
  2.2914 +
  2.2915 +
  2.2916 +
  2.2917 +Andersen, et al.              Experimental                     [Page 52]
  2.2918 +
  2.2919 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2920 +
  2.2921 +
  2.2922 +A.3.  iLBC_encode.c
  2.2923 +
  2.2924 +   /******************************************************************
  2.2925 +
  2.2926 +       iLBC Speech Coder ANSI-C Source Code
  2.2927 +
  2.2928 +       iLBC_encode.c
  2.2929 +
  2.2930 +       Copyright (C) The Internet Society (2004).
  2.2931 +       All Rights Reserved.
  2.2932 +
  2.2933 +   ******************************************************************/
  2.2934 +
  2.2935 +   #include <math.h>
  2.2936 +   #include <stdlib.h>
  2.2937 +   #include <string.h>
  2.2938 +
  2.2939 +   #include "iLBC_define.h"
  2.2940 +   #include "LPCencode.h"
  2.2941 +   #include "FrameClassify.h"
  2.2942 +   #include "StateSearchW.h"
  2.2943 +   #include "StateConstructW.h"
  2.2944 +   #include "helpfun.h"
  2.2945 +   #include "constants.h"
  2.2946 +   #include "packing.h"
  2.2947 +   #include "iCBSearch.h"
  2.2948 +   #include "iCBConstruct.h"
  2.2949 +   #include "hpInput.h"
  2.2950 +   #include "anaFilter.h"
  2.2951 +   #include "syntFilter.h"
  2.2952 +
  2.2953 +   /*----------------------------------------------------------------*
  2.2954 +    *  Initiation of encoder instance.
  2.2955 +    *---------------------------------------------------------------*/
  2.2956 +
  2.2957 +   short initEncode(                   /* (o) Number of bytes
  2.2958 +                                              encoded */
  2.2959 +       iLBC_Enc_Inst_t *iLBCenc_inst,  /* (i/o) Encoder instance */
  2.2960 +       int mode                    /* (i) frame size mode */
  2.2961 +   ){
  2.2962 +       iLBCenc_inst->mode = mode;
  2.2963 +       if (mode==30) {
  2.2964 +           iLBCenc_inst->blockl = BLOCKL_30MS;
  2.2965 +           iLBCenc_inst->nsub = NSUB_30MS;
  2.2966 +           iLBCenc_inst->nasub = NASUB_30MS;
  2.2967 +           iLBCenc_inst->lpc_n = LPC_N_30MS;
  2.2968 +           iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS;
  2.2969 +           iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS;
  2.2970 +
  2.2971 +
  2.2972 +
  2.2973 +Andersen, et al.              Experimental                     [Page 53]
  2.2974 +
  2.2975 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.2976 +
  2.2977 +
  2.2978 +           iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS;
  2.2979 +           /* ULP init */
  2.2980 +           iLBCenc_inst->ULP_inst=&ULP_30msTbl;
  2.2981 +       }
  2.2982 +       else if (mode==20) {
  2.2983 +           iLBCenc_inst->blockl = BLOCKL_20MS;
  2.2984 +           iLBCenc_inst->nsub = NSUB_20MS;
  2.2985 +           iLBCenc_inst->nasub = NASUB_20MS;
  2.2986 +           iLBCenc_inst->lpc_n = LPC_N_20MS;
  2.2987 +           iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS;
  2.2988 +           iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS;
  2.2989 +           iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS;
  2.2990 +           /* ULP init */
  2.2991 +           iLBCenc_inst->ULP_inst=&ULP_20msTbl;
  2.2992 +       }
  2.2993 +       else {
  2.2994 +           exit(2);
  2.2995 +       }
  2.2996 +
  2.2997 +       memset((*iLBCenc_inst).anaMem, 0,
  2.2998 +           LPC_FILTERORDER*sizeof(float));
  2.2999 +       memcpy((*iLBCenc_inst).lsfold, lsfmeanTbl,
  2.3000 +           LPC_FILTERORDER*sizeof(float));
  2.3001 +       memcpy((*iLBCenc_inst).lsfdeqold, lsfmeanTbl,
  2.3002 +           LPC_FILTERORDER*sizeof(float));
  2.3003 +       memset((*iLBCenc_inst).lpc_buffer, 0,
  2.3004 +           (LPC_LOOKBACK+BLOCKL_MAX)*sizeof(float));
  2.3005 +       memset((*iLBCenc_inst).hpimem, 0, 4*sizeof(float));
  2.3006 +
  2.3007 +       return (iLBCenc_inst->no_of_bytes);
  2.3008 +   }
  2.3009 +
  2.3010 +   /*----------------------------------------------------------------*
  2.3011 +    *  main encoder function
  2.3012 +    *---------------------------------------------------------------*/
  2.3013 +
  2.3014 +   void iLBC_encode(
  2.3015 +       unsigned char *bytes,           /* (o) encoded data bits iLBC */
  2.3016 +       float *block,                   /* (o) speech vector to
  2.3017 +                                              encode */
  2.3018 +       iLBC_Enc_Inst_t *iLBCenc_inst   /* (i/o) the general encoder
  2.3019 +                                              state */
  2.3020 +   ){
  2.3021 +
  2.3022 +       float data[BLOCKL_MAX];
  2.3023 +       float residual[BLOCKL_MAX], reverseResidual[BLOCKL_MAX];
  2.3024 +
  2.3025 +       int start, idxForMax, idxVec[STATE_LEN];
  2.3026 +
  2.3027 +
  2.3028 +
  2.3029 +Andersen, et al.              Experimental                     [Page 54]
  2.3030 +
  2.3031 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3032 +
  2.3033 +
  2.3034 +       float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];
  2.3035 +       int n, k, meml_gotten, Nfor, Nback, i, pos;
  2.3036 +       int gain_index[CB_NSTAGES*NASUB_MAX],
  2.3037 +           extra_gain_index[CB_NSTAGES];
  2.3038 +       int cb_index[CB_NSTAGES*NASUB_MAX],extra_cb_index[CB_NSTAGES];
  2.3039 +       int lsf_i[LSF_NSPLIT*LPC_N_MAX];
  2.3040 +       unsigned char *pbytes;
  2.3041 +       int diff, start_pos, state_first;
  2.3042 +       float en1, en2;
  2.3043 +       int index, ulp, firstpart;
  2.3044 +       int subcount, subframe;
  2.3045 +       float weightState[LPC_FILTERORDER];
  2.3046 +       float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)];
  2.3047 +       float weightdenum[NSUB_MAX*(LPC_FILTERORDER+1)];
  2.3048 +       float decresidual[BLOCKL_MAX];
  2.3049 +
  2.3050 +       /* high pass filtering of input signal if such is not done
  2.3051 +              prior to calling this function */
  2.3052 +
  2.3053 +       hpInput(block, iLBCenc_inst->blockl,
  2.3054 +                   data, (*iLBCenc_inst).hpimem);
  2.3055 +
  2.3056 +       /* otherwise simply copy */
  2.3057 +
  2.3058 +       /*memcpy(data,block,iLBCenc_inst->blockl*sizeof(float));*/
  2.3059 +
  2.3060 +       /* LPC of hp filtered input data */
  2.3061 +
  2.3062 +       LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst);
  2.3063 +
  2.3064 +
  2.3065 +       /* inverse filter to get residual */
  2.3066 +
  2.3067 +       for (n=0; n<iLBCenc_inst->nsub; n++) {
  2.3068 +           anaFilter(&data[n*SUBL], &syntdenum[n*(LPC_FILTERORDER+1)],
  2.3069 +               SUBL, &residual[n*SUBL], iLBCenc_inst->anaMem);
  2.3070 +       }
  2.3071 +
  2.3072 +       /* find state location */
  2.3073 +
  2.3074 +       start = FrameClassify(iLBCenc_inst, residual);
  2.3075 +
  2.3076 +       /* check if state should be in first or last part of the
  2.3077 +       two subframes */
  2.3078 +
  2.3079 +       diff = STATE_LEN - iLBCenc_inst->state_short_len;
  2.3080 +       en1 = 0;
  2.3081 +       index = (start-1)*SUBL;
  2.3082 +
  2.3083 +
  2.3084 +
  2.3085 +Andersen, et al.              Experimental                     [Page 55]
  2.3086 +
  2.3087 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3088 +
  2.3089 +
  2.3090 +       for (i = 0; i < iLBCenc_inst->state_short_len; i++) {
  2.3091 +           en1 += residual[index+i]*residual[index+i];
  2.3092 +       }
  2.3093 +       en2 = 0;
  2.3094 +       index = (start-1)*SUBL+diff;
  2.3095 +       for (i = 0; i < iLBCenc_inst->state_short_len; i++) {
  2.3096 +           en2 += residual[index+i]*residual[index+i];
  2.3097 +       }
  2.3098 +
  2.3099 +
  2.3100 +       if (en1 > en2) {
  2.3101 +           state_first = 1;
  2.3102 +           start_pos = (start-1)*SUBL;
  2.3103 +       } else {
  2.3104 +           state_first = 0;
  2.3105 +           start_pos = (start-1)*SUBL + diff;
  2.3106 +       }
  2.3107 +
  2.3108 +       /* scalar quantization of state */
  2.3109 +
  2.3110 +       StateSearchW(iLBCenc_inst, &residual[start_pos],
  2.3111 +           &syntdenum[(start-1)*(LPC_FILTERORDER+1)],
  2.3112 +           &weightdenum[(start-1)*(LPC_FILTERORDER+1)], &idxForMax,
  2.3113 +           idxVec, iLBCenc_inst->state_short_len, state_first);
  2.3114 +
  2.3115 +       StateConstructW(idxForMax, idxVec,
  2.3116 +           &syntdenum[(start-1)*(LPC_FILTERORDER+1)],
  2.3117 +           &decresidual[start_pos], iLBCenc_inst->state_short_len);
  2.3118 +
  2.3119 +       /* predictive quantization in state */
  2.3120 +
  2.3121 +       if (state_first) { /* put adaptive part in the end */
  2.3122 +
  2.3123 +           /* setup memory */
  2.3124 +
  2.3125 +           memset(mem, 0,
  2.3126 +               (CB_MEML-iLBCenc_inst->state_short_len)*sizeof(float));
  2.3127 +           memcpy(mem+CB_MEML-iLBCenc_inst->state_short_len,
  2.3128 +               decresidual+start_pos,
  2.3129 +               iLBCenc_inst->state_short_len*sizeof(float));
  2.3130 +           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
  2.3131 +
  2.3132 +           /* encode sub-frames */
  2.3133 +
  2.3134 +           iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index,
  2.3135 +               &residual[start_pos+iLBCenc_inst->state_short_len],
  2.3136 +               mem+CB_MEML-stMemLTbl,
  2.3137 +               stMemLTbl, diff, CB_NSTAGES,
  2.3138 +
  2.3139 +
  2.3140 +
  2.3141 +Andersen, et al.              Experimental                     [Page 56]
  2.3142 +
  2.3143 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3144 +
  2.3145 +
  2.3146 +               &weightdenum[start*(LPC_FILTERORDER+1)],
  2.3147 +               weightState, 0);
  2.3148 +
  2.3149 +           /* construct decoded vector */
  2.3150 +
  2.3151 +           iCBConstruct(
  2.3152 +               &decresidual[start_pos+iLBCenc_inst->state_short_len],
  2.3153 +               extra_cb_index, extra_gain_index,
  2.3154 +               mem+CB_MEML-stMemLTbl,
  2.3155 +               stMemLTbl, diff, CB_NSTAGES);
  2.3156 +
  2.3157 +       }
  2.3158 +       else { /* put adaptive part in the beginning */
  2.3159 +
  2.3160 +           /* create reversed vectors for prediction */
  2.3161 +
  2.3162 +           for (k=0; k<diff; k++) {
  2.3163 +               reverseResidual[k] = residual[(start+1)*SUBL-1
  2.3164 +                   -(k+iLBCenc_inst->state_short_len)];
  2.3165 +           }
  2.3166 +
  2.3167 +           /* setup memory */
  2.3168 +
  2.3169 +           meml_gotten = iLBCenc_inst->state_short_len;
  2.3170 +           for (k=0; k<meml_gotten; k++) {
  2.3171 +               mem[CB_MEML-1-k] = decresidual[start_pos + k];
  2.3172 +           }
  2.3173 +           memset(mem, 0, (CB_MEML-k)*sizeof(float));
  2.3174 +           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
  2.3175 +
  2.3176 +           /* encode sub-frames */
  2.3177 +
  2.3178 +           iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index,
  2.3179 +               reverseResidual, mem+CB_MEML-stMemLTbl, stMemLTbl,
  2.3180 +               diff, CB_NSTAGES,
  2.3181 +               &weightdenum[(start-1)*(LPC_FILTERORDER+1)],
  2.3182 +               weightState, 0);
  2.3183 +
  2.3184 +           /* construct decoded vector */
  2.3185 +
  2.3186 +           iCBConstruct(reverseDecresidual, extra_cb_index,
  2.3187 +               extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl,
  2.3188 +               diff, CB_NSTAGES);
  2.3189 +
  2.3190 +           /* get decoded residual from reversed vector */
  2.3191 +
  2.3192 +           for (k=0; k<diff; k++) {
  2.3193 +               decresidual[start_pos-1-k] = reverseDecresidual[k];
  2.3194 +
  2.3195 +
  2.3196 +
  2.3197 +Andersen, et al.              Experimental                     [Page 57]
  2.3198 +
  2.3199 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3200 +
  2.3201 +
  2.3202 +           }
  2.3203 +       }
  2.3204 +
  2.3205 +       /* counter for predicted sub-frames */
  2.3206 +
  2.3207 +       subcount=0;
  2.3208 +
  2.3209 +       /* forward prediction of sub-frames */
  2.3210 +
  2.3211 +       Nfor = iLBCenc_inst->nsub-start-1;
  2.3212 +
  2.3213 +
  2.3214 +       if ( Nfor > 0 ) {
  2.3215 +
  2.3216 +           /* setup memory */
  2.3217 +
  2.3218 +           memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));
  2.3219 +           memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL,
  2.3220 +               STATE_LEN*sizeof(float));
  2.3221 +           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
  2.3222 +
  2.3223 +           /* loop over sub-frames to encode */
  2.3224 +
  2.3225 +           for (subframe=0; subframe<Nfor; subframe++) {
  2.3226 +
  2.3227 +               /* encode sub-frame */
  2.3228 +
  2.3229 +               iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES,
  2.3230 +                   gain_index+subcount*CB_NSTAGES,
  2.3231 +                   &residual[(start+1+subframe)*SUBL],
  2.3232 +                   mem+CB_MEML-memLfTbl[subcount],
  2.3233 +                   memLfTbl[subcount], SUBL, CB_NSTAGES,
  2.3234 +                   &weightdenum[(start+1+subframe)*
  2.3235 +                               (LPC_FILTERORDER+1)],
  2.3236 +                   weightState, subcount+1);
  2.3237 +
  2.3238 +               /* construct decoded vector */
  2.3239 +
  2.3240 +               iCBConstruct(&decresidual[(start+1+subframe)*SUBL],
  2.3241 +                   cb_index+subcount*CB_NSTAGES,
  2.3242 +                   gain_index+subcount*CB_NSTAGES,
  2.3243 +                   mem+CB_MEML-memLfTbl[subcount],
  2.3244 +                   memLfTbl[subcount], SUBL, CB_NSTAGES);
  2.3245 +
  2.3246 +               /* update memory */
  2.3247 +
  2.3248 +               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
  2.3249 +               memcpy(mem+CB_MEML-SUBL,
  2.3250 +
  2.3251 +
  2.3252 +
  2.3253 +Andersen, et al.              Experimental                     [Page 58]
  2.3254 +
  2.3255 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3256 +
  2.3257 +
  2.3258 +                   &decresidual[(start+1+subframe)*SUBL],
  2.3259 +                   SUBL*sizeof(float));
  2.3260 +               memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
  2.3261 +
  2.3262 +               subcount++;
  2.3263 +           }
  2.3264 +       }
  2.3265 +
  2.3266 +
  2.3267 +       /* backward prediction of sub-frames */
  2.3268 +
  2.3269 +       Nback = start-1;
  2.3270 +
  2.3271 +
  2.3272 +       if ( Nback > 0 ) {
  2.3273 +
  2.3274 +           /* create reverse order vectors */
  2.3275 +
  2.3276 +           for (n=0; n<Nback; n++) {
  2.3277 +               for (k=0; k<SUBL; k++) {
  2.3278 +                   reverseResidual[n*SUBL+k] =
  2.3279 +                       residual[(start-1)*SUBL-1-n*SUBL-k];
  2.3280 +                   reverseDecresidual[n*SUBL+k] =
  2.3281 +                       decresidual[(start-1)*SUBL-1-n*SUBL-k];
  2.3282 +               }
  2.3283 +           }
  2.3284 +
  2.3285 +           /* setup memory */
  2.3286 +
  2.3287 +           meml_gotten = SUBL*(iLBCenc_inst->nsub+1-start);
  2.3288 +
  2.3289 +
  2.3290 +           if ( meml_gotten > CB_MEML ) {
  2.3291 +               meml_gotten=CB_MEML;
  2.3292 +           }
  2.3293 +           for (k=0; k<meml_gotten; k++) {
  2.3294 +               mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];
  2.3295 +           }
  2.3296 +           memset(mem, 0, (CB_MEML-k)*sizeof(float));
  2.3297 +           memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
  2.3298 +
  2.3299 +           /* loop over sub-frames to encode */
  2.3300 +
  2.3301 +           for (subframe=0; subframe<Nback; subframe++) {
  2.3302 +
  2.3303 +               /* encode sub-frame */
  2.3304 +
  2.3305 +               iCBSearch(iLBCenc_inst, cb_index+subcount*CB_NSTAGES,
  2.3306 +
  2.3307 +
  2.3308 +
  2.3309 +Andersen, et al.              Experimental                     [Page 59]
  2.3310 +
  2.3311 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3312 +
  2.3313 +
  2.3314 +                   gain_index+subcount*CB_NSTAGES,
  2.3315 +                   &reverseResidual[subframe*SUBL],
  2.3316 +                   mem+CB_MEML-memLfTbl[subcount],
  2.3317 +                   memLfTbl[subcount], SUBL, CB_NSTAGES,
  2.3318 +                   &weightdenum[(start-2-subframe)*
  2.3319 +                               (LPC_FILTERORDER+1)],
  2.3320 +                   weightState, subcount+1);
  2.3321 +
  2.3322 +               /* construct decoded vector */
  2.3323 +
  2.3324 +               iCBConstruct(&reverseDecresidual[subframe*SUBL],
  2.3325 +                   cb_index+subcount*CB_NSTAGES,
  2.3326 +                   gain_index+subcount*CB_NSTAGES,
  2.3327 +                   mem+CB_MEML-memLfTbl[subcount],
  2.3328 +                   memLfTbl[subcount], SUBL, CB_NSTAGES);
  2.3329 +
  2.3330 +               /* update memory */
  2.3331 +
  2.3332 +               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
  2.3333 +               memcpy(mem+CB_MEML-SUBL,
  2.3334 +                   &reverseDecresidual[subframe*SUBL],
  2.3335 +                   SUBL*sizeof(float));
  2.3336 +               memset(weightState, 0, LPC_FILTERORDER*sizeof(float));
  2.3337 +
  2.3338 +               subcount++;
  2.3339 +
  2.3340 +           }
  2.3341 +
  2.3342 +           /* get decoded residual from reversed vector */
  2.3343 +
  2.3344 +           for (i=0; i<SUBL*Nback; i++) {
  2.3345 +               decresidual[SUBL*Nback - i - 1] =
  2.3346 +                   reverseDecresidual[i];
  2.3347 +           }
  2.3348 +       }
  2.3349 +       /* end encoding part */
  2.3350 +
  2.3351 +       /* adjust index */
  2.3352 +       index_conv_enc(cb_index);
  2.3353 +
  2.3354 +       /* pack bytes */
  2.3355 +
  2.3356 +       pbytes=bytes;
  2.3357 +       pos=0;
  2.3358 +
  2.3359 +       /* loop over the 3 ULP classes */
  2.3360 +
  2.3361 +       for (ulp=0; ulp<3; ulp++) {
  2.3362 +
  2.3363 +
  2.3364 +
  2.3365 +Andersen, et al.              Experimental                     [Page 60]
  2.3366 +
  2.3367 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3368 +
  2.3369 +
  2.3370 +
  2.3371 +           /* LSF */
  2.3372 +           for (k=0; k<LSF_NSPLIT*iLBCenc_inst->lpc_n; k++) {
  2.3373 +               packsplit(&lsf_i[k], &firstpart, &lsf_i[k],
  2.3374 +                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp],
  2.3375 +                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp]+
  2.3376 +                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+1]+
  2.3377 +                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp+2]);
  2.3378 +               dopack( &pbytes, firstpart,
  2.3379 +                   iLBCenc_inst->ULP_inst->lsf_bits[k][ulp], &pos);
  2.3380 +           }
  2.3381 +
  2.3382 +           /* Start block info */
  2.3383 +
  2.3384 +           packsplit(&start, &firstpart, &start,
  2.3385 +               iLBCenc_inst->ULP_inst->start_bits[ulp],
  2.3386 +               iLBCenc_inst->ULP_inst->start_bits[ulp]+
  2.3387 +               iLBCenc_inst->ULP_inst->start_bits[ulp+1]+
  2.3388 +               iLBCenc_inst->ULP_inst->start_bits[ulp+2]);
  2.3389 +           dopack( &pbytes, firstpart,
  2.3390 +               iLBCenc_inst->ULP_inst->start_bits[ulp], &pos);
  2.3391 +
  2.3392 +           packsplit(&state_first, &firstpart, &state_first,
  2.3393 +               iLBCenc_inst->ULP_inst->startfirst_bits[ulp],
  2.3394 +               iLBCenc_inst->ULP_inst->startfirst_bits[ulp]+
  2.3395 +               iLBCenc_inst->ULP_inst->startfirst_bits[ulp+1]+
  2.3396 +               iLBCenc_inst->ULP_inst->startfirst_bits[ulp+2]);
  2.3397 +           dopack( &pbytes, firstpart,
  2.3398 +               iLBCenc_inst->ULP_inst->startfirst_bits[ulp], &pos);
  2.3399 +
  2.3400 +           packsplit(&idxForMax, &firstpart, &idxForMax,
  2.3401 +               iLBCenc_inst->ULP_inst->scale_bits[ulp],
  2.3402 +               iLBCenc_inst->ULP_inst->scale_bits[ulp]+
  2.3403 +               iLBCenc_inst->ULP_inst->scale_bits[ulp+1]+
  2.3404 +               iLBCenc_inst->ULP_inst->scale_bits[ulp+2]);
  2.3405 +           dopack( &pbytes, firstpart,
  2.3406 +               iLBCenc_inst->ULP_inst->scale_bits[ulp], &pos);
  2.3407 +
  2.3408 +           for (k=0; k<iLBCenc_inst->state_short_len; k++) {
  2.3409 +               packsplit(idxVec+k, &firstpart, idxVec+k,
  2.3410 +                   iLBCenc_inst->ULP_inst->state_bits[ulp],
  2.3411 +                   iLBCenc_inst->ULP_inst->state_bits[ulp]+
  2.3412 +                   iLBCenc_inst->ULP_inst->state_bits[ulp+1]+
  2.3413 +                   iLBCenc_inst->ULP_inst->state_bits[ulp+2]);
  2.3414 +               dopack( &pbytes, firstpart,
  2.3415 +                   iLBCenc_inst->ULP_inst->state_bits[ulp], &pos);
  2.3416 +           }
  2.3417 +
  2.3418 +
  2.3419 +
  2.3420 +
  2.3421 +Andersen, et al.              Experimental                     [Page 61]
  2.3422 +
  2.3423 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3424 +
  2.3425 +
  2.3426 +           /* 23/22 (20ms/30ms) sample block */
  2.3427 +
  2.3428 +           for (k=0;k<CB_NSTAGES;k++) {
  2.3429 +               packsplit(extra_cb_index+k, &firstpart,
  2.3430 +                   extra_cb_index+k,
  2.3431 +                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp],
  2.3432 +                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp]+
  2.3433 +                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+1]+
  2.3434 +                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp+2]);
  2.3435 +               dopack( &pbytes, firstpart,
  2.3436 +                   iLBCenc_inst->ULP_inst->extra_cb_index[k][ulp],
  2.3437 +                   &pos);
  2.3438 +           }
  2.3439 +
  2.3440 +           for (k=0;k<CB_NSTAGES;k++) {
  2.3441 +               packsplit(extra_gain_index+k, &firstpart,
  2.3442 +                   extra_gain_index+k,
  2.3443 +                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp],
  2.3444 +                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp]+
  2.3445 +                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+1]+
  2.3446 +                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp+2]);
  2.3447 +               dopack( &pbytes, firstpart,
  2.3448 +                   iLBCenc_inst->ULP_inst->extra_cb_gain[k][ulp],
  2.3449 +                   &pos);
  2.3450 +           }
  2.3451 +
  2.3452 +           /* The two/four (20ms/30ms) 40 sample sub-blocks */
  2.3453 +
  2.3454 +           for (i=0; i<iLBCenc_inst->nasub; i++) {
  2.3455 +               for (k=0; k<CB_NSTAGES; k++) {
  2.3456 +                   packsplit(cb_index+i*CB_NSTAGES+k, &firstpart,
  2.3457 +                       cb_index+i*CB_NSTAGES+k,
  2.3458 +                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp],
  2.3459 +                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp]+
  2.3460 +                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+1]+
  2.3461 +                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp+2]);
  2.3462 +                   dopack( &pbytes, firstpart,
  2.3463 +                       iLBCenc_inst->ULP_inst->cb_index[i][k][ulp],
  2.3464 +                       &pos);
  2.3465 +               }
  2.3466 +           }
  2.3467 +
  2.3468 +           for (i=0; i<iLBCenc_inst->nasub; i++) {
  2.3469 +               for (k=0; k<CB_NSTAGES; k++) {
  2.3470 +                   packsplit(gain_index+i*CB_NSTAGES+k, &firstpart,
  2.3471 +                       gain_index+i*CB_NSTAGES+k,
  2.3472 +                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp],
  2.3473 +                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp]+
  2.3474 +
  2.3475 +
  2.3476 +
  2.3477 +Andersen, et al.              Experimental                     [Page 62]
  2.3478 +
  2.3479 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3480 +
  2.3481 +
  2.3482 +                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+1]+
  2.3483 +                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp+2]);
  2.3484 +                   dopack( &pbytes, firstpart,
  2.3485 +                       iLBCenc_inst->ULP_inst->cb_gain[i][k][ulp],
  2.3486 +                       &pos);
  2.3487 +               }
  2.3488 +           }
  2.3489 +       }
  2.3490 +
  2.3491 +       /* set the last bit to zero (otherwise the decoder
  2.3492 +          will treat it as a lost frame) */
  2.3493 +       dopack( &pbytes, 0, 1, &pos);
  2.3494 +   }
  2.3495 +
  2.3496 +A.4.  iLBC_decode.h
  2.3497 +
  2.3498 +   /******************************************************************
  2.3499 +
  2.3500 +       iLBC Speech Coder ANSI-C Source Code
  2.3501 +
  2.3502 +       iLBC_decode.h
  2.3503 +
  2.3504 +       Copyright (C) The Internet Society (2004).
  2.3505 +       All Rights Reserved.
  2.3506 +
  2.3507 +   ******************************************************************/
  2.3508 +
  2.3509 +   #ifndef __iLBC_ILBCDECODE_H
  2.3510 +   #define __iLBC_ILBCDECODE_H
  2.3511 +
  2.3512 +   #include "iLBC_define.h"
  2.3513 +
  2.3514 +   short initDecode(                   /* (o) Number of decoded
  2.3515 +                                              samples */
  2.3516 +       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */
  2.3517 +       int mode,                       /* (i) frame size mode */
  2.3518 +       int use_enhancer                /* (i) 1 to use enhancer
  2.3519 +                                              0 to run without
  2.3520 +                                                enhancer */
  2.3521 +   );
  2.3522 +
  2.3523 +   void iLBC_decode(
  2.3524 +       float *decblock,            /* (o) decoded signal block */
  2.3525 +       unsigned char *bytes,           /* (i) encoded signal bits */
  2.3526 +       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state
  2.3527 +                                                structure */
  2.3528 +       int mode                    /* (i) 0: bad packet, PLC,
  2.3529 +                                              1: normal */
  2.3530 +
  2.3531 +
  2.3532 +
  2.3533 +Andersen, et al.              Experimental                     [Page 63]
  2.3534 +
  2.3535 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3536 +
  2.3537 +
  2.3538 +   );
  2.3539 +
  2.3540 +   #endif
  2.3541 +
  2.3542 +A.5.  iLBC_decode.c
  2.3543 +
  2.3544 +   /******************************************************************
  2.3545 +
  2.3546 +       iLBC Speech Coder ANSI-C Source Code
  2.3547 +
  2.3548 +       iLBC_decode.c
  2.3549 +
  2.3550 +       Copyright (C) The Internet Society (2004).
  2.3551 +       All Rights Reserved.
  2.3552 +
  2.3553 +   ******************************************************************/
  2.3554 +
  2.3555 +   #include <math.h>
  2.3556 +   #include <stdlib.h>
  2.3557 +
  2.3558 +   #include "iLBC_define.h"
  2.3559 +   #include "StateConstructW.h"
  2.3560 +   #include "LPCdecode.h"
  2.3561 +   #include "iCBConstruct.h"
  2.3562 +   #include "doCPLC.h"
  2.3563 +   #include "helpfun.h"
  2.3564 +   #include "constants.h"
  2.3565 +   #include "packing.h"
  2.3566 +   #include "string.h"
  2.3567 +   #include "enhancer.h"
  2.3568 +   #include "hpOutput.h"
  2.3569 +   #include "syntFilter.h"
  2.3570 +
  2.3571 +   /*----------------------------------------------------------------*
  2.3572 +    *  Initiation of decoder instance.
  2.3573 +    *---------------------------------------------------------------*/
  2.3574 +
  2.3575 +   short initDecode(                   /* (o) Number of decoded
  2.3576 +                                              samples */
  2.3577 +       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */
  2.3578 +       int mode,                       /* (i) frame size mode */
  2.3579 +       int use_enhancer                /* (i) 1 to use enhancer
  2.3580 +                                              0 to run without
  2.3581 +                                                enhancer */
  2.3582 +   ){
  2.3583 +       int i;
  2.3584 +
  2.3585 +       iLBCdec_inst->mode = mode;
  2.3586 +
  2.3587 +
  2.3588 +
  2.3589 +Andersen, et al.              Experimental                     [Page 64]
  2.3590 +
  2.3591 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3592 +
  2.3593 +
  2.3594 +       if (mode==30) {
  2.3595 +           iLBCdec_inst->blockl = BLOCKL_30MS;
  2.3596 +           iLBCdec_inst->nsub = NSUB_30MS;
  2.3597 +           iLBCdec_inst->nasub = NASUB_30MS;
  2.3598 +           iLBCdec_inst->lpc_n = LPC_N_30MS;
  2.3599 +           iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS;
  2.3600 +           iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS;
  2.3601 +           iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS;
  2.3602 +           /* ULP init */
  2.3603 +           iLBCdec_inst->ULP_inst=&ULP_30msTbl;
  2.3604 +       }
  2.3605 +       else if (mode==20) {
  2.3606 +           iLBCdec_inst->blockl = BLOCKL_20MS;
  2.3607 +           iLBCdec_inst->nsub = NSUB_20MS;
  2.3608 +           iLBCdec_inst->nasub = NASUB_20MS;
  2.3609 +           iLBCdec_inst->lpc_n = LPC_N_20MS;
  2.3610 +           iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS;
  2.3611 +           iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS;
  2.3612 +           iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS;
  2.3613 +           /* ULP init */
  2.3614 +           iLBCdec_inst->ULP_inst=&ULP_20msTbl;
  2.3615 +       }
  2.3616 +       else {
  2.3617 +           exit(2);
  2.3618 +       }
  2.3619 +
  2.3620 +       memset(iLBCdec_inst->syntMem, 0,
  2.3621 +           LPC_FILTERORDER*sizeof(float));
  2.3622 +       memcpy((*iLBCdec_inst).lsfdeqold, lsfmeanTbl,
  2.3623 +           LPC_FILTERORDER*sizeof(float));
  2.3624 +
  2.3625 +       memset(iLBCdec_inst->old_syntdenum, 0,
  2.3626 +           ((LPC_FILTERORDER + 1)*NSUB_MAX)*sizeof(float));
  2.3627 +       for (i=0; i<NSUB_MAX; i++)
  2.3628 +           iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)]=1.0;
  2.3629 +
  2.3630 +       iLBCdec_inst->last_lag = 20;
  2.3631 +
  2.3632 +       iLBCdec_inst->prevLag = 120;
  2.3633 +       iLBCdec_inst->per = 0.0;
  2.3634 +       iLBCdec_inst->consPLICount = 0;
  2.3635 +       iLBCdec_inst->prevPLI = 0;
  2.3636 +       iLBCdec_inst->prevLpc[0] = 1.0;
  2.3637 +       memset(iLBCdec_inst->prevLpc+1,0,
  2.3638 +           LPC_FILTERORDER*sizeof(float));
  2.3639 +       memset(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX*sizeof(float));
  2.3640 +       iLBCdec_inst->seed=777;
  2.3641 +
  2.3642 +
  2.3643 +
  2.3644 +
  2.3645 +Andersen, et al.              Experimental                     [Page 65]
  2.3646 +
  2.3647 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3648 +
  2.3649 +
  2.3650 +       memset(iLBCdec_inst->hpomem, 0, 4*sizeof(float));
  2.3651 +
  2.3652 +       iLBCdec_inst->use_enhancer = use_enhancer;
  2.3653 +       memset(iLBCdec_inst->enh_buf, 0, ENH_BUFL*sizeof(float));
  2.3654 +       for (i=0;i<ENH_NBLOCKS_TOT;i++)
  2.3655 +           iLBCdec_inst->enh_period[i]=(float)40.0;
  2.3656 +
  2.3657 +       iLBCdec_inst->prev_enh_pl = 0;
  2.3658 +
  2.3659 +       return (iLBCdec_inst->blockl);
  2.3660 +   }
  2.3661 +
  2.3662 +   /*----------------------------------------------------------------*
  2.3663 +    *  frame residual decoder function (subrutine to iLBC_decode)
  2.3664 +    *---------------------------------------------------------------*/
  2.3665 +
  2.3666 +   void Decode(
  2.3667 +       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state
  2.3668 +                                                structure */
  2.3669 +       float *decresidual,             /* (o) decoded residual frame */
  2.3670 +       int start,                      /* (i) location of start
  2.3671 +                                              state */
  2.3672 +       int idxForMax,                  /* (i) codebook index for the
  2.3673 +                                              maximum value */
  2.3674 +       int *idxVec,                /* (i) codebook indexes for the
  2.3675 +                                              samples  in the start
  2.3676 +                                              state */
  2.3677 +       float *syntdenum,               /* (i) the decoded synthesis
  2.3678 +                                              filter coefficients */
  2.3679 +       int *cb_index,                  /* (i) the indexes for the
  2.3680 +                                              adaptive codebook */
  2.3681 +       int *gain_index,            /* (i) the indexes for the
  2.3682 +                                              corresponding gains */
  2.3683 +       int *extra_cb_index,        /* (i) the indexes for the
  2.3684 +                                              adaptive codebook part
  2.3685 +                                              of start state */
  2.3686 +       int *extra_gain_index,          /* (i) the indexes for the
  2.3687 +                                              corresponding gains */
  2.3688 +       int state_first                 /* (i) 1 if non adaptive part
  2.3689 +                                              of start state comes
  2.3690 +                                              first 0 if that part
  2.3691 +                                              comes last */
  2.3692 +   ){
  2.3693 +       float reverseDecresidual[BLOCKL_MAX], mem[CB_MEML];
  2.3694 +       int k, meml_gotten, Nfor, Nback, i;
  2.3695 +       int diff, start_pos;
  2.3696 +       int subcount, subframe;
  2.3697 +
  2.3698 +
  2.3699 +
  2.3700 +
  2.3701 +Andersen, et al.              Experimental                     [Page 66]
  2.3702 +
  2.3703 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3704 +
  2.3705 +
  2.3706 +       diff = STATE_LEN - iLBCdec_inst->state_short_len;
  2.3707 +
  2.3708 +       if (state_first == 1) {
  2.3709 +           start_pos = (start-1)*SUBL;
  2.3710 +       } else {
  2.3711 +           start_pos = (start-1)*SUBL + diff;
  2.3712 +       }
  2.3713 +
  2.3714 +       /* decode scalar part of start state */
  2.3715 +
  2.3716 +       StateConstructW(idxForMax, idxVec,
  2.3717 +           &syntdenum[(start-1)*(LPC_FILTERORDER+1)],
  2.3718 +           &decresidual[start_pos], iLBCdec_inst->state_short_len);
  2.3719 +
  2.3720 +
  2.3721 +       if (state_first) { /* put adaptive part in the end */
  2.3722 +
  2.3723 +           /* setup memory */
  2.3724 +
  2.3725 +           memset(mem, 0,
  2.3726 +               (CB_MEML-iLBCdec_inst->state_short_len)*sizeof(float));
  2.3727 +           memcpy(mem+CB_MEML-iLBCdec_inst->state_short_len,
  2.3728 +               decresidual+start_pos,
  2.3729 +               iLBCdec_inst->state_short_len*sizeof(float));
  2.3730 +
  2.3731 +           /* construct decoded vector */
  2.3732 +
  2.3733 +           iCBConstruct(
  2.3734 +               &decresidual[start_pos+iLBCdec_inst->state_short_len],
  2.3735 +               extra_cb_index, extra_gain_index, mem+CB_MEML-stMemLTbl,
  2.3736 +               stMemLTbl, diff, CB_NSTAGES);
  2.3737 +
  2.3738 +       }
  2.3739 +       else {/* put adaptive part in the beginning */
  2.3740 +
  2.3741 +           /* create reversed vectors for prediction */
  2.3742 +
  2.3743 +           for (k=0; k<diff; k++) {
  2.3744 +               reverseDecresidual[k] =
  2.3745 +                   decresidual[(start+1)*SUBL-1-
  2.3746 +                           (k+iLBCdec_inst->state_short_len)];
  2.3747 +           }
  2.3748 +
  2.3749 +           /* setup memory */
  2.3750 +
  2.3751 +           meml_gotten = iLBCdec_inst->state_short_len;
  2.3752 +           for (k=0; k<meml_gotten; k++){
  2.3753 +               mem[CB_MEML-1-k] = decresidual[start_pos + k];
  2.3754 +
  2.3755 +
  2.3756 +
  2.3757 +Andersen, et al.              Experimental                     [Page 67]
  2.3758 +
  2.3759 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3760 +
  2.3761 +
  2.3762 +           }
  2.3763 +           memset(mem, 0, (CB_MEML-k)*sizeof(float));
  2.3764 +
  2.3765 +           /* construct decoded vector */
  2.3766 +
  2.3767 +           iCBConstruct(reverseDecresidual, extra_cb_index,
  2.3768 +               extra_gain_index, mem+CB_MEML-stMemLTbl, stMemLTbl,
  2.3769 +               diff, CB_NSTAGES);
  2.3770 +
  2.3771 +           /* get decoded residual from reversed vector */
  2.3772 +
  2.3773 +           for (k=0; k<diff; k++) {
  2.3774 +               decresidual[start_pos-1-k] = reverseDecresidual[k];
  2.3775 +           }
  2.3776 +       }
  2.3777 +
  2.3778 +       /* counter for predicted sub-frames */
  2.3779 +
  2.3780 +       subcount=0;
  2.3781 +
  2.3782 +       /* forward prediction of sub-frames */
  2.3783 +
  2.3784 +       Nfor = iLBCdec_inst->nsub-start-1;
  2.3785 +
  2.3786 +       if ( Nfor > 0 ){
  2.3787 +
  2.3788 +           /* setup memory */
  2.3789 +
  2.3790 +           memset(mem, 0, (CB_MEML-STATE_LEN)*sizeof(float));
  2.3791 +           memcpy(mem+CB_MEML-STATE_LEN, decresidual+(start-1)*SUBL,
  2.3792 +               STATE_LEN*sizeof(float));
  2.3793 +
  2.3794 +           /* loop over sub-frames to encode */
  2.3795 +
  2.3796 +           for (subframe=0; subframe<Nfor; subframe++) {
  2.3797 +
  2.3798 +               /* construct decoded vector */
  2.3799 +
  2.3800 +               iCBConstruct(&decresidual[(start+1+subframe)*SUBL],
  2.3801 +                   cb_index+subcount*CB_NSTAGES,
  2.3802 +                   gain_index+subcount*CB_NSTAGES,
  2.3803 +                   mem+CB_MEML-memLfTbl[subcount],
  2.3804 +                   memLfTbl[subcount], SUBL, CB_NSTAGES);
  2.3805 +
  2.3806 +               /* update memory */
  2.3807 +
  2.3808 +               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
  2.3809 +               memcpy(mem+CB_MEML-SUBL,
  2.3810 +
  2.3811 +
  2.3812 +
  2.3813 +Andersen, et al.              Experimental                     [Page 68]
  2.3814 +
  2.3815 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3816 +
  2.3817 +
  2.3818 +                   &decresidual[(start+1+subframe)*SUBL],
  2.3819 +                   SUBL*sizeof(float));
  2.3820 +
  2.3821 +               subcount++;
  2.3822 +
  2.3823 +           }
  2.3824 +
  2.3825 +       }
  2.3826 +
  2.3827 +       /* backward prediction of sub-frames */
  2.3828 +
  2.3829 +       Nback = start-1;
  2.3830 +
  2.3831 +       if ( Nback > 0 ) {
  2.3832 +
  2.3833 +           /* setup memory */
  2.3834 +
  2.3835 +           meml_gotten = SUBL*(iLBCdec_inst->nsub+1-start);
  2.3836 +
  2.3837 +           if ( meml_gotten > CB_MEML ) {
  2.3838 +               meml_gotten=CB_MEML;
  2.3839 +           }
  2.3840 +           for (k=0; k<meml_gotten; k++) {
  2.3841 +               mem[CB_MEML-1-k] = decresidual[(start-1)*SUBL + k];
  2.3842 +           }
  2.3843 +           memset(mem, 0, (CB_MEML-k)*sizeof(float));
  2.3844 +
  2.3845 +           /* loop over subframes to decode */
  2.3846 +
  2.3847 +           for (subframe=0; subframe<Nback; subframe++) {
  2.3848 +
  2.3849 +               /* construct decoded vector */
  2.3850 +
  2.3851 +               iCBConstruct(&reverseDecresidual[subframe*SUBL],
  2.3852 +                   cb_index+subcount*CB_NSTAGES,
  2.3853 +                   gain_index+subcount*CB_NSTAGES,
  2.3854 +                   mem+CB_MEML-memLfTbl[subcount], memLfTbl[subcount],
  2.3855 +                   SUBL, CB_NSTAGES);
  2.3856 +
  2.3857 +               /* update memory */
  2.3858 +
  2.3859 +               memcpy(mem, mem+SUBL, (CB_MEML-SUBL)*sizeof(float));
  2.3860 +               memcpy(mem+CB_MEML-SUBL,
  2.3861 +                   &reverseDecresidual[subframe*SUBL],
  2.3862 +                   SUBL*sizeof(float));
  2.3863 +
  2.3864 +               subcount++;
  2.3865 +           }
  2.3866 +
  2.3867 +
  2.3868 +
  2.3869 +Andersen, et al.              Experimental                     [Page 69]
  2.3870 +
  2.3871 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3872 +
  2.3873 +
  2.3874 +           /* get decoded residual from reversed vector */
  2.3875 +
  2.3876 +           for (i=0; i<SUBL*Nback; i++)
  2.3877 +               decresidual[SUBL*Nback - i - 1] =
  2.3878 +               reverseDecresidual[i];
  2.3879 +       }
  2.3880 +   }
  2.3881 +
  2.3882 +   /*----------------------------------------------------------------*
  2.3883 +    *  main decoder function
  2.3884 +    *---------------------------------------------------------------*/
  2.3885 +
  2.3886 +   void iLBC_decode(
  2.3887 +       float *decblock,            /* (o) decoded signal block */
  2.3888 +       unsigned char *bytes,           /* (i) encoded signal bits */
  2.3889 +       iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) the decoder state
  2.3890 +                                                structure */
  2.3891 +       int mode                    /* (i) 0: bad packet, PLC,
  2.3892 +                                              1: normal */
  2.3893 +   ){
  2.3894 +       float data[BLOCKL_MAX];
  2.3895 +       float lsfdeq[LPC_FILTERORDER*LPC_N_MAX];
  2.3896 +       float PLCresidual[BLOCKL_MAX], PLClpc[LPC_FILTERORDER + 1];
  2.3897 +       float zeros[BLOCKL_MAX], one[LPC_FILTERORDER + 1];
  2.3898 +       int k, i, start, idxForMax, pos, lastpart, ulp;
  2.3899 +       int lag, ilag;
  2.3900 +       float cc, maxcc;
  2.3901 +       int idxVec[STATE_LEN];
  2.3902 +       int check;
  2.3903 +       int gain_index[NASUB_MAX*CB_NSTAGES],
  2.3904 +           extra_gain_index[CB_NSTAGES];
  2.3905 +       int cb_index[CB_NSTAGES*NASUB_MAX], extra_cb_index[CB_NSTAGES];
  2.3906 +       int lsf_i[LSF_NSPLIT*LPC_N_MAX];
  2.3907 +       int state_first;
  2.3908 +       int last_bit;
  2.3909 +       unsigned char *pbytes;
  2.3910 +       float weightdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];
  2.3911 +       int order_plus_one;
  2.3912 +       float syntdenum[NSUB_MAX*(LPC_FILTERORDER+1)];
  2.3913 +       float decresidual[BLOCKL_MAX];
  2.3914 +
  2.3915 +       if (mode>0) { /* the data are good */
  2.3916 +
  2.3917 +           /* decode data */
  2.3918 +
  2.3919 +           pbytes=bytes;
  2.3920 +           pos=0;
  2.3921 +
  2.3922 +
  2.3923 +
  2.3924 +
  2.3925 +Andersen, et al.              Experimental                     [Page 70]
  2.3926 +
  2.3927 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3928 +
  2.3929 +
  2.3930 +           /* Set everything to zero before decoding */
  2.3931 +
  2.3932 +           for (k=0; k<LSF_NSPLIT*LPC_N_MAX; k++) {
  2.3933 +               lsf_i[k]=0;
  2.3934 +           }
  2.3935 +           start=0;
  2.3936 +           state_first=0;
  2.3937 +           idxForMax=0;
  2.3938 +           for (k=0; k<iLBCdec_inst->state_short_len; k++) {
  2.3939 +               idxVec[k]=0;
  2.3940 +           }
  2.3941 +           for (k=0; k<CB_NSTAGES; k++) {
  2.3942 +               extra_cb_index[k]=0;
  2.3943 +           }
  2.3944 +           for (k=0; k<CB_NSTAGES; k++) {
  2.3945 +               extra_gain_index[k]=0;
  2.3946 +           }
  2.3947 +           for (i=0; i<iLBCdec_inst->nasub; i++) {
  2.3948 +               for (k=0; k<CB_NSTAGES; k++) {
  2.3949 +                   cb_index[i*CB_NSTAGES+k]=0;
  2.3950 +               }
  2.3951 +           }
  2.3952 +           for (i=0; i<iLBCdec_inst->nasub; i++) {
  2.3953 +               for (k=0; k<CB_NSTAGES; k++) {
  2.3954 +                   gain_index[i*CB_NSTAGES+k]=0;
  2.3955 +               }
  2.3956 +           }
  2.3957 +
  2.3958 +           /* loop over ULP classes */
  2.3959 +
  2.3960 +           for (ulp=0; ulp<3; ulp++) {
  2.3961 +
  2.3962 +               /* LSF */
  2.3963 +               for (k=0; k<LSF_NSPLIT*iLBCdec_inst->lpc_n; k++){
  2.3964 +                   unpack( &pbytes, &lastpart,
  2.3965 +                       iLBCdec_inst->ULP_inst->lsf_bits[k][ulp], &pos);
  2.3966 +                   packcombine(&lsf_i[k], lastpart,
  2.3967 +                       iLBCdec_inst->ULP_inst->lsf_bits[k][ulp]);
  2.3968 +               }
  2.3969 +
  2.3970 +               /* Start block info */
  2.3971 +
  2.3972 +               unpack( &pbytes, &lastpart,
  2.3973 +                   iLBCdec_inst->ULP_inst->start_bits[ulp], &pos);
  2.3974 +               packcombine(&start, lastpart,
  2.3975 +                   iLBCdec_inst->ULP_inst->start_bits[ulp]);
  2.3976 +
  2.3977 +               unpack( &pbytes, &lastpart,
  2.3978 +
  2.3979 +
  2.3980 +
  2.3981 +Andersen, et al.              Experimental                     [Page 71]
  2.3982 +
  2.3983 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.3984 +
  2.3985 +
  2.3986 +                   iLBCdec_inst->ULP_inst->startfirst_bits[ulp], &pos);
  2.3987 +               packcombine(&state_first, lastpart,
  2.3988 +                   iLBCdec_inst->ULP_inst->startfirst_bits[ulp]);
  2.3989 +
  2.3990 +               unpack( &pbytes, &lastpart,
  2.3991 +                   iLBCdec_inst->ULP_inst->scale_bits[ulp], &pos);
  2.3992 +               packcombine(&idxForMax, lastpart,
  2.3993 +                   iLBCdec_inst->ULP_inst->scale_bits[ulp]);
  2.3994 +
  2.3995 +               for (k=0; k<iLBCdec_inst->state_short_len; k++) {
  2.3996 +                   unpack( &pbytes, &lastpart,
  2.3997 +                       iLBCdec_inst->ULP_inst->state_bits[ulp], &pos);
  2.3998 +                   packcombine(idxVec+k, lastpart,
  2.3999 +                       iLBCdec_inst->ULP_inst->state_bits[ulp]);
  2.4000 +               }
  2.4001 +
  2.4002 +               /* 23/22 (20ms/30ms) sample block */
  2.4003 +
  2.4004 +               for (k=0; k<CB_NSTAGES; k++) {
  2.4005 +                   unpack( &pbytes, &lastpart,
  2.4006 +                       iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp],
  2.4007 +                       &pos);
  2.4008 +                   packcombine(extra_cb_index+k, lastpart,
  2.4009 +                       iLBCdec_inst->ULP_inst->extra_cb_index[k][ulp]);
  2.4010 +               }
  2.4011 +               for (k=0; k<CB_NSTAGES; k++) {
  2.4012 +                   unpack( &pbytes, &lastpart,
  2.4013 +                       iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp],
  2.4014 +                       &pos);
  2.4015 +                   packcombine(extra_gain_index+k, lastpart,
  2.4016 +                       iLBCdec_inst->ULP_inst->extra_cb_gain[k][ulp]);
  2.4017 +               }
  2.4018 +
  2.4019 +               /* The two/four (20ms/30ms) 40 sample sub-blocks */
  2.4020 +
  2.4021 +               for (i=0; i<iLBCdec_inst->nasub; i++) {
  2.4022 +                   for (k=0; k<CB_NSTAGES; k++) {
  2.4023 +                       unpack( &pbytes, &lastpart,
  2.4024 +                       iLBCdec_inst->ULP_inst->cb_index[i][k][ulp],
  2.4025 +                           &pos);
  2.4026 +                       packcombine(cb_index+i*CB_NSTAGES+k, lastpart,
  2.4027 +                       iLBCdec_inst->ULP_inst->cb_index[i][k][ulp]);
  2.4028 +                   }
  2.4029 +               }
  2.4030 +
  2.4031 +               for (i=0; i<iLBCdec_inst->nasub; i++) {
  2.4032 +                   for (k=0; k<CB_NSTAGES; k++) {
  2.4033 +                       unpack( &pbytes, &lastpart,
  2.4034 +
  2.4035 +
  2.4036 +
  2.4037 +Andersen, et al.              Experimental                     [Page 72]
  2.4038 +
  2.4039 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4040 +
  2.4041 +
  2.4042 +                       iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp],
  2.4043 +                           &pos);
  2.4044 +                       packcombine(gain_index+i*CB_NSTAGES+k, lastpart,
  2.4045 +                           iLBCdec_inst->ULP_inst->cb_gain[i][k][ulp]);
  2.4046 +                   }
  2.4047 +               }
  2.4048 +           }
  2.4049 +           /* Extract last bit. If it is 1 this indicates an
  2.4050 +              empty/lost frame */
  2.4051 +           unpack( &pbytes, &last_bit, 1, &pos);
  2.4052 +
  2.4053 +           /* Check for bit errors or empty/lost frames */
  2.4054 +           if (start<1)
  2.4055 +               mode = 0;
  2.4056 +           if (iLBCdec_inst->mode==20 && start>3)
  2.4057 +               mode = 0;
  2.4058 +           if (iLBCdec_inst->mode==30 && start>5)
  2.4059 +               mode = 0;
  2.4060 +           if (last_bit==1)
  2.4061 +               mode = 0;
  2.4062 +
  2.4063 +           if (mode==1) { /* No bit errors was detected,
  2.4064 +                             continue decoding */
  2.4065 +
  2.4066 +               /* adjust index */
  2.4067 +               index_conv_dec(cb_index);
  2.4068 +
  2.4069 +               /* decode the lsf */
  2.4070 +
  2.4071 +               SimplelsfDEQ(lsfdeq, lsf_i, iLBCdec_inst->lpc_n);
  2.4072 +               check=LSF_check(lsfdeq, LPC_FILTERORDER,
  2.4073 +                   iLBCdec_inst->lpc_n);
  2.4074 +               DecoderInterpolateLSF(syntdenum, weightdenum,
  2.4075 +                   lsfdeq, LPC_FILTERORDER, iLBCdec_inst);
  2.4076 +
  2.4077 +               Decode(iLBCdec_inst, decresidual, start, idxForMax,
  2.4078 +                   idxVec, syntdenum, cb_index, gain_index,
  2.4079 +                   extra_cb_index, extra_gain_index,
  2.4080 +                   state_first);
  2.4081 +
  2.4082 +               /* preparing the plc for a future loss! */
  2.4083 +
  2.4084 +               doThePLC(PLCresidual, PLClpc, 0, decresidual,
  2.4085 +                   syntdenum +
  2.4086 +                   (LPC_FILTERORDER + 1)*(iLBCdec_inst->nsub - 1),
  2.4087 +                   (*iLBCdec_inst).last_lag, iLBCdec_inst);
  2.4088 +
  2.4089 +
  2.4090 +
  2.4091 +
  2.4092 +
  2.4093 +Andersen, et al.              Experimental                     [Page 73]
  2.4094 +
  2.4095 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4096 +
  2.4097 +
  2.4098 +               memcpy(decresidual, PLCresidual,
  2.4099 +                   iLBCdec_inst->blockl*sizeof(float));
  2.4100 +           }
  2.4101 +
  2.4102 +       }
  2.4103 +
  2.4104 +       if (mode == 0) {
  2.4105 +           /* the data is bad (either a PLC call
  2.4106 +            * was made or a severe bit error was detected)
  2.4107 +            */
  2.4108 +
  2.4109 +           /* packet loss conceal */
  2.4110 +
  2.4111 +           memset(zeros, 0, BLOCKL_MAX*sizeof(float));
  2.4112 +
  2.4113 +           one[0] = 1;
  2.4114 +           memset(one+1, 0, LPC_FILTERORDER*sizeof(float));
  2.4115 +
  2.4116 +           start=0;
  2.4117 +
  2.4118 +           doThePLC(PLCresidual, PLClpc, 1, zeros, one,
  2.4119 +               (*iLBCdec_inst).last_lag, iLBCdec_inst);
  2.4120 +           memcpy(decresidual, PLCresidual,
  2.4121 +               iLBCdec_inst->blockl*sizeof(float));
  2.4122 +
  2.4123 +           order_plus_one = LPC_FILTERORDER + 1;
  2.4124 +           for (i = 0; i < iLBCdec_inst->nsub; i++) {
  2.4125 +               memcpy(syntdenum+(i*order_plus_one), PLClpc,
  2.4126 +                   order_plus_one*sizeof(float));
  2.4127 +           }
  2.4128 +       }
  2.4129 +
  2.4130 +       if (iLBCdec_inst->use_enhancer == 1) {
  2.4131 +
  2.4132 +           /* post filtering */
  2.4133 +
  2.4134 +           iLBCdec_inst->last_lag =
  2.4135 +               enhancerInterface(data, decresidual, iLBCdec_inst);
  2.4136 +
  2.4137 +           /* synthesis filtering */
  2.4138 +
  2.4139 +           if (iLBCdec_inst->mode==20) {
  2.4140 +               /* Enhancer has 40 samples delay */
  2.4141 +               i=0;
  2.4142 +               syntFilter(data + i*SUBL,
  2.4143 +                   iLBCdec_inst->old_syntdenum +
  2.4144 +                   (i+iLBCdec_inst->nsub-1)*(LPC_FILTERORDER+1),
  2.4145 +                   SUBL, iLBCdec_inst->syntMem);
  2.4146 +
  2.4147 +
  2.4148 +
  2.4149 +Andersen, et al.              Experimental                     [Page 74]
  2.4150 +
  2.4151 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4152 +
  2.4153 +
  2.4154 +               for (i=1; i < iLBCdec_inst->nsub; i++) {
  2.4155 +                   syntFilter(data + i*SUBL,
  2.4156 +                       syntdenum + (i-1)*(LPC_FILTERORDER+1),
  2.4157 +                       SUBL, iLBCdec_inst->syntMem);
  2.4158 +               }
  2.4159 +           } else if (iLBCdec_inst->mode==30) {
  2.4160 +               /* Enhancer has 80 samples delay */
  2.4161 +               for (i=0; i < 2; i++) {
  2.4162 +                   syntFilter(data + i*SUBL,
  2.4163 +                       iLBCdec_inst->old_syntdenum +
  2.4164 +                       (i+iLBCdec_inst->nsub-2)*(LPC_FILTERORDER+1),
  2.4165 +                       SUBL, iLBCdec_inst->syntMem);
  2.4166 +               }
  2.4167 +               for (i=2; i < iLBCdec_inst->nsub; i++) {
  2.4168 +                   syntFilter(data + i*SUBL,
  2.4169 +                       syntdenum + (i-2)*(LPC_FILTERORDER+1), SUBL,
  2.4170 +                       iLBCdec_inst->syntMem);
  2.4171 +               }
  2.4172 +           }
  2.4173 +
  2.4174 +       } else {
  2.4175 +
  2.4176 +           /* Find last lag */
  2.4177 +           lag = 20;
  2.4178 +           maxcc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL],
  2.4179 +               &decresidual[BLOCKL_MAX-ENH_BLOCKL-lag], ENH_BLOCKL);
  2.4180 +
  2.4181 +           for (ilag=21; ilag<120; ilag++) {
  2.4182 +               cc = xCorrCoef(&decresidual[BLOCKL_MAX-ENH_BLOCKL],
  2.4183 +                   &decresidual[BLOCKL_MAX-ENH_BLOCKL-ilag],
  2.4184 +                   ENH_BLOCKL);
  2.4185 +
  2.4186 +               if (cc > maxcc) {
  2.4187 +                   maxcc = cc;
  2.4188 +                   lag = ilag;
  2.4189 +               }
  2.4190 +           }
  2.4191 +           iLBCdec_inst->last_lag = lag;
  2.4192 +
  2.4193 +           /* copy data and run synthesis filter */
  2.4194 +
  2.4195 +           memcpy(data, decresidual,
  2.4196 +               iLBCdec_inst->blockl*sizeof(float));
  2.4197 +           for (i=0; i < iLBCdec_inst->nsub; i++) {
  2.4198 +               syntFilter(data + i*SUBL,
  2.4199 +                   syntdenum + i*(LPC_FILTERORDER+1), SUBL,
  2.4200 +                   iLBCdec_inst->syntMem);
  2.4201 +           }
  2.4202 +
  2.4203 +
  2.4204 +
  2.4205 +Andersen, et al.              Experimental                     [Page 75]
  2.4206 +
  2.4207 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4208 +
  2.4209 +
  2.4210 +       }
  2.4211 +
  2.4212 +       /* high pass filtering on output if desired, otherwise
  2.4213 +          copy to out */
  2.4214 +
  2.4215 +       hpOutput(data, iLBCdec_inst->blockl,
  2.4216 +                   decblock,iLBCdec_inst->hpomem);
  2.4217 +
  2.4218 +       /* memcpy(decblock,data,iLBCdec_inst->blockl*sizeof(float));*/
  2.4219 +
  2.4220 +       memcpy(iLBCdec_inst->old_syntdenum, syntdenum,
  2.4221 +
  2.4222 +           iLBCdec_inst->nsub*(LPC_FILTERORDER+1)*sizeof(float));
  2.4223 +
  2.4224 +       iLBCdec_inst->prev_enh_pl=0;
  2.4225 +
  2.4226 +       if (mode==0) { /* PLC was used */
  2.4227 +           iLBCdec_inst->prev_enh_pl=1;
  2.4228 +       }
  2.4229 +   }
  2.4230 +
  2.4231 +A.6.  iLBC_define.h
  2.4232 +
  2.4233 +   /******************************************************************
  2.4234 +
  2.4235 +       iLBC Speech Coder ANSI-C Source Code
  2.4236 +
  2.4237 +       iLBC_define.h
  2.4238 +
  2.4239 +       Copyright (C) The Internet Society (2004).
  2.4240 +       All Rights Reserved.
  2.4241 +
  2.4242 +   ******************************************************************/
  2.4243 +   #include <string.h>
  2.4244 +
  2.4245 +   #ifndef __iLBC_ILBCDEFINE_H
  2.4246 +   #define __iLBC_ILBCDEFINE_H
  2.4247 +
  2.4248 +   /* general codec settings */
  2.4249 +
  2.4250 +   #define FS                      (float)8000.0
  2.4251 +   #define BLOCKL_20MS             160
  2.4252 +   #define BLOCKL_30MS             240
  2.4253 +   #define BLOCKL_MAX              240
  2.4254 +   #define NSUB_20MS               4
  2.4255 +   #define NSUB_30MS               6
  2.4256 +   #define NSUB_MAX            6
  2.4257 +   #define NASUB_20MS              2
  2.4258 +
  2.4259 +
  2.4260 +
  2.4261 +Andersen, et al.              Experimental                     [Page 76]
  2.4262 +
  2.4263 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4264 +
  2.4265 +
  2.4266 +   #define NASUB_30MS              4
  2.4267 +   #define NASUB_MAX               4
  2.4268 +   #define SUBL                40
  2.4269 +   #define STATE_LEN               80
  2.4270 +   #define STATE_SHORT_LEN_30MS    58
  2.4271 +   #define STATE_SHORT_LEN_20MS    57
  2.4272 +
  2.4273 +   /* LPC settings */
  2.4274 +
  2.4275 +   #define LPC_FILTERORDER         10
  2.4276 +   #define LPC_CHIRP_SYNTDENUM     (float)0.9025
  2.4277 +   #define LPC_CHIRP_WEIGHTDENUM   (float)0.4222
  2.4278 +   #define LPC_LOOKBACK        60
  2.4279 +   #define LPC_N_20MS              1
  2.4280 +   #define LPC_N_30MS              2
  2.4281 +   #define LPC_N_MAX               2
  2.4282 +   #define LPC_ASYMDIFF        20
  2.4283 +   #define LPC_BW                  (float)60.0
  2.4284 +   #define LPC_WN                  (float)1.0001
  2.4285 +   #define LSF_NSPLIT              3
  2.4286 +   #define LSF_NUMBER_OF_STEPS     4
  2.4287 +   #define LPC_HALFORDER           (LPC_FILTERORDER/2)
  2.4288 +
  2.4289 +   /* cb settings */
  2.4290 +
  2.4291 +   #define CB_NSTAGES              3
  2.4292 +   #define CB_EXPAND               2
  2.4293 +   #define CB_MEML                 147
  2.4294 +   #define CB_FILTERLEN        2*4
  2.4295 +   #define CB_HALFFILTERLEN    4
  2.4296 +   #define CB_RESRANGE             34
  2.4297 +   #define CB_MAXGAIN              (float)1.3
  2.4298 +
  2.4299 +   /* enhancer */
  2.4300 +
  2.4301 +   #define ENH_BLOCKL              80  /* block length */
  2.4302 +   #define ENH_BLOCKL_HALF         (ENH_BLOCKL/2)
  2.4303 +   #define ENH_HL                  3   /* 2*ENH_HL+1 is number blocks
  2.4304 +                                          in said second sequence */
  2.4305 +   #define ENH_SLOP            2   /* max difference estimated and
  2.4306 +                                          correct pitch period */
  2.4307 +   #define ENH_PLOCSL              20  /* pitch-estimates and pitch-
  2.4308 +                                          locations buffer length */
  2.4309 +   #define ENH_OVERHANG        2
  2.4310 +   #define ENH_UPS0            4   /* upsampling rate */
  2.4311 +   #define ENH_FL0                 3   /* 2*FLO+1 is the length of
  2.4312 +                                          each filter */
  2.4313 +   #define ENH_VECTL               (ENH_BLOCKL+2*ENH_FL0)
  2.4314 +
  2.4315 +
  2.4316 +
  2.4317 +Andersen, et al.              Experimental                     [Page 77]
  2.4318 +
  2.4319 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4320 +
  2.4321 +
  2.4322 +   #define ENH_CORRDIM             (2*ENH_SLOP+1)
  2.4323 +   #define ENH_NBLOCKS             (BLOCKL_MAX/ENH_BLOCKL)
  2.4324 +   #define ENH_NBLOCKS_EXTRA       5
  2.4325 +   #define ENH_NBLOCKS_TOT         8   /* ENH_NBLOCKS +
  2.4326 +                                          ENH_NBLOCKS_EXTRA */
  2.4327 +   #define ENH_BUFL            (ENH_NBLOCKS_TOT)*ENH_BLOCKL
  2.4328 +   #define ENH_ALPHA0              (float)0.05
  2.4329 +
  2.4330 +   /* Down sampling */
  2.4331 +
  2.4332 +   #define FILTERORDER_DS          7
  2.4333 +   #define DELAY_DS            3
  2.4334 +   #define FACTOR_DS               2
  2.4335 +
  2.4336 +   /* bit stream defs */
  2.4337 +
  2.4338 +   #define NO_OF_BYTES_20MS    38
  2.4339 +   #define NO_OF_BYTES_30MS    50
  2.4340 +   #define NO_OF_WORDS_20MS    19
  2.4341 +   #define NO_OF_WORDS_30MS    25
  2.4342 +   #define STATE_BITS              3
  2.4343 +   #define BYTE_LEN            8
  2.4344 +   #define ULP_CLASSES             3
  2.4345 +
  2.4346 +   /* help parameters */
  2.4347 +
  2.4348 +   #define FLOAT_MAX               (float)1.0e37
  2.4349 +   #define EPS                     (float)2.220446049250313e-016
  2.4350 +   #define PI                      (float)3.14159265358979323846
  2.4351 +   #define MIN_SAMPLE              -32768
  2.4352 +   #define MAX_SAMPLE              32767
  2.4353 +   #define TWO_PI                  (float)6.283185307
  2.4354 +   #define PI2                     (float)0.159154943
  2.4355 +
  2.4356 +   /* type definition encoder instance */
  2.4357 +   typedef struct iLBC_ULP_Inst_t_ {
  2.4358 +       int lsf_bits[6][ULP_CLASSES+2];
  2.4359 +       int start_bits[ULP_CLASSES+2];
  2.4360 +       int startfirst_bits[ULP_CLASSES+2];
  2.4361 +       int scale_bits[ULP_CLASSES+2];
  2.4362 +       int state_bits[ULP_CLASSES+2];
  2.4363 +       int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2];
  2.4364 +       int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2];
  2.4365 +       int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];
  2.4366 +       int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2];
  2.4367 +   } iLBC_ULP_Inst_t;
  2.4368 +
  2.4369 +   /* type definition encoder instance */
  2.4370 +
  2.4371 +
  2.4372 +
  2.4373 +Andersen, et al.              Experimental                     [Page 78]
  2.4374 +
  2.4375 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4376 +
  2.4377 +
  2.4378 +   typedef struct iLBC_Enc_Inst_t_ {
  2.4379 +
  2.4380 +       /* flag for frame size mode */
  2.4381 +       int mode;
  2.4382 +
  2.4383 +       /* basic parameters for different frame sizes */
  2.4384 +       int blockl;
  2.4385 +       int nsub;
  2.4386 +       int nasub;
  2.4387 +       int no_of_bytes, no_of_words;
  2.4388 +       int lpc_n;
  2.4389 +       int state_short_len;
  2.4390 +       const iLBC_ULP_Inst_t *ULP_inst;
  2.4391 +
  2.4392 +       /* analysis filter state */
  2.4393 +       float anaMem[LPC_FILTERORDER];
  2.4394 +
  2.4395 +       /* old lsf parameters for interpolation */
  2.4396 +       float lsfold[LPC_FILTERORDER];
  2.4397 +       float lsfdeqold[LPC_FILTERORDER];
  2.4398 +
  2.4399 +       /* signal buffer for LP analysis */
  2.4400 +       float lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];
  2.4401 +
  2.4402 +       /* state of input HP filter */
  2.4403 +       float hpimem[4];
  2.4404 +
  2.4405 +   } iLBC_Enc_Inst_t;
  2.4406 +
  2.4407 +   /* type definition decoder instance */
  2.4408 +   typedef struct iLBC_Dec_Inst_t_ {
  2.4409 +
  2.4410 +       /* flag for frame size mode */
  2.4411 +       int mode;
  2.4412 +
  2.4413 +       /* basic parameters for different frame sizes */
  2.4414 +       int blockl;
  2.4415 +       int nsub;
  2.4416 +       int nasub;
  2.4417 +       int no_of_bytes, no_of_words;
  2.4418 +       int lpc_n;
  2.4419 +       int state_short_len;
  2.4420 +       const iLBC_ULP_Inst_t *ULP_inst;
  2.4421 +
  2.4422 +       /* synthesis filter state */
  2.4423 +       float syntMem[LPC_FILTERORDER];
  2.4424 +
  2.4425 +       /* old LSF for interpolation */
  2.4426 +
  2.4427 +
  2.4428 +
  2.4429 +Andersen, et al.              Experimental                     [Page 79]
  2.4430 +
  2.4431 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4432 +
  2.4433 +
  2.4434 +       float lsfdeqold[LPC_FILTERORDER];
  2.4435 +
  2.4436 +       /* pitch lag estimated in enhancer and used in PLC */
  2.4437 +       int last_lag;
  2.4438 +
  2.4439 +       /* PLC state information */
  2.4440 +       int prevLag, consPLICount, prevPLI, prev_enh_pl;
  2.4441 +       float prevLpc[LPC_FILTERORDER+1];
  2.4442 +       float prevResidual[NSUB_MAX*SUBL];
  2.4443 +       float per;
  2.4444 +       unsigned long seed;
  2.4445 +
  2.4446 +       /* previous synthesis filter parameters */
  2.4447 +       float old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX];
  2.4448 +
  2.4449 +       /* state of output HP filter */
  2.4450 +       float hpomem[4];
  2.4451 +
  2.4452 +       /* enhancer state information */
  2.4453 +       int use_enhancer;
  2.4454 +       float enh_buf[ENH_BUFL];
  2.4455 +       float enh_period[ENH_NBLOCKS_TOT];
  2.4456 +
  2.4457 +   } iLBC_Dec_Inst_t;
  2.4458 +
  2.4459 +   #endif
  2.4460 +
  2.4461 +A.7.  constants.h
  2.4462 +
  2.4463 +   /******************************************************************
  2.4464 +
  2.4465 +       iLBC Speech Coder ANSI-C Source Code
  2.4466 +
  2.4467 +       constants.h
  2.4468 +
  2.4469 +       Copyright (C) The Internet Society (2004).
  2.4470 +       All Rights Reserved.
  2.4471 +
  2.4472 +   ******************************************************************/
  2.4473 +
  2.4474 +   #ifndef __iLBC_CONSTANTS_H
  2.4475 +   #define __iLBC_CONSTANTS_H
  2.4476 +
  2.4477 +   #include "iLBC_define.h"
  2.4478 +
  2.4479 +
  2.4480 +   /* ULP bit allocation */
  2.4481 +
  2.4482 +
  2.4483 +
  2.4484 +
  2.4485 +Andersen, et al.              Experimental                     [Page 80]
  2.4486 +
  2.4487 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4488 +
  2.4489 +
  2.4490 +   extern const iLBC_ULP_Inst_t ULP_20msTbl;
  2.4491 +   extern const iLBC_ULP_Inst_t ULP_30msTbl;
  2.4492 +
  2.4493 +   /* high pass filters */
  2.4494 +
  2.4495 +   extern float hpi_zero_coefsTbl[];
  2.4496 +   extern float hpi_pole_coefsTbl[];
  2.4497 +   extern float hpo_zero_coefsTbl[];
  2.4498 +   extern float hpo_pole_coefsTbl[];
  2.4499 +
  2.4500 +   /* low pass filters */
  2.4501 +   extern float lpFilt_coefsTbl[];
  2.4502 +
  2.4503 +   /* LPC analysis and quantization */
  2.4504 +
  2.4505 +   extern float lpc_winTbl[];
  2.4506 +   extern float lpc_asymwinTbl[];
  2.4507 +   extern float lpc_lagwinTbl[];
  2.4508 +   extern float lsfCbTbl[];
  2.4509 +   extern float lsfmeanTbl[];
  2.4510 +   extern int   dim_lsfCbTbl[];
  2.4511 +   extern int   size_lsfCbTbl[];
  2.4512 +   extern float lsf_weightTbl_30ms[];
  2.4513 +   extern float lsf_weightTbl_20ms[];
  2.4514 +
  2.4515 +   /* state quantization tables */
  2.4516 +
  2.4517 +   extern float state_sq3Tbl[];
  2.4518 +   extern float state_frgqTbl[];
  2.4519 +
  2.4520 +   /* gain quantization tables */
  2.4521 +
  2.4522 +   extern float gain_sq3Tbl[];
  2.4523 +   extern float gain_sq4Tbl[];
  2.4524 +   extern float gain_sq5Tbl[];
  2.4525 +
  2.4526 +   /* adaptive codebook definitions */
  2.4527 +
  2.4528 +   extern int search_rangeTbl[5][CB_NSTAGES];
  2.4529 +   extern int memLfTbl[];
  2.4530 +   extern int stMemLTbl;
  2.4531 +   extern float cbfiltersTbl[CB_FILTERLEN];
  2.4532 +
  2.4533 +   /* enhancer definitions */
  2.4534 +
  2.4535 +   extern float polyphaserTbl[];
  2.4536 +   extern float enh_plocsTbl[];
  2.4537 +
  2.4538 +
  2.4539 +
  2.4540 +
  2.4541 +Andersen, et al.              Experimental                     [Page 81]
  2.4542 +
  2.4543 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4544 +
  2.4545 +
  2.4546 +   #endif
  2.4547 +
  2.4548 +A.8.  constants.c
  2.4549 +
  2.4550 +   /******************************************************************
  2.4551 +
  2.4552 +       iLBC Speech Coder ANSI-C Source Code
  2.4553 +
  2.4554 +       constants.c
  2.4555 +
  2.4556 +       Copyright (C) The Internet Society (2004).
  2.4557 +       All Rights Reserved.
  2.4558 +
  2.4559 +   ******************************************************************/
  2.4560 +
  2.4561 +   #include "iLBC_define.h"
  2.4562 +
  2.4563 +   /* ULP bit allocation */
  2.4564 +
  2.4565 +       /* 20 ms frame */
  2.4566 +
  2.4567 +   const iLBC_ULP_Inst_t ULP_20msTbl = {
  2.4568 +       /* LSF */
  2.4569 +       {   {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0},
  2.4570 +           {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},
  2.4571 +       /* Start state location, gain and samples */
  2.4572 +       {2,0,0,0,0},
  2.4573 +       {1,0,0,0,0},
  2.4574 +       {6,0,0,0,0},
  2.4575 +       {0,1,2,0,0},
  2.4576 +       /* extra CB index and extra CB gain */
  2.4577 +       {{6,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
  2.4578 +       {{2,0,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},
  2.4579 +       /* CB index and CB gain */
  2.4580 +       {   {{7,0,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
  2.4581 +           {{0,0,8,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},
  2.4582 +           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},
  2.4583 +           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}},
  2.4584 +       {   {{1,2,2,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},
  2.4585 +           {{1,1,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},
  2.4586 +           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}},
  2.4587 +           {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}}}
  2.4588 +   };
  2.4589 +
  2.4590 +       /* 30 ms frame */
  2.4591 +
  2.4592 +   const iLBC_ULP_Inst_t ULP_30msTbl = {
  2.4593 +       /* LSF */
  2.4594 +
  2.4595 +
  2.4596 +
  2.4597 +Andersen, et al.              Experimental                     [Page 82]
  2.4598 +
  2.4599 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4600 +
  2.4601 +
  2.4602 +       {   {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0},
  2.4603 +           {6,0,0,0,0}, {7,0,0,0,0}, {7,0,0,0,0}},
  2.4604 +       /* Start state location, gain and samples */
  2.4605 +       {3,0,0,0,0},
  2.4606 +       {1,0,0,0,0},
  2.4607 +       {6,0,0,0,0},
  2.4608 +       {0,1,2,0,0},
  2.4609 +       /* extra CB index and extra CB gain */
  2.4610 +       {{4,2,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
  2.4611 +       {{1,1,3,0,0}, {1,1,2,0,0}, {0,0,3,0,0}},
  2.4612 +       /* CB index and CB gain */
  2.4613 +       {   {{6,1,1,0,0}, {0,0,7,0,0}, {0,0,7,0,0}},
  2.4614 +           {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},
  2.4615 +           {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}},
  2.4616 +           {{0,7,1,0,0}, {0,0,8,0,0}, {0,0,8,0,0}}},
  2.4617 +       {   {{1,2,2,0,0}, {1,2,1,0,0}, {0,0,3,0,0}},
  2.4618 +           {{0,2,3,0,0}, {0,2,2,0,0}, {0,0,3,0,0}},
  2.4619 +           {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}},
  2.4620 +           {{0,1,4,0,0}, {0,1,3,0,0}, {0,0,3,0,0}}}
  2.4621 +   };
  2.4622 +
  2.4623 +   /* HP Filters */
  2.4624 +
  2.4625 +   float hpi_zero_coefsTbl[3] = {
  2.4626 +       (float)0.92727436, (float)-1.8544941, (float)0.92727436
  2.4627 +   };
  2.4628 +   float hpi_pole_coefsTbl[3] = {
  2.4629 +       (float)1.0, (float)-1.9059465, (float)0.9114024
  2.4630 +   };
  2.4631 +   float hpo_zero_coefsTbl[3] = {
  2.4632 +       (float)0.93980581, (float)-1.8795834, (float)0.93980581
  2.4633 +   };
  2.4634 +   float hpo_pole_coefsTbl[3] = {
  2.4635 +       (float)1.0, (float)-1.9330735, (float)0.93589199
  2.4636 +   };
  2.4637 +
  2.4638 +   /* LP Filter */
  2.4639 +
  2.4640 +   float lpFilt_coefsTbl[FILTERORDER_DS]={
  2.4641 +       (float)-0.066650, (float)0.125000, (float)0.316650,
  2.4642 +       (float)0.414063, (float)0.316650,
  2.4643 +       (float)0.125000, (float)-0.066650
  2.4644 +   };
  2.4645 +
  2.4646 +   /* State quantization tables */
  2.4647 +
  2.4648 +   float state_sq3Tbl[8] = {
  2.4649 +       (float)-3.719849, (float)-2.177490, (float)-1.130005,
  2.4650 +
  2.4651 +
  2.4652 +
  2.4653 +Andersen, et al.              Experimental                     [Page 83]
  2.4654 +
  2.4655 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4656 +
  2.4657 +
  2.4658 +       (float)-0.309692, (float)0.444214, (float)1.329712,
  2.4659 +       (float)2.436279, (float)3.983887
  2.4660 +   };
  2.4661 +
  2.4662 +   float state_frgqTbl[64] = {
  2.4663 +       (float)1.000085, (float)1.071695, (float)1.140395,
  2.4664 +       (float)1.206868, (float)1.277188, (float)1.351503,
  2.4665 +       (float)1.429380, (float)1.500727, (float)1.569049,
  2.4666 +       (float)1.639599, (float)1.707071, (float)1.781531,
  2.4667 +       (float)1.840799, (float)1.901550, (float)1.956695,
  2.4668 +       (float)2.006750, (float)2.055474, (float)2.102787,
  2.4669 +       (float)2.142819, (float)2.183592, (float)2.217962,
  2.4670 +       (float)2.257177, (float)2.295739, (float)2.332967,
  2.4671 +       (float)2.369248, (float)2.402792, (float)2.435080,
  2.4672 +       (float)2.468598, (float)2.503394, (float)2.539284,
  2.4673 +       (float)2.572944, (float)2.605036, (float)2.636331,
  2.4674 +       (float)2.668939, (float)2.698780, (float)2.729101,
  2.4675 +       (float)2.759786, (float)2.789834, (float)2.818679,
  2.4676 +       (float)2.848074, (float)2.877470, (float)2.906899,
  2.4677 +       (float)2.936655, (float)2.967804, (float)3.000115,
  2.4678 +       (float)3.033367, (float)3.066355, (float)3.104231,
  2.4679 +       (float)3.141499, (float)3.183012, (float)3.222952,
  2.4680 +       (float)3.265433, (float)3.308441, (float)3.350823,
  2.4681 +       (float)3.395275, (float)3.442793, (float)3.490801,
  2.4682 +       (float)3.542514, (float)3.604064, (float)3.666050,
  2.4683 +       (float)3.740994, (float)3.830749, (float)3.938770,
  2.4684 +       (float)4.101764
  2.4685 +   };
  2.4686 +
  2.4687 +   /* CB tables */
  2.4688 +
  2.4689 +   int search_rangeTbl[5][CB_NSTAGES]={{58,58,58}, {108,44,44},
  2.4690 +               {108,108,108}, {108,108,108}, {108,108,108}};
  2.4691 +   int stMemLTbl=85;
  2.4692 +   int memLfTbl[NASUB_MAX]={147,147,147,147};
  2.4693 +
  2.4694 +   /* expansion filter(s) */
  2.4695 +
  2.4696 +   float cbfiltersTbl[CB_FILTERLEN]={
  2.4697 +       (float)-0.034180, (float)0.108887, (float)-0.184326,
  2.4698 +       (float)0.806152,  (float)0.713379, (float)-0.144043,
  2.4699 +       (float)0.083740,  (float)-0.033691
  2.4700 +   };
  2.4701 +
  2.4702 +   /* Gain Quantization */
  2.4703 +
  2.4704 +   float gain_sq3Tbl[8]={
  2.4705 +       (float)-1.000000,  (float)-0.659973,  (float)-0.330017,
  2.4706 +
  2.4707 +
  2.4708 +
  2.4709 +Andersen, et al.              Experimental                     [Page 84]
  2.4710 +
  2.4711 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4712 +
  2.4713 +
  2.4714 +       (float)0.000000, (float)0.250000, (float)0.500000,
  2.4715 +       (float)0.750000, (float)1.00000};
  2.4716 +
  2.4717 +   float gain_sq4Tbl[16]={
  2.4718 +       (float)-1.049988, (float)-0.900024, (float)-0.750000,
  2.4719 +       (float)-0.599976, (float)-0.450012, (float)-0.299988,
  2.4720 +       (float)-0.150024, (float)0.000000, (float)0.150024,
  2.4721 +       (float)0.299988, (float)0.450012, (float)0.599976,
  2.4722 +       (float)0.750000, (float)0.900024, (float)1.049988,
  2.4723 +       (float)1.200012};
  2.4724 +
  2.4725 +   float gain_sq5Tbl[32]={
  2.4726 +       (float)0.037476, (float)0.075012, (float)0.112488,
  2.4727 +       (float)0.150024, (float)0.187500, (float)0.224976,
  2.4728 +       (float)0.262512, (float)0.299988, (float)0.337524,
  2.4729 +       (float)0.375000, (float)0.412476, (float)0.450012,
  2.4730 +       (float)0.487488, (float)0.525024, (float)0.562500,
  2.4731 +       (float)0.599976, (float)0.637512, (float)0.674988,
  2.4732 +       (float)0.712524, (float)0.750000, (float)0.787476,
  2.4733 +       (float)0.825012, (float)0.862488, (float)0.900024,
  2.4734 +       (float)0.937500, (float)0.974976, (float)1.012512,
  2.4735 +       (float)1.049988, (float)1.087524, (float)1.125000,
  2.4736 +       (float)1.162476, (float)1.200012};
  2.4737 +
  2.4738 +   /* Enhancer - Upsamling a factor 4 (ENH_UPS0 = 4) */
  2.4739 +   float polyphaserTbl[ENH_UPS0*(2*ENH_FL0+1)]={
  2.4740 +       (float)0.000000, (float)0.000000, (float)0.000000,
  2.4741 +   (float)1.000000,
  2.4742 +           (float)0.000000, (float)0.000000, (float)0.000000,
  2.4743 +       (float)0.015625, (float)-0.076904, (float)0.288330,
  2.4744 +   (float)0.862061,
  2.4745 +           (float)-0.106445, (float)0.018799, (float)-0.015625,
  2.4746 +       (float)0.023682, (float)-0.124268, (float)0.601563,
  2.4747 +   (float)0.601563,
  2.4748 +           (float)-0.124268, (float)0.023682, (float)-0.023682,
  2.4749 +       (float)0.018799, (float)-0.106445, (float)0.862061,
  2.4750 +   (float)0.288330,
  2.4751 +           (float)-0.076904, (float)0.015625, (float)-0.018799};
  2.4752 +
  2.4753 +   float enh_plocsTbl[ENH_NBLOCKS_TOT] = {(float)40.0, (float)120.0,
  2.4754 +               (float)200.0, (float)280.0, (float)360.0,
  2.4755 +               (float)440.0, (float)520.0, (float)600.0};
  2.4756 +
  2.4757 +   /* LPC analysis and quantization */
  2.4758 +
  2.4759 +   int dim_lsfCbTbl[LSF_NSPLIT] = {3, 3, 4};
  2.4760 +   int size_lsfCbTbl[LSF_NSPLIT] = {64,128,128};
  2.4761 +
  2.4762 +
  2.4763 +
  2.4764 +
  2.4765 +Andersen, et al.              Experimental                     [Page 85]
  2.4766 +
  2.4767 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4768 +
  2.4769 +
  2.4770 +   float lsfmeanTbl[LPC_FILTERORDER] = {
  2.4771 +       (float)0.281738, (float)0.445801, (float)0.663330,
  2.4772 +       (float)0.962524, (float)1.251831, (float)1.533081,
  2.4773 +       (float)1.850586, (float)2.137817, (float)2.481445,
  2.4774 +       (float)2.777344};
  2.4775 +
  2.4776 +   float lsf_weightTbl_30ms[6] = {(float)(1.0/2.0), (float)1.0,
  2.4777 +   (float)(2.0/3.0),
  2.4778 +       (float)(1.0/3.0), (float)0.0, (float)0.0};
  2.4779 +
  2.4780 +   float lsf_weightTbl_20ms[4] = {(float)(3.0/4.0), (float)(2.0/4.0),
  2.4781 +       (float)(1.0/4.0), (float)(0.0)};
  2.4782 +
  2.4783 +   /* Hanning LPC window */
  2.4784 +   float lpc_winTbl[BLOCKL_MAX]={
  2.4785 +       (float)0.000183, (float)0.000671, (float)0.001526,
  2.4786 +       (float)0.002716, (float)0.004242, (float)0.006104,
  2.4787 +       (float)0.008301, (float)0.010834, (float)0.013702,
  2.4788 +       (float)0.016907, (float)0.020416, (float)0.024261,
  2.4789 +       (float)0.028442, (float)0.032928, (float)0.037750,
  2.4790 +       (float)0.042877, (float)0.048309, (float)0.054047,
  2.4791 +       (float)0.060089, (float)0.066437, (float)0.073090,
  2.4792 +       (float)0.080017, (float)0.087219, (float)0.094727,
  2.4793 +       (float)0.102509, (float)0.110535, (float)0.118835,
  2.4794 +       (float)0.127411, (float)0.136230, (float)0.145294,
  2.4795 +       (float)0.154602, (float)0.164154, (float)0.173920,
  2.4796 +       (float)0.183899, (float)0.194122, (float)0.204529,
  2.4797 +       (float)0.215149, (float)0.225952, (float)0.236938,
  2.4798 +       (float)0.248108, (float)0.259460, (float)0.270966,
  2.4799 +       (float)0.282654, (float)0.294464, (float)0.306396,
  2.4800 +       (float)0.318481, (float)0.330688, (float)0.343018,
  2.4801 +       (float)0.355438, (float)0.367981, (float)0.380585,
  2.4802 +       (float)0.393280, (float)0.406067, (float)0.418884,
  2.4803 +       (float)0.431763, (float)0.444702, (float)0.457672,
  2.4804 +       (float)0.470673, (float)0.483704, (float)0.496735,
  2.4805 +       (float)0.509766, (float)0.522797, (float)0.535828,
  2.4806 +       (float)0.548798, (float)0.561768, (float)0.574677,
  2.4807 +       (float)0.587524, (float)0.600342, (float)0.613068,
  2.4808 +       (float)0.625732, (float)0.638306, (float)0.650787,
  2.4809 +       (float)0.663147, (float)0.675415, (float)0.687561,
  2.4810 +       (float)0.699585, (float)0.711487, (float)0.723206,
  2.4811 +       (float)0.734802, (float)0.746216, (float)0.757477,
  2.4812 +       (float)0.768585, (float)0.779480, (float)0.790192,
  2.4813 +       (float)0.800720, (float)0.811005, (float)0.821106,
  2.4814 +       (float)0.830994, (float)0.840668, (float)0.850067,
  2.4815 +       (float)0.859253, (float)0.868225, (float)0.876892,
  2.4816 +       (float)0.885345, (float)0.893524, (float)0.901428,
  2.4817 +       (float)0.909058, (float)0.916412, (float)0.923492,
  2.4818 +
  2.4819 +
  2.4820 +
  2.4821 +Andersen, et al.              Experimental                     [Page 86]
  2.4822 +
  2.4823 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4824 +
  2.4825 +
  2.4826 +       (float)0.930267, (float)0.936768, (float)0.942963,
  2.4827 +       (float)0.948853, (float)0.954437, (float)0.959717,
  2.4828 +       (float)0.964691, (float)0.969360, (float)0.973694,
  2.4829 +       (float)0.977692, (float)0.981384, (float)0.984741,
  2.4830 +       (float)0.987762, (float)0.990479, (float)0.992828,
  2.4831 +       (float)0.994873, (float)0.996552, (float)0.997925,
  2.4832 +       (float)0.998932, (float)0.999603, (float)0.999969,
  2.4833 +       (float)0.999969, (float)0.999603, (float)0.998932,
  2.4834 +       (float)0.997925, (float)0.996552, (float)0.994873,
  2.4835 +       (float)0.992828, (float)0.990479, (float)0.987762,
  2.4836 +       (float)0.984741, (float)0.981384, (float)0.977692,
  2.4837 +       (float)0.973694, (float)0.969360, (float)0.964691,
  2.4838 +       (float)0.959717, (float)0.954437, (float)0.948853,
  2.4839 +       (float)0.942963, (float)0.936768, (float)0.930267,
  2.4840 +       (float)0.923492, (float)0.916412, (float)0.909058,
  2.4841 +       (float)0.901428, (float)0.893524, (float)0.885345,
  2.4842 +       (float)0.876892, (float)0.868225, (float)0.859253,
  2.4843 +       (float)0.850067, (float)0.840668, (float)0.830994,
  2.4844 +       (float)0.821106, (float)0.811005, (float)0.800720,
  2.4845 +       (float)0.790192, (float)0.779480, (float)0.768585,
  2.4846 +       (float)0.757477, (float)0.746216, (float)0.734802,
  2.4847 +       (float)0.723206, (float)0.711487, (float)0.699585,
  2.4848 +       (float)0.687561, (float)0.675415, (float)0.663147,
  2.4849 +       (float)0.650787, (float)0.638306, (float)0.625732,
  2.4850 +       (float)0.613068, (float)0.600342, (float)0.587524,
  2.4851 +       (float)0.574677, (float)0.561768, (float)0.548798,
  2.4852 +       (float)0.535828, (float)0.522797, (float)0.509766,
  2.4853 +       (float)0.496735, (float)0.483704, (float)0.470673,
  2.4854 +       (float)0.457672, (float)0.444702, (float)0.431763,
  2.4855 +       (float)0.418884, (float)0.406067, (float)0.393280,
  2.4856 +       (float)0.380585, (float)0.367981, (float)0.355438,
  2.4857 +       (float)0.343018, (float)0.330688, (float)0.318481,
  2.4858 +       (float)0.306396, (float)0.294464, (float)0.282654,
  2.4859 +       (float)0.270966, (float)0.259460, (float)0.248108,
  2.4860 +       (float)0.236938, (float)0.225952, (float)0.215149,
  2.4861 +       (float)0.204529, (float)0.194122, (float)0.183899,
  2.4862 +       (float)0.173920, (float)0.164154, (float)0.154602,
  2.4863 +       (float)0.145294, (float)0.136230, (float)0.127411,
  2.4864 +       (float)0.118835, (float)0.110535, (float)0.102509,
  2.4865 +       (float)0.094727, (float)0.087219, (float)0.080017,
  2.4866 +       (float)0.073090, (float)0.066437, (float)0.060089,
  2.4867 +       (float)0.054047, (float)0.048309, (float)0.042877,
  2.4868 +       (float)0.037750, (float)0.032928, (float)0.028442,
  2.4869 +       (float)0.024261, (float)0.020416, (float)0.016907,
  2.4870 +       (float)0.013702, (float)0.010834, (float)0.008301,
  2.4871 +       (float)0.006104, (float)0.004242, (float)0.002716,
  2.4872 +       (float)0.001526, (float)0.000671, (float)0.000183
  2.4873 +   };
  2.4874 +
  2.4875 +
  2.4876 +
  2.4877 +Andersen, et al.              Experimental                     [Page 87]
  2.4878 +
  2.4879 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4880 +
  2.4881 +
  2.4882 +   /* Asymmetric LPC window */
  2.4883 +   float lpc_asymwinTbl[BLOCKL_MAX]={
  2.4884 +       (float)0.000061, (float)0.000214, (float)0.000458,
  2.4885 +       (float)0.000824, (float)0.001282, (float)0.001831,
  2.4886 +       (float)0.002472, (float)0.003235, (float)0.004120,
  2.4887 +       (float)0.005066, (float)0.006134, (float)0.007294,
  2.4888 +       (float)0.008545, (float)0.009918, (float)0.011383,
  2.4889 +       (float)0.012939, (float)0.014587, (float)0.016357,
  2.4890 +       (float)0.018219, (float)0.020172, (float)0.022217,
  2.4891 +       (float)0.024353, (float)0.026611, (float)0.028961,
  2.4892 +       (float)0.031372, (float)0.033905, (float)0.036530,
  2.4893 +       (float)0.039276, (float)0.042084, (float)0.044983,
  2.4894 +       (float)0.047974, (float)0.051086, (float)0.054260,
  2.4895 +       (float)0.057526, (float)0.060883, (float)0.064331,
  2.4896 +       (float)0.067871, (float)0.071503, (float)0.075226,
  2.4897 +       (float)0.079010, (float)0.082916, (float)0.086884,
  2.4898 +       (float)0.090942, (float)0.095062, (float)0.099304,
  2.4899 +       (float)0.103607, (float)0.107971, (float)0.112427,
  2.4900 +       (float)0.116974, (float)0.121582, (float)0.126282,
  2.4901 +       (float)0.131073, (float)0.135895, (float)0.140839,
  2.4902 +       (float)0.145813, (float)0.150879, (float)0.156006,
  2.4903 +       (float)0.161224, (float)0.166504, (float)0.171844,
  2.4904 +       (float)0.177246, (float)0.182709, (float)0.188263,
  2.4905 +       (float)0.193848, (float)0.199524, (float)0.205231,
  2.4906 +       (float)0.211029, (float)0.216858, (float)0.222778,
  2.4907 +       (float)0.228729, (float)0.234741, (float)0.240814,
  2.4908 +       (float)0.246918, (float)0.253082, (float)0.259308,
  2.4909 +       (float)0.265564, (float)0.271881, (float)0.278259,
  2.4910 +       (float)0.284668, (float)0.291107, (float)0.297607,
  2.4911 +       (float)0.304138, (float)0.310730, (float)0.317322,
  2.4912 +       (float)0.323975, (float)0.330658, (float)0.337372,
  2.4913 +       (float)0.344147, (float)0.350922, (float)0.357727,
  2.4914 +       (float)0.364594, (float)0.371460, (float)0.378357,
  2.4915 +       (float)0.385284, (float)0.392212, (float)0.399170,
  2.4916 +       (float)0.406158, (float)0.413177, (float)0.420197,
  2.4917 +       (float)0.427246, (float)0.434296, (float)0.441376,
  2.4918 +       (float)0.448456, (float)0.455536, (float)0.462646,
  2.4919 +       (float)0.469757, (float)0.476868, (float)0.483978,
  2.4920 +       (float)0.491089, (float)0.498230, (float)0.505341,
  2.4921 +       (float)0.512451, (float)0.519592, (float)0.526703,
  2.4922 +       (float)0.533813, (float)0.540924, (float)0.548004,
  2.4923 +       (float)0.555084, (float)0.562164, (float)0.569244,
  2.4924 +       (float)0.576294, (float)0.583313, (float)0.590332,
  2.4925 +       (float)0.597321, (float)0.604309, (float)0.611267,
  2.4926 +       (float)0.618195, (float)0.625092, (float)0.631989,
  2.4927 +       (float)0.638855, (float)0.645660, (float)0.652466,
  2.4928 +       (float)0.659241, (float)0.665985, (float)0.672668,
  2.4929 +       (float)0.679352, (float)0.685974, (float)0.692566,
  2.4930 +
  2.4931 +
  2.4932 +
  2.4933 +Andersen, et al.              Experimental                     [Page 88]
  2.4934 +
  2.4935 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4936 +
  2.4937 +
  2.4938 +       (float)0.699127, (float)0.705658, (float)0.712128,
  2.4939 +       (float)0.718536, (float)0.724945, (float)0.731262,
  2.4940 +       (float)0.737549, (float)0.743805, (float)0.750000,
  2.4941 +       (float)0.756134, (float)0.762238, (float)0.768280,
  2.4942 +       (float)0.774261, (float)0.780182, (float)0.786072,
  2.4943 +       (float)0.791870, (float)0.797638, (float)0.803314,
  2.4944 +       (float)0.808960, (float)0.814514, (float)0.820038,
  2.4945 +       (float)0.825470, (float)0.830841, (float)0.836151,
  2.4946 +       (float)0.841400, (float)0.846558, (float)0.851654,
  2.4947 +       (float)0.856689, (float)0.861633, (float)0.866516,
  2.4948 +       (float)0.871338, (float)0.876068, (float)0.880737,
  2.4949 +       (float)0.885315, (float)0.889801, (float)0.894226,
  2.4950 +       (float)0.898560, (float)0.902832, (float)0.907013,
  2.4951 +       (float)0.911102, (float)0.915100, (float)0.919037,
  2.4952 +       (float)0.922882, (float)0.926636, (float)0.930328,
  2.4953 +       (float)0.933899, (float)0.937408, (float)0.940796,
  2.4954 +       (float)0.944122, (float)0.947357, (float)0.950470,
  2.4955 +       (float)0.953522, (float)0.956482, (float)0.959351,
  2.4956 +       (float)0.962097, (float)0.964783, (float)0.967377,
  2.4957 +       (float)0.969849, (float)0.972229, (float)0.974518,
  2.4958 +       (float)0.976715, (float)0.978821, (float)0.980835,
  2.4959 +       (float)0.982727, (float)0.984528, (float)0.986237,
  2.4960 +       (float)0.987854, (float)0.989380, (float)0.990784,
  2.4961 +       (float)0.992096, (float)0.993317, (float)0.994415,
  2.4962 +       (float)0.995422, (float)0.996338, (float)0.997162,
  2.4963 +       (float)0.997864, (float)0.998474, (float)0.998962,
  2.4964 +       (float)0.999390, (float)0.999695, (float)0.999878,
  2.4965 +       (float)0.999969, (float)0.999969, (float)0.996918,
  2.4966 +       (float)0.987701, (float)0.972382, (float)0.951050,
  2.4967 +       (float)0.923889, (float)0.891022, (float)0.852631,
  2.4968 +       (float)0.809021, (float)0.760406, (float)0.707092,
  2.4969 +       (float)0.649445, (float)0.587799, (float)0.522491,
  2.4970 +       (float)0.453979, (float)0.382690, (float)0.309021,
  2.4971 +       (float)0.233459, (float)0.156433, (float)0.078461
  2.4972 +   };
  2.4973 +
  2.4974 +   /* Lag window for LPC */
  2.4975 +   float lpc_lagwinTbl[LPC_FILTERORDER + 1]={
  2.4976 +       (float)1.000100, (float)0.998890, (float)0.995569,
  2.4977 +           (float)0.990057, (float)0.982392,
  2.4978 +       (float)0.972623, (float)0.960816, (float)0.947047,
  2.4979 +           (float)0.931405, (float)0.913989, (float)0.894909};
  2.4980 +
  2.4981 +   /* LSF quantization*/
  2.4982 +   float lsfCbTbl[64 * 3 + 128 * 3 + 128 * 4] = {
  2.4983 +   (float)0.155396, (float)0.273193, (float)0.451172,
  2.4984 +   (float)0.390503, (float)0.648071, (float)1.002075,
  2.4985 +   (float)0.440186, (float)0.692261, (float)0.955688,
  2.4986 +
  2.4987 +
  2.4988 +
  2.4989 +Andersen, et al.              Experimental                     [Page 89]
  2.4990 +
  2.4991 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.4992 +
  2.4993 +
  2.4994 +   (float)0.343628, (float)0.642334, (float)1.071533,
  2.4995 +   (float)0.318359, (float)0.491577, (float)0.670532,
  2.4996 +   (float)0.193115, (float)0.375488, (float)0.725708,
  2.4997 +   (float)0.364136, (float)0.510376, (float)0.658691,
  2.4998 +   (float)0.297485, (float)0.527588, (float)0.842529,
  2.4999 +   (float)0.227173, (float)0.365967, (float)0.563110,
  2.5000 +   (float)0.244995, (float)0.396729, (float)0.636475,
  2.5001 +   (float)0.169434, (float)0.300171, (float)0.520264,
  2.5002 +   (float)0.312866, (float)0.464478, (float)0.643188,
  2.5003 +   (float)0.248535, (float)0.429932, (float)0.626099,
  2.5004 +   (float)0.236206, (float)0.491333, (float)0.817139,
  2.5005 +   (float)0.334961, (float)0.625122, (float)0.895752,
  2.5006 +   (float)0.343018, (float)0.518555, (float)0.698608,
  2.5007 +   (float)0.372803, (float)0.659790, (float)0.945435,
  2.5008 +   (float)0.176880, (float)0.316528, (float)0.581421,
  2.5009 +   (float)0.416382, (float)0.625977, (float)0.805176,
  2.5010 +   (float)0.303223, (float)0.568726, (float)0.915039,
  2.5011 +   (float)0.203613, (float)0.351440, (float)0.588135,
  2.5012 +   (float)0.221191, (float)0.375000, (float)0.614746,
  2.5013 +   (float)0.199951, (float)0.323364, (float)0.476074,
  2.5014 +   (float)0.300781, (float)0.433350, (float)0.566895,
  2.5015 +   (float)0.226196, (float)0.354004, (float)0.507568,
  2.5016 +   (float)0.300049, (float)0.508179, (float)0.711670,
  2.5017 +   (float)0.312012, (float)0.492676, (float)0.763428,
  2.5018 +   (float)0.329956, (float)0.541016, (float)0.795776,
  2.5019 +   (float)0.373779, (float)0.604614, (float)0.928833,
  2.5020 +   (float)0.210571, (float)0.452026, (float)0.755249,
  2.5021 +   (float)0.271118, (float)0.473267, (float)0.662476,
  2.5022 +   (float)0.285522, (float)0.436890, (float)0.634399,
  2.5023 +   (float)0.246704, (float)0.565552, (float)0.859009,
  2.5024 +   (float)0.270508, (float)0.406250, (float)0.553589,
  2.5025 +   (float)0.361450, (float)0.578491, (float)0.813843,
  2.5026 +   (float)0.342651, (float)0.482788, (float)0.622437,
  2.5027 +   (float)0.340332, (float)0.549438, (float)0.743164,
  2.5028 +   (float)0.200439, (float)0.336304, (float)0.540894,
  2.5029 +   (float)0.407837, (float)0.644775, (float)0.895142,
  2.5030 +   (float)0.294678, (float)0.454834, (float)0.699097,
  2.5031 +   (float)0.193115, (float)0.344482, (float)0.643188,
  2.5032 +   (float)0.275757, (float)0.420776, (float)0.598755,
  2.5033 +   (float)0.380493, (float)0.608643, (float)0.861084,
  2.5034 +   (float)0.222778, (float)0.426147, (float)0.676514,
  2.5035 +   (float)0.407471, (float)0.700195, (float)1.053101,
  2.5036 +   (float)0.218384, (float)0.377197, (float)0.669922,
  2.5037 +   (float)0.313232, (float)0.454102, (float)0.600952,
  2.5038 +   (float)0.347412, (float)0.571533, (float)0.874146,
  2.5039 +   (float)0.238037, (float)0.405396, (float)0.729492,
  2.5040 +   (float)0.223877, (float)0.412964, (float)0.822021,
  2.5041 +   (float)0.395264, (float)0.582153, (float)0.743896,
  2.5042 +
  2.5043 +
  2.5044 +
  2.5045 +Andersen, et al.              Experimental                     [Page 90]
  2.5046 +
  2.5047 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5048 +
  2.5049 +
  2.5050 +   (float)0.247925, (float)0.485596, (float)0.720581,
  2.5051 +   (float)0.229126, (float)0.496582, (float)0.907715,
  2.5052 +   (float)0.260132, (float)0.566895, (float)1.012695,
  2.5053 +   (float)0.337402, (float)0.611572, (float)0.978149,
  2.5054 +   (float)0.267822, (float)0.447632, (float)0.769287,
  2.5055 +   (float)0.250610, (float)0.381714, (float)0.530029,
  2.5056 +   (float)0.430054, (float)0.805054, (float)1.221924,
  2.5057 +   (float)0.382568, (float)0.544067, (float)0.701660,
  2.5058 +   (float)0.383545, (float)0.710327, (float)1.149170,
  2.5059 +   (float)0.271362, (float)0.529053, (float)0.775513,
  2.5060 +   (float)0.246826, (float)0.393555, (float)0.588623,
  2.5061 +   (float)0.266846, (float)0.422119, (float)0.676758,
  2.5062 +   (float)0.311523, (float)0.580688, (float)0.838623,
  2.5063 +   (float)1.331177, (float)1.576782, (float)1.779541,
  2.5064 +   (float)1.160034, (float)1.401978, (float)1.768188,
  2.5065 +   (float)1.161865, (float)1.525146, (float)1.715332,
  2.5066 +   (float)0.759521, (float)0.913940, (float)1.119873,
  2.5067 +   (float)0.947144, (float)1.121338, (float)1.282471,
  2.5068 +   (float)1.015015, (float)1.557007, (float)1.804932,
  2.5069 +   (float)1.172974, (float)1.402100, (float)1.692627,
  2.5070 +   (float)1.087524, (float)1.474243, (float)1.665405,
  2.5071 +   (float)0.899536, (float)1.105225, (float)1.406250,
  2.5072 +   (float)1.148438, (float)1.484741, (float)1.796265,
  2.5073 +   (float)0.785645, (float)1.209839, (float)1.567749,
  2.5074 +   (float)0.867798, (float)1.166504, (float)1.450684,
  2.5075 +   (float)0.922485, (float)1.229858, (float)1.420898,
  2.5076 +   (float)0.791260, (float)1.123291, (float)1.409546,
  2.5077 +   (float)0.788940, (float)0.966064, (float)1.340332,
  2.5078 +   (float)1.051147, (float)1.272827, (float)1.556641,
  2.5079 +   (float)0.866821, (float)1.181152, (float)1.538818,
  2.5080 +   (float)0.906738, (float)1.373535, (float)1.607910,
  2.5081 +   (float)1.244751, (float)1.581421, (float)1.933838,
  2.5082 +   (float)0.913940, (float)1.337280, (float)1.539673,
  2.5083 +   (float)0.680542, (float)0.959229, (float)1.662720,
  2.5084 +   (float)0.887207, (float)1.430542, (float)1.800781,
  2.5085 +   (float)0.912598, (float)1.433594, (float)1.683960,
  2.5086 +   (float)0.860474, (float)1.060303, (float)1.455322,
  2.5087 +   (float)1.005127, (float)1.381104, (float)1.706909,
  2.5088 +   (float)0.800781, (float)1.363892, (float)1.829102,
  2.5089 +   (float)0.781860, (float)1.124390, (float)1.505981,
  2.5090 +   (float)1.003662, (float)1.471436, (float)1.684692,
  2.5091 +   (float)0.981323, (float)1.309570, (float)1.618042,
  2.5092 +   (float)1.228760, (float)1.554321, (float)1.756470,
  2.5093 +   (float)0.734375, (float)0.895752, (float)1.225586,
  2.5094 +   (float)0.841797, (float)1.055664, (float)1.249268,
  2.5095 +   (float)0.920166, (float)1.119385, (float)1.486206,
  2.5096 +   (float)0.894409, (float)1.539063, (float)1.828979,
  2.5097 +   (float)1.283691, (float)1.543335, (float)1.858276,
  2.5098 +
  2.5099 +
  2.5100 +
  2.5101 +Andersen, et al.              Experimental                     [Page 91]
  2.5102 +
  2.5103 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5104 +
  2.5105 +
  2.5106 +   (float)0.676025, (float)0.933105, (float)1.490845,
  2.5107 +   (float)0.821289, (float)1.491821, (float)1.739868,
  2.5108 +   (float)0.923218, (float)1.144653, (float)1.580566,
  2.5109 +   (float)1.057251, (float)1.345581, (float)1.635864,
  2.5110 +   (float)0.888672, (float)1.074951, (float)1.353149,
  2.5111 +   (float)0.942749, (float)1.195435, (float)1.505493,
  2.5112 +   (float)1.492310, (float)1.788086, (float)2.039673,
  2.5113 +   (float)1.070313, (float)1.634399, (float)1.860962,
  2.5114 +   (float)1.253296, (float)1.488892, (float)1.686035,
  2.5115 +   (float)0.647095, (float)0.864014, (float)1.401855,
  2.5116 +   (float)0.866699, (float)1.254883, (float)1.453369,
  2.5117 +   (float)1.063965, (float)1.532593, (float)1.731323,
  2.5118 +   (float)1.167847, (float)1.521484, (float)1.884033,
  2.5119 +   (float)0.956055, (float)1.502075, (float)1.745605,
  2.5120 +   (float)0.928711, (float)1.288574, (float)1.479614,
  2.5121 +   (float)1.088013, (float)1.380737, (float)1.570801,
  2.5122 +   (float)0.905029, (float)1.186768, (float)1.371948,
  2.5123 +   (float)1.057861, (float)1.421021, (float)1.617432,
  2.5124 +   (float)1.108276, (float)1.312500, (float)1.501465,
  2.5125 +   (float)0.979492, (float)1.416992, (float)1.624268,
  2.5126 +   (float)1.276001, (float)1.661011, (float)2.007935,
  2.5127 +   (float)0.993042, (float)1.168579, (float)1.331665,
  2.5128 +   (float)0.778198, (float)0.944946, (float)1.235962,
  2.5129 +   (float)1.223755, (float)1.491333, (float)1.815674,
  2.5130 +   (float)0.852661, (float)1.350464, (float)1.722290,
  2.5131 +   (float)1.134766, (float)1.593140, (float)1.787354,
  2.5132 +   (float)1.051392, (float)1.339722, (float)1.531006,
  2.5133 +   (float)0.803589, (float)1.271240, (float)1.652100,
  2.5134 +   (float)0.755737, (float)1.143555, (float)1.639404,
  2.5135 +   (float)0.700928, (float)0.837280, (float)1.130371,
  2.5136 +   (float)0.942749, (float)1.197876, (float)1.669800,
  2.5137 +   (float)0.993286, (float)1.378296, (float)1.566528,
  2.5138 +   (float)0.801025, (float)1.095337, (float)1.298950,
  2.5139 +   (float)0.739990, (float)1.032959, (float)1.383667,
  2.5140 +   (float)0.845703, (float)1.072266, (float)1.543823,
  2.5141 +   (float)0.915649, (float)1.072266, (float)1.224487,
  2.5142 +   (float)1.021973, (float)1.226196, (float)1.481323,
  2.5143 +   (float)0.999878, (float)1.204102, (float)1.555908,
  2.5144 +   (float)0.722290, (float)0.913940, (float)1.340210,
  2.5145 +   (float)0.673340, (float)0.835938, (float)1.259521,
  2.5146 +   (float)0.832397, (float)1.208374, (float)1.394165,
  2.5147 +   (float)0.962158, (float)1.576172, (float)1.912842,
  2.5148 +   (float)1.166748, (float)1.370850, (float)1.556763,
  2.5149 +   (float)0.946289, (float)1.138550, (float)1.400391,
  2.5150 +   (float)1.035034, (float)1.218262, (float)1.386475,
  2.5151 +   (float)1.393799, (float)1.717773, (float)2.000244,
  2.5152 +   (float)0.972656, (float)1.260986, (float)1.760620,
  2.5153 +   (float)1.028198, (float)1.288452, (float)1.484619,
  2.5154 +
  2.5155 +
  2.5156 +
  2.5157 +Andersen, et al.              Experimental                     [Page 92]
  2.5158 +
  2.5159 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5160 +
  2.5161 +
  2.5162 +   (float)0.773560, (float)1.258057, (float)1.756714,
  2.5163 +   (float)1.080322, (float)1.328003, (float)1.742676,
  2.5164 +   (float)0.823975, (float)1.450806, (float)1.917725,
  2.5165 +   (float)0.859009, (float)1.016602, (float)1.191895,
  2.5166 +   (float)0.843994, (float)1.131104, (float)1.645020,
  2.5167 +   (float)1.189697, (float)1.702759, (float)1.894409,
  2.5168 +   (float)1.346680, (float)1.763184, (float)2.066040,
  2.5169 +   (float)0.980469, (float)1.253784, (float)1.441650,
  2.5170 +   (float)1.338135, (float)1.641968, (float)1.932739,
  2.5171 +   (float)1.223267, (float)1.424194, (float)1.626465,
  2.5172 +   (float)0.765747, (float)1.004150, (float)1.579102,
  2.5173 +   (float)1.042847, (float)1.269165, (float)1.647461,
  2.5174 +   (float)0.968750, (float)1.257568, (float)1.555786,
  2.5175 +   (float)0.826294, (float)0.993408, (float)1.275146,
  2.5176 +   (float)0.742310, (float)0.950439, (float)1.430542,
  2.5177 +   (float)1.054321, (float)1.439819, (float)1.828003,
  2.5178 +   (float)1.072998, (float)1.261719, (float)1.441895,
  2.5179 +   (float)0.859375, (float)1.036377, (float)1.314819,
  2.5180 +   (float)0.895752, (float)1.267212, (float)1.605591,
  2.5181 +   (float)0.805420, (float)0.962891, (float)1.142334,
  2.5182 +   (float)0.795654, (float)1.005493, (float)1.468506,
  2.5183 +   (float)1.105347, (float)1.313843, (float)1.584839,
  2.5184 +   (float)0.792236, (float)1.221802, (float)1.465698,
  2.5185 +   (float)1.170532, (float)1.467651, (float)1.664063,
  2.5186 +   (float)0.838257, (float)1.153198, (float)1.342163,
  2.5187 +   (float)0.968018, (float)1.198242, (float)1.391235,
  2.5188 +   (float)1.250122, (float)1.623535, (float)1.823608,
  2.5189 +   (float)0.711670, (float)1.058350, (float)1.512085,
  2.5190 +   (float)1.204834, (float)1.454468, (float)1.739136,
  2.5191 +   (float)1.137451, (float)1.421753, (float)1.620117,
  2.5192 +   (float)0.820435, (float)1.322754, (float)1.578247,
  2.5193 +   (float)0.798706, (float)1.005005, (float)1.213867,
  2.5194 +   (float)0.980713, (float)1.324951, (float)1.512939,
  2.5195 +   (float)1.112305, (float)1.438843, (float)1.735596,
  2.5196 +   (float)1.135498, (float)1.356689, (float)1.635742,
  2.5197 +   (float)1.101318, (float)1.387451, (float)1.686523,
  2.5198 +   (float)0.849854, (float)1.276978, (float)1.523438,
  2.5199 +   (float)1.377930, (float)1.627563, (float)1.858154,
  2.5200 +   (float)0.884888, (float)1.095459, (float)1.287476,
  2.5201 +   (float)1.289795, (float)1.505859, (float)1.756592,
  2.5202 +   (float)0.817505, (float)1.384155, (float)1.650513,
  2.5203 +   (float)1.446655, (float)1.702148, (float)1.931885,
  2.5204 +   (float)0.835815, (float)1.023071, (float)1.385376,
  2.5205 +   (float)0.916626, (float)1.139038, (float)1.335327,
  2.5206 +   (float)0.980103, (float)1.174072, (float)1.453735,
  2.5207 +   (float)1.705688, (float)2.153809, (float)2.398315, (float)2.743408,
  2.5208 +   (float)1.797119, (float)2.016846, (float)2.445679, (float)2.701904,
  2.5209 +   (float)1.990356, (float)2.219116, (float)2.576416, (float)2.813477,
  2.5210 +
  2.5211 +
  2.5212 +
  2.5213 +Andersen, et al.              Experimental                     [Page 93]
  2.5214 +
  2.5215 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5216 +
  2.5217 +
  2.5218 +   (float)1.849365, (float)2.190918, (float)2.611572, (float)2.835083,
  2.5219 +   (float)1.657959, (float)1.854370, (float)2.159058, (float)2.726196,
  2.5220 +   (float)1.437744, (float)1.897705, (float)2.253174, (float)2.655396,
  2.5221 +   (float)2.028687, (float)2.247314, (float)2.542358, (float)2.875854,
  2.5222 +   (float)1.736938, (float)1.922119, (float)2.185913, (float)2.743408,
  2.5223 +   (float)1.521606, (float)1.870972, (float)2.526855, (float)2.786987,
  2.5224 +   (float)1.841431, (float)2.050659, (float)2.463623, (float)2.857666,
  2.5225 +   (float)1.590088, (float)2.067261, (float)2.427979, (float)2.794434,
  2.5226 +   (float)1.746826, (float)2.057373, (float)2.320190, (float)2.800781,
  2.5227 +   (float)1.734619, (float)1.940552, (float)2.306030, (float)2.826416,
  2.5228 +   (float)1.786255, (float)2.204468, (float)2.457520, (float)2.795288,
  2.5229 +   (float)1.861084, (float)2.170532, (float)2.414551, (float)2.763672,
  2.5230 +   (float)2.001465, (float)2.307617, (float)2.552734, (float)2.811890,
  2.5231 +   (float)1.784424, (float)2.124146, (float)2.381592, (float)2.645508,
  2.5232 +   (float)1.888794, (float)2.135864, (float)2.418579, (float)2.861206,
  2.5233 +   (float)2.301147, (float)2.531250, (float)2.724976, (float)2.913086,
  2.5234 +   (float)1.837769, (float)2.051270, (float)2.261963, (float)2.553223,
  2.5235 +   (float)2.012939, (float)2.221191, (float)2.440186, (float)2.678101,
  2.5236 +   (float)1.429565, (float)1.858276, (float)2.582275, (float)2.845703,
  2.5237 +   (float)1.622803, (float)1.897705, (float)2.367310, (float)2.621094,
  2.5238 +   (float)1.581543, (float)1.960449, (float)2.515869, (float)2.736450,
  2.5239 +   (float)1.419434, (float)1.933960, (float)2.394653, (float)2.746704,
  2.5240 +   (float)1.721924, (float)2.059570, (float)2.421753, (float)2.769653,
  2.5241 +   (float)1.911011, (float)2.220703, (float)2.461060, (float)2.740723,
  2.5242 +   (float)1.581177, (float)1.860840, (float)2.516968, (float)2.874634,
  2.5243 +   (float)1.870361, (float)2.098755, (float)2.432373, (float)2.656494,
  2.5244 +   (float)2.059692, (float)2.279785, (float)2.495605, (float)2.729370,
  2.5245 +   (float)1.815674, (float)2.181519, (float)2.451538, (float)2.680542,
  2.5246 +   (float)1.407959, (float)1.768311, (float)2.343018, (float)2.668091,
  2.5247 +   (float)2.168701, (float)2.394653, (float)2.604736, (float)2.829346,
  2.5248 +   (float)1.636230, (float)1.865723, (float)2.329102, (float)2.824219,
  2.5249 +   (float)1.878906, (float)2.139526, (float)2.376709, (float)2.679810,
  2.5250 +   (float)1.765381, (float)1.971802, (float)2.195435, (float)2.586914,
  2.5251 +   (float)2.164795, (float)2.410889, (float)2.673706, (float)2.903198,
  2.5252 +   (float)2.071899, (float)2.331055, (float)2.645874, (float)2.907104,
  2.5253 +   (float)2.026001, (float)2.311523, (float)2.594849, (float)2.863892,
  2.5254 +   (float)1.948975, (float)2.180786, (float)2.514893, (float)2.797852,
  2.5255 +   (float)1.881836, (float)2.130859, (float)2.478149, (float)2.804199,
  2.5256 +   (float)2.238159, (float)2.452759, (float)2.652832, (float)2.868286,
  2.5257 +   (float)1.897949, (float)2.101685, (float)2.524292, (float)2.880127,
  2.5258 +   (float)1.856445, (float)2.074585, (float)2.541016, (float)2.791748,
  2.5259 +   (float)1.695557, (float)2.199097, (float)2.506226, (float)2.742676,
  2.5260 +   (float)1.612671, (float)1.877075, (float)2.435425, (float)2.732910,
  2.5261 +   (float)1.568848, (float)1.786499, (float)2.194580, (float)2.768555,
  2.5262 +   (float)1.953369, (float)2.164551, (float)2.486938, (float)2.874023,
  2.5263 +   (float)1.388306, (float)1.725342, (float)2.384521, (float)2.771851,
  2.5264 +   (float)2.115356, (float)2.337769, (float)2.592896, (float)2.864014,
  2.5265 +   (float)1.905762, (float)2.111328, (float)2.363525, (float)2.789307,
  2.5266 +
  2.5267 +
  2.5268 +
  2.5269 +Andersen, et al.              Experimental                     [Page 94]
  2.5270 +
  2.5271 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5272 +
  2.5273 +
  2.5274 +   (float)1.882568, (float)2.332031, (float)2.598267, (float)2.827637,
  2.5275 +   (float)1.683594, (float)2.088745, (float)2.361938, (float)2.608643,
  2.5276 +   (float)1.874023, (float)2.182129, (float)2.536133, (float)2.766968,
  2.5277 +   (float)1.861938, (float)2.070435, (float)2.309692, (float)2.700562,
  2.5278 +   (float)1.722168, (float)2.107422, (float)2.477295, (float)2.837646,
  2.5279 +   (float)1.926880, (float)2.184692, (float)2.442627, (float)2.663818,
  2.5280 +   (float)2.123901, (float)2.337280, (float)2.553101, (float)2.777466,
  2.5281 +   (float)1.588135, (float)1.911499, (float)2.212769, (float)2.543945,
  2.5282 +   (float)2.053955, (float)2.370850, (float)2.712158, (float)2.939941,
  2.5283 +   (float)2.210449, (float)2.519653, (float)2.770386, (float)2.958618,
  2.5284 +   (float)2.199463, (float)2.474731, (float)2.718262, (float)2.919922,
  2.5285 +   (float)1.960083, (float)2.175415, (float)2.608032, (float)2.888794,
  2.5286 +   (float)1.953735, (float)2.185181, (float)2.428223, (float)2.809570,
  2.5287 +   (float)1.615234, (float)2.036499, (float)2.576538, (float)2.834595,
  2.5288 +   (float)1.621094, (float)2.028198, (float)2.431030, (float)2.664673,
  2.5289 +   (float)1.824951, (float)2.267456, (float)2.514526, (float)2.747925,
  2.5290 +   (float)1.994263, (float)2.229126, (float)2.475220, (float)2.833984,
  2.5291 +   (float)1.746338, (float)2.011353, (float)2.588257, (float)2.826904,
  2.5292 +   (float)1.562866, (float)2.135986, (float)2.471680, (float)2.687256,
  2.5293 +   (float)1.748901, (float)2.083496, (float)2.460938, (float)2.686279,
  2.5294 +   (float)1.758057, (float)2.131470, (float)2.636597, (float)2.891602,
  2.5295 +   (float)2.071289, (float)2.299072, (float)2.550781, (float)2.814331,
  2.5296 +   (float)1.839600, (float)2.094360, (float)2.496460, (float)2.723999,
  2.5297 +   (float)1.882202, (float)2.088257, (float)2.636841, (float)2.923096,
  2.5298 +   (float)1.957886, (float)2.153198, (float)2.384399, (float)2.615234,
  2.5299 +   (float)1.992920, (float)2.351196, (float)2.654419, (float)2.889771,
  2.5300 +   (float)2.012817, (float)2.262451, (float)2.643799, (float)2.903076,
  2.5301 +   (float)2.025635, (float)2.254761, (float)2.508423, (float)2.784058,
  2.5302 +   (float)2.316040, (float)2.589355, (float)2.794189, (float)2.963623,
  2.5303 +   (float)1.741211, (float)2.279541, (float)2.578491, (float)2.816284,
  2.5304 +   (float)1.845337, (float)2.055786, (float)2.348511, (float)2.822021,
  2.5305 +   (float)1.679932, (float)1.926514, (float)2.499756, (float)2.835693,
  2.5306 +   (float)1.722534, (float)1.946899, (float)2.448486, (float)2.728760,
  2.5307 +   (float)1.829834, (float)2.043213, (float)2.580444, (float)2.867676,
  2.5308 +   (float)1.676636, (float)2.071655, (float)2.322510, (float)2.704834,
  2.5309 +   (float)1.791504, (float)2.113525, (float)2.469727, (float)2.784058,
  2.5310 +   (float)1.977051, (float)2.215088, (float)2.497437, (float)2.726929,
  2.5311 +   (float)1.800171, (float)2.106689, (float)2.357788, (float)2.738892,
  2.5312 +   (float)1.827759, (float)2.170166, (float)2.525879, (float)2.852417,
  2.5313 +   (float)1.918335, (float)2.132813, (float)2.488403, (float)2.728149,
  2.5314 +   (float)1.916748, (float)2.225098, (float)2.542603, (float)2.857666,
  2.5315 +   (float)1.761230, (float)1.976074, (float)2.507446, (float)2.884521,
  2.5316 +   (float)2.053711, (float)2.367432, (float)2.608032, (float)2.837646,
  2.5317 +   (float)1.595337, (float)2.000977, (float)2.307129, (float)2.578247,
  2.5318 +   (float)1.470581, (float)2.031250, (float)2.375854, (float)2.647583,
  2.5319 +   (float)1.801392, (float)2.128052, (float)2.399780, (float)2.822876,
  2.5320 +   (float)1.853638, (float)2.066650, (float)2.429199, (float)2.751465,
  2.5321 +   (float)1.956299, (float)2.163696, (float)2.394775, (float)2.734253,
  2.5322 +
  2.5323 +
  2.5324 +
  2.5325 +Andersen, et al.              Experimental                     [Page 95]
  2.5326 +
  2.5327 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5328 +
  2.5329 +
  2.5330 +   (float)1.963623, (float)2.275757, (float)2.585327, (float)2.865234,
  2.5331 +   (float)1.887451, (float)2.105469, (float)2.331787, (float)2.587402,
  2.5332 +   (float)2.120117, (float)2.443359, (float)2.733887, (float)2.941406,
  2.5333 +   (float)1.506348, (float)1.766968, (float)2.400513, (float)2.851807,
  2.5334 +   (float)1.664551, (float)1.981079, (float)2.375732, (float)2.774414,
  2.5335 +   (float)1.720703, (float)1.978882, (float)2.391479, (float)2.640991,
  2.5336 +   (float)1.483398, (float)1.814819, (float)2.434448, (float)2.722290,
  2.5337 +   (float)1.769043, (float)2.136597, (float)2.563721, (float)2.774414,
  2.5338 +   (float)1.810791, (float)2.049316, (float)2.373901, (float)2.613647,
  2.5339 +   (float)1.788330, (float)2.005981, (float)2.359131, (float)2.723145,
  2.5340 +   (float)1.785156, (float)1.993164, (float)2.399780, (float)2.832520,
  2.5341 +   (float)1.695313, (float)2.022949, (float)2.522583, (float)2.745117,
  2.5342 +   (float)1.584106, (float)1.965576, (float)2.299927, (float)2.715576,
  2.5343 +   (float)1.894897, (float)2.249878, (float)2.655884, (float)2.897705,
  2.5344 +   (float)1.720581, (float)1.995728, (float)2.299438, (float)2.557007,
  2.5345 +   (float)1.619385, (float)2.173950, (float)2.574219, (float)2.787964,
  2.5346 +   (float)1.883179, (float)2.220459, (float)2.474365, (float)2.825073,
  2.5347 +   (float)1.447632, (float)2.045044, (float)2.555542, (float)2.744873,
  2.5348 +   (float)1.502686, (float)2.156616, (float)2.653320, (float)2.846558,
  2.5349 +   (float)1.711548, (float)1.944092, (float)2.282959, (float)2.685791,
  2.5350 +   (float)1.499756, (float)1.867554, (float)2.341064, (float)2.578857,
  2.5351 +   (float)1.916870, (float)2.135132, (float)2.568237, (float)2.826050,
  2.5352 +   (float)1.498047, (float)1.711182, (float)2.223267, (float)2.755127,
  2.5353 +   (float)1.808716, (float)1.997559, (float)2.256470, (float)2.758545,
  2.5354 +   (float)2.088501, (float)2.402710, (float)2.667358, (float)2.890259,
  2.5355 +   (float)1.545044, (float)1.819214, (float)2.324097, (float)2.692993,
  2.5356 +   (float)1.796021, (float)2.012573, (float)2.505737, (float)2.784912,
  2.5357 +   (float)1.786499, (float)2.041748, (float)2.290405, (float)2.650757,
  2.5358 +   (float)1.938232, (float)2.264404, (float)2.529053, (float)2.796143
  2.5359 +   };
  2.5360 +
  2.5361 +A.9.  anaFilter.h
  2.5362 +
  2.5363 +   /******************************************************************
  2.5364 +
  2.5365 +       iLBC Speech Coder ANSI-C Source Code
  2.5366 +
  2.5367 +       anaFilter.h
  2.5368 +
  2.5369 +       Copyright (C) The Internet Society (2004).
  2.5370 +       All Rights Reserved.
  2.5371 +
  2.5372 +   ******************************************************************/
  2.5373 +
  2.5374 +   #ifndef __iLBC_ANAFILTER_H
  2.5375 +   #define __iLBC_ANAFILTER_H
  2.5376 +
  2.5377 +   void anaFilter(
  2.5378 +
  2.5379 +
  2.5380 +
  2.5381 +Andersen, et al.              Experimental                     [Page 96]
  2.5382 +
  2.5383 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5384 +
  2.5385 +
  2.5386 +       float *In,  /* (i) Signal to be filtered */
  2.5387 +       float *a,   /* (i) LP parameters */
  2.5388 +       int len,/* (i) Length of signal */
  2.5389 +       float *Out, /* (o) Filtered signal */
  2.5390 +       float *mem  /* (i/o) Filter state */
  2.5391 +   );
  2.5392 +
  2.5393 +   #endif
  2.5394 +
  2.5395 +A.10.  anaFilter.c
  2.5396 +
  2.5397 +   /******************************************************************
  2.5398 +
  2.5399 +       iLBC Speech Coder ANSI-C Source Code
  2.5400 +
  2.5401 +       anaFilter.c
  2.5402 +
  2.5403 +       Copyright (C) The Internet Society (2004).
  2.5404 +       All Rights Reserved.
  2.5405 +
  2.5406 +   ******************************************************************/
  2.5407 +
  2.5408 +   #include <string.h>
  2.5409 +   #include "iLBC_define.h"
  2.5410 +
  2.5411 +   /*----------------------------------------------------------------*
  2.5412 +    *  LP analysis filter.
  2.5413 +    *---------------------------------------------------------------*/
  2.5414 +
  2.5415 +   void anaFilter(
  2.5416 +       float *In,  /* (i) Signal to be filtered */
  2.5417 +       float *a,   /* (i) LP parameters */
  2.5418 +       int len,/* (i) Length of signal */
  2.5419 +       float *Out, /* (o) Filtered signal */
  2.5420 +       float *mem  /* (i/o) Filter state */
  2.5421 +   ){
  2.5422 +       int i, j;
  2.5423 +       float *po, *pi, *pm, *pa;
  2.5424 +
  2.5425 +       po = Out;
  2.5426 +
  2.5427 +       /* Filter first part using memory from past */
  2.5428 +
  2.5429 +       for (i=0; i<LPC_FILTERORDER; i++) {
  2.5430 +           pi = &In[i];
  2.5431 +           pm = &mem[LPC_FILTERORDER-1];
  2.5432 +           pa = a;
  2.5433 +           *po=0.0;
  2.5434 +
  2.5435 +
  2.5436 +
  2.5437 +Andersen, et al.              Experimental                     [Page 97]
  2.5438 +
  2.5439 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5440 +
  2.5441 +
  2.5442 +           for (j=0; j<=i; j++) {
  2.5443 +               *po+=(*pa++)*(*pi--);
  2.5444 +           }
  2.5445 +           for (j=i+1; j<LPC_FILTERORDER+1; j++) {
  2.5446 +
  2.5447 +               *po+=(*pa++)*(*pm--);
  2.5448 +           }
  2.5449 +           po++;
  2.5450 +       }
  2.5451 +
  2.5452 +       /* Filter last part where the state is entirely
  2.5453 +          in the input vector */
  2.5454 +
  2.5455 +       for (i=LPC_FILTERORDER; i<len; i++) {
  2.5456 +           pi = &In[i];
  2.5457 +           pa = a;
  2.5458 +           *po=0.0;
  2.5459 +           for (j=0; j<LPC_FILTERORDER+1; j++) {
  2.5460 +               *po+=(*pa++)*(*pi--);
  2.5461 +           }
  2.5462 +           po++;
  2.5463 +       }
  2.5464 +
  2.5465 +       /* Update state vector */
  2.5466 +
  2.5467 +       memcpy(mem, &In[len-LPC_FILTERORDER],
  2.5468 +           LPC_FILTERORDER*sizeof(float));
  2.5469 +   }
  2.5470 +
  2.5471 +A.11.  createCB.h
  2.5472 +
  2.5473 +   /******************************************************************
  2.5474 +
  2.5475 +       iLBC Speech Coder ANSI-C Source Code
  2.5476 +
  2.5477 +       createCB.h
  2.5478 +
  2.5479 +       Copyright (C) The Internet Society (2004).
  2.5480 +       All Rights Reserved.
  2.5481 +
  2.5482 +   ******************************************************************/
  2.5483 +
  2.5484 +   #ifndef __iLBC_CREATECB_H
  2.5485 +   #define __iLBC_CREATECB_H
  2.5486 +
  2.5487 +   void filteredCBvecs(
  2.5488 +       float *cbvectors,   /* (o) Codebook vector for the
  2.5489 +                                  higher section */
  2.5490 +
  2.5491 +
  2.5492 +
  2.5493 +Andersen, et al.              Experimental                     [Page 98]
  2.5494 +
  2.5495 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5496 +
  2.5497 +
  2.5498 +       float *mem,         /* (i) Buffer to create codebook
  2.5499 +                                  vectors from */
  2.5500 +       int lMem        /* (i) Length of buffer */
  2.5501 +   );
  2.5502 +
  2.5503 +   void searchAugmentedCB(
  2.5504 +       int low,        /* (i) Start index for the search */
  2.5505 +       int high,           /* (i) End index for the search */
  2.5506 +       int stage,          /* (i) Current stage */
  2.5507 +       int startIndex,     /* (i) CB index for the first
  2.5508 +                                  augmented vector */
  2.5509 +       float *target,      /* (i) Target vector for encoding */
  2.5510 +       float *buffer,      /* (i) Pointer to the end of the
  2.5511 +                                  buffer for augmented codebook
  2.5512 +                                  construction */
  2.5513 +       float *max_measure, /* (i/o) Currently maximum measure */
  2.5514 +       int *best_index,/* (o) Currently the best index */
  2.5515 +       float *gain,    /* (o) Currently the best gain */
  2.5516 +       float *energy,      /* (o) Energy of augmented
  2.5517 +                                  codebook vectors */
  2.5518 +       float *invenergy/* (o) Inv energy of aug codebook
  2.5519 +                                  vectors */
  2.5520 +   );
  2.5521 +
  2.5522 +   void createAugmentedVec(
  2.5523 +       int index,          /* (i) Index for the aug vector
  2.5524 +                                  to be created */
  2.5525 +       float *buffer,      /* (i) Pointer to the end of the
  2.5526 +                                  buffer for augmented codebook
  2.5527 +                                  construction */
  2.5528 +       float *cbVec    /* (o) The construced codebook vector */
  2.5529 +   );
  2.5530 +
  2.5531 +   #endif
  2.5532 +
  2.5533 +A.12.  createCB.c
  2.5534 +
  2.5535 +
  2.5536 +   /******************************************************************
  2.5537 +
  2.5538 +       iLBC Speech Coder ANSI-C Source Code
  2.5539 +
  2.5540 +       createCB.c
  2.5541 +
  2.5542 +       Copyright (C) The Internet Society (2004).
  2.5543 +       All Rights Reserved.
  2.5544 +
  2.5545 +   ******************************************************************/
  2.5546 +
  2.5547 +
  2.5548 +
  2.5549 +Andersen, et al.              Experimental                     [Page 99]
  2.5550 +
  2.5551 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5552 +
  2.5553 +
  2.5554 +   #include "iLBC_define.h"
  2.5555 +   #include "constants.h"
  2.5556 +   #include <string.h>
  2.5557 +   #include <math.h>
  2.5558 +
  2.5559 +   /*----------------------------------------------------------------*
  2.5560 +    *  Construct an additional codebook vector by filtering the
  2.5561 +    *  initial codebook buffer. This vector is then used to expand
  2.5562 +    *  the codebook with an additional section.
  2.5563 +    *---------------------------------------------------------------*/
  2.5564 +
  2.5565 +   void filteredCBvecs(
  2.5566 +       float *cbvectors,   /* (o) Codebook vectors for the
  2.5567 +                                  higher section */
  2.5568 +       float *mem,         /* (i) Buffer to create codebook
  2.5569 +                                  vector from */
  2.5570 +       int lMem        /* (i) Length of buffer */
  2.5571 +   ){
  2.5572 +       int j, k;
  2.5573 +       float *pp, *pp1;
  2.5574 +       float tempbuff2[CB_MEML+CB_FILTERLEN];
  2.5575 +       float *pos;
  2.5576 +
  2.5577 +       memset(tempbuff2, 0, (CB_HALFFILTERLEN-1)*sizeof(float));
  2.5578 +       memcpy(&tempbuff2[CB_HALFFILTERLEN-1], mem, lMem*sizeof(float));
  2.5579 +       memset(&tempbuff2[lMem+CB_HALFFILTERLEN-1], 0,
  2.5580 +           (CB_HALFFILTERLEN+1)*sizeof(float));
  2.5581 +
  2.5582 +       /* Create codebook vector for higher section by filtering */
  2.5583 +
  2.5584 +       /* do filtering */
  2.5585 +       pos=cbvectors;
  2.5586 +       memset(pos, 0, lMem*sizeof(float));
  2.5587 +       for (k=0; k<lMem; k++) {
  2.5588 +           pp=&tempbuff2[k];
  2.5589 +           pp1=&cbfiltersTbl[CB_FILTERLEN-1];
  2.5590 +           for (j=0;j<CB_FILTERLEN;j++) {
  2.5591 +               (*pos)+=(*pp++)*(*pp1--);
  2.5592 +           }
  2.5593 +           pos++;
  2.5594 +       }
  2.5595 +   }
  2.5596 +
  2.5597 +   /*----------------------------------------------------------------*
  2.5598 +    *  Search the augmented part of the codebook to find the best
  2.5599 +    *  measure.
  2.5600 +    *----------------------------------------------------------------*/
  2.5601 +
  2.5602 +
  2.5603 +
  2.5604 +
  2.5605 +Andersen, et al.              Experimental                    [Page 100]
  2.5606 +
  2.5607 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5608 +
  2.5609 +
  2.5610 +   void searchAugmentedCB(
  2.5611 +       int low,        /* (i) Start index for the search */
  2.5612 +       int high,           /* (i) End index for the search */
  2.5613 +       int stage,          /* (i) Current stage */
  2.5614 +       int startIndex,     /* (i) Codebook index for the first
  2.5615 +                                  aug vector */
  2.5616 +       float *target,      /* (i) Target vector for encoding */
  2.5617 +       float *buffer,      /* (i) Pointer to the end of the buffer for
  2.5618 +                                  augmented codebook construction */
  2.5619 +       float *max_measure, /* (i/o) Currently maximum measure */
  2.5620 +       int *best_index,/* (o) Currently the best index */
  2.5621 +       float *gain,    /* (o) Currently the best gain */
  2.5622 +       float *energy,      /* (o) Energy of augmented codebook
  2.5623 +                                  vectors */
  2.5624 +       float *invenergy/* (o) Inv energy of augmented codebook
  2.5625 +                                  vectors */
  2.5626 +   ) {
  2.5627 +       int icount, ilow, j, tmpIndex;
  2.5628 +       float *pp, *ppo, *ppi, *ppe, crossDot, alfa;
  2.5629 +       float weighted, measure, nrjRecursive;
  2.5630 +       float ftmp;
  2.5631 +
  2.5632 +       /* Compute the energy for the first (low-5)
  2.5633 +          noninterpolated samples */
  2.5634 +       nrjRecursive = (float) 0.0;
  2.5635 +       pp = buffer - low + 1;
  2.5636 +       for (j=0; j<(low-5); j++) {
  2.5637 +           nrjRecursive += ( (*pp)*(*pp) );
  2.5638 +           pp++;
  2.5639 +       }
  2.5640 +       ppe = buffer - low;
  2.5641 +
  2.5642 +
  2.5643 +       for (icount=low; icount<=high; icount++) {
  2.5644 +
  2.5645 +           /* Index of the codebook vector used for retrieving
  2.5646 +              energy values */
  2.5647 +           tmpIndex = startIndex+icount-20;
  2.5648 +
  2.5649 +           ilow = icount-4;
  2.5650 +
  2.5651 +           /* Update the energy recursively to save complexity */
  2.5652 +           nrjRecursive = nrjRecursive + (*ppe)*(*ppe);
  2.5653 +           ppe--;
  2.5654 +           energy[tmpIndex] = nrjRecursive;
  2.5655 +
  2.5656 +           /* Compute cross dot product for the first (low-5)
  2.5657 +              samples */
  2.5658 +
  2.5659 +
  2.5660 +
  2.5661 +Andersen, et al.              Experimental                    [Page 101]
  2.5662 +
  2.5663 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5664 +
  2.5665 +
  2.5666 +           crossDot = (float) 0.0;
  2.5667 +           pp = buffer-icount;
  2.5668 +           for (j=0; j<ilow; j++) {
  2.5669 +               crossDot += target[j]*(*pp++);
  2.5670 +           }
  2.5671 +
  2.5672 +           /* interpolation */
  2.5673 +           alfa = (float) 0.2;
  2.5674 +           ppo = buffer-4;
  2.5675 +           ppi = buffer-icount-4;
  2.5676 +           for (j=ilow; j<icount; j++) {
  2.5677 +               weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);
  2.5678 +               ppo++;
  2.5679 +               ppi++;
  2.5680 +               energy[tmpIndex] += weighted*weighted;
  2.5681 +               crossDot += target[j]*weighted;
  2.5682 +               alfa += (float)0.2;
  2.5683 +           }
  2.5684 +
  2.5685 +           /* Compute energy and cross dot product for the
  2.5686 +              remaining samples */
  2.5687 +           pp = buffer - icount;
  2.5688 +           for (j=icount; j<SUBL; j++) {
  2.5689 +               energy[tmpIndex] += (*pp)*(*pp);
  2.5690 +               crossDot += target[j]*(*pp++);
  2.5691 +           }
  2.5692 +
  2.5693 +           if (energy[tmpIndex]>0.0) {
  2.5694 +               invenergy[tmpIndex]=(float)1.0/(energy[tmpIndex]+EPS);
  2.5695 +           } else {
  2.5696 +               invenergy[tmpIndex] = (float) 0.0;
  2.5697 +           }
  2.5698 +
  2.5699 +           if (stage==0) {
  2.5700 +               measure = (float)-10000000.0;
  2.5701 +
  2.5702 +               if (crossDot > 0.0) {
  2.5703 +                   measure = crossDot*crossDot*invenergy[tmpIndex];
  2.5704 +               }
  2.5705 +           }
  2.5706 +           else {
  2.5707 +               measure = crossDot*crossDot*invenergy[tmpIndex];
  2.5708 +           }
  2.5709 +
  2.5710 +           /* check if measure is better */
  2.5711 +           ftmp = crossDot*invenergy[tmpIndex];
  2.5712 +
  2.5713 +           if ((measure>*max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
  2.5714 +
  2.5715 +
  2.5716 +
  2.5717 +Andersen, et al.              Experimental                    [Page 102]
  2.5718 +
  2.5719 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5720 +
  2.5721 +
  2.5722 +               *best_index = tmpIndex;
  2.5723 +               *max_measure = measure;
  2.5724 +               *gain = ftmp;
  2.5725 +           }
  2.5726 +       }
  2.5727 +   }
  2.5728 +
  2.5729 +
  2.5730 +   /*----------------------------------------------------------------*
  2.5731 +    *  Recreate a specific codebook vector from the augmented part.
  2.5732 +    *
  2.5733 +    *----------------------------------------------------------------*/
  2.5734 +
  2.5735 +   void createAugmentedVec(
  2.5736 +       int index,      /* (i) Index for the augmented vector
  2.5737 +                              to be created */
  2.5738 +       float *buffer,  /* (i) Pointer to the end of the buffer for
  2.5739 +                              augmented codebook construction */
  2.5740 +       float *cbVec/* (o) The construced codebook vector */
  2.5741 +   ) {
  2.5742 +       int ilow, j;
  2.5743 +       float *pp, *ppo, *ppi, alfa, alfa1, weighted;
  2.5744 +
  2.5745 +       ilow = index-5;
  2.5746 +
  2.5747 +       /* copy the first noninterpolated part */
  2.5748 +
  2.5749 +       pp = buffer-index;
  2.5750 +       memcpy(cbVec,pp,sizeof(float)*index);
  2.5751 +
  2.5752 +       /* interpolation */
  2.5753 +
  2.5754 +       alfa1 = (float)0.2;
  2.5755 +       alfa = 0.0;
  2.5756 +       ppo = buffer-5;
  2.5757 +       ppi = buffer-index-5;
  2.5758 +       for (j=ilow; j<index; j++) {
  2.5759 +           weighted = ((float)1.0-alfa)*(*ppo)+alfa*(*ppi);
  2.5760 +           ppo++;
  2.5761 +           ppi++;
  2.5762 +           cbVec[j] = weighted;
  2.5763 +           alfa += alfa1;
  2.5764 +       }
  2.5765 +
  2.5766 +       /* copy the second noninterpolated part */
  2.5767 +
  2.5768 +       pp = buffer - index;
  2.5769 +       memcpy(cbVec+index,pp,sizeof(float)*(SUBL-index));
  2.5770 +
  2.5771 +
  2.5772 +
  2.5773 +Andersen, et al.              Experimental                    [Page 103]
  2.5774 +
  2.5775 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5776 +
  2.5777 +
  2.5778 +   }
  2.5779 +
  2.5780 +A.13.  doCPLC.h
  2.5781 +
  2.5782 +   /******************************************************************
  2.5783 +
  2.5784 +       iLBC Speech Coder ANSI-C Source Code
  2.5785 +
  2.5786 +       doCPLC.h
  2.5787 +
  2.5788 +       Copyright (C) The Internet Society (2004).
  2.5789 +       All Rights Reserved.
  2.5790 +
  2.5791 +   ******************************************************************/
  2.5792 +
  2.5793 +   #ifndef __iLBC_DOLPC_H
  2.5794 +   #define __iLBC_DOLPC_H
  2.5795 +
  2.5796 +   void doThePLC(
  2.5797 +       float *PLCresidual, /* (o) concealed residual */
  2.5798 +       float *PLClpc,      /* (o) concealed LP parameters */
  2.5799 +       int PLI,        /* (i) packet loss indicator
  2.5800 +                                  0 - no PL, 1 = PL */
  2.5801 +       float *decresidual, /* (i) decoded residual */
  2.5802 +       float *lpc,         /* (i) decoded LPC (only used for no PL) */
  2.5803 +       int inlag,          /* (i) pitch lag */
  2.5804 +       iLBC_Dec_Inst_t *iLBCdec_inst
  2.5805 +                           /* (i/o) decoder instance */
  2.5806 +   );
  2.5807 +
  2.5808 +   #endif
  2.5809 +
  2.5810 +A.14.  doCPLC.c
  2.5811 +
  2.5812 +   /******************************************************************
  2.5813 +
  2.5814 +       iLBC Speech Coder ANSI-C Source Code
  2.5815 +
  2.5816 +       doCPLC.c
  2.5817 +
  2.5818 +       Copyright (C) The Internet Society (2004).
  2.5819 +       All Rights Reserved.
  2.5820 +
  2.5821 +   ******************************************************************/
  2.5822 +
  2.5823 +   #include <math.h>
  2.5824 +   #include <string.h>
  2.5825 +   #include <stdio.h>
  2.5826 +
  2.5827 +
  2.5828 +
  2.5829 +Andersen, et al.              Experimental                    [Page 104]
  2.5830 +
  2.5831 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5832 +
  2.5833 +
  2.5834 +   #include "iLBC_define.h"
  2.5835 +
  2.5836 +   /*----------------------------------------------------------------*
  2.5837 +    *  Compute cross correlation and pitch gain for pitch prediction
  2.5838 +    *  of last subframe at given lag.
  2.5839 +    *---------------------------------------------------------------*/
  2.5840 +
  2.5841 +   void compCorr(
  2.5842 +       float *cc,      /* (o) cross correlation coefficient */
  2.5843 +       float *gc,      /* (o) gain */
  2.5844 +       float *pm,
  2.5845 +       float *buffer,  /* (i) signal buffer */
  2.5846 +       int lag,    /* (i) pitch lag */
  2.5847 +       int bLen,       /* (i) length of buffer */
  2.5848 +       int sRange      /* (i) correlation search length */
  2.5849 +   ){
  2.5850 +       int i;
  2.5851 +       float ftmp1, ftmp2, ftmp3;
  2.5852 +
  2.5853 +       /* Guard against getting outside buffer */
  2.5854 +       if ((bLen-sRange-lag)<0) {
  2.5855 +           sRange=bLen-lag;
  2.5856 +       }
  2.5857 +
  2.5858 +       ftmp1 = 0.0;
  2.5859 +       ftmp2 = 0.0;
  2.5860 +       ftmp3 = 0.0;
  2.5861 +       for (i=0; i<sRange; i++) {
  2.5862 +           ftmp1 += buffer[bLen-sRange+i] *
  2.5863 +               buffer[bLen-sRange+i-lag];
  2.5864 +           ftmp2 += buffer[bLen-sRange+i-lag] *
  2.5865 +                   buffer[bLen-sRange+i-lag];
  2.5866 +           ftmp3 += buffer[bLen-sRange+i] *
  2.5867 +                   buffer[bLen-sRange+i];
  2.5868 +       }
  2.5869 +
  2.5870 +       if (ftmp2 > 0.0) {
  2.5871 +           *cc = ftmp1*ftmp1/ftmp2;
  2.5872 +           *gc = (float)fabs(ftmp1/ftmp2);
  2.5873 +           *pm=(float)fabs(ftmp1)/
  2.5874 +               ((float)sqrt(ftmp2)*(float)sqrt(ftmp3));
  2.5875 +       }
  2.5876 +       else {
  2.5877 +           *cc = 0.0;
  2.5878 +           *gc = 0.0;
  2.5879 +           *pm=0.0;
  2.5880 +       }
  2.5881 +   }
  2.5882 +
  2.5883 +
  2.5884 +
  2.5885 +Andersen, et al.              Experimental                    [Page 105]
  2.5886 +
  2.5887 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5888 +
  2.5889 +
  2.5890 +   /*----------------------------------------------------------------*
  2.5891 +    *  Packet loss concealment routine. Conceals a residual signal
  2.5892 +    *  and LP parameters. If no packet loss, update state.
  2.5893 +    *---------------------------------------------------------------*/
  2.5894 +
  2.5895 +   void doThePLC(
  2.5896 +       float *PLCresidual, /* (o) concealed residual */
  2.5897 +       float *PLClpc,      /* (o) concealed LP parameters */
  2.5898 +       int PLI,        /* (i) packet loss indicator
  2.5899 +                                  0 - no PL, 1 = PL */
  2.5900 +       float *decresidual, /* (i) decoded residual */
  2.5901 +       float *lpc,         /* (i) decoded LPC (only used for no PL) */
  2.5902 +       int inlag,          /* (i) pitch lag */
  2.5903 +       iLBC_Dec_Inst_t *iLBCdec_inst
  2.5904 +                           /* (i/o) decoder instance */
  2.5905 +   ){
  2.5906 +       int lag=20, randlag;
  2.5907 +       float gain, maxcc;
  2.5908 +       float use_gain;
  2.5909 +       float gain_comp, maxcc_comp, per, max_per;
  2.5910 +       int i, pick, use_lag;
  2.5911 +       float ftmp, randvec[BLOCKL_MAX], pitchfact, energy;
  2.5912 +
  2.5913 +       /* Packet Loss */
  2.5914 +
  2.5915 +       if (PLI == 1) {
  2.5916 +
  2.5917 +           iLBCdec_inst->consPLICount += 1;
  2.5918 +
  2.5919 +           /* if previous frame not lost,
  2.5920 +              determine pitch pred. gain */
  2.5921 +
  2.5922 +           if (iLBCdec_inst->prevPLI != 1) {
  2.5923 +
  2.5924 +               /* Search around the previous lag to find the
  2.5925 +                  best pitch period */
  2.5926 +
  2.5927 +               lag=inlag-3;
  2.5928 +               compCorr(&maxcc, &gain, &max_per,
  2.5929 +                   iLBCdec_inst->prevResidual,
  2.5930 +                   lag, iLBCdec_inst->blockl, 60);
  2.5931 +               for (i=inlag-2;i<=inlag+3;i++) {
  2.5932 +                   compCorr(&maxcc_comp, &gain_comp, &per,
  2.5933 +                       iLBCdec_inst->prevResidual,
  2.5934 +                       i, iLBCdec_inst->blockl, 60);
  2.5935 +
  2.5936 +                   if (maxcc_comp>maxcc) {
  2.5937 +                       maxcc=maxcc_comp;
  2.5938 +
  2.5939 +
  2.5940 +
  2.5941 +Andersen, et al.              Experimental                    [Page 106]
  2.5942 +
  2.5943 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.5944 +
  2.5945 +
  2.5946 +                       gain=gain_comp;
  2.5947 +                       lag=i;
  2.5948 +                       max_per=per;
  2.5949 +                   }
  2.5950 +               }
  2.5951 +
  2.5952 +           }
  2.5953 +
  2.5954 +           /* previous frame lost, use recorded lag and periodicity */
  2.5955 +
  2.5956 +           else {
  2.5957 +               lag=iLBCdec_inst->prevLag;
  2.5958 +               max_per=iLBCdec_inst->per;
  2.5959 +           }
  2.5960 +
  2.5961 +           /* downscaling */
  2.5962 +
  2.5963 +           use_gain=1.0;
  2.5964 +           if (iLBCdec_inst->consPLICount*iLBCdec_inst->blockl>320)
  2.5965 +               use_gain=(float)0.9;
  2.5966 +           else if (iLBCdec_inst->consPLICount*
  2.5967 +                           iLBCdec_inst->blockl>2*320)
  2.5968 +               use_gain=(float)0.7;
  2.5969 +           else if (iLBCdec_inst->consPLICount*
  2.5970 +                           iLBCdec_inst->blockl>3*320)
  2.5971 +               use_gain=(float)0.5;
  2.5972 +           else if (iLBCdec_inst->consPLICount*
  2.5973 +                           iLBCdec_inst->blockl>4*320)
  2.5974 +               use_gain=(float)0.0;
  2.5975 +
  2.5976 +           /* mix noise and pitch repeatition */
  2.5977 +           ftmp=(float)sqrt(max_per);
  2.5978 +           if (ftmp>(float)0.7)
  2.5979 +               pitchfact=(float)1.0;
  2.5980 +           else if (ftmp>(float)0.4)
  2.5981 +               pitchfact=(ftmp-(float)0.4)/((float)0.7-(float)0.4);
  2.5982 +           else
  2.5983 +               pitchfact=0.0;
  2.5984 +
  2.5985 +
  2.5986 +           /* avoid repetition of same pitch cycle */
  2.5987 +           use_lag=lag;
  2.5988 +           if (lag<80) {
  2.5989 +               use_lag=2*lag;
  2.5990 +           }
  2.5991 +
  2.5992 +           /* compute concealed residual */
  2.5993 +
  2.5994 +
  2.5995 +
  2.5996 +
  2.5997 +Andersen, et al.              Experimental                    [Page 107]
  2.5998 +
  2.5999 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6000 +
  2.6001 +
  2.6002 +           energy = 0.0;
  2.6003 +           for (i=0; i<iLBCdec_inst->blockl; i++) {
  2.6004 +
  2.6005 +               /* noise component */
  2.6006 +
  2.6007 +               iLBCdec_inst->seed=(iLBCdec_inst->seed*69069L+1) &
  2.6008 +                   (0x80000000L-1);
  2.6009 +               randlag = 50 + ((signed long) iLBCdec_inst->seed)%70;
  2.6010 +               pick = i - randlag;
  2.6011 +
  2.6012 +               if (pick < 0) {
  2.6013 +                   randvec[i] =
  2.6014 +                       iLBCdec_inst->prevResidual[
  2.6015 +                                   iLBCdec_inst->blockl+pick];
  2.6016 +               } else {
  2.6017 +                   randvec[i] =  randvec[pick];
  2.6018 +               }
  2.6019 +
  2.6020 +               /* pitch repeatition component */
  2.6021 +               pick = i - use_lag;
  2.6022 +
  2.6023 +               if (pick < 0) {
  2.6024 +                   PLCresidual[i] =
  2.6025 +                       iLBCdec_inst->prevResidual[
  2.6026 +                                   iLBCdec_inst->blockl+pick];
  2.6027 +               } else {
  2.6028 +                   PLCresidual[i] = PLCresidual[pick];
  2.6029 +               }
  2.6030 +
  2.6031 +               /* mix random and periodicity component */
  2.6032 +
  2.6033 +               if (i<80)
  2.6034 +                   PLCresidual[i] = use_gain*(pitchfact *
  2.6035 +                               PLCresidual[i] +
  2.6036 +                               ((float)1.0 - pitchfact) * randvec[i]);
  2.6037 +               else if (i<160)
  2.6038 +                   PLCresidual[i] = (float)0.95*use_gain*(pitchfact *
  2.6039 +                               PLCresidual[i] +
  2.6040 +                               ((float)1.0 - pitchfact) * randvec[i]);
  2.6041 +               else
  2.6042 +                   PLCresidual[i] = (float)0.9*use_gain*(pitchfact *
  2.6043 +                               PLCresidual[i] +
  2.6044 +                               ((float)1.0 - pitchfact) * randvec[i]);
  2.6045 +
  2.6046 +               energy += PLCresidual[i] * PLCresidual[i];
  2.6047 +           }
  2.6048 +
  2.6049 +           /* less than 30 dB, use only noise */
  2.6050 +
  2.6051 +
  2.6052 +
  2.6053 +Andersen, et al.              Experimental                    [Page 108]
  2.6054 +
  2.6055 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6056 +
  2.6057 +
  2.6058 +
  2.6059 +           if (sqrt(energy/(float)iLBCdec_inst->blockl) < 30.0) {
  2.6060 +               gain=0.0;
  2.6061 +               for (i=0; i<iLBCdec_inst->blockl; i++) {
  2.6062 +                   PLCresidual[i] = randvec[i];
  2.6063 +               }
  2.6064 +           }
  2.6065 +
  2.6066 +           /* use old LPC */
  2.6067 +
  2.6068 +           memcpy(PLClpc,iLBCdec_inst->prevLpc,
  2.6069 +               (LPC_FILTERORDER+1)*sizeof(float));
  2.6070 +
  2.6071 +       }
  2.6072 +
  2.6073 +       /* no packet loss, copy input */
  2.6074 +
  2.6075 +       else {
  2.6076 +           memcpy(PLCresidual, decresidual,
  2.6077 +               iLBCdec_inst->blockl*sizeof(float));
  2.6078 +           memcpy(PLClpc, lpc, (LPC_FILTERORDER+1)*sizeof(float));
  2.6079 +           iLBCdec_inst->consPLICount = 0;
  2.6080 +       }
  2.6081 +
  2.6082 +       /* update state */
  2.6083 +
  2.6084 +       if (PLI) {
  2.6085 +           iLBCdec_inst->prevLag = lag;
  2.6086 +           iLBCdec_inst->per=max_per;
  2.6087 +       }
  2.6088 +
  2.6089 +       iLBCdec_inst->prevPLI = PLI;
  2.6090 +       memcpy(iLBCdec_inst->prevLpc, PLClpc,
  2.6091 +           (LPC_FILTERORDER+1)*sizeof(float));
  2.6092 +       memcpy(iLBCdec_inst->prevResidual, PLCresidual,
  2.6093 +           iLBCdec_inst->blockl*sizeof(float));
  2.6094 +   }
  2.6095 +
  2.6096 +A.15.  enhancer.h
  2.6097 +
  2.6098 +   /******************************************************************
  2.6099 +
  2.6100 +       iLBC Speech Coder ANSI-C Source Code
  2.6101 +
  2.6102 +       enhancer.h
  2.6103 +
  2.6104 +       Copyright (C) The Internet Society (2004).
  2.6105 +       All Rights Reserved.
  2.6106 +
  2.6107 +
  2.6108 +
  2.6109 +Andersen, et al.              Experimental                    [Page 109]
  2.6110 +
  2.6111 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6112 +
  2.6113 +
  2.6114 +   ******************************************************************/
  2.6115 +
  2.6116 +   #ifndef __ENHANCER_H
  2.6117 +   #define __ENHANCER_H
  2.6118 +
  2.6119 +   #include "iLBC_define.h"
  2.6120 +
  2.6121 +   float xCorrCoef(
  2.6122 +       float *target,      /* (i) first array */
  2.6123 +       float *regressor,   /* (i) second array */
  2.6124 +       int subl        /* (i) dimension arrays */
  2.6125 +   );
  2.6126 +
  2.6127 +   int enhancerInterface(
  2.6128 +       float *out,         /* (o) the enhanced recidual signal */
  2.6129 +       float *in,          /* (i) the recidual signal to enhance */
  2.6130 +       iLBC_Dec_Inst_t *iLBCdec_inst
  2.6131 +                           /* (i/o) the decoder state structure */
  2.6132 +   );
  2.6133 +
  2.6134 +   #endif
  2.6135 +
  2.6136 +A.16.  enhancer.c
  2.6137 +
  2.6138 +   /******************************************************************
  2.6139 +
  2.6140 +       iLBC Speech Coder ANSI-C Source Code
  2.6141 +
  2.6142 +       enhancer.c
  2.6143 +
  2.6144 +       Copyright (C) The Internet Society (2004).
  2.6145 +       All Rights Reserved.
  2.6146 +
  2.6147 +   ******************************************************************/
  2.6148 +
  2.6149 +   #include <math.h>
  2.6150 +   #include <string.h>
  2.6151 +   #include "iLBC_define.h"
  2.6152 +   #include "constants.h"
  2.6153 +   #include "filter.h"
  2.6154 +
  2.6155 +   /*----------------------------------------------------------------*
  2.6156 +    * Find index in array such that the array element with said
  2.6157 +    * index is the element of said array closest to "value"
  2.6158 +    * according to the squared-error criterion
  2.6159 +    *---------------------------------------------------------------*/
  2.6160 +
  2.6161 +   void NearestNeighbor(
  2.6162 +
  2.6163 +
  2.6164 +
  2.6165 +Andersen, et al.              Experimental                    [Page 110]
  2.6166 +
  2.6167 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6168 +
  2.6169 +
  2.6170 +       int   *index,   /* (o) index of array element closest
  2.6171 +                              to value */
  2.6172 +       float *array,   /* (i) data array */
  2.6173 +       float value,/* (i) value */
  2.6174 +       int arlength/* (i) dimension of data array */
  2.6175 +   ){
  2.6176 +       int i;
  2.6177 +       float bestcrit,crit;
  2.6178 +
  2.6179 +       crit=array[0]-value;
  2.6180 +       bestcrit=crit*crit;
  2.6181 +       *index=0;
  2.6182 +       for (i=1; i<arlength; i++) {
  2.6183 +           crit=array[i]-value;
  2.6184 +           crit=crit*crit;
  2.6185 +
  2.6186 +           if (crit<bestcrit) {
  2.6187 +               bestcrit=crit;
  2.6188 +               *index=i;
  2.6189 +           }
  2.6190 +       }
  2.6191 +   }
  2.6192 +
  2.6193 +   /*----------------------------------------------------------------*
  2.6194 +    * compute cross correlation between sequences
  2.6195 +    *---------------------------------------------------------------*/
  2.6196 +
  2.6197 +   void mycorr1(
  2.6198 +       float* corr,    /* (o) correlation of seq1 and seq2 */
  2.6199 +       float* seq1,    /* (i) first sequence */
  2.6200 +       int dim1,           /* (i) dimension first seq1 */
  2.6201 +       const float *seq2,  /* (i) second sequence */
  2.6202 +       int dim2        /* (i) dimension seq2 */
  2.6203 +   ){
  2.6204 +       int i,j;
  2.6205 +
  2.6206 +       for (i=0; i<=dim1-dim2; i++) {
  2.6207 +           corr[i]=0.0;
  2.6208 +           for (j=0; j<dim2; j++) {
  2.6209 +               corr[i] += seq1[i+j] * seq2[j];
  2.6210 +           }
  2.6211 +       }
  2.6212 +   }
  2.6213 +
  2.6214 +   /*----------------------------------------------------------------*
  2.6215 +    * upsample finite array assuming zeros outside bounds
  2.6216 +    *---------------------------------------------------------------*/
  2.6217 +
  2.6218 +
  2.6219 +
  2.6220 +
  2.6221 +Andersen, et al.              Experimental                    [Page 111]
  2.6222 +
  2.6223 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6224 +
  2.6225 +
  2.6226 +   void enh_upsample(
  2.6227 +       float* useq1,   /* (o) upsampled output sequence */
  2.6228 +       float* seq1,/* (i) unupsampled sequence */
  2.6229 +       int dim1,       /* (i) dimension seq1 */
  2.6230 +       int hfl         /* (i) polyphase filter length=2*hfl+1 */
  2.6231 +   ){
  2.6232 +       float *pu,*ps;
  2.6233 +       int i,j,k,q,filterlength,hfl2;
  2.6234 +       const float *polyp[ENH_UPS0]; /* pointers to
  2.6235 +                                        polyphase columns */
  2.6236 +       const float *pp;
  2.6237 +
  2.6238 +       /* define pointers for filter */
  2.6239 +
  2.6240 +       filterlength=2*hfl+1;
  2.6241 +
  2.6242 +       if ( filterlength > dim1 ) {
  2.6243 +           hfl2=(int) (dim1/2);
  2.6244 +           for (j=0; j<ENH_UPS0; j++) {
  2.6245 +               polyp[j]=polyphaserTbl+j*filterlength+hfl-hfl2;
  2.6246 +           }
  2.6247 +           hfl=hfl2;
  2.6248 +           filterlength=2*hfl+1;
  2.6249 +       }
  2.6250 +       else {
  2.6251 +           for (j=0; j<ENH_UPS0; j++) {
  2.6252 +               polyp[j]=polyphaserTbl+j*filterlength;
  2.6253 +           }
  2.6254 +       }
  2.6255 +
  2.6256 +       /* filtering: filter overhangs left side of sequence */
  2.6257 +
  2.6258 +       pu=useq1;
  2.6259 +       for (i=hfl; i<filterlength; i++) {
  2.6260 +           for (j=0; j<ENH_UPS0; j++) {
  2.6261 +               *pu=0.0;
  2.6262 +               pp = polyp[j];
  2.6263 +               ps = seq1+i;
  2.6264 +               for (k=0; k<=i; k++) {
  2.6265 +                   *pu += *ps-- * *pp++;
  2.6266 +               }
  2.6267 +               pu++;
  2.6268 +           }
  2.6269 +       }
  2.6270 +
  2.6271 +       /* filtering: simple convolution=inner products */
  2.6272 +
  2.6273 +       for (i=filterlength; i<dim1; i++) {
  2.6274 +
  2.6275 +
  2.6276 +
  2.6277 +Andersen, et al.              Experimental                    [Page 112]
  2.6278 +
  2.6279 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6280 +
  2.6281 +
  2.6282 +           for (j=0;j<ENH_UPS0; j++){
  2.6283 +               *pu=0.0;
  2.6284 +               pp = polyp[j];
  2.6285 +               ps = seq1+i;
  2.6286 +               for (k=0; k<filterlength; k++) {
  2.6287 +                   *pu += *ps-- * *pp++;
  2.6288 +               }
  2.6289 +               pu++;
  2.6290 +           }
  2.6291 +       }
  2.6292 +
  2.6293 +       /* filtering: filter overhangs right side of sequence */
  2.6294 +
  2.6295 +       for (q=1; q<=hfl; q++) {
  2.6296 +           for (j=0; j<ENH_UPS0; j++) {
  2.6297 +               *pu=0.0;
  2.6298 +               pp = polyp[j]+q;
  2.6299 +               ps = seq1+dim1-1;
  2.6300 +               for (k=0; k<filterlength-q; k++) {
  2.6301 +                   *pu += *ps-- * *pp++;
  2.6302 +               }
  2.6303 +               pu++;
  2.6304 +           }
  2.6305 +       }
  2.6306 +   }
  2.6307 +
  2.6308 +
  2.6309 +   /*----------------------------------------------------------------*
  2.6310 +    * find segment starting near idata+estSegPos that has highest
  2.6311 +    * correlation with idata+centerStartPos through
  2.6312 +    * idata+centerStartPos+ENH_BLOCKL-1 segment is found at a
  2.6313 +    * resolution of ENH_UPSO times the original of the original
  2.6314 +    * sampling rate
  2.6315 +    *---------------------------------------------------------------*/
  2.6316 +
  2.6317 +   void refiner(
  2.6318 +       float *seg,         /* (o) segment array */
  2.6319 +       float *updStartPos, /* (o) updated start point */
  2.6320 +       float* idata,       /* (i) original data buffer */
  2.6321 +       int idatal,         /* (i) dimension of idata */
  2.6322 +       int centerStartPos, /* (i) beginning center segment */
  2.6323 +       float estSegPos,/* (i) estimated beginning other segment */
  2.6324 +       float period    /* (i) estimated pitch period */
  2.6325 +   ){
  2.6326 +       int estSegPosRounded,searchSegStartPos,searchSegEndPos,corrdim;
  2.6327 +       int tloc,tloc2,i,st,en,fraction;
  2.6328 +       float vect[ENH_VECTL],corrVec[ENH_CORRDIM],maxv;
  2.6329 +       float corrVecUps[ENH_CORRDIM*ENH_UPS0];
  2.6330 +
  2.6331 +
  2.6332 +
  2.6333 +Andersen, et al.              Experimental                    [Page 113]
  2.6334 +
  2.6335 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6336 +
  2.6337 +
  2.6338 +       /* defining array bounds */
  2.6339 +
  2.6340 +       estSegPosRounded=(int)(estSegPos - 0.5);
  2.6341 +
  2.6342 +       searchSegStartPos=estSegPosRounded-ENH_SLOP;
  2.6343 +
  2.6344 +       if (searchSegStartPos<0) {
  2.6345 +           searchSegStartPos=0;
  2.6346 +       }
  2.6347 +       searchSegEndPos=estSegPosRounded+ENH_SLOP;
  2.6348 +
  2.6349 +       if (searchSegEndPos+ENH_BLOCKL >= idatal) {
  2.6350 +           searchSegEndPos=idatal-ENH_BLOCKL-1;
  2.6351 +       }
  2.6352 +       corrdim=searchSegEndPos-searchSegStartPos+1;
  2.6353 +
  2.6354 +       /* compute upsampled correlation (corr33) and find
  2.6355 +          location of max */
  2.6356 +
  2.6357 +       mycorr1(corrVec,idata+searchSegStartPos,
  2.6358 +           corrdim+ENH_BLOCKL-1,idata+centerStartPos,ENH_BLOCKL);
  2.6359 +       enh_upsample(corrVecUps,corrVec,corrdim,ENH_FL0);
  2.6360 +       tloc=0; maxv=corrVecUps[0];
  2.6361 +       for (i=1; i<ENH_UPS0*corrdim; i++) {
  2.6362 +
  2.6363 +           if (corrVecUps[i]>maxv) {
  2.6364 +               tloc=i;
  2.6365 +               maxv=corrVecUps[i];
  2.6366 +           }
  2.6367 +       }
  2.6368 +
  2.6369 +       /* make vector can be upsampled without ever running outside
  2.6370 +          bounds */
  2.6371 +
  2.6372 +       *updStartPos= (float)searchSegStartPos +
  2.6373 +           (float)tloc/(float)ENH_UPS0+(float)1.0;
  2.6374 +       tloc2=(int)(tloc/ENH_UPS0);
  2.6375 +
  2.6376 +       if (tloc>tloc2*ENH_UPS0) {
  2.6377 +           tloc2++;
  2.6378 +       }
  2.6379 +       st=searchSegStartPos+tloc2-ENH_FL0;
  2.6380 +
  2.6381 +       if (st<0) {
  2.6382 +           memset(vect,0,-st*sizeof(float));
  2.6383 +           memcpy(&vect[-st],idata, (ENH_VECTL+st)*sizeof(float));
  2.6384 +       }
  2.6385 +       else {
  2.6386 +
  2.6387 +
  2.6388 +
  2.6389 +Andersen, et al.              Experimental                    [Page 114]
  2.6390 +
  2.6391 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6392 +
  2.6393 +
  2.6394 +           en=st+ENH_VECTL;
  2.6395 +
  2.6396 +           if (en>idatal) {
  2.6397 +               memcpy(vect, &idata[st],
  2.6398 +                   (ENH_VECTL-(en-idatal))*sizeof(float));
  2.6399 +               memset(&vect[ENH_VECTL-(en-idatal)], 0,
  2.6400 +                   (en-idatal)*sizeof(float));
  2.6401 +           }
  2.6402 +           else {
  2.6403 +               memcpy(vect, &idata[st], ENH_VECTL*sizeof(float));
  2.6404 +           }
  2.6405 +       }
  2.6406 +       fraction=tloc2*ENH_UPS0-tloc;
  2.6407 +
  2.6408 +       /* compute the segment (this is actually a convolution) */
  2.6409 +
  2.6410 +       mycorr1(seg,vect,ENH_VECTL,polyphaserTbl+(2*ENH_FL0+1)*fraction,
  2.6411 +           2*ENH_FL0+1);
  2.6412 +   }
  2.6413 +
  2.6414 +   /*----------------------------------------------------------------*
  2.6415 +    * find the smoothed output data
  2.6416 +    *---------------------------------------------------------------*/
  2.6417 +
  2.6418 +   void smath(
  2.6419 +       float *odata,   /* (o) smoothed output */
  2.6420 +       float *sseq,/* (i) said second sequence of waveforms */
  2.6421 +       int hl,         /* (i) 2*hl+1 is sseq dimension */
  2.6422 +       float alpha0/* (i) max smoothing energy fraction */
  2.6423 +   ){
  2.6424 +       int i,k;
  2.6425 +       float w00,w10,w11,A,B,C,*psseq,err,errs;
  2.6426 +       float surround[BLOCKL_MAX]; /* shape contributed by other than
  2.6427 +                                      current */
  2.6428 +       float wt[2*ENH_HL+1];       /* waveform weighting to get
  2.6429 +                                      surround shape */
  2.6430 +       float denom;
  2.6431 +
  2.6432 +       /* create shape of contribution from all waveforms except the
  2.6433 +          current one */
  2.6434 +
  2.6435 +       for (i=1; i<=2*hl+1; i++) {
  2.6436 +           wt[i-1] = (float)0.5*(1 - (float)cos(2*PI*i/(2*hl+2)));
  2.6437 +       }
  2.6438 +       wt[hl]=0.0; /* for clarity, not used */
  2.6439 +       for (i=0; i<ENH_BLOCKL; i++) {
  2.6440 +           surround[i]=sseq[i]*wt[0];
  2.6441 +       }
  2.6442 +
  2.6443 +
  2.6444 +
  2.6445 +Andersen, et al.              Experimental                    [Page 115]
  2.6446 +
  2.6447 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6448 +
  2.6449 +
  2.6450 +       for (k=1; k<hl; k++) {
  2.6451 +           psseq=sseq+k*ENH_BLOCKL;
  2.6452 +           for(i=0;i<ENH_BLOCKL; i++) {
  2.6453 +               surround[i]+=psseq[i]*wt[k];
  2.6454 +           }
  2.6455 +       }
  2.6456 +       for (k=hl+1; k<=2*hl; k++) {
  2.6457 +           psseq=sseq+k*ENH_BLOCKL;
  2.6458 +           for(i=0;i<ENH_BLOCKL; i++) {
  2.6459 +               surround[i]+=psseq[i]*wt[k];
  2.6460 +           }
  2.6461 +       }
  2.6462 +
  2.6463 +       /* compute some inner products */
  2.6464 +
  2.6465 +       w00 = w10 = w11 = 0.0;
  2.6466 +       psseq=sseq+hl*ENH_BLOCKL; /* current block  */
  2.6467 +       for (i=0; i<ENH_BLOCKL;i++) {
  2.6468 +           w00+=psseq[i]*psseq[i];
  2.6469 +           w11+=surround[i]*surround[i];
  2.6470 +           w10+=surround[i]*psseq[i];
  2.6471 +       }
  2.6472 +
  2.6473 +       if (fabs(w11) < 1.0) {
  2.6474 +           w11=1.0;
  2.6475 +       }
  2.6476 +       C = (float)sqrt( w00/w11);
  2.6477 +
  2.6478 +       /* first try enhancement without power-constraint */
  2.6479 +
  2.6480 +       errs=0.0;
  2.6481 +       psseq=sseq+hl*ENH_BLOCKL;
  2.6482 +       for (i=0; i<ENH_BLOCKL; i++) {
  2.6483 +           odata[i]=C*surround[i];
  2.6484 +           err=psseq[i]-odata[i];
  2.6485 +           errs+=err*err;
  2.6486 +       }
  2.6487 +
  2.6488 +       /* if constraint violated by first try, add constraint */
  2.6489 +
  2.6490 +       if (errs > alpha0 * w00) {
  2.6491 +           if ( w00 < 1) {
  2.6492 +               w00=1;
  2.6493 +           }
  2.6494 +           denom = (w11*w00-w10*w10)/(w00*w00);
  2.6495 +
  2.6496 +           if (denom > 0.0001) { /* eliminates numerical problems
  2.6497 +                                    for if smooth */
  2.6498 +
  2.6499 +
  2.6500 +
  2.6501 +Andersen, et al.              Experimental                    [Page 116]
  2.6502 +
  2.6503 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6504 +
  2.6505 +
  2.6506 +               A = (float)sqrt( (alpha0- alpha0*alpha0/4)/denom);
  2.6507 +               B = -alpha0/2 - A * w10/w00;
  2.6508 +               B = B+1;
  2.6509 +           }
  2.6510 +           else { /* essentially no difference between cycles;
  2.6511 +                     smoothing not needed */
  2.6512 +               A= 0.0;
  2.6513 +               B= 1.0;
  2.6514 +           }
  2.6515 +
  2.6516 +           /* create smoothed sequence */
  2.6517 +
  2.6518 +           psseq=sseq+hl*ENH_BLOCKL;
  2.6519 +           for (i=0; i<ENH_BLOCKL; i++) {
  2.6520 +               odata[i]=A*surround[i]+B*psseq[i];
  2.6521 +           }
  2.6522 +       }
  2.6523 +   }
  2.6524 +
  2.6525 +   /*----------------------------------------------------------------*
  2.6526 +    * get the pitch-synchronous sample sequence
  2.6527 +    *---------------------------------------------------------------*/
  2.6528 +
  2.6529 +   void getsseq(
  2.6530 +       float *sseq,    /* (o) the pitch-synchronous sequence */
  2.6531 +       float *idata,       /* (i) original data */
  2.6532 +       int idatal,         /* (i) dimension of data */
  2.6533 +       int centerStartPos, /* (i) where current block starts */
  2.6534 +       float *period,      /* (i) rough-pitch-period array */
  2.6535 +       float *plocs,       /* (i) where periods of period array
  2.6536 +                                  are taken */
  2.6537 +       int periodl,    /* (i) dimension period array */
  2.6538 +       int hl              /* (i) 2*hl+1 is the number of sequences */
  2.6539 +   ){
  2.6540 +       int i,centerEndPos,q;
  2.6541 +       float blockStartPos[2*ENH_HL+1];
  2.6542 +       int lagBlock[2*ENH_HL+1];
  2.6543 +       float plocs2[ENH_PLOCSL];
  2.6544 +       float *psseq;
  2.6545 +
  2.6546 +       centerEndPos=centerStartPos+ENH_BLOCKL-1;
  2.6547 +
  2.6548 +       /* present */
  2.6549 +
  2.6550 +       NearestNeighbor(lagBlock+hl,plocs,
  2.6551 +           (float)0.5*(centerStartPos+centerEndPos),periodl);
  2.6552 +
  2.6553 +       blockStartPos[hl]=(float)centerStartPos;
  2.6554 +
  2.6555 +
  2.6556 +
  2.6557 +Andersen, et al.              Experimental                    [Page 117]
  2.6558 +
  2.6559 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6560 +
  2.6561 +
  2.6562 +       psseq=sseq+ENH_BLOCKL*hl;
  2.6563 +       memcpy(psseq, idata+centerStartPos, ENH_BLOCKL*sizeof(float));
  2.6564 +
  2.6565 +       /* past */
  2.6566 +
  2.6567 +       for (q=hl-1; q>=0; q--) {
  2.6568 +           blockStartPos[q]=blockStartPos[q+1]-period[lagBlock[q+1]];
  2.6569 +           NearestNeighbor(lagBlock+q,plocs,
  2.6570 +               blockStartPos[q]+
  2.6571 +               ENH_BLOCKL_HALF-period[lagBlock[q+1]], periodl);
  2.6572 +
  2.6573 +
  2.6574 +           if (blockStartPos[q]-ENH_OVERHANG>=0) {
  2.6575 +               refiner(sseq+q*ENH_BLOCKL, blockStartPos+q, idata,
  2.6576 +                   idatal, centerStartPos, blockStartPos[q],
  2.6577 +                   period[lagBlock[q+1]]);
  2.6578 +           } else {
  2.6579 +               psseq=sseq+q*ENH_BLOCKL;
  2.6580 +               memset(psseq, 0, ENH_BLOCKL*sizeof(float));
  2.6581 +           }
  2.6582 +       }
  2.6583 +
  2.6584 +       /* future */
  2.6585 +
  2.6586 +       for (i=0; i<periodl; i++) {
  2.6587 +           plocs2[i]=plocs[i]-period[i];
  2.6588 +       }
  2.6589 +       for (q=hl+1; q<=2*hl; q++) {
  2.6590 +           NearestNeighbor(lagBlock+q,plocs2,
  2.6591 +               blockStartPos[q-1]+ENH_BLOCKL_HALF,periodl);
  2.6592 +
  2.6593 +           blockStartPos[q]=blockStartPos[q-1]+period[lagBlock[q]];
  2.6594 +           if (blockStartPos[q]+ENH_BLOCKL+ENH_OVERHANG<idatal) {
  2.6595 +               refiner(sseq+ENH_BLOCKL*q, blockStartPos+q, idata,
  2.6596 +                   idatal, centerStartPos, blockStartPos[q],
  2.6597 +                   period[lagBlock[q]]);
  2.6598 +           }
  2.6599 +           else {
  2.6600 +               psseq=sseq+q*ENH_BLOCKL;
  2.6601 +               memset(psseq, 0, ENH_BLOCKL*sizeof(float));
  2.6602 +           }
  2.6603 +       }
  2.6604 +   }
  2.6605 +
  2.6606 +   /*----------------------------------------------------------------*
  2.6607 +    * perform enhancement on idata+centerStartPos through
  2.6608 +    * idata+centerStartPos+ENH_BLOCKL-1
  2.6609 +    *---------------------------------------------------------------*/
  2.6610 +
  2.6611 +
  2.6612 +
  2.6613 +Andersen, et al.              Experimental                    [Page 118]
  2.6614 +
  2.6615 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6616 +
  2.6617 +
  2.6618 +   void enhancer(
  2.6619 +       float *odata,       /* (o) smoothed block, dimension blockl */
  2.6620 +       float *idata,       /* (i) data buffer used for enhancing */
  2.6621 +       int idatal,         /* (i) dimension idata */
  2.6622 +       int centerStartPos, /* (i) first sample current block
  2.6623 +                                  within idata */
  2.6624 +       float alpha0,       /* (i) max correction-energy-fraction
  2.6625 +                                 (in [0,1]) */
  2.6626 +       float *period,      /* (i) pitch period array */
  2.6627 +       float *plocs,       /* (i) locations where period array
  2.6628 +                                  values valid */
  2.6629 +       int periodl         /* (i) dimension of period and plocs */
  2.6630 +   ){
  2.6631 +       float sseq[(2*ENH_HL+1)*ENH_BLOCKL];
  2.6632 +
  2.6633 +       /* get said second sequence of segments */
  2.6634 +
  2.6635 +       getsseq(sseq,idata,idatal,centerStartPos,period,
  2.6636 +           plocs,periodl,ENH_HL);
  2.6637 +
  2.6638 +       /* compute the smoothed output from said second sequence */
  2.6639 +
  2.6640 +       smath(odata,sseq,ENH_HL,alpha0);
  2.6641 +
  2.6642 +   }
  2.6643 +
  2.6644 +   /*----------------------------------------------------------------*
  2.6645 +    * cross correlation
  2.6646 +    *---------------------------------------------------------------*/
  2.6647 +
  2.6648 +   float xCorrCoef(
  2.6649 +       float *target,      /* (i) first array */
  2.6650 +       float *regressor,   /* (i) second array */
  2.6651 +       int subl        /* (i) dimension arrays */
  2.6652 +   ){
  2.6653 +       int i;
  2.6654 +       float ftmp1, ftmp2;
  2.6655 +
  2.6656 +       ftmp1 = 0.0;
  2.6657 +       ftmp2 = 0.0;
  2.6658 +       for (i=0; i<subl; i++) {
  2.6659 +           ftmp1 += target[i]*regressor[i];
  2.6660 +           ftmp2 += regressor[i]*regressor[i];
  2.6661 +       }
  2.6662 +
  2.6663 +       if (ftmp1 > 0.0) {
  2.6664 +           return (float)(ftmp1*ftmp1/ftmp2);
  2.6665 +       }
  2.6666 +
  2.6667 +
  2.6668 +
  2.6669 +Andersen, et al.              Experimental                    [Page 119]
  2.6670 +
  2.6671 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6672 +
  2.6673 +
  2.6674 +       else {
  2.6675 +           return (float)0.0;
  2.6676 +       }
  2.6677 +   }
  2.6678 +
  2.6679 +   /*----------------------------------------------------------------*
  2.6680 +    * interface for enhancer
  2.6681 +    *---------------------------------------------------------------*/
  2.6682 +
  2.6683 +   int enhancerInterface(
  2.6684 +       float *out,                     /* (o) enhanced signal */
  2.6685 +       float *in,                      /* (i) unenhanced signal */
  2.6686 +       iLBC_Dec_Inst_t *iLBCdec_inst   /* (i) buffers etc */
  2.6687 +   ){
  2.6688 +       float *enh_buf, *enh_period;
  2.6689 +       int iblock, isample;
  2.6690 +       int lag=0, ilag, i, ioffset;
  2.6691 +       float cc, maxcc;
  2.6692 +       float ftmp1, ftmp2;
  2.6693 +       float *inPtr, *enh_bufPtr1, *enh_bufPtr2;
  2.6694 +       float plc_pred[ENH_BLOCKL];
  2.6695 +
  2.6696 +       float lpState[6], downsampled[(ENH_NBLOCKS*ENH_BLOCKL+120)/2];
  2.6697 +       int inLen=ENH_NBLOCKS*ENH_BLOCKL+120;
  2.6698 +       int start, plc_blockl, inlag;
  2.6699 +
  2.6700 +       enh_buf=iLBCdec_inst->enh_buf;
  2.6701 +       enh_period=iLBCdec_inst->enh_period;
  2.6702 +
  2.6703 +       memmove(enh_buf, &enh_buf[iLBCdec_inst->blockl],
  2.6704 +           (ENH_BUFL-iLBCdec_inst->blockl)*sizeof(float));
  2.6705 +
  2.6706 +       memcpy(&enh_buf[ENH_BUFL-iLBCdec_inst->blockl], in,
  2.6707 +           iLBCdec_inst->blockl*sizeof(float));
  2.6708 +
  2.6709 +       if (iLBCdec_inst->mode==30)
  2.6710 +           plc_blockl=ENH_BLOCKL;
  2.6711 +       else
  2.6712 +           plc_blockl=40;
  2.6713 +
  2.6714 +       /* when 20 ms frame, move processing one block */
  2.6715 +       ioffset=0;
  2.6716 +       if (iLBCdec_inst->mode==20) ioffset=1;
  2.6717 +
  2.6718 +       i=3-ioffset;
  2.6719 +       memmove(enh_period, &enh_period[i],
  2.6720 +           (ENH_NBLOCKS_TOT-i)*sizeof(float));
  2.6721 +
  2.6722 +
  2.6723 +
  2.6724 +
  2.6725 +Andersen, et al.              Experimental                    [Page 120]
  2.6726 +
  2.6727 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6728 +
  2.6729 +
  2.6730 +       /* Set state information to the 6 samples right before
  2.6731 +          the samples to be downsampled. */
  2.6732 +
  2.6733 +       memcpy(lpState,
  2.6734 +           enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-126,
  2.6735 +           6*sizeof(float));
  2.6736 +
  2.6737 +       /* Down sample a factor 2 to save computations */
  2.6738 +
  2.6739 +       DownSample(enh_buf+(ENH_NBLOCKS_EXTRA+ioffset)*ENH_BLOCKL-120,
  2.6740 +                   lpFilt_coefsTbl, inLen-ioffset*ENH_BLOCKL,
  2.6741 +                   lpState, downsampled);
  2.6742 +
  2.6743 +       /* Estimate the pitch in the down sampled domain. */
  2.6744 +       for (iblock = 0; iblock<ENH_NBLOCKS-ioffset; iblock++) {
  2.6745 +
  2.6746 +           lag = 10;
  2.6747 +           maxcc = xCorrCoef(downsampled+60+iblock*
  2.6748 +               ENH_BLOCKL_HALF, downsampled+60+iblock*
  2.6749 +               ENH_BLOCKL_HALF-lag, ENH_BLOCKL_HALF);
  2.6750 +           for (ilag=11; ilag<60; ilag++) {
  2.6751 +               cc = xCorrCoef(downsampled+60+iblock*
  2.6752 +                   ENH_BLOCKL_HALF, downsampled+60+iblock*
  2.6753 +                   ENH_BLOCKL_HALF-ilag, ENH_BLOCKL_HALF);
  2.6754 +
  2.6755 +               if (cc > maxcc) {
  2.6756 +                   maxcc = cc;
  2.6757 +                   lag = ilag;
  2.6758 +               }
  2.6759 +           }
  2.6760 +
  2.6761 +           /* Store the estimated lag in the non-downsampled domain */
  2.6762 +           enh_period[iblock+ENH_NBLOCKS_EXTRA+ioffset] = (float)lag*2;
  2.6763 +
  2.6764 +
  2.6765 +       }
  2.6766 +
  2.6767 +
  2.6768 +       /* PLC was performed on the previous packet */
  2.6769 +       if (iLBCdec_inst->prev_enh_pl==1) {
  2.6770 +
  2.6771 +           inlag=(int)enh_period[ENH_NBLOCKS_EXTRA+ioffset];
  2.6772 +
  2.6773 +           lag = inlag-1;
  2.6774 +           maxcc = xCorrCoef(in, in+lag, plc_blockl);
  2.6775 +           for (ilag=inlag; ilag<=inlag+1; ilag++) {
  2.6776 +               cc = xCorrCoef(in, in+ilag, plc_blockl);
  2.6777 +
  2.6778 +
  2.6779 +
  2.6780 +
  2.6781 +Andersen, et al.              Experimental                    [Page 121]
  2.6782 +
  2.6783 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6784 +
  2.6785 +
  2.6786 +               if (cc > maxcc) {
  2.6787 +                   maxcc = cc;
  2.6788 +                   lag = ilag;
  2.6789 +               }
  2.6790 +           }
  2.6791 +
  2.6792 +           enh_period[ENH_NBLOCKS_EXTRA+ioffset-1]=(float)lag;
  2.6793 +
  2.6794 +           /* compute new concealed residual for the old lookahead,
  2.6795 +              mix the forward PLC with a backward PLC from
  2.6796 +              the new frame */
  2.6797 +
  2.6798 +           inPtr=&in[lag-1];
  2.6799 +
  2.6800 +           enh_bufPtr1=&plc_pred[plc_blockl-1];
  2.6801 +
  2.6802 +           if (lag>plc_blockl) {
  2.6803 +               start=plc_blockl;
  2.6804 +           } else {
  2.6805 +               start=lag;
  2.6806 +           }
  2.6807 +
  2.6808 +           for (isample = start; isample>0; isample--) {
  2.6809 +               *enh_bufPtr1-- = *inPtr--;
  2.6810 +           }
  2.6811 +
  2.6812 +           enh_bufPtr2=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
  2.6813 +           for (isample = (plc_blockl-1-lag); isample>=0; isample--) {
  2.6814 +               *enh_bufPtr1-- = *enh_bufPtr2--;
  2.6815 +           }
  2.6816 +
  2.6817 +           /* limit energy change */
  2.6818 +           ftmp2=0.0;
  2.6819 +           ftmp1=0.0;
  2.6820 +           for (i=0;i<plc_blockl;i++) {
  2.6821 +               ftmp2+=enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i]*
  2.6822 +                   enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl-i];
  2.6823 +               ftmp1+=plc_pred[i]*plc_pred[i];
  2.6824 +           }
  2.6825 +           ftmp1=(float)sqrt(ftmp1/(float)plc_blockl);
  2.6826 +           ftmp2=(float)sqrt(ftmp2/(float)plc_blockl);
  2.6827 +           if (ftmp1>(float)2.0*ftmp2 && ftmp1>0.0) {
  2.6828 +               for (i=0;i<plc_blockl-10;i++) {
  2.6829 +                   plc_pred[i]*=(float)2.0*ftmp2/ftmp1;
  2.6830 +               }
  2.6831 +               for (i=plc_blockl-10;i<plc_blockl;i++) {
  2.6832 +                   plc_pred[i]*=(float)(i-plc_blockl+10)*
  2.6833 +                       ((float)1.0-(float)2.0*ftmp2/ftmp1)/(float)(10)+
  2.6834 +
  2.6835 +
  2.6836 +
  2.6837 +Andersen, et al.              Experimental                    [Page 122]
  2.6838 +
  2.6839 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6840 +
  2.6841 +
  2.6842 +                       (float)2.0*ftmp2/ftmp1;
  2.6843 +               }
  2.6844 +           }
  2.6845 +
  2.6846 +           enh_bufPtr1=&enh_buf[ENH_BUFL-1-iLBCdec_inst->blockl];
  2.6847 +           for (i=0; i<plc_blockl; i++) {
  2.6848 +               ftmp1 = (float) (i+1) / (float) (plc_blockl+1);
  2.6849 +               *enh_bufPtr1 *= ftmp1;
  2.6850 +               *enh_bufPtr1 += ((float)1.0-ftmp1)*
  2.6851 +                                   plc_pred[plc_blockl-1-i];
  2.6852 +               enh_bufPtr1--;
  2.6853 +           }
  2.6854 +       }
  2.6855 +
  2.6856 +       if (iLBCdec_inst->mode==20) {
  2.6857 +           /* Enhancer with 40 samples delay */
  2.6858 +           for (iblock = 0; iblock<2; iblock++) {
  2.6859 +               enhancer(out+iblock*ENH_BLOCKL, enh_buf,
  2.6860 +                   ENH_BUFL, (5+iblock)*ENH_BLOCKL+40,
  2.6861 +                   ENH_ALPHA0, enh_period, enh_plocsTbl,
  2.6862 +                       ENH_NBLOCKS_TOT);
  2.6863 +           }
  2.6864 +       } else if (iLBCdec_inst->mode==30) {
  2.6865 +           /* Enhancer with 80 samples delay */
  2.6866 +           for (iblock = 0; iblock<3; iblock++) {
  2.6867 +               enhancer(out+iblock*ENH_BLOCKL, enh_buf,
  2.6868 +                   ENH_BUFL, (4+iblock)*ENH_BLOCKL,
  2.6869 +                   ENH_ALPHA0, enh_period, enh_plocsTbl,
  2.6870 +                       ENH_NBLOCKS_TOT);
  2.6871 +           }
  2.6872 +       }
  2.6873 +
  2.6874 +       return (lag*2);
  2.6875 +   }
  2.6876 +
  2.6877 +A.17.  filter.h
  2.6878 +
  2.6879 +   /******************************************************************
  2.6880 +
  2.6881 +       iLBC Speech Coder ANSI-C Source Code
  2.6882 +
  2.6883 +       filter.h
  2.6884 +
  2.6885 +       Copyright (C) The Internet Society (2004).
  2.6886 +       All Rights Reserved.
  2.6887 +
  2.6888 +   ******************************************************************/
  2.6889 +
  2.6890 +
  2.6891 +
  2.6892 +
  2.6893 +Andersen, et al.              Experimental                    [Page 123]
  2.6894 +
  2.6895 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6896 +
  2.6897 +
  2.6898 +   #ifndef __iLBC_FILTER_H
  2.6899 +   #define __iLBC_FILTER_H
  2.6900 +
  2.6901 +   void AllPoleFilter(
  2.6902 +       float *InOut,   /* (i/o) on entrance InOut[-orderCoef] to
  2.6903 +                              InOut[-1] contain the state of the
  2.6904 +                              filter (delayed samples). InOut[0] to
  2.6905 +                              InOut[lengthInOut-1] contain the filter
  2.6906 +                              input, on en exit InOut[-orderCoef] to
  2.6907 +                              InOut[-1] is unchanged and InOut[0] to
  2.6908 +                              InOut[lengthInOut-1] contain filtered
  2.6909 +                              samples */
  2.6910 +       float *Coef,/* (i) filter coefficients, Coef[0] is assumed
  2.6911 +                              to be 1.0 */
  2.6912 +       int lengthInOut,/* (i) number of input/output samples */
  2.6913 +       int orderCoef   /* (i) number of filter coefficients */
  2.6914 +   );
  2.6915 +
  2.6916 +   void AllZeroFilter(
  2.6917 +       float *In,      /* (i) In[0] to In[lengthInOut-1] contain
  2.6918 +                              filter input samples */
  2.6919 +       float *Coef,/* (i) filter coefficients (Coef[0] is assumed
  2.6920 +                              to be 1.0) */
  2.6921 +       int lengthInOut,/* (i) number of input/output samples */
  2.6922 +       int orderCoef,  /* (i) number of filter coefficients */
  2.6923 +       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]
  2.6924 +                              contain the filter state, on exit Out[0]
  2.6925 +                              to Out[lengthInOut-1] contain filtered
  2.6926 +                              samples */
  2.6927 +   );
  2.6928 +
  2.6929 +   void ZeroPoleFilter(
  2.6930 +       float *In,      /* (i) In[0] to In[lengthInOut-1] contain filter
  2.6931 +                              input samples In[-orderCoef] to In[-1]
  2.6932 +                              contain state of all-zero section */
  2.6933 +       float *ZeroCoef,/* (i) filter coefficients for all-zero
  2.6934 +                              section (ZeroCoef[0] is assumed to
  2.6935 +                              be 1.0) */
  2.6936 +       float *PoleCoef,/* (i) filter coefficients for all-pole section
  2.6937 +                              (ZeroCoef[0] is assumed to be 1.0) */
  2.6938 +       int lengthInOut,/* (i) number of input/output samples */
  2.6939 +       int orderCoef,  /* (i) number of filter coefficients */
  2.6940 +       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]
  2.6941 +                              contain state of all-pole section. On
  2.6942 +                              exit Out[0] to Out[lengthInOut-1]
  2.6943 +                              contain filtered samples */
  2.6944 +   );
  2.6945 +
  2.6946 +
  2.6947 +
  2.6948 +
  2.6949 +Andersen, et al.              Experimental                    [Page 124]
  2.6950 +
  2.6951 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.6952 +
  2.6953 +
  2.6954 +   void DownSample (
  2.6955 +       float  *In,     /* (i) input samples */
  2.6956 +       float  *Coef,   /* (i) filter coefficients */
  2.6957 +       int lengthIn,   /* (i) number of input samples */
  2.6958 +       float  *state,  /* (i) filter state */
  2.6959 +       float  *Out     /* (o) downsampled output */
  2.6960 +   );
  2.6961 +
  2.6962 +   #endif
  2.6963 +
  2.6964 +A.18.  filter.c
  2.6965 +
  2.6966 +   /******************************************************************
  2.6967 +
  2.6968 +       iLBC Speech Coder ANSI-C Source Code
  2.6969 +
  2.6970 +       filter.c
  2.6971 +
  2.6972 +       Copyright (C) The Internet Society (2004).
  2.6973 +       All Rights Reserved.
  2.6974 +
  2.6975 +   ******************************************************************/
  2.6976 +
  2.6977 +   #include "iLBC_define.h"
  2.6978 +
  2.6979 +   /*----------------------------------------------------------------*
  2.6980 +    *  all-pole filter
  2.6981 +    *---------------------------------------------------------------*/
  2.6982 +
  2.6983 +   void AllPoleFilter(
  2.6984 +       float *InOut,   /* (i/o) on entrance InOut[-orderCoef] to
  2.6985 +                              InOut[-1] contain the state of the
  2.6986 +                              filter (delayed samples). InOut[0] to
  2.6987 +                              InOut[lengthInOut-1] contain the filter
  2.6988 +                              input, on en exit InOut[-orderCoef] to
  2.6989 +                              InOut[-1] is unchanged and InOut[0] to
  2.6990 +                              InOut[lengthInOut-1] contain filtered
  2.6991 +                              samples */
  2.6992 +       float *Coef,/* (i) filter coefficients, Coef[0] is assumed
  2.6993 +                              to be 1.0 */
  2.6994 +       int lengthInOut,/* (i) number of input/output samples */
  2.6995 +       int orderCoef   /* (i) number of filter coefficients */
  2.6996 +   ){
  2.6997 +       int n,k;
  2.6998 +
  2.6999 +       for(n=0;n<lengthInOut;n++){
  2.7000 +           for(k=1;k<=orderCoef;k++){
  2.7001 +               *InOut -= Coef[k]*InOut[-k];
  2.7002 +
  2.7003 +
  2.7004 +
  2.7005 +Andersen, et al.              Experimental                    [Page 125]
  2.7006 +
  2.7007 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7008 +
  2.7009 +
  2.7010 +           }
  2.7011 +           InOut++;
  2.7012 +       }
  2.7013 +   }
  2.7014 +
  2.7015 +   /*----------------------------------------------------------------*
  2.7016 +    *  all-zero filter
  2.7017 +    *---------------------------------------------------------------*/
  2.7018 +
  2.7019 +   void AllZeroFilter(
  2.7020 +       float *In,      /* (i) In[0] to In[lengthInOut-1] contain
  2.7021 +                              filter input samples */
  2.7022 +       float *Coef,/* (i) filter coefficients (Coef[0] is assumed
  2.7023 +                              to be 1.0) */
  2.7024 +       int lengthInOut,/* (i) number of input/output samples */
  2.7025 +       int orderCoef,  /* (i) number of filter coefficients */
  2.7026 +       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]
  2.7027 +                              contain the filter state, on exit Out[0]
  2.7028 +                              to Out[lengthInOut-1] contain filtered
  2.7029 +                              samples */
  2.7030 +   ){
  2.7031 +       int n,k;
  2.7032 +
  2.7033 +       for(n=0;n<lengthInOut;n++){
  2.7034 +           *Out = Coef[0]*In[0];
  2.7035 +           for(k=1;k<=orderCoef;k++){
  2.7036 +               *Out += Coef[k]*In[-k];
  2.7037 +           }
  2.7038 +           Out++;
  2.7039 +           In++;
  2.7040 +       }
  2.7041 +   }
  2.7042 +
  2.7043 +   /*----------------------------------------------------------------*
  2.7044 +    *  pole-zero filter
  2.7045 +    *---------------------------------------------------------------*/
  2.7046 +
  2.7047 +   void ZeroPoleFilter(
  2.7048 +       float *In,      /* (i) In[0] to In[lengthInOut-1] contain
  2.7049 +                              filter input samples In[-orderCoef] to
  2.7050 +                              In[-1] contain state of all-zero
  2.7051 +                              section */
  2.7052 +       float *ZeroCoef,/* (i) filter coefficients for all-zero
  2.7053 +                              section (ZeroCoef[0] is assumed to
  2.7054 +                              be 1.0) */
  2.7055 +       float *PoleCoef,/* (i) filter coefficients for all-pole section
  2.7056 +                              (ZeroCoef[0] is assumed to be 1.0) */
  2.7057 +       int lengthInOut,/* (i) number of input/output samples */
  2.7058 +
  2.7059 +
  2.7060 +
  2.7061 +Andersen, et al.              Experimental                    [Page 126]
  2.7062 +
  2.7063 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7064 +
  2.7065 +
  2.7066 +       int orderCoef,  /* (i) number of filter coefficients */
  2.7067 +       float *Out      /* (i/o) on entrance Out[-orderCoef] to Out[-1]
  2.7068 +                              contain state of all-pole section. On
  2.7069 +                              exit Out[0] to Out[lengthInOut-1]
  2.7070 +                              contain filtered samples */
  2.7071 +   ){
  2.7072 +       AllZeroFilter(In,ZeroCoef,lengthInOut,orderCoef,Out);
  2.7073 +       AllPoleFilter(Out,PoleCoef,lengthInOut,orderCoef);
  2.7074 +   }
  2.7075 +
  2.7076 +   /*----------------------------------------------------------------*
  2.7077 +    * downsample (LP filter and decimation)
  2.7078 +    *---------------------------------------------------------------*/
  2.7079 +
  2.7080 +   void DownSample (
  2.7081 +       float  *In,     /* (i) input samples */
  2.7082 +       float  *Coef,   /* (i) filter coefficients */
  2.7083 +       int lengthIn,   /* (i) number of input samples */
  2.7084 +       float  *state,  /* (i) filter state */
  2.7085 +       float  *Out     /* (o) downsampled output */
  2.7086 +   ){
  2.7087 +       float   o;
  2.7088 +       float *Out_ptr = Out;
  2.7089 +       float *Coef_ptr, *In_ptr;
  2.7090 +       float *state_ptr;
  2.7091 +       int i, j, stop;
  2.7092 +
  2.7093 +       /* LP filter and decimate at the same time */
  2.7094 +
  2.7095 +       for (i = DELAY_DS; i < lengthIn; i+=FACTOR_DS)
  2.7096 +       {
  2.7097 +           Coef_ptr = &Coef[0];
  2.7098 +           In_ptr = &In[i];
  2.7099 +           state_ptr = &state[FILTERORDER_DS-2];
  2.7100 +
  2.7101 +           o = (float)0.0;
  2.7102 +
  2.7103 +           stop = (i < FILTERORDER_DS) ? i + 1 : FILTERORDER_DS;
  2.7104 +
  2.7105 +           for (j = 0; j < stop; j++)
  2.7106 +           {
  2.7107 +               o += *Coef_ptr++ * (*In_ptr--);
  2.7108 +           }
  2.7109 +           for (j = i + 1; j < FILTERORDER_DS; j++)
  2.7110 +           {
  2.7111 +               o += *Coef_ptr++ * (*state_ptr--);
  2.7112 +           }
  2.7113 +
  2.7114 +
  2.7115 +
  2.7116 +
  2.7117 +Andersen, et al.              Experimental                    [Page 127]
  2.7118 +
  2.7119 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7120 +
  2.7121 +
  2.7122 +           *Out_ptr++ = o;
  2.7123 +       }
  2.7124 +
  2.7125 +       /* Get the last part (use zeros as input for the future) */
  2.7126 +
  2.7127 +       for (i=(lengthIn+FACTOR_DS); i<(lengthIn+DELAY_DS);
  2.7128 +               i+=FACTOR_DS) {
  2.7129 +
  2.7130 +           o=(float)0.0;
  2.7131 +
  2.7132 +           if (i<lengthIn) {
  2.7133 +               Coef_ptr = &Coef[0];
  2.7134 +               In_ptr = &In[i];
  2.7135 +               for (j=0; j<FILTERORDER_DS; j++) {
  2.7136 +                       o += *Coef_ptr++ * (*Out_ptr--);
  2.7137 +               }
  2.7138 +           } else {
  2.7139 +               Coef_ptr = &Coef[i-lengthIn];
  2.7140 +               In_ptr = &In[lengthIn-1];
  2.7141 +               for (j=0; j<FILTERORDER_DS-(i-lengthIn); j++) {
  2.7142 +                       o += *Coef_ptr++ * (*In_ptr--);
  2.7143 +               }
  2.7144 +           }
  2.7145 +           *Out_ptr++ = o;
  2.7146 +       }
  2.7147 +   }
  2.7148 +
  2.7149 +A.19.  FrameClassify.h
  2.7150 +
  2.7151 +   /******************************************************************
  2.7152 +
  2.7153 +       iLBC Speech Coder ANSI-C Source Code
  2.7154 +
  2.7155 +       FrameClassify.h
  2.7156 +
  2.7157 +       Copyright (C) The Internet Society (2004).
  2.7158 +       All Rights Reserved.
  2.7159 +
  2.7160 +   ******************************************************************/
  2.7161 +
  2.7162 +   #ifndef __iLBC_FRAMECLASSIFY_H
  2.7163 +   #define __iLBC_FRAMECLASSIFY_H
  2.7164 +
  2.7165 +   int FrameClassify(      /* index to the max-energy sub-frame */
  2.7166 +       iLBC_Enc_Inst_t *iLBCenc_inst,
  2.7167 +                           /* (i/o) the encoder state structure */
  2.7168 +       float *residual     /* (i) lpc residual signal */
  2.7169 +   );
  2.7170 +
  2.7171 +
  2.7172 +
  2.7173 +Andersen, et al.              Experimental                    [Page 128]
  2.7174 +
  2.7175 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7176 +
  2.7177 +
  2.7178 +   #endif
  2.7179 +
  2.7180 +A.20.  FrameClassify.c
  2.7181 +
  2.7182 +   /******************************************************************
  2.7183 +
  2.7184 +       iLBC Speech Coder ANSI-C Source Code
  2.7185 +
  2.7186 +       FrameClassify.c
  2.7187 +
  2.7188 +       Copyright (C) The Internet Society (2004).
  2.7189 +       All Rights Reserved.
  2.7190 +
  2.7191 +   ******************************************************************/
  2.7192 +
  2.7193 +   #include "iLBC_define.h"
  2.7194 +
  2.7195 +   /*---------------------------------------------------------------*
  2.7196 +    *  Classification of subframes to localize start state
  2.7197 +    *--------------------------------------------------------------*/
  2.7198 +
  2.7199 +   int FrameClassify(      /* index to the max-energy sub-frame */
  2.7200 +       iLBC_Enc_Inst_t *iLBCenc_inst,
  2.7201 +                           /* (i/o) the encoder state structure */
  2.7202 +       float *residual     /* (i) lpc residual signal */
  2.7203 +   ) {
  2.7204 +       float max_ssqEn, fssqEn[NSUB_MAX], bssqEn[NSUB_MAX], *pp;
  2.7205 +       int n, l, max_ssqEn_n;
  2.7206 +       const float ssqEn_win[NSUB_MAX-1]={(float)0.8,(float)0.9,
  2.7207 +           (float)1.0,(float)0.9,(float)0.8};
  2.7208 +       const float sampEn_win[5]={(float)1.0/(float)6.0,
  2.7209 +           (float)2.0/(float)6.0, (float)3.0/(float)6.0,
  2.7210 +           (float)4.0/(float)6.0, (float)5.0/(float)6.0};
  2.7211 +
  2.7212 +       /* init the front and back energies to zero */
  2.7213 +
  2.7214 +       memset(fssqEn, 0, NSUB_MAX*sizeof(float));
  2.7215 +       memset(bssqEn, 0, NSUB_MAX*sizeof(float));
  2.7216 +
  2.7217 +       /* Calculate front of first seqence */
  2.7218 +
  2.7219 +       n=0;
  2.7220 +       pp=residual;
  2.7221 +       for (l=0; l<5; l++) {
  2.7222 +           fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
  2.7223 +           pp++;
  2.7224 +       }
  2.7225 +       for (l=5; l<SUBL; l++) {
  2.7226 +
  2.7227 +
  2.7228 +
  2.7229 +Andersen, et al.              Experimental                    [Page 129]
  2.7230 +
  2.7231 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7232 +
  2.7233 +
  2.7234 +           fssqEn[n] += (*pp) * (*pp);
  2.7235 +           pp++;
  2.7236 +       }
  2.7237 +
  2.7238 +       /* Calculate front and back of all middle sequences */
  2.7239 +
  2.7240 +       for (n=1; n<iLBCenc_inst->nsub-1; n++) {
  2.7241 +           pp=residual+n*SUBL;
  2.7242 +           for (l=0; l<5; l++) {
  2.7243 +               fssqEn[n] += sampEn_win[l] * (*pp) * (*pp);
  2.7244 +               bssqEn[n] += (*pp) * (*pp);
  2.7245 +               pp++;
  2.7246 +           }
  2.7247 +           for (l=5; l<SUBL-5; l++) {
  2.7248 +               fssqEn[n] += (*pp) * (*pp);
  2.7249 +               bssqEn[n] += (*pp) * (*pp);
  2.7250 +               pp++;
  2.7251 +           }
  2.7252 +           for (l=SUBL-5; l<SUBL; l++) {
  2.7253 +               fssqEn[n] += (*pp) * (*pp);
  2.7254 +               bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
  2.7255 +               pp++;
  2.7256 +           }
  2.7257 +       }
  2.7258 +
  2.7259 +       /* Calculate back of last seqence */
  2.7260 +
  2.7261 +       n=iLBCenc_inst->nsub-1;
  2.7262 +       pp=residual+n*SUBL;
  2.7263 +       for (l=0; l<SUBL-5; l++) {
  2.7264 +           bssqEn[n] += (*pp) * (*pp);
  2.7265 +           pp++;
  2.7266 +       }
  2.7267 +       for (l=SUBL-5; l<SUBL; l++) {
  2.7268 +           bssqEn[n] += sampEn_win[SUBL-l-1] * (*pp) * (*pp);
  2.7269 +           pp++;
  2.7270 +       }
  2.7271 +
  2.7272 +       /* find the index to the weighted 80 sample with
  2.7273 +          most energy */
  2.7274 +
  2.7275 +       if (iLBCenc_inst->mode==20) l=1;
  2.7276 +       else                        l=0;
  2.7277 +
  2.7278 +       max_ssqEn=(fssqEn[0]+bssqEn[1])*ssqEn_win[l];
  2.7279 +       max_ssqEn_n=1;
  2.7280 +       for (n=2; n<iLBCenc_inst->nsub; n++) {
  2.7281 +
  2.7282 +
  2.7283 +
  2.7284 +
  2.7285 +Andersen, et al.              Experimental                    [Page 130]
  2.7286 +
  2.7287 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7288 +
  2.7289 +
  2.7290 +           l++;
  2.7291 +           if ((fssqEn[n-1]+bssqEn[n])*ssqEn_win[l] > max_ssqEn) {
  2.7292 +               max_ssqEn=(fssqEn[n-1]+bssqEn[n]) *
  2.7293 +                               ssqEn_win[l];
  2.7294 +               max_ssqEn_n=n;
  2.7295 +           }
  2.7296 +       }
  2.7297 +
  2.7298 +       return max_ssqEn_n;
  2.7299 +   }
  2.7300 +
  2.7301 +A.21.  gainquant.h
  2.7302 +
  2.7303 +   /******************************************************************
  2.7304 +
  2.7305 +       iLBC Speech Coder ANSI-C Source Code
  2.7306 +
  2.7307 +       gainquant.h
  2.7308 +
  2.7309 +       Copyright (C) The Internet Society (2004).
  2.7310 +       All Rights Reserved.
  2.7311 +
  2.7312 +   ******************************************************************/
  2.7313 +
  2.7314 +   #ifndef __iLBC_GAINQUANT_H
  2.7315 +   #define __iLBC_GAINQUANT_H
  2.7316 +
  2.7317 +   float gainquant(/* (o) quantized gain value */
  2.7318 +       float in,       /* (i) gain value */
  2.7319 +       float maxIn,/* (i) maximum of gain value */
  2.7320 +       int cblen,      /* (i) number of quantization indices */
  2.7321 +       int *index      /* (o) quantization index */
  2.7322 +   );
  2.7323 +
  2.7324 +   float gaindequant(  /* (o) quantized gain value */
  2.7325 +       int index,      /* (i) quantization index */
  2.7326 +       float maxIn,/* (i) maximum of unquantized gain */
  2.7327 +       int cblen       /* (i) number of quantization indices */
  2.7328 +   );
  2.7329 +
  2.7330 +   #endif
  2.7331 +
  2.7332 +A.22.  gainquant.c
  2.7333 +
  2.7334 +   /******************************************************************
  2.7335 +
  2.7336 +       iLBC Speech Coder ANSI-C Source Code
  2.7337 +
  2.7338 +
  2.7339 +
  2.7340 +
  2.7341 +Andersen, et al.              Experimental                    [Page 131]
  2.7342 +
  2.7343 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7344 +
  2.7345 +
  2.7346 +       gainquant.c
  2.7347 +
  2.7348 +       Copyright (C) The Internet Society (2004).
  2.7349 +       All Rights Reserved.
  2.7350 +
  2.7351 +   ******************************************************************/
  2.7352 +
  2.7353 +   #include <string.h>
  2.7354 +   #include <math.h>
  2.7355 +   #include "constants.h"
  2.7356 +   #include "filter.h"
  2.7357 +
  2.7358 +   /*----------------------------------------------------------------*
  2.7359 +    *  quantizer for the gain in the gain-shape coding of residual
  2.7360 +    *---------------------------------------------------------------*/
  2.7361 +
  2.7362 +   float gainquant(/* (o) quantized gain value */
  2.7363 +       float in,       /* (i) gain value */
  2.7364 +       float maxIn,/* (i) maximum of gain value */
  2.7365 +       int cblen,      /* (i) number of quantization indices */
  2.7366 +       int *index      /* (o) quantization index */
  2.7367 +   ){
  2.7368 +       int i, tindex;
  2.7369 +       float minmeasure,measure, *cb, scale;
  2.7370 +
  2.7371 +       /* ensure a lower bound on the scaling factor */
  2.7372 +
  2.7373 +       scale=maxIn;
  2.7374 +
  2.7375 +       if (scale<0.1) {
  2.7376 +           scale=(float)0.1;
  2.7377 +       }
  2.7378 +
  2.7379 +       /* select the quantization table */
  2.7380 +
  2.7381 +       if (cblen == 8) {
  2.7382 +           cb = gain_sq3Tbl;
  2.7383 +       } else if (cblen == 16) {
  2.7384 +           cb = gain_sq4Tbl;
  2.7385 +       } else  {
  2.7386 +           cb = gain_sq5Tbl;
  2.7387 +       }
  2.7388 +
  2.7389 +       /* select the best index in the quantization table */
  2.7390 +
  2.7391 +       minmeasure=10000000.0;
  2.7392 +       tindex=0;
  2.7393 +       for (i=0; i<cblen; i++) {
  2.7394 +
  2.7395 +
  2.7396 +
  2.7397 +Andersen, et al.              Experimental                    [Page 132]
  2.7398 +
  2.7399 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7400 +
  2.7401 +
  2.7402 +           measure=(in-scale*cb[i])*(in-scale*cb[i]);
  2.7403 +
  2.7404 +           if (measure<minmeasure) {
  2.7405 +               tindex=i;
  2.7406 +               minmeasure=measure;
  2.7407 +           }
  2.7408 +       }
  2.7409 +       *index=tindex;
  2.7410 +
  2.7411 +       /* return the quantized value */
  2.7412 +
  2.7413 +       return scale*cb[tindex];
  2.7414 +   }
  2.7415 +
  2.7416 +   /*----------------------------------------------------------------*
  2.7417 +    *  decoder for quantized gains in the gain-shape coding of
  2.7418 +    *  residual
  2.7419 +    *---------------------------------------------------------------*/
  2.7420 +
  2.7421 +   float gaindequant(  /* (o) quantized gain value */
  2.7422 +       int index,      /* (i) quantization index */
  2.7423 +       float maxIn,/* (i) maximum of unquantized gain */
  2.7424 +       int cblen       /* (i) number of quantization indices */
  2.7425 +   ){
  2.7426 +       float scale;
  2.7427 +
  2.7428 +       /* obtain correct scale factor */
  2.7429 +
  2.7430 +       scale=(float)fabs(maxIn);
  2.7431 +
  2.7432 +       if (scale<0.1) {
  2.7433 +           scale=(float)0.1;
  2.7434 +       }
  2.7435 +
  2.7436 +       /* select the quantization table and return the decoded value */
  2.7437 +
  2.7438 +       if (cblen==8) {
  2.7439 +           return scale*gain_sq3Tbl[index];
  2.7440 +       } else if (cblen==16) {
  2.7441 +           return scale*gain_sq4Tbl[index];
  2.7442 +       }
  2.7443 +       else if (cblen==32) {
  2.7444 +           return scale*gain_sq5Tbl[index];
  2.7445 +       }
  2.7446 +
  2.7447 +       return 0.0;
  2.7448 +   }
  2.7449 +
  2.7450 +
  2.7451 +
  2.7452 +
  2.7453 +Andersen, et al.              Experimental                    [Page 133]
  2.7454 +
  2.7455 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7456 +
  2.7457 +
  2.7458 +A.23.  getCBvec.h
  2.7459 +
  2.7460 +   /******************************************************************
  2.7461 +
  2.7462 +       iLBC Speech Coder ANSI-C Source Code
  2.7463 +
  2.7464 +       getCBvec.h
  2.7465 +
  2.7466 +       Copyright (C) The Internet Society (2004).
  2.7467 +       All Rights Reserved.
  2.7468 +
  2.7469 +   ******************************************************************/
  2.7470 +
  2.7471 +   #ifndef __iLBC_GETCBVEC_H
  2.7472 +   #define __iLBC_GETCBVEC_H
  2.7473 +
  2.7474 +   void getCBvec(
  2.7475 +       float *cbvec,   /* (o) Constructed codebook vector */
  2.7476 +       float *mem,     /* (i) Codebook buffer */
  2.7477 +       int index,      /* (i) Codebook index */
  2.7478 +       int lMem,       /* (i) Length of codebook buffer */
  2.7479 +       int cbveclen/* (i) Codebook vector length */
  2.7480 +   );
  2.7481 +
  2.7482 +   #endif
  2.7483 +
  2.7484 +A.24.  getCBvec.c
  2.7485 +
  2.7486 +   /******************************************************************
  2.7487 +
  2.7488 +       iLBC Speech Coder ANSI-C Source Code
  2.7489 +
  2.7490 +       getCBvec.c
  2.7491 +
  2.7492 +       Copyright (C) The Internet Society (2004).
  2.7493 +       All Rights Reserved.
  2.7494 +
  2.7495 +   ******************************************************************/
  2.7496 +
  2.7497 +   #include "iLBC_define.h"
  2.7498 +   #include "constants.h"
  2.7499 +   #include <string.h>
  2.7500 +
  2.7501 +   /*----------------------------------------------------------------*
  2.7502 +    *  Construct codebook vector for given index.
  2.7503 +    *---------------------------------------------------------------*/
  2.7504 +
  2.7505 +   void getCBvec(
  2.7506 +
  2.7507 +
  2.7508 +
  2.7509 +Andersen, et al.              Experimental                    [Page 134]
  2.7510 +
  2.7511 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7512 +
  2.7513 +
  2.7514 +       float *cbvec,   /* (o) Constructed codebook vector */
  2.7515 +       float *mem,     /* (i) Codebook buffer */
  2.7516 +       int index,      /* (i) Codebook index */
  2.7517 +       int lMem,       /* (i) Length of codebook buffer */
  2.7518 +       int cbveclen/* (i) Codebook vector length */
  2.7519 +   ){
  2.7520 +       int j, k, n, memInd, sFilt;
  2.7521 +       float tmpbuf[CB_MEML];
  2.7522 +       int base_size;
  2.7523 +       int ilow, ihigh;
  2.7524 +       float alfa, alfa1;
  2.7525 +
  2.7526 +       /* Determine size of codebook sections */
  2.7527 +
  2.7528 +       base_size=lMem-cbveclen+1;
  2.7529 +
  2.7530 +       if (cbveclen==SUBL) {
  2.7531 +           base_size+=cbveclen/2;
  2.7532 +       }
  2.7533 +
  2.7534 +       /* No filter -> First codebook section */
  2.7535 +
  2.7536 +       if (index<lMem-cbveclen+1) {
  2.7537 +
  2.7538 +           /* first non-interpolated vectors */
  2.7539 +
  2.7540 +           k=index+cbveclen;
  2.7541 +           /* get vector */
  2.7542 +           memcpy(cbvec, mem+lMem-k, cbveclen*sizeof(float));
  2.7543 +
  2.7544 +       } else if (index < base_size) {
  2.7545 +
  2.7546 +           k=2*(index-(lMem-cbveclen+1))+cbveclen;
  2.7547 +
  2.7548 +           ihigh=k/2;
  2.7549 +           ilow=ihigh-5;
  2.7550 +
  2.7551 +           /* Copy first noninterpolated part */
  2.7552 +
  2.7553 +           memcpy(cbvec, mem+lMem-k/2, ilow*sizeof(float));
  2.7554 +
  2.7555 +           /* interpolation */
  2.7556 +
  2.7557 +           alfa1=(float)0.2;
  2.7558 +           alfa=0.0;
  2.7559 +           for (j=ilow; j<ihigh; j++) {
  2.7560 +               cbvec[j]=((float)1.0-alfa)*mem[lMem-k/2+j]+
  2.7561 +                   alfa*mem[lMem-k+j];
  2.7562 +
  2.7563 +
  2.7564 +
  2.7565 +Andersen, et al.              Experimental                    [Page 135]
  2.7566 +
  2.7567 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7568 +
  2.7569 +
  2.7570 +               alfa+=alfa1;
  2.7571 +           }
  2.7572 +
  2.7573 +           /* Copy second noninterpolated part */
  2.7574 +
  2.7575 +           memcpy(cbvec+ihigh, mem+lMem-k+ihigh,
  2.7576 +               (cbveclen-ihigh)*sizeof(float));
  2.7577 +
  2.7578 +       }
  2.7579 +
  2.7580 +       /* Higher codebook section based on filtering */
  2.7581 +
  2.7582 +       else {
  2.7583 +
  2.7584 +           /* first non-interpolated vectors */
  2.7585 +
  2.7586 +           if (index-base_size<lMem-cbveclen+1) {
  2.7587 +               float tempbuff2[CB_MEML+CB_FILTERLEN+1];
  2.7588 +               float *pos;
  2.7589 +               float *pp, *pp1;
  2.7590 +
  2.7591 +               memset(tempbuff2, 0,
  2.7592 +                   CB_HALFFILTERLEN*sizeof(float));
  2.7593 +               memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,
  2.7594 +                   lMem*sizeof(float));
  2.7595 +               memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,
  2.7596 +                   (CB_HALFFILTERLEN+1)*sizeof(float));
  2.7597 +
  2.7598 +               k=index-base_size+cbveclen;
  2.7599 +               sFilt=lMem-k;
  2.7600 +               memInd=sFilt+1-CB_HALFFILTERLEN;
  2.7601 +
  2.7602 +               /* do filtering */
  2.7603 +               pos=cbvec;
  2.7604 +               memset(pos, 0, cbveclen*sizeof(float));
  2.7605 +               for (n=0; n<cbveclen; n++) {
  2.7606 +                   pp=&tempbuff2[memInd+n+CB_HALFFILTERLEN];
  2.7607 +                   pp1=&cbfiltersTbl[CB_FILTERLEN-1];
  2.7608 +                   for (j=0; j<CB_FILTERLEN; j++) {
  2.7609 +                       (*pos)+=(*pp++)*(*pp1--);
  2.7610 +                   }
  2.7611 +                   pos++;
  2.7612 +               }
  2.7613 +           }
  2.7614 +
  2.7615 +           /* interpolated vectors */
  2.7616 +
  2.7617 +           else {
  2.7618 +
  2.7619 +
  2.7620 +
  2.7621 +Andersen, et al.              Experimental                    [Page 136]
  2.7622 +
  2.7623 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7624 +
  2.7625 +
  2.7626 +               float tempbuff2[CB_MEML+CB_FILTERLEN+1];
  2.7627 +
  2.7628 +               float *pos;
  2.7629 +               float *pp, *pp1;
  2.7630 +               int i;
  2.7631 +
  2.7632 +               memset(tempbuff2, 0,
  2.7633 +                   CB_HALFFILTERLEN*sizeof(float));
  2.7634 +               memcpy(&tempbuff2[CB_HALFFILTERLEN], mem,
  2.7635 +                   lMem*sizeof(float));
  2.7636 +               memset(&tempbuff2[lMem+CB_HALFFILTERLEN], 0,
  2.7637 +                   (CB_HALFFILTERLEN+1)*sizeof(float));
  2.7638 +
  2.7639 +               k=2*(index-base_size-
  2.7640 +                   (lMem-cbveclen+1))+cbveclen;
  2.7641 +               sFilt=lMem-k;
  2.7642 +               memInd=sFilt+1-CB_HALFFILTERLEN;
  2.7643 +
  2.7644 +               /* do filtering */
  2.7645 +               pos=&tmpbuf[sFilt];
  2.7646 +               memset(pos, 0, k*sizeof(float));
  2.7647 +               for (i=0; i<k; i++) {
  2.7648 +                   pp=&tempbuff2[memInd+i+CB_HALFFILTERLEN];
  2.7649 +                   pp1=&cbfiltersTbl[CB_FILTERLEN-1];
  2.7650 +                   for (j=0; j<CB_FILTERLEN; j++) {
  2.7651 +                       (*pos)+=(*pp++)*(*pp1--);
  2.7652 +                   }
  2.7653 +                   pos++;
  2.7654 +               }
  2.7655 +
  2.7656 +               ihigh=k/2;
  2.7657 +               ilow=ihigh-5;
  2.7658 +
  2.7659 +               /* Copy first noninterpolated part */
  2.7660 +
  2.7661 +               memcpy(cbvec, tmpbuf+lMem-k/2,
  2.7662 +                   ilow*sizeof(float));
  2.7663 +
  2.7664 +               /* interpolation */
  2.7665 +
  2.7666 +               alfa1=(float)0.2;
  2.7667 +               alfa=0.0;
  2.7668 +               for (j=ilow; j<ihigh; j++) {
  2.7669 +                   cbvec[j]=((float)1.0-alfa)*
  2.7670 +                       tmpbuf[lMem-k/2+j]+alfa*tmpbuf[lMem-k+j];
  2.7671 +                   alfa+=alfa1;
  2.7672 +               }
  2.7673 +
  2.7674 +
  2.7675 +
  2.7676 +
  2.7677 +Andersen, et al.              Experimental                    [Page 137]
  2.7678 +
  2.7679 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7680 +
  2.7681 +
  2.7682 +               /* Copy second noninterpolated part */
  2.7683 +
  2.7684 +               memcpy(cbvec+ihigh, tmpbuf+lMem-k+ihigh,
  2.7685 +                   (cbveclen-ihigh)*sizeof(float));
  2.7686 +           }
  2.7687 +       }
  2.7688 +   }
  2.7689 +
  2.7690 +A.25.  helpfun.h
  2.7691 +
  2.7692 +   /******************************************************************
  2.7693 +
  2.7694 +       iLBC Speech Coder ANSI-C Source Code
  2.7695 +
  2.7696 +       helpfun.h
  2.7697 +
  2.7698 +       Copyright (C) The Internet Society (2004).
  2.7699 +       All Rights Reserved.
  2.7700 +
  2.7701 +   ******************************************************************/
  2.7702 +
  2.7703 +   #ifndef __iLBC_HELPFUN_H
  2.7704 +   #define __iLBC_HELPFUN_H
  2.7705 +
  2.7706 +   void autocorr(
  2.7707 +       float *r,       /* (o) autocorrelation vector */
  2.7708 +       const float *x, /* (i) data vector */
  2.7709 +       int N,          /* (i) length of data vector */
  2.7710 +       int order       /* largest lag for calculated
  2.7711 +                          autocorrelations */
  2.7712 +   );
  2.7713 +
  2.7714 +   void window(
  2.7715 +       float *z,       /* (o) the windowed data */
  2.7716 +       const float *x, /* (i) the original data vector */
  2.7717 +       const float *y, /* (i) the window */
  2.7718 +       int N           /* (i) length of all vectors */
  2.7719 +   );
  2.7720 +
  2.7721 +   void levdurb(
  2.7722 +       float *a,       /* (o) lpc coefficient vector starting
  2.7723 +                              with 1.0 */
  2.7724 +       float *k,       /* (o) reflection coefficients */
  2.7725 +       float *r,       /* (i) autocorrelation vector */
  2.7726 +       int order       /* (i) order of lpc filter */
  2.7727 +   );
  2.7728 +
  2.7729 +   void interpolate(
  2.7730 +
  2.7731 +
  2.7732 +
  2.7733 +Andersen, et al.              Experimental                    [Page 138]
  2.7734 +
  2.7735 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7736 +
  2.7737 +
  2.7738 +       float *out,     /* (o) the interpolated vector */
  2.7739 +       float *in1,     /* (i) the first vector for the
  2.7740 +                              interpolation */
  2.7741 +       float *in2,     /* (i) the second vector for the
  2.7742 +                              interpolation */
  2.7743 +       float coef,     /* (i) interpolation weights */
  2.7744 +       int length      /* (i) length of all vectors */
  2.7745 +   );
  2.7746 +
  2.7747 +   void bwexpand(
  2.7748 +       float *out,     /* (o) the bandwidth expanded lpc
  2.7749 +                              coefficients */
  2.7750 +       float *in,      /* (i) the lpc coefficients before bandwidth
  2.7751 +                              expansion */
  2.7752 +       float coef,     /* (i) the bandwidth expansion factor */
  2.7753 +       int length      /* (i) the length of lpc coefficient vectors */
  2.7754 +   );
  2.7755 +
  2.7756 +   void vq(
  2.7757 +       float *Xq,      /* (o) the quantized vector */
  2.7758 +       int *index,     /* (o) the quantization index */
  2.7759 +       const float *CB,/* (i) the vector quantization codebook */
  2.7760 +       float *X,       /* (i) the vector to quantize */
  2.7761 +       int n_cb,       /* (i) the number of vectors in the codebook */
  2.7762 +       int dim         /* (i) the dimension of all vectors */
  2.7763 +   );
  2.7764 +
  2.7765 +   void SplitVQ(
  2.7766 +       float *qX,      /* (o) the quantized vector */
  2.7767 +       int *index,     /* (o) a vector of indexes for all vector
  2.7768 +                              codebooks in the split */
  2.7769 +       float *X,       /* (i) the vector to quantize */
  2.7770 +       const float *CB,/* (i) the quantizer codebook */
  2.7771 +       int nsplit,     /* the number of vector splits */
  2.7772 +       const int *dim, /* the dimension of X and qX */
  2.7773 +       const int *cbsize /* the number of vectors in the codebook */
  2.7774 +   );
  2.7775 +
  2.7776 +
  2.7777 +   void sort_sq(
  2.7778 +       float *xq,      /* (o) the quantized value */
  2.7779 +       int *index,     /* (o) the quantization index */
  2.7780 +       float x,    /* (i) the value to quantize */
  2.7781 +       const float *cb,/* (i) the quantization codebook */
  2.7782 +       int cb_size     /* (i) the size of the quantization codebook */
  2.7783 +   );
  2.7784 +
  2.7785 +   int LSF_check(      /* (o) 1 for stable lsf vectors and 0 for
  2.7786 +
  2.7787 +
  2.7788 +
  2.7789 +Andersen, et al.              Experimental                    [Page 139]
  2.7790 +
  2.7791 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7792 +
  2.7793 +
  2.7794 +                              nonstable ones */
  2.7795 +       float *lsf,     /* (i) a table of lsf vectors */
  2.7796 +       int dim,    /* (i) the dimension of each lsf vector */
  2.7797 +       int NoAn    /* (i) the number of lsf vectors in the
  2.7798 +                              table */
  2.7799 +   );
  2.7800 +
  2.7801 +   #endif
  2.7802 +
  2.7803 +A.26.  helpfun.c
  2.7804 +
  2.7805 +   /******************************************************************
  2.7806 +
  2.7807 +       iLBC Speech Coder ANSI-C Source Code
  2.7808 +
  2.7809 +       helpfun.c
  2.7810 +
  2.7811 +       Copyright (C) The Internet Society (2004).
  2.7812 +       All Rights Reserved.
  2.7813 +
  2.7814 +   ******************************************************************/
  2.7815 +
  2.7816 +   #include <math.h>
  2.7817 +
  2.7818 +   #include "iLBC_define.h"
  2.7819 +   #include "constants.h"
  2.7820 +
  2.7821 +   /*----------------------------------------------------------------*
  2.7822 +    *  calculation of auto correlation
  2.7823 +    *---------------------------------------------------------------*/
  2.7824 +
  2.7825 +   void autocorr(
  2.7826 +       float *r,       /* (o) autocorrelation vector */
  2.7827 +       const float *x, /* (i) data vector */
  2.7828 +       int N,          /* (i) length of data vector */
  2.7829 +       int order       /* largest lag for calculated
  2.7830 +                          autocorrelations */
  2.7831 +   ){
  2.7832 +       int     lag, n;
  2.7833 +       float   sum;
  2.7834 +
  2.7835 +       for (lag = 0; lag <= order; lag++) {
  2.7836 +           sum = 0;
  2.7837 +           for (n = 0; n < N - lag; n++) {
  2.7838 +               sum += x[n] * x[n+lag];
  2.7839 +           }
  2.7840 +           r[lag] = sum;
  2.7841 +       }
  2.7842 +
  2.7843 +
  2.7844 +
  2.7845 +Andersen, et al.              Experimental                    [Page 140]
  2.7846 +
  2.7847 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7848 +
  2.7849 +
  2.7850 +   }
  2.7851 +
  2.7852 +   /*----------------------------------------------------------------*
  2.7853 +    *  window multiplication
  2.7854 +    *---------------------------------------------------------------*/
  2.7855 +
  2.7856 +   void window(
  2.7857 +       float *z,       /* (o) the windowed data */
  2.7858 +       const float *x, /* (i) the original data vector */
  2.7859 +       const float *y, /* (i) the window */
  2.7860 +       int N           /* (i) length of all vectors */
  2.7861 +   ){
  2.7862 +       int     i;
  2.7863 +
  2.7864 +       for (i = 0; i < N; i++) {
  2.7865 +           z[i] = x[i] * y[i];
  2.7866 +       }
  2.7867 +   }
  2.7868 +
  2.7869 +   /*----------------------------------------------------------------*
  2.7870 +    *  levinson-durbin solution for lpc coefficients
  2.7871 +    *---------------------------------------------------------------*/
  2.7872 +
  2.7873 +   void levdurb(
  2.7874 +       float *a,       /* (o) lpc coefficient vector starting
  2.7875 +                              with 1.0 */
  2.7876 +       float *k,       /* (o) reflection coefficients */
  2.7877 +       float *r,       /* (i) autocorrelation vector */
  2.7878 +       int order       /* (i) order of lpc filter */
  2.7879 +   ){
  2.7880 +       float  sum, alpha;
  2.7881 +       int     m, m_h, i;
  2.7882 +
  2.7883 +       a[0] = 1.0;
  2.7884 +
  2.7885 +       if (r[0] < EPS) { /* if r[0] <= 0, set LPC coeff. to zero */
  2.7886 +           for (i = 0; i < order; i++) {
  2.7887 +               k[i] = 0;
  2.7888 +               a[i+1] = 0;
  2.7889 +           }
  2.7890 +       } else {
  2.7891 +           a[1] = k[0] = -r[1]/r[0];
  2.7892 +           alpha = r[0] + r[1] * k[0];
  2.7893 +           for (m = 1; m < order; m++){
  2.7894 +               sum = r[m + 1];
  2.7895 +               for (i = 0; i < m; i++){
  2.7896 +                   sum += a[i+1] * r[m - i];
  2.7897 +               }
  2.7898 +
  2.7899 +
  2.7900 +
  2.7901 +Andersen, et al.              Experimental                    [Page 141]
  2.7902 +
  2.7903 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7904 +
  2.7905 +
  2.7906 +               k[m] = -sum / alpha;
  2.7907 +               alpha += k[m] * sum;
  2.7908 +               m_h = (m + 1) >> 1;
  2.7909 +               for (i = 0; i < m_h; i++){
  2.7910 +                   sum = a[i+1] + k[m] * a[m - i];
  2.7911 +                   a[m - i] += k[m] * a[i+1];
  2.7912 +                   a[i+1] = sum;
  2.7913 +               }
  2.7914 +               a[m+1] = k[m];
  2.7915 +           }
  2.7916 +       }
  2.7917 +   }
  2.7918 +
  2.7919 +   /*----------------------------------------------------------------*
  2.7920 +    *  interpolation between vectors
  2.7921 +    *---------------------------------------------------------------*/
  2.7922 +
  2.7923 +   void interpolate(
  2.7924 +       float *out,      /* (o) the interpolated vector */
  2.7925 +       float *in1,     /* (i) the first vector for the
  2.7926 +                              interpolation */
  2.7927 +       float *in2,     /* (i) the second vector for the
  2.7928 +                              interpolation */
  2.7929 +       float coef,      /* (i) interpolation weights */
  2.7930 +       int length      /* (i) length of all vectors */
  2.7931 +   ){
  2.7932 +       int i;
  2.7933 +       float invcoef;
  2.7934 +
  2.7935 +       invcoef = (float)1.0 - coef;
  2.7936 +       for (i = 0; i < length; i++) {
  2.7937 +           out[i] = coef * in1[i] + invcoef * in2[i];
  2.7938 +       }
  2.7939 +   }
  2.7940 +
  2.7941 +   /*----------------------------------------------------------------*
  2.7942 +    *  lpc bandwidth expansion
  2.7943 +    *---------------------------------------------------------------*/
  2.7944 +
  2.7945 +   void bwexpand(
  2.7946 +       float *out,      /* (o) the bandwidth expanded lpc
  2.7947 +                              coefficients */
  2.7948 +       float *in,      /* (i) the lpc coefficients before bandwidth
  2.7949 +                              expansion */
  2.7950 +       float coef,     /* (i) the bandwidth expansion factor */
  2.7951 +       int length      /* (i) the length of lpc coefficient vectors */
  2.7952 +   ){
  2.7953 +       int i;
  2.7954 +
  2.7955 +
  2.7956 +
  2.7957 +Andersen, et al.              Experimental                    [Page 142]
  2.7958 +
  2.7959 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.7960 +
  2.7961 +
  2.7962 +       float  chirp;
  2.7963 +
  2.7964 +       chirp = coef;
  2.7965 +
  2.7966 +       out[0] = in[0];
  2.7967 +       for (i = 1; i < length; i++) {
  2.7968 +           out[i] = chirp * in[i];
  2.7969 +           chirp *= coef;
  2.7970 +       }
  2.7971 +   }
  2.7972 +
  2.7973 +   /*----------------------------------------------------------------*
  2.7974 +    *  vector quantization
  2.7975 +    *---------------------------------------------------------------*/
  2.7976 +
  2.7977 +   void vq(
  2.7978 +       float *Xq,      /* (o) the quantized vector */
  2.7979 +       int *index,     /* (o) the quantization index */
  2.7980 +       const float *CB,/* (i) the vector quantization codebook */
  2.7981 +       float *X,       /* (i) the vector to quantize */
  2.7982 +       int n_cb,       /* (i) the number of vectors in the codebook */
  2.7983 +       int dim         /* (i) the dimension of all vectors */
  2.7984 +   ){
  2.7985 +       int     i, j;
  2.7986 +       int     pos, minindex;
  2.7987 +       float   dist, tmp, mindist;
  2.7988 +
  2.7989 +       pos = 0;
  2.7990 +       mindist = FLOAT_MAX;
  2.7991 +       minindex = 0;
  2.7992 +       for (j = 0; j < n_cb; j++) {
  2.7993 +           dist = X[0] - CB[pos];
  2.7994 +           dist *= dist;
  2.7995 +           for (i = 1; i < dim; i++) {
  2.7996 +               tmp = X[i] - CB[pos + i];
  2.7997 +               dist += tmp*tmp;
  2.7998 +           }
  2.7999 +
  2.8000 +           if (dist < mindist) {
  2.8001 +               mindist = dist;
  2.8002 +               minindex = j;
  2.8003 +           }
  2.8004 +           pos += dim;
  2.8005 +       }
  2.8006 +       for (i = 0; i < dim; i++) {
  2.8007 +           Xq[i] = CB[minindex*dim + i];
  2.8008 +       }
  2.8009 +       *index = minindex;
  2.8010 +
  2.8011 +
  2.8012 +
  2.8013 +Andersen, et al.              Experimental                    [Page 143]
  2.8014 +
  2.8015 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8016 +
  2.8017 +
  2.8018 +   }
  2.8019 +
  2.8020 +   /*----------------------------------------------------------------*
  2.8021 +    *  split vector quantization
  2.8022 +    *---------------------------------------------------------------*/
  2.8023 +
  2.8024 +   void SplitVQ(
  2.8025 +       float *qX,      /* (o) the quantized vector */
  2.8026 +       int *index,     /* (o) a vector of indexes for all vector
  2.8027 +                              codebooks in the split */
  2.8028 +       float *X,       /* (i) the vector to quantize */
  2.8029 +       const float *CB,/* (i) the quantizer codebook */
  2.8030 +       int nsplit,     /* the number of vector splits */
  2.8031 +       const int *dim, /* the dimension of X and qX */
  2.8032 +       const int *cbsize /* the number of vectors in the codebook */
  2.8033 +   ){
  2.8034 +       int    cb_pos, X_pos, i;
  2.8035 +
  2.8036 +       cb_pos = 0;
  2.8037 +       X_pos= 0;
  2.8038 +       for (i = 0; i < nsplit; i++) {
  2.8039 +           vq(qX + X_pos, index + i, CB + cb_pos, X + X_pos,
  2.8040 +               cbsize[i], dim[i]);
  2.8041 +           X_pos += dim[i];
  2.8042 +           cb_pos += dim[i] * cbsize[i];
  2.8043 +       }
  2.8044 +   }
  2.8045 +
  2.8046 +   /*----------------------------------------------------------------*
  2.8047 +    *  scalar quantization
  2.8048 +    *---------------------------------------------------------------*/
  2.8049 +
  2.8050 +   void sort_sq(
  2.8051 +       float *xq,      /* (o) the quantized value */
  2.8052 +       int *index,     /* (o) the quantization index */
  2.8053 +       float x,    /* (i) the value to quantize */
  2.8054 +       const float *cb,/* (i) the quantization codebook */
  2.8055 +       int cb_size      /* (i) the size of the quantization codebook */
  2.8056 +   ){
  2.8057 +       int i;
  2.8058 +
  2.8059 +       if (x <= cb[0]) {
  2.8060 +           *index = 0;
  2.8061 +           *xq = cb[0];
  2.8062 +       } else {
  2.8063 +           i = 0;
  2.8064 +           while ((x > cb[i]) && i < cb_size - 1) {
  2.8065 +               i++;
  2.8066 +
  2.8067 +
  2.8068 +
  2.8069 +Andersen, et al.              Experimental                    [Page 144]
  2.8070 +
  2.8071 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8072 +
  2.8073 +
  2.8074 +           }
  2.8075 +
  2.8076 +           if (x > ((cb[i] + cb[i - 1])/2)) {
  2.8077 +               *index = i;
  2.8078 +               *xq = cb[i];
  2.8079 +           } else {
  2.8080 +               *index = i - 1;
  2.8081 +               *xq = cb[i - 1];
  2.8082 +           }
  2.8083 +       }
  2.8084 +   }
  2.8085 +
  2.8086 +   /*----------------------------------------------------------------*
  2.8087 +    *  check for stability of lsf coefficients
  2.8088 +    *---------------------------------------------------------------*/
  2.8089 +
  2.8090 +   int LSF_check(    /* (o) 1 for stable lsf vectors and 0 for
  2.8091 +                              nonstable ones */
  2.8092 +       float *lsf,     /* (i) a table of lsf vectors */
  2.8093 +       int dim,    /* (i) the dimension of each lsf vector */
  2.8094 +       int NoAn    /* (i) the number of lsf vectors in the
  2.8095 +                              table */
  2.8096 +   ){
  2.8097 +       int k,n,m, Nit=2, change=0,pos;
  2.8098 +       float tmp;
  2.8099 +       static float eps=(float)0.039; /* 50 Hz */
  2.8100 +       static float eps2=(float)0.0195;
  2.8101 +       static float maxlsf=(float)3.14; /* 4000 Hz */
  2.8102 +       static float minlsf=(float)0.01; /* 0 Hz */
  2.8103 +
  2.8104 +       /* LSF separation check*/
  2.8105 +
  2.8106 +       for (n=0; n<Nit; n++) { /* Run through a couple of times */
  2.8107 +           for (m=0; m<NoAn; m++) { /* Number of analyses per frame */
  2.8108 +               for (k=0; k<(dim-1); k++) {
  2.8109 +                   pos=m*dim+k;
  2.8110 +
  2.8111 +                   if ((lsf[pos+1]-lsf[pos])<eps) {
  2.8112 +
  2.8113 +                       if (lsf[pos+1]<lsf[pos]) {
  2.8114 +                           tmp=lsf[pos+1];
  2.8115 +                           lsf[pos+1]= lsf[pos]+eps2;
  2.8116 +                           lsf[pos]= lsf[pos+1]-eps2;
  2.8117 +                       } else {
  2.8118 +                           lsf[pos]-=eps2;
  2.8119 +                           lsf[pos+1]+=eps2;
  2.8120 +                       }
  2.8121 +                       change=1;
  2.8122 +
  2.8123 +
  2.8124 +
  2.8125 +Andersen, et al.              Experimental                    [Page 145]
  2.8126 +
  2.8127 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8128 +
  2.8129 +
  2.8130 +                   }
  2.8131 +
  2.8132 +                   if (lsf[pos]<minlsf) {
  2.8133 +                       lsf[pos]=minlsf;
  2.8134 +                       change=1;
  2.8135 +                   }
  2.8136 +
  2.8137 +                   if (lsf[pos]>maxlsf) {
  2.8138 +                       lsf[pos]=maxlsf;
  2.8139 +                       change=1;
  2.8140 +                   }
  2.8141 +               }
  2.8142 +           }
  2.8143 +       }
  2.8144 +
  2.8145 +       return change;
  2.8146 +   }
  2.8147 +
  2.8148 +A.27.  hpInput.h
  2.8149 +
  2.8150 +   /******************************************************************
  2.8151 +
  2.8152 +       iLBC Speech Coder ANSI-C Source Code
  2.8153 +
  2.8154 +       hpInput.h
  2.8155 +
  2.8156 +       Copyright (C) The Internet Society (2004).
  2.8157 +       All Rights Reserved.
  2.8158 +
  2.8159 +   ******************************************************************/
  2.8160 +
  2.8161 +   #ifndef __iLBC_HPINPUT_H
  2.8162 +   #define __iLBC_HPINPUT_H
  2.8163 +
  2.8164 +   void hpInput(
  2.8165 +       float *In,  /* (i) vector to filter */
  2.8166 +       int len,    /* (i) length of vector to filter */
  2.8167 +       float *Out, /* (o) the resulting filtered vector */
  2.8168 +       float *mem  /* (i/o) the filter state */
  2.8169 +   );
  2.8170 +
  2.8171 +   #endif
  2.8172 +
  2.8173 +A.28.  hpInput.c
  2.8174 +
  2.8175 +   /******************************************************************
  2.8176 +
  2.8177 +       iLBC Speech Coder ANSI-C Source Code
  2.8178 +
  2.8179 +
  2.8180 +
  2.8181 +Andersen, et al.              Experimental                    [Page 146]
  2.8182 +
  2.8183 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8184 +
  2.8185 +
  2.8186 +       hpInput.c
  2.8187 +
  2.8188 +       Copyright (C) The Internet Society (2004).
  2.8189 +       All Rights Reserved.
  2.8190 +
  2.8191 +   ******************************************************************/
  2.8192 +
  2.8193 +   #include "constants.h"
  2.8194 +
  2.8195 +   /*----------------------------------------------------------------*
  2.8196 +    *  Input high-pass filter
  2.8197 +    *---------------------------------------------------------------*/
  2.8198 +
  2.8199 +   void hpInput(
  2.8200 +       float *In,  /* (i) vector to filter */
  2.8201 +       int len,    /* (i) length of vector to filter */
  2.8202 +       float *Out, /* (o) the resulting filtered vector */
  2.8203 +       float *mem  /* (i/o) the filter state */
  2.8204 +   ){
  2.8205 +       int i;
  2.8206 +       float *pi, *po;
  2.8207 +
  2.8208 +       /* all-zero section*/
  2.8209 +
  2.8210 +       pi = &In[0];
  2.8211 +       po = &Out[0];
  2.8212 +       for (i=0; i<len; i++) {
  2.8213 +           *po = hpi_zero_coefsTbl[0] * (*pi);
  2.8214 +           *po += hpi_zero_coefsTbl[1] * mem[0];
  2.8215 +           *po += hpi_zero_coefsTbl[2] * mem[1];
  2.8216 +
  2.8217 +           mem[1] = mem[0];
  2.8218 +           mem[0] = *pi;
  2.8219 +           po++;
  2.8220 +           pi++;
  2.8221 +
  2.8222 +       }
  2.8223 +
  2.8224 +       /* all-pole section*/
  2.8225 +
  2.8226 +       po = &Out[0];
  2.8227 +       for (i=0; i<len; i++) {
  2.8228 +           *po -= hpi_pole_coefsTbl[1] * mem[2];
  2.8229 +           *po -= hpi_pole_coefsTbl[2] * mem[3];
  2.8230 +
  2.8231 +           mem[3] = mem[2];
  2.8232 +           mem[2] = *po;
  2.8233 +           po++;
  2.8234 +
  2.8235 +
  2.8236 +
  2.8237 +Andersen, et al.              Experimental                    [Page 147]
  2.8238 +
  2.8239 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8240 +
  2.8241 +
  2.8242 +       }
  2.8243 +   }
  2.8244 +
  2.8245 +A.29.  hpOutput.h
  2.8246 +
  2.8247 +   /******************************************************************
  2.8248 +
  2.8249 +       iLBC Speech Coder ANSI-C Source Code
  2.8250 +
  2.8251 +       hpOutput.h
  2.8252 +
  2.8253 +       Copyright (C) The Internet Society (2004).
  2.8254 +       All Rights Reserved.
  2.8255 +
  2.8256 +   ******************************************************************/
  2.8257 +
  2.8258 +   #ifndef __iLBC_HPOUTPUT_H
  2.8259 +   #define __iLBC_HPOUTPUT_H
  2.8260 +
  2.8261 +   void hpOutput(
  2.8262 +       float *In,  /* (i) vector to filter */
  2.8263 +       int len,/* (i) length of vector to filter */
  2.8264 +       float *Out, /* (o) the resulting filtered vector */
  2.8265 +       float *mem  /* (i/o) the filter state */
  2.8266 +   );
  2.8267 +
  2.8268 +   #endif
  2.8269 +
  2.8270 +A.30.  hpOutput.c
  2.8271 +
  2.8272 +   /******************************************************************
  2.8273 +
  2.8274 +       iLBC Speech Coder ANSI-C Source Code
  2.8275 +
  2.8276 +       hpOutput.c
  2.8277 +
  2.8278 +       Copyright (C) The Internet Society (2004).
  2.8279 +       All Rights Reserved.
  2.8280 +
  2.8281 +   ******************************************************************/
  2.8282 +
  2.8283 +   #include "constants.h"
  2.8284 +
  2.8285 +   /*----------------------------------------------------------------*
  2.8286 +    *  Output high-pass filter
  2.8287 +    *---------------------------------------------------------------*/
  2.8288 +
  2.8289 +   void hpOutput(
  2.8290 +
  2.8291 +
  2.8292 +
  2.8293 +Andersen, et al.              Experimental                    [Page 148]
  2.8294 +
  2.8295 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8296 +
  2.8297 +
  2.8298 +       float *In,  /* (i) vector to filter */
  2.8299 +       int len,/* (i) length of vector to filter */
  2.8300 +       float *Out, /* (o) the resulting filtered vector */
  2.8301 +       float *mem  /* (i/o) the filter state */
  2.8302 +   ){
  2.8303 +       int i;
  2.8304 +       float *pi, *po;
  2.8305 +
  2.8306 +       /* all-zero section*/
  2.8307 +
  2.8308 +       pi = &In[0];
  2.8309 +       po = &Out[0];
  2.8310 +       for (i=0; i<len; i++) {
  2.8311 +           *po = hpo_zero_coefsTbl[0] * (*pi);
  2.8312 +           *po += hpo_zero_coefsTbl[1] * mem[0];
  2.8313 +           *po += hpo_zero_coefsTbl[2] * mem[1];
  2.8314 +
  2.8315 +           mem[1] = mem[0];
  2.8316 +           mem[0] = *pi;
  2.8317 +           po++;
  2.8318 +           pi++;
  2.8319 +
  2.8320 +       }
  2.8321 +
  2.8322 +       /* all-pole section*/
  2.8323 +
  2.8324 +       po = &Out[0];
  2.8325 +       for (i=0; i<len; i++) {
  2.8326 +           *po -= hpo_pole_coefsTbl[1] * mem[2];
  2.8327 +           *po -= hpo_pole_coefsTbl[2] * mem[3];
  2.8328 +
  2.8329 +           mem[3] = mem[2];
  2.8330 +           mem[2] = *po;
  2.8331 +           po++;
  2.8332 +       }
  2.8333 +   }
  2.8334 +
  2.8335 +A.31.  iCBConstruct.h
  2.8336 +
  2.8337 +   /******************************************************************
  2.8338 +
  2.8339 +       iLBC Speech Coder ANSI-C Source Code
  2.8340 +
  2.8341 +       iCBConstruct.h
  2.8342 +
  2.8343 +       Copyright (C) The Internet Society (2004).
  2.8344 +       All Rights Reserved.
  2.8345 +
  2.8346 +
  2.8347 +
  2.8348 +
  2.8349 +Andersen, et al.              Experimental                    [Page 149]
  2.8350 +
  2.8351 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8352 +
  2.8353 +
  2.8354 +   ******************************************************************/
  2.8355 +
  2.8356 +   #ifndef __iLBC_ICBCONSTRUCT_H
  2.8357 +   #define __iLBC_ICBCONSTRUCT_H
  2.8358 +
  2.8359 +   void index_conv_enc(
  2.8360 +       int *index          /* (i/o) Codebook indexes */
  2.8361 +   );
  2.8362 +
  2.8363 +   void index_conv_dec(
  2.8364 +       int *index          /* (i/o) Codebook indexes */
  2.8365 +   );
  2.8366 +
  2.8367 +   void iCBConstruct(
  2.8368 +       float *decvector,   /* (o) Decoded vector */
  2.8369 +       int *index,         /* (i) Codebook indices */
  2.8370 +       int *gain_index,/* (i) Gain quantization indices */
  2.8371 +       float *mem,         /* (i) Buffer for codevector construction */
  2.8372 +       int lMem,           /* (i) Length of buffer */
  2.8373 +       int veclen,         /* (i) Length of vector */
  2.8374 +       int nStages         /* (i) Number of codebook stages */
  2.8375 +   );
  2.8376 +
  2.8377 +   #endif
  2.8378 +
  2.8379 +A.32.  iCBConstruct.c
  2.8380 +
  2.8381 +   /******************************************************************
  2.8382 +
  2.8383 +       iLBC Speech Coder ANSI-C Source Code
  2.8384 +
  2.8385 +       iCBConstruct.c
  2.8386 +
  2.8387 +       Copyright (C) The Internet Society (2004).
  2.8388 +       All Rights Reserved.
  2.8389 +
  2.8390 +   ******************************************************************/
  2.8391 +
  2.8392 +   #include <math.h>
  2.8393 +
  2.8394 +   #include "iLBC_define.h"
  2.8395 +   #include "gainquant.h"
  2.8396 +   #include "getCBvec.h"
  2.8397 +
  2.8398 +   /*----------------------------------------------------------------*
  2.8399 +    *  Convert the codebook indexes to make the search easier
  2.8400 +    *---------------------------------------------------------------*/
  2.8401 +
  2.8402 +
  2.8403 +
  2.8404 +
  2.8405 +Andersen, et al.              Experimental                    [Page 150]
  2.8406 +
  2.8407 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8408 +
  2.8409 +
  2.8410 +   void index_conv_enc(
  2.8411 +       int *index          /* (i/o) Codebook indexes */
  2.8412 +   ){
  2.8413 +       int k;
  2.8414 +
  2.8415 +       for (k=1; k<CB_NSTAGES; k++) {
  2.8416 +
  2.8417 +           if ((index[k]>=108)&&(index[k]<172)) {
  2.8418 +               index[k]-=64;
  2.8419 +           } else if (index[k]>=236) {
  2.8420 +               index[k]-=128;
  2.8421 +           } else {
  2.8422 +               /* ERROR */
  2.8423 +           }
  2.8424 +       }
  2.8425 +   }
  2.8426 +
  2.8427 +   void index_conv_dec(
  2.8428 +       int *index          /* (i/o) Codebook indexes */
  2.8429 +   ){
  2.8430 +       int k;
  2.8431 +
  2.8432 +       for (k=1; k<CB_NSTAGES; k++) {
  2.8433 +
  2.8434 +           if ((index[k]>=44)&&(index[k]<108)) {
  2.8435 +               index[k]+=64;
  2.8436 +           } else if ((index[k]>=108)&&(index[k]<128)) {
  2.8437 +               index[k]+=128;
  2.8438 +           } else {
  2.8439 +               /* ERROR */
  2.8440 +           }
  2.8441 +       }
  2.8442 +   }
  2.8443 +
  2.8444 +   /*----------------------------------------------------------------*
  2.8445 +    *  Construct decoded vector from codebook and gains.
  2.8446 +    *---------------------------------------------------------------*/
  2.8447 +
  2.8448 +   void iCBConstruct(
  2.8449 +       float *decvector,   /* (o) Decoded vector */
  2.8450 +       int *index,         /* (i) Codebook indices */
  2.8451 +       int *gain_index,/* (i) Gain quantization indices */
  2.8452 +       float *mem,         /* (i) Buffer for codevector construction */
  2.8453 +       int lMem,           /* (i) Length of buffer */
  2.8454 +       int veclen,         /* (i) Length of vector */
  2.8455 +       int nStages         /* (i) Number of codebook stages */
  2.8456 +   ){
  2.8457 +       int j,k;
  2.8458 +
  2.8459 +
  2.8460 +
  2.8461 +Andersen, et al.              Experimental                    [Page 151]
  2.8462 +
  2.8463 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8464 +
  2.8465 +
  2.8466 +       float gain[CB_NSTAGES];
  2.8467 +       float cbvec[SUBL];
  2.8468 +
  2.8469 +       /* gain de-quantization */
  2.8470 +
  2.8471 +       gain[0] = gaindequant(gain_index[0], 1.0, 32);
  2.8472 +       if (nStages > 1) {
  2.8473 +           gain[1] = gaindequant(gain_index[1],
  2.8474 +               (float)fabs(gain[0]), 16);
  2.8475 +       }
  2.8476 +       if (nStages > 2) {
  2.8477 +           gain[2] = gaindequant(gain_index[2],
  2.8478 +               (float)fabs(gain[1]), 8);
  2.8479 +       }
  2.8480 +
  2.8481 +       /* codebook vector construction and construction of
  2.8482 +       total vector */
  2.8483 +
  2.8484 +       getCBvec(cbvec, mem, index[0], lMem, veclen);
  2.8485 +       for (j=0;j<veclen;j++){
  2.8486 +           decvector[j] = gain[0]*cbvec[j];
  2.8487 +       }
  2.8488 +       if (nStages > 1) {
  2.8489 +           for (k=1; k<nStages; k++) {
  2.8490 +               getCBvec(cbvec, mem, index[k], lMem, veclen);
  2.8491 +               for (j=0;j<veclen;j++) {
  2.8492 +                   decvector[j] += gain[k]*cbvec[j];
  2.8493 +               }
  2.8494 +           }
  2.8495 +       }
  2.8496 +   }
  2.8497 +
  2.8498 +A.33.  iCBSearch.h
  2.8499 +
  2.8500 +   /******************************************************************
  2.8501 +
  2.8502 +       iLBC Speech Coder ANSI-C Source Code
  2.8503 +
  2.8504 +       iCBSearch.h
  2.8505 +
  2.8506 +       Copyright (C) The Internet Society (2004).
  2.8507 +       All Rights Reserved.
  2.8508 +
  2.8509 +   ******************************************************************/
  2.8510 +
  2.8511 +   #ifndef __iLBC_ICBSEARCH_H
  2.8512 +   #define __iLBC_ICBSEARCH_H
  2.8513 +
  2.8514 +
  2.8515 +
  2.8516 +
  2.8517 +Andersen, et al.              Experimental                    [Page 152]
  2.8518 +
  2.8519 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8520 +
  2.8521 +
  2.8522 +   void iCBSearch(
  2.8523 +       iLBC_Enc_Inst_t *iLBCenc_inst,
  2.8524 +                           /* (i) the encoder state structure */
  2.8525 +       int *index,         /* (o) Codebook indices */
  2.8526 +       int *gain_index,/* (o) Gain quantization indices */
  2.8527 +       float *intarget,/* (i) Target vector for encoding */
  2.8528 +       float *mem,         /* (i) Buffer for codebook construction */
  2.8529 +       int lMem,           /* (i) Length of buffer */
  2.8530 +       int lTarget,    /* (i) Length of vector */
  2.8531 +       int nStages,    /* (i) Number of codebook stages */
  2.8532 +       float *weightDenum, /* (i) weighting filter coefficients */
  2.8533 +       float *weightState, /* (i) weighting filter state */
  2.8534 +       int block           /* (i) the sub-block number */
  2.8535 +   );
  2.8536 +
  2.8537 +   #endif
  2.8538 +
  2.8539 +A.34.  iCBSearch.c
  2.8540 +
  2.8541 +   /******************************************************************
  2.8542 +
  2.8543 +       iLBC Speech Coder ANSI-C Source Code
  2.8544 +
  2.8545 +       iCBSearch.c
  2.8546 +
  2.8547 +       Copyright (C) The Internet Society (2004).
  2.8548 +       All Rights Reserved.
  2.8549 +
  2.8550 +   ******************************************************************/
  2.8551 +
  2.8552 +   #include <math.h>
  2.8553 +   #include <string.h>
  2.8554 +
  2.8555 +   #include "iLBC_define.h"
  2.8556 +   #include "gainquant.h"
  2.8557 +   #include "createCB.h"
  2.8558 +   #include "filter.h"
  2.8559 +   #include "constants.h"
  2.8560 +
  2.8561 +   /*----------------------------------------------------------------*
  2.8562 +    *  Search routine for codebook encoding and gain quantization.
  2.8563 +    *---------------------------------------------------------------*/
  2.8564 +
  2.8565 +   void iCBSearch(
  2.8566 +       iLBC_Enc_Inst_t *iLBCenc_inst,
  2.8567 +                           /* (i) the encoder state structure */
  2.8568 +       int *index,         /* (o) Codebook indices */
  2.8569 +       int *gain_index,/* (o) Gain quantization indices */
  2.8570 +
  2.8571 +
  2.8572 +
  2.8573 +Andersen, et al.              Experimental                    [Page 153]
  2.8574 +
  2.8575 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8576 +
  2.8577 +
  2.8578 +       float *intarget,/* (i) Target vector for encoding */
  2.8579 +       float *mem,         /* (i) Buffer for codebook construction */
  2.8580 +       int lMem,           /* (i) Length of buffer */
  2.8581 +       int lTarget,    /* (i) Length of vector */
  2.8582 +       int nStages,    /* (i) Number of codebook stages */
  2.8583 +       float *weightDenum, /* (i) weighting filter coefficients */
  2.8584 +       float *weightState, /* (i) weighting filter state */
  2.8585 +       int block           /* (i) the sub-block number */
  2.8586 +   ){
  2.8587 +       int i, j, icount, stage, best_index, range, counter;
  2.8588 +       float max_measure, gain, measure, crossDot, ftmp;
  2.8589 +       float gains[CB_NSTAGES];
  2.8590 +       float target[SUBL];
  2.8591 +       int base_index, sInd, eInd, base_size;
  2.8592 +       int sIndAug=0, eIndAug=0;
  2.8593 +       float buf[CB_MEML+SUBL+2*LPC_FILTERORDER];
  2.8594 +       float invenergy[CB_EXPAND*128], energy[CB_EXPAND*128];
  2.8595 +       float *pp, *ppi=0, *ppo=0, *ppe=0;
  2.8596 +       float cbvectors[CB_MEML];
  2.8597 +       float tene, cene, cvec[SUBL];
  2.8598 +       float aug_vec[SUBL];
  2.8599 +
  2.8600 +       memset(cvec,0,SUBL*sizeof(float));
  2.8601 +
  2.8602 +       /* Determine size of codebook sections */
  2.8603 +
  2.8604 +       base_size=lMem-lTarget+1;
  2.8605 +
  2.8606 +       if (lTarget==SUBL) {
  2.8607 +           base_size=lMem-lTarget+1+lTarget/2;
  2.8608 +       }
  2.8609 +
  2.8610 +       /* setup buffer for weighting */
  2.8611 +
  2.8612 +       memcpy(buf,weightState,sizeof(float)*LPC_FILTERORDER);
  2.8613 +       memcpy(buf+LPC_FILTERORDER,mem,lMem*sizeof(float));
  2.8614 +       memcpy(buf+LPC_FILTERORDER+lMem,intarget,lTarget*sizeof(float));
  2.8615 +
  2.8616 +       /* weighting */
  2.8617 +
  2.8618 +       AllPoleFilter(buf+LPC_FILTERORDER, weightDenum,
  2.8619 +           lMem+lTarget, LPC_FILTERORDER);
  2.8620 +
  2.8621 +       /* Construct the codebook and target needed */
  2.8622 +
  2.8623 +       memcpy(target, buf+LPC_FILTERORDER+lMem, lTarget*sizeof(float));
  2.8624 +
  2.8625 +       tene=0.0;
  2.8626 +
  2.8627 +
  2.8628 +
  2.8629 +Andersen, et al.              Experimental                    [Page 154]
  2.8630 +
  2.8631 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8632 +
  2.8633 +
  2.8634 +       for (i=0; i<lTarget; i++) {
  2.8635 +           tene+=target[i]*target[i];
  2.8636 +       }
  2.8637 +
  2.8638 +       /* Prepare search over one more codebook section. This section
  2.8639 +          is created by filtering the original buffer with a filter. */
  2.8640 +
  2.8641 +       filteredCBvecs(cbvectors, buf+LPC_FILTERORDER, lMem);
  2.8642 +
  2.8643 +       /* The Main Loop over stages */
  2.8644 +
  2.8645 +       for (stage=0; stage<nStages; stage++) {
  2.8646 +
  2.8647 +           range = search_rangeTbl[block][stage];
  2.8648 +
  2.8649 +           /* initialize search measure */
  2.8650 +
  2.8651 +           max_measure = (float)-10000000.0;
  2.8652 +           gain = (float)0.0;
  2.8653 +           best_index = 0;
  2.8654 +
  2.8655 +           /* Compute cross dot product between the target
  2.8656 +              and the CB memory */
  2.8657 +
  2.8658 +           crossDot=0.0;
  2.8659 +           pp=buf+LPC_FILTERORDER+lMem-lTarget;
  2.8660 +           for (j=0; j<lTarget; j++) {
  2.8661 +               crossDot += target[j]*(*pp++);
  2.8662 +           }
  2.8663 +
  2.8664 +           if (stage==0) {
  2.8665 +
  2.8666 +               /* Calculate energy in the first block of
  2.8667 +                 'lTarget' samples. */
  2.8668 +               ppe = energy;
  2.8669 +               ppi = buf+LPC_FILTERORDER+lMem-lTarget-1;
  2.8670 +               ppo = buf+LPC_FILTERORDER+lMem-1;
  2.8671 +
  2.8672 +               *ppe=0.0;
  2.8673 +               pp=buf+LPC_FILTERORDER+lMem-lTarget;
  2.8674 +               for (j=0; j<lTarget; j++) {
  2.8675 +                   *ppe+=(*pp)*(*pp++);
  2.8676 +               }
  2.8677 +
  2.8678 +               if (*ppe>0.0) {
  2.8679 +                   invenergy[0] = (float) 1.0 / (*ppe + EPS);
  2.8680 +               } else {
  2.8681 +                   invenergy[0] = (float) 0.0;
  2.8682 +
  2.8683 +
  2.8684 +
  2.8685 +Andersen, et al.              Experimental                    [Page 155]
  2.8686 +
  2.8687 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8688 +
  2.8689 +
  2.8690 +               }
  2.8691 +               ppe++;
  2.8692 +
  2.8693 +               measure=(float)-10000000.0;
  2.8694 +
  2.8695 +               if (crossDot > 0.0) {
  2.8696 +                      measure = crossDot*crossDot*invenergy[0];
  2.8697 +               }
  2.8698 +           }
  2.8699 +           else {
  2.8700 +               measure = crossDot*crossDot*invenergy[0];
  2.8701 +           }
  2.8702 +
  2.8703 +           /* check if measure is better */
  2.8704 +           ftmp = crossDot*invenergy[0];
  2.8705 +
  2.8706 +           if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
  2.8707 +               best_index = 0;
  2.8708 +               max_measure = measure;
  2.8709 +               gain = ftmp;
  2.8710 +           }
  2.8711 +
  2.8712 +           /* loop over the main first codebook section,
  2.8713 +              full search */
  2.8714 +
  2.8715 +           for (icount=1; icount<range; icount++) {
  2.8716 +
  2.8717 +               /* calculate measure */
  2.8718 +
  2.8719 +               crossDot=0.0;
  2.8720 +               pp = buf+LPC_FILTERORDER+lMem-lTarget-icount;
  2.8721 +
  2.8722 +               for (j=0; j<lTarget; j++) {
  2.8723 +                   crossDot += target[j]*(*pp++);
  2.8724 +               }
  2.8725 +
  2.8726 +               if (stage==0) {
  2.8727 +                   *ppe++ = energy[icount-1] + (*ppi)*(*ppi) -
  2.8728 +                       (*ppo)*(*ppo);
  2.8729 +                   ppo--;
  2.8730 +                   ppi--;
  2.8731 +
  2.8732 +                   if (energy[icount]>0.0) {
  2.8733 +                       invenergy[icount] =
  2.8734 +                           (float)1.0/(energy[icount]+EPS);
  2.8735 +                   } else {
  2.8736 +                       invenergy[icount] = (float) 0.0;
  2.8737 +                   }
  2.8738 +
  2.8739 +
  2.8740 +
  2.8741 +Andersen, et al.              Experimental                    [Page 156]
  2.8742 +
  2.8743 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8744 +
  2.8745 +
  2.8746 +                   measure=(float)-10000000.0;
  2.8747 +
  2.8748 +                   if (crossDot > 0.0) {
  2.8749 +                       measure = crossDot*crossDot*invenergy[icount];
  2.8750 +                   }
  2.8751 +               }
  2.8752 +               else {
  2.8753 +                   measure = crossDot*crossDot*invenergy[icount];
  2.8754 +               }
  2.8755 +
  2.8756 +               /* check if measure is better */
  2.8757 +               ftmp = crossDot*invenergy[icount];
  2.8758 +
  2.8759 +               if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
  2.8760 +                   best_index = icount;
  2.8761 +                   max_measure = measure;
  2.8762 +                   gain = ftmp;
  2.8763 +               }
  2.8764 +           }
  2.8765 +
  2.8766 +           /* Loop over augmented part in the first codebook
  2.8767 +            * section, full search.
  2.8768 +            * The vectors are interpolated.
  2.8769 +            */
  2.8770 +
  2.8771 +           if (lTarget==SUBL) {
  2.8772 +
  2.8773 +               /* Search for best possible cb vector and
  2.8774 +                  compute the CB-vectors' energy. */
  2.8775 +               searchAugmentedCB(20, 39, stage, base_size-lTarget/2,
  2.8776 +                   target, buf+LPC_FILTERORDER+lMem,
  2.8777 +                   &max_measure, &best_index, &gain, energy,
  2.8778 +                   invenergy);
  2.8779 +           }
  2.8780 +
  2.8781 +           /* set search range for following codebook sections */
  2.8782 +
  2.8783 +           base_index=best_index;
  2.8784 +
  2.8785 +           /* unrestricted search */
  2.8786 +
  2.8787 +           if (CB_RESRANGE == -1) {
  2.8788 +               sInd=0;
  2.8789 +               eInd=range-1;
  2.8790 +               sIndAug=20;
  2.8791 +               eIndAug=39;
  2.8792 +           }
  2.8793 +
  2.8794 +
  2.8795 +
  2.8796 +
  2.8797 +Andersen, et al.              Experimental                    [Page 157]
  2.8798 +
  2.8799 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8800 +
  2.8801 +
  2.8802 +           /* restricted search around best index from first
  2.8803 +           codebook section */
  2.8804 +
  2.8805 +           else {
  2.8806 +               /* Initialize search indices */
  2.8807 +               sIndAug=0;
  2.8808 +               eIndAug=0;
  2.8809 +               sInd=base_index-CB_RESRANGE/2;
  2.8810 +               eInd=sInd+CB_RESRANGE;
  2.8811 +
  2.8812 +               if (lTarget==SUBL) {
  2.8813 +
  2.8814 +                   if (sInd<0) {
  2.8815 +
  2.8816 +                       sIndAug = 40 + sInd;
  2.8817 +                       eIndAug = 39;
  2.8818 +                       sInd=0;
  2.8819 +
  2.8820 +                   } else if ( base_index < (base_size-20) ) {
  2.8821 +
  2.8822 +                       if (eInd > range) {
  2.8823 +                           sInd -= (eInd-range);
  2.8824 +                           eInd = range;
  2.8825 +                       }
  2.8826 +                   } else { /* base_index >= (base_size-20) */
  2.8827 +
  2.8828 +                       if (sInd < (base_size-20)) {
  2.8829 +                           sIndAug = 20;
  2.8830 +                           sInd = 0;
  2.8831 +                           eInd = 0;
  2.8832 +                           eIndAug = 19 + CB_RESRANGE;
  2.8833 +
  2.8834 +                           if(eIndAug > 39) {
  2.8835 +                               eInd = eIndAug-39;
  2.8836 +                               eIndAug = 39;
  2.8837 +                           }
  2.8838 +                       } else {
  2.8839 +                           sIndAug = 20 + sInd - (base_size-20);
  2.8840 +                           eIndAug = 39;
  2.8841 +                           sInd = 0;
  2.8842 +                           eInd = CB_RESRANGE - (eIndAug-sIndAug+1);
  2.8843 +                       }
  2.8844 +                   }
  2.8845 +
  2.8846 +               } else { /* lTarget = 22 or 23 */
  2.8847 +
  2.8848 +                   if (sInd < 0) {
  2.8849 +                       eInd -= sInd;
  2.8850 +
  2.8851 +
  2.8852 +
  2.8853 +Andersen, et al.              Experimental                    [Page 158]
  2.8854 +
  2.8855 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8856 +
  2.8857 +
  2.8858 +                       sInd = 0;
  2.8859 +                   }
  2.8860 +
  2.8861 +                   if(eInd > range) {
  2.8862 +                       sInd -= (eInd - range);
  2.8863 +                       eInd = range;
  2.8864 +                   }
  2.8865 +               }
  2.8866 +           }
  2.8867 +
  2.8868 +           /* search of higher codebook section */
  2.8869 +
  2.8870 +           /* index search range */
  2.8871 +           counter = sInd;
  2.8872 +           sInd += base_size;
  2.8873 +           eInd += base_size;
  2.8874 +
  2.8875 +
  2.8876 +           if (stage==0) {
  2.8877 +               ppe = energy+base_size;
  2.8878 +               *ppe=0.0;
  2.8879 +
  2.8880 +               pp=cbvectors+lMem-lTarget;
  2.8881 +               for (j=0; j<lTarget; j++) {
  2.8882 +                   *ppe+=(*pp)*(*pp++);
  2.8883 +               }
  2.8884 +
  2.8885 +               ppi = cbvectors + lMem - 1 - lTarget;
  2.8886 +               ppo = cbvectors + lMem - 1;
  2.8887 +
  2.8888 +               for (j=0; j<(range-1); j++) {
  2.8889 +                   *(ppe+1) = *ppe + (*ppi)*(*ppi) - (*ppo)*(*ppo);
  2.8890 +                   ppo--;
  2.8891 +                   ppi--;
  2.8892 +                   ppe++;
  2.8893 +               }
  2.8894 +           }
  2.8895 +
  2.8896 +           /* loop over search range */
  2.8897 +
  2.8898 +           for (icount=sInd; icount<eInd; icount++) {
  2.8899 +
  2.8900 +               /* calculate measure */
  2.8901 +
  2.8902 +               crossDot=0.0;
  2.8903 +               pp=cbvectors + lMem - (counter++) - lTarget;
  2.8904 +
  2.8905 +               for (j=0;j<lTarget;j++) {
  2.8906 +
  2.8907 +
  2.8908 +
  2.8909 +Andersen, et al.              Experimental                    [Page 159]
  2.8910 +
  2.8911 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8912 +
  2.8913 +
  2.8914 +                   crossDot += target[j]*(*pp++);
  2.8915 +               }
  2.8916 +
  2.8917 +               if (energy[icount]>0.0) {
  2.8918 +                   invenergy[icount] =(float)1.0/(energy[icount]+EPS);
  2.8919 +               } else {
  2.8920 +                   invenergy[icount] =(float)0.0;
  2.8921 +               }
  2.8922 +
  2.8923 +               if (stage==0) {
  2.8924 +
  2.8925 +                   measure=(float)-10000000.0;
  2.8926 +
  2.8927 +                   if (crossDot > 0.0) {
  2.8928 +                       measure = crossDot*crossDot*
  2.8929 +                           invenergy[icount];
  2.8930 +                   }
  2.8931 +               }
  2.8932 +               else {
  2.8933 +                   measure = crossDot*crossDot*invenergy[icount];
  2.8934 +               }
  2.8935 +
  2.8936 +               /* check if measure is better */
  2.8937 +               ftmp = crossDot*invenergy[icount];
  2.8938 +
  2.8939 +               if ((measure>max_measure) && (fabs(ftmp)<CB_MAXGAIN)) {
  2.8940 +                   best_index = icount;
  2.8941 +                   max_measure = measure;
  2.8942 +                   gain = ftmp;
  2.8943 +               }
  2.8944 +           }
  2.8945 +
  2.8946 +           /* Search the augmented CB inside the limited range. */
  2.8947 +
  2.8948 +           if ((lTarget==SUBL)&&(sIndAug!=0)) {
  2.8949 +               searchAugmentedCB(sIndAug, eIndAug, stage,
  2.8950 +                   2*base_size-20, target, cbvectors+lMem,
  2.8951 +                   &max_measure, &best_index, &gain, energy,
  2.8952 +                   invenergy);
  2.8953 +           }
  2.8954 +
  2.8955 +           /* record best index */
  2.8956 +
  2.8957 +           index[stage] = best_index;
  2.8958 +
  2.8959 +           /* gain quantization */
  2.8960 +
  2.8961 +           if (stage==0){
  2.8962 +
  2.8963 +
  2.8964 +
  2.8965 +Andersen, et al.              Experimental                    [Page 160]
  2.8966 +
  2.8967 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.8968 +
  2.8969 +
  2.8970 +
  2.8971 +               if (gain<0.0){
  2.8972 +                   gain = 0.0;
  2.8973 +               }
  2.8974 +
  2.8975 +               if (gain>CB_MAXGAIN) {
  2.8976 +                   gain = (float)CB_MAXGAIN;
  2.8977 +               }
  2.8978 +               gain = gainquant(gain, 1.0, 32, &gain_index[stage]);
  2.8979 +           }
  2.8980 +           else {
  2.8981 +               if (stage==1) {
  2.8982 +                   gain = gainquant(gain, (float)fabs(gains[stage-1]),
  2.8983 +                       16, &gain_index[stage]);
  2.8984 +               } else {
  2.8985 +                   gain = gainquant(gain, (float)fabs(gains[stage-1]),
  2.8986 +                       8, &gain_index[stage]);
  2.8987 +               }
  2.8988 +           }
  2.8989 +
  2.8990 +           /* Extract the best (according to measure)
  2.8991 +              codebook vector */
  2.8992 +
  2.8993 +           if (lTarget==(STATE_LEN-iLBCenc_inst->state_short_len)) {
  2.8994 +
  2.8995 +               if (index[stage]<base_size) {
  2.8996 +                   pp=buf+LPC_FILTERORDER+lMem-lTarget-index[stage];
  2.8997 +               } else {
  2.8998 +                   pp=cbvectors+lMem-lTarget-
  2.8999 +                       index[stage]+base_size;
  2.9000 +               }
  2.9001 +           } else {
  2.9002 +
  2.9003 +               if (index[stage]<base_size) {
  2.9004 +                   if (index[stage]<(base_size-20)) {
  2.9005 +                       pp=buf+LPC_FILTERORDER+lMem-
  2.9006 +                           lTarget-index[stage];
  2.9007 +                   } else {
  2.9008 +                       createAugmentedVec(index[stage]-base_size+40,
  2.9009 +                               buf+LPC_FILTERORDER+lMem,aug_vec);
  2.9010 +                       pp=aug_vec;
  2.9011 +                   }
  2.9012 +               } else {
  2.9013 +                   int filterno, position;
  2.9014 +
  2.9015 +                   filterno=index[stage]/base_size;
  2.9016 +                   position=index[stage]-filterno*base_size;
  2.9017 +
  2.9018 +
  2.9019 +
  2.9020 +
  2.9021 +Andersen, et al.              Experimental                    [Page 161]
  2.9022 +
  2.9023 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9024 +
  2.9025 +
  2.9026 +
  2.9027 +                   if (position<(base_size-20)) {
  2.9028 +                       pp=cbvectors+filterno*lMem-lTarget-
  2.9029 +                           index[stage]+filterno*base_size;
  2.9030 +                   } else {
  2.9031 +                       createAugmentedVec(
  2.9032 +                           index[stage]-(filterno+1)*base_size+40,
  2.9033 +                           cbvectors+filterno*lMem,aug_vec);
  2.9034 +                       pp=aug_vec;
  2.9035 +                   }
  2.9036 +               }
  2.9037 +           }
  2.9038 +
  2.9039 +           /* Subtract the best codebook vector, according
  2.9040 +              to measure, from the target vector */
  2.9041 +
  2.9042 +           for (j=0;j<lTarget;j++) {
  2.9043 +               cvec[j] += gain*(*pp);
  2.9044 +               target[j] -= gain*(*pp++);
  2.9045 +           }
  2.9046 +
  2.9047 +           /* record quantized gain */
  2.9048 +
  2.9049 +           gains[stage]=gain;
  2.9050 +
  2.9051 +       }/* end of Main Loop. for (stage=0;... */
  2.9052 +
  2.9053 +       /* Gain adjustment for energy matching */
  2.9054 +       cene=0.0;
  2.9055 +       for (i=0; i<lTarget; i++) {
  2.9056 +           cene+=cvec[i]*cvec[i];
  2.9057 +       }
  2.9058 +       j=gain_index[0];
  2.9059 +
  2.9060 +       for (i=gain_index[0]; i<32; i++) {
  2.9061 +           ftmp=cene*gain_sq5Tbl[i]*gain_sq5Tbl[i];
  2.9062 +
  2.9063 +           if ((ftmp<(tene*gains[0]*gains[0])) &&
  2.9064 +               (gain_sq5Tbl[j]<(2.0*gains[0]))) {
  2.9065 +               j=i;
  2.9066 +           }
  2.9067 +       }
  2.9068 +       gain_index[0]=j;
  2.9069 +   }
  2.9070 +
  2.9071 +
  2.9072 +
  2.9073 +
  2.9074 +
  2.9075 +
  2.9076 +
  2.9077 +Andersen, et al.              Experimental                    [Page 162]
  2.9078 +
  2.9079 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9080 +
  2.9081 +
  2.9082 +A.35.  LPCdecode.h
  2.9083 +
  2.9084 +   /******************************************************************
  2.9085 +
  2.9086 +       iLBC Speech Coder ANSI-C Source Code
  2.9087 +
  2.9088 +       LPC_decode.h
  2.9089 +
  2.9090 +       Copyright (C) The Internet Society (2004).
  2.9091 +       All Rights Reserved.
  2.9092 +
  2.9093 +   ******************************************************************/
  2.9094 +
  2.9095 +   #ifndef __iLBC_LPC_DECODE_H
  2.9096 +   #define __iLBC_LPC_DECODE_H
  2.9097 +
  2.9098 +   void LSFinterpolate2a_dec(
  2.9099 +       float *a,           /* (o) lpc coefficients for a sub-frame */
  2.9100 +       float *lsf1,    /* (i) first lsf coefficient vector */
  2.9101 +       float *lsf2,    /* (i) second lsf coefficient vector */
  2.9102 +       float coef,         /* (i) interpolation weight */
  2.9103 +       int length          /* (i) length of lsf vectors */
  2.9104 +   );
  2.9105 +
  2.9106 +   void SimplelsfDEQ(
  2.9107 +       float *lsfdeq,      /* (o) dequantized lsf coefficients */
  2.9108 +       int *index,         /* (i) quantization index */
  2.9109 +       int lpc_n           /* (i) number of LPCs */
  2.9110 +   );
  2.9111 +
  2.9112 +   void DecoderInterpolateLSF(
  2.9113 +       float *syntdenum,   /* (o) synthesis filter coefficients */
  2.9114 +       float *weightdenum, /* (o) weighting denumerator
  2.9115 +                                  coefficients */
  2.9116 +       float *lsfdeq,      /* (i) dequantized lsf coefficients */
  2.9117 +       int length,         /* (i) length of lsf coefficient vector */
  2.9118 +       iLBC_Dec_Inst_t *iLBCdec_inst
  2.9119 +                           /* (i) the decoder state structure */
  2.9120 +   );
  2.9121 +
  2.9122 +   #endif
  2.9123 +
  2.9124 +
  2.9125 +
  2.9126 +
  2.9127 +
  2.9128 +
  2.9129 +
  2.9130 +
  2.9131 +
  2.9132 +
  2.9133 +Andersen, et al.              Experimental                    [Page 163]
  2.9134 +
  2.9135 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9136 +
  2.9137 +
  2.9138 +A.36.  LPCdecode.c
  2.9139 +
  2.9140 +   /******************************************************************
  2.9141 +
  2.9142 +       iLBC Speech Coder ANSI-C Source Code
  2.9143 +
  2.9144 +       LPC_decode.c
  2.9145 +
  2.9146 +       Copyright (C) The Internet Society (2004).
  2.9147 +       All Rights Reserved.
  2.9148 +
  2.9149 +   ******************************************************************/
  2.9150 +
  2.9151 +   #include <math.h>
  2.9152 +   #include <string.h>
  2.9153 +
  2.9154 +   #include "helpfun.h"
  2.9155 +   #include "lsf.h"
  2.9156 +   #include "iLBC_define.h"
  2.9157 +   #include "constants.h"
  2.9158 +
  2.9159 +   /*---------------------------------------------------------------*
  2.9160 +    *  interpolation of lsf coefficients for the decoder
  2.9161 +    *--------------------------------------------------------------*/
  2.9162 +
  2.9163 +   void LSFinterpolate2a_dec(
  2.9164 +       float *a,           /* (o) lpc coefficients for a sub-frame */
  2.9165 +       float *lsf1,    /* (i) first lsf coefficient vector */
  2.9166 +       float *lsf2,    /* (i) second lsf coefficient vector */
  2.9167 +       float coef,         /* (i) interpolation weight */
  2.9168 +       int length          /* (i) length of lsf vectors */
  2.9169 +   ){
  2.9170 +       float  lsftmp[LPC_FILTERORDER];
  2.9171 +
  2.9172 +       interpolate(lsftmp, lsf1, lsf2, coef, length);
  2.9173 +       lsf2a(a, lsftmp);
  2.9174 +   }
  2.9175 +
  2.9176 +   /*---------------------------------------------------------------*
  2.9177 +    *  obtain dequantized lsf coefficients from quantization index
  2.9178 +    *--------------------------------------------------------------*/
  2.9179 +
  2.9180 +   void SimplelsfDEQ(
  2.9181 +       float *lsfdeq,    /* (o) dequantized lsf coefficients */
  2.9182 +       int *index,         /* (i) quantization index */
  2.9183 +       int lpc_n           /* (i) number of LPCs */
  2.9184 +   ){
  2.9185 +       int i, j, pos, cb_pos;
  2.9186 +
  2.9187 +
  2.9188 +
  2.9189 +Andersen, et al.              Experimental                    [Page 164]
  2.9190 +
  2.9191 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9192 +
  2.9193 +
  2.9194 +       /* decode first LSF */
  2.9195 +
  2.9196 +       pos = 0;
  2.9197 +       cb_pos = 0;
  2.9198 +       for (i = 0; i < LSF_NSPLIT; i++) {
  2.9199 +           for (j = 0; j < dim_lsfCbTbl[i]; j++) {
  2.9200 +               lsfdeq[pos + j] = lsfCbTbl[cb_pos +
  2.9201 +                   (long)(index[i])*dim_lsfCbTbl[i] + j];
  2.9202 +           }
  2.9203 +           pos += dim_lsfCbTbl[i];
  2.9204 +           cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
  2.9205 +       }
  2.9206 +
  2.9207 +       if (lpc_n>1) {
  2.9208 +
  2.9209 +           /* decode last LSF */
  2.9210 +
  2.9211 +           pos = 0;
  2.9212 +           cb_pos = 0;
  2.9213 +           for (i = 0; i < LSF_NSPLIT; i++) {
  2.9214 +               for (j = 0; j < dim_lsfCbTbl[i]; j++) {
  2.9215 +                   lsfdeq[LPC_FILTERORDER + pos + j] =
  2.9216 +                       lsfCbTbl[cb_pos +
  2.9217 +                       (long)(index[LSF_NSPLIT + i])*
  2.9218 +                       dim_lsfCbTbl[i] + j];
  2.9219 +               }
  2.9220 +               pos += dim_lsfCbTbl[i];
  2.9221 +               cb_pos += size_lsfCbTbl[i]*dim_lsfCbTbl[i];
  2.9222 +           }
  2.9223 +       }
  2.9224 +   }
  2.9225 +
  2.9226 +   /*----------------------------------------------------------------*
  2.9227 +    *  obtain synthesis and weighting filters form lsf coefficients
  2.9228 +    *---------------------------------------------------------------*/
  2.9229 +
  2.9230 +   void DecoderInterpolateLSF(
  2.9231 +       float *syntdenum, /* (o) synthesis filter coefficients */
  2.9232 +       float *weightdenum, /* (o) weighting denumerator
  2.9233 +                                  coefficients */
  2.9234 +       float *lsfdeq,       /* (i) dequantized lsf coefficients */
  2.9235 +       int length,         /* (i) length of lsf coefficient vector */
  2.9236 +       iLBC_Dec_Inst_t *iLBCdec_inst
  2.9237 +                           /* (i) the decoder state structure */
  2.9238 +   ){
  2.9239 +       int    i, pos, lp_length;
  2.9240 +       float  lp[LPC_FILTERORDER + 1], *lsfdeq2;
  2.9241 +
  2.9242 +
  2.9243 +
  2.9244 +
  2.9245 +Andersen, et al.              Experimental                    [Page 165]
  2.9246 +
  2.9247 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9248 +
  2.9249 +
  2.9250 +       lsfdeq2 = lsfdeq + length;
  2.9251 +       lp_length = length + 1;
  2.9252 +
  2.9253 +       if (iLBCdec_inst->mode==30) {
  2.9254 +           /* sub-frame 1: Interpolation between old and first */
  2.9255 +
  2.9256 +           LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold, lsfdeq,
  2.9257 +               lsf_weightTbl_30ms[0], length);
  2.9258 +           memcpy(syntdenum,lp,lp_length*sizeof(float));
  2.9259 +           bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM,
  2.9260 +               lp_length);
  2.9261 +
  2.9262 +           /* sub-frames 2 to 6: interpolation between first
  2.9263 +              and last LSF */
  2.9264 +
  2.9265 +           pos = lp_length;
  2.9266 +           for (i = 1; i < 6; i++) {
  2.9267 +               LSFinterpolate2a_dec(lp, lsfdeq, lsfdeq2,
  2.9268 +                   lsf_weightTbl_30ms[i], length);
  2.9269 +               memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
  2.9270 +               bwexpand(weightdenum + pos, lp,
  2.9271 +                   LPC_CHIRP_WEIGHTDENUM, lp_length);
  2.9272 +               pos += lp_length;
  2.9273 +           }
  2.9274 +       }
  2.9275 +       else {
  2.9276 +           pos = 0;
  2.9277 +           for (i = 0; i < iLBCdec_inst->nsub; i++) {
  2.9278 +               LSFinterpolate2a_dec(lp, iLBCdec_inst->lsfdeqold,
  2.9279 +                   lsfdeq, lsf_weightTbl_20ms[i], length);
  2.9280 +               memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
  2.9281 +               bwexpand(weightdenum+pos, lp, LPC_CHIRP_WEIGHTDENUM,
  2.9282 +                   lp_length);
  2.9283 +               pos += lp_length;
  2.9284 +           }
  2.9285 +       }
  2.9286 +
  2.9287 +       /* update memory */
  2.9288 +
  2.9289 +       if (iLBCdec_inst->mode==30)
  2.9290 +           memcpy(iLBCdec_inst->lsfdeqold, lsfdeq2,
  2.9291 +                       length*sizeof(float));
  2.9292 +       else
  2.9293 +           memcpy(iLBCdec_inst->lsfdeqold, lsfdeq,
  2.9294 +                       length*sizeof(float));
  2.9295 +
  2.9296 +   }
  2.9297 +
  2.9298 +
  2.9299 +
  2.9300 +
  2.9301 +Andersen, et al.              Experimental                    [Page 166]
  2.9302 +
  2.9303 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9304 +
  2.9305 +
  2.9306 +A.37.  LPCencode.h
  2.9307 +
  2.9308 +   /******************************************************************
  2.9309 +
  2.9310 +       iLBC Speech Coder ANSI-C Source Code
  2.9311 +
  2.9312 +       LPCencode.h
  2.9313 +
  2.9314 +       Copyright (C) The Internet Society (2004).
  2.9315 +       All Rights Reserved.
  2.9316 +
  2.9317 +   ******************************************************************/
  2.9318 +
  2.9319 +   #ifndef __iLBC_LPCENCOD_H
  2.9320 +   #define __iLBC_LPCENCOD_H
  2.9321 +
  2.9322 +   void LPCencode(
  2.9323 +       float *syntdenum,   /* (i/o) synthesis filter coefficients
  2.9324 +                                  before/after encoding */
  2.9325 +       float *weightdenum, /* (i/o) weighting denumerator coefficients
  2.9326 +                                  before/after encoding */
  2.9327 +       int *lsf_index,     /* (o) lsf quantization index */
  2.9328 +       float *data,    /* (i) lsf coefficients to quantize */
  2.9329 +       iLBC_Enc_Inst_t *iLBCenc_inst
  2.9330 +                           /* (i/o) the encoder state structure */
  2.9331 +   );
  2.9332 +
  2.9333 +   #endif
  2.9334 +
  2.9335 +A.38.  LPCencode.c
  2.9336 +
  2.9337 +   /******************************************************************
  2.9338 +
  2.9339 +       iLBC Speech Coder ANSI-C Source Code
  2.9340 +
  2.9341 +       LPCencode.c
  2.9342 +
  2.9343 +       Copyright (C) The Internet Society (2004).
  2.9344 +       All Rights Reserved.
  2.9345 +
  2.9346 +   ******************************************************************/
  2.9347 +
  2.9348 +   #include <string.h>
  2.9349 +
  2.9350 +   #include "iLBC_define.h"
  2.9351 +   #include "helpfun.h"
  2.9352 +   #include "lsf.h"
  2.9353 +   #include "constants.h"
  2.9354 +
  2.9355 +
  2.9356 +
  2.9357 +Andersen, et al.              Experimental                    [Page 167]
  2.9358 +
  2.9359 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9360 +
  2.9361 +
  2.9362 +   /*----------------------------------------------------------------*
  2.9363 +    *  lpc analysis (subrutine to LPCencode)
  2.9364 +    *---------------------------------------------------------------*/
  2.9365 +
  2.9366 +   void SimpleAnalysis(
  2.9367 +       float *lsf,         /* (o) lsf coefficients */
  2.9368 +       float *data,    /* (i) new data vector */
  2.9369 +       iLBC_Enc_Inst_t *iLBCenc_inst
  2.9370 +                           /* (i/o) the encoder state structure */
  2.9371 +   ){
  2.9372 +       int k, is;
  2.9373 +       float temp[BLOCKL_MAX], lp[LPC_FILTERORDER + 1];
  2.9374 +       float lp2[LPC_FILTERORDER + 1];
  2.9375 +       float r[LPC_FILTERORDER + 1];
  2.9376 +
  2.9377 +       is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;
  2.9378 +       memcpy(iLBCenc_inst->lpc_buffer+is,data,
  2.9379 +           iLBCenc_inst->blockl*sizeof(float));
  2.9380 +
  2.9381 +       /* No lookahead, last window is asymmetric */
  2.9382 +
  2.9383 +       for (k = 0; k < iLBCenc_inst->lpc_n; k++) {
  2.9384 +
  2.9385 +           is = LPC_LOOKBACK;
  2.9386 +
  2.9387 +           if (k < (iLBCenc_inst->lpc_n - 1)) {
  2.9388 +               window(temp, lpc_winTbl,
  2.9389 +                   iLBCenc_inst->lpc_buffer, BLOCKL_MAX);
  2.9390 +           } else {
  2.9391 +               window(temp, lpc_asymwinTbl,
  2.9392 +                   iLBCenc_inst->lpc_buffer + is, BLOCKL_MAX);
  2.9393 +           }
  2.9394 +
  2.9395 +           autocorr(r, temp, BLOCKL_MAX, LPC_FILTERORDER);
  2.9396 +           window(r, r, lpc_lagwinTbl, LPC_FILTERORDER + 1);
  2.9397 +
  2.9398 +           levdurb(lp, temp, r, LPC_FILTERORDER);
  2.9399 +           bwexpand(lp2, lp, LPC_CHIRP_SYNTDENUM, LPC_FILTERORDER+1);
  2.9400 +
  2.9401 +           a2lsf(lsf + k*LPC_FILTERORDER, lp2);
  2.9402 +       }
  2.9403 +       is=LPC_LOOKBACK+BLOCKL_MAX-iLBCenc_inst->blockl;
  2.9404 +       memmove(iLBCenc_inst->lpc_buffer,
  2.9405 +           iLBCenc_inst->lpc_buffer+LPC_LOOKBACK+BLOCKL_MAX-is,
  2.9406 +           is*sizeof(float));
  2.9407 +   }
  2.9408 +
  2.9409 +   /*----------------------------------------------------------------*
  2.9410 +
  2.9411 +
  2.9412 +
  2.9413 +Andersen, et al.              Experimental                    [Page 168]
  2.9414 +
  2.9415 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9416 +
  2.9417 +
  2.9418 +    *  lsf interpolator and conversion from lsf to a coefficients
  2.9419 +    *  (subrutine to SimpleInterpolateLSF)
  2.9420 +    *---------------------------------------------------------------*/
  2.9421 +
  2.9422 +   void LSFinterpolate2a_enc(
  2.9423 +       float *a,       /* (o) lpc coefficients */
  2.9424 +       float *lsf1,/* (i) first set of lsf coefficients */
  2.9425 +       float *lsf2,/* (i) second set of lsf coefficients */
  2.9426 +       float coef,     /* (i) weighting coefficient to use between
  2.9427 +                              lsf1 and lsf2 */
  2.9428 +       long length      /* (i) length of coefficient vectors */
  2.9429 +   ){
  2.9430 +       float  lsftmp[LPC_FILTERORDER];
  2.9431 +
  2.9432 +       interpolate(lsftmp, lsf1, lsf2, coef, length);
  2.9433 +       lsf2a(a, lsftmp);
  2.9434 +   }
  2.9435 +
  2.9436 +   /*----------------------------------------------------------------*
  2.9437 +    *  lsf interpolator (subrutine to LPCencode)
  2.9438 +    *---------------------------------------------------------------*/
  2.9439 +
  2.9440 +   void SimpleInterpolateLSF(
  2.9441 +       float *syntdenum,   /* (o) the synthesis filter denominator
  2.9442 +                                  resulting from the quantized
  2.9443 +                                  interpolated lsf */
  2.9444 +       float *weightdenum, /* (o) the weighting filter denominator
  2.9445 +                                  resulting from the unquantized
  2.9446 +                                  interpolated lsf */
  2.9447 +       float *lsf,         /* (i) the unquantized lsf coefficients */
  2.9448 +       float *lsfdeq,      /* (i) the dequantized lsf coefficients */
  2.9449 +       float *lsfold,      /* (i) the unquantized lsf coefficients of
  2.9450 +                                  the previous signal frame */
  2.9451 +       float *lsfdeqold, /* (i) the dequantized lsf coefficients of
  2.9452 +                                  the previous signal frame */
  2.9453 +       int length,         /* (i) should equate LPC_FILTERORDER */
  2.9454 +       iLBC_Enc_Inst_t *iLBCenc_inst
  2.9455 +                           /* (i/o) the encoder state structure */
  2.9456 +   ){
  2.9457 +       int    i, pos, lp_length;
  2.9458 +       float  lp[LPC_FILTERORDER + 1], *lsf2, *lsfdeq2;
  2.9459 +
  2.9460 +       lsf2 = lsf + length;
  2.9461 +       lsfdeq2 = lsfdeq + length;
  2.9462 +       lp_length = length + 1;
  2.9463 +
  2.9464 +       if (iLBCenc_inst->mode==30) {
  2.9465 +           /* sub-frame 1: Interpolation between old and first
  2.9466 +
  2.9467 +
  2.9468 +
  2.9469 +Andersen, et al.              Experimental                    [Page 169]
  2.9470 +
  2.9471 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9472 +
  2.9473 +
  2.9474 +              set of lsf coefficients */
  2.9475 +
  2.9476 +           LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq,
  2.9477 +               lsf_weightTbl_30ms[0], length);
  2.9478 +           memcpy(syntdenum,lp,lp_length*sizeof(float));
  2.9479 +           LSFinterpolate2a_enc(lp, lsfold, lsf,
  2.9480 +               lsf_weightTbl_30ms[0], length);
  2.9481 +           bwexpand(weightdenum, lp, LPC_CHIRP_WEIGHTDENUM, lp_length);
  2.9482 +
  2.9483 +           /* sub-frame 2 to 6: Interpolation between first
  2.9484 +              and second set of lsf coefficients */
  2.9485 +
  2.9486 +           pos = lp_length;
  2.9487 +           for (i = 1; i < iLBCenc_inst->nsub; i++) {
  2.9488 +               LSFinterpolate2a_enc(lp, lsfdeq, lsfdeq2,
  2.9489 +                   lsf_weightTbl_30ms[i], length);
  2.9490 +               memcpy(syntdenum + pos,lp,lp_length*sizeof(float));
  2.9491 +
  2.9492 +               LSFinterpolate2a_enc(lp, lsf, lsf2,
  2.9493 +                   lsf_weightTbl_30ms[i], length);
  2.9494 +               bwexpand(weightdenum + pos, lp,
  2.9495 +                   LPC_CHIRP_WEIGHTDENUM, lp_length);
  2.9496 +               pos += lp_length;
  2.9497 +           }
  2.9498 +       }
  2.9499 +       else {
  2.9500 +           pos = 0;
  2.9501 +           for (i = 0; i < iLBCenc_inst->nsub; i++) {
  2.9502 +               LSFinterpolate2a_enc(lp, lsfdeqold, lsfdeq,
  2.9503 +                   lsf_weightTbl_20ms[i], length);
  2.9504 +               memcpy(syntdenum+pos,lp,lp_length*sizeof(float));
  2.9505 +               LSFinterpolate2a_enc(lp, lsfold, lsf,
  2.9506 +                   lsf_weightTbl_20ms[i], length);
  2.9507 +               bwexpand(weightdenum+pos, lp,
  2.9508 +                   LPC_CHIRP_WEIGHTDENUM, lp_length);
  2.9509 +               pos += lp_length;
  2.9510 +           }
  2.9511 +       }
  2.9512 +
  2.9513 +       /* update memory */
  2.9514 +
  2.9515 +       if (iLBCenc_inst->mode==30) {
  2.9516 +           memcpy(lsfold, lsf2, length*sizeof(float));
  2.9517 +           memcpy(lsfdeqold, lsfdeq2, length*sizeof(float));
  2.9518 +       }
  2.9519 +       else {
  2.9520 +           memcpy(lsfold, lsf, length*sizeof(float));
  2.9521 +           memcpy(lsfdeqold, lsfdeq, length*sizeof(float));
  2.9522 +
  2.9523 +
  2.9524 +
  2.9525 +Andersen, et al.              Experimental                    [Page 170]
  2.9526 +
  2.9527 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9528 +
  2.9529 +
  2.9530 +       }
  2.9531 +   }
  2.9532 +
  2.9533 +   /*----------------------------------------------------------------*
  2.9534 +    *  lsf quantizer (subrutine to LPCencode)
  2.9535 +    *---------------------------------------------------------------*/
  2.9536 +
  2.9537 +   void SimplelsfQ(
  2.9538 +       float *lsfdeq,    /* (o) dequantized lsf coefficients
  2.9539 +                              (dimension FILTERORDER) */
  2.9540 +       int *index,     /* (o) quantization index */
  2.9541 +       float *lsf,      /* (i) the lsf coefficient vector to be
  2.9542 +                              quantized (dimension FILTERORDER ) */
  2.9543 +       int lpc_n     /* (i) number of lsf sets to quantize */
  2.9544 +   ){
  2.9545 +       /* Quantize first LSF with memoryless split VQ */
  2.9546 +       SplitVQ(lsfdeq, index, lsf, lsfCbTbl, LSF_NSPLIT,
  2.9547 +           dim_lsfCbTbl, size_lsfCbTbl);
  2.9548 +
  2.9549 +       if (lpc_n==2) {
  2.9550 +           /* Quantize second LSF with memoryless split VQ */
  2.9551 +           SplitVQ(lsfdeq + LPC_FILTERORDER, index + LSF_NSPLIT,
  2.9552 +               lsf + LPC_FILTERORDER, lsfCbTbl, LSF_NSPLIT,
  2.9553 +               dim_lsfCbTbl, size_lsfCbTbl);
  2.9554 +       }
  2.9555 +   }
  2.9556 +
  2.9557 +   /*----------------------------------------------------------------*
  2.9558 +    *  lpc encoder
  2.9559 +    *---------------------------------------------------------------*/
  2.9560 +
  2.9561 +   void LPCencode(
  2.9562 +       float *syntdenum, /* (i/o) synthesis filter coefficients
  2.9563 +                                  before/after encoding */
  2.9564 +       float *weightdenum, /* (i/o) weighting denumerator
  2.9565 +                                  coefficients before/after
  2.9566 +                                  encoding */
  2.9567 +       int *lsf_index,     /* (o) lsf quantization index */
  2.9568 +       float *data,    /* (i) lsf coefficients to quantize */
  2.9569 +       iLBC_Enc_Inst_t *iLBCenc_inst
  2.9570 +                           /* (i/o) the encoder state structure */
  2.9571 +   ){
  2.9572 +       float lsf[LPC_FILTERORDER * LPC_N_MAX];
  2.9573 +       float lsfdeq[LPC_FILTERORDER * LPC_N_MAX];
  2.9574 +       int change=0;
  2.9575 +
  2.9576 +       SimpleAnalysis(lsf, data, iLBCenc_inst);
  2.9577 +       SimplelsfQ(lsfdeq, lsf_index, lsf, iLBCenc_inst->lpc_n);
  2.9578 +
  2.9579 +
  2.9580 +
  2.9581 +Andersen, et al.              Experimental                    [Page 171]
  2.9582 +
  2.9583 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9584 +
  2.9585 +
  2.9586 +       change=LSF_check(lsfdeq, LPC_FILTERORDER, iLBCenc_inst->lpc_n);
  2.9587 +       SimpleInterpolateLSF(syntdenum, weightdenum,
  2.9588 +           lsf, lsfdeq, iLBCenc_inst->lsfold,
  2.9589 +           iLBCenc_inst->lsfdeqold, LPC_FILTERORDER, iLBCenc_inst);
  2.9590 +   }
  2.9591 +
  2.9592 +A.39.  lsf.h
  2.9593 +
  2.9594 +   /******************************************************************
  2.9595 +
  2.9596 +       iLBC Speech Coder ANSI-C Source Code
  2.9597 +
  2.9598 +       lsf.h
  2.9599 +
  2.9600 +       Copyright (C) The Internet Society (2004).
  2.9601 +       All Rights Reserved.
  2.9602 +
  2.9603 +   ******************************************************************/
  2.9604 +
  2.9605 +   #ifndef __iLBC_LSF_H
  2.9606 +   #define __iLBC_LSF_H
  2.9607 +
  2.9608 +   void a2lsf(
  2.9609 +       float *freq,/* (o) lsf coefficients */
  2.9610 +       float *a    /* (i) lpc coefficients */
  2.9611 +   );
  2.9612 +
  2.9613 +   void lsf2a(
  2.9614 +       float *a_coef,  /* (o) lpc coefficients */
  2.9615 +       float *freq     /* (i) lsf coefficients */
  2.9616 +   );
  2.9617 +
  2.9618 +   #endif
  2.9619 +
  2.9620 +A.40.  lsf.c
  2.9621 +
  2.9622 +   /******************************************************************
  2.9623 +
  2.9624 +       iLBC Speech Coder ANSI-C Source Code
  2.9625 +
  2.9626 +       lsf.c
  2.9627 +
  2.9628 +       Copyright (C) The Internet Society (2004).
  2.9629 +       All Rights Reserved.
  2.9630 +
  2.9631 +   ******************************************************************/
  2.9632 +
  2.9633 +   #include <string.h>
  2.9634 +
  2.9635 +
  2.9636 +
  2.9637 +Andersen, et al.              Experimental                    [Page 172]
  2.9638 +
  2.9639 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9640 +
  2.9641 +
  2.9642 +   #include <math.h>
  2.9643 +
  2.9644 +   #include "iLBC_define.h"
  2.9645 +
  2.9646 +   /*----------------------------------------------------------------*
  2.9647 +    *  conversion from lpc coefficients to lsf coefficients
  2.9648 +    *---------------------------------------------------------------*/
  2.9649 +
  2.9650 +   void a2lsf(
  2.9651 +       float *freq,/* (o) lsf coefficients */
  2.9652 +       float *a    /* (i) lpc coefficients */
  2.9653 +   ){
  2.9654 +       float steps[LSF_NUMBER_OF_STEPS] =
  2.9655 +           {(float)0.00635, (float)0.003175, (float)0.0015875,
  2.9656 +           (float)0.00079375};
  2.9657 +       float step;
  2.9658 +       int step_idx;
  2.9659 +       int lsp_index;
  2.9660 +       float p[LPC_HALFORDER];
  2.9661 +       float q[LPC_HALFORDER];
  2.9662 +       float p_pre[LPC_HALFORDER];
  2.9663 +       float q_pre[LPC_HALFORDER];
  2.9664 +       float old_p, old_q, *old;
  2.9665 +       float *pq_coef;
  2.9666 +       float omega, old_omega;
  2.9667 +       int i;
  2.9668 +       float hlp, hlp1, hlp2, hlp3, hlp4, hlp5;
  2.9669 +
  2.9670 +       for (i=0; i<LPC_HALFORDER; i++) {
  2.9671 +           p[i] = (float)-1.0 * (a[i + 1] + a[LPC_FILTERORDER - i]);
  2.9672 +           q[i] = a[LPC_FILTERORDER - i] - a[i + 1];
  2.9673 +       }
  2.9674 +
  2.9675 +       p_pre[0] = (float)-1.0 - p[0];
  2.9676 +       p_pre[1] = - p_pre[0] - p[1];
  2.9677 +       p_pre[2] = - p_pre[1] - p[2];
  2.9678 +       p_pre[3] = - p_pre[2] - p[3];
  2.9679 +       p_pre[4] = - p_pre[3] - p[4];
  2.9680 +       p_pre[4] = p_pre[4] / 2;
  2.9681 +
  2.9682 +       q_pre[0] = (float)1.0 - q[0];
  2.9683 +       q_pre[1] = q_pre[0] - q[1];
  2.9684 +       q_pre[2] = q_pre[1] - q[2];
  2.9685 +       q_pre[3] = q_pre[2] - q[3];
  2.9686 +       q_pre[4] = q_pre[3] - q[4];
  2.9687 +       q_pre[4] = q_pre[4] / 2;
  2.9688 +
  2.9689 +       omega = 0.0;
  2.9690 +
  2.9691 +
  2.9692 +
  2.9693 +Andersen, et al.              Experimental                    [Page 173]
  2.9694 +
  2.9695 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9696 +
  2.9697 +
  2.9698 +       old_omega = 0.0;
  2.9699 +
  2.9700 +       old_p = FLOAT_MAX;
  2.9701 +       old_q = FLOAT_MAX;
  2.9702 +
  2.9703 +       /* Here we loop through lsp_index to find all the
  2.9704 +          LPC_FILTERORDER roots for omega. */
  2.9705 +
  2.9706 +       for (lsp_index = 0; lsp_index<LPC_FILTERORDER; lsp_index++) {
  2.9707 +
  2.9708 +           /* Depending on lsp_index being even or odd, we
  2.9709 +           alternatively solve the roots for the two LSP equations. */
  2.9710 +
  2.9711 +
  2.9712 +           if ((lsp_index & 0x1) == 0) {
  2.9713 +               pq_coef = p_pre;
  2.9714 +               old = &old_p;
  2.9715 +           } else {
  2.9716 +               pq_coef = q_pre;
  2.9717 +               old = &old_q;
  2.9718 +           }
  2.9719 +
  2.9720 +           /* Start with low resolution grid */
  2.9721 +
  2.9722 +           for (step_idx = 0, step = steps[step_idx];
  2.9723 +               step_idx < LSF_NUMBER_OF_STEPS;){
  2.9724 +
  2.9725 +               /*  cos(10piw) + pq(0)cos(8piw) + pq(1)cos(6piw) +
  2.9726 +               pq(2)cos(4piw) + pq(3)cod(2piw) + pq(4) */
  2.9727 +
  2.9728 +               hlp = (float)cos(omega * TWO_PI);
  2.9729 +               hlp1 = (float)2.0 * hlp + pq_coef[0];
  2.9730 +               hlp2 = (float)2.0 * hlp * hlp1 - (float)1.0 +
  2.9731 +                   pq_coef[1];
  2.9732 +               hlp3 = (float)2.0 * hlp * hlp2 - hlp1 + pq_coef[2];
  2.9733 +               hlp4 = (float)2.0 * hlp * hlp3 - hlp2 + pq_coef[3];
  2.9734 +               hlp5 = hlp * hlp4 - hlp3 + pq_coef[4];
  2.9735 +
  2.9736 +
  2.9737 +               if (((hlp5 * (*old)) <= 0.0) || (omega >= 0.5)){
  2.9738 +
  2.9739 +                   if (step_idx == (LSF_NUMBER_OF_STEPS - 1)){
  2.9740 +
  2.9741 +                       if (fabs(hlp5) >= fabs(*old)) {
  2.9742 +                           freq[lsp_index] = omega - step;
  2.9743 +                       } else {
  2.9744 +                           freq[lsp_index] = omega;
  2.9745 +                       }
  2.9746 +
  2.9747 +
  2.9748 +
  2.9749 +Andersen, et al.              Experimental                    [Page 174]
  2.9750 +
  2.9751 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9752 +
  2.9753 +
  2.9754 +
  2.9755 +
  2.9756 +                       if ((*old) >= 0.0){
  2.9757 +                           *old = (float)-1.0 * FLOAT_MAX;
  2.9758 +                       } else {
  2.9759 +                           *old = FLOAT_MAX;
  2.9760 +                       }
  2.9761 +
  2.9762 +                       omega = old_omega;
  2.9763 +                       step_idx = 0;
  2.9764 +
  2.9765 +                       step_idx = LSF_NUMBER_OF_STEPS;
  2.9766 +                   } else {
  2.9767 +
  2.9768 +                       if (step_idx == 0) {
  2.9769 +                           old_omega = omega;
  2.9770 +                       }
  2.9771 +
  2.9772 +                       step_idx++;
  2.9773 +                       omega -= steps[step_idx];
  2.9774 +
  2.9775 +                       /* Go back one grid step */
  2.9776 +
  2.9777 +                       step = steps[step_idx];
  2.9778 +                   }
  2.9779 +               } else {
  2.9780 +
  2.9781 +               /* increment omega until they are of different sign,
  2.9782 +               and we know there is at least one root between omega
  2.9783 +               and old_omega */
  2.9784 +                   *old = hlp5;
  2.9785 +                   omega += step;
  2.9786 +               }
  2.9787 +           }
  2.9788 +       }
  2.9789 +
  2.9790 +       for (i = 0; i<LPC_FILTERORDER; i++) {
  2.9791 +           freq[i] = freq[i] * TWO_PI;
  2.9792 +       }
  2.9793 +   }
  2.9794 +
  2.9795 +   /*----------------------------------------------------------------*
  2.9796 +    *  conversion from lsf coefficients to lpc coefficients
  2.9797 +    *---------------------------------------------------------------*/
  2.9798 +
  2.9799 +   void lsf2a(
  2.9800 +       float *a_coef,  /* (o) lpc coefficients */
  2.9801 +       float *freq     /* (i) lsf coefficients */
  2.9802 +
  2.9803 +
  2.9804 +
  2.9805 +Andersen, et al.              Experimental                    [Page 175]
  2.9806 +
  2.9807 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9808 +
  2.9809 +
  2.9810 +   ){
  2.9811 +       int i, j;
  2.9812 +       float hlp;
  2.9813 +       float p[LPC_HALFORDER], q[LPC_HALFORDER];
  2.9814 +       float a[LPC_HALFORDER + 1], a1[LPC_HALFORDER],
  2.9815 +           a2[LPC_HALFORDER];
  2.9816 +       float b[LPC_HALFORDER + 1], b1[LPC_HALFORDER],
  2.9817 +           b2[LPC_HALFORDER];
  2.9818 +
  2.9819 +       for (i=0; i<LPC_FILTERORDER; i++) {
  2.9820 +           freq[i] = freq[i] * PI2;
  2.9821 +       }
  2.9822 +
  2.9823 +       /* Check input for ill-conditioned cases.  This part is not
  2.9824 +       found in the TIA standard.  It involves the following 2 IF
  2.9825 +       blocks.  If "freq" is judged ill-conditioned, then we first
  2.9826 +       modify freq[0] and freq[LPC_HALFORDER-1] (normally
  2.9827 +       LPC_HALFORDER = 10 for LPC applications), then we adjust
  2.9828 +       the other "freq" values slightly */
  2.9829 +
  2.9830 +
  2.9831 +       if ((freq[0] <= 0.0) || (freq[LPC_FILTERORDER - 1] >= 0.5)){
  2.9832 +
  2.9833 +
  2.9834 +           if (freq[0] <= 0.0) {
  2.9835 +               freq[0] = (float)0.022;
  2.9836 +           }
  2.9837 +
  2.9838 +
  2.9839 +           if (freq[LPC_FILTERORDER - 1] >= 0.5) {
  2.9840 +               freq[LPC_FILTERORDER - 1] = (float)0.499;
  2.9841 +           }
  2.9842 +
  2.9843 +           hlp = (freq[LPC_FILTERORDER - 1] - freq[0]) /
  2.9844 +               (float) (LPC_FILTERORDER - 1);
  2.9845 +
  2.9846 +           for (i=1; i<LPC_FILTERORDER; i++) {
  2.9847 +               freq[i] = freq[i - 1] + hlp;
  2.9848 +           }
  2.9849 +       }
  2.9850 +
  2.9851 +       memset(a1, 0, LPC_HALFORDER*sizeof(float));
  2.9852 +       memset(a2, 0, LPC_HALFORDER*sizeof(float));
  2.9853 +       memset(b1, 0, LPC_HALFORDER*sizeof(float));
  2.9854 +       memset(b2, 0, LPC_HALFORDER*sizeof(float));
  2.9855 +       memset(a, 0, (LPC_HALFORDER+1)*sizeof(float));
  2.9856 +       memset(b, 0, (LPC_HALFORDER+1)*sizeof(float));
  2.9857 +
  2.9858 +
  2.9859 +
  2.9860 +
  2.9861 +Andersen, et al.              Experimental                    [Page 176]
  2.9862 +
  2.9863 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9864 +
  2.9865 +
  2.9866 +       /* p[i] and q[i] compute cos(2*pi*omega_{2j}) and
  2.9867 +       cos(2*pi*omega_{2j-1} in eqs. 4.2.2.2-1 and 4.2.2.2-2.
  2.9868 +       Note that for this code p[i] specifies the coefficients
  2.9869 +       used in .Q_A(z) while q[i] specifies the coefficients used
  2.9870 +       in .P_A(z) */
  2.9871 +
  2.9872 +       for (i=0; i<LPC_HALFORDER; i++) {
  2.9873 +           p[i] = (float)cos(TWO_PI * freq[2 * i]);
  2.9874 +           q[i] = (float)cos(TWO_PI * freq[2 * i + 1]);
  2.9875 +       }
  2.9876 +
  2.9877 +       a[0] = 0.25;
  2.9878 +       b[0] = 0.25;
  2.9879 +
  2.9880 +       for (i= 0; i<LPC_HALFORDER; i++) {
  2.9881 +           a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];
  2.9882 +           b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];
  2.9883 +           a2[i] = a1[i];
  2.9884 +           a1[i] = a[i];
  2.9885 +           b2[i] = b1[i];
  2.9886 +           b1[i] = b[i];
  2.9887 +       }
  2.9888 +
  2.9889 +       for (j=0; j<LPC_FILTERORDER; j++) {
  2.9890 +
  2.9891 +           if (j == 0) {
  2.9892 +               a[0] = 0.25;
  2.9893 +               b[0] = -0.25;
  2.9894 +           } else {
  2.9895 +               a[0] = b[0] = 0.0;
  2.9896 +           }
  2.9897 +
  2.9898 +           for (i=0; i<LPC_HALFORDER; i++) {
  2.9899 +               a[i + 1] = a[i] - 2 * p[i] * a1[i] + a2[i];
  2.9900 +               b[i + 1] = b[i] - 2 * q[i] * b1[i] + b2[i];
  2.9901 +               a2[i] = a1[i];
  2.9902 +               a1[i] = a[i];
  2.9903 +               b2[i] = b1[i];
  2.9904 +               b1[i] = b[i];
  2.9905 +           }
  2.9906 +
  2.9907 +           a_coef[j + 1] = 2 * (a[LPC_HALFORDER] + b[LPC_HALFORDER]);
  2.9908 +       }
  2.9909 +
  2.9910 +       a_coef[0] = 1.0;
  2.9911 +   }
  2.9912 +
  2.9913 +
  2.9914 +
  2.9915 +
  2.9916 +
  2.9917 +Andersen, et al.              Experimental                    [Page 177]
  2.9918 +
  2.9919 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9920 +
  2.9921 +
  2.9922 +A.41.  packing.h
  2.9923 +
  2.9924 +   /******************************************************************
  2.9925 +
  2.9926 +       iLBC Speech Coder ANSI-C Source Code
  2.9927 +
  2.9928 +       packing.h
  2.9929 +
  2.9930 +       Copyright (C) The Internet Society (2004).
  2.9931 +       All Rights Reserved.
  2.9932 +
  2.9933 +   ******************************************************************/
  2.9934 +
  2.9935 +   #ifndef __PACKING_H
  2.9936 +   #define __PACKING_H
  2.9937 +
  2.9938 +   void packsplit(
  2.9939 +       int *index,                 /* (i) the value to split */
  2.9940 +       int *firstpart,             /* (o) the value specified by most
  2.9941 +                                          significant bits */
  2.9942 +       int *rest,                  /* (o) the value specified by least
  2.9943 +                                          significant bits */
  2.9944 +       int bitno_firstpart,    /* (i) number of bits in most
  2.9945 +                                          significant part */
  2.9946 +       int bitno_total             /* (i) number of bits in full range
  2.9947 +                                          of value */
  2.9948 +   );
  2.9949 +
  2.9950 +   void packcombine(
  2.9951 +       int *index,                 /* (i/o) the msb value in the
  2.9952 +                                          combined value out */
  2.9953 +       int rest,                   /* (i) the lsb value */
  2.9954 +       int bitno_rest              /* (i) the number of bits in the
  2.9955 +                                          lsb part */
  2.9956 +   );
  2.9957 +
  2.9958 +   void dopack(
  2.9959 +       unsigned char **bitstream,  /* (i/o) on entrance pointer to
  2.9960 +                                          place in bitstream to pack
  2.9961 +                                          new data, on exit pointer
  2.9962 +                                          to place in bitstream to
  2.9963 +                                          pack future data */
  2.9964 +       int index,                  /* (i) the value to pack */
  2.9965 +       int bitno,                  /* (i) the number of bits that the
  2.9966 +                                          value will fit within */
  2.9967 +       int *pos                /* (i/o) write position in the
  2.9968 +                                          current byte */
  2.9969 +   );
  2.9970 +
  2.9971 +
  2.9972 +
  2.9973 +Andersen, et al.              Experimental                    [Page 178]
  2.9974 +
  2.9975 +RFC 3951              Internet Low Bit Rate Codec          December 2004
  2.9976 +
  2.9977 +
  2.9978 +   void unpack(
  2.9979 +       unsigned char **bitstream,  /* (i/o) on entrance pointer to
  2.9980 +                                          place in bitstream to
  2.9981 +                                          unpack new data from, on
  2.9982 +                                          exit pointer to place in
  2.9983 +                                          bitstream to unpack future
  2.9984 +                                          data from */
  2.9985 +       int *index,                 /* (o) resulting value */
  2.9986 +       int bitno,                  /* (i) number of bits used to
  2.9987 +                                          represent the value */
  2.9988 +       int *pos                /* (i/o) read position in the
  2.9989 +                                          current byte */
  2.9990 +   );
  2.9991 +
  2.9992 +   #endif
  2.9993 +
  2.9994 +A.42.  packing.c
  2.9995 +
  2.9996 +   /******************************************************************
  2.9997 +
  2.9998 +       iLBC Speech Coder ANSI-C Source Code
  2.9999 +
 2.10000 +       packing.c
 2.10001 +
 2.10002 +       Copyright (C) The Internet Society (2004).
 2.10003 +       All Rights Reserved.
 2.10004 +
 2.10005 +   ******************************************************************/
 2.10006 +
 2.10007 +   #include <math.h>
 2.10008 +   #include <stdlib.h>
 2.10009 +
 2.10010 +   #include "iLBC_define.h"
 2.10011 +   #include "constants.h"
 2.10012 +   #include "helpfun.h"
 2.10013 +   #include "string.h"
 2.10014 +
 2.10015 +   /*----------------------------------------------------------------*
 2.10016 +    *  splitting an integer into first most significant bits and
 2.10017 +    *  remaining least significant bits
 2.10018 +    *---------------------------------------------------------------*/
 2.10019 +
 2.10020 +   void packsplit(
 2.10021 +       int *index,                 /* (i) the value to split */
 2.10022 +       int *firstpart,             /* (o) the value specified by most
 2.10023 +                                          significant bits */
 2.10024 +       int *rest,                  /* (o) the value specified by least
 2.10025 +                                          significant bits */
 2.10026 +
 2.10027 +
 2.10028 +
 2.10029 +Andersen, et al.              Experimental                    [Page 179]
 2.10030 +
 2.10031 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10032 +
 2.10033 +
 2.10034 +       int bitno_firstpart,    /* (i) number of bits in most
 2.10035 +                                          significant part */
 2.10036 +       int bitno_total             /* (i) number of bits in full range
 2.10037 +                                          of value */
 2.10038 +   ){
 2.10039 +       int bitno_rest = bitno_total-bitno_firstpart;
 2.10040 +
 2.10041 +       *firstpart = *index>>(bitno_rest);
 2.10042 +       *rest = *index-(*firstpart<<(bitno_rest));
 2.10043 +   }
 2.10044 +
 2.10045 +   /*----------------------------------------------------------------*
 2.10046 +    *  combining a value corresponding to msb's with a value
 2.10047 +    *  corresponding to lsb's
 2.10048 +    *---------------------------------------------------------------*/
 2.10049 +
 2.10050 +   void packcombine(
 2.10051 +       int *index,                 /* (i/o) the msb value in the
 2.10052 +                                          combined value out */
 2.10053 +       int rest,                   /* (i) the lsb value */
 2.10054 +       int bitno_rest              /* (i) the number of bits in the
 2.10055 +                                          lsb part */
 2.10056 +   ){
 2.10057 +       *index = *index<<bitno_rest;
 2.10058 +       *index += rest;
 2.10059 +   }
 2.10060 +
 2.10061 +   /*----------------------------------------------------------------*
 2.10062 +    *  packing of bits into bitstream, i.e., vector of bytes
 2.10063 +    *---------------------------------------------------------------*/
 2.10064 +
 2.10065 +   void dopack(
 2.10066 +       unsigned char **bitstream,  /* (i/o) on entrance pointer to
 2.10067 +                                          place in bitstream to pack
 2.10068 +                                          new data, on exit pointer
 2.10069 +                                          to place in bitstream to
 2.10070 +                                          pack future data */
 2.10071 +       int index,                  /* (i) the value to pack */
 2.10072 +       int bitno,                  /* (i) the number of bits that the
 2.10073 +                                          value will fit within */
 2.10074 +       int *pos                /* (i/o) write position in the
 2.10075 +                                          current byte */
 2.10076 +   ){
 2.10077 +       int posLeft;
 2.10078 +
 2.10079 +       /* Clear the bits before starting in a new byte */
 2.10080 +
 2.10081 +       if ((*pos)==0) {
 2.10082 +
 2.10083 +
 2.10084 +
 2.10085 +Andersen, et al.              Experimental                    [Page 180]
 2.10086 +
 2.10087 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10088 +
 2.10089 +
 2.10090 +           **bitstream=0;
 2.10091 +       }
 2.10092 +
 2.10093 +       while (bitno>0) {
 2.10094 +
 2.10095 +           /* Jump to the next byte if end of this byte is reached*/
 2.10096 +
 2.10097 +           if (*pos==8) {
 2.10098 +               *pos=0;
 2.10099 +               (*bitstream)++;
 2.10100 +               **bitstream=0;
 2.10101 +           }
 2.10102 +
 2.10103 +           posLeft=8-(*pos);
 2.10104 +
 2.10105 +           /* Insert index into the bitstream */
 2.10106 +
 2.10107 +           if (bitno <= posLeft) {
 2.10108 +               **bitstream |= (unsigned char)(index<<(posLeft-bitno));
 2.10109 +               *pos+=bitno;
 2.10110 +               bitno=0;
 2.10111 +           } else {
 2.10112 +               **bitstream |= (unsigned char)(index>>(bitno-posLeft));
 2.10113 +
 2.10114 +               *pos=8;
 2.10115 +               index-=((index>>(bitno-posLeft))<<(bitno-posLeft));
 2.10116 +
 2.10117 +               bitno-=posLeft;
 2.10118 +           }
 2.10119 +       }
 2.10120 +   }
 2.10121 +
 2.10122 +   /*----------------------------------------------------------------*
 2.10123 +    *  unpacking of bits from bitstream, i.e., vector of bytes
 2.10124 +    *---------------------------------------------------------------*/
 2.10125 +
 2.10126 +   void unpack(
 2.10127 +       unsigned char **bitstream,  /* (i/o) on entrance pointer to
 2.10128 +                                          place in bitstream to
 2.10129 +                                          unpack new data from, on
 2.10130 +                                          exit pointer to place in
 2.10131 +                                          bitstream to unpack future
 2.10132 +                                          data from */
 2.10133 +       int *index,                 /* (o) resulting value */
 2.10134 +       int bitno,                  /* (i) number of bits used to
 2.10135 +                                          represent the value */
 2.10136 +       int *pos                /* (i/o) read position in the
 2.10137 +                                          current byte */
 2.10138 +
 2.10139 +
 2.10140 +
 2.10141 +Andersen, et al.              Experimental                    [Page 181]
 2.10142 +
 2.10143 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10144 +
 2.10145 +
 2.10146 +   ){
 2.10147 +       int BitsLeft;
 2.10148 +
 2.10149 +       *index=0;
 2.10150 +
 2.10151 +       while (bitno>0) {
 2.10152 +
 2.10153 +           /* move forward in bitstream when the end of the
 2.10154 +              byte is reached */
 2.10155 +
 2.10156 +           if (*pos==8) {
 2.10157 +               *pos=0;
 2.10158 +               (*bitstream)++;
 2.10159 +           }
 2.10160 +
 2.10161 +           BitsLeft=8-(*pos);
 2.10162 +
 2.10163 +           /* Extract bits to index */
 2.10164 +
 2.10165 +           if (BitsLeft>=bitno) {
 2.10166 +               *index+=((((**bitstream)<<(*pos)) & 0xFF)>>(8-bitno));
 2.10167 +
 2.10168 +               *pos+=bitno;
 2.10169 +               bitno=0;
 2.10170 +           } else {
 2.10171 +
 2.10172 +               if ((8-bitno)>0) {
 2.10173 +                   *index+=((((**bitstream)<<(*pos)) & 0xFF)>>
 2.10174 +                       (8-bitno));
 2.10175 +                   *pos=8;
 2.10176 +               } else {
 2.10177 +                   *index+=(((int)(((**bitstream)<<(*pos)) & 0xFF))<<
 2.10178 +                       (bitno-8));
 2.10179 +                   *pos=8;
 2.10180 +               }
 2.10181 +               bitno-=BitsLeft;
 2.10182 +           }
 2.10183 +       }
 2.10184 +   }
 2.10185 +
 2.10186 +A.43.  StateConstructW.h
 2.10187 +
 2.10188 +   /******************************************************************
 2.10189 +
 2.10190 +       iLBC Speech Coder ANSI-C Source Code
 2.10191 +
 2.10192 +       StateConstructW.h
 2.10193 +
 2.10194 +
 2.10195 +
 2.10196 +
 2.10197 +Andersen, et al.              Experimental                    [Page 182]
 2.10198 +
 2.10199 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10200 +
 2.10201 +
 2.10202 +       Copyright (C) The Internet Society (2004).
 2.10203 +       All Rights Reserved.
 2.10204 +
 2.10205 +   ******************************************************************/
 2.10206 +
 2.10207 +   #ifndef __iLBC_STATECONSTRUCTW_H
 2.10208 +   #define __iLBC_STATECONSTRUCTW_H
 2.10209 +
 2.10210 +   void StateConstructW(
 2.10211 +       int idxForMax,      /* (i) 6-bit index for the quantization of
 2.10212 +                                  max amplitude */
 2.10213 +       int *idxVec,    /* (i) vector of quantization indexes */
 2.10214 +       float *syntDenum,   /* (i) synthesis filter denumerator */
 2.10215 +       float *out,         /* (o) the decoded state vector */
 2.10216 +       int len             /* (i) length of a state vector */
 2.10217 +   );
 2.10218 +
 2.10219 +   #endif
 2.10220 +
 2.10221 +A.44.  StateConstructW.c
 2.10222 +
 2.10223 +   /******************************************************************
 2.10224 +
 2.10225 +       iLBC Speech Coder ANSI-C Source Code
 2.10226 +
 2.10227 +       StateConstructW.c
 2.10228 +
 2.10229 +       Copyright (C) The Internet Society (2004).
 2.10230 +       All Rights Reserved.
 2.10231 +
 2.10232 +   ******************************************************************/
 2.10233 +
 2.10234 +   #include <math.h>
 2.10235 +   #include <string.h>
 2.10236 +
 2.10237 +   #include "iLBC_define.h"
 2.10238 +   #include "constants.h"
 2.10239 +   #include "filter.h"
 2.10240 +
 2.10241 +   /*----------------------------------------------------------------*
 2.10242 +    *  decoding of the start state
 2.10243 +    *---------------------------------------------------------------*/
 2.10244 +
 2.10245 +   void StateConstructW(
 2.10246 +       int idxForMax,      /* (i) 6-bit index for the quantization of
 2.10247 +                                  max amplitude */
 2.10248 +       int *idxVec,    /* (i) vector of quantization indexes */
 2.10249 +       float *syntDenum,   /* (i) synthesis filter denumerator */
 2.10250 +
 2.10251 +
 2.10252 +
 2.10253 +Andersen, et al.              Experimental                    [Page 183]
 2.10254 +
 2.10255 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10256 +
 2.10257 +
 2.10258 +       float *out,         /* (o) the decoded state vector */
 2.10259 +       int len             /* (i) length of a state vector */
 2.10260 +   ){
 2.10261 +       float maxVal, tmpbuf[LPC_FILTERORDER+2*STATE_LEN], *tmp,
 2.10262 +           numerator[LPC_FILTERORDER+1];
 2.10263 +       float foutbuf[LPC_FILTERORDER+2*STATE_LEN], *fout;
 2.10264 +       int k,tmpi;
 2.10265 +
 2.10266 +       /* decoding of the maximum value */
 2.10267 +
 2.10268 +       maxVal = state_frgqTbl[idxForMax];
 2.10269 +       maxVal = (float)pow(10,maxVal)/(float)4.5;
 2.10270 +
 2.10271 +       /* initialization of buffers and coefficients */
 2.10272 +
 2.10273 +       memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));
 2.10274 +       memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));
 2.10275 +       for (k=0; k<LPC_FILTERORDER; k++) {
 2.10276 +           numerator[k]=syntDenum[LPC_FILTERORDER-k];
 2.10277 +       }
 2.10278 +       numerator[LPC_FILTERORDER]=syntDenum[0];
 2.10279 +       tmp = &tmpbuf[LPC_FILTERORDER];
 2.10280 +       fout = &foutbuf[LPC_FILTERORDER];
 2.10281 +
 2.10282 +       /* decoding of the sample values */
 2.10283 +
 2.10284 +       for (k=0; k<len; k++) {
 2.10285 +           tmpi = len-1-k;
 2.10286 +           /* maxVal = 1/scal */
 2.10287 +           tmp[k] = maxVal*state_sq3Tbl[idxVec[tmpi]];
 2.10288 +       }
 2.10289 +
 2.10290 +       /* circular convolution with all-pass filter */
 2.10291 +
 2.10292 +       memset(tmp+len, 0, len*sizeof(float));
 2.10293 +       ZeroPoleFilter(tmp, numerator, syntDenum, 2*len,
 2.10294 +           LPC_FILTERORDER, fout);
 2.10295 +       for (k=0;k<len;k++) {
 2.10296 +           out[k] = fout[len-1-k]+fout[2*len-1-k];
 2.10297 +       }
 2.10298 +   }
 2.10299 +
 2.10300 +
 2.10301 +
 2.10302 +
 2.10303 +
 2.10304 +
 2.10305 +
 2.10306 +
 2.10307 +
 2.10308 +
 2.10309 +Andersen, et al.              Experimental                    [Page 184]
 2.10310 +
 2.10311 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10312 +
 2.10313 +
 2.10314 +A.45.  StateSearchW.h
 2.10315 +
 2.10316 +   /******************************************************************
 2.10317 +
 2.10318 +       iLBC Speech Coder ANSI-C Source Code
 2.10319 +
 2.10320 +       StateSearchW.h
 2.10321 +
 2.10322 +       Copyright (C) The Internet Society (2004).
 2.10323 +       All Rights Reserved.
 2.10324 +
 2.10325 +   ******************************************************************/
 2.10326 +
 2.10327 +   #ifndef __iLBC_STATESEARCHW_H
 2.10328 +   #define __iLBC_STATESEARCHW_H
 2.10329 +
 2.10330 +   void AbsQuantW(
 2.10331 +       iLBC_Enc_Inst_t *iLBCenc_inst,
 2.10332 +                           /* (i) Encoder instance */
 2.10333 +       float *in,          /* (i) vector to encode */
 2.10334 +       float *syntDenum,   /* (i) denominator of synthesis filter */
 2.10335 +       float *weightDenum, /* (i) denominator of weighting filter */
 2.10336 +       int *out,           /* (o) vector of quantizer indexes */
 2.10337 +       int len,        /* (i) length of vector to encode and
 2.10338 +                                  vector of quantizer indexes */
 2.10339 +       int state_first     /* (i) position of start state in the
 2.10340 +                                  80 vec */
 2.10341 +   );
 2.10342 +
 2.10343 +   void StateSearchW(
 2.10344 +       iLBC_Enc_Inst_t *iLBCenc_inst,
 2.10345 +                           /* (i) Encoder instance */
 2.10346 +       float *residual,/* (i) target residual vector */
 2.10347 +       float *syntDenum,   /* (i) lpc synthesis filter */
 2.10348 +       float *weightDenum, /* (i) weighting filter denuminator */
 2.10349 +       int *idxForMax,     /* (o) quantizer index for maximum
 2.10350 +                                  amplitude */
 2.10351 +       int *idxVec,    /* (o) vector of quantization indexes */
 2.10352 +       int len,        /* (i) length of all vectors */
 2.10353 +       int state_first     /* (i) position of start state in the
 2.10354 +                                  80 vec */
 2.10355 +   );
 2.10356 +
 2.10357 +
 2.10358 +   #endif
 2.10359 +
 2.10360 +
 2.10361 +
 2.10362 +
 2.10363 +
 2.10364 +
 2.10365 +Andersen, et al.              Experimental                    [Page 185]
 2.10366 +
 2.10367 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10368 +
 2.10369 +
 2.10370 +A.46.  StateSearchW.c
 2.10371 +
 2.10372 +   /******************************************************************
 2.10373 +
 2.10374 +       iLBC Speech Coder ANSI-C Source Code
 2.10375 +
 2.10376 +       StateSearchW.c
 2.10377 +
 2.10378 +       Copyright (C) The Internet Society (2004).
 2.10379 +       All Rights Reserved.
 2.10380 +
 2.10381 +   ******************************************************************/
 2.10382 +
 2.10383 +   #include <math.h>
 2.10384 +   #include <string.h>
 2.10385 +
 2.10386 +   #include "iLBC_define.h"
 2.10387 +   #include "constants.h"
 2.10388 +   #include "filter.h"
 2.10389 +   #include "helpfun.h"
 2.10390 +
 2.10391 +   /*----------------------------------------------------------------*
 2.10392 +    *  predictive noise shaping encoding of scaled start state
 2.10393 +    *  (subrutine for StateSearchW)
 2.10394 +    *---------------------------------------------------------------*/
 2.10395 +
 2.10396 +   void AbsQuantW(
 2.10397 +       iLBC_Enc_Inst_t *iLBCenc_inst,
 2.10398 +                           /* (i) Encoder instance */
 2.10399 +       float *in,          /* (i) vector to encode */
 2.10400 +       float *syntDenum,   /* (i) denominator of synthesis filter */
 2.10401 +       float *weightDenum, /* (i) denominator of weighting filter */
 2.10402 +       int *out,           /* (o) vector of quantizer indexes */
 2.10403 +       int len,        /* (i) length of vector to encode and
 2.10404 +                                  vector of quantizer indexes */
 2.10405 +       int state_first     /* (i) position of start state in the
 2.10406 +                                  80 vec */
 2.10407 +   ){
 2.10408 +       float *syntOut;
 2.10409 +       float syntOutBuf[LPC_FILTERORDER+STATE_SHORT_LEN_30MS];
 2.10410 +       float toQ, xq;
 2.10411 +       int n;
 2.10412 +       int index;
 2.10413 +
 2.10414 +       /* initialization of buffer for filtering */
 2.10415 +
 2.10416 +       memset(syntOutBuf, 0, LPC_FILTERORDER*sizeof(float));
 2.10417 +
 2.10418 +
 2.10419 +
 2.10420 +
 2.10421 +Andersen, et al.              Experimental                    [Page 186]
 2.10422 +
 2.10423 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10424 +
 2.10425 +
 2.10426 +       /* initialization of pointer for filtering */
 2.10427 +
 2.10428 +       syntOut = &syntOutBuf[LPC_FILTERORDER];
 2.10429 +
 2.10430 +       /* synthesis and weighting filters on input */
 2.10431 +
 2.10432 +       if (state_first) {
 2.10433 +           AllPoleFilter (in, weightDenum, SUBL, LPC_FILTERORDER);
 2.10434 +       } else {
 2.10435 +           AllPoleFilter (in, weightDenum,
 2.10436 +               iLBCenc_inst->state_short_len-SUBL,
 2.10437 +               LPC_FILTERORDER);
 2.10438 +       }
 2.10439 +
 2.10440 +       /* encoding loop */
 2.10441 +
 2.10442 +       for (n=0; n<len; n++) {
 2.10443 +
 2.10444 +           /* time update of filter coefficients */
 2.10445 +
 2.10446 +           if ((state_first)&&(n==SUBL)){
 2.10447 +               syntDenum += (LPC_FILTERORDER+1);
 2.10448 +               weightDenum += (LPC_FILTERORDER+1);
 2.10449 +
 2.10450 +               /* synthesis and weighting filters on input */
 2.10451 +               AllPoleFilter (&in[n], weightDenum, len-n,
 2.10452 +                   LPC_FILTERORDER);
 2.10453 +
 2.10454 +           } else if ((state_first==0)&&
 2.10455 +               (n==(iLBCenc_inst->state_short_len-SUBL))) {
 2.10456 +               syntDenum += (LPC_FILTERORDER+1);
 2.10457 +               weightDenum += (LPC_FILTERORDER+1);
 2.10458 +
 2.10459 +               /* synthesis and weighting filters on input */
 2.10460 +               AllPoleFilter (&in[n], weightDenum, len-n,
 2.10461 +                   LPC_FILTERORDER);
 2.10462 +
 2.10463 +           }
 2.10464 +
 2.10465 +           /* prediction of synthesized and weighted input */
 2.10466 +
 2.10467 +           syntOut[n] = 0.0;
 2.10468 +           AllPoleFilter (&syntOut[n], weightDenum, 1,
 2.10469 +               LPC_FILTERORDER);
 2.10470 +
 2.10471 +           /* quantization */
 2.10472 +
 2.10473 +           toQ = in[n]-syntOut[n];
 2.10474 +
 2.10475 +
 2.10476 +
 2.10477 +Andersen, et al.              Experimental                    [Page 187]
 2.10478 +
 2.10479 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10480 +
 2.10481 +
 2.10482 +           sort_sq(&xq, &index, toQ, state_sq3Tbl, 8);
 2.10483 +           out[n]=index;
 2.10484 +           syntOut[n] = state_sq3Tbl[out[n]];
 2.10485 +
 2.10486 +           /* update of the prediction filter */
 2.10487 +
 2.10488 +           AllPoleFilter(&syntOut[n], weightDenum, 1,
 2.10489 +               LPC_FILTERORDER);
 2.10490 +       }
 2.10491 +   }
 2.10492 +
 2.10493 +   /*----------------------------------------------------------------*
 2.10494 +    *  encoding of start state
 2.10495 +    *---------------------------------------------------------------*/
 2.10496 +
 2.10497 +   void StateSearchW(
 2.10498 +       iLBC_Enc_Inst_t *iLBCenc_inst,
 2.10499 +                           /* (i) Encoder instance */
 2.10500 +       float *residual,/* (i) target residual vector */
 2.10501 +       float *syntDenum,   /* (i) lpc synthesis filter */
 2.10502 +       float *weightDenum, /* (i) weighting filter denuminator */
 2.10503 +       int *idxForMax,     /* (o) quantizer index for maximum
 2.10504 +                                  amplitude */
 2.10505 +       int *idxVec,    /* (o) vector of quantization indexes */
 2.10506 +       int len,        /* (i) length of all vectors */
 2.10507 +       int state_first     /* (i) position of start state in the
 2.10508 +                                  80 vec */
 2.10509 +   ){
 2.10510 +       float dtmp, maxVal;
 2.10511 +       float tmpbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS];
 2.10512 +       float *tmp, numerator[1+LPC_FILTERORDER];
 2.10513 +       float foutbuf[LPC_FILTERORDER+2*STATE_SHORT_LEN_30MS], *fout;
 2.10514 +       int k;
 2.10515 +       float qmax, scal;
 2.10516 +
 2.10517 +       /* initialization of buffers and filter coefficients */
 2.10518 +
 2.10519 +       memset(tmpbuf, 0, LPC_FILTERORDER*sizeof(float));
 2.10520 +       memset(foutbuf, 0, LPC_FILTERORDER*sizeof(float));
 2.10521 +       for (k=0; k<LPC_FILTERORDER; k++) {
 2.10522 +           numerator[k]=syntDenum[LPC_FILTERORDER-k];
 2.10523 +       }
 2.10524 +       numerator[LPC_FILTERORDER]=syntDenum[0];
 2.10525 +       tmp = &tmpbuf[LPC_FILTERORDER];
 2.10526 +       fout = &foutbuf[LPC_FILTERORDER];
 2.10527 +
 2.10528 +       /* circular convolution with the all-pass filter */
 2.10529 +
 2.10530 +
 2.10531 +
 2.10532 +
 2.10533 +Andersen, et al.              Experimental                    [Page 188]
 2.10534 +
 2.10535 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10536 +
 2.10537 +
 2.10538 +       memcpy(tmp, residual, len*sizeof(float));
 2.10539 +       memset(tmp+len, 0, len*sizeof(float));
 2.10540 +       ZeroPoleFilter(tmp, numerator, syntDenum, 2*len,
 2.10541 +           LPC_FILTERORDER, fout);
 2.10542 +       for (k=0; k<len; k++) {
 2.10543 +           fout[k] += fout[k+len];
 2.10544 +       }
 2.10545 +
 2.10546 +       /* identification of the maximum amplitude value */
 2.10547 +
 2.10548 +       maxVal = fout[0];
 2.10549 +       for (k=1; k<len; k++) {
 2.10550 +
 2.10551 +           if (fout[k]*fout[k] > maxVal*maxVal){
 2.10552 +               maxVal = fout[k];
 2.10553 +           }
 2.10554 +       }
 2.10555 +       maxVal=(float)fabs(maxVal);
 2.10556 +
 2.10557 +       /* encoding of the maximum amplitude value */
 2.10558 +
 2.10559 +       if (maxVal < 10.0) {
 2.10560 +           maxVal = 10.0;
 2.10561 +       }
 2.10562 +       maxVal = (float)log10(maxVal);
 2.10563 +       sort_sq(&dtmp, idxForMax, maxVal, state_frgqTbl, 64);
 2.10564 +
 2.10565 +       /* decoding of the maximum amplitude representation value,
 2.10566 +          and corresponding scaling of start state */
 2.10567 +
 2.10568 +       maxVal=state_frgqTbl[*idxForMax];
 2.10569 +       qmax = (float)pow(10,maxVal);
 2.10570 +       scal = (float)(4.5)/qmax;
 2.10571 +       for (k=0; k<len; k++){
 2.10572 +           fout[k] *= scal;
 2.10573 +       }
 2.10574 +
 2.10575 +       /* predictive noise shaping encoding of scaled start state */
 2.10576 +
 2.10577 +       AbsQuantW(iLBCenc_inst, fout,syntDenum,
 2.10578 +           weightDenum,idxVec, len, state_first);
 2.10579 +   }
 2.10580 +
 2.10581 +
 2.10582 +
 2.10583 +
 2.10584 +
 2.10585 +
 2.10586 +
 2.10587 +
 2.10588 +
 2.10589 +Andersen, et al.              Experimental                    [Page 189]
 2.10590 +
 2.10591 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10592 +
 2.10593 +
 2.10594 +A.47.  syntFilter.h
 2.10595 +
 2.10596 +   /******************************************************************
 2.10597 +
 2.10598 +       iLBC Speech Coder ANSI-C Source Code
 2.10599 +
 2.10600 +       syntFilter.h
 2.10601 +
 2.10602 +       Copyright (C) The Internet Society (2004).
 2.10603 +       All Rights Reserved.
 2.10604 +
 2.10605 +   ******************************************************************/
 2.10606 +
 2.10607 +   #ifndef __iLBC_SYNTFILTER_H
 2.10608 +   #define __iLBC_SYNTFILTER_H
 2.10609 +
 2.10610 +   void syntFilter(
 2.10611 +       float *Out,     /* (i/o) Signal to be filtered */
 2.10612 +       float *a,       /* (i) LP parameters */
 2.10613 +       int len,    /* (i) Length of signal */
 2.10614 +       float *mem      /* (i/o) Filter state */
 2.10615 +   );
 2.10616 +
 2.10617 +   #endif
 2.10618 +
 2.10619 +A.48.  syntFilter.c
 2.10620 +
 2.10621 +   /******************************************************************
 2.10622 +
 2.10623 +       iLBC Speech Coder ANSI-C Source Code
 2.10624 +
 2.10625 +       syntFilter.c
 2.10626 +
 2.10627 +       Copyright (C) The Internet Society (2004).
 2.10628 +       All Rights Reserved.
 2.10629 +
 2.10630 +   ******************************************************************/
 2.10631 +
 2.10632 +   #include "iLBC_define.h"
 2.10633 +
 2.10634 +   /*----------------------------------------------------------------*
 2.10635 +    *  LP synthesis filter.
 2.10636 +    *---------------------------------------------------------------*/
 2.10637 +
 2.10638 +   void syntFilter(
 2.10639 +       float *Out,     /* (i/o) Signal to be filtered */
 2.10640 +       float *a,       /* (i) LP parameters */
 2.10641 +       int len,    /* (i) Length of signal */
 2.10642 +
 2.10643 +
 2.10644 +
 2.10645 +Andersen, et al.              Experimental                    [Page 190]
 2.10646 +
 2.10647 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10648 +
 2.10649 +
 2.10650 +       float *mem      /* (i/o) Filter state */
 2.10651 +   ){
 2.10652 +       int i, j;
 2.10653 +       float *po, *pi, *pa, *pm;
 2.10654 +
 2.10655 +       po=Out;
 2.10656 +
 2.10657 +       /* Filter first part using memory from past */
 2.10658 +
 2.10659 +       for (i=0; i<LPC_FILTERORDER; i++) {
 2.10660 +           pi=&Out[i-1];
 2.10661 +           pa=&a[1];
 2.10662 +           pm=&mem[LPC_FILTERORDER-1];
 2.10663 +           for (j=1; j<=i; j++) {
 2.10664 +               *po-=(*pa++)*(*pi--);
 2.10665 +           }
 2.10666 +           for (j=i+1; j<LPC_FILTERORDER+1; j++) {
 2.10667 +               *po-=(*pa++)*(*pm--);
 2.10668 +           }
 2.10669 +           po++;
 2.10670 +       }
 2.10671 +
 2.10672 +       /* Filter last part where the state is entirely in
 2.10673 +          the output vector */
 2.10674 +
 2.10675 +       for (i=LPC_FILTERORDER; i<len; i++) {
 2.10676 +           pi=&Out[i-1];
 2.10677 +           pa=&a[1];
 2.10678 +           for (j=1; j<LPC_FILTERORDER+1; j++) {
 2.10679 +               *po-=(*pa++)*(*pi--);
 2.10680 +           }
 2.10681 +           po++;
 2.10682 +       }
 2.10683 +
 2.10684 +       /* Update state vector */
 2.10685 +
 2.10686 +       memcpy(mem, &Out[len-LPC_FILTERORDER],
 2.10687 +           LPC_FILTERORDER*sizeof(float));
 2.10688 +   }
 2.10689 +
 2.10690 +
 2.10691 +
 2.10692 +
 2.10693 +
 2.10694 +
 2.10695 +
 2.10696 +
 2.10697 +
 2.10698 +
 2.10699 +
 2.10700 +
 2.10701 +Andersen, et al.              Experimental                    [Page 191]
 2.10702 +
 2.10703 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10704 +
 2.10705 +
 2.10706 +Authors' Addresses
 2.10707 +
 2.10708 +   Soren Vang Andersen
 2.10709 +   Department of Communication Technology
 2.10710 +   Aalborg University
 2.10711 +   Fredrik Bajers Vej 7A
 2.10712 +   9200 Aalborg
 2.10713 +   Denmark
 2.10714 +
 2.10715 +   Phone:  ++45 9 6358627
 2.10716 +   EMail:  sva@kom.auc.dk
 2.10717 +
 2.10718 +
 2.10719 +   Alan Duric
 2.10720 +   Telio AS
 2.10721 +   Stoperigt. 2
 2.10722 +   Oslo, N-0250
 2.10723 +   Norway
 2.10724 +
 2.10725 +   Phone:  +47 21673555
 2.10726 +   EMail:  alan.duric@telio.no
 2.10727 +
 2.10728 +
 2.10729 +   Henrik Astrom
 2.10730 +   Global IP Sound AB
 2.10731 +   Olandsgatan 42
 2.10732 +   Stockholm, S-11663
 2.10733 +   Sweden
 2.10734 +
 2.10735 +   Phone:  +46 8 54553040
 2.10736 +   EMail:  henrik.astrom@globalipsound.com
 2.10737 +
 2.10738 +
 2.10739 +   Roar Hagen
 2.10740 +   Global IP Sound AB
 2.10741 +   Olandsgatan 42
 2.10742 +   Stockholm, S-11663
 2.10743 +   Sweden
 2.10744 +
 2.10745 +   Phone:  +46 8 54553040
 2.10746 +   EMail:  roar.hagen@globalipsound.com
 2.10747 +
 2.10748 +
 2.10749 +
 2.10750 +
 2.10751 +
 2.10752 +
 2.10753 +
 2.10754 +
 2.10755 +
 2.10756 +
 2.10757 +Andersen, et al.              Experimental                    [Page 192]
 2.10758 +
 2.10759 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10760 +
 2.10761 +
 2.10762 +   W. Bastiaan Kleijn
 2.10763 +   Global IP Sound AB
 2.10764 +   Olandsgatan 42
 2.10765 +   Stockholm, S-11663
 2.10766 +   Sweden
 2.10767 +
 2.10768 +   Phone:  +46 8 54553040
 2.10769 +   EMail:  bastiaan.kleijn@globalipsound.com
 2.10770 +
 2.10771 +
 2.10772 +   Jan Linden
 2.10773 +   Global IP Sound Inc.
 2.10774 +   900 Kearny Street, suite 500
 2.10775 +   San Francisco, CA-94133
 2.10776 +   USA
 2.10777 +
 2.10778 +   Phone: +1 415 397 2555
 2.10779 +   EMail: jan.linden@globalipsound.com
 2.10780 +
 2.10781 +
 2.10782 +
 2.10783 +
 2.10784 +
 2.10785 +
 2.10786 +
 2.10787 +
 2.10788 +
 2.10789 +
 2.10790 +
 2.10791 +
 2.10792 +
 2.10793 +
 2.10794 +
 2.10795 +
 2.10796 +
 2.10797 +
 2.10798 +
 2.10799 +
 2.10800 +
 2.10801 +
 2.10802 +
 2.10803 +
 2.10804 +
 2.10805 +
 2.10806 +
 2.10807 +
 2.10808 +
 2.10809 +
 2.10810 +
 2.10811 +
 2.10812 +
 2.10813 +Andersen, et al.              Experimental                    [Page 193]
 2.10814 +
 2.10815 +RFC 3951              Internet Low Bit Rate Codec          December 2004
 2.10816 +
 2.10817 +
 2.10818 +Full Copyright Statement
 2.10819 +
 2.10820 +   Copyright (C) The Internet Society (2004).
 2.10821 +
 2.10822 +   This document is subject to the rights, licenses and restrictions
 2.10823 +   contained in BCP 78, and except as set forth therein, the authors
 2.10824 +   retain all their rights.
 2.10825 +
 2.10826 +   This document and the information contained herein are provided on an
 2.10827 +   "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
 2.10828 +   OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET
 2.10829 +   ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED,
 2.10830 +   INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE
 2.10831 +   INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
 2.10832 +   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
 2.10833 +
 2.10834 +Intellectual Property
 2.10835 +
 2.10836 +   The IETF takes no position regarding the validity or scope of any
 2.10837 +   Intellectual Property Rights or other rights that might be claimed to
 2.10838 +   pertain to the implementation or use of the technology described in
 2.10839 +   this document or the extent to which any license under such rights
 2.10840 +   might or might not be available; nor does it represent that it has
 2.10841 +   made any independent effort to identify any such rights.  Information
 2.10842 +   on the IETF's procedures with respect to rights in IETF Documents can
 2.10843 +   be found in BCP 78 and BCP 79.
 2.10844 +
 2.10845 +   Copies of IPR disclosures made to the IETF Secretariat and any
 2.10846 +   assurances of licenses to be made available, or the result of an
 2.10847 +   attempt made to obtain a general license or permission for the use of
 2.10848 +   such proprietary rights by implementers or users of this
 2.10849 +   specification can be obtained from the IETF on-line IPR repository at
 2.10850 +   http://www.ietf.org/ipr.
 2.10851 +
 2.10852 +   The IETF invites any interested party to bring to its attention any
 2.10853 +   copyrights, patents or patent applications, or other proprietary
 2.10854 +   rights that may cover technology that may be required to implement
 2.10855 +   this standard.  Please address the information to the IETF at ietf-
 2.10856 +   ipr@ietf.org.
 2.10857 +
 2.10858 +
 2.10859 +Acknowledgement
 2.10860 +
 2.10861 +   Funding for the RFC Editor function is currently provided by the
 2.10862 +   Internet Society.
 2.10863 +
 2.10864 +
 2.10865 +
 2.10866 +
 2.10867 +
 2.10868 +
 2.10869 +Andersen, et al.              Experimental                    [Page 194]
 2.10870 +