RFC 6716






Internet Engineering Task Force (IETF)                         JM. Valin
Request for Comments: 6716                           Mozilla Corporation
Category: Standards Track                                         K. Vos
ISSN: 2070-1721                                  Skype Technologies S.A.
                                                           T. Terriberry
                                                     Mozilla Corporation
                                                          September 2012


                   Definition of the Opus Audio Codec

Abstract



   This document defines the Opus interactive speech and audio codec.
   Opus is designed to handle a wide range of interactive audio
   applications, including Voice over IP, videoconferencing, in-game
   chat, and even live, distributed music performances.  It scales from
   low bitrate narrowband speech at 6 kbit/s to very high quality stereo
   music at 510 kbit/s.  Opus uses both Linear Prediction (LP) and the
   Modified Discrete Cosine Transform (MDCT) to achieve good compression
   of both speech and music.

Status of This Memo



   This is an Internet Standards Track document.

   This document is a product of the Internet Engineering Task Force
   (IETF).  It represents the consensus of the IETF community.  It has
   received public review and has been approved for publication by the
   Internet Engineering Steering Group (IESG).  Further information on
   Internet Standards is available in Section 2 of RFC 5741.

   Information about the current status of this document, any errata,
   and how to provide feedback on it may be obtained at
   http://www.rfc-editor.org/info/rfc6716.
















Valin, et al.                Standards Track                    [Page 1]

RFC 6716                 Interactive Audio Codec          September 2012


Copyright Notice



   Copyright (c) 2012 IETF Trust and the persons identified as the
   document authors.  All rights reserved.

   This document is subject to BCP 78 and the IETF Trust's Legal
   Provisions Relating to IETF Documents
   (http://trustee.ietf.org/license-info) in effect on the date of
   publication of this document.  Please review these documents
   carefully, as they describe your rights and restrictions with respect
   to this document.  Code Components extracted from this document must
   include Simplified BSD License text as described in Section 4.e of
   the Trust Legal Provisions and are provided without warranty as
   described in the Simplified BSD License.

   The licenses granted by the IETF Trust to this RFC under Section 3.c
   of the Trust Legal Provisions shall also include the right to extract
   text from Sections 1 through 8 and A">Appendix A and Appendix B of this
   RFC and create derivative works from these extracts, and to copy,
   publish, display and distribute such derivative works in any medium
   and for any purpose, provided that no such derivative work shall be
   presented, displayed or published in a manner that states or implies
   that it is part of this RFC or any other IETF Document.

Table of Contents



   1. Introduction ....................................................5
      1.1. Notation and Conventions ...................................6
   2. Opus Codec Overview .............................................8
      2.1. Control Parameters ........................................10
           2.1.1. Bitrate ............................................10
           2.1.2. Number of Channels (Mono/Stereo) ...................11
           2.1.3. Audio Bandwidth ....................................11
           2.1.4. Frame Duration .....................................11
           2.1.5. Complexity .........................................11
           2.1.6. Packet Loss Resilience .............................12
           2.1.7. Forward Error Correction (FEC) .....................12
           2.1.8. Constant/Variable Bitrate ..........................12
           2.1.9. Discontinuous Transmission (DTX) ...................13
   3. Internal Framing ...............................................13
      3.1. The TOC Byte ..............................................13
      3.2. Frame Packing .............................................16
           3.2.1. Frame Length Coding ................................16
           3.2.2. Code 0: One Frame in the Packet ....................16
           3.2.3. Code 1: Two Frames in the Packet, Each with
                  Equal Compressed Size ..............................17
           3.2.4. Code 2: Two Frames in the Packet, with
                  Different Compressed Sizes .........................17



Valin, et al.                Standards Track                    [Page 2]

RFC 6716                 Interactive Audio Codec          September 2012


           3.2.5. Code 3: A Signaled Number of Frames in the Packet ..18
      3.3. Examples ..................................................21
      3.4. Receiving Malformed Packets ...............................22
   4. Opus Decoder ...................................................23
      4.1. Range Decoder .............................................23
           4.1.1. Range Decoder Initialization .......................25
           4.1.2. Decoding Symbols ...................................25
           4.1.3. Alternate Decoding Methods .........................27
           4.1.4. Decoding Raw Bits ..................................29
           4.1.5. Decoding Uniformly Distributed Integers ............29
           4.1.6. Current Bit Usage ..................................30
      4.2. SILK Decoder ..............................................32
           4.2.1. SILK Decoder Modules ...............................32
           4.2.2. LP Layer Organization ..............................33
           4.2.3. Header Bits ........................................35
           4.2.4. Per-Frame LBRR Flags ...............................36
           4.2.5. LBRR Frames ........................................36
           4.2.6. Regular SILK Frames ................................37
           4.2.7. SILK Frame Contents ................................37
                  4.2.7.1. Stereo Prediction Weights .................40
                  4.2.7.2. Mid-Only Flag .............................42
                  4.2.7.3. Frame Type ................................43
                  4.2.7.4. Subframe Gains ............................44
                  4.2.7.5. Normalized Line Spectral Frequency
                           (LSF) and Linear Predictive Coding (LPC)
                           Coeffieients ..............................46
                  4.2.7.6. Long-Term Prediction (LTP) Parameters .....74
                  4.2.7.7. Linear Congruential Generator (LCG) Seed ..86
                  4.2.7.8. Excitation ................................86
                  4.2.7.9. SILK Frame Reconstruction .................98
           4.2.8. Stereo Unmixing ...................................102
           4.2.9. Resampling ........................................103
      4.3. CELT Decoder .............................................104
           4.3.1. Transient Decoding ................................108
           4.3.2. Energy Envelope Decoding ..........................108
           4.3.3. Bit Allocation ....................................110
           4.3.4. Shape Decoding ....................................116
           4.3.5. Anti-collapse Processing ..........................120
           4.3.6. Denormalization ...................................121
           4.3.7. Inverse MDCT ......................................121
      4.4. Packet Loss Concealment (PLC) ............................122
           4.4.1. Clock Drift Compensation ..........................122
      4.5. Configuration Switching ..................................123
           4.5.1. Transition Side Information (Redundancy) ..........124
           4.5.2. State Reset .......................................127
           4.5.3. Summary of Transitions ............................128
   5. Opus Encoder ..................................................131
      5.1. Range Encoder ............................................132



Valin, et al.                Standards Track                    [Page 3]

RFC 6716                 Interactive Audio Codec          September 2012


           5.1.1. Encoding Symbols ..................................133
           5.1.2. Alternate Encoding Methods ........................134
           5.1.3. Encoding Raw Bits .................................135
           5.1.4. Encoding Uniformly Distributed Integers ...........135
           5.1.5. Finalizing the Stream .............................135
           5.1.6. Current Bit Usage .................................136
      5.2. SILK Encoder .............................................136
           5.2.1. Sample Rate Conversion ............................137
           5.2.2. Stereo Mixing .....................................137
           5.2.3. SILK Core Encoder .................................138
      5.3. CELT Encoder .............................................150
           5.3.1. Pitch Pre-filter ..................................150
           5.3.2. Bands and Normalization ...........................151
           5.3.3. Energy Envelope Quantization ......................151
           5.3.4. Bit Allocation ....................................151
           5.3.5. Stereo Decisions ..................................152
           5.3.6. Time-Frequency Decision ...........................153
           5.3.7. Spreading Values Decision .........................153
           5.3.8. Spherical Vector Quantization .....................154
   6. Conformance ...................................................155
      6.1. Testing ..................................................155
      6.2. Opus Custom ..............................................156
   7. Security Considerations .......................................157
   8. Acknowledgements ..............................................158
   9. References ....................................................159
      9.1. Normative References .....................................159
      9.2. Informative References ...................................159
   Appendix A. Reference Implementation .............................163
      A.1. Extracting the Source ....................................164
      A.2. Up-to-Date Implementation ................................164
      A.3. Base64-Encoded Source Code ...............................164
      A.4. Test Vectors .............................................321
   Appendix B. Self-Delimiting Framing ..............................321


















Valin, et al.                Standards Track                    [Page 4]

RFC 6716                 Interactive Audio Codec          September 2012


1.  Introduction



   The Opus codec is a real-time interactive audio codec designed to
   meet the requirements described in [REQUIREMENTS].  It is composed of
   a layer based on Linear Prediction (LP) [LPC] and a layer based on
   the Modified Discrete Cosine Transform (MDCT) [MDCT].  The main idea
   behind using two layers is as follows: in speech, linear prediction
   techniques (such as Code-Excited Linear Prediction, or CELP) code low
   frequencies more efficiently than transform (e.g., MDCT) domain
   techniques, while the situation is reversed for music and higher
   speech frequencies.  Thus, a codec with both layers available can
   operate over a wider range than either one alone and can achieve
   better quality by combining them than by using either one
   individually.

   The primary normative part of this specification is provided by the
   source code in Appendix A.  Only the decoder portion of this software
   is normative, though a significant amount of code is shared by both
   the encoder and decoder.  Section 6 provides a decoder conformance
   test.  The decoder contains a great deal of integer and fixed-point
   arithmetic that needs to be performed exactly, including all rounding
   considerations, so any useful specification requires domain-specific
   symbolic language to adequately define these operations.
   Additionally, any conflict between the symbolic representation and
   the included reference implementation must be resolved.  For the
   practical reasons of compatibility and testability, it would be
   advantageous to give the reference implementation priority in any
   disagreement.  The C language is also one of the most widely
   understood, human-readable symbolic representations for machine
   behavior.  For these reasons, this RFC uses the reference
   implementation as the sole symbolic representation of the codec.

   While the symbolic representation is unambiguous and complete, it is
   not always the easiest way to understand the codec's operation.  For
   this reason, this document also describes significant parts of the
   codec in prose and takes the opportunity to explain the rationale
   behind many of the more surprising elements of the design.  These
   descriptions are intended to be accurate and informative, but the
   limitations of common English sometimes result in ambiguity, so it is
   expected that the reader will always read them alongside the symbolic
   representation.  Numerous references to the implementation are
   provided for this purpose.  The descriptions sometimes differ from
   the reference in ordering or through mathematical simplification
   wherever such deviation makes an explanation easier to understand.
   For example, the right shift and left shift operations in the
   reference implementation are often described using division and





Valin, et al.                Standards Track                    [Page 5]

RFC 6716                 Interactive Audio Codec          September 2012


   multiplication in the text.  In general, the text is focused on the
   "what" and "why" while the symbolic representation most clearly
   provides the "how".

1.1.  Notation and Conventions



   The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
   "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
   document are to be interpreted as described in RFC 2119 [RFC2119].

   Various operations in the codec require bit-exact fixed-point
   behavior, even when writing a floating point implementation.  The
   notation "Q<n>", where n is an integer, denotes the number of binary
   digits to the right of the decimal point in a fixed-point number.
   For example, a signed Q14 value in a 16-bit word can represent values
   from -2.0 to 1.99993896484375, inclusive.  This notation is for
   informational purposes only.  Arithmetic, when described, always
   operates on the underlying integer.  For example, the text will
   explicitly indicate any shifts required after a multiplication.

   Expressions, where included in the text, follow C operator rules and
   precedence, with the exception that the syntax "x**y" indicates x
   raised to the power y.  The text also makes use of the following
   functions.

1.1.1.  min(x,y)



   The smallest of two values x and y.

1.1.2.  max(x,y)



   The largest of two values x and y.

1.1.3.  clamp(lo,x,hi)



                     clamp(lo,x,hi) = max(lo,min(x,hi))

   With this definition, if lo > hi, then lo is returned.

1.1.4.  sign(x)



   The sign of x, i.e.,

                                    ( -1,  x < 0
                          sign(x) = <  0,  x == 0
                                    (  1,  x > 0





Valin, et al.                Standards Track                    [Page 6]

RFC 6716                 Interactive Audio Codec          September 2012


1.1.5.  abs(x)



   The absolute value of x, i.e.,

                             abs(x) = sign(x)*x

1.1.6.  floor(f)



   The largest integer z such that z <= f.

1.1.7.  ceil(f)



   The smallest integer z such that z >= f.

1.1.8.  round(f)



   The integer z nearest to f, with ties rounded towards negative
   infinity, i.e.,

                           round(f) = ceil(f - 0.5)

1.1.9.  log2(f)



   The base-two logarithm of f.

1.1.10.  ilog(n)



   The minimum number of bits required to store a positive integer n in
   binary, or 0 for a non-positive integer n.

                              ( 0,                 n <= 0
                    ilog(n) = <
                              ( floor(log2(n))+1,  n > 0

   Examples:

   o  ilog(-1) = 0

   o  ilog(0) = 0

   o  ilog(1) = 1

   o  ilog(2) = 2

   o  ilog(3) = 2

   o  ilog(4) = 3




Valin, et al.                Standards Track                    [Page 7]

RFC 6716                 Interactive Audio Codec          September 2012


   o  ilog(7) = 3

2.  Opus Codec Overview



   The Opus codec scales from 6 kbit/s narrowband mono speech to
   510 kbit/s fullband stereo music, with algorithmic delays ranging
   from 5 ms to 65.2 ms.  At any given time, either the LP layer, the
   MDCT layer, or both, may be active.  It can seamlessly switch between
   all of its various operating modes, giving it a great deal of
   flexibility to adapt to varying content and network conditions
   without renegotiating the current session.  The codec allows input
   and output of various audio bandwidths, defined as follows:

   +----------------------+-----------------+-------------------------+
   | Abbreviation         | Audio Bandwidth | Sample Rate (Effective) |
   +----------------------+-----------------+-------------------------+
   | NB (narrowband)      |           4 kHz |                   8 kHz |
   |                      |                 |                         |
   | MB (medium-band)     |           6 kHz |                  12 kHz |
   |                      |                 |                         |
   | WB (wideband)        |           8 kHz |                  16 kHz |
   |                      |                 |                         |
   | SWB (super-wideband) |          12 kHz |                  24 kHz |
   |                      |                 |                         |
   | FB (fullband)        |      20 kHz (*) |                  48 kHz |
   +----------------------+-----------------+-------------------------+

                                  Table 1

   (*) Although the sampling theorem allows a bandwidth as large as half
   the sampling rate, Opus never codes audio above 20 kHz, as that is
   the generally accepted upper limit of human hearing.

   Opus defines super-wideband (SWB) with an effective sample rate of
   24 kHz, unlike some other audio coding standards that use 32 kHz.
   This was chosen for a number of reasons.  The band layout in the MDCT
   layer naturally allows skipping coefficients for frequencies over
   12 kHz, but does not allow cleanly dropping just those frequencies
   over 16 kHz.  A sample rate of 24 kHz also makes resampling in the
   MDCT layer easier, as 24 evenly divides 48, and when 24 kHz is
   sufficient, it can save computation in other processing, such as
   Acoustic Echo Cancellation (AEC).  Experimental changes to the band
   layout to allow a 16 kHz cutoff (32 kHz effective sample rate) showed
   potential quality degradations at other sample rates, and, at typical
   bitrates, the number of bits saved by using such a cutoff instead of
   coding in fullband (FB) mode is very small.  Therefore, if an
   application wishes to process a signal sampled at 32 kHz, it should
   just use FB.



Valin, et al.                Standards Track                    [Page 8]

RFC 6716                 Interactive Audio Codec          September 2012


   The LP layer is based on the SILK codec [SILK].  It supports NB, MB,
   or WB audio and frame sizes from 10 ms to 60 ms, and requires an
   additional 5 ms look-ahead for noise shaping estimation.  A small
   additional delay (up to 1.5 ms) may be required for sampling rate
   conversion.  Like Vorbis [VORBIS-WEBSITE] and many other modern
   codecs, SILK is inherently designed for variable bitrate (VBR)
   coding, though the encoder can also produce constant bitrate (CBR)
   streams.  The version of SILK used in Opus is substantially modified
   from, and not compatible with, the stand-alone SILK codec previously
   deployed by Skype.  This document does not serve to define that
   format, but those interested in the original SILK codec should see
   [SILK] instead.

   The MDCT layer is based on the Constrained-Energy Lapped Transform
   (CELT) codec [CELT].  It supports NB, WB, SWB, or FB audio and frame
   sizes from 2.5 ms to 20 ms, and requires an additional 2.5 ms look-
   ahead due to the overlapping MDCT windows.  The CELT codec is
   inherently designed for CBR coding, but unlike many CBR codecs, it is
   not limited to a set of predetermined rates.  It internally allocates
   bits to exactly fill any given target budget, and an encoder can
   produce a VBR stream by varying the target on a per-frame basis.  The
   MDCT layer is not used for speech when the audio bandwidth is WB or
   less, as it is not useful there.  On the other hand, non-speech
   signals are not always adequately coded using linear prediction.
   Therefore, the MDCT layer should be used for music signals.

   A "Hybrid" mode allows the use of both layers simultaneously with a
   frame size of 10 or 20 ms and an SWB or FB audio bandwidth.  The LP
   layer codes the low frequencies by resampling the signal down to WB.
   The MDCT layer follows, coding the high frequency portion of the
   signal.  The cutoff between the two lies at 8 kHz, the maximum WB
   audio bandwidth.  In the MDCT layer, all bands below 8 kHz are
   discarded, so there is no coding redundancy between the two layers.

   The sample rate (in contrast to the actual audio bandwidth) can be
   chosen independently on the encoder and decoder side, e.g., a
   fullband signal can be decoded as wideband, or vice versa.  This
   approach ensures a sender and receiver can always interoperate,
   regardless of the capabilities of their actual audio hardware.
   Internally, the LP layer always operates at a sample rate of twice
   the audio bandwidth, up to a maximum of 16 kHz, which it continues to
   use for SWB and FB.  The decoder simply resamples its output to
   support different sample rates.  The MDCT layer always operates
   internally at a sample rate of 48 kHz.  Since all the supported
   sample rates evenly divide this rate, and since the decoder may
   easily zero out the high frequency portion of the spectrum in the
   frequency domain, it can simply decimate the MDCT layer output to
   achieve the other supported sample rates very cheaply.



Valin, et al.                Standards Track                    [Page 9]

RFC 6716                 Interactive Audio Codec          September 2012


   After conversion to the common, desired output sample rate, the
   decoder simply adds the output from the two layers together.  To
   compensate for the different look-ahead required by each layer, the
   CELT encoder input is delayed by an additional 2.7 ms.  This ensures
   that low frequencies and high frequencies arrive at the same time.
   This extra delay may be reduced by an encoder by using less look-
   ahead for noise shaping or using a simpler resampler in the LP layer,
   but this will reduce quality.  However, the base 2.5 ms look-ahead in
   the CELT layer cannot be reduced in the encoder because it is needed
   for the MDCT overlap, whose size is fixed by the decoder.

   Both layers use the same entropy coder, avoiding any waste from
   "padding bits" between them.  The hybrid approach makes it easy to
   support both CBR and VBR coding.  Although the LP layer is VBR, the
   bit allocation of the MDCT layer can produce a final stream that is
   CBR by using all the bits left unused by the LP layer.

2.1.  Control Parameters



   The Opus codec includes a number of control parameters that can be
   changed dynamically during regular operation of the codec, without
   interrupting the audio stream from the encoder to the decoder.  These
   parameters only affect the encoder since any impact they have on the
   bitstream is signaled in-band such that a decoder can decode any Opus
   stream without any out-of-band signaling.  Any Opus implementation
   can add or modify these control parameters without affecting
   interoperability.  The most important encoder control parameters in
   the reference encoder are listed below.

2.1.1.  Bitrate



   Opus supports all bitrates from 6 kbit/s to 510 kbit/s.  All other
   parameters being equal, higher bitrate results in higher quality.
   For a frame size of 20 ms, these are the bitrate "sweet spots" for
   Opus in various configurations:

   o  8-12 kbit/s for NB speech,

   o  16-20 kbit/s for WB speech,

   o  28-40 kbit/s for FB speech,

   o  48-64 kbit/s for FB mono music, and

   o  64-128 kbit/s for FB stereo music.






Valin, et al.                Standards Track                   [Page 10]

RFC 6716                 Interactive Audio Codec          September 2012


2.1.2.  Number of Channels (Mono/Stereo)



   Opus can transmit either mono or stereo frames within a single
   stream.  When decoding a mono frame in a stereo decoder, the left and
   right channels are identical, and when decoding a stereo frame in a
   mono decoder, the mono output is the average of the left and right
   channels.  In some cases, it is desirable to encode a stereo input
   stream in mono (e.g., because the bitrate is too low to encode stereo
   with sufficient quality).  The number of channels encoded can be
   selected in real-time, but by default the reference encoder attempts
   to make the best decision possible given the current bitrate.

2.1.3.  Audio Bandwidth



   The audio bandwidths supported by Opus are listed in Table 1.  Just
   like for the number of channels, any decoder can decode audio that is
   encoded at any bandwidth.  For example, any Opus decoder operating at
   8 kHz can decode an FB Opus frame, and any Opus decoder operating at
   48 kHz can decode an NB frame.  Similarly, the reference encoder can
   take a 48 kHz input signal and encode it as NB.  The higher the audio
   bandwidth, the higher the required bitrate to achieve acceptable
   quality.  The audio bandwidth can be explicitly specified in real-
   time, but, by default, the reference encoder attempts to make the
   best bandwidth decision possible given the current bitrate.

2.1.4.  Frame Duration



   Opus can encode frames of 2.5, 5, 10, 20, 40, or 60 ms.  It can also
   combine multiple frames into packets of up to 120 ms.  For real-time
   applications, sending fewer packets per second reduces the bitrate,
   since it reduces the overhead from IP, UDP, and RTP headers.
   However, it increases latency and sensitivity to packet losses, as
   losing one packet constitutes a loss of a bigger chunk of audio.
   Increasing the frame duration also slightly improves coding
   efficiency, but the gain becomes small for frame sizes above 20 ms.
   For this reason, 20 ms frames are a good choice for most
   applications.

2.1.5.  Complexity



   There are various aspects of the Opus encoding process where trade-
   offs can be made between CPU complexity and quality/bitrate.  In the
   reference encoder, the complexity is selected using an integer from 0
   to 10, where 0 is the lowest complexity and 10 is the highest.
   Examples of computations for which such trade-offs may occur are:

   o  The order of the pitch analysis whitening filter [WHITENING],




Valin, et al.                Standards Track                   [Page 11]

RFC 6716                 Interactive Audio Codec          September 2012


   o  The order of the short-term noise shaping filter,

   o  The number of states in delayed decision quantization of the
      residual signal, and

   o  The use of certain bitstream features such as variable time-
      frequency resolution and the pitch post-filter.

2.1.6.  Packet Loss Resilience



   Audio codecs often exploit inter-frame correlations to reduce the
   bitrate at a cost in error propagation: after losing one packet,
   several packets need to be received before the decoder is able to
   accurately reconstruct the speech signal.  The extent to which Opus
   exploits inter-frame dependencies can be adjusted on the fly to
   choose a trade-off between bitrate and amount of error propagation.

2.1.7.  Forward Error Correction (FEC)



   Another mechanism providing robustness against packet loss is the in-
   band Forward Error Correction (FEC).  Packets that are determined to
   contain perceptually important speech information, such as onsets or
   transients, are encoded again at a lower bitrate and this re-encoded
   information is added to a subsequent packet.

2.1.8.  Constant/Variable Bitrate



   Opus is more efficient when operating with variable bitrate (VBR),
   which is the default.  When low-latency transmission is required over
   a relatively slow connection, then constrained VBR can also be used.
   This uses VBR in a way that simulates a "bit reservoir" and is
   equivalent to what MP3 (MPEG 1, Layer 3) and AAC (Advanced Audio
   Coding) call CBR (i.e., not true CBR due to the bit reservoir).  In
   some (rare) applications, constant bitrate (CBR) is required.  There
   are two main reasons to operate in CBR mode:

   o  When the transport only supports a fixed size for each compressed
      frame, or

   o  When encryption is used for an audio stream that is either highly
      constrained (e.g., yes/no, recorded prompts) or highly sensitive
      [SRTP-VBR].

   Bitrate may still be allowed to vary, even with sensitive data, as
   long as the variation is not driven by the input signal (for example,
   to match changing network conditions).  To achieve this, an
   application should still run Opus in CBR mode, but change the target
   rate before each packet.



Valin, et al.                Standards Track                   [Page 12]

RFC 6716                 Interactive Audio Codec          September 2012


2.1.9.  Discontinuous Transmission (DTX)



   Discontinuous Transmission (DTX) reduces the bitrate during silence
   or background noise.  When DTX is enabled, only one frame is encoded
   every 400 milliseconds.

3.  Internal Framing



   The Opus encoder produces "packets", which are each a contiguous set
   of bytes meant to be transmitted as a single unit.  The packets
   described here do not include such things as IP, UDP, or RTP headers,
   which are normally found in a transport-layer packet.  A single
   packet may contain multiple audio frames, so long as they share a
   common set of parameters, including the operating mode, audio
   bandwidth, frame size, and channel count (mono vs. stereo).  This
   section describes the possible combinations of these parameters and
   the internal framing used to pack multiple frames into a single
   packet.  This framing is not self-delimiting.  Instead, it assumes
   that a lower layer (such as UDP or RTP [RFC3550] or Ogg [RFC3533] or
   Matroska [MATROSKA-WEBSITE]) will communicate the length, in bytes,
   of the packet, and it uses this information to reduce the framing
   overhead in the packet itself.  A decoder implementation MUST support
   the framing described in this section.  An alternative, self-
   delimiting variant of the framing is described in Appendix B.
   Support for that variant is OPTIONAL.

   All bit diagrams in this document number the bits so that bit 0 is
   the most significant bit of the first byte, and bit 7 is the least
   significant.  Bit 8 is thus the most significant bit of the second
   byte, etc.  Well-formed Opus packets obey certain requirements,
   marked [R1] through [R7] below.  These are summarized in Section 3.4
   along with appropriate means of handling malformed packets.

3.1.  The TOC Byte



   A well-formed Opus packet MUST contain at least one byte [R1].  This
   byte forms a table-of-contents (TOC) header that signals which of the
   various modes and configurations a given packet uses.  It is composed
   of a configuration number, "config", a stereo flag, "s", and a frame
   count code, "c", arranged as illustrated in Figure 1.  A description
   of each of these fields follows.










Valin, et al.                Standards Track                   [Page 13]

RFC 6716                 Interactive Audio Codec          September 2012


                              0
                              0 1 2 3 4 5 6 7
                             +-+-+-+-+-+-+-+-+
                             | config  |s| c |
                             +-+-+-+-+-+-+-+-+

                          Figure 1: The TOC Byte

   The top five bits of the TOC byte, labeled "config", encode one of 32
   possible configurations of operating mode, audio bandwidth, and frame
   size.  As described, the LP (SILK) layer and MDCT (CELT) layer can be
   combined in three possible operating modes:

   1.  A SILK-only mode for use in low bitrate connections with an audio
       bandwidth of WB or less,

   2.  A Hybrid (SILK+CELT) mode for SWB or FB speech at medium
       bitrates, and

   3.  A CELT-only mode for very low delay speech transmission as well
       as music transmission (NB to FB).

   The 32 possible configurations each identify which one of these
   operating modes the packet uses, as well as the audio bandwidth and
   the frame size.  Table 2 lists the parameters for each configuration.


























Valin, et al.                Standards Track                   [Page 14]

RFC 6716                 Interactive Audio Codec          September 2012


   +-----------------------+-----------+-----------+-------------------+
   | Configuration         | Mode      | Bandwidth | Frame Sizes       |
   | Number(s)             |           |           |                   |
   +-----------------------+-----------+-----------+-------------------+
   | 0...3                 | SILK-only | NB        | 10, 20, 40, 60 ms |
   |                       |           |           |                   |
   | 4...7                 | SILK-only | MB        | 10, 20, 40, 60 ms |
   |                       |           |           |                   |
   | 8...11                | SILK-only | WB        | 10, 20, 40, 60 ms |
   |                       |           |           |                   |
   | 12...13               | Hybrid    | SWB       | 10, 20 ms         |
   |                       |           |           |                   |
   | 14...15               | Hybrid    | FB        | 10, 20 ms         |
   |                       |           |           |                   |
   | 16...19               | CELT-only | NB        | 2.5, 5, 10, 20 ms |
   |                       |           |           |                   |
   | 20...23               | CELT-only | WB        | 2.5, 5, 10, 20 ms |
   |                       |           |           |                   |
   | 24...27               | CELT-only | SWB       | 2.5, 5, 10, 20 ms |
   |                       |           |           |                   |
   | 28...31               | CELT-only | FB        | 2.5, 5, 10, 20 ms |
   +-----------------------+-----------+-----------+-------------------+

                Table 2: TOC Byte Configuration Parameters

   The configuration numbers in each range (e.g., 0...3 for NB SILK-
   only) correspond to the various choices of frame size, in the same
   order.  For example, configuration 0 has a 10 ms frame size and
   configuration 3 has a 60 ms frame size.

   One additional bit, labeled "s", signals mono vs. stereo, with 0
   indicating mono and 1 indicating stereo.

   The remaining two bits of the TOC byte, labeled "c", code the number
   of frames per packet (codes 0 to 3) as follows:

   o  0: 1 frame in the packet

   o  1: 2 frames in the packet, each with equal compressed size

   o  2: 2 frames in the packet, with different compressed sizes

   o  3: an arbitrary number of frames in the packet

   This document refers to a packet as a code 0 packet, code 1 packet,
   etc., based on the value of "c".





Valin, et al.                Standards Track                   [Page 15]

RFC 6716                 Interactive Audio Codec          September 2012


3.2.  Frame Packing



   This section describes how frames are packed according to each
   possible value of "c" in the TOC byte.

3.2.1.  Frame Length Coding



   When a packet contains multiple VBR frames (i.e., code 2 or 3), the
   compressed length of one or more of these frames is indicated with a
   one- or two-byte sequence, with the meaning of the first byte as
   follows:

   o  0: No frame (Discontinuous Transmission (DTX) or lost packet)

   o  1...251: Length of the frame in bytes

   o  252...255: A second byte is needed.  The total length is
      (second_byte*4)+first_byte

   The special length 0 indicates that no frame is available, either
   because it was dropped during transmission by some intermediary or
   because the encoder chose not to transmit it.  Any Opus frame in any
   mode MAY have a length of 0.

   The maximum representable length is 255*4+255=1275 bytes.  For 20 ms
   frames, this represents a bitrate of 510 kbit/s, which is
   approximately the highest useful rate for lossily compressed fullband
   stereo music.  Beyond this point, lossless codecs are more
   appropriate.  It is also roughly the maximum useful rate of the MDCT
   layer as, shortly thereafter, quality no longer improves with
   additional bits due to limitations on the codebook sizes.

   No length is transmitted for the last frame in a VBR packet, or for
   any of the frames in a CBR packet, as it can be inferred from the
   total size of the packet and the size of all other data in the
   packet.  However, the length of any individual frame MUST NOT exceed
   1275 bytes [R2] to allow for repacketization by gateways, conference
   bridges, or other software.

3.2.2.  Code 0: One Frame in the Packet



   For code 0 packets, the TOC byte is immediately followed by N-1 bytes
   of compressed data for a single frame (where N is the size of the
   packet), as illustrated in Figure 2.







Valin, et al.                Standards Track                   [Page 16]

RFC 6716                 Interactive Audio Codec          September 2012


      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | config  |s|0|0|                                               |
     +-+-+-+-+-+-+-+-+                                               |
     |                    Compressed frame 1 (N-1 bytes)...          :
     :                                                               |
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                         Figure 2: A Code 0 Packet

3.2.3.  Code 1: Two Frames in the Packet, Each with Equal Compressed
        Size



   For code 1 packets, the TOC byte is immediately followed by the
   (N-1)/2 bytes of compressed data for the first frame, followed by
   (N-1)/2 bytes of compressed data for the second frame, as illustrated
   in Figure 3.  The number of payload bytes available for compressed
   data, N-1, MUST be even for all code 1 packets [R3].

      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | config  |s|0|1|                                               |
     +-+-+-+-+-+-+-+-+                                               :
     |             Compressed frame 1 ((N-1)/2 bytes)...             |
     :                               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                               |                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               :
     |             Compressed frame 2 ((N-1)/2 bytes)...             |
     :                                               +-+-+-+-+-+-+-+-+
     |                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                         Figure 3: A Code 1 Packet

3.2.4.  Code 2: Two Frames in the Packet, with Different Compressed
        Sizes



   For code 2 packets, the TOC byte is followed by a one- or two-byte
   sequence indicating the length of the first frame (marked N1 in
   Figure 4), followed by N1 bytes of compressed data for the first
   frame.  The remaining N-N1-2 or N-N1-3 bytes are the compressed data
   for the second frame.  This is illustrated in Figure 4.  A code 2
   packet MUST contain enough bytes to represent a valid length.  For
   example, a 1-byte code 2 packet is always invalid, and a 2-byte code
   2 packet whose second byte is in the range 252...255 is also invalid.



Valin, et al.                Standards Track                   [Page 17]

RFC 6716                 Interactive Audio Codec          September 2012


   The length of the first frame, N1, MUST also be no larger than the
   size of the payload remaining after decoding that length for all code
   2 packets [R4].  This makes, for example, a 2-byte code 2 packet with
   a second byte in the range 1...251 invalid as well (the only valid
   2-byte code 2 packet is one where the length of both frames is zero).

      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | config  |s|1|0| N1 (1-2 bytes):                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               :
     |               Compressed frame 1 (N1 bytes)...                |
     :                               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                               |                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               |
     |                     Compressed frame 2...                     :
     :                                                               |
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                         Figure 4: A Code 2 Packet

3.2.5.  Code 3: A Signaled Number of Frames in the Packet



   Code 3 packets signal the number of frames, as well as additional
   padding, called "Opus padding" to indicate that this padding is added
   at the Opus layer rather than at the transport layer.  Code 3 packets
   MUST have at least 2 bytes [R6,R7].  The TOC byte is followed by a
   byte encoding the number of frames in the packet in bits 2 to 7
   (marked "M" in Figure 5), with bit 1 indicating whether or not Opus
   padding is inserted (marked "p" in Figure 5), and bit 0 indicating
   VBR (marked "v" in Figure 5).  M MUST NOT be zero, and the audio
   duration contained within a packet MUST NOT exceed 120 ms [R5].  This
   limits the maximum frame count for any frame size to 48 (for 2.5 ms
   frames), with lower limits for longer frame sizes.  Figure 5
   illustrates the layout of the frame count byte.

                              0
                              0 1 2 3 4 5 6 7
                             +-+-+-+-+-+-+-+-+
                             |v|p|     M     |
                             +-+-+-+-+-+-+-+-+

                      Figure 5: The frame count byte

   When Opus padding is used, the number of bytes of padding is encoded
   in the bytes following the frame count byte.  Values from 0...254
   indicate that 0...254 bytes of padding are included, in addition to



Valin, et al.                Standards Track                   [Page 18]

RFC 6716                 Interactive Audio Codec          September 2012


   the byte(s) used to indicate the size of the padding.  If the value
   is 255, then the size of the additional padding is 254 bytes, plus
   the padding value encoded in the next byte.  There MUST be at least
   one more byte in the packet in this case [R6,R7].  The additional
   padding bytes appear at the end of the packet and MUST be set to zero
   by the encoder to avoid creating a covert channel.  The decoder MUST
   accept any value for the padding bytes, however.

   Although this encoding provides multiple ways to indicate a given
   number of padding bytes, each uses a different number of bytes to
   indicate the padding size and thus will increase the total packet
   size by a different amount.  For example, to add 255 bytes to a
   packet, set the padding bit, p, to 1, insert a single byte after the
   frame count byte with a value of 254, and append 254 padding bytes
   with the value zero to the end of the packet.  To add 256 bytes to a
   packet, set the padding bit to 1, insert two bytes after the frame
   count byte with the values 255 and 0, respectively, and append 254
   padding bytes with the value zero to the end of the packet.  By using
   the value 255 multiple times, it is possible to create a packet of
   any specific, desired size.  Let P be the number of header bytes used
   to indicate the padding size plus the number of padding bytes
   themselves (i.e., P is the total number of bytes added to the
   packet).  Then, P MUST be no more than N-2 [R6,R7].

   In the CBR case, let R=N-2-P be the number of bytes remaining in the
   packet after subtracting the (optional) padding.  Then, the
   compressed length of each frame in bytes is equal to R/M.  The value
   R MUST be a non-negative integer multiple of M [R6].  The compressed
   data for all M frames follows, each of size R/M bytes, as illustrated
   in Figure 6.





















Valin, et al.                Standards Track                   [Page 19]

RFC 6716                 Interactive Audio Codec          September 2012


      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | config  |s|1|1|0|p|     M     |  Padding length (Optional)    :
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     :               Compressed frame 1 (R/M bytes)...               :
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     :               Compressed frame 2 (R/M bytes)...               :
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     :                              ...                              :
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     :               Compressed frame M (R/M bytes)...               :
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     :                  Opus Padding (Optional)...                   |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                       Figure 6: A CBR Code 3 Packet

   In the VBR case, the (optional) padding length is followed by M-1
   frame lengths (indicated by "N1" to "N[M-1]" in Figure 7), each
   encoded in a one- or two-byte sequence as described above.  The
   packet MUST contain enough data for the M-1 lengths after removing
   the (optional) padding, and the sum of these lengths MUST be no
   larger than the number of bytes remaining in the packet after
   decoding them [R7].  The compressed data for all M frames follows,
   each frame consisting of the indicated number of bytes, with the
   final frame consuming any remaining bytes before the final padding,
   as illustrated in Figure 6.  The number of header bytes (TOC byte,
   frame count byte, padding length bytes, and frame length bytes), plus
   the signaled length of the first M-1 frames themselves, plus the
   signaled length of the padding MUST be no larger than N, the total
   size of the packet.











Valin, et al.                Standards Track                   [Page 20]

RFC 6716                 Interactive Audio Codec          September 2012


      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | config  |s|1|1|1|p|     M     | Padding length (Optional)     :
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     : N1 (1-2 bytes): N2 (1-2 bytes):     ...       :     N[M-1]    |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     :               Compressed frame 1 (N1 bytes)...                :
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     :               Compressed frame 2 (N2 bytes)...                :
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     :                              ...                              :
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     :                     Compressed frame M...                     :
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     :                  Opus Padding (Optional)...                   |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                       Figure 7: A VBR Code 3 Packet

3.3.  Examples



   Simplest case, one NB mono 20 ms SILK frame:

    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |    1    |0|0|0|               compressed data...              :
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                                 Figure 8












Valin, et al.                Standards Track                   [Page 21]

RFC 6716                 Interactive Audio Codec          September 2012


   Two FB mono 5 ms CELT frames of the same compressed size:

    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |   29    |0|0|1|               compressed data...              :
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                                 Figure 9

   Two FB mono 20 ms Hybrid frames of different compressed size:

    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |   15    |0|1|1|1|0|     2     |      N1       |               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+               |
   |                       compressed data...                      :
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                                 Figure 10

   Four FB stereo 20 ms CELT frames of the same compressed size:

    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |   31    |1|1|1|0|0|     4     |      compressed data...       :
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                                 Figure 11

3.4.  Receiving Malformed Packets



   A receiver MUST NOT process packets that violate any of the rules
   above as normal Opus packets.  They are reserved for future
   applications, such as in-band headers (containing metadata, etc.).
   Packets that violate these constraints may cause implementations of
   _this_ specification to treat them as malformed and discard them.

   These constraints are summarized here for reference:

   [R1]  Packets are at least one byte.

   [R2]  No implicit frame length is larger than 1275 bytes.

   [R3]  Code 1 packets have an odd total length, N, so that (N-1)/2 is
         an integer.



Valin, et al.                Standards Track                   [Page 22]

RFC 6716                 Interactive Audio Codec          September 2012


   [R4]  Code 2 packets have enough bytes after the TOC for a valid
         frame length, and that length is no larger than the number of
         bytes remaining in the packet.

   [R5]  Code 3 packets contain at least one frame, but no more than
         120 ms of audio total.

   [R6]  The length of a CBR code 3 packet, N, is at least two bytes,
         the number of bytes added to indicate the padding size plus the
         trailing padding bytes themselves, P, is no more than N-2, and
         the frame count, M, satisfies the constraint that (N-2-P) is a
         non-negative integer multiple of M.

   [R7]  VBR code 3 packets are large enough to contain all the header
         bytes (TOC byte, frame count byte, any padding length bytes,
         and any frame length bytes), plus the length of the first M-1
         frames, plus any trailing padding bytes.

4.  Opus Decoder



   The Opus decoder consists of two main blocks: the SILK decoder and
   the CELT decoder.  At any given time, one or both of the SILK and
   CELT decoders may be active.  The output of the Opus decode is the
   sum of the outputs from the SILK and CELT decoders with proper sample
   rate conversion and delay compensation on the SILK side, and optional
   decimation (when decoding to sample rates less than 48 kHz) on the
   CELT side, as illustrated in the block diagram below.


                            +---------+    +------------+
                            |  SILK   |    |   Sample   |
                         +->| Decoder |--->|    Rate    |----+
   Bit-    +---------+   |  |         |    | Conversion |    v
   stream  |  Range  |---+  +---------+    +------------+  /---\  Audio
   ------->| Decoder |                                     | + |------>
           |         |---+  +---------+    +------------+  \---/
           +---------+   |  |  CELT   |    | Decimation |    ^
                         +->| Decoder |--->| (Optional) |----+
                            |         |    |            |
                            +---------+    +------------+


4.1.  Range Decoder



   Opus uses an entropy coder based on range coding [RANGE-CODING]
   [MARTIN79], which is itself a rediscovery of the FIFO arithmetic code
   introduced by [CODING-THESIS].  It is very similar to arithmetic
   encoding, except that encoding is done with digits in any base



Valin, et al.                Standards Track                   [Page 23]

RFC 6716                 Interactive Audio Codec          September 2012


   instead of with bits, so it is faster when using larger bases (i.e.,
   a byte).  All of the calculations in the range coder must use bit-
   exact integer arithmetic.

   Symbols may also be coded as "raw bits" packed directly into the
   bitstream, bypassing the range coder.  These are packed backwards
   starting at the end of the frame, as illustrated in Figure 12.  This
   reduces complexity and makes the stream more resilient to bit errors,
   as corruption in the raw bits will not desynchronize the decoding
   process, unlike corruption in the input to the range decoder.  Raw
   bits are only used in the CELT layer.

      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | Range coder data (packed MSB to LSB) ->                       :
     +                                                               +
     :                                                               :
     +     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     :     | <- Boundary occurs at an arbitrary bit position         :
     +-+-+-+                                                         +
     :                          <- Raw bits data (packed LSB to MSB) |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

     Legend:

     LSB = Least Significant Bit
     MSB = Most Significant Bit

          Figure 12: Illustrative Example of Packing Range Coder
                             and Raw Bits Data

   Each symbol coded by the range coder is drawn from a finite alphabet
   and coded in a separate "context", which describes the size of the
   alphabet and the relative frequency of each symbol in that alphabet.

   Suppose there is a context with n symbols, identified with an index
   that ranges from 0 to n-1.  The parameters needed to encode or decode
   symbol k in this context are represented by a three-tuple
   (fl[k], fh[k], ft), all 16-bit unsigned integers, with
   0 <= fl[k] < fh[k] <= ft <= 65535.  The values of this tuple are
   derived from the probability model for the symbol, represented by
   traditional "frequency counts".  Because Opus uses static contexts,
   those are not updated as symbols are decoded.  Let f[i] be the
   frequency of symbol i.  Then, the three-tuple corresponding to symbol
   k is given by the following:





Valin, et al.                Standards Track                   [Page 24]

RFC 6716                 Interactive Audio Codec          September 2012


                   k-1                                   n-1
                   __                                    __
           fl[k] = \  f[i],  fh[k] = fl[k] + f[k],  ft = \  f[i]
                   /_                                    /_
                   i=0                                   i=0

   The range decoder extracts the symbols and integers encoded using the
   range encoder in Section 5.1.  The range decoder maintains an
   internal state vector composed of the two-tuple (val, rng), where val
   represents the difference between the high end of the current range
   and the actual coded value, minus one, and rng represents the size of
   the current range.  Both val and rng are 32-bit unsigned integer
   values.

4.1.1.  Range Decoder Initialization



   Let b0 be an 8-bit unsigned integer containing first input byte (or
   containing zero if there are no bytes in this Opus frame).  The
   decoder initializes rng to 128 and initializes val to (127 -
    (b0>>1)), where (b0>>1) is the top 7 bits of the first input byte.
   It saves the remaining bit, (b0&1), for use in the renormalization
   procedure described in Section 4.1.2.1, which the decoder invokes
   immediately after initialization to read additional bits and
   establish the invariant that rng > 2**23.

4.1.2.  Decoding Symbols



   Decoding a symbol is a two-step process.  The first step determines a
   16-bit unsigned value fs, which lies within the range of some symbol
   in the current context.  The second step updates the range decoder
   state with the three-tuple (fl[k], fh[k], ft) corresponding to that
   symbol.

   The first step is implemented by ec_decode() (entdec.c), which
   computes

                                      val
                       fs = ft - min(------ + 1, ft)
                                     rng/ft

   The divisions here are integer division.

   The decoder then identifies the symbol in the current context
   corresponding to fs; i.e., the value of k whose three-tuple
   (fl[k], fh[k], ft) satisfies fl[k] <= fs < fh[k].  It uses this tuple
   to update val according to





Valin, et al.                Standards Track                   [Page 25]

RFC 6716                 Interactive Audio Codec          September 2012


                                   rng
                       val = val - --- * (ft - fh[k])
                                   ft

   If fl[k] is greater than zero, then the decoder updates rng using

                              rng
                        rng = --- * (fh[k] - fl[k])
                              ft

   Otherwise, it updates rng using

                                   rng
                       rng = rng - --- * (ft - fh[k])
                                   ft

   Using a special case for the first symbol (rather than the last
   symbol, as is commonly done in other arithmetic coders) ensures that
   all the truncation error from the finite precision arithmetic
   accumulates in symbol 0.  This makes the cost of coding a 0 slightly
   smaller, on average, than its estimated probability indicates and
   makes the cost of coding any other symbol slightly larger.  When
   contexts are designed so that 0 is the most probable symbol, which is
   often the case, this strategy minimizes the inefficiency introduced
   by the finite precision.  It also makes some of the special-case
   decoding routines in Section 4.1.3 particularly simple.

   After the updates, implemented by ec_dec_update() (entdec.c), the
   decoder normalizes the range using the procedure in the next section,
   and returns the index k.

4.1.2.1.  Renormalization



   To normalize the range, the decoder repeats the following process,
   implemented by ec_dec_normalize() (entdec.c), until rng > 2**23.  If
   rng is already greater than 2**23, the entire process is skipped.
   First, it sets rng to (rng<<8).  Then, it reads the next byte of the
   Opus frame and forms an 8-bit value sym, using the leftover bit
   buffered from the previous byte as the high bit and the top 7 bits of
   the byte just read as the other 7 bits of sym.  The remaining bit in
   the byte just read is buffered for use in the next iteration.  If no
   more input bytes remain, it uses zero bits instead.  See
   Section 4.1.1 for the initialization used to process the first byte.
   Then, it sets

                 val = ((val<<8) + (255-sym)) & 0x7FFFFFFF





Valin, et al.                Standards Track                   [Page 26]

RFC 6716                 Interactive Audio Codec          September 2012


   It is normal and expected that the range decoder will read several
   bytes into the data of the raw bits (if any) at the end of the frame
   by the time the frame is completely decoded, as illustrated in
   Figure 13.  This same data MUST also be returned as raw bits when
   requested.  The encoder is expected to terminate the stream in such a
   way that the range decoder will decode the intended values regardless
   of the data contained in the raw bits.  Section 5.1.5 describes a
   procedure for doing this.  If the range decoder consumes all of the
   bytes belonging to the current frame, it MUST continue to use zero
   when any further input bytes are required, even if there is
   additional data in the current packet from padding or other frames.

      n              n+1             n+2             n+3
      0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     :     | <----------- Overlap region ------------> |             :
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
           ^                                           ^
           |   End of data buffered by the range coder |
     ...-----------------------------------------------+
           |
           | End of data consumed by raw bits
           +-------------------------------------------------------...

          Figure 13: Illustrative Example of Raw Bits Overlapping
                             Range Coder Data

4.1.3.  Alternate Decoding Methods



   The reference implementation uses three additional decoding methods
   that are exactly equivalent to the above but make assumptions and
   simplifications that allow for a more efficient implementation.

4.1.3.1.  ec_decode_bin()



   The first is ec_decode_bin() (entdec.c), defined using the parameter
   ftb instead of ft.  It is mathematically equivalent to calling
   ec_decode() with ft = (1<<ftb), but it avoids one of the divisions.

4.1.3.2.  ec_dec_bit_logp()



   The next is ec_dec_bit_logp() (entdec.c), which decodes a single
   binary symbol, replacing both the ec_decode() and ec_dec_update()
   steps.  The context is described by a single parameter, logp, which
   is the absolute value of the base-2 logarithm of the probability of a
   "1".  It is mathematically equivalent to calling ec_decode() with
   ft = (1<<logp), followed by ec_dec_update() with the 3-tuple
   (fl[k] = 0, fh[k] = (1<<logp) - 1, ft = (1<<logp)) if the returned



Valin, et al.                Standards Track                   [Page 27]

RFC 6716                 Interactive Audio Codec          September 2012


   value of fs is less than (1<<logp) - 1 (a "0" was decoded), and with
   (fl[k] = (1<<logp) - 1, fh[k] = ft = (1<<logp)) otherwise (a "1" was
   decoded).  The implementation requires no multiplications or
   divisions.

4.1.3.3.  ec_dec_icdf()



   The last is ec_dec_icdf() (entdec.c), which decodes a single symbol
   with a table-based context of up to 8 bits, also replacing both the
   ec_decode() and ec_dec_update() steps, as well as the search for the
   decoded symbol in between.  The context is described by two
   parameters, an icdf ("inverse" cumulative distribution function)
   table and ftb.  As with ec_decode_bin(), (1<<ftb) is equivalent to
   ft. idcf[k], on the other hand, stores (1<<ftb)-fh[k], which is equal
   to (1<<ftb) - fl[k+1]. fl[0] is assumed to be 0, and the table is
   terminated by a value of 0 (where fh[k] == ft).

   The function is mathematically equivalent to calling ec_decode() with
   ft = (1<<ftb), using the returned value fs to search the table for
   the first entry where fs < (1<<ftb)-icdf[k], and calling
   ec_dec_update() with fl[k] = (1<<ftb) - icdf[k-1] (or 0 if k == 0),
   fh[k] = (1<<ftb) - idcf[k], and ft = (1<<ftb).  Combining the search
   with the update allows the division to be replaced by a series of
   multiplications (which are usually much cheaper), and using an
   inverse CDF allows the use of an ftb as large as 8 in an 8-bit table
   without any special cases.  This is the primary interface with the
   range decoder in the SILK layer, though it is used in a few places in
   the CELT layer as well.

   Although icdf[k] is more convenient for the code, the frequency
   counts, f[k], are a more natural representation of the probability
   distribution function (PDF) for a given symbol.  Therefore, this
   document lists the latter, not the former, when describing the
   context in which a symbol is coded as a list, e.g., {4, 4, 4, 4}/16
   for a uniform context with four possible values and ft = 16.  The
   value of ft after the slash is always the sum of the entries in the
   PDF, but is included for convenience.  Contexts with identical
   probabilities, f[k]/ft, but different values of ft (or equivalently,
   ftb) are not the same, and cannot, in general, be used in place of
   one another.  An icdf table is also not capable of representing a PDF
   where the first symbol has 0 probability.  In such contexts,
   ec_dec_icdf() can decode the symbol by using a table that drops the
   entries for any initial zero-probability values and by adding the
   constant offset of the first value with a non-zero probability to its
   return value.






Valin, et al.                Standards Track                   [Page 28]

RFC 6716                 Interactive Audio Codec          September 2012


4.1.4.  Decoding Raw Bits



   The raw bits used by the CELT layer are packed at the end of the
   frame, with the least significant bit of the first value packed in
   the least significant bit of the last byte, filling up to the most
   significant bit in the last byte, continuing on to the least
   significant bit of the penultimate byte, and so on.  The reference
   implementation reads them using ec_dec_bits() (entdec.c).  Because
   the range decoder must read several bytes ahead in the stream, as
   described in Section 4.1.2.1, the input consumed by the raw bits may
   overlap with the input consumed by the range coder, and a decoder
   MUST allow this.  The format should render it impossible to attempt
   to read more raw bits than there are actual bits in the frame, though
   a decoder may wish to check for this and report an error.

4.1.5.  Decoding Uniformly Distributed Integers



   The function ec_dec_uint() (entdec.c) decodes one of ft equiprobable
   values in the range 0 to (ft - 1), inclusive, each with a frequency
   of 1, where ft may be as large as (2**32 - 1).  Because ec_decode()
   is limited to a total frequency of (2**16 - 1), it splits up the
   value into a range coded symbol representing up to 8 of the high
   bits, and, if necessary, raw bits representing the remainder of the
   value.  The limit of 8 bits in the range coded symbol is a trade-off
   between implementation complexity, modeling error (since the symbols
   no longer truly have equal coding cost), and rounding error
   introduced by the range coder itself (which gets larger as more bits
   are included).  Using raw bits reduces the maximum number of
   divisions required in the worst case, but means that it may be
   possible to decode a value outside the range 0 to (ft - 1),
   inclusive.

   ec_dec_uint() takes a single, positive parameter, ft, which is not
   necessarily a power of two, and returns an integer, t, whose value
   lies between 0 and (ft - 1), inclusive.  Let ftb = ilog(ft - 1),
   i.e., the number of bits required to store (ft - 1) in two's
   complement notation.  If ftb is 8 or less, then t is decoded with
   t = ec_decode(ft), and the range coder state is updated using the
   three-tuple (t, t + 1, ft).

   If ftb is greater than 8, then the top 8 bits of t are decoded using

                 t = ec_decode(((ft - 1) >> (ftb - 8)) + 1)

   the decoder state is updated using the three-tuple (t, t + 1, ((ft -
    1) >> (ftb - 8)) + 1), and the remaining bits are decoded as raw
   bits, setting




Valin, et al.                Standards Track                   [Page 29]

RFC 6716                 Interactive Audio Codec          September 2012


                t = (t << (ftb - 8)) | ec_dec_bits(ftb - 8)

   If, at this point, t >= ft, then the current frame is corrupt.  In
   that case, the decoder should assume there has been an error in the
   coding, decoding, or transmission and SHOULD take measures to conceal
   the error (e.g., saturate to ft-1 or use the Packet Loss Concealment
   (PLC)) and/or report to the application that the error has occurred.

4.1.6.  Current Bit Usage



   The bit allocation routines in the CELT decoder need a conservative
   upper bound on the number of bits that have been used from the
   current frame thus far, including both range coder bits and raw bits.
   This drives allocation decisions that must match those made in the
   encoder.  The upper bound is computed in the reference implementation
   to whole-bit precision by the function ec_tell() (entcode.h) and to
   fractional 1/8th bit precision by the function ec_tell_frac()
   (entcode.c).  Like all operations in the range coder, it must be
   implemented in a bit-exact manner, and it must produce exactly the
   same value returned by the same functions in the encoder after
   encoding the same symbols.

   ec_tell() is guaranteed to return ceil(ec_tell_frac()/8.0).  In
   various places, the codec will check to ensure there is enough room
   to contain a symbol before attempting to decode it.  In practice,
   although the number of bits used so far is an upper bound, decoding a
   symbol whose probability model suggests it has a worst-case cost of p
   1/8th bits may actually advance the return value of ec_tell_frac() by
   p-1, p, or p+1 1/8th bits, due to approximation error in that upper
   bound, truncation error in the range coder, and for large values of
   ft, modeling error in ec_dec_uint().

   However, this error is bounded, and periodic calls to ec_tell() or
   ec_tell_frac() at precisely defined points in the decoding process
   prevent it from accumulating.  For a range coder symbol that requires
   a whole number of bits (i.e., for which ft/(fh[k] - fl[k]) is a power
   of two), where there are at least p 1/8th bits available, decoding
   the symbol will never cause ec_tell() or ec_tell_frac() to exceed the
   size of the frame ("bust the budget").  In this case, the return
   value of ec_tell_frac() will only advance by more than p 1/8th bits
   if there were an additional, fractional number of bits remaining, and
   it will never advance beyond the next whole-bit boundary, which is
   safe, since frames always contain a whole number of bits.  However,
   when p is not a whole number of bits, an extra 1/8th bit is required
   to ensure that decoding the symbol will not bust the budget.






Valin, et al.                Standards Track                   [Page 30]

RFC 6716                 Interactive Audio Codec          September 2012


   The reference implementation keeps track of the total number of whole
   bits that have been processed by the decoder so far in the variable
   nbits_total, including the (possibly fractional) number of bits that
   are currently buffered, but not consumed, inside the range coder.
   nbits_total is initialized to 9 just before the initial range
   renormalization process completes (or equivalently, it can be
   initialized to 33 after the first renormalization).  The extra two
   bits over the actual amount buffered by the range coder guarantees
   that it is an upper bound and that there is enough room for the
   encoder to terminate the stream.  Each iteration through the range
   coder's renormalization loop increases nbits_total by 8.  Reading raw
   bits increases nbits_total by the number of raw bits read.

4.1.6.1.  ec_tell()



   The whole number of bits buffered in rng may be estimated via
   lg = ilog(rng). ec_tell() then becomes a simple matter of removing
   these bits from the total.  It returns (nbits_total - lg).

   In a newly initialized decoder, before any symbols have been read,
   this reports that 1 bit has been used.  This is the bit reserved for
   termination of the encoder.

4.1.6.2.  ec_tell_frac()



   ec_tell_frac() estimates the number of bits buffered in rng to
   fractional precision.  Since rng must be greater than 2**23 after
   renormalization, lg must be at least 24.  Let

                           r_Q15 = rng >> (lg-16)

   so that 32768 <= r_Q15 < 65536, an unsigned Q15 value representing
   the fractional part of rng.  Then, the following procedure can be
   used to add one bit of precision to lg.  First, update

                        r_Q15 = (r_Q15*r_Q15) >> 15

   Then, add the 16th bit of r_Q15 to lg via

                         lg = 2*lg + (r_Q15 >> 16)

   Finally, if this bit was a 1, reduce r_Q15 by a factor of two via

                             r_Q15 = r_Q15 >> 1

   so that it once again lies in the range 32768 <= r_Q15 < 65536.  This
   procedure is repeated three times to extend lg to 1/8th bit
   precision. ec_tell_frac() then returns (nbits_total*8 - lg).



Valin, et al.                Standards Track                   [Page 31]

RFC 6716                 Interactive Audio Codec          September 2012


4.2.  SILK Decoder



   The decoder's LP layer uses a modified version of the SILK codec
   (herein simply called "SILK"), which runs a decoded excitation signal
   through adaptive long-term and short-term prediction synthesis
   filters.  It runs at NB, MB, and WB sample rates internally.  When
   used in a SWB or FB Hybrid frame, the LP layer itself still only runs
   in WB.

4.2.1.  SILK Decoder Modules



   An overview of the decoder is given in Figure 14.

        +---------+    +------------+
     -->| Range   |--->| Decode     |---------------------------+
      1 | Decoder | 2  | Parameters |----------+       5        |
        +---------+    +------------+     4    |                |
                            3 |                |                |
                             \/               \/               \/
                       +------------+   +------------+   +------------+
                       | Generate   |-->| LTP        |-->| LPC        |
                       | Excitation |   | Synthesis  |   | Synthesis  |
                       +------------+   +------------+   +------------+
                                               ^                |
                                               |                |
                           +-------------------+----------------+
                           |                                      6
                           |   +------------+   +-------------+
                           +-->| Stereo     |-->| Sample Rate |-->
                               | Unmixing   | 7 | Conversion  | 8
                               +------------+   +-------------+

     1: Range encoded bitstream
     2: Coded parameters
     3: Pulses, LSBs, and signs
     4: Pitch lags, Long-Term Prediction (LTP) coefficients
     5: Linear Predictive Coding (LPC) coefficients and gains
     6: Decoded signal (mono or mid-side stereo)
     7: Unmixed signal (mono or left-right stereo)
     8: Resampled signal


                          Figure 14: SILK Decoder








Valin, et al.                Standards Track                   [Page 32]

RFC 6716                 Interactive Audio Codec          September 2012


   The decoder feeds the bitstream (1) to the range decoder from
   Section 4.1 and then decodes the parameters in it (2) using the
   procedures detailed in Sections 4.2.3 through 4.2.7.8.5.  These
   parameters (3, 4, 5) are used to generate an excitation signal (see
   4.2.7.8.6">Section 4.2.7.8.6), which is fed to an optional Long-Term Prediction
   (LTP) filter (voiced frames only, see 4.2.7.9.1">Section 4.2.7.9.1) and then a
   short-term prediction filter (see 4.2.7.9.2">Section 4.2.7.9.2), producing the
   decoded signal (6).  For stereo streams, the mid-side representation
   is converted to separate left and right channels (7).  The result is
   finally resampled to the desired output sample rate (e.g., 48 kHz) so
   that the resampled signal (8) can be mixed with the CELT layer.

4.2.2.  LP Layer Organization



   Internally, the LP layer of a single Opus frame is composed of either
   a single 10 ms regular SILK frame or between one and three 20 ms
   regular SILK frames.  A stereo Opus frame may double the number of
   regular SILK frames (up to a total of six), since it includes
   separate frames for a mid channel and, optionally, a side channel.
   Optional Low Bit-Rate Redundancy (LBRR) frames, which are reduced-
   bitrate encodings of previous SILK frames, may be included to aid in
   recovery from packet loss.  If present, these appear before the
   regular SILK frames.  They are, in most respects, identical to
   regular, active SILK frames, except that they are usually encoded
   with a lower bitrate.  This document uses "SILK frame" to refer to
   either one and "regular SILK frame" if it needs to draw a distinction
   between the two.

   Logically, each SILK frame is, in turn, composed of either two or
   four 5 ms subframes.  Various parameters, such as the quantization
   gain of the excitation and the pitch lag and filter coefficients can
   vary on a subframe-by-subframe basis.  Physically, the parameters for
   each subframe are interleaved in the bitstream, as described in the
   relevant sections for each parameter.

   All of these frames and subframes are decoded from the same range
   coder, with no padding between them.  Thus, packing multiple SILK
   frames in a single Opus frame saves, on average, half a byte per SILK
   frame.  It also allows some parameters to be predicted from prior
   SILK frames in the same Opus frame, since this does not degrade
   packet loss robustness (beyond any penalty for merely using fewer,
   larger packets to store multiple frames).

   Stereo support in SILK uses a variant of mid-side coding, allowing a
   mono decoder to simply decode the mid channel.  However, the data for
   the two channels is interleaved, so a mono decoder must still unpack





Valin, et al.                Standards Track                   [Page 33]

RFC 6716                 Interactive Audio Codec          September 2012


   the data for the side channel.  It would be required to do so anyway
   for Hybrid Opus frames or to support decoding individual 20 ms
   frames.

   Table 3 summarizes the overall grouping of the contents of the LP
   layer.  Figures 15 and 16 illustrate the ordering of the various SILK
   frames for a 60 ms Opus frame, for both mono and stereo,
   respectively.

   +-----------------------------------+---------------+---------------+
   |             Symbol(s)             |     PDF(s)    |   Condition   |
   +-----------------------------------+---------------+---------------+
   |   Voice Activity Detection (VAD)  |    {1, 1}/2   |               |
   |               Flags               |               |               |
   |                                   |               |               |
   |             LBRR Flag             |    {1, 1}/2   |               |
   |                                   |               |               |
   |        Per-Frame LBRR Flags       |    Table 4    | Section 4.2.4 |
   |                                   |               |               |
   |           LBRR Frame(s)           | Section 4.2.7 | Section 4.2.4 |
   |                                   |               |               |
   |       Regular SILK Frame(s)       | Section 4.2.7 |               |
   +-----------------------------------+---------------+---------------+

         Table 3: Organization of the SILK layer of an Opus Frame


                    +---------------------------------+
                    |            VAD Flags            |
                    +---------------------------------+
                    |            LBRR Flag            |
                    +---------------------------------+
                    | Per-Frame LBRR Flags (Optional) |
                    +---------------------------------+
                    |     LBRR Frame 1 (Optional)     |
                    +---------------------------------+
                    |     LBRR Frame 2 (Optional)     |
                    +---------------------------------+
                    |     LBRR Frame 3 (Optional)     |
                    +---------------------------------+
                    |      Regular SILK Frame 1       |
                    +---------------------------------+
                    |      Regular SILK Frame 2       |
                    +---------------------------------+
                    |      Regular SILK Frame 3       |
                    +---------------------------------+

                       Figure 15: A 60 ms Mono Frame



Valin, et al.                Standards Track                   [Page 34]

RFC 6716                 Interactive Audio Codec          September 2012


                 +---------------------------------------+
                 |             Mid VAD Flags             |
                 +---------------------------------------+
                 |             Mid LBRR Flag             |
                 +---------------------------------------+
                 |             Side VAD Flags            |
                 +---------------------------------------+
                 |             Side LBRR Flag            |
                 +---------------------------------------+
                 |  Mid Per-Frame LBRR Flags (Optional)  |
                 +---------------------------------------+
                 | Side Per-Frame LBRR Flags (Optional)  |
                 +---------------------------------------+
                 |     Mid LBRR Frame 1 (Optional)       |
                 +---------------------------------------+
                 |     Side LBRR Frame 1 (Optional)      |
                 +---------------------------------------+
                 |     Mid LBRR Frame 2 (Optional)       |
                 +---------------------------------------+
                 |     Side LBRR Frame 2 (Optional)      |
                 +---------------------------------------+
                 |     Mid LBRR Frame 3 (Optional)       |
                 +---------------------------------------+
                 |     Side LBRR Frame 3 (Optional)      |
                 +---------------------------------------+
                 |      Mid Regular SILK Frame 1         |
                 +---------------------------------------+
                 | Side Regular SILK Frame 1 (Optional)  |
                 +---------------------------------------+
                 |      Mid Regular SILK Frame 2         |
                 +---------------------------------------+
                 | Side Regular SILK Frame 2 (Optional)  |
                 +---------------------------------------+
                 |      Mid Regular SILK Frame 3         |
                 +---------------------------------------+
                 | Side Regular SILK Frame 3 (Optional)  |
                 +---------------------------------------+

                      Figure 16: A 60 ms Stereo Frame

4.2.3.  Header Bits



   The LP layer begins with two to eight header bits, decoded in
   silk_Decode() (dec_API.c).  These consist of one Voice Activity
   Detection (VAD) bit per frame (up to 3), followed by a single flag
   indicating the presence of LBRR frames.  For a stereo packet, these
   first flags correspond to the mid channel, and a second set of flags
   is included for the side channel.



Valin, et al.                Standards Track                   [Page 35]

RFC 6716                 Interactive Audio Codec          September 2012


   Because these are the first symbols decoded by the range coder and
   because they are coded as binary values with uniform probability,
   they can be extracted directly from the most significant bits of the
   first byte of compressed data.  Thus, a receiver can determine if an
   Opus frame contains any active SILK frames without the overhead of
   using the range decoder.

4.2.4.  Per-Frame LBRR Flags



   For Opus frames longer than 20 ms, a set of LBRR flags is decoded for
   each channel that has its LBRR flag set.  Each set contains one flag
   per 20 ms SILK frame. 40 ms Opus frames use the 2-frame LBRR flag PDF
   from Table 4, and 60 ms Opus frames use the 3-frame LBRR flag PDF.
   For each channel, the resulting 2- or 3-bit integer contains the
   corresponding LBRR flag for each frame, packed in order from the LSB
   to the MSB.

           +------------+-------------------------------------+
           | Frame Size | PDF                                 |
           +------------+-------------------------------------+
           | 40 ms      | {0, 53, 53, 150}/256                |
           |            |                                     |
           | 60 ms      | {0, 41, 20, 29, 41, 15, 28, 82}/256 |
           +------------+-------------------------------------+

                          Table 4: LBRR Flag PDFs

   A 10 or 20 ms Opus frame does not contain any per-frame LBRR flags,
   as there may be at most one LBRR frame per channel.  The global LBRR
   flag in the header bits (see Section 4.2.3) is already sufficient to
   indicate the presence of that single LBRR frame.

4.2.5.  LBRR Frames



   The LBRR frames, if present, contain an encoded representation of the
   signal immediately prior to the current Opus frame as if it were
   encoded with the current mode, frame size, audio bandwidth, and
   channel count, even if those differ from the prior Opus frame.  When
   one of these parameters changes from one Opus frame to the next, this
   implies that the LBRR frames of the current Opus frame may not be
   simple drop-in replacements for the contents of the previous Opus
   frame.

   For example, when switching from 20 ms to 60 ms, the 60 ms Opus frame
   may contain LBRR frames covering up to three prior 20 ms Opus frames,
   even if those frames already contained LBRR frames covering some of
   the same time periods.  When switching from 20 ms to 10 ms, the 10 ms
   Opus frame can contain an LBRR frame covering at most half the prior



Valin, et al.                Standards Track                   [Page 36]

RFC 6716                 Interactive Audio Codec          September 2012


   20 ms Opus frame, potentially leaving a hole that needs to be
   concealed from even a single packet loss (see Section 4.4).  When
   switching from mono to stereo, the LBRR frames in the first stereo
   Opus frame MAY contain a non-trivial side channel.

   In order to properly produce LBRR frames under all conditions, an
   encoder might need to buffer up to 60 ms of audio and re-encode it
   during these transitions.  However, the reference implementation opts
   to disable LBRR frames at the transition point for simplicity.  Since
   transitions are relatively infrequent in normal usage, this does not
   have a significant impact on packet loss robustness.

   The LBRR frames immediately follow the LBRR flags, prior to any
   regular SILK frames.  Section 4.2.7 describes their exact contents.
   LBRR frames do not include their own separate VAD flags.  LBRR frames
   are only meant to be transmitted for active speech, thus all LBRR
   frames are treated as active.

   In a stereo Opus frame longer than 20 ms, although the per-frame LBRR
   flags for the mid channel are coded as a unit before the per-frame
   LBRR flags for the side channel, the LBRR frames themselves are
   interleaved.  The decoder parses an LBRR frame for the mid channel of
   a given 20 ms interval (if present) and then immediately parses the
   corresponding LBRR frame for the side channel (if present), before
   proceeding to the next 20 ms interval.

4.2.6.  Regular SILK Frames



   The regular SILK frame(s) follow the LBRR frames (if any).
   Section 4.2.7 describes their contents, as well.  Unlike the LBRR
   frames, a regular SILK frame is coded for each time interval in an
   Opus frame, even if the corresponding VAD flags are unset.  For
   stereo Opus frames longer than 20 ms, the regular mid and side SILK
   frames for each 20 ms interval are interleaved, just as with the LBRR
   frames.  The side frame may be skipped by coding an appropriate flag,
   as detailed in Section 4.2.7.2.

4.2.7.  SILK Frame Contents



   Each SILK frame includes a set of side information that encodes

   o  The frame type and quantization type (Section 4.2.7.3),

   o  Quantization gains (Section 4.2.7.4),

   o  Short-term prediction filter coefficients (Section 4.2.7.5),





Valin, et al.                Standards Track                   [Page 37]

RFC 6716                 Interactive Audio Codec          September 2012


   o  A Line Spectral Frequencies (LSFs) interpolation weight
      (Section 4.2.7.5.5),

   o  LTP filter lags and gains (Section 4.2.7.6), and

   o  A Linear Congruential Generator (LCG) seed (Section 4.2.7.7).

   The quantized excitation signal (see Section 4.2.7.8) follows these
   at the end of the frame.  Table 5 details the overall organization of
   a SILK frame.









































Valin, et al.                Standards Track                   [Page 38]

RFC 6716                 Interactive Audio Codec          September 2012


   +---------------------------+-------------------+-------------------+
   |         Symbol(s)         |       PDF(s)      |     Condition     |
   +---------------------------+-------------------+-------------------+
   | Stereo Prediction Weights |      Table 6      |  Section 4.2.7.1  |
   |                           |                   |                   |
   |       Mid-only Flag       |      Table 8      |  Section 4.2.7.2  |
   |                           |                   |                   |
   |         Frame Type        |  Section 4.2.7.3  |                   |
   |                           |                   |                   |
   |       Subframe Gains      |  Section 4.2.7.4  |                   |
   |                           |                   |                   |
   |   Normalized LSF Stage-1  |      Table 14     |                   |
   |           Index           |                   |                   |
   |                           |                   |                   |
   |   Normalized LSF Stage-2  | Section 4.2.7.5.2 |                   |
   |          Residual         |                   |                   |
   |                           |                   |                   |
   |       Normalized LSF      |      Table 26     |    20 ms frame    |
   |    Interpolation Weight   |                   |                   |
   |                           |                   |                   |
   |     Primary Pitch Lag     | Section 4.2.7.6.1 |    Voiced frame   |
   |                           |                   |                   |
   |   Subframe Pitch Contour  |      Table 32     |    Voiced frame   |
   |                           |                   |                   |
   |     Periodicity Index     |      Table 37     |    Voiced frame   |
   |                           |                   |                   |
   |         LTP Filter        |      Table 38     |    Voiced frame   |
   |                           |                   |                   |
   |        LTP Scaling        |      Table 42     | Section 4.2.7.6.3 |
   |                           |                   |                   |
   |          LCG Seed         |      Table 43     |                   |
   |                           |                   |                   |
   |   Excitation Rate Level   |      Table 45     |                   |
   |                           |                   |                   |
   |  Excitation Pulse Counts  |      Table 46     |                   |
   |                           |                   |                   |
   |      Excitation Pulse     | Section 4.2.7.8.3 |   Non-zero pulse  |
   |         Locations         |                   |       count       |
   |                           |                   |                   |
   |      Excitation LSBs      |      Table 51     | Section 4.2.7.8.2 |
   |                           |                   |                   |
   |      Excitation Signs     |      Table 52     |                   |
   +---------------------------+-------------------+-------------------+

         Table 5: Order of the Symbols in an Individual SILK Frame






Valin, et al.                Standards Track                   [Page 39]

RFC 6716                 Interactive Audio Codec          September 2012


4.2.7.1.  Stereo Prediction Weights



   A SILK frame corresponding to the mid channel of a stereo Opus frame
   begins with a pair of side channel prediction weights, designed such
   that zeros indicate normal mid-side coupling.  Since these weights
   can change on every frame, the first portion of each frame linearly
   interpolates between the previous weights and the current ones, using
   zeros for the previous weights if none are available.  These
   prediction weights are never included in a mono Opus frame, and the
   previous weights are reset to zeros on any transition from mono to
   stereo.  They are also not included in an LBRR frame for the side
   channel, even if the LBRR flags indicate the corresponding mid
   channel was not coded.  In that case, the previous weights are used,
   again substituting in zeros if no previous weights are available
   since the last decoder reset (see Section 4.5.2).

   To summarize, these weights are coded if and only if

   o  This is a stereo Opus frame (Section 3.1), and

   o  The current SILK frame corresponds to the mid channel.

   The prediction weights are coded in three separate pieces, which are
   decoded by silk_stereo_decode_pred() (stereo_decode_pred.c).  The
   first piece jointly codes the high-order part of a table index for
   both weights.  The second piece codes the low-order part of each
   table index.  The third piece codes an offset used to linearly
   interpolate between table indices.  The details are as follows.

   Let n be an index decoded with the 25-element stage-1 PDF in Table 6.
   Then, let i0 and i1 be indices decoded with the stage-2 and stage-3
   PDFs in Table 6, respectively, and let i2 and i3 be two more indices
   decoded with the stage-2 and stage-3 PDFs, all in that order.

   +-------+-----------------------------------------------------------+
   | Stage | PDF                                                       |
   +-------+-----------------------------------------------------------+
   | Stage | {7, 2, 1, 1, 1, 10, 24, 8, 1, 1, 3, 23, 92, 23, 3, 1, 1,  |
   | 1     | 8, 24, 10, 1, 1, 1, 2, 7}/256                             |
   |       |                                                           |
   | Stage | {85, 86, 85}/256                                          |
   | 2     |                                                           |
   |       |                                                           |
   | Stage | {51, 51, 52, 51, 51}/256                                  |
   | 3     |                                                           |
   +-------+-----------------------------------------------------------+

                        Table 6: Stereo Weight PDFs



Valin, et al.                Standards Track                   [Page 40]

RFC 6716                 Interactive Audio Codec          September 2012


   Then, use n, i0, and i2 to form two table indices, wi0 and wi1,
   according to

                             wi0 = i0 + 3*(n/5)
                             wi1 = i2 + 3*(n%5)

   where the division is integer division.  The range of these indices
   is 0 to 14, inclusive.  Let w_Q13[i] be the i'th weight from Table 7.
   Then, the two prediction weights, w0_Q13 and w1_Q13, are

      w1_Q13 = w_Q13[wi1]
               + (((w_Q13[wi1+1] - w_Q13[wi1])*6554) >> 16)*(2*i3 + 1)

      w0_Q13 = w_Q13[wi0]
               + (((w_Q13[wi0+1] - w_Q13[wi0])*6554) >> 16)*(2*i1 + 1)
               - w1_Q13

   N.B., w1_Q13 is computed first here, because w0_Q13 depends on it.
   The constant 6554 is approximately 0.1 in Q16.  Although wi0 and wi1
   only have 15 possible values, Table 7 contains 16 entries to allow
   interpolation between entry wi0 and (wi0 + 1) (and likewise for wi1).






























Valin, et al.                Standards Track                   [Page 41]

RFC 6716                 Interactive Audio Codec          September 2012


                         +-------+--------------+
                         | Index | Weight (Q13) |
                         +-------+--------------+
                         | 0     |       -13732 |
                         |       |              |
                         | 1     |       -10050 |
                         |       |              |
                         | 2     |        -8266 |
                         |       |              |
                         | 3     |        -7526 |
                         |       |              |
                         | 4     |        -6500 |
                         |       |              |
                         | 5     |        -5000 |
                         |       |              |
                         | 6     |        -2950 |
                         |       |              |
                         | 7     |         -820 |
                         |       |              |
                         | 8     |          820 |
                         |       |              |
                         | 9     |         2950 |
                         |       |              |
                         | 10    |         5000 |
                         |       |              |
                         | 11    |         6500 |
                         |       |              |
                         | 12    |         7526 |
                         |       |              |
                         | 13    |         8266 |
                         |       |              |
                         | 14    |        10050 |
                         |       |              |
                         | 15    |        13732 |
                         +-------+--------------+

                       Table 7: Stereo Weight Table

4.2.7.2.  Mid-Only Flag



   A flag appears after the stereo prediction weights that indicates if
   only the mid channel is coded for this time interval.  It appears
   only when

   o  This is a stereo Opus frame (see Section 3.1),

   o  The current SILK frame corresponds to the mid channel, and




Valin, et al.                Standards Track                   [Page 42]

RFC 6716                 Interactive Audio Codec          September 2012


   o  Either

      *  This is a regular SILK frame where the VAD flags (see
         Section 4.2.3) indicate that the corresponding side channel is
         not active.

      *  This is an LBRR frame where the LBRR flags (see Sections 4.2.3
         and 4.2.4) indicate that the corresponding side channel is not
         coded.

   It is omitted when there are no stereo weights, for all of the same
   reasons.  It is also omitted for a regular SILK frame when the VAD
   flag of the corresponding side channel frame is set (indicating it is
   active).  The side channel must be coded in this case, making the
   mid-only flag redundant.  It is also omitted for an LBRR frame when
   the corresponding LBRR flags indicate the side channel is coded.

   When the flag is present, the decoder reads a single value using the
   PDF in Table 8, as implemented in silk_stereo_decode_mid_only()
   (stereo_decode_pred.c).  If the flag is set, then there is no
   corresponding SILK frame for the side channel, the entire decoding
   process for the side channel is skipped, and zeros are fed to the
   stereo unmixing process (see Section 4.2.8) instead.  As stated
   above, LBRR frames still include this flag when the LBRR flag
   indicates that the side channel is not coded.  In that case, if this
   flag is zero (indicating that there should be a side channel), then
   Packet Loss Concealment (PLC, see Section 4.4) SHOULD be invoked to
   recover a side channel signal.  Otherwise, the stereo image will
   collapse.

                             +---------------+
                             | PDF           |
                             +---------------+
                             | {192, 64}/256 |
                             +---------------+

                        Table 8: Mid-only Flag PDF

4.2.7.3.  Frame Type



   Each SILK frame contains a single "frame type" symbol that jointly
   codes the signal type and quantization offset type of the
   corresponding frame.  If the current frame is a regular SILK frame
   whose VAD bit was not set (an "inactive" frame), then the frame type
   symbol takes on a value of either 0 or 1 and is decoded using the
   first PDF in Table 9.  If the frame is an LBRR frame or a regular
   SILK frame whose VAD flag was set (an "active" frame), then the value
   of the symbol may range from 2 to 5, inclusive, and is decoded using



Valin, et al.                Standards Track                   [Page 43]

RFC 6716                 Interactive Audio Codec          September 2012


   the second PDF in Table 9.  Table 10 translates between the value of
   the frame type symbol and the corresponding signal type and
   quantization offset type.

                +----------+-----------------------------+
                | VAD Flag | PDF                         |
                +----------+-----------------------------+
                | Inactive | {26, 230, 0, 0, 0, 0}/256   |
                |          |                             |
                | Active   | {0, 0, 24, 74, 148, 10}/256 |
                +----------+-----------------------------+

                         Table 9: Frame Type PDFs

          +------------+-------------+--------------------------+
          | Frame Type | Signal Type | Quantization Offset Type |
          +------------+-------------+--------------------------+
          | 0          | Inactive    |                      Low |
          |            |             |                          |
          | 1          | Inactive    |                     High |
          |            |             |                          |
          | 2          | Unvoiced    |                      Low |
          |            |             |                          |
          | 3          | Unvoiced    |                     High |
          |            |             |                          |
          | 4          | Voiced      |                      Low |
          |            |             |                          |
          | 5          | Voiced      |                     High |
          +------------+-------------+--------------------------+

    Table 10: Signal Type and Quantization Offset Type from Frame Type

4.2.7.4.  Subframe Gains



   A separate quantization gain is coded for each 5 ms subframe.  These
   gains control the step size between quantization levels of the
   excitation signal and, therefore, the quality of the reconstruction.
   They are independent of and unrelated to the pitch contours coded for
   voiced frames.  The quantization gains are themselves uniformly
   quantized to 6 bits on a log scale, giving them a resolution of
   approximately 1.369 dB and a range of approximately 1.94 dB to
   88.21 dB.

   The subframe gains are either coded independently, or relative to the
   gain from the most recent coded subframe in the same channel.
   Independent coding is used if and only if





Valin, et al.                Standards Track                   [Page 44]

RFC 6716                 Interactive Audio Codec          September 2012


   o  This is the first subframe in the current SILK frame, and

   o  Either

      *  This is the first SILK frame of its type (LBRR or regular) for
         this channel in the current Opus frame, or

      *  The previous SILK frame of the same type (LBRR or regular) for
         this channel in the same Opus frame was not coded.

   In an independently coded subframe gain, the 3 most significant bits
   of the quantization gain are decoded using a PDF selected from
   Table 11 based on the decoded signal type (see Section 4.2.7.3).

           +-------------+------------------------------------+
           | Signal Type | PDF                                |
           +-------------+------------------------------------+
           | Inactive    | {32, 112, 68, 29, 12, 1, 1, 1}/256 |
           |             |                                    |
           | Unvoiced    | {2, 17, 45, 60, 62, 47, 19, 4}/256 |
           |             |                                    |
           | Voiced      | {1, 3, 26, 71, 94, 50, 9, 2}/256   |
           +-------------+------------------------------------+

        Table 11: PDFs for Independent Quantization Gain MSB Coding

   The 3 least significant bits are decoded using a uniform PDF:

                 +--------------------------------------+
                 | PDF                                  |
                 +--------------------------------------+
                 | {32, 32, 32, 32, 32, 32, 32, 32}/256 |
                 +--------------------------------------+

        Table 12: PDF for Independent Quantization Gain LSB Coding

   These 6 bits are combined to form a value, gain_index, between 0 and
   63.  When the gain for the previous subframe is available, then the
   current gain is limited as follows:

             log_gain = max(gain_index, previous_log_gain - 16)

   This may help some implementations limit the change in precision of
   their internal LTP history.  The indices to which this clamp applies
   cannot simply be removed from the codebook, because previous_log_gain
   will not be available after packet loss.  The clamping is skipped
   after a decoder reset, and in the side channel if the previous frame




Valin, et al.                Standards Track                   [Page 45]

RFC 6716                 Interactive Audio Codec          September 2012


   in the side channel was not coded, since there is no value for
   previous_log_gain available.  It MAY also be skipped after packet
   loss.

   For subframes that do not have an independent gain (including the
   first subframe of frames not listed as using independent coding
   above), the quantization gain is coded relative to the gain from the
   previous subframe (in the same channel).  The PDF in Table 13 yields
   a delta_gain_index value between 0 and 40, inclusive.

   +-------------------------------------------------------------------+
   | PDF                                                               |
   +-------------------------------------------------------------------+
   | {6, 5, 11, 31, 132, 21, 8, 4, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, |
   | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,       |
   | 1}/256                                                            |
   +-------------------------------------------------------------------+

             Table 13: PDF for Delta Quantization Gain Coding

   The following formula translates this index into a quantization gain
   for the current subframe using the gain from the previous subframe:

     log_gain = clamp(0, max(2*delta_gain_index - 16,
                        previous_log_gain + delta_gain_index - 4), 63)

   silk_gains_dequant() (gain_quant.c) dequantizes log_gain for the k'th
   subframe and converts it into a linear Q16 scale factor via

         gain_Q16[k] = silk_log2lin((0x1D1C71*log_gain>>16) + 2090)

   The function silk_log2lin() (log2lin.c) computes an approximation of
   2**(inLog_Q7/128.0), where inLog_Q7 is its Q7 input.  Let i =
   inLog_Q7>>7 be the integer part of inLogQ7 and f = inLog_Q7&127 be
   the fractional part.  Then,

               (1<<i) + ((-174*f*(128-f)>>16)+f)*((1<<i)>>7)

   yields the approximate exponential.  The final Q16 gain values lies
   between 81920 and 1686110208, inclusive (representing scale factors
   of 1.25 to 25728, respectively).

4.2.7.5.  Normalized Line Spectral Frequency (LSF) and Linear Predictive
          Coding (LPC) Coefficients



   A set of normalized Line Spectral Frequency (LSF) coefficients follow
   the quantization gains in the bitstream and represent the Linear
   Predictive Coding (LPC) coefficients for the current SILK frame.



Valin, et al.                Standards Track                   [Page 46]

RFC 6716                 Interactive Audio Codec          September 2012


   Once decoded, the normalized LSFs form an increasing list of Q15
   values between 0 and 1.  These represent the interleaved zeros on the
   upper half of the unit circle (between 0 and pi, hence "normalized")
   in the standard decomposition [SPECTRAL-PAIRS] of the LPC filter into
   a symmetric part and an anti-symmetric part (P and Q in
   Section 4.2.7.5.6).  Because of non-linear effects in the decoding
   process, an implementation SHOULD match the fixed-point arithmetic
   described in this section exactly.  An encoder SHOULD also use the
   same process.

   The normalized LSFs are coded using a two-stage vector quantizer (VQ)
   (Sections 4.2.7.5.1 and 4.2.7.5.2).  NB and MB frames use an order-10
   predictor, while WB frames use an order-16 predictor.  Thus, each of
   these two cases uses a different set of tables.  After reconstructing
   the normalized LSFs (Section 4.2.7.5.3), the decoder runs them
   through a stabilization process (Section 4.2.7.5.4), interpolates
   them between frames (Section 4.2.7.5.5), converts them back into LPC
   coefficients (Section 4.2.7.5.6), and then runs them through further
   processes to limit the range of the coefficients (Section 4.2.7.5.7)
   and the gain of the filter (Section 4.2.7.5.8).  All of this is
   necessary to ensure the reconstruction process is stable.

4.2.7.5.1.  Normalized LSF Stage 1 Decoding


   The first VQ stage uses a 32-element codebook, coded with one of the
   PDFs in Table 14, depending on the audio bandwidth and the signal
   type of the current SILK frame.  This yields a single index, I1, for
   the entire frame, which

   1.  Indexes an element in a coarse codebook,

   2.  Selects the PDFs for the second stage of the VQ, and

   3.  Selects the prediction weights used to remove intra-frame
       redundancy from the second stage.

   The actual codebook elements are listed in Tables 23 and 24, but they
   are not needed until the last stages of reconstructing the LSF
   coefficients.












Valin, et al.                Standards Track                   [Page 47]

RFC 6716                 Interactive Audio Codec          September 2012


   +-----------+----------+--------------------------------------------+
   | Audio     | Signal   | PDF                                        |
   | Bandwidth | Type     |                                            |
   +-----------+----------+--------------------------------------------+
   | NB or MB  | Inactive | {44, 34, 30, 19, 21, 12, 11, 3, 3, 2, 16,  |
   |           | or       | 2, 2, 1, 5, 2, 1, 3, 3, 1, 1, 2, 2, 2, 3,  |
   |           | unvoiced | 1, 9, 9, 2, 7, 2, 1}/256                   |
   |           |          |                                            |
   | NB or MB  | Voiced   | {1, 10, 1, 8, 3, 8, 8, 14, 13, 14, 1, 14,  |
   |           |          | 12, 13, 11, 11, 12, 11, 10, 10, 11, 8, 9,  |
   |           |          | 8, 7, 8, 1, 1, 6, 1, 6, 5}/256             |
   |           |          |                                            |
   | WB        | Inactive | {31, 21, 3, 17, 1, 8, 17, 4, 1, 18, 16, 4, |
   |           | or       | 2, 3, 1, 10, 1, 3, 16, 11, 16, 2, 2, 3, 2, |
   |           | unvoiced | 11, 1, 4, 9, 8, 7, 3}/256                  |
   |           |          |                                            |
   | WB        | Voiced   | {1, 4, 16, 5, 18, 11, 5, 14, 15, 1, 3, 12, |
   |           |          | 13, 14, 14, 6, 14, 12, 2, 6, 1, 12, 12,    |
   |           |          | 11, 10, 3, 10, 5, 1, 1, 1, 3}/256          |
   +-----------+----------+--------------------------------------------+

         Table 14: PDFs for Normalized LSF Stage-1 Index Decoding

4.2.7.5.2.  Normalized LSF Stage 2 Decoding


   A total of 16 PDFs are available for the LSF residual in the second
   stage: the 8 (a...h) for NB and MB frames given in Table 15, and the
   8 (i...p) for WB frames given in Table 16.  Which PDF is used for
   which coefficient is driven by the index, I1, decoded in the first
   stage.  Table 17 lists the letter of the corresponding PDF for each
   normalized LSF coefficient for NB and MB, and Table 18 lists the same
   information for WB.



















Valin, et al.                Standards Track                   [Page 48]

RFC 6716                 Interactive Audio Codec          September 2012


            +----------+--------------------------------------+
            | Codebook | PDF                                  |
            +----------+--------------------------------------+
            | a        | {1, 1, 1, 15, 224, 11, 1, 1, 1}/256  |
            |          |                                      |
            | b        | {1, 1, 2, 34, 183, 32, 1, 1, 1}/256  |
            |          |                                      |
            | c        | {1, 1, 4, 42, 149, 55, 2, 1, 1}/256  |
            |          |                                      |
            | d        | {1, 1, 8, 52, 123, 61, 8, 1, 1}/256  |
            |          |                                      |
            | e        | {1, 3, 16, 53, 101, 74, 6, 1, 1}/256 |
            |          |                                      |
            | f        | {1, 3, 17, 55, 90, 73, 15, 1, 1}/256 |
            |          |                                      |
            | g        | {1, 7, 24, 53, 74, 67, 26, 3, 1}/256 |
            |          |                                      |
            | h        | {1, 1, 18, 63, 78, 58, 30, 6, 1}/256 |
            +----------+--------------------------------------+

      Table 15: PDFs for NB/MB Normalized LSF Stage-2 Index Decoding

           +----------+---------------------------------------+
           | Codebook | PDF                                   |
           +----------+---------------------------------------+
           | i        | {1, 1, 1, 9, 232, 9, 1, 1, 1}/256     |
           |          |                                       |
           | j        | {1, 1, 2, 28, 186, 35, 1, 1, 1}/256   |
           |          |                                       |
           | k        | {1, 1, 3, 42, 152, 53, 2, 1, 1}/256   |
           |          |                                       |
           | l        | {1, 1, 10, 49, 126, 65, 2, 1, 1}/256  |
           |          |                                       |
           | m        | {1, 4, 19, 48, 100, 77, 5, 1, 1}/256  |
           |          |                                       |
           | n        | {1, 1, 14, 54, 100, 72, 12, 1, 1}/256 |
           |          |                                       |
           | o        | {1, 1, 15, 61, 87, 61, 25, 4, 1}/256  |
           |          |                                       |
           | p        | {1, 7, 21, 50, 77, 81, 17, 1, 1}/256  |
           +----------+---------------------------------------+

        Table 16: PDFs for WB Normalized LSF Stage-2 Index Decoding








Valin, et al.                Standards Track                   [Page 49]

RFC 6716                 Interactive Audio Codec          September 2012


                       +----+---------------------+
                       | I1 | Coefficient         |
                       +----+---------------------+
                       |    | 0 1 2 3 4 5 6 7 8 9 |
                       | 0  | a a a a a a a a a a |
                       |    |                     |
                       | 1  | b d b c c b c b b b |
                       |    |                     |
                       | 2  | c b b b b b b b b b |
                       |    |                     |
                       | 3  | b c c c c b c b b b |
                       |    |                     |
                       | 4  | c d d d d c c c c c |
                       |    |                     |
                       | 5  | a f d d c c c c b b |
                       |    |                     |
                       | g  | a c c c c c c c c b |
                       |    |                     |
                       | 7  | c d g e e e f e f f |
                       |    |                     |
                       | 8  | c e f f e f e g e e |
                       |    |                     |
                       | 9  | c e e h e f e f f e |
                       |    |                     |
                       | 10 | e d d d c d c c c c |
                       |    |                     |
                       | 11 | b f f g e f e f f f |
                       |    |                     |
                       | 12 | c h e g f f f f f f |
                       |    |                     |
                       | 13 | c h f f f f f g f e |
                       |    |                     |
                       | 14 | d d f e e f e f e e |
                       |    |                     |
                       | 15 | c d d f f e e e e e |
                       |    |                     |
                       | 16 | c e e g e f e f f f |
                       |    |                     |
                       | 17 | c f e g f f f e f e |
                       |    |                     |
                       | 18 | c h e f e f e f f f |
                       |    |                     |
                       | 19 | c f e g h g f g f e |
                       |    |                     |
                       | 20 | d g h e g f f g e f |
                       |    |                     |
                       | 21 | c h g e e e f e f f |
                       |    |                     |



Valin, et al.                Standards Track                   [Page 50]

RFC 6716                 Interactive Audio Codec          September 2012


                       | 22 | e f f e g g f g f e |
                       |    |                     |
                       | 23 | c f f g f g e g e e |
                       |    |                     |
                       | 24 | e f f f d h e f f e |
                       |    |                     |
                       | 25 | c d e f f g e f f e |
                       |    |                     |
                       | 26 | c d c d d e c d d d |
                       |    |                     |
                       | 27 | b b c c c c c d c c |
                       |    |                     |
                       | 28 | e f f g g g f g e f |
                       |    |                     |
                       | 29 | d f f e e e e d d c |
                       |    |                     |
                       | 30 | c f d h f f e e f e |
                       |    |                     |
                       | 31 | e e f e f g f g f e |
                       +----+---------------------+

    Table 17: Codebook Selection for NB/MB Normalized LSF Stage-2 Index
                                 Decoding

          +----+------------------------------------------------+
          | I1 | Coefficient                                    |
          +----+------------------------------------------------+
          |    | 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 |
          |    |                                                |
          | 0  | i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i |
          |    |                                                |
          | 1  | k  l  l  l  l  l  k  k  k  k  k  j  j  j  i  l |
          |    |                                                |
          | 2  | k  n  n  l  p  m  m  n  k  n  m  n  n  m  l  l |
          |    |                                                |
          | 3  | i  k  j  k  k  j  j  j  j  j  i  i  i  i  i  j |
          |    |                                                |
          | 4  | i  o  n  m  o  m  p  n  m  m  m  n  n  m  m  l |
          |    |                                                |
          | 5  | i  l  n  n  m  l  l  n  l  l  l  l  l  l  k  m |
          |    |                                                |
          | 6  | i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i |
          |    |                                                |
          | 7  | i  k  o  l  p  k  n  l  m  n  n  m  l  l  k  l |
          |    |                                                |
          | 8  | i  o  k  o  o  m  n  m  o  n  m  m  n  l  l  l |
          |    |                                                |
          | 9  | k  j  i  i  i  i  i  i  i  i  i  i  i  i  i  i |



Valin, et al.                Standards Track                   [Page 51]

RFC 6716                 Interactive Audio Codec          September 2012


          |    |                                                |
          | 10 | i  j  i  i  i  i  i  i  i  i  i  i  i  i  i  j |
          |    |                                                |
          | 11 | k  k  l  m  n  l  l  l  l  l  l  l  k  k  j  l |
          |    |                                                |
          | 12 | k  k  l  l  m  l  l  l  l  l  l  l  l  k  j  l |
          |    |                                                |
          | 13 | l  m  m  m  o  m  m  n  l  n  m  m  n  m  l  m |
          |    |                                                |
          | 14 | i  o  m  n  m  p  n  k  o  n  p  m  m  l  n  l |
          |    |                                                |
          | 15 | i  j  i  j  j  j  j  j  j  j  i  i  i  i  j  i |
          |    |                                                |
          | 16 | j  o  n  p  n  m  n  l  m  n  m  m  m  l  l  m |
          |    |                                                |
          | 17 | j  l  l  m  m  l  l  n  k  l  l  n  n  n  l  m |
          |    |                                                |
          | 18 | k  l  l  k  k  k  l  k  j  k  j  k  j  j  j  m |
          |    |                                                |
          | 19 | i  k  l  n  l  l  k  k  k  j  j  i  i  i  i  i |
          |    |                                                |
          | 20 | l  m  l  n  l  l  k  k  j  j  j  j  j  k  k  m |
          |    |                                                |
          | 21 | k  o  l  p  p  m  n  m  n  l  n  l  l  k  l  l |
          |    |                                                |
          | 22 | k  l  n  o  o  l  n  l  m  m  l  l  l  l  k  m |
          |    |                                                |
          | 23 | j  l  l  m  m  m  m  l  n  n  n  l  j  j  j  j |
          |    |                                                |
          | 24 | k  n  l  o  o  m  p  m  m  n  l  m  m  l  l  l |
          |    |                                                |
          | 25 | i  o  j  j  i  i  i  i  i  i  i  i  i  i  i  i |
          |    |                                                |
          | 26 | i  o  o  l  n  k  n  n  l  m  m  p  p  m  m  m |
          |    |                                                |
          | 27 | l  l  p  l  n  m  l  l  l  k  k  l  l  l  k  l |
          |    |                                                |
          | 28 | i  i  j  i  i  i  k  j  k  j  j  k  k  k  j  j |
          |    |                                                |
          | 29 | i  l  k  n  l  l  k  l  k  j  i  i  j  i  i  j |
          |    |                                                |
          | 30 | l  n  n  m  p  n  l  l  k  l  k  k  j  i  j  i |
          |    |                                                |
          | 31 | k  l  n  l  m  l  l  l  k  j  k  o  m  i  i  i |
          +----+------------------------------------------------+

     Table 18: Codebook Selection for WB Normalized LSF Stage-2 Index
                                 Decoding



Valin, et al.                Standards Track                   [Page 52]

RFC 6716                 Interactive Audio Codec          September 2012


   Decoding the second stage residual proceeds as follows.  For each
   coefficient, the decoder reads a symbol using the PDF corresponding
   to I1 from either Table 17 or Table 18, and subtracts 4 from the
   result to give an index in the range -4 to 4, inclusive.  If the
   index is either -4 or 4, it reads a second symbol using the PDF in
   Table 19, and adds the value of this second symbol to the index,
   using the same sign.  This gives the index, I2[k], a total range of
   -10 to 10, inclusive.

                     +-------------------------------+
                     | PDF                           |
                     +-------------------------------+
                     | {156, 60, 24, 9, 4, 2, 1}/256 |
                     +-------------------------------+

         Table 19: PDF for Normalized LSF Index Extension Decoding

   The decoded indices from both stages are translated back into
   normalized LSF coefficients in silk_NLSF_decode() (NLSF_decode.c).
   The stage-2 indices represent residuals after both the first stage of
   the VQ and a separate backwards-prediction step.  The backwards
   prediction process in the encoder subtracts a prediction from each
   residual formed by a multiple of the coefficient that follows it.
   The decoder must undo this process.  Table 20 contains lists of
   prediction weights for each coefficient.  There are two lists for NB
   and MB, and another two lists for WB, giving two possible prediction
   weights for each coefficient.
























Valin, et al.                Standards Track                   [Page 53]

RFC 6716                 Interactive Audio Codec          September 2012


                  +-------------+-----+-----+-----+-----+
                  | Coefficient |   A |   B |   C |   D |
                  +-------------+-----+-----+-----+-----+
                  | 0           | 179 | 116 | 175 |  68 |
                  |             |     |     |     |     |
                  | 1           | 138 |  67 | 148 |  62 |
                  |             |     |     |     |     |
                  | 2           | 140 |  82 | 160 |  66 |
                  |             |     |     |     |     |
                  | 3           | 148 |  59 | 176 |  60 |
                  |             |     |     |     |     |
                  | 4           | 151 |  92 | 178 |  72 |
                  |             |     |     |     |     |
                  | 5           | 149 |  72 | 173 | 117 |
                  |             |     |     |     |     |
                  | 6           | 153 | 100 | 174 |  85 |
                  |             |     |     |     |     |
                  | 7           | 151 |  89 | 164 |  90 |
                  |             |     |     |     |     |
                  | 8           | 163 |  92 | 177 | 118 |
                  |             |     |     |     |     |
                  | 9           |     |     | 174 | 136 |
                  |             |     |     |     |     |
                  | 10          |     |     | 196 | 151 |
                  |             |     |     |     |     |
                  | 11          |     |     | 182 | 142 |
                  |             |     |     |     |     |
                  | 12          |     |     | 198 | 160 |
                  |             |     |     |     |     |
                  | 13          |     |     | 192 | 142 |
                  |             |     |     |     |     |
                  | 14          |     |     | 182 | 155 |
                  +-------------+-----+-----+-----+-----+

         Table 20: Prediction Weights for Normalized LSF Decoding

   The prediction is undone using the procedure implemented in
   silk_NLSF_residual_dequant() (NLSF_decode.c), which is as follows.
   Each coefficient selects its prediction weight from one of the two
   lists based on the stage-1 index, I1.  Table 21 gives the selections
   for each coefficient for NB and MB, and Table 22 gives the selections
   for WB.  Let d_LPC be the order of the codebook, i.e., 10 for NB and
   MB, and 16 for WB, and let pred_Q8[k] be the weight for the k'th
   coefficient selected by this process for 0 <= k < d_LPC-1.  Then, the
   stage-2 residual for each coefficient is computed via

       res_Q10[k] = (k+1 < d_LPC ? (res_Q10[k+1]*pred_Q8[k])>>8 : 0)
                    + ((((I2[k]<<10) - sign(I2[k])*102)*qstep)>>16) ,



Valin, et al.                Standards Track                   [Page 54]

RFC 6716                 Interactive Audio Codec          September 2012


   where qstep is the Q16 quantization step size, which is 11796 for NB
   and MB and 9830 for WB (representing step sizes of approximately 0.18
   and 0.15, respectively).

                        +----+-------------------+
                        | I1 | Coefficient       |
                        +----+-------------------+
                        |    | 0 1 2 3 4 5 6 7 8 |
                        |    |                   |
                        | 0  | A B A A A A A A A |
                        |    |                   |
                        | 1  | B A A A A A A A A |
                        |    |                   |
                        | 2  | A A A A A A A A A |
                        |    |                   |
                        | 3  | B B B A A A A B A |
                        |    |                   |
                        | 4  | A B A A A A A A A |
                        |    |                   |
                        | 5  | A B A A A A A A A |
                        |    |                   |
                        | 6  | B A B B A A A B A |
                        |    |                   |
                        | 7  | A B B A A B B A A |
                        |    |                   |
                        | 8  | A A B B A B A B B |
                        |    |                   |
                        | 9  | A A B B A A B B B |
                        |    |                   |
                        | 10 | A A A A A A A A A |
                        |    |                   |
                        | 11 | A B A B B B B B A |
                        |    |                   |
                        | 12 | A B A B B B B B A |
                        |    |                   |
                        | 13 | A B B B B B B B A |
                        |    |                   |
                        | 14 | B A B B A B B B B |
                        |    |                   |
                        | 15 | A B B B B B A B A |
                        |    |                   |
                        | 16 | A A B B A B A B A |
                        |    |                   |
                        | 17 | A A B B B A B B B |
                        |    |                   |
                        | 18 | A B B A A B B B A |
                        |    |                   |
                        | 19 | A A A B B B A B A |



Valin, et al.                Standards Track                   [Page 55]

RFC 6716                 Interactive Audio Codec          September 2012


                        |    |                   |
                        | 20 | A B B A A B A B A |
                        |    |                   |
                        | 21 | A B B A A A B B A |
                        |    |                   |
                        | 22 | A A A A A B B B B |
                        |    |                   |
                        | 23 | A A B B A A A B B |
                        |    |                   |
                        | 24 | A A A B A B B B B |
                        |    |                   |
                        | 25 | A B B B B B B B A |
                        |    |                   |
                        | 26 | A A A A A A A A A |
                        |    |                   |
                        | 27 | A A A A A A A A A |
                        |    |                   |
                        | 28 | A A B A B B A B A |
                        |    |                   |
                        | 29 | B A A B A A A A A |
                        |    |                   |
                        | 30 | A A A B B A B A B |
                        |    |                   |
                        | 31 | B A B B A B B B B |
                        +----+-------------------+

      Table 21: Prediction Weight Selection for NB/MB Normalized LSF
                                 Decoding

           +----+---------------------------------------------+
           | I1 | Coefficient                                 |
           +----+---------------------------------------------+
           |    | 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 |
           |    |                                             |
           | 0  | C  C  C  C  C  C  C  C  C  C  C  C  C  C  D |
           |    |                                             |
           | 1  | C  C  C  C  C  C  C  C  C  C  C  C  C  C  C |
           |    |                                             |
           | 2  | C  C  D  C  C  D  D  D  C  D  D  D  D  C  C |
           |    |                                             |
           | 3  | C  C  C  C  C  C  C  C  C  C  C  C  D  C  C |
           |    |                                             |
           | 4  | C  D  D  C  D  C  D  D  C  D  D  D  D  D  C |
           |    |                                             |
           | 5  | C  C  D  C  C  C  C  C  C  C  C  C  C  C  C |






Valin, et al.                Standards Track                   [Page 56]

RFC 6716                 Interactive Audio Codec          September 2012


           |    |                                             |
           | 6  | D  C  C  C  C  C  C  C  C  C  C  D  C  D  C |
           |    |                                             |
           | 7  | C  D  D  C  C  C  D  C  D  D  D  C  D  C  D |
           |    |                                             |
           | 8  | C  D  C  D  D  C  D  C  D  C  D  D  D  D  D |
           |    |                                             |
           | 9  | C  C  C  C  C  C  C  C  C  C  C  C  C  C  D |
           |    |                                             |
           | 10 | C  D  C  C  C  C  C  C  C  C  C  C  C  C  C |
           |    |                                             |
           | 11 | C  C  D  C  D  D  D  D  D  D  D  C  D  C  C |
           |    |                                             |
           | 12 | C  C  D  C  C  D  C  D  C  D  C  C  D  C  C |
           |    |                                             |
           | 13 | C  C  C  C  D  D  C  D  C  D  D  D  D  C  C |
           |    |                                             |
           | 14 | C  D  C  C  C  D  D  C  D  D  D  C  D  D  D |
           |    |                                             |
           | 15 | C  C  D  D  C  C  C  C  C  C  C  C  D  D  C |
           |    |                                             |
           | 16 | C  D  D  C  D  C  D  D  D  D  D  C  D  C  C |
           |    |                                             |
           | 17 | C  C  D  C  C  C  C  D  C  C  D  D  D  C  C |
           |    |                                             |
           | 18 | C  C  C  C  C  C  C  C  C  C  C  C  C  C  D |
           |    |                                             |
           | 19 | C  C  C  C  C  C  C  C  C  C  C  C  D  C  C |
           |    |                                             |
           | 20 | C  C  C  C  C  C  C  C  C  C  C  C  C  C  C |
           |    |                                             |
           | 21 | C  D  C  D  C  D  D  C  D  C  D  C  D  D  C |
           |    |                                             |
           | 22 | C  C  D  D  D  D  C  D  D  C  C  D  D  C  C |
           |    |                                             |
           | 23 | C  D  D  C  D  C  D  C  D  C  C  C  C  D  C |
           |    |                                             |
           | 24 | C  C  C  D  D  C  D  C  D  D  D  D  D  D  D |
           |    |                                             |
           | 25 | C  C  C  C  C  C  C  C  C  C  C  C  C  C  D |
           |    |                                             |
           | 26 | C  D  D  C  C  C  D  D  C  C  D  D  D  D  D |
           |    |                                             |
           | 27 | C  C  C  C  C  D  C  D  D  D  D  C  D  D  D |
           |    |                                             |
           | 28 | C  C  C  C  C  C  C  C  C  C  C  C  C  C  D |
           |    |                                             |
           | 29 | C  C  C  C  C  C  C  C  C  C  C  C  C  C  D |



Valin, et al.                Standards Track                   [Page 57]

RFC 6716                 Interactive Audio Codec          September 2012


           |    |                                             |
           | 30 | D  C  C  C  C  C  C  C  C  C  C  D  C  C  C |
           |    |                                             |
           | 31 | C  C  D  C  C  D  D  D  C  C  D  C  C  D  C |
           +----+---------------------------------------------+

   Table 22: Prediction Weight Selection for WB Normalized LSF Decoding

4.2.7.5.3.  Reconstructing the Normalized LSF Coefficients


   Once the stage-1 index I1 and the stage-2 residual res_Q10[] have
   been decoded, the final normalized LSF coefficients can be
   reconstructed.

   The spectral distortion introduced by the quantization of each LSF
   coefficient varies, so the stage-2 residual is weighted accordingly,
   using the low-complexity Inverse Harmonic Mean Weighting (IHMW)
   function proposed in [LAROIA-ICASSP].  The weights are derived
   directly from the stage-1 codebook vector.  Let cb1_Q8[k] be the k'th
   entry of the stage-1 codebook vector from Table 23 or Table 24.
   Then, for 0 <= k < d_LPC, the following expression computes the
   square of the weight as a Q18 value:


            w2_Q18[k] = (1024/(cb1_Q8[k] - cb1_Q8[k-1])
                         + 1024/(cb1_Q8[k+1] - cb1_Q8[k])) << 16


   where cb1_Q8[-1] = 0 and cb1_Q8[d_LPC] = 256, and the division is
   integer division.  This is reduced to an unsquared, Q9 value using
   the following square-root approximation:

                 i = ilog(w2_Q18[k])
                 f = (w2_Q18[k]>>(i-8)) & 127
                 y = ((i&1) ? 32768 : 46214) >> ((32-i)>>1)
                 w_Q9[k] = y + ((213*f*y)>>16)

   The constant 46214 here is approximately the square root of 2 in Q15.
   The cb1_Q8[] vector completely determines these weights, and they may
   be tabulated and stored as 13-bit unsigned values (with a range of
   1819 to 5227, inclusive) to avoid computing them when decoding.  The
   reference implementation already requires code to compute these
   weights on unquantized coefficients in the encoder, in
   silk_NLSF_VQ_weights_laroia() (NLSF_VQ_weights_laroia.c) and its
   callers, so it reuses that code in the decoder instead of using a
   pre-computed table to reduce the amount of ROM required.





Valin, et al.                Standards Track                   [Page 58]

RFC 6716                 Interactive Audio Codec          September 2012


              +----+----------------------------------------+
              | I1 | Codebook (Q8)                          |
              +----+----------------------------------------+
              |    |  0   1   2   3   4   5   6   7   8   9 |
              |    |                                        |
              | 0  | 12  35  60  83 108 132 157 180 206 228 |
              |    |                                        |
              | 1  | 15  32  55  77 101 125 151 175 201 225 |
              |    |                                        |
              | 2  | 19  42  66  89 114 137 162 184 209 230 |
              |    |                                        |
              | 3  | 12  25  50  72  97 120 147 172 200 223 |
              |    |                                        |
              | 4  | 26  44  69  90 114 135 159 180 205 225 |
              |    |                                        |
              | 5  | 13  22  53  80 106 130 156 180 205 228 |
              |    |                                        |
              | 6  | 15  25  44  64  90 115 142 168 196 222 |
              |    |                                        |
              | 7  | 19  24  62  82 100 120 145 168 190 214 |
              |    |                                        |
              | 8  | 22  31  50  79 103 120 151 170 203 227 |
              |    |                                        |
              | 9  | 21  29  45  65 106 124 150 171 196 224 |
              |    |                                        |
              | 10 | 30  49  75  97 121 142 165 186 209 229 |
              |    |                                        |
              | 11 | 19  25  52  70  93 116 143 166 192 219 |
              |    |                                        |
              | 12 | 26  34  62  75  97 118 145 167 194 217 |
              |    |                                        |
              | 13 | 25  33  56  70  91 113 143 165 196 223 |
              |    |                                        |
              | 14 | 21  34  51  72  97 117 145 171 196 222 |
              |    |                                        |
              | 15 | 20  29  50  67  90 117 144 168 197 221 |
              |    |                                        |
              | 16 | 22  31  48  66  95 117 146 168 196 222 |
              |    |                                        |
              | 17 | 24  33  51  77 116 134 158 180 200 224 |
              |    |                                        |
              | 18 | 21  28  70  87 106 124 149 170 194 217 |
              |    |                                        |
              | 19 | 26  33  53  64  83 117 152 173 204 225 |
              |    |                                        |
              | 20 | 27  34  65  95 108 129 155 174 210 225 |
              |    |                                        |
              | 21 | 20  26  72  99 113 131 154 176 200 219 |



Valin, et al.                Standards Track                   [Page 59]

RFC 6716                 Interactive Audio Codec          September 2012


              |    |                                        |
              | 22 | 34  43  61  78  93 114 155 177 205 229 |
              |    |                                        |
              | 23 | 23  29  54  97 124 138 163 179 209 229 |
              |    |                                        |
              | 24 | 30  38  56  89 118 129 158 178 200 231 |
              |    |                                        |
              | 25 | 21  29  49  63  85 111 142 163 193 222 |
              |    |                                        |
              | 26 | 27  48  77 103 133 158 179 196 215 232 |
              |    |                                        |
              | 27 | 29  47  74  99 124 151 176 198 220 237 |
              |    |                                        |
              | 28 | 33  42  61  76  93 121 155 174 207 225 |
              |    |                                        |
              | 29 | 29  53  87 112 136 154 170 188 208 227 |
              |    |                                        |
              | 30 | 24  30  52  84 131 150 166 186 203 229 |
              |    |                                        |
              | 31 | 37  48  64  84 104 118 156 177 201 230 |
              +----+----------------------------------------+

          Table 23: NB/MB Normalized LSF Stage-1 Codebook Vectors

    +----+------------------------------------------------------------+
    | I1 | Codebook (Q8)                                              |
    +----+------------------------------------------------------------+
    |    |  0  1  2  3  4   5   6   7   8   9  10  11  12  13  14  15 |
    |    |                                                            |
    | 0  |  7 23 38 54 69  85 100 116 131 147 162 178 193 208 223 239 |
    |    |                                                            |
    | 1  | 13 25 41 55 69  83  98 112 127 142 157 171 187 203 220 236 |
    |    |                                                            |
    | 2  | 15 21 34 51 61  78  92 106 126 136 152 167 185 205 225 240 |
    |    |                                                            |
    | 3  | 10 21 36 50 63  79  95 110 126 141 157 173 189 205 221 237 |
    |    |                                                            |
    | 4  | 17 20 37 51 59  78  89 107 123 134 150 164 184 205 224 240 |
    |    |                                                            |
    | 5  | 10 15 32 51 67  81  96 112 129 142 158 173 189 204 220 236 |
    |    |                                                            |
    | 6  |  8 21 37 51 65  79  98 113 126 138 155 168 179 192 209 218 |
    |    |                                                            |
    | 7  | 12 15 34 55 63  78  87 108 118 131 148 167 185 203 219 236 |
    |    |                                                            |
    | 8  | 16 19 32 36 56  79  91 108 118 136 154 171 186 204 220 237 |
    |    |                                                            |
    | 9  | 11 28 43 58 74  89 105 120 135 150 165 180 196 211 226 241 |



Valin, et al.                Standards Track                   [Page 60]

RFC 6716                 Interactive Audio Codec          September 2012


    |    |                                                            |
    | 10 |  6 16 33 46 60  75  92 107 123 137 156 169 185 199 214 225 |
    |    |                                                            |
    | 11 | 11 19 30 44 57  74  89 105 121 135 152 169 186 202 218 234 |
    |    |                                                            |
    | 12 | 12 19 29 46 57  71  88 100 120 132 148 165 182 199 216 233 |
    |    |                                                            |
    | 13 | 17 23 35 46 56  77  92 106 123 134 152 167 185 204 222 237 |
    |    |                                                            |
    | 14 | 14 17 45 53 63  75  89 107 115 132 151 171 188 206 221 240 |
    |    |                                                            |
    | 15 |  9 16 29 40 56  71  88 103 119 137 154 171 189 205 222 237 |
    |    |                                                            |
    | 16 | 16 19 36 48 57  76  87 105 118 132 150 167 185 202 218 236 |
    |    |                                                            |
    | 17 | 12 17 29 54 71  81  94 104 126 136 149 164 182 201 221 237 |
    |    |                                                            |
    | 18 | 15 28 47 62 79  97 115 129 142 155 168 180 194 208 223 238 |
    |    |                                                            |
    | 19 |  8 14 30 45 62  78  94 111 127 143 159 175 192 207 223 239 |
    |    |                                                            |
    | 20 | 17 30 49 62 79  92 107 119 132 145 160 174 190 204 220 235 |
    |    |                                                            |
    | 21 | 14 19 36 45 61  76  91 108 121 138 154 172 189 205 222 238 |
    |    |                                                            |
    | 22 | 12 18 31 45 60  76  91 107 123 138 154 171 187 204 221 236 |
    |    |                                                            |
    | 23 | 13 17 31 43 53  70  83 103 114 131 149 167 185 203 220 237 |
    |    |                                                            |
    | 24 | 17 22 35 42 58  78  93 110 125 139 155 170 188 206 224 240 |
    |    |                                                            |
    | 25 |  8 15 34 50 67  83  99 115 131 146 162 178 193 209 224 239 |
    |    |                                                            |
    | 26 | 13 16 41 66 73  86  95 111 128 137 150 163 183 206 225 241 |
    |    |                                                            |
    | 27 | 17 25 37 52 63  75  92 102 119 132 144 160 175 191 212 231 |
    |    |                                                            |
    | 28 | 19 31 49 65 83 100 117 133 147 161 174 187 200 213 227 242 |
    |    |                                                            |
    | 29 | 18 31 52 68 88 103 117 126 138 149 163 177 192 207 223 239 |
    |    |                                                            |
    | 30 | 16 29 47 61 76  90 106 119 133 147 161 176 193 209 224 240 |
    |    |                                                            |
    | 31 | 15 21 35 50 61  73  86  97 110 119 129 141 175 198 218 237 |
    +----+------------------------------------------------------------+

           Table 24: WB Normalized LSF Stage-1 Codebook Vectors




Valin, et al.                Standards Track                   [Page 61]

RFC 6716                 Interactive Audio Codec          September 2012


   Given the stage-1 codebook entry cb1_Q8[], the stage-2 residual
   res_Q10[], and their corresponding weights, w_Q9[], the reconstructed
   normalized LSF coefficients are

      NLSF_Q15[k] = clamp(0,
                     (cb1_Q8[k]<<7) + (res_Q10[k]<<14)/w_Q9[k], 32767)

   where the division is integer division.  However, nothing in either
   the reconstruction process or the quantization process in the encoder
   thus far guarantees that the coefficients are monotonically
   increasing and separated well enough to ensure a stable filter
   [KABAL86].  When using the reference encoder, roughly 2% of frames
   violate this constraint.  The next section describes a stabilization
   procedure used to make these guarantees.

4.2.7.5.4.  Normalized LSF Stabilization


   The normalized LSF stabilization procedure is implemented in
   silk_NLSF_stabilize() (NLSF_stabilize.c).  This process ensures that
   consecutive values of the normalized LSF coefficients, NLSF_Q15[],
   are spaced some minimum distance apart (predetermined to be the 0.01
   percentile of a large training set).  Table 25 gives the minimum
   spacings for NB and MB and those for WB, where row k is the minimum
   allowed value of NLSF_Q15[k]-NLSF_Q15[k-1].  For the purposes of
   computing this spacing for the first and last coefficient,
   NLSF_Q15[-1] is taken to be 0 and NLSF_Q15[d_LPC] is taken to be
   32768.
























Valin, et al.                Standards Track                   [Page 62]

RFC 6716                 Interactive Audio Codec          September 2012


                     +-------------+-----------+-----+
                     | Coefficient | NB and MB |  WB |
                     +-------------+-----------+-----+
                     | 0           |       250 | 100 |
                     |             |           |     |
                     | 1           |         3 |   3 |
                     |             |           |     |
                     | 2           |         6 |  40 |
                     |             |           |     |
                     | 3           |         3 |   3 |
                     |             |           |     |
                     | 4           |         3 |   3 |
                     |             |           |     |
                     | 5           |         3 |   3 |
                     |             |           |     |
                     | 6           |         4 |   5 |
                     |             |           |     |
                     | 7           |         3 |  14 |
                     |             |           |     |
                     | 8           |         3 |  14 |
                     |             |           |     |
                     | 9           |         3 |  10 |
                     |             |           |     |
                     | 10          |       461 |  11 |
                     |             |           |     |
                     | 11          |           |   3 |
                     |             |           |     |
                     | 12          |           |   8 |
                     |             |           |     |
                     | 13          |           |   9 |
                     |             |           |     |
                     | 14          |           |   7 |
                     |             |           |     |
                     | 15          |           |   3 |
                     |             |           |     |
                     | 16          |           | 347 |
                     +-------------+-----------+-----+

         Table 25: Minimum Spacing for Normalized LSF Coefficients

   The procedure starts off by trying to make small adjustments that
   attempt to minimize the amount of distortion introduced.  After 20
   such adjustments, it falls back to a more direct method that
   guarantees the constraints are enforced but may require large
   adjustments.






Valin, et al.                Standards Track                   [Page 63]

RFC 6716                 Interactive Audio Codec          September 2012


   Let NDeltaMin_Q15[k] be the minimum required spacing for the current
   audio bandwidth from Table 25.  First, the procedure finds the index
   i where NLSF_Q15[i] - NLSF_Q15[i-1] - NDeltaMin_Q15[i] is the
   smallest, breaking ties by using the lower value of i.  If this value
   is non-negative, then the stabilization stops; the coefficients
   satisfy all the constraints.  Otherwise, if i == 0, it sets
   NLSF_Q15[0] to NDeltaMin_Q15[0], and if i == d_LPC, it sets
   NLSF_Q15[d_LPC-1] to (32768 - NDeltaMin_Q15[d_LPC]).  For all other
   values of i, both NLSF_Q15[i-1] and NLSF_Q15[i] are updated as
   follows:

                                             i-1
                                             __
    min_center_Q15 = (NDeltaMin_Q15[i]>>1) + \  NDeltaMin_Q15[k]
                                             /_
                                             k=0
                                                    d_LPC
                                                     __
    max_center_Q15 = 32768 - (NDeltaMin_Q15[i]>>1) - \  NDeltaMin_Q15[k]
                                                     /_
                                                    k=i+1
   center_freq_Q15 = clamp(min_center_Q15[i],
                           (NLSF_Q15[i-1] + NLSF_Q15[i] + 1)>>1
                           max_center_Q15[i])

    NLSF_Q15[i-1] = center_freq_Q15 - (NDeltaMin_Q15[i]>>1)

      NLSF_Q15[i] = NLSF_Q15[i-1] + NDeltaMin_Q15[i]

   Then, the procedure repeats again, until it has either executed 20
   times or stopped because the coefficients satisfy all the
   constraints.

   After the 20th repetition of the above procedure, the following
   fallback procedure executes once.  First, the values of NLSF_Q15[k]
   for 0 <= k < d_LPC are sorted in ascending order.  Then, for each
   value of k from 0 to d_LPC-1, NLSF_Q15[k] is set to

             max(NLSF_Q15[k], NLSF_Q15[k-1] + NDeltaMin_Q15[k])

   Next, for each value of k from d_LPC-1 down to 0, NLSF_Q15[k] is set
   to

            min(NLSF_Q15[k], NLSF_Q15[k+1] - NDeltaMin_Q15[k+1])

   There is no need to check if the coefficients satisfy all the
   constraints before applying this fallback procedure.  If they do,
   then it will not change their values.



Valin, et al.                Standards Track                   [Page 64]

RFC 6716                 Interactive Audio Codec          September 2012


4.2.7.5.5.  Normalized LSF Interpolation


   For 20 ms SILK frames, the first half of the frame (i.e., the first
   two subframes) may use normalized LSF coefficients that are
   interpolated between the decoded LSFs for the most recent coded frame
   (in the same channel) and the current frame.  A Q2 interpolation
   factor follows the LSF coefficient indices in the bitstream, which is
   decoded using the PDF in Table 26.  This happens in
   silk_decode_indices() (decode_indices.c).  After either

   o  An uncoded regular SILK frame in the side channel, or

   o  A decoder reset (see Section 4.5.2),

   the decoder still decodes this factor, but ignores its value and
   always uses 4 instead.  For 10 ms SILK frames, this factor is not
   stored at all.

                       +---------------------------+
                       | PDF                       |
                       +---------------------------+
                       | {13, 22, 29, 11, 181}/256 |
                       +---------------------------+

           Table 26: PDF for Normalized LSF Interpolation Index

   Let n2_Q15[k] be the normalized LSF coefficients decoded by the
   procedure in Section 4.2.7.5, n0_Q15[k] be the LSF coefficients
   decoded for the prior frame, and w_Q2 be the interpolation factor.
   Then, the normalized LSF coefficients used for the first half of a
   20 ms frame, n1_Q15[k], are

        n1_Q15[k] = n0_Q15[k] + (w_Q2*(n2_Q15[k] - n0_Q15[k]) >> 2)

   This interpolation is performed in silk_decode_parameters()
   (decode_parameters.c).

4.2.7.5.6.  Converting Normalized LSFs to LPC Coefficients


   Any LPC filter A(z) can be split into a symmetric part P(z) and an
   anti-symmetric part Q(z) such that

                          d_LPC
                           __         -k   1
                A(z) = 1 - \  a[k] * z   = - * (P(z) + Q(z))
                           /_              2
                           k=1




Valin, et al.                Standards Track                   [Page 65]

RFC 6716                 Interactive Audio Codec          September 2012


   with

                                     -d_LPC-1      -1
                      P(z) = A(z) + z         * A(z  )

                                     -d_LPC-1      -1
                      Q(z) = A(z) - z         * A(z  )

   The even normalized LSF coefficients correspond to a pair of
   conjugate roots of P(z), while the odd coefficients correspond to a
   pair of conjugate roots of Q(z), all of which lie on the unit circle.
   In addition, P(z) has a root at pi and Q(z) has a root at 0.  Thus,
   they may be reconstructed mathematically from a set of normalized LSF
   coefficients, n[k], as

                          d_LPC/2-1
                      -1     ___                        -1    -2
         P(z) = (1 + z  ) *  | |  (1 - 2*cos(pi*n[2*k])*z  + z  )
                             k=0

                          d_LPC/2-1
                      -1     ___                          -1    -2
         Q(z) = (1 - z  ) *  | |  (1 - 2*cos(pi*n[2*k+1])*z  + z  )
                             k=0

   However, SILK performs this reconstruction using a fixed-point
   approximation so that all decoders can reproduce it in a bit-exact
   manner to avoid prediction drift.  The function silk_NLSF2A()
   (NLSF2A.c) implements this procedure.

   To start, it approximates cos(pi*n[k]) using a table lookup with
   linear interpolation.  The encoder SHOULD use the inverse of this
   piecewise linear approximation, rather than the true inverse of the
   cosine function, when deriving the normalized LSF coefficients.
   These values are also re-ordered to improve numerical accuracy when
   constructing the LPC polynomials.















Valin, et al.                Standards Track                   [Page 66]

RFC 6716                 Interactive Audio Codec          September 2012


                     +-------------+-----------+----+
                     | Coefficient | NB and MB | WB |
                     +-------------+-----------+----+
                     | 0           |         0 |  0 |
                     |             |           |    |
                     | 1           |         9 | 15 |
                     |             |           |    |
                     | 2           |         6 |  8 |
                     |             |           |    |
                     | 3           |         3 |  7 |
                     |             |           |    |
                     | 4           |         4 |  4 |
                     |             |           |    |
                     | 5           |         5 | 11 |
                     |             |           |    |
                     | 6           |         8 | 12 |
                     |             |           |    |
                     | 7           |         1 |  3 |
                     |             |           |    |
                     | 8           |         2 |  2 |
                     |             |           |    |
                     | 9           |         7 | 13 |
                     |             |           |    |
                     | 10          |           | 10 |
                     |             |           |    |
                     | 11          |           |  5 |
                     |             |           |    |
                     | 12          |           |  6 |
                     |             |           |    |
                     | 13          |           |  9 |
                     |             |           |    |
                     | 14          |           | 14 |
                     |             |           |    |
                     | 15          |           |  1 |
                     +-------------+-----------+----+

             Table 27: LSF Ordering for Polynomial Evaluation

   The top 7 bits of each normalized LSF coefficient index a value in
   the table, and the next 8 bits interpolate between it and the next
   value.  Let i = (n[k] >> 8) be the integer index and f = (n[k] & 255)
   be the fractional part of a given coefficient.  Then, the re-ordered,
   approximated cosine, c_Q17[ordering[k]], is

       c_Q17[ordering[k]] = (cos_Q12[i]*256
                             + (cos_Q12[i+1]-cos_Q12[i])*f + 4) >> 3





Valin, et al.                Standards Track                   [Page 67]

RFC 6716                 Interactive Audio Codec          September 2012


   where ordering[k] is the k'th entry of the column of Table 27
   corresponding to the current audio bandwidth and cos_Q12[i] is the
   i'th entry of Table 28.

                  +-----+-------+-------+-------+-------+
                  |   i |    +0 |    +1 |    +2 |    +3 |
                  +-----+-------+-------+-------+-------+
                  |   0 |  4096 |  4095 |  4091 |  4085 |
                  |     |       |       |       |       |
                  |   4 |  4076 |  4065 |  4052 |  4036 |
                  |     |       |       |       |       |
                  |   8 |  4017 |  3997 |  3973 |  3948 |
                  |     |       |       |       |       |
                  |  12 |  3920 |  3889 |  3857 |  3822 |
                  |     |       |       |       |       |
                  |  16 |  3784 |  3745 |  3703 |  3659 |
                  |     |       |       |       |       |
                  |  20 |  3613 |  3564 |  3513 |  3461 |
                  |     |       |       |       |       |
                  |  24 |  3406 |  3349 |  3290 |  3229 |
                  |     |       |       |       |       |
                  |  28 |  3166 |  3102 |  3035 |  2967 |
                  |     |       |       |       |       |
                  |  32 |  2896 |  2824 |  2751 |  2676 |
                  |     |       |       |       |       |
                  |  36 |  2599 |  2520 |  2440 |  2359 |
                  |     |       |       |       |       |
                  |  40 |  2276 |  2191 |  2106 |  2019 |
                  |     |       |       |       |       |
                  |  44 |  1931 |  1842 |  1751 |  1660 |
                  |     |       |       |       |       |
                  |  48 |  1568 |  1474 |  1380 |  1285 |
                  |     |       |       |       |       |
                  |  52 |  1189 |  1093 |   995 |   897 |
                  |     |       |       |       |       |
                  |  56 |   799 |   700 |   601 |   501 |
                  |     |       |       |       |       |
                  |  60 |   401 |   301 |   201 |   101 |
                  |     |       |       |       |       |
                  |  64 |     0 |  -101 |  -201 |  -301 |
                  |     |       |       |       |       |
                  |  68 |  -401 |  -501 |  -601 |  -700 |
                  |     |       |       |       |       |
                  |  72 |  -799 |  -897 |  -995 | -1093 |
                  |     |       |       |       |       |
                  |  76 | -1189 | -1285 | -1380 | -1474 |
                  |     |       |       |       |       |
                  |  80 | -1568 | -1660 | -1751 | -1842 |



Valin, et al.                Standards Track                   [Page 68]

RFC 6716                 Interactive Audio Codec          September 2012


                  |     |       |       |       |       |
                  |  84 | -1931 | -2019 | -2106 | -2191 |
                  |     |       |       |       |       |
                  |  88 | -2276 | -2359 | -2440 | -2520 |
                  |     |       |       |       |       |
                  |  92 | -2599 | -2676 | -2751 | -2824 |
                  |     |       |       |       |       |
                  |  96 | -2896 | -2967 | -3035 | -3102 |
                  |     |       |       |       |       |
                  | 100 | -3166 | -3229 | -3290 | -3349 |
                  |     |       |       |       |       |
                  | 104 | -3406 | -3461 | -3513 | -3564 |
                  |     |       |       |       |       |
                  | 108 | -3613 | -3659 | -3703 | -3745 |
                  |     |       |       |       |       |
                  | 112 | -3784 | -3822 | -3857 | -3889 |
                  |     |       |       |       |       |
                  | 116 | -3920 | -3948 | -3973 | -3997 |
                  |     |       |       |       |       |
                  | 120 | -4017 | -4036 | -4052 | -4065 |
                  |     |       |       |       |       |
                  | 124 | -4076 | -4085 | -4091 | -4095 |
                  |     |       |       |       |       |
                  | 128 | -4096 |       |       |       |
                  +-----+-------+-------+-------+-------+

               Table 28: Q12 Cosine Table for LSF Conversion

   Given the list of cosine values, silk_NLSF2A_find_poly() (NLSF2A.c)
   computes the coefficients of P and Q, described here via a simple
   recurrence.  Let p_Q16[k][j] and q_Q16[k][j] be the coefficients of
   the products of the first (k+1) root pairs for P and Q, with j
   indexing the coefficient number.  Only the first (k+2) coefficients
   are needed, as the products are symmetric.  Let
   p_Q16[0][0] = q_Q16[0][0] = 1<<16, p_Q16[0][1] = -c_Q17[0],
   q_Q16[0][1] = -c_Q17[1], and d2 = d_LPC/2.  As boundary conditions,
   assume p_Q16[k][j] = q_Q16[k][j] = 0 for all j < 0.  Also, assume
   p_Q16[k][k+2] = p_Q16[k][k] and q_Q16[k][k+2] = q_Q16[k][k] (because
   of the symmetry).  Then, for 0 < k < d2 and 0 <= j <= k+1,

        p_Q16[k][j] = p_Q16[k-1][j] + p_Q16[k-1][j-2]
                      - ((c_Q17[2*k]*p_Q16[k-1][j-1] + 32768)>>16)

        q_Q16[k][j] = q_Q16[k-1][j] + q_Q16[k-1][j-2]
                      - ((c_Q17[2*k+1]*q_Q16[k-1][j-1] + 32768)>>16)






Valin, et al.                Standards Track                   [Page 69]

RFC 6716                 Interactive Audio Codec          September 2012


   The use of Q17 values for the cosine terms in an otherwise Q16
   expression implicitly scales them by a factor of 2.  The
   multiplications in this recurrence may require up to 48 bits of
   precision in the result to avoid overflow.  In practice, each row of
   the recurrence only depends on the previous row, so an implementation
   does not need to store all of them.

   silk_NLSF2A() uses the values from the last row of this recurrence to
   reconstruct a 32-bit version of the LPC filter (without the leading
   1.0 coefficient), a32_Q17[k], 0 <= k < d2:

        a32_Q17[k]         = -(q_Q16[d2-1][k+1] - q_Q16[d2-1][k])
                             - (p_Q16[d2-1][k+1] + p_Q16[d2-1][k]))

        a32_Q17[d_LPC-k-1] =  (q_Q16[d2-1][k+1] - q_Q16[d2-1][k])
                             - (p_Q16[d2-1][k+1] + p_Q16[d2-1][k]))

   The sum and difference of two terms from each of the p_Q16 and q_Q16
   coefficient lists reflect the (1 + z**-1) and (1 - z**-1) factors of
   P and Q, respectively.  The promotion of the expression from Q16 to
   Q17 implicitly scales the result by 1/2.

4.2.7.5.7.  Limiting the Range of the LPC Coefficients


   The a32_Q17[] coefficients are too large to fit in a 16-bit value,
   which significantly increases the cost of applying this filter in
   fixed-point decoders.  Reducing them to Q12 precision doesn't incur
   any significant quality loss, but still does not guarantee they will
   fit. silk_NLSF2A() applies up to 10 rounds of bandwidth expansion to
   limit the dynamic range of these coefficients.  Even floating-point
   decoders SHOULD perform these steps, to avoid mismatch.

   For each round, the process first finds the index k such that
   abs(a32_Q17[k]) is largest, breaking ties by choosing the lowest
   value of k.  Then, it computes the corresponding Q12 precision value,
   maxabs_Q12, subject to an upper bound to avoid overflow in subsequent
   computations:

              maxabs_Q12 = min((maxabs_Q17 + 16) >> 5, 163838)

   If this is larger than 32767, the procedure derives the chirp factor,
   sc_Q16[0], to use in the bandwidth expansion as

                                   (maxabs_Q12 - 32767) << 14
               sc_Q16[0] = 65470 - --------------------------
                                   (maxabs_Q12 * (k+1)) >> 2





Valin, et al.                Standards Track                   [Page 70]

RFC 6716                 Interactive Audio Codec          September 2012


   where the division here is integer division.  This is an
   approximation of the chirp factor needed to reduce the target
   coefficient to 32767, though it is both less than 0.999 and, for
   k > 0 when maxabs_Q12 is much greater than 32767, still slightly too
   large.  The upper bound on maxabs_Q12, 163838, was chosen because it
   is equal to ((2**31 - 1) >> 14) + 32767, i.e., the largest value of
   maxabs_Q12 that would not overflow the numerator in the equation
   above when stored in a signed 32-bit integer.

   silk_bwexpander_32() (bwexpander_32.c) performs the bandwidth
   expansion (again, only when maxabs_Q12 is greater than 32767) using
   the following recurrence:

              a32_Q17[k] = (a32_Q17[k]*sc_Q16[k]) >> 16

             sc_Q16[k+1] = (sc_Q16[0]*sc_Q16[k] + 32768) >> 16

   The first multiply may require up to 48 bits of precision in the
   result to avoid overflow.  The second multiply must be unsigned to
   avoid overflow with only 32 bits of precision.  The reference
   implementation uses a slightly more complex formulation that avoids
   the 32-bit overflow using signed multiplication, but is otherwise
   equivalent.

   After 10 rounds of bandwidth expansion are performed, they are simply
   saturated to 16 bits:

       a32_Q17[k] = clamp(-32768, (a32_Q17[k] + 16) >> 5, 32767) << 5

   Because this performs the actual saturation in the Q12 domain, but
   converts the coefficients back to the Q17 domain for the purposes of
   prediction gain limiting, this step must be performed after the 10th
   round of bandwidth expansion, regardless of whether or not the Q12
   version of any coefficient still overflows a 16-bit integer.  This
   saturation is not performed if maxabs_Q12 drops to 32767 or less
   prior to the 10th round.

4.2.7.5.8.  Limiting the Prediction Gain of the LPC Filter


   The prediction gain of an LPC synthesis filter is the square root of
   the output energy when the filter is excited by a unit-energy
   impulse.  Even if the Q12 coefficients would fit, the resulting
   filter may still have a significant gain (especially for voiced
   sounds), making the filter unstable. silk_NLSF2A() applies up to 16
   additional rounds of bandwidth expansion to limit the prediction
   gain.  Instead of controlling the amount of bandwidth expansion using
   the prediction gain itself (which may diverge to infinity for an
   unstable filter), silk_NLSF2A() uses silk_LPC_inverse_pred_gain_QA()



Valin, et al.                Standards Track                   [Page 71]

RFC 6716                 Interactive Audio Codec          September 2012


   (LPC_inv_pred_gain.c) to compute the reflection coefficients
   associated with the filter.  The filter is stable if and only if the
   magnitude of these coefficients is sufficiently less than one.  The
   reflection coefficients, rc[k], can be computed using a simple
   Levinson recurrence, initialized with the LPC coefficients a[d_LPC-
   1][n] = a[n], and then updated via

                      rc[k] = -a[k][k] ,

                              a[k][n] - a[k][k-n-1]*rc[k]
                  a[k-1][n] = ---------------------------
                                               2
                                      1 - rc[k]

   However, silk_LPC_inverse_pred_gain_QA() approximates this using
   fixed-point arithmetic to guarantee reproducible results across
   platforms and implementations.  Since small changes in the
   coefficients can make a stable filter unstable, it takes the real Q12
   coefficients that will be used during reconstruction as input.  Thus,
   let

                    a32_Q12[n] = (a32_Q17[n] + 16) >> 5

   be the Q12 version of the LPC coefficients that will eventually be
   used.  As a simple initial check, the decoder computes the DC
   response as

                                  d_PLC-1
                                    __
                          DC_resp = \   a32_Q12[n]
                                    /_
                                    n=0

   and if DC_resp > 4096, the filter is unstable.

   Increasing the precision of these Q12 coefficients to Q24 for
   intermediate computations allows more accurate computation of the
   reflection coefficients, so the decoder initializes the recurrence
   via

                   inv_gain_Q30[d_LPC] = 1 << 30

                   a32_Q24[d_LPC-1][n] = a32_Q12[n] << 12








Valin, et al.                Standards Track                   [Page 72]

RFC 6716                 Interactive Audio Codec          September 2012


   Then, for each k from d_LPC-1 down to 0, if
   abs(a32_Q24[k][k]) > 16773022, the filter is unstable and the
   recurrence stops.  The constant 16773022 here is approximately
   0.99975 in Q24.  Otherwise, the inverse of the prediction gain,
   inv_gain_Q30[k], is updated via

              rc_Q31[k] = -a32_Q24[k][k] << 7

             div_Q30[k] = (1<<30) - (rc_Q31[k]*rc_Q31[k] >> 32)

        inv_gain_Q30[k] = (inv_gain_Q30[k+1]*div_Q30[k] >> 32) << 2

   and if inv_gain_Q30[k] < 107374, the filter is unstable and the
   recurrence stops.  The constant 107374 here is approximately 1/10000
   in Q30.  If neither of these checks determine that the filter is
   unstable and k > 0, row k-1 of a32_Q24 is computed from row k as

              b1[k] = ilog(div_Q30[k])

              b2[k] = b1[k] - 16

                            (1<<29) - 1
         inv_Qb2[k] = -----------------------
                      div_Q30[k] >> (b2[k]+1)

         err_Q29[k] = (1<<29)
                      - ((div_Q30[k]<<(15-b2[k]))*inv_Qb2[k] >> 16)

        gain_Qb1[k] = ((inv_Qb2[k] << 16)
                       + (err_Q29[k]*inv_Qb2[k] >> 13))

    num_Q24[k-1][n] = a32_Q24[k][n]
                      - ((a32_Q24[k][k-n-1]*rc_Q31[k] + (1<<30)) >> 31)

    a32_Q24[k-1][n] = (num_Q24[k-1][n]*gain_Qb1[k]
                       + (1<<(b1[k]-1))) >> b1[k]

   where 0 <= n < k.  In the above, rc_Q31[k] are the reflection
   coefficients. div_Q30[k] is the denominator for each iteration, and
   gain_Qb1[k] is its multiplicative inverse (with b1[k] fractional
   bits, where b1[k] ranges from 20 to 31). inv_Qb2[k], which ranges
   from 16384 to 32767, is a low-precision version of that inverse (with
   b2[k] fractional bits). err_Q29[k] is the residual error, ranging
   from -32763 to 32392, which is used to improve the accuracy.  The
   values t_Q24[k-1][n] for each n are the numerators for the next row
   of coefficients in the recursion, and a32_Q24[k-1][n] is the final
   version of that row.  Every multiply in this procedure except the one
   used to compute gain_Qb1[k] requires more than 32 bits of precision,



Valin, et al.                Standards Track                   [Page 73]

RFC 6716                 Interactive Audio Codec          September 2012


   but otherwise all intermediate results fit in 32 bits or less.  In
   practice, because each row only depends on the next one, an
   implementation does not need to store them all.

   If abs(a32_Q24[k][k]) <= 16773022 and inv_gain_Q30[k] >= 107374 for
   0 <= k < d_LPC, then the filter is considered stable.  However, the
   problem of determining stability is ill-conditioned when the filter
   contains several reflection coefficients whose magnitude is very
   close to one.  This fixed-point algorithm is not mathematically
   guaranteed to correctly classify filters as stable or unstable in
   this case, though it does very well in practice.

   On round i, 0 <= i < 16, if the filter passes these stability checks,
   then this procedure stops, and the final LPC coefficients to use for
   reconstruction in Section 4.2.7.9.2 are

                     a_Q12[k] = (a32_Q17[k] + 16) >> 5

   Otherwise, a round of bandwidth expansion is applied using the same
   procedure as in Section 4.2.7.5.7, with

                         sc_Q16[0] = 65536 - (2<<i)

   During round 15, sc_Q16[0] becomes 0 in the above equation, so
   a_Q12[k] is set to 0 for all k, guaranteeing a stable filter.

4.2.7.6.  Long-Term Prediction (LTP) Parameters



   After the normalized LSF indices and, for 20 ms frames, the LSF
   interpolation index, voiced frames (see Section 4.2.7.3) include
   additional LTP parameters.  There is one primary lag index for each
   SILK frame, but this is refined to produce a separate lag index per
   subframe using a vector quantizer.  Each subframe also gets its own
   prediction gain coefficient.

4.2.7.6.1.  Pitch Lags


   The primary lag index is coded either relative to the primary lag of
   the prior frame in the same channel or as an absolute index.
   Absolute coding is used if and only if

   o  This is the first SILK frame of its type (LBRR or regular) for
      this channel in the current Opus frame,

   o  The previous SILK frame of the same type (LBRR or regular) for
      this channel in the same Opus frame was not coded, or





Valin, et al.                Standards Track                   [Page 74]

RFC 6716                 Interactive Audio Codec          September 2012


   o  That previous SILK frame was coded, but was not voiced (see
      Section 4.2.7.3).

   With absolute coding, the primary pitch lag may range from 2 ms
   (inclusive) up to 18 ms (exclusive), corresponding to pitches from
   500 Hz down to 55.6 Hz, respectively.  It is comprised of a high part
   and a low part, where the decoder first reads the high part using the
   32-entry codebook in Table 29 and then the low part using the
   codebook corresponding to the current audio bandwidth from Table 30.
   The final primary pitch lag is then

                lag = lag_high*lag_scale + lag_low + lag_min

   where lag_high is the high part, lag_low is the low part, and
   lag_scale and lag_min are the values from the "Scale" and "Minimum
   Lag" columns of Table 30, respectively.

   +-------------------------------------------------------------------+
   | PDF                                                               |
   +-------------------------------------------------------------------+
   | {3, 3, 6, 11, 21, 30, 32, 19, 11, 10, 12, 13, 13, 12, 11, 9, 8,   |
   | 7, 6, 4, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256                  |
   +-------------------------------------------------------------------+

             Table 29: PDF for High Part of Primary Pitch Lag

   +------------+------------------------+-------+----------+----------+
   | Audio      | PDF                    | Scale | Minimum  | Maximum  |
   | Bandwidth  |                        |       | Lag      | Lag      |
   +------------+------------------------+-------+----------+----------+
   | NB         | {64, 64, 64, 64}/256   | 4     | 16       | 144      |
   |            |                        |       |          |          |
   | MB         | {43, 42, 43, 43, 42,   | 6     | 24       | 216      |
   |            | 43}/256                |       |          |          |
   |            |                        |       |          |          |
   | WB         | {32, 32, 32, 32, 32,   | 8     | 32       | 288      |
   |            | 32, 32, 32}/256        |       |          |          |
   +------------+------------------------+-------+----------+----------+

              Table 30: PDF for Low Part of Primary Pitch Lag

   All frames that do not use absolute coding for the primary lag index
   use relative coding instead.  The decoder reads a single delta value
   using the 21-entry PDF in Table 31.  If the resulting value is zero,
   it falls back to the absolute coding procedure from the prior
   paragraph.  Otherwise, the final primary pitch lag is then

                 lag = previous_lag + (delta_lag_index - 9)



Valin, et al.                Standards Track                   [Page 75]

RFC 6716                 Interactive Audio Codec          September 2012


   where previous_lag is the primary pitch lag from the most recent
   frame in the same channel and delta_lag_index is the value just
   decoded.  This allows a per-frame change in the pitch lag of -8 to
   +11 samples.  The decoder does no clamping at this point, so this
   value can fall outside the range of 2 ms to 18 ms, and the decoder
   must use this unclamped value when using relative coding in the next
   SILK frame (if any).  However, because an Opus frame can use relative
   coding for at most two consecutive SILK frames, integer overflow
   should not be an issue.

   +-------------------------------------------------------------------+
   | PDF                                                               |
   +-------------------------------------------------------------------+
   | {46, 2, 2, 3, 4, 6, 10, 15, 26, 38, 30, 22, 15, 10, 7, 6, 4, 4,   |
   | 2, 2, 2}/256                                                      |
   +-------------------------------------------------------------------+

                Table 31: PDF for Primary Pitch Lag Change

   After the primary pitch lag, a "pitch contour", stored as a single
   entry from one of four small VQ codebooks, gives lag offsets for each
   subframe in the current SILK frame.  The codebook index is decoded
   using one of the PDFs in Table 32 depending on the current frame size
   and audio bandwidth.  Tables 33 through 36 give the corresponding
   offsets to apply to the primary pitch lag for each subframe given the
   decoded codebook index.

   +-----------+--------+----------+-----------------------------------+
   | Audio     | SILK   | Codebook | PDF                               |
   | Bandwidth | Frame  |     Size |                                   |
   |           | Size   |          |                                   |
   +-----------+--------+----------+-----------------------------------+
   | NB        | 10 ms  |        3 | {143, 50, 63}/256                 |
   |           |        |          |                                   |
   | NB        | 20 ms  |       11 | {68, 12, 21, 17, 19, 22, 30, 24,  |
   |           |        |          | 17, 16, 10}/256                   |
   |           |        |          |                                   |
   | MB or WB  | 10 ms  |       12 | {91, 46, 39, 19, 14, 12, 8, 7, 6, |
   |           |        |          | 5, 5, 4}/256                      |
   |           |        |          |                                   |
   | MB or WB  | 20 ms  |       34 | {33, 22, 18, 16, 15, 14, 14, 13,  |
   |           |        |          | 13, 10, 9, 9, 8, 6, 6, 6, 5, 4,   |
   |           |        |          | 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2,  |
   |           |        |          | 2, 1, 1, 1, 1}/256                |
   +-----------+--------+----------+-----------------------------------+

                 Table 32: PDFs for Subframe Pitch Contour




Valin, et al.                Standards Track                   [Page 76]

RFC 6716                 Interactive Audio Codec          September 2012


                       +-------+------------------+
                       | Index | Subframe Offsets |
                       +-------+------------------+
                       | 0     |             0  0 |
                       |       |                  |
                       | 1     |             1  0 |
                       |       |                  |
                       | 2     |             0  1 |
                       +-------+------------------+

          Table 33: Codebook Vectors for Subframe Pitch Contour:
                             NB, 10 ms Frames

                       +-------+------------------+
                       | Index | Subframe Offsets |
                       +-------+------------------+
                       | 0     |       0  0  0  0 |
                       |       |                  |
                       | 1     |       2  1  0 -1 |
                       |       |                  |
                       | 2     |      -1  0  1  2 |
                       |       |                  |
                       | 3     |      -1  0  0  1 |
                       |       |                  |
                       | 4     |      -1  0  0  0 |
                       |       |                  |
                       | 5     |       0  0  0  1 |
                       |       |                  |
                       | 6     |       0  0  1  1 |
                       |       |                  |
                       | 7     |       1  1  0  0 |
                       |       |                  |
                       | 8     |       1  0  0  0 |
                       |       |                  |
                       | 9     |       0  0  0 -1 |
                       |       |                  |
                       | 10    |       1  0  0 -1 |
                       +-------+------------------+

          Table 34: Codebook Vectors for Subframe Pitch Contour:
                             NB, 20 ms Frames










Valin, et al.                Standards Track                   [Page 77]

RFC 6716                 Interactive Audio Codec          September 2012


                       +-------+------------------+
                       | Index | Subframe Offsets |
                       +-------+------------------+
                       | 0     |             0  0 |
                       |       |                  |
                       | 1     |             0  1 |
                       |       |                  |
                       | 2     |             1  0 |
                       |       |                  |
                       | 3     |            -1  1 |
                       |       |                  |
                       | 4     |             1 -1 |
                       |       |                  |
                       | 5     |            -1  2 |
                       |       |                  |
                       | 6     |             2 -1 |
                       |       |                  |
                       | 7     |            -2  2 |
                       |       |                  |
                       | 8     |             2 -2 |
                       |       |                  |
                       | 9     |            -2  3 |
                       |       |                  |
                       | 10    |             3 -2 |
                       |       |                  |
                       | 11    |            -3  3 |
                       +-------+------------------+

     Table 35: Codebook Vectors for Subframe Pitch Contour: MB or WB,
                               10 ms Frames

                       +-------+------------------+
                       | Index | Subframe Offsets |
                       +-------+------------------+
                       | 0     |       0  0  0  0 |
                       |       |                  |
                       | 1     |       0  0  1  1 |
                       |       |                  |
                       | 2     |       1  1  0  0 |
                       |       |                  |
                       | 3     |      -1  0  0  0 |
                       |       |                  |
                       | 4     |       0  0  0  1 |
                       |       |                  |
                       | 5     |       1  0  0  0 |
                       |       |                  |
                       | 6     |      -1  0  0  1 |
                       |       |                  |



Valin, et al.                Standards Track                   [Page 78]

RFC 6716                 Interactive Audio Codec          September 2012


                       | 7     |       0  0  0 -1 |
                       |       |                  |
                       | 8     |      -1  0  1  2 |
                       |       |                  |
                       | 9     |       1  0  0 -1 |
                       |       |                  |
                       | 10    |      -2 -1  1  2 |
                       |       |                  |
                       | 11    |       2  1  0 -1 |
                       |       |                  |
                       | 12    |      -2  0  0  2 |
                       |       |                  |
                       | 13    |      -2  0  1  3 |
                       |       |                  |
                       | 14    |       2  1 -1 -2 |
                       |       |                  |
                       | 15    |      -3 -1  1  3 |
                       |       |                  |
                       | 16    |       2  0  0 -2 |
                       |       |                  |
                       | 17    |       3  1  0 -2 |
                       |       |                  |
                       | 18    |      -3 -1  2  4 |
                       |       |                  |
                       | 19    |      -4 -1  1  4 |
                       |       |                  |
                       | 20    |       3  1 -1 -3 |
                       |       |                  |
                       | 21    |      -4 -1  2  5 |
                       |       |                  |
                       | 22    |       4  2 -1 -3 |
                       |       |                  |
                       | 23    |       4  1 -1 -4 |
                       |       |                  |
                       | 24    |      -5 -1  2  6 |
                       |       |                  |
                       | 25    |       5  2 -1 -4 |
                       |       |                  |
                       | 26    |      -6 -2  2  6 |
                       |       |                  |
                       | 27    |      -5 -2  2  5 |
                       |       |                  |
                       | 28    |       6  2 -1 -5 |
                       |       |                  |
                       | 29    |      -7 -2  3  8 |
                       |       |                  |
                       | 30    |       6  2 -2 -6 |
                       |       |                  |



Valin, et al.                Standards Track                   [Page 79]

RFC 6716                 Interactive Audio Codec          September 2012


                       | 31    |       5  2 -2 -5 |
                       |       |                  |
                       | 32    |       8  3 -2 -7 |
                       |       |                  |
                       | 33    |      -9 -3  3  9 |
                       +-------+------------------+

     Table 36: Codebook Vectors for Subframe Pitch Contour: MB or WB,
                               20 ms Frames

   The final pitch lag for each subframe is assembled in
   silk_decode_pitch() (decode_pitch.c).  Let lag be the primary pitch
   lag for the current SILK frame, contour_index be index of the VQ
   codebook, and lag_cb[contour_index][k] be the corresponding entry of
   the codebook from the appropriate table given above for the k'th
   subframe.  Then the final pitch lag for that subframe is

       pitch_lags[k] = clamp(lag_min, lag + lag_cb[contour_index][k],
                             lag_max)

   where lag_min and lag_max are the values from the "Minimum Lag" and
   "Maximum Lag" columns of Table 30, respectively.

4.2.7.6.2.  LTP Filter Coefficients


   SILK uses a separate 5-tap pitch filter for each subframe, selected
   from one of three codebooks.  The three codebooks each represent
   different rate-distortion trade-offs, with average rates of
   1.61 bits/subframe, 3.68 bits/subframe, and 4.85 bits/subframe,
   respectively.

   The importance of the filter coefficients generally depends on two
   factors: the periodicity of the signal and relative energy between
   the current subframe and the signal from one period earlier.  Greater
   periodicity and decaying energy both lead to more important filter
   coefficients.  Thus, they should be coded with lower distortion and
   higher rate.  These properties are relatively stable over the
   duration of a single SILK frame.  Hence, all of the subframes in a
   SILK frame choose their filter from the same codebook.  This is
   signaled with an explicitly-coded "periodicity index".  This
   immediately follows the subframe pitch lags, and is coded using the
   3-entry PDF from Table 37.









Valin, et al.                Standards Track                   [Page 80]

RFC 6716                 Interactive Audio Codec          September 2012


                           +------------------+
                           | PDF              |
                           +------------------+
                           | {77, 80, 99}/256 |
                           +------------------+

                      Table 37: Periodicity Index PDF

   The indices of the filters for each subframe follow.  They are all
   coded using the PDF from Table 38 corresponding to the periodicity
   index.  Tables 39 through 41 contain the corresponding filter taps as
   signed Q7 integers.

   +-------------+----------+------------------------------------------+
   | Periodicity | Codebook | PDF                                      |
   | Index       |     Size |                                          |
   +-------------+----------+------------------------------------------+
   | 0           |        8 | {185, 15, 13, 13, 9, 9, 6, 6}/256        |
   |             |          |                                          |
   | 1           |       16 | {57, 34, 21, 20, 15, 13, 12, 13, 10, 10, |
   |             |          | 9, 10, 9, 8, 7, 8}/256                   |
   |             |          |                                          |
   | 2           |       32 | {15, 16, 14, 12, 12, 12, 11, 11, 11, 10, |
   |             |          | 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 6, 6, 5,   |
   |             |          | 4, 5, 4, 4, 4, 3, 4, 3, 2}/256           |
   +-------------+----------+------------------------------------------+

                         Table 38: LTP Filter PDFs























Valin, et al.                Standards Track                   [Page 81]

RFC 6716                 Interactive Audio Codec          September 2012


                      +-------+---------------------+
                      | Index |    Filter Taps (Q7) |
                      +-------+---------------------+
                      | 0     |   4   6  24   7   5 |
                      |       |                     |
                      | 1     |   0   0   2   0   0 |
                      |       |                     |
                      | 2     |  12  28  41  13  -4 |
                      |       |                     |
                      | 3     |  -9  15  42  25  14 |
                      |       |                     |
                      | 4     |   1  -2  62  41  -9 |
                      |       |                     |
                      | 5     | -10  37  65  -4   3 |
                      |       |                     |
                      | 6     |  -6   4  66   7  -8 |
                      |       |                     |
                      | 7     |  16  14  38  -3  33 |
                      +-------+---------------------+

      Table 39: Codebook Vectors for LTP Filter, Periodicity Index 0






























Valin, et al.                Standards Track                   [Page 82]

RFC 6716                 Interactive Audio Codec          September 2012


                      +-------+---------------------+
                      | Index |    Filter Taps (Q7) |
                      +-------+---------------------+
                      | 0     |  13  22  39  23  12 |
                      |       |                     |
                      | 1     |  -1  36  64  27  -6 |
                      |       |                     |
                      | 2     |  -7  10  55  43  17 |
                      |       |                     |
                      | 3     |   1   1   8   1   1 |
                      |       |                     |
                      | 4     |   6 -11  74  53  -9 |
                      |       |                     |
                      | 5     | -12  55  76 -12   8 |
                      |       |                     |
                      | 6     |  -3   3  93  27  -4 |
                      |       |                     |
                      | 7     |  26  39  59   3  -8 |
                      |       |                     |
                      | 8     |   2   0  77  11   9 |
                      |       |                     |
                      | 9     |  -8  22  44  -6   7 |
                      |       |                     |
                      | 10    |  40   9  26   3   9 |
                      |       |                     |
                      | 11    |  -7  20 101  -7   4 |
                      |       |                     |
                      | 12    |   3  -8  42  26   0 |
                      |       |                     |
                      | 13    | -15  33  68   2  23 |
                      |       |                     |
                      | 14    |  -2  55  46  -2  15 |
                      |       |                     |
                      | 15    |   3  -1  21  16  41 |
                      +-------+---------------------+

      Table 40: Codebook Vectors for LTP Filter, Periodicity Index 1

                      +-------+---------------------+
                      | Index |    Filter Taps (Q7) |
                      +-------+---------------------+
                      | 0     |  -6  27  61  39   5 |
                      |       |                     |
                      | 1     | -11  42  88   4   1 |
                      |       |                     |
                      | 2     |  -2  60  65   6  -4 |
                      |       |                     |
                      | 3     |  -1  -5  73  56   1 |



Valin, et al.                Standards Track                   [Page 83]

RFC 6716                 Interactive Audio Codec          September 2012


                      | 4     |  -9  19  94  29  -9 |
                      |       |                     |
                      | 5     |   0  12  99   6   4 |
                      |       |                     |
                      | 6     |   8 -19 102  46 -13 |
                      |       |                     |
                      | 7     |   3   2  13   3   2 |
                      |       |                     |
                      | 8     |   9 -21  84  72 -18 |
                      |       |                     |
                      | 9     | -11  46 104 -22   8 |
                      |       |                     |
                      | 10    |  18  38  48  23   0 |
                      |       |                     |
                      | 11    | -16  70  83 -21  11 |
                      |       |                     |
                      | 12    |   5 -11 117  22  -8 |
                      |       |                     |
                      | 13    |  -6  23 117 -12   3 |
                      |       |                     |
                      | 14    |   3  -8  95  28   4 |
                      |       |                     |
                      | 15    | -10  15  77  60 -15 |
                      |       |                     |
                      | 16    |  -1   4 124   2  -4 |
                      |       |                     |
                      | 17    |   3  38  84  24 -25 |
                      |       |                     |
                      | 18    |   2  13  42  13  31 |
                      |       |                     |
                      | 19    |  21  -4  56  46  -1 |
                      |       |                     |
                      | 20    |  -1  35  79 -13  19 |
                      |       |                     |
                      | 21    |  -7  65  88  -9 -14 |
                      |       |                     |
                      | 22    |  20   4  81  49 -29 |
                      |       |                     |
                      | 23    |  20   0  75   3 -17 |
                      |       |                     |
                      | 24    |   5  -9  44  92  -8 |
                      |       |                     |
                      | 25    |   1  -3  22  69  31 |
                      |       |                     |
                      | 26    |  -6  95  41 -12   5 |
                      |       |                     |
                      | 27    |  39  67  16  -4   1 |
                      |       |                     |



Valin, et al.                Standards Track                   [Page 84]

RFC 6716                 Interactive Audio Codec          September 2012


                      | 28    |   0  -6 120  55 -36 |
                      |       |                     |
                      | 29    | -13  44 122   4 -24 |
                      |       |                     |
                      | 30    |  81   5  11   3   7 |
                      |       |                     |
                      | 31    |   2   0   9  10  88 |
                      +-------+---------------------+

      Table 41: Codebook Vectors for LTP Filter, Periodicity Index 2

4.2.7.6.3.  LTP Scaling Parameter


   An LTP scaling parameter appears after the LTP filter coefficients if
   and only if

   o  This is a voiced frame (see Section 4.2.7.3), and

   o  Either

      *  This SILK frame corresponds to the first time interval of the
         current Opus frame for its type (LBRR or regular), or

      *  This is an LBRR frame where the LBRR flags (see Section 4.2.4)
         indicate the previous LBRR frame in the same channel is not
         coded.

   This allows the encoder to trade off the prediction gain between
   packets against the recovery time after packet loss.  Unlike
   absolute-coding for pitch lags, regular SILK frames that are not at
   the start of an Opus frame (i.e., that do not correspond to the first
   20 ms time interval in Opus frames of 40 or 60 ms) do not include
   this field, even if the prior frame was not voiced, or (in the case
   of the side channel) not even coded.  After an uncoded frame in the
   side channel, the LTP buffer (see Section 4.2.7.9.1) is cleared to
   zero, and is thus in a known state.  In contrast, LBRR frames do
   include this field when the prior frame was not coded, since the LTP
   buffer contains the output of the PLC, which is non-normative.

   If present, the decoder reads a value using the 3-entry PDF in
   Table 42.  The three possible values represent Q14 scale factors of
   15565, 12288, and 8192, respectively (corresponding to approximately
   0.95, 0.75, and 0.5).  Frames that do not code the scaling parameter
   use the default factor of 15565 (approximately 0.95).







Valin, et al.                Standards Track                   [Page 85]

RFC 6716                 Interactive Audio Codec          September 2012


                           +-------------------+
                           | PDF               |
                           +-------------------+
                           | {128, 64, 64}/256 |
                           +-------------------+

                  Table 42: PDF for LTP Scaling Parameter

4.2.7.7.  Linear Congruential Generator (LCG) Seed



   As described in Section 4.2.7.8.6, SILK uses a Linear Congruential
   Generator (LCG) to inject pseudorandom noise into the quantized
   excitation.  To ensure synchronization of this process between the
   encoder and decoder, each SILK frame stores a 2-bit seed after the
   LTP parameters (if any).  The encoder may consider the choice of seed
   during quantization, and the flexibility of this choice lets it
   reduce distortion, helping to pay for the bit cost required to signal
   it.  The decoder reads the seed using the uniform 4-entry PDF in
   Table 43, yielding a value between 0 and 3, inclusive.

                         +----------------------+
                         | PDF                  |
                         +----------------------+
                         | {64, 64, 64, 64}/256 |
                         +----------------------+

                        Table 43: PDF for LCG Seed

4.2.7.8.  Excitation



   SILK codes the excitation using a modified version of the Pyramid
   Vector Quantizer (PVQ) codebook [PVQ].  The PVQ codebook is designed
   for Laplace-distributed values and consists of all sums of K signed,
   unit pulses in a vector of dimension N, where two pulses at the same
   position are required to have the same sign.  Thus, the codebook
   includes all integer codevectors y of dimension N that satisfy

                              N-1
                              __
                              \  abs(y[j]) = K
                              /_
                              j=0

   Unlike regular PVQ, SILK uses a variable-length, rather than fixed-
   length, encoding.  This encoding is better suited to the more
   Gaussian-like distribution of the coefficient magnitudes and the non-
   uniform distribution of their signs (caused by the quantization
   offset described below).  SILK also handles large codebooks by coding



Valin, et al.                Standards Track                   [Page 86]

RFC 6716                 Interactive Audio Codec          September 2012


   the least significant bits (LSBs) of each coefficient directly.  This
   adds a small coding efficiency loss, but greatly reduces the
   computation time and ROM size required for decoding, as implemented
   in silk_decode_pulses() (decode_pulses.c).

   SILK fixes the dimension of the codebook to N = 16.  The excitation
   is made up of a number of "shell blocks", each 16 samples in size.
   Table 44 lists the number of shell blocks required for a SILK frame
   for each possible audio bandwidth and frame size. 10 ms MB frames
   nominally contain 120 samples (10 ms at 12 kHz), which is not a
   multiple of 16.  This is handled by coding 8 shell blocks (128
   samples) and discarding the final 8 samples of the last block.  The
   decoder contains no special case that prevents an encoder from
   placing pulses in these samples, and they must be correctly parsed
   from the bitstream if present, but they are otherwise ignored.

         +-----------------+------------+------------------------+
         | Audio Bandwidth | Frame Size | Number of Shell Blocks |
         +-----------------+------------+------------------------+
         | NB              | 10 ms      |                      5 |
         |                 |            |                        |
         | MB              | 10 ms      |                      8 |
         |                 |            |                        |
         | WB              | 10 ms      |                     10 |
         |                 |            |                        |
         | NB              | 20 ms      |                     10 |
         |                 |            |                        |
         | MB              | 20 ms      |                     15 |
         |                 |            |                        |
         | WB              | 20 ms      |                     20 |
         +-----------------+------------+------------------------+

              Table 44: Number of Shell Blocks Per SILK Frame

4.2.7.8.1.  Rate Level


   The first symbol in the excitation is a "rate level", which is an
   index from 0 to 8, inclusive, coded using the PDF in Table 45
   corresponding to the signal type of the current frame (from
   Section 4.2.7.3).  The rate level selects the PDF used to decode the
   number of pulses in the individual shell blocks.  It does not
   directly convey any information about the bitrate or the number of
   pulses itself, but merely changes the probability of the symbols in
   Section 4.2.7.8.2.  Level 0 provides a more efficient encoding at low
   rates generally, and level 8 provides a more efficient encoding at
   high rates generally, though the most efficient level for a





Valin, et al.                Standards Track                   [Page 87]

RFC 6716                 Interactive Audio Codec          September 2012


   particular SILK frame may depend on the exact distribution of the
   coded symbols.  An encoder should, but is not required to, use the
   most efficient rate level.

    +----------------------+------------------------------------------+
    | Signal Type          | PDF                                      |
    +----------------------+------------------------------------------+
    | Inactive or Unvoiced | {15, 51, 12, 46, 45, 13, 33, 27, 14}/256 |
    |                      |                                          |
    | Voiced               | {33, 30, 36, 17, 34, 49, 18, 21, 18}/256 |
    +----------------------+------------------------------------------+

                     Table 45: PDFs for the Rate Level

4.2.7.8.2.  Pulses per Shell Block


   The total number of pulses in each of the shell blocks follows the
   rate level.  The pulse counts for all of the shell blocks are coded
   consecutively, before the content of any of the blocks.  Each block
   may have anywhere from 0 to 16 pulses, inclusive, coded using the 18-
   entry PDF in Table 46 corresponding to the rate level from
   Section 4.2.7.8.1.  The special value 17 indicates that this block
   has one or more additional LSBs to decode for each coefficient.  If
   the decoder encounters this value, it decodes another value for the
   actual pulse count of the block, but uses the PDF corresponding to
   the special rate level 9 instead of the normal rate level.  This
   process repeats until the decoder reads a value less than 17, and it
   then sets the number of extra LSBs used to the number of 17's decoded
   for that block.  If it reads the value 17 ten times, then the next
   iteration uses the special rate level 10 instead of 9.  The
   probability of decoding a 17 when using the PDF for rate level 10 is
   zero, ensuring that the number of LSBs for a block will not exceed
   10.  The cumulative distribution for rate level 10 is just a shifted
   version of that for 9 and thus does not require any additional
   storage.
















Valin, et al.                Standards Track                   [Page 88]

RFC 6716                 Interactive Audio Codec          September 2012


   +----------+--------------------------------------------------------+
   | Rate     | PDF                                                    |
   | Level    |                                                        |
   +----------+--------------------------------------------------------+
   | 0        | {131, 74, 25, 8, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   |
   |          | 1, 1}/256                                              |
   |          |                                                        |
   | 1        | {58, 93, 60, 23, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,   |
   |          | 1, 1}/256                                              |
   |          |                                                        |
   | 2        | {43, 51, 46, 33, 24, 16, 11, 8, 6, 3, 3, 3, 2, 1, 1,   |
   |          | 2, 1, 2}/256                                           |
   |          |                                                        |
   | 3        | {17, 52, 71, 57, 31, 12, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
   |          | 1, 1}/256                                              |
   |          |                                                        |
   | 4        | {6, 21, 41, 53, 49, 35, 21, 11, 6, 3, 2, 2, 1, 1, 1,   |
   |          | 1, 1, 1}/256                                           |
   |          |                                                        |
   | 5        | {7, 14, 22, 28, 29, 28, 25, 20, 17, 13, 11, 9, 7, 5,   |
   |          | 4, 4, 3, 10}/256                                       |
   |          |                                                        |
   | 6        | {2, 5, 14, 29, 42, 46, 41, 31, 19, 11, 6, 3, 2, 1, 1,  |
   |          | 1, 1, 1}/256                                           |
   |          |                                                        |
   | 7        | {1, 2, 4, 10, 19, 29, 35, 37, 34, 28, 20, 14, 8, 5, 4, |
   |          | 2, 2, 2}/256                                           |
   |          |                                                        |
   | 8        | {1, 2, 2, 5, 9, 14, 20, 24, 27, 28, 26, 23, 20, 15,    |
   |          | 11, 8, 6, 15}/256                                      |
   |          |                                                        |
   | 9        | {1, 1, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2,   |
   |          | 1, 1, 2}/256                                           |
   |          |                                                        |
   | 10       | {2, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1,   |
   |          | 1, 2, 0}/256                                           |
   +----------+--------------------------------------------------------+

                    Table 46: PDFs for the Pulse Count

4.2.7.8.3.  Pulse Location Decoding


   The locations of the pulses in each shell block follow the pulse
   counts, as decoded by silk_shell_decoder() (shell_coder.c).  As with
   the pulse counts, these locations are coded for all the shell blocks
   before any of the remaining information for each block.  Unlike many
   other codecs, SILK places no restriction on the distribution of




Valin, et al.                Standards Track                   [Page 89]

RFC 6716                 Interactive Audio Codec          September 2012


   pulses within a shell block.  All of the pulses may be placed in a
   single location, or each one in a unique location, or anything in
   between.

   The location of pulses is coded by recursively partitioning each
   block into halves, and coding how many pulses fall on the left side
   of the split.  All remaining pulses must fall on the right side of
   the split.  The process then recurses into the left half, and after
   that returns, the right half (preorder traversal).  The PDF to use is
   chosen by the size of the current partition (16, 8, 4, or 2) and the
   number of pulses in the partition (1 to 16, inclusive).  Tables 47
   through 50 list the PDFs used for each partition size and pulse
   count.  This process skips partitions without any pulses, i.e., where
   the initial pulse count from Section 4.2.7.8.2 was zero, or where the
   split in the prior level indicated that all of the pulses fell on the
   other side.  These partitions have nothing to code, so they require
   no PDF.


































Valin, et al.                Standards Track                   [Page 90]

RFC 6716                 Interactive Audio Codec          September 2012


   +------------+------------------------------------------------------+
   | Pulse      | PDF                                                  |
   | Count      |                                                      |
   +------------+------------------------------------------------------+
   | 1          | {126, 130}/256                                       |
   |            |                                                      |
   | 2          | {56, 142, 58}/256                                    |
   |            |                                                      |
   | 3          | {25, 101, 104, 26}/256                               |
   |            |                                                      |
   | 4          | {12, 60, 108, 64, 12}/256                            |
   |            |                                                      |
   | 5          | {7, 35, 84, 87, 37, 6}/256                           |
   |            |                                                      |
   | 6          | {4, 20, 59, 86, 63, 21, 3}/256                       |
   |            |                                                      |
   | 7          | {3, 12, 38, 72, 75, 42, 12, 2}/256                   |
   |            |                                                      |
   | 8          | {2, 8, 25, 54, 73, 59, 27, 7, 1}/256                 |
   |            |                                                      |
   | 9          | {2, 5, 17, 39, 63, 65, 42, 18, 4, 1}/256             |
   |            |                                                      |
   | 10         | {1, 4, 12, 28, 49, 63, 54, 30, 11, 3, 1}/256         |
   |            |                                                      |
   | 11         | {1, 4, 8, 20, 37, 55, 57, 41, 22, 8, 2, 1}/256       |
   |            |                                                      |
   | 12         | {1, 3, 7, 15, 28, 44, 53, 48, 33, 16, 6, 1, 1}/256   |
   |            |                                                      |
   | 13         | {1, 2, 6, 12, 21, 35, 47, 48, 40, 25, 12, 5, 1,      |
   |            | 1}/256                                               |
   |            |                                                      |
   | 14         | {1, 1, 4, 10, 17, 27, 37, 47, 43, 33, 21, 9, 4, 1,   |
   |            | 1}/256                                               |
   |            |                                                      |
   | 15         | {1, 1, 1, 8, 14, 22, 33, 40, 43, 38, 28, 16, 8, 1,   |
   |            | 1, 1}/256                                            |
   |            |                                                      |
   | 16         | {1, 1, 1, 1, 13, 18, 27, 36, 41, 41, 34, 24, 14, 1,  |
   |            | 1, 1, 1}/256                                         |
   +------------+------------------------------------------------------+

        Table 47: PDFs for Pulse Count Split, 16 Sample Partitions









Valin, et al.                Standards Track                   [Page 91]

RFC 6716                 Interactive Audio Codec          September 2012


   +------------+------------------------------------------------------+
   | Pulse      | PDF                                                  |
   | Count      |                                                      |
   +------------+------------------------------------------------------+
   | 1          | {127, 129}/256                                       |
   |            |                                                      |
   | 2          | {53, 149, 54}/256                                    |
   |            |                                                      |
   | 3          | {22, 105, 106, 23}/256                               |
   |            |                                                      |
   | 4          | {11, 61, 111, 63, 10}/256                            |
   |            |                                                      |
   | 5          | {6, 35, 86, 88, 36, 5}/256                           |
   |            |                                                      |
   | 6          | {4, 20, 59, 87, 62, 21, 3}/256                       |
   |            |                                                      |
   | 7          | {3, 13, 40, 71, 73, 41, 13, 2}/256                   |
   |            |                                                      |
   | 8          | {3, 9, 27, 53, 70, 56, 28, 9, 1}/256                 |
   |            |                                                      |
   | 9          | {3, 8, 19, 37, 57, 61, 44, 20, 6, 1}/256             |
   |            |                                                      |
   | 10         | {3, 7, 15, 28, 44, 54, 49, 33, 17, 5, 1}/256         |
   |            |                                                      |
   | 11         | {1, 7, 13, 22, 34, 46, 48, 38, 28, 14, 4, 1}/256     |
   |            |                                                      |
   | 12         | {1, 1, 11, 22, 27, 35, 42, 47, 33, 25, 10, 1, 1}/256 |
   |            |                                                      |
   | 13         | {1, 1, 6, 14, 26, 37, 43, 43, 37, 26, 14, 6, 1,      |
   |            | 1}/256                                               |
   |            |                                                      |
   | 14         | {1, 1, 4, 10, 20, 31, 40, 42, 40, 31, 20, 10, 4, 1,  |
   |            | 1}/256                                               |
   |            |                                                      |
   | 15         | {1, 1, 3, 8, 16, 26, 35, 38, 38, 35, 26, 16, 8, 3,   |
   |            | 1, 1}/256                                            |
   |            |                                                      |
   | 16         | {1, 1, 2, 6, 12, 21, 30, 36, 38, 36, 30, 21, 12, 6,  |
   |            | 2, 1, 1}/256                                         |
   +------------+------------------------------------------------------+

         Table 48: PDFs for Pulse Count Split, 8 Sample Partitions









Valin, et al.                Standards Track                   [Page 92]

RFC 6716                 Interactive Audio Codec          September 2012


   +------------+------------------------------------------------------+
   | Pulse      | PDF                                                  |
   | Count      |                                                      |
   +------------+------------------------------------------------------+
   | 1          | {127, 129}/256                                       |
   |            |                                                      |
   | 2          | {49, 157, 50}/256                                    |
   |            |                                                      |
   | 3          | {20, 107, 109, 20}/256                               |
   |            |                                                      |
   | 4          | {11, 60, 113, 62, 10}/256                            |
   |            |                                                      |
   | 5          | {7, 36, 84, 87, 36, 6}/256                           |
   |            |                                                      |
   | 6          | {6, 24, 57, 82, 60, 23, 4}/256                       |
   |            |                                                      |
   | 7          | {5, 18, 39, 64, 68, 42, 16, 4}/256                   |
   |            |                                                      |
   | 8          | {6, 14, 29, 47, 61, 52, 30, 14, 3}/256               |
   |            |                                                      |
   | 9          | {1, 15, 23, 35, 51, 50, 40, 30, 10, 1}/256           |
   |            |                                                      |
   | 10         | {1, 1, 21, 32, 42, 52, 46, 41, 18, 1, 1}/256         |
   |            |                                                      |
   | 11         | {1, 6, 16, 27, 36, 42, 42, 36, 27, 16, 6, 1}/256     |
   |            |                                                      |
   | 12         | {1, 5, 12, 21, 31, 38, 40, 38, 31, 21, 12, 5, 1}/256 |
   |            |                                                      |
   | 13         | {1, 3, 9, 17, 26, 34, 38, 38, 34, 26, 17, 9, 3,      |
   |            | 1}/256                                               |
   |            |                                                      |
   | 14         | {1, 3, 7, 14, 22, 29, 34, 36, 34, 29, 22, 14, 7, 3,  |
   |            | 1}/256                                               |
   |            |                                                      |
   | 15         | {1, 2, 5, 11, 18, 25, 31, 35, 35, 31, 25, 18, 11, 5, |
   |            | 2, 1}/256                                            |
   |            |                                                      |
   | 16         | {1, 1, 4, 9, 15, 21, 28, 32, 34, 32, 28, 21, 15, 9,  |
   |            | 4, 1, 1}/256                                         |
   +------------+------------------------------------------------------+

         Table 49: PDFs for Pulse Count Split, 4 Sample Partitions









Valin, et al.                Standards Track                   [Page 93]

RFC 6716                 Interactive Audio Codec          September 2012


   +------------+------------------------------------------------------+
   | Pulse      | PDF                                                  |
   | Count      |                                                      |
   +------------+------------------------------------------------------+
   | 1          | {128, 128}/256                                       |
   |            |                                                      |
   | 2          | {42, 172, 42}/256                                    |
   |            |                                                      |
   | 3          | {21, 107, 107, 21}/256                               |
   |            |                                                      |
   | 4          | {12, 60, 112, 61, 11}/256                            |
   |            |                                                      |
   | 5          | {8, 34, 86, 86, 35, 7}/256                           |
   |            |                                                      |
   | 6          | {8, 23, 55, 90, 55, 20, 5}/256                       |
   |            |                                                      |
   | 7          | {5, 15, 38, 72, 72, 36, 15, 3}/256                   |
   |            |                                                      |
   | 8          | {6, 12, 27, 52, 77, 47, 20, 10, 5}/256               |
   |            |                                                      |
   | 9          | {6, 19, 28, 35, 40, 40, 35, 28, 19, 6}/256           |
   |            |                                                      |
   | 10         | {4, 14, 22, 31, 37, 40, 37, 31, 22, 14, 4}/256       |
   |            |                                                      |
   | 11         | {3, 10, 18, 26, 33, 38, 38, 33, 26, 18, 10, 3}/256   |
   |            |                                                      |
   | 12         | {2, 8, 13, 21, 29, 36, 38, 36, 29, 21, 13, 8, 2}/256 |
   |            |                                                      |
   | 13         | {1, 5, 10, 17, 25, 32, 38, 38, 32, 25, 17, 10, 5,    |
   |            | 1}/256                                               |
   |            |                                                      |
   | 14         | {1, 4, 7, 13, 21, 29, 35, 36, 35, 29, 21, 13, 7, 4,  |
   |            | 1}/256                                               |
   |            |                                                      |
   | 15         | {1, 2, 5, 10, 17, 25, 32, 36, 36, 32, 25, 17, 10, 5, |
   |            | 2, 1}/256                                            |
   |            |                                                      |
   | 16         | {1, 2, 4, 7, 13, 21, 28, 34, 36, 34, 28, 21, 13, 7,  |
   |            | 4, 2, 1}/256                                         |
   +------------+------------------------------------------------------+

         Table 50: PDFs for Pulse Count Split, 2 Sample Partitions

4.2.7.8.4.  LSB Decoding


   After the decoder reads the pulse locations for all blocks, it reads
   the LSBs (if any) for each block in turn.  Inside each block, it
   reads all the LSBs for each coefficient in turn, even those where no



Valin, et al.                Standards Track                   [Page 94]

RFC 6716                 Interactive Audio Codec          September 2012


   pulses were allocated, before proceeding to the next one.  For 10 ms
   MB frames, it reads LSBs even for the extra 8 samples in the last
   block.  The LSBs are coded from most significant to least
   significant, and they all use the PDF in Table 51.

                            +----------------+
                            | PDF            |
                            +----------------+
                            | {136, 120}/256 |
                            +----------------+

                     Table 51: PDF for Excitation LSBs

   The number of LSBs read for each coefficient in a block is determined
   in Section 4.2.7.8.2.  The magnitude of the coefficient is initially
   equal to the number of pulses placed at that location in
   Section 4.2.7.8.3.  As each LSB is decoded, the magnitude is doubled,
   and then the value of the LSB added to it, to obtain an updated
   magnitude.

4.2.7.8.5.  Sign Decoding


   After decoding the pulse locations and the LSBs, the decoder knows
   the magnitude of each coefficient in the excitation.  It then decodes
   a sign for all coefficients with a non-zero magnitude, using one of
   the PDFs from Table 52.  If the value decoded is 0, then the
   coefficient magnitude is negated.  Otherwise, it remains positive.

   The decoder chooses the PDF for the sign based on the signal type and
   quantization offset type (from Section 4.2.7.3) and the number of
   pulses in the block (from Section 4.2.7.8.2).  The number of pulses
   in the block does not take into account any LSBs.  Most PDFs are
   skewed towards negative signs because of the quantization offset, but
   the PDFs for zero pulses are highly skewed towards positive signs.
   If a block contains many positive coefficients, it is sometimes
   beneficial to code it solely using LSBs (i.e., with zero pulses),
   since the encoder may be able to save enough bits on the signs to
   justify the less efficient coefficient magnitude encoding.

   +-------------+-----------------------+-------------+---------------+
   | Signal Type | Quantization Offset   | Pulse Count | PDF           |
   |             | Type                  |             |               |
   +-------------+-----------------------+-------------+---------------+
   | Inactive    | Low                   | 0           | {2, 254}/256  |
   |             |                       |             |               |
   | Inactive    | Low                   | 1           | {207, 49}/256 |
   |             |                       |             |               |
   | Inactive    | Low                   | 2           | {189, 67}/256 |



Valin, et al.                Standards Track                   [Page 95]

RFC 6716                 Interactive Audio Codec          September 2012


   | Inactive    | Low                   | 3           | {179, 77}/256 |
   |             |                       |             |               |
   | Inactive    | Low                   | 4           | {174, 82}/256 |
   |             |                       |             |               |
   | Inactive    | Low                   | 5           | {163, 93}/256 |
   |             |                       |             |               |
   | Inactive    | Low                   | 6 or more   | {157, 99}/256 |
   |             |                       |             |               |
   | Inactive    | High                  | 0           | {58, 198}/256 |
   |             |                       |             |               |
   | Inactive    | High                  | 1           | {245, 11}/256 |
   |             |                       |             |               |
   | Inactive    | High                  | 2           | {238, 18}/256 |
   |             |                       |             |               |
   | Inactive    | High                  | 3           | {232, 24}/256 |
   |             |                       |             |               |
   | Inactive    | High                  | 4           | {225, 31}/256 |
   |             |                       |             |               |
   | Inactive    | High                  | 5           | {220, 36}/256 |
   |             |                       |             |               |
   | Inactive    | High                  | 6 or more   | {211, 45}/256 |
   |             |                       |             |               |
   | Unvoiced    | Low                   | 0           | {1, 255}/256  |
   |             |                       |             |               |
   | Unvoiced    | Low                   | 1           | {210, 46}/256 |
   |             |                       |             |               |
   | Unvoiced    | Low                   | 2           | {190, 66}/256 |
   |             |                       |             |               |
   | Unvoiced    | Low                   | 3           | {178, 78}/256 |
   |             |                       |             |               |
   | Unvoiced    | Low                   | 4           | {169, 87}/256 |
   |             |                       |             |               |
   | Unvoiced    | Low                   | 5           | {162, 94}/256 |
   |             |                       |             |               |
   | Unvoiced    | Low                   | 6 or more   | {152,         |
   |             |                       |             | 104}/256      |
   |             |                       |             |               |
   | Unvoiced    | High                  | 0           | {48, 208}/256 |
   |             |                       |             |               |
   | Unvoiced    | High                  | 1           | {242, 14}/256 |
   |             |                       |             |               |
   | Unvoiced    | High                  | 2           | {235, 21}/256 |
   |             |                       |             |               |
   | Unvoiced    | High                  | 3           | {224, 32}/256 |
   |             |                       |             |               |
   | Unvoiced    | High                  | 4           | {214, 42}/256 |
   |             |                       |             |               |
   | Unvoiced    | High                  | 5           | {205, 51}/256 |



Valin, et al.                Standards Track                   [Page 96]

RFC 6716                 Interactive Audio Codec          September 2012


   | Unvoiced    | High                  | 6 or more   | {190, 66}/256 |
   |             |                       |             |               |
   | Voiced      | Low                   | 0           | {1, 255}/256  |
   |             |                       |             |               |
   | Voiced      | Low                   | 1           | {162, 94}/256 |
   |             |                       |             |               |
   | Voiced      | Low                   | 2           | {152,         |
   |             |                       |             | 104}/256      |
   |             |                       |             |               |
   | Voiced      | Low                   | 3           | {147,         |
   |             |                       |             | 109}/256      |
   |             |                       |             |               |
   | Voiced      | Low                   | 4           | {144,         |
   |             |                       |             | 112}/256      |
   |             |                       |             |               |
   | Voiced      | Low                   | 5           | {141,         |
   |             |                       |             | 115}/256      |
   |             |                       |             |               |
   | Voiced      | Low                   | 6 or more   | {138,         |
   |             |                       |             | 118}/256      |
   |             |                       |             |               |
   | Voiced      | High                  | 0           | {8, 248}/256  |
   |             |                       |             |               |
   | Voiced      | High                  | 1           | {203, 53}/256 |
   |             |                       |             |               |
   | Voiced      | High                  | 2           | {187, 69}/256 |
   |             |                       |             |               |
   | Voiced      | High                  | 3           | {176, 80}/256 |
   |             |                       |             |               |
   | Voiced      | High                  | 4           | {168, 88}/256 |
   |             |                       |             |               |
   | Voiced      | High                  | 5           | {161, 95}/256 |
   |             |                       |             |               |
   | Voiced      | High                  | 6 or more   | {154,         |
   |             |                       |             | 102}/256      |
   +-------------+-----------------------+-------------+---------------+

                    Table 52: PDFs for Excitation Signs

4.2.7.8.6.  Reconstructing the Excitation


   After the signs have been read, there is enough information to
   reconstruct the complete excitation signal.  This requires adding a
   constant quantization offset to each non-zero sample and then
   pseudorandomly inverting and offsetting every sample.  The constant
   quantization offset varies depending on the signal type and
   quantization offset type (see Section 4.2.7.3).




Valin, et al.                Standards Track                   [Page 97]

RFC 6716                 Interactive Audio Codec          September 2012


   +-------------+--------------------------+--------------------------+
   | Signal Type | Quantization Offset Type |      Quantization Offset |
   |             |                          |                    (Q23) |
   +-------------+--------------------------+--------------------------+
   | Inactive    | Low                      |                       25 |
   |             |                          |                          |
   | Inactive    | High                     |                       60 |
   |             |                          |                          |
   | Unvoiced    | Low                      |                       25 |
   |             |                          |                          |
   | Unvoiced    | High                     |                       60 |
   |             |                          |                          |
   | Voiced      | Low                      |                        8 |
   |             |                          |                          |
   | Voiced      | High                     |                       25 |
   +-------------+--------------------------+--------------------------+

                 Table 53: Excitation Quantization Offsets

   Let e_raw[i] be the raw excitation value at position i, with a
   magnitude composed of the pulses at that location (see
   Section 4.2.7.8.3) combined with any additional LSBs (see
   Section 4.2.7.8.4), and with the corresponding sign decoded in
   Section 4.2.7.8.5.  Additionally, let seed be the current
   pseudorandom seed, which is initialized to the value decoded from
   Section 4.2.7.7 for the first sample in the current SILK frame, and
   updated for each subsequent sample according to the procedure below.
   Finally, let offset_Q23 be the quantization offset from Table 53.
   Then the following procedure produces the final reconstructed
   excitation value, e_Q23[i]:

        e_Q23[i] = (e_raw[i] << 8) - sign(e_raw[i])*20 + offset_Q23;
            seed = (196314165*seed + 907633515) & 0xFFFFFFFF;
        e_Q23[i] = (seed & 0x80000000) ? -e_Q23[i] : e_Q23[i];
            seed = (seed + e_raw[i]) & 0xFFFFFFFF;

   When e_raw[i] is zero, sign() returns 0 by the definition in
   Section 1.1.4, so the factor of 20 does not get added.  The final
   e_Q23[i] value may require more than 16 bits per sample, but it will
   not require more than 23, including the sign.

4.2.7.9.  SILK Frame Reconstruction



   The remainder of the reconstruction process for the frame does not
   need to be bit-exact, as small errors should only introduce
   proportionally small distortions.  Although the reference
   implementation only includes a fixed-point version of the remaining




Valin, et al.                Standards Track                   [Page 98]

RFC 6716                 Interactive Audio Codec          September 2012


   steps, this section describes them in terms of a floating-point
   version for simplicity.  This produces a signal with a nominal range
   of -1.0 to 1.0.

   silk_decode_core() (decode_core.c) contains the code for the main
   reconstruction process.  It proceeds subframe-by-subframe, since
   quantization gains, LTP parameters, and (in 20 ms SILK frames) LPC
   coefficients can vary from one to the next.

   Let a_Q12[k] be the LPC coefficients for the current subframe.  If
   this is the first or second subframe of a 20 ms SILK frame and the
   LSF interpolation factor, w_Q2 (see Section 4.2.7.5.5), is less than
   4, then these correspond to the final LPC coefficients produced by
   Section 4.2.7.5.8 from the interpolated LSF coefficients, n1_Q15[k]
   (computed in Section 4.2.7.5.5).  Otherwise, they correspond to the
   final LPC coefficients produced from the uninterpolated LSF
   coefficients for the current frame, n2_Q15[k].

   Also, let n be the number of samples in a subframe (40 for NB, 60 for
   MB, and 80 for WB), s be the index of the current subframe in this
   SILK frame (0 or 1 for 10 ms frames, or 0 to 3 for 20 ms frames), and
   j be the index of the first sample in the residual corresponding to
   the current subframe.

4.2.7.9.1.  LTP Synthesis


   For unvoiced frames (see Section 4.2.7.3), the LPC residual for i
   such that j <= i < (j + n) is simply a normalized copy of the
   excitation signal, i.e.,

                                       e_Q23[i]
                             res[i] = ---------
                                       2.0**23

   Voiced SILK frames, on the other hand, pass the excitation through an
   LTP filter using the parameters decoded in Section 4.2.7.6 to produce
   an LPC residual.  The LTP filter requires LPC residual values from
   before the current subframe as input.  However, since the LPC
   coefficients may have changed, it obtains this residual by
   "rewhitening" the corresponding output signal using the LPC
   coefficients from the current subframe.  Let out[i] for i such that
   (j - pitch_lags[s] - d_LPC - 2) <= i < j be the fully reconstructed
   output signal from the last (pitch_lags[s] + d_LPC + 2) samples of
   previous subframes (see Section 4.2.7.9.2), where pitch_lags[s] is
   the pitch lag for the current subframe from Section 4.2.7.6.1.
   Additionally, let lpc[i] for i such that (j - s*n - d_LPC) <= i < j
   be the fully reconstructed output signal from the last (s*n + d_LPC)




Valin, et al.                Standards Track                   [Page 99]

RFC 6716                 Interactive Audio Codec          September 2012


   samples of previous subframes before clamping (see
   Section 4.2.7.9.2).  During reconstruction of the first subframe for
   this channel after either

   o  An uncoded regular SILK frame (if this is the side channel), or

   o  A decoder reset (see Section 4.5.2),

   out[i] and lpc[i] are initially cleared to all zeros.  If this is the
   third or fourth subframe of a 20 ms SILK frame and the LSF
   interpolation factor, w_Q2 (see Section 4.2.7.5.5), is less than 4,
   then let out_end be set to (j - (s-2)*n) and let LTP_scale_Q14 be set
   to 16384.  Otherwise, set out_end to (j - s*n) and set LTP_scale_Q14
   to the Q14 LTP scaling value from Section 4.2.7.6.3.  Then, for i
   such that (j - pitch_lags[s] - 2) <= i < out_end, out[i] is
   rewhitened into an LPC residual, res[i], via

             4.0*LTP_scale_Q14
    res[i] = ----------------- * clamp(-1.0,
                gain_Q16[s]
                                       d_LPC-1
                                         __              a_Q12[k]
                                out[i] - \  out[i-k-1] * --------, 1.0)
                                         /_               4096.0
                                         k=0

   This requires storage to buffer up to 306 values of out[i] from
   previous subframes.  This corresponds to WB with a maximum pitch lag
   of 18 ms * 16 kHz samples, plus 16 samples for d_LPC, plus 2 samples
   for the width of the LTP filter.  Then, for i such that
   out_end <= i < j, lpc[i] is rewhitened into an LPC residual, res[i],
   via

                                        d_LPC-1
                    65536.0               __              a_Q12[k]
         res[i] = ----------- * (lpc[i] - \  lpc[i-k-1] * --------)
                  gain_Q16[s]             /_               4096.0
                                          k=0

   This requires storage to buffer up to 256 values of lpc[i] from
   previous subframes (240 from the current SILK frame and 16 from the
   previous SILK frame).  This corresponds to WB with up to three
   previous subframes in the current SILK frame, plus 16 samples for
   d_LPC.  The astute reader will notice that, given the definition of
   lpc[i] in Section 4.2.7.9.2, the output of this latter equation is
   merely a scaled version of the values of res[i] from previous
   subframes.




Valin, et al.                Standards Track                  [Page 100]

RFC 6716                 Interactive Audio Codec          September 2012


   Let e_Q23[i] for j <= i < (j + n) be the excitation for the current
   subframe, and b_Q7[k] for 0 <= k < 5 be the coefficients of the LTP
   filter taken from the codebook entry in one of Tables 39 through 41
   corresponding to the index decoded for the current subframe in
   Section 4.2.7.6.2.  Then for i such that j <= i < (j + n), the LPC
   residual is

                            4
                e_Q23[i]   __                                  b_Q7[k]
      res[i] = --------- + \  res[i - pitch_lags[s] + 2 - k] * -------
                2.0**23    /_                                   128.0
                           k=0

4.2.7.9.2.  LPC Synthesis


   LPC synthesis uses the short-term LPC filter to predict the next
   output coefficient.  For i such that (j - d_LPC) <= i < j, let lpc[i]
   be the result of LPC synthesis from the last d_LPC samples of the
   previous subframe or zeros in the first subframe for this channel
   after either

   o  An uncoded regular SILK frame (if this is the side channel), or

   o  A decoder reset (see Section 4.5.2).

   Then, for i such that j <= i < (j + n), the result of LPC synthesis
   for the current subframe is

                                        d_LPC-1
                   gain_Q16[i]            __              a_Q12[k]
          lpc[i] = ----------- * res[i] + \  lpc[i-k-1] * --------
                     65536.0              /_               4096.0
                                          k=0

   The decoder saves the final d_LPC values, i.e., lpc[i] such that
   (j + n - d_LPC) <= i < (j + n), to feed into the LPC synthesis of the
   next subframe.  This requires storage for up to 16 values of lpc[i]
   (for WB frames).

   Then, the signal is clamped into the final nominal range:

                     out[i] = clamp(-1.0, lpc[i], 1.0)

   This clamping occurs entirely after the LPC synthesis filter has run.
   The decoder saves the unclamped values, lpc[i], to feed into the LPC
   filter for the next subframe, but saves the clamped values, out[i],
   for rewhitening in voiced frames.




Valin, et al.                Standards Track                  [Page 101]

RFC 6716                 Interactive Audio Codec          September 2012


4.2.8.  Stereo Unmixing



   For stereo streams, after decoding a frame from each channel, the
   decoder must convert the mid-side (MS) representation into a left-
   right (LR) representation.  The function silk_stereo_MS_to_LR
   (stereo_MS_to_LR.c) implements this process.  In it, the decoder
   predicts the side channel using a) a simple low-passed version of the
   mid channel, and b) the unfiltered mid channel, using the prediction
   weights decoded in Section 4.2.7.1.  This simple low-pass filter
   imposes a one-sample delay, and the unfiltered mid channel is also
   delayed by one sample.  In order to allow seamless switching between
   stereo and mono, mono streams must also impose the same one-sample
   delay.  The encoder requires an additional one-sample delay for both
   mono and stereo streams, though an encoder may omit the delay for
   mono if it knows it will never switch to stereo.

   The unmixing process operates in two phases.  The first phase lasts
   for 8 ms, during which it interpolates the prediction weights from
   the previous frame, prev_w0_Q13 and prev_w1_Q13, to the values for
   the current frame, w0_Q13 and w1_Q13.  The second phase simply uses
   these weights for the remainder of the frame.

   Let mid[i] and side[i] be the contents of out[i] (from
   Section 4.2.7.9.2) for the current mid and side channels,
   respectively, and let left[i] and right[i] be the corresponding
   stereo output channels.  If the side channel is not coded (see
   Section 4.2.7.2), then side[i] is set to zero.  Also, let j be
   defined as in Section 4.2.7.9, n1 be the number of samples in phase 1
   (64 for NB, 96 for MB, and 128 for WB), and n2 be the total number of
   samples in the frame.  Then, for i such that j <= i < (j + n2), the
   left and right channel output is

                   prev_w0_Q13                  (w0_Q13 - prev_w0_Q13)
             w0 =  ----------- + min(i - j, n1)*----------------------
                     8192.0                           8192.0*n1

                   prev_w1_Q13                  (w1_Q13 - prev_w1_Q13)
             w1 =  ----------- + min(i - j, n1)*----------------------
                     8192.0                            8192.0*n1

                  mid[i-2] + 2*mid[i-1] + mid[i]
             p0 = ------------------------------
                               4.0

      left[i] = clamp(-1.0, (1 + w1)*mid[i-1] + side[i-1] + w0*p0, 1.0)

     right[i] = clamp(-1.0, (1 - w1)*mid[i-1] - side[i-1] - w0*p0, 1.0)




Valin, et al.                Standards Track                  [Page 102]

RFC 6716                 Interactive Audio Codec          September 2012


   These formulas require two samples prior to index j, the start of the
   frame, for the mid channel, and one prior sample for the side
   channel.  For the first frame after a decoder reset, zeros are used
   instead.

4.2.9.  Resampling



   After stereo unmixing (if any), the decoder applies resampling to
   convert the decoded SILK output to the sample rate desired by the
   application.  This is necessary when decoding a Hybrid frame at SWB
   or FB sample rates, or whenever the decoder wants the output at a
   different sample rate than the internal SILK sampling rate (e.g., to
   allow a constant sample rate when the audio bandwidth changes, or to
   allow mixing with audio from other applications).  The resampler
   itself is non-normative, and a decoder can use any method it wants to
   perform the resampling.

   However, a minimum amount of delay is imposed to allow the resampler
   to operate, and this delay is normative, so that the corresponding
   delay can be applied to the MDCT layer in the encoder.  A decoder is
   always free to use a resampler that requires more delay than allowed
   for here (e.g., to improve quality), but it must then delay the
   output of the MDCT layer by this extra amount.  Keeping as much delay
   as possible on the encoder side allows an encoder that knows it will
   never use any of the SILK or Hybrid modes to skip this delay.  By
   contrast, if it were all applied by the decoder, then a decoder that
   processes audio in fixed-size blocks would be forced to delay the
   output of CELT frames just in case of a later switch to a SILK or
   Hybrid mode.

   Table 54 gives the maximum resampler delay in samples at 48 kHz for
   each SILK audio bandwidth.  Because the actual output rate may not be
   48 kHz, it may not be possible to achieve exactly these delays while
   using a whole number of input or output samples.  The reference
   implementation is able to resample to any of the supported output
   sampling rates (8, 12, 16, 24, or 48 kHz) within or near this delay
   constraint.  Some resampling filters (including those used by the
   reference implementation) may add a delay that is not an exact
   integer, or is not linear-phase, and so cannot be represented by a
   single delay at all frequencies.  However, such deviations are
   unlikely to be perceptible, and the comparison tool described in
   Section 6 is designed to be relatively insensitive to them.  The
   delays listed here are the ones that should be targeted by the
   encoder.







Valin, et al.                Standards Track                  [Page 103]

RFC 6716                 Interactive Audio Codec          September 2012


                +-----------------+-----------------------+
                | Audio Bandwidth | Delay in Milliseconds |
                +-----------------+-----------------------+
                | NB              | 0.538                 |
                |                 |                       |
                | MB              | 0.692                 |
                |                 |                       |
                | WB              | 0.706                 |
                +-----------------+-----------------------+

                Table 54: SILK Resampler Delay Allocations

   NB is given a smaller decoder delay allocation than MB and WB to
   allow a higher-order filter when resampling to 8 kHz in both the
   encoder and decoder.  This implies that the audio content of two SILK
   frames operating at different bandwidths is not perfectly aligned in
   time.  This is not an issue for any transitions described in
   Section 4.5, because they all involve a SILK decoder reset.  When the
   decoder is reset, any samples remaining in the resampling buffer are
   discarded, and the resampler is re-initialized with silence.

4.3.  CELT Decoder



   The CELT layer of Opus is based on the Modified Discrete Cosine
   Transform [MDCT] with partially overlapping windows of 5 to 22.5 ms.
   The main principle behind CELT is that the MDCT spectrum is divided
   into bands that (roughly) follow the Bark scale, i.e., the scale of
   the ear's critical bands [ZWICKER61].  The normal CELT layer uses 21
   of those bands, though Opus Custom (see Section 6.2) may use a
   different number of bands.  In Hybrid mode, the first 17 bands (up to
   8 kHz) are not coded.  A band can contain as little as one MDCT bin
   per channel, and as many as 176 bins per channel, as detailed in
   Table 55.  In each band, the gain (energy) is coded separately from
   the shape of the spectrum.  Coding the gain explicitly makes it easy
   to preserve the spectral envelope of the signal.  The remaining unit-
   norm shape vector is encoded using a Pyramid Vector Quantizer
   (PVQ) Section 4.3.4.

   +--------+--------+------+-------+-------+-------------+------------+
   | Frame  | 2.5 ms | 5 ms | 10 ms | 20 ms |       Start |       Stop |
   | Size:  |        |      |       |       |   Frequency |  Frequency |
   +--------+--------+------+-------+-------+-------------+------------+
   | Band   |  Bins: |      |       |       |             |            |
   |        |        |      |       |       |             |            |
   | 0      |      1 |    2 |     4 |     8 |        0 Hz |     200 Hz |
   |        |        |      |       |       |             |            |
   | 1      |      1 |    2 |     4 |     8 |      200 Hz |     400 Hz |
   |        |        |      |       |       |             |            |



Valin, et al.                Standards Track                  [Page 104]

RFC 6716                 Interactive Audio Codec          September 2012


   | 2      |      1 |    2 |     4 |     8 |      400 Hz |     600 Hz |
   |        |        |      |       |       |             |            |
   | 3      |      1 |    2 |     4 |     8 |      600 Hz |     800 Hz |
   |        |        |      |       |       |             |            |
   | 4      |      1 |    2 |     4 |     8 |      800 Hz |    1000 Hz |
   |        |        |      |       |       |             |            |
   | 5      |      1 |    2 |     4 |     8 |     1000 Hz |    1200 Hz |
   |        |        |      |       |       |             |            |
   | 6      |      1 |    2 |     4 |     8 |     1200 Hz |    1400 Hz |
   |        |        |      |       |       |             |            |
   | 7      |      1 |    2 |     4 |     8 |     1400 Hz |    1600 Hz |
   |        |        |      |       |       |             |            |
   | 8      |      2 |    4 |     8 |    16 |     1600 Hz |    2000 Hz |
   |        |        |      |       |       |             |            |
   | 9      |      2 |    4 |     8 |    16 |     2000 Hz |    2400 Hz |
   |        |        |      |       |       |             |            |
   | 10     |      2 |    4 |     8 |    16 |     2400 Hz |    2800 Hz |
   |        |        |      |       |       |             |            |
   | 11     |      2 |    4 |     8 |    16 |     2800 Hz |    3200 Hz |
   |        |        |      |       |       |             |            |
   | 12     |      4 |    8 |    16 |    32 |     3200 Hz |    4000 Hz |
   |        |        |      |       |       |             |            |
   | 13     |      4 |    8 |    16 |    32 |     4000 Hz |    4800 Hz |
   |        |        |      |       |       |             |            |
   | 14     |      4 |    8 |    16 |    32 |     4800 Hz |    5600 Hz |
   |        |        |      |       |       |             |            |
   | 15     |      6 |   12 |    24 |    48 |     5600 Hz |    6800 Hz |
   |        |        |      |       |       |             |            |
   | 16     |      6 |   12 |    24 |    48 |     6800 Hz |    8000 Hz |
   |        |        |      |       |       |             |            |
   | 17     |      8 |   16 |    32 |    64 |     8000 Hz |    9600 Hz |
   |        |        |      |       |       |             |            |
   | 18     |     12 |   24 |    48 |    96 |     9600 Hz |   12000 Hz |
   |        |        |      |       |       |             |            |
   | 19     |     18 |   36 |    72 |   144 |    12000 Hz |   15600 Hz |
   |        |        |      |       |       |             |            |
   | 20     |     22 |   44 |    88 |   176 |    15600 Hz |   20000 Hz |
   +--------+--------+------+-------+-------+-------------+------------+

       Table 55: MDCT Bins per Channel per Band for Each Frame Size

   Transients are notoriously difficult for transform codecs to code.
   CELT uses two different strategies for them:

   1.  Using multiple smaller MDCTs instead of a single large MDCT, and

   2.  Dynamic time-frequency resolution changes (See Section 4.3.4.5).




Valin, et al.                Standards Track                  [Page 105]

RFC 6716                 Interactive Audio Codec          September 2012


   To improve quality on highly tonal and periodic signals, CELT
   includes a pre-filter/post-filter combination.  The pre-filter on the
   encoder side attenuates the signal's harmonics.  The post-filter on
   the decoder side restores the original gain of the harmonics, while
   shaping the coding noise to roughly follow the harmonics.  Such noise
   shaping reduces the perception of the noise.

   When coding a stereo signal, three coding methods are available:

   o  mid-side stereo: encodes the mean and the difference of the left
      and right channels,

   o  intensity stereo: only encodes the mean of the left and right
      channels (discards the difference),

   o  dual stereo: encodes the left and right channels separately.

   An overview of the decoder is given in Figure 17.

                       +---------+
                       | Coarse  |
                    +->| decoder |----+
                    |  +---------+    |
                    |                 |
                    |  +---------+    v
                    |  |  Fine   |  +---+
                    +->| decoder |->| + |
                    |  +---------+  +---+
                    |       ^         |
        +---------+ |       |         |
        |  Range  | | +----------+    v
        | Decoder |-+ |   Bit    | +------+
        +---------+ | |Allocation| | 2**x |
                    | +----------+ +------+
                    |       |         |
                    |       v         v               +--------+
                    |  +---------+  +---+  +-------+  | pitch  |
                    +->|   PVQ   |->| * |->| IMDCT |->| post-  |--->
                    |  | decoder |  +---+  +-------+  | filter |
                    |  +---------+                    +--------+
                    |                                      ^
                    +--------------------------------------+

        Legend: IMDCT = Inverse MDCT

                 Figure 17: Structure of the CELT decoder

   The decoder is based on the following symbols and sets of symbols:



Valin, et al.                Standards Track                  [Page 106]

RFC 6716                 Interactive Audio Codec          September 2012


          +---------------+---------------------+---------------+
          |   Symbol(s)   |         PDF         |   Condition   |
          +---------------+---------------------+---------------+
          |    silence    |   {32767, 1}/32768  |               |
          |               |                     |               |
          |  post-filter  |       {1, 1}/2      |               |
          |               |                     |               |
          |     octave    |     uniform (6)     |  post-filter  |
          |               |                     |               |
          |     period    | raw bits (4+octave) |  post-filter  |
          |               |                     |               |
          |      gain     |     raw bits (3)    |  post-filter  |
          |               |                     |               |
          |     tapset    |     {2, 1, 1}/4     |  post-filter  |
          |               |                     |               |
          |   transient   |       {7, 1}/8      |               |
          |               |                     |               |
          |     intra     |       {7, 1}/8      |               |
          |               |                     |               |
          | coarse energy |    Section 4.3.2    |               |
          |               |                     |               |
          |   tf_change   |    Section 4.3.1    |               |
          |               |                     |               |
          |   tf_select   |       {1, 1}/2      | Section 4.3.1 |
          |               |                     |               |
          |     spread    |   {7, 2, 21, 2}/32  |               |
          |               |                     |               |
          |  dyn. alloc.  |    Section 4.3.3    |               |
          |               |                     |               |
          |  alloc. trim  |       Table 58      |               |
          |               |                     |               |
          |      skip     |       {1, 1}/2      | Section 4.3.3 |
          |               |                     |               |
          |   intensity   |       uniform       | Section 4.3.3 |
          |               |                     |               |
          |      dual     |       {1, 1}/2      |               |
          |               |                     |               |
          |  fine energy  |    Section 4.3.2    |               |
          |               |                     |               |
          |    residual   |    Section 4.3.4    |               |
          |               |                     |               |
          | anti-collapse |       {1, 1}/2      | Section 4.3.5 |
          |               |                     |               |
          |    finalize   |    Section 4.3.2    |               |
          +---------------+---------------------+---------------+

    Table 56: Order of the Symbols in the CELT Section of the Bitstream




Valin, et al.                Standards Track                  [Page 107]

RFC 6716                 Interactive Audio Codec          September 2012


   The decoder extracts information from the range-coded bitstream in
   the order described in Table 56.  In some circumstances, it is
   possible for a decoded value to be out of range due to a very small
   amount of redundancy in the encoding of large integers by the range
   coder.  In that case, the decoder should assume there has been an
   error in the coding, decoding, or transmission and SHOULD take
   measures to conceal the error and/or report to the application that a
   problem has occurred.  Such out of range errors cannot occur in the
   SILK layer.

4.3.1.  Transient Decoding



   The "transient" flag indicates whether the frame uses a single long
   MDCT or several short MDCTs.  When it is set, then the MDCT
   coefficients represent multiple short MDCTs in the frame.  When not
   set, the coefficients represent a single long MDCT for the frame.
   The flag is encoded in the bitstream with a probability of 1/8.  In
   addition to the global transient flag is a per-band binary flag to
   change the time-frequency (tf) resolution independently in each band.
   The change in tf resolution is defined in tf_select_table[][] in
   celt.c and depends on the frame size, whether the transient flag is
   set, and the value of tf_select.  The tf_select flag uses a 1/2
   probability, but is only decoded if it can have an impact on the
   result knowing the value of all per-band tf_change flags.

4.3.2.  Energy Envelope Decoding



   It is important to quantize the energy with sufficient resolution
   because any energy quantization error cannot be compensated for at a
   later stage.  Regardless of the resolution used for encoding the
   spectral shape of a band, it is perceptually important to preserve
   the energy in each band.  CELT uses a three-step coarse-fine-fine
   strategy for encoding the energy in the base-2 log domain, as
   implemented in quant_bands.c.

4.3.2.1.  Coarse Energy Decoding



   Coarse quantization of the energy uses a fixed resolution of 6 dB
   (integer part of base-2 log).  To minimize the bitrate, prediction is
   applied both in time (using the previous frame) and in frequency
   (using the previous bands).  The part of the prediction that is based
   on the previous frame can be disabled, creating an "intra" frame
   where the energy is coded without reference to prior frames.  The
   decoder first reads the intra flag to determine what prediction is
   used.  The 2-D z-transform [Z-TRANSFORM] of the prediction filter is






Valin, et al.                Standards Track                  [Page 108]

RFC 6716                 Interactive Audio Codec          September 2012


                                            -1          -1
                              (1 - alpha*z_l  )*(1 - z_b  )
                A(z_l, z_b) = -----------------------------
                                                 -1
                                     1 - beta*z_b

   where b is the band index and l is the frame index.  The prediction
   coefficients applied depend on the frame size in use when not using
   intra energy and are alpha=0, beta=4915/32768 when using intra
   energy.  The time-domain prediction is based on the final fine
   quantization of the previous frame, while the frequency domain
   (within the current frame) prediction is based on coarse quantization
   only (because the fine quantization has not been computed yet).  The
   prediction is clamped internally so that fixed-point implementations
   with limited dynamic range always remain in the same state as
   floating point implementations.  We approximate the ideal probability
   distribution of the prediction error using a Laplace distribution
   with separate parameters for each frame size in intra- and inter-
   frame modes.  These parameters are held in the e_prob_model table in
   quant_bands.c.  The coarse energy decoding is performed by
   unquant_coarse_energy() (quant_bands.c).  The decoding of the
   Laplace-distributed values is implemented in ec_laplace_decode()
   (laplace.c).

4.3.2.2.  Fine Energy Quantization



   The number of bits assigned to fine energy quantization in each band
   is determined by the bit allocation computation described in
   Section 4.3.3.  Let B_i be the number of fine energy bits for band i;
   the refinement is an integer f in the range [0,2**B_i-1].  The
   mapping between f and the correction applied to the coarse energy is
   equal to (f+1/2)/2**B_i - 1/2.  Fine energy quantization is
   implemented in quant_fine_energy() (quant_bands.c).

   When some bits are left "unused" after all other flags have been
   decoded, these bits are assigned to a "final" step of fine
   allocation.  In effect, these bits are used to add one extra fine
   energy bit per band per channel.  The allocation process determines
   two "priorities" for the final fine bits.  Any remaining bits are
   first assigned only to bands of priority 0, starting from band 0 and
   going up.  If all bands of priority 0 have received one bit per
   channel, then bands of priority 1 are assigned an extra bit per
   channel, starting from band 0.  If any bits are left after this, they
   are left unused.  This is implemented in unquant_energy_finalise()
   (quant_bands.c).






Valin, et al.                Standards Track                  [Page 109]

RFC 6716                 Interactive Audio Codec          September 2012


4.3.3.  Bit Allocation



   Because the bit allocation drives the decoding of the range-coder
   stream, it MUST be recovered exactly so that identical coding
   decisions are made in the encoder and decoder.  Any deviation from
   the reference's resulting bit allocation will result in corrupted
   output, though implementers are free to implement the procedure in
   any way that produces identical results.

   The per-band gain-shape structure of the CELT layer ensures that
   using the same number of bits for the spectral shape of a band in
   every frame will result in a roughly constant signal-to-noise ratio
   in that band.  This results in coding noise that has the same
   spectral envelope as the signal.  The masking curve produced by a
   standard psychoacoustic model also closely follows the spectral
   envelope of the signal.  This structure means that the ideal
   allocation is more consistent from frame to frame than it is for
   other codecs without an equivalent structure and that a fixed
   allocation provides fairly consistent perceptual
   performance [VALIN2010].

   Many codecs transmit significant amounts of side information to
   control the bit allocation within a frame.  Often this control is
   only indirect, and it must be exercised carefully to achieve the
   desired rate constraints.  The CELT layer, however, can adapt over a
   very wide range of rates, so it has a large number of codebook sizes
   to choose from for each band.  Explicitly signaling the size of each
   of these codebooks would impose considerable overhead, even though
   the allocation is relatively static from frame to frame.  This is
   because all of the information required to compute these codebook
   sizes must be derived from a single frame by itself, in order to
   retain robustness to packet loss, so the signaling cannot take
   advantage of knowledge of the allocation in neighboring frames.  This
   problem is exacerbated in low-latency (small frame size)
   applications, which would include this overhead in every frame.

   For this reason, in the MDCT mode, Opus uses a primarily implicit bit
   allocation.  The available bitstream capacity is known in advance to
   both the encoder and decoder without additional signaling, ultimately
   from the packet sizes expressed by a higher-level protocol.  Using
   this information, the codec interpolates an allocation from a hard-
   coded table.

   While the band-energy structure effectively models intra-band
   masking, it ignores the weaker inter-band masking, band-temporal
   masking, and other less significant perceptual effects.  While these
   effects can often be ignored, they can become significant for
   particular samples.  One mechanism available to encoders would be to



Valin, et al.                Standards Track                  [Page 110]

RFC 6716                 Interactive Audio Codec          September 2012


   simply increase the overall rate for these frames, but this is not
   possible in a constant rate mode and can be fairly inefficient.  As a
   result three explicitly signaled mechanisms are provided to alter the
   implicit allocation:

   o  Band boost

   o  Allocation trim

   o  Band skipping

   The first of these mechanisms, band boost, allows an encoder to boost
   the allocation in specific bands.  The second, allocation trim, works
   by biasing the overall allocation towards higher or lower frequency
   bands.  The third, band skipping, selects which low-precision high
   frequency bands will be allocated no shape bits at all.

   In stereo mode, there are two additional parameters potentially coded
   as part of the allocation procedure: a parameter to allow the
   selective elimination of allocation for the 'side' (i.e., intensity
   stereo) in jointly coded bands, and a flag to deactivate joint coding
   (i.e., dual stereo).  These values are not signaled if they would be
   meaningless in the overall context of the allocation.

   Because every signaled adjustment increases overhead and
   implementation complexity, none were included speculatively: the
   reference encoder makes use of all of these mechanisms.  While the
   decision logic in the reference was found to be effective enough to
   justify the overhead and complexity, further analysis techniques may
   be discovered that increase the effectiveness of these parameters.
   As with other signaled parameters, an encoder is free to choose the
   values in any manner, but, unless a technique is known to deliver
   superior perceptual results, the methods used by the reference
   implementation should be used.

   The allocation process consists of the following steps: determining
   the per-band maximum allocation vector, decoding the boosts, decoding
   the tilt, determining the remaining capacity of the frame, searching
   the mode table for the entry nearest but not exceeding the available
   space (subject to the tilt, boosts, band maximums, and band
   minimums), linear interpolation, reallocation of unused bits with
   concurrent skip decoding, determination of the fine-energy vs. shape
   split, and final reallocation.  This process results in a per-band
   shape allocation (in 1/8th-bit units), a per-band fine-energy
   allocation (in 1 bit per channel units), a set of band priorities for
   controlling the use of remaining bits at the end of the frame, and a
   remaining balance of unallocated space, which is usually zero except
   at very high rates.



Valin, et al.                Standards Track                  [Page 111]

RFC 6716                 Interactive Audio Codec          September 2012


   The "static" bit allocation (in 1/8 bits) for a quality q, excluding
   the minimums, maximums, tilt and boosts, is equal to
   channels*N*alloc[band][q]<<LM>>2, where alloc[][] is given in
   Table 57 and LM=log2(frame_size/120).  The allocation is obtained by
   linearly interpolating between two values of q (in steps of 1/64) to
   find the highest allocation that does not exceed the number of bits
   remaining.

    Rows indicate the MDCT bands, columns are the different quality (q)
             parameters.  The units are 1/32 bit per MDCT bin.

     +---+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
     | 0 |  1 |   2 |   3 |   4 |   5 |   6 |   7 |   8 |   9 |  10 |
     +---+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
     | 0 | 90 | 110 | 118 | 126 | 134 | 144 | 152 | 162 | 172 | 200 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 80 | 100 | 110 | 119 | 127 | 137 | 145 | 155 | 165 | 200 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 75 |  90 | 103 | 112 | 120 | 130 | 138 | 148 | 158 | 200 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 69 |  84 |  93 | 104 | 114 | 124 | 132 | 142 | 152 | 200 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 63 |  78 |  86 |  95 | 103 | 113 | 123 | 133 | 143 | 200 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 56 |  71 |  80 |  89 |  97 | 107 | 117 | 127 | 137 | 200 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 49 |  65 |  75 |  83 |  91 | 101 | 111 | 121 | 131 | 200 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 40 |  58 |  70 |  78 |  85 |  95 | 105 | 115 | 125 | 200 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 34 |  51 |  65 |  72 |  78 |  88 |  98 | 108 | 118 | 198 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 29 |  45 |  59 |  66 |  72 |  82 |  92 | 102 | 112 | 193 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 20 |  39 |  53 |  60 |  66 |  76 |  86 |  96 | 106 | 188 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 18 |  32 |  47 |  54 |  60 |  70 |  80 |  90 | 100 | 183 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 | 10 |  26 |  40 |  47 |  54 |  64 |  74 |  84 |  94 | 178 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 |  0 |  20 |  31 |  39 |  47 |  57 |  67 |  77 |  87 | 173 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 |  0 |  12 |  23 |  32 |  41 |  51 |  61 |  71 |  81 | 168 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 |  0 |   0 |  15 |  25 |  35 |  45 |  55 |  65 |  75 | 163 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 |  0 |   0 |   4 |  17 |  29 |  39 |  49 |  59 |  69 | 158 |
     |   |    |     |     |     |     |     |     |     |     |     |



Valin, et al.                Standards Track                  [Page 112]

RFC 6716                 Interactive Audio Codec          September 2012


     | 0 |  0 |   0 |   0 |  12 |  23 |  33 |  43 |  53 |  63 | 153 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 |  0 |   0 |   0 |   1 |  16 |  26 |  36 |  46 |  56 | 148 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 |  0 |   0 |   0 |   0 |  10 |  15 |  20 |  30 |  45 | 129 |
     |   |    |     |     |     |     |     |     |     |     |     |
     | 0 |  0 |   0 |   0 |   0 |   1 |   1 |   1 |   1 |  20 | 104 |
     +---+----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

                  Table 57: CELT Static Allocation Table

   The maximum allocation vector is an approximation of the maximum
   space that can be used by each band for a given mode.  The value is
   approximate because the shape encoding is variable rate (due to
   entropy coding of splitting parameters).  Setting the maximum too low
   reduces the maximum achievable quality in a band while setting it too
   high may result in waste: bitstream capacity available at the end of
   the frame that cannot be put to any use.  The maximums specified by
   the codec reflect the average maximum.  In the reference
   implementation, the maximums in bits/sample are precomputed in a
   static table (see cache_caps50[] in static_modes_float.h) for each
   band, for each value of LM, and for both mono and stereo.
   Implementations are expected to simply use the same table data, but
   the procedure for generating this table is included in rate.c as part
   of compute_pulse_cache().

   To convert the values in cache.caps into the actual maximums: first,
   set nbBands to the maximum number of bands for this mode, and stereo
   to zero if stereo is not in use and one otherwise.  For each band,
   set N to the number of MDCT bins covered by the band (for one
   channel), set LM to the shift value for the frame size.  Then, set i
   to nbBands*(2*LM+stereo).  Next, set the maximum for the band to the
   i-th index of cache.caps + 64 and multiply by the number of channels
   in the current frame (one or two) and by N, then divide the result by
   4 using integer division.  The resulting vector will be called cap[].
   The elements fit in signed 16-bit integers but do not fit in 8 bits.
   This procedure is implemented in the reference in the function
   init_caps() in celt.c.

   The band boosts are represented by a series of binary symbols that
   are entropy coded with very low probability.  Each band can
   potentially be boosted multiple times, subject to the frame actually
   having enough room to obey the boost and having enough room to code
   the boost symbol.  The default coding cost for a boost starts out at
   six bits (probability p=1/64), but subsequent boosts in a band cost
   only a single bit and every time a band is boosted the initial cost
   is reduced (down to a minimum of two bits, or p=1/4).  Since the




Valin, et al.                Standards Track                  [Page 113]

RFC 6716                 Interactive Audio Codec          September 2012


   initial cost of coding a boost is 6 bits, the coding cost of the
   boost symbols when completely unused is 0.48 bits/frame for a 21 band
   mode (21*-log2(1-1/2**6)).

   To decode the band boosts: First, set 'dynalloc_logp' to 6, the
   initial amount of storage required to signal a boost in bits,
   'total_bits' to the size of the frame in 8th bits, 'total_boost' to
   zero, and 'tell' to the total number of 8th bits decoded so far.  For
   each band from the coding start (0 normally, but 17 in Hybrid mode)
   to the coding end (which changes depending on the signaled
   bandwidth), the boost quanta in units of 1/8 bit is calculated as
   quanta = min(8*N, max(48, N)).  This represents a boost step size of
   six bits, subject to a lower limit of 1/8th bit/sample and an upper
   limit of 1 bit/sample.  Set 'boost' to zero and 'dynalloc_loop_logp'
   to dynalloc_logp.  While dynalloc_loop_log (the current worst case
   symbol cost) in 8th bits plus tell is less than total_bits plus
   total_boost and boost is less than cap[] for this band: Decode a bit
   from the bitstream with dynalloc_loop_logp as the cost of a one and
   update tell to reflect the current used capacity.  If the decoded
   value is zero break the loop.  Otherwise, add quanta to boost and
   total_boost, subtract quanta from total_bits, and set
   dynalloc_loop_log to 1.  When the loop finishes 'boost' contains the
   bit allocation boost for this band.  If boost is non-zero and
   dynalloc_logp is greater than 2, decrease dynalloc_logp.  Once this
   process has been executed on all bands, the band boosts have been
   decoded.  This procedure is implemented around line 2474 of celt.c.

   At very low rates, it is possible that there won't be enough
   available space to execute the inner loop even once.  In these cases,
   band boost is not possible, but its overhead is completely
   eliminated.  Because of the high cost of band boost when activated, a
   reasonable encoder should not be using it at very low rates.  The
   reference implements its dynalloc decision logic around line 1304 of
   celt.c.

   The allocation trim is an integer value from 0-10.  The default value
   of 5 indicates no trim.  The trim parameter is entropy coded in order
   to lower the coding cost of less extreme adjustments.  Values lower
   than 5 bias the allocation towards lower frequencies and values above
   5 bias it towards higher frequencies.  Like other signaled
   parameters, signaling of the trim is gated so that it is not included
   if there is insufficient space available in the bitstream.  To decode
   the trim, first set the trim value to 5, then if and only if the
   count of decoded 8th bits so far (ec_tell_frac) plus 48 (6 bits) is
   less than or equal to the total frame size in 8th bits minus
   total_boost (a product of the above band boost procedure), decode the
   trim value using the PDF in Table 58.




Valin, et al.                Standards Track                  [Page 114]

RFC 6716                 Interactive Audio Codec          September 2012


              +--------------------------------------------+
              | PDF                                        |
              +--------------------------------------------+
              | {2, 2, 5, 10, 22, 46, 22, 10, 5, 2, 2}/128 |
              +--------------------------------------------+

                        Table 58: PDF for the Trim

   For 10 ms and 20 ms frames using short blocks and that have at least
   LM+2 bits left prior to the allocation process, one anti-collapse bit
   is reserved in the allocation process so it can be decoded later.
   Following the anti-collapse reservation, one bit is reserved for skip
   if available.

   For stereo frames, bits are reserved for intensity stereo and for
   dual stereo.  Intensity stereo requires ilog2(end-start) bits.  Those
   bits are reserved if there are enough bits left.  Following this, one
   bit is reserved for dual stereo if available.

   The allocation computation begins by setting up some initial
   conditions. 'total' is set to the remaining available 8th bits,
   computed by taking the size of the coded frame times 8 and
   subtracting ec_tell_frac().  From this value, one (8th bit) is
   subtracted to ensure that the resulting allocation will be
   conservative. 'anti_collapse_rsv' is set to 8 (8th bits) if and only
   if the frame is a transient, LM is greater than 1, and total is
   greater than or equal to (LM+2) * 8.  Total is then decremented by
   anti_collapse_rsv and clamped to be equal to or greater than zero.
   'skip_rsv' is set to 8 (8th bits) if total is greater than 8,
   otherwise it is zero.  Total is then decremented by skip_rsv.  This
   reserves space for the final skipping flag.

   If the current frame is stereo, intensity_rsv is set to the
   conservative log2 in 8th bits of the number of coded bands for this
   frame (given by the table LOG2_FRAC_TABLE in rate.c).  If
   intensity_rsv is greater than total, then intensity_rsv is set to
   zero.  Otherwise, total is decremented by intensity_rsv, and if total
   is still greater than 8, dual_stereo_rsv is set to 8 and total is
   decremented by dual_stereo_rsv.

   The allocation process then computes a vector representing the hard
   minimum amounts allocation any band will receive for shape.  This
   minimum is higher than the technical limit of the PVQ process, but
   very low rate allocations produce an excessively sparse spectrum and
   these bands are better served by having no allocation at all.  For
   each coded band, set thresh[band] to 24 times the number of MDCT bins
   in the band and divide by 16.  If 8 times the number of channels is
   greater, use that instead.  This sets the minimum allocation to one



Valin, et al.                Standards Track                  [Page 115]

RFC 6716                 Interactive Audio Codec          September 2012


   bit per channel or 48 128th bits per MDCT bin, whichever is greater.
   The band-size dependent part of this value is not scaled by the
   channel count, because at the very low rates where this limit is
   applicable there will usually be no bits allocated to the side.

   The previously decoded allocation trim is used to derive a vector of
   per-band adjustments, 'trim_offsets[]'.  For each coded band take the
   alloc_trim and subtract 5 and LM.  Then, multiply the result by the
   number of channels, the number of MDCT bins in the shortest frame
   size for this mode, the number of remaining bands, 2**LM, and 8.
   Next, divide this value by 64.  Finally, if the number of MDCT bins
   in the band per channel is only one, 8 times the number of channels
   is subtracted in order to diminish the allocation by one bit, because
   width 1 bands receive greater benefit from the coarse energy coding.

4.3.4.  Shape Decoding



   In each band, the normalized "shape" is encoded using Pyramid Vector
   Quantizer.

   In the simplest case, the number of bits allocated in Section 4.3.3
   is converted to a number of pulses as described by Section 4.3.4.1.
   Knowing the number of pulses and the number of samples in the band,
   the decoder calculates the size of the codebook as detailed in
   Section 4.3.4.2.  The size is used to decode an unsigned integer
   (uniform probability model), which is the codeword index.  This index
   is converted into the corresponding vector as explained in
   Section 4.3.4.2.  This vector is then scaled to unit norm.

4.3.4.1.  Bits to Pulses



   Although the allocation is performed in 1/8th bit units, the
   quantization requires an integer number of pulses K.  To do this, the
   encoder searches for the value of K that produces the number of bits
   nearest to the allocated value (rounding down if exactly halfway
   between two values), not to exceed the total number of bits
   available.  For efficiency reasons, the search is performed against a
   precomputed allocation table that only permits some K values for each
   N.  The number of codebook entries can be computed as explained in
   Section 4.3.4.2.  The difference between the number of bits allocated
   and the number of bits used is accumulated to a "balance"
   (initialized to zero) that helps adjust the allocation for the next
   bands.  One third of the balance is applied to the bit allocation of
   each band to help achieve the target allocation.  The only exceptions
   are the band before the last and the last band, for which half the
   balance and the whole balance are applied, respectively.





Valin, et al.                Standards Track                  [Page 116]

RFC 6716                 Interactive Audio Codec          September 2012


4.3.4.2.  PVQ Decoding



   Decoding of PVQ vectors is implemented in decode_pulses() (cwrs.c).
   The unique codeword index is decoded as a uniformly distributed
   integer value between 0 and V(N,K)-1, where V(N,K) is the number of
   possible combinations of K pulses in N samples.  The index is then
   converted to a vector in the same way specified in [PVQ].  The
   indexing is based on the calculation of V(N,K) (denoted N(L,K) in
   [PVQ]).

   The number of combinations can be computed recursively as V(N,K) =
   V(N-1,K) + V(N,K-1) + V(N-1,K-1), with V(N,0) = 1 and V(0,K) = 0, K
   != 0.  There are many different ways to compute V(N,K), including
   precomputed tables and direct use of the recursive formulation.  The
   reference implementation applies the recursive formulation one line
   (or column) at a time to save on memory use, along with an alternate,
   univariate recurrence to initialize an arbitrary line, and direct
   polynomial solutions for small N.  All of these methods are
   equivalent, and have different trade-offs in speed, memory usage, and
   code size.  Implementations MAY use any methods they like, as long as
   they are equivalent to the mathematical definition.

   The decoded vector X is recovered as follows.  Let i be the index
   decoded with the procedure in Section 4.1.5 with ft = V(N,K), so that
   0 <= i < V(N,K).  Let k = K.  Then, for j = 0 to (N - 1), inclusive,
   do:

   1.  Let p = (V(N-j-1,k) + V(N-j,k))/2.

   2.  If i < p, then let sgn = 1, else let sgn = -1 and set i = i - p.

   3.  Let k0 = k and set p = p - V(N-j-1,k).

   4.  While p > i, set k = k - 1 and p = p - V(N-j-1,k).

   5.  Set X[j] = sgn*(k0 - k) and i = i - p.



   The decoded vector X is then normalized such that its L2-norm equals
   one.

4.3.4.3.  Spreading



   The normalized vector decoded in Section 4.3.4.2 is then rotated for
   the purpose of avoiding tonal artifacts.  The rotation gain is equal
   to

                           g_r = N / (N + f_r*K)




Valin, et al.                Standards Track                  [Page 117]

RFC 6716                 Interactive Audio Codec          September 2012


   where N is the number of dimensions, K is the number of pulses, and
   f_r depends on the value of the "spread" parameter in the bitstream.

                 +--------------+------------------------+
                 | Spread value | f_r                    |
                 +--------------+------------------------+
                 | 0            | infinite (no rotation) |
                 |              |                        |
                 | 1            | 15                     |
                 |              |                        |
                 | 2            | 10                     |
                 |              |                        |
                 | 3            | 5                      |
                 +--------------+------------------------+

                        Table 59: Spreading Values

   The rotation angle is then calculated as

                                              2
                                     pi *  g_r
                             theta = ----------
                                         4

   A 2-D rotation R(i,j) between points x_i and x_j is defined as:

                  x_i' =  cos(theta)*x_i + sin(theta)*x_j
                  x_j' = -sin(theta)*x_i + cos(theta)*x_j

   An N-D rotation is then achieved by applying a series of 2-D
   rotations back and forth, in the following order: R(x_1, x_2), R(x_2,
   x_3), ..., R(x_N-2, X_N-1), R(x_N-1, X_N), R(x_N-2, X_N-1), ...,
   R(x_1, x_2).

   If the decoded vector represents more than one time block, then this
   spreading process is applied separately on each time block.  Also, if
   each block represents 8 samples or more, then another N-D rotation,
   by (pi/2-theta), is applied _before_ the rotation described above.
   This extra rotation is applied in an interleaved manner with a stride
   equal to round(sqrt(N/nb_blocks)), i.e., it is applied independently
   for each set of sample S_k = {stride*n + k}, n=0..N/stride-1.

4.3.4.4.  Split Decoding



   To avoid the need for multi-precision calculations when decoding PVQ
   codevectors, the maximum size allowed for codebooks is 32 bits.  When
   larger codebooks are needed, the vector is instead split in two sub-
   vectors of size N/2.  A quantized gain parameter with precision



Valin, et al.                Standards Track                  [Page 118]

RFC 6716                 Interactive Audio Codec          September 2012


   derived from the current allocation is entropy coded to represent the
   relative gains of each side of the split, and the entire decoding
   process is recursively applied.  Multiple levels of splitting may be
   applied up to a limit of LM+1 splits.  The same recursive mechanism
   is applied for the joint coding of stereo audio.

4.3.4.5.  Time-Frequency Change



   The time-frequency (TF) parameters are used to control the time-
   frequency resolution trade-off in each coded band.  For each band,
   there are two possible TF choices.  For the first band coded, the PDF
   is {3, 1}/4 for frames marked as transient and {15, 1}/16 for the
   other frames.  For subsequent bands, the TF choice is coded relative
   to the previous TF choice with probability {15, 1}/16 for transient
   frames and {31, 1}/32 otherwise.  The mapping between the decoded TF
   choices and the adjustment in TF resolution is shown in the tables
   below.

                       +-----------------+---+----+
                       | Frame size (ms) | 0 |  1 |
                       +-----------------+---+----+
                       |       2.5       | 0 | -1 |
                       |                 |   |    |
                       |        5        | 0 | -1 |
                       |                 |   |    |
                       |        10       | 0 | -2 |
                       |                 |   |    |
                       |        20       | 0 | -2 |
                       +-----------------+---+----+

     Table 60: TF Adjustments for Non-transient Frames and tf_select=0

                       +-----------------+---+----+
                       | Frame size (ms) | 0 |  1 |
                       +-----------------+---+----+
                       |       2.5       | 0 | -1 |
                       |                 |   |    |
                       |        5        | 0 | -2 |
                       |                 |   |    |
                       |        10       | 0 | -3 |
                       |                 |   |    |
                       |        20       | 0 | -3 |
                       +-----------------+---+----+

     Table 61: TF Adjustments for Non-transient Frames and tf_select=1






Valin, et al.                Standards Track                  [Page 119]

RFC 6716                 Interactive Audio Codec          September 2012


                       +-----------------+---+----+
                       | Frame size (ms) | 0 |  1 |
                       +-----------------+---+----+
                       |       2.5       | 0 | -1 |
                       |                 |   |    |
                       |        5        | 1 |  0 |
                       |                 |   |    |
                       |        10       | 2 |  0 |
                       |                 |   |    |
                       |        20       | 3 |  0 |
                       +-----------------+---+----+

       Table 62: TF Adjustments for Transient Frames and tf_select=0

                       +-----------------+---+----+
                       | Frame size (ms) | 0 |  1 |
                       +-----------------+---+----+
                       |       2.5       | 0 | -1 |
                       |                 |   |    |
                       |        5        | 1 | -1 |
                       |                 |   |    |
                       |        10       | 1 | -1 |
                       |                 |   |    |
                       |        20       | 1 | -1 |
                       +-----------------+---+----+

       Table 63: TF Adjustments for Transient Frames and tf_select=1

   A negative TF adjustment means that the temporal resolution is
   increased, while a positive TF adjustment means that the frequency
   resolution is increased.  Changes in TF resolution are implemented
   using the Hadamard transform [HADAMARD].  To increase the time
   resolution by N, N "levels" of the Hadamard transform are applied to
   the decoded vector for each interleaved MDCT vector.  To increase the
   frequency resolution (assumes a transient frame), then N levels of
   the Hadamard transform are applied _across_ the interleaved MDCT
   vector.  In the case of increased time resolution, the decoder uses
   the "sequency order" because the input vector is sorted in time.

4.3.5.  Anti-collapse Processing



   The anti-collapse feature is designed to avoid the situation where
   the use of multiple short MDCTs causes the energy in one or more of
   the MDCTs to be zero for some bands, causing unpleasant artifacts.
   When the frame has the transient bit set, an anti-collapse bit is
   decoded.  When anti-collapse is set, the energy in each small MDCT is
   prevented from collapsing to zero.  For each band of each MDCT where
   a collapse is detected, a pseudo-random signal is inserted with an



Valin, et al.                Standards Track                  [Page 120]

RFC 6716                 Interactive Audio Codec          September 2012


   energy corresponding to the minimum energy over the two previous
   frames.  A renormalization step is then required to ensure that the
   anti-collapse step did not alter the energy preservation property.

4.3.6.  Denormalization



   Just as each band was normalized in the encoder, the last step of the
   decoder before the inverse MDCT is to denormalize the bands.  Each
   decoded normalized band is multiplied by the square root of the
   decoded energy.  This is done by denormalise_bands() (bands.c).

4.3.7.  Inverse MDCT



   The inverse MDCT implementation has no special characteristics.  The
   input is N frequency-domain samples and the output is 2*N time-domain
   samples, while scaling by 1/2.  A "low-overlap" window reduces the
   algorithmic delay.  It is derived from a basic (full-overlap) 240-
   sample version of the window used by the Vorbis codec:

                                                         2
                          /   /pi      /pi   n + 1/2\ \ \
                   W(n) = |sin|-- * sin|-- * -------| | |
                          \   \2       \2       L   / / /

   The low-overlap window is created by zero-padding the basic window
   and inserting ones in the middle, such that the resulting window
   still satisfies power complementarity [PRINCEN86].  The IMDCT and
   windowing are performed by mdct_backward (mdct.c).

4.3.7.1.  Post-Filter



   The output of the inverse MDCT (after weighted overlap-add) is sent
   to the post-filter.  Although the post-filter is applied at the end,
   the post-filter parameters are encoded at the beginning, just after
   the silence flag.  The post-filter can be switched on or off using
   one bit (logp=1).  If the post-filter is enabled, then the octave is
   decoded as an integer value between 0 and 6 of uniform probability.
   Once the octave is known, the fine pitch within the octave is decoded
   using 4+octave raw bits.  The final pitch period is equal to
   (16<<octave)+fine_pitch-1 so it is bounded between 15 and 1022,
   inclusively.  Next, the gain is decoded as three raw bits and is
   equal to G=3*(int_gain+1)/32.  The set of post-filter taps is decoded
   last, using a pdf equal to {2, 1, 1}/4.  Tapset zero corresponds to
   the filter coefficients g0 = 0.3066406250, g1 = 0.2170410156, g2 =
   0.1296386719.  Tapset one corresponds to the filter coefficients g0 =
   0.4638671875, g1 = 0.2680664062, g2 = 0, and tapset two uses filter
   coefficients g0 = 0.7998046875, g1 = 0.1000976562, g2 = 0.




Valin, et al.                Standards Track                  [Page 121]

RFC 6716                 Interactive Audio Codec          September 2012


   The post-filter response is thus computed as:


             y(n) = x(n) + G*(g0*y(n-T) + g1*(y(n-T+1)+y(n-T+1))
                                        + g2*(y(n-T+2)+y(n-T+2)))


   During a transition between different gains, a smooth transition is
   calculated using the square of the MDCT window.  It is important that
   values of y(n) be interpolated one at a time such that the past value
   of y(n) used is interpolated.

4.3.7.2.  De-emphasis



   After the post-filter, the signal is de-emphasized using the inverse
   of the pre-emphasis filter used in the encoder:

                            1            1
                           ---- = ---------------
                           A(z)                -1
                                  1 - alpha_p*z

   where alpha_p=0.8500061035.

4.4.  Packet Loss Concealment (PLC)



   Packet Loss Concealment (PLC) is an optional decoder-side feature
   that SHOULD be included when receiving from an unreliable channel.
   Because PLC is not part of the bitstream, there are many acceptable
   ways to implement PLC with different complexity/quality trade-offs.

   The PLC in the reference implementation depends on the mode of last
   packet received.  In CELT mode, the PLC finds a periodicity in the
   decoded signal and repeats the windowed waveform using the pitch
   offset.  The windowed waveform is overlapped in such a way as to
   preserve the time-domain aliasing cancellation with the previous
   frame and the next frame.  This is implemented in celt_decode_lost()
   (mdct.c).  In SILK mode, the PLC uses LPC extrapolation from the
   previous frame, implemented in silk_PLC() (PLC.c).

4.4.1.  Clock Drift Compensation



   Clock drift refers to the gradual desynchronization of two endpoints
   whose sample clocks run at different frequencies while they are
   streaming live audio.  Differences in clock frequencies are generally
   attributable to manufacturing variation in the endpoints' clock
   hardware.  For long-lived streams, the time difference between sender
   and receiver can grow without bound.



Valin, et al.                Standards Track                  [Page 122]

RFC 6716                 Interactive Audio Codec          September 2012


   When the sender's clock runs slower than the receiver's, the effect
   is similar to packet loss: too few packets are received.  The
   receiver can distinguish between drift and loss if the transport
   provides packet timestamps.  A receiver for live streams SHOULD
   conceal the effects of drift, and it MAY do so by invoking the PLC.

   When the sender's clock runs faster than the receiver's, too many
   packets will be received.  The receiver MAY respond by skipping any
   packet (i.e., not submitting the packet for decoding).  This is
   likely to produce a less severe artifact than if the frame were
   dropped after decoding.

   A decoder MAY employ a more sophisticated drift compensation method.
   For example, the NetEQ component [GOOGLE-NETEQ] of the Google WebRTC
   codebase [GOOGLE-WEBRTC] compensates for drift by adding or removing
   one period when the signal is highly periodic.  The reference
   implementation of Opus allows a caller to learn whether the current
   frame's signal is highly periodic, and if so what the period is,
   using the OPUS_GET_PITCH() request.

4.5.  Configuration Switching



   Switching between the Opus coding modes, audio bandwidths, and
   channel counts requires careful consideration to avoid audible
   glitches.  Switching between any two configurations of the CELT-only
   mode, any two configurations of the Hybrid mode, or from WB SILK to
   Hybrid mode does not require any special treatment in the decoder, as
   the MDCT overlap will smooth the transition.  Switching from Hybrid
   mode to WB SILK requires adding in the final contents of the CELT
   overlap buffer to the first SILK-only packet.  This can be done by
   decoding a 2.5 ms silence frame with the CELT decoder using the
   channel count of the SILK-only packet (and any choice of audio
   bandwidth), which will correctly handle the cases when the channel
   count changes as well.

   When changing the channel count for SILK-only or Hybrid packets, the
   encoder can avoid glitches by smoothly varying the stereo width of
   the input signal before or after the transition, and it SHOULD do so.
   However, other transitions between SILK-only packets or between NB or
   MB SILK and Hybrid packets may cause glitches, because neither the
   LSF coefficients nor the LTP, LPC, stereo unmixing, and resampler
   buffers are available at the new sample rate.  These switches SHOULD
   be delayed by the encoder until quiet periods or transients, where
   the inevitable glitches will be less audible.  Additionally, the
   bitstream MAY include redundant side information ("redundancy"), in
   the form of additional CELT frames embedded in each of the Opus
   frames around the transition.




Valin, et al.                Standards Track                  [Page 123]

RFC 6716                 Interactive Audio Codec          September 2012


   The other transitions that cannot be easily handled are those where
   the lower frequencies switch between the SILK LP-based model and the
   CELT MDCT model.  However, an encoder may not have an opportunity to
   delay such a switch to a convenient point.  For example, if the
   content switches from speech to music, and the encoder does not have
   enough latency in its analysis to detect this in advance, there may
   be no convenient silence period during which to make the transition
   for quite some time.  To avoid or reduce glitches during these
   problematic mode transitions, and between audio bandwidth changes in
   the SILK-only modes, transitions MAY include redundant side
   information ("redundancy"), in the form of an additional CELT frame
   embedded in the Opus frame.

   A transition between coding the lower frequencies with the LP model
   and the MDCT model or a transition that involves changing the SILK
   bandwidth is only normatively specified when it includes redundancy.
   For those without redundancy, it is RECOMMENDED that the decoder use
   a concealment technique (e.g., make use of a PLC algorithm) to "fill
   in" the gap or discontinuity caused by the mode transition.
   Therefore, PLC MUST NOT be applied during any normative transition,
   i.e., when

   o  A packet includes redundancy for this transition (as described
      below),

   o  The transition is between any WB SILK packet and any Hybrid
      packet, or vice versa,

   o  The transition is between any two Hybrid mode packets, or

   o  The transition is between any two CELT mode packets,

   unless there is actual packet loss.

4.5.1.  Transition Side Information (Redundancy)



   Transitions with side information include an extra 5 ms "redundant"
   CELT frame within the Opus frame.  This frame is designed to fill in
   the gap or discontinuity in the different layers without requiring
   the decoder to conceal it.  For transitions from CELT-only to SILK-
   only or Hybrid, the redundant frame is inserted in the first Opus
   frame after the transition (i.e., the first SILK-only or Hybrid
   frame).  For transitions from SILK-only or Hybrid to CELT-only, the
   redundant frame is inserted in the last Opus frame before the
   transition (i.e., the last SILK-only or Hybrid frame).






Valin, et al.                Standards Track                  [Page 124]

RFC 6716                 Interactive Audio Codec          September 2012


4.5.1.1.  Redundancy Flag



   The presence of redundancy is signaled in all SILK-only and Hybrid
   frames, not just those involved in a mode transition.  This allows
   the frames to be decoded correctly even if an adjacent frame is lost.
   For SILK-only frames, this signaling is implicit, based on the size
   of the Opus frame and the number of bits consumed decoding the SILK
   portion of it.  After decoding the SILK portion of the Opus frame,
   the decoder uses ec_tell() (see Section 4.1.6.1) to check if there
   are at least 17 bits remaining.  If so, then the frame contains
   redundancy.

   For Hybrid frames, this signaling is explicit.  After decoding the
   SILK portion of the Opus frame, the decoder uses ec_tell() (see
   Section 4.1.6.1) to ensure there are at least 37 bits remaining.  If
   so, it reads a symbol with the PDF in Table 64, and if the value is
   1, then the frame contains redundancy.  Otherwise (if there were
   fewer than 37 bits left or the value was 0), the frame does not
   contain redundancy.

                            +----------------+
                            | PDF            |
                            +----------------+
                            | {4095, 1}/4096 |
                            +----------------+

                       Table 64: Redundancy Flag PDF

4.5.1.2.  Redundancy Position Flag



   Since the current frame is a SILK-only or a Hybrid frame, it must be
   at least 10 ms.  Therefore, it needs an additional flag to indicate
   whether the redundant 5 ms CELT frame should be mixed into the
   beginning of the current frame, or the end.  After determining that a
   frame contains redundancy, the decoder reads a 1 bit symbol with a
   uniform PDF (Table 65).

                               +----------+
                               | PDF      |
                               +----------+
                               | {1, 1}/2 |
                               +----------+

                     Table 65: Redundancy Position PDF







Valin, et al.                Standards Track                  [Page 125]

RFC 6716                 Interactive Audio Codec          September 2012


   If the value is zero, this is the first frame in the transition, and
   the redundancy belongs at the end.  If the value is one, this is the
   second frame in the transition, and the redundancy belongs at the
   beginning.  There is no way to specify that an Opus frame contains
   separate redundant CELT frames at both the beginning and the end.

4.5.1.3.  Redundancy Size



   Unlike the CELT portion of a Hybrid frame, the redundant CELT frame
   does not use the same entropy coder state as the rest of the Opus
   frame, because this would break the CELT bit allocation mechanism in
   Hybrid frames.  Thus, a redundant CELT frame always starts and ends
   on a byte boundary, even in SILK-only frames, where this is not
   strictly necessary.

   For SILK-only frames, the number of bytes in the redundant CELT frame
   is simply the number of whole bytes remaining, which must be at least
   2, due to the space check in Section 4.5.1.1.  For Hybrid frames, the
   number of bytes is equal to 2, plus a decoded unsigned integer less
   than 256 (see Section 4.1.5).  This may be more than the number of
   whole bytes remaining in the Opus frame, in which case the frame is
   invalid.  However, a decoder is not required to ignore the entire
   frame, as this may be the result of a bit error that desynchronized
   the range coder.  There may still be useful data before the error,
   and a decoder MAY keep any audio decoded so far instead of invoking
   the PLC, but it is RECOMMENDED that the decoder stop decoding and
   discard the rest of the current Opus frame.

   It would have been possible to avoid these invalid states in the
   design of Opus by limiting the range of the explicit length decoded
   from Hybrid frames by the actual number of whole bytes remaining.
   However, this would require an encoder to determine the rate
   allocation for the MDCT layer up front, before it began encoding that
   layer.  By allowing some invalid sizes, the encoder is able to defer
   that decision until much later.  When encoding Hybrid frames that do
   not include redundancy, the encoder must still decide up front if it
   wishes to use the minimum 37 bits required to trigger encoding of the
   redundancy flag, but this is a much looser restriction.

   After determining the size of the redundant CELT frame, the decoder
   reduces the size of the buffer currently in use by the range coder by
   that amount.  The MDCT layer reads any raw bits from the end of this
   reduced buffer, and all calculations of the number of bits remaining
   in the buffer must be done using this new, reduced size, rather than
   the original size of the Opus frame.






Valin, et al.                Standards Track                  [Page 126]

RFC 6716                 Interactive Audio Codec          September 2012


4.5.1.4.  Decoding the Redundancy



   The redundant frame is decoded like any other CELT-only frame, with
   the exception that it does not contain a TOC byte.  The frame size is
   fixed at 5 ms, the channel count is set to that of the current frame,
   and the audio bandwidth is also set to that of the current frame,
   with the exception that for MB SILK frames, it is set to WB.

   If the redundancy belongs at the beginning (in a CELT-only to SILK-
   only or Hybrid transition), the final reconstructed output uses the
   first 2.5 ms of audio output by the decoder for the redundant frame
   as is, discarding the corresponding output from the SILK-only or
   Hybrid portion of the frame.  The remaining 2.5 ms is cross-lapped
   with the decoded SILK/Hybrid signal using the CELT's power-
   complementary MDCT window to ensure a smooth transition.

   If the redundancy belongs at the end (in a SILK-only or Hybrid to
   CELT-only transition), only the second half (2.5 ms) of the audio
   output by the decoder for the redundant frame is used.  In that case,
   the second half of the redundant frame is cross-lapped with the end
   of the SILK/Hybrid signal, again using CELT's power-complementary
   MDCT window to ensure a smooth transition.

4.5.2.  State Reset



   When a transition occurs, the state of the SILK or the CELT decoder
   (or both) may need to be reset before decoding a frame in the new
   mode.  This avoids reusing "out of date" memory, which may not have
   been updated in some time or may not be in a well-defined state due
   to, e.g., PLC.  The SILK state is reset before every SILK-only or
   Hybrid frame where the previous frame was CELT-only.  The CELT state
   is reset every time the operating mode changes and the new mode is
   either Hybrid or CELT-only, except when the transition uses
   redundancy as described above.  When switching from SILK-only or
   Hybrid to CELT-only with redundancy, the CELT state is reset before
   decoding the redundant CELT frame embedded in the SILK-only or Hybrid
   frame, but it is not reset before decoding the following CELT-only
   frame.  When switching from CELT-only mode to SILK-only or Hybrid
   mode with redundancy, the CELT decoder is not reset for decoding the
   redundant CELT frame.











Valin, et al.                Standards Track                  [Page 127]

RFC 6716                 Interactive Audio Codec          September 2012


4.5.3.  Summary of Transitions



   Figure 18 illustrates all of the normative transitions involving a
   mode change, an audio bandwidth change, or both.  Each one uses an S,
   H, or C to represent an Opus frame in the corresponding mode.  In
   addition, an R indicates the presence of redundancy in the Opus frame
   with which it is cross-lapped.  Its location in the first or last
   5 ms is assumed to correspond to whether it is the frame before or
   after the transition.  Other uses of redundancy are non-normative.
   Finally, a c indicates the contents of the CELT overlap buffer after
   the previously decoded frame (i.e., as extracted by decoding a
   silence frame).







































Valin, et al.                Standards Track                  [Page 128]

RFC 6716                 Interactive Audio Codec          September 2012


    SILK to SILK with Redundancy:             S -> S -> S
                                                        &
                                                       !R -> R
                                                             &
                                                            ;S -> S -> S

    NB or MB SILK to Hybrid with Redundancy:  S -> S -> S
                                                        &
                                                       !R ->;H -> H -> H

    WB SILK to Hybrid:                        S -> S -> S ->!H -> H -> H

    SILK to CELT with Redundancy:             S -> S -> S
                                                        &
                                                       !R -> C -> C -> C

    Hybrid to NB or MB SILK with Redundancy:  H -> H -> H
                                                        &
                                                       !R -> R
                                                             &
                                                            ;S -> S -> S

    Hybrid to WB SILK:                        H -> H -> H -> c
                                                          \  +
                                                           > S -> S -> S

    Hybrid to CELT with Redundancy:           H -> H -> H
                                                        &
                                                       !R -> C -> C -> C

    CELT to SILK with Redundancy:             C -> C -> C -> R
                                                             &
                                                            ;S -> S -> S

    CELT to Hybrid with Redundancy:           C -> C -> C -> R
                                                             &
                                                            |H -> H -> H

    Key:
    S   SILK-only frame                 ;   SILK decoder reset
    H   Hybrid frame                    |   CELT and SILK decoder resets
    C   CELT-only frame                 !   CELT decoder reset
    c   CELT overlap                    +   Direct mixing
    R   Redundant CELT frame            &   Windowed cross-lap

                     Figure 18: Normative Transitions





Valin, et al.                Standards Track                  [Page 129]

RFC 6716                 Interactive Audio Codec          September 2012


   The first two and the last two Opus frames in each example are
   illustrative, i.e., there is no requirement that a stream remain in
   the same configuration for three consecutive frames before or after a
   switch.

   The behavior of transitions without redundancy where PLC is allowed
   is non-normative.  An encoder might still wish to use these
   transitions if, for example, it doesn't want to add the extra bitrate
   required for redundancy or if it makes a decision to switch after it
   has already transmitted the frame that would have had to contain the
   redundancy.  Figure 19 illustrates the recommended cross-lapping and
   decoder resets for these transitions.

    SILK to SILK (audio bandwidth change):    S -> S -> S   ;S -> S -> S

    NB or MB SILK to Hybrid:                  S -> S -> S   |H -> H -> H

    SILK to CELT without Redundancy:          S -> S -> S -> P
                                                             &
                                                            !C -> C -> C

    Hybrid to NB or MB SILK:                  H -> H -> H -> c
                                                             +
                                                            ;S -> S -> S

    Hybrid to CELT without Redundancy:        H -> H -> H -> P
                                                             &
                                                            !C -> C -> C

    CELT to SILK without Redundancy:          C -> C -> C -> P
                                                             &
                                                            ;S -> S -> S

    CELT to Hybrid without Redundancy:        C -> C -> C -> P
                                                             &
                                                            |H -> H -> H

    Key:
    S   SILK-only frame                 ;   SILK decoder reset
    H   Hybrid frame                    |   CELT and SILK decoder resets
    C   CELT-only frame                 !   CELT decoder reset
    c   CELT overlap                    +   Direct mixing
    P   Packet Loss Concealment         &   Windowed cross-lap

             Figure 19: Recommended Non-Normative Transitions

   Encoders SHOULD NOT use other transitions, e.g., those that involve
   redundancy in ways not illustrated in Figure 18.



Valin, et al.                Standards Track                  [Page 130]

RFC 6716                 Interactive Audio Codec          September 2012


5.  Opus Encoder

   Just like the decoder, the Opus encoder also normally consists of two
   main blocks: the SILK encoder and the CELT encoder.  However, unlike
   the case of the decoder, a valid (though potentially suboptimal) Opus
   encoder is not required to support all modes and may thus only
   include a SILK encoder module or a CELT encoder module.  The output
   bitstream of the Opus encoding contains bits from the SILK and CELT
   encoders, though these are not separable due to the use of a range
   coder.  A block diagram of the encoder is illustrated below.

                        +------------+    +---------+
                        |   Sample   |    |  SILK   |------+
                     +->|    Rate    |--->| Encoder |      V
      +-----------+  |  | Conversion |    |         | +---------+
      | Optional  |  |  +------------+    +---------+ |  Range  |
    ->| High-pass |--+                                | Encoder |---->
      |  Filter   |  |  +--------------+  +---------+ |         | Bit-
      +-----------+  |  |    Delay     |  |  CELT   | +---------+ stream
                     +->| Compensation |->| Encoder |      ^
                        |              |  |         |------+
                        +--------------+  +---------+

                          Figure 20: Opus Encoder

   For a normal encoder where both the SILK and the CELT modules are
   included, an optimal encoder should select which coding mode to use
   at run-time depending on the conditions.  In the reference
   implementation, the frame size is selected by the application, but
   the other configuration parameters (number of channels, bandwidth,
   mode) are automatically selected (unless explicitly overridden by the
   application) depending on the following:

   o  Requested bitrate

   o  Input sampling rate

   o  Type of signal (speech vs. music)

   o  Frame size in use

   The type of signal currently needs to be provided by the application
   (though it can be changed in real-time).  An Opus encoder
   implementation could also do automatic detection, but since Opus is
   an interactive codec, such an implementation would likely have to
   either delay the signal (for non-interactive applications) or delay
   the mode switching decisions (for interactive applications).




Valin, et al.                Standards Track                  [Page 131]

RFC 6716                 Interactive Audio Codec          September 2012


   When the encoder is configured for voice over IP applications, the
   input signal is filtered by a high-pass filter to remove the lowest
   part of the spectrum that contains little speech energy and may
   contain background noise.  This is a second order Auto Regressive
   Moving Average (i.e., with poles and zeros) filter with a cut-off
   frequency around 50 Hz.  In the future, a music detector may also be
   used to lower the cut-off frequency when the input signal is detected
   to be music rather than speech.

5.1.  Range Encoder



   The range coder acts as the bit-packer for Opus.  It is used in three
   different ways: to encode

   o  Entropy-coded symbols with a fixed probability model using
      ec_encode() (entenc.c),

   o  Integers from 0 to (2**M - 1) using ec_enc_uint() or ec_enc_bits()
      (entenc.c),

   o  Integers from 0 to (ft - 1) (where ft is not a power of two) using
      ec_enc_uint() (entenc.c).

   The range encoder maintains an internal state vector composed of the
   four-tuple (val, rng, rem, ext) representing the low end of the
   current range, the size of the current range, a single buffered
   output byte, and a count of additional carry-propagating output
   bytes.  Both val and rng are 32-bit unsigned integer values, rem is a
   byte value or less than 255 or the special value -1, and ext is an
   unsigned integer with at least 11 bits.  This state vector is
   initialized at the start of each frame to the value
   (0, 2**31, -1, 0).  After encoding a sequence of symbols, the value
   of rng in the encoder should exactly match the value of rng in the
   decoder after decoding the same sequence of symbols.  This is a
   powerful tool for detecting errors in either an encoder or decoder
   implementation.  The value of val, on the other hand, represents
   different things in the encoder and decoder, and is not expected to
   match.

   The decoder has no analog for rem and ext.  These are used to perform
   carry propagation in the renormalization loop below.  Each iteration
   of this loop produces 9 bits of output, consisting of 8 data bits and
   a carry flag.  The encoder cannot determine the final value of the
   output bytes until it propagates these carry flags.  Therefore, the
   reference implementation buffers a single non-propagating output byte
   (i.e., one less than 255) in rem and keeps a count of additional





Valin, et al.                Standards Track                  [Page 132]

RFC 6716                 Interactive Audio Codec          September 2012


   propagating (i.e., 255) output bytes in ext.  An implementation may
   choose to use any mathematically equivalent scheme to perform carry
   propagation.

5.1.1.  Encoding Symbols



   The main encoding function is ec_encode() (entenc.c), which encodes
   symbol k in the current context using the same three-tuple
   (fl[k], fh[k], ft) as the decoder to describe the range of the symbol
   (see Section 4.1).

   ec_encode() updates the state of the encoder as follows.  If fl[k] is
   greater than zero, then

                                       rng
                     val = val + rng - --- * (ft - fl)
                                       ft

                           rng
                     rng = --- * (fh - fl)
                           ft

   Otherwise, val is unchanged and

                                    rng
                        rng = rng - --- * (fh - fl)
                                    ft

   The divisions here are integer division.

5.1.1.1.  Renormalization



   After this update, the range is normalized using a procedure very
   similar to that of Section 4.1.2.1, implemented by ec_enc_normalize()
   (entenc.c).  The following process is repeated until rng > 2**23.
   First, the top 9 bits of val, (val>>23), are sent to the carry
   buffer, described in Section 5.1.1.2.  Then, the encoder sets

                        val = (val<<8) & 0x7FFFFFFF

                        rng = rng<<8

5.1.1.2.  Carry Propagation and Output Buffering



   The function ec_enc_carry_out() (entenc.c) implements carry
   propagation and output buffering.  It takes, as input, a 9-bit
   unsigned value, c, consisting of 8 data bits and an additional carry




Valin, et al.                Standards Track                  [Page 133]

RFC 6716                 Interactive Audio Codec          September 2012


   bit.  If c is equal to the value 255, then ext is simply incremented,
   and no other state updates are performed.  Otherwise, let b = (c>>8)
   be the carry bit.  Then,

   o  If the buffered byte rem contains a value other than -1, the
      encoder outputs the byte (rem + b).  Otherwise, if rem is -1, no
      byte is output.

   o  If ext is non-zero, then the encoder outputs ext bytes -- all with
      a value of 0 if b is set, or 255 if b is unset -- and sets ext to
      0.

   o  rem is set to the 8 data bits:

                               rem = c & 255

5.1.2.  Alternate Encoding Methods



   The reference implementation uses three additional encoding methods
   that are exactly equivalent to the above, but make assumptions and
   simplifications that allow for a more efficient implementation.

5.1.2.1.  ec_encode_bin()



   The first is ec_encode_bin() (entenc.c), defined using the parameter
   ftb instead of ft.  It is mathematically equivalent to calling
   ec_encode() with ft = (1<<ftb), but it avoids using division.

5.1.2.2.  ec_enc_bit_logp()



   The next is ec_enc_bit_logp() (entenc.c), which encodes a single
   binary symbol.  The context is described by a single parameter, logp,
   which is the absolute value of the base-2 logarithm of the
   probability of a "1".  It is mathematically equivalent to calling
   ec_encode() with the 3-tuple (fl[k] = 0, fh[k] = (1<<logp) - 1,
   ft = (1<<logp)) if k is 0 and with (fl[k] = (1<<logp) - 1,
   fh[k] = ft = (1<<logp)) if k is 1.  The implementation requires no
   multiplications or divisions.

5.1.2.3.  ec_enc_icdf()



   The last is ec_enc_icdf() (entenc.c), which encodes a single binary
   symbol with a table-based context of up to 8 bits.  This uses the
   same icdf table as ec_dec_icdf() from Section 4.1.3.3.  The function







Valin, et al.                Standards Track                  [Page 134]

RFC 6716                 Interactive Audio Codec          September 2012


   is mathematically equivalent to calling ec_encode() with
   fl[k] = (1<<ftb) - icdf[k-1] (or 0 if k == 0), fh[k] = (1<<ftb) -
    icdf[k], and ft = (1<<ftb).  This only saves a few arithmetic
   operations over ec_encode_bin(), but it allows the encoder to use the
   same icdf tables as the decoder.

5.1.3.  Encoding Raw Bits



   The raw bits used by the CELT layer are packed at the end of the
   buffer using ec_enc_bits() (entenc.c).  Because the raw bits may
   continue into the last byte output by the range coder if there is
   room in the low-order bits, the encoder must be prepared to merge
   these values into a single byte.  The procedure in Section 5.1.5 does
   this in a way that ensures both the range coded data and the raw bits
   can be decoded successfully.

5.1.4.  Encoding Uniformly Distributed Integers



   The function ec_enc_uint() (entenc.c) encodes one of ft equiprobable
   symbols in the range 0 to (ft - 1), inclusive, each with a frequency
   of 1, where ft may be as large as (2**32 - 1).  Like the decoder (see
   Section 4.1.5), it splits up the value into a range coded symbol
   representing up to 8 of the high bits, and, if necessary, raw bits
   representing the remainder of the value.

   ec_enc_uint() takes a two-tuple (t, ft), where t is the unsigned
   integer to be encoded, 0 <= t < ft, and ft is not necessarily a power
   of two.  Let ftb = ilog(ft - 1), i.e., the number of bits required to
   store (ft - 1) in two's complement notation.  If ftb is 8 or less,
   then t is encoded directly using ec_encode() with the three-tuple (t,
   t + 1, ft).

   If ftb is greater than 8, then the top 8 bits of t are encoded using
   the three-tuple (t>>(ftb - 8), (t>>(ftb - 8)) + 1,
   ((ft - 1)>>(ftb - 8)) + 1), and the remaining bits,
   (t & ((1<<(ftb - 8)) - 1), are encoded as raw bits with
   ec_enc_bits().

5.1.5.  Finalizing the Stream



   After all symbols are encoded, the stream must be finalized by
   outputting a value inside the current range.  Let end be the unsigned
   integer in the interval [val, val + rng) with the largest number of
   trailing zero bits, b, such that (end + (1<<b) - 1) is also in the
   interval [val, val + rng).  This choice of end allows the maximum
   number of trailing bits to be set to arbitrary values while still
   ensuring the range coded part of the buffer can be decoded correctly.




Valin, et al.                Standards Track                  [Page 135]

RFC 6716                 Interactive Audio Codec          September 2012


   Then, while end is not zero, the top 9 bits of end, i.e., (end>>23),
   are passed to the carry buffer in accordance with the procedure in
   Section 5.1.1.2, and end is updated via

                        end = (end<<8) & 0x7FFFFFFF

   Finally, if the buffered output byte, rem, is neither zero nor the
   special value -1, or the carry count, ext, is greater than zero, then
   9 zero bits are sent to the carry buffer to flush it to the output
   buffer.  When outputting the final byte from the range coder, if it
   would overlap any raw bits already packed into the end of the output
   buffer, they should be ORed into the same byte.  The bit allocation
   routines in the CELT layer should ensure that this can be done
   without corrupting the range coder data so long as end is chosen as
   described above.  If there is any space between the end of the range
   coder data and the end of the raw bits, it is padded with zero bits.
   This entire process is implemented by ec_enc_done() (entenc.c).

5.1.6.  Current Bit Usage



   The bit allocation routines in Opus need to be able to determine a
   conservative upper bound on the number of bits that have been used to
   encode the current frame thus far.  This drives allocation decisions
   and ensures that the range coder and raw bits will not overflow the
   output buffer.  This is computed in the reference implementation to
   whole-bit precision by the function ec_tell() (entcode.h) and to
   fractional 1/8th bit precision by the function ec_tell_frac()
   (entcode.c).  Like all operations in the range coder, it must be
   implemented in a bit-exact manner, and it must produce exactly the
   same value returned by the same functions in the decoder after
   decoding the same symbols.

5.2.  SILK Encoder



   In many respects, the SILK encoder mirrors the SILK decoder described
   in Section 4.2.  Details such as the quantization and range coder
   tables can be found there, while this section describes the high-
   level design choices that were made.  The diagram below shows the
   basic modules of the SILK encoder.

               +----------+    +--------+    +---------+
               |  Sample  |    | Stereo |    |  SILK   |
        ------>|   Rate   |--->| Mixing |--->|  Core   |---------->
        Input  |Conversion|    |        |    | Encoder |  Bitstream
               +----------+    +--------+    +---------+

                          Figure 21: SILK Encoder




Valin, et al.                Standards Track                  [Page 136]

RFC 6716                 Interactive Audio Codec          September 2012


5.2.1.  Sample Rate Conversion



   The input signal's sampling rate is adjusted by a sample rate
   conversion module so that it matches the SILK internal sampling rate.
   The input to the sample rate converter is delayed by a number of
   samples depending on the sample rate ratio, such that the overall
   delay is constant for all input and output sample rates.

5.2.2.  Stereo Mixing



   The stereo mixer is only used for stereo input signals.  It converts
   a stereo left-right signal into an adaptive mid-side representation.
   The first step is to compute non-adaptive mid-side signals as half
   the sum and difference between left and right signals.  The side
   signal is then minimized in energy by subtracting a prediction of it
   based on the mid signal.  This prediction works well when the left
   and right signals exhibit linear dependency, for instance, for an
   amplitude-panned input signal.  Like in the decoder, the prediction
   coefficients are linearly interpolated during the first 8 ms of the
   frame.  The mid signal is always encoded, whereas the residual side
   signal is only encoded if it has sufficient energy compared to the
   mid signal's energy.  If it has not, the "mid_only_flag" is set
   without encoding the side signal.

   The predictor coefficients are coded regardless of whether the side
   signal is encoded.  For each frame, two predictor coefficients are
   computed, one that predicts between low-passed mid and side channels,
   and one that predicts between high-passed mid and side channels.  The
   low-pass filter is a simple three-tap filter and creates a delay of
   one sample.  The high-pass filtered signal is the difference between
   the mid signal delayed by one sample and the low-passed signal.
   Instead of explicitly computing the high-passed signal, it is
   computationally more efficient to transform the prediction
   coefficients before applying them to the filtered mid signal, as
   follows:

               pred(n) = LP(n) * w0 + HP(n) * w1
                       = LP(n) * w0 + (mid(n-1) - LP(n)) * w1
                       = LP(n) * (w0 - w1) + mid(n-1) * w1


   where w0 and w1 are the low-pass and high-pass prediction
   coefficients, mid(n-1) is the mid signal delayed by one sample, LP(n)
   and HP(n) are the low-passed and high-passed signals and pred(n) is
   the prediction signal that is subtracted from the side signal.






Valin, et al.                Standards Track                  [Page 137]

RFC 6716                 Interactive Audio Codec          September 2012


5.2.3.  SILK Core Encoder



   What follows is a description of the core encoder and its components.
   For simplicity, the core encoder is referred to simply as the encoder
   in the remainder of this section.  An overview of the encoder is
   given in Figure 22.

                                                                +---+
                             +--------------------------------->|   |
        +---------+          |      +---------+                 |   |
        |Voice    |          |      |LTP      |12               |   |
    +-->|Activity |--+       +----->|Scaling  |-----------+---->|   |
    |   |Detection|3 |       |      |Control  |<--+       |     |   |
    |   +---------+  |       |      +---------+   |       |     |   |
    |                |       |      +---------+   |       |     |   |
    |                |       |      |Gains    |   |       |     |   |
    |                |       |  +-->|Processor|---|---+---|---->| R |
    |                |       |  |   |         |11 |   |   |     | a |
    |               \/       |  |   +---------+   |   |   |     | n |
    |          +---------+   |  |   +---------+   |   |   |     | g |
    |          |Pitch    |   |  |   |LSF      |   |   |   |     | e |
    |       +->|Analysis |---+  |   |Quantizer|---|---|---|---->|   |
    |       |  |         |4  |  |   |         |8  |   |   |     | E |-->
    |       |  +---------+   |  |   +---------+   |   |   |     | n | 2
    |       |                |  |    9/\  10|     |   |   |     | c |
    |       |                |  |     |    \/     |   |   |     | o |
    |       |  +---------+   |  |   +----------+  |   |   |     | d |
    |       |  |Noise    |   +--|-->|Prediction|--+---|---|---->| e |
    |       +->|Shaping  |---|--+   |Analysis  |7 |   |   |     | r |
    |       |  |Analysis |5  |  |   |          |  |   |   |     |   |
    |       |  +---------+   |  |   +----------+  |   |   |     |   |
    |       |                |  |        /\       |   |   |     |   |
    |       |     +----------|--|--------+        |   |   |     |   |
    |       |     |         \/  \/               \/  \/  \/     |   |
    |       |     |      +----------+          +------------+   |   |
    |       |     |      |          |          |Noise       |   |   |
   -+-------+-----+----->|Pre-filter|--------->|Shaping     |-->|   |
   1                     |          | 6        |Quantization|13 |   |
                         +----------+          +------------+   +---+

   1:  Input speech signal
   2:  Range encoded bitstream
   3:  Voice activity estimate
   4:  Pitch lags (per 5 ms) and voicing decision (per 20 ms)
   5:  Noise shaping quantization coefficients
     - Short-term synthesis and analysis
       noise shaping coefficients (per 5 ms)




Valin, et al.                Standards Track                  [Page 138]

RFC 6716                 Interactive Audio Codec          September 2012


     - Long-term synthesis and analysis noise
       shaping coefficients (per 5 ms and for voiced speech only)
     - Noise shaping tilt (per 5 ms)
     - Quantizer gain/step size (per 5 ms)
   6:  Input signal filtered with analysis noise shaping filters
   7:  Short- and Long-Term Prediction coefficients
       LTP (per 5 ms) and LPC (per 20 ms)
   8:  LSF quantization indices
   9:  LSF coefficients
   10: Quantized LSF coefficients
   11: Processed gains, and synthesis noise shape coefficients
   12: LTP state scaling coefficient.  Controlling error
       propagation / prediction gain trade-off
   13: Quantized signal

                       Figure 22: SILK Core Encoder

5.2.3.1.  Voice Activity Detection



   The input signal is processed by a Voice Activity Detection (VAD)
   algorithm to produce a measure of voice activity, spectral tilt, and
   signal-to-noise estimates for each frame.  The VAD uses a sequence of
   half-band filterbanks to split the signal into four subbands:
   0...Fs/16, Fs/16...Fs/8, Fs/8...Fs/4, and Fs/4...Fs/2, where Fs is
   the sampling frequency (8, 12, 16, or 24 kHz).  The lowest subband,
   from 0 - Fs/16, is high-pass filtered with a first-order moving
   average (MA) filter (with transfer function H(z) = 1-z**(-1)) to
   reduce the energy at the lowest frequencies.  For each frame, the
   signal energy per subband is computed.  In each subband, a noise
   level estimator tracks the background noise level and a Signal-to-
   Noise Ratio (SNR) value is computed as the logarithm of the ratio of
   energy-to-noise level.  Using these intermediate variables, the
   following parameters are calculated for use in other SILK modules:

   o  Average SNR.  The average of the subband SNR values.

   o  Smoothed subband SNRs.  Temporally smoothed subband SNR values.

   o  Speech activity level.  Based on the average SNR and a weighted
      average of the subband energies.

   o  Spectral tilt.  A weighted average of the subband SNRs, with
      positive weights for the low subbands and negative weights for the
      high subbands.







Valin, et al.                Standards Track                  [Page 139]

RFC 6716                 Interactive Audio Codec          September 2012


5.2.3.2.  Pitch Analysis



   The input signal is processed by the open loop pitch estimator shown
   in Figure 23.

                                    +--------+  +----------+
                                    |2 x Down|  |Time-     |
                                 +->|sampling|->|Correlator|     |
                                 |  |        |  |          |     |4
                                 |  +--------+  +----------+    \/
                                 |                    | 2    +-------+
                                 |                    |  +-->|Speech |5
       +---------+    +--------+ |                   \/  |   |Type   |->
       |LPC      |    |Down    | |              +----------+ |       |
    +->|Analysis | +->|sample  |-+------------->|Time-     | +-------+
    |  |         | |  |to 8 kHz|                |Correlator|----------->
    |  +---------+ |  +--------+                |__________|          6
    |       |      |                                  |3
    |      \/      |                                 \/
    |  +---------+ |                            +----------+
    |  |Whitening| |                            |Time-     |
   -+->|Filter   |-+--------------------------->|Correlator|----------->
   1   |         |                              |          |          7
       +---------+                              +----------+

   1: Input signal
   2: Lag candidates from stage 1
   3: Lag candidates from stage 2
   4: Correlation threshold
   5: Voiced/unvoiced flag
   6: Pitch correlation
   7: Pitch lags

              Figure 23: Block Diagram of the Pitch Estimator

   The pitch analysis finds a binary voiced/unvoiced classification,
   and, for frames classified as voiced, four pitch lags per frame --
   one for each 5 ms subframe -- and a pitch correlation indicating the
   periodicity of the signal.  The input is first whitened using a
   Linear Prediction (LP) whitening filter, where the coefficients are
   computed through standard Linear Predictive Coding (LPC) analysis.
   The order of the whitening filter is 16 for best results, but is
   reduced to 12 for medium complexity and 8 for low complexity modes.
   The whitened signal is analyzed to find pitch lags for which the time
   correlation is high.  The analysis consists of three stages for
   reducing the complexity:





Valin, et al.                Standards Track                  [Page 140]

RFC 6716                 Interactive Audio Codec          September 2012


   o  In the first stage, the whitened signal is downsampled to 4 kHz
      (from 8 kHz), and the current frame is correlated to a signal
      delayed by a range of lags, starting from a shortest lag
      corresponding to 500 Hz, to a longest lag corresponding to 56 Hz.

   o  The second stage operates on an 8 kHz signal (downsampled from 12,
      16, or 24 kHz) and measures time correlations only near the lags
      corresponding to those that had sufficiently high correlations in
      the first stage.  The resulting correlations are adjusted for a
      small bias towards short lags to avoid ending up with a multiple
      of the true pitch lag.  The highest adjusted correlation is
      compared to a threshold depending on:

      *  Whether the previous frame was classified as voiced.

      *  The speech activity level.

      *  The spectral tilt.

      If the threshold is exceeded, the current frame is classified as
      voiced and the lag with the highest adjusted correlation is stored
      for a final pitch analysis of the highest precision in the third
      stage.

   o  The last stage operates directly on the whitened input signal to
      compute time correlations for each of the four subframes
      independently in a narrow range around the lag with highest
      correlation from the second stage.

5.2.3.3.  Noise Shaping Analysis



   The noise shaping analysis finds gains and filter coefficients used
   in the pre-filter and noise shaping quantizer.  These parameters are
   chosen such that they will fulfill several requirements:

   o  Balancing quantization noise and bitrate.  The quantization gains
      determine the step size between reconstruction levels of the
      excitation signal.  Therefore, increasing the quantization gain
      amplifies quantization noise, but also reduces the bitrate by
      lowering the entropy of the quantization indices.

   o  Spectral shaping of the quantization noise; the noise shaping
      quantizer is capable of reducing quantization noise in some parts
      of the spectrum at the cost of increased noise in other parts
      without substantially changing the bitrate.  By shaping the noise
      such that it follows the signal spectrum, it becomes less audible.
      In practice, best results are obtained by making the shape of the
      noise spectrum slightly flatter than the signal spectrum.



Valin, et al.                Standards Track                  [Page 141]

RFC 6716                 Interactive Audio Codec          September 2012


   o  De-emphasizing spectral valleys; by using different coefficients
      in the analysis and synthesis part of the pre-filter and noise
      shaping quantizer, the levels of the spectral valleys can be
      decreased relative to the levels of the spectral peaks such as
      speech formants and harmonics.  This reduces the entropy of the
      signal, which is the difference between the coded signal and the
      quantization noise, thus lowering the bitrate.

   o  Matching the levels of the decoded speech formants to the levels
      of the original speech formants; an adjustment gain and a first
      order tilt coefficient are computed to compensate for the effect
      of the noise shaping quantization on the level and spectral tilt.

                 / \   ___
                  |   // \\
                  |  //   \\     ____
                  |_//     \\___//  \\         ____
                  | /  ___  \   /    \\       //  \\
                P |/  /   \  \_/      \\_____//    \\
                o |  /     \     ____  \     /      \\
                w | /       \___/    \  \___/  ____  \\___ 1
                e |/                  \       /    \  \
                r |                    \_____/      \  \__ 2
                  |                                  \
                  |                                   \___ 3
                  |
                  +---------------------------------------->
                                   Frequency

               1: Input signal spectrum
               2: De-emphasized and level matched spectrum
               3: Quantization noise spectrum

      Figure 24: Noise Shaping and Spectral De-emphasis Illustration

   Figure 24 shows an example of an input signal spectrum (1).  After
   de-emphasis and level matching, the spectrum has deeper valleys (2).
   The quantization noise spectrum (3) more or less follows the input
   signal spectrum, while having slightly less pronounced peaks.  The
   entropy, which provides a lower bound on the bitrate for encoding the
   excitation signal, is proportional to the area between the de-
   emphasized spectrum (2) and the quantization noise spectrum (3).
   Without de-emphasis, the entropy is proportional to the area between
   input spectrum (1) and quantization noise (3) -- clearly higher.

   The transformation from input signal to de-emphasized signal can be
   described as a filtering operation with a filter




Valin, et al.                Standards Track                  [Page 142]

RFC 6716                 Interactive Audio Codec          September 2012


                                             -1    Wana(z)
                  H(z) = G * ( 1 - c_tilt * z  ) * -------
                                                   Wsyn(z)

   having an adjustment gain G, a first order tilt adjustment filter
   with tilt coefficient c_tilt, and where

                       16                           d
                       __            -k        -L  __            -k
        Wana(z) = (1 - \ a_ana(k) * z  )*(1 - z  * \ b_ana(k) * z  )
                       /_                          /_
                       k=1                         k=-d

   is the analysis part of the de-emphasis filter, consisting of the
   short-term shaping filter with coefficients a_ana(k) and the long-
   term shaping filter with coefficients b_ana(k) and pitch lag L.  The
   parameter d determines the number of long-term shaping filter taps.

   Similarly, but without the tilt adjustment, the synthesis part can be
   written as

                       16                           d
                       __            -k        -L  __            -k
        Wsyn(z) = (1 - \ a_syn(k) * z  )*(1 - z  * \ b_syn(k) * z  )
                       /_                          /_
                       k=1                         k=-d

   All noise shaping parameters are computed and applied per subframe of
   5 ms.  First, an LPC analysis is performed on a windowed signal block
   of 15 ms.  The signal block has a look-ahead of 5 ms relative to the
   current subframe, and the window is an asymmetric sine window.  The
   LPC analysis is done with the autocorrelation method, with an order
   of between 8, in lowest-complexity mode, and 16, for best quality.

   Optionally, the LPC analysis and noise shaping filters are warped by
   replacing the delay elements by first-order allpass filters.  This
   increases the frequency resolution at low frequencies and reduces it
   at high ones, which better matches the human auditory system and
   improves quality.  The warped analysis and filtering comes at a cost
   in complexity and is therefore only done in higher complexity modes.

   The quantization gain is found by taking the square root of the
   residual energy from the LPC analysis and multiplying it by a value
   inversely proportional to the coding quality control parameter and
   the pitch correlation.






Valin, et al.                Standards Track                  [Page 143]

RFC 6716                 Interactive Audio Codec          September 2012


   Next, the two sets of short-term noise shaping coefficients a_ana(k)
   and a_syn(k) are obtained by applying different amounts of bandwidth
   expansion to the coefficients found in the LPC analysis.  This
   bandwidth expansion moves the roots of the LPC polynomial towards the
   origin, using the formulas

                                              k
                         a_ana(k) = a(k)*g_ana   and

                                              k
                         a_syn(k) = a(k)*g_syn

   where a(k) is the k'th LPC coefficient, and the bandwidth expansion
   factors g_ana and g_syn are calculated as

                         g_ana = 0.95 - 0.01*C  and

                         g_syn = 0.95 + 0.01*C

   where C is the coding quality control parameter between 0 and 1.
   Applying more bandwidth expansion to the analysis part than to the
   synthesis part gives the desired de-emphasis of spectral valleys in
   between formants.

   The long-term shaping is applied only during voiced frames.  It uses
   a three-tap filter, described by

                   b_ana = F_ana * [0.25, 0.5, 0.25]  and

                   b_syn = F_syn * [0.25, 0.5, 0.25].

   For unvoiced frames, these coefficients are set to 0.  The
   multiplication factors F_ana and F_syn are chosen between 0 and 1,
   depending on the coding quality control parameter, as well as the
   calculated pitch correlation and smoothed subband SNR of the lowest
   subband.  By having F_ana less than F_syn, the pitch harmonics are
   emphasized relative to the valleys in between the harmonics.

   The tilt coefficient c_tilt is for unvoiced frames chosen as

                               c_tilt = 0.25

   and as

                         c_tilt = 0.25 + 0.2625 * V

   for voiced frames, where V is the voice activity level between 0 and
   1.



Valin, et al.                Standards Track                  [Page 144]

RFC 6716                 Interactive Audio Codec          September 2012


   The adjustment gain G serves to correct any level mismatch between
   the original and decoded signals that might arise from the noise
   shaping and de-emphasis.  This gain is computed as the ratio of the
   prediction gain of the short-term analysis and synthesis filter
   coefficients.  The prediction gain of an LPC synthesis filter is the
   square root of the output energy when the filter is excited by a
   unit-energy impulse on the input.  An efficient way to compute the
   prediction gain is by first computing the reflection coefficients
   from the LPC coefficients through the step-down algorithm, and
   extracting the prediction gain from the reflection coefficients as

                                    K
                                   ___          2  -0.5
                      predGain = ( | | 1 - (r_k)  )
                                   k=1

   where r_k is the k'th reflection coefficient.

   Initial values for the quantization gains are computed as the square
   root of the residual energy of the LPC analysis, adjusted by the
   coding quality control parameter.  These quantization gains are later
   adjusted based on the results of the prediction analysis.

5.2.3.4.  Prediction Analysis



   The prediction analysis is performed in one of two ways depending on
   how the pitch estimator classified the frame.  The processing for
   voiced and unvoiced speech is described in Section 5.2.3.4.1 and
   Section 5.2.3.4.2, respectively.  Inputs to this function include the
   pre-whitened signal from the pitch estimator (see Section 5.2.3.2).

5.2.3.4.1.  Voiced Speech


   For a frame of voiced speech, the pitch pulses will remain dominant
   in the pre-whitened input signal.  Further whitening is desirable as
   it leads to higher quality at the same available bitrate.  To achieve
   this, a Long-Term Prediction (LTP) analysis is carried out to
   estimate the coefficients of a fifth-order LTP filter for each of
   four subframes.  The LTP coefficients are quantized using the method
   described in Section 5.2.3.6, and the quantized LTP coefficients are
   used to compute the LTP residual signal.  This LTP residual signal is
   the input to an LPC analysis where the LPC coefficients are estimated
   using Burg's method [BURG], such that the residual energy is
   minimized.  The estimated LPC coefficients are converted to a Line
   Spectral Frequency (LSF) vector and quantized as described in
   Section 5.2.3.5.  After quantization, the quantized LSF vector is
   converted back to LPC coefficients using the full procedure in
   Section 4.2.7.5.  By using quantized LTP coefficients and LPC



Valin, et al.                Standards Track                  [Page 145]

RFC 6716                 Interactive Audio Codec          September 2012


   coefficients derived from the quantized LSF coefficients, the encoder
   remains fully synchronized with the decoder.  The quantized LPC and
   LTP coefficients are also used to filter the input signal and measure
   residual energy for each of the four subframes.

5.2.3.4.2.  Unvoiced Speech


   For a speech signal that has been classified as unvoiced, there is no
   need for LTP filtering, as it has already been determined that the
   pre-whitened input signal is not periodic enough within the allowed
   pitch period range for LTP analysis to be worth the cost in terms of
   complexity and bitrate.  The pre-whitened input signal is therefore
   discarded, and, instead, the input signal is used for LPC analysis
   using Burg's method.  The resulting LPC coefficients are converted to
   an LSF vector and quantized as described in the following section.
   They are then transformed back to obtain quantized LPC coefficients,
   which are then used to filter the input signal and measure residual
   energy for each of the four subframes.

5.2.3.4.2.1.  Burg's Method


   The main purpose of linear prediction in SILK is to reduce the
   bitrate by minimizing the residual energy.  At least at high
   bitrates, perceptual aspects are handled independently by the noise
   shaping filter.  Burg's method is used because it provides higher
   prediction gain than the autocorrelation method and, unlike the
   covariance method, produces stable filters (assuming numerical errors
   don't spoil that).  SILK's implementation of Burg's method is also
   computationally faster than the autocovariance method.  The
   implementation of Burg's method differs from traditional
   implementations in two aspects.  The first difference is that it
   operates on autocorrelations, similar to the Schur algorithm [SCHUR],
   but with a simple update to the autocorrelations after finding each
   reflection coefficient to make the result identical to Burg's method.
   This brings down the complexity of Burg's method to near that of the
   autocorrelation method.  The second difference is that the signal in
   each subframe is scaled by the inverse of the residual quantization
   step size.  Subframes with a small quantization step size will, on
   average, spend more bits for a given amount of residual energy than
   subframes with a large step size.  Without scaling, Burg's method
   minimizes the total residual energy in all subframes, which doesn't
   necessarily minimize the total number of bits needed for coding the
   quantized residual.  The residual energy of the scaled subframes is a
   better measure for that number of bits.







Valin, et al.                Standards Track                  [Page 146]

RFC 6716                 Interactive Audio Codec          September 2012


5.2.3.5.  LSF Quantization



   Unlike many other speech codecs, SILK uses variable bitrate coding
   for the LSFs.  This improves the average rate-distortion (R-D) trade-
   off and reduces outliers.  The variable bitrate coding minimizes a
   linear combination of the weighted quantization errors and the
   bitrate.  The weights for the quantization errors are the Inverse
   Harmonic Mean Weighting (IHMW) function proposed by Laroia et al.
   (see [LAROIA-ICASSP]).  These weights are referred to here as Laroia
   weights.

   The LSF quantizer consists of two stages.  The first stage is an
   (unweighted) vector quantizer (VQ), with a codebook size of 32
   vectors.  The quantization errors for the codebook vector are sorted,
   and for the N best vectors a second stage quantizer is run.  By
   varying the number N, a trade-off is made between R-D performance and
   computational efficiency.  For each of the N codebook vectors, the
   Laroia weights corresponding to that vector (and not to the input
   vector) are calculated.  Then, the residual between the input LSF
   vector and the codebook vector is scaled by the square roots of these
   Laroia weights.  This scaling partially normalizes error sensitivity
   for the residual vector so that a uniform quantizer with fixed step
   sizes can be used in the second stage without too much performance
   loss.  Additionally, by scaling with Laroia weights determined from
   the first-stage codebook vector, the process can be reversed in the
   decoder.

   The second stage uses predictive delayed decision scalar
   quantization.  The quantization error is weighted by Laroia weights
   determined from the LSF input vector.  The predictor multiplies the
   previous quantized residual value by a prediction coefficient that
   depends on the vector index from the first stage VQ and on the
   location in the LSF vector.  The prediction is subtracted from the
   LSF residual value before quantizing the result and is added back
   afterwards.  This subtraction can be interpreted as shifting the
   quantization levels of the scalar quantizer, and as a result the
   quantization error of each value depends on the quantization decision
   of the previous value.  This dependency is exploited by the delayed
   decision mechanism to search for a quantization sequency with best
   R-D performance with a Viterbi-like algorithm [VITERBI].  The
   quantizer processes the residual LSF vector in reverse order (i.e.,
   it starts with the highest residual LSF value).  This is done because
   the prediction works slightly better in the reverse direction.








Valin, et al.                Standards Track                  [Page 147]

RFC 6716                 Interactive Audio Codec          September 2012


   The quantization index of the first stage is entropy coded.  The
   quantization sequence from the second stage is also entropy coded,
   where for each element the probability table is chosen depending on
   the vector index from the first stage and the location of that
   element in the LSF vector.

5.2.3.5.1.  LSF Stabilization


   If the input is stable, finding the best candidate usually results in
   a quantized vector that is also stable.  Because of the two-stage
   approach, however, it is possible that the best quantization
   candidate is unstable.  The encoder applies the same stabilization
   procedure applied by the decoder (see Section 4.2.7.5.4) to ensure
   the LSF parameters are within their valid range, increasingly sorted,
   and have minimum distances between each other and the border values.

5.2.3.6.  LTP Quantization



   For voiced frames, the prediction analysis described in
   Section 5.2.3.4.1 resulted in four sets (one set per subframe) of
   five LTP coefficients, plus four weighting matrices.  The LTP
   coefficients for each subframe are quantized using entropy
   constrained vector quantization.  A total of three vector codebooks
   are available for quantization, with different rate-distortion trade-
   offs.  The three codebooks have 10, 20, and 40 vectors and average
   rates of about 3, 4, and 5 bits per vector, respectively.
   Consequently, the first codebook has larger average quantization
   distortion at a lower rate, whereas the last codebook has smaller
   average quantization distortion at a higher rate.  Given the
   weighting matrix W_ltp and LTP vector b, the weighted rate-distortion
   measure for a codebook vector cb_i with rate r_i is give by

               RD = u * (b - cb_i)' * W_ltp * (b - cb_i) + r_i

   where u is a fixed, heuristically determined parameter balancing the
   distortion and rate.  Which codebook gives the best performance for a
   given LTP vector depends on the weighting matrix for that LTP vector.
   For example, for a low valued W_ltp, it is advantageous to use the
   codebook with 10 vectors as it has a lower average rate.  For a large
   W_ltp, on the other hand, it is often better to use the codebook with
   40 vectors, as it is more likely to contain the best codebook vector.
   The weighting matrix W_ltp depends mostly on two aspects of the input
   signal.  The first is the periodicity of the signal; the more
   periodic, the larger W_ltp.  The second is the change in signal
   energy in the current subframe, relative to the signal one pitch lag
   earlier.  A decaying energy leads to a larger W_ltp than an
   increasing energy.  Both aspects fluctuate relatively slowly, which
   causes the W_ltp matrices for different subframes of one frame often



Valin, et al.                Standards Track                  [Page 148]

RFC 6716                 Interactive Audio Codec          September 2012


   to be similar.  Because of this, one of the three codebooks typically
   gives good performance for all subframes.  Therefore, the codebook
   search for the subframe LTP vectors is constrained to only allow
   codebook vectors to be chosen from the same codebook, resulting in a
   rate reduction.

   To find the best codebook, each of the three vector codebooks is used
   to quantize all subframe LTP vectors and produce a combined weighted
   rate-distortion measure for each vector codebook.  The vector
   codebook with the lowest combined rate-distortion over all subframes
   is chosen.  The quantized LTP vectors are used in the noise shaping
   quantizer, and the index of the codebook plus the four indices for
   the four subframe codebook vectors are passed on to the range
   encoder.

5.2.3.7.  Pre-filter



   In the pre-filter, the input signal is filtered using the spectral
   valley de-emphasis filter coefficients from the noise shaping
   analysis (see Section 5.2.3.3).  By applying only the noise shaping
   analysis filter to the input signal, it provides the input to the
   noise shaping quantizer.

5.2.3.8.  Noise Shaping Quantizer



   The noise shaping quantizer independently shapes the signal and
   coding noise spectra to obtain a perceptually higher quality at the
   same bitrate.

   The pre-filter output signal is multiplied with a compensation gain G
   computed in the noise shaping analysis.  Then, the output of a
   synthesis shaping filter is added, and the output of a prediction
   filter is subtracted to create a residual signal.  The residual
   signal is multiplied by the inverse quantized quantization gain from
   the noise shaping analysis and input to a scalar quantizer.  The
   quantization indices of the scalar quantizer represent a signal of
   pulses that is input to the pyramid range encoder.  The scalar
   quantizer also outputs a quantization signal, which is multiplied by
   the quantized quantization gain from the noise shaping analysis to
   create an excitation signal.  The output of the prediction filter is
   added to the excitation signal to form the quantized output signal
   y(n).  The quantized output signal y(n) is input to the synthesis
   shaping and prediction filters.








Valin, et al.                Standards Track                  [Page 149]

RFC 6716                 Interactive Audio Codec          September 2012


   Optionally, the noise shaping quantizer operates in a delayed
   decision mode.  In this mode, it uses a Viterbi algorithm to keep
   track of multiple rounding choices in the quantizer and select the
   best one after a delay of 32 samples.  This improves the rate/
   distortion performance of the quantizer.

5.2.3.9.  Constant Bitrate Mode



   SILK was designed to run in variable bitrate (VBR) mode.  However,
   the reference implementation also has a constant bitrate (CBR) mode
   for SILK.  In CBR mode, SILK will attempt to encode each packet with
   no more than the allowed number of bits.  The Opus wrapper code then
   pads the bitstream if any unused bits are left in SILK mode, or it
   encodes the high band with the remaining number of bits in Hybrid
   mode.  The number of payload bits is adjusted by changing the
   quantization gains and the rate/distortion trade-off in the noise
   shaping quantizer, in an iterative loop around the noise shaping
   quantizer and entropy coding.  Compared to the SILK VBR mode, the CBR
   mode has lower audio quality at a given average bitrate and has
   higher computational complexity.

5.3.  CELT Encoder



   Most of the aspects of the CELT encoder can be directly derived from
   the description of the decoder.  For example, the filters and
   rotations in the encoder are simply the inverse of the operation
   performed by the decoder.  Similarly, the quantizers generally
   optimize for the mean square error (because noise shaping is part of
   the bitstream itself), so no special search is required.  For this
   reason, only the less straightforward aspects of the encoder are
   described here.

5.3.1.  Pitch Pre-filter



   The pitch pre-filter is applied after the pre-emphasis.  It is
   applied in such a way as to be the inverse of the decoder's post-
   filter.  The main non-obvious aspect of the pre-filter is the
   selection of the pitch period.  The pitch search should be optimized
   for the following criteria:

   o  continuity: it is important that the pitch period does not change
      abruptly between frames; and

   o  avoidance of pitch multiples: when the period used is a multiple
      of the real period (lower frequency fundamental), the post-filter
      loses most of its ability to reduce noise





Valin, et al.                Standards Track                  [Page 150]

RFC 6716                 Interactive Audio Codec          September 2012


5.3.2.  Bands and Normalization



   The MDCT output is divided into bands that are designed to match the
   ear's critical bands for the smallest (2.5 ms) frame size.  The
   larger frame sizes use integer multiples of the 2.5 ms layout.  For
   each band, the encoder computes the energy that will later be
   encoded.  Each band is then normalized by the square root of the
   *unquantized* energy, such that each band now forms a unit vector X.
   The energy and the normalization are computed by
   compute_band_energies() and normalise_bands() (bands.c),
   respectively.

5.3.3.  Energy Envelope Quantization



   Energy quantization (both coarse and fine) can be easily understood
   from the decoding process.  For all useful bitrates, the coarse
   quantizer always chooses the quantized log energy value that
   minimizes the error for each band.  Only at very low rate does the
   encoder allow larger errors to minimize the rate and avoid using more
   bits than are available.  When the available CPU requirements allow
   it, it is best to try encoding the coarse energy both with and
   without inter-frame prediction such that the best prediction mode can
   be selected.  The optimal mode depends on the coding rate, the
   available bitrate, and the current rate of packet loss.

   The fine energy quantizer always chooses the quantized log energy
   value that minimizes the error for each band because the rate of the
   fine quantization depends only on the bit allocation and not on the
   values that are coded.

5.3.4.  Bit Allocation



   The encoder must use exactly the same bit allocation process as used
   by the decoder and described in Section 4.3.3.  The three mechanisms
   that can be used by the encoder to adjust the bitrate on a frame-by-
   frame basis are band boost, allocation trim, and band skipping.

5.3.4.1.  Band Boost



   The reference encoder makes a decision to boost a band when the
   energy of that band is significantly higher than that of the
   neighboring bands.  Let E_j be the log-energy of band j, we define

      D_j = 2*E_j - E_j-1 - E_j+1

   The allocation of band j is boosted once if D_j > t1 and twice if D_j
   > t2.  For LM>=1, t1=2 and t2=4, while for LM<1, t1=3 and t2=5.




Valin, et al.                Standards Track                  [Page 151]

RFC 6716                 Interactive Audio Codec          September 2012


5.3.4.2.  Allocation Trim



   The allocation trim is a value between 0 and 10 (inclusively) that
   controls the allocation balance between the low and high frequencies.
   The encoder starts with a safe "default" of 5 and deviates from that
   default in two different ways.  First, the trim can deviate by +/- 2
   depending on the spectral tilt of the input signal.  For signals with
   more low frequencies, the trim is increased by up to 2, while for
   signals with more high frequencies, the trim is decreased by up to 2.
   For stereo inputs, the trim value can be decreased by up to 4 when
   the inter-channel correlation at low frequency (first 8 bands) is
   high.

5.3.4.3.  Band Skipping



   The encoder uses band skipping to ensure that the shape of the bands
   is only coded if there is at least 1/2 bit per sample available for
   the PVQ.  If not, then no bit is allocated and folding is used
   instead.  To ensure continuity in the allocation, some amount of
   hysteresis is added to the process, such that a band that received
   PVQ bits in the previous frame only needs 7/16 bit/sample to be coded
   for the current frame, while a band that did not receive PVQ bits in
   the previous frames needs at least 9/16 bit/sample to be coded.

5.3.5.  Stereo Decisions



   Because CELT applies mid-side stereo coupling in the normalized
   domain, it does not suffer from important stereo image problems even
   when the two channels are completely uncorrelated.  For this reason,
   it is always safe to use stereo coupling on any audio frame.  That
   being said, there are some frames for which dual (independent) stereo
   is still more efficient.  This decision is made by comparing the
   estimated entropy with and without coupling over the first 13 bands,
   taking into account the fact that all bands with more than two MDCT
   bins require one extra degree of freedom when coded in mid-side.  Let
   L1_ms and L1_lr be the L1-norm of the mid-side vector and the L1-norm
   of the left-right vector, respectively.  The decision to use mid-side
   is made if and only if

                            L1_ms          L1_lr
                           --------    <   -----
                           bins + E        bins

   where bins is the number of MDCT bins in the first 13 bands and E is
   the number of extra degrees of freedom for mid-side coding.  For
   LM>1, E=13, otherwise E=5.





Valin, et al.                Standards Track                  [Page 152]

RFC 6716                 Interactive Audio Codec          September 2012


   The reference encoder decides on the intensity stereo threshold based
   on the bitrate alone.  After taking into account the frame size by
   subtracting 80 bits per frame for coarse energy, the first band using
   intensity coding is as follows:

                     +------------------+------------+
                     | bitrate (kbit/s) | start band |
                     +------------------+------------+
                     |        <35       |      8     |
                     |                  |            |
                     |       35-50      |     12     |
                     |                  |            |
                     |       50-68      |     16     |
                     |                  |            |
                     |       84-84      |     18     |
                     |                  |            |
                     |      84-102      |     19     |
                     |                  |            |
                     |      102-130     |     20     |
                     |                  |            |
                     |       >130       |  disabled  |
                     +------------------+------------+

                 Table 66: Thresholds for Intensity Stereo

5.3.6.  Time-Frequency Decision



   The choice of time-frequency resolution used in Section 4.3.4.5 is
   based on R-D optimization.  The distortion is the L1-norm (sum of
   absolute values) of each band after each TF resolution under
   consideration.  The L1 norm is used because it represents the entropy
   for a Laplacian source.  The number of bits required to code a change
   in TF resolution between two bands is higher than the cost of having
   those two bands use the same resolution, which is what requires the
   R-D optimization.  The optimal decision is computed using the Viterbi
   algorithm.  See tf_analysis() in celt/celt.c.

5.3.7.  Spreading Values Decision



   The choice of the spreading value in Table 59 has an impact on the
   nature of the coding noise introduced by CELT.  The larger the f_r
   value, the lower the impact of the rotation, and the more tonal the
   coding noise.  The more tonal the signal, the more tonal the noise
   should be, so the CELT encoder determines the optimal value for f_r
   by estimating how tonal the signal is.  The tonality estimate is
   based on discrete pdf (4-bin histogram) of each band.  Bands that





Valin, et al.                Standards Track                  [Page 153]

RFC 6716                 Interactive Audio Codec          September 2012


   have a large number of small values are considered more tonal and a
   decision is made by combining all bands with more than 8 samples.
   See spreading_decision() in celt/bands.c.

5.3.8.  Spherical Vector Quantization



   CELT uses a Pyramid Vector Quantizer (PVQ) [PVQ] for quantizing the
   details of the spectrum in each band that have not been predicted by
   the pitch predictor.  The PVQ codebook consists of all sums of K
   signed pulses in a vector of N samples, where two pulses at the same
   position are required to have the same sign.  Thus, the codebook
   includes all integer codevectors y of N dimensions that satisfy
   sum(abs(y(j))) = K.

   In bands where there are sufficient bits allocated, PVQ is used to
   encode the unit vector that results from the normalization in
   Section 5.3.2 directly.  Given a PVQ codevector y, the unit vector X
   is obtained as X = y/||y||, where ||.|| denotes the L2 norm.

5.3.8.1.  PVQ Search



   The search for the best codevector y is performed by alg_quant()
   (vq.c).  There are several possible approaches to the search, with a
   trade-off between quality and complexity.  The method used in the
   reference implementation computes an initial codeword y1 by
   projecting the normalized spectrum X onto the codebook pyramid of K-1
   pulses:

   y0 = truncate_towards_zero( (K-1) * X / sum(abs(X)))

   Depending on N, K and the input data, the initial codeword y0 may
   contain from 0 to K-1 non-zero values.  All the remaining pulses,
   with the exception of the last one, are found iteratively with a
   greedy search that minimizes the normalized correlation between y and
   X:

                                   T
                             J = -X * y / ||y||

   The search described above is considered to be a good trade-off
   between quality and computational cost.  However, there are other
   possible ways to search the PVQ codebook and the implementers MAY use
   any other search methods.  See alg_quant() in celt/vq.c.








Valin, et al.                Standards Track                  [Page 154]

RFC 6716                 Interactive Audio Codec          September 2012


5.3.8.2.  PVQ Encoding



   The vector to encode, X, is converted into an index i such that
   0 <= i < V(N,K) as follows.  Let i = 0 and k = 0.  Then, for
   j = (N - 1) down to 0, inclusive, do:

   1.  If k > 0, set i = i + (V(N-j-1,k-1) + V(N-j,k-1))/2.

   2.  Set k = k + abs(X[j]).

   3.  If X[j] < 0, set i = i + (V(N-j-1,k) + V(N-j,k))/2.

   The index i is then encoded using the procedure in Section 5.1.4 with
   ft = V(N,K).

6.  Conformance



   It is our intention to allow the greatest possible choice of freedom
   in implementing the specification.  For this reason, outside of the
   exceptions noted in this section, conformance is defined through the
   reference implementation of the decoder provided in Appendix A.
   Although this document includes a prose description of the codec,
   should the description contradict the source code of the reference
   implementation, the latter shall take precedence.

   Compliance with this specification means that, in addition to
   following the normative keywords in this document, a decoder's output
   MUST also be within the thresholds specified by the opus_compare.c
   tool (included with the code) when compared to the reference
   implementation for each of the test vectors provided (see
   Appendix A.4) and for each output sampling rate and channel count
   supported.  In addition, a compliant decoder implementation MUST have
   the same final range decoder state as that of the reference decoder.
   It is therefore RECOMMENDED that the decoder implement the same
   functional behavior as the reference.  A decoder implementation is
   not required to support all output sampling rates or all output
   channel counts.

6.1.  Testing



   Using the reference code provided in Appendix A, a test vector can be
   decoded with

      opus_demo -d <rate> <channels> testvectorX.bit testX.out

   where <rate> is the sampling rate and can be 8000, 12000, 16000,
   24000, or 48000, and <channels> is 1 for mono or 2 for stereo.




Valin, et al.                Standards Track                  [Page 155]

RFC 6716                 Interactive Audio Codec          September 2012


   If the range decoder state is incorrect for one of the frames, the
   decoder will exit with "Error: Range coder state mismatch between
   encoder and decoder".  If the decoder succeeds, then the output can
   be compared with the "reference" output with

      opus_compare -s -r <rate> testvectorX.dec testX.out

   for stereo or

      opus_compare -r <rate> testvectorX.dec testX.out

   for mono.

   In addition to indicating whether the test vector comparison passes,
   the opus_compare tool outputs an "Opus quality metric" that indicates
   how well the tested decoder matches the reference implementation.  A
   quality of 0 corresponds to the passing threshold, while a quality of
   100 is the highest possible value and means that the output of the
   tested decoder is identical to the reference implementation.  The
   passing threshold (quality 0) was calibrated in such a way that it
   corresponds to additive white noise with a 48 dB SNR (similar to what
   can be obtained on a cassette deck).  It is still possible for an
   implementation to sound very good with such a low quality measure
   (e.g., if the deviation is due to inaudible phase distortion), but
   unless this is verified by listening tests, it is RECOMMENDED that
   implementations achieve a quality above 90 for 48 kHz decoding.  For
   other sampling rates, it is normal for the quality metric to be lower
   (typically, as low as 50 even for a good implementation) because of
   harmless mismatch with the delay and phase of the internal sampling
   rate conversion.

   On POSIX environments, the run_vectors.sh script can be used to
   verify all test vectors.  This can be done with

      run_vectors.sh <exec path> <vector path> <rate>

   where <exec path> is the directory where the opus_demo and
   opus_compare executables are built and <vector path> is the directory
   containing the test vectors.

6.2.  Opus Custom



   Opus Custom is an OPTIONAL part of the specification that is defined
   to handle special sample rates and frame rates that are not supported
   by the main Opus specification.  Use of Opus Custom is discouraged
   for all but very special applications for which a frame size
   different from 2.5, 5, 10, or 20 ms is needed (for either complexity
   or latency reasons).  Because Opus Custom is optional, streams



Valin, et al.                Standards Track                  [Page 156]

RFC 6716                 Interactive Audio Codec          September 2012


   encoded using Opus Custom cannot be expected to be decodable by all
   Opus implementations.  Also, because no in-band mechanism exists for
   specifying the sampling rate and frame size of Opus Custom streams,
   out-of-band signaling is required.  In Opus Custom operation, only
   the CELT layer is available, using the opus_custom_* function calls
   in opus_custom.h.

7.  Security Considerations



   Like any other audio codec, Opus should not be used with insecure
   ciphers or cipher-modes that are vulnerable to known plaintext
   attacks.  In addition to the zeros used in Opus padding, digital
   silence frames generate predictable compressed results and the TOC
   byte may have an easily predictable value.

   Implementations of the Opus codec need to take appropriate security
   considerations into account, as outlined in [DOS].  It is extremely
   important for the decoder to be robust against malicious payloads.
   Malicious payloads must not cause the decoder to overrun its
   allocated memory or to take an excessive amount of resources to
   decode.  Although problems in encoders are typically rarer, the same
   applies to the encoder.  Malicious audio streams must not cause the
   encoder to misbehave because this would allow an attacker to attack
   transcoding gateways.

   The reference implementation contains no known buffer overflow or
   cases where a specially crafted packet or audio segment could cause a
   significant increase in CPU load.  However, on certain CPU
   architectures where denormalized floating-point operations are much
   slower than normal floating-point operations, it is possible for some
   audio content (e.g., silence or near silence) to cause an increase in
   CPU load.  Denormals can be introduced by reordering operations in
   the compiler and depend on the target architecture, so it is
   difficult to guarantee that an implementation avoids them.  For
   architectures on which denormals are problematic, adding very small
   floating-point offsets to the affected signals to prevent significant
   numbers of denormalized operations is RECOMMENDED.  Alternatively, it
   is often possible to configure the hardware to treat denormals as
   zero (DAZ).  No such issue exists for the fixed-point reference
   implementation.

   The reference implementation was validated in the following
   conditions:

   1.  Sending the decoder valid packets generated by the reference
       encoder and verifying that the decoder's final range coder state
       matches that of the encoder.




Valin, et al.                Standards Track                  [Page 157]

RFC 6716                 Interactive Audio Codec          September 2012


   2.  Sending the decoder packets generated by the reference encoder
       and then subjected to random corruption.

   3.  Sending the decoder random packets.

   4.  Sending the decoder packets generated by a version of the
       reference encoder modified to make random coding decisions
       (internal fuzzing), including mode switching, and verifying that
       the range coder final states match.

   In all of the conditions above, both the encoder and the decoder were
   run inside the Valgrind [VALGRIND] memory debugger, which tracks
   reads and writes to invalid memory regions as well as the use of
   uninitialized memory.  There were no errors reported on any of the
   tested conditions.

8.  Acknowledgements



   Thanks to all other developers, including Henrik Astrom, Jon
   Bergenheim, Raymond Chen, Soren Skak Jensen, Gregory Maxwell,
   Christopher Montgomery, and Karsten Vandborg Sorensen.  We would also
   like to thank Igor Dyakonov, Hoang Thi Minh Nguyet, Christian Hoene,
   Gian-Carlo Pascutto, and Jan Skoglund for their help with testing of
   the Opus codec.  Thanks to Andrew D'Addesio, Elwyn Davies, Ralph
   Giles, John Ridges, Ben Schwartz, Kat Walsh, Mark Warner, Keith Yan,
   and many others on the Opus and CELT mailing lists for their bug
   reports and feedback.  At last, the authors would like to thank
   Robert Sparks, Cullen Jennings, and Jonathan Rosenberg for their
   support throughout the standardization process.






















Valin, et al.                Standards Track                  [Page 158]

RFC 6716                 Interactive Audio Codec          September 2012


9.  References



9.1.  Normative References



   [RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
              Requirement Levels", BCP 14, RFC 2119, March 1997.

9.2.  Informative References



   [BURG]     Burg, J., "Maximum Entropy Spectral Analysis", Proceedings
              of the 37th Annual International SEG Meeting, Vol.
              6, 1975.

   [CELT]     Valin, JM., Terriberry, T., Maxwell, G., and C.
              Montgomery, "Constrained-Energy Lapped Transform (CELT)
              Codec", Work in Progress, July 2010.

   [CODING-THESIS]
              Pasco, R., "Source coding algorithms for fast data
              compression", Ph.D. thesis Dept. of Electrical
              Engineering, Stanford University, May 1976.

   [DOS]      Handley, M., Rescorla, E., and IAB, "Internet Denial-of-
              Service Considerations", RFC 4732, December 2006.

   [FFT]      Wikipedia, "Fast Fourier Transform",
              <http://en.wikipedia.org/w/
              index.php?title=Fast_Fourier_transform&oldid=508004516>.

   [GOOGLE-NETEQ]
              "Google NetEQ code", <http://code.google.com/p/webrtc/
              source/browse/trunk/src/modules/audio_coding/NetEQ/main/
              source/?r=583>.

   [GOOGLE-WEBRTC]
              "Google WebRTC code", <http://code.google.com/p/webrtc/>.

   [HADAMARD] Wikipedia, "Hadamard Transform", <http://en.wikipedia.org/
              w/index.php?title=Hadamard_transform&oldid=508252957>.

   [KABAL86]  Kabal, P. and R. Ramachandran, "The Computation of Line
              Spectral Frequencies Using Chebyshev Polynomials", IEEE
              Trans. Acoustics, Speech, Signal Processing, Vol. 34, no.
              6, pp. 1419-1426, December 1986.







Valin, et al.                Standards Track                  [Page 159]

RFC 6716                 Interactive Audio Codec          September 2012


   [LAROIA-ICASSP]
              Laroia, R., Phamdo, N., and N. Farvardin, "Robust and
              Efficient Quantization of Speech LSP Parameters Using
              Structured Vector Quantization", ICASSP-1991, Proc. IEEE
              Int. Conf. Acoust., Speech, Signal Processing, pp. 641-
              644, October 1991.

   [LPC]      Wikipedia, "Linear Prediction", <http://en.wikipedia.org/
              w/index.php?title=Linear_prediction&oldid=497201278>.

   [MARTIN79] Martin, G., "Range encoding: An algorithm for removing
              redundancy from a digitised message", Proc. Institution of
              Electronic and Radio Engineers International Conference on
              Video and Data Recording, 1979.

   [MATROSKA-WEBSITE]
              "Matroska website", <http://matroska.org/>.

   [MDCT]     Wikipedia, "Modified Discrete Cosine Transform", <http://
              en.wikipedia.org/w/
              index.php?title=Modified_discrete_cosine_
              transform&oldid=490295438>.

   [OPUS-GIT] "Opus Git Repository", <https://git.xiph.org/opus.git>.

   [OPUS-WEBSITE]
              "Opus website", <http://opus-codec.org/>.

   [PRINCEN86]
              Princen, J. and A. Bradley, "Analysis/Synthesis Filter
              Bank Design Based on Time Domain Aliasing Cancellation",
              IEEE Trans. Acoustics, Speech, and Siginal Processing,
              ASSP-34 (5), pp. 1153-1161, October, 1986.

   [PVQ]      Fischer, T., "A Pyramid Vector Quantizer", IEEE Trans. on
              Information Theory, Vol. 32, pp. 568-583, July 1986.

   [RANGE-CODING]
              Wikipedia, "Range Coding", <http://en.wikipedia.org/w/
              index.php?title=Range_encoding&oldid=509582757>.

   [REQUIREMENTS]
              Valin, JM. and K. Vos, "Requirements for an Internet Audio
              Codec", RFC 6366, August 2011.







Valin, et al.                Standards Track                  [Page 160]

RFC 6716                 Interactive Audio Codec          September 2012


   [RFC3533]  Pfeiffer, S., "The Ogg Encapsulation Format Version 0",
              RFC 3533, May 2003.

   [RFC3550]  Schulzrinne, H., Casner, S., Frederick, R., and V.
              Jacobson, "RTP: A Transport Protocol for Real-Time
              Applications", STD 64, RFC 3550, July 2003.

   [SCHUR]    Le Roux, J. and C. Gueguen, "A fixed point computation of
              partial correlation coefficients", ICASSP-1977, Proc. IEEE
              Int. Conf. Acoustics, Speech, and Signal Processing, pp.
              257-259, June 1977.

   [SILK]     Vos, K., Jensen, S., and K. Sorensen, "SILK Speech Codec",
              Work in Progress, September 2010.

   [SPECTRAL-PAIRS]
              Wikipedia, "Line Spectral Pairs", <http://
              en.wikipedia.org/w/
              index.php?title=Line_spectral_pairs&oldid=365426016>.

   [SRTP-VBR] Perkins, C. and JM. Valin, "Guidelines for the Use of
              Variable Bit Rate Audio with Secure RTP", RFC 6562,
              March 2012.

   [VALGRIND] "Valgrind website", <http://valgrind.org/>.

   [VALIN2010]
              Valin, JM., Terriberry, T., Montgomery, C., and G.
              Maxwell, "A High-Quality Speech and Audio Codec With Less
              Than 10 ms Delay", IEEE Trans. on Audio, Speech, and
              Language Processing, Vol. 18, No. 1, pp. 58-67 2010.

   [VECTORS-PROC]
              "Opus Testvectors (proceedings)", <http://www.ietf.org/
              proceedings/83/slides/slides-83-codec-0.gz>.

   [VECTORS-WEBSITE]
              "Opus Testvectors (website)",
              <http://opus-codec.org/testvectors/>.

   [VITERBI]  Wikipedia, "Viterbi Algorithm", <http://en.wikipedia.org/
              w/index.php?title=Viterbi_algorithm&oldid=508835871>.

   [VORBIS-WEBSITE]
              "Vorbis website", <http://xiph.org/vorbis/>.






Valin, et al.                Standards Track                  [Page 161]

RFC 6716                 Interactive Audio Codec          September 2012


   [WHITENING]
              Wikipedia, "White Noise", <http://en.wikipedia.org/w/
              index.php?title=White_noise&oldid=497791998>.

   [Z-TRANSFORM]
              Wikipedia, "Z-transform", <http://en.wikipedia.org/w/
              index.php?title=Z-transform&oldid=508392884>.

   [ZWICKER61]
              Zwicker, E., "Subdivision of the Audible Frequency Range
              into Critical Bands", The Journal of the Acoustical
              Society of America, Vol. 33, No 2 pp. 248, February 1961.







































Valin, et al.                Standards Track                  [Page 162]

RFC 6716                 Interactive Audio Codec          September 2012


Appendix A.  Reference Implementation



   This appendix contains the complete source code for the reference
   implementation of the Opus codec written in C.  By default, this
   implementation relies on floating-point arithmetic, but it can be
   compiled to use only fixed-point arithmetic by defining the
   FIXED_POINT macro.  The normative behavior is defined as the output
   using the floating-point configuration.  Information on building and
   using the reference implementation is available in the README file.

   The implementation can be compiled with either a C89 or a C99
   compiler.  It is reasonably optimized for most platforms such that
   only architecture-specific optimizations are likely to be useful.
   The Fast Fourier Transform (FFT) [FFT] used is a slightly modified
   version of the KISS-FFT library, but it is easy to substitute any
   other FFT library.

   While the reference implementation does not rely on any _undefined
   behavior_ as defined by C89 or C99, it relies on common
   _implementation-defined behavior_ for two's complement architectures:

   o  Right shifts of negative values are consistent with two's
      complement arithmetic, so that a>>b is equivalent to
      floor(a/(2**b)),

   o  For conversion to a signed integer of N bits, the value is reduced
      modulo 2**N to be within range of the type,

   o  The result of integer division of a negative value is truncated
      towards zero, and

   o  The compiler provides a 64-bit integer type (a C99 requirement
      which is supported by most C89 compilers).

   In its current form, the reference implementation also requires the
   following architectural characteristics to obtain acceptable
   performance:

   o  Two's complement arithmetic,

   o  At least a 16 bit by 16 bit integer multiplier (32-bit result),
      and

   o  At least a 32-bit adder/accumulator.







Valin, et al.                Standards Track                  [Page 163]

RFC 6716                 Interactive Audio Codec          September 2012


A.1.  Extracting the Source



   The complete source code can be extracted from this document, by
   running the following command line:

   o  cat rfc6716.txt | grep '^\ \ \ ###' | sed -e 's/...###//' | base64
      --decode > opus-rfc6716.tar.gz

   o  tar xzvf opus-rfc6716.tar.gz

   o  cd opus-rfc6716

   o  make

   On systems where the provided Makefile does not work, the following
   command line may be used to compile the source code:

   o  cc -O2 -g -o opus_demo src/opus_demo.c `cat *.mk | grep -v fixed |
      sed -e 's/.*=//' -e 's/\\\\//'` -DOPUS_BUILD -Iinclude -Icelt
      -Isilk -Isilk/float -DUSE_ALLOCA -Drestrict= -lm

   On systems where the base64 utility is not present, the following
   commands can be used instead:

   o  cat rfc6716.txt | grep '^\ \ \ ###' | sed -e 's/...###//' >
      opus.b64

   o  openssl base64 -d -in opus.b64 > opus-rfc6716.tar.gz

   The SHA1 hash of the opus-rfc6716.tar.gz file is
   86a927223e73d2476646a1b933fcd3fffb6ecc8c.

A.2.  Up-to-Date Implementation



   As of the time of publication of this memo, an up-to-date
   implementation conforming to this RFC is available in a Git
   repository [OPUS-GIT].  Releases and other resources are available at
   [OPUS-WEBSITE].  However, although that implementation is expected to
   remain conformant with the RFC, it is the code in this document that
   shall remain normative.

A.3.  Base64-Encoded Source Code



   ###H4sIAEeqNVACA+xde3PixrLfv/kUfXarEvDF2ODHZrNJajHIWCe8LgJ7t+65pSOL
   ###AXRWSEQPe52c891v98xISEI8vMZ7kyqTikHSdE93T0/Pr+ehdRehf+hNzPO31fOj
   ###V8/zOcbP27dn/Bs/2W/+u1o7rp6d1M6qx29fHVfxv7NXcPbqL/TJKvcX+bjJ9m/0
   ###+p/Ubus5THN+frqu/U9O3lZl+x/XzslPqugF1Vfw6qX9n/3TcBcPnjWdBVB99+70
   ###EFuhCqoyvIShF/pBGT5ai1ml503LoH1+WDBoW3MrYOMy9MzA8C2zXICcz9+Z4Rx2



Valin, et al.                Standards Track                  [Page 164]

RFC 6716                 Interactive Audio Codec          September 2012


   ###DM+Ea8O2nDIMrbkbzB7gogJD5nnWLf55yKdtaOqgV4aWx6au9wAd48s9s+0y/vA+
   ###w4XrTZk3tpxpPrHiWZ9hzKBh+IHnQttduBWo2zZwHX3wmM+8OzauFArDmeXDxLIZ
   ###4Df7EniGiYrBxHPnMLhsUIeoQN9mhs/AZwyCmRHQA5i4HhjjsRVYrmPYBcvBG3OD
   ###rpDrgI0trNq6DekGGM4YQmRgOeC7oWcyfufWcgxUjej8MtxbwQyQJ327YVCYu2Nr
   ###YpmcYxkMj8GCeWh1km7huXfWGH9waYIZQya27d6jQcB0HSGUXyCiOQt+LBQOIS2R
   ###D+4kEsV00VJzbGY0S2CgiMTPuHXv6JF0i4LjBpbJyvgMzWQjJ2KwrIrrk5YDqzNt
   ###w5ozr5JXP9aT0D+qHxUbhybbuwgg1CqMXTOcMycwomY5QoujS2IJbDvmWYbtL63L
   ###m4RYJkXn2nSZxYnooWPMGYmiOsjAYQFormmx4KEsehBWkOxJjsupCkQlWmHBTGpo
   ###UkVU4nroDnPjAW4ZeQ1q5QJzxnibETcUD3sRKwhboTePUe67yGe5dXx3EtxT60tn
   ###Wlay8CzyMY/8yClwj/J9odXwStVA610Ob+oDBfB3f9C7VptKEy4+wfBKARoXBmrr
   ###aghXvXZTGWhQ7zbxbnc4UC9Gw95AK/zzn3UNSb//nj+qdz+B8rE/UDQNegNQO/22
   ###iuyQ/6DeHaqKhibqNtqjJo42ZUAW0O0NC221ow6x2BC7P1W7Sga9S+gog8YVXtYv
   ###1LY6/MTru1SHXarrsjco1KFfHwzVxqhdH0B/NOj3NAVIsaaqNdp1taM0K1g71gjK
   ###tdIdgnZVb7czevZuusqggKInlYQLBdpq/aKtUEVcyaY6UBpD0mb5q4GmQ/HaGDL7
   ###SkPFHwXlo4K61AefyiB4asp/j7AQPoRmvVNvoWrFVYtAwiIFbJTGaKB0SGQ0gza6
   ###0IbqcDRUoNXrNbmdNWVwrTYU7T20exo31khTyljDsE4VEwu0FD7GshcjTeU2U7tD
   ###ZTAY9Ydqr1vCBr5Bq6CMdSRtcuP2ulxVNFBv8AmZFsgG3PZluLlS8P6A7MktVScT
   ###aGixxhASxbA+NOAwoWOhq7TaakvpNhR62iMuN6qmlLCpVJSsRSyp2ps61jniKlMT
   ###oVTip6oVIpct84YE9RLqzWuVxJaFsek1VboJN1njSpq7Unj18lnBfyazA10MDn5l
   ###/vlb4b/zM4H/T8+rteo54f+T4/PjF/z3LT5vYIkAi2YJCAASCqylxq4MnlsDqd4U
   ###3gDsC1YhqxSy4sz3gK6Qyx4AFnKJMRaX7Mk4C3k8DWqtEePxcOuJkkSIC9nsBXRJ
   ###vZ4OvEivJ2MvZLIH+EVcEghMdJw9oDBksw8ghmz2g8WQ0R7hGHLbGyJDXvsAZchm
   ###D7hMcNkHNOMttwd0hnz2ANCQy5MwWqGhtIe61hsN0HjwMxA+ObrFOOJXTPhHgV/S
   ###n8TVvZd4hqGHYm/qxpiZqWvmJK4/Y4/UJ5MEQ9tY2IaZYIGBa+YuEpXMx2aiPI4t
   ###LPFwYQXmLC2sbi8SNf4WGk6gZ3TyMDgur+5+q5iFb4L/LMe0wzE7egZo9Lj5X5oK
   ###fJn//eb4P2p/uqnPQzuggZgZ88rsGfF/rfr2uJaZ/z2rnZ6+4P9v8Tk62CkBiKaB
   ###4dINnbGA5PlJAADcCJQDtw/ZxAEOjgpHBwUqtK88ATJ5At3YQ5oAe0kTIJEm0MWT
   ###swR4apaQL8XjkwTYT5IAe0oShFpPzxFgHzkC7CVHgHSOwPvMHlIE2E+KAPtKEWCv
   ###KQLsMUWA/aQIsJcUAfaWIsCeUgTYS4oAT0wRcEDBEeWgAAfwgY8mq9iFP7v1LDaB
   ###Hj7EwDZhHsJ+HBDmC5stY0+CCup9tUCjVeGNNXHGRNofaXpn1B6qaB2l3tGvCm/w
   ###vuWwvEdIJrAUvCaBKrPXnBMx0nVzYYc+/V/AcQ+DE7xuvIY/Cm8wlFiTQiF4WDAq
   ###iJJgCOEydzTFofHBS1+9zy/bZMmy8up9IZZX17mRzBkzP+toCB/1Z/oi8Ir4fwmK
   ###4uu/oh+HUCROss6DgxK/XSrl88P8ajd+Uq4Ev/UGbSlDHd2shyFN14b1oaIPqCNq
   ###QzhD4LiZrqmsoas9psLil/JD6RGCldNWsZyg+KVU3mD6h9Ij1NggTa66u0iTajiU
   ###hroVQTwXEZBATJaDIzvCuN/xMtVZmHROTg/u7b8YpsTU7aBhIEbMdkldlscqaZX+
   ###oViigdRjHOxxMj5QCj5wP0MoiXax/BniS+qTXG8csiggpXvHwdqqTLwKWFFuGuDF
   ###0AonNbjEIT3xQaV/As3AwECAxeP6TFDzBQ3U1hQRJxSvfi+RGIIAuYA5MxyH2WlO
   ###glU3nN+iYISMZCEJfdI8U+yE6Blugt3QDbC0EzOVRQUQ4QhSAo2If1pON8SAN9bT
   ###FWTlFIWg6GNsYm4pp46YaeiQ/FgYlUPrz43FgrZmRExFs4xB3kfYFNwzbM3YFORV
   ###EfuUpEhgx9A7bYKGS9s/CJ0zDCTkCvU+Ao9GnYZA/bqn9o9W7tZxyOplGu2AeR7C
   ###LcixssKfRKqW3ou+oCbcH4GqjWKPH/Bb9JDx+h6x4rRU/VpPpV4W+WnGuwmppuRM
   ###9btYuxfv/ut4N+zVuyNXHbAg9DAFs5kzpbx2IlImIzBgYTzYroEGoJzvIWB+iVIX
   ###Axw2RYEwx2Mp59/RbYXDrnfXTQ6L6ZUfxE5bPYeDhTlPtp6a9CWDXAzbDgcLyqt8
   ###cmbmV6AtVKVJBQ8zON3HfnoQN4WsijRYPt7o0JIx5WCCZKWnSJ4ZLyEjp3tpLwyI
   ###6jacTIiXyDRR6/nCYz5lkXGTOC42vMfnOhCNGl90YqbzVgLbdaalpB6Z52k96suo
   ###xOauyOujet5jyu18H/ApkQlvakxvMUfnPmwFnmya/frSY2KgPkGuT4yBwqk4o6Q/
   ###5bpU0p+suP+iKsi3Eum92bE2udbXOtYm13oux9rkWvtyLIDItVos8LnMZDIyA0qX
   ###bm6R14Qeo4lFTOM86YxEQHfSPpUY+NYOr1MW8BYqft2QJEJ+blTPjD/wuPEn0eOa



Valin, et al.                Standards Track                  [Page 165]

RFC 6716                 Interactive Audio Codec          September 2012


   ###zIhhN0cVuTA7o/uda423I+2VzpRoCuq7Pn0t5NSksxHmPwbTmIFdzOnHROOx30JG
   ###F5VKJRJmt6xjzB6Xdcjy+8s6ojz7YG1VT8g6UDbBBTCCPRWULZl9LRRL+70EecnW
   ###2CMU28R9CybTRHHUN4riEToLjFubPTkDWHoixtg7yw19O5kC5LrkTj0l8phV9B97
   ###2R7RP/vzY//dA2350YF2kyvBI1wpC5H4usPKQC+advw0mC2YJGF2nl9I0ZtsLczO
   ###hxQJTCTH8gqMfHLz7qjdhoXLIRLZwnLGFg/NC8P8jIOF7fopdI1oqZx3MCPTOgJY
   ###oL9EEEWyyM8CVjGPcK5ybONNEA52xHDPkRwQT9F0+oSZOSa5tI0pFI+PqnI04oOh
   ###WFU0nAekP6S9IQSn7g1vHHuN52FkofSR4/DbRPdf/+H1SWesgDoBRIV+aM4ED7SN
   ###cWdYNvdtvmzH9bKW/kuZF2qJYyN2KGp4Edq+eSdIpgffoitIgP3MPSKuLOoZvFUk
   ###n7w8JsXnIp0DuMleQulZondku0fppXt8i+6xPtdZuui+cp0ITPwFcp1d8o4xe2ze
   ###EePvOO9IhYh1ecdK4rUp1dgtAcsmHSvSUN05K4P/iZcDxTfaNmedkWR4rv1ftLTo
   ###P3Hn1y77v6q12slZZv/X6fHpycv+r2+0/6vYKCX2UUTHgL9u/5fY4AUdvnWKjV+2
   ###gL1sAXvZAvayBexlC9jLFrDn3AKGQ04Ss8CtQV0TY4k7ncY3ef+zrVu8B/G2MUhu
   ###G5Ml+d1dNozx8lR/apPY8FNf0bLbw6KbJCrlkRSfECDaCCnHCEdRPJ48fM9zBIwM
   ###xcD4TDPQJHPfCG248i02w8eLiIDP1GHFUBT1jIu6rg2bDV0vwXffQXSR+I1uodF6
   ###sQ6//Ezj/LvjarsE//53kkOrO4o4LO8iNTqZfsULr9zVS8n7ULyqXytLktJyK9xP
   ###kei/8FAW7V3j0z16cgX4ffJxmHoerhbgSVCC/qS2Qr98HsoCb5iNpot1uVG7JzXa
   ###gQaQvK03PrXwERqEnhDMkJroLR2HhIk1JWV47hNVh0/WCJQqky9VDqfqedYwK3yi
   ###IpFtUNS0dnoHe+INVod6pBj4M9cL1vOPZ0gS5cK8gnESlqdHzCUuFTfCqqA3yuBX
   ###bUXOr+S/L125nD4ryCQXOtp14+jC9WzCN1FeHDdKMivfKG+qZL4LbPOANK88R4iS
   ###yIyd640eN7M4Zx31zwf/SMbAX5JdSFPzpIiejtTVmjPEq+ZIEmdNIKVNRCXa7aLI
   ###sJRS4kqn6ENNYpg9DT7CJU3L3LveZ7gNLXsstvDuoOK2IKQ/NQrpuR1+pWEuFNku
   ###wtMu+HxHUgEkXCv/FumfVXZA4ZXOx4TsPe2oBq1GQ/aQjf1wx4izIR5sjwZZeZt/
   ###b/X7sbT86s8panFw9u74OJa0r9VAUTKi7lJNNs48Wc0V79U+dS7UeleMNFJc7WF+
   ###axlOniesMP5qK2cN+QRjIwa+VFv6UNUbZ6cf09Am+ezsY6mwb2ehvThbFVgW2q7B
   ###+TMI+dVGxhFU+kSLFn/CRRkI5YJBSNh3HT63Pg1ZvH7yZ5Bajp8Sy0cc4onz5O/0
   ###hLqYHhD7oEKagfCBBeZ72s5BU1oBYEC+tQKua5b9+alkw9ua/qwU+SGqKbGIlZEz
   ###TAiX0nE/coYJQdPOuSpwmJA4te4Wz2/HE9wyU3r61PbL50nz/6L59rECsHn+//T0
   ###7Wn2/PfpSe3l/Pf/2/nv453m/zNvBP2q4+CUP/3q4rNr139ZGHhZGHhZGHhZGHhZ
   ###GHhZGHjOs+Exrtn5XDjfLmY4gZ9zIrypXJKxs9P9y9uZk+DRGsMjzoPTzpQPWHLq
   ###ueFCbHGi8cBPbFL2uS5/FMQYegBdV26F+jDDyLjcQe8lMDyXs/drNnE55gx6Do9a
   ###/NCI5dwhMYbekEdxz3CmGPO9KY/M/tYqLupNvT5oLWs4rPIqhrTFm8Y1eXZ9YfAz
   ###K5YfVbid8+jyUhnow15P1zrU6w9r4viAI/aD0kYzYYZ7g6JtwDiM2MaWd5tuva1j
   ###50HXRYFPYoETh2vkCahIaNp0Fi52439db6tNvV9v/KoMif+p3F0u7Iz5UbhYYC6L
   ###vKIdb3JT1jbWoy4FWh5MsIsQ67PIItHhDbTGOLvhLGl0QlDyaOvEY49Qhx8453We
   ###8zo74nyQ3FFF/WiGrTAxLHsHptiavYZ+WVfbkdO8JaYf/iP7NHwgMJFpr2avITuA
   ###8oXsFx1A4rCQOh9MQscUAER2ZMhd+YpuSi9T201a/0nKJ/d86boRiOGf6ToUi3eW
   ###b91athU8QPE1ljdCO3jNX5WQmqCRq01vQESAZTV8lSm3Hmwzm8BAcWzbjGtH9HxO
   ###ZScaDGkRDY8qbyTpKmEq7qDP06ZXTwI99BbsU9HBg8awDWpT+qYvdi0iwQPNxIT2
   ###mEBgjIbGFm3JtB8oC0gcf/UrkG16TRmmTrdGb2yIPqeYXaUpWtspqqt1XKg4oiXe
   ###CJH8IEVttY4tFCerdXTqHzH+dZs3anN4laFDitPVOrZQnK3WcX0xyJVIUpyv1rGF
   ###4m2OrdZIJCl+yLHVZop3q3U0ehS6PuJAvkpyiknpah1bKHLaXO2SXPql0silyGnz
   ###LRQ5bS7Cuk5QTe8jwE3SIUVOm2+hyGnz5vDjhhas5rT5Foq3+X5FqBZ9nlbyU8Sn
   ###x7XjfL/aQJHTHoi6G4pOOUBXaWsrFDntsYUipz00tUWDQ67ySJHTHlsozlYp2r3e
   ###r/UrBZFOnrfXaOyCFBFmVFQRHzKxwA8rUZDrqnIx6t2WkhPTTqo5nqQOG1dr2hkp
   ###Tvj2k45hei4/E4hD13TKPI5qLFsM0hww+eL8I8X8e49mdDlqFfMc8eyGCwYfAhKi
   ###57xlBkfFIm2NLhXp4uefobichS8dl0rl1A0sU1rLbeMrhZZMtrygKNyJU5hhxTEH
   ###DowcdsQgJEblOLQhfEKoBn2PHUbrRfIWwQ8yFAelE8NkYn8/zVxNmcM8y0RyvxxB
   ###NLoQJf4Q2/6xza6XnKhR7gyPzh7GoA65+ysuVMccd8N5h8MqDqR8y349DNwjiVZo



Valin, et al.                Standards Track                  [Page 166]

RFC 6716                 Interactive Audio Codec          September 2012


   ###J35A8zFbwbccDHHAWlsB594xvljzcB6fAM9hzI15QTh3wpMO/HHtqv0jcjSX9tnI
   ###vCwJHMhD6ZyF5QfMIYF/Q2hCwEucGQ4YYp5pBMbmCNOY4MwzpYwIq6bLvHMjq1rt
   ###+PSHtNC3nmuMTcMPjmbWdHY4wQqENIlXfQiJ+QRVdGYkHFtuBJcQKiFANm3X5z8W
   ###ro9g0uYngeNTlY+Wnr8bZFX6dzLLQ0BGs5+8t9vuPWpzaJgzi93xtTgMCWj3B0oP
   ###7mkuU5jR53asYBNZJjukUxtzFGPMkzmU33ASuK/yaIExMvIZBqWJUfWmqbTrn1Dg
   ###s2rmZV0yRmPjNJQ85ztBzCfPcYoTR7eMnITJd7agRnck/ir6FHw7I01trOFb28x3
   ###HvqWCatZcISHunVMK2/oOsm3Wo3kPf189TvQqSbKLXfIriO+HaWpjjo5fKW851/J
   ###F/8qWa6c74ng+8NX8tVGfZoSyjBHvqecb7X2lXwvR+12rrxnnG/teBvfZaKZnXpZ
   ###xuc4B/KYzU9+UwSmaB0lQTJrwuB1h+GJR6+5GHcpWvA+F81W/8MUE1Py5SfInjOJ
   ###R4uKSKqIXTSxzIcN/paAGY+KnrvwLLr2cTThM9ScxXKSRgwc2IVNg/4tNVKdn2Tm
   ###Uxr8tBwf4svidBp/cZHLWdC0O63BLMTcCfFhGCGQgxdYZmgbXjRHUYnV19w5iWpM
   ###GRKKo4A/xg8/kJKRgrSc8Z5f4A/4OWkHcXgLf+P3l3JOKlKMB7lSSfCgPWPE528/
   ###R5NbJRCH6OJ6lhWjtQTVljpTyUzxO6KT9e1CncB5UkgBIoQJ1uAA4ilZpnAAd8cG
   ###33YaekycJpTlvvc5iAvFjCWGJbqy2RccguK8HBLTSnwOD4PVMaIAsbfMpy0Z3Cfx
   ###Dq3voAs7QeQkNKjRUJfHNkIOHO0Q0+qxPMGITmLM/8dy/he+wE9B8Asa/qcj/P6R
   ###5hmx5vKyakGwbaBI54kEKDekj7kvPUyfxUxbTygGprSwXNzj7ZNTTVJFNwwSOh5I
   ###Jb9KxVa+iq0dVeTI9ksp11ciBCbXD6Xyoq0GBh075itRZwgLMcbQmzXxF9/6QQd5
   ###fcaxr1izNAhyTUL+Oi765xnpW6yRHYg1K3RBiX5TaJFjUiOauUtgyKU7CTdawZiI
   ###K5JLa6YRyl30pIRJt0KBm+Z0Zpf0FCHQpyO5SFxGCGOZ/JAzFiTRs68o4lvyyT40
   ###RTX+V+jH3i+OU3N+8mVLFCbXOPkyEYl9PWH4jDkru/u9NEbK6TMzUo/y+Eioje4u
   ###K1jj64mcS+r6ZE1bOZq2dtF0neNfXwxyHX6YWn2WvsqH7BDHQ4emKuN4yUcvWkQ+
   ###hsbFILqoct5FGf5KMdfIoHT8UZqD1oUlKv4/9t68r41rSRiev/0pOs7vJlpB3VoA
   ###g7jD6vAEsAM4cR4Po7cltaCDNndLBm7i57O/tZy1uyUExknujEgMUvdZ69SpU1Wn
   ###lgEcUHAqsi40YDQmX3LiHAWSUYRJZABQOh+mo2aww74A6a0fkQBE3DzO82R/74Kv
   ###Vkbiags3jxDcnWt0lIdpQC/X/qdwFC1CrDdhtvZMF8JZAJCFr4bm8VG4ioCei6c/
   ###i2WZT49hFotjoTn21w+NfRb20dVh5JM24Jkx8d0w2bi9QIShUvgeDWXEAiZgZHEB
   ###rCtQujieDojQAVMQ07UJcQE+8ZIIHxZegaqjCTFH/xuOoAoKP4zfYhpowCC0B3ih
   ###FGFsrU/+cKKVSVJfQfdNhISIpo/AYwWRaxhNLOi/gAJzoI5zDiMFQk8VQUYb4TqE
   ###knWZBP37knN9345Cllhpb+KtFB4hozYw2iFvQmQnsf3jt3sgCN8HxLXHfCUq9zXF
   ###07MH4dySMA9bi8GiDYMW2Wd6DRfG1bSuNrXl0krZR/JGNp5ZOzG9EY3uvsKezJrn
   ###60fMc9ZOHYyGo1UOVIGcQYewOHO3IvIqJkKhNgpWMOqb4eg21pZfVtCT0ERgn3pk
   ###homNvAIg890uBzCC3cdDEUHsH0YdrfIzUcjJ4VxIOTMcwQNPPRAxORbHMVvzbuFY
   ###tlL+UTgmRiUj08wl9nZ3D+OYAs3mI9FtxpRfP2LK8/hxPfuB1JFKtQTemt9imnU9
   ###89TtYIZcpw8PdVDM1z6Rsgl7xJ5nVEkolhoLVEmoddYXqGKrg1j780AVW9PDih1Z
   ###JcmtzNs6u1D+NuzCoUfwW3xLWMth7YjMa9zsDTGH6ko2chH0OM9Ej7n74knzfj1z
   ###3q8Xn/diu0JON7kLnrIDbMr4v3xzfMUtkb0dHrMVEuiAakmyuM1Qt9snsu9cE/9F
   ###Yv510B+nqCxZmwFT2mHD4MWxR9wKzEEi8z4i6wVdKDwMd3GpgJNeHObchQVw+wr7
   ###sdyepDuxHk2S1HAHWok5j848elKv05N6vcCkFFWZT1ZQrh7S7Zu+m9PIIMaltZnA
   ###qPno8kDGbEKhLu/k7OwiyrzsMaiVump8G4066AIngI9aqnCAwjsuCIs2ievNme3x
   ###5d+h/wnaABFncg0c6xDbFsMfRdAGR0CX+q2sZrKu5BR0OVQvQA0PKHVn2eE0BiRi
   ###JpEkG/MdZ8e4Kn0k1TFGa22DDKuwp+4FKyOJvReMXhbbEE+e6+sZc3296Fytg1dN
   ###eEKB/2TUxlFPqgZIGmnfC6BMwkhoWw26K9SyH6d48WQUZjlfuHmwhKQsR9LRQbkV
   ###FoZuwvGYg7eoZB/xxI8mKvNAIFdHRLkEZJa6rUk4CIA5kp6OEqlxGFx4xTmUjYJc
   ###jppqikOK4Ri5YcRa885exWkRkSRhv8TsqwFUgXeenAReBK6Yd4DK0FY5iVCLI67P
   ###MMajq4uw7Yi9jqHLRT1gfNrTidKrS6AiQcGGFDywHdRifCInHZxfMk7NKPGkRA1+
   ###gi7Ea/GxhOa/wSdYsG4wDoa0CkniyeTREtAYH3ZM64xhEGgKQLqXYBgLTRKbO6DA
   ###zJBA2xhoiL1z/CE1hlrKslwP3iIri2wsHX2yPxrd+NeBr3KELL7FlDmXtcFSRl5P
   ###5WtR5UsBUefGLhXTHY7gYJEszghVYwI9DdMQpaJajNQeHuw5vb5/VSJ9UxhjU908



Valin, et al.                Standards Track                  [Page 167]

RFC 6716                 Interactive Audio Codec          September 2012


   ###xzIl1mZxwqvNIy26m7aafIDsZpLcxeCUpMa678WIsYTG4uiRMenXC056MQRR1+1m
   ###SGGgVx3cv1diI/yAV7KR5CvYmkDY8wE5vEIvBSBtgC+ksaQm4FlInixK959QcTG1
   ###ZNUVDmLIK6BMqyawF69CpA+Ju0Rsvo+cRcePAyZbV8QTRbIyNT0dIgHDwiuLoeqx
   ###PXPZHd9f4/2qecH6iMu0pMmthb2z7HGfyjpkr2ISb5O9Loa9XwNAr+cB6PWjAPQo
   ###goguoCO0OZiibSPdRygXx69FC/cv3j8XLYSmLDQyTK6/gPrNBkoSgaC/BdlPOenF
   ###0cGc2+uH5iYX3XbYUWZUhq0LTJ8+Z5lPCXMpZfaUspcygjw7Uqlh21LxO2Q0Ystq
   ###yjfMl4T1UcKE6RdkWkmlTzwQsKfQspG1FAfC2HfPiOczohhmUZL5C8l5EM24Uo3K
   ###IRvpVVMNCwOteIzO08AMiRs2aZxFNw3qWk10VcK7K2HB82VmWUaU8XE46VynjLXM
   ###SNvwOWE4Rfboue+oatJKq/mAldajLaseGE+qQnKC2H77toQLB3+fYhzGLeQXG0+i
   ###LvdqAolbQ2s28c75nUV0dAYfTnq5l+JgaStlHVCGgQ+w/ua/hi9FS5/nWJ0Zhmal
   ###1HBLqcmnjdHOAMUmsWGGwwHSAXFBJoQ9FQJ3ItQlProTxtf9eyOhU1fkxzTuj5Up
   ###tNgndL8W3yICEfbrFEGc24OEP5RYeP+RmRNAhYaAf5VQR3IR8C4ca6BHJuWI6DHm
   ###16K3YksFzOaQKClrL3hwJr06EmJ2j3QtIoZ8T0MNOT40QxrfO9kXjWx3OQnYImk8
   ###jcajOIhLSs40xW07VL2Gp5Yy/d6EZFIhW4nEE9RYTlkDDEcs8Qq3VpI3Ix2foD29
   ###ivNzThvTh0KcOgfmFHl4uoGFbuO0O4x9FZd2kynNcPlIaT6IMsnF6GO0I2maT9YS
   ###REhV3oe02kOtDSajgEWZlMesvSPQ9q9GERxaAzpewkhak4mDnbrmNQxWrlYY4RC/
   ###GdVXKZwVuTZQNgo1QDbjQI9mtCgiK/Yuye1sr8DHEE1LlhGm6UOdt6LEWhmA9AhR
   ###jMmv0KfrSZLPimC0lP5ATDh5uqUZ+rl2YjxA4FvDURf3W23dwQuKHLRcwYngsBXc
   ###84/DEz50LH7VdItaVCmWyZSpGzjhiKOVUbQ2WTdW56kbq69zKZd9IffIy7gsfq0f
   ###tjGKDlvgwJcI1UxGXB3tVZ1prfwpiCYY8IU9sI2MP9A1HgvX04GPR7/fJTYeI7cI
   ###gpvk3rmuzcFzDATWKNppU/gNN5dOn8IpgDjzD4EDdx7WwGQ53FMqcwvGjsY5SL1Z
   ###aqiy65+tAgt0jolaRKstrsQ+c5t6TR6TI0RFn3g4iNrM+F/Pkvljkfhfda/RaCTi
   ###f3mN6jL/xzL+1zL+1zL+1zL+1zL+1zL+1zL+13PF/3pE3K+dt0cZEb8Skb7mRPhK
   ###PFeBxx4X+4uGOwCiP0bNHY74hUMPUfJnq3hSvZDKWkTWJaMRJG4+328LuxGkuuxy
   ###buqRHaDeTBclPSSv7aOJ1aS42SfCuEcd/jKKbpByvyYpgd3uO6NoPIrIl2wCPQ5H
   ###/dHVvdCuFJhhAFnp/Oj4RzFqrCaZC3izd3B8oWwMHpolUNhrqN9Hhe4tXv/zrQdd
   ###Geq584TN0AGlF6TmxLXB8ZMfOwPh6G3JsYMOUHLpcFi+wiMDOHY4D3DIdEceBUjS
   ###4Xj7FLDXN7YLdJk4DpKJEYioKog7fj8QCWhGt3h5ViZFNByr0eiWrjfFEvFd/D05
   ###XOqrs4I0B6dusFm0P4Bzshf4E7pQIbsiQpV+aGcSF15969g0i9my2K4YhijRcG7a
   ###q7FTdyv0QTXGJkwc5QDOXhUOT08jt7d7lie4YGAKEuP0u5/hnWxrh9ZC6yupXwMI
   ###MMTetN8vs5Fiun8DjxXAk2XQ0p09mAlksgglhiC/PTFdb6XuDOheoFGBD7Lc69Go
   ###K25LR204/8leCpszb/EABJ3A75MpWO7t8Z6a4CEmaiUlHSaIpXq98C7olvm7TWAE
   ###hu9bTE7Mt9qomucmQars2S7BiedCB2E9BwaNhovaAuuFEOZfZMQwMfrgHXeQ8kHm
   ###e4QQaSWVIPM4UuWhLwTt0JJWnhAcpDUbmvCIa2qyliMN2dC6eGZlsKVg66I+FivN
   ###uqlQPySys8rbvE4pQAeb0nwm5WFOV9Q5TJOuE51bhl7fSU1AphL9UDFutLwlGBt1
   ###k9QOKmjAcxHyg906zMB8SiMKhxNz2fDXDKHWkwEZyesIASOykwopI0YERy3iCizR
   ###IOz7Ebo6JW/3WS+c7iIKyqZiXjn6k77QvBhTgTQTUMzLUH/oTMOx/2S4GuqzxOmt
   ###gGMfKTtB1tmPjCsB1OaXZUNd0dCDi4/bevMJOEHRDhJIoZLmSpTIm/gzoLHlsIB8
   ###TnqmRCM4IbzAKTkzkWsWUnGUmOwhyZuyWNiloVqZ7HT/FShgW/i04pyO2E+N70d6
   ###U4r3KHRNMWu+w1gImGipdU1nqExUXAKRBO8C8F5ApOfVVwoDv0vCH8gp4cS2fLMG
   ###QWSif+vfE+GUV9lwegk0IfM8us2Hxsm1gYRJrBZPeyD9hOp6ZyTeANklpTm00Bnf
   ###5/JaRcxsixk8R0wpHg3UtYvW7YrrVLxmUd7eyTu/fDIexw5ZrgWkfRDVZcxMGQxB
   ###3N1GQJsHAzY3Jn0uAXSigySKSydyBhYjFZdewwAJJ8jdKyJUKodfGNAZIXpFIoCr
   ###duvzJZuYqjQyTmyZrMvMUtrBXJj2WNeYs2sZsQp0DIUF6wobb7Z0Jr45P3dX6Dn5
   ###0ZU2QYoz3M2dHLAweV3YiO9AhxabdxMj4CLkMFID7zwXC7BN060d8oIQFeNlxGZM
   ###DN2HMQ9SXLHCIcP9pJT2GaAbnEyHAT5zg4DPbzMGDQ6HHpoWFaQCU86uSvdCWvSA
   ###ojeJODB0RMWcfluY7644J4hlRlm7mMRPkX2dr0inEd8jGp6KTAZGYrB09UuXTgY6
   ###ACkTQVll3BvKcQ+P6VwyLoCRY5AO89qNOQfsW8mB/3HhPPhXq2CDxMrlyZ6Xzlm8



Valin, et al.                Standards Track                  [Page 168]

RFC 6716                 Interactive Audio Codec          September 2012


   ###w3yV2AZ92FwWuWaspAotMVIz0T1zUqjcuWvx5weR1Nma9rf5Qz/cNlqWuKNHR1fZ
   ###KrMN3YARJFTQ2gR88lur0KRqWw9UNt2VjrmC1ol+h8pOOYe7RBxJidYEjytawnAD
   ###QEsin0xR2K9mkhEEGcODsWLKbk0DTLYoHdmSIQ1MlBRNyftK0UDO9dYaMgBCbNJV
   ###cwqrAuxJ4pNj6cQCJ4JFHaisFkyMisPdAtrJIQmizkPSTh6iCSYpW+1tMZFhcOWj
   ###BLq12t5W0UdArGcWiabsi3iLFBp51CHv4K667jXb5SMoBuqEYysZVvUMn+4o4Mte
   ###NLwWBhhCyCeldG7/4n1eb843Q6G7TRzUePNK6Xsw7gS0hFfLoVoakcRe7MqHThiZ
   ###8h6+z9owR9ZxTBfWzE2KfZ/mqfKmpXg2H1qSliBD4lxInGKcEeySH6OygGj/GLij
   ###IbKefQ53LXkAwZnQIuGoQJ4nVGADWcWekp4F7018DiGDTdB8NTfGllasI1dcipC9
   ###SIay+TXDxABYJT8cxmrLET1X1iMwe7P6is38hDzpIZvxB0IUFcuIo+yjIcY4VFEJ
   ###pDlQApql1Arw8FVmLo7dbnLXxufNF9a1p0qvleJr8Y3Bbgu1l4DSjhIrWMckRYXY
   ###kB8V9GhHRjJkNUxUGrpQdMJXQuSmUzPb/QrNm2OAEhxCc8yecXnJ9OIFGWSJo58V
   ###PsHwmrQ/tHB2BIA2K3bKZELQC/sTjsQhtB0osQzGQArCfxEykRppwtO+9iPg/MIO
   ###dPFmzNdbsISIfELJiEyQ0pvAzyxzeeEug7HwHf8KEWxiqjZWRHbiMBbtkNMkYfP9
   ###mMyHMDJnIoT3rohjo7hrAgDqNEpyXgg8gCOptQQQYyO2EnGxMd4tGsZZyv+HYLgy
   ###d+3Y1W3xxZOhQOmualjmYJBiFYFpugmkqk2CQwOCAzySDgpVO6KVHD1epYbytHlx
   ###+jouKOsNrQim2iwITedFO0TXXFJN0ZWZ9qKZD4AsJ72ONrgGZrYsPIVwHiwQUofC
   ###6JlXgxVsiaCeeBQHd0K2IDVcH+/5AP+Amk4xbIM1vsdFyMjsERVFIGMJ1QQfRE5O
   ###RU0EbCMJmqOLErvqkIXIYZwdgstSiLKC2NiVuR/+lU+2JKlRwtxEuxepAjl31csj
   ###iMw2k82ZLmV2i3uaPDm52XRpdQ7ary6MEdY0yf7IsqmRNkgsaahEIy+U7f0ZsDRR
   ###lxw9xF6PLcgiigsuSsGHHa6RkZhIVb6hySTtOJl3spEoCl2R1NkntMUjMxaWal+E
   ###6VGhiAqqR+I6R8jP3AqtIimfMHqdQMCQzsvY75GiQOgoEM2EPZrQuqvQuzg/OIYt
   ###pkVirqX3XHmRtPmxFFBZfAsldjbMkQ/JwJMzTCoFknpiainVwwKt2QtpuHRkHpVk
   ###JotBo/v3BgOTVj5eaO6HlJqCmwTqPFGimdQOKcNBfJ95stumrMrzmoRUO5gzcsci
   ###pF8IQL0dylGO2MgQHflg2Vn/Np9pARZwhvpMCqZonzKxYZKySpajSZv27l0cm76I
   ###vMMBMriLjGXWhq8pBe8zkaznpllPI1rZ9GoGqVqQSglrOhB9VJ6i82mHbhIwq1GS
   ###PiU3W4rTJNmB9om1D+NJ6cnbTm0zbi1WHLnWmNNmEimCDEGdtpE0iOype6mkBhe1
   ###kyYScJOHqJhnoaLElrNIqIRDsxD2jBhyLupGvBoqSNYrpGTaaIjwrG9FEGAKN2Vq
   ###DYi+Mx9SATYkBzWV8kD2mKcTmo2N2f7eIorEummVKjploZSrw67Fz7eDxp2BtYXc
   ###hqx3ZG0ZUuD2Ax9NbuDQ8LTEsSICKiKN0utUkO8L+G3Uy+kO0nvPWN5Zu0+CcEzw
   ###ESZIMzcgnc6kXsH20FZUhbNijlnY7Ts5lagX9S1Yo8XqCxTj0wNNFLIHu5O4eCGU
   ###FB1t4mXc9xMii8nQqWYcQGUFK2Aq3dQ5XZYYMypssf/8U7bznI3MlrWGPq0A2KG3
   ###r6HWe5FKRewUcIy6sA2p+dudEb5n3/5KsWVJCP5cQkDL8JVoALW93P5/5fYXmvCH
   ###iABr0Z9//x9Ggd79sm/NUSc5YWZJUwEcZ+P4ueFCRxn4VtIQQeeAbGVrAiBy0G/Z
   ###Kklk7JEOG8K1NaVHpMGSay5pmeRdcxCzGjGetmP8ivyQyjCANEY62PKtJobRTidA
   ###MFj3RL6bB1g4vD5MLrdwVqWhlZyVlRXTYyJt3SKdlmjC+0GWdYsdu8W0YCHZMduM
   ###xekGj7BiWdCCRXoaF6Bxfor2b0m32ywLlplGK8YFFRkrxfJeJi3FS1FvvYIRBCgU
   #